uboot/board/Marvell/common/serial.c
<<
>>
Prefs
   1/*
   2 * (C) Copyright 2001
   3 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
   4 *
   5 * modified for marvell db64360 eval board by
   6 * Ingo Assmus <ingo.assmus@keymile.com>
   7 *
   8 * See file CREDITS for list of people who contributed to this
   9 * project.
  10 *
  11 * This program is free software; you can redistribute it and/or
  12 * modify it under the terms of the GNU General Public License as
  13 * published by the Free Software Foundation; either version 2 of
  14 * the License, or (at your option) any later version.
  15 *
  16 * This program is distributed in the hope that it will be useful,
  17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19 * GNU General Public License for more details.
  20 *
  21 * You should have received a copy of the GNU General Public License
  22 * along with this program; if not, write to the Free Software
  23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24 * MA 02111-1307 USA
  25 */
  26
  27/*
  28 * serial.c - serial support for the gal ev board
  29 */
  30
  31/* supports both the 16650 duart and the MPSC */
  32
  33#include <common.h>
  34#include <command.h>
  35#include "../include/memory.h"
  36#include "serial.h"
  37
  38#ifdef CONFIG_DB64360
  39#include "../db64360/mpsc.h"
  40#endif
  41
  42#ifdef CONFIG_DB64460
  43#include "../db64460/mpsc.h"
  44#endif
  45
  46#include "ns16550.h"
  47
  48DECLARE_GLOBAL_DATA_PTR;
  49
  50#ifdef CONFIG_MPSC
  51
  52
  53int serial_init (void)
  54{
  55#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
  56        int clock_divisor = 230400 / gd->baudrate;
  57#endif
  58
  59        mpsc_init (gd->baudrate);
  60
  61        /* init the DUART chans so that KGDB in the kernel can use them */
  62#ifdef CONFIG_SYS_INIT_CHAN1
  63        NS16550_reinit (COM_PORTS[0], clock_divisor);
  64#endif
  65#ifdef CONFIG_SYS_INIT_CHAN2
  66        NS16550_reinit (COM_PORTS[1], clock_divisor);
  67#endif
  68        return (0);
  69}
  70
  71void serial_putc (const char c)
  72{
  73        if (c == '\n')
  74                mpsc_putchar ('\r');
  75
  76        mpsc_putchar (c);
  77}
  78
  79int serial_getc (void)
  80{
  81        return mpsc_getchar ();
  82}
  83
  84int serial_tstc (void)
  85{
  86        return mpsc_test_char ();
  87}
  88
  89void serial_setbrg (void)
  90{
  91        galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate);
  92}
  93
  94#else  /* ! CONFIG_MPSC */
  95
  96int serial_init (void)
  97{
  98        int clock_divisor = 230400 / gd->baudrate;
  99
 100#ifdef CONFIG_SYS_INIT_CHAN1
 101        (void) NS16550_init (0, clock_divisor);
 102#endif
 103#ifdef CONFIG_SYS_INIT_CHAN2
 104        (void) NS16550_init (1, clock_divisor);
 105#endif
 106        return (0);
 107}
 108
 109void serial_putc (const char c)
 110{
 111        if (c == '\n')
 112                NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
 113
 114        NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
 115}
 116
 117int serial_getc (void)
 118{
 119        return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
 120}
 121
 122int serial_tstc (void)
 123{
 124        return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
 125}
 126
 127void serial_setbrg (void)
 128{
 129        int clock_divisor = 230400 / gd->baudrate;
 130
 131#ifdef CONFIG_SYS_INIT_CHAN1
 132        NS16550_reinit (COM_PORTS[0], clock_divisor);
 133#endif
 134#ifdef CONFIG_SYS_INIT_CHAN2
 135        NS16550_reinit (COM_PORTS[1], clock_divisor);
 136#endif
 137}
 138
 139#endif /* CONFIG_MPSC */
 140
 141void serial_puts (const char *s)
 142{
 143        while (*s) {
 144                serial_putc (*s++);
 145        }
 146}
 147
 148#if defined(CONFIG_CMD_KGDB)
 149void kgdb_serial_init (void)
 150{
 151}
 152
 153void putDebugChar (int c)
 154{
 155        serial_putc (c);
 156}
 157
 158void putDebugStr (const char *str)
 159{
 160        serial_puts (str);
 161}
 162
 163int getDebugChar (void)
 164{
 165        return serial_getc ();
 166}
 167
 168void kgdb_interruptible (int yes)
 169{
 170        return;
 171}
 172#endif
 173