tegra: i2c: Add function to find DVC bus
[oweals/u-boot.git] / drivers / serial / serial.c
index 182ca2d149ead9aba81003418e0e6c418dec2890..0d6ad6283ace04ff723afafc1bb1908cc9d4d310 100644 (file)
  */
 
 #include <common.h>
-
-#ifdef CFG_NS16550_SERIAL
+#include <linux/compiler.h>
 
 #include <ns16550.h>
-#ifdef CFG_NS87308
+#ifdef CONFIG_NS87308
 #include <ns87308.h>
 #endif
 
@@ -48,13 +47,13 @@ DECLARE_GLOBAL_DATA_PTR;
 #error "Invalid console index value."
 #endif
 
-#if CONFIG_CONS_INDEX == 1 && !defined(CFG_NS16550_COM1)
+#if CONFIG_CONS_INDEX == 1 && !defined(CONFIG_SYS_NS16550_COM1)
 #error "Console port 1 defined but not configured."
-#elif CONFIG_CONS_INDEX == 2 && !defined(CFG_NS16550_COM2)
+#elif CONFIG_CONS_INDEX == 2 && !defined(CONFIG_SYS_NS16550_COM2)
 #error "Console port 2 defined but not configured."
-#elif CONFIG_CONS_INDEX == 3 && !defined(CFG_NS16550_COM3)
+#elif CONFIG_CONS_INDEX == 3 && !defined(CONFIG_SYS_NS16550_COM3)
 #error "Console port 3 defined but not configured."
-#elif CONFIG_CONS_INDEX == 4 && !defined(CFG_NS16550_COM4)
+#elif CONFIG_CONS_INDEX == 4 && !defined(CONFIG_SYS_NS16550_COM4)
 #error "Console port 4 defined but not configured."
 #endif
 
