Patchwork New CMOS option sata_mode

login
register
about
Submitter Josef Kellermann
Date 2011-02-18 19:12:10
Message ID <4D5EC48A.9030907@arcor.de>
Download mbox | patch
Permalink /patch/2680/
State Accepted
Headers show

Comments

Josef Kellermann - 2011-02-18 19:12:10
Attached patch implements a new CMOS option 'sata_mode'.
A new Kconfig option 'SATA_MODE' with default 'ide' is added to 
amd/sb600/Kconfig.
The handling of the CMOS option is placed in amd/sb600/sata.c and 
overrides the hardcoded 'ide' mode
in the following way:
if get_option(., "sata_mode") returns 0 use CMOS option
in case of -2 grab the Kconfig option CONFIG_SATA_MODE if exist
otherwise use the hardcoded mode.

Signed-off-by: Josef Kellermann <seppk@arcor.de> <mailto://seppk@arcor.de>
From c349a79ea1ac9bcd52376b80f32cfa0552259219 Mon Sep 17 00:00:00 2001
From: Josef Kellermann <seppk@arcor.de>
Date: Fri, 18 Feb 2011 11:44:31 +0100
Subject: [PATCH 1/2] added new cmos option 'sata_mode' and Kconfig option 'SATA_MODE'
 This options override the default chipset mode 'IDE'
 in the following way: if cmos option exist use cmos option, if Kconfig option
 exist use Kconfig option else use default 'IDE'.

---
 src/southbridge/amd/sb600/Kconfig |    5 ++++-
 src/southbridge/amd/sb600/sata.c  |   30 ++++++++++++++++++++++--------
 2 files changed, 26 insertions(+), 9 deletions(-)
Patrick Georgi - 2011-02-24 13:56:22
Hi Josef.

Thank you for the contribution.

Am Freitag, den 18.02.2011, 20:12 +0100 schrieb Josef Kellermann:
> Attached patch implements a new CMOS option 'sata_mode'.
> A new Kconfig option 'SATA_MODE' with default 'ide' is added to
> amd/sb600/Kconfig. 
I changed the Kconfig handling a bit to not use a magic string, and to
handle the default value in Kconfig instead of doing it in code.

> Signed-off-by: Josef Kellermann <seppk@arcor.de>
Acked-by: Patrick Georgi <patrick.georgi@secunet.com>
r6379


Patrick

Patch

diff --git a/src/southbridge/amd/sb600/Kconfig b/src/southbridge/amd/sb600/Kconfig
index 4e86999..7831aa3 100644
--- a/src/southbridge/amd/sb600/Kconfig
+++ b/src/southbridge/amd/sb600/Kconfig
@@ -35,4 +35,7 @@  config EHCI_BAR
 config EHCI_DEBUG_OFFSET
 	hex
 	default 0xe0 if SOUTHBRIDGE_AMD_SB600
-
+	
+config SATA_MODE
+	string 
+	default "ide"
diff --git a/src/southbridge/amd/sb600/sata.c b/src/southbridge/amd/sb600/sata.c
index 055e7da..143135e 100644
--- a/src/southbridge/amd/sb600/sata.c
+++ b/src/southbridge/amd/sb600/sata.c
@@ -17,7 +17,6 @@ 
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
-
 #include <console/console.h>
 #include <device/device.h>
 #include <delay.h>
@@ -26,6 +25,10 @@ 
 #include <device/pci_ops.h>
 #include <arch/io.h>
 #include "sb600.h"
+#include <pc80/mc146818rtc.h>
+
+#define SATA_MODE_IDE 1
+#define SATA_MODE_AHCI !(SATA_MODE_IDE)
 
 static int sata_drive_detect(int portnum, u16 iobar)
 {
@@ -98,10 +101,6 @@  static void sata_init(struct device *dev)
 	printk(BIOS_SPEW, "sata_bar4=%x\n", sata_bar4);	/* 3000 */
 	printk(BIOS_SPEW, "sata_bar5=%x\n", sata_bar5);	/* e0309000 */
 
-	/* Program the 2C to 0x43801002 */
-	dword = 0x43801002;
-	pci_write_config32(dev, 0x2c, dword);
-
 	/* SERR-Enable */
 	word = pci_read_config16(dev, 0x04);
 	word |= (1 << 8);
@@ -112,13 +111,28 @@  static void sata_init(struct device *dev)
 	byte |= (1 << 2);
 	pci_write_config8(dev, 0x40, byte);
 
-	/* Set SATA Operation Mode, Set to IDE mode */
+	/* Set SATA Operation Mode */
 	byte = pci_read_config8(dev, 0x40);
 	byte |= (1 << 0);
 	byte |= (1 << 4);
 	pci_write_config8(dev, 0x40, byte);
 
-	dword = 0x01018f00;
+	// 1 means IDE, 0 means AHCI
+	if( get_option(&i, "sata_mode") < 0 ) {
+		// no cmos option
+		i = SATA_MODE_IDE; // default
+#if defined(CONFIG_SATA_MODE)
+		i = ((CONFIG_SATA_MODE[0] & ~0x20) == 'A') ? SATA_MODE_AHCI : SATA_MODE_IDE;
+#endif
+	}
+	printk(BIOS_INFO, "%s: setting sata mode = %s\n",__func__, (i == SATA_MODE_IDE) ? "ide" : "ahci" );	
+	
+	dword = pci_read_config32(dev, 0x8);
+	dword &= 0xff0000ff;
+	if( i == SATA_MODE_IDE )
+		dword |= 0x00018f00; // IDE mode
+	else
+		dword |= 0x00060100; // AHCI mode
 	pci_write_config32(dev, 0x8, dword);
 
 	byte = pci_read_config8(dev, 0x40);
@@ -245,7 +259,7 @@  static void sata_init(struct device *dev)
 }
 
 static struct pci_operations lops_pci = {
-	/* .set_subsystem = pci_dev_set_subsystem, */
+	.set_subsystem = pci_dev_set_subsystem,
 };
 
 static struct device_operations sata_ops = {