Skip to content

Commit fafd679

Browse files
committed
Merge remote-tracking branches 'spi/topic/spidev', 'spi/topic/sunxi', 'spi/topic/ti-qspi', 'spi/topic/topcliff-pch' and 'spi/topic/xlp' into spi-next
6 parents 6694430 + 144235e + 10565df + d06a350 + 9677e7d + b87c701 commit fafd679

7 files changed

Lines changed: 107 additions & 27 deletions

File tree

‎Documentation/devicetree/bindings/spi/spi-sun6i.txt‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Allwinner A31 SPI controller
1+
Allwinner A31/H3 SPI controller
22

33
Required properties:
4-
- compatible: Should be "allwinner,sun6i-a31-spi".
4+
- compatible: Should be "allwinner,sun6i-a31-spi" or "allwinner,sun8i-h3-spi".
55
- reg: Should contain register location and length.
66
- interrupts: Should contain interrupt.
77
- clocks: phandle to the clocks feeding the SPI controller. Two are
@@ -12,6 +12,11 @@ Required properties:
1212
- resets: phandle to the reset controller asserting this device in
1313
reset
1414

15+
Optional properties:
16+
- dmas: DMA specifiers for rx and tx dma. See the DMA client binding,
17+
Documentation/devicetree/bindings/dma/dma.txt
18+
- dma-names: DMA request names should include "rx" and "tx" if present.
19+
1520
Example:
1621

1722
spi1: spi@01c69000 {
@@ -22,3 +27,19 @@ spi1: spi@01c69000 {
2227
clock-names = "ahb", "mod";
2328
resets = <&ahb1_rst 21>;
2429
};
30+
31+
spi0: spi@01c68000 {
32+
compatible = "allwinner,sun8i-h3-spi";
33+
reg = <0x01c68000 0x1000>;
34+
interrupts = <GIC_SPI 65 IRQ_TYPE_LEVEL_HIGH>;
35+
clocks = <&ccu CLK_BUS_SPI0>, <&ccu CLK_SPI0>;
36+
clock-names = "ahb", "mod";
37+
dmas = <&dma 23>, <&dma 23>;
38+
dma-names = "rx", "tx";
39+
pinctrl-names = "default";
40+
pinctrl-0 = <&spi0_pins>;
41+
resets = <&ccu RST_BUS_SPI0>;
42+
status = "disabled";
43+
#address-cells = <1>;
44+
#size-cells = <0>;
45+
};

‎drivers/spi/spi-sun4i.c‎

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
#define SUN4I_CTL_TP BIT(18)
4747

4848
#define SUN4I_INT_CTL_REG 0x0c
49+
#define SUN4I_INT_CTL_RF_F34 BIT(4)
50+
#define SUN4I_INT_CTL_TF_E34 BIT(12)
4951
#define SUN4I_INT_CTL_TC BIT(16)
5052

5153
#define SUN4I_INT_STA_REG 0x10
@@ -61,11 +63,14 @@
6163
#define SUN4I_CLK_CTL_CDR1(div) (((div) & SUN4I_CLK_CTL_CDR1_MASK) << 8)
6264
#define SUN4I_CLK_CTL_DRS BIT(12)
6365

66+
#define SUN4I_MAX_XFER_SIZE 0xffffff
67+
6468
#define SUN4I_BURST_CNT_REG 0x20
65-
#define SUN4I_BURST_CNT(cnt) ((cnt) & 0xffffff)
69+
#define SUN4I_BURST_CNT(cnt) ((cnt) & SUN4I_MAX_XFER_SIZE)
6670

6771
#define SUN4I_XMIT_CNT_REG 0x24
68-
#define SUN4I_XMIT_CNT(cnt) ((cnt) & 0xffffff)
72+
#define SUN4I_XMIT_CNT(cnt) ((cnt) & SUN4I_MAX_XFER_SIZE)
73+
6974

7075
#define SUN4I_FIFO_STA_REG 0x28
7176
#define SUN4I_FIFO_STA_RF_CNT_MASK 0x7f
@@ -96,6 +101,31 @@ static inline void sun4i_spi_write(struct sun4i_spi *sspi, u32 reg, u32 value)
96101
writel(value, sspi->base_addr + reg);
97102
}
98103

