Commit 49a23e4a414ef9cfb92b1de193d7fa700fb55bf1

Authored by Michal Simek
Committed by Wolfgang Denk
1 parent 4b0a03d375

serial: uartlite: Support for SERIAL_MULTI

Add support for SERIAL MULTI for uartlite.

Signed-off-by: Michal Simek <monstr@monstr.eu>

Showing 3 changed files with 142 additions and 19 deletions Side-by-side Diff

... ... @@ -108,6 +108,20 @@
108 108 #if defined(CONFIG_SYS_BFIN_UART)
109 109 serial_register_bfin_uart();
110 110 #endif
  111 +#if defined(CONFIG_XILINX_UARTLITE)
  112 +# ifdef XILINX_UARTLITE_BASEADDR
  113 + serial_register(&uartlite_serial0_device);
  114 +# endif /* XILINX_UARTLITE_BASEADDR */
  115 +# ifdef XILINX_UARTLITE_BASEADDR1
  116 + serial_register(&uartlite_serial1_device);
  117 +# endif /* XILINX_UARTLITE_BASEADDR1 */
  118 +# ifdef XILINX_UARTLITE_BASEADDR2
  119 + serial_register(&uartlite_serial2_device);
  120 +# endif /* XILINX_UARTLITE_BASEADDR2 */
  121 +# ifdef XILINX_UARTLITE_BASEADDR3
  122 + serial_register(&uartlite_serial3_device);
  123 +# endif /* XILINX_UARTLITE_BASEADDR3 */
  124 +#endif /* CONFIG_XILINX_UARTLITE */
111 125 serial_assign (default_serial_console ()->name);
112 126 }
113 127  
drivers/serial/serial_xuartlite.c
1 1 /*
2   - * (C) Copyright 2008 Michal Simek <monstr@monstr.eu>
  2 + * (C) Copyright 2008-2011 Michal Simek <monstr@monstr.eu>
3 3 * Clean driver and add xilinx constant from header file
4 4 *
5 5 * (C) Copyright 2004 Atmark Techno, Inc.
6 6  
7 7  
8 8  
9 9  
... ... @@ -25,20 +25,71 @@
25 25 */
26 26  
27 27 #include <config.h>
  28 +#include <common.h>
28 29 #include <asm/io.h>
  30 +#include <linux/compiler.h>
  31 +#include <serial.h>
29 32  
30   -#define RX_FIFO_OFFSET 0 /* receive FIFO, read only */
31   -#define TX_FIFO_OFFSET 4 /* transmit FIFO, write only */
32   -#define STATUS_REG_OFFSET 8 /* status register, read only */
33   -
34 33 #define SR_TX_FIFO_FULL 0x08 /* transmit FIFO full */
35 34 #define SR_RX_FIFO_VALID_DATA 0x01 /* data in receive FIFO */
36 35 #define SR_RX_FIFO_FULL 0x02 /* receive FIFO full */
37 36  
38   -#define UARTLITE_STATUS (CONFIG_SERIAL_BASE + STATUS_REG_OFFSET)
39   -#define UARTLITE_TX_FIFO (CONFIG_SERIAL_BASE + TX_FIFO_OFFSET)
40   -#define UARTLITE_RX_FIFO (CONFIG_SERIAL_BASE + RX_FIFO_OFFSET)
  37 +struct uartlite {
  38 + unsigned int rx_fifo;
  39 + unsigned int tx_fifo;
  40 + unsigned int status;
  41 +};
41 42  
  43 +static const struct uartlite *userial_ports[4] = {
  44 +#ifdef XILINX_UARTLITE_BASEADDR
  45 + [0] = (struct uartlite *)XILINX_UARTLITE_BASEADDR,
  46 +#endif
  47 +#ifdef XILINX_UARTLITE_BASEADDR1
  48 + [1] = (struct uartlite *)XILINX_UARTLITE_BASEADDR1,
  49 +#endif
  50 +#ifdef XILINX_UARTLITE_BASEADDR2
  51 + [2] = (struct uartlite *)XILINX_UARTLITE_BASEADDR2,
  52 +#endif
  53 +#ifdef XILINX_UARTLITE_BASEADDR3
  54 + [3] = (struct uartlite *)XILINX_UARTLITE_BASEADDR3
  55 +#endif
  56 +};
  57 +
  58 +void uartlite_serial_putc(const char c, const int port)
  59 +{
  60 + struct uartlite *regs = userial_ports[port];
  61 +
  62 + if (c == '\n')
  63 + uartlite_serial_putc('\r', port);
  64 +
  65 + while (in_be32(&regs->status) & SR_TX_FIFO_FULL)
  66 + ;
  67 + out_be32(&regs->tx_fifo, c & 0xff);
  68 +}
  69 +
  70 +void uartlite_serial_puts(const char *s, const int port)
  71 +{
  72 + while (*s)
  73 + uartlite_serial_putc(*s++, port);
  74 +}
  75 +
  76 +int uartlite_serial_getc(const int port)
  77 +{
  78 + struct uartlite *regs = userial_ports[port];
  79 +
  80 + while (!(in_be32(&regs->status) & SR_RX_FIFO_VALID_DATA))
  81 + ;
  82 + return in_be32(&regs->rx_fifo) & 0xff;
  83 +}
  84 +
  85 +int uartlite_serial_tstc(const int port)
  86 +{
  87 + struct uartlite *regs = userial_ports[port];
  88 +
  89 + return in_be32(&regs->status) & SR_RX_FIFO_VALID_DATA;
  90 +}
  91 +
  92 +#if !defined(CONFIG_SERIAL_MULTI)
