diff mbox

[NAND] S3C2410: Fix NFC clock enable/disable imbalance

Message ID 200912081056.40210.jbe@pengutronix.de
State New, archived
Headers show

Commit Message

Juergen Borleis Dec. 8, 2009, 9:56 a.m. UTC
When unmounting an mtd filesystem the s3c2410_nand_select_chip() function
gets called again with "chip == -1". In this case the current code disables
the NFC clock at least a second time, so it does not work anymore.
Clock disabling should only happen if it was really enabled.

Signed-off-by: Juergen Beisert <jbe@pengutronix.de>

---
 drivers/mtd/nand/s3c2410.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Juergen Borleis Dec. 8, 2009, 10:23 a.m. UTC | #1
Hi,

ups, forget this patch, does't work as expected (thanks Wolfram!). Will try 
again later...

Juergen Beisert wrote:
> When unmounting an mtd filesystem the s3c2410_nand_select_chip() function
> gets called again with "chip == -1". In this case the current code disables
> the NFC clock at least a second time, so it does not work anymore.
> Clock disabling should only happen if it was really enabled.
>
> Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
>
> ---
>  drivers/mtd/nand/s3c2410.c |    8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> Index: linux-2.6.32/drivers/mtd/nand/s3c2410.c
> ===================================================================
> --- linux-2.6.32.orig/drivers/mtd/nand/s3c2410.c
> +++ linux-2.6.32/drivers/mtd/nand/s3c2410.c
> @@ -329,12 +329,16 @@ static void s3c2410_nand_select_chip(str
>  	struct s3c2410_nand_mtd *nmtd;
>  	struct nand_chip *this = mtd->priv;
>  	unsigned long cur;
> +	int clock_enabled;
>
>  	nmtd = this->priv;
>  	info = nmtd->info;
>
> -	if (chip != -1 && allow_clk_stop(info))
> +	if (chip != -1 && allow_clk_stop(info)) {
>  		clk_enable(info->clk);
> +		clock_enabled = 1;
> +	} else
> +		clock_enabled = 0;
>
>  	cur = readl(info->sel_reg);
>
> @@ -356,7 +360,7 @@ static void s3c2410_nand_select_chip(str
>
>  	writel(cur, info->sel_reg);
>
> -	if (chip == -1 && allow_clk_stop(info))
> +	if (chip == -1 && allow_clk_stop(info) && clock_enabled != 0)
>  		clk_disable(info->clk);
>  }

Juergen
Juergen Borleis Dec. 8, 2009, 12:07 p.m. UTC | #2
On Dienstag, 8. Dezember 2009, Sergei Shtylyov wrote:
> Hello.
>
> Juergen Beisert wrote:
> > When unmounting an mtd filesystem the s3c2410_nand_select_chip() function
> > gets called again with "chip == -1". In this case the current code
> > disables the NFC clock at least a second time, so it does not work
> > anymore. Clock disabling should only happen if it was really enabled.
> >
> > Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
> >
> > ---
> >  drivers/mtd/nand/s3c2410.c |    8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > Index: linux-2.6.32/drivers/mtd/nand/s3c2410.c
> > ===================================================================
> > --- linux-2.6.32.orig/drivers/mtd/nand/s3c2410.c
> > +++ linux-2.6.32/drivers/mtd/nand/s3c2410.c
> > @@ -329,12 +329,16 @@ static void s3c2410_nand_select_chip(str
> >  	struct s3c2410_nand_mtd *nmtd;
> >  	struct nand_chip *this = mtd->priv;
> >  	unsigned long cur;
> > +	int clock_enabled;
>
>    Could be *bool*...

I'm not sure. When this function is called more than once to disable a NAND 
device chip select, who knows if it might be called more than once to enable 
it? Just an idea.

jbe
Ben Dooks Dec. 8, 2009, 12:16 p.m. UTC | #3
On Tue, Dec 08, 2009 at 01:07:17PM +0100, Juergen Beisert wrote:
> On Dienstag, 8. Dezember 2009, Sergei Shtylyov wrote:
> > Hello.
> >
> > Juergen Beisert wrote:
> > > When unmounting an mtd filesystem the s3c2410_nand_select_chip() function
> > > gets called again with "chip == -1". In this case the current code
> > > disables the NFC clock at least a second time, so it does not work
> > > anymore. Clock disabling should only happen if it was really enabled.
> > >
> > > Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
> > >
> > > ---
> > >  drivers/mtd/nand/s3c2410.c |    8 ++++++--
> > >  1 file changed, 6 insertions(+), 2 deletions(-)
> > >
> > > Index: linux-2.6.32/drivers/mtd/nand/s3c2410.c
> > > ===================================================================
> > > --- linux-2.6.32.orig/drivers/mtd/nand/s3c2410.c
> > > +++ linux-2.6.32/drivers/mtd/nand/s3c2410.c
> > > @@ -329,12 +329,16 @@ static void s3c2410_nand_select_chip(str
> > >  	struct s3c2410_nand_mtd *nmtd;
> > >  	struct nand_chip *this = mtd->priv;
> > >  	unsigned long cur;
> > > +	int clock_enabled;
> >
> >    Could be *bool*...
> 
> I'm not sure. When this function is called more than once to disable a NAND 
> device chip select, who knows if it might be called more than once to enable 
> it? Just an idea.

it might be worth tracking the clock state, not only in these case but to
ensure that things like suspend/resume cycles don't cause problems too.
diff mbox

Patch

Index: linux-2.6.32/drivers/mtd/nand/s3c2410.c
===================================================================
--- linux-2.6.32.orig/drivers/mtd/nand/s3c2410.c
+++ linux-2.6.32/drivers/mtd/nand/s3c2410.c
@@ -329,12 +329,16 @@  static void s3c2410_nand_select_chip(str
 	struct s3c2410_nand_mtd *nmtd;
 	struct nand_chip *this = mtd->priv;
 	unsigned long cur;
+	int clock_enabled;
 
 	nmtd = this->priv;
 	info = nmtd->info;
 
-	if (chip != -1 && allow_clk_stop(info))
+	if (chip != -1 && allow_clk_stop(info)) {
 		clk_enable(info->clk);
+		clock_enabled = 1;
+	} else
+		clock_enabled = 0;
 
 	cur = readl(info->sel_reg);
 
@@ -356,7 +360,7 @@  static void s3c2410_nand_select_chip(str
 
 	writel(cur, info->sel_reg);
 
-	if (chip == -1 && allow_clk_stop(info))
+	if (chip == -1 && allow_clk_stop(info) && clock_enabled != 0)
 		clk_disable(info->clk);
 }