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