serial: sandbox: Implement CONFIG_SERIAL_MULTI into sandbox serial driver
[oweals/u-boot.git] / drivers / serial / ns9750_serial.c
index 02c0d3952099c58cf4a8034adf55ae4f51ea8877..829f6d580c34777acd4990a2a0d21fe3ef7e592a 100644 (file)
@@ -28,8 +28,6 @@
 
 #include <common.h>
 
-#ifdef CFG_NS9750_UART
-
 #include "ns9750_bbus.h"       /* for GPIOs */
 #include "ns9750_ser.h"                /* for serial configuration */
 
@@ -54,7 +52,7 @@ static unsigned int unCharCache; /* unCharCache is only valid if
  * @Descr: configures GPIOs and UART. Requires BBUS Master Reset turned off
  ***********************************************************************/
 
-int serial_init( void )
+static int ns9750_serial_init(void)
 {
        unsigned int aunGPIOTxD[] = { 0, 8, 40, 44 };
        unsigned int aunGPIORxD[] = { 1, 9, 41, 45 };
@@ -87,7 +85,7 @@ int serial_init( void )
  * @Descr: writes one character to the FIFO. Blocks until FIFO is not full
  ***********************************************************************/
 
-void serial_putc( const char c )
+static void ns9750_serial_putc(const char c)
 {
        if (c == '\n')
                serial_putc( '\r' );
@@ -107,7 +105,7 @@ void serial_putc( const char c )
  * @Descr: writes non-zero string to the FIFO.
  ***********************************************************************/
 
-void serial_puts( const char *s )
+static void ns9750_serial_puts(const char *s)
 {
        while (*s) {
                serial_putc( *s++ );
@@ -120,7 +118,7 @@ void serial_puts( const char *s )
  * @Descr: performs only 8bit accesses to the FIFO. No error handling
  ***********************************************************************/
 
-int serial_getc( void )
+static int ns9750_serial_getc(void)
 {
        int i;
 
@@ -144,7 +142,7 @@ int serial_getc( void )
  *        unCharCache and the numbers of characters in cCharsAvailable
  ***********************************************************************/
 
-int serial_tstc( void )
+static int ns9750_serial_tstc(void)
 {
        unsigned int unRegCache;
 
@@ -173,7 +171,7 @@ int serial_tstc( void )
        return 0;
 }
 
-void serial_setbrg( void )
+static void ns9750_serial_setbrg(void)
 {
        *get_ser_reg_addr_channel( NS9750_SER_BITRATE, CONSOLE ) =
                calcBitrateRegister();
@@ -211,4 +209,55 @@ static unsigned int calcRxCharGapRegister( void )
        return NS9750_SER_RX_CHAR_TIMER_TRUN;
 }
 
-#endif /* CFG_NS9750_UART */
+#ifdef CONFIG_SERIAL_MULTI
+static struct serial_device ns9750_serial_drv = {
+       .name   = "ns9750_serial",
+       .start  = ns9750_serial_init,
+       .stop   = NULL,
+       .setbrg = ns9750_serial_setbrg,
+       .putc   = ns9750_serial_putc,
+       .puts   = ns9750_serial_puts,
+       .getc   = ns9750_serial_getc,
+       .tstc   = ns9750_serial_tstc,
+};
+
+void ns9750_serial_initialize(void)
+{
+       serial_register(&ns9750_serial_drv);
+}
+
+__weak struct serial_device *default_serial_console(void)
+{
+       return &ns9750_serial_drv;
+}
+#else
+int serial_init(void)
+{
+       return ns9750_serial_init();
+}
+
+void serial_setbrg(void)
+{
+       ns9750_serial_setbrg();
+}
+
+void serial_putc(const char c)
+{
+       ns9750_serial_putc(c);
+}
+
+void serial_puts(const char *s)
+{
+       ns9750_serial_puts(s);
+}
+
+int serial_getc(void)
+{
+       return ns9750_serial_getc();
+}
+
+int serial_tstc(void)
+{
+       return ns9750_serial_tstc();
+}
+#endif