Home | History | Annotate | Line # | Download | only in dev
slhci_intio.c revision 1.6
      1  1.6       he /*	$NetBSD: slhci_intio.c,v 1.6 2005/06/13 00:34:08 he Exp $	*/
      2  1.1    isaki 
      3  1.1    isaki /*
      4  1.1    isaki  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.1    isaki  * All rights reserved.
      6  1.1    isaki  *
      7  1.1    isaki  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1    isaki  * by Tetsuya Isaki.
      9  1.1    isaki  *
     10  1.1    isaki  * Redistribution and use in source and binary forms, with or without
     11  1.1    isaki  * modification, are permitted provided that the following conditions
     12  1.1    isaki  * are met:
     13  1.1    isaki  * 1. Redistributions of source code must retain the above copyright
     14  1.1    isaki  *    notice, this list of conditions and the following disclaimer.
     15  1.1    isaki  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1    isaki  *    notice, this list of conditions and the following disclaimer in the
     17  1.1    isaki  *    documentation and/or other materials provided with the distribution.
     18  1.1    isaki  * 3. All advertising materials mentioning features or use of this software
     19  1.1    isaki  *    must display the following acknowledgement:
     20  1.1    isaki  *      This product includes software developed by the NetBSD
     21  1.1    isaki  *      Foundation, Inc. and its contributors.
     22  1.1    isaki  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1    isaki  *    contributors may be used to endorse or promote products derived
     24  1.1    isaki  *    from this software without specific prior written permission.
     25  1.1    isaki  *
     26  1.1    isaki  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1    isaki  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1    isaki  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1    isaki  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1    isaki  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1    isaki  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1    isaki  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1    isaki  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1    isaki  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1    isaki  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1    isaki  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1    isaki  */
     38  1.1    isaki 
     39  1.1    isaki /*
     40  1.1    isaki  * USB part of Nereid Ethernet/USB/Memory board
     41  1.1    isaki  */
     42  1.5    lukem 
     43  1.5    lukem #include <sys/cdefs.h>
     44  1.6       he __KERNEL_RCSID(0, "$NetBSD: slhci_intio.c,v 1.6 2005/06/13 00:34:08 he Exp $");
     45  1.1    isaki 
     46  1.1    isaki #include <sys/param.h>
     47  1.1    isaki #include <sys/systm.h>
     48  1.1    isaki #include <sys/device.h>
     49  1.1    isaki 
     50  1.1    isaki #include <machine/bus.h>
     51  1.1    isaki #include <machine/cpu.h>
     52  1.1    isaki 
     53  1.1    isaki #include <dev/usb/usb.h>
     54  1.1    isaki #include <dev/usb/usbdi.h>
     55  1.1    isaki #include <dev/usb/usbdivar.h>
     56  1.1    isaki 
     57  1.1    isaki #include <dev/ic/sl811hsreg.h>
     58  1.1    isaki #include <dev/ic/sl811hsvar.h>
     59  1.1    isaki 
     60  1.1    isaki #include <arch/x68k/dev/intiovar.h>
     61  1.1    isaki 
     62  1.1    isaki #include <arch/x68k/dev/slhci_intio_var.h>
     63  1.1    isaki 
     64  1.1    isaki static int  slhci_intio_match(struct device *, struct cfdata *, void *);
     65  1.1    isaki static void slhci_intio_attach(struct device *, struct device *, void *);
     66  1.1    isaki static void slhci_intio_enable_power(void *, int);
     67  1.1    isaki static void slhci_intio_enable_intr(void *, int);
     68  1.1    isaki static int  slhci_intio_intr(void *);
     69  1.1    isaki 
     70  1.3  thorpej CFATTACH_DECL(slhci_intio, sizeof(struct slhci_intio_softc),
     71  1.4  thorpej     slhci_intio_match, slhci_intio_attach, NULL, NULL);
     72  1.1    isaki 
     73  1.1    isaki static int
     74  1.1    isaki slhci_intio_match(struct device *parent, struct cfdata *cf, void *aux)
     75  1.1    isaki {
     76  1.1    isaki 	struct intio_attach_args *ia = aux;
     77  1.1    isaki 	bus_space_tag_t iot = ia->ia_bst;
     78  1.1    isaki 	bus_space_handle_t ioh;
     79  1.1    isaki 	bus_space_handle_t nch;
     80  1.1    isaki 	int nc_addr;
     81  1.1    isaki 	int nc_size;
     82  1.1    isaki 
     83  1.1    isaki 	if (ia->ia_addr == INTIOCF_ADDR_DEFAULT)
     84  1.1    isaki 		ia->ia_addr = SLHCI_INTIO_ADDR1;
     85  1.1    isaki 	if (ia->ia_intr == INTIOCF_INTR_DEFAULT)
     86  1.1    isaki 		ia->ia_intr = SLHCI_INTIO_INTR1;
     87  1.1    isaki 
     88  1.1    isaki 	/* fixed parameters */
     89  1.1    isaki 	if ( !(ia->ia_addr == SLHCI_INTIO_ADDR1 &&
     90  1.1    isaki 	       ia->ia_intr == SLHCI_INTIO_INTR1   ) &&
     91  1.1    isaki 	     !(ia->ia_addr == SLHCI_INTIO_ADDR2 &&
     92  1.1    isaki 	       ia->ia_intr == SLHCI_INTIO_INTR2   ) )
     93  1.1    isaki 		return 0;
     94  1.1    isaki 
     95  1.1    isaki 	/* Whether the control port is accessible or not */
     96  1.1    isaki 	nc_addr = ia->ia_addr + NEREID_ADDR_OFFSET;
     97  1.1    isaki 	nc_size = 0x02;
     98  1.6       he 	if (badbaddr(INTIO_ADDR(nc_addr)))
     99  1.1    isaki 		return 0;
    100  1.1    isaki 
    101  1.1    isaki 	/* Map two I/O spaces */
    102  1.1    isaki 	ia->ia_size = SL11_PORTSIZE * 2;
    103  1.1    isaki 	if (bus_space_map(iot, ia->ia_addr, ia->ia_size,
    104  1.1    isaki 			BUS_SPACE_MAP_SHIFTED, &ioh))
    105  1.1    isaki 		return 0;
    106  1.1    isaki 
    107  1.1    isaki 	if (bus_space_map(iot, nc_addr, nc_size,
    108  1.1    isaki 			BUS_SPACE_MAP_SHIFTED, &nch))
    109  1.1    isaki 		return 0;
    110  1.1    isaki 
    111  1.1    isaki 	bus_space_unmap(iot, ioh, ia->ia_size);
    112  1.1    isaki 	bus_space_unmap(iot, nch, nc_size);
    113  1.1    isaki 
    114  1.1    isaki 	return 1;
    115  1.1    isaki }
    116  1.1    isaki 
    117  1.1    isaki static void
    118  1.1    isaki slhci_intio_attach(struct device *parent, struct device *self, void *aux)
    119  1.1    isaki {
    120  1.1    isaki 	struct slhci_intio_softc *sc = (struct slhci_intio_softc *)self;
    121  1.1    isaki 	struct intio_attach_args *ia = aux;
    122  1.1    isaki 	bus_space_tag_t iot = ia->ia_bst;
    123  1.1    isaki 	bus_space_handle_t ioh;
    124  1.1    isaki 	int nc_addr;
    125  1.1    isaki 	int nc_size;
    126  1.1    isaki 
    127  1.1    isaki 	printf(": Nereid USB\n");
    128  1.1    isaki 
    129  1.1    isaki 	/* Map I/O space */
    130  1.1    isaki 	if (bus_space_map(iot, ia->ia_addr, SL11_PORTSIZE * 2,
    131  1.1    isaki 			BUS_SPACE_MAP_SHIFTED, &ioh)) {
    132  1.1    isaki 		printf("%s: can't map I/O space\n",
    133  1.1    isaki 			sc->sc_sc.sc_bus.bdev.dv_xname);
    134  1.1    isaki 		return;
    135  1.1    isaki 	}
    136  1.1    isaki 
    137  1.1    isaki 	nc_addr = ia->ia_addr + NEREID_ADDR_OFFSET;
    138  1.1    isaki 	nc_size = 0x02;
    139  1.1    isaki 	if (bus_space_map(iot, nc_addr, nc_size,
    140  1.1    isaki 			BUS_SPACE_MAP_SHIFTED, &sc->sc_nch)) {
    141  1.1    isaki 		printf("%s: can't map I/O control space\n",
    142  1.1    isaki 			sc->sc_sc.sc_bus.bdev.dv_xname);
    143  1.1    isaki 		return;
    144  1.1    isaki 	}
    145  1.1    isaki 
    146  1.1    isaki 	/* Initialize sc */
    147  1.1    isaki 	sc->sc_sc.sc_iot = iot;
    148  1.1    isaki 	sc->sc_sc.sc_ioh = ioh;
    149  1.1    isaki 	sc->sc_sc.sc_dmat = ia->ia_dmat;
    150  1.1    isaki 	sc->sc_sc.sc_enable_power = slhci_intio_enable_power;
    151  1.1    isaki 	sc->sc_sc.sc_enable_intr  = slhci_intio_enable_intr;
    152  1.1    isaki 	sc->sc_sc.sc_arg = sc;
    153  1.1    isaki 
    154  1.1    isaki 	/* Establish the interrupt handler */
    155  1.1    isaki 	if (intio_intr_establish(ia->ia_intr, "slhci", slhci_intio_intr, sc)) {
    156  1.1    isaki 		printf("%s: can't establish interrupt\n",
    157  1.1    isaki 			sc->sc_sc.sc_bus.bdev.dv_xname);
    158  1.1    isaki 		return;
    159  1.1    isaki 	}
    160  1.1    isaki 
    161  1.1    isaki 	/* Reset controller */
    162  1.1    isaki 	bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL, NEREID_CTRL_RESET);
    163  1.1    isaki 	delay(40000);
    164  1.1    isaki 
    165  1.1    isaki 	/* Attach SL811HS/T */
    166  1.1    isaki 	if (slhci_attach(&sc->sc_sc, self))
    167  1.1    isaki 		return;
    168  1.1    isaki }
    169  1.1    isaki 
    170  1.1    isaki static void
    171  1.1    isaki slhci_intio_enable_power(void *arg, int mode)
    172  1.1    isaki {
    173  1.1    isaki 	struct slhci_intio_softc *sc = arg;
    174  1.1    isaki 	bus_space_tag_t iot = sc->sc_sc.sc_iot;
    175  1.1    isaki 	u_int8_t r;
    176  1.1    isaki 
    177  1.1    isaki 	r = bus_space_read_1(iot, sc->sc_nch, NEREID_CTRL);
    178  1.1    isaki 	if (mode == POWER_ON)
    179  1.1    isaki 		bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
    180  1.1    isaki 			r |  NEREID_CTRL_POWER);
    181  1.1    isaki 	else
    182  1.1    isaki 		bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
    183  1.1    isaki 			r & ~NEREID_CTRL_POWER);
    184  1.1    isaki }
    185  1.1    isaki 
    186  1.1    isaki static void
    187  1.1    isaki slhci_intio_enable_intr(void *arg, int mode)
    188  1.1    isaki {
    189  1.1    isaki 	struct slhci_intio_softc *sc = arg;
    190  1.1    isaki 	bus_space_tag_t iot = sc->sc_sc.sc_iot;
    191  1.1    isaki 	u_int8_t r;
    192  1.1    isaki 
    193  1.1    isaki 	r = bus_space_read_1(iot, sc->sc_nch, NEREID_CTRL);
    194  1.1    isaki 	if (mode == INTR_ON)
    195  1.1    isaki 		bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
    196  1.1    isaki 			r |  NEREID_CTRL_INTR);
    197  1.1    isaki 	else
    198  1.1    isaki 		bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
    199  1.1    isaki 			r & ~NEREID_CTRL_INTR);
    200  1.1    isaki }
    201  1.1    isaki 
    202  1.1    isaki static int
    203  1.1    isaki slhci_intio_intr(void *arg)
    204  1.1    isaki {
    205  1.1    isaki 	struct slhci_intio_softc *sc = arg;
    206  1.1    isaki 
    207  1.1    isaki 	return slhci_intr(&sc->sc_sc);
    208  1.1    isaki }
    209