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