Show
Ignore:
Timestamp:
06/27/08 17:18:20 (5 months ago)
Author:
stepan
Message:

indent according to development guidelines (trivial)
Signed-off-by: Stefan Reinauer <stepan@…>
Acked-by: Stefan Reinauer <stepan@…>

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/util/flashrom/ichspi.c

    r3325 r3392  
    7272#define SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS  3 
    7373 
    74  
    7574typedef struct _OPCODE { 
    7675        uint8_t opcode;         //This commands spi opcode 
     
    9796} OPCODES; 
    9897 
    99  
    100 static OPCODES *curopcodes=NULL; 
    101  
     98static OPCODES *curopcodes = NULL; 
    10299 
    103100/* HW access functions */ 
     
    105102{ 
    106103        volatile uint32_t regval; 
    107         regval = *(volatile uint32_t *)((uint8_t *)ich_spibar + X); 
     104        regval = *(volatile uint32_t *)((uint8_t *) ich_spibar + X); 
    108105        return regval; 
    109106} 
     
    113110#define REGWRITE8(X,Y)  (*(uint8_t *)((uint8_t *)ich_spibar+X)=Y) 
    114111 
    115  
    116112/* Common SPI functions */ 
    117113static 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); 
     114static int run_opcode(uint8_t nr, OPCODE op, uint32_t offset, 
     115                      uint8_t datalength, uint8_t * data); 
     116static int ich_spi_read_page(struct flashchip *flash, uint8_t * buf, 
     117                             int Offset); 
     118static int ich_spi_write_page(struct flashchip *flash, uint8_t * bytes, 
     119                              int Offset); 
    121120static int ich_spi_erase_block(struct flashchip *flash, int offset); 
    122  
    123121 
    124122OPCODES O_ST_M25P = { 
    125123        { 
    126124         JEDEC_WREN, 
    127          0 
    128         }, 
     125         0}, 
    129126        { 
    130          {JEDEC_BYTE_PROGRAM,   SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS,     1},     // Write Byte 
    131          {JEDEC_READ,           SPI_OPCODE_TYPE_READ_WITH_ADDRESS,      0},     // Read Data 
    132          {JEDEC_BE_D8,          SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS,     1},     // Erase Sector 
    133          {JEDEC_RDSR,           SPI_OPCODE_TYPE_READ_NO_ADDRESS,        0},     // Read Device Status Reg 
    134          {JEDEC_RES,            SPI_OPCODE_TYPE_READ_WITH_ADDRESS,      0},     // Resume Deep Power-Down 
    135          {JEDEC_WRSR,           SPI_OPCODE_TYPE_WRITE_NO_ADDRESS,       1},     // Write Status Register 
    136          {JEDEC_RDID,           SPI_OPCODE_TYPE_READ_NO_ADDRESS,        0},     // Read JDEC ID 
    137          {JEDEC_CE_C7,          SPI_OPCODE_TYPE_WRITE_NO_ADDRESS,       1},     // Bulk erase 
    138         } 
     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         } 
    139136}; 
    140  
    141137 
    142138int program_opcodes(OPCODES * op) 
     
    179175 
    180176int run_opcode(uint8_t nr, OPCODE op, uint32_t offset, uint8_t datalength, 
    181               uint8_t * data) 
     177               uint8_t * data) 
    182178{ 
    183179        int write_cmd = 0; 
     
    276272} 
    277273 
    278  
    279274static int ich_spi_erase_block(struct flashchip *flash, int offset) 
    280275{ 
     
    297292        int a; 
    298293 
    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); 
    300296 
    301297        for (a = 0; a < page_size; a += MAXDATABYTES) { 
     
    326322 
    327323static int ich_spi_write_page(struct flashchip *flash, uint8_t * bytes, 
    328                              int Offset) 
     324                              int Offset) 
    329325{ 
    330326        int page_size = flash->page_size; 
     
    332328        int a; 
    333329 
    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); 
    336332 
    337333        for (a = 0; a < page_size; a += MAXDATABYTES) { 
     
    360356} 
    361357 
    362  
    363358int ich_spi_read(struct flashchip *flash, uint8_t * buf) 
    364359{ 
     
    369364        for (i = 0; (i < total_size / page_size) && (rc == 0); i++) { 
    370365                rc = ich_spi_read_page(flash, (void *)(buf + i * page_size), 
    371                                       i * page_size); 
     366                                       i * page_size); 
    372367        } 
    373368 
    374369        return rc; 
    375370} 
    376  
    377371 
    378372int ich_spi_write(struct flashchip *flash, uint8_t * buf) 
     
    393387                        break; 
    394388                } 
    395                  
     389 
    396390                for (j = 0; j < erase_size / page_size; j++) { 
    397391                        ich_spi_write_page(flash, (void *)(buf + (i * erase_size) + (j * page_size)), 
     
    405399} 
    406400 
    407 int ich_spi_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr) 
     401int ich_spi_command(unsigned int writecnt, unsigned int readcnt, 
     402                    const unsigned char *writearr, unsigned char *readarr) 
    408403{ 
    409404        int a; 
     
    418413        if (curopcodes == NULL) { 
    419414                printf_debug("Programming OPCODES\n"); 
    420                 curopcodes=&O_ST_M25P; 
     415                curopcodes = &O_ST_M25P; 
    421416                program_opcodes(curopcodes); 
    422417        } 
     
    441436        if (opcode->spi_type == SPI_OPCODE_TYPE_READ_WITH_ADDRESS || 
    442437            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 
    448442        /* translate read/write array/count */ 
    449443        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; 
    459451                count = readcnt; 
    460452        } 
    461          
     453 
    462454        if (run_opcode(opcode_index, *opcode, addr, count, data) != 0) { 
    463455                printf_debug("run OPCODE 0x%02x failed\n", opcode->opcode);