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