ssb: add some missing sprom attributes
[deliverable/linux.git] / drivers / bcma / main.c
CommitLineData
8369ae33
RM
1/*
2 * Broadcom specific AMBA
3 * Bus subsystem
4 *
5 * Licensed under the GNU/GPL. See COPYING for details.
6 */
7
8#include "bcma_private.h"
200351c7 9#include <linux/module.h>
8369ae33 10#include <linux/bcma/bcma.h>
eef72699 11#include <linux/slab.h>
8369ae33
RM
12
13MODULE_DESCRIPTION("Broadcom's specific AMBA driver");
14MODULE_LICENSE("GPL");
15
8f9ada4f
HM
16/* contains the number the next bus should get. */
17static unsigned int bcma_bus_next_num = 0;
18
19/* bcma_buses_mutex locks the bcma_bus_next_num */
20static DEFINE_MUTEX(bcma_buses_mutex);
21
8369ae33
RM
22static int bcma_bus_match(struct device *dev, struct device_driver *drv);
23static int bcma_device_probe(struct device *dev);
24static int bcma_device_remove(struct device *dev);
886b66ef 25static int bcma_device_uevent(struct device *dev, struct kobj_uevent_env *env);
8369ae33
RM
26
27static ssize_t manuf_show(struct device *dev, struct device_attribute *attr, char *buf)
28{
29 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
30 return sprintf(buf, "0x%03X\n", core->id.manuf);
31}
32static ssize_t id_show(struct device *dev, struct device_attribute *attr, char *buf)
33{
34 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
35 return sprintf(buf, "0x%03X\n", core->id.id);
36}
37static ssize_t rev_show(struct device *dev, struct device_attribute *attr, char *buf)
38{
39 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
40 return sprintf(buf, "0x%02X\n", core->id.rev);
41}
42static ssize_t class_show(struct device *dev, struct device_attribute *attr, char *buf)
43{
44 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
45 return sprintf(buf, "0x%X\n", core->id.class);
46}
47static struct device_attribute bcma_device_attrs[] = {
48 __ATTR_RO(manuf),
49 __ATTR_RO(id),
50 __ATTR_RO(rev),
51 __ATTR_RO(class),
52 __ATTR_NULL,
53};
54
55static struct bus_type bcma_bus_type = {
56 .name = "bcma",
57 .match = bcma_bus_match,
58 .probe = bcma_device_probe,
59 .remove = bcma_device_remove,
886b66ef 60 .uevent = bcma_device_uevent,
8369ae33
RM
61 .dev_attrs = bcma_device_attrs,
62};
63
64static struct bcma_device *bcma_find_core(struct bcma_bus *bus, u16 coreid)
65{
66 struct bcma_device *core;
67
68 list_for_each_entry(core, &bus->cores, list) {
69 if (core->id.id == coreid)
70 return core;
71 }
72 return NULL;
73}
74
75static void bcma_release_core_dev(struct device *dev)
76{
77 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
ecd177c2
HM
78 if (core->io_addr)
79 iounmap(core->io_addr);
80 if (core->io_wrap)
81 iounmap(core->io_wrap);
8369ae33
RM
82 kfree(core);
83}
84
85static int bcma_register_cores(struct bcma_bus *bus)
86{
87 struct bcma_device *core;
88 int err, dev_id = 0;
89
90 list_for_each_entry(core, &bus->cores, list) {
91 /* We support that cores ourself */
92 switch (core->id.id) {
93 case BCMA_CORE_CHIPCOMMON:
94 case BCMA_CORE_PCI:
95 case BCMA_CORE_PCIE:
21e0534a 96 case BCMA_CORE_MIPS_74K:
8369ae33
RM
97 continue;
98 }
99
100 core->dev.release = bcma_release_core_dev;
101 core->dev.bus = &bcma_bus_type;
8f9ada4f 102 dev_set_name(&core->dev, "bcma%d:%d", bus->num, dev_id);
8369ae33
RM
103
104 switch (bus->hosttype) {
105 case BCMA_HOSTTYPE_PCI:
106 core->dev.parent = &bus->host_pci->dev;
1bdcd095
RM
107 core->dma_dev = &bus->host_pci->dev;
108 core->irq = bus->host_pci->irq;
8369ae33 109 break;
ecd177c2
HM
110 case BCMA_HOSTTYPE_SOC:
111 core->dev.dma_mask = &core->dev.coherent_dma_mask;
112 core->dma_dev = &core->dev;
113 break;
8369ae33
RM
114 case BCMA_HOSTTYPE_SDIO:
115 break;
116 }
117
118 err = device_register(&core->dev);
119 if (err) {
120 pr_err("Could not register dev for core 0x%03X\n",
121 core->id.id);
122 continue;
123 }
124 core->dev_registered = true;
125 dev_id++;
126 }
127
128 return 0;
129}
130
131static void bcma_unregister_cores(struct bcma_bus *bus)
132{
133 struct bcma_device *core;
134
135 list_for_each_entry(core, &bus->cores, list) {
136 if (core->dev_registered)
137 device_unregister(&core->dev);
138 }
139}
140
d1a7a8e1 141int __devinit bcma_bus_register(struct bcma_bus *bus)
8369ae33
RM
142{
143 int err;
144 struct bcma_device *core;
145
8f9ada4f
HM
146 mutex_lock(&bcma_buses_mutex);
147 bus->num = bcma_bus_next_num++;
148 mutex_unlock(&bcma_buses_mutex);
149
8369ae33
RM
150 /* Scan for devices (cores) */
151 err = bcma_bus_scan(bus);
152 if (err) {
153 pr_err("Failed to scan: %d\n", err);
154 return -1;
155 }
156
157 /* Init CC core */
158 core = bcma_find_core(bus, BCMA_CORE_CHIPCOMMON);
159 if (core) {
160 bus->drv_cc.core = core;
161 bcma_core_chipcommon_init(&bus->drv_cc);
162 }
163
21e0534a
HM
164 /* Init MIPS core */
165 core = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
166 if (core) {
167 bus->drv_mips.core = core;
168 bcma_core_mips_init(&bus->drv_mips);
169 }
170
8369ae33
RM
171 /* Init PCIE core */
172 core = bcma_find_core(bus, BCMA_CORE_PCIE);
173 if (core) {
174 bus->drv_pci.core = core;
175 bcma_core_pci_init(&bus->drv_pci);
176 }
177
27f18dc2
RM
178 /* Try to get SPROM */
179 err = bcma_sprom_get(bus);
534e7a45
HM
180 if (err == -ENOENT) {
181 pr_err("No SPROM available\n");
2e6b4119 182 } else if (err)
27f18dc2 183 pr_err("Failed to get SPROM: %d\n", err);
27f18dc2 184
8369ae33
RM
185 /* Register found cores */
186 bcma_register_cores(bus);
187
188 pr_info("Bus registered\n");
189
190 return 0;
191}
8369ae33
RM
192
193void bcma_bus_unregister(struct bcma_bus *bus)
194{
195 bcma_unregister_cores(bus);
196}
8369ae33 197
517f43e5
HM
198int __init bcma_bus_early_register(struct bcma_bus *bus,
199 struct bcma_device *core_cc,
200 struct bcma_device *core_mips)
201{
202 int err;
203 struct bcma_device *core;
204 struct bcma_device_id match;
205
206 bcma_init_bus(bus);
207
208 match.manuf = BCMA_MANUF_BCM;
209 match.id = BCMA_CORE_CHIPCOMMON;
210 match.class = BCMA_CL_SIM;
211 match.rev = BCMA_ANY_REV;
212
213 /* Scan for chip common core */
214 err = bcma_bus_scan_early(bus, &match, core_cc);
215 if (err) {
216 pr_err("Failed to scan for common core: %d\n", err);
217 return -1;
218 }
219
220 match.manuf = BCMA_MANUF_MIPS;
221 match.id = BCMA_CORE_MIPS_74K;
222 match.class = BCMA_CL_SIM;
223 match.rev = BCMA_ANY_REV;
224
225 /* Scan for mips core */
226 err = bcma_bus_scan_early(bus, &match, core_mips);
227 if (err) {
228 pr_err("Failed to scan for mips core: %d\n", err);
229 return -1;
230 }
231
232 /* Init CC core */
233 core = bcma_find_core(bus, BCMA_CORE_CHIPCOMMON);
234 if (core) {
235 bus->drv_cc.core = core;
236 bcma_core_chipcommon_init(&bus->drv_cc);
237 }
238
21e0534a
HM
239 /* Init MIPS core */
240 core = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
241 if (core) {
242 bus->drv_mips.core = core;
243 bcma_core_mips_init(&bus->drv_mips);
244 }
245
517f43e5
HM
246 pr_info("Early bus registered\n");
247
248 return 0;
249}
250
775ab521 251#ifdef CONFIG_PM
685a4ef0
LT
252int bcma_bus_suspend(struct bcma_bus *bus)
253{
7d5869e7
LT
254 struct bcma_device *core;
255
256 list_for_each_entry(core, &bus->cores, list) {
257 struct device_driver *drv = core->dev.driver;
258 if (drv) {
259 struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv);
260 if (adrv->suspend)
261 adrv->suspend(core);
262 }
263 }
685a4ef0
LT
264 return 0;
265}
266
775ab521
RM
267int bcma_bus_resume(struct bcma_bus *bus)
268{
269 struct bcma_device *core;
270
271 /* Init CC core */
272 core = bcma_find_core(bus, BCMA_CORE_CHIPCOMMON);
273 if (core) {
274 bus->drv_cc.setup_done = false;
275 bcma_core_chipcommon_init(&bus->drv_cc);
276 }
277
7d5869e7
LT
278 list_for_each_entry(core, &bus->cores, list) {
279 struct device_driver *drv = core->dev.driver;
280 if (drv) {
281 struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv);
282 if (adrv->resume)
283 adrv->resume(core);
284 }
285 }
286
775ab521
RM
287 return 0;
288}
289#endif
290
8369ae33
RM
291int __bcma_driver_register(struct bcma_driver *drv, struct module *owner)
292{
293 drv->drv.name = drv->name;
294 drv->drv.bus = &bcma_bus_type;
295 drv->drv.owner = owner;
296
297 return driver_register(&drv->drv);
298}
299EXPORT_SYMBOL_GPL(__bcma_driver_register);
300
301void bcma_driver_unregister(struct bcma_driver *drv)
302{
303 driver_unregister(&drv->drv);
304}
305EXPORT_SYMBOL_GPL(bcma_driver_unregister);
306
307static int bcma_bus_match(struct device *dev, struct device_driver *drv)
308{
309 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
310 struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv);
311 const struct bcma_device_id *cid = &core->id;
312 const struct bcma_device_id *did;
313
314 for (did = adrv->id_table; did->manuf || did->id || did->rev; did++) {
315 if ((did->manuf == cid->manuf || did->manuf == BCMA_ANY_MANUF) &&
316 (did->id == cid->id || did->id == BCMA_ANY_ID) &&
317 (did->rev == cid->rev || did->rev == BCMA_ANY_REV) &&
318 (did->class == cid->class || did->class == BCMA_ANY_CLASS))
319 return 1;
320 }
321 return 0;
322}
323
324static int bcma_device_probe(struct device *dev)
325{
326 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
327 struct bcma_driver *adrv = container_of(dev->driver, struct bcma_driver,
328 drv);
329 int err = 0;
330
331 if (adrv->probe)
332 err = adrv->probe(core);
333
334 return err;
335}
336
337static int bcma_device_remove(struct device *dev)
338{
339 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
340 struct bcma_driver *adrv = container_of(dev->driver, struct bcma_driver,
341 drv);
342
343 if (adrv->remove)
344 adrv->remove(core);
345
346 return 0;
347}
348
886b66ef
DW
349static int bcma_device_uevent(struct device *dev, struct kobj_uevent_env *env)
350{
351 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
352
353 return add_uevent_var(env,
354 "MODALIAS=bcma:m%04Xid%04Xrev%02Xcl%02X",
355 core->id.manuf, core->id.id,
356 core->id.rev, core->id.class);
357}
358
8369ae33
RM
359static int __init bcma_modinit(void)
360{
361 int err;
362
363 err = bus_register(&bcma_bus_type);
364 if (err)
365 return err;
366
367#ifdef CONFIG_BCMA_HOST_PCI
368 err = bcma_host_pci_init();
369 if (err) {
370 pr_err("PCI host initialization failed\n");
371 err = 0;
372 }
373#endif
374
375 return err;
376}
377fs_initcall(bcma_modinit);
378
379static void __exit bcma_modexit(void)
380{
381#ifdef CONFIG_BCMA_HOST_PCI
382 bcma_host_pci_exit();
383#endif
384 bus_unregister(&bcma_bus_type);
385}
386module_exit(bcma_modexit)
This page took 0.089542 seconds and 5 git commands to generate.