Patchwork [U-Boot,4/7] ahci: move link bring-up handling to separate function

login
register
mail settings
Submitter Rob Herring
Date May 21, 2013, 10:44 p.m.
Message ID <1369176276-1895-4-git-send-email-robherring2@gmail.com>
Download mbox | patch
Permalink /patch/245441/
State Changes Requested
Delegated to: Tom Rini
Headers show

Comments

Rob Herring - May 21, 2013, 10:44 p.m.
From: Rob Herring <rob.herring@calxeda.com>

Move the link bring-up handling to a separate weak function in order to
allow platforms to override it. This is needed on highbank platform which
needs special phy handling.

Signed-off-by: Rob Herring <rob.herring@calxeda.com>
---
 drivers/block/ahci.c | 39 +++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)
Tom Rini - May 24, 2013, 1:44 p.m.
On Tue, May 21, 2013 at 05:44:33PM -0500, Rob Herring wrote:

> From: Rob Herring <rob.herring@calxeda.com>
> 
> Move the link bring-up handling to a separate weak function in order to
> allow platforms to override it. This is needed on highbank platform which
> needs special phy handling.
> 
> Signed-off-by: Rob Herring <rob.herring@calxeda.com>
[snip]
> +static int __ahci_link_up(struct ahci_probe_ent *probe_ent, u8 port)
> +{
> +	u32 tmp;
> +	int j = 0;
> +	u8 *port_mmio = (u8 *)probe_ent->port[port].port_mmio;
> +
> +	/* Bring up SATA link.

/*
 * Like this
 */

> +int ahci_link_up(struct ahci_probe_ent *probe_ent, u8 port)
> +	__attribute__((weak, alias("__ahci_link_up")));

Just use __weak please, thanks.

Patch

diff --git a/drivers/block/ahci.c b/drivers/block/ahci.c
index a2aa433..79710ef 100644
--- a/drivers/block/ahci.c
+++ b/drivers/block/ahci.c
@@ -124,6 +124,27 @@  static int waiting_for_cmd_completed(volatile u8 *offset,
 	return (i < timeout_msec) ? 0 : -1;
 }
 
+static int __ahci_link_up(struct ahci_probe_ent *probe_ent, u8 port)
+{
+	u32 tmp;
+	int j = 0;
+	u8 *port_mmio = (u8 *)probe_ent->port[port].port_mmio;
+
+	/* Bring up SATA link.
+	 * SATA link bringup time is usually less than 1 ms; only very
+	 * rarely has it taken between 1-2 ms. Never seen it above 2 ms.
+	 */
+	while (j < WAIT_MS_LINKUP) {
+		tmp = readl(port_mmio + PORT_SCR_STAT);
+		if ((tmp & 0xf) == 0x3)
+			return 0;
+		udelay(1000);
+		j++;
+	}
+	return 1;
+}
+int ahci_link_up(struct ahci_probe_ent *probe_ent, u8 port)
+	__attribute__((weak, alias("__ahci_link_up")));
 
 static int ahci_host_init(struct ahci_probe_ent *probe_ent)
 {
@@ -134,7 +155,7 @@  static int ahci_host_init(struct ahci_probe_ent *probe_ent)
 #endif
 	volatile u8 *mmio = (volatile u8 *)probe_ent->mmio_base;
 	u32 tmp, cap_save, cmd;
-	int i, j;
+	int i, j, ret;
 	volatile u8 *port_mmio;
 	u32 port_map;
 
@@ -217,19 +238,9 @@  static int ahci_host_init(struct ahci_probe_ent *probe_ent)
 		cmd |= PORT_CMD_SPIN_UP;
 		writel_with_flush(cmd, port_mmio + PORT_CMD);
 
-		/* Bring up SATA link.
-		 * SATA link bringup time is usually less than 1 ms; only very
-		 * rarely has it taken between 1-2 ms. Never seen it above 2 ms.
-		 */
-		j = 0;
-		while (j < WAIT_MS_LINKUP) {
-			tmp = readl(port_mmio + PORT_SCR_STAT);
-			if ((tmp & 0xf) == 0x3)
-				break;
-			udelay(1000);
-			j++;
-		}
-		if (j == WAIT_MS_LINKUP) {
+		/* Bring up SATA link. */
+		ret = ahci_link_up(probe_ent, i);
+		if (ret) {
 			printf("SATA link %d timeout.\n", i);
 			continue;
 		} else {