Skip to content

Commit 45cfc32

Browse files
committed
Merge remote-tracking branches 'spi/topic/altera', 'spi/topic/at79', 'spi/topic/bcm-qspi', 'spi/topic/bcm63xx' and 'spi/topic/bcm63xx-hspi' into spi-next
6 parents 0d1a619 + b64836a + da470d6 + 054e532 + 378da4a + c3c25ea commit 45cfc32

File tree

6 files changed

+105
-175
lines changed

6 files changed

+105
-175
lines changed

drivers/spi/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ comment "SPI Master Controller Drivers"
5555

5656
config SPI_ALTERA
5757
tristate "Altera SPI Controller"
58-
select SPI_BITBANG
5958
help
6059
This is the driver for the Altera SPI Controller.
6160

drivers/spi/spi-altera.c

Lines changed: 59 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <linux/module.h>
1919
#include <linux/platform_device.h>
2020
#include <linux/spi/spi.h>
21-
#include <linux/spi/spi_bitbang.h>
2221
#include <linux/io.h>
2322
#include <linux/of.h>
2423

@@ -45,10 +44,6 @@
4544
#define ALTERA_SPI_CONTROL_SSO_MSK 0x400
4645

4746
struct altera_spi {
48-
/* bitbang has to be first */
49-
struct spi_bitbang bitbang;
50-
struct completion done;
51-
5247
void __iomem *base;
5348
int irq;
5449
int len;
@@ -66,59 +61,64 @@ static inline struct altera_spi *altera_spi_to_hw(struct spi_device *sdev)
6661
return spi_master_get_devdata(sdev->master);
6762
}
6863

