Home | History | Annotate | Line # | Download | only in g42xxeb
gb225_slhci.c revision 1.6.2.2
      1  1.6.2.2     yamt /*	$NetBSD: gb225_slhci.c,v 1.6.2.2 2013/01/16 05:32:53 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.6   dyoung #include <sys/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.6.2.1     yamt static int  slhci_opio_match(device_t, cfdata_t, void *);
     64  1.6.2.1     yamt static void slhci_opio_attach(device_t, device_t, 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.6.2.1     yamt CFATTACH_DECL_NEW(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.6.2.1     yamt slhci_opio_match(device_t parent, cfdata_t 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.6.2.1     yamt 	struct obio_softc *bsc = device_private(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.6.2.1     yamt 	psc = device_private(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.6.2.1     yamt slhci_opio_attach(device_t parent, device_t self, void *aux)
    118      1.1      bsh {
    119  1.6.2.1     yamt 	struct slhci_opio_softc *sc = device_private(self);
    120      1.1      bsh 	struct obio_attach_args *oba = aux;
    121      1.3  thorpej 	struct opio_softc *psc =
    122  1.6.2.1     yamt 	    device_private(device_parent(self));
    123      1.3  thorpej 	struct obio_softc *bsc =
    124  1.6.2.1     yamt 	    device_private(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.5      bsh 		aprint_error_dev(self, "can't map I/O space\n");
    133      1.1      bsh 		return;
    134      1.1      bsh 	}
    135      1.1      bsh 
    136      1.1      bsh 	/* Initialize sc */
    137      1.1      bsh 	sc->sc_sc.sc_iot = iot;
    138      1.1      bsh 	sc->sc_sc.sc_ioh = ioh;
    139      1.1      bsh 	sc->sc_sc.sc_dmat = &pxa2x0_bus_dma_tag;	/* XXX */
    140      1.1      bsh 	sc->sc_sc.sc_enable_power = slhci_opio_enable_power;
    141      1.1      bsh 	sc->sc_sc.sc_enable_intr  = slhci_opio_enable_intr;
    142      1.1      bsh 	sc->sc_sc.sc_arg = sc;
    143      1.1      bsh 
    144      1.1      bsh 	/* Establish the interrupt handler */
    145      1.1      bsh 	sc->sc_ih = obio_intr_establish(bsc, oba->oba_intr, IPL_BIO,
    146      1.1      bsh 	    IST_LEVEL_HIGH, slhci_opio_intr, sc);
    147      1.1      bsh 	if( sc->sc_ih == NULL) {
    148      1.5      bsh 		aprint_error_dev(self, "can't establish interrupt\n");
    149      1.1      bsh 		return;
    150      1.1      bsh 	}
    151      1.1      bsh 
    152      1.1      bsh #if 0
    153      1.1      bsh 	/* Reset controller */
    154      1.1      bsh 	obio_peripheral_reset(bsc, 2, 1);
    155      1.1      bsh 	delay(100);
    156      1.1      bsh 	obio_peripheral_reset(bsc, 2, 0);
    157      1.1      bsh 	delay(40000);
    158      1.1      bsh #endif
    159      1.1      bsh 
    160      1.1      bsh 	bus_space_write_1(iot, ioh, SL11_IDX_ADDR, SL11_CTRL);
    161      1.1      bsh 	bus_space_write_1(iot, ioh, SL11_IDX_DATA, 0x01);
    162      1.1      bsh 
    163      1.1      bsh 	/* Attach SL811HS/T */
    164      1.1      bsh 	if (slhci_attach(&sc->sc_sc, self))
    165      1.1      bsh 		return;
    166      1.1      bsh }
    167      1.1      bsh 
    168      1.1      bsh static void
    169      1.1      bsh slhci_opio_enable_power(void *arg, int mode)
    170      1.1      bsh {
    171      1.1      bsh #if 0
    172      1.1      bsh 	struct slhci_opio_softc *sc = arg;
    173      1.1      bsh 	bus_space_tag_t iot = sc->sc_sc.sc_iot;
    174  1.6.2.2     yamt 	uint8_t r;
    175      1.1      bsh 
    176      1.1      bsh 	r = bus_space_read_1(iot, sc->sc_nch, NEREID_CTRL);
    177      1.1      bsh 	if (mode == POWER_ON)
    178      1.1      bsh 		bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
    179      1.1      bsh 			r |  NEREID_CTRL_POWER);
    180      1.1      bsh 	else
    181      1.1      bsh 		bus_space_write_1(iot, sc->sc_nch, NEREID_CTRL,
    182      1.1      bsh 			r & ~NEREID_CTRL_POWER);
    183      1.1      bsh #endif
    184      1.1      bsh }
    185      1.1      bsh 
    186      1.1      bsh static void
    187      1.1      bsh slhci_opio_enable_intr(void *arg, int mode)
    188      1.1      bsh {
    189      1.1      bsh 	struct slhci_opio_softc *sc = arg;
    190      1.1      bsh 	struct obio_softc *bsc;
    191      1.1      bsh 
    192  1.6.2.1     yamt 	bsc = device_private(device_parent(
    193  1.6.2.1     yamt 	    device_parent(sc->sc_sc.sc_bus.bdev)));
    194      1.1      bsh 
    195      1.1      bsh 	if (mode == INTR_ON)
    196      1.1      bsh 		obio_intr_unmask(bsc, sc->sc_ih);
    197      1.1      bsh 	else
    198      1.1      bsh 		obio_intr_mask(bsc, sc->sc_ih);
    199      1.1      bsh }
    200      1.1      bsh 
    201      1.1      bsh static int
    202      1.1      bsh slhci_opio_intr(void *arg)
    203      1.1      bsh {
    204      1.1      bsh 	struct slhci_opio_softc *sc = arg;
    205      1.1      bsh 
    206      1.1      bsh 	return slhci_intr(&sc->sc_sc);
    207      1.1      bsh }
    208