mcbsp.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 <linux/slab.h>
  20. #include <mach/irqs.h>
  21. #include <plat/dma.h>
  22. #include <plat/mux.h>
  23. #include <plat/cpu.h>
  24. #include <plat/mcbsp.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. /*
  44. * DSP external peripheral reset
  45. * FIXME: This should be moved to dsp code
  46. */
  47. __raw_writew(__raw_readw(DSP_RSTCT2) | DPS_RSTCT2_PER_EN |
  48. DSP_RSTCT2_WD_PER_EN, DSP_RSTCT2);
  49. }
  50. }
  51. }
  52. }
  53. static void omap1_mcbsp_free(unsigned int id)
  54. {
  55. if (id == OMAP_MCBSP1 || id == OMAP_MCBSP3) {
  56. if (--dsp_use == 0) {
  57. if (!IS_ERR(api_clk)) {
  58. clk_disable(api_clk);
  59. clk_put(api_clk);
  60. }
  61. if (!IS_ERR(dsp_clk)) {
  62. clk_disable(dsp_clk);
  63. clk_put(dsp_clk);
  64. }
  65. }
  66. }
  67. }
  68. static struct omap_mcbsp_ops omap1_mcbsp_ops = {
  69. .request = omap1_mcbsp_request,
  70. .free = omap1_mcbsp_free,
  71. };
  72. #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
  73. static struct omap_mcbsp_platform_data omap7xx_mcbsp_pdata[] = {
  74. {
  75. .phys_base = OMAP7XX_MCBSP1_BASE,
  76. .dma_rx_sync = OMAP_DMA_MCBSP1_RX,
  77. .dma_tx_sync = OMAP_DMA_MCBSP1_TX,
  78. .rx_irq = INT_7XX_McBSP1RX,
  79. .tx_irq = INT_7XX_McBSP1TX,
  80. .ops = &omap1_mcbsp_ops,
  81. },
  82. {
  83. .phys_base = OMAP7XX_MCBSP2_BASE,
  84. .dma_rx_sync = OMAP_DMA_MCBSP3_RX,
  85. .dma_tx_sync = OMAP_DMA_MCBSP3_TX,
  86. .rx_irq = INT_7XX_McBSP2RX,
  87. .tx_irq = INT_7XX_McBSP2TX,
  88. .ops = &omap1_mcbsp_ops,
  89. },
  90. };
  91. #define OMAP7XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap7xx_mcbsp_pdata)
  92. #define OMAP7XX_MCBSP_REG_NUM (OMAP_MCBSP_REG_XCERH / sizeof(u16) + 1)
  93. #else
  94. #define omap7xx_mcbsp_pdata NULL
  95. #define OMAP7XX_MCBSP_PDATA_SZ 0
  96. #define OMAP7XX_MCBSP_REG_NUM 0
  97. #endif
  98. #ifdef CONFIG_ARCH_OMAP15XX
  99. static struct omap_mcbsp_platform_data omap15xx_mcbsp_pdata[] = {
  100. {
  101. .phys_base = OMAP1510_MCBSP1_BASE,
  102. .dma_rx_sync = OMAP_DMA_MCBSP1_RX,
  103. .dma_tx_sync = OMAP_DMA_MCBSP1_TX,
  104. .rx_irq = INT_McBSP1RX,
  105. .tx_irq = INT_McBSP1TX,
  106. .ops = &omap1_mcbsp_ops,
  107. },
  108. {
  109. .phys_base = OMAP1510_MCBSP2_BASE,
  110. .dma_rx_sync = OMAP_DMA_MCBSP2_RX,
  111. .dma_tx_sync = OMAP_DMA_MCBSP2_TX,
  112. .rx_irq = INT_1510_SPI_RX,
  113. .tx_irq = INT_1510_SPI_TX,
  114. .ops = &omap1_mcbsp_ops,
  115. },
  116. {
  117. .phys_base = OMAP1510_MCBSP3_BASE,
  118. .dma_rx_sync = OMAP_DMA_MCBSP3_RX,
  119. .dma_tx_sync = OMAP_DMA_MCBSP3_TX,
  120. .rx_irq = INT_McBSP3RX,
  121. .tx_irq = INT_McBSP3TX,
  122. .ops = &omap1_mcbsp_ops,
  123. },
  124. };
  125. #define OMAP15XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap15xx_mcbsp_pdata)
  126. #define OMAP15XX_MCBSP_REG_NUM (OMAP_MCBSP_REG_XCERH / sizeof(u16) + 1)
  127. #else
  128. #define omap15xx_mcbsp_pdata NULL
  129. #define OMAP15XX_MCBSP_PDATA_SZ 0
  130. #define OMAP15XX_MCBSP_REG_NUM 0
  131. #endif
  132. #ifdef CONFIG_ARCH_OMAP16XX
  133. static struct omap_mcbsp_platform_data omap16xx_mcbsp_pdata[] = {
  134. {
  135. .phys_base = OMAP1610_MCBSP1_BASE,
  136. .dma_rx_sync = OMAP_DMA_MCBSP1_RX,
  137. .dma_tx_sync = OMAP_DMA_MCBSP1_TX,
  138. .rx_irq = INT_McBSP1RX,
  139. .tx_irq = INT_McBSP1TX,
  140. .ops = &omap1_mcbsp_ops,
  141. },
  142. {
  143. .phys_base = OMAP1610_MCBSP2_BASE,
  144. .dma_rx_sync = OMAP_DMA_MCBSP2_RX,
  145. .dma_tx_sync = OMAP_DMA_MCBSP2_TX,
  146. .rx_irq = INT_1610_McBSP2_RX,
  147. .tx_irq = INT_1610_McBSP2_TX,
  148. .ops = &omap1_mcbsp_ops,
  149. },
  150. {
  151. .phys_base = OMAP1610_MCBSP3_BASE,
  152. .dma_rx_sync = OMAP_DMA_MCBSP3_RX,
  153. .dma_tx_sync = OMAP_DMA_MCBSP3_TX,
  154. .rx_irq = INT_McBSP3RX,
  155. .tx_irq = INT_McBSP3TX,
  156. .ops = &omap1_mcbsp_ops,
  157. },
  158. };
  159. #define OMAP16XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap16xx_mcbsp_pdata)
  160. #define OMAP16XX_MCBSP_REG_NUM (OMAP_MCBSP_REG_XCERH / sizeof(u16) + 1)
  161. #else
  162. #define omap16xx_mcbsp_pdata NULL
  163. #define OMAP16XX_MCBSP_PDATA_SZ 0
  164. #define OMAP16XX_MCBSP_REG_NUM 0
  165. #endif
  166. int __init omap1_mcbsp_init(void)
  167. {
  168. if (cpu_is_omap7xx()) {
  169. omap_mcbsp_count = OMAP7XX_MCBSP_PDATA_SZ;
  170. omap_mcbsp_cache_size = OMAP7XX_MCBSP_REG_NUM * sizeof(u16);
  171. } else if (cpu_is_omap15xx()) {
  172. omap_mcbsp_count = OMAP15XX_MCBSP_PDATA_SZ;
  173. omap_mcbsp_cache_size = OMAP15XX_MCBSP_REG_NUM * sizeof(u16);
  174. } else if (cpu_is_omap16xx()) {
  175. omap_mcbsp_count = OMAP16XX_MCBSP_PDATA_SZ;
  176. omap_mcbsp_cache_size = OMAP16XX_MCBSP_REG_NUM * sizeof(u16);
  177. }
  178. mcbsp_ptr = kzalloc(omap_mcbsp_count * sizeof(struct omap_mcbsp *),
  179. GFP_KERNEL);
  180. if (!mcbsp_ptr)
  181. return -ENOMEM;
  182. if (cpu_is_omap7xx())
  183. omap_mcbsp_register_board_cfg(omap7xx_mcbsp_pdata,
  184. OMAP7XX_MCBSP_PDATA_SZ);
  185. if (cpu_is_omap15xx())
  186. omap_mcbsp_register_board_cfg(omap15xx_mcbsp_pdata,
  187. OMAP15XX_MCBSP_PDATA_SZ);
  188. if (cpu_is_omap16xx())
  189. omap_mcbsp_register_board_cfg(omap16xx_mcbsp_pdata,
  190. OMAP16XX_MCBSP_PDATA_SZ);
  191. return omap_mcbsp_init();
  192. }
  193. arch_initcall(omap1_mcbsp_init);