104+
static inline u32 sun4i_spi_get_tx_fifo_count(struct sun4i_spi *sspi)
105+
{
106+
u32 reg = sun4i_spi_read(sspi, SUN4I_FIFO_STA_REG);
107+
108+
reg >>= SUN4I_FIFO_STA_TF_CNT_BITS;
109+
110+
return reg & SUN4I_FIFO_STA_TF_CNT_MASK;
111+
}
112+
113+
static inline void sun4i_spi_enable_interrupt(struct sun4i_spi *sspi, u32 mask)
114+
{
115+
u32 reg = sun4i_spi_read(sspi, SUN4I_INT_CTL_REG);
116+
117+
reg |= mask;
118+
sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, reg);
119+
}
120+
121+
static inline void sun4i_spi_disable_interrupt(struct sun4i_spi *sspi, u32 mask)
122+
{
123+
u32 reg = sun4i_spi_read(sspi, SUN4I_INT_CTL_REG);
124+
125+
reg &= ~mask;
126+
sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, reg);
127+
}
128+
99129
static inline void sun4i_spi_drain_fifo(struct sun4i_spi *sspi, int len)
100130
{
101131
u32 reg, cnt;
@@ -118,10 +148,13 @@ static inline void sun4i_spi_drain_fifo(struct sun4i_spi *sspi, int len)
118148

119149
static inline void sun4i_spi_fill_fifo(struct sun4i_spi *sspi, int len)
120150
{
151+
u32 cnt;
121152
u8 byte;
122153

123-
if (len > sspi->len)
124-
len = sspi->len;
154+
/* See how much data we can fit */
155+
cnt = SUN4I_FIFO_DEPTH - sun4i_spi_get_tx_fifo_count(sspi);
156+
157+
len = min3(len, (int)cnt, sspi->len);
125158

126159
while (len--) {
127160
byte = sspi->tx_buf ? *sspi->tx_buf++ : 0;
@@ -184,10 +217,10 @@ static int sun4i_spi_transfer_one(struct spi_master *master,
184217
u32 reg;
185218

186219
/* We don't support transfer larger than the FIFO */
187-
if (tfr->len > SUN4I_FIFO_DEPTH)
220+
if (tfr->len > SUN4I_MAX_XFER_SIZE)
188221
return -EMSGSIZE;
189222

190-
if (tfr->tx_buf && tfr->len >= SUN4I_FIFO_DEPTH)
223+
if (tfr->tx_buf && tfr->len >= SUN4I_MAX_XFER_SIZE)
191224
return -EMSGSIZE;
192225

193226
reinit_completion(&sspi->done);
@@ -286,7 +319,11 @@ static int sun4i_spi_transfer_one(struct spi_master *master,
286319
sun4i_spi_fill_fifo(sspi, SUN4I_FIFO_DEPTH - 1);
287320

288321
/* Enable the interrupts */
289-
sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, SUN4I_INT_CTL_TC);
322+
sun4i_spi_enable_interrupt(sspi, SUN4I_INT_CTL_TC |
323+
SUN4I_INT_CTL_RF_F34);
324+
/* Only enable Tx FIFO interrupt if we really need it */
325+
if (tx_len > SUN4I_FIFO_DEPTH)
326+
sun4i_spi_enable_interrupt(sspi, SUN4I_INT_CTL_TF_E34);
290327

291328
/* Start the transfer */
292329
reg = sun4i_spi_read(sspi, SUN4I_CTL_REG);
@@ -306,7 +343,6 @@ static int sun4i_spi_transfer_one(struct spi_master *master,
306343
goto out;
307344
}
308345

309-
sun4i_spi_drain_fifo(sspi, SUN4I_FIFO_DEPTH);
310346

311347
out:
312348
sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, 0);
@@ -322,10 +358,33 @@ static irqreturn_t sun4i_spi_handler(int irq, void *dev_id)
322358
/* Transfer complete */
323359
if (status & SUN4I_INT_CTL_TC) {
324360
sun4i_spi_write(sspi, SUN4I_INT_STA_REG, SUN4I_INT_CTL_TC);
361+
sun4i_spi_drain_fifo(sspi, SUN4I_FIFO_DEPTH);
325362
complete(&sspi->done);
326363
return IRQ_HANDLED;
327364
}
328365

366+
/* Receive FIFO 3/4 full */
367+
if (status & SUN4I_INT_CTL_RF_F34) {
368+
sun4i_spi_drain_fifo(sspi, SUN4I_FIFO_DEPTH);
369+
/* Only clear the interrupt _after_ draining the FIFO */
370+
sun4i_spi_write(sspi, SUN4I_INT_STA_REG, SUN4I_INT_CTL_RF_F34);
371+
return IRQ_HANDLED;
372+
}
373+
374+
/* Transmit FIFO 3/4 empty */
375+
if (status & SUN4I_INT_CTL_TF_E34) {
376+
sun4i_spi_fill_fifo(sspi, SUN4I_FIFO_DEPTH);
377+
378+
if (!sspi->len)
379+
/* nothing left to transmit */
380+
sun4i_spi_disable_interrupt(sspi, SUN4I_INT_CTL_TF_E34);
381+
382+
/* Only clear the interrupt _after_ re-seeding the FIFO */
383+
sun4i_spi_write(sspi, SUN4I_INT_STA_REG, SUN4I_INT_CTL_TF_E34);
384+
385+
return IRQ_HANDLED;
386+
}
387+
329388
return IRQ_NONE;
330389
}
331390

‎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);

‎drivers/spi/spi-ti-qspi.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ static int ti_qspi_dma_xfer(struct ti_qspi *qspi, dma_addr_t dma_dst,
411411
tx->callback = ti_qspi_dma_callback;
412412
tx->callback_param = qspi;
413413
cookie = tx->tx_submit(tx);
414+
reinit_completion(&qspi->transfer_complete);
414415

415416
ret = dma_submit_error(cookie);
416417
if (ret) {

‎drivers/spi/spi-topcliff-pch.c‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,27 +1268,16 @@ static void pch_spi_free_resources(struct pch_spi_board_data *board_dat,
12681268
static int pch_spi_get_resources(struct pch_spi_board_data *board_dat,
12691269
struct pch_spi_data *data)
12701270
{
1271-
int retval = 0;
1272-
12731271
dev_dbg(&board_dat->pdev->dev, "%s ENTRY\n", __func__);
12741272

1275-
12761273
/* reset PCH SPI h/w */
12771274
pch_spi_reset(data->master);
12781275
dev_dbg(&board_dat->pdev->dev,
12791276
"%s pch_spi_reset invoked successfully\n", __func__);
12801277

12811278
dev_dbg(&board_dat->pdev->dev, "%s data->irq_reg_sts=true\n", __func__);
12821279

1283-
if (retval != 0) {
1284-
dev_err(&board_dat->pdev->dev,
1285-
"%s FAIL:invoking pch_spi_free_resources\n", __func__);
1286-
pch_spi_free_resources(board_dat, data);
1287-
}
1288-
1289-
dev_dbg(&board_dat->pdev->dev, "%s Return=%d\n", __func__, retval);
1290-
1291-
return retval;
1280+
return 0;
12921281
}
12931282

12941283
static void pch_free_dma_buf(struct pch_spi_board_data *board_dat,

‎drivers/spi/spi-xlp.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ static const struct of_device_id xlp_spi_dt_id[] = {
451451
{ .compatible = "netlogic,xlp832-spi" },
452452
{ },
453453
};
454+
MODULE_DEVICE_TABLE(of, xlp_spi_dt_id);
454455

455456
static struct platform_driver xlp_spi_driver = {
456457
.probe = xlp_spi_probe,

‎drivers/spi/spidev.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ static struct class *spidev_class;
696696
static const struct of_device_id spidev_dt_ids[] = {
697697
{ .compatible = "rohm,dh2228fv" },
698698
{ .compatible = "lineartechnology,ltc2488" },
699+
{ .compatible = "ge,achc" },
699700
{},
700701
};
701702
MODULE_DEVICE_TABLE(of, spidev_dt_ids);

0 commit comments

Comments
 (0)