Skip to contentSkip to conversation

Generic platform device IDE driver

PATCH In review Paul Mundt 6 participants 13 messages Oct 4, 2006 – Oct 13, 2006 libata

lore
Share & tools
lore

Paul Mundt

author
#0 lore raw

PATCH 1/1 Generic platform device IDE driver

Currently the platforms that have very simplistic needs for IDE devices are forced to invent their own driver for adding the built-in devices. At the moment ARM is the in-tree user in this category, h8300 could be switched to something more generic, and SH is roughly in the same category as ARM.

The only constant that really tends to change between these platforms are the I/O base and the IRQ, with everything else rather constant. The ctl base could also change, but everyone seems to keep it at 0x206, so it's debatable whether it's worth leaving this configurable or not.

I've hacked together a quick driver, 'ide-platform' (for lack of a better name), that allows for these specifics to be passed in via platform device resources (registering a device per-port) rather than having to add more of these things to drivers/ide.

With this we can remove ide_arm (and the h8300 driver can likely be reworked to use this too), and I don't have to invent a new driver for SH that does effectively the same thing.

This is intended purely for the simple NO_DMA ide_generic case.. nothing complicated.

What do people think about this, is there a better way to do this?

--

 drivers/ide/Makefile       |    3 +-
 drivers/ide/ide-platform.c |   60 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/ide/ide.c          |    3 ++
 3 files changed, 65 insertions(+), 1 deletion(-)

commit f2da2c8c9b5e648ca9a43d9d3fed9bcd356f0efd

Author: Paul Mundt <[email protected]>
Date:   Wed Oct 4 16:41:21 2006 +0900

ide: Simple platform device IDE driver.

This adds a trivial platform device IDE driver. Users are required to register a couple of resources:

- I/O Base
- CTL Base
- IRQ

drivers/ide/Makefile +2 -1
index 569fae7..24c9a0f 100644
@@ -13,7 +13,8 @@ EXTRA_CFLAGS				+= -Idrivers/ide
 
 obj-$(CONFIG_BLK_DEV_IDE)		+= pci/
 
-ide-core-y += ide.o ide-io.o ide-iops.o ide-lib.o ide-probe.o ide-taskfile.o
+ide-core-y += ide.o ide-io.o ide-iops.o ide-lib.o ide-probe.o ide-taskfile.o \
+	      ide-platform.o
 
 ide-core-$(CONFIG_BLK_DEV_CMD640)	+= pci/cmd640.o
 
drivers/ide/ide-platform.c new file +60 -0

60 lines not on this page · raw message

drivers/ide/ide.c +3 -0
index 287a662..994cdd4 100644
@@ -1782,6 +1782,7 @@ done:
 }
 
 extern void pnpide_init(void);
+extern void ide_platform_init(void);
 extern void h8300_ide_init(void);
 
 /*
@@ -1793,6 +1794,8 @@ #ifdef CONFIG_BLK_DEV_IDEPCI
 	ide_scan_pcibus(ide_scan_direction);
 #endif /* CONFIG_BLK_DEV_IDEPCI */
 
