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