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 | * |
| 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. |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <console/console.h> |
| 17 | #include <device/device.h> |
| 18 | #include <device/pci.h> |
| 19 | #include <device/pci_ids.h> |
| 20 | #include <device/pci_ops.h> |
| 21 | #include <device/smbus.h> |
| 22 | #include <pc80/mc146818rtc.h> |
| 23 | #include <arch/io.h> |
| 24 | #include <cpu/x86/lapic.h> |
| 25 | #include <arch/ioapic.h> |
| 26 | #include <stdlib.h> |
| 27 | #include "hudson.h" |
| 28 | #include "smbus.c" |
| 29 | |
| 30 | #define NMI_OFF 0 |
| 31 | |
| 32 | #define MAINBOARD_POWER_OFF 0 |
| 33 | #define MAINBOARD_POWER_ON 1 |
| 34 | |
| 35 | #ifndef CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL |
| 36 | #define CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL MAINBOARD_POWER_ON |
| 37 | #endif |
| 38 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 39 | /* |
| 40 | * HUDSON enables all USB controllers by default in SMBUS Control. |
| 41 | * HUDSON enables SATA by default in SMBUS Control. |
| 42 | */ |
| 43 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame^] | 44 | static void sm_init(struct device *dev) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 45 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 46 | setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 47 | } |
| 48 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame^] | 49 | static int lsmbus_recv_byte(struct device *dev) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 50 | { |
| 51 | u32 device; |
| 52 | struct resource *res; |
| 53 | struct bus *pbus; |
| 54 | |
| 55 | device = dev->path.i2c.device; |
| 56 | pbus = get_pbus_smbus(dev); |
| 57 | |
| 58 | res = find_resource(pbus->dev, 0x90); |
| 59 | |
| 60 | return do_smbus_recv_byte(res->base, device); |
| 61 | } |
| 62 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame^] | 63 | static int lsmbus_send_byte(struct device *dev, u8 val) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 64 | { |
| 65 | u32 device; |
| 66 | struct resource *res; |
| 67 | struct bus *pbus; |
| 68 | |
| 69 | device = dev->path.i2c.device; |
| 70 | pbus = get_pbus_smbus(dev); |
| 71 | |
| 72 | res = find_resource(pbus->dev, 0x90); |
| 73 | |
| 74 | return do_smbus_send_byte(res->base, device, val); |
| 75 | } |
| 76 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame^] | 77 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 78 | { |
| 79 | u32 device; |
| 80 | struct resource *res; |
| 81 | struct bus *pbus; |
| 82 | |
| 83 | device = dev->path.i2c.device; |
| 84 | pbus = get_pbus_smbus(dev); |
| 85 | |
| 86 | res = find_resource(pbus->dev, 0x90); |
| 87 | |
| 88 | return do_smbus_read_byte(res->base, device, address); |
| 89 | } |
| 90 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame^] | 91 | 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] | 92 | { |
| 93 | u32 device; |
| 94 | struct resource *res; |
| 95 | struct bus *pbus; |
| 96 | |
| 97 | device = dev->path.i2c.device; |
| 98 | pbus = get_pbus_smbus(dev); |
| 99 | |
| 100 | res = find_resource(pbus->dev, 0x90); |
| 101 | |
| 102 | return do_smbus_write_byte(res->base, device, address, val); |
| 103 | } |
| 104 | static struct smbus_bus_operations lops_smbus_bus = { |
| 105 | .recv_byte = lsmbus_recv_byte, |
| 106 | .send_byte = lsmbus_send_byte, |
| 107 | .read_byte = lsmbus_read_byte, |
| 108 | .write_byte = lsmbus_write_byte, |
| 109 | }; |
| 110 | |
Elyes HAOUAS | d9ef546 | 2018-05-19 17:08:23 +0200 | [diff] [blame^] | 111 | static void hudson_sm_read_resources(struct device *dev) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 112 | { |
| 113 | } |
| 114 | |
| 115 | static void hudson_sm_set_resources(struct device *dev) |
| 116 | { |
| 117 | } |
| 118 | |
| 119 | static struct pci_operations lops_pci = { |
| 120 | .set_subsystem = pci_dev_set_subsystem, |
| 121 | }; |
| 122 | static struct device_operations smbus_ops = { |
| 123 | .read_resources = hudson_sm_read_resources, |
| 124 | .set_resources = hudson_sm_set_resources, |
| 125 | .enable_resources = pci_dev_enable_resources, |
| 126 | .init = sm_init, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 127 | .scan_bus = scan_smbus, |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 128 | .ops_pci = &lops_pci, |
| 129 | .ops_smbus_bus = &lops_smbus_bus, |
| 130 | }; |
| 131 | static const struct pci_driver smbus_driver __pci_driver = { |
| 132 | .ops = &smbus_ops, |
| 133 | .vendor = PCI_VENDOR_ID_AMD, |
Kyösti Mälkki | 9d9a552 | 2016-11-19 22:14:59 +0200 | [diff] [blame] | 134 | .device = PCI_DEVICE_ID_AMD_SB900_SM, |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 135 | }; |