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