Here we explore another feature of Earlycon: the machine id provided to the driver. In this way we can cut&paste the OAMP code from uncompress.h directly to the omap-earlycon.c driver :) Of course this is possible because the OMAP legacy support was already quite dynamic and then ready for this job. Conceptually the OMAP port is already finished [0]. Actually it would be nice if the OMAP driver probed the expected shift value but used the UART base provided in drv->base if non-zero. UART base addresses specified on the cmdline would then have higher precedence respect the builtin logics. Again I only built omap1 and omap2plus defconfigs but could not test any. [0] It's interesting the approach of set_omap_uart_info() to store enough info to make later kernel early console automagically work. This concept could well be added to Earlycon and seamlessly link it to the main kernel's true early console. Let's see what people think. Signed-off-by: Domenico Andreoli --- arch/arm/plat-omap/include/plat/uncompress.h | 171 ----------------------- drivers/tty/serial/Makefile | 2 drivers/tty/serial/omap-earlycon.c | 200 +++++++++++++++++++++++++++ 3 files changed, 205 insertions(+), 168 deletions(-) Index: b/arch/arm/plat-omap/include/plat/uncompress.h =================================================================== --- a/arch/arm/plat-omap/include/plat/uncompress.h +++ b/arch/arm/plat-omap/include/plat/uncompress.h @@ -17,176 +17,13 @@ * kind, whether express or implied. */ -#include -#include - -#include -#include - -#include - -#define MDR1_MODE_MASK 0x07 - -volatile u8 *uart_base; -int uart_shift; - -/* - * Store the DEBUG_LL uart number into memory. - * See also debug-macro.S, and serial.c for related code. - */ -static void set_omap_uart_info(unsigned char port) +static inline void arch_decomp_setup(void) { - /* - * Get address of some.bss variable and round it down - * a la CONFIG_AUTO_ZRELADDR. - */ - u32 ram_start = (u32)&uart_shift & 0xf8000000; - u32 *uart_info = (u32 *)(ram_start + OMAP_UART_INFO_OFS); - *uart_info = port; -} - -static void putc(int c) -{ - if (!uart_base) - return; - - /* Check for UART 16x mode */ - if ((uart_base[UART_OMAP_MDR1 << uart_shift] & MDR1_MODE_MASK) != 0) - return; - - while (!(uart_base[UART_LSR << uart_shift] & UART_LSR_THRE)) - barrier(); - uart_base[UART_TX << uart_shift] = c; -} - -static inline void flush(void) -{ -} - -/* - * Macros to configure UART1 and debug UART - */ -#define _DEBUG_LL_ENTRY(mach, dbg_uart, dbg_shft, dbg_id) \ - if (machine_is_##mach()) { \ - uart_base = (volatile u8 *)(dbg_uart); \ - uart_shift = (dbg_shft); \ - port = (dbg_id); \ - set_omap_uart_info(port); \ - break; \ - } - -#define DEBUG_LL_OMAP7XX(p, mach) \ - _DEBUG_LL_ENTRY(mach, OMAP1_UART##p##_BASE, OMAP7XX_PORT_SHIFT, \ - OMAP1UART##p) - -#define DEBUG_LL_OMAP1(p, mach) \ - _DEBUG_LL_ENTRY(mach, OMAP1_UART##p##_BASE, OMAP_PORT_SHIFT, \ - OMAP1UART##p) - -#define DEBUG_LL_OMAP2(p, mach) \ - _DEBUG_LL_ENTRY(mach, OMAP2_UART##p##_BASE, OMAP_PORT_SHIFT, \ - OMAP2UART##p) - -#define DEBUG_LL_OMAP3(p, mach) \ - _DEBUG_LL_ENTRY(mach, OMAP3_UART##p##_BASE, OMAP_PORT_SHIFT, \ - OMAP3UART##p) - -#define DEBUG_LL_OMAP4(p, mach) \ - _DEBUG_LL_ENTRY(mach, OMAP4_UART##p##_BASE, OMAP_PORT_SHIFT, \ - OMAP4UART##p) - -/* Zoom2/3 shift is different for UART1 and external port */ -#define DEBUG_LL_ZOOM(mach) \ - _DEBUG_LL_ENTRY(mach, ZOOM_UART_BASE, ZOOM_PORT_SHIFT, ZOOM_UART) - -#define DEBUG_LL_TI81XX(p, mach) \ - _DEBUG_LL_ENTRY(mach, TI81XX_UART##p##_BASE, OMAP_PORT_SHIFT, \ - TI81XXUART##p) - -static inline void __arch_decomp_setup(unsigned long arch_id) -{ - int port = 0; - - /* - * Initialize the port based on the machine ID from the bootloader. - * Note that we're using macros here instead of switch statement - * as machine_is functions are optimized out for the boards that - * are not selected. - */ - do { - /* omap7xx/8xx based boards using UART1 with shift 0 */ - DEBUG_LL_OMAP7XX(1, herald); - DEBUG_LL_OMAP7XX(1, omap_perseus2); - - /* omap15xx/16xx based boards using UART1 */ - DEBUG_LL_OMAP1(1, ams_delta); - DEBUG_LL_OMAP1(1, nokia770); - DEBUG_LL_OMAP1(1, omap_h2); - DEBUG_LL_OMAP1(1, omap_h3); - DEBUG_LL_OMAP1(1, omap_innovator); - DEBUG_LL_OMAP1(1, omap_osk); - DEBUG_LL_OMAP1(1, omap_palmte); - DEBUG_LL_OMAP1(1, omap_palmz71); - - /* omap15xx/16xx based boards using UART2 */ - DEBUG_LL_OMAP1(2, omap_palmtt); - - /* omap15xx/16xx based boards using UART3 */ - DEBUG_LL_OMAP1(3, sx1); - - /* omap2 based boards using UART1 */ - DEBUG_LL_OMAP2(1, omap_2430sdp); - DEBUG_LL_OMAP2(1, omap_apollon); - DEBUG_LL_OMAP2(1, omap_h4); - - /* omap2 based boards using UART3 */ - DEBUG_LL_OMAP2(3, nokia_n800); - DEBUG_LL_OMAP2(3, nokia_n810); - DEBUG_LL_OMAP2(3, nokia_n810_wimax); - - /* omap3 based boards using UART1 */ - DEBUG_LL_OMAP2(1, omap3evm); - DEBUG_LL_OMAP3(1, omap_3430sdp); - DEBUG_LL_OMAP3(1, omap_3630sdp); - DEBUG_LL_OMAP3(1, omap3530_lv_som); - DEBUG_LL_OMAP3(1, omap3_torpedo); - - /* omap3 based boards using UART3 */ - DEBUG_LL_OMAP3(3, cm_t35); - DEBUG_LL_OMAP3(3, cm_t3517); - DEBUG_LL_OMAP3(3, cm_t3730); - DEBUG_LL_OMAP3(3, craneboard); - DEBUG_LL_OMAP3(3, devkit8000); - DEBUG_LL_OMAP3(3, igep0020); - DEBUG_LL_OMAP3(3, igep0030); - DEBUG_LL_OMAP3(3, nokia_rm680); - DEBUG_LL_OMAP3(3, nokia_rm696); - DEBUG_LL_OMAP3(3, nokia_rx51); - DEBUG_LL_OMAP3(3, omap3517evm); - DEBUG_LL_OMAP3(3, omap3_beagle); - DEBUG_LL_OMAP3(3, omap3_pandora); - DEBUG_LL_OMAP3(3, omap_ldp); - DEBUG_LL_OMAP3(3, overo); - DEBUG_LL_OMAP3(3, touchbook); - - /* omap4 based boards using UART3 */ - DEBUG_LL_OMAP4(3, omap_4430sdp); - DEBUG_LL_OMAP4(3, omap4_panda); - - /* zoom2/3 external uart */ - DEBUG_LL_ZOOM(omap_zoom2); - DEBUG_LL_ZOOM(omap_zoom3); - - /* TI8168 base boards using UART3 */ - DEBUG_LL_TI81XX(3, ti8168evm); - - /* TI8148 base boards using UART1 */ - DEBUG_LL_TI81XX(1, ti8148evm); - - } while (0); + /* use the builtin uart base probing */ + setup_earlycon("omap-uart", 0); } -#define arch_decomp_setup() __arch_decomp_setup(arch_id) +#define EARLYCON_STATIC_SETUP /* * nothing to do Index: b/drivers/tty/serial/Makefile =================================================================== --- a/drivers/tty/serial/Makefile +++ b/drivers/tty/serial/Makefile @@ -60,7 +60,7 @@ obj-$(CONFIG_SERIAL_NETX) += netx-serial obj-$(CONFIG_SERIAL_OF_PLATFORM) += of_serial.o obj-$(CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL) += nwpserial.o obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o -obj-$(CONFIG_SERIAL_OMAP) += omap-serial.o +obj-$(CONFIG_SERIAL_OMAP) += omap-serial.o omap-earlycon.o obj-$(CONFIG_SERIAL_ALTERA_UART) += altera_uart.o obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o obj-$(CONFIG_SERIAL_QE) += ucc_uart.o Index: b/drivers/tty/serial/omap-earlycon.c =================================================================== --- /dev/null +++ b/drivers/tty/serial/omap-earlycon.c @@ -0,0 +1,200 @@ +/* + * Earlycon driver for OMAP UARTs + * + * Copyright (C) 2012 Domenico Andreoli + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include + +#include +#include + +#include + +#define MDR1_MODE_MASK 0x07 + +struct uart_drvdata { + int shift; +}; + +/* + * Store the DEBUG_LL uart number into memory. + * See also debug-macro.S, and serial.c for related code. + */ +static void __earlyconinit set_omap_uart_info(struct uart_drvdata *drvdata, unsigned char port) +{ + /* + * Get address of some.bss variable and round it down + * a la CONFIG_AUTO_ZRELADDR. + */ + u32 ram_start = (u32) drvdata->shift & 0xf8000000; + u32 *uart_info = (u32 *)(ram_start + OMAP_UART_INFO_OFS); + *uart_info = port; +} + +/* + * Macros to configure UART1 and debug UART + */ +#define _DEBUG_LL_ENTRY(mach, dbg_uart, dbg_shft, dbg_id) \ + if (machine_is_##mach()) { \ + drv->base = (dbg_uart); \ + drvdata->shift = (dbg_shft); \ + RELOC_FUN(set_omap_uart_info)(drvdata, (dbg_id)); \ + break; \ + } + +#define DEBUG_LL_OMAP7XX(p, mach) \ + _DEBUG_LL_ENTRY(mach, OMAP1_UART##p##_BASE, OMAP7XX_PORT_SHIFT, \ + OMAP1UART##p) + +#define DEBUG_LL_OMAP1(p, mach) \ + _DEBUG_LL_ENTRY(mach, OMAP1_UART##p##_BASE, OMAP_PORT_SHIFT, \ + OMAP1UART##p) + +#define DEBUG_LL_OMAP2(p, mach) \ + _DEBUG_LL_ENTRY(mach, OMAP2_UART##p##_BASE, OMAP_PORT_SHIFT, \ + OMAP2UART##p) + +#define DEBUG_LL_OMAP3(p, mach) \ + _DEBUG_LL_ENTRY(mach, OMAP3_UART##p##_BASE, OMAP_PORT_SHIFT, \ + OMAP3UART##p) + +#define DEBUG_LL_OMAP4(p, mach) \ + _DEBUG_LL_ENTRY(mach, OMAP4_UART##p##_BASE, OMAP_PORT_SHIFT, \ + OMAP4UART##p) + +/* Zoom2/3 shift is different for UART1 and external port */ +#define DEBUG_LL_ZOOM(mach) \ + _DEBUG_LL_ENTRY(mach, ZOOM_UART_BASE, ZOOM_PORT_SHIFT, ZOOM_UART) + +#define DEBUG_LL_TI81XX(p, mach) \ + _DEBUG_LL_ENTRY(mach, TI81XX_UART##p##_BASE, OMAP_PORT_SHIFT, \ + TI81XXUART##p) + +static int __earlyconinit omap_earlycon_probe(struct earlycon_drv *drv) +{ + struct uart_drvdata *drvdata = (struct uart_drvdata *) drv->data; + + /* + * Initialize the port based on the machine ID from the bootloader. + * Note that we're using macros here instead of switch statement + * as machine_is functions are optimized out for the boards that + * are not selected. + */ + do { + /* omap7xx/8xx based boards using UART1 with shift 0 */ + DEBUG_LL_OMAP7XX(1, herald); + DEBUG_LL_OMAP7XX(1, omap_perseus2); + + /* omap15xx/16xx based boards using UART1 */ + DEBUG_LL_OMAP1(1, ams_delta); + DEBUG_LL_OMAP1(1, nokia770); + DEBUG_LL_OMAP1(1, omap_h2); + DEBUG_LL_OMAP1(1, omap_h3); + DEBUG_LL_OMAP1(1, omap_innovator); + DEBUG_LL_OMAP1(1, omap_osk); + DEBUG_LL_OMAP1(1, omap_palmte); + DEBUG_LL_OMAP1(1, omap_palmz71); + + /* omap15xx/16xx based boards using UART2 */ + DEBUG_LL_OMAP1(2, omap_palmtt); + + /* omap15xx/16xx based boards using UART3 */ + DEBUG_LL_OMAP1(3, sx1); + + /* omap2 based boards using UART1 */ + DEBUG_LL_OMAP2(1, omap_2430sdp); + DEBUG_LL_OMAP2(1, omap_apollon); + DEBUG_LL_OMAP2(1, omap_h4); + + /* omap2 based boards using UART3 */ + DEBUG_LL_OMAP2(3, nokia_n800); + DEBUG_LL_OMAP2(3, nokia_n810); + DEBUG_LL_OMAP2(3, nokia_n810_wimax); + + /* omap3 based boards using UART1 */ + DEBUG_LL_OMAP2(1, omap3evm); + DEBUG_LL_OMAP3(1, omap_3430sdp); + DEBUG_LL_OMAP3(1, omap_3630sdp); + DEBUG_LL_OMAP3(1, omap3530_lv_som); + DEBUG_LL_OMAP3(1, omap3_torpedo); + + /* omap3 based boards using UART3 */ + DEBUG_LL_OMAP3(3, cm_t35); + DEBUG_LL_OMAP3(3, cm_t3517); + DEBUG_LL_OMAP3(3, cm_t3730); + DEBUG_LL_OMAP3(3, craneboard); + DEBUG_LL_OMAP3(3, devkit8000); + DEBUG_LL_OMAP3(3, igep0020); + DEBUG_LL_OMAP3(3, igep0030); + DEBUG_LL_OMAP3(3, nokia_rm680); + DEBUG_LL_OMAP3(3, nokia_rm696); + DEBUG_LL_OMAP3(3, nokia_rx51); + DEBUG_LL_OMAP3(3, omap3517evm); + DEBUG_LL_OMAP3(3, omap3_beagle); + DEBUG_LL_OMAP3(3, omap3_pandora); + DEBUG_LL_OMAP3(3, omap_ldp); + DEBUG_LL_OMAP3(3, overo); + DEBUG_LL_OMAP3(3, touchbook); + + /* omap4 based boards using UART3 */ + DEBUG_LL_OMAP4(3, omap_4430sdp); + DEBUG_LL_OMAP4(3, omap4_panda); + + /* zoom2/3 external uart */ + DEBUG_LL_ZOOM(omap_zoom2); + DEBUG_LL_ZOOM(omap_zoom3); + + /* TI8168 base boards using UART3 */ + DEBUG_LL_TI81XX(3, ti8168evm); + + /* TI8148 base boards using UART1 */ + DEBUG_LL_TI81XX(1, ti8148evm); + + } while (0); + + return 0; +} + +/* we can deal with the case the UARTs are being run + * in FIFO mode, so that we don't hold up our execution + * waiting for tx to happen... +*/ +static void __earlyconinit omap_earlycon_putc(struct earlycon_drv *drv, int ch) +{ + struct uart_drvdata *drvdata = (struct uart_drvdata *) drv->data; + volatile u8 *uart_base = (volatile u8 *) drv->base; + + if (!uart_base) + return; + + /* Check for UART 16x mode */ + if ((uart_base[UART_OMAP_MDR1 << drvdata->shift] & MDR1_MODE_MASK) != 0) + return; + + while (!(uart_base[UART_LSR << drvdata->shift] & UART_LSR_THRE)) + barrier(); + uart_base[UART_TX << drvdata->shift] = ch; +} + +static void __earlyconinit omap_earlycon_flush(struct earlycon_drv *drv) +{ + /* TODO */ +} + +EARLYCON_START("omap-uart") + .probe = omap_earlycon_probe, + .putc = omap_earlycon_putc, + .flush = omap_earlycon_flush, +EARLYCON_END