pxa2x0_com.c revision 1.1 1 1.1 scw /* $NetBSD: pxa2x0_com.c,v 1.1 2003/06/05 13:48:27 scw 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.1 scw
38 1.1 scw #include "opt_com.h"
39 1.1 scw
40 1.1 scw #ifndef COM_PXA2X0
41 1.1 scw #error "You must use options COM_PXA2X0 to get PXA2x0 serial port support"
42 1.1 scw #endif
43 1.1 scw
44 1.1 scw #include <sys/param.h>
45 1.1 scw #include <sys/systm.h>
46 1.1 scw #include <sys/device.h>
47 1.1 scw #include <sys/termios.h>
48 1.1 scw
49 1.1 scw #include <machine/intr.h>
50 1.1 scw #include <machine/bus.h>
51 1.1 scw
52 1.1 scw #include <dev/ic/comreg.h>
53 1.1 scw #include <dev/ic/comvar.h>
54 1.1 scw
55 1.1 scw #include <arm/xscale/pxa2x0reg.h>
56 1.1 scw #include <arm/xscale/pxa2x0var.h>
57 1.1 scw
58 1.1 scw #include "locators.h"
59 1.1 scw
60 1.1 scw static int pxauart_match(struct device *, struct cfdata *, void *);
61 1.1 scw static void pxauart_attach(struct device *, struct device *, void *);
62 1.1 scw
63 1.1 scw CFATTACH_DECL(pxauart, sizeof(struct com_softc),
64 1.1 scw pxauart_match, pxauart_attach, NULL, NULL);
65 1.1 scw
66 1.1 scw static int
67 1.1 scw pxauart_match(struct device *parent, struct cfdata *cf, void *aux)
68 1.1 scw {
69 1.1 scw struct pxaip_attach_args *pxa = aux;
70 1.1 scw bus_space_tag_t bt = &pxa2x0_a4x_bs_tag; /* XXX: This sucks */
71 1.1 scw bus_space_handle_t bh;
72 1.1 scw int rv;
73 1.1 scw
74 1.1 scw switch (pxa->pxa_addr) {
75 1.1 scw case PXA2X0_FFUART_BASE:
76 1.1 scw if (pxa->pxa_intr != PXA2X0_INT_FFUART)
77 1.1 scw return (0);
78 1.1 scw break;
79 1.1 scw
80 1.1 scw case PXA2X0_STUART_BASE:
81 1.1 scw if (pxa->pxa_intr != PXA2X0_INT_STUART)
82 1.1 scw return (0);
83 1.1 scw break;
84 1.1 scw
85 1.1 scw #if 0
86 1.1 scw case PXA2X0_BTUART_BASE: /* XXX: Config file option ... */
87 1.1 scw if (pxa->pxa_intr != PXA2X0_INT_BTUART)
88 1.1 scw return (0);
89 1.1 scw break;
90 1.1 scw #endif
91 1.1 scw
92 1.1 scw default:
93 1.1 scw return (0);
94 1.1 scw }
95 1.1 scw
96 1.1 scw pxa->pxa_size = 0x20;
97 1.1 scw
98 1.1 scw if (com_is_console(bt, pxa->pxa_addr, NULL))
99 1.1 scw return (1);
100 1.1 scw
101 1.1 scw if (bus_space_map(bt, pxa->pxa_addr, pxa->pxa_size, 0, &bh))
102 1.1 scw return (0);
103 1.1 scw
104 1.1 scw /* Make sure the UART is enabled */
105 1.1 scw bus_space_write_1(bt, bh, com_ier, IER_EUART);
106 1.1 scw
107 1.1 scw rv = comprobe1(bt, bh);
108 1.1 scw bus_space_unmap(bt, bh, pxa->pxa_size);
109 1.1 scw
110 1.1 scw return (rv);
111 1.1 scw }
112 1.1 scw
113 1.1 scw static void
114 1.1 scw pxauart_attach(struct device *parent, struct device *self, void *aux)
115 1.1 scw {
116 1.1 scw struct com_softc *sc = (struct com_softc *)self;
117 1.1 scw struct pxaip_attach_args *pxa = aux;
118 1.1 scw
119 1.1 scw sc->sc_iot = &pxa2x0_a4x_bs_tag; /* XXX: This sucks */
120 1.1 scw sc->sc_iobase = pxa->pxa_addr;
121 1.1 scw sc->sc_frequency = PXA2X0_COM_FREQ;
122 1.1 scw sc->sc_hwflags = COM_HW_PXA2X0;
123 1.1 scw
124 1.1 scw if (com_is_console(sc->sc_iot, sc->sc_iobase, &sc->sc_ioh) == 0 &&
125 1.1 scw bus_space_map(sc->sc_iot, sc->sc_iobase, pxa->pxa_size, 0,
126 1.1 scw &sc->sc_ioh)) {
127 1.1 scw printf(": can't map registers\n");
128 1.1 scw return;
129 1.1 scw }
130 1.1 scw
131 1.1 scw com_attach_subr(sc);
132 1.1 scw
133 1.1 scw pxa2x0_intr_establish(pxa->pxa_intr, IPL_SERIAL, comintr, sc);
134 1.1 scw }
135