linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tejun Heo <htejun@gmail.com>
To: Jeff Garzik <jeff@garzik.org>,
	IDE/ATA development list <linux-ide@vger.kernel.org>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>
Subject: [PATCH 2/3] libata: extend ata_acpi_cbl_80wire() and fix cable detection in pata_via and pata_amd
Date: Sat, 03 Nov 2007 00:21:28 +0900	[thread overview]
Message-ID: <472B4078.90009@gmail.com> (raw)
In-Reply-To: <472B402A.4030009@gmail.com>

The current ata_acpi_cbl_80wire() is too retricted in its
functionality.  It always reads GTM itself and only returns whether
the cable is 80 wire or not.  Extend it such that...

* It accepts @gtm argument instead of reading iteslf.

* Returns one of ATA_CBL_PATA40, ATA_CBL_PATA80 or ATA_CBL_PATA_UNK.

The function is renamed to ata_acpi_cbl().  Currently there are two
users - cable detection functions of pata_via and pata_amd.  Both are
converted to use the new function with ap->acpi_init_gtm.

Using the initial GTM value is the right thing to do because both are
trying to check firmware setting and by the time ->cable_detect runs
the controller is already forced into PIO0 by reset.

Signed-off-by: Tejun Heo <htejun@gmail.com>
---
 drivers/ata/libata-acpi.c |   68 +++++++++++++++++++++++++---------------------
 drivers/ata/pata_amd.c    |    3 +-
 drivers/ata/pata_via.c    |    3 +-
 include/linux/libata.h    |    2 -
 4 files changed, 43 insertions(+), 33 deletions(-)

Index: work/drivers/ata/libata-acpi.c
===================================================================
--- work.orig/drivers/ata/libata-acpi.c
+++ work/drivers/ata/libata-acpi.c
@@ -390,42 +390,50 @@ static int ata_dev_get_GTF(struct ata_de
 }
 
 /**
- * ata_acpi_cbl_80wire		-	Check for 80 wire cable
- * @ap: Port to check
+ * ata_acpi_cbl - determine cable type from GTM values
+ * @ap: target ATA port
+ * @gtm: GTM to use
+ *
+ * Determine cable type from UDMA configuration in @gtm.  If UDMA is
+ * disabled, it returns ATA_CBL_PATA_UNK.  If UDMA is enabled and
+ * faster than 33, PATA_80; otherwise, PATA_40.
+ *
+ * LOCKING:
+ * None.
  *
- * Return 1 if the ACPI mode data for this port indicates the BIOS selected
- * an 80wire mode.
+ * RETURNS:
+ * Determined cable type (ATA_CBL_*).
  */
-
-int ata_acpi_cbl_80wire(struct ata_port *ap)
+int ata_acpi_cbl(struct ata_port *ap, const struct ata_acpi_gtm *gtm)
 {
-	struct ata_acpi_gtm gtm;
-	int valid = 0;
+	int cbl = ATA_CBL_PATA_UNK;
 
-	/* No _GTM data, no information */
-	if (ata_acpi_gtm(ap, &gtm) < 0)
-		return 0;
+	if (ata_dev_enabled(&ap->link.device[0]) && (gtm->flags & 0x1)) {
+		if (gtm->drive[0].dma < 55)
+			return ATA_CBL_PATA80;
+		else
+			cbl = ATA_CBL_PATA40;
+	}
 
-	/* Split timing, DMA enabled */
-	if ((gtm.flags & 0x11) == 0x11 && gtm.drive[0].dma < 55)
-		valid |= 1;
-	if ((gtm.flags & 0x14) == 0x14 && gtm.drive[1].dma < 55)
-		valid |= 2;
-	/* Shared timing, DMA enabled */
-	if ((gtm.flags & 0x11) == 0x01 && gtm.drive[0].dma < 55)
-		valid |= 1;
-	if ((gtm.flags & 0x14) == 0x04 && gtm.drive[0].dma < 55)
-		valid |= 2;
-
-	/* Drive check */
-	if ((valid & 1) && ata_dev_enabled(&ap->link.device[0]))
-		return 1;
-	if ((valid & 2) && ata_dev_enabled(&ap->link.device[1]))
-		return 1;
-	return 0;
-}
+	if (ata_dev_enabled(&ap->link.device[1]) && (gtm->flags & 0x4)) {
+		u32 acpi_dma;
 
-EXPORT_SYMBOL_GPL(ata_acpi_cbl_80wire);
+		/* if split timing, use drive[0]; otherwise, drive[1] */
+		if (gtm->flags & 0x10)
+			acpi_dma = gtm->drive[1].dma;
+		else
+			acpi_dma = gtm->drive[0].dma;
+
+		if (acpi_dma < 55)
+			return ATA_CBL_PATA80;
+		else
+			cbl = ATA_CBL_PATA40;
+	}
+
+	return cbl;
+
+}
+EXPORT_SYMBOL_GPL(ata_acpi_cbl);
 
 /**
  * taskfile_load_raw - send taskfile registers to host controller
Index: work/drivers/ata/pata_amd.c
===================================================================
--- work.orig/drivers/ata/pata_amd.c
+++ work/drivers/ata/pata_amd.c
@@ -271,7 +271,8 @@ static int nv_cable_detect(struct ata_po
  	if ((udma & 0xC4) == 0xC4 || (udma & 0xC400) == 0xC400)
 		cbl = ATA_CBL_PATA80;
 	/* And a triple check across suspend/resume with ACPI around */
