Skip to content

Commit

Permalink
spi: amd: Limit max transfer and message size
Browse files Browse the repository at this point in the history
[ Upstream commit 6ece49c ]

Enabling the SPI CS35L41 audio codec driver for Steam Deck [1]
revealed a problem with the current AMD SPI controller driver
implementation, consisting of an unrecoverable system hang.

The issue can be prevented if we ensure the max transfer size
and the max message size do not exceed the FIFO buffer size.

According to the implementation of the downstream driver, the
AMD SPI controller is not able to handle more than 70 bytes per
transfer, which corresponds to the size of the FIFO buffer.

Hence, let's fix this by setting the SPI limits mentioned above.

[1] https://lore.kernel.org/r/[email protected]

Reported-by: Anastasios Vacharakis <[email protected]>
Fixes: bbb336f ("spi: spi-amd: Add AMD SPI controller driver support")
Signed-off-by: Cristian Ciocaltea <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
cristicc authored and gregkh committed Jul 21, 2022
1 parent 28ad09b commit 2bcb2e4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/spi/spi-amd.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define AMD_SPI_RX_COUNT_REG 0x4B
#define AMD_SPI_STATUS_REG 0x4C

#define AMD_SPI_FIFO_SIZE 70
#define AMD_SPI_MEM_SIZE 200

/* M_CMD OP codes for SPI */
Expand Down Expand Up @@ -245,6 +246,11 @@ static int amd_spi_master_transfer(struct spi_master *master,
return 0;
}

static size_t amd_spi_max_transfer_size(struct spi_device *spi)
{
return AMD_SPI_FIFO_SIZE;
}

static int amd_spi_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
Expand Down Expand Up @@ -275,6 +281,8 @@ static int amd_spi_probe(struct platform_device *pdev)
master->flags = SPI_MASTER_HALF_DUPLEX;
master->setup = amd_spi_master_setup;
master->transfer_one_message = amd_spi_master_transfer;
master->max_transfer_size = amd_spi_max_transfer_size;
master->max_message_size = amd_spi_max_transfer_size;

/* Register the controller with SPI framework */
err = devm_spi_register_master(dev, master);
Expand Down

0 comments on commit 2bcb2e4

Please sign in to comment.