linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] mtd: rawnand: arasan: Fix clock rate in NV-DDR
@ 2022-06-21  8:54 Amit Kumar Mahapatra
  2022-06-21  8:54 ` [PATCH v2 1/2] mtd: rawnand: arasan: Update NAND bus clock instead of system clock Amit Kumar Mahapatra
  2022-06-21  8:55 ` [PATCH v2 2/2] mtd: rawnand: arasan: Fix clock rate in NV-DDR Amit Kumar Mahapatra
  0 siblings, 2 replies; 5+ messages in thread
From: Amit Kumar Mahapatra @ 2022-06-21  8:54 UTC (permalink / raw)
  To: miquel.raynal, vigneshr
  Cc: git, boris.brezillon, linux-mtd, linux-kernel,
	amit.kumar-mahapatra, akumarma, Amit Kumar Mahapatra

Based on upstream discussion here:
https://lore.kernel.org/all/20211127180758.30884-1-okitain@gmail.com/

This patch series:
 - Updates NAND bus clock, instead of system clock, as per the timing modes.
 - Fixes clock rate in NV-DDR
---
BRANCH: mtd/next
---
Amit Kumar Mahapatra (1):
  mtd: rawnand: arasan: Update NAND bus clock instead of system clock

Olga Kitaina (1):
  mtd: rawnand: arasan: Fix clock rate in NV-DDR

 drivers/mtd/nand/raw/arasan-nand-controller.c | 26 ++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

-- 
2.17.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] mtd: rawnand: arasan: Update NAND bus clock instead of system clock
  2022-06-21  8:54 [PATCH v2 0/2] mtd: rawnand: arasan: Fix clock rate in NV-DDR Amit Kumar Mahapatra
@ 2022-06-21  8:54 ` Amit Kumar Mahapatra
  2022-06-24 18:45   ` Miquel Raynal
  2022-06-21  8:55 ` [PATCH v2 2/2] mtd: rawnand: arasan: Fix clock rate in NV-DDR Amit Kumar Mahapatra
  1 sibling, 1 reply; 5+ messages in thread
From: Amit Kumar Mahapatra @ 2022-06-21  8:54 UTC (permalink / raw)
  To: miquel.raynal, vigneshr
  Cc: git, boris.brezillon, linux-mtd, linux-kernel,
	amit.kumar-mahapatra, akumarma, Amit Kumar Mahapatra

In current implementation the Arasan NAND driver is updating the
system clock(i.e., anand->clk) in accordance to the timing modes
(i.e., SDR or NVDDR). But as per the Arasan NAND controller spec the
flash clock or the NAND bus clock(i.e., nfc->bus_clk), need to be
updated instead. This patch keeps the system clock unchanged and updates
the NAND bus clock as per the timing modes.

Fixes: 197b88fecc50 ("mtd: rawnand: arasan: Add new Arasan NAND controller")
Signed-off-by: Amit Kumar Mahapatra <amit.kumar-mahapatra@xilinx.com>
---
 drivers/mtd/nand/raw/arasan-nand-controller.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/raw/arasan-nand-controller.c b/drivers/mtd/nand/raw/arasan-nand-controller.c
index 53bd10738418..4f6da82dd2b1 100644
--- a/drivers/mtd/nand/raw/arasan-nand-controller.c
+++ b/drivers/mtd/nand/raw/arasan-nand-controller.c
@@ -968,6 +968,7 @@ static int anfc_setup_interface(struct nand_chip *chip, int target,
 	const struct nand_sdr_timings *sdr;
 	const struct nand_nvddr_timings *nvddr;
 	unsigned int tccs_min, dqs_mode, fast_tcad;
+	int ret;
 
 	if (nand_interface_is_nvddr(conf)) {
 		nvddr = nand_get_nvddr_timings(conf);
@@ -1043,7 +1044,11 @@ static int anfc_setup_interface(struct nand_chip *chip, int target,
 				 DQS_BUFF_SEL_OUT(dqs_mode);
 	}
 
-	anand->clk = ANFC_XLNX_SDR_DFLT_CORE_CLK;
+	ret = clk_set_rate(nfc->bus_clk, ANFC_XLNX_SDR_DFLT_CORE_CLK);
+	if (ret) {
+		dev_err(nfc->dev, "Failed to change bus clock rate\n");
+		return ret;
+	}
 
 	/*
 	 * Due to a hardware bug in the ZynqMP SoC, SDR timing modes 0-1 work
@@ -1052,8 +1057,13 @@ static int anfc_setup_interface(struct nand_chip *chip, int target,
 	 * 80MHz when using SDR modes 2-5 with this SoC.
 	 */
 	if (of_device_is_compatible(np, "xlnx,zynqmp-nand-controller") &&
-	    nand_interface_is_sdr(conf) && conf->timings.mode >= 2)
-		anand->clk = ANFC_XLNX_SDR_HS_CORE_CLK;
+	    nand_interface_is_sdr(conf) && conf->timings.mode >= 2) {
+		ret = clk_set_rate(nfc->bus_clk, ANFC_XLNX_SDR_HS_CORE_CLK);
+		if (ret) {
+			dev_err(nfc->dev, "Failed to change bus clock rate\n");
+			return ret;
+		}
+	}
 
 	return 0;
 }
-- 
2.17.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] mtd: rawnand: arasan: Fix clock rate in NV-DDR
  2022-06-21  8:54 [PATCH v2 0/2] mtd: rawnand: arasan: Fix clock rate in NV-DDR Amit Kumar Mahapatra
  2022-06-21  8:54 ` [PATCH v2 1/2] mtd: rawnand: arasan: Update NAND bus clock instead of system clock Amit Kumar Mahapatra
