blob: b4d85fd62ce910505d5f93ae471210d72d97fe55 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Driver for Atmel QSPI Controller
4 *
5 * Copyright (C) 2015 Atmel Corporation
6 * Copyright (C) 2018 Cryptera A/S
7 *
8 * Author: Cyrille Pitchen <cyrille.pitchen@atmel.com>
9 * Author: Piotr Bugalski <bugalski.piotr@gmail.com>
10 *
11 * This driver is based on drivers/mtd/spi-nor/fsl-quadspi.c from Freescale.
12 */
13
14#include <linux/clk.h>
15#include <linux/delay.h>
16#include <linux/err.h>
17#include <linux/interrupt.h>
18#include <linux/io.h>
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/of.h>
22#include <linux/of_platform.h>
23#include <linux/platform_device.h>
24#include <linux/spi/spi-mem.h>
25
26/* QSPI register offsets */
27#define QSPI_CR 0x0000 /* Control Register */
28#define QSPI_MR 0x0004 /* Mode Register */
29#define QSPI_RD 0x0008 /* Receive Data Register */
30#define QSPI_TD 0x000c /* Transmit Data Register */
31#define QSPI_SR 0x0010 /* Status Register */
32#define QSPI_IER 0x0014 /* Interrupt Enable Register */
33#define QSPI_IDR 0x0018 /* Interrupt Disable Register */
34#define QSPI_IMR 0x001c /* Interrupt Mask Register */
35#define QSPI_SCR 0x0020 /* Serial Clock Register */
36
37#define QSPI_IAR 0x0030 /* Instruction Address Register */
38#define QSPI_ICR 0x0034 /* Instruction Code Register */
39#define QSPI_WICR 0x0034 /* Write Instruction Code Register */
40#define QSPI_IFR 0x0038 /* Instruction Frame Register */
41#define QSPI_RICR 0x003C /* Read Instruction Code Register */
42
43#define QSPI_SMR 0x0040 /* Scrambling Mode Register */
44#define QSPI_SKR 0x0044 /* Scrambling Key Register */
45
46#define QSPI_WPMR 0x00E4 /* Write Protection Mode Register */
47#define QSPI_WPSR 0x00E8 /* Write Protection Status Register */
48
49#define QSPI_VERSION 0x00FC /* Version Register */
50
51
52/* Bitfields in QSPI_CR (Control Register) */
53#define QSPI_CR_QSPIEN BIT(0)
54#define QSPI_CR_QSPIDIS BIT(1)
55#define QSPI_CR_SWRST BIT(7)
56#define QSPI_CR_LASTXFER BIT(24)
57
58/* Bitfields in QSPI_MR (Mode Register) */
59#define QSPI_MR_SMM BIT(0)
60#define QSPI_MR_LLB BIT(1)
61#define QSPI_MR_WDRBT BIT(2)
62#define QSPI_MR_SMRM BIT(3)
63#define QSPI_MR_CSMODE_MASK GENMASK(5, 4)
64#define QSPI_MR_CSMODE_NOT_RELOADED (0 << 4)
65#define QSPI_MR_CSMODE_LASTXFER (1 << 4)
66#define QSPI_MR_CSMODE_SYSTEMATICALLY (2 << 4)
67#define QSPI_MR_NBBITS_MASK GENMASK(11, 8)
68#define QSPI_MR_NBBITS(n) ((((n) - 8) << 8) & QSPI_MR_NBBITS_MASK)
69#define QSPI_MR_DLYBCT_MASK GENMASK(23, 16)
70#define QSPI_MR_DLYBCT(n) (((n) << 16) & QSPI_MR_DLYBCT_MASK)
71#define QSPI_MR_DLYCS_MASK GENMASK(31, 24)
72#define QSPI_MR_DLYCS(n) (((n) << 24) & QSPI_MR_DLYCS_MASK)
73
74/* Bitfields in QSPI_SR/QSPI_IER/QSPI_IDR/QSPI_IMR */
75#define QSPI_SR_RDRF BIT(0)
76#define QSPI_SR_TDRE BIT(1)
77#define QSPI_SR_TXEMPTY BIT(2)
78#define QSPI_SR_OVRES BIT(3)
79#define QSPI_SR_CSR BIT(8)
80#define QSPI_SR_CSS BIT(9)
81#define QSPI_SR_INSTRE BIT(10)
82#define QSPI_SR_QSPIENS BIT(24)
83
84#define QSPI_SR_CMD_COMPLETED (QSPI_SR_INSTRE | QSPI_SR_CSR)
85
86/* Bitfields in QSPI_SCR (Serial Clock Register) */
87#define QSPI_SCR_CPOL BIT(0)
88#define QSPI_SCR_CPHA BIT(1)
89#define QSPI_SCR_SCBR_MASK GENMASK(15, 8)
90#define QSPI_SCR_SCBR(n) (((n) << 8) & QSPI_SCR_SCBR_MASK)
91#define QSPI_SCR_DLYBS_MASK GENMASK(23, 16)
92#define QSPI_SCR_DLYBS(n) (((n) << 16) & QSPI_SCR_DLYBS_MASK)
93
94/* Bitfields in QSPI_ICR (Read/Write Instruction Code Register) */
95#define QSPI_ICR_INST_MASK GENMASK(7, 0)
96#define QSPI_ICR_INST(inst) (((inst) << 0) & QSPI_ICR_INST_MASK)
97#define QSPI_ICR_OPT_MASK GENMASK(23, 16)
98#define QSPI_ICR_OPT(opt) (((opt) << 16) & QSPI_ICR_OPT_MASK)
99
100/* Bitfields in QSPI_IFR (Instruction Frame Register) */
101#define QSPI_IFR_WIDTH_MASK GENMASK(2, 0)
102#define QSPI_IFR_WIDTH_SINGLE_BIT_SPI (0 << 0)
103#define QSPI_IFR_WIDTH_DUAL_OUTPUT (1 << 0)
104#define QSPI_IFR_WIDTH_QUAD_OUTPUT (2 << 0)
105#define QSPI_IFR_WIDTH_DUAL_IO (3 << 0)
106#define QSPI_IFR_WIDTH_QUAD_IO (4 << 0)
107#define QSPI_IFR_WIDTH_DUAL_CMD (5 << 0)
108#define QSPI_IFR_WIDTH_QUAD_CMD (6 << 0)
109#define QSPI_IFR_INSTEN BIT(4)
110#define QSPI_IFR_ADDREN BIT(5)
111#define QSPI_IFR_OPTEN BIT(6)
112#define QSPI_IFR_DATAEN BIT(7)
113#define QSPI_IFR_OPTL_MASK GENMASK(9, 8)
114#define QSPI_IFR_OPTL_1BIT (0 << 8)
115#define QSPI_IFR_OPTL_2BIT (1 << 8)
116#define QSPI_IFR_OPTL_4BIT (2 << 8)
117#define QSPI_IFR_OPTL_8BIT (3 << 8)
118#define QSPI_IFR_ADDRL BIT(10)
119#define QSPI_IFR_TFRTYP_MEM BIT(12)
120#define QSPI_IFR_SAMA5D2_WRITE_TRSFR BIT(13)
121#define QSPI_IFR_CRM BIT(14)
122#define QSPI_IFR_NBDUM_MASK GENMASK(20, 16)
123#define QSPI_IFR_NBDUM(n) (((n) << 16) & QSPI_IFR_NBDUM_MASK)
124#define QSPI_IFR_APBTFRTYP_READ BIT(24) /* Defined in SAM9X60 */
125
126/* Bitfields in QSPI_SMR (Scrambling Mode Register) */
127#define QSPI_SMR_SCREN BIT(0)
128#define QSPI_SMR_RVDIS BIT(1)
129
130/* Bitfields in QSPI_WPMR (Write Protection Mode Register) */
131#define QSPI_WPMR_WPEN BIT(0)
132#define QSPI_WPMR_WPKEY_MASK GENMASK(31, 8)
133#define QSPI_WPMR_WPKEY(wpkey) (((wpkey) << 8) & QSPI_WPMR_WPKEY_MASK)
134
135/* Bitfields in QSPI_WPSR (Write Protection Status Register) */
136#define QSPI_WPSR_WPVS BIT(0)
137#define QSPI_WPSR_WPVSRC_MASK GENMASK(15, 8)
138#define QSPI_WPSR_WPVSRC(src) (((src) << 8) & QSPI_WPSR_WPVSRC)
139
140struct atmel_qspi_caps {
141 bool has_qspick;
142 bool has_ricr;
143};
144
145struct atmel_qspi {
146 void __iomem *regs;
147 void __iomem *mem;
148 struct clk *pclk;
149 struct clk *qspick;
150 struct platform_device *pdev;
151 const struct atmel_qspi_caps *caps;
152 resource_size_t mmap_size;
153 u32 pending;
154 u32 mr;
155 u32 scr;
156 struct completion cmd_completion;
157};
158
159struct atmel_qspi_mode {
160 u8 cmd_buswidth;
161 u8 addr_buswidth;
162 u8 data_buswidth;
163 u32 config;
164};
165
166static const struct atmel_qspi_mode atmel_qspi_modes[] = {
167 { 1, 1, 1, QSPI_IFR_WIDTH_SINGLE_BIT_SPI },
168 { 1, 1, 2, QSPI_IFR_WIDTH_DUAL_OUTPUT },
169 { 1, 1, 4, QSPI_IFR_WIDTH_QUAD_OUTPUT },
170 { 1, 2, 2, QSPI_IFR_WIDTH_DUAL_IO },
171 { 1, 4, 4, QSPI_IFR_WIDTH_QUAD_IO },
172 { 2, 2, 2, QSPI_IFR_WIDTH_DUAL_CMD },
173 { 4, 4, 4, QSPI_IFR_WIDTH_QUAD_CMD },
174};
175
176static inline bool atmel_qspi_is_compatible(const struct spi_mem_op *op,
177 const struct atmel_qspi_mode *mode)
178{
179 if (op->cmd.buswidth != mode->cmd_buswidth)
180 return false;
181
182 if (op->addr.nbytes && op->addr.buswidth != mode->addr_buswidth)
183 return false;
184
185 if (op->data.nbytes && op->data.buswidth != mode->data_buswidth)
186 return false;
187
188 return true;
189}
190
191static int atmel_qspi_find_mode(const struct spi_mem_op *op)
192{
193 u32 i;
194
195 for (i = 0; i < ARRAY_SIZE(atmel_qspi_modes); i++)
196 if (atmel_qspi_is_compatible(op, &atmel_qspi_modes[i]))
197 return i;
198
199 return -ENOTSUPP;
200}
201
202static bool atmel_qspi_supports_op(struct spi_mem *mem,
203 const struct spi_mem_op *op)
204{
205 if (!spi_mem_default_supports_op(mem, op))
206 return false;
207
208 if (atmel_qspi_find_mode(op) < 0)
209 return false;
210
211 /* special case not supported by hardware */
212 if (op->addr.nbytes == 2 && op->cmd.buswidth != op->addr.buswidth &&
213 op->dummy.nbytes == 0)
214 return false;
215
216 return true;
217}
218
219static int atmel_qspi_set_cfg(struct atmel_qspi *aq,
220 const struct spi_mem_op *op, u32 *offset)
221{
222 u32 iar, icr, ifr;
223 u32 dummy_cycles = 0;
224 int mode;
225
226 iar = 0;
227 icr = QSPI_ICR_INST(op->cmd.opcode);
228 ifr = QSPI_IFR_INSTEN;
229
230 mode = atmel_qspi_find_mode(op);
231 if (mode < 0)
232 return mode;
233 ifr |= atmel_qspi_modes[mode].config;
234
235 if (op->dummy.buswidth && op->dummy.nbytes)
236 dummy_cycles = op->dummy.nbytes * 8 / op->dummy.buswidth;
237
238 /*
239 * The controller allows 24 and 32-bit addressing while NAND-flash
240 * requires 16-bit long. Handling 8-bit long addresses is done using
241 * the option field. For the 16-bit addresses, the workaround depends
242 * of the number of requested dummy bits. If there are 8 or more dummy
243 * cycles, the address is shifted and sent with the first dummy byte.
244 * Otherwise opcode is disabled and the first byte of the address
245 * contains the command opcode (works only if the opcode and address
246 * use the same buswidth). The limitation is when the 16-bit address is
247 * used without enough dummy cycles and the opcode is using a different
248 * buswidth than the address.
249 */
250 if (op->addr.buswidth) {
251 switch (op->addr.nbytes) {
252 case 0:
253 break;
254 case 1:
255 ifr |= QSPI_IFR_OPTEN | QSPI_IFR_OPTL_8BIT;
256 icr |= QSPI_ICR_OPT(op->addr.val & 0xff);
257 break;
258 case 2:
259 if (dummy_cycles < 8 / op->addr.buswidth) {
260 ifr &= ~QSPI_IFR_INSTEN;
261 ifr |= QSPI_IFR_ADDREN;
262 iar = (op->cmd.opcode << 16) |
263 (op->addr.val & 0xffff);
264 } else {
265 ifr |= QSPI_IFR_ADDREN;
266 iar = (op->addr.val << 8) & 0xffffff;
267 dummy_cycles -= 8 / op->addr.buswidth;
268 }
269 break;
270 case 3:
271 ifr |= QSPI_IFR_ADDREN;
272 iar = op->addr.val & 0xffffff;
273 break;
274 case 4:
275 ifr |= QSPI_IFR_ADDREN | QSPI_IFR_ADDRL;
276 iar = op->addr.val & 0x7ffffff;
277 break;
278 default:
279 return -ENOTSUPP;
280 }
281 }
282
283 /* offset of the data access in the QSPI memory space */
284 *offset = iar;
285
286 /* Set number of dummy cycles */
287 if (dummy_cycles)
288 ifr |= QSPI_IFR_NBDUM(dummy_cycles);
289
290 /* Set data enable and data transfer type. */
291 if (op->data.nbytes) {
292 ifr |= QSPI_IFR_DATAEN;
293
294 if (op->addr.nbytes)
295 ifr |= QSPI_IFR_TFRTYP_MEM;
296 }
297
298 /*
299 * If the QSPI controller is set in regular SPI mode, set it in
300 * Serial Memory Mode (SMM).
301 */
302 if (aq->mr != QSPI_MR_SMM) {
303 writel_relaxed(QSPI_MR_SMM, aq->regs + QSPI_MR);
304 aq->mr = QSPI_MR_SMM;
305 }
306
307 /* Clear pending interrupts */
308 (void)readl_relaxed(aq->regs + QSPI_SR);
309
310 if (aq->caps->has_ricr) {
311 if (!op->addr.nbytes && op->data.dir == SPI_MEM_DATA_IN)
312 ifr |= QSPI_IFR_APBTFRTYP_READ;
313
314 /* Set QSPI Instruction Frame registers */
315 writel_relaxed(iar, aq->regs + QSPI_IAR);
316 if (op->data.dir == SPI_MEM_DATA_IN)
317 writel_relaxed(icr, aq->regs + QSPI_RICR);
318 else
319 writel_relaxed(icr, aq->regs + QSPI_WICR);
320 writel_relaxed(ifr, aq->regs + QSPI_IFR);
321 } else {
322 if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_OUT)
323 ifr |= QSPI_IFR_SAMA5D2_WRITE_TRSFR;
324
325 /* Set QSPI Instruction Frame registers */
326 writel_relaxed(iar, aq->regs + QSPI_IAR);
327 writel_relaxed(icr, aq->regs + QSPI_ICR);
328 writel_relaxed(ifr, aq->regs + QSPI_IFR);
329 }
330
331 return 0;
332}
333
334static int atmel_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
335{
336 struct atmel_qspi *aq = spi_controller_get_devdata(mem->spi->master);
337 u32 sr, offset;
338 int err;
339
340 /*
341 * Check if the address exceeds the MMIO window size. An improvement
342 * would be to add support for regular SPI mode and fall back to it
343 * when the flash memories overrun the controller's memory space.
344 */
345 if (op->addr.val + op->data.nbytes > aq->mmap_size)
346 return -ENOTSUPP;
347
348 err = atmel_qspi_set_cfg(aq, op, &offset);
349 if (err)
350 return err;
351
352 /* Skip to the final steps if there is no data */
353 if (op->data.nbytes) {
354 /* Dummy read of QSPI_IFR to synchronize APB and AHB accesses */
355 (void)readl_relaxed(aq->regs + QSPI_IFR);
356
357 /* Send/Receive data */
358 if (op->data.dir == SPI_MEM_DATA_IN)
359 _memcpy_fromio(op->data.buf.in, aq->mem + offset,
360 op->data.nbytes);
361 else
362 _memcpy_toio(aq->mem + offset, op->data.buf.out,
363 op->data.nbytes);
364
365 /* Release the chip-select */
366 writel_relaxed(QSPI_CR_LASTXFER, aq->regs + QSPI_CR);
367 }
368
369 /* Poll INSTRuction End status */
370 sr = readl_relaxed(aq->regs + QSPI_SR);
371 if ((sr & QSPI_SR_CMD_COMPLETED) == QSPI_SR_CMD_COMPLETED)
372 return err;
373
374 /* Wait for INSTRuction End interrupt */
375 reinit_completion(&aq->cmd_completion);
376 aq->pending = sr & QSPI_SR_CMD_COMPLETED;
377 writel_relaxed(QSPI_SR_CMD_COMPLETED, aq->regs + QSPI_IER);
378 if (!wait_for_completion_timeout(&aq->cmd_completion,
379 msecs_to_jiffies(1000)))
380 err = -ETIMEDOUT;
381 writel_relaxed(QSPI_SR_CMD_COMPLETED, aq->regs + QSPI_IDR);
382
383 return err;
384}
385
386static const char *atmel_qspi_get_name(struct spi_mem *spimem)
387{
388 return dev_name(spimem->spi->dev.parent);
389}
390
391static const struct spi_controller_mem_ops atmel_qspi_mem_ops = {
392 .supports_op = atmel_qspi_supports_op,
393 .exec_op = atmel_qspi_exec_op,
394 .get_name = atmel_qspi_get_name
395};
396
397static int atmel_qspi_setup(struct spi_device *spi)
398{
399 struct spi_controller *ctrl = spi->master;
400 struct atmel_qspi *aq = spi_controller_get_devdata(ctrl);
401 unsigned long src_rate;
402 u32 scbr;
403
404 if (ctrl->busy)
405 return -EBUSY;
406
407 if (!spi->max_speed_hz)
408 return -EINVAL;
409
410 src_rate = clk_get_rate(aq->pclk);
411 if (!src_rate)
412 return -EINVAL;
413
414 /* Compute the QSPI baudrate */
415 scbr = DIV_ROUND_UP(src_rate, spi->max_speed_hz);
416 if (scbr > 0)
417 scbr--;
418
419 aq->scr = QSPI_SCR_SCBR(scbr);
420 writel_relaxed(aq->scr, aq->regs + QSPI_SCR);
421
422 return 0;
423}
424
425static void atmel_qspi_init(struct atmel_qspi *aq)
426{
427 /* Reset the QSPI controller */
428 writel_relaxed(QSPI_CR_SWRST, aq->regs + QSPI_CR);
429
430 /* Set the QSPI controller by default in Serial Memory Mode */
431 writel_relaxed(QSPI_MR_SMM, aq->regs + QSPI_MR);
432 aq->mr = QSPI_MR_SMM;
433
434 /* Enable the QSPI controller */
435 writel_relaxed(QSPI_CR_QSPIEN, aq->regs + QSPI_CR);
436}
437
438static irqreturn_t atmel_qspi_interrupt(int irq, void *dev_id)
439{
440 struct atmel_qspi *aq = dev_id;
441 u32 status, mask, pending;
442
443 status = readl_relaxed(aq->regs + QSPI_SR);
444 mask = readl_relaxed(aq->regs + QSPI_IMR);
445 pending = status & mask;
446
447 if (!pending)
448 return IRQ_NONE;
449
450 aq->pending |= pending;
451 if ((aq->pending & QSPI_SR_CMD_COMPLETED) == QSPI_SR_CMD_COMPLETED)
452 complete(&aq->cmd_completion);
453
454 return IRQ_HANDLED;
455}
456
457static int atmel_qspi_probe(struct platform_device *pdev)
458{
459 struct spi_controller *ctrl;
460 struct atmel_qspi *aq;
461 struct resource *res;
462 int irq, err = 0;
463
464 ctrl = devm_spi_alloc_master(&pdev->dev, sizeof(*aq));
465 if (!ctrl)
466 return -ENOMEM;
467
468 ctrl->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD | SPI_TX_DUAL | SPI_TX_QUAD;
469 ctrl->setup = atmel_qspi_setup;
470 ctrl->bus_num = -1;
471 ctrl->mem_ops = &atmel_qspi_mem_ops;
472 ctrl->num_chipselect = 1;
473 ctrl->dev.of_node = pdev->dev.of_node;
474 platform_set_drvdata(pdev, ctrl);
475
476 aq = spi_controller_get_devdata(ctrl);
477
478 init_completion(&aq->cmd_completion);
479 aq->pdev = pdev;
480
481 /* Map the registers */
482 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qspi_base");
483 aq->regs = devm_ioremap_resource(&pdev->dev, res);
484 if (IS_ERR(aq->regs)) {
485 dev_err(&pdev->dev, "missing registers\n");
486 return PTR_ERR(aq->regs);
487 }
488
489 /* Map the AHB memory */
490 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qspi_mmap");
491 aq->mem = devm_ioremap_resource(&pdev->dev, res);
492 if (IS_ERR(aq->mem)) {
493 dev_err(&pdev->dev, "missing AHB memory\n");
494 return PTR_ERR(aq->mem);
495 }
496
497 aq->mmap_size = resource_size(res);
498
499 /* Get the peripheral clock */
500 aq->pclk = devm_clk_get(&pdev->dev, "pclk");
501 if (IS_ERR(aq->pclk))
502 aq->pclk = devm_clk_get(&pdev->dev, NULL);
503
504 if (IS_ERR(aq->pclk)) {
505 dev_err(&pdev->dev, "missing peripheral clock\n");
506 return PTR_ERR(aq->pclk);
507 }
508
509 /* Enable the peripheral clock */
510 err = clk_prepare_enable(aq->pclk);
511 if (err) {
512 dev_err(&pdev->dev, "failed to enable the peripheral clock\n");
513 return err;
514 }
515
516 aq->caps = of_device_get_match_data(&pdev->dev);
517 if (!aq->caps) {
518 dev_err(&pdev->dev, "Could not retrieve QSPI caps\n");
519 err = -EINVAL;
520 goto disable_pclk;
521 }
522
523 if (aq->caps->has_qspick) {
524 /* Get the QSPI system clock */
525 aq->qspick = devm_clk_get(&pdev->dev, "qspick");
526 if (IS_ERR(aq->qspick)) {
527 dev_err(&pdev->dev, "missing system clock\n");
528 err = PTR_ERR(aq->qspick);
529 goto disable_pclk;
530 }
531
532 /* Enable the QSPI system clock */
533 err = clk_prepare_enable(aq->qspick);
534 if (err) {
535 dev_err(&pdev->dev,
536 "failed to enable the QSPI system clock\n");
537 goto disable_pclk;
538 }
539 }
540
541 /* Request the IRQ */
542 irq = platform_get_irq(pdev, 0);
543 if (irq < 0) {
544 err = irq;
545 goto disable_qspick;
546 }
547 err = devm_request_irq(&pdev->dev, irq, atmel_qspi_interrupt,
548 0, dev_name(&pdev->dev), aq);
549 if (err)
550 goto disable_qspick;
551
552 atmel_qspi_init(aq);
553
554 err = spi_register_controller(ctrl);
555 if (err)
556 goto disable_qspick;
557
558 return 0;
559
560disable_qspick:
561 clk_disable_unprepare(aq->qspick);
562disable_pclk:
563 clk_disable_unprepare(aq->pclk);
564
565 return err;
566}
567
568static int atmel_qspi_remove(struct platform_device *pdev)
569{
570 struct spi_controller *ctrl = platform_get_drvdata(pdev);
571 struct atmel_qspi *aq = spi_controller_get_devdata(ctrl);
572
573 spi_unregister_controller(ctrl);
574 writel_relaxed(QSPI_CR_QSPIDIS, aq->regs + QSPI_CR);
575 clk_disable_unprepare(aq->qspick);
576 clk_disable_unprepare(aq->pclk);
577 return 0;
578}
579
580static int __maybe_unused atmel_qspi_suspend(struct device *dev)
581{
582 struct spi_controller *ctrl = dev_get_drvdata(dev);
583 struct atmel_qspi *aq = spi_controller_get_devdata(ctrl);
584
585 clk_disable_unprepare(aq->qspick);
586 clk_disable_unprepare(aq->pclk);
587
588 return 0;
589}
590
591static int __maybe_unused atmel_qspi_resume(struct device *dev)
592{
593 struct spi_controller *ctrl = dev_get_drvdata(dev);
594 struct atmel_qspi *aq = spi_controller_get_devdata(ctrl);
595
596 clk_prepare_enable(aq->pclk);
597 clk_prepare_enable(aq->qspick);
598
599 atmel_qspi_init(aq);
600
601 writel_relaxed(aq->scr, aq->regs + QSPI_SCR);
602
603 return 0;
604}
605
606static SIMPLE_DEV_PM_OPS(atmel_qspi_pm_ops, atmel_qspi_suspend,
607 atmel_qspi_resume);
608
609static const struct atmel_qspi_caps atmel_sama5d2_qspi_caps = {};
610
611static const struct atmel_qspi_caps atmel_sam9x60_qspi_caps = {
612 .has_qspick = true,
613 .has_ricr = true,
614};
615
616static const struct of_device_id atmel_qspi_dt_ids[] = {
617 {
618 .compatible = "atmel,sama5d2-qspi",
619 .data = &atmel_sama5d2_qspi_caps,
620 },
621 {
622 .compatible = "microchip,sam9x60-qspi",
623 .data = &atmel_sam9x60_qspi_caps,
624 },
625 { /* sentinel */ }
626};
627
628MODULE_DEVICE_TABLE(of, atmel_qspi_dt_ids);
629
630static struct platform_driver atmel_qspi_driver = {
631 .driver = {
632 .name = "atmel_qspi",
633 .of_match_table = atmel_qspi_dt_ids,
634 .pm = &atmel_qspi_pm_ops,
635 },
636 .probe = atmel_qspi_probe,
637 .remove = atmel_qspi_remove,
638};
639module_platform_driver(atmel_qspi_driver);
640
641MODULE_AUTHOR("Cyrille Pitchen <cyrille.pitchen@atmel.com>");
642MODULE_AUTHOR("Piotr Bugalski <bugalski.piotr@gmail.com");
643MODULE_DESCRIPTION("Atmel QSPI Controller driver");
644MODULE_LICENSE("GPL v2");