blob: fd36a6fcf18eda268dc952fd1876fa134651cadc [file] [log] [blame]
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03001/*
2 * This file is part of the coreboot project.
3 *
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03004 *
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älkkie8b4da22014-10-21 18:22:32 +030013 */
14
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030015#include <device/device.h>
16#include <device/pci.h>
17#include <device/pci_ids.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030018#include <device/smbus.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030019#include <cpu/x86/lapic.h>
20#include <arch/ioapic.h>
Elyes HAOUAS400f9ca2019-06-23 07:01:22 +020021
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030022#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älkkie8b4da22014-10-21 18:22:32 +030030/*
31* HUDSON enables all USB controllers by default in SMBUS Control.
32* HUDSON enables SATA by default in SMBUS Control.
33*/
34
Elyes HAOUASd9ef5462018-05-19 17:08:23 +020035static void sm_init(struct device *dev)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030036{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080037 setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030038}
39
Elyes HAOUASd9ef5462018-05-19 17:08:23 +020040static int lsmbus_recv_byte(struct device *dev)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030041{
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 HAOUASd9ef5462018-05-19 17:08:23 +020054static int lsmbus_send_byte(struct device *dev, u8 val)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030055{
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 HAOUASd9ef5462018-05-19 17:08:23 +020068static int lsmbus_read_byte(struct device *dev, u8 address)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030069{
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 HAOUASd9ef5462018-05-19 17:08:23 +020082static int lsmbus_write_byte(struct device *dev, u8 address, u8 val)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030083{
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}
95static 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 HAOUASd9ef5462018-05-19 17:08:23 +0200102static void hudson_sm_read_resources(struct device *dev)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300103{
104}
105
106static void hudson_sm_set_resources(struct device *dev)
107{
108}
109
110static struct pci_operations lops_pci = {
111 .set_subsystem = pci_dev_set_subsystem,
112};
113static 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älkkid0e212c2015-02-26 20:47:47 +0200118 .scan_bus = scan_smbus,
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300119 .ops_pci = &lops_pci,
120 .ops_smbus_bus = &lops_smbus_bus,
121};
122static const struct pci_driver smbus_driver __pci_driver = {
123 .ops = &smbus_ops,
124 .vendor = PCI_VENDOR_ID_AMD,
Kyösti Mälkki9d9a5522016-11-19 22:14:59 +0200125 .device = PCI_DEVICE_ID_AMD_SB900_SM,
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300126};