Home | History | Annotate | Line # | Download | only in dev
slhci_intio.c revision 1.9.18.1
      1 /*	$NetBSD: slhci_intio.c,v 1.9.18.1 2008/05/18 12:33:00 yamt Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Tetsuya Isaki.
      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  * USB part of Nereid Ethernet/USB/Memory board
     34  */
     35 
     36 #include <sys/cdefs.h>
     37 __KERNEL_RCSID(0, "$NetBSD: slhci_intio.c,v 1.9.18.1 2008/05/18 12:33:00 yamt Exp $");
     38 
     39 #include <sys/param.h>
     40 #include <sys/systm.h>
     41 #include <sys/device.h>
     42 
     43 #include <machine/bus.h>
     44 #include <machine/cpu.h>
     45 
     46 #include <dev/usb/usb.h>
     47 #include <dev/usb/usbdi.h>
     48 #include <dev/usb/usbdivar.h>
     49 
     50 #include <dev/ic/sl811hsreg.h>
     51 #include <dev/ic/sl811hsvar.h>
     52 
     53 #include <arch/x68k/dev/intiovar.h>
     54 
     55 #include <arch/x68k/dev/slhci_intio_var.h>
     56 
     57 static int  slhci_intio_match(struct device *, struct cfdata *, void *);
     58 static void slhci_intio_attach(struct device *, struct device *, void *);
     59 static void slhci_intio_enable_power(void *, enum power_change);
     60 static void slhci_intio_enable_intr(void *, int);
     61 
     62 CFATTACH_DECL(slhci_intio, sizeof(struct slhci_intio_softc),
     63     slhci_intio_match, slhci_intio_attach, NULL, NULL);
     64 
     65 #define INTR_ON 	1
     66 #define INTR_OFF 	0
     67 
     68 static int
     69 slhci_intio_match(struct device *parent, struct cfdata *cf, void *aux)
     70 {
     71 	struct intio_attach_args *ia = aux;
     72 	bus_space_tag_t iot = ia->ia_bst;
     73 	bus_space_handle_t ioh;
     74 	bus_space_handle_t nch;
     75 	int nc_addr;
     76 	int nc_size;
     77 
     78 	if (ia->ia_addr == INTIOCF_ADDR_DEFAULT)
     79 		ia->ia_addr = SLHCI_INTIO_ADDR1;
     80 	if (ia->ia_intr == INTIOCF_INTR_DEFAULT)
     81 		ia->ia_intr = SLHCI_INTIO_INTR1;
     82 
     83 	/* fixed parameters */
     84 	if ( !(ia->ia_addr == SLHCI_INTIO_ADDR1 &&
     85 	       ia->ia_intr == SLHCI_INTIO_INTR1   ) &&
     86 	     !(ia->ia_addr == SLHCI_INTIO_ADDR2 &&
     87 	       ia->ia_intr == SLHCI_INTIO_INTR2   ) )
     88 		return 0;
     89 
     90 	/* Whether the control port is accessible or not */
     91 	nc_addr = ia->ia_addr + NEREID_ADDR_OFFSET;
     92 	nc_size = 0x02;
     93 	if (badbaddr(INTIO_ADDR(nc_addr)))
     94 		return 0;
     95 
     96 	/* Map two I/O spaces */
     97 	ia->ia_size = SL11_PORTSIZE * 2;
     98 	if (bus_space_map(iot, ia->ia_addr, ia->ia_size,
     99 			BUS_SPACE_MAP_SHIFTED, &ioh))
    100 		return 0;
    101 
    102 	if (bus_space_map(iot, nc_addr, nc_size,
    103 			BUS_SPACE_MAP_SHIFTED, &nch))
    104 		return 0;
    105 
    106 	bus_space_unmap(iot, ioh, ia->ia_size);
    107 	bus_space_unmap(iot, nch, nc_size);
    108 
    109 	return 1;
    110 }
    111 
    112 static void
    113 slhci_intio_attach(struct device *parent, struct device *self, void *aux)
    114 {
    115 	struct slhci_intio_softc *sc = (struct slhci_intio_softc *)self;
    116 	struct intio_attach_args *ia = aux;
    117 	bus_space_tag_t iot = ia->ia_bst;
    118 	bus_space_handle_t ioh;
    119 	int nc_addr;
    120 	int nc_size;
    121 
    122 	printf(": Nereid USB\n");
    123 
    124 	/* Map I/O space */
    125 	if (bus_space_map(iot, ia->ia_addr, SL11_PORTSIZE * 2,
    126 			BUS_SPACE_MAP_SHIFTED, &ioh)) {
    127 		printf("%s: can't map I/O space\n",
    128 			sc->sc_sc.sc_bus.bdev.dv_xname);
    129 		return;
    130 	}
    131 
    132 	nc_addr = ia->ia_addr + NEREID_ADDR_OFFSET;
    133 	nc_size = 0x02;
    134 	if (bus_space_map(iot, nc_addr, nc_size,
    135 			BUS_SPACE_MAP_SHIFTED, &sc->sc_nch)) {
    136 		printf("%s: can't map I/O control space\n",
    137 			sc->sc_sc.sc_bus.bdev.dv_xname);
    138 		return;
    139 	}
    140 
    141 	/* Initialize sc */
    142 	slhci_preinit(&sc->sc_sc, slhci_intio_enable_power, iot, ioh, 30,
    143 	    SL11_IDX_DATA);
    144 
    145 	/* Establish the interrupt handler */
    146 	if (intio_intr_establish(ia->ia_intr, "slhci", slhci_intr, sc)) {
    147 		printf("%s: can't establish interrupt\n",
    148 			sc->sc_sc.sc_bus.bdev.dv_xname);
    149 		return;
    150 	}
    151 
    152 	/* Reset controller */
    153 	bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL, NEREID_CTRL_RESET);
    154 	delay(40000);
    155 
    156 	slhci_intio_enable_intr(sc, INTR_ON);
    157 
    158 	/* Attach SL811HS/T */
    159 	if (slhci_attach(&sc->sc_sc))
    160 		return;
    161 }
    162 
    163 static void
    164 slhci_intio_enable_power(void *arg, enum power_change mode)
    165 {
    166 	struct slhci_intio_softc *sc = arg;
    167 	bus_space_tag_t iot = sc->sc_sc.sc_iot;
    168 	u_int8_t r;
    169 
    170 	r = bus_space_read_1(iot, sc->sc_nch, NEREID_CTRL);
    171 	if (mode == POWER_ON)
    172 		bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
    173 			r |  NEREID_CTRL_POWER);
    174 	else
    175 		bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
    176 			r & ~NEREID_CTRL_POWER);
    177 }
    178 
    179 static void
    180 slhci_intio_enable_intr(void *arg, int mode)
    181 {
    182 	struct slhci_intio_softc *sc = arg;
    183 	bus_space_tag_t iot = sc->sc_sc.sc_iot;
    184 	u_int8_t r;
    185 
    186 	r = bus_space_read_1(iot, sc->sc_nch, NEREID_CTRL);
    187 	if (mode == INTR_ON)
    188 		bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
    189 			r |  NEREID_CTRL_INTR);
    190 	else
    191 		bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
    192 			r & ~NEREID_CTRL_INTR);
    193 }
    194 
    195