@ 2022-06-21  8:55 ` Amit Kumar Mahapatra
  1 sibling, 0 replies; 5+ messages in thread
From: Amit Kumar Mahapatra @ 2022-06-21  8:55 UTC (permalink / raw)
  To: miquel.raynal, vigneshr
  Cc: git, boris.brezillon, linux-mtd, linux-kernel,
	amit.kumar-mahapatra, akumarma, Olga Kitaina,
	Amit Kumar Mahapatra

From: Olga Kitaina <okitain@gmail.com>

According to the Arasan NAND controller spec, the flash clock rate for SDR
must be <= 100 MHz, while for NV-DDR it must be the same as the rate of the
CLK line for the mode. The driver previously always set 100 MHz for NV-DDR,
which would result in incorrect behavior for NV-DDR modes 0-4.

The appropriate clock rate can be calculated from the NV-DDR timing
parameters as 1/tCK, or for rates measured in picoseconds,
10^12 / nand_nvddr_timings->tCK_min.

Signed-off-by: Olga Kitaina <okitain@gmail.com>
Signed-off-by: Amit Kumar Mahapatra <amit.kumar-mahapatra@xilinx.com>
---
 drivers/mtd/nand/raw/arasan-nand-controller.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/raw/arasan-nand-controller.c b/drivers/mtd/nand/raw/arasan-nand-controller.c
index 4f6da82dd2b1..0eff069d7f80 100644
--- a/drivers/mtd/nand/raw/arasan-nand-controller.c
+++ b/drivers/mtd/nand/raw/arasan-nand-controller.c
@@ -1044,10 +1044,20 @@ static int anfc_setup_interface(struct nand_chip *chip, int target,
 				 DQS_BUFF_SEL_OUT(dqs_mode);
 	}
 
-	ret = clk_set_rate(nfc->bus_clk, ANFC_XLNX_SDR_DFLT_CORE_CLK);
-	if (ret) {
-		dev_err(nfc->dev, "Failed to change bus clock rate\n");
-		return ret;
+	if (nand_interface_is_sdr(conf)) {
+		ret = clk_set_rate(nfc->bus_clk, ANFC_XLNX_SDR_DFLT_CORE_CLK);
+		if (ret) {
+			dev_err(nfc->dev, "Failed to change bus clock rate\n");
+			return ret;
+		}
+	} else {
+		/* ONFI timings are defined in picoseconds */
+		ret = clk_set_rate(nfc->bus_clk, div_u64((u64)NSEC_PER_SEC * 1000,
+							 conf->timings.nvddr.tCK_min));
+		if (ret) {
+			dev_err(nfc->dev, "Failed to change bus clock rate\n");
+			return ret;
+		}
 	}
 
 	/*
-- 
2.17.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] mtd: rawnand: arasan: Update NAND bus clock instead of system clock
  2022-06-21  8:54 ` [PATCH v2 1/2] mtd: rawnand: arasan: Update NAND bus clock instead of system clock Amit Kumar Mahapatra
@ 2022-06-24 18:45   ` Miquel Raynal
  2022-06-27 16:23     ` Mahapatra, Amit Kumar
  0 siblings, 1 reply; 5+ messages in thread
From: Miquel Raynal @ 2022-06-24 18:45 UTC (permalink / raw)
  To: Amit Kumar Mahapatra
  Cc: vigneshr, git, boris.brezillon, linux-mtd, linux-kernel,
	amit.kumar-mahapatra, akumarma

Hi Amit,

amit.kumar-mahapatra@xilinx.com wrote on Tue, 21 Jun 2022 14:24:59
+0530:

> In current implementation the Arasan NAND driver is updating the
> system clock(i.e., anand->clk) in accordance to the timing modes
> (i.e., SDR or NVDDR). But as per the Arasan NAND controller spec the
> flash clock or the NAND bus clock(i.e., nfc->bus_clk), need to be
> updated instead. This patch keeps the system clock unchanged and updates
> the NAND bus clock as per the timing modes.

This is not what you do below. If the clock that is changed is the
wrong one, then just change the clock used in the clk_set_rate call
instead of calling clk_set_rate twice at the wrong location.
->set_interface is done once per chip, if you have two different chips
on the same system you must change the clock when you switch from one
chip to the other. Your current implementation disrespects that,
unfortunately.

> 
> Fixes: 197b88fecc50 ("mtd: rawnand: arasan: Add new Arasan NAND controller")

Requires a Cc: stable tag

> Signed-off-by: Amit Kumar Mahapatra <amit.kumar-mahapatra@xilinx.com>
> ---
>  drivers/mtd/nand/raw/arasan-nand-controller.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/arasan-nand-controller.c b/drivers/mtd/nand/raw/arasan-nand-controller.c
> index 53bd10738418..4f6da82dd2b1 100644
> --- a/drivers/mtd/nand/raw/arasan-nand-controller.c
> +++ b/drivers/mtd/nand/raw/arasan-nand-controller.c
> @@ -968,6 +968,7 @@ static int anfc_setup_interface(struct nand_chip *chip, int target,
>  	const struct nand_sdr_timings *sdr;
>  	const struct nand_nvddr_timings *nvddr;
>  	unsigned int tccs_min, dqs_mode, fast_tcad;
> +	int ret;
>  
>  	if (nand_interface_is_nvddr(conf)) {
>  		nvddr = nand_get_nvddr_timings(conf);
> @@ -1043,7 +1044,11 @@ static int anfc_setup_interface(struct nand_chip *chip, int target,
>  				 DQS_BUFF_SEL_OUT(dqs_mode);
>  	}
>  
> -	anand->clk = ANFC_XLNX_SDR_DFLT_CORE_CLK;
> +	ret = clk_set_rate(nfc->bus_clk, ANFC_XLNX_SDR_DFLT_CORE_CLK);
> +	if (ret) {
> +		dev_err(nfc->dev, "Failed to change bus clock rate\n");
> +		return ret;
> +	}
>  
>  	/*
>  	 * Due to a hardware bug in the ZynqMP SoC, SDR timing modes 0-1 work
> @@ -1052,8 +1057,13 @@ static int anfc_setup_interface(struct nand_chip *chip, int target,
>  	 * 80MHz when using SDR modes 2-5 with this SoC.
>  	 */
>  	if (of_device_is_compatible(np, "xlnx,zynqmp-nand-controller") &&
> -	    nand_interface_is_sdr(conf) && conf->timings.mode >= 2)
> -		anand->clk = ANFC_XLNX_SDR_HS_CORE_CLK;
> +	    nand_interface_is_sdr(conf) && conf->timings.mode >= 2) {
> +		ret = clk_set_rate(nfc->bus_clk, ANFC_XLNX_SDR_HS_CORE_CLK);
> +		if (ret) {
> +			dev_err(nfc->dev, "Failed to change bus clock rate\n");
> +			return ret;
> +		}
> +	}
>  
>  	return 0;
>  }


Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH v2 1/2] mtd: rawnand: arasan: Update NAND bus clock instead of system clock
  2022-06-24 18:45   ` Miquel Raynal
@ 2022-06-27 16:23     ` Mahapatra, Amit Kumar
  0 siblings, 0 replies; 5+ messages in thread
From: Mahapatra, Amit Kumar @ 2022-06-27 16:23 UTC (permalink / raw)
  To: Miquel Raynal, Amit Kumar Mahapatra
  Cc: vigneshr, git (AMD-Xilinx), boris.brezillon, linux-mtd, linux-kernel

Hello Miquel,

