Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 2 | |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 3 | #include <device/device.h> |
| 4 | #include <device/pci.h> |
| 5 | #include <device/pci_ids.h> |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 6 | #include <device/smbus.h> |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 7 | #include <arch/ioapic.h> |
Elyes HAOUAS | 400f9ca | 2019-06-23 07:01:22 +0200 | [diff] [blame] | 8 | |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [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 | |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 17 | #define BIT0 (1 << 0) |
| 18 | #define BIT1 (1 << 1) |
| 19 | #define BIT2 (1 << 2) |
| 20 | #define BIT3 (1 << 3) |
| 21 | #define BIT4 (1 << 4) |
| 22 | #define BIT5 (1 << 5) |
| 23 | #define BIT6 (1 << 6) |
| 24 | #define BIT7 (1 << 7) |
| 25 | |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 26 | #define BIT8 (1 << 8) |
| 27 | #define BIT9 (1 << 9) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 28 | #define BIT10 (1 << 10) |
| 29 | #define BIT11 (1 << 11) |
| 30 | #define BIT12 (1 << 12) |
| 31 | #define BIT13 (1 << 13) |
| 32 | #define BIT14 (1 << 14) |
| 33 | #define BIT15 (1 << 15) |
| 34 | |
| 35 | #define BIT16 (1 << 16) |
| 36 | #define BIT17 (1 << 17) |
| 37 | #define BIT18 (1 << 18) |
| 38 | #define BIT19 (1 << 19) |
| 39 | #define BIT20 (1 << 20) |
| 40 | #define BIT21 (1 << 21) |
| 41 | #define BIT22 (1 << 22) |
| 42 | #define BIT23 (1 << 23) |
| 43 | #define BIT24 (1 << 24) |
| 44 | #define BIT25 (1 << 25) |
| 45 | #define BIT26 (1 << 26) |
| 46 | #define BIT27 (1 << 27) |
| 47 | #define BIT28 (1 << 28) |
| 48 | #define BIT29 (1 << 29) |
| 49 | #define BIT30 (1 << 30) |
| 50 | #define BIT31 (1 << 31) |
| 51 | |
| 52 | /* |
| 53 | * HUDSON enables all USB controllers by default in SMBUS Control. |
| 54 | * HUDSON enables SATA by default in SMBUS Control. |
| 55 | */ |
| 56 | |
Elyes HAOUAS | a93e754 | 2018-05-19 14:30:47 +0200 | [diff] [blame] | 57 | static void sm_init(struct device *dev) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 58 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 59 | setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS); |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 60 | } |
| 61 | |
Elyes HAOUAS | a93e754 | 2018-05-19 14:30:47 +0200 | [diff] [blame] | 62 | static int lsmbus_recv_byte(struct device *dev) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 63 | { |
| 64 | u32 device; |
| 65 | struct resource *res; |
| 66 | struct bus *pbus; |
| 67 | |
| 68 | device = dev->path.i2c.device; |
| 69 | pbus = get_pbus_smbus(dev); |
| 70 | |
| 71 | res = find_resource(pbus->dev, 0x90); |
| 72 | |
| 73 | return do_smbus_recv_byte(res->base, device); |
| 74 | } |
| 75 | |
Elyes HAOUAS | a93e754 | 2018-05-19 14:30:47 +0200 | [diff] [blame] | 76 | static int lsmbus_send_byte(struct device *dev, u8 val) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 77 | { |
| 78 | u32 device; |
| 79 | struct resource *res; |
| 80 | struct bus *pbus; |
| 81 | |
| 82 | device = dev->path.i2c.device; |
| 83 | pbus = get_pbus_smbus(dev); |
| 84 | |
| 85 | res = find_resource(pbus->dev, 0x90); |
| 86 | |
| 87 | return do_smbus_send_byte(res->base, device, val); |
| 88 | } |
| 89 | |
Elyes HAOUAS | a93e754 | 2018-05-19 14:30:47 +0200 | [diff] [blame] | 90 | static int lsmbus_read_byte(struct device *dev, u8 address) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 91 | { |
| 92 | u32 device; |
| 93 | struct resource *res; |
| 94 | struct bus *pbus; |
| 95 | |
| 96 | device = dev->path.i2c.device; |
| 97 | pbus = get_pbus_smbus(dev); |
| 98 | |
| 99 | res = find_resource(pbus->dev, 0x90); |
| 100 | |
| 101 | return do_smbus_read_byte(res->base, device, address); |
| 102 | } |
| 103 | |
Elyes HAOUAS | a93e754 | 2018-05-19 14:30:47 +0200 | [diff] [blame] | 104 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 val) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 105 | { |
| 106 | u32 device; |
| 107 | struct resource *res; |
| 108 | struct bus *pbus; |
| 109 | |
| 110 | device = dev->path.i2c.device; |
| 111 | pbus = get_pbus_smbus(dev); |
| 112 | |
| 113 | res = find_resource(pbus->dev, 0x90); |
| 114 | |
| 115 | return do_smbus_write_byte(res->base, device, address, val); |
| 116 | } |
| 117 | static struct smbus_bus_operations lops_smbus_bus = { |
| 118 | .recv_byte = lsmbus_recv_byte, |
| 119 | .send_byte = lsmbus_send_byte, |
| 120 | .read_byte = lsmbus_read_byte, |
| 121 | .write_byte = lsmbus_write_byte, |
| 122 | }; |
| 123 | |
Elyes HAOUAS | a93e754 | 2018-05-19 14:30:47 +0200 | [diff] [blame] | 124 | static void hudson_sm_read_resources(struct device *dev) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 125 | { |
| 126 | } |
| 127 | |
| 128 | static void hudson_sm_set_resources(struct device *dev) |
| 129 | { |
| 130 | } |
| 131 | |
| 132 | static struct pci_operations lops_pci = { |
| 133 | .set_subsystem = pci_dev_set_subsystem, |
| 134 | }; |
| 135 | static struct device_operations smbus_ops = { |
| 136 | .read_resources = hudson_sm_read_resources, |
| 137 | .set_resources = hudson_sm_set_resources, |
| 138 | .enable_resources = pci_dev_enable_resources, |
| 139 | .init = sm_init, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 140 | .scan_bus = scan_smbus, |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 141 | .ops_pci = &lops_pci, |
| 142 | .ops_smbus_bus = &lops_smbus_bus, |
| 143 | }; |
| 144 | static const struct pci_driver smbus_driver __pci_driver = { |
| 145 | .ops = &smbus_ops, |
| 146 | .vendor = PCI_VENDOR_ID_AMD, |
Kyösti Mälkki | 9d9a552 | 2016-11-19 22:14:59 +0200 | [diff] [blame] | 147 | .device = PCI_DEVICE_ID_AMD_SB900_SM, |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 148 | }; |