Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1 | /* |
| 2 | * soc-core.c -- ALSA SoC Audio Layer |
| 3 | * |
| 4 | * Copyright 2005 Wolfson Microelectronics PLC. |
Liam Girdwood | 0664d88 | 2006-12-18 14:39:02 +0100 | [diff] [blame] | 5 | * Copyright 2005 Openedhand Ltd. |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 6 | * Copyright (C) 2010 Slimlogic Ltd. |
| 7 | * Copyright (C) 2010 Texas Instruments Inc. |
Liam Girdwood | 0664d88 | 2006-12-18 14:39:02 +0100 | [diff] [blame] | 8 | * |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 9 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
Liam Girdwood | 0664d88 | 2006-12-18 14:39:02 +0100 | [diff] [blame] | 10 | * with code, comments and ideas from :- |
| 11 | * Richard Purdie <richard@openedhand.com> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify it |
| 14 | * under the terms of the GNU General Public License as published by the |
| 15 | * Free Software Foundation; either version 2 of the License, or (at your |
| 16 | * option) any later version. |
| 17 | * |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 18 | * TODO: |
| 19 | * o Add hw rules to enforce rates, etc. |
| 20 | * o More testing with other codecs/machines. |
| 21 | * o Add more codecs and platforms to ensure good API coverage. |
| 22 | * o Support TDM on PCM and I2S |
| 23 | */ |
| 24 | |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/moduleparam.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/delay.h> |
| 29 | #include <linux/pm.h> |
| 30 | #include <linux/bitops.h> |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 31 | #include <linux/debugfs.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
Mark Brown | f0e8ed8 | 2011-09-20 11:41:54 +0100 | [diff] [blame] | 33 | #include <linux/ctype.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 35 | #include <linux/of.h> |
Marek Vasut | 474828a | 2009-07-22 13:01:03 +0200 | [diff] [blame] | 36 | #include <sound/ac97_codec.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 37 | #include <sound/core.h> |
Mark Brown | 3028eb8 | 2010-12-05 12:22:46 +0000 | [diff] [blame] | 38 | #include <sound/jack.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 39 | #include <sound/pcm.h> |
| 40 | #include <sound/pcm_params.h> |
| 41 | #include <sound/soc.h> |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 42 | #include <sound/soc-dpcm.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 43 | #include <sound/initval.h> |
| 44 | |
Mark Brown | a8b1d34 | 2010-11-03 18:05:58 -0400 | [diff] [blame] | 45 | #define CREATE_TRACE_POINTS |
| 46 | #include <trace/events/asoc.h> |
| 47 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 48 | #define NAME_SIZE 32 |
| 49 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 50 | static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq); |
| 51 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 52 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 53 | struct dentry *snd_soc_debugfs_root; |
| 54 | EXPORT_SYMBOL_GPL(snd_soc_debugfs_root); |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 55 | #endif |
| 56 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 57 | static DEFINE_MUTEX(client_mutex); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 58 | static LIST_HEAD(dai_list); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 59 | static LIST_HEAD(platform_list); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 60 | static LIST_HEAD(codec_list); |
Kuninori Morimoto | 030e79f | 2013-03-11 18:27:21 -0700 | [diff] [blame] | 61 | static LIST_HEAD(component_list); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 62 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 63 | /* |
| 64 | * This is a timeout to do a DAPM powerdown after a stream is closed(). |
| 65 | * It can be used to eliminate pops between different playback streams, e.g. |
| 66 | * between two audio tracks. |
| 67 | */ |
| 68 | static int pmdown_time = 5000; |
| 69 | module_param(pmdown_time, int, 0); |
| 70 | MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)"); |
| 71 | |
Dimitris Papastamos | 2bc9a81 | 2011-02-01 12:24:08 +0000 | [diff] [blame] | 72 | /* returns the minimum number of bytes needed to represent |
| 73 | * a particular given value */ |
| 74 | static int min_bytes_needed(unsigned long val) |
| 75 | { |
| 76 | int c = 0; |
| 77 | int i; |
| 78 | |
| 79 | for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c) |
| 80 | if (val & (1UL << i)) |
| 81 | break; |
| 82 | c = (sizeof val * 8) - c; |
| 83 | if (!c || (c % 8)) |
| 84 | c = (c + 8) / 8; |
| 85 | else |
| 86 | c /= 8; |
| 87 | return c; |
| 88 | } |
| 89 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 90 | /* fill buf which is 'len' bytes with a formatted |
| 91 | * string of the form 'reg: value\n' */ |
| 92 | static int format_register_str(struct snd_soc_codec *codec, |
| 93 | unsigned int reg, char *buf, size_t len) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 94 | { |
Stephen Warren | 00b317a | 2011-04-01 14:50:44 -0600 | [diff] [blame] | 95 | int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; |
| 96 | int regsize = codec->driver->reg_word_size * 2; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 97 | int ret; |
| 98 | char tmpbuf[len + 1]; |
| 99 | char regbuf[regsize + 1]; |
| 100 | |
| 101 | /* since tmpbuf is allocated on the stack, warn the callers if they |
| 102 | * try to abuse this function */ |
| 103 | WARN_ON(len > 63); |
| 104 | |
| 105 | /* +2 for ': ' and + 1 for '\n' */ |
| 106 | if (wordsize + regsize + 2 + 1 != len) |
| 107 | return -EINVAL; |
| 108 | |
Mark Brown | 25032c1 | 2011-08-01 13:52:48 +0900 | [diff] [blame] | 109 | ret = snd_soc_read(codec, reg); |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 110 | if (ret < 0) { |
| 111 | memset(regbuf, 'X', regsize); |
| 112 | regbuf[regsize] = '\0'; |
| 113 | } else { |
| 114 | snprintf(regbuf, regsize + 1, "%.*x", regsize, ret); |
| 115 | } |
| 116 | |
| 117 | /* prepare the buffer */ |
| 118 | snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf); |
| 119 | /* copy it back to the caller without the '\0' */ |
| 120 | memcpy(buf, tmpbuf, len); |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | /* codec register dump */ |
| 126 | static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf, |
| 127 | size_t count, loff_t pos) |
| 128 | { |
| 129 | int i, step = 1; |
Dimitris Papastamos | 2bc9a81 | 2011-02-01 12:24:08 +0000 | [diff] [blame] | 130 | int wordsize, regsize; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 131 | int len; |
| 132 | size_t total = 0; |
| 133 | loff_t p = 0; |
Dimitris Papastamos | 2bc9a81 | 2011-02-01 12:24:08 +0000 | [diff] [blame] | 134 | |
Stephen Warren | 00b317a | 2011-04-01 14:50:44 -0600 | [diff] [blame] | 135 | wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; |
| 136 | regsize = codec->driver->reg_word_size * 2; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 137 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 138 | len = wordsize + regsize + 2 + 1; |
| 139 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 140 | if (!codec->driver->reg_cache_size) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 141 | return 0; |
| 142 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 143 | if (codec->driver->reg_cache_step) |
| 144 | step = codec->driver->reg_cache_step; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 145 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 146 | for (i = 0; i < codec->driver->reg_cache_size; i += step) { |
Lars-Peter Clausen | b92d150 | 2011-08-27 18:24:14 +0200 | [diff] [blame] | 147 | if (!snd_soc_codec_readable_register(codec, i)) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 148 | continue; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 149 | if (codec->driver->display_register) { |
| 150 | count += codec->driver->display_register(codec, buf + count, |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 151 | PAGE_SIZE - count, i); |
Mark Brown | 5164d74 | 2010-07-14 16:14:33 +0100 | [diff] [blame] | 152 | } else { |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 153 | /* only support larger than PAGE_SIZE bytes debugfs |
| 154 | * entries for the default case */ |
| 155 | if (p >= pos) { |
| 156 | if (total + len >= count - 1) |
| 157 | break; |
| 158 | format_register_str(codec, i, buf + total, len); |
| 159 | total += len; |
| 160 | } |
| 161 | p += len; |
Mark Brown | 5164d74 | 2010-07-14 16:14:33 +0100 | [diff] [blame] | 162 | } |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 165 | total = min(total, count - 1); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 166 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 167 | return total; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 168 | } |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 169 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 170 | static ssize_t codec_reg_show(struct device *dev, |
| 171 | struct device_attribute *attr, char *buf) |
| 172 | { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 173 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 174 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 175 | return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL); |
| 179 | |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 180 | static ssize_t pmdown_time_show(struct device *dev, |
| 181 | struct device_attribute *attr, char *buf) |
| 182 | { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 183 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 184 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 185 | return sprintf(buf, "%ld\n", rtd->pmdown_time); |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | static ssize_t pmdown_time_set(struct device *dev, |
| 189 | struct device_attribute *attr, |
| 190 | const char *buf, size_t count) |
| 191 | { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 192 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
Mark Brown | c593b52 | 2010-10-27 20:11:17 -0700 | [diff] [blame] | 193 | int ret; |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 194 | |
Mark Brown | c593b52 | 2010-10-27 20:11:17 -0700 | [diff] [blame] | 195 | ret = strict_strtol(buf, 10, &rtd->pmdown_time); |
| 196 | if (ret) |
| 197 | return ret; |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 198 | |
| 199 | return count; |
| 200 | } |
| 201 | |
| 202 | static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set); |
| 203 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 204 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 205 | static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf, |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 206 | size_t count, loff_t *ppos) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 207 | { |
| 208 | ssize_t ret; |
| 209 | struct snd_soc_codec *codec = file->private_data; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 210 | char *buf; |
| 211 | |
| 212 | if (*ppos < 0 || !count) |
| 213 | return -EINVAL; |
| 214 | |
| 215 | buf = kmalloc(count, GFP_KERNEL); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 216 | if (!buf) |
| 217 | return -ENOMEM; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 218 | |
| 219 | ret = soc_codec_reg_show(codec, buf, count, *ppos); |
| 220 | if (ret >= 0) { |
| 221 | if (copy_to_user(user_buf, buf, ret)) { |
| 222 | kfree(buf); |
| 223 | return -EFAULT; |
| 224 | } |
| 225 | *ppos += ret; |
| 226 | } |
| 227 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 228 | kfree(buf); |
| 229 | return ret; |
| 230 | } |
| 231 | |
| 232 | static ssize_t codec_reg_write_file(struct file *file, |
| 233 | const char __user *user_buf, size_t count, loff_t *ppos) |
| 234 | { |
| 235 | char buf[32]; |
Stephen Boyd | 34e268d | 2011-05-12 16:50:10 -0700 | [diff] [blame] | 236 | size_t buf_size; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 237 | char *start = buf; |
| 238 | unsigned long reg, value; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 239 | struct snd_soc_codec *codec = file->private_data; |
| 240 | |
| 241 | buf_size = min(count, (sizeof(buf)-1)); |
| 242 | if (copy_from_user(buf, user_buf, buf_size)) |
| 243 | return -EFAULT; |
| 244 | buf[buf_size] = 0; |
| 245 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 246 | while (*start == ' ') |
| 247 | start++; |
| 248 | reg = simple_strtoul(start, &start, 16); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 249 | while (*start == ' ') |
| 250 | start++; |
| 251 | if (strict_strtoul(start, 16, &value)) |
| 252 | return -EINVAL; |
Mark Brown | 0d51a9c | 2011-01-06 16:04:57 +0000 | [diff] [blame] | 253 | |
| 254 | /* Userspace has been fiddling around behind the kernel's back */ |
Rusty Russell | 373d4d0 | 2013-01-21 17:17:39 +1030 | [diff] [blame] | 255 | add_taint(TAINT_USER, LOCKDEP_NOW_UNRELIABLE); |
Mark Brown | 0d51a9c | 2011-01-06 16:04:57 +0000 | [diff] [blame] | 256 | |
Dimitris Papastamos | e4f078d | 2010-12-07 16:30:38 +0000 | [diff] [blame] | 257 | snd_soc_write(codec, reg, value); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 258 | return buf_size; |
| 259 | } |
| 260 | |
| 261 | static const struct file_operations codec_reg_fops = { |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 262 | .open = simple_open, |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 263 | .read = codec_reg_read_file, |
| 264 | .write = codec_reg_write_file, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 265 | .llseek = default_llseek, |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 266 | }; |
| 267 | |
| 268 | static void soc_init_codec_debugfs(struct snd_soc_codec *codec) |
| 269 | { |
Jarkko Nikula | d6ce4cf | 2010-11-05 20:35:20 +0200 | [diff] [blame] | 270 | struct dentry *debugfs_card_root = codec->card->debugfs_card_root; |
| 271 | |
| 272 | codec->debugfs_codec_root = debugfs_create_dir(codec->name, |
| 273 | debugfs_card_root); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 274 | if (!codec->debugfs_codec_root) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 275 | dev_warn(codec->dev, |
| 276 | "ASoC: Failed to create codec debugfs directory\n"); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 277 | return; |
| 278 | } |
| 279 | |
Mark Brown | aaee8ef | 2011-01-26 20:53:50 +0000 | [diff] [blame] | 280 | debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root, |
| 281 | &codec->cache_sync); |
| 282 | debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root, |
| 283 | &codec->cache_only); |
| 284 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 285 | codec->debugfs_reg = debugfs_create_file("codec_reg", 0644, |
| 286 | codec->debugfs_codec_root, |
| 287 | codec, &codec_reg_fops); |
| 288 | if (!codec->debugfs_reg) |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 289 | dev_warn(codec->dev, |
| 290 | "ASoC: Failed to create codec register debugfs file\n"); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 291 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 292 | snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) |
| 296 | { |
| 297 | debugfs_remove_recursive(codec->debugfs_codec_root); |
| 298 | } |
| 299 | |
Sebastien Guiriec | 731f1ab | 2012-02-15 15:25:31 +0000 | [diff] [blame] | 300 | static void soc_init_platform_debugfs(struct snd_soc_platform *platform) |
| 301 | { |
| 302 | struct dentry *debugfs_card_root = platform->card->debugfs_card_root; |
| 303 | |
| 304 | platform->debugfs_platform_root = debugfs_create_dir(platform->name, |
| 305 | debugfs_card_root); |
| 306 | if (!platform->debugfs_platform_root) { |
| 307 | dev_warn(platform->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 308 | "ASoC: Failed to create platform debugfs directory\n"); |
Sebastien Guiriec | 731f1ab | 2012-02-15 15:25:31 +0000 | [diff] [blame] | 309 | return; |
| 310 | } |
| 311 | |
| 312 | snd_soc_dapm_debugfs_init(&platform->dapm, |
| 313 | platform->debugfs_platform_root); |
| 314 | } |
| 315 | |
| 316 | static void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform) |
| 317 | { |
| 318 | debugfs_remove_recursive(platform->debugfs_platform_root); |
| 319 | } |
| 320 | |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 321 | static ssize_t codec_list_read_file(struct file *file, char __user *user_buf, |
| 322 | size_t count, loff_t *ppos) |
| 323 | { |
| 324 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 325 | ssize_t len, ret = 0; |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 326 | struct snd_soc_codec *codec; |
| 327 | |
| 328 | if (!buf) |
| 329 | return -ENOMEM; |
| 330 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 331 | list_for_each_entry(codec, &codec_list, list) { |
| 332 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", |
| 333 | codec->name); |
| 334 | if (len >= 0) |
| 335 | ret += len; |
| 336 | if (ret > PAGE_SIZE) { |
| 337 | ret = PAGE_SIZE; |
| 338 | break; |
| 339 | } |
| 340 | } |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 341 | |
| 342 | if (ret >= 0) |
| 343 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 344 | |
| 345 | kfree(buf); |
| 346 | |
| 347 | return ret; |
| 348 | } |
| 349 | |
| 350 | static const struct file_operations codec_list_fops = { |
| 351 | .read = codec_list_read_file, |
| 352 | .llseek = default_llseek,/* read accesses f_pos */ |
| 353 | }; |
| 354 | |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 355 | static ssize_t dai_list_read_file(struct file *file, char __user *user_buf, |
| 356 | size_t count, loff_t *ppos) |
| 357 | { |
| 358 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 359 | ssize_t len, ret = 0; |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 360 | struct snd_soc_dai *dai; |
| 361 | |
| 362 | if (!buf) |
| 363 | return -ENOMEM; |
| 364 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 365 | list_for_each_entry(dai, &dai_list, list) { |
| 366 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name); |
| 367 | if (len >= 0) |
| 368 | ret += len; |
| 369 | if (ret > PAGE_SIZE) { |
| 370 | ret = PAGE_SIZE; |
| 371 | break; |
| 372 | } |
| 373 | } |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 374 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 375 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 376 | |
| 377 | kfree(buf); |
| 378 | |
| 379 | return ret; |
| 380 | } |
| 381 | |
| 382 | static const struct file_operations dai_list_fops = { |
| 383 | .read = dai_list_read_file, |
| 384 | .llseek = default_llseek,/* read accesses f_pos */ |
| 385 | }; |
| 386 | |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 387 | static ssize_t platform_list_read_file(struct file *file, |
| 388 | char __user *user_buf, |
| 389 | size_t count, loff_t *ppos) |
| 390 | { |
| 391 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 392 | ssize_t len, ret = 0; |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 393 | struct snd_soc_platform *platform; |
| 394 | |
| 395 | if (!buf) |
| 396 | return -ENOMEM; |
| 397 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 398 | list_for_each_entry(platform, &platform_list, list) { |
| 399 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", |
| 400 | platform->name); |
| 401 | if (len >= 0) |
| 402 | ret += len; |
| 403 | if (ret > PAGE_SIZE) { |
| 404 | ret = PAGE_SIZE; |
| 405 | break; |
| 406 | } |
| 407 | } |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 408 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 409 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 410 | |
| 411 | kfree(buf); |
| 412 | |
| 413 | return ret; |
| 414 | } |
| 415 | |
| 416 | static const struct file_operations platform_list_fops = { |
| 417 | .read = platform_list_read_file, |
| 418 | .llseek = default_llseek,/* read accesses f_pos */ |
| 419 | }; |
| 420 | |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 421 | static void soc_init_card_debugfs(struct snd_soc_card *card) |
| 422 | { |
| 423 | card->debugfs_card_root = debugfs_create_dir(card->name, |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 424 | snd_soc_debugfs_root); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 425 | if (!card->debugfs_card_root) { |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 426 | dev_warn(card->dev, |
Lothar Waßmann | 7c08be8 | 2011-12-09 14:16:29 +0100 | [diff] [blame] | 427 | "ASoC: Failed to create card debugfs directory\n"); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 428 | return; |
| 429 | } |
| 430 | |
| 431 | card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644, |
| 432 | card->debugfs_card_root, |
| 433 | &card->pop_time); |
| 434 | if (!card->debugfs_pop_time) |
| 435 | dev_warn(card->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 436 | "ASoC: Failed to create pop time debugfs file\n"); |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | static void soc_cleanup_card_debugfs(struct snd_soc_card *card) |
| 440 | { |
| 441 | debugfs_remove_recursive(card->debugfs_card_root); |
| 442 | } |
| 443 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 444 | #else |
| 445 | |
| 446 | static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec) |
| 447 | { |
| 448 | } |
| 449 | |
| 450 | static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) |
| 451 | { |
| 452 | } |
Axel Lin | b95fccb | 2010-11-09 17:06:44 +0800 | [diff] [blame] | 453 | |
Sebastien Guiriec | 731f1ab | 2012-02-15 15:25:31 +0000 | [diff] [blame] | 454 | static inline void soc_init_platform_debugfs(struct snd_soc_platform *platform) |
| 455 | { |
| 456 | } |
| 457 | |
| 458 | static inline void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform) |
| 459 | { |
| 460 | } |
| 461 | |
Axel Lin | b95fccb | 2010-11-09 17:06:44 +0800 | [diff] [blame] | 462 | static inline void soc_init_card_debugfs(struct snd_soc_card *card) |
| 463 | { |
| 464 | } |
| 465 | |
| 466 | static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card) |
| 467 | { |
| 468 | } |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 469 | #endif |
| 470 | |
Liam Girdwood | 47c88ff | 2012-04-25 12:12:53 +0100 | [diff] [blame] | 471 | struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card, |
| 472 | const char *dai_link, int stream) |
| 473 | { |
| 474 | int i; |
| 475 | |
| 476 | for (i = 0; i < card->num_links; i++) { |
| 477 | if (card->rtd[i].dai_link->no_pcm && |
| 478 | !strcmp(card->rtd[i].dai_link->name, dai_link)) |
| 479 | return card->rtd[i].pcm->streams[stream].substream; |
| 480 | } |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 481 | dev_dbg(card->dev, "ASoC: failed to find dai link %s\n", dai_link); |
Liam Girdwood | 47c88ff | 2012-04-25 12:12:53 +0100 | [diff] [blame] | 482 | return NULL; |
| 483 | } |
| 484 | EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream); |
| 485 | |
| 486 | struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card, |
| 487 | const char *dai_link) |
| 488 | { |
| 489 | int i; |
| 490 | |
| 491 | for (i = 0; i < card->num_links; i++) { |
| 492 | if (!strcmp(card->rtd[i].dai_link->name, dai_link)) |
| 493 | return &card->rtd[i]; |
| 494 | } |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 495 | dev_dbg(card->dev, "ASoC: failed to find rtd %s\n", dai_link); |
Liam Girdwood | 47c88ff | 2012-04-25 12:12:53 +0100 | [diff] [blame] | 496 | return NULL; |
| 497 | } |
| 498 | EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime); |
| 499 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 500 | #ifdef CONFIG_SND_SOC_AC97_BUS |
| 501 | /* unregister ac97 codec */ |
| 502 | static int soc_ac97_dev_unregister(struct snd_soc_codec *codec) |
| 503 | { |
| 504 | if (codec->ac97->dev.bus) |
| 505 | device_unregister(&codec->ac97->dev); |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | /* stop no dev release warning */ |
| 510 | static void soc_ac97_device_release(struct device *dev){} |
| 511 | |
| 512 | /* register ac97 codec to bus */ |
| 513 | static int soc_ac97_dev_register(struct snd_soc_codec *codec) |
| 514 | { |
| 515 | int err; |
| 516 | |
| 517 | codec->ac97->dev.bus = &ac97_bus_type; |
Mark Brown | 4ac5c61 | 2009-04-01 19:35:01 +0100 | [diff] [blame] | 518 | codec->ac97->dev.parent = codec->card->dev; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 519 | codec->ac97->dev.release = soc_ac97_device_release; |
| 520 | |
Kay Sievers | bb072bf | 2008-11-02 03:50:35 +0100 | [diff] [blame] | 521 | dev_set_name(&codec->ac97->dev, "%d-%d:%s", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 522 | codec->card->snd_card->number, 0, codec->name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 523 | err = device_register(&codec->ac97->dev); |
| 524 | if (err < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 525 | dev_err(codec->dev, "ASoC: Can't register ac97 bus\n"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 526 | codec->ac97->dev.bus = NULL; |
| 527 | return err; |
| 528 | } |
| 529 | return 0; |
| 530 | } |
| 531 | #endif |
| 532 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 533 | #ifdef CONFIG_PM_SLEEP |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 534 | /* powers down audio subsystem for suspend */ |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 535 | int snd_soc_suspend(struct device *dev) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 536 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 537 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 538 | struct snd_soc_codec *codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 539 | int i; |
| 540 | |
Daniel Mack | e3509ff | 2009-06-03 17:44:49 +0200 | [diff] [blame] | 541 | /* If the initialization of this soc device failed, there is no codec |
| 542 | * associated with it. Just bail out in this case. |
| 543 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 544 | if (list_empty(&card->codec_dev_list)) |
Daniel Mack | e3509ff | 2009-06-03 17:44:49 +0200 | [diff] [blame] | 545 | return 0; |
| 546 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 547 | /* Due to the resume being scheduled into a workqueue we could |
| 548 | * suspend before that's finished - wait for it to complete. |
| 549 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 550 | snd_power_lock(card->snd_card); |
| 551 | snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0); |
| 552 | snd_power_unlock(card->snd_card); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 553 | |
| 554 | /* we're going to block userspace touching us until resume completes */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 555 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 556 | |
Mark Brown | a00f90f | 2010-12-02 16:24:24 +0000 | [diff] [blame] | 557 | /* mute any active DACs */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 558 | for (i = 0; i < card->num_rtd; i++) { |
| 559 | struct snd_soc_dai *dai = card->rtd[i].codec_dai; |
| 560 | struct snd_soc_dai_driver *drv = dai->driver; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 561 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 562 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 563 | continue; |
| 564 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 565 | if (drv->ops->digital_mute && dai->playback_active) |
| 566 | drv->ops->digital_mute(dai, 1); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 567 | } |
| 568 | |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 569 | /* suspend all pcms */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 570 | for (i = 0; i < card->num_rtd; i++) { |
| 571 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 572 | continue; |
| 573 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 574 | snd_pcm_suspend_all(card->rtd[i].pcm); |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 575 | } |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 576 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 577 | if (card->suspend_pre) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 578 | card->suspend_pre(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 579 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 580 | for (i = 0; i < card->num_rtd; i++) { |
| 581 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
| 582 | struct snd_soc_platform *platform = card->rtd[i].platform; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 583 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 584 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 585 | continue; |
| 586 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 587 | if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control) |
| 588 | cpu_dai->driver->suspend(cpu_dai); |
| 589 | if (platform->driver->suspend && !platform->suspended) { |
| 590 | platform->driver->suspend(cpu_dai); |
| 591 | platform->suspended = 1; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 592 | } |
| 593 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 594 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 595 | /* close any waiting streams and save state */ |
| 596 | for (i = 0; i < card->num_rtd; i++) { |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 597 | flush_delayed_work(&card->rtd[i].delayed_work); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 598 | card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 599 | } |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 600 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 601 | for (i = 0; i < card->num_rtd; i++) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 602 | |
| 603 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 604 | continue; |
| 605 | |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 606 | snd_soc_dapm_stream_event(&card->rtd[i], |
| 607 | SNDRV_PCM_STREAM_PLAYBACK, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 608 | SND_SOC_DAPM_STREAM_SUSPEND); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 609 | |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 610 | snd_soc_dapm_stream_event(&card->rtd[i], |
| 611 | SNDRV_PCM_STREAM_CAPTURE, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 612 | SND_SOC_DAPM_STREAM_SUSPEND); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 613 | } |
| 614 | |
Mark Brown | e2d32ff | 2012-08-31 17:38:32 -0700 | [diff] [blame] | 615 | /* Recheck all analogue paths too */ |
| 616 | dapm_mark_io_dirty(&card->dapm); |
| 617 | snd_soc_dapm_sync(&card->dapm); |
| 618 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 619 | /* suspend all CODECs */ |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 620 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 621 | /* If there are paths active then the CODEC will be held with |
| 622 | * bias _ON and should not be suspended. */ |
| 623 | if (!codec->suspended && codec->driver->suspend) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 624 | switch (codec->dapm.bias_level) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 625 | case SND_SOC_BIAS_STANDBY: |
Mark Brown | 125a25d | 2012-01-31 15:49:10 +0000 | [diff] [blame] | 626 | /* |
| 627 | * If the CODEC is capable of idle |
| 628 | * bias off then being in STANDBY |
| 629 | * means it's doing something, |
| 630 | * otherwise fall through. |
| 631 | */ |
| 632 | if (codec->dapm.idle_bias_off) { |
| 633 | dev_dbg(codec->dev, |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 634 | "ASoC: idle_bias_off CODEC on over suspend\n"); |
Mark Brown | 125a25d | 2012-01-31 15:49:10 +0000 | [diff] [blame] | 635 | break; |
| 636 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 637 | case SND_SOC_BIAS_OFF: |
Lars-Peter Clausen | 84b315e | 2011-12-02 10:18:28 +0100 | [diff] [blame] | 638 | codec->driver->suspend(codec); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 639 | codec->suspended = 1; |
Mark Brown | 7be4ba2 | 2011-07-18 13:17:13 +0900 | [diff] [blame] | 640 | codec->cache_sync = 1; |
Mark Brown | da8b8e0 | 2012-09-12 12:21:52 +0800 | [diff] [blame] | 641 | if (codec->using_regmap) |
| 642 | regcache_mark_dirty(codec->control_data); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 643 | break; |
| 644 | default: |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 645 | dev_dbg(codec->dev, |
| 646 | "ASoC: CODEC is on over suspend\n"); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 647 | break; |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | for (i = 0; i < card->num_rtd; i++) { |
| 653 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
| 654 | |
| 655 | if (card->rtd[i].dai_link->ignore_suspend) |
| 656 | continue; |
| 657 | |
| 658 | if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control) |
| 659 | cpu_dai->driver->suspend(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 660 | } |
| 661 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 662 | if (card->suspend_post) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 663 | card->suspend_post(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 664 | |
| 665 | return 0; |
| 666 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 667 | EXPORT_SYMBOL_GPL(snd_soc_suspend); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 668 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 669 | /* deferred resume work, so resume can complete before we finished |
| 670 | * setting our codec back up, which can be very slow on I2C |
| 671 | */ |
| 672 | static void soc_resume_deferred(struct work_struct *work) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 673 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 674 | struct snd_soc_card *card = |
| 675 | container_of(work, struct snd_soc_card, deferred_resume_work); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 676 | struct snd_soc_codec *codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 677 | int i; |
| 678 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 679 | /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, |
| 680 | * so userspace apps are blocked from touching us |
| 681 | */ |
| 682 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 683 | dev_dbg(card->dev, "ASoC: starting resume work\n"); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 684 | |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 685 | /* Bring us up into D2 so that DAPM starts enabling things */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 686 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2); |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 687 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 688 | if (card->resume_pre) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 689 | card->resume_pre(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 690 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 691 | /* resume AC97 DAIs */ |
| 692 | for (i = 0; i < card->num_rtd; i++) { |
| 693 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 694 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 695 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 696 | continue; |
| 697 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 698 | if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control) |
| 699 | cpu_dai->driver->resume(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 700 | } |
| 701 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 702 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 703 | /* If the CODEC was idle over suspend then it will have been |
| 704 | * left with bias OFF or STANDBY and suspended so we must now |
| 705 | * resume. Otherwise the suspend was suppressed. |
| 706 | */ |
| 707 | if (codec->driver->resume && codec->suspended) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 708 | switch (codec->dapm.bias_level) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 709 | case SND_SOC_BIAS_STANDBY: |
| 710 | case SND_SOC_BIAS_OFF: |
| 711 | codec->driver->resume(codec); |
| 712 | codec->suspended = 0; |
| 713 | break; |
| 714 | default: |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 715 | dev_dbg(codec->dev, |
| 716 | "ASoC: CODEC was on over suspend\n"); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 717 | break; |
| 718 | } |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 719 | } |
| 720 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 721 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 722 | for (i = 0; i < card->num_rtd; i++) { |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 723 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 724 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 725 | continue; |
| 726 | |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 727 | snd_soc_dapm_stream_event(&card->rtd[i], |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 728 | SNDRV_PCM_STREAM_PLAYBACK, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 729 | SND_SOC_DAPM_STREAM_RESUME); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 730 | |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 731 | snd_soc_dapm_stream_event(&card->rtd[i], |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 732 | SNDRV_PCM_STREAM_CAPTURE, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 733 | SND_SOC_DAPM_STREAM_RESUME); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 734 | } |
| 735 | |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 736 | /* unmute any active DACs */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 737 | for (i = 0; i < card->num_rtd; i++) { |
| 738 | struct snd_soc_dai *dai = card->rtd[i].codec_dai; |
| 739 | struct snd_soc_dai_driver *drv = dai->driver; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 740 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 741 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 742 | continue; |
| 743 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 744 | if (drv->ops->digital_mute && dai->playback_active) |
| 745 | drv->ops->digital_mute(dai, 0); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 746 | } |
| 747 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 748 | for (i = 0; i < card->num_rtd; i++) { |
| 749 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
| 750 | struct snd_soc_platform *platform = card->rtd[i].platform; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 751 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 752 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 753 | continue; |
| 754 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 755 | if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control) |
| 756 | cpu_dai->driver->resume(cpu_dai); |
| 757 | if (platform->driver->resume && platform->suspended) { |
| 758 | platform->driver->resume(cpu_dai); |
| 759 | platform->suspended = 0; |
| 760 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 761 | } |
| 762 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 763 | if (card->resume_post) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 764 | card->resume_post(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 765 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 766 | dev_dbg(card->dev, "ASoC: resume work completed\n"); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 767 | |
| 768 | /* userspace can access us now we are back as we were before */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 769 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0); |
Mark Brown | e2d32ff | 2012-08-31 17:38:32 -0700 | [diff] [blame] | 770 | |
| 771 | /* Recheck all analogue paths too */ |
| 772 | dapm_mark_io_dirty(&card->dapm); |
| 773 | snd_soc_dapm_sync(&card->dapm); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | /* powers up audio subsystem after a suspend */ |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 777 | int snd_soc_resume(struct device *dev) |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 778 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 779 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Stephen Warren | 82e14e8 | 2011-05-25 14:06:41 -0600 | [diff] [blame] | 780 | int i, ac97_control = 0; |
Peter Ujfalusi | b9dd94a | 2010-02-22 13:27:13 +0200 | [diff] [blame] | 781 | |
Eric Miao | 5ff1ddf | 2011-11-23 22:37:00 +0800 | [diff] [blame] | 782 | /* If the initialization of this soc device failed, there is no codec |
| 783 | * associated with it. Just bail out in this case. |
| 784 | */ |
| 785 | if (list_empty(&card->codec_dev_list)) |
| 786 | return 0; |
| 787 | |
Mark Brown | 64ab9ba | 2009-03-31 11:27:03 +0100 | [diff] [blame] | 788 | /* AC97 devices might have other drivers hanging off them so |
| 789 | * need to resume immediately. Other drivers don't have that |
| 790 | * problem and may take a substantial amount of time to resume |
| 791 | * due to I/O costs and anti-pop so handle them out of line. |
| 792 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 793 | for (i = 0; i < card->num_rtd; i++) { |
| 794 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
Stephen Warren | 82e14e8 | 2011-05-25 14:06:41 -0600 | [diff] [blame] | 795 | ac97_control |= cpu_dai->driver->ac97_control; |
| 796 | } |
| 797 | if (ac97_control) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 798 | dev_dbg(dev, "ASoC: Resuming AC97 immediately\n"); |
Stephen Warren | 82e14e8 | 2011-05-25 14:06:41 -0600 | [diff] [blame] | 799 | soc_resume_deferred(&card->deferred_resume_work); |
| 800 | } else { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 801 | dev_dbg(dev, "ASoC: Scheduling resume work\n"); |
Stephen Warren | 82e14e8 | 2011-05-25 14:06:41 -0600 | [diff] [blame] | 802 | if (!schedule_work(&card->deferred_resume_work)) |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 803 | dev_err(dev, "ASoC: resume work item may be lost\n"); |
Mark Brown | 64ab9ba | 2009-03-31 11:27:03 +0100 | [diff] [blame] | 804 | } |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 805 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 806 | return 0; |
| 807 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 808 | EXPORT_SYMBOL_GPL(snd_soc_resume); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 809 | #else |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 810 | #define snd_soc_suspend NULL |
| 811 | #define snd_soc_resume NULL |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 812 | #endif |
| 813 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 814 | static const struct snd_soc_dai_ops null_dai_ops = { |
Barry Song | 02a06d3 | 2009-10-16 18:13:38 +0800 | [diff] [blame] | 815 | }; |
| 816 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 817 | static int soc_bind_dai_link(struct snd_soc_card *card, int num) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 818 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 819 | struct snd_soc_dai_link *dai_link = &card->dai_link[num]; |
| 820 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 821 | struct snd_soc_codec *codec; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 822 | struct snd_soc_platform *platform; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 823 | struct snd_soc_dai *codec_dai, *cpu_dai; |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 824 | const char *platform_name; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 825 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 826 | dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num); |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 827 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 828 | /* Find CPU DAI from registered DAIs*/ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 829 | list_for_each_entry(cpu_dai, &dai_list, list) { |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 830 | if (dai_link->cpu_of_node && |
| 831 | (cpu_dai->dev->of_node != dai_link->cpu_of_node)) |
| 832 | continue; |
| 833 | if (dai_link->cpu_name && |
| 834 | strcmp(dev_name(cpu_dai->dev), dai_link->cpu_name)) |
| 835 | continue; |
| 836 | if (dai_link->cpu_dai_name && |
| 837 | strcmp(cpu_dai->name, dai_link->cpu_dai_name)) |
| 838 | continue; |
Stephen Warren | 2610ab7 | 2011-12-07 13:58:27 -0700 | [diff] [blame] | 839 | |
| 840 | rtd->cpu_dai = cpu_dai; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 841 | } |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 842 | |
| 843 | if (!rtd->cpu_dai) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 844 | dev_err(card->dev, "ASoC: CPU DAI %s not registered\n", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 845 | dai_link->cpu_dai_name); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 846 | return -EPROBE_DEFER; |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 847 | } |
| 848 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 849 | /* Find CODEC from registered CODECs */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 850 | list_for_each_entry(codec, &codec_list, list) { |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 851 | if (dai_link->codec_of_node) { |
| 852 | if (codec->dev->of_node != dai_link->codec_of_node) |
| 853 | continue; |
| 854 | } else { |
| 855 | if (strcmp(codec->name, dai_link->codec_name)) |
| 856 | continue; |
| 857 | } |
Mark Brown | 6b05eda | 2008-12-08 19:26:48 +0000 | [diff] [blame] | 858 | |
Stephen Warren | 2610ab7 | 2011-12-07 13:58:27 -0700 | [diff] [blame] | 859 | rtd->codec = codec; |
| 860 | |
| 861 | /* |
| 862 | * CODEC found, so find CODEC DAI from registered DAIs from |
| 863 | * this CODEC |
| 864 | */ |
| 865 | list_for_each_entry(codec_dai, &dai_list, list) { |
| 866 | if (codec->dev == codec_dai->dev && |
| 867 | !strcmp(codec_dai->name, |
| 868 | dai_link->codec_dai_name)) { |
| 869 | |
| 870 | rtd->codec_dai = codec_dai; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 871 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 872 | } |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 873 | |
| 874 | if (!rtd->codec_dai) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 875 | dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n", |
Stephen Warren | 2610ab7 | 2011-12-07 13:58:27 -0700 | [diff] [blame] | 876 | dai_link->codec_dai_name); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 877 | return -EPROBE_DEFER; |
| 878 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 879 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 880 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 881 | if (!rtd->codec) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 882 | dev_err(card->dev, "ASoC: CODEC %s not registered\n", |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 883 | dai_link->codec_name); |
| 884 | return -EPROBE_DEFER; |
| 885 | } |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 886 | |
| 887 | /* if there's no platform we match on the empty platform */ |
| 888 | platform_name = dai_link->platform_name; |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 889 | if (!platform_name && !dai_link->platform_of_node) |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 890 | platform_name = "snd-soc-dummy"; |
| 891 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 892 | /* find one from the set of registered platforms */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 893 | list_for_each_entry(platform, &platform_list, list) { |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 894 | if (dai_link->platform_of_node) { |
| 895 | if (platform->dev->of_node != |
| 896 | dai_link->platform_of_node) |
| 897 | continue; |
| 898 | } else { |
| 899 | if (strcmp(platform->name, platform_name)) |
| 900 | continue; |
| 901 | } |
Stephen Warren | 2610ab7 | 2011-12-07 13:58:27 -0700 | [diff] [blame] | 902 | |
| 903 | rtd->platform = platform; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 904 | } |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 905 | if (!rtd->platform) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 906 | dev_err(card->dev, "ASoC: platform %s not registered\n", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 907 | dai_link->platform_name); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 908 | return -EPROBE_DEFER; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 909 | } |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 910 | |
| 911 | card->num_rtd++; |
| 912 | |
| 913 | return 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 914 | } |
| 915 | |
Stephen Warren | d12cd19 | 2012-06-08 12:34:22 -0600 | [diff] [blame] | 916 | static int soc_remove_platform(struct snd_soc_platform *platform) |
| 917 | { |
| 918 | int ret; |
| 919 | |
| 920 | if (platform->driver->remove) { |
| 921 | ret = platform->driver->remove(platform); |
| 922 | if (ret < 0) |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 923 | dev_err(platform->dev, "ASoC: failed to remove %d\n", |
| 924 | ret); |
Stephen Warren | d12cd19 | 2012-06-08 12:34:22 -0600 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | /* Make sure all DAPM widgets are freed */ |
| 928 | snd_soc_dapm_free(&platform->dapm); |
| 929 | |
| 930 | soc_cleanup_platform_debugfs(platform); |
| 931 | platform->probed = 0; |
| 932 | list_del(&platform->card_list); |
| 933 | module_put(platform->dev->driver->owner); |
| 934 | |
| 935 | return 0; |
| 936 | } |
| 937 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 938 | static void soc_remove_codec(struct snd_soc_codec *codec) |
| 939 | { |
| 940 | int err; |
| 941 | |
| 942 | if (codec->driver->remove) { |
| 943 | err = codec->driver->remove(codec); |
| 944 | if (err < 0) |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 945 | dev_err(codec->dev, "ASoC: failed to remove %d\n", err); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | /* Make sure all DAPM widgets are freed */ |
| 949 | snd_soc_dapm_free(&codec->dapm); |
| 950 | |
| 951 | soc_cleanup_codec_debugfs(codec); |
| 952 | codec->probed = 0; |
| 953 | list_del(&codec->card_list); |
| 954 | module_put(codec->dev->driver->owner); |
| 955 | } |
| 956 | |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 957 | static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 958 | { |
| 959 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 960 | struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; |
| 961 | int err; |
| 962 | |
| 963 | /* unregister the rtd device */ |
| 964 | if (rtd->dev_registered) { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 965 | device_remove_file(rtd->dev, &dev_attr_pmdown_time); |
| 966 | device_remove_file(rtd->dev, &dev_attr_codec_reg); |
| 967 | device_unregister(rtd->dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 968 | rtd->dev_registered = 0; |
| 969 | } |
| 970 | |
| 971 | /* remove the CODEC DAI */ |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 972 | if (codec_dai && codec_dai->probed && |
| 973 | codec_dai->driver->remove_order == order) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 974 | if (codec_dai->driver->remove) { |
| 975 | err = codec_dai->driver->remove(codec_dai); |
| 976 | if (err < 0) |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 977 | dev_err(codec_dai->dev, |
| 978 | "ASoC: failed to remove %s: %d\n", |
| 979 | codec_dai->name, err); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 980 | } |
| 981 | codec_dai->probed = 0; |
| 982 | list_del(&codec_dai->card_list); |
| 983 | } |
| 984 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 985 | /* remove the cpu_dai */ |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 986 | if (cpu_dai && cpu_dai->probed && |
| 987 | cpu_dai->driver->remove_order == order) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 988 | if (cpu_dai->driver->remove) { |
| 989 | err = cpu_dai->driver->remove(cpu_dai); |
| 990 | if (err < 0) |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 991 | dev_err(cpu_dai->dev, |
| 992 | "ASoC: failed to remove %s: %d\n", |
| 993 | cpu_dai->name, err); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 994 | } |
| 995 | cpu_dai->probed = 0; |
| 996 | list_del(&cpu_dai->card_list); |
Stephen Warren | a9db7db | 2012-06-08 12:34:20 -0600 | [diff] [blame] | 997 | |
Stephen Warren | 18d7564 | 2012-06-08 12:34:21 -0600 | [diff] [blame] | 998 | if (!cpu_dai->codec) { |
| 999 | snd_soc_dapm_free(&cpu_dai->dapm); |
Stephen Warren | a9db7db | 2012-06-08 12:34:20 -0600 | [diff] [blame] | 1000 | module_put(cpu_dai->dev->driver->owner); |
Stephen Warren | 18d7564 | 2012-06-08 12:34:21 -0600 | [diff] [blame] | 1001 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1002 | } |
| 1003 | } |
| 1004 | |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1005 | static void soc_remove_link_components(struct snd_soc_card *card, int num, |
| 1006 | int order) |
| 1007 | { |
| 1008 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
| 1009 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1010 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 1011 | struct snd_soc_platform *platform = rtd->platform; |
| 1012 | struct snd_soc_codec *codec; |
| 1013 | |
| 1014 | /* remove the platform */ |
| 1015 | if (platform && platform->probed && |
| 1016 | platform->driver->remove_order == order) { |
| 1017 | soc_remove_platform(platform); |
| 1018 | } |
| 1019 | |
| 1020 | /* remove the CODEC-side CODEC */ |
| 1021 | if (codec_dai) { |
| 1022 | codec = codec_dai->codec; |
| 1023 | if (codec && codec->probed && |
| 1024 | codec->driver->remove_order == order) |
| 1025 | soc_remove_codec(codec); |
| 1026 | } |
| 1027 | |
| 1028 | /* remove any CPU-side CODEC */ |
| 1029 | if (cpu_dai) { |
| 1030 | codec = cpu_dai->codec; |
| 1031 | if (codec && codec->probed && |
| 1032 | codec->driver->remove_order == order) |
| 1033 | soc_remove_codec(codec); |
| 1034 | } |
| 1035 | } |
| 1036 | |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1037 | static void soc_remove_dai_links(struct snd_soc_card *card) |
| 1038 | { |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1039 | int dai, order; |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1040 | |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1041 | for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; |
| 1042 | order++) { |
| 1043 | for (dai = 0; dai < card->num_rtd; dai++) |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1044 | soc_remove_link_dais(card, dai, order); |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1045 | } |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1046 | |
| 1047 | for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; |
| 1048 | order++) { |
| 1049 | for (dai = 0; dai < card->num_rtd; dai++) |
| 1050 | soc_remove_link_components(card, dai, order); |
| 1051 | } |
| 1052 | |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1053 | card->num_rtd = 0; |
| 1054 | } |
| 1055 | |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1056 | static void soc_set_name_prefix(struct snd_soc_card *card, |
| 1057 | struct snd_soc_codec *codec) |
| 1058 | { |
| 1059 | int i; |
| 1060 | |
Dimitris Papastamos | ff819b8 | 2010-12-02 14:53:03 +0000 | [diff] [blame] | 1061 | if (card->codec_conf == NULL) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1062 | return; |
| 1063 | |
Dimitris Papastamos | ff819b8 | 2010-12-02 14:53:03 +0000 | [diff] [blame] | 1064 | for (i = 0; i < card->num_configs; i++) { |
| 1065 | struct snd_soc_codec_conf *map = &card->codec_conf[i]; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1066 | if (map->dev_name && !strcmp(codec->name, map->dev_name)) { |
| 1067 | codec->name_prefix = map->name_prefix; |
| 1068 | break; |
| 1069 | } |
| 1070 | } |
| 1071 | } |
| 1072 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1073 | static int soc_probe_codec(struct snd_soc_card *card, |
| 1074 | struct snd_soc_codec *codec) |
| 1075 | { |
| 1076 | int ret = 0; |
Mark Brown | 89b95ac0 | 2011-03-07 16:38:44 +0000 | [diff] [blame] | 1077 | const struct snd_soc_codec_driver *driver = codec->driver; |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 1078 | struct snd_soc_dai *dai; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1079 | |
| 1080 | codec->card = card; |
| 1081 | codec->dapm.card = card; |
| 1082 | soc_set_name_prefix(card, codec); |
| 1083 | |
Jarkko Nikula | 70d2933 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1084 | if (!try_module_get(codec->dev->driver->owner)) |
| 1085 | return -ENODEV; |
| 1086 | |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1087 | soc_init_codec_debugfs(codec); |
| 1088 | |
Lars-Peter Clausen | 7753015 | 2011-05-05 16:59:09 +0200 | [diff] [blame] | 1089 | if (driver->dapm_widgets) |
| 1090 | snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets, |
| 1091 | driver->num_dapm_widgets); |
| 1092 | |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 1093 | /* Create DAPM widgets for each DAI stream */ |
| 1094 | list_for_each_entry(dai, &dai_list, list) { |
| 1095 | if (dai->dev != codec->dev) |
| 1096 | continue; |
| 1097 | |
| 1098 | snd_soc_dapm_new_dai_widgets(&codec->dapm, dai); |
| 1099 | } |
| 1100 | |
Mark Brown | 33c5f96 | 2011-08-22 18:40:30 +0100 | [diff] [blame] | 1101 | codec->dapm.idle_bias_off = driver->idle_bias_off; |
| 1102 | |
Mark Brown | 89b95ac0 | 2011-03-07 16:38:44 +0000 | [diff] [blame] | 1103 | if (driver->probe) { |
| 1104 | ret = driver->probe(codec); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1105 | if (ret < 0) { |
| 1106 | dev_err(codec->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1107 | "ASoC: failed to probe CODEC %d\n", ret); |
Jarkko Nikula | 70d2933 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1108 | goto err_probe; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1109 | } |
Chuansheng Liu | ff541f4 | 2012-12-21 18:17:12 +0800 | [diff] [blame] | 1110 | WARN(codec->dapm.idle_bias_off && |
| 1111 | codec->dapm.bias_level != SND_SOC_BIAS_OFF, |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 1112 | "codec %s can not start from non-off bias with idle_bias_off==1\n", |
| 1113 | codec->name); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1114 | } |
| 1115 | |
Mark Brown | 38cbf95 | 2012-06-22 13:04:02 +0100 | [diff] [blame] | 1116 | /* If the driver didn't set I/O up try regmap */ |
Mark Brown | 98d3088 | 2012-08-01 20:05:47 +0100 | [diff] [blame] | 1117 | if (!codec->write && dev_get_regmap(codec->dev, NULL)) |
Mark Brown | 38cbf95 | 2012-06-22 13:04:02 +0100 | [diff] [blame] | 1118 | snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP); |
| 1119 | |
Mark Brown | b7af1da | 2011-04-07 19:18:44 +0900 | [diff] [blame] | 1120 | if (driver->controls) |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1121 | snd_soc_add_codec_controls(codec, driver->controls, |
Mark Brown | b7af1da | 2011-04-07 19:18:44 +0900 | [diff] [blame] | 1122 | driver->num_controls); |
Mark Brown | 89b95ac0 | 2011-03-07 16:38:44 +0000 | [diff] [blame] | 1123 | if (driver->dapm_routes) |
| 1124 | snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes, |
| 1125 | driver->num_dapm_routes); |
| 1126 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1127 | /* mark codec as probed and add to card codec list */ |
| 1128 | codec->probed = 1; |
| 1129 | list_add(&codec->card_list, &card->codec_dev_list); |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1130 | list_add(&codec->dapm.list, &card->dapm_list); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1131 | |
Jarkko Nikula | 70d2933 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1132 | return 0; |
| 1133 | |
| 1134 | err_probe: |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1135 | soc_cleanup_codec_debugfs(codec); |
Jarkko Nikula | 70d2933 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1136 | module_put(codec->dev->driver->owner); |
| 1137 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1138 | return ret; |
| 1139 | } |
| 1140 | |
Liam Girdwood | 956245e | 2011-07-01 16:54:08 +0100 | [diff] [blame] | 1141 | static int soc_probe_platform(struct snd_soc_card *card, |
| 1142 | struct snd_soc_platform *platform) |
| 1143 | { |
| 1144 | int ret = 0; |
| 1145 | const struct snd_soc_platform_driver *driver = platform->driver; |
Liam Girdwood | be09ad9 | 2012-03-07 11:47:41 +0000 | [diff] [blame] | 1146 | struct snd_soc_dai *dai; |
Liam Girdwood | 956245e | 2011-07-01 16:54:08 +0100 | [diff] [blame] | 1147 | |
| 1148 | platform->card = card; |
Liam Girdwood | b795064 | 2011-07-04 22:10:52 +0100 | [diff] [blame] | 1149 | platform->dapm.card = card; |
Liam Girdwood | 956245e | 2011-07-01 16:54:08 +0100 | [diff] [blame] | 1150 | |
| 1151 | if (!try_module_get(platform->dev->driver->owner)) |
| 1152 | return -ENODEV; |
| 1153 | |
Sebastien Guiriec | 731f1ab | 2012-02-15 15:25:31 +0000 | [diff] [blame] | 1154 | soc_init_platform_debugfs(platform); |
| 1155 | |
Liam Girdwood | cb2cf61 | 2011-07-04 22:10:53 +0100 | [diff] [blame] | 1156 | if (driver->dapm_widgets) |
| 1157 | snd_soc_dapm_new_controls(&platform->dapm, |
| 1158 | driver->dapm_widgets, driver->num_dapm_widgets); |
| 1159 | |
Liam Girdwood | be09ad9 | 2012-03-07 11:47:41 +0000 | [diff] [blame] | 1160 | /* Create DAPM widgets for each DAI stream */ |
| 1161 | list_for_each_entry(dai, &dai_list, list) { |
| 1162 | if (dai->dev != platform->dev) |
| 1163 | continue; |
| 1164 | |
| 1165 | snd_soc_dapm_new_dai_widgets(&platform->dapm, dai); |
| 1166 | } |
| 1167 | |
Stephen Warren | 3fec6b6 | 2012-04-05 12:28:01 -0600 | [diff] [blame] | 1168 | platform->dapm.idle_bias_off = 1; |
| 1169 | |
Liam Girdwood | 956245e | 2011-07-01 16:54:08 +0100 | [diff] [blame] | 1170 | if (driver->probe) { |
| 1171 | ret = driver->probe(platform); |
| 1172 | if (ret < 0) { |
| 1173 | dev_err(platform->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1174 | "ASoC: failed to probe platform %d\n", ret); |
Liam Girdwood | 956245e | 2011-07-01 16:54:08 +0100 | [diff] [blame] | 1175 | goto err_probe; |
| 1176 | } |
| 1177 | } |
| 1178 | |
Liam Girdwood | cb2cf61 | 2011-07-04 22:10:53 +0100 | [diff] [blame] | 1179 | if (driver->controls) |
| 1180 | snd_soc_add_platform_controls(platform, driver->controls, |
| 1181 | driver->num_controls); |
| 1182 | if (driver->dapm_routes) |
| 1183 | snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes, |
| 1184 | driver->num_dapm_routes); |
| 1185 | |
Liam Girdwood | 956245e | 2011-07-01 16:54:08 +0100 | [diff] [blame] | 1186 | /* mark platform as probed and add to card platform list */ |
| 1187 | platform->probed = 1; |
| 1188 | list_add(&platform->card_list, &card->platform_dev_list); |
Liam Girdwood | b795064 | 2011-07-04 22:10:52 +0100 | [diff] [blame] | 1189 | list_add(&platform->dapm.list, &card->dapm_list); |
Liam Girdwood | 956245e | 2011-07-01 16:54:08 +0100 | [diff] [blame] | 1190 | |
| 1191 | return 0; |
| 1192 | |
| 1193 | err_probe: |
Liam Girdwood | 02db110 | 2012-03-02 16:13:44 +0000 | [diff] [blame] | 1194 | soc_cleanup_platform_debugfs(platform); |
Liam Girdwood | 956245e | 2011-07-01 16:54:08 +0100 | [diff] [blame] | 1195 | module_put(platform->dev->driver->owner); |
| 1196 | |
| 1197 | return ret; |
| 1198 | } |
| 1199 | |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1200 | static void rtd_release(struct device *dev) |
| 1201 | { |
| 1202 | kfree(dev); |
| 1203 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1204 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1205 | static int soc_post_component_init(struct snd_soc_card *card, |
| 1206 | struct snd_soc_codec *codec, |
| 1207 | int num, int dailess) |
| 1208 | { |
| 1209 | struct snd_soc_dai_link *dai_link = NULL; |
| 1210 | struct snd_soc_aux_dev *aux_dev = NULL; |
| 1211 | struct snd_soc_pcm_runtime *rtd; |
| 1212 | const char *temp, *name; |
| 1213 | int ret = 0; |
| 1214 | |
| 1215 | if (!dailess) { |
| 1216 | dai_link = &card->dai_link[num]; |
| 1217 | rtd = &card->rtd[num]; |
| 1218 | name = dai_link->name; |
| 1219 | } else { |
| 1220 | aux_dev = &card->aux_dev[num]; |
| 1221 | rtd = &card->rtd_aux[num]; |
| 1222 | name = aux_dev->name; |
| 1223 | } |
Janusz Krzysztofik | 0962bb2 | 2011-02-02 21:11:41 +0100 | [diff] [blame] | 1224 | rtd->card = card; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1225 | |
Mark Brown | 4b1cfcb | 2011-10-18 00:11:49 +0100 | [diff] [blame] | 1226 | /* Make sure all DAPM widgets are instantiated */ |
| 1227 | snd_soc_dapm_new_widgets(&codec->dapm); |
| 1228 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1229 | /* machine controls, routes and widgets are not prefixed */ |
| 1230 | temp = codec->name_prefix; |
| 1231 | codec->name_prefix = NULL; |
| 1232 | |
| 1233 | /* do machine specific initialization */ |
| 1234 | if (!dailess && dai_link->init) |
| 1235 | ret = dai_link->init(rtd); |
| 1236 | else if (dailess && aux_dev->init) |
| 1237 | ret = aux_dev->init(&codec->dapm); |
| 1238 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1239 | dev_err(card->dev, "ASoC: failed to init %s: %d\n", name, ret); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1240 | return ret; |
| 1241 | } |
| 1242 | codec->name_prefix = temp; |
| 1243 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1244 | /* register the rtd device */ |
| 1245 | rtd->codec = codec; |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1246 | |
| 1247 | rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL); |
| 1248 | if (!rtd->dev) |
| 1249 | return -ENOMEM; |
| 1250 | device_initialize(rtd->dev); |
| 1251 | rtd->dev->parent = card->dev; |
| 1252 | rtd->dev->release = rtd_release; |
| 1253 | rtd->dev->init_name = name; |
| 1254 | dev_set_drvdata(rtd->dev, rtd); |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 1255 | mutex_init(&rtd->pcm_mutex); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1256 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients); |
| 1257 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients); |
| 1258 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients); |
| 1259 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients); |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1260 | ret = device_add(rtd->dev); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1261 | if (ret < 0) { |
Chuansheng Liu | 865df9c | 2012-12-26 00:56:05 +0800 | [diff] [blame] | 1262 | /* calling put_device() here to free the rtd->dev */ |
| 1263 | put_device(rtd->dev); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1264 | dev_err(card->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1265 | "ASoC: failed to register runtime device: %d\n", ret); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1266 | return ret; |
| 1267 | } |
| 1268 | rtd->dev_registered = 1; |
| 1269 | |
| 1270 | /* add DAPM sysfs entries for this codec */ |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1271 | ret = snd_soc_dapm_sys_add(rtd->dev); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1272 | if (ret < 0) |
| 1273 | dev_err(codec->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1274 | "ASoC: failed to add codec dapm sysfs entries: %d\n", ret); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1275 | |
| 1276 | /* add codec sysfs entries */ |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1277 | ret = device_create_file(rtd->dev, &dev_attr_codec_reg); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1278 | if (ret < 0) |
| 1279 | dev_err(codec->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1280 | "ASoC: failed to add codec sysfs files: %d\n", ret); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1281 | |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 1282 | #ifdef CONFIG_DEBUG_FS |
| 1283 | /* add DPCM sysfs entries */ |
Liam Girdwood | cd0f891 | 2012-04-30 11:05:30 +0100 | [diff] [blame] | 1284 | if (!dailess && !dai_link->dynamic) |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 1285 | goto out; |
| 1286 | |
| 1287 | ret = soc_dpcm_debugfs_add(rtd); |
| 1288 | if (ret < 0) |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1289 | dev_err(rtd->dev, "ASoC: failed to add dpcm sysfs entries: %d\n", ret); |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 1290 | |
| 1291 | out: |
| 1292 | #endif |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1293 | return 0; |
| 1294 | } |
| 1295 | |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1296 | static int soc_probe_link_components(struct snd_soc_card *card, int num, |
| 1297 | int order) |
| 1298 | { |
| 1299 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
| 1300 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1301 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 1302 | struct snd_soc_platform *platform = rtd->platform; |
| 1303 | int ret; |
| 1304 | |
| 1305 | /* probe the CPU-side component, if it is a CODEC */ |
| 1306 | if (cpu_dai->codec && |
| 1307 | !cpu_dai->codec->probed && |
| 1308 | cpu_dai->codec->driver->probe_order == order) { |
| 1309 | ret = soc_probe_codec(card, cpu_dai->codec); |
| 1310 | if (ret < 0) |
| 1311 | return ret; |
| 1312 | } |
| 1313 | |
| 1314 | /* probe the CODEC-side component */ |
| 1315 | if (!codec_dai->codec->probed && |
| 1316 | codec_dai->codec->driver->probe_order == order) { |
| 1317 | ret = soc_probe_codec(card, codec_dai->codec); |
| 1318 | if (ret < 0) |
| 1319 | return ret; |
| 1320 | } |
| 1321 | |
| 1322 | /* probe the platform */ |
| 1323 | if (!platform->probed && |
| 1324 | platform->driver->probe_order == order) { |
| 1325 | ret = soc_probe_platform(card, platform); |
| 1326 | if (ret < 0) |
| 1327 | return ret; |
| 1328 | } |
| 1329 | |
| 1330 | return 0; |
| 1331 | } |
| 1332 | |
| 1333 | static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1334 | { |
| 1335 | struct snd_soc_dai_link *dai_link = &card->dai_link[num]; |
| 1336 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
| 1337 | struct snd_soc_codec *codec = rtd->codec; |
| 1338 | struct snd_soc_platform *platform = rtd->platform; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 1339 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 1340 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1341 | struct snd_soc_dapm_widget *play_w, *capture_w; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1342 | int ret; |
| 1343 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1344 | dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n", |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1345 | card->name, num, order); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1346 | |
| 1347 | /* config components */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1348 | cpu_dai->platform = platform; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1349 | codec_dai->card = card; |
| 1350 | cpu_dai->card = card; |
| 1351 | |
| 1352 | /* set default power off timeout */ |
| 1353 | rtd->pmdown_time = pmdown_time; |
| 1354 | |
| 1355 | /* probe the cpu_dai */ |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1356 | if (!cpu_dai->probed && |
| 1357 | cpu_dai->driver->probe_order == order) { |
Stephen Warren | a9db7db | 2012-06-08 12:34:20 -0600 | [diff] [blame] | 1358 | if (!cpu_dai->codec) { |
| 1359 | cpu_dai->dapm.card = card; |
| 1360 | if (!try_module_get(cpu_dai->dev->driver->owner)) |
| 1361 | return -ENODEV; |
Liam Girdwood | 61b61e3 | 2011-05-24 13:57:43 +0100 | [diff] [blame] | 1362 | |
Stephen Warren | 18d7564 | 2012-06-08 12:34:21 -0600 | [diff] [blame] | 1363 | list_add(&cpu_dai->dapm.list, &card->dapm_list); |
Stephen Warren | a9db7db | 2012-06-08 12:34:20 -0600 | [diff] [blame] | 1364 | snd_soc_dapm_new_dai_widgets(&cpu_dai->dapm, cpu_dai); |
| 1365 | } |
Liam Girdwood | be09ad9 | 2012-03-07 11:47:41 +0000 | [diff] [blame] | 1366 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1367 | if (cpu_dai->driver->probe) { |
| 1368 | ret = cpu_dai->driver->probe(cpu_dai); |
| 1369 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1370 | dev_err(cpu_dai->dev, |
| 1371 | "ASoC: failed to probe CPU DAI %s: %d\n", |
| 1372 | cpu_dai->name, ret); |
Liam Girdwood | 61b61e3 | 2011-05-24 13:57:43 +0100 | [diff] [blame] | 1373 | module_put(cpu_dai->dev->driver->owner); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1374 | return ret; |
| 1375 | } |
| 1376 | } |
| 1377 | cpu_dai->probed = 1; |
Wolfram Sang | 1c8371d | 2011-07-17 18:00:26 +0200 | [diff] [blame] | 1378 | /* mark cpu_dai as probed and add to card dai list */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1379 | list_add(&cpu_dai->card_list, &card->dai_dev_list); |
| 1380 | } |
| 1381 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1382 | /* probe the CODEC DAI */ |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1383 | if (!codec_dai->probed && codec_dai->driver->probe_order == order) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1384 | if (codec_dai->driver->probe) { |
| 1385 | ret = codec_dai->driver->probe(codec_dai); |
| 1386 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1387 | dev_err(codec_dai->dev, |
| 1388 | "ASoC: failed to probe CODEC DAI %s: %d\n", |
| 1389 | codec_dai->name, ret); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1390 | return ret; |
Mark Brown | 6b05eda | 2008-12-08 19:26:48 +0000 | [diff] [blame] | 1391 | } |
| 1392 | } |
| 1393 | |
Wolfram Sang | 1c8371d | 2011-07-17 18:00:26 +0200 | [diff] [blame] | 1394 | /* mark codec_dai as probed and add to card dai list */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1395 | codec_dai->probed = 1; |
| 1396 | list_add(&codec_dai->card_list, &card->dai_dev_list); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1397 | } |
| 1398 | |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1399 | /* complete DAI probe during last probe */ |
| 1400 | if (order != SND_SOC_COMP_ORDER_LAST) |
| 1401 | return 0; |
| 1402 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1403 | ret = soc_post_component_init(card, codec, num, 0); |
| 1404 | if (ret) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1405 | return ret; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1406 | |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1407 | ret = device_create_file(rtd->dev, &dev_attr_pmdown_time); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1408 | if (ret < 0) |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1409 | dev_warn(rtd->dev, "ASoC: failed to add pmdown_time sysfs: %d\n", |
| 1410 | ret); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1411 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1412 | if (cpu_dai->driver->compress_dai) { |
| 1413 | /*create compress_device"*/ |
| 1414 | ret = soc_new_compress(rtd, num); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 1415 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1416 | dev_err(card->dev, "ASoC: can't create compress %s\n", |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1417 | dai_link->stream_name); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 1418 | return ret; |
| 1419 | } |
| 1420 | } else { |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1421 | |
| 1422 | if (!dai_link->params) { |
| 1423 | /* create the pcm */ |
| 1424 | ret = soc_new_pcm(rtd, num); |
| 1425 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1426 | dev_err(card->dev, "ASoC: can't create pcm %s :%d\n", |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1427 | dai_link->stream_name, ret); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 1428 | return ret; |
| 1429 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1430 | } else { |
| 1431 | /* link the DAI widgets */ |
| 1432 | play_w = codec_dai->playback_widget; |
| 1433 | capture_w = cpu_dai->capture_widget; |
| 1434 | if (play_w && capture_w) { |
| 1435 | ret = snd_soc_dapm_new_pcm(card, dai_link->params, |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 1436 | capture_w, play_w); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1437 | if (ret != 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1438 | dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n", |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1439 | play_w->name, capture_w->name, ret); |
| 1440 | return ret; |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | play_w = cpu_dai->playback_widget; |
| 1445 | capture_w = codec_dai->capture_widget; |
| 1446 | if (play_w && capture_w) { |
| 1447 | ret = snd_soc_dapm_new_pcm(card, dai_link->params, |
| 1448 | capture_w, play_w); |
| 1449 | if (ret != 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1450 | dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n", |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1451 | play_w->name, capture_w->name, ret); |
| 1452 | return ret; |
| 1453 | } |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 1454 | } |
| 1455 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | /* add platform data for AC97 devices */ |
| 1459 | if (rtd->codec_dai->driver->ac97_control) |
| 1460 | snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata); |
| 1461 | |
| 1462 | return 0; |
| 1463 | } |
| 1464 | |
| 1465 | #ifdef CONFIG_SND_SOC_AC97_BUS |
| 1466 | static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd) |
| 1467 | { |
| 1468 | int ret; |
| 1469 | |
| 1470 | /* Only instantiate AC97 if not already done by the adaptor |
| 1471 | * for the generic AC97 subsystem. |
| 1472 | */ |
| 1473 | if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) { |
Mika Westerberg | 0562f78 | 2010-10-13 11:30:32 +0300 | [diff] [blame] | 1474 | /* |
| 1475 | * It is possible that the AC97 device is already registered to |
| 1476 | * the device subsystem. This happens when the device is created |
| 1477 | * via snd_ac97_mixer(). Currently only SoC codec that does so |
| 1478 | * is the generic AC97 glue but others migh emerge. |
| 1479 | * |
| 1480 | * In those cases we don't try to register the device again. |
| 1481 | */ |
| 1482 | if (!rtd->codec->ac97_created) |
| 1483 | return 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1484 | |
| 1485 | ret = soc_ac97_dev_register(rtd->codec); |
| 1486 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1487 | dev_err(rtd->codec->dev, |
| 1488 | "ASoC: AC97 device register failed: %d\n", ret); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1489 | return ret; |
| 1490 | } |
| 1491 | |
| 1492 | rtd->codec->ac97_registered = 1; |
| 1493 | } |
| 1494 | return 0; |
| 1495 | } |
| 1496 | |
| 1497 | static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec) |
| 1498 | { |
| 1499 | if (codec->ac97_registered) { |
| 1500 | soc_ac97_dev_unregister(codec); |
| 1501 | codec->ac97_registered = 0; |
| 1502 | } |
| 1503 | } |
| 1504 | #endif |
| 1505 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1506 | static int soc_check_aux_dev(struct snd_soc_card *card, int num) |
| 1507 | { |
| 1508 | struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; |
| 1509 | struct snd_soc_codec *codec; |
| 1510 | |
| 1511 | /* find CODEC from registered CODECs*/ |
| 1512 | list_for_each_entry(codec, &codec_list, list) { |
| 1513 | if (!strcmp(codec->name, aux_dev->codec_name)) |
| 1514 | return 0; |
| 1515 | } |
| 1516 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1517 | dev_err(card->dev, "ASoC: %s not registered\n", aux_dev->codec_name); |
Mark Brown | fb099cb | 2012-08-09 18:44:37 +0100 | [diff] [blame] | 1518 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1519 | return -EPROBE_DEFER; |
| 1520 | } |
| 1521 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1522 | static int soc_probe_aux_dev(struct snd_soc_card *card, int num) |
| 1523 | { |
| 1524 | struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1525 | struct snd_soc_codec *codec; |
Jarkko Nikula | 676ad98 | 2010-12-03 09:18:22 +0200 | [diff] [blame] | 1526 | int ret = -ENODEV; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1527 | |
| 1528 | /* find CODEC from registered CODECs*/ |
| 1529 | list_for_each_entry(codec, &codec_list, list) { |
| 1530 | if (!strcmp(codec->name, aux_dev->codec_name)) { |
| 1531 | if (codec->probed) { |
| 1532 | dev_err(codec->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1533 | "ASoC: codec already probed"); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1534 | ret = -EBUSY; |
| 1535 | goto out; |
| 1536 | } |
Jarkko Nikula | 676ad98 | 2010-12-03 09:18:22 +0200 | [diff] [blame] | 1537 | goto found; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1538 | } |
| 1539 | } |
Jarkko Nikula | 676ad98 | 2010-12-03 09:18:22 +0200 | [diff] [blame] | 1540 | /* codec not found */ |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1541 | dev_err(card->dev, "ASoC: codec %s not found", aux_dev->codec_name); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1542 | return -EPROBE_DEFER; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1543 | |
Jarkko Nikula | 676ad98 | 2010-12-03 09:18:22 +0200 | [diff] [blame] | 1544 | found: |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1545 | ret = soc_probe_codec(card, codec); |
| 1546 | if (ret < 0) |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1547 | return ret; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1548 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1549 | ret = soc_post_component_init(card, codec, num, 1); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1550 | |
| 1551 | out: |
| 1552 | return ret; |
| 1553 | } |
| 1554 | |
| 1555 | static void soc_remove_aux_dev(struct snd_soc_card *card, int num) |
| 1556 | { |
| 1557 | struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; |
| 1558 | struct snd_soc_codec *codec = rtd->codec; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1559 | |
| 1560 | /* unregister the rtd device */ |
| 1561 | if (rtd->dev_registered) { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1562 | device_remove_file(rtd->dev, &dev_attr_codec_reg); |
Chuansheng Liu | d3bf156 | 2012-12-26 00:57:32 +0800 | [diff] [blame] | 1563 | device_unregister(rtd->dev); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1564 | rtd->dev_registered = 0; |
| 1565 | } |
| 1566 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1567 | if (codec && codec->probed) |
| 1568 | soc_remove_codec(codec); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1569 | } |
| 1570 | |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1571 | static int snd_soc_init_codec_cache(struct snd_soc_codec *codec, |
| 1572 | enum snd_soc_compress_type compress_type) |
| 1573 | { |
| 1574 | int ret; |
| 1575 | |
| 1576 | if (codec->cache_init) |
| 1577 | return 0; |
| 1578 | |
| 1579 | /* override the compress_type if necessary */ |
| 1580 | if (compress_type && codec->compress_type != compress_type) |
| 1581 | codec->compress_type = compress_type; |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1582 | ret = snd_soc_cache_init(codec); |
| 1583 | if (ret < 0) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 1584 | dev_err(codec->dev, |
| 1585 | "ASoC: Failed to set cache compression type: %d\n", |
| 1586 | ret); |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1587 | return ret; |
| 1588 | } |
| 1589 | codec->cache_init = 1; |
| 1590 | return 0; |
| 1591 | } |
| 1592 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1593 | static int snd_soc_instantiate_card(struct snd_soc_card *card) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1594 | { |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1595 | struct snd_soc_codec *codec; |
| 1596 | struct snd_soc_codec_conf *codec_conf; |
| 1597 | enum snd_soc_compress_type compress_type; |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1598 | struct snd_soc_dai_link *dai_link; |
Mark Brown | f04209a | 2012-04-09 16:29:21 +0100 | [diff] [blame] | 1599 | int ret, i, order, dai_fmt; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1600 | |
Liam Girdwood | 01b9d99 | 2012-03-07 10:38:25 +0000 | [diff] [blame] | 1601 | mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1602 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1603 | /* bind DAIs */ |
| 1604 | for (i = 0; i < card->num_links; i++) { |
| 1605 | ret = soc_bind_dai_link(card, i); |
| 1606 | if (ret != 0) |
| 1607 | goto base_error; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1608 | } |
| 1609 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1610 | /* check aux_devs too */ |
| 1611 | for (i = 0; i < card->num_aux_devs; i++) { |
| 1612 | ret = soc_check_aux_dev(card, i); |
| 1613 | if (ret != 0) |
| 1614 | goto base_error; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1615 | } |
| 1616 | |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1617 | /* initialize the register cache for each available codec */ |
| 1618 | list_for_each_entry(codec, &codec_list, list) { |
| 1619 | if (codec->cache_init) |
| 1620 | continue; |
Dimitris Papastamos | 861f2fa | 2011-01-11 11:43:51 +0000 | [diff] [blame] | 1621 | /* by default we don't override the compress_type */ |
| 1622 | compress_type = 0; |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1623 | /* check to see if we need to override the compress_type */ |
| 1624 | for (i = 0; i < card->num_configs; ++i) { |
| 1625 | codec_conf = &card->codec_conf[i]; |
| 1626 | if (!strcmp(codec->name, codec_conf->dev_name)) { |
| 1627 | compress_type = codec_conf->compress_type; |
| 1628 | if (compress_type && compress_type |
| 1629 | != codec->compress_type) |
| 1630 | break; |
| 1631 | } |
| 1632 | } |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1633 | ret = snd_soc_init_codec_cache(codec, compress_type); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1634 | if (ret < 0) |
| 1635 | goto base_error; |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1638 | /* card bind complete so register a sound card */ |
| 1639 | ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, |
| 1640 | card->owner, 0, &card->snd_card); |
| 1641 | if (ret < 0) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 1642 | dev_err(card->dev, |
| 1643 | "ASoC: can't create sound card for card %s: %d\n", |
| 1644 | card->name, ret); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1645 | goto base_error; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1646 | } |
| 1647 | card->snd_card->dev = card->dev; |
| 1648 | |
Mark Brown | e37a497 | 2011-03-02 18:21:57 +0000 | [diff] [blame] | 1649 | card->dapm.bias_level = SND_SOC_BIAS_OFF; |
| 1650 | card->dapm.dev = card->dev; |
| 1651 | card->dapm.card = card; |
| 1652 | list_add(&card->dapm.list, &card->dapm_list); |
| 1653 | |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1654 | #ifdef CONFIG_DEBUG_FS |
| 1655 | snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root); |
| 1656 | #endif |
| 1657 | |
Mark Brown | 88ee1c6 | 2011-02-02 10:43:26 +0000 | [diff] [blame] | 1658 | #ifdef CONFIG_PM_SLEEP |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1659 | /* deferred resume work */ |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 1660 | INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); |
Randy Dunlap | 1301a96 | 2008-06-17 19:19:34 +0100 | [diff] [blame] | 1661 | #endif |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1662 | |
Mark Brown | 9a841eb | 2011-04-12 17:51:37 -0700 | [diff] [blame] | 1663 | if (card->dapm_widgets) |
| 1664 | snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, |
| 1665 | card->num_dapm_widgets); |
| 1666 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1667 | /* initialise the sound card only once */ |
| 1668 | if (card->probe) { |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 1669 | ret = card->probe(card); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1670 | if (ret < 0) |
| 1671 | goto card_probe_error; |
| 1672 | } |
| 1673 | |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1674 | /* probe all components used by DAI links on this card */ |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1675 | for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; |
| 1676 | order++) { |
| 1677 | for (i = 0; i < card->num_links; i++) { |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1678 | ret = soc_probe_link_components(card, i, order); |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1679 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1680 | dev_err(card->dev, |
| 1681 | "ASoC: failed to instantiate card %d\n", |
| 1682 | ret); |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1683 | goto probe_dai_err; |
| 1684 | } |
| 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | /* probe all DAI links on this card */ |
| 1689 | for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; |
| 1690 | order++) { |
| 1691 | for (i = 0; i < card->num_links; i++) { |
| 1692 | ret = soc_probe_link_dais(card, i, order); |
| 1693 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1694 | dev_err(card->dev, |
| 1695 | "ASoC: failed to instantiate card %d\n", |
| 1696 | ret); |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1697 | goto probe_dai_err; |
| 1698 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1699 | } |
| 1700 | } |
| 1701 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1702 | for (i = 0; i < card->num_aux_devs; i++) { |
| 1703 | ret = soc_probe_aux_dev(card, i); |
| 1704 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1705 | dev_err(card->dev, |
| 1706 | "ASoC: failed to add auxiliary devices %d\n", |
| 1707 | ret); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1708 | goto probe_aux_dev_err; |
| 1709 | } |
| 1710 | } |
| 1711 | |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 1712 | snd_soc_dapm_link_dai_widgets(card); |
| 1713 | |
Mark Brown | b7af1da | 2011-04-07 19:18:44 +0900 | [diff] [blame] | 1714 | if (card->controls) |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1715 | snd_soc_add_card_controls(card, card->controls, card->num_controls); |
Mark Brown | b7af1da | 2011-04-07 19:18:44 +0900 | [diff] [blame] | 1716 | |
Mark Brown | b8ad29d | 2011-03-02 18:35:51 +0000 | [diff] [blame] | 1717 | if (card->dapm_routes) |
| 1718 | snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, |
| 1719 | card->num_dapm_routes); |
| 1720 | |
Mark Brown | b90d2f9 | 2011-10-10 13:38:06 +0100 | [diff] [blame] | 1721 | snd_soc_dapm_new_widgets(&card->dapm); |
| 1722 | |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1723 | for (i = 0; i < card->num_links; i++) { |
| 1724 | dai_link = &card->dai_link[i]; |
Mark Brown | f04209a | 2012-04-09 16:29:21 +0100 | [diff] [blame] | 1725 | dai_fmt = dai_link->dai_fmt; |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1726 | |
Mark Brown | f04209a | 2012-04-09 16:29:21 +0100 | [diff] [blame] | 1727 | if (dai_fmt) { |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1728 | ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai, |
Mark Brown | f04209a | 2012-04-09 16:29:21 +0100 | [diff] [blame] | 1729 | dai_fmt); |
Shawn Guo | 5e4ba56 | 2012-03-09 00:59:40 +0800 | [diff] [blame] | 1730 | if (ret != 0 && ret != -ENOTSUPP) |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1731 | dev_warn(card->rtd[i].codec_dai->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1732 | "ASoC: Failed to set DAI format: %d\n", |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1733 | ret); |
Mark Brown | f04209a | 2012-04-09 16:29:21 +0100 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | /* If this is a regular CPU link there will be a platform */ |
Stephen Warren | fe33d4c | 2012-05-14 14:47:22 -0600 | [diff] [blame] | 1737 | if (dai_fmt && |
| 1738 | (dai_link->platform_name || dai_link->platform_of_node)) { |
Mark Brown | f04209a | 2012-04-09 16:29:21 +0100 | [diff] [blame] | 1739 | ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai, |
| 1740 | dai_fmt); |
| 1741 | if (ret != 0 && ret != -ENOTSUPP) |
| 1742 | dev_warn(card->rtd[i].cpu_dai->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1743 | "ASoC: Failed to set DAI format: %d\n", |
Mark Brown | f04209a | 2012-04-09 16:29:21 +0100 | [diff] [blame] | 1744 | ret); |
| 1745 | } else if (dai_fmt) { |
| 1746 | /* Flip the polarity for the "CPU" end */ |
| 1747 | dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK; |
| 1748 | switch (dai_link->dai_fmt & |
| 1749 | SND_SOC_DAIFMT_MASTER_MASK) { |
| 1750 | case SND_SOC_DAIFMT_CBM_CFM: |
| 1751 | dai_fmt |= SND_SOC_DAIFMT_CBS_CFS; |
| 1752 | break; |
| 1753 | case SND_SOC_DAIFMT_CBM_CFS: |
| 1754 | dai_fmt |= SND_SOC_DAIFMT_CBS_CFM; |
| 1755 | break; |
| 1756 | case SND_SOC_DAIFMT_CBS_CFM: |
| 1757 | dai_fmt |= SND_SOC_DAIFMT_CBM_CFS; |
| 1758 | break; |
| 1759 | case SND_SOC_DAIFMT_CBS_CFS: |
| 1760 | dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; |
| 1761 | break; |
| 1762 | } |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1763 | |
| 1764 | ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai, |
Mark Brown | f04209a | 2012-04-09 16:29:21 +0100 | [diff] [blame] | 1765 | dai_fmt); |
Shawn Guo | 5e4ba56 | 2012-03-09 00:59:40 +0800 | [diff] [blame] | 1766 | if (ret != 0 && ret != -ENOTSUPP) |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1767 | dev_warn(card->rtd[i].cpu_dai->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1768 | "ASoC: Failed to set DAI format: %d\n", |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1769 | ret); |
| 1770 | } |
| 1771 | } |
| 1772 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1773 | snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1774 | "%s", card->name); |
Liam Girdwood | 22de71b | 2011-05-12 16:14:04 +0100 | [diff] [blame] | 1775 | snprintf(card->snd_card->longname, sizeof(card->snd_card->longname), |
| 1776 | "%s", card->long_name ? card->long_name : card->name); |
Mark Brown | f0e8ed8 | 2011-09-20 11:41:54 +0100 | [diff] [blame] | 1777 | snprintf(card->snd_card->driver, sizeof(card->snd_card->driver), |
| 1778 | "%s", card->driver_name ? card->driver_name : card->name); |
| 1779 | for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) { |
| 1780 | switch (card->snd_card->driver[i]) { |
| 1781 | case '_': |
| 1782 | case '-': |
| 1783 | case '\0': |
| 1784 | break; |
| 1785 | default: |
| 1786 | if (!isalnum(card->snd_card->driver[i])) |
| 1787 | card->snd_card->driver[i] = '_'; |
| 1788 | break; |
| 1789 | } |
| 1790 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1791 | |
Mark Brown | 28e9ad9 | 2011-03-02 18:36:34 +0000 | [diff] [blame] | 1792 | if (card->late_probe) { |
| 1793 | ret = card->late_probe(card); |
| 1794 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1795 | dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n", |
Mark Brown | 28e9ad9 | 2011-03-02 18:36:34 +0000 | [diff] [blame] | 1796 | card->name, ret); |
| 1797 | goto probe_aux_dev_err; |
| 1798 | } |
| 1799 | } |
| 1800 | |
Mark Brown | 2dc0021 | 2011-10-08 13:59:44 +0100 | [diff] [blame] | 1801 | snd_soc_dapm_new_widgets(&card->dapm); |
| 1802 | |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 1803 | if (card->fully_routed) |
Mark Brown | b05d8dc | 2011-11-27 19:38:34 +0000 | [diff] [blame] | 1804 | list_for_each_entry(codec, &card->codec_dev_list, card_list) |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 1805 | snd_soc_dapm_auto_nc_codec_pins(codec); |
| 1806 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1807 | ret = snd_card_register(card->snd_card); |
| 1808 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1809 | dev_err(card->dev, "ASoC: failed to register soundcard %d\n", |
| 1810 | ret); |
Axel Lin | 6b3ed78 | 2010-12-07 16:12:29 +0800 | [diff] [blame] | 1811 | goto probe_aux_dev_err; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | #ifdef CONFIG_SND_SOC_AC97_BUS |
| 1815 | /* register any AC97 codecs */ |
| 1816 | for (i = 0; i < card->num_rtd; i++) { |
Axel Lin | 6b3ed78 | 2010-12-07 16:12:29 +0800 | [diff] [blame] | 1817 | ret = soc_register_ac97_dai_link(&card->rtd[i]); |
| 1818 | if (ret < 0) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 1819 | dev_err(card->dev, |
| 1820 | "ASoC: failed to register AC97: %d\n", ret); |
Axel Lin | 6b3ed78 | 2010-12-07 16:12:29 +0800 | [diff] [blame] | 1821 | while (--i >= 0) |
Mark Brown | 7d8316d | 2010-12-13 17:03:27 +0000 | [diff] [blame] | 1822 | soc_unregister_ac97_dai_link(card->rtd[i].codec); |
Axel Lin | 6b3ed78 | 2010-12-07 16:12:29 +0800 | [diff] [blame] | 1823 | goto probe_aux_dev_err; |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 1824 | } |
Axel Lin | 6b3ed78 | 2010-12-07 16:12:29 +0800 | [diff] [blame] | 1825 | } |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 1826 | #endif |
| 1827 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1828 | card->instantiated = 1; |
Mark Brown | 4f4c007 | 2011-10-07 14:29:19 +0100 | [diff] [blame] | 1829 | snd_soc_dapm_sync(&card->dapm); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1830 | mutex_unlock(&card->mutex); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1831 | |
| 1832 | return 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1833 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1834 | probe_aux_dev_err: |
| 1835 | for (i = 0; i < card->num_aux_devs; i++) |
| 1836 | soc_remove_aux_dev(card, i); |
| 1837 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1838 | probe_dai_err: |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1839 | soc_remove_dai_links(card); |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 1840 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1841 | card_probe_error: |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1842 | if (card->remove) |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 1843 | card->remove(card); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1844 | |
| 1845 | snd_card_free(card->snd_card); |
| 1846 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1847 | base_error: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1848 | mutex_unlock(&card->mutex); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1849 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1850 | return ret; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | /* probes a new socdev */ |
| 1854 | static int soc_probe(struct platform_device *pdev) |
| 1855 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1856 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1857 | |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 1858 | /* |
| 1859 | * no card, so machine driver should be registering card |
| 1860 | * we should not be here in that case so ret error |
| 1861 | */ |
| 1862 | if (!card) |
| 1863 | return -EINVAL; |
| 1864 | |
Mark Brown | fe4085e | 2012-03-02 13:07:41 +0000 | [diff] [blame] | 1865 | dev_warn(&pdev->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1866 | "ASoC: machine %s should use snd_soc_register_card()\n", |
Mark Brown | fe4085e | 2012-03-02 13:07:41 +0000 | [diff] [blame] | 1867 | card->name); |
| 1868 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1869 | /* Bodge while we unpick instantiation */ |
| 1870 | card->dev = &pdev->dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1871 | |
Mark Brown | 28d528c | 2012-08-09 18:45:23 +0100 | [diff] [blame] | 1872 | return snd_soc_register_card(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1873 | } |
| 1874 | |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1875 | static int soc_cleanup_card_resources(struct snd_soc_card *card) |
| 1876 | { |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1877 | int i; |
| 1878 | |
| 1879 | /* make sure any delayed work runs */ |
| 1880 | for (i = 0; i < card->num_rtd; i++) { |
| 1881 | struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 1882 | flush_delayed_work(&rtd->delayed_work); |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | /* remove auxiliary devices */ |
| 1886 | for (i = 0; i < card->num_aux_devs; i++) |
| 1887 | soc_remove_aux_dev(card, i); |
| 1888 | |
| 1889 | /* remove and free each DAI */ |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1890 | soc_remove_dai_links(card); |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1891 | |
| 1892 | soc_cleanup_card_debugfs(card); |
| 1893 | |
| 1894 | /* remove the card */ |
| 1895 | if (card->remove) |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 1896 | card->remove(card); |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1897 | |
Lars-Peter Clausen | 0aaae52 | 2011-04-30 19:45:47 +0200 | [diff] [blame] | 1898 | snd_soc_dapm_free(&card->dapm); |
| 1899 | |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1900 | snd_card_free(card->snd_card); |
| 1901 | return 0; |
| 1902 | |
| 1903 | } |
| 1904 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1905 | /* removes a socdev */ |
| 1906 | static int soc_remove(struct platform_device *pdev) |
| 1907 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1908 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1909 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 1910 | snd_soc_unregister_card(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1911 | return 0; |
| 1912 | } |
| 1913 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1914 | int snd_soc_poweroff(struct device *dev) |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1915 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1916 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1917 | int i; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1918 | |
| 1919 | if (!card->instantiated) |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1920 | return 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1921 | |
| 1922 | /* Flush out pmdown_time work - we actually do want to run it |
| 1923 | * now, we're shutting down so no imminent restart. */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1924 | for (i = 0; i < card->num_rtd; i++) { |
| 1925 | struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 1926 | flush_delayed_work(&rtd->delayed_work); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1927 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1928 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1929 | snd_soc_dapm_shutdown(card); |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1930 | |
| 1931 | return 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1932 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1933 | EXPORT_SYMBOL_GPL(snd_soc_poweroff); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1934 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1935 | const struct dev_pm_ops snd_soc_pm_ops = { |
Viresh Kumar | b1dd589 | 2012-02-24 16:25:49 +0530 | [diff] [blame] | 1936 | .suspend = snd_soc_suspend, |
| 1937 | .resume = snd_soc_resume, |
| 1938 | .freeze = snd_soc_suspend, |
| 1939 | .thaw = snd_soc_resume, |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1940 | .poweroff = snd_soc_poweroff, |
Viresh Kumar | b1dd589 | 2012-02-24 16:25:49 +0530 | [diff] [blame] | 1941 | .restore = snd_soc_resume, |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1942 | }; |
Stephen Warren | deb2607 | 2011-04-05 19:35:30 -0600 | [diff] [blame] | 1943 | EXPORT_SYMBOL_GPL(snd_soc_pm_ops); |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1944 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1945 | /* ASoC platform driver */ |
| 1946 | static struct platform_driver soc_driver = { |
| 1947 | .driver = { |
| 1948 | .name = "soc-audio", |
Kay Sievers | 8b45a20 | 2008-04-14 13:33:36 +0200 | [diff] [blame] | 1949 | .owner = THIS_MODULE, |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1950 | .pm = &snd_soc_pm_ops, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1951 | }, |
| 1952 | .probe = soc_probe, |
| 1953 | .remove = soc_remove, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1954 | }; |
| 1955 | |
Mark Brown | 096e49d | 2009-07-05 15:12:22 +0100 | [diff] [blame] | 1956 | /** |
| 1957 | * snd_soc_codec_volatile_register: Report if a register is volatile. |
| 1958 | * |
| 1959 | * @codec: CODEC to query. |
| 1960 | * @reg: Register to query. |
| 1961 | * |
| 1962 | * Boolean function indiciating if a CODEC register is volatile. |
| 1963 | */ |
Mark Brown | 181e055 | 2011-01-24 14:05:25 +0000 | [diff] [blame] | 1964 | int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, |
| 1965 | unsigned int reg) |
Mark Brown | 096e49d | 2009-07-05 15:12:22 +0100 | [diff] [blame] | 1966 | { |
Dimitris Papastamos | 1500b7b | 2011-01-13 12:20:38 +0000 | [diff] [blame] | 1967 | if (codec->volatile_register) |
| 1968 | return codec->volatile_register(codec, reg); |
Mark Brown | 096e49d | 2009-07-05 15:12:22 +0100 | [diff] [blame] | 1969 | else |
| 1970 | return 0; |
| 1971 | } |
| 1972 | EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register); |
| 1973 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1974 | /** |
Dimitris Papastamos | 239c970 | 2011-03-24 13:45:18 +0000 | [diff] [blame] | 1975 | * snd_soc_codec_readable_register: Report if a register is readable. |
| 1976 | * |
| 1977 | * @codec: CODEC to query. |
| 1978 | * @reg: Register to query. |
| 1979 | * |
| 1980 | * Boolean function indicating if a CODEC register is readable. |
| 1981 | */ |
| 1982 | int snd_soc_codec_readable_register(struct snd_soc_codec *codec, |
| 1983 | unsigned int reg) |
| 1984 | { |
| 1985 | if (codec->readable_register) |
| 1986 | return codec->readable_register(codec, reg); |
| 1987 | else |
Lars-Peter Clausen | 63fa0a2 | 2011-08-27 18:24:12 +0200 | [diff] [blame] | 1988 | return 1; |
Dimitris Papastamos | 239c970 | 2011-03-24 13:45:18 +0000 | [diff] [blame] | 1989 | } |
| 1990 | EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register); |
| 1991 | |
| 1992 | /** |
| 1993 | * snd_soc_codec_writable_register: Report if a register is writable. |
| 1994 | * |
| 1995 | * @codec: CODEC to query. |
| 1996 | * @reg: Register to query. |
| 1997 | * |
| 1998 | * Boolean function indicating if a CODEC register is writable. |
| 1999 | */ |
| 2000 | int snd_soc_codec_writable_register(struct snd_soc_codec *codec, |
| 2001 | unsigned int reg) |
| 2002 | { |
| 2003 | if (codec->writable_register) |
| 2004 | return codec->writable_register(codec, reg); |
| 2005 | else |
Lars-Peter Clausen | 63fa0a2 | 2011-08-27 18:24:12 +0200 | [diff] [blame] | 2006 | return 1; |
Dimitris Papastamos | 239c970 | 2011-03-24 13:45:18 +0000 | [diff] [blame] | 2007 | } |
| 2008 | EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register); |
| 2009 | |
Liam Girdwood | f1442bc | 2011-07-04 11:10:15 +0100 | [diff] [blame] | 2010 | int snd_soc_platform_read(struct snd_soc_platform *platform, |
| 2011 | unsigned int reg) |
| 2012 | { |
| 2013 | unsigned int ret; |
| 2014 | |
| 2015 | if (!platform->driver->read) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 2016 | dev_err(platform->dev, "ASoC: platform has no read back\n"); |
Liam Girdwood | f1442bc | 2011-07-04 11:10:15 +0100 | [diff] [blame] | 2017 | return -1; |
| 2018 | } |
| 2019 | |
| 2020 | ret = platform->driver->read(platform, reg); |
| 2021 | dev_dbg(platform->dev, "read %x => %x\n", reg, ret); |
Liam Girdwood | a82ce2a | 2011-07-04 22:10:50 +0100 | [diff] [blame] | 2022 | trace_snd_soc_preg_read(platform, reg, ret); |
Liam Girdwood | f1442bc | 2011-07-04 11:10:15 +0100 | [diff] [blame] | 2023 | |
| 2024 | return ret; |
| 2025 | } |
| 2026 | EXPORT_SYMBOL_GPL(snd_soc_platform_read); |
| 2027 | |
| 2028 | int snd_soc_platform_write(struct snd_soc_platform *platform, |
| 2029 | unsigned int reg, unsigned int val) |
| 2030 | { |
| 2031 | if (!platform->driver->write) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 2032 | dev_err(platform->dev, "ASoC: platform has no write back\n"); |
Liam Girdwood | f1442bc | 2011-07-04 11:10:15 +0100 | [diff] [blame] | 2033 | return -1; |
| 2034 | } |
| 2035 | |
| 2036 | dev_dbg(platform->dev, "write %x = %x\n", reg, val); |
Liam Girdwood | a82ce2a | 2011-07-04 22:10:50 +0100 | [diff] [blame] | 2037 | trace_snd_soc_preg_write(platform, reg, val); |
Liam Girdwood | f1442bc | 2011-07-04 11:10:15 +0100 | [diff] [blame] | 2038 | return platform->driver->write(platform, reg, val); |
| 2039 | } |
| 2040 | EXPORT_SYMBOL_GPL(snd_soc_platform_write); |
| 2041 | |
Dimitris Papastamos | 239c970 | 2011-03-24 13:45:18 +0000 | [diff] [blame] | 2042 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2043 | * snd_soc_new_ac97_codec - initailise AC97 device |
| 2044 | * @codec: audio codec |
| 2045 | * @ops: AC97 bus operations |
| 2046 | * @num: AC97 codec number |
| 2047 | * |
| 2048 | * Initialises AC97 codec resources for use by ad-hoc devices only. |
| 2049 | */ |
| 2050 | int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, |
| 2051 | struct snd_ac97_bus_ops *ops, int num) |
| 2052 | { |
| 2053 | mutex_lock(&codec->mutex); |
| 2054 | |
| 2055 | codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL); |
| 2056 | if (codec->ac97 == NULL) { |
| 2057 | mutex_unlock(&codec->mutex); |
| 2058 | return -ENOMEM; |
| 2059 | } |
| 2060 | |
| 2061 | codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL); |
| 2062 | if (codec->ac97->bus == NULL) { |
| 2063 | kfree(codec->ac97); |
| 2064 | codec->ac97 = NULL; |
| 2065 | mutex_unlock(&codec->mutex); |
| 2066 | return -ENOMEM; |
| 2067 | } |
| 2068 | |
| 2069 | codec->ac97->bus->ops = ops; |
| 2070 | codec->ac97->num = num; |
Mika Westerberg | 0562f78 | 2010-10-13 11:30:32 +0300 | [diff] [blame] | 2071 | |
| 2072 | /* |
| 2073 | * Mark the AC97 device to be created by us. This way we ensure that the |
| 2074 | * device will be registered with the device subsystem later on. |
| 2075 | */ |
| 2076 | codec->ac97_created = 1; |
| 2077 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2078 | mutex_unlock(&codec->mutex); |
| 2079 | return 0; |
| 2080 | } |
| 2081 | EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec); |
| 2082 | |
Mark Brown | b047e1c | 2013-06-26 12:45:59 +0100 | [diff] [blame] | 2083 | struct snd_ac97_bus_ops *soc_ac97_ops; |
Kevin Hilman | f74b5e2 | 2013-06-28 11:17:49 -0700 | [diff] [blame] | 2084 | EXPORT_SYMBOL_GPL(soc_ac97_ops); |
Mark Brown | b047e1c | 2013-06-26 12:45:59 +0100 | [diff] [blame] | 2085 | |
| 2086 | int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops) |
| 2087 | { |
| 2088 | if (ops == soc_ac97_ops) |
| 2089 | return 0; |
| 2090 | |
| 2091 | if (soc_ac97_ops && ops) |
| 2092 | return -EBUSY; |
| 2093 | |
| 2094 | soc_ac97_ops = ops; |
| 2095 | |
| 2096 | return 0; |
| 2097 | } |
| 2098 | EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops); |
| 2099 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2100 | /** |
| 2101 | * snd_soc_free_ac97_codec - free AC97 codec device |
| 2102 | * @codec: audio codec |
| 2103 | * |
| 2104 | * Frees AC97 codec device resources. |
| 2105 | */ |
| 2106 | void snd_soc_free_ac97_codec(struct snd_soc_codec *codec) |
| 2107 | { |
| 2108 | mutex_lock(&codec->mutex); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2109 | #ifdef CONFIG_SND_SOC_AC97_BUS |
| 2110 | soc_unregister_ac97_dai_link(codec); |
| 2111 | #endif |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2112 | kfree(codec->ac97->bus); |
| 2113 | kfree(codec->ac97); |
| 2114 | codec->ac97 = NULL; |
Mika Westerberg | 0562f78 | 2010-10-13 11:30:32 +0300 | [diff] [blame] | 2115 | codec->ac97_created = 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2116 | mutex_unlock(&codec->mutex); |
| 2117 | } |
| 2118 | EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec); |
| 2119 | |
Mark Brown | c375370 | 2010-11-01 15:41:57 -0400 | [diff] [blame] | 2120 | unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg) |
| 2121 | { |
| 2122 | unsigned int ret; |
| 2123 | |
Mark Brown | c3acec2 | 2010-12-02 16:15:29 +0000 | [diff] [blame] | 2124 | ret = codec->read(codec, reg); |
Mark Brown | c375370 | 2010-11-01 15:41:57 -0400 | [diff] [blame] | 2125 | dev_dbg(codec->dev, "read %x => %x\n", reg, ret); |
Mark Brown | a8b1d34 | 2010-11-03 18:05:58 -0400 | [diff] [blame] | 2126 | trace_snd_soc_reg_read(codec, reg, ret); |
Mark Brown | c375370 | 2010-11-01 15:41:57 -0400 | [diff] [blame] | 2127 | |
| 2128 | return ret; |
| 2129 | } |
| 2130 | EXPORT_SYMBOL_GPL(snd_soc_read); |
| 2131 | |
| 2132 | unsigned int snd_soc_write(struct snd_soc_codec *codec, |
| 2133 | unsigned int reg, unsigned int val) |
| 2134 | { |
| 2135 | dev_dbg(codec->dev, "write %x = %x\n", reg, val); |
Mark Brown | a8b1d34 | 2010-11-03 18:05:58 -0400 | [diff] [blame] | 2136 | trace_snd_soc_reg_write(codec, reg, val); |
Mark Brown | c3acec2 | 2010-12-02 16:15:29 +0000 | [diff] [blame] | 2137 | return codec->write(codec, reg, val); |
Mark Brown | c375370 | 2010-11-01 15:41:57 -0400 | [diff] [blame] | 2138 | } |
| 2139 | EXPORT_SYMBOL_GPL(snd_soc_write); |
| 2140 | |
Dimitris Papastamos | 5fb609d | 2011-03-22 10:37:03 +0000 | [diff] [blame] | 2141 | unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec, |
| 2142 | unsigned int reg, const void *data, size_t len) |
| 2143 | { |
| 2144 | return codec->bulk_write_raw(codec, reg, data, len); |
| 2145 | } |
| 2146 | EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw); |
| 2147 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2148 | /** |
| 2149 | * snd_soc_update_bits - update codec register bits |
| 2150 | * @codec: audio codec |
| 2151 | * @reg: codec register |
| 2152 | * @mask: register mask |
| 2153 | * @value: new value |
| 2154 | * |
| 2155 | * Writes new register value. |
| 2156 | * |
Timur Tabi | 180c329 | 2011-01-10 15:58:13 -0600 | [diff] [blame] | 2157 | * Returns 1 for change, 0 for no change, or negative error code. |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2158 | */ |
| 2159 | int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg, |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2160 | unsigned int mask, unsigned int value) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2161 | { |
Mark Brown | 8a713da | 2011-12-03 12:33:55 +0000 | [diff] [blame] | 2162 | bool change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2163 | unsigned int old, new; |
Timur Tabi | 180c329 | 2011-01-10 15:58:13 -0600 | [diff] [blame] | 2164 | int ret; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2165 | |
Mark Brown | 8a713da | 2011-12-03 12:33:55 +0000 | [diff] [blame] | 2166 | if (codec->using_regmap) { |
| 2167 | ret = regmap_update_bits_check(codec->control_data, reg, |
| 2168 | mask, value, &change); |
| 2169 | } else { |
| 2170 | ret = snd_soc_read(codec, reg); |
Timur Tabi | 180c329 | 2011-01-10 15:58:13 -0600 | [diff] [blame] | 2171 | if (ret < 0) |
| 2172 | return ret; |
Mark Brown | 8a713da | 2011-12-03 12:33:55 +0000 | [diff] [blame] | 2173 | |
| 2174 | old = ret; |
| 2175 | new = (old & ~mask) | (value & mask); |
| 2176 | change = old != new; |
| 2177 | if (change) |
| 2178 | ret = snd_soc_write(codec, reg, new); |
Timur Tabi | 180c329 | 2011-01-10 15:58:13 -0600 | [diff] [blame] | 2179 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2180 | |
Mark Brown | 8a713da | 2011-12-03 12:33:55 +0000 | [diff] [blame] | 2181 | if (ret < 0) |
| 2182 | return ret; |
| 2183 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2184 | return change; |
| 2185 | } |
| 2186 | EXPORT_SYMBOL_GPL(snd_soc_update_bits); |
| 2187 | |
| 2188 | /** |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2189 | * snd_soc_update_bits_locked - update codec register bits |
| 2190 | * @codec: audio codec |
| 2191 | * @reg: codec register |
| 2192 | * @mask: register mask |
| 2193 | * @value: new value |
| 2194 | * |
| 2195 | * Writes new register value, and takes the codec mutex. |
| 2196 | * |
| 2197 | * Returns 1 for change else 0. |
| 2198 | */ |
Mark Brown | dd1b3d5 | 2009-12-04 14:22:03 +0000 | [diff] [blame] | 2199 | int snd_soc_update_bits_locked(struct snd_soc_codec *codec, |
| 2200 | unsigned short reg, unsigned int mask, |
| 2201 | unsigned int value) |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2202 | { |
| 2203 | int change; |
| 2204 | |
| 2205 | mutex_lock(&codec->mutex); |
| 2206 | change = snd_soc_update_bits(codec, reg, mask, value); |
| 2207 | mutex_unlock(&codec->mutex); |
| 2208 | |
| 2209 | return change; |
| 2210 | } |
Mark Brown | dd1b3d5 | 2009-12-04 14:22:03 +0000 | [diff] [blame] | 2211 | EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked); |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2212 | |
| 2213 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2214 | * snd_soc_test_bits - test register for change |
| 2215 | * @codec: audio codec |
| 2216 | * @reg: codec register |
| 2217 | * @mask: register mask |
| 2218 | * @value: new value |
| 2219 | * |
| 2220 | * Tests a register with a new value and checks if the new value is |
| 2221 | * different from the old value. |
| 2222 | * |
| 2223 | * Returns 1 for change else 0. |
| 2224 | */ |
| 2225 | int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg, |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2226 | unsigned int mask, unsigned int value) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2227 | { |
| 2228 | int change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2229 | unsigned int old, new; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2230 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2231 | old = snd_soc_read(codec, reg); |
| 2232 | new = (old & ~mask) | value; |
| 2233 | change = old != new; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2234 | |
| 2235 | return change; |
| 2236 | } |
| 2237 | EXPORT_SYMBOL_GPL(snd_soc_test_bits); |
| 2238 | |
| 2239 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2240 | * snd_soc_cnew - create new control |
| 2241 | * @_template: control template |
| 2242 | * @data: control private data |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2243 | * @long_name: control long name |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2244 | * @prefix: control name prefix |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2245 | * |
| 2246 | * Create a new mixer control from a template control. |
| 2247 | * |
| 2248 | * Returns 0 for success, else error. |
| 2249 | */ |
| 2250 | struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, |
Mark Brown | 3056557 | 2012-02-16 17:07:42 -0800 | [diff] [blame] | 2251 | void *data, const char *long_name, |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2252 | const char *prefix) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2253 | { |
| 2254 | struct snd_kcontrol_new template; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2255 | struct snd_kcontrol *kcontrol; |
| 2256 | char *name = NULL; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2257 | |
| 2258 | memcpy(&template, _template, sizeof(template)); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2259 | template.index = 0; |
| 2260 | |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2261 | if (!long_name) |
| 2262 | long_name = template.name; |
| 2263 | |
| 2264 | if (prefix) { |
Lars-Peter Clausen | 2b58107 | 2013-05-14 11:05:32 +0200 | [diff] [blame] | 2265 | name = kasprintf(GFP_KERNEL, "%s %s", prefix, long_name); |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2266 | if (!name) |
| 2267 | return NULL; |
| 2268 | |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2269 | template.name = name; |
| 2270 | } else { |
| 2271 | template.name = long_name; |
| 2272 | } |
| 2273 | |
| 2274 | kcontrol = snd_ctl_new1(&template, data); |
| 2275 | |
| 2276 | kfree(name); |
| 2277 | |
| 2278 | return kcontrol; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2279 | } |
| 2280 | EXPORT_SYMBOL_GPL(snd_soc_cnew); |
| 2281 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2282 | static int snd_soc_add_controls(struct snd_card *card, struct device *dev, |
| 2283 | const struct snd_kcontrol_new *controls, int num_controls, |
| 2284 | const char *prefix, void *data) |
| 2285 | { |
| 2286 | int err, i; |
| 2287 | |
| 2288 | for (i = 0; i < num_controls; i++) { |
| 2289 | const struct snd_kcontrol_new *control = &controls[i]; |
| 2290 | err = snd_ctl_add(card, snd_soc_cnew(control, data, |
| 2291 | control->name, prefix)); |
| 2292 | if (err < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 2293 | dev_err(dev, "ASoC: Failed to add %s: %d\n", |
| 2294 | control->name, err); |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2295 | return err; |
| 2296 | } |
| 2297 | } |
| 2298 | |
| 2299 | return 0; |
| 2300 | } |
| 2301 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2302 | /** |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2303 | * snd_soc_add_codec_controls - add an array of controls to a codec. |
| 2304 | * Convenience function to add a list of controls. Many codecs were |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 2305 | * duplicating this code. |
| 2306 | * |
| 2307 | * @codec: codec to add controls to |
| 2308 | * @controls: array of controls to add |
| 2309 | * @num_controls: number of elements in the array |
| 2310 | * |
| 2311 | * Return 0 for success, else error. |
| 2312 | */ |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2313 | int snd_soc_add_codec_controls(struct snd_soc_codec *codec, |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 2314 | const struct snd_kcontrol_new *controls, int num_controls) |
| 2315 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2316 | struct snd_card *card = codec->card->snd_card; |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 2317 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2318 | return snd_soc_add_controls(card, codec->dev, controls, num_controls, |
| 2319 | codec->name_prefix, codec); |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 2320 | } |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2321 | EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls); |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 2322 | |
| 2323 | /** |
Liam Girdwood | a491a5c | 2011-07-04 22:10:51 +0100 | [diff] [blame] | 2324 | * snd_soc_add_platform_controls - add an array of controls to a platform. |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2325 | * Convenience function to add a list of controls. |
Liam Girdwood | a491a5c | 2011-07-04 22:10:51 +0100 | [diff] [blame] | 2326 | * |
| 2327 | * @platform: platform to add controls to |
| 2328 | * @controls: array of controls to add |
| 2329 | * @num_controls: number of elements in the array |
| 2330 | * |
| 2331 | * Return 0 for success, else error. |
| 2332 | */ |
| 2333 | int snd_soc_add_platform_controls(struct snd_soc_platform *platform, |
| 2334 | const struct snd_kcontrol_new *controls, int num_controls) |
| 2335 | { |
| 2336 | struct snd_card *card = platform->card->snd_card; |
Liam Girdwood | a491a5c | 2011-07-04 22:10:51 +0100 | [diff] [blame] | 2337 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2338 | return snd_soc_add_controls(card, platform->dev, controls, num_controls, |
| 2339 | NULL, platform); |
Liam Girdwood | a491a5c | 2011-07-04 22:10:51 +0100 | [diff] [blame] | 2340 | } |
| 2341 | EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls); |
| 2342 | |
| 2343 | /** |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2344 | * snd_soc_add_card_controls - add an array of controls to a SoC card. |
| 2345 | * Convenience function to add a list of controls. |
| 2346 | * |
| 2347 | * @soc_card: SoC card to add controls to |
| 2348 | * @controls: array of controls to add |
| 2349 | * @num_controls: number of elements in the array |
| 2350 | * |
| 2351 | * Return 0 for success, else error. |
| 2352 | */ |
| 2353 | int snd_soc_add_card_controls(struct snd_soc_card *soc_card, |
| 2354 | const struct snd_kcontrol_new *controls, int num_controls) |
| 2355 | { |
| 2356 | struct snd_card *card = soc_card->snd_card; |
| 2357 | |
| 2358 | return snd_soc_add_controls(card, soc_card->dev, controls, num_controls, |
| 2359 | NULL, soc_card); |
| 2360 | } |
| 2361 | EXPORT_SYMBOL_GPL(snd_soc_add_card_controls); |
| 2362 | |
| 2363 | /** |
| 2364 | * snd_soc_add_dai_controls - add an array of controls to a DAI. |
| 2365 | * Convienience function to add a list of controls. |
| 2366 | * |
| 2367 | * @dai: DAI to add controls to |
| 2368 | * @controls: array of controls to add |
| 2369 | * @num_controls: number of elements in the array |
| 2370 | * |
| 2371 | * Return 0 for success, else error. |
| 2372 | */ |
| 2373 | int snd_soc_add_dai_controls(struct snd_soc_dai *dai, |
| 2374 | const struct snd_kcontrol_new *controls, int num_controls) |
| 2375 | { |
| 2376 | struct snd_card *card = dai->card->snd_card; |
| 2377 | |
| 2378 | return snd_soc_add_controls(card, dai->dev, controls, num_controls, |
| 2379 | NULL, dai); |
| 2380 | } |
| 2381 | EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls); |
| 2382 | |
| 2383 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2384 | * snd_soc_info_enum_double - enumerated double mixer info callback |
| 2385 | * @kcontrol: mixer control |
| 2386 | * @uinfo: control element information |
| 2387 | * |
| 2388 | * Callback to provide information about a double enumerated |
| 2389 | * mixer control. |
| 2390 | * |
| 2391 | * Returns 0 for success. |
| 2392 | */ |
| 2393 | int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, |
| 2394 | struct snd_ctl_elem_info *uinfo) |
| 2395 | { |
| 2396 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 2397 | |
| 2398 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2399 | uinfo->count = e->shift_l == e->shift_r ? 1 : 2; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2400 | uinfo->value.enumerated.items = e->max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2401 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2402 | if (uinfo->value.enumerated.item > e->max - 1) |
| 2403 | uinfo->value.enumerated.item = e->max - 1; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2404 | strcpy(uinfo->value.enumerated.name, |
| 2405 | e->texts[uinfo->value.enumerated.item]); |
| 2406 | return 0; |
| 2407 | } |
| 2408 | EXPORT_SYMBOL_GPL(snd_soc_info_enum_double); |
| 2409 | |
| 2410 | /** |
| 2411 | * snd_soc_get_enum_double - enumerated double mixer get callback |
| 2412 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2413 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2414 | * |
| 2415 | * Callback to get the value of a double enumerated mixer. |
| 2416 | * |
| 2417 | * Returns 0 for success. |
| 2418 | */ |
| 2419 | int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol, |
| 2420 | struct snd_ctl_elem_value *ucontrol) |
| 2421 | { |
| 2422 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2423 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 2424 | unsigned int val; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2425 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2426 | val = snd_soc_read(codec, e->reg); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 2427 | ucontrol->value.enumerated.item[0] |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 2428 | = (val >> e->shift_l) & e->mask; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2429 | if (e->shift_l != e->shift_r) |
| 2430 | ucontrol->value.enumerated.item[1] = |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 2431 | (val >> e->shift_r) & e->mask; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2432 | |
| 2433 | return 0; |
| 2434 | } |
| 2435 | EXPORT_SYMBOL_GPL(snd_soc_get_enum_double); |
| 2436 | |
| 2437 | /** |
| 2438 | * snd_soc_put_enum_double - enumerated double mixer put callback |
| 2439 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2440 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2441 | * |
| 2442 | * Callback to set the value of a double enumerated mixer. |
| 2443 | * |
| 2444 | * Returns 0 for success. |
| 2445 | */ |
| 2446 | int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, |
| 2447 | struct snd_ctl_elem_value *ucontrol) |
| 2448 | { |
| 2449 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2450 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2451 | unsigned int val; |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 2452 | unsigned int mask; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2453 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2454 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2455 | return -EINVAL; |
| 2456 | val = ucontrol->value.enumerated.item[0] << e->shift_l; |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 2457 | mask = e->mask << e->shift_l; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2458 | if (e->shift_l != e->shift_r) { |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2459 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2460 | return -EINVAL; |
| 2461 | val |= ucontrol->value.enumerated.item[1] << e->shift_r; |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 2462 | mask |= e->mask << e->shift_r; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2463 | } |
| 2464 | |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2465 | return snd_soc_update_bits_locked(codec, e->reg, mask, val); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2466 | } |
| 2467 | EXPORT_SYMBOL_GPL(snd_soc_put_enum_double); |
| 2468 | |
| 2469 | /** |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2470 | * snd_soc_get_value_enum_double - semi enumerated double mixer get callback |
| 2471 | * @kcontrol: mixer control |
| 2472 | * @ucontrol: control element information |
| 2473 | * |
| 2474 | * Callback to get the value of a double semi enumerated mixer. |
| 2475 | * |
| 2476 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2477 | * used for handling bitfield coded enumeration for example. |
| 2478 | * |
| 2479 | * Returns 0 for success. |
| 2480 | */ |
| 2481 | int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2482 | struct snd_ctl_elem_value *ucontrol) |
| 2483 | { |
| 2484 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2485 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2486 | unsigned int reg_val, val, mux; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2487 | |
| 2488 | reg_val = snd_soc_read(codec, e->reg); |
| 2489 | val = (reg_val >> e->shift_l) & e->mask; |
| 2490 | for (mux = 0; mux < e->max; mux++) { |
| 2491 | if (val == e->values[mux]) |
| 2492 | break; |
| 2493 | } |
| 2494 | ucontrol->value.enumerated.item[0] = mux; |
| 2495 | if (e->shift_l != e->shift_r) { |
| 2496 | val = (reg_val >> e->shift_r) & e->mask; |
| 2497 | for (mux = 0; mux < e->max; mux++) { |
| 2498 | if (val == e->values[mux]) |
| 2499 | break; |
| 2500 | } |
| 2501 | ucontrol->value.enumerated.item[1] = mux; |
| 2502 | } |
| 2503 | |
| 2504 | return 0; |
| 2505 | } |
| 2506 | EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double); |
| 2507 | |
| 2508 | /** |
| 2509 | * snd_soc_put_value_enum_double - semi enumerated double mixer put callback |
| 2510 | * @kcontrol: mixer control |
| 2511 | * @ucontrol: control element information |
| 2512 | * |
| 2513 | * Callback to set the value of a double semi enumerated mixer. |
| 2514 | * |
| 2515 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2516 | * used for handling bitfield coded enumeration for example. |
| 2517 | * |
| 2518 | * Returns 0 for success. |
| 2519 | */ |
| 2520 | int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2521 | struct snd_ctl_elem_value *ucontrol) |
| 2522 | { |
| 2523 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2524 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2525 | unsigned int val; |
| 2526 | unsigned int mask; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2527 | |
| 2528 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 2529 | return -EINVAL; |
| 2530 | val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; |
| 2531 | mask = e->mask << e->shift_l; |
| 2532 | if (e->shift_l != e->shift_r) { |
| 2533 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
| 2534 | return -EINVAL; |
| 2535 | val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; |
| 2536 | mask |= e->mask << e->shift_r; |
| 2537 | } |
| 2538 | |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2539 | return snd_soc_update_bits_locked(codec, e->reg, mask, val); |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2540 | } |
| 2541 | EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double); |
| 2542 | |
| 2543 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2544 | * snd_soc_info_enum_ext - external enumerated single mixer info callback |
| 2545 | * @kcontrol: mixer control |
| 2546 | * @uinfo: control element information |
| 2547 | * |
| 2548 | * Callback to provide information about an external enumerated |
| 2549 | * single mixer. |
| 2550 | * |
| 2551 | * Returns 0 for success. |
| 2552 | */ |
| 2553 | int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol, |
| 2554 | struct snd_ctl_elem_info *uinfo) |
| 2555 | { |
| 2556 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 2557 | |
| 2558 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2559 | uinfo->count = 1; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2560 | uinfo->value.enumerated.items = e->max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2561 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2562 | if (uinfo->value.enumerated.item > e->max - 1) |
| 2563 | uinfo->value.enumerated.item = e->max - 1; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2564 | strcpy(uinfo->value.enumerated.name, |
| 2565 | e->texts[uinfo->value.enumerated.item]); |
| 2566 | return 0; |
| 2567 | } |
| 2568 | EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext); |
| 2569 | |
| 2570 | /** |
| 2571 | * snd_soc_info_volsw_ext - external single mixer info callback |
| 2572 | * @kcontrol: mixer control |
| 2573 | * @uinfo: control element information |
| 2574 | * |
| 2575 | * Callback to provide information about a single external mixer control. |
| 2576 | * |
| 2577 | * Returns 0 for success. |
| 2578 | */ |
| 2579 | int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol, |
| 2580 | struct snd_ctl_elem_info *uinfo) |
| 2581 | { |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2582 | int max = kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2583 | |
Mark Brown | fd5dfad | 2009-04-15 21:37:46 +0100 | [diff] [blame] | 2584 | if (max == 1 && !strstr(kcontrol->id.name, " Volume")) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2585 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 2586 | else |
| 2587 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2588 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2589 | uinfo->count = 1; |
| 2590 | uinfo->value.integer.min = 0; |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2591 | uinfo->value.integer.max = max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2592 | return 0; |
| 2593 | } |
| 2594 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext); |
| 2595 | |
| 2596 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2597 | * snd_soc_info_volsw - single mixer info callback |
| 2598 | * @kcontrol: mixer control |
| 2599 | * @uinfo: control element information |
| 2600 | * |
Peter Ujfalusi | e8f5a10 | 2011-10-05 10:29:23 +0300 | [diff] [blame] | 2601 | * Callback to provide information about a single mixer control, or a double |
| 2602 | * mixer control that spans 2 registers. |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2603 | * |
| 2604 | * Returns 0 for success. |
| 2605 | */ |
| 2606 | int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, |
| 2607 | struct snd_ctl_elem_info *uinfo) |
| 2608 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2609 | struct soc_mixer_control *mc = |
| 2610 | (struct soc_mixer_control *)kcontrol->private_value; |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 2611 | int platform_max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2612 | |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 2613 | if (!mc->platform_max) |
| 2614 | mc->platform_max = mc->max; |
| 2615 | platform_max = mc->platform_max; |
| 2616 | |
| 2617 | if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume")) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2618 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 2619 | else |
| 2620 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2621 | |
Peter Ujfalusi | e8f5a10 | 2011-10-05 10:29:23 +0300 | [diff] [blame] | 2622 | uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2623 | uinfo->value.integer.min = 0; |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 2624 | uinfo->value.integer.max = platform_max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2625 | return 0; |
| 2626 | } |
| 2627 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw); |
| 2628 | |
| 2629 | /** |
| 2630 | * snd_soc_get_volsw - single mixer get callback |
| 2631 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2632 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2633 | * |
Peter Ujfalusi | f7915d9 | 2011-10-05 10:29:24 +0300 | [diff] [blame] | 2634 | * Callback to get the value of a single mixer control, or a double mixer |
| 2635 | * control that spans 2 registers. |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2636 | * |
| 2637 | * Returns 0 for success. |
| 2638 | */ |
| 2639 | int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, |
| 2640 | struct snd_ctl_elem_value *ucontrol) |
| 2641 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2642 | struct soc_mixer_control *mc = |
| 2643 | (struct soc_mixer_control *)kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2644 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2645 | unsigned int reg = mc->reg; |
Peter Ujfalusi | f7915d9 | 2011-10-05 10:29:24 +0300 | [diff] [blame] | 2646 | unsigned int reg2 = mc->rreg; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2647 | unsigned int shift = mc->shift; |
| 2648 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2649 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2650 | unsigned int mask = (1 << fls(max)) - 1; |
| 2651 | unsigned int invert = mc->invert; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2652 | |
| 2653 | ucontrol->value.integer.value[0] = |
| 2654 | (snd_soc_read(codec, reg) >> shift) & mask; |
Peter Ujfalusi | f7915d9 | 2011-10-05 10:29:24 +0300 | [diff] [blame] | 2655 | if (invert) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2656 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2657 | max - ucontrol->value.integer.value[0]; |
Peter Ujfalusi | f7915d9 | 2011-10-05 10:29:24 +0300 | [diff] [blame] | 2658 | |
| 2659 | if (snd_soc_volsw_is_stereo(mc)) { |
| 2660 | if (reg == reg2) |
| 2661 | ucontrol->value.integer.value[1] = |
| 2662 | (snd_soc_read(codec, reg) >> rshift) & mask; |
| 2663 | else |
| 2664 | ucontrol->value.integer.value[1] = |
| 2665 | (snd_soc_read(codec, reg2) >> shift) & mask; |
| 2666 | if (invert) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2667 | ucontrol->value.integer.value[1] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2668 | max - ucontrol->value.integer.value[1]; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | return 0; |
| 2672 | } |
| 2673 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw); |
| 2674 | |
| 2675 | /** |
| 2676 | * snd_soc_put_volsw - single mixer put callback |
| 2677 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2678 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2679 | * |
Peter Ujfalusi | 974815b | 2011-10-05 10:29:25 +0300 | [diff] [blame] | 2680 | * Callback to set the value of a single mixer control, or a double mixer |
| 2681 | * control that spans 2 registers. |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2682 | * |
| 2683 | * Returns 0 for success. |
| 2684 | */ |
| 2685 | int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, |
| 2686 | struct snd_ctl_elem_value *ucontrol) |
| 2687 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2688 | struct soc_mixer_control *mc = |
| 2689 | (struct soc_mixer_control *)kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2690 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2691 | unsigned int reg = mc->reg; |
Peter Ujfalusi | 974815b | 2011-10-05 10:29:25 +0300 | [diff] [blame] | 2692 | unsigned int reg2 = mc->rreg; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2693 | unsigned int shift = mc->shift; |
| 2694 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2695 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2696 | unsigned int mask = (1 << fls(max)) - 1; |
| 2697 | unsigned int invert = mc->invert; |
Peter Ujfalusi | 974815b | 2011-10-05 10:29:25 +0300 | [diff] [blame] | 2698 | int err; |
| 2699 | bool type_2r = 0; |
| 2700 | unsigned int val2 = 0; |
| 2701 | unsigned int val, val_mask; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2702 | |
| 2703 | val = (ucontrol->value.integer.value[0] & mask); |
| 2704 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2705 | val = max - val; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2706 | val_mask = mask << shift; |
| 2707 | val = val << shift; |
Peter Ujfalusi | 974815b | 2011-10-05 10:29:25 +0300 | [diff] [blame] | 2708 | if (snd_soc_volsw_is_stereo(mc)) { |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2709 | val2 = (ucontrol->value.integer.value[1] & mask); |
| 2710 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2711 | val2 = max - val2; |
Peter Ujfalusi | 974815b | 2011-10-05 10:29:25 +0300 | [diff] [blame] | 2712 | if (reg == reg2) { |
| 2713 | val_mask |= mask << rshift; |
| 2714 | val |= val2 << rshift; |
| 2715 | } else { |
| 2716 | val2 = val2 << shift; |
| 2717 | type_2r = 1; |
| 2718 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2719 | } |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2720 | err = snd_soc_update_bits_locked(codec, reg, val_mask, val); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 2721 | if (err < 0) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2722 | return err; |
| 2723 | |
Peter Ujfalusi | 974815b | 2011-10-05 10:29:25 +0300 | [diff] [blame] | 2724 | if (type_2r) |
| 2725 | err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2); |
| 2726 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2727 | return err; |
| 2728 | } |
Peter Ujfalusi | 974815b | 2011-10-05 10:29:25 +0300 | [diff] [blame] | 2729 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2730 | |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2731 | /** |
Brian Austin | 1d99f24 | 2012-03-30 10:43:55 -0500 | [diff] [blame] | 2732 | * snd_soc_get_volsw_sx - single mixer get callback |
| 2733 | * @kcontrol: mixer control |
| 2734 | * @ucontrol: control element information |
| 2735 | * |
| 2736 | * Callback to get the value of a single mixer control, or a double mixer |
| 2737 | * control that spans 2 registers. |
| 2738 | * |
| 2739 | * Returns 0 for success. |
| 2740 | */ |
| 2741 | int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol, |
| 2742 | struct snd_ctl_elem_value *ucontrol) |
| 2743 | { |
| 2744 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2745 | struct soc_mixer_control *mc = |
| 2746 | (struct soc_mixer_control *)kcontrol->private_value; |
| 2747 | |
| 2748 | unsigned int reg = mc->reg; |
| 2749 | unsigned int reg2 = mc->rreg; |
| 2750 | unsigned int shift = mc->shift; |
| 2751 | unsigned int rshift = mc->rshift; |
| 2752 | int max = mc->max; |
| 2753 | int min = mc->min; |
| 2754 | int mask = (1 << (fls(min + max) - 1)) - 1; |
| 2755 | |
| 2756 | ucontrol->value.integer.value[0] = |
| 2757 | ((snd_soc_read(codec, reg) >> shift) - min) & mask; |
| 2758 | |
| 2759 | if (snd_soc_volsw_is_stereo(mc)) |
| 2760 | ucontrol->value.integer.value[1] = |
| 2761 | ((snd_soc_read(codec, reg2) >> rshift) - min) & mask; |
| 2762 | |
| 2763 | return 0; |
| 2764 | } |
| 2765 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx); |
| 2766 | |
| 2767 | /** |
| 2768 | * snd_soc_put_volsw_sx - double mixer set callback |
| 2769 | * @kcontrol: mixer control |
| 2770 | * @uinfo: control element information |
| 2771 | * |
| 2772 | * Callback to set the value of a double mixer control that spans 2 registers. |
| 2773 | * |
| 2774 | * Returns 0 for success. |
| 2775 | */ |
| 2776 | int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, |
| 2777 | struct snd_ctl_elem_value *ucontrol) |
| 2778 | { |
| 2779 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2780 | struct soc_mixer_control *mc = |
| 2781 | (struct soc_mixer_control *)kcontrol->private_value; |
| 2782 | |
| 2783 | unsigned int reg = mc->reg; |
| 2784 | unsigned int reg2 = mc->rreg; |
| 2785 | unsigned int shift = mc->shift; |
| 2786 | unsigned int rshift = mc->rshift; |
| 2787 | int max = mc->max; |
| 2788 | int min = mc->min; |
| 2789 | int mask = (1 << (fls(min + max) - 1)) - 1; |
Brian Austin | 27f1d75 | 2012-04-03 11:33:50 -0500 | [diff] [blame] | 2790 | int err = 0; |
Brian Austin | 1d99f24 | 2012-03-30 10:43:55 -0500 | [diff] [blame] | 2791 | unsigned short val, val_mask, val2 = 0; |
| 2792 | |
| 2793 | val_mask = mask << shift; |
| 2794 | val = (ucontrol->value.integer.value[0] + min) & mask; |
| 2795 | val = val << shift; |
| 2796 | |
Mukund Navada | d055852 | 2012-11-09 11:53:40 +0530 | [diff] [blame] | 2797 | err = snd_soc_update_bits_locked(codec, reg, val_mask, val); |
| 2798 | if (err < 0) |
| 2799 | return err; |
Brian Austin | 1d99f24 | 2012-03-30 10:43:55 -0500 | [diff] [blame] | 2800 | |
| 2801 | if (snd_soc_volsw_is_stereo(mc)) { |
| 2802 | val_mask = mask << rshift; |
| 2803 | val2 = (ucontrol->value.integer.value[1] + min) & mask; |
| 2804 | val2 = val2 << rshift; |
| 2805 | |
| 2806 | if (snd_soc_update_bits_locked(codec, reg2, val_mask, val2)) |
| 2807 | return err; |
| 2808 | } |
| 2809 | return 0; |
| 2810 | } |
| 2811 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx); |
| 2812 | |
| 2813 | /** |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2814 | * snd_soc_info_volsw_s8 - signed mixer info callback |
| 2815 | * @kcontrol: mixer control |
| 2816 | * @uinfo: control element information |
| 2817 | * |
| 2818 | * Callback to provide information about a signed mixer control. |
| 2819 | * |
| 2820 | * Returns 0 for success. |
| 2821 | */ |
| 2822 | int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol, |
| 2823 | struct snd_ctl_elem_info *uinfo) |
| 2824 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2825 | struct soc_mixer_control *mc = |
| 2826 | (struct soc_mixer_control *)kcontrol->private_value; |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 2827 | int platform_max; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2828 | int min = mc->min; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2829 | |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 2830 | if (!mc->platform_max) |
| 2831 | mc->platform_max = mc->max; |
| 2832 | platform_max = mc->platform_max; |
| 2833 | |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2834 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2835 | uinfo->count = 2; |
| 2836 | uinfo->value.integer.min = 0; |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 2837 | uinfo->value.integer.max = platform_max - min; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2838 | return 0; |
| 2839 | } |
| 2840 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8); |
| 2841 | |
| 2842 | /** |
| 2843 | * snd_soc_get_volsw_s8 - signed mixer get callback |
| 2844 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2845 | * @ucontrol: control element information |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2846 | * |
| 2847 | * Callback to get the value of a signed mixer control. |
| 2848 | * |
| 2849 | * Returns 0 for success. |
| 2850 | */ |
| 2851 | int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, |
| 2852 | struct snd_ctl_elem_value *ucontrol) |
| 2853 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2854 | struct soc_mixer_control *mc = |
| 2855 | (struct soc_mixer_control *)kcontrol->private_value; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2856 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2857 | unsigned int reg = mc->reg; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2858 | int min = mc->min; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2859 | int val = snd_soc_read(codec, reg); |
| 2860 | |
| 2861 | ucontrol->value.integer.value[0] = |
| 2862 | ((signed char)(val & 0xff))-min; |
| 2863 | ucontrol->value.integer.value[1] = |
| 2864 | ((signed char)((val >> 8) & 0xff))-min; |
| 2865 | return 0; |
| 2866 | } |
| 2867 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8); |
| 2868 | |
| 2869 | /** |
| 2870 | * snd_soc_put_volsw_sgn - signed mixer put callback |
| 2871 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2872 | * @ucontrol: control element information |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2873 | * |
| 2874 | * Callback to set the value of a signed mixer control. |
| 2875 | * |
| 2876 | * Returns 0 for success. |
| 2877 | */ |
| 2878 | int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, |
| 2879 | struct snd_ctl_elem_value *ucontrol) |
| 2880 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2881 | struct soc_mixer_control *mc = |
| 2882 | (struct soc_mixer_control *)kcontrol->private_value; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2883 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2884 | unsigned int reg = mc->reg; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2885 | int min = mc->min; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2886 | unsigned int val; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2887 | |
| 2888 | val = (ucontrol->value.integer.value[0]+min) & 0xff; |
| 2889 | val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8; |
| 2890 | |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2891 | return snd_soc_update_bits_locked(codec, reg, 0xffff, val); |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2892 | } |
| 2893 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8); |
| 2894 | |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2895 | /** |
Adam Thomson | 6c9d8cf | 2012-05-31 15:18:01 +0100 | [diff] [blame] | 2896 | * snd_soc_info_volsw_range - single mixer info callback with range. |
| 2897 | * @kcontrol: mixer control |
| 2898 | * @uinfo: control element information |
| 2899 | * |
| 2900 | * Callback to provide information, within a range, about a single |
| 2901 | * mixer control. |
| 2902 | * |
| 2903 | * returns 0 for success. |
| 2904 | */ |
| 2905 | int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol, |
| 2906 | struct snd_ctl_elem_info *uinfo) |
| 2907 | { |
| 2908 | struct soc_mixer_control *mc = |
| 2909 | (struct soc_mixer_control *)kcontrol->private_value; |
| 2910 | int platform_max; |
| 2911 | int min = mc->min; |
| 2912 | |
| 2913 | if (!mc->platform_max) |
| 2914 | mc->platform_max = mc->max; |
| 2915 | platform_max = mc->platform_max; |
| 2916 | |
| 2917 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
Mark Brown | 9bde4f0 | 2012-12-19 16:05:00 +0000 | [diff] [blame] | 2918 | uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1; |
Adam Thomson | 6c9d8cf | 2012-05-31 15:18:01 +0100 | [diff] [blame] | 2919 | uinfo->value.integer.min = 0; |
| 2920 | uinfo->value.integer.max = platform_max - min; |
| 2921 | |
| 2922 | return 0; |
| 2923 | } |
| 2924 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range); |
| 2925 | |
| 2926 | /** |
| 2927 | * snd_soc_put_volsw_range - single mixer put value callback with range. |
| 2928 | * @kcontrol: mixer control |
| 2929 | * @ucontrol: control element information |
| 2930 | * |
| 2931 | * Callback to set the value, within a range, for a single mixer control. |
| 2932 | * |
| 2933 | * Returns 0 for success. |
| 2934 | */ |
| 2935 | int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, |
| 2936 | struct snd_ctl_elem_value *ucontrol) |
| 2937 | { |
| 2938 | struct soc_mixer_control *mc = |
| 2939 | (struct soc_mixer_control *)kcontrol->private_value; |
| 2940 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2941 | unsigned int reg = mc->reg; |
Mark Brown | 9bde4f0 | 2012-12-19 16:05:00 +0000 | [diff] [blame] | 2942 | unsigned int rreg = mc->rreg; |
Adam Thomson | 6c9d8cf | 2012-05-31 15:18:01 +0100 | [diff] [blame] | 2943 | unsigned int shift = mc->shift; |
| 2944 | int min = mc->min; |
| 2945 | int max = mc->max; |
| 2946 | unsigned int mask = (1 << fls(max)) - 1; |
| 2947 | unsigned int invert = mc->invert; |
| 2948 | unsigned int val, val_mask; |
Mark Brown | 9bde4f0 | 2012-12-19 16:05:00 +0000 | [diff] [blame] | 2949 | int ret; |
Adam Thomson | 6c9d8cf | 2012-05-31 15:18:01 +0100 | [diff] [blame] | 2950 | |
| 2951 | val = ((ucontrol->value.integer.value[0] + min) & mask); |
| 2952 | if (invert) |
| 2953 | val = max - val; |
| 2954 | val_mask = mask << shift; |
| 2955 | val = val << shift; |
| 2956 | |
Mark Brown | 9bde4f0 | 2012-12-19 16:05:00 +0000 | [diff] [blame] | 2957 | ret = snd_soc_update_bits_locked(codec, reg, val_mask, val); |
Joonyoung Shim | 0eaa6cc | 2013-03-26 14:41:05 +0900 | [diff] [blame] | 2958 | if (ret < 0) |
Mark Brown | 9bde4f0 | 2012-12-19 16:05:00 +0000 | [diff] [blame] | 2959 | return ret; |
| 2960 | |
| 2961 | if (snd_soc_volsw_is_stereo(mc)) { |
| 2962 | val = ((ucontrol->value.integer.value[1] + min) & mask); |
| 2963 | if (invert) |
| 2964 | val = max - val; |
| 2965 | val_mask = mask << shift; |
| 2966 | val = val << shift; |
| 2967 | |
| 2968 | ret = snd_soc_update_bits_locked(codec, rreg, val_mask, val); |
| 2969 | } |
| 2970 | |
| 2971 | return ret; |
Adam Thomson | 6c9d8cf | 2012-05-31 15:18:01 +0100 | [diff] [blame] | 2972 | } |
| 2973 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range); |
| 2974 | |
| 2975 | /** |
| 2976 | * snd_soc_get_volsw_range - single mixer get callback with range |
| 2977 | * @kcontrol: mixer control |
| 2978 | * @ucontrol: control element information |
| 2979 | * |
| 2980 | * Callback to get the value, within a range, of a single mixer control. |
| 2981 | * |
| 2982 | * Returns 0 for success. |
| 2983 | */ |
| 2984 | int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol, |
| 2985 | struct snd_ctl_elem_value *ucontrol) |
| 2986 | { |
| 2987 | struct soc_mixer_control *mc = |
| 2988 | (struct soc_mixer_control *)kcontrol->private_value; |
| 2989 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2990 | unsigned int reg = mc->reg; |
Mark Brown | 9bde4f0 | 2012-12-19 16:05:00 +0000 | [diff] [blame] | 2991 | unsigned int rreg = mc->rreg; |
Adam Thomson | 6c9d8cf | 2012-05-31 15:18:01 +0100 | [diff] [blame] | 2992 | unsigned int shift = mc->shift; |
| 2993 | int min = mc->min; |
| 2994 | int max = mc->max; |
| 2995 | unsigned int mask = (1 << fls(max)) - 1; |
| 2996 | unsigned int invert = mc->invert; |
| 2997 | |
| 2998 | ucontrol->value.integer.value[0] = |
| 2999 | (snd_soc_read(codec, reg) >> shift) & mask; |
| 3000 | if (invert) |
| 3001 | ucontrol->value.integer.value[0] = |
| 3002 | max - ucontrol->value.integer.value[0]; |
| 3003 | ucontrol->value.integer.value[0] = |
| 3004 | ucontrol->value.integer.value[0] - min; |
| 3005 | |
Mark Brown | 9bde4f0 | 2012-12-19 16:05:00 +0000 | [diff] [blame] | 3006 | if (snd_soc_volsw_is_stereo(mc)) { |
| 3007 | ucontrol->value.integer.value[1] = |
| 3008 | (snd_soc_read(codec, rreg) >> shift) & mask; |
| 3009 | if (invert) |
| 3010 | ucontrol->value.integer.value[1] = |
| 3011 | max - ucontrol->value.integer.value[1]; |
| 3012 | ucontrol->value.integer.value[1] = |
| 3013 | ucontrol->value.integer.value[1] - min; |
| 3014 | } |
| 3015 | |
Adam Thomson | 6c9d8cf | 2012-05-31 15:18:01 +0100 | [diff] [blame] | 3016 | return 0; |
| 3017 | } |
| 3018 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range); |
| 3019 | |
| 3020 | /** |
Peter Ujfalusi | 637d384 | 2010-05-07 14:05:49 +0300 | [diff] [blame] | 3021 | * snd_soc_limit_volume - Set new limit to an existing volume control. |
| 3022 | * |
| 3023 | * @codec: where to look for the control |
| 3024 | * @name: Name of the control |
| 3025 | * @max: new maximum limit |
| 3026 | * |
| 3027 | * Return 0 for success, else error. |
| 3028 | */ |
| 3029 | int snd_soc_limit_volume(struct snd_soc_codec *codec, |
| 3030 | const char *name, int max) |
| 3031 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3032 | struct snd_card *card = codec->card->snd_card; |
Peter Ujfalusi | 637d384 | 2010-05-07 14:05:49 +0300 | [diff] [blame] | 3033 | struct snd_kcontrol *kctl; |
| 3034 | struct soc_mixer_control *mc; |
| 3035 | int found = 0; |
| 3036 | int ret = -EINVAL; |
| 3037 | |
| 3038 | /* Sanity check for name and max */ |
| 3039 | if (unlikely(!name || max <= 0)) |
| 3040 | return -EINVAL; |
| 3041 | |
| 3042 | list_for_each_entry(kctl, &card->controls, list) { |
| 3043 | if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) { |
| 3044 | found = 1; |
| 3045 | break; |
| 3046 | } |
| 3047 | } |
| 3048 | if (found) { |
| 3049 | mc = (struct soc_mixer_control *)kctl->private_value; |
| 3050 | if (max <= mc->max) { |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 3051 | mc->platform_max = max; |
Peter Ujfalusi | 637d384 | 2010-05-07 14:05:49 +0300 | [diff] [blame] | 3052 | ret = 0; |
| 3053 | } |
| 3054 | } |
| 3055 | return ret; |
| 3056 | } |
| 3057 | EXPORT_SYMBOL_GPL(snd_soc_limit_volume); |
| 3058 | |
Mark Brown | 71d0851 | 2011-10-10 18:31:26 +0100 | [diff] [blame] | 3059 | int snd_soc_bytes_info(struct snd_kcontrol *kcontrol, |
| 3060 | struct snd_ctl_elem_info *uinfo) |
| 3061 | { |
| 3062 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3063 | struct soc_bytes *params = (void *)kcontrol->private_value; |
| 3064 | |
| 3065 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; |
| 3066 | uinfo->count = params->num_regs * codec->val_bytes; |
| 3067 | |
| 3068 | return 0; |
| 3069 | } |
| 3070 | EXPORT_SYMBOL_GPL(snd_soc_bytes_info); |
| 3071 | |
| 3072 | int snd_soc_bytes_get(struct snd_kcontrol *kcontrol, |
| 3073 | struct snd_ctl_elem_value *ucontrol) |
| 3074 | { |
| 3075 | struct soc_bytes *params = (void *)kcontrol->private_value; |
| 3076 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3077 | int ret; |
| 3078 | |
| 3079 | if (codec->using_regmap) |
| 3080 | ret = regmap_raw_read(codec->control_data, params->base, |
| 3081 | ucontrol->value.bytes.data, |
| 3082 | params->num_regs * codec->val_bytes); |
| 3083 | else |
| 3084 | ret = -EINVAL; |
| 3085 | |
Mark Brown | f831b05 | 2012-02-17 16:20:33 -0800 | [diff] [blame] | 3086 | /* Hide any masked bytes to ensure consistent data reporting */ |
| 3087 | if (ret == 0 && params->mask) { |
| 3088 | switch (codec->val_bytes) { |
| 3089 | case 1: |
| 3090 | ucontrol->value.bytes.data[0] &= ~params->mask; |
| 3091 | break; |
| 3092 | case 2: |
| 3093 | ((u16 *)(&ucontrol->value.bytes.data))[0] |
| 3094 | &= ~params->mask; |
| 3095 | break; |
| 3096 | case 4: |
| 3097 | ((u32 *)(&ucontrol->value.bytes.data))[0] |
| 3098 | &= ~params->mask; |
| 3099 | break; |
| 3100 | default: |
| 3101 | return -EINVAL; |
| 3102 | } |
| 3103 | } |
| 3104 | |
Mark Brown | 71d0851 | 2011-10-10 18:31:26 +0100 | [diff] [blame] | 3105 | return ret; |
| 3106 | } |
| 3107 | EXPORT_SYMBOL_GPL(snd_soc_bytes_get); |
| 3108 | |
| 3109 | int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, |
| 3110 | struct snd_ctl_elem_value *ucontrol) |
| 3111 | { |
| 3112 | struct soc_bytes *params = (void *)kcontrol->private_value; |
| 3113 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Mark Brown | f831b05 | 2012-02-17 16:20:33 -0800 | [diff] [blame] | 3114 | int ret, len; |
| 3115 | unsigned int val; |
| 3116 | void *data; |
Mark Brown | 71d0851 | 2011-10-10 18:31:26 +0100 | [diff] [blame] | 3117 | |
Mark Brown | f831b05 | 2012-02-17 16:20:33 -0800 | [diff] [blame] | 3118 | if (!codec->using_regmap) |
| 3119 | return -EINVAL; |
| 3120 | |
Mark Brown | f831b05 | 2012-02-17 16:20:33 -0800 | [diff] [blame] | 3121 | len = params->num_regs * codec->val_bytes; |
| 3122 | |
Mark Brown | b5a8fe4 | 2013-01-20 21:42:22 +0900 | [diff] [blame] | 3123 | data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA); |
| 3124 | if (!data) |
| 3125 | return -ENOMEM; |
| 3126 | |
Mark Brown | f831b05 | 2012-02-17 16:20:33 -0800 | [diff] [blame] | 3127 | /* |
| 3128 | * If we've got a mask then we need to preserve the register |
| 3129 | * bits. We shouldn't modify the incoming data so take a |
| 3130 | * copy. |
| 3131 | */ |
| 3132 | if (params->mask) { |
| 3133 | ret = regmap_read(codec->control_data, params->base, &val); |
| 3134 | if (ret != 0) |
Wei Yongjun | e8b18ad | 2013-03-12 00:35:14 +0800 | [diff] [blame] | 3135 | goto out; |
Mark Brown | f831b05 | 2012-02-17 16:20:33 -0800 | [diff] [blame] | 3136 | |
| 3137 | val &= params->mask; |
| 3138 | |
Mark Brown | f831b05 | 2012-02-17 16:20:33 -0800 | [diff] [blame] | 3139 | switch (codec->val_bytes) { |
| 3140 | case 1: |
| 3141 | ((u8 *)data)[0] &= ~params->mask; |
| 3142 | ((u8 *)data)[0] |= val; |
| 3143 | break; |
| 3144 | case 2: |
| 3145 | ((u16 *)data)[0] &= cpu_to_be16(~params->mask); |
| 3146 | ((u16 *)data)[0] |= cpu_to_be16(val); |
| 3147 | break; |
| 3148 | case 4: |
| 3149 | ((u32 *)data)[0] &= cpu_to_be32(~params->mask); |
| 3150 | ((u32 *)data)[0] |= cpu_to_be32(val); |
| 3151 | break; |
| 3152 | default: |
Wei Yongjun | e8b18ad | 2013-03-12 00:35:14 +0800 | [diff] [blame] | 3153 | ret = -EINVAL; |
| 3154 | goto out; |
Mark Brown | f831b05 | 2012-02-17 16:20:33 -0800 | [diff] [blame] | 3155 | } |
| 3156 | } |
| 3157 | |
| 3158 | ret = regmap_raw_write(codec->control_data, params->base, |
| 3159 | data, len); |
| 3160 | |
Wei Yongjun | e8b18ad | 2013-03-12 00:35:14 +0800 | [diff] [blame] | 3161 | out: |
Mark Brown | b5a8fe4 | 2013-01-20 21:42:22 +0900 | [diff] [blame] | 3162 | kfree(data); |
Mark Brown | 71d0851 | 2011-10-10 18:31:26 +0100 | [diff] [blame] | 3163 | |
| 3164 | return ret; |
| 3165 | } |
| 3166 | EXPORT_SYMBOL_GPL(snd_soc_bytes_put); |
| 3167 | |
apatard@mandriva.com | b6f4bb3 | 2010-05-15 17:30:01 +0200 | [diff] [blame] | 3168 | /** |
Kristoffer KARLSSON | 4183eed2 | 2012-04-20 11:32:13 +0200 | [diff] [blame] | 3169 | * snd_soc_info_xr_sx - signed multi register info callback |
| 3170 | * @kcontrol: mreg control |
| 3171 | * @uinfo: control element information |
| 3172 | * |
| 3173 | * Callback to provide information of a control that can |
| 3174 | * span multiple codec registers which together |
| 3175 | * forms a single signed value in a MSB/LSB manner. |
| 3176 | * |
| 3177 | * Returns 0 for success. |
| 3178 | */ |
| 3179 | int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol, |
| 3180 | struct snd_ctl_elem_info *uinfo) |
| 3181 | { |
| 3182 | struct soc_mreg_control *mc = |
| 3183 | (struct soc_mreg_control *)kcontrol->private_value; |
| 3184 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 3185 | uinfo->count = 1; |
| 3186 | uinfo->value.integer.min = mc->min; |
| 3187 | uinfo->value.integer.max = mc->max; |
| 3188 | |
| 3189 | return 0; |
| 3190 | } |
| 3191 | EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx); |
| 3192 | |
| 3193 | /** |
| 3194 | * snd_soc_get_xr_sx - signed multi register get callback |
| 3195 | * @kcontrol: mreg control |
| 3196 | * @ucontrol: control element information |
| 3197 | * |
| 3198 | * Callback to get the value of a control that can span |
| 3199 | * multiple codec registers which together forms a single |
| 3200 | * signed value in a MSB/LSB manner. The control supports |
| 3201 | * specifying total no of bits used to allow for bitfields |
| 3202 | * across the multiple codec registers. |
| 3203 | * |
| 3204 | * Returns 0 for success. |
| 3205 | */ |
| 3206 | int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol, |
| 3207 | struct snd_ctl_elem_value *ucontrol) |
| 3208 | { |
| 3209 | struct soc_mreg_control *mc = |
| 3210 | (struct soc_mreg_control *)kcontrol->private_value; |
| 3211 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3212 | unsigned int regbase = mc->regbase; |
| 3213 | unsigned int regcount = mc->regcount; |
| 3214 | unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE; |
| 3215 | unsigned int regwmask = (1<<regwshift)-1; |
| 3216 | unsigned int invert = mc->invert; |
| 3217 | unsigned long mask = (1UL<<mc->nbits)-1; |
| 3218 | long min = mc->min; |
| 3219 | long max = mc->max; |
| 3220 | long val = 0; |
| 3221 | unsigned long regval; |
| 3222 | unsigned int i; |
| 3223 | |
| 3224 | for (i = 0; i < regcount; i++) { |
| 3225 | regval = snd_soc_read(codec, regbase+i) & regwmask; |
| 3226 | val |= regval << (regwshift*(regcount-i-1)); |
| 3227 | } |
| 3228 | val &= mask; |
| 3229 | if (min < 0 && val > max) |
| 3230 | val |= ~mask; |
| 3231 | if (invert) |
| 3232 | val = max - val; |
| 3233 | ucontrol->value.integer.value[0] = val; |
| 3234 | |
| 3235 | return 0; |
| 3236 | } |
| 3237 | EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx); |
| 3238 | |
| 3239 | /** |
| 3240 | * snd_soc_put_xr_sx - signed multi register get callback |
| 3241 | * @kcontrol: mreg control |
| 3242 | * @ucontrol: control element information |
| 3243 | * |
| 3244 | * Callback to set the value of a control that can span |
| 3245 | * multiple codec registers which together forms a single |
| 3246 | * signed value in a MSB/LSB manner. The control supports |
| 3247 | * specifying total no of bits used to allow for bitfields |
| 3248 | * across the multiple codec registers. |
| 3249 | * |
| 3250 | * Returns 0 for success. |
| 3251 | */ |
| 3252 | int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol, |
| 3253 | struct snd_ctl_elem_value *ucontrol) |
| 3254 | { |
| 3255 | struct soc_mreg_control *mc = |
| 3256 | (struct soc_mreg_control *)kcontrol->private_value; |
| 3257 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3258 | unsigned int regbase = mc->regbase; |
| 3259 | unsigned int regcount = mc->regcount; |
| 3260 | unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE; |
| 3261 | unsigned int regwmask = (1<<regwshift)-1; |
| 3262 | unsigned int invert = mc->invert; |
| 3263 | unsigned long mask = (1UL<<mc->nbits)-1; |
Kristoffer KARLSSON | 4183eed2 | 2012-04-20 11:32:13 +0200 | [diff] [blame] | 3264 | long max = mc->max; |
| 3265 | long val = ucontrol->value.integer.value[0]; |
| 3266 | unsigned int i, regval, regmask; |
| 3267 | int err; |
| 3268 | |
| 3269 | if (invert) |
| 3270 | val = max - val; |
| 3271 | val &= mask; |
| 3272 | for (i = 0; i < regcount; i++) { |
| 3273 | regval = (val >> (regwshift*(regcount-i-1))) & regwmask; |
| 3274 | regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask; |
| 3275 | err = snd_soc_update_bits_locked(codec, regbase+i, |
| 3276 | regmask, regval); |
| 3277 | if (err < 0) |
| 3278 | return err; |
| 3279 | } |
| 3280 | |
| 3281 | return 0; |
| 3282 | } |
| 3283 | EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx); |
| 3284 | |
| 3285 | /** |
Kristoffer KARLSSON | dd7b10b | 2012-04-20 11:32:44 +0200 | [diff] [blame] | 3286 | * snd_soc_get_strobe - strobe get callback |
| 3287 | * @kcontrol: mixer control |
| 3288 | * @ucontrol: control element information |
| 3289 | * |
| 3290 | * Callback get the value of a strobe mixer control. |
| 3291 | * |
| 3292 | * Returns 0 for success. |
| 3293 | */ |
| 3294 | int snd_soc_get_strobe(struct snd_kcontrol *kcontrol, |
| 3295 | struct snd_ctl_elem_value *ucontrol) |
| 3296 | { |
| 3297 | struct soc_mixer_control *mc = |
| 3298 | (struct soc_mixer_control *)kcontrol->private_value; |
| 3299 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3300 | unsigned int reg = mc->reg; |
| 3301 | unsigned int shift = mc->shift; |
| 3302 | unsigned int mask = 1 << shift; |
| 3303 | unsigned int invert = mc->invert != 0; |
| 3304 | unsigned int val = snd_soc_read(codec, reg) & mask; |
| 3305 | |
| 3306 | if (shift != 0 && val != 0) |
| 3307 | val = val >> shift; |
| 3308 | ucontrol->value.enumerated.item[0] = val ^ invert; |
| 3309 | |
| 3310 | return 0; |
| 3311 | } |
| 3312 | EXPORT_SYMBOL_GPL(snd_soc_get_strobe); |
| 3313 | |
| 3314 | /** |
| 3315 | * snd_soc_put_strobe - strobe put callback |
| 3316 | * @kcontrol: mixer control |
| 3317 | * @ucontrol: control element information |
| 3318 | * |
| 3319 | * Callback strobe a register bit to high then low (or the inverse) |
| 3320 | * in one pass of a single mixer enum control. |
| 3321 | * |
| 3322 | * Returns 1 for success. |
| 3323 | */ |
| 3324 | int snd_soc_put_strobe(struct snd_kcontrol *kcontrol, |
| 3325 | struct snd_ctl_elem_value *ucontrol) |
| 3326 | { |
| 3327 | struct soc_mixer_control *mc = |
| 3328 | (struct soc_mixer_control *)kcontrol->private_value; |
| 3329 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3330 | unsigned int reg = mc->reg; |
| 3331 | unsigned int shift = mc->shift; |
| 3332 | unsigned int mask = 1 << shift; |
| 3333 | unsigned int invert = mc->invert != 0; |
| 3334 | unsigned int strobe = ucontrol->value.enumerated.item[0] != 0; |
| 3335 | unsigned int val1 = (strobe ^ invert) ? mask : 0; |
| 3336 | unsigned int val2 = (strobe ^ invert) ? 0 : mask; |
| 3337 | int err; |
| 3338 | |
| 3339 | err = snd_soc_update_bits_locked(codec, reg, mask, val1); |
| 3340 | if (err < 0) |
| 3341 | return err; |
| 3342 | |
| 3343 | err = snd_soc_update_bits_locked(codec, reg, mask, val2); |
| 3344 | return err; |
| 3345 | } |
| 3346 | EXPORT_SYMBOL_GPL(snd_soc_put_strobe); |
| 3347 | |
| 3348 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3349 | * snd_soc_dai_set_sysclk - configure DAI system or master clock. |
| 3350 | * @dai: DAI |
| 3351 | * @clk_id: DAI specific clock ID |
| 3352 | * @freq: new clock frequency in Hz |
| 3353 | * @dir: new clock direction - input/output. |
| 3354 | * |
| 3355 | * Configures the DAI master (MCLK) or system (SYSCLK) clocking. |
| 3356 | */ |
| 3357 | int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, |
| 3358 | unsigned int freq, int dir) |
| 3359 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3360 | if (dai->driver && dai->driver->ops->set_sysclk) |
| 3361 | return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir); |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 3362 | else if (dai->codec && dai->codec->driver->set_sysclk) |
Mark Brown | da1c6ea | 2011-08-24 20:09:01 +0100 | [diff] [blame] | 3363 | return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0, |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 3364 | freq, dir); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3365 | else |
| 3366 | return -EINVAL; |
| 3367 | } |
| 3368 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); |
| 3369 | |
| 3370 | /** |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 3371 | * snd_soc_codec_set_sysclk - configure CODEC system or master clock. |
| 3372 | * @codec: CODEC |
| 3373 | * @clk_id: DAI specific clock ID |
Mark Brown | da1c6ea | 2011-08-24 20:09:01 +0100 | [diff] [blame] | 3374 | * @source: Source for the clock |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 3375 | * @freq: new clock frequency in Hz |
| 3376 | * @dir: new clock direction - input/output. |
| 3377 | * |
| 3378 | * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. |
| 3379 | */ |
| 3380 | int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id, |
Mark Brown | da1c6ea | 2011-08-24 20:09:01 +0100 | [diff] [blame] | 3381 | int source, unsigned int freq, int dir) |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 3382 | { |
| 3383 | if (codec->driver->set_sysclk) |
Mark Brown | da1c6ea | 2011-08-24 20:09:01 +0100 | [diff] [blame] | 3384 | return codec->driver->set_sysclk(codec, clk_id, source, |
| 3385 | freq, dir); |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 3386 | else |
| 3387 | return -EINVAL; |
| 3388 | } |
| 3389 | EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk); |
| 3390 | |
| 3391 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3392 | * snd_soc_dai_set_clkdiv - configure DAI clock dividers. |
| 3393 | * @dai: DAI |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3394 | * @div_id: DAI specific clock divider ID |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3395 | * @div: new clock divisor. |
| 3396 | * |
| 3397 | * Configures the clock dividers. This is used to derive the best DAI bit and |
| 3398 | * frame clocks from the system or master clock. It's best to set the DAI bit |
| 3399 | * and frame clocks as low as possible to save system power. |
| 3400 | */ |
| 3401 | int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, |
| 3402 | int div_id, int div) |
| 3403 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3404 | if (dai->driver && dai->driver->ops->set_clkdiv) |
| 3405 | return dai->driver->ops->set_clkdiv(dai, div_id, div); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3406 | else |
| 3407 | return -EINVAL; |
| 3408 | } |
| 3409 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); |
| 3410 | |
| 3411 | /** |
| 3412 | * snd_soc_dai_set_pll - configure DAI PLL. |
| 3413 | * @dai: DAI |
| 3414 | * @pll_id: DAI specific PLL ID |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 3415 | * @source: DAI specific source for the PLL |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3416 | * @freq_in: PLL input clock frequency in Hz |
| 3417 | * @freq_out: requested PLL output clock frequency in Hz |
| 3418 | * |
| 3419 | * Configures and enables PLL to generate output clock based on input clock. |
| 3420 | */ |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 3421 | int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, |
| 3422 | unsigned int freq_in, unsigned int freq_out) |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3423 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3424 | if (dai->driver && dai->driver->ops->set_pll) |
| 3425 | return dai->driver->ops->set_pll(dai, pll_id, source, |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 3426 | freq_in, freq_out); |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 3427 | else if (dai->codec && dai->codec->driver->set_pll) |
| 3428 | return dai->codec->driver->set_pll(dai->codec, pll_id, source, |
| 3429 | freq_in, freq_out); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3430 | else |
| 3431 | return -EINVAL; |
| 3432 | } |
| 3433 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); |
| 3434 | |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 3435 | /* |
| 3436 | * snd_soc_codec_set_pll - configure codec PLL. |
| 3437 | * @codec: CODEC |
| 3438 | * @pll_id: DAI specific PLL ID |
| 3439 | * @source: DAI specific source for the PLL |
| 3440 | * @freq_in: PLL input clock frequency in Hz |
| 3441 | * @freq_out: requested PLL output clock frequency in Hz |
| 3442 | * |
| 3443 | * Configures and enables PLL to generate output clock based on input clock. |
| 3444 | */ |
| 3445 | int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source, |
| 3446 | unsigned int freq_in, unsigned int freq_out) |
| 3447 | { |
| 3448 | if (codec->driver->set_pll) |
| 3449 | return codec->driver->set_pll(codec, pll_id, source, |
| 3450 | freq_in, freq_out); |
| 3451 | else |
| 3452 | return -EINVAL; |
| 3453 | } |
| 3454 | EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll); |
| 3455 | |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3456 | /** |
| 3457 | * snd_soc_dai_set_fmt - configure DAI hardware audio format. |
| 3458 | * @dai: DAI |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3459 | * @fmt: SND_SOC_DAIFMT_ format value. |
| 3460 | * |
| 3461 | * Configures the DAI hardware format and clocking. |
| 3462 | */ |
| 3463 | int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 3464 | { |
Shawn Guo | 5e4ba56 | 2012-03-09 00:59:40 +0800 | [diff] [blame] | 3465 | if (dai->driver == NULL) |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3466 | return -EINVAL; |
Shawn Guo | 5e4ba56 | 2012-03-09 00:59:40 +0800 | [diff] [blame] | 3467 | if (dai->driver->ops->set_fmt == NULL) |
| 3468 | return -ENOTSUPP; |
| 3469 | return dai->driver->ops->set_fmt(dai, fmt); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3470 | } |
| 3471 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt); |
| 3472 | |
| 3473 | /** |
| 3474 | * snd_soc_dai_set_tdm_slot - configure DAI TDM. |
| 3475 | * @dai: DAI |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 3476 | * @tx_mask: bitmask representing active TX slots. |
| 3477 | * @rx_mask: bitmask representing active RX slots. |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3478 | * @slots: Number of slots in use. |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 3479 | * @slot_width: Width in bits for each slot. |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3480 | * |
| 3481 | * Configures a DAI for TDM operation. Both mask and slots are codec and DAI |
| 3482 | * specific. |
| 3483 | */ |
| 3484 | int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 3485 | unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3486 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3487 | if (dai->driver && dai->driver->ops->set_tdm_slot) |
| 3488 | return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask, |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 3489 | slots, slot_width); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3490 | else |
| 3491 | return -EINVAL; |
| 3492 | } |
| 3493 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); |
| 3494 | |
| 3495 | /** |
Barry Song | 472df3c | 2009-09-12 01:16:29 +0800 | [diff] [blame] | 3496 | * snd_soc_dai_set_channel_map - configure DAI audio channel map |
| 3497 | * @dai: DAI |
| 3498 | * @tx_num: how many TX channels |
| 3499 | * @tx_slot: pointer to an array which imply the TX slot number channel |
| 3500 | * 0~num-1 uses |
| 3501 | * @rx_num: how many RX channels |
| 3502 | * @rx_slot: pointer to an array which imply the RX slot number channel |
| 3503 | * 0~num-1 uses |
| 3504 | * |
| 3505 | * configure the relationship between channel number and TDM slot number. |
| 3506 | */ |
| 3507 | int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai, |
| 3508 | unsigned int tx_num, unsigned int *tx_slot, |
| 3509 | unsigned int rx_num, unsigned int *rx_slot) |
| 3510 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3511 | if (dai->driver && dai->driver->ops->set_channel_map) |
| 3512 | return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot, |
Barry Song | 472df3c | 2009-09-12 01:16:29 +0800 | [diff] [blame] | 3513 | rx_num, rx_slot); |
| 3514 | else |
| 3515 | return -EINVAL; |
| 3516 | } |
| 3517 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map); |
| 3518 | |
| 3519 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3520 | * snd_soc_dai_set_tristate - configure DAI system or master clock. |
| 3521 | * @dai: DAI |
| 3522 | * @tristate: tristate enable |
| 3523 | * |
| 3524 | * Tristates the DAI so that others can use it. |
| 3525 | */ |
| 3526 | int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) |
| 3527 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3528 | if (dai->driver && dai->driver->ops->set_tristate) |
| 3529 | return dai->driver->ops->set_tristate(dai, tristate); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3530 | else |
| 3531 | return -EINVAL; |
| 3532 | } |
| 3533 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate); |
| 3534 | |
| 3535 | /** |
| 3536 | * snd_soc_dai_digital_mute - configure DAI system or master clock. |
| 3537 | * @dai: DAI |
| 3538 | * @mute: mute enable |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 3539 | * @direction: stream to mute |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3540 | * |
| 3541 | * Mutes the DAI DAC. |
| 3542 | */ |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 3543 | int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute, |
| 3544 | int direction) |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3545 | { |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 3546 | if (!dai->driver) |
| 3547 | return -ENOTSUPP; |
| 3548 | |
| 3549 | if (dai->driver->ops->mute_stream) |
| 3550 | return dai->driver->ops->mute_stream(dai, mute, direction); |
| 3551 | else if (direction == SNDRV_PCM_STREAM_PLAYBACK && |
| 3552 | dai->driver->ops->digital_mute) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3553 | return dai->driver->ops->digital_mute(dai, mute); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3554 | else |
Mark Brown | 04570c6 | 2012-04-13 19:16:03 +0100 | [diff] [blame] | 3555 | return -ENOTSUPP; |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3556 | } |
| 3557 | EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); |
| 3558 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3559 | /** |
| 3560 | * snd_soc_register_card - Register a card with the ASoC core |
| 3561 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3562 | * @card: Card to register |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3563 | * |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3564 | */ |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 3565 | int snd_soc_register_card(struct snd_soc_card *card) |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3566 | { |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 3567 | int i, ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3568 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3569 | if (!card->name || !card->dev) |
| 3570 | return -EINVAL; |
| 3571 | |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 3572 | for (i = 0; i < card->num_links; i++) { |
| 3573 | struct snd_soc_dai_link *link = &card->dai_link[i]; |
| 3574 | |
| 3575 | /* |
| 3576 | * Codec must be specified by 1 of name or OF node, |
| 3577 | * not both or neither. |
| 3578 | */ |
| 3579 | if (!!link->codec_name == !!link->codec_of_node) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 3580 | dev_err(card->dev, |
| 3581 | "ASoC: Neither/both codec name/of_node are set for %s\n", |
| 3582 | link->name); |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 3583 | return -EINVAL; |
| 3584 | } |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 3585 | /* Codec DAI name must be specified */ |
| 3586 | if (!link->codec_dai_name) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 3587 | dev_err(card->dev, |
| 3588 | "ASoC: codec_dai_name not set for %s\n", |
| 3589 | link->name); |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 3590 | return -EINVAL; |
| 3591 | } |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 3592 | |
| 3593 | /* |
| 3594 | * Platform may be specified by either name or OF node, but |
| 3595 | * can be left unspecified, and a dummy platform will be used. |
| 3596 | */ |
| 3597 | if (link->platform_name && link->platform_of_node) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 3598 | dev_err(card->dev, |
| 3599 | "ASoC: Both platform name/of_node are set for %s\n", |
| 3600 | link->name); |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 3601 | return -EINVAL; |
| 3602 | } |
| 3603 | |
| 3604 | /* |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 3605 | * CPU device may be specified by either name or OF node, but |
| 3606 | * can be left unspecified, and will be matched based on DAI |
| 3607 | * name alone.. |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 3608 | */ |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 3609 | if (link->cpu_name && link->cpu_of_node) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 3610 | dev_err(card->dev, |
| 3611 | "ASoC: Neither/both cpu name/of_node are set for %s\n", |
| 3612 | link->name); |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 3613 | return -EINVAL; |
| 3614 | } |
| 3615 | /* |
| 3616 | * At least one of CPU DAI name or CPU device name/node must be |
| 3617 | * specified |
| 3618 | */ |
| 3619 | if (!link->cpu_dai_name && |
| 3620 | !(link->cpu_name || link->cpu_of_node)) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 3621 | dev_err(card->dev, |
| 3622 | "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n", |
| 3623 | link->name); |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 3624 | return -EINVAL; |
| 3625 | } |
| 3626 | } |
| 3627 | |
Mark Brown | ed77cc1 | 2011-05-03 18:25:34 +0100 | [diff] [blame] | 3628 | dev_set_drvdata(card->dev, card); |
| 3629 | |
Stephen Warren | 111c641 | 2011-01-28 14:26:35 -0700 | [diff] [blame] | 3630 | snd_soc_initialize_card_lists(card); |
| 3631 | |
Vinod Koul | 150dd2f | 2011-01-13 22:48:32 +0530 | [diff] [blame] | 3632 | soc_init_card_debugfs(card); |
| 3633 | |
Mark Brown | 181a689 | 2012-03-14 20:18:49 +0000 | [diff] [blame] | 3634 | card->rtd = devm_kzalloc(card->dev, |
| 3635 | sizeof(struct snd_soc_pcm_runtime) * |
| 3636 | (card->num_links + card->num_aux_devs), |
| 3637 | GFP_KERNEL); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3638 | if (card->rtd == NULL) |
| 3639 | return -ENOMEM; |
Liam Girdwood | a7dbb60 | 2012-04-17 18:00:11 +0100 | [diff] [blame] | 3640 | card->num_rtd = 0; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 3641 | card->rtd_aux = &card->rtd[card->num_links]; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3642 | |
| 3643 | for (i = 0; i < card->num_links; i++) |
| 3644 | card->rtd[i].dai_link = &card->dai_link[i]; |
| 3645 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3646 | INIT_LIST_HEAD(&card->list); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 3647 | INIT_LIST_HEAD(&card->dapm_dirty); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3648 | card->instantiated = 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3649 | mutex_init(&card->mutex); |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3650 | mutex_init(&card->dapm_mutex); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3651 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 3652 | ret = snd_soc_instantiate_card(card); |
| 3653 | if (ret != 0) |
| 3654 | soc_cleanup_card_debugfs(card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3655 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 3656 | return ret; |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3657 | } |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 3658 | EXPORT_SYMBOL_GPL(snd_soc_register_card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3659 | |
| 3660 | /** |
| 3661 | * snd_soc_unregister_card - Unregister a card with the ASoC core |
| 3662 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3663 | * @card: Card to unregister |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3664 | * |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3665 | */ |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 3666 | int snd_soc_unregister_card(struct snd_soc_card *card) |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3667 | { |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 3668 | if (card->instantiated) |
| 3669 | soc_cleanup_card_resources(card); |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 3670 | dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3671 | |
| 3672 | return 0; |
| 3673 | } |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 3674 | EXPORT_SYMBOL_GPL(snd_soc_unregister_card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3675 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3676 | /* |
| 3677 | * Simplify DAI link configuration by removing ".-1" from device names |
| 3678 | * and sanitizing names. |
| 3679 | */ |
Dimitris Papastamos | 0b9a214 | 2010-12-06 15:49:20 +0000 | [diff] [blame] | 3680 | static char *fmt_single_name(struct device *dev, int *id) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3681 | { |
| 3682 | char *found, name[NAME_SIZE]; |
| 3683 | int id1, id2; |
| 3684 | |
| 3685 | if (dev_name(dev) == NULL) |
| 3686 | return NULL; |
| 3687 | |
Dimitris Papastamos | 58818a7 | 2010-12-06 15:42:17 +0000 | [diff] [blame] | 3688 | strlcpy(name, dev_name(dev), NAME_SIZE); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3689 | |
| 3690 | /* are we a "%s.%d" name (platform and SPI components) */ |
| 3691 | found = strstr(name, dev->driver->name); |
| 3692 | if (found) { |
| 3693 | /* get ID */ |
| 3694 | if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) { |
| 3695 | |
| 3696 | /* discard ID from name if ID == -1 */ |
| 3697 | if (*id == -1) |
| 3698 | found[strlen(dev->driver->name)] = '\0'; |
| 3699 | } |
| 3700 | |
| 3701 | } else { |
| 3702 | /* I2C component devices are named "bus-addr" */ |
| 3703 | if (sscanf(name, "%x-%x", &id1, &id2) == 2) { |
| 3704 | char tmp[NAME_SIZE]; |
| 3705 | |
| 3706 | /* create unique ID number from I2C addr and bus */ |
Jarkko Nikula | 0589944 | 2010-10-19 11:10:45 +0300 | [diff] [blame] | 3707 | *id = ((id1 & 0xffff) << 16) + id2; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3708 | |
| 3709 | /* sanitize component name for DAI link creation */ |
| 3710 | snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name); |
Dimitris Papastamos | 58818a7 | 2010-12-06 15:42:17 +0000 | [diff] [blame] | 3711 | strlcpy(name, tmp, NAME_SIZE); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3712 | } else |
| 3713 | *id = 0; |
| 3714 | } |
| 3715 | |
| 3716 | return kstrdup(name, GFP_KERNEL); |
| 3717 | } |
| 3718 | |
| 3719 | /* |
| 3720 | * Simplify DAI link naming for single devices with multiple DAIs by removing |
| 3721 | * any ".-1" and using the DAI name (instead of device name). |
| 3722 | */ |
| 3723 | static inline char *fmt_multiple_name(struct device *dev, |
| 3724 | struct snd_soc_dai_driver *dai_drv) |
| 3725 | { |
| 3726 | if (dai_drv->name == NULL) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 3727 | dev_err(dev, |
| 3728 | "ASoC: error - multiple DAI %s registered with no name\n", |
| 3729 | dev_name(dev)); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3730 | return NULL; |
| 3731 | } |
| 3732 | |
| 3733 | return kstrdup(dai_drv->name, GFP_KERNEL); |
| 3734 | } |
| 3735 | |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3736 | /** |
| 3737 | * snd_soc_register_dai - Register a DAI with the ASoC core |
| 3738 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3739 | * @dai: DAI to register |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3740 | */ |
Kuninori Morimoto | f53179c0 | 2013-03-21 03:38:30 -0700 | [diff] [blame] | 3741 | static int snd_soc_register_dai(struct device *dev, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3742 | struct snd_soc_dai_driver *dai_drv) |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3743 | { |
Mark Brown | 054880f | 2012-04-09 17:29:19 +0100 | [diff] [blame] | 3744 | struct snd_soc_codec *codec; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3745 | struct snd_soc_dai *dai; |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3746 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 3747 | dev_dbg(dev, "ASoC: dai register %s\n", dev_name(dev)); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3748 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3749 | dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); |
| 3750 | if (dai == NULL) |
Lu Guanqun | a739362 | 2011-04-20 16:00:51 +0800 | [diff] [blame] | 3751 | return -ENOMEM; |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 3752 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3753 | /* create DAI component name */ |
| 3754 | dai->name = fmt_single_name(dev, &dai->id); |
| 3755 | if (dai->name == NULL) { |
| 3756 | kfree(dai); |
| 3757 | return -ENOMEM; |
| 3758 | } |
| 3759 | |
| 3760 | dai->dev = dev; |
| 3761 | dai->driver = dai_drv; |
Liam Girdwood | be09ad9 | 2012-03-07 11:47:41 +0000 | [diff] [blame] | 3762 | dai->dapm.dev = dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3763 | if (!dai->driver->ops) |
| 3764 | dai->driver->ops = &null_dai_ops; |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3765 | |
| 3766 | mutex_lock(&client_mutex); |
Mark Brown | 054880f | 2012-04-09 17:29:19 +0100 | [diff] [blame] | 3767 | |
| 3768 | list_for_each_entry(codec, &codec_list, list) { |
| 3769 | if (codec->dev == dev) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 3770 | dev_dbg(dev, "ASoC: Mapped DAI %s to CODEC %s\n", |
Mark Brown | 054880f | 2012-04-09 17:29:19 +0100 | [diff] [blame] | 3771 | dai->name, codec->name); |
| 3772 | dai->codec = codec; |
| 3773 | break; |
| 3774 | } |
| 3775 | } |
| 3776 | |
Peter Ujfalusi | 5f80008 | 2012-08-07 10:24:13 +0300 | [diff] [blame] | 3777 | if (!dai->codec) |
| 3778 | dai->dapm.idle_bias_off = 1; |
| 3779 | |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3780 | list_add(&dai->list, &dai_list); |
Mark Brown | 054880f | 2012-04-09 17:29:19 +0100 | [diff] [blame] | 3781 | |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3782 | mutex_unlock(&client_mutex); |
| 3783 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 3784 | dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3785 | |
| 3786 | return 0; |
| 3787 | } |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3788 | |
| 3789 | /** |
| 3790 | * snd_soc_unregister_dai - Unregister a DAI from the ASoC core |
| 3791 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3792 | * @dai: DAI to unregister |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3793 | */ |
Kuninori Morimoto | f53179c0 | 2013-03-21 03:38:30 -0700 | [diff] [blame] | 3794 | static void snd_soc_unregister_dai(struct device *dev) |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3795 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3796 | struct snd_soc_dai *dai; |
| 3797 | |
| 3798 | list_for_each_entry(dai, &dai_list, list) { |
| 3799 | if (dev == dai->dev) |
| 3800 | goto found; |
| 3801 | } |
| 3802 | return; |
| 3803 | |
| 3804 | found: |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3805 | mutex_lock(&client_mutex); |
| 3806 | list_del(&dai->list); |
| 3807 | mutex_unlock(&client_mutex); |
| 3808 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 3809 | dev_dbg(dev, "ASoC: Unregistered DAI '%s'\n", dai->name); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3810 | kfree(dai->name); |
| 3811 | kfree(dai); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3812 | } |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3813 | |
| 3814 | /** |
| 3815 | * snd_soc_register_dais - Register multiple DAIs with the ASoC core |
| 3816 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3817 | * @dai: Array of DAIs to register |
| 3818 | * @count: Number of DAIs |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3819 | */ |
Kuninori Morimoto | f53179c0 | 2013-03-21 03:38:30 -0700 | [diff] [blame] | 3820 | static int snd_soc_register_dais(struct device *dev, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3821 | struct snd_soc_dai_driver *dai_drv, size_t count) |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3822 | { |
Mark Brown | 054880f | 2012-04-09 17:29:19 +0100 | [diff] [blame] | 3823 | struct snd_soc_codec *codec; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3824 | struct snd_soc_dai *dai; |
| 3825 | int i, ret = 0; |
| 3826 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 3827 | dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3828 | |
| 3829 | for (i = 0; i < count; i++) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3830 | |
| 3831 | dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); |
Axel Lin | c46e007 | 2010-11-03 15:04:45 +0800 | [diff] [blame] | 3832 | if (dai == NULL) { |
| 3833 | ret = -ENOMEM; |
| 3834 | goto err; |
| 3835 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3836 | |
| 3837 | /* create DAI component name */ |
| 3838 | dai->name = fmt_multiple_name(dev, &dai_drv[i]); |
| 3839 | if (dai->name == NULL) { |
| 3840 | kfree(dai); |
| 3841 | ret = -EINVAL; |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3842 | goto err; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3843 | } |
| 3844 | |
| 3845 | dai->dev = dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3846 | dai->driver = &dai_drv[i]; |
Mark Brown | 0f9141c | 2010-10-12 15:43:21 +0100 | [diff] [blame] | 3847 | if (dai->driver->id) |
| 3848 | dai->id = dai->driver->id; |
| 3849 | else |
| 3850 | dai->id = i; |
Liam Girdwood | be09ad9 | 2012-03-07 11:47:41 +0000 | [diff] [blame] | 3851 | dai->dapm.dev = dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3852 | if (!dai->driver->ops) |
| 3853 | dai->driver->ops = &null_dai_ops; |
| 3854 | |
| 3855 | mutex_lock(&client_mutex); |
Mark Brown | 054880f | 2012-04-09 17:29:19 +0100 | [diff] [blame] | 3856 | |
| 3857 | list_for_each_entry(codec, &codec_list, list) { |
| 3858 | if (codec->dev == dev) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 3859 | dev_dbg(dev, |
| 3860 | "ASoC: Mapped DAI %s to CODEC %s\n", |
| 3861 | dai->name, codec->name); |
Mark Brown | 054880f | 2012-04-09 17:29:19 +0100 | [diff] [blame] | 3862 | dai->codec = codec; |
| 3863 | break; |
| 3864 | } |
| 3865 | } |
| 3866 | |
Peter Ujfalusi | 5f80008 | 2012-08-07 10:24:13 +0300 | [diff] [blame] | 3867 | if (!dai->codec) |
| 3868 | dai->dapm.idle_bias_off = 1; |
| 3869 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3870 | list_add(&dai->list, &dai_list); |
Mark Brown | 054880f | 2012-04-09 17:29:19 +0100 | [diff] [blame] | 3871 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3872 | mutex_unlock(&client_mutex); |
| 3873 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 3874 | dev_dbg(dai->dev, "ASoC: Registered DAI '%s'\n", dai->name); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3875 | } |
| 3876 | |
| 3877 | return 0; |
| 3878 | |
| 3879 | err: |
| 3880 | for (i--; i >= 0; i--) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3881 | snd_soc_unregister_dai(dev); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3882 | |
| 3883 | return ret; |
| 3884 | } |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3885 | |
| 3886 | /** |
| 3887 | * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core |
| 3888 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3889 | * @dai: Array of DAIs to unregister |
| 3890 | * @count: Number of DAIs |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3891 | */ |
Kuninori Morimoto | f53179c0 | 2013-03-21 03:38:30 -0700 | [diff] [blame] | 3892 | static void snd_soc_unregister_dais(struct device *dev, size_t count) |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3893 | { |
| 3894 | int i; |
| 3895 | |
| 3896 | for (i = 0; i < count; i++) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3897 | snd_soc_unregister_dai(dev); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3898 | } |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3899 | |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3900 | /** |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 3901 | * snd_soc_add_platform - Add a platform to the ASoC core |
| 3902 | * @dev: The parent device for the platform |
| 3903 | * @platform: The platform to add |
| 3904 | * @platform_driver: The driver for the platform |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3905 | */ |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 3906 | int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform, |
Lars-Peter Clausen | d79e57d | 2013-03-27 12:02:22 +0100 | [diff] [blame] | 3907 | const struct snd_soc_platform_driver *platform_drv) |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3908 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3909 | /* create platform component name */ |
| 3910 | platform->name = fmt_single_name(dev, &platform->id); |
| 3911 | if (platform->name == NULL) { |
| 3912 | kfree(platform); |
| 3913 | return -ENOMEM; |
| 3914 | } |
| 3915 | |
| 3916 | platform->dev = dev; |
| 3917 | platform->driver = platform_drv; |
Liam Girdwood | b795064 | 2011-07-04 22:10:52 +0100 | [diff] [blame] | 3918 | platform->dapm.dev = dev; |
| 3919 | platform->dapm.platform = platform; |
Liam Girdwood | 64a648c | 2011-07-25 11:15:15 +0100 | [diff] [blame] | 3920 | platform->dapm.stream_event = platform_drv->stream_event; |
Liam Girdwood | cc22d37 | 2012-03-06 18:16:18 +0000 | [diff] [blame] | 3921 | mutex_init(&platform->mutex); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3922 | |
| 3923 | mutex_lock(&client_mutex); |
| 3924 | list_add(&platform->list, &platform_list); |
| 3925 | mutex_unlock(&client_mutex); |
| 3926 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 3927 | dev_dbg(dev, "ASoC: Registered platform '%s'\n", platform->name); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3928 | |
| 3929 | return 0; |
| 3930 | } |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 3931 | EXPORT_SYMBOL_GPL(snd_soc_add_platform); |
| 3932 | |
| 3933 | /** |
| 3934 | * snd_soc_register_platform - Register a platform with the ASoC core |
| 3935 | * |
| 3936 | * @platform: platform to register |
| 3937 | */ |
| 3938 | int snd_soc_register_platform(struct device *dev, |
| 3939 | const struct snd_soc_platform_driver *platform_drv) |
| 3940 | { |
| 3941 | struct snd_soc_platform *platform; |
| 3942 | int ret; |
| 3943 | |
| 3944 | dev_dbg(dev, "ASoC: platform register %s\n", dev_name(dev)); |
| 3945 | |
| 3946 | platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL); |
| 3947 | if (platform == NULL) |
| 3948 | return -ENOMEM; |
| 3949 | |
| 3950 | ret = snd_soc_add_platform(dev, platform, platform_drv); |
| 3951 | if (ret) |
| 3952 | kfree(platform); |
| 3953 | |
| 3954 | return ret; |
| 3955 | } |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3956 | EXPORT_SYMBOL_GPL(snd_soc_register_platform); |
| 3957 | |
| 3958 | /** |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 3959 | * snd_soc_remove_platform - Remove a platform from the ASoC core |
| 3960 | * @platform: the platform to remove |
| 3961 | */ |
| 3962 | void snd_soc_remove_platform(struct snd_soc_platform *platform) |
| 3963 | { |
| 3964 | mutex_lock(&client_mutex); |
| 3965 | list_del(&platform->list); |
| 3966 | mutex_unlock(&client_mutex); |
| 3967 | |
| 3968 | dev_dbg(platform->dev, "ASoC: Unregistered platform '%s'\n", |
| 3969 | platform->name); |
| 3970 | kfree(platform->name); |
| 3971 | } |
| 3972 | EXPORT_SYMBOL_GPL(snd_soc_remove_platform); |
| 3973 | |
| 3974 | struct snd_soc_platform *snd_soc_lookup_platform(struct device *dev) |
| 3975 | { |
| 3976 | struct snd_soc_platform *platform; |
| 3977 | |
| 3978 | list_for_each_entry(platform, &platform_list, list) { |
| 3979 | if (dev == platform->dev) |
| 3980 | return platform; |
| 3981 | } |
| 3982 | |
| 3983 | return NULL; |
| 3984 | } |
| 3985 | EXPORT_SYMBOL_GPL(snd_soc_lookup_platform); |
| 3986 | |
| 3987 | /** |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3988 | * snd_soc_unregister_platform - Unregister a platform from the ASoC core |
| 3989 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3990 | * @platform: platform to unregister |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3991 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3992 | void snd_soc_unregister_platform(struct device *dev) |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3993 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3994 | struct snd_soc_platform *platform; |
| 3995 | |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 3996 | platform = snd_soc_lookup_platform(dev); |
| 3997 | if (!platform) |
| 3998 | return; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3999 | |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 4000 | snd_soc_remove_platform(platform); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4001 | kfree(platform); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 4002 | } |
| 4003 | EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); |
| 4004 | |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 4005 | static u64 codec_format_map[] = { |
| 4006 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE, |
| 4007 | SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE, |
| 4008 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE, |
| 4009 | SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, |
| 4010 | SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE, |
| 4011 | SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE, |
| 4012 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, |
| 4013 | SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, |
| 4014 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE, |
| 4015 | SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE, |
| 4016 | SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE, |
| 4017 | SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE, |
| 4018 | SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE, |
| 4019 | SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE, |
| 4020 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE |
| 4021 | | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE, |
| 4022 | }; |
| 4023 | |
| 4024 | /* Fix up the DAI formats for endianness: codecs don't actually see |
| 4025 | * the endianness of the data but we're using the CPU format |
| 4026 | * definitions which do need to include endianness so we ensure that |
| 4027 | * codec DAIs always have both big and little endian variants set. |
| 4028 | */ |
| 4029 | static void fixup_codec_formats(struct snd_soc_pcm_stream *stream) |
| 4030 | { |
| 4031 | int i; |
| 4032 | |
| 4033 | for (i = 0; i < ARRAY_SIZE(codec_format_map); i++) |
| 4034 | if (stream->formats & codec_format_map[i]) |
| 4035 | stream->formats |= codec_format_map[i]; |
| 4036 | } |
| 4037 | |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4038 | /** |
| 4039 | * snd_soc_register_codec - Register a codec with the ASoC core |
| 4040 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 4041 | * @codec: codec to register |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4042 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4043 | int snd_soc_register_codec(struct device *dev, |
Mark Brown | 001ae4c | 2010-12-02 16:21:08 +0000 | [diff] [blame] | 4044 | const struct snd_soc_codec_driver *codec_drv, |
| 4045 | struct snd_soc_dai_driver *dai_drv, |
| 4046 | int num_dai) |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4047 | { |
Dimitris Papastamos | 3335ddc | 2010-12-02 16:11:05 +0000 | [diff] [blame] | 4048 | size_t reg_size; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4049 | struct snd_soc_codec *codec; |
| 4050 | int ret, i; |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 4051 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4052 | dev_dbg(dev, "codec register %s\n", dev_name(dev)); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4053 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4054 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
| 4055 | if (codec == NULL) |
| 4056 | return -ENOMEM; |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4057 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4058 | /* create CODEC component name */ |
| 4059 | codec->name = fmt_single_name(dev, &codec->id); |
| 4060 | if (codec->name == NULL) { |
Kuninori Morimoto | f790b94 | 2013-02-25 00:40:09 -0800 | [diff] [blame] | 4061 | ret = -ENOMEM; |
| 4062 | goto fail_codec; |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 4063 | } |
| 4064 | |
Dimitris Papastamos | 23bbce3 | 2010-12-02 14:53:01 +0000 | [diff] [blame] | 4065 | if (codec_drv->compress_type) |
| 4066 | codec->compress_type = codec_drv->compress_type; |
| 4067 | else |
| 4068 | codec->compress_type = SND_SOC_FLAT_COMPRESSION; |
| 4069 | |
Mark Brown | c3acec2 | 2010-12-02 16:15:29 +0000 | [diff] [blame] | 4070 | codec->write = codec_drv->write; |
| 4071 | codec->read = codec_drv->read; |
Dimitris Papastamos | 1500b7b | 2011-01-13 12:20:38 +0000 | [diff] [blame] | 4072 | codec->volatile_register = codec_drv->volatile_register; |
| 4073 | codec->readable_register = codec_drv->readable_register; |
Dimitris Papastamos | 8020454 | 2011-03-24 13:45:17 +0000 | [diff] [blame] | 4074 | codec->writable_register = codec_drv->writable_register; |
Mark Brown | 5124e69 | 2012-02-08 13:20:50 +0000 | [diff] [blame] | 4075 | codec->ignore_pmdown_time = codec_drv->ignore_pmdown_time; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4076 | codec->dapm.bias_level = SND_SOC_BIAS_OFF; |
| 4077 | codec->dapm.dev = dev; |
| 4078 | codec->dapm.codec = codec; |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 4079 | codec->dapm.seq_notifier = codec_drv->seq_notifier; |
Liam Girdwood | 64a648c | 2011-07-25 11:15:15 +0100 | [diff] [blame] | 4080 | codec->dapm.stream_event = codec_drv->stream_event; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4081 | codec->dev = dev; |
| 4082 | codec->driver = codec_drv; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4083 | codec->num_dai = num_dai; |
| 4084 | mutex_init(&codec->mutex); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4085 | |
Dimitris Papastamos | 7a30a3d | 2010-11-11 10:04:57 +0000 | [diff] [blame] | 4086 | /* allocate CODEC register cache */ |
| 4087 | if (codec_drv->reg_cache_size && codec_drv->reg_word_size) { |
Dimitris Papastamos | 3335ddc | 2010-12-02 16:11:05 +0000 | [diff] [blame] | 4088 | reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size; |
Dimitris Papastamos | aea170a | 2011-01-12 10:38:58 +0000 | [diff] [blame] | 4089 | codec->reg_size = reg_size; |
Dimitris Papastamos | 3335ddc | 2010-12-02 16:11:05 +0000 | [diff] [blame] | 4090 | /* it is necessary to make a copy of the default register cache |
| 4091 | * because in the case of using a compression type that requires |
Bill Pemberton | f6e6574 | 2012-11-19 13:25:33 -0500 | [diff] [blame] | 4092 | * the default register cache to be marked as the |
Dimitris Papastamos | 3335ddc | 2010-12-02 16:11:05 +0000 | [diff] [blame] | 4093 | * kernel might have freed the array by the time we initialize |
| 4094 | * the cache. |
| 4095 | */ |
Dimitris Papastamos | 2aa8632 | 2011-01-10 10:10:56 +0000 | [diff] [blame] | 4096 | if (codec_drv->reg_cache_default) { |
| 4097 | codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default, |
| 4098 | reg_size, GFP_KERNEL); |
| 4099 | if (!codec->reg_def_copy) { |
| 4100 | ret = -ENOMEM; |
Kuninori Morimoto | f790b94 | 2013-02-25 00:40:09 -0800 | [diff] [blame] | 4101 | goto fail_codec_name; |
Dimitris Papastamos | 2aa8632 | 2011-01-10 10:10:56 +0000 | [diff] [blame] | 4102 | } |
Dimitris Papastamos | 7a30a3d | 2010-11-11 10:04:57 +0000 | [diff] [blame] | 4103 | } |
| 4104 | } |
| 4105 | |
Dimitris Papastamos | 1500b7b | 2011-01-13 12:20:38 +0000 | [diff] [blame] | 4106 | if (codec_drv->reg_access_size && codec_drv->reg_access_default) { |
| 4107 | if (!codec->volatile_register) |
| 4108 | codec->volatile_register = snd_soc_default_volatile_register; |
| 4109 | if (!codec->readable_register) |
| 4110 | codec->readable_register = snd_soc_default_readable_register; |
Dimitris Papastamos | 8020454 | 2011-03-24 13:45:17 +0000 | [diff] [blame] | 4111 | if (!codec->writable_register) |
| 4112 | codec->writable_register = snd_soc_default_writable_register; |
Dimitris Papastamos | 1500b7b | 2011-01-13 12:20:38 +0000 | [diff] [blame] | 4113 | } |
| 4114 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4115 | for (i = 0; i < num_dai; i++) { |
| 4116 | fixup_codec_formats(&dai_drv[i].playback); |
| 4117 | fixup_codec_formats(&dai_drv[i].capture); |
| 4118 | } |
| 4119 | |
Mark Brown | 054880f | 2012-04-09 17:29:19 +0100 | [diff] [blame] | 4120 | mutex_lock(&client_mutex); |
| 4121 | list_add(&codec->list, &codec_list); |
| 4122 | mutex_unlock(&client_mutex); |
| 4123 | |
Mark Brown | 26b01cc | 2010-08-18 20:20:55 +0100 | [diff] [blame] | 4124 | /* register any DAIs */ |
Kuninori Morimoto | 5acd7df | 2013-02-25 00:40:40 -0800 | [diff] [blame] | 4125 | ret = snd_soc_register_dais(dev, dai_drv, num_dai); |
| 4126 | if (ret < 0) { |
| 4127 | dev_err(codec->dev, "ASoC: Failed to regster DAIs: %d\n", ret); |
| 4128 | goto fail_codec_name; |
Mark Brown | 26b01cc | 2010-08-18 20:20:55 +0100 | [diff] [blame] | 4129 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4130 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 4131 | dev_dbg(codec->dev, "ASoC: Registered codec '%s'\n", codec->name); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4132 | return 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4133 | |
Kuninori Morimoto | f790b94 | 2013-02-25 00:40:09 -0800 | [diff] [blame] | 4134 | fail_codec_name: |
Kuninori Morimoto | e1328a8 | 2013-03-07 17:42:33 -0800 | [diff] [blame] | 4135 | mutex_lock(&client_mutex); |
| 4136 | list_del(&codec->list); |
| 4137 | mutex_unlock(&client_mutex); |
| 4138 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4139 | kfree(codec->name); |
Kuninori Morimoto | f790b94 | 2013-02-25 00:40:09 -0800 | [diff] [blame] | 4140 | fail_codec: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4141 | kfree(codec); |
| 4142 | return ret; |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4143 | } |
| 4144 | EXPORT_SYMBOL_GPL(snd_soc_register_codec); |
| 4145 | |
| 4146 | /** |
| 4147 | * snd_soc_unregister_codec - Unregister a codec from the ASoC core |
| 4148 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 4149 | * @codec: codec to unregister |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4150 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4151 | void snd_soc_unregister_codec(struct device *dev) |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4152 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4153 | struct snd_soc_codec *codec; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4154 | |
| 4155 | list_for_each_entry(codec, &codec_list, list) { |
| 4156 | if (dev == codec->dev) |
| 4157 | goto found; |
| 4158 | } |
| 4159 | return; |
| 4160 | |
| 4161 | found: |
Kuninori Morimoto | 5acd7df | 2013-02-25 00:40:40 -0800 | [diff] [blame] | 4162 | snd_soc_unregister_dais(dev, codec->num_dai); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4163 | |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4164 | mutex_lock(&client_mutex); |
| 4165 | list_del(&codec->list); |
| 4166 | mutex_unlock(&client_mutex); |
| 4167 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 4168 | dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", codec->name); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4169 | |
Dimitris Papastamos | 7a30a3d | 2010-11-11 10:04:57 +0000 | [diff] [blame] | 4170 | snd_soc_cache_exit(codec); |
Dimitris Papastamos | 3335ddc | 2010-12-02 16:11:05 +0000 | [diff] [blame] | 4171 | kfree(codec->reg_def_copy); |
Dimitris Papastamos | 1aafcd4 | 2010-10-21 13:19:45 +0100 | [diff] [blame] | 4172 | kfree(codec->name); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4173 | kfree(codec); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4174 | } |
| 4175 | EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); |
| 4176 | |
Kuninori Morimoto | 030e79f | 2013-03-11 18:27:21 -0700 | [diff] [blame] | 4177 | |
| 4178 | /** |
| 4179 | * snd_soc_register_component - Register a component with the ASoC core |
| 4180 | * |
| 4181 | */ |
| 4182 | int snd_soc_register_component(struct device *dev, |
| 4183 | const struct snd_soc_component_driver *cmpnt_drv, |
| 4184 | struct snd_soc_dai_driver *dai_drv, |
| 4185 | int num_dai) |
| 4186 | { |
| 4187 | struct snd_soc_component *cmpnt; |
| 4188 | int ret; |
| 4189 | |
| 4190 | dev_dbg(dev, "component register %s\n", dev_name(dev)); |
| 4191 | |
| 4192 | cmpnt = devm_kzalloc(dev, sizeof(*cmpnt), GFP_KERNEL); |
| 4193 | if (!cmpnt) { |
| 4194 | dev_err(dev, "ASoC: Failed to allocate memory\n"); |
| 4195 | return -ENOMEM; |
| 4196 | } |
| 4197 | |
| 4198 | cmpnt->name = fmt_single_name(dev, &cmpnt->id); |
| 4199 | if (!cmpnt->name) { |
| 4200 | dev_err(dev, "ASoC: Failed to simplifying name\n"); |
| 4201 | return -ENOMEM; |
| 4202 | } |
| 4203 | |
| 4204 | cmpnt->dev = dev; |
| 4205 | cmpnt->driver = cmpnt_drv; |
| 4206 | cmpnt->num_dai = num_dai; |
| 4207 | |
Kuninori Morimoto | a1422b8 | 2013-03-21 03:27:13 -0700 | [diff] [blame] | 4208 | /* |
| 4209 | * snd_soc_register_dai() uses fmt_single_name(), and |
| 4210 | * snd_soc_register_dais() uses fmt_multiple_name() |
| 4211 | * for dai->name which is used for name based matching |
| 4212 | */ |
| 4213 | if (1 == num_dai) |
| 4214 | ret = snd_soc_register_dai(dev, dai_drv); |
| 4215 | else |
| 4216 | ret = snd_soc_register_dais(dev, dai_drv, num_dai); |
Kuninori Morimoto | 030e79f | 2013-03-11 18:27:21 -0700 | [diff] [blame] | 4217 | if (ret < 0) { |
| 4218 | dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret); |
| 4219 | goto error_component_name; |
| 4220 | } |
| 4221 | |
| 4222 | mutex_lock(&client_mutex); |
| 4223 | list_add(&cmpnt->list, &component_list); |
| 4224 | mutex_unlock(&client_mutex); |
| 4225 | |
| 4226 | dev_dbg(cmpnt->dev, "ASoC: Registered component '%s'\n", cmpnt->name); |
| 4227 | |
| 4228 | return ret; |
| 4229 | |
| 4230 | error_component_name: |
| 4231 | kfree(cmpnt->name); |
| 4232 | |
| 4233 | return ret; |
| 4234 | } |
Stephen Warren | 2e1cc19 | 2013-03-26 16:38:19 -0600 | [diff] [blame] | 4235 | EXPORT_SYMBOL_GPL(snd_soc_register_component); |
Kuninori Morimoto | 030e79f | 2013-03-11 18:27:21 -0700 | [diff] [blame] | 4236 | |
| 4237 | /** |
| 4238 | * snd_soc_unregister_component - Unregister a component from the ASoC core |
| 4239 | * |
| 4240 | */ |
| 4241 | void snd_soc_unregister_component(struct device *dev) |
| 4242 | { |
| 4243 | struct snd_soc_component *cmpnt; |
| 4244 | |
| 4245 | list_for_each_entry(cmpnt, &component_list, list) { |
| 4246 | if (dev == cmpnt->dev) |
| 4247 | goto found; |
| 4248 | } |
| 4249 | return; |
| 4250 | |
| 4251 | found: |
| 4252 | snd_soc_unregister_dais(dev, cmpnt->num_dai); |
| 4253 | |
| 4254 | mutex_lock(&client_mutex); |
| 4255 | list_del(&cmpnt->list); |
| 4256 | mutex_unlock(&client_mutex); |
| 4257 | |
| 4258 | dev_dbg(dev, "ASoC: Unregistered component '%s'\n", cmpnt->name); |
| 4259 | kfree(cmpnt->name); |
| 4260 | } |
Stephen Warren | 2e1cc19 | 2013-03-26 16:38:19 -0600 | [diff] [blame] | 4261 | EXPORT_SYMBOL_GPL(snd_soc_unregister_component); |
Kuninori Morimoto | 030e79f | 2013-03-11 18:27:21 -0700 | [diff] [blame] | 4262 | |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 4263 | /* Retrieve a card's name from device tree */ |
| 4264 | int snd_soc_of_parse_card_name(struct snd_soc_card *card, |
| 4265 | const char *propname) |
| 4266 | { |
| 4267 | struct device_node *np = card->dev->of_node; |
| 4268 | int ret; |
| 4269 | |
| 4270 | ret = of_property_read_string_index(np, propname, 0, &card->name); |
| 4271 | /* |
| 4272 | * EINVAL means the property does not exist. This is fine providing |
| 4273 | * card->name was previously set, which is checked later in |
| 4274 | * snd_soc_register_card. |
| 4275 | */ |
| 4276 | if (ret < 0 && ret != -EINVAL) { |
| 4277 | dev_err(card->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 4278 | "ASoC: Property '%s' could not be read: %d\n", |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 4279 | propname, ret); |
| 4280 | return ret; |
| 4281 | } |
| 4282 | |
| 4283 | return 0; |
| 4284 | } |
| 4285 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name); |
| 4286 | |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 4287 | int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, |
| 4288 | const char *propname) |
| 4289 | { |
| 4290 | struct device_node *np = card->dev->of_node; |
| 4291 | int num_routes; |
| 4292 | struct snd_soc_dapm_route *routes; |
| 4293 | int i, ret; |
| 4294 | |
| 4295 | num_routes = of_property_count_strings(np, propname); |
Richard Zhao | c34ce32 | 2012-04-24 15:24:43 +0800 | [diff] [blame] | 4296 | if (num_routes < 0 || num_routes & 1) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 4297 | dev_err(card->dev, |
| 4298 | "ASoC: Property '%s' does not exist or its length is not even\n", |
| 4299 | propname); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 4300 | return -EINVAL; |
| 4301 | } |
| 4302 | num_routes /= 2; |
| 4303 | if (!num_routes) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 4304 | dev_err(card->dev, "ASoC: Property '%s's length is zero\n", |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 4305 | propname); |
| 4306 | return -EINVAL; |
| 4307 | } |
| 4308 | |
| 4309 | routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes), |
| 4310 | GFP_KERNEL); |
| 4311 | if (!routes) { |
| 4312 | dev_err(card->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 4313 | "ASoC: Could not allocate DAPM route table\n"); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 4314 | return -EINVAL; |
| 4315 | } |
| 4316 | |
| 4317 | for (i = 0; i < num_routes; i++) { |
| 4318 | ret = of_property_read_string_index(np, propname, |
| 4319 | 2 * i, &routes[i].sink); |
| 4320 | if (ret) { |
Mark Brown | c871bd0 | 2012-12-10 16:19:52 +0900 | [diff] [blame] | 4321 | dev_err(card->dev, |
| 4322 | "ASoC: Property '%s' index %d could not be read: %d\n", |
| 4323 | propname, 2 * i, ret); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 4324 | return -EINVAL; |
| 4325 | } |
| 4326 | ret = of_property_read_string_index(np, propname, |
| 4327 | (2 * i) + 1, &routes[i].source); |
| 4328 | if (ret) { |
| 4329 | dev_err(card->dev, |
Mark Brown | c871bd0 | 2012-12-10 16:19:52 +0900 | [diff] [blame] | 4330 | "ASoC: Property '%s' index %d could not be read: %d\n", |
| 4331 | propname, (2 * i) + 1, ret); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 4332 | return -EINVAL; |
| 4333 | } |
| 4334 | } |
| 4335 | |
| 4336 | card->num_dapm_routes = num_routes; |
| 4337 | card->dapm_routes = routes; |
| 4338 | |
| 4339 | return 0; |
| 4340 | } |
| 4341 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing); |
| 4342 | |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 4343 | unsigned int snd_soc_of_parse_daifmt(struct device_node *np, |
| 4344 | const char *prefix) |
| 4345 | { |
| 4346 | int ret, i; |
| 4347 | char prop[128]; |
| 4348 | unsigned int format = 0; |
| 4349 | int bit, frame; |
| 4350 | const char *str; |
| 4351 | struct { |
| 4352 | char *name; |
| 4353 | unsigned int val; |
| 4354 | } of_fmt_table[] = { |
| 4355 | { "i2s", SND_SOC_DAIFMT_I2S }, |
| 4356 | { "right_j", SND_SOC_DAIFMT_RIGHT_J }, |
| 4357 | { "left_j", SND_SOC_DAIFMT_LEFT_J }, |
| 4358 | { "dsp_a", SND_SOC_DAIFMT_DSP_A }, |
| 4359 | { "dsp_b", SND_SOC_DAIFMT_DSP_B }, |
| 4360 | { "ac97", SND_SOC_DAIFMT_AC97 }, |
| 4361 | { "pdm", SND_SOC_DAIFMT_PDM}, |
| 4362 | { "msb", SND_SOC_DAIFMT_MSB }, |
| 4363 | { "lsb", SND_SOC_DAIFMT_LSB }, |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 4364 | }; |
| 4365 | |
| 4366 | if (!prefix) |
| 4367 | prefix = ""; |
| 4368 | |
| 4369 | /* |
| 4370 | * check "[prefix]format = xxx" |
| 4371 | * SND_SOC_DAIFMT_FORMAT_MASK area |
| 4372 | */ |
| 4373 | snprintf(prop, sizeof(prop), "%sformat", prefix); |
| 4374 | ret = of_property_read_string(np, prop, &str); |
| 4375 | if (ret == 0) { |
| 4376 | for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) { |
| 4377 | if (strcmp(str, of_fmt_table[i].name) == 0) { |
| 4378 | format |= of_fmt_table[i].val; |
| 4379 | break; |
| 4380 | } |
| 4381 | } |
| 4382 | } |
| 4383 | |
| 4384 | /* |
Kuninori Morimoto | 8c2d6a9 | 2013-01-29 21:03:36 -0800 | [diff] [blame] | 4385 | * check "[prefix]continuous-clock" |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 4386 | * SND_SOC_DAIFMT_CLOCK_MASK area |
| 4387 | */ |
Kuninori Morimoto | 8c2d6a9 | 2013-01-29 21:03:36 -0800 | [diff] [blame] | 4388 | snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix); |
| 4389 | if (of_get_property(np, prop, NULL)) |
| 4390 | format |= SND_SOC_DAIFMT_CONT; |
| 4391 | else |
| 4392 | format |= SND_SOC_DAIFMT_GATED; |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 4393 | |
| 4394 | /* |
| 4395 | * check "[prefix]bitclock-inversion" |
| 4396 | * check "[prefix]frame-inversion" |
| 4397 | * SND_SOC_DAIFMT_INV_MASK area |
| 4398 | */ |
| 4399 | snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix); |
| 4400 | bit = !!of_get_property(np, prop, NULL); |
| 4401 | |
| 4402 | snprintf(prop, sizeof(prop), "%sframe-inversion", prefix); |
| 4403 | frame = !!of_get_property(np, prop, NULL); |
| 4404 | |
| 4405 | switch ((bit << 4) + frame) { |
| 4406 | case 0x11: |
| 4407 | format |= SND_SOC_DAIFMT_IB_IF; |
| 4408 | break; |
| 4409 | case 0x10: |
| 4410 | format |= SND_SOC_DAIFMT_IB_NF; |
| 4411 | break; |
| 4412 | case 0x01: |
| 4413 | format |= SND_SOC_DAIFMT_NB_IF; |
| 4414 | break; |
| 4415 | default: |
| 4416 | /* SND_SOC_DAIFMT_NB_NF is default */ |
| 4417 | break; |
| 4418 | } |
| 4419 | |
| 4420 | /* |
| 4421 | * check "[prefix]bitclock-master" |
| 4422 | * check "[prefix]frame-master" |
| 4423 | * SND_SOC_DAIFMT_MASTER_MASK area |
| 4424 | */ |
| 4425 | snprintf(prop, sizeof(prop), "%sbitclock-master", prefix); |
| 4426 | bit = !!of_get_property(np, prop, NULL); |
| 4427 | |
| 4428 | snprintf(prop, sizeof(prop), "%sframe-master", prefix); |
| 4429 | frame = !!of_get_property(np, prop, NULL); |
| 4430 | |
| 4431 | switch ((bit << 4) + frame) { |
| 4432 | case 0x11: |
| 4433 | format |= SND_SOC_DAIFMT_CBM_CFM; |
| 4434 | break; |
| 4435 | case 0x10: |
| 4436 | format |= SND_SOC_DAIFMT_CBM_CFS; |
| 4437 | break; |
| 4438 | case 0x01: |
| 4439 | format |= SND_SOC_DAIFMT_CBS_CFM; |
| 4440 | break; |
| 4441 | default: |
| 4442 | format |= SND_SOC_DAIFMT_CBS_CFS; |
| 4443 | break; |
| 4444 | } |
| 4445 | |
| 4446 | return format; |
| 4447 | } |
| 4448 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt); |
| 4449 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 4450 | static int __init snd_soc_init(void) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 4451 | { |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 4452 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 4453 | snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL); |
| 4454 | if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) { |
Fabio Estevam | 0837fc6 | 2012-02-17 19:40:38 -0200 | [diff] [blame] | 4455 | pr_warn("ASoC: Failed to create debugfs directory\n"); |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 4456 | snd_soc_debugfs_root = NULL; |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 4457 | } |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 4458 | |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 4459 | if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL, |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 4460 | &codec_list_fops)) |
| 4461 | pr_warn("ASoC: Failed to create CODEC list debugfs file\n"); |
| 4462 | |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 4463 | if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL, |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 4464 | &dai_list_fops)) |
| 4465 | pr_warn("ASoC: Failed to create DAI list debugfs file\n"); |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 4466 | |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 4467 | if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL, |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 4468 | &platform_list_fops)) |
| 4469 | pr_warn("ASoC: Failed to create platform list debugfs file\n"); |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 4470 | #endif |
| 4471 | |
Mark Brown | fb25789 | 2011-04-28 10:57:54 +0100 | [diff] [blame] | 4472 | snd_soc_util_init(); |
| 4473 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 4474 | return platform_driver_register(&soc_driver); |
| 4475 | } |
Mark Brown | 4abe8e1 | 2010-10-12 17:41:03 +0100 | [diff] [blame] | 4476 | module_init(snd_soc_init); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 4477 | |
Mark Brown | 7d8c16a | 2008-11-30 22:11:24 +0000 | [diff] [blame] | 4478 | static void __exit snd_soc_exit(void) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 4479 | { |
Mark Brown | fb25789 | 2011-04-28 10:57:54 +0100 | [diff] [blame] | 4480 | snd_soc_util_exit(); |
| 4481 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 4482 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 4483 | debugfs_remove_recursive(snd_soc_debugfs_root); |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 4484 | #endif |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 4485 | platform_driver_unregister(&soc_driver); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 4486 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 4487 | module_exit(snd_soc_exit); |
| 4488 | |
| 4489 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 4490 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 4491 | MODULE_DESCRIPTION("ALSA SoC Core"); |
| 4492 | MODULE_LICENSE("GPL"); |
Kay Sievers | 8b45a20 | 2008-04-14 13:33:36 +0200 | [diff] [blame] | 4493 | MODULE_ALIAS("platform:soc-audio"); |