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