xref: /netbsd-src/sys/arch/arm/s3c2xx0/sscom_s3c2800.c (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1 /*	$NetBSD: sscom_s3c2800.c,v 1.10 2014/03/14 21:40:48 matt Exp $ */
2 
3 /*
4  * Copyright (c) 2002, 2003 Fujitsu Component Limited
5  * Copyright (c) 2002, 2003 Genetec Corporation
6  * All rights reserved.
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  * 3. Neither the name of The Fujitsu Component Limited nor the name of
17  *    Genetec corporation may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC
21  * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED.  IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC
25  * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: sscom_s3c2800.c,v 1.10 2014/03/14 21:40:48 matt Exp $");
37 
38 #include "opt_sscom.h"
39 #include "opt_ddb.h"
40 #include "opt_kgdb.h"
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/ioctl.h>
45 #include <sys/select.h>
46 #include <sys/tty.h>
47 #include <sys/proc.h>
48 #include <sys/conf.h>
49 #include <sys/file.h>
50 #include <sys/uio.h>
51 #include <sys/kernel.h>
52 #include <sys/syslog.h>
53 #include <sys/types.h>
54 #include <sys/device.h>
55 #include <sys/malloc.h>
56 #include <sys/timepps.h>
57 #include <sys/vnode.h>
58 
59 #include <machine/intr.h>
60 #include <sys/bus.h>
61 
62 #include <arm/s3c2xx0/s3c2800reg.h>
63 #include <arm/s3c2xx0/s3c2800var.h>
64 #include <arm/s3c2xx0/sscom_var.h>
65 #include <sys/termios.h>
66 
67 static int sscom_match(device_t, cfdata_t, void *);
68 static void sscom_attach(device_t, device_t, void *);
69 
70 CFATTACH_DECL_NEW(sscom, sizeof(struct sscom_softc), sscom_match,
71     sscom_attach, NULL, NULL);
72 
73 const struct sscom_uart_info s3c2800_uart_config[] = {
74 	/* UART 0 */
75 	{
76 		0,
77 		S3C2800_INT_TXD0,
78 		S3C2800_INT_RXD0,
79 		S3C2800_INT_UERR0,
80 		S3C2800_UART0_BASE,
81 	},
82 	/* UART 1 */
83 	{
84 		1,
85 		S3C2800_INT_TXD1,
86 		S3C2800_INT_RXD1,
87 		S3C2800_INT_UERR1,
88 		S3C2800_UART1_BASE,
89 	},
90 };
91 
92 static int
93 sscom_match(device_t parent, cfdata_t cf, void *aux)
94 {
95 	struct s3c2xx0_attach_args *sa = aux;
96 	int unit = sa->sa_index;
97 
98 	return unit == 0 || unit == 1;
99 }
100 
101 static void
102 s3c2800_change_txrx_interrupts(struct sscom_softc *sc, bool unmask_p,
103     u_int flags)
104 {
105 	int intbits = 0;
106 	if (flags & SSCOM_HW_RXINT)
107 		intbits |= 1 << sc->sc_rx_irqno;
108 	if (flags & SSCOM_HW_TXINT)
109 		intbits |= 1 << sc->sc_tx_irqno;
110 	if (unmask_p) {
111 		s3c2xx0_unmask_interrupts(intbits);
112 	} else {
113 		s3c2xx0_mask_interrupts(intbits);
114 	}
115 }
116 
117 static void
118 sscom_attach(device_t parent, device_t self, void *aux)
119 {
120 	struct sscom_softc *sc = device_private(self);
121 	struct s3c2xx0_attach_args *sa = aux;
122 	int unit = sa->sa_index;
123 	bus_addr_t iobase = s3c2800_uart_config[unit].iobase;
124 
125 	printf( ": UART%d addr=%lx", sa->sa_index, iobase );
126 
127 	sc->sc_dev = self;
128 	sc->sc_iot = s3c2xx0_softc->sc_iot;
129 	sc->sc_unit = unit;
130 	sc->sc_frequency = s3c2xx0_softc->sc_pclk;
131 
132 	sc->sc_change_txrx_interrupts = s3c2800_change_txrx_interrupts;
133 
134 	sc->sc_rx_irqno = S3C2800_INT_RXD0 + sa->sa_index;
135 	sc->sc_tx_irqno = S3C2800_INT_TXD0 + sa->sa_index;
136 
137 	if (bus_space_map(sc->sc_iot, iobase, SSCOM_SIZE, 0, &sc->sc_ioh)) {
138 		printf( ": failed to map registers\n" );
139 		return;
140 	}
141 
142 	printf("\n");
143 
144 	s3c2800_intr_establish(s3c2800_uart_config[unit].tx_int,
145 	    IPL_SERIAL, IST_LEVEL, sscomtxintr, sc);
146 	s3c2800_intr_establish(s3c2800_uart_config[unit].rx_int,
147 	    IPL_SERIAL, IST_LEVEL, sscomrxintr, sc);
148 	s3c2800_intr_establish(s3c2800_uart_config[unit].err_int,
149 	    IPL_SERIAL, IST_LEVEL, sscomrxintr, sc);
150 	sscom_disable_txrxint(sc);
151 
152 	sscom_attach_subr(sc);
153 }
154 
155 
156 
157 int
158 s3c2800_sscom_cnattach(bus_space_tag_t iot, int unit, int rate,
159     int frequency, tcflag_t cflag)
160 {
161 	return sscom_cnattach(iot, s3c2800_uart_config + unit,
162 	    rate, frequency, cflag);
163 }
164 
165 #ifdef KGDB
166 int
167 s3c2800_sscom_kgdb_attach(bus_space_tag_t iot, int unit, int rate,
168     int frequency, tcflag_t cflag)
169 {
170 	return sscom_kgdb_attach(iot, s3c2800_uart_config + unit,
171 	    rate, frequency, cflag);
172 }
173 #endif /* KGDB */
174