mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/6] ata: move ATA_ID_ fields and functions to include/
@ 2013-06-06 14:22 Sascha Hauer
  2013-06-06 14:22 ` [PATCH 2/6] ata: ahci: only use lba48 on drives which support it Sascha Hauer
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Sascha Hauer @ 2013-06-06 14:22 UTC (permalink / raw)
  To: barebox

We need ata_id_has_lba48() in another C file, so move
the ATA_ID_* stuff to include/ata_drive.h like in the Linux
Kernel.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/ata/disk_ata_drive.c | 44 --------------------------------------------
 include/ata_drive.h          | 44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/drivers/ata/disk_ata_drive.c b/drivers/ata/disk_ata_drive.c
index 2cff584..034233d 100644
--- a/drivers/ata/disk_ata_drive.c
+++ b/drivers/ata/disk_ata_drive.c
@@ -26,41 +26,6 @@
 #include <disks.h>
 #include <dma.h>
 
-#define ata_id_u32(id,n)        \
-        (((uint32_t) (id)[(n) + 1] << 16) | ((uint32_t) (id)[(n)]))
-#define ata_id_u64(id,n)        \
-        ( ((uint64_t) (id)[(n) + 3] << 48) | \
-          ((uint64_t) (id)[(n) + 2] << 32) | \
-          ((uint64_t) (id)[(n) + 1] << 16) | \
-          ((uint64_t) (id)[(n) + 0]) )
-
-#define ata_id_has_lba(id)               ((id)[49] & (1 << 9))
-
-enum {
-	ATA_ID_SERNO		= 10,
-#define ATA_ID_SERNO_LEN 20
-	ATA_ID_FW_REV		= 23,
-#define ATA_ID_FW_REV_LEN 8
-	ATA_ID_PROD		= 27,
-#define ATA_ID_PROD_LEN 40
-	ATA_ID_CAPABILITY	= 49,
-	ATA_ID_FIELD_VALID	= 53,
-	ATA_ID_LBA_CAPACITY	= 60,
-	ATA_ID_MWDMA_MODES	= 63,
-	ATA_ID_PIO_MODES	= 64,
-	ATA_ID_QUEUE_DEPTH	= 75,
-	ATA_ID_MAJOR_VER	= 80,
-	ATA_ID_COMMAND_SET_1	= 82,
-	ATA_ID_COMMAND_SET_2	= 83,
-	ATA_ID_CFSSE		= 84,
-	ATA_ID_CFS_ENABLE_1	= 85,
-	ATA_ID_CFS_ENABLE_2	= 86,
-	ATA_ID_CSF_DEFAULT	= 87,
-	ATA_ID_UDMA_MODES	= 88,
-	ATA_ID_HW_CONFIG	= 93,
-	ATA_ID_LBA_CAPACITY_2	= 100,
-};
-
 static int ata_id_is_valid(const uint16_t *id)
 {
 	if ((id[ATA_ID_FIELD_VALID] & 1) == 0) {
@@ -71,15 +36,6 @@ static int ata_id_is_valid(const uint16_t *id)
 	return 0;
 }
 
-static inline int ata_id_has_lba48(const uint16_t *id)
-{
-	if ((id[ATA_ID_COMMAND_SET_2] & 0xC000) != 0x4000)
-		return 0;
-	if (!ata_id_u64(id, ATA_ID_LBA_CAPACITY_2))
-		return 0;
-	return id[ATA_ID_COMMAND_SET_2] & (1 << 10);
-}
-
 static uint64_t ata_id_n_sectors(uint16_t *id)
 {
 	if (ata_id_has_lba(id)) {
diff --git a/include/ata_drive.h b/include/ata_drive.h
index 049082f..abbafb9 100644
--- a/include/ata_drive.h
+++ b/include/ata_drive.h
@@ -55,6 +55,50 @@
 #define ATA_DEVCTL_SOFT_RESET	(1 << 2)
 #define ATA_DEVCTL_INTR_DISABLE	(1 << 1)
 
+#define ata_id_u32(id,n)        \
+        (((uint32_t) (id)[(n) + 1] << 16) | ((uint32_t) (id)[(n)]))
+#define ata_id_u64(id,n)        \
+        ( ((uint64_t) (id)[(n) + 3] << 48) | \
+          ((uint64_t) (id)[(n) + 2] << 32) | \
+          ((uint64_t) (id)[(n) + 1] << 16) | \
+          ((uint64_t) (id)[(n) + 0]) )
+
+#define ata_id_has_lba(id)               ((id)[49] & (1 << 9))
+
+enum {
+	ATA_ID_SERNO		= 10,
+#define ATA_ID_SERNO_LEN 20
+	ATA_ID_FW_REV		= 23,
+#define ATA_ID_FW_REV_LEN 8
+	ATA_ID_PROD		= 27,
+#define ATA_ID_PROD_LEN 40
+	ATA_ID_CAPABILITY	= 49,
+	ATA_ID_FIELD_VALID	= 53,
+	ATA_ID_LBA_CAPACITY	= 60,
+	ATA_ID_MWDMA_MODES	= 63,
+	ATA_ID_PIO_MODES	= 64,
+	ATA_ID_QUEUE_DEPTH	= 75,
+	ATA_ID_MAJOR_VER	= 80,
+	ATA_ID_COMMAND_SET_1	= 82,
+	ATA_ID_COMMAND_SET_2	= 83,
+	ATA_ID_CFSSE		= 84,
+	ATA_ID_CFS_ENABLE_1	= 85,
+	ATA_ID_CFS_ENABLE_2	= 86,
+	ATA_ID_CSF_DEFAULT	= 87,
+	ATA_ID_UDMA_MODES	= 88,
+	ATA_ID_HW_CONFIG	= 93,
+	ATA_ID_LBA_CAPACITY_2	= 100,
+};
+
+static inline int ata_id_has_lba48(const uint16_t *id)
+{
+	if ((id[ATA_ID_COMMAND_SET_2] & 0xC000) != 0x4000)
+		return 0;
+	if (!ata_id_u64(id, ATA_ID_LBA_CAPACITY_2))
+		return 0;
+	return id[ATA_ID_COMMAND_SET_2] & (1 << 10);
+}
+
 /** addresses of each individual IDE drive register */
 struct ata_ioports {
 	void __iomem *cmd_addr;
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/6] ata: ahci: only use lba48 on drives which support it
  2013-06-06 14:22 [PATCH 1/6] ata: move ATA_ID_ fields and functions to include/ Sascha Hauer
@ 2013-06-06 14:22 ` Sascha Hauer
  2013-06-06 14:22 ` [PATCH 3/6] ata: implement detect Sascha Hauer
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2013-06-06 14:22 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/ata/ahci.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 7def9a0..19d445a 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -224,13 +224,19 @@ static int ahci_rw(struct ata_port *ata, void *rbuf, const void *wbuf,
 	struct ahci_port *ahci = container_of(ata, struct ahci_port, ata);
 	u8 fis[20];
 	int ret;
+	int lba48 = ata_id_has_lba48(ata->id);
 
 	memset(fis, 0, sizeof(fis));
 
 	/* Construct the FIS */
 	fis[0] = 0x27;			/* Host to device FIS. */
 	fis[1] = 1 << 7;		/* Command FIS. */
-	fis[2] = wbuf ? ATA_CMD_WRITE_EXT : ATA_CMD_READ_EXT;	/* Command byte. */
+
+	/* Command byte. */
+	if (lba48)
+		fis[2] = wbuf ? ATA_CMD_WRITE_EXT : ATA_CMD_READ_EXT;
+	else
+		fis[2] = wbuf ? ATA_CMD_WRITE : ATA_CMD_READ;
 
 	while (num_blocks) {
 		int now;
@@ -240,9 +246,14 @@ static int ahci_rw(struct ata_port *ata, void *rbuf, const void *wbuf,
 		fis[4] = (block >> 0) & 0xff;
 		fis[5] = (block >> 8) & 0xff;
 		fis[6] = (block >> 16) & 0xff;
-		fis[7] = 1 << 6; /* device reg: set LBA mode */
-		fis[8] = ((block >> 24) & 0xff);
-		fis[3] = 0xe0; /* features */
+
+		if (lba48) {
+			fis[7] = 1 << 6; /* device reg: set LBA mode */
+			fis[8] = ((block >> 24) & 0xff);
+			fis[3] = 0xe0; /* features */
+		} else {
+			fis[7] = ((block >> 24) & 0xf) | 0xe0;
+		}
 
 		/* Block (sector) count */
 		fis[12] = (now >> 0) & 0xff;
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/6] ata: implement detect
  2013-06-06 14:22 [PATCH 1/6] ata: move ATA_ID_ fields and functions to include/ Sascha Hauer
  2013-06-06 14:22 ` [PATCH 2/6] ata: ahci: only use lba48 on drives which support it Sascha Hauer
