blob: 6b961005f91388e5355a7aaac2d447e0ad347d1a [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.
Uwe Hermannb80dbf02007-04-22 19:08:13 +000019 */
20
Eric Biedermane9a271e32003-09-02 03:36:25 +000021#include <console/console.h>
22#include <device/device.h>
23#include <device/pci.h>
Stefan Reinauerde3206a2010-02-22 06:09:43 +000024#include <reset.h>
Eric Biedermane9a271e32003-09-02 03:36:25 +000025
Kyösti Mälkkia93c3fe2012-10-09 22:28:56 +030026const char mainboard_name[] = CONFIG_MAINBOARD_VENDOR " " CONFIG_MAINBOARD_PART_NUMBER;
27
Stefan Reinauer14e22772010-04-27 06:56:47 +000028/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +000029 * Scan devices on static buses.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000030 *
Li-Ta Lo9f0d0f92004-05-10 16:05:16 +000031 * The enumeration of certain buses is purely static. The existence of
32 * devices on those buses can be completely determined at compile time
Stefan Reinauer14e22772010-04-27 06:56:47 +000033 * and is specified in the config file. Typical examples are the 'PNP'
34 * devices on a legacy ISA/LPC bus. There is no need of probing of any kind,
35 * the only thing we have to do is to walk through the bus and
Li-Ta Lo04930692004-11-25 17:37:19 +000036 * enable or disable devices as indicated in the config file.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000037 *
Li-Ta Lo04930692004-11-25 17:37:19 +000038 * On the other hand, some devices are virtual and their existence is
39 * artificial. They can not be probed at run time. One example is the
40 * debug device. Those virtual devices have to be listed in the config
41 * file under some static bus in order to be enumerated at run time.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000042 *
Uwe Hermannc1ee4292010-10-17 19:01:48 +000043 * @param bus Pointer to the device to which the static buses are attached to.
Eric Biedermane9a271e32003-09-02 03:36:25 +000044 */
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020045
Kyösti Mälkki580e7222015-03-19 21:04:23 +020046static void scan_static_bus(device_t bus)
Eric Biedermane9a271e32003-09-02 03:36:25 +000047{
48 device_t child;
Uwe Hermannd453dd02010-10-18 00:00:57 +000049 struct bus *link;
Li-Ta Loe5266692004-03-23 21:28:05 +000050
Uwe Hermannd453dd02010-10-18 00:00:57 +000051 for (link = bus->link_list; link; link = link->next) {
Uwe Hermannd453dd02010-10-18 00:00:57 +000052 for (child = link->children; child; child = child->sibling) {
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020053
Uwe Hermannd453dd02010-10-18 00:00:57 +000054 if (child->chip_ops && child->chip_ops->enable_dev)
Eric Biederman7003ba42004-10-16 06:20:29 +000055 child->chip_ops->enable_dev(child);
Uwe Hermannd453dd02010-10-18 00:00:57 +000056
57 if (child->ops && child->ops->enable)
Eric Biedermane9a271e32003-09-02 03:36:25 +000058 child->ops->enable(child);
Uwe Hermannd453dd02010-10-18 00:00:57 +000059
Uwe Hermannd453dd02010-10-18 00:00:57 +000060 printk(BIOS_DEBUG, "%s %s\n", dev_path(child),
61 child->enabled ? "enabled" : "disabled");
Eric Biedermane9a271e32003-09-02 03:36:25 +000062 }
63 }
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020064}
65
Kyösti Mälkki580e7222015-03-19 21:04:23 +020066void scan_lpc_bus(device_t bus)
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020067{
68 printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
69
Kyösti Mälkki580e7222015-03-19 21:04:23 +020070 scan_static_bus(bus);
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020071
72 printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020073}
74
Kyösti Mälkki580e7222015-03-19 21:04:23 +020075void scan_smbus(device_t bus)
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020076{
77 device_t child;
78 struct bus *link;
79 static int smbus_max = 0;
80
81 printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
82
Uwe Hermannd453dd02010-10-18 00:00:57 +000083 for (link = bus->link_list; link; link = link->next) {
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020084
85 link->secondary = ++smbus_max;
86
Uwe Hermannd453dd02010-10-18 00:00:57 +000087 for (child = link->children; child; child = child->sibling) {
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020088
89 if (child->chip_ops && child->chip_ops->enable_dev)
90 child->chip_ops->enable_dev(child);
91
92 if (child->ops && child->ops->enable)
93 child->ops->enable(child);
94
95 printk(BIOS_DEBUG, "smbus: %s[%d]->", dev_path(child->bus->dev),
96 child->bus->link_num);
97
98 printk(BIOS_DEBUG, "%s %s\n", dev_path(child),
99 child->enabled ? "enabled" : "disabled");
Eric Biedermane9a271e32003-09-02 03:36:25 +0000100 }
101 }
Li-Ta Lofb4c50f2004-05-07 21:52:47 +0000102
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000103 printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
Eric Biedermane9a271e32003-09-02 03:36:25 +0000104}
105
Li-Ta Lo9782f752004-05-05 21:15:42 +0000106/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000107 * Scan root bus for generic systems.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000108 *
Li-Ta Lo04930692004-11-25 17:37:19 +0000109 * This function is the default scan_bus() method of the root device.
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000110 *
111 * @param root The root device structure.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000112 */
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200113static void root_dev_scan_bus(device_t bus)
Eric Biedermane9a271e32003-09-02 03:36:25 +0000114{
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200115 struct bus *link;
116
117 printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
118
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200119 scan_static_bus(bus);
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200120
Kyösti Mälkki2d2367c2015-02-20 21:28:31 +0200121 for (link = bus->link_list; link; link = link->next)
122 scan_bridges(link);
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200123
124 printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
Eric Biederman03acab62004-10-14 21:25:53 +0000125}
126
Myles Watson7eac4452010-06-17 16:16:56 +0000127static void root_dev_reset(struct bus *bus)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000128{
Uwe Hermannd453dd02010-10-18 00:00:57 +0000129 printk(BIOS_INFO, "Resetting board...\n");
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000130 hard_reset();
131}
132
Li-Ta Lo9782f752004-05-05 21:15:42 +0000133/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000134 * Default device operation for root device.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000135 *
Li-Ta Lo04930692004-11-25 17:37:19 +0000136 * This is the default device operation for root devices. These operations
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000137 * should be fully usable as is. However the chip_operations::enable_dev()
Li-Ta Lo04930692004-11-25 17:37:19 +0000138 * of a motherboard can override this if you want non-default behavior.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000139 */
Eric Biedermane9a271e32003-09-02 03:36:25 +0000140struct device_operations default_dev_ops_root = {
Kyösti Mälkki85756c12015-02-06 09:15:52 +0200141 .read_resources = DEVICE_NOOP,
142 .set_resources = DEVICE_NOOP,
143 .enable_resources = DEVICE_NOOP,
144 .init = DEVICE_NOOP,
Eric Biederman03acab62004-10-14 21:25:53 +0000145 .scan_bus = root_dev_scan_bus,
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000146 .reset_bus = root_dev_reset,
Eric Biedermane9a271e32003-09-02 03:36:25 +0000147};