/* * Service routine to read status register until ready, or timeout occurs. * Returns non-zero if error. */ static int raspi_wait_ready(int sleep_ms) { int count; int sr = 0; /*int timeout = sleep_ms * HZ / 1000; while (timeout) timeout = schedule_timeout (timeout);*/ /* one chip guarantees max 5 msec wait here after page writes, * but potentially three seconds (!) after page erase. */ for (count = 0; count < ((sleep_ms+1)*1000); count++) { if ((raspi_read_sr((u8 *)&sr)) < 0) break; else if (!(sr & (SR_WIP | SR_EPE))) { return 0; } udelay(5); /* REVISIT sometimes sleeping would be best */ } printk("%s: read_sr fail: %x\n", __func__, sr); return -EIO; }
/* * Set all sectors (global) unprotected if they are protected. * Returns negative if error occurred. */ static inline int raspi_unprotect(void) { u8 sr = 0; if (raspi_read_sr(&sr) < 0) { printf("%s: read_sr fail: %x\n", __func__, sr); return -1; } if ((sr & (SR_BP0 | SR_BP1 | SR_BP2)) != 0) { sr = 0; raspi_write_sr(&sr); } }
static int raspi_wait_sleep_ready(int sleep_ms) { int count; int sr = 0; /* one chip guarantees max 5 msec wait here after page writes, * but potentially three seconds (!) after page erase. */ for (count = 0; count < ((sleep_ms+1)*100); count++) { if ((raspi_read_sr((u8 *)&sr)) < 0) break; else if (!(sr & (SR_WIP | SR_EPE))) { return 0; } usleep(100); } printk("%s: read_sr fail: %x\n", __func__, sr); return -EIO; }
/* * Service routine to read status register until ready, or timeout occurs. * Returns non-zero if error. */ static int raspi_wait_ready(int sleep_ms) { int count; int sr = 0; //udelay(1000 * sleep_ms); /* one chip guarantees max 5 msec wait here after page writes, * but potentially three seconds (!) after page erase. */ for (count = 0; count < ((sleep_ms+1) *1000); count++) { if ((raspi_read_sr((u8 *)&sr)) < 0) break; else if (!(sr & (SR_WIP | SR_EPE | SR_WEL))) { return 0; } udelay(500); /* REVISIT sometimes sleeping would be best */ } printf("%s: read_sr fail: %x\n", __func__, sr); return -1; }