Home | History | Annotate | Line # | Download | only in imx
imx51_usb.c revision 1.5.12.4
      1  1.5.12.4  thorpej /*	$NetBSD: imx51_usb.c,v 1.5.12.4 2021/04/04 22:01:12 thorpej Exp $	*/
      2       1.1      bsh /*
      3       1.1      bsh  * Copyright (c) 2010  Genetec Corporation.  All rights reserved.
      4       1.1      bsh  * Written by Hiroyuki Bessho for Genetec Corporation.
      5       1.1      bsh  *
      6       1.1      bsh  * Redistribution and use in source and binary forms, with or without
      7       1.1      bsh  * modification, are permitted provided that the following conditions
      8       1.1      bsh  * are met:
      9       1.1      bsh  * 1. Redistributions of source code must retain the above copyright
     10       1.1      bsh  *    notice, this list of conditions and the following disclaimer.
     11       1.1      bsh  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.1      bsh  *    notice, this list of conditions and the following disclaimer in the
     13       1.1      bsh  *    documentation and/or other materials provided with the distribution.
     14       1.1      bsh  *
     15       1.1      bsh  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     16       1.1      bsh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17       1.1      bsh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18       1.1      bsh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     19       1.1      bsh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20       1.1      bsh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21       1.1      bsh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22       1.1      bsh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23       1.1      bsh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24       1.1      bsh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25       1.1      bsh  * POSSIBILITY OF SUCH DAMAGE.
     26       1.1      bsh  */
     27       1.1      bsh #include <sys/cdefs.h>
     28  1.5.12.4  thorpej __KERNEL_RCSID(0, "$NetBSD: imx51_usb.c,v 1.5.12.4 2021/04/04 22:01:12 thorpej Exp $");
     29       1.2  hkenken 
     30       1.5  hkenken #include "locators.h"
     31       1.2  hkenken #include "opt_imx.h"
     32       1.1      bsh 
     33       1.1      bsh #include <sys/param.h>
     34       1.1      bsh #include <sys/systm.h>
     35       1.1      bsh #include <sys/conf.h>
     36       1.1      bsh #include <sys/kernel.h>
     37       1.1      bsh #include <sys/device.h>
     38       1.1      bsh #include <sys/intr.h>
     39       1.1      bsh #include <sys/bus.h>
     40       1.1      bsh 
     41       1.1      bsh #include <dev/usb/usb.h>
     42       1.1      bsh #include <dev/usb/usbdi.h>
     43       1.1      bsh #include <dev/usb/usbdivar.h>
     44       1.1      bsh #include <dev/usb/usb_mem.h>
     45       1.1      bsh 
     46       1.1      bsh #include <dev/usb/ehcireg.h>
     47       1.1      bsh #include <dev/usb/ehcivar.h>
     48       1.1      bsh 
     49       1.1      bsh #include <arm/imx/imx51reg.h>
     50       1.1      bsh #include <arm/imx/imx51var.h>
     51       1.1      bsh #include <arm/imx/imxusbvar.h>
     52       1.5  hkenken #include <arm/imx/imxusbreg.h>
     53       1.1      bsh 
     54       1.5  hkenken static int imxusbc_search(device_t, cfdata_t, const int *, void *);
     55       1.5  hkenken static int imxusbc_print(void *, const char *);
     56       1.1      bsh 
     57       1.1      bsh int
     58       1.5  hkenken imxusbc_attach_common(device_t parent, device_t self, bus_space_tag_t iot,
     59       1.5  hkenken     bus_addr_t addr, bus_size_t size)
     60       1.1      bsh {
     61       1.1      bsh 	struct imxusbc_softc *sc = device_private(self);
     62       1.1      bsh 
     63       1.5  hkenken 	sc->sc_dev = self;
     64       1.1      bsh 	sc->sc_iot = iot;
     65       1.5  hkenken 	sc->sc_ehci_size = IMXUSB_EHCI_SIZE;
     66       1.5  hkenken 	sc->sc_ehci_offset = IMXUSB_EHCI_SIZE;
     67       1.1      bsh 
     68       1.1      bsh 	/* Map entire USBOH3 registers.  Host controller drivers
     69       1.1      bsh 	 * re-use subregions of this. */
     70       1.5  hkenken 	if (bus_space_map(iot, addr, size, 0, &sc->sc_ioh))
     71       1.1      bsh 		return -1;
     72       1.1      bsh 
     73       1.1      bsh 	/* attach OTG/EHCI host controllers */
     74  1.5.12.1  thorpej 	config_search(self, NULL,
     75  1.5.12.4  thorpej 	    CFARG_SEARCH, imxusbc_search,
     76  1.5.12.1  thorpej 	    CFARG_EOL);
     77       1.1      bsh 
     78       1.1      bsh 	return 0;
     79       1.1      bsh }
     80       1.1      bsh 
     81       1.1      bsh static int
     82       1.1      bsh imxusbc_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
     83       1.1      bsh {
     84       1.1      bsh 	struct imxusbc_softc *sc = device_private(parent);
     85       1.1      bsh 	struct imxusbc_attach_args aa;
     86       1.1      bsh 
     87       1.5  hkenken 	aa.aa_iot = sc->sc_iot;
     88       1.1      bsh 	aa.aa_ioh = sc->sc_ioh;
     89       1.4      ryo 	aa.aa_dmat = &arm_generic_dma_tag;
     90       1.5  hkenken 	aa.aa_unit = cf->cf_loc[IMXUSBCCF_UNIT];
     91       1.1      bsh 	aa.aa_irq = cf->cf_loc[IMXUSBCCF_IRQ];
     92       1.1      bsh 
     93       1.5  hkenken 	if (config_match(parent, cf, &aa) > 0)
     94  1.5.12.3  thorpej 		config_attach(parent, cf, &aa, imxusbc_print, CFARG_EOL);
     95       1.1      bsh 
     96       1.5  hkenken 	return 0;
     97       1.1      bsh }
     98       1.1      bsh 
     99       1.2  hkenken /* ARGSUSED */
    100       1.2  hkenken static int
    101       1.2  hkenken imxusbc_print(void *aux, const char *name __unused)
    102       1.2  hkenken {
    103       1.2  hkenken 	struct imxusbc_attach_args *aa = aux;
    104       1.2  hkenken 
    105       1.2  hkenken 	aprint_normal(" unit %d irq %d", aa->aa_unit, aa->aa_irq);
    106       1.2  hkenken 	return (UNCONF);
    107       1.2  hkenken }
    108