xref: /netbsd/sys/arch/hpcmips/tx/tx39ir.c (revision bf9ec67e)
1 /*	$NetBSD: tx39ir.c,v 1.4 2002/01/29 18:53:17 uch 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 struct cfattach tx39ir_ca = {
82 	sizeof(struct tx39ir_softc), tx39ir_match, tx39ir_attach
83 };
84 
85 int
86 tx39ir_match(struct device *parent, struct cfdata *cf, void *aux)
87 {
88 	return (ATTACH_NORMAL);
89 }
90 
91 void
92 tx39ir_attach(struct device *parent, struct device *self, void *aux)
93 {
94 	struct txcom_attach_args *tca = aux;
95 	struct tx39ir_softc *sc = (void*)self;
96 	tx_chipset_tag_t tc;
97 	txreg_t reg;
98 
99 	sc->sc_tc = tc = tca->tca_tc;
100 	sc->sc_parent = tca->tca_parent;
101 
102 	printf("\n");
103 
104 	/* setup IR module */
105 	reg = tx_conf_read(tc, TX39_IRCTRL1_REG);
106 	reg |= TX39_IRCTRL1_RXPWR;
107 	tx_conf_write(tc, TX39_IRCTRL1_REG, reg);
108 
109 	/* power up IR module */
110 	reg = tx_conf_read(tc, TX39_CLOCKCTRL_REG);
111 	reg |= TX39_CLOCK_ENIRCLK | TX39_CLOCK_ENUARTBCLK;
112 	tx_conf_write(tc, TX39_CLOCKCTRL_REG, reg);
113 
114 	/* turn to pulse mode UARTB */
115 	txcom_pulse_mode(sc->sc_parent);
116 
117 #if not_required_yet
118 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_CARSTINT),
119 	    IST_EDGE, IPL_TTY, tx39ir_intr, sc);
120 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSCARINT),
121 	    IST_EDGE, IPL_TTY, tx39ir_intr, sc);
122 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGCARINT),
123 	    IST_EDGE, IPL_TTY, tx39ir_intr, sc);
124 #endif
125 
126 #ifdef TX39IRDEBUG
127 	tx39ir_dump(sc);
128 #endif
129 }
130 
131 #ifdef TX39IRDEBUG
132 void
133 tx39ir_dump(struct tx39ir_softc *sc)
134 {
135 	tx_chipset_tag_t tc = sc->sc_tc;
136 	txreg_t reg;
137 
138 	reg = tx_conf_read(tc, TX39_IRCTRL1_REG);
139 #define ISSETPRINT(r, m) dbg_bitmask_print((u_int32_t)(r),			\
140 	TX39_IRCTRL1_##m, #m)
141 	ISSETPRINT(reg, CARDET);
142 	ISSETPRINT(reg, TESTIR);
143 	ISSETPRINT(reg, DTINVERT);
144 	ISSETPRINT(reg, RXPWR);
145 	ISSETPRINT(reg, ENSTATE);
146 	ISSETPRINT(reg, ENCOMSM);
147 #undef	ISSETPRINT
148 	printf("baudval %d\n", TX39_IRCTRL1_BAUDVAL(reg));
149 }
150 #endif
151 
152 #if not_required_yet
153 int
154 tx39ir_intr(void *arg)
155 {
156 	return (0);
157 }
158 #endif
159