uboot/board/evb64260/serial.c
<<
>>
Prefs
   1/*
   2 * (C) Copyright 2001
   3 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
   4 *
   5 * SPDX-License-Identifier:     GPL-2.0+
   6 */
   7
   8/*
   9 * serial.c - serial support for the gal ev board
  10 */
  11
  12/* supports both the 16650 duart and the MPSC */
  13
  14#include <common.h>
  15#include <command.h>
  16#include <galileo/memory.h>
  17#include <serial.h>
  18#include <linux/compiler.h>
  19
  20#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
  21#include <ns16550.h>
  22#endif
  23
  24#include "mpsc.h"
  25
  26DECLARE_GLOBAL_DATA_PTR;
  27
  28#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
  29const NS16550_t COM_PORTS[] = { (NS16550_t) CONFIG_SYS_NS16550_COM1,
  30                                (NS16550_t) CONFIG_SYS_NS16550_COM2 };
  31#endif
  32
  33#ifdef CONFIG_MPSC
  34
  35static int evb64260_serial_init(void)
  36{
  37#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
  38        int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
  39#endif
  40
  41        mpsc_init(gd->baudrate);
  42
  43        /* init the DUART chans so that KGDB in the kernel can use them */
  44#ifdef CONFIG_SYS_INIT_CHAN1
  45        NS16550_reinit(COM_PORTS[0], clock_divisor);
  46#endif
  47#ifdef CONFIG_SYS_INIT_CHAN2
  48        NS16550_reinit(COM_PORTS[1], clock_divisor);
  49#endif
  50        return (0);
  51}
  52
  53static void evb64260_serial_putc(const char c)
  54{
  55        if (c == '\n')
  56                mpsc_putchar('\r');
  57
  58        mpsc_putchar(c);
  59}
  60
  61static int evb64260_serial_getc(void)
  62{
  63        return mpsc_getchar();
  64}
  65
  66static int evb64260_serial_tstc(void)
  67{
  68        return mpsc_test_char();
  69}
  70
  71static void evb64260_serial_setbrg(void)
  72{
  73        galbrg_set_baudrate(CONFIG_MPSC_PORT, gd->baudrate);
  74}
  75
  76#else /* ! CONFIG_MPSC */
  77
  78static int evb64260_serial_init(void)
  79{
  80        int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
  81
  82#ifdef CONFIG_SYS_INIT_CHAN1
  83        (void)NS16550_init(COM_PORTS[0], clock_divisor);
  84#endif
  85#ifdef CONFIG_SYS_INIT_CHAN2
  86        (void)NS16550_init(COM_PORTS[1], clock_divisor);
  87#endif
  88
  89        return (0);
  90}
  91
  92static void evb64260_serial_putc(const char c)
  93{
  94        if (c == '\n')
  95                NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
  96
  97        NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
  98}
  99
 100static int evb64260_serial_getc(void)
 101{
 102        return NS16550_getc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
 103}
 104
 105static int evb64260_serial_tstc(void)
 106{
 107        return NS16550_tstc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
 108}
 109
 110static void evb64260_serial_setbrg(void)
 111{
 112        int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
 113
 114#ifdef CONFIG_SYS_INIT_CHAN1
 115        NS16550_reinit(COM_PORTS[0], clock_divisor);
 116#endif
 117#ifdef CONFIG_SYS_INIT_CHAN2
 118        NS16550_reinit(COM_PORTS[1], clock_divisor);
 119#endif
 120}
 121
 122#endif /* CONFIG_MPSC */
 123
 124static struct serial_device evb64260_serial_drv = {
 125        .name   = "evb64260_serial",
 126        .start  = evb64260_serial_init,
 127        .stop   = NULL,
 128        .setbrg = evb64260_serial_setbrg,
 129        .putc   = evb64260_serial_putc,
 130        .puts   = default_serial_puts,
 131        .getc   = evb64260_serial_getc,
 132        .tstc   = evb64260_serial_tstc,
 133};
 134
 135void evb64260_serial_initialize(void)
 136{
 137        serial_register(&evb64260_serial_drv);
 138}
 139
 140__weak struct serial_device *default_serial_console(void)
 141{
 142        return &evb64260_serial_drv;
 143}
 144
 145#if defined(CONFIG_CMD_KGDB)
 146void
 147kgdb_serial_init(void)
 148{
 149}
 150
 151void
 152putDebugChar (int c)
 153{
 154        serial_putc (c);
 155}
 156
 157void
 158putDebugStr (const char *str)
 159{
 160        serial_puts (str);
 161}
 162
 163int
 164getDebugChar (void)
 165{
 166        return serial_getc();
 167}
 168
 169void
 170kgdb_interruptible (int yes)
 171{
 172        return;
 173}
 174#endif
 175