|
30 | 30 | */ |
31 | 31 | #define XSPI_CR_OFFSET 0x60 /* Control Register */ |
32 | 32 |
|
| 33 | +#define XSPI_CR_LOOP 0x01 |
33 | 34 | #define XSPI_CR_ENABLE 0x02 |
34 | 35 | #define XSPI_CR_MASTER_MODE 0x04 |
35 | 36 | #define XSPI_CR_CPOL 0x08 |
@@ -359,11 +360,12 @@ static const struct of_device_id xilinx_spi_of_match[] = { |
359 | 360 | MODULE_DEVICE_TABLE(of, xilinx_spi_of_match); |
360 | 361 |
|
361 | 362 | 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) |
363 | 364 | { |
364 | 365 | struct spi_master *master; |
365 | 366 | struct xilinx_spi *xspi; |
366 | 367 | int ret; |
| 368 | + u32 tmp; |
367 | 369 |
|
368 | 370 | master = spi_alloc_master(dev, sizeof(struct xilinx_spi)); |
369 | 371 | if (!master) |
@@ -396,13 +398,25 @@ struct spi_master *xilinx_spi_init(struct device *dev, struct resource *mem, |
396 | 398 |
|
397 | 399 | xspi->mem = *mem; |
398 | 400 | 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) { |
403 | 416 | xspi->read_fn = xspi_read32_be; |
404 | 417 | xspi->write_fn = xspi_write32_be; |
405 | 418 | } |
| 419 | + |
406 | 420 | xspi->bits_per_word = bits_per_word; |
407 | 421 | if (xspi->bits_per_word == 8) { |
408 | 422 | xspi->tx_fn = xspi_tx8; |
@@ -466,14 +480,13 @@ static int xilinx_spi_probe(struct platform_device *dev) |
466 | 480 | { |
467 | 481 | struct xspi_platform_data *pdata; |
468 | 482 | 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; |
470 | 484 | struct spi_master *master; |
471 | 485 | u8 i; |
472 | 486 |
|
473 | 487 | pdata = dev->dev.platform_data; |
474 | 488 | if (pdata) { |
475 | 489 | num_cs = pdata->num_chipselect; |
476 | | - little_endian = pdata->little_endian; |
477 | 490 | bits_per_word = pdata->bits_per_word; |
478 | 491 | } |
479 | 492 |
|
@@ -505,7 +518,7 @@ static int xilinx_spi_probe(struct platform_device *dev) |
505 | 518 | return -ENXIO; |
506 | 519 |
|
507 | 520 | master = xilinx_spi_init(&dev->dev, r, irq, dev->id, num_cs, |
508 | | - little_endian, bits_per_word); |
| 521 | + bits_per_word); |
509 | 522 | if (!master) |
510 | 523 | return -ENODEV; |
511 | 524 |
|
|
0 commit comments