2 * Copyright 2009 Pengutronix, Sascha Hauer <s.hauer@pengutronix.de>
4 * Initial development of this code was funded by
5 * Phytec Messtechnik GmbH, http://www.phytec.de
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.
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.
18 #include <linux/module.h>
19 #include <linux/err.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>
27 static struct clk
*audmux_clk
;
28 static void __iomem
*audmux_base
;
30 #define MXC_AUDMUX_V2_PTCR(x) ((x) * 8)
31 #define MXC_AUDMUX_V2_PDCR(x) ((x) * 8 + 4)
33 #ifdef CONFIG_DEBUG_FS
34 static struct dentry
*audmux_debugfs_root
;
36 static int audmux_open_file(struct inode
*inode
, struct file
*file
)
38 file
->private_data
= inode
->i_private
;
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
)
47 case MX31_AUDMUX_PORT1_SSI0
:
49 case MX31_AUDMUX_PORT2_SSI1
:
51 case MX31_AUDMUX_PORT3_SSI_PINS_3
:
53 case MX31_AUDMUX_PORT4_SSI_PINS_4
:
55 case MX31_AUDMUX_PORT5_SSI_PINS_5
:
57 case MX31_AUDMUX_PORT6_SSI_PINS_6
:
64 static ssize_t
audmux_read_file(struct file
*file
, char __user
*user_buf
,
65 size_t count
, loff_t
*ppos
)
68 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
69 int port
= (int)file
->private_data
;
76 clk_enable(audmux_clk
);
78 ptcr
= readl(audmux_base
+ MXC_AUDMUX_V2_PTCR(port
));
79 pdcr
= readl(audmux_base
+ MXC_AUDMUX_V2_PDCR(port
));
82 clk_disable(audmux_clk
);
84 ret
= snprintf(buf
, PAGE_SIZE
, "PDCR: %08x\nPTCR: %08x\n",
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));
92 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
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));
100 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
103 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
105 if (ptcr
& MXC_AUDMUX_V2_PTCR_SYN
) {
106 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
107 "Port is symmetric");
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));
114 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
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));
122 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
126 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
127 "\nData received from %s\n",
128 audmux_port_string((pdcr
>> 13) & 0x7));
130 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
137 static const struct file_operations audmux_debugfs_fops
= {
138 .open
= audmux_open_file
,
139 .read
= audmux_read_file
,
140 .llseek
= default_llseek
,
143 static void audmux_debugfs_init(void)
148 audmux_debugfs_root
= debugfs_create_dir("audmux", NULL
);
149 if (!audmux_debugfs_root
) {
150 pr_warning("Failed to create AUDMUX debugfs root\n");
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",
163 static inline void audmux_debugfs_init(void)
168 int mxc_audmux_v2_configure_port(unsigned int port
, unsigned int ptcr
,
175 clk_enable(audmux_clk
);
177 writel(ptcr
, audmux_base
+ MXC_AUDMUX_V2_PTCR(port
));
178 writel(pdcr
, audmux_base
+ MXC_AUDMUX_V2_PDCR(port
));
181 clk_disable(audmux_clk
);
185 EXPORT_SYMBOL_GPL(mxc_audmux_v2_configure_port
);
187 static int mxc_audmux_v2_init(void)
191 audmux_base
= MX51_IO_ADDRESS(MX51_AUDMUX_BASE_ADDR
);
192 } else if (cpu_is_mx31()) {
193 audmux_base
= MX31_IO_ADDRESS(MX31_AUDMUX_BASE_ADDR
);
194 } else if (cpu_is_mx35()) {
195 audmux_clk
= clk_get(NULL
, "audmux");
196 if (IS_ERR(audmux_clk
)) {
197 ret
= PTR_ERR(audmux_clk
);
198 printk(KERN_ERR
"%s: cannot get clock: %d\n", __func__
,
202 audmux_base
= MX35_IO_ADDRESS(MX35_AUDMUX_BASE_ADDR
);
203 } else if (cpu_is_mx25()) {
204 audmux_clk
= clk_get(NULL
, "audmux");
205 if (IS_ERR(audmux_clk
)) {
206 ret
= PTR_ERR(audmux_clk
);
207 printk(KERN_ERR
"%s: cannot get clock: %d\n", __func__
,
211 audmux_base
= MX25_IO_ADDRESS(MX25_AUDMUX_BASE_ADDR
);
214 audmux_debugfs_init();
219 postcore_initcall(mxc_audmux_v2_init
);