Sascha Hauer | 9eedbdf | 2009-10-29 17:12:39 +0100 | [diff] [blame] | 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. |
Sascha Hauer | 9eedbdf | 2009-10-29 17:12:39 +0100 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/err.h> |
| 20 | #include <linux/io.h> |
| 21 | #include <linux/clk.h> |
Mark Brown | 7b4e08a | 2010-01-11 16:33:18 +0000 | [diff] [blame] | 22 | #include <linux/debugfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Sascha Hauer | 9eedbdf | 2009-10-29 17:12:39 +0100 | [diff] [blame] | 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 | |
Mark Brown | 7b4e08a | 2010-01-11 16:33:18 +0000 | [diff] [blame] | 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, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 140 | .llseek = default_llseek, |
Mark Brown | 7b4e08a | 2010-01-11 16:33:18 +0000 | [diff] [blame] | 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 | |
Sascha Hauer | 9eedbdf | 2009-10-29 17:12:39 +0100 | [diff] [blame] | 168 | int mxc_audmux_v2_configure_port(unsigned int port, unsigned int ptcr, |
| 169 | unsigned int pdcr) |
| 170 | { |
| 171 | if (!audmux_base) |
| 172 | return -ENOSYS; |
| 173 | |
| 174 | if (audmux_clk) |
| 175 | clk_enable(audmux_clk); |
| 176 | |
| 177 | writel(ptcr, audmux_base + MXC_AUDMUX_V2_PTCR(port)); |
| 178 | writel(pdcr, audmux_base + MXC_AUDMUX_V2_PDCR(port)); |
| 179 | |
| 180 | if (audmux_clk) |
| 181 | clk_disable(audmux_clk); |
| 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | EXPORT_SYMBOL_GPL(mxc_audmux_v2_configure_port); |
| 186 | |
| 187 | static int mxc_audmux_v2_init(void) |
| 188 | { |
| 189 | int ret; |
Sascha Hauer | 40e2eda | 2010-08-20 16:44:34 +0200 | [diff] [blame] | 190 | #if defined(CONFIG_ARCH_MX5) |
| 191 | if (cpu_is_mx51()) { |
| 192 | audmux_base = MX51_IO_ADDRESS(MX51_AUDMUX_BASE_ADDR); |
| 193 | ret = 0; |
| 194 | return ret; |
| 195 | } |
| 196 | #endif |
Eric Bénard | 8402ed3 | 2010-06-08 11:03:00 +0200 | [diff] [blame] | 197 | #if defined(CONFIG_ARCH_MX3) |
Uwe Kleine-König | 8e99805 | 2010-02-12 22:38:31 +0100 | [diff] [blame] | 198 | if (cpu_is_mx31()) |
| 199 | audmux_base = MX31_IO_ADDRESS(MX31_AUDMUX_BASE_ADDR); |
| 200 | |
| 201 | else if (cpu_is_mx35()) { |
Sascha Hauer | 9eedbdf | 2009-10-29 17:12:39 +0100 | [diff] [blame] | 202 | audmux_clk = clk_get(NULL, "audmux"); |
| 203 | if (IS_ERR(audmux_clk)) { |
| 204 | ret = PTR_ERR(audmux_clk); |
| 205 | printk(KERN_ERR "%s: cannot get clock: %d\n", __func__, |
| 206 | ret); |
| 207 | return ret; |
| 208 | } |
Uwe Kleine-König | 8e99805 | 2010-02-12 22:38:31 +0100 | [diff] [blame] | 209 | audmux_base = MX35_IO_ADDRESS(MX35_AUDMUX_BASE_ADDR); |
Sascha Hauer | 9eedbdf | 2009-10-29 17:12:39 +0100 | [diff] [blame] | 210 | } |
Eric Bénard | 8402ed3 | 2010-06-08 11:03:00 +0200 | [diff] [blame] | 211 | #endif |
Uwe Kleine-König | 972cc48 | 2010-11-11 18:35:01 +0100 | [diff] [blame] | 212 | #if defined(CONFIG_SOC_IMX25) |
Eric Bénard | 8402ed3 | 2010-06-08 11:03:00 +0200 | [diff] [blame] | 213 | if (cpu_is_mx25()) { |
| 214 | audmux_clk = clk_get(NULL, "audmux"); |
| 215 | if (IS_ERR(audmux_clk)) { |
| 216 | ret = PTR_ERR(audmux_clk); |
| 217 | printk(KERN_ERR "%s: cannot get clock: %d\n", __func__, |
| 218 | ret); |
| 219 | return ret; |
| 220 | } |
| 221 | audmux_base = MX25_IO_ADDRESS(MX25_AUDMUX_BASE_ADDR); |
| 222 | } |
Uwe Kleine-König | 972cc48 | 2010-11-11 18:35:01 +0100 | [diff] [blame] | 223 | #endif /* if defined(CONFIG_SOC_IMX25) */ |
Mark Brown | 7b4e08a | 2010-01-11 16:33:18 +0000 | [diff] [blame] | 224 | audmux_debugfs_init(); |
| 225 | |
Sascha Hauer | 9eedbdf | 2009-10-29 17:12:39 +0100 | [diff] [blame] | 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | postcore_initcall(mxc_audmux_v2_init); |