Home | History | Annotate | Line # | Download | only in gemini
      1  1.7  thorpej /*	$NetBSD: obio_ehci.c,v 1.7 2021/08/07 16:18:44 thorpej Exp $	*/
      2  1.1     matt 
      3  1.1     matt /*
      4  1.1     matt  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
      5  1.1     matt  * All rights reserved.
      6  1.1     matt  *
      7  1.1     matt  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1     matt  * by Lennart Augustsson (lennart (at) augustsson.net).
      9  1.1     matt  *
     10  1.1     matt  * Redistribution and use in source and binary forms, with or without
     11  1.1     matt  * modification, are permitted provided that the following conditions
     12  1.1     matt  * are met:
     13  1.1     matt  * 1. Redistributions of source code must retain the above copyright
     14  1.1     matt  *    notice, this list of conditions and the following disclaimer.
     15  1.1     matt  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1     matt  *    notice, this list of conditions and the following disclaimer in the
     17  1.1     matt  *    documentation and/or other materials provided with the distribution.
     18  1.1     matt  *
     19  1.1     matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1     matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1     matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1     matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1     matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1     matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1     matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1     matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1     matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1     matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1     matt  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1     matt  */
     31  1.1     matt 
     32  1.1     matt #include <sys/cdefs.h>
     33  1.7  thorpej __KERNEL_RCSID(0, "$NetBSD: obio_ehci.c,v 1.7 2021/08/07 16:18:44 thorpej Exp $");
     34  1.1     matt 
     35  1.1     matt #include "locators.h"
     36  1.1     matt 
     37  1.1     matt #include <sys/param.h>
     38  1.1     matt #include <sys/systm.h>
     39  1.1     matt #include <sys/kernel.h>
     40  1.1     matt #include <sys/device.h>
     41  1.1     matt #include <sys/proc.h>
     42  1.1     matt #include <sys/queue.h>
     43  1.1     matt 
     44  1.1     matt #include <sys/bus.h>
     45  1.1     matt 
     46  1.1     matt #include <arm/gemini/gemini_reg.h>
     47  1.1     matt #include <arm/gemini/gemini_obiovar.h>
     48  1.1     matt 
     49  1.1     matt #include <dev/usb/usb.h>
     50  1.1     matt #include <dev/usb/usbdi.h>
     51  1.1     matt #include <dev/usb/usbdivar.h>
     52  1.1     matt #include <dev/usb/usb_mem.h>
     53  1.1     matt 
     54  1.1     matt #include <dev/usb/ehcireg.h>
     55  1.1     matt #include <dev/usb/ehcivar.h>
     56  1.1     matt 
     57  1.1     matt #ifdef EHCI_DEBUG
     58  1.1     matt #define DPRINTF(x)	if (ehcidebug) printf x
     59  1.1     matt extern int ehcidebug;
     60  1.1     matt #else
     61  1.1     matt #define DPRINTF(x)
     62  1.1     matt #endif
     63  1.1     matt 
     64  1.1     matt #define	EHCI_HCOTGDEV_INTR_STATUS		0xc0
     65  1.1     matt #define	EHCI_HCOTGDEV_INTR_MASK			0xc4
     66  1.1     matt #define	HC_INT					0x04
     67  1.1     matt #define	OTG_INT					0x02
     68  1.1     matt #define	DEV_INT					0x01
     69  1.1     matt 
     70  1.1     matt static int
     71  1.1     matt ehci_obio_intr(void *arg)
     72  1.1     matt {
     73  1.1     matt 	struct ehci_softc * const sc = arg;
     74  1.1     matt 	int rv = 0;
     75  1.1     matt 	uint32_t v;
     76  1.1     matt 
     77  1.1     matt 	v = bus_space_read_4(sc->iot, sc->ioh, EHCI_HCOTGDEV_INTR_STATUS);
     78  1.1     matt 	bus_space_write_4(sc->iot, sc->ioh, EHCI_HCOTGDEV_INTR_STATUS, v);
     79  1.1     matt 	if (v & HC_INT)
     80  1.1     matt 		rv = ehci_intr(sc);
     81  1.1     matt 	return rv;
     82  1.1     matt }
     83  1.1     matt 
     84  1.1     matt static int
     85  1.1     matt ehci_obio_match(device_t parent, cfdata_t match, void *aux)
     86  1.1     matt {
     87  1.1     matt 	struct obio_attach_args * const obio = aux;
     88  1.1     matt 
     89  1.1     matt 	if (obio->obio_addr == GEMINI_USB0_BASE
     90  1.1     matt 	    || obio->obio_addr == GEMINI_USB1_BASE)
     91  1.1     matt 		return 1;
     92  1.1     matt 
     93  1.1     matt 	return 0;
     94  1.1     matt }
     95  1.1     matt 
     96  1.1     matt static void
     97  1.1     matt ehci_obio_attach(device_t parent, device_t self, void *aux)
     98  1.1     matt {
     99  1.1     matt 	struct ehci_softc * const sc = device_private(self);
    100  1.1     matt 	struct obio_attach_args * const obio = aux;
    101  1.1     matt 	const char * const devname = device_xname(self);
    102  1.1     matt 
    103  1.1     matt 	sc->sc_dev = self;
    104  1.4    skrll 	sc->sc_bus.ub_hcpriv = sc;
    105  1.1     matt 	sc->iot = obio->obio_iot;
    106  1.1     matt 
    107  1.1     matt 	aprint_naive(": EHCI USB controller\n");
    108  1.2     matt 	aprint_normal(": EHCI USB controller\n");
    109  1.1     matt 
    110  1.1     matt 	/* Map I/O registers */
    111  1.1     matt 	if (bus_space_map(sc->iot, obio->obio_addr, obio->obio_size, 0,
    112  1.1     matt 			   &sc->ioh)) {
    113  1.1     matt 		aprint_error("%s: can't map memory space\n", devname);
    114  1.1     matt 		return;
    115  1.1     matt 	}
    116  1.1     matt 
    117  1.4    skrll 	sc->sc_bus.ub_dmatag = obio->obio_dmat;
    118  1.1     matt 
    119  1.1     matt 	/* Disable interrupts, so we don't get any spurious ones. */
    120  1.1     matt 	sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH);
    121  1.1     matt 	DPRINTF(("%s: offs=%d\n", devname, sc->sc_offs));
    122  1.3     matt 	EOWRITE4(sc, EHCI_USBINTR, 0);
    123  1.1     matt 	bus_space_write_4(sc->iot, sc->ioh, EHCI_HCOTGDEV_INTR_MASK,
    124  1.1     matt 	    OTG_INT|DEV_INT);
    125  1.1     matt 
    126  1.1     matt 	if (obio->obio_intr != OBIOCF_INTR_DEFAULT) {
    127  1.1     matt 		intr_establish(obio->obio_intr, IPL_USB, IST_LEVEL,
    128  1.1     matt 		    ehci_obio_intr, sc);
    129  1.1     matt 	}
    130  1.1     matt 
    131  1.4    skrll 	sc->sc_bus.ub_revision = USBREV_2_0;
    132  1.1     matt 
    133  1.4    skrll 	int err = ehci_init(sc);
    134  1.4    skrll 	if (err) {
    135  1.4    skrll 		aprint_error("%s: init failed, error=%d\n", devname, err);
    136  1.1     matt 		return;
    137  1.1     matt 	}
    138  1.1     matt 
    139  1.1     matt 	/* Attach usb device. */
    140  1.7  thorpej 	sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint, CFARGS_NONE);
    141  1.1     matt }
    142  1.1     matt 
    143  1.1     matt CFATTACH_DECL2_NEW(ehci_obio, sizeof(struct ehci_softc),
    144  1.1     matt     ehci_obio_match, ehci_obio_attach, NULL, NULL, NULL, ehci_childdet);
    145