Home | History | Annotate | Line # | Download | only in g42xxeb
gb225_slhci.c revision 1.3.72.1
      1  1.3.72.1     yamt /*	$NetBSD: gb225_slhci.c,v 1.3.72.1 2008/05/16 02:22:10 yamt Exp $ */
      2       1.1      bsh 
      3       1.1      bsh /*
      4       1.1      bsh  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5       1.1      bsh  * All rights reserved.
      6       1.1      bsh  *
      7       1.1      bsh  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1      bsh  * by Tetsuya Isaki.
      9       1.1      bsh  *
     10       1.1      bsh  * Redistribution and use in source and binary forms, with or without
     11       1.1      bsh  * modification, are permitted provided that the following conditions
     12       1.1      bsh  * are met:
     13       1.1      bsh  * 1. Redistributions of source code must retain the above copyright
     14       1.1      bsh  *    notice, this list of conditions and the following disclaimer.
     15       1.1      bsh  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1      bsh  *    notice, this list of conditions and the following disclaimer in the
     17       1.1      bsh  *    documentation and/or other materials provided with the distribution.
     18       1.1      bsh  *
     19       1.1      bsh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1      bsh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1      bsh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1      bsh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1      bsh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1      bsh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1      bsh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1      bsh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1      bsh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1      bsh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1      bsh  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1      bsh  */
     31       1.1      bsh 
     32       1.1      bsh /*
     33       1.1      bsh  * SL811HS USB host controller for GB-225 Option board of G4250EBX.
     34       1.1      bsh  */
     35       1.1      bsh 
     36       1.1      bsh #include <sys/param.h>
     37       1.1      bsh #include <sys/systm.h>
     38       1.1      bsh #include <sys/device.h>
     39       1.1      bsh 
     40       1.1      bsh #include <machine/bus.h>
     41       1.1      bsh #include <machine/cpu.h>
     42       1.1      bsh 
     43       1.1      bsh #include <dev/usb/usb.h>
     44       1.1      bsh #include <dev/usb/usbdi.h>
     45       1.1      bsh #include <dev/usb/usbdivar.h>
     46       1.1      bsh 
     47       1.1      bsh #include <dev/ic/sl811hsreg.h>
     48       1.1      bsh #include <dev/ic/sl811hsvar.h>
     49       1.1      bsh 
     50       1.1      bsh #include <arch/arm/xscale/pxa2x0reg.h>
     51       1.1      bsh #include <arch/arm/xscale/pxa2x0var.h>
     52       1.1      bsh #include <arch/evbarm/g42xxeb/g42xxeb_reg.h>
     53       1.1      bsh #include <arch/evbarm/g42xxeb/g42xxeb_var.h>
     54       1.1      bsh #include <arch/evbarm/g42xxeb/gb225reg.h>
     55       1.1      bsh #include <arch/evbarm/g42xxeb/gb225var.h>
     56       1.1      bsh 
     57       1.1      bsh struct slhci_opio_softc {
     58       1.1      bsh 	struct slhci_softc sc_sc;
     59       1.1      bsh 
     60       1.1      bsh 	void *sc_ih;
     61       1.1      bsh };
     62       1.1      bsh 
     63       1.1      bsh static int  slhci_opio_match(struct device *, struct cfdata *, void *);
     64       1.1      bsh static void slhci_opio_attach(struct device *, struct device *, void *);
     65       1.1      bsh static void slhci_opio_enable_power(void *, int);
     66       1.1      bsh static void slhci_opio_enable_intr(void *, int);
     67       1.1      bsh static int  slhci_opio_intr(void *);
     68       1.1      bsh 
     69       1.1      bsh CFATTACH_DECL(slhci_opio, sizeof(struct slhci_opio_softc),
     70       1.1      bsh     slhci_opio_match, slhci_opio_attach, NULL, NULL);
     71       1.1      bsh 
     72       1.1      bsh #define PORTSIZE	(SL11_PORTSIZE*4)
     73       1.1      bsh 
     74       1.1      bsh static int
     75       1.1      bsh slhci_opio_match(struct device *parent, struct cfdata *cf, void *aux)
     76       1.1      bsh {
     77       1.1      bsh 	struct obio_attach_args *oba = aux;
     78       1.1      bsh 	bus_space_tag_t iot = &pxa2x0_a4x_bs_tag; /* Use special BS funcs */
     79       1.1      bsh 	bus_space_handle_t ioh;
     80       1.3  thorpej 	struct obio_softc *bsc = (struct obio_softc *)device_parent(parent);
     81       1.1      bsh 	struct pxa2x0_softc *psc;
     82       1.1      bsh 	int type;
     83       1.1      bsh 	uint32_t reg;
     84       1.1      bsh 
     85       1.1      bsh 	struct slhci_softc sc;
     86       1.1      bsh 
     87       1.1      bsh 	obio_peripheral_reset(bsc, 2, 0);
     88       1.3  thorpej 	psc = (struct pxa2x0_softc *)device_parent(&bsc->sc_dev);
     89       1.1      bsh 
     90       1.1      bsh 	reg = bus_space_read_4(psc->saip.sc_iot, psc->sc_memctl_ioh,
     91       1.1      bsh 	    MEMCTL_MSC2);
     92       1.1      bsh #if 0
     93       1.1      bsh 	bus_space_write_4(psc->saip.sc_iot, psc->sc_memctl_ioh, MEMCTL_MSC2,xxx)
     94       1.1      bsh #endif
     95       1.1      bsh 
     96       1.1      bsh 
     97       1.1      bsh 	oba->oba_iot = iot;
     98       1.1      bsh 	if (oba->oba_addr == OBIOCF_ADDR_DEFAULT)
     99       1.1      bsh 		oba->oba_addr = PXA2X0_CS5_START;
    100       1.1      bsh 	if (oba->oba_intr == OBIOCF_INTR_DEFAULT)
    101       1.1      bsh 		oba->oba_intr = G4250EBX_INT_EXT2;
    102       1.1      bsh 
    103       1.1      bsh 	if (bus_space_map(iot, oba->oba_addr, PORTSIZE, 0, &ioh))
    104       1.1      bsh 		return 0;
    105       1.1      bsh 
    106       1.1      bsh 	/* construct fake softc to call sl811hs */
    107       1.1      bsh 	sc.sc_iot = iot;
    108       1.1      bsh 	sc.sc_ioh = ioh;
    109       1.1      bsh 	type = sl811hs_find(&sc);
    110       1.1      bsh 
    111       1.1      bsh 	bus_space_unmap(iot, ioh, PORTSIZE);
    112       1.1      bsh 
    113       1.1      bsh 	return type >= 0;
    114       1.1      bsh }
    115       1.1      bsh 
    116       1.1      bsh static void
    117       1.1      bsh slhci_opio_attach(struct device *parent, struct device *self, void *aux)
    118       1.1      bsh {
    119       1.1      bsh 	struct slhci_opio_softc *sc = (struct slhci_opio_softc *)self;
    120       1.1      bsh 	struct obio_attach_args *oba = aux;
    121       1.3  thorpej 	struct opio_softc *psc =
    122       1.3  thorpej 	    (struct opio_softc *)device_parent(self);
    123       1.3  thorpej 	struct obio_softc *bsc =
    124       1.3  thorpej 	    (struct obio_softc *)device_parent(&psc->sc_dev);
    125       1.1      bsh 	bus_space_tag_t iot = oba->oba_iot;
    126       1.1      bsh 	bus_space_handle_t ioh;
    127       1.1      bsh 
    128       1.1      bsh 	printf("\n");
    129       1.1      bsh 
    130       1.1      bsh 	/* Map I/O space */
    131       1.1      bsh 	if (bus_space_map(iot, oba->oba_addr, PORTSIZE, 0, &ioh)) {
    132       1.1      bsh 		printf("%s: can't map I/O space\n",
    133       1.1      bsh 			sc->sc_sc.sc_bus.bdev.dv_xname);
    134       1.1      bsh 		return;
    135       1.1      bsh 	}
    136       1.1      bsh 
    137       1.1      bsh 	/* Initialize sc */
    138       1.1      bsh 	sc->sc_sc.sc_iot = iot;
    139       1.1      bsh 	sc->sc_sc.sc_ioh = ioh;
    140       1.1      bsh 	sc->sc_sc.sc_dmat = &pxa2x0_bus_dma_tag;	/* XXX */
    141       1.1      bsh 	sc->sc_sc.sc_enable_power = slhci_opio_enable_power;
    142       1.1      bsh 	sc->sc_sc.sc_enable_intr  = slhci_opio_enable_intr;
    143       1.1      bsh 	sc->sc_sc.sc_arg = sc;
    144       1.1      bsh 
    145       1.1      bsh 	/* Establish the interrupt handler */
    146       1.1      bsh 	sc->sc_ih = obio_intr_establish(bsc, oba->oba_intr, IPL_BIO,
    147       1.1      bsh 	    IST_LEVEL_HIGH, slhci_opio_intr, sc);
    148       1.1      bsh 	if( sc->sc_ih == NULL) {
    149       1.1      bsh 		printf("%s: can't establish interrupt\n",
    150       1.1      bsh 			sc->sc_sc.sc_bus.bdev.dv_xname);
    151       1.1      bsh 		return;
    152       1.1      bsh 	}
    153       1.1      bsh 
    154       1.1      bsh #if 0
    155       1.1      bsh 	/* Reset controller */
    156       1.1      bsh 	obio_peripheral_reset(bsc, 2, 1);
    157       1.1      bsh 	delay(100);
    158       1.1      bsh 	obio_peripheral_reset(bsc, 2, 0);
    159       1.1      bsh 	delay(40000);
    160       1.1      bsh #endif
    161       1.1      bsh 
    162       1.1      bsh 	bus_space_write_1(iot, ioh, SL11_IDX_ADDR, SL11_CTRL);
    163       1.1      bsh 	bus_space_write_1(iot, ioh, SL11_IDX_DATA, 0x01);
    164       1.1      bsh 
    165       1.1      bsh 	/* Attach SL811HS/T */
    166       1.1      bsh 	if (slhci_attach(&sc->sc_sc, self))
    167       1.1      bsh 		return;
    168       1.1      bsh }
    169       1.1      bsh 
    170       1.1      bsh static void
    171       1.1      bsh slhci_opio_enable_power(void *arg, int mode)
    172       1.1      bsh {
    173       1.1      bsh #if 0
    174       1.1      bsh 	struct slhci_opio_softc *sc = arg;
    175       1.1      bsh 	bus_space_tag_t iot = sc->sc_sc.sc_iot;
    176       1.1      bsh 	u_int8_t r;
    177       1.1      bsh 
    178       1.1      bsh 	r = bus_space_read_1(iot, sc->sc_nch, NEREID_CTRL);
    179       1.1      bsh 	if (mode == POWER_ON)
    180       1.1      bsh 		bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
    181       1.1      bsh 			r |  NEREID_CTRL_POWER);
    182       1.1      bsh 	else
    183       1.1      bsh 		bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
    184       1.1      bsh 			r & ~NEREID_CTRL_POWER);
    185       1.1      bsh #endif
    186       1.1      bsh }
    187       1.1      bsh 
    188       1.1      bsh static void
    189       1.1      bsh slhci_opio_enable_intr(void *arg, int mode)
    190       1.1      bsh {
    191       1.1      bsh 	struct slhci_opio_softc *sc = arg;
    192       1.1      bsh 	struct obio_softc *bsc;
    193       1.1      bsh 
    194       1.3  thorpej 	bsc = (struct obio_softc *)device_parent(
    195       1.3  thorpej 	    device_parent(&sc->sc_sc.sc_bus.bdev));
    196       1.1      bsh 
    197       1.1      bsh 	if (mode == INTR_ON)
    198       1.1      bsh 		obio_intr_unmask(bsc, sc->sc_ih);
    199       1.1      bsh 	else
    200       1.1      bsh 		obio_intr_mask(bsc, sc->sc_ih);
    201       1.1      bsh }
    202       1.1      bsh 
    203       1.1      bsh static int
    204       1.1      bsh slhci_opio_intr(void *arg)
    205       1.1      bsh {
    206       1.1      bsh 	struct slhci_opio_softc *sc = arg;
    207       1.1      bsh 
    208       1.1      bsh 	return slhci_intr(&sc->sc_sc);
    209       1.1      bsh }
    210