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