X-Git-Url: http://pilppa.org/gitweb/?a=blobdiff_plain;f=drivers%2Fblock%2Fxsysace.c;h=3ea172b7b7a40476d91f8db0095b3321ef718f16;hb=ed155a95a4eb7d8dae61b64ab394314c5195e414;hp=732ec63b6e9cdd2733ed66270e0c4f2f602f9fd2;hpb=efffbeee5bc4168059683714b300d307f5193d69;p=linux-2.6-omap-h63xx.git diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c index 732ec63b6e9..3ea172b7b7a 100644 --- a/drivers/block/xsysace.c +++ b/drivers/block/xsysace.c @@ -91,6 +91,10 @@ #include #include #include +#if defined(CONFIG_OF) +#include +#include +#endif MODULE_AUTHOR("Grant Likely "); MODULE_DESCRIPTION("Xilinx SystemACE device driver"); @@ -158,6 +162,9 @@ MODULE_LICENSE("GPL"); #define ACE_FIFO_SIZE (32) #define ACE_BUF_PER_SECTOR (ACE_SECTOR_SIZE / ACE_FIFO_SIZE) +#define ACE_BUS_WIDTH_8 0 +#define ACE_BUS_WIDTH_16 1 + struct ace_reg_ops; struct ace_device { @@ -458,7 +465,7 @@ static inline void ace_fsm_yieldirq(struct ace_device *ace) } /* Get the next read/write request; ending requests that we don't handle */ -struct request *ace_get_next_request(request_queue_t * q) +struct request *ace_get_next_request(struct request_queue * q) { struct request *req; @@ -825,7 +832,7 @@ static irqreturn_t ace_interrupt(int irq, void *dev_id) /* --------------------------------------------------------------------- * Block ops */ -static void ace_request(request_queue_t * q) +static void ace_request(struct request_queue * q) { struct request *req; struct ace_device *ace; @@ -902,26 +909,17 @@ static int ace_release(struct inode *inode, struct file *filp) return 0; } -static int ace_ioctl(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +static int ace_getgeo(struct block_device *bdev, struct hd_geometry *geo) { - struct ace_device *ace = inode->i_bdev->bd_disk->private_data; - struct hd_geometry __user *geo = (struct hd_geometry __user *)arg; - struct hd_geometry g; - dev_dbg(ace->dev, "ace_ioctl()\n"); - - switch (cmd) { - case HDIO_GETGEO: - g.heads = ace->cf_id.heads; - g.sectors = ace->cf_id.sectors; - g.cylinders = ace->cf_id.cyls; - g.start = 0; - return copy_to_user(geo, &g, sizeof(g)) ? -EFAULT : 0; + struct ace_device *ace = bdev->bd_disk->private_data; - default: - return -ENOTTY; - } - return -ENOTTY; + dev_dbg(ace->dev, "ace_getgeo()\n"); + + geo->heads = ace->cf_id.heads; + geo->sectors = ace->cf_id.sectors; + geo->cylinders = ace->cf_id.cyls; + + return 0; } static struct block_device_operations ace_fops = { @@ -930,7 +928,7 @@ static struct block_device_operations ace_fops = { .release = ace_release, .media_changed = ace_media_changed, .revalidate_disk = ace_revalidate_disk, - .ioctl = ace_ioctl, + .getgeo = ace_getgeo, }; /* -------------------------------------------------------------------- @@ -940,9 +938,11 @@ static int __devinit ace_setup(struct ace_device *ace) { u16 version; u16 val; - int rc; + dev_dbg(ace->dev, "ace_setup(ace=0x%p)\n", ace); + dev_dbg(ace->dev, "physaddr=0x%lx irq=%i\n", ace->physaddr, ace->irq); + spin_lock_init(&ace->lock); init_completion(&ace->id_completion); @@ -953,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 */ @@ -991,7 +982,7 @@ static int __devinit ace_setup(struct ace_device *ace) snprintf(ace->gd->disk_name, 32, "xs%c", ace->id + 'a'); /* set bus width */ - if (ace->bus_width == 1) { + if (ace->bus_width == ACE_BUS_WIDTH_16) { /* 0x0101 should work regardless of endianess */ ace_out_le16(ace, ACE_BUSMODE, 0x0101); @@ -1019,6 +1010,16 @@ static int __devinit ace_setup(struct ace_device *ace) val |= ACE_CTRL_DATABUFRDYIRQ | ACE_CTRL_ERRORIRQ; ace_out(ace, ACE_CTRL, val); + /* 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; + } + } + /* Print the identification */ dev_info(ace->dev, "Xilinx SystemACE revision %i.%i.%i\n", (version >> 12) & 0xf, (version >> 8) & 0x0f, version & 0xff); @@ -1033,16 +1034,14 @@ 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: - printk(KERN_INFO "xsysace: error initializing device at 0x%lx\n", +err_ioremap: + dev_info(ace->dev, "xsysace: error initializing device at 0x%lx\n", ace->physaddr); return -ENOMEM; } @@ -1065,98 +1064,219 @@ static void __devexit ace_teardown(struct ace_device *ace) iounmap(ace->baseaddr); } -/* --------------------------------------------------------------------- - * Platform Bus Support - */ - -static int __devinit ace_probe(struct device *device) +static int __devinit +ace_alloc(struct device *dev, int id, unsigned long physaddr, + int irq, int bus_width) { - struct platform_device *dev = to_platform_device(device); struct ace_device *ace; - int i; + int rc; + dev_dbg(dev, "ace_alloc(%p)\n", dev); - dev_dbg(device, "ace_probe(%p)\n", device); + if (!physaddr) { + rc = -ENODEV; + goto err_noreg; + } - /* - * Allocate the ace device structure - */ + /* Allocate and initialize the ace device structure */ ace = kzalloc(sizeof(struct ace_device), GFP_KERNEL); - if (!ace) + if (!ace) { + rc = -ENOMEM; goto err_alloc; - - ace->dev = device; - ace->id = dev->id; - ace->irq = NO_IRQ; - - for (i = 0; i < dev->num_resources; i++) { - if (dev->resource[i].flags & IORESOURCE_MEM) - ace->physaddr = dev->resource[i].start; - if (dev->resource[i].flags & IORESOURCE_IRQ) - ace->irq = dev->resource[i].start; } - /* FIXME: Should get bus_width from the platform_device struct */ - ace->bus_width = 1; + ace->dev = dev; + ace->id = id; + ace->physaddr = physaddr; + ace->irq = irq; + ace->bus_width = bus_width; - dev_set_drvdata(&dev->dev, ace); - - /* Call the bus-independant setup code */ - if (ace_setup(ace) != 0) + /* Call the setup code */ + if ((rc = ace_setup(ace)) != 0) goto err_setup; + dev_set_drvdata(dev, ace); return 0; - err_setup: - dev_set_drvdata(&dev->dev, NULL); +err_setup: + dev_set_drvdata(dev, NULL); kfree(ace); - err_alloc: - printk(KERN_ERR "xsysace: could not initialize device\n"); - return -ENOMEM; +err_alloc: +err_noreg: + dev_err(dev, "could not initialize device, err=%i\n", rc); + return rc; } -/* - * Platform bus remove() method - */ -static int __devexit ace_remove(struct device *device) +static void __devexit ace_free(struct device *dev) { - struct ace_device *ace = dev_get_drvdata(device); - - dev_dbg(device, "ace_remove(%p)\n", device); + struct ace_device *ace = dev_get_drvdata(dev); + dev_dbg(dev, "ace_free(%p)\n", dev); if (ace) { ace_teardown(ace); + dev_set_drvdata(dev, NULL); kfree(ace); } +} + +/* --------------------------------------------------------------------- + * Platform Bus Support + */ +static int __devinit ace_probe(struct platform_device *dev) +{ + unsigned long physaddr = 0; + int bus_width = ACE_BUS_WIDTH_16; /* FIXME: should not be hard coded */ + int id = dev->id; + int irq = NO_IRQ; + int i; + + dev_dbg(&dev->dev, "ace_probe(%p)\n", dev); + + for (i = 0; i < dev->num_resources; i++) { + if (dev->resource[i].flags & IORESOURCE_MEM) + physaddr = dev->resource[i].start; + if (dev->resource[i].flags & IORESOURCE_IRQ) + irq = dev->resource[i].start; + } + + /* Call the bus-independant setup code */ + return ace_alloc(&dev->dev, id, physaddr, irq, bus_width); +} + +/* + * Platform bus remove() method + */ +static int __devexit ace_remove(struct platform_device *dev) +{ + ace_free(&dev->dev); return 0; } -static struct device_driver ace_driver = { - .name = "xsysace", - .bus = &platform_bus_type, +static struct platform_driver ace_platform_driver = { .probe = ace_probe, .remove = __devexit_p(ace_remove), + .driver = { + .owner = THIS_MODULE, + .name = "xsysace", + }, }; +/* --------------------------------------------------------------------- + * 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 */ static int __init ace_init(void) { + int rc; + ace_major = register_blkdev(ace_major, "xsysace"); if (ace_major <= 0) { - printk(KERN_WARNING "xsysace: register_blkdev() failed\n"); - return ace_major; + rc = -ENOMEM; + goto err_blk; } - pr_debug("Registering Xilinx SystemACE driver, major=%i\n", ace_major); - return driver_register(&ace_driver); + if ((rc = ace_of_register()) != 0) + goto err_of; + + pr_debug("xsysace: registering platform binding\n"); + if ((rc = platform_driver_register(&ace_platform_driver)) != 0) + goto err_plat; + + pr_info("Xilinx SystemACE device driver, major=%i\n", ace_major); + return 0; + +err_plat: + ace_of_unregister(); +err_of: + unregister_blkdev(ace_major, "xsysace"); +err_blk: + printk(KERN_ERR "xsysace: registration failed; err=%i\n", rc); + return rc; } static void __exit ace_exit(void) { pr_debug("Unregistering Xilinx SystemACE driver\n"); - driver_unregister(&ace_driver); + platform_driver_unregister(&ace_platform_driver); + ace_of_unregister(); unregister_blkdev(ace_major, "xsysace"); }