Home | History | Annotate | Line # | Download | only in samsung
exynos_ohci.c revision 1.5.2.1
      1  1.5.2.1   thorpej /* $NetBSD: exynos_ohci.c,v 1.5.2.1 2021/03/21 21:08:56 thorpej Exp $ */
      2      1.1     marty 
      3      1.1     marty /*-
      4      1.3  jmcneill  * Copyright (c) 2015-2018 Jared McNeill <jmcneill (at) invisible.ca>
      5      1.1     marty  * All rights reserved.
      6      1.1     marty  *
      7      1.1     marty  * Redistribution and use in source and binary forms, with or without
      8      1.1     marty  * modification, are permitted provided that the following conditions
      9      1.1     marty  * are met:
     10      1.1     marty  * 1. Redistributions of source code must retain the above copyright
     11      1.1     marty  *    notice, this list of conditions and the following disclaimer.
     12      1.1     marty  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1     marty  *    notice, this list of conditions and the following disclaimer in the
     14      1.1     marty  *    documentation and/or other materials provided with the distribution.
     15      1.1     marty  *
     16      1.3  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17      1.3  jmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18      1.3  jmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19      1.3  jmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20      1.3  jmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21      1.3  jmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22      1.3  jmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23      1.3  jmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24      1.3  jmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25      1.3  jmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26      1.3  jmcneill  * SUCH DAMAGE.
     27      1.1     marty  */
     28      1.1     marty 
     29      1.1     marty #include <sys/cdefs.h>
     30  1.5.2.1   thorpej __KERNEL_RCSID(0, "$NetBSD: exynos_ohci.c,v 1.5.2.1 2021/03/21 21:08:56 thorpej Exp $");
     31      1.1     marty 
     32      1.1     marty #include <sys/param.h>
     33      1.3  jmcneill #include <sys/bus.h>
     34      1.3  jmcneill #include <sys/device.h>
     35      1.3  jmcneill #include <sys/intr.h>
     36      1.1     marty #include <sys/systm.h>
     37      1.1     marty #include <sys/kernel.h>
     38      1.1     marty 
     39      1.1     marty #include <dev/usb/usb.h>
     40      1.1     marty #include <dev/usb/usbdi.h>
     41      1.1     marty #include <dev/usb/usbdivar.h>
     42      1.1     marty #include <dev/usb/usb_mem.h>
     43      1.1     marty #include <dev/usb/ohcireg.h>
     44      1.1     marty #include <dev/usb/ohcivar.h>
     45      1.1     marty 
     46      1.1     marty #include <dev/fdt/fdtvar.h>
     47      1.1     marty 
     48      1.1     marty static int	exynos_ohci_match(device_t, cfdata_t, void *);
     49      1.1     marty static void	exynos_ohci_attach(device_t, device_t, void *);
     50      1.1     marty 
     51      1.3  jmcneill CFATTACH_DECL2_NEW(exynos_ohci, sizeof(struct ohci_softc),
     52      1.3  jmcneill 	exynos_ohci_match, exynos_ohci_attach, NULL,
     53      1.3  jmcneill 	ohci_activate, NULL, ohci_childdet);
     54      1.1     marty 
     55      1.4   thorpej static const struct device_compatible_entry compat_data[] = {
     56      1.4   thorpej 	{ .compat = "samsung,exynos4210-ohci" },
     57      1.4   thorpej 	DEVICE_COMPAT_EOL
     58      1.4   thorpej };
     59      1.4   thorpej 
     60      1.1     marty static int
     61      1.1     marty exynos_ohci_match(device_t parent, cfdata_t cf, void *aux)
     62      1.1     marty {
     63      1.1     marty 	struct fdt_attach_args * const faa = aux;
     64      1.3  jmcneill 
     65      1.4   thorpej 	return of_compatible_match(faa->faa_phandle, compat_data);
     66      1.1     marty }
     67      1.1     marty 
     68      1.1     marty static void
     69      1.1     marty exynos_ohci_attach(device_t parent, device_t self, void *aux)
     70      1.1     marty {
     71      1.3  jmcneill 	struct ohci_softc * const sc = device_private(self);
     72      1.1     marty 	struct fdt_attach_args * const faa = aux;
     73      1.3  jmcneill 	const int phandle = faa->faa_phandle;
     74      1.3  jmcneill 	struct fdtbus_phy *phy;
     75      1.3  jmcneill 	struct clk *clk;
     76      1.3  jmcneill 	char intrstr[128];
     77      1.1     marty 	bus_addr_t addr;
     78      1.1     marty 	bus_size_t size;
     79      1.3  jmcneill 	int error, child;
     80      1.3  jmcneill 	void *ih;
     81      1.1     marty 
     82      1.3  jmcneill 	if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
     83      1.1     marty 		aprint_error(": couldn't get registers\n");
     84      1.1     marty 		return;
     85      1.1     marty 	}
     86      1.1     marty 
     87      1.3  jmcneill 	/* Enable clocks */
     88      1.3  jmcneill 	clk = fdtbus_clock_get(phandle, "usbhost");
     89      1.3  jmcneill 	if (clk == NULL || clk_enable(clk) != 0) {
     90      1.3  jmcneill 		aprint_error(": couldn't enable clock\n");
     91      1.3  jmcneill 		return;
     92      1.3  jmcneill 	}
     93      1.3  jmcneill 
     94      1.3  jmcneill 	/* Enable phys for each port */
     95      1.3  jmcneill 	for (child = OF_child(phandle); child; child = OF_peer(child)) {
     96      1.3  jmcneill 		phy = fdtbus_phy_get_index(child, 0);
     97      1.3  jmcneill 		if (phy && fdtbus_phy_enable(phy, true) != 0)
     98      1.3  jmcneill 			aprint_error(": couldn't enable phy for %s\n",
     99      1.3  jmcneill 			    fdtbus_get_string(child, "name"));
    100      1.3  jmcneill 	}
    101      1.3  jmcneill 
    102      1.1     marty 	sc->sc_dev = self;
    103      1.3  jmcneill 	sc->sc_bus.ub_hcpriv = sc;
    104      1.3  jmcneill 	sc->sc_bus.ub_dmatag = faa->faa_dmat;
    105      1.3  jmcneill 	sc->sc_flags = 0;
    106      1.3  jmcneill 	sc->sc_size = size;
    107      1.1     marty 	sc->iot = faa->faa_bst;
    108      1.3  jmcneill 	if (bus_space_map(sc->iot, addr, size, 0, &sc->ioh) != 0) {
    109      1.3  jmcneill 		aprint_error(": couldn't map registers\n");
    110      1.3  jmcneill 		return;
    111      1.3  jmcneill 	}
    112      1.3  jmcneill 
    113      1.3  jmcneill 	aprint_naive("\n");
    114      1.3  jmcneill 	aprint_normal(": Exynos OHCI\n");
    115      1.3  jmcneill 
    116      1.3  jmcneill 	/* Disable interrupts */
    117      1.3  jmcneill 	bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE,
    118      1.3  jmcneill 	    OHCI_ALL_INTRS);
    119      1.1     marty 
    120      1.3  jmcneill 	if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
    121      1.3  jmcneill 		aprint_error_dev(self, "failed to decode interrupt\n");
    122      1.1     marty 		return;
    123      1.1     marty 	}
    124      1.1     marty 
    125      1.5     skrll 	ih = fdtbus_intr_establish_xname(phandle, 0, IPL_USB, FDT_INTR_MPSAFE,
    126      1.5     skrll 	    ohci_intr, sc, device_xname(self));
    127      1.3  jmcneill 	if (ih == NULL) {
    128      1.3  jmcneill 		aprint_error_dev(self, "couldn't establish interrupt on %s\n",
    129      1.3  jmcneill 		    intrstr);
    130      1.3  jmcneill 		return;
    131      1.3  jmcneill 	}
    132      1.3  jmcneill 	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
    133      1.1     marty 
    134      1.2     skrll 	error = ohci_init(sc);
    135      1.2     skrll 	if (error) {
    136      1.2     skrll 		aprint_error_dev(self, "init failed, error = %d\n", error);
    137      1.1     marty 		return;
    138      1.1     marty 	}
    139      1.3  jmcneill 
    140  1.5.2.1   thorpej 	sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint, CFARG_EOL);
    141      1.1     marty }
    142