Skip to content

Commit b771327

Browse files
author
Boris Brezillon
committed
Merge tag 'spi-nor/for-4.18' of git://git.infradead.org/linux-mtd into mtd/next
Core changes: - Add support for a bunch of SPI NOR chips - Clear EAR reg when switching to 3-byte addressing mode on Winbond chips SPI NOR controller driver changes: - cadence: Add DMA support for direct mode reads - hisi: Prefix a few functions with hisi_ - intel: * Mark the driver as "dangerous" in Kconfig * Fix atomic sequence handling * Pass a 40us delay (instead of 0us) to readl_poll_timeout() - fsl: * fix a typo in a function name * add support for IP variants embedded in the ls2080a and ls1080a SoCs - stm32: request exclusive control of the reset line
2 parents 6e89b84 + 771ff17 commit b771327

8 files changed

Lines changed: 220 additions & 24 deletions

File tree

‎drivers/mtd/spi-nor/Kconfig‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ config SPI_INTEL_SPI
9090
tristate
9191

9292
config SPI_INTEL_SPI_PCI
93-
tristate "Intel PCH/PCU SPI flash PCI driver"
93+
tristate "Intel PCH/PCU SPI flash PCI driver (DANGEROUS)"
9494
depends on X86 && PCI
9595
select SPI_INTEL_SPI
9696
help
@@ -106,7 +106,7 @@ config SPI_INTEL_SPI_PCI
106106
will be called intel-spi-pci.
107107

108108
config SPI_INTEL_SPI_PLATFORM
109-
tristate "Intel PCH/PCU SPI flash platform driver"
109+
tristate "Intel PCH/PCU SPI flash platform driver (DANGEROUS)"
110110
depends on X86
111111
select SPI_INTEL_SPI
112112
help

