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