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