tx39ir.c revision 1.9.34.1       1 /*	$NetBSD: tx39ir.c,v 1.9.34.1 2012/10/30 17:19:45 yamt 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  *
     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.
     30  */
     31 
     32 /*
     33  * TX39 IR module (connected to UARTB)
     34  */
     35 
     36 #include <sys/cdefs.h>
     37 __KERNEL_RCSID(0, "$NetBSD: tx39ir.c,v 1.9.34.1 2012/10/30 17:19:45 yamt Exp $");
     38 
     39 #undef TX39IRDEBUG
     40 
     41 #include <sys/param.h>
     42 #include <sys/systm.h>
     43 #include <sys/device.h>
     44 
     45 #include <machine/bus.h>
     46 #include <machine/intr.h>
     47 
     48 #include <hpcmips/tx/tx39var.h>
     49 #include <hpcmips/tx/tx39icureg.h>
     50 #include <hpcmips/tx/tx39irvar.h>
     51 #include <hpcmips/tx/tx39irreg.h>
     52 
     53 #include <hpcmips/tx/tx39clockreg.h> /* XXX */
     54 
     55 #ifdef TX39IRDEBUG
     56 int	tx39ir_debug = 1;
     57 #define	DPRINTF(arg) if (vrpiu_debug) printf arg;
     58 #else
     59 #define	DPRINTF(arg)
     60 #endif
     61 
     62 int	tx39ir_match(device_t, cfdata_t, void *);
     63 void	tx39ir_attach(device_t, device_t, void *);
     64 
     65 struct tx39ir_softc {
     66 	device_t sc_parent;
     67 	tx_chipset_tag_t sc_tc;
     68 };
     69 
     70 #ifdef TX39IRDEBUG
     71 static void	tx39ir_dump(struct tx39ir_softc *);
     72 #endif
     73 #if not_required_yet
     74 static int	tx39ir_intr(void *);
     75 #endif
     76 
     77 CFATTACH_DECL_NEW(tx39ir, sizeof(struct tx39ir_softc),
     78     tx39ir_match, tx39ir_attach, NULL, NULL);
     79 
     80 int
     81 tx39ir_match(device_t parent, cfdata_t cf, void *aux)
     82 {
     83 	return (ATTACH_NORMAL);
     84 }
     85 
     86 void
     87 tx39ir_attach(device_t parent, device_t self, void *aux)
     88 {
     89 	struct txcom_attach_args *tca = aux;
     90 	struct tx39ir_softc *sc = device_private(self);
     91 	tx_chipset_tag_t tc;
     92 	txreg_t reg;
     93 
     94 	sc->sc_tc = tc = tca->tca_tc;
     95 	sc->sc_parent = tca->tca_parent;
     96 
     97 	printf("\n");
     98 
     99 	/* setup IR module */
    100 	reg = tx_conf_read(tc, TX39_IRCTRL1_REG);
    101 	reg |= TX39_IRCTRL1_RXPWR;
    102 	tx_conf_write(tc, TX39_IRCTRL1_REG, reg);
    103 
    104 	/* power up IR module */
    105 	reg = tx_conf_read(tc, TX39_CLOCKCTRL_REG);
    106 	reg |= TX39_CLOCK_ENIRCLK | TX39_CLOCK_ENUARTBCLK;
    107 	tx_conf_write(tc, TX39_CLOCKCTRL_REG, reg);
    108 
    109 	/* turn to pulse mode UARTB */
    110 	txcom_pulse_mode(sc->sc_parent);
    111 
    112 #if not_required_yet
    113 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_CARSTINT),
    114 	    IST_EDGE, IPL_TTY, tx39ir_intr, sc);
    115 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSCARINT),
    116 	    IST_EDGE, IPL_TTY, tx39ir_intr, sc);
    117 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGCARINT),
    118 	    IST_EDGE, IPL_TTY, tx39ir_intr, sc);
    119 #endif
    120 
    121 #ifdef TX39IRDEBUG
    122 	tx39ir_dump(sc);
    123 #endif
    124 }
    125 
    126 #ifdef TX39IRDEBUG
    127 void
    128 tx39ir_dump(struct tx39ir_softc *sc)
    129 {
    130 	tx_chipset_tag_t tc = sc->sc_tc;
    131 	txreg_t reg;
    132 
    133 	reg = tx_conf_read(tc, TX39_IRCTRL1_REG);
    134 #define ISSETPRINT(r, m) dbg_bitmask_print((u_int32_t)(r),			\
    135 	TX39_IRCTRL1_##m, #m)
    136 	ISSETPRINT(reg, CARDET);
    137 	ISSETPRINT(reg, TESTIR);
    138 	ISSETPRINT(reg, DTINVERT);
    139 	ISSETPRINT(reg, RXPWR);
    140 	ISSETPRINT(reg, ENSTATE);
    141 	ISSETPRINT(reg, ENCOMSM);
    142 #undef	ISSETPRINT
    143 	printf("baudval %d\n", TX39_IRCTRL1_BAUDVAL(reg));
    144 }
    145 #endif
    146 
    147 #if not_required_yet
    148 int
    149 tx39ir_intr(void *arg)
    150 {
    151 	return (0);
    152 }
    153 #endif
    154