ARM: davinci: serial: provide API to initialze UART clocks
authorSekhar Nori <nsekhar@ti.com>
Wed, 29 Aug 2012 17:18:52 +0000 (22:48 +0530)
committerSekhar Nori <nsekhar@ti.com>
Sat, 27 Oct 2012 10:58:31 +0000 (16:28 +0530)
Provide an API to initialize a UART clock. Refactor existing
davinci_serial_init() to separate out the part which enables
the clock.

This will later be used to help DA850 DT boot support.

Signed-off-by: Sekhar Nori <nsekhar@ti.com>
arch/arm/mach-davinci/include/mach/serial.h
arch/arm/mach-davinci/serial.c

index 46b3cd11c3c2ec582e2972202f1c6277494fe9ea..2d9d921e8b01be034549d9d1ea3df3c7f713d79a 100644 (file)
@@ -43,6 +43,7 @@ struct davinci_uart_config {
 };
 
 extern int davinci_serial_init(struct davinci_uart_config *);
+extern int davinci_serial_setup_clk(unsigned instance, unsigned int *rate);
 #endif
 
 #endif /* __ASM_ARCH_SERIAL_H */
index 24ddb0d32a0f8c36b964d744c2837d34274a8ff4..f2625814c3c9b3160d5b163efbbd9cb799ced23e 100644 (file)
@@ -70,11 +70,33 @@ static void __init davinci_serial_reset(struct plat_serial8250_port *p)
                                 UART_DM646X_SCR_TX_WATERMARK);
 }
 
-int __init davinci_serial_init(struct davinci_uart_config *info)
+/* Enable UART clock and obtain its rate */
+int __init davinci_serial_setup_clk(unsigned instance, unsigned int *rate)
 {
-       int i;
        char name[16];
-       struct clk *uart_clk;
+       struct clk *clk;
+       struct davinci_soc_info *soc_info = &davinci_soc_info;
+       struct device *dev = &soc_info->serial_dev->dev;
+
+       sprintf(name, "uart%d", instance);
+       clk = clk_get(dev, name);
+       if (IS_ERR(clk)) {
+               pr_err("%s:%d: failed to get UART%d clock\n",
+                                       __func__, __LINE__, instance);
+               return PTR_ERR(clk);
+       }
+
+       clk_prepare_enable(clk);
+
+       if (rate)
+               *rate = clk_get_rate(clk);
+
+       return 0;
+}
+
+int __init davinci_serial_init(struct davinci_uart_config *info)
+{
+       int i, ret;
        struct davinci_soc_info *soc_info = &davinci_soc_info;
        struct device *dev = &soc_info->serial_dev->dev;
        struct plat_serial8250_port *p = dev->platform_data;
@@ -87,16 +109,9 @@ int __init davinci_serial_init(struct davinci_uart_config *info)
                if (!(info->enabled_uarts & (1 << i)))
                        continue;
 
-               sprintf(name, "uart%d", i);
-               uart_clk = clk_get(dev, name);
-               if (IS_ERR(uart_clk)) {
-                       printk(KERN_ERR "%s:%d: failed to get UART%d clock\n",
-                                       __func__, __LINE__, i);
+               ret = davinci_serial_setup_clk(i, &p->uartclk);
+               if (ret)
                        continue;
-               }
-
-               clk_prepare_enable(uart_clk);
-               p->uartclk = clk_get_rate(uart_clk);
 
                if (!p->membase && p->mapbase) {
                        p->membase = ioremap(p->mapbase, SZ_4K);