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