/* erase one block or chip or sector as needed */ static int ec_unit_erase(unsigned char erase_cmd, unsigned int addr) { unsigned char status; int ret = 0, i = 0; int unprotect_count = 3; int check_flag = 0; /* enable spicmd writing. */ ec_start_spi(); #ifdef EC_ROM_PROTECTION /* added for re-check SPICMD_READ_STATUS */ while (unprotect_count-- > 0) { if (EC_ROM_unprotect()) { ret = -EINVAL; goto out; } /* first time:500ms --> 5.5sec -->10.5sec */ for (i = 0; i < ((2 - unprotect_count) * 100 + 10); i++) udelay(50000); ec_write(REG_XBISPICMD, SPICMD_READ_STATUS); if (rom_instruction_cycle(SPICMD_READ_STATUS) == EC_STATE_BUSY) { printk(KERN_ERR "EC_PROGRAM_ROM : SPICMD_READ_STATUS failed.\n"); } else { status = ec_read(REG_XBISPIDAT); printk(KERN_INFO "Read unprotect status : 0x%x\n", status); if ((status & 0x1C) == 0x00) { printk(KERN_INFO "Read unprotect status OK1 : 0x%x\n", status & 0x1C); check_flag = 1; break; } } } if (!check_flag) { printk(KERN_INFO "SPI ROM unprotect fail.\n"); return 1; } #endif /* block address fill */ if (erase_cmd == SPICMD_BLK_ERASE) { ec_write(REG_XBISPIA2, (addr & 0x00ff0000) >> 16); ec_write(REG_XBISPIA1, (addr & 0x0000ff00) >> 8); ec_write(REG_XBISPIA0, (addr & 0x000000ff) >> 0); }
/* Starts to execute the unprotect SPI ROM function. */ int EC_ROM_start_unprotect(void) { unsigned char status; int ret = 0, i = 0; int unprotect_count = 3; int check_flag =0; /* added for re-check SPICMD_READ_STATUS */ while(unprotect_count-- > 0){ if(EC_ROM_unprotect()){ ret = -1; return ret; } for(i = 0; i < ((2 - unprotect_count) * 100 + 10); i++) //first time:500ms --> 5.5sec -->10.5sec udelay(50000); wrec(REG_XBISPICMD, SPICMD_READ_STATUS); if(rom_instruction_cycle(SPICMD_READ_STATUS) == EC_STATE_BUSY){ printf("EC_PROGRAM_ROM : SPICMD_READ_STATUS failed.\n"); } else { status = rdec(REG_XBISPIDAT); //printf("Read unprotect status : 0x%x\n", status); if((status & 0x1C) == 0x00){ //printf("Read unprotect status OK1 : 0x%x\n", status & 0x1C); check_flag = 1; break; } } } if(!check_flag){ printf("SPI ROM unprotect fail.\n"); return 1; } //printf("SPI ROM unprotect success.\n"); return ret; }