usb-tusb6010.c 5.4 KB

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