Home | History | Annotate | Line # | Download | only in dev
ucbio.c revision 1.10.6.1
      1  1.10.6.1      mjf /*	$NetBSD: ucbio.c,v 1.10.6.1 2008/06/02 13:22:10 mjf Exp $	*/
      2       1.1      uch 
      3       1.2      uch /*-
      4       1.2      uch  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5       1.1      uch  * All rights reserved.
      6       1.1      uch  *
      7       1.2      uch  * This code is derived from software contributed to The NetBSD Foundation
      8       1.2      uch  * by UCHIYAMA Yasushi.
      9       1.2      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.2      uch  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.2      uch  *    notice, this list of conditions and the following disclaimer in the
     17       1.2      uch  *    documentation and/or other materials provided with the distribution.
     18       1.1      uch  *
     19       1.2      uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.2      uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.2      uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.2      uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.2      uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.2      uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.2      uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.2      uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.2      uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.2      uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.2      uch  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1      uch  */
     31       1.1      uch 
     32       1.1      uch /*
     33       1.1      uch  * Device driver for PHILIPS UCB1200 Advanced modem/audio analog front-end
     34       1.1      uch  *	General Purpose I/O part.
     35       1.1      uch  */
     36       1.8    lukem 
     37       1.8    lukem #include <sys/cdefs.h>
     38  1.10.6.1      mjf __KERNEL_RCSID(0, "$NetBSD: ucbio.c,v 1.10.6.1 2008/06/02 13:22:10 mjf Exp $");
     39       1.1      uch 
     40       1.1      uch #include <sys/param.h>
     41       1.1      uch #include <sys/systm.h>
     42       1.1      uch #include <sys/device.h>
     43       1.1      uch 
     44       1.1      uch #include <machine/bus.h>
     45       1.1      uch #include <machine/intr.h>
     46       1.1      uch 
     47       1.1      uch #include <hpcmips/tx/tx39var.h>
     48       1.1      uch #include <hpcmips/tx/tx39sibvar.h>
     49       1.1      uch #include <hpcmips/tx/tx39sibreg.h>
     50       1.1      uch 
     51       1.1      uch #include <hpcmips/dev/ucb1200var.h>
     52       1.1      uch #include <hpcmips/dev/ucb1200reg.h>
     53       1.1      uch 
     54       1.3      uch #include <dev/hpc/hpciovar.h>	/* I/O manager */
     55       1.3      uch 
     56       1.5      uch #include <machine/debug.h>
     57       1.5      uch 
     58       1.2      uch int ucbio_match(struct device*, struct cfdata *, void *);
     59       1.2      uch void ucbio_attach(struct device*, struct device *, void *);
     60       1.1      uch 
     61       1.2      uch struct betty_port_status {
     62       1.2      uch 	u_int16_t dir;
     63       1.2      uch 	u_int16_t in, out;
     64       1.2      uch };
     65       1.1      uch 
     66       1.2      uch struct ucbio_softc {
     67       1.2      uch 	struct device sc_dev;
     68       1.2      uch 	tx_chipset_tag_t sc_tc;
     69       1.1      uch 
     70       1.2      uch 	struct betty_port_status sc_stat, sc_ostat;
     71       1.3      uch 	struct hpcio_chip sc_hc;
     72       1.1      uch };
     73       1.1      uch 
     74       1.7  thorpej CFATTACH_DECL(ucbio, sizeof(struct ucbio_softc),
     75       1.7  thorpej     ucbio_match, ucbio_attach, NULL, NULL);
     76       1.1      uch 
     77       1.2      uch /* I/O */
     78       1.3      uch static int betty_in(hpcio_chip_t, int);
     79       1.3      uch static void betty_out(hpcio_chip_t, int, int);
     80       1.2      uch /* interrupt */
     81       1.3      uch static hpcio_intr_handle_t betty_intr_establish(hpcio_chip_t, int, int,
     82       1.3      uch     int (*)(void *), void *);
     83       1.3      uch static void betty_intr_disestablish(hpcio_chip_t, void *);
     84       1.2      uch /* debug */
     85       1.3      uch static void betty_update(hpcio_chip_t);
     86       1.3      uch static void betty_dump(hpcio_chip_t);
     87       1.1      uch 
     88       1.1      uch int
     89       1.2      uch ucbio_match(struct device *parent, struct cfdata *cf, void *aux)
     90       1.1      uch {
     91       1.3      uch 	return (1);
     92       1.1      uch }
     93       1.1      uch 
     94       1.1      uch void
     95       1.2      uch ucbio_attach(struct device *parent, struct device *self, void *aux)
     96       1.1      uch {
     97       1.1      uch 	struct ucb1200_attach_args *ucba = aux;
     98       1.2      uch 	struct ucbio_softc *sc = (void *)self;
     99       1.3      uch 	struct hpcio_chip *hc = &sc->sc_hc;
    100       1.1      uch 
    101       1.2      uch 	sc->sc_tc = ucba->ucba_tc;
    102       1.1      uch 	printf("\n");
    103       1.2      uch 
    104       1.3      uch 	hc->hc_sc		 = sc;
    105       1.3      uch 	hc->hc_chipid		 = 2;
    106       1.3      uch 	hc->hc_name		 = "UCB1200";
    107       1.3      uch 	hc->hc_portread		 = betty_in;
    108       1.3      uch 	hc->hc_portwrite	 = betty_out;
    109       1.3      uch 	hc->hc_intr_establish	 = betty_intr_establish;
    110       1.3      uch 	hc->hc_intr_disestablish = betty_intr_disestablish;
    111       1.3      uch 	hc->hc_update		 = betty_update;
    112       1.3      uch 	hc->hc_dump		 = betty_dump;
    113       1.2      uch 
    114       1.3      uch 	tx_conf_register_ioman(sc->sc_tc, hc);
    115       1.2      uch 
    116       1.3      uch 	hpcio_update(hc);
    117       1.3      uch 	hpcio_dump(hc);
    118       1.2      uch }
    119       1.2      uch 
    120       1.2      uch /* basic I/O */
    121       1.2      uch static void
    122       1.3      uch betty_out(hpcio_chip_t hc, int port, int onoff)
    123       1.2      uch {
    124       1.3      uch 	struct ucbio_softc *sc = hc->hc_sc;
    125       1.2      uch 	tx_chipset_tag_t tc = sc->sc_tc;
    126       1.2      uch 	txreg_t reg, pos;
    127       1.2      uch 
    128       1.2      uch 	pos = 1 << port;
    129       1.2      uch 	reg = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
    130       1.2      uch 	if (onoff)
    131       1.2      uch 		reg |= pos;
    132       1.2      uch 	else
    133       1.2      uch 		reg &= ~pos;
    134       1.2      uch 	txsibsf0_reg_write(tc, UCB1200_IO_DATA_REG, reg);
    135       1.2      uch }
    136       1.2      uch 
    137       1.2      uch static int
    138       1.3      uch betty_in(hpcio_chip_t hc, int port)
    139       1.2      uch {
    140       1.3      uch 	struct ucbio_softc *sc = hc->hc_sc;
    141       1.2      uch 	tx_chipset_tag_t tc = sc->sc_tc;
    142       1.2      uch 	txreg_t reg = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
    143       1.3      uch 
    144       1.3      uch 	return (reg & (1 << port));
    145       1.1      uch }
    146       1.1      uch 
    147       1.2      uch /* interrupt method not implemented */
    148       1.3      uch static hpcio_intr_handle_t
    149       1.3      uch betty_intr_establish(hpcio_chip_t hc, int port, int mode, int (*func)(void *),
    150       1.3      uch     void *func_arg)
    151       1.1      uch {
    152       1.3      uch 	struct ucbio_softc *sc = hc->hc_sc;
    153       1.1      uch 
    154       1.2      uch 	printf("%s: %s not implemented.\n", sc->sc_dev.dv_xname,
    155      1.10    perry 	    __func__);
    156       1.3      uch 
    157       1.3      uch 	return (0);
    158       1.2      uch }
    159       1.1      uch 
    160       1.2      uch static void
    161       1.3      uch betty_intr_disestablish(hpcio_chip_t hc, void *ih)
    162       1.2      uch {
    163       1.3      uch 	struct ucbio_softc *sc = hc->hc_sc;
    164       1.3      uch 
    165       1.2      uch 	printf("%s: %s not implemented.\n", sc->sc_dev.dv_xname,
    166      1.10    perry 	    __func__);
    167       1.1      uch }
    168       1.1      uch 
    169       1.2      uch /* debug */
    170       1.2      uch static void
    171       1.3      uch betty_update(hpcio_chip_t hc)
    172       1.1      uch {
    173       1.3      uch 	struct ucbio_softc *sc = hc->hc_sc;
    174       1.2      uch 	tx_chipset_tag_t tc = sc->sc_tc;
    175       1.2      uch 	struct betty_port_status *stat = &sc->sc_stat;
    176       1.2      uch 	u_int16_t dir, data;
    177       1.1      uch 
    178       1.2      uch 	sc->sc_ostat = *stat; /* save old status */
    179       1.2      uch 	dir = stat->dir = txsibsf0_reg_read(tc, UCB1200_IO_DIR_REG);
    180       1.2      uch 	data = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
    181       1.2      uch 	stat->out = data & dir;
    182       1.2      uch 	stat->in = data & ~dir;
    183       1.2      uch }
    184       1.2      uch 
    185       1.2      uch static void
    186       1.3      uch betty_dump(hpcio_chip_t hc)
    187       1.2      uch {
    188       1.5      uch #ifdef UCBIO_DEBUG
    189       1.3      uch 	struct ucbio_softc *sc = hc->hc_sc;
    190       1.2      uch 	struct betty_port_status *stat = &sc->sc_stat;
    191       1.2      uch 
    192       1.2      uch 	printf("[BETTY I/O]\n");
    193       1.2      uch 	printf("IN  ");
    194       1.5      uch 	dbg_bit_print(stat->in);
    195       1.2      uch 	printf("OUT ");
    196       1.5      uch 	dbg_bit_print(stat->out);
    197       1.2      uch 	printf("DIR ");
    198       1.5      uch 	dbg_bit_print(stat->dir);
    199       1.5      uch #endif /* UCBIO_DEBUG */
    200       1.1      uch }
    201