Home | History | Annotate | Line # | Download | only in ralink
ralink_ohci.c revision 1.2.26.1
      1  1.2.26.1   tls /*	$NetBSD: ralink_ohci.c,v 1.2.26.1 2014/08/10 06:54:02 tls Exp $	*/
      2       1.2  matt /*-
      3       1.2  matt  * Copyright (c) 2011 CradlePoint Technology, Inc.
      4       1.2  matt  * All rights reserved.
      5       1.2  matt  *
      6       1.2  matt  *
      7       1.2  matt  * Redistribution and use in source and binary forms, with or without
      8       1.2  matt  * modification, are permitted provided that the following conditions
      9       1.2  matt  * are met:
     10       1.2  matt  * 1. Redistributions of source code must retain the above copyright
     11       1.2  matt  *    notice, this list of conditions and the following disclaimer.
     12       1.2  matt  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.2  matt  *    notice, this list of conditions and the following disclaimer in the
     14       1.2  matt  *    documentation and/or other materials provided with the distribution.
     15       1.2  matt  *
     16       1.2  matt  * THIS SOFTWARE IS PROVIDED BY CRADLEPOINT TECHNOLOGY, INC. AND CONTRIBUTORS
     17       1.2  matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18       1.2  matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19       1.2  matt  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
     20       1.2  matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21       1.2  matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22       1.2  matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23       1.2  matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24       1.2  matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25       1.2  matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26       1.2  matt  * POSSIBILITY OF SUCH DAMAGE.
     27       1.2  matt  */
     28       1.2  matt 
     29       1.2  matt /* ralink_ohci.c -- Ralink OHCI USB Driver */
     30       1.2  matt 
     31       1.2  matt #include "ehci.h"
     32       1.2  matt 
     33       1.2  matt #include <sys/cdefs.h>
     34  1.2.26.1   tls __KERNEL_RCSID(0, "$NetBSD: ralink_ohci.c,v 1.2.26.1 2014/08/10 06:54:02 tls Exp $");
     35       1.2  matt 
     36       1.2  matt #include <sys/param.h>
     37       1.2  matt #include <sys/bus.h>
     38       1.2  matt 
     39       1.2  matt #include <dev/usb/usb.h>
     40       1.2  matt #include <dev/usb/usbdi.h>
     41       1.2  matt #include <dev/usb/usbdivar.h>
     42       1.2  matt #include <dev/usb/usb_mem.h>
     43       1.2  matt 
     44       1.2  matt #include <dev/usb/ohcireg.h>
     45       1.2  matt #include <dev/usb/ohcivar.h>
     46       1.2  matt 
     47       1.2  matt #include <mips/ralink/ralink_var.h>
     48       1.2  matt #include <mips/ralink/ralink_reg.h>
     49       1.2  matt #include <mips/ralink/ralink_usbhcvar.h>
     50       1.2  matt 
     51       1.2  matt #define OREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (a))
     52       1.2  matt #define OWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (a), (x))
     53       1.2  matt 
     54       1.2  matt struct ralink_ohci_softc {
     55       1.2  matt 	struct ohci_softc sc_ohci;
     56       1.2  matt #if NEHCI > 0
     57       1.2  matt 	struct ralink_usb_hc sc_hc;
     58       1.2  matt #endif
     59       1.2  matt 	void  *sc_ih;
     60       1.2  matt };
     61       1.2  matt 
     62       1.2  matt static int  ralink_ohci_match(device_t, cfdata_t, void *);
     63       1.2  matt static void ralink_ohci_attach(device_t, device_t, void *);
     64       1.2  matt static int  ralink_ohci_detach(device_t, int);
     65       1.2  matt 
     66       1.2  matt CFATTACH_DECL2_NEW(ralink_ohci, sizeof(struct ralink_ohci_softc),
     67       1.2  matt 	ralink_ohci_match, ralink_ohci_attach, ralink_ohci_detach,
     68       1.2  matt 	ohci_activate, NULL, ohci_childdet);
     69       1.2  matt 
     70       1.2  matt /*
     71       1.2  matt  * ralink_ohci_match
     72       1.2  matt  */
     73       1.2  matt static int
     74       1.2  matt ralink_ohci_match(device_t parent, cfdata_t cf, void *aux)
     75       1.2  matt {
     76       1.2  matt 	return 1;
     77       1.2  matt }
     78       1.2  matt 
     79       1.2  matt /*
     80       1.2  matt  * ralink_ohci_attach
     81       1.2  matt  */
     82       1.2  matt static void
     83       1.2  matt ralink_ohci_attach(device_t parent, device_t self, void *aux)
     84       1.2  matt {
     85       1.2  matt 	struct ralink_ohci_softc * const sc = device_private(self);
     86  1.2.26.1   tls 	const struct mainbus_attach_args * const ma = aux;
     87       1.2  matt 	usbd_status status;
     88       1.2  matt 	int error;
     89       1.2  matt #ifdef RALINK_OHCI_DEBUG
     90       1.2  matt 	const char * const devname = device_xname(self);
     91       1.2  matt #endif
     92       1.2  matt 
     93       1.2  matt 	aprint_naive(": OHCI USB controller\n");
     94       1.2  matt 	aprint_normal(": OHCI USB controller\n");
     95       1.2  matt 
     96       1.2  matt 	sc->sc_ohci.sc_dev = self;
     97       1.2  matt 	sc->sc_ohci.sc_bus.hci_private = sc;
     98       1.2  matt 	sc->sc_ohci.iot = ma->ma_memt;
     99       1.2  matt 	sc->sc_ohci.sc_bus.dmatag = ma->ma_dmat;
    100       1.2  matt 
    101       1.2  matt 	/* Map I/O registers */
    102  1.2.26.1   tls 	if ((error = bus_space_map(sc->sc_ohci.iot, RA_USB_OHCI_BASE,
    103  1.2.26.1   tls 	    RA_USB_BLOCK_SIZE, 0, &sc->sc_ohci.ioh)) != 0) {
    104       1.2  matt 		aprint_error_dev(self, "can't map OHCI registers, "
    105       1.2  matt 			"error=%d\n", error);
    106       1.2  matt 		return;
    107       1.2  matt 	}
    108       1.2  matt 
    109  1.2.26.1   tls 	sc->sc_ohci.sc_size = RA_USB_BLOCK_SIZE;
    110       1.2  matt 
    111       1.2  matt #ifdef RALINK_OHCI_DEBUG
    112       1.2  matt 	printf("%s sc: %p ma: %p\n", devname, sc, ma);
    113       1.2  matt 	printf("%s memt: %p dmat: %p\n", devname, ma->ma_memt, ma->ma_dmat);
    114       1.2  matt 
    115       1.2  matt 	printf("%s: OHCI HcRevision=0x%x\n", devname,
    116       1.2  matt 		OREAD4(&sc->sc_ohci, OHCI_REVISION));
    117       1.2  matt 	printf("%s: OHCI HcControl=0x%x\n", devname,
    118       1.2  matt 		OREAD4(&sc->sc_ohci, OHCI_CONTROL));
    119       1.2  matt 	printf("%s: OHCI HcCommandStatus=0x%x\n", devname,
    120       1.2  matt 		OREAD4(&sc->sc_ohci, OHCI_COMMAND_STATUS));
    121       1.2  matt 	printf("%s: OHCI HcInterruptStatus=0x%x\n", devname,
    122       1.2  matt 		OREAD4(&sc->sc_ohci, OHCI_INTERRUPT_STATUS));
    123       1.2  matt #endif
    124       1.2  matt 
    125       1.2  matt 	/* Disable OHCI interrupts. */
    126       1.2  matt 	OWRITE4(&sc->sc_ohci, OHCI_INTERRUPT_DISABLE, OHCI_ALL_INTRS);
    127       1.2  matt 
    128       1.2  matt 	/* establish the MIPS level interrupt */
    129       1.2  matt 	sc->sc_ih = ra_intr_establish(RA_IRQ_USB, ohci_intr, sc, 0);
    130       1.2  matt 	if (sc->sc_ih == NULL) {
    131       1.2  matt 		aprint_error_dev(self, "unable to establish irq %d\n",
    132       1.2  matt 			RA_IRQ_USB);
    133       1.2  matt 		goto fail_0;
    134       1.2  matt 	}
    135       1.2  matt 
    136       1.2  matt 	/* Set vendor for root hub descriptor. */
    137       1.2  matt 	sc->sc_ohci.sc_id_vendor = 0x1814;
    138       1.2  matt 	strlcpy(sc->sc_ohci.sc_vendor, "Ralink", sizeof(sc->sc_ohci.sc_vendor));
    139       1.2  matt 
    140       1.2  matt 	/* Initialize OHCI */
    141       1.2  matt 	status = ohci_init(&sc->sc_ohci);
    142       1.2  matt 	if (status != USBD_NORMAL_COMPLETION) {
    143       1.2  matt 		aprint_error_dev(self, "init failed, error=%d\n", status);
    144       1.2  matt 		goto fail_0;
    145       1.2  matt 	}
    146       1.2  matt 
    147       1.2  matt #if NEHCI > 0
    148       1.2  matt 	ralink_usb_hc_add(&sc->sc_hc, self);
    149       1.2  matt #endif
    150       1.2  matt 
    151       1.2  matt 	if (!pmf_device_register1(self, ohci_suspend, ohci_resume,
    152       1.2  matt 	    ohci_shutdown))
    153       1.2  matt 		aprint_error_dev(self, "couldn't establish power handler\n");
    154       1.2  matt 
    155       1.2  matt 	/* Attach usb device. */
    156       1.2  matt 	sc->sc_ohci.sc_child = config_found(self, &sc->sc_ohci.sc_bus,
    157       1.2  matt 		usbctlprint);
    158       1.2  matt 
    159       1.2  matt 	return;
    160       1.2  matt 
    161       1.2  matt  fail_0:
    162       1.2  matt 	bus_space_unmap(sc->sc_ohci.iot, sc->sc_ohci.ioh, sc->sc_ohci.sc_size);
    163       1.2  matt 	sc->sc_ohci.sc_size = 0;
    164       1.2  matt }
    165       1.2  matt 
    166       1.2  matt static int
    167       1.2  matt ralink_ohci_detach(device_t self, int flags)
    168       1.2  matt {
    169       1.2  matt 	struct ralink_ohci_softc *sc = device_private(self);
    170       1.2  matt 	int rv;
    171       1.2  matt 
    172       1.2  matt 	pmf_device_deregister(self);
    173       1.2  matt 
    174       1.2  matt 	rv = ohci_detach(&sc->sc_ohci, flags);
    175       1.2  matt 	if (rv != 0)
    176       1.2  matt 		return rv;
    177       1.2  matt 
    178       1.2  matt 	if (sc->sc_ih != NULL) {
    179       1.2  matt 		ra_intr_disestablish(sc->sc_ih);
    180       1.2  matt 		sc->sc_ih = NULL;
    181       1.2  matt 	}
    182       1.2  matt 
    183       1.2  matt 	if (sc->sc_ohci.sc_size == 0) {
    184       1.2  matt 		bus_space_unmap(sc->sc_ohci.iot, sc->sc_ohci.ioh,
    185       1.2  matt 			sc->sc_ohci.sc_size);
    186       1.2  matt 		sc->sc_ohci.sc_size = 0;
    187       1.2  matt 	}
    188       1.2  matt 
    189       1.2  matt #if NEHCI > 0
    190       1.2  matt 	ralink_usb_hc_rem(&sc->sc_hc);
    191       1.2  matt #endif
    192       1.2  matt 
    193       1.2  matt 	return 0;
    194       1.2  matt }
    195