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