410-spi-ath79-Implement-the-spi_mem-interface.patch 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From 8d8cdb4a6ccee5b62cc0dc64651c3946364514dc Mon Sep 17 00:00:00 2001
  2. From: Luiz Angelo Daros de Luca <[email protected]>
  3. Date: Mon, 10 Feb 2020 16:11:27 -0300
  4. Subject: [PATCH] spi: ath79: Implement the spi_mem interface
  5. Signed-off-by: Luiz Angelo Daros de Luca <[email protected]>
  6. ---
  7. drivers/spi/spi-ath79.c | 35 +++++++++++++++++++++++++++++++++++
  8. 1 file changed, 35 insertions(+)
  9. --- a/drivers/spi/spi-ath79.c
  10. +++ b/drivers/spi/spi-ath79.c
  11. @@ -19,6 +19,7 @@
  12. #include <linux/platform_device.h>
  13. #include <linux/io.h>
  14. #include <linux/spi/spi.h>
  15. +#include <linux/spi/spi-mem.h>
  16. #include <linux/spi/spi_bitbang.h>
  17. #include <linux/bitops.h>
  18. #include <linux/gpio.h>
  19. @@ -203,6 +204,39 @@ static u32 ath79_spi_txrx_mode0(struct s
  20. return ath79_spi_rr(sp, AR71XX_SPI_REG_RDS);
  21. }
  22. +static int ath79_exec_mem_op(struct spi_mem *mem,
  23. + const struct spi_mem_op *op)
  24. +{
  25. + struct ath79_spi *sp = ath79_spidev_to_sp(mem->spi);
  26. +
  27. + /* Ensures that reading is performed on device connected
  28. + to hardware cs0 */
  29. + if (mem->spi->chip_select || gpio_is_valid(mem->spi->cs_gpio))
  30. + return -ENOTSUPP;
  31. +
  32. + /* Only use for fast-read op. */
  33. + if (op->cmd.opcode != 0x0b || op->data.dir != SPI_MEM_DATA_IN ||
  34. + op->addr.nbytes != 3 || op->dummy.nbytes != 1)
  35. + return -ENOTSUPP;
  36. +
  37. + /* disable GPIO mode */
  38. + ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0);
  39. +
  40. + memcpy_fromio(op->data.buf.in, sp->base + op->addr.val, op->data.nbytes);
  41. +
  42. + /* enable GPIO mode */
  43. + ath79_spi_wr(sp, AR71XX_SPI_REG_FS, AR71XX_SPI_FS_GPIO);
  44. +
  45. + /* restore IOC register */
  46. + ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
  47. +
  48. + return 0;
  49. +}
  50. +
  51. +static const struct spi_controller_mem_ops ath79_mem_ops = {
  52. + .exec_op = ath79_exec_mem_op,
  53. +};
  54. +
  55. static int ath79_spi_probe(struct platform_device *pdev)
  56. {
  57. struct spi_master *master;
  58. @@ -237,6 +271,7 @@ static int ath79_spi_probe(struct platfo
  59. ret = PTR_ERR(sp->base);
  60. goto err_put_master;
  61. }
  62. + master->mem_ops = &ath79_mem_ops;
  63. sp->clk = devm_clk_get(&pdev->dev, "ahb");
  64. if (IS_ERR(sp->clk)) {