Home | History | Annotate | Line # | Download | only in dev
ohci_aubus.c revision 1.10
      1  1.10  gdamore /*	$NetBSD: ohci_aubus.c,v 1.10 2006/02/09 03:14:31 gdamore Exp $	*/
      2   1.1  hpeyerl 
      3   1.1  hpeyerl /*-
      4   1.1  hpeyerl  * Copyright (c) 1998, 1999, 2000, 2002, 2003 The NetBSD Foundation, Inc.
      5   1.1  hpeyerl  * All rights reserved.
      6   1.1  hpeyerl  *
      7   1.1  hpeyerl  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1  hpeyerl  * by Herb Peyerl of Middle Digital Inc.
      9   1.1  hpeyerl  *
     10   1.1  hpeyerl  * Redistribution and use in source and binary forms, with or without
     11   1.1  hpeyerl  * modification, are permitted provided that the following conditions
     12   1.1  hpeyerl  * are met:
     13   1.1  hpeyerl  * 1. Redistributions of source code must retain the above copyright
     14   1.1  hpeyerl  *    notice, this list of conditions and the following disclaimer.
     15   1.1  hpeyerl  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1  hpeyerl  *    notice, this list of conditions and the following disclaimer in the
     17   1.1  hpeyerl  *    documentation and/or other materials provided with the distribution.
     18   1.1  hpeyerl  * 3. All advertising materials mentioning features or use of this software
     19   1.1  hpeyerl  *    must display the following acknowledgement:
     20   1.1  hpeyerl  *      This product includes software developed by the NetBSD
     21   1.1  hpeyerl  *      Foundation, Inc. and its contributors.
     22   1.1  hpeyerl  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1  hpeyerl  *    contributors may be used to endorse or promote products derived
     24   1.1  hpeyerl  *    from this software without specific prior written permission.
     25   1.1  hpeyerl  *
     26   1.1  hpeyerl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1  hpeyerl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1  hpeyerl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1  hpeyerl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1  hpeyerl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1  hpeyerl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1  hpeyerl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1  hpeyerl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1  hpeyerl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1  hpeyerl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1  hpeyerl  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1  hpeyerl  */
     38   1.3    lukem 
     39   1.3    lukem #include <sys/cdefs.h>
     40  1.10  gdamore __KERNEL_RCSID(0, "$NetBSD: ohci_aubus.c,v 1.10 2006/02/09 03:14:31 gdamore Exp $");
     41   1.1  hpeyerl 
     42   1.1  hpeyerl #include <sys/param.h>
     43   1.1  hpeyerl #include <sys/systm.h>
     44   1.1  hpeyerl #include <sys/device.h>
     45   1.1  hpeyerl 
     46   1.1  hpeyerl #include <machine/bus.h>
     47   1.1  hpeyerl 
     48   1.1  hpeyerl #include <mips/alchemy/include/aureg.h>
     49   1.1  hpeyerl #include <mips/alchemy/include/auvar.h>
     50   1.1  hpeyerl #include <mips/alchemy/include/aubusvar.h>
     51  1.10  gdamore #include <mips/alchemy/dev/ohcireg.h>
     52   1.1  hpeyerl 
     53   1.1  hpeyerl #include <dev/usb/usb.h>
     54   1.1  hpeyerl #include <dev/usb/usbdi.h>
     55   1.1  hpeyerl #include <dev/usb/usbdivar.h>
     56   1.1  hpeyerl #include <dev/usb/usb_mem.h>
     57   1.1  hpeyerl 
     58   1.1  hpeyerl #include <dev/usb/ohcireg.h>
     59   1.1  hpeyerl #include <dev/usb/ohcivar.h>
     60   1.1  hpeyerl 
     61   1.1  hpeyerl 
     62   1.1  hpeyerl static int	ohci_aubus_match(struct device *, struct cfdata *, void *);
     63   1.1  hpeyerl static void	ohci_aubus_attach(struct device *, struct device *, void *);
     64   1.1  hpeyerl 
     65   1.1  hpeyerl CFATTACH_DECL(ohci_aubus, sizeof (ohci_softc_t),
     66   1.1  hpeyerl     ohci_aubus_match, ohci_aubus_attach, NULL, NULL);
     67   1.1  hpeyerl 
     68   1.1  hpeyerl int
     69   1.1  hpeyerl ohci_aubus_match(struct device *parent, struct cfdata *match, void *aux)
     70   1.1  hpeyerl {
     71   1.1  hpeyerl 	struct aubus_attach_args *aa = aux;
     72   1.1  hpeyerl 
     73   1.1  hpeyerl 	if (strcmp(aa->aa_name, match->cf_name) == 0)
     74   1.1  hpeyerl 		return (1);
     75   1.1  hpeyerl 
     76   1.1  hpeyerl 	return (0);
     77   1.1  hpeyerl }
     78   1.1  hpeyerl 
     79   1.1  hpeyerl void
     80   1.1  hpeyerl ohci_aubus_attach(struct device *parent, struct device *self, void *aux)
     81   1.1  hpeyerl {
     82   1.5   simonb 	ohci_softc_t *sc = (ohci_softc_t *)self;
     83   1.5   simonb 	void *ih;
     84   1.1  hpeyerl 	usbd_status r;
     85   1.1  hpeyerl 	uint32_t x, tmp;
     86   1.8     tron 	bus_addr_t usbh_base, usbh_enable;
     87   1.1  hpeyerl 	struct aubus_attach_args *aa = aux;
     88   1.1  hpeyerl 
     89   1.1  hpeyerl 	r = 0;
     90   1.1  hpeyerl 
     91   1.8     tron 	usbh_base = aa->aa_addrs[0];
     92   1.8     tron 	usbh_enable = aa->aa_addrs[1];
     93   1.8     tron 	sc->sc_size = aa->aa_addrs[2];
     94   1.5   simonb 	sc->iot = aa->aa_st;
     95   1.5   simonb 	sc->sc_bus.dmatag = (bus_dma_tag_t)aa->aa_dt;
     96   1.1  hpeyerl 
     97   1.8     tron 	if (bus_space_map(sc->iot, usbh_base, sc->sc_size, 0, &sc->ioh)) {
     98   1.1  hpeyerl 		printf("%s: Unable to map USBH registers\n",
     99   1.5   simonb 			sc->sc_bus.bdev.dv_xname);
    100   1.1  hpeyerl 		return;
    101   1.1  hpeyerl 	}
    102   1.1  hpeyerl 	/*
    103   1.1  hpeyerl 	 * Enable the USB Host controller here.
    104   1.1  hpeyerl 	 * As per 7.2 in the Au1500 manual:
    105   1.1  hpeyerl 	 *
    106   1.1  hpeyerl 	 *  (1) Set CE bit to enable clocks.
    107   1.1  hpeyerl 	 *  (2) Set E to enable OHCI
    108   1.1  hpeyerl 	 *  (3) Clear HCFS in OHCI_CONTROL.
    109   1.1  hpeyerl 	 *  (4) Wait for RD bit to be set.
    110   1.1  hpeyerl 	 */
    111   1.8     tron 	x = bus_space_read_4(sc->iot, sc->ioh, usbh_enable);
    112   1.1  hpeyerl 	x |= UE_CE;
    113   1.8     tron 	bus_space_write_4(sc->iot, sc->ioh, usbh_enable, x);
    114   1.1  hpeyerl 	delay(10);
    115   1.4   simonb 	x |= UE_E;
    116   1.4   simonb #ifdef __MIPSEB__
    117   1.4   simonb 	x |= UE_BE;
    118   1.4   simonb #endif
    119   1.8     tron 	bus_space_write_4(sc->iot, sc->ioh, usbh_enable, x);
    120   1.1  hpeyerl 	delay(10);
    121   1.5   simonb 	x = bus_space_read_4(sc->iot, sc->ioh, OHCI_CONTROL);
    122   1.1  hpeyerl 	x &= ~(OHCI_HCFS_MASK);
    123   1.5   simonb 	bus_space_write_4(sc->iot, sc->ioh, OHCI_CONTROL, x);
    124   1.1  hpeyerl 	delay(10);
    125   1.2  hpeyerl 	/*  Need to read USBH_ENABLE twice in succession according to
    126   1.2  hpeyerl          *  au1500 Errata #7.
    127   1.2  hpeyerl          */
    128   1.1  hpeyerl 	for (x = 100; x; x--) {
    129   1.8     tron 		bus_space_read_4(sc->iot, sc->ioh, usbh_enable);
    130   1.8     tron 		tmp = bus_space_read_4(sc->iot, sc->ioh, usbh_enable);
    131   1.1  hpeyerl 		if (tmp&UE_RD)
    132   1.1  hpeyerl 			break;
    133   1.1  hpeyerl 		delay(1000);
    134   1.1  hpeyerl 	}
    135   1.8     tron 	printf(": Alchemy OHCI\n");
    136   1.1  hpeyerl 
    137   1.1  hpeyerl 	/* Disable OHCI interrupts */
    138   1.5   simonb 	bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE,
    139   1.1  hpeyerl 				OHCI_ALL_INTRS);
    140   1.1  hpeyerl 	/* hook interrupt */
    141   1.5   simonb 	ih = au_intr_establish(aa->aa_irq[0], 0, IPL_USB, IST_LEVEL_LOW,
    142   1.1  hpeyerl 			ohci_intr, sc);
    143   1.5   simonb 	if (ih == NULL) {
    144   1.1  hpeyerl 		printf("%s: couldn't establish interrupt\n",
    145   1.5   simonb 			sc->sc_bus.bdev.dv_xname);
    146   1.1  hpeyerl 	}
    147   1.1  hpeyerl 
    148   1.7     tron 	sc->sc_endian = OHCI_HOST_ENDIAN;
    149   1.7     tron 
    150   1.1  hpeyerl 	if (x)
    151   1.5   simonb 		r = ohci_init(sc);
    152   1.1  hpeyerl 	if (r != USBD_NORMAL_COMPLETION) {
    153   1.1  hpeyerl 		printf("%s: init failed, error=%d\n",
    154   1.5   simonb 			sc->sc_bus.bdev.dv_xname, r);
    155   1.5   simonb 		au_intr_disestablish(ih);
    156   1.1  hpeyerl 		return;
    157   1.1  hpeyerl 	}
    158   1.1  hpeyerl 
    159   1.1  hpeyerl 	/* Attach USB device */
    160   1.5   simonb 	sc->sc_child = config_found((void *)sc, &sc->sc_bus, usbctlprint);
    161   1.1  hpeyerl 
    162   1.1  hpeyerl }
    163