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