2 * linux/arch/arm/mach-omap2/usb-tusb6010.c
4 * Copyright (C) 2006 Nokia Corporation
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.
11 #include <linux/string.h>
12 #include <linux/types.h>
13 #include <linux/errno.h>
14 #include <linux/delay.h>
15 #include <linux/platform_device.h>
16 #include <linux/gpio.h>
17 #include <linux/export.h>
19 #include <linux/usb/musb.h>
21 #include <plat/gpmc.h>
25 static u8 async_cs
, sync_cs
;
26 static unsigned refclk_psec
;
29 /* t2_ps, when quantized to fclk units, must happen no earlier than
30 * the clock after after t1_NS.
32 * Return a possibly updated value of t2_ps, converted to nsec.
35 next_clk(unsigned t1_NS
, unsigned t2_ps
, unsigned fclk_ps
)
37 unsigned t1_ps
= t1_NS
* 1000;
40 if ((t1_ps
+ fclk_ps
) < t2_ps
)
43 t1_f
= (t1_ps
+ fclk_ps
- 1) / fclk_ps
;
44 t2_f
= (t2_ps
+ fclk_ps
- 1) / fclk_ps
;
49 return (t2_f
* fclk_ps
) / 1000;
52 /* NOTE: timings are from tusb 6010 datasheet Rev 1.8, 12-Sept 2006 */
54 static int tusb_set_async_mode(unsigned sysclk_ps
, unsigned fclk_ps
)
56 struct gpmc_timings t
;
57 unsigned t_acsnh_advnh
= sysclk_ps
+ 3000;
60 memset(&t
, 0, sizeof(t
));
62 /* CS_ON = t_acsnh_acsnl */
64 /* ADV_ON = t_acsnh_advnh - t_advn */
65 t
.adv_on
= next_clk(t
.cs_on
, t_acsnh_advnh
- 7000, fclk_ps
);
68 * READ ... from omap2420 TRM fig 12-13
71 /* ADV_RD_OFF = t_acsnh_advnh */
72 t
.adv_rd_off
= next_clk(t
.adv_on
, t_acsnh_advnh
, fclk_ps
);
74 /* OE_ON = t_acsnh_advnh + t_advn_oen (then wait for nRDY) */
75 t
.oe_on
= next_clk(t
.adv_on
, t_acsnh_advnh
+ 1000, fclk_ps
);
77 /* ACCESS = counters continue only after nRDY */
78 tmp
= t
.oe_on
* 1000 + 300;
79 t
.access
= next_clk(t
.oe_on
, tmp
, fclk_ps
);
81 /* OE_OFF = after data gets sampled */
82 tmp
= t
.access
* 1000;
83 t
.oe_off
= next_clk(t
.access
, tmp
, fclk_ps
);
85 t
.cs_rd_off
= t
.oe_off
;
87 tmp
= t
.cs_rd_off
* 1000 + 7000 /* t_acsn_rdy_z */;
88 t
.rd_cycle
= next_clk(t
.cs_rd_off
, tmp
, fclk_ps
);
91 * WRITE ... from omap2420 TRM fig 12-15
94 /* ADV_WR_OFF = t_acsnh_advnh */
95 t
.adv_wr_off
= t
.adv_rd_off
;
97 /* WE_ON = t_acsnh_advnh + t_advn_wen (then wait for nRDY) */
98 t
.we_on
= next_clk(t
.adv_wr_off
, t_acsnh_advnh
+ 1000, fclk_ps
);
100 /* WE_OFF = after data gets sampled */
101 tmp
= t
.we_on
* 1000 + 300;
102 t
.we_off
= next_clk(t
.we_on
, tmp
, fclk_ps
);
104 t
.cs_wr_off
= t
.we_off
;
106 tmp
= t
.cs_wr_off
* 1000 + 7000 /* t_acsn_rdy_z */;
107 t
.wr_cycle
= next_clk(t
.cs_wr_off
, tmp
, fclk_ps
);
109 return gpmc_cs_set_timings(async_cs
, &t
);
112 static int tusb_set_sync_mode(unsigned sysclk_ps
, unsigned fclk_ps
)
114 struct gpmc_timings t
;
115 unsigned t_scsnh_advnh
= sysclk_ps
+ 3000;
118 memset(&t
, 0, sizeof(t
));
121 /* ADV_ON = t_acsnh_advnh - t_advn */
122 t
.adv_on
= next_clk(t
.cs_on
, t_scsnh_advnh
- 7000, fclk_ps
);
124 /* GPMC_CLK rate = fclk rate / div */
125 t
.sync_clk
= 11100 /* 11.1 nsec */;
126 tmp
= (t
.sync_clk
+ fclk_ps
- 1) / fclk_ps
;
131 t
.page_burst_access
= (fclk_ps
* tmp
) / 1000;
134 * READ ... based on omap2420 TRM fig 12-19, 12-20
137 /* ADV_RD_OFF = t_scsnh_advnh */
138 t
.adv_rd_off
= next_clk(t
.adv_on
, t_scsnh_advnh
, fclk_ps
);
140 /* OE_ON = t_scsnh_advnh + t_advn_oen * fclk_ps (then wait for nRDY) */
141 tmp
= (t
.adv_rd_off
* 1000) + (3 * fclk_ps
);
142 t
.oe_on
= next_clk(t
.adv_on
, tmp
, fclk_ps
);
144 /* ACCESS = number of clock cycles after t_adv_eon */
145 tmp
= (t
.oe_on
* 1000) + (5 * fclk_ps
);
146 t
.access
= next_clk(t
.oe_on
, tmp
, fclk_ps
);
148 /* OE_OFF = after data gets sampled */
149 tmp
= (t
.access
* 1000) + (1 * fclk_ps
);
150 t
.oe_off
= next_clk(t
.access
, tmp
, fclk_ps
);
152 t
.cs_rd_off
= t
.oe_off
;
154 tmp
= t
.cs_rd_off
* 1000 + 7000 /* t_scsn_rdy_z */;
155 t
.rd_cycle
= next_clk(t
.cs_rd_off
, tmp
, fclk_ps
);
158 * WRITE ... based on omap2420 TRM fig 12-21
161 /* ADV_WR_OFF = t_scsnh_advnh */
162 t
.adv_wr_off
= t
.adv_rd_off
;
164 /* WE_ON = t_scsnh_advnh + t_advn_wen * fclk_ps (then wait for nRDY) */
165 tmp
= (t
.adv_wr_off
* 1000) + (3 * fclk_ps
);
166 t
.we_on
= next_clk(t
.adv_wr_off
, tmp
, fclk_ps
);
168 /* WE_OFF = number of clock cycles after t_adv_wen */
169 tmp
= (t
.we_on
* 1000) + (6 * fclk_ps
);
170 t
.we_off
= next_clk(t
.we_on
, tmp
, fclk_ps
);
172 t
.cs_wr_off
= t
.we_off
;
174 tmp
= t
.cs_wr_off
* 1000 + 7000 /* t_scsn_rdy_z */;
175 t
.wr_cycle
= next_clk(t
.cs_wr_off
, tmp
, fclk_ps
);
177 return gpmc_cs_set_timings(sync_cs
, &t
);
180 extern unsigned long gpmc_get_fclk_period(void);
182 /* tusb driver calls this when it changes the chip's clocking */
183 int tusb6010_platform_retime(unsigned is_refclk
)
185 static const char error
[] =
186 KERN_ERR
"tusb6010 %s retime error %d\n";
188 unsigned fclk_ps
= gpmc_get_fclk_period();
192 if (!refclk_psec
|| fclk_ps
== 0)
195 sysclk_ps
= is_refclk
? refclk_psec
: TUSB6010_OSCCLK_60
;
197 status
= tusb_set_async_mode(sysclk_ps
, fclk_ps
);
199 printk(error
, "async", status
);
202 status
= tusb_set_sync_mode(sysclk_ps
, fclk_ps
);
204 printk(error
, "sync", status
);
208 EXPORT_SYMBOL_GPL(tusb6010_platform_retime
);
210 static struct resource tusb_resources
[] = {
211 /* Order is significant! The start/end fields
212 * are updated during setup..
214 { /* Asynchronous access */
215 .flags
= IORESOURCE_MEM
,
217 { /* Synchronous access */
218 .flags
= IORESOURCE_MEM
,
222 .flags
= IORESOURCE_IRQ
,
226 static u64 tusb_dmamask
= ~(u32
)0;
228 static struct platform_device tusb_device
= {
232 .dma_mask
= &tusb_dmamask
,
233 .coherent_dma_mask
= 0xffffffff,
235 .num_resources
= ARRAY_SIZE(tusb_resources
),
236 .resource
= tusb_resources
,
240 /* this may be called only from board-*.c setup code */
242 tusb6010_setup_interface(struct musb_hdrc_platform_data
*data
,
243 unsigned ps_refclk
, unsigned waitpin
,
244 unsigned async
, unsigned sync
,
245 unsigned irq
, unsigned dmachan
)
248 static char error
[] __initdata
=
249 KERN_ERR
"tusb6010 init error %d, %d\n";
251 /* ASYNC region, primarily for PIO */
252 status
= gpmc_cs_request(async
, SZ_16M
, (unsigned long *)
253 &tusb_resources
[0].start
);
255 printk(error
, 1, status
);
258 tusb_resources
[0].end
= tusb_resources
[0].start
+ 0x9ff;
260 gpmc_cs_write_reg(async
, GPMC_CS_CONFIG1
,
261 GPMC_CONFIG1_PAGE_LEN(2)
262 | GPMC_CONFIG1_WAIT_READ_MON
263 | GPMC_CONFIG1_WAIT_WRITE_MON
264 | GPMC_CONFIG1_WAIT_PIN_SEL(waitpin
)
265 | GPMC_CONFIG1_READTYPE_ASYNC
266 | GPMC_CONFIG1_WRITETYPE_ASYNC
267 | GPMC_CONFIG1_DEVICESIZE_16
268 | GPMC_CONFIG1_DEVICETYPE_NOR
269 | GPMC_CONFIG1_MUXADDDATA
);
272 /* SYNC region, primarily for DMA */
273 status
= gpmc_cs_request(sync
, SZ_16M
, (unsigned long *)
274 &tusb_resources
[1].start
);
276 printk(error
, 2, status
);
279 tusb_resources
[1].end
= tusb_resources
[1].start
+ 0x9ff;
281 gpmc_cs_write_reg(sync
, GPMC_CS_CONFIG1
,
282 GPMC_CONFIG1_READMULTIPLE_SUPP
283 | GPMC_CONFIG1_READTYPE_SYNC
284 | GPMC_CONFIG1_WRITEMULTIPLE_SUPP
285 | GPMC_CONFIG1_WRITETYPE_SYNC
286 | GPMC_CONFIG1_CLKACTIVATIONTIME(1)
287 | GPMC_CONFIG1_PAGE_LEN(2)
288 | GPMC_CONFIG1_WAIT_READ_MON
289 | GPMC_CONFIG1_WAIT_WRITE_MON
290 | GPMC_CONFIG1_WAIT_PIN_SEL(waitpin
)
291 | GPMC_CONFIG1_DEVICESIZE_16
292 | GPMC_CONFIG1_DEVICETYPE_NOR
293 | GPMC_CONFIG1_MUXADDDATA
294 /* fclk divider gets set later */
298 status
= gpio_request_one(irq
, GPIOF_IN
, "TUSB6010 irq");
300 printk(error
, 3, status
);
303 tusb_resources
[2].start
= irq
+ IH_GPIO_BASE
;
305 /* set up memory timings ... can speed them up later */
307 printk(error
, 4, status
);
310 refclk_psec
= ps_refclk
;
311 status
= tusb6010_platform_retime(1);
313 printk(error
, 5, status
);
317 /* finish device setup ... */
319 printk(error
, 6, status
);
322 tusb_device
.dev
.platform_data
= data
;
324 /* REVISIT let the driver know what DMA channels work */
326 tusb_device
.dev
.dma_mask
= NULL
;
328 /* assume OMAP 2420 ES2.0 and later */
329 if (dmachan
& (1 << 0))
330 omap_mux_init_signal("sys_ndmareq0", 0);
331 if (dmachan
& (1 << 1))
332 omap_mux_init_signal("sys_ndmareq1", 0);
333 if (dmachan
& (1 << 2))
334 omap_mux_init_signal("sys_ndmareq2", 0);
335 if (dmachan
& (1 << 3))
336 omap_mux_init_signal("sys_ndmareq3", 0);
337 if (dmachan
& (1 << 4))
338 omap_mux_init_signal("sys_ndmareq4", 0);
339 if (dmachan
& (1 << 5))
340 omap_mux_init_signal("sys_ndmareq5", 0);
343 /* so far so good ... register the device */
344 status
= platform_device_register(&tusb_device
);
346 printk(error
, 7, status
);