summaryrefslogtreecommitdiff
path: root/arch/arm/mach-mx27/usb.c
blob: 3aa63e3dab4b9268f04fabf9747ae0547c744b32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
/*
 * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
 */

/*
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 */

/*!
 * @defgroup USB_MX27 ARC OTG USB Driver for i.MX27
 * @ingroup USB
 */

/*!
 * @file mach-mx27/usb.c
 *
 * @brief platform related part of usb driver.
 * @ingroup USB_MX27
 */

/*!
 *Include files
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/fsl_devices.h>
#include <linux/usb/fsl_xcvr.h>
#include <linux/usb/otg.h>

#include <asm/io.h>
#include <asm/irq.h>
#include <asm/system.h>
#include <asm/hardware.h>
#include <asm/mach-types.h>
#include <asm/arch/arc_otg.h>

extern struct platform_device *host_pdev_register(struct resource *res,
						  int n_res,
						  struct fsl_usb2_platform_data
						  *config);
extern int fsl_usb_host_init(struct platform_device *pdev);
extern void fsl_usb_host_uninit(struct fsl_usb2_platform_data *pdata);
extern int usbotg_init(struct platform_device *pdev);
extern void usbotg_uninit(struct fsl_usb2_platform_data *pdata);
extern int gpio_usbh1_active(void);
extern void gpio_usbh1_inactive(void);
extern int gpio_usbh2_active(void);
extern void gpio_usbh2_inactive(void);
extern int gpio_usbotg_hs_active(void);
extern void gpio_usbotg_hs_inactive(void);
extern int gpio_usbotg_fs_active(void);
extern void gpio_usbotg_fs_inactive(void);

#ifdef CONFIG_USB_EHCI_ARC_H1
/*!
 * HOST1 config
 */
/* *INDENT-OFF* */
static struct fsl_usb2_platform_data usbh1_config = {
	.name              = "Host 1",
	.platform_init     = fsl_usb_host_init,
	.platform_uninit   = fsl_usb_host_uninit,
	.usbmode           = (u32) &UH1_USBMODE,
	.power_budget      = 500,		/* 500 mA max power */
	.gpio_usb_active   = gpio_usbh1_active,
	.gpio_usb_inactive = gpio_usbh1_inactive,
	.transceiver       = "serial",
};

static struct resource usbh1_resources[] = {
	{
		.start = (u32) (USB_H1REGS_BASE),
		.end   = (u32) (USB_H1REGS_BASE + 0x1ff),
		.flags = IORESOURCE_MEM,
	},
	{
		.start = INT_USB1,
		.flags = IORESOURCE_IRQ,
	},
};
/* *INDENT-ON* */
#endif

#ifdef CONFIG_USB_EHCI_ARC_H2
/*!
 * HOST2 config
 */
/* *INDENT-OFF* */
static struct fsl_usb2_platform_data usbh2_config = {
	.name              = "Host 2",
	.platform_init     = fsl_usb_host_init,
	.platform_uninit   = fsl_usb_host_uninit,
	.usbmode           = (u32) &UH2_USBMODE,
	.viewport          = (u32) &UH2_ULPIVIEW,
	.power_budget      = 500,  /* 500 mA max power */
	.gpio_usb_active   = gpio_usbh2_active,
	.gpio_usb_inactive = gpio_usbh2_inactive,
	.transceiver       = "isp1504",
};

static struct resource usbh2_resources[] = {
	{
		.start = (u32) (USB_H2REGS_BASE),
		.end   = (u32) (USB_H2REGS_BASE + 0x1ff),
		.flags = IORESOURCE_MEM,
	},
	{
		.start = INT_USB2,
		.flags = IORESOURCE_IRQ,
	},
};
/* *INDENT-ON* */
#endif

/*!
 * OTG config
 */
