15 #include <linux/module.h>
20 #include <linux/pci.h>
22 #include <linux/slab.h>
37 static unsigned int next_busnumber;
48 static bool ssb_is_early_boot = 1;
50 static void ssb_buses_lock(
void);
51 static void ssb_buses_unlock(
void);
54 #ifdef CONFIG_SSB_PCIHOST
73 #ifdef CONFIG_SSB_PCMCIAHOST
92 #ifdef CONFIG_SSB_SDIOHOST
112 int (*func)(
struct ssb_bus *bus,
unsigned long data))
119 res =
func(bus, data);
137 static void ssb_device_put(
struct ssb_device *dev)
143 static int ssb_device_resume(
struct device *dev)
145 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
151 if (ssb_drv && ssb_drv->
resume)
152 err = ssb_drv->
resume(ssb_dev);
162 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
168 if (ssb_drv && ssb_drv->
suspend)
169 err = ssb_drv->
suspend(ssb_dev, state);
184 #ifdef CONFIG_SSB_DRIVER_PCICORE
212 #ifdef CONFIG_SSB_SPROM
228 memset(ctx, 0,
sizeof(*ctx));
233 sdev = ssb_device_get(&bus->
devices[i]);
235 if (!sdev->
dev || !sdev->
dev->driver ||
236 !device_is_registered(sdev->
dev)) {
237 ssb_device_put(sdev);
275 err = sdrv->
probe(sdev, &sdev->
id);
278 dev_name(sdev->
dev));
281 ssb_device_put(sdev);
288 static void ssb_device_shutdown(
struct device *dev)
290 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
300 static int ssb_device_remove(
struct device *dev)
302 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
305 if (ssb_drv && ssb_drv->
remove)
307 ssb_device_put(ssb_dev);
312 static int ssb_device_probe(
struct device *dev)
314 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
318 ssb_device_get(ssb_dev);
319 if (ssb_drv && ssb_drv->
probe)
320 err = ssb_drv->
probe(ssb_dev, &ssb_dev->
id);
322 ssb_device_put(ssb_dev);
327 static int ssb_match_devid(
const struct ssb_device_id *tabid,
344 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
351 if (ssb_match_devid(
id, &ssb_dev->
id))
360 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
366 "MODALIAS=ssb:v%04Xid%04Xrev%02X",
367 ssb_dev->
id.vendor, ssb_dev->
id.coreid,
368 ssb_dev->
id.revision);
371 #define ssb_config_attr(attrib, field, format_string) \
373 attrib##_show(struct device *dev, struct device_attribute *attr, char *buf) \
375 return sprintf(buf, format_string, dev_to_ssb_dev(dev)->field); \
402 .match = ssb_bus_match,
403 .probe = ssb_device_probe,
404 .remove = ssb_device_remove,
405 .shutdown = ssb_device_shutdown,
406 .suspend = ssb_device_suspend,
407 .resume = ssb_device_resume,
408 .uevent = ssb_device_uevent,
409 .dev_attrs = ssb_device_attrs,
412 static void ssb_buses_lock(
void)
415 if (!ssb_is_early_boot)
419 static void ssb_buses_unlock(
void)
422 if (!ssb_is_early_boot)
426 static void ssb_devices_unregister(
struct ssb_bus *bus)
441 ssb_devices_unregister(bus);
451 static void ssb_release_dev(
struct device *dev)
459 static int ssb_devices_register(
struct ssb_bus *bus)
472 switch (sdev->
id.coreid) {
483 devwrap = kzalloc(
sizeof(*devwrap),
GFP_KERNEL);
486 "Could not allocate device\n");
493 dev->
release = ssb_release_dev;
499 #ifdef CONFIG_SSB_PCIHOST
506 #ifdef CONFIG_SSB_PCMCIAHOST
512 #ifdef CONFIG_SSB_SDIOHOST
526 "Could not register %s\n",
540 ssb_devices_unregister(bus);
545 static int __devinit ssb_attach_queued_buses(
void)
549 int drop_them_all = 0;
566 err = ssb_devices_register(bus);
573 list_move_tail(&bus->
list, &buses);
603 #ifdef CONFIG_SSB_BLOCKIO
676 #ifdef CONFIG_SSB_BLOCKIO
677 static void ssb_ssb_block_write(
struct ssb_device *dev,
const void *buffer,
678 size_t count,
u16 offset,
u8 reg_width)
727 .read8 = ssb_ssb_read8,
728 .read16 = ssb_ssb_read16,
729 .read32 = ssb_ssb_read32,
730 .write8 = ssb_ssb_write8,
731 .write16 = ssb_ssb_write16,
732 .write32 = ssb_ssb_write32,
733 #ifdef CONFIG_SSB_BLOCKIO
734 .block_read = ssb_ssb_block_read,
735 .block_write = ssb_ssb_block_write,
739 static int ssb_fetch_invariants(
struct ssb_bus *bus,
746 err = get_invariants(bus, &
iv);
758 unsigned long baseaddr)
763 INIT_LIST_HEAD(&bus->
list);
764 #ifdef CONFIG_SSB_EMBEDDED
776 goto err_disable_xtal;
797 goto err_pcmcia_exit;
800 err = ssb_fetch_invariants(bus, get_invariants);
803 goto err_pcmcia_exit;
810 if (!ssb_is_early_boot) {
812 err = ssb_attach_queued_buses();
838 #ifdef CONFIG_SSB_PCIHOST
851 "PCI device %s\n", dev_name(&host_pci->
dev));
854 " of SSB with error %d\n", err);
862 #ifdef CONFIG_SSB_PCMCIAHOST
864 struct pcmcia_device *pcmcia_dev,
865 unsigned long baseaddr)
876 "PCMCIA device %s\n", pcmcia_dev->devname);
884 #ifdef CONFIG_SSB_SDIOHOST
908 unsigned long baseaddr,
914 bus->
ops = &ssb_ssb_ops;
916 err = ssb_bus_register(bus, get_invariants, baseaddr);
919 "address 0x%08lX\n", baseaddr);
949 if (ent->
id.vendor != dev->
id.vendor)
951 if (ent->
id.coreid != dev->
id.coreid)
959 static u32 clkfactor_f6_resolve(
u32 v)
996 n1 = clkfactor_f6_resolve(n1);
1032 m1 = clkfactor_f6_resolve(m1);
1037 m2 = clkfactor_f6_resolve(m2);
1038 m3 = clkfactor_f6_resolve(m3);
1044 return (clock / m1);
1046 return (clock / (m1 * m2));
1048 return (clock / (m1 * m2 * m3));
1050 return (clock / (m1 * m3));
1079 u32 clkctl_n, clkctl_m;
1084 if (ssb_extif_available(&bus->
extif))
1086 &clkctl_n, &clkctl_m);
1087 else if (bus->
chipco.dev)
1089 &clkctl_n, &clkctl_m);
1105 static u32 ssb_tmslow_reject_bitmask(
struct ssb_device *dev)
1132 reject = ssb_tmslow_reject_bitmask(dev);
1140 static void ssb_flush_tmslow(
struct ssb_device *dev)
1160 ssb_flush_tmslow(dev);
1174 core_specific_flags);
1175 ssb_flush_tmslow(dev);
1178 core_specific_flags);
1179 ssb_flush_tmslow(dev);
1186 int timeout,
int set)
1191 for (i = 0; i < timeout; i++) {
1192 val = ssb_read32(dev, reg);
1194 if ((val & bitmask) == bitmask)
1197 if (!(val & bitmask))
1203 "register %04X to %s.\n",
1204 bitmask, reg, (
set ?
"set" :
"clear"));
1216 reject = ssb_tmslow_reject_bitmask(dev);
1219 ssb_write32(dev,
SSB_TMSLOW, reject | SSB_TMSLOW_CLOCK);
1220 ssb_wait_bits(dev,
SSB_TMSLOW, reject, 1000, 1);
1233 reject | SSB_TMSLOW_RESET |
1234 core_specific_flags);
1235 ssb_flush_tmslow(dev);
1237 if (ssb_read32(dev,
SSB_IDLOW) & SSB_IDLOW_INITIATOR) {
1245 reject | SSB_TMSLOW_RESET |
1246 core_specific_flags);
1247 ssb_flush_tmslow(dev);
1252 static bool ssb_dma_translation_special_bit(
struct ssb_device *dev)
1257 return (chip_id == 0x4322 || chip_id == 43221 ||
1258 chip_id == 43231 || chip_id == 43222);
1266 switch (dev->
bus->bustype) {
1270 if (pci_is_pcie(dev->
bus->host_pci) &&
1274 if (ssb_dma_translation_special_bit(dev))
1280 __ssb_dma_not_implemented(dev);
1301 if (cc->
dev->id.revision < 5)
1309 #ifdef CONFIG_SSB_DEBUG
1310 bus->powered_up = 0;
1328 #ifdef CONFIG_SSB_DEBUG
1329 bus->powered_up = 1;
1342 static void ssb_broadcast_value(
struct ssb_device *dev,
1345 #ifdef CONFIG_SSB_DRIVER_PCICORE
1361 #ifdef CONFIG_SSB_DRIVER_PCICORE
1369 ssb_broadcast_value(dev, 0xFD8, 0);
1416 size = (1 << (size + 1));
1422 static int __init ssb_modinit(
void)
1427 ssb_is_early_boot = 0;
1436 err = ssb_attach_queued_buses();
1446 "initialization failed\n");
1453 "driver initialization failed\n");
1465 static void __exit ssb_modexit(
void)