xref: /netbsd-src/sys/arch/arm/imx/imx23_usb.c (revision 6cf6fe02a981b55727c49c3d37b0d8191a98c0ee)
1 /* $Id: imx23_usb.c,v 1.1 2013/10/07 17:36:40 matt Exp $ */
2 
3 /*
4  * Copyright (c) 2013 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Petri Laakso.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/param.h>
33 #include <sys/types.h>
34 #include <sys/bus.h>
35 #include <sys/errno.h>
36 
37 #include <arm/pic/picvar.h>
38 
39 #include <dev/usb/usb.h>
40 #include <dev/usb/usbdi.h>
41 #include <dev/usb/usbdivar.h>
42 #include <dev/usb/usb_mem.h>
43 #include <dev/usb/ehcireg.h>
44 #include <dev/usb/ehcivar.h>
45 #include <arm/imx/imxusbvar.h>
46 
47 #include <arm/mainbus/mainbus.h>
48 
49 #include <arm/imx/imx23_clkctrlvar.h>
50 #include <arm/imx/imx23_digctlvar.h>
51 #include <arm/imx/imx23_pinctrlvar.h>
52 #include <arm/imx/imx23var.h>
53 
54 #include "locators.h"
55 
56 struct imx23_usb_softc {
57 	struct imxusbc_softc  sc_imxusbc;
58 };
59 
60 static int	imx23_usb_match(device_t, cfdata_t, void *);
61 static void	imx23_usb_attach(device_t, device_t, void *);
62 static int	imx23_usb_activate(device_t, enum devact);
63 
64 static int      imxusbc_search(device_t, cfdata_t, const int *, void *);
65 static void	imx23_usb_init(struct imxehci_softc *);
66 
67 CFATTACH_DECL3_NEW(imxusbc,
68         sizeof(struct imx23_usb_softc),
69         imx23_usb_match,
70         imx23_usb_attach,
71         NULL,
72         imx23_usb_activate,
73         NULL,
74         NULL,
75         0
76 );
77 
78 #define AHB_USB		0x80080000
79 #define AHB_USB_SIZE	0x40000
80 
81 static int
82 imx23_usb_match(device_t parent, cfdata_t match, void *aux)
83 {
84 	struct ahb_attach_args *aa = aux;
85 
86 	if ((aa->aa_addr == AHB_USB) && (aa->aa_size == AHB_USB_SIZE))
87 		return 1;
88 
89 	return 0;
90 }
91 
92 static void
93 imx23_usb_attach(device_t parent, device_t self, void *aux)
94 {
95 	struct imxusbc_softc *sc = device_private(self);
96 
97 	sc->sc_init_md_hook = imx23_usb_init;
98 	sc->sc_setup_md_hook = NULL;
99 	sc->sc_iot = &imx23_bus_space;
100 
101 	if (bus_space_map(sc->sc_iot, AHB_USB, AHB_USB_SIZE, 0, &sc->sc_ioh)) {
102 		aprint_error_dev(sc->sc_dev, "Unable to map bus space");
103 		return;
104 	}
105 
106 	/* Enable PLL outputs for USB PHY. */
107 	clkctrl_en_usb();
108 
109 	/* Enable external USB chip. */
110 	pinctrl_en_usb();
111 
112 	/* USB clock on. */
113 	digctl_usb_clkgate(0);
114 
115 	aprint_normal("\n");
116 
117 	/* attach OTG/EHCI host controllers */
118 	config_search_ia(imxusbc_search, self, "imxusbc", NULL);
119 
120 	return;
121 }
122 
123 static int
124 imx23_usb_activate(device_t self, enum devact act)
125 {
126 	return EOPNOTSUPP;
127 }
128 
129 static int
130 imxusbc_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
131 {
132         struct imxusbc_softc *sc = device_private(parent);
133         struct imxusbc_attach_args aa;
134 
135         aa.aa_iot = sc->sc_iot;
136         aa.aa_ioh = sc->sc_ioh;
137         aa.aa_dmat = &imx23_bus_dma_tag;
138         aa.aa_unit = cf->cf_loc[IMXUSBCCF_UNIT];
139         aa.aa_irq = cf->cf_loc[IMXUSBCCF_IRQ];
140 
141         if (config_match(parent, cf, &aa) > 0)
142                 config_attach(parent, cf, &aa, NULL);
143 
144         return 0;
145 }
146 
147 static
148 void imx23_usb_init(struct imxehci_softc *sc)
149 {
150 
151 	sc->sc_iftype = IMXUSBC_IF_UTMI;
152 
153 	return;
154 }
155