Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 2 | |
Kyösti Mälkki | d786520 | 2020-07-01 13:15:27 +0300 | [diff] [blame] | 3 | #include <amdblocks/acpimmio.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 4 | #include <device/device.h> |
| 5 | #include <device/pci.h> |
| 6 | #include <device/pci_ids.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 7 | #include <device/smbus.h> |
Aaron Durbin | 178d644 | 2020-01-28 11:10:23 -0700 | [diff] [blame] | 8 | #include <device/smbus_host.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 9 | #include <arch/ioapic.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 10 | #include <soc/southbridge.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 11 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 12 | static void sm_init(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 13 | { |
Felix Held | 1b33205 | 2021-02-11 03:01:18 +0100 | [diff] [blame] | 14 | fch_enable_ioapic_decode(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 15 | setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS); |
Felix Held | 34fc29a | 2021-02-11 02:43:07 +0100 | [diff] [blame^] | 16 | fch_configure_hpet(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 17 | } |
| 18 | |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 19 | static u32 get_sm_mmio(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 20 | { |
Felix Held | 8199b88 | 2021-01-05 00:03:20 +0100 | [diff] [blame] | 21 | /* |
| 22 | * Since SMBus and ASF controller are behind the same PCIe device, we don't know behind |
| 23 | * which controller a device is. We assume here that the devices are behind the SMBus |
| 24 | * controller. The proper solution would be to handle those as MMIO devices instead of |
| 25 | * PCI ones. |
| 26 | */ |
| 27 | return (uintptr_t)acpimmio_smbus; |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | static int lsmbus_recv_byte(struct device *dev) |
| 31 | { |
| 32 | u8 device; |
| 33 | |
| 34 | device = dev->path.i2c.device; |
| 35 | return do_smbus_recv_byte(get_sm_mmio(dev), device); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 36 | } |
| 37 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 38 | static int lsmbus_send_byte(struct device *dev, u8 val) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 39 | { |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 40 | u8 device; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 41 | |
| 42 | device = dev->path.i2c.device; |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 43 | return do_smbus_send_byte(get_sm_mmio(dev), device, val); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 44 | } |
| 45 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 46 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 47 | { |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 48 | u8 device; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 49 | |
| 50 | device = dev->path.i2c.device; |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 51 | return do_smbus_read_byte(get_sm_mmio(dev), device, address); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 52 | } |
| 53 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 54 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 val) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 55 | { |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 56 | u8 device; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 57 | |
| 58 | device = dev->path.i2c.device; |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 59 | return do_smbus_write_byte(get_sm_mmio(dev), device, address, val); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 60 | } |
| 61 | static struct smbus_bus_operations lops_smbus_bus = { |
| 62 | .recv_byte = lsmbus_recv_byte, |
| 63 | .send_byte = lsmbus_send_byte, |
| 64 | .read_byte = lsmbus_read_byte, |
| 65 | .write_byte = lsmbus_write_byte, |
| 66 | }; |
| 67 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 68 | static struct device_operations smbus_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 69 | .read_resources = noop_read_resources, |
| 70 | .set_resources = noop_set_resources, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 71 | .enable_resources = pci_dev_enable_resources, |
| 72 | .init = sm_init, |
| 73 | .scan_bus = scan_smbus, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 74 | .ops_pci = &pci_dev_ops_pci, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 75 | .ops_smbus_bus = &lops_smbus_bus, |
| 76 | }; |
| 77 | static const struct pci_driver smbus_driver __pci_driver = { |
| 78 | .ops = &smbus_ops, |
| 79 | .vendor = PCI_VENDOR_ID_AMD, |
Martin Roth | 069ca66 | 2018-03-01 11:26:18 -0700 | [diff] [blame] | 80 | .device = PCI_DEVICE_ID_AMD_CZ_SMBUS, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 81 | }; |