com_aubus.c revision 1.2.14.3 1 1.2.14.3 yamt /* $NetBSD: com_aubus.c,v 1.2.14.3 2007/09/03 14:27:53 yamt Exp $ */
2 1.2.14.2 yamt
3 1.2.14.2 yamt /*
4 1.2.14.2 yamt * Copyright 2001 Wasabi Systems, Inc.
5 1.2.14.2 yamt * All rights reserved.
6 1.2.14.2 yamt *
7 1.2.14.2 yamt * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
8 1.2.14.2 yamt *
9 1.2.14.2 yamt * Redistribution and use in source and binary forms, with or without
10 1.2.14.2 yamt * modification, are permitted provided that the following conditions
11 1.2.14.2 yamt * are met:
12 1.2.14.2 yamt * 1. Redistributions of source code must retain the above copyright
13 1.2.14.2 yamt * notice, this list of conditions and the following disclaimer.
14 1.2.14.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
15 1.2.14.2 yamt * notice, this list of conditions and the following disclaimer in the
16 1.2.14.2 yamt * documentation and/or other materials provided with the distribution.
17 1.2.14.2 yamt * 3. All advertising materials mentioning features or use of this software
18 1.2.14.2 yamt * must display the following acknowledgement:
19 1.2.14.2 yamt * This product includes software developed for the NetBSD Project by
20 1.2.14.2 yamt * Wasabi Systems, Inc.
21 1.2.14.2 yamt * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.2.14.2 yamt * or promote products derived from this software without specific prior
23 1.2.14.2 yamt * written permission.
24 1.2.14.2 yamt *
25 1.2.14.2 yamt * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.2.14.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.2.14.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.2.14.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.2.14.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.2.14.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.2.14.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.2.14.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.2.14.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.2.14.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.2.14.2 yamt * POSSIBILITY OF SUCH DAMAGE.
36 1.2.14.2 yamt */
37 1.2.14.2 yamt
38 1.2.14.2 yamt #include <sys/cdefs.h>
39 1.2.14.3 yamt __KERNEL_RCSID(0, "$NetBSD: com_aubus.c,v 1.2.14.3 2007/09/03 14:27:53 yamt Exp $");
40 1.2.14.2 yamt
41 1.2.14.2 yamt #include <sys/param.h>
42 1.2.14.2 yamt #include <sys/device.h>
43 1.2.14.3 yamt #include <sys/lwp.h>
44 1.2.14.2 yamt #include <sys/systm.h>
45 1.2.14.2 yamt #include <sys/tty.h>
46 1.2.14.2 yamt
47 1.2.14.2 yamt #include <machine/bus.h>
48 1.2.14.2 yamt #include <dev/ic/comvar.h>
49 1.2.14.2 yamt
50 1.2.14.2 yamt #include <mips/alchemy/include/aureg.h>
51 1.2.14.2 yamt #include <mips/alchemy/include/auvar.h>
52 1.2.14.2 yamt #include <mips/alchemy/include/aubusvar.h>
53 1.2.14.2 yamt #include <mips/alchemy/dev/com_aubus_reg.h>
54 1.2.14.2 yamt
55 1.2.14.2 yamt struct com_aubus_softc {
56 1.2.14.2 yamt struct com_softc sc_com;
57 1.2.14.2 yamt int sc_irq;
58 1.2.14.2 yamt void *sc_ih;
59 1.2.14.2 yamt };
60 1.2.14.2 yamt
61 1.2.14.2 yamt static int com_aubus_probe(struct device *, struct cfdata *, void *);
62 1.2.14.2 yamt static void com_aubus_attach(struct device *, struct device *, void *);
63 1.2.14.2 yamt static int com_aubus_enable(struct com_softc *);
64 1.2.14.2 yamt static void com_aubus_disable(struct com_softc *);
65 1.2.14.2 yamt static void com_aubus_initmap(struct com_regs *);
66 1.2.14.2 yamt
67 1.2.14.2 yamt CFATTACH_DECL(com_aubus, sizeof(struct com_aubus_softc),
68 1.2.14.2 yamt com_aubus_probe, com_aubus_attach, NULL, NULL);
69 1.2.14.2 yamt
70 1.2.14.2 yamt #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
71 1.2.14.2 yamt
72 1.2.14.2 yamt #ifndef COM_REGMAP
73 1.2.14.2 yamt #error COM_REGMAP not defined!
74 1.2.14.2 yamt #endif
75 1.2.14.2 yamt
76 1.2.14.2 yamt int
77 1.2.14.2 yamt com_aubus_probe(struct device *parent, struct cfdata *cf, void *aux)
78 1.2.14.2 yamt {
79 1.2.14.2 yamt struct aubus_attach_args *aa = aux;
80 1.2.14.2 yamt
81 1.2.14.2 yamt /* match only aucom devices */
82 1.2.14.2 yamt if (strcmp(aa->aa_name, cf->cf_name) == 0)
83 1.2.14.2 yamt return (1);
84 1.2.14.2 yamt
85 1.2.14.2 yamt return (0);
86 1.2.14.2 yamt }
87 1.2.14.2 yamt
88 1.2.14.2 yamt void
89 1.2.14.2 yamt com_aubus_attach(struct device *parent, struct device *self, void *aux)
90 1.2.14.2 yamt {
91 1.2.14.2 yamt struct com_aubus_softc *asc = (void *)self;
92 1.2.14.2 yamt struct com_softc *sc = &asc->sc_com;
93 1.2.14.2 yamt struct aubus_attach_args *aa = aux;
94 1.2.14.2 yamt int addr = aa->aa_addr;
95 1.2.14.2 yamt
96 1.2.14.2 yamt sc->sc_regs.cr_iot = aa->aa_st;
97 1.2.14.2 yamt sc->sc_regs.cr_iobase = addr;
98 1.2.14.2 yamt asc->sc_irq = aa->aa_irq[0];
99 1.2.14.2 yamt
100 1.2.14.2 yamt if (com_is_console(aa->aa_st, addr, &sc->sc_regs.cr_ioh) == 0 &&
101 1.2.14.2 yamt bus_space_map(aa->aa_st, addr, AUCOM_NPORTS, 0,
102 1.2.14.2 yamt &sc->sc_regs.cr_ioh) != 0) {
103 1.2.14.2 yamt printf(": can't map i/o space\n");
104 1.2.14.2 yamt return;
105 1.2.14.2 yamt }
106 1.2.14.2 yamt com_aubus_initmap(&sc->sc_regs);
107 1.2.14.2 yamt
108 1.2.14.2 yamt /*
109 1.2.14.2 yamt * The input to the clock divider is the internal pbus clock (1/4 the
110 1.2.14.2 yamt * processor frequency). The actual baud rate of the interface will
111 1.2.14.2 yamt * be pbus_freq / CLKDIV.
112 1.2.14.2 yamt */
113 1.2.14.2 yamt sc->sc_frequency = curcpu()->ci_cpu_freq / 4;
114 1.2.14.2 yamt
115 1.2.14.2 yamt sc->sc_hwflags = COM_HW_NO_TXPRELOAD;
116 1.2.14.2 yamt sc->sc_type = COM_TYPE_AU1x00;
117 1.2.14.2 yamt
118 1.2.14.2 yamt sc->enable = com_aubus_enable;
119 1.2.14.2 yamt sc->disable = com_aubus_disable;
120 1.2.14.2 yamt
121 1.2.14.2 yamt /* Enable UART so we can access it. */
122 1.2.14.2 yamt com_aubus_enable(sc);
123 1.2.14.2 yamt sc->enabled = 1;
124 1.2.14.2 yamt
125 1.2.14.2 yamt /* Attach MI com driver. */
126 1.2.14.2 yamt com_attach_subr(sc);
127 1.2.14.2 yamt
128 1.2.14.2 yamt /* Disable UART if it's not the console. (XXX kgdb?) */
129 1.2.14.2 yamt if (!ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
130 1.2.14.2 yamt com_aubus_disable(sc);
131 1.2.14.2 yamt sc->enabled = 0;
132 1.2.14.2 yamt }
133 1.2.14.2 yamt }
134 1.2.14.2 yamt
135 1.2.14.2 yamt int
136 1.2.14.2 yamt com_aubus_enable(struct com_softc *sc)
137 1.2.14.2 yamt {
138 1.2.14.2 yamt struct com_aubus_softc *asc = (void *)sc; /* XXX mi prototype */
139 1.2.14.2 yamt
140 1.2.14.2 yamt /* Ignore requests to enable an already enabled console. */
141 1.2.14.2 yamt if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE) && (asc->sc_ih != NULL))
142 1.2.14.2 yamt return (0);
143 1.2.14.2 yamt
144 1.2.14.2 yamt /* Enable the UART module. */
145 1.2.14.2 yamt bus_space_write_1(sc->sc_regs.cr_iot, sc->sc_regs.cr_ioh, AUCOM_MODCTL,
146 1.2.14.2 yamt UMC_ME | UMC_CE);
147 1.2.14.2 yamt
148 1.2.14.2 yamt /* Establish the interrupt. */
149 1.2.14.2 yamt asc->sc_ih = au_intr_establish(asc->sc_irq, 0, IPL_SERIAL, IST_LEVEL,
150 1.2.14.2 yamt comintr, sc);
151 1.2.14.2 yamt if (asc->sc_ih == NULL) {
152 1.2.14.2 yamt printf("%s: unable to establish interrupt\n",
153 1.2.14.2 yamt sc->sc_dev.dv_xname);
154 1.2.14.2 yamt return (1);
155 1.2.14.2 yamt }
156 1.2.14.2 yamt
157 1.2.14.2 yamt return (0);
158 1.2.14.2 yamt }
159 1.2.14.2 yamt
160 1.2.14.2 yamt void
161 1.2.14.2 yamt com_aubus_disable(struct com_softc *sc)
162 1.2.14.2 yamt {
163 1.2.14.2 yamt struct com_aubus_softc *asc = (void *)sc; /* XXX mi prototype */
164 1.2.14.2 yamt
165 1.2.14.2 yamt /* Ignore requests to disable the console. */
166 1.2.14.2 yamt if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE))
167 1.2.14.2 yamt return;
168 1.2.14.2 yamt
169 1.2.14.2 yamt /* Disestablish the interrupt. */
170 1.2.14.2 yamt au_intr_disestablish(asc->sc_ih);
171 1.2.14.2 yamt
172 1.2.14.2 yamt /* Disable the UART module. */
173 1.2.14.2 yamt bus_space_write_1(sc->sc_regs.cr_iot, sc->sc_regs.cr_ioh,
174 1.2.14.2 yamt AUCOM_MODCTL, 0);
175 1.2.14.2 yamt }
176 1.2.14.2 yamt
177 1.2.14.2 yamt void
178 1.2.14.2 yamt com_aubus_initmap(struct com_regs *regsp)
179 1.2.14.2 yamt {
180 1.2.14.2 yamt regsp->cr_nports = AUCOM_NPORTS;
181 1.2.14.2 yamt regsp->cr_map[COM_REG_RXDATA] = AUCOM_RXDATA;
182 1.2.14.2 yamt regsp->cr_map[COM_REG_TXDATA] = AUCOM_TXDATA;
183 1.2.14.2 yamt regsp->cr_map[COM_REG_DLBL] = AUCOM_DLB;
184 1.2.14.2 yamt regsp->cr_map[COM_REG_DLBH] = AUCOM_DLB;
185 1.2.14.2 yamt regsp->cr_map[COM_REG_IER] = AUCOM_IER;
186 1.2.14.2 yamt regsp->cr_map[COM_REG_IIR] = AUCOM_IIR;
187 1.2.14.2 yamt regsp->cr_map[COM_REG_FIFO] = AUCOM_FIFO;
188 1.2.14.2 yamt regsp->cr_map[COM_REG_EFR] = 0;
189 1.2.14.2 yamt regsp->cr_map[COM_REG_LCR] = AUCOM_LCTL;
190 1.2.14.2 yamt regsp->cr_map[COM_REG_MCR] = AUCOM_MCR;
191 1.2.14.2 yamt regsp->cr_map[COM_REG_LSR] = AUCOM_LSR;
192 1.2.14.2 yamt regsp->cr_map[COM_REG_MSR] = AUCOM_MSR;
193 1.2.14.2 yamt }
194 1.2.14.2 yamt
195 1.2.14.2 yamt int
196 1.2.14.2 yamt com_aubus_cnattach(bus_addr_t addr, int baud)
197 1.2.14.2 yamt {
198 1.2.14.2 yamt struct com_regs regs;
199 1.2.14.2 yamt uint32_t sysfreq;
200 1.2.14.2 yamt
201 1.2.14.2 yamt regs.cr_iot = aubus_st;
202 1.2.14.2 yamt regs.cr_iobase = addr;
203 1.2.14.2 yamt regs.cr_nports = AUCOM_NPORTS;
204 1.2.14.2 yamt com_aubus_initmap(®s);
205 1.2.14.2 yamt
206 1.2.14.2 yamt sysfreq = curcpu()->ci_cpu_freq / 4;
207 1.2.14.2 yamt
208 1.2.14.2 yamt return comcnattach1(®s, baud, sysfreq, COM_TYPE_AU1x00, CONMODE);
209 1.2.14.2 yamt }
210