> -----Original Message-----
> From: Miquel Raynal <miquel.raynal@bootlin.com>
> Sent: Saturday, June 25, 2022 12:15 AM
> To: Amit Kumar Mahapatra <amit.kumar-mahapatra@xilinx.com>
> Cc: vigneshr@ti.com; git (AMD-Xilinx) <git@amd.com>;
> boris.brezillon@collabora.com; linux-mtd@lists.infradead.org; linux-
> kernel@vger.kernel.org; Mahapatra, Amit Kumar <amit.kumar-
> mahapatra@amd.com>; Mahapatra, Amit Kumar <amit.kumar-
> mahapatra@amd.com>
> Subject: Re: [PATCH v2 1/2] mtd: rawnand: arasan: Update NAND bus clock
> instead of system clock
> 
> Hi Amit,
> 
> amit.kumar-mahapatra@xilinx.com wrote on Tue, 21 Jun 2022 14:24:59
> +0530:
> 
> > In current implementation the Arasan NAND driver is updating the
> > system clock(i.e., anand->clk) in accordance to the timing modes
> > (i.e., SDR or NVDDR). But as per the Arasan NAND controller spec the
> > flash clock or the NAND bus clock(i.e., nfc->bus_clk), need to be
> > updated instead. This patch keeps the system clock unchanged and
> > updates the NAND bus clock as per the timing modes.
> 
> This is not what you do below. If the clock that is changed is the wrong one,
> then just change the clock used in the clk_set_rate call instead of calling
> clk_set_rate twice at the wrong location.
> ->set_interface is done once per chip, if you have two different chips
> on the same system you must change the clock when you switch from one
> chip to the other. Your current implementation disrespects that,
> unfortunately.


 Will make the changes in the next iteration.
> 
> >
> > Fixes: 197b88fecc50 ("mtd: rawnand: arasan: Add new Arasan NAND
> > controller")
> 
> Requires a Cc: stable tag

Will this in the next iteration.

Regards,
Amit
> 
> > Signed-off-by: Amit Kumar Mahapatra <amit.kumar-
> mahapatra@xilinx.com>
> > ---
> >  drivers/mtd/nand/raw/arasan-nand-controller.c | 16 +++++++++++++---
> >  1 file changed, 13 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/mtd/nand/raw/arasan-nand-controller.c
> > b/drivers/mtd/nand/raw/arasan-nand-controller.c
> > index 53bd10738418..4f6da82dd2b1 100644
> > --- a/drivers/mtd/nand/raw/arasan-nand-controller.c
> > +++ b/drivers/mtd/nand/raw/arasan-nand-controller.c
> > @@ -968,6 +968,7 @@ static int anfc_setup_interface(struct nand_chip
> *chip, int target,
> >  	const struct nand_sdr_timings *sdr;
> >  	const struct nand_nvddr_timings *nvddr;
> >  	unsigned int tccs_min, dqs_mode, fast_tcad;
> > +	int ret;
> >
> >  	if (nand_interface_is_nvddr(conf)) {
> >  		nvddr = nand_get_nvddr_timings(conf); @@ -1043,7
> +1044,11 @@ static
> > int anfc_setup_interface(struct nand_chip *chip, int target,
> >  				 DQS_BUFF_SEL_OUT(dqs_mode);
> >  	}
> >
> > -	anand->clk = ANFC_XLNX_SDR_DFLT_CORE_CLK;
> > +	ret = clk_set_rate(nfc->bus_clk, ANFC_XLNX_SDR_DFLT_CORE_CLK);
> > +	if (ret) {
> > +		dev_err(nfc->dev, "Failed to change bus clock rate\n");
> > +		return ret;
> > +	}
> >
> >  	/*
> >  	 * Due to a hardware bug in the ZynqMP SoC, SDR timing modes 0-1
> > work @@ -1052,8 +1057,13 @@ static int anfc_setup_interface(struct
> nand_chip *chip, int target,
> >  	 * 80MHz when using SDR modes 2-5 with this SoC.
> >  	 */
> >  	if (of_device_is_compatible(np, "xlnx,zynqmp-nand-controller") &&
> > -	    nand_interface_is_sdr(conf) && conf->timings.mode >= 2)
> > -		anand->clk = ANFC_XLNX_SDR_HS_CORE_CLK;
> > +	    nand_interface_is_sdr(conf) && conf->timings.mode >= 2) {
> > +		ret = clk_set_rate(nfc->bus_clk,
> ANFC_XLNX_SDR_HS_CORE_CLK);
> > +		if (ret) {
> > +			dev_err(nfc->dev, "Failed to change bus clock
> rate\n");
> > +			return ret;
> > +		}
> > +	}
> >
> >  	return 0;
> >  }
> 
> 
> Thanks,
> Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-06-27 16:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-21  8:54 [PATCH v2 0/2] mtd: rawnand: arasan: Fix clock rate in NV-DDR Amit Kumar Mahapatra
2022-06-21  8:54 ` [PATCH v2 1/2] mtd: rawnand: arasan: Update NAND bus clock instead of system clock Amit Kumar Mahapatra
2022-06-24 18:45   ` Miquel Raynal
2022-06-27 16:23     ` Mahapatra, Amit Kumar
2022-06-21  8:55 ` [PATCH v2 2/2] mtd: rawnand: arasan: Fix clock rate in NV-DDR Amit Kumar Mahapatra

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).