示例#1
0
static int raspi_4byte_mode(int enable)
{
    ssize_t retval;
    u8 code;

    raspi_wait_ready(1);

    if (enable)
        code = 0xB7; /* EN4B, enter 4-byte mode */
    else
        code = 0xE9; /* EX4B, exit 4-byte mode */
    retval = spic_read(&code, 1, 0, 0);
    if (retval != 0) {
        printk("%s: ret: %x\n", __func__, retval);
        return -1;
    }
    return 0;
}
示例#2
0
/*
 * Erase one sector of flash memory at offset ``offset'' which is any
 * address within the sector which should be erased.
 *
 * Returns 0 if successful, non-zero otherwise.
 */
static int raspi_erase_sector(u32 offset)
{
	u8 buf[5];

	/* Wait until finished previous write command. */
	if (raspi_wait_ready(950))
		return -1;

	/* Send write enable, then erase commands. */
	raspi_write_enable();
	raspi_unprotect();

#ifdef MX_4B_MODE
	if (spi_chip_info->addr4b) {
		raspi_4byte_mode(1);
		buf[0] = OPCODE_SE;
		buf[1] = offset >> 24;
		buf[2] = offset >> 16;
		buf[3] = offset >> 8;
		buf[4] = offset;
		spic_write(buf, 5, 0 , 0);
		raspi_4byte_mode(0);
		return 0;
	}
示例#3
0
/*
 * Erase one sector of flash memory at offset ``offset'' which is any
 * address within the sector which should be erased.
 *
 * Returns 0 if successful, non-zero otherwise.
 */
static int raspi_erase_sector(u32 offset)
{
    /* Wait until finished previous write command. */
    if (raspi_wait_ready(10))
        return -EIO;

    /* Send write enable, then erase commands. */
    raspi_write_enable();
    raspi_unprotect();

#ifdef MX_4B_MODE
    if (flash->chip->addr4b) {
        flash->command[0] = OPCODE_SE;
        flash->command[1] = offset >> 24;
        flash->command[2] = offset >> 16;
        flash->command[3] = offset >> 8;
        flash->command[4] = offset;
        raspi_4byte_mode(1);
        spic_write(flash->command, 5, 0 , 0);
        raspi_wait_sleep_ready(950);
        raspi_4byte_mode(0);
        raspi_write_disable();
        return 0;
    }