usb-tusb6010.c 6.1 KB

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