Skip to content

Commit 145d61c

Browse files
RajuRangojubroonie
authored andcommitted
spi: spi_amd: Add support for HID2 SPI controller
AMD SoC has HID2 SPI controller in addition to the existing SPI0 controller(AMDI0062). Add HID2 SPI controller's ACPI ID AMDI0063 with its version ID to the list of supported devices. Use the version ID to differentiate the register offsets. And, the AMD HID2 SPI controller supports DMA read, allowing for up to 4 KB of data to be read in single transaction. Update the SPI-MEM support function to reflect this capability. Co-developed-by: Krishnamoorthi M <[email protected]> Signed-off-by: Krishnamoorthi M <[email protected]> Co-developed-by: Akshata MukundShetty <[email protected]> Signed-off-by: Akshata MukundShetty <[email protected]> Signed-off-by: Raju Rangoju <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent d97735d commit 145d61c

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

drivers/spi/spi-amd.c

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#define AMD_SPI_FIFO_SIZE 70
3939
#define AMD_SPI_MEM_SIZE 200
4040
#define AMD_SPI_MAX_DATA 64
41+
#define AMD_SPI_HID2_DMA_SIZE 4096
4142

4243
#define AMD_SPI_ENA_REG 0x20
4344
#define AMD_SPI_ALT_SPD_SHIFT 20
@@ -70,10 +71,12 @@
7071
* enum amd_spi_versions - SPI controller versions
7172
* @AMD_SPI_V1: AMDI0061 hardware version
7273
* @AMD_SPI_V2: AMDI0062 hardware version
74+
* @AMD_HID2_SPI: AMDI0063 hardware version
7375
*/
7476
enum amd_spi_versions {
7577
AMD_SPI_V1 = 1,
7678
AMD_SPI_V2,
79+
AMD_HID2_SPI,
7780
};
7881

7982
enum amd_spi_speed {
@@ -182,6 +185,7 @@ static int amd_spi_set_opcode(struct amd_spi *amd_spi, u8 cmd_opcode)
182185
AMD_SPI_OPCODE_MASK);
183186
return 0;
184187
case AMD_SPI_V2:
188+
case AMD_HID2_SPI:
185189
amd_spi_writereg8(amd_spi, AMD_SPI_OPCODE_REG, cmd_opcode);
186190
return 0;
187191
default:
@@ -209,6 +213,7 @@ static int amd_spi_busy_wait(struct amd_spi *amd_spi)
209213
reg = AMD_SPI_CTRL0_REG;
210214
break;
211215
case AMD_SPI_V2:
216+
case AMD_HID2_SPI:
212217
reg = AMD_SPI_STATUS_REG;
213218
break;
214219
default:
@@ -234,6 +239,7 @@ static int amd_spi_execute_opcode(struct amd_spi *amd_spi)
234239
AMD_SPI_EXEC_CMD);
235240
return 0;
236241
case AMD_SPI_V2:
242+
case AMD_HID2_SPI:
237243
/* Trigger the command execution */
238244
amd_spi_setclear_reg8(amd_spi, AMD_SPI_CMD_TRIGGER_REG,
239245
AMD_SPI_TRIGGER_CMD, AMD_SPI_TRIGGER_CMD);
@@ -375,6 +381,7 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi,
375381
case AMD_SPI_V1:
376382
break;
377383
case AMD_SPI_V2:
384+
case AMD_HID2_SPI:
378385
amd_spi_clear_chip(amd_spi, spi_get_chipselect(message->spi, 0));
379386
break;
380387
default:
@@ -418,15 +425,29 @@ static inline bool amd_is_spi_read_cmd(const u16 op)
418425
static bool amd_spi_supports_op(struct spi_mem *mem,
419426
const struct spi_mem_op *op)
420427
{
428+
struct amd_spi *amd_spi = spi_controller_get_devdata(mem->spi->controller);
429+
421430
/* bus width is number of IO lines used to transmit */
422-
if (op->cmd.buswidth > 1 || op->addr.buswidth > 4 || op->data.nbytes > AMD_SPI_MAX_DATA)
431+
if (op->cmd.buswidth > 1 || op->addr.buswidth > 4)
423432
return false;
424433

425434
/* AMD SPI controllers support quad mode only for read operations */
426435
if (amd_is_spi_read_cmd(op->cmd.opcode)) {
427436
if (op->data.buswidth > 4)
428437
return false;
429-
} else if (op->data.buswidth > 1) {
438+
439+
/*
440+
* HID2 SPI controller supports DMA read up to 4K bytes and
441+
* doesn't support 4-byte address commands.
442+
*/
443+
if (amd_spi->version == AMD_HID2_SPI) {
444+
if (amd_is_spi_read_cmd_4b(op->cmd.opcode) ||
445+
op->data.nbytes > AMD_SPI_HID2_DMA_SIZE)
446+
return false;
447+
} else if (op->data.nbytes > AMD_SPI_MAX_DATA) {
448+
return false;
449+
}
450+
} else if (op->data.buswidth > 1 || op->data.nbytes > AMD_SPI_MAX_DATA) {
430451
return false;
431452
}
432453

@@ -435,7 +456,19 @@ static bool amd_spi_supports_op(struct spi_mem *mem,
435456

436457
static int amd_spi_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
437458
{
438-
op->data.nbytes = clamp_val(op->data.nbytes, 0, AMD_SPI_MAX_DATA);
459+
struct amd_spi *amd_spi = spi_controller_get_devdata(mem->spi->controller);
460+
461+
/*
462+
* HID2 SPI controller DMA read mode supports reading up to 4k
463+
* bytes in single transaction, where as SPI0 and HID2 SPI
464+
* controller index mode supports maximum of 64 bytes in a single
465+
* transaction.
466+
*/
467+
if (amd_spi->version == AMD_HID2_SPI && amd_is_spi_read_cmd(op->cmd.opcode))
468+
op->data.nbytes = clamp_val(op->data.nbytes, 0, AMD_SPI_HID2_DMA_SIZE);
469+
else
470+
op->data.nbytes = clamp_val(op->data.nbytes, 0, AMD_SPI_MAX_DATA);
471+
439472
return 0;
440473
}
441474

@@ -592,7 +625,7 @@ static int amd_spi_probe(struct platform_device *pdev)
592625
amd_spi->version = (uintptr_t) device_get_match_data(dev);
593626

594627
/* Initialize the spi_controller fields */
595-
host->bus_num = 0;
628+
host->bus_num = (amd_spi->version == AMD_HID2_SPI) ? 2 : 0;
596629
host->num_chipselect = 4;
597630
host->mode_bits = SPI_TX_DUAL | SPI_TX_QUAD | SPI_RX_DUAL | SPI_RX_QUAD;
598631
host->flags = SPI_CONTROLLER_HALF_DUPLEX;
@@ -616,6 +649,7 @@ static int amd_spi_probe(struct platform_device *pdev)
616649
static const struct acpi_device_id spi_acpi_match[] = {
617650
{ "AMDI0061", AMD_SPI_V1 },
618651
{ "AMDI0062", AMD_SPI_V2 },
652+
{ "AMDI0063", AMD_HID2_SPI },
619653
{},
620654
};
621655
MODULE_DEVICE_TABLE(acpi, spi_acpi_match);

0 commit comments

Comments
 (0)