Skip to content

Commit 263b81d

Browse files
adureghello-tsbroonie
authored andcommitted
spi: spi-fsl-dspi: fix native data copy
ColdFire is a big-endian cpu with a big-endian dspi hw module, so, it uses native access, but memcpy breaks the endianness. So, if i understand properly, by native copy we would mean be(cpu)->be(dspi) or le(cpu)->le(dspi) accesses, so my fix shouldn't break anything, but i couldn't test it on LS family, so every test is really appreciated. Fixes: 53fadb4 ("spi: spi-fsl-dspi: Simplify bytes_per_word gymnastics") Signed-off-by: Angelo Dureghello <[email protected]> Tested-by: Vladimir Oltean <[email protected]> Reviewed-by: Vladimir Oltean <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 164c05f commit 263b81d

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

drivers/spi/spi-fsl-dspi.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,33 @@ struct fsl_dspi {
250250

251251
static void dspi_native_host_to_dev(struct fsl_dspi *dspi, u32 *txdata)
252252
{
253-
memcpy(txdata, dspi->tx, dspi->oper_word_size);
253+
switch (dspi->oper_word_size) {
254+
case 1:
255+
*txdata = *(u8 *)dspi->tx;
256+
break;
257+
case 2:
258+
*txdata = *(u16 *)dspi->tx;
259+
break;
260+
case 4:
261+
*txdata = *(u32 *)dspi->tx;
262+
break;
263+
}
254264
dspi->tx += dspi->oper_word_size;
255265
}
256266

257267
static void dspi_native_dev_to_host(struct fsl_dspi *dspi, u32 rxdata)
258268
{
259-
memcpy(dspi->rx, &rxdata, dspi->oper_word_size);
269+
switch (dspi->oper_word_size) {
270+
case 1:
271+
*(u8 *)dspi->rx = rxdata;
272+
break;
273+
case 2:
274+
*(u16 *)dspi->rx = rxdata;
275+
break;
276+
case 4:
277+
*(u32 *)dspi->rx = rxdata;
278+
break;
279+
}
260280
dspi->rx += dspi->oper_word_size;
261281
}
262282

0 commit comments

Comments
 (0)