Home | History | Annotate | Line # | Download | only in g42xxeb
gb225_slhci.c revision 1.3
      1 /*	$NetBSD: gb225_slhci.c,v 1.3 2006/02/23 05:37:47 thorpej 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  * SL811HS USB host controller for GB-225 Option board of G4250EBX.
     41  */
     42 
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/device.h>
     46 
     47 #include <machine/bus.h>
     48 #include <machine/cpu.h>
     49 
     50 #include <dev/usb/usb.h>
     51 #include <dev/usb/usbdi.h>
     52 #include <dev/usb/usbdivar.h>
     53 
     54 #include <dev/ic/sl811hsreg.h>
     55 #include <dev/ic/sl811hsvar.h>
     56 
     57 #include <arch/arm/xscale/pxa2x0reg.h>
     58 #include <arch/arm/xscale/pxa2x0var.h>
     59 #include <arch/evbarm/g42xxeb/g42xxeb_reg.h>
     60 #include <arch/evbarm/g42xxeb/g42xxeb_var.h>
     61 #include <arch/evbarm/g42xxeb/gb225reg.h>
     62 #include <arch/evbarm/g42xxeb/gb225var.h>
     63 
     64 struct slhci_opio_softc {
     65 	struct slhci_softc sc_sc;
     66 
     67 	void *sc_ih;
     68 };
     69 
     70 static int  slhci_opio_match(struct device *, struct cfdata *, void *);
     71 static void slhci_opio_attach(struct device *, struct device *, void *);
     72 static void slhci_opio_enable_power(void *, int);
     73 static void slhci_opio_enable_intr(void *, int);
     74 static int  slhci_opio_intr(void *);
     75 
     76 CFATTACH_DECL(slhci_opio, sizeof(struct slhci_opio_softc),
     77     slhci_opio_match, slhci_opio_attach, NULL, NULL);
     78 
     79 #define PORTSIZE	(SL11_PORTSIZE*4)
     80 
     81 static int
     82 slhci_opio_match(struct device *parent, struct cfdata *cf, void *aux)
     83 {
     84 	struct obio_attach_args *oba = aux;
     85 	bus_space_tag_t iot = &pxa2x0_a4x_bs_tag; /* Use special BS funcs */
     86 	bus_space_handle_t ioh;
     87 	struct obio_softc *bsc = (struct obio_softc *)device_parent(parent);
     88 	struct pxa2x0_softc *psc;
     89 	int type;
     90 	uint32_t reg;
     91 
     92 	struct slhci_softc sc;
     93 
     94 	obio_peripheral_reset(bsc, 2, 0);
     95 	psc = (struct pxa2x0_softc *)device_parent(&bsc->sc_dev);
     96 
     97 	reg = bus_space_read_4(psc->saip.sc_iot, psc->sc_memctl_ioh,
     98 	    MEMCTL_MSC2);
     99 #if 0
    100 	bus_space_write_4(psc->saip.sc_iot, psc->sc_memctl_ioh, MEMCTL_MSC2,xxx)
    101 #endif
    102 
    103 
    104 	oba->oba_iot = iot;
    105 	if (oba->oba_addr == OBIOCF_ADDR_DEFAULT)
    106 		oba->oba_addr = PXA2X0_CS5_START;
    107 	if (oba->oba_intr == OBIOCF_INTR_DEFAULT)
    108 		oba->oba_intr = G4250EBX_INT_EXT2;
    109 
    110 	if (bus_space_map(iot, oba->oba_addr, PORTSIZE, 0, &ioh))
    111 		return 0;
    112 
    113 	/* construct fake softc to call sl811hs */
    114 	sc.sc_iot = iot;
    115 	sc.sc_ioh = ioh;
    116 	type = sl811hs_find(&sc);
    117 
    118 	bus_space_unmap(iot, ioh, PORTSIZE);
    119 
    120 	return type >= 0;
    121 }
    122 
    123 static void
    124 slhci_opio_attach(struct device *parent, struct device *self, void *aux)
    125 {
    126 	struct slhci_opio_softc *sc = (struct slhci_opio_softc *)self;
    127 	struct obio_attach_args *oba = aux;
    128 	struct opio_softc *psc =
    129 	    (struct opio_softc *)device_parent(self);
    130 	struct obio_softc *bsc =
    131 	    (struct obio_softc *)device_parent(&psc->sc_dev);
    132 	bus_space_tag_t iot = oba->oba_iot;
    133 	bus_space_handle_t ioh;
    134 
    135 	printf("\n");
    136 
    137 	/* Map I/O space */
    138 	if (bus_space_map(iot, oba->oba_addr, PORTSIZE, 0, &ioh)) {
    139 		printf("%s: can't map I/O space\n",
    140 			sc->sc_sc.sc_bus.bdev.dv_xname);
    141 		return;
    142 	}
    143 
    144 	/* Initialize sc */
    145 	sc->sc_sc.sc_iot = iot;
    146 	sc->sc_sc.sc_ioh = ioh;
    147 	sc->sc_sc.sc_dmat = &pxa2x0_bus_dma_tag;	/* XXX */
    148 	sc->sc_sc.sc_enable_power = slhci_opio_enable_power;
    149 	sc->sc_sc.sc_enable_intr  = slhci_opio_enable_intr;
    150 	sc->sc_sc.sc_arg = sc;
    151 
    152 	/* Establish the interrupt handler */
    153 	sc->sc_ih = obio_intr_establish(bsc, oba->oba_intr, IPL_BIO,
    154 	    IST_LEVEL_HIGH, slhci_opio_intr, sc);
    155 	if( sc->sc_ih == NULL) {
    156 		printf("%s: can't establish interrupt\n",
    157 			sc->sc_sc.sc_bus.bdev.dv_xname);
    158 		return;
    159 	}
    160 
    161 #if 0
    162 	/* Reset controller */
    163 	obio_peripheral_reset(bsc, 2, 1);
    164 	delay(100);
    165 	obio_peripheral_reset(bsc, 2, 0);
    166 	delay(40000);
    167 #endif
    168 
    169 	bus_space_write_1(iot, ioh, SL11_IDX_ADDR, SL11_CTRL);
    170 	bus_space_write_1(iot, ioh, SL11_IDX_DATA, 0x01);
    171 
    172 	/* Attach SL811HS/T */
    173 	if (slhci_attach(&sc->sc_sc, self))
    174 		return;
    175 }
    176 
    177 static void
    178 slhci_opio_enable_power(void *arg, int mode)
    179 {
    180 #if 0
    181 	struct slhci_opio_softc *sc = arg;
    182 	bus_space_tag_t iot = sc->sc_sc.sc_iot;
    183 	u_int8_t r;
    184 
    185 	r = bus_space_read_1(iot, sc->sc_nch, NEREID_CTRL);
    186 	if (mode == POWER_ON)
    187 		bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
    188 			r |  NEREID_CTRL_POWER);
    189 	else
    190 		bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
    191 			r & ~NEREID_CTRL_POWER);
    192 #endif
    193 }
    194 
    195 static void
    196 slhci_opio_enable_intr(void *arg, int mode)
    197 {
    198 	struct slhci_opio_softc *sc = arg;
    199 	struct obio_softc *bsc;
    200 
    201 	bsc = (struct obio_softc *)device_parent(
    202 	    device_parent(&sc->sc_sc.sc_bus.bdev));
    203 
    204 	if (mode == INTR_ON)
    205 		obio_intr_unmask(bsc, sc->sc_ih);
    206 	else
    207 		obio_intr_mask(bsc, sc->sc_ih);
    208 }
    209 
    210 static int
    211 slhci_opio_intr(void *arg)
    212 {
    213 	struct slhci_opio_softc *sc = arg;
    214 
    215 	return slhci_intr(&sc->sc_sc);
    216 }
    217