Home | History | Annotate | Line # | Download | only in s3c2xx0
sscom_s3c2410.c revision 1.8
      1  1.8     skrll /*	$NetBSD: sscom_s3c2410.c,v 1.8 2022/09/27 06:36:43 skrll Exp $ */
      2  1.1       bsh 
      3  1.1       bsh /*
      4  1.1       bsh  * Copyright (c) 2002, 2003 Fujitsu Component Limited
      5  1.1       bsh  * Copyright (c) 2002, 2003 Genetec Corporation
      6  1.1       bsh  * All rights reserved.
      7  1.1       bsh  *
      8  1.1       bsh  * Redistribution and use in source and binary forms, with or without
      9  1.1       bsh  * modification, are permitted provided that the following conditions
     10  1.1       bsh  * are met:
     11  1.1       bsh  * 1. Redistributions of source code must retain the above copyright
     12  1.1       bsh  *    notice, this list of conditions and the following disclaimer.
     13  1.1       bsh  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1       bsh  *    notice, this list of conditions and the following disclaimer in the
     15  1.1       bsh  *    documentation and/or other materials provided with the distribution.
     16  1.1       bsh  * 3. Neither the name of The Fujitsu Component Limited nor the name of
     17  1.1       bsh  *    Genetec corporation may not be used to endorse or promote products
     18  1.1       bsh  *    derived from this software without specific prior written permission.
     19  1.1       bsh  *
     20  1.1       bsh  * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC
     21  1.1       bsh  * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     22  1.1       bsh  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     23  1.1       bsh  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     24  1.1       bsh  * DISCLAIMED.  IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC
     25  1.1       bsh  * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     26  1.1       bsh  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     27  1.1       bsh  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
     28  1.1       bsh  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     29  1.1       bsh  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     30  1.1       bsh  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     31  1.1       bsh  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1       bsh  * SUCH DAMAGE.
     33  1.1       bsh  */
     34  1.1       bsh 
     35  1.1       bsh #include <sys/cdefs.h>
     36  1.8     skrll __KERNEL_RCSID(0, "$NetBSD: sscom_s3c2410.c,v 1.8 2022/09/27 06:36:43 skrll Exp $");
     37  1.1       bsh 
     38  1.1       bsh #include "opt_sscom.h"
     39  1.1       bsh #include "opt_ddb.h"
     40  1.1       bsh #include "opt_kgdb.h"
     41  1.1       bsh 
     42  1.1       bsh #include <sys/param.h>
     43  1.1       bsh #include <sys/systm.h>
     44  1.1       bsh #include <sys/ioctl.h>
     45  1.1       bsh #include <sys/select.h>
     46  1.1       bsh #include <sys/tty.h>
     47  1.1       bsh #include <sys/proc.h>
     48  1.1       bsh #include <sys/conf.h>
     49  1.1       bsh #include <sys/file.h>
     50  1.1       bsh #include <sys/uio.h>
     51  1.1       bsh #include <sys/kernel.h>
     52  1.1       bsh #include <sys/syslog.h>
     53  1.1       bsh #include <sys/types.h>
     54  1.1       bsh #include <sys/device.h>
     55  1.1       bsh #include <sys/timepps.h>
     56  1.1       bsh #include <sys/vnode.h>
     57  1.1       bsh 
     58  1.1       bsh #include <machine/intr.h>
     59  1.4    dyoung #include <sys/bus.h>
     60  1.1       bsh 
     61  1.1       bsh #include <arm/s3c2xx0/s3c2410reg.h>
     62  1.1       bsh #include <arm/s3c2xx0/s3c2410var.h>
     63  1.1       bsh #include <arm/s3c2xx0/sscom_var.h>
     64  1.1       bsh #include <sys/termios.h>
     65  1.1       bsh 
     66  1.6       chs static int sscom_match(device_t, cfdata_t, void *);
     67  1.6       chs static void sscom_attach(device_t, device_t, void *);
     68  1.1       bsh 
     69  1.5  nisimura CFATTACH_DECL_NEW(sscom, sizeof(struct sscom_softc), sscom_match,
     70  1.1       bsh     sscom_attach, NULL, NULL);
     71  1.1       bsh 
     72  1.1       bsh const struct sscom_uart_info s3c2410_uart_config[] = {
     73  1.1       bsh 	/* UART 0 */
     74  1.1       bsh 	{
     75  1.1       bsh 		0,
     76  1.1       bsh 		S3C2410_INT_TXD0,
     77  1.1       bsh 		S3C2410_INT_RXD0,
     78  1.1       bsh 		S3C2410_INT_ERR0,
     79  1.1       bsh 		S3C2410_UART_BASE(0),
     80  1.1       bsh 	},
     81  1.1       bsh 	/* UART 1 */
     82  1.1       bsh 	{
     83  1.1       bsh 		1,
     84  1.1       bsh 		S3C2410_INT_TXD1,
     85  1.1       bsh 		S3C2410_INT_RXD1,
     86  1.1       bsh 		S3C2410_INT_ERR1,
     87  1.1       bsh 		S3C2410_UART_BASE(1),
     88  1.1       bsh 	},
     89  1.1       bsh 	/* UART 2 */
     90  1.1       bsh 	{
     91  1.1       bsh 		2,
     92  1.1       bsh 		S3C2410_INT_TXD2,
     93  1.1       bsh 		S3C2410_INT_RXD2,
     94  1.1       bsh 		S3C2410_INT_ERR2,
     95  1.1       bsh 		S3C2410_UART_BASE(2),
     96  1.1       bsh 	},
     97  1.1       bsh };
     98  1.1       bsh 
     99  1.1       bsh static int
    100  1.6       chs sscom_match(device_t parent, cfdata_t cf, void *aux)
    101  1.1       bsh {
    102  1.1       bsh 	struct s3c2xx0_attach_args *sa = aux;
    103  1.1       bsh 	int unit = sa->sa_index;
    104  1.1       bsh 
    105  1.1       bsh 	return unit == 0 || unit == 1;
    106  1.1       bsh }
    107  1.1       bsh 
    108  1.7      matt /* RXINTn, TXINTn and ERRn interrupts are cascaded to UARTn irq. */
    109  1.7      matt 
    110  1.7      matt #define	_sscom_intbit(irqno)	(1<<((irqno)-S3C2410_SUBIRQ_MIN))
    111  1.7      matt 
    112  1.7      matt static void
    113  1.7      matt s3c2410_change_txrx_interrupts(struct sscom_softc *sc, bool unmask_p,
    114  1.7      matt     u_int flags)
    115  1.7      matt {
    116  1.7      matt 	int intbits = 0;
    117  1.7      matt 	if (flags & SSCOM_HW_RXINT)
    118  1.7      matt 		intbits |= _sscom_intbit((sc)->sc_rx_irqno);
    119  1.7      matt 	if (flags & SSCOM_HW_TXINT)
    120  1.7      matt 		intbits |= _sscom_intbit((sc)->sc_rx_irqno);
    121  1.7      matt 	if (unmask_p) {
    122  1.7      matt 		s3c2410_unmask_subinterrupts(intbits);
    123  1.7      matt 	} else {
    124  1.7      matt 		s3c2410_mask_subinterrupts(intbits);
    125  1.7      matt 	}
    126  1.7      matt }
    127  1.7      matt 
    128  1.1       bsh static void
    129  1.6       chs sscom_attach(device_t parent, device_t self, void *aux)
    130  1.1       bsh {
    131  1.5  nisimura 	struct sscom_softc *sc = device_private(self);
    132  1.1       bsh 	struct s3c2xx0_attach_args *sa = aux;
    133  1.1       bsh 	int unit = sa->sa_index;
    134  1.1       bsh 	bus_addr_t iobase = s3c2410_uart_config[unit].iobase;
    135  1.1       bsh 
    136  1.7      matt 	aprint_normal(": UART%d addr=%lx", sa->sa_index, iobase );
    137  1.1       bsh 
    138  1.5  nisimura 	sc->sc_dev = self;
    139  1.1       bsh 	sc->sc_iot = s3c2xx0_softc->sc_iot;
    140  1.1       bsh 	sc->sc_unit = unit;
    141  1.1       bsh 	sc->sc_frequency = s3c2xx0_softc->sc_pclk;
    142  1.1       bsh 
    143  1.7      matt 	sc->sc_change_txrx_interrupts = s3c2410_change_txrx_interrupts;
    144  1.7      matt 
    145  1.1       bsh 	sc->sc_rx_irqno = s3c2410_uart_config[sa->sa_index].rx_int;
    146  1.1       bsh 	sc->sc_tx_irqno = s3c2410_uart_config[sa->sa_index].tx_int;
    147  1.1       bsh 
    148  1.1       bsh 	if (bus_space_map(sc->sc_iot, iobase, SSCOM_SIZE, 0, &sc->sc_ioh)) {
    149  1.7      matt 		aprint_error( ": failed to map registers\n" );
    150  1.1       bsh 		return;
    151  1.1       bsh 	}
    152  1.1       bsh 
    153  1.1       bsh 	printf("\n");
    154  1.1       bsh 
    155  1.1       bsh 	s3c24x0_intr_establish(s3c2410_uart_config[unit].tx_int,
    156  1.1       bsh 	    IPL_SERIAL, IST_LEVEL, sscomtxintr, sc);
    157  1.1       bsh 	s3c24x0_intr_establish(s3c2410_uart_config[unit].rx_int,
    158  1.1       bsh 	    IPL_SERIAL, IST_LEVEL, sscomrxintr, sc);
    159  1.1       bsh 	s3c24x0_intr_establish(s3c2410_uart_config[unit].err_int,
    160  1.1       bsh 	    IPL_SERIAL, IST_LEVEL, sscomrxintr, sc);
    161  1.1       bsh 	sscom_disable_txrxint(sc);
    162  1.1       bsh 
    163  1.1       bsh 	sscom_attach_subr(sc);
    164  1.1       bsh }
    165  1.1       bsh 
    166  1.1       bsh 
    167  1.1       bsh 
    168  1.1       bsh int
    169  1.1       bsh s3c2410_sscom_cnattach(bus_space_tag_t iot, int unit, int rate,
    170  1.1       bsh     int frequency, tcflag_t cflag)
    171  1.1       bsh {
    172  1.1       bsh 	return sscom_cnattach(iot, s3c2410_uart_config + unit,
    173  1.1       bsh 	    rate, frequency, cflag);
    174  1.1       bsh }
    175  1.1       bsh 
    176  1.1       bsh #ifdef KGDB
    177  1.1       bsh int
    178  1.1       bsh s3c2410_sscom_kgdb_attach(bus_space_tag_t iot, int unit, int rate,
    179  1.1       bsh     int frequency, tcflag_t cflag)
    180  1.1       bsh {
    181  1.1       bsh 	return sscom_kgdb_attach(iot, s3c2410_uart_config + unit,
    182  1.1       bsh 	    rate, frequency, cflag);
    183  1.1       bsh }
    184  1.1       bsh #endif /* KGDB */
    185