blob: 4dab915696e7749e8743b0bf2b5b21c47e09a102 [file] [log] [blame]
Marc St-Jean35832e22007-06-14 15:54:47 -06001/*
2 * The setup file for USB related hardware on PMC-Sierra MSP processors.
3 *
Anoop P A50270702011-01-25 13:52:05 +05304 * Copyright 2006 PMC-Sierra, Inc.
Marc St-Jean35832e22007-06-14 15:54:47 -06005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
12 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
14 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
15 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
17 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
18 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
19 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
20 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
Anoop P A50270702011-01-25 13:52:05 +053026#if defined(CONFIG_USB_EHCI_HCD) || defined(CONFIG_USB_GADGET)
Marc St-Jean35832e22007-06-14 15:54:47 -060027
Marc St-Jean35832e22007-06-14 15:54:47 -060028#include <linux/init.h>
29#include <linux/ioport.h>
30#include <linux/platform_device.h>
31
32#include <asm/mipsregs.h>
33
34#include <msp_regs.h>
35#include <msp_int.h>
36#include <msp_prom.h>
Anoop P A50270702011-01-25 13:52:05 +053037#include <msp_usb.h>
38
Marc St-Jean35832e22007-06-14 15:54:47 -060039
40#if defined(CONFIG_USB_EHCI_HCD)
Anoop P A50270702011-01-25 13:52:05 +053041static struct resource msp_usbhost0_resources[] = {
42 [0] = { /* EHCI-HS operational and capabilities registers */
Ralf Baechle70342282013-01-22 12:59:30 +010043 .start = MSP_USB0_HS_START,
44 .end = MSP_USB0_HS_END,
45 .flags = IORESOURCE_MEM,
Marc St-Jean35832e22007-06-14 15:54:47 -060046 },
47 [1] = {
Ralf Baechle70342282013-01-22 12:59:30 +010048 .start = MSP_INT_USB,
49 .end = MSP_INT_USB,
50 .flags = IORESOURCE_IRQ,
Anoop P A50270702011-01-25 13:52:05 +053051 },
52 [2] = { /* MSBus-to-AMBA bridge register space */
53 .start = MSP_USB0_MAB_START,
54 .end = MSP_USB0_MAB_END,
55 .flags = IORESOURCE_MEM,
56 },
57 [3] = { /* Identification and general hardware parameters */
58 .start = MSP_USB0_ID_START,
59 .end = MSP_USB0_ID_END,
60 .flags = IORESOURCE_MEM,
Marc St-Jean35832e22007-06-14 15:54:47 -060061 },
62};
63
Anoop P A50270702011-01-25 13:52:05 +053064static u64 msp_usbhost0_dma_mask = 0xffffffffUL;
Marc St-Jean35832e22007-06-14 15:54:47 -060065
Anoop P A50270702011-01-25 13:52:05 +053066static struct mspusb_device msp_usbhost0_device = {
Marc St-Jean35832e22007-06-14 15:54:47 -060067 .dev = {
Anoop P A50270702011-01-25 13:52:05 +053068 .name = "pmcmsp-ehci",
69 .id = 0,
70 .dev = {
71 .dma_mask = &msp_usbhost0_dma_mask,
72 .coherent_dma_mask = 0xffffffffUL,
73 },
Ralf Baechle70342282013-01-22 12:59:30 +010074 .num_resources = ARRAY_SIZE(msp_usbhost0_resources),
75 .resource = msp_usbhost0_resources,
Marc St-Jean35832e22007-06-14 15:54:47 -060076 },
Marc St-Jean35832e22007-06-14 15:54:47 -060077};
Marc St-Jean35832e22007-06-14 15:54:47 -060078
Anoop P A50270702011-01-25 13:52:05 +053079/* MSP7140/MSP82XX has two USB2 hosts. */
80#ifdef CONFIG_MSP_HAS_DUAL_USB
81static u64 msp_usbhost1_dma_mask = 0xffffffffUL;
82
83static struct resource msp_usbhost1_resources[] = {
84 [0] = { /* EHCI-HS operational and capabilities registers */
85 .start = MSP_USB1_HS_START,
86 .end = MSP_USB1_HS_END,
Marc St-Jean35832e22007-06-14 15:54:47 -060087 .flags = IORESOURCE_MEM,
88 },
89 [1] = {
90 .start = MSP_INT_USB,
91 .end = MSP_INT_USB,
92 .flags = IORESOURCE_IRQ,
93 },
Anoop P A50270702011-01-25 13:52:05 +053094 [2] = { /* MSBus-to-AMBA bridge register space */
95 .start = MSP_USB1_MAB_START,
96 .end = MSP_USB1_MAB_END,
97 .flags = IORESOURCE_MEM,
Marc St-Jean35832e22007-06-14 15:54:47 -060098 },
Anoop P A50270702011-01-25 13:52:05 +053099 [3] = { /* Identification and general hardware parameters */
100 .start = MSP_USB1_ID_START,
101 .end = MSP_USB1_ID_END,
102 .flags = IORESOURCE_MEM,
103 },
Marc St-Jean35832e22007-06-14 15:54:47 -0600104};
Anoop P A50270702011-01-25 13:52:05 +0530105
106static struct mspusb_device msp_usbhost1_device = {
107 .dev = {
108 .name = "pmcmsp-ehci",
109 .id = 1,
110 .dev = {
111 .dma_mask = &msp_usbhost1_dma_mask,
112 .coherent_dma_mask = 0xffffffffUL,
113 },
114 .num_resources = ARRAY_SIZE(msp_usbhost1_resources),
115 .resource = msp_usbhost1_resources,
116 },
117};
118#endif /* CONFIG_MSP_HAS_DUAL_USB */
119#endif /* CONFIG_USB_EHCI_HCD */
120
121#if defined(CONFIG_USB_GADGET)
122static struct resource msp_usbdev0_resources[] = {
123 [0] = { /* EHCI-HS operational and capabilities registers */
Ralf Baechle70342282013-01-22 12:59:30 +0100124 .start = MSP_USB0_HS_START,
125 .end = MSP_USB0_HS_END,
126 .flags = IORESOURCE_MEM,
Anoop P A50270702011-01-25 13:52:05 +0530127 },
128 [1] = {
Ralf Baechle70342282013-01-22 12:59:30 +0100129 .start = MSP_INT_USB,
130 .end = MSP_INT_USB,
131 .flags = IORESOURCE_IRQ,
Anoop P A50270702011-01-25 13:52:05 +0530132 },
133 [2] = { /* MSBus-to-AMBA bridge register space */
134 .start = MSP_USB0_MAB_START,
135 .end = MSP_USB0_MAB_END,
136 .flags = IORESOURCE_MEM,
137 },
138 [3] = { /* Identification and general hardware parameters */
139 .start = MSP_USB0_ID_START,
140 .end = MSP_USB0_ID_END,
141 .flags = IORESOURCE_MEM,
142 },
143};
144
145static u64 msp_usbdev_dma_mask = 0xffffffffUL;
146
147/* This may need to be converted to a mspusb_device, too. */
148static struct mspusb_device msp_usbdev0_device = {
149 .dev = {
150 .name = "msp71xx_udc",
151 .id = 0,
152 .dev = {
153 .dma_mask = &msp_usbdev_dma_mask,
154 .coherent_dma_mask = 0xffffffffUL,
155 },
Ralf Baechle70342282013-01-22 12:59:30 +0100156 .num_resources = ARRAY_SIZE(msp_usbdev0_resources),
157 .resource = msp_usbdev0_resources,
Anoop P A50270702011-01-25 13:52:05 +0530158 },
159};
160
161#ifdef CONFIG_MSP_HAS_DUAL_USB
162static struct resource msp_usbdev1_resources[] = {
163 [0] = { /* EHCI-HS operational and capabilities registers */
Ralf Baechle70342282013-01-22 12:59:30 +0100164 .start = MSP_USB1_HS_START,
165 .end = MSP_USB1_HS_END,
166 .flags = IORESOURCE_MEM,
Anoop P A50270702011-01-25 13:52:05 +0530167 },
168 [1] = {
Ralf Baechle70342282013-01-22 12:59:30 +0100169 .start = MSP_INT_USB,
170 .end = MSP_INT_USB,
171 .flags = IORESOURCE_IRQ,
Anoop P A50270702011-01-25 13:52:05 +0530172 },
173 [2] = { /* MSBus-to-AMBA bridge register space */
174 .start = MSP_USB1_MAB_START,
175 .end = MSP_USB1_MAB_END,
176 .flags = IORESOURCE_MEM,
177 },
178 [3] = { /* Identification and general hardware parameters */
179 .start = MSP_USB1_ID_START,
180 .end = MSP_USB1_ID_END,
181 .flags = IORESOURCE_MEM,
182 },
183};
184
185/* This may need to be converted to a mspusb_device, too. */
186static struct mspusb_device msp_usbdev1_device = {
187 .dev = {
188 .name = "msp71xx_udc",
189 .id = 0,
190 .dev = {
191 .dma_mask = &msp_usbdev_dma_mask,
192 .coherent_dma_mask = 0xffffffffUL,
193 },
Ralf Baechle70342282013-01-22 12:59:30 +0100194 .num_resources = ARRAY_SIZE(msp_usbdev1_resources),
195 .resource = msp_usbdev1_resources,
Anoop P A50270702011-01-25 13:52:05 +0530196 },
197};
198
199#endif /* CONFIG_MSP_HAS_DUAL_USB */
Marc St-Jean35832e22007-06-14 15:54:47 -0600200#endif /* CONFIG_USB_GADGET */
201
Marc St-Jean35832e22007-06-14 15:54:47 -0600202static int __init msp_usb_setup(void)
203{
Anoop P A50270702011-01-25 13:52:05 +0530204 char *strp;
205 char envstr[32];
206 struct platform_device *msp_devs[NUM_USB_DEVS];
207 unsigned int val;
Marc St-Jean35832e22007-06-14 15:54:47 -0600208
Anoop P A50270702011-01-25 13:52:05 +0530209 /* construct environment name usbmode */
210 /* set usbmode <host/device> as pmon environment var */
Marc St-Jean35832e22007-06-14 15:54:47 -0600211 /*
Anoop P A50270702011-01-25 13:52:05 +0530212 * Could this perhaps be integrated into the "features" env var?
213 * Use the features key "U", and follow with "H" for host-mode,
Ralf Baechle70342282013-01-22 12:59:30 +0100214 * "D" for device-mode. If it works for Ethernet, why not USB...
Anoop P A50270702011-01-25 13:52:05 +0530215 * -- hammtrev, 2007/03/22
Marc St-Jean35832e22007-06-14 15:54:47 -0600216 */
217 snprintf((char *)&envstr[0], sizeof(envstr), "usbmode");
218
Anoop P A50270702011-01-25 13:52:05 +0530219 /* set default host mode */
Marc St-Jean35832e22007-06-14 15:54:47 -0600220 val = 1;
Marc St-Jean35832e22007-06-14 15:54:47 -0600221
222 /* get environment string */
223 strp = prom_getenv((char *)&envstr[0]);
224 if (strp) {
Anoop P A50270702011-01-25 13:52:05 +0530225 /* compare string */
Marc St-Jean35832e22007-06-14 15:54:47 -0600226 if (!strcmp(strp, "device"))
227 val = 0;
228 }
229
230 if (val) {
231#if defined(CONFIG_USB_EHCI_HCD)
Anoop P A50270702011-01-25 13:52:05 +0530232 msp_devs[0] = &msp_usbhost0_device.dev;
233 ppfinit("platform add USB HOST done %s.\n", msp_devs[0]->name);
234#ifdef CONFIG_MSP_HAS_DUAL_USB
235 msp_devs[1] = &msp_usbhost1_device.dev;
236 ppfinit("platform add USB HOST done %s.\n", msp_devs[1]->name);
237#endif
238#else
239 ppfinit("%s: echi_hcd not supported\n", __FILE__);
Ralf Baechle70342282013-01-22 12:59:30 +0100240#endif /* CONFIG_USB_EHCI_HCD */
Anoop P A50270702011-01-25 13:52:05 +0530241 } else {
Marc St-Jean35832e22007-06-14 15:54:47 -0600242#if defined(CONFIG_USB_GADGET)
Marc St-Jean35832e22007-06-14 15:54:47 -0600243 /* get device mode structure */
Anoop P A50270702011-01-25 13:52:05 +0530244 msp_devs[0] = &msp_usbdev0_device.dev;
245 ppfinit("platform add USB DEVICE done %s.\n"
246 , msp_devs[0]->name);
247#ifdef CONFIG_MSP_HAS_DUAL_USB
248 msp_devs[1] = &msp_usbdev1_device.dev;
249 ppfinit("platform add USB DEVICE done %s.\n"
250 , msp_devs[1]->name);
251#endif
252#else
253 ppfinit("%s: usb_gadget not supported\n", __FILE__);
Ralf Baechle70342282013-01-22 12:59:30 +0100254#endif /* CONFIG_USB_GADGET */
Marc St-Jean35832e22007-06-14 15:54:47 -0600255 }
Anoop P A50270702011-01-25 13:52:05 +0530256 /* add device */
257 platform_add_devices(msp_devs, ARRAY_SIZE(msp_devs));
Marc St-Jean35832e22007-06-14 15:54:47 -0600258
Anoop P A50270702011-01-25 13:52:05 +0530259 return 0;
Marc St-Jean35832e22007-06-14 15:54:47 -0600260}
261
262subsys_initcall(msp_usb_setup);
Anoop P A50270702011-01-25 13:52:05 +0530263#endif /* CONFIG_USB_EHCI_HCD || CONFIG_USB_GADGET */