Skip to contentSkip to conversation

S3C2410: Fix NFC clock enable/disable imbalance

PATCH New Juergen Beisert 3 participants 6 messages Dec 8, 2009 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 S3C2410: Fix NFC clock enable/disable imbalance

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.

---
 drivers/mtd/nand/s3c2410.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/mtd/nand/s3c2410.c +6 -2
Index: 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);
 }
 
Signature · 4 lines
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/  |
#1 lore raw

PATCH 1/1 S3C2410: Fix NFC clock enable/disable imbalance

Hi,

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

Quoted 34 lines · Juergen Beisert

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.

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

Index: linux-2.6.32/drivers/mtd/nand/s3c2410.c
===================================================================

drivers/mtd/nand/s3c2410.c +5 -1
@@ -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);
 

drivers/mtd/nand/s3c2410.c static void s3c2410_nand_select_chip(str · line 365

Quoted 7 lines
drivers/mtd/nand/s3c2410.c +1 -1
@@ -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

Signature · 4 lines
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/  |
#2 lore raw

PATCH 1/1 S3C2410: Fix NFC clock enable/disable imbalance (2nd try)

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.

---
 drivers/mtd/nand/s3c2410.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/mtd/nand/s3c2410.c +7 -2
Index: 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
Signature · 4 lines
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/  |
#3 lore raw

PATCH 1/1 S3C2410: Fix NFC clock enable/disable imbalance (2nd try)

Quoted 23 lines · Juergen Beisert

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.

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

Index: linux-2.6.32/drivers/mtd/nand/s3c2410.c
===================================================================

drivers/mtd/nand/s3c2410.c static void s3c2410_nand_select_chip(str · line 332

Quoted 4 lines
drivers/mtd/nand/s3c2410.c +1 -0
@@ -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.

Quoted 33 lines
drivers/mtd/nand/s3c2410.c +6 -2
 	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
Signature · 9 lines
-- 
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/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

PATCH 1/1 S3C2410: Fix NFC clock enable/disable imbalance

Quoted 14 lines · Sergei Shtylyov

Hello.

Quoted 11 lines · Juergen Beisert

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.

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

drivers/mtd/nand/s3c2410.c static void s3c2410_nand_select_chip(str · line 332

Quoted 9 lines

Index: linux-2.6.32/drivers/mtd/nand/s3c2410.c
===================================================================

drivers/mtd/nand/s3c2410.c +1 -0
@@ -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

Signature · 4 lines
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/  |
#6 lore raw

PATCH 1/1 S3C2410: Fix NFC clock enable/disable imbalance

Quoted 27 lines · Juergen Beisert
Quoted 14 lines · Sergei Shtylyov

Hello.

Quoted 11 lines · Juergen Beisert

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.

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

drivers/mtd/nand/s3c2410.c static void s3c2410_nand_select_chip(str · line 332

Quoted 9 lines

Index: linux-2.6.32/drivers/mtd/nand/s3c2410.c
===================================================================

drivers/mtd/nand/s3c2410.c +1 -0
@@ -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*...
Quoted 3 lines

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.

Signature · 4 lines
Ben

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