@@ -62,23 +61,23 @@ DECLARE_GLOBAL_DATA_PTR;
  *      the array is 0 based.
  */
 static NS16550_t serial_ports[4] = {
-#ifdef CFG_NS16550_COM1
-       (NS16550_t)CFG_NS16550_COM1,
+#ifdef CONFIG_SYS_NS16550_COM1
+       (NS16550_t)CONFIG_SYS_NS16550_COM1,
 #else
        NULL,
 #endif
-#ifdef CFG_NS16550_COM2
-       (NS16550_t)CFG_NS16550_COM2,
+#ifdef CONFIG_SYS_NS16550_COM2
+       (NS16550_t)CONFIG_SYS_NS16550_COM2,
 #else
        NULL,
 #endif
-#ifdef CFG_NS16550_COM3
-       (NS16550_t)CFG_NS16550_COM3,
+#ifdef CONFIG_SYS_NS16550_COM3
+       (NS16550_t)CONFIG_SYS_NS16550_COM3,
 #else
        NULL,
 #endif
-#ifdef CFG_NS16550_COM4
-       (NS16550_t)CFG_NS16550_COM4
+#ifdef CONFIG_SYS_NS16550_COM4
+       (NS16550_t)CONFIG_SYS_NS16550_COM4
 #else
        NULL
 #endif
@@ -110,10 +109,10 @@ static NS16550_t serial_ports[4] = {
        serial_puts_dev(port, s);}
 
 /* Serial device descriptor */
-#define INIT_ESERIAL_STRUCTURE(port,name,bus) {\
+#define INIT_ESERIAL_STRUCTURE(port, name) {\
        name,\
-       bus,\
        eserial##port##_init,\
+       NULL,\
        eserial##port##_setbrg,\
        eserial##port##_getc,\
        eserial##port##_tstc,\
@@ -126,7 +125,7 @@ static int calc_divisor (NS16550_t port)
 {
 #ifdef CONFIG_OMAP1510
        /* If can't cleanly clock 115200 set div to 1 */
-       if ((CFG_NS16550_CLK == 12000000) && (gd->baudrate == 115200)) {
+       if ((CONFIG_SYS_NS16550_CLK == 12000000) && (gd->baudrate == 115200)) {
                port->osc_12m_sel = OSC_12M_SEL;        /* enable 6.5 * divisor */
                return (1);                             /* return 1 for base divisor */
        }
@@ -134,7 +133,7 @@ static int calc_divisor (NS16550_t port)
 #endif
 #ifdef CONFIG_OMAP1610
        /* If can't cleanly clock 115200 set div to 1 */
-       if ((CFG_NS16550_CLK == 48000000) && (gd->baudrate == 115200)) {
+       if ((CONFIG_SYS_NS16550_CLK == 48000000) && (gd->baudrate == 115200)) {
                return (26);            /* return 26 for base divisor */
        }
 #endif
@@ -146,11 +145,12 @@ static int calc_divisor (NS16550_t port)
 #endif
 
        /* Compute divisor value. Normally, we should simply return:
-        *   CFG_NS16550_CLK) / MODE_X_DIV / gd->baudrate
-        * but we need to round that value by adding 0.5 or 8/16.
+        *   CONFIG_SYS_NS16550_CLK) / MODE_X_DIV / gd->baudrate
+        * but we need to round that value by adding 0.5.
         * Rounding is especially important at high baud rates.
         */
-       return (((16 * CFG_NS16550_CLK) / MODE_X_DIV / gd->baudrate) + 8) / 16;
+       return (CONFIG_SYS_NS16550_CLK + (gd->baudrate * (MODE_X_DIV / 2))) /
+               (MODE_X_DIV * gd->baudrate);
 }
 
 #if !defined(CONFIG_SERIAL_MULTI)
@@ -158,23 +158,23 @@ int serial_init (void)
 {
        int clock_divisor;
 
-#ifdef CFG_NS87308
+#ifdef CONFIG_NS87308
        initialise_ns87308();
 #endif
 
-#ifdef CFG_NS16550_COM1
+#ifdef CONFIG_SYS_NS16550_COM1
        clock_divisor = calc_divisor(serial_ports[0]);
        NS16550_init(serial_ports[0], clock_divisor);
 #endif
-#ifdef CFG_NS16550_COM2
+#ifdef CONFIG_SYS_NS16550_COM2
        clock_divisor = calc_divisor(serial_ports[1]);
        NS16550_init(serial_ports[1], clock_divisor);
 #endif
-#ifdef CFG_NS16550_COM3
+#ifdef CONFIG_SYS_NS16550_COM3
        clock_divisor = calc_divisor(serial_ports[2]);
        NS16550_init(serial_ports[2], clock_divisor);
 #endif
-#ifdef CFG_NS16550_COM4
+#ifdef CONFIG_SYS_NS16550_COM4
        clock_divisor = calc_divisor(serial_ports[3]);
        NS16550_init(serial_ports[3], clock_divisor);
 #endif
@@ -316,16 +316,30 @@ serial_setbrg(void)
 
 DECLARE_ESERIAL_FUNCTIONS(1);
 struct serial_device eserial1_device =
-       INIT_ESERIAL_STRUCTURE(1,"eserial0","EUART1");
+       INIT_ESERIAL_STRUCTURE(1, "eserial0");
 DECLARE_ESERIAL_FUNCTIONS(2);
 struct serial_device eserial2_device =
-       INIT_ESERIAL_STRUCTURE(2,"eserial1","EUART2");
+       INIT_ESERIAL_STRUCTURE(2, "eserial1");
 DECLARE_ESERIAL_FUNCTIONS(3);
 struct serial_device eserial3_device =
-       INIT_ESERIAL_STRUCTURE(3,"eserial2","EUART3");
+       INIT_ESERIAL_STRUCTURE(3, "eserial2");
 DECLARE_ESERIAL_FUNCTIONS(4);
 struct serial_device eserial4_device =
-       INIT_ESERIAL_STRUCTURE(4,"eserial3","EUART4");
-#endif /* CONFIG_SERIAL_MULTI */
+       INIT_ESERIAL_STRUCTURE(4, "eserial3");
 
+__weak struct serial_device *default_serial_console(void)
+{
+#if CONFIG_CONS_INDEX == 1
+       return &eserial1_device;
+#elif CONFIG_CONS_INDEX == 2
+       return &eserial2_device;
+#elif CONFIG_CONS_INDEX == 3
+       return &eserial3_device;
+#elif CONFIG_CONS_INDEX == 4
+       return &eserial4_device;
+#else
+#error "Bad CONFIG_CONS_INDEX."
 #endif
+}
+
+#endif /* CONFIG_SERIAL_MULTI */