ata: Add iMX pata support
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v3 1/1 ata: Add iMX pata support
Add basic support for pata on iMX. It has been tested only on imx51. SDMA support will probably be added later so this version supports only PIO.
v2:
- enable only when needed IORDY
- use dev_get_drvdata
v3:
- add missing clk_put() calls
- use platform_get_irq()
- fix resume code to avoid disabling IORDY on resume
drivers/ata/Kconfig +9 -0
@@ -467,6 +467,15 @@ config PATA_ICSIDE interface card. This is not required for ICS partition support. If you are unsure, say N to this. +config PATA_IMX + tristate "PATA support for Freescale iMX (Experimental)" + depends on ARCH_MX5 && EXPERIMENTAL + help + This option enables support for the PATA host available on Freescale + iMX SoCs. + + If unsure, say N. + config PATA_IT8213 tristate "IT8213 PATA support (Experimental)" depends on PCI && EXPERIMENTAL
drivers/ata/Makefile +1 -0
@@ -48,6 +48,7 @@ obj-$(CONFIG_PATA_HPT37X) += pata_hpt37x obj-$(CONFIG_PATA_HPT3X2N) += pata_hpt3x2n.o obj-$(CONFIG_PATA_HPT3X3) += pata_hpt3x3.o obj-$(CONFIG_PATA_ICSIDE) += pata_icside.o +obj-$(CONFIG_PATA_IMX) += pata_imx.o obj-$(CONFIG_PATA_IT8213) += pata_it8213.o obj-$(CONFIG_PATA_IT821X) += pata_it821x.o obj-$(CONFIG_PATA_JMICRON) += pata_jmicron.o
drivers/ata/pata_imx.c new file +263 -0
263 lines not on this page · raw message
Sascha Hauer
maintainerHi Arnaud,
Quoted 18 lines · Arnaud Patard
Add basic support for pata on iMX. It has been tested only on imx51. SDMA support will probably be added later so this version supports only PIO.
v2:
- enable only when needed IORDY
- usedev_get_drvdata
v3:
- add missingclk_put()calls
- useplatform_get_irq()
- fix resume code to avoid disabling IORDY on resumeSigned-off-by Arnaud Patard <[email protected]>Index: linux-2.6-submit/drivers/ata/Kconfig
===================================================================
drivers/ata/Kconfig config PATA_ICSIDE · line 472
Quoted 6 lines
drivers/ata/Kconfig +3
-0@@ -467,6 +467,15 @@ config PATA_ICSIDE interface card. This is not required for ICS partition support. If you are unsure, say N to this. +config PATA_IMX + tristate "PATA support for Freescale iMX (Experimental)" + depends on ARCH_MX5 && EXPERIMENTAL
Should this really depend on EXPERIMENTAL? This driver looks pretty straightforward.
Also, please depend on ARCH_MXC instead. This may make this driver selectable on some i.MX SoCs which do not support it, but we don't have to add new ARCH_MX* to this list once a new SoC is supported.
(And no, IMX_HAVE_PLATFORM_BLA_BLA is not a good idea either as we are converting to the device tree and the Kconfig entries will probably go in the longer run)
Quoted 10 lines
drivers/ata/Kconfig +10
-0+ +static int __devinit pata_imx_probe(struct platform_device *pdev) +{ + struct ata_host *host; + struct ata_port *ap; + struct pata_imx_priv *priv; + int irq = 0; + struct resource *io_res; + + io_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
drivers/ata/Kconfig config PATA_ICSIDE
Quoted 10 lines
drivers/ata/Kconfig +10
-0+ if (io_res == NULL) + return -EINVAL; + + irq = platform_get_irq(pdev, 0); + if (irq <= 0) + return -EINVAL; + + priv = kzalloc(sizeof(struct pata_imx_priv), GFP_KERNEL); + if (!priv) + return -ENOMEM;
Given that you already use devm_ioremap, you can also use devm_kzalloc here.
drivers/ata/Kconfig
Quoted 3 lines
drivers/ata/Kconfig +3
-0+ + priv->clk = clk_get(&pdev->dev, "imx-pata"); + if (!priv->clk)
IS_ERR(priv->clk)
(also for the checks below)
Does it really make sense to continue when the clock failed?
Quoted 7 lines
drivers/ata/Kconfig +7
-0+ dev_warn(&pdev->dev, "Failed to get clock\n"); + else + clk_enable(priv->clk); + + + host = ata_host_alloc(&pdev->dev, 1); + if (!host)
drivers/ata/Kconfig
Quoted 10 lines
drivers/ata/Kconfig +10
-0+ goto free_priv; + + host->private_data = priv; + ap = host->ports[0]; + + ap->ops = &pata_imx_port_ops; + ap->pio_mask = ATA_PIO0; + ap->flags |= ATA_FLAG_SLAVE_POSS; + + priv->host_regs = devm_ioremap(&pdev->dev, io_res->start, 0x40);
resource_size() instead of hardcoded 0x40?
drivers/ata/Kconfig
Quoted 6 lines
drivers/ata/Kconfig +6
-0+ ap->ioaddr.cmd_addr = devm_ioremap(&pdev->dev, + io_res->start + PATA_IMX_DRIVE_DATA, + 0x20); + ap->ioaddr.ctl_addr = devm_ioremap(&pdev->dev, + io_res->start + PATA_IMX_DRIVE_CONTROL, + 0x04);
It looks strange to ioremap the register offsets again. Why not just a
ap->ioaddr.cmd_addr = priv->host_regs + PATA_IMX_DRIVE_DATA ap->ioaddr.ctl_addr = priv->host_regs + PATA_IMX_DRIVE_CONTROL
Hm, probably copied from the pxa driver, but this uses different resources which makes different ioremaps necessary.
Quoted 35 lines
drivers/ata/Kconfig +35
-0+ if (!priv->host_regs || !ap->ioaddr.cmd_addr || !ap->ioaddr.ctl_addr) { + dev_err(&pdev->dev, "failed to map IO/CTL base\n"); + goto free_priv; + } + + ap->ioaddr.altstatus_addr = ap->ioaddr.ctl_addr; + + + pata_imx_setup_port(&ap->ioaddr); + + ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx", + (unsigned long long)io_res->start + PATA_IMX_DRIVE_DATA, + (unsigned long long)io_res->start + PATA_IMX_DRIVE_CONTROL); + + /* deassert resets */ + __raw_writel(PATA_IMX_ATA_CTRL_FIFO_RST_B | + PATA_IMX_ATA_CTRL_ATA_RST_B, + priv->host_regs + PATA_IMX_ATA_CONTROL); + /* enable interrupts */ + __raw_writel(PATA_IMX_ATA_INTR_ATA_INTRQ2, + priv->host_regs + PATA_IMX_ATA_INT_EN); + + /* activate */ + return ata_host_activate(host, irq, ata_sff_interrupt, 0, + &pata_imx_sht); + +free_priv: + if (priv->clk) { + clk_disable(priv->clk); + clk_put(priv->clk); + } + kfree(priv); + return -ENOMEM; +} +
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 1 line · Sascha Hauer
Hi Arnaud,
Hi,
Quoted 23 lines · Arnaud Patard
Quoted 21 lines
Add basic support for pata on iMX. It has been tested only on imx51. SDMA support will probably be added later so this version supports only PIO.
v2:
- enable only when needed IORDY
- usedev_get_drvdata
v3:
- add missingclk_put()calls
- useplatform_get_irq()
- fix resume code to avoid disabling IORDY on resumeSigned-off-by Arnaud Patard <[email protected]>Index: linux-2.6-submit/drivers/ata/Kconfig
===================================================================drivers/ata/Kconfig +0
-0@@ -467,6 +467,15 @@ config PATA_ICSIDE interface card. This is not required for ICS partition support. If you are unsure, say N to this.
Quoted 6 lines
drivers/ata/Kconfig config PATA_ICSIDE · line 472
Quoted 3 lines
drivers/ata/Kconfig +3
-0+config PATA_IMX + tristate "PATA support for Freescale iMX (Experimental)" + depends on ARCH_MX5 && EXPERIMENTALShould this really depend on EXPERIMENTAL? This driver looks pretty straightforward.
I've been wondering about it but given that it has been tested only on efika platforms, I prefered to keep it. If you think it's better to remove it, fine. I'll do it.
Quoted 4 lines
Also, please depend on
ARCH_MXCinstead. This may make this driver selectable on some i.MX SoCs which do not support it, but we don't have to add new ARCH_MX* to this list once a new SoC is supported.
Well, it's for the same reason as for the EXPERIMENTAL. It's working on my mx51 platforms, but I've not tested on plateforms like iMX3 (as I don't have them). Will change.
Quoted 21 lines
(And no,
IMX_HAVE_PLATFORM_BLA_BLAis not a good idea either as we are converting to the device tree and theKconfigentries will probably go in the longer run)Quoted 15 lines
drivers/ata/Kconfig +15
-0+ +static int __devinit pata_imx_probe(struct platform_device *pdev) +{ + struct ata_host *host; + struct ata_port *ap; + struct pata_imx_priv *priv; + int irq = 0; + struct resource *io_res; + + io_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (io_res == NULL) + return -EINVAL; + + irq = platform_get_irq(pdev, 0); + if (irq <= 0)
Quoted 8 lines
drivers/ata/Kconfig
Quoted 5 lines
drivers/ata/Kconfig +5
-0+ return -EINVAL; + + priv = kzalloc(sizeof(struct pata_imx_priv), GFP_KERNEL); + if (!priv) + return -ENOMEM;Given that you already use
devm_ioremap, you can also usedevm_kzallochere.
thanks, will do. I didn't know there was such a function.
Quoted 10 lines
drivers/ata/Kconfig
Quoted 4 lines
drivers/ata/Kconfig +3
-0+ + priv->clk = clk_get(&pdev->dev, "imx-pata"); + if (!priv->clk)
IS_ERR(priv->clk)(also for the checks below)
Does it really make sense to continue when the clock failed?
if you have uboot version like the one I have, the clock will be already enabled before booting linux so the driver will work. Maybe too fragile ? I've changed the checks on my local version and about to test it. Let me know if you think it should really be a failure, in order to avoid having to send a new version only to make it a failure.
Quoted 30 lines
Quoted 8 lines
drivers/ata/Kconfig +7
-0+ dev_warn(&pdev->dev, "Failed to get clock\n"); + else + clk_enable(priv->clk); + + + host = ata_host_alloc(&pdev->dev, 1); + if (!host)drivers/ata/Kconfig
Quoted 10 lines
drivers/ata/Kconfig +10
-0+ goto free_priv; + + host->private_data = priv; + ap = host->ports[0]; + + ap->ops = &pata_imx_port_ops; + ap->pio_mask = ATA_PIO0; + ap->flags |= ATA_FLAG_SLAVE_POSS; + + priv->host_regs = devm_ioremap(&pdev->dev, io_res->start, 0x40);
resource_size()instead of hardcoded0x40?drivers/ata/Kconfig
Quoted 6 lines
drivers/ata/Kconfig +6
-0+ ap->ioaddr.cmd_addr = devm_ioremap(&pdev->dev, + io_res->start + PATA_IMX_DRIVE_DATA, + 0x20); + ap->ioaddr.ctl_addr = devm_ioremap(&pdev->dev, + io_res->start + PATA_IMX_DRIVE_CONTROL, + 0x04);It looks strange to ioremap the register offsets again. Why not just a
Quoted 5 lines
ap->ioaddr.cmd_addr = priv->host_regs + PATA_IMX_DRIVE_DATA ap->ioaddr.ctl_addr = priv->host_regs + PATA_IMX_DRIVE_CONTROLHm, probably copied from the pxa driver, but this uses different resources which makes different ioremaps necessary.
There are holes in the register map in the manual, that's why I used several ioremap. I prefer staying near to what the manual says and avoid remapping unknown registers.
Thanks,
Arnaud
Sascha Hauer
maintainerQuoted 35 lines · Arnaud Patard
Quoted 1 line · Sascha Hauer
Hi Arnaud,
Hi,
Quoted 23 lines · Arnaud Patard
Quoted 21 lines
Add basic support for pata on iMX. It has been tested only on imx51. SDMA support will probably be added later so this version supports only PIO.
v2:
- enable only when needed IORDY
- usedev_get_drvdata
v3:
- add missingclk_put()calls
- useplatform_get_irq()
- fix resume code to avoid disabling IORDY on resumeSigned-off-by Arnaud Patard <[email protected]>Index: linux-2.6-submit/drivers/ata/Kconfig
===================================================================drivers/ata/Kconfig +0
-0@@ -467,6 +467,15 @@ config PATA_ICSIDE interface card. This is not required for ICS partition support. If you are unsure, say N to this.Quoted 6 lines
drivers/ata/Kconfig config PATA_ICSIDE · line 472
Quoted 3 lines
drivers/ata/Kconfig +3
-0+config PATA_IMX + tristate "PATA support for Freescale iMX (Experimental)" + depends on ARCH_MX5 && EXPERIMENTALShould this really depend on EXPERIMENTAL? This driver looks pretty straightforward.
Quoted 3 lines
I've been wondering about it but given that it has been tested only on efika platforms, I prefered to keep it. If you think it's better to remove it, fine. I'll do it.
Only the efika platform registers the device, so there's no risk to harm other boards.
Quoted 5 lines
Quoted 5 lines
IS_ERR(priv->clk)(also for the checks below)
Quoted 7 lines
Quoted 1 line
Does it really make sense to continue when the clock failed?
if you have uboot version like the one I have, the clock will be already enabled before booting linux so the driver will work. Maybe too fragile ? I've changed the checks on my local version and about to test it. Let me know if you think it should really be a failure, in order to avoid having to send a new version only to make it a failure.
Yes, it should be a failure.
Quoted 12 lines
Quoted 12 lines
drivers/ata/Kconfig config PATA_ICSIDE · line 478
Quoted 6 lines
drivers/ata/Kconfig +6
-0+ ap->ioaddr.cmd_addr = devm_ioremap(&pdev->dev, + io_res->start + PATA_IMX_DRIVE_DATA, + 0x20); + ap->ioaddr.ctl_addr = devm_ioremap(&pdev->dev, + io_res->start + PATA_IMX_DRIVE_CONTROL, + 0x04);It looks strange to ioremap the register offsets again. Why not just a
ap->ioaddr.cmd_addr = priv->host_regs + PATA_IMX_DRIVE_DATA ap->ioaddr.ctl_addr = priv->host_regs + PATA_IMX_DRIVE_CONTROL
Quoted 6 lines
Quoted 2 lines
Hm, probably copied from the pxa driver, but this uses different resources which makes different ioremaps necessary.
There are holes in the register map in the manual, that's why I used several ioremap. I prefer staying near to what the manual says and avoid remapping unknown registers.
Having holes in the register space is a very common case, no need to do several ioremaps. Besides, ioremap will give you a whole page anyway.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |