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