blob: 591ba66d5d3c322e41085c0e09b5d99e93cb5ce7 [file] [log] [blame]
Uwe Hermannb80dbf02007-04-22 19:08:13 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Uwe Hermannb80dbf02007-04-22 19:08:13 +00003 *
4 * Copyright (C) 2003-2004 Linux Networx
5 * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
6 * Copyright (C) 2003 Ronald G. Minnich <rminnich@gmail.com>
7 * Copyright (C) 2004-2005 Li-Ta Lo <ollie@lanl.gov>
8 * Copyright (C) 2005 Tyan
9 * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
Eric Biedermane9a271e32003-09-02 03:36:25 +000025#include <console/console.h>
26#include <device/device.h>
27#include <device/pci.h>
Stefan Reinauerde3206a2010-02-22 06:09:43 +000028#include <reset.h>
Eric Biedermane9a271e32003-09-02 03:36:25 +000029
Stefan Reinauer14e22772010-04-27 06:56:47 +000030/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +000031 * Read the resources for the root device, that encompass the resources for
32 * the entire system.
33 *
34 * @param root Pointer to the device structure for the system root device.
Eric Biedermane9a271e32003-09-02 03:36:25 +000035 */
Myles Watson7eac4452010-06-17 16:16:56 +000036static void root_dev_read_resources(device_t root)
Eric Biedermane9a271e32003-09-02 03:36:25 +000037{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000038 printk(BIOS_ERR, "%s should never be called.\n", __func__);
Eric Biedermane9a271e32003-09-02 03:36:25 +000039}
40
41/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +000042 * Write the resources for every device.
Li-Ta Lo04930692004-11-25 17:37:19 +000043 *
Uwe Hermannc1ee4292010-10-17 19:01:48 +000044 * Write the resources for the root device, and every device under it which
45 * are all of the devices.
46 *
47 * @param root Pointer to the device structure for the system root device.
Eric Biedermane9a271e32003-09-02 03:36:25 +000048 */
Myles Watson7eac4452010-06-17 16:16:56 +000049static void root_dev_set_resources(device_t root)
Eric Biedermane9a271e32003-09-02 03:36:25 +000050{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000051 printk(BIOS_ERR, "%s should never be called.\n", __func__);
Eric Biedermane9a271e32003-09-02 03:36:25 +000052}
53
54/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +000055 * Scan devices on static buses.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000056 *
Li-Ta Lo9f0d0f92004-05-10 16:05:16 +000057 * The enumeration of certain buses is purely static. The existence of
58 * devices on those buses can be completely determined at compile time
Stefan Reinauer14e22772010-04-27 06:56:47 +000059 * and is specified in the config file. Typical examples are the 'PNP'
60 * devices on a legacy ISA/LPC bus. There is no need of probing of any kind,
61 * the only thing we have to do is to walk through the bus and
Li-Ta Lo04930692004-11-25 17:37:19 +000062 * enable or disable devices as indicated in the config file.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000063 *
Li-Ta Lo04930692004-11-25 17:37:19 +000064 * On the other hand, some devices are virtual and their existence is
65 * artificial. They can not be probed at run time. One example is the
66 * debug device. Those virtual devices have to be listed in the config
67 * file under some static bus in order to be enumerated at run time.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000068 *
Li-Ta Lo04930692004-11-25 17:37:19 +000069 * This function is the default scan_bus() method for the root device and
70 * LPC bridges.
71 *
Uwe Hermannc1ee4292010-10-17 19:01:48 +000072 * @param bus Pointer to the device to which the static buses are attached to.
73 * @param max Maximum bus number currently used before scanning.
Uwe Hermannd453dd02010-10-18 00:00:57 +000074 * @return The largest bus number used.
Eric Biedermane9a271e32003-09-02 03:36:25 +000075 */
arch import user (historical)98d0d302005-07-06 17:13:46 +000076static int smbus_max = 0;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000077unsigned int scan_static_bus(device_t bus, unsigned int max)
Eric Biedermane9a271e32003-09-02 03:36:25 +000078{
79 device_t child;
Uwe Hermannd453dd02010-10-18 00:00:57 +000080 struct bus *link;
Li-Ta Loe5266692004-03-23 21:28:05 +000081
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000082 printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
Li-Ta Lo04930692004-11-25 17:37:19 +000083
Uwe Hermannd453dd02010-10-18 00:00:57 +000084 for (link = bus->link_list; link; link = link->next) {
85 /* For SMBus bus enumerate. */
Myles Watson894a3472010-06-09 22:41:35 +000086 child = link->children;
Uwe Hermannd453dd02010-10-18 00:00:57 +000087
88 if (child && child->path.type == DEVICE_PATH_I2C)
Myles Watson894a3472010-06-09 22:41:35 +000089 link->secondary = ++smbus_max;
Uwe Hermannd453dd02010-10-18 00:00:57 +000090
91 for (child = link->children; child; child = child->sibling) {
92 if (child->chip_ops && child->chip_ops->enable_dev)
Eric Biederman7003ba42004-10-16 06:20:29 +000093 child->chip_ops->enable_dev(child);
Uwe Hermannd453dd02010-10-18 00:00:57 +000094
95 if (child->ops && child->ops->enable)
Eric Biedermane9a271e32003-09-02 03:36:25 +000096 child->ops->enable(child);
Uwe Hermannd453dd02010-10-18 00:00:57 +000097
98 if (child->path.type == DEVICE_PATH_I2C) {
99 printk(BIOS_DEBUG, "smbus: %s[%d]->",
100 dev_path(child->bus->dev),
101 child->bus->link_num);
Eric Biedermane9a271e32003-09-02 03:36:25 +0000102 }
Uwe Hermannd453dd02010-10-18 00:00:57 +0000103 printk(BIOS_DEBUG, "%s %s\n", dev_path(child),
104 child->enabled ? "enabled" : "disabled");
Eric Biedermane9a271e32003-09-02 03:36:25 +0000105 }
106 }
Uwe Hermannd453dd02010-10-18 00:00:57 +0000107
108 for (link = bus->link_list; link; link = link->next) {
109 for (child = link->children; child; child = child->sibling) {
Eric Biedermane9a271e32003-09-02 03:36:25 +0000110 if (!child->ops || !child->ops->scan_bus)
111 continue;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000112 printk(BIOS_SPEW, "%s scanning...\n", dev_path(child));
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000113 max = scan_bus(child, max);
Eric Biedermane9a271e32003-09-02 03:36:25 +0000114 }
115 }
Li-Ta Lofb4c50f2004-05-07 21:52:47 +0000116
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000117 printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
Li-Ta Lofb4c50f2004-05-07 21:52:47 +0000118
Eric Biedermane9a271e32003-09-02 03:36:25 +0000119 return max;
120}
121
Myles Watson7eac4452010-06-17 16:16:56 +0000122static void root_dev_enable_resources(device_t dev)
Eric Biedermane9a271e32003-09-02 03:36:25 +0000123{
Eric Biederman03acab62004-10-14 21:25:53 +0000124}
125
Li-Ta Lo9782f752004-05-05 21:15:42 +0000126/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000127 * Scan root bus for generic systems.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000128 *
Li-Ta Lo04930692004-11-25 17:37:19 +0000129 * This function is the default scan_bus() method of the root device.
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000130 *
131 * @param root The root device structure.
132 * @param max The current bus number scanned so far, usually 0x00.
Uwe Hermannd453dd02010-10-18 00:00:57 +0000133 * @return The largest bus number used.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000134 */
Myles Watson7eac4452010-06-17 16:16:56 +0000135static unsigned int root_dev_scan_bus(device_t root, unsigned int max)
Eric Biedermane9a271e32003-09-02 03:36:25 +0000136{
Eric Biederman03acab62004-10-14 21:25:53 +0000137 return scan_static_bus(root, max);
138}
139
Myles Watson7eac4452010-06-17 16:16:56 +0000140static void root_dev_init(device_t root)
Eric Biederman03acab62004-10-14 21:25:53 +0000141{
Eric Biedermane9a271e32003-09-02 03:36:25 +0000142}
143
Myles Watson7eac4452010-06-17 16:16:56 +0000144static void root_dev_reset(struct bus *bus)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000145{
Uwe Hermannd453dd02010-10-18 00:00:57 +0000146 printk(BIOS_INFO, "Resetting board...\n");
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000147 hard_reset();
148}
149
Li-Ta Lo9782f752004-05-05 21:15:42 +0000150/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000151 * Default device operation for root device.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000152 *
Li-Ta Lo04930692004-11-25 17:37:19 +0000153 * This is the default device operation for root devices. These operations
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000154 * should be fully usable as is. However the chip_operations::enable_dev()
Li-Ta Lo04930692004-11-25 17:37:19 +0000155 * of a motherboard can override this if you want non-default behavior.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000156 */
Eric Biedermane9a271e32003-09-02 03:36:25 +0000157struct device_operations default_dev_ops_root = {
158 .read_resources = root_dev_read_resources,
159 .set_resources = root_dev_set_resources,
Eric Biederman03acab62004-10-14 21:25:53 +0000160 .enable_resources = root_dev_enable_resources,
161 .init = root_dev_init,
162 .scan_bus = root_dev_scan_bus,
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000163 .reset_bus = root_dev_reset,
Eric Biedermane9a271e32003-09-02 03:36:25 +0000164};