spi: spi-nxp-fspi: enable runtime pm for fspi
Subsystems (2)
[email protected]
maintainerPATCH 1/5 spi: spi-nxp-fspi: enable runtime pm for fspi
From: Haibo Chen <[email protected]>
Enable the runtime PM in fspi driver.
Also for system PM, On some board like i.MX8ULP-EVK board, after system suspend, IOMUX module will lost power, so all the pinctrl setting will lost when system resume back, need driver to save/restore the pinctrl setting.
--- drivers/spi/spi-nxp-fspi.c | 111 ++++++++++++++++++++++++++++++++----- 1 file changed, 97 insertions(+), 14 deletions(-)
drivers/spi/spi-nxp-fspi.c +97 -14
@@ -48,6 +48,8 @@#include <linux/mutex.h> #include <linux/of.h> #include <linux/platform_device.h> +#include <linux/pinctrl/consumer.h> +#include <linux/pm_runtime.h> #include <linux/pm_qos.h> #include <linux/regmap.h> #include <linux/sizes.h>
@@ -57,6 +59,8 @@#include <linux/spi/spi.h> #include <linux/spi/spi-mem.h> +/* runtime pm timeout */ +#define FSPI_RPM_TIMEOUT 50/* 50ms */ /* * The driver only uses one single LUT entry, that is updated on * each call of exec_op(). Index 0 is preset at boot with a basic
@@ -390,6 +394,8 @@ struct nxp_fspi {struct mutex lock;struct pm_qos_request pm_qos_req;int selected; +#define FSPI_INITILIZED (1 << 0) +int flags; };static inline int needs_ip_only (struct nxp_fspi *f)
@@ -917,6 +923,12 @@ static int nxp_fspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)mutex_lock (&f->lock); + err =pm_runtime_get_sync (f->dev); +if (err <0 ) { +dev_err (f->dev,"Failed to enable clock %d\n" , __LINE__); + goto err_mutex; + } +/* Wait for controller being ready. */ err =fspi_readl_poll_tout (f, f->iobase +FSPI_STS0 ,FSPI_STS0_ARB_IDLE ,1 ,POLL_TOUT , true);
@@ -945,8 +957,14 @@ static int nxp_fspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)/* Invalidate the data in the AHB buffer. */ nxp_fspi_invalid (f); +pm_runtime_mark_last_busy (f->dev); +pm_runtime_put_autosuspend (f->dev); +mutex_unlock (&f->lock); +return err; +err_mutex: +mutex_unlock (&f->lock);return err; }
@@ -1201,12 +1219,17 @@ static int nxp_fspi_probe(struct platform_device *pdev) ret =PTR_ERR (f->clk); goto err_put_ctrl; } + } - ret =nxp_fspi_clk_prep_enable (f); -if (ret) { -dev_err (dev,"can not enable the clock\n" ); - goto err_put_ctrl; - } +pm_runtime_enable (dev); +pm_runtime_set_autosuspend_delay (dev,FSPI_RPM_TIMEOUT ); +pm_runtime_use_autosuspend (dev); + +/* enable clock */ + ret =pm_runtime_get_sync (f->dev); +if (ret <0 ) { +dev_err (f->dev,"Failed to enable clock %d\n" , __LINE__); + goto err_put_ctrl; }/* Clear potential interrupts */
@@ -1240,13 +1263,19 @@ static int nxp_fspi_probe(struct platform_device *pdev)if (ret) goto err_destroy_mutex; +pm_runtime_mark_last_busy (f->dev); +pm_runtime_put_autosuspend (f->dev); + +/* indicate the controller has been initialized */ + f->flags |=FSPI_INITILIZED ; +return 0 ; err_destroy_mutex:mutex_destroy (&f->lock); err_disable_clk: -nxp_fspi_clk_disable_unprep (f); +pm_runtime_disable (dev); err_put_ctrl:spi_controller_put (ctlr);
@@ -1270,20 +1299,79 @@ static void nxp_fspi_remove(struct platform_device *pdev)iounmap (f->ahb_addr); } -static int nxp_fspi_suspend (struct device *dev) +#ifdef CONFIG_PM +static int nxp_fspi_initialized (struct nxp_fspi *f) +{ +return f->flags &FSPI_INITILIZED ; +} + +static int nxp_fspi_need_reinit (struct nxp_fspi *f) +{ +/* +* we always use the controller in combination mode, so we check +* this register bit to determine if the controller once lost power, +* such as suspend/resume, and need to be re-init. +*/ + +return !(readl (f->iobase +FSPI_MCR0 ) &FSPI_MCR0_OCTCOMB_EN ); +} + +static int nxp_fspi_runtime_suspend (struct device *dev) { +struct nxp_fspi *f =dev_get_drvdata (dev); + +nxp_fspi_clk_disable_unprep (f); +return 0 ; } -static int nxp_fspi_resume (struct device *dev) +static int nxp_fspi_runtime_resume (struct device *dev) {struct nxp_fspi *f =dev_get_drvdata (dev); -nxp_fspi_default_setup (f); +nxp_fspi_clk_prep_enable (f); + +if (nxp_fspi_initialized (f) &&nxp_fspi_need_reinit (f)) +nxp_fspi_default_setup (f);return 0 ; } +static int nxp_fspi_suspend (struct device *dev) +{ +int ret; + + ret =pinctrl_pm_select_sleep_state (dev); +if (ret) { +dev_err (dev,"select flexspi sleep pinctrl failed!\n" ); +return ret; + } + +return pm_runtime_force_suspend (dev); +} + +static int nxp_fspi_resume (struct device *dev) +{ +int ret; + + ret =pm_runtime_force_resume (dev); +if (ret) +return ret; + + ret =pinctrl_pm_select_default_state (dev); +if (ret) +dev_err (dev,"select flexspi default pinctrl failed!\n" ); + +return ret; +} + + +static const struct dev_pm_ops nxp_fspi_pm_ops = { + SET_RUNTIME_PM_OPS(nxp_fspi_runtime_suspend, nxp_fspi_runtime_resume, NULL) +SET_SYSTEM_SLEEP_PM_OPS (nxp_fspi_suspend, nxp_fspi_resume) +}; +#endif /* CONFIG_PM */ +static const struct of_device_id nxp_fspi_dt_ids[] = { { .compatible ="nxp,lx2160a-fspi" , .data = (void *)&lx2160a_data, }, { .compatible ="nxp,imx8mm-fspi" , .data = (void *)&imx8mm_data, },
@@ -1302,11 +1390,6 @@ static const struct acpi_device_id nxp_fspi_acpi_ids[] = {MODULE_DEVICE_TABLE (acpi, nxp_fspi_acpi_ids);#endif -static const struct dev_pm_ops nxp_fspi_pm_ops = { - .suspend = nxp_fspi_suspend, - .resume = nxp_fspi_resume, -}; -static struct platform_driver nxp_fspi_driver = { .driver = { .name ="nxp-fspi" ,
Signature · 1 line
2.34.1
[email protected]
maintainerPATCH 2/5 spi: spi-nxp-fspi: change the default lut index
From: Haibo Chen <[email protected]>
The fspi dynamic lut use the last lut for all IPS operations, the imx8ulp only supports 15 luts, so change the last lut index from 31 to 15.
--- drivers/spi/spi-nxp-fspi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi-nxp-fspi.c +2 -2
@@ -64,9 +64,9 @@/* * The driver only uses one single LUT entry, that is updated on * each call of exec_op(). Index 0 is preset at boot with a basic -* read operation, so let's use the last entry (31). +* read operation, so let's use the last entry (15). */ -#define SEQID_LUT 31 +#define SEQID_LUT 15/* Registers used by the driver */ #define FSPI_MCR0 0x00
Signature · 1 line
2.34.1
Re: [PATCH 2/5] spi: spi-nxp-fspi: change the default lut index
Quoted 2 lines
The fspi dynamic lut use the last lut for all IPS operations, the imx8ulp only supports 15 luts, so change the last lut index from
It's 16 LUTs, no? There's also index 0.
Quoted 13 lines
31 to 15.
Signed-off-by Han Xu <[email protected]>Signed-off-by Haibo Chen <[email protected]>--- drivers/spi/spi-nxp-fspi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/spi/spi-nxp-fspi.c +0
-0
drivers/spi/spi-nxp-fspi.c line 67
Quoted 5 lines
drivers/spi/spi-nxp-fspi.c +1
-1@@ -64,9 +64,9 @@/* * The driver only uses one single LUT entry, that is updated on * each call of exec_op(). Index 0 is preset at boot with a basic -* read operation, so let's use the last entry (31). +* read operation, so let's use the last entry (15).
Please add the information about the imx8mulp to the comment. Otherwise, the comment will be confusing for SoCs where there are 32 LUTs.
-michael
drivers/spi/spi-nxp-fspi.c line 72
Quoted 7 lines
drivers/spi/spi-nxp-fspi.c +1
-1*/ -#define SEQID_LUT 31 +#define SEQID_LUT 15/* Registers used by the driver */ #define FSPI_MCR0 0x00
2.34.1
Bough Chen
maintainerRE: [PATCH 2/5] spi: spi-nxp-fspi: change the default lut index
Quoted 9 lines
-----Original Message-----
From: Michael Walle <[email protected]>
Sent: 2023年12月14日 0:25
To: Bough Chen <[email protected]>
Cc: [email protected]; Han Xu <[email protected]>; dl-linux-imx <[email protected]>; [email protected]; [email protected]; Michael Walle <[email protected]>
Subject: Re: [PATCH 2/5] spi: spi-nxp-fspi: change the default lut index
Quoted 4 lines
Quoted 2 lines
The fspi dynamic lut use the last lut for all IPS operations, the imx8ulp only supports 15 luts, so change the last lut index from
It's 16 LUTs, no? There's also index 0.
Yes, should be 16 LUTs.
Quoted 9 lines
Quoted 9 lines
31 to 15.
Signed-off-by Han Xu <[email protected]>Signed-off-by Haibo Chen <[email protected]>--- drivers/spi/spi-nxp-fspi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines
drivers/spi/spi-nxp-fspi.c line 67
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c +1
-1@@ -64,9 +64,9 @@/* * The driver only uses one single LUT entry, that is updated on * each call of exec_op(). Index 0 is preset at boot with a basic -* read operation, so let's use the last entry (31). +* read operation, so let's use the last entry (15). Please add the information about the imx8mulp to the comment. Otherwise, the comment will be confusing for SoCs where there are 32 LUTs.
Yes, will add.
Best Regards
Haibo Chen
Quoted 12 lines
-michael
drivers/spi/spi-nxp-fspi.c
Quoted 7 lines
drivers/spi/spi-nxp-fspi.c +1
-2*/ -#define SEQID_LUT 31 +#define SEQID_LUT 15/* Registers used by the driver */ #define FSPI_MCR0 0x00 --2.34.1
Re: [PATCH 2/5] spi: spi-nxp-fspi: change the default lut index
In reply to [email protected]Quoted 18 lines · On Wed, Dec 13, 2023 at 3:08 AM <[email protected]> wrote:
From: Haibo Chen <[email protected]>
The fspi dynamic lut use the last lut for all IPS operations, the imx8ulp only supports 15 luts, so change the last lut index from 31 to 15.
Signed-off-by Han Xu <[email protected]>Signed-off-by Haibo Chen <[email protected]>--- drivers/spi/spi-nxp-fspi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/spi/spi-nxp-fspi.c +0
-0
drivers/spi/spi-nxp-fspi.c line 69
Quoted 8 lines
drivers/spi/spi-nxp-fspi.c +2
-2@@ -64,9 +64,9 @@/* * The driver only uses one single LUT entry, that is updated on * each call of exec_op(). Index 0 is preset at boot with a basic -* read operation, so let's use the last entry (31). +* read operation, so let's use the last entry (15). */ -#define SEQID_LUT 31 +#define SEQID_LUT 15
What impact does this have on other SoC's with the FlexSPI with 32?
adam
Quoted 7 lines
drivers/spi/spi-nxp-fspi.c +0
-1/* Registers used by the driver */ #define FSPI_MCR0 0x00 --2.34.1
Bough Chen
maintainerRE: [PATCH 2/5] spi: spi-nxp-fspi: change the default lut index
Quoted 22 lines
-----Original Message-----
From: Adam Ford <[email protected]>
Sent: 2023年12月14日 11:04
To: Bough Chen <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>; Han Xu <[email protected]>
Subject: Re: [PATCH 2/5] spi: spi-nxp-fspi: change the default lut indexQuoted 13 lines · On Wed, Dec 13, 2023 at 3:08 AM <[email protected]> wrote:
From: Haibo Chen <[email protected]>
The fspi dynamic lut use the last lut for all IPS operations, the imx8ulp only supports 15 luts, so change the last lut index from 31 to 15.
Signed-off-by Han Xu <[email protected]>Signed-off-by Haibo Chen <[email protected]>--- drivers/spi/spi-nxp-fspi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 15 lines
drivers/spi/spi-nxp-fspi.c line 69
Quoted 13 lines
drivers/spi/spi-nxp-fspi.c +2
-2@@ -64,9 +64,9 @@/* * The driver only uses one single LUT entry, that is updated on * each call of exec_op(). Index 0 is preset at boot with a basic -* read operation, so let's use the last entry (31). +* read operation, so let's use the last entry (15). */ -#define SEQID_LUT 31 +#define SEQID_LUT 15What impact does this have on other SoC's with the FlexSPI with 32?
No impact, just use another LUT to send command queue.
Best Regards
Haibo Chen
Quoted 9 lines
adam
Quoted 7 lines
drivers/spi/spi-nxp-fspi.c +0
-1/* Registers used by the driver */ #define FSPI_MCR0 0x00 --2.34.1
[email protected]
maintainerPATCH 3/5 spi: spi-nxp-fspi: add DTR mode support
In reply to [email protected]From: Haibo Chen <[email protected]>
For LUT, add DTR command support.
--- drivers/spi/spi-nxp-fspi.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)
drivers/spi/spi-nxp-fspi.c +22 -5
@@ -552,12 +552,22 @@ static void nxp_fspi_prepare_lut(struct nxp_fspi *f,int lutidx =1 , i;/* cmd */ - lutval[0 ] |=LUT_DEF (0 ,LUT_CMD ,LUT_PAD (op->cmd.buswidth), - op->cmd.opcode); +if (op->cmd.dtr) { + lutval[0 ] |=LUT_DEF (0 ,LUT_CMD_DDR ,LUT_PAD (op->cmd.buswidth), + op->cmd.opcode >>8 ); + lutval[lutidx /2 ] |=LUT_DEF (lutidx,LUT_CMD_DDR , +LUT_PAD (op->cmd.buswidth), + op->cmd.opcode &0x00ff ); + lutidx++; + }else { + lutval[0 ] |=LUT_DEF (0 ,LUT_CMD ,LUT_PAD (op->cmd.buswidth), + op->cmd.opcode); + }/* addr bytes */ if (op->addr.nbytes) { - lutval[lutidx /2 ] |=LUT_DEF (lutidx,LUT_ADDR , + lutval[lutidx /2 ] |=LUT_DEF (lutidx, op->addr.dtr ? +LUT_ADDR_DDR :LUT_ADDR ,LUT_PAD (op->addr.buswidth), op->addr.nbytes *8 ); lutidx++;
@@ -565,7 +575,8 @@ static void nxp_fspi_prepare_lut(struct nxp_fspi *f,/* dummy bytes, if needed */ if (op->dummy.nbytes) { - lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_DUMMY, + lutval[lutidx / 2] |= LUT_DEF(lutidx, op->dummy.dtr ? + LUT_DUMMY_DDR : LUT_DUMMY,/* * Due to FlexSPI controller limitation number of PAD for dummy * buswidth needs to be programmed as equal to data buswidth.
@@ -580,7 +591,8 @@ static void nxp_fspi_prepare_lut(struct nxp_fspi *f,if (op->data.nbytes) { lutval[lutidx /2 ] |=LUT_DEF (lutidx, op->data.dir ==SPI_MEM_DATA_IN ? -LUT_NXP_READ :LUT_NXP_WRITE , + (op->data.dtr ?LUT_READ_DDR :LUT_NXP_READ ) : + (op->data.dtr ?LUT_WRITE_DDR :LUT_NXP_WRITE ),LUT_PAD (op->data.buswidth),0 ); lutidx++;
@@ -1152,6 +1164,10 @@ static const struct spi_controller_mem_ops nxp_fspi_mem_ops = { .get_name = nxp_fspi_get_name, }; +static struct spi_controller_mem_caps nxp_fspi_mem_caps = { + .dtr = true, +}; +static int nxp_fspi_probe (struct platform_device *pdev) {struct spi_controller *ctlr;
@@ -1254,6 +1270,7 @@ static int nxp_fspi_probe(struct platform_device *pdev) ctlr->bus_num =-1 ; ctlr->num_chipselect =NXP_FSPI_MAX_CHIPSELECT ; ctlr->mem_ops = &nxp_fspi_mem_ops; + ctlr->mem_caps = &nxp_fspi_mem_caps;nxp_fspi_default_setup (f);
Signature · 1 line
2.34.1
Re: [PATCH 3/5] spi: spi-nxp-fspi: add DTR mode support
Quoted 3 lines
From: Haibo Chen <[email protected]>
For LUT, add DTR command support.
Please elaborate a bit more.
Quoted 10 lines
Signed-off-by Haibo Chen <[email protected]>--- drivers/spi/spi-nxp-fspi.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)drivers/spi/spi-nxp-fspi.c +0
-0
drivers/spi/spi-nxp-fspi.c static void nxp_fspi_prepare_lut(struct nxp_fspi *f, · line 557
Quoted 8 lines
drivers/spi/spi-nxp-fspi.c +3
-2@@ -552,12 +552,22 @@ static void nxp_fspi_prepare_lut(struct nxp_fspi *f,int lutidx =1 , i;/* cmd */ - lutval[0 ] |=LUT_DEF (0 ,LUT_CMD ,LUT_PAD (op->cmd.buswidth), - op->cmd.opcode); +if (op->cmd.dtr) { + lutval[0 ] |=LUT_DEF (0 ,LUT_CMD_DDR ,LUT_PAD (op->cmd.buswidth), + op->cmd.opcode >>8 );
Shouldn't we check cmd.nbytes here? You seem to mix dtr with cmd.nbytes == 2 here.
drivers/spi/spi-nxp-fspi.c static void nxp_fspi_prepare_lut(struct nxp_fspi *f, · line 560
Quoted 3 lines
drivers/spi/spi-nxp-fspi.c +3
-0+ lutval[lutidx /2 ] |=LUT_DEF (lutidx,LUT_CMD_DDR , +LUT_PAD (op->cmd.buswidth), + op->cmd.opcode &0x00ff );
And you seem to assume dtr is always octal mode?
-michael
Quoted 55 lines
drivers/spi/spi-nxp-fspi.c +16
-3+ lutidx++; + }else { + lutval[0 ] |=LUT_DEF (0 ,LUT_CMD ,LUT_PAD (op->cmd.buswidth), + op->cmd.opcode); + }/* addr bytes */ if (op->addr.nbytes) { - lutval[lutidx /2 ] |=LUT_DEF (lutidx,LUT_ADDR , + lutval[lutidx /2 ] |=LUT_DEF (lutidx, op->addr.dtr ? +LUT_ADDR_DDR :LUT_ADDR ,LUT_PAD (op->addr.buswidth), op->addr.nbytes *8 ); lutidx++;@@ -565,7 +575,8 @@ static void nxp_fspi_prepare_lut(struct nxp_fspi *f,/* dummy bytes, if needed */ if (op->dummy.nbytes) { - lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_DUMMY, + lutval[lutidx / 2] |= LUT_DEF(lutidx, op->dummy.dtr ? + LUT_DUMMY_DDR : LUT_DUMMY,/* * Due to FlexSPI controller limitation number of PAD for dummy * buswidth needs to be programmed as equal to data buswidth. @@ -580,7 +591,8 @@ static void nxp_fspi_prepare_lut(struct nxp_fspi *f,if (op->data.nbytes) { lutval[lutidx /2 ] |=LUT_DEF (lutidx, op->data.dir ==SPI_MEM_DATA_IN ? -LUT_NXP_READ :LUT_NXP_WRITE , + (op->data.dtr ?LUT_READ_DDR :LUT_NXP_READ ) : + (op->data.dtr ?LUT_WRITE_DDR :LUT_NXP_WRITE ),LUT_PAD (op->data.buswidth),0 ); lutidx++;@@ -1152,6 +1164,10 @@ static const struct spi_controller_mem_ops nxp_fspi_mem_ops = { .get_name = nxp_fspi_get_name, }; +static struct spi_controller_mem_caps nxp_fspi_mem_caps = { + .dtr = true, +}; +static int nxp_fspi_probe (struct platform_device *pdev) {struct spi_controller *ctlr;@@ -1254,6 +1270,7 @@ static int nxp_fspi_probe(struct platform_device *pdev) ctlr->bus_num =-1 ; ctlr->num_chipselect =NXP_FSPI_MAX_CHIPSELECT ; ctlr->mem_ops = &nxp_fspi_mem_ops; + ctlr->mem_caps = &nxp_fspi_mem_caps;nxp_fspi_default_setup (f);Signature · 1 line
2.34.1
Bough Chen
maintainerRE: [PATCH 3/5] spi: spi-nxp-fspi: add DTR mode support
Quoted 9 lines
-----Original Message-----
From: Michael Walle <[email protected]>
Sent: 2023年12月14日 0:53
To: Bough Chen <[email protected]>
Cc: [email protected]; Han Xu <[email protected]>; dl-linux-imx <[email protected]>; [email protected]; [email protected]; Michael Walle <[email protected]>
Subject: Re: [PATCH 3/5] spi: spi-nxp-fspi: add DTR mode support
Quoted 5 lines
Quoted 3 lines
From: Haibo Chen <[email protected]>
For LUT, add DTR command support.
Please elaborate a bit more.
Okay.
Quoted 20 lines
Quoted 12 lines
Signed-off-by Haibo Chen <[email protected]>--- drivers/spi/spi-nxp-fspi.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)drivers/spi/spi-nxp-fspi.c +0
-0drivers/spi/spi-nxp-fspi.c static void nxp_fspi_prepare_lut(struct nxp_fspi *f, · line 556
Quoted 7 lines
drivers/spi/spi-nxp-fspi.c +2
-2@@ -552,12 +552,22 @@ static void nxp_fspi_prepare_lut(struct nxp_fspi *f,int lutidx =1 , i;/* cmd */ - lutval[0 ] |=LUT_DEF (0 ,LUT_CMD ,LUT_PAD (op->cmd.buswidth), - op->cmd.opcode); +if (op->cmd.dtr) { + lutval[0] |= LUT_DEF(0, LUT_CMD_DDR,
LUT_PAD(op->cmd.buswidth),
Quoted 4 lines
drivers/spi/spi-nxp-fspi.c static void nxp_fspi_prepare_lut(struct nxp_fspi *f, · line 557
Quoted 1 line
drivers/spi/spi-nxp-fspi.c +1
-0+ op->cmd.opcode >> 8);Shouldn't we check cmd.nbytes here? You seem to mix dtr with cmd.nbytes == 2 here.
Currently, for DTR mode, all cmd.nbytes == 2. Refer to drivers/mtd/spi-nor/core.c : spi_nor_spimem_setup_op() But better to check the cmd.nbytes here to make the code more strong.
Quoted 6 lines
drivers/spi/spi-nxp-fspi.c static void nxp_fspi_prepare_lut(struct nxp_fspi *f, · line 560
Quoted 4 lines
drivers/spi/spi-nxp-fspi.c +3
-0+ lutval[lutidx /2 ] |=LUT_DEF (lutidx,LUT_CMD_DDR , +LUT_PAD (op->cmd.buswidth), + op->cmd.opcode &0x00ff );And you seem to assume dtr is always octal mode?
Currently, I only test the octa dtr mode(8D-8D-8D). but here, we config the op->cmd.buswidth, op->addr.buswidth, op->dummy.buswidth, op->data.buswidth. So I think current LUT config can cover other dts mode, like 1D-8D-8D, 1D-4D-4D, 1D-2D-2D, 1D-1D-1D
Best Regards
Haibo Chen
Quoted 62 lines
-michael
Quoted 26 lines
drivers/spi/spi-nxp-fspi.c +9
-2+ lutidx++; + }else { + lutval[0 ] |=LUT_DEF (0 ,LUT_CMD ,LUT_PAD (op->cmd.buswidth), + op->cmd.opcode); + }/* addr bytes */ if (op->addr.nbytes) { - lutval[lutidx /2 ] |=LUT_DEF (lutidx,LUT_ADDR , + lutval[lutidx /2 ] |=LUT_DEF (lutidx, op->addr.dtr ? +LUT_ADDR_DDR :LUT_ADDR ,LUT_PAD (op->addr.buswidth), op->addr.nbytes *8 ); lutidx++;@@ -565,7 +575,8 @@ static void nxp_fspi_prepare_lut(struct nxp_fspi *f,/* dummy bytes, if needed */ if (op->dummy.nbytes) { - lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_DUMMY, + lutval[lutidx / 2] |= LUT_DEF(lutidx, op->dummy.dtr ? + LUT_DUMMY_DDR : LUT_DUMMY,/* * Due to FlexSPI controller limitation number of PAD for dummy drivers/spi/spi-nxp-fspi.c +0
-0* buswidth needs to be programmed as equal to data buswidth. drivers/spi/spi-nxp-fspi.c static void nxp_fspi_prepare_lut(struct nxp_fspi *f, · line 594
Quoted 5 lines
drivers/spi/spi-nxp-fspi.c +1
-1@@ -580,7 +591,8 @@ static void nxp_fspi_prepare_lut(struct nxp_fspi *f,if (op->data.nbytes) { lutval[lutidx / 2] |= LUT_DEF(lutidx, op->data.dir == SPI_MEM_DATA_IN ? - LUT_NXP_READ : LUT_NXP_WRITE, + (op->data.dtr ? LUT_READ_DDR :
LUT_NXP_READ) :drivers/spi/spi-nxp-fspi.c static void nxp_fspi_prepare_lut(struct nxp_fspi *f, · line 595
Quoted 1 line
drivers/spi/spi-nxp-fspi.c +1
-0+ (op->data.dtr ? LUT_WRITE_DDR :
LUT_NXP_WRITE),drivers/spi/spi-nxp-fspi.c static const struct spi_controller_mem_ops
Quoted 4 lines
drivers/spi/spi-nxp-fspi.c +0
-0LUT_PAD (op->data.buswidth), 0); lutidx++;@@ -1152,6 +1164,10 @@ static const struct spi_controller_mem_ops
nxp_fspi_mem_ops= {drivers/spi/spi-nxp-fspi.c static int nxp_fspi_probe(struct platform_device
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c +4
-0.get_name = nxp_fspi_get_name, }; +static struct spi_controller_mem_caps nxp_fspi_mem_caps = { + .dtr = true, +}; +static int nxp_fspi_probe (struct platform_device *pdev) {struct spi_controller *ctlr;@@ -1254,6 +1270,7 @@ static int nxp_fspi_probe(struct platform_device*pdev)
Quoted 9 lines
drivers/spi/spi-nxp-fspi.c +1
-1ctlr->bus_num =-1 ; ctlr->num_chipselect =NXP_FSPI_MAX_CHIPSELECT ; ctlr->mem_ops = &nxp_fspi_mem_ops; + ctlr->mem_caps = &nxp_fspi_mem_caps;nxp_fspi_default_setup (f); --2.34.1
Re: [PATCH 3/5] spi: spi-nxp-fspi: add DTR mode support
Hi,
Quoted 13 lines
Quoted 13 lines
drivers/spi/spi-nxp-fspi.c static void nxp_fspi_prepare_lut(struct nxp_fspi *f, · line 556
Quoted 12 lines
drivers/spi/spi-nxp-fspi.c +2
-2@@ -552,12 +552,22 @@ static void nxp_fspi_prepare_lut(struct nxp_fspi *f,int lutidx =1 , i;/* cmd */ - lutval[0 ] |=LUT_DEF (0 ,LUT_CMD ,LUT_PAD (op->cmd.buswidth), - op->cmd.opcode); +if (op->cmd.dtr) { + lutval[0] |= LUT_DEF(0, LUT_CMD_DDR,
LUT_PAD(op->cmd.buswidth),
Quoted 8 lines
Quoted 4 lines
drivers/spi/spi-nxp-fspi.c static void nxp_fspi_prepare_lut(struct nxp_fspi *f, · line 557
Quoted 1 line
drivers/spi/spi-nxp-fspi.c +1
-0+ op->cmd.opcode >> 8);Shouldn't we check cmd.nbytes here? You seem to mix dtr with cmd.nbytes == 2 here.
Currently, for DTR mode, all cmd.nbytes == 2. Refer to
drivers/mtd/spi-nor/core.c:spi_nor_spimem_setup_op()
But better to check the cmd.nbytes here to make the code more strong.
I'm aware of that, but that might change.
Quoted 10 lines
Quoted 5 lines
drivers/spi/spi-nxp-fspi.c static void nxp_fspi_prepare_lut(struct nxp_fspi *f, · line 560
Quoted 3 lines
drivers/spi/spi-nxp-fspi.c +3
-0+ lutval[lutidx /2 ] |=LUT_DEF (lutidx,LUT_CMD_DDR , +LUT_PAD (op->cmd.buswidth), + op->cmd.opcode &0x00ff );And you seem to assume dtr is always octal mode?
Currently, I only test the octa dtr mode(8D-8D-8D). but here, we config the
op->cmd.buswidth,op->addr.buswidth,op->dummy.buswidth,op->data.buswidth. So I think current LUT config can cover other dts mode, like 1D-8D-8D, 1D-4D-4D, 1D-2D-2D, 1D-1D-1D.
Agreed, for the code that follows this. But the 16bit opcode, ie. the LUT above only makes sense for 8d8d8d. There you have to have 16bit because thats what transferred in one clock cycle.
You could add that to your .supports_op(). I.e. restrict this driver to only support 8d8d8d. I know that the default op will already check that, but better be safe.
-michael
[email protected]
maintainerPATCH 4/5 spi: spi-nxp-fspi: add function to select sample clock source for flash reading
In reply to [email protected]From: Haibo Chen <[email protected]>
fspi define four mode for sample clock source selection.
Here is the list of modes:
mode 0: Dummy Read strobe generated by FlexSPI Controller and loopback internally mode 1: Dummy Read strobe generated by FlexSPI Controller and loopback from DQS pad mode 2: Reserved
mode 3: Flash provided Read strobe and input from DQS pad
In default, fspi use mode 0 after reset.
For 8-8-8-DTR mode, need to use mode 3, otherwise 8-8-8-DTR read always get incorrect data.
--- drivers/spi/spi-nxp-fspi.c | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
drivers/spi/spi-nxp-fspi.c +47 -0
@@ -395,6 +395,7 @@ struct nxp_fspi {struct pm_qos_request pm_qos_req;int selected;#define FSPI_INITILIZED (1 << 0) +#define FSPI_RXCLKSRC_3 (1 << 1)int flags; };
@@ -928,6 +929,50 @@ static int nxp_fspi_do_op(struct nxp_fspi *f, const struct spi_mem_op *op)return err; } +/* +* Sample Clock source selection for Flash Reading +* Four modes defined by fspi: +* mode 0: Dummy Read strobe generated by FlexSPI Controller +* and loopback internally +* mode 1: Dummy Read strobe generated by FlexSPI Controller +* and loopback from DQS pad +* mode 2: Reserved +* mode 3: Flash provided Read strobe and input from DQS pad +* +* fspi default use mode 0 after reset +*/ +static void nxp_fspi_select_rx_sample_clk_source (struct nxp_fspi *f, +const struct spi_mem_op *op) +{ +u32 reg; + +/* +* For 8-8-8-DTR mode, need to use mode 3 (Flash provided Read +* strobe and input from DQS pad), otherwise read operaton may +* meet issue. +* This mode require flash device connect the DQS pad on board. +* For other modes, still use mode 0, keep align with before. +* spi_nor_suspend will disable 8-8-8-DTR mode, also need to +* change the mode back to mode 0. +*/ +if (!(f->flags &FSPI_RXCLKSRC_3 ) && + op->cmd.dtr && op->addr.dtr && + op->dummy.dtr && op->data.dtr) { + reg =fspi_readl (f, f->iobase +FSPI_MCR0 ); + reg |=FSPI_MCR0_RXCLKSRC (3 ); +fspi_writel (f, reg, f->iobase +FSPI_MCR0 ); + f->flags |=FSPI_RXCLKSRC_3 ; + }else if ((f->flags &FSPI_RXCLKSRC_3 ) && + !op->cmd.dtr && !op->addr.dtr && + !op->dummy.dtr && !op->data.dtr) { + reg =fspi_readl (f, f->iobase +FSPI_MCR0 ); + reg &= ~FSPI_MCR0_RXCLKSRC (3 );/* select mode 0 */ +fspi_writel (f, reg, f->iobase +FSPI_MCR0 ); + f->flags &= ~FSPI_RXCLKSRC_3 ; + } + +} +static int nxp_fspi_exec_op (struct spi_mem *mem,const struct spi_mem_op *op) {struct nxp_fspi *f =spi_controller_get_devdata (mem->spi->controller);
@@ -948,6 +993,8 @@ static int nxp_fspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)nxp_fspi_select_mem (f, mem->spi); +nxp_fspi_select_rx_sample_clk_source (f, op); +nxp_fspi_prepare_lut (f, op);/* * If we have large chunks of data, we read them through the AHB bus by
Signature · 1 line
2.34.1
Re: [PATCH 4/5] spi: spi-nxp-fspi: add function to select sample clock source for flash reading
Quoted 10 lines
From: Haibo Chen <[email protected]>
fspi define four mode for sample clock source selection.
Here is the list of modes:
mode 0: Dummy Read strobe generated by FlexSPI Controller and loopback internally mode 1: Dummy Read strobe generated by FlexSPI Controller and loopback from DQS pad mode 2: Reserved
mode 3: Flash provided Read strobe and input from DQS pad
Quoted 3 lines
In default, fspi use mode 0 after reset.
For 8-8-8-DTR mode, need to use mode 3, otherwise 8-8-8-DTR read always get incorrect data.
I'd say this is board dependant, right? If you now hardcode 8d8d8d to always use mode 3. I'm not sure how a board which doesn't have the DQS connected to the flash can change this to another mode again. Looks like we'd need a (DT) property which tells you if there is actually a DQS line connected to the flash.
Btw you don't check buswidth, so you'll enable that mode for any DTR mode.
-michael
Bough Chen
maintainerRE: [PATCH 4/5] spi: spi-nxp-fspi: add function to select sample clock source for flash reading
Quoted 20 lines
-----Original Message-----
From: Michael Walle <[email protected]>
Sent: 2023年12月14日 1:21
To: Bough Chen <[email protected]>
Cc: [email protected]; Han Xu <[email protected]>; dl-linux-imx <[email protected]>; [email protected]; [email protected]; Michael Walle <[email protected]>
Subject: Re: [PATCH 4/5] spi: spi-nxp-fspi: add function to select sample clock source for flash readingQuoted 10 lines
From: Haibo Chen <[email protected]>
fspi define four mode for sample clock source selection.
Here is the list of modes:
mode 0: Dummy Read strobe generated by FlexSPI Controller and loopback internally mode 1: Dummy Read strobe generated by FlexSPI Controller and loopback from DQS pad mode 2: Reserved mode 3: Flash provided Read strobe and input from DQS pad
Quoted 8 lines
Quoted 3 lines
In default, fspi use mode 0 after reset.
For 8-8-8-DTR mode, need to use mode 3, otherwise 8-8-8-DTR read always get incorrect data.I'd say this is board dependant, right? If you now hardcode 8d8d8d to always use mode 3. I'm not sure how a board which doesn't have the DQS connected to the flash can change this to another mode again. Looks like we'd need a (DT) property which tells you if there is actually a DQS line connected to the flash.
Currently we distinguish through SoC chip, not board. Like patch5.
If SoC contain the DQS, but the board do not connect it to flash device, then this is a real issue.
But I think if user use one octal flash device which support dtr mode, they should connect this DQS pad if want to work in DTR mode. If forget to connect the DQS pad, they can limit the tx/rx buswidth to 4 or 1 in dts.
Anyway, add a DT property seems better. DQS is a must requirement for octal dtr mode, if detect no DQS, we can also disable the DTR mode support. Will add in next version.
Quoted 2 lines
Btw you don't check buswidth, so you'll enable that mode for any DTR mode.
Seems current spi-nor code only support one DTR mode, that is 8d-8d-8d.
Best Regards
Haibo Chen
Quoted 2 lines
-michael
Re: [PATCH 4/5] spi: spi-nxp-fspi: add function to select sample clock source for flash reading
Hi,
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
From: Haibo Chen <[email protected]>
fspi define four mode for sample clock source selection.
Here is the list of modes:
mode 0: Dummy Read strobe generated by FlexSPI Controller and loopback internally mode 1: Dummy Read strobe generated by FlexSPI Controller and loopback from DQS pad mode 2: Reserved mode 3: Flash provided Read strobe and input from DQS padIn default, fspi use mode 0 after reset.
For 8-8-8-DTR mode, need to use mode 3, otherwise 8-8-8-DTR read always get incorrect data.
Quoted 7 lines
Quoted 4 lines
I'd say this is board dependant, right? If you now hardcode 8d8d8d to always use mode 3. I'm not sure how a board which doesn't have the DQS connected to the flash can change this to another mode again. Looks like we'd need a (DT) property which tells you if there is actually a DQS line connected to the flash.
Currently we distinguish through SoC chip, not board. Like patch5.
If SoC contain the DQS, but the board do not connect it to flash device, then this is a real issue.
See below, there are alternatives to the DQS pin.
But it really is frequency dependent. I'd bet you can use mode 0 with a slow frequency in 8d8d8d mode. I.e. the LS1028ARM will always refer you to mode 3 if you want to archive "the highest frequency".
Quoted 7 lines
But I think if user use one octal flash device which support dtr mode, they should connect this DQS pad if want to work in DTR mode.
If forget to connect the DQS pad, they can limit the tx/rx buswidth to 4 or 1 in dts.Anyway, add a DT property seems better.
DQS is a must requirement for octal dtr mode, if detect no DQS, we can also disable the DTR mode support.
I don't think this is true in general. I haven't checked with the FSPI controller. But DQS is used for higher frequencies which isn't necessarily related to DTR.
Also, there are other methods, like manual calibration of the delay lines on the I/Os. There was once a patchset to add that calibration for a TI (?) controller, but it was never merged. I've seen the fspi also supports some DLL configuration and some kind of data learning feature. As far as I understand that, these are all alternatives. I.e.
(1) don't use high frequencies
(2) use DQS (driven by the flash)
(3) manually/automatically set the DLL
Quoted 5 lines
Will add in next version.
Quoted 1 line
Btw you don't check buswidth, so you'll enable that mode for any DTR mode.
Seems current spi-nor code only support one DTR mode, that is 8d-8d-8d.
Yes. But that doesn't mean the spi controller should assume that. If you don't want to support any other mode, you should probably check that in your .supports_op() callback.
-michael
[email protected]
maintainerPATCH 5/5 spi: spi-nxp-fspi: Add quirk to disable DTR support
In reply to [email protected]From: Haibo Chen <[email protected]>
Not all platform currently supports octal DTR mode. lx2160a do not implement DQS, this causes flash probe failure and therefore, provide an option of quirk FSPI_QUIRK_DISABLE_DTR for platforms not support DTR mode.
--- drivers/spi/spi-nxp-fspi.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/spi/spi-nxp-fspi.c +13 -3
@@ -340,6 +340,9 @@/* Access flash memory using IP bus only */ #define FSPI_QUIRK_USE_IP_ONLY BIT(0) +/* Disable DTR */ +#define FSPI_QUIRK_DISABLE_DTR BIT(1) +struct nxp_fspi_devtype_data {unsigned int rxfifo;unsigned int txfifo;
@@ -352,7 +355,7 @@ static struct nxp_fspi_devtype_data lx2160a_data = { .rxfifo = SZ_512, /* (64 * 64 bits) */ .txfifo = SZ_1K, /* (128 * 64 bits) */ .ahb_buf_size = SZ_2K, /* (256 * 64 bits) */ - .quirks = 0, + .quirks = FSPI_QUIRK_DISABLE_DTR, .little_endian = true, /* little-endian */ };
@@ -1211,10 +1214,14 @@ static const struct spi_controller_mem_ops nxp_fspi_mem_ops = { .get_name = nxp_fspi_get_name, }; -static struct spi_controller_mem_caps nxp_fspi_mem_caps = { +static const struct spi_controller_mem_caps nxp_fspi_mem_caps = { .dtr = true, }; +static const struct spi_controller_mem_caps nxp_fspi_mem_caps_quirks = { + .dtr = false, +}; +static int nxp_fspi_probe (struct platform_device *pdev) {struct spi_controller *ctlr;
@@ -1317,7 +1324,10 @@ static int nxp_fspi_probe(struct platform_device *pdev) ctlr->bus_num =-1 ; ctlr->num_chipselect =NXP_FSPI_MAX_CHIPSELECT ; ctlr->mem_ops = &nxp_fspi_mem_ops; - ctlr->mem_caps = &nxp_fspi_mem_caps; +if (f->devtype_data->quirks &FSPI_QUIRK_DISABLE_DTR ) + ctlr->mem_caps = &nxp_fspi_mem_caps_quirks; +else + ctlr->mem_caps = &nxp_fspi_mem_caps;nxp_fspi_default_setup (f);
Signature · 1 line
2.34.1