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