2 * Sonics Silicon Backplane
5 * Copyright 2005, Broadcom Corporation
6 * Copyright 2006, 2007, Michael Buesch <mb@bu3sch.de>
8 * Licensed under the GNU/GPL. See COPYING for details.
11 #include "ssb_private.h"
13 #include <linux/delay.h>
15 #include <linux/ssb/ssb.h>
16 #include <linux/ssb/ssb_regs.h>
17 #include <linux/dma-mapping.h>
18 #include <linux/pci.h>
20 #include <pcmcia/cs_types.h>
21 #include <pcmcia/cs.h>
22 #include <pcmcia/cistpl.h>
23 #include <pcmcia/ds.h>
26 MODULE_DESCRIPTION("Sonics Silicon Backplane driver");
27 MODULE_LICENSE("GPL");
30 /* Temporary list of yet-to-be-attached buses */
31 static LIST_HEAD(attach_queue);
32 /* List if running buses */
33 static LIST_HEAD(buses);
34 /* Software ID counter */
35 static unsigned int next_busnumber;
36 /* buses_mutes locks the two buslists and the next_busnumber.
37 * Don't lock this directly, but use ssb_buses_[un]lock() below. */
38 static DEFINE_MUTEX(buses_mutex);
40 /* There are differences in the codeflow, if the bus is
41 * initialized from early boot, as various needed services
42 * are not available early. This is a mechanism to delay
43 * these initializations to after early boot has finished.
44 * It's also used to avoid mutex locking, as that's not
45 * available and needed early. */
46 static bool ssb_is_early_boot = 1;
48 static void ssb_buses_lock(void);
49 static void ssb_buses_unlock(void);
52 #ifdef CONFIG_SSB_PCIHOST
53 struct ssb_bus *ssb_pci_dev_to_bus(struct pci_dev *pdev)
58 list_for_each_entry(bus, &buses, list) {
59 if (bus->bustype == SSB_BUSTYPE_PCI &&
60 bus->host_pci == pdev)
69 #endif /* CONFIG_SSB_PCIHOST */
71 static struct ssb_device *ssb_device_get(struct ssb_device *dev)
78 static void ssb_device_put(struct ssb_device *dev)
84 static int ssb_bus_resume(struct ssb_bus *bus)
88 ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 1);
89 err = ssb_pcmcia_init(bus);
91 /* No need to disable XTAL, as we don't have one on PCMCIA. */
94 ssb_chipco_resume(&bus->chipco);
99 static int ssb_device_resume(struct device *dev)
101 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
102 struct ssb_driver *ssb_drv;
107 if (bus->suspend_cnt == bus->nr_devices) {
108 err = ssb_bus_resume(bus);
114 ssb_drv = drv_to_ssb_drv(dev->driver);
115 if (ssb_drv && ssb_drv->resume)
116 err = ssb_drv->resume(ssb_dev);
124 static void ssb_bus_suspend(struct ssb_bus *bus, pm_message_t state)
126 ssb_chipco_suspend(&bus->chipco, state);
127 ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 0);
129 /* Reset HW state information in memory, so that HW is
130 * completely reinitialized on resume. */
131 bus->mapped_device = NULL;
132 #ifdef CONFIG_SSB_DRIVER_PCICORE
133 bus->pcicore.setup_done = 0;
135 #ifdef CONFIG_SSB_DEBUG
140 static int ssb_device_suspend(struct device *dev, pm_message_t state)
142 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
143 struct ssb_driver *ssb_drv;
148 ssb_drv = drv_to_ssb_drv(dev->driver);
149 if (ssb_drv && ssb_drv->suspend)
150 err = ssb_drv->suspend(ssb_dev, state);
157 if (bus->suspend_cnt == bus->nr_devices) {
158 /* All devices suspended. Shutdown the bus. */
159 ssb_bus_suspend(bus, state);
166 #ifdef CONFIG_SSB_PCIHOST
167 int ssb_devices_freeze(struct ssb_bus *bus)
169 struct ssb_device *dev;
170 struct ssb_driver *drv;
173 pm_message_t state = PMSG_FREEZE;
175 /* First check that we are capable to freeze all devices. */
176 for (i = 0; i < bus->nr_devices; i++) {
177 dev = &(bus->devices[i]);
180 !device_is_registered(dev->dev))
182 drv = drv_to_ssb_drv(dev->dev->driver);
186 /* Nope, can't suspend this one. */
190 /* Now suspend all devices */
191 for (i = 0; i < bus->nr_devices; i++) {
192 dev = &(bus->devices[i]);
195 !device_is_registered(dev->dev))
197 drv = drv_to_ssb_drv(dev->dev->driver);
200 err = drv->suspend(dev, state);
202 ssb_printk(KERN_ERR PFX "Failed to freeze device %s\n",
210 for (i--; i >= 0; i--) {
211 dev = &(bus->devices[i]);
214 !device_is_registered(dev->dev))
216 drv = drv_to_ssb_drv(dev->dev->driver);
225 int ssb_devices_thaw(struct ssb_bus *bus)
227 struct ssb_device *dev;
228 struct ssb_driver *drv;
232 for (i = 0; i < bus->nr_devices; i++) {
233 dev = &(bus->devices[i]);
236 !device_is_registered(dev->dev))
238 drv = drv_to_ssb_drv(dev->dev->driver);
241 if (SSB_WARN_ON(!drv->resume))
243 err = drv->resume(dev);
245 ssb_printk(KERN_ERR PFX "Failed to thaw device %s\n",
252 #endif /* CONFIG_SSB_PCIHOST */
254 static void ssb_device_shutdown(struct device *dev)
256 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
257 struct ssb_driver *ssb_drv;
261 ssb_drv = drv_to_ssb_drv(dev->driver);
262 if (ssb_drv && ssb_drv->shutdown)
263 ssb_drv->shutdown(ssb_dev);
266 static int ssb_device_remove(struct device *dev)
268 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
269 struct ssb_driver *ssb_drv = drv_to_ssb_drv(dev->driver);
271 if (ssb_drv && ssb_drv->remove)
272 ssb_drv->remove(ssb_dev);
273 ssb_device_put(ssb_dev);
278 static int ssb_device_probe(struct device *dev)
280 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
281 struct ssb_driver *ssb_drv = drv_to_ssb_drv(dev->driver);
284 ssb_device_get(ssb_dev);
285 if (ssb_drv && ssb_drv->probe)
286 err = ssb_drv->probe(ssb_dev, &ssb_dev->id);
288 ssb_device_put(ssb_dev);
293 static int ssb_match_devid(const struct ssb_device_id *tabid,
294 const struct ssb_device_id *devid)
296 if ((tabid->vendor != devid->vendor) &&
297 tabid->vendor != SSB_ANY_VENDOR)
299 if ((tabid->coreid != devid->coreid) &&
300 tabid->coreid != SSB_ANY_ID)
302 if ((tabid->revision != devid->revision) &&
303 tabid->revision != SSB_ANY_REV)
308 static int ssb_bus_match(struct device *dev, struct device_driver *drv)
310 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
311 struct ssb_driver *ssb_drv = drv_to_ssb_drv(drv);
312 const struct ssb_device_id *id;
314 for (id = ssb_drv->id_table;
315 id->vendor || id->coreid || id->revision;
317 if (ssb_match_devid(id, &ssb_dev->id))
318 return 1; /* found */
324 static int ssb_device_uevent(struct device *dev, struct kobj_uevent_env *env)
326 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
331 return add_uevent_var(env,
332 "MODALIAS=ssb:v%04Xid%04Xrev%02X",
333 ssb_dev->id.vendor, ssb_dev->id.coreid,
334 ssb_dev->id.revision);
337 static struct bus_type ssb_bustype = {
339 .match = ssb_bus_match,
340 .probe = ssb_device_probe,
341 .remove = ssb_device_remove,
342 .shutdown = ssb_device_shutdown,
343 .suspend = ssb_device_suspend,
344 .resume = ssb_device_resume,
345 .uevent = ssb_device_uevent,
348 static void ssb_buses_lock(void)
350 /* See the comment at the ssb_is_early_boot definition */
351 if (!ssb_is_early_boot)
352 mutex_lock(&buses_mutex);
355 static void ssb_buses_unlock(void)
357 /* See the comment at the ssb_is_early_boot definition */
358 if (!ssb_is_early_boot)
359 mutex_unlock(&buses_mutex);
362 static void ssb_devices_unregister(struct ssb_bus *bus)
364 struct ssb_device *sdev;
367 for (i = bus->nr_devices - 1; i >= 0; i--) {
368 sdev = &(bus->devices[i]);
370 device_unregister(sdev->dev);
374 void ssb_bus_unregister(struct ssb_bus *bus)
377 ssb_devices_unregister(bus);
378 list_del(&bus->list);
381 /* ssb_pcmcia_exit(bus); */
385 EXPORT_SYMBOL(ssb_bus_unregister);
387 static void ssb_release_dev(struct device *dev)
389 struct __ssb_dev_wrapper *devwrap;
391 devwrap = container_of(dev, struct __ssb_dev_wrapper, dev);
395 static int ssb_devices_register(struct ssb_bus *bus)
397 struct ssb_device *sdev;
399 struct __ssb_dev_wrapper *devwrap;
403 for (i = 0; i < bus->nr_devices; i++) {
404 sdev = &(bus->devices[i]);
406 /* We don't register SSB-system devices to the kernel,
407 * as the drivers for them are built into SSB. */
408 switch (sdev->id.coreid) {
409 case SSB_DEV_CHIPCOMMON:
414 case SSB_DEV_MIPS_3302:
419 devwrap = kzalloc(sizeof(*devwrap), GFP_KERNEL);
421 ssb_printk(KERN_ERR PFX
422 "Could not allocate device\n");
427 devwrap->sdev = sdev;
429 dev->release = ssb_release_dev;
430 dev->bus = &ssb_bustype;
431 snprintf(dev->bus_id, sizeof(dev->bus_id),
432 "ssb%u:%d", bus->busnumber, dev_idx);
434 switch (bus->bustype) {
435 case SSB_BUSTYPE_PCI:
436 #ifdef CONFIG_SSB_PCIHOST
437 sdev->irq = bus->host_pci->irq;
438 dev->parent = &bus->host_pci->dev;
441 case SSB_BUSTYPE_PCMCIA:
442 #ifdef CONFIG_SSB_PCMCIAHOST
443 dev->parent = &bus->host_pcmcia->dev;
446 case SSB_BUSTYPE_SSB:
451 err = device_register(dev);
453 ssb_printk(KERN_ERR PFX
454 "Could not register %s\n",
456 /* Set dev to NULL to not unregister
457 * dev on error unwinding. */
467 /* Unwind the already registered devices. */
468 ssb_devices_unregister(bus);
472 /* Needs ssb_buses_lock() */
473 static int ssb_attach_queued_buses(void)
475 struct ssb_bus *bus, *n;
477 int drop_them_all = 0;
479 list_for_each_entry_safe(bus, n, &attach_queue, list) {
481 list_del(&bus->list);
484 /* Can't init the PCIcore in ssb_bus_register(), as that
485 * is too early in boot for embedded systems
486 * (no udelay() available). So do it here in attach stage.
488 err = ssb_bus_powerup(bus, 0);
491 ssb_pcicore_init(&bus->pcicore);
492 ssb_bus_may_powerdown(bus);
494 err = ssb_devices_register(bus);
498 list_del(&bus->list);
501 list_move_tail(&bus->list, &buses);
507 static u16 ssb_ssb_read16(struct ssb_device *dev, u16 offset)
509 struct ssb_bus *bus = dev->bus;
511 offset += dev->core_index * SSB_CORE_SIZE;
512 return readw(bus->mmio + offset);
515 static u32 ssb_ssb_read32(struct ssb_device *dev, u16 offset)
517 struct ssb_bus *bus = dev->bus;
519 offset += dev->core_index * SSB_CORE_SIZE;
520 return readl(bus->mmio + offset);
523 static void ssb_ssb_write16(struct ssb_device *dev, u16 offset, u16 value)
525 struct ssb_bus *bus = dev->bus;
527 offset += dev->core_index * SSB_CORE_SIZE;
528 writew(value, bus->mmio + offset);
531 static void ssb_ssb_write32(struct ssb_device *dev, u16 offset, u32 value)
533 struct ssb_bus *bus = dev->bus;
535 offset += dev->core_index * SSB_CORE_SIZE;
536 writel(value, bus->mmio + offset);
539 /* Ops for the plain SSB bus without a host-device (no PCI or PCMCIA). */
540 static const struct ssb_bus_ops ssb_ssb_ops = {
541 .read16 = ssb_ssb_read16,
542 .read32 = ssb_ssb_read32,
543 .write16 = ssb_ssb_write16,
544 .write32 = ssb_ssb_write32,
547 static int ssb_fetch_invariants(struct ssb_bus *bus,
548 ssb_invariants_func_t get_invariants)
550 struct ssb_init_invariants iv;
553 memset(&iv, 0, sizeof(iv));
554 err = get_invariants(bus, &iv);
557 memcpy(&bus->boardinfo, &iv.boardinfo, sizeof(iv.boardinfo));
558 memcpy(&bus->sprom, &iv.sprom, sizeof(iv.sprom));
563 static int ssb_bus_register(struct ssb_bus *bus,
564 ssb_invariants_func_t get_invariants,
565 unsigned long baseaddr)
569 spin_lock_init(&bus->bar_lock);
570 INIT_LIST_HEAD(&bus->list);
572 /* Powerup the bus */
573 err = ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 1);
577 bus->busnumber = next_busnumber;
578 /* Scan for devices (cores) */
579 err = ssb_bus_scan(bus, baseaddr);
581 goto err_disable_xtal;
583 /* Init PCI-host device (if any) */
584 err = ssb_pci_init(bus);
587 /* Init PCMCIA-host device (if any) */
588 err = ssb_pcmcia_init(bus);
592 /* Initialize basic system devices (if available) */
593 err = ssb_bus_powerup(bus, 0);
595 goto err_pcmcia_exit;
596 ssb_chipcommon_init(&bus->chipco);
597 ssb_mipscore_init(&bus->mipscore);
598 err = ssb_fetch_invariants(bus, get_invariants);
600 ssb_bus_may_powerdown(bus);
601 goto err_pcmcia_exit;
603 ssb_bus_may_powerdown(bus);
605 /* Queue it for attach.
606 * See the comment at the ssb_is_early_boot definition. */
607 list_add_tail(&bus->list, &attach_queue);
608 if (!ssb_is_early_boot) {
609 /* This is not early boot, so we must attach the bus now */
610 err = ssb_attach_queued_buses();
621 list_del(&bus->list);
623 /* ssb_pcmcia_exit(bus); */
630 ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 0);
634 #ifdef CONFIG_SSB_PCIHOST
635 int ssb_bus_pcibus_register(struct ssb_bus *bus,
636 struct pci_dev *host_pci)
640 bus->bustype = SSB_BUSTYPE_PCI;
641 bus->host_pci = host_pci;
642 bus->ops = &ssb_pci_ops;
644 err = ssb_bus_register(bus, ssb_pci_get_invariants, 0);
646 ssb_printk(KERN_INFO PFX "Sonics Silicon Backplane found on "
647 "PCI device %s\n", host_pci->dev.bus_id);
652 EXPORT_SYMBOL(ssb_bus_pcibus_register);
653 #endif /* CONFIG_SSB_PCIHOST */
655 #ifdef CONFIG_SSB_PCMCIAHOST
656 int ssb_bus_pcmciabus_register(struct ssb_bus *bus,
657 struct pcmcia_device *pcmcia_dev,
658 unsigned long baseaddr)
662 bus->bustype = SSB_BUSTYPE_PCMCIA;
663 bus->host_pcmcia = pcmcia_dev;
664 bus->ops = &ssb_pcmcia_ops;
666 err = ssb_bus_register(bus, ssb_pcmcia_get_invariants, baseaddr);
668 ssb_printk(KERN_INFO PFX "Sonics Silicon Backplane found on "
669 "PCMCIA device %s\n", pcmcia_dev->devname);
674 EXPORT_SYMBOL(ssb_bus_pcmciabus_register);
675 #endif /* CONFIG_SSB_PCMCIAHOST */
677 int ssb_bus_ssbbus_register(struct ssb_bus *bus,
678 unsigned long baseaddr,
679 ssb_invariants_func_t get_invariants)
683 bus->bustype = SSB_BUSTYPE_SSB;
684 bus->ops = &ssb_ssb_ops;
686 err = ssb_bus_register(bus, get_invariants, baseaddr);
688 ssb_printk(KERN_INFO PFX "Sonics Silicon Backplane found at "
689 "address 0x%08lX\n", baseaddr);
695 int __ssb_driver_register(struct ssb_driver *drv, struct module *owner)
697 drv->drv.name = drv->name;
698 drv->drv.bus = &ssb_bustype;
699 drv->drv.owner = owner;
701 return driver_register(&drv->drv);
703 EXPORT_SYMBOL(__ssb_driver_register);
705 void ssb_driver_unregister(struct ssb_driver *drv)
707 driver_unregister(&drv->drv);
709 EXPORT_SYMBOL(ssb_driver_unregister);
711 void ssb_set_devtypedata(struct ssb_device *dev, void *data)
713 struct ssb_bus *bus = dev->bus;
714 struct ssb_device *ent;
717 for (i = 0; i < bus->nr_devices; i++) {
718 ent = &(bus->devices[i]);
719 if (ent->id.vendor != dev->id.vendor)
721 if (ent->id.coreid != dev->id.coreid)
724 ent->devtypedata = data;
727 EXPORT_SYMBOL(ssb_set_devtypedata);
729 static u32 clkfactor_f6_resolve(u32 v)
731 /* map the magic values */
733 case SSB_CHIPCO_CLK_F6_2:
735 case SSB_CHIPCO_CLK_F6_3:
737 case SSB_CHIPCO_CLK_F6_4:
739 case SSB_CHIPCO_CLK_F6_5:
741 case SSB_CHIPCO_CLK_F6_6:
743 case SSB_CHIPCO_CLK_F6_7:
749 /* Calculate the speed the backplane would run at a given set of clockcontrol values */
750 u32 ssb_calc_clock_rate(u32 plltype, u32 n, u32 m)
752 u32 n1, n2, clock, m1, m2, m3, mc;
754 n1 = (n & SSB_CHIPCO_CLK_N1);
755 n2 = ((n & SSB_CHIPCO_CLK_N2) >> SSB_CHIPCO_CLK_N2_SHIFT);
758 case SSB_PLLTYPE_6: /* 100/200 or 120/240 only */
759 if (m & SSB_CHIPCO_CLK_T6_MMASK)
760 return SSB_CHIPCO_CLK_T6_M0;
761 return SSB_CHIPCO_CLK_T6_M1;
762 case SSB_PLLTYPE_1: /* 48Mhz base, 3 dividers */
763 case SSB_PLLTYPE_3: /* 25Mhz, 2 dividers */
764 case SSB_PLLTYPE_4: /* 48Mhz, 4 dividers */
765 case SSB_PLLTYPE_7: /* 25Mhz, 4 dividers */
766 n1 = clkfactor_f6_resolve(n1);
767 n2 += SSB_CHIPCO_CLK_F5_BIAS;
769 case SSB_PLLTYPE_2: /* 48Mhz, 4 dividers */
770 n1 += SSB_CHIPCO_CLK_T2_BIAS;
771 n2 += SSB_CHIPCO_CLK_T2_BIAS;
772 SSB_WARN_ON(!((n1 >= 2) && (n1 <= 7)));
773 SSB_WARN_ON(!((n2 >= 5) && (n2 <= 23)));
775 case SSB_PLLTYPE_5: /* 25Mhz, 4 dividers */
782 case SSB_PLLTYPE_3: /* 25Mhz, 2 dividers */
783 case SSB_PLLTYPE_7: /* 25Mhz, 4 dividers */
784 clock = SSB_CHIPCO_CLK_BASE2 * n1 * n2;
787 clock = SSB_CHIPCO_CLK_BASE1 * n1 * n2;
792 m1 = (m & SSB_CHIPCO_CLK_M1);
793 m2 = ((m & SSB_CHIPCO_CLK_M2) >> SSB_CHIPCO_CLK_M2_SHIFT);
794 m3 = ((m & SSB_CHIPCO_CLK_M3) >> SSB_CHIPCO_CLK_M3_SHIFT);
795 mc = ((m & SSB_CHIPCO_CLK_MC) >> SSB_CHIPCO_CLK_MC_SHIFT);
798 case SSB_PLLTYPE_1: /* 48Mhz base, 3 dividers */
799 case SSB_PLLTYPE_3: /* 25Mhz, 2 dividers */
800 case SSB_PLLTYPE_4: /* 48Mhz, 4 dividers */
801 case SSB_PLLTYPE_7: /* 25Mhz, 4 dividers */
802 m1 = clkfactor_f6_resolve(m1);
803 if ((plltype == SSB_PLLTYPE_1) ||
804 (plltype == SSB_PLLTYPE_3))
805 m2 += SSB_CHIPCO_CLK_F5_BIAS;
807 m2 = clkfactor_f6_resolve(m2);
808 m3 = clkfactor_f6_resolve(m3);
811 case SSB_CHIPCO_CLK_MC_BYPASS:
813 case SSB_CHIPCO_CLK_MC_M1:
815 case SSB_CHIPCO_CLK_MC_M1M2:
816 return (clock / (m1 * m2));
817 case SSB_CHIPCO_CLK_MC_M1M2M3:
818 return (clock / (m1 * m2 * m3));
819 case SSB_CHIPCO_CLK_MC_M1M3:
820 return (clock / (m1 * m3));
824 m1 += SSB_CHIPCO_CLK_T2_BIAS;
825 m2 += SSB_CHIPCO_CLK_T2M2_BIAS;
826 m3 += SSB_CHIPCO_CLK_T2_BIAS;
827 SSB_WARN_ON(!((m1 >= 2) && (m1 <= 7)));
828 SSB_WARN_ON(!((m2 >= 3) && (m2 <= 10)));
829 SSB_WARN_ON(!((m3 >= 2) && (m3 <= 7)));
831 if (!(mc & SSB_CHIPCO_CLK_T2MC_M1BYP))
833 if (!(mc & SSB_CHIPCO_CLK_T2MC_M2BYP))
835 if (!(mc & SSB_CHIPCO_CLK_T2MC_M3BYP))
844 /* Get the current speed the backplane is running at */
845 u32 ssb_clockspeed(struct ssb_bus *bus)
849 u32 clkctl_n, clkctl_m;
851 if (ssb_extif_available(&bus->extif))
852 ssb_extif_get_clockcontrol(&bus->extif, &plltype,
853 &clkctl_n, &clkctl_m);
854 else if (bus->chipco.dev)
855 ssb_chipco_get_clockcontrol(&bus->chipco, &plltype,
856 &clkctl_n, &clkctl_m);
860 if (bus->chip_id == 0x5365) {
863 rate = ssb_calc_clock_rate(plltype, clkctl_n, clkctl_m);
864 if (plltype == SSB_PLLTYPE_3) /* 25Mhz, 2 dividers */
870 EXPORT_SYMBOL(ssb_clockspeed);
872 static u32 ssb_tmslow_reject_bitmask(struct ssb_device *dev)
874 /* The REJECT bit changed position in TMSLOW between
875 * Backplane revisions. */
876 switch (ssb_read32(dev, SSB_IDLOW) & SSB_IDLOW_SSBREV) {
877 case SSB_IDLOW_SSBREV_22:
878 return SSB_TMSLOW_REJECT_22;
879 case SSB_IDLOW_SSBREV_23:
880 return SSB_TMSLOW_REJECT_23;
884 return (SSB_TMSLOW_REJECT_22 | SSB_TMSLOW_REJECT_23);
887 int ssb_device_is_enabled(struct ssb_device *dev)
892 reject = ssb_tmslow_reject_bitmask(dev);
893 val = ssb_read32(dev, SSB_TMSLOW);
894 val &= SSB_TMSLOW_CLOCK | SSB_TMSLOW_RESET | reject;
896 return (val == SSB_TMSLOW_CLOCK);
898 EXPORT_SYMBOL(ssb_device_is_enabled);
900 static void ssb_flush_tmslow(struct ssb_device *dev)
902 /* Make _really_ sure the device has finished the TMSLOW
903 * register write transaction, as we risk running into
904 * a machine check exception otherwise.
905 * Do this by reading the register back to commit the
906 * PCI write and delay an additional usec for the device
907 * to react to the change. */
908 ssb_read32(dev, SSB_TMSLOW);
912 void ssb_device_enable(struct ssb_device *dev, u32 core_specific_flags)
916 ssb_device_disable(dev, core_specific_flags);
917 ssb_write32(dev, SSB_TMSLOW,
918 SSB_TMSLOW_RESET | SSB_TMSLOW_CLOCK |
919 SSB_TMSLOW_FGC | core_specific_flags);
920 ssb_flush_tmslow(dev);
922 /* Clear SERR if set. This is a hw bug workaround. */
923 if (ssb_read32(dev, SSB_TMSHIGH) & SSB_TMSHIGH_SERR)
924 ssb_write32(dev, SSB_TMSHIGH, 0);
926 val = ssb_read32(dev, SSB_IMSTATE);
927 if (val & (SSB_IMSTATE_IBE | SSB_IMSTATE_TO)) {
928 val &= ~(SSB_IMSTATE_IBE | SSB_IMSTATE_TO);
929 ssb_write32(dev, SSB_IMSTATE, val);
932 ssb_write32(dev, SSB_TMSLOW,
933 SSB_TMSLOW_CLOCK | SSB_TMSLOW_FGC |
934 core_specific_flags);
935 ssb_flush_tmslow(dev);
937 ssb_write32(dev, SSB_TMSLOW, SSB_TMSLOW_CLOCK |
938 core_specific_flags);
939 ssb_flush_tmslow(dev);
941 EXPORT_SYMBOL(ssb_device_enable);
943 /* Wait for a bit in a register to get set or unset.
944 * timeout is in units of ten-microseconds */
945 static int ssb_wait_bit(struct ssb_device *dev, u16 reg, u32 bitmask,
946 int timeout, int set)
951 for (i = 0; i < timeout; i++) {
952 val = ssb_read32(dev, reg);
957 if (!(val & bitmask))
962 printk(KERN_ERR PFX "Timeout waiting for bitmask %08X on "
963 "register %04X to %s.\n",
964 bitmask, reg, (set ? "set" : "clear"));
969 void ssb_device_disable(struct ssb_device *dev, u32 core_specific_flags)
973 if (ssb_read32(dev, SSB_TMSLOW) & SSB_TMSLOW_RESET)
976 reject = ssb_tmslow_reject_bitmask(dev);
977 ssb_write32(dev, SSB_TMSLOW, reject | SSB_TMSLOW_CLOCK);
978 ssb_wait_bit(dev, SSB_TMSLOW, reject, 1000, 1);
979 ssb_wait_bit(dev, SSB_TMSHIGH, SSB_TMSHIGH_BUSY, 1000, 0);
980 ssb_write32(dev, SSB_TMSLOW,
981 SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
982 reject | SSB_TMSLOW_RESET |
983 core_specific_flags);
984 ssb_flush_tmslow(dev);
986 ssb_write32(dev, SSB_TMSLOW,
987 reject | SSB_TMSLOW_RESET |
988 core_specific_flags);
989 ssb_flush_tmslow(dev);
991 EXPORT_SYMBOL(ssb_device_disable);
993 u32 ssb_dma_translation(struct ssb_device *dev)
995 switch (dev->bus->bustype) {
996 case SSB_BUSTYPE_SSB:
998 case SSB_BUSTYPE_PCI:
999 case SSB_BUSTYPE_PCMCIA:
1004 EXPORT_SYMBOL(ssb_dma_translation);
1006 int ssb_dma_set_mask(struct ssb_device *ssb_dev, u64 mask)
1008 struct device *dev = ssb_dev->dev;
1010 #ifdef CONFIG_SSB_PCIHOST
1011 if (ssb_dev->bus->bustype == SSB_BUSTYPE_PCI &&
1012 !dma_supported(dev, mask))
1015 dev->coherent_dma_mask = mask;
1016 dev->dma_mask = &dev->coherent_dma_mask;
1020 EXPORT_SYMBOL(ssb_dma_set_mask);
1022 int ssb_bus_may_powerdown(struct ssb_bus *bus)
1024 struct ssb_chipcommon *cc;
1027 /* On buses where more than one core may be working
1028 * at a time, we must not powerdown stuff if there are
1029 * still cores that may want to run. */
1030 if (bus->bustype == SSB_BUSTYPE_SSB)
1034 ssb_chipco_set_clockmode(cc, SSB_CLKMODE_SLOW);
1035 err = ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 0);
1039 #ifdef CONFIG_SSB_DEBUG
1040 bus->powered_up = 0;
1044 ssb_printk(KERN_ERR PFX "Bus powerdown failed\n");
1047 EXPORT_SYMBOL(ssb_bus_may_powerdown);
1049 int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl)
1051 struct ssb_chipcommon *cc;
1053 enum ssb_clkmode mode;
1055 err = ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 1);
1059 mode = dynamic_pctl ? SSB_CLKMODE_DYNAMIC : SSB_CLKMODE_FAST;
1060 ssb_chipco_set_clockmode(cc, mode);
1062 #ifdef CONFIG_SSB_DEBUG
1063 bus->powered_up = 1;
1067 ssb_printk(KERN_ERR PFX "Bus powerup failed\n");
1070 EXPORT_SYMBOL(ssb_bus_powerup);
1072 u32 ssb_admatch_base(u32 adm)
1076 switch (adm & SSB_ADM_TYPE) {
1078 base = (adm & SSB_ADM_BASE0);
1081 SSB_WARN_ON(adm & SSB_ADM_NEG); /* unsupported */
1082 base = (adm & SSB_ADM_BASE1);
1085 SSB_WARN_ON(adm & SSB_ADM_NEG); /* unsupported */
1086 base = (adm & SSB_ADM_BASE2);
1094 EXPORT_SYMBOL(ssb_admatch_base);
1096 u32 ssb_admatch_size(u32 adm)
1100 switch (adm & SSB_ADM_TYPE) {
1102 size = ((adm & SSB_ADM_SZ0) >> SSB_ADM_SZ0_SHIFT);
1105 SSB_WARN_ON(adm & SSB_ADM_NEG); /* unsupported */
1106 size = ((adm & SSB_ADM_SZ1) >> SSB_ADM_SZ1_SHIFT);
1109 SSB_WARN_ON(adm & SSB_ADM_NEG); /* unsupported */
1110 size = ((adm & SSB_ADM_SZ2) >> SSB_ADM_SZ2_SHIFT);
1115 size = (1 << (size + 1));
1119 EXPORT_SYMBOL(ssb_admatch_size);
1121 static int __init ssb_modinit(void)
1125 /* See the comment at the ssb_is_early_boot definition */
1126 ssb_is_early_boot = 0;
1127 err = bus_register(&ssb_bustype);
1131 /* Maybe we already registered some buses at early boot.
1132 * Check for this and attach them
1135 err = ssb_attach_queued_buses();
1138 bus_unregister(&ssb_bustype);
1140 err = b43_pci_ssb_bridge_init();
1142 ssb_printk(KERN_ERR "Broadcom 43xx PCI-SSB-bridge "
1143 "initialization failed");
1144 /* don't fail SSB init because of this */
1150 subsys_initcall(ssb_modinit);
1152 static void __exit ssb_modexit(void)
1154 b43_pci_ssb_bridge_exit();
1155 bus_unregister(&ssb_bustype);
1157 module_exit(ssb_modexit)