/* *INDENT-OFF* */
#if defined(CONFIG_USB_EHCI_ARC_OTG) || defined(CONFIG_USB_GADGET_ARC) || defined(CONFIG_OTG_BTC_ARC)
#if defined(CONFIG_MC13783_MXC)
static struct fsl_usb2_platform_data mxc_serial_host_config = {
	.name              = "OTG",
	.platform_init     = usbotg_init,
	.platform_uninit   = usbotg_uninit,
	.usbmode           = (u32) &UOG_USBMODE,
	.viewport          = (u32) &UOG_ULPIVIEW,
	.does_otg          = 1,
	.operating_mode    = FSL_USB2_DR_HOST,
	.power_budget      = 500,  /* 500 mA max power */
	.gpio_usb_active   = gpio_usbotg_fs_active,
	.gpio_usb_inactive = gpio_usbotg_fs_inactive,
	.transceiver       = "mc13783",
};
#elif defined(CONFIG_ISP1301_MXC)
static struct fsl_usb2_platform_data mxc_serial_host_config = {
	.name              = "OTG",
	.platform_init     = usbotg_init,
	.platform_uninit   = usbotg_uninit,
	.usbmode           = (u32) &UOG_USBMODE,
	.viewport          = (u32) &UOG_ULPIVIEW,
	.does_otg          = 0,
	.operating_mode    = FSL_USB2_DR_HOST,
	.power_budget      = 500,  /* 500 mA max power */
	.gpio_usb_active   = gpio_usbotg_fs_active,
	.gpio_usb_inactive = gpio_usbotg_fs_inactive,
	.transceiver       = "isp1301",
};
#endif
#if defined(CONFIG_ISP1504_MXC)
static struct fsl_usb2_platform_data mxc_isp1504_config = {
	.name              = "OTG",
	.platform_init     = usbotg_init,
	.platform_uninit   = usbotg_uninit,
	.usbmode           = (u32) &UOG_USBMODE,
	.viewport          = (u32) &UOG_ULPIVIEW,
	.does_otg          = 1,
	.power_budget      = 500,  /* 500 mA max power */
	.gpio_usb_active   = gpio_usbotg_hs_active,
	.gpio_usb_inactive = gpio_usbotg_hs_inactive,
	.transceiver       = "isp1504",
};
#endif

static struct resource otg_resources[] = {
	{
		.start = (u32) (USB_OTGREGS_BASE),
		.end   = (u32) (USB_OTGREGS_BASE + 0x1ff),
		.flags = IORESOURCE_MEM,
	},
	{
		.start = INT_USB3,
		.flags = IORESOURCE_IRQ,
	},
};
#endif
/* *INDENT-ON* */

#if defined(CONFIG_USB_GADGET_ARC) || defined(CONFIG_OTG_BTC_ARC)
/*!
 * OTG Gadget device
 */
static void udc_release(struct device *dev)
{
	/* normally not freed */
}

static u64 udc_dmamask = ~(u32) 0;

#if defined(CONFIG_MC13783_MXC)
static struct fsl_usb2_platform_data mxc_serial_peripheral_config = {
	.name = "OTG",
	.platform_init = usbotg_init,
	.platform_uninit = usbotg_uninit,
	.usbmode = (u32) & UOG_USBMODE,
	.does_otg = 1,
	.operating_mode = FSL_USB2_DR_DEVICE,
	.power_budget = 150,	/* 150 mA max power */
	.gpio_usb_active = gpio_usbotg_fs_active,
	.gpio_usb_inactive = gpio_usbotg_fs_inactive,
	.transceiver = "mc13783",
};
#elif defined(CONFIG_ISP1301_MXC)
static struct fsl_usb2_platform_data mxc_serial_peripheral_config = {
	.name = "OTG",
	.platform_init = usbotg_init,
	.platform_uninit = usbotg_uninit,
	.usbmode = (u32) & UOG_USBMODE,
	.does_otg = 0,
	.operating_mode = FSL_USB2_DR_DEVICE,
	.power_budget = 150,	/* 150 mA max power */
	.gpio_usb_active = gpio_usbotg_fs_active,
	.gpio_usb_inactive = gpio_usbotg_fs_inactive,
	.transceiver = "isp1301",
};
#endif

