blob: c2a6fbd7f8a96f372751aab9e781d48cebf6198f [file] [log] [blame]
David Brownellc1ed6402006-12-07 14:03:49 -08001/*
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 Hunter012e3382013-02-21 13:01:47 -060011#include <linux/err.h>
Paul Gortmakerd44b28c2011-07-31 10:52:44 -040012#include <linux/string.h>
David Brownellc1ed6402006-12-07 14:03:49 -080013#include <linux/types.h>
14#include <linux/errno.h>
15#include <linux/delay.h>
16#include <linux/platform_device.h>
Jarkko Nikulaf2d18fe2008-12-10 17:35:30 -080017#include <linux/gpio.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040018#include <linux/export.h>
Felipe Balbie8c4a7a2012-10-24 14:26:19 -070019#include <linux/platform_data/usb-omap.h>
David Brownellc1ed6402006-12-07 14:03:49 -080020
21#include <linux/usb/musb.h>
22
Afzal Mohammed3ef5d002012-10-05 10:37:27 +053023#include "gpmc.h"
David Brownellc1ed6402006-12-07 14:03:49 -080024
David Brownellc1ed6402006-12-07 14:03:49 -080025static u8 async_cs, sync_cs;
26static unsigned refclk_psec;
27
Jon Hunterc3be5b42013-02-21 13:46:22 -060028static struct gpmc_settings tusb_async = {
Jon Hunter012e3382013-02-21 13:01:47 -060029 .wait_on_read = true,
30 .wait_on_write = true,
31 .device_width = GPMC_DEVWIDTH_16BIT,
Jon Hunterc3be5b42013-02-21 13:46:22 -060032 .mux_add_data = GPMC_MUX_AD,
33};
34
35static struct gpmc_settings tusb_sync = {
Jon Hunter012e3382013-02-21 13:01:47 -060036 .burst_read = true,
37 .burst_write = true,
Jon Hunterc3be5b42013-02-21 13:46:22 -060038 .sync_read = true,
39 .sync_write = true,
Jon Hunter012e3382013-02-21 13:01:47 -060040 .wait_on_read = true,
41 .wait_on_write = true,
42 .burst_len = GPMC_BURST_16,
43 .device_width = GPMC_DEVWIDTH_16BIT,
Jon Hunterc3be5b42013-02-21 13:46:22 -060044 .mux_add_data = GPMC_MUX_AD,
45};
David Brownellc1ed6402006-12-07 14:03:49 -080046
David Brownellc1ed6402006-12-07 14:03:49 -080047/* NOTE: timings are from tusb 6010 datasheet Rev 1.8, 12-Sept 2006 */
48
Afzal Mohammed47acde12012-08-17 12:16:14 +053049static int tusb_set_async_mode(unsigned sysclk_ps)
David Brownellc1ed6402006-12-07 14:03:49 -080050{
Afzal Mohammed47acde12012-08-17 12:16:14 +053051 struct gpmc_device_timings dev_t;
David Brownellc1ed6402006-12-07 14:03:49 -080052 struct gpmc_timings t;
53 unsigned t_acsnh_advnh = sysclk_ps + 3000;
David Brownellc1ed6402006-12-07 14:03:49 -080054
Afzal Mohammed47acde12012-08-17 12:16:14 +053055 memset(&dev_t, 0, sizeof(dev_t));
David Brownellc1ed6402006-12-07 14:03:49 -080056
Afzal Mohammed47acde12012-08-17 12:16:14 +053057 dev_t.t_ceasu = 8 * 1000;
58 dev_t.t_avdasu = t_acsnh_advnh - 7000;
59 dev_t.t_ce_avd = 1000;
60 dev_t.t_avdp_r = t_acsnh_advnh;
61 dev_t.t_oeasu = t_acsnh_advnh + 1000;
62 dev_t.t_oe = 300;
63 dev_t.t_cez_r = 7000;
64 dev_t.t_cez_w = dev_t.t_cez_r;
65 dev_t.t_avdp_w = t_acsnh_advnh;
66 dev_t.t_weasu = t_acsnh_advnh + 1000;
67 dev_t.t_wpl = 300;
68 dev_t.cyc_aavdh_we = 1;
David Brownellc1ed6402006-12-07 14:03:49 -080069
Jon Hunterc3be5b42013-02-21 13:46:22 -060070 gpmc_calc_timings(&t, &tusb_async, &dev_t);
David Brownellc1ed6402006-12-07 14:03:49 -080071
Robert ABEL2e676902015-02-27 16:56:53 +010072 return gpmc_cs_set_timings(async_cs, &t, &tusb_async);
David Brownellc1ed6402006-12-07 14:03:49 -080073}
74
Afzal Mohammed47acde12012-08-17 12:16:14 +053075static int tusb_set_sync_mode(unsigned sysclk_ps)
David Brownellc1ed6402006-12-07 14:03:49 -080076{
Afzal Mohammed47acde12012-08-17 12:16:14 +053077 struct gpmc_device_timings dev_t;
David Brownellc1ed6402006-12-07 14:03:49 -080078 struct gpmc_timings t;
79 unsigned t_scsnh_advnh = sysclk_ps + 3000;
David Brownellc1ed6402006-12-07 14:03:49 -080080
Afzal Mohammed47acde12012-08-17 12:16:14 +053081 memset(&dev_t, 0, sizeof(dev_t));
David Brownellc1ed6402006-12-07 14:03:49 -080082
Afzal Mohammed47acde12012-08-17 12:16:14 +053083 dev_t.clk = 11100;
84 dev_t.t_bacc = 1000;
85 dev_t.t_ces = 1000;
86 dev_t.t_ceasu = 8 * 1000;
87 dev_t.t_avdasu = t_scsnh_advnh - 7000;
88 dev_t.t_ce_avd = 1000;
89 dev_t.t_avdp_r = t_scsnh_advnh;
90 dev_t.cyc_aavdh_oe = 3;
91 dev_t.cyc_oe = 5;
92 dev_t.t_ce_rdyz = 7000;
93 dev_t.t_avdp_w = t_scsnh_advnh;
94 dev_t.cyc_aavdh_we = 3;
95 dev_t.cyc_wpl = 6;
David Brownellc1ed6402006-12-07 14:03:49 -080096
Jon Hunterc3be5b42013-02-21 13:46:22 -060097 gpmc_calc_timings(&t, &tusb_sync, &dev_t);
Afzal Mohammed559d94b2012-05-28 17:51:37 +053098
Robert ABEL2e676902015-02-27 16:56:53 +010099 return gpmc_cs_set_timings(sync_cs, &t, &tusb_sync);
David Brownellc1ed6402006-12-07 14:03:49 -0800100}
101
David Brownellc1ed6402006-12-07 14:03:49 -0800102/* tusb driver calls this when it changes the chip's clocking */
103int tusb6010_platform_retime(unsigned is_refclk)
104{
105 static const char error[] =
106 KERN_ERR "tusb6010 %s retime error %d\n";
107
David Brownellc1ed6402006-12-07 14:03:49 -0800108 unsigned sysclk_ps;
109 int status;
110
Afzal Mohammed47acde12012-08-17 12:16:14 +0530111 if (!refclk_psec)
David Brownellc1ed6402006-12-07 14:03:49 -0800112 return -ENODEV;
113
114 sysclk_ps = is_refclk ? refclk_psec : TUSB6010_OSCCLK_60;
115
Afzal Mohammed47acde12012-08-17 12:16:14 +0530116 status = tusb_set_async_mode(sysclk_ps);
David Brownellc1ed6402006-12-07 14:03:49 -0800117 if (status < 0) {
118 printk(error, "async", status);
119 goto done;
120 }
Afzal Mohammed47acde12012-08-17 12:16:14 +0530121 status = tusb_set_sync_mode(sysclk_ps);
David Brownellc1ed6402006-12-07 14:03:49 -0800122 if (status < 0)
123 printk(error, "sync", status);
124done:
125 return status;
126}
127EXPORT_SYMBOL_GPL(tusb6010_platform_retime);
128
129static struct resource tusb_resources[] = {
130 /* Order is significant! The start/end fields
131 * are updated during setup..
132 */
133 { /* Asynchronous access */
134 .flags = IORESOURCE_MEM,
135 },
136 { /* Synchronous access */
137 .flags = IORESOURCE_MEM,
138 },
139 { /* IRQ */
Felipe Balbi6ec1e072010-12-23 12:17:49 -0800140 .name = "mc",
David Brownellc1ed6402006-12-07 14:03:49 -0800141 .flags = IORESOURCE_IRQ,
142 },
143};
144
145static u64 tusb_dmamask = ~(u32)0;
146
147static struct platform_device tusb_device = {
Felipe Balbi18688fb2010-12-02 09:13:54 +0200148 .name = "musb-tusb",
David Brownellc1ed6402006-12-07 14:03:49 -0800149 .id = -1,
150 .dev = {
151 .dma_mask = &tusb_dmamask,
152 .coherent_dma_mask = 0xffffffff,
153 },
154 .num_resources = ARRAY_SIZE(tusb_resources),
155 .resource = tusb_resources,
156};
157
158
159/* this may be called only from board-*.c setup code */
160int __init
161tusb6010_setup_interface(struct musb_hdrc_platform_data *data,
162 unsigned ps_refclk, unsigned waitpin,
163 unsigned async, unsigned sync,
164 unsigned irq, unsigned dmachan)
165{
166 int status;
167 static char error[] __initdata =
168 KERN_ERR "tusb6010 init error %d, %d\n";
169
170 /* ASYNC region, primarily for PIO */
171 status = gpmc_cs_request(async, SZ_16M, (unsigned long *)
172 &tusb_resources[0].start);
173 if (status < 0) {
174 printk(error, 1, status);
175 return status;
176 }
177 tusb_resources[0].end = tusb_resources[0].start + 0x9ff;
Jon Hunter012e3382013-02-21 13:01:47 -0600178 tusb_async.wait_pin = waitpin;
David Brownellc1ed6402006-12-07 14:03:49 -0800179 async_cs = async;
David Brownellc1ed6402006-12-07 14:03:49 -0800180
Jon Hunter012e3382013-02-21 13:01:47 -0600181 status = gpmc_cs_program_settings(async_cs, &tusb_async);
182 if (status < 0)
183 return status;
David Brownellc1ed6402006-12-07 14:03:49 -0800184
185 /* SYNC region, primarily for DMA */
186 status = gpmc_cs_request(sync, SZ_16M, (unsigned long *)
187 &tusb_resources[1].start);
188 if (status < 0) {
189 printk(error, 2, status);
190 return status;
191 }
192 tusb_resources[1].end = tusb_resources[1].start + 0x9ff;
Jon Hunter012e3382013-02-21 13:01:47 -0600193 tusb_sync.wait_pin = waitpin;
David Brownellc1ed6402006-12-07 14:03:49 -0800194 sync_cs = sync;
Jon Hunter012e3382013-02-21 13:01:47 -0600195
196 status = gpmc_cs_program_settings(sync_cs, &tusb_sync);
197 if (status < 0)
198 return status;
David Brownellc1ed6402006-12-07 14:03:49 -0800199
200 /* IRQ */
Igor Grinbergbc593f52011-05-03 18:22:09 +0300201 status = gpio_request_one(irq, GPIOF_IN, "TUSB6010 irq");
David Brownellc1ed6402006-12-07 14:03:49 -0800202 if (status < 0) {
203 printk(error, 3, status);
204 return status;
205 }
Tony Lindgren3d09b332012-06-20 07:18:15 -0700206 tusb_resources[2].start = gpio_to_irq(irq);
David Brownellc1ed6402006-12-07 14:03:49 -0800207
208 /* set up memory timings ... can speed them up later */
209 if (!ps_refclk) {
210 printk(error, 4, status);
211 return -ENODEV;
212 }
213 refclk_psec = ps_refclk;
214 status = tusb6010_platform_retime(1);
215 if (status < 0) {
216 printk(error, 5, status);
217 return status;
218 }
219
220 /* finish device setup ... */
221 if (!data) {
222 printk(error, 6, status);
223 return -ENODEV;
224 }
David Brownellc1ed6402006-12-07 14:03:49 -0800225 tusb_device.dev.platform_data = data;
226
David Brownellc1ed6402006-12-07 14:03:49 -0800227 /* so far so good ... register the device */
228 status = platform_device_register(&tusb_device);
229 if (status < 0) {
230 printk(error, 7, status);
231 return status;
232 }
233 return 0;
234}