]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/block/xsysace.c
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/sparc-2.6
[linux-2.6-omap-h63xx.git] / drivers / block / xsysace.c
index 10bb4e54f68522a14daf1c0003a4d40176d7bfb9..82effce97c514601dfbc3f5d9f5e953fe98bcd5b 100644 (file)
 #include <linux/blkdev.h>
 #include <linux/hdreg.h>
 #include <linux/platform_device.h>
+#if defined(CONFIG_OF)
+#include <linux/of_device.h>
+#include <linux/of_platform.h>
+#endif
 
 MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>");
 MODULE_DESCRIPTION("Xilinx SystemACE device driver");
@@ -191,7 +195,7 @@ struct ace_device {
 
        /* Details of hardware device */
        unsigned long physaddr;
-       void *baseaddr;
+       void __iomem *baseaddr;
        int irq;
        int bus_width;          /* 0 := 8 bit; 1 := 16 bit */
        struct ace_reg_ops *reg_ops;
@@ -223,20 +227,20 @@ struct ace_reg_ops {
 /* 8 Bit bus width */
 static u16 ace_in_8(struct ace_device *ace, int reg)
 {
-       void *r = ace->baseaddr + reg;
+       void __iomem *r = ace->baseaddr + reg;
        return in_8(r) | (in_8(r + 1) << 8);
 }
 
 static void ace_out_8(struct ace_device *ace, int reg, u16 val)
 {
-       void *r = ace->baseaddr + reg;
+       void __iomem *r = ace->baseaddr + reg;
        out_8(r, val);
        out_8(r + 1, val >> 8);
 }
 
 static void ace_datain_8(struct ace_device *ace)
 {
-       void *r = ace->baseaddr + 0x40;
+       void __iomem *r = ace->baseaddr + 0x40;
        u8 *dst = ace->data_ptr;
        int i = ACE_FIFO_SIZE;
        while (i--)
@@ -246,7 +250,7 @@ static void ace_datain_8(struct ace_device *ace)
 
 static void ace_dataout_8(struct ace_device *ace)
 {
-       void *r = ace->baseaddr + 0x40;
+       void __iomem *r = ace->baseaddr + 0x40;
        u8 *src = ace->data_ptr;
        int i = ACE_FIFO_SIZE;
        while (i--)
@@ -386,8 +390,8 @@ static inline void ace_dump_mem(void *base, int len)
 static void ace_dump_regs(struct ace_device *ace)
 {
        dev_info(ace->dev, "    ctrl:  %.8x  seccnt/cmd: %.4x      ver:%.4x\n"
-                "    status:%.8x  mpu_lba:%.8x  busmode:%4x\n"
-                "    error: %.8x  cfg_lba:%.8x  fatstat:%.4x\n",
+                KERN_INFO "    status:%.8x  mpu_lba:%.8x  busmode:%4x\n"
+                KERN_INFO "    error: %.8x  cfg_lba:%.8x  fatstat:%.4x\n",
                 ace_in32(ace, ACE_CTRL),
                 ace_in(ace, ACE_SECCNTCMD),
                 ace_in(ace, ACE_VERSION),
@@ -949,15 +953,6 @@ static int __devinit ace_setup(struct ace_device *ace)
        if (!ace->baseaddr)
                goto err_ioremap;
 
-       if (ace->irq != NO_IRQ) {
-               rc = request_irq(ace->irq, ace_interrupt, 0, "systemace", ace);
-               if (rc) {
-                       /* Failure - fall back to polled mode */
-                       dev_err(ace->dev, "request_irq failed\n");
-                       ace->irq = NO_IRQ;
-               }
-       }
-
        /*
         * Initialize the state machine tasklet and stall timer
         */
@@ -1010,6 +1005,16 @@ static int __devinit ace_setup(struct ace_device *ace)
        ace_out(ace, ACE_CTRL, ACE_CTRL_FORCECFGMODE |
                ACE_CTRL_DATABUFRDYIRQ | ACE_CTRL_ERRORIRQ);
 
+       /* Now we can hook up the irq handler */
+       if (ace->irq != NO_IRQ) {
+               rc = request_irq(ace->irq, ace_interrupt, 0, "systemace", ace);
+               if (rc) {
+                       /* Failure - fall back to polled mode */
+                       dev_err(ace->dev, "request_irq failed\n");
+                       ace->irq = NO_IRQ;
+               }
+       }
+
        /* Enable interrupts */
        val = ace_in(ace, ACE_CTRL);
        val |= ACE_CTRL_DATABUFRDYIRQ | ACE_CTRL_ERRORIRQ;
@@ -1029,15 +1034,13 @@ static int __devinit ace_setup(struct ace_device *ace)
 
        return 0;
 
-      err_read:
+err_read:
        put_disk(ace->gd);
-      err_alloc_disk:
+err_alloc_disk:
        blk_cleanup_queue(ace->queue);
-      err_blk_initq:
+err_blk_initq:
        iounmap(ace->baseaddr);
-       if (ace->irq != NO_IRQ)
-               free_irq(ace->irq, ace);
-      err_ioremap:
+err_ioremap:
        dev_info(ace->dev, "xsysace: error initializing device at 0x%lx\n",
               ace->physaddr);
        return -ENOMEM;
@@ -1088,17 +1091,18 @@ ace_alloc(struct device *dev, int id, unsigned long physaddr,
        ace->bus_width = bus_width;
 
        /* Call the setup code */
-       if ((rc = ace_setup(ace)) != 0)
+       rc = ace_setup(ace);
+       if (rc)
                goto err_setup;
 
        dev_set_drvdata(dev, ace);
        return 0;
 
-      err_setup:
+err_setup:
        dev_set_drvdata(dev, NULL);
        kfree(ace);
-      err_alloc:
-      err_noreg:
+err_alloc:
+err_noreg:
        dev_err(dev, "could not initialize device, err=%i\n", rc);
        return rc;
 }
@@ -1158,6 +1162,85 @@ static struct platform_driver ace_platform_driver = {
        },
 };
 
+/* ---------------------------------------------------------------------
+ * OF_Platform Bus Support
+ */
+
+#if defined(CONFIG_OF)
+static int __devinit
+ace_of_probe(struct of_device *op, const struct of_device_id *match)
+{
+       struct resource res;
+       unsigned long physaddr;
+       const u32 *id;
+       int irq, bus_width, rc;
+
+       dev_dbg(&op->dev, "ace_of_probe(%p, %p)\n", op, match);
+
+       /* device id */
+       id = of_get_property(op->node, "port-number", NULL);
+
+       /* physaddr */
+       rc = of_address_to_resource(op->node, 0, &res);
+       if (rc) {
+               dev_err(&op->dev, "invalid address\n");
+               return rc;
+       }
+       physaddr = res.start;
+
+       /* irq */
+       irq = irq_of_parse_and_map(op->node, 0);
+
+       /* bus width */
+       bus_width = ACE_BUS_WIDTH_16;
+       if (of_find_property(op->node, "8-bit", NULL))
+               bus_width = ACE_BUS_WIDTH_8;
+
+       /* Call the bus-independant setup code */
+       return ace_alloc(&op->dev, id ? *id : 0, physaddr, irq, bus_width);
+}
+
+static int __devexit ace_of_remove(struct of_device *op)
+{
+       ace_free(&op->dev);
+       return 0;
+}
+
+/* Match table for of_platform binding */
+static struct of_device_id __devinit ace_of_match[] = {
+       { .compatible = "xilinx,xsysace", },
+       {},
+};
+MODULE_DEVICE_TABLE(of, ace_of_match);
+
+static struct of_platform_driver ace_of_driver = {
+       .owner = THIS_MODULE,
+       .name = "xsysace",
+       .match_table = ace_of_match,
+       .probe = ace_of_probe,
+       .remove = __devexit_p(ace_of_remove),
+       .driver = {
+               .name = "xsysace",
+       },
+};
+
+/* Registration helpers to keep the number of #ifdefs to a minimum */
+static inline int __init ace_of_register(void)
+{
+       pr_debug("xsysace: registering OF binding\n");
+       return of_register_platform_driver(&ace_of_driver);
+}
+
+static inline void __exit ace_of_unregister(void)
+{
+       of_unregister_platform_driver(&ace_of_driver);
+}
+#else /* CONFIG_OF */
+/* CONFIG_OF not enabled; do nothing helpers */
+static inline int __init ace_of_register(void) { return 0; }
+static inline void __exit ace_of_unregister(void) { }
+#endif /* CONFIG_OF */
+
 /* ---------------------------------------------------------------------
  * Module init/exit routines
  */
@@ -1171,16 +1254,23 @@ static int __init ace_init(void)
                goto err_blk;
        }
 
+       rc = ace_of_register();
+       if (rc)
+               goto err_of;
+
        pr_debug("xsysace: registering platform binding\n");
-       if ((rc = platform_driver_register(&ace_platform_driver)) != 0)
+       rc = platform_driver_register(&ace_platform_driver);
+       if (rc)
                goto err_plat;
 
        pr_info("Xilinx SystemACE device driver, major=%i\n", ace_major);
        return 0;
 
-      err_plat:
+err_plat:
+       ace_of_unregister();
+err_of:
        unregister_blkdev(ace_major, "xsysace");
-      err_blk:
+err_blk:
        printk(KERN_ERR "xsysace: registration failed; err=%i\n", rc);
        return rc;
 }
@@ -1189,6 +1279,7 @@ static void __exit ace_exit(void)
 {
        pr_debug("Unregistering Xilinx SystemACE driver\n");
        platform_driver_unregister(&ace_platform_driver);
+       ace_of_unregister();
        unregister_blkdev(ace_major, "xsysace");
 }