blob: 70e49858d635e50c20a6df6b9456333fa1f880fc [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03002
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03003#include <device/device.h>
4#include <device/pci.h>
5#include <device/pci_ids.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03006#include <device/smbus.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03007#include <arch/ioapic.h>
Elyes HAOUAS400f9ca2019-06-23 07:01:22 +02008
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03009#include "hudson.h"
10#include "smbus.c"
11
12#define NMI_OFF 0
13
14#define MAINBOARD_POWER_OFF 0
15#define MAINBOARD_POWER_ON 1
16
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030017/*
18* HUDSON enables all USB controllers by default in SMBUS Control.
19* HUDSON enables SATA by default in SMBUS Control.
20*/
21
Kyösti Mälkkie742b682023-04-10 17:03:32 +030022void ioapic_get_sci_pin(u8 *gsi, u8 *irq, u8 *flags)
23{
24 *gsi = ACPI_SCI_IRQ;
25 *irq = ACPI_SCI_IRQ;
26 *flags = MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW;
27}
28
Elyes HAOUASd9ef5462018-05-19 17:08:23 +020029static void sm_init(struct device *dev)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030030{
Felix Held0d192892024-02-06 16:55:29 +010031 register_new_ioapic_gsi0(IO_APIC_ADDR);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030032}
33
Elyes HAOUASd9ef5462018-05-19 17:08:23 +020034static int lsmbus_recv_byte(struct device *dev)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030035{
36 u32 device;
37 struct resource *res;
38 struct bus *pbus;
39
40 device = dev->path.i2c.device;
41 pbus = get_pbus_smbus(dev);
42
43 res = find_resource(pbus->dev, 0x90);
44
45 return do_smbus_recv_byte(res->base, device);
46}
47
Elyes HAOUASd9ef5462018-05-19 17:08:23 +020048static int lsmbus_send_byte(struct device *dev, u8 val)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030049{
50 u32 device;
51 struct resource *res;
52 struct bus *pbus;
53
54 device = dev->path.i2c.device;
55 pbus = get_pbus_smbus(dev);
56
57 res = find_resource(pbus->dev, 0x90);
58
59 return do_smbus_send_byte(res->base, device, val);
60}
61
Elyes HAOUASd9ef5462018-05-19 17:08:23 +020062static int lsmbus_read_byte(struct device *dev, u8 address)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030063{
64 u32 device;
65 struct resource *res;
66 struct bus *pbus;
67
68 device = dev->path.i2c.device;
69 pbus = get_pbus_smbus(dev);
70
71 res = find_resource(pbus->dev, 0x90);
72
73 return do_smbus_read_byte(res->base, device, address);
74}
75
Elyes HAOUASd9ef5462018-05-19 17:08:23 +020076static int lsmbus_write_byte(struct device *dev, u8 address, u8 val)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030077{
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_write_byte(res->base, device, address, val);
88}
89static struct smbus_bus_operations lops_smbus_bus = {
90 .recv_byte = lsmbus_recv_byte,
91 .send_byte = lsmbus_send_byte,
92 .read_byte = lsmbus_read_byte,
93 .write_byte = lsmbus_write_byte,
94};
95
Elyes HAOUASd9ef5462018-05-19 17:08:23 +020096static void hudson_sm_read_resources(struct device *dev)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030097{
98}
99
100static void hudson_sm_set_resources(struct device *dev)
101{
102}
103
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300104static struct device_operations smbus_ops = {
105 .read_resources = hudson_sm_read_resources,
106 .set_resources = hudson_sm_set_resources,
107 .enable_resources = pci_dev_enable_resources,
108 .init = sm_init,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200109 .scan_bus = scan_smbus,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200110 .ops_pci = &pci_dev_ops_pci,
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300111 .ops_smbus_bus = &lops_smbus_bus,
112};
113static const struct pci_driver smbus_driver __pci_driver = {
114 .ops = &smbus_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100115 .vendor = PCI_VID_AMD,
Felix Held43cf27d2021-10-27 18:31:16 +0200116 /* PCI device ID is used on all discrete FCHs and Family 16h Models 00h-3Fh */
Felix Singer43b7f412022-03-07 04:34:52 +0100117 .device = PCI_DID_AMD_SB900_SM,
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300118};