Changeset 3392
- Timestamp:
- 06/27/08 17:18:20 (3 months ago)
- Files:
-
- 1 modified
-
trunk/util/flashrom/ichspi.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/util/flashrom/ichspi.c
r3325 r3392 72 72 #define SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS 3 73 73 74 75 74 typedef struct _OPCODE { 76 75 uint8_t opcode; //This commands spi opcode … … 97 96 } OPCODES; 98 97 99 100 static OPCODES *curopcodes=NULL; 101 98 static OPCODES *curopcodes = NULL; 102 99 103 100 /* HW access functions */ … … 105 102 { 106 103 volatile uint32_t regval; 107 regval = *(volatile uint32_t *)((uint8_t *) ich_spibar + X);104 regval = *(volatile uint32_t *)((uint8_t *) ich_spibar + X); 108 105 return regval; 109 106 } … … 113 110 #define REGWRITE8(X,Y) (*(uint8_t *)((uint8_t *)ich_spibar+X)=Y) 114 111 115 116 112 /* Common SPI functions */ 117 113 static int program_opcodes(OPCODES * op); 118 static int run_opcode(uint8_t nr, OPCODE op, uint32_t offset, uint8_t datalength, uint8_t * data); 119 static int ich_spi_read_page(struct flashchip *flash, uint8_t * buf, int Offset); 120 static int ich_spi_write_page(struct flashchip *flash, uint8_t * bytes, int Offset); 114 static int run_opcode(uint8_t nr, OPCODE op, uint32_t offset, 115 uint8_t datalength, uint8_t * data); 116 static int ich_spi_read_page(struct flashchip *flash, uint8_t * buf, 117 int Offset); 118 static int ich_spi_write_page(struct flashchip *flash, uint8_t * bytes, 119 int Offset); 121 120 static int ich_spi_erase_block(struct flashchip *flash, int offset); 122 123 121 124 122 OPCODES O_ST_M25P = { 125 123 { 126 124 JEDEC_WREN, 127 0 128 }, 125 0}, 129 126 { 130 {JEDEC_BYTE_PROGRAM, SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS,1}, // Write Byte131 {JEDEC_READ, SPI_OPCODE_TYPE_READ_WITH_ADDRESS,0}, // Read Data132 {JEDEC_BE_D8, SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS,1}, // Erase Sector133 {JEDEC_RDSR, SPI_OPCODE_TYPE_READ_NO_ADDRESS,0}, // Read Device Status Reg134 {JEDEC_RES, SPI_OPCODE_TYPE_READ_WITH_ADDRESS,0}, // Resume Deep Power-Down135 {JEDEC_WRSR, SPI_OPCODE_TYPE_WRITE_NO_ADDRESS,1}, // Write Status Register136 {JEDEC_RDID, SPI_OPCODE_TYPE_READ_NO_ADDRESS,0}, // Read JDEC ID137 {JEDEC_CE_C7, SPI_OPCODE_TYPE_WRITE_NO_ADDRESS,1}, // Bulk erase138 }127 {JEDEC_BYTE_PROGRAM, SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS, 1}, // Write Byte 128 {JEDEC_READ, SPI_OPCODE_TYPE_READ_WITH_ADDRESS, 0}, // Read Data 129 {JEDEC_BE_D8, SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS, 1}, // Erase Sector 130 {JEDEC_RDSR, SPI_OPCODE_TYPE_READ_NO_ADDRESS, 0}, // Read Device Status Reg 131 {JEDEC_RES, SPI_OPCODE_TYPE_READ_WITH_ADDRESS, 0}, // Resume Deep Power-Down 132 {JEDEC_WRSR, SPI_OPCODE_TYPE_WRITE_NO_ADDRESS, 1}, // Write Status Register 133 {JEDEC_RDID, SPI_OPCODE_TYPE_READ_NO_ADDRESS, 0}, // Read JDEC ID 134 {JEDEC_CE_C7, SPI_OPCODE_TYPE_WRITE_NO_ADDRESS, 1}, // Bulk erase 135 } 139 136 }; 140 141 137 142 138 int program_opcodes(OPCODES * op) … … 179 175 180 176 int run_opcode(uint8_t nr, OPCODE op, uint32_t offset, uint8_t datalength, 181 uint8_t * data)177 uint8_t * data) 182 178 { 183 179 int write_cmd = 0; … … 276 272 } 277 273 278 279 274 static int ich_spi_erase_block(struct flashchip *flash, int offset) 280 275 { … … 297 292 int a; 298 293 299 printf_debug("Spi_Read,Offset=%d,number=%d,buf=%p\n", Offset, page_size, buf); 294 printf_debug("Spi_Read,Offset=%d,number=%d,buf=%p\n", Offset, page_size, 295 buf); 300 296 301 297 for (a = 0; a < page_size; a += MAXDATABYTES) { … … 326 322 327 323 static int ich_spi_write_page(struct flashchip *flash, uint8_t * bytes, 328 int Offset)324 int Offset) 329 325 { 330 326 int page_size = flash->page_size; … … 332 328 int a; 333 329 334 printf_debug("write_page_ichspi,Offset=%d,number=%d,buf=%p\n", Offset, page_size,335 bytes);330 printf_debug("write_page_ichspi,Offset=%d,number=%d,buf=%p\n", Offset, 331 page_size, bytes); 336 332 337 333 for (a = 0; a < page_size; a += MAXDATABYTES) { … … 360 356 } 361 357 362 363 358 int ich_spi_read(struct flashchip *flash, uint8_t * buf) 364 359 { … … 369 364 for (i = 0; (i < total_size / page_size) && (rc == 0); i++) { 370 365 rc = ich_spi_read_page(flash, (void *)(buf + i * page_size), 371 i * page_size);366 i * page_size); 372 367 } 373 368 374 369 return rc; 375 370 } 376 377 371 378 372 int ich_spi_write(struct flashchip *flash, uint8_t * buf) … … 393 387 break; 394 388 } 395 389 396 390 for (j = 0; j < erase_size / page_size; j++) { 397 391 ich_spi_write_page(flash, (void *)(buf + (i * erase_size) + (j * page_size)), … … 405 399 } 406 400 407 int ich_spi_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr) 401 int ich_spi_command(unsigned int writecnt, unsigned int readcnt, 402 const unsigned char *writearr, unsigned char *readarr) 408 403 { 409 404 int a; … … 418 413 if (curopcodes == NULL) { 419 414 printf_debug("Programming OPCODES\n"); 420 curopcodes =&O_ST_M25P;415 curopcodes = &O_ST_M25P; 421 416 program_opcodes(curopcodes); 422 417 } … … 441 436 if (opcode->spi_type == SPI_OPCODE_TYPE_READ_WITH_ADDRESS || 442 437 opcode->spi_type == SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS) { 443 addr = (writearr[1]<<16) | 444 (writearr[2]<<8) | 445 (writearr[3]<<0); 446 } 447 438 addr = (writearr[1] << 16) | 439 (writearr[2] << 8) | (writearr[3] << 0); 440 } 441 448 442 /* translate read/write array/count */ 449 443 if (opcode->spi_type == SPI_OPCODE_TYPE_WRITE_NO_ADDRESS) { 450 data = (uint8_t*)(writearr+1); 451 count = writecnt-1; 452 } 453 else if (opcode->spi_type == SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS) { 454 data = (uint8_t*)(writearr+4); 455 count = writecnt-4; 456 } 457 else { 458 data = (uint8_t*)readarr; 444 data = (uint8_t *) (writearr + 1); 445 count = writecnt - 1; 446 } else if (opcode->spi_type == SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS) { 447 data = (uint8_t *) (writearr + 4); 448 count = writecnt - 4; 449 } else { 450 data = (uint8_t *) readarr; 459 451 count = readcnt; 460 452 } 461 453 462 454 if (run_opcode(opcode_index, *opcode, addr, count, data) != 0) { 463 455 printf_debug("run OPCODE 0x%02x failed\n", opcode->opcode);