+	ide_platform_init();
+
 #ifdef CONFIG_ETRAX_IDE
 	{
 		extern void init_e100_ide(void);
#1 lore raw

Ar Mer, 2006-10-04 am 16:45 +0900, ysgrifennodd Paul Mundt:

Quoted 4 lines

This is intended purely for the simple NO_DMA ide_generic case.. nothing complicated.

What do people think about this, is there a better way to do this?

drivers/ide is going away over time. I think the concept is nice and it's sort of reflected in the libata VLB drivers. I think it would be a very good way to get good platform drivers for libata for the embedded platforms.

Moving the existing drivers/ide stuff to a new drivers/ide variant is wasted work however.

author
#2 lore raw
Quoted 7 lines · Alan Cox

Ar Mer, 2006-10-04 am 16:45 +0900, ysgrifennodd Paul Mundt:

Quoted 4 lines

This is intended purely for the simple NO_DMA ide_generic case.. nothing complicated.

What do people think about this, is there a better way to do this?

drivers/ide is going away over time.

That was the impression I got.

Quoted 4 lines

I think the concept is nice and it's sort of reflected in the libata VLB drivers. I think it would be a very good way to get good platform drivers for libata for the embedded platforms.

Ok, I wasn't sure if libata was intended for anything outside of the SATA case (especially non-PCI), but if that's the way to go, I'll look at hacking something up under libata.

Quoted 3 lines

Moving the existing drivers/ide stuff to a new drivers/ide variant is wasted work however.

That's what I figured, thanks for clearing it up.

#3 lore raw

Ar Iau, 2006-10-05 am 05:05 +0900, ysgrifennodd Paul Mundt:

Quoted 3 lines

Ok, I wasn't sure if libata was intended for anything outside of the SATA case (especially non-PCI), but if that's the way to go, I'll look at hacking something up under libata.

Take a look at 2.6.18-mm or 2.6.19-* and you should see all you need in that including the pcmcia driver and other users who set up much the same way a generic platform device driver would.

author
#4 lore raw
Quoted 9 lines · Alan Cox

Ar Iau, 2006-10-05 am 05:05 +0900, ysgrifennodd Paul Mundt:

Quoted 3 lines

Ok, I wasn't sure if libata was intended for anything outside of the SATA case (especially non-PCI), but if that's the way to go, I'll look at hacking something up under libata.

Take a look at 2.6.18-mm or 2.6.19-* and you should see all you need in that including the pcmcia driver and other users who set up much the same way a generic platform device driver would.

Ok, just hacked this together quickly, how does it look? I'm booting this on an SH-4A (R7780RP) from current git and all works fine..

Thankfully you did most of the heavy lifting :-)

--

 drivers/ata/Kconfig         |    9 ++
 drivers/ata/Makefile        |    1 
 drivers/ata/pata_platform.c |  198 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 208 insertions(+)

commit f257da330416413947c65dac20cefbd39231eb30

Author: Paul Mundt <[email protected]>
Date:   Thu Oct 5 18:13:27 2006 +0900

ata: Simple generic platform device libata driver.

This adds a simple generic libata driver for directly-connected and pre-configured platform devices commonly found on embedded systems.

For most of these devices, the only variation ends up being the I/O and CTL bases as well as the IRQ, with everything else effectively behaving as a standard ISA bus PIO device.

Users of 'pata_platform' are required to pack in 3 resources per port, namely, the aforementioned variations. Each port must be registered independently, which doesn't end up being a big problem, as most of the embedded use cases don't have more than one or two ports anyways.

drivers/ata/Kconfig +9 -0
index 3f4aa0c..70a5a08 100644
@@ -482,6 +482,15 @@ config PATA_WINBOND
 
 	  If unsure, say N.
 
+config PATA_PLATFORM
+	tristate "Generic platform device PATA support"
+	depends on EMBEDDED
+	help
+	  This option enables support for generic directly connected ATA
+	  devices commonly found on embedded systems.
+
+	  If unsure, say N.
+
 endif
 endmenu
 
drivers/ata/Makefile +1 -0
index 72243a6..408c8c9 100644
@@ -53,6 +53,7 @@ obj-$(CONFIG_PATA_VIA)		+= pata_via.o
 obj-$(CONFIG_PATA_WINBOND)	+= pata_sl82c105.o
 obj-$(CONFIG_PATA_SIS)		+= pata_sis.o
 obj-$(CONFIG_PATA_TRIFLEX)	+= pata_triflex.o
+obj-$(CONFIG_PATA_PLATFORM)	+= pata_platform.o
 # Should be last but one libata driver
 obj-$(CONFIG_ATA_GENERIC)	+= ata_generic.o
 # Should be last libata driver
drivers/ata/pata_platform.c new file +198 -0

198 lines not on this page · raw message

#5 lore raw

Hi Paul,

I tried you patch on our CPCI405 PowerPC board (arch/ppc/platforms/4xx/cpci405.c).
It seems to work fine together with our onboard CompactFlash slot.

Because our IDE registers are memory mapped, I had to patch the resource .start and .end address by subtracting _IO_BASE, so that the pata code can use the IO way to talk to the IDE registers.

Perhaps it is a good idea to update the pata platform driver to be able to handle both _IO and _MEM resources. The _IO resources be be handled as it is already done by your code and for _MEM resources the pata platform driver can do the ioremapping as I currently do in my board setup.

I vote for the generic pata platform device IDE driver:-)

Here's my patch for the cpci405 board setup - just for information:

(quoted diff) +0 -0

b/arch/ppc/platforms/4xx/cpci405.c
index 3674309..f696854 100644

arch/ppc/platforms/4xx/cpci405.c +30 -0
@@ -26,6 +26,8 @@ #include <linux/serial_core.h>
 #include <asm/ocp.h>
 #include <asm/ibm_ocp_pci.h>
 #include <platforms/4xx/ibm405gp.h>
+#include <linux/delay.h>
+#include <linux/platform_device.h>
 
 #ifdef CONFIG_GEN_RTC
 void *cpci405_nvram;
@@ -108,6 +110,68 @@ #endif
        }
 }
 
+#ifdef CONFIG_PATA_PLATFORM
+#define CPCI405_CF_PADDR        0xf0100000
+#define CPCI405_CF_SIZE         0x10
+#define CPCI405_CF_IRQ          31
+#define CPCI405_CTRL_PADDR      0xf0400000
+#define CPCI405_CTRL_SIZE       0x100
+
+static struct resource cpci405_cf_resources[3];
+
+static struct platform_device cpci405_cf = {
+       .name           = "pata_platform",
+       .id             = 0,
+       .num_resources  = 3,
+       .resource       = cpci405_cf_resources
+};
+
+static int __init
+cpci405_setup_cf(void)
+{
+       void __iomem *cf;
+       volatile u16 __iomem *fpgactrl;
+
+       if ((cf = ioremap(CPCI405_CF_PADDR, CPCI405_CF_SIZE)) == NULL) {
+               printk("ioremap for CompactFlash controller failed\n");
+               return -1;
+       }
+
+       if ((fpgactrl = ioremap(CPCI405_CTRL_PADDR, CPCI405_CTRL_SIZE)) == 

NULL) {
+ printk("ioremap for FPGA control registers failed\n");
+ goto unmap;
+ }
+

+       /* reset CompactFlash card */
+       *fpgactrl &= ~0x0001;
+       mdelay(1);
+       *fpgactrl |= 0x0001;
+       iounmap(fpgactrl);
+
+       cpci405_cf_resources[0].start = (resource_size_t)cf - _IO_BASE;
+       cpci405_cf_resources[0].end   = (resource_size_t)cf - _IO_BASE + 7;
+       cpci405_cf_resources[0].flags = IORESOURCE_IO;
+
+       cpci405_cf_resources[1].start = (resource_size_t)cf - _IO_BASE + 0x0e;
+       cpci405_cf_resources[1].end   = (resource_size_t)cf - _IO_BASE + 0x0f;
+       cpci405_cf_resources[1].flags = IORESOURCE_IO;

+
+ cpci405_cf_resources[2].start = CPCI405_CF_IRQ;
+ cpci405_cf_resources[2].flags = IORESOURCE_IRQ;
+
+ if (platform_device_register(&cpci405_cf) < 0) {
+ printk("platform_device_register for CompactFlash failed\n");
+ goto unmap;
+ }
+
+ return 0;
+unmap:
+ iounmap(cf);
+ return -1;
+}
+arch_initcall(cpci405_setup_cf);
+#endif /* CONFIG_PATA_PLATFORM */
+
void __init
cpci405_setup_arch(void)
{

Matthias

Quoted 15 lines · Paul Mundt
Quoted 9 lines · Alan Cox

Ar Iau, 2006-10-05 am 05:05 +0900, ysgrifennodd Paul Mundt:

Quoted 3 lines

Ok, I wasn't sure if libata was intended for anything outside of the SATA case (especially non-PCI), but if that's the way to go, I'll look at hacking something up under libata.

Take a look at 2.6.18-mm or 2.6.19-* and you should see all you need in that including the pcmcia driver and other users who set up much the same way a generic platform device driver would.

Ok, just hacked this together quickly, how does it look? I'm booting this on an SH-4A (R7780RP) from current git and all works fine..

Thankfully you did most of the heavy lifting :-)

author
#6 lore raw

Hi Matthias,

Quoted 9 lines · Matthias Fuchs

I tried you patch on our CPCI405 PowerPC board (arch/ppc/platforms/4xx/cpci405.c).
It seems to work fine together with our onboard CompactFlash slot.

Because our IDE registers are memory mapped, I had to patch the resource .start and .end address by subtracting _IO_BASE, so that the pata code can use the IO way to talk to the IDE registers.

Quoted 5 lines

