1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
7 #define LOG_CATEGORY UCLASS_CPU
16 #include <linux/err.h>
18 int cpu_probe_all(void)
23 ret = uclass_first_device(UCLASS_CPU, &cpu);
25 debug("%s: No CPU found (err = %d)\n", __func__, ret);
30 ret = uclass_next_device(&cpu);
32 debug("%s: Error while probing CPU (err = %d)\n",
41 int cpu_is_current(struct udevice *cpu)
43 struct cpu_ops *ops = cpu_get_ops(cpu);
45 if (ops->is_current) {
46 if (ops->is_current(cpu))
53 struct udevice *cpu_get_current_dev(void)
58 uclass_foreach_dev_probe(UCLASS_CPU, cpu) {
59 if (cpu_is_current(cpu) > 0)
63 /* If can't find current cpu device, use the first dev instead */
64 ret = uclass_first_device_err(UCLASS_CPU, &cpu);
66 debug("%s: Could not get CPU device (err = %d)\n",
74 int cpu_get_desc(const struct udevice *dev, char *buf, int size)
76 struct cpu_ops *ops = cpu_get_ops(dev);
81 return ops->get_desc(dev, buf, size);
84 int cpu_get_info(const struct udevice *dev, struct cpu_info *info)
86 struct cpu_ops *ops = cpu_get_ops(dev);
91 /* Init cpu_info to 0 */
92 memset(info, 0, sizeof(struct cpu_info));
94 return ops->get_info(dev, info);
97 int cpu_get_count(const struct udevice *dev)
99 struct cpu_ops *ops = cpu_get_ops(dev);
104 return ops->get_count(dev);
107 int cpu_get_vendor(const struct udevice *dev, char *buf, int size)
109 struct cpu_ops *ops = cpu_get_ops(dev);
111 if (!ops->get_vendor)
114 return ops->get_vendor(dev, buf, size);
117 U_BOOT_DRIVER(cpu_bus) = {
119 .id = UCLASS_SIMPLE_BUS,
120 .per_child_plat_auto = sizeof(struct cpu_plat),
123 static int uclass_cpu_init(struct uclass *uc)
129 node = ofnode_path("/cpus");
130 if (!ofnode_valid(node))
133 ret = device_bind_driver_to_node(dm_root(), "cpu_bus", "cpus", node,
139 UCLASS_DRIVER(cpu) = {
142 .flags = DM_UC_FLAG_SEQ_ALIAS,
143 .init = uclass_cpu_init,