1 From 5b3f9de4171368d9a99fa4c8b8b1bcc8505fb3c6 Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Mon, 11 Jan 2010 04:29:44 +0100
4 Subject: [PATCH] /opt/Projects/openwrt/target/linux/xburst/patches-2.6.31/103-serial.patch
7 drivers/serial/8250.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++-
8 1 files changed, 103 insertions(+), 1 deletions(-)
10 --- a/drivers/serial/8250.c
11 +++ b/drivers/serial/8250.c
12 @@ -196,7 +196,7 @@ static const struct serial8250_config ua
18 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
19 .flags = UART_CAP_FIFO,
21 @@ -403,6 +403,10 @@ static unsigned int mem_serial_in(struct
22 static void mem_serial_out(struct uart_port *p, int offset, int value)
24 offset = map_8250_out_reg(p, offset) << p->regshift;
25 +#if defined(CONFIG_JZSOC)
26 + if (offset == (UART_FCR << p->regshift))
27 + value |= 0x10; /* set FCR.UUE */
29 writeb(value, p->membase + offset);
32 @@ -2213,6 +2217,83 @@ static void serial8250_shutdown(struct u
33 serial_unlink_irq_chain(up);
36 +#if defined(CONFIG_JZSOC) && !defined(CONFIG_SOC_JZ4730)
37 +static unsigned short quot1[3] = {0}; /* quot[0]:baud_div, quot[1]:umr, quot[2]:uacr */
38 +static unsigned short * serial8250_get_divisor(struct uart_port *port, unsigned int baud)
42 + unsigned short div, umr, uacr;
43 + unsigned short umr_best, div_best, uacr_best;
44 + long long t0, t1, t2, t3;
47 + umr_best = div_best = uacr_best = 0;
50 + if ((port->uartclk % (16 * baud)) == 0) {
51 + quot1[0] = port->uartclk / (16 * baud);
58 + umr = port->uartclk / (baud * div);
66 + for (i = 0; i < 12; i++) {
70 + for (j = 0; j <= i; j++) {
74 + /* the precision could be 1/2^(36) due to the value of t0 */
75 + t0 = 0x1000000000LL;
77 + t2 = (sum * div) * t0;
80 + do_div(t2, port->uartclk);
81 + do_div(t3, (2 * port->uartclk));
91 + for (i = 0; i < 12; i++) {
97 + /* the best value of umr should be near 16, and the value of uacr should better be smaller */
98 + if (abs(umr - 16) < abs(umr_best - 16) || (abs(umr - 16) == abs(umr_best - 16) && uacr_best > uacr)) {
106 + quot1[0] = div_best;
107 + quot1[1] = umr_best;
108 + quot1[2] = uacr_best;
113 static unsigned int serial8250_get_divisor(struct uart_port *port, unsigned int baud)
116 @@ -2232,6 +2313,7 @@ static unsigned int serial8250_get_divis
123 serial8250_set_termios(struct uart_port *port, struct ktermios *termios,
124 @@ -2241,6 +2323,9 @@ serial8250_set_termios(struct uart_port
125 unsigned char cval, fcr = 0;
127 unsigned int baud, quot;
128 +#if defined(CONFIG_JZSOC) && !defined(CONFIG_SOC_JZ4730)
129 + unsigned short *quot1;
132 switch (termios->c_cflag & CSIZE) {
134 @@ -2275,7 +2360,12 @@ serial8250_set_termios(struct uart_port
135 baud = uart_get_baud_rate(port, termios, old,
136 port->uartclk / 16 / 0xffff,
138 +#if defined(CONFIG_JZSOC) && !defined(CONFIG_SOC_JZ4730)
139 + quot1 = serial8250_get_divisor(port, baud);
140 + quot = quot1[0]; /* not usefull, just let gcc happy */
142 quot = serial8250_get_divisor(port, baud);
146 * Oxford Semi 952 rev B workaround
147 @@ -2353,6 +2443,10 @@ serial8250_set_termios(struct uart_port
148 if (up->capabilities & UART_CAP_UUE)
149 up->ier |= UART_IER_UUE | UART_IER_RTOIE;
152 + up->ier |= UART_IER_RTOIE; /* Set this flag, or very slow */
155 serial_out(up, UART_IER, up->ier);
157 if (up->capabilities & UART_CAP_EFR) {
158 @@ -2387,7 +2481,15 @@ serial8250_set_termios(struct uart_port
159 serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */
162 +#if defined(CONFIG_JZSOC) && !defined(CONFIG_SOC_JZ4730)
164 +#define UART_UACR 10
165 + serial_dl_write(up, quot1[0]);
166 + serial_outp(up, UART_UMR, quot1[1]);
167 + serial_outp(up, UART_UACR, quot1[2]);
169 serial_dl_write(up, quot);
173 * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR