mirror of
https://git.proxmox.com/git/mirror_ubuntu-kernels.git
synced 2025-12-16 10:38:07 +00:00
mtd: spi-nor: split spi_nor_spimem_xfer_data()
spi_nor_spimem_xfer_data() being a helper function for the data reads/
writes contains 3 fragments that depend on the data direction; and I'm
going to add another one to call the SPI dirmap API...
I think this function should be split so that the common fragments are
put into 2 functions, spi_nor_spimem_bounce() and spi_nor_spimem_exec_op()
called from spi_nor_spimem_{read|write}_data(), and the data direction
dependent bits moved back into those read/write functions -- that way we
would be able to avoid *goto*s otherwise needed in the next patch adding
the SPI dirmap support...
Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
This commit is contained in:
parent
8c79fa6c44
commit
b7ad6be2ee
@ -246,55 +246,45 @@ struct flash_info {
|
|||||||
#define JEDEC_MFR(info) ((info)->id[0])
|
#define JEDEC_MFR(info) ((info)->id[0])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* spi_nor_spimem_xfer_data() - helper function to read/write data to
|
* spi_nor_spimem_bounce() - check if a bounce buffer is needed for the data
|
||||||
* flash's memory region
|
* transfer
|
||||||
* @nor: pointer to 'struct spi_nor'
|
* @nor: pointer to 'struct spi_nor'
|
||||||
* @op: pointer to 'struct spi_mem_op' template for transfer
|
* @op: pointer to 'struct spi_mem_op' template for transfer
|
||||||
*
|
*
|
||||||
* Return: number of bytes transferred on success, -errno otherwise
|
* If we have to use the bounce buffer, the data field in @op will be updated.
|
||||||
|
*
|
||||||
|
* Return: true if the bounce buffer is needed, false if not
|
||||||
*/
|
*/
|
||||||
static ssize_t spi_nor_spimem_xfer_data(struct spi_nor *nor,
|
static bool spi_nor_spimem_bounce(struct spi_nor *nor, struct spi_mem_op *op)
|
||||||
struct spi_mem_op *op)
|
|
||||||
{
|
{
|
||||||
bool usebouncebuf = false;
|
/* op->data.buf.in occupies the same memory as op->data.buf.out */
|
||||||
void *rdbuf = NULL;
|
if (object_is_on_stack(op->data.buf.in) ||
|
||||||
const void *buf;
|
!virt_addr_valid(op->data.buf.in)) {
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (op->data.dir == SPI_MEM_DATA_IN)
|
|
||||||
buf = op->data.buf.in;
|
|
||||||
else
|
|
||||||
buf = op->data.buf.out;
|
|
||||||
|
|
||||||
if (object_is_on_stack(buf) || !virt_addr_valid(buf))
|
|
||||||
usebouncebuf = true;
|
|
||||||
|
|
||||||
if (usebouncebuf) {
|
|
||||||
if (op->data.nbytes > nor->bouncebuf_size)
|
if (op->data.nbytes > nor->bouncebuf_size)
|
||||||
op->data.nbytes = nor->bouncebuf_size;
|
op->data.nbytes = nor->bouncebuf_size;
|
||||||
|
op->data.buf.in = nor->bouncebuf;
|
||||||
if (op->data.dir == SPI_MEM_DATA_IN) {
|
return true;
|
||||||
rdbuf = op->data.buf.in;
|
|
||||||
op->data.buf.in = nor->bouncebuf;
|
|
||||||
} else {
|
|
||||||
op->data.buf.out = nor->bouncebuf;
|
|
||||||
memcpy(nor->bouncebuf, buf,
|
|
||||||
op->data.nbytes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = spi_mem_adjust_op_size(nor->spimem, op);
|
return false;
|
||||||
if (ret)
|
}
|
||||||
return ret;
|
|
||||||
|
|
||||||
ret = spi_mem_exec_op(nor->spimem, op);
|
/**
|
||||||
if (ret)
|
* spi_nor_spimem_exec_op() - execute a memory operation
|
||||||
return ret;
|
* @nor: pointer to 'struct spi_nor'
|
||||||
|
* @op: pointer to 'struct spi_mem_op' template for transfer
|
||||||
|
*
|
||||||
|
* Return: 0 on success, -error otherwise.
|
||||||
|
*/
|
||||||
|
static int spi_nor_spimem_exec_op(struct spi_nor *nor, struct spi_mem_op *op)
|
||||||
|
{
|
||||||
|
int error;
|
||||||
|
|
||||||
if (usebouncebuf && op->data.dir == SPI_MEM_DATA_IN)
|
error = spi_mem_adjust_op_size(nor->spimem, op);
|
||||||
memcpy(rdbuf, nor->bouncebuf, op->data.nbytes);
|
if (error)
|
||||||
|
return error;
|
||||||
|
|
||||||
return op->data.nbytes;
|
return spi_mem_exec_op(nor->spimem, op);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -315,6 +305,8 @@ static ssize_t spi_nor_spimem_read_data(struct spi_nor *nor, loff_t from,
|
|||||||
SPI_MEM_OP_ADDR(nor->addr_width, from, 1),
|
SPI_MEM_OP_ADDR(nor->addr_width, from, 1),
|
||||||
SPI_MEM_OP_DUMMY(nor->read_dummy, 1),
|
SPI_MEM_OP_DUMMY(nor->read_dummy, 1),
|
||||||
SPI_MEM_OP_DATA_IN(len, buf, 1));
|
SPI_MEM_OP_DATA_IN(len, buf, 1));
|
||||||
|
bool usebouncebuf;
|
||||||
|
int error;
|
||||||
|
|
||||||
/* get transfer protocols. */
|
/* get transfer protocols. */
|
||||||
op.cmd.buswidth = spi_nor_get_protocol_inst_nbits(nor->read_proto);
|
op.cmd.buswidth = spi_nor_get_protocol_inst_nbits(nor->read_proto);
|
||||||
@ -325,7 +317,16 @@ static ssize_t spi_nor_spimem_read_data(struct spi_nor *nor, loff_t from,
|
|||||||
/* convert the dummy cycles to the number of bytes */
|
/* convert the dummy cycles to the number of bytes */
|
||||||
op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8;
|
op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8;
|
||||||
|
|
||||||
return spi_nor_spimem_xfer_data(nor, &op);
|
usebouncebuf = spi_nor_spimem_bounce(nor, &op);
|
||||||
|
|
||||||
|
error = spi_nor_spimem_exec_op(nor, &op);
|
||||||
|
if (error)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
if (usebouncebuf)
|
||||||
|
memcpy(buf, op.data.buf.in, op.data.nbytes);
|
||||||
|
|
||||||
|
return op.data.nbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -364,6 +365,7 @@ static ssize_t spi_nor_spimem_write_data(struct spi_nor *nor, loff_t to,
|
|||||||
SPI_MEM_OP_ADDR(nor->addr_width, to, 1),
|
SPI_MEM_OP_ADDR(nor->addr_width, to, 1),
|
||||||
SPI_MEM_OP_NO_DUMMY,
|
SPI_MEM_OP_NO_DUMMY,
|
||||||
SPI_MEM_OP_DATA_OUT(len, buf, 1));
|
SPI_MEM_OP_DATA_OUT(len, buf, 1));
|
||||||
|
int error;
|
||||||
|
|
||||||
op.cmd.buswidth = spi_nor_get_protocol_inst_nbits(nor->write_proto);
|
op.cmd.buswidth = spi_nor_get_protocol_inst_nbits(nor->write_proto);
|
||||||
op.addr.buswidth = spi_nor_get_protocol_addr_nbits(nor->write_proto);
|
op.addr.buswidth = spi_nor_get_protocol_addr_nbits(nor->write_proto);
|
||||||
@ -372,7 +374,14 @@ static ssize_t spi_nor_spimem_write_data(struct spi_nor *nor, loff_t to,
|
|||||||
if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second)
|
if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second)
|
||||||
op.addr.nbytes = 0;
|
op.addr.nbytes = 0;
|
||||||
|
|
||||||
return spi_nor_spimem_xfer_data(nor, &op);
|
if (spi_nor_spimem_bounce(nor, &op))
|
||||||
|
memcpy(nor->bouncebuf, buf, op.data.nbytes);
|
||||||
|
|
||||||
|
error = spi_nor_spimem_exec_op(nor, &op);
|
||||||
|
if (error)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
return op.data.nbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user