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