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