Debian Codegraph @

src/soc/amd/common/block/smbus/sm.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <amdblocks/acpimmio.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <device/smbus.h>
7 #include <device/smbus_host.h>
8
9 static u32 get_sm_mmio(struct device *dev)
10 {
11 /*
12 * Since SMBus and ASF controller are behind the same PCIe device, we don't know behind
13 * which controller a device is. We assume here that the devices are behind the SMBus
14 * controller. The proper solution would be to handle those as MMIO devices instead of
15 * PCI ones.
16 */
17 return (uintptr_t)acpimmio_smbus;
18 }
19
20 static int lsmbus_recv_byte(struct device *dev)
21 {
22 u8 device;
23
24 device = dev->path.i2c.device;
25 return do_smbus_recv_byte(get_sm_mmio(dev), device);
26 }
27
28 static int lsmbus_send_byte(struct device *dev, u8 val)
29 {
30 u8 device;
31
32 device = dev->path.i2c.device;
33 return do_smbus_send_byte(get_sm_mmio(dev), device, val);
34 }
35
36 static int lsmbus_read_byte(struct device *dev, u8 address)
37 {
38 u8 device;
39
40 device = dev->path.i2c.device;
41 return do_smbus_read_byte(get_sm_mmio(dev), device, address);
42 }
43
44 static int lsmbus_write_byte(struct device *dev, u8 address, u8 val)
45 {
46 u8 device;
47
48 device = dev->path.i2c.device;
49 return do_smbus_write_byte(get_sm_mmio(dev), device, address, val);
50 }
51
52 static struct smbus_bus_operations lops_smbus_bus = {
53 .recv_byte = lsmbus_recv_byte,
54 .send_byte = lsmbus_send_byte,
55 .read_byte = lsmbus_read_byte,
56 .write_byte = lsmbus_write_byte,
57 };
58
59 #if CONFIG(HAVE_ACPI_TABLES)
60 static const char *smbus_acpi_name(const struct device *dev)
61 {
62 return "SBUS";
63 }
64 #endif
65
66 struct device_operations amd_smbus_ops = {
67 .read_resources = noop_read_resources,
68 .set_resources = noop_set_resources,
69 .enable_resources = pci_dev_enable_resources,
70 .scan_bus = scan_smbus,
71 .ops_pci = &pci_dev_ops_pci,
72 .ops_smbus_bus = &lops_smbus_bus,
73 #if CONFIG(HAVE_ACPI_TABLES)
74 .acpi_name = smbus_acpi_name,
75 #endif
76 };