Ejemplo n.º 1
0
static int qspi_flash_read(qspi_flash_t *flash, unsigned int from,
			   void *buf, unsigned int buf_len)
{
	qspi_command_t cmd;

	if (buf && !buf_len)
		return 0;

	memset(&cmd, 0, sizeof(cmd));
	cmd.enable.bits.instruction = 1;
	cmd.enable.bits.address = flash->addr_width;
	cmd.enable.bits.mode = (flash->num_mode_cycles > 0);
	cmd.enable.bits.dummy = (flash->num_dummy_cycles > 0);
	cmd.enable.bits.data = 1;
	cmd.instruction = flash->read_opcode;
	cmd.address = from;
	cmd.mode = (buf) ? flash->normal_mode : flash->continuous_read_mode;
	cmd.num_mode_cycles = flash->num_mode_cycles;
	cmd.num_dummy_cycles = flash->num_dummy_cycles;
	cmd.rx_buf = buf;
	cmd.buf_len = buf_len;
	cmd.protocol = flash->read_proto;
	cmd.transfer_type = QSPI_TFRTYPE_READ_MEMORY;
	return qspi_send_command(&cmd);
}
Ejemplo n.º 2
0
static int qspi_flash_erase(qspi_flash_t *flash, unsigned int address)
{
	qspi_command_t cmd;

	memset(&cmd, 0, sizeof(cmd));
	cmd.enable.bits.instruction = 1;
	cmd.enable.bits.address = flash->addr_width;
	cmd.instruction = flash->erase_opcode;
	cmd.address = address;
	cmd.protocol = flash->erase_proto;
	cmd.transfer_type = QSPI_TFRTYPE_WRITE;
	return qspi_send_command(&cmd);
}
Ejemplo n.º 3
0
static int qspi_flash_write_reg(qspi_flash_t *flash, unsigned char opcode,
				const void *buf, unsigned int buf_len)
{
	qspi_command_t cmd;

	memset(&cmd, 0, sizeof(cmd));
	cmd.enable.bits.instruction = 1;
	cmd.enable.bits.data = (buf && buf_len);
	cmd.instruction = opcode;
	cmd.tx_buf = buf;
	cmd.buf_len = buf_len;
	cmd.protocol = flash->reg_proto;
	cmd.transfer_type = QSPI_TFRTYPE_WRITE;
	return qspi_send_command(&cmd);
}
Ejemplo n.º 4
0
static void qspi_flash_write_en_vol_config(unsigned char value)
{
	qspi_frame_t *frame = &qspi_frame;
	qspi_data_t *data = &qspi_data;

	qspi_init_frame(frame);
	frame->instruction = CMD_WRITE_EN_VOLATILE_CONFIG_REG;
	frame->tansfer_type = write;
	frame->protocol = spi_mode;

	qspi_init_data_buff(data, qspi_buff);
	data->buffer[0] = value;
	data->size = 1;
	data->direction = DATA_DIR_WRITE;

	qspi_send_command(frame, data);
}
Ejemplo n.º 5
0
static unsigned int qspi_flash_read_en_vol_config(void)
{
	qspi_frame_t *frame = &qspi_frame;
	qspi_data_t *data = &qspi_data;
	
	qspi_init_frame(frame);
	frame->instruction = CMD_READ_EN_VOLATILE_CONFIG_REG;
	frame->tansfer_type = read;
	frame->protocol = spi_mode;

	qspi_init_data_buff(data, qspi_buff);
	data->size = 1;
	data->direction = DATA_DIR_READ;

	qspi_send_command(frame, data);

	return data->buffer[0];
}
Ejemplo n.º 6
0
static unsigned char qspi_flash_read_status_reg(void)
{
	qspi_frame_t *frame = &qspi_frame;
	qspi_data_t *data = &qspi_data;

	qspi_init_frame(frame);
	frame->instruction = CMD_READ_STATUS_REG;
	frame->tansfer_type = read;
	frame->protocol = spi_mode;

	qspi_init_data_buff(data, qspi_buff);
	data->size = 1;
	data->direction = DATA_DIR_READ;

	qspi_send_command(frame, data);

	return data->buffer[0];
}
Ejemplo n.º 7
0
static int qspi_flash_enable_write(void)
{
	qspi_frame_t *frame = &qspi_frame;
	unsigned char status;

	qspi_init_frame(frame);
	frame->instruction = CMD_WRITE_ENABLE;
	frame->tansfer_type = read;
	frame->protocol = spi_mode;

	qspi_send_command(frame, 0);

	status = qspi_flash_read_status_reg();
	if (status & STATUS_WRITE_ENABLE_SET)
		return 0;
	else
		return -1;
}
Ejemplo n.º 8
0
static int qspi_flash_read_image(struct image_info *image)
{
	qspi_frame_t *frame = &qspi_frame;
	qspi_data_t *data = &qspi_data;

	qspi_init_frame(frame);
	frame->instruction = CMD_QUAD_IO_FAST_READ;
	frame->tansfer_type = read_memory;
	frame->has_address = 1;
	frame->address = image->offset;
	frame->continue_read = 0;
	frame->dummy_cycles = 10;
	frame->protocol = quad;

	data->buffer = (unsigned int *)image->dest;
	data->size = image->length;
	data->direction = DATA_DIR_READ;

	return qspi_send_command(frame, data);
}
Ejemplo n.º 9
0
static int qspi_flash_program(qspi_flash_t *flash, unsigned int to,
			      const void *buf, unsigned int buf_len)
{
	qspi_command_t cmd;

	if (!buf_len)
		return 0;

	memset(&cmd, 0, sizeof(cmd));
	cmd.enable.bits.instruction = 1;
	cmd.enable.bits.address = flash->addr_width;
	cmd.enable.bits.data = 1;
	cmd.instruction = flash->program_opcode;
	cmd.address = to;
	cmd.tx_buf = buf;
	cmd.buf_len = buf_len;
	cmd.protocol = flash->program_proto;
	cmd.transfer_type = QSPI_TFRTYPE_WRITE_MEMORY;
	return qspi_send_command(&cmd);
}
Ejemplo n.º 10
0
static void qspi_flash_read_jedec_id(void)
{
	qspi_frame_t *frame = &qspi_frame;
	qspi_data_t *data = &qspi_data;

	qspi_init_frame(frame);
	frame->instruction = CMD_READ_ID;
	frame->tansfer_type = read;
	frame->protocol = spi_mode;

	qspi_init_data_buff(data, qspi_buff);
	data->size = 3;
	data->direction = DATA_DIR_READ;

	qspi_send_command(frame, data);

	dbg_info("QSPI Flash: Manufacturer and Device ID: %d %d %d\n",
				data->buffer[0] & 0xff,
				(data->buffer[0] >> 8) & 0xff,
				(data->buffer[0] >> 16) & 0xff);
}