blob: 640ea505d4ed4f425a1f6d9bb2fcbb202c9c4271 [file] [log] [blame]
Angel Ponsc74dae92020-04-02 23:48:16 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Uwe Hermannb80dbf02007-04-22 19:08:13 +00002
Eric Biedermane9a271e32003-09-02 03:36:25 +00003#include <console/console.h>
4#include <device/device.h>
5#include <device/pci.h>
Stefan Reinauerde3206a2010-02-22 06:09:43 +00006#include <reset.h>
Eric Biedermane9a271e32003-09-02 03:36:25 +00007
Kyösti Mälkkia93c3fe2012-10-09 22:28:56 +03008const char mainboard_name[] = CONFIG_MAINBOARD_VENDOR " " CONFIG_MAINBOARD_PART_NUMBER;
9
Stefan Reinauer14e22772010-04-27 06:56:47 +000010/**
Nico Huberf7ed3d42019-03-14 15:50:06 +010011 * Enable devices on static buses.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000012 *
Li-Ta Lo9f0d0f92004-05-10 16:05:16 +000013 * The enumeration of certain buses is purely static. The existence of
14 * devices on those buses can be completely determined at compile time
Stefan Reinauer14e22772010-04-27 06:56:47 +000015 * and is specified in the config file. Typical examples are the 'PNP'
16 * devices on a legacy ISA/LPC bus. There is no need of probing of any kind,
17 * the only thing we have to do is to walk through the bus and
Li-Ta Lo04930692004-11-25 17:37:19 +000018 * enable or disable devices as indicated in the config file.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000019 *
Li-Ta Lo04930692004-11-25 17:37:19 +000020 * On the other hand, some devices are virtual and their existence is
21 * artificial. They can not be probed at run time. One example is the
22 * debug device. Those virtual devices have to be listed in the config
23 * file under some static bus in order to be enumerated at run time.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000024 *
Uwe Hermannc1ee4292010-10-17 19:01:48 +000025 * @param bus Pointer to the device to which the static buses are attached to.
Eric Biedermane9a271e32003-09-02 03:36:25 +000026 */
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020027
Nico Huberf7ed3d42019-03-14 15:50:06 +010028void enable_static_devices(struct device *bus)
Eric Biedermane9a271e32003-09-02 03:36:25 +000029{
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020030 struct device *child;
Uwe Hermannd453dd02010-10-18 00:00:57 +000031 struct bus *link;
Li-Ta Loe5266692004-03-23 21:28:05 +000032
Uwe Hermannd453dd02010-10-18 00:00:57 +000033 for (link = bus->link_list; link; link = link->next) {
Uwe Hermannd453dd02010-10-18 00:00:57 +000034 for (child = link->children; child; child = child->sibling) {
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020035
Uwe Hermannd453dd02010-10-18 00:00:57 +000036 if (child->chip_ops && child->chip_ops->enable_dev)
Eric Biederman7003ba42004-10-16 06:20:29 +000037 child->chip_ops->enable_dev(child);
Uwe Hermannd453dd02010-10-18 00:00:57 +000038
39 if (child->ops && child->ops->enable)
Eric Biedermane9a271e32003-09-02 03:36:25 +000040 child->ops->enable(child);
Uwe Hermannd453dd02010-10-18 00:00:57 +000041
Uwe Hermannd453dd02010-10-18 00:00:57 +000042 printk(BIOS_DEBUG, "%s %s\n", dev_path(child),
43 child->enabled ? "enabled" : "disabled");
Eric Biedermane9a271e32003-09-02 03:36:25 +000044 }
45 }
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020046}
47
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020048void scan_generic_bus(struct device *bus)
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020049{
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020050 struct device *child;
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020051 struct bus *link;
Furquan Shaikh4e084792017-02-13 13:22:19 -080052 static int bus_max = 0;
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020053
54 printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
55
Uwe Hermannd453dd02010-10-18 00:00:57 +000056 for (link = bus->link_list; link; link = link->next) {
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020057
Furquan Shaikh4e084792017-02-13 13:22:19 -080058 link->secondary = ++bus_max;
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020059
Uwe Hermannd453dd02010-10-18 00:00:57 +000060 for (child = link->children; child; child = child->sibling) {
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020061
62 if (child->chip_ops && child->chip_ops->enable_dev)
63 child->chip_ops->enable_dev(child);
64
65 if (child->ops && child->ops->enable)
66 child->ops->enable(child);
67
Furquan Shaikh4e084792017-02-13 13:22:19 -080068 printk(BIOS_DEBUG, "bus: %s[%d]->", dev_path(child->bus->dev),
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020069 child->bus->link_num);
70
71 printk(BIOS_DEBUG, "%s %s\n", dev_path(child),
72 child->enabled ? "enabled" : "disabled");
Eric Biedermane9a271e32003-09-02 03:36:25 +000073 }
74 }
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000075
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000076 printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
Eric Biedermane9a271e32003-09-02 03:36:25 +000077}
78
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020079void scan_smbus(struct device *bus)
Furquan Shaikh4e084792017-02-13 13:22:19 -080080{
81 scan_generic_bus(bus);
82}
83
Nico Hubera89c82e2017-09-14 15:40:28 +020084/*
85 * Default scan_bus() implementation
Li-Ta Lo9782f752004-05-05 21:15:42 +000086 *
Nico Hubera89c82e2017-09-14 15:40:28 +020087 * This is the default implementation for buses that can't
88 * be probed at runtime. It simply walks through the topology
89 * given by the mainboard's `devicetree.cb`.
Uwe Hermannc1ee4292010-10-17 19:01:48 +000090 *
Nico Hubera89c82e2017-09-14 15:40:28 +020091 * First, all direct descendants of the given device are
92 * enabled. Then, downstream buses are scanned.
Li-Ta Lo9782f752004-05-05 21:15:42 +000093 */
Nico Hubera89c82e2017-09-14 15:40:28 +020094void scan_static_bus(struct device *bus)
Eric Biedermane9a271e32003-09-02 03:36:25 +000095{
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020096 struct bus *link;
97
98 printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
99
Nico Huberf7ed3d42019-03-14 15:50:06 +0100100 enable_static_devices(bus);
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200101
Kyösti Mälkki2d2367c2015-02-20 21:28:31 +0200102 for (link = bus->link_list; link; link = link->next)
103 scan_bridges(link);
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200104
105 printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
Eric Biederman03acab62004-10-14 21:25:53 +0000106}
107
Myles Watson7eac4452010-06-17 16:16:56 +0000108static void root_dev_reset(struct bus *bus)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000109{
Uwe Hermannd453dd02010-10-18 00:00:57 +0000110 printk(BIOS_INFO, "Resetting board...\n");
Nico Huber4f32b642018-10-05 23:40:21 +0200111 board_reset();
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000112}
113
Julius Wernercd49cce2019-03-05 16:53:33 -0800114#if CONFIG(HAVE_ACPI_TABLES)
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600115static const char *root_dev_acpi_name(const struct device *dev)
Duncan Lauried9af3ce2016-05-08 18:15:25 -0700116{
117 return "\\_SB";
118}
119#endif
120
Li-Ta Lo9782f752004-05-05 21:15:42 +0000121/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000122 * Default device operation for root device.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000123 *
Li-Ta Lo04930692004-11-25 17:37:19 +0000124 * This is the default device operation for root devices. These operations
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000125 * should be fully usable as is. However the chip_operations::enable_dev()
Li-Ta Lo04930692004-11-25 17:37:19 +0000126 * of a motherboard can override this if you want non-default behavior.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000127 */
Eric Biedermane9a271e32003-09-02 03:36:25 +0000128struct device_operations default_dev_ops_root = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200129 .read_resources = noop_read_resources,
130 .set_resources = noop_set_resources,
Nico Hubera89c82e2017-09-14 15:40:28 +0200131 .scan_bus = scan_static_bus,
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000132 .reset_bus = root_dev_reset,
Julius Wernercd49cce2019-03-05 16:53:33 -0800133#if CONFIG(HAVE_ACPI_TABLES)
Duncan Lauried9af3ce2016-05-08 18:15:25 -0700134 .acpi_name = root_dev_acpi_name,
135#endif
Eric Biedermane9a271e32003-09-02 03:36:25 +0000136};