Author: mkarcher
Date: Wed May 11 19:07:02 2011
New Revision: 1298
URL: http://flashrom.org/trac/flashrom/changeset/1298

Log:
Factor out SPI write/read chunking wrappers.

Signed-off-by: Michael Karcher <[email protected]>
Acked-by: Carl-Daniel Hailfinger <[email protected]>

Modified:
   trunk/bitbang_spi.c
   trunk/buspirate_spi.c
   trunk/dummyflasher.c
   trunk/ft2232_spi.c
   trunk/ichspi.c
   trunk/it85spi.c
   trunk/programmer.h
   trunk/sb600spi.c
   trunk/spi.c

Modified: trunk/bitbang_spi.c
==============================================================================
--- trunk/bitbang_spi.c Sun May  8 02:24:18 2011        (r1297)
+++ trunk/bitbang_spi.c Wed May 11 19:07:02 2011        (r1298)
@@ -151,14 +151,3 @@
 
        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);
-}

Modified: trunk/buspirate_spi.c
==============================================================================
--- trunk/buspirate_spi.c       Sun May  8 02:24:18 2011        (r1297)
+++ trunk/buspirate_spi.c       Wed May 11 19:07:02 2011        (r1298)
@@ -326,13 +326,3 @@
 
        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);
-}

Modified: trunk/dummyflasher.c
==============================================================================
--- trunk/dummyflasher.c        Sun May  8 02:24:18 2011        (r1297)
+++ trunk/dummyflasher.c        Wed May 11 19:07:02 2011        (r1298)
@@ -507,12 +507,6 @@
        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,

Modified: trunk/ft2232_spi.c
==============================================================================
--- trunk/ft2232_spi.c  Sun May  8 02:24:18 2011        (r1297)
+++ trunk/ft2232_spi.c  Wed May 11 19:07:02 2011        (r1298)
@@ -352,17 +352,6 @@
        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;

Modified: trunk/ichspi.c
==============================================================================
--- trunk/ichspi.c      Sun May  8 02:24:18 2011        (r1297)
+++ trunk/ichspi.c      Wed May 11 19:07:02 2011        (r1298)
@@ -834,26 +834,6 @@
        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)
 {

Modified: trunk/it85spi.c
==============================================================================
--- trunk/it85spi.c     Sun May  8 02:24:18 2011        (r1297)
+++ trunk/it85spi.c     Wed May 11 19:07:02 2011        (r1298)
@@ -347,14 +347,4 @@
        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

Modified: trunk/programmer.h
==============================================================================
--- trunk/programmer.h  Sun May  8 02:24:18 2011        (r1297)
+++ trunk/programmer.h  Wed May 11 19:07:02 2011        (r1298)
@@ -374,7 +374,6 @@
 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 @@
 };
 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 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 @@
 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 @@
        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 @@
 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 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_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 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 */

Modified: trunk/sb600spi.c
==============================================================================
--- trunk/sb600spi.c    Sun May  8 02:24:18 2011        (r1297)
+++ trunk/sb600spi.c    Wed May 11 19:07:02 2011        (r1298)
@@ -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);

Modified: trunk/spi.c
==============================================================================
--- trunk/spi.c Sun May  8 02:24:18 2011        (r1297)
+++ trunk/spi.c Wed May 11 19:07:02 2011        (r1298)
@@ -34,6 +34,8 @@
 
 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 @@
 #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 @@
        },
 
        { /* 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 @@
        },
 
        { /* 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 @@
 
 #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 @@
        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 "
+                        "[email protected]\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 "
+                        "[email protected]\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;

_______________________________________________
flashrom mailing list
[email protected]
http://www.flashrom.org/mailman/listinfo/flashrom

Reply via email to