Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 2 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 3 | #include <device/device.h> |
| 4 | #include <device/pci.h> |
| 5 | #include <device/pci_ids.h> |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 6 | #include <device/smbus.h> |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 7 | #include <arch/ioapic.h> |
Elyes HAOUAS | 400f9ca | 2019-06-23 07:01:22 +0200 | [diff] [blame] | 8 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 9 | #include "hudson.h" |
| 10 | #include "smbus.c" |
| 11 | |
| 12 | #define NMI_OFF 0 |
| 13 | |
| 14 | #define MAINBOARD_POWER_OFF 0 |
| 15 | #define MAINBOARD_POWER_ON 1 |
| 16 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 17 | /* |
| 18 | * HUDSON enables all USB controllers by default in SMBUS Control. |
| 19 | * HUDSON enables SATA by default in SMBUS Control. |
| 20 | */ |
| 21 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame] | 22 | static void sm_init(struct device *dev) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 23 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 24 | setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 25 | } |
| 26 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame] | 27 | static int lsmbus_recv_byte(struct device *dev) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 28 | { |
| 29 | u32 device; |
| 30 | struct resource *res; |
| 31 | struct bus *pbus; |
| 32 | |
| 33 | device = dev->path.i2c.device; |
| 34 | pbus = get_pbus_smbus(dev); |
| 35 | |
| 36 | res = find_resource(pbus->dev, 0x90); |
| 37 | |
| 38 | return do_smbus_recv_byte(res->base, device); |
| 39 | } |
| 40 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame] | 41 | static int lsmbus_send_byte(struct device *dev, u8 val) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 42 | { |
| 43 | u32 device; |
| 44 | struct resource *res; |
| 45 | struct bus *pbus; |
| 46 | |
| 47 | device = dev->path.i2c.device; |
| 48 | pbus = get_pbus_smbus(dev); |
| 49 | |
| 50 | res = find_resource(pbus->dev, 0x90); |
| 51 | |
| 52 | return do_smbus_send_byte(res->base, device, val); |
| 53 | } |
| 54 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame] | 55 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 56 | { |
| 57 | u32 device; |
| 58 | struct resource *res; |
| 59 | struct bus *pbus; |
| 60 | |
| 61 | device = dev->path.i2c.device; |
| 62 | pbus = get_pbus_smbus(dev); |
| 63 | |
| 64 | res = find_resource(pbus->dev, 0x90); |
| 65 | |
| 66 | return do_smbus_read_byte(res->base, device, address); |
| 67 | } |
| 68 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame] | 69 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 val) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 70 | { |
| 71 | u32 device; |
| 72 | struct resource *res; |
| 73 | struct bus *pbus; |
| 74 | |
| 75 | device = dev->path.i2c.device; |
| 76 | pbus = get_pbus_smbus(dev); |
| 77 | |
| 78 | res = find_resource(pbus->dev, 0x90); |
| 79 | |
| 80 | return do_smbus_write_byte(res->base, device, address, val); |
| 81 | } |
| 82 | static struct smbus_bus_operations lops_smbus_bus = { |
| 83 | .recv_byte = lsmbus_recv_byte, |
| 84 | .send_byte = lsmbus_send_byte, |
| 85 | .read_byte = lsmbus_read_byte, |
| 86 | .write_byte = lsmbus_write_byte, |
| 87 | }; |
| 88 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame] | 89 | static void hudson_sm_read_resources(struct device *dev) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 90 | { |
| 91 | } |
| 92 | |
| 93 | static void hudson_sm_set_resources(struct device *dev) |
| 94 | { |
| 95 | } |
| 96 | |
| 97 | static struct pci_operations lops_pci = { |
| 98 | .set_subsystem = pci_dev_set_subsystem, |
| 99 | }; |
| 100 | static struct device_operations smbus_ops = { |
| 101 | .read_resources = hudson_sm_read_resources, |
| 102 | .set_resources = hudson_sm_set_resources, |
| 103 | .enable_resources = pci_dev_enable_resources, |
| 104 | .init = sm_init, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 105 | .scan_bus = scan_smbus, |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 106 | .ops_pci = &lops_pci, |
| 107 | .ops_smbus_bus = &lops_smbus_bus, |
| 108 | }; |
| 109 | static const struct pci_driver smbus_driver __pci_driver = { |
| 110 | .ops = &smbus_ops, |
| 111 | .vendor = PCI_VENDOR_ID_AMD, |
Kyösti Mälkki | 9d9a552 | 2016-11-19 22:14:59 +0200 | [diff] [blame] | 112 | .device = PCI_DEVICE_ID_AMD_SB900_SM, |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 113 | }; |