audmux-v2.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright 2009 Pengutronix, Sascha Hauer <s.hauer@pengutronix.de>
  3. *
  4. * Initial development of this code was funded by
  5. * Phytec Messtechnik GmbH, http://www.phytec.de
  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 as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <linux/module.h>
  22. #include <linux/err.h>
  23. #include <linux/io.h>
  24. #include <linux/clk.h>
  25. #include <linux/debugfs.h>
  26. #include <linux/slab.h>
  27. #include <mach/audmux.h>
  28. #include <mach/hardware.h>
  29. static struct clk *audmux_clk;
  30. static void __iomem *audmux_base;
  31. #define MXC_AUDMUX_V2_PTCR(x) ((x) * 8)
  32. #define MXC_AUDMUX_V2_PDCR(x) ((x) * 8 + 4)
  33. #ifdef CONFIG_DEBUG_FS
  34. static struct dentry *audmux_debugfs_root;
  35. static int audmux_open_file(struct inode *inode, struct file *file)
  36. {
  37. file->private_data = inode->i_private;
  38. return 0;
  39. }
  40. /* There is an annoying discontinuity in the SSI numbering with regard
  41. * to the Linux number of the devices */
  42. static const char *audmux_port_string(int port)
  43. {
  44. switch (port) {
  45. case MX31_AUDMUX_PORT1_SSI0:
  46. return "imx-ssi.0";
  47. case MX31_AUDMUX_PORT2_SSI1:
  48. return "imx-ssi.1";
  49. case MX31_AUDMUX_PORT3_SSI_PINS_3:
  50. return "SSI3";
  51. case MX31_AUDMUX_PORT4_SSI_PINS_4:
  52. return "SSI4";
  53. case MX31_AUDMUX_PORT5_SSI_PINS_5:
  54. return "SSI5";
  55. case MX31_AUDMUX_PORT6_SSI_PINS_6:
  56. return "SSI6";
  57. default:
  58. return "UNKNOWN";
  59. }
  60. }
  61. static ssize_t audmux_read_file(struct file *file, char __user *user_buf,
  62. size_t count, loff_t *ppos)
  63. {
  64. ssize_t ret;
  65. char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  66. int port = (int)file->private_data;
  67. u32 pdcr, ptcr;
  68. if (!buf)
  69. return -ENOMEM;
  70. if (audmux_clk)
  71. clk_enable(audmux_clk);
  72. ptcr = readl(audmux_base + MXC_AUDMUX_V2_PTCR(port));
  73. pdcr = readl(audmux_base + MXC_AUDMUX_V2_PDCR(port));
  74. if (audmux_clk)
  75. clk_disable(audmux_clk);
  76. ret = snprintf(buf, PAGE_SIZE, "PDCR: %08x\nPTCR: %08x\n",
  77. pdcr, ptcr);
  78. if (ptcr & MXC_AUDMUX_V2_PTCR_TFSDIR)
  79. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  80. "TxFS output from %s, ",
  81. audmux_port_string((ptcr >> 27) & 0x7));
  82. else
  83. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  84. "TxFS input, ");
  85. if (ptcr & MXC_AUDMUX_V2_PTCR_TCLKDIR)
  86. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  87. "TxClk output from %s",
  88. audmux_port_string((ptcr >> 22) & 0x7));
  89. else
  90. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  91. "TxClk input");
  92. ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
  93. if (ptcr & MXC_AUDMUX_V2_PTCR_SYN) {
  94. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  95. "Port is symmetric");
  96. } else {
  97. if (ptcr & MXC_AUDMUX_V2_PTCR_RFSDIR)
  98. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  99. "RxFS output from %s, ",
  100. audmux_port_string((ptcr >> 17) & 0x7));
  101. else
  102. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  103. "RxFS input, ");
  104. if (ptcr & MXC_AUDMUX_V2_PTCR_RCLKDIR)
  105. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  106. "RxClk output from %s",
  107. audmux_port_string((ptcr >> 12) & 0x7));
  108. else
  109. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  110. "RxClk input");
  111. }
  112. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  113. "\nData received from %s\n",
  114. audmux_port_string((pdcr >> 13) & 0x7));
  115. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  116. kfree(buf);
  117. return ret;
  118. }
  119. static const struct file_operations audmux_debugfs_fops = {
  120. .open = audmux_open_file,
  121. .read = audmux_read_file,
  122. };
  123. static void audmux_debugfs_init(void)
  124. {
  125. int i;
  126. char buf[20];
  127. audmux_debugfs_root = debugfs_create_dir("audmux", NULL);
  128. if (!audmux_debugfs_root) {
  129. pr_warning("Failed to create AUDMUX debugfs root\n");
  130. return;
  131. }
  132. for (i = 1; i < 8; i++) {
  133. snprintf(buf, sizeof(buf), "ssi%d", i);
  134. if (!debugfs_create_file(buf, 0444, audmux_debugfs_root,
  135. (void *)i, &audmux_debugfs_fops))
  136. pr_warning("Failed to create AUDMUX port %d debugfs file\n",
  137. i);
  138. }
  139. }
  140. #else
  141. static inline void audmux_debugfs_init(void)
  142. {
  143. }
  144. #endif
  145. int mxc_audmux_v2_configure_port(unsigned int port, unsigned int ptcr,
  146. unsigned int pdcr)
  147. {
  148. if (!audmux_base)
  149. return -ENOSYS;
  150. if (audmux_clk)
  151. clk_enable(audmux_clk);
  152. writel(ptcr, audmux_base + MXC_AUDMUX_V2_PTCR(port));
  153. writel(pdcr, audmux_base + MXC_AUDMUX_V2_PDCR(port));
  154. if (audmux_clk)
  155. clk_disable(audmux_clk);
  156. return 0;
  157. }
  158. EXPORT_SYMBOL_GPL(mxc_audmux_v2_configure_port);
  159. static int mxc_audmux_v2_init(void)
  160. {
  161. int ret;
  162. if (cpu_is_mx31())
  163. audmux_base = MX31_IO_ADDRESS(MX31_AUDMUX_BASE_ADDR);
  164. else if (cpu_is_mx35()) {
  165. audmux_clk = clk_get(NULL, "audmux");
  166. if (IS_ERR(audmux_clk)) {
  167. ret = PTR_ERR(audmux_clk);
  168. printk(KERN_ERR "%s: cannot get clock: %d\n", __func__,
  169. ret);
  170. return ret;
  171. }
  172. audmux_base = MX35_IO_ADDRESS(MX35_AUDMUX_BASE_ADDR);
  173. }
  174. audmux_debugfs_init();
  175. return 0;
  176. }
  177. postcore_initcall(mxc_audmux_v2_init);