tx39ir.c revision 1.1.8.1       1 /*	$NetBSD: tx39ir.c,v 1.1.8.1 2001/06/21 19:24:31 nathanw 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 #include "opt_tx39_debug.h"
     44 
     45 #include <sys/param.h>
     46 #include <sys/systm.h>
     47 #include <sys/device.h>
     48 
     49 #include <machine/bus.h>
     50 #include <machine/intr.h>
     51 
     52 #include <hpcmips/tx/tx39var.h>
     53 #include <hpcmips/tx/tx39icureg.h>
     54 #include <hpcmips/tx/tx39irvar.h>
     55 #include <hpcmips/tx/tx39irreg.h>
     56 
     57 #include <hpcmips/tx/tx39clockreg.h> /* XXX */
     58 
     59 #ifdef TX39IRDEBUG
     60 int	tx39ir_debug = 1;
     61 #define	DPRINTF(arg) if (vrpiu_debug) printf arg;
     62 #else
     63 #define	DPRINTF(arg)
     64 #endif
     65 
     66 int	tx39ir_match(struct device *, struct cfdata *, void *);
     67 void	tx39ir_attach(struct device *, struct device *, void *);
     68 
     69 struct tx39ir_softc {
     70 	struct	device sc_dev;
     71 	struct	device *sc_parent;
     72 	tx_chipset_tag_t sc_tc;
     73 };
     74 
     75 static void	tx39ir_dump(struct tx39ir_softc *);
     76 static int	tx39ir_intr(void *);
     77 
     78 struct cfattach tx39ir_ca = {
     79 	sizeof(struct tx39ir_softc), tx39ir_match, tx39ir_attach
     80 };
     81 
     82 int
     83 tx39ir_match(struct device *parent, struct cfdata *cf, void *aux)
     84 {
     85 	return (ATTACH_NORMAL);
     86 }
     87 
     88 void
     89 tx39ir_attach(struct device *parent, struct device *self, void *aux)
     90 {
     91 	struct txcom_attach_args *tca = aux;
     92 	struct tx39ir_softc *sc = (void*)self;
     93 	tx_chipset_tag_t tc;
     94 	txreg_t reg;
     95 
     96 	sc->sc_tc = tc = tca->tca_tc;
     97 	sc->sc_parent = tca->tca_parent;
     98 
     99 	printf("\n");
    100 
    101 	/* setup IR module */
    102 	reg = tx_conf_read(tc, TX39_IRCTRL1_REG);
    103 	reg |= TX39_IRCTRL1_RXPWR;
    104 	tx_conf_write(tc, TX39_IRCTRL1_REG, reg);
    105 
    106 	/* power up IR module */
    107 	reg = tx_conf_read(tc, TX39_CLOCKCTRL_REG);
    108 	reg |= TX39_CLOCK_ENIRCLK | TX39_CLOCK_ENUARTBCLK;
    109 	tx_conf_write(tc, TX39_CLOCKCTRL_REG, reg);
    110 
    111 	/* turn to pulse mode UARTB */
    112 	txcom_pulse_mode(sc->sc_parent);
    113 
    114 #if not_required_yet
    115 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_CARSTINT),
    116 	    IST_EDGE, IPL_TTY, tx39ir_intr, sc);
    117 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSCARINT),
    118 	    IST_EDGE, IPL_TTY, tx39ir_intr, sc);
    119 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGCARINT),
    120 	    IST_EDGE, IPL_TTY, tx39ir_intr, sc);
    121 #endif
    122 
    123 #ifdef TX39IRDEBUG
    124 	tx39ir_dump(sc);
    125 #endif
    126 }
    127 
    128 void
    129 tx39ir_dump(struct tx39ir_softc *sc)
    130 {
    131 	tx_chipset_tag_t tc = sc->sc_tc;
    132 	txreg_t reg;
    133 
    134 	reg = tx_conf_read(tc, TX39_IRCTRL1_REG);
    135 #define ISSETPRINT(r, m) __is_set_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);
    143 #undef	ISSETPRINT
    144 	printf("baudval %d\n", TX39_IRCTRL1_BAUDVAL(reg));
    145 }
    146 
    147 int
    148 tx39ir_intr(void *arg)
    149 {
    150 	return (0);
    151 }
    152