1 /* $NetBSD: obio_com.c,v 1.2 2008/04/27 18:58:45 matt Exp $ */
4 * Based on arch/arm/omap/omap_com.c
6 * Copyright 2003 Wasabi Systems, Inc.
7 * OMAP support Copyright (c) 2007 Microsoft
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
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
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 $");
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>
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
);
78 obiouart_match(device_t parent
, cfdata_t cf
, void *aux
)
80 struct obio_attach_args
*obio
= aux
;
81 bus_space_handle_t bh
;
84 if (obio
->obio_addr
== OBIOCF_ADDR_DEFAULT
)
85 panic("obiouart must have addr specified in config.");
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.");
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
))
102 if (uart_enable(obio
) != 0)
105 if (bus_space_map(obio
->obio_iot
, obio
->obio_addr
, obio
->obio_size
,
109 rv
= comprobe1(obio
->obio_iot
, bh
);
111 bus_space_unmap(obio
->obio_iot
, bh
, obio
->obio_size
);
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
;
123 bus_space_handle_t ioh
= 0;
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");
138 COM_INIT_REGS(sc
->sc_regs
, iot
, ioh
, iobase
);
143 if (obio
->obio_intr
!= OBIOCF_INTR_DEFAULT
) {
144 intr_establish(obio
->obio_intr
, IPL_SERIAL
, IST_LEVEL
,
147 callout_init(&osc
->sc_callout
, 0);
148 callout_reset(&osc
->sc_callout
, 1, obiouart_callout
, osc
);
153 obiouart_callout(void *arg
)
155 struct com_obio_softc
* const osc
= arg
;
160 callout_schedule(&osc
->sc_callout
, 1);
165 uart_enable(struct obio_attach_args
*obio
)
167 bus_space_handle_t ioh
;
177 KASSERT(obio
!= NULL
);
179 err
= bus_space_map(obio
->obio_iot
, OMAP2_CM_BASE
,
180 OMAP2_CM_SIZE
, 0, &ioh
);
184 switch(obio
->obio_addr
) {
186 fclken1
= OMAP2_CM_FCLKEN1_CORE_EN_UART1
;
187 iclken1
= OMAP2_CM_ICLKEN1_CORE_EN_UART1
;
191 fclken1
= OMAP2_CM_FCLKEN1_CORE_EN_UART2
;
192 iclken1
= OMAP2_CM_ICLKEN1_CORE_EN_UART2
;
196 fclken1
= OMAP2_CM_FCLKEN2_CORE_EN_UART3
;
197 iclken1
= OMAP2_CM_ICLKEN2_CORE_EN_UART3
;
204 printf("%s: UART#%d\n", __func__
, n
);
207 r
= bus_space_read_4(obio
->obio_iot
, ioh
, OMAP2_CM_CLKSEL2_CORE
);
209 bus_space_write_4(obio
->obio_iot
, ioh
, OMAP2_CM_CLKSEL2_CORE
, r
);
212 r
= bus_space_read_4(obio
->obio_iot
, ioh
, OMAP2_CM_FCLKEN1_CORE
);
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
);
218 bus_space_write_4(obio
->obio_iot
, ioh
, OMAP2_CM_ICLKEN1_CORE
, r
);
221 // bus_space_unmap(obio->obio_iot, ioh, OMAP2_CM_SIZE);