summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@sunset.davemloft.net>2006-06-23 01:44:10 -0700
committerDavid S. Miller <davem@sunset.davemloft.net>2006-06-23 23:15:43 -0700
commita2bd4fd17926d715a470fbe0ebe05128ba410984 (patch)
tree3e39a2f6aaf3a628b955067ef3668cae3456de03
parent8cd24ed4f8031636fb5dacb04adee9e02556ecd5 (diff)
[SPARC64]: Add of_device layer and make ebus/isa use it.
Sparcspkr and power drivers are converted, to make sure it works. Eventually the SBUS device layer will use this as a sub-class. I really cannot cut loose on that bit until sparc32 is given the same infrastructure. Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--arch/sparc64/kernel/Makefile2
-rw-r--r--arch/sparc64/kernel/ebus.c21
-rw-r--r--arch/sparc64/kernel/isa.c37
-rw-r--r--arch/sparc64/kernel/of_device.c279
-rw-r--r--arch/sparc64/kernel/power.c109
-rw-r--r--drivers/input/misc/Kconfig2
-rw-r--r--drivers/input/misc/sparcspkr.c218
-rw-r--r--include/asm-sparc64/ebus.h5
-rw-r--r--include/asm-sparc64/isa.h5
-rw-r--r--include/asm-sparc64/of_device.h64
10 files changed, 585 insertions, 157 deletions
diff --git a/arch/sparc64/kernel/Makefile b/arch/sparc64/kernel/Makefile
index 7f00189ed29..86c9fe3f3e4 100644
--- a/arch/sparc64/kernel/Makefile
+++ b/arch/sparc64/kernel/Makefile
@@ -12,7 +12,7 @@ obj-y := process.o setup.o cpu.o idprom.o \
irq.o ptrace.o time.o sys_sparc.o signal.o \
unaligned.o central.o pci.o starfire.o semaphore.o \
power.o sbus.o iommu_common.o sparc64_ksyms.o chmc.o \
- visemul.o prom.o
+ visemul.o prom.o of_device.o
obj-$(CONFIG_PCI) += ebus.o isa.o pci_common.o pci_iommu.o \
pci_psycho.o pci_sabre.o pci_schizo.o \
diff --git a/arch/sparc64/kernel/ebus.c b/arch/sparc64/kernel/ebus.c
index 33d79e10c65..b390a2f3a15 100644
--- a/arch/sparc64/kernel/ebus.c
+++ b/arch/sparc64/kernel/ebus.c
@@ -475,6 +475,16 @@ probe_interrupts:
}
}
+ dev->ofdev.node = dp;
+ dev->ofdev.dev.parent = &dev->bus->ofdev.dev;
+ dev->ofdev.dev.bus = &ebus_bus_type;
+ strcpy(dev->ofdev.dev.bus_id, dp->path_component_name);
+
+ /* Register with core */
+ if (of_device_register(&dev->ofdev) != 0)
+ printk(KERN_DEBUG "ebus: device registration error for %s!\n",
+ dev->ofdev.dev.bus_id);
+
dp = dp->child;
if (dp) {
printk(" ->");
@@ -570,6 +580,17 @@ void __init ebus_init(void)
ebus->self = pdev;
ebus->parent = pbm = cookie->pbm;
+ ebus->ofdev.node = dp;
+ ebus->ofdev.dev.parent = &pdev->dev;
+ ebus->ofdev.dev.bus = &ebus_bus_type;
+ strcpy(ebus->ofdev.dev.bus_id, dp->path_component_name);
+
+ /* Register with core */
+ if (of_device_register(&ebus->ofdev) != 0)
+ printk(KERN_DEBUG "ebus: device registration error for %s!\n",
+ ebus->ofdev.dev.bus_id);
+
+
child = dp->child;
if (!child)
goto next_ebus;
diff --git a/arch/sparc64/kernel/isa.c b/arch/sparc64/kernel/isa.c
index 2693f2de549..6f16dee280a 100644
--- a/arch/sparc64/kernel/isa.c
+++ b/arch/sparc64/kernel/isa.c
@@ -195,12 +195,25 @@ static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL);
if (!isa_dev) {
- fatal_err("cannot allocate isa_dev");
- prom_halt();
+ printk(KERN_DEBUG "ISA: cannot allocate isa_dev");
+ return;
}
memset(isa_dev, 0, sizeof(*isa_dev));
+ isa_dev->ofdev.node = dp;
+ isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
+ isa_dev->ofdev.dev.bus = &isa_bus_type;
+ strcpy(isa_dev->ofdev.dev.bus_id, dp->path_component_name);
+
+ /* Register with core */
+ if (of_device_register(&isa_dev->ofdev) != 0) {
+ printk(KERN_DEBUG "isa: device registration error for %s!\n",
+ isa_dev->ofdev.dev.bus_id);
+ kfree(isa_dev);
+ goto next_sibling;
+ }
+
/* Link it in. */
isa_dev->next = NULL;
if (isa_br->devices == NULL) {
@@ -226,6 +239,7 @@ static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
printk("]");
+ next_sibling:
dp = dp->sibling;
}
}
@@ -244,6 +258,7 @@ void __init isa_init(void)
struct pcidev_cookie *pdev_cookie;
struct pci_pbm_info *pbm;
struct sparc_isa_bridge *isa_br;
+ struct device_node *dp;
pdev_cookie = pdev->sysdata;
if (!pdev_cookie) {
@@ -252,15 +267,29 @@ void __init isa_init(void)
continue;
}
pbm = pdev_cookie->pbm;
+ dp = pdev_cookie->prom_node;
isa_br = kmalloc(sizeof(*isa_br), GFP_KERNEL);
if (!isa_br) {
- fatal_err("cannot allocate sparc_isa_bridge");
- prom_halt();
+ printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge");
+ return;
}
memset(isa_br, 0, sizeof(*isa_br));
+ isa_br->ofdev.node = dp;
+ isa_br->ofdev.dev.parent = &pdev->dev;
+ isa_br->ofdev.dev.bus = &isa_bus_type;
+ strcpy(isa_br->ofdev.dev.bus_id, dp->path_component_name);
+
+ /* Register with core */
+ if (of_device_register(&isa_br->ofdev) != 0) {
+ printk(KERN_DEBUG "isa: device registration error for %s!\n",
+ isa_br->ofdev.dev.bus_id);
+ kfree(isa_br);
+ return;
+ }
+
/* Link it in. */
isa_br->next = isa_chain;
isa_chain = isa_br;
diff --git a/arch/sparc64/kernel/of_device.c b/arch/sparc64/kernel/of_device.c
new file mode 100644
index 00000000000..566aa343aa6
--- /dev/null
+++ b/arch/sparc64/kernel/of_device.c
@@ -0,0 +1,279 @@
+#include <linux/config.h>
+#include <linux/string.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/slab.h>
+
+#include <asm/errno.h>
+#include <asm/of_device.h>
+
+/**
+ * of_match_device - Tell if an of_device structure has a matching
+ * of_match structure
+ * @ids: array of of device match structures to search in
+ * @dev: the of device structure to match against
+ *
+ * Used by a driver to check whether an of_device present in the
+ * system is in its list of supported devices.
+ */
+const struct of_device_id *of_match_device(const struct of_device_id *matches,
+ const struct of_device *dev)
+{
+ if (!dev->node)
+ return NULL;
+ while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
+ int match = 1;
+ if (matches->name[0])
+ match &= dev->node->name
+ && !strcmp(matches->name, dev->node->name);
+ if (matches->type[0])
+ match &= dev->node->type
+ && !strcmp(matches->type, dev->node->type);
+ if (matches->compatible[0])
+ match &= of_device_is_compatible(dev->node,
+ matches->compatible);
+ if (match)
+ return matches;
+ matches++;
+ }
+ return NULL;
+}
+
+static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
+{
+ struct of_device * of_dev = to_of_device(dev);
+ struct of_platform_driver * of_drv = to_of_platform_driver(drv);
+ const struct of_device_id * matches = of_drv->match_table;
+
+ if (!matches)
+ return 0;
+
+ return of_match_device(matches, of_dev) != NULL;
+}
+
+struct of_device *of_dev_get(struct of_device *dev)
+{
+ struct device *tmp;
+
+ if (!dev)
+ return NULL;
+ tmp = get_device(&dev->dev);
+ if (tmp)
+ return to_of_device(tmp);
+ else
+ return NULL;
+}
+
+void of_dev_put(struct of_device *dev)
+{
+ if (dev)
+ put_device(&dev->dev);
+}
+
+
+static int of_device_probe(struct device *dev)
+{
+ int error = -ENODEV;
+ struct of_platform_driver *drv;
+ struct of_device *of_dev;
+ const struct of_device_id *match;
+
+ drv = to_of_platform_driver(dev->driver);
+ of_dev = to_of_device(dev);
+
+ if (!drv->probe)
+ return error;
+
+ of_dev_get(of_dev);
+
+ match = of_match_device(drv->match_table, of_dev);
+ if (match)
+ error = drv->probe(of_dev, match);
+ if (error)
+ of_dev_put(of_dev);
+
+ return error;
+}
+
+static int of_device_remove(struct device *dev)
+{
+ struct of_device * of_dev = to_of_device(dev);
+ struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
+
+ if (dev->driver && drv->remove)
+ drv->remove(of_dev);
+ return 0;
+}
+
+static int of_device_suspend(struct device *dev, pm_message_t state)
+{
+ struct of_device * of_dev = to_of_device(dev);
+ struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
+ int error = 0;
+
+ if (dev->driver && drv->suspend)
+ error = drv->suspend(of_dev, state);
+ return error;
+}
+
+static int of_device_resume(struct device * dev)
+{
+ struct of_device * of_dev = to_of_device(dev);
+ struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
+ int error = 0;
+
+ if (dev->driver && drv->resume)
+ error = drv->resume(of_dev);
+ return error;
+}
+
+#ifdef CONFIG_PCI
+struct bus_type isa_bus_type = {
+ .name = "isa",
+ .match = of_platform_bus_match,
+ .probe = of_device_probe,
+ .remove = of_device_remove,
+ .suspend = of_device_suspend,
+ .resume = of_device_resume,
+};
+
+struct bus_type ebus_bus_type = {
+ .name = "ebus",
+ .match = of_platform_bus_match,
+ .probe = of_device_probe,
+ .remove = of_device_remove,
+ .suspend = of_device_suspend,
+ .resume = of_device_resume,
+};
+#endif
+
+#ifdef CONFIG_SBUS
+struct bus_type sbus_bus_type = {
+ .name = "sbus",
+ .match = of_platform_bus_match,
+ .probe = of_device_probe,
+ .remove = of_device_remove,
+ .suspend = of_device_suspend,
+ .resume = of_device_resume,
+};
+#endif
+
+static int __init of_bus_driver_init(void)
+{
+ int err = 0;
+
+#ifdef CONFIG_PCI
+ if (!err)
+ err = bus_register(&isa_bus_type);
+ if (!err)
+ err = bus_register(&ebus_bus_type);
+#endif
+#ifdef CONFIG_SBUS
+ if (!err)
+ err = bus_register(&sbus_bus_type);
+#endif
+ return 0;
+}
+
+postcore_initcall(of_bus_driver_init);
+
+int of_register_driver(struct of_platform_driver *drv, struct bus_type *bus)
+{
+ /* initialize common driver fields */
+ drv->driver.name = drv->name;
+ drv->driver.bus = bus;
+
+ /* register with core */
+ return driver_register(&drv->driver);
+}
+
+void of_unregister_driver(struct of_platform_driver *drv)
+{
+ driver_unregister(&drv->driver);
+}
+
+
+static ssize_t dev_show_devspec(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ struct of_device *ofdev;
+
+ ofdev = to_of_device(dev);
+ return sprintf(buf, "%s", ofdev->node->full_name);
+}
+
+static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL);
+
+/**
+ * of_release_dev - free an of device structure when all users of it are finished.
+ * @dev: device that's been disconnected
+ *
+ * Will be called only by the device core when all users of this of device are
+ * done.
+ */
+void of_release_dev(struct device *dev)
+{
+ struct of_device *ofdev;
+
+ ofdev = to_of_device(dev);
+
+ kfree(ofdev);
+}
+
+int of_device_register(struct of_device *ofdev)
+{
+ int rc;
+
+ BUG_ON(ofdev->node == NULL);
+
+ rc = device_register(&ofdev->dev);
+ if (rc)
+ return rc;
+
+ device_create_file(&ofdev->dev, &dev_attr_devspec);
+
+ return 0;
+}
+
+void of_device_unregister(struct of_device *ofdev)
+{
+ device_remove_file(&ofdev->dev, &dev_attr_devspec);
+ device_unregister(&ofdev->dev);
+}
+
+struct of_device* of_platform_device_create(struct device_node *np,
+ const char *bus_id,
+ struct device *parent,
+ struct bus_type *bus)
+{
+ struct of_device *dev;
+
+ dev = kmalloc(sizeof(*dev), GFP_KERNEL);
+ if (!dev)
+ return NULL;
+ memset(dev, 0, sizeof(*dev));
+
+ dev->dev.parent = parent;
+ dev->dev.bus = bus;
+ dev->dev.release = of_release_dev;
+
+ strlcpy(dev->dev.bus_id, bus_id, BUS_ID_SIZE);
+
+ if (of_device_register(dev) != 0) {
+ kfree(dev);
+ return NULL;
+ }
+
+ return dev;
+}
+
+EXPORT_SYMBOL(of_match_device);
+EXPORT_SYMBOL(of_register_driver);
+EXPORT_SYMBOL(of_unregister_driver);
+EXPORT_SYMBOL(of_device_register);
+EXPORT_SYMBOL(of_device_unregister);
+EXPORT_SYMBOL(of_dev_get);
+EXPORT_SYMBOL(of_dev_put);
+EXPORT_SYMBOL(of_platform_device_create);
+EXPORT_SYMBOL(of_release_dev);
diff --git a/arch/sparc64/kernel/power.c b/arch/sparc64/kernel/power.c
index 75159a7843f..9496c773401 100644
--- a/arch/sparc64/kernel/power.c
+++ b/arch/sparc64/kernel/power.c
@@ -115,66 +115,15 @@ static int __init has_button_interrupt(unsigned int irq, struct device_node *dp)
return 1;
}
-static int __init power_probe_ebus(struct resource **resp, unsigned int *irq_p, struct device_node **prom_node_p)
+static void __devinit power_probe_common(struct of_device *dev, struct resource *res, unsigned int irq)
{
- struct linux_ebus *ebus;
- struct linux_ebus_device *edev;
-
- for_each_ebus(ebus) {
- for_each_ebusdev(edev, ebus) {
- if (!strcmp(edev->prom_node->name, "power")) {
- *resp = &edev->resource[0];
- *irq_p = edev->irqs[0];
- *prom_node_p = edev->prom_node;
- return 0;
- }
- }
- }
- return -ENODEV;
-}
-
-static int __init power_probe_isa(struct resource **resp, unsigned int *irq_p, struct device_node **prom_node_p)
-{
- struct sparc_isa_bridge *isa_bus;
- struct sparc_isa_device *isa_dev;
-
- for_each_isa(isa_bus) {
- for_each_isadev(isa_dev, isa_bus) {
- if (!strcmp(isa_dev->prom_node->name, "power")) {
- *resp = &isa_dev->resource;
- *irq_p = isa_dev->irq;
- *prom_node_p = isa_dev->prom_node;
- return 0;
- }
- }
- }
- return -ENODEV;
-}
-
-void __init power_init(void)
-{
- struct resource *res = NULL;
- unsigned int irq;
- struct device_node *dp;
- static int invoked;
-
- if (invoked)
- return;
- invoked = 1;
-
- if (!power_probe_ebus(&res, &irq, &dp))
- goto found;
-
- if (!power_probe_isa(&res, &irq, &dp))
- goto found;
-
- return;
-
-found:
power_reg = ioremap(res->start, 0x4);
+
printk("power: Control reg at %p ... ", power_reg);
+
poweroff_method = machine_halt; /* able to use the standard halt */
- if (has_button_interrupt(irq, dp)) {
+
+ if (has_button_interrupt(irq, dev->node)) {
if (kernel_thread(powerd, NULL, CLONE_FS) < 0) {
printk("Failed to start power daemon.\n");
return;
@@ -188,4 +137,52 @@ found:
printk("not using powerd.\n");
}
}
+
+static struct of_device_id power_match[] = {
+ {
+ .name = "power",
+ },
+ {},
+};
+
+static int __devinit ebus_power_probe(struct of_device *dev, const struct of_device_id *match)
+{
+ struct linux_ebus_device *edev = to_ebus_device(&dev->dev);
+ struct resource *res = &edev->resource[0];
+ unsigned int irq = edev->irqs[0];
+
+ power_probe_common(dev, res,irq);
+
+ return 0;
+}
+
+static struct of_platform_driver ebus_power_driver = {
+ .name = "power",
+ .match_table = power_match,
+ .probe = ebus_power_probe,
+};
+
+static int __devinit isa_power_probe(struct of_device *dev, const struct of_device_id *match)
+{
+ struct sparc_isa_device *idev = to_isa_device(&dev->dev);
+ struct resource *res = &idev->resource;
+ unsigned int irq = idev->irq;
+
+ power_probe_common(dev, res,irq);
+
+ return 0;
+}
+
+static struct of_platform_driver isa_power_driver = {
+ .name = "power",
+ .match_table = power_match,
+ .probe = isa_power_probe,
+};
+
+void __init power_init(void)
+{
+ of_register_driver(&ebus_power_driver, &ebus_bus_type);
+ of_register_driver(&isa_power_driver, &isa_bus_type);
+ return;
+}
#endif /* CONFIG_PCI */
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 4bad588d0e5..a6dfc745573 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -26,7 +26,7 @@ config INPUT_PCSPKR
config INPUT_SPARCSPKR
tristate "SPARC Speaker support"
- depends on PCI && SPARC
+ depends on PCI && SPARC64
help
Say Y here if you want the standard Speaker on Sparc PCI systems
to be used for bells and whistles.
diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c
index ed95dc9420d..42c11fbf3c7 100644
--- a/drivers/input/misc/sparcspkr.c
+++ b/drivers/input/misc/sparcspkr.c
@@ -2,7 +2,7 @@
* Driver for PC-speaker like devices found on various Sparc systems.
*
* Copyright (c) 2002 Vojtech Pavlik
- * Copyright (c) 2002 David S. Miller (davem@redhat.com)
+ * Copyright (c) 2002, 2006 David S. Miller (davem@davemloft.net)
*/
#include <linux/config.h>
#include <linux/kernel.h>
@@ -13,21 +13,23 @@
#include <asm/io.h>
#include <asm/ebus.h>
-#ifdef CONFIG_SPARC64
#include <asm/isa.h>
-#endif
-MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
+MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
MODULE_DESCRIPTION("Sparc Speaker beeper driver");
MODULE_LICENSE("GPL");
-const char *beep_name;
-static unsigned long beep_iobase;
-static int (*beep_event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
-static DEFINE_SPINLOCK(beep_lock);
+struct sparcspkr_state {
+ const char *name;
+ unsigned long iobase;
+ int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
+ spinlock_t lock;
+ struct input_dev *input_dev;
+};
static int ebus_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
{
+ struct sparcspkr_state *state = dev_get_drvdata(dev->cdev.dev);
unsigned int count = 0;
unsigned long flags;
@@ -43,24 +45,24 @@ static int ebus_spkr_event(struct input_dev *dev, unsigned int type, unsigned in
if (value > 20 && value < 32767)
count = 1193182 / value;
- spin_lock_irqsave(&beep_lock, flags);
+ spin_lock_irqsave(&state->lock, flags);
/* EBUS speaker only has on/off state, the frequency does not
* appear to be programmable.
*/
- if (beep_iobase & 0x2UL)
- outb(!!count, beep_iobase);
+ if (state->iobase & 0x2UL)
+ outb(!!count, state->iobase);
else
- outl(!!count, beep_iobase);
+ outl(!!count, state->iobase);
- spin_unlock_irqrestore(&beep_lock, flags);
+ spin_unlock_irqrestore(&state->lock, flags);
return 0;
}
-#ifdef CONFIG_SPARC64
static int isa_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
{
+ struct sparcspkr_state *state = dev_get_drvdata(dev->cdev.dev);
unsigned int count = 0;
unsigned long flags;
@@ -76,29 +78,29 @@ static int isa_spkr_event(struct input_dev *dev, unsigned int type, unsigned int
if (value > 20 && value < 32767)
count = 1193182 / value;
- spin_lock_irqsave(&beep_lock, flags);
+ spin_lock_irqsave(&state->lock, flags);
if (count) {
/* enable counter 2 */
- outb(inb(beep_iobase + 0x61) | 3, beep_iobase + 0x61);
+ outb(inb(state->iobase + 0x61) | 3, state->iobase + 0x61);
/* set command for counter 2, 2 byte write */
- outb(0xB6, beep_iobase + 0x43);
+ outb(0xB6, state->iobase + 0x43);
/* select desired HZ */
- outb(count & 0xff, beep_iobase + 0x42);
- outb((count >> 8) & 0xff, beep_iobase + 0x42);
+ outb(count & 0xff, state->iobase + 0x42);
+ outb((count >> 8) & 0xff, state->iobase + 0x42);
} else {
/* disable counter 2 */
- outb(inb_p(beep_iobase + 0x61) & 0xFC, beep_iobase + 0x61);
+ outb(inb_p(state->iobase + 0x61) & 0xFC, state->iobase + 0x61);
}
- spin_unlock_irqrestore(&beep_lock, flags);
+ spin_unlock_irqrestore(&state->lock, flags);
return 0;
}
-#endif
-static int __devinit sparcspkr_probe(struct platform_device *dev)
+static int __devinit sparcspkr_probe(struct device *dev)
{
+ struct sparcspkr_state *state = dev_get_drvdata(dev);
struct input_dev *input_dev;
int error;
@@ -106,18 +108,18 @@ static int __devinit sparcspkr_probe(struct platform_device *dev)
if (!input_dev)
return -ENOMEM;
- input_dev->name = beep_name;
+ input_dev->name = state->name;
input_dev->phys = "sparc/input0";
input_dev->id.bustype = BUS_ISA;
input_dev->id.vendor = 0x001f;
input_dev->id.product = 0x0001;
input_dev->id.version = 0x0100;
- input_dev->cdev.dev = &dev->dev;
+ input_dev->cdev.dev = dev;
input_dev->evbit[0] = BIT(EV_SND);
input_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
- input_dev->event = beep_event;
+ input_dev->event = state->event;
error = input_register_device(input_dev);
if (error) {
@@ -125,111 +127,137 @@ static int __devinit sparcspkr_probe(struct platform_device *dev)
return error;
}
- platform_set_drvdata(dev, input_dev);
+ state->input_dev = input_dev;
return 0;
}
-static int __devexit sparcspkr_remove(struct platform_device *dev)
+static int __devexit sparcspkr_remove(struct of_device *dev)
{
- struct input_dev *input_dev = platform_get_drvdata(dev);
+ struct sparcspkr_state *state = dev_get_drvdata(&dev->dev);
+ struct input_dev *input_dev = state->input_dev;
- input_unregister_device(input_dev);
- platform_set_drvdata(dev, NULL);
/* turn off the speaker */
- beep_event(NULL, EV_SND, SND_BELL, 0);
+ state->event(input_dev, EV_SND, SND_BELL, 0);
+
+ input_unregister_device(input_dev);
+
+ dev_set_drvdata(&dev->dev, NULL);
+ kfree(state);
return 0;
}
-static void sparcspkr_shutdown(struct platform_device *dev)
+static int sparcspkr_shutdown(struct of_device *dev)
{
+ struct sparcspkr_state *state = dev_get_drvdata(&dev->dev);
+ struct input_dev *input_dev = state->input_dev;
+
/* turn off the speaker */
- beep_event(NULL, EV_SND, SND_BELL, 0);
+ state->event(input_dev, EV_SND, SND_BELL, 0);
+
+ return 0;
+}
+
+static int __devinit ebus_beep_probe(struct of_device *dev, const struct of_device_id *match)
+{
+ struct linux_ebus_device *edev = to_ebus_device(&dev->dev);
+ struct sparcspkr_state *state;
+ int err;
+
+ state = kzalloc(sizeof(*state), GFP_KERNEL);
+ if (!state)
+ return -ENOMEM;
+
+ state->name = "Sparc EBUS Speaker";
+ state->iobase = edev->resource[0].start;
+ state->event = ebus_spkr_event;
+ spin_lock_init(&state->lock);
+
+ dev_set_drvdata(&dev->dev, state);
+
+ err = sparcspkr_probe(&dev->dev);
+ if (err) {
+ dev_set_drvdata(&dev->dev, NULL);
+ kfree(state);
+ }
+
+ return 0;
}
-static struct platform_driver sparcspkr_platform_driver = {
- .driver = {
- .name = "sparcspkr",
- .owner = THIS_MODULE,
+static struct of_device_id ebus_beep_match[] = {
+ {
+ .name = "beep",
},
- .probe = sparcspkr_probe,
- .remove = __devexit_p(sparcspkr_remove),
- .shutdown = sparcspkr_shutdown,
+ {},
};
-static struct platform_device *sparcspkr_platform_device;
+static struct of_platform_driver ebus_beep_driver = {
+ .name = "beep",
+ .match_table = ebus_beep_match,
+ .probe = ebus_beep_probe,
+ .remove = sparcspkr_remove,
+ .shutdown = sparcspkr_shutdown,
+};
-static int __init sparcspkr_drv_init(void)
+static int __devinit isa_beep_probe(struct of_device *dev, const struct of_device_id *match)
{
- int error;
+ struct sparc_isa_device *idev = to_isa_device(&dev->dev);
+ struct sparcspkr_state *state;
+ int err;
- error = platform_driver_register(&sparcspkr_platform_driver);
- if (error)
- return error;
+ state = kzalloc(sizeof(*state), GFP_KERNEL);
+ if (!state)
+ return -ENOMEM;
- sparcspkr_platform_device = platform_device_alloc("sparcspkr", -1);
- if (!sparcspkr_platform_device) {
- error = -ENOMEM;
- goto err_unregister_driver;
- }
+ state->name = "Sparc ISA Speaker";
+ state->iobase = idev->resource.start;
+ state->event = isa_spkr_event;
+ spin_lock_init(&state->lock);
+
+ dev_set_drvdata(&dev->dev, state);
- error = platform_device_add(sparcspkr_platform_device);
- if (error)
- goto err_free_device;
+ err = sparcspkr_probe(&dev->dev);
+ if (err) {
+ dev_set_drvdata(&dev->dev, NULL);
+ kfree(state);
+ }
return 0;
+}
- err_free_device:
- platform_device_put(sparcspkr_platform_device);
- err_unregister_driver:
- platform_driver_unregister(&sparcspkr_platform_driver);
+static struct of_device_id isa_beep_match[] = {
+ {
+ .name = "dma",
+ },
+ {},
+};
- return error;
-}
+static struct of_platform_driver isa_beep_driver = {
+ .name = "beep",
+ .match_table = isa_beep_match,
+ .probe = isa_beep_probe,
+ .remove = sparcspkr_remove,
+ .shutdown = sparcspkr_shutdown,
+};
static int __init sparcspkr_init(void)
{
- struct linux_ebus *ebus;
- struct linux_ebus_device *edev;
-#ifdef CONFIG_SPARC64
- struct sparc_isa_bridge *isa_br;
- struct sparc_isa_device *isa_dev;
-#endif
-
- for_each_ebus(ebus) {
- for_each_ebusdev(edev, ebus) {
- if (!strcmp(edev->prom_node->name, "beep")) {
- beep_name = "Sparc EBUS Speaker";
- beep_event = ebus_spkr_event;
- beep_iobase = edev->resource[0].start;
- return sparcspkr_drv_init();
- }
- }
- }
-#ifdef CONFIG_SPARC64
- for_each_isa(isa_br) {
- for_each_isadev(isa_dev, isa_br) {
- /* A hack, the beep device's base lives in
- * the DMA isa node.
- */
- if (!strcmp(isa_dev->prom_node->name, "dma")) {
- beep_name = "Sparc ISA Speaker";
- beep_event = isa_spkr_event,
- beep_iobase = isa_dev->resource.start;
- return sparcspkr_drv_init();
- }
- }
+ int err = of_register_driver(&ebus_beep_driver, &ebus_bus_type);
+
+ if (!err) {
+ err = of_register_driver(&isa_beep_driver, &isa_bus_type);
+ if (err)
+ of_unregister_driver(&ebus_beep_driver);
}
-#endif
- return -ENODEV;
+ return err;
}
static void __exit sparcspkr_exit(void)
{
- platform_device_unregister(sparcspkr_platform_device);
- platform_driver_unregister(&sparcspkr_platform_driver);
+ of_unregister_driver(&ebus_beep_driver);
+ of_unregister_driver(&isa_beep_driver);
}
module_init(sparcspkr_init);
diff --git a/include/asm-sparc64/ebus.h b/include/asm-sparc64/ebus.h
index 545882bd356..a4afe9d5703 100644
--- a/include/asm-sparc64/ebus.h
+++ b/include/asm-sparc64/ebus.h
@@ -11,6 +11,7 @@
#include <asm/pbm.h>
#include <asm/oplib.h>
#include <asm/prom.h>
+#include <asm/of_device.h>
struct linux_ebus_child {
struct linux_ebus_child *next;
@@ -24,6 +25,7 @@ struct linux_ebus_child {
};
struct linux_ebus_device {
+ struct of_device ofdev;
struct linux_ebus_device *next;
struct linux_ebus_child *children;
struct linux_ebus *bus;
@@ -33,8 +35,10 @@ struct linux_ebus_device {
unsigned int irqs[PROMINTR_MAX];
int num_irqs;
};
+#define to_ebus_device(d) container_of(d, struct linux_ebus_device, ofdev.dev)
struct linux_ebus {
+ struct of_device ofdev;
struct linux_ebus *next;
struct linux_ebus_device *devices;
struct pci_pbm_info *parent;
@@ -43,6 +47,7 @@ struct linux_ebus {
int is_rio;
struct device_node *prom_node;
};
+#define to_ebus(d) container_of(d, struct linux_ebus, ofdev.dev)
struct ebus_dma_info {
spinlock_t lock;
diff --git a/include/asm-sparc64/isa.h b/include/asm-sparc64/isa.h
index 2e7fb18ec1b..d9728b9031f 100644
--- a/include/asm-sparc64/isa.h
+++ b/include/asm-sparc64/isa.h
@@ -10,10 +10,12 @@
#include <asm/pbm.h>
#include <asm/oplib.h>
#include <asm/prom.h>
+#include <asm/of_device.h>
struct sparc_isa_bridge;
struct sparc_isa_device {
+ struct of_device ofdev;
struct sparc_isa_device *next;
struct sparc_isa_device *child;
struct sparc_isa_bridge *bus;
@@ -21,8 +23,10 @@ struct sparc_isa_device {
struct resource resource;
unsigned int irq;
};
+#define to_isa_device(d) container_of(d, struct sparc_isa_device, ofdev.dev)
struct sparc_isa_bridge {
+ struct of_device ofdev;
struct sparc_isa_bridge *next;
struct sparc_isa_device *devices;
struct pci_pbm_info *parent;
@@ -30,6 +34,7 @@ struct sparc_isa_bridge {
int index;
struct device_node *prom_node;
};
+#define to_isa_bridge(d) container_of(d, struct sparc_isa_bridge, ofdev.dev)
extern struct sparc_isa_bridge *isa_chain;
diff --git a/include/asm-sparc64/of_device.h b/include/asm-sparc64/of_device.h
new file mode 100644
index 00000000000..ceea825899c
--- /dev/null
+++ b/include/asm-sparc64/of_device.h
@@ -0,0 +1,64 @@
+#ifndef _ASM_SPARC64_OF_DEVICE_H
+#define _ASM_SPARC64_OF_DEVICE_H
+#ifdef __KERNEL__
+
+#include <linux/device.h>
+#include <linux/mod_devicetable.h>
+#include <asm/prom.h>
+
+extern struct bus_type isa_bus_type;
+extern struct bus_type ebus_bus_type;
+extern struct bus_type sbus_bus_type;
+
+/*
+ * The of_device is a kind of "base class" that is a superset of
+ * struct device for use by devices attached to an OF node and
+ * probed using OF properties.
+ */
+struct of_device
+{
+ struct device_node *node; /* OF device node */
+ struct device dev; /* Generic device interface */
+};
+#define to_of_device(d) container_of(d, struct of_device, dev)
+
+extern const struct of_device_id *of_match_device(
+ const struct of_device_id *matches, const struct of_device *dev);
+
+extern struct of_device *of_dev_get(struct of_device *dev);
+extern void of_dev_put(struct of_device *dev);
+
+/*
+ * An of_platform_driver driver is attached to a basic of_device on
+ * the ISA, EBUS, and SBUS busses on sparc64.
+ */
+struct of_platform_driver
+{
+ char *name;
+ struct of_device_id *match_table;
+ struct module *owner;
+
+ int (*probe)(struct of_device* dev, const struct of_device_id *match);
+ int (*remove)(struct of_device* dev);
+
+ int (*suspend)(struct of_device* dev, pm_message_t state);
+ int (*resume)(struct of_device* dev);
+ int (*shutdown)(struct of_device* dev);
+
+ struct device_driver driver;
+};
+#define to_of_platform_driver(drv) container_of(drv,struct of_platform_driver, driver)
+
+extern int of_register_driver(struct of_platform_driver *drv,
+ struct bus_type *bus);
+extern void of_unregister_driver(struct of_platform_driver *drv);
+extern int of_device_register(struct of_device *ofdev);
+extern void of_device_unregister(struct of_device *ofdev);
+extern struct of_device *of_platform_device_create(struct device_node *np,
+ const char *bus_id,
+ struct device *parent,
+ struct bus_type *bus);
+extern void of_release_dev(struct device *dev);
+
+#endif /* __KERNEL__ */
+#endif /* _ASM_POWERPC_OF_DEVICE_H */