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