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