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