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/err.h>
12 #include <linux/string.h>
13 #include <linux/types.h>
14 #include <linux/errno.h>
15 #include <linux/delay.h>
16 #include <linux/platform_device.h>
17 #include <linux/gpio.h>
18 #include <linux/export.h>
19 #include <linux/platform_data/usb-omap.h>
21 #include <linux/usb/musb.h>
27 static u8 async_cs
, sync_cs
;
28 static unsigned refclk_psec
;
30 static struct gpmc_settings tusb_async
= {
32 .wait_on_write
= true,
33 .device_width
= GPMC_DEVWIDTH_16BIT
,
34 .mux_add_data
= GPMC_MUX_AD
,
37 static struct gpmc_settings tusb_sync
= {
43 .wait_on_write
= true,
44 .burst_len
= GPMC_BURST_16
,
45 .device_width
= GPMC_DEVWIDTH_16BIT
,
46 .mux_add_data
= GPMC_MUX_AD
,
49 /* NOTE: timings are from tusb 6010 datasheet Rev 1.8, 12-Sept 2006 */
51 static int tusb_set_async_mode(unsigned sysclk_ps
)
53 struct gpmc_device_timings dev_t
;
54 struct gpmc_timings t
;
55 unsigned t_acsnh_advnh
= sysclk_ps
+ 3000;
57 memset(&dev_t
, 0, sizeof(dev_t
));
59 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;
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;
70 dev_t
.cyc_aavdh_we
= 1;
72 gpmc_calc_timings(&t
, &tusb_async
, &dev_t
);
74 return gpmc_cs_set_timings(async_cs
, &t
);
77 static int tusb_set_sync_mode(unsigned sysclk_ps
)
79 struct gpmc_device_timings dev_t
;
80 struct gpmc_timings t
;
81 unsigned t_scsnh_advnh
= sysclk_ps
+ 3000;
83 memset(&dev_t
, 0, sizeof(dev_t
));
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;
94 dev_t
.t_ce_rdyz
= 7000;
95 dev_t
.t_avdp_w
= t_scsnh_advnh
;
96 dev_t
.cyc_aavdh_we
= 3;
99 gpmc_calc_timings(&t
, &tusb_sync
, &dev_t
);
101 return gpmc_cs_set_timings(sync_cs
, &t
);
104 /* tusb driver calls this when it changes the chip's clocking */
105 int tusb6010_platform_retime(unsigned is_refclk
)
107 static const char error
[] =
108 KERN_ERR
"tusb6010 %s retime error %d\n";
116 sysclk_ps
= is_refclk
? refclk_psec
: TUSB6010_OSCCLK_60
;
118 status
= tusb_set_async_mode(sysclk_ps
);
120 printk(error
, "async", status
);
123 status
= tusb_set_sync_mode(sysclk_ps
);
125 printk(error
, "sync", status
);
129 EXPORT_SYMBOL_GPL(tusb6010_platform_retime
);
131 static struct resource tusb_resources
[] = {
132 /* Order is significant! The start/end fields
133 * are updated during setup..
135 { /* Asynchronous access */
136 .flags
= IORESOURCE_MEM
,
138 { /* Synchronous access */
139 .flags
= IORESOURCE_MEM
,
143 .flags
= IORESOURCE_IRQ
,
147 static u64 tusb_dmamask
= ~(u32
)0;
149 static struct platform_device tusb_device
= {
153 .dma_mask
= &tusb_dmamask
,
154 .coherent_dma_mask
= 0xffffffff,
156 .num_resources
= ARRAY_SIZE(tusb_resources
),
157 .resource
= tusb_resources
,
161 /* this may be called only from board-*.c setup code */
163 tusb6010_setup_interface(struct musb_hdrc_platform_data
*data
,
164 unsigned ps_refclk
, unsigned waitpin
,
165 unsigned async
, unsigned sync
,
166 unsigned irq
, unsigned dmachan
)
169 static char error
[] __initdata
=
170 KERN_ERR
"tusb6010 init error %d, %d\n";
172 /* ASYNC region, primarily for PIO */
173 status
= gpmc_cs_request(async
, SZ_16M
, (unsigned long *)
174 &tusb_resources
[0].start
);
176 printk(error
, 1, status
);
179 tusb_resources
[0].end
= tusb_resources
[0].start
+ 0x9ff;
180 tusb_async
.wait_pin
= waitpin
;
183 status
= gpmc_cs_program_settings(async_cs
, &tusb_async
);
187 /* SYNC region, primarily for DMA */
188 status
= gpmc_cs_request(sync
, SZ_16M
, (unsigned long *)
189 &tusb_resources
[1].start
);
191 printk(error
, 2, status
);
194 tusb_resources
[1].end
= tusb_resources
[1].start
+ 0x9ff;
195 tusb_sync
.wait_pin
= waitpin
;
198 status
= gpmc_cs_program_settings(sync_cs
, &tusb_sync
);
203 status
= gpio_request_one(irq
, GPIOF_IN
, "TUSB6010 irq");
205 printk(error
, 3, status
);
208 tusb_resources
[2].start
= gpio_to_irq(irq
);
210 /* set up memory timings ... can speed them up later */
212 printk(error
, 4, status
);
215 refclk_psec
= ps_refclk
;
216 status
= tusb6010_platform_retime(1);
218 printk(error
, 5, status
);
222 /* finish device setup ... */
224 printk(error
, 6, status
);
227 tusb_device
.dev
.platform_data
= data
;
229 /* REVISIT let the driver know what DMA channels work */
231 tusb_device
.dev
.dma_mask
= NULL
;
233 /* assume OMAP 2420 ES2.0 and later */
234 if (dmachan
& (1 << 0))
235 omap_mux_init_signal("sys_ndmareq0", 0);
236 if (dmachan
& (1 << 1))
237 omap_mux_init_signal("sys_ndmareq1", 0);
238 if (dmachan
& (1 << 2))
239 omap_mux_init_signal("sys_ndmareq2", 0);
240 if (dmachan
& (1 << 3))
241 omap_mux_init_signal("sys_ndmareq3", 0);
242 if (dmachan
& (1 << 4))
243 omap_mux_init_signal("sys_ndmareq4", 0);
244 if (dmachan
& (1 << 5))
245 omap_mux_init_signal("sys_ndmareq5", 0);
248 /* so far so good ... register the device */
249 status
= platform_device_register(&tusb_device
);
251 printk(error
, 7, status
);