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