Skip to content

Commit 082339b

Browse files
Michal Simekbroonie
authored andcommitted
spi: spi-xilinx: Add run run-time endian detection
Do not load endian value from platform data and rather autodetect it. Signed-off-by: Michal Simek <michal.simek@xilinx.com> Signed-off-by: Mark Brown <broonie@linaro.org>
1 parent d683b96 commit 082339b

3 files changed

Lines changed: 21 additions & 10 deletions

File tree

‎drivers/mfd/timberdale.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ static struct spi_board_info timberdale_spi_8bit_board_info[] = {
145145

146146
static struct xspi_platform_data timberdale_xspi_platform_data = {
147147
.num_chipselect = 3,
148-
.little_endian = true,
149148
/* bits per word and devices will be filled in runtime depending
150149
* on the HW config
151150
*/

‎drivers/spi/spi-xilinx.c‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*/
3131
#define XSPI_CR_OFFSET 0x60 /* Control Register */
3232

33+
#define XSPI_CR_LOOP 0x01
3334
#define XSPI_CR_ENABLE 0x02
3435
#define XSPI_CR_MASTER_MODE 0x04
3536
#define XSPI_CR_CPOL 0x08
@@ -359,11 +360,12 @@ static const struct of_device_id xilinx_spi_of_match[] = {
359360
MODULE_DEVICE_TABLE(of, xilinx_spi_of_match);
360361

361362
struct spi_master *xilinx_spi_init(struct device *dev, struct resource *mem,
362-
u32 irq, s16 bus_num, int num_cs, int little_endian, int bits_per_word)
363+
u32 irq, s16 bus_num, int num_cs, int bits_per_word)
363364
{
364365
struct spi_master *master;
365366
struct xilinx_spi *xspi;
366367
int ret;
368+
u32 tmp;
367369

368370
master = spi_alloc_master(dev, sizeof(struct xilinx_spi));
369371
if (!master)
@@ -396,13 +398,25 @@ struct spi_master *xilinx_spi_init(struct device *dev, struct resource *mem,
396398

397399
xspi->mem = *mem;
398400
xspi->irq = irq;
399-
if (little_endian) {
400-
xspi->read_fn = xspi_read32;
401-
xspi->write_fn = xspi_write32;
402-
} else {
401+
402+
/*
403+
* Detect endianess on the IP via loop bit in CR. Detection
404+
* must be done before reset is sent because incorrect reset
405+
* value generates error interrupt.
406+
* Setup little endian helper functions first and try to use them
407+
* and check if bit was correctly setup or not.
408+
*/
409+
xspi->read_fn = xspi_read32;
410+
xspi->write_fn = xspi_write32;
411+
412+
xspi->write_fn(XSPI_CR_LOOP, xspi->regs + XSPI_CR_OFFSET);
413+
tmp = xspi->read_fn(xspi->regs + XSPI_CR_OFFSET);
414+
tmp &= XSPI_CR_LOOP;
415+
if (tmp != XSPI_CR_LOOP) {
403416
xspi->read_fn = xspi_read32_be;
404417
xspi->write_fn = xspi_write32_be;
405418
}
419+
406420
xspi->bits_per_word = bits_per_word;
407421
if (xspi->bits_per_word == 8) {
408422
xspi->tx_fn = xspi_tx8;
@@ -466,14 +480,13 @@ static int xilinx_spi_probe(struct platform_device *dev)
466480
{
467481
struct xspi_platform_data *pdata;
468482
struct resource *r;
469-
int irq, num_cs = 0, little_endian = 0, bits_per_word = 8;
483+
int irq, num_cs = 0, bits_per_word = 8;
470484
struct spi_master *master;
471485
u8 i;
472486

473487
pdata = dev->dev.platform_data;
474488
if (pdata) {
475489
num_cs = pdata->num_chipselect;
476-
little_endian = pdata->little_endian;
477490
bits_per_word = pdata->bits_per_word;
478491
}
479492

@@ -505,7 +518,7 @@ static int xilinx_spi_probe(struct platform_device *dev)
505518
return -ENXIO;
506519

507520
master = xilinx_spi_init(&dev->dev, r, irq, dev->id, num_cs,
508-
little_endian, bits_per_word);
521+
bits_per_word);
509522
if (!master)
510523
return -ENODEV;
511524

‎include/linux/spi/xilinx_spi.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
*/
1212
struct xspi_platform_data {
1313
u16 num_chipselect;
14-
bool little_endian;
1514
u8 bits_per_word;
1615
struct spi_board_info *devices;
1716
u8 num_devices;

0 commit comments

Comments
 (0)