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