ARM: tegra: move uart debug port initialization into common file.
Laxman Dewangan [Thu, 11 Oct 2012 13:44:10 +0000 (18:44 +0530)]
There is lots of duplicate code for initializing
the debug port for all platform.
Move this to board-common file so that duplicate code
can be avoided.

Change-Id: I3e8a10cd3db4db21d6752a0b689136bfe9828197
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/143721
Reviewed-by: Mrutyunjay Sawant <msawant@nvidia.com>
Tested-by: Mrutyunjay Sawant <msawant@nvidia.com>

arch/arm/mach-tegra/Makefile
arch/arm/mach-tegra/board-cardhu.c
arch/arm/mach-tegra/board-common.c [new file with mode: 0644]
arch/arm/mach-tegra/board-common.h [new file with mode: 0644]
arch/arm/mach-tegra/board-enterprise.c
arch/arm/mach-tegra/board-kai.c

index 0f23463..0836b6d 100644 (file)
@@ -131,6 +131,7 @@ obj-$(CONFIG_TEGRA_DYNAMIC_PWRDET)      += powerdetect.o
 obj-$(CONFIG_TEGRA_USB_MODEM_POWER)     += tegra_usb_modem_power.o
 obj-$(CONFIG_ARCH_TEGRA_HAS_CL_DVFS)    += tegra_cl_dvfs.o
 
+obj-y                                  += board-common.o
 obj-$(CONFIG_TEGRA_PCI)                 += pcie.o
 obj-$(CONFIG_MACH_HARMONY)              += board-harmony.o
 obj-$(CONFIG_MACH_HARMONY)              += board-harmony-kbc.o
index 1e1f2a8..2584396 100644 (file)
@@ -72,6 +72,7 @@
 #include <asm/mach/arch.h>
 
 #include "board.h"
+#include "board-common.h"
 #include "clock.h"
 #include "board-cardhu.h"
 #include "board-touch-raydium.h"
