davinci_voicecodec.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * DaVinci Voice Codec Core Interface for TI platforms
  3. *
  4. * Copyright (C) 2010 Texas Instruments, Inc
  5. *
  6. * Author: Miguel Aguilar <miguel.aguilar@ridgerun.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/init.h>
  23. #include <linux/module.h>
  24. #include <linux/device.h>
  25. #include <linux/delay.h>
  26. #include <linux/io.h>
  27. #include <linux/clk.h>
  28. #include <sound/pcm.h>
  29. #include <linux/mfd/davinci_voicecodec.h>
  30. u32 davinci_vc_read(struct davinci_vc *davinci_vc, int reg)
  31. {
  32. return __raw_readl(davinci_vc->base + reg);
  33. }
  34. void davinci_vc_write(struct davinci_vc *davinci_vc,
  35. int reg, u32 val)
  36. {
  37. __raw_writel(val, davinci_vc->base + reg);
  38. }
  39. static int __init davinci_vc_probe(struct platform_device *pdev)
  40. {
  41. struct davinci_vc *davinci_vc;
  42. struct resource *res, *mem;
  43. struct mfd_cell *cell = NULL;
  44. int ret;
  45. davinci_vc = kzalloc(sizeof(struct davinci_vc), GFP_KERNEL);
  46. if (!davinci_vc) {
  47. dev_dbg(&pdev->dev,
  48. "could not allocate memory for private data\n");
  49. return -ENOMEM;
  50. }
  51. davinci_vc->clk = clk_get(&pdev->dev, NULL);
  52. if (IS_ERR(davinci_vc->clk)) {
  53. dev_dbg(&pdev->dev,
  54. "could not get the clock for voice codec\n");
  55. ret = -ENODEV;
  56. goto fail1;
  57. }
  58. clk_enable(davinci_vc->clk);
  59. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  60. if (!res) {
  61. dev_err(&pdev->dev, "no mem resource\n");
  62. ret = -ENODEV;
  63. goto fail2;
  64. }
  65. davinci_vc->pbase = res->start;
  66. davinci_vc->base_size = resource_size(res);
  67. mem = request_mem_region(davinci_vc->pbase, davinci_vc->base_size,
  68. pdev->name);
  69. if (!mem) {
  70. dev_err(&pdev->dev, "VCIF region already claimed\n");
  71. ret = -EBUSY;
  72. goto fail2;
  73. }
  74. davinci_vc->base = ioremap(davinci_vc->pbase, davinci_vc->base_size);
  75. if (!davinci_vc->base) {
  76. dev_err(&pdev->dev, "can't ioremap mem resource.\n");
  77. ret = -ENOMEM;
  78. goto fail3;
  79. }
  80. res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  81. if (!res) {
  82. dev_err(&pdev->dev, "no DMA resource\n");
  83. return -ENXIO;
  84. }
  85. davinci_vc->davinci_vcif.dma_tx_channel = res->start;
  86. davinci_vc->davinci_vcif.dma_tx_addr =
  87. (dma_addr_t)(io_v2p(davinci_vc->base) + DAVINCI_VC_WFIFO);
  88. res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
  89. if (!res) {
  90. dev_err(&pdev->dev, "no DMA resource\n");
  91. return -ENXIO;
  92. }
  93. davinci_vc->davinci_vcif.dma_rx_channel = res->start;
  94. davinci_vc->davinci_vcif.dma_rx_addr =
  95. (dma_addr_t)(io_v2p(davinci_vc->base) + DAVINCI_VC_RFIFO);
  96. davinci_vc->dev = &pdev->dev;
  97. davinci_vc->pdev = pdev;
  98. /* Voice codec interface client */
  99. cell = &davinci_vc->cells[DAVINCI_VC_VCIF_CELL];
  100. cell->name = "davinci_vcif";
  101. cell->driver_data = davinci_vc;
  102. /* Voice codec CQ93VC client */
  103. cell = &davinci_vc->cells[DAVINCI_VC_CQ93VC_CELL];
  104. cell->name = "cq93vc";
  105. cell->driver_data = davinci_vc;
  106. ret = mfd_add_devices(&pdev->dev, pdev->id, davinci_vc->cells,
  107. DAVINCI_VC_CELLS, NULL, 0);
  108. if (ret != 0) {
  109. dev_err(&pdev->dev, "fail to register client devices\n");
  110. goto fail4;
  111. }
  112. return 0;
  113. fail4:
  114. iounmap(davinci_vc->base);
  115. fail3:
  116. release_mem_region(davinci_vc->pbase, davinci_vc->base_size);
  117. fail2:
  118. clk_disable(davinci_vc->clk);
  119. clk_put(davinci_vc->clk);
  120. davinci_vc->clk = NULL;
  121. fail1:
  122. kfree(davinci_vc);
  123. return ret;
  124. }
  125. static int __devexit davinci_vc_remove(struct platform_device *pdev)
  126. {
  127. struct davinci_vc *davinci_vc = platform_get_drvdata(pdev);
  128. mfd_remove_devices(&pdev->dev);
  129. iounmap(davinci_vc->base);
  130. release_mem_region(davinci_vc->pbase, davinci_vc->base_size);
  131. clk_disable(davinci_vc->clk);
  132. clk_put(davinci_vc->clk);
  133. davinci_vc->clk = NULL;
  134. kfree(davinci_vc);
  135. return 0;
  136. }
  137. static struct platform_driver davinci_vc_driver = {
  138. .driver = {
  139. .name = "davinci_voicecodec",
  140. .owner = THIS_MODULE,
  141. },
  142. .remove = __devexit_p(davinci_vc_remove),
  143. };
  144. static int __init davinci_vc_init(void)
  145. {
  146. return platform_driver_probe(&davinci_vc_driver, davinci_vc_probe);
  147. }
  148. module_init(davinci_vc_init);
  149. static void __exit davinci_vc_exit(void)
  150. {
  151. platform_driver_unregister(&davinci_vc_driver);
  152. }
  153. module_exit(davinci_vc_exit);
  154. MODULE_AUTHOR("Miguel Aguilar");
  155. MODULE_DESCRIPTION("Texas Instruments DaVinci Voice Codec Core Interface");
  156. MODULE_LICENSE("GPL");