Permalink
Browse files

Add struct flashctx * parameter to all functions accessing flash chips.

All programmer access function prototypes except init have been made
static and moved to the respective file.

A few internal functions in flash chip drivers had chipaddr parameters
which are no longer needed.

The lines touched by flashctx changes have been adjusted to 80 columns
except in header files.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de>


git-svn-id: svn://flashrom.org/flashrom/trunk@1474 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
  • Loading branch information...
1 parent 74511e8 commit 68c98275ab11c35357131bfaa0999d04761519c5 hailfinger committed Dec 18, 2011
Showing with 727 additions and 541 deletions.
  1. +35 −34 82802ab.c
  2. +4 −4 a25.c
  3. +11 −11 at25.c
  4. +8 −2 atahpt.c
  5. +8 −4 bitbang_spi.c
  6. +10 −4 buspirate_spi.c
  7. +10 −10 chipdrivers.h
  8. +5 −2 dediprog.c
  9. +8 −2 drkaiser.c
  10. +44 −14 dummyflasher.c
  11. +12 −12 flash.h
  12. +31 −24 flashrom.c
  13. +8 −4 ft2232_spi.c
  14. +8 −2 gfxnvidia.c
  15. +18 −16 ichspi.c
  16. +28 −7 internal.c
  17. +8 −4 it85spi.c
  18. +11 −7 it87spi.c
  19. +72 −64 jedec.c
  20. +12 −6 linux_spi.c
  21. +34 −31 m29f400bt.c
  22. +8 −2 nic3com.c
  23. +8 −2 nicintel.c
  24. +8 −2 nicnatsemi.c
  25. +8 −2 nicrealtek.c
  26. +9 −5 pm49fl00x.c
  27. +23 −19 programmer.c
  28. +31 −67 programmer.h
  29. +8 −2 satamv.c
  30. +8 −2 satasii.c
  31. +4 −2 sb600spi.c
  32. +21 −9 serprog.c
  33. +8 −7 sharplhf00l04.c
  34. +25 −17 spi.c
  35. +87 −69 spi25.c
  36. +29 −26 sst28sf040.c
  37. +10 −6 sst49lfxxxc.c
  38. +2 −2 sst_fwhub.c
  39. +11 −8 stm50flw0x0x.c
  40. +11 −11 w29ee011.c
  41. +11 −11 w39.c
  42. +12 −6 wbsio_spi.c
