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