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