View
@@ -47,18 +47,18 @@ int probe_82802ab(struct flashctx *flash)
int shifted = (flash->feature_bits & FEATURE_ADDR_SHIFTED) != 0;
/* Reset to get a clean state */
- chip_writeb(0xFF, bios);
+ chip_writeb(flash, 0xFF, bios);
programmer_delay(10);
/* Enter ID mode */
- chip_writeb(0x90, bios);
+ chip_writeb(flash, 0x90, bios);
programmer_delay(10);
- id1 = chip_readb(bios + (0x00 << shifted));
- id2 = chip_readb(bios + (0x01 << shifted));
+ id1 = chip_readb(flash, bios + (0x00 << shifted));
+ id2 = chip_readb(flash, bios + (0x01 << shifted));
/* Leave ID mode */
- chip_writeb(0xFF, bios);
+ chip_writeb(flash, 0xFF, bios);
programmer_delay(10);
@@ -71,8 +71,8 @@ int probe_82802ab(struct flashctx *flash)
* Read the product ID location again. We should now see normal
* flash contents.
*/
- flashcontent1 = chip_readb(bios + (0x00 << shifted));
- flashcontent2 = chip_readb(bios + (0x01 << shifted));
+ flashcontent1 = chip_readb(flash, bios + (0x00 << shifted));
+ flashcontent2 = chip_readb(flash, bios + (0x01 << shifted));
if (id1 == flashcontent1)
msg_cdbg(", id1 is normal flash content");
@@ -94,15 +94,15 @@ uint8_t wait_82802ab(struct flashctx *flash)
uint8_t status;
chipaddr bios = flash->virtual_memory;
- chip_writeb(0x70, bios);
- if ((chip_readb(bios) & 0x80) == 0) { // it's busy
- while ((chip_readb(bios) & 0x80) == 0) ;
+ chip_writeb(flash, 0x70, bios);
+ if ((chip_readb(flash, bios) & 0x80) == 0) { // it's busy
+ while ((chip_readb(flash, bios) & 0x80) == 0) ;
}
- status = chip_readb(bios);
+ status = chip_readb(flash, bios);
/* Reset to get a clean state */
- chip_writeb(0xFF, bios);
+ chip_writeb(flash, 0xFF, bios);
return status;
}
@@ -113,7 +113,7 @@ int unlock_82802ab(struct flashctx *flash)
//chipaddr wrprotect = flash->virtual_registers + page + 2;
for (i = 0; i < flash->total_size * 1024; i+= flash->page_size)
- chip_writeb(0, flash->virtual_registers + i + 2);
+ chip_writeb(flash, 0, flash->virtual_registers + i + 2);
return 0;
}
@@ -125,11 +125,11 @@ int erase_block_82802ab(struct flashctx *flash, unsigned int page,
uint8_t status;
// clear status register
- chip_writeb(0x50, bios + page);
+ chip_writeb(flash, 0x50, bios + page);
// now start it
- chip_writeb(0x20, bios + page);
- chip_writeb(0xd0, bios + page);
+ chip_writeb(flash, 0x20, bios + page);
+ chip_writeb(flash, 0xd0, bios + page);
programmer_delay(10);
// now let's see what the register is
@@ -141,15 +141,16 @@ int erase_block_82802ab(struct flashctx *flash, unsigned int page,
}
/* chunksize is 1 */
-int write_82802ab(struct flashctx *flash, uint8_t *src, unsigned int start, unsigned int len)
+int write_82802ab(struct flashctx *flash, uint8_t *src, unsigned int start,
+ unsigned int len)
{
int i;
chipaddr dst = flash->virtual_memory + start;
for (i = 0; i < len; i++) {
/* transfer data from source to destination */
- chip_writeb(0x40, dst);
- chip_writeb(*src++, dst++);
+ chip_writeb(flash, 0x40, dst);
+ chip_writeb(flash, *src++, dst++);
wait_82802ab(flash);
}
@@ -164,13 +165,13 @@ int unlock_28f004s5(struct flashctx *flash)
int i;
/* Clear status register */
- chip_writeb(0x50, bios);
+ chip_writeb(flash, 0x50, bios);
/* Read identifier codes */
- chip_writeb(0x90, bios);
+ chip_writeb(flash, 0x90, bios);
/* Read master lock-bit */
- mcfg = chip_readb(bios + 0x3);
+ mcfg = chip_readb(flash, bios + 0x3);
msg_cdbg("master lock is ");
if (mcfg) {
msg_cdbg("locked!\n");
@@ -181,22 +182,22 @@ int unlock_28f004s5(struct flashctx *flash)
/* Read block lock-bits */
for (i = 0; i < flash->total_size * 1024; i+= (64 * 1024)) {
- bcfg = chip_readb(bios + i + 2); // read block lock config
+ bcfg = chip_readb(flash, bios + i + 2); // read block lock config
msg_cdbg("block lock at %06x is %slocked!\n", i, bcfg ? "" : "un");
if (bcfg) {
need_unlock = 1;
}
}
/* Reset chip */
- chip_writeb(0xFF, bios);
+ chip_writeb(flash, 0xFF, bios);
/* Unlock: clear block lock-bits, if needed */
if (can_unlock && need_unlock) {
msg_cdbg("Unlock: ");
- chip_writeb(0x60, bios);
- chip_writeb(0xD0, bios);
- chip_writeb(0xFF, bios);
+ chip_writeb(flash, 0x60, bios);
+ chip_writeb(flash, 0xD0, bios);
+ chip_writeb(flash, 0xFF, bios);
msg_cdbg("Done!\n");
}
@@ -220,10 +221,10 @@ int unlock_lh28f008bjt(struct flashctx *flash)
wait_82802ab(flash);
/* Read identifier codes */
- chip_writeb(0x90, bios);
+ chip_writeb(flash, 0x90, bios);
/* Read master lock-bit */
- mcfg = chip_readb(bios + 0x3);
+ mcfg = chip_readb(flash, bios + 0x3);
msg_cdbg("master lock is ");
if (mcfg) {
msg_cdbg("locked!\n");
@@ -235,22 +236,22 @@ int unlock_lh28f008bjt(struct flashctx *flash)
/* Read block lock-bits, 8 * 8 KB + 15 * 64 KB */
for (i = 0; i < flash->total_size * 1024;
i += (i >= (64 * 1024) ? 64 * 1024 : 8 * 1024)) {
- bcfg = chip_readb(bios + i + 2); /* read block lock config */
+ bcfg = chip_readb(flash, bios + i + 2); /* read block lock config */
msg_cdbg("block lock at %06x is %slocked!\n", i,
bcfg ? "" : "un");
if (bcfg)
need_unlock = 1;
}
/* Reset chip */
- chip_writeb(0xFF, bios);
+ chip_writeb(flash, 0xFF, bios);
/* Unlock: clear block lock-bits, if needed */
if (can_unlock && need_unlock) {
msg_cdbg("Unlock: ");
- chip_writeb(0x60, bios);
- chip_writeb(0xD0, bios);
- chip_writeb(0xFF, bios);
+ chip_writeb(flash, 0x60, bios);
+ chip_writeb(flash, 0xD0, bios);
+ chip_writeb(flash, 0xFF, bios);
wait_82802ab(flash);
msg_cdbg("Done!\n");
}
View
8 a25.c
@@ -33,7 +33,7 @@ int spi_prettyprint_status_register_amic_a25l05p(struct flashctx *flash)
{
uint8_t status;
- status = spi_read_status_register();
+ status = spi_read_status_register(flash);
msg_cdbg("Chip status register is %02x\n", status);
spi_prettyprint_status_register_amic_a25_srwd(status);
@@ -49,7 +49,7 @@ int spi_prettyprint_status_register_amic_a25l40p(struct flashctx *flash)
{
uint8_t status;
- status = spi_read_status_register();
+ status = spi_read_status_register(flash);
msg_cdbg("Chip status register is %02x\n", status);
spi_prettyprint_status_register_amic_a25_srwd(status);
@@ -64,7 +64,7 @@ int spi_prettyprint_status_register_amic_a25l032(struct flashctx *flash)
{
uint8_t status;
- status = spi_read_status_register();
+ status = spi_read_status_register(flash);
msg_cdbg("Chip status register is %02x\n", status);
spi_prettyprint_status_register_amic_a25_srwd(status);
@@ -82,7 +82,7 @@ int spi_prettyprint_status_register_amic_a25lq032(struct flashctx *flash)
{
uint8_t status;
- status = spi_read_status_register();
+ status = spi_read_status_register(flash);
msg_cdbg("Chip status register is %02x\n", status);
spi_prettyprint_status_register_amic_a25_srwd(status);
View
22 at25.c
@@ -61,7 +61,7 @@ int spi_prettyprint_status_register_at25df(struct flashctx *flash)
{
uint8_t status;
- status = spi_read_status_register();
+ status = spi_read_status_register(flash);
msg_cdbg("Chip status register is %02x\n", status);
spi_prettyprint_status_register_atmel_at25_srpl(status);
@@ -84,7 +84,7 @@ int spi_prettyprint_status_register_at25f(struct flashctx *flash)
{
uint8_t status;
- status = spi_read_status_register();
+ status = spi_read_status_register(flash);
msg_cdbg("Chip status register is %02x\n", status);
spi_prettyprint_status_register_atmel_at25_srpl(status);
@@ -103,7 +103,7 @@ int spi_prettyprint_status_register_at25fs010(struct flashctx *flash)
{
uint8_t status;
- status = spi_read_status_register();
+ status = spi_read_status_register(flash);
msg_cdbg("Chip status register is %02x\n", status);
msg_cdbg("Chip status register: Status Register Write Protect (WPEN) "
@@ -127,7 +127,7 @@ int spi_prettyprint_status_register_at25fs040(struct flashctx *flash)
{
uint8_t status;
- status = spi_read_status_register();
+ status = spi_read_status_register(flash);
msg_cdbg("Chip status register is %02x\n", status);
msg_cdbg("Chip status register: Status Register Write Protect (WPEN) "
@@ -151,7 +151,7 @@ int spi_prettyprint_status_register_atmel_at26df081a(struct flashctx *flash)
{
uint8_t status;
- status = spi_read_status_register();
+ status = spi_read_status_register(flash);
msg_cdbg("Chip status register is %02x\n", status);
spi_prettyprint_status_register_atmel_at25_srpl(status);
@@ -168,7 +168,7 @@ int spi_disable_blockprotect_at25df(struct flashctx *flash)
uint8_t status;
int result;
- status = spi_read_status_register();
+ status = spi_read_status_register(flash);
/* If block protection is disabled, stop here. */
if ((status & (3 << 2)) == 0)
return 0;
@@ -195,7 +195,7 @@ int spi_disable_blockprotect_at25df(struct flashctx *flash)
msg_cerr("spi_write_status_register failed\n");
return result;
}
- status = spi_read_status_register();
+ status = spi_read_status_register(flash);
if ((status & (3 << 2)) != 0) {
msg_cerr("Block protection could not be disabled!\n");
return 1;
@@ -223,7 +223,7 @@ int spi_disable_blockprotect_at25fs010(struct flashctx *flash)
uint8_t status;
int result;
- status = spi_read_status_register();
+ status = spi_read_status_register(flash);
/* If block protection is disabled, stop here. */
if ((status & 0x6c) == 0)
return 0;
@@ -244,7 +244,7 @@ int spi_disable_blockprotect_at25fs010(struct flashctx *flash)
msg_cerr("spi_write_status_register failed\n");
return result;
}
- status = spi_read_status_register();
+ status = spi_read_status_register(flash);
if ((status & 0x6c) != 0) {
msg_cerr("Block protection could not be disabled!\n");
return 1;
@@ -257,7 +257,7 @@ int spi_disable_blockprotect_at25fs040(struct flashctx *flash)
uint8_t status;
int result;
- status = spi_read_status_register();
+ status = spi_read_status_register(flash);
/* If block protection is disabled, stop here. */
if ((status & 0x7c) == 0)
return 0;
@@ -278,7 +278,7 @@ int spi_disable_blockprotect_at25fs040(struct flashctx *flash)
msg_cerr("spi_write_status_register failed\n");
return result;
}
- status = spi_read_status_register();
+ status = spi_read_status_register(flash);
if ((status & 0x7c) != 0) {
msg_cerr("Block protection could not be disabled!\n");
return 1;
View
@@ -40,6 +40,10 @@ const struct pcidev_status ata_hpt[] = {
{},
};
+static void atahpt_chip_writeb(const struct flashctx *flash, uint8_t val,
+ chipaddr addr);
+static uint8_t atahpt_chip_readb(const struct flashctx *flash,
+ const chipaddr addr);
static const struct par_programmer par_programmer_atahpt = {
.chip_readb = atahpt_chip_readb,
.chip_readw = fallback_chip_readw,
@@ -80,13 +84,15 @@ int atahpt_init(void)
return 0;
}
-void atahpt_chip_writeb(uint8_t val, chipaddr addr)
+static void atahpt_chip_writeb(const struct flashctx *flash, uint8_t val,
+ chipaddr addr)
{
OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
OUTB(val, io_base_addr + BIOS_ROM_DATA);
}
-uint8_t atahpt_chip_readb(const chipaddr addr)
+static uint8_t atahpt_chip_readb(const struct flashctx *flash,
+ const chipaddr addr)
{
OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
return INB(io_base_addr + BIOS_ROM_DATA);
View
@@ -63,8 +63,10 @@ static void bitbang_spi_release_bus(void)
bitbang_spi_master->release_bus();
}
-static int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt,
- const unsigned char *writearr, unsigned char *readarr);
+static int bitbang_spi_send_command(struct flashctx *flash,
+ unsigned int writecnt, unsigned int readcnt,
+ const unsigned char *writearr,
+ unsigned char *readarr);
static const struct spi_programmer spi_programmer_bitbang = {
.type = SPI_CONTROLLER_BITBANG,
@@ -141,8 +143,10 @@ static uint8_t bitbang_spi_readwrite_byte(uint8_t val)
return ret;
}
-static int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt,
- const unsigned char *writearr, unsigned char *readarr)
+static int bitbang_spi_send_command(struct flashctx *flash,
+ unsigned int writecnt, unsigned int readcnt,
+ const unsigned char *writearr,
+ unsigned char *readarr)
{
int i;
Oops, something went wrong.

0 comments on commit 68c9827

Please sign in to comment.