tegra_das.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * tegra_das.c - Tegra DAS driver
  3. *
  4. * Author: Stephen Warren <swarren@nvidia.com>
  5. * Copyright (C) 2010 - NVIDIA, Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * version 2 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  19. * 02110-1301 USA
  20. *
  21. */
  22. #include <linux/module.h>
  23. #include <linux/debugfs.h>
  24. #include <linux/device.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/slab.h>
  28. #include <linux/io.h>
  29. #include <mach/iomap.h>
  30. #include <sound/soc.h>
  31. #include "tegra_das.h"
  32. #define DRV_NAME "tegra-das"
  33. static struct tegra_das *das;
  34. static inline void tegra_das_write(u32 reg, u32 val)
  35. {
  36. __raw_writel(val, das->regs + reg);
  37. }
  38. static inline u32 tegra_das_read(u32 reg)
  39. {
  40. return __raw_readl(das->regs + reg);
  41. }
  42. int tegra_das_connect_dap_to_dac(int dap, int dac)
  43. {
  44. u32 addr;
  45. u32 reg;
  46. if (!das)
  47. return -ENODEV;
  48. addr = TEGRA_DAS_DAP_CTRL_SEL +
  49. (dap * TEGRA_DAS_DAP_CTRL_SEL_STRIDE);
  50. reg = dac << TEGRA_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P;
  51. tegra_das_write(addr, reg);
  52. return 0;
  53. }
  54. EXPORT_SYMBOL_GPL(tegra_das_connect_dap_to_dac);
  55. int tegra_das_connect_dap_to_dap(int dap, int otherdap, int master,
  56. int sdata1rx, int sdata2rx)
  57. {
  58. u32 addr;
  59. u32 reg;
  60. if (!das)
  61. return -ENODEV;
  62. addr = TEGRA_DAS_DAP_CTRL_SEL +
  63. (dap * TEGRA_DAS_DAP_CTRL_SEL_STRIDE);
  64. reg = otherdap << TEGRA_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P |
  65. !!sdata2rx << TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_P |
  66. !!sdata1rx << TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_P |
  67. !!master << TEGRA_DAS_DAP_CTRL_SEL_DAP_MS_SEL_P;
  68. tegra_das_write(addr, reg);
  69. return 0;
  70. }
  71. EXPORT_SYMBOL_GPL(tegra_das_connect_dap_to_dap);
  72. int tegra_das_connect_dac_to_dap(int dac, int dap)
  73. {
  74. u32 addr;
  75. u32 reg;
  76. if (!das)
  77. return -ENODEV;
  78. addr = TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL +
  79. (dac * TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE);
  80. reg = dap << TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_P |
  81. dap << TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_P |
  82. dap << TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_P;
  83. tegra_das_write(addr, reg);
  84. return 0;
  85. }
  86. EXPORT_SYMBOL_GPL(tegra_das_connect_dac_to_dap);
  87. #ifdef CONFIG_DEBUG_FS
  88. static int tegra_das_show(struct seq_file *s, void *unused)
  89. {
  90. int i;
  91. u32 addr;
  92. u32 reg;
  93. for (i = 0; i < TEGRA_DAS_DAP_CTRL_SEL_COUNT; i++) {
  94. addr = TEGRA_DAS_DAP_CTRL_SEL +
  95. (i * TEGRA_DAS_DAP_CTRL_SEL_STRIDE);
  96. reg = tegra_das_read(addr);
  97. seq_printf(s, "TEGRA_DAS_DAP_CTRL_SEL[%d] = %08x\n", i, reg);
  98. }
  99. for (i = 0; i < TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_COUNT; i++) {
  100. addr = TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL +
  101. (i * TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE);
  102. reg = tegra_das_read(addr);
  103. seq_printf(s, "TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL[%d] = %08x\n",
  104. i, reg);
  105. }
  106. return 0;
  107. }
  108. static int tegra_das_debug_open(struct inode *inode, struct file *file)
  109. {
  110. return single_open(file, tegra_das_show, inode->i_private);
  111. }
  112. static const struct file_operations tegra_das_debug_fops = {
  113. .open = tegra_das_debug_open,
  114. .read = seq_read,
  115. .llseek = seq_lseek,
  116. .release = single_release,
  117. };
  118. static void tegra_das_debug_add(struct tegra_das *das)
  119. {
  120. das->debug = debugfs_create_file(DRV_NAME, S_IRUGO,
  121. snd_soc_debugfs_root, das,
  122. &tegra_das_debug_fops);
  123. }
  124. static void tegra_das_debug_remove(struct tegra_das *das)
  125. {
  126. if (das->debug)
  127. debugfs_remove(das->debug);
  128. }
  129. #else
  130. static inline void tegra_das_debug_add(struct tegra_das *das)
  131. {
  132. }
  133. static inline void tegra_das_debug_remove(struct tegra_das *das)
  134. {
  135. }
  136. #endif
  137. static int __devinit tegra_das_probe(struct platform_device *pdev)
  138. {
  139. struct resource *res, *region;
  140. int ret = 0;
  141. if (das)
  142. return -ENODEV;
  143. das = kzalloc(sizeof(struct tegra_das), GFP_KERNEL);
  144. if (!das) {
  145. dev_err(&pdev->dev, "Can't allocate tegra_das\n");
  146. ret = -ENOMEM;
  147. goto exit;
  148. }
  149. das->dev = &pdev->dev;
  150. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  151. if (!res) {
  152. dev_err(&pdev->dev, "No memory resource\n");
  153. ret = -ENODEV;
  154. goto err_free;
  155. }
  156. region = request_mem_region(res->start, resource_size(res),
  157. pdev->name);
  158. if (!region) {
  159. dev_err(&pdev->dev, "Memory region already claimed\n");
  160. ret = -EBUSY;
  161. goto err_free;
  162. }
  163. das->regs = ioremap(res->start, resource_size(res));
  164. if (!das->regs) {
  165. dev_err(&pdev->dev, "ioremap failed\n");
  166. ret = -ENOMEM;
  167. goto err_release;
  168. }
  169. tegra_das_debug_add(das);
  170. platform_set_drvdata(pdev, das);
  171. return 0;
  172. err_release:
  173. release_mem_region(res->start, resource_size(res));
  174. err_free:
  175. kfree(das);
  176. das = 0;
  177. exit:
  178. return ret;
  179. }
  180. static int __devexit tegra_das_remove(struct platform_device *pdev)
  181. {
  182. struct resource *res;
  183. if (!das)
  184. return -ENODEV;
  185. platform_set_drvdata(pdev, NULL);
  186. tegra_das_debug_remove(das);
  187. iounmap(das->regs);
  188. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  189. release_mem_region(res->start, resource_size(res));
  190. kfree(das);
  191. das = 0;
  192. return 0;
  193. }
  194. static struct platform_driver tegra_das_driver = {
  195. .probe = tegra_das_probe,
  196. .remove = __devexit_p(tegra_das_remove),
  197. .driver = {
  198. .name = DRV_NAME,
  199. },
  200. };
  201. static int __init tegra_das_modinit(void)
  202. {
  203. return platform_driver_register(&tegra_das_driver);
  204. }
  205. module_init(tegra_das_modinit);
  206. static void __exit tegra_das_modexit(void)
  207. {
  208. platform_driver_unregister(&tegra_das_driver);
  209. }
  210. module_exit(tegra_das_modexit);
  211. MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
  212. MODULE_DESCRIPTION("Tegra DAS driver");
  213. MODULE_LICENSE("GPL");
  214. MODULE_ALIAS("platform:" DRV_NAME);