Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:50

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  *  @file
0005  *
0006  *  This file contains the libchip configuration information
0007  *  to instantiate the libchip driver for the serial ports.
0008  */
0009 
0010 /*
0011  *  COPYRIGHT (c) 1989-2012.
0012  *  On-Line Applications Research Corporation (OAR).
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #include <unistd.h> /* write */
0037 
0038 #include <bsp.h>
0039 #include <libchip/serial.h>
0040 #include <libchip/ns16550.h>
0041 #include <rtems/pci.h>
0042 #include <bsp/irq.h>
0043 
0044 #if 1
0045 #define COM_CONSOLE_FUNCTIONS  &ns16550_fns_polled
0046 #else
0047 #define COM_CONSOLE_FUNCTIONS  &ns16550_fns
0048 #endif
0049 
0050 /*
0051  * Base IO for UART
0052  */
0053 #define COM1_BASE_IO  0x3F8
0054 #define COM2_BASE_IO  0x3E8
0055 
0056 // #define CLOCK_RATE     368640
0057 #define CLOCK_RATE     (115200 * 16)
0058 
0059 #define COM_IO_BASE_ADDRESS   (0xa0000000UL | 0x18000000UL)
0060 
0061 static uint8_t com_get_register(uintptr_t addr, uint8_t i);
0062 static void com_set_register(uintptr_t addr, uint8_t i, uint8_t val);
0063 static uint8_t tty2_get_register(uintptr_t addr, uint8_t i);
0064 static void tty2_set_register(uintptr_t addr, uint8_t i, uint8_t val);
0065 
0066 
0067 uint8_t com_get_register(uintptr_t addr, uint8_t i)
0068 {
0069   uint8_t val;
0070   volatile uint8_t *ptr;
0071   ptr = (volatile uint8_t *) COM_IO_BASE_ADDRESS;
0072   ptr += addr;
0073   ptr += i;
0074   val = *ptr;
0075 
0076   return val;
0077 }
0078 
0079 void com_set_register(uintptr_t addr, uint8_t i, uint8_t val)
0080 {
0081   volatile uint8_t *ptr;
0082 
0083   ptr = (volatile uint8_t *) COM_IO_BASE_ADDRESS;
0084   ptr += addr;
0085   ptr += i;
0086   *ptr = val;
0087 }
0088 
0089 uint8_t tty2_get_register(uintptr_t addr, uint8_t i)
0090 {
0091   uint8_t val;
0092   volatile uint8_t *ptr;
0093 
0094   ptr = (volatile uint8_t *) COM_IO_BASE_ADDRESS;
0095   ptr += addr;
0096   ptr += (i * 8);
0097   val = *ptr;
0098 
0099   return val;
0100 }
0101 
0102 void tty2_set_register(uintptr_t addr, uint8_t i, uint8_t val)
0103 {
0104   volatile uint8_t *ptr;
0105 
0106   ptr = (volatile uint8_t *) COM_IO_BASE_ADDRESS;
0107   ptr += addr;
0108   ptr += (i * 8);
0109   *ptr = val;
0110 }
0111 
0112 console_tbl     Console_Configuration_Ports[] = {
0113   {
0114     "/dev/tty0",                          /* sDeviceName */
0115     SERIAL_NS16550,                       /* deviceType */
0116     COM_CONSOLE_FUNCTIONS,                /* pDeviceFns */
0117     NULL,                                 /* deviceProbe, assume it is there */
0118     NULL,                                 /* pDeviceFlow */
0119     16,                                   /* ulMargin */
0120     8,                                    /* ulHysteresis */
0121     (void *) 9600,        /* Baud Rate */ /* pDeviceParams */
0122     COM1_BASE_IO,                         /* ulCtrlPort1 */
0123     0x00000000,                           /* ulCtrlPort2 */
0124     COM1_BASE_IO,                         /* ulDataPort */
0125     com_get_register,                     /* getRegister */
0126     com_set_register,                     /* setRegister */
0127     NULL,/* unused */                     /* getData */
0128     NULL,/* unused */                     /* setData */
0129     CLOCK_RATE,                           /* ulClock */
0130     MALTA_IRQ_TTY0                        /* ulIntVector -- base for port */
0131   },
0132   {
0133     "/dev/tty1",                          /* sDeviceName */
0134     SERIAL_NS16550,                       /* deviceType */
0135     COM_CONSOLE_FUNCTIONS,                /* pDeviceFns */
0136     NULL,                                 /* deviceProbe, assume it is there */
0137     NULL,                                 /* pDeviceFlow */
0138     16,                                   /* ulMargin */
0139     8,                                    /* ulHysteresis */
0140     (void *) 9600,        /* Baud Rate */ /* pDeviceParams */
0141     COM2_BASE_IO,                         /* ulCtrlPort1 */
0142     0x00000000,                           /* ulCtrlPort2 */
0143     COM2_BASE_IO,                         /* ulDataPort */
0144     com_get_register,                     /* getRegister */
0145     com_set_register,                     /* setRegister */
0146     NULL,/* unused */                     /* getData */
0147     NULL,/* unused */                     /* setData */
0148     CLOCK_RATE,                           /* ulClock */
0149     MALTA_IRQ_TTY1                        /* ulIntVector -- base for port */
0150   },
0151   {
0152     "/dev/tty2",                          /* sDeviceName */
0153     SERIAL_NS16550,                       /* deviceType */
0154     COM_CONSOLE_FUNCTIONS,                /* pDeviceFns */
0155     NULL,                                 /* deviceProbe, assume it is there */
0156     NULL,                                 /* pDeviceFlow */
0157     16,                                   /* ulMargin */
0158     8,                                    /* ulHysteresis */
0159     (void *) 9600,        /* Baud Rate */ /* pDeviceParams */
0160     0,                    /* IGNORED */   /* ulCtrlPort1 */
0161     0,                    /* IGNORED */   /* ulCtrlPort2 */
0162     0,                    /* IGNORED */   /* ulDataPort */
0163     tty2_get_register,                    /* getRegister */
0164     tty2_set_register,                    /* setRegister */
0165     NULL,/* unused */                     /* getData */
0166     NULL,/* unused */                     /* setData */
0167     CLOCK_RATE,                           /* ulClock */
0168     MALTA_CPU_INT2                        /* ulIntVector -- base for port */
0169   },
0170 };
0171 
0172 /*
0173  *  Define a variable that contains the number of statically configured
0174  *  console devices.
0175  */
0176 unsigned long  Console_Configuration_Count = \
0177     (sizeof(Console_Configuration_Ports)/sizeof(console_tbl));