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