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. |
| 6 | * |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 7 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
Liam Girdwood | 0664d88 | 2006-12-18 14:39:02 +0100 | [diff] [blame] | 8 | * with code, comments and ideas from :- |
| 9 | * Richard Purdie <richard@openedhand.com> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License as published by the |
| 13 | * Free Software Foundation; either version 2 of the License, or (at your |
| 14 | * option) any later version. |
| 15 | * |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 16 | * TODO: |
| 17 | * o Add hw rules to enforce rates, etc. |
| 18 | * o More testing with other codecs/machines. |
| 19 | * o Add more codecs and platforms to ensure good API coverage. |
| 20 | * o Support TDM on PCM and I2S |
| 21 | */ |
| 22 | |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/moduleparam.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/pm.h> |
| 28 | #include <linux/bitops.h> |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 29 | #include <linux/debugfs.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 30 | #include <linux/platform_device.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 31 | #include <sound/core.h> |
| 32 | #include <sound/pcm.h> |
| 33 | #include <sound/pcm_params.h> |
| 34 | #include <sound/soc.h> |
| 35 | #include <sound/soc-dapm.h> |
| 36 | #include <sound/initval.h> |
| 37 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 38 | static DEFINE_MUTEX(pcm_mutex); |
| 39 | static DEFINE_MUTEX(io_mutex); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 40 | static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq); |
| 41 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 42 | #ifdef CONFIG_DEBUG_FS |
| 43 | static struct dentry *debugfs_root; |
| 44 | #endif |
| 45 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 46 | static DEFINE_MUTEX(client_mutex); |
| 47 | static LIST_HEAD(card_list); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 48 | static LIST_HEAD(dai_list); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 49 | static LIST_HEAD(platform_list); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 50 | static LIST_HEAD(codec_list); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 51 | |
| 52 | static int snd_soc_register_card(struct snd_soc_card *card); |
| 53 | static int snd_soc_unregister_card(struct snd_soc_card *card); |
| 54 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 55 | /* |
| 56 | * This is a timeout to do a DAPM powerdown after a stream is closed(). |
| 57 | * It can be used to eliminate pops between different playback streams, e.g. |
| 58 | * between two audio tracks. |
| 59 | */ |
| 60 | static int pmdown_time = 5000; |
| 61 | module_param(pmdown_time, int, 0); |
| 62 | MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)"); |
| 63 | |
Liam Girdwood | 965ac42 | 2007-01-31 14:14:57 +0100 | [diff] [blame] | 64 | /* |
| 65 | * This function forces any delayed work to be queued and run. |
| 66 | */ |
| 67 | static int run_delayed_work(struct delayed_work *dwork) |
| 68 | { |
| 69 | int ret; |
| 70 | |
| 71 | /* cancel any work waiting to be queued. */ |
| 72 | ret = cancel_delayed_work(dwork); |
| 73 | |
| 74 | /* if there was any work waiting then we run it now and |
| 75 | * wait for it's completion */ |
| 76 | if (ret) { |
| 77 | schedule_delayed_work(dwork, 0); |
| 78 | flush_scheduled_work(); |
| 79 | } |
| 80 | return ret; |
| 81 | } |
| 82 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 83 | #ifdef CONFIG_SND_SOC_AC97_BUS |
| 84 | /* unregister ac97 codec */ |
| 85 | static int soc_ac97_dev_unregister(struct snd_soc_codec *codec) |
| 86 | { |
| 87 | if (codec->ac97->dev.bus) |
| 88 | device_unregister(&codec->ac97->dev); |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | /* stop no dev release warning */ |
| 93 | static void soc_ac97_device_release(struct device *dev){} |
| 94 | |
| 95 | /* register ac97 codec to bus */ |
| 96 | static int soc_ac97_dev_register(struct snd_soc_codec *codec) |
| 97 | { |
| 98 | int err; |
| 99 | |
| 100 | codec->ac97->dev.bus = &ac97_bus_type; |
Mark Brown | 4ac5c61 | 2009-04-01 19:35:01 +0100 | [diff] [blame] | 101 | codec->ac97->dev.parent = codec->card->dev; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 102 | codec->ac97->dev.release = soc_ac97_device_release; |
| 103 | |
Kay Sievers | bb072bf | 2008-11-02 03:50:35 +0100 | [diff] [blame] | 104 | dev_set_name(&codec->ac97->dev, "%d-%d:%s", |
| 105 | codec->card->number, 0, codec->name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 106 | err = device_register(&codec->ac97->dev); |
| 107 | if (err < 0) { |
| 108 | snd_printk(KERN_ERR "Can't register ac97 bus\n"); |
| 109 | codec->ac97->dev.bus = NULL; |
| 110 | return err; |
| 111 | } |
| 112 | return 0; |
| 113 | } |
| 114 | #endif |
| 115 | |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame^] | 116 | static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream) |
| 117 | { |
| 118 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 119 | struct snd_soc_device *socdev = rtd->socdev; |
| 120 | struct snd_soc_card *card = socdev->card; |
| 121 | struct snd_soc_dai_link *machine = rtd->dai; |
| 122 | struct snd_soc_dai *cpu_dai = machine->cpu_dai; |
| 123 | struct snd_soc_dai *codec_dai = machine->codec_dai; |
| 124 | int ret; |
| 125 | |
| 126 | if (codec_dai->symmetric_rates || cpu_dai->symmetric_rates || |
| 127 | machine->symmetric_rates) { |
| 128 | dev_dbg(card->dev, "Symmetry forces %dHz rate\n", |
| 129 | machine->rate); |
| 130 | |
| 131 | ret = snd_pcm_hw_constraint_minmax(substream->runtime, |
| 132 | SNDRV_PCM_HW_PARAM_RATE, |
| 133 | machine->rate, |
| 134 | machine->rate); |
| 135 | if (ret < 0) { |
| 136 | dev_err(card->dev, |
| 137 | "Unable to apply rate symmetry constraint: %d\n", ret); |
| 138 | return ret; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 145 | /* |
| 146 | * Called by ALSA when a PCM substream is opened, the runtime->hw record is |
| 147 | * then initialized and any private data can be allocated. This also calls |
| 148 | * startup for the cpu DAI, platform, machine and codec DAI. |
| 149 | */ |
| 150 | static int soc_pcm_open(struct snd_pcm_substream *substream) |
| 151 | { |
| 152 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 153 | struct snd_soc_device *socdev = rtd->socdev; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 154 | struct snd_soc_card *card = socdev->card; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 155 | struct snd_pcm_runtime *runtime = substream->runtime; |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 156 | struct snd_soc_dai_link *machine = rtd->dai; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 157 | struct snd_soc_platform *platform = card->platform; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 158 | struct snd_soc_dai *cpu_dai = machine->cpu_dai; |
| 159 | struct snd_soc_dai *codec_dai = machine->codec_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 160 | int ret = 0; |
| 161 | |
| 162 | mutex_lock(&pcm_mutex); |
| 163 | |
| 164 | /* startup the audio subsystem */ |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 165 | if (cpu_dai->ops->startup) { |
| 166 | ret = cpu_dai->ops->startup(substream, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 167 | if (ret < 0) { |
| 168 | printk(KERN_ERR "asoc: can't open interface %s\n", |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 169 | cpu_dai->name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 170 | goto out; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | if (platform->pcm_ops->open) { |
| 175 | ret = platform->pcm_ops->open(substream); |
| 176 | if (ret < 0) { |
| 177 | printk(KERN_ERR "asoc: can't open platform %s\n", platform->name); |
| 178 | goto platform_err; |
| 179 | } |
| 180 | } |
| 181 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 182 | if (codec_dai->ops->startup) { |
| 183 | ret = codec_dai->ops->startup(substream, codec_dai); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 184 | if (ret < 0) { |
| 185 | printk(KERN_ERR "asoc: can't open codec %s\n", |
| 186 | codec_dai->name); |
| 187 | goto codec_dai_err; |
| 188 | } |
| 189 | } |
| 190 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 191 | if (machine->ops && machine->ops->startup) { |
| 192 | ret = machine->ops->startup(substream); |
| 193 | if (ret < 0) { |
| 194 | printk(KERN_ERR "asoc: %s startup failed\n", machine->name); |
| 195 | goto machine_err; |
| 196 | } |
| 197 | } |
| 198 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 199 | /* Check that the codec and cpu DAI's are compatible */ |
| 200 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 201 | runtime->hw.rate_min = |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 202 | max(codec_dai->playback.rate_min, |
| 203 | cpu_dai->playback.rate_min); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 204 | runtime->hw.rate_max = |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 205 | min(codec_dai->playback.rate_max, |
| 206 | cpu_dai->playback.rate_max); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 207 | runtime->hw.channels_min = |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 208 | max(codec_dai->playback.channels_min, |
| 209 | cpu_dai->playback.channels_min); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 210 | runtime->hw.channels_max = |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 211 | min(codec_dai->playback.channels_max, |
| 212 | cpu_dai->playback.channels_max); |
| 213 | runtime->hw.formats = |
| 214 | codec_dai->playback.formats & cpu_dai->playback.formats; |
| 215 | runtime->hw.rates = |
| 216 | codec_dai->playback.rates & cpu_dai->playback.rates; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 217 | } else { |
| 218 | runtime->hw.rate_min = |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 219 | max(codec_dai->capture.rate_min, |
| 220 | cpu_dai->capture.rate_min); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 221 | runtime->hw.rate_max = |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 222 | min(codec_dai->capture.rate_max, |
| 223 | cpu_dai->capture.rate_max); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 224 | runtime->hw.channels_min = |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 225 | max(codec_dai->capture.channels_min, |
| 226 | cpu_dai->capture.channels_min); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 227 | runtime->hw.channels_max = |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 228 | min(codec_dai->capture.channels_max, |
| 229 | cpu_dai->capture.channels_max); |
| 230 | runtime->hw.formats = |
| 231 | codec_dai->capture.formats & cpu_dai->capture.formats; |
| 232 | runtime->hw.rates = |
| 233 | codec_dai->capture.rates & cpu_dai->capture.rates; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | snd_pcm_limit_hw_rates(runtime); |
| 237 | if (!runtime->hw.rates) { |
| 238 | printk(KERN_ERR "asoc: %s <-> %s No matching rates\n", |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 239 | codec_dai->name, cpu_dai->name); |
| 240 | goto machine_err; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 241 | } |
| 242 | if (!runtime->hw.formats) { |
| 243 | printk(KERN_ERR "asoc: %s <-> %s No matching formats\n", |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 244 | codec_dai->name, cpu_dai->name); |
| 245 | goto machine_err; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 246 | } |
| 247 | if (!runtime->hw.channels_min || !runtime->hw.channels_max) { |
| 248 | printk(KERN_ERR "asoc: %s <-> %s No matching channels\n", |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 249 | codec_dai->name, cpu_dai->name); |
| 250 | goto machine_err; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 251 | } |
| 252 | |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame^] | 253 | /* Symmetry only applies if we've already got an active stream. */ |
| 254 | if (cpu_dai->active || codec_dai->active) { |
| 255 | ret = soc_pcm_apply_symmetry(substream); |
| 256 | if (ret != 0) |
| 257 | goto machine_err; |
| 258 | } |
| 259 | |
Mark Brown | f24368c | 2008-10-21 21:45:08 +0100 | [diff] [blame] | 260 | pr_debug("asoc: %s <-> %s info:\n", codec_dai->name, cpu_dai->name); |
| 261 | pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates); |
| 262 | pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min, |
| 263 | runtime->hw.channels_max); |
| 264 | pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min, |
| 265 | runtime->hw.rate_max); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 266 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 267 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 268 | cpu_dai->playback.active = codec_dai->playback.active = 1; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 269 | else |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 270 | cpu_dai->capture.active = codec_dai->capture.active = 1; |
| 271 | cpu_dai->active = codec_dai->active = 1; |
| 272 | cpu_dai->runtime = runtime; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 273 | card->codec->active++; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 274 | mutex_unlock(&pcm_mutex); |
| 275 | return 0; |
| 276 | |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 277 | machine_err: |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 278 | if (machine->ops && machine->ops->shutdown) |
| 279 | machine->ops->shutdown(substream); |
| 280 | |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 281 | codec_dai_err: |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 282 | if (platform->pcm_ops->close) |
| 283 | platform->pcm_ops->close(substream); |
| 284 | |
| 285 | platform_err: |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 286 | if (cpu_dai->ops->shutdown) |
| 287 | cpu_dai->ops->shutdown(substream, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 288 | out: |
| 289 | mutex_unlock(&pcm_mutex); |
| 290 | return ret; |
| 291 | } |
| 292 | |
| 293 | /* |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 294 | * Power down the audio subsystem pmdown_time msecs after close is called. |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 295 | * This is to ensure there are no pops or clicks in between any music tracks |
| 296 | * due to DAPM power cycling. |
| 297 | */ |
Andrew Morton | 4484bb2 | 2006-12-15 09:30:07 +0100 | [diff] [blame] | 298 | static void close_delayed_work(struct work_struct *work) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 299 | { |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 300 | struct snd_soc_card *card = container_of(work, struct snd_soc_card, |
| 301 | delayed_work.work); |
| 302 | struct snd_soc_device *socdev = card->socdev; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 303 | struct snd_soc_codec *codec = card->codec; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 304 | struct snd_soc_dai *codec_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 305 | int i; |
| 306 | |
| 307 | mutex_lock(&pcm_mutex); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 308 | for (i = 0; i < codec->num_dai; i++) { |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 309 | codec_dai = &codec->dai[i]; |
| 310 | |
Mark Brown | f24368c | 2008-10-21 21:45:08 +0100 | [diff] [blame] | 311 | pr_debug("pop wq checking: %s status: %s waiting: %s\n", |
| 312 | codec_dai->playback.stream_name, |
| 313 | codec_dai->playback.active ? "active" : "inactive", |
| 314 | codec_dai->pop_wait ? "yes" : "no"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 315 | |
| 316 | /* are we waiting on this codec DAI stream */ |
| 317 | if (codec_dai->pop_wait == 1) { |
| 318 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 319 | /* Reduce power if no longer active */ |
Liam Girdwood | 3c1c47e | 2008-01-10 14:38:24 +0100 | [diff] [blame] | 320 | if (codec->active == 0) { |
Mark Brown | f24368c | 2008-10-21 21:45:08 +0100 | [diff] [blame] | 321 | pr_debug("pop wq D1 %s %s\n", codec->name, |
| 322 | codec_dai->playback.stream_name); |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 323 | snd_soc_dapm_set_bias_level(socdev, |
| 324 | SND_SOC_BIAS_PREPARE); |
Liam Girdwood | 3c1c47e | 2008-01-10 14:38:24 +0100 | [diff] [blame] | 325 | } |
| 326 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 327 | codec_dai->pop_wait = 0; |
Liam Girdwood | 0b4d221 | 2008-01-10 14:36:20 +0100 | [diff] [blame] | 328 | snd_soc_dapm_stream_event(codec, |
| 329 | codec_dai->playback.stream_name, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 330 | SND_SOC_DAPM_STREAM_STOP); |
| 331 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 332 | /* Fall into standby if no longer active */ |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 333 | if (codec->active == 0) { |
Mark Brown | f24368c | 2008-10-21 21:45:08 +0100 | [diff] [blame] | 334 | pr_debug("pop wq D3 %s %s\n", codec->name, |
| 335 | codec_dai->playback.stream_name); |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 336 | snd_soc_dapm_set_bias_level(socdev, |
| 337 | SND_SOC_BIAS_STANDBY); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | } |
| 341 | mutex_unlock(&pcm_mutex); |
| 342 | } |
| 343 | |
| 344 | /* |
| 345 | * Called by ALSA when a PCM substream is closed. Private data can be |
| 346 | * freed here. The cpu DAI, codec DAI, machine and platform are also |
| 347 | * shutdown. |
| 348 | */ |
| 349 | static int soc_codec_close(struct snd_pcm_substream *substream) |
| 350 | { |
| 351 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 352 | struct snd_soc_device *socdev = rtd->socdev; |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 353 | struct snd_soc_card *card = socdev->card; |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 354 | struct snd_soc_dai_link *machine = rtd->dai; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 355 | struct snd_soc_platform *platform = card->platform; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 356 | struct snd_soc_dai *cpu_dai = machine->cpu_dai; |
| 357 | struct snd_soc_dai *codec_dai = machine->codec_dai; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 358 | struct snd_soc_codec *codec = card->codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 359 | |
| 360 | mutex_lock(&pcm_mutex); |
| 361 | |
| 362 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 363 | cpu_dai->playback.active = codec_dai->playback.active = 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 364 | else |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 365 | cpu_dai->capture.active = codec_dai->capture.active = 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 366 | |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 367 | if (codec_dai->playback.active == 0 && |
| 368 | codec_dai->capture.active == 0) { |
| 369 | cpu_dai->active = codec_dai->active = 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 370 | } |
| 371 | codec->active--; |
| 372 | |
Mark Brown | 6010b2d | 2008-09-06 18:33:24 +0100 | [diff] [blame] | 373 | /* Muting the DAC suppresses artifacts caused during digital |
| 374 | * shutdown, for example from stopping clocks. |
| 375 | */ |
| 376 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 377 | snd_soc_dai_digital_mute(codec_dai, 1); |
| 378 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 379 | if (cpu_dai->ops->shutdown) |
| 380 | cpu_dai->ops->shutdown(substream, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 381 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 382 | if (codec_dai->ops->shutdown) |
| 383 | codec_dai->ops->shutdown(substream, codec_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 384 | |
| 385 | if (machine->ops && machine->ops->shutdown) |
| 386 | machine->ops->shutdown(substream); |
| 387 | |
| 388 | if (platform->pcm_ops->close) |
| 389 | platform->pcm_ops->close(substream); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 390 | cpu_dai->runtime = NULL; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 391 | |
| 392 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 393 | /* start delayed pop wq here for playback streams */ |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 394 | codec_dai->pop_wait = 1; |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 395 | schedule_delayed_work(&card->delayed_work, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 396 | msecs_to_jiffies(pmdown_time)); |
| 397 | } else { |
| 398 | /* capture streams can be powered down now */ |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 399 | snd_soc_dapm_stream_event(codec, |
Liam Girdwood | 0b4d221 | 2008-01-10 14:36:20 +0100 | [diff] [blame] | 400 | codec_dai->capture.stream_name, |
| 401 | SND_SOC_DAPM_STREAM_STOP); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 402 | |
Liam Girdwood | 0b4d221 | 2008-01-10 14:36:20 +0100 | [diff] [blame] | 403 | if (codec->active == 0 && codec_dai->pop_wait == 0) |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 404 | snd_soc_dapm_set_bias_level(socdev, |
| 405 | SND_SOC_BIAS_STANDBY); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | mutex_unlock(&pcm_mutex); |
| 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | /* |
| 413 | * Called by ALSA when the PCM substream is prepared, can set format, sample |
| 414 | * rate, etc. This function is non atomic and can be called multiple times, |
| 415 | * it can refer to the runtime info. |
| 416 | */ |
| 417 | static int soc_pcm_prepare(struct snd_pcm_substream *substream) |
| 418 | { |
| 419 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 420 | struct snd_soc_device *socdev = rtd->socdev; |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 421 | struct snd_soc_card *card = socdev->card; |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 422 | struct snd_soc_dai_link *machine = rtd->dai; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 423 | struct snd_soc_platform *platform = card->platform; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 424 | struct snd_soc_dai *cpu_dai = machine->cpu_dai; |
| 425 | struct snd_soc_dai *codec_dai = machine->codec_dai; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 426 | struct snd_soc_codec *codec = card->codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 427 | int ret = 0; |
| 428 | |
| 429 | mutex_lock(&pcm_mutex); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 430 | |
| 431 | if (machine->ops && machine->ops->prepare) { |
| 432 | ret = machine->ops->prepare(substream); |
| 433 | if (ret < 0) { |
| 434 | printk(KERN_ERR "asoc: machine prepare error\n"); |
| 435 | goto out; |
| 436 | } |
| 437 | } |
| 438 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 439 | if (platform->pcm_ops->prepare) { |
| 440 | ret = platform->pcm_ops->prepare(substream); |
Liam Girdwood | a71a468 | 2006-10-19 20:35:56 +0200 | [diff] [blame] | 441 | if (ret < 0) { |
| 442 | printk(KERN_ERR "asoc: platform prepare error\n"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 443 | goto out; |
Liam Girdwood | a71a468 | 2006-10-19 20:35:56 +0200 | [diff] [blame] | 444 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 445 | } |
| 446 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 447 | if (codec_dai->ops->prepare) { |
| 448 | ret = codec_dai->ops->prepare(substream, codec_dai); |
Liam Girdwood | a71a468 | 2006-10-19 20:35:56 +0200 | [diff] [blame] | 449 | if (ret < 0) { |
| 450 | printk(KERN_ERR "asoc: codec DAI prepare error\n"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 451 | goto out; |
Liam Girdwood | a71a468 | 2006-10-19 20:35:56 +0200 | [diff] [blame] | 452 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 453 | } |
| 454 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 455 | if (cpu_dai->ops->prepare) { |
| 456 | ret = cpu_dai->ops->prepare(substream, cpu_dai); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 457 | if (ret < 0) { |
| 458 | printk(KERN_ERR "asoc: cpu DAI prepare error\n"); |
| 459 | goto out; |
| 460 | } |
| 461 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 462 | |
Mark Brown | d45f621 | 2008-10-14 13:58:36 +0100 | [diff] [blame] | 463 | /* cancel any delayed stream shutdown that is pending */ |
| 464 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && |
| 465 | codec_dai->pop_wait) { |
| 466 | codec_dai->pop_wait = 0; |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 467 | cancel_delayed_work(&card->delayed_work); |
Mark Brown | d45f621 | 2008-10-14 13:58:36 +0100 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /* do we need to power up codec */ |
| 471 | if (codec->bias_level != SND_SOC_BIAS_ON) { |
| 472 | snd_soc_dapm_set_bias_level(socdev, |
| 473 | SND_SOC_BIAS_PREPARE); |
| 474 | |
| 475 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 476 | snd_soc_dapm_stream_event(codec, |
| 477 | codec_dai->playback.stream_name, |
| 478 | SND_SOC_DAPM_STREAM_START); |
| 479 | else |
| 480 | snd_soc_dapm_stream_event(codec, |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 481 | codec_dai->capture.stream_name, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 482 | SND_SOC_DAPM_STREAM_START); |
Mark Brown | d45f621 | 2008-10-14 13:58:36 +0100 | [diff] [blame] | 483 | |
| 484 | snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_ON); |
| 485 | snd_soc_dai_digital_mute(codec_dai, 0); |
| 486 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 487 | } else { |
Mark Brown | d45f621 | 2008-10-14 13:58:36 +0100 | [diff] [blame] | 488 | /* codec already powered - power on widgets */ |
| 489 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 490 | snd_soc_dapm_stream_event(codec, |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 491 | codec_dai->playback.stream_name, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 492 | SND_SOC_DAPM_STREAM_START); |
Mark Brown | d45f621 | 2008-10-14 13:58:36 +0100 | [diff] [blame] | 493 | else |
| 494 | snd_soc_dapm_stream_event(codec, |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 495 | codec_dai->capture.stream_name, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 496 | SND_SOC_DAPM_STREAM_START); |
| 497 | |
Mark Brown | d45f621 | 2008-10-14 13:58:36 +0100 | [diff] [blame] | 498 | snd_soc_dai_digital_mute(codec_dai, 0); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | out: |
| 502 | mutex_unlock(&pcm_mutex); |
| 503 | return ret; |
| 504 | } |
| 505 | |
| 506 | /* |
| 507 | * Called by ALSA when the hardware params are set by application. This |
| 508 | * function can also be called multiple times and can allocate buffers |
| 509 | * (using snd_pcm_lib_* ). It's non-atomic. |
| 510 | */ |
| 511 | static int soc_pcm_hw_params(struct snd_pcm_substream *substream, |
| 512 | struct snd_pcm_hw_params *params) |
| 513 | { |
| 514 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 515 | struct snd_soc_device *socdev = rtd->socdev; |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 516 | struct snd_soc_dai_link *machine = rtd->dai; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 517 | struct snd_soc_card *card = socdev->card; |
| 518 | struct snd_soc_platform *platform = card->platform; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 519 | struct snd_soc_dai *cpu_dai = machine->cpu_dai; |
| 520 | struct snd_soc_dai *codec_dai = machine->codec_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 521 | int ret = 0; |
| 522 | |
| 523 | mutex_lock(&pcm_mutex); |
| 524 | |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 525 | if (machine->ops && machine->ops->hw_params) { |
| 526 | ret = machine->ops->hw_params(substream, params); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 527 | if (ret < 0) { |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 528 | printk(KERN_ERR "asoc: machine hw_params failed\n"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 529 | goto out; |
| 530 | } |
| 531 | } |
| 532 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 533 | if (codec_dai->ops->hw_params) { |
| 534 | ret = codec_dai->ops->hw_params(substream, params, codec_dai); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 535 | if (ret < 0) { |
| 536 | printk(KERN_ERR "asoc: can't set codec %s hw params\n", |
| 537 | codec_dai->name); |
| 538 | goto codec_err; |
| 539 | } |
| 540 | } |
| 541 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 542 | if (cpu_dai->ops->hw_params) { |
| 543 | ret = cpu_dai->ops->hw_params(substream, params, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 544 | if (ret < 0) { |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 545 | printk(KERN_ERR "asoc: interface %s hw params failed\n", |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 546 | cpu_dai->name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 547 | goto interface_err; |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | if (platform->pcm_ops->hw_params) { |
| 552 | ret = platform->pcm_ops->hw_params(substream, params); |
| 553 | if (ret < 0) { |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 554 | printk(KERN_ERR "asoc: platform %s hw params failed\n", |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 555 | platform->name); |
| 556 | goto platform_err; |
| 557 | } |
| 558 | } |
| 559 | |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame^] | 560 | machine->rate = params_rate(params); |
| 561 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 562 | out: |
| 563 | mutex_unlock(&pcm_mutex); |
| 564 | return ret; |
| 565 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 566 | platform_err: |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 567 | if (cpu_dai->ops->hw_free) |
| 568 | cpu_dai->ops->hw_free(substream, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 569 | |
| 570 | interface_err: |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 571 | if (codec_dai->ops->hw_free) |
| 572 | codec_dai->ops->hw_free(substream, codec_dai); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 573 | |
| 574 | codec_err: |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 575 | if (machine->ops && machine->ops->hw_free) |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 576 | machine->ops->hw_free(substream); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 577 | |
| 578 | mutex_unlock(&pcm_mutex); |
| 579 | return ret; |
| 580 | } |
| 581 | |
| 582 | /* |
| 583 | * Free's resources allocated by hw_params, can be called multiple times |
| 584 | */ |
| 585 | static int soc_pcm_hw_free(struct snd_pcm_substream *substream) |
| 586 | { |
| 587 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 588 | struct snd_soc_device *socdev = rtd->socdev; |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 589 | struct snd_soc_dai_link *machine = rtd->dai; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 590 | struct snd_soc_card *card = socdev->card; |
| 591 | struct snd_soc_platform *platform = card->platform; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 592 | struct snd_soc_dai *cpu_dai = machine->cpu_dai; |
| 593 | struct snd_soc_dai *codec_dai = machine->codec_dai; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 594 | struct snd_soc_codec *codec = card->codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 595 | |
| 596 | mutex_lock(&pcm_mutex); |
| 597 | |
| 598 | /* apply codec digital mute */ |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 599 | if (!codec->active) |
| 600 | snd_soc_dai_digital_mute(codec_dai, 1); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 601 | |
| 602 | /* free any machine hw params */ |
| 603 | if (machine->ops && machine->ops->hw_free) |
| 604 | machine->ops->hw_free(substream); |
| 605 | |
| 606 | /* free any DMA resources */ |
| 607 | if (platform->pcm_ops->hw_free) |
| 608 | platform->pcm_ops->hw_free(substream); |
| 609 | |
| 610 | /* now free hw params for the DAI's */ |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 611 | if (codec_dai->ops->hw_free) |
| 612 | codec_dai->ops->hw_free(substream, codec_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 613 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 614 | if (cpu_dai->ops->hw_free) |
| 615 | cpu_dai->ops->hw_free(substream, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 616 | |
| 617 | mutex_unlock(&pcm_mutex); |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
| 622 | { |
| 623 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 624 | struct snd_soc_device *socdev = rtd->socdev; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 625 | struct snd_soc_card *card= socdev->card; |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 626 | struct snd_soc_dai_link *machine = rtd->dai; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 627 | struct snd_soc_platform *platform = card->platform; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 628 | struct snd_soc_dai *cpu_dai = machine->cpu_dai; |
| 629 | struct snd_soc_dai *codec_dai = machine->codec_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 630 | int ret; |
| 631 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 632 | if (codec_dai->ops->trigger) { |
| 633 | ret = codec_dai->ops->trigger(substream, cmd, codec_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 634 | if (ret < 0) |
| 635 | return ret; |
| 636 | } |
| 637 | |
| 638 | if (platform->pcm_ops->trigger) { |
| 639 | ret = platform->pcm_ops->trigger(substream, cmd); |
| 640 | if (ret < 0) |
| 641 | return ret; |
| 642 | } |
| 643 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 644 | if (cpu_dai->ops->trigger) { |
| 645 | ret = cpu_dai->ops->trigger(substream, cmd, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 646 | if (ret < 0) |
| 647 | return ret; |
| 648 | } |
| 649 | return 0; |
| 650 | } |
| 651 | |
| 652 | /* ASoC PCM operations */ |
| 653 | static struct snd_pcm_ops soc_pcm_ops = { |
| 654 | .open = soc_pcm_open, |
| 655 | .close = soc_codec_close, |
| 656 | .hw_params = soc_pcm_hw_params, |
| 657 | .hw_free = soc_pcm_hw_free, |
| 658 | .prepare = soc_pcm_prepare, |
| 659 | .trigger = soc_pcm_trigger, |
| 660 | }; |
| 661 | |
| 662 | #ifdef CONFIG_PM |
| 663 | /* powers down audio subsystem for suspend */ |
| 664 | static int soc_suspend(struct platform_device *pdev, pm_message_t state) |
| 665 | { |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 666 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 667 | struct snd_soc_card *card = socdev->card; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 668 | struct snd_soc_platform *platform = card->platform; |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 669 | struct snd_soc_codec_device *codec_dev = socdev->codec_dev; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 670 | struct snd_soc_codec *codec = card->codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 671 | int i; |
| 672 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 673 | /* Due to the resume being scheduled into a workqueue we could |
| 674 | * suspend before that's finished - wait for it to complete. |
| 675 | */ |
| 676 | snd_power_lock(codec->card); |
| 677 | snd_power_wait(codec->card, SNDRV_CTL_POWER_D0); |
| 678 | snd_power_unlock(codec->card); |
| 679 | |
| 680 | /* we're going to block userspace touching us until resume completes */ |
| 681 | snd_power_change_state(codec->card, SNDRV_CTL_POWER_D3hot); |
| 682 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 683 | /* mute any active DAC's */ |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 684 | for (i = 0; i < card->num_links; i++) { |
| 685 | struct snd_soc_dai *dai = card->dai_link[i].codec_dai; |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 686 | if (dai->ops->digital_mute && dai->playback.active) |
| 687 | dai->ops->digital_mute(dai, 1); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 688 | } |
| 689 | |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 690 | /* suspend all pcms */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 691 | for (i = 0; i < card->num_links; i++) |
| 692 | snd_pcm_suspend_all(card->dai_link[i].pcm); |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 693 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 694 | if (card->suspend_pre) |
| 695 | card->suspend_pre(pdev, state); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 696 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 697 | for (i = 0; i < card->num_links; i++) { |
| 698 | struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; |
Mark Brown | 3ba9e10a | 2008-11-24 18:01:05 +0000 | [diff] [blame] | 699 | if (cpu_dai->suspend && !cpu_dai->ac97_control) |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 700 | cpu_dai->suspend(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 701 | if (platform->suspend) |
Mark Brown | 07c84d0 | 2008-12-03 18:17:28 +0000 | [diff] [blame] | 702 | platform->suspend(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | /* close any waiting streams and save state */ |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 706 | run_delayed_work(&card->delayed_work); |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 707 | codec->suspend_bias_level = codec->bias_level; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 708 | |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 709 | for (i = 0; i < codec->num_dai; i++) { |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 710 | char *stream = codec->dai[i].playback.stream_name; |
| 711 | if (stream != NULL) |
| 712 | snd_soc_dapm_stream_event(codec, stream, |
| 713 | SND_SOC_DAPM_STREAM_SUSPEND); |
| 714 | stream = codec->dai[i].capture.stream_name; |
| 715 | if (stream != NULL) |
| 716 | snd_soc_dapm_stream_event(codec, stream, |
| 717 | SND_SOC_DAPM_STREAM_SUSPEND); |
| 718 | } |
| 719 | |
| 720 | if (codec_dev->suspend) |
| 721 | codec_dev->suspend(pdev, state); |
| 722 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 723 | for (i = 0; i < card->num_links; i++) { |
| 724 | struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; |
Mark Brown | 3ba9e10a | 2008-11-24 18:01:05 +0000 | [diff] [blame] | 725 | if (cpu_dai->suspend && cpu_dai->ac97_control) |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 726 | cpu_dai->suspend(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 727 | } |
| 728 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 729 | if (card->suspend_post) |
| 730 | card->suspend_post(pdev, state); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 731 | |
| 732 | return 0; |
| 733 | } |
| 734 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 735 | /* deferred resume work, so resume can complete before we finished |
| 736 | * setting our codec back up, which can be very slow on I2C |
| 737 | */ |
| 738 | static void soc_resume_deferred(struct work_struct *work) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 739 | { |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 740 | struct snd_soc_card *card = container_of(work, |
| 741 | struct snd_soc_card, |
| 742 | deferred_resume_work); |
| 743 | struct snd_soc_device *socdev = card->socdev; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 744 | struct snd_soc_platform *platform = card->platform; |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 745 | struct snd_soc_codec_device *codec_dev = socdev->codec_dev; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 746 | struct snd_soc_codec *codec = card->codec; |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 747 | struct platform_device *pdev = to_platform_device(socdev->dev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 748 | int i; |
| 749 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 750 | /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, |
| 751 | * so userspace apps are blocked from touching us |
| 752 | */ |
| 753 | |
Mark Brown | fde22f2 | 2008-11-24 18:08:18 +0000 | [diff] [blame] | 754 | dev_dbg(socdev->dev, "starting resume work\n"); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 755 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 756 | if (card->resume_pre) |
| 757 | card->resume_pre(pdev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 758 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 759 | for (i = 0; i < card->num_links; i++) { |
| 760 | struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; |
Mark Brown | 3ba9e10a | 2008-11-24 18:01:05 +0000 | [diff] [blame] | 761 | if (cpu_dai->resume && cpu_dai->ac97_control) |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 762 | cpu_dai->resume(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | if (codec_dev->resume) |
| 766 | codec_dev->resume(pdev); |
| 767 | |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 768 | for (i = 0; i < codec->num_dai; i++) { |
| 769 | char *stream = codec->dai[i].playback.stream_name; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 770 | if (stream != NULL) |
| 771 | snd_soc_dapm_stream_event(codec, stream, |
| 772 | SND_SOC_DAPM_STREAM_RESUME); |
| 773 | stream = codec->dai[i].capture.stream_name; |
| 774 | if (stream != NULL) |
| 775 | snd_soc_dapm_stream_event(codec, stream, |
| 776 | SND_SOC_DAPM_STREAM_RESUME); |
| 777 | } |
| 778 | |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 779 | /* unmute any active DACs */ |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 780 | for (i = 0; i < card->num_links; i++) { |
| 781 | struct snd_soc_dai *dai = card->dai_link[i].codec_dai; |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 782 | if (dai->ops->digital_mute && dai->playback.active) |
| 783 | dai->ops->digital_mute(dai, 0); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 784 | } |
| 785 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 786 | for (i = 0; i < card->num_links; i++) { |
| 787 | struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; |
Mark Brown | 3ba9e10a | 2008-11-24 18:01:05 +0000 | [diff] [blame] | 788 | if (cpu_dai->resume && !cpu_dai->ac97_control) |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 789 | cpu_dai->resume(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 790 | if (platform->resume) |
Mark Brown | 07c84d0 | 2008-12-03 18:17:28 +0000 | [diff] [blame] | 791 | platform->resume(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 792 | } |
| 793 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 794 | if (card->resume_post) |
| 795 | card->resume_post(pdev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 796 | |
Mark Brown | fde22f2 | 2008-11-24 18:08:18 +0000 | [diff] [blame] | 797 | dev_dbg(socdev->dev, "resume work completed\n"); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 798 | |
| 799 | /* userspace can access us now we are back as we were before */ |
| 800 | snd_power_change_state(codec->card, SNDRV_CTL_POWER_D0); |
| 801 | } |
| 802 | |
| 803 | /* powers up audio subsystem after a suspend */ |
| 804 | static int soc_resume(struct platform_device *pdev) |
| 805 | { |
| 806 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 807 | struct snd_soc_card *card = socdev->card; |
Mark Brown | 64ab9ba | 2009-03-31 11:27:03 +0100 | [diff] [blame] | 808 | struct snd_soc_dai *cpu_dai = card->dai_link[0].cpu_dai; |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 809 | |
Mark Brown | 64ab9ba | 2009-03-31 11:27:03 +0100 | [diff] [blame] | 810 | /* AC97 devices might have other drivers hanging off them so |
| 811 | * need to resume immediately. Other drivers don't have that |
| 812 | * problem and may take a substantial amount of time to resume |
| 813 | * due to I/O costs and anti-pop so handle them out of line. |
| 814 | */ |
| 815 | if (cpu_dai->ac97_control) { |
| 816 | dev_dbg(socdev->dev, "Resuming AC97 immediately\n"); |
| 817 | soc_resume_deferred(&card->deferred_resume_work); |
| 818 | } else { |
| 819 | dev_dbg(socdev->dev, "Scheduling resume work\n"); |
| 820 | if (!schedule_work(&card->deferred_resume_work)) |
| 821 | dev_err(socdev->dev, "resume work item may be lost\n"); |
| 822 | } |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 823 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 824 | return 0; |
| 825 | } |
| 826 | |
| 827 | #else |
| 828 | #define soc_suspend NULL |
| 829 | #define soc_resume NULL |
| 830 | #endif |
| 831 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 832 | static void snd_soc_instantiate_card(struct snd_soc_card *card) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 833 | { |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 834 | struct platform_device *pdev = container_of(card->dev, |
| 835 | struct platform_device, |
| 836 | dev); |
| 837 | struct snd_soc_codec_device *codec_dev = card->socdev->codec_dev; |
| 838 | struct snd_soc_platform *platform; |
| 839 | struct snd_soc_dai *dai; |
Mark Brown | 6b05eda | 2008-12-08 19:26:48 +0000 | [diff] [blame] | 840 | int i, found, ret, ac97; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 841 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 842 | if (card->instantiated) |
| 843 | return; |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 844 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 845 | found = 0; |
| 846 | list_for_each_entry(platform, &platform_list, list) |
| 847 | if (card->platform == platform) { |
| 848 | found = 1; |
| 849 | break; |
| 850 | } |
| 851 | if (!found) { |
| 852 | dev_dbg(card->dev, "Platform %s not registered\n", |
| 853 | card->platform->name); |
| 854 | return; |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 855 | } |
| 856 | |
Mark Brown | 6b05eda | 2008-12-08 19:26:48 +0000 | [diff] [blame] | 857 | ac97 = 0; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 858 | for (i = 0; i < card->num_links; i++) { |
| 859 | found = 0; |
| 860 | list_for_each_entry(dai, &dai_list, list) |
| 861 | if (card->dai_link[i].cpu_dai == dai) { |
| 862 | found = 1; |
| 863 | break; |
| 864 | } |
| 865 | if (!found) { |
| 866 | dev_dbg(card->dev, "DAI %s not registered\n", |
| 867 | card->dai_link[i].cpu_dai->name); |
| 868 | return; |
| 869 | } |
Mark Brown | 6b05eda | 2008-12-08 19:26:48 +0000 | [diff] [blame] | 870 | |
| 871 | if (card->dai_link[i].cpu_dai->ac97_control) |
| 872 | ac97 = 1; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Mark Brown | 6b05eda | 2008-12-08 19:26:48 +0000 | [diff] [blame] | 875 | /* If we have AC97 in the system then don't wait for the |
| 876 | * codec. This will need revisiting if we have to handle |
| 877 | * systems with mixed AC97 and non-AC97 parts. Only check for |
| 878 | * DAIs currently; we can't do this per link since some AC97 |
| 879 | * codecs have non-AC97 DAIs. |
| 880 | */ |
| 881 | if (!ac97) |
| 882 | for (i = 0; i < card->num_links; i++) { |
| 883 | found = 0; |
| 884 | list_for_each_entry(dai, &dai_list, list) |
| 885 | if (card->dai_link[i].codec_dai == dai) { |
| 886 | found = 1; |
| 887 | break; |
| 888 | } |
| 889 | if (!found) { |
| 890 | dev_dbg(card->dev, "DAI %s not registered\n", |
| 891 | card->dai_link[i].codec_dai->name); |
| 892 | return; |
| 893 | } |
| 894 | } |
| 895 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 896 | /* Note that we do not current check for codec components */ |
| 897 | |
| 898 | dev_dbg(card->dev, "All components present, instantiating\n"); |
| 899 | |
| 900 | /* Found everything, bring it up */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 901 | if (card->probe) { |
| 902 | ret = card->probe(pdev); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 903 | if (ret < 0) |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 904 | return; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 905 | } |
| 906 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 907 | for (i = 0; i < card->num_links; i++) { |
| 908 | struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 909 | if (cpu_dai->probe) { |
Mark Brown | bdb9287 | 2008-06-11 13:47:10 +0100 | [diff] [blame] | 910 | ret = cpu_dai->probe(pdev, cpu_dai); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 911 | if (ret < 0) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 912 | goto cpu_dai_err; |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | if (codec_dev->probe) { |
| 917 | ret = codec_dev->probe(pdev); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 918 | if (ret < 0) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 919 | goto cpu_dai_err; |
| 920 | } |
| 921 | |
| 922 | if (platform->probe) { |
| 923 | ret = platform->probe(pdev); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 924 | if (ret < 0) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 925 | goto platform_err; |
| 926 | } |
| 927 | |
| 928 | /* DAPM stream work */ |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 929 | INIT_DELAYED_WORK(&card->delayed_work, close_delayed_work); |
Randy Dunlap | 1301a96 | 2008-06-17 19:19:34 +0100 | [diff] [blame] | 930 | #ifdef CONFIG_PM |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 931 | /* deferred resume work */ |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 932 | INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); |
Randy Dunlap | 1301a96 | 2008-06-17 19:19:34 +0100 | [diff] [blame] | 933 | #endif |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 934 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 935 | card->instantiated = 1; |
| 936 | |
| 937 | return; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 938 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 939 | platform_err: |
| 940 | if (codec_dev->remove) |
| 941 | codec_dev->remove(pdev); |
| 942 | |
| 943 | cpu_dai_err: |
Liam Girdwood | 18b9b3d | 2007-01-30 17:18:45 +0100 | [diff] [blame] | 944 | for (i--; i >= 0; i--) { |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 945 | struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 946 | if (cpu_dai->remove) |
Mark Brown | bdb9287 | 2008-06-11 13:47:10 +0100 | [diff] [blame] | 947 | cpu_dai->remove(pdev, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 948 | } |
| 949 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 950 | if (card->remove) |
| 951 | card->remove(pdev); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 952 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 953 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 954 | /* |
| 955 | * Attempt to initialise any uninitalised cards. Must be called with |
| 956 | * client_mutex. |
| 957 | */ |
| 958 | static void snd_soc_instantiate_cards(void) |
| 959 | { |
| 960 | struct snd_soc_card *card; |
| 961 | list_for_each_entry(card, &card_list, list) |
| 962 | snd_soc_instantiate_card(card); |
| 963 | } |
| 964 | |
| 965 | /* probes a new socdev */ |
| 966 | static int soc_probe(struct platform_device *pdev) |
| 967 | { |
| 968 | int ret = 0; |
| 969 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 970 | struct snd_soc_card *card = socdev->card; |
| 971 | |
| 972 | /* Bodge while we push things out of socdev */ |
| 973 | card->socdev = socdev; |
| 974 | |
| 975 | /* Bodge while we unpick instantiation */ |
| 976 | card->dev = &pdev->dev; |
| 977 | ret = snd_soc_register_card(card); |
| 978 | if (ret != 0) { |
| 979 | dev_err(&pdev->dev, "Failed to register card\n"); |
| 980 | return ret; |
| 981 | } |
| 982 | |
| 983 | return 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | /* removes a socdev */ |
| 987 | static int soc_remove(struct platform_device *pdev) |
| 988 | { |
| 989 | int i; |
| 990 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 991 | struct snd_soc_card *card = socdev->card; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 992 | struct snd_soc_platform *platform = card->platform; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 993 | struct snd_soc_codec_device *codec_dev = socdev->codec_dev; |
| 994 | |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 995 | run_delayed_work(&card->delayed_work); |
Liam Girdwood | 965ac42 | 2007-01-31 14:14:57 +0100 | [diff] [blame] | 996 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 997 | if (platform->remove) |
| 998 | platform->remove(pdev); |
| 999 | |
| 1000 | if (codec_dev->remove) |
| 1001 | codec_dev->remove(pdev); |
| 1002 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1003 | for (i = 0; i < card->num_links; i++) { |
| 1004 | struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1005 | if (cpu_dai->remove) |
Mark Brown | bdb9287 | 2008-06-11 13:47:10 +0100 | [diff] [blame] | 1006 | cpu_dai->remove(pdev, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1007 | } |
| 1008 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1009 | if (card->remove) |
| 1010 | card->remove(pdev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1011 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 1012 | snd_soc_unregister_card(card); |
| 1013 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1014 | return 0; |
| 1015 | } |
| 1016 | |
| 1017 | /* ASoC platform driver */ |
| 1018 | static struct platform_driver soc_driver = { |
| 1019 | .driver = { |
| 1020 | .name = "soc-audio", |
Kay Sievers | 8b45a20 | 2008-04-14 13:33:36 +0200 | [diff] [blame] | 1021 | .owner = THIS_MODULE, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1022 | }, |
| 1023 | .probe = soc_probe, |
| 1024 | .remove = soc_remove, |
| 1025 | .suspend = soc_suspend, |
| 1026 | .resume = soc_resume, |
| 1027 | }; |
| 1028 | |
| 1029 | /* create a new pcm */ |
| 1030 | static int soc_new_pcm(struct snd_soc_device *socdev, |
| 1031 | struct snd_soc_dai_link *dai_link, int num) |
| 1032 | { |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 1033 | struct snd_soc_card *card = socdev->card; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 1034 | struct snd_soc_codec *codec = card->codec; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 1035 | struct snd_soc_platform *platform = card->platform; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 1036 | struct snd_soc_dai *codec_dai = dai_link->codec_dai; |
| 1037 | struct snd_soc_dai *cpu_dai = dai_link->cpu_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1038 | struct snd_soc_pcm_runtime *rtd; |
| 1039 | struct snd_pcm *pcm; |
| 1040 | char new_name[64]; |
| 1041 | int ret = 0, playback = 0, capture = 0; |
| 1042 | |
| 1043 | rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL); |
| 1044 | if (rtd == NULL) |
| 1045 | return -ENOMEM; |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 1046 | |
| 1047 | rtd->dai = dai_link; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1048 | rtd->socdev = socdev; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 1049 | codec_dai->codec = card->codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1050 | |
| 1051 | /* check client and interface hw capabilities */ |
Mark Brown | 3ba9e10a | 2008-11-24 18:01:05 +0000 | [diff] [blame] | 1052 | sprintf(new_name, "%s %s-%d", dai_link->stream_name, codec_dai->name, |
| 1053 | num); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1054 | |
| 1055 | if (codec_dai->playback.channels_min) |
| 1056 | playback = 1; |
| 1057 | if (codec_dai->capture.channels_min) |
| 1058 | capture = 1; |
| 1059 | |
| 1060 | ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback, |
| 1061 | capture, &pcm); |
| 1062 | if (ret < 0) { |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 1063 | printk(KERN_ERR "asoc: can't create pcm for codec %s\n", |
| 1064 | codec->name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1065 | kfree(rtd); |
| 1066 | return ret; |
| 1067 | } |
| 1068 | |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 1069 | dai_link->pcm = pcm; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1070 | pcm->private_data = rtd; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 1071 | soc_pcm_ops.mmap = platform->pcm_ops->mmap; |
| 1072 | soc_pcm_ops.pointer = platform->pcm_ops->pointer; |
| 1073 | soc_pcm_ops.ioctl = platform->pcm_ops->ioctl; |
| 1074 | soc_pcm_ops.copy = platform->pcm_ops->copy; |
| 1075 | soc_pcm_ops.silence = platform->pcm_ops->silence; |
| 1076 | soc_pcm_ops.ack = platform->pcm_ops->ack; |
| 1077 | soc_pcm_ops.page = platform->pcm_ops->page; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1078 | |
| 1079 | if (playback) |
| 1080 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops); |
| 1081 | |
| 1082 | if (capture) |
| 1083 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops); |
| 1084 | |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 1085 | ret = platform->pcm_new(codec->card, codec_dai, pcm); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1086 | if (ret < 0) { |
| 1087 | printk(KERN_ERR "asoc: platform pcm constructor failed\n"); |
| 1088 | kfree(rtd); |
| 1089 | return ret; |
| 1090 | } |
| 1091 | |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 1092 | pcm->private_free = platform->pcm_free; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1093 | printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name, |
| 1094 | cpu_dai->name); |
| 1095 | return ret; |
| 1096 | } |
| 1097 | |
| 1098 | /* codec register dump */ |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 1099 | static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1100 | { |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1101 | int i, step = 1, count = 0; |
| 1102 | |
| 1103 | if (!codec->reg_cache_size) |
| 1104 | return 0; |
| 1105 | |
| 1106 | if (codec->reg_cache_step) |
| 1107 | step = codec->reg_cache_step; |
| 1108 | |
| 1109 | count += sprintf(buf, "%s registers\n", codec->name); |
Mark Brown | 58cd33c | 2008-07-29 11:42:25 +0100 | [diff] [blame] | 1110 | for (i = 0; i < codec->reg_cache_size; i += step) { |
| 1111 | count += sprintf(buf + count, "%2x: ", i); |
| 1112 | if (count >= PAGE_SIZE - 1) |
| 1113 | break; |
| 1114 | |
| 1115 | if (codec->display_register) |
| 1116 | count += codec->display_register(codec, buf + count, |
| 1117 | PAGE_SIZE - count, i); |
| 1118 | else |
| 1119 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 1120 | "%4x", codec->read(codec, i)); |
| 1121 | |
| 1122 | if (count >= PAGE_SIZE - 1) |
| 1123 | break; |
| 1124 | |
| 1125 | count += snprintf(buf + count, PAGE_SIZE - count, "\n"); |
| 1126 | if (count >= PAGE_SIZE - 1) |
| 1127 | break; |
| 1128 | } |
| 1129 | |
| 1130 | /* Truncate count; min() would cause a warning */ |
| 1131 | if (count >= PAGE_SIZE) |
| 1132 | count = PAGE_SIZE - 1; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1133 | |
| 1134 | return count; |
| 1135 | } |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1136 | static ssize_t codec_reg_show(struct device *dev, |
| 1137 | struct device_attribute *attr, char *buf) |
| 1138 | { |
| 1139 | struct snd_soc_device *devdata = dev_get_drvdata(dev); |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 1140 | return soc_codec_reg_show(devdata->card->codec, buf); |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1143 | static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL); |
| 1144 | |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1145 | #ifdef CONFIG_DEBUG_FS |
| 1146 | static int codec_reg_open_file(struct inode *inode, struct file *file) |
| 1147 | { |
| 1148 | file->private_data = inode->i_private; |
| 1149 | return 0; |
| 1150 | } |
| 1151 | |
| 1152 | static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf, |
| 1153 | size_t count, loff_t *ppos) |
| 1154 | { |
| 1155 | ssize_t ret; |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 1156 | struct snd_soc_codec *codec = file->private_data; |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1157 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 1158 | if (!buf) |
| 1159 | return -ENOMEM; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 1160 | ret = soc_codec_reg_show(codec, buf); |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1161 | if (ret >= 0) |
| 1162 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 1163 | kfree(buf); |
| 1164 | return ret; |
| 1165 | } |
| 1166 | |
| 1167 | static ssize_t codec_reg_write_file(struct file *file, |
| 1168 | const char __user *user_buf, size_t count, loff_t *ppos) |
| 1169 | { |
| 1170 | char buf[32]; |
| 1171 | int buf_size; |
| 1172 | char *start = buf; |
| 1173 | unsigned long reg, value; |
| 1174 | int step = 1; |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 1175 | struct snd_soc_codec *codec = file->private_data; |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1176 | |
| 1177 | buf_size = min(count, (sizeof(buf)-1)); |
| 1178 | if (copy_from_user(buf, user_buf, buf_size)) |
| 1179 | return -EFAULT; |
| 1180 | buf[buf_size] = 0; |
| 1181 | |
| 1182 | if (codec->reg_cache_step) |
| 1183 | step = codec->reg_cache_step; |
| 1184 | |
| 1185 | while (*start == ' ') |
| 1186 | start++; |
| 1187 | reg = simple_strtoul(start, &start, 16); |
| 1188 | if ((reg >= codec->reg_cache_size) || (reg % step)) |
| 1189 | return -EINVAL; |
| 1190 | while (*start == ' ') |
| 1191 | start++; |
| 1192 | if (strict_strtoul(start, 16, &value)) |
| 1193 | return -EINVAL; |
| 1194 | codec->write(codec, reg, value); |
| 1195 | return buf_size; |
| 1196 | } |
| 1197 | |
| 1198 | static const struct file_operations codec_reg_fops = { |
| 1199 | .open = codec_reg_open_file, |
| 1200 | .read = codec_reg_read_file, |
| 1201 | .write = codec_reg_write_file, |
| 1202 | }; |
| 1203 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 1204 | static void soc_init_codec_debugfs(struct snd_soc_codec *codec) |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1205 | { |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 1206 | codec->debugfs_reg = debugfs_create_file("codec_reg", 0644, |
| 1207 | debugfs_root, codec, |
| 1208 | &codec_reg_fops); |
| 1209 | if (!codec->debugfs_reg) |
| 1210 | printk(KERN_WARNING |
| 1211 | "ASoC: Failed to create codec register debugfs file\n"); |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1212 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 1213 | codec->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0744, |
| 1214 | debugfs_root, |
| 1215 | &codec->pop_time); |
| 1216 | if (!codec->debugfs_pop_time) |
| 1217 | printk(KERN_WARNING |
| 1218 | "Failed to create pop time debugfs file\n"); |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 1221 | static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1222 | { |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 1223 | debugfs_remove(codec->debugfs_pop_time); |
| 1224 | debugfs_remove(codec->debugfs_reg); |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | #else |
| 1228 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 1229 | static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec) |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1230 | { |
| 1231 | } |
| 1232 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 1233 | static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1234 | { |
| 1235 | } |
| 1236 | #endif |
| 1237 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1238 | /** |
| 1239 | * snd_soc_new_ac97_codec - initailise AC97 device |
| 1240 | * @codec: audio codec |
| 1241 | * @ops: AC97 bus operations |
| 1242 | * @num: AC97 codec number |
| 1243 | * |
| 1244 | * Initialises AC97 codec resources for use by ad-hoc devices only. |
| 1245 | */ |
| 1246 | int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, |
| 1247 | struct snd_ac97_bus_ops *ops, int num) |
| 1248 | { |
| 1249 | mutex_lock(&codec->mutex); |
| 1250 | |
| 1251 | codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL); |
| 1252 | if (codec->ac97 == NULL) { |
| 1253 | mutex_unlock(&codec->mutex); |
| 1254 | return -ENOMEM; |
| 1255 | } |
| 1256 | |
| 1257 | codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL); |
| 1258 | if (codec->ac97->bus == NULL) { |
| 1259 | kfree(codec->ac97); |
| 1260 | codec->ac97 = NULL; |
| 1261 | mutex_unlock(&codec->mutex); |
| 1262 | return -ENOMEM; |
| 1263 | } |
| 1264 | |
| 1265 | codec->ac97->bus->ops = ops; |
| 1266 | codec->ac97->num = num; |
| 1267 | mutex_unlock(&codec->mutex); |
| 1268 | return 0; |
| 1269 | } |
| 1270 | EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec); |
| 1271 | |
| 1272 | /** |
| 1273 | * snd_soc_free_ac97_codec - free AC97 codec device |
| 1274 | * @codec: audio codec |
| 1275 | * |
| 1276 | * Frees AC97 codec device resources. |
| 1277 | */ |
| 1278 | void snd_soc_free_ac97_codec(struct snd_soc_codec *codec) |
| 1279 | { |
| 1280 | mutex_lock(&codec->mutex); |
| 1281 | kfree(codec->ac97->bus); |
| 1282 | kfree(codec->ac97); |
| 1283 | codec->ac97 = NULL; |
| 1284 | mutex_unlock(&codec->mutex); |
| 1285 | } |
| 1286 | EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec); |
| 1287 | |
| 1288 | /** |
| 1289 | * snd_soc_update_bits - update codec register bits |
| 1290 | * @codec: audio codec |
| 1291 | * @reg: codec register |
| 1292 | * @mask: register mask |
| 1293 | * @value: new value |
| 1294 | * |
| 1295 | * Writes new register value. |
| 1296 | * |
| 1297 | * Returns 1 for change else 0. |
| 1298 | */ |
| 1299 | int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg, |
| 1300 | unsigned short mask, unsigned short value) |
| 1301 | { |
| 1302 | int change; |
| 1303 | unsigned short old, new; |
| 1304 | |
| 1305 | mutex_lock(&io_mutex); |
| 1306 | old = snd_soc_read(codec, reg); |
| 1307 | new = (old & ~mask) | value; |
| 1308 | change = old != new; |
| 1309 | if (change) |
| 1310 | snd_soc_write(codec, reg, new); |
| 1311 | |
| 1312 | mutex_unlock(&io_mutex); |
| 1313 | return change; |
| 1314 | } |
| 1315 | EXPORT_SYMBOL_GPL(snd_soc_update_bits); |
| 1316 | |
| 1317 | /** |
| 1318 | * snd_soc_test_bits - test register for change |
| 1319 | * @codec: audio codec |
| 1320 | * @reg: codec register |
| 1321 | * @mask: register mask |
| 1322 | * @value: new value |
| 1323 | * |
| 1324 | * Tests a register with a new value and checks if the new value is |
| 1325 | * different from the old value. |
| 1326 | * |
| 1327 | * Returns 1 for change else 0. |
| 1328 | */ |
| 1329 | int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg, |
| 1330 | unsigned short mask, unsigned short value) |
| 1331 | { |
| 1332 | int change; |
| 1333 | unsigned short old, new; |
| 1334 | |
| 1335 | mutex_lock(&io_mutex); |
| 1336 | old = snd_soc_read(codec, reg); |
| 1337 | new = (old & ~mask) | value; |
| 1338 | change = old != new; |
| 1339 | mutex_unlock(&io_mutex); |
| 1340 | |
| 1341 | return change; |
| 1342 | } |
| 1343 | EXPORT_SYMBOL_GPL(snd_soc_test_bits); |
| 1344 | |
| 1345 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1346 | * snd_soc_new_pcms - create new sound card and pcms |
| 1347 | * @socdev: the SoC audio device |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1348 | * @idx: ALSA card index |
| 1349 | * @xid: card identification |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1350 | * |
| 1351 | * Create a new sound card based upon the codec and interface pcms. |
| 1352 | * |
| 1353 | * Returns 0 for success, else error. |
| 1354 | */ |
Liam Girdwood | bc7320c | 2007-02-01 12:26:07 +0100 | [diff] [blame] | 1355 | int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1356 | { |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1357 | struct snd_soc_card *card = socdev->card; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 1358 | struct snd_soc_codec *codec = card->codec; |
Takashi Iwai | bd7dd77 | 2008-12-28 16:45:02 +0100 | [diff] [blame] | 1359 | int ret, i; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1360 | |
| 1361 | mutex_lock(&codec->mutex); |
| 1362 | |
| 1363 | /* register a sound card */ |
Takashi Iwai | bd7dd77 | 2008-12-28 16:45:02 +0100 | [diff] [blame] | 1364 | ret = snd_card_create(idx, xid, codec->owner, 0, &codec->card); |
| 1365 | if (ret < 0) { |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1366 | printk(KERN_ERR "asoc: can't create sound card for codec %s\n", |
| 1367 | codec->name); |
| 1368 | mutex_unlock(&codec->mutex); |
Takashi Iwai | bd7dd77 | 2008-12-28 16:45:02 +0100 | [diff] [blame] | 1369 | return ret; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | codec->card->dev = socdev->dev; |
| 1373 | codec->card->private_data = codec; |
| 1374 | strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver)); |
| 1375 | |
| 1376 | /* create the pcms */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1377 | for (i = 0; i < card->num_links; i++) { |
| 1378 | ret = soc_new_pcm(socdev, &card->dai_link[i], i); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1379 | if (ret < 0) { |
| 1380 | printk(KERN_ERR "asoc: can't create pcm %s\n", |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1381 | card->dai_link[i].stream_name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1382 | mutex_unlock(&codec->mutex); |
| 1383 | return ret; |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | mutex_unlock(&codec->mutex); |
| 1388 | return ret; |
| 1389 | } |
| 1390 | EXPORT_SYMBOL_GPL(snd_soc_new_pcms); |
| 1391 | |
| 1392 | /** |
Mark Brown | 968a602 | 2008-11-28 11:49:07 +0000 | [diff] [blame] | 1393 | * snd_soc_init_card - register sound card |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1394 | * @socdev: the SoC audio device |
| 1395 | * |
| 1396 | * Register a SoC sound card. Also registers an AC97 device if the |
| 1397 | * codec is AC97 for ad hoc devices. |
| 1398 | * |
| 1399 | * Returns 0 for success, else error. |
| 1400 | */ |
Mark Brown | 968a602 | 2008-11-28 11:49:07 +0000 | [diff] [blame] | 1401 | int snd_soc_init_card(struct snd_soc_device *socdev) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1402 | { |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1403 | struct snd_soc_card *card = socdev->card; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 1404 | struct snd_soc_codec *codec = card->codec; |
Liam Girdwood | 12e74f7 | 2006-10-16 21:19:48 +0200 | [diff] [blame] | 1405 | int ret = 0, i, ac97 = 0, err = 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1406 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1407 | for (i = 0; i < card->num_links; i++) { |
| 1408 | if (card->dai_link[i].init) { |
| 1409 | err = card->dai_link[i].init(codec); |
Liam Girdwood | 12e74f7 | 2006-10-16 21:19:48 +0200 | [diff] [blame] | 1410 | if (err < 0) { |
| 1411 | printk(KERN_ERR "asoc: failed to init %s\n", |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1412 | card->dai_link[i].stream_name); |
Liam Girdwood | 12e74f7 | 2006-10-16 21:19:48 +0200 | [diff] [blame] | 1413 | continue; |
| 1414 | } |
| 1415 | } |
Mark Brown | 3ba9e10a | 2008-11-24 18:01:05 +0000 | [diff] [blame] | 1416 | if (card->dai_link[i].codec_dai->ac97_control) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1417 | ac97 = 1; |
| 1418 | } |
| 1419 | snprintf(codec->card->shortname, sizeof(codec->card->shortname), |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1420 | "%s", card->name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1421 | snprintf(codec->card->longname, sizeof(codec->card->longname), |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1422 | "%s (%s)", card->name, codec->name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1423 | |
| 1424 | ret = snd_card_register(codec->card); |
| 1425 | if (ret < 0) { |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 1426 | printk(KERN_ERR "asoc: failed to register soundcard for %s\n", |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1427 | codec->name); |
Liam Girdwood | 12e74f7 | 2006-10-16 21:19:48 +0200 | [diff] [blame] | 1428 | goto out; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1429 | } |
| 1430 | |
Mark Brown | 08c8efe | 2008-01-21 14:33:37 +0100 | [diff] [blame] | 1431 | mutex_lock(&codec->mutex); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1432 | #ifdef CONFIG_SND_SOC_AC97_BUS |
Mark Brown | 14fa43f | 2009-02-12 19:33:19 +0000 | [diff] [blame] | 1433 | /* Only instantiate AC97 if not already done by the adaptor |
| 1434 | * for the generic AC97 subsystem. |
| 1435 | */ |
| 1436 | if (ac97 && strcmp(codec->name, "AC97") != 0) { |
Liam Girdwood | 12e74f7 | 2006-10-16 21:19:48 +0200 | [diff] [blame] | 1437 | ret = soc_ac97_dev_register(codec); |
| 1438 | if (ret < 0) { |
| 1439 | printk(KERN_ERR "asoc: AC97 device register failed\n"); |
| 1440 | snd_card_free(codec->card); |
Mark Brown | 08c8efe | 2008-01-21 14:33:37 +0100 | [diff] [blame] | 1441 | mutex_unlock(&codec->mutex); |
Liam Girdwood | 12e74f7 | 2006-10-16 21:19:48 +0200 | [diff] [blame] | 1442 | goto out; |
| 1443 | } |
| 1444 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1445 | #endif |
| 1446 | |
Liam Girdwood | 12e74f7 | 2006-10-16 21:19:48 +0200 | [diff] [blame] | 1447 | err = snd_soc_dapm_sys_add(socdev->dev); |
| 1448 | if (err < 0) |
| 1449 | printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n"); |
| 1450 | |
| 1451 | err = device_create_file(socdev->dev, &dev_attr_codec_reg); |
| 1452 | if (err < 0) |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 1453 | printk(KERN_WARNING "asoc: failed to add codec sysfs files\n"); |
Mark Brown | 08c8efe | 2008-01-21 14:33:37 +0100 | [diff] [blame] | 1454 | |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 1455 | soc_init_codec_debugfs(codec); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1456 | mutex_unlock(&codec->mutex); |
Mark Brown | 08c8efe | 2008-01-21 14:33:37 +0100 | [diff] [blame] | 1457 | |
| 1458 | out: |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1459 | return ret; |
| 1460 | } |
Mark Brown | 968a602 | 2008-11-28 11:49:07 +0000 | [diff] [blame] | 1461 | EXPORT_SYMBOL_GPL(snd_soc_init_card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1462 | |
| 1463 | /** |
| 1464 | * snd_soc_free_pcms - free sound card and pcms |
| 1465 | * @socdev: the SoC audio device |
| 1466 | * |
| 1467 | * Frees sound card and pcms associated with the socdev. |
| 1468 | * Also unregister the codec if it is an AC97 device. |
| 1469 | */ |
| 1470 | void snd_soc_free_pcms(struct snd_soc_device *socdev) |
| 1471 | { |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 1472 | struct snd_soc_codec *codec = socdev->card->codec; |
Liam Girdwood | a68660e | 2007-05-10 19:27:27 +0200 | [diff] [blame] | 1473 | #ifdef CONFIG_SND_SOC_AC97_BUS |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 1474 | struct snd_soc_dai *codec_dai; |
Liam Girdwood | a68660e | 2007-05-10 19:27:27 +0200 | [diff] [blame] | 1475 | int i; |
| 1476 | #endif |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1477 | |
| 1478 | mutex_lock(&codec->mutex); |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 1479 | soc_cleanup_codec_debugfs(codec); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1480 | #ifdef CONFIG_SND_SOC_AC97_BUS |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 1481 | for (i = 0; i < codec->num_dai; i++) { |
Liam Girdwood | a68660e | 2007-05-10 19:27:27 +0200 | [diff] [blame] | 1482 | codec_dai = &codec->dai[i]; |
Atsushi Nemoto | d2314e0 | 2009-03-16 23:26:20 +0900 | [diff] [blame] | 1483 | if (codec_dai->ac97_control && codec->ac97 && |
| 1484 | strcmp(codec->name, "AC97") != 0) { |
Liam Girdwood | a68660e | 2007-05-10 19:27:27 +0200 | [diff] [blame] | 1485 | soc_ac97_dev_unregister(codec); |
| 1486 | goto free_card; |
| 1487 | } |
| 1488 | } |
| 1489 | free_card: |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1490 | #endif |
| 1491 | |
| 1492 | if (codec->card) |
| 1493 | snd_card_free(codec->card); |
| 1494 | device_remove_file(socdev->dev, &dev_attr_codec_reg); |
| 1495 | mutex_unlock(&codec->mutex); |
| 1496 | } |
| 1497 | EXPORT_SYMBOL_GPL(snd_soc_free_pcms); |
| 1498 | |
| 1499 | /** |
| 1500 | * snd_soc_set_runtime_hwparams - set the runtime hardware parameters |
| 1501 | * @substream: the pcm substream |
| 1502 | * @hw: the hardware parameters |
| 1503 | * |
| 1504 | * Sets the substream runtime hardware parameters. |
| 1505 | */ |
| 1506 | int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, |
| 1507 | const struct snd_pcm_hardware *hw) |
| 1508 | { |
| 1509 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1510 | runtime->hw.info = hw->info; |
| 1511 | runtime->hw.formats = hw->formats; |
| 1512 | runtime->hw.period_bytes_min = hw->period_bytes_min; |
| 1513 | runtime->hw.period_bytes_max = hw->period_bytes_max; |
| 1514 | runtime->hw.periods_min = hw->periods_min; |
| 1515 | runtime->hw.periods_max = hw->periods_max; |
| 1516 | runtime->hw.buffer_bytes_max = hw->buffer_bytes_max; |
| 1517 | runtime->hw.fifo_size = hw->fifo_size; |
| 1518 | return 0; |
| 1519 | } |
| 1520 | EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams); |
| 1521 | |
| 1522 | /** |
| 1523 | * snd_soc_cnew - create new control |
| 1524 | * @_template: control template |
| 1525 | * @data: control private data |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1526 | * @long_name: control long name |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1527 | * |
| 1528 | * Create a new mixer control from a template control. |
| 1529 | * |
| 1530 | * Returns 0 for success, else error. |
| 1531 | */ |
| 1532 | struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, |
| 1533 | void *data, char *long_name) |
| 1534 | { |
| 1535 | struct snd_kcontrol_new template; |
| 1536 | |
| 1537 | memcpy(&template, _template, sizeof(template)); |
| 1538 | if (long_name) |
| 1539 | template.name = long_name; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1540 | template.index = 0; |
| 1541 | |
| 1542 | return snd_ctl_new1(&template, data); |
| 1543 | } |
| 1544 | EXPORT_SYMBOL_GPL(snd_soc_cnew); |
| 1545 | |
| 1546 | /** |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 1547 | * snd_soc_add_controls - add an array of controls to a codec. |
| 1548 | * Convienience function to add a list of controls. Many codecs were |
| 1549 | * duplicating this code. |
| 1550 | * |
| 1551 | * @codec: codec to add controls to |
| 1552 | * @controls: array of controls to add |
| 1553 | * @num_controls: number of elements in the array |
| 1554 | * |
| 1555 | * Return 0 for success, else error. |
| 1556 | */ |
| 1557 | int snd_soc_add_controls(struct snd_soc_codec *codec, |
| 1558 | const struct snd_kcontrol_new *controls, int num_controls) |
| 1559 | { |
| 1560 | struct snd_card *card = codec->card; |
| 1561 | int err, i; |
| 1562 | |
| 1563 | for (i = 0; i < num_controls; i++) { |
| 1564 | const struct snd_kcontrol_new *control = &controls[i]; |
| 1565 | err = snd_ctl_add(card, snd_soc_cnew(control, codec, NULL)); |
| 1566 | if (err < 0) { |
| 1567 | dev_err(codec->dev, "%s: Failed to add %s\n", |
| 1568 | codec->name, control->name); |
| 1569 | return err; |
| 1570 | } |
| 1571 | } |
| 1572 | |
| 1573 | return 0; |
| 1574 | } |
| 1575 | EXPORT_SYMBOL_GPL(snd_soc_add_controls); |
| 1576 | |
| 1577 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1578 | * snd_soc_info_enum_double - enumerated double mixer info callback |
| 1579 | * @kcontrol: mixer control |
| 1580 | * @uinfo: control element information |
| 1581 | * |
| 1582 | * Callback to provide information about a double enumerated |
| 1583 | * mixer control. |
| 1584 | * |
| 1585 | * Returns 0 for success. |
| 1586 | */ |
| 1587 | int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, |
| 1588 | struct snd_ctl_elem_info *uinfo) |
| 1589 | { |
| 1590 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1591 | |
| 1592 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1593 | uinfo->count = e->shift_l == e->shift_r ? 1 : 2; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1594 | uinfo->value.enumerated.items = e->max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1595 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1596 | if (uinfo->value.enumerated.item > e->max - 1) |
| 1597 | uinfo->value.enumerated.item = e->max - 1; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1598 | strcpy(uinfo->value.enumerated.name, |
| 1599 | e->texts[uinfo->value.enumerated.item]); |
| 1600 | return 0; |
| 1601 | } |
| 1602 | EXPORT_SYMBOL_GPL(snd_soc_info_enum_double); |
| 1603 | |
| 1604 | /** |
| 1605 | * snd_soc_get_enum_double - enumerated double mixer get callback |
| 1606 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1607 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1608 | * |
| 1609 | * Callback to get the value of a double enumerated mixer. |
| 1610 | * |
| 1611 | * Returns 0 for success. |
| 1612 | */ |
| 1613 | int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol, |
| 1614 | struct snd_ctl_elem_value *ucontrol) |
| 1615 | { |
| 1616 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1617 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1618 | unsigned short val, bitmask; |
| 1619 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1620 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1621 | ; |
| 1622 | val = snd_soc_read(codec, e->reg); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 1623 | ucontrol->value.enumerated.item[0] |
| 1624 | = (val >> e->shift_l) & (bitmask - 1); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1625 | if (e->shift_l != e->shift_r) |
| 1626 | ucontrol->value.enumerated.item[1] = |
| 1627 | (val >> e->shift_r) & (bitmask - 1); |
| 1628 | |
| 1629 | return 0; |
| 1630 | } |
| 1631 | EXPORT_SYMBOL_GPL(snd_soc_get_enum_double); |
| 1632 | |
| 1633 | /** |
| 1634 | * snd_soc_put_enum_double - enumerated double mixer put callback |
| 1635 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1636 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1637 | * |
| 1638 | * Callback to set the value of a double enumerated mixer. |
| 1639 | * |
| 1640 | * Returns 0 for success. |
| 1641 | */ |
| 1642 | int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, |
| 1643 | struct snd_ctl_elem_value *ucontrol) |
| 1644 | { |
| 1645 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1646 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1647 | unsigned short val; |
| 1648 | unsigned short mask, bitmask; |
| 1649 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1650 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1651 | ; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1652 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1653 | return -EINVAL; |
| 1654 | val = ucontrol->value.enumerated.item[0] << e->shift_l; |
| 1655 | mask = (bitmask - 1) << e->shift_l; |
| 1656 | if (e->shift_l != e->shift_r) { |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1657 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1658 | return -EINVAL; |
| 1659 | val |= ucontrol->value.enumerated.item[1] << e->shift_r; |
| 1660 | mask |= (bitmask - 1) << e->shift_r; |
| 1661 | } |
| 1662 | |
| 1663 | return snd_soc_update_bits(codec, e->reg, mask, val); |
| 1664 | } |
| 1665 | EXPORT_SYMBOL_GPL(snd_soc_put_enum_double); |
| 1666 | |
| 1667 | /** |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1668 | * snd_soc_get_value_enum_double - semi enumerated double mixer get callback |
| 1669 | * @kcontrol: mixer control |
| 1670 | * @ucontrol: control element information |
| 1671 | * |
| 1672 | * Callback to get the value of a double semi enumerated mixer. |
| 1673 | * |
| 1674 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 1675 | * used for handling bitfield coded enumeration for example. |
| 1676 | * |
| 1677 | * Returns 0 for success. |
| 1678 | */ |
| 1679 | int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol, |
| 1680 | struct snd_ctl_elem_value *ucontrol) |
| 1681 | { |
| 1682 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 1683 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1684 | unsigned short reg_val, val, mux; |
| 1685 | |
| 1686 | reg_val = snd_soc_read(codec, e->reg); |
| 1687 | val = (reg_val >> e->shift_l) & e->mask; |
| 1688 | for (mux = 0; mux < e->max; mux++) { |
| 1689 | if (val == e->values[mux]) |
| 1690 | break; |
| 1691 | } |
| 1692 | ucontrol->value.enumerated.item[0] = mux; |
| 1693 | if (e->shift_l != e->shift_r) { |
| 1694 | val = (reg_val >> e->shift_r) & e->mask; |
| 1695 | for (mux = 0; mux < e->max; mux++) { |
| 1696 | if (val == e->values[mux]) |
| 1697 | break; |
| 1698 | } |
| 1699 | ucontrol->value.enumerated.item[1] = mux; |
| 1700 | } |
| 1701 | |
| 1702 | return 0; |
| 1703 | } |
| 1704 | EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double); |
| 1705 | |
| 1706 | /** |
| 1707 | * snd_soc_put_value_enum_double - semi enumerated double mixer put callback |
| 1708 | * @kcontrol: mixer control |
| 1709 | * @ucontrol: control element information |
| 1710 | * |
| 1711 | * Callback to set the value of a double semi enumerated mixer. |
| 1712 | * |
| 1713 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 1714 | * used for handling bitfield coded enumeration for example. |
| 1715 | * |
| 1716 | * Returns 0 for success. |
| 1717 | */ |
| 1718 | int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol, |
| 1719 | struct snd_ctl_elem_value *ucontrol) |
| 1720 | { |
| 1721 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 1722 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1723 | unsigned short val; |
| 1724 | unsigned short mask; |
| 1725 | |
| 1726 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 1727 | return -EINVAL; |
| 1728 | val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; |
| 1729 | mask = e->mask << e->shift_l; |
| 1730 | if (e->shift_l != e->shift_r) { |
| 1731 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
| 1732 | return -EINVAL; |
| 1733 | val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; |
| 1734 | mask |= e->mask << e->shift_r; |
| 1735 | } |
| 1736 | |
| 1737 | return snd_soc_update_bits(codec, e->reg, mask, val); |
| 1738 | } |
| 1739 | EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double); |
| 1740 | |
| 1741 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1742 | * snd_soc_info_enum_ext - external enumerated single mixer info callback |
| 1743 | * @kcontrol: mixer control |
| 1744 | * @uinfo: control element information |
| 1745 | * |
| 1746 | * Callback to provide information about an external enumerated |
| 1747 | * single mixer. |
| 1748 | * |
| 1749 | * Returns 0 for success. |
| 1750 | */ |
| 1751 | int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol, |
| 1752 | struct snd_ctl_elem_info *uinfo) |
| 1753 | { |
| 1754 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1755 | |
| 1756 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1757 | uinfo->count = 1; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1758 | uinfo->value.enumerated.items = e->max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1759 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1760 | if (uinfo->value.enumerated.item > e->max - 1) |
| 1761 | uinfo->value.enumerated.item = e->max - 1; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1762 | strcpy(uinfo->value.enumerated.name, |
| 1763 | e->texts[uinfo->value.enumerated.item]); |
| 1764 | return 0; |
| 1765 | } |
| 1766 | EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext); |
| 1767 | |
| 1768 | /** |
| 1769 | * snd_soc_info_volsw_ext - external single mixer info callback |
| 1770 | * @kcontrol: mixer control |
| 1771 | * @uinfo: control element information |
| 1772 | * |
| 1773 | * Callback to provide information about a single external mixer control. |
| 1774 | * |
| 1775 | * Returns 0 for success. |
| 1776 | */ |
| 1777 | int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol, |
| 1778 | struct snd_ctl_elem_info *uinfo) |
| 1779 | { |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1780 | int max = kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1781 | |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1782 | if (max == 1) |
| 1783 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 1784 | else |
| 1785 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1786 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1787 | uinfo->count = 1; |
| 1788 | uinfo->value.integer.min = 0; |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1789 | uinfo->value.integer.max = max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1790 | return 0; |
| 1791 | } |
| 1792 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext); |
| 1793 | |
| 1794 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1795 | * snd_soc_info_volsw - single mixer info callback |
| 1796 | * @kcontrol: mixer control |
| 1797 | * @uinfo: control element information |
| 1798 | * |
| 1799 | * Callback to provide information about a single mixer control. |
| 1800 | * |
| 1801 | * Returns 0 for success. |
| 1802 | */ |
| 1803 | int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, |
| 1804 | struct snd_ctl_elem_info *uinfo) |
| 1805 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1806 | struct soc_mixer_control *mc = |
| 1807 | (struct soc_mixer_control *)kcontrol->private_value; |
| 1808 | int max = mc->max; |
Mark Brown | 762b8df | 2008-10-30 12:37:08 +0000 | [diff] [blame] | 1809 | unsigned int shift = mc->shift; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1810 | unsigned int rshift = mc->rshift; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1811 | |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1812 | if (max == 1) |
| 1813 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 1814 | else |
| 1815 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1816 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1817 | uinfo->count = shift == rshift ? 1 : 2; |
| 1818 | uinfo->value.integer.min = 0; |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1819 | uinfo->value.integer.max = max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1820 | return 0; |
| 1821 | } |
| 1822 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw); |
| 1823 | |
| 1824 | /** |
| 1825 | * snd_soc_get_volsw - single mixer get callback |
| 1826 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1827 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1828 | * |
| 1829 | * Callback to get the value of a single mixer control. |
| 1830 | * |
| 1831 | * Returns 0 for success. |
| 1832 | */ |
| 1833 | int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, |
| 1834 | struct snd_ctl_elem_value *ucontrol) |
| 1835 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1836 | struct soc_mixer_control *mc = |
| 1837 | (struct soc_mixer_control *)kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1838 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1839 | unsigned int reg = mc->reg; |
| 1840 | unsigned int shift = mc->shift; |
| 1841 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1842 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1843 | unsigned int mask = (1 << fls(max)) - 1; |
| 1844 | unsigned int invert = mc->invert; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1845 | |
| 1846 | ucontrol->value.integer.value[0] = |
| 1847 | (snd_soc_read(codec, reg) >> shift) & mask; |
| 1848 | if (shift != rshift) |
| 1849 | ucontrol->value.integer.value[1] = |
| 1850 | (snd_soc_read(codec, reg) >> rshift) & mask; |
| 1851 | if (invert) { |
| 1852 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1853 | max - ucontrol->value.integer.value[0]; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1854 | if (shift != rshift) |
| 1855 | ucontrol->value.integer.value[1] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1856 | max - ucontrol->value.integer.value[1]; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | return 0; |
| 1860 | } |
| 1861 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw); |
| 1862 | |
| 1863 | /** |
| 1864 | * snd_soc_put_volsw - single mixer put callback |
| 1865 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1866 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1867 | * |
| 1868 | * Callback to set the value of a single mixer control. |
| 1869 | * |
| 1870 | * Returns 0 for success. |
| 1871 | */ |
| 1872 | int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, |
| 1873 | struct snd_ctl_elem_value *ucontrol) |
| 1874 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1875 | struct soc_mixer_control *mc = |
| 1876 | (struct soc_mixer_control *)kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1877 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1878 | unsigned int reg = mc->reg; |
| 1879 | unsigned int shift = mc->shift; |
| 1880 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1881 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1882 | unsigned int mask = (1 << fls(max)) - 1; |
| 1883 | unsigned int invert = mc->invert; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1884 | unsigned short val, val2, val_mask; |
| 1885 | |
| 1886 | val = (ucontrol->value.integer.value[0] & mask); |
| 1887 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1888 | val = max - val; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1889 | val_mask = mask << shift; |
| 1890 | val = val << shift; |
| 1891 | if (shift != rshift) { |
| 1892 | val2 = (ucontrol->value.integer.value[1] & mask); |
| 1893 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1894 | val2 = max - val2; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1895 | val_mask |= mask << rshift; |
| 1896 | val |= val2 << rshift; |
| 1897 | } |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1898 | return snd_soc_update_bits(codec, reg, val_mask, val); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1899 | } |
| 1900 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw); |
| 1901 | |
| 1902 | /** |
| 1903 | * snd_soc_info_volsw_2r - double mixer info callback |
| 1904 | * @kcontrol: mixer control |
| 1905 | * @uinfo: control element information |
| 1906 | * |
| 1907 | * Callback to provide information about a double mixer control that |
| 1908 | * spans 2 codec registers. |
| 1909 | * |
| 1910 | * Returns 0 for success. |
| 1911 | */ |
| 1912 | int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol, |
| 1913 | struct snd_ctl_elem_info *uinfo) |
| 1914 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1915 | struct soc_mixer_control *mc = |
| 1916 | (struct soc_mixer_control *)kcontrol->private_value; |
| 1917 | int max = mc->max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1918 | |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1919 | if (max == 1) |
| 1920 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 1921 | else |
| 1922 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1923 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1924 | uinfo->count = 2; |
| 1925 | uinfo->value.integer.min = 0; |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1926 | uinfo->value.integer.max = max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1927 | return 0; |
| 1928 | } |
| 1929 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r); |
| 1930 | |
| 1931 | /** |
| 1932 | * snd_soc_get_volsw_2r - double mixer get callback |
| 1933 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1934 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1935 | * |
| 1936 | * Callback to get the value of a double mixer control that spans 2 registers. |
| 1937 | * |
| 1938 | * Returns 0 for success. |
| 1939 | */ |
| 1940 | int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol, |
| 1941 | struct snd_ctl_elem_value *ucontrol) |
| 1942 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1943 | struct soc_mixer_control *mc = |
| 1944 | (struct soc_mixer_control *)kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1945 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1946 | unsigned int reg = mc->reg; |
| 1947 | unsigned int reg2 = mc->rreg; |
| 1948 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1949 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1950 | unsigned int mask = (1<<fls(max))-1; |
| 1951 | unsigned int invert = mc->invert; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1952 | |
| 1953 | ucontrol->value.integer.value[0] = |
| 1954 | (snd_soc_read(codec, reg) >> shift) & mask; |
| 1955 | ucontrol->value.integer.value[1] = |
| 1956 | (snd_soc_read(codec, reg2) >> shift) & mask; |
| 1957 | if (invert) { |
| 1958 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1959 | max - ucontrol->value.integer.value[0]; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1960 | ucontrol->value.integer.value[1] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1961 | max - ucontrol->value.integer.value[1]; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | return 0; |
| 1965 | } |
| 1966 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r); |
| 1967 | |
| 1968 | /** |
| 1969 | * snd_soc_put_volsw_2r - double mixer set callback |
| 1970 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1971 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1972 | * |
| 1973 | * Callback to set the value of a double mixer control that spans 2 registers. |
| 1974 | * |
| 1975 | * Returns 0 for success. |
| 1976 | */ |
| 1977 | int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol, |
| 1978 | struct snd_ctl_elem_value *ucontrol) |
| 1979 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1980 | struct soc_mixer_control *mc = |
| 1981 | (struct soc_mixer_control *)kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1982 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1983 | unsigned int reg = mc->reg; |
| 1984 | unsigned int reg2 = mc->rreg; |
| 1985 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1986 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1987 | unsigned int mask = (1 << fls(max)) - 1; |
| 1988 | unsigned int invert = mc->invert; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1989 | int err; |
| 1990 | unsigned short val, val2, val_mask; |
| 1991 | |
| 1992 | val_mask = mask << shift; |
| 1993 | val = (ucontrol->value.integer.value[0] & mask); |
| 1994 | val2 = (ucontrol->value.integer.value[1] & mask); |
| 1995 | |
| 1996 | if (invert) { |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1997 | val = max - val; |
| 1998 | val2 = max - val2; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | val = val << shift; |
| 2002 | val2 = val2 << shift; |
| 2003 | |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 2004 | err = snd_soc_update_bits(codec, reg, val_mask, val); |
| 2005 | if (err < 0) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2006 | return err; |
| 2007 | |
| 2008 | err = snd_soc_update_bits(codec, reg2, val_mask, val2); |
| 2009 | return err; |
| 2010 | } |
| 2011 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r); |
| 2012 | |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2013 | /** |
| 2014 | * snd_soc_info_volsw_s8 - signed mixer info callback |
| 2015 | * @kcontrol: mixer control |
| 2016 | * @uinfo: control element information |
| 2017 | * |
| 2018 | * Callback to provide information about a signed mixer control. |
| 2019 | * |
| 2020 | * Returns 0 for success. |
| 2021 | */ |
| 2022 | int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol, |
| 2023 | struct snd_ctl_elem_info *uinfo) |
| 2024 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2025 | struct soc_mixer_control *mc = |
| 2026 | (struct soc_mixer_control *)kcontrol->private_value; |
| 2027 | int max = mc->max; |
| 2028 | int min = mc->min; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2029 | |
| 2030 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2031 | uinfo->count = 2; |
| 2032 | uinfo->value.integer.min = 0; |
| 2033 | uinfo->value.integer.max = max-min; |
| 2034 | return 0; |
| 2035 | } |
| 2036 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8); |
| 2037 | |
| 2038 | /** |
| 2039 | * snd_soc_get_volsw_s8 - signed mixer get callback |
| 2040 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2041 | * @ucontrol: control element information |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2042 | * |
| 2043 | * Callback to get the value of a signed mixer control. |
| 2044 | * |
| 2045 | * Returns 0 for success. |
| 2046 | */ |
| 2047 | int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, |
| 2048 | struct snd_ctl_elem_value *ucontrol) |
| 2049 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2050 | struct soc_mixer_control *mc = |
| 2051 | (struct soc_mixer_control *)kcontrol->private_value; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2052 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2053 | unsigned int reg = mc->reg; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2054 | int min = mc->min; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2055 | int val = snd_soc_read(codec, reg); |
| 2056 | |
| 2057 | ucontrol->value.integer.value[0] = |
| 2058 | ((signed char)(val & 0xff))-min; |
| 2059 | ucontrol->value.integer.value[1] = |
| 2060 | ((signed char)((val >> 8) & 0xff))-min; |
| 2061 | return 0; |
| 2062 | } |
| 2063 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8); |
| 2064 | |
| 2065 | /** |
| 2066 | * snd_soc_put_volsw_sgn - signed mixer put callback |
| 2067 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2068 | * @ucontrol: control element information |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2069 | * |
| 2070 | * Callback to set the value of a signed mixer control. |
| 2071 | * |
| 2072 | * Returns 0 for success. |
| 2073 | */ |
| 2074 | int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, |
| 2075 | struct snd_ctl_elem_value *ucontrol) |
| 2076 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2077 | struct soc_mixer_control *mc = |
| 2078 | (struct soc_mixer_control *)kcontrol->private_value; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2079 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2080 | unsigned int reg = mc->reg; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2081 | int min = mc->min; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2082 | unsigned short val; |
| 2083 | |
| 2084 | val = (ucontrol->value.integer.value[0]+min) & 0xff; |
| 2085 | val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8; |
| 2086 | |
| 2087 | return snd_soc_update_bits(codec, reg, 0xffff, val); |
| 2088 | } |
| 2089 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8); |
| 2090 | |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2091 | /** |
| 2092 | * snd_soc_dai_set_sysclk - configure DAI system or master clock. |
| 2093 | * @dai: DAI |
| 2094 | * @clk_id: DAI specific clock ID |
| 2095 | * @freq: new clock frequency in Hz |
| 2096 | * @dir: new clock direction - input/output. |
| 2097 | * |
| 2098 | * Configures the DAI master (MCLK) or system (SYSCLK) clocking. |
| 2099 | */ |
| 2100 | int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, |
| 2101 | unsigned int freq, int dir) |
| 2102 | { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 2103 | if (dai->ops->set_sysclk) |
| 2104 | return dai->ops->set_sysclk(dai, clk_id, freq, dir); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2105 | else |
| 2106 | return -EINVAL; |
| 2107 | } |
| 2108 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); |
| 2109 | |
| 2110 | /** |
| 2111 | * snd_soc_dai_set_clkdiv - configure DAI clock dividers. |
| 2112 | * @dai: DAI |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2113 | * @div_id: DAI specific clock divider ID |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2114 | * @div: new clock divisor. |
| 2115 | * |
| 2116 | * Configures the clock dividers. This is used to derive the best DAI bit and |
| 2117 | * frame clocks from the system or master clock. It's best to set the DAI bit |
| 2118 | * and frame clocks as low as possible to save system power. |
| 2119 | */ |
| 2120 | int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, |
| 2121 | int div_id, int div) |
| 2122 | { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 2123 | if (dai->ops->set_clkdiv) |
| 2124 | return dai->ops->set_clkdiv(dai, div_id, div); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2125 | else |
| 2126 | return -EINVAL; |
| 2127 | } |
| 2128 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); |
| 2129 | |
| 2130 | /** |
| 2131 | * snd_soc_dai_set_pll - configure DAI PLL. |
| 2132 | * @dai: DAI |
| 2133 | * @pll_id: DAI specific PLL ID |
| 2134 | * @freq_in: PLL input clock frequency in Hz |
| 2135 | * @freq_out: requested PLL output clock frequency in Hz |
| 2136 | * |
| 2137 | * Configures and enables PLL to generate output clock based on input clock. |
| 2138 | */ |
| 2139 | int snd_soc_dai_set_pll(struct snd_soc_dai *dai, |
| 2140 | int pll_id, unsigned int freq_in, unsigned int freq_out) |
| 2141 | { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 2142 | if (dai->ops->set_pll) |
| 2143 | return dai->ops->set_pll(dai, pll_id, freq_in, freq_out); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2144 | else |
| 2145 | return -EINVAL; |
| 2146 | } |
| 2147 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); |
| 2148 | |
| 2149 | /** |
| 2150 | * snd_soc_dai_set_fmt - configure DAI hardware audio format. |
| 2151 | * @dai: DAI |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2152 | * @fmt: SND_SOC_DAIFMT_ format value. |
| 2153 | * |
| 2154 | * Configures the DAI hardware format and clocking. |
| 2155 | */ |
| 2156 | int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 2157 | { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 2158 | if (dai->ops->set_fmt) |
| 2159 | return dai->ops->set_fmt(dai, fmt); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2160 | else |
| 2161 | return -EINVAL; |
| 2162 | } |
| 2163 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt); |
| 2164 | |
| 2165 | /** |
| 2166 | * snd_soc_dai_set_tdm_slot - configure DAI TDM. |
| 2167 | * @dai: DAI |
| 2168 | * @mask: DAI specific mask representing used slots. |
| 2169 | * @slots: Number of slots in use. |
| 2170 | * |
| 2171 | * Configures a DAI for TDM operation. Both mask and slots are codec and DAI |
| 2172 | * specific. |
| 2173 | */ |
| 2174 | int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, |
| 2175 | unsigned int mask, int slots) |
| 2176 | { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 2177 | if (dai->ops->set_sysclk) |
| 2178 | return dai->ops->set_tdm_slot(dai, mask, slots); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2179 | else |
| 2180 | return -EINVAL; |
| 2181 | } |
| 2182 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); |
| 2183 | |
| 2184 | /** |
| 2185 | * snd_soc_dai_set_tristate - configure DAI system or master clock. |
| 2186 | * @dai: DAI |
| 2187 | * @tristate: tristate enable |
| 2188 | * |
| 2189 | * Tristates the DAI so that others can use it. |
| 2190 | */ |
| 2191 | int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) |
| 2192 | { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 2193 | if (dai->ops->set_sysclk) |
| 2194 | return dai->ops->set_tristate(dai, tristate); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2195 | else |
| 2196 | return -EINVAL; |
| 2197 | } |
| 2198 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate); |
| 2199 | |
| 2200 | /** |
| 2201 | * snd_soc_dai_digital_mute - configure DAI system or master clock. |
| 2202 | * @dai: DAI |
| 2203 | * @mute: mute enable |
| 2204 | * |
| 2205 | * Mutes the DAI DAC. |
| 2206 | */ |
| 2207 | int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute) |
| 2208 | { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 2209 | if (dai->ops->digital_mute) |
| 2210 | return dai->ops->digital_mute(dai, mute); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2211 | else |
| 2212 | return -EINVAL; |
| 2213 | } |
| 2214 | EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); |
| 2215 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2216 | /** |
| 2217 | * snd_soc_register_card - Register a card with the ASoC core |
| 2218 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2219 | * @card: Card to register |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2220 | * |
| 2221 | * Note that currently this is an internal only function: it will be |
| 2222 | * exposed to machine drivers after further backporting of ASoC v2 |
| 2223 | * registration APIs. |
| 2224 | */ |
| 2225 | static int snd_soc_register_card(struct snd_soc_card *card) |
| 2226 | { |
| 2227 | if (!card->name || !card->dev) |
| 2228 | return -EINVAL; |
| 2229 | |
| 2230 | INIT_LIST_HEAD(&card->list); |
| 2231 | card->instantiated = 0; |
| 2232 | |
| 2233 | mutex_lock(&client_mutex); |
| 2234 | list_add(&card->list, &card_list); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2235 | snd_soc_instantiate_cards(); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2236 | mutex_unlock(&client_mutex); |
| 2237 | |
| 2238 | dev_dbg(card->dev, "Registered card '%s'\n", card->name); |
| 2239 | |
| 2240 | return 0; |
| 2241 | } |
| 2242 | |
| 2243 | /** |
| 2244 | * snd_soc_unregister_card - Unregister a card with the ASoC core |
| 2245 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2246 | * @card: Card to unregister |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2247 | * |
| 2248 | * Note that currently this is an internal only function: it will be |
| 2249 | * exposed to machine drivers after further backporting of ASoC v2 |
| 2250 | * registration APIs. |
| 2251 | */ |
| 2252 | static int snd_soc_unregister_card(struct snd_soc_card *card) |
| 2253 | { |
| 2254 | mutex_lock(&client_mutex); |
| 2255 | list_del(&card->list); |
| 2256 | mutex_unlock(&client_mutex); |
| 2257 | |
| 2258 | dev_dbg(card->dev, "Unregistered card '%s'\n", card->name); |
| 2259 | |
| 2260 | return 0; |
| 2261 | } |
| 2262 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 2263 | static struct snd_soc_dai_ops null_dai_ops = { |
| 2264 | }; |
| 2265 | |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2266 | /** |
| 2267 | * snd_soc_register_dai - Register a DAI with the ASoC core |
| 2268 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2269 | * @dai: DAI to register |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2270 | */ |
| 2271 | int snd_soc_register_dai(struct snd_soc_dai *dai) |
| 2272 | { |
| 2273 | if (!dai->name) |
| 2274 | return -EINVAL; |
| 2275 | |
| 2276 | /* The device should become mandatory over time */ |
| 2277 | if (!dai->dev) |
| 2278 | printk(KERN_WARNING "No device for DAI %s\n", dai->name); |
| 2279 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 2280 | if (!dai->ops) |
| 2281 | dai->ops = &null_dai_ops; |
| 2282 | |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2283 | INIT_LIST_HEAD(&dai->list); |
| 2284 | |
| 2285 | mutex_lock(&client_mutex); |
| 2286 | list_add(&dai->list, &dai_list); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2287 | snd_soc_instantiate_cards(); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2288 | mutex_unlock(&client_mutex); |
| 2289 | |
| 2290 | pr_debug("Registered DAI '%s'\n", dai->name); |
| 2291 | |
| 2292 | return 0; |
| 2293 | } |
| 2294 | EXPORT_SYMBOL_GPL(snd_soc_register_dai); |
| 2295 | |
| 2296 | /** |
| 2297 | * snd_soc_unregister_dai - Unregister a DAI from the ASoC core |
| 2298 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2299 | * @dai: DAI to unregister |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2300 | */ |
| 2301 | void snd_soc_unregister_dai(struct snd_soc_dai *dai) |
| 2302 | { |
| 2303 | mutex_lock(&client_mutex); |
| 2304 | list_del(&dai->list); |
| 2305 | mutex_unlock(&client_mutex); |
| 2306 | |
| 2307 | pr_debug("Unregistered DAI '%s'\n", dai->name); |
| 2308 | } |
| 2309 | EXPORT_SYMBOL_GPL(snd_soc_unregister_dai); |
| 2310 | |
| 2311 | /** |
| 2312 | * snd_soc_register_dais - Register multiple DAIs with the ASoC core |
| 2313 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2314 | * @dai: Array of DAIs to register |
| 2315 | * @count: Number of DAIs |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2316 | */ |
| 2317 | int snd_soc_register_dais(struct snd_soc_dai *dai, size_t count) |
| 2318 | { |
| 2319 | int i, ret; |
| 2320 | |
| 2321 | for (i = 0; i < count; i++) { |
| 2322 | ret = snd_soc_register_dai(&dai[i]); |
| 2323 | if (ret != 0) |
| 2324 | goto err; |
| 2325 | } |
| 2326 | |
| 2327 | return 0; |
| 2328 | |
| 2329 | err: |
| 2330 | for (i--; i >= 0; i--) |
| 2331 | snd_soc_unregister_dai(&dai[i]); |
| 2332 | |
| 2333 | return ret; |
| 2334 | } |
| 2335 | EXPORT_SYMBOL_GPL(snd_soc_register_dais); |
| 2336 | |
| 2337 | /** |
| 2338 | * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core |
| 2339 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2340 | * @dai: Array of DAIs to unregister |
| 2341 | * @count: Number of DAIs |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2342 | */ |
| 2343 | void snd_soc_unregister_dais(struct snd_soc_dai *dai, size_t count) |
| 2344 | { |
| 2345 | int i; |
| 2346 | |
| 2347 | for (i = 0; i < count; i++) |
| 2348 | snd_soc_unregister_dai(&dai[i]); |
| 2349 | } |
| 2350 | EXPORT_SYMBOL_GPL(snd_soc_unregister_dais); |
| 2351 | |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2352 | /** |
| 2353 | * snd_soc_register_platform - Register a platform with the ASoC core |
| 2354 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2355 | * @platform: platform to register |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2356 | */ |
| 2357 | int snd_soc_register_platform(struct snd_soc_platform *platform) |
| 2358 | { |
| 2359 | if (!platform->name) |
| 2360 | return -EINVAL; |
| 2361 | |
| 2362 | INIT_LIST_HEAD(&platform->list); |
| 2363 | |
| 2364 | mutex_lock(&client_mutex); |
| 2365 | list_add(&platform->list, &platform_list); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2366 | snd_soc_instantiate_cards(); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2367 | mutex_unlock(&client_mutex); |
| 2368 | |
| 2369 | pr_debug("Registered platform '%s'\n", platform->name); |
| 2370 | |
| 2371 | return 0; |
| 2372 | } |
| 2373 | EXPORT_SYMBOL_GPL(snd_soc_register_platform); |
| 2374 | |
| 2375 | /** |
| 2376 | * snd_soc_unregister_platform - Unregister a platform from the ASoC core |
| 2377 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2378 | * @platform: platform to unregister |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2379 | */ |
| 2380 | void snd_soc_unregister_platform(struct snd_soc_platform *platform) |
| 2381 | { |
| 2382 | mutex_lock(&client_mutex); |
| 2383 | list_del(&platform->list); |
| 2384 | mutex_unlock(&client_mutex); |
| 2385 | |
| 2386 | pr_debug("Unregistered platform '%s'\n", platform->name); |
| 2387 | } |
| 2388 | EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); |
| 2389 | |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 2390 | /** |
| 2391 | * snd_soc_register_codec - Register a codec with the ASoC core |
| 2392 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2393 | * @codec: codec to register |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 2394 | */ |
| 2395 | int snd_soc_register_codec(struct snd_soc_codec *codec) |
| 2396 | { |
| 2397 | if (!codec->name) |
| 2398 | return -EINVAL; |
| 2399 | |
| 2400 | /* The device should become mandatory over time */ |
| 2401 | if (!codec->dev) |
| 2402 | printk(KERN_WARNING "No device for codec %s\n", codec->name); |
| 2403 | |
| 2404 | INIT_LIST_HEAD(&codec->list); |
| 2405 | |
| 2406 | mutex_lock(&client_mutex); |
| 2407 | list_add(&codec->list, &codec_list); |
| 2408 | snd_soc_instantiate_cards(); |
| 2409 | mutex_unlock(&client_mutex); |
| 2410 | |
| 2411 | pr_debug("Registered codec '%s'\n", codec->name); |
| 2412 | |
| 2413 | return 0; |
| 2414 | } |
| 2415 | EXPORT_SYMBOL_GPL(snd_soc_register_codec); |
| 2416 | |
| 2417 | /** |
| 2418 | * snd_soc_unregister_codec - Unregister a codec from the ASoC core |
| 2419 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2420 | * @codec: codec to unregister |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 2421 | */ |
| 2422 | void snd_soc_unregister_codec(struct snd_soc_codec *codec) |
| 2423 | { |
| 2424 | mutex_lock(&client_mutex); |
| 2425 | list_del(&codec->list); |
| 2426 | mutex_unlock(&client_mutex); |
| 2427 | |
| 2428 | pr_debug("Unregistered codec '%s'\n", codec->name); |
| 2429 | } |
| 2430 | EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); |
| 2431 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 2432 | static int __init snd_soc_init(void) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2433 | { |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 2434 | #ifdef CONFIG_DEBUG_FS |
| 2435 | debugfs_root = debugfs_create_dir("asoc", NULL); |
| 2436 | if (IS_ERR(debugfs_root) || !debugfs_root) { |
| 2437 | printk(KERN_WARNING |
| 2438 | "ASoC: Failed to create debugfs directory\n"); |
| 2439 | debugfs_root = NULL; |
| 2440 | } |
| 2441 | #endif |
| 2442 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2443 | return platform_driver_register(&soc_driver); |
| 2444 | } |
| 2445 | |
Mark Brown | 7d8c16a | 2008-11-30 22:11:24 +0000 | [diff] [blame] | 2446 | static void __exit snd_soc_exit(void) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2447 | { |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 2448 | #ifdef CONFIG_DEBUG_FS |
| 2449 | debugfs_remove_recursive(debugfs_root); |
| 2450 | #endif |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 2451 | platform_driver_unregister(&soc_driver); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2452 | } |
| 2453 | |
| 2454 | module_init(snd_soc_init); |
| 2455 | module_exit(snd_soc_exit); |
| 2456 | |
| 2457 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 2458 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2459 | MODULE_DESCRIPTION("ALSA SoC Core"); |
| 2460 | MODULE_LICENSE("GPL"); |
Kay Sievers | 8b45a20 | 2008-04-14 13:33:36 +0200 | [diff] [blame] | 2461 | MODULE_ALIAS("platform:soc-audio"); |