-	if (ata_acpi_cbl_80wire(ap))
+	if ((ap->pflags & ATA_PFLAG_INIT_GTM_VALID) &&
+	    ata_acpi_cbl(ap, &ap->acpi_init_gtm) == ATA_CBL_PATA80)
 		cbl = ATA_CBL_PATA80;
 	return cbl;
 }
Index: work/drivers/ata/pata_via.c
===================================================================
--- work.orig/drivers/ata/pata_via.c
+++ work/drivers/ata/pata_via.c
@@ -185,7 +185,8 @@ static int via_cable_detect(struct ata_p
 	if (ata66 & (0x10100000 >> (16 * ap->port_no)))
 		return ATA_CBL_PATA80;
 	/* Check with ACPI so we can spot BIOS reported SATA bridges */
-	if (ata_acpi_cbl_80wire(ap))
+	if ((ap->pflags & ATA_PFLAG_INIT_GTM_VALID) &&
+	    ata_acpi_cbl(ap, &ap->acpi_init_gtm) == ATA_CBL_PATA80)
 		return ATA_CBL_PATA80;
 	return ATA_CBL_PATA40;
 }
Index: work/include/linux/libata.h
===================================================================
--- work.orig/include/linux/libata.h
+++ work/include/linux/libata.h
@@ -921,7 +921,7 @@ enum {
 
 /* libata-acpi.c */
 #ifdef CONFIG_ATA_ACPI
-extern int ata_acpi_cbl_80wire(struct ata_port *ap);
+int ata_acpi_cbl(struct ata_port *ap, const struct ata_acpi_gtm *gtm);
 int ata_acpi_stm(const struct ata_port *ap, struct ata_acpi_gtm *stm);
 int ata_acpi_gtm(const struct ata_port *ap, struct ata_acpi_gtm *stm);
 #else

  reply	other threads:[~2007-11-02 15:21 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-02 15:20 [PATCH 1/3] libata: implement dev->acpi_init_gtm Tejun Heo
2007-11-02 15:21 ` Tejun Heo [this message]
2007-11-02 15:22   ` [PATCH 3/3] pata_amd: fix and improve cable detection Tejun Heo
2007-11-02 15:44     ` Alan Cox
2007-11-02 22:22       ` Tejun Heo
2007-11-03  0:10         ` Alan Cox
2007-11-03  0:35           ` Tejun Heo
2007-11-03  0:42           ` Tejun Heo
2007-11-02 15:42   ` [PATCH 2/3] libata: extend ata_acpi_cbl_80wire() and fix cable detection in pata_via and pata_amd Alan Cox
2007-11-02 22:18     ` Tejun Heo
2007-11-02 23:45       ` Alan Cox
2007-11-03  0:46         ` Tejun Heo
2007-11-03  1:12           ` Alan Cox
2007-11-03  1:16             ` Tejun Heo
2007-11-03  1:23               ` Alan Cox
2007-11-03  7:03                 ` Tejun Heo
2007-11-03  0:57     ` Bartlomiej Zolnierkiewicz
2007-11-03  1:12       ` Bartlomiej Zolnierkiewicz
2007-11-02 15:36 ` [PATCH 1/3] libata: implement dev->acpi_init_gtm Jeff Garzik
2007-11-02 22:12   ` Tejun Heo
2007-11-03  7:10     ` Tejun Heo
2007-11-03 12:33       ` Jeff Garzik
2007-11-02 15:44 ` Alan Cox
2007-11-02 22:08   ` Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=472B4078.90009@gmail.com \
    --to=htejun@gmail.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=jeff@garzik.org \
    --cc=linux-ide@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).