]> git.sur5r.net Git - u-boot/blobdiff - arch/powerpc/cpu/mpc512x/serial.c
GCC4.6: Squash warnings in denali_spd_ddr2.c
[u-boot] / arch / powerpc / cpu / mpc512x / serial.c
index f421968896bb58904dcedd3d0c899e57f5d036ca..7c53346ea03fe3dec884a11539f71e465d513f3a 100644 (file)
@@ -30,6 +30,7 @@
  */
 
 #include <common.h>
+#include <linux/compiler.h>
 #include <asm/io.h>
 #include <asm/processor.h>
 #include <serial.h>
@@ -139,7 +140,7 @@ void serial_setbrg_dev(unsigned int idx)
                if (br_env)
                        baudrate = simple_strtoul(br_env, NULL, 10);
 
-               debug("%s: idx %d, baudrate %d\n", __func__, idx, baudrate);
+               debug("%s: idx %d, baudrate %ld\n", __func__, idx, baudrate);
        }
 
        /* calculate divisor for setting PSC CTUR and CTLR registers */
@@ -318,9 +319,8 @@ int serial_getcts_dev(unsigned int idx)
                serial_puts_dev(port, s); \
        }
 
-#define INIT_PSC_SERIAL_STRUCTURE(port, name, bus) { \
+#define INIT_PSC_SERIAL_STRUCTURE(port, name) { \
        name, \
-       bus, \
        serial##port##_init, \
        serial##port##_uninit, \
        serial##port##_setbrg, \
@@ -333,27 +333,38 @@ int serial_getcts_dev(unsigned int idx)
 #if defined(CONFIG_SYS_PSC1)
 DECLARE_PSC_SERIAL_FUNCTIONS(1);
 struct serial_device serial1_device =
-INIT_PSC_SERIAL_STRUCTURE(1, "psc1", "UART1");
+INIT_PSC_SERIAL_STRUCTURE(1, "psc1");
 #endif
 
 #if defined(CONFIG_SYS_PSC3)
 DECLARE_PSC_SERIAL_FUNCTIONS(3);
 struct serial_device serial3_device =
-INIT_PSC_SERIAL_STRUCTURE(3, "psc3", "UART3");
+INIT_PSC_SERIAL_STRUCTURE(3, "psc3");
 #endif
 
 #if defined(CONFIG_SYS_PSC4)
 DECLARE_PSC_SERIAL_FUNCTIONS(4);
 struct serial_device serial4_device =
-INIT_PSC_SERIAL_STRUCTURE(4, "psc4", "UART4");
+INIT_PSC_SERIAL_STRUCTURE(4, "psc4");
 #endif
 
 #if defined(CONFIG_SYS_PSC6)
 DECLARE_PSC_SERIAL_FUNCTIONS(6);
 struct serial_device serial6_device =
-INIT_PSC_SERIAL_STRUCTURE(6, "psc6", "UART6");
+INIT_PSC_SERIAL_STRUCTURE(6, "psc6");
 #endif
 
+__weak struct serial_device *default_serial_console(void)
+{
+#if (CONFIG_PSC_CONSOLE == 3)
+       return &serial3_device;
+#elif (CONFIG_PSC_CONSOLE == 6)
+       return &serial6_device;
+#else
+#error "invalid CONFIG_PSC_CONSOLE"
+#endif
+}
+
 #else
 
 void serial_setbrg(void)
@@ -401,3 +412,90 @@ int serial_getcts(void)
        return serial_getcts_dev(CONFIG_PSC_CONSOLE);
 }
 #endif /* CONFIG_PSC_CONSOLE */
+
+#if defined(CONFIG_SERIAL_MULTI)
+#include <stdio_dev.h>
+/*
+ * Routines for communication with serial devices over PSC
+ */
+/* Bitfield for initialized PSCs */
+static unsigned int initialized;
+
+struct stdio_dev *open_port(int num, int baudrate)
+{
+       struct stdio_dev *port;
+       char env_var[16];
+       char env_val[10];
+       char name[7];
+
+       if (num < 0 || num > 11)
+               return NULL;
+
+       sprintf(name, "psc%d", num);
+       port = stdio_get_by_name(name);
+       if (!port)
+               return NULL;
+
+       if (!test_bit(num, &initialized)) {
+               sprintf(env_var, "psc%d_baudrate", num);
+               sprintf(env_val, "%d", baudrate);
+               setenv(env_var, env_val);
+
+               if (port->start())
+                       return NULL;
+
+               set_bit(num, &initialized);
+       }
+
+       return port;
+}
+
+int close_port(int num)
+{
+       struct stdio_dev *port;
+       int ret;
+       char name[7];
+
+       if (num < 0 || num > 11)
+               return -1;
+
+       sprintf(name, "psc%d", num);
+       port = stdio_get_by_name(name);
+       if (!port)
+               return -1;
+
+       ret = port->stop();
+       clear_bit(num, &initialized);
+
+       return ret;
+}
+
+int write_port(struct stdio_dev *port, char *buf)
+{
+       if (!port || !buf)
+               return -1;
+
+       port->puts(buf);
+
+       return 0;
+}
+
+int read_port(struct stdio_dev *port, char *buf, int size)
+{
+       int cnt = 0;
+
+       if (!port || !buf)
+               return -1;
+
+       if (!size)
+               return 0;
+
+       while (port->tstc()) {
+               buf[cnt++] = port->getc();
+               if (cnt > size)
+                       break;
+       }
+
+       return cnt;
+}
+#endif /* CONFIG_SERIAL_MULTI */