Skip to content

Commit 769c16f

Browse files
RajuRangojubroonie
authored andcommitted
spi: spi_amd: Enable dual and quad I/O modes
The current spi_amd driver only supports single I/O mode, despite the AMD SPI controller's capability for dual and quad I/O modes for read operations. And AMD SPI0 controller has limited support for quad mode write operations. Update the SPI-MEM support function to reflect these hardware capabilities. Co-developed-by: Krishnamoorthi M <krishnamoorthi.m@amd.com> Signed-off-by: Krishnamoorthi M <krishnamoorthi.m@amd.com> Co-developed-by: Akshata MukundShetty <akshata.mukundshetty@amd.com> Signed-off-by: Akshata MukundShetty <akshata.mukundshetty@amd.com> Signed-off-by: Raju Rangoju <Raju.Rangoju@amd.com> Link: https://patch.msgid.link/20240925133644.2922359-3-Raju.Rangoju@amd.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent d6dc8b7 commit 769c16f

1 file changed

Lines changed: 54 additions & 3 deletions

File tree

drivers/spi/spi-amd.c

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@
5050
#define AMD_SPI_MAX_HZ 100000000
5151
#define AMD_SPI_MIN_HZ 800000
5252

53+
/* SPI read command opcodes */
54+
#define AMD_SPI_OP_READ 0x03 /* Read data bytes (low frequency) */
55+
#define AMD_SPI_OP_READ_FAST 0x0b /* Read data bytes (high frequency) */
56+
#define AMD_SPI_OP_READ_1_1_2 0x3b /* Read data bytes (Dual Output SPI) */
57+
#define AMD_SPI_OP_READ_1_2_2 0xbb /* Read data bytes (Dual I/O SPI) */
58+
#define AMD_SPI_OP_READ_1_1_4 0x6b /* Read data bytes (Quad Output SPI) */
59+
#define AMD_SPI_OP_READ_1_4_4 0xeb /* Read data bytes (Quad I/O SPI) */
60+
61+
/* SPI read command opcodes - 4B address */
62+
#define AMD_SPI_OP_READ_FAST_4B 0x0c /* Read data bytes (high frequency) */
63+
#define AMD_SPI_OP_READ_1_1_2_4B 0x3c /* Read data bytes (Dual Output SPI) */
64+
#define AMD_SPI_OP_READ_1_2_2_4B 0xbc /* Read data bytes (Dual I/O SPI) */
65+
#define AMD_SPI_OP_READ_1_1_4_4B 0x6c /* Read data bytes (Quad Output SPI) */
66+
#define AMD_SPI_OP_READ_1_4_4_4B 0xec /* Read data bytes (Quad I/O SPI) */
67+
5368
/**
5469
* enum amd_spi_versions - SPI controller versions
5570
* @AMD_SPI_V1: AMDI0061 hardware version
@@ -360,14 +375,50 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi,
360375
return message->status;
361376
}
362377

378+
static inline bool amd_is_spi_read_cmd_4b(const u16 op)
379+
{
380+
switch (op) {
381+
case AMD_SPI_OP_READ_FAST_4B:
382+
case AMD_SPI_OP_READ_1_1_2_4B:
383+
case AMD_SPI_OP_READ_1_2_2_4B:
384+
case AMD_SPI_OP_READ_1_1_4_4B:
385+
case AMD_SPI_OP_READ_1_4_4_4B:
386+
return true;
387+
default:
388+
return false;
389+
}
390+
}
391+
392+
static inline bool amd_is_spi_read_cmd(const u16 op)
393+
{
394+
switch (op) {
395+
case AMD_SPI_OP_READ:
396+
case AMD_SPI_OP_READ_FAST:
397+
case AMD_SPI_OP_READ_1_1_2:
398+
case AMD_SPI_OP_READ_1_2_2:
399+
case AMD_SPI_OP_READ_1_1_4:
400+
case AMD_SPI_OP_READ_1_4_4:
401+
return true;
402+
default:
403+
return amd_is_spi_read_cmd_4b(op);
404+
}
405+
}
406+
363407
static bool amd_spi_supports_op(struct spi_mem *mem,
364408
const struct spi_mem_op *op)
365409
{
366410
/* bus width is number of IO lines used to transmit */
367-
if (op->cmd.buswidth > 1 || op->addr.buswidth > 1 ||
368-
op->data.buswidth > 1 || op->data.nbytes > AMD_SPI_MAX_DATA)
411+
if (op->cmd.buswidth > 1 || op->addr.buswidth > 4 || op->data.nbytes > AMD_SPI_MAX_DATA)
369412
return false;
370413

414+
/* AMD SPI controllers support quad mode only for read operations */
415+
if (amd_is_spi_read_cmd(op->cmd.opcode)) {
416+
if (op->data.buswidth > 4)
417+
return false;
418+
} else if (op->data.buswidth > 1) {
419+
return false;
420+
}
421+
371422
return spi_mem_default_supports_op(mem, op);
372423
}
373424

@@ -514,7 +565,7 @@ static int amd_spi_probe(struct platform_device *pdev)
514565
/* Initialize the spi_controller fields */
515566
host->bus_num = 0;
516567
host->num_chipselect = 4;
517-
host->mode_bits = 0;
568+
host->mode_bits = SPI_TX_DUAL | SPI_TX_QUAD | SPI_RX_DUAL | SPI_RX_QUAD;
518569
host->flags = SPI_CONTROLLER_HALF_DUPLEX;
519570
host->max_speed_hz = AMD_SPI_MAX_HZ;
520571
host->min_speed_hz = AMD_SPI_MIN_HZ;

0 commit comments

Comments
 (0)