1
2
3
4
5
6
7
8#include <linux/clk.h>
9#include <linux/delay.h>
10#include <linux/gpio.h>
11#include <linux/interrupt.h>
12#include <linux/io.h>
13#include <linux/module.h>
14#include <linux/of_irq.h>
15#include <linux/of_address.h>
16#include <linux/platform_device.h>
17#include <linux/spi/spi.h>
18#include <linux/workqueue.h>
19#include <linux/spi/spi-mem.h>
20
21
22#define ZYNQ_QSPI_CONFIG_OFFSET 0x00
23#define ZYNQ_QSPI_STATUS_OFFSET 0x04
24#define ZYNQ_QSPI_IEN_OFFSET 0x08
25#define ZYNQ_QSPI_IDIS_OFFSET 0x0C
26#define ZYNQ_QSPI_IMASK_OFFSET 0x10
27#define ZYNQ_QSPI_ENABLE_OFFSET 0x14
28#define ZYNQ_QSPI_DELAY_OFFSET 0x18
29#define ZYNQ_QSPI_TXD_00_00_OFFSET 0x1C
30#define ZYNQ_QSPI_TXD_00_01_OFFSET 0x80
31#define ZYNQ_QSPI_TXD_00_10_OFFSET 0x84
32#define ZYNQ_QSPI_TXD_00_11_OFFSET 0x88
33#define ZYNQ_QSPI_RXD_OFFSET 0x20
34#define ZYNQ_QSPI_SIC_OFFSET 0x24
35#define ZYNQ_QSPI_TX_THRESH_OFFSET 0x28
36#define ZYNQ_QSPI_RX_THRESH_OFFSET 0x2C
37#define ZYNQ_QSPI_GPIO_OFFSET 0x30
38#define ZYNQ_QSPI_LINEAR_CFG_OFFSET 0xA0
39#define ZYNQ_QSPI_MOD_ID_OFFSET 0xFC
40
41
42
43
44
45
46
47#define ZYNQ_QSPI_CONFIG_IFMODE_MASK BIT(31)
48#define ZYNQ_QSPI_CONFIG_MANSRT_MASK BIT(16)
49#define ZYNQ_QSPI_CONFIG_MANSRTEN_MASK BIT(15)
50#define ZYNQ_QSPI_CONFIG_SSFORCE_MASK BIT(14)
51#define ZYNQ_QSPI_CONFIG_BDRATE_MASK GENMASK(5, 3)
52#define ZYNQ_QSPI_CONFIG_CPHA_MASK BIT(2)
53#define ZYNQ_QSPI_CONFIG_CPOL_MASK BIT(1)
54#define ZYNQ_QSPI_CONFIG_SSCTRL_MASK BIT(10)
55#define ZYNQ_QSPI_CONFIG_FWIDTH_MASK GENMASK(7, 6)
56#define ZYNQ_QSPI_CONFIG_MSTREN_MASK BIT(0)
57
58
59
60
61
62
63
64#define ZYNQ_QSPI_BAUD_DIV_MAX GENMASK(2, 0)
65#define ZYNQ_QSPI_BAUD_DIV_SHIFT 3
66#define ZYNQ_QSPI_SS_SHIFT 10
67
68
69
70
71
72
73
74#define ZYNQ_QSPI_IXR_RX_OVERFLOW_MASK BIT(0)
75#define ZYNQ_QSPI_IXR_TXNFULL_MASK BIT(2)
76#define ZYNQ_QSPI_IXR_TXFULL_MASK BIT(3)
77#define ZYNQ_QSPI_IXR_RXNEMTY_MASK BIT(4)
78#define ZYNQ_QSPI_IXR_RXF_FULL_MASK BIT(5)
79#define ZYNQ_QSPI_IXR_TXF_UNDRFLOW_MASK BIT(6)
80#define ZYNQ_QSPI_IXR_ALL_MASK (ZYNQ_QSPI_IXR_RX_OVERFLOW_MASK | \
81 ZYNQ_QSPI_IXR_TXNFULL_MASK | \
82 ZYNQ_QSPI_IXR_TXFULL_MASK | \
83 ZYNQ_QSPI_IXR_RXNEMTY_MASK | \
84 ZYNQ_QSPI_IXR_RXF_FULL_MASK | \
85 ZYNQ_QSPI_IXR_TXF_UNDRFLOW_MASK)
86#define ZYNQ_QSPI_IXR_RXTX_MASK (ZYNQ_QSPI_IXR_TXNFULL_MASK | \
87 ZYNQ_QSPI_IXR_RXNEMTY_MASK)
88
89
90
91
92
93
94#define ZYNQ_QSPI_ENABLE_ENABLE_MASK BIT(0)
95
96
97
98
99
100
101
102#define ZYNQ_QSPI_LCFG_TWO_MEM_MASK BIT(30)
103#define ZYNQ_QSPI_LCFG_SEP_BUS_MASK BIT(29)
104#define ZYNQ_QSPI_LCFG_U_PAGE_MASK BIT(28)
105
106#define ZYNQ_QSPI_LCFG_DUMMY_SHIFT 8
107
108#define ZYNQ_QSPI_FAST_READ_QOUT_CODE 0x6B
109#define ZYNQ_QSPI_FIFO_DEPTH 63
110#define ZYNQ_QSPI_RX_THRESHOLD 32
111#define ZYNQ_QSPI_TX_THRESHOLD 1
112
113
114
115
116
117#define ZYNQ_QSPI_MODEBITS (SPI_CPOL | SPI_CPHA)
118
119
120#define ZYNQ_QSPI_DEFAULT_NUM_CS 1
121
122
123
124
125
126
127
128
129
130
131
132
133
134struct zynq_qspi {
135 struct device *dev;
136 void __iomem *regs;
137 struct clk *refclk;
138 struct clk *pclk;
139 int irq;
140 u8 *txbuf;
141 u8 *rxbuf;
142 int tx_bytes;
143 int rx_bytes;
144 struct completion data_completion;
145};
146
147
148
149
150static inline u32 zynq_qspi_read(struct zynq_qspi *xqspi, u32 offset)
151{
152 return readl_relaxed(xqspi->regs + offset);
153}
154
155static inline void zynq_qspi_write(struct zynq_qspi *xqspi, u32 offset,
156 u32 val)
157{
158 writel_relaxed(val, xqspi->regs + offset);
159}
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181static void zynq_qspi_init_hw(struct zynq_qspi *xqspi)
182{
183 u32 config_reg;
184
185 zynq_qspi_write(xqspi, ZYNQ_QSPI_ENABLE_OFFSET, 0);
186 zynq_qspi_write(xqspi, ZYNQ_QSPI_IDIS_OFFSET, ZYNQ_QSPI_IXR_ALL_MASK);
187
188
189 zynq_qspi_write(xqspi, ZYNQ_QSPI_LINEAR_CFG_OFFSET, 0);
190
191
192 while (zynq_qspi_read(xqspi, ZYNQ_QSPI_STATUS_OFFSET) &
193 ZYNQ_QSPI_IXR_RXNEMTY_MASK)
194 zynq_qspi_read(xqspi, ZYNQ_QSPI_RXD_OFFSET);
195
196 zynq_qspi_write(xqspi, ZYNQ_QSPI_STATUS_OFFSET, ZYNQ_QSPI_IXR_ALL_MASK);
197 config_reg = zynq_qspi_read(xqspi, ZYNQ_QSPI_CONFIG_OFFSET);
198 config_reg &= ~(ZYNQ_QSPI_CONFIG_MSTREN_MASK |
199 ZYNQ_QSPI_CONFIG_CPOL_MASK |
200 ZYNQ_QSPI_CONFIG_CPHA_MASK |
201 ZYNQ_QSPI_CONFIG_BDRATE_MASK |
202 ZYNQ_QSPI_CONFIG_SSFORCE_MASK |
203 ZYNQ_QSPI_CONFIG_MANSRTEN_MASK |
204 ZYNQ_QSPI_CONFIG_MANSRT_MASK);
205 config_reg |= (ZYNQ_QSPI_CONFIG_MSTREN_MASK |
206 ZYNQ_QSPI_CONFIG_SSFORCE_MASK |
207 ZYNQ_QSPI_CONFIG_FWIDTH_MASK |
208 ZYNQ_QSPI_CONFIG_IFMODE_MASK);
209 zynq_qspi_write(xqspi, ZYNQ_QSPI_CONFIG_OFFSET, config_reg);
210
211 zynq_qspi_write(xqspi, ZYNQ_QSPI_RX_THRESH_OFFSET,
212 ZYNQ_QSPI_RX_THRESHOLD);
213 zynq_qspi_write(xqspi, ZYNQ_QSPI_TX_THRESH_OFFSET,
214 ZYNQ_QSPI_TX_THRESHOLD);
215
216 zynq_qspi_write(xqspi, ZYNQ_QSPI_ENABLE_OFFSET,
217 ZYNQ_QSPI_ENABLE_ENABLE_MASK);
218}
219
220static bool zynq_qspi_supports_op(struct spi_mem *mem,
221 const struct spi_mem_op *op)
222{
223 if (!spi_mem_default_supports_op(mem, op))
224 return false;
225
226
227
228
229 if (op->addr.nbytes > 3)
230 return false;
231
232 return true;
233}
234
235
236
237
238
239
240static void zynq_qspi_rxfifo_op(struct zynq_qspi *xqspi, unsigned int size)
241{
242 u32 data;
243
244 data = zynq_qspi_read(xqspi, ZYNQ_QSPI_RXD_OFFSET);
245
246 if (xqspi->rxbuf) {
247 memcpy(xqspi->rxbuf, ((u8 *)&data) + 4 - size, size);
248 xqspi->rxbuf += size;
249 }
250
251 xqspi->rx_bytes -= size;
252 if (xqspi->rx_bytes < 0)
253 xqspi->rx_bytes = 0;
254}
255
256
257
258
259
260
261static void zynq_qspi_txfifo_op(struct zynq_qspi *xqspi, unsigned int size)
262{
263 static const unsigned int offset[4] = {
264 ZYNQ_QSPI_TXD_00_01_OFFSET, ZYNQ_QSPI_TXD_00_10_OFFSET,
265 ZYNQ_QSPI_TXD_00_11_OFFSET, ZYNQ_QSPI_TXD_00_00_OFFSET };
266 u32 data;
267
268 if (xqspi->txbuf) {
269 data = 0xffffffff;
270 memcpy(&data, xqspi->txbuf, size);
271 xqspi->txbuf += size;
272 } else {
273 data = 0;
274 }
275
276 xqspi->tx_bytes -= size;
277 zynq_qspi_write(xqspi, offset[size - 1], data);
278}
279
280
281
282
283
284
285static void zynq_qspi_chipselect(struct spi_device *spi, bool assert)
286{
287 struct spi_controller *ctrl = spi->master;
288 struct zynq_qspi *xqspi = spi_controller_get_devdata(ctrl);
289 u32 config_reg;
290
291 config_reg = zynq_qspi_read(xqspi, ZYNQ_QSPI_CONFIG_OFFSET);
292 if (assert) {
293
294 config_reg &= ~ZYNQ_QSPI_CONFIG_SSCTRL_MASK;
295 config_reg |= (((~(BIT(spi->chip_select))) <<
296 ZYNQ_QSPI_SS_SHIFT) &
297 ZYNQ_QSPI_CONFIG_SSCTRL_MASK);
298 } else {
299 config_reg |= ZYNQ_QSPI_CONFIG_SSCTRL_MASK;
300 }
301
302 zynq_qspi_write(xqspi, ZYNQ_QSPI_CONFIG_OFFSET, config_reg);
303}
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322static int zynq_qspi_config_op(struct zynq_qspi *xqspi, struct spi_device *spi)
323{
324 u32 config_reg, baud_rate_val = 0;
325
326
327
328
329
330
331
332
333
334
335 while ((baud_rate_val < ZYNQ_QSPI_BAUD_DIV_MAX) &&
336 (clk_get_rate(xqspi->refclk) / (2 << baud_rate_val)) >
337 spi->max_speed_hz)
338 baud_rate_val++;
339
340 config_reg = zynq_qspi_read(xqspi, ZYNQ_QSPI_CONFIG_OFFSET);
341
342
343 config_reg &= (~ZYNQ_QSPI_CONFIG_CPHA_MASK) &
344 (~ZYNQ_QSPI_CONFIG_CPOL_MASK);
345 if (spi->mode & SPI_CPHA)
346 config_reg |= ZYNQ_QSPI_CONFIG_CPHA_MASK;
347 if (spi->mode & SPI_CPOL)
348 config_reg |= ZYNQ_QSPI_CONFIG_CPOL_MASK;
349
350 config_reg &= ~ZYNQ_QSPI_CONFIG_BDRATE_MASK;
351 config_reg |= (baud_rate_val << ZYNQ_QSPI_BAUD_DIV_SHIFT);
352 zynq_qspi_write(xqspi, ZYNQ_QSPI_CONFIG_OFFSET, config_reg);
353
354 return 0;
355}
356
357
358
359
360
361
362
363
364
365
366static int zynq_qspi_setup_op(struct spi_device *spi)
367{
368 struct spi_controller *ctrl = spi->master;
369 struct zynq_qspi *qspi = spi_controller_get_devdata(ctrl);
370
371 if (ctrl->busy)
372 return -EBUSY;
373
374 clk_enable(qspi->refclk);
375 clk_enable(qspi->pclk);
376 zynq_qspi_write(qspi, ZYNQ_QSPI_ENABLE_OFFSET,
377 ZYNQ_QSPI_ENABLE_ENABLE_MASK);
378
379 return 0;
380}
381
382
383
384
385
386
387
388static void zynq_qspi_write_op(struct zynq_qspi *xqspi, int txcount,
389 bool txempty)
390{
391 int count, len, k;
392
393 len = xqspi->tx_bytes;
394 if (len && len < 4) {
395
396
397
398
399 if (txempty)
400 zynq_qspi_txfifo_op(xqspi, len);
401
402 return;
403 }
404
405 count = len / 4;
406 if (count > txcount)
407 count = txcount;
408
409 if (xqspi->txbuf) {
410 iowrite32_rep(xqspi->regs + ZYNQ_QSPI_TXD_00_00_OFFSET,
411 xqspi->txbuf, count);
412 xqspi->txbuf += count * 4;
413 } else {
414 for (k = 0; k < count; k++)
415 writel_relaxed(0, xqspi->regs +
416 ZYNQ_QSPI_TXD_00_00_OFFSET);
417 }
418
419 xqspi->tx_bytes -= count * 4;
420}
421
422
423
424
425
426
427static void zynq_qspi_read_op(struct zynq_qspi *xqspi, int rxcount)
428{
429 int count, len, k;
430
431 len = xqspi->rx_bytes - xqspi->tx_bytes;
432 count = len / 4;
433 if (count > rxcount)
434 count = rxcount;
435 if (xqspi->rxbuf) {
436 ioread32_rep(xqspi->regs + ZYNQ_QSPI_RXD_OFFSET,
437 xqspi->rxbuf, count);
438 xqspi->rxbuf += count * 4;
439 } else {
440 for (k = 0; k < count; k++)
441 readl_relaxed(xqspi->regs + ZYNQ_QSPI_RXD_OFFSET);
442 }
443 xqspi->rx_bytes -= count * 4;
444 len -= count * 4;
445
446 if (len && len < 4 && count < rxcount)
447 zynq_qspi_rxfifo_op(xqspi, len);
448}
449
450
451
452
453
454
455
456
457
458
459
460
461static irqreturn_t zynq_qspi_irq(int irq, void *dev_id)
462{
463 u32 intr_status;
464 bool txempty;
465 struct zynq_qspi *xqspi = (struct zynq_qspi *)dev_id;
466
467 intr_status = zynq_qspi_read(xqspi, ZYNQ_QSPI_STATUS_OFFSET);
468 zynq_qspi_write(xqspi, ZYNQ_QSPI_STATUS_OFFSET, intr_status);
469
470 if ((intr_status & ZYNQ_QSPI_IXR_TXNFULL_MASK) ||
471 (intr_status & ZYNQ_QSPI_IXR_RXNEMTY_MASK)) {
472
473
474
475
476
477 txempty = !!(intr_status & ZYNQ_QSPI_IXR_TXNFULL_MASK);
478
479 zynq_qspi_read_op(xqspi, ZYNQ_QSPI_RX_THRESHOLD);
480 if (xqspi->tx_bytes) {
481
482 zynq_qspi_write_op(xqspi, ZYNQ_QSPI_RX_THRESHOLD,
483 txempty);
484 } else {
485
486
487
488
489 if (!xqspi->rx_bytes) {
490 zynq_qspi_write(xqspi,
491 ZYNQ_QSPI_IDIS_OFFSET,
492 ZYNQ_QSPI_IXR_RXTX_MASK);
493 complete(&xqspi->data_completion);
494 }
495 }
496 return IRQ_HANDLED;
497 }
498
499 return IRQ_NONE;
500}
501
502
503
504
505
506
507
508
509
510
511
512
513static int zynq_qspi_exec_mem_op(struct spi_mem *mem,
514 const struct spi_mem_op *op)
515{
516 struct zynq_qspi *xqspi = spi_controller_get_devdata(mem->spi->master);
517 int err = 0, i;
518 u8 *tmpbuf;
519
520 dev_dbg(xqspi->dev, "cmd:%#x mode:%d.%d.%d.%d\n",
521 op->cmd.opcode, op->cmd.buswidth, op->addr.buswidth,
522 op->dummy.buswidth, op->data.buswidth);
523
524 zynq_qspi_chipselect(mem->spi, true);
525 zynq_qspi_config_op(xqspi, mem->spi);
526
527 if (op->cmd.opcode) {
528 reinit_completion(&xqspi->data_completion);
529 xqspi->txbuf = (u8 *)&op->cmd.opcode;
530 xqspi->rxbuf = NULL;
531 xqspi->tx_bytes = sizeof(op->cmd.opcode);
532 xqspi->rx_bytes = sizeof(op->cmd.opcode);
533 zynq_qspi_write_op(xqspi, ZYNQ_QSPI_FIFO_DEPTH, true);
534 zynq_qspi_write(xqspi, ZYNQ_QSPI_IEN_OFFSET,
535 ZYNQ_QSPI_IXR_RXTX_MASK);
536 if (!wait_for_completion_interruptible_timeout(&xqspi->data_completion,
537 msecs_to_jiffies(1000)))
538 err = -ETIMEDOUT;
539 }
540
541 if (op->addr.nbytes) {
542 for (i = 0; i < op->addr.nbytes; i++) {
543 xqspi->txbuf[i] = op->addr.val >>
544 (8 * (op->addr.nbytes - i - 1));
545 }
546
547 reinit_completion(&xqspi->data_completion);
548 xqspi->rxbuf = NULL;
549 xqspi->tx_bytes = op->addr.nbytes;
550 xqspi->rx_bytes = op->addr.nbytes;
551 zynq_qspi_write_op(xqspi, ZYNQ_QSPI_FIFO_DEPTH, true);
552 zynq_qspi_write(xqspi, ZYNQ_QSPI_IEN_OFFSET,
553 ZYNQ_QSPI_IXR_RXTX_MASK);
554 if (!wait_for_completion_interruptible_timeout(&xqspi->data_completion,
555 msecs_to_jiffies(1000)))
556 err = -ETIMEDOUT;
557 }
558
559 if (op->dummy.nbytes) {
560 tmpbuf = kzalloc(op->dummy.nbytes, GFP_KERNEL);
561 memset(tmpbuf, 0xff, op->dummy.nbytes);
562 reinit_completion(&xqspi->data_completion);
563 xqspi->txbuf = tmpbuf;
564 xqspi->rxbuf = NULL;
565 xqspi->tx_bytes = op->dummy.nbytes;
566 xqspi->rx_bytes = op->dummy.nbytes;
567 zynq_qspi_write_op(xqspi, ZYNQ_QSPI_FIFO_DEPTH, true);
568 zynq_qspi_write(xqspi, ZYNQ_QSPI_IEN_OFFSET,
569 ZYNQ_QSPI_IXR_RXTX_MASK);
570 if (!wait_for_completion_interruptible_timeout(&xqspi->data_completion,
571 msecs_to_jiffies(1000)))
572 err = -ETIMEDOUT;
573
574 kfree(tmpbuf);
575 }
576
577 if (op->data.nbytes) {
578 reinit_completion(&xqspi->data_completion);
579 if (op->data.dir == SPI_MEM_DATA_OUT) {
580 xqspi->txbuf = (u8 *)op->data.buf.out;
581 xqspi->tx_bytes = op->data.nbytes;
582 xqspi->rxbuf = NULL;
583 xqspi->rx_bytes = op->data.nbytes;
584 } else {
585 xqspi->txbuf = NULL;
586 xqspi->rxbuf = (u8 *)op->data.buf.in;
587 xqspi->rx_bytes = op->data.nbytes;
588 xqspi->tx_bytes = op->data.nbytes;
589 }
590
591 zynq_qspi_write_op(xqspi, ZYNQ_QSPI_FIFO_DEPTH, true);
592 zynq_qspi_write(xqspi, ZYNQ_QSPI_IEN_OFFSET,
593 ZYNQ_QSPI_IXR_RXTX_MASK);
594 if (!wait_for_completion_interruptible_timeout(&xqspi->data_completion,
595 msecs_to_jiffies(1000)))
596 err = -ETIMEDOUT;
597 }
598 zynq_qspi_chipselect(mem->spi, false);
599
600 return err;
601}
602
603static const struct spi_controller_mem_ops zynq_qspi_mem_ops = {
604 .supports_op = zynq_qspi_supports_op,
605 .exec_op = zynq_qspi_exec_mem_op,
606};
607
608
609
610
611
612
613
614
615
616static int zynq_qspi_probe(struct platform_device *pdev)
617{
618 int ret = 0;
619 struct spi_controller *ctlr;
620 struct device *dev = &pdev->dev;
621 struct device_node *np = dev->of_node;
622 struct zynq_qspi *xqspi;
623 u32 num_cs;
624
625 ctlr = spi_alloc_master(&pdev->dev, sizeof(*xqspi));
626 if (!ctlr)
627 return -ENOMEM;
628
629 xqspi = spi_controller_get_devdata(ctlr);
630 xqspi->dev = dev;
631 platform_set_drvdata(pdev, xqspi);
632 xqspi->regs = devm_platform_ioremap_resource(pdev, 0);
633 if (IS_ERR(xqspi->regs)) {
634 ret = PTR_ERR(xqspi->regs);
635 goto remove_master;
636 }
637
638 xqspi->pclk = devm_clk_get(&pdev->dev, "pclk");
639 if (IS_ERR(xqspi->pclk)) {
640 dev_err(&pdev->dev, "pclk clock not found.\n");
641 ret = PTR_ERR(xqspi->pclk);
642 goto remove_master;
643 }
644
645 init_completion(&xqspi->data_completion);
646
647 xqspi->refclk = devm_clk_get(&pdev->dev, "ref_clk");
648 if (IS_ERR(xqspi->refclk)) {
649 dev_err(&pdev->dev, "ref_clk clock not found.\n");
650 ret = PTR_ERR(xqspi->refclk);
651 goto remove_master;
652 }
653
654 ret = clk_prepare_enable(xqspi->pclk);
655 if (ret) {
656 dev_err(&pdev->dev, "Unable to enable APB clock.\n");
657 goto remove_master;
658 }
659
660 ret = clk_prepare_enable(xqspi->refclk);
661 if (ret) {
662 dev_err(&pdev->dev, "Unable to enable device clock.\n");
663 goto clk_dis_pclk;
664 }
665
666
667 zynq_qspi_init_hw(xqspi);
668
669 xqspi->irq = platform_get_irq(pdev, 0);
670 if (xqspi->irq <= 0) {
671 ret = -ENXIO;
672 goto remove_master;
673 }
674 ret = devm_request_irq(&pdev->dev, xqspi->irq, zynq_qspi_irq,
675 0, pdev->name, xqspi);
676 if (ret != 0) {
677 ret = -ENXIO;
678 dev_err(&pdev->dev, "request_irq failed\n");
679 goto remove_master;
680 }
681
682 ret = of_property_read_u32(np, "num-cs",
683 &num_cs);
684 if (ret < 0)
685 ctlr->num_chipselect = ZYNQ_QSPI_DEFAULT_NUM_CS;
686 else
687 ctlr->num_chipselect = num_cs;
688
689 ctlr->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD |
690 SPI_TX_DUAL | SPI_TX_QUAD;
691 ctlr->mem_ops = &zynq_qspi_mem_ops;
692 ctlr->setup = zynq_qspi_setup_op;
693 ctlr->max_speed_hz = clk_get_rate(xqspi->refclk) / 2;
694 ctlr->dev.of_node = np;
695 ret = devm_spi_register_controller(&pdev->dev, ctlr);
696 if (ret) {
697 dev_err(&pdev->dev, "spi_register_master failed\n");
698 goto clk_dis_all;
699 }
700
701 return ret;
702
703clk_dis_all:
704 clk_disable_unprepare(xqspi->refclk);
705clk_dis_pclk:
706 clk_disable_unprepare(xqspi->pclk);
707remove_master:
708 spi_controller_put(ctlr);
709
710 return ret;
711}
712
713
714
715
716
717
718
719
720
721
722
723static int zynq_qspi_remove(struct platform_device *pdev)
724{
725 struct zynq_qspi *xqspi = platform_get_drvdata(pdev);
726
727 zynq_qspi_write(xqspi, ZYNQ_QSPI_ENABLE_OFFSET, 0);
728
729 clk_disable_unprepare(xqspi->refclk);
730 clk_disable_unprepare(xqspi->pclk);
731
732 return 0;
733}
734
735static const struct of_device_id zynq_qspi_of_match[] = {
736 { .compatible = "xlnx,zynq-qspi-1.0", },
737 { }
738};
739
740MODULE_DEVICE_TABLE(of, zynq_qspi_of_match);
741
742
743
744
745static struct platform_driver zynq_qspi_driver = {
746 .probe = zynq_qspi_probe,
747 .remove = zynq_qspi_remove,
748 .driver = {
749 .name = "zynq-qspi",
750 .of_match_table = zynq_qspi_of_match,
751 },
752};
753
754module_platform_driver(zynq_qspi_driver);
755
756MODULE_AUTHOR("Xilinx, Inc.");
757MODULE_DESCRIPTION("Xilinx Zynq QSPI driver");
758MODULE_LICENSE("GPL");
759