No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / arm / omap / obio_com.c
blobb9d2da30d72ead647221b07c1b787c9f7a7ffa2d
1 /* $NetBSD: obio_com.c,v 1.2 2008/04/27 18:58:45 matt Exp $ */
3 /*
4 * Based on arch/arm/omap/omap_com.c
6 * Copyright 2003 Wasabi Systems, Inc.
7 * OMAP support Copyright (c) 2007 Microsoft
8 * All rights reserved.
10 * Written by Steve C. Woodford for Wasabi Systems, Inc.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed for the NetBSD Project by
23 * Wasabi Systems, Inc.
24 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
25 * or promote products derived from this software without specific prior
26 * written permission.
28 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: obio_com.c,v 1.2 2008/04/27 18:58:45 matt Exp $");
44 #include "opt_omap.h"
45 #include "opt_com.h"
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/device.h>
50 #include <sys/termios.h>
52 #include <machine/intr.h>
53 #include <machine/bus.h>
55 #include <dev/ic/comreg.h>
56 #include <dev/ic/comvar.h>
58 #include <arm/omap/omap2_obiovar.h>
59 #include <arm/omap/omap2_reg.h>
60 #include <arm/omap/omap_com.h>
62 #include "locators.h"
64 static int obiouart_match(device_t, cfdata_t, void *);
65 static void obiouart_attach(device_t, device_t, void *);
66 static int uart_enable(struct obio_attach_args *);
67 static void obiouart_callout(void *);
69 struct com_obio_softc {
70 struct com_softc sc_sc;
71 struct callout sc_callout;
74 CFATTACH_DECL_NEW(obiouart, sizeof(struct com_obio_softc),
75 obiouart_match, obiouart_attach, NULL, NULL);
77 static int
78 obiouart_match(device_t parent, cfdata_t cf, void *aux)
80 struct obio_attach_args *obio = aux;
81 bus_space_handle_t bh;
82 int rv;
84 if (obio->obio_addr == OBIOCF_ADDR_DEFAULT)
85 panic("obiouart must have addr specified in config.");
87 #if 0
89 * XXX this should be ifdefed on a board-dependent switch
90 * We don't know what is the irq for com0 on the sdp2430
92 if (obio->obio_intr == OBIOCF_INTR_DEFAULT)
93 panic("obiouart must have intr specified in config.");
94 #endif
96 if (obio->obio_size == OBIOCF_SIZE_DEFAULT)
97 obio->obio_size = OMAP_COM_SIZE;
99 if (com_is_console(obio->obio_iot, obio->obio_addr, NULL))
100 return 1;
102 if (uart_enable(obio) != 0)
103 return 1;
105 if (bus_space_map(obio->obio_iot, obio->obio_addr, obio->obio_size,
106 0, &bh))
107 return 1;
109 rv = comprobe1(obio->obio_iot, bh);
111 bus_space_unmap(obio->obio_iot, bh, obio->obio_size);
113 return rv;
116 static void
117 obiouart_attach(device_t parent, device_t self, void *aux)
119 struct com_obio_softc *osc = device_private(self);
120 struct com_softc *sc = &osc->sc_sc;
121 struct obio_attach_args *obio = aux;
122 bus_space_tag_t iot;
123 bus_space_handle_t ioh = 0;
124 bus_addr_t iobase;
126 sc->sc_dev = self;
128 iot = obio->obio_iot;
129 iobase = obio->obio_addr;
130 sc->sc_frequency = OMAP_COM_FREQ;
131 sc->sc_type = COM_TYPE_NORMAL;
133 if (com_is_console(iot, iobase, &ioh) == 0 &&
134 bus_space_map(iot, iobase, obio->obio_size, 0, &ioh)) {
135 panic(": can't map registers\n");
136 return;
138 COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
140 com_attach_subr(sc);
141 aprint_naive("\n");
143 if (obio->obio_intr != OBIOCF_INTR_DEFAULT) {
144 intr_establish(obio->obio_intr, IPL_SERIAL, IST_LEVEL,
145 comintr, sc);
146 } else {
147 callout_init(&osc->sc_callout, 0);
148 callout_reset(&osc->sc_callout, 1, obiouart_callout, osc);
152 static void
153 obiouart_callout(void *arg)
155 struct com_obio_softc * const osc = arg;
156 int s;
157 s = splserial();
158 comintr(arg);
159 splx(s);
160 callout_schedule(&osc->sc_callout, 1);
164 static int
165 uart_enable(struct obio_attach_args *obio)
167 bus_space_handle_t ioh;
168 uint32_t r;
169 #if 0
170 uint32_t clksel2;
171 #endif
172 uint32_t fclken1;
173 uint32_t iclken1;
174 int err;
175 int n=-1;
177 KASSERT(obio != NULL);
179 err = bus_space_map(obio->obio_iot, OMAP2_CM_BASE,
180 OMAP2_CM_SIZE, 0, &ioh);
181 KASSERT(err == 0);
184 switch(obio->obio_addr) {
185 case 0x4806a000:
186 fclken1 = OMAP2_CM_FCLKEN1_CORE_EN_UART1;
187 iclken1 = OMAP2_CM_ICLKEN1_CORE_EN_UART1;
188 n = 1;
189 break;
190 case 0x4806c000:
191 fclken1 = OMAP2_CM_FCLKEN1_CORE_EN_UART2;
192 iclken1 = OMAP2_CM_ICLKEN1_CORE_EN_UART2;
193 n = 2;
194 break;
195 case 0x4806e000:
196 fclken1 = OMAP2_CM_FCLKEN2_CORE_EN_UART3;
197 iclken1 = OMAP2_CM_ICLKEN2_CORE_EN_UART3;
198 n = 3;
199 break;
200 default:
201 goto err;
204 printf("%s: UART#%d\n", __func__, n);
206 #if 0
207 r = bus_space_read_4(obio->obio_iot, ioh, OMAP2_CM_CLKSEL2_CORE);
208 r |= clksel2;
209 bus_space_write_4(obio->obio_iot, ioh, OMAP2_CM_CLKSEL2_CORE, r);
210 #endif
212 r = bus_space_read_4(obio->obio_iot, ioh, OMAP2_CM_FCLKEN1_CORE);
213 r |= fclken1;
214 bus_space_write_4(obio->obio_iot, ioh, OMAP2_CM_FCLKEN1_CORE, r);
216 r = bus_space_read_4(obio->obio_iot, ioh, OMAP2_CM_ICLKEN1_CORE);
217 r |= iclken1;
218 bus_space_write_4(obio->obio_iot, ioh, OMAP2_CM_ICLKEN1_CORE, r);
220 err:
221 // bus_space_unmap(obio->obio_iot, ioh, OMAP2_CM_SIZE);
223 return 0;