/* * Sonics Silicon Backplane * Subsystem core * * Copyright 2005, Broadcom Corporation * Copyright 2006, 2007, Michael Buesch <m@bues.ch> * * Licensed under the GNU/GPL. See COPYING for details. */ #include "ssb_private.h" #include <linux/delay.h>#include <linux/io.h>#include <linux/module.h>#include <linux/platform_device.h>#include <linux/ssb/ssb.h>#include <linux/ssb/ssb_regs.h>#include <linux/ssb/ssb_driver_gige.h>#include <linux/dma-mapping.h>#include <linux/pci.h>#include <linux/mmc/sdio_func.h>#include <linux/slab.h> #include <pcmcia/cistpl.h>#include <pcmcia/ds.h> MODULE_DESCRIPTION("Sonics Silicon Backplane driver");MODULE_LICENSE("GPL"); /* Temporary list of yet-to-be-attached buses */static LIST_HEAD(attach_queue);/* List if running buses */static LIST_HEAD(buses);/* Software ID counter */static unsigned int next_busnumber;/* buses_mutes locks the two buslists and the next_busnumber. * Don't lock this directly, but use ssb_buses_[un]lock() below. */static DEFINE_MUTEX(buses_mutex); /* There are differences in the codeflow, if the bus is * initialized from early boot, as various needed services * are not available early. This is a mechanism to delay * these initializations to after early boot has finished. * It's also used to avoid mutex locking, as that's not * available and needed early. */static bool ssb_is_early_boot = 1; static void ssb_buses_lock(void);static void ssb_buses_unlock(void); #ifdef CONFIG_SSB_PCIHOSTstruct ssb_bus *ssb_pci_dev_to_bus(struct pci_dev *pdev){ struct ssb_bus *bus; ssb_buses_lock(); list_for_each_entry(bus, &buses, list) { if (bus->bustype == SSB_BUSTYPE_PCI && bus->host_pci == pdev) goto found; } bus = NULL;found: ssb_buses_unlock(); return bus;}#endif /* CONFIG_SSB_PCIHOST */ #ifdef CONFIG_SSB_PCMCIAHOSTstruct ssb_bus *ssb_pcmcia_dev_to_bus(struct pcmcia_device *pdev){ struct ssb_bus *bus; ssb_buses_lock(); list_for_each_entry(bus, &buses, list) { if (bus->bustype == SSB_BUSTYPE_PCMCIA && bus->host_pcmcia == pdev) goto found; } bus = NULL;found: ssb_buses_unlock(); return bus;}#endif /* CONFIG_SSB_PCMCIAHOST */ int ssb_for_each_bus_call(unsigned long data, int (*func)(struct ssb_bus *bus, unsigned long data)){ struct ssb_bus *bus; int res; ssb_buses_lock(); list_for_each_entry(bus, &buses, list) { res = func(bus, data); if (res >= 0) { ssb_buses_unlock(); return res; } } ssb_buses_unlock(); return -ENODEV;} static struct ssb_device *ssb_device_get(struct ssb_device *dev){ if (dev) get_device(dev->dev); return dev;} static void ssb_device_put(struct ssb_device *dev){ if (dev) put_device(dev->dev);} static int ssb_device_resume(struct device *dev){ struct ssb_device *ssb_dev = dev_to_ssb_dev(dev); struct ssb_driver *ssb_drv; int err = 0; if (dev->driver) { ssb_drv = drv_to_ssb_drv(dev->driver); if (ssb_drv && ssb_drv->resume) err = ssb_drv->resume(ssb_dev); if (err) goto out; }out: return err;} static int ssb_device_suspend(struct device *dev, pm_message_t state){ struct ssb_device *ssb_dev = dev_to_ssb_dev(dev); struct ssb_driver *ssb_drv; int err = 0; if (dev->driver) { ssb_drv = drv_to_ssb_drv(dev->driver); if (ssb_drv && ssb_drv->suspend) err = ssb_drv->suspend(ssb_dev, state); if (err) goto out; }out: return err;} int ssb_bus_resume(struct ssb_bus *bus){ int err; /* Reset HW state information in memory, so that HW is * completely reinitialized. */ bus->mapped_device = NULL;#ifdef CONFIG_SSB_DRIVER_PCICORE bus->pcicore.setup_done = 0;#endif err = ssb_bus_powerup(bus, 0); if (err) return err; err = ssb_pcmcia_hardware_setup(bus); if (err) { ssb_bus_may_powerdown(bus); return err; } ssb_chipco_resume(&bus->chipco); ssb_bus_may_powerdown(bus); return 0;}EXPORT_SYMBOL(ssb_bus_resume); int ssb_bus_suspend(struct ssb_bus *bus){ ssb_chipco_suspend(&bus->chipco); ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 0); return 0;}EXPORT_SYMBOL(ssb_bus_suspend); #ifdef CONFIG_SSB_SPROM/** ssb_devices_freeze - Freeze all devices on the bus. * * After freezing no device driver will be handling a device * on this bus anymore. ssb_devices_thaw() must be called after * a successful freeze to reactivate the devices. * * @bus: The bus. * @ctx: Context structure. Pass this to ssb_devices_thaw(). */int ssb_devices_freeze(struct ssb_bus *bus, struct ssb_freeze_context *ctx){ struct ssb_device *sdev; struct ssb_driver *sdrv; unsigned int i; memset(ctx, 0, sizeof(*ctx)); ctx->bus = bus; WARN_ON(bus->nr_devices > ARRAY_SIZE(ctx->device_frozen)); for (i = 0; i < bus->nr_devices; i++) { sdev = ssb_device_get(&bus->devices[i]); if (!sdev->dev || !sdev->dev->driver || !device_is_registered(sdev->dev)) { ssb_device_put(sdev); continue; } sdrv = drv_to_ssb_drv(sdev->dev->driver); if (WARN_ON(!sdrv->remove)) continue; sdrv->remove(sdev); ctx->device_frozen[i] = 1; } return 0;} /** ssb_devices_thaw - Unfreeze all devices on the bus. * * This will re-attach the device drivers and re-init the devices. * * @ctx: The context structure from ssb_devices_freeze() */int ssb_devices_thaw(struct ssb_freeze_context *ctx){ struct ssb_bus *bus = ctx->bus; struct ssb_device *sdev; struct ssb_driver *sdrv; unsigned int i; int err, result = 0; for (i = 0; i < bus->nr_devices; i++) { if (!ctx->device_frozen[i]) continue; sdev = &bus->devices[i]; if (WARN_ON(!sdev->dev || !sdev->dev->driver)) continue; sdrv = drv_to_ssb_drv(sdev->dev->driver); if (WARN_ON(!sdrv || !sdrv->probe)) continue; err = sdrv->probe(sdev, &sdev->id); if (err) { dev_err(sdev->dev, "Failed to thaw device %s\n", dev_name(sdev->dev)); result = err; } ssb_device_put(sdev); } return result;}#endif /* CONFIG_SSB_SPROM */ static void ssb_device_shutdown(struct device *dev){ struct ssb_device *ssb_dev = dev_to_ssb_dev(dev); struct ssb_driver *ssb_drv; if (!dev->driver) return; ssb_drv = drv_to_ssb_drv(dev->driver); if (ssb_drv && ssb_drv->shutdown) ssb_drv->shutdown(ssb_dev);} static void ssb_device_remove(struct device *dev){ struct ssb_device *ssb_dev = dev_to_ssb_dev(dev); struct ssb_driver *ssb_drv = drv_to_ssb_drv(dev->driver); if (ssb_drv && ssb_drv->remove) ssb_drv->remove(ssb_dev); ssb_device_put(ssb_dev);} static int ssb_device_probe(struct device *dev){ struct ssb_device *ssb_dev = dev_to_ssb_dev(dev); struct ssb_driver *ssb_drv = drv_to_ssb_drv(dev->driver); int err = 0; ssb_device_get(ssb_dev); if (ssb_drv && ssb_drv->probe) err = ssb_drv->probe(ssb_dev, &ssb_dev->id); if (err) ssb_device_put(ssb_dev); return err;} static int ssb_match_devid(const struct ssb_device_id *tabid, const struct ssb_device_id *devid){ if ((tabid->vendor != devid->vendor) && tabid->vendor != SSB_ANY_VENDOR) return 0; if ((tabid->coreid != devid->coreid) && tabid->coreid != SSB_ANY_ID) return 0; if ((tabid->revision != devid->revision) && tabid->revision != SSB_ANY_REV) return 0; return 1;} static int ssb_bus_match(struct device *dev, const struct device_driver *drv){ struct ssb_device *ssb_dev = dev_to_ssb_dev(dev); const struct ssb_driver *ssb_drv = drv_to_ssb_drv(drv); const struct ssb_device_id *id; for (id = ssb_drv->id_table; id->vendor || id->coreid || id->revision; id++) { if (ssb_match_devid(id, &ssb_dev->id)) return 1; /* found */ } return 0;} static int ssb_device_uevent(const struct device *dev, struct kobj_uevent_env *env){ const struct ssb_device *ssb_dev; if (!dev) return -ENODEV; ssb_dev = dev_to_ssb_dev(dev); return add_uevent_var(env, "MODALIAS=ssb:v%04Xid%04Xrev%02X", ssb_dev->id.vendor, ssb_dev->id.coreid, ssb_dev->id.revision);} #define ssb_config_attr(attrib, field, format_string) \static ssize_t \attrib##_show(struct device *dev, struct device_attribute *attr, char *buf) \{ \ return sprintf(buf, format_string, dev_to_ssb_dev(dev)->field); \} \static DEVICE_ATTR_RO(attrib); ssb_config_attr(core_num, core_index, "%u\n")ssb_config_attr(coreid, id.coreid, "0x%04x\n")ssb_config_attr(vendor, id.vendor, "0x%04x\n")ssb_config_attr(revision, id.revision, "%u\n")ssb_config_attr(irq, irq, "%u\n")static ssize_tname_show(struct device *dev, struct device_attribute *attr, char *buf){ return sprintf(buf, "%s\n", ssb_core_name(dev_to_ssb_dev(dev)->id.coreid));}static DEVICE_ATTR_RO(name); static struct attribute *ssb_device_attrs[] = { &dev_attr_name.attr, &dev_attr_core_num.attr, &dev_attr_coreid.attr, &dev_attr_vendor.attr, &dev_attr_revision.attr, &dev_attr_irq.attr, NULL,};ATTRIBUTE_GROUPS(ssb_device); static const struct bus_type ssb_bustype = { .name = "ssb", .match = ssb_bus_match, .probe = ssb_device_probe, .remove = ssb_device_remove, .shutdown = ssb_device_shutdown, .suspend = ssb_device_suspend, .resume = ssb_device_resume, .uevent = ssb_device_uevent, .dev_groups = ssb_device_groups,}; static void ssb_buses_lock(void){ /* See the comment at the ssb_is_early_boot definition */ if (!ssb_is_early_boot) mutex_lock(&buses_mutex);} static void ssb_buses_unlock(void){ /* See the comment at the ssb_is_early_boot definition */ if (!ssb_is_early_boot) mutex_unlock(&buses_mutex);} static void ssb_devices_unregister(struct ssb_bus *bus){ struct ssb_device *sdev; int i; for (i = bus->nr_devices - 1; i >= 0; i--) { sdev = &(bus->devices[i]); if (sdev->dev) device_unregister(sdev->dev); } #ifdef CONFIG_SSB_EMBEDDED if (bus->bustype == SSB_BUSTYPE_SSB) platform_device_unregister(bus->watchdog);#endif} void ssb_bus_unregister(struct ssb_bus *bus){ int err; err = ssb_gpio_unregister(bus); if (err) pr_debug("Can not unregister GPIO driver: %i\n", err); ssb_buses_lock(); ssb_devices_unregister(bus); list_del(&bus->list); ssb_buses_unlock(); ssb_pcmcia_exit(bus); ssb_pci_exit(bus); ssb_iounmap(bus);}EXPORT_SYMBOL(ssb_bus_unregister); static void ssb_release_dev(struct device *dev){ struct __ssb_dev_wrapper *devwrap; devwrap = container_of(dev, struct __ssb_dev_wrapper, dev); kfree(devwrap);} static int ssb_devices_register(struct ssb_bus *bus){ struct ssb_device *sdev; struct device *dev; struct __ssb_dev_wrapper *devwrap; int i, err = 0; int dev_idx = 0; for (i = 0; i < bus->nr_devices; i++) { sdev = &(bus->devices[i]); /* We don't register SSB-system devices to the kernel, * as the drivers for them are built into SSB. */ switch (sdev->id.coreid) { case SSB_DEV_CHIPCOMMON: case SSB_DEV_PCI: case SSB_DEV_PCIE: case SSB_DEV_PCMCIA: case SSB_DEV_MIPS: case SSB_DEV_MIPS_3302: case SSB_DEV_EXTIF: continue; } devwrap = kzalloc_obj(*devwrap); if (!devwrap) { err = -ENOMEM; goto error; } dev = &devwrap->dev; devwrap->sdev = sdev; dev->release = ssb_release_dev; dev->bus = &ssb_bustype; dev_set_name(dev, "ssb%u:%d", bus->busnumber, dev_idx); switch (bus->bustype) { case SSB_BUSTYPE_PCI:#ifdef CONFIG_SSB_PCIHOST sdev->irq = bus->host_pci->irq; dev->parent = &bus->host_pci->dev;Lines 1–500 of 1341. Load more
/* * Sonics Silicon Backplane * Subsystem core * * Copyright 2005, Broadcom Corporation * Copyright 2006, 2007, Michael Buesch <m@bues.ch> * * Licensed under the GNU/GPL. See COPYING for details. */ #include "ssb_private.h" #include <linux/delay.h> #include <linux/io.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/ssb/ssb.h> #include <linux/ssb/ssb_regs.h> #include <linux/ssb/ssb_driver_gige.h> #include <linux/dma-mapping.h> #include <linux/pci.h> #include <linux/mmc/sdio_func.h> #include <linux/slab.h> #include <pcmcia/cistpl.h> #include <pcmcia/ds.h> MODULE_DESCRIPTION("Sonics Silicon Backplane driver"); MODULE_LICENSE("GPL"); /* Temporary list of yet-to-be-attached buses */ static LIST_HEAD(attach_queue); /* List if running buses */ static LIST_HEAD(buses); /* Software ID counter */ static unsigned int next_busnumber; /* buses_mutes locks the two buslists and the next_busnumber. * Don't lock this directly, but use ssb_buses_[un]lock() below. */ static DEFINE_MUTEX(buses_mutex); /* There are differences in the codeflow, if the bus is * initialized from early boot, as various needed services * are not available early. This is a mechanism to delay * these initializations to after early boot has finished. * It's also used to avoid mutex locking, as that's not * available and needed early. */ static bool ssb_is_early_boot = 1; static void ssb_buses_lock(void); static void ssb_buses_unlock(void); #ifdef CONFIG_SSB_PCIHOST struct ssb_bus *ssb_pci_dev_to_bus(struct pci_dev *pdev) { struct ssb_bus *bus; ssb_buses_lock(); list_for_each_entry(bus, &buses, list) { if (bus->bustype == SSB_BUSTYPE_PCI && bus->host_pci == pdev) goto found; } bus = NULL; found: ssb_buses_unlock(); return bus; } #endif /* CONFIG_SSB_PCIHOST */ #ifdef CONFIG_SSB_PCMCIAHOST struct ssb_bus *ssb_pcmcia_dev_to_bus(struct pcmcia_device *pdev) { struct ssb_bus *bus; ssb_buses_lock(); list_for_each_entry(bus, &buses, list) { if (bus->bustype == SSB_BUSTYPE_PCMCIA && bus->host_pcmcia == pdev) goto found; } bus = NULL; found: ssb_buses_unlock(); return bus; } #endif /* CONFIG_SSB_PCMCIAHOST */ int ssb_for_each_bus_call(unsigned long data, int (*func)(struct ssb_bus *bus, unsigned long data)) { struct ssb_bus *bus; int res; ssb_buses_lock(); list_for_each_entry(bus, &buses, list) { res = func(bus, data); if (res >= 0) { ssb_buses_unlock(); return res; } } ssb_buses_unlock(); return -ENODEV; } static struct ssb_device *ssb_device_get(struct ssb_device *dev) { if (dev) get_device(dev->dev); return dev; } static void ssb_device_put(struct ssb_device *dev) { if (dev) put_device(dev->dev); } static int ssb_device_resume(struct device *dev) { struct ssb_device *ssb_dev = dev_to_ssb_dev(dev); struct ssb_driver *ssb_drv; int err = 0; if (dev->driver) { ssb_drv = drv_to_ssb_drv(dev->driver); if (ssb_drv && ssb_drv->resume) err = ssb_drv->resume(ssb_dev); if (err) goto out; } out: return err; } static int ssb_device_suspend(struct device *dev, pm_message_t state) { struct ssb_device *ssb_dev = dev_to_ssb_dev(dev); struct ssb_driver *ssb_drv; int err = 0; if (dev->driver) { ssb_drv = drv_to_ssb_drv(dev->driver); if (ssb_drv && ssb_drv->suspend) err = ssb_drv->suspend(ssb_dev, state); if (err) goto out; } out: return err; } int ssb_bus_resume(struct ssb_bus *bus) { int err; /* Reset HW state information in memory, so that HW is * completely reinitialized. */ bus->mapped_device = NULL; #ifdef CONFIG_SSB_DRIVER_PCICORE bus->pcicore.setup_done = 0; #endif err = ssb_bus_powerup(bus, 0); if (err) return err; err = ssb_pcmcia_hardware_setup(bus); if (err) { ssb_bus_may_powerdown(bus); return err; } ssb_chipco_resume(&bus->chipco); ssb_bus_may_powerdown(bus); return 0; } EXPORT_SYMBOL(ssb_bus_resume); int ssb_bus_suspend(struct ssb_bus *bus) { ssb_chipco_suspend(&bus->chipco); ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 0); return 0; } EXPORT_SYMBOL(ssb_bus_suspend); #ifdef CONFIG_SSB_SPROM /** ssb_devices_freeze - Freeze all devices on the bus. * * After freezing no device driver will be handling a device * on this bus anymore. ssb_devices_thaw() must be called after * a successful freeze to reactivate the devices. * * @bus: The bus. * @ctx: Context structure. Pass this to ssb_devices_thaw(). */ int ssb_devices_freeze(struct ssb_bus *bus, struct ssb_freeze_context *ctx) { struct ssb_device *sdev; struct ssb_driver *sdrv; unsigned int i; memset(ctx, 0, sizeof(*ctx)); ctx->bus = bus; WARN_ON(bus->nr_devices > ARRAY_SIZE(ctx->device_frozen)); for (i = 0; i < bus->nr_devices; i++) { sdev = ssb_device_get(&bus->devices[i]); if (!sdev->dev || !sdev->dev->driver || !device_is_registered(sdev->dev)) { ssb_device_put(sdev); continue; } sdrv = drv_to_ssb_drv(sdev->dev->driver); if (WARN_ON(!sdrv->remove)) continue; sdrv->remove(sdev); ctx->device_frozen[i] = 1; } return 0; } /** ssb_devices_thaw - Unfreeze all devices on the bus. * * This will re-attach the device drivers and re-init the devices. * * @ctx: The context structure from ssb_devices_freeze() */ int ssb_devices_thaw(struct ssb_freeze_context *ctx) { struct ssb_bus *bus = ctx->bus; struct ssb_device *sdev; struct ssb_driver *sdrv; unsigned int i; int err, result = 0; for (i = 0; i < bus->nr_devices; i++) { if (!ctx->device_frozen[i]) continue; sdev = &bus->devices[i]; if (WARN_ON(!sdev->dev || !sdev->dev->driver)) continue; sdrv = drv_to_ssb_drv(sdev->dev->driver); if (WARN_ON(!sdrv || !sdrv->probe)) continue; err = sdrv->probe(sdev, &sdev->id); if (err) { dev_err(sdev->dev, "Failed to thaw device %s\n", dev_name(sdev->dev)); result = err; } ssb_device_put(sdev); } return result; } #endif /* CONFIG_SSB_SPROM */ static void ssb_device_shutdown(struct device *dev) { struct ssb_device *ssb_dev = dev_to_ssb_dev(dev); struct ssb_driver *ssb_drv; if (!dev->driver) return; ssb_drv = drv_to_ssb_drv(dev->driver); if (ssb_drv && ssb_drv->shutdown) ssb_drv->shutdown(ssb_dev); } static void ssb_device_remove(struct device *dev) { struct ssb_device *ssb_dev = dev_to_ssb_dev(dev); struct ssb_driver *ssb_drv = drv_to_ssb_drv(dev->driver); if (ssb_drv && ssb_drv->remove) ssb_drv->remove(ssb_dev); ssb_device_put(ssb_dev); } static int ssb_device_probe(struct device *dev) { struct ssb_device *ssb_dev = dev_to_ssb_dev(dev); struct ssb_driver *ssb_drv = drv_to_ssb_drv(dev->driver); int err = 0; ssb_device_get(ssb_dev); if (ssb_drv && ssb_drv->probe) err = ssb_drv->probe(ssb_dev, &ssb_dev->id); if (err) ssb_device_put(ssb_dev); return err; } static int ssb_match_devid(const struct ssb_device_id *tabid, const struct ssb_device_id *devid) { if ((tabid->vendor != devid->vendor) && tabid->vendor != SSB_ANY_VENDOR) return 0; if ((tabid->coreid != devid->coreid) && tabid->coreid != SSB_ANY_ID) return 0; if ((tabid->revision != devid->revision) && tabid->revision != SSB_ANY_REV) return 0; return 1; } static int ssb_bus_match(struct device *dev, const struct device_driver *drv) { struct ssb_device *ssb_dev = dev_to_ssb_dev(dev); const struct ssb_driver *ssb_drv = drv_to_ssb_drv(drv); const struct ssb_device_id *id; for (id = ssb_drv->id_table; id->vendor || id->coreid || id->revision; id++) { if (ssb_match_devid(id, &ssb_dev->id)) return 1; /* found */ } return 0; } static int ssb_device_uevent(const struct device *dev, struct kobj_uevent_env *env) { const struct ssb_device *ssb_dev; if (!dev) return -ENODEV; ssb_dev = dev_to_ssb_dev(dev); return add_uevent_var(env, "MODALIAS=ssb:v%04Xid%04Xrev%02X", ssb_dev->id.vendor, ssb_dev->id.coreid, ssb_dev->id.revision); } #define ssb_config_attr(attrib, field, format_string) \ static ssize_t \ attrib##_show(struct device *dev, struct device_attribute *attr, char *buf) \ { \ return sprintf(buf, format_string, dev_to_ssb_dev(dev)->field); \ } \ static DEVICE_ATTR_RO(attrib); ssb_config_attr(core_num, core_index, "%u\n") ssb_config_attr(coreid, id.coreid, "0x%04x\n") ssb_config_attr(vendor, id.vendor, "0x%04x\n") ssb_config_attr(revision, id.revision, "%u\n") ssb_config_attr(irq, irq, "%u\n") static ssize_t name_show(struct device *dev, struct device_attribute *attr, char *buf) { return sprintf(buf, "%s\n", ssb_core_name(dev_to_ssb_dev(dev)->id.coreid)); } static DEVICE_ATTR_RO(name); static struct attribute *ssb_device_attrs[] = { &dev_attr_name.attr, &dev_attr_core_num.attr, &dev_attr_coreid.attr, &dev_attr_vendor.attr, &dev_attr_revision.attr, &dev_attr_irq.attr, NULL, }; ATTRIBUTE_GROUPS(ssb_device); static const struct bus_type ssb_bustype = { .name = "ssb", .match = ssb_bus_match, .probe = ssb_device_probe, .remove = ssb_device_remove, .shutdown = ssb_device_shutdown, .suspend = ssb_device_suspend, .resume = ssb_device_resume, .uevent = ssb_device_uevent, .dev_groups = ssb_device_groups, }; static void ssb_buses_lock(void) { /* See the comment at the ssb_is_early_boot definition */ if (!ssb_is_early_boot) mutex_lock(&buses_mutex); } static void ssb_buses_unlock(void) { /* See the comment at the ssb_is_early_boot definition */ if (!ssb_is_early_boot) mutex_unlock(&buses_mutex); } static void ssb_devices_unregister(struct ssb_bus *bus) { struct ssb_device *sdev; int i; for (i = bus->nr_devices - 1; i >= 0; i--) { sdev = &(bus->devices[i]); if (sdev->dev) device_unregister(sdev->dev); } #ifdef CONFIG_SSB_EMBEDDED if (bus->bustype == SSB_BUSTYPE_SSB) platform_device_unregister(bus->watchdog); #endif } void ssb_bus_unregister(struct ssb_bus *bus) { int err; err = ssb_gpio_unregister(bus); if (err) pr_debug("Can not unregister GPIO driver: %i\n", err); ssb_buses_lock(); ssb_devices_unregister(bus); list_del(&bus->list); ssb_buses_unlock(); ssb_pcmcia_exit(bus); ssb_pci_exit(bus); ssb_iounmap(bus); } EXPORT_SYMBOL(ssb_bus_unregister); static void ssb_release_dev(struct device *dev) { struct __ssb_dev_wrapper *devwrap; devwrap = container_of(dev, struct __ssb_dev_wrapper, dev); kfree(devwrap); } static int ssb_devices_register(struct ssb_bus *bus) { struct ssb_device *sdev; struct device *dev; struct __ssb_dev_wrapper *devwrap; int i, err = 0; int dev_idx = 0; for (i = 0; i < bus->nr_devices; i++) { sdev = &(bus->devices[i]); /* We don't register SSB-system devices to the kernel, * as the drivers for them are built into SSB. */ switch (sdev->id.coreid) { case SSB_DEV_CHIPCOMMON: case SSB_DEV_PCI: case SSB_DEV_PCIE: case SSB_DEV_PCMCIA: case SSB_DEV_MIPS: case SSB_DEV_MIPS_3302: case SSB_DEV_EXTIF: continue; } devwrap = kzalloc_obj(*devwrap); if (!devwrap) { err = -ENOMEM; goto error; } dev = &devwrap->dev; devwrap->sdev = sdev; dev->release = ssb_release_dev; dev->bus = &ssb_bustype; dev_set_name(dev, "ssb%u:%d", bus->busnumber, dev_idx); switch (bus->bustype) { case SSB_BUSTYPE_PCI: #ifdef CONFIG_SSB_PCIHOST sdev->irq = bus->host_pci->irq; dev->parent = &bus->host_pci->dev;