void sfc_set_status_reg(unsigned regnum) { struct jz_sfc sfc; volatile unsigned int tmp; unsigned int data; unsigned char cmd_wdsr[3] = {0x01, 0x31, 0x11}; printf("coc -1\n"); sfc_write_enable(); printf("coc -2\n"); sfc.cmd = cmd_wdsr[regnum]; sfc.addr_len = 0; sfc.addr = 0; sfc.addr_plus = 0; sfc.dummy_byte = 0; sfc.daten = 1; // sfc.len = 1; sfc.len = 2; sfc.sfc_mode = 0; data = 0x0200; // data = 0x2; sfc_set_transfer(&sfc,0); printf("coc -3\n"); jz_sfc_writel(START,SFC_TRIG); sfc_write_data(&data, 1); while (!(jz_nor_read_status(1) & 0x2/*STATUS_WIP*/)) { } }
/** * jz_nor_wait_busy - Wait SPI NOR Write In Process finished * @flash: jz_nor_read_status needed. * @max_busytime: Max Busy times, unit: ms. * * SPI NOR WIP bit only be set 1, while nor WRSR, PP, CE, SE and BE. */ static int jz_nor_wait_busy(struct jz_nor_local *flash, u32 max_busytime) { int this_cpu = smp_processor_id(); u64 t_start = cpu_clock(this_cpu); /* Nano seconds get */ u64 m_sec = 0; while ((jz_nor_read_status(flash, 0) & STATUS_WIP)) { m_sec = cpu_clock(this_cpu) - t_start; do_div(m_sec, 1000000); if ((u32)m_sec >= max_busytime) { dev_dbg(&flash->spi->dev, "WIP wait busy timeout, max_busytime: %d ms\n", max_busytime); break; } } return (u32)m_sec < max_busytime ? 0 : -EIO; }