42 93 int serial_init(void)
43 94 {
44 95 /* FIXME: Nothing for now. We should initialize fifo, etc */
45 96  
46 97  
47 98  
48 99  
49 100  
... ... @@ -52,27 +103,78 @@
52 103  
53 104 void serial_putc(const char c)
54 105 {
55   - if (c == '\n')
56   - serial_putc('\r');
57   - while (in_be32((u32 *) UARTLITE_STATUS) & SR_TX_FIFO_FULL);
58   - out_be32((u32 *) UARTLITE_TX_FIFO, (unsigned char) (c & 0xff));
  106 + uartlite_serial_putc(c, 0);
59 107 }
60 108  
61   -void serial_puts(const char * s)
  109 +void serial_puts(const char *s)
62 110 {
63   - while (*s) {
64   - serial_putc(*s++);
65   - }
  111 + uartlite_serial_puts(s, 0);
66 112 }
67 113  
68 114 int serial_getc(void)
69 115 {
70   - while (!(in_be32((u32 *) UARTLITE_STATUS) & SR_RX_FIFO_VALID_DATA));
71   - return in_be32((u32 *) UARTLITE_RX_FIFO) & 0xff;
  116 + return uartlite_serial_getc(0);
72 117 }
73 118  
74 119 int serial_tstc(void)
75 120 {
76   - return (in_be32((u32 *) UARTLITE_STATUS) & SR_RX_FIFO_VALID_DATA);
  121 + return uartlite_serial_tstc(0);
77 122 }
  123 +#endif
  124 +
  125 +#if defined(CONFIG_SERIAL_MULTI)
  126 +/* Multi serial device functions */
  127 +#define DECLARE_ESERIAL_FUNCTIONS(port) \
  128 + int userial##port##_init(void) \
  129 + { return(0); } \
  130 + void userial##port##_setbrg(void) {} \
  131 + int userial##port##_getc(void) \
  132 + { return uartlite_serial_getc(port); } \
  133 + int userial##port##_tstc(void) \
  134 + { return uartlite_serial_tstc(port); } \
  135 + void userial##port##_putc(const char c) \
  136 + { uartlite_serial_putc(c, port); } \
  137 + void userial##port##_puts(const char *s) \
  138 + { uartlite_serial_puts(s, port); }
  139 +
  140 +/* Serial device descriptor */
  141 +#define INIT_ESERIAL_STRUCTURE(port, name) {\
  142 + name,\
  143 + userial##port##_init,\
  144 + NULL,\
  145 + userial##port##_setbrg,\
  146 + userial##port##_getc,\
  147 + userial##port##_tstc,\
  148 + userial##port##_putc,\
  149 + userial##port##_puts, }
  150 +
  151 +DECLARE_ESERIAL_FUNCTIONS(0);
  152 +struct serial_device uartlite_serial0_device =
  153 + INIT_ESERIAL_STRUCTURE(0, "ttyUL0");
  154 +DECLARE_ESERIAL_FUNCTIONS(1);
  155 +struct serial_device uartlite_serial1_device =
  156 + INIT_ESERIAL_STRUCTURE(1, "ttyUL1");
  157 +DECLARE_ESERIAL_FUNCTIONS(2);
  158 +struct serial_device uartlite_serial2_device =
  159 + INIT_ESERIAL_STRUCTURE(2, "ttyUL2");
  160 +DECLARE_ESERIAL_FUNCTIONS(3);
  161 +struct serial_device uartlite_serial3_device =
  162 + INIT_ESERIAL_STRUCTURE(3, "ttyUL3");
  163 +
  164 +__weak struct serial_device *default_serial_console(void)
  165 +{
  166 +# ifdef XILINX_UARTLITE_BASEADDR
  167 + return &uartlite_serial0_device;
  168 +# endif /* XILINX_UARTLITE_BASEADDR */
  169 +# ifdef XILINX_UARTLITE_BASEADDR1
  170 + return &uartlite_serial1_device;
  171 +# endif /* XILINX_UARTLITE_BASEADDR1 */
  172 +# ifdef XILINX_UARTLITE_BASEADDR2
  173 + return &uartlite_serial2_device;
  174 +# endif /* XILINX_UARTLITE_BASEADDR2 */
  175 +# ifdef XILINX_UARTLITE_BASEADDR3
  176 + return &uartlite_serial3_device;
  177 +# endif /* XILINX_UARTLITE_BASEADDR3 */
  178 +}
  179 +#endif /* CONFIG_SERIAL_MULTI */
... ... @@ -50,6 +50,13 @@
50 50 extern struct serial_device serial6_device;
51 51 #endif
52 52  
  53 +#if defined(CONFIG_XILINX_UARTLITE)
  54 +extern struct serial_device uartlite_serial0_device;
  55 +extern struct serial_device uartlite_serial1_device;
  56 +extern struct serial_device uartlite_serial2_device;
  57 +extern struct serial_device uartlite_serial3_device;
  58 +#endif
  59 +
53 60 #if defined(CONFIG_S3C2410)
54 61 extern struct serial_device s3c24xx_serial0_device;
55 62 extern struct serial_device s3c24xx_serial1_device;