Commit 046c217c authored by Thomas Abraham's avatar Thomas Abraham Committed by Kukjin Kim

ARM: S3C2440: move handling of fclk/n clock to platform code

s3c2440 uses fclk/n (fclk divided by n) clock as one of the possible clocks used
to generate the baud rate clock. The divider 'n' in this case can be logically
represented outside of the uart controller.

This patch creates a new clock by name "fclk_n" for s3c2440 based platforms to
represent the fclk/n clock in the platform code. This clock provides a get_rate
callback that checks the UCON0/1/2 registers to determine the clock rate. The
samsung uart driver would receive the "fclk_n" clock name as one of the possible
baud rate clock options and the driver need not determine clock rate of fclk/n.

Cc: Ben Dooks <ben-linux@fluff.org>
Cc: Vasily Khoruzhick <anarsoul@gmail.com>
Signed-off-by: default avatarThomas Abraham <thomas.abraham@linaro.org>
Signed-off-by: default avatarKukjin Kim <kgene.kim@samsung.com>
parent 4d84e970
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/serial_core.h>
#include <mach/hardware.h> #include <mach/hardware.h>
#include <linux/atomic.h> #include <linux/atomic.h>
...@@ -43,6 +44,7 @@ ...@@ -43,6 +44,7 @@
#include <plat/clock.h> #include <plat/clock.h>
#include <plat/cpu.h> #include <plat/cpu.h>
#include <plat/regs-serial.h>
/* S3C2440 extended clock support */ /* S3C2440 extended clock support */
...@@ -108,6 +110,40 @@ static struct clk s3c2440_clk_ac97 = { ...@@ -108,6 +110,40 @@ static struct clk s3c2440_clk_ac97 = {
.ctrlbit = S3C2440_CLKCON_CAMERA, .ctrlbit = S3C2440_CLKCON_CAMERA,
}; };
static unsigned long s3c2440_fclk_n_getrate(struct clk *clk)
{
unsigned long ucon0, ucon1, ucon2, divisor;
/* the fun of calculating the uart divisors on the s3c2440 */
ucon0 = __raw_readl(S3C24XX_VA_UART0 + S3C2410_UCON);
ucon1 = __raw_readl(S3C24XX_VA_UART1 + S3C2410_UCON);
ucon2 = __raw_readl(S3C24XX_VA_UART2 + S3C2410_UCON);
ucon0 &= S3C2440_UCON0_DIVMASK;
ucon1 &= S3C2440_UCON1_DIVMASK;
ucon2 &= S3C2440_UCON2_DIVMASK;
if (ucon0 != 0)
divisor = (ucon0 >> S3C2440_UCON_DIVSHIFT) + 6;
else if (ucon1 != 0)
divisor = (ucon1 >> S3C2440_UCON_DIVSHIFT) + 21;
else if (ucon2 != 0)
divisor = (ucon2 >> S3C2440_UCON_DIVSHIFT) + 36;
else
/* manual calims 44, seems to be 9 */
divisor = 9;
return clk_get_rate(clk->parent) / divisor;
}
static struct clk s3c2440_clk_fclk_n = {
.name = "fclk_n",
.parent = &clk_f,
.ops = &(struct clk_ops) {
.get_rate = s3c2440_fclk_n_getrate,
},
};
static int s3c2440_clk_add(struct sys_device *sysdev) static int s3c2440_clk_add(struct sys_device *sysdev)
{ {
struct clk *clock_upll; struct clk *clock_upll;
...@@ -126,6 +162,7 @@ static int s3c2440_clk_add(struct sys_device *sysdev) ...@@ -126,6 +162,7 @@ static int s3c2440_clk_add(struct sys_device *sysdev)
s3c2440_clk_cam.parent = clock_h; s3c2440_clk_cam.parent = clock_h;
s3c2440_clk_ac97.parent = clock_p; s3c2440_clk_ac97.parent = clock_p;
s3c2440_clk_cam_upll.parent = clock_upll; s3c2440_clk_cam_upll.parent = clock_upll;
s3c24xx_register_clock(&s3c2440_clk_fclk_n);
s3c24xx_register_clock(&s3c2440_clk_ac97); s3c24xx_register_clock(&s3c2440_clk_ac97);
s3c24xx_register_clock(&s3c2440_clk_cam); s3c24xx_register_clock(&s3c2440_clk_cam);
......
...@@ -70,8 +70,8 @@ static struct map_desc rx1950_iodesc[] __initdata = { ...@@ -70,8 +70,8 @@ static struct map_desc rx1950_iodesc[] __initdata = {
static struct s3c24xx_uart_clksrc rx1950_serial_clocks[] = { static struct s3c24xx_uart_clksrc rx1950_serial_clocks[] = {
[0] = { [0] = {
.name = "fclk", .name = "fclk_n",
.divisor = 0x0a, .divisor = 1,
.min_baud = 0, .min_baud = 0,
.max_baud = 0, .max_baud = 0,
}, },
......
...@@ -70,8 +70,8 @@ static struct map_desc rx3715_iodesc[] __initdata = { ...@@ -70,8 +70,8 @@ static struct map_desc rx3715_iodesc[] __initdata = {
static struct s3c24xx_uart_clksrc rx3715_serial_clocks[] = { static struct s3c24xx_uart_clksrc rx3715_serial_clocks[] = {
[0] = { [0] = {
.name = "fclk", .name = "fclk_n",
.divisor = 0, .divisor = 1,
.min_baud = 0, .min_baud = 0,
.max_baud = 0, .max_baud = 0,
} }
......
...@@ -39,7 +39,7 @@ static int s3c2440_serial_setsource(struct uart_port *port, ...@@ -39,7 +39,7 @@ static int s3c2440_serial_setsource(struct uart_port *port,
ucon |= S3C2440_UCON_UCLK; ucon |= S3C2440_UCON_UCLK;
else if (strcmp(clk->name, "pclk") == 0) else if (strcmp(clk->name, "pclk") == 0)
ucon |= S3C2440_UCON_PCLK; ucon |= S3C2440_UCON_PCLK;
else if (strcmp(clk->name, "fclk") == 0) else if (strcmp(clk->name, "fclk_n") == 0)
ucon |= S3C2440_UCON_FCLK; ucon |= S3C2440_UCON_FCLK;
else { else {
printk(KERN_ERR "unknown clock source %s\n", clk->name); printk(KERN_ERR "unknown clock source %s\n", clk->name);
...@@ -55,7 +55,6 @@ static int s3c2440_serial_getsource(struct uart_port *port, ...@@ -55,7 +55,6 @@ static int s3c2440_serial_getsource(struct uart_port *port,
struct s3c24xx_uart_clksrc *clk) struct s3c24xx_uart_clksrc *clk)
{ {
unsigned long ucon = rd_regl(port, S3C2410_UCON); unsigned long ucon = rd_regl(port, S3C2410_UCON);
unsigned long ucon0, ucon1, ucon2;
switch (ucon & S3C2440_UCON_CLKMASK) { switch (ucon & S3C2440_UCON_CLKMASK) {
case S3C2440_UCON_UCLK: case S3C2440_UCON_UCLK:
...@@ -70,34 +69,8 @@ static int s3c2440_serial_getsource(struct uart_port *port, ...@@ -70,34 +69,8 @@ static int s3c2440_serial_getsource(struct uart_port *port,
break; break;
case S3C2440_UCON_FCLK: case S3C2440_UCON_FCLK:
/* the fun of calculating the uart divisors on clk->divisor = 1;
* the s3c2440 */ clk->name = "fclk_n";
ucon0 = __raw_readl(S3C24XX_VA_UART0 + S3C2410_UCON);
ucon1 = __raw_readl(S3C24XX_VA_UART1 + S3C2410_UCON);
ucon2 = __raw_readl(S3C24XX_VA_UART2 + S3C2410_UCON);
printk("ucons: %08lx, %08lx, %08lx\n", ucon0, ucon1, ucon2);
ucon0 &= S3C2440_UCON0_DIVMASK;
ucon1 &= S3C2440_UCON1_DIVMASK;
ucon2 &= S3C2440_UCON2_DIVMASK;
if (ucon0 != 0) {
clk->divisor = ucon0 >> S3C2440_UCON_DIVSHIFT;
clk->divisor += 6;
} else if (ucon1 != 0) {
clk->divisor = ucon1 >> S3C2440_UCON_DIVSHIFT;
clk->divisor += 21;
} else if (ucon2 != 0) {
clk->divisor = ucon2 >> S3C2440_UCON_DIVSHIFT;
clk->divisor += 36;
} else {
/* manual calims 44, seems to be 9 */
clk->divisor = 9;
}
clk->name = "fclk";
break; break;
} }
......
...@@ -649,27 +649,6 @@ static unsigned int s3c24xx_serial_getclk(struct uart_port *port, ...@@ -649,27 +649,6 @@ static unsigned int s3c24xx_serial_getclk(struct uart_port *port,
if (cfg->clocks_size == 0) if (cfg->clocks_size == 0)
clkp = &tmp_clksrc; clkp = &tmp_clksrc;
/* check to see if we're sourcing fclk, and if so we're
* going to have to update the clock source
*/
if (strcmp(clkp->name, "fclk") == 0) {
struct s3c24xx_uart_clksrc src;
s3c24xx_serial_getsource(port, &src);
/* check that the port already using fclk, and if
* not, then re-select fclk
*/
if (strcmp(src.name, clkp->name) == 0) {
s3c24xx_serial_setsource(port, clkp);
s3c24xx_serial_getsource(port, &src);
}
clkp->divisor = src.divisor;
}
s3c24xx_serial_calcbaud(res, port, clkp, baud); s3c24xx_serial_calcbaud(res, port, clkp, baud);
best = res; best = res;
resptr = best + 1; resptr = best + 1;
......
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