Example #1
0
/*
 * write status register
 */
static int raspi_write_sr(u8 *val)
{
	ssize_t retval;
	u8 code = OPCODE_WRSR;

	retval = spic_write(&code, 1, val, 1);
	if (retval != 1) {
		printf("%s: ret: %x\n", __func__, retval);
		return -1;
	}
	return 0;
}
Example #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;
	}
Example #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;
    }
Example #4
0
/*
 * Set write enable latch with Write Enable command.
 * Returns negative if error occurred.
 */
static inline int raspi_write_enable(void)
{
	u8 code = OPCODE_WREN;

	return spic_write(&code, 1, NULL, 0);
}