1 /* sbus.c: SBus support routines.
3 * Copyright (C) 1995, 2006 David S. Miller (davem@davemloft.net)
6 #include <linux/kernel.h>
7 #include <linux/slab.h>
8 #include <linux/init.h>
9 #include <linux/device.h>
10 #include <linux/of_device.h>
12 #include <asm/system.h>
15 #include <asm/oplib.h>
20 show_sbusobppath_attr(struct device * dev, struct device_attribute * attr, char * buf)
22 struct sbus_dev *sbus;
24 sbus = to_sbus_device(dev);
26 return snprintf (buf, PAGE_SIZE, "%s\n", sbus->ofdev.node->full_name);
29 static DEVICE_ATTR(obppath, S_IRUSR | S_IRGRP | S_IROTH, show_sbusobppath_attr, NULL);
31 static void __init fill_sbus_device_iommu(struct sbus_dev *sdev)
33 struct of_device *op = of_find_device_by_node(sdev->ofdev.node);
34 struct dev_archdata *sd, *bus_sd;
35 struct sbus_bus *sbus;
38 bus_sd = &sbus->ofdev.dev.archdata;
40 sd = &sdev->ofdev.dev.archdata;
41 sd->iommu = bus_sd->iommu;
42 sd->stc = bus_sd->stc;
44 sd = &op->dev.archdata;
45 sd->iommu = bus_sd->iommu;
46 sd->stc = bus_sd->stc;
49 static void __init fill_sbus_device(struct device_node *dp, struct sbus_dev *sdev)
51 struct dev_archdata *sd;
54 sdev->prom_node = dp->node;
55 strcpy(sdev->prom_name, dp->name);
57 sd = &sdev->ofdev.dev.archdata;
59 sd->op = &sdev->ofdev;
61 sdev->ofdev.node = dp;
63 sdev->ofdev.dev.parent = &sdev->parent->ofdev.dev;
65 sdev->ofdev.dev.parent = &sdev->bus->ofdev.dev;
66 sdev->ofdev.dev.bus = &sbus_bus_type;
67 dev_set_name(&sdev->ofdev.dev, "sbus[%08x]", dp->node);
69 if (of_device_register(&sdev->ofdev) != 0)
70 printk(KERN_DEBUG "sbus: device registration error for %s!\n",
71 dp->path_component_name);
73 /* WE HAVE BEEN INVADED BY ALIENS! */
74 err = sysfs_create_file(&sdev->ofdev.dev.kobj, &dev_attr_obppath.attr);
76 fill_sbus_device_iommu(sdev);
79 static void __init sdev_insert(struct sbus_dev *sdev, struct sbus_dev **root)
82 root = &(*root)->next;
87 static void __init walk_children(struct device_node *dp, struct sbus_dev *parent, struct sbus_bus *sbus)
91 struct sbus_dev *sdev;
93 sdev = kzalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
95 sdev_insert(sdev, &parent->child);
98 sdev->parent = parent;
100 fill_sbus_device(dp, sdev);
102 walk_children(dp, sdev, sbus);
108 static void __init build_one_sbus(struct device_node *dp, int num_sbus)
110 struct sbus_bus *sbus;
111 unsigned int sbus_clock;
112 struct device_node *dev_dp;
114 sbus = kzalloc(sizeof(struct sbus_bus), GFP_ATOMIC);
118 sbus->prom_node = dp->node;
120 sbus_setup_iommu(sbus, dp);
122 printk("sbus%d: ", num_sbus);
124 sbus_clock = of_getintprop_default(dp, "clock-frequency",
126 sbus->clock_freq = sbus_clock;
128 printk("Clock %d.%d MHz\n", (int) ((sbus_clock/1000)/1000),
129 (int) (((sbus_clock/1000)%1000 != 0) ?
130 (((sbus_clock/1000)%1000) + 1000) : 0));
132 strcpy(sbus->prom_name, dp->name);
134 sbus->ofdev.node = dp;
135 sbus->ofdev.dev.parent = NULL;
136 sbus->ofdev.dev.bus = &sbus_bus_type;
137 dev_set_name(&sbus->ofdev.dev, "sbus%d", num_sbus);
139 if (of_device_register(&sbus->ofdev) != 0)
140 printk(KERN_DEBUG "sbus: device registration error for %s!\n",
141 dev_name(&sbus->ofdev.dev));
145 struct sbus_dev *sdev;
147 sdev = kzalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
149 sdev_insert(sdev, &sbus->devices);
153 sdev->ofdev.dev.archdata.iommu =
154 sbus->ofdev.dev.archdata.iommu;
155 sdev->ofdev.dev.archdata.stc =
156 sbus->ofdev.dev.archdata.stc;
158 fill_sbus_device(dev_dp, sdev);
160 walk_children(dev_dp, sdev, sbus);
162 dev_dp = dev_dp->sibling;
166 static int __init sbus_init(void)
168 struct device_node *dp;
169 const char *sbus_name = "sbus";
172 if (sbus_arch_preinit())
175 if (sparc_cpu_model == sun4d)
178 for_each_node_by_name(dp, sbus_name) {
179 build_one_sbus(dp, num_sbus);
184 sbus_arch_postinit();
189 subsys_initcall(sbus_init);