Commit 2a513ce7 authored by Ben Dooks's avatar Ben Dooks Committed by Russell King

[ARM] 3303/1: S3C24XX - add clock enable usage counting

Patch from Ben Dooks

Move to using an enable count for the shared clocks
and protect the clock system using a mutex instead
of just disabling IRQs during the clock update.

Since there is little more code in the path for
non-shared clocks, the enable and disable calls
use the same code for each.
Signed-off-by: default avatarBen Dooks <ben-linux@fluff.org>
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent f8e5b284
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <asm/hardware.h> #include <asm/hardware.h>
#include <asm/atomic.h>
#include <asm/irq.h> #include <asm/irq.h>
#include <asm/io.h> #include <asm/io.h>
...@@ -59,22 +58,18 @@ static DEFINE_MUTEX(clocks_mutex); ...@@ -59,22 +58,18 @@ static DEFINE_MUTEX(clocks_mutex);
void inline s3c24xx_clk_enable(unsigned int clocks, unsigned int enable) void inline s3c24xx_clk_enable(unsigned int clocks, unsigned int enable)
{ {
unsigned long clkcon; unsigned long clkcon;
unsigned long flags;
local_irq_save(flags);
clkcon = __raw_readl(S3C2410_CLKCON); clkcon = __raw_readl(S3C2410_CLKCON);
clkcon &= ~clocks;
if (enable) if (enable)
clkcon |= clocks; clkcon |= clocks;
else
clkcon &= ~clocks;
/* ensure none of the special function bits set */ /* ensure none of the special function bits set */
clkcon &= ~(S3C2410_CLKCON_IDLE|S3C2410_CLKCON_POWER); clkcon &= ~(S3C2410_CLKCON_IDLE|S3C2410_CLKCON_POWER);
__raw_writel(clkcon, S3C2410_CLKCON); __raw_writel(clkcon, S3C2410_CLKCON);
local_irq_restore(flags);
} }
/* enable and disable calls for use with the clk struct */ /* enable and disable calls for use with the clk struct */
...@@ -138,16 +133,32 @@ void clk_put(struct clk *clk) ...@@ -138,16 +133,32 @@ void clk_put(struct clk *clk)
int clk_enable(struct clk *clk) int clk_enable(struct clk *clk)
{ {
if (IS_ERR(clk)) if (IS_ERR(clk) || clk == NULL)
return -EINVAL; return -EINVAL;
return (clk->enable)(clk, 1); clk_enable(clk->parent);
mutex_lock(&clocks_mutex);
if ((clk->usage++) == 0)
(clk->enable)(clk, 1);
mutex_unlock(&clocks_mutex);
return 0;
} }
void clk_disable(struct clk *clk) void clk_disable(struct clk *clk)
{ {
if (!IS_ERR(clk)) if (IS_ERR(clk) || clk == NULL)
return;
mutex_lock(&clocks_mutex);
if ((--clk->usage) == 0)
(clk->enable)(clk, 0); (clk->enable)(clk, 0);
mutex_unlock(&clocks_mutex);
clk_disable(clk->parent);
} }
...@@ -361,6 +372,14 @@ int s3c24xx_register_clock(struct clk *clk) ...@@ -361,6 +372,14 @@ int s3c24xx_register_clock(struct clk *clk)
if (clk->enable == NULL) if (clk->enable == NULL)
clk->enable = clk_null_enable; clk->enable = clk_null_enable;
/* if this is a standard clock, set the usage state */
if (clk->ctrlbit) {
unsigned long clkcon = __raw_readl(S3C2410_CLKCON);
clk->usage = (clkcon & clk->ctrlbit) ? 1 : 0;
}
/* add to the list of available clocks */ /* add to the list of available clocks */
mutex_lock(&clocks_mutex); mutex_lock(&clocks_mutex);
...@@ -402,6 +421,8 @@ int __init s3c24xx_setup_clocks(unsigned long xtal, ...@@ -402,6 +421,8 @@ int __init s3c24xx_setup_clocks(unsigned long xtal,
* the LCD clock if it is not needed. * the LCD clock if it is not needed.
*/ */
mutex_lock(&clocks_mutex);
s3c24xx_clk_enable(S3C2410_CLKCON_NAND, 0); s3c24xx_clk_enable(S3C2410_CLKCON_NAND, 0);
s3c24xx_clk_enable(S3C2410_CLKCON_USBH, 0); s3c24xx_clk_enable(S3C2410_CLKCON_USBH, 0);
s3c24xx_clk_enable(S3C2410_CLKCON_USBD, 0); s3c24xx_clk_enable(S3C2410_CLKCON_USBD, 0);
...@@ -409,6 +430,8 @@ int __init s3c24xx_setup_clocks(unsigned long xtal, ...@@ -409,6 +430,8 @@ int __init s3c24xx_setup_clocks(unsigned long xtal,
s3c24xx_clk_enable(S3C2410_CLKCON_IIC, 0); s3c24xx_clk_enable(S3C2410_CLKCON_IIC, 0);
s3c24xx_clk_enable(S3C2410_CLKCON_SPI, 0); s3c24xx_clk_enable(S3C2410_CLKCON_SPI, 0);
mutex_unlock(&clocks_mutex);
/* assume uart clocks are correctly setup */ /* assume uart clocks are correctly setup */
/* register our clocks */ /* register our clocks */
......
...@@ -16,6 +16,7 @@ struct clk { ...@@ -16,6 +16,7 @@ struct clk {
struct clk *parent; struct clk *parent;
const char *name; const char *name;
int id; int id;
int usage;
unsigned long rate; unsigned long rate;
unsigned long ctrlbit; unsigned long ctrlbit;
int (*enable)(struct clk *, int enable); int (*enable)(struct clk *, int enable);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment