aboutsummaryrefslogtreecommitdiff
path: root/drivers/spi
diff options
context:
space:
mode:
authorChristophe Leroy2024-04-09 08:38:08 +0200
committerChristophe Leroy2024-04-18 15:47:46 +0200
commitea208201a12913e7a5b7b4b38624942effa44c05 (patch)
tree3137f6adde92d54ade76dff1ad26cca8364d6187 /drivers/spi
parent8f58ecf6c328b318187027e1a911a975747b173d (diff)
spi: mpc8xx: Fix transfert when input or output buffer is NULL
xfer ops can be passed a NULL input or output buffer. At the time being the driver ignores it and overwrites memory at 0. Define a dummy buffer and use it when either input or output buffer is NULL. Bail out when both are NULL as it shouldn't. Also increase MAX_BUFFER len to 32k as the current is pretty low. Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/mpc8xx_spi.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/spi/mpc8xx_spi.c b/drivers/spi/mpc8xx_spi.c
index 5c8d7609351..2aa9c7d5df9 100644
--- a/drivers/spi/mpc8xx_spi.c
+++ b/drivers/spi/mpc8xx_spi.c
@@ -29,7 +29,7 @@
#define CPM_SPI_BASE_RX CPM_SPI_BASE
#define CPM_SPI_BASE_TX (CPM_SPI_BASE + sizeof(cbd_t))
-#define MAX_BUFFER 0x104
+#define MAX_BUFFER 0x8000 /* Max possible is 0xffff. We want power of 2 */
struct mpc8xx_priv {
spi_t __iomem *spi;
@@ -37,6 +37,8 @@ struct mpc8xx_priv {
int max_cs;
};
+static char dummy_buffer[MAX_BUFFER];
+
static int mpc8xx_spi_set_mode(struct udevice *dev, uint mod)
{
return 0;
@@ -154,6 +156,8 @@ static int mpc8xx_spi_xfer(struct udevice *dev, unsigned int bitlen,
int tm;
size_t count = (bitlen + 7) / 8;
+ if (!din && !dout)
+ return -EINVAL;
if (count > MAX_BUFFER)
return -EINVAL;
@@ -165,12 +169,12 @@ static int mpc8xx_spi_xfer(struct udevice *dev, unsigned int bitlen,
mpc8xx_spi_cs_activate(dev);
/* Setting tx bd status and data length */
- out_be32(&tbdf->cbd_bufaddr, (ulong)dout);
+ out_be32(&tbdf->cbd_bufaddr, dout ? (ulong)dout : (ulong)dummy_buffer);
out_be16(&tbdf->cbd_sc, BD_SC_READY | BD_SC_LAST | BD_SC_WRAP);
out_be16(&tbdf->cbd_datlen, count);
/* Setting rx bd status and data length */
- out_be32(&rbdf->cbd_bufaddr, (ulong)din);
+ out_be32(&rbdf->cbd_bufaddr, din ? (ulong)din : (ulong)dummy_buffer);
out_be16(&rbdf->cbd_sc, BD_SC_EMPTY | BD_SC_WRAP);
out_be16(&rbdf->cbd_datlen, 0); /* rx length has no significance */