2 * linux/arch/arm/mach-omap/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/types.h>
12 #include <linux/errno.h>
13 #include <linux/delay.h>
14 #include <linux/platform_device.h>
16 #include <linux/usb/musb.h>
18 #include <asm/arch/gpmc.h>
19 #include <asm/arch/gpio.h>
22 static u8 async_cs, sync_cs;
23 static unsigned refclk_psec;
26 /* t2_ps, when quantized to fclk units, must happen no earlier than
27 * the clock after after t1_NS.
29 * Return a possibly updated value of t2_ps, converted to nsec.
32 next_clk(unsigned t1_NS, unsigned t2_ps, unsigned fclk_ps)
34 unsigned t1_ps = t1_NS * 1000;
37 if ((t1_ps + fclk_ps) < t2_ps)
40 t1_f = (t1_ps + fclk_ps - 1) / fclk_ps;
41 t2_f = (t2_ps + fclk_ps - 1) / fclk_ps;
46 return (t2_f * fclk_ps) / 1000;
49 /* NOTE: timings are from tusb 6010 datasheet Rev 1.8, 12-Sept 2006 */
51 static int tusb_set_async_mode(unsigned sysclk_ps, unsigned fclk_ps)
53 struct gpmc_timings t;
54 unsigned t_acsnh_advnh = sysclk_ps + 3000;
57 memset(&t, 0, sizeof(t));
59 /* CS_ON = t_acsnh_acsnl */
61 /* ADV_ON = t_acsnh_advnh - t_advn */
62 t.adv_on = next_clk(t.cs_on, t_acsnh_advnh - 7000, fclk_ps);
65 * READ ... from omap2420 TRM fig 12-13
68 /* ADV_RD_OFF = t_acsnh_advnh */
69 t.adv_rd_off = next_clk(t.adv_on, t_acsnh_advnh, fclk_ps);
71 /* OE_ON = t_acsnh_advnh + t_advn_oen (then wait for nRDY) */
72 t.oe_on = next_clk(t.adv_on, t_acsnh_advnh + 1000, fclk_ps);
74 /* ACCESS = counters continue only after nRDY */
75 tmp = t.oe_on * 1000 + 300;
76 t.access = next_clk(t.oe_on, tmp, fclk_ps);
78 /* OE_OFF = after data gets sampled */
79 tmp = t.access * 1000;
80 t.oe_off = next_clk(t.access, tmp, fclk_ps);
82 t.cs_rd_off = t.oe_off;
84 tmp = t.cs_rd_off * 1000 + 7000 /* t_acsn_rdy_z */;
85 t.rd_cycle = next_clk(t.cs_rd_off, tmp, fclk_ps);
88 * WRITE ... from omap2420 TRM fig 12-15
91 /* ADV_WR_OFF = t_acsnh_advnh */
92 t.adv_wr_off = t.adv_rd_off;
94 /* WE_ON = t_acsnh_advnh + t_advn_wen (then wait for nRDY) */
95 t.we_on = next_clk(t.adv_wr_off, t_acsnh_advnh + 1000, fclk_ps);
97 /* WE_OFF = after data gets sampled */
98 tmp = t.we_on * 1000 + 300;
99 t.we_off = next_clk(t.we_on, tmp, fclk_ps);
101 t.cs_wr_off = t.we_off;
103 tmp = t.cs_wr_off * 1000 + 7000 /* t_acsn_rdy_z */;
104 t.wr_cycle = next_clk(t.cs_wr_off, tmp, fclk_ps);
106 return gpmc_cs_set_timings(async_cs, &t);
109 static int tusb_set_sync_mode(unsigned sysclk_ps, unsigned fclk_ps)
111 struct gpmc_timings t;
112 unsigned t_scsnh_advnh = sysclk_ps + 3000;
115 memset(&t, 0, sizeof(t));
118 /* ADV_ON = t_acsnh_advnh - t_advn */
119 t.adv_on = next_clk(t.cs_on, t_scsnh_advnh - 7000, fclk_ps);
121 /* GPMC_CLK rate = fclk rate / div */
122 t.sync_clk = 12 /* 11.1 nsec */;
123 tmp = (t.sync_clk * 1000 + fclk_ps - 1) / fclk_ps;
128 t.page_burst_access = (fclk_ps * tmp) / 1000;
131 * READ ... based on omap2420 TRM fig 12-19, 12-20
134 /* ADV_RD_OFF = t_scsnh_advnh */
135 t.adv_rd_off = next_clk(t.adv_on, t_scsnh_advnh, fclk_ps);
137 /* OE_ON = t_scsnh_advnh + t_advn_oen * fclk_ps (then wait for nRDY) */
138 tmp = (t.adv_rd_off * 1000) + (3 * fclk_ps);
139 t.oe_on = next_clk(t.adv_on, tmp, fclk_ps);
141 /* ACCESS = number of clock cycles after t_adv_eon */
142 tmp = (t.oe_on * 1000) + (5 * fclk_ps);
143 t.access = next_clk(t.oe_on, tmp, fclk_ps);
145 /* OE_OFF = after data gets sampled */
146 tmp = (t.access * 1000) + (1 * fclk_ps);
147 t.oe_off = next_clk(t.access, tmp, fclk_ps);
149 t.cs_rd_off = t.oe_off;
151 tmp = t.cs_rd_off * 1000 + 7000 /* t_scsn_rdy_z */;
152 t.rd_cycle = next_clk(t.cs_rd_off, tmp, fclk_ps);
155 * WRITE ... based on omap2420 TRM fig 12-21
158 /* ADV_WR_OFF = t_scsnh_advnh */
159 t.adv_wr_off = t.adv_rd_off;
161 /* WE_ON = t_scsnh_advnh + t_advn_wen * fclk_ps (then wait for nRDY) */
162 tmp = (t.adv_wr_off * 1000) + (3 * fclk_ps);
163 t.we_on = next_clk(t.adv_wr_off, tmp, fclk_ps);
165 /* WE_OFF = number of clock cycles after t_adv_wen */
166 tmp = (t.we_on * 1000) + (6 * fclk_ps);
167 t.we_off = next_clk(t.we_on, tmp, fclk_ps);
169 t.cs_wr_off = t.we_off;
171 tmp = t.cs_wr_off * 1000 + 7000 /* t_scsn_rdy_z */;
172 t.wr_cycle = next_clk(t.cs_wr_off, tmp, fclk_ps);
174 return gpmc_cs_set_timings(sync_cs, &t);
177 extern unsigned long gpmc_get_fclk_period(void);
179 /* tusb driver calls this when it changes the chip's clocking */
180 int tusb6010_platform_retime(unsigned is_refclk)
182 static const char error[] =
183 KERN_ERR "tusb6010 %s retime error %d\n";
185 unsigned fclk_ps = gpmc_get_fclk_period();
192 sysclk_ps = is_refclk ? refclk_psec : TUSB6010_OSCCLK_60;
194 status = tusb_set_async_mode(sysclk_ps, fclk_ps);
196 printk(error, "async", status);
199 status = tusb_set_sync_mode(sysclk_ps, fclk_ps);
201 printk(error, "sync", status);
205 EXPORT_SYMBOL_GPL(tusb6010_platform_retime);
207 static struct resource tusb_resources[] = {
208 /* Order is significant! The start/end fields
209 * are updated during setup..
211 { /* Asynchronous access */
212 .flags = IORESOURCE_MEM,
214 { /* Synchronous access */
215 .flags = IORESOURCE_MEM,
218 .flags = IORESOURCE_IRQ,
222 static u64 tusb_dmamask = ~(u32)0;
224 static struct platform_device tusb_device = {
228 .dma_mask = &tusb_dmamask,
229 .coherent_dma_mask = 0xffffffff,
231 .num_resources = ARRAY_SIZE(tusb_resources),
232 .resource = tusb_resources,
236 /* this may be called only from board-*.c setup code */
238 tusb6010_setup_interface(struct musb_hdrc_platform_data *data,
239 unsigned ps_refclk, unsigned waitpin,
240 unsigned async, unsigned sync,
241 unsigned irq, unsigned dmachan)
244 static char error[] __initdata =
245 KERN_ERR "tusb6010 init error %d, %d\n";
247 /* ASYNC region, primarily for PIO */
248 status = gpmc_cs_request(async, SZ_16M, (unsigned long *)
249 &tusb_resources[0].start);
251 printk(error, 1, status);
254 tusb_resources[0].end = tusb_resources[0].start + 0x9ff;
256 gpmc_cs_write_reg(async, GPMC_CS_CONFIG1,
257 GPMC_CONFIG1_PAGE_LEN(2)
258 | GPMC_CONFIG1_WAIT_READ_MON
259 | GPMC_CONFIG1_WAIT_WRITE_MON
260 | GPMC_CONFIG1_WAIT_PIN_SEL(waitpin)
261 | GPMC_CONFIG1_READTYPE_ASYNC
262 | GPMC_CONFIG1_WRITETYPE_ASYNC
263 | GPMC_CONFIG1_DEVICESIZE_16
264 | GPMC_CONFIG1_DEVICETYPE_NOR
265 | GPMC_CONFIG1_MUXADDDATA);
268 /* SYNC region, primarily for DMA */
269 status = gpmc_cs_request(sync, SZ_16M, (unsigned long *)
270 &tusb_resources[1].start);
272 printk(error, 2, status);
275 tusb_resources[1].end = tusb_resources[1].start + 0x9ff;
277 gpmc_cs_write_reg(sync, GPMC_CS_CONFIG1,
278 GPMC_CONFIG1_READMULTIPLE_SUPP
279 | GPMC_CONFIG1_READTYPE_SYNC
280 | GPMC_CONFIG1_WRITEMULTIPLE_SUPP
281 | GPMC_CONFIG1_WRITETYPE_SYNC
282 | GPMC_CONFIG1_CLKACTIVATIONTIME(1)
283 | GPMC_CONFIG1_PAGE_LEN(2)
284 | GPMC_CONFIG1_WAIT_READ_MON
285 | GPMC_CONFIG1_WAIT_WRITE_MON
286 | GPMC_CONFIG1_WAIT_PIN_SEL(waitpin)
287 | GPMC_CONFIG1_DEVICESIZE_16
288 | GPMC_CONFIG1_DEVICETYPE_NOR
289 | GPMC_CONFIG1_MUXADDDATA
290 /* fclk divider gets set later */
294 status = omap_request_gpio(irq);
296 printk(error, 3, status);
299 omap_set_gpio_direction(irq, 1);
300 tusb_resources[2].start = irq + IH_GPIO_BASE;
302 /* set up memory timings ... can speed them up later */
304 printk(error, 4, status);
307 refclk_psec = ps_refclk;
308 status = tusb6010_platform_retime(1);
310 printk(error, 5, status);
314 /* finish device setup ... */
316 printk(error, 6, status);
319 data->multipoint = 1;
320 tusb_device.dev.platform_data = data;
322 /* REVISIT let the driver know what DMA channels work */
324 tusb_device.dev.dma_mask = NULL;
326 /* so far so good ... register the device */
327 status = platform_device_register(&tusb_device);
329 printk(error, 7, status);