Skip to content

Commit 6ece49c

Browse files
cristiccbroonie
authored andcommitted
spi: amd: Limit max transfer and message size
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/20220621213819.262537-1-cristian.ciocaltea@collabora.com Reported-by: Anastasios Vacharakis <vacharakis@o2mail.de> Fixes: bbb336f ("spi: spi-amd: Add AMD SPI controller driver support") Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com> Link: https://lore.kernel.org/r/20220706100626.1234731-2-cristian.ciocaltea@collabora.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent f2906aa commit 6ece49c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/spi/spi-amd.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#define AMD_SPI_RX_COUNT_REG 0x4B
3434
#define AMD_SPI_STATUS_REG 0x4C
3535

36+
#define AMD_SPI_FIFO_SIZE 70
3637
#define AMD_SPI_MEM_SIZE 200
3738

3839
/* M_CMD OP codes for SPI */
@@ -270,6 +271,11 @@ static int amd_spi_master_transfer(struct spi_master *master,
270271
return 0;
271272
}
272273

274+
static size_t amd_spi_max_transfer_size(struct spi_device *spi)
275+
{
276+
return AMD_SPI_FIFO_SIZE;
277+
}
278+
273279
static int amd_spi_probe(struct platform_device *pdev)
274280
{
275281
struct device *dev = &pdev->dev;
@@ -302,6 +308,8 @@ static int amd_spi_probe(struct platform_device *pdev)
302308
master->flags = SPI_MASTER_HALF_DUPLEX;
303309
master->setup = amd_spi_master_setup;
304310
master->transfer_one_message = amd_spi_master_transfer;
311+
master->max_transfer_size = amd_spi_max_transfer_size;
312+
master->max_message_size = amd_spi_max_transfer_size;
305313

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

0 commit comments

Comments
 (0)