From: Guochun Mao <guochun.mao@mediatek.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 17/18] spi: mtk_qspi: add qspi driver for MT7629 SoC
Date: Wed, 14 Nov 2018 20:53:11 +0800 [thread overview]
Message-ID: <1542199991.32108.6.camel@mhfsdcap03> (raw)
In-Reply-To: <CAMty3ZAP9QuiD+0muN1vPWOY8ysv7CVZmEXOmQy6tRG2vVVSNA@mail.gmail.com>
On Wed, 2018-11-14 at 14:34 +0530, Jagan Teki wrote:
> On Fri, Oct 12, 2018 at 12:46 PM Ryder Lee <ryder.lee@mediatek.com> wrote:
> >
> > From: Guochun Mao <guochun.mao@mediatek.com>
> >
> > This patch adds MT7629 qspi driver for accessing SPI NOR flash.
> >
> > Cc: Jagan Teki <jagan@openedev.com>
> > Signed-off-by: Guochun Mao <guochun.mao@mediatek.com>
> > ---
> > change since v2:
> > - Drop flash commands in the driver.
> > ---
> > drivers/spi/Kconfig | 7 +
> > drivers/spi/Makefile | 1 +
> > drivers/spi/mtk_qspi.c | 359 +++++++++++++++++++++++++++++++++++++++++++++++++
> > 3 files changed, 367 insertions(+)
> > create mode 100644 drivers/spi/mtk_qspi.c
> >
> > diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
> > index 1df6876..f9cf4ba 100644
> > --- a/drivers/spi/Kconfig
> > +++ b/drivers/spi/Kconfig
> > @@ -124,6 +124,13 @@ config MT7621_SPI
> > the SPI NOR flash on platforms embedding this Ralink / MediaTek
> > SPI core, like MT7621/7628/7688.
> >
> > +config MTK_QSPI
> > + bool "Mediatek QSPI driver"
> > + help
> > + Enable the Mediatek QSPI driver. This driver can be
> > + used to access the SPI NOR flash on platforms embedding this
> > + Mediatek QSPI IP core.
> > +
> > config MVEBU_A3700_SPI
> > bool "Marvell Armada 3700 SPI driver"
> > select CLK_ARMADA_3720
> > diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
> > index 7242ea7..e5a78f5 100644
> > --- a/drivers/spi/Makefile
> > +++ b/drivers/spi/Makefile
> > @@ -33,6 +33,7 @@ obj-$(CONFIG_KIRKWOOD_SPI) += kirkwood_spi.o
> > obj-$(CONFIG_LPC32XX_SSP) += lpc32xx_ssp.o
> > obj-$(CONFIG_MPC8XX_SPI) += mpc8xx_spi.o
> > obj-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o
> > +obj-$(CONFIG_MTK_QSPI) += mtk_qspi.o
> > obj-$(CONFIG_MT7621_SPI) += mt7621_spi.o
> > obj-$(CONFIG_MVEBU_A3700_SPI) += mvebu_a3700_spi.o
> > obj-$(CONFIG_MXC_SPI) += mxc_spi.o
> > diff --git a/drivers/spi/mtk_qspi.c b/drivers/spi/mtk_qspi.c
> > new file mode 100644
> > index 0000000..b510733
> > --- /dev/null
> > +++ b/drivers/spi/mtk_qspi.c
> > @@ -0,0 +1,359 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright (c) 2018 MediaTek, Inc.
> > + * Author : Guochun.Mao at mediatek.com
> > + */
> > +
> > +#include <common.h>
> > +#include <dm.h>
> > +#include <malloc.h>
> > +#include <spi.h>
> > +#include <asm/io.h>
> > +#include <linux/iopoll.h>
> > +#include <linux/ioport.h>
> > +
> > +/* Register Offset */
> > +struct mtk_qspi_regs {
> > + u32 cmd;
> > + u32 cnt;
> > + u32 rdsr;
> > + u32 rdata;
> > + u32 radr[3];
> > + u32 wdata;
> > + u32 prgdata[6];
> > + u32 shreg[10];
> > + u32 cfg[2];
> > + u32 shreg10;
> > + u32 mode_mon;
> > + u32 status[4];
> > + u32 flash_time;
> > + u32 flash_cfg;
> > + u32 reserved_0[3];
> > + u32 sf_time;
> > + u32 pp_dw_data;
> > + u32 reserved_1;
> > + u32 delsel_0[2];
> > + u32 intrstus;
> > + u32 intren;
> > + u32 reserved_2;
> > + u32 cfg3;
> > + u32 reserved_3;
> > + u32 chksum;
> > + u32 aaicmd;
> > + u32 wrprot;
> > + u32 radr3;
> > + u32 dual;
> > + u32 delsel_1[3];
> > +};
> > +
> > +struct mtk_qspi_platdata {
> > + fdt_addr_t reg_base;
> > + fdt_addr_t mem_base;
> > +};
> > +
> > +struct mtk_qspi_priv {
> > + struct mtk_qspi_regs *regs;
> > + unsigned long *mem_base;
> > + u8 op;
> > + u8 tx[3]; /* only record max 3 bytes paras, when it's address. */
> > + u32 txlen; /* dout buffer length - op code length */
> > + u8 *rx;
> > + u32 rxlen;
> > +};
> > +
> > +#define MTK_QSPI_CMD_POLLINGREG_US 500000
> > +#define MTK_QSPI_WRBUF_SIZE 256
> > +#define MTK_QSPI_COMMAND_ENABLE 0x30
> > +
> > +/* NOR flash controller commands */
> > +#define MTK_QSPI_RD_TRIGGER BIT(0)
> > +#define MTK_QSPI_READSTATUS BIT(1)
> > +#define MTK_QSPI_PRG_CMD BIT(2)
> > +#define MTK_QSPI_WR_TRIGGER BIT(4)
> > +#define MTK_QSPI_WRITESTATUS BIT(5)
> > +#define MTK_QSPI_AUTOINC BIT(7)
> > +
> > +#define MTK_QSPI_MAX_RX_TX_SHIFT 0x6
> > +#define MTK_QSPI_MAX_SHIFT 0x8
> > +
> > +#define MTK_QSPI_WR_BUF_ENABLE 0x1
> > +#define MTK_QSPI_WR_BUF_DISABLE 0x0
>
> All these bits look flash handling bit's , aren't ?
>
> > +
> > +static int mtk_qspi_execute_cmd(struct mtk_qspi_priv *priv, u8 cmd)
> > +{
> > + u8 tmp;
> > + u8 val = cmd & ~MTK_QSPI_AUTOINC;
> > +
> > + writeb(cmd, &priv->regs->cmd);
> > +
> > + return readb_poll_timeout(&priv->regs->cmd, tmp, !(val & tmp),
> > + MTK_QSPI_CMD_POLLINGREG_US);
> > +}
> > +
> > +static int mtk_qspi_tx_rx(struct mtk_qspi_priv *priv)
> > +{
> > + int len = 1 + priv->txlen + priv->rxlen;
> > + int i, ret, idx;
> > +
> > + if (len > MTK_QSPI_MAX_SHIFT)
> > + return -ERR_INVAL;
> > +
> > + writeb(len * 8, &priv->regs->cnt);
> > +
> > + /* start at PRGDATA5, go down to PRGDATA0 */
> > + idx = MTK_QSPI_MAX_RX_TX_SHIFT - 1;
> > +
> > + /* opcode */
> > + writeb(priv->op, &priv->regs->prgdata[idx]);
> > + idx--;
> > +
> > + /* program TX data */
> > + for (i = 0; i < priv->txlen; i++, idx--)
> > + writeb(priv->tx[i], &priv->regs->prgdata[idx]);
> > +
> > + /* clear out rest of TX registers */
> > + while (idx >= 0) {
> > + writeb(0, &priv->regs->prgdata[idx]);
> > + idx--;
> > + }
> > +
> > + ret = mtk_qspi_execute_cmd(priv, MTK_QSPI_PRG_CMD);
>
> What does this execute do?
It send command to flash, and latch data if need.
> does it intiate the controller register
> based flash command or so?
No, it doesn't.
>
> Do you have Linux driver on the controller?
Yes, it's drivers/mtd/spi-nor/mtk-quadspi.c
BR,
Guochun
next prev parent reply other threads:[~2018-11-14 12:53 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-12 7:00 [U-Boot] [PATCH v2 00/18] Add U-Boot support for MediaTek SoCs - MT7623n & MT7629 Ryder Lee
2018-10-12 7:00 ` [U-Boot] [PATCH v2 01/18] tools: MediaTek: add MTK boot header generation to mkimage Ryder Lee
2018-10-25 3:29 ` Simon Glass
2018-10-25 13:11 ` Ryder Lee
2018-10-12 7:00 ` [U-Boot] [PATCH v2 02/18] arm: dts: MediaTek: add device tree for MT7629 Ryder Lee
2018-10-25 3:29 ` Simon Glass
2018-10-12 7:00 ` [U-Boot] [PATCH v2 03/18] arm: dts: MediaTek: add device tree for MT7623 Ryder Lee
2018-10-25 3:29 ` Simon Glass
2018-10-12 7:00 ` [U-Boot] [PATCH v2 04/18] arm: MediaTek: add basic support for MT7629 boards Ryder Lee
2018-10-25 3:29 ` Simon Glass
2018-10-25 6:44 ` Ryder Lee
2018-10-12 7:00 ` [U-Boot] [PATCH v2 05/18] arm: MediaTek: add basic support for MT7623 boards Ryder Lee
2018-10-25 3:29 ` Simon Glass
2018-10-25 6:40 ` Ryder Lee
2018-10-12 7:00 ` [U-Boot] [PATCH v2 06/18] clk: MediaTek: add clock driver for MT7629 SoC Ryder Lee
2018-10-25 3:29 ` Simon Glass
2018-10-25 6:37 ` Ryder Lee
2018-11-03 6:08 ` Simon Glass
2018-10-12 7:00 ` [U-Boot] [PATCH v2 07/18] clk: MediaTek: add clock driver for MT7623 SoC Ryder Lee
2018-10-25 3:29 ` Simon Glass
2018-10-12 7:00 ` [U-Boot] [PATCH v2 08/18] timer: MediaTek: add timer driver for MediaTek SoCs Ryder Lee
2018-10-25 3:29 ` Simon Glass
2018-10-12 7:00 ` [U-Boot] [PATCH v2 09/18] watchdog: MediaTek: add watchdog " Ryder Lee
2018-10-25 3:29 ` Simon Glass
2018-10-12 7:00 ` [U-Boot] [PATCH v2 10/18] pinctrl: MediaTek: add pinctrl driver for MT7629 SoC Ryder Lee
2018-10-25 3:29 ` Simon Glass
2018-10-25 6:08 ` Ryder Lee
2018-11-03 6:08 ` Simon Glass
2018-10-12 7:01 ` [U-Boot] [PATCH v2 11/18] pinctrl: MediaTek: add pinctrl driver for MT7623 SoC Ryder Lee
2018-10-25 3:29 ` Simon Glass
2018-10-25 6:13 ` Ryder Lee
2018-11-03 6:08 ` Simon Glass
2018-10-12 7:01 ` [U-Boot] [PATCH v2 12/18] power domain: MediaTek: add power domain driver for MT7629 SoC Ryder Lee
2018-10-25 3:29 ` Simon Glass
2018-10-12 7:01 ` [U-Boot] [PATCH v2 13/18] power domain: MediaTek: add power domain driver for MT7623 SoC Ryder Lee
2018-10-25 3:30 ` Simon Glass
2018-10-12 7:01 ` [U-Boot] [PATCH v2 14/18] serial: 16550: allow the driver to support MediaTek serial Ryder Lee
2018-10-25 3:30 ` Simon Glass
2018-10-12 7:01 ` [U-Boot] [PATCH v2 15/18] ram: MediaTek: add DDR3 driver for MT7629 SoC Ryder Lee
2018-10-25 3:30 ` Simon Glass
2018-10-25 9:38 ` Ryder Lee
2018-10-26 16:53 ` Simon Glass
2018-10-12 7:01 ` [U-Boot] [PATCH v2 16/18] mmc: mtk-sd: add SD/MMC host controller driver for MT7623 SoC Ryder Lee
2018-10-25 3:30 ` Simon Glass
2018-10-12 7:01 ` [U-Boot] [PATCH v2 17/18] spi: mtk_qspi: add qspi driver for MT7629 SoC Ryder Lee
2018-10-25 3:30 ` Simon Glass
2018-10-26 6:33 ` Jagan Teki
2018-11-14 9:04 ` Jagan Teki
2018-11-14 12:53 ` Guochun Mao [this message]
2018-11-21 9:38 ` Jagan Teki
2018-11-21 11:46 ` Guochun Mao
2018-11-22 6:21 ` Jagan Teki
2018-11-22 8:58 ` Guochun Mao
2018-11-23 5:43 ` Jagan Teki
2018-11-23 8:24 ` Guochun Mao
2018-10-12 7:01 ` [U-Boot] [PATCH v2 18/18] MAINTAINERS: add an entry for MediaTek Ryder Lee
2018-10-25 3:30 ` Simon Glass
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=1542199991.32108.6.camel@mhfsdcap03 \
--to=guochun.mao@mediatek.com \
--cc=u-boot@lists.denx.de \
/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