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