audmux-v2.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 <mach/audmux.h>
  27. #include <mach/hardware.h>
  28. static struct clk *audmux_clk;
  29. static void __iomem *audmux_base;
  30. #define MXC_AUDMUX_V2_PTCR(x) ((x) * 8)
  31. #define MXC_AUDMUX_V2_PDCR(x) ((x) * 8 + 4)
  32. #ifdef CONFIG_DEBUG_FS
  33. static struct dentry *audmux_debugfs_root;
  34. static int audmux_open_file(struct inode *inode, struct file *file)
  35. {
  36. file->private_data = inode->i_private;
  37. return 0;
  38. }
  39. /* There is an annoying discontinuity in the SSI numbering with regard
  40. * to the Linux number of the devices */
  41. static const char *audmux_port_string(int port)
  42. {
  43. switch (port) {
  44. case MX31_AUDMUX_PORT1_SSI0:
  45. return "imx-ssi.0";
  46. case MX31_AUDMUX_PORT2_SSI1:
  47. return "imx-ssi.1";
  48. case MX31_AUDMUX_PORT3_SSI_PINS_3:
  49. return "SSI3";
  50. case MX31_AUDMUX_PORT4_SSI_PINS_4:
  51. return "SSI4";
  52. case MX31_AUDMUX_PORT5_SSI_PINS_5:
  53. return "SSI5";
  54. case MX31_AUDMUX_PORT6_SSI_PINS_6:
  55. return "SSI6";
  56. default:
  57. return "UNKNOWN";
  58. }
  59. }
  60. static ssize_t audmux_read_file(struct file *file, char __user *user_buf,
  61. size_t count, loff_t *ppos)
  62. {
  63. ssize_t ret;
  64. char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  65. int port = (int)file->private_data;
  66. u32 pdcr, ptcr;
  67. if (!buf)
  68. return -ENOMEM;
  69. if (audmux_clk)
  70. clk_enable(audmux_clk);
  71. ptcr = readl(audmux_base + MXC_AUDMUX_V2_PTCR(port));
  72. pdcr = readl(audmux_base + MXC_AUDMUX_V2_PDCR(port));
  73. if (audmux_clk)
  74. clk_disable(audmux_clk);
  75. ret = snprintf(buf, PAGE_SIZE, "PDCR: %08x\nPTCR: %08x\n",
  76. pdcr, ptcr);
  77. if (ptcr & MXC_AUDMUX_V2_PTCR_TFSDIR)
  78. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  79. "TxFS output from %s, ",
  80. audmux_port_string((ptcr >> 27) & 0x7));
  81. else
  82. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  83. "TxFS input, ");
  84. if (ptcr & MXC_AUDMUX_V2_PTCR_TCLKDIR)
  85. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  86. "TxClk output from %s",
  87. audmux_port_string((ptcr >> 22) & 0x7));
  88. else
  89. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  90. "TxClk input");
  91. ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
  92. if (ptcr & MXC_AUDMUX_V2_PTCR_SYN) {
  93. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  94. "Port is symmetric");
  95. } else {
  96. if (ptcr & MXC_AUDMUX_V2_PTCR_RFSDIR)
  97. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  98. "RxFS output from %s, ",
  99. audmux_port_string((ptcr >> 17) & 0x7));
  100. else
  101. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  102. "RxFS input, ");
  103. if (ptcr & MXC_AUDMUX_V2_PTCR_RCLKDIR)
  104. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  105. "RxClk output from %s",
  106. audmux_port_string((ptcr >> 12) & 0x7));
  107. else
  108. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  109. "RxClk input");
  110. }
  111. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  112. "\nData received from %s\n",
  113. audmux_port_string((pdcr >> 13) & 0x7));
  114. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  115. kfree(buf);
  116. return ret;
  117. }
  118. static const struct file_operations audmux_debugfs_fops = {
  119. .open = audmux_open_file,
  120. .read = audmux_read_file,
  121. };
  122. static void audmux_debugfs_init(void)
  123. {
  124. int i;
  125. char buf[20];
  126. audmux_debugfs_root = debugfs_create_dir("audmux", NULL);
  127. if (!audmux_debugfs_root) {
  128. pr_warning("Failed to create AUDMUX debugfs root\n");
  129. return;
  130. }
  131. for (i = 1; i < 8; i++) {
  132. snprintf(buf, sizeof(buf), "ssi%d", i);
  133. if (!debugfs_create_file(buf, 0444, audmux_debugfs_root,
  134. (void *)i, &audmux_debugfs_fops))
  135. pr_warning("Failed to create AUDMUX port %d debugfs file\n",
  136. i);
  137. }
  138. }
  139. #else
  140. static inline void audmux_debugfs_init(void)
  141. {
  142. }
  143. #endif
  144. int mxc_audmux_v2_configure_port(unsigned int port, unsigned int ptcr,
  145. unsigned int pdcr)
  146. {
  147. if (!audmux_base)
  148. return -ENOSYS;
  149. if (audmux_clk)
  150. clk_enable(audmux_clk);
  151. writel(ptcr, audmux_base + MXC_AUDMUX_V2_PTCR(port));
  152. writel(pdcr, audmux_base + MXC_AUDMUX_V2_PDCR(port));
  153. if (audmux_clk)
  154. clk_disable(audmux_clk);
  155. return 0;
  156. }
  157. EXPORT_SYMBOL_GPL(mxc_audmux_v2_configure_port);
  158. static int mxc_audmux_v2_init(void)
  159. {
  160. int ret;
  161. if (cpu_is_mx31())
  162. audmux_base = MX31_IO_ADDRESS(MX31_AUDMUX_BASE_ADDR);
  163. else if (cpu_is_mx35()) {
  164. audmux_clk = clk_get(NULL, "audmux");
  165. if (IS_ERR(audmux_clk)) {
  166. ret = PTR_ERR(audmux_clk);
  167. printk(KERN_ERR "%s: cannot get clock: %d\n", __func__,
  168. ret);
  169. return ret;
  170. }
  171. audmux_base = MX35_IO_ADDRESS(MX35_AUDMUX_BASE_ADDR);
  172. }
  173. audmux_debugfs_init();
  174. return 0;
  175. }
  176. postcore_initcall(mxc_audmux_v2_init);