blob: 07646c862cff62065d8ab3ccd68f9547043f4a4b [file] [log] [blame]
zbao246e84b2012-07-13 18:47:03 +08001/*
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.
zbao246e84b2012-07-13 18:47:03 +080014 */
15
zbao246e84b2012-07-13 18:47:03 +080016#include <device/device.h>
17#include <device/pci.h>
18#include <device/pci_ids.h>
zbao246e84b2012-07-13 18:47:03 +080019#include <device/smbus.h>
zbao246e84b2012-07-13 18:47:03 +080020#include <cpu/x86/lapic.h>
21#include <arch/ioapic.h>
Elyes HAOUAS400f9ca2019-06-23 07:01:22 +020022
zbao246e84b2012-07-13 18:47:03 +080023#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
zbao246e84b2012-07-13 18:47:03 +080031#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 HAOUASa342f392018-10-17 10:56:26 +020040#define BIT8 (1 << 8)
41#define BIT9 (1 << 9)
zbao246e84b2012-07-13 18:47:03 +080042#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 HAOUASa93e7542018-05-19 14:30:47 +020071static void sm_init(struct device *dev)
zbao246e84b2012-07-13 18:47:03 +080072{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080073 setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS);
zbao246e84b2012-07-13 18:47:03 +080074}
75
Elyes HAOUASa93e7542018-05-19 14:30:47 +020076static int lsmbus_recv_byte(struct device *dev)
zbao246e84b2012-07-13 18:47:03 +080077{
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 HAOUASa93e7542018-05-19 14:30:47 +020090static int lsmbus_send_byte(struct device *dev, u8 val)
zbao246e84b2012-07-13 18:47:03 +080091{
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 HAOUASa93e7542018-05-19 14:30:47 +0200104static int lsmbus_read_byte(struct device *dev, u8 address)
zbao246e84b2012-07-13 18:47:03 +0800105{
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 HAOUASa93e7542018-05-19 14:30:47 +0200118static int lsmbus_write_byte(struct device *dev, u8 address, u8 val)
zbao246e84b2012-07-13 18:47:03 +0800119{
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}
131static 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 HAOUASa93e7542018-05-19 14:30:47 +0200138static void hudson_sm_read_resources(struct device *dev)
zbao246e84b2012-07-13 18:47:03 +0800139{
140}
141
142static void hudson_sm_set_resources(struct device *dev)
143{
144}
145
146static struct pci_operations lops_pci = {
147 .set_subsystem = pci_dev_set_subsystem,
148};
149static 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älkkid0e212c2015-02-26 20:47:47 +0200154 .scan_bus = scan_smbus,
zbao246e84b2012-07-13 18:47:03 +0800155 .ops_pci = &lops_pci,
156 .ops_smbus_bus = &lops_smbus_bus,
157};
158static const struct pci_driver smbus_driver __pci_driver = {
159 .ops = &smbus_ops,
160 .vendor = PCI_VENDOR_ID_AMD,
Kyösti Mälkki9d9a5522016-11-19 22:14:59 +0200161 .device = PCI_DEVICE_ID_AMD_SB900_SM,
zbao246e84b2012-07-13 18:47:03 +0800162};