1/* 2 * Copyright 2014, General Dynamics C4 Systems 3 * 4 * This software may be distributed and modified according to the terms of 5 * the GNU General Public License version 2. Note that NO WARRANTY is provided. 6 * See "LICENSE_GPLv2.txt" for details. 7 * 8 * @TAG(GD_GPL) 9 */ 10 11#include <config.h> 12#include <arch/kernel/boot_sys.h> 13#include <arch/model/statedata.h> 14#include <machine/io.h> 15#include <plat/machine/io.h> 16 17#if defined(CONFIG_DEBUG_BUILD) || defined(CONFIG_PRINTING) 18void 19serial_init(uint16_t port) 20{ 21 while (!(in8(port + 5) & 0x60)); /* wait until not busy */ 22 23 out8(port + 1, 0x00); /* disable generating interrupts */ 24 out8(port + 3, 0x80); /* line control register: command: set divisor */ 25 out8(port, 0x01); /* set low byte of divisor to 0x01 = 115200 baud */ 26 out8(port + 1, 0x00); /* set high byte of divisor to 0x00 */ 27 out8(port + 3, 0x03); /* line control register: set 8 bit, no parity, 1 stop bit */ 28 out8(port + 4, 0x0b); /* modem control register: set DTR/RTS/OUT2 */ 29 30 in8(port); /* clear receiver port */ 31 in8(port + 5); /* clear line status port */ 32 in8(port + 6); /* clear modem status port */ 33} 34#endif /* CONFIG_PRINTING || CONFIG_DEBUG_BUILD */ 35 36#ifdef CONFIG_PRINTING 37void 38putConsoleChar(unsigned char a) 39{ 40 while (x86KSconsolePort && !(in8(x86KSconsolePort + 5) & 0x20)); 41 out8(x86KSconsolePort, a); 42} 43#endif /* CONFIG_PRINTING */ 44 45#ifdef CONFIG_DEBUG_BUILD 46void 47putDebugChar(unsigned char a) 48{ 49 while (x86KSdebugPort && (in8(x86KSdebugPort + 5) & 0x20) == 0); 50 out8(x86KSdebugPort, a); 51} 52 53unsigned char 54getDebugChar(void) 55{ 56 while ((in8(x86KSdebugPort + 5) & 1) == 0); 57 return in8(x86KSdebugPort); 58} 59#endif /* CONFIG_DEBUG_BUILD */ 60