Home | History | Annotate | Line # | Download | only in rmi
rmixl_ohci.c revision 1.1.10.1
      1  1.1.10.1  bouyer /*	$NetBSD: rmixl_ohci.c,v 1.1.10.1 2011/03/05 15:09:51 bouyer Exp $	*/
      2  1.1.10.1  bouyer 
      3  1.1.10.1  bouyer /*-
      4  1.1.10.1  bouyer  * Copyright (c) 1998, 1999, 2000, 2002, 2003 The NetBSD Foundation, Inc.
      5  1.1.10.1  bouyer  * All rights reserved.
      6  1.1.10.1  bouyer  *
      7  1.1.10.1  bouyer  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.10.1  bouyer  * by Herb Peyerl of Middle Digital Inc.
      9  1.1.10.1  bouyer  *
     10  1.1.10.1  bouyer  * Redistribution and use in source and binary forms, with or without
     11  1.1.10.1  bouyer  * modification, are permitted provided that the following conditions
     12  1.1.10.1  bouyer  * are met:
     13  1.1.10.1  bouyer  * 1. Redistributions of source code must retain the above copyright
     14  1.1.10.1  bouyer  *    notice, this list of conditions and the following disclaimer.
     15  1.1.10.1  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.10.1  bouyer  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.10.1  bouyer  *    documentation and/or other materials provided with the distribution.
     18  1.1.10.1  bouyer  *
     19  1.1.10.1  bouyer  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1.10.1  bouyer  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1.10.1  bouyer  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1.10.1  bouyer  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1.10.1  bouyer  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1.10.1  bouyer  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1.10.1  bouyer  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1.10.1  bouyer  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1.10.1  bouyer  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1.10.1  bouyer  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1.10.1  bouyer  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1.10.1  bouyer  */
     31  1.1.10.1  bouyer 
     32  1.1.10.1  bouyer #include "locators.h"
     33  1.1.10.1  bouyer 
     34  1.1.10.1  bouyer #include <sys/cdefs.h>
     35  1.1.10.1  bouyer __KERNEL_RCSID(0, "$NetBSD: rmixl_ohci.c,v 1.1.10.1 2011/03/05 15:09:51 bouyer Exp $");
     36  1.1.10.1  bouyer 
     37  1.1.10.1  bouyer #include <sys/param.h>
     38  1.1.10.1  bouyer #include <sys/systm.h>
     39  1.1.10.1  bouyer #include <sys/device.h>
     40  1.1.10.1  bouyer 
     41  1.1.10.1  bouyer #include <machine/bus.h>
     42  1.1.10.1  bouyer 
     43  1.1.10.1  bouyer #include <mips/rmi/rmixlreg.h>
     44  1.1.10.1  bouyer #include <mips/rmi/rmixlvar.h>
     45  1.1.10.1  bouyer #include <mips/rmi/rmixl_intr.h>
     46  1.1.10.1  bouyer #include <mips/rmi/rmixl_usbivar.h>
     47  1.1.10.1  bouyer 
     48  1.1.10.1  bouyer #include <dev/usb/usb.h>
     49  1.1.10.1  bouyer #include <dev/usb/usbdi.h>
     50  1.1.10.1  bouyer #include <dev/usb/usbdivar.h>
     51  1.1.10.1  bouyer #include <dev/usb/usb_mem.h>
     52  1.1.10.1  bouyer 
     53  1.1.10.1  bouyer #include <dev/usb/ohcireg.h>
     54  1.1.10.1  bouyer #include <dev/usb/ohcivar.h>
     55  1.1.10.1  bouyer 
     56  1.1.10.1  bouyer 
     57  1.1.10.1  bouyer static int	rmixl_ohci_match(device_t, cfdata_t, void *);
     58  1.1.10.1  bouyer static void	rmixl_ohci_attach(device_t, device_t, void *);
     59  1.1.10.1  bouyer 
     60  1.1.10.1  bouyer 
     61  1.1.10.1  bouyer CFATTACH_DECL_NEW(rmixl_ohci, sizeof (ohci_softc_t),
     62  1.1.10.1  bouyer     rmixl_ohci_match, rmixl_ohci_attach, NULL, NULL);
     63  1.1.10.1  bouyer 
     64  1.1.10.1  bouyer int
     65  1.1.10.1  bouyer rmixl_ohci_match(device_t parent, cfdata_t match, void *aux)
     66  1.1.10.1  bouyer {
     67  1.1.10.1  bouyer 	struct rmixl_usbi_attach_args *usbi = aux;
     68  1.1.10.1  bouyer 
     69  1.1.10.1  bouyer         if ((usbi->usbi_addr == (RMIXL_IO_DEV_USB_A+RMIXL_USB_HOST_0HCI0_BASE))
     70  1.1.10.1  bouyer         ||  (usbi->usbi_addr == (RMIXL_IO_DEV_USB_A+RMIXL_USB_HOST_0HCI1_BASE)))
     71  1.1.10.1  bouyer                 return rmixl_probe_4((volatile uint32_t *)
     72  1.1.10.1  bouyer 			RMIXL_IOREG_VADDR(usbi->usbi_addr));
     73  1.1.10.1  bouyer 
     74  1.1.10.1  bouyer         return 0;
     75  1.1.10.1  bouyer }
     76  1.1.10.1  bouyer 
     77  1.1.10.1  bouyer void
     78  1.1.10.1  bouyer rmixl_ohci_attach(device_t parent, device_t self, void *aux)
     79  1.1.10.1  bouyer {
     80  1.1.10.1  bouyer 	ohci_softc_t *sc = device_private(self);
     81  1.1.10.1  bouyer 	struct rmixl_usbi_attach_args *usbi = aux;
     82  1.1.10.1  bouyer 	void *ih = NULL;
     83  1.1.10.1  bouyer 	uint32_t r;
     84  1.1.10.1  bouyer 	usbd_status status;
     85  1.1.10.1  bouyer 
     86  1.1.10.1  bouyer 	/* check state of IO_AD9 signal latched in GPIO Reset Config reg */
     87  1.1.10.1  bouyer 	r = RMIXL_IOREG_READ(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET_CFG);
     88  1.1.10.1  bouyer 	if ((r & RMIXL_GPIO_RESET_CFG_USB_DEV) == 0) {
     89  1.1.10.1  bouyer 		aprint_error_dev(self,
     90  1.1.10.1  bouyer 			"IO_AD9 selects Device mode, abort Host attach\n");
     91  1.1.10.1  bouyer 		return;
     92  1.1.10.1  bouyer 	}
     93  1.1.10.1  bouyer 
     94  1.1.10.1  bouyer 	sc->sc_dev = self;
     95  1.1.10.1  bouyer 	sc->iot = usbi->usbi_el_bst;
     96  1.1.10.1  bouyer 	sc->sc_size = usbi->usbi_size;
     97  1.1.10.1  bouyer 	sc->sc_bus.dmatag = usbi->usbi_dmat;
     98  1.1.10.1  bouyer 	sc->sc_bus.hci_private = sc;
     99  1.1.10.1  bouyer 
    100  1.1.10.1  bouyer 	if (bus_space_map(sc->iot, usbi->usbi_addr, sc->sc_size, 0, &sc->ioh)) {
    101  1.1.10.1  bouyer 		aprint_error_dev(self, "unable to map registers\n");
    102  1.1.10.1  bouyer 		return;
    103  1.1.10.1  bouyer 	}
    104  1.1.10.1  bouyer 
    105  1.1.10.1  bouyer 	/* Disable OHCI interrupts */
    106  1.1.10.1  bouyer 	bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE,
    107  1.1.10.1  bouyer 				OHCI_ALL_INTRS);
    108  1.1.10.1  bouyer 
    109  1.1.10.1  bouyer 	/* establish interrupt */
    110  1.1.10.1  bouyer 	if (usbi->usbi_intr != RMIXL_USBICF_INTR_DEFAULT) {
    111  1.1.10.1  bouyer 		ih = rmixl_usbi_intr_establish(device_private(parent),
    112  1.1.10.1  bouyer 			usbi->usbi_intr, ohci_intr, sc);
    113  1.1.10.1  bouyer 		if (ih == NULL)
    114  1.1.10.1  bouyer 			panic("%s: couldn't establish interrupt",
    115  1.1.10.1  bouyer 				device_xname(self));
    116  1.1.10.1  bouyer 	}
    117  1.1.10.1  bouyer 
    118  1.1.10.1  bouyer 	/* we handle endianess in bus space */
    119  1.1.10.1  bouyer 	sc->sc_endian = OHCI_HOST_ENDIAN;
    120  1.1.10.1  bouyer 
    121  1.1.10.1  bouyer 	status = ohci_init(sc);
    122  1.1.10.1  bouyer 	if (status != USBD_NORMAL_COMPLETION) {
    123  1.1.10.1  bouyer 		aprint_error_dev(self, "init failed, error=%d\n", status);
    124  1.1.10.1  bouyer 		if (ih != NULL)
    125  1.1.10.1  bouyer 			rmixl_intr_disestablish(ih);
    126  1.1.10.1  bouyer 		return;
    127  1.1.10.1  bouyer 	}
    128  1.1.10.1  bouyer 
    129  1.1.10.1  bouyer 	/* Attach USB device */
    130  1.1.10.1  bouyer 	sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint);
    131  1.1.10.1  bouyer }
    132  1.1.10.1  bouyer 
    133