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);
  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. dev_t.t_ce_rdyz = 7000;
  83. gpmc_calc_timings(&t, &tusb_sync, &dev_t);
  84. return gpmc_cs_set_timings(sync_cs, &t);
  85. }
  86. /* tusb driver calls this when it changes the chip's clocking */
  87. int tusb6010_platform_retime(unsigned is_refclk)
  88. {
  89. static const char error[] =
  90. KERN_ERR "tusb6010 %s retime error %d\n";
  91. unsigned sysclk_ps;
  92. int status;
  93. if (!refclk_psec)
  94. return -ENODEV;
  95. sysclk_ps = is_refclk ? refclk_psec : TUSB6010_OSCCLK_60;
  96. status = tusb_set_async_mode(sysclk_ps);
  97. if (status < 0) {
  98. printk(error, "async", status);
  99. goto done;
  100. }
  101. status = tusb_set_sync_mode(sysclk_ps);
  102. if (status < 0)
  103. printk(error, "sync", status);
  104. done:
  105. return status;
  106. }
  107. EXPORT_SYMBOL_GPL(tusb6010_platform_retime);
  108. static struct resource tusb_resources[] = {
  109. /* Order is significant! The start/end fields
  110. * are updated during setup..
  111. */
  112. { /* Asynchronous access */
  113. .flags = IORESOURCE_MEM,
  114. },
  115. { /* Synchronous access */
  116. .flags = IORESOURCE_MEM,
  117. },
  118. { /* IRQ */
  119. .name = "mc",
  120. .flags = IORESOURCE_IRQ,
  121. },
  122. };
  123. static u64 tusb_dmamask = ~(u32)0;
  124. static struct platform_device tusb_device = {
  125. .name = "musb-tusb",
  126. .id = -1,
  127. .dev = {
  128. .dma_mask = &tusb_dmamask,
  129. .coherent_dma_mask = 0xffffffff,
  130. },
  131. .num_resources = ARRAY_SIZE(tusb_resources),
  132. .resource = tusb_resources,
  133. };
  134. /* this may be called only from board-*.c setup code */
  135. int __init
  136. tusb6010_setup_interface(struct musb_hdrc_platform_data *data,
  137. unsigned ps_refclk, unsigned waitpin,
  138. unsigned async, unsigned sync,
  139. unsigned irq, unsigned dmachan)
  140. {
  141. int status;
  142. static char error[] __initdata =
  143. KERN_ERR "tusb6010 init error %d, %d\n";
  144. /* ASYNC region, primarily for PIO */
  145. status = gpmc_cs_request(async, SZ_16M, (unsigned long *)
  146. &tusb_resources[0].start);
  147. if (status < 0) {
  148. printk(error, 1, status);
  149. return status;
  150. }
  151. tusb_resources[0].end = tusb_resources[0].start + 0x9ff;
  152. tusb_async.wait_pin = waitpin;
  153. async_cs = async;
  154. status = gpmc_cs_program_settings(async_cs, &tusb_async);
  155. if (status < 0)
  156. return status;
  157. /* SYNC region, primarily for DMA */
  158. status = gpmc_cs_request(sync, SZ_16M, (unsigned long *)
  159. &tusb_resources[1].start);
  160. if (status < 0) {
  161. printk(error, 2, status);
  162. return status;
  163. }
  164. tusb_resources[1].end = tusb_resources[1].start + 0x9ff;
  165. tusb_sync.wait_pin = waitpin;
  166. sync_cs = sync;
  167. status = gpmc_cs_program_settings(sync_cs, &tusb_sync);
  168. if (status < 0)
  169. return status;
  170. /* IRQ */
  171. status = gpio_request_one(irq, GPIOF_IN, "TUSB6010 irq");
  172. if (status < 0) {
  173. printk(error, 3, status);
  174. return status;
  175. }
  176. tusb_resources[2].start = gpio_to_irq(irq);
  177. /* set up memory timings ... can speed them up later */
  178. if (!ps_refclk) {
  179. printk(error, 4, status);
  180. return -ENODEV;
  181. }
  182. refclk_psec = ps_refclk;
  183. status = tusb6010_platform_retime(1);
  184. if (status < 0) {
  185. printk(error, 5, status);
  186. return status;
  187. }
  188. /* finish device setup ... */
  189. if (!data) {
  190. printk(error, 6, status);
  191. return -ENODEV;
  192. }
  193. tusb_device.dev.platform_data = data;
  194. /* REVISIT let the driver know what DMA channels work */
  195. if (!dmachan)
  196. tusb_device.dev.dma_mask = NULL;
  197. else {
  198. /* assume OMAP 2420 ES2.0 and later */
  199. if (dmachan & (1 << 0))
  200. omap_mux_init_signal("sys_ndmareq0", 0);
  201. if (dmachan & (1 << 1))
  202. omap_mux_init_signal("sys_ndmareq1", 0);
  203. if (dmachan & (1 << 2))
  204. omap_mux_init_signal("sys_ndmareq2", 0);
  205. if (dmachan & (1 << 3))
  206. omap_mux_init_signal("sys_ndmareq3", 0);
  207. if (dmachan & (1 << 4))
  208. omap_mux_init_signal("sys_ndmareq4", 0);
  209. if (dmachan & (1 << 5))
  210. omap_mux_init_signal("sys_ndmareq5", 0);
  211. }
  212. /* so far so good ... register the device */
  213. status = platform_device_register(&tusb_device);
  214. if (status < 0) {
  215. printk(error, 7, status);
  216. return status;
  217. }
  218. return 0;
  219. }