0075-spi-spi-sun6i-Use-a-struct-for-quirks.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. From dbc9e83cefe51d19877a4a7349ebbeafa31c0e06 Mon Sep 17 00:00:00 2001
  2. From: Samuel Holland <[email protected]>
  3. Date: Fri, 16 Jul 2021 21:33:16 -0500
  4. Subject: [PATCH 075/117] spi: spi-sun6i: Use a struct for quirks
  5. Signed-off-by: Samuel Holland <[email protected]>
  6. ---
  7. drivers/spi/spi-sun6i.c | 32 ++++++++++++++++++++++----------
  8. 1 file changed, 22 insertions(+), 10 deletions(-)
  9. --- a/drivers/spi/spi-sun6i.c
  10. +++ b/drivers/spi/spi-sun6i.c
  11. @@ -85,7 +85,12 @@
  12. #define SUN6I_TXDATA_REG 0x200
  13. #define SUN6I_RXDATA_REG 0x300
  14. +struct sun6i_spi_quirks {
  15. + unsigned long fifo_depth;
  16. +};
  17. +
  18. struct sun6i_spi {
  19. + const struct sun6i_spi_quirks *quirks;
  20. struct spi_master *master;
  21. void __iomem *base_addr;
  22. dma_addr_t dma_addr_rx;
  23. @@ -100,7 +105,6 @@ struct sun6i_spi {
  24. const u8 *tx_buf;
  25. u8 *rx_buf;
  26. int len;
  27. - unsigned long fifo_depth;
  28. };
  29. static inline u32 sun6i_spi_read(struct sun6i_spi *sspi, u32 reg)
  30. @@ -157,7 +161,7 @@ static inline void sun6i_spi_fill_fifo(s
  31. u8 byte;
  32. /* See how much data we can fit */
  33. - cnt = sspi->fifo_depth - sun6i_spi_get_tx_fifo_count(sspi);
  34. + cnt = sspi->quirks->fifo_depth - sun6i_spi_get_tx_fifo_count(sspi);
  35. len = min((int)cnt, sspi->len);
  36. @@ -300,14 +304,14 @@ static int sun6i_spi_transfer_one(struct
  37. * the hardcoded value used in old generation of Allwinner
  38. * SPI controller. (See spi-sun4i.c)
  39. */
  40. - trig_level = sspi->fifo_depth / 4 * 3;
  41. + trig_level = sspi->quirks->fifo_depth / 4 * 3;
  42. } else {
  43. /*
  44. * Setup FIFO DMA request trigger level
  45. * We choose 1/2 of the full fifo depth, that value will
  46. * be used as DMA burst length.
  47. */
  48. - trig_level = sspi->fifo_depth / 2;
  49. + trig_level = sspi->quirks->fifo_depth / 2;
  50. if (tfr->tx_buf)
  51. reg |= SUN6I_FIFO_CTL_TF_DRQ_EN;
  52. @@ -421,9 +425,9 @@ static int sun6i_spi_transfer_one(struct
  53. reg = SUN6I_INT_CTL_TC;
  54. if (!use_dma) {
  55. - if (rx_len > sspi->fifo_depth)
  56. + if (rx_len > sspi->quirks->fifo_depth)
  57. reg |= SUN6I_INT_CTL_RF_RDY;
  58. - if (tx_len > sspi->fifo_depth)
  59. + if (tx_len > sspi->quirks->fifo_depth)
  60. reg |= SUN6I_INT_CTL_TF_ERQ;
  61. }
  62. @@ -569,7 +573,7 @@ static bool sun6i_spi_can_dma(struct spi
  63. * the fifo length we can just fill the fifo and wait for a single
  64. * irq, so don't bother setting up dma
  65. */
  66. - return xfer->len > sspi->fifo_depth;
  67. + return xfer->len > sspi->quirks->fifo_depth;
  68. }
  69. static int sun6i_spi_probe(struct platform_device *pdev)
  70. @@ -608,7 +612,7 @@ static int sun6i_spi_probe(struct platfo
  71. }
  72. sspi->master = master;
  73. - sspi->fifo_depth = (unsigned long)of_device_get_match_data(&pdev->dev);
  74. + sspi->quirks = of_device_get_match_data(&pdev->dev);
  75. master->max_speed_hz = 100 * 1000 * 1000;
  76. master->min_speed_hz = 3 * 1000;
  77. @@ -723,9 +727,17 @@ static int sun6i_spi_remove(struct platf
  78. return 0;
  79. }
  80. +static const struct sun6i_spi_quirks sun6i_a31_spi_quirks = {
  81. + .fifo_depth = SUN6I_FIFO_DEPTH,
  82. +};
  83. +
  84. +static const struct sun6i_spi_quirks sun8i_h3_spi_quirks = {
  85. + .fifo_depth = SUN8I_FIFO_DEPTH,
  86. +};
  87. +
  88. static const struct of_device_id sun6i_spi_match[] = {
  89. - { .compatible = "allwinner,sun6i-a31-spi", .data = (void *)SUN6I_FIFO_DEPTH },
  90. - { .compatible = "allwinner,sun8i-h3-spi", .data = (void *)SUN8I_FIFO_DEPTH },
  91. + { .compatible = "allwinner,sun6i-a31-spi", .data = &sun6i_a31_spi_quirks },
  92. + { .compatible = "allwinner,sun8i-h3-spi", .data = &sun8i_h3_spi_quirks },
  93. {}
  94. };
  95. MODULE_DEVICE_TABLE(of, sun6i_spi_match);