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