Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  *  @file
0005  *
0006  *  @brief Driver for RTD316 ISA SCC Board
0007  *
0008  *  The RTD316 has a single Z85C30.
0009  */
0010 
0011 /*
0012  *  COPYRIGHT (c) 1989-2014.
0013  *  On-Line Applications Research Corporation (OAR).
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #include <bsp.h>
0038 #include <termios.h>
0039 #include <stdio.h>
0040 #include <stdlib.h>
0041 
0042 #include <rtems/termiostypes.h>
0043 #include <libchip/serial.h>
0044 #include <libchip/z85c30.h>
0045 #include <rtems/bspIo.h>
0046 #include <bsp/rtd316.h>
0047 #include <rtems/score/i386.h>
0048 #include "../../shared/dev/serial/legacy-console.h"
0049 
0050 #define RTD_CLOCK_RATE  (460800 * 32)
0051 
0052 uint8_t rtd316_com_get_register(uintptr_t addr, uint8_t reg)
0053 {
0054   register uint8_t val = 0;
0055 
0056   outport_byte( addr, reg );
0057   /* It appears the no delay is needed between the accesses. */
0058   inport_byte( addr, val );
0059 
0060   return val;
0061 }
0062 
0063 void rtd316_com_set_register(uintptr_t addr, uint8_t reg, uint8_t val)
0064 {
0065   outport_byte( addr, reg );
0066   /* It appears the no delay is needed between the accesses. */
0067   outport_byte( addr, val );
0068 }
0069 
0070 rtems_device_driver rtd316_initialize(
0071   rtems_device_major_number  major,
0072   rtems_device_minor_number  minor_arg,
0073   void                      *arg
0074 )
0075 {
0076   int           p;
0077   console_tbl  *ports;
0078   console_tbl  *port_p;
0079 
0080   /*
0081    *  Now allocate array of device structures and fill them in
0082    */
0083   ports = calloc( 2, sizeof( console_tbl ) );
0084   port_p = ports;
0085 
0086   for ( p=0 ; p<2 ; p++ ) {
0087     char name[32];
0088     sprintf( name, "/dev/rtd316_1_%d", p );
0089     printk("Found %s\n", name );
0090     port_p->sDeviceName   = strdup( name );
0091     port_p->deviceType    = SERIAL_Z85C30;
0092     #if 0
0093       port_p->pDeviceFns  = &z85c30_fns_polled;
0094     #else
0095       port_p->pDeviceFns  = &z85c30_fns;
0096     #endif
0097 
0098     port_p->deviceProbe   = NULL;
0099     port_p->pDeviceFlow   = NULL;
0100     port_p->ulMargin      = 16;
0101     port_p->ulHysteresis  = 8;
0102     port_p->pDeviceParams = (void *) 9600;
0103     port_p->getRegister   = rtd316_com_get_register;
0104     port_p->setRegister   = rtd316_com_set_register;
0105     port_p->getData       = NULL;
0106     port_p->setData       = NULL;
0107     port_p->ulClock       = RTD_CLOCK_RATE;
0108     port_p->ulIntVector   = 9;
0109 
0110     if ( p==0 ) {
0111       port_p->ulDataPort    = 0;
0112       port_p->ulCtrlPort1   = 0x340;
0113       port_p->ulCtrlPort2   = 0x341;
0114     } else {
0115       port_p->ulDataPort    = 1;
0116       port_p->ulCtrlPort1   = 0x342;
0117       port_p->ulCtrlPort2   = 0x343;
0118     }
0119     port_p++;
0120   }  /* end ports */
0121 
0122   /*
0123    *  Register the devices
0124    */
0125   console_register_devices( ports, 2 );
0126 
0127   return RTEMS_SUCCESSFUL;
0128 }