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