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