From: Mason Yang <masonccyang@mxic.com.tw>
To: broonie@kernel.org, marek.vasut@gmail.com,
linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org,
bbrezillon@kernel.org, dwmw2@infradead.org, lee.jones@linaro.org,
robh+dt@kernel.org, mark.rutland@arm.com,
computersforpeace@gmal.com, paul.burton@mips.com,
stefan@agner.ch, christophe.kerello@st.com,
liang.yang@amlogic.com, geert@linux-m68k.org,
devicetree@vger.kernel.org, marcel.ziswiler@toradex.com,
linux-mtd@lists.infradead.org, richard@nod.at,
miquel.raynal@bootlin.com
Cc: juliensu@mxic.com.tw, zhengxunli@mxic.com.tw,
Mason Yang <masonccyang@mxic.com.tw>
Subject: [PATCH 5/7] spi: Add direct mapping mode for Macronix SPI controller
Date: Thu, 28 Mar 2019 18:18:36 +0800 [thread overview]
Message-ID: <1553768318-23149-6-git-send-email-masonccyang@mxic.com.tw> (raw)
In-Reply-To: <1553768318-23149-1-git-send-email-masonccyang@mxic.com.tw>
Add direct mapping read mode for Macronix SPI controller driver.
Signed-off-by: Mason Yang <masonccyang@mxic.com.tw>
---
drivers/spi/spi-mxic.c | 129 ++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 100 insertions(+), 29 deletions(-)
diff --git a/drivers/spi/spi-mxic.c b/drivers/spi/spi-mxic.c
index fbebf89..9f5ff2b 100644
--- a/drivers/spi/spi-mxic.c
+++ b/drivers/spi/spi-mxic.c
@@ -19,6 +19,7 @@ struct mxic_spi {
struct clk *send_clk;
struct clk *send_dly_clk;
void __iomem *regs;
+ void __iomem *dirmap;
u32 cur_speed_hz;
};
@@ -128,6 +129,42 @@ static void mxic_spi_hw_init(struct mxic_spi *mxic)
mxic->regs + HC_CFG);
}
+static u32 mxic_spi_mem_prep_op_cfg(const struct spi_mem_op *op)
+{
+ u32 cfg = OP_CMD_BYTES(1) | OP_CMD_BUSW(fls(op->cmd.buswidth) - 1);
+
+ if (op->addr.nbytes)
+ cfg |= OP_ADDR_BYTES(op->addr.nbytes) |
+ OP_ADDR_BUSW(fls(op->addr.buswidth) - 1);
+
+ if (op->dummy.nbytes)
+ cfg |= OP_DUMMY_CYC(op->dummy.nbytes);
+
+ if (op->data.nbytes) {
+ cfg |= OP_DATA_BUSW(fls(op->data.buswidth) - 1);
+ if (op->data.dir == SPI_MEM_DATA_IN)
+ cfg |= OP_READ;
+ }
+
+ return cfg;
+}
+
+static void mxic_spi_set_hc_cfg(struct spi_device *spi, u32 flags)
+{
+ struct mxic_spi *mxic = spi_master_get_devdata(spi->master);
+ int nio = 1;
+
+ if (spi->mode & (SPI_TX_QUAD | SPI_RX_QUAD))
+ nio = 4;
+ else if (spi->mode & (SPI_TX_DUAL | SPI_RX_DUAL))
+ nio = 2;
+
+ writel(flags | HC_CFG_NIO(nio) |
+ HC_CFG_TYPE(spi->chip_select, HC_CFG_TYPE_SPI_NOR) |
+ HC_CFG_SLV_ACT(spi->chip_select) | HC_CFG_IDLE_SIO_LVL(1),
+ mxic->regs + HC_CFG);
+}
+
static int mxic_spi_data_xfer(struct mxic_spi *mxic, const void *txbuf,
void *rxbuf, unsigned int len)
{
@@ -201,43 +238,18 @@ static int mxic_spi_mem_exec_op(struct spi_mem *mem,
const struct spi_mem_op *op)
{
struct mxic_spi *mxic = spi_master_get_devdata(mem->spi->master);
- int nio = 1, i, ret;
- u32 ss_ctrl;
+ int i, ret;
u8 addr[8];
ret = mxic_spi_set_freq(mxic, mem->spi->max_speed_hz);
if (ret)
return ret;
- if (mem->spi->mode & (SPI_TX_QUAD | SPI_RX_QUAD))
- nio = 4;
- else if (mem->spi->mode & (SPI_TX_DUAL | SPI_RX_DUAL))
- nio = 2;
+ mxic_spi_set_hc_cfg(mem->spi, HC_CFG_MAN_CS_EN);
- writel(HC_CFG_NIO(nio) |
- HC_CFG_TYPE(mem->spi->chip_select, HC_CFG_TYPE_SPI_NOR) |
- HC_CFG_SLV_ACT(mem->spi->chip_select) | HC_CFG_IDLE_SIO_LVL(1) |
- HC_CFG_MAN_CS_EN,
- mxic->regs + HC_CFG);
writel(HC_EN_BIT, mxic->regs + HC_EN);
-
- ss_ctrl = OP_CMD_BYTES(1) | OP_CMD_BUSW(fls(op->cmd.buswidth) - 1);
-
- if (op->addr.nbytes)
- ss_ctrl |= OP_ADDR_BYTES(op->addr.nbytes) |
- OP_ADDR_BUSW(fls(op->addr.buswidth) - 1);
-
- if (op->dummy.nbytes)
- ss_ctrl |= OP_DUMMY_CYC(op->dummy.nbytes);
-
- if (op->data.nbytes) {
- ss_ctrl |= OP_DATA_BUSW(fls(op->data.buswidth) - 1);
- if (op->data.dir == SPI_MEM_DATA_IN)
- ss_ctrl |= OP_READ;
- }
-
- writel(ss_ctrl, mxic->regs + SS_CTRL(mem->spi->chip_select));
-
+ writel(mxic_spi_mem_prep_op_cfg(op),
+ mxic->regs + SS_CTRL(mem->spi->chip_select));
writel(readl(mxic->regs + HC_CFG) | HC_CFG_MAN_CS_ASSERT,
mxic->regs + HC_CFG);
@@ -271,9 +283,64 @@ static int mxic_spi_mem_exec_op(struct spi_mem *mem,
return ret;
}
+static int mxic_spi_mem_dirmap_create(struct spi_mem_dirmap_desc *desc)
+{
+ struct mxic_spi *mxic = spi_master_get_devdata(desc->mem->spi->master);
+
+ if (!mxic->dirmap)
+ return -ENOTSUPP;
+
+ /*
+ * TODO: overcome this limitation by moving LWR/LRD_ADDR during a
+ * read/write operation.
+ */
+ if (desc->info.offset + desc->info.length > U32_MAX)
+ return -ENOTSUPP;
+
+ if (!mxic_spi_mem_supports_op(desc->mem, &desc->info.op_tmpl))
+ return -ENOTSUPP;
+
+ if (desc->info.op_tmpl.data.dir == SPI_MEM_DATA_OUT)
+ return -ENOTSUPP;
+
+ return 0;
+}
+
+static ssize_t mxic_spi_mem_dirmap_read(struct spi_mem_dirmap_desc *desc,
+ u64 offs, size_t len, void *buf)
+{
+ struct mxic_spi *mxic = spi_master_get_devdata(desc->mem->spi->master);
+ int ret;
+ u32 sts;
+
+ mxic_spi_set_hc_cfg(desc->mem->spi, 0);
+
+ writel(mxic_spi_mem_prep_op_cfg(&desc->info.op_tmpl),
+ mxic->regs + LRD_CFG);
+ writel(LMODE_CMD0(desc->info.op_tmpl.cmd.opcode >> 8) |
+ (LMODE_CMD1(desc->info.op_tmpl.cmd.opcode) & 0xff00) |
+ LMODE_SLV_ACT(desc->mem->spi->chip_select) |
+ LMODE_EN, mxic->regs + LRD_CTRL);
+
+ memcpy_fromio(buf, mxic->dirmap + offs, len);
+
+ writel(INT_LRD_DIS, mxic->regs + INT_STS);
+ writel(0, mxic->regs + LRD_CTRL);
+
+ ret = readl_poll_timeout(mxic->regs + INT_STS, sts,
+ sts & INT_LRD_DIS, 0, USEC_PER_SEC);
+
+ if (ret)
+ return ret;
+
+ return len;
+}
+
static const struct spi_controller_mem_ops mxic_spi_mem_ops = {
.supports_op = mxic_spi_mem_supports_op,
.exec_op = mxic_spi_mem_exec_op,
+ .dirmap_create = mxic_spi_mem_dirmap_create,
+ .dirmap_read = mxic_spi_mem_dirmap_read,
};
static void mxic_spi_set_cs(struct spi_device *spi, bool lvl)
@@ -404,6 +471,10 @@ static int mxic_spi_probe(struct platform_device *pdev)
if (IS_ERR(mxic->regs))
return PTR_ERR(mxic->regs);
+ mxic->dirmap = mxic_mfd->dirmap;
+ if (IS_ERR(mxic->dirmap))
+ mxic->dirmap = NULL;
+
pm_runtime_enable(&pdev->dev);
master->auto_runtime_pm = true;
--
1.9.1
next prev parent reply other threads:[~2019-03-28 10:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-28 10:18 [PATCH 0/7] Add Macronix MX25F0A MFD driver and NAND function Mason Yang
2019-03-28 10:18 ` [PATCH 1/7] mfd: Add Macronix MX25F0A MFD controller driver Mason Yang
2019-03-28 10:18 ` [PATCH 2/7] mtd: rawnand: Add Macronix MX25F0A NAND " Mason Yang
2019-03-28 10:18 ` [PATCH 3/7] spi: Patch Macronix MX25F0A SPI " Mason Yang
2019-04-01 7:51 ` Mark Brown
2019-03-28 10:18 ` [PATCH 4/7] dt-bindings: mfd: Document Macronix MX25F0A controller bindings Mason Yang
2019-04-01 17:52 ` Miquel Raynal
2019-04-03 11:51 ` Lee Jones
2019-03-28 10:18 ` Mason Yang [this message]
2019-03-28 10:18 ` [PATCH 6/7] mtd: rawnand: Add Macronix NAND read retry and randomizer support Mason Yang
2019-03-28 10:18 ` [PATCH 7/7] mtd: rawnand: Add Macronix NAND block protection driver Mason Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1553768318-23149-6-git-send-email-masonccyang@mxic.com.tw \
--to=masonccyang@mxic.com.tw \
--cc=bbrezillon@kernel.org \
--cc=broonie@kernel.org \
--cc=christophe.kerello@st.com \
--cc=computersforpeace@gmal.com \
--cc=devicetree@vger.kernel.org \
--cc=dwmw2@infradead.org \
--cc=geert@linux-m68k.org \
--cc=juliensu@mxic.com.tw \
--cc=lee.jones@linaro.org \
--cc=liang.yang@amlogic.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
--cc=marcel.ziswiler@toradex.com \
--cc=marek.vasut@gmail.com \
--cc=mark.rutland@arm.com \
--cc=miquel.raynal@bootlin.com \
--cc=paul.burton@mips.com \
--cc=richard@nod.at \
--cc=robh+dt@kernel.org \
--cc=stefan@agner.ch \
--cc=zhengxunli@mxic.com.tw \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).