David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Jon Hunter | 012e338 | 2013-02-21 13:01:47 -0600 | [diff] [blame] | 11 | #include <linux/err.h> |
Paul Gortmaker | d44b28c | 2011-07-31 10:52:44 -0400 | [diff] [blame] | 12 | #include <linux/string.h> |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 13 | #include <linux/types.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/platform_device.h> |
Jarkko Nikula | f2d18fe | 2008-12-10 17:35:30 -0800 | [diff] [blame] | 17 | #include <linux/gpio.h> |
Paul Gortmaker | dc28094 | 2011-07-31 16:17:29 -0400 | [diff] [blame] | 18 | #include <linux/export.h> |
Felipe Balbi | e8c4a7a | 2012-10-24 14:26:19 -0700 | [diff] [blame] | 19 | #include <linux/platform_data/usb-omap.h> |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 20 | |
| 21 | #include <linux/usb/musb.h> |
| 22 | |
Afzal Mohammed | 3ef5d00 | 2012-10-05 10:37:27 +0530 | [diff] [blame] | 23 | #include "gpmc.h" |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 24 | |
Tony Lindgren | f99bf16 | 2010-07-05 16:31:40 +0300 | [diff] [blame] | 25 | #include "mux.h" |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 26 | |
| 27 | static u8 async_cs, sync_cs; |
| 28 | static unsigned refclk_psec; |
| 29 | |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 30 | static struct gpmc_settings tusb_async = { |
Jon Hunter | 012e338 | 2013-02-21 13:01:47 -0600 | [diff] [blame] | 31 | .wait_on_read = true, |
| 32 | .wait_on_write = true, |
| 33 | .device_width = GPMC_DEVWIDTH_16BIT, |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 34 | .mux_add_data = GPMC_MUX_AD, |
| 35 | }; |
| 36 | |
| 37 | static struct gpmc_settings tusb_sync = { |
Jon Hunter | 012e338 | 2013-02-21 13:01:47 -0600 | [diff] [blame] | 38 | .burst_read = true, |
| 39 | .burst_write = true, |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 40 | .sync_read = true, |
| 41 | .sync_write = true, |
Jon Hunter | 012e338 | 2013-02-21 13:01:47 -0600 | [diff] [blame] | 42 | .wait_on_read = true, |
| 43 | .wait_on_write = true, |
| 44 | .burst_len = GPMC_BURST_16, |
| 45 | .device_width = GPMC_DEVWIDTH_16BIT, |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 46 | .mux_add_data = GPMC_MUX_AD, |
| 47 | }; |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 48 | |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 49 | /* NOTE: timings are from tusb 6010 datasheet Rev 1.8, 12-Sept 2006 */ |
| 50 | |
Afzal Mohammed | 47acde1 | 2012-08-17 12:16:14 +0530 | [diff] [blame] | 51 | static int tusb_set_async_mode(unsigned sysclk_ps) |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 52 | { |
Afzal Mohammed | 47acde1 | 2012-08-17 12:16:14 +0530 | [diff] [blame] | 53 | struct gpmc_device_timings dev_t; |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 54 | struct gpmc_timings t; |
| 55 | unsigned t_acsnh_advnh = sysclk_ps + 3000; |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 56 | |
Afzal Mohammed | 47acde1 | 2012-08-17 12:16:14 +0530 | [diff] [blame] | 57 | memset(&dev_t, 0, sizeof(dev_t)); |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 58 | |
Afzal Mohammed | 47acde1 | 2012-08-17 12:16:14 +0530 | [diff] [blame] | 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; |
| 64 | dev_t.t_oe = 300; |
| 65 | dev_t.t_cez_r = 7000; |
| 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; |
| 69 | dev_t.t_wpl = 300; |
| 70 | dev_t.cyc_aavdh_we = 1; |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 71 | |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 72 | gpmc_calc_timings(&t, &tusb_async, &dev_t); |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 73 | |
Robert ABEL | 2e67690 | 2015-02-27 16:56:53 +0100 | [diff] [blame] | 74 | return gpmc_cs_set_timings(async_cs, &t, &tusb_async); |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 75 | } |
| 76 | |
Afzal Mohammed | 47acde1 | 2012-08-17 12:16:14 +0530 | [diff] [blame] | 77 | static int tusb_set_sync_mode(unsigned sysclk_ps) |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 78 | { |
Afzal Mohammed | 47acde1 | 2012-08-17 12:16:14 +0530 | [diff] [blame] | 79 | struct gpmc_device_timings dev_t; |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 80 | struct gpmc_timings t; |
| 81 | unsigned t_scsnh_advnh = sysclk_ps + 3000; |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 82 | |
Afzal Mohammed | 47acde1 | 2012-08-17 12:16:14 +0530 | [diff] [blame] | 83 | memset(&dev_t, 0, sizeof(dev_t)); |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 84 | |
Afzal Mohammed | 47acde1 | 2012-08-17 12:16:14 +0530 | [diff] [blame] | 85 | dev_t.clk = 11100; |
| 86 | dev_t.t_bacc = 1000; |
| 87 | dev_t.t_ces = 1000; |
| 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; |
| 93 | dev_t.cyc_oe = 5; |
| 94 | dev_t.t_ce_rdyz = 7000; |
| 95 | dev_t.t_avdp_w = t_scsnh_advnh; |
| 96 | dev_t.cyc_aavdh_we = 3; |
| 97 | dev_t.cyc_wpl = 6; |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 98 | |
Jon Hunter | c3be5b4 | 2013-02-21 13:46:22 -0600 | [diff] [blame] | 99 | gpmc_calc_timings(&t, &tusb_sync, &dev_t); |
Afzal Mohammed | 559d94b | 2012-05-28 17:51:37 +0530 | [diff] [blame] | 100 | |
Robert ABEL | 2e67690 | 2015-02-27 16:56:53 +0100 | [diff] [blame] | 101 | return gpmc_cs_set_timings(sync_cs, &t, &tusb_sync); |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 102 | } |
| 103 | |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 104 | /* tusb driver calls this when it changes the chip's clocking */ |
| 105 | int tusb6010_platform_retime(unsigned is_refclk) |
| 106 | { |
| 107 | static const char error[] = |
| 108 | KERN_ERR "tusb6010 %s retime error %d\n"; |
| 109 | |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 110 | unsigned sysclk_ps; |
| 111 | int status; |
| 112 | |
Afzal Mohammed | 47acde1 | 2012-08-17 12:16:14 +0530 | [diff] [blame] | 113 | if (!refclk_psec) |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 114 | return -ENODEV; |
| 115 | |
| 116 | sysclk_ps = is_refclk ? refclk_psec : TUSB6010_OSCCLK_60; |
| 117 | |
Afzal Mohammed | 47acde1 | 2012-08-17 12:16:14 +0530 | [diff] [blame] | 118 | status = tusb_set_async_mode(sysclk_ps); |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 119 | if (status < 0) { |
| 120 | printk(error, "async", status); |
| 121 | goto done; |
| 122 | } |
Afzal Mohammed | 47acde1 | 2012-08-17 12:16:14 +0530 | [diff] [blame] | 123 | status = tusb_set_sync_mode(sysclk_ps); |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 124 | if (status < 0) |
| 125 | printk(error, "sync", status); |
| 126 | done: |
| 127 | return status; |
| 128 | } |
| 129 | EXPORT_SYMBOL_GPL(tusb6010_platform_retime); |
| 130 | |
| 131 | static struct resource tusb_resources[] = { |
| 132 | /* Order is significant! The start/end fields |
| 133 | * are updated during setup.. |
| 134 | */ |
| 135 | { /* Asynchronous access */ |
| 136 | .flags = IORESOURCE_MEM, |
| 137 | }, |
| 138 | { /* Synchronous access */ |
| 139 | .flags = IORESOURCE_MEM, |
| 140 | }, |
| 141 | { /* IRQ */ |
Felipe Balbi | 6ec1e07 | 2010-12-23 12:17:49 -0800 | [diff] [blame] | 142 | .name = "mc", |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 143 | .flags = IORESOURCE_IRQ, |
| 144 | }, |
| 145 | }; |
| 146 | |
| 147 | static u64 tusb_dmamask = ~(u32)0; |
| 148 | |
| 149 | static struct platform_device tusb_device = { |
Felipe Balbi | 18688fb | 2010-12-02 09:13:54 +0200 | [diff] [blame] | 150 | .name = "musb-tusb", |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 151 | .id = -1, |
| 152 | .dev = { |
| 153 | .dma_mask = &tusb_dmamask, |
| 154 | .coherent_dma_mask = 0xffffffff, |
| 155 | }, |
| 156 | .num_resources = ARRAY_SIZE(tusb_resources), |
| 157 | .resource = tusb_resources, |
| 158 | }; |
| 159 | |
| 160 | |
| 161 | /* this may be called only from board-*.c setup code */ |
| 162 | int __init |
| 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) |
| 167 | { |
| 168 | int status; |
| 169 | static char error[] __initdata = |
| 170 | KERN_ERR "tusb6010 init error %d, %d\n"; |
| 171 | |
| 172 | /* ASYNC region, primarily for PIO */ |
| 173 | status = gpmc_cs_request(async, SZ_16M, (unsigned long *) |
| 174 | &tusb_resources[0].start); |
| 175 | if (status < 0) { |
| 176 | printk(error, 1, status); |
| 177 | return status; |
| 178 | } |
| 179 | tusb_resources[0].end = tusb_resources[0].start + 0x9ff; |
Jon Hunter | 012e338 | 2013-02-21 13:01:47 -0600 | [diff] [blame] | 180 | tusb_async.wait_pin = waitpin; |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 181 | async_cs = async; |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 182 | |
Jon Hunter | 012e338 | 2013-02-21 13:01:47 -0600 | [diff] [blame] | 183 | status = gpmc_cs_program_settings(async_cs, &tusb_async); |
| 184 | if (status < 0) |
| 185 | return status; |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 186 | |
| 187 | /* SYNC region, primarily for DMA */ |
| 188 | status = gpmc_cs_request(sync, SZ_16M, (unsigned long *) |
| 189 | &tusb_resources[1].start); |
| 190 | if (status < 0) { |
| 191 | printk(error, 2, status); |
| 192 | return status; |
| 193 | } |
| 194 | tusb_resources[1].end = tusb_resources[1].start + 0x9ff; |
Jon Hunter | 012e338 | 2013-02-21 13:01:47 -0600 | [diff] [blame] | 195 | tusb_sync.wait_pin = waitpin; |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 196 | sync_cs = sync; |
Jon Hunter | 012e338 | 2013-02-21 13:01:47 -0600 | [diff] [blame] | 197 | |
| 198 | status = gpmc_cs_program_settings(sync_cs, &tusb_sync); |
| 199 | if (status < 0) |
| 200 | return status; |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 201 | |
| 202 | /* IRQ */ |
Igor Grinberg | bc593f5 | 2011-05-03 18:22:09 +0300 | [diff] [blame] | 203 | status = gpio_request_one(irq, GPIOF_IN, "TUSB6010 irq"); |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 204 | if (status < 0) { |
| 205 | printk(error, 3, status); |
| 206 | return status; |
| 207 | } |
Tony Lindgren | 3d09b33 | 2012-06-20 07:18:15 -0700 | [diff] [blame] | 208 | tusb_resources[2].start = gpio_to_irq(irq); |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 209 | |
| 210 | /* set up memory timings ... can speed them up later */ |
| 211 | if (!ps_refclk) { |
| 212 | printk(error, 4, status); |
| 213 | return -ENODEV; |
| 214 | } |
| 215 | refclk_psec = ps_refclk; |
| 216 | status = tusb6010_platform_retime(1); |
| 217 | if (status < 0) { |
| 218 | printk(error, 5, status); |
| 219 | return status; |
| 220 | } |
| 221 | |
| 222 | /* finish device setup ... */ |
| 223 | if (!data) { |
| 224 | printk(error, 6, status); |
| 225 | return -ENODEV; |
| 226 | } |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 227 | tusb_device.dev.platform_data = data; |
| 228 | |
| 229 | /* REVISIT let the driver know what DMA channels work */ |
| 230 | if (!dmachan) |
| 231 | tusb_device.dev.dma_mask = NULL; |
| 232 | else { |
| 233 | /* assume OMAP 2420 ES2.0 and later */ |
| 234 | if (dmachan & (1 << 0)) |
Tony Lindgren | f99bf16 | 2010-07-05 16:31:40 +0300 | [diff] [blame] | 235 | omap_mux_init_signal("sys_ndmareq0", 0); |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 236 | if (dmachan & (1 << 1)) |
Tony Lindgren | f99bf16 | 2010-07-05 16:31:40 +0300 | [diff] [blame] | 237 | omap_mux_init_signal("sys_ndmareq1", 0); |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 238 | if (dmachan & (1 << 2)) |
Tony Lindgren | f99bf16 | 2010-07-05 16:31:40 +0300 | [diff] [blame] | 239 | omap_mux_init_signal("sys_ndmareq2", 0); |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 240 | if (dmachan & (1 << 3)) |
Tony Lindgren | f99bf16 | 2010-07-05 16:31:40 +0300 | [diff] [blame] | 241 | omap_mux_init_signal("sys_ndmareq3", 0); |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 242 | if (dmachan & (1 << 4)) |
Tony Lindgren | f99bf16 | 2010-07-05 16:31:40 +0300 | [diff] [blame] | 243 | omap_mux_init_signal("sys_ndmareq4", 0); |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 244 | if (dmachan & (1 << 5)) |
Tony Lindgren | f99bf16 | 2010-07-05 16:31:40 +0300 | [diff] [blame] | 245 | omap_mux_init_signal("sys_ndmareq5", 0); |
David Brownell | c1ed640 | 2006-12-07 14:03:49 -0800 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /* so far so good ... register the device */ |
| 249 | status = platform_device_register(&tusb_device); |
| 250 | if (status < 0) { |
| 251 | printk(error, 7, status); |
| 252 | return status; |
| 253 | } |
| 254 | return 0; |
| 255 | } |