coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
smbus.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <arch/io.h>
4 #include <device/pci_ops.h>
5 #include <console/console.h>
6 #include <stdint.h>
7 #include <device/device.h>
8 #include <device/pci.h>
9 #include <device/pci_ids.h>
10 #include <device/smbus.h>
11 #include "chip.h"
12 #include "i82371eb.h"
13 
14 static void pwrmgt_enable(struct device *dev)
15 {
17  u32 reg, gpo = sb->gpo;
18 
19  /* Sets the base address of power management ports. */
21 
22  /* Set Power Management IO Space Enable bit */
24  pci_write_config8(dev, PMREGMISC, val | 1);
25 
26  /* set global control:
27  * bit25 (lid_pol): 1=invert lid polarity
28  * bit24 (sm_freeze): 1=freeze idle and standby timers
29  * bit16 (end of smi): 0=disable smi assertion (cleared by hw)
30  * bits8-15,26: global standby timer initial count 127 * 4minutes
31  * bit2 (thrm_pol): 1=active low THRM#
32  * bit0 (smi_en): 1=disable smi generation upon smi event
33  */
34  reg = (sb->lid_polarity<<25)|
35  (1<<24)|
36  (0xff<<8)|
37  (sb->thrm_polarity<<2);
38  outl(reg, DEFAULT_PMBASE + GLBCTL);
39 
40  /* set processor control:
41  * bit12 (stpclk_en): 1=enable stopping of host clk on lvl3
42  * bit11 (sleep_en): 1=enable slp# assertion on lvl3
43  * bit9 (cc_en): 1=enable clk control with lvl2 and lvl3 regs
44  */
46 
47  /* disable smi event enables */
50 
51  /* set default gpo value.
52  * power-on default is 0x7fffbfffh */
53  if (gpo) {
54  /* only 8bit access allowed */
55  outb(gpo & 0xff, DEFAULT_PMBASE + GPO0);
56  outb((gpo >> 8) & 0xff, DEFAULT_PMBASE + GPO1);
57  outb((gpo >> 16) & 0xff, DEFAULT_PMBASE + GPO2);
58  outb((gpo >> 24) & 0xff, DEFAULT_PMBASE + GPO3);
59  } else {
61  "%s: gpo default missing in devicetree.cb!\n", __func__);
62  }
63 
64  /* Clear status events. */
65  outw(0xffff, DEFAULT_PMBASE + PMSTS);
66  outw(0xffff, DEFAULT_PMBASE + GPSTS);
67  outw(0xffff, DEFAULT_PMBASE + GLBSTS);
68  outl(0xffffffff, DEFAULT_PMBASE + DEVSTS);
69 
70  /* set PMCNTRL default */
72 }
73 
74 static void pwrmgt_read_resources(struct device *dev)
75 {
76  struct resource *res;
77 
79 
80  res = new_resource(dev, 1);
81  res->base = DEFAULT_PMBASE;
82  res->size = 0x0040;
83  res->limit = 0xffff;
86 
87  res = new_resource(dev, 2);
88  res->base = SMBUS_IO_BASE;
89  res->size = 0x0010;
90  res->limit = 0xffff;
93 }
94 
95 static const struct smbus_bus_operations lops_smbus_bus = {
96 };
97 
98 static const struct device_operations smbus_ops = {
100  .set_resources = pci_dev_set_resources,
101  .enable_resources = pci_dev_enable_resources,
102  .scan_bus = scan_smbus,
103  .enable = pwrmgt_enable,
104  .ops_pci = 0, /* No subsystem IDs on 82371EB! */
105  .ops_smbus_bus = &lops_smbus_bus,
106 };
107 
108 /* Note: There's no SMBus on 82371FB/SB/MX and 82437MX. */
109 
110 /* Intel 82371AB/EB/MB */
111 static const struct pci_driver smbus_driver __pci_driver = {
112  .ops = &smbus_ops,
113  .vendor = PCI_VID_INTEL,
115 };
#define SCI_EN
Definition: pm.h:30
#define printk(level,...)
Definition: stdlib.h:16
void outb(u8 val, u16 port)
void outl(u32 val, u16 port)
void outw(u16 val, u16 port)
struct resource * new_resource(struct device *dev, unsigned int index)
See if a resource structure already exists for a given index and if not allocate one.
Definition: device_util.c:346
#define GLBCTL
Definition: i82371eb.h:78
#define GLBSTS
Definition: i82371eb.h:61
#define GLBEN
Definition: i82371eb.h:72
#define GPO0
Definition: i82371eb.h:83
#define GPO2
Definition: i82371eb.h:85
#define PMCNTRL
Definition: i82371eb.h:47
#define SUS_TYP_S0
Definition: i82371eb.h:50
#define GPO1
Definition: i82371eb.h:84
#define PMREGMISC
Definition: i82371eb.h:102
#define PCNTRL
Definition: i82371eb.h:60
#define GPO3
Definition: i82371eb.h:86
#define PMBA
Definition: i82371eb.h:89
#define DEVSTS
Definition: i82371eb.h:71
#define DEVCTL
Definition: i82371eb.h:81
#define GPSTS
Definition: i82371eb.h:57
static __always_inline u8 pci_read_config8(const struct device *dev, u16 reg)
Definition: pci_ops.h:46
static __always_inline void pci_write_config16(const struct device *dev, u16 reg, u16 val)
Definition: pci_ops.h:70
static __always_inline void pci_write_config8(const struct device *dev, u16 reg, u8 val)
Definition: pci_ops.h:64
#define DEFAULT_PMBASE
Definition: iomap.h:14
#define BIOS_SPEW
BIOS_SPEW - Excessively verbose output.
Definition: loglevel.h:142
#define PMSTS
Definition: mchbar_regs.h:475
void pci_dev_enable_resources(struct device *dev)
Definition: pci_device.c:721
void pci_dev_read_resources(struct device *dev)
Definition: pci_device.c:534
void pci_dev_set_resources(struct device *dev)
Definition: pci_device.c:691
#define PCI_DID_INTEL_82371AB_SMB_ACPI
Definition: pci_ids.h:2206
#define PCI_VID_INTEL
Definition: pci_ids.h:2157
#define IORESOURCE_RESERVE
Definition: resource.h:30
#define IORESOURCE_ASSIGNED
Definition: resource.h:34
#define IORESOURCE_IO
Definition: resource.h:9
#define IORESOURCE_FIXED
Definition: resource.h:36
void scan_smbus(struct device *bus)
Definition: root_device.c:74
#define SMBUS_IO_BASE
Definition: smbuslib.h:7
static void pwrmgt_enable(struct device *dev)
Definition: smbus.c:14
static void pwrmgt_read_resources(struct device *dev)
Definition: smbus.c:74
static const struct device_operations smbus_ops
Definition: smbus.c:98
static const struct smbus_bus_operations lops_smbus_bus
Definition: smbus.c:95
static const struct pci_driver smbus_driver __pci_driver
Definition: smbus.c:111
uint32_t u32
Definition: stdint.h:51
uint8_t u8
Definition: stdint.h:45
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107
DEVTREE_CONST void * chip_info
Definition: device.h:164
unsigned long flags
Definition: resource.h:49
resource_t limit
Definition: resource.h:47
resource_t base
Definition: resource.h:45
resource_t size
Definition: resource.h:46
u8 val
Definition: sys.c:300