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-only */
2 
3 #include <device/device.h>
4 #include <device/path.h>
5 #include <device/smbus.h>
6 #include <device/pci.h>
7 #include <device/pci_ids.h>
8 #include <soc/smbus.h>
9 #include <device/smbus_host.h>
10 #include <intelblocks/tco.h>
11 #include "smbuslib.h"
12 
13 static int lsmbus_read_byte(struct device *dev, u8 address)
14 {
15  u16 device;
16  struct resource *res;
17  struct bus *pbus;
19  pbus = get_pbus_smbus(dev);
20  res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4);
21  return do_smbus_read_byte(res->base, device, address);
22 }
23 
24 static int lsmbus_write_byte(struct device *dev, u8 address, u8 data)
25 {
26  u16 device;
27  struct resource *res;
28  struct bus *pbus;
29 
31  pbus = get_pbus_smbus(dev);
32  res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4);
33  return do_smbus_write_byte(res->base, device, address, data);
34 }
35 
36 static struct smbus_bus_operations lops_smbus_bus = {
38  .write_byte = lsmbus_write_byte,
39 };
40 
41 static void pch_smbus_init(struct device *dev)
42 {
43  struct resource *res;
44 
45  /* Enable clock gating */
46  pci_update_config32(dev, 0x80,
47  ~((1 << 8) | (1 << 10) | (1 << 12) | (1 << 14)), 0);
48 
49  /* Set Receive Slave Address */
51  if (res)
53 }
54 
55 static void smbus_read_resources(struct device *dev)
56 {
58 
59  struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4);
60  res->base = SMBUS_IO_BASE;
61  res->size = 32;
62  res->limit = res->base + res->size - 1;
65 }
66 
67 /*
68  * `finalize_smbus` function is native implementation of equivalent events
69  * performed by each FSP NotifyPhase() API invocations.
70  *
71  * Operations are:
72  * 1. TCO Lock.
73  */
74 static void finalize_smbus(struct device *dev)
75 {
76  if (!CONFIG(USE_FSP_NOTIFY_PHASE_POST_PCI_ENUM))
77  tco_lockdown();
78 }
79 
80 static struct device_operations smbus_ops = {
82  .set_resources = pci_dev_set_resources,
83  .enable_resources = pci_dev_enable_resources,
84  .scan_bus = scan_smbus,
85  .init = pch_smbus_init,
86  .ops_pci = &pci_dev_ops_pci,
87  .ops_smbus_bus = &lops_smbus_bus,
88  .final = finalize_smbus,
89 };
90 
91 static const unsigned short pci_device_ids[] = {
111  0
112 };
113 
114 static const struct pci_driver pch_smbus __pci_driver = {
115  .ops = &smbus_ops,
116  .vendor = PCI_VID_INTEL,
117  .devices = pci_device_ids,
118 };
enum fch_io_device device
Definition: fch.c:74
struct bus * get_pbus_smbus(struct device *dev)
Definition: smbus_ops.c:8
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
struct resource * probe_resource(const struct device *dev, unsigned int index)
See if a resource structure already exists for a given index.
Definition: device_util.c:323
struct resource * find_resource(const struct device *dev, unsigned int index)
Return an existing resource structure for a given index.
Definition: device_util.c:394
@ CONFIG
Definition: dsi_common.h:201
uint64_t address
Definition: fw_cfg_if.h:0
static __always_inline void pci_update_config32(const struct device *dev, u16 reg, u32 mask, u32 or)
Definition: pci_ops.h:120
#define PCI_BASE_ADDRESS_4
Definition: pci_def.h:67
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
struct pci_operations pci_dev_ops_pci
Default device operation for PCI devices.
Definition: pci_device.c:911
void pci_dev_set_resources(struct device *dev)
Definition: pci_device.c:691
#define PCI_DID_INTEL_CMP_SMBUS
Definition: pci_ids.h:4095
#define PCI_DID_INTEL_APL_SMBUS
Definition: pci_ids.h:4087
#define PCI_DID_INTEL_CNP_H_SMBUS
Definition: pci_ids.h:4093
#define PCI_DID_INTEL_DNV_SMBUS_LEGACY
Definition: pci_ids.h:2790
#define PCI_DID_INTEL_MCC_SMBUS
Definition: pci_ids.h:4099
#define PCI_DID_INTEL_MTL_SMBUS
Definition: pci_ids.h:4104
#define PCI_DID_INTEL_ADP_M_N_SMBUS
Definition: pci_ids.h:4103
#define PCI_DID_INTEL_LWB_SMBUS_SUPER
Definition: pci_ids.h:4091
#define PCI_DID_INTEL_CNL_SMBUS
Definition: pci_ids.h:4092
#define PCI_DID_INTEL_SPT_LP_SMBUS
Definition: pci_ids.h:4088
#define PCI_DID_INTEL_TGP_H_SMBUS
Definition: pci_ids.h:4098
#define PCI_DID_INTEL_ICP_LP_SMBUS
Definition: pci_ids.h:4094
#define PCI_DID_INTEL_LWB_SMBUS
Definition: pci_ids.h:4090
#define PCI_DID_INTEL_SPT_H_SMBUS
Definition: pci_ids.h:4089
#define PCI_DID_INTEL_TGP_LP_SMBUS
Definition: pci_ids.h:4097
#define PCI_DID_INTEL_JSP_SMBUS
Definition: pci_ids.h:4100
#define PCI_VID_INTEL
Definition: pci_ids.h:2157
#define PCI_DID_INTEL_ADP_S_SMBUS
Definition: pci_ids.h:4102
#define PCI_DID_INTEL_CMP_H_SMBUS
Definition: pci_ids.h:4096
#define PCI_DID_INTEL_ADP_P_SMBUS
Definition: pci_ids.h:4101
#define IORESOURCE_RESERVE
Definition: resource.h:30
#define IORESOURCE_STORED
Definition: resource.h:32
#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
int do_smbus_read_byte(uintptr_t mmio, u8 device, u8 address)
Definition: smbus.c:121
int do_smbus_write_byte(uintptr_t mmio, u8 device, u8 address, u8 val)
Definition: smbus.c:149
#define SMBUS_SLAVE_ADDR
Definition: smbus.h:20
void tco_lockdown(void)
Definition: tco.c:50
static int lsmbus_write_byte(struct device *dev, u8 address, u8 data)
Definition: smbus.c:24
static const struct pci_driver pch_smbus __pci_driver
Definition: smbus.c:114
static struct smbus_bus_operations lops_smbus_bus
Definition: smbus.c:36
static const unsigned short pci_device_ids[]
Definition: smbus.c:91
static void pch_smbus_init(struct device *dev)
Definition: smbus.c:41
static struct device_operations smbus_ops
Definition: smbus.c:80
static void smbus_read_resources(struct device *dev)
Definition: smbus.c:55
static void finalize_smbus(struct device *dev)
Definition: smbus.c:74
static int lsmbus_read_byte(struct device *dev, u8 address)
Definition: smbus.c:13
void smbus_set_slave_addr(uintptr_t base, u8 slave_address)
Definition: smbus.c:102
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45
Definition: device.h:76
DEVTREE_CONST struct device * dev
Definition: device.h:78
void(* read_resources)(struct device *dev)
Definition: device.h:39
struct i2c_path i2c
Definition: path.h:118
Definition: device.h:107
struct device_path path
Definition: device.h:115
unsigned int device
Definition: path.h:63
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
int(* read_byte)(struct device *dev, u8 addr)
Definition: smbus.h:12