Skip to content

Commit bdc6bf7

Browse files
committed
Merge branch 'at91-4.19-trunk/base_qspi' into linux-4.19-at91
2 parents 229b27d + a290e7b commit bdc6bf7

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

drivers/spi/atmel-quadspi.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ struct atmel_qspi {
154154
void __iomem *mem;
155155
struct clk *clk;
156156
struct platform_device *pdev;
157+
resource_size_t mmap_size;
157158
u32 pending;
159+
u32 scr;
158160
struct completion cmd_completion;
159161
};
160162

@@ -234,6 +236,14 @@ static int atmel_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
234236
u32 iar, icr, ifr, sr;
235237
int err = 0;
236238

239+
/*
240+
* Check if the address exceeds the MMIO window size. An improvement
241+
* would be to add support for regular SPI mode and fall back to it
242+
* when the flash memories overrun the controller's memory space.
243+
*/
244+
if (op->addr.val + op->data.nbytes > aq->mmap_size)
245+
return -EADDRNOTAVAIL;
246+
237247
iar = 0;
238248
icr = QSPI_ICR_INST(op->cmd.opcode);
239249
ifr = QSPI_IFR_INSTEN;
@@ -353,7 +363,7 @@ static int atmel_qspi_setup(struct spi_device *spi)
353363
struct spi_controller *ctrl = spi->master;
354364
struct atmel_qspi *aq = spi_controller_get_devdata(ctrl);
355365
unsigned long src_rate;
356-
u32 scr, scbr;
366+
u32 scbr;
357367

358368
if (ctrl->busy)
359369
return -EBUSY;
@@ -370,21 +380,19 @@ static int atmel_qspi_setup(struct spi_device *spi)
370380
if (scbr > 0)
371381
scbr--;
372382

373-
scr = QSPI_SCR_SCBR(scbr);
374-
qspi_writel(aq, QSPI_SCR, scr);
383+
aq->scr = QSPI_SCR_SCBR(scbr);
384+
writel_relaxed(aq->scr, aq->regs + QSPI_SCR);
375385

376386
return 0;
377387
}
378388

379-
static int atmel_qspi_init(struct atmel_qspi *aq)
389+
static void atmel_qspi_init(struct atmel_qspi *aq)
380390
{
381391
/* Reset the QSPI controller */
382392
qspi_writel(aq, QSPI_CR, QSPI_CR_SWRST);
383393

384394
/* Enable the QSPI controller */
385395
qspi_writel(aq, QSPI_CR, QSPI_CR_QSPIEN);
386-
387-
return 0;
388396
}
389397

390398
static irqreturn_t atmel_qspi_interrupt(int irq, void *dev_id)
@@ -447,6 +455,7 @@ static int atmel_qspi_probe(struct platform_device *pdev)
447455
err = PTR_ERR(aq->mem);
448456
goto exit;
449457
}
458+
aq->mmap_size = resource_size(res);
450459

451460
/* Get the peripheral clock */
452461
aq->clk = devm_clk_get(&pdev->dev, NULL);
@@ -475,9 +484,7 @@ static int atmel_qspi_probe(struct platform_device *pdev)
475484
if (err)
476485
goto disable_clk;
477486

478-
err = atmel_qspi_init(aq);
479-
if (err)
480-
goto disable_clk;
487+
atmel_qspi_init(aq);
481488

482489
err = spi_register_controller(ctrl);
483490
if (err)
@@ -521,7 +528,11 @@ static int __maybe_unused atmel_qspi_resume(struct device *dev)
521528

522529
clk_prepare_enable(aq->clk);
523530

524-
return atmel_qspi_init(aq);
531+
atmel_qspi_init(aq);
532+
533+
writel_relaxed(aq->scr, aq->regs + QSPI_SCR);
534+
535+
return 0;
525536
}
526537

527538
static SIMPLE_DEV_PM_OPS(atmel_qspi_pm_ops, atmel_qspi_suspend,

0 commit comments

Comments
 (0)