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