Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 13 | */ |
| 14 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 15 | #include <device/device.h> |
| 16 | #include <device/pci.h> |
| 17 | #include <device/pci_ids.h> |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 18 | #include <device/smbus.h> |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 19 | #include <cpu/x86/lapic.h> |
| 20 | #include <arch/ioapic.h> |
Elyes HAOUAS | 400f9ca | 2019-06-23 07:01:22 +0200 | [diff] [blame] | 21 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 22 | #include "hudson.h" |
| 23 | #include "smbus.c" |
| 24 | |
| 25 | #define NMI_OFF 0 |
| 26 | |
| 27 | #define MAINBOARD_POWER_OFF 0 |
| 28 | #define MAINBOARD_POWER_ON 1 |
| 29 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 30 | /* |
| 31 | * HUDSON enables all USB controllers by default in SMBUS Control. |
| 32 | * HUDSON enables SATA by default in SMBUS Control. |
| 33 | */ |
| 34 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame] | 35 | static void sm_init(struct device *dev) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 36 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 37 | setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 38 | } |
| 39 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame] | 40 | static int lsmbus_recv_byte(struct device *dev) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 41 | { |
| 42 | u32 device; |
| 43 | struct resource *res; |
| 44 | struct bus *pbus; |
| 45 | |
| 46 | device = dev->path.i2c.device; |
| 47 | pbus = get_pbus_smbus(dev); |
| 48 | |
| 49 | res = find_resource(pbus->dev, 0x90); |
| 50 | |
| 51 | return do_smbus_recv_byte(res->base, device); |
| 52 | } |
| 53 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame] | 54 | static int lsmbus_send_byte(struct device *dev, u8 val) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 55 | { |
| 56 | u32 device; |
| 57 | struct resource *res; |
| 58 | struct bus *pbus; |
| 59 | |
| 60 | device = dev->path.i2c.device; |
| 61 | pbus = get_pbus_smbus(dev); |
| 62 | |
| 63 | res = find_resource(pbus->dev, 0x90); |
| 64 | |
| 65 | return do_smbus_send_byte(res->base, device, val); |
| 66 | } |
| 67 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame] | 68 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 69 | { |
| 70 | u32 device; |
| 71 | struct resource *res; |
| 72 | struct bus *pbus; |
| 73 | |
| 74 | device = dev->path.i2c.device; |
| 75 | pbus = get_pbus_smbus(dev); |
| 76 | |
| 77 | res = find_resource(pbus->dev, 0x90); |
| 78 | |
| 79 | return do_smbus_read_byte(res->base, device, address); |
| 80 | } |
| 81 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame] | 82 | 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] | 83 | { |
| 84 | u32 device; |
| 85 | struct resource *res; |
| 86 | struct bus *pbus; |
| 87 | |
| 88 | device = dev->path.i2c.device; |
| 89 | pbus = get_pbus_smbus(dev); |
| 90 | |
| 91 | res = find_resource(pbus->dev, 0x90); |
| 92 | |
| 93 | return do_smbus_write_byte(res->base, device, address, val); |
| 94 | } |
| 95 | static struct smbus_bus_operations lops_smbus_bus = { |
| 96 | .recv_byte = lsmbus_recv_byte, |
| 97 | .send_byte = lsmbus_send_byte, |
| 98 | .read_byte = lsmbus_read_byte, |
| 99 | .write_byte = lsmbus_write_byte, |
| 100 | }; |
| 101 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame] | 102 | static void hudson_sm_read_resources(struct device *dev) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 103 | { |
| 104 | } |
| 105 | |
| 106 | static void hudson_sm_set_resources(struct device *dev) |
| 107 | { |
| 108 | } |
| 109 | |
| 110 | static struct pci_operations lops_pci = { |
| 111 | .set_subsystem = pci_dev_set_subsystem, |
| 112 | }; |
| 113 | static struct device_operations smbus_ops = { |
| 114 | .read_resources = hudson_sm_read_resources, |
| 115 | .set_resources = hudson_sm_set_resources, |
| 116 | .enable_resources = pci_dev_enable_resources, |
| 117 | .init = sm_init, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 118 | .scan_bus = scan_smbus, |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 119 | .ops_pci = &lops_pci, |
| 120 | .ops_smbus_bus = &lops_smbus_bus, |
| 121 | }; |
| 122 | static const struct pci_driver smbus_driver __pci_driver = { |
| 123 | .ops = &smbus_ops, |
| 124 | .vendor = PCI_VENDOR_ID_AMD, |
Kyösti Mälkki | 9d9a552 | 2016-11-19 22:14:59 +0200 | [diff] [blame] | 125 | .device = PCI_DEVICE_ID_AMD_SB900_SM, |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 126 | }; |