blob: b3691555d288f1eaa69f2a347c3fea1cf4f0f50a [file] [log] [blame]
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03001/*
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älkkie8b4da22014-10-21 18:22:32 +030014 */
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älkkie8b4da22014-10-21 18:22:32 +030039/*
40* HUDSON enables all USB controllers by default in SMBUS Control.
41* HUDSON enables SATA by default in SMBUS Control.
42*/
43
Elyes HAOUASd9ef5462018-05-19 17:08:23 +020044static void sm_init(struct device *dev)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030045{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080046 setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030047}
48
Elyes HAOUASd9ef5462018-05-19 17:08:23 +020049static int lsmbus_recv_byte(struct device *dev)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030050{
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 HAOUASd9ef5462018-05-19 17:08:23 +020063static int lsmbus_send_byte(struct device *dev, u8 val)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030064{
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 HAOUASd9ef5462018-05-19 17:08:23 +020077static int lsmbus_read_byte(struct device *dev, u8 address)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030078{
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 HAOUASd9ef5462018-05-19 17:08:23 +020091static int lsmbus_write_byte(struct device *dev, u8 address, u8 val)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030092{
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}
104static 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 HAOUASd9ef5462018-05-19 17:08:23 +0200111static void hudson_sm_read_resources(struct device *dev)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300112{
113}
114
115static void hudson_sm_set_resources(struct device *dev)
116{
117}
118
119static struct pci_operations lops_pci = {
120 .set_subsystem = pci_dev_set_subsystem,
121};
122static 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älkkid0e212c2015-02-26 20:47:47 +0200127 .scan_bus = scan_smbus,
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300128 .ops_pci = &lops_pci,
129 .ops_smbus_bus = &lops_smbus_bus,
130};
131static const struct pci_driver smbus_driver __pci_driver = {
132 .ops = &smbus_ops,
133 .vendor = PCI_VENDOR_ID_AMD,
Kyösti Mälkki9d9a5522016-11-19 22:14:59 +0200134 .device = PCI_DEVICE_ID_AMD_SB900_SM,
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300135};