drivers/spi: support cmd opcode deduction for spi_crop_chunk()
spi_crop_chunk() currently supports deducting the command length when determining maximum payload size in a transaction. Add support for deducting just the opcode part of the command by replacing deduct_cmd_len field to generic flags field. The two enums supported drive the logic within spi_crop_chunk(): SPI_CNTRLR_DEDUCT_CMD_LEN SPI_CNTRLR_DEDUCT_OPCODE_LEN All existing users of deduct_cmd_len were converted to using the flags field. BUG=b:65485690 Change-Id: I771fba684f0ed76ffdc8573aa10f775070edc691 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/23491 Reviewed-by: Furquan Shaikh <furquan@google.com> Reviewed-by: Justin TerAvest <teravest@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
3c0d7cfb94
commit
1fcc9f3125
|
@ -93,15 +93,24 @@ unsigned int spi_crop_chunk(const struct spi_slave *slave, unsigned int cmd_len,
|
|||
{
|
||||
const struct spi_ctrlr *ctrlr = slave->ctrlr;
|
||||
unsigned int ctrlr_max;
|
||||
bool deduct_cmd_len;
|
||||
bool deduct_opcode_len;
|
||||
|
||||
if (!ctrlr)
|
||||
return 0;
|
||||
|
||||
deduct_cmd_len = !!(ctrlr->flags & SPI_CNTRLR_DEDUCT_CMD_LEN);
|
||||
deduct_opcode_len = !!(ctrlr->flags & SPI_CNTRLR_DEDUCT_OPCODE_LEN);
|
||||
ctrlr_max = ctrlr->max_xfer_size;
|
||||
|
||||
assert (ctrlr_max != 0);
|
||||
|
||||
if (ctrlr->deduct_cmd_len && (ctrlr_max > cmd_len))
|
||||
/* Assume opcode is always one byte and deduct it from the cmd_len
|
||||
as the hardware has a separate register for the opcode. */
|
||||
if (deduct_opcode_len)
|
||||
cmd_len--;
|
||||
|
||||
if (deduct_cmd_len && (ctrlr_max > cmd_len))
|
||||
ctrlr_max -= cmd_len;
|
||||
|
||||
return min(ctrlr_max, buf_len);
|
||||
|
|
|
@ -97,6 +97,17 @@ struct spi_cfg {
|
|||
|
||||
struct spi_flash;
|
||||
|
||||
enum {
|
||||
/* Deduct the command length from the spi_crop_chunk() calculation for
|
||||
sizing a transaction. */
|
||||
SPI_CNTRLR_DEDUCT_CMD_LEN = 1 << 0,
|
||||
/* Remove the opcode size from the command length used in the
|
||||
spi_crop_chunk() calculation. Controllers which have a dedicated
|
||||
register for the command byte would set this flag which would
|
||||
allow the use of the maximum transfer size. */
|
||||
SPI_CNTRLR_DEDUCT_OPCODE_LEN = 1 << 1,
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
* Representation of a SPI controller.
|
||||
*
|
||||
|
@ -108,8 +119,7 @@ struct spi_flash;
|
|||
* max_xfer_size: Maximum transfer size supported by the controller
|
||||
* (0 = invalid,
|
||||
* SPI_CTRLR_DEFAULT_MAX_XFER_SIZE = unlimited)
|
||||
* deduct_cmd_len: Whether cmd_len should be deducted from max_xfer_size
|
||||
* when calculating max_data_size
|
||||
* flags: See SPI_CNTRLR_* enums above.
|
||||
*
|
||||
* Following member is provided by specialized SPI controllers that are
|
||||
* actually SPI flash controllers.
|
||||
|
@ -127,7 +137,7 @@ struct spi_ctrlr {
|
|||
int (*xfer_vector)(const struct spi_slave *slave,
|
||||
struct spi_op vectors[], size_t count);
|
||||
uint32_t max_xfer_size;
|
||||
bool deduct_cmd_len;
|
||||
uint32_t flags;
|
||||
int (*flash_probe)(const struct spi_slave *slave,
|
||||
struct spi_flash *flash);
|
||||
int (*flash_protect)(const struct spi_flash *flash,
|
||||
|
|
|
@ -193,7 +193,7 @@ static const struct spi_ctrlr spi_ctrlr = {
|
|||
.xfer = spi_ctrlr_xfer,
|
||||
.xfer_vector = spi_xfer_two_vectors,
|
||||
.max_xfer_size = SPI_FIFO_DEPTH,
|
||||
.deduct_cmd_len = true,
|
||||
.flags = SPI_CNTRLR_DEDUCT_CMD_LEN,
|
||||
};
|
||||
|
||||
const struct spi_ctrlr_buses spi_ctrlr_bus_map[] = {
|
||||
|
|
|
@ -290,7 +290,6 @@ BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_ENTRY, spi_init_cb, NULL);
|
|||
const struct spi_ctrlr spi_driver = {
|
||||
.xfer = xfer,
|
||||
.max_xfer_size = 64,
|
||||
.deduct_cmd_len = false,
|
||||
};
|
||||
|
||||
const struct spi_ctrlr_buses spi_ctrlr_bus_map[] = {
|
||||
|
|
|
@ -164,7 +164,7 @@ static const struct spi_ctrlr spi_ctrlr = {
|
|||
.xfer = spi_ctrlr_xfer,
|
||||
.xfer_vector = spi_xfer_two_vectors,
|
||||
.max_xfer_size = AMD_SB_SPI_TX_LEN,
|
||||
.deduct_cmd_len = true,
|
||||
.flags = SPI_CNTRLR_DEDUCT_CMD_LEN,
|
||||
};
|
||||
|
||||
const struct spi_ctrlr_buses spi_ctrlr_bus_map[] = {
|
||||
|
|
|
@ -155,7 +155,7 @@ static const struct spi_ctrlr spi_ctrlr = {
|
|||
.xfer = spi_ctrlr_xfer,
|
||||
.xfer_vector = spi_xfer_two_vectors,
|
||||
.max_xfer_size = AMD_SB_SPI_TX_LEN,
|
||||
.deduct_cmd_len = true,
|
||||
.flags = SPI_CNTRLR_DEDUCT_CMD_LEN,
|
||||
};
|
||||
|
||||
const struct spi_ctrlr_buses spi_ctrlr_bus_map[] = {
|
||||
|
|
|
@ -112,7 +112,7 @@ static const struct spi_ctrlr spi_ctrlr = {
|
|||
.xfer = spi_ctrlr_xfer,
|
||||
.xfer_vector = spi_xfer_two_vectors,
|
||||
.max_xfer_size = AMD_SB_SPI_TX_LEN,
|
||||
.deduct_cmd_len = true,
|
||||
.flags = SPI_CNTRLR_DEDUCT_CMD_LEN,
|
||||
};
|
||||
|
||||
const struct spi_ctrlr_buses spi_ctrlr_bus_map[] = {
|
||||
|
|
Loading…
Reference in New Issue