@@ -438,28 +439,29 @@ static struct uart_clk_parent uart_parent_clk[] = {
 static struct tegra_uart_platform_data cardhu_uart_pdata;
 static struct tegra_uart_platform_data cardhu_loopback_uart_pdata;
 
-static void __init uart_debug_init(void)
+static int __init uart_debug_init(void)
 {
        struct board_info board_info;
        int debug_port_id;
+       int default_debug_port = 0;
 
        tegra_get_board_info(&board_info);
 
-       debug_port_id = get_tegra_uart_debug_port_id();
-       if (debug_port_id < 0) {
-               debug_port_id = 0;
-                       /* UARTB is debug port
-                        *       for SLT - E1186/E1187/PM269
-                        *       for E1256/E1257
-                        */
-               if (((board_info.sku & SKU_SLT_ULPI_SUPPORT) &&
-                       ((board_info.board_id == BOARD_E1186) ||
-                       (board_info.board_id == BOARD_E1187) ||
-                       (board_info.board_id == BOARD_PM269))) ||
-                       (board_info.board_id == BOARD_E1256) ||
-                       (board_info.board_id == BOARD_E1257))
-                               debug_port_id = 1;
-       }
+       /* UARTB is debug port
+        *       for SLT - E1186/E1187/PM269
+        *       for E1256/E1257
+        */
+       if (((board_info.sku & SKU_SLT_ULPI_SUPPORT) &&
+               ((board_info.board_id == BOARD_E1186) ||
+               (board_info.board_id == BOARD_E1187) ||
+               (board_info.board_id == BOARD_PM269))) ||
+               (board_info.board_id == BOARD_E1256) ||
+               (board_info.board_id == BOARD_E1257))
+                       default_debug_port = 1;
+
+       debug_port_id = uart_console_debug_init(default_debug_port);
+       if (debug_port_id < 0)
+               return debug_port_id;
 
 #ifdef CONFIG_TEGRA_IRDA
        if ((board_info.board_id == BOARD_E1186) ||
@@ -470,62 +472,8 @@ static void __init uart_debug_init(void)
                }
        }
 #endif
-
-       switch (debug_port_id) {
-       case 0:
-               /* UARTA is the debug port. */
-               pr_info("Selecting UARTA as the debug console\n");
-               cardhu_uart_devices[0] = &debug_uarta_device;
-               debug_uart_clk = clk_get_sys("serial8250.0", "uarta");
-               debug_uart_port_base = ((struct plat_serial8250_port *)(
-                       debug_uarta_device.dev.platform_data))->mapbase;
-               break;
-
-       case 1:
-               /* UARTB is the debug port. */
-               pr_info("Selecting UARTB as the debug console\n");
-               cardhu_uart_devices[1] = &debug_uartb_device;
-               debug_uart_clk =  clk_get_sys("serial8250.0", "uartb");
-               debug_uart_port_base = ((struct plat_serial8250_port *)(
-                       debug_uartb_device.dev.platform_data))->mapbase;
-               break;
-
-       case 2:
-               /* UARTC is the debug port. */
-               pr_info("Selecting UARTC as the debug console\n");
-               cardhu_uart_devices[2] = &debug_uartc_device;
-               debug_uart_clk =  clk_get_sys("serial8250.0", "uartc");
-               debug_uart_port_base = ((struct plat_serial8250_port *)(
-                       debug_uartc_device.dev.platform_data))->mapbase;
-               break;
-
-       case 3:
-               /* UARTD is the debug port. */
-               pr_info("Selecting UARTD as the debug console\n");
-               cardhu_uart_devices[3] = &debug_uartd_device;
-               debug_uart_clk =  clk_get_sys("serial8250.0", "uartd");
-               debug_uart_port_base = ((struct plat_serial8250_port *)(
-                       debug_uartd_device.dev.platform_data))->mapbase;
-               break;
-
-       case 4:
-               /* UARTE is the debug port. */
-               pr_info("Selecting UARTE as the debug console\n");
-               cardhu_uart_devices[4] = &debug_uarte_device;
-               debug_uart_clk =  clk_get_sys("serial8250.0", "uarte");
-               debug_uart_port_base = ((struct plat_serial8250_port *)(
-                       debug_uarte_device.dev.platform_data))->mapbase;
-               break;
-
-       default:
-               pr_info("The debug console id %d is invalid, Assuming UARTA", debug_port_id);
-               cardhu_uart_devices[0] = &debug_uarta_device;
-               debug_uart_clk = clk_get_sys("serial8250.0", "uarta");
-               debug_uart_port_base = ((struct plat_serial8250_port *)(
-                       debug_uarta_device.dev.platform_data))->mapbase;
-               break;
-       }
-       return;
+       cardhu_uart_devices[debug_port_id] = uart_console_debug_device;
+       return debug_port_id;
 }
 
 static void __init cardhu_uart_init(void)
@@ -560,25 +508,8 @@ static void __init cardhu_uart_init(void)
        tegra_uarte_device.dev.platform_data = &cardhu_loopback_uart_pdata;
 
        /* Register low speed only if it is selected */