69-
static void altera_spi_chipsel(struct spi_device *spi, int value)
64+
static void altera_spi_set_cs(struct spi_device *spi, bool is_high)
7065
{
7166
struct altera_spi *hw = altera_spi_to_hw(spi);
7267

73-
if (spi->mode & SPI_CS_HIGH) {
74-
switch (value) {
75-
case BITBANG_CS_INACTIVE:
76-
writel(1 << spi->chip_select,
77-
hw->base + ALTERA_SPI_SLAVE_SEL);
78-
hw->imr |= ALTERA_SPI_CONTROL_SSO_MSK;
79-
writel(hw->imr, hw->base + ALTERA_SPI_CONTROL);
80-
break;
81-
82-
case BITBANG_CS_ACTIVE:
83-
hw->imr &= ~ALTERA_SPI_CONTROL_SSO_MSK;
84-
writel(hw->imr, hw->base + ALTERA_SPI_CONTROL);
85-
writel(0, hw->base + ALTERA_SPI_SLAVE_SEL);
86-
break;
87-
}
68+
if (is_high) {
69+
hw->imr &= ~ALTERA_SPI_CONTROL_SSO_MSK;
70+
writel(hw->imr, hw->base + ALTERA_SPI_CONTROL);
71+
writel(0, hw->base + ALTERA_SPI_SLAVE_SEL);
8872
} else {
89-
switch (value) {
90-
case BITBANG_CS_INACTIVE:
91-
hw->imr &= ~ALTERA_SPI_CONTROL_SSO_MSK;
92-
writel(hw->imr, hw->base + ALTERA_SPI_CONTROL);
93-
break;
73+
writel(BIT(spi->chip_select), hw->base + ALTERA_SPI_SLAVE_SEL);
74+
hw->imr |= ALTERA_SPI_CONTROL_SSO_MSK;
75+
writel(hw->imr, hw->base + ALTERA_SPI_CONTROL);
76+
}
77+
}
78+
79+
static void altera_spi_tx_word(struct altera_spi *hw)
80+
{
81+
unsigned int txd = 0;
9482

95-
case BITBANG_CS_ACTIVE:
96-
writel(1 << spi->chip_select,
97-
hw->base + ALTERA_SPI_SLAVE_SEL);
98-
hw->imr |= ALTERA_SPI_CONTROL_SSO_MSK;
99-
writel(hw->imr, hw->base + ALTERA_SPI_CONTROL);
83+
if (hw->tx) {
84+
switch (hw->bytes_per_word) {
85+
case 1:
86+
txd = hw->tx[hw->count];
87+
break;
88+
case 2:
89+
txd = (hw->tx[hw->count * 2]
90+
| (hw->tx[hw->count * 2 + 1] << 8));
10091
break;
10192
}
10293
}
94+
95+
writel(txd, hw->base + ALTERA_SPI_TXDATA);
10396
}
10497

105-
static inline unsigned int hw_txbyte(struct altera_spi *hw, int count)
98+
static void altera_spi_rx_word(struct altera_spi *hw)
10699
{
107-
if (hw->tx) {
100+
unsigned int rxd;
101+
102+
rxd = readl(hw->base + ALTERA_SPI_RXDATA);
103+
if (hw->rx) {
108104
switch (hw->bytes_per_word) {
109105
case 1:
110-
return hw->tx[count];
106+
hw->rx[hw->count] = rxd;
107+
break;
111108
case 2:
112-
return (hw->tx[count * 2]
113-
| (hw->tx[count * 2 + 1] << 8));
109+
hw->rx[hw->count * 2] = rxd;
110+
hw->rx[hw->count * 2 + 1] = rxd >> 8;
111+
break;
114112
}
115113
}
116-
return 0;
114+
115+
hw->count++;
117116
}
118117

119-
static int altera_spi_txrx(struct spi_device *spi, struct spi_transfer *t)
118+
static int altera_spi_txrx(struct spi_master *master,
119+
struct spi_device *spi, struct spi_transfer *t)
120120
{
121-
struct altera_spi *hw = altera_spi_to_hw(spi);
121+
struct altera_spi *hw = spi_master_get_devdata(master);
122122

123123
hw->tx = t->tx_buf;
124124
hw->rx = t->rx_buf;
@@ -132,67 +132,39 @@ static int altera_spi_txrx(struct spi_device *spi, struct spi_transfer *t)
132132
writel(hw->imr, hw->base + ALTERA_SPI_CONTROL);
133133

134134
/* send the first byte */
135-
writel(hw_txbyte(hw, 0), hw->base + ALTERA_SPI_TXDATA);
136-
137-
wait_for_completion(&hw->done);
138-
/* disable receive interrupt */
139-
hw->imr &= ~ALTERA_SPI_CONTROL_IRRDY_MSK;
140-
writel(hw->imr, hw->base + ALTERA_SPI_CONTROL);
135+
altera_spi_tx_word(hw);
141136
} else {
142137
while (hw->count < hw->len) {
143-
unsigned int rxd;
144-
145-
writel(hw_txbyte(hw, hw->count),
146-
hw->base + ALTERA_SPI_TXDATA);
138+
altera_spi_tx_word(hw);
147139

148140
while (!(readl(hw->base + ALTERA_SPI_STATUS) &
149141
ALTERA_SPI_STATUS_RRDY_MSK))
150142
cpu_relax();
151143

152-
rxd = readl(hw->base + ALTERA_SPI_RXDATA);
153-
if (hw->rx) {
154-
switch (hw->bytes_per_word) {
155-
case 1:
156-
hw->rx[hw->count] = rxd;
157-
break;
158-
case 2:
159-
hw->rx[hw->count * 2] = rxd;
160-
hw->rx[hw->count * 2 + 1] = rxd >> 8;
161-
break;
162-
}
163-
}
164-
165-
hw->count++;
144+
altera_spi_rx_word(hw);
166145
}
146+
spi_finalize_current_transfer(master);
167147
}
168148

169-
return hw->count * hw->bytes_per_word;
149+
return t->len;
170150
}
171151

172152
static irqreturn_t altera_spi_irq(int irq, void *dev)
173153
{
174-
struct altera_spi *hw = dev;
175-
unsigned int rxd;
154+
struct spi_master *master = dev;
155+
struct altera_spi *hw = spi_master_get_devdata(master);
176156

177-
rxd = readl(hw->base + ALTERA_SPI_RXDATA);
178-
if (hw->rx) {
179-
switch (hw->bytes_per_word) {
180-
case 1:
181-
hw->rx[hw->count] = rxd;
182-
break;
183-
case 2:
184-
hw->rx[hw->count * 2] = rxd;
185-
hw->rx[hw->count * 2 + 1] = rxd >> 8;
186-
break;
187-
}
188-
}
157+
altera_spi_rx_word(hw);
189158

190-
hw->count++;
159+
if (hw->count < hw->len) {
160+
altera_spi_tx_word(hw);
161+
} else {
162+
/* disable receive interrupt */
163+
hw->imr &= ~ALTERA_SPI_CONTROL_IRRDY_MSK;
164+
writel(hw->imr, hw->base + ALTERA_SPI_CONTROL);
191165

192-
if (hw->count < hw->len)
193-
writel(hw_txbyte(hw, hw->count), hw->base + ALTERA_SPI_TXDATA);
194-
else
195-
complete(&hw->done);
166+
spi_finalize_current_transfer(master);
167+
}
196168

197169
return IRQ_HANDLED;
198170
}
@@ -214,14 +186,10 @@ static int altera_spi_probe(struct platform_device *pdev)
214186
master->mode_bits = SPI_CS_HIGH;
215187
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 16);
216188
master->dev.of_node = pdev->dev.of_node;
189+
master->transfer_one = altera_spi_txrx;
190+
master->set_cs = altera_spi_set_cs;
217191

218192
hw = spi_master_get_devdata(master);
219-
platform_set_drvdata(pdev, hw);
220-
221-
/* setup the state for the bitbang driver */
222-
hw->bitbang.master = master;
223-
hw->bitbang.chipselect = altera_spi_chipsel;
224-
hw->bitbang.txrx_bufs = altera_spi_txrx;
225193

226194
/* find and map our resources */
227195
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -239,15 +207,13 @@ static int altera_spi_probe(struct platform_device *pdev)
239207
/* irq is optional */
240208
hw->irq = platform_get_irq(pdev, 0);
241209
if (hw->irq >= 0) {
242-
init_completion(&hw->done);
243210
err = devm_request_irq(&pdev->dev, hw->irq, altera_spi_irq, 0,
244-
pdev->name, hw);
211+
pdev->name, master);
245212
if (err)
246213
goto exit;
247214
}
248215

249-
/* register our spi controller */
250-
err = spi_bitbang_start(&hw->bitbang);
216+
err = devm_spi_register_master(&pdev->dev, master);
251217
if (err)
252218
goto exit;
253219
dev_info(&pdev->dev, "base %p, irq %d\n", hw->base, hw->irq);
@@ -258,16 +224,6 @@ static int altera_spi_probe(struct platform_device *pdev)
258224
return err;
259225
}
260226

261-
static int altera_spi_remove(struct platform_device *dev)
262-
{
263-
struct altera_spi *hw = platform_get_drvdata(dev);
264-
struct spi_master *master = hw->bitbang.master;
265-
266-
spi_bitbang_stop(&hw->bitbang);
267-
spi_master_put(master);
268-
return 0;
269-
}
270-
271227
#ifdef CONFIG_OF
272228
static const struct of_device_id altera_spi_match[] = {
273229
{ .compatible = "ALTR,spi-1.0", },
@@ -279,7 +235,6 @@ MODULE_DEVICE_TABLE(of, altera_spi_match);
279235

280236
static struct platform_driver altera_spi_driver = {
281237
.probe = altera_spi_probe,
282-
.remove = altera_spi_remove,
283238
.driver = {
284239
.name = DRV_NAME,
285240
.pm = NULL,

drivers/spi/spi-ath79.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ struct ath79_spi {
3939
u32 reg_ctrl;
4040
void __iomem *base;
4141
struct clk *clk;
42-
unsigned rrw_delay;
42+
unsigned int rrw_delay;
4343
};
4444

45-
static inline u32 ath79_spi_rr(struct ath79_spi *sp, unsigned reg)
45+
static inline u32 ath79_spi_rr(struct ath79_spi *sp, unsigned int reg)
4646
{
4747
return ioread32(sp->base + reg);
4848
}
4949

50-
static inline void ath79_spi_wr(struct ath79_spi *sp, unsigned reg, u32 val)
50+
static inline void ath79_spi_wr(struct ath79_spi *sp, unsigned int reg, u32 val)
5151
{
5252
iowrite32(val, sp->base + reg);
5353
}
@@ -57,7 +57,7 @@ static inline struct ath79_spi *ath79_spidev_to_sp(struct spi_device *spi)
5757
return spi_master_get_devdata(spi->master);
5858
}
5959

60-
static inline void ath79_spi_delay(struct ath79_spi *sp, unsigned nsecs)
60+
static inline void ath79_spi_delay(struct ath79_spi *sp, unsigned int nsecs)
6161
{
6262
if (nsecs > sp->rrw_delay)
6363
ndelay(nsecs - sp->rrw_delay);
@@ -148,9 +148,8 @@ static int ath79_spi_setup_cs(struct spi_device *spi)
148148

149149
static void ath79_spi_cleanup_cs(struct spi_device *spi)
150150
{
151-
if (gpio_is_valid(spi->cs_gpio)) {
151+
if (gpio_is_valid(spi->cs_gpio))
152152
gpio_free(spi->cs_gpio);
153-
}
154153
}
155154

156155
static int ath79_spi_setup(struct spi_device *spi)
@@ -176,7 +175,7 @@ static void ath79_spi_cleanup(struct spi_device *spi)
176175
spi_bitbang_cleanup(spi);
177176
}
178177

179-
static u32 ath79_spi_txrx_mode0(struct spi_device *spi, unsigned nsecs,
178+
static u32 ath79_spi_txrx_mode0(struct spi_device *spi, unsigned int nsecs,
180179
u32 word, u8 bits)
181180
{
182181
struct ath79_spi *sp = ath79_spidev_to_sp(spi);

0 commit comments

Comments
 (0)