/* *INDENT-OFF* */
static struct platform_device otg_udc_device = {
	.name = "arc_udc",
	.id   = -1,
	.dev  = {
		.release           = udc_release,
		.dma_mask          = &udc_dmamask,
		.coherent_dma_mask = 0xffffffff,
#if defined(CONFIG_MC13783_MXC) || defined(CONFIG_ISP1301_MXC)
		.platform_data     = &mxc_serial_peripheral_config,
#elif defined(CONFIG_ISP1504_MXC)
		.platform_data     = &mxc_isp1504_config,
#endif
		},
	.resource = otg_resources,
	.num_resources = ARRAY_SIZE(otg_resources),
};
/* *INDENT-ON* */
#endif

#if defined(CONFIG_USB_OTG)
static void pindetect_release(struct device *dev)
{
}

/* *INDENT-OFF* */
static struct resource pindetect_resources[] = {
	{
		.start = (u32) (USB_OTGREGS_BASE),
		.end   = (u32) (USB_OTGREGS_BASE + 0x1ff),
		.flags = IORESOURCE_MEM,
	},
	{
		.start = INT_USB3,
		.flags = IORESOURCE_IRQ,
	},
};

static u64 pindetect_dmamask = ~(u32) 0;

static struct fsl_usb2_platform_data fsl_otg_config = {
	.name            = "fsl_arc",
	.platform_init   = usbotg_init,
	.platform_uninit = usbotg_uninit,
	.usbmode         = (u32) &UOG_USBMODE,
	.power_budget    = 500,		/* 500 mA max power */
#if defined(CONFIG_MC13783_MXC)
	.operating_mode    = FSL_USB2_DR_DEVICE,
	.gpio_usb_active   = gpio_usbotg_fs_active,
	.gpio_usb_inactive = gpio_usbotg_fs_inactive,
	.transceiver       = "mc13783",
#elif defined(CONFIG_ISP1504_MXC)
	.gpio_usb_active   = gpio_usbotg_hs_active,
	.gpio_usb_inactive = gpio_usbotg_hs_inactive,
	.transceiver       = "isp1504",
#endif
};

static struct platform_device fsl_device = {
	.name = "fsl_arc",
	.id   = -1,
	.dev  = {
		.release           = pindetect_release,
		.dma_mask          = &pindetect_dmamask,
		.coherent_dma_mask = 0xffffffff,
		.platform_data     = &fsl_otg_config,
		},
	.resource      = pindetect_resources,
	.num_resources = ARRAY_SIZE(pindetect_resources),
};
#endif				/* CONFIG_USB_OTG */

static int __init mx27_usb_init(void)
{
	struct fsl_usb2_platform_data __attribute__((unused)) *pdata;

	pr_debug("%s: \n", __FUNCTION__);

#ifdef CONFIG_USB_EHCI_ARC_H1
	host_pdev_register(usbh1_resources, ARRAY_SIZE(usbh1_resources),
			   &usbh1_config);
#endif

#ifdef CONFIG_USB_EHCI_ARC_H2
	host_pdev_register(usbh2_resources, ARRAY_SIZE(usbh2_resources),
			   &usbh2_config);
#endif

#ifdef CONFIG_USB_EHCI_ARC_OTG
#if defined(CONFIG_MC13783_MXC)	|| defined(CONFIG_ISP1301_MXC)
	host_pdev_register(otg_resources, ARRAY_SIZE(otg_resources),
			   &mxc_serial_host_config);
#elif defined(CONFIG_ISP1504_MXC)
	host_pdev_register(otg_resources, ARRAY_SIZE(otg_resources),
			   &mxc_isp1504_config);
#endif
#endif

#if defined(CONFIG_USB_GADGET_ARC) || defined(CONFIG_OTG_BTC_ARC)
	if (platform_device_register(&otg_udc_device)) {
		printk(KERN_ERR "usb: can't register OTG Gadget\n");
	} else {
		pdata = otg_udc_device.dev.platform_data;
		printk(KERN_INFO "usb: OTG gadget (%s) registered\n",
		       pdata->transceiver);
	}
#endif

#ifdef CONFIG_USB_OTG
	if (platform_device_register(&fsl_device))
		printk(KERN_ERR "usb: can't register otg device\n");
	else
		printk(KERN_INFO "usb: OTG OTG registered\n");
#endif

	return 0;
}

module_init(mx27_usb_init);