Path: blob/main/sys/arm/freescale/imx/imx_console.c
39536 views
/*-1* Copyright (c) 2012, 2013 The FreeBSD Foundation2*3* This software was developed by Oleksandr Rybalko under sponsorship4* from the FreeBSD Foundation.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728/* Simple UART console driver for Freescale i.MX515 */2930#include <sys/types.h>31#include <sys/param.h>32#include <sys/systm.h>33#include <sys/cons.h>34#include <sys/consio.h>35#include <sys/kernel.h>3637/* Allow it to be predefined, to be able to use another UART for console */38#ifndef IMX_UART_BASE39#define IMX_UART_BASE 0xe3fbc000 /* imx51 UART1 */40#endif4142#define IMX_RXD 0x0043#define IMX_TXD 0x404445#define IMX_UFCR 0x9046#define IMX_USR1 0x9447#define IMX_USR1_TRDY (1 << 13)4849#define IMX_USR2 0x9850#define IMX_USR2_RDR (1 << 0)51#define IMX_USR2_TXFE (1 << 14)52#define IMX_USR2_TXDC (1 << 3)5354#define IMX_UTS 0xb455#define IMX_UTS_TXFULL (1 << 4)5657/*58* The base address of the uart registers.59*60* This is global so that it can be changed on the fly from the outside. For61* example, set imx_uart_base=physaddr and then call cninit() as the first two62* lines of initarm() and enjoy printf() availability through the tricky bits of63* startup. After initarm() switches from physical to virtual addressing, just64* set imx_uart_base=virtaddr and printf keeps working.65*/66uint32_t imx_uart_base = IMX_UART_BASE;6768/*69* uart related funcs70*/71static uint32_t72ub_getreg(uint32_t off)73{7475return *((volatile uint32_t *)(imx_uart_base + off));76}7778static void79ub_setreg(uint32_t off, uint32_t val)80{8182*((volatile uint32_t *)(imx_uart_base + off)) = val;83}8485static int86ub_tstc(void)87{8889return ((ub_getreg(IMX_USR2) & IMX_USR2_RDR) ? 1 : 0);90}9192static int93ub_getc(void)94{9596while (!ub_tstc());97__asm __volatile("nop");9899return (ub_getreg(IMX_RXD) & 0xff);100}101102static void103ub_putc(unsigned char c)104{105106if (c == '\n')107ub_putc('\r');108109while (ub_getreg(IMX_UTS) & IMX_UTS_TXFULL)110__asm __volatile("nop");111112ub_setreg(IMX_TXD, c);113}114115static cn_probe_t uart_cnprobe;116static cn_init_t uart_cninit;117static cn_term_t uart_cnterm;118static cn_getc_t uart_cngetc;119static cn_putc_t uart_cnputc;120static cn_grab_t uart_cngrab;121static cn_ungrab_t uart_cnungrab;122123static void124uart_cngrab(struct consdev *cp)125{126127}128129static void130uart_cnungrab(struct consdev *cp)131{132133}134135static void136uart_cnprobe(struct consdev *cp)137{138139sprintf(cp->cn_name, "uart");140cp->cn_pri = CN_NORMAL;141}142143static void144uart_cninit(struct consdev *cp)145{146147/* Init fifo trigger levels to 32 bytes, refclock div to 2. */148ub_setreg(IMX_UFCR, 0x00004210);149}150151static void152uart_cnputc(struct consdev *cp, int c)153{154155ub_putc(c);156}157158static int159uart_cngetc(struct consdev * cp)160{161162return ub_getc();163}164165static void166uart_cnterm(struct consdev * cp)167{168169}170171CONSOLE_DRIVER(uart);172173174