sparc: Remove SBUS layer resource and irq handling.
[firefly-linux-kernel-4.4.55.git] / drivers / sbus / sbus.c
1 /* sbus.c: SBus support routines.
2  *
3  * Copyright (C) 1995, 2006 David S. Miller (davem@davemloft.net)
4  */
5
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>
11
12 #include <asm/system.h>
13 #include <asm/sbus.h>
14 #include <asm/dma.h>
15 #include <asm/oplib.h>
16 #include <asm/prom.h>
17 #include <asm/irq.h>
18
19 static ssize_t
20 show_sbusobppath_attr(struct device * dev, struct device_attribute * attr, char * buf)
21 {
22         struct sbus_dev *sbus;
23
24         sbus = to_sbus_device(dev);
25
26         return snprintf (buf, PAGE_SIZE, "%s\n", sbus->ofdev.node->full_name);
27 }
28
29 static DEVICE_ATTR(obppath, S_IRUSR | S_IRGRP | S_IROTH, show_sbusobppath_attr, NULL);
30
31 struct sbus_bus *sbus_root;
32
33 static void __init fill_sbus_device_iommu(struct sbus_dev *sdev)
34 {
35         struct of_device *op = of_find_device_by_node(sdev->ofdev.node);
36         struct dev_archdata *sd, *bus_sd;
37         struct sbus_bus *sbus;
38
39         sbus = sdev->bus;
40         bus_sd = &sbus->ofdev.dev.archdata;
41
42         sd = &sdev->ofdev.dev.archdata;
43         sd->iommu = bus_sd->iommu;
44         sd->stc = bus_sd->stc;
45
46         sd = &op->dev.archdata;
47         sd->iommu = bus_sd->iommu;
48         sd->stc = bus_sd->stc;
49 }
50
51 static void __init fill_sbus_device(struct device_node *dp, struct sbus_dev *sdev)
52 {
53         struct dev_archdata *sd;
54         int err;
55
56         sdev->prom_node = dp->node;
57         strcpy(sdev->prom_name, dp->name);
58
59         sd = &sdev->ofdev.dev.archdata;
60         sd->prom_node = dp;
61         sd->op = &sdev->ofdev;
62
63         sdev->ofdev.node = dp;
64         if (sdev->parent)
65                 sdev->ofdev.dev.parent = &sdev->parent->ofdev.dev;
66         else
67                 sdev->ofdev.dev.parent = &sdev->bus->ofdev.dev;
68         sdev->ofdev.dev.bus = &sbus_bus_type;
69         dev_set_name(&sdev->ofdev.dev, "sbus[%08x]", dp->node);
70
71         if (of_device_register(&sdev->ofdev) != 0)
72                 printk(KERN_DEBUG "sbus: device registration error for %s!\n",
73                        dp->path_component_name);
74
75         /* WE HAVE BEEN INVADED BY ALIENS! */
76         err = sysfs_create_file(&sdev->ofdev.dev.kobj, &dev_attr_obppath.attr);
77
78         fill_sbus_device_iommu(sdev);
79 }
80
81 /* We preserve the "probe order" of these bus and device lists to give
82  * the same ordering as the old code.
83  */
84 static void __init sbus_insert(struct sbus_bus *sbus, struct sbus_bus **root)
85 {
86         while (*root)
87                 root = &(*root)->next;
88         *root = sbus;
89         sbus->next = NULL;
90 }
91
92 static void __init sdev_insert(struct sbus_dev *sdev, struct sbus_dev **root)
93 {
94         while (*root)
95                 root = &(*root)->next;
96         *root = sdev;
97         sdev->next = NULL;
98 }
99
100 static void __init walk_children(struct device_node *dp, struct sbus_dev *parent, struct sbus_bus *sbus)
101 {
102         dp = dp->child;
103         while (dp) {
104                 struct sbus_dev *sdev;
105
106                 sdev = kzalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
107                 if (sdev) {
108                         sdev_insert(sdev, &parent->child);
109
110                         sdev->bus = sbus;
111                         sdev->parent = parent;
112
113                         fill_sbus_device(dp, sdev);
114
115                         walk_children(dp, sdev, sbus);
116                 }
117                 dp = dp->sibling;
118         }
119 }
120
121 static void __init build_one_sbus(struct device_node *dp, int num_sbus)
122 {
123         struct sbus_bus *sbus;
124         unsigned int sbus_clock;
125         struct device_node *dev_dp;
126
127         sbus = kzalloc(sizeof(struct sbus_bus), GFP_ATOMIC);
128         if (!sbus)
129                 return;
130
131         sbus_insert(sbus, &sbus_root);
132         sbus->prom_node = dp->node;
133
134         sbus_setup_iommu(sbus, dp);
135
136         printk("sbus%d: ", num_sbus);
137
138         sbus_clock = of_getintprop_default(dp, "clock-frequency",
139                                            (25*1000*1000));
140         sbus->clock_freq = sbus_clock;
141
142         printk("Clock %d.%d MHz\n", (int) ((sbus_clock/1000)/1000),
143                (int) (((sbus_clock/1000)%1000 != 0) ? 
144                       (((sbus_clock/1000)%1000) + 1000) : 0));
145
146         strcpy(sbus->prom_name, dp->name);
147
148         sbus->ofdev.node = dp;
149         sbus->ofdev.dev.parent = NULL;
150         sbus->ofdev.dev.bus = &sbus_bus_type;
151         dev_set_name(&sbus->ofdev.dev, "sbus%d", num_sbus);
152
153         if (of_device_register(&sbus->ofdev) != 0)
154                 printk(KERN_DEBUG "sbus: device registration error for %s!\n",
155                        dev_name(&sbus->ofdev.dev));
156
157         dev_dp = dp->child;
158         while (dev_dp) {
159                 struct sbus_dev *sdev;
160
161                 sdev = kzalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
162                 if (sdev) {
163                         sdev_insert(sdev, &sbus->devices);
164
165                         sdev->bus = sbus;
166                         sdev->parent = NULL;
167                         sdev->ofdev.dev.archdata.iommu =
168                                 sbus->ofdev.dev.archdata.iommu;
169                         sdev->ofdev.dev.archdata.stc =
170                                 sbus->ofdev.dev.archdata.stc;
171
172                         fill_sbus_device(dev_dp, sdev);
173
174                         walk_children(dev_dp, sdev, sbus);
175                 }
176                 dev_dp = dev_dp->sibling;
177         }
178 }
179
180 static int __init sbus_init(void)
181 {
182         struct device_node *dp;
183         const char *sbus_name = "sbus";
184         int num_sbus = 0;
185
186         if (sbus_arch_preinit())
187                 return 0;
188
189         if (sparc_cpu_model == sun4d)
190                 sbus_name = "sbi";
191
192         for_each_node_by_name(dp, sbus_name) {
193                 build_one_sbus(dp, num_sbus);
194                 num_sbus++;
195
196         }
197
198         sbus_arch_postinit();
199
200         return 0;
201 }
202
203 subsys_initcall(sbus_init);