Home | History | Annotate | Line # | Download | only in dev
ucb1200.c revision 1.6
      1  1.6  uch /*	$NetBSD: ucb1200.c,v 1.6 2001/09/15 12:47:07 uch Exp $ */
      2  1.1  uch 
      3  1.6  uch /*-
      4  1.6  uch  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  1.1  uch  * All rights reserved.
      6  1.1  uch  *
      7  1.6  uch  * This code is derived from software contributed to The NetBSD Foundation
      8  1.6  uch  * by UCHIYAMA Yasushi.
      9  1.6  uch  *
     10  1.1  uch  * Redistribution and use in source and binary forms, with or without
     11  1.1  uch  * modification, are permitted provided that the following conditions
     12  1.1  uch  * are met:
     13  1.1  uch  * 1. Redistributions of source code must retain the above copyright
     14  1.1  uch  *    notice, this list of conditions and the following disclaimer.
     15  1.6  uch  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.6  uch  *    notice, this list of conditions and the following disclaimer in the
     17  1.6  uch  *    documentation and/or other materials provided with the distribution.
     18  1.6  uch  * 3. All advertising materials mentioning features or use of this software
     19  1.6  uch  *    must display the following acknowledgement:
     20  1.6  uch  *        This product includes software developed by the NetBSD
     21  1.6  uch  *        Foundation, Inc. and its contributors.
     22  1.6  uch  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.6  uch  *    contributors may be used to endorse or promote products derived
     24  1.6  uch  *    from this software without specific prior written permission.
     25  1.1  uch  *
     26  1.6  uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.6  uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.6  uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.6  uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.6  uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.6  uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.6  uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.6  uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.6  uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.6  uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.6  uch  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  uch  */
     38  1.1  uch 
     39  1.1  uch /*
     40  1.1  uch  * Device driver for PHILIPS UCB1200 Advanced modem/audio analog front-end
     41  1.1  uch  */
     42  1.3  uch #define UCB1200DEBUG
     43  1.1  uch #include "opt_tx39_debug.h"
     44  1.1  uch 
     45  1.1  uch #include <sys/param.h>
     46  1.1  uch #include <sys/systm.h>
     47  1.1  uch #include <sys/device.h>
     48  1.1  uch 
     49  1.1  uch #include <machine/bus.h>
     50  1.1  uch #include <machine/intr.h>
     51  1.1  uch 
     52  1.1  uch #include <hpcmips/tx/tx39var.h>
     53  1.1  uch #include <hpcmips/tx/tx39sibvar.h>
     54  1.1  uch #include <hpcmips/tx/tx39sibreg.h>
     55  1.1  uch 
     56  1.1  uch #include <hpcmips/dev/ucb1200var.h>
     57  1.1  uch #include <hpcmips/dev/ucb1200reg.h>
     58  1.1  uch 
     59  1.1  uch #ifdef UCB1200DEBUG
     60  1.5  uch int	ucb1200debug = 1;
     61  1.3  uch #define	DPRINTF(arg) if (ucb1200debug) printf arg;
     62  1.3  uch #define	DPRINTFN(n, arg) if (ucb1200debug > (n)) printf arg;
     63  1.1  uch #else
     64  1.1  uch #define	DPRINTF(arg)
     65  1.2  uch #define DPRINTFN(n, arg)
     66  1.1  uch #endif
     67  1.1  uch 
     68  1.2  uch struct ucbchild_state {
     69  1.5  uch 	int (*cs_busy)(void *);
     70  1.2  uch 	void *cs_arg;
     71  1.2  uch };
     72  1.1  uch 
     73  1.2  uch struct ucb1200_softc {
     74  1.4  uch 	struct device	sc_dev;
     75  1.4  uch 	struct device	*sc_parent; /* parent (TX39 SIB module) */
     76  1.4  uch 	tx_chipset_tag_t sc_tc;
     77  1.2  uch 
     78  1.2  uch 	int		sc_snd_rate; /* passed down from SIB module */
     79  1.2  uch 	int		sc_tel_rate;
     80  1.1  uch 
     81  1.2  uch 	/* inquire child module state */
     82  1.2  uch 	struct ucbchild_state sc_child[UCB1200_MODULE_MAX];
     83  1.2  uch };
     84  1.1  uch 
     85  1.5  uch int	ucb1200_match(struct device *, struct cfdata *, void *);
     86  1.5  uch void	ucb1200_attach(struct device *, struct device *, void *);
     87  1.5  uch int	ucb1200_print(void *, const char *);
     88  1.5  uch int	ucb1200_search(struct device *, struct cfdata *, void *);
     89  1.5  uch int	ucb1200_check_id(u_int16_t, int);
     90  1.1  uch 
     91  1.3  uch #ifdef UCB1200DEBUG
     92  1.5  uch void	ucb1200_dump(struct ucb1200_softc *);
     93  1.3  uch #endif
     94  1.1  uch 
     95  1.1  uch struct cfattach ucb_ca = {
     96  1.1  uch 	sizeof(struct ucb1200_softc), ucb1200_match, ucb1200_attach
     97  1.1  uch };
     98  1.1  uch 
     99  1.4  uch const struct ucb_id {
    100  1.4  uch 	u_int16_t	id;
    101  1.4  uch 	const char	*product;
    102  1.4  uch } ucb_id[] = {
    103  1.4  uch 	{ UCB1100_ID,	"PHILIPS UCB1100" },
    104  1.4  uch 	{ UCB1200_ID,	"PHILIPS UCB1200" },
    105  1.4  uch 	{ UCB1300_ID,	"PHILIPS UCB1300" },
    106  1.4  uch 	{ TC35413F_ID,	"TOSHIBA TC35413F" },
    107  1.4  uch 	{ 0, 0 }
    108  1.4  uch };
    109  1.4  uch 
    110  1.1  uch int
    111  1.5  uch ucb1200_match(struct device *parent, struct cfdata *cf, void *aux)
    112  1.1  uch {
    113  1.1  uch 	struct txsib_attach_args *sa = aux;
    114  1.2  uch 	u_int16_t reg;
    115  1.1  uch 
    116  1.1  uch 	if (sa->sa_slot != 0) /* UCB1200 must be subframe 0 */
    117  1.6  uch 		return (0);
    118  1.2  uch 	reg = txsibsf0_reg_read(sa->sa_tc, UCB1200_ID_REG);
    119  1.2  uch 
    120  1.4  uch 	return (ucb1200_check_id(reg, 0));
    121  1.1  uch }
    122  1.1  uch 
    123  1.1  uch void
    124  1.5  uch ucb1200_attach(struct device *parent, struct device *self, void *aux)
    125  1.1  uch {
    126  1.1  uch 	struct txsib_attach_args *sa = aux;
    127  1.1  uch 	struct ucb1200_softc *sc = (void*)self;
    128  1.4  uch 	u_int16_t reg;
    129  1.1  uch 
    130  1.4  uch 	printf(": ");
    131  1.1  uch 	sc->sc_tc = sa->sa_tc;
    132  1.1  uch 	sc->sc_parent = parent;
    133  1.2  uch 	sc->sc_snd_rate = sa->sa_snd_rate;
    134  1.2  uch 	sc->sc_tel_rate = sa->sa_tel_rate;
    135  1.2  uch 
    136  1.2  uch 	tx39sib_enable1(sc->sc_parent);
    137  1.2  uch 	tx39sib_enable2(sc->sc_parent);
    138  1.1  uch 
    139  1.1  uch #ifdef UCB1200DEBUG
    140  1.3  uch 	if (ucb1200debug)
    141  1.3  uch 		ucb1200_dump(sc);
    142  1.1  uch #endif
    143  1.4  uch 	reg = txsibsf0_reg_read(sa->sa_tc, UCB1200_ID_REG);
    144  1.4  uch 	(void)ucb1200_check_id(reg, 1);
    145  1.1  uch 	printf("\n");
    146  1.1  uch 
    147  1.2  uch 	config_search(ucb1200_search, self, ucb1200_print);
    148  1.1  uch }
    149  1.1  uch 
    150  1.1  uch int
    151  1.5  uch ucb1200_search(struct device *parent, struct cfdata *cf, void *aux)
    152  1.1  uch {
    153  1.2  uch 	struct ucb1200_softc *sc = (void*)parent;
    154  1.2  uch 	struct ucb1200_attach_args ucba;
    155  1.1  uch 
    156  1.2  uch 	ucba.ucba_tc = sc->sc_tc;
    157  1.2  uch 	ucba.ucba_snd_rate = sc->sc_snd_rate;
    158  1.2  uch 	ucba.ucba_tel_rate = sc->sc_tel_rate;
    159  1.2  uch 	ucba.ucba_sib	   = sc->sc_parent;
    160  1.2  uch 	ucba.ucba_ucb	   = parent;
    161  1.1  uch 
    162  1.2  uch 	if ((*cf->cf_attach->ca_match)(parent, cf, &ucba))
    163  1.2  uch 		config_attach(parent, cf, &ucba, ucb1200_print);
    164  1.1  uch 
    165  1.6  uch 	return (0);
    166  1.1  uch }
    167  1.1  uch 
    168  1.1  uch int
    169  1.5  uch ucb1200_print(void *aux, const char *pnp)
    170  1.1  uch {
    171  1.6  uch 
    172  1.6  uch 	return (pnp ? QUIET : UNCONF);
    173  1.4  uch }
    174  1.4  uch 
    175  1.4  uch int
    176  1.5  uch ucb1200_check_id(u_int16_t idreg, int print)
    177  1.4  uch {
    178  1.4  uch 	int i;
    179  1.4  uch 
    180  1.4  uch 	for (i = 0; ucb_id[i].product; i++) {
    181  1.4  uch 		if (ucb_id[i].id == idreg) {
    182  1.4  uch 			if (print) {
    183  1.4  uch 				printf("%s", ucb_id[i].product);
    184  1.4  uch 			}
    185  1.4  uch 
    186  1.4  uch 			return (1);
    187  1.4  uch 		}
    188  1.4  uch 	}
    189  1.4  uch 
    190  1.6  uch 	return (0);
    191  1.1  uch }
    192  1.1  uch 
    193  1.1  uch void
    194  1.5  uch ucb1200_state_install(struct device *dev, int (*sfun)(void *), void *sarg,
    195  1.6  uch     int sid)
    196  1.1  uch {
    197  1.2  uch 	struct ucb1200_softc *sc = (void*)dev;
    198  1.1  uch 
    199  1.2  uch 	sc->sc_child[sid].cs_busy = sfun;
    200  1.2  uch 	sc->sc_child[sid].cs_arg = sarg;
    201  1.1  uch }
    202  1.1  uch 
    203  1.1  uch int
    204  1.2  uch ucb1200_state_idle(dev)
    205  1.2  uch 	struct device *dev;
    206  1.1  uch {
    207  1.2  uch 	struct ucb1200_softc *sc = (void*)dev;
    208  1.2  uch 	struct ucbchild_state *cs;
    209  1.2  uch 	int i;
    210  1.1  uch 
    211  1.2  uch 	cs = sc->sc_child;
    212  1.2  uch 	for (i = 0; i < UCB1200_MODULE_MAX; i++, cs++)
    213  1.2  uch 		if (cs->cs_busy)
    214  1.2  uch 			if ((*cs->cs_busy)(cs->cs_arg))
    215  1.6  uch 				return (0);
    216  1.2  uch 
    217  1.6  uch 	return (1); /* idle state */
    218  1.1  uch }
    219  1.1  uch 
    220  1.3  uch #ifdef UCB1200DEBUG
    221  1.1  uch void
    222  1.5  uch ucb1200_dump(struct ucb1200_softc *sc)
    223  1.1  uch {
    224  1.1  uch         const char *regname[] = {
    225  1.1  uch                 "IO_DATA        ",
    226  1.1  uch                 "IO_DIR         ",
    227  1.1  uch                 "POSINTEN       ",
    228  1.1  uch                 "NEGINTEN       ",
    229  1.1  uch                 "INTSTAT        ",
    230  1.1  uch                 "TELECOMCTRLA   ",
    231  1.1  uch                 "TELECOMCTRLB   ",
    232  1.1  uch                 "AUDIOCTRLA     ",
    233  1.1  uch                 "AUDIOCTRLB     ",
    234  1.1  uch                 "TOUCHSCREENCTRL",
    235  1.1  uch                 "ADCCTRL        ",
    236  1.1  uch                 "ADCDATA        ",
    237  1.1  uch                 "ID             ",
    238  1.1  uch                 "MODE           ",
    239  1.1  uch                 "RESERVED       ",
    240  1.1  uch                 "NULL           "
    241  1.1  uch         };
    242  1.5  uch 	tx_chipset_tag_t tc;
    243  1.1  uch 	u_int16_t reg;
    244  1.1  uch 	int i;
    245  1.5  uch 
    246  1.5  uch 	tc = sc->sc_tc;
    247  1.1  uch 
    248  1.2  uch 	printf("\n\t[UCB1200 register]\n");
    249  1.1  uch 	for (i = 0; i < 16; i++) {
    250  1.1  uch 		reg = txsibsf0_reg_read(tc, i);
    251  1.1  uch 		printf("%s(%02d) 0x%04x ", regname[i], i, reg);
    252  1.1  uch 		bitdisp(reg);
    253  1.1  uch 	}
    254  1.1  uch }
    255  1.3  uch #endif /* UCB1200DEBUG */
    256