ARM: imx: merge audmux-v1 and audmux-v2
[deliverable/linux.git] / arch / arm / plat-mxc / audmux.c
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
18 #include <linux/module.h>
19 #include <linux/err.h>
20 #include <linux/io.h>
21 #include <linux/clk.h>
22 #include <linux/debugfs.h>
23 #include <linux/slab.h>
24 #include <mach/audmux.h>
25 #include <mach/hardware.h>
26
27 static struct clk *audmux_clk;
28 static void __iomem *audmux_base;
29
30 #define MXC_AUDMUX_V2_PTCR(x) ((x) * 8)
31 #define MXC_AUDMUX_V2_PDCR(x) ((x) * 8 + 4)
32
33 #ifdef CONFIG_DEBUG_FS
34 static struct dentry *audmux_debugfs_root;
35
36 static int audmux_open_file(struct inode *inode, struct file *file)
37 {
38 file->private_data = inode->i_private;
39 return 0;
40 }
41
42 /* There is an annoying discontinuity in the SSI numbering with regard
43 * to the Linux number of the devices */
44 static const char *audmux_port_string(int port)
45 {
46 switch (port) {
47 case MX31_AUDMUX_PORT1_SSI0:
48 return "imx-ssi.0";
49 case MX31_AUDMUX_PORT2_SSI1:
50 return "imx-ssi.1";
51 case MX31_AUDMUX_PORT3_SSI_PINS_3:
52 return "SSI3";
53 case MX31_AUDMUX_PORT4_SSI_PINS_4:
54 return "SSI4";
55 case MX31_AUDMUX_PORT5_SSI_PINS_5:
56 return "SSI5";
57 case MX31_AUDMUX_PORT6_SSI_PINS_6:
58 return "SSI6";
59 default:
60 return "UNKNOWN";
61 }
62 }
63
64 static ssize_t audmux_read_file(struct file *file, char __user *user_buf,
65 size_t count, loff_t *ppos)
66 {
67 ssize_t ret;
68 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
69 int port = (int)file->private_data;
70 u32 pdcr, ptcr;
71
72 if (!buf)
73 return -ENOMEM;
74
75 if (audmux_clk)
76 clk_enable(audmux_clk);
77
78 ptcr = readl(audmux_base + MXC_AUDMUX_V2_PTCR(port));
79 pdcr = readl(audmux_base + MXC_AUDMUX_V2_PDCR(port));
80
81 if (audmux_clk)
82 clk_disable(audmux_clk);
83
84 ret = snprintf(buf, PAGE_SIZE, "PDCR: %08x\nPTCR: %08x\n",
85 pdcr, ptcr);
86
87 if (ptcr & MXC_AUDMUX_V2_PTCR_TFSDIR)
88 ret += snprintf(buf + ret, PAGE_SIZE - ret,
89 "TxFS output from %s, ",
90 audmux_port_string((ptcr >> 27) & 0x7));
91 else
92 ret += snprintf(buf + ret, PAGE_SIZE - ret,
93 "TxFS input, ");
94
95 if (ptcr & MXC_AUDMUX_V2_PTCR_TCLKDIR)
96 ret += snprintf(buf + ret, PAGE_SIZE - ret,
97 "TxClk output from %s",
98 audmux_port_string((ptcr >> 22) & 0x7));
99 else
100 ret += snprintf(buf + ret, PAGE_SIZE - ret,
101 "TxClk input");
102
103 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
104
105 if (ptcr & MXC_AUDMUX_V2_PTCR_SYN) {
106 ret += snprintf(buf + ret, PAGE_SIZE - ret,
107 "Port is symmetric");
108 } else {
109 if (ptcr & MXC_AUDMUX_V2_PTCR_RFSDIR)
110 ret += snprintf(buf + ret, PAGE_SIZE - ret,
111 "RxFS output from %s, ",
112 audmux_port_string((ptcr >> 17) & 0x7));
113 else
114 ret += snprintf(buf + ret, PAGE_SIZE - ret,
115 "RxFS input, ");
116
117 if (ptcr & MXC_AUDMUX_V2_PTCR_RCLKDIR)
118 ret += snprintf(buf + ret, PAGE_SIZE - ret,
119 "RxClk output from %s",
120 audmux_port_string((ptcr >> 12) & 0x7));
121 else
122 ret += snprintf(buf + ret, PAGE_SIZE - ret,
123 "RxClk input");
124 }
125
126 ret += snprintf(buf + ret, PAGE_SIZE - ret,
127 "\nData received from %s\n",
128 audmux_port_string((pdcr >> 13) & 0x7));
129
130 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
131
132 kfree(buf);
133
134 return ret;
135 }
136
137 static const struct file_operations audmux_debugfs_fops = {
138 .open = audmux_open_file,
139 .read = audmux_read_file,
140 .llseek = default_llseek,
141 };
142
143 static void audmux_debugfs_init(void)
144 {
145 int i;
146 char buf[20];
147
148 audmux_debugfs_root = debugfs_create_dir("audmux", NULL);
149 if (!audmux_debugfs_root) {
150 pr_warning("Failed to create AUDMUX debugfs root\n");
151 return;
152 }
153
154 for (i = 1; i < 8; i++) {
155 snprintf(buf, sizeof(buf), "ssi%d", i);
156 if (!debugfs_create_file(buf, 0444, audmux_debugfs_root,
157 (void *)i, &audmux_debugfs_fops))
158 pr_warning("Failed to create AUDMUX port %d debugfs file\n",
159 i);
160 }
161 }
162 #else
163 static inline void audmux_debugfs_init(void)
164 {
165 }
166 #endif
167
168 static const uint8_t port_mapping[] = {
169 0x0, 0x4, 0x8, 0x10, 0x14, 0x1c,
170 };
171
172 int mxc_audmux_v1_configure_port(unsigned int port, unsigned int pcr)
173 {
174 if (!audmux_base)
175 return -ENOSYS;
176
177 if (port >= ARRAY_SIZE(port_mapping))
178 return -EINVAL;
179
180 writel(pcr, audmux_base + port_mapping[port]);
181
182 return 0;
183 }
184 EXPORT_SYMBOL_GPL(mxc_audmux_v1_configure_port);
185
186 int mxc_audmux_v2_configure_port(unsigned int port, unsigned int ptcr,
187 unsigned int pdcr)
188 {
189 if (!audmux_base)
190 return -ENOSYS;
191
192 if (audmux_clk)
193 clk_enable(audmux_clk);
194
195 writel(ptcr, audmux_base + MXC_AUDMUX_V2_PTCR(port));
196 writel(pdcr, audmux_base + MXC_AUDMUX_V2_PDCR(port));
197
198 if (audmux_clk)
199 clk_disable(audmux_clk);
200
201 return 0;
202 }
203 EXPORT_SYMBOL_GPL(mxc_audmux_v2_configure_port);
204
205 static int mxc_audmux_init(void)
206 {
207 int ret;
208 if (cpu_is_mx51()) {
209 audmux_base = MX51_IO_ADDRESS(MX51_AUDMUX_BASE_ADDR);
210 } else if (cpu_is_mx31()) {
211 audmux_base = MX31_IO_ADDRESS(MX31_AUDMUX_BASE_ADDR);
212 } else if (cpu_is_mx35()) {
213 audmux_clk = clk_get(NULL, "audmux");
214 if (IS_ERR(audmux_clk)) {
215 ret = PTR_ERR(audmux_clk);
216 printk(KERN_ERR "%s: cannot get clock: %d\n", __func__,
217 ret);
218 return ret;
219 }
220 audmux_base = MX35_IO_ADDRESS(MX35_AUDMUX_BASE_ADDR);
221 } else if (cpu_is_mx25()) {
222 audmux_clk = clk_get(NULL, "audmux");
223 if (IS_ERR(audmux_clk)) {
224 ret = PTR_ERR(audmux_clk);
225 printk(KERN_ERR "%s: cannot get clock: %d\n", __func__,
226 ret);
227 return ret;
228 }
229 audmux_base = MX25_IO_ADDRESS(MX25_AUDMUX_BASE_ADDR);
230 } else if (cpu_is_mx27()) {
231 audmux_base = MX27_IO_ADDRESS(MX27_AUDMUX_BASE_ADDR);
232 } else if (cpu_is_mx21()) {
233 audmux_base = MX21_IO_ADDRESS(MX21_AUDMUX_BASE_ADDR);
234 }
235
236 if (!cpu_is_mx2())
237 audmux_debugfs_init();
238
239 return 0;
240 }
241
242 postcore_initcall(mxc_audmux_init);
This page took 0.086195 seconds and 5 git commands to generate.