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