board-mop500-msp.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2010
  3. *
  4. * License terms: GNU General Public License (GPL), version 2
  5. */
  6. #include <linux/platform_device.h>
  7. #include <linux/init.h>
  8. #include <linux/gpio.h>
  9. #include <linux/pinctrl/consumer.h>
  10. #include <plat/gpio-nomadik.h>
  11. #include <plat/pincfg.h>
  12. #include <plat/ste_dma40.h>
  13. #include <mach/devices.h>
  14. #include <mach/hardware.h>
  15. #include <mach/irqs.h>
  16. #include <mach/msp.h>
  17. #include "ste-dma40-db8500.h"
  18. #include "board-mop500.h"
  19. #include "devices-db8500.h"
  20. #include "pins-db8500.h"
  21. /* MSP1/3 Tx/Rx usage protection */
  22. static DEFINE_SPINLOCK(msp_rxtx_lock);
  23. /* Reference Count */
  24. static int msp_rxtx_ref;
  25. /* Pin modes */
  26. struct pinctrl *msp1_p;
  27. struct pinctrl_state *msp1_def;
  28. struct pinctrl_state *msp1_sleep;
  29. int msp13_i2s_init(void)
  30. {
  31. int retval = 0;
  32. unsigned long flags;
  33. spin_lock_irqsave(&msp_rxtx_lock, flags);
  34. if (msp_rxtx_ref == 0 && !(IS_ERR(msp1_p) || IS_ERR(msp1_def))) {
  35. retval = pinctrl_select_state(msp1_p, msp1_def);
  36. if (retval)
  37. pr_err("could not set MSP1 defstate\n");
  38. }
  39. if (!retval)
  40. msp_rxtx_ref++;
  41. spin_unlock_irqrestore(&msp_rxtx_lock, flags);
  42. return retval;
  43. }
  44. int msp13_i2s_exit(void)
  45. {
  46. int retval = 0;
  47. unsigned long flags;
  48. spin_lock_irqsave(&msp_rxtx_lock, flags);
  49. WARN_ON(!msp_rxtx_ref);
  50. msp_rxtx_ref--;
  51. if (msp_rxtx_ref == 0 && !(IS_ERR(msp1_p) || IS_ERR(msp1_sleep))) {
  52. retval = pinctrl_select_state(msp1_p, msp1_sleep);
  53. if (retval)
  54. pr_err("could not set MSP1 sleepstate\n");
  55. }
  56. spin_unlock_irqrestore(&msp_rxtx_lock, flags);
  57. return retval;
  58. }
  59. static struct stedma40_chan_cfg msp0_dma_rx = {
  60. .high_priority = true,
  61. .dir = STEDMA40_PERIPH_TO_MEM,
  62. .src_dev_type = DB8500_DMA_DEV31_MSP0_RX_SLIM0_CH0_RX,
  63. .dst_dev_type = STEDMA40_DEV_DST_MEMORY,
  64. .src_info.psize = STEDMA40_PSIZE_LOG_4,
  65. .dst_info.psize = STEDMA40_PSIZE_LOG_4,
  66. /* data_width is set during configuration */
  67. };
  68. static struct stedma40_chan_cfg msp0_dma_tx = {
  69. .high_priority = true,
  70. .dir = STEDMA40_MEM_TO_PERIPH,
  71. .src_dev_type = STEDMA40_DEV_DST_MEMORY,
  72. .dst_dev_type = DB8500_DMA_DEV31_MSP0_TX_SLIM0_CH0_TX,
  73. .src_info.psize = STEDMA40_PSIZE_LOG_4,
  74. .dst_info.psize = STEDMA40_PSIZE_LOG_4,
  75. /* data_width is set during configuration */
  76. };
  77. static struct msp_i2s_platform_data msp0_platform_data = {
  78. .id = MSP_I2S_0,
  79. .msp_i2s_dma_rx = &msp0_dma_rx,
  80. .msp_i2s_dma_tx = &msp0_dma_tx,
  81. };
  82. static struct stedma40_chan_cfg msp1_dma_rx = {
  83. .high_priority = true,
  84. .dir = STEDMA40_PERIPH_TO_MEM,
  85. .src_dev_type = DB8500_DMA_DEV30_MSP3_RX,
  86. .dst_dev_type = STEDMA40_DEV_DST_MEMORY,
  87. .src_info.psize = STEDMA40_PSIZE_LOG_4,
  88. .dst_info.psize = STEDMA40_PSIZE_LOG_4,
  89. /* data_width is set during configuration */
  90. };
  91. static struct stedma40_chan_cfg msp1_dma_tx = {
  92. .high_priority = true,
  93. .dir = STEDMA40_MEM_TO_PERIPH,
  94. .src_dev_type = STEDMA40_DEV_DST_MEMORY,
  95. .dst_dev_type = DB8500_DMA_DEV30_MSP1_TX,
  96. .src_info.psize = STEDMA40_PSIZE_LOG_4,
  97. .dst_info.psize = STEDMA40_PSIZE_LOG_4,
  98. /* data_width is set during configuration */
  99. };
  100. static struct msp_i2s_platform_data msp1_platform_data = {
  101. .id = MSP_I2S_1,
  102. .msp_i2s_dma_rx = NULL,
  103. .msp_i2s_dma_tx = &msp1_dma_tx,
  104. .msp_i2s_init = msp13_i2s_init,
  105. .msp_i2s_exit = msp13_i2s_exit,
  106. };
  107. static struct stedma40_chan_cfg msp2_dma_rx = {
  108. .high_priority = true,
  109. .dir = STEDMA40_PERIPH_TO_MEM,
  110. .src_dev_type = DB8500_DMA_DEV14_MSP2_RX,
  111. .dst_dev_type = STEDMA40_DEV_DST_MEMORY,
  112. /* MSP2 DMA doesn't work with PSIZE == 4 on DB8500v2 */
  113. .src_info.psize = STEDMA40_PSIZE_LOG_1,
  114. .dst_info.psize = STEDMA40_PSIZE_LOG_1,
  115. /* data_width is set during configuration */
  116. };
  117. static struct stedma40_chan_cfg msp2_dma_tx = {
  118. .high_priority = true,
  119. .dir = STEDMA40_MEM_TO_PERIPH,
  120. .src_dev_type = STEDMA40_DEV_DST_MEMORY,
  121. .dst_dev_type = DB8500_DMA_DEV14_MSP2_TX,
  122. .src_info.psize = STEDMA40_PSIZE_LOG_4,
  123. .dst_info.psize = STEDMA40_PSIZE_LOG_4,
  124. .use_fixed_channel = true,
  125. .phy_channel = 1,
  126. /* data_width is set during configuration */
  127. };
  128. static struct platform_device *db8500_add_msp_i2s(struct device *parent,
  129. int id,
  130. resource_size_t base, int irq,
  131. struct msp_i2s_platform_data *pdata)
  132. {
  133. struct platform_device *pdev;
  134. struct resource res[] = {
  135. DEFINE_RES_MEM(base, SZ_4K),
  136. DEFINE_RES_IRQ(irq),
  137. };
  138. pr_info("Register platform-device 'ux500-msp-i2s', id %d, irq %d\n",
  139. id, irq);
  140. pdev = platform_device_register_resndata(parent, "ux500-msp-i2s", id,
  141. res, ARRAY_SIZE(res),
  142. pdata, sizeof(*pdata));
  143. if (!pdev) {
  144. pr_err("Failed to register platform-device 'ux500-msp-i2s.%d'!\n",
  145. id);
  146. return NULL;
  147. }
  148. return pdev;
  149. }
  150. /* Platform device for ASoC U8500 machine */
  151. static struct platform_device snd_soc_u8500 = {
  152. .name = "snd-soc-u8500",
  153. .id = 0,
  154. .dev = {
  155. .platform_data = NULL,
  156. },
  157. };
  158. /* Platform device for Ux500-PCM */
  159. static struct platform_device ux500_pcm = {
  160. .name = "ux500-pcm",
  161. .id = 0,
  162. .dev = {
  163. .platform_data = NULL,
  164. },
  165. };
  166. static struct msp_i2s_platform_data msp2_platform_data = {
  167. .id = MSP_I2S_2,
  168. .msp_i2s_dma_rx = &msp2_dma_rx,
  169. .msp_i2s_dma_tx = &msp2_dma_tx,
  170. };
  171. static struct msp_i2s_platform_data msp3_platform_data = {
  172. .id = MSP_I2S_3,
  173. .msp_i2s_dma_rx = &msp1_dma_rx,
  174. .msp_i2s_dma_tx = NULL,
  175. .msp_i2s_init = msp13_i2s_init,
  176. .msp_i2s_exit = msp13_i2s_exit,
  177. };
  178. int mop500_msp_init(struct device *parent)
  179. {
  180. struct platform_device *msp1;
  181. pr_info("%s: Register platform-device 'snd-soc-u8500'.\n", __func__);
  182. platform_device_register(&snd_soc_u8500);
  183. pr_info("Initialize MSP I2S-devices.\n");
  184. db8500_add_msp_i2s(parent, 0, U8500_MSP0_BASE, IRQ_DB8500_MSP0,
  185. &msp0_platform_data);
  186. msp1 = db8500_add_msp_i2s(parent, 1, U8500_MSP1_BASE, IRQ_DB8500_MSP1,
  187. &msp1_platform_data);
  188. db8500_add_msp_i2s(parent, 2, U8500_MSP2_BASE, IRQ_DB8500_MSP2,
  189. &msp2_platform_data);
  190. db8500_add_msp_i2s(parent, 3, U8500_MSP3_BASE, IRQ_DB8500_MSP1,
  191. &msp3_platform_data);
  192. /* Get the pinctrl handle for MSP1 */
  193. if (msp1) {
  194. msp1_p = pinctrl_get(&msp1->dev);
  195. if (IS_ERR(msp1_p))
  196. dev_err(&msp1->dev, "could not get MSP1 pinctrl\n");
  197. else {
  198. msp1_def = pinctrl_lookup_state(msp1_p,
  199. PINCTRL_STATE_DEFAULT);
  200. if (IS_ERR(msp1_def)) {
  201. dev_err(&msp1->dev,
  202. "could not get MSP1 defstate\n");
  203. }
  204. msp1_sleep = pinctrl_lookup_state(msp1_p,
  205. PINCTRL_STATE_SLEEP);
  206. if (IS_ERR(msp1_sleep))
  207. dev_err(&msp1->dev,
  208. "could not get MSP1 idlestate\n");
  209. }
  210. }
  211. pr_info("%s: Register platform-device 'ux500-pcm'\n", __func__);
  212. platform_device_register(&ux500_pcm);
  213. return 0;
  214. }