OMAP2/3: PM: push core PM code from linux-omap
[linux-2.6] / arch / arm / mach-omap2 / usb-musb.c
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/mux.h>
32 #include <mach/usb.h>
33
34 static struct resource musb_resources[] = {
35         [0] = { /* start and end set dynamically */
36                 .flags  = IORESOURCE_MEM,
37         },
38         [1] = { /* general IRQ */
39                 .start  = INT_243X_HS_USB_MC,
40                 .flags  = IORESOURCE_IRQ,
41         },
42         [2] = { /* DMA IRQ */
43                 .start  = INT_243X_HS_USB_DMA,
44                 .flags  = IORESOURCE_IRQ,
45         },
46 };
47
48 static int clk_on;
49
50 static int musb_set_clock(struct clk *clk, int state)
51 {
52         if (state) {
53                 if (clk_on > 0)
54                         return -ENODEV;
55
56                 clk_enable(clk);
57                 clk_on = 1;
58         } else {
59                 if (clk_on == 0)
60                         return -ENODEV;
61
62                 clk_disable(clk);
63                 clk_on = 0;
64         }
65
66         return 0;
67 }
68
69 static struct musb_hdrc_eps_bits musb_eps[] = {
70         {       "ep1_tx", 10,   },
71         {       "ep1_rx", 10,   },
72         {       "ep2_tx", 9,    },
73         {       "ep2_rx", 9,    },
74         {       "ep3_tx", 3,    },
75         {       "ep3_rx", 3,    },
76         {       "ep4_tx", 3,    },
77         {       "ep4_rx", 3,    },
78         {       "ep5_tx", 3,    },
79         {       "ep5_rx", 3,    },
80         {       "ep6_tx", 3,    },
81         {       "ep6_rx", 3,    },
82         {       "ep7_tx", 3,    },
83         {       "ep7_rx", 3,    },
84         {       "ep8_tx", 2,    },
85         {       "ep8_rx", 2,    },
86         {       "ep9_tx", 2,    },
87         {       "ep9_rx", 2,    },
88         {       "ep10_tx", 2,   },
89         {       "ep10_rx", 2,   },
90         {       "ep11_tx", 2,   },
91         {       "ep11_rx", 2,   },
92         {       "ep12_tx", 2,   },
93         {       "ep12_rx", 2,   },
94         {       "ep13_tx", 2,   },
95         {       "ep13_rx", 2,   },
96         {       "ep14_tx", 2,   },
97         {       "ep14_rx", 2,   },
98         {       "ep15_tx", 2,   },
99         {       "ep15_rx", 2,   },
100 };
101
102 static struct musb_hdrc_config musb_config = {
103         .multipoint     = 1,
104         .dyn_fifo       = 1,
105         .soft_con       = 1,
106         .dma            = 1,
107         .num_eps        = 16,
108         .dma_channels   = 7,
109         .dma_req_chan   = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3),
110         .ram_bits       = 12,
111         .eps_bits       = musb_eps,
112 };
113
114 static struct musb_hdrc_platform_data musb_plat = {
115 #ifdef CONFIG_USB_MUSB_OTG
116         .mode           = MUSB_OTG,
117 #elif defined(CONFIG_USB_MUSB_HDRC_HCD)
118         .mode           = MUSB_HOST,
119 #elif defined(CONFIG_USB_GADGET_MUSB_HDRC)
120         .mode           = MUSB_PERIPHERAL,
121 #endif
122         /* .clock is set dynamically */
123         .set_clock      = musb_set_clock,
124         .config         = &musb_config,
125
126         /* REVISIT charge pump on TWL4030 can supply up to
127          * 100 mA ... but this value is board-specific, like
128          * "mode", and should be passed to usb_musb_init().
129          */
130         .power          = 50,                   /* up to 100 mA */
131 };
132
133 static u64 musb_dmamask = DMA_BIT_MASK(32);
134
135 static struct platform_device musb_device = {
136         .name           = "musb_hdrc",
137         .id             = -1,
138         .dev = {
139                 .dma_mask               = &musb_dmamask,
140                 .coherent_dma_mask      = DMA_BIT_MASK(32),
141                 .platform_data          = &musb_plat,
142         },
143         .num_resources  = ARRAY_SIZE(musb_resources),
144         .resource       = musb_resources,
145 };
146
147 #ifdef CONFIG_NOP_USB_XCEIV
148 static u64 nop_xceiv_dmamask = DMA_BIT_MASK(32);
149
150 static struct platform_device nop_xceiv_device = {
151         .name           = "nop_usb_xceiv",
152         .id             = -1,
153         .dev = {
154                 .dma_mask               = &nop_xceiv_dmamask,
155                 .coherent_dma_mask      = DMA_BIT_MASK(32),
156                 .platform_data          = NULL,
157         },
158 };
159 #endif
160
161 void __init usb_musb_init(void)
162 {
163         if (cpu_is_omap243x())
164                 musb_resources[0].start = OMAP243X_HS_BASE;
165         else
166                 musb_resources[0].start = OMAP34XX_HSUSB_OTG_BASE;
167         musb_resources[0].end = musb_resources[0].start + SZ_8K - 1;
168
169         /*
170          * REVISIT: This line can be removed once all the platforms using
171          * musb_core.c have been converted to use use clkdev.
172          */
173         musb_plat.clock = "ick";
174
175 #ifdef CONFIG_NOP_USB_XCEIV
176         if (platform_device_register(&nop_xceiv_device) < 0) {
177                 printk(KERN_ERR "Unable to register NOP-XCEIV device\n");
178                 return;
179         }
180 #endif
181
182         if (platform_device_register(&musb_device) < 0) {
183                 printk(KERN_ERR "Unable to register HS-USB (MUSB) device\n");
184                 return;
185         }
186 }