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