brcm47xx: update early printk patches
[openwrt.git] / target / linux / brcm47xx / patches-3.10 / 080-MIPS-Add-8250-16550-serial-early-printk-driver.patch
1 commit 0a76092a63809a0e72e3e9552acadf42869c0293
2 Author: Yoichi Yuasa <yuasa@linux-mips.org>
3 Date:   Mon Feb 8 20:59:39 2010 +0900
4
5     MIPS: Add 8250/16550 serial early printk driver
6     
7     Signed-off-by: Yoichi Yuasa <yuasa@linux-mips.org>
8     Cc: linux-mips <linux-mips@linux-mips.org>
9     Patchwork: https://patchwork.linux-mips.org/patch/947/
10     Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
11
12 --- a/arch/mips/Kconfig.debug
13 +++ b/arch/mips/Kconfig.debug
14 @@ -20,6 +20,14 @@ config EARLY_PRINTK
15           doesn't cooperate with an X server. You should normally say N here,
16           unless you want to debug such a crash.
17  
18 +config EARLY_PRINTK_8250
19 +       bool "8250/16550 and compatible serial early printk driver"
20 +       depends on EARLY_PRINTK
21 +       default n
22 +       help
23 +         If you say Y here, it will be possible to use a 8250/16550 serial
24 +         port as the boot console.
25 +
26  config CMDLINE_BOOL
27         bool "Built-in kernel command line"
28         default n
29 --- a/arch/mips/include/asm/setup.h
30 +++ b/arch/mips/include/asm/setup.h
31 @@ -5,6 +5,14 @@
32  
33  extern void setup_early_printk(void);
34  
35 +#ifdef CONFIG_EARLY_PRINTK_8250
36 +extern void setup_8250_early_printk_port(unsigned long base,
37 +       unsigned int reg_shift, unsigned int timeout);
38 +#else
39 +static inline void setup_8250_early_printk_port(unsigned long base,
40 +       unsigned int reg_shift, unsigned int timeout) {}
41 +#endif
42 +
43  extern void set_handler(unsigned long offset, void *addr, unsigned long len);
44  extern void set_uncached_handler(unsigned long offset, void *addr, unsigned long len);
45  
46 --- a/arch/mips/kernel/Makefile
47 +++ b/arch/mips/kernel/Makefile
48 @@ -84,6 +84,7 @@ obj-$(CONFIG_GPIO_TXX9)               += gpio_txx9.o
49  obj-$(CONFIG_KEXEC)            += machine_kexec.o relocate_kernel.o crash.o
50  obj-$(CONFIG_CRASH_DUMP)       += crash_dump.o
51  obj-$(CONFIG_EARLY_PRINTK)     += early_printk.o
52 +obj-$(CONFIG_EARLY_PRINTK_8250)        += early_printk_8250.o
53  obj-$(CONFIG_SPINLOCK_TEST)    += spinlock_test.o
54  obj-$(CONFIG_MIPS_MACHINE)     += mips_machine.o
55  
56 --- /dev/null
57 +++ b/arch/mips/kernel/early_printk_8250.c
58 @@ -0,0 +1,66 @@
59 +/*
60 + *  8250/16550-type serial ports prom_putchar()
61 + *
62 + *  Copyright (C) 2010  Yoichi Yuasa <yuasa@linux-mips.org>
63 + *
64 + *  This program is free software; you can redistribute it and/or modify
65 + *  it under the terms of the GNU General Public License as published by
66 + *  the Free Software Foundation; either version 2 of the License, or
67 + *  (at your option) any later version.
68 + *
69 + *  This program is distributed in the hope that it will be useful,
70 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
71 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
72 + *  GNU General Public License for more details.
73 + *
74 + *  You should have received a copy of the GNU General Public License
75 + *  along with this program; if not, write to the Free Software
76 + *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
77 + */
78 +#include <linux/io.h>
79 +#include <linux/serial_core.h>
80 +#include <linux/serial_reg.h>
81 +
82 +static void __iomem *serial8250_base;
83 +static unsigned int serial8250_reg_shift;
84 +static unsigned int serial8250_tx_timeout;
85 +
86 +void setup_8250_early_printk_port(unsigned long base, unsigned int reg_shift,
87 +                                 unsigned int timeout)
88 +{
89 +       serial8250_base = (void __iomem *)base;
90 +       serial8250_reg_shift = reg_shift;
91 +       serial8250_tx_timeout = timeout;
92 +}
93 +
94 +static inline u8 serial_in(int offset)
95 +{
96 +       return readb(serial8250_base + (offset << serial8250_reg_shift));
97 +}
98 +
99 +static inline void serial_out(int offset, char value)
100 +{
101 +       writeb(value, serial8250_base + (offset << serial8250_reg_shift));
102 +}
103 +
104 +void prom_putchar(char c)
105 +{
106 +       unsigned int timeout;
107 +       int status, bits;
108 +
109 +       if (!serial8250_base)
110 +               return;
111 +
112 +       timeout = serial8250_tx_timeout;
113 +       bits = UART_LSR_TEMT | UART_LSR_THRE;
114 +
115 +       do {
116 +               status = serial_in(UART_LSR);
117 +
118 +               if (--timeout == 0)
119 +                       break;
120 +       } while ((status & bits) != bits);
121 +
122 +       if (timeout)
123 +               serial_out(UART_TX, c);
124 +}