‎drivers/mtd/spi-nor/cadence-quadspi.c‎

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <linux/clk.h>
1919
#include <linux/completion.h>
2020
#include <linux/delay.h>
21+
#include <linux/dma-mapping.h>
22+
#include <linux/dmaengine.h>
2123
#include <linux/err.h>
2224
#include <linux/errno.h>
2325
#include <linux/interrupt.h>
@@ -73,6 +75,10 @@ struct cqspi_st {
7375
struct completion transfer_complete;
7476
struct mutex bus_mutex;
7577

78+
struct dma_chan *rx_chan;
79+
struct completion rx_dma_complete;
80+
dma_addr_t mmap_phys_base;
81+
7682
int current_cs;
7783
int current_page_size;
7884
int current_erase_size;
@@ -915,11 +921,75 @@ static ssize_t cqspi_write(struct spi_nor *nor, loff_t to,
915921
return len;
916922
}
917923

924+
static void cqspi_rx_dma_callback(void *param)
925+
{
926+
struct cqspi_st *cqspi = param;
927+
928+
complete(&cqspi->rx_dma_complete);
929+
}
930+
931+
static int cqspi_direct_read_execute(struct spi_nor *nor, u_char *buf,
932+
loff_t from, size_t len)
933+
{
934+
struct cqspi_flash_pdata *f_pdata = nor->priv;
935+
struct cqspi_st *cqspi = f_pdata->cqspi;
936+
enum dma_ctrl_flags flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
937+
dma_addr_t dma_src = (dma_addr_t)cqspi->mmap_phys_base + from;
938+
int ret = 0;
939+
struct dma_async_tx_descriptor *tx;
940+
dma_cookie_t cookie;
941+
dma_addr_t dma_dst;
942+
943+
if (!cqspi->rx_chan || !virt_addr_valid(buf)) {
944+
memcpy_fromio(buf, cqspi->ahb_base + from, len);
945+
return 0;
946+
}
947+
948+
dma_dst = dma_map_single(nor->dev, buf, len, DMA_DEV_TO_MEM);
949+
if (dma_mapping_error(nor->dev, dma_dst)) {
950+
dev_err(nor->dev, "dma mapping failed\n");
951+
return -ENOMEM;
952+
}
953+
tx = dmaengine_prep_dma_memcpy(cqspi->rx_chan, dma_dst, dma_src,
954+
len, flags);
955+
if (!tx) {
956+
dev_err(nor->dev, "device_prep_dma_memcpy error\n");
957+
ret = -EIO;
958+
goto err_unmap;
959+
}
960+
961+
tx->callback = cqspi_rx_dma_callback;
962+
tx->callback_param = cqspi;
963+
cookie = tx->tx_submit(tx);
964+
reinit_completion(&cqspi->rx_dma_complete);
965+
966+
ret = dma_submit_error(cookie);
967+
if (ret) {
968+
dev_err(nor->dev, "dma_submit_error %d\n", cookie);
969+
ret = -EIO;
970+
goto err_unmap;
971+
}
972+
973+
dma_async_issue_pending(cqspi->rx_chan);
974+
ret = wait_for_completion_timeout(&cqspi->rx_dma_complete,
975+
msecs_to_jiffies(len));
976+
if (ret <= 0) {
977+
dmaengine_terminate_sync(cqspi->rx_chan);
978+
dev_err(nor->dev, "DMA wait_for_completion_timeout\n");
979+
ret = -ETIMEDOUT;
980+
goto err_unmap;
981+
}
982+
983+
err_unmap:
984+
dma_unmap_single(nor->dev, dma_dst, len, DMA_DEV_TO_MEM);
985+
986+
return 0;
987+
}
988+
918989
static ssize_t cqspi_read(struct spi_nor *nor, loff_t from,
919990
size_t len, u_char *buf)
920991
{
921992
struct cqspi_flash_pdata *f_pdata = nor->priv;
922-
struct cqspi_st *cqspi = f_pdata->cqspi;
923993
int ret;
924994

925995
ret = cqspi_set_protocol(nor, 1);
@@ -931,7 +1001,7 @@ static ssize_t cqspi_read(struct spi_nor *nor, loff_t from,
9311001
return ret;
9321002

9331003
if (f_pdata->use_direct_mode)
934-
memcpy_fromio(buf, cqspi->ahb_base + from, len);
1004+
ret = cqspi_direct_read_execute(nor, buf, from, len);
9351005
else
9361006
ret = cqspi_indirect_read_execute(nor, buf, from, len);
9371007
if (ret)
@@ -1100,6 +1170,21 @@ static void cqspi_controller_init(struct cqspi_st *cqspi)
11001170
cqspi_controller_enable(cqspi, 1);
11011171
}
11021172

1173+
static void cqspi_request_mmap_dma(struct cqspi_st *cqspi)
1174+
{
1175+
dma_cap_mask_t mask;
1176+
1177+
dma_cap_zero(mask);
1178+
dma_cap_set(DMA_MEMCPY, mask);
1179+
1180+
cqspi->rx_chan = dma_request_chan_by_mask(&mask);
1181+
if (IS_ERR(cqspi->rx_chan)) {
1182+
dev_err(&cqspi->pdev->dev, "No Rx DMA available\n");
1183+
cqspi->rx_chan = NULL;
1184+
}
1185+
init_completion(&cqspi->rx_dma_complete);
1186+
}
1187+
11031188
static int cqspi_setup_flash(struct cqspi_st *cqspi, struct device_node *np)
11041189
{
11051190
const struct spi_nor_hwcaps hwcaps = {
@@ -1177,6 +1262,9 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi, struct device_node *np)
11771262
f_pdata->use_direct_mode = true;
11781263
dev_dbg(nor->dev, "using direct mode for %s\n",
11791264
mtd->name);
1265+
1266+
if (!cqspi->rx_chan)
1267+
cqspi_request_mmap_dma(cqspi);
11801268
}
11811269
}
11821270

@@ -1237,6 +1325,7 @@ static int cqspi_probe(struct platform_device *pdev)
12371325
dev_err(dev, "Cannot remap AHB address.\n");
12381326
return PTR_ERR(cqspi->ahb_base);
12391327
}
1328+
cqspi->mmap_phys_base = (dma_addr_t)res_ahb->start;
12401329
cqspi->ahb_size = resource_size(res_ahb);
12411330

12421331
init_completion(&cqspi->transfer_complete);
@@ -1307,6 +1396,9 @@ static int cqspi_remove(struct platform_device *pdev)
13071396

13081397
cqspi_controller_enable(cqspi, 0);
13091398

1399+
if (cqspi->rx_chan)
1400+
dma_release_channel(cqspi->rx_chan);
1401+
13101402
clk_disable_unprepare(cqspi->clk);
13111403

13121404
pm_runtime_put_sync(&pdev->dev);

‎drivers/mtd/spi-nor/fsl-quadspi.c‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ enum fsl_qspi_devtype {
214214
FSL_QUADSPI_IMX7D,
215215
FSL_QUADSPI_IMX6UL,
216216
FSL_QUADSPI_LS1021A,
217+
FSL_QUADSPI_LS2080A,
217218
};
218219

219220
struct fsl_qspi_devtype_data {
@@ -267,6 +268,15 @@ static struct fsl_qspi_devtype_data ls1021a_data = {
267268
.driver_data = 0,
268269
};
269270

271+
static const struct fsl_qspi_devtype_data ls2080a_data = {
272+
.devtype = FSL_QUADSPI_LS2080A,
273+
.rxfifo = 128,
274+
.txfifo = 64,
275+
.ahb_buf_size = 1024,
276+
.driver_data = QUADSPI_QUIRK_TKT253890,
277+
};
278+
279+
270280
#define FSL_QSPI_MAX_CHIP 4
271281
struct fsl_qspi {
272282
struct spi_nor nor[FSL_QSPI_MAX_CHIP];
@@ -661,7 +671,7 @@ static void fsl_qspi_set_map_addr(struct fsl_qspi *q)
661671
* causes the controller to clear the buffer, and use the sequence pointed
662672
* by the QUADSPI_BFGENCR[SEQID] to initiate a read from the flash.
663673
*/
664-
static void fsl_qspi_init_abh_read(struct fsl_qspi *q)
674+
static void fsl_qspi_init_ahb_read(struct fsl_qspi *q)
665675
{
666676
void __iomem *base = q->iobase;
667677
int seqid;
@@ -795,7 +805,7 @@ static int fsl_qspi_nor_setup_last(struct fsl_qspi *q)
795805
fsl_qspi_init_lut(q);
796806

797807
/* Init for AHB read */
798-
fsl_qspi_init_abh_read(q);
808+
fsl_qspi_init_ahb_read(q);
799809

800810
return 0;
801811
}
@@ -806,6 +816,7 @@ static const struct of_device_id fsl_qspi_dt_ids[] = {
806816
{ .compatible = "fsl,imx7d-qspi", .data = &imx7d_data, },
807817
{ .compatible = "fsl,imx6ul-qspi", .data = &imx6ul_data, },
808818
{ .compatible = "fsl,ls1021a-qspi", .data = (void *)&ls1021a_data, },
819+
{ .compatible = "fsl,ls2080a-qspi", .data = &ls2080a_data, },
809820
{ /* sentinel */ }
810821
};
811822
MODULE_DEVICE_TABLE(of, fsl_qspi_dt_ids);

‎drivers/mtd/spi-nor/hisi-sfc.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ struct hifmc_host {
112112
u32 num_chip;
113113
};
114114

115-
static inline int wait_op_finish(struct hifmc_host *host)
115+
static inline int hisi_spi_nor_wait_op_finish(struct hifmc_host *host)
116116
{
117117
u32 reg;
118118

119119
return readl_poll_timeout(host->regbase + FMC_INT, reg,
120120
(reg & FMC_INT_OP_DONE), 0, FMC_WAIT_TIMEOUT);
121121
}
122122

123-
static int get_if_type(enum spi_nor_protocol proto)
123+
static int hisi_spi_nor_get_if_type(enum spi_nor_protocol proto)
124124
{
125125
enum hifmc_iftype if_type;
126126

@@ -208,7 +208,7 @@ static int hisi_spi_nor_op_reg(struct spi_nor *nor,
208208
reg = FMC_OP_CMD1_EN | FMC_OP_REG_OP_START | optype;
209209
writel(reg, host->regbase + FMC_OP);
210210

211-
return wait_op_finish(host);
211+
return hisi_spi_nor_wait_op_finish(host);
212212
}
213213

214214
static int hisi_spi_nor_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf,
@@ -259,9 +259,9 @@ static int hisi_spi_nor_dma_transfer(struct spi_nor *nor, loff_t start_off,
259259

260260
reg = OP_CFG_FM_CS(priv->chipselect);
261261
if (op_type == FMC_OP_READ)
262-
if_type = get_if_type(nor->read_proto);
262+
if_type = hisi_spi_nor_get_if_type(nor->read_proto);
263263
else
264-
if_type = get_if_type(nor->write_proto);
264+
if_type = hisi_spi_nor_get_if_type(nor->write_proto);
265265
reg |= OP_CFG_MEM_IF_TYPE(if_type);
266266
if (op_type == FMC_OP_READ)
267267
reg |= OP_CFG_DUMMY_NUM(nor->read_dummy >> 3);
@@ -274,7 +274,7 @@ static int hisi_spi_nor_dma_transfer(struct spi_nor *nor, loff_t start_off,
274274
: OP_CTRL_WR_OPCODE(nor->program_opcode);
275275
writel(reg, host->regbase + FMC_OP_DMA);
276276

277-
return wait_op_finish(host);
277+
return hisi_spi_nor_wait_op_finish(host);
278278
}
279279

280280
static ssize_t hisi_spi_nor_read(struct spi_nor *nor, loff_t from, size_t len,

0 commit comments

Comments
 (0)