Commit 2cb94e18 authored by Stefan Reinauer's avatar Stefan Reinauer Committed by Stefan Reinauer
Browse files

First attempt to clean up SPI probing and create a common construct: the flash bus


At some point the flash bus will be part of struct flashchip.

Pardon me for pushing this in, but I think it is important to beware of further
decay and it will improve things for other developers in the short run.

Carl-Daniel, I will consider your suggestions in another patch. I want to keep
things from getting too much for now. The patch includes Rudolf's VIA SPI
changes though.

Corresponding to flashrom svn r285 and coreboot v2 svn r3401.
Signed-off-by: default avatarStefan Reinauer <stepan@coresystems.de>
Acked-by: default avatarCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
parent e3eb9c1d
...@@ -35,6 +35,17 @@ ...@@ -35,6 +35,17 @@
#include <unistd.h> #include <unistd.h>
#include "flash.h" #include "flash.h"
/**
* flashrom defaults to LPC flash devices. If a known SPI controller is found
* and the SPI strappings are set, this will be overwritten by the probing code.
*
* Eventually, this will become an array when multiple flash support works.
*/
flashbus_t flashbus = BUS_TYPE_LPC;
void *spibar = NULL;
static int enable_flash_ali_m1533(struct pci_dev *dev, const char *name) static int enable_flash_ali_m1533(struct pci_dev *dev, const char *name)
{ {
uint8_t tmp; uint8_t tmp;
...@@ -124,7 +135,7 @@ static int enable_flash_piix4(struct pci_dev *dev, const char *name) ...@@ -124,7 +135,7 @@ static int enable_flash_piix4(struct pci_dev *dev, const char *name)
* Note: Accesses to FFFF0000-FFFFFFFF are always forwarded to ISA. * Note: Accesses to FFFF0000-FFFFFFFF are always forwarded to ISA.
* Set bit 2: BIOSCS# Write Enable (1=enable, 0=disable). * Set bit 2: BIOSCS# Write Enable (1=enable, 0=disable).
*/ */
new = old | 0x2c4; new = old | 0x02c4;
if (new == old) if (new == old)
return 0; return 0;
...@@ -185,88 +196,131 @@ static int enable_flash_ich_dc(struct pci_dev *dev, const char *name) ...@@ -185,88 +196,131 @@ static int enable_flash_ich_dc(struct pci_dev *dev, const char *name)
return enable_flash_ich(dev, name, 0xdc); return enable_flash_ich(dev, name, 0xdc);
} }
void *ich_spibar = NULL; #define ICH_STRAP_RSVD 0x00
#define ICH_STRAP_SPI 0x01
#define ICH_STRAP_PCI 0x02
#define ICH_STRAP_LPC 0x03
static int enable_flash_vt8237s_spi(struct pci_dev *dev, const char *name) { static int enable_flash_vt8237s_spi(struct pci_dev *dev, const char *name) {
uint32_t mmio_base; uint32_t mmio_base;
mmio_base = (pci_read_long(dev, 0xbc)) << 8; mmio_base = (pci_read_long(dev, 0xbc)) << 8;
printf_debug("MMIO base at = 0x%x\n", mmio_base); printf_debug("MMIO base at = 0x%x\n", mmio_base);
ich_spibar = mmap(NULL, 0x70, PROT_READ | PROT_WRITE, MAP_SHARED, spibar = mmap(NULL, 0x70, PROT_READ | PROT_WRITE, MAP_SHARED,
fd_mem, mmio_base); fd_mem, mmio_base);
if (ich_spibar == MAP_FAILED) { if (spibar == MAP_FAILED) {
perror("Can't mmap memory using " MEM_DEV); perror("Can't mmap memory using " MEM_DEV);
exit(1); exit(1);
} }
printf_debug("0x6c: 0x%04x (CLOCK/DEBUG)\n", *(uint16_t *)(ich_spibar + 0x6c)); printf_debug("0x6c: 0x%04x (CLOCK/DEBUG)\n", *(uint16_t *)(spibar + 0x6c));
viaspi_detected = 1;
flashbus = BUS_TYPE_VIA_SPI;
return 0; return 0;
} }
static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name, unsigned long spibar) static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name, int ich_generation)
{ {
int ret, i;
uint8_t old, new, bbs, buc; uint8_t old, new, bbs, buc;
uint16_t spibar_offset;
uint32_t tmp, gcs; uint32_t tmp, gcs;
void *rcrb; void *rcrb;
static const char *straps_names[] = { "reserved", "SPI", "PCI", "LPC" };
/* Enable Flash Writes */
ret = enable_flash_ich_dc(dev, name);
/* Read the Root Complex Base Address Register (RCBA) */ /* Get physical address of Root Complex Register Block */
tmp = pci_read_long(dev, 0xf0); tmp = pci_read_long(dev, 0xf0) & 0xffffc000;
/* Calculate the Root Complex Register Block address */
tmp &= 0xffffc000;
printf_debug("\nRoot Complex Register Block address = 0x%x\n", tmp); printf_debug("\nRoot Complex Register Block address = 0x%x\n", tmp);
/* Map RCBA to virtual memory */
rcrb = mmap(0, 0x4000, PROT_READ | PROT_WRITE, MAP_SHARED, fd_mem, (off_t)tmp); rcrb = mmap(0, 0x4000, PROT_READ | PROT_WRITE, MAP_SHARED, fd_mem, (off_t)tmp);
if (rcrb == MAP_FAILED) { if (rcrb == MAP_FAILED) {
perror("Can't mmap memory using " MEM_DEV); perror("Can't mmap memory using " MEM_DEV);
exit(1); exit(1);
} }
printf_debug("GCS address = 0x%x\n", tmp + 0x3410);
gcs = *(volatile uint32_t *)(rcrb + 0x3410); gcs = *(volatile uint32_t *)(rcrb + 0x3410);
printf_debug("GCS = 0x%x: ", gcs); printf_debug("GCS = 0x%x: ", gcs);
printf_debug("BIOS Interface Lock-Down: %sabled, ", printf_debug("BIOS Interface Lock-Down: %sabled, ",
(gcs & 0x1) ? "en" : "dis"); (gcs & 0x1) ? "en" : "dis");
bbs = (gcs >> 10) & 0x3; bbs = (gcs >> 10) & 0x3;
printf_debug("BOOT BIOS Straps: 0x%x (%s)\n", bbs, printf_debug("BOOT BIOS Straps: 0x%x (%s)\n", bbs, straps_names[bbs]);
(bbs == 0x3) ? "LPC" : ((bbs == 0x2) ? "PCI" : "SPI"));
if (bbs >= 2)
ich7_detected = 0;
buc = *(volatile uint8_t *)(rcrb + 0x3414); buc = *(volatile uint8_t *)(rcrb + 0x3414);
printf_debug("Top Swap : %s\n", (buc & 1)?"enabled (A16 inverted)":"not enabled"); printf_debug("Top Swap : %s\n", (buc & 1)?"enabled (A16 inverted)":"not enabled");
/* It seems the ICH7 does not support SPI and LPC chips at the same
* time. At least not with our current code. So we prevent searching
* on ICH7 when the southbridge is strapped to LPC
*/
if (ich_generation == 7 && bbs == ICH_STRAP_LPC) {
/* No further SPI initialization required */
return ret;
}
switch (ich_generation) {
case 7:
flashbus = BUS_TYPE_ICH7_SPI;
spibar_offset = 0x3020;
break;
case 8:
flashbus = BUS_TYPE_ICH9_SPI;
spibar_offset = 0x3020;
break;
case 9:
default: /* Future version might behave the same */
flashbus = BUS_TYPE_ICH9_SPI;
spibar_offset = 0x3800;
break;
}
/* SPIBAR is at RCRB+0x3020 for ICH[78] and RCRB+0x3800 for ICH9. */ /* SPIBAR is at RCRB+0x3020 for ICH[78] and RCRB+0x3800 for ICH9. */
printf_debug("SPIBAR = 0x%x + 0x%04x\n", tmp, (uint16_t)spibar); printf_debug("SPIBAR = 0x%x + 0x%04x\n", tmp, spibar_offset);
// Assign Virtual Address /* Assign Virtual Address */
ich_spibar = rcrb + spibar; spibar = rcrb + spibar_offset;
if (ich7_detected) { switch (flashbus) {
int i; case BUS_TYPE_ICH7_SPI:
printf_debug("0x00: 0x%04x (SPIS)\n", *(uint16_t *)(ich_spibar + 0)); printf_debug("0x00: 0x%04x (SPIS)\n", *(uint16_t *)(spibar + 0));
printf_debug("0x02: 0x%04x (SPIC)\n", *(uint16_t *)(ich_spibar + 2)); printf_debug("0x02: 0x%04x (SPIC)\n", *(uint16_t *)(spibar + 2));
printf_debug("0x04: 0x%08x (SPIA)\n", *(uint32_t *)(ich_spibar + 4)); printf_debug("0x04: 0x%08x (SPIA)\n", *(uint32_t *)(spibar + 4));
for (i=0; i < 8; i++) { for (i=0; i < 8; i++) {
int offs; int offs;
offs = 8 + (i * 8); offs = 8 + (i * 8);
printf_debug("0x%02x: 0x%08x (SPID%d)\n", offs, *(uint32_t *)(ich_spibar + offs), i); printf_debug("0x%02x: 0x%08x (SPID%d)\n", offs, *(uint32_t *)(spibar + offs), i);
printf_debug("0x%02x: 0x%08x (SPID%d+4)\n", offs+4, *(uint32_t *)(ich_spibar + offs +4), i); printf_debug("0x%02x: 0x%08x (SPID%d+4)\n", offs+4, *(uint32_t *)(spibar + offs +4), i);
} }
printf_debug("0x50: 0x%08x (BBAR)\n", *(uint32_t *)(ich_spibar + 0x50)); printf_debug("0x50: 0x%08x (BBAR)\n", *(uint32_t *)(spibar + 0x50));
printf_debug("0x54: 0x%04x (PREOP)\n", *(uint16_t *)(ich_spibar + 0x54)); printf_debug("0x54: 0x%04x (PREOP)\n", *(uint16_t *)(spibar + 0x54));
printf_debug("0x56: 0x%04x (OPTYPE)\n", *(uint16_t *)(ich_spibar + 0x56)); printf_debug("0x56: 0x%04x (OPTYPE)\n", *(uint16_t *)(spibar + 0x56));
printf_debug("0x58: 0x%08x (OPMENU)\n", *(uint32_t *)(ich_spibar + 0x58)); printf_debug("0x58: 0x%08x (OPMENU)\n", *(uint32_t *)(spibar + 0x58));
printf_debug("0x5c: 0x%08x (OPMENU+4)\n", *(uint32_t *)(ich_spibar + 0x5c)); printf_debug("0x5c: 0x%08x (OPMENU+4)\n", *(uint32_t *)(spibar + 0x5c));
for (i=0; i < 4; i++) { for (i=0; i < 4; i++) {
int offs; int offs;
offs = 0x60 + (i * 4); offs = 0x60 + (i * 4);
printf_debug("0x%02x: 0x%08x (PBR%d)\n", offs, *(uint32_t *)(ich_spibar + offs), i); printf_debug("0x%02x: 0x%08x (PBR%d)\n", offs, *(uint32_t *)(spibar + offs), i);
} }
printf_debug("\n"); printf_debug("\n");
if ( (*(uint16_t *)ich_spibar) & (1 << 15)) { if ( (*(uint16_t *)spibar) & (1 << 15)) {
printf("WARNING: SPI Configuration Lockdown activated.\n"); printf("WARNING: SPI Configuration Lockdown activated.\n");
} }
break;
case BUS_TYPE_ICH9_SPI:
/* TODO: Add dumping function for ICH8/ICH9, or drop the
* whole SPIBAR dumping from chipset_enable.c - There's
* inteltool for this task already.
*/
break;
default:
/* Nothing */
break;
} }
old = pci_read_byte(dev, 0xdc); old = pci_read_byte(dev, 0xdc);
...@@ -277,38 +331,30 @@ static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name, unsign ...@@ -277,38 +331,30 @@ static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name, unsign
case 1: case 1:
case 2: case 2:
printf_debug("prefetching %sabled, caching %sabled, ", printf_debug("prefetching %sabled, caching %sabled, ",
(new & 0x2) ? "en" : "dis", (new & 0x1) ? "dis" : "en"); (new & 0x2) ? "en" : "dis",
(new & 0x1) ? "dis" : "en");
break; break;
default: default:
printf_debug("invalid prefetching/caching settings, "); printf_debug("invalid prefetching/caching settings, ");
break; break;
} }
return enable_flash_ich_dc(dev, name);
}
/* Flag for ICH7 SPI register block */ return ret;
int ich7_detected = 0; }
int viaspi_detected = 0;
static int enable_flash_ich7(struct pci_dev *dev, const char *name) static int enable_flash_ich7(struct pci_dev *dev, const char *name)
{ {
ich7_detected = 1; return enable_flash_ich_dc_spi(dev, name, 7);
return enable_flash_ich_dc_spi(dev, name, 0x3020);
} }
/* Flag for ICH8/ICH9 SPI register block */
int ich9_detected = 0;
static int enable_flash_ich8(struct pci_dev *dev, const char *name) static int enable_flash_ich8(struct pci_dev *dev, const char *name)
{ {
ich9_detected = 1; return enable_flash_ich_dc_spi(dev, name, 8);
return enable_flash_ich_dc_spi(dev, name, 0x3020);
} }
static int enable_flash_ich9(struct pci_dev *dev, const char *name) static int enable_flash_ich9(struct pci_dev *dev, const char *name)
{ {
ich9_detected = 1; return enable_flash_ich_dc_spi(dev, name, 9);
return enable_flash_ich_dc_spi(dev, name, 0x3800);
} }
static int enable_flash_vt823x(struct pci_dev *dev, const char *name) static int enable_flash_vt823x(struct pci_dev *dev, const char *name)
......
...@@ -370,10 +370,17 @@ void print_supported_boards(void); ...@@ -370,10 +370,17 @@ void print_supported_boards(void);
/* chipset_enable.c */ /* chipset_enable.c */
int chipset_flash_enable(void); int chipset_flash_enable(void);
void print_supported_chipsets(void); void print_supported_chipsets(void);
extern int ich7_detected;
extern int viaspi_detected; typedef enum {
extern int ich9_detected; BUS_TYPE_LPC,
extern void *ich_spibar; BUS_TYPE_ICH7_SPI,
BUS_TYPE_ICH9_SPI,
BUS_TYPE_IT87XX_SPI,
BUS_TYPE_VIA_SPI
} flashbus_t;
extern flashbus_t flashbus;
extern void *spibar;
/* Physical memory mapping device */ /* Physical memory mapping device */
#if defined (__sun) && (defined(__i386) || defined(__amd64)) #if defined (__sun) && (defined(__i386) || defined(__amd64))
......
...@@ -131,20 +131,20 @@ static OPCODES *curopcodes = NULL; ...@@ -131,20 +131,20 @@ static OPCODES *curopcodes = NULL;
static inline uint32_t REGREAD32(int X) static inline uint32_t REGREAD32(int X)
{ {
volatile uint32_t regval; volatile uint32_t regval;
regval = *(volatile uint32_t *) ((uint8_t *) ich_spibar + X); regval = *(volatile uint32_t *) ((uint8_t *) spibar + X);
return regval; return regval;
} }
static inline uint16_t REGREAD16(int X) static inline uint16_t REGREAD16(int X)
{ {
volatile uint16_t regval; volatile uint16_t regval;
regval = *(volatile uint16_t *) ((uint8_t *) ich_spibar + X); regval = *(volatile uint16_t *) ((uint8_t *) spibar + X);
return regval; return regval;
} }
#define REGWRITE32(X,Y) (*(uint32_t *)((uint8_t *)ich_spibar+X)=Y) #define REGWRITE32(X,Y) (*(uint32_t *)((uint8_t *)spibar+X)=Y)
#define REGWRITE16(X,Y) (*(uint16_t *)((uint8_t *)ich_spibar+X)=Y) #define REGWRITE16(X,Y) (*(uint16_t *)((uint8_t *)spibar+X)=Y)
#define REGWRITE8(X,Y) (*(uint8_t *)((uint8_t *)ich_spibar+X)=Y) #define REGWRITE8(X,Y) (*(uint8_t *)((uint8_t *)spibar+X)=Y)
/* Common SPI functions */ /* Common SPI functions */
static int program_opcodes(OPCODES * op); static int program_opcodes(OPCODES * op);
...@@ -175,58 +175,51 @@ OPCODES O_ST_M25P = { ...@@ -175,58 +175,51 @@ OPCODES O_ST_M25P = {
int program_opcodes(OPCODES * op) int program_opcodes(OPCODES * op)
{ {
uint8_t a; uint8_t a;
uint16_t temp16; uint16_t preop, optype;
uint32_t temp32; uint32_t opmenu[2];
/* Program Prefix Opcodes */ /* Program Prefix Opcodes */
temp16 = 0; preop = 0;
/* 0:7 Prefix Opcode 1 */ /* 0:7 Prefix Opcode 1 */
temp16 = (op->preop[0]); preop = (op->preop[0]);
/* 8:16 Prefix Opcode 2 */ /* 8:16 Prefix Opcode 2 */
temp16 |= ((uint16_t) op->preop[1]) << 8; preop |= ((uint16_t) op->preop[1]) << 8;
if ((ich7_detected) || (viaspi_detected)) {
REGWRITE16(ICH7_REG_PREOP, temp16);
} else if (ich9_detected) {
REGWRITE16(ICH9_REG_PREOP, temp16);
}
/* Program Opcode Types 0 - 7 */ /* Program Opcode Types 0 - 7 */
temp16 = 0; optype = 0;
for (a = 0; a < 8; a++) { for (a = 0; a < 8; a++) {
temp16 |= ((uint16_t) op->opcode[a].spi_type) << (a * 2); optype |= ((uint16_t) op->opcode[a].spi_type) << (a * 2);
}
if ((ich7_detected) || (viaspi_detected)) {
REGWRITE16(ICH7_REG_OPTYPE, temp16);
} else if (ich9_detected) {
REGWRITE16(ICH9_REG_OPTYPE, temp16);
} }
/* Program Allowable Opcodes 0 - 3 */ /* Program Allowable Opcodes 0 - 3 */
temp32 = 0; opmenu[0] = 0;
for (a = 0; a < 4; a++) { for (a = 0; a < 4; a++) {
temp32 |= ((uint32_t) op->opcode[a].opcode) << (a * 8); opmenu[0] |= ((uint32_t) op->opcode[a].opcode) << (a * 8);
} }
if ((ich7_detected) || (viaspi_detected)) {
REGWRITE32(ICH7_REG_OPMENU, temp32);
} else if (ich9_detected) {
REGWRITE32(ICH9_REG_OPMENU, temp32);
}
/*Program Allowable Opcodes 4 - 7 */ /*Program Allowable Opcodes 4 - 7 */
temp32 = 0; opmenu[1] = 0;
for (a = 4; a < 8; a++) { for (a = 4; a < 8; a++) {
temp32 |= opmenu[1] |= ((uint32_t) op->opcode[a].opcode) << ((a - 4) * 8);
((uint32_t) op->opcode[a].opcode) << ((a - 4) * 8); }
}
switch (flashbus) {
if ((ich7_detected) || (viaspi_detected)) { case BUS_TYPE_ICH7_SPI:
REGWRITE32(ICH7_REG_OPMENU + 4, temp32); case BUS_TYPE_VIA_SPI:
} else if (ich9_detected) { REGWRITE16(ICH7_REG_PREOP, preop);
REGWRITE32(ICH9_REG_OPMENU + 4, temp32); REGWRITE16(ICH7_REG_OPTYPE, optype);
REGWRITE32(ICH7_REG_OPMENU, opmenu[0]);
REGWRITE32(ICH7_REG_OPMENU + 4, opmenu[1]);
break;
case BUS_TYPE_ICH9_SPI:
REGWRITE16(ICH9_REG_PREOP, preop);
REGWRITE16(ICH9_REG_OPTYPE, optype);
REGWRITE32(ICH9_REG_OPMENU, opmenu[0]);
REGWRITE32(ICH9_REG_OPMENU + 4, opmenu[1]);
break;
default:
printf_debug("%s: unsupported chipset\n", __FUNCTION__);
return -1;
} }
return 0; return 0;
...@@ -340,6 +333,7 @@ static int ich9_run_opcode(uint8_t nr, OPCODE op, uint32_t offset, ...@@ -340,6 +333,7 @@ static int ich9_run_opcode(uint8_t nr, OPCODE op, uint32_t offset,
uint8_t datalength, uint8_t * data) uint8_t datalength, uint8_t * data)
{ {
int write_cmd = 0; int write_cmd = 0;
int timeout;
uint32_t temp32; uint32_t temp32;
uint32_t a; uint32_t a;
...@@ -410,9 +404,12 @@ static int ich9_run_opcode(uint8_t nr, OPCODE op, uint32_t offset, ...@@ -410,9 +404,12 @@ static int ich9_run_opcode(uint8_t nr, OPCODE op, uint32_t offset,
REGWRITE32(ICH9_REG_SSFS, temp32); REGWRITE32(ICH9_REG_SSFS, temp32);
/*wait for cycle complete */ /*wait for cycle complete */
while ((REGREAD32(ICH9_REG_SSFS) & SSFS_CDS) == 0) { timeout = 1000 * 60; // 60s is a looong timeout.
/*TODO; Do something that this can't lead into an endless loop. but some while (((REGREAD32(ICH9_REG_SSFS) & SSFS_CDS) == 0) && --timeout) {
* commands may cause this to be last more than 30 seconds */ myusec_delay(1000);
}
if (!timeout) {
printf_debug("timeout\n");
} }
if ((REGREAD32(ICH9_REG_SSFS) & SSFS_FCERR) != 0) { if ((REGREAD32(ICH9_REG_SSFS) & SSFS_FCERR) != 0) {
...@@ -438,12 +435,16 @@ static int ich9_run_opcode(uint8_t nr, OPCODE op, uint32_t offset, ...@@ -438,12 +435,16 @@ static int ich9_run_opcode(uint8_t nr, OPCODE op, uint32_t offset,
static int run_opcode(uint8_t nr, OPCODE op, uint32_t offset, static int run_opcode(uint8_t nr, OPCODE op, uint32_t offset,
uint8_t datalength, uint8_t * data) uint8_t datalength, uint8_t * data)
{ {
if (ich7_detected) switch (flashbus) {
return ich7_run_opcode(nr, op, offset, datalength, data, 64); case BUS_TYPE_VIA_SPI:
else if (viaspi_detected)
return ich7_run_opcode(nr, op, offset, datalength, data, 16); return ich7_run_opcode(nr, op, offset, datalength, data, 16);
else if (ich9_detected) case BUS_TYPE_ICH7_SPI:
return ich7_run_opcode(nr, op, offset, datalength, data, 64);
case BUS_TYPE_ICH9_SPI:
return ich9_run_opcode(nr, op, offset, datalength, data); return ich9_run_opcode(nr, op, offset, datalength, data);
default:
printf_debug("%s: unsupported chipset\n", __FUNCTION__);
}
/* If we ever get here, something really weird happened */ /* If we ever get here, something really weird happened */
return -1; return -1;
...@@ -541,7 +542,7 @@ int ich_spi_read(struct flashchip *flash, uint8_t * buf) ...@@ -541,7 +542,7 @@ int ich_spi_read(struct flashchip *flash, uint8_t * buf)
int page_size = flash->page_size; int page_size = flash->page_size;
int maxdata = 64; int maxdata = 64;
if (viaspi_detected) { if (flashbus == BUS_TYPE_VIA_SPI) {
maxdata = 16; maxdata = 16;
} }
...@@ -572,7 +573,7 @@ int ich_spi_write(struct flashchip *flash, uint8_t * buf) ...@@ -572,7 +573,7 @@ int ich_spi_write(struct flashchip *flash, uint8_t * buf)
break; break;
} }
if (viaspi_detected) { if (flashbus == BUS_TYPE_VIA_SPI) {
maxdata = 16; maxdata = 16;
} }
for (j = 0; j < erase_size / page_size; j++) { for (j = 0; j < erase_size / page_size; j++) {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* *
* Copyright (C) 2007, 2008 Carl-Daniel Hailfinger * Copyright (C) 2007, 2008 Carl-Daniel Hailfinger
* Copyright (C) 2008 Ronald Hoogenboom <ronald@zonnet.nl> * Copyright (C) 2008 Ronald Hoogenboom <ronald@zonnet.nl>
* Copyright (C) 2008 coresystems GmbH
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -112,8 +113,13 @@ static uint16_t find_ite_spi_flash_port(uint16_t port) ...@@ -112,8 +113,13 @@ static uint16_t find_ite_spi_flash_port(uint16_t port)
int it87xx_probe_spi_flash(const char *name) int it87xx_probe_spi_flash(const char *name)
{ {
it8716f_flashport = find_ite_spi_flash_port(ITE_SUPERIO_PORT1); it8716f_flashport = find_ite_spi_flash_port(ITE_SUPERIO_PORT1);
if (!it8716f_flashport) if (!it8716f_flashport)
it8716f_flashport = find_ite_spi_flash_port(ITE_SUPERIO_PORT2); it8716f_flashport = find_ite_spi_flash_port(ITE_SUPERIO_PORT2);
if (it8716f_flashport)
flashbus = BUS_TYPE_IT87XX_SPI;
return (!it8716f_flashport); return (!it8716f_flashport);
} }
......
...@@ -34,13 +34,16 @@ void spi_prettyprint_status_register(struct flashchip *flash); ...@@ -34,13 +34,16 @@ void spi_prettyprint_status_register(struct flashchip *flash);
int spi_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr) int spi_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr)
{ {
if (it8716f_flashport) switch (flashbus) {
case BUS_TYPE_IT87XX_SPI:
return it8716f_spi_command(writecnt, readcnt, writearr, readarr); return it8716f_spi_command(writecnt, readcnt, writearr, readarr);
else if ((ich7_detected) || (viaspi_detected)) case BUS_TYPE_ICH7_SPI:
return ich_spi_command(writecnt, readcnt, writearr, readarr); case BUS_TYPE_ICH9_SPI:
else if (ich9_detected) case BUS_TYPE_VIA_SPI:
return ich_spi_command(writecnt, readcnt, writearr, readarr); return ich_spi_command(writecnt, readcnt, writearr, readarr);
printf_debug("%s called, but no SPI chipset detected\n", __FUNCTION__); default:
printf_debug("%s called, but no SPI chipset/strapping detected\n", __FUNCTION__);
}
return 1; return 1;
} }
...@@ -135,9 +138,16 @@ int probe_spi_rdid(struct flashchip *flash) { ...@@ -135,9 +138,16 @@ int probe_spi_rdid(struct flashchip *flash) {
int probe_spi_rdid4(struct flashchip *flash) { int probe_spi_rdid4(struct flashchip *flash) {
/* only some SPI chipsets support 4 bytes commands */ /* only some SPI chipsets support 4 bytes commands */
if (!((ich7_detected) || (ich9_detected) || (viaspi_detected))) switch (flashbus) {
return 0; case BUS_TYPE_ICH7_SPI:
return probe_spi_rdid_generic(flash, 4); case BUS_TYPE_ICH9_SPI:
case BUS_TYPE_VIA_SPI:
return probe_spi_rdid_generic(flash, 4);
default:
printf_debug("4b ID not supported on this SPI controller\n");
}
return 0;
} }
int probe_spi_res(struct flashchip *flash) int probe_spi_res(struct flashchip *flash)
...@@ -316,11 +326,17 @@ int spi_sector_erase(const struct flashchip *flash, unsigned long addr) ...@@ -316,11 +326,17 @@ int spi_sector_erase(const struct flashchip *flash, unsigned long addr)
void spi_page_program(int block, uint8_t *buf, uint8_t *bios) void spi_page_program(int block, uint8_t *buf, uint8_t *bios)
{ {
if (it8716f_flashport) { switch (flashbus) {
case BUS_TYPE_IT87XX_SPI:
it8716f_spi_page_program(block, buf, bios); it8716f_spi_page_program(block, buf, bios);
return; break;
case BUS_TYPE_ICH7_SPI:
case BUS_TYPE_ICH9_SPI:
printf_debug("%s called, but not implemented for ICH\n", __FUNCTION__);
break;
default:
printf_debug("%s called, but no SPI chipset/strapping detected\n", __FUNCTION__);
} }
printf_debug("%s called, but no SPI chipset detected\n", __FUNCTION__);
} }
/* /*
...@@ -375,25 +391,34 @@ void spi_nbyte_read(int address, uint8_t *bytes, int len) ...@@ -375,25 +391,34 @@ void spi_nbyte_read(int address, uint8_t *bytes, int len)
int spi_chip_read(struct flashchip *flash, uint8_t *buf) int spi_chip_read(struct flashchip *flash, uint8_t *buf)
{ {
if (it8716f_flashport)
switch (flashbus) {
case BUS_TYPE_IT87XX_SPI:
return it8716f_spi_chip_read(flash, buf); return it8716f_spi_chip_read(flash, buf);
else if ((ich7_detected) || (viaspi_detected)) case BUS_TYPE_ICH7_SPI:
return ich_spi_read(flash, buf); case BUS_TYPE_ICH9_SPI:
else if (ich9_detected) case BUS_TYPE_VIA_SPI:
return ich_spi_read(flash, buf); return ich_spi_read(flash, buf);
printf_debug("%s called, but no SPI chipset detected\n", __FUNCTION__); default:
printf_debug("%s called, but no SPI chipset/strapping detected\n", __FUNCTION__);
}
return 1; return 1;
} }
int spi_chip_write(struct flashchip *flash, uint8_t *buf) int spi_chip_write(struct flashchip *flash, uint8_t *buf)
{ {
if (it8716f_flashport) switch (flashbus) {
case BUS_TYPE_IT87XX_SPI:
return it8716f_spi_chip_write(flash, buf); return it8716f_spi_chip_write(flash, buf);
else if ((ich7_detected) || (viaspi_detected)) case BUS_TYPE_ICH7_SPI:
case BUS_TYPE_ICH9_SPI:
case BUS_TYPE_VIA_SPI:
return ich_spi_write(flash, buf); return ich_spi_write(flash, buf);
else if (ich9_detected) default:
return ich_spi_write(flash, buf); printf_debug("%s called, but no SPI chipset/strapping detected\n", __FUNCTION__);
printf_debug("%s called, but no SPI chipset detected\n", __FUNCTION__); }
return 1; return 1;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment