Here is a proposed way how to handle the SATA PHY settings on SB700. It
[coreboot.git] / src / southbridge / amd / sb700 / sb700_sata.c
index cd5084e7450111cc221dd8e9b246141d40038947..5c72a98a76938ef7a15c1a351e757680e9077b54 100644 (file)
@@ -26,7 +26,7 @@
 #include <arch/io.h>
 #include "sb700.h"
 
-int sata_drive_detect(int portnum, u16 iobar)
+static int sata_drive_detect(int portnum, u16 iobar)
 {
        u8 byte, byte2;
        int i = 0;
@@ -34,32 +34,55 @@ int sata_drive_detect(int portnum, u16 iobar)
        while (byte = inb(iobar + 0x6), byte2 = inb(iobar + 0x7),
                (byte != (0xA0 + 0x10 * (portnum % 2))) ||
                ((byte2 & 0x88) != 0)) {
-               printk_spew("0x6=%x, 0x7=%x\n", byte, byte2);
+               printk(BIOS_SPEW, "0x6=%x, 0x7=%x\n", byte, byte2);
                if (byte != (0xA0 + 0x10 * (portnum % 2))) {
                        /* This will happen at the first iteration of this loop
                         * if the first SATA port is unpopulated and the
                         * second SATA port is poulated.
                         */
-                       printk_debug("drive no longer selected after %i ms, "
+                       printk(BIOS_DEBUG, "drive no longer selected after %i ms, "
                                "retrying init\n", i * 10);
                        return 1;
                } else
-                       printk_spew("drive detection not yet completed, "
+                       printk(BIOS_SPEW, "drive detection not yet completed, "
                                "waiting...\n");
                mdelay(10);
                i++;
        }
-       printk_spew("drive detection done after %i ms\n", i * 10);
+       printk(BIOS_SPEW, "drive detection done after %i ms\n", i * 10);
        return 0;
 }
 
+       /* This function can be overloaded in mainboard.c */
+
+void __attribute__((weak)) sb700_setup_sata_phys(struct device *dev) {
+       /* RPR7.6.1 Program the PHY Global Control to 0x2C00 */
+       pci_write_config16(dev, 0x86, 0x2c00);
+
+       /* RPR7.6.2 SATA GENI PHY ports setting */
+       pci_write_config32(dev, 0x88, 0x01B48017);
+       pci_write_config32(dev, 0x8c, 0x01B48019);
+       pci_write_config32(dev, 0x90, 0x01B48016);
+       pci_write_config32(dev, 0x94, 0x01B48016);
+       pci_write_config32(dev, 0x98, 0x01B48016);
+       pci_write_config32(dev, 0x9C, 0x01B48016);
+
+       /* RPR7.6.3 SATA GEN II PHY port setting for port [0~5]. */
+       pci_write_config16(dev, 0xA0, 0xA09A);
+       pci_write_config16(dev, 0xA2, 0xA09F);
+       pci_write_config16(dev, 0xA4, 0xA07A);
+       pci_write_config16(dev, 0xA6, 0xA07A);
+       pci_write_config16(dev, 0xA8, 0xA07A);
+       pci_write_config16(dev, 0xAA, 0xA07A);
+}
+
 static void sata_init(struct device *dev)
 {
        u8 byte;
        u16 word;
        u32 dword;
        u8 rev_id;
-       u8 *sata_bar5;
+       u32 sata_bar5;
        u16 sata_bar0, sata_bar1, sata_bar2, sata_bar3, sata_bar4;
        int i, j;
 
@@ -89,19 +112,19 @@ static void sata_init(struct device *dev)
        rev_id = pci_read_config8(sm_dev, 0x08) - 0x28;
 
        /* get base addresss */
-       sata_bar5 = (u8 *) (pci_read_config32(dev, 0x24) & ~0x3FF);
+       sata_bar5 = pci_read_config32(dev, 0x24) & ~0x3FF;
        sata_bar0 = pci_read_config16(dev, 0x10) & ~0x7;
        sata_bar1 = pci_read_config16(dev, 0x14) & ~0x3;
        sata_bar2 = pci_read_config16(dev, 0x18) & ~0x7;
        sata_bar3 = pci_read_config16(dev, 0x1C) & ~0x3;
        sata_bar4 = pci_read_config16(dev, 0x20) & ~0xf;
 
-       printk_spew("sata_bar0=%x\n", sata_bar0);       /* 3030 */
-       printk_spew("sata_bar1=%x\n", sata_bar1);       /* 3070 */
-       printk_spew("sata_bar2=%x\n", sata_bar2);       /* 3040 */
-       printk_spew("sata_bar3=%x\n", sata_bar3);       /* 3080 */
-       printk_spew("sata_bar4=%x\n", sata_bar4);       /* 3000 */
-       printk_spew("sata_bar5=%p\n", sata_bar5);       /* e0309000 */
+       printk(BIOS_SPEW, "sata_bar0=%x\n", sata_bar0); /* 3030 */
+       printk(BIOS_SPEW, "sata_bar1=%x\n", sata_bar1); /* 3070 */
+       printk(BIOS_SPEW, "sata_bar2=%x\n", sata_bar2); /* 3040 */
+       printk(BIOS_SPEW, "sata_bar3=%x\n", sata_bar3); /* 3080 */
+       printk(BIOS_SPEW, "sata_bar4=%x\n", sata_bar4); /* 3000 */
+       printk(BIOS_SPEW, "sata_bar5=%x\n", sata_bar5); /* e0309000 */
 
        /* disable combined mode */
        byte = pci_read_config8(sm_dev, 0xAD);
@@ -161,27 +184,7 @@ static void sata_init(struct device *dev)
        /* Program the watchdog counter to 0x10 */
        byte = 0x10;
        pci_write_config8(dev, 0x46, byte);
-
-       /* RPR7.6.1 Program the PHY Global Control to 0x2C00 */
-       word = 0x2c00;
-       pci_write_config16(dev, 0x86, word);
-
-       /* RPR7.6.2 SATA GENI PHY ports setting */
-       pci_write_config32(dev, 0x88, 0x01B48017);
-       pci_write_config32(dev, 0x8c, 0x01B48019);
-       pci_write_config32(dev, 0x90, 0x01B48016);
-       pci_write_config32(dev, 0x94, 0x01B48016);
-       pci_write_config32(dev, 0x98, 0x01B48016);
-       pci_write_config32(dev, 0x9C, 0x01B48016);
-
-       /* RPR7.6.3 SATA GEN II PHY port setting for port [0~5]. */
-       pci_write_config16(dev, 0xA0, 0xA09A);
-       pci_write_config16(dev, 0xA2, 0xA09F);
-       pci_write_config16(dev, 0xA4, 0xA07A);
-       pci_write_config16(dev, 0xA6, 0xA07A);
-       pci_write_config16(dev, 0xA8, 0xA07A);
-       pci_write_config16(dev, 0xAA, 0xA07A);
-
+       sb700_setup_sata_phys(dev);
        /* Enable the I/O, MM, BusMaster access for SATA */
        byte = pci_read_config8(dev, 0x4);
        byte |= 7 << 0;
@@ -199,12 +202,12 @@ static void sata_init(struct device *dev)
 
        for (i = 0; i < 4; i++) {
                byte = read8(sata_bar5 + 0x128 + 0x80 * i);
-               printk_spew("SATA port %i status = %x\n", i, byte);
+               printk(BIOS_SPEW, "SATA port %i status = %x\n", i, byte);
                byte &= 0xF;
                if( byte == 0x1 ) {
                        /* If the drive status is 0x1 then we see it but we aren't talking to it. */
                        /* Try to do something about it. */
-                       printk_spew("SATA device detected but not talking. Trying lower speed.\n");
+                       printk(BIOS_SPEW, "SATA device detected but not talking. Trying lower speed.\n");
 
                        /* Read in Port-N Serial ATA Control Register */
                        byte = read8(sata_bar5 + 0x12C + 0x80 * i);
@@ -225,7 +228,7 @@ static void sata_init(struct device *dev)
 
                        /* Reread status */
                        byte = read8(sata_bar5 + 0x128 + 0x80 * i);
-                       printk_spew("SATA port %i status = %x\n", i, byte);
+                       printk(BIOS_SPEW, "SATA port %i status = %x\n", i, byte);
                        byte &= 0xF;
                }
 
@@ -234,13 +237,13 @@ static void sata_init(struct device *dev)
                                if (!sata_drive_detect(i, ((i / 2) == 0) ? sata_bar0 : sata_bar2))
                                        break;
                        }
-                       printk_debug("%s %s device is %sready after %i tries\n",
+                       printk(BIOS_DEBUG, "%s %s device is %sready after %i tries\n",
                                        (i / 2) ? "Secondary" : "Primary",
                                        (i % 2 ) ? "Slave" : "Master",
                                        (j == 10) ? "not " : "",
                                        (j == 10) ? j : j + 1);
                } else {
-                       printk_debug("No %s %s SATA drive on Slot%i\n",
+                       printk(BIOS_DEBUG, "No %s %s SATA drive on Slot%i\n",
                                        (i / 2) ? "Secondary" : "Primary",
                                        (i % 2 ) ? "Slave" : "Master", i);
                }
@@ -267,7 +270,7 @@ static void sata_init(struct device *dev)
        /* word = pm_ioread(0x28); */
        /* byte = pm_ioread(0x29); */
        /* word |= byte<<8; */
-       /* printk_debug("AcpiGpe0Blk addr = %x\n", word); */
+       /* printk(BIOS_DEBUG, "AcpiGpe0Blk addr = %x\n", word); */
        /* write32(word, 0x80000000); */
 }