Skip to contentSkip to conversation

ata: Add iMX pata support

PATCH In review Arnaud Patard (Rtp) 2 participants 4 messages Jul 16, 2011 – Jul 22, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 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.

drivers/ata/Kconfig +9 -0
Index: linux-2.6-submit/drivers/ata/Kconfig
===================================================================
@@ -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
Index: linux-2.6-submit/drivers/ata/Makefile
===================================================================
@@ -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 +254 -0

254 lines not on this page · raw message

#1 lore raw

Hello.

Quoted 5 lines · Arnaud Patard (Rtp)

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.

[...]

Quoted 5 lines

Index: linux-2.6-submit/drivers/ata/pata_imx.c
===================================================================

drivers/ata/pata_imx.c new file +0 -0
@@ -0,0 +1,254 @@

[...]

Quoted 3 lines

+ * TODO:
+ * - dmaengine support
+ * - check if timing stuff needed

Sure, it's needed, especially if you want to support DMA.

drivers/ata/pata_imx.c line 31

Quoted 4 lines
drivers/ata/pata_imx.c new file +4 -0
+#define PATA_IMX_ATA_CONTROL		0x24
+#define PATA_IMX_ATA_CTRL_FIFO_RST_B	(1<<7)
+#define PATA_IMX_ATA_CTRL_ATA_RST_B	(1<<6)
+#define PATA_IMX_ATA_CTRL_IORDY_EN	(1<<0)

So, it seems to support advanced PIO modes...

Quoted 4 lines
drivers/ata/pata_imx.c new file +4 -0
+static int __devinit pata_imx_probe(struct platform_device *pdev)
+{
+	struct ata_host *host;
+	struct ata_port *ap;

drivers/ata/pata_imx.c line 95

Quoted 10 lines
drivers/ata/pata_imx.c new file +10 -0
+	struct pata_imx_priv *priv;
+	int irq = 0;
+	struct resource *io_res;
+	struct resource *irq_res;
+
+	io_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (io_res == NULL)
+		return -EINVAL;
+
+	irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);

Why not use platform_get_irq()?

drivers/ata/pata_imx.c line 104

Quoted 9 lines
drivers/ata/pata_imx.c new file +9 -0
+	if (irq_res == NULL)
+		return -EINVAL;
+	irq = irq_res->start;
+
+	priv = kzalloc(sizeof(struct pata_imx_priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->clk = clk_get(&pdev->dev, "imx-pata");

Does iMX support clkdev?

[...]

drivers/ata/pata_imx.c line 120

Quoted 3 lines
drivers/ata/pata_imx.c new file +3 -0
+	ap->ops = &pata_imx_port_ops;
+	/* pio 0-4 */
+	ap->pio_mask = ATA_PIO4;

But you don't support PIO1-4!

drivers/ata/pata_imx.c line 129

Quoted 9 lines
drivers/ata/pata_imx.c new file +9 -0
+	ap->flags |= ATA_FLAG_SLAVE_POSS;
+
+	priv->host_regs = devm_ioremap(&pdev->dev, io_res->start, 0x40);
+	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);

Why not ioremap all registers as one block?

drivers/ata/pata_imx.c line 146

Quoted 8 lines
drivers/ata/pata_imx.c new file +8 -0
+	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 |
+			PATA_IMX_ATA_CTRL_IORDY_EN,

You can't enable IORDY by default, only when the drive supports it!

[...]

drivers/ata/pata_imx.c line 184

Quoted 5 lines
drivers/ata/pata_imx.c new file +5 -0
+#ifdef CONFIG_PM
+static int pata_imx_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct ata_host *host = platform_get_drvdata(pdev);

You can just use dev_get_drvdata(), without calling to_platfrom_device().

drivers/ata/pata_imx.c line 189

Quoted 5 lines
drivers/ata/pata_imx.c new file +5 -0
+	struct pata_imx_priv *priv = host->private_data;
+	int ret;
+
+	ret = ata_host_suspend(host, PMSG_SUSPEND);
+

Empty line not needed here...

Quoted 2 lines
drivers/ata/pata_imx.c new file +2 -0
+	if (!ret)
+		__raw_writel(0, priv->host_regs + PATA_IMX_ATA_INT_EN);

[...]

drivers/ata/pata_imx.c line 202

Quoted 4 lines
drivers/ata/pata_imx.c new file +4 -0
+static int pata_imx_resume(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct ata_host *host = platform_get_drvdata(pdev);

Just use dev_get_drvdata().

drivers/ata/pata_imx.c

Quoted 1 line
drivers/ata/pata_imx.c new file +1 -0
+	struct pata_imx_priv *priv = host->private_data;

[...]

WBR, Sergei

#2 lore raw
Quoted 1 line · Sergei Shtylyov

Hello.

Hi,

Quoted 28 lines · Arnaud Patard (Rtp)
Quoted 6 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.

[...]

Quoted 5 lines

Index: linux-2.6-submit/drivers/ata/pata_imx.c
===================================================================

drivers/ata/pata_imx.c new file +0 -0
@@ -0,0 +1,254 @@

[...]

Quoted 3 lines

+ * TODO:
+ * - dmaengine support
+ * - check if timing stuff needed

Sure, it's needed, especially if you want to support DMA.

drivers/ata/pata_imx.c line 31

Quoted 4 lines
drivers/ata/pata_imx.c new file +4 -0
+#define PATA_IMX_ATA_CONTROL		0x24
+#define PATA_IMX_ATA_CTRL_FIFO_RST_B	(1<<7)
+#define PATA_IMX_ATA_CTRL_ATA_RST_B	(1<<6)
+#define PATA_IMX_ATA_CTRL_IORDY_EN	(1<<0)

So, it seems to support advanced PIO modes...

Quoted 16 lines
Quoted 4 lines
drivers/ata/pata_imx.c new file +4 -0
+static int __devinit pata_imx_probe(struct platform_device *pdev)
+{
+	struct ata_host *host;
+	struct ata_port *ap;

drivers/ata/pata_imx.c line 95

Quoted 10 lines
drivers/ata/pata_imx.c new file +10 -0
+	struct pata_imx_priv *priv;
+	int irq = 0;
+	struct resource *io_res;
+	struct resource *irq_res;
+
+	io_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (io_res == NULL)
+		return -EINVAL;
+
+	irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);

Why not use platform_get_irq()?

No special reason. Was using get_resource() for mem, so I used it for irq too.

Quoted 13 lines

drivers/ata/pata_imx.c line 104

Quoted 10 lines
drivers/ata/pata_imx.c new file +9 -0
+	if (irq_res == NULL)
+		return -EINVAL;
+	irq = irq_res->start;
+
+	priv = kzalloc(sizeof(struct pata_imx_priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->clk = clk_get(&pdev->dev, "imx-pata");

Does iMX support clkdev?

Quoted 1 line

[...]

iirc, it's not supported

Quoted 6 lines

drivers/ata/pata_imx.c line 120

Quoted 3 lines
drivers/ata/pata_imx.c new file +3 -0
+	ap->ops = &pata_imx_port_ops;
+	/* pio 0-4 */
+	ap->pio_mask = ATA_PIO4;

But you don't support PIO1-4!

Quoted 12 lines

drivers/ata/pata_imx.c line 129

Quoted 9 lines
drivers/ata/pata_imx.c new file +9 -0
+	ap->flags |= ATA_FLAG_SLAVE_POSS;
+
+	priv->host_regs = devm_ioremap(&pdev->dev, io_res->start, 0x40);
+	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);

Why not ioremap all registers as one block?

the manual doesn't talk about the address space in between so I prefered to be safe and use 2 parts, like the manual.

Quoted 11 lines

drivers/ata/pata_imx.c line 146

Quoted 8 lines
drivers/ata/pata_imx.c new file +8 -0
+	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 |
+			PATA_IMX_ATA_CTRL_IORDY_EN,

You can't enable IORDY by default, only when the drive supports it!

hm... ok. The original code was enabling it in the machine file and fsl driver doesn't handle IORDY at all so I'm not sure how to do that and make sure it won't break. I guess I'll have to see if it break on my system to test it but it's not a really complete test.

Quoted 9 lines

[...]

drivers/ata/pata_imx.c line 184

Quoted 5 lines
drivers/ata/pata_imx.c new file +5 -0
+#ifdef CONFIG_PM
+static int pata_imx_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct ata_host *host = platform_get_drvdata(pdev);

You can just use dev_get_drvdata(), without calling to_platfrom_device().

ok.

Arnaud

#3 lore raw

Hello.

Quoted 30 lines · Arnaud Patard (Rtp)
Quoted 13 lines
Quoted 5 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.

[...]

Quoted 5 lines

Index: linux-2.6-submit/drivers/ata/pata_imx.c
===================================================================

drivers/ata/pata_imx.c new file +0 -0
@@ -0,0 +1,254 @@

[...]

Quoted 16 lines
Quoted 4 lines
drivers/ata/pata_imx.c new file +4 -0
+static int __devinit pata_imx_probe(struct platform_device *pdev)
+{
+	struct ata_host *host;
+	struct ata_port *ap;

drivers/ata/pata_imx.c line 95

Quoted 10 lines
drivers/ata/pata_imx.c new file +10 -0
+	struct pata_imx_priv *priv;
+	int irq = 0;
+	struct resource *io_res;
+	struct resource *irq_res;
+
+	io_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (io_res == NULL)
+		return -EINVAL;
+
+	irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);

Why not use platform_get_irq()?

Quoted 2 lines

No special reason. Was using get_resource() for mem, so I used it for irq too.

platform_get_irq() would yield smaller code.

Quoted 12 lines
Quoted 12 lines

drivers/ata/pata_imx.c line 104

Quoted 9 lines
drivers/ata/pata_imx.c new file +9 -0
+	if (irq_res == NULL)
+		return -EINVAL;
+	irq = irq_res->start;
+
+	priv = kzalloc(sizeof(struct pata_imx_priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->clk = clk_get(&pdev->dev, "imx-pata");

Does iMX support clkdev?

Quoted 3 lines
Quoted 1 line

[...]

iirc, it's not supported

Then it's good idea to pass the clock name thru the platfrom data.

WBR, Sergei