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