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