usb-tusb6010.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. #include <linux/err.h>
  11. #include <linux/string.h>
  12. #include <linux/types.h>
  13. #include <linux/errno.h>
  14. #include <linux/delay.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/gpio.h>
  17. #include <linux/export.h>
  18. #include <linux/platform_data/usb-omap.h>
  19. #include <linux/usb/musb.h>
  20. #include "gpmc.h"
  21. #include "mux.h"
  22. static u8 async_cs, sync_cs;
  23. static unsigned refclk_psec;
  24. static struct gpmc_settings tusb_async = {
  25. .wait_on_read = true,
  26. .wait_on_write = true,
  27. .device_width = GPMC_DEVWIDTH_16BIT,
  28. .mux_add_data = GPMC_MUX_AD,
  29. };
  30. static struct gpmc_settings tusb_sync = {
  31. .burst_read = true,
  32. .burst_write = true,
  33. .sync_read = true,
  34. .sync_write = true,
  35. .wait_on_read = true,
  36. .wait_on_write = true,
  37. .burst_len = GPMC_BURST_16,
  38. .device_width = GPMC_DEVWIDTH_16BIT,
  39. .mux_add_data = GPMC_MUX_AD,
  40. };
  41. /* NOTE: timings are from tusb 6010 datasheet Rev 1.8, 12-Sept 2006 */
  42. static int tusb_set_async_mode(unsigned sysclk_ps)
  43. {
  44. struct gpmc_device_timings dev_t;
  45. struct gpmc_timings t;
  46. unsigned t_acsnh_advnh = sysclk_ps + 3000;
  47. memset(&dev_t, 0, sizeof(dev_t));
  48. dev_t.t_ceasu = 8 * 1000;
  49. dev_t.t_avdasu = t_acsnh_advnh - 7000;
  50. dev_t.t_ce_avd = 1000;
  51. dev_t.t_avdp_r = t_acsnh_advnh;
  52. dev_t.t_oeasu = t_acsnh_advnh + 1000;
  53. dev_t.t_oe = 300;
  54. dev_t.t_cez_r = 7000;
  55. dev_t.t_cez_w = dev_t.t_cez_r;
  56. dev_t.t_avdp_w = t_acsnh_advnh;
  57. dev_t.t_weasu = t_acsnh_advnh + 1000;
  58. dev_t.t_wpl = 300;
  59. dev_t.cyc_aavdh_we = 1;
  60. gpmc_calc_timings(&t, &tusb_async, &dev_t);
  61. return gpmc_cs_set_timings(async_cs, &t, &tusb_async);
  62. }
  63. static int tusb_set_sync_mode(unsigned sysclk_ps)
  64. {
  65. struct gpmc_device_timings dev_t;
  66. struct gpmc_timings t;
  67. unsigned t_scsnh_advnh = sysclk_ps + 3000;
  68. memset(&dev_t, 0, sizeof(dev_t));
  69. dev_t.clk = 11100;
  70. dev_t.t_bacc = 1000;
  71. dev_t.t_ces = 1000;
  72. dev_t.t_ceasu = 8 * 1000;
  73. dev_t.t_avdasu = t_scsnh_advnh - 7000;
  74. dev_t.t_ce_avd = 1000;
  75. dev_t.t_avdp_r = t_scsnh_advnh;
  76. dev_t.cyc_aavdh_oe = 3;
  77. dev_t.cyc_oe = 5;
  78. dev_t.t_ce_rdyz = 7000;
  79. dev_t.t_avdp_w = t_scsnh_advnh;
  80. dev_t.cyc_aavdh_we = 3;
  81. dev_t.cyc_wpl = 6;
  82. gpmc_calc_timings(&t, &tusb_sync, &dev_t);
  83. return gpmc_cs_set_timings(sync_cs, &t, &tusb_sync);
  84. }
  85. /* tusb driver calls this when it changes the chip's clocking */
  86. int tusb6010_platform_retime(unsigned is_refclk)
  87. {
  88. static const char error[] =
  89. KERN_ERR "tusb6010 %s retime error %d\n";
  90. unsigned sysclk_ps;
  91. int status;
  92. if (!refclk_psec)
  93. return -ENODEV;
  94. sysclk_ps = is_refclk ? refclk_psec : TUSB6010_OSCCLK_60;
  95. status = tusb_set_async_mode(sysclk_ps);
  96. if (status < 0) {
  97. printk(error, "async", status);
  98. goto done;
  99. }
  100. status = tusb_set_sync_mode(sysclk_ps);
  101. if (status < 0)
  102. printk(error, "sync", status);
  103. done:
  104. return status;
  105. }
  106. EXPORT_SYMBOL_GPL(tusb6010_platform_retime);
  107. static struct resource tusb_resources[] = {
  108. /* Order is significant! The start/end fields
  109. * are updated during setup..
  110. */
  111. { /* Asynchronous access */
  112. .flags = IORESOURCE_MEM,
  113. },
  114. { /* Synchronous access */
  115. .flags = IORESOURCE_MEM,
  116. },
  117. { /* IRQ */
  118. .name = "mc",
  119. .flags = IORESOURCE_IRQ,
  120. },
  121. };
  122. static u64 tusb_dmamask = ~(u32)0;
  123. static struct platform_device tusb_device = {
  124. .name = "musb-tusb",
  125. .id = -1,
  126. .dev = {
  127. .dma_mask = &tusb_dmamask,
  128. .coherent_dma_mask = 0xffffffff,
  129. },
  130. .num_resources = ARRAY_SIZE(tusb_resources),
  131. .resource = tusb_resources,
  132. };
  133. /* this may be called only from board-*.c setup code */
  134. int __init
  135. tusb6010_setup_interface(struct musb_hdrc_platform_data *data,
  136. unsigned ps_refclk, unsigned waitpin,
  137. unsigned async, unsigned sync,
  138. unsigned irq, unsigned dmachan)
  139. {
  140. int status;
  141. static char error[] __initdata =
  142. KERN_ERR "tusb6010 init error %d, %d\n";
  143. /* ASYNC region, primarily for PIO */
  144. status = gpmc_cs_request(async, SZ_16M, (unsigned long *)
  145. &tusb_resources[0].start);
  146. if (status < 0) {
  147. printk(error, 1, status);
  148. return status;
  149. }
  150. tusb_resources[0].end = tusb_resources[0].start + 0x9ff;
  151. tusb_async.wait_pin = waitpin;
  152. async_cs = async;
  153. status = gpmc_cs_program_settings(async_cs, &tusb_async);
  154. if (status < 0)
  155. return status;
  156. /* SYNC region, primarily for DMA */
  157. status = gpmc_cs_request(sync, SZ_16M, (unsigned long *)
  158. &tusb_resources[1].start);
  159. if (status < 0) {
  160. printk(error, 2, status);
  161. return status;
  162. }
  163. tusb_resources[1].end = tusb_resources[1].start + 0x9ff;
  164. tusb_sync.wait_pin = waitpin;
  165. sync_cs = sync;
  166. status = gpmc_cs_program_settings(sync_cs, &tusb_sync);
  167. if (status < 0)
  168. return status;
  169. /* IRQ */
  170. status = gpio_request_one(irq, GPIOF_IN, "TUSB6010 irq");
  171. if (status < 0) {
  172. printk(error, 3, status);
  173. return status;
  174. }
  175. tusb_resources[2].start = gpio_to_irq(irq);
  176. /* set up memory timings ... can speed them up later */
  177. if (!ps_refclk) {
  178. printk(error, 4, status);
  179. return -ENODEV;
  180. }
  181. refclk_psec = ps_refclk;
  182. status = tusb6010_platform_retime(1);
  183. if (status < 0) {
  184. printk(error, 5, status);
  185. return status;
  186. }
  187. /* finish device setup ... */
  188. if (!data) {
  189. printk(error, 6, status);
  190. return -ENODEV;
  191. }
  192. tusb_device.dev.platform_data = data;
  193. /* REVISIT let the driver know what DMA channels work */
  194. if (!dmachan)
  195. tusb_device.dev.dma_mask = NULL;
  196. else {
  197. /* assume OMAP 2420 ES2.0 and later */
  198. if (dmachan & (1 << 0))
  199. omap_mux_init_signal("sys_ndmareq0", 0);
  200. if (dmachan & (1 << 1))
  201. omap_mux_init_signal("sys_ndmareq1", 0);
  202. if (dmachan & (1 << 2))
  203. omap_mux_init_signal("sys_ndmareq2", 0);
  204. if (dmachan & (1 << 3))
  205. omap_mux_init_signal("sys_ndmareq3", 0);
  206. if (dmachan & (1 << 4))
  207. omap_mux_init_signal("sys_ndmareq4", 0);
  208. if (dmachan & (1 << 5))
  209. omap_mux_init_signal("sys_ndmareq5", 0);
  210. }
  211. /* so far so good ... register the device */
  212. status = platform_device_register(&tusb_device);
  213. if (status < 0) {
  214. printk(error, 7, status);
  215. return status;
  216. }
  217. return 0;
  218. }