Commit | Line | Data |
---|---|---|
c1ed6407 DB |
1 | /* |
2 | * linux/arch/arm/mach-omap2/usb-tusb6010.c | |
3 | * | |
4 | * Copyright (C) 2006 Nokia Corporation | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | */ | |
10 | ||
d44b28c4 | 11 | #include <linux/string.h> |
c1ed6407 DB |
12 | #include <linux/types.h> |
13 | #include <linux/errno.h> | |
14 | #include <linux/delay.h> | |
15 | #include <linux/platform_device.h> | |
f2d18fea | 16 | #include <linux/gpio.h> |
dc28094b | 17 | #include <linux/export.h> |
e8c4a7ac | 18 | #include <linux/platform_data/usb-omap.h> |
c1ed6407 DB |
19 | |
20 | #include <linux/usb/musb.h> | |
21 | ||
3ef5d007 | 22 | #include "gpmc.h" |
c1ed6407 | 23 | |
f99bf16d | 24 | #include "mux.h" |
c1ed6407 DB |
25 | |
26 | static u8 async_cs, sync_cs; | |
27 | static unsigned refclk_psec; | |
28 | ||
c3be5b45 JH |
29 | static struct gpmc_settings tusb_async = { |
30 | .mux_add_data = GPMC_MUX_AD, | |
31 | }; | |
32 | ||
33 | static struct gpmc_settings tusb_sync = { | |
34 | .sync_read = true, | |
35 | .sync_write = true, | |
36 | .mux_add_data = GPMC_MUX_AD, | |
37 | }; | |
c1ed6407 | 38 | |
c1ed6407 DB |
39 | /* NOTE: timings are from tusb 6010 datasheet Rev 1.8, 12-Sept 2006 */ |
40 | ||
47acde16 | 41 | static int tusb_set_async_mode(unsigned sysclk_ps) |
c1ed6407 | 42 | { |
47acde16 | 43 | struct gpmc_device_timings dev_t; |
c1ed6407 DB |
44 | struct gpmc_timings t; |
45 | unsigned t_acsnh_advnh = sysclk_ps + 3000; | |
c1ed6407 | 46 | |
47acde16 | 47 | memset(&dev_t, 0, sizeof(dev_t)); |
c1ed6407 | 48 | |
47acde16 AM |
49 | dev_t.t_ceasu = 8 * 1000; |
50 | dev_t.t_avdasu = t_acsnh_advnh - 7000; | |
51 | dev_t.t_ce_avd = 1000; | |
52 | dev_t.t_avdp_r = t_acsnh_advnh; | |
53 | dev_t.t_oeasu = t_acsnh_advnh + 1000; | |
54 | dev_t.t_oe = 300; | |
55 | dev_t.t_cez_r = 7000; | |
56 | dev_t.t_cez_w = dev_t.t_cez_r; | |
57 | dev_t.t_avdp_w = t_acsnh_advnh; | |
58 | dev_t.t_weasu = t_acsnh_advnh + 1000; | |
59 | dev_t.t_wpl = 300; | |
60 | dev_t.cyc_aavdh_we = 1; | |
c1ed6407 | 61 | |
c3be5b45 | 62 | gpmc_calc_timings(&t, &tusb_async, &dev_t); |
c1ed6407 DB |
63 | |
64 | return gpmc_cs_set_timings(async_cs, &t); | |
65 | } | |
66 | ||
47acde16 | 67 | static int tusb_set_sync_mode(unsigned sysclk_ps) |
c1ed6407 | 68 | { |
47acde16 | 69 | struct gpmc_device_timings dev_t; |
c1ed6407 DB |
70 | struct gpmc_timings t; |
71 | unsigned t_scsnh_advnh = sysclk_ps + 3000; | |
c1ed6407 | 72 | |
47acde16 AM |
73 | memset(&dev_t, 0, sizeof(dev_t)); |
74 | ||
47acde16 AM |
75 | dev_t.clk = 11100; |
76 | dev_t.t_bacc = 1000; | |
77 | dev_t.t_ces = 1000; | |
78 | dev_t.t_ceasu = 8 * 1000; | |
79 | dev_t.t_avdasu = t_scsnh_advnh - 7000; | |
80 | dev_t.t_ce_avd = 1000; | |
81 | dev_t.t_avdp_r = t_scsnh_advnh; | |
82 | dev_t.cyc_aavdh_oe = 3; | |
83 | dev_t.cyc_oe = 5; | |
84 | dev_t.t_ce_rdyz = 7000; | |
85 | dev_t.t_avdp_w = t_scsnh_advnh; | |
86 | dev_t.cyc_aavdh_we = 3; | |
87 | dev_t.cyc_wpl = 6; | |
88 | dev_t.t_ce_rdyz = 7000; | |
89 | ||
c3be5b45 | 90 | gpmc_calc_timings(&t, &tusb_sync, &dev_t); |
559d94b0 | 91 | |
c1ed6407 DB |
92 | return gpmc_cs_set_timings(sync_cs, &t); |
93 | } | |
94 | ||
c1ed6407 DB |
95 | /* tusb driver calls this when it changes the chip's clocking */ |
96 | int tusb6010_platform_retime(unsigned is_refclk) | |
97 | { | |
98 | static const char error[] = | |
99 | KERN_ERR "tusb6010 %s retime error %d\n"; | |
100 | ||
c1ed6407 DB |
101 | unsigned sysclk_ps; |
102 | int status; | |
103 | ||
47acde16 | 104 | if (!refclk_psec) |
c1ed6407 DB |
105 | return -ENODEV; |
106 | ||
107 | sysclk_ps = is_refclk ? refclk_psec : TUSB6010_OSCCLK_60; | |
108 | ||
47acde16 | 109 | status = tusb_set_async_mode(sysclk_ps); |
c1ed6407 DB |
110 | if (status < 0) { |
111 | printk(error, "async", status); | |
112 | goto done; | |
113 | } | |
47acde16 | 114 | status = tusb_set_sync_mode(sysclk_ps); |
c1ed6407 DB |
115 | if (status < 0) |
116 | printk(error, "sync", status); | |
117 | done: | |
118 | return status; | |
119 | } | |
120 | EXPORT_SYMBOL_GPL(tusb6010_platform_retime); | |
121 | ||
122 | static struct resource tusb_resources[] = { | |
123 | /* Order is significant! The start/end fields | |
124 | * are updated during setup.. | |
125 | */ | |
126 | { /* Asynchronous access */ | |
127 | .flags = IORESOURCE_MEM, | |
128 | }, | |
129 | { /* Synchronous access */ | |
130 | .flags = IORESOURCE_MEM, | |
131 | }, | |
132 | { /* IRQ */ | |
6ec1e077 | 133 | .name = "mc", |
c1ed6407 DB |
134 | .flags = IORESOURCE_IRQ, |
135 | }, | |
136 | }; | |
137 | ||
138 | static u64 tusb_dmamask = ~(u32)0; | |
139 | ||
140 | static struct platform_device tusb_device = { | |
18688fbe | 141 | .name = "musb-tusb", |
c1ed6407 DB |
142 | .id = -1, |
143 | .dev = { | |
144 | .dma_mask = &tusb_dmamask, | |
145 | .coherent_dma_mask = 0xffffffff, | |
146 | }, | |
147 | .num_resources = ARRAY_SIZE(tusb_resources), | |
148 | .resource = tusb_resources, | |
149 | }; | |
150 | ||
151 | ||
152 | /* this may be called only from board-*.c setup code */ | |
153 | int __init | |
154 | tusb6010_setup_interface(struct musb_hdrc_platform_data *data, | |
155 | unsigned ps_refclk, unsigned waitpin, | |
156 | unsigned async, unsigned sync, | |
157 | unsigned irq, unsigned dmachan) | |
158 | { | |
159 | int status; | |
160 | static char error[] __initdata = | |
161 | KERN_ERR "tusb6010 init error %d, %d\n"; | |
162 | ||
163 | /* ASYNC region, primarily for PIO */ | |
164 | status = gpmc_cs_request(async, SZ_16M, (unsigned long *) | |
165 | &tusb_resources[0].start); | |
166 | if (status < 0) { | |
167 | printk(error, 1, status); | |
168 | return status; | |
169 | } | |
170 | tusb_resources[0].end = tusb_resources[0].start + 0x9ff; | |
171 | async_cs = async; | |
172 | gpmc_cs_write_reg(async, GPMC_CS_CONFIG1, | |
173 | GPMC_CONFIG1_PAGE_LEN(2) | |
174 | | GPMC_CONFIG1_WAIT_READ_MON | |
175 | | GPMC_CONFIG1_WAIT_WRITE_MON | |
176 | | GPMC_CONFIG1_WAIT_PIN_SEL(waitpin) | |
177 | | GPMC_CONFIG1_READTYPE_ASYNC | |
178 | | GPMC_CONFIG1_WRITETYPE_ASYNC | |
179 | | GPMC_CONFIG1_DEVICESIZE_16 | |
180 | | GPMC_CONFIG1_DEVICETYPE_NOR | |
181 | | GPMC_CONFIG1_MUXADDDATA); | |
182 | ||
183 | ||
184 | /* SYNC region, primarily for DMA */ | |
185 | status = gpmc_cs_request(sync, SZ_16M, (unsigned long *) | |
186 | &tusb_resources[1].start); | |
187 | if (status < 0) { | |
188 | printk(error, 2, status); | |
189 | return status; | |
190 | } | |
191 | tusb_resources[1].end = tusb_resources[1].start + 0x9ff; | |
192 | sync_cs = sync; | |
193 | gpmc_cs_write_reg(sync, GPMC_CS_CONFIG1, | |
194 | GPMC_CONFIG1_READMULTIPLE_SUPP | |
195 | | GPMC_CONFIG1_READTYPE_SYNC | |
196 | | GPMC_CONFIG1_WRITEMULTIPLE_SUPP | |
197 | | GPMC_CONFIG1_WRITETYPE_SYNC | |
c1ed6407 DB |
198 | | GPMC_CONFIG1_PAGE_LEN(2) |
199 | | GPMC_CONFIG1_WAIT_READ_MON | |
200 | | GPMC_CONFIG1_WAIT_WRITE_MON | |
201 | | GPMC_CONFIG1_WAIT_PIN_SEL(waitpin) | |
202 | | GPMC_CONFIG1_DEVICESIZE_16 | |
203 | | GPMC_CONFIG1_DEVICETYPE_NOR | |
204 | | GPMC_CONFIG1_MUXADDDATA | |
205 | /* fclk divider gets set later */ | |
206 | ); | |
207 | ||
208 | /* IRQ */ | |
bc593f5d | 209 | status = gpio_request_one(irq, GPIOF_IN, "TUSB6010 irq"); |
c1ed6407 DB |
210 | if (status < 0) { |
211 | printk(error, 3, status); | |
212 | return status; | |
213 | } | |
3d09b33f | 214 | tusb_resources[2].start = gpio_to_irq(irq); |
c1ed6407 DB |
215 | |
216 | /* set up memory timings ... can speed them up later */ | |
217 | if (!ps_refclk) { | |
218 | printk(error, 4, status); | |
219 | return -ENODEV; | |
220 | } | |
221 | refclk_psec = ps_refclk; | |
222 | status = tusb6010_platform_retime(1); | |
223 | if (status < 0) { | |
224 | printk(error, 5, status); | |
225 | return status; | |
226 | } | |
227 | ||
228 | /* finish device setup ... */ | |
229 | if (!data) { | |
230 | printk(error, 6, status); | |
231 | return -ENODEV; | |
232 | } | |
c1ed6407 DB |
233 | tusb_device.dev.platform_data = data; |
234 | ||
235 | /* REVISIT let the driver know what DMA channels work */ | |
236 | if (!dmachan) | |
237 | tusb_device.dev.dma_mask = NULL; | |
238 | else { | |
239 | /* assume OMAP 2420 ES2.0 and later */ | |
240 | if (dmachan & (1 << 0)) | |
f99bf16d | 241 | omap_mux_init_signal("sys_ndmareq0", 0); |
c1ed6407 | 242 | if (dmachan & (1 << 1)) |
f99bf16d | 243 | omap_mux_init_signal("sys_ndmareq1", 0); |
c1ed6407 | 244 | if (dmachan & (1 << 2)) |
f99bf16d | 245 | omap_mux_init_signal("sys_ndmareq2", 0); |
c1ed6407 | 246 | if (dmachan & (1 << 3)) |
f99bf16d | 247 | omap_mux_init_signal("sys_ndmareq3", 0); |
c1ed6407 | 248 | if (dmachan & (1 << 4)) |
f99bf16d | 249 | omap_mux_init_signal("sys_ndmareq4", 0); |
c1ed6407 | 250 | if (dmachan & (1 << 5)) |
f99bf16d | 251 | omap_mux_init_signal("sys_ndmareq5", 0); |
c1ed6407 DB |
252 | } |
253 | ||
254 | /* so far so good ... register the device */ | |
255 | status = platform_device_register(&tusb_device); | |
256 | if (status < 0) { | |
257 | printk(error, 7, status); | |
258 | return status; | |
259 | } | |
260 | return 0; | |
261 | } |