plcom_ifpga.c revision 1.1.4.4 1 1.1.4.4 jdolecek /* $NetBSD: plcom_ifpga.c,v 1.1.4.4 2002/10/10 18:32:24 jdolecek Exp $ */
2 1.1.4.2 thorpej
3 1.1.4.2 thorpej /*
4 1.1.4.2 thorpej * Copyright (c) 2001 ARM Ltd
5 1.1.4.2 thorpej * All rights reserved.
6 1.1.4.2 thorpej *
7 1.1.4.2 thorpej * Redistribution and use in source and binary forms, with or without
8 1.1.4.2 thorpej * modification, are permitted provided that the following conditions
9 1.1.4.2 thorpej * are met:
10 1.1.4.2 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.1.4.2 thorpej * notice, this list of conditions and the following disclaimer.
12 1.1.4.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.4.2 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.1.4.2 thorpej * documentation and/or other materials provided with the distribution.
15 1.1.4.2 thorpej * 3. The name of the company may not be used to endorse or promote
16 1.1.4.2 thorpej * products derived from this software without specific prior written
17 1.1.4.2 thorpej * permission.
18 1.1.4.2 thorpej *
19 1.1.4.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 1.1.4.2 thorpej * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 1.1.4.2 thorpej * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 1.1.4.2 thorpej * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 1.1.4.2 thorpej * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 1.1.4.2 thorpej * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 1.1.4.2 thorpej * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1.4.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1.4.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1.4.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1.4.2 thorpej * SUCH DAMAGE.
30 1.1.4.2 thorpej */
31 1.1.4.2 thorpej
32 1.1.4.2 thorpej /* Interface to plcom (PL010) serial driver. */
33 1.1.4.2 thorpej
34 1.1.4.2 thorpej #include <sys/types.h>
35 1.1.4.2 thorpej #include <sys/device.h>
36 1.1.4.2 thorpej #include <sys/systm.h>
37 1.1.4.2 thorpej #include <sys/param.h>
38 1.1.4.2 thorpej #include <sys/malloc.h>
39 1.1.4.2 thorpej
40 1.1.4.2 thorpej #include <sys/termios.h>
41 1.1.4.2 thorpej
42 1.1.4.2 thorpej #include <machine/intr.h>
43 1.1.4.3 jdolecek #include <evbarm/ifpga/irqhandler.h> /* XXX XXX XXX */
44 1.1.4.2 thorpej #include <machine/bus.h>
45 1.1.4.2 thorpej
46 1.1.4.2 thorpej #include <evbarm/dev/plcomreg.h>
47 1.1.4.2 thorpej #include <evbarm/dev/plcomvar.h>
48 1.1.4.2 thorpej
49 1.1.4.2 thorpej #include <evbarm/ifpga/plcom_ifpgavar.h>
50 1.1.4.2 thorpej
51 1.1.4.2 thorpej #include <evbarm/ifpga/ifpgareg.h>
52 1.1.4.2 thorpej #include <evbarm/ifpga/ifpgavar.h>
53 1.1.4.2 thorpej
54 1.1.4.2 thorpej static int plcom_ifpga_match(struct device *, struct cfdata *, void *);
55 1.1.4.2 thorpej static void plcom_ifpga_attach(struct device *, struct device *, void *);
56 1.1.4.2 thorpej static void plcom_ifpga_set_mcr(void *, int, u_int);
57 1.1.4.2 thorpej
58 1.1.4.4 jdolecek CFATTACH_DECL(plcom_ifpga, sizeof(struct plcom_softc),
59 1.1.4.4 jdolecek plcom_ifpga_match, plcom_ifpga_attach, NULL, NULL);
60 1.1.4.2 thorpej
61 1.1.4.2 thorpej static int
62 1.1.4.2 thorpej plcom_ifpga_match(struct device *parent, struct cfdata *cf, void *aux)
63 1.1.4.2 thorpej {
64 1.1.4.4 jdolecek return 1;
65 1.1.4.2 thorpej }
66 1.1.4.2 thorpej
67 1.1.4.2 thorpej static void
68 1.1.4.2 thorpej plcom_ifpga_attach(struct device *parent, struct device *self, void *aux)
69 1.1.4.2 thorpej {
70 1.1.4.2 thorpej struct plcom_ifpga_softc *isc = (struct plcom_ifpga_softc *)self;
71 1.1.4.2 thorpej struct plcom_softc *sc = &isc->sc_plcom;
72 1.1.4.2 thorpej struct ifpga_attach_args *ifa = aux;
73 1.1.4.2 thorpej char *irqname;
74 1.1.4.2 thorpej
75 1.1.4.2 thorpej isc->sc_iot = ifa->ifa_iot;
76 1.1.4.2 thorpej isc->sc_ioh = ifa->ifa_sc_ioh;
77 1.1.4.2 thorpej sc->sc_iounit = sc->sc_dev.dv_unit;
78 1.1.4.2 thorpej sc->sc_frequency = IFPGA_UART_CLK;
79 1.1.4.2 thorpej sc->sc_iot = ifa->ifa_iot;
80 1.1.4.2 thorpej sc->sc_hwflags = 0;
81 1.1.4.2 thorpej sc->sc_swflags = 0;
82 1.1.4.2 thorpej sc->sc_set_mcr = plcom_ifpga_set_mcr;
83 1.1.4.2 thorpej sc->sc_set_mcr_arg = (void *)isc;
84 1.1.4.2 thorpej
85 1.1.4.2 thorpej if (bus_space_map(ifa->ifa_iot, ifa->ifa_addr, PLCOM_UART_SIZE, 0,
86 1.1.4.2 thorpej &sc->sc_ioh)) {
87 1.1.4.2 thorpej printf("%s: unable to map device\n", sc->sc_dev.dv_xname);
88 1.1.4.2 thorpej return;
89 1.1.4.2 thorpej }
90 1.1.4.2 thorpej
91 1.1.4.2 thorpej plcom_attach_subr(sc);
92 1.1.4.2 thorpej irqname = malloc(sizeof("uart") + 2, M_DEVBUF, M_WAITOK);
93 1.1.4.2 thorpej sprintf(irqname, "uart%d", sc->sc_dev.dv_unit);
94 1.1.4.2 thorpej isc->sc_ih = intr_claim(ifa->ifa_irq, IPL_SERIAL, irqname, plcomintr,
95 1.1.4.2 thorpej sc);
96 1.1.4.2 thorpej if (isc->sc_ih == NULL)
97 1.1.4.4 jdolecek panic("%s: cannot install interrupt handler",
98 1.1.4.2 thorpej sc->sc_dev.dv_xname);
99 1.1.4.2 thorpej }
100 1.1.4.2 thorpej
101 1.1.4.2 thorpej static void plcom_ifpga_set_mcr(void *aux, int unit, u_int mcr)
102 1.1.4.2 thorpej {
103 1.1.4.2 thorpej struct plcom_ifpga_softc *isc = (struct plcom_ifpga_softc *)aux;
104 1.1.4.2 thorpej u_int set, clr;
105 1.1.4.2 thorpej
106 1.1.4.2 thorpej set = clr = 0;
107 1.1.4.2 thorpej
108 1.1.4.2 thorpej switch (unit) {
109 1.1.4.2 thorpej case 0:
110 1.1.4.2 thorpej if (mcr & MCR_RTS)
111 1.1.4.2 thorpej set |= IFPGA_SC_CTRL_UART0RTS;
112 1.1.4.2 thorpej else
113 1.1.4.2 thorpej clr |= IFPGA_SC_CTRL_UART0RTS;
114 1.1.4.2 thorpej if (mcr & MCR_DTR)
115 1.1.4.2 thorpej set |= IFPGA_SC_CTRL_UART0DTR;
116 1.1.4.2 thorpej else
117 1.1.4.2 thorpej clr |= IFPGA_SC_CTRL_UART0DTR;
118 1.1.4.2 thorpej case 1:
119 1.1.4.2 thorpej if (mcr & MCR_RTS)
120 1.1.4.2 thorpej set |= IFPGA_SC_CTRL_UART1RTS;
121 1.1.4.2 thorpej else
122 1.1.4.2 thorpej clr |= IFPGA_SC_CTRL_UART1RTS;
123 1.1.4.2 thorpej if (mcr & MCR_DTR)
124 1.1.4.2 thorpej set |= IFPGA_SC_CTRL_UART1DTR;
125 1.1.4.2 thorpej else
126 1.1.4.2 thorpej clr |= IFPGA_SC_CTRL_UART1DTR;
127 1.1.4.2 thorpej default:
128 1.1.4.2 thorpej return;
129 1.1.4.2 thorpej }
130 1.1.4.2 thorpej
131 1.1.4.2 thorpej if (set)
132 1.1.4.2 thorpej bus_space_write_1(isc->sc_iot, isc->sc_ioh, IFPGA_SC_CTRLS,
133 1.1.4.2 thorpej set);
134 1.1.4.2 thorpej if (clr)
135 1.1.4.2 thorpej bus_space_write_1(isc->sc_iot, isc->sc_ioh, IFPGA_SC_CTRLC,
136 1.1.4.2 thorpej clr);
137 1.1.4.2 thorpej }
138