[coreboot] New patch to review for coreboot: 2781b84 util: Add utility to read EPHY config on VX900

Alexandru Gagniuc (mr.nuke.me@gmail.com) gerrit at coreboot.org
Fri Aug 10 10:57:47 CEST 2012


Alexandru Gagniuc (mr.nuke.me at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/1430

-gerrit

commit 2781b84aeb42563f898348ba7ed7278422ea2ccc
Author: Alexandru Gagniuc <mr.nuke.me at gmail.com>
Date:   Fri Aug 10 03:55:42 2012 -0500

    util: Add utility to read EPHY config on VX900
    
    Seems there is bo tool in our arsenal that does anything related.
    
    See util/viatools/vx900_ephy/README for all relevant details.
    
    Change-Id: Icbd39eaf7c7da5568732d77dbf2aed135f835754
    Signed-off-by: Alexandru Gagniuc <mr.nuke.me at gmail.com>
---
 util/viatools/vx900_ephy/Makefile     |   35 +++++++++++
 util/viatools/vx900_ephy/README       |    9 +++
 util/viatools/vx900_ephy/vx900_ephy.c |  106 +++++++++++++++++++++++++++++++++
 3 files changed, 150 insertions(+), 0 deletions(-)

diff --git a/util/viatools/vx900_ephy/Makefile b/util/viatools/vx900_ephy/Makefile
new file mode 100644
index 0000000..1bdb4d5
--- /dev/null
+++ b/util/viatools/vx900_ephy/Makefile
@@ -0,0 +1,35 @@
+ ##
+ ## This file is part of the vx900_ephy utlity.
+ ##
+ ##
+ ## Copyright (C) 2011-2012 Alexandru Gagniuc <mr.nuke.me at gmail.com>
+ ##
+ ## This program is free software: you can redistribute it and/or modify
+ ## it under the terms of the GNU General Public License as published by
+ ## the Free Software Foundation, either version 2 of the License, or
+ ## (at your option) any later version.
+ ##
+ ## This program is distributed in the hope that it will be useful,
+ ## but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ ## GNU General Public License for more details.
+ ##
+ ## You should have received a copy of the GNU General Public License
+ ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ ##
+
+CC=gcc
+
+SRCS = vx900_ephy.c
+OBJS = $(sort ${SRCS:.c=.o})
+
+all: vx900_ephy
+
+vx900_ephy: $(OBJS)
+	$(CC) $< -o $@ -lpci
+
+%.o: %.c
+	$(CC) -c $< -o $@
+
+clean:
+	rm -f $(OBJS)
\ No newline at end of file
diff --git a/util/viatools/vx900_ephy/README b/util/viatools/vx900_ephy/README
new file mode 100644
index 0000000..70d7d9f
--- /dev/null
+++ b/util/viatools/vx900_ephy/README
@@ -0,0 +1,9 @@
+
+On the VX900 chipset, the SATA physical layer is controllable by index/value
+pairs in the PCI config space. Getting the EPHY config (as VIA calls it) is thus
+not achievable by a simple lspci -xx.
+
+The EPHY config is needed to get the SATA links running properly. The default
+values disable the driving resistors. While the SATA link may appear to work
+initially, the chipset indicates a PHY error occurs. This tool reads the EPHY
+config from a VX900 chipset.
diff --git a/util/viatools/vx900_ephy/vx900_ephy.c b/util/viatools/vx900_ephy/vx900_ephy.c
new file mode 100644
index 0000000..913f2fd
--- /dev/null
+++ b/util/viatools/vx900_ephy/vx900_ephy.c
@@ -0,0 +1,106 @@
+/*
+ * This file is part of the vx900_ephy utlity.
+ *
+ * Copyright (C) 2012  Alexandru Gagniuc <mr.nuke.me at gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <pci/pci.h>
+#include <stddef.h>
+#include <stdio.h>
+
+#define VX900_SATA_DOM          0
+#define VX900_SATA_BUS          0
+#define VX900_SATA_DEV          0x0f
+#define VX900_SATA_FUNC         0
+
+#define VX900_SATA_DEV_ID       0x9001
+#define VX900_SATA_VEND_ID      0x1106
+
+typedef struct pci_dev *device_t;
+
+typedef u8 sata_phy_config[64];
+
+static u32 sata_phy_read32(device_t dev, u8 index)
+{
+	/* The SATA PHY control registers are accessed by a funny index/value
+	 * scheme. Each byte (0,1,2,3) has its own 4-bit index */
+	index = (index >> 2) & 0xf;
+	u16 i16 = index | (index<<4) | (index<<8)| (index<<12);
+	/* The index */
+	pci_write_word(dev, 0x68, i16);
+	/* The value */
+	return pci_read_long(dev, 0x64);
+
+}
+
+static void vx900_sata_read_phy_config(device_t dev, sata_phy_config cfg)
+{
+	size_t i;
+	u32* data = (u32*)cfg;
+	for(i = 0; i < (sizeof(sata_phy_config) ) >> 2; i++) {
+		data[i] = sata_phy_read32(dev, i<<2);
+	}
+}
+
+int main()
+{
+	sata_phy_config ephy;
+	struct pci_access *pci_lord;
+	device_t dev;
+
+	printf(" vx900_ephy tool:\n");
+	printf(" Copyright (C) 2012  Alexandru Gagniuc\n");
+	printf("======================================\n");
+
+	/* libpci mambo jumbo we need to do, but don't care about */
+	pci_lord = pci_alloc();
+	pci_init(pci_lord);
+	pci_scan_bus(pci_lord);
+
+	/* We write to the PCI config, so stop here if it's the wrong device */
+	dev = pci_get_dev(pci_lord, VX900_SATA_DOM, VX900_SATA_BUS,
+				    VX900_SATA_DEV, VX900_SATA_FUNC);
+
+	pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_CLASS);
+
+	if( (VX900_SATA_VEND_ID != dev->vendor_id) ||
+		(VX900_SATA_DEV_ID != dev->device_id) )
+	{
+		printf("VX900 SATA controller not found\n");
+		return -1;
+
+	}
+	/* Get all the info in one pass */
+	vx900_sata_read_phy_config(dev, ephy);
+
+	/* Put it on the terminal for the user to read and be done with it */
+	printf("SATA PHY config:\n");
+	int i;
+	for (i = 0; i < sizeof(sata_phy_config); i++) {
+		if ((i & 0x0f) == 0) {
+			printf("%.2x :", i);
+		}
+		if( (i & 0x0f) == 0x08 )
+			printf("| ");
+		printf("%.2x ", ephy[i]);
+		if ((i & 0x0f) == 0x0f) {
+			printf("\n");
+		}
+	}
+
+	printf("Compare that with the coreboot debug output, and see if the"
+	       " EPHY values need adjustment for your mainboard.\n");
+}
\ No newline at end of file




More information about the coreboot mailing list