1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
13 #include <linux/err.h>
15 int cpu_probe_all(void)
20 ret = uclass_first_device(UCLASS_CPU, &cpu);
22 debug("%s: No CPU found (err = %d)\n", __func__, ret);
27 ret = uclass_next_device(&cpu);
29 debug("%s: Error while probing CPU (err = %d)\n",
38 int cpu_is_current(struct udevice *cpu)
40 struct cpu_ops *ops = cpu_get_ops(cpu);
42 if (ops->is_current) {
43 if (ops->is_current(cpu))
50 struct udevice *cpu_get_current_dev(void)
55 uclass_foreach_dev_probe(UCLASS_CPU, cpu) {
56 if (cpu_is_current(cpu) > 0)
60 /* If can't find current cpu device, use the first dev instead */
61 ret = uclass_first_device_err(UCLASS_CPU, &cpu);
63 debug("%s: Could not get CPU device (err = %d)\n",
71 int cpu_get_desc(struct udevice *dev, char *buf, int size)
73 struct cpu_ops *ops = cpu_get_ops(dev);
78 return ops->get_desc(dev, buf, size);
81 int cpu_get_info(struct udevice *dev, struct cpu_info *info)
83 struct cpu_ops *ops = cpu_get_ops(dev);
88 return ops->get_info(dev, info);
91 int cpu_get_count(struct udevice *dev)
93 struct cpu_ops *ops = cpu_get_ops(dev);
98 return ops->get_count(dev);
101 int cpu_get_vendor(struct udevice *dev, char *buf, int size)
103 struct cpu_ops *ops = cpu_get_ops(dev);
105 if (!ops->get_vendor)
108 return ops->get_vendor(dev, buf, size);
111 U_BOOT_DRIVER(cpu_bus) = {
113 .id = UCLASS_SIMPLE_BUS,
114 .per_child_platdata_auto_alloc_size = sizeof(struct cpu_platdata),
117 static int uclass_cpu_init(struct uclass *uc)
123 node = ofnode_path("/cpus");
124 if (!ofnode_valid(node))
127 ret = device_bind_driver_to_node(dm_root(), "cpu_bus", "cpus", node,
133 UCLASS_DRIVER(cpu) = {
136 .flags = DM_UC_FLAG_SEQ_ALIAS,
137 .init = uclass_cpu_init,