tx39ir.c revision 1.2.2.3 1 /* $NetBSD: tx39ir.c,v 1.2.2.3 2002/10/10 18:32:59 jdolecek Exp $ */
2
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * TX39 IR module (connected to UARTB)
41 */
42 #undef TX39IRDEBUG
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/device.h>
47
48 #include <machine/bus.h>
49 #include <machine/intr.h>
50
51 #include <hpcmips/tx/tx39var.h>
52 #include <hpcmips/tx/tx39icureg.h>
53 #include <hpcmips/tx/tx39irvar.h>
54 #include <hpcmips/tx/tx39irreg.h>
55
56 #include <hpcmips/tx/tx39clockreg.h> /* XXX */
57
58 #ifdef TX39IRDEBUG
59 int tx39ir_debug = 1;
60 #define DPRINTF(arg) if (vrpiu_debug) printf arg;
61 #else
62 #define DPRINTF(arg)
63 #endif
64
65 int tx39ir_match(struct device *, struct cfdata *, void *);
66 void tx39ir_attach(struct device *, struct device *, void *);
67
68 struct tx39ir_softc {
69 struct device sc_dev;
70 struct device *sc_parent;
71 tx_chipset_tag_t sc_tc;
72 };
73
74 #ifdef TX39IRDEBUG
75 static void tx39ir_dump(struct tx39ir_softc *);
76 #endif
77 #if not_required_yet
78 static int tx39ir_intr(void *);
79 #endif
80
81 CFATTACH_DECL(tx39ir, sizeof(struct tx39ir_softc),
82 tx39ir_match, tx39ir_attach, NULL, NULL);
83
84 int
85 tx39ir_match(struct device *parent, struct cfdata *cf, void *aux)
86 {
87 return (ATTACH_NORMAL);
88 }
89
90 void
91 tx39ir_attach(struct device *parent, struct device *self, void *aux)
92 {
93 struct txcom_attach_args *tca = aux;
94 struct tx39ir_softc *sc = (void*)self;
95 tx_chipset_tag_t tc;
96 txreg_t reg;
97
98 sc->sc_tc = tc = tca->tca_tc;
99 sc->sc_parent = tca->tca_parent;
100
101 printf("\n");
102
103 /* setup IR module */
104 reg = tx_conf_read(tc, TX39_IRCTRL1_REG);
105 reg |= TX39_IRCTRL1_RXPWR;
106 tx_conf_write(tc, TX39_IRCTRL1_REG, reg);
107
108 /* power up IR module */
109 reg = tx_conf_read(tc, TX39_CLOCKCTRL_REG);
110 reg |= TX39_CLOCK_ENIRCLK | TX39_CLOCK_ENUARTBCLK;
111 tx_conf_write(tc, TX39_CLOCKCTRL_REG, reg);
112
113 /* turn to pulse mode UARTB */
114 txcom_pulse_mode(sc->sc_parent);
115
116 #if not_required_yet
117 tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_CARSTINT),
118 IST_EDGE, IPL_TTY, tx39ir_intr, sc);
119 tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSCARINT),
120 IST_EDGE, IPL_TTY, tx39ir_intr, sc);
121 tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGCARINT),
122 IST_EDGE, IPL_TTY, tx39ir_intr, sc);
123 #endif
124
125 #ifdef TX39IRDEBUG
126 tx39ir_dump(sc);
127 #endif
128 }
129
130 #ifdef TX39IRDEBUG
131 void
132 tx39ir_dump(struct tx39ir_softc *sc)
133 {
134 tx_chipset_tag_t tc = sc->sc_tc;
135 txreg_t reg;
136
137 reg = tx_conf_read(tc, TX39_IRCTRL1_REG);
138 #define ISSETPRINT(r, m) dbg_bitmask_print((u_int32_t)(r), \
139 TX39_IRCTRL1_##m, #m)
140 ISSETPRINT(reg, CARDET);
141 ISSETPRINT(reg, TESTIR);
142 ISSETPRINT(reg, DTINVERT);
143 ISSETPRINT(reg, RXPWR);
144 ISSETPRINT(reg, ENSTATE);
145 ISSETPRINT(reg, ENCOMSM);
146 #undef ISSETPRINT
147 printf("baudval %d\n", TX39_IRCTRL1_BAUDVAL(reg));
148 }
149 #endif
150
151 #if not_required_yet
152 int
153 tx39ir_intr(void *arg)
154 {
155 return (0);
156 }
157 #endif
158