@ 2013-06-06 14:22 ` Sascha Hauer
  2013-06-06 14:22 ` [PATCH 4/6] ata: ahci: Allow 'detect' on hardware device Sascha Hauer
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2013-06-06 14:22 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/ata/disk_ata_drive.c | 24 +++++++++++++++++++-----
 include/ata_drive.h          |  1 +
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/ata/disk_ata_drive.c b/drivers/ata/disk_ata_drive.c
index 034233d..7669539 100644
--- a/drivers/ata/disk_ata_drive.c
+++ b/drivers/ata/disk_ata_drive.c
@@ -281,14 +281,10 @@ on_error:
 	return rc;
 }
 
-static int ata_set_probe(struct param_d *param, void *priv)
+int ata_port_detect(struct ata_port *port)
 {
-	struct ata_port *port = priv;
 	int ret;
 
-	if (!port->probe)
-		return 0;
-
 	if (port->initialized) {
 		dev_info(&port->class_dev, "already initialized\n");
 		return 0;
@@ -303,6 +299,23 @@ static int ata_set_probe(struct param_d *param, void *priv)
 	return 0;
 }
 
+static int ata_set_probe(struct param_d *param, void *priv)
+{
+	struct ata_port *port = priv;
+
+	if (!port->probe)
+		return 0;
+
+	return ata_port_detect(port);
+}
+
+static int ata_detect(struct device_d *dev)
+{
+	struct ata_port *port = container_of(dev, struct ata_port, class_dev);
+
+	return ata_port_detect(port);
+}
+
 /**
  * Register an ATA drive behind an IDE like interface
  * @param dev The interface device
@@ -316,6 +329,7 @@ int ata_port_register(struct ata_port *port)
 	port->class_dev.id = DEVICE_ID_DYNAMIC;
 	strcpy(port->class_dev.name, "ata");
 	port->class_dev.parent = port->dev;
+	port->class_dev.detect = ata_detect;
 
 	ret = register_device(&port->class_dev);
 	if (ret)
diff --git a/include/ata_drive.h b/include/ata_drive.h
index abbafb9..9961aea 100644
--- a/include/ata_drive.h
+++ b/include/ata_drive.h
@@ -144,6 +144,7 @@ struct ata_port {
 
 int ide_port_register(struct device_d *, struct ata_ioports *);
 int ata_port_register(struct ata_port *port);
+int ata_port_detect(struct ata_port *port);
 
 struct device_d;
 
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/6] ata: ahci: Allow 'detect' on hardware device
  2013-06-06 14:22 [PATCH 1/6] ata: move ATA_ID_ fields and functions to include/ Sascha Hauer
  2013-06-06 14:22 ` [PATCH 2/6] ata: ahci: only use lba48 on drives which support it Sascha Hauer
  2013-06-06 14:22 ` [PATCH 3/6] ata: implement detect Sascha Hauer
@ 2013-06-06 14:22 ` Sascha Hauer
  2013-06-06 14:22 ` [PATCH 5/6] ata: i.MX sata: Add devicetree probe support Sascha Hauer
  2013-06-06 14:22 ` [PATCH 6/6] ARM: i.MX6: Add sata device to devicetree Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2013-06-06 14:22 UTC (permalink / raw)
  To: barebox

Hook the detect callback to the hardware device.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/ata/ahci.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 19d445a..f9cf2d1 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -569,6 +569,20 @@ void ahci_info(struct device_d *dev)
 	ahci_print_info(ahci);
 }
 
+static int ahci_detect(struct device_d *dev)
+{
+	struct ahci_device *ahci = dev->priv;
+	int i;
+
+	for (i = 0; i < ahci->n_ports; i++) {
+		struct ahci_port *ahci_port = &ahci->ports[i];
+
+		ata_port_detect(&ahci_port->ata);
+	}
+
+	return 0;
+}
+
 int ahci_add_host(struct ahci_device *ahci)
 {
 	u8 *mmio = (u8 *)ahci->mmio_base;
@@ -630,6 +644,8 @@ int ahci_add_host(struct ahci_device *ahci)
 	ahci_iowrite(ahci, HOST_CTL, tmp | HOST_IRQ_EN);
 	tmp = ahci_ioread(ahci, HOST_CTL);
 
+	ahci->dev->detect = ahci_detect;
+
 	return 0;
 }
 
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 5/6] ata: i.MX sata: Add devicetree probe support
  2013-06-06 14:22 [PATCH 1/6] ata: move ATA_ID_ fields and functions to include/ Sascha Hauer
                   ` (2 preceding siblings ...)
  2013-06-06 14:22 ` [PATCH 4/6] ata: ahci: Allow 'detect' on hardware device Sascha Hauer
@ 2013-06-06 14:22 ` Sascha Hauer
  2013-06-06 14:22 ` [PATCH 6/6] ARM: i.MX6: Add sata device to devicetree Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2013-06-06 14:22 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/ata/sata-imx.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/ata/sata-imx.c b/drivers/ata/sata-imx.c
index 13bf116..ef7989e 100644
--- a/drivers/ata/sata-imx.c
+++ b/drivers/ata/sata-imx.c
@@ -141,9 +141,22 @@ static struct platform_device_id imx_sata_ids[] = {
 	},
 };
 
+static __maybe_unused struct of_device_id imx_sata_dt_ids[] = {
+	{
+		.compatible = "fsl,imx6q-ahci",
+		.data = (unsigned long)&data_imx6,
+	}, {
+		.compatible = "fsl,imx53-ahci",
+		.data = (unsigned long)&data_imx53,
+	}, {
+		/* sentinel */
+	}
+};
+
 static struct driver_d imx_sata_driver = {
 	.name   = "imx-sata",
 	.probe  = imx_sata_probe,
 	.id_table = imx_sata_ids,
+	.of_compatible = DRV_OF_COMPAT(imx_sata_dt_ids),
 };
 device_platform_driver(imx_sata_driver);
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 6/6] ARM: i.MX6: Add sata device to devicetree
  2013-06-06 14:22 [PATCH 1/6] ata: move ATA_ID_ fields and functions to include/ Sascha Hauer
                   ` (3 preceding siblings ...)
  2013-06-06 14:22 ` [PATCH 5/6] ata: i.MX sata: Add devicetree probe support Sascha Hauer
