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