[flashrom] [patch] VT6421A LPC programmer
Jonathan A. Kollasch
jakllsch at kollasch.net
Tue Jan 4 04:23:26 CET 2011
Add VIA VT6421A LPC programmer driver.
Signed-off-by: Jonathan Kollasch <jakllsch at kollasch.net>
-------------- next part --------------
Index: pcidev.c
===================================================================
--- pcidev.c (revision 1250)
+++ pcidev.c (working copy)
@@ -38,16 +38,22 @@
if (dev->device_id != devs[i].device_id)
continue;
+ msg_pinfo("Found \"%s %s\" (%04x:%04x, BDF %02x:%02x.%x).\n",
+ devs[i].vendor_name, devs[i].device_name,
+ dev->vendor_id, dev->device_id, dev->bus, dev->dev,
+ dev->func);
+
+ if (bar == -1) {
+ addr = -1;
+ goto no_bar;
+ }
+
/*
* Don't use dev->base_addr[x] (as value for 'bar'), won't
* work on older libpci.
*/
addr = pci_read_long(dev, bar);
- msg_pinfo("Found \"%s %s\" (%04x:%04x, BDF %02x:%02x.%x).\n",
- devs[i].vendor_name, devs[i].device_name,
- dev->vendor_id, dev->device_id, dev->bus, dev->dev,
- dev->func);
msg_pdbg("Requested BAR is %s", (addr & 0x1) ? "IO" : "MEM");
if (addr & 0x1) {
/* Mask off IO space indicator and reserved bit. */
@@ -64,6 +70,7 @@
addr &= ~0xf;
}
+no_bar:
if (devs[i].status == NT) {
msg_pinfo("===\nThis PCI device is UNTESTED. Please "
"report the 'flashrom -p xxxx' output \n"
Index: Makefile
===================================================================
--- Makefile (revision 1250)
+++ Makefile (working copy)
@@ -128,6 +128,9 @@
# IMPORTANT: This code is not yet working!
CONFIG_ATAHPT ?= no
+# VIA VT6421A LPC memory support
+CONFIG_ATAVIA ?= yes
+
# Always enable FT2232 SPI dongles for now.
CONFIG_FT2232_SPI ?= yes
@@ -228,6 +231,12 @@
NEED_PCI := yes
endif
+ifeq ($(CONFIG_ATAVIA), yes)
+FEATURE_CFLAGS += -D'CONFIG_ATAVIA=1'
+PROGRAMMER_OBJS += atavia.o
+NEED_PCI := yes
+endif
+
ifeq ($(CONFIG_FT2232_SPI), yes)
FTDILIBS := $(shell pkg-config --libs libftdi 2>/dev/null || printf "%s" "-lftdi -lusb")
# This is a totally ugly hack.
Index: atavia.c
===================================================================
--- atavia.c (revision 0)
+++ atavia.c (revision 0)
@@ -0,0 +1,97 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2010 Uwe Hermann <uwe at hermann-uwe.de>
+ * Copyright (C) 2011 Jonathan Kollasch <jakllsch at kollasch.net>
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include "flash.h"
+#include "programmer.h"
+#include <stdio.h>
+
+#define PCI_VENDOR_ID_VIA 0x1106
+
+#define BROM_ADDR 0x60
+#define BROM_DATA 0x64
+
+#define BROM_ACCESS 0x68
+#define BROM_TRIGGER 0x80
+#define BROM_WRITE 0x40
+#define BROM_SIZE_MASK 0x30
+#define BROM_SIZE_64K 0x00
+#define BROM_SIZE_32K 0x10
+#define BROM_SIZE_16K 0x20
+#define BROM_SIZE_0K 0x30
+#define BROM_BYTE_ENABLE_MASK 0x0f
+
+/*
+ * Select the byte we want to access. This is done by clearing the bit
+ * corresponding to the byte we want to access, leaving the others set.
+ * (Yes, really.)
+ */
+#define ENABLE(address) ((~(1 << ((address) & 3))) & BROM_BYTE_ENABLE_MASK)
+
+#define BROM_STATUS 0x69
+#define BROM_ERROR_STATUS 0x80
+
+const struct pcidev_status ata_via[] = {
+ {PCI_VENDOR_ID_VIA, 0x3249, NT, "VIA", "VT6421A"},
+
+ {},
+};
+
+int atavia_init(void)
+{
+ buses_supported = CHIP_BUSTYPE_LPC;
+
+ pcidev_init(PCI_VENDOR_ID_VIA, -1, ata_via);
+
+ return 0;
+}
+
+int atavia_shutdown(void)
+{
+ pci_cleanup(pacc);
+ return 0;
+}
+
+void *atavia_map(const char *descr, unsigned long phys_addr, size_t len)
+{
+ return (void *)phys_addr;
+}
+
+void atavia_chip_writeb(uint8_t val, chipaddr addr)
+{
+ pci_write_long(pcidev_dev, BROM_ADDR, (addr & ~3));
+ pci_write_long(pcidev_dev, BROM_DATA, val << (8 * (addr & 3)));
+ pci_write_byte(pcidev_dev, BROM_ACCESS, BROM_TRIGGER | BROM_WRITE | ENABLE(addr));
+ programmer_delay(1);
+ /* maybe check the status bit? */
+}
+
+uint8_t atavia_chip_readb(const chipaddr addr)
+{
+ uint8_t val;
+ pci_write_long(pcidev_dev, BROM_ADDR, (addr & ~3));
+ pci_write_byte(pcidev_dev, BROM_ACCESS, BROM_TRIGGER | ENABLE(addr));
+ programmer_delay(1);
+ val = (pci_read_long(pcidev_dev, BROM_DATA) >> ((addr & 3)*8)) & 0xff;
+ /* maybe check the status bit? */
+ return val;
+}
Index: flashrom.c
===================================================================
--- flashrom.c (revision 1250)
+++ flashrom.c (working copy)
@@ -52,7 +52,7 @@
* if more than one of them is selected. If only one is selected, it is clear
* that the user wants that one to become the default.
*/
-#if CONFIG_NIC3COM+CONFIG_NICREALTEK+CONFIG_NICNATSEMI+CONFIG_GFXNVIDIA+CONFIG_DRKAISER+CONFIG_SATASII+CONFIG_ATAHPT+CONFIG_FT2232_SPI+CONFIG_SERPROG+CONFIG_BUSPIRATE_SPI+CONFIG_DEDIPROG+CONFIG_RAYER_SPI+CONFIG_NICINTEL_SPI+CONFIG_OGP_SPI > 1
+#if CONFIG_NIC3COM+CONFIG_NICREALTEK+CONFIG_NICNATSEMI+CONFIG_GFXNVIDIA+CONFIG_DRKAISER+CONFIG_SATASII+CONFIG_ATAHPT+CONFIG_ATAVIA+CONFIG_FT2232_SPI+CONFIG_SERPROG+CONFIG_BUSPIRATE_SPI+CONFIG_DEDIPROG+CONFIG_RAYER_SPI+CONFIG_NICINTEL_SPI+CONFIG_OGP_SPI > 1
#error Please enable either CONFIG_DUMMY or CONFIG_INTERNAL or disable support for all programmers except one.
#endif
enum programmer programmer =
@@ -78,6 +78,9 @@
#if CONFIG_ATAHPT == 1
PROGRAMMER_ATAHPT
#endif
+#if CONFIG_ATAVIA == 1
+ PROGRAMMER_ATAVIA
+#endif
#if CONFIG_FT2232_SPI == 1
PROGRAMMER_FT2232_SPI
#endif
@@ -307,6 +310,25 @@
},
#endif
+#if CONFIG_ATAVIA == 1
+ {
+ .name = "atavia",
+ .init = atavia_init,
+ .shutdown = atavia_shutdown,
+ .map_flash_region = atavia_map,
+ .unmap_flash_region = fallback_unmap,
+ .chip_readb = atavia_chip_readb,
+ .chip_readw = fallback_chip_readw,
+ .chip_readl = fallback_chip_readl,
+ .chip_readn = fallback_chip_readn,
+ .chip_writeb = atavia_chip_writeb,
+ .chip_writew = fallback_chip_writew,
+ .chip_writel = fallback_chip_writel,
+ .chip_writen = fallback_chip_writen,
+ .delay = internal_delay,
+ },
+#endif
+
#if CONFIG_INTERNAL == 1
#if defined(__i386__) || defined(__x86_64__)
{
Index: programmer.h
===================================================================
--- programmer.h (revision 1250)
+++ programmer.h (working copy)
@@ -53,6 +53,9 @@
#if CONFIG_ATAHPT == 1
PROGRAMMER_ATAHPT,
#endif
+#if CONFIG_ATAVIA == 1
+ PROGRAMMER_ATAVIA,
+#endif
#if CONFIG_INTERNAL == 1
#if defined(__i386__) || defined(__x86_64__)
PROGRAMMER_IT87SPI,
@@ -433,6 +436,16 @@
extern const struct pcidev_status ata_hpt[];
#endif
+/* atavia.c */
+#if CONFIG_ATAVIA == 1
+int atavia_init(void);
+int atavia_shutdown(void);
+void *atavia_map(const char *descr, unsigned long phys_addr, size_t len);
+void atavia_chip_writeb(uint8_t val, chipaddr addr);
+uint8_t atavia_chip_readb(const chipaddr addr);
+extern const struct pcidev_status ata_via[];
+#endif
+
/* ft2232_spi.c */
#if CONFIG_FT2232_SPI == 1
struct usbdev_status {
Index: print.c
===================================================================
--- print.c (revision 1250)
+++ print.c (working copy)
@@ -278,6 +278,11 @@
programmer_table[PROGRAMMER_ATAHPT].name);
print_supported_pcidevs(ata_hpt);
#endif
+#if CONFIG_ATAVIA == 1
+ printf("\nSupported devices for the %s programmer:\n",
+ programmer_table[PROGRAMMER_ATAVIA].name);
+ print_supported_pcidevs(ata_via);
+#endif
#if CONFIG_FT2232_SPI == 1
printf("\nSupported devices for the %s programmer:\n",
programmer_table[PROGRAMMER_FT2232_SPI].name);
More information about the flashrom
mailing list