@ 2013-06-06 14:22 ` Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2013-06-06 14:22 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/dts/imx6qdl.dtsi | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/dts/imx6qdl.dtsi b/arch/arm/dts/imx6qdl.dtsi
index b636002..86084be 100644
--- a/arch/arm/dts/imx6qdl.dtsi
+++ b/arch/arm/dts/imx6qdl.dtsi
@@ -827,6 +827,16 @@
 			};
 		};
 
+		sata: sata@02200000 {
+			compatible = "fsl,imx6q-ahci";
+			reg = <0x02200000 0x4000>;
+			interrupts = <0 39 0x04>;
+			clocks = <&clks 154 &clks 105 &clks 187>;
+			clock-names = "ipg", "ahb", "per";
+			gprreg = <&gpr>;
+			status = "disabled";
+		};
+
 		ipu1: ipu@02400000 {
 			#crtc-cells = <1>;
 			compatible = "fsl,imx6q-ipu";
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-06-06 14:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-06 14:22 [PATCH 1/6] ata: move ATA_ID_ fields and functions to include/ Sascha Hauer
2013-06-06 14:22 ` [PATCH 2/6] ata: ahci: only use lba48 on drives which support it Sascha Hauer
2013-06-06 14:22 ` [PATCH 3/6] ata: implement detect Sascha Hauer
2013-06-06 14:22 ` [PATCH 4/6] ata: ahci: Allow 'detect' on hardware device Sascha Hauer
2013-06-06 14:22 ` [PATCH 5/6] ata: i.MX sata: Add devicetree probe support Sascha Hauer
2013-06-06 14:22 ` [PATCH 6/6] ARM: i.MX6: Add sata device to devicetree Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox