blob: e832bc7b8e2dd77042ef323d68185d8f9a7dd135 [file] [log] [blame]
David Brownellc1ed6402006-12-07 14:03:49 -08001/*
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
Jon Hunter012e3382013-02-21 13:01:47 -060011#include <linux/err.h>
Paul Gortmakerd44b28c2011-07-31 10:52:44 -040012#include <linux/string.h>
David Brownellc1ed6402006-12-07 14:03:49 -080013#include <linux/types.h>
14#include <linux/errno.h>
15#include <linux/delay.h>
16#include <linux/platform_device.h>
Jarkko Nikulaf2d18fe2008-12-10 17:35:30 -080017#include <linux/gpio.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040018#include <linux/export.h>
Felipe Balbie8c4a7a2012-10-24 14:26:19 -070019#include <linux/platform_data/usb-omap.h>
David Brownellc1ed6402006-12-07 14:03:49 -080020
21#include <linux/usb/musb.h>
22
Afzal Mohammed3ef5d002012-10-05 10:37:27 +053023#include "gpmc.h"
David Brownellc1ed6402006-12-07 14:03:49 -080024
Tony Lindgrenf99bf162010-07-05 16:31:40 +030025#include "mux.h"
David Brownellc1ed6402006-12-07 14:03:49 -080026
27static u8 async_cs, sync_cs;
28static unsigned refclk_psec;
29
Jon Hunterc3be5b42013-02-21 13:46:22 -060030static struct gpmc_settings tusb_async = {
Jon Hunter012e3382013-02-21 13:01:47 -060031 .wait_on_read = true,
32 .wait_on_write = true,
33 .device_width = GPMC_DEVWIDTH_16BIT,
Jon Hunterc3be5b42013-02-21 13:46:22 -060034 .mux_add_data = GPMC_MUX_AD,
35};
36
37static struct gpmc_settings tusb_sync = {
Jon Hunter012e3382013-02-21 13:01:47 -060038 .burst_read = true,
39 .burst_write = true,
Jon Hunterc3be5b42013-02-21 13:46:22 -060040 .sync_read = true,
41 .sync_write = true,
Jon Hunter012e3382013-02-21 13:01:47 -060042 .wait_on_read = true,
43 .wait_on_write = true,
44 .burst_len = GPMC_BURST_16,
45 .device_width = GPMC_DEVWIDTH_16BIT,
Jon Hunterc3be5b42013-02-21 13:46:22 -060046 .mux_add_data = GPMC_MUX_AD,
47};
David Brownellc1ed6402006-12-07 14:03:49 -080048
David Brownellc1ed6402006-12-07 14:03:49 -080049/* NOTE: timings are from tusb 6010 datasheet Rev 1.8, 12-Sept 2006 */
50
Afzal Mohammed47acde12012-08-17 12:16:14 +053051static int tusb_set_async_mode(unsigned sysclk_ps)
David Brownellc1ed6402006-12-07 14:03:49 -080052{
Afzal Mohammed47acde12012-08-17 12:16:14 +053053 struct gpmc_device_timings dev_t;
David Brownellc1ed6402006-12-07 14:03:49 -080054 struct gpmc_timings t;
55 unsigned t_acsnh_advnh = sysclk_ps + 3000;
David Brownellc1ed6402006-12-07 14:03:49 -080056
Afzal Mohammed47acde12012-08-17 12:16:14 +053057 memset(&dev_t, 0, sizeof(dev_t));
David Brownellc1ed6402006-12-07 14:03:49 -080058
Afzal Mohammed47acde12012-08-17 12:16:14 +053059 dev_t.t_ceasu = 8 * 1000;
60 dev_t.t_avdasu = t_acsnh_advnh - 7000;
61 dev_t.t_ce_avd = 1000;
62 dev_t.t_avdp_r = t_acsnh_advnh;
63 dev_t.t_oeasu = t_acsnh_advnh + 1000;
64 dev_t.t_oe = 300;
65 dev_t.t_cez_r = 7000;
66 dev_t.t_cez_w = dev_t.t_cez_r;
67 dev_t.t_avdp_w = t_acsnh_advnh;
68 dev_t.t_weasu = t_acsnh_advnh + 1000;
69 dev_t.t_wpl = 300;
70 dev_t.cyc_aavdh_we = 1;
David Brownellc1ed6402006-12-07 14:03:49 -080071
Jon Hunterc3be5b42013-02-21 13:46:22 -060072 gpmc_calc_timings(&t, &tusb_async, &dev_t);
David Brownellc1ed6402006-12-07 14:03:49 -080073
74 return gpmc_cs_set_timings(async_cs, &t);
75}
76
Afzal Mohammed47acde12012-08-17 12:16:14 +053077static int tusb_set_sync_mode(unsigned sysclk_ps)
David Brownellc1ed6402006-12-07 14:03:49 -080078{
Afzal Mohammed47acde12012-08-17 12:16:14 +053079 struct gpmc_device_timings dev_t;
David Brownellc1ed6402006-12-07 14:03:49 -080080 struct gpmc_timings t;
81 unsigned t_scsnh_advnh = sysclk_ps + 3000;
David Brownellc1ed6402006-12-07 14:03:49 -080082
Afzal Mohammed47acde12012-08-17 12:16:14 +053083 memset(&dev_t, 0, sizeof(dev_t));
David Brownellc1ed6402006-12-07 14:03:49 -080084
Afzal Mohammed47acde12012-08-17 12:16:14 +053085 dev_t.clk = 11100;
86 dev_t.t_bacc = 1000;
87 dev_t.t_ces = 1000;
88 dev_t.t_ceasu = 8 * 1000;
89 dev_t.t_avdasu = t_scsnh_advnh - 7000;
90 dev_t.t_ce_avd = 1000;
91 dev_t.t_avdp_r = t_scsnh_advnh;
92 dev_t.cyc_aavdh_oe = 3;
93 dev_t.cyc_oe = 5;
94 dev_t.t_ce_rdyz = 7000;
95 dev_t.t_avdp_w = t_scsnh_advnh;
96 dev_t.cyc_aavdh_we = 3;
97 dev_t.cyc_wpl = 6;
98 dev_t.t_ce_rdyz = 7000;
David Brownellc1ed6402006-12-07 14:03:49 -080099
Jon Hunterc3be5b42013-02-21 13:46:22 -0600100 gpmc_calc_timings(&t, &tusb_sync, &dev_t);
Afzal Mohammed559d94b2012-05-28 17:51:37 +0530101
David Brownellc1ed6402006-12-07 14:03:49 -0800102 return gpmc_cs_set_timings(sync_cs, &t);
103}
104
David Brownellc1ed6402006-12-07 14:03:49 -0800105/* tusb driver calls this when it changes the chip's clocking */
106int tusb6010_platform_retime(unsigned is_refclk)
107{
108 static const char error[] =
109 KERN_ERR "tusb6010 %s retime error %d\n";
110
David Brownellc1ed6402006-12-07 14:03:49 -0800111 unsigned sysclk_ps;
112 int status;
113
Afzal Mohammed47acde12012-08-17 12:16:14 +0530114 if (!refclk_psec)
David Brownellc1ed6402006-12-07 14:03:49 -0800115 return -ENODEV;
116
117 sysclk_ps = is_refclk ? refclk_psec : TUSB6010_OSCCLK_60;
118
Afzal Mohammed47acde12012-08-17 12:16:14 +0530119 status = tusb_set_async_mode(sysclk_ps);
David Brownellc1ed6402006-12-07 14:03:49 -0800120 if (status < 0) {
121 printk(error, "async", status);
122 goto done;
123 }
Afzal Mohammed47acde12012-08-17 12:16:14 +0530124 status = tusb_set_sync_mode(sysclk_ps);
David Brownellc1ed6402006-12-07 14:03:49 -0800125 if (status < 0)
126 printk(error, "sync", status);
127done:
128 return status;
129}
130EXPORT_SYMBOL_GPL(tusb6010_platform_retime);
131
132static struct resource tusb_resources[] = {
133 /* Order is significant! The start/end fields
134 * are updated during setup..
135 */
136 { /* Asynchronous access */
137 .flags = IORESOURCE_MEM,
138 },
139 { /* Synchronous access */
140 .flags = IORESOURCE_MEM,
141 },
142 { /* IRQ */
Felipe Balbi6ec1e072010-12-23 12:17:49 -0800143 .name = "mc",
David Brownellc1ed6402006-12-07 14:03:49 -0800144 .flags = IORESOURCE_IRQ,
145 },
146};
147
148static u64 tusb_dmamask = ~(u32)0;
149
150static struct platform_device tusb_device = {
Felipe Balbi18688fb2010-12-02 09:13:54 +0200151 .name = "musb-tusb",
David Brownellc1ed6402006-12-07 14:03:49 -0800152 .id = -1,
153 .dev = {
154 .dma_mask = &tusb_dmamask,
155 .coherent_dma_mask = 0xffffffff,
156 },
157 .num_resources = ARRAY_SIZE(tusb_resources),
158 .resource = tusb_resources,
159};
160
161
162/* this may be called only from board-*.c setup code */
163int __init
164tusb6010_setup_interface(struct musb_hdrc_platform_data *data,
165 unsigned ps_refclk, unsigned waitpin,
166 unsigned async, unsigned sync,
167 unsigned irq, unsigned dmachan)
168{
169 int status;
170 static char error[] __initdata =
171 KERN_ERR "tusb6010 init error %d, %d\n";
172
173 /* ASYNC region, primarily for PIO */
174 status = gpmc_cs_request(async, SZ_16M, (unsigned long *)
175 &tusb_resources[0].start);
176 if (status < 0) {
177 printk(error, 1, status);
178 return status;
179 }
180 tusb_resources[0].end = tusb_resources[0].start + 0x9ff;
Jon Hunter012e3382013-02-21 13:01:47 -0600181 tusb_async.wait_pin = waitpin;
David Brownellc1ed6402006-12-07 14:03:49 -0800182 async_cs = async;
David Brownellc1ed6402006-12-07 14:03:49 -0800183
Jon Hunter012e3382013-02-21 13:01:47 -0600184 status = gpmc_cs_program_settings(async_cs, &tusb_async);
185 if (status < 0)
186 return status;
David Brownellc1ed6402006-12-07 14:03:49 -0800187
188 /* SYNC region, primarily for DMA */
189 status = gpmc_cs_request(sync, SZ_16M, (unsigned long *)
190 &tusb_resources[1].start);
191 if (status < 0) {
192 printk(error, 2, status);
193 return status;
194 }
195 tusb_resources[1].end = tusb_resources[1].start + 0x9ff;
Jon Hunter012e3382013-02-21 13:01:47 -0600196 tusb_sync.wait_pin = waitpin;
David Brownellc1ed6402006-12-07 14:03:49 -0800197 sync_cs = sync;
Jon Hunter012e3382013-02-21 13:01:47 -0600198
199 status = gpmc_cs_program_settings(sync_cs, &tusb_sync);
200 if (status < 0)
201 return status;
David Brownellc1ed6402006-12-07 14:03:49 -0800202
203 /* IRQ */
Igor Grinbergbc593f52011-05-03 18:22:09 +0300204 status = gpio_request_one(irq, GPIOF_IN, "TUSB6010 irq");
David Brownellc1ed6402006-12-07 14:03:49 -0800205 if (status < 0) {
206 printk(error, 3, status);
207 return status;
208 }
Tony Lindgren3d09b332012-06-20 07:18:15 -0700209 tusb_resources[2].start = gpio_to_irq(irq);
David Brownellc1ed6402006-12-07 14:03:49 -0800210
211 /* set up memory timings ... can speed them up later */
212 if (!ps_refclk) {
213 printk(error, 4, status);
214 return -ENODEV;
215 }
216 refclk_psec = ps_refclk;
217 status = tusb6010_platform_retime(1);
218 if (status < 0) {
219 printk(error, 5, status);
220 return status;
221 }
222
223 /* finish device setup ... */
224 if (!data) {
225 printk(error, 6, status);
226 return -ENODEV;
227 }
David Brownellc1ed6402006-12-07 14:03:49 -0800228 tusb_device.dev.platform_data = data;
229
230 /* REVISIT let the driver know what DMA channels work */
231 if (!dmachan)
232 tusb_device.dev.dma_mask = NULL;
233 else {
234 /* assume OMAP 2420 ES2.0 and later */
235 if (dmachan & (1 << 0))
Tony Lindgrenf99bf162010-07-05 16:31:40 +0300236 omap_mux_init_signal("sys_ndmareq0", 0);
David Brownellc1ed6402006-12-07 14:03:49 -0800237 if (dmachan & (1 << 1))
Tony Lindgrenf99bf162010-07-05 16:31:40 +0300238 omap_mux_init_signal("sys_ndmareq1", 0);
David Brownellc1ed6402006-12-07 14:03:49 -0800239 if (dmachan & (1 << 2))
Tony Lindgrenf99bf162010-07-05 16:31:40 +0300240 omap_mux_init_signal("sys_ndmareq2", 0);
David Brownellc1ed6402006-12-07 14:03:49 -0800241 if (dmachan & (1 << 3))
Tony Lindgrenf99bf162010-07-05 16:31:40 +0300242 omap_mux_init_signal("sys_ndmareq3", 0);
David Brownellc1ed6402006-12-07 14:03:49 -0800243 if (dmachan & (1 << 4))
Tony Lindgrenf99bf162010-07-05 16:31:40 +0300244 omap_mux_init_signal("sys_ndmareq4", 0);
David Brownellc1ed6402006-12-07 14:03:49 -0800245 if (dmachan & (1 << 5))
Tony Lindgrenf99bf162010-07-05 16:31:40 +0300246 omap_mux_init_signal("sys_ndmareq5", 0);
David Brownellc1ed6402006-12-07 14:03:49 -0800247 }
248
249 /* so far so good ... register the device */
250 status = platform_device_register(&tusb_device);
251 if (status < 0) {
252 printk(error, 7, status);
253 return status;
254 }
255 return 0;
256}