-       if (!is_tegra_debug_uartport_hs()) {
+       if (!is_tegra_debug_uartport_hs())
                uart_debug_init();
-               /* Clock enable for the debug channel */
-               if (!IS_ERR_OR_NULL(debug_uart_clk)) {
-                       pr_info("The debug console clock name is %s\n",
-                                               debug_uart_clk->name);
-                       c = tegra_get_clock_by_name("pll_p");
-                       if (IS_ERR_OR_NULL(c))
-                               pr_err("Not getting the parent clock pll_p\n");
-                       else
-                               clk_set_parent(debug_uart_clk, c);
-
-                       clk_enable(debug_uart_clk);
-                       clk_set_rate(debug_uart_clk, clk_get_rate(c));
-               } else {
-                       pr_err("Not getting the clock %s for debug console\n",
-                                       debug_uart_clk->name);
-               }
-       }
 
 #ifdef CONFIG_TEGRA_IRDA
        if (((board_info.board_id == BOARD_E1186) ||
diff --git a/arch/arm/mach-tegra/board-common.c b/arch/arm/mach-tegra/board-common.c
new file mode 100644 (file)
index 0000000..54c4f61
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * board-common.c: Implement function which is common across
+ * different boards.
+ *
+ * Copyright (c) 2011-2012, NVIDIA CORPORATION.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include <linux/clk.h>
+#include <linux/serial_8250.h>
+
+#include <mach/clk.h>
+
+#include "board.h"
+#include "board-common.h"
+#include "devices.h"
+#include "clock.h"
+
+extern unsigned long  debug_uart_port_base;
+extern struct clk *debug_uart_clk;
+
+struct platform_device *uart_console_debug_device = NULL;
+
+int uart_console_debug_init(int default_debug_port)
+{
+       int debug_port_id;
+
+       debug_port_id = get_tegra_uart_debug_port_id();
+       if (debug_port_id < 0)
+               debug_port_id = default_debug_port;
+
+       if (debug_port_id < 0) {
+               pr_warn("No debug console channel\n");
+               return -EINVAL;
+       }
+
+       switch (debug_port_id) {
+       case 0:
+               /* UARTA is the debug port. */
+               pr_info("Selecting UARTA as the debug console\n");
+               debug_uart_clk = clk_get_sys("serial8250.0", "uarta");
+               debug_uart_port_base = ((struct plat_serial8250_port *)(
+                       debug_uarta_device.dev.platform_data))->mapbase;
+               uart_console_debug_device = &debug_uarta_device;
+               break;
+
+       case 1:
+               /* UARTB is the debug port. */
+               pr_info("Selecting UARTB as the debug console\n");
+               debug_uart_clk =  clk_get_sys("serial8250.0", "uartb");
+               debug_uart_port_base = ((struct plat_serial8250_port *)(
+                       debug_uartb_device.dev.platform_data))->mapbase;
+               uart_console_debug_device = &debug_uartb_device;
+               break;
+
+       case 2:
+               /* UARTC is the debug port. */
+               pr_info("Selecting UARTC as the debug console\n");
+               debug_uart_clk =  clk_get_sys("serial8250.0", "uartc");
+               debug_uart_port_base = ((struct plat_serial8250_port *)(
+                       debug_uartc_device.dev.platform_data))->mapbase;
+               uart_console_debug_device = &debug_uartc_device;
+               break;
+
+       case 3:
+               /* UARTD is the debug port. */
+               pr_info("Selecting UARTD as the debug console\n");
+               debug_uart_clk =  clk_get_sys("serial8250.0", "uartd");
+               debug_uart_port_base = ((struct plat_serial8250_port *)(
+                       debug_uartd_device.dev.platform_data))->mapbase;
+               uart_console_debug_device = &debug_uartd_device;
+               break;
+
+#if !defined(CONFIG_ARCH_TEGRA_2x_SOC)
+       case 4:
+               /* UARTE is the debug port. */
+               pr_info("Selecting UARTE as the debug console\n");
+               debug_uart_clk =  clk_get_sys("serial8250.0", "uarte");
+               debug_uart_port_base = ((struct plat_serial8250_port *)(
+                       debug_uarte_device.dev.platform_data))->mapbase;
+               uart_console_debug_device = &debug_uarte_device;
+               break;
+#endif
+
+       default:
+               pr_info("The debug console id %d is invalid, Assuming UARTA", debug_port_id);
+               debug_uart_clk = clk_get_sys("serial8250.0", "uarta");
+               debug_uart_port_base = ((struct plat_serial8250_port *)(
+                       debug_uarta_device.dev.platform_data))->mapbase;
+               uart_console_debug_device = &debug_uarta_device;
+               break;
+       }
+
+       if (!IS_ERR_OR_NULL(debug_uart_clk)) {
+               struct clk *c;
+               pr_info("The debug console clock name is %s\n",
+                                               debug_uart_clk->name);
+               c = tegra_get_clock_by_name("pll_p");
+               if (IS_ERR_OR_NULL(c))
+                       pr_err("Not getting the parent clock pll_p\n");
+               else
+                       clk_set_parent(debug_uart_clk, c);
+
+               clk_enable(debug_uart_clk);
+               clk_set_rate(debug_uart_clk, clk_get_rate(c));
+       } else {
+               pr_err("Not getting the clock for debug consolei %d\n",
+                       debug_port_id);
+       }
+       return debug_port_id;
+}
diff --git a/arch/arm/mach-tegra/board-common.h b/arch/arm/mach-tegra/board-common.h
new file mode 100644 (file)
index 0000000..fdacefd
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * board-common.h: Common function API declaration for all board files.
+ *
+ * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __MACH_TEGRA_BOARD_COMMON_H
+#define __MACH_TEGRA_BOARD_COMMON_H
+
+extern struct platform_device *uart_console_debug_device;
+int  uart_console_debug_init(int defaul_debug_port);
+
+#endif
index 418929e..bae84aa 100644 (file)
@@ -69,6 +69,7 @@
 #include <asm/mach/arch.h>
 
 #include "board.h"
+#include "board-common.h"
 #include "clock.h"
 #include "board-enterprise.h"
 #include "baseband-xmm-power.h"
@@ -449,34 +450,15 @@ static struct tegra_uart_platform_data enterprise_loopback_uart_pdata;
 
 static void __init uart_debug_init(void)
 {
-       unsigned long rate;
-       struct clk *c;
+       int debug_port_id;
 
        /* UARTD is the debug port. */
        pr_info("Selecting UARTD as the debug console\n");
-       enterprise_uart_devices[3] = &debug_uartd_device;
-       debug_uart_port_base = ((struct plat_serial8250_port *)(
-                       debug_uartd_device.dev.platform_data))->mapbase;
-       debug_uart_clk = clk_get_sys("serial8250.0", "uartd");
-
-       /* Clock enable for the debug channel */
-       if (!IS_ERR_OR_NULL(debug_uart_clk)) {
-               rate = ((struct plat_serial8250_port *)(
-                       debug_uartd_device.dev.platform_data))->uartclk;
-               pr_info("The debug console clock name is %s\n",
-                                               debug_uart_clk->name);
-               c = tegra_get_clock_by_name("pll_p");
-               if (IS_ERR_OR_NULL(c))
-                       pr_err("Not getting the parent clock pll_p\n");
-               else
-                       clk_set_parent(debug_uart_clk, c);
-
-               clk_enable(debug_uart_clk);
-               clk_set_rate(debug_uart_clk, rate);
-       } else {
-               pr_err("Not getting the clock %s for debug console\n",
-                               debug_uart_clk->name);
-       }
+       debug_port_id = uart_console_debug_init(3);
+       if (debug_port_id < 0)
+               return;
+
+       enterprise_uart_devices[debug_port_id] = uart_console_debug_device;
 }
 
 static void __init enterprise_uart_init(void)
index bdba7fc..e3158f7 100644 (file)
@@ -66,6 +66,7 @@
 #include <mach/tegra_fiq_debugger.h>
 
 #include "board.h"
+#include "board-common.h"
 #include "clock.h"
 #include "board-kai.h"
 #include "board-touch-raydium.h"
@@ -381,65 +382,12 @@ static void __init uart_debug_init(void)
 {
        int debug_port_id;
 
-       debug_port_id = get_tegra_uart_debug_port_id();
+       debug_port_id = uart_console_debug_init(3);
        if (debug_port_id < 0)
-               debug_port_id = 3;
+               return;
+       kai_uart_devices[debug_port_id] = uart_console_debug_device;
 
-       switch (debug_port_id) {
-       case 0:
-               /* UARTA is the debug port. */
-               pr_info("Selecting UARTA as the debug console\n");
-               kai_uart_devices[0] = &debug_uarta_device;
-               debug_uart_clk = clk_get_sys("serial8250.0", "uarta");
-               debug_uart_port_base = ((struct plat_serial8250_port *)(
-                       debug_uarta_device.dev.platform_data))->mapbase;
-               break;
-
-       case 1:
-               /* UARTB is the debug port. */
-               pr_info("Selecting UARTB as the debug console\n");
-               kai_uart_devices[1] = &debug_uartb_device;
-               debug_uart_clk = clk_get_sys("serial8250.0", "uartb");
-               debug_uart_port_base = ((struct plat_serial8250_port *)(
-                       debug_uartb_device.dev.platform_data))->mapbase;
-               break;
-
-       case 2:
-               /* UARTC is the debug port. */
-               pr_info("Selecting UARTC as the debug console\n");
-               kai_uart_devices[2] = &debug_uartc_device;
-               debug_uart_clk = clk_get_sys("serial8250.0", "uartc");
-               debug_uart_port_base = ((struct plat_serial8250_port *)(
-                       debug_uartc_device.dev.platform_data))->mapbase;
-               break;
-
-       case 3:
-               /* UARTD is the debug port. */
-               pr_info("Selecting UARTD as the debug console\n");
-               kai_uart_devices[3] = &debug_uartd_device;
-               debug_uart_clk = clk_get_sys("serial8250.0", "uartd");
-               debug_uart_port_base = ((struct plat_serial8250_port *)(
-                       debug_uartd_device.dev.platform_data))->mapbase;
-               break;
-
-       case 4:
-               /* UARTE is the debug port. */
-               pr_info("Selecting UARTE as the debug console\n");
-               kai_uart_devices[4] = &debug_uarte_device;
-               debug_uart_clk = clk_get_sys("serial8250.0", "uarte");
-               debug_uart_port_base = ((struct plat_serial8250_port *)(
-                       debug_uarte_device.dev.platform_data))->mapbase;
-               break;
-
-       default:
-               pr_info("The debug console id %d is invalid, Assuming UARTA",
-                       debug_port_id);
-               kai_uart_devices[0] = &debug_uarta_device;
-               debug_uart_clk = clk_get_sys("serial8250.0", "uarta");
-               debug_uart_port_base = ((struct plat_serial8250_port *)(
-                       debug_uarta_device.dev.platform_data))->mapbase;
-               break;
-       }
+       return;
 }
 
 static void __init kai_uart_init(void)
@@ -471,25 +419,8 @@ static void __init kai_uart_init(void)
        tegra_uarte_device.dev.platform_data = &kai_loopback_uart_pdata;
 
        /* Register low speed only if it is selected */
-       if (!is_tegra_debug_uartport_hs()) {
+       if (!is_tegra_debug_uartport_hs())
                uart_debug_init();
-               /* Clock enable for the debug channel */
-               if (!IS_ERR_OR_NULL(debug_uart_clk)) {
-                       pr_info("The debug console clock name is %s\n",
-                                               debug_uart_clk->name);
-                       c = tegra_get_clock_by_name("pll_p");
-                       if (IS_ERR_OR_NULL(c))
-                               pr_err("Not getting the parent clock pll_p\n");
-                       else
-                               clk_set_parent(debug_uart_clk, c);
-
-                       clk_enable(debug_uart_clk);
-                       clk_set_rate(debug_uart_clk, clk_get_rate(c));
-               } else {
-                       pr_err("Not getting the clock %s for debug console\n",
-                                       debug_uart_clk->name);
-               }
-       }
 
        platform_add_devices(kai_uart_devices,
                                ARRAY_SIZE(kai_uart_devices));