Home | History | Annotate | Line # | Download | only in dev
slhci_intio.c revision 1.8
      1  1.8  kiyohara /*	$NetBSD: slhci_intio.c,v 1.8 2007/08/15 03:53:09 kiyohara 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.8  kiyohara __KERNEL_RCSID(0, "$NetBSD: slhci_intio.c,v 1.8 2007/08/15 03:53:09 kiyohara 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.8  kiyohara static void slhci_intio_enable_power(void *, enum power_change);
     67  1.1     isaki static void slhci_intio_enable_intr(void *, int);
     68  1.1     isaki 
     69  1.3   thorpej CFATTACH_DECL(slhci_intio, sizeof(struct slhci_intio_softc),
     70  1.4   thorpej     slhci_intio_match, slhci_intio_attach, NULL, NULL);
     71  1.1     isaki 
     72  1.8  kiyohara #define INTR_ON 	1
     73  1.8  kiyohara #define INTR_OFF 	0
     74  1.8  kiyohara 
     75  1.1     isaki static int
     76  1.1     isaki slhci_intio_match(struct device *parent, struct cfdata *cf, void *aux)
     77  1.1     isaki {
     78  1.1     isaki 	struct intio_attach_args *ia = aux;
     79  1.1     isaki 	bus_space_tag_t iot = ia->ia_bst;
     80  1.1     isaki 	bus_space_handle_t ioh;
     81  1.1     isaki 	bus_space_handle_t nch;
     82  1.1     isaki 	int nc_addr;
     83  1.1     isaki 	int nc_size;
     84  1.1     isaki 
     85  1.1     isaki 	if (ia->ia_addr == INTIOCF_ADDR_DEFAULT)
     86  1.1     isaki 		ia->ia_addr = SLHCI_INTIO_ADDR1;
     87  1.1     isaki 	if (ia->ia_intr == INTIOCF_INTR_DEFAULT)
     88  1.1     isaki 		ia->ia_intr = SLHCI_INTIO_INTR1;
     89  1.1     isaki 
     90  1.1     isaki 	/* fixed parameters */
     91  1.1     isaki 	if ( !(ia->ia_addr == SLHCI_INTIO_ADDR1 &&
     92  1.1     isaki 	       ia->ia_intr == SLHCI_INTIO_INTR1   ) &&
     93  1.1     isaki 	     !(ia->ia_addr == SLHCI_INTIO_ADDR2 &&
     94  1.1     isaki 	       ia->ia_intr == SLHCI_INTIO_INTR2   ) )
     95  1.1     isaki 		return 0;
     96  1.1     isaki 
     97  1.1     isaki 	/* Whether the control port is accessible or not */
     98  1.1     isaki 	nc_addr = ia->ia_addr + NEREID_ADDR_OFFSET;
     99  1.1     isaki 	nc_size = 0x02;
    100  1.6        he 	if (badbaddr(INTIO_ADDR(nc_addr)))
    101  1.1     isaki 		return 0;
    102  1.1     isaki 
    103  1.1     isaki 	/* Map two I/O spaces */
    104  1.1     isaki 	ia->ia_size = SL11_PORTSIZE * 2;
    105  1.1     isaki 	if (bus_space_map(iot, ia->ia_addr, ia->ia_size,
    106  1.1     isaki 			BUS_SPACE_MAP_SHIFTED, &ioh))
    107  1.1     isaki 		return 0;
    108  1.1     isaki 
    109  1.1     isaki 	if (bus_space_map(iot, nc_addr, nc_size,
    110  1.1     isaki 			BUS_SPACE_MAP_SHIFTED, &nch))
    111  1.1     isaki 		return 0;
    112  1.1     isaki 
    113  1.1     isaki 	bus_space_unmap(iot, ioh, ia->ia_size);
    114  1.1     isaki 	bus_space_unmap(iot, nch, nc_size);
    115  1.1     isaki 
    116  1.1     isaki 	return 1;
    117  1.1     isaki }
    118  1.1     isaki 
    119  1.1     isaki static void
    120  1.1     isaki slhci_intio_attach(struct device *parent, struct device *self, void *aux)
    121  1.1     isaki {
    122  1.1     isaki 	struct slhci_intio_softc *sc = (struct slhci_intio_softc *)self;
    123  1.1     isaki 	struct intio_attach_args *ia = aux;
    124  1.1     isaki 	bus_space_tag_t iot = ia->ia_bst;
    125  1.1     isaki 	bus_space_handle_t ioh;
    126  1.1     isaki 	int nc_addr;
    127  1.1     isaki 	int nc_size;
    128  1.1     isaki 
    129  1.1     isaki 	printf(": Nereid USB\n");
    130  1.1     isaki 
    131  1.1     isaki 	/* Map I/O space */
    132  1.1     isaki 	if (bus_space_map(iot, ia->ia_addr, SL11_PORTSIZE * 2,
    133  1.1     isaki 			BUS_SPACE_MAP_SHIFTED, &ioh)) {
    134  1.1     isaki 		printf("%s: can't map I/O space\n",
    135  1.1     isaki 			sc->sc_sc.sc_bus.bdev.dv_xname);
    136  1.1     isaki 		return;
    137  1.1     isaki 	}
    138  1.1     isaki 
    139  1.1     isaki 	nc_addr = ia->ia_addr + NEREID_ADDR_OFFSET;
    140  1.1     isaki 	nc_size = 0x02;
    141  1.1     isaki 	if (bus_space_map(iot, nc_addr, nc_size,
    142  1.1     isaki 			BUS_SPACE_MAP_SHIFTED, &sc->sc_nch)) {
    143  1.1     isaki 		printf("%s: can't map I/O control space\n",
    144  1.1     isaki 			sc->sc_sc.sc_bus.bdev.dv_xname);
    145  1.1     isaki 		return;
    146  1.1     isaki 	}
    147  1.1     isaki 
    148  1.1     isaki 	/* Initialize sc */
    149  1.8  kiyohara 	slhci_preinit(&sc->sc_sc, slhci_intio_enable_power, iot, ioh, 30,
    150  1.8  kiyohara 	    SL11_IDX_DATA);
    151  1.1     isaki 
    152  1.1     isaki 	/* Establish the interrupt handler */
    153  1.8  kiyohara 	if (intio_intr_establish(ia->ia_intr, "slhci", slhci_intr, sc)) {
    154  1.1     isaki 		printf("%s: can't establish interrupt\n",
    155  1.1     isaki 			sc->sc_sc.sc_bus.bdev.dv_xname);
    156  1.1     isaki 		return;
    157  1.1     isaki 	}
    158  1.1     isaki 
    159  1.1     isaki 	/* Reset controller */
    160  1.1     isaki 	bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL, NEREID_CTRL_RESET);
    161  1.1     isaki 	delay(40000);
    162  1.1     isaki 
    163  1.8  kiyohara 	slhci_intio_enable_intr(sc, INTR_ON);
    164  1.8  kiyohara 
    165  1.1     isaki 	/* Attach SL811HS/T */
    166  1.8  kiyohara 	if (slhci_attach(&sc->sc_sc))
    167  1.1     isaki 		return;
    168  1.1     isaki }
    169  1.1     isaki 
    170  1.1     isaki static void
    171  1.8  kiyohara slhci_intio_enable_power(void *arg, enum power_change 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