mcbsp.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * linux/arch/arm/mach-omap1/mcbsp.c
  3. *
  4. * Copyright (C) 2008 Instituto Nokia de Tecnologia
  5. * Contact: Eduardo Valentin <eduardo.valentin@indt.org.br>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Multichannel mode not supported.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/clk.h>
  16. #include <linux/err.h>
  17. #include <linux/io.h>
  18. #include <linux/platform_device.h>
  19. #include <mach/irqs.h>
  20. #include <plat/dma.h>
  21. #include <plat/mux.h>
  22. #include <plat/cpu.h>
  23. #include <plat/mcbsp.h>
  24. #include <plat/dsp_common.h>
  25. #define DPS_RSTCT2_PER_EN (1 << 0)
  26. #define DSP_RSTCT2_WD_PER_EN (1 << 1)
  27. static int dsp_use;
  28. static struct clk *api_clk;
  29. static struct clk *dsp_clk;
  30. static void omap1_mcbsp_request(unsigned int id)
  31. {
  32. /*
  33. * On 1510, 1610 and 1710, McBSP1 and McBSP3
  34. * are DSP public peripherals.
  35. */
  36. if (id == OMAP_MCBSP1 || id == OMAP_MCBSP3) {
  37. if (dsp_use++ == 0) {
  38. api_clk = clk_get(NULL, "api_ck");
  39. dsp_clk = clk_get(NULL, "dsp_ck");
  40. if (!IS_ERR(api_clk) && !IS_ERR(dsp_clk)) {
  41. clk_enable(api_clk);
  42. clk_enable(dsp_clk);
  43. omap_dsp_request_mem();
  44. /*
  45. * DSP external peripheral reset
  46. * FIXME: This should be moved to dsp code
  47. */
  48. __raw_writew(__raw_readw(DSP_RSTCT2) | DPS_RSTCT2_PER_EN |
  49. DSP_RSTCT2_WD_PER_EN, DSP_RSTCT2);
  50. }
  51. }
  52. }
  53. }
  54. static void omap1_mcbsp_free(unsigned int id)
  55. {
  56. if (id == OMAP_MCBSP1 || id == OMAP_MCBSP3) {
  57. if (--dsp_use == 0) {
  58. omap_dsp_release_mem();
  59. if (!IS_ERR(api_clk)) {
  60. clk_disable(api_clk);
  61. clk_put(api_clk);
  62. }
  63. if (!IS_ERR(dsp_clk)) {
  64. clk_disable(dsp_clk);
  65. clk_put(dsp_clk);
  66. }
  67. }
  68. }
  69. }
  70. static struct omap_mcbsp_ops omap1_mcbsp_ops = {
  71. .request = omap1_mcbsp_request,
  72. .free = omap1_mcbsp_free,
  73. };
  74. #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
  75. static struct omap_mcbsp_platform_data omap7xx_mcbsp_pdata[] = {
  76. {
  77. .phys_base = OMAP7XX_MCBSP1_BASE,
  78. .dma_rx_sync = OMAP_DMA_MCBSP1_RX,
  79. .dma_tx_sync = OMAP_DMA_MCBSP1_TX,
  80. .rx_irq = INT_7XX_McBSP1RX,
  81. .tx_irq = INT_7XX_McBSP1TX,
  82. .ops = &omap1_mcbsp_ops,
  83. },
  84. {
  85. .phys_base = OMAP7XX_MCBSP2_BASE,
  86. .dma_rx_sync = OMAP_DMA_MCBSP3_RX,
  87. .dma_tx_sync = OMAP_DMA_MCBSP3_TX,
  88. .rx_irq = INT_7XX_McBSP2RX,
  89. .tx_irq = INT_7XX_McBSP2TX,
  90. .ops = &omap1_mcbsp_ops,
  91. },
  92. };
  93. #define OMAP7XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap7xx_mcbsp_pdata)
  94. #define OMAP7XX_MCBSP_REG_NUM (OMAP_MCBSP_REG_XCERH / sizeof(u16) + 1)
  95. #else
  96. #define omap7xx_mcbsp_pdata NULL
  97. #define OMAP7XX_MCBSP_PDATA_SZ 0
  98. #define OMAP7XX_MCBSP_REG_NUM 0
  99. #endif
  100. #ifdef CONFIG_ARCH_OMAP15XX
  101. static struct omap_mcbsp_platform_data omap15xx_mcbsp_pdata[] = {
  102. {
  103. .phys_base = OMAP1510_MCBSP1_BASE,
  104. .dma_rx_sync = OMAP_DMA_MCBSP1_RX,
  105. .dma_tx_sync = OMAP_DMA_MCBSP1_TX,
  106. .rx_irq = INT_McBSP1RX,
  107. .tx_irq = INT_McBSP1TX,
  108. .ops = &omap1_mcbsp_ops,
  109. },
  110. {
  111. .phys_base = OMAP1510_MCBSP2_BASE,
  112. .dma_rx_sync = OMAP_DMA_MCBSP2_RX,
  113. .dma_tx_sync = OMAP_DMA_MCBSP2_TX,
  114. .rx_irq = INT_1510_SPI_RX,
  115. .tx_irq = INT_1510_SPI_TX,
  116. .ops = &omap1_mcbsp_ops,
  117. },
  118. {
  119. .phys_base = OMAP1510_MCBSP3_BASE,
  120. .dma_rx_sync = OMAP_DMA_MCBSP3_RX,
  121. .dma_tx_sync = OMAP_DMA_MCBSP3_TX,
  122. .rx_irq = INT_McBSP3RX,
  123. .tx_irq = INT_McBSP3TX,
  124. .ops = &omap1_mcbsp_ops,
  125. },
  126. };
  127. #define OMAP15XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap15xx_mcbsp_pdata)
  128. #define OMAP15XX_MCBSP_REG_NUM (OMAP_MCBSP_REG_XCERH / sizeof(u16) + 1)
  129. #else
  130. #define omap15xx_mcbsp_pdata NULL
  131. #define OMAP15XX_MCBSP_PDATA_SZ 0
  132. #define OMAP15XX_MCBSP_REG_NUM 0
  133. #endif
  134. #ifdef CONFIG_ARCH_OMAP16XX
  135. static struct omap_mcbsp_platform_data omap16xx_mcbsp_pdata[] = {
  136. {
  137. .phys_base = OMAP1610_MCBSP1_BASE,
  138. .dma_rx_sync = OMAP_DMA_MCBSP1_RX,
  139. .dma_tx_sync = OMAP_DMA_MCBSP1_TX,
  140. .rx_irq = INT_McBSP1RX,
  141. .tx_irq = INT_McBSP1TX,
  142. .ops = &omap1_mcbsp_ops,
  143. },
  144. {
  145. .phys_base = OMAP1610_MCBSP2_BASE,
  146. .dma_rx_sync = OMAP_DMA_MCBSP2_RX,
  147. .dma_tx_sync = OMAP_DMA_MCBSP2_TX,
  148. .rx_irq = INT_1610_McBSP2_RX,
  149. .tx_irq = INT_1610_McBSP2_TX,
  150. .ops = &omap1_mcbsp_ops,
  151. },
  152. {
  153. .phys_base = OMAP1610_MCBSP3_BASE,
  154. .dma_rx_sync = OMAP_DMA_MCBSP3_RX,
  155. .dma_tx_sync = OMAP_DMA_MCBSP3_TX,
  156. .rx_irq = INT_McBSP3RX,
  157. .tx_irq = INT_McBSP3TX,
  158. .ops = &omap1_mcbsp_ops,
  159. },
  160. };
  161. #define OMAP16XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap16xx_mcbsp_pdata)
  162. #define OMAP16XX_MCBSP_REG_NUM (OMAP_MCBSP_REG_XCERH / sizeof(u16) + 1)
  163. #else
  164. #define omap16xx_mcbsp_pdata NULL
  165. #define OMAP16XX_MCBSP_PDATA_SZ 0
  166. #define OMAP16XX_MCBSP_REG_NUM 0
  167. #endif
  168. int __init omap1_mcbsp_init(void)
  169. {
  170. if (cpu_is_omap7xx()) {
  171. omap_mcbsp_count = OMAP7XX_MCBSP_PDATA_SZ;
  172. omap_mcbsp_cache_size = OMAP7XX_MCBSP_REG_NUM * sizeof(u16);
  173. } else if (cpu_is_omap15xx()) {
  174. omap_mcbsp_count = OMAP15XX_MCBSP_PDATA_SZ;
  175. omap_mcbsp_cache_size = OMAP15XX_MCBSP_REG_NUM * sizeof(u16);
  176. } else if (cpu_is_omap16xx()) {
  177. omap_mcbsp_count = OMAP16XX_MCBSP_PDATA_SZ;
  178. omap_mcbsp_cache_size = OMAP16XX_MCBSP_REG_NUM * sizeof(u16);
  179. }
  180. mcbsp_ptr = kzalloc(omap_mcbsp_count * sizeof(struct omap_mcbsp *),
  181. GFP_KERNEL);
  182. if (!mcbsp_ptr)
  183. return -ENOMEM;
  184. if (cpu_is_omap7xx())
  185. omap_mcbsp_register_board_cfg(omap7xx_mcbsp_pdata,
  186. OMAP7XX_MCBSP_PDATA_SZ);
  187. if (cpu_is_omap15xx())
  188. omap_mcbsp_register_board_cfg(omap15xx_mcbsp_pdata,
  189. OMAP15XX_MCBSP_PDATA_SZ);
  190. if (cpu_is_omap16xx())
  191. omap_mcbsp_register_board_cfg(omap16xx_mcbsp_pdata,
  192. OMAP16XX_MCBSP_PDATA_SZ);
  193. return omap_mcbsp_init();
  194. }
  195. arch_initcall(omap1_mcbsp_init);