1 /* $NetBSD: tx39ir.c,v 1.8 2005/12/11 12:17:34 christos Exp $ */
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * TX39 IR module (connected to UARTB)
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: tx39ir.c,v 1.8 2005/12/11 12:17:34 christos Exp $");
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/device.h>
45 #include <machine/bus.h>
46 #include <machine/intr.h>
48 #include <hpcmips/tx/tx39var.h>
49 #include <hpcmips/tx/tx39icureg.h>
50 #include <hpcmips/tx/tx39irvar.h>
51 #include <hpcmips/tx/tx39irreg.h>
53 #include <hpcmips/tx/tx39clockreg.h> /* XXX */
57 #define DPRINTF(arg) if (vrpiu_debug) printf arg;
62 int tx39ir_match(struct device
*, struct cfdata
*, void *);
63 void tx39ir_attach(struct device
*, struct device
*, void *);
67 struct device
*sc_parent
;
68 tx_chipset_tag_t sc_tc
;
72 static void tx39ir_dump(struct tx39ir_softc
*);
75 static int tx39ir_intr(void *);
78 CFATTACH_DECL(tx39ir
, sizeof(struct tx39ir_softc
),
79 tx39ir_match
, tx39ir_attach
, NULL
, NULL
);
82 tx39ir_match(struct device
*parent
, struct cfdata
*cf
, void *aux
)
84 return (ATTACH_NORMAL
);
88 tx39ir_attach(struct device
*parent
, struct device
*self
, void *aux
)
90 struct txcom_attach_args
*tca
= aux
;
91 struct tx39ir_softc
*sc
= (void*)self
;
95 sc
->sc_tc
= tc
= tca
->tca_tc
;
96 sc
->sc_parent
= tca
->tca_parent
;
100 /* setup IR module */
101 reg
= tx_conf_read(tc
, TX39_IRCTRL1_REG
);
102 reg
|= TX39_IRCTRL1_RXPWR
;
103 tx_conf_write(tc
, TX39_IRCTRL1_REG
, reg
);
105 /* power up IR module */
106 reg
= tx_conf_read(tc
, TX39_CLOCKCTRL_REG
);
107 reg
|= TX39_CLOCK_ENIRCLK
| TX39_CLOCK_ENUARTBCLK
;
108 tx_conf_write(tc
, TX39_CLOCKCTRL_REG
, reg
);
110 /* turn to pulse mode UARTB */
111 txcom_pulse_mode(sc
->sc_parent
);
114 tx_intr_establish(tc
, MAKEINTR(5, TX39_INTRSTATUS5_CARSTINT
),
115 IST_EDGE
, IPL_TTY
, tx39ir_intr
, sc
);
116 tx_intr_establish(tc
, MAKEINTR(5, TX39_INTRSTATUS5_POSCARINT
),
117 IST_EDGE
, IPL_TTY
, tx39ir_intr
, sc
);
118 tx_intr_establish(tc
, MAKEINTR(5, TX39_INTRSTATUS5_NEGCARINT
),
119 IST_EDGE
, IPL_TTY
, tx39ir_intr
, sc
);
129 tx39ir_dump(struct tx39ir_softc
*sc
)
131 tx_chipset_tag_t tc
= sc
->sc_tc
;
134 reg
= tx_conf_read(tc
, TX39_IRCTRL1_REG
);
135 #define ISSETPRINT(r, m) dbg_bitmask_print((u_int32_t)(r), \
136 TX39_IRCTRL1_##m, #m)
137 ISSETPRINT(reg
, CARDET
);
138 ISSETPRINT(reg
, TESTIR
);
139 ISSETPRINT(reg
, DTINVERT
);
140 ISSETPRINT(reg
, RXPWR
);
141 ISSETPRINT(reg
, ENSTATE
);
142 ISSETPRINT(reg
, ENCOMSM
);
144 printf("baudval %d\n", TX39_IRCTRL1_BAUDVAL(reg
));
150 tx39ir_intr(void *arg
)