Skip to content

Commit 10565df

Browse files
woogyombroonie
authored andcommitted
spi: sun6i: Support Allwinner H3 SPI controller
H3 has two SPI controllers. The size of the buffer is 64 * 8. (8 bit transfer by 64 entry FIFO) A31 has four controllers. The size of the buffer is 128 * 8. (8 bit transfer by 128 entry FIFO) Register maps are sharable, so sun6i SPI driver is reusable with device configuration. Use the variable, 'fifo_depth' instead of fixed value to support both SPI controllers. Signed-off-by: Milo Kim <woogyom.kim@gmail.com> Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 8ea7ce9 commit 10565df

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎drivers/spi/spi-sun6i.c‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
#include <linux/interrupt.h>
1818
#include <linux/io.h>
1919
#include <linux/module.h>
20+
#include <linux/of_device.h>
2021
#include <linux/platform_device.h>
2122
#include <linux/pm_runtime.h>
2223
#include <linux/reset.h>
2324

2425
#include <linux/spi/spi.h>
2526

2627
#define SUN6I_FIFO_DEPTH 128
28+
#define SUN8I_FIFO_DEPTH 64
2729

2830
#define SUN6I_GBL_CTL_REG 0x04
2931
#define SUN6I_GBL_CTL_BUS_ENABLE BIT(0)
@@ -90,6 +92,7 @@ struct sun6i_spi {
9092
const u8 *tx_buf;
9193
u8 *rx_buf;
9294
int len;
95+
unsigned long fifo_depth;
9396
};
9497

9598
static inline u32 sun6i_spi_read(struct sun6i_spi *sspi, u32 reg)
@@ -155,7 +158,9 @@ static void sun6i_spi_set_cs(struct spi_device *spi, bool enable)
155158

156159
static size_t sun6i_spi_max_transfer_size(struct spi_device *spi)
157160
{
158-
return SUN6I_FIFO_DEPTH - 1;
161+
struct sun6i_spi *sspi = spi_master_get_devdata(spi->master);
162+
163+
return sspi->fifo_depth - 1;
159164
}
160165

161166
static int sun6i_spi_transfer_one(struct spi_master *master,
@@ -170,7 +175,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master,
170175
u32 reg;
171176

172177
/* We don't support transfer larger than the FIFO */
173-
if (tfr->len > SUN6I_FIFO_DEPTH)
178+
if (tfr->len > sspi->fifo_depth)
174179
return -EINVAL;
175180

176181
reinit_completion(&sspi->done);
@@ -265,7 +270,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master,
265270
SUN6I_BURST_CTL_CNT_STC(tx_len));
266271

267272
/* Fill the TX FIFO */
268-
sun6i_spi_fill_fifo(sspi, SUN6I_FIFO_DEPTH);
273+
sun6i_spi_fill_fifo(sspi, sspi->fifo_depth);
269274

270275
/* Enable the interrupts */
271276
sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, SUN6I_INT_CTL_TC);
@@ -288,7 +293,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master,
288293
goto out;
289294
}
290295

291-
sun6i_spi_drain_fifo(sspi, SUN6I_FIFO_DEPTH);
296+
sun6i_spi_drain_fifo(sspi, sspi->fifo_depth);
292297

293298
out:
294299
sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, 0);
@@ -398,6 +403,8 @@ static int sun6i_spi_probe(struct platform_device *pdev)
398403
}
399404

400405
sspi->master = master;
406+
sspi->fifo_depth = (unsigned long)of_device_get_match_data(&pdev->dev);
407+
401408
master->max_speed_hz = 100 * 1000 * 1000;
402409
master->min_speed_hz = 3 * 1000;
403410
master->set_cs = sun6i_spi_set_cs;
@@ -470,7 +477,8 @@ static int sun6i_spi_remove(struct platform_device *pdev)
470477
}
471478

472479
static const struct of_device_id sun6i_spi_match[] = {
473-
{ .compatible = "allwinner,sun6i-a31-spi", },
480+
{ .compatible = "allwinner,sun6i-a31-spi", .data = (void *)SUN6I_FIFO_DEPTH },
481+
{ .compatible = "allwinner,sun8i-h3-spi", .data = (void *)SUN8I_FIFO_DEPTH },
474482
{}
475483
};
476484
MODULE_DEVICE_TABLE(of, sun6i_spi_match);

0 commit comments

Comments
 (0)