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>
18 #include <linux/platform_data/usb-omap.h>
20 #include <linux/usb/musb.h>
26 static u8 async_cs, sync_cs;
27 static unsigned refclk_psec;
30 /* NOTE: timings are from tusb 6010 datasheet Rev 1.8, 12-Sept 2006 */
32 static int tusb_set_async_mode(unsigned sysclk_ps)
34 struct gpmc_device_timings dev_t;
35 struct gpmc_timings t;
36 unsigned t_acsnh_advnh = sysclk_ps + 3000;
38 memset(&dev_t, 0, sizeof(dev_t));
42 dev_t.t_ceasu = 8 * 1000;
43 dev_t.t_avdasu = t_acsnh_advnh - 7000;
44 dev_t.t_ce_avd = 1000;
45 dev_t.t_avdp_r = t_acsnh_advnh;
46 dev_t.t_oeasu = t_acsnh_advnh + 1000;
49 dev_t.t_cez_w = dev_t.t_cez_r;
50 dev_t.t_avdp_w = t_acsnh_advnh;
51 dev_t.t_weasu = t_acsnh_advnh + 1000;
53 dev_t.cyc_aavdh_we = 1;
55 gpmc_calc_timings(&t, &dev_t);
57 return gpmc_cs_set_timings(async_cs, &t);
60 static int tusb_set_sync_mode(unsigned sysclk_ps)
62 struct gpmc_device_timings dev_t;
63 struct gpmc_timings t;
64 unsigned t_scsnh_advnh = sysclk_ps + 3000;
66 memset(&dev_t, 0, sizeof(dev_t));
69 dev_t.sync_read = true;
70 dev_t.sync_write = true;
75 dev_t.t_ceasu = 8 * 1000;
76 dev_t.t_avdasu = t_scsnh_advnh - 7000;
77 dev_t.t_ce_avd = 1000;
78 dev_t.t_avdp_r = t_scsnh_advnh;
79 dev_t.cyc_aavdh_oe = 3;
81 dev_t.t_ce_rdyz = 7000;
82 dev_t.t_avdp_w = t_scsnh_advnh;
83 dev_t.cyc_aavdh_we = 3;
85 dev_t.t_ce_rdyz = 7000;
87 gpmc_calc_timings(&t, &dev_t);
89 return gpmc_cs_set_timings(sync_cs, &t);
92 /* tusb driver calls this when it changes the chip's clocking */
93 int tusb6010_platform_retime(unsigned is_refclk)
95 static const char error[] =
96 KERN_ERR "tusb6010 %s retime error %d\n";
104 sysclk_ps = is_refclk ? refclk_psec : TUSB6010_OSCCLK_60;
106 status = tusb_set_async_mode(sysclk_ps);
108 printk(error, "async", status);
111 status = tusb_set_sync_mode(sysclk_ps);
113 printk(error, "sync", status);
117 EXPORT_SYMBOL_GPL(tusb6010_platform_retime);
119 static struct resource tusb_resources[] = {
120 /* Order is significant! The start/end fields
121 * are updated during setup..
123 { /* Asynchronous access */
124 .flags = IORESOURCE_MEM,
126 { /* Synchronous access */
127 .flags = IORESOURCE_MEM,
131 .flags = IORESOURCE_IRQ,
135 static u64 tusb_dmamask = ~(u32)0;
137 static struct platform_device tusb_device = {
141 .dma_mask = &tusb_dmamask,
142 .coherent_dma_mask = 0xffffffff,
144 .num_resources = ARRAY_SIZE(tusb_resources),
145 .resource = tusb_resources,
149 /* this may be called only from board-*.c setup code */
151 tusb6010_setup_interface(struct musb_hdrc_platform_data *data,
152 unsigned ps_refclk, unsigned waitpin,
153 unsigned async, unsigned sync,
154 unsigned irq, unsigned dmachan)
157 static char error[] __initdata =
158 KERN_ERR "tusb6010 init error %d, %d\n";
160 /* ASYNC region, primarily for PIO */
161 status = gpmc_cs_request(async, SZ_16M, (unsigned long *)
162 &tusb_resources[0].start);
164 printk(error, 1, status);
167 tusb_resources[0].end = tusb_resources[0].start + 0x9ff;
169 gpmc_cs_write_reg(async, GPMC_CS_CONFIG1,
170 GPMC_CONFIG1_PAGE_LEN(2)
171 | GPMC_CONFIG1_WAIT_READ_MON
172 | GPMC_CONFIG1_WAIT_WRITE_MON
173 | GPMC_CONFIG1_WAIT_PIN_SEL(waitpin)
174 | GPMC_CONFIG1_READTYPE_ASYNC
175 | GPMC_CONFIG1_WRITETYPE_ASYNC
176 | GPMC_CONFIG1_DEVICESIZE_16
177 | GPMC_CONFIG1_DEVICETYPE_NOR
178 | GPMC_CONFIG1_MUXADDDATA);
181 /* SYNC region, primarily for DMA */
182 status = gpmc_cs_request(sync, SZ_16M, (unsigned long *)
183 &tusb_resources[1].start);
185 printk(error, 2, status);
188 tusb_resources[1].end = tusb_resources[1].start + 0x9ff;
190 gpmc_cs_write_reg(sync, GPMC_CS_CONFIG1,
191 GPMC_CONFIG1_READMULTIPLE_SUPP
192 | GPMC_CONFIG1_READTYPE_SYNC
193 | GPMC_CONFIG1_WRITEMULTIPLE_SUPP
194 | GPMC_CONFIG1_WRITETYPE_SYNC
195 | GPMC_CONFIG1_PAGE_LEN(2)
196 | GPMC_CONFIG1_WAIT_READ_MON
197 | GPMC_CONFIG1_WAIT_WRITE_MON
198 | GPMC_CONFIG1_WAIT_PIN_SEL(waitpin)
199 | GPMC_CONFIG1_DEVICESIZE_16
200 | GPMC_CONFIG1_DEVICETYPE_NOR
201 | GPMC_CONFIG1_MUXADDDATA
202 /* fclk divider gets set later */
206 status = gpio_request_one(irq, GPIOF_IN, "TUSB6010 irq");
208 printk(error, 3, status);
211 tusb_resources[2].start = gpio_to_irq(irq);
213 /* set up memory timings ... can speed them up later */
215 printk(error, 4, status);
218 refclk_psec = ps_refclk;
219 status = tusb6010_platform_retime(1);
221 printk(error, 5, status);
225 /* finish device setup ... */
227 printk(error, 6, status);
230 tusb_device.dev.platform_data = data;
232 /* REVISIT let the driver know what DMA channels work */
234 tusb_device.dev.dma_mask = NULL;
236 /* assume OMAP 2420 ES2.0 and later */
237 if (dmachan & (1 << 0))
238 omap_mux_init_signal("sys_ndmareq0", 0);
239 if (dmachan & (1 << 1))
240 omap_mux_init_signal("sys_ndmareq1", 0);
241 if (dmachan & (1 << 2))
242 omap_mux_init_signal("sys_ndmareq2", 0);
243 if (dmachan & (1 << 3))
244 omap_mux_init_signal("sys_ndmareq3", 0);
245 if (dmachan & (1 << 4))
246 omap_mux_init_signal("sys_ndmareq4", 0);
247 if (dmachan & (1 << 5))
248 omap_mux_init_signal("sys_ndmareq5", 0);
251 /* so far so good ... register the device */
252 status = platform_device_register(&tusb_device);
254 printk(error, 7, status);