zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 14 | */ |
| 15 | |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 16 | #include <device/device.h> |
| 17 | #include <device/pci.h> |
| 18 | #include <device/pci_ids.h> |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 19 | #include <device/smbus.h> |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 20 | #include <cpu/x86/lapic.h> |
| 21 | #include <arch/ioapic.h> |
Elyes HAOUAS | 400f9ca | 2019-06-23 07:01:22 +0200 | [diff] [blame^] | 22 | |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 23 | #include "hudson.h" |
| 24 | #include "smbus.c" |
| 25 | |
| 26 | #define NMI_OFF 0 |
| 27 | |
| 28 | #define MAINBOARD_POWER_OFF 0 |
| 29 | #define MAINBOARD_POWER_ON 1 |
| 30 | |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 31 | #define BIT0 (1 << 0) |
| 32 | #define BIT1 (1 << 1) |
| 33 | #define BIT2 (1 << 2) |
| 34 | #define BIT3 (1 << 3) |
| 35 | #define BIT4 (1 << 4) |
| 36 | #define BIT5 (1 << 5) |
| 37 | #define BIT6 (1 << 6) |
| 38 | #define BIT7 (1 << 7) |
| 39 | |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 40 | #define BIT8 (1 << 8) |
| 41 | #define BIT9 (1 << 9) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 42 | #define BIT10 (1 << 10) |
| 43 | #define BIT11 (1 << 11) |
| 44 | #define BIT12 (1 << 12) |
| 45 | #define BIT13 (1 << 13) |
| 46 | #define BIT14 (1 << 14) |
| 47 | #define BIT15 (1 << 15) |
| 48 | |
| 49 | #define BIT16 (1 << 16) |
| 50 | #define BIT17 (1 << 17) |
| 51 | #define BIT18 (1 << 18) |
| 52 | #define BIT19 (1 << 19) |
| 53 | #define BIT20 (1 << 20) |
| 54 | #define BIT21 (1 << 21) |
| 55 | #define BIT22 (1 << 22) |
| 56 | #define BIT23 (1 << 23) |
| 57 | #define BIT24 (1 << 24) |
| 58 | #define BIT25 (1 << 25) |
| 59 | #define BIT26 (1 << 26) |
| 60 | #define BIT27 (1 << 27) |
| 61 | #define BIT28 (1 << 28) |
| 62 | #define BIT29 (1 << 29) |
| 63 | #define BIT30 (1 << 30) |
| 64 | #define BIT31 (1 << 31) |
| 65 | |
| 66 | /* |
| 67 | * HUDSON enables all USB controllers by default in SMBUS Control. |
| 68 | * HUDSON enables SATA by default in SMBUS Control. |
| 69 | */ |
| 70 | |
Elyes HAOUAS | a93e754 | 2018-05-19 14:30:47 +0200 | [diff] [blame] | 71 | static void sm_init(struct device *dev) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 72 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 73 | setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS); |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 74 | } |
| 75 | |
Elyes HAOUAS | a93e754 | 2018-05-19 14:30:47 +0200 | [diff] [blame] | 76 | static int lsmbus_recv_byte(struct device *dev) |
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_recv_byte(res->base, device); |
| 88 | } |
| 89 | |
Elyes HAOUAS | a93e754 | 2018-05-19 14:30:47 +0200 | [diff] [blame] | 90 | static int lsmbus_send_byte(struct device *dev, u8 val) |
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_send_byte(res->base, device, val); |
| 102 | } |
| 103 | |
Elyes HAOUAS | a93e754 | 2018-05-19 14:30:47 +0200 | [diff] [blame] | 104 | static int lsmbus_read_byte(struct device *dev, u8 address) |
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_read_byte(res->base, device, address); |
| 116 | } |
| 117 | |
Elyes HAOUAS | a93e754 | 2018-05-19 14:30:47 +0200 | [diff] [blame] | 118 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 val) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 119 | { |
| 120 | u32 device; |
| 121 | struct resource *res; |
| 122 | struct bus *pbus; |
| 123 | |
| 124 | device = dev->path.i2c.device; |
| 125 | pbus = get_pbus_smbus(dev); |
| 126 | |
| 127 | res = find_resource(pbus->dev, 0x90); |
| 128 | |
| 129 | return do_smbus_write_byte(res->base, device, address, val); |
| 130 | } |
| 131 | static struct smbus_bus_operations lops_smbus_bus = { |
| 132 | .recv_byte = lsmbus_recv_byte, |
| 133 | .send_byte = lsmbus_send_byte, |
| 134 | .read_byte = lsmbus_read_byte, |
| 135 | .write_byte = lsmbus_write_byte, |
| 136 | }; |
| 137 | |
Elyes HAOUAS | a93e754 | 2018-05-19 14:30:47 +0200 | [diff] [blame] | 138 | static void hudson_sm_read_resources(struct device *dev) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 139 | { |
| 140 | } |
| 141 | |
| 142 | static void hudson_sm_set_resources(struct device *dev) |
| 143 | { |
| 144 | } |
| 145 | |
| 146 | static struct pci_operations lops_pci = { |
| 147 | .set_subsystem = pci_dev_set_subsystem, |
| 148 | }; |
| 149 | static struct device_operations smbus_ops = { |
| 150 | .read_resources = hudson_sm_read_resources, |
| 151 | .set_resources = hudson_sm_set_resources, |
| 152 | .enable_resources = pci_dev_enable_resources, |
| 153 | .init = sm_init, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 154 | .scan_bus = scan_smbus, |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 155 | .ops_pci = &lops_pci, |
| 156 | .ops_smbus_bus = &lops_smbus_bus, |
| 157 | }; |
| 158 | static const struct pci_driver smbus_driver __pci_driver = { |
| 159 | .ops = &smbus_ops, |
| 160 | .vendor = PCI_VENDOR_ID_AMD, |
Kyösti Mälkki | 9d9a552 | 2016-11-19 22:14:59 +0200 | [diff] [blame] | 161 | .device = PCI_DEVICE_ID_AMD_SB900_SM, |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 162 | }; |