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