pxa2x0_com.c revision 1.7 1 1.7 kiyohara /* $NetBSD: pxa2x0_com.c,v 1.7 2006/12/10 12:46:48 kiyohara Exp $ */
2 1.1 scw
3 1.1 scw /*
4 1.1 scw * Copyright 2003 Wasabi Systems, Inc.
5 1.1 scw * All rights reserved.
6 1.1 scw *
7 1.1 scw * Written by Steve C. Woodford for Wasabi Systems, Inc.
8 1.1 scw *
9 1.1 scw * Redistribution and use in source and binary forms, with or without
10 1.1 scw * modification, are permitted provided that the following conditions
11 1.1 scw * are met:
12 1.1 scw * 1. Redistributions of source code must retain the above copyright
13 1.1 scw * notice, this list of conditions and the following disclaimer.
14 1.1 scw * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 scw * notice, this list of conditions and the following disclaimer in the
16 1.1 scw * documentation and/or other materials provided with the distribution.
17 1.1 scw * 3. All advertising materials mentioning features or use of this software
18 1.1 scw * must display the following acknowledgement:
19 1.1 scw * This product includes software developed for the NetBSD Project by
20 1.1 scw * Wasabi Systems, Inc.
21 1.1 scw * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1 scw * or promote products derived from this software without specific prior
23 1.1 scw * written permission.
24 1.1 scw *
25 1.1 scw * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1 scw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 scw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 scw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1 scw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 scw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 scw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 scw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 scw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 scw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 scw * POSSIBILITY OF SUCH DAMAGE.
36 1.1 scw */
37 1.4 lukem
38 1.4 lukem #include <sys/cdefs.h>
39 1.7 kiyohara __KERNEL_RCSID(0, "$NetBSD: pxa2x0_com.c,v 1.7 2006/12/10 12:46:48 kiyohara Exp $");
40 1.1 scw
41 1.1 scw #include "opt_com.h"
42 1.1 scw
43 1.1 scw #ifndef COM_PXA2X0
44 1.1 scw #error "You must use options COM_PXA2X0 to get PXA2x0 serial port support"
45 1.1 scw #endif
46 1.1 scw
47 1.1 scw #include <sys/param.h>
48 1.1 scw #include <sys/systm.h>
49 1.1 scw #include <sys/device.h>
50 1.1 scw #include <sys/termios.h>
51 1.1 scw
52 1.1 scw #include <machine/intr.h>
53 1.1 scw #include <machine/bus.h>
54 1.1 scw
55 1.1 scw #include <dev/ic/comreg.h>
56 1.1 scw #include <dev/ic/comvar.h>
57 1.1 scw
58 1.1 scw #include <arm/xscale/pxa2x0reg.h>
59 1.1 scw #include <arm/xscale/pxa2x0var.h>
60 1.1 scw
61 1.1 scw #include "locators.h"
62 1.1 scw
63 1.1 scw static int pxauart_match(struct device *, struct cfdata *, void *);
64 1.1 scw static void pxauart_attach(struct device *, struct device *, void *);
65 1.1 scw
66 1.1 scw CFATTACH_DECL(pxauart, sizeof(struct com_softc),
67 1.1 scw pxauart_match, pxauart_attach, NULL, NULL);
68 1.1 scw
69 1.1 scw static int
70 1.1 scw pxauart_match(struct device *parent, struct cfdata *cf, void *aux)
71 1.1 scw {
72 1.1 scw struct pxaip_attach_args *pxa = aux;
73 1.1 scw bus_space_tag_t bt = &pxa2x0_a4x_bs_tag; /* XXX: This sucks */
74 1.1 scw bus_space_handle_t bh;
75 1.1 scw int rv;
76 1.1 scw
77 1.1 scw switch (pxa->pxa_addr) {
78 1.1 scw case PXA2X0_FFUART_BASE:
79 1.1 scw if (pxa->pxa_intr != PXA2X0_INT_FFUART)
80 1.1 scw return (0);
81 1.1 scw break;
82 1.1 scw
83 1.1 scw case PXA2X0_STUART_BASE:
84 1.1 scw if (pxa->pxa_intr != PXA2X0_INT_STUART)
85 1.1 scw return (0);
86 1.1 scw break;
87 1.1 scw
88 1.1 scw case PXA2X0_BTUART_BASE: /* XXX: Config file option ... */
89 1.1 scw if (pxa->pxa_intr != PXA2X0_INT_BTUART)
90 1.1 scw return (0);
91 1.1 scw break;
92 1.1 scw
93 1.7 kiyohara case PXA2X0_HWUART_BASE:
94 1.7 kiyohara if (pxa->pxa_intr != PXA2X0_INT_HWUART)
95 1.7 kiyohara return (0);
96 1.7 kiyohara break;
97 1.7 kiyohara
98 1.1 scw default:
99 1.1 scw return (0);
100 1.1 scw }
101 1.1 scw
102 1.1 scw pxa->pxa_size = 0x20;
103 1.1 scw
104 1.1 scw if (com_is_console(bt, pxa->pxa_addr, NULL))
105 1.1 scw return (1);
106 1.1 scw
107 1.1 scw if (bus_space_map(bt, pxa->pxa_addr, pxa->pxa_size, 0, &bh))
108 1.1 scw return (0);
109 1.1 scw
110 1.1 scw /* Make sure the UART is enabled */
111 1.1 scw bus_space_write_1(bt, bh, com_ier, IER_EUART);
112 1.1 scw
113 1.1 scw rv = comprobe1(bt, bh);
114 1.1 scw bus_space_unmap(bt, bh, pxa->pxa_size);
115 1.1 scw
116 1.1 scw return (rv);
117 1.1 scw }
118 1.1 scw
119 1.1 scw static void
120 1.1 scw pxauart_attach(struct device *parent, struct device *self, void *aux)
121 1.1 scw {
122 1.1 scw struct com_softc *sc = (struct com_softc *)self;
123 1.1 scw struct pxaip_attach_args *pxa = aux;
124 1.6 gdamore bus_space_tag_t iot;
125 1.6 gdamore bus_space_handle_t ioh;
126 1.6 gdamore bus_addr_t iobase;
127 1.1 scw
128 1.6 gdamore iot = &pxa2x0_a4x_bs_tag; /* XXX: This sucks */
129 1.6 gdamore iobase = pxa->pxa_addr;
130 1.1 scw sc->sc_frequency = PXA2X0_COM_FREQ;
131 1.2 thorpej sc->sc_type = COM_TYPE_PXA2x0;
132 1.1 scw
133 1.6 gdamore if (com_is_console(iot, iobase, &ioh) == 0 &&
134 1.6 gdamore bus_space_map(iot, iobase, pxa->pxa_size, 0, &ioh)) {
135 1.1 scw printf(": can't map registers\n");
136 1.1 scw return;
137 1.1 scw }
138 1.6 gdamore COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
139 1.1 scw
140 1.1 scw com_attach_subr(sc);
141 1.1 scw
142 1.1 scw pxa2x0_intr_establish(pxa->pxa_intr, IPL_SERIAL, comintr, sc);
143 1.1 scw }
144