blob: faaf96dca0fa146b0f29efc7e4726a1aaa2140c8 [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
Paul Gortmakerd44b28c2011-07-31 10:52:44 -040011#include <linux/string.h>
David Brownellc1ed6402006-12-07 14:03:49 -080012#include <linux/types.h>
13#include <linux/errno.h>
14#include <linux/delay.h>
15#include <linux/platform_device.h>
Jarkko Nikulaf2d18fe2008-12-10 17:35:30 -080016#include <linux/gpio.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040017#include <linux/export.h>
Felipe Balbie8c4a7a2012-10-24 14:26:19 -070018#include <linux/platform_data/usb-omap.h>
David Brownellc1ed6402006-12-07 14:03:49 -080019
20#include <linux/usb/musb.h>
21
Afzal Mohammed3ef5d002012-10-05 10:37:27 +053022#include "gpmc.h"
David Brownellc1ed6402006-12-07 14:03:49 -080023
Tony Lindgrenf99bf162010-07-05 16:31:40 +030024#include "mux.h"
David Brownellc1ed6402006-12-07 14:03:49 -080025
26static u8 async_cs, sync_cs;
27static unsigned refclk_psec;
28
Jon Hunterc3be5b42013-02-21 13:46:22 -060029static struct gpmc_settings tusb_async = {
30 .mux_add_data = GPMC_MUX_AD,
31};
32
33static struct gpmc_settings tusb_sync = {
34 .sync_read = true,
35 .sync_write = true,
36 .mux_add_data = GPMC_MUX_AD,
37};
David Brownellc1ed6402006-12-07 14:03:49 -080038
David Brownellc1ed6402006-12-07 14:03:49 -080039/* NOTE: timings are from tusb 6010 datasheet Rev 1.8, 12-Sept 2006 */
40
Afzal Mohammed47acde12012-08-17 12:16:14 +053041static int tusb_set_async_mode(unsigned sysclk_ps)
David Brownellc1ed6402006-12-07 14:03:49 -080042{
Afzal Mohammed47acde12012-08-17 12:16:14 +053043 struct gpmc_device_timings dev_t;
David Brownellc1ed6402006-12-07 14:03:49 -080044 struct gpmc_timings t;
45 unsigned t_acsnh_advnh = sysclk_ps + 3000;
David Brownellc1ed6402006-12-07 14:03:49 -080046
Afzal Mohammed47acde12012-08-17 12:16:14 +053047 memset(&dev_t, 0, sizeof(dev_t));
David Brownellc1ed6402006-12-07 14:03:49 -080048
Afzal Mohammed47acde12012-08-17 12:16:14 +053049 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;
David Brownellc1ed6402006-12-07 14:03:49 -080061
Jon Hunterc3be5b42013-02-21 13:46:22 -060062 gpmc_calc_timings(&t, &tusb_async, &dev_t);
David Brownellc1ed6402006-12-07 14:03:49 -080063
64 return gpmc_cs_set_timings(async_cs, &t);
65}
66
Afzal Mohammed47acde12012-08-17 12:16:14 +053067static int tusb_set_sync_mode(unsigned sysclk_ps)
David Brownellc1ed6402006-12-07 14:03:49 -080068{
Afzal Mohammed47acde12012-08-17 12:16:14 +053069 struct gpmc_device_timings dev_t;
David Brownellc1ed6402006-12-07 14:03:49 -080070 struct gpmc_timings t;
71 unsigned t_scsnh_advnh = sysclk_ps + 3000;
David Brownellc1ed6402006-12-07 14:03:49 -080072
Afzal Mohammed47acde12012-08-17 12:16:14 +053073 memset(&dev_t, 0, sizeof(dev_t));
David Brownellc1ed6402006-12-07 14:03:49 -080074
Afzal Mohammed47acde12012-08-17 12:16:14 +053075 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;
David Brownellc1ed6402006-12-07 14:03:49 -080089
Jon Hunterc3be5b42013-02-21 13:46:22 -060090 gpmc_calc_timings(&t, &tusb_sync, &dev_t);
Afzal Mohammed559d94b2012-05-28 17:51:37 +053091
David Brownellc1ed6402006-12-07 14:03:49 -080092 return gpmc_cs_set_timings(sync_cs, &t);
93}
94
David Brownellc1ed6402006-12-07 14:03:49 -080095/* tusb driver calls this when it changes the chip's clocking */
96int tusb6010_platform_retime(unsigned is_refclk)
97{
98 static const char error[] =
99 KERN_ERR "tusb6010 %s retime error %d\n";
100
David Brownellc1ed6402006-12-07 14:03:49 -0800101 unsigned sysclk_ps;
102 int status;
103
Afzal Mohammed47acde12012-08-17 12:16:14 +0530104 if (!refclk_psec)
David Brownellc1ed6402006-12-07 14:03:49 -0800105 return -ENODEV;
106
107 sysclk_ps = is_refclk ? refclk_psec : TUSB6010_OSCCLK_60;
108
Afzal Mohammed47acde12012-08-17 12:16:14 +0530109 status = tusb_set_async_mode(sysclk_ps);
David Brownellc1ed6402006-12-07 14:03:49 -0800110 if (status < 0) {
111 printk(error, "async", status);
112 goto done;
113 }
Afzal Mohammed47acde12012-08-17 12:16:14 +0530114 status = tusb_set_sync_mode(sysclk_ps);
David Brownellc1ed6402006-12-07 14:03:49 -0800115 if (status < 0)
116 printk(error, "sync", status);
117done:
118 return status;
119}
120EXPORT_SYMBOL_GPL(tusb6010_platform_retime);
121
122static 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 */
Felipe Balbi6ec1e072010-12-23 12:17:49 -0800133 .name = "mc",
David Brownellc1ed6402006-12-07 14:03:49 -0800134 .flags = IORESOURCE_IRQ,
135 },
136};
137
138static u64 tusb_dmamask = ~(u32)0;
139
140static struct platform_device tusb_device = {
Felipe Balbi18688fb2010-12-02 09:13:54 +0200141 .name = "musb-tusb",
David Brownellc1ed6402006-12-07 14:03:49 -0800142 .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 */
153int __init
154tusb6010_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
David Brownellc1ed6402006-12-07 14:03:49 -0800198 | 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 */
Igor Grinbergbc593f52011-05-03 18:22:09 +0300209 status = gpio_request_one(irq, GPIOF_IN, "TUSB6010 irq");
David Brownellc1ed6402006-12-07 14:03:49 -0800210 if (status < 0) {
211 printk(error, 3, status);
212 return status;
213 }
Tony Lindgren3d09b332012-06-20 07:18:15 -0700214 tusb_resources[2].start = gpio_to_irq(irq);
David Brownellc1ed6402006-12-07 14:03:49 -0800215
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 }
David Brownellc1ed6402006-12-07 14:03:49 -0800233 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))
Tony Lindgrenf99bf162010-07-05 16:31:40 +0300241 omap_mux_init_signal("sys_ndmareq0", 0);
David Brownellc1ed6402006-12-07 14:03:49 -0800242 if (dmachan & (1 << 1))
Tony Lindgrenf99bf162010-07-05 16:31:40 +0300243 omap_mux_init_signal("sys_ndmareq1", 0);
David Brownellc1ed6402006-12-07 14:03:49 -0800244 if (dmachan & (1 << 2))
Tony Lindgrenf99bf162010-07-05 16:31:40 +0300245 omap_mux_init_signal("sys_ndmareq2", 0);
David Brownellc1ed6402006-12-07 14:03:49 -0800246 if (dmachan & (1 << 3))
Tony Lindgrenf99bf162010-07-05 16:31:40 +0300247 omap_mux_init_signal("sys_ndmareq3", 0);
David Brownellc1ed6402006-12-07 14:03:49 -0800248 if (dmachan & (1 << 4))
Tony Lindgrenf99bf162010-07-05 16:31:40 +0300249 omap_mux_init_signal("sys_ndmareq4", 0);
David Brownellc1ed6402006-12-07 14:03:49 -0800250 if (dmachan & (1 << 5))
Tony Lindgrenf99bf162010-07-05 16:31:40 +0300251 omap_mux_init_signal("sys_ndmareq5", 0);
David Brownellc1ed6402006-12-07 14:03:49 -0800252 }
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}