1 /*
2  * linux/arch/arm/mach-omap2/usb-musb.c
3  *
4  * This file will contain the board specific details for the
5  * MENTOR USB OTG controller on OMAP3430
6  *
7  * Copyright (C) 2007-2008 Texas Instruments
8  * Copyright (C) 2008 Nokia Corporation
9  * Author: Vikram Pandita
10  *
11  * Generalization by:
12  * Felipe Balbi <felipe.balbi@nokia.com>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License version 2 as
16  * published by the Free Software Foundation.
17  */
18 
19 #include <linux/types.h>
20 #include <linux/errno.h>
21 #include <linux/delay.h>
22 #include <linux/platform_device.h>
23 #include <linux/clk.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/io.h>
26 
27 #include <linux/usb/musb.h>
28 
29 #include <mach/hardware.h>
30 #include <mach/irqs.h>
31 #include <mach/am35xx.h>
32 #include <plat/usb.h>
33 #include <plat/omap_device.h>
34 #include "mux.h"
35 
36 static struct musb_hdrc_config musb_config = {
37 	.multipoint	= 1,
38 	.dyn_fifo	= 1,
39 	.num_eps	= 16,
40 	.ram_bits	= 12,
41 };
42 
43 static struct musb_hdrc_platform_data musb_plat = {
44 #ifdef CONFIG_USB_MUSB_OTG
45 	.mode		= MUSB_OTG,
46 #elif defined(CONFIG_USB_MUSB_HDRC_HCD)
47 	.mode		= MUSB_HOST,
48 #elif defined(CONFIG_USB_GADGET_MUSB_HDRC)
49 	.mode		= MUSB_PERIPHERAL,
50 #endif
51 	/* .clock is set dynamically */
52 	.config		= &musb_config,
53 
54 	/* REVISIT charge pump on TWL4030 can supply up to
55 	 * 100 mA ... but this value is board-specific, like
56 	 * "mode", and should be passed to usb_musb_init().
57 	 */
58 	.power		= 50,			/* up to 100 mA */
59 };
60 
61 static u64 musb_dmamask = DMA_BIT_MASK(32);
62 
63 static struct omap_musb_board_data musb_default_board_data = {
64 	.interface_type		= MUSB_INTERFACE_ULPI,
65 	.mode			= MUSB_OTG,
66 	.power			= 100,
67 };
68 
usb_musb_init(struct omap_musb_board_data * musb_board_data)69 void __init usb_musb_init(struct omap_musb_board_data *musb_board_data)
70 {
71 	struct omap_hwmod		*oh;
72 	struct platform_device		*pdev;
73 	struct device			*dev;
74 	int				bus_id = -1;
75 	const char			*oh_name, *name;
76 	struct omap_musb_board_data	*board_data;
77 
78 	if (musb_board_data)
79 		board_data = musb_board_data;
80 	else
81 		board_data = &musb_default_board_data;
82 
83 	/*
84 	 * REVISIT: This line can be removed once all the platforms using
85 	 * musb_core.c have been converted to use use clkdev.
86 	 */
87 	musb_plat.clock = "ick";
88 	musb_plat.board_data = board_data;
89 	musb_plat.power = board_data->power >> 1;
90 	musb_plat.mode = board_data->mode;
91 	musb_plat.extvbus = board_data->extvbus;
92 
93 	if (cpu_is_omap3517() || cpu_is_omap3505()) {
94 		oh_name = "am35x_otg_hs";
95 		name = "musb-am35x";
96 	} else if (cpu_is_ti81xx()) {
97 		oh_name = "usb_otg_hs";
98 		name = "musb-ti81xx";
99 	} else {
100 		oh_name = "usb_otg_hs";
101 		name = "musb-omap2430";
102 	}
103 
104         oh = omap_hwmod_lookup(oh_name);
105         if (WARN(!oh, "%s: could not find omap_hwmod for %s\n",
106                  __func__, oh_name))
107                 return;
108 
109 	pdev = omap_device_build(name, bus_id, oh, &musb_plat,
110 			       sizeof(musb_plat), NULL, 0, false);
111 	if (IS_ERR(pdev)) {
112 		pr_err("Could not build omap_device for %s %s\n",
113 						name, oh_name);
114 		return;
115 	}
116 
117 	dev = &pdev->dev;
118 	get_device(dev);
119 	dev->dma_mask = &musb_dmamask;
120 	dev->coherent_dma_mask = musb_dmamask;
121 	put_device(dev);
122 
123 	if (cpu_is_omap44xx())
124 		omap4430_phy_init(dev);
125 }
126