linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [NAND] S3C2410: Fix NFC clock enable/disable imbalance
@ 2009-12-08  9:56 Juergen Beisert
  2009-12-08 10:23 ` Juergen Beisert
       [not found] ` <4B1E3815.9020901@ru.mvista.com>
  0 siblings, 2 replies; 6+ messages in thread
From: Juergen Beisert @ 2009-12-08  9:56 UTC (permalink / raw)
  To: linux-arm-kernel

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);
 }
 

-- 
Pengutronix e.K.                              | Juergen Beisert             |
Linux Solutions for Science and Industry      | Phone: +49-8766-939 228     |
Vertretung Sued/Muenchen, Germany             | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686              | http://www.pengutronix.de/  |

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

* [PATCH] [NAND] S3C2410: Fix NFC clock enable/disable imbalance
  2009-12-08  9:56 [PATCH] [NAND] S3C2410: Fix NFC clock enable/disable imbalance Juergen Beisert
@ 2009-12-08 10:23 ` Juergen Beisert
  2009-12-08 12:01   ` [PATCH] [NAND] S3C2410: Fix NFC clock enable/disable imbalance (2nd try) Juergen Beisert
       [not found] ` <4B1E3815.9020901@ru.mvista.com>
  1 sibling, 1 reply; 6+ messages in thread
From: Juergen Beisert @ 2009-12-08 10:23 UTC (permalink / raw)
  To: linux-arm-kernel

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

-- 
Pengutronix e.K.                              | Juergen Beisert             |
Linux Solutions for Science and Industry      | Phone: +49-8766-939 228     |
Vertretung Sued/Muenchen, Germany             | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686              | http://www.pengutronix.de/  |

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

* [PATCH] [NAND] S3C2410: Fix NFC clock enable/disable imbalance (2nd try)
  2009-12-08 10:23 ` Juergen Beisert
@ 2009-12-08 12:01   ` Juergen Beisert
  2009-12-08 13:17     ` Ladislav Michl
  0 siblings, 1 reply; 6+ messages in thread
From: Juergen Beisert @ 2009-12-08 12:01 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Due to a lack of a query function if a clock is already enabled (and how often),
we must count enable/disable calls by our own here.

Note: Other enable/disable sequences can be found in the power management
functions. I'm not sure if they interfere with this local enable/disable count.

Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
Acked-by: Wolfram Sang <wsa@pengutronix.de>

---
 drivers/mtd/nand/s3c2410.c |    9 +++++++--
 1 file changed, 7 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,15 @@ static void s3c2410_nand_select_chip(str
 	struct s3c2410_nand_mtd *nmtd;
 	struct nand_chip *this = mtd->priv;
 	unsigned long cur;
+	static int clock_enable_cnt = 0;
 
 	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_enable_cnt++;
+	}
 
 	cur = readl(info->sel_reg);
 
@@ -356,8 +359,10 @@ 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_enable_cnt > 0) {
 		clk_disable(info->clk);
+		clock_enable_cnt--;
+	}
 }
 
 /* s3c2410_nand_hwcontrol

-- 
Pengutronix e.K.                              | Juergen Beisert             |
Linux Solutions for Science and Industry      | Phone: +49-8766-939 228     |
Vertretung Sued/Muenchen, Germany             | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686              | http://www.pengutronix.de/  |

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

* [PATCH] [NAND] S3C2410: Fix NFC clock enable/disable imbalance
       [not found] ` <4B1E3815.9020901@ru.mvista.com>
@ 2009-12-08 12:07   ` Juergen Beisert
  2009-12-08 12:16     ` Ben Dooks
  0 siblings, 1 reply; 6+ messages in thread
From: Juergen Beisert @ 2009-12-08 12:07 UTC (permalink / raw)
  To: linux-arm-kernel

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

-- 
Pengutronix e.K.                              | Juergen Beisert             |
Linux Solutions for Science and Industry      | Phone: +49-8766-939 228     |
Vertretung Sued/Muenchen, Germany             | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686              | http://www.pengutronix.de/  |

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

* [PATCH] [NAND] S3C2410: Fix NFC clock enable/disable imbalance
  2009-12-08 12:07   ` [PATCH] [NAND] S3C2410: Fix NFC clock enable/disable imbalance Juergen Beisert
@ 2009-12-08 12:16     ` Ben Dooks
  0 siblings, 0 replies; 6+ messages in thread
From: Ben Dooks @ 2009-12-08 12:16 UTC (permalink / raw)
  To: linux-arm-kernel

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.

-- 
Ben

Q:      What's a light-year?
A:      One-third less calories than a regular year.

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

* [PATCH] [NAND] S3C2410: Fix NFC clock enable/disable imbalance (2nd try)
  2009-12-08 12:01   ` [PATCH] [NAND] S3C2410: Fix NFC clock enable/disable imbalance (2nd try) Juergen Beisert
@ 2009-12-08 13:17     ` Ladislav Michl
  0 siblings, 0 replies; 6+ messages in thread
From: Ladislav Michl @ 2009-12-08 13:17 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Dec 08, 2009 at 01:01:25PM +0100, 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.
> 
> Due to a lack of a query function if a clock is already enabled (and how often),
> we must count enable/disable calls by our own here.
> 
> Note: Other enable/disable sequences can be found in the power management
> functions. I'm not sure if they interfere with this local enable/disable count.
> 
> Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
> Acked-by: Wolfram Sang <wsa@pengutronix.de>
> 
> ---
>  drivers/mtd/nand/s3c2410.c |    9 +++++++--
>  1 file changed, 7 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,15 @@ static void s3c2410_nand_select_chip(str
>  	struct s3c2410_nand_mtd *nmtd;
>  	struct nand_chip *this = mtd->priv;
>  	unsigned long cur;
> +	static int clock_enable_cnt = 0;

It probably does not matter a lot, since there seem to be only one
nand controller and associated clock per system, but it would be
cleaner to move this variable into struct s3c2410_nand_info to allow
this driver eventually service multiple instances of nand controller.

>  	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_enable_cnt++;
> +	}
>  
>  	cur = readl(info->sel_reg);
>  
> @@ -356,8 +359,10 @@ 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_enable_cnt > 0) {
>  		clk_disable(info->clk);
> +		clock_enable_cnt--;
> +	}
>  }
>  
>  /* s3c2410_nand_hwcontrol
> 
> -- 
> Pengutronix e.K.                              | Juergen Beisert             |
> Linux Solutions for Science and Industry      | Phone: +49-8766-939 228     |
> Vertretung Sued/Muenchen, Germany             | Fax:   +49-5121-206917-5555 |
> Amtsgericht Hildesheim, HRA 2686              | http://www.pengutronix.de/  |
> 
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

end of thread, other threads:[~2009-12-08 13:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-08  9:56 [PATCH] [NAND] S3C2410: Fix NFC clock enable/disable imbalance Juergen Beisert
2009-12-08 10:23 ` Juergen Beisert
2009-12-08 12:01   ` [PATCH] [NAND] S3C2410: Fix NFC clock enable/disable imbalance (2nd try) Juergen Beisert
2009-12-08 13:17     ` Ladislav Michl
     [not found] ` <4B1E3815.9020901@ru.mvista.com>
2009-12-08 12:07   ` [PATCH] [NAND] S3C2410: Fix NFC clock enable/disable imbalance Juergen Beisert
2009-12-08 12:16     ` Ben Dooks

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