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> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 37 | #include <sound/core.h> |
Mark Brown | 3028eb8 | 2010-12-05 12:22:46 +0000 | [diff] [blame] | 38 | #include <sound/jack.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 39 | #include <sound/pcm.h> |
| 40 | #include <sound/pcm_params.h> |
| 41 | #include <sound/soc.h> |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 42 | #include <sound/soc-dpcm.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 43 | #include <sound/initval.h> |
| 44 | |
Mark Brown | a8b1d34 | 2010-11-03 18:05:58 -0400 | [diff] [blame] | 45 | #define CREATE_TRACE_POINTS |
| 46 | #include <trace/events/asoc.h> |
| 47 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 48 | #define NAME_SIZE 32 |
| 49 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 50 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 51 | struct dentry *snd_soc_debugfs_root; |
| 52 | EXPORT_SYMBOL_GPL(snd_soc_debugfs_root); |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 53 | #endif |
| 54 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 55 | static DEFINE_MUTEX(client_mutex); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 56 | static LIST_HEAD(platform_list); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 57 | static LIST_HEAD(codec_list); |
Kuninori Morimoto | 030e79f | 2013-03-11 18:27:21 -0700 | [diff] [blame] | 58 | static LIST_HEAD(component_list); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 59 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 60 | /* |
| 61 | * This is a timeout to do a DAPM powerdown after a stream is closed(). |
| 62 | * It can be used to eliminate pops between different playback streams, e.g. |
| 63 | * between two audio tracks. |
| 64 | */ |
| 65 | static int pmdown_time = 5000; |
| 66 | module_param(pmdown_time, int, 0); |
| 67 | MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)"); |
| 68 | |
Dimitris Papastamos | 2bc9a81 | 2011-02-01 12:24:08 +0000 | [diff] [blame] | 69 | /* returns the minimum number of bytes needed to represent |
| 70 | * a particular given value */ |
| 71 | static int min_bytes_needed(unsigned long val) |
| 72 | { |
| 73 | int c = 0; |
| 74 | int i; |
| 75 | |
| 76 | for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c) |
| 77 | if (val & (1UL << i)) |
| 78 | break; |
| 79 | c = (sizeof val * 8) - c; |
| 80 | if (!c || (c % 8)) |
| 81 | c = (c + 8) / 8; |
| 82 | else |
| 83 | c /= 8; |
| 84 | return c; |
| 85 | } |
| 86 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 87 | /* fill buf which is 'len' bytes with a formatted |
| 88 | * string of the form 'reg: value\n' */ |
| 89 | static int format_register_str(struct snd_soc_codec *codec, |
| 90 | unsigned int reg, char *buf, size_t len) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 91 | { |
Stephen Warren | 00b317a | 2011-04-01 14:50:44 -0600 | [diff] [blame] | 92 | int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; |
| 93 | int regsize = codec->driver->reg_word_size * 2; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 94 | int ret; |
| 95 | char tmpbuf[len + 1]; |
| 96 | char regbuf[regsize + 1]; |
| 97 | |
| 98 | /* since tmpbuf is allocated on the stack, warn the callers if they |
| 99 | * try to abuse this function */ |
| 100 | WARN_ON(len > 63); |
| 101 | |
| 102 | /* +2 for ': ' and + 1 for '\n' */ |
| 103 | if (wordsize + regsize + 2 + 1 != len) |
| 104 | return -EINVAL; |
| 105 | |
Mark Brown | 25032c1 | 2011-08-01 13:52:48 +0900 | [diff] [blame] | 106 | ret = snd_soc_read(codec, reg); |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 107 | if (ret < 0) { |
| 108 | memset(regbuf, 'X', regsize); |
| 109 | regbuf[regsize] = '\0'; |
| 110 | } else { |
| 111 | snprintf(regbuf, regsize + 1, "%.*x", regsize, ret); |
| 112 | } |
| 113 | |
| 114 | /* prepare the buffer */ |
| 115 | snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf); |
| 116 | /* copy it back to the caller without the '\0' */ |
| 117 | memcpy(buf, tmpbuf, len); |
| 118 | |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | /* codec register dump */ |
| 123 | static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf, |
| 124 | size_t count, loff_t pos) |
| 125 | { |
| 126 | int i, step = 1; |
Dimitris Papastamos | 2bc9a81 | 2011-02-01 12:24:08 +0000 | [diff] [blame] | 127 | int wordsize, regsize; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 128 | int len; |
| 129 | size_t total = 0; |
| 130 | loff_t p = 0; |
Dimitris Papastamos | 2bc9a81 | 2011-02-01 12:24:08 +0000 | [diff] [blame] | 131 | |
Stephen Warren | 00b317a | 2011-04-01 14:50:44 -0600 | [diff] [blame] | 132 | wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; |
| 133 | regsize = codec->driver->reg_word_size * 2; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 134 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 135 | len = wordsize + regsize + 2 + 1; |
| 136 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 137 | if (!codec->driver->reg_cache_size) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 138 | return 0; |
| 139 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 140 | if (codec->driver->reg_cache_step) |
| 141 | step = codec->driver->reg_cache_step; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 142 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 143 | for (i = 0; i < codec->driver->reg_cache_size; i += step) { |
Lars-Peter Clausen | 20a0ec2 | 2014-03-18 09:02:09 +0100 | [diff] [blame] | 144 | /* only support larger than PAGE_SIZE bytes debugfs |
| 145 | * entries for the default case */ |
| 146 | if (p >= pos) { |
| 147 | if (total + len >= count - 1) |
| 148 | break; |
| 149 | format_register_str(codec, i, buf + total, len); |
| 150 | total += len; |
Mark Brown | 5164d74 | 2010-07-14 16:14:33 +0100 | [diff] [blame] | 151 | } |
Lars-Peter Clausen | 20a0ec2 | 2014-03-18 09:02:09 +0100 | [diff] [blame] | 152 | p += len; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 155 | total = min(total, count - 1); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 156 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 157 | return total; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 158 | } |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 159 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 160 | static ssize_t codec_reg_show(struct device *dev, |
| 161 | struct device_attribute *attr, char *buf) |
| 162 | { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 163 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 164 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 165 | return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL); |
| 169 | |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 170 | static ssize_t pmdown_time_show(struct device *dev, |
| 171 | struct device_attribute *attr, char *buf) |
| 172 | { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 173 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 174 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 175 | return sprintf(buf, "%ld\n", rtd->pmdown_time); |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static ssize_t pmdown_time_set(struct device *dev, |
| 179 | struct device_attribute *attr, |
| 180 | const char *buf, size_t count) |
| 181 | { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 182 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
Mark Brown | c593b52 | 2010-10-27 20:11:17 -0700 | [diff] [blame] | 183 | int ret; |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 184 | |
Jingoo Han | b785a49 | 2013-07-19 16:24:59 +0900 | [diff] [blame] | 185 | ret = kstrtol(buf, 10, &rtd->pmdown_time); |
Mark Brown | c593b52 | 2010-10-27 20:11:17 -0700 | [diff] [blame] | 186 | if (ret) |
| 187 | return ret; |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 188 | |
| 189 | return count; |
| 190 | } |
| 191 | |
| 192 | static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set); |
| 193 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 194 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 195 | 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] | 196 | size_t count, loff_t *ppos) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 197 | { |
| 198 | ssize_t ret; |
| 199 | struct snd_soc_codec *codec = file->private_data; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 200 | char *buf; |
| 201 | |
| 202 | if (*ppos < 0 || !count) |
| 203 | return -EINVAL; |
| 204 | |
| 205 | buf = kmalloc(count, GFP_KERNEL); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 206 | if (!buf) |
| 207 | return -ENOMEM; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 208 | |
| 209 | ret = soc_codec_reg_show(codec, buf, count, *ppos); |
| 210 | if (ret >= 0) { |
| 211 | if (copy_to_user(user_buf, buf, ret)) { |
| 212 | kfree(buf); |
| 213 | return -EFAULT; |
| 214 | } |
| 215 | *ppos += ret; |
| 216 | } |
| 217 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 218 | kfree(buf); |
| 219 | return ret; |
| 220 | } |
| 221 | |
| 222 | static ssize_t codec_reg_write_file(struct file *file, |
| 223 | const char __user *user_buf, size_t count, loff_t *ppos) |
| 224 | { |
| 225 | char buf[32]; |
Stephen Boyd | 34e268d | 2011-05-12 16:50:10 -0700 | [diff] [blame] | 226 | size_t buf_size; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 227 | char *start = buf; |
| 228 | unsigned long reg, value; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 229 | struct snd_soc_codec *codec = file->private_data; |
Jingoo Han | b785a49 | 2013-07-19 16:24:59 +0900 | [diff] [blame] | 230 | int ret; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 231 | |
| 232 | buf_size = min(count, (sizeof(buf)-1)); |
| 233 | if (copy_from_user(buf, user_buf, buf_size)) |
| 234 | return -EFAULT; |
| 235 | buf[buf_size] = 0; |
| 236 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 237 | while (*start == ' ') |
| 238 | start++; |
| 239 | reg = simple_strtoul(start, &start, 16); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 240 | while (*start == ' ') |
| 241 | start++; |
Jingoo Han | b785a49 | 2013-07-19 16:24:59 +0900 | [diff] [blame] | 242 | ret = kstrtoul(start, 16, &value); |
| 243 | if (ret) |
| 244 | return ret; |
Mark Brown | 0d51a9c | 2011-01-06 16:04:57 +0000 | [diff] [blame] | 245 | |
| 246 | /* Userspace has been fiddling around behind the kernel's back */ |
Rusty Russell | 373d4d0 | 2013-01-21 17:17:39 +1030 | [diff] [blame] | 247 | add_taint(TAINT_USER, LOCKDEP_NOW_UNRELIABLE); |
Mark Brown | 0d51a9c | 2011-01-06 16:04:57 +0000 | [diff] [blame] | 248 | |
Dimitris Papastamos | e4f078d | 2010-12-07 16:30:38 +0000 | [diff] [blame] | 249 | snd_soc_write(codec, reg, value); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 250 | return buf_size; |
| 251 | } |
| 252 | |
| 253 | static const struct file_operations codec_reg_fops = { |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 254 | .open = simple_open, |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 255 | .read = codec_reg_read_file, |
| 256 | .write = codec_reg_write_file, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 257 | .llseek = default_llseek, |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 258 | }; |
| 259 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 260 | static void soc_init_component_debugfs(struct snd_soc_component *component) |
Russell King | e73f3de | 2014-06-26 15:22:50 +0100 | [diff] [blame] | 261 | { |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 262 | if (component->debugfs_prefix) { |
| 263 | char *name; |
Russell King | e73f3de | 2014-06-26 15:22:50 +0100 | [diff] [blame] | 264 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 265 | name = kasprintf(GFP_KERNEL, "%s:%s", |
| 266 | component->debugfs_prefix, component->name); |
| 267 | if (name) { |
| 268 | component->debugfs_root = debugfs_create_dir(name, |
| 269 | component->card->debugfs_card_root); |
| 270 | kfree(name); |
| 271 | } |
| 272 | } else { |
| 273 | component->debugfs_root = debugfs_create_dir(component->name, |
| 274 | component->card->debugfs_card_root); |
| 275 | } |
Russell King | e73f3de | 2014-06-26 15:22:50 +0100 | [diff] [blame] | 276 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 277 | if (!component->debugfs_root) { |
| 278 | dev_warn(component->dev, |
| 279 | "ASoC: Failed to create component debugfs directory\n"); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 280 | return; |
| 281 | } |
| 282 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 283 | snd_soc_dapm_debugfs_init(snd_soc_component_get_dapm(component), |
| 284 | component->debugfs_root); |
| 285 | |
| 286 | if (component->init_debugfs) |
| 287 | component->init_debugfs(component); |
| 288 | } |
| 289 | |
| 290 | static void soc_cleanup_component_debugfs(struct snd_soc_component *component) |
| 291 | { |
| 292 | debugfs_remove_recursive(component->debugfs_root); |
| 293 | } |
| 294 | |
| 295 | static void soc_init_codec_debugfs(struct snd_soc_component *component) |
| 296 | { |
| 297 | struct snd_soc_codec *codec = snd_soc_component_to_codec(component); |
| 298 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 299 | codec->debugfs_reg = debugfs_create_file("codec_reg", 0644, |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 300 | codec->component.debugfs_root, |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 301 | codec, &codec_reg_fops); |
| 302 | if (!codec->debugfs_reg) |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 303 | dev_warn(codec->dev, |
| 304 | "ASoC: Failed to create codec register debugfs file\n"); |
Sebastien Guiriec | 731f1ab | 2012-02-15 15:25:31 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 307 | static ssize_t codec_list_read_file(struct file *file, char __user *user_buf, |
| 308 | size_t count, loff_t *ppos) |
| 309 | { |
| 310 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 311 | ssize_t len, ret = 0; |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 312 | struct snd_soc_codec *codec; |
| 313 | |
| 314 | if (!buf) |
| 315 | return -ENOMEM; |
| 316 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 317 | list_for_each_entry(codec, &codec_list, list) { |
| 318 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 319 | codec->component.name); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 320 | if (len >= 0) |
| 321 | ret += len; |
| 322 | if (ret > PAGE_SIZE) { |
| 323 | ret = PAGE_SIZE; |
| 324 | break; |
| 325 | } |
| 326 | } |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 327 | |
| 328 | if (ret >= 0) |
| 329 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 330 | |
| 331 | kfree(buf); |
| 332 | |
| 333 | return ret; |
| 334 | } |
| 335 | |
| 336 | static const struct file_operations codec_list_fops = { |
| 337 | .read = codec_list_read_file, |
| 338 | .llseek = default_llseek,/* read accesses f_pos */ |
| 339 | }; |
| 340 | |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 341 | static ssize_t dai_list_read_file(struct file *file, char __user *user_buf, |
| 342 | size_t count, loff_t *ppos) |
| 343 | { |
| 344 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 345 | ssize_t len, ret = 0; |
Lars-Peter Clausen | 1438c2f | 2014-03-09 17:41:47 +0100 | [diff] [blame] | 346 | struct snd_soc_component *component; |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 347 | struct snd_soc_dai *dai; |
| 348 | |
| 349 | if (!buf) |
| 350 | return -ENOMEM; |
| 351 | |
Lars-Peter Clausen | 1438c2f | 2014-03-09 17:41:47 +0100 | [diff] [blame] | 352 | list_for_each_entry(component, &component_list, list) { |
| 353 | list_for_each_entry(dai, &component->dai_list, list) { |
| 354 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", |
| 355 | dai->name); |
| 356 | if (len >= 0) |
| 357 | ret += len; |
| 358 | if (ret > PAGE_SIZE) { |
| 359 | ret = PAGE_SIZE; |
| 360 | break; |
| 361 | } |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 362 | } |
| 363 | } |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 364 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 365 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 366 | |
| 367 | kfree(buf); |
| 368 | |
| 369 | return ret; |
| 370 | } |
| 371 | |
| 372 | static const struct file_operations dai_list_fops = { |
| 373 | .read = dai_list_read_file, |
| 374 | .llseek = default_llseek,/* read accesses f_pos */ |
| 375 | }; |
| 376 | |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 377 | static ssize_t platform_list_read_file(struct file *file, |
| 378 | char __user *user_buf, |
| 379 | size_t count, loff_t *ppos) |
| 380 | { |
| 381 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 382 | ssize_t len, ret = 0; |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 383 | struct snd_soc_platform *platform; |
| 384 | |
| 385 | if (!buf) |
| 386 | return -ENOMEM; |
| 387 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 388 | list_for_each_entry(platform, &platform_list, list) { |
| 389 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 390 | platform->component.name); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 391 | if (len >= 0) |
| 392 | ret += len; |
| 393 | if (ret > PAGE_SIZE) { |
| 394 | ret = PAGE_SIZE; |
| 395 | break; |
| 396 | } |
| 397 | } |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 398 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 399 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 400 | |
| 401 | kfree(buf); |
| 402 | |
| 403 | return ret; |
| 404 | } |
| 405 | |
| 406 | static const struct file_operations platform_list_fops = { |
| 407 | .read = platform_list_read_file, |
| 408 | .llseek = default_llseek,/* read accesses f_pos */ |
| 409 | }; |
| 410 | |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 411 | static void soc_init_card_debugfs(struct snd_soc_card *card) |
| 412 | { |
| 413 | card->debugfs_card_root = debugfs_create_dir(card->name, |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 414 | snd_soc_debugfs_root); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 415 | if (!card->debugfs_card_root) { |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 416 | dev_warn(card->dev, |
Lothar Waßmann | 7c08be8 | 2011-12-09 14:16:29 +0100 | [diff] [blame] | 417 | "ASoC: Failed to create card debugfs directory\n"); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 418 | return; |
| 419 | } |
| 420 | |
| 421 | card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644, |
| 422 | card->debugfs_card_root, |
| 423 | &card->pop_time); |
| 424 | if (!card->debugfs_pop_time) |
| 425 | dev_warn(card->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 426 | "ASoC: Failed to create pop time debugfs file\n"); |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | static void soc_cleanup_card_debugfs(struct snd_soc_card *card) |
| 430 | { |
| 431 | debugfs_remove_recursive(card->debugfs_card_root); |
| 432 | } |
| 433 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 434 | #else |
| 435 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 436 | #define soc_init_codec_debugfs NULL |
| 437 | |
| 438 | static inline void soc_init_component_debugfs( |
| 439 | struct snd_soc_component *component) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 440 | { |
| 441 | } |
| 442 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 443 | static inline void soc_cleanup_component_debugfs( |
| 444 | struct snd_soc_component *component) |
Sebastien Guiriec | 731f1ab | 2012-02-15 15:25:31 +0000 | [diff] [blame] | 445 | { |
| 446 | } |
| 447 | |
Axel Lin | b95fccb | 2010-11-09 17:06:44 +0800 | [diff] [blame] | 448 | static inline void soc_init_card_debugfs(struct snd_soc_card *card) |
| 449 | { |
| 450 | } |
| 451 | |
| 452 | static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card) |
| 453 | { |
| 454 | } |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 455 | #endif |
| 456 | |
Liam Girdwood | 47c88ff | 2012-04-25 12:12:53 +0100 | [diff] [blame] | 457 | struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card, |
| 458 | const char *dai_link, int stream) |
| 459 | { |
| 460 | int i; |
| 461 | |
| 462 | for (i = 0; i < card->num_links; i++) { |
| 463 | if (card->rtd[i].dai_link->no_pcm && |
| 464 | !strcmp(card->rtd[i].dai_link->name, dai_link)) |
| 465 | return card->rtd[i].pcm->streams[stream].substream; |
| 466 | } |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 467 | 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] | 468 | return NULL; |
| 469 | } |
| 470 | EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream); |
| 471 | |
| 472 | struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card, |
| 473 | const char *dai_link) |
| 474 | { |
| 475 | int i; |
| 476 | |
| 477 | for (i = 0; i < card->num_links; i++) { |
| 478 | if (!strcmp(card->rtd[i].dai_link->name, dai_link)) |
| 479 | return &card->rtd[i]; |
| 480 | } |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 481 | 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] | 482 | return NULL; |
| 483 | } |
| 484 | EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime); |
| 485 | |
Richard Fitzgerald | 9d58a07 | 2013-08-05 13:17:28 +0100 | [diff] [blame] | 486 | static void codec2codec_close_delayed_work(struct work_struct *work) |
| 487 | { |
| 488 | /* Currently nothing to do for c2c links |
| 489 | * Since c2c links are internal nodes in the DAPM graph and |
| 490 | * don't interface with the outside world or application layer |
| 491 | * we don't have to do any special handling on close. |
| 492 | */ |
| 493 | } |
| 494 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 495 | #ifdef CONFIG_PM_SLEEP |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 496 | /* powers down audio subsystem for suspend */ |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 497 | int snd_soc_suspend(struct device *dev) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 498 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 499 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 500 | struct snd_soc_codec *codec; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 501 | int i, j; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 502 | |
Lars-Peter Clausen | c5599b8 | 2014-08-19 15:51:30 +0200 | [diff] [blame] | 503 | /* If the card is not initialized yet there is nothing to do */ |
| 504 | if (!card->instantiated) |
Daniel Mack | e3509ff | 2009-06-03 17:44:49 +0200 | [diff] [blame] | 505 | return 0; |
| 506 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 507 | /* Due to the resume being scheduled into a workqueue we could |
| 508 | * suspend before that's finished - wait for it to complete. |
| 509 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 510 | snd_power_lock(card->snd_card); |
| 511 | snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0); |
| 512 | snd_power_unlock(card->snd_card); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 513 | |
| 514 | /* we're going to block userspace touching us until resume completes */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 515 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 516 | |
Mark Brown | a00f90f | 2010-12-02 16:24:24 +0000 | [diff] [blame] | 517 | /* mute any active DACs */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 518 | for (i = 0; i < card->num_rtd; i++) { |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 519 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 520 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 521 | continue; |
| 522 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 523 | for (j = 0; j < card->rtd[i].num_codecs; j++) { |
| 524 | struct snd_soc_dai *dai = card->rtd[i].codec_dais[j]; |
| 525 | struct snd_soc_dai_driver *drv = dai->driver; |
| 526 | |
| 527 | if (drv->ops->digital_mute && dai->playback_active) |
| 528 | drv->ops->digital_mute(dai, 1); |
| 529 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 530 | } |
| 531 | |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 532 | /* suspend all pcms */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 533 | for (i = 0; i < card->num_rtd; i++) { |
| 534 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 535 | continue; |
| 536 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 537 | snd_pcm_suspend_all(card->rtd[i].pcm); |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 538 | } |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 539 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 540 | if (card->suspend_pre) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 541 | card->suspend_pre(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 542 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 543 | for (i = 0; i < card->num_rtd; i++) { |
| 544 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 545 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 546 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 547 | continue; |
| 548 | |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 549 | if (cpu_dai->driver->suspend && !cpu_dai->driver->bus_control) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 550 | cpu_dai->driver->suspend(cpu_dai); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 551 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 552 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 553 | /* close any waiting streams and save state */ |
| 554 | for (i = 0; i < card->num_rtd; i++) { |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 555 | struct snd_soc_dai **codec_dais = card->rtd[i].codec_dais; |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 556 | flush_delayed_work(&card->rtd[i].delayed_work); |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 557 | for (j = 0; j < card->rtd[i].num_codecs; j++) { |
| 558 | codec_dais[j]->codec->dapm.suspend_bias_level = |
| 559 | codec_dais[j]->codec->dapm.bias_level; |
| 560 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 561 | } |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 562 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 563 | for (i = 0; i < card->num_rtd; i++) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 564 | |
| 565 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 566 | continue; |
| 567 | |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 568 | snd_soc_dapm_stream_event(&card->rtd[i], |
| 569 | SNDRV_PCM_STREAM_PLAYBACK, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 570 | SND_SOC_DAPM_STREAM_SUSPEND); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 571 | |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 572 | snd_soc_dapm_stream_event(&card->rtd[i], |
| 573 | SNDRV_PCM_STREAM_CAPTURE, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 574 | SND_SOC_DAPM_STREAM_SUSPEND); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Lars-Peter Clausen | 8be4da2 | 2014-10-25 17:42:01 +0200 | [diff] [blame] | 577 | /* Recheck all endpoints too, their state is affected by suspend */ |
| 578 | dapm_mark_endpoints_dirty(card); |
Mark Brown | e2d32ff | 2012-08-31 17:38:32 -0700 | [diff] [blame] | 579 | snd_soc_dapm_sync(&card->dapm); |
| 580 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 581 | /* suspend all CODECs */ |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 582 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 583 | /* If there are paths active then the CODEC will be held with |
| 584 | * bias _ON and should not be suspended. */ |
Lars-Peter Clausen | a809329 | 2014-09-04 19:44:07 +0200 | [diff] [blame] | 585 | if (!codec->suspended) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 586 | switch (codec->dapm.bias_level) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 587 | case SND_SOC_BIAS_STANDBY: |
Mark Brown | 125a25d | 2012-01-31 15:49:10 +0000 | [diff] [blame] | 588 | /* |
| 589 | * If the CODEC is capable of idle |
| 590 | * bias off then being in STANDBY |
| 591 | * means it's doing something, |
| 592 | * otherwise fall through. |
| 593 | */ |
| 594 | if (codec->dapm.idle_bias_off) { |
| 595 | dev_dbg(codec->dev, |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 596 | "ASoC: idle_bias_off CODEC on over suspend\n"); |
Mark Brown | 125a25d | 2012-01-31 15:49:10 +0000 | [diff] [blame] | 597 | break; |
| 598 | } |
Lars-Peter Clausen | a809329 | 2014-09-04 19:44:07 +0200 | [diff] [blame] | 599 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 600 | case SND_SOC_BIAS_OFF: |
Lars-Peter Clausen | a809329 | 2014-09-04 19:44:07 +0200 | [diff] [blame] | 601 | if (codec->driver->suspend) |
| 602 | codec->driver->suspend(codec); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 603 | codec->suspended = 1; |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 604 | if (codec->component.regmap) |
| 605 | regcache_mark_dirty(codec->component.regmap); |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 606 | /* deactivate pins to sleep state */ |
| 607 | pinctrl_pm_select_sleep_state(codec->dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 608 | break; |
| 609 | default: |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 610 | dev_dbg(codec->dev, |
| 611 | "ASoC: CODEC is on over suspend\n"); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 612 | break; |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | for (i = 0; i < card->num_rtd; i++) { |
| 618 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
| 619 | |
| 620 | if (card->rtd[i].dai_link->ignore_suspend) |
| 621 | continue; |
| 622 | |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 623 | if (cpu_dai->driver->suspend && cpu_dai->driver->bus_control) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 624 | cpu_dai->driver->suspend(cpu_dai); |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 625 | |
| 626 | /* deactivate pins to sleep state */ |
| 627 | pinctrl_pm_select_sleep_state(cpu_dai->dev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 628 | } |
| 629 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 630 | if (card->suspend_post) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 631 | card->suspend_post(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 632 | |
| 633 | return 0; |
| 634 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 635 | EXPORT_SYMBOL_GPL(snd_soc_suspend); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 636 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 637 | /* deferred resume work, so resume can complete before we finished |
| 638 | * setting our codec back up, which can be very slow on I2C |
| 639 | */ |
| 640 | static void soc_resume_deferred(struct work_struct *work) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 641 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 642 | struct snd_soc_card *card = |
| 643 | container_of(work, struct snd_soc_card, deferred_resume_work); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 644 | struct snd_soc_codec *codec; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 645 | int i, j; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 646 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 647 | /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, |
| 648 | * so userspace apps are blocked from touching us |
| 649 | */ |
| 650 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 651 | dev_dbg(card->dev, "ASoC: starting resume work\n"); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 652 | |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 653 | /* Bring us up into D2 so that DAPM starts enabling things */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 654 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2); |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 655 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 656 | if (card->resume_pre) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 657 | card->resume_pre(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 658 | |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 659 | /* resume control bus DAIs */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 660 | for (i = 0; i < card->num_rtd; i++) { |
| 661 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 662 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 663 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 664 | continue; |
| 665 | |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 666 | if (cpu_dai->driver->resume && cpu_dai->driver->bus_control) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 667 | cpu_dai->driver->resume(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 668 | } |
| 669 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 670 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 671 | /* If the CODEC was idle over suspend then it will have been |
| 672 | * left with bias OFF or STANDBY and suspended so we must now |
| 673 | * resume. Otherwise the suspend was suppressed. |
| 674 | */ |
Lars-Peter Clausen | a809329 | 2014-09-04 19:44:07 +0200 | [diff] [blame] | 675 | if (codec->suspended) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 676 | switch (codec->dapm.bias_level) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 677 | case SND_SOC_BIAS_STANDBY: |
| 678 | case SND_SOC_BIAS_OFF: |
Lars-Peter Clausen | a809329 | 2014-09-04 19:44:07 +0200 | [diff] [blame] | 679 | if (codec->driver->resume) |
| 680 | codec->driver->resume(codec); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 681 | codec->suspended = 0; |
| 682 | break; |
| 683 | default: |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 684 | dev_dbg(codec->dev, |
| 685 | "ASoC: CODEC was on over suspend\n"); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 686 | break; |
| 687 | } |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 688 | } |
| 689 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 690 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 691 | for (i = 0; i < card->num_rtd; i++) { |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 692 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 693 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 694 | continue; |
| 695 | |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 696 | snd_soc_dapm_stream_event(&card->rtd[i], |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 697 | SNDRV_PCM_STREAM_PLAYBACK, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 698 | SND_SOC_DAPM_STREAM_RESUME); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 699 | |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 700 | snd_soc_dapm_stream_event(&card->rtd[i], |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 701 | SNDRV_PCM_STREAM_CAPTURE, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 702 | SND_SOC_DAPM_STREAM_RESUME); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 703 | } |
| 704 | |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 705 | /* unmute any active DACs */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 706 | for (i = 0; i < card->num_rtd; i++) { |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 707 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 708 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 709 | continue; |
| 710 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 711 | for (j = 0; j < card->rtd[i].num_codecs; j++) { |
| 712 | struct snd_soc_dai *dai = card->rtd[i].codec_dais[j]; |
| 713 | struct snd_soc_dai_driver *drv = dai->driver; |
| 714 | |
| 715 | if (drv->ops->digital_mute && dai->playback_active) |
| 716 | drv->ops->digital_mute(dai, 0); |
| 717 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 718 | } |
| 719 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 720 | for (i = 0; i < card->num_rtd; i++) { |
| 721 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 722 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 723 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 724 | continue; |
| 725 | |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 726 | if (cpu_dai->driver->resume && !cpu_dai->driver->bus_control) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 727 | cpu_dai->driver->resume(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 728 | } |
| 729 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 730 | if (card->resume_post) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 731 | card->resume_post(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 732 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 733 | dev_dbg(card->dev, "ASoC: resume work completed\n"); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 734 | |
| 735 | /* userspace can access us now we are back as we were before */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 736 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0); |
Mark Brown | e2d32ff | 2012-08-31 17:38:32 -0700 | [diff] [blame] | 737 | |
Lars-Peter Clausen | 8be4da2 | 2014-10-25 17:42:01 +0200 | [diff] [blame] | 738 | /* Recheck all endpoints too, their state is affected by suspend */ |
| 739 | dapm_mark_endpoints_dirty(card); |
Mark Brown | e2d32ff | 2012-08-31 17:38:32 -0700 | [diff] [blame] | 740 | snd_soc_dapm_sync(&card->dapm); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | /* powers up audio subsystem after a suspend */ |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 744 | int snd_soc_resume(struct device *dev) |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 745 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 746 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 747 | bool bus_control = false; |
| 748 | int i; |
Peter Ujfalusi | b9dd94a | 2010-02-22 13:27:13 +0200 | [diff] [blame] | 749 | |
Lars-Peter Clausen | c5599b8 | 2014-08-19 15:51:30 +0200 | [diff] [blame] | 750 | /* If the card is not initialized yet there is nothing to do */ |
| 751 | if (!card->instantiated) |
Eric Miao | 5ff1ddf | 2011-11-23 22:37:00 +0800 | [diff] [blame] | 752 | return 0; |
| 753 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 754 | /* activate pins from sleep state */ |
| 755 | for (i = 0; i < card->num_rtd; i++) { |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 756 | struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; |
| 757 | struct snd_soc_dai **codec_dais = rtd->codec_dais; |
| 758 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 759 | int j; |
| 760 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 761 | if (cpu_dai->active) |
| 762 | pinctrl_pm_select_default_state(cpu_dai->dev); |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 763 | |
| 764 | for (j = 0; j < rtd->num_codecs; j++) { |
| 765 | struct snd_soc_dai *codec_dai = codec_dais[j]; |
| 766 | if (codec_dai->active) |
| 767 | pinctrl_pm_select_default_state(codec_dai->dev); |
| 768 | } |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 769 | } |
| 770 | |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 771 | /* |
| 772 | * DAIs that also act as the control bus master might have other drivers |
| 773 | * hanging off them so need to resume immediately. Other drivers don't |
| 774 | * have that problem and may take a substantial amount of time to resume |
Mark Brown | 64ab9ba | 2009-03-31 11:27:03 +0100 | [diff] [blame] | 775 | * due to I/O costs and anti-pop so handle them out of line. |
| 776 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 777 | for (i = 0; i < card->num_rtd; i++) { |
| 778 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 779 | bus_control |= cpu_dai->driver->bus_control; |
Stephen Warren | 82e14e8 | 2011-05-25 14:06:41 -0600 | [diff] [blame] | 780 | } |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 781 | if (bus_control) { |
| 782 | dev_dbg(dev, "ASoC: Resuming control bus master immediately\n"); |
Stephen Warren | 82e14e8 | 2011-05-25 14:06:41 -0600 | [diff] [blame] | 783 | soc_resume_deferred(&card->deferred_resume_work); |
| 784 | } else { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 785 | dev_dbg(dev, "ASoC: Scheduling resume work\n"); |
Stephen Warren | 82e14e8 | 2011-05-25 14:06:41 -0600 | [diff] [blame] | 786 | if (!schedule_work(&card->deferred_resume_work)) |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 787 | dev_err(dev, "ASoC: resume work item may be lost\n"); |
Mark Brown | 64ab9ba | 2009-03-31 11:27:03 +0100 | [diff] [blame] | 788 | } |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 789 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 790 | return 0; |
| 791 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 792 | EXPORT_SYMBOL_GPL(snd_soc_resume); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 793 | #else |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 794 | #define snd_soc_suspend NULL |
| 795 | #define snd_soc_resume NULL |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 796 | #endif |
| 797 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 798 | static const struct snd_soc_dai_ops null_dai_ops = { |
Barry Song | 02a06d3 | 2009-10-16 18:13:38 +0800 | [diff] [blame] | 799 | }; |
| 800 | |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 801 | static struct snd_soc_component *soc_find_component( |
| 802 | const struct device_node *of_node, const char *name) |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 803 | { |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 804 | struct snd_soc_component *component; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 805 | |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 806 | list_for_each_entry(component, &component_list, list) { |
| 807 | if (of_node) { |
| 808 | if (component->dev->of_node == of_node) |
| 809 | return component; |
| 810 | } else if (strcmp(component->name, name) == 0) { |
| 811 | return component; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 812 | } |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | return NULL; |
| 816 | } |
| 817 | |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 818 | static struct snd_soc_dai *snd_soc_find_dai( |
| 819 | const struct snd_soc_dai_link_component *dlc) |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 820 | { |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 821 | struct snd_soc_component *component; |
| 822 | struct snd_soc_dai *dai; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 823 | |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 824 | /* Find CPU DAI from registered DAIs*/ |
| 825 | list_for_each_entry(component, &component_list, list) { |
| 826 | if (dlc->of_node && component->dev->of_node != dlc->of_node) |
| 827 | continue; |
Lars-Peter Clausen | 1ffae36 | 2014-10-29 21:46:30 +0100 | [diff] [blame] | 828 | if (dlc->name && strcmp(component->name, dlc->name)) |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 829 | continue; |
| 830 | list_for_each_entry(dai, &component->dai_list, list) { |
| 831 | if (dlc->dai_name && strcmp(dai->name, dlc->dai_name)) |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 832 | continue; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 833 | |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 834 | return dai; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | |
| 838 | return NULL; |
| 839 | } |
| 840 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 841 | 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] | 842 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 843 | struct snd_soc_dai_link *dai_link = &card->dai_link[num]; |
| 844 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 845 | struct snd_soc_dai_link_component *codecs = dai_link->codecs; |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 846 | struct snd_soc_dai_link_component cpu_dai_component; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 847 | struct snd_soc_dai **codec_dais = rtd->codec_dais; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 848 | struct snd_soc_platform *platform; |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 849 | const char *platform_name; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 850 | int i; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 851 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 852 | 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] | 853 | |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 854 | cpu_dai_component.name = dai_link->cpu_name; |
| 855 | cpu_dai_component.of_node = dai_link->cpu_of_node; |
| 856 | cpu_dai_component.dai_name = dai_link->cpu_dai_name; |
| 857 | rtd->cpu_dai = snd_soc_find_dai(&cpu_dai_component); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 858 | if (!rtd->cpu_dai) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 859 | dev_err(card->dev, "ASoC: CPU DAI %s not registered\n", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 860 | dai_link->cpu_dai_name); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 861 | return -EPROBE_DEFER; |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 862 | } |
| 863 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 864 | rtd->num_codecs = dai_link->num_codecs; |
| 865 | |
| 866 | /* Find CODEC from registered CODECs */ |
| 867 | for (i = 0; i < rtd->num_codecs; i++) { |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 868 | codec_dais[i] = snd_soc_find_dai(&codecs[i]); |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 869 | if (!codec_dais[i]) { |
| 870 | dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n", |
| 871 | codecs[i].dai_name); |
| 872 | return -EPROBE_DEFER; |
| 873 | } |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 874 | } |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 875 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 876 | /* Single codec links expect codec and codec_dai in runtime data */ |
| 877 | rtd->codec_dai = codec_dais[0]; |
| 878 | rtd->codec = rtd->codec_dai->codec; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 879 | |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 880 | /* if there's no platform we match on the empty platform */ |
| 881 | platform_name = dai_link->platform_name; |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 882 | if (!platform_name && !dai_link->platform_of_node) |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 883 | platform_name = "snd-soc-dummy"; |
| 884 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 885 | /* find one from the set of registered platforms */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 886 | list_for_each_entry(platform, &platform_list, list) { |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 887 | if (dai_link->platform_of_node) { |
| 888 | if (platform->dev->of_node != |
| 889 | dai_link->platform_of_node) |
| 890 | continue; |
| 891 | } else { |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 892 | if (strcmp(platform->component.name, platform_name)) |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 893 | continue; |
| 894 | } |
Stephen Warren | 2610ab7 | 2011-12-07 13:58:27 -0700 | [diff] [blame] | 895 | |
| 896 | rtd->platform = platform; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 897 | } |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 898 | if (!rtd->platform) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 899 | dev_err(card->dev, "ASoC: platform %s not registered\n", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 900 | dai_link->platform_name); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 901 | return -EPROBE_DEFER; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 902 | } |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 903 | |
| 904 | card->num_rtd++; |
| 905 | |
| 906 | return 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 907 | } |
| 908 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 909 | static void soc_remove_component(struct snd_soc_component *component) |
Stephen Warren | d12cd19 | 2012-06-08 12:34:22 -0600 | [diff] [blame] | 910 | { |
Lars-Peter Clausen | 70090bb | 2014-08-19 15:51:24 +0200 | [diff] [blame] | 911 | if (!component->probed) |
| 912 | return; |
Stephen Warren | d12cd19 | 2012-06-08 12:34:22 -0600 | [diff] [blame] | 913 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 914 | /* This is a HACK and will be removed soon */ |
| 915 | if (component->codec) |
| 916 | list_del(&component->codec->card_list); |
Stephen Warren | d12cd19 | 2012-06-08 12:34:22 -0600 | [diff] [blame] | 917 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 918 | if (component->remove) |
| 919 | component->remove(component); |
Stephen Warren | d12cd19 | 2012-06-08 12:34:22 -0600 | [diff] [blame] | 920 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 921 | snd_soc_dapm_free(snd_soc_component_get_dapm(component)); |
Stephen Warren | d12cd19 | 2012-06-08 12:34:22 -0600 | [diff] [blame] | 922 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 923 | soc_cleanup_component_debugfs(component); |
| 924 | component->probed = 0; |
| 925 | module_put(component->dev->driver->owner); |
Stephen Warren | d12cd19 | 2012-06-08 12:34:22 -0600 | [diff] [blame] | 926 | } |
| 927 | |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 928 | static void soc_remove_dai(struct snd_soc_dai *dai, int order) |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 929 | { |
| 930 | int err; |
| 931 | |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 932 | if (dai && dai->probed && |
| 933 | dai->driver->remove_order == order) { |
| 934 | if (dai->driver->remove) { |
| 935 | err = dai->driver->remove(dai); |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 936 | if (err < 0) |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 937 | dev_err(dai->dev, |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 938 | "ASoC: failed to remove %s: %d\n", |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 939 | dai->name, err); |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 940 | } |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 941 | dai->probed = 0; |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 942 | } |
| 943 | } |
| 944 | |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 945 | 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] | 946 | { |
| 947 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 948 | int i; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 949 | |
| 950 | /* unregister the rtd device */ |
| 951 | if (rtd->dev_registered) { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 952 | device_remove_file(rtd->dev, &dev_attr_pmdown_time); |
| 953 | device_remove_file(rtd->dev, &dev_attr_codec_reg); |
| 954 | device_unregister(rtd->dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 955 | rtd->dev_registered = 0; |
| 956 | } |
| 957 | |
| 958 | /* remove the CODEC DAI */ |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 959 | for (i = 0; i < rtd->num_codecs; i++) |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 960 | soc_remove_dai(rtd->codec_dais[i], order); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 961 | |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 962 | soc_remove_dai(rtd->cpu_dai, order); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 963 | } |
| 964 | |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 965 | static void soc_remove_link_components(struct snd_soc_card *card, int num, |
| 966 | int order) |
| 967 | { |
| 968 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
| 969 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 970 | struct snd_soc_platform *platform = rtd->platform; |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 971 | struct snd_soc_component *component; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 972 | int i; |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 973 | |
| 974 | /* remove the platform */ |
Lars-Peter Clausen | 70090bb | 2014-08-19 15:51:24 +0200 | [diff] [blame] | 975 | if (platform && platform->component.driver->remove_order == order) |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 976 | soc_remove_component(&platform->component); |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 977 | |
| 978 | /* remove the CODEC-side CODEC */ |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 979 | for (i = 0; i < rtd->num_codecs; i++) { |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 980 | component = rtd->codec_dais[i]->component; |
Lars-Peter Clausen | 70090bb | 2014-08-19 15:51:24 +0200 | [diff] [blame] | 981 | if (component->driver->remove_order == order) |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 982 | soc_remove_component(component); |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | /* remove any CPU-side CODEC */ |
| 986 | if (cpu_dai) { |
Lars-Peter Clausen | 70090bb | 2014-08-19 15:51:24 +0200 | [diff] [blame] | 987 | if (cpu_dai->component->driver->remove_order == order) |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 988 | soc_remove_component(cpu_dai->component); |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 989 | } |
| 990 | } |
| 991 | |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 992 | static void soc_remove_dai_links(struct snd_soc_card *card) |
| 993 | { |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 994 | int dai, order; |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 995 | |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 996 | for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; |
| 997 | order++) { |
| 998 | for (dai = 0; dai < card->num_rtd; dai++) |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 999 | soc_remove_link_dais(card, dai, order); |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1000 | } |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1001 | |
| 1002 | for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; |
| 1003 | order++) { |
| 1004 | for (dai = 0; dai < card->num_rtd; dai++) |
| 1005 | soc_remove_link_components(card, dai, order); |
| 1006 | } |
| 1007 | |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1008 | card->num_rtd = 0; |
| 1009 | } |
| 1010 | |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1011 | static void soc_set_name_prefix(struct snd_soc_card *card, |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 1012 | struct snd_soc_component *component) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1013 | { |
| 1014 | int i; |
| 1015 | |
Dimitris Papastamos | ff819b8 | 2010-12-02 14:53:03 +0000 | [diff] [blame] | 1016 | if (card->codec_conf == NULL) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1017 | return; |
| 1018 | |
Dimitris Papastamos | ff819b8 | 2010-12-02 14:53:03 +0000 | [diff] [blame] | 1019 | for (i = 0; i < card->num_configs; i++) { |
| 1020 | struct snd_soc_codec_conf *map = &card->codec_conf[i]; |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 1021 | if (map->of_node && component->dev->of_node != map->of_node) |
Sebastian Reichel | 3ca041e | 2014-04-28 16:07:22 +0200 | [diff] [blame] | 1022 | continue; |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 1023 | if (map->dev_name && strcmp(component->name, map->dev_name)) |
Sebastian Reichel | 3ca041e | 2014-04-28 16:07:22 +0200 | [diff] [blame] | 1024 | continue; |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 1025 | component->name_prefix = map->name_prefix; |
Sebastian Reichel | 3ca041e | 2014-04-28 16:07:22 +0200 | [diff] [blame] | 1026 | break; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1030 | static int soc_probe_component(struct snd_soc_card *card, |
| 1031 | struct snd_soc_component *component) |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1032 | { |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1033 | struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 1034 | struct snd_soc_dai *dai; |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1035 | int ret; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1036 | |
Lars-Peter Clausen | 70090bb | 2014-08-19 15:51:24 +0200 | [diff] [blame] | 1037 | if (component->probed) |
| 1038 | return 0; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1039 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1040 | component->card = card; |
| 1041 | dapm->card = card; |
| 1042 | soc_set_name_prefix(card, component); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1043 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1044 | if (!try_module_get(component->dev->driver->owner)) |
Jarkko Nikula | 70d2933 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1045 | return -ENODEV; |
| 1046 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1047 | soc_init_component_debugfs(component); |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1048 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1049 | if (component->dapm_widgets) { |
| 1050 | ret = snd_soc_dapm_new_controls(dapm, component->dapm_widgets, |
| 1051 | component->num_dapm_widgets); |
Nariman Poushin | b318ad5 | 2014-04-01 13:59:33 +0100 | [diff] [blame] | 1052 | |
| 1053 | if (ret != 0) { |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1054 | dev_err(component->dev, |
Nariman Poushin | b318ad5 | 2014-04-01 13:59:33 +0100 | [diff] [blame] | 1055 | "Failed to create new controls %d\n", ret); |
| 1056 | goto err_probe; |
| 1057 | } |
| 1058 | } |
Lars-Peter Clausen | 7753015 | 2011-05-05 16:59:09 +0200 | [diff] [blame] | 1059 | |
Lars-Peter Clausen | 0634814 | 2014-08-20 13:08:49 +0200 | [diff] [blame] | 1060 | list_for_each_entry(dai, &component->dai_list, list) { |
| 1061 | ret = snd_soc_dapm_new_dai_widgets(dapm, dai); |
Nariman Poushin | 261edc7 | 2014-03-31 15:47:12 +0100 | [diff] [blame] | 1062 | if (ret != 0) { |
Lars-Peter Clausen | 0634814 | 2014-08-20 13:08:49 +0200 | [diff] [blame] | 1063 | dev_err(component->dev, |
Nariman Poushin | 261edc7 | 2014-03-31 15:47:12 +0100 | [diff] [blame] | 1064 | "Failed to create DAI widgets %d\n", ret); |
| 1065 | goto err_probe; |
| 1066 | } |
| 1067 | } |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 1068 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1069 | if (component->probe) { |
| 1070 | ret = component->probe(component); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1071 | if (ret < 0) { |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1072 | dev_err(component->dev, |
| 1073 | "ASoC: failed to probe component %d\n", ret); |
Jarkko Nikula | 70d2933 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1074 | goto err_probe; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1075 | } |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1076 | |
| 1077 | WARN(dapm->idle_bias_off && |
| 1078 | dapm->bias_level != SND_SOC_BIAS_OFF, |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 1079 | "codec %s can not start from non-off bias with idle_bias_off==1\n", |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1080 | component->name); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1081 | } |
| 1082 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1083 | if (component->controls) |
| 1084 | snd_soc_add_component_controls(component, component->controls, |
| 1085 | component->num_controls); |
| 1086 | if (component->dapm_routes) |
| 1087 | snd_soc_dapm_add_routes(dapm, component->dapm_routes, |
| 1088 | component->num_dapm_routes); |
Mark Brown | 89b95ac0 | 2011-03-07 16:38:44 +0000 | [diff] [blame] | 1089 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1090 | component->probed = 1; |
| 1091 | list_add(&dapm->list, &card->dapm_list); |
| 1092 | |
| 1093 | /* This is a HACK and will be removed soon */ |
| 1094 | if (component->codec) |
| 1095 | list_add(&component->codec->card_list, &card->codec_dev_list); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1096 | |
Jarkko Nikula | 70d2933 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1097 | return 0; |
| 1098 | |
| 1099 | err_probe: |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1100 | soc_cleanup_component_debugfs(component); |
| 1101 | module_put(component->dev->driver->owner); |
Liam Girdwood | 956245e | 2011-07-01 16:54:08 +0100 | [diff] [blame] | 1102 | |
| 1103 | return ret; |
| 1104 | } |
| 1105 | |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1106 | static void rtd_release(struct device *dev) |
| 1107 | { |
| 1108 | kfree(dev); |
| 1109 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1110 | |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1111 | static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd, |
| 1112 | const char *name) |
Misael Lopez Cruz | 503ae5e | 2014-04-24 14:01:44 +0200 | [diff] [blame] | 1113 | { |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1114 | int ret = 0; |
| 1115 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1116 | /* register the rtd device */ |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1117 | rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL); |
| 1118 | if (!rtd->dev) |
| 1119 | return -ENOMEM; |
| 1120 | device_initialize(rtd->dev); |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1121 | rtd->dev->parent = rtd->card->dev; |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1122 | rtd->dev->release = rtd_release; |
Lars-Peter Clausen | f294afe | 2014-08-17 11:28:35 +0200 | [diff] [blame] | 1123 | dev_set_name(rtd->dev, "%s", name); |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1124 | dev_set_drvdata(rtd->dev, rtd); |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 1125 | mutex_init(&rtd->pcm_mutex); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1126 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients); |
| 1127 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients); |
| 1128 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients); |
| 1129 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients); |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1130 | ret = device_add(rtd->dev); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1131 | if (ret < 0) { |
Chuansheng Liu | 865df9c | 2012-12-26 00:56:05 +0800 | [diff] [blame] | 1132 | /* calling put_device() here to free the rtd->dev */ |
| 1133 | put_device(rtd->dev); |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1134 | dev_err(rtd->card->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1135 | "ASoC: failed to register runtime device: %d\n", ret); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1136 | return ret; |
| 1137 | } |
| 1138 | rtd->dev_registered = 1; |
| 1139 | |
Lars-Peter Clausen | 93c3ce7 | 2014-08-19 15:51:20 +0200 | [diff] [blame] | 1140 | if (rtd->codec) { |
| 1141 | /* add DAPM sysfs entries for this codec */ |
| 1142 | ret = snd_soc_dapm_sys_add(rtd->dev); |
| 1143 | if (ret < 0) |
| 1144 | dev_err(rtd->dev, |
| 1145 | "ASoC: failed to add codec dapm sysfs entries: %d\n", |
| 1146 | ret); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1147 | |
Lars-Peter Clausen | 93c3ce7 | 2014-08-19 15:51:20 +0200 | [diff] [blame] | 1148 | /* add codec sysfs entries */ |
| 1149 | ret = device_create_file(rtd->dev, &dev_attr_codec_reg); |
| 1150 | if (ret < 0) |
| 1151 | dev_err(rtd->dev, |
| 1152 | "ASoC: failed to add codec sysfs files: %d\n", |
| 1153 | ret); |
| 1154 | } |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1155 | |
| 1156 | return 0; |
| 1157 | } |
| 1158 | |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1159 | static int soc_probe_link_components(struct snd_soc_card *card, int num, |
| 1160 | int order) |
| 1161 | { |
| 1162 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1163 | struct snd_soc_platform *platform = rtd->platform; |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1164 | struct snd_soc_component *component; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1165 | int i, ret; |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1166 | |
| 1167 | /* probe the CPU-side component, if it is a CODEC */ |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 1168 | component = rtd->cpu_dai->component; |
Lars-Peter Clausen | 70090bb | 2014-08-19 15:51:24 +0200 | [diff] [blame] | 1169 | if (component->driver->probe_order == order) { |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 1170 | ret = soc_probe_component(card, component); |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1171 | if (ret < 0) |
| 1172 | return ret; |
| 1173 | } |
| 1174 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1175 | /* probe the CODEC-side components */ |
| 1176 | for (i = 0; i < rtd->num_codecs; i++) { |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 1177 | component = rtd->codec_dais[i]->component; |
Lars-Peter Clausen | 70090bb | 2014-08-19 15:51:24 +0200 | [diff] [blame] | 1178 | if (component->driver->probe_order == order) { |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1179 | ret = soc_probe_component(card, component); |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1180 | if (ret < 0) |
| 1181 | return ret; |
| 1182 | } |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | /* probe the platform */ |
Lars-Peter Clausen | 70090bb | 2014-08-19 15:51:24 +0200 | [diff] [blame] | 1186 | if (platform->component.driver->probe_order == order) { |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1187 | ret = soc_probe_component(card, &platform->component); |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1188 | if (ret < 0) |
| 1189 | return ret; |
| 1190 | } |
| 1191 | |
| 1192 | return 0; |
| 1193 | } |
| 1194 | |
Lars-Peter Clausen | 8e2be56 | 2014-11-04 11:30:59 +0100 | [diff] [blame] | 1195 | static int soc_probe_dai(struct snd_soc_dai *dai, int order) |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 1196 | { |
| 1197 | int ret; |
| 1198 | |
Lars-Peter Clausen | 8e2be56 | 2014-11-04 11:30:59 +0100 | [diff] [blame] | 1199 | if (!dai->probed && dai->driver->probe_order == order) { |
| 1200 | if (dai->driver->probe) { |
| 1201 | ret = dai->driver->probe(dai); |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 1202 | if (ret < 0) { |
Lars-Peter Clausen | 8e2be56 | 2014-11-04 11:30:59 +0100 | [diff] [blame] | 1203 | dev_err(dai->dev, |
| 1204 | "ASoC: failed to probe DAI %s: %d\n", |
| 1205 | dai->name, ret); |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 1206 | return ret; |
| 1207 | } |
| 1208 | } |
| 1209 | |
Lars-Peter Clausen | 8e2be56 | 2014-11-04 11:30:59 +0100 | [diff] [blame] | 1210 | dai->probed = 1; |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | return 0; |
| 1214 | } |
| 1215 | |
Misael Lopez Cruz | 2436a72 | 2014-03-21 16:27:27 +0100 | [diff] [blame] | 1216 | static int soc_link_dai_widgets(struct snd_soc_card *card, |
| 1217 | struct snd_soc_dai_link *dai_link, |
Benoit Cousson | 3f901a0 | 2014-07-01 09:47:54 +0200 | [diff] [blame] | 1218 | struct snd_soc_pcm_runtime *rtd) |
Misael Lopez Cruz | 2436a72 | 2014-03-21 16:27:27 +0100 | [diff] [blame] | 1219 | { |
Benoit Cousson | 3f901a0 | 2014-07-01 09:47:54 +0200 | [diff] [blame] | 1220 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1221 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Misael Lopez Cruz | 2436a72 | 2014-03-21 16:27:27 +0100 | [diff] [blame] | 1222 | struct snd_soc_dapm_widget *play_w, *capture_w; |
| 1223 | int ret; |
| 1224 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1225 | if (rtd->num_codecs > 1) |
| 1226 | dev_warn(card->dev, "ASoC: Multiple codecs not supported yet\n"); |
| 1227 | |
Misael Lopez Cruz | 2436a72 | 2014-03-21 16:27:27 +0100 | [diff] [blame] | 1228 | /* link the DAI widgets */ |
| 1229 | play_w = codec_dai->playback_widget; |
| 1230 | capture_w = cpu_dai->capture_widget; |
| 1231 | if (play_w && capture_w) { |
| 1232 | ret = snd_soc_dapm_new_pcm(card, dai_link->params, |
| 1233 | capture_w, play_w); |
| 1234 | if (ret != 0) { |
| 1235 | dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n", |
| 1236 | play_w->name, capture_w->name, ret); |
| 1237 | return ret; |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | play_w = cpu_dai->playback_widget; |
| 1242 | capture_w = codec_dai->capture_widget; |
| 1243 | if (play_w && capture_w) { |
| 1244 | ret = snd_soc_dapm_new_pcm(card, dai_link->params, |
| 1245 | capture_w, play_w); |
| 1246 | if (ret != 0) { |
| 1247 | dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n", |
| 1248 | play_w->name, capture_w->name, ret); |
| 1249 | return ret; |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | return 0; |
| 1254 | } |
| 1255 | |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1256 | 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] | 1257 | { |
| 1258 | struct snd_soc_dai_link *dai_link = &card->dai_link[num]; |
| 1259 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 1260 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1261 | int i, ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1262 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1263 | 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] | 1264 | card->name, num, order); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1265 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1266 | /* set default power off timeout */ |
| 1267 | rtd->pmdown_time = pmdown_time; |
| 1268 | |
Lars-Peter Clausen | 8e2be56 | 2014-11-04 11:30:59 +0100 | [diff] [blame] | 1269 | ret = soc_probe_dai(cpu_dai, order); |
| 1270 | if (ret) |
| 1271 | return ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1272 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1273 | /* probe the CODEC DAI */ |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1274 | for (i = 0; i < rtd->num_codecs; i++) { |
Lars-Peter Clausen | 8e2be56 | 2014-11-04 11:30:59 +0100 | [diff] [blame] | 1275 | ret = soc_probe_dai(rtd->codec_dais[i], order); |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1276 | if (ret) |
| 1277 | return ret; |
| 1278 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1279 | |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1280 | /* complete DAI probe during last probe */ |
| 1281 | if (order != SND_SOC_COMP_ORDER_LAST) |
| 1282 | return 0; |
| 1283 | |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1284 | /* do machine specific initialization */ |
| 1285 | if (dai_link->init) { |
| 1286 | ret = dai_link->init(rtd); |
| 1287 | if (ret < 0) { |
| 1288 | dev_err(card->dev, "ASoC: failed to init %s: %d\n", |
| 1289 | dai_link->name, ret); |
| 1290 | return ret; |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | ret = soc_post_component_init(rtd, dai_link->name); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1295 | if (ret) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1296 | return ret; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1297 | |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1298 | #ifdef CONFIG_DEBUG_FS |
| 1299 | /* add DPCM sysfs entries */ |
| 1300 | if (dai_link->dynamic) { |
| 1301 | ret = soc_dpcm_debugfs_add(rtd); |
| 1302 | if (ret < 0) { |
| 1303 | dev_err(rtd->dev, |
| 1304 | "ASoC: failed to add dpcm sysfs entries: %d\n", |
| 1305 | ret); |
| 1306 | return ret; |
| 1307 | } |
| 1308 | } |
| 1309 | #endif |
| 1310 | |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1311 | ret = device_create_file(rtd->dev, &dev_attr_pmdown_time); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1312 | if (ret < 0) |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1313 | dev_warn(rtd->dev, "ASoC: failed to add pmdown_time sysfs: %d\n", |
| 1314 | ret); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1315 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1316 | if (cpu_dai->driver->compress_dai) { |
| 1317 | /*create compress_device"*/ |
| 1318 | ret = soc_new_compress(rtd, num); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 1319 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1320 | dev_err(card->dev, "ASoC: can't create compress %s\n", |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1321 | dai_link->stream_name); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 1322 | return ret; |
| 1323 | } |
| 1324 | } else { |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1325 | |
| 1326 | if (!dai_link->params) { |
| 1327 | /* create the pcm */ |
| 1328 | ret = soc_new_pcm(rtd, num); |
| 1329 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1330 | dev_err(card->dev, "ASoC: can't create pcm %s :%d\n", |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1331 | dai_link->stream_name, ret); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 1332 | return ret; |
| 1333 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1334 | } else { |
Richard Fitzgerald | 9d58a07 | 2013-08-05 13:17:28 +0100 | [diff] [blame] | 1335 | INIT_DELAYED_WORK(&rtd->delayed_work, |
| 1336 | codec2codec_close_delayed_work); |
| 1337 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1338 | /* link the DAI widgets */ |
Benoit Cousson | 3f901a0 | 2014-07-01 09:47:54 +0200 | [diff] [blame] | 1339 | ret = soc_link_dai_widgets(card, dai_link, rtd); |
Misael Lopez Cruz | 2436a72 | 2014-03-21 16:27:27 +0100 | [diff] [blame] | 1340 | if (ret) |
| 1341 | return ret; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 1342 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1343 | } |
| 1344 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1345 | return 0; |
| 1346 | } |
| 1347 | |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1348 | 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] | 1349 | { |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1350 | struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; |
Sebastian Reichel | 3ca041e | 2014-04-28 16:07:22 +0200 | [diff] [blame] | 1351 | struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1352 | const char *name = aux_dev->codec_name; |
Sebastian Reichel | 3ca041e | 2014-04-28 16:07:22 +0200 | [diff] [blame] | 1353 | |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1354 | rtd->component = soc_find_component(aux_dev->codec_of_node, name); |
| 1355 | if (!rtd->component) { |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1356 | if (aux_dev->codec_of_node) |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1357 | name = of_node_full_name(aux_dev->codec_of_node); |
Sebastian Reichel | 3ca041e | 2014-04-28 16:07:22 +0200 | [diff] [blame] | 1358 | |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1359 | dev_err(card->dev, "ASoC: %s not registered\n", name); |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1360 | return -EPROBE_DEFER; |
| 1361 | } |
| 1362 | |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1363 | /* |
| 1364 | * Some places still reference rtd->codec, so we have to keep that |
| 1365 | * initialized if the component is a CODEC. Once all those references |
| 1366 | * have been removed, this code can be removed as well. |
| 1367 | */ |
| 1368 | rtd->codec = rtd->component->codec; |
| 1369 | |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1370 | return 0; |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1373 | static int soc_probe_aux_dev(struct snd_soc_card *card, int num) |
| 1374 | { |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1375 | struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1376 | struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1377 | int ret; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1378 | |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1379 | ret = soc_probe_component(card, rtd->component); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1380 | if (ret < 0) |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1381 | return ret; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1382 | |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1383 | /* do machine specific initialization */ |
| 1384 | if (aux_dev->init) { |
Lars-Peter Clausen | 57bf772 | 2014-08-19 15:51:23 +0200 | [diff] [blame] | 1385 | ret = aux_dev->init(rtd->component); |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1386 | if (ret < 0) { |
| 1387 | dev_err(card->dev, "ASoC: failed to init %s: %d\n", |
| 1388 | aux_dev->name, ret); |
| 1389 | return ret; |
| 1390 | } |
| 1391 | } |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1392 | |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1393 | return soc_post_component_init(rtd, aux_dev->name); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | static void soc_remove_aux_dev(struct snd_soc_card *card, int num) |
| 1397 | { |
| 1398 | struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1399 | struct snd_soc_component *component = rtd->component; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1400 | |
| 1401 | /* unregister the rtd device */ |
| 1402 | if (rtd->dev_registered) { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1403 | device_remove_file(rtd->dev, &dev_attr_codec_reg); |
Chuansheng Liu | d3bf156 | 2012-12-26 00:57:32 +0800 | [diff] [blame] | 1404 | device_unregister(rtd->dev); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1405 | rtd->dev_registered = 0; |
| 1406 | } |
| 1407 | |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1408 | if (component && component->probed) |
| 1409 | soc_remove_component(component); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1410 | } |
| 1411 | |
Lars-Peter Clausen | f90fb3f | 2013-08-31 20:31:15 +0200 | [diff] [blame] | 1412 | static int snd_soc_init_codec_cache(struct snd_soc_codec *codec) |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1413 | { |
| 1414 | int ret; |
| 1415 | |
| 1416 | if (codec->cache_init) |
| 1417 | return 0; |
| 1418 | |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1419 | ret = snd_soc_cache_init(codec); |
| 1420 | if (ret < 0) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 1421 | dev_err(codec->dev, |
| 1422 | "ASoC: Failed to set cache compression type: %d\n", |
| 1423 | ret); |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1424 | return ret; |
| 1425 | } |
| 1426 | codec->cache_init = 1; |
| 1427 | return 0; |
| 1428 | } |
| 1429 | |
Lars-Peter Clausen | ce64c8b | 2015-01-06 15:17:20 +0100 | [diff] [blame^] | 1430 | /** |
| 1431 | * snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime |
| 1432 | * @rtd: The runtime for which the DAI link format should be changed |
| 1433 | * @dai_fmt: The new DAI link format |
| 1434 | * |
| 1435 | * This function updates the DAI link format for all DAIs connected to the DAI |
| 1436 | * link for the specified runtime. |
| 1437 | * |
| 1438 | * Note: For setups with a static format set the dai_fmt field in the |
| 1439 | * corresponding snd_dai_link struct instead of using this function. |
| 1440 | * |
| 1441 | * Returns 0 on success, otherwise a negative error code. |
| 1442 | */ |
| 1443 | int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, |
| 1444 | unsigned int dai_fmt) |
| 1445 | { |
| 1446 | struct snd_soc_dai **codec_dais = rtd->codec_dais; |
| 1447 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1448 | unsigned int i; |
| 1449 | int ret; |
| 1450 | |
| 1451 | for (i = 0; i < rtd->num_codecs; i++) { |
| 1452 | struct snd_soc_dai *codec_dai = codec_dais[i]; |
| 1453 | |
| 1454 | ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt); |
| 1455 | if (ret != 0 && ret != -ENOTSUPP) { |
| 1456 | dev_warn(codec_dai->dev, |
| 1457 | "ASoC: Failed to set DAI format: %d\n", ret); |
| 1458 | return ret; |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | /* Flip the polarity for the "CPU" end of a CODEC<->CODEC link */ |
| 1463 | if (cpu_dai->codec) { |
| 1464 | unsigned int inv_dai_fmt; |
| 1465 | |
| 1466 | inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK; |
| 1467 | switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 1468 | case SND_SOC_DAIFMT_CBM_CFM: |
| 1469 | inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS; |
| 1470 | break; |
| 1471 | case SND_SOC_DAIFMT_CBM_CFS: |
| 1472 | inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM; |
| 1473 | break; |
| 1474 | case SND_SOC_DAIFMT_CBS_CFM: |
| 1475 | inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS; |
| 1476 | break; |
| 1477 | case SND_SOC_DAIFMT_CBS_CFS: |
| 1478 | inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; |
| 1479 | break; |
| 1480 | } |
| 1481 | |
| 1482 | dai_fmt = inv_dai_fmt; |
| 1483 | } |
| 1484 | |
| 1485 | ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt); |
| 1486 | if (ret != 0 && ret != -ENOTSUPP) { |
| 1487 | dev_warn(cpu_dai->dev, |
| 1488 | "ASoC: Failed to set DAI format: %d\n", ret); |
| 1489 | return ret; |
| 1490 | } |
| 1491 | |
| 1492 | return 0; |
| 1493 | } |
| 1494 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1495 | static int snd_soc_instantiate_card(struct snd_soc_card *card) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1496 | { |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1497 | struct snd_soc_codec *codec; |
Lars-Peter Clausen | ce64c8b | 2015-01-06 15:17:20 +0100 | [diff] [blame^] | 1498 | int ret, i, order; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1499 | |
Liam Girdwood | 01b9d99 | 2012-03-07 10:38:25 +0000 | [diff] [blame] | 1500 | mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1501 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1502 | /* bind DAIs */ |
| 1503 | for (i = 0; i < card->num_links; i++) { |
| 1504 | ret = soc_bind_dai_link(card, i); |
| 1505 | if (ret != 0) |
| 1506 | goto base_error; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1509 | /* bind aux_devs too */ |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1510 | for (i = 0; i < card->num_aux_devs; i++) { |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1511 | ret = soc_bind_aux_dev(card, i); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1512 | if (ret != 0) |
| 1513 | goto base_error; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1514 | } |
| 1515 | |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1516 | /* initialize the register cache for each available codec */ |
| 1517 | list_for_each_entry(codec, &codec_list, list) { |
| 1518 | if (codec->cache_init) |
| 1519 | continue; |
Lars-Peter Clausen | f90fb3f | 2013-08-31 20:31:15 +0200 | [diff] [blame] | 1520 | ret = snd_soc_init_codec_cache(codec); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1521 | if (ret < 0) |
| 1522 | goto base_error; |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1525 | /* card bind complete so register a sound card */ |
Takashi Iwai | 102b5a8 | 2014-01-29 14:42:55 +0100 | [diff] [blame] | 1526 | ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1527 | card->owner, 0, &card->snd_card); |
| 1528 | if (ret < 0) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 1529 | dev_err(card->dev, |
| 1530 | "ASoC: can't create sound card for card %s: %d\n", |
| 1531 | card->name, ret); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1532 | goto base_error; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1533 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1534 | |
Mark Brown | e37a497 | 2011-03-02 18:21:57 +0000 | [diff] [blame] | 1535 | card->dapm.bias_level = SND_SOC_BIAS_OFF; |
| 1536 | card->dapm.dev = card->dev; |
| 1537 | card->dapm.card = card; |
| 1538 | list_add(&card->dapm.list, &card->dapm_list); |
| 1539 | |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1540 | #ifdef CONFIG_DEBUG_FS |
| 1541 | snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root); |
| 1542 | #endif |
| 1543 | |
Mark Brown | 88ee1c6 | 2011-02-02 10:43:26 +0000 | [diff] [blame] | 1544 | #ifdef CONFIG_PM_SLEEP |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1545 | /* deferred resume work */ |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 1546 | INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); |
Randy Dunlap | 1301a96 | 2008-06-17 19:19:34 +0100 | [diff] [blame] | 1547 | #endif |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1548 | |
Mark Brown | 9a841eb | 2011-04-12 17:51:37 -0700 | [diff] [blame] | 1549 | if (card->dapm_widgets) |
| 1550 | snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, |
| 1551 | card->num_dapm_widgets); |
| 1552 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1553 | /* initialise the sound card only once */ |
| 1554 | if (card->probe) { |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 1555 | ret = card->probe(card); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1556 | if (ret < 0) |
| 1557 | goto card_probe_error; |
| 1558 | } |
| 1559 | |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1560 | /* probe all components used by DAI links on this card */ |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1561 | for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; |
| 1562 | order++) { |
| 1563 | for (i = 0; i < card->num_links; i++) { |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1564 | ret = soc_probe_link_components(card, i, order); |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1565 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1566 | dev_err(card->dev, |
| 1567 | "ASoC: failed to instantiate card %d\n", |
| 1568 | ret); |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1569 | goto probe_dai_err; |
| 1570 | } |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | /* probe all DAI links on this card */ |
| 1575 | for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; |
| 1576 | order++) { |
| 1577 | for (i = 0; i < card->num_links; i++) { |
| 1578 | ret = soc_probe_link_dais(card, i, order); |
| 1579 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1580 | dev_err(card->dev, |
| 1581 | "ASoC: failed to instantiate card %d\n", |
| 1582 | ret); |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1583 | goto probe_dai_err; |
| 1584 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1585 | } |
| 1586 | } |
| 1587 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1588 | for (i = 0; i < card->num_aux_devs; i++) { |
| 1589 | ret = soc_probe_aux_dev(card, i); |
| 1590 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1591 | dev_err(card->dev, |
| 1592 | "ASoC: failed to add auxiliary devices %d\n", |
| 1593 | ret); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1594 | goto probe_aux_dev_err; |
| 1595 | } |
| 1596 | } |
| 1597 | |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 1598 | snd_soc_dapm_link_dai_widgets(card); |
Liam Girdwood | b893ea5 | 2014-01-08 10:40:19 +0000 | [diff] [blame] | 1599 | snd_soc_dapm_connect_dai_link_widgets(card); |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 1600 | |
Mark Brown | b7af1da | 2011-04-07 19:18:44 +0900 | [diff] [blame] | 1601 | if (card->controls) |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1602 | snd_soc_add_card_controls(card, card->controls, card->num_controls); |
Mark Brown | b7af1da | 2011-04-07 19:18:44 +0900 | [diff] [blame] | 1603 | |
Mark Brown | b8ad29d | 2011-03-02 18:35:51 +0000 | [diff] [blame] | 1604 | if (card->dapm_routes) |
| 1605 | snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, |
| 1606 | card->num_dapm_routes); |
| 1607 | |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1608 | for (i = 0; i < card->num_links; i++) { |
Lars-Peter Clausen | ce64c8b | 2015-01-06 15:17:20 +0100 | [diff] [blame^] | 1609 | if (card->dai_link[i].dai_fmt) |
| 1610 | snd_soc_runtime_set_dai_fmt(&card->rtd[i], |
| 1611 | card->dai_link[i].dai_fmt); |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1612 | } |
| 1613 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1614 | snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1615 | "%s", card->name); |
Liam Girdwood | 22de71b | 2011-05-12 16:14:04 +0100 | [diff] [blame] | 1616 | snprintf(card->snd_card->longname, sizeof(card->snd_card->longname), |
| 1617 | "%s", card->long_name ? card->long_name : card->name); |
Mark Brown | f0e8ed8 | 2011-09-20 11:41:54 +0100 | [diff] [blame] | 1618 | snprintf(card->snd_card->driver, sizeof(card->snd_card->driver), |
| 1619 | "%s", card->driver_name ? card->driver_name : card->name); |
| 1620 | for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) { |
| 1621 | switch (card->snd_card->driver[i]) { |
| 1622 | case '_': |
| 1623 | case '-': |
| 1624 | case '\0': |
| 1625 | break; |
| 1626 | default: |
| 1627 | if (!isalnum(card->snd_card->driver[i])) |
| 1628 | card->snd_card->driver[i] = '_'; |
| 1629 | break; |
| 1630 | } |
| 1631 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1632 | |
Mark Brown | 28e9ad9 | 2011-03-02 18:36:34 +0000 | [diff] [blame] | 1633 | if (card->late_probe) { |
| 1634 | ret = card->late_probe(card); |
| 1635 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1636 | dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n", |
Mark Brown | 28e9ad9 | 2011-03-02 18:36:34 +0000 | [diff] [blame] | 1637 | card->name, ret); |
| 1638 | goto probe_aux_dev_err; |
| 1639 | } |
| 1640 | } |
| 1641 | |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 1642 | if (card->fully_routed) |
Lars-Peter Clausen | 7df3788 | 2014-06-16 18:13:04 +0200 | [diff] [blame] | 1643 | snd_soc_dapm_auto_nc_pins(card); |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 1644 | |
Lars-Peter Clausen | 824ef82 | 2013-08-27 15:51:01 +0200 | [diff] [blame] | 1645 | snd_soc_dapm_new_widgets(card); |
Lars-Peter Clausen | 8c193b8 | 2013-08-27 15:51:00 +0200 | [diff] [blame] | 1646 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1647 | ret = snd_card_register(card->snd_card); |
| 1648 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1649 | dev_err(card->dev, "ASoC: failed to register soundcard %d\n", |
| 1650 | ret); |
Axel Lin | 6b3ed78 | 2010-12-07 16:12:29 +0800 | [diff] [blame] | 1651 | goto probe_aux_dev_err; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1654 | card->instantiated = 1; |
Mark Brown | 4f4c007 | 2011-10-07 14:29:19 +0100 | [diff] [blame] | 1655 | snd_soc_dapm_sync(&card->dapm); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1656 | mutex_unlock(&card->mutex); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1657 | |
| 1658 | return 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1659 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1660 | probe_aux_dev_err: |
| 1661 | for (i = 0; i < card->num_aux_devs; i++) |
| 1662 | soc_remove_aux_dev(card, i); |
| 1663 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1664 | probe_dai_err: |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1665 | soc_remove_dai_links(card); |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 1666 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1667 | card_probe_error: |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1668 | if (card->remove) |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 1669 | card->remove(card); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1670 | |
| 1671 | snd_card_free(card->snd_card); |
| 1672 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1673 | base_error: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1674 | mutex_unlock(&card->mutex); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1675 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1676 | return ret; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | /* probes a new socdev */ |
| 1680 | static int soc_probe(struct platform_device *pdev) |
| 1681 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1682 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1683 | |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 1684 | /* |
| 1685 | * no card, so machine driver should be registering card |
| 1686 | * we should not be here in that case so ret error |
| 1687 | */ |
| 1688 | if (!card) |
| 1689 | return -EINVAL; |
| 1690 | |
Mark Brown | fe4085e | 2012-03-02 13:07:41 +0000 | [diff] [blame] | 1691 | dev_warn(&pdev->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1692 | "ASoC: machine %s should use snd_soc_register_card()\n", |
Mark Brown | fe4085e | 2012-03-02 13:07:41 +0000 | [diff] [blame] | 1693 | card->name); |
| 1694 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1695 | /* Bodge while we unpick instantiation */ |
| 1696 | card->dev = &pdev->dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1697 | |
Mark Brown | 28d528c | 2012-08-09 18:45:23 +0100 | [diff] [blame] | 1698 | return snd_soc_register_card(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1699 | } |
| 1700 | |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1701 | static int soc_cleanup_card_resources(struct snd_soc_card *card) |
| 1702 | { |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1703 | int i; |
| 1704 | |
| 1705 | /* make sure any delayed work runs */ |
| 1706 | for (i = 0; i < card->num_rtd; i++) { |
| 1707 | struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 1708 | flush_delayed_work(&rtd->delayed_work); |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | /* remove auxiliary devices */ |
| 1712 | for (i = 0; i < card->num_aux_devs; i++) |
| 1713 | soc_remove_aux_dev(card, i); |
| 1714 | |
| 1715 | /* remove and free each DAI */ |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1716 | soc_remove_dai_links(card); |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1717 | |
| 1718 | soc_cleanup_card_debugfs(card); |
| 1719 | |
| 1720 | /* remove the card */ |
| 1721 | if (card->remove) |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 1722 | card->remove(card); |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1723 | |
Lars-Peter Clausen | 0aaae52 | 2011-04-30 19:45:47 +0200 | [diff] [blame] | 1724 | snd_soc_dapm_free(&card->dapm); |
| 1725 | |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1726 | snd_card_free(card->snd_card); |
| 1727 | return 0; |
| 1728 | |
| 1729 | } |
| 1730 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1731 | /* removes a socdev */ |
| 1732 | static int soc_remove(struct platform_device *pdev) |
| 1733 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1734 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1735 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 1736 | snd_soc_unregister_card(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1737 | return 0; |
| 1738 | } |
| 1739 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1740 | int snd_soc_poweroff(struct device *dev) |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1741 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1742 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1743 | int i; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1744 | |
| 1745 | if (!card->instantiated) |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1746 | return 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1747 | |
| 1748 | /* Flush out pmdown_time work - we actually do want to run it |
| 1749 | * now, we're shutting down so no imminent restart. */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1750 | for (i = 0; i < card->num_rtd; i++) { |
| 1751 | struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 1752 | flush_delayed_work(&rtd->delayed_work); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1753 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1754 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1755 | snd_soc_dapm_shutdown(card); |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1756 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 1757 | /* deactivate pins to sleep state */ |
| 1758 | for (i = 0; i < card->num_rtd; i++) { |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1759 | struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; |
| 1760 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1761 | int j; |
| 1762 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 1763 | pinctrl_pm_select_sleep_state(cpu_dai->dev); |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1764 | for (j = 0; j < rtd->num_codecs; j++) { |
| 1765 | struct snd_soc_dai *codec_dai = rtd->codec_dais[j]; |
| 1766 | pinctrl_pm_select_sleep_state(codec_dai->dev); |
| 1767 | } |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 1768 | } |
| 1769 | |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1770 | return 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1771 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1772 | EXPORT_SYMBOL_GPL(snd_soc_poweroff); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1773 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1774 | const struct dev_pm_ops snd_soc_pm_ops = { |
Viresh Kumar | b1dd589 | 2012-02-24 16:25:49 +0530 | [diff] [blame] | 1775 | .suspend = snd_soc_suspend, |
| 1776 | .resume = snd_soc_resume, |
| 1777 | .freeze = snd_soc_suspend, |
| 1778 | .thaw = snd_soc_resume, |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1779 | .poweroff = snd_soc_poweroff, |
Viresh Kumar | b1dd589 | 2012-02-24 16:25:49 +0530 | [diff] [blame] | 1780 | .restore = snd_soc_resume, |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1781 | }; |
Stephen Warren | deb2607 | 2011-04-05 19:35:30 -0600 | [diff] [blame] | 1782 | EXPORT_SYMBOL_GPL(snd_soc_pm_ops); |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1783 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1784 | /* ASoC platform driver */ |
| 1785 | static struct platform_driver soc_driver = { |
| 1786 | .driver = { |
| 1787 | .name = "soc-audio", |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1788 | .pm = &snd_soc_pm_ops, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1789 | }, |
| 1790 | .probe = soc_probe, |
| 1791 | .remove = soc_remove, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1792 | }; |
| 1793 | |
Mark Brown | 096e49d | 2009-07-05 15:12:22 +0100 | [diff] [blame] | 1794 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1795 | * snd_soc_cnew - create new control |
| 1796 | * @_template: control template |
| 1797 | * @data: control private data |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1798 | * @long_name: control long name |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 1799 | * @prefix: control name prefix |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1800 | * |
| 1801 | * Create a new mixer control from a template control. |
| 1802 | * |
| 1803 | * Returns 0 for success, else error. |
| 1804 | */ |
| 1805 | struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, |
Mark Brown | 3056557 | 2012-02-16 17:07:42 -0800 | [diff] [blame] | 1806 | void *data, const char *long_name, |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 1807 | const char *prefix) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1808 | { |
| 1809 | struct snd_kcontrol_new template; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 1810 | struct snd_kcontrol *kcontrol; |
| 1811 | char *name = NULL; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1812 | |
| 1813 | memcpy(&template, _template, sizeof(template)); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1814 | template.index = 0; |
| 1815 | |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 1816 | if (!long_name) |
| 1817 | long_name = template.name; |
| 1818 | |
| 1819 | if (prefix) { |
Lars-Peter Clausen | 2b58107 | 2013-05-14 11:05:32 +0200 | [diff] [blame] | 1820 | name = kasprintf(GFP_KERNEL, "%s %s", prefix, long_name); |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 1821 | if (!name) |
| 1822 | return NULL; |
| 1823 | |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 1824 | template.name = name; |
| 1825 | } else { |
| 1826 | template.name = long_name; |
| 1827 | } |
| 1828 | |
| 1829 | kcontrol = snd_ctl_new1(&template, data); |
| 1830 | |
| 1831 | kfree(name); |
| 1832 | |
| 1833 | return kcontrol; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1834 | } |
| 1835 | EXPORT_SYMBOL_GPL(snd_soc_cnew); |
| 1836 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1837 | static int snd_soc_add_controls(struct snd_card *card, struct device *dev, |
| 1838 | const struct snd_kcontrol_new *controls, int num_controls, |
| 1839 | const char *prefix, void *data) |
| 1840 | { |
| 1841 | int err, i; |
| 1842 | |
| 1843 | for (i = 0; i < num_controls; i++) { |
| 1844 | const struct snd_kcontrol_new *control = &controls[i]; |
| 1845 | err = snd_ctl_add(card, snd_soc_cnew(control, data, |
| 1846 | control->name, prefix)); |
| 1847 | if (err < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1848 | dev_err(dev, "ASoC: Failed to add %s: %d\n", |
| 1849 | control->name, err); |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1850 | return err; |
| 1851 | } |
| 1852 | } |
| 1853 | |
| 1854 | return 0; |
| 1855 | } |
| 1856 | |
Dimitris Papastamos | 4fefd69 | 2013-07-29 13:51:58 +0100 | [diff] [blame] | 1857 | struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card, |
| 1858 | const char *name) |
| 1859 | { |
| 1860 | struct snd_card *card = soc_card->snd_card; |
| 1861 | struct snd_kcontrol *kctl; |
| 1862 | |
| 1863 | if (unlikely(!name)) |
| 1864 | return NULL; |
| 1865 | |
| 1866 | list_for_each_entry(kctl, &card->controls, list) |
| 1867 | if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) |
| 1868 | return kctl; |
| 1869 | return NULL; |
| 1870 | } |
| 1871 | EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol); |
| 1872 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1873 | /** |
Lars-Peter Clausen | 0f2780a | 2014-07-17 22:01:08 +0200 | [diff] [blame] | 1874 | * snd_soc_add_component_controls - Add an array of controls to a component. |
| 1875 | * |
| 1876 | * @component: Component to add controls to |
| 1877 | * @controls: Array of controls to add |
| 1878 | * @num_controls: Number of elements in the array |
| 1879 | * |
| 1880 | * Return: 0 for success, else error. |
| 1881 | */ |
| 1882 | int snd_soc_add_component_controls(struct snd_soc_component *component, |
| 1883 | const struct snd_kcontrol_new *controls, unsigned int num_controls) |
| 1884 | { |
| 1885 | struct snd_card *card = component->card->snd_card; |
| 1886 | |
| 1887 | return snd_soc_add_controls(card, component->dev, controls, |
| 1888 | num_controls, component->name_prefix, component); |
| 1889 | } |
| 1890 | EXPORT_SYMBOL_GPL(snd_soc_add_component_controls); |
| 1891 | |
| 1892 | /** |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1893 | * snd_soc_add_codec_controls - add an array of controls to a codec. |
| 1894 | * Convenience function to add a list of controls. Many codecs were |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 1895 | * duplicating this code. |
| 1896 | * |
| 1897 | * @codec: codec to add controls to |
| 1898 | * @controls: array of controls to add |
| 1899 | * @num_controls: number of elements in the array |
| 1900 | * |
| 1901 | * Return 0 for success, else error. |
| 1902 | */ |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1903 | int snd_soc_add_codec_controls(struct snd_soc_codec *codec, |
Lars-Peter Clausen | 0f2780a | 2014-07-17 22:01:08 +0200 | [diff] [blame] | 1904 | const struct snd_kcontrol_new *controls, unsigned int num_controls) |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 1905 | { |
Lars-Peter Clausen | 0f2780a | 2014-07-17 22:01:08 +0200 | [diff] [blame] | 1906 | return snd_soc_add_component_controls(&codec->component, controls, |
| 1907 | num_controls); |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 1908 | } |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1909 | EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls); |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 1910 | |
| 1911 | /** |
Liam Girdwood | a491a5c | 2011-07-04 22:10:51 +0100 | [diff] [blame] | 1912 | * 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] | 1913 | * Convenience function to add a list of controls. |
Liam Girdwood | a491a5c | 2011-07-04 22:10:51 +0100 | [diff] [blame] | 1914 | * |
| 1915 | * @platform: platform to add controls to |
| 1916 | * @controls: array of controls to add |
| 1917 | * @num_controls: number of elements in the array |
| 1918 | * |
| 1919 | * Return 0 for success, else error. |
| 1920 | */ |
| 1921 | int snd_soc_add_platform_controls(struct snd_soc_platform *platform, |
Lars-Peter Clausen | 0f2780a | 2014-07-17 22:01:08 +0200 | [diff] [blame] | 1922 | const struct snd_kcontrol_new *controls, unsigned int num_controls) |
Liam Girdwood | a491a5c | 2011-07-04 22:10:51 +0100 | [diff] [blame] | 1923 | { |
Lars-Peter Clausen | 0f2780a | 2014-07-17 22:01:08 +0200 | [diff] [blame] | 1924 | return snd_soc_add_component_controls(&platform->component, controls, |
| 1925 | num_controls); |
Liam Girdwood | a491a5c | 2011-07-04 22:10:51 +0100 | [diff] [blame] | 1926 | } |
| 1927 | EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls); |
| 1928 | |
| 1929 | /** |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1930 | * snd_soc_add_card_controls - add an array of controls to a SoC card. |
| 1931 | * Convenience function to add a list of controls. |
| 1932 | * |
| 1933 | * @soc_card: SoC card to add controls to |
| 1934 | * @controls: array of controls to add |
| 1935 | * @num_controls: number of elements in the array |
| 1936 | * |
| 1937 | * Return 0 for success, else error. |
| 1938 | */ |
| 1939 | int snd_soc_add_card_controls(struct snd_soc_card *soc_card, |
| 1940 | const struct snd_kcontrol_new *controls, int num_controls) |
| 1941 | { |
| 1942 | struct snd_card *card = soc_card->snd_card; |
| 1943 | |
| 1944 | return snd_soc_add_controls(card, soc_card->dev, controls, num_controls, |
| 1945 | NULL, soc_card); |
| 1946 | } |
| 1947 | EXPORT_SYMBOL_GPL(snd_soc_add_card_controls); |
| 1948 | |
| 1949 | /** |
| 1950 | * snd_soc_add_dai_controls - add an array of controls to a DAI. |
| 1951 | * Convienience function to add a list of controls. |
| 1952 | * |
| 1953 | * @dai: DAI to add controls to |
| 1954 | * @controls: array of controls to add |
| 1955 | * @num_controls: number of elements in the array |
| 1956 | * |
| 1957 | * Return 0 for success, else error. |
| 1958 | */ |
| 1959 | int snd_soc_add_dai_controls(struct snd_soc_dai *dai, |
| 1960 | const struct snd_kcontrol_new *controls, int num_controls) |
| 1961 | { |
Lars-Peter Clausen | 313665b | 2014-11-04 11:30:58 +0100 | [diff] [blame] | 1962 | struct snd_card *card = dai->component->card->snd_card; |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1963 | |
| 1964 | return snd_soc_add_controls(card, dai->dev, controls, num_controls, |
| 1965 | NULL, dai); |
| 1966 | } |
| 1967 | EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls); |
| 1968 | |
| 1969 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 1970 | * snd_soc_dai_set_sysclk - configure DAI system or master clock. |
| 1971 | * @dai: DAI |
| 1972 | * @clk_id: DAI specific clock ID |
| 1973 | * @freq: new clock frequency in Hz |
| 1974 | * @dir: new clock direction - input/output. |
| 1975 | * |
| 1976 | * Configures the DAI master (MCLK) or system (SYSCLK) clocking. |
| 1977 | */ |
| 1978 | int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, |
| 1979 | unsigned int freq, int dir) |
| 1980 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1981 | if (dai->driver && dai->driver->ops->set_sysclk) |
| 1982 | return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir); |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 1983 | else if (dai->codec && dai->codec->driver->set_sysclk) |
Mark Brown | da1c6ea | 2011-08-24 20:09:01 +0100 | [diff] [blame] | 1984 | return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0, |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 1985 | freq, dir); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 1986 | else |
Mark Brown | 1104a9c | 2014-01-15 19:04:19 +0000 | [diff] [blame] | 1987 | return -ENOTSUPP; |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 1988 | } |
| 1989 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); |
| 1990 | |
| 1991 | /** |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 1992 | * snd_soc_codec_set_sysclk - configure CODEC system or master clock. |
| 1993 | * @codec: CODEC |
| 1994 | * @clk_id: DAI specific clock ID |
Mark Brown | da1c6ea | 2011-08-24 20:09:01 +0100 | [diff] [blame] | 1995 | * @source: Source for the clock |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 1996 | * @freq: new clock frequency in Hz |
| 1997 | * @dir: new clock direction - input/output. |
| 1998 | * |
| 1999 | * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. |
| 2000 | */ |
| 2001 | 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] | 2002 | int source, unsigned int freq, int dir) |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2003 | { |
| 2004 | if (codec->driver->set_sysclk) |
Mark Brown | da1c6ea | 2011-08-24 20:09:01 +0100 | [diff] [blame] | 2005 | return codec->driver->set_sysclk(codec, clk_id, source, |
| 2006 | freq, dir); |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2007 | else |
Mark Brown | 1104a9c | 2014-01-15 19:04:19 +0000 | [diff] [blame] | 2008 | return -ENOTSUPP; |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2009 | } |
| 2010 | EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk); |
| 2011 | |
| 2012 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2013 | * snd_soc_dai_set_clkdiv - configure DAI clock dividers. |
| 2014 | * @dai: DAI |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2015 | * @div_id: DAI specific clock divider ID |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2016 | * @div: new clock divisor. |
| 2017 | * |
| 2018 | * Configures the clock dividers. This is used to derive the best DAI bit and |
| 2019 | * frame clocks from the system or master clock. It's best to set the DAI bit |
| 2020 | * and frame clocks as low as possible to save system power. |
| 2021 | */ |
| 2022 | int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, |
| 2023 | int div_id, int div) |
| 2024 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2025 | if (dai->driver && dai->driver->ops->set_clkdiv) |
| 2026 | return dai->driver->ops->set_clkdiv(dai, div_id, div); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2027 | else |
| 2028 | return -EINVAL; |
| 2029 | } |
| 2030 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); |
| 2031 | |
| 2032 | /** |
| 2033 | * snd_soc_dai_set_pll - configure DAI PLL. |
| 2034 | * @dai: DAI |
| 2035 | * @pll_id: DAI specific PLL ID |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 2036 | * @source: DAI specific source for the PLL |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2037 | * @freq_in: PLL input clock frequency in Hz |
| 2038 | * @freq_out: requested PLL output clock frequency in Hz |
| 2039 | * |
| 2040 | * Configures and enables PLL to generate output clock based on input clock. |
| 2041 | */ |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 2042 | int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, |
| 2043 | unsigned int freq_in, unsigned int freq_out) |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2044 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2045 | if (dai->driver && dai->driver->ops->set_pll) |
| 2046 | return dai->driver->ops->set_pll(dai, pll_id, source, |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 2047 | freq_in, freq_out); |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2048 | else if (dai->codec && dai->codec->driver->set_pll) |
| 2049 | return dai->codec->driver->set_pll(dai->codec, pll_id, source, |
| 2050 | freq_in, freq_out); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2051 | else |
| 2052 | return -EINVAL; |
| 2053 | } |
| 2054 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); |
| 2055 | |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2056 | /* |
| 2057 | * snd_soc_codec_set_pll - configure codec PLL. |
| 2058 | * @codec: CODEC |
| 2059 | * @pll_id: DAI specific PLL ID |
| 2060 | * @source: DAI specific source for the PLL |
| 2061 | * @freq_in: PLL input clock frequency in Hz |
| 2062 | * @freq_out: requested PLL output clock frequency in Hz |
| 2063 | * |
| 2064 | * Configures and enables PLL to generate output clock based on input clock. |
| 2065 | */ |
| 2066 | int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source, |
| 2067 | unsigned int freq_in, unsigned int freq_out) |
| 2068 | { |
| 2069 | if (codec->driver->set_pll) |
| 2070 | return codec->driver->set_pll(codec, pll_id, source, |
| 2071 | freq_in, freq_out); |
| 2072 | else |
| 2073 | return -EINVAL; |
| 2074 | } |
| 2075 | EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll); |
| 2076 | |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2077 | /** |
Liam Girdwood | e54cf76 | 2013-09-16 13:01:46 +0100 | [diff] [blame] | 2078 | * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio. |
| 2079 | * @dai: DAI |
| 2080 | * @ratio Ratio of BCLK to Sample rate. |
| 2081 | * |
| 2082 | * Configures the DAI for a preset BCLK to sample rate ratio. |
| 2083 | */ |
| 2084 | int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio) |
| 2085 | { |
| 2086 | if (dai->driver && dai->driver->ops->set_bclk_ratio) |
| 2087 | return dai->driver->ops->set_bclk_ratio(dai, ratio); |
| 2088 | else |
| 2089 | return -EINVAL; |
| 2090 | } |
| 2091 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio); |
| 2092 | |
| 2093 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2094 | * snd_soc_dai_set_fmt - configure DAI hardware audio format. |
| 2095 | * @dai: DAI |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2096 | * @fmt: SND_SOC_DAIFMT_ format value. |
| 2097 | * |
| 2098 | * Configures the DAI hardware format and clocking. |
| 2099 | */ |
| 2100 | int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 2101 | { |
Shawn Guo | 5e4ba56 | 2012-03-09 00:59:40 +0800 | [diff] [blame] | 2102 | if (dai->driver == NULL) |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2103 | return -EINVAL; |
Shawn Guo | 5e4ba56 | 2012-03-09 00:59:40 +0800 | [diff] [blame] | 2104 | if (dai->driver->ops->set_fmt == NULL) |
| 2105 | return -ENOTSUPP; |
| 2106 | return dai->driver->ops->set_fmt(dai, fmt); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2107 | } |
| 2108 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt); |
| 2109 | |
| 2110 | /** |
Xiubo Li | e5c2151 | 2014-03-21 14:17:12 +0800 | [diff] [blame] | 2111 | * snd_soc_xlate_tdm_slot - generate tx/rx slot mask. |
Xiubo Li | 89c6785 | 2014-02-14 09:34:35 +0800 | [diff] [blame] | 2112 | * @slots: Number of slots in use. |
| 2113 | * @tx_mask: bitmask representing active TX slots. |
| 2114 | * @rx_mask: bitmask representing active RX slots. |
| 2115 | * |
| 2116 | * Generates the TDM tx and rx slot default masks for DAI. |
| 2117 | */ |
Xiubo Li | e5c2151 | 2014-03-21 14:17:12 +0800 | [diff] [blame] | 2118 | static int snd_soc_xlate_tdm_slot_mask(unsigned int slots, |
Xiubo Li | 89c6785 | 2014-02-14 09:34:35 +0800 | [diff] [blame] | 2119 | unsigned int *tx_mask, |
| 2120 | unsigned int *rx_mask) |
| 2121 | { |
| 2122 | if (*tx_mask || *rx_mask) |
| 2123 | return 0; |
| 2124 | |
| 2125 | if (!slots) |
| 2126 | return -EINVAL; |
| 2127 | |
| 2128 | *tx_mask = (1 << slots) - 1; |
| 2129 | *rx_mask = (1 << slots) - 1; |
| 2130 | |
| 2131 | return 0; |
| 2132 | } |
| 2133 | |
| 2134 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2135 | * snd_soc_dai_set_tdm_slot - configure DAI TDM. |
| 2136 | * @dai: DAI |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 2137 | * @tx_mask: bitmask representing active TX slots. |
| 2138 | * @rx_mask: bitmask representing active RX slots. |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2139 | * @slots: Number of slots in use. |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 2140 | * @slot_width: Width in bits for each slot. |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2141 | * |
| 2142 | * Configures a DAI for TDM operation. Both mask and slots are codec and DAI |
| 2143 | * specific. |
| 2144 | */ |
| 2145 | int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 2146 | 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] | 2147 | { |
Xiubo Li | e5c2151 | 2014-03-21 14:17:12 +0800 | [diff] [blame] | 2148 | if (dai->driver && dai->driver->ops->xlate_tdm_slot_mask) |
| 2149 | dai->driver->ops->xlate_tdm_slot_mask(slots, |
Xiubo Li | 89c6785 | 2014-02-14 09:34:35 +0800 | [diff] [blame] | 2150 | &tx_mask, &rx_mask); |
| 2151 | else |
Xiubo Li | e5c2151 | 2014-03-21 14:17:12 +0800 | [diff] [blame] | 2152 | snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask); |
Xiubo Li | 89c6785 | 2014-02-14 09:34:35 +0800 | [diff] [blame] | 2153 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2154 | dai->tx_mask = tx_mask; |
| 2155 | dai->rx_mask = rx_mask; |
| 2156 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2157 | if (dai->driver && dai->driver->ops->set_tdm_slot) |
| 2158 | return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask, |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 2159 | slots, slot_width); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2160 | else |
Xiubo Li | b2cbb6e | 2014-01-23 13:02:47 +0800 | [diff] [blame] | 2161 | return -ENOTSUPP; |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2162 | } |
| 2163 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); |
| 2164 | |
| 2165 | /** |
Barry Song | 472df3c | 2009-09-12 01:16:29 +0800 | [diff] [blame] | 2166 | * snd_soc_dai_set_channel_map - configure DAI audio channel map |
| 2167 | * @dai: DAI |
| 2168 | * @tx_num: how many TX channels |
| 2169 | * @tx_slot: pointer to an array which imply the TX slot number channel |
| 2170 | * 0~num-1 uses |
| 2171 | * @rx_num: how many RX channels |
| 2172 | * @rx_slot: pointer to an array which imply the RX slot number channel |
| 2173 | * 0~num-1 uses |
| 2174 | * |
| 2175 | * configure the relationship between channel number and TDM slot number. |
| 2176 | */ |
| 2177 | int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai, |
| 2178 | unsigned int tx_num, unsigned int *tx_slot, |
| 2179 | unsigned int rx_num, unsigned int *rx_slot) |
| 2180 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2181 | if (dai->driver && dai->driver->ops->set_channel_map) |
| 2182 | return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot, |
Barry Song | 472df3c | 2009-09-12 01:16:29 +0800 | [diff] [blame] | 2183 | rx_num, rx_slot); |
| 2184 | else |
| 2185 | return -EINVAL; |
| 2186 | } |
| 2187 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map); |
| 2188 | |
| 2189 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2190 | * snd_soc_dai_set_tristate - configure DAI system or master clock. |
| 2191 | * @dai: DAI |
| 2192 | * @tristate: tristate enable |
| 2193 | * |
| 2194 | * Tristates the DAI so that others can use it. |
| 2195 | */ |
| 2196 | int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) |
| 2197 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2198 | if (dai->driver && dai->driver->ops->set_tristate) |
| 2199 | return dai->driver->ops->set_tristate(dai, tristate); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2200 | else |
| 2201 | return -EINVAL; |
| 2202 | } |
| 2203 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate); |
| 2204 | |
| 2205 | /** |
| 2206 | * snd_soc_dai_digital_mute - configure DAI system or master clock. |
| 2207 | * @dai: DAI |
| 2208 | * @mute: mute enable |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 2209 | * @direction: stream to mute |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2210 | * |
| 2211 | * Mutes the DAI DAC. |
| 2212 | */ |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 2213 | int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute, |
| 2214 | int direction) |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2215 | { |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 2216 | if (!dai->driver) |
| 2217 | return -ENOTSUPP; |
| 2218 | |
| 2219 | if (dai->driver->ops->mute_stream) |
| 2220 | return dai->driver->ops->mute_stream(dai, mute, direction); |
| 2221 | else if (direction == SNDRV_PCM_STREAM_PLAYBACK && |
| 2222 | dai->driver->ops->digital_mute) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2223 | return dai->driver->ops->digital_mute(dai, mute); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2224 | else |
Mark Brown | 04570c6 | 2012-04-13 19:16:03 +0100 | [diff] [blame] | 2225 | return -ENOTSUPP; |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2226 | } |
| 2227 | EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); |
| 2228 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2229 | static int snd_soc_init_multicodec(struct snd_soc_card *card, |
| 2230 | struct snd_soc_dai_link *dai_link) |
| 2231 | { |
| 2232 | /* Legacy codec/codec_dai link is a single entry in multicodec */ |
| 2233 | if (dai_link->codec_name || dai_link->codec_of_node || |
| 2234 | dai_link->codec_dai_name) { |
| 2235 | dai_link->num_codecs = 1; |
| 2236 | |
| 2237 | dai_link->codecs = devm_kzalloc(card->dev, |
| 2238 | sizeof(struct snd_soc_dai_link_component), |
| 2239 | GFP_KERNEL); |
| 2240 | if (!dai_link->codecs) |
| 2241 | return -ENOMEM; |
| 2242 | |
| 2243 | dai_link->codecs[0].name = dai_link->codec_name; |
| 2244 | dai_link->codecs[0].of_node = dai_link->codec_of_node; |
| 2245 | dai_link->codecs[0].dai_name = dai_link->codec_dai_name; |
| 2246 | } |
| 2247 | |
| 2248 | if (!dai_link->codecs) { |
| 2249 | dev_err(card->dev, "ASoC: DAI link has no CODECs\n"); |
| 2250 | return -EINVAL; |
| 2251 | } |
| 2252 | |
| 2253 | return 0; |
| 2254 | } |
| 2255 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2256 | /** |
| 2257 | * snd_soc_register_card - Register a card with the ASoC core |
| 2258 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2259 | * @card: Card to register |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2260 | * |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2261 | */ |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 2262 | int snd_soc_register_card(struct snd_soc_card *card) |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2263 | { |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2264 | int i, j, ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2265 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2266 | if (!card->name || !card->dev) |
| 2267 | return -EINVAL; |
| 2268 | |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 2269 | for (i = 0; i < card->num_links; i++) { |
| 2270 | struct snd_soc_dai_link *link = &card->dai_link[i]; |
| 2271 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2272 | ret = snd_soc_init_multicodec(card, link); |
| 2273 | if (ret) { |
| 2274 | dev_err(card->dev, "ASoC: failed to init multicodec\n"); |
| 2275 | return ret; |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 2276 | } |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2277 | |
| 2278 | for (j = 0; j < link->num_codecs; j++) { |
| 2279 | /* |
| 2280 | * Codec must be specified by 1 of name or OF node, |
| 2281 | * not both or neither. |
| 2282 | */ |
| 2283 | if (!!link->codecs[j].name == |
| 2284 | !!link->codecs[j].of_node) { |
| 2285 | dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n", |
| 2286 | link->name); |
| 2287 | return -EINVAL; |
| 2288 | } |
| 2289 | /* Codec DAI name must be specified */ |
| 2290 | if (!link->codecs[j].dai_name) { |
| 2291 | dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n", |
| 2292 | link->name); |
| 2293 | return -EINVAL; |
| 2294 | } |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 2295 | } |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 2296 | |
| 2297 | /* |
| 2298 | * Platform may be specified by either name or OF node, but |
| 2299 | * can be left unspecified, and a dummy platform will be used. |
| 2300 | */ |
| 2301 | if (link->platform_name && link->platform_of_node) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 2302 | dev_err(card->dev, |
| 2303 | "ASoC: Both platform name/of_node are set for %s\n", |
| 2304 | link->name); |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 2305 | return -EINVAL; |
| 2306 | } |
| 2307 | |
| 2308 | /* |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 2309 | * CPU device may be specified by either name or OF node, but |
| 2310 | * can be left unspecified, and will be matched based on DAI |
| 2311 | * name alone.. |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 2312 | */ |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 2313 | if (link->cpu_name && link->cpu_of_node) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 2314 | dev_err(card->dev, |
| 2315 | "ASoC: Neither/both cpu name/of_node are set for %s\n", |
| 2316 | link->name); |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 2317 | return -EINVAL; |
| 2318 | } |
| 2319 | /* |
| 2320 | * At least one of CPU DAI name or CPU device name/node must be |
| 2321 | * specified |
| 2322 | */ |
| 2323 | if (!link->cpu_dai_name && |
| 2324 | !(link->cpu_name || link->cpu_of_node)) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 2325 | dev_err(card->dev, |
| 2326 | "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n", |
| 2327 | link->name); |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 2328 | return -EINVAL; |
| 2329 | } |
| 2330 | } |
| 2331 | |
Mark Brown | ed77cc1 | 2011-05-03 18:25:34 +0100 | [diff] [blame] | 2332 | dev_set_drvdata(card->dev, card); |
| 2333 | |
Stephen Warren | 111c641 | 2011-01-28 14:26:35 -0700 | [diff] [blame] | 2334 | snd_soc_initialize_card_lists(card); |
| 2335 | |
Vinod Koul | 150dd2f | 2011-01-13 22:48:32 +0530 | [diff] [blame] | 2336 | soc_init_card_debugfs(card); |
| 2337 | |
Mark Brown | 181a689 | 2012-03-14 20:18:49 +0000 | [diff] [blame] | 2338 | card->rtd = devm_kzalloc(card->dev, |
| 2339 | sizeof(struct snd_soc_pcm_runtime) * |
| 2340 | (card->num_links + card->num_aux_devs), |
| 2341 | GFP_KERNEL); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2342 | if (card->rtd == NULL) |
| 2343 | return -ENOMEM; |
Liam Girdwood | a7dbb60 | 2012-04-17 18:00:11 +0100 | [diff] [blame] | 2344 | card->num_rtd = 0; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 2345 | card->rtd_aux = &card->rtd[card->num_links]; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2346 | |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 2347 | for (i = 0; i < card->num_links; i++) { |
| 2348 | card->rtd[i].card = card; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2349 | card->rtd[i].dai_link = &card->dai_link[i]; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2350 | card->rtd[i].codec_dais = devm_kzalloc(card->dev, |
| 2351 | sizeof(struct snd_soc_dai *) * |
| 2352 | (card->rtd[i].dai_link->num_codecs), |
| 2353 | GFP_KERNEL); |
| 2354 | if (card->rtd[i].codec_dais == NULL) |
| 2355 | return -ENOMEM; |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | for (i = 0; i < card->num_aux_devs; i++) |
| 2359 | card->rtd_aux[i].card = card; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2360 | |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 2361 | INIT_LIST_HEAD(&card->dapm_dirty); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2362 | card->instantiated = 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2363 | mutex_init(&card->mutex); |
Liam Girdwood | a73fb2df | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2364 | mutex_init(&card->dapm_mutex); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2365 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 2366 | ret = snd_soc_instantiate_card(card); |
| 2367 | if (ret != 0) |
| 2368 | soc_cleanup_card_debugfs(card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2369 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 2370 | /* deactivate pins to sleep state */ |
| 2371 | for (i = 0; i < card->num_rtd; i++) { |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2372 | struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; |
| 2373 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 2374 | int j; |
| 2375 | |
| 2376 | for (j = 0; j < rtd->num_codecs; j++) { |
| 2377 | struct snd_soc_dai *codec_dai = rtd->codec_dais[j]; |
| 2378 | if (!codec_dai->active) |
| 2379 | pinctrl_pm_select_sleep_state(codec_dai->dev); |
| 2380 | } |
| 2381 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 2382 | if (!cpu_dai->active) |
| 2383 | pinctrl_pm_select_sleep_state(cpu_dai->dev); |
| 2384 | } |
| 2385 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 2386 | return ret; |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2387 | } |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 2388 | EXPORT_SYMBOL_GPL(snd_soc_register_card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2389 | |
| 2390 | /** |
| 2391 | * snd_soc_unregister_card - Unregister a card with the ASoC core |
| 2392 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2393 | * @card: Card to unregister |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2394 | * |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2395 | */ |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 2396 | int snd_soc_unregister_card(struct snd_soc_card *card) |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2397 | { |
Lars-Peter Clausen | 01e0df6 | 2014-09-04 19:44:04 +0200 | [diff] [blame] | 2398 | if (card->instantiated) { |
| 2399 | card->instantiated = false; |
Lars-Peter Clausen | 1c325f7 | 2014-09-04 19:44:05 +0200 | [diff] [blame] | 2400 | snd_soc_dapm_shutdown(card); |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 2401 | soc_cleanup_card_resources(card); |
Lars-Peter Clausen | 01e0df6 | 2014-09-04 19:44:04 +0200 | [diff] [blame] | 2402 | } |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 2403 | dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2404 | |
| 2405 | return 0; |
| 2406 | } |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 2407 | EXPORT_SYMBOL_GPL(snd_soc_unregister_card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2408 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2409 | /* |
| 2410 | * Simplify DAI link configuration by removing ".-1" from device names |
| 2411 | * and sanitizing names. |
| 2412 | */ |
Dimitris Papastamos | 0b9a214 | 2010-12-06 15:49:20 +0000 | [diff] [blame] | 2413 | static char *fmt_single_name(struct device *dev, int *id) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2414 | { |
| 2415 | char *found, name[NAME_SIZE]; |
| 2416 | int id1, id2; |
| 2417 | |
| 2418 | if (dev_name(dev) == NULL) |
| 2419 | return NULL; |
| 2420 | |
Dimitris Papastamos | 58818a7 | 2010-12-06 15:42:17 +0000 | [diff] [blame] | 2421 | strlcpy(name, dev_name(dev), NAME_SIZE); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2422 | |
| 2423 | /* are we a "%s.%d" name (platform and SPI components) */ |
| 2424 | found = strstr(name, dev->driver->name); |
| 2425 | if (found) { |
| 2426 | /* get ID */ |
| 2427 | if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) { |
| 2428 | |
| 2429 | /* discard ID from name if ID == -1 */ |
| 2430 | if (*id == -1) |
| 2431 | found[strlen(dev->driver->name)] = '\0'; |
| 2432 | } |
| 2433 | |
| 2434 | } else { |
| 2435 | /* I2C component devices are named "bus-addr" */ |
| 2436 | if (sscanf(name, "%x-%x", &id1, &id2) == 2) { |
| 2437 | char tmp[NAME_SIZE]; |
| 2438 | |
| 2439 | /* create unique ID number from I2C addr and bus */ |
Jarkko Nikula | 0589944 | 2010-10-19 11:10:45 +0300 | [diff] [blame] | 2440 | *id = ((id1 & 0xffff) << 16) + id2; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2441 | |
| 2442 | /* sanitize component name for DAI link creation */ |
| 2443 | snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name); |
Dimitris Papastamos | 58818a7 | 2010-12-06 15:42:17 +0000 | [diff] [blame] | 2444 | strlcpy(name, tmp, NAME_SIZE); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2445 | } else |
| 2446 | *id = 0; |
| 2447 | } |
| 2448 | |
| 2449 | return kstrdup(name, GFP_KERNEL); |
| 2450 | } |
| 2451 | |
| 2452 | /* |
| 2453 | * Simplify DAI link naming for single devices with multiple DAIs by removing |
| 2454 | * any ".-1" and using the DAI name (instead of device name). |
| 2455 | */ |
| 2456 | static inline char *fmt_multiple_name(struct device *dev, |
| 2457 | struct snd_soc_dai_driver *dai_drv) |
| 2458 | { |
| 2459 | if (dai_drv->name == NULL) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 2460 | dev_err(dev, |
| 2461 | "ASoC: error - multiple DAI %s registered with no name\n", |
| 2462 | dev_name(dev)); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2463 | return NULL; |
| 2464 | } |
| 2465 | |
| 2466 | return kstrdup(dai_drv->name, GFP_KERNEL); |
| 2467 | } |
| 2468 | |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2469 | /** |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2470 | * snd_soc_unregister_dai - Unregister DAIs from the ASoC core |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2471 | * |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2472 | * @component: The component for which the DAIs should be unregistered |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2473 | */ |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2474 | static void snd_soc_unregister_dais(struct snd_soc_component *component) |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2475 | { |
Lars-Peter Clausen | 5c1d5f0 | 2014-03-12 08:34:39 +0100 | [diff] [blame] | 2476 | struct snd_soc_dai *dai, *_dai; |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2477 | |
Lars-Peter Clausen | 5c1d5f0 | 2014-03-12 08:34:39 +0100 | [diff] [blame] | 2478 | list_for_each_entry_safe(dai, _dai, &component->dai_list, list) { |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2479 | dev_dbg(component->dev, "ASoC: Unregistered DAI '%s'\n", |
| 2480 | dai->name); |
Lars-Peter Clausen | 5c1d5f0 | 2014-03-12 08:34:39 +0100 | [diff] [blame] | 2481 | list_del(&dai->list); |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2482 | kfree(dai->name); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2483 | kfree(dai); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2484 | } |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2485 | } |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2486 | |
| 2487 | /** |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2488 | * snd_soc_register_dais - Register a DAI with the ASoC core |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2489 | * |
Lars-Peter Clausen | 6106d12 | 2014-03-05 13:17:46 +0100 | [diff] [blame] | 2490 | * @component: The component the DAIs are registered for |
| 2491 | * @dai_drv: DAI driver to use for the DAIs |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2492 | * @count: Number of DAIs |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2493 | * @legacy_dai_naming: Use the legacy naming scheme and let the DAI inherit the |
| 2494 | * parent's name. |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2495 | */ |
Lars-Peter Clausen | 6106d12 | 2014-03-05 13:17:46 +0100 | [diff] [blame] | 2496 | static int snd_soc_register_dais(struct snd_soc_component *component, |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2497 | struct snd_soc_dai_driver *dai_drv, size_t count, |
| 2498 | bool legacy_dai_naming) |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2499 | { |
Lars-Peter Clausen | 6106d12 | 2014-03-05 13:17:46 +0100 | [diff] [blame] | 2500 | struct device *dev = component->dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2501 | struct snd_soc_dai *dai; |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2502 | unsigned int i; |
| 2503 | int ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2504 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 2505 | 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] | 2506 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2507 | component->dai_drv = dai_drv; |
| 2508 | component->num_dai = count; |
| 2509 | |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2510 | for (i = 0; i < count; i++) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2511 | |
| 2512 | dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); |
Axel Lin | c46e007 | 2010-11-03 15:04:45 +0800 | [diff] [blame] | 2513 | if (dai == NULL) { |
| 2514 | ret = -ENOMEM; |
| 2515 | goto err; |
| 2516 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2517 | |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2518 | /* |
| 2519 | * Back in the old days when we still had component-less DAIs, |
| 2520 | * instead of having a static name, component-less DAIs would |
| 2521 | * inherit the name of the parent device so it is possible to |
| 2522 | * register multiple instances of the DAI. We still need to keep |
| 2523 | * the same naming style even though those DAIs are not |
| 2524 | * component-less anymore. |
| 2525 | */ |
| 2526 | if (count == 1 && legacy_dai_naming) { |
| 2527 | dai->name = fmt_single_name(dev, &dai->id); |
| 2528 | } else { |
| 2529 | dai->name = fmt_multiple_name(dev, &dai_drv[i]); |
| 2530 | if (dai_drv[i].id) |
| 2531 | dai->id = dai_drv[i].id; |
| 2532 | else |
| 2533 | dai->id = i; |
| 2534 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2535 | if (dai->name == NULL) { |
| 2536 | kfree(dai); |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2537 | ret = -ENOMEM; |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2538 | goto err; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2539 | } |
| 2540 | |
Lars-Peter Clausen | 6106d12 | 2014-03-05 13:17:46 +0100 | [diff] [blame] | 2541 | dai->component = component; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2542 | dai->dev = dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2543 | dai->driver = &dai_drv[i]; |
| 2544 | if (!dai->driver->ops) |
| 2545 | dai->driver->ops = &null_dai_ops; |
| 2546 | |
Lars-Peter Clausen | 1438c2f | 2014-03-09 17:41:47 +0100 | [diff] [blame] | 2547 | list_add(&dai->list, &component->dai_list); |
Mark Brown | 054880f | 2012-04-09 17:29:19 +0100 | [diff] [blame] | 2548 | |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2549 | dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | return 0; |
| 2553 | |
| 2554 | err: |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2555 | snd_soc_unregister_dais(component); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2556 | |
| 2557 | return ret; |
| 2558 | } |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2559 | |
Lars-Peter Clausen | 14e8bde | 2014-06-16 18:13:08 +0200 | [diff] [blame] | 2560 | static void snd_soc_component_seq_notifier(struct snd_soc_dapm_context *dapm, |
| 2561 | enum snd_soc_dapm_type type, int subseq) |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2562 | { |
Lars-Peter Clausen | 14e8bde | 2014-06-16 18:13:08 +0200 | [diff] [blame] | 2563 | struct snd_soc_component *component = dapm->component; |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2564 | |
Lars-Peter Clausen | 14e8bde | 2014-06-16 18:13:08 +0200 | [diff] [blame] | 2565 | component->driver->seq_notifier(component, type, subseq); |
| 2566 | } |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2567 | |
Lars-Peter Clausen | 14e8bde | 2014-06-16 18:13:08 +0200 | [diff] [blame] | 2568 | static int snd_soc_component_stream_event(struct snd_soc_dapm_context *dapm, |
| 2569 | int event) |
| 2570 | { |
| 2571 | struct snd_soc_component *component = dapm->component; |
| 2572 | |
| 2573 | return component->driver->stream_event(component, event); |
| 2574 | } |
| 2575 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2576 | static int snd_soc_component_initialize(struct snd_soc_component *component, |
| 2577 | const struct snd_soc_component_driver *driver, struct device *dev) |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2578 | { |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 2579 | struct snd_soc_dapm_context *dapm; |
| 2580 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2581 | component->name = fmt_single_name(dev, &component->id); |
| 2582 | if (!component->name) { |
| 2583 | dev_err(dev, "ASoC: Failed to allocate name\n"); |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2584 | return -ENOMEM; |
| 2585 | } |
| 2586 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2587 | component->dev = dev; |
| 2588 | component->driver = driver; |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 2589 | component->probe = component->driver->probe; |
| 2590 | component->remove = component->driver->remove; |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 2591 | |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 2592 | if (!component->dapm_ptr) |
| 2593 | component->dapm_ptr = &component->dapm; |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2594 | |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 2595 | dapm = component->dapm_ptr; |
| 2596 | dapm->dev = dev; |
| 2597 | dapm->component = component; |
| 2598 | dapm->bias_level = SND_SOC_BIAS_OFF; |
Lars-Peter Clausen | 5819c2f | 2014-08-24 15:36:55 +0200 | [diff] [blame] | 2599 | dapm->idle_bias_off = true; |
Lars-Peter Clausen | 14e8bde | 2014-06-16 18:13:08 +0200 | [diff] [blame] | 2600 | if (driver->seq_notifier) |
| 2601 | dapm->seq_notifier = snd_soc_component_seq_notifier; |
| 2602 | if (driver->stream_event) |
| 2603 | dapm->stream_event = snd_soc_component_stream_event; |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2604 | |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 2605 | component->controls = driver->controls; |
| 2606 | component->num_controls = driver->num_controls; |
| 2607 | component->dapm_widgets = driver->dapm_widgets; |
| 2608 | component->num_dapm_widgets = driver->num_dapm_widgets; |
| 2609 | component->dapm_routes = driver->dapm_routes; |
| 2610 | component->num_dapm_routes = driver->num_dapm_routes; |
| 2611 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2612 | INIT_LIST_HEAD(&component->dai_list); |
| 2613 | mutex_init(&component->io_mutex); |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2614 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2615 | return 0; |
| 2616 | } |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2617 | |
Lars-Peter Clausen | 20feb88 | 2014-11-18 19:45:52 +0100 | [diff] [blame] | 2618 | static void snd_soc_component_setup_regmap(struct snd_soc_component *component) |
Lars-Peter Clausen | 886f569 | 2014-08-19 15:51:28 +0200 | [diff] [blame] | 2619 | { |
Lars-Peter Clausen | 20feb88 | 2014-11-18 19:45:52 +0100 | [diff] [blame] | 2620 | int val_bytes = regmap_get_val_bytes(component->regmap); |
| 2621 | |
| 2622 | /* Errors are legitimate for non-integer byte multiples */ |
| 2623 | if (val_bytes > 0) |
| 2624 | component->val_bytes = val_bytes; |
Lars-Peter Clausen | 886f569 | 2014-08-19 15:51:28 +0200 | [diff] [blame] | 2625 | } |
| 2626 | |
Lars-Peter Clausen | e874bf5 | 2014-11-25 21:41:03 +0100 | [diff] [blame] | 2627 | #ifdef CONFIG_REGMAP |
| 2628 | |
Lars-Peter Clausen | 20feb88 | 2014-11-18 19:45:52 +0100 | [diff] [blame] | 2629 | /** |
| 2630 | * snd_soc_component_init_regmap() - Initialize regmap instance for the component |
| 2631 | * @component: The component for which to initialize the regmap instance |
| 2632 | * @regmap: The regmap instance that should be used by the component |
| 2633 | * |
| 2634 | * This function allows deferred assignment of the regmap instance that is |
| 2635 | * associated with the component. Only use this if the regmap instance is not |
| 2636 | * yet ready when the component is registered. The function must also be called |
| 2637 | * before the first IO attempt of the component. |
| 2638 | */ |
| 2639 | void snd_soc_component_init_regmap(struct snd_soc_component *component, |
| 2640 | struct regmap *regmap) |
| 2641 | { |
| 2642 | component->regmap = regmap; |
| 2643 | snd_soc_component_setup_regmap(component); |
| 2644 | } |
| 2645 | EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap); |
| 2646 | |
| 2647 | /** |
| 2648 | * snd_soc_component_exit_regmap() - De-initialize regmap instance for the component |
| 2649 | * @component: The component for which to de-initialize the regmap instance |
| 2650 | * |
| 2651 | * Calls regmap_exit() on the regmap instance associated to the component and |
| 2652 | * removes the regmap instance from the component. |
| 2653 | * |
| 2654 | * This function should only be used if snd_soc_component_init_regmap() was used |
| 2655 | * to initialize the regmap instance. |
| 2656 | */ |
| 2657 | void snd_soc_component_exit_regmap(struct snd_soc_component *component) |
| 2658 | { |
| 2659 | regmap_exit(component->regmap); |
| 2660 | component->regmap = NULL; |
| 2661 | } |
| 2662 | EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap); |
| 2663 | |
Lars-Peter Clausen | e874bf5 | 2014-11-25 21:41:03 +0100 | [diff] [blame] | 2664 | #endif |
| 2665 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2666 | static void snd_soc_component_add_unlocked(struct snd_soc_component *component) |
| 2667 | { |
Lars-Peter Clausen | 20feb88 | 2014-11-18 19:45:52 +0100 | [diff] [blame] | 2668 | if (!component->write && !component->read) { |
| 2669 | if (!component->regmap) |
| 2670 | component->regmap = dev_get_regmap(component->dev, NULL); |
| 2671 | if (component->regmap) |
| 2672 | snd_soc_component_setup_regmap(component); |
| 2673 | } |
Lars-Peter Clausen | 886f569 | 2014-08-19 15:51:28 +0200 | [diff] [blame] | 2674 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2675 | list_add(&component->list, &component_list); |
| 2676 | } |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2677 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2678 | static void snd_soc_component_add(struct snd_soc_component *component) |
| 2679 | { |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2680 | mutex_lock(&client_mutex); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2681 | snd_soc_component_add_unlocked(component); |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2682 | mutex_unlock(&client_mutex); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2683 | } |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2684 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2685 | static void snd_soc_component_cleanup(struct snd_soc_component *component) |
| 2686 | { |
| 2687 | snd_soc_unregister_dais(component); |
| 2688 | kfree(component->name); |
| 2689 | } |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2690 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2691 | static void snd_soc_component_del_unlocked(struct snd_soc_component *component) |
| 2692 | { |
| 2693 | list_del(&component->list); |
| 2694 | } |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2695 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2696 | static void snd_soc_component_del(struct snd_soc_component *component) |
| 2697 | { |
| 2698 | mutex_lock(&client_mutex); |
| 2699 | snd_soc_component_del_unlocked(component); |
| 2700 | mutex_unlock(&client_mutex); |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | int snd_soc_register_component(struct device *dev, |
| 2704 | const struct snd_soc_component_driver *cmpnt_drv, |
| 2705 | struct snd_soc_dai_driver *dai_drv, |
| 2706 | int num_dai) |
| 2707 | { |
| 2708 | struct snd_soc_component *cmpnt; |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2709 | int ret; |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2710 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2711 | cmpnt = kzalloc(sizeof(*cmpnt), GFP_KERNEL); |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2712 | if (!cmpnt) { |
| 2713 | dev_err(dev, "ASoC: Failed to allocate memory\n"); |
| 2714 | return -ENOMEM; |
| 2715 | } |
| 2716 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2717 | ret = snd_soc_component_initialize(cmpnt, cmpnt_drv, dev); |
| 2718 | if (ret) |
| 2719 | goto err_free; |
| 2720 | |
Lars-Peter Clausen | 3d59400 | 2014-03-05 13:17:48 +0100 | [diff] [blame] | 2721 | cmpnt->ignore_pmdown_time = true; |
Lars-Peter Clausen | 98e639f | 2014-03-18 09:02:11 +0100 | [diff] [blame] | 2722 | cmpnt->registered_as_component = true; |
Lars-Peter Clausen | 3d59400 | 2014-03-05 13:17:48 +0100 | [diff] [blame] | 2723 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2724 | ret = snd_soc_register_dais(cmpnt, dai_drv, num_dai, true); |
| 2725 | if (ret < 0) { |
| 2726 | dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret); |
| 2727 | goto err_cleanup; |
| 2728 | } |
| 2729 | |
| 2730 | snd_soc_component_add(cmpnt); |
| 2731 | |
| 2732 | return 0; |
| 2733 | |
| 2734 | err_cleanup: |
| 2735 | snd_soc_component_cleanup(cmpnt); |
| 2736 | err_free: |
| 2737 | kfree(cmpnt); |
| 2738 | return ret; |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2739 | } |
| 2740 | EXPORT_SYMBOL_GPL(snd_soc_register_component); |
| 2741 | |
| 2742 | /** |
| 2743 | * snd_soc_unregister_component - Unregister a component from the ASoC core |
| 2744 | * |
| 2745 | */ |
| 2746 | void snd_soc_unregister_component(struct device *dev) |
| 2747 | { |
| 2748 | struct snd_soc_component *cmpnt; |
| 2749 | |
| 2750 | list_for_each_entry(cmpnt, &component_list, list) { |
Lars-Peter Clausen | 98e639f | 2014-03-18 09:02:11 +0100 | [diff] [blame] | 2751 | if (dev == cmpnt->dev && cmpnt->registered_as_component) |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2752 | goto found; |
| 2753 | } |
| 2754 | return; |
| 2755 | |
| 2756 | found: |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2757 | snd_soc_component_del(cmpnt); |
| 2758 | snd_soc_component_cleanup(cmpnt); |
| 2759 | kfree(cmpnt); |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2760 | } |
| 2761 | EXPORT_SYMBOL_GPL(snd_soc_unregister_component); |
| 2762 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 2763 | static int snd_soc_platform_drv_probe(struct snd_soc_component *component) |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 2764 | { |
| 2765 | struct snd_soc_platform *platform = snd_soc_component_to_platform(component); |
| 2766 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 2767 | return platform->driver->probe(platform); |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 2768 | } |
| 2769 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 2770 | static void snd_soc_platform_drv_remove(struct snd_soc_component *component) |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 2771 | { |
| 2772 | struct snd_soc_platform *platform = snd_soc_component_to_platform(component); |
| 2773 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 2774 | platform->driver->remove(platform); |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 2775 | } |
| 2776 | |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2777 | /** |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2778 | * snd_soc_add_platform - Add a platform to the ASoC core |
| 2779 | * @dev: The parent device for the platform |
| 2780 | * @platform: The platform to add |
| 2781 | * @platform_driver: The driver for the platform |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2782 | */ |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2783 | 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] | 2784 | const struct snd_soc_platform_driver *platform_drv) |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2785 | { |
Lars-Peter Clausen | b37f1d1 | 2014-03-18 09:02:12 +0100 | [diff] [blame] | 2786 | int ret; |
| 2787 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2788 | ret = snd_soc_component_initialize(&platform->component, |
| 2789 | &platform_drv->component_driver, dev); |
| 2790 | if (ret) |
| 2791 | return ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2792 | |
| 2793 | platform->dev = dev; |
| 2794 | platform->driver = platform_drv; |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 2795 | |
| 2796 | if (platform_drv->probe) |
| 2797 | platform->component.probe = snd_soc_platform_drv_probe; |
| 2798 | if (platform_drv->remove) |
| 2799 | platform->component.remove = snd_soc_platform_drv_remove; |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2800 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 2801 | #ifdef CONFIG_DEBUG_FS |
| 2802 | platform->component.debugfs_prefix = "platform"; |
| 2803 | #endif |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2804 | |
| 2805 | mutex_lock(&client_mutex); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2806 | snd_soc_component_add_unlocked(&platform->component); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2807 | list_add(&platform->list, &platform_list); |
| 2808 | mutex_unlock(&client_mutex); |
| 2809 | |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 2810 | dev_dbg(dev, "ASoC: Registered platform '%s'\n", |
| 2811 | platform->component.name); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2812 | |
| 2813 | return 0; |
| 2814 | } |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2815 | EXPORT_SYMBOL_GPL(snd_soc_add_platform); |
| 2816 | |
| 2817 | /** |
| 2818 | * snd_soc_register_platform - Register a platform with the ASoC core |
| 2819 | * |
| 2820 | * @platform: platform to register |
| 2821 | */ |
| 2822 | int snd_soc_register_platform(struct device *dev, |
| 2823 | const struct snd_soc_platform_driver *platform_drv) |
| 2824 | { |
| 2825 | struct snd_soc_platform *platform; |
| 2826 | int ret; |
| 2827 | |
| 2828 | dev_dbg(dev, "ASoC: platform register %s\n", dev_name(dev)); |
| 2829 | |
| 2830 | platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL); |
| 2831 | if (platform == NULL) |
| 2832 | return -ENOMEM; |
| 2833 | |
| 2834 | ret = snd_soc_add_platform(dev, platform, platform_drv); |
| 2835 | if (ret) |
| 2836 | kfree(platform); |
| 2837 | |
| 2838 | return ret; |
| 2839 | } |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2840 | EXPORT_SYMBOL_GPL(snd_soc_register_platform); |
| 2841 | |
| 2842 | /** |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2843 | * snd_soc_remove_platform - Remove a platform from the ASoC core |
| 2844 | * @platform: the platform to remove |
| 2845 | */ |
| 2846 | void snd_soc_remove_platform(struct snd_soc_platform *platform) |
| 2847 | { |
Lars-Peter Clausen | b37f1d1 | 2014-03-18 09:02:12 +0100 | [diff] [blame] | 2848 | |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2849 | mutex_lock(&client_mutex); |
| 2850 | list_del(&platform->list); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2851 | snd_soc_component_del_unlocked(&platform->component); |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2852 | mutex_unlock(&client_mutex); |
| 2853 | |
| 2854 | dev_dbg(platform->dev, "ASoC: Unregistered platform '%s'\n", |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 2855 | platform->component.name); |
Daniel Mack | decc27b | 2014-10-07 13:41:23 +0200 | [diff] [blame] | 2856 | |
| 2857 | snd_soc_component_cleanup(&platform->component); |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2858 | } |
| 2859 | EXPORT_SYMBOL_GPL(snd_soc_remove_platform); |
| 2860 | |
| 2861 | struct snd_soc_platform *snd_soc_lookup_platform(struct device *dev) |
| 2862 | { |
| 2863 | struct snd_soc_platform *platform; |
| 2864 | |
| 2865 | list_for_each_entry(platform, &platform_list, list) { |
| 2866 | if (dev == platform->dev) |
| 2867 | return platform; |
| 2868 | } |
| 2869 | |
| 2870 | return NULL; |
| 2871 | } |
| 2872 | EXPORT_SYMBOL_GPL(snd_soc_lookup_platform); |
| 2873 | |
| 2874 | /** |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2875 | * snd_soc_unregister_platform - Unregister a platform from the ASoC core |
| 2876 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2877 | * @platform: platform to unregister |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2878 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2879 | void snd_soc_unregister_platform(struct device *dev) |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2880 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2881 | struct snd_soc_platform *platform; |
| 2882 | |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2883 | platform = snd_soc_lookup_platform(dev); |
| 2884 | if (!platform) |
| 2885 | return; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2886 | |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2887 | snd_soc_remove_platform(platform); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2888 | kfree(platform); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2889 | } |
| 2890 | EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); |
| 2891 | |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 2892 | static u64 codec_format_map[] = { |
| 2893 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE, |
| 2894 | SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE, |
| 2895 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE, |
| 2896 | SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, |
| 2897 | SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE, |
| 2898 | SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE, |
| 2899 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, |
| 2900 | SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, |
| 2901 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE, |
| 2902 | SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE, |
| 2903 | SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE, |
| 2904 | SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE, |
| 2905 | SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE, |
| 2906 | SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE, |
| 2907 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE |
| 2908 | | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE, |
| 2909 | }; |
| 2910 | |
| 2911 | /* Fix up the DAI formats for endianness: codecs don't actually see |
| 2912 | * the endianness of the data but we're using the CPU format |
| 2913 | * definitions which do need to include endianness so we ensure that |
| 2914 | * codec DAIs always have both big and little endian variants set. |
| 2915 | */ |
| 2916 | static void fixup_codec_formats(struct snd_soc_pcm_stream *stream) |
| 2917 | { |
| 2918 | int i; |
| 2919 | |
| 2920 | for (i = 0; i < ARRAY_SIZE(codec_format_map); i++) |
| 2921 | if (stream->formats & codec_format_map[i]) |
| 2922 | stream->formats |= codec_format_map[i]; |
| 2923 | } |
| 2924 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 2925 | static int snd_soc_codec_drv_probe(struct snd_soc_component *component) |
| 2926 | { |
| 2927 | struct snd_soc_codec *codec = snd_soc_component_to_codec(component); |
| 2928 | |
| 2929 | return codec->driver->probe(codec); |
| 2930 | } |
| 2931 | |
| 2932 | static void snd_soc_codec_drv_remove(struct snd_soc_component *component) |
| 2933 | { |
| 2934 | struct snd_soc_codec *codec = snd_soc_component_to_codec(component); |
| 2935 | |
| 2936 | codec->driver->remove(codec); |
| 2937 | } |
| 2938 | |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 2939 | static int snd_soc_codec_drv_write(struct snd_soc_component *component, |
| 2940 | unsigned int reg, unsigned int val) |
| 2941 | { |
| 2942 | struct snd_soc_codec *codec = snd_soc_component_to_codec(component); |
| 2943 | |
| 2944 | return codec->driver->write(codec, reg, val); |
| 2945 | } |
| 2946 | |
| 2947 | static int snd_soc_codec_drv_read(struct snd_soc_component *component, |
| 2948 | unsigned int reg, unsigned int *val) |
| 2949 | { |
| 2950 | struct snd_soc_codec *codec = snd_soc_component_to_codec(component); |
| 2951 | |
| 2952 | *val = codec->driver->read(codec, reg); |
| 2953 | |
| 2954 | return 0; |
| 2955 | } |
| 2956 | |
Lars-Peter Clausen | 68f831c | 2014-06-16 18:13:05 +0200 | [diff] [blame] | 2957 | static int snd_soc_codec_set_bias_level(struct snd_soc_dapm_context *dapm, |
| 2958 | enum snd_soc_bias_level level) |
| 2959 | { |
| 2960 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm); |
| 2961 | |
| 2962 | return codec->driver->set_bias_level(codec, level); |
| 2963 | } |
| 2964 | |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 2965 | /** |
| 2966 | * snd_soc_register_codec - Register a codec with the ASoC core |
| 2967 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2968 | * @codec: codec to register |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 2969 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2970 | int snd_soc_register_codec(struct device *dev, |
Mark Brown | 001ae4c | 2010-12-02 16:21:08 +0000 | [diff] [blame] | 2971 | const struct snd_soc_codec_driver *codec_drv, |
| 2972 | struct snd_soc_dai_driver *dai_drv, |
| 2973 | int num_dai) |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 2974 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2975 | struct snd_soc_codec *codec; |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2976 | struct snd_soc_dai *dai; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2977 | int ret, i; |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 2978 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2979 | dev_dbg(dev, "codec register %s\n", dev_name(dev)); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 2980 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2981 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
| 2982 | if (codec == NULL) |
| 2983 | return -ENOMEM; |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 2984 | |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 2985 | codec->component.dapm_ptr = &codec->dapm; |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 2986 | codec->component.codec = codec; |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 2987 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2988 | ret = snd_soc_component_initialize(&codec->component, |
| 2989 | &codec_drv->component_driver, dev); |
| 2990 | if (ret) |
| 2991 | goto err_free; |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 2992 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 2993 | if (codec_drv->controls) { |
| 2994 | codec->component.controls = codec_drv->controls; |
| 2995 | codec->component.num_controls = codec_drv->num_controls; |
| 2996 | } |
| 2997 | if (codec_drv->dapm_widgets) { |
| 2998 | codec->component.dapm_widgets = codec_drv->dapm_widgets; |
| 2999 | codec->component.num_dapm_widgets = codec_drv->num_dapm_widgets; |
| 3000 | } |
| 3001 | if (codec_drv->dapm_routes) { |
| 3002 | codec->component.dapm_routes = codec_drv->dapm_routes; |
| 3003 | codec->component.num_dapm_routes = codec_drv->num_dapm_routes; |
| 3004 | } |
| 3005 | |
| 3006 | if (codec_drv->probe) |
| 3007 | codec->component.probe = snd_soc_codec_drv_probe; |
| 3008 | if (codec_drv->remove) |
| 3009 | codec->component.remove = snd_soc_codec_drv_remove; |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 3010 | if (codec_drv->write) |
| 3011 | codec->component.write = snd_soc_codec_drv_write; |
| 3012 | if (codec_drv->read) |
| 3013 | codec->component.read = snd_soc_codec_drv_read; |
Lars-Peter Clausen | 3d59400 | 2014-03-05 13:17:48 +0100 | [diff] [blame] | 3014 | codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time; |
Lars-Peter Clausen | 5819c2f | 2014-08-24 15:36:55 +0200 | [diff] [blame] | 3015 | codec->dapm.idle_bias_off = codec_drv->idle_bias_off; |
Lars-Peter Clausen | 86dbf2a | 2014-09-04 19:44:06 +0200 | [diff] [blame] | 3016 | codec->dapm.suspend_bias_off = codec_drv->suspend_bias_off; |
Lars-Peter Clausen | 14e8bde | 2014-06-16 18:13:08 +0200 | [diff] [blame] | 3017 | if (codec_drv->seq_notifier) |
| 3018 | codec->dapm.seq_notifier = codec_drv->seq_notifier; |
Lars-Peter Clausen | 68f831c | 2014-06-16 18:13:05 +0200 | [diff] [blame] | 3019 | if (codec_drv->set_bias_level) |
| 3020 | codec->dapm.set_bias_level = snd_soc_codec_set_bias_level; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3021 | codec->dev = dev; |
| 3022 | codec->driver = codec_drv; |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 3023 | codec->component.val_bytes = codec_drv->reg_word_size; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3024 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 3025 | #ifdef CONFIG_DEBUG_FS |
| 3026 | codec->component.init_debugfs = soc_init_codec_debugfs; |
| 3027 | codec->component.debugfs_prefix = "codec"; |
| 3028 | #endif |
Xiubo Li | a39f75f | 2014-03-26 13:40:23 +0800 | [diff] [blame] | 3029 | |
Lars-Peter Clausen | 886f569 | 2014-08-19 15:51:28 +0200 | [diff] [blame] | 3030 | if (codec_drv->get_regmap) |
| 3031 | codec->component.regmap = codec_drv->get_regmap(dev); |
Xiubo Li | a39f75f | 2014-03-26 13:40:23 +0800 | [diff] [blame] | 3032 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3033 | for (i = 0; i < num_dai; i++) { |
| 3034 | fixup_codec_formats(&dai_drv[i].playback); |
| 3035 | fixup_codec_formats(&dai_drv[i].capture); |
| 3036 | } |
| 3037 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 3038 | ret = snd_soc_register_dais(&codec->component, dai_drv, num_dai, false); |
| 3039 | if (ret < 0) { |
| 3040 | dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret); |
| 3041 | goto err_cleanup; |
| 3042 | } |
| 3043 | |
| 3044 | list_for_each_entry(dai, &codec->component.dai_list, list) |
| 3045 | dai->codec = codec; |
| 3046 | |
Mark Brown | 054880f | 2012-04-09 17:29:19 +0100 | [diff] [blame] | 3047 | mutex_lock(&client_mutex); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 3048 | snd_soc_component_add_unlocked(&codec->component); |
Mark Brown | 054880f | 2012-04-09 17:29:19 +0100 | [diff] [blame] | 3049 | list_add(&codec->list, &codec_list); |
| 3050 | mutex_unlock(&client_mutex); |
| 3051 | |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 3052 | dev_dbg(codec->dev, "ASoC: Registered codec '%s'\n", |
| 3053 | codec->component.name); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3054 | return 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3055 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 3056 | err_cleanup: |
| 3057 | snd_soc_component_cleanup(&codec->component); |
| 3058 | err_free: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3059 | kfree(codec); |
| 3060 | return ret; |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3061 | } |
| 3062 | EXPORT_SYMBOL_GPL(snd_soc_register_codec); |
| 3063 | |
| 3064 | /** |
| 3065 | * snd_soc_unregister_codec - Unregister a codec from the ASoC core |
| 3066 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3067 | * @codec: codec to unregister |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3068 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3069 | void snd_soc_unregister_codec(struct device *dev) |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3070 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3071 | struct snd_soc_codec *codec; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3072 | |
| 3073 | list_for_each_entry(codec, &codec_list, list) { |
| 3074 | if (dev == codec->dev) |
| 3075 | goto found; |
| 3076 | } |
| 3077 | return; |
| 3078 | |
| 3079 | found: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3080 | |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3081 | mutex_lock(&client_mutex); |
| 3082 | list_del(&codec->list); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 3083 | snd_soc_component_del_unlocked(&codec->component); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3084 | mutex_unlock(&client_mutex); |
| 3085 | |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 3086 | dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", |
| 3087 | codec->component.name); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3088 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 3089 | snd_soc_component_cleanup(&codec->component); |
Dimitris Papastamos | 7a30a3d | 2010-11-11 10:04:57 +0000 | [diff] [blame] | 3090 | snd_soc_cache_exit(codec); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3091 | kfree(codec); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3092 | } |
| 3093 | EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); |
| 3094 | |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 3095 | /* Retrieve a card's name from device tree */ |
| 3096 | int snd_soc_of_parse_card_name(struct snd_soc_card *card, |
| 3097 | const char *propname) |
| 3098 | { |
Tushar Behera | 7e07e7c | 2014-07-04 14:23:00 +0530 | [diff] [blame] | 3099 | struct device_node *np; |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 3100 | int ret; |
| 3101 | |
Tushar Behera | 7e07e7c | 2014-07-04 14:23:00 +0530 | [diff] [blame] | 3102 | if (!card->dev) { |
| 3103 | pr_err("card->dev is not set before calling %s\n", __func__); |
| 3104 | return -EINVAL; |
| 3105 | } |
| 3106 | |
| 3107 | np = card->dev->of_node; |
| 3108 | |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 3109 | ret = of_property_read_string_index(np, propname, 0, &card->name); |
| 3110 | /* |
| 3111 | * EINVAL means the property does not exist. This is fine providing |
| 3112 | * card->name was previously set, which is checked later in |
| 3113 | * snd_soc_register_card. |
| 3114 | */ |
| 3115 | if (ret < 0 && ret != -EINVAL) { |
| 3116 | dev_err(card->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 3117 | "ASoC: Property '%s' could not be read: %d\n", |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 3118 | propname, ret); |
| 3119 | return ret; |
| 3120 | } |
| 3121 | |
| 3122 | return 0; |
| 3123 | } |
| 3124 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name); |
| 3125 | |
Xiubo Li | 9a6d486 | 2014-02-08 15:59:52 +0800 | [diff] [blame] | 3126 | static const struct snd_soc_dapm_widget simple_widgets[] = { |
| 3127 | SND_SOC_DAPM_MIC("Microphone", NULL), |
| 3128 | SND_SOC_DAPM_LINE("Line", NULL), |
| 3129 | SND_SOC_DAPM_HP("Headphone", NULL), |
| 3130 | SND_SOC_DAPM_SPK("Speaker", NULL), |
| 3131 | }; |
| 3132 | |
| 3133 | int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card, |
| 3134 | const char *propname) |
| 3135 | { |
| 3136 | struct device_node *np = card->dev->of_node; |
| 3137 | struct snd_soc_dapm_widget *widgets; |
| 3138 | const char *template, *wname; |
| 3139 | int i, j, num_widgets, ret; |
| 3140 | |
| 3141 | num_widgets = of_property_count_strings(np, propname); |
| 3142 | if (num_widgets < 0) { |
| 3143 | dev_err(card->dev, |
| 3144 | "ASoC: Property '%s' does not exist\n", propname); |
| 3145 | return -EINVAL; |
| 3146 | } |
| 3147 | if (num_widgets & 1) { |
| 3148 | dev_err(card->dev, |
| 3149 | "ASoC: Property '%s' length is not even\n", propname); |
| 3150 | return -EINVAL; |
| 3151 | } |
| 3152 | |
| 3153 | num_widgets /= 2; |
| 3154 | if (!num_widgets) { |
| 3155 | dev_err(card->dev, "ASoC: Property '%s's length is zero\n", |
| 3156 | propname); |
| 3157 | return -EINVAL; |
| 3158 | } |
| 3159 | |
| 3160 | widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets), |
| 3161 | GFP_KERNEL); |
| 3162 | if (!widgets) { |
| 3163 | dev_err(card->dev, |
| 3164 | "ASoC: Could not allocate memory for widgets\n"); |
| 3165 | return -ENOMEM; |
| 3166 | } |
| 3167 | |
| 3168 | for (i = 0; i < num_widgets; i++) { |
| 3169 | ret = of_property_read_string_index(np, propname, |
| 3170 | 2 * i, &template); |
| 3171 | if (ret) { |
| 3172 | dev_err(card->dev, |
| 3173 | "ASoC: Property '%s' index %d read error:%d\n", |
| 3174 | propname, 2 * i, ret); |
| 3175 | return -EINVAL; |
| 3176 | } |
| 3177 | |
| 3178 | for (j = 0; j < ARRAY_SIZE(simple_widgets); j++) { |
| 3179 | if (!strncmp(template, simple_widgets[j].name, |
| 3180 | strlen(simple_widgets[j].name))) { |
| 3181 | widgets[i] = simple_widgets[j]; |
| 3182 | break; |
| 3183 | } |
| 3184 | } |
| 3185 | |
| 3186 | if (j >= ARRAY_SIZE(simple_widgets)) { |
| 3187 | dev_err(card->dev, |
| 3188 | "ASoC: DAPM widget '%s' is not supported\n", |
| 3189 | template); |
| 3190 | return -EINVAL; |
| 3191 | } |
| 3192 | |
| 3193 | ret = of_property_read_string_index(np, propname, |
| 3194 | (2 * i) + 1, |
| 3195 | &wname); |
| 3196 | if (ret) { |
| 3197 | dev_err(card->dev, |
| 3198 | "ASoC: Property '%s' index %d read error:%d\n", |
| 3199 | propname, (2 * i) + 1, ret); |
| 3200 | return -EINVAL; |
| 3201 | } |
| 3202 | |
| 3203 | widgets[i].name = wname; |
| 3204 | } |
| 3205 | |
| 3206 | card->dapm_widgets = widgets; |
| 3207 | card->num_dapm_widgets = num_widgets; |
| 3208 | |
| 3209 | return 0; |
| 3210 | } |
| 3211 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets); |
| 3212 | |
Xiubo Li | 89c6785 | 2014-02-14 09:34:35 +0800 | [diff] [blame] | 3213 | int snd_soc_of_parse_tdm_slot(struct device_node *np, |
| 3214 | unsigned int *slots, |
| 3215 | unsigned int *slot_width) |
| 3216 | { |
| 3217 | u32 val; |
| 3218 | int ret; |
| 3219 | |
| 3220 | if (of_property_read_bool(np, "dai-tdm-slot-num")) { |
| 3221 | ret = of_property_read_u32(np, "dai-tdm-slot-num", &val); |
| 3222 | if (ret) |
| 3223 | return ret; |
| 3224 | |
| 3225 | if (slots) |
| 3226 | *slots = val; |
| 3227 | } |
| 3228 | |
| 3229 | if (of_property_read_bool(np, "dai-tdm-slot-width")) { |
| 3230 | ret = of_property_read_u32(np, "dai-tdm-slot-width", &val); |
| 3231 | if (ret) |
| 3232 | return ret; |
| 3233 | |
| 3234 | if (slot_width) |
| 3235 | *slot_width = val; |
| 3236 | } |
| 3237 | |
| 3238 | return 0; |
| 3239 | } |
| 3240 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot); |
| 3241 | |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3242 | int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, |
| 3243 | const char *propname) |
| 3244 | { |
| 3245 | struct device_node *np = card->dev->of_node; |
Peter Rosin | f8781db | 2014-11-27 22:02:42 +0100 | [diff] [blame] | 3246 | int num_routes, old_routes; |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3247 | struct snd_soc_dapm_route *routes; |
| 3248 | int i, ret; |
| 3249 | |
| 3250 | num_routes = of_property_count_strings(np, propname); |
Richard Zhao | c34ce32 | 2012-04-24 15:24:43 +0800 | [diff] [blame] | 3251 | if (num_routes < 0 || num_routes & 1) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 3252 | dev_err(card->dev, |
| 3253 | "ASoC: Property '%s' does not exist or its length is not even\n", |
| 3254 | propname); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3255 | return -EINVAL; |
| 3256 | } |
| 3257 | num_routes /= 2; |
| 3258 | if (!num_routes) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 3259 | dev_err(card->dev, "ASoC: Property '%s's length is zero\n", |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3260 | propname); |
| 3261 | return -EINVAL; |
| 3262 | } |
| 3263 | |
Peter Rosin | f8781db | 2014-11-27 22:02:42 +0100 | [diff] [blame] | 3264 | old_routes = card->num_dapm_routes; |
| 3265 | routes = devm_kzalloc(card->dev, |
| 3266 | (old_routes + num_routes) * sizeof(*routes), |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3267 | GFP_KERNEL); |
| 3268 | if (!routes) { |
| 3269 | dev_err(card->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 3270 | "ASoC: Could not allocate DAPM route table\n"); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3271 | return -EINVAL; |
| 3272 | } |
| 3273 | |
Peter Rosin | f8781db | 2014-11-27 22:02:42 +0100 | [diff] [blame] | 3274 | memcpy(routes, card->dapm_routes, old_routes * sizeof(*routes)); |
| 3275 | |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3276 | for (i = 0; i < num_routes; i++) { |
| 3277 | ret = of_property_read_string_index(np, propname, |
Peter Rosin | f8781db | 2014-11-27 22:02:42 +0100 | [diff] [blame] | 3278 | 2 * i, &routes[old_routes + i].sink); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3279 | if (ret) { |
Mark Brown | c871bd0 | 2012-12-10 16:19:52 +0900 | [diff] [blame] | 3280 | dev_err(card->dev, |
| 3281 | "ASoC: Property '%s' index %d could not be read: %d\n", |
| 3282 | propname, 2 * i, ret); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3283 | return -EINVAL; |
| 3284 | } |
| 3285 | ret = of_property_read_string_index(np, propname, |
Peter Rosin | f8781db | 2014-11-27 22:02:42 +0100 | [diff] [blame] | 3286 | (2 * i) + 1, &routes[old_routes + i].source); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3287 | if (ret) { |
| 3288 | dev_err(card->dev, |
Mark Brown | c871bd0 | 2012-12-10 16:19:52 +0900 | [diff] [blame] | 3289 | "ASoC: Property '%s' index %d could not be read: %d\n", |
| 3290 | propname, (2 * i) + 1, ret); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3291 | return -EINVAL; |
| 3292 | } |
| 3293 | } |
| 3294 | |
Peter Rosin | f8781db | 2014-11-27 22:02:42 +0100 | [diff] [blame] | 3295 | card->num_dapm_routes += num_routes; |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3296 | card->dapm_routes = routes; |
| 3297 | |
| 3298 | return 0; |
| 3299 | } |
| 3300 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing); |
| 3301 | |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3302 | unsigned int snd_soc_of_parse_daifmt(struct device_node *np, |
Jyri Sarha | 389cb83 | 2014-03-24 12:15:24 +0200 | [diff] [blame] | 3303 | const char *prefix, |
| 3304 | struct device_node **bitclkmaster, |
| 3305 | struct device_node **framemaster) |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3306 | { |
| 3307 | int ret, i; |
| 3308 | char prop[128]; |
| 3309 | unsigned int format = 0; |
| 3310 | int bit, frame; |
| 3311 | const char *str; |
| 3312 | struct { |
| 3313 | char *name; |
| 3314 | unsigned int val; |
| 3315 | } of_fmt_table[] = { |
| 3316 | { "i2s", SND_SOC_DAIFMT_I2S }, |
| 3317 | { "right_j", SND_SOC_DAIFMT_RIGHT_J }, |
| 3318 | { "left_j", SND_SOC_DAIFMT_LEFT_J }, |
| 3319 | { "dsp_a", SND_SOC_DAIFMT_DSP_A }, |
| 3320 | { "dsp_b", SND_SOC_DAIFMT_DSP_B }, |
| 3321 | { "ac97", SND_SOC_DAIFMT_AC97 }, |
| 3322 | { "pdm", SND_SOC_DAIFMT_PDM}, |
| 3323 | { "msb", SND_SOC_DAIFMT_MSB }, |
| 3324 | { "lsb", SND_SOC_DAIFMT_LSB }, |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3325 | }; |
| 3326 | |
| 3327 | if (!prefix) |
| 3328 | prefix = ""; |
| 3329 | |
| 3330 | /* |
| 3331 | * check "[prefix]format = xxx" |
| 3332 | * SND_SOC_DAIFMT_FORMAT_MASK area |
| 3333 | */ |
| 3334 | snprintf(prop, sizeof(prop), "%sformat", prefix); |
| 3335 | ret = of_property_read_string(np, prop, &str); |
| 3336 | if (ret == 0) { |
| 3337 | for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) { |
| 3338 | if (strcmp(str, of_fmt_table[i].name) == 0) { |
| 3339 | format |= of_fmt_table[i].val; |
| 3340 | break; |
| 3341 | } |
| 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | /* |
Kuninori Morimoto | 8c2d6a9 | 2013-01-29 21:03:36 -0800 | [diff] [blame] | 3346 | * check "[prefix]continuous-clock" |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3347 | * SND_SOC_DAIFMT_CLOCK_MASK area |
| 3348 | */ |
Kuninori Morimoto | 8c2d6a9 | 2013-01-29 21:03:36 -0800 | [diff] [blame] | 3349 | snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix); |
| 3350 | if (of_get_property(np, prop, NULL)) |
| 3351 | format |= SND_SOC_DAIFMT_CONT; |
| 3352 | else |
| 3353 | format |= SND_SOC_DAIFMT_GATED; |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3354 | |
| 3355 | /* |
| 3356 | * check "[prefix]bitclock-inversion" |
| 3357 | * check "[prefix]frame-inversion" |
| 3358 | * SND_SOC_DAIFMT_INV_MASK area |
| 3359 | */ |
| 3360 | snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix); |
| 3361 | bit = !!of_get_property(np, prop, NULL); |
| 3362 | |
| 3363 | snprintf(prop, sizeof(prop), "%sframe-inversion", prefix); |
| 3364 | frame = !!of_get_property(np, prop, NULL); |
| 3365 | |
| 3366 | switch ((bit << 4) + frame) { |
| 3367 | case 0x11: |
| 3368 | format |= SND_SOC_DAIFMT_IB_IF; |
| 3369 | break; |
| 3370 | case 0x10: |
| 3371 | format |= SND_SOC_DAIFMT_IB_NF; |
| 3372 | break; |
| 3373 | case 0x01: |
| 3374 | format |= SND_SOC_DAIFMT_NB_IF; |
| 3375 | break; |
| 3376 | default: |
| 3377 | /* SND_SOC_DAIFMT_NB_NF is default */ |
| 3378 | break; |
| 3379 | } |
| 3380 | |
| 3381 | /* |
| 3382 | * check "[prefix]bitclock-master" |
| 3383 | * check "[prefix]frame-master" |
| 3384 | * SND_SOC_DAIFMT_MASTER_MASK area |
| 3385 | */ |
| 3386 | snprintf(prop, sizeof(prop), "%sbitclock-master", prefix); |
| 3387 | bit = !!of_get_property(np, prop, NULL); |
Jyri Sarha | 389cb83 | 2014-03-24 12:15:24 +0200 | [diff] [blame] | 3388 | if (bit && bitclkmaster) |
| 3389 | *bitclkmaster = of_parse_phandle(np, prop, 0); |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3390 | |
| 3391 | snprintf(prop, sizeof(prop), "%sframe-master", prefix); |
| 3392 | frame = !!of_get_property(np, prop, NULL); |
Jyri Sarha | 389cb83 | 2014-03-24 12:15:24 +0200 | [diff] [blame] | 3393 | if (frame && framemaster) |
| 3394 | *framemaster = of_parse_phandle(np, prop, 0); |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3395 | |
| 3396 | switch ((bit << 4) + frame) { |
| 3397 | case 0x11: |
| 3398 | format |= SND_SOC_DAIFMT_CBM_CFM; |
| 3399 | break; |
| 3400 | case 0x10: |
| 3401 | format |= SND_SOC_DAIFMT_CBM_CFS; |
| 3402 | break; |
| 3403 | case 0x01: |
| 3404 | format |= SND_SOC_DAIFMT_CBS_CFM; |
| 3405 | break; |
| 3406 | default: |
| 3407 | format |= SND_SOC_DAIFMT_CBS_CFS; |
| 3408 | break; |
| 3409 | } |
| 3410 | |
| 3411 | return format; |
| 3412 | } |
| 3413 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt); |
| 3414 | |
Jean-Francois Moine | 93b0f3e | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3415 | static int snd_soc_get_dai_name(struct of_phandle_args *args, |
| 3416 | const char **dai_name) |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3417 | { |
| 3418 | struct snd_soc_component *pos; |
Jean-Francois Moine | 93b0f3e | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3419 | int ret = -EPROBE_DEFER; |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3420 | |
| 3421 | mutex_lock(&client_mutex); |
| 3422 | list_for_each_entry(pos, &component_list, list) { |
Jean-Francois Moine | 93b0f3e | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3423 | if (pos->dev->of_node != args->np) |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3424 | continue; |
| 3425 | |
Kuninori Morimoto | 6833c45 | 2013-10-16 22:05:26 -0700 | [diff] [blame] | 3426 | if (pos->driver->of_xlate_dai_name) { |
Jean-Francois Moine | 93b0f3e | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3427 | ret = pos->driver->of_xlate_dai_name(pos, |
| 3428 | args, |
| 3429 | dai_name); |
Kuninori Morimoto | 6833c45 | 2013-10-16 22:05:26 -0700 | [diff] [blame] | 3430 | } else { |
| 3431 | int id = -1; |
| 3432 | |
Jean-Francois Moine | 93b0f3e | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3433 | switch (args->args_count) { |
Kuninori Morimoto | 6833c45 | 2013-10-16 22:05:26 -0700 | [diff] [blame] | 3434 | case 0: |
| 3435 | id = 0; /* same as dai_drv[0] */ |
| 3436 | break; |
| 3437 | case 1: |
Jean-Francois Moine | 93b0f3e | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3438 | id = args->args[0]; |
Kuninori Morimoto | 6833c45 | 2013-10-16 22:05:26 -0700 | [diff] [blame] | 3439 | break; |
| 3440 | default: |
| 3441 | /* not supported */ |
| 3442 | break; |
| 3443 | } |
| 3444 | |
| 3445 | if (id < 0 || id >= pos->num_dai) { |
| 3446 | ret = -EINVAL; |
Nicolin Chen | 3dcba28 | 2014-04-21 19:14:46 +0800 | [diff] [blame] | 3447 | continue; |
Kuninori Morimoto | 6833c45 | 2013-10-16 22:05:26 -0700 | [diff] [blame] | 3448 | } |
Xiubo Li | e41975e | 2013-12-20 14:39:51 +0800 | [diff] [blame] | 3449 | |
| 3450 | ret = 0; |
| 3451 | |
| 3452 | *dai_name = pos->dai_drv[id].name; |
| 3453 | if (!*dai_name) |
| 3454 | *dai_name = pos->name; |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3455 | } |
| 3456 | |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3457 | break; |
| 3458 | } |
| 3459 | mutex_unlock(&client_mutex); |
Jean-Francois Moine | 93b0f3e | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3460 | return ret; |
| 3461 | } |
| 3462 | |
| 3463 | int snd_soc_of_get_dai_name(struct device_node *of_node, |
| 3464 | const char **dai_name) |
| 3465 | { |
| 3466 | struct of_phandle_args args; |
| 3467 | int ret; |
| 3468 | |
| 3469 | ret = of_parse_phandle_with_args(of_node, "sound-dai", |
| 3470 | "#sound-dai-cells", 0, &args); |
| 3471 | if (ret) |
| 3472 | return ret; |
| 3473 | |
| 3474 | ret = snd_soc_get_dai_name(&args, dai_name); |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3475 | |
| 3476 | of_node_put(args.np); |
| 3477 | |
| 3478 | return ret; |
| 3479 | } |
| 3480 | EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name); |
| 3481 | |
Jean-Francois Moine | 93b0f3e | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3482 | /* |
| 3483 | * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree |
| 3484 | * @dev: Card device |
| 3485 | * @of_node: Device node |
| 3486 | * @dai_link: DAI link |
| 3487 | * |
| 3488 | * Builds an array of CODEC DAI components from the DAI link property |
| 3489 | * 'sound-dai'. |
| 3490 | * The array is set in the DAI link and the number of DAIs is set accordingly. |
| 3491 | * The device nodes in the array (of_node) must be dereferenced by the caller. |
| 3492 | * |
| 3493 | * Returns 0 for success |
| 3494 | */ |
| 3495 | int snd_soc_of_get_dai_link_codecs(struct device *dev, |
| 3496 | struct device_node *of_node, |
| 3497 | struct snd_soc_dai_link *dai_link) |
| 3498 | { |
| 3499 | struct of_phandle_args args; |
| 3500 | struct snd_soc_dai_link_component *component; |
| 3501 | char *name; |
| 3502 | int index, num_codecs, ret; |
| 3503 | |
| 3504 | /* Count the number of CODECs */ |
| 3505 | name = "sound-dai"; |
| 3506 | num_codecs = of_count_phandle_with_args(of_node, name, |
| 3507 | "#sound-dai-cells"); |
| 3508 | if (num_codecs <= 0) { |
| 3509 | if (num_codecs == -ENOENT) |
| 3510 | dev_err(dev, "No 'sound-dai' property\n"); |
| 3511 | else |
| 3512 | dev_err(dev, "Bad phandle in 'sound-dai'\n"); |
| 3513 | return num_codecs; |
| 3514 | } |
| 3515 | component = devm_kzalloc(dev, |
| 3516 | sizeof *component * num_codecs, |
| 3517 | GFP_KERNEL); |
| 3518 | if (!component) |
| 3519 | return -ENOMEM; |
| 3520 | dai_link->codecs = component; |
| 3521 | dai_link->num_codecs = num_codecs; |
| 3522 | |
| 3523 | /* Parse the list */ |
| 3524 | for (index = 0, component = dai_link->codecs; |
| 3525 | index < dai_link->num_codecs; |
| 3526 | index++, component++) { |
| 3527 | ret = of_parse_phandle_with_args(of_node, name, |
| 3528 | "#sound-dai-cells", |
| 3529 | index, &args); |
| 3530 | if (ret) |
| 3531 | goto err; |
| 3532 | component->of_node = args.np; |
| 3533 | ret = snd_soc_get_dai_name(&args, &component->dai_name); |
| 3534 | if (ret < 0) |
| 3535 | goto err; |
| 3536 | } |
| 3537 | return 0; |
| 3538 | err: |
| 3539 | for (index = 0, component = dai_link->codecs; |
| 3540 | index < dai_link->num_codecs; |
| 3541 | index++, component++) { |
| 3542 | if (!component->of_node) |
| 3543 | break; |
| 3544 | of_node_put(component->of_node); |
| 3545 | component->of_node = NULL; |
| 3546 | } |
| 3547 | dai_link->codecs = NULL; |
| 3548 | dai_link->num_codecs = 0; |
| 3549 | return ret; |
| 3550 | } |
| 3551 | EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs); |
| 3552 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 3553 | static int __init snd_soc_init(void) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3554 | { |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 3555 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 3556 | snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL); |
| 3557 | if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) { |
Fabio Estevam | 0837fc6 | 2012-02-17 19:40:38 -0200 | [diff] [blame] | 3558 | pr_warn("ASoC: Failed to create debugfs directory\n"); |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 3559 | snd_soc_debugfs_root = NULL; |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 3560 | } |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 3561 | |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 3562 | if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL, |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 3563 | &codec_list_fops)) |
| 3564 | pr_warn("ASoC: Failed to create CODEC list debugfs file\n"); |
| 3565 | |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 3566 | if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL, |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 3567 | &dai_list_fops)) |
| 3568 | pr_warn("ASoC: Failed to create DAI list debugfs file\n"); |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 3569 | |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 3570 | if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL, |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 3571 | &platform_list_fops)) |
| 3572 | pr_warn("ASoC: Failed to create platform list debugfs file\n"); |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 3573 | #endif |
| 3574 | |
Mark Brown | fb25789 | 2011-04-28 10:57:54 +0100 | [diff] [blame] | 3575 | snd_soc_util_init(); |
| 3576 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3577 | return platform_driver_register(&soc_driver); |
| 3578 | } |
Mark Brown | 4abe8e1 | 2010-10-12 17:41:03 +0100 | [diff] [blame] | 3579 | module_init(snd_soc_init); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3580 | |
Mark Brown | 7d8c16a | 2008-11-30 22:11:24 +0000 | [diff] [blame] | 3581 | static void __exit snd_soc_exit(void) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3582 | { |
Mark Brown | fb25789 | 2011-04-28 10:57:54 +0100 | [diff] [blame] | 3583 | snd_soc_util_exit(); |
| 3584 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 3585 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 3586 | debugfs_remove_recursive(snd_soc_debugfs_root); |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 3587 | #endif |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 3588 | platform_driver_unregister(&soc_driver); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3589 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3590 | module_exit(snd_soc_exit); |
| 3591 | |
| 3592 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 3593 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3594 | MODULE_DESCRIPTION("ALSA SoC Core"); |
| 3595 | MODULE_LICENSE("GPL"); |
Kay Sievers | 8b45a20 | 2008-04-14 13:33:36 +0200 | [diff] [blame] | 3596 | MODULE_ALIAS("platform:soc-audio"); |