mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 15:12:36 +02:00
Factor out SPI write/read chunking wrappers
Corresponding to flashrom svn r1298. Signed-off-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
This commit is contained in:
parent
b713d2e35c
commit
627975196d
@ -151,14 +151,3 @@ int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bitbang_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len)
|
||||
{
|
||||
/* Maximum read length is unlimited, use 64k bytes. */
|
||||
return spi_read_chunked(flash, buf, start, len, 64 * 1024);
|
||||
}
|
||||
|
||||
int bitbang_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len)
|
||||
{
|
||||
return spi_write_chunked(flash, buf, start, len, 256);
|
||||
}
|
||||
|
@ -326,13 +326,3 @@ int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int buspirate_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len)
|
||||
{
|
||||
return spi_read_chunked(flash, buf, start, len, 12);
|
||||
}
|
||||
|
||||
int buspirate_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len)
|
||||
{
|
||||
return spi_write_chunked(flash, buf, start, len, 12);
|
||||
}
|
||||
|
@ -507,12 +507,6 @@ int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dummy_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len)
|
||||
{
|
||||
/* Maximum read length is unlimited, use 64kB. */
|
||||
return spi_read_chunked(flash, buf, start, len, 64 * 1024);
|
||||
}
|
||||
|
||||
int dummy_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len)
|
||||
{
|
||||
return spi_write_chunked(flash, buf, start, len,
|
||||
|
11
ft2232_spi.c
11
ft2232_spi.c
@ -352,17 +352,6 @@ int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
||||
return failed ? -1 : 0;
|
||||
}
|
||||
|
||||
int ft2232_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len)
|
||||
{
|
||||
/* Maximum read length is 64k bytes. */
|
||||
return spi_read_chunked(flash, buf, start, len, 64 * 1024);
|
||||
}
|
||||
|
||||
int ft2232_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len)
|
||||
{
|
||||
return spi_write_chunked(flash, buf, start, len, 256);
|
||||
}
|
||||
|
||||
void print_supported_usbdevs(const struct usbdev_status *devs)
|
||||
{
|
||||
int i;
|
||||
|
20
ichspi.c
20
ichspi.c
@ -834,26 +834,6 @@ static int run_opcode(OPCODE op, uint32_t offset,
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ich_spi_read(struct flashchip *flash, uint8_t * buf, int start, int len)
|
||||
{
|
||||
int maxdata = 64;
|
||||
|
||||
if (spi_controller == SPI_CONTROLLER_VIA)
|
||||
maxdata = 16;
|
||||
|
||||
return spi_read_chunked(flash, buf, start, len, maxdata);
|
||||
}
|
||||
|
||||
int ich_spi_write_256(struct flashchip *flash, uint8_t * buf, int start, int len)
|
||||
{
|
||||
int maxdata = 64;
|
||||
|
||||
if (spi_controller == SPI_CONTROLLER_VIA)
|
||||
maxdata = 16;
|
||||
|
||||
return spi_write_chunked(flash, buf, start, len, maxdata);
|
||||
}
|
||||
|
||||
int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
||||
const unsigned char *writearr, unsigned char *readarr)
|
||||
{
|
||||
|
10
it85spi.c
10
it85spi.c
@ -347,14 +347,4 @@ int it85xx_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int it85_spi_read(struct flashchip *flash, uint8_t * buf, int start, int len)
|
||||
{
|
||||
return spi_read_chunked(flash, buf, start, len, 64);
|
||||
}
|
||||
|
||||
int it85_spi_write_256(struct flashchip *flash, uint8_t * buf, int start, int len)
|
||||
{
|
||||
return spi_write_chunked(flash, buf, start, len, 64);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
21
programmer.h
21
programmer.h
@ -374,7 +374,6 @@ uint32_t dummy_chip_readl(const chipaddr addr);
|
||||
void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
|
||||
int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
||||
const unsigned char *writearr, unsigned char *readarr);
|
||||
int dummy_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
|
||||
int dummy_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
|
||||
#endif
|
||||
|
||||
@ -487,8 +486,6 @@ struct usbdev_status {
|
||||
};
|
||||
int ft2232_spi_init(void);
|
||||
int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
|
||||
int ft2232_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
|
||||
int ft2232_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
|
||||
extern const struct usbdev_status devs_ft2232spi[];
|
||||
void print_supported_usbdevs(const struct usbdev_status *devs);
|
||||
#endif
|
||||
@ -509,8 +506,6 @@ int mcp6x_spi_init(int want_spi);
|
||||
int bitbang_spi_init(const struct bitbang_spi_master *master, int halfperiod);
|
||||
int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
|
||||
int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
|
||||
int bitbang_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
|
||||
int bitbang_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
|
||||
|
||||
/* buspirate_spi.c */
|
||||
struct buspirate_spispeeds {
|
||||
@ -520,8 +515,6 @@ struct buspirate_spispeeds {
|
||||
int buspirate_spi_init(void);
|
||||
int buspirate_spi_shutdown(void);
|
||||
int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
|
||||
int buspirate_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
|
||||
int buspirate_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
|
||||
|
||||
/* dediprog.c */
|
||||
int dediprog_init(void);
|
||||
@ -586,7 +579,13 @@ enum spi_controller {
|
||||
SPI_CONTROLLER_INVALID /* This must always be the last entry. */
|
||||
};
|
||||
extern const int spi_programmer_count;
|
||||
|
||||
#define MAX_DATA_UNSPECIFIED 0
|
||||
#define MAX_DATA_READ_UNLIMITED 64 * 1024
|
||||
#define MAX_DATA_WRITE_UNLIMITED 256
|
||||
struct spi_programmer {
|
||||
int max_data_read;
|
||||
int max_data_write;
|
||||
int (*command)(unsigned int writecnt, unsigned int readcnt,
|
||||
const unsigned char *writearr, unsigned char *readarr);
|
||||
int (*multicommand)(struct spi_command *cmds);
|
||||
@ -601,6 +600,8 @@ extern const struct spi_programmer spi_programmer[];
|
||||
int default_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
||||
const unsigned char *writearr, unsigned char *readarr);
|
||||
int default_spi_send_multicommand(struct spi_command *cmds);
|
||||
int default_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
|
||||
int default_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
|
||||
|
||||
/* ichspi.c */
|
||||
#if CONFIG_INTERNAL == 1
|
||||
@ -610,8 +611,6 @@ int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
|
||||
int via_init_spi(struct pci_dev *dev);
|
||||
int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
||||
const unsigned char *writearr, unsigned char *readarr);
|
||||
int ich_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
|
||||
int ich_spi_write_256(struct flashchip *flash, uint8_t * buf, int start, int len);
|
||||
int ich_spi_send_multicommand(struct spi_command *cmds);
|
||||
#endif
|
||||
|
||||
@ -620,8 +619,6 @@ int it85xx_spi_init(struct superio s);
|
||||
int it85xx_shutdown(void);
|
||||
int it85xx_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
||||
const unsigned char *writearr, unsigned char *readarr);
|
||||
int it85_spi_read(struct flashchip *flash, uint8_t * buf, int start, int len);
|
||||
int it85_spi_write_256(struct flashchip *flash, uint8_t * buf, int start, int len);
|
||||
|
||||
/* it87spi.c */
|
||||
void enter_conf_mode_ite(uint16_t port);
|
||||
@ -638,8 +635,6 @@ int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf, int start,
|
||||
int sb600_probe_spi(struct pci_dev *dev);
|
||||
int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt,
|
||||
const unsigned char *writearr, unsigned char *readarr);
|
||||
int sb600_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
|
||||
int sb600_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
|
||||
#endif
|
||||
|
||||
/* wbsio_spi.c */
|
||||
|
11
sb600spi.c
11
sb600spi.c
@ -43,17 +43,6 @@
|
||||
|
||||
static uint8_t *sb600_spibar = NULL;
|
||||
|
||||
int sb600_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len)
|
||||
{
|
||||
/* Maximum read length is 8 bytes. */
|
||||
return spi_read_chunked(flash, buf, start, len, 8);
|
||||
}
|
||||
|
||||
int sb600_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len)
|
||||
{
|
||||
return spi_write_chunked(flash, buf, start, len, 5);
|
||||
}
|
||||
|
||||
static void reset_internal_fifo_pointer(void)
|
||||
{
|
||||
mmio_writeb(mmio_readb(sb600_spibar + 2) | 0x10, sb600_spibar + 2);
|
||||
|
102
spi.c
102
spi.c
@ -34,6 +34,8 @@ enum spi_controller spi_controller = SPI_CONTROLLER_NONE;
|
||||
|
||||
const struct spi_programmer spi_programmer[] = {
|
||||
{ /* SPI_CONTROLLER_NONE */
|
||||
.max_data_read = MAX_DATA_UNSPECIFIED,
|
||||
.max_data_write = MAX_DATA_UNSPECIFIED,
|
||||
.command = NULL,
|
||||
.multicommand = NULL,
|
||||
.read = NULL,
|
||||
@ -43,27 +45,35 @@ const struct spi_programmer spi_programmer[] = {
|
||||
#if CONFIG_INTERNAL == 1
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
{ /* SPI_CONTROLLER_ICH7 */
|
||||
.max_data_read = 64,
|
||||
.max_data_write = 64,
|
||||
.command = ich_spi_send_command,
|
||||
.multicommand = ich_spi_send_multicommand,
|
||||
.read = ich_spi_read,
|
||||
.write_256 = ich_spi_write_256,
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
},
|
||||
|
||||
{ /* SPI_CONTROLLER_ICH9 */
|
||||
.max_data_read = 64,
|
||||
.max_data_write = 64,
|
||||
.command = ich_spi_send_command,
|
||||
.multicommand = ich_spi_send_multicommand,
|
||||
.read = ich_spi_read,
|
||||
.write_256 = ich_spi_write_256,
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
},
|
||||
|
||||
{ /* SPI_CONTROLLER_IT85XX */
|
||||
.max_data_read = 64,
|
||||
.max_data_write = 64,
|
||||
.command = it85xx_spi_send_command,
|
||||
.multicommand = default_spi_send_multicommand,
|
||||
.read = it85_spi_read,
|
||||
.write_256 = it85_spi_write_256,
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
},
|
||||
|
||||
{ /* SPI_CONTROLLER_IT87XX */
|
||||
.max_data_read = MAX_DATA_UNSPECIFIED,
|
||||
.max_data_write = MAX_DATA_UNSPECIFIED,
|
||||
.command = it8716f_spi_send_command,
|
||||
.multicommand = default_spi_send_multicommand,
|
||||
.read = it8716f_spi_chip_read,
|
||||
@ -71,20 +81,26 @@ const struct spi_programmer spi_programmer[] = {
|
||||
},
|
||||
|
||||
{ /* SPI_CONTROLLER_SB600 */
|
||||
.max_data_read = 8,
|
||||
.max_data_write = 5,
|
||||
.command = sb600_spi_send_command,
|
||||
.multicommand = default_spi_send_multicommand,
|
||||
.read = sb600_spi_read,
|
||||
.write_256 = sb600_spi_write_256,
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
},
|
||||
|
||||
{ /* SPI_CONTROLLER_VIA */
|
||||
.max_data_read = 16,
|
||||
.max_data_write = 16,
|
||||
.command = ich_spi_send_command,
|
||||
.multicommand = ich_spi_send_multicommand,
|
||||
.read = ich_spi_read,
|
||||
.write_256 = ich_spi_write_256,
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
},
|
||||
|
||||
{ /* SPI_CONTROLLER_WBSIO */
|
||||
.max_data_read = MAX_DATA_UNSPECIFIED,
|
||||
.max_data_write = MAX_DATA_UNSPECIFIED,
|
||||
.command = wbsio_spi_send_command,
|
||||
.multicommand = default_spi_send_multicommand,
|
||||
.read = wbsio_spi_read,
|
||||
@ -92,43 +108,53 @@ const struct spi_programmer spi_programmer[] = {
|
||||
},
|
||||
|
||||
{ /* SPI_CONTROLLER_MCP6X_BITBANG */
|
||||
.max_data_read = MAX_DATA_READ_UNLIMITED,
|
||||
.max_data_write = MAX_DATA_WRITE_UNLIMITED,
|
||||
.command = bitbang_spi_send_command,
|
||||
.multicommand = default_spi_send_multicommand,
|
||||
.read = bitbang_spi_read,
|
||||
.write_256 = bitbang_spi_write_256,
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
},
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CONFIG_FT2232_SPI == 1
|
||||
{ /* SPI_CONTROLLER_FT2232 */
|
||||
.max_data_read = 64 * 1024,
|
||||
.max_data_write = 256,
|
||||
.command = ft2232_spi_send_command,
|
||||
.multicommand = default_spi_send_multicommand,
|
||||
.read = ft2232_spi_read,
|
||||
.write_256 = ft2232_spi_write_256,
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
},
|
||||
#endif
|
||||
|
||||
#if CONFIG_DUMMY == 1
|
||||
{ /* SPI_CONTROLLER_DUMMY */
|
||||
.max_data_read = MAX_DATA_READ_UNLIMITED,
|
||||
.max_data_write = MAX_DATA_UNSPECIFIED,
|
||||
.command = dummy_spi_send_command,
|
||||
.multicommand = default_spi_send_multicommand,
|
||||
.read = dummy_spi_read,
|
||||
.read = default_spi_read,
|
||||
.write_256 = dummy_spi_write_256,
|
||||
},
|
||||
#endif
|
||||
|
||||
#if CONFIG_BUSPIRATE_SPI == 1
|
||||
{ /* SPI_CONTROLLER_BUSPIRATE */
|
||||
.max_data_read = 12,
|
||||
.max_data_write = 12,
|
||||
.command = buspirate_spi_send_command,
|
||||
.multicommand = default_spi_send_multicommand,
|
||||
.read = buspirate_spi_read,
|
||||
.write_256 = buspirate_spi_write_256,
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
},
|
||||
#endif
|
||||
|
||||
#if CONFIG_DEDIPROG == 1
|
||||
{ /* SPI_CONTROLLER_DEDIPROG */
|
||||
.max_data_read = MAX_DATA_UNSPECIFIED,
|
||||
.max_data_write = MAX_DATA_UNSPECIFIED,
|
||||
.command = dediprog_spi_send_command,
|
||||
.multicommand = default_spi_send_multicommand,
|
||||
.read = dediprog_spi_read,
|
||||
@ -138,28 +164,34 @@ const struct spi_programmer spi_programmer[] = {
|
||||
|
||||
#if CONFIG_RAYER_SPI == 1
|
||||
{ /* SPI_CONTROLLER_RAYER */
|
||||
.max_data_read = MAX_DATA_READ_UNLIMITED,
|
||||
.max_data_write = MAX_DATA_WRITE_UNLIMITED,
|
||||
.command = bitbang_spi_send_command,
|
||||
.multicommand = default_spi_send_multicommand,
|
||||
.read = bitbang_spi_read,
|
||||
.write_256 = bitbang_spi_write_256,
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
},
|
||||
#endif
|
||||
|
||||
#if CONFIG_NICINTEL_SPI == 1
|
||||
{ /* SPI_CONTROLLER_NICINTEL */
|
||||
.max_data_read = MAX_DATA_READ_UNLIMITED,
|
||||
.max_data_write = MAX_DATA_WRITE_UNLIMITED,
|
||||
.command = bitbang_spi_send_command,
|
||||
.multicommand = default_spi_send_multicommand,
|
||||
.read = bitbang_spi_read,
|
||||
.write_256 = bitbang_spi_write_256,
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
},
|
||||
#endif
|
||||
|
||||
#if CONFIG_OGP_SPI == 1
|
||||
{ /* SPI_CONTROLLER_OGP */
|
||||
.max_data_read = MAX_DATA_READ_UNLIMITED,
|
||||
.max_data_write = MAX_DATA_WRITE_UNLIMITED,
|
||||
.command = bitbang_spi_send_command,
|
||||
.multicommand = default_spi_send_multicommand,
|
||||
.read = bitbang_spi_read,
|
||||
.write_256 = bitbang_spi_write_256,
|
||||
.read = default_spi_read,
|
||||
.write_256 = default_spi_write_256,
|
||||
},
|
||||
#endif
|
||||
|
||||
@ -223,6 +255,30 @@ int default_spi_send_multicommand(struct spi_command *cmds)
|
||||
return result;
|
||||
}
|
||||
|
||||
int default_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len)
|
||||
{
|
||||
int max_data = spi_programmer[spi_controller].max_data_read;
|
||||
if (max_data == MAX_DATA_UNSPECIFIED) {
|
||||
msg_perr("%s called, but SPI read chunk size not defined "
|
||||
"on this hardware. Please report a bug at "
|
||||
"flashrom@flashrom.org\n", __func__);
|
||||
return 1;
|
||||
}
|
||||
return spi_read_chunked(flash, buf, start, len, max_data);
|
||||
}
|
||||
|
||||
int default_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len)
|
||||
{
|
||||
int max_data = spi_programmer[spi_controller].max_data_write;
|
||||
if (max_data == MAX_DATA_UNSPECIFIED) {
|
||||
msg_perr("%s called, but SPI write chunk size not defined "
|
||||
"on this hardware. Please report a bug at "
|
||||
"flashrom@flashrom.org\n", __func__);
|
||||
return 1;
|
||||
}
|
||||
return spi_write_chunked(flash, buf, start, len, max_data);
|
||||
}
|
||||
|
||||
int spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len)
|
||||
{
|
||||
int addrbase = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user