diff mbox

[U-Boot,v3] scsi/ahci: add support for non-PCI controllers

Message ID 1310004816-18266-1-git-send-email-robherring2@gmail.com
State Accepted
Commit 942e31437d2ba34acab259901b929532ba77390a
Headers show

Commit Message

Rob Herring July 7, 2011, 2:13 a.m. UTC
From: Rob Herring <rob.herring@calxeda.com>

Add support for AHCI controllers that are not PCI based.

Signed-off-by: Rob Herring <rob.herring@calxeda.com>
Cc: Wolfgang Denk <wd@denx.de>
---
changes in v2:
- fix checkpatch.pl warnings/errors
- fix label indentation
- simplify "sizeof(hd_driveid_t *) * AHCI_MAX_PORTS" to "sizeof(ataid)"
- Add function prototypes for ahci_init and scsi_scan

changes in v3:
- Introduce CONFIG_SCSI_AHCI_PLAT and replace CONFIG_PCI with it in 
  ahci.c
- Make no SCSI_DEV_ID and SCSI_VEND_ID only okay if CONFIG_SCSI_AHCI_PLAT
  is defined.
- fix checkpatch.pl warnings/errors (again...)

 common/cmd_scsi.c    |    5 ++-
 drivers/block/ahci.c |   70 ++++++++++++++++++++++++++++++++++++++++++++-----
 include/ahci.h       |    4 +++
 include/scsi.h       |    1 +
 4 files changed, 70 insertions(+), 10 deletions(-)

Comments

Wolfgang Denk July 25, 2011, 10:07 p.m. UTC | #1
Dear Rob Herring,

In message <1310004816-18266-1-git-send-email-robherring2@gmail.com> you wrote:
> From: Rob Herring <rob.herring@calxeda.com>
> 
> Add support for AHCI controllers that are not PCI based.
> 
> Signed-off-by: Rob Herring <rob.herring@calxeda.com>
> Cc: Wolfgang Denk <wd@denx.de>
> ---
> changes in v2:
> - fix checkpatch.pl warnings/errors
> - fix label indentation
> - simplify "sizeof(hd_driveid_t *) * AHCI_MAX_PORTS" to "sizeof(ataid)"
> - Add function prototypes for ahci_init and scsi_scan
> 
> changes in v3:
> - Introduce CONFIG_SCSI_AHCI_PLAT and replace CONFIG_PCI with it in 
>   ahci.c
> - Make no SCSI_DEV_ID and SCSI_VEND_ID only okay if CONFIG_SCSI_AHCI_PLAT
>   is defined.
> - fix checkpatch.pl warnings/errors (again...)
> 
>  common/cmd_scsi.c    |    5 ++-
>  drivers/block/ahci.c |   70 ++++++++++++++++++++++++++++++++++++++++++++-----
>  include/ahci.h       |    4 +++
>  include/scsi.h       |    1 +
>  4 files changed, 70 insertions(+), 10 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk
diff mbox

Patch

diff --git a/common/cmd_scsi.c b/common/cmd_scsi.c
index be4fe74..352781b 100644
--- a/common/cmd_scsi.c
+++ b/common/cmd_scsi.c
@@ -46,7 +46,7 @@ 
 #define SCSI_VEND_ID 0x10b9
 #define SCSI_DEV_ID  0x5288
 
-#else
+#elif !defined(CONFIG_SCSI_AHCI_PLAT)
 #error no scsi device defined
 #endif
 
@@ -174,7 +174,7 @@  removable:
 		scsi_curr_dev = -1;
 }
 
-
+#ifdef CONFIG_PCI
 void scsi_init(void)
 {
 	int busdevfunc;
@@ -192,6 +192,7 @@  void scsi_init(void)
 	scsi_low_level_init(busdevfunc);
 	scsi_scan(1);
 }
+#endif
 
 block_dev_desc_t * scsi_get_dev(int dev)
 {
diff --git a/drivers/block/ahci.c b/drivers/block/ahci.c
index d431c5a..64f52bb 100644
--- a/drivers/block/ahci.c
+++ b/drivers/block/ahci.c
@@ -78,13 +78,15 @@  static int waiting_for_cmd_completed(volatile u8 *offset,
 
 static int ahci_host_init(struct ahci_probe_ent *probe_ent)
 {
+#ifndef CONFIG_SCSI_AHCI_PLAT
 	pci_dev_t pdev = probe_ent->dev;
+	u16 tmp16;
+	unsigned short vendor;
+#endif
 	volatile u8 *mmio = (volatile u8 *)probe_ent->mmio_base;
 	u32 tmp, cap_save;
-	u16 tmp16;
 	int i, j;
 	volatile u8 *port_mmio;
-	unsigned short vendor;
 
 	cap_save = readl(mmio + HOST_CAP);
 	cap_save &= ((1 << 28) | (1 << 17));
@@ -110,6 +112,7 @@  static int ahci_host_init(struct ahci_probe_ent *probe_ent)
 	writel(cap_save, mmio + HOST_CAP);
 	writel_with_flush(0xf, mmio + HOST_PORTS_IMPL);
 
+#ifndef CONFIG_SCSI_AHCI_PLAT
 	pci_read_config_word(pdev, PCI_VENDOR_ID, &vendor);
 
 	if (vendor == PCI_VENDOR_ID_INTEL) {
@@ -118,7 +121,7 @@  static int ahci_host_init(struct ahci_probe_ent *probe_ent)
 		tmp16 |= 0xf;
 		pci_write_config_word(pdev, 0x92, tmp16);
 	}
-
+#endif
 	probe_ent->cap = readl(mmio + HOST_CAP);
 	probe_ent->port_map = readl(mmio + HOST_PORTS_IMPL);
 	probe_ent->n_ports = (probe_ent->cap & 0x1f) + 1;
@@ -183,22 +186,24 @@  static int ahci_host_init(struct ahci_probe_ent *probe_ent)
 	writel(tmp | HOST_IRQ_EN, mmio + HOST_CTL);
 	tmp = readl(mmio + HOST_CTL);
 	debug("HOST_CTL 0x%x\n", tmp);
-
+#ifndef CONFIG_SCSI_AHCI_PLAT
 	pci_read_config_word(pdev, PCI_COMMAND, &tmp16);
 	tmp |= PCI_COMMAND_MASTER;
 	pci_write_config_word(pdev, PCI_COMMAND, tmp16);
-
+#endif
 	return 0;
 }
 
 
 static void ahci_print_info(struct ahci_probe_ent *probe_ent)
 {
+#ifndef CONFIG_SCSI_AHCI_PLAT
 	pci_dev_t pdev = probe_ent->dev;
+	u16 cc;
+#endif
 	volatile u8 *mmio = (volatile u8 *)probe_ent->mmio_base;
 	u32 vers, cap, impl, speed;
 	const char *speed_s;
-	u16 cc;
 	const char *scc_s;
 
 	vers = readl(mmio + HOST_VERSION);
@@ -213,6 +218,9 @@  static void ahci_print_info(struct ahci_probe_ent *probe_ent)
 	else
 		speed_s = "?";
 
+#ifdef CONFIG_SCSI_AHCI_PLAT
+	scc_s = "SATA";
+#else
 	pci_read_config_word(pdev, 0x0a, &cc);
 	if (cc == 0x0101)
 		scc_s = "IDE";
@@ -222,7 +230,7 @@  static void ahci_print_info(struct ahci_probe_ent *probe_ent)
 		scc_s = "RAID";
 	else
 		scc_s = "unknown";
-
+#endif
 	printf("AHCI %02x%02x.%02x%02x "
 	       "%u slots %u ports %s Gbps 0x%x impl %s mode\n",
 	       (vers >> 24) & 0xff,
@@ -249,6 +257,7 @@  static void ahci_print_info(struct ahci_probe_ent *probe_ent)
 	       cap & (1 << 13) ? "part " : "");
 }
 
+#ifndef CONFIG_SCSI_AHCI_PLAT
 static int ahci_init_one(pci_dev_t pdev)
 {
 	u16 vendor;
@@ -291,7 +300,7 @@  static int ahci_init_one(pci_dev_t pdev)
       err_out:
 	return rc;
 }
-
+#endif
 
 #define MAX_DATA_BYTE_COUNT  (4*1024*1024)
 
@@ -667,7 +676,9 @@  void scsi_low_level_init(int busdevfunc)
 	int i;
 	u32 linkmap;
 
+#ifndef CONFIG_SCSI_AHCI_PLAT
 	ahci_init_one(busdevfunc);
+#endif
 
 	linkmap = probe_ent->link_port_map;
 
@@ -682,6 +693,49 @@  void scsi_low_level_init(int busdevfunc)
 	}
 }
 
+#ifdef CONFIG_SCSI_AHCI_PLAT
+int ahci_init(u32 base)
+{
+	int i, rc = 0;
+	u32 linkmap;
+
+	memset(ataid, 0, sizeof(ataid));
+
+	probe_ent = malloc(sizeof(struct ahci_probe_ent));
+	memset(probe_ent, 0, sizeof(struct ahci_probe_ent));
+
+	probe_ent->host_flags = ATA_FLAG_SATA
+				| ATA_FLAG_NO_LEGACY
+				| ATA_FLAG_MMIO
+				| ATA_FLAG_PIO_DMA
+				| ATA_FLAG_NO_ATAPI;
+	probe_ent->pio_mask = 0x1f;
+	probe_ent->udma_mask = 0x7f;	/*Fixme,assume to support UDMA6 */
+
+	probe_ent->mmio_base = base;
+
+	/* initialize adapter */
+	rc = ahci_host_init(probe_ent);
+	if (rc)
+		goto err_out;
+
+	ahci_print_info(probe_ent);
+
+	linkmap = probe_ent->link_port_map;
+
+	for (i = 0; i < CONFIG_SYS_SCSI_MAX_SCSI_ID; i++) {
+		if (((linkmap >> i) & 0x01)) {
+			if (ahci_port_start((u8) i)) {
+				printf("Can not start port %d\n", i);
+				continue;
+			}
+			ahci_set_feature((u8) i);
+		}
+	}
+err_out:
+	return rc;
+}
+#endif
 
 void scsi_bus_reset(void)
 {
diff --git a/include/ahci.h b/include/ahci.h
index 0c6bbbd..465ea7f 100644
--- a/include/ahci.h
+++ b/include/ahci.h
@@ -25,6 +25,8 @@ 
 #ifndef _AHCI_H_
 #define _AHCI_H_
 
+#include <pci.h>
+
 #define AHCI_PCI_BAR		0x24
 #define AHCI_MAX_SG		56 /* hardware max is 64K */
 #define AHCI_CMD_SLOT_SZ	32
@@ -187,4 +189,6 @@  struct ahci_probe_ent {
 	u32	link_port_map; /*linkup port map*/
 };
 
+int ahci_init(u32 base);
+
 #endif
diff --git a/include/scsi.h b/include/scsi.h
index aaafc9c..c52759c 100644
--- a/include/scsi.h
+++ b/include/scsi.h
@@ -185,6 +185,7 @@  void scsi_low_level_init(int busdevfunc);
  * functions residing inside cmd_scsi.c
  */
 void scsi_init(void);
+void scsi_scan(int mode);
 
 
 #define SCSI_IDENTIFY					0xC0  /* not used */