sscom_s3c2800.c revision 1.1 1 /* $NetBSD: sscom_s3c2800.c,v 1.1 2002/11/20 17:52:52 bsh Exp $ */
2
3 /*
4 * Copyright (c) 2002 Fujitsu Component Limited
5 * Copyright (c) 2002 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
36 #include "opt_sscom.h"
37 #include "opt_ddb.h"
38 #include "opt_kgdb.h"
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/ioctl.h>
43 #include <sys/select.h>
44 #include <sys/tty.h>
45 #include <sys/proc.h>
46 #include <sys/user.h>
47 #include <sys/conf.h>
48 #include <sys/file.h>
49 #include <sys/uio.h>
50 #include <sys/kernel.h>
51 #include <sys/syslog.h>
52 #include <sys/types.h>
53 #include <sys/device.h>
54 #include <sys/malloc.h>
55 #include <sys/timepps.h>
56 #include <sys/vnode.h>
57
58 #include <machine/intr.h>
59 #include <machine/bus.h>
60
61 #include <arm/s3c2xx0/s3c2800reg.h>
62 #include <arm/s3c2xx0/s3c2800var.h>
63 #include <arm/s3c2xx0/sscom_var.h>
64 #include <sys/termios.h>
65
66 #ifndef SSCOM_FREQ
67 #define SSCOM_FREQ 50000000
68 #endif
69
70 static int sscom_match(struct device *, struct cfdata *, void *);
71 static void sscom_attach(struct device *, struct device *, void *);
72
73 CFATTACH_DECL(sscom, sizeof(struct sscom_softc), sscom_match,
74 sscom_attach, NULL, NULL);
75
76 const struct sscom_uart_info s3c2800_uart_config[] = {
77 /* UART 0 */
78 {
79 0,
80 S3C2800_INT_TXD0,
81 S3C2800_INT_RXD0,
82 S3C2800_INT_UERR0,
83 S3C2800_UART0_BASE,
84 },
85 /* UART 1 */
86 {
87 1,
88 S3C2800_INT_TXD1,
89 S3C2800_INT_RXD1,
90 S3C2800_INT_UERR1,
91 S3C2800_UART1_BASE,
92 },
93 };
94
95 static int
96 sscom_match(struct device * parent, struct cfdata * cf, void *aux)
97 {
98 struct s3c2xx0_attach_args *sa = aux;
99 int unit = sa->sa_index;
100
101 return unit == 0 || unit == 1;
102 }
103
104 int tx_int(void *);
105 int rx_int(void *);
106 int err_int(void *);
107
108 int
109 tx_int(void *arg)
110 {
111 return sscomintr(arg);
112 }
113
114 int
115 rx_int(void *arg)
116 {
117 return sscomintr(arg);
118 }
119
120 int
121 err_int(void *arg)
122 {
123 return sscomintr(arg);
124 }
125
126
127 static void
128 sscom_attach(struct device * parent, struct device * self, void *aux)
129 {
130 struct sscom_softc *sc = (struct sscom_softc *) self;
131 struct s3c2xx0_attach_args *sa = aux;
132 int unit = sa->sa_index;
133 bus_addr_t iobase = s3c2800_uart_config[unit].iobase;
134
135
136 printf(": UART%d addr=%lx", sa->sa_index, iobase);
137
138 sc->sc_iot = s3c2xx0_softc->sc_iot;
139 sc->sc_unit = unit;
140 sc->sc_frequency = SSCOM_FREQ;
141
142 sc->sc_rx_irqno = S3C2800_INT_RXD0 + sa->sa_index;
143 sc->sc_tx_irqno = S3C2800_INT_TXD0 + sa->sa_index;
144
145 if (bus_space_map(sc->sc_iot, iobase, SSCOM_SIZE, 0, &sc->sc_ioh)) {
146 printf(": failed to map registers\n");
147 return;
148 }
149 printf("\n");
150
151 #if 0
152 s3c2800_intr_establish(s3c2800_uart_config[unit].tx_int,
153 IPL_SERIAL, sscomintr, sc);
154 s3c2800_intr_establish(s3c2800_uart_config[unit].rx_int,
155 IPL_SERIAL, sscomintr, sc);
156 s3c2800_intr_establish(s3c2800_uart_config[unit].err_int,
157 IPL_SERIAL, sscomintr, sc);
158 #else
159 s3c2800_intr_establish(s3c2800_uart_config[unit].tx_int,
160 IPL_SERIAL, tx_int, sc);
161 s3c2800_intr_establish(s3c2800_uart_config[unit].rx_int,
162 IPL_SERIAL, rx_int, sc);
163 s3c2800_intr_establish(s3c2800_uart_config[unit].err_int,
164 IPL_SERIAL, err_int, sc);
165 #endif
166 sscom_disable_txrxint(sc);
167
168 sscom_attach_subr(sc);
169 }
170
171
172
173 int
174 s3c2800_sscom_cnattach(bus_space_tag_t iot, int unit, int rate,
175 int frequency, tcflag_t cflag)
176 {
177 return sscom_cnattach(iot, s3c2800_uart_config + unit,
178 rate, frequency, cflag);
179 }
180 #ifdef KGDB
181 int
182 s3c2800_sscom_kgdb_attach(bus_space_tag_t iot, int unit, int rate,
183 int frequency, tcflag_t cflag)
184 {
185 return sscom_kgdb_attach(iot, s3c2800_uart_config + unit,
186 rate, frequency, cflag);
187 }
188 #endif /* KGDB */
189