Perhaps it is a good idea to update the pata platform driver to be able to handle both _IO and _MEM resources. The _IO resources be be handled as it is already done by your code and for _MEM resources the pata platform driver can do the ioremapping as I currently do in my board setup.

Yes, that's one thing I was thinking of as well.. Here's a patch that makes an attempt at that, can you give it a try and see if it works for you? This applies on top of the earlier patch. None of the ARM, SH, or H8300 cases need to do the remapping at least.

Hopefully this will clean up your setup mess a bit.. If this works for you, I'll tidy it up a bit and submit the entire patch again.

 drivers/ata/pata_platform.c |  103 ++++++++++++++++++++++++++++++++++++++------
 1 file changed, 90 insertions(+), 13 deletions(-)

--

drivers/ata/pata_platform.c +90 -13
index 5d98332..a716e63 100644
@@ -21,7 +21,7 @@ #include <linux/libata.h>
 #include <linux/platform_device.h>
 
 #define DRV_NAME "pata_platform"
-#define DRV_VERSION "0.1.0"
+#define DRV_VERSION "0.1.1"
 
 static int pio_mask = 1;
 
@@ -45,6 +45,23 @@ static void pata_platform_set_mode(struc
 	}
 }
 
+static void pata_platform_host_stop(struct ata_host *host)
+{
+	int i;
+
+	/*
+	 * Unmap the bases for MMIO
+	 */
+	for (i = 0; i < host->n_ports; i++) {
+		struct ata_port *ap = host->ports[i];
+
+		if (ap->flags & ATA_FLAG_MMIO) {
+			iounmap((void __iomem *)ap->ioaddr.ctl_addr);
+			iounmap((void __iomem *)ap->ioaddr.cmd_addr);
+		}
+	}
+}
+
 static struct scsi_host_template pata_platform_sht = {
 	.module			= THIS_MODULE,
 	.name			= DRV_NAME,
@@ -88,7 +105,7 @@ static struct ata_port_operations pata_p
 
 	.port_start		= ata_port_start,
 	.port_stop		= ata_port_stop,
-	.host_stop		= ata_host_stop
+	.host_stop		= pata_platform_host_stop
 };
 
 /**
@@ -100,14 +117,20 @@ static struct ata_port_operations pata_p
  *
  *	Platform devices are expected to contain 3 resources per port:
  *
- *		- I/O Base (IORESOURCE_IO)
- *		- CTL Base (IORESOURCE_IO)
+ *		- I/O Base (IORESOURCE_IO or IORESOURCE_MEM)
+ *		- CTL Base (IORESOURCE_IO or IORESOURCE_MEM)
  *		- IRQ	   (IORESOURCE_IRQ)
+ *
+ * 	If the base resources are both mem types, the ioremap() is handled
+ * 	here. For IORESOURCE_IO, it's assumed that there's no remapping
+ * 	necessary.
  */
 static int __devinit pata_platform_probe(struct platform_device *pdev)
 {
 	struct resource *io_res, *ctl_res;
 	struct ata_probe_ent ae;
+	unsigned int mmio;
+	int ret;
 
 	/*
 	 * Simple resource validation ..
@@ -117,13 +140,31 @@ static int __devinit pata_platform_probe
 		return -EINVAL;
 	}
 
+	/*
+	 * Get the I/O base first
+	 */
 	io_res = platform_get_resource(pdev, IORESOURCE_IO, 0);
-	if (unlikely(io_res == NULL))
-		return -EINVAL;
+	if (io_res == NULL) {
+		io_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+		if (unlikely(io_res == NULL))
+			return -EINVAL;
+	}
 
+	/*
+	 * Then the CTL base
+	 */
 	ctl_res = platform_get_resource(pdev, IORESOURCE_IO, 1);
-	if (unlikely(ctl_res == NULL))
-		return -EINVAL;
+	if (ctl_res == NULL) {
+		ctl_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+		if (unlikely(ctl_res == NULL))
+			return -EINVAL;
+	}
+
+	/*
+	 * Check for MMIO
+	 */
+	mmio = (( io_res->flags == IORESOURCE_MEM) &&
+		(ctl_res->flags == IORESOURCE_MEM));
 
 	/*
 	 * Now that that's out of the way, wire up the port..
@@ -138,15 +179,51 @@ static int __devinit pata_platform_probe
 	ae.irq = platform_get_irq(pdev, 0);
 	ae.irq_flags = 0;
 	ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST;
-	ae.port[0].cmd_addr = io_res->start;
-	ae.port[0].altstatus_addr = ctl_res->start;
-	ae.port[0].ctl_addr = ctl_res->start;
+
+	/*
+	 * Handle the MMIO case
+	 */
+	if (mmio) {
+		ae.port_flags |= ATA_FLAG_MMIO;
+
+		ae.port[0].cmd_addr = (unsigned long)ioremap(io_res->start,
+				io_res->end - io_res->start + 1);
+		if (unlikely(!ae.port[0].cmd_addr)) {
+			dev_err(&pdev->dev, "failed to remap IO base\n");
+			return -ENXIO;
+		}
+
+		ae.port[0].ctl_addr = (unsigned long)ioremap(ctl_res->start,
+				ctl_res->end - ctl_res->start + 1);
+		if (unlikely(!ae.port[0].ctl_addr)) {
+			dev_err(&pdev->dev, "failed to remap CTL base\n");
+			ret = -ENXIO;
+			goto bad_remap;
+		}
+	} else {
+		ae.port[0].cmd_addr = io_res->start;
+		ae.port[0].ctl_addr = ctl_res->start;
+	}
+
+	ae.port[0].altstatus_addr = ae.port[0].ctl_addr;
+
 	ata_std_ports(&ae.port[0]);
 
-	if (unlikely(ata_device_add(&ae) == 0))
-		return -ENODEV;
+	if (unlikely(ata_device_add(&ae) == 0)) {
+		ret = -ENODEV;
+		goto add_failed;
+	}
 
 	return 0;
+
+add_failed:
+	if (ae.port[0].ctl_addr && mmio)
+		iounmap((void __iomem *)ae.port[0].ctl_addr);
+bad_remap:
+	if (ae.port[0].cmd_addr && mmio)
+		iounmap((void __iomem *)ae.port[0].cmd_addr);
+
+	return ret;
 }
 
 /**
#7 lore raw
Quoted 10 lines · Paul Mundt
Quoted 4 lines · Matthias Fuchs

Perhaps it is a good idea to update the pata platform driver to be able to handle both _IO and _MEM resources. The _IO resources be be handled as it is already done by your code and for _MEM resources the pata platform driver can do the ioremapping as I currently do in my board setup.

Yes, that's one thing I was thinking of as well.. Here's a patch that makes an attempt at that, can you give it a try and see if it works for you? This applies on top of the earlier patch. None of the ARM, SH, or H8300 cases need to do the remapping at least.

It's likely that ARM will switch over to using the MMIO resources if this patch makes it in. There's certain ARM platforms which would benefit from this change (since inb() and friends are more complex than they necessarily need to be.)

However, one issue needs to be solved before we could do that - how do we handle the case where the IDE registers are on a 4 byte spacing interval instead of the usual 1 byte?

I notice that this driver is calling ata_std_ports() which handles the standard setup. Maybe that needs to become a little more inteligent?

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
author
#8 lore raw
Quoted 6 lines · Russell King
Quoted 4 lines · Paul Mundt

Yes, that's one thing I was thinking of as well.. Here's a patch that makes an attempt at that, can you give it a try and see if it works for you? This applies on top of the earlier patch. None of the ARM, SH, or H8300 cases need to do the remapping at least.

Quoted 9 lines

It's likely that ARM will switch over to using the MMIO resources if this patch makes it in. There's certain ARM platforms which would benefit from this change (since inb() and friends are more complex than they necessarily need to be.)

However, one issue needs to be solved before we could do that - how do we handle the case where the IDE registers are on a 4 byte spacing interval instead of the usual 1 byte?

We could solve this in the driver, but it sounds like this is something that libata should have some visibility of directly.

Quoted 3 lines

I notice that this driver is calling ata_std_ports() which handles the standard setup. Maybe that needs to become a little more inteligent?

If we go this route, I suppose the easiest option will be simply to have a private structure with a few function pointers for these sorts of things, or we can simply have an element for the spacing interval if you don't forsee needing to change the ioaddrs in any fashion beyond the register spacing.. Which approach would you be more comfortable with? Are there any other items that you're concerned with in the current driver?

Thanks for the feedback!

#9 lore raw
Quoted 21 lines · Paul Mundt
Quoted 5 lines · Russell King
Quoted 4 lines · Paul Mundt

Yes, that's one thing I was thinking of as well.. Here's a patch that makes an attempt at that, can you give it a try and see if it works for you? This applies on top of the earlier patch. None of the ARM, SH, or H8300 cases need to do the remapping at least.

Quoted 9 lines

It's likely that ARM will switch over to using the MMIO resources if this patch makes it in. There's certain ARM platforms which would benefit from this change (since inb() and friends are more complex than they necessarily need to be.)

However, one issue needs to be solved before we could do that - how do we handle the case where the IDE registers are on a 4 byte spacing interval instead of the usual 1 byte?

We could solve this in the driver, but it sounds like this is something that libata should have some visibility of directly.

Quoted 3 lines

I notice that this driver is calling ata_std_ports() which handles the standard setup. Maybe that needs to become a little more inteligent?

Quoted 7 lines

If we go this route, I suppose the easiest option will be simply to have a private structure with a few function pointers for these sorts of things, or we can simply have an element for the spacing interval if you don't forsee needing to change the ioaddrs in any fashion beyond the register spacing.. Which approach would you be more comfortable with? Are there any other items that you're concerned with in the current driver?

Here's the decision matrix for libata: Will the hardware use the standard taskfile push/pull functions like ata_tf_load(), ata_tf_read(), ata_exec_command(), etc.? If yes, simply replace ata_std_ports() call with a call to your own function, written similarly to pdc_ata_setup_port() in sata_promise.c.

If the hardware requires non-standard I/O accessors, or the register sizes themselves changed, then you must implement your own taskfile I/O functions, similar to k2_sata_tf_load(), k2_sata_tf_read(), and k2_bmdma_setup_mmio() in sata_svw.c. For this case, data in struct ata_ioports is largely up to you to manage, or ignore.

If there are special command setup or teardown operations, there are other standard hooks to override as well.

Jeff

#10 lore raw
In reply to Paul Mundt

question: where is linux/ide-platform.h header?

Quoted 161 lines · Paul Mundt

Currently the platforms that have very simplistic needs for IDE devices are forced to invent their own driver for adding the built-in devices. At the moment ARM is the in-tree user in this category, h8300 could be switched to something more generic, and SH is roughly in the same category as ARM.

The only constant that really tends to change between these platforms are the I/O base and the IRQ, with everything else rather constant. The ctl base could also change, but everyone seems to keep it at 0x206, so it's debatable whether it's worth leaving this configurable or not.

I've hacked together a quick driver, 'ide-platform' (for lack of a better name), that allows for these specifics to be passed in via platform device resources (registering a device per-port) rather than having to add more of these things to drivers/ide.

With this we can remove ide_arm (and the h8300 driver can likely be reworked to use this too), and I don't have to invent a new driver for SH that does effectively the same thing.

This is intended purely for the simple NO_DMA ide_generic case.. nothing complicated.

What do people think about this, is there a better way to do this?

--

 drivers/ide/Makefile       |    3 +-
 drivers/ide/ide-platform.c |   60 +++++++++++++++++++++++++++++++++ 
++++++++++++
 drivers/ide/ide.c          |    3 ++
 3 files changed, 65 insertions(+), 1 deletion(-)

commit f2da2c8c9b5e648ca9a43d9d3fed9bcd356f0efd

Author: Paul Mundt <[email protected]>
Date:   Wed Oct 4 16:41:21 2006 +0900

ide: Simple platform device IDE driver.

This adds a trivial platform device IDE driver. Users are
required to
register a couple of resources:

- I/O Base
- CTL Base
- IRQ

drivers/ide/Makefile +0 -1
index 569fae7..24c9a0f 100644
@@ -13,7 +13,8 @@ EXTRA_CFLAGS				+= -Idrivers/ide
 
 obj-$(CONFIG_BLK_DEV_IDE)		+= pci/
 
-ide-core-y += ide.o ide-io.o ide-iops.o ide-lib.o ide-probe.o ide- 

taskfile.o
+ide-core-y += ide.o ide-io.o ide-iops.o ide-lib.o ide-probe.o ide- taskfile.o \

drivers/ide/Makefile +1 -0
+	      ide-platform.o
 
 ide-core-$(CONFIG_BLK_DEV_CMD640)	+= pci/cmd640.o
drivers/ide/ide-platform.c new file +6 -0
new file mode 100644
index 0000000..6d89878
@@ -0,0 +1,60 @@
+/*
+ * Generic IDE platform device driver
+ *
+ * Copyright (C) 2006  Paul Mundt
+ *
+ * This file is subject to the terms and conditions of the GNU  

General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */

drivers/ide/ide-platform.c new file +51 -0
+#include <linux/init.h>
+#include <linux/ide.h>
+#include <linux/platform_device.h>
+
+/*
+ * Users use per-port registration with a simple set of 3 resources
+ * per port:
+ * 		- I/O Base (IORESOURCE_IO)
+ * 		- CTL Base (IORESOURCE_IO)
+ * 		- IRQ	   (IORESOURCE_IRQ)
+ */
+static int __devinit ide_platform_probe(struct platform_device *dev)
+{
+	struct resource *io_res, *ctl_res;
+	hw_regs_t hw;
+
+	if (unlikely(dev->num_resources != 3)) {
+		dev_err(&dev->dev, "invalid number of resources\n");
+		return -EINVAL;
+	}
+
+	io_res = platform_get_resource(dev, IORESOURCE_IO, 0);
+	if (unlikely(io_res == NULL))
+		return -EINVAL;
+
+	ctl_res = platform_get_resource(dev, IORESOURCE_IO, 1);
+	if (unlikely(ctl_res == NULL))
+		return -EINVAL;
+
+	memset(&hw, 0, sizeof(hw_regs_t));
+	ide_std_init_ports(&hw, io_res->start, ctl_res->start);
+
+	hw.irq		= platform_get_irq(dev, 0);
+	hw.chipset	= ide_generic;
+
+	return ide_register_hw(&hw, NULL);
+}
+
+static struct platform_driver ide_platform_driver = {
+	.probe		= ide_platform_probe,
+	.driver		= {
+		.name	= "ide-platform",
+		.owner	= THIS_MODULE,
+	},
+};
+
+void __init ide_platform_init(void)
+{
+	printk(KERN_INFO "ide-platform: platform device IDE interface\n");
+	platform_driver_register(&ide_platform_driver);
+}
drivers/ide/ide.c +3 -1
index 287a662..994cdd4 100644
@@ -1782,6 +1782,7 @@ done:
 }
 
 extern void pnpide_init(void);
+extern void ide_platform_init(void);
 extern void h8300_ide_init(void);
 
 /*
@@ -1793,6 +1794,8 @@ #ifdef CONFIG_BLK_DEV_IDEPCI
 	ide_scan_pcibus(ide_scan_direction);
 #endif /* CONFIG_BLK_DEV_IDEPCI */
 
+	ide_platform_init();
+
 #ifdef CONFIG_ETRAX_IDE
 	{
 		extern void init_e100_ide(void);
-

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

author
#11 lore raw
Quoted 2 lines · girish

question: where is linux/ide-platform.h header?

answer: there isn't one, as it's not needed. The reason for using platform devices is so we get _away_ from this ridiculous static set of definitions for I/O addresses and IRQs that are sprinkled around a lot of these drivers.

#12 lore raw
Quoted 7 lines · Paul Mundt
Quoted 2 lines · girish

question: where is linux/ide-platform.h header?

answer: there isn't one, as it's not needed. The reason for using platform devices is so we get _away_ from this ridiculous static set of definitions for I/O addresses and IRQs that are sprinkled around a lot of these drivers.

i wrote wrong file name:

where is linux/platform_device.h file?

as per the patch :

+#include <linux/ide.h>
+#include <linux/platform_device.h>
+
+/*
+ * Users use per-port registration with a simple set of 3 resources
+ * per port:
+ * - I/O Base (IORESOURCE_IO)
+ * - CTL Base (IORESOURCE_IO)
+ * - IRQ (IORESOURCE_IRQ)
+ */
+static int __devinit ide_platform_probe(struct platform_device *dev) +{
+ struct resource *io_res, *ctl_res;
+ hw_regs_t hw;
+
+ if (unlikely(dev->num_resources != 3)) {
+ dev_err(&dev->dev, "invalid number of resources\n");
+ return -EINVAL;
+ }
+
+ io_res = platform_get_resource(dev, IORESOURCE_IO, 0);
+ if (unlikely(io_res == NULL))
+ return -EINVAL;
+