1/* $NetBSD: imx51_usb.c,v 1.7 2021/08/07 16:18:44 thorpej 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.7 2021/08/07 16:18:44 thorpej Exp $"); 29 30#include "locators.h" 31#include "opt_imx.h" 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/conf.h> 36#include <sys/kernel.h> 37#include <sys/device.h> 38#include <sys/intr.h> 39#include <sys/bus.h> 40 41#include <dev/usb/usb.h> 42#include <dev/usb/usbdi.h> 43#include <dev/usb/usbdivar.h> 44#include <dev/usb/usb_mem.h> 45 46#include <dev/usb/ehcireg.h> 47#include <dev/usb/ehcivar.h> 48 49#include <arm/imx/imx51reg.h> 50#include <arm/imx/imx51var.h> 51#include <arm/imx/imxusbvar.h> 52#include <arm/imx/imxusbreg.h> 53 54static int imxusbc_search(device_t, cfdata_t, const int *, void *); 55static int imxusbc_print(void *, const char *); 56 57int 58imxusbc_attach_common(device_t parent, device_t self, bus_space_tag_t iot, 59 bus_addr_t addr, bus_size_t size) 60{ 61 struct imxusbc_softc *sc = device_private(self); 62 63 sc->sc_dev = self; 64 sc->sc_iot = iot; 65 sc->sc_ehci_size = IMXUSB_EHCI_SIZE; 66 sc->sc_ehci_offset = IMXUSB_EHCI_SIZE; 67 68 /* Map entire USBOH3 registers. Host controller drivers 69 * re-use subregions of this. */ 70 if (bus_space_map(iot, addr, size, 0, &sc->sc_ioh)) 71 return -1; 72 73 /* attach OTG/EHCI host controllers */ 74 config_search(self, NULL, 75 CFARGS(.search = imxusbc_search)); 76 77 return 0; 78} 79 80static int 81imxusbc_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux) 82{ 83 struct imxusbc_softc *sc = device_private(parent); 84 struct imxusbc_attach_args aa; 85 86 aa.aa_iot = sc->sc_iot; 87 aa.aa_ioh = sc->sc_ioh; 88 aa.aa_dmat = &arm_generic_dma_tag; 89 aa.aa_unit = cf->cf_loc[IMXUSBCCF_UNIT]; 90 aa.aa_irq = cf->cf_loc[IMXUSBCCF_IRQ]; 91 92 if (config_probe(parent, cf, &aa)) 93 config_attach(parent, cf, &aa, imxusbc_print, CFARGS_NONE); 94 95 return 0; 96} 97 98/* ARGSUSED */ 99static int 100imxusbc_print(void *aux, const char *name __unused) 101{ 102 struct imxusbc_attach_args *aa = aux; 103 104 aprint_normal(" unit %d irq %d", aa->aa_unit, aa->aa_irq); 105 return (UNCONF); 106} 107