blob: ec10a41647615e7bbc5b763b51e160a9b4cdae70 [file] [log] [blame]
zbao246e84b2012-07-13 18:47:03 +08001/*
2 * This file is part of the coreboot project.
3 *
zbao246e84b2012-07-13 18:47:03 +08004 *
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.
zbao246e84b2012-07-13 18:47:03 +080013 */
14
zbao246e84b2012-07-13 18:47:03 +080015#include <device/device.h>
16#include <device/pci.h>
17#include <device/pci_ids.h>
zbao246e84b2012-07-13 18:47:03 +080018#include <device/smbus.h>
zbao246e84b2012-07-13 18:47:03 +080019#include <cpu/x86/lapic.h>
20#include <arch/ioapic.h>
Elyes HAOUAS400f9ca2019-06-23 07:01:22 +020021
zbao246e84b2012-07-13 18:47:03 +080022#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
zbao246e84b2012-07-13 18:47:03 +080030#define BIT0 (1 << 0)
31#define BIT1 (1 << 1)
32#define BIT2 (1 << 2)
33#define BIT3 (1 << 3)
34#define BIT4 (1 << 4)
35#define BIT5 (1 << 5)
36#define BIT6 (1 << 6)
37#define BIT7 (1 << 7)
38
Elyes HAOUASa342f392018-10-17 10:56:26 +020039#define BIT8 (1 << 8)
40#define BIT9 (1 << 9)
zbao246e84b2012-07-13 18:47:03 +080041#define BIT10 (1 << 10)
42#define BIT11 (1 << 11)
43#define BIT12 (1 << 12)
44#define BIT13 (1 << 13)
45#define BIT14 (1 << 14)
46#define BIT15 (1 << 15)
47
48#define BIT16 (1 << 16)
49#define BIT17 (1 << 17)
50#define BIT18 (1 << 18)
51#define BIT19 (1 << 19)
52#define BIT20 (1 << 20)
53#define BIT21 (1 << 21)
54#define BIT22 (1 << 22)
55#define BIT23 (1 << 23)
56#define BIT24 (1 << 24)
57#define BIT25 (1 << 25)
58#define BIT26 (1 << 26)
59#define BIT27 (1 << 27)
60#define BIT28 (1 << 28)
61#define BIT29 (1 << 29)
62#define BIT30 (1 << 30)
63#define BIT31 (1 << 31)
64
65/*
66* HUDSON enables all USB controllers by default in SMBUS Control.
67* HUDSON enables SATA by default in SMBUS Control.
68*/
69
Elyes HAOUASa93e7542018-05-19 14:30:47 +020070static void sm_init(struct device *dev)
zbao246e84b2012-07-13 18:47:03 +080071{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080072 setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS);
zbao246e84b2012-07-13 18:47:03 +080073}
74
Elyes HAOUASa93e7542018-05-19 14:30:47 +020075static int lsmbus_recv_byte(struct device *dev)
zbao246e84b2012-07-13 18:47:03 +080076{
77 u32 device;
78 struct resource *res;
79 struct bus *pbus;
80
81 device = dev->path.i2c.device;
82 pbus = get_pbus_smbus(dev);
83
84 res = find_resource(pbus->dev, 0x90);
85
86 return do_smbus_recv_byte(res->base, device);
87}
88
Elyes HAOUASa93e7542018-05-19 14:30:47 +020089static int lsmbus_send_byte(struct device *dev, u8 val)
zbao246e84b2012-07-13 18:47:03 +080090{
91 u32 device;
92 struct resource *res;
93 struct bus *pbus;
94
95 device = dev->path.i2c.device;
96 pbus = get_pbus_smbus(dev);
97
98 res = find_resource(pbus->dev, 0x90);
99
100 return do_smbus_send_byte(res->base, device, val);
101}
102
Elyes HAOUASa93e7542018-05-19 14:30:47 +0200103static int lsmbus_read_byte(struct device *dev, u8 address)
zbao246e84b2012-07-13 18:47:03 +0800104{
105 u32 device;
106 struct resource *res;
107 struct bus *pbus;
108
109 device = dev->path.i2c.device;
110 pbus = get_pbus_smbus(dev);
111
112 res = find_resource(pbus->dev, 0x90);
113
114 return do_smbus_read_byte(res->base, device, address);
115}
116
Elyes HAOUASa93e7542018-05-19 14:30:47 +0200117static int lsmbus_write_byte(struct device *dev, u8 address, u8 val)
zbao246e84b2012-07-13 18:47:03 +0800118{
119 u32 device;
120 struct resource *res;
121 struct bus *pbus;
122
123 device = dev->path.i2c.device;
124 pbus = get_pbus_smbus(dev);
125
126 res = find_resource(pbus->dev, 0x90);
127
128 return do_smbus_write_byte(res->base, device, address, val);
129}
130static struct smbus_bus_operations lops_smbus_bus = {
131 .recv_byte = lsmbus_recv_byte,
132 .send_byte = lsmbus_send_byte,
133 .read_byte = lsmbus_read_byte,
134 .write_byte = lsmbus_write_byte,
135};
136
Elyes HAOUASa93e7542018-05-19 14:30:47 +0200137static void hudson_sm_read_resources(struct device *dev)
zbao246e84b2012-07-13 18:47:03 +0800138{
139}
140
141static void hudson_sm_set_resources(struct device *dev)
142{
143}
144
145static struct pci_operations lops_pci = {
146 .set_subsystem = pci_dev_set_subsystem,
147};
148static struct device_operations smbus_ops = {
149 .read_resources = hudson_sm_read_resources,
150 .set_resources = hudson_sm_set_resources,
151 .enable_resources = pci_dev_enable_resources,
152 .init = sm_init,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200153 .scan_bus = scan_smbus,
zbao246e84b2012-07-13 18:47:03 +0800154 .ops_pci = &lops_pci,
155 .ops_smbus_bus = &lops_smbus_bus,
156};
157static const struct pci_driver smbus_driver __pci_driver = {
158 .ops = &smbus_ops,
159 .vendor = PCI_VENDOR_ID_AMD,
Kyösti Mälkki9d9a5522016-11-19 22:14:59 +0200160 .device = PCI_DEVICE_ID_AMD_SB900_SM,
zbao246e84b2012-07-13 18:47:03 +0800161};