Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1 | /* |
| 2 | * soc-dapm.c -- ALSA SoC Dynamic Audio Power Management |
| 3 | * |
| 4 | * Copyright 2005 Wolfson Microelectronics PLC. |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 5 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | * |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 12 | * Features: |
| 13 | * o Changes power status of internal codec blocks depending on the |
| 14 | * dynamic configuration of codec internal audio paths and active |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 15 | * DACs/ADCs. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 16 | * o Platform power domain - can support external components i.e. amps and |
Liam Girdwood | 612a3fe | 2012-02-06 16:05:29 +0000 | [diff] [blame] | 17 | * mic/headphone insertion events. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 18 | * o Automatic Mic Bias support |
| 19 | * o Jack insertion power event initiation - e.g. hp insertion will enable |
| 20 | * sinks, dacs, etc |
Liam Girdwood | 612a3fe | 2012-02-06 16:05:29 +0000 | [diff] [blame] | 21 | * o Delayed power down of audio subsystem to reduce pops between a quick |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 22 | * device reopen. |
| 23 | * |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/moduleparam.h> |
| 28 | #include <linux/init.h> |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 29 | #include <linux/async.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 30 | #include <linux/delay.h> |
| 31 | #include <linux/pm.h> |
| 32 | #include <linux/bitops.h> |
| 33 | #include <linux/platform_device.h> |
| 34 | #include <linux/jiffies.h> |
Takashi Iwai | 20496ff | 2009-08-24 09:40:34 +0200 | [diff] [blame] | 35 | #include <linux/debugfs.h> |
Mark Brown | f1aac48 | 2011-12-05 15:17:06 +0000 | [diff] [blame] | 36 | #include <linux/pm_runtime.h> |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 37 | #include <linux/regulator/consumer.h> |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 38 | #include <linux/clk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 39 | #include <linux/slab.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 40 | #include <sound/core.h> |
| 41 | #include <sound/pcm.h> |
| 42 | #include <sound/pcm_params.h> |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 43 | #include <sound/soc.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 44 | #include <sound/initval.h> |
| 45 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 46 | #include <trace/events/asoc.h> |
| 47 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 48 | #define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++; |
| 49 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 50 | /* dapm power sequences - make this per codec in the future */ |
| 51 | static int dapm_up_seq[] = { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 52 | [snd_soc_dapm_pre] = 0, |
| 53 | [snd_soc_dapm_supply] = 1, |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 54 | [snd_soc_dapm_regulator_supply] = 1, |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 55 | [snd_soc_dapm_clock_supply] = 1, |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 56 | [snd_soc_dapm_micbias] = 2, |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 57 | [snd_soc_dapm_dai_link] = 2, |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 58 | [snd_soc_dapm_dai_in] = 3, |
| 59 | [snd_soc_dapm_dai_out] = 3, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 60 | [snd_soc_dapm_aif_in] = 3, |
| 61 | [snd_soc_dapm_aif_out] = 3, |
| 62 | [snd_soc_dapm_mic] = 4, |
| 63 | [snd_soc_dapm_mux] = 5, |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 64 | [snd_soc_dapm_virt_mux] = 5, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 65 | [snd_soc_dapm_value_mux] = 5, |
| 66 | [snd_soc_dapm_dac] = 6, |
Lars-Peter Clausen | efc77e3 | 2013-06-14 13:16:50 +0200 | [diff] [blame] | 67 | [snd_soc_dapm_switch] = 7, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 68 | [snd_soc_dapm_mixer] = 7, |
| 69 | [snd_soc_dapm_mixer_named_ctl] = 7, |
| 70 | [snd_soc_dapm_pga] = 8, |
| 71 | [snd_soc_dapm_adc] = 9, |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 72 | [snd_soc_dapm_out_drv] = 10, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 73 | [snd_soc_dapm_hp] = 10, |
| 74 | [snd_soc_dapm_spk] = 10, |
Mark Brown | 7e1f7c8 | 2012-04-12 17:29:36 +0100 | [diff] [blame] | 75 | [snd_soc_dapm_line] = 10, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 76 | [snd_soc_dapm_post] = 11, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 77 | }; |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 78 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 79 | static int dapm_down_seq[] = { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 80 | [snd_soc_dapm_pre] = 0, |
| 81 | [snd_soc_dapm_adc] = 1, |
| 82 | [snd_soc_dapm_hp] = 2, |
Mark Brown | 1ca0406 | 2009-08-17 16:26:59 +0100 | [diff] [blame] | 83 | [snd_soc_dapm_spk] = 2, |
Mark Brown | 7e1f7c8 | 2012-04-12 17:29:36 +0100 | [diff] [blame] | 84 | [snd_soc_dapm_line] = 2, |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 85 | [snd_soc_dapm_out_drv] = 2, |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 86 | [snd_soc_dapm_pga] = 4, |
Lars-Peter Clausen | efc77e3 | 2013-06-14 13:16:50 +0200 | [diff] [blame] | 87 | [snd_soc_dapm_switch] = 5, |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 88 | [snd_soc_dapm_mixer_named_ctl] = 5, |
Mark Brown | e3d4dab | 2009-06-07 13:08:45 +0100 | [diff] [blame] | 89 | [snd_soc_dapm_mixer] = 5, |
| 90 | [snd_soc_dapm_dac] = 6, |
| 91 | [snd_soc_dapm_mic] = 7, |
| 92 | [snd_soc_dapm_micbias] = 8, |
| 93 | [snd_soc_dapm_mux] = 9, |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 94 | [snd_soc_dapm_virt_mux] = 9, |
Mark Brown | e3d4dab | 2009-06-07 13:08:45 +0100 | [diff] [blame] | 95 | [snd_soc_dapm_value_mux] = 9, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 96 | [snd_soc_dapm_aif_in] = 10, |
| 97 | [snd_soc_dapm_aif_out] = 10, |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 98 | [snd_soc_dapm_dai_in] = 10, |
| 99 | [snd_soc_dapm_dai_out] = 10, |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 100 | [snd_soc_dapm_dai_link] = 11, |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 101 | [snd_soc_dapm_clock_supply] = 12, |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 102 | [snd_soc_dapm_regulator_supply] = 12, |
| 103 | [snd_soc_dapm_supply] = 12, |
| 104 | [snd_soc_dapm_post] = 13, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 105 | }; |
| 106 | |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 107 | static void pop_wait(u32 pop_time) |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 108 | { |
| 109 | if (pop_time) |
| 110 | schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time)); |
| 111 | } |
| 112 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 113 | static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...) |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 114 | { |
| 115 | va_list args; |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 116 | char *buf; |
| 117 | |
| 118 | if (!pop_time) |
| 119 | return; |
| 120 | |
| 121 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 122 | if (buf == NULL) |
| 123 | return; |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 124 | |
| 125 | va_start(args, fmt); |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 126 | vsnprintf(buf, PAGE_SIZE, fmt, args); |
Takashi Iwai | 9d01df0 | 2010-12-22 14:08:40 +0100 | [diff] [blame] | 127 | dev_info(dev, "%s", buf); |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 128 | va_end(args); |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 129 | |
| 130 | kfree(buf); |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 131 | } |
| 132 | |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 133 | static bool dapm_dirty_widget(struct snd_soc_dapm_widget *w) |
| 134 | { |
| 135 | return !list_empty(&w->dirty); |
| 136 | } |
| 137 | |
Mark Brown | 25c77c5 | 2011-10-08 13:36:03 +0100 | [diff] [blame] | 138 | void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason) |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 139 | { |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 140 | if (!dapm_dirty_widget(w)) { |
| 141 | dev_vdbg(w->dapm->dev, "Marking %s dirty due to %s\n", |
| 142 | w->name, reason); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 143 | list_add_tail(&w->dirty, &w->dapm->card->dapm_dirty); |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 144 | } |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 145 | } |
Mark Brown | 25c77c5 | 2011-10-08 13:36:03 +0100 | [diff] [blame] | 146 | EXPORT_SYMBOL_GPL(dapm_mark_dirty); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 147 | |
Mark Brown | e2d32ff | 2012-08-31 17:38:32 -0700 | [diff] [blame] | 148 | void dapm_mark_io_dirty(struct snd_soc_dapm_context *dapm) |
| 149 | { |
| 150 | struct snd_soc_card *card = dapm->card; |
| 151 | struct snd_soc_dapm_widget *w; |
| 152 | |
| 153 | mutex_lock(&card->dapm_mutex); |
| 154 | |
| 155 | list_for_each_entry(w, &card->widgets, list) { |
| 156 | switch (w->id) { |
| 157 | case snd_soc_dapm_input: |
| 158 | case snd_soc_dapm_output: |
| 159 | dapm_mark_dirty(w, "Rechecking inputs and outputs"); |
| 160 | break; |
| 161 | default: |
| 162 | break; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | mutex_unlock(&card->dapm_mutex); |
| 167 | } |
| 168 | EXPORT_SYMBOL_GPL(dapm_mark_io_dirty); |
| 169 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 170 | /* create a new dapm widget */ |
Takashi Iwai | 88cb429 | 2007-02-05 14:56:20 +0100 | [diff] [blame] | 171 | static inline struct snd_soc_dapm_widget *dapm_cnew_widget( |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 172 | const struct snd_soc_dapm_widget *_widget) |
| 173 | { |
Takashi Iwai | 88cb429 | 2007-02-05 14:56:20 +0100 | [diff] [blame] | 174 | return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 175 | } |
| 176 | |
Liam Girdwood | 4805608 | 2011-07-20 12:23:33 +0100 | [diff] [blame] | 177 | /* get snd_card from DAPM context */ |
| 178 | static inline struct snd_card *dapm_get_snd_card( |
| 179 | struct snd_soc_dapm_context *dapm) |
| 180 | { |
| 181 | if (dapm->codec) |
| 182 | return dapm->codec->card->snd_card; |
| 183 | else if (dapm->platform) |
| 184 | return dapm->platform->card->snd_card; |
| 185 | else |
| 186 | BUG(); |
| 187 | |
| 188 | /* unreachable */ |
| 189 | return NULL; |
| 190 | } |
| 191 | |
| 192 | /* get soc_card from DAPM context */ |
| 193 | static inline struct snd_soc_card *dapm_get_soc_card( |
| 194 | struct snd_soc_dapm_context *dapm) |
| 195 | { |
| 196 | if (dapm->codec) |
| 197 | return dapm->codec->card; |
| 198 | else if (dapm->platform) |
| 199 | return dapm->platform->card; |
| 200 | else |
| 201 | BUG(); |
| 202 | |
| 203 | /* unreachable */ |
| 204 | return NULL; |
| 205 | } |
| 206 | |
Liam Girdwood | 6c120e1 | 2012-02-15 15:15:34 +0000 | [diff] [blame] | 207 | static void dapm_reset(struct snd_soc_card *card) |
| 208 | { |
| 209 | struct snd_soc_dapm_widget *w; |
| 210 | |
| 211 | memset(&card->dapm_stats, 0, sizeof(card->dapm_stats)); |
| 212 | |
| 213 | list_for_each_entry(w, &card->widgets, list) { |
| 214 | w->power_checked = false; |
| 215 | w->inputs = -1; |
| 216 | w->outputs = -1; |
| 217 | } |
| 218 | } |
| 219 | |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 220 | static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg) |
| 221 | { |
| 222 | if (w->codec) |
| 223 | return snd_soc_read(w->codec, reg); |
Liam Girdwood | b795064 | 2011-07-04 22:10:52 +0100 | [diff] [blame] | 224 | else if (w->platform) |
| 225 | return snd_soc_platform_read(w->platform, reg); |
| 226 | |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 227 | dev_err(w->dapm->dev, "ASoC: no valid widget read method\n"); |
Liam Girdwood | b795064 | 2011-07-04 22:10:52 +0100 | [diff] [blame] | 228 | return -1; |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg, int val) |
| 232 | { |
| 233 | if (w->codec) |
| 234 | return snd_soc_write(w->codec, reg, val); |
Liam Girdwood | b795064 | 2011-07-04 22:10:52 +0100 | [diff] [blame] | 235 | else if (w->platform) |
| 236 | return snd_soc_platform_write(w->platform, reg, val); |
| 237 | |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 238 | dev_err(w->dapm->dev, "ASoC: no valid widget write method\n"); |
Liam Girdwood | b795064 | 2011-07-04 22:10:52 +0100 | [diff] [blame] | 239 | return -1; |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 240 | } |
| 241 | |
Liam Girdwood | 49575fb5 | 2012-03-06 18:16:19 +0000 | [diff] [blame] | 242 | static inline void soc_widget_lock(struct snd_soc_dapm_widget *w) |
| 243 | { |
Mark Brown | e06ab3b | 2012-03-06 23:58:22 +0000 | [diff] [blame] | 244 | if (w->codec && !w->codec->using_regmap) |
Liam Girdwood | 49575fb5 | 2012-03-06 18:16:19 +0000 | [diff] [blame] | 245 | mutex_lock(&w->codec->mutex); |
| 246 | else if (w->platform) |
| 247 | mutex_lock(&w->platform->mutex); |
| 248 | } |
| 249 | |
| 250 | static inline void soc_widget_unlock(struct snd_soc_dapm_widget *w) |
| 251 | { |
Mark Brown | e06ab3b | 2012-03-06 23:58:22 +0000 | [diff] [blame] | 252 | if (w->codec && !w->codec->using_regmap) |
Liam Girdwood | 49575fb5 | 2012-03-06 18:16:19 +0000 | [diff] [blame] | 253 | mutex_unlock(&w->codec->mutex); |
| 254 | else if (w->platform) |
| 255 | mutex_unlock(&w->platform->mutex); |
| 256 | } |
| 257 | |
| 258 | static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget *w, |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 259 | unsigned short reg, unsigned int mask, unsigned int value) |
| 260 | { |
Mark Brown | 8a713da | 2011-12-03 12:33:55 +0000 | [diff] [blame] | 261 | bool change; |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 262 | unsigned int old, new; |
| 263 | int ret; |
| 264 | |
Mark Brown | 8a713da | 2011-12-03 12:33:55 +0000 | [diff] [blame] | 265 | if (w->codec && w->codec->using_regmap) { |
| 266 | ret = regmap_update_bits_check(w->codec->control_data, |
| 267 | reg, mask, value, &change); |
| 268 | if (ret != 0) |
| 269 | return ret; |
| 270 | } else { |
Liam Girdwood | 49575fb5 | 2012-03-06 18:16:19 +0000 | [diff] [blame] | 271 | soc_widget_lock(w); |
Mark Brown | 8a713da | 2011-12-03 12:33:55 +0000 | [diff] [blame] | 272 | ret = soc_widget_read(w, reg); |
Liam Girdwood | 49575fb5 | 2012-03-06 18:16:19 +0000 | [diff] [blame] | 273 | if (ret < 0) { |
| 274 | soc_widget_unlock(w); |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 275 | return ret; |
Liam Girdwood | 49575fb5 | 2012-03-06 18:16:19 +0000 | [diff] [blame] | 276 | } |
Mark Brown | 8a713da | 2011-12-03 12:33:55 +0000 | [diff] [blame] | 277 | |
| 278 | old = ret; |
| 279 | new = (old & ~mask) | (value & mask); |
| 280 | change = old != new; |
| 281 | if (change) { |
| 282 | ret = soc_widget_write(w, reg, new); |
Liam Girdwood | 49575fb5 | 2012-03-06 18:16:19 +0000 | [diff] [blame] | 283 | if (ret < 0) { |
| 284 | soc_widget_unlock(w); |
Mark Brown | 8a713da | 2011-12-03 12:33:55 +0000 | [diff] [blame] | 285 | return ret; |
Liam Girdwood | 49575fb5 | 2012-03-06 18:16:19 +0000 | [diff] [blame] | 286 | } |
Mark Brown | 8a713da | 2011-12-03 12:33:55 +0000 | [diff] [blame] | 287 | } |
Liam Girdwood | 49575fb5 | 2012-03-06 18:16:19 +0000 | [diff] [blame] | 288 | soc_widget_unlock(w); |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | return change; |
| 292 | } |
| 293 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 294 | /** |
| 295 | * snd_soc_dapm_set_bias_level - set the bias level for the system |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 296 | * @dapm: DAPM context |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 297 | * @level: level to configure |
| 298 | * |
| 299 | * Configure the bias (power) levels for the SoC audio device. |
| 300 | * |
| 301 | * Returns 0 for success else error. |
| 302 | */ |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 303 | static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm, |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 304 | enum snd_soc_bias_level level) |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 305 | { |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 306 | struct snd_soc_card *card = dapm->card; |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 307 | int ret = 0; |
| 308 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 309 | trace_snd_soc_bias_level_start(card, level); |
| 310 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 311 | if (card && card->set_bias_level) |
Mark Brown | d4c6005 | 2011-06-06 19:13:23 +0100 | [diff] [blame] | 312 | ret = card->set_bias_level(card, dapm, level); |
Mark Brown | 171ec6b | 2011-06-06 18:15:19 +0100 | [diff] [blame] | 313 | if (ret != 0) |
| 314 | goto out; |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 315 | |
Mark Brown | cc4c670 | 2011-06-06 19:03:34 +0100 | [diff] [blame] | 316 | if (dapm->codec) { |
| 317 | if (dapm->codec->driver->set_bias_level) |
| 318 | ret = dapm->codec->driver->set_bias_level(dapm->codec, |
| 319 | level); |
Mark Brown | d8c3bb9 | 2012-08-23 18:10:42 +0100 | [diff] [blame] | 320 | else |
| 321 | dapm->bias_level = level; |
Mark Brown | 4e872a4 | 2012-08-23 18:20:49 +0100 | [diff] [blame] | 322 | } else if (!card || dapm != &card->dapm) { |
Liam Girdwood | 4123128 | 2012-07-06 16:56:16 +0100 | [diff] [blame] | 323 | dapm->bias_level = level; |
Mark Brown | 4e872a4 | 2012-08-23 18:20:49 +0100 | [diff] [blame] | 324 | } |
Liam Girdwood | 4123128 | 2012-07-06 16:56:16 +0100 | [diff] [blame] | 325 | |
Mark Brown | 171ec6b | 2011-06-06 18:15:19 +0100 | [diff] [blame] | 326 | if (ret != 0) |
| 327 | goto out; |
| 328 | |
| 329 | if (card && card->set_bias_level_post) |
Mark Brown | d4c6005 | 2011-06-06 19:13:23 +0100 | [diff] [blame] | 330 | ret = card->set_bias_level_post(card, dapm, level); |
Mark Brown | 171ec6b | 2011-06-06 18:15:19 +0100 | [diff] [blame] | 331 | out: |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 332 | trace_snd_soc_bias_level_done(card, level); |
| 333 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 334 | return ret; |
| 335 | } |
| 336 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 337 | /* set up initial codec paths */ |
| 338 | static void dapm_set_path_status(struct snd_soc_dapm_widget *w, |
| 339 | struct snd_soc_dapm_path *p, int i) |
| 340 | { |
| 341 | switch (w->id) { |
| 342 | case snd_soc_dapm_switch: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 343 | case snd_soc_dapm_mixer: |
| 344 | case snd_soc_dapm_mixer_named_ctl: { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 345 | int val; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 346 | struct soc_mixer_control *mc = (struct soc_mixer_control *) |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 347 | w->kcontrol_news[i].private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 348 | unsigned int reg = mc->reg; |
| 349 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 350 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 351 | unsigned int mask = (1 << fls(max)) - 1; |
| 352 | unsigned int invert = mc->invert; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 353 | |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 354 | val = soc_widget_read(w, reg); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 355 | val = (val >> shift) & mask; |
Benoît Thébaudeau | 32fee7a | 2012-07-02 13:45:21 +0200 | [diff] [blame] | 356 | if (invert) |
| 357 | val = max - val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 358 | |
Benoît Thébaudeau | 32fee7a | 2012-07-02 13:45:21 +0200 | [diff] [blame] | 359 | p->connect = !!val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 360 | } |
| 361 | break; |
| 362 | case snd_soc_dapm_mux: { |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 363 | struct soc_enum *e = (struct soc_enum *) |
| 364 | w->kcontrol_news[i].private_value; |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 365 | int val, item; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 366 | |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 367 | val = soc_widget_read(w, e->reg); |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 368 | item = (val >> e->shift_l) & e->mask; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 369 | |
Lars-Peter Clausen | 58fee77 | 2013-06-14 13:16:52 +0200 | [diff] [blame] | 370 | if (item < e->max && !strcmp(p->name, e->texts[item])) |
| 371 | p->connect = 1; |
| 372 | else |
| 373 | p->connect = 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 374 | } |
| 375 | break; |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 376 | case snd_soc_dapm_virt_mux: { |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 377 | struct soc_enum *e = (struct soc_enum *) |
| 378 | w->kcontrol_news[i].private_value; |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 379 | |
| 380 | p->connect = 0; |
| 381 | /* since a virtual mux has no backing registers to |
| 382 | * decide which path to connect, it will try to match |
| 383 | * with the first enumeration. This is to ensure |
| 384 | * that the default mux choice (the first) will be |
| 385 | * correctly powered up during initialization. |
| 386 | */ |
| 387 | if (!strcmp(p->name, e->texts[0])) |
| 388 | p->connect = 1; |
| 389 | } |
| 390 | break; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 391 | case snd_soc_dapm_value_mux: { |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 392 | struct soc_enum *e = (struct soc_enum *) |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 393 | w->kcontrol_news[i].private_value; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 394 | int val, item; |
| 395 | |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 396 | val = soc_widget_read(w, e->reg); |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 397 | val = (val >> e->shift_l) & e->mask; |
| 398 | for (item = 0; item < e->max; item++) { |
| 399 | if (val == e->values[item]) |
| 400 | break; |
| 401 | } |
| 402 | |
Lars-Peter Clausen | 58fee77 | 2013-06-14 13:16:52 +0200 | [diff] [blame] | 403 | if (item < e->max && !strcmp(p->name, e->texts[item])) |
| 404 | p->connect = 1; |
| 405 | else |
| 406 | p->connect = 0; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 407 | } |
| 408 | break; |
Mark Brown | 5656310 | 2011-10-03 22:41:09 +0100 | [diff] [blame] | 409 | /* does not affect routing - always connected */ |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 410 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 411 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 412 | case snd_soc_dapm_output: |
| 413 | case snd_soc_dapm_adc: |
| 414 | case snd_soc_dapm_input: |
Mark Brown | 1ab97c8 | 2011-11-27 16:21:51 +0000 | [diff] [blame] | 415 | case snd_soc_dapm_siggen: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 416 | case snd_soc_dapm_dac: |
| 417 | case snd_soc_dapm_micbias: |
| 418 | case snd_soc_dapm_vmid: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 419 | case snd_soc_dapm_supply: |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 420 | case snd_soc_dapm_regulator_supply: |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 421 | case snd_soc_dapm_clock_supply: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 422 | case snd_soc_dapm_aif_in: |
| 423 | case snd_soc_dapm_aif_out: |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 424 | case snd_soc_dapm_dai_in: |
| 425 | case snd_soc_dapm_dai_out: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 426 | case snd_soc_dapm_hp: |
| 427 | case snd_soc_dapm_mic: |
| 428 | case snd_soc_dapm_spk: |
| 429 | case snd_soc_dapm_line: |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 430 | case snd_soc_dapm_dai_link: |
Mark Brown | 5656310 | 2011-10-03 22:41:09 +0100 | [diff] [blame] | 431 | p->connect = 1; |
| 432 | break; |
| 433 | /* does affect routing - dynamically connected */ |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 434 | case snd_soc_dapm_pre: |
| 435 | case snd_soc_dapm_post: |
| 436 | p->connect = 0; |
| 437 | break; |
| 438 | } |
| 439 | } |
| 440 | |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 441 | /* connect mux widget to its interconnecting audio paths */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 442 | static int dapm_connect_mux(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 443 | struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, |
| 444 | struct snd_soc_dapm_path *path, const char *control_name, |
| 445 | const struct snd_kcontrol_new *kcontrol) |
| 446 | { |
| 447 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 448 | int i; |
| 449 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 450 | for (i = 0; i < e->max; i++) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 451 | if (!(strcmp(control_name, e->texts[i]))) { |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 452 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 453 | list_add(&path->list_sink, &dest->sources); |
| 454 | list_add(&path->list_source, &src->sinks); |
| 455 | path->name = (char*)e->texts[i]; |
| 456 | dapm_set_path_status(dest, path, 0); |
| 457 | return 0; |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | return -ENODEV; |
| 462 | } |
| 463 | |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 464 | /* connect mixer widget to its interconnecting audio paths */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 465 | static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 466 | struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, |
| 467 | struct snd_soc_dapm_path *path, const char *control_name) |
| 468 | { |
| 469 | int i; |
| 470 | |
| 471 | /* search for mixer kcontrol */ |
| 472 | for (i = 0; i < dest->num_kcontrols; i++) { |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 473 | if (!strcmp(control_name, dest->kcontrol_news[i].name)) { |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 474 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 475 | list_add(&path->list_sink, &dest->sources); |
| 476 | list_add(&path->list_source, &src->sinks); |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 477 | path->name = dest->kcontrol_news[i].name; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 478 | dapm_set_path_status(dest, path, i); |
| 479 | return 0; |
| 480 | } |
| 481 | } |
| 482 | return -ENODEV; |
| 483 | } |
| 484 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 485 | static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context *dapm, |
Stephen Warren | 1007da0 | 2011-05-26 09:57:33 -0600 | [diff] [blame] | 486 | struct snd_soc_dapm_widget *kcontrolw, |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 487 | const struct snd_kcontrol_new *kcontrol_new, |
| 488 | struct snd_kcontrol **kcontrol) |
| 489 | { |
| 490 | struct snd_soc_dapm_widget *w; |
| 491 | int i; |
| 492 | |
| 493 | *kcontrol = NULL; |
| 494 | |
| 495 | list_for_each_entry(w, &dapm->card->widgets, list) { |
Stephen Warren | 1007da0 | 2011-05-26 09:57:33 -0600 | [diff] [blame] | 496 | if (w == kcontrolw || w->dapm != kcontrolw->dapm) |
| 497 | continue; |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 498 | for (i = 0; i < w->num_kcontrols; i++) { |
| 499 | if (&w->kcontrol_news[i] == kcontrol_new) { |
| 500 | if (w->kcontrols) |
| 501 | *kcontrol = w->kcontrols[i]; |
| 502 | return 1; |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | return 0; |
| 508 | } |
| 509 | |
Lars-Peter Clausen | 6b75bf0 | 2013-06-14 13:16:51 +0200 | [diff] [blame] | 510 | static void dapm_kcontrol_free(struct snd_kcontrol *kctl) |
| 511 | { |
| 512 | kfree(kctl->private_data); |
| 513 | } |
| 514 | |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 515 | /* |
| 516 | * Determine if a kcontrol is shared. If it is, look it up. If it isn't, |
| 517 | * create it. Either way, add the widget into the control's widget list |
| 518 | */ |
| 519 | static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget *w, |
| 520 | int kci, struct snd_soc_dapm_path *path) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 521 | { |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 522 | struct snd_soc_dapm_context *dapm = w->dapm; |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 523 | struct snd_card *card = dapm->card->snd_card; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 524 | const char *prefix; |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 525 | size_t prefix_len; |
| 526 | int shared; |
| 527 | struct snd_kcontrol *kcontrol; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 528 | struct snd_soc_dapm_widget_list *wlist; |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 529 | int wlistentries; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 530 | size_t wlistsize; |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 531 | bool wname_in_long_name, kcname_in_long_name; |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 532 | char *long_name; |
| 533 | const char *name; |
| 534 | int ret; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 535 | |
| 536 | if (dapm->codec) |
| 537 | prefix = dapm->codec->name_prefix; |
| 538 | else |
| 539 | prefix = NULL; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 540 | |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 541 | if (prefix) |
| 542 | prefix_len = strlen(prefix) + 1; |
| 543 | else |
| 544 | prefix_len = 0; |
| 545 | |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 546 | shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[kci], |
| 547 | &kcontrol); |
| 548 | |
| 549 | if (kcontrol) { |
| 550 | wlist = kcontrol->private_data; |
| 551 | wlistentries = wlist->num_widgets + 1; |
| 552 | } else { |
| 553 | wlist = NULL; |
| 554 | wlistentries = 1; |
| 555 | } |
| 556 | |
| 557 | wlistsize = sizeof(struct snd_soc_dapm_widget_list) + |
| 558 | wlistentries * sizeof(struct snd_soc_dapm_widget *); |
| 559 | wlist = krealloc(wlist, wlistsize, GFP_KERNEL); |
| 560 | if (wlist == NULL) { |
| 561 | dev_err(dapm->dev, "ASoC: can't allocate widget list for %s\n", |
| 562 | w->name); |
| 563 | return -ENOMEM; |
| 564 | } |
| 565 | wlist->num_widgets = wlistentries; |
| 566 | wlist->widgets[wlistentries - 1] = w; |
| 567 | |
| 568 | if (!kcontrol) { |
| 569 | if (shared) { |
| 570 | wname_in_long_name = false; |
| 571 | kcname_in_long_name = true; |
| 572 | } else { |
| 573 | switch (w->id) { |
| 574 | case snd_soc_dapm_switch: |
| 575 | case snd_soc_dapm_mixer: |
| 576 | wname_in_long_name = true; |
| 577 | kcname_in_long_name = true; |
| 578 | break; |
| 579 | case snd_soc_dapm_mixer_named_ctl: |
| 580 | wname_in_long_name = false; |
| 581 | kcname_in_long_name = true; |
| 582 | break; |
| 583 | case snd_soc_dapm_mux: |
| 584 | case snd_soc_dapm_virt_mux: |
| 585 | case snd_soc_dapm_value_mux: |
| 586 | wname_in_long_name = true; |
| 587 | kcname_in_long_name = false; |
| 588 | break; |
| 589 | default: |
| 590 | kfree(wlist); |
| 591 | return -EINVAL; |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | if (wname_in_long_name && kcname_in_long_name) { |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 596 | /* |
| 597 | * The control will get a prefix from the control |
| 598 | * creation process but we're also using the same |
| 599 | * prefix for widgets so cut the prefix off the |
| 600 | * front of the widget name. |
| 601 | */ |
Lars-Peter Clausen | 2b58107 | 2013-05-14 11:05:32 +0200 | [diff] [blame] | 602 | long_name = kasprintf(GFP_KERNEL, "%s %s", |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 603 | w->name + prefix_len, |
| 604 | w->kcontrol_news[kci].name); |
Lars-Peter Clausen | 2b58107 | 2013-05-14 11:05:32 +0200 | [diff] [blame] | 605 | if (long_name == NULL) { |
| 606 | kfree(wlist); |
| 607 | return -ENOMEM; |
| 608 | } |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 609 | |
| 610 | name = long_name; |
| 611 | } else if (wname_in_long_name) { |
| 612 | long_name = NULL; |
| 613 | name = w->name + prefix_len; |
| 614 | } else { |
| 615 | long_name = NULL; |
| 616 | name = w->kcontrol_news[kci].name; |
| 617 | } |
| 618 | |
| 619 | kcontrol = snd_soc_cnew(&w->kcontrol_news[kci], wlist, name, |
| 620 | prefix); |
Lars-Peter Clausen | 6b75bf0 | 2013-06-14 13:16:51 +0200 | [diff] [blame] | 621 | kcontrol->private_free = dapm_kcontrol_free; |
Lars-Peter Clausen | 656ca9d | 2013-06-14 13:16:54 +0200 | [diff] [blame] | 622 | kfree(long_name); |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 623 | ret = snd_ctl_add(card, kcontrol); |
| 624 | if (ret < 0) { |
| 625 | dev_err(dapm->dev, |
| 626 | "ASoC: failed to add widget %s dapm kcontrol %s: %d\n", |
| 627 | w->name, name, ret); |
| 628 | kfree(wlist); |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 629 | return ret; |
| 630 | } |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | kcontrol->private_data = wlist; |
| 634 | w->kcontrols[kci] = kcontrol; |
| 635 | path->kcontrol = kcontrol; |
| 636 | |
| 637 | return 0; |
| 638 | } |
| 639 | |
| 640 | /* create new dapm mixer control */ |
| 641 | static int dapm_new_mixer(struct snd_soc_dapm_widget *w) |
| 642 | { |
| 643 | int i, ret; |
| 644 | struct snd_soc_dapm_path *path; |
| 645 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 646 | /* add kcontrol */ |
| 647 | for (i = 0; i < w->num_kcontrols; i++) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 648 | /* match name */ |
| 649 | list_for_each_entry(path, &w->sources, list_sink) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 650 | /* mixer/mux paths name must match control name */ |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 651 | if (path->name != (char *)w->kcontrol_news[i].name) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 652 | continue; |
| 653 | |
Lars-Peter Clausen | 82cd876 | 2011-08-15 20:15:21 +0200 | [diff] [blame] | 654 | if (w->kcontrols[i]) { |
| 655 | path->kcontrol = w->kcontrols[i]; |
| 656 | continue; |
| 657 | } |
| 658 | |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 659 | ret = dapm_create_or_share_mixmux_kcontrol(w, i, path); |
| 660 | if (ret < 0) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 661 | return ret; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 662 | } |
| 663 | } |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 664 | |
| 665 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | /* create new dapm mux control */ |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 669 | static int dapm_new_mux(struct snd_soc_dapm_widget *w) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 670 | { |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 671 | struct snd_soc_dapm_context *dapm = w->dapm; |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 672 | struct snd_soc_dapm_path *path; |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 673 | int ret; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 674 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 675 | if (w->num_kcontrols != 1) { |
| 676 | dev_err(dapm->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 677 | "ASoC: mux %s has incorrect number of controls\n", |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 678 | w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 679 | return -EINVAL; |
| 680 | } |
| 681 | |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 682 | path = list_first_entry(&w->sources, struct snd_soc_dapm_path, |
| 683 | list_sink); |
| 684 | if (!path) { |
| 685 | dev_err(dapm->dev, "ASoC: mux %s has no paths\n", w->name); |
| 686 | return -EINVAL; |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 687 | } |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 688 | |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 689 | ret = dapm_create_or_share_mixmux_kcontrol(w, 0, path); |
| 690 | if (ret < 0) |
| 691 | return ret; |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 692 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 693 | list_for_each_entry(path, &w->sources, list_sink) |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 694 | path->kcontrol = w->kcontrols[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 695 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 696 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /* create new dapm volume control */ |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 700 | static int dapm_new_pga(struct snd_soc_dapm_widget *w) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 701 | { |
Mark Brown | a6c6573 | 2010-03-03 17:45:21 +0000 | [diff] [blame] | 702 | if (w->num_kcontrols) |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 703 | dev_err(w->dapm->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 704 | "ASoC: PGA controls not supported: '%s'\n", w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 705 | |
Mark Brown | a6c6573 | 2010-03-03 17:45:21 +0000 | [diff] [blame] | 706 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | /* reset 'walked' bit for each dapm path */ |
Ryo Tsutsui | 1059ecf | 2013-04-01 12:50:01 +0100 | [diff] [blame] | 710 | static void dapm_clear_walk_output(struct snd_soc_dapm_context *dapm, |
| 711 | struct list_head *sink) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 712 | { |
| 713 | struct snd_soc_dapm_path *p; |
| 714 | |
Ryo Tsutsui | 1059ecf | 2013-04-01 12:50:01 +0100 | [diff] [blame] | 715 | list_for_each_entry(p, sink, list_source) { |
| 716 | if (p->walked) { |
| 717 | p->walked = 0; |
| 718 | dapm_clear_walk_output(dapm, &p->sink->sinks); |
| 719 | } |
| 720 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 721 | } |
| 722 | |
Ryo Tsutsui | 1059ecf | 2013-04-01 12:50:01 +0100 | [diff] [blame] | 723 | static void dapm_clear_walk_input(struct snd_soc_dapm_context *dapm, |
| 724 | struct list_head *source) |
| 725 | { |
| 726 | struct snd_soc_dapm_path *p; |
| 727 | |
| 728 | list_for_each_entry(p, source, list_sink) { |
| 729 | if (p->walked) { |
| 730 | p->walked = 0; |
| 731 | dapm_clear_walk_input(dapm, &p->source->sources); |
| 732 | } |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 737 | /* We implement power down on suspend by checking the power state of |
| 738 | * the ALSA card - when we are suspending the ALSA state for the card |
| 739 | * is set to D3. |
| 740 | */ |
| 741 | static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget) |
| 742 | { |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 743 | int level = snd_power_get_state(widget->dapm->card->snd_card); |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 744 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 745 | switch (level) { |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 746 | case SNDRV_CTL_POWER_D3hot: |
| 747 | case SNDRV_CTL_POWER_D3cold: |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 748 | if (widget->ignore_suspend) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 749 | dev_dbg(widget->dapm->dev, "ASoC: %s ignoring suspend\n", |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 750 | widget->name); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 751 | return widget->ignore_suspend; |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 752 | default: |
| 753 | return 1; |
| 754 | } |
| 755 | } |
| 756 | |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 757 | /* add widget to list if it's not already in the list */ |
| 758 | static int dapm_list_add_widget(struct snd_soc_dapm_widget_list **list, |
| 759 | struct snd_soc_dapm_widget *w) |
| 760 | { |
| 761 | struct snd_soc_dapm_widget_list *wlist; |
| 762 | int wlistsize, wlistentries, i; |
| 763 | |
| 764 | if (*list == NULL) |
| 765 | return -EINVAL; |
| 766 | |
| 767 | wlist = *list; |
| 768 | |
| 769 | /* is this widget already in the list */ |
| 770 | for (i = 0; i < wlist->num_widgets; i++) { |
| 771 | if (wlist->widgets[i] == w) |
| 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | /* allocate some new space */ |
| 776 | wlistentries = wlist->num_widgets + 1; |
| 777 | wlistsize = sizeof(struct snd_soc_dapm_widget_list) + |
| 778 | wlistentries * sizeof(struct snd_soc_dapm_widget *); |
| 779 | *list = krealloc(wlist, wlistsize, GFP_KERNEL); |
| 780 | if (*list == NULL) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 781 | dev_err(w->dapm->dev, "ASoC: can't allocate widget list for %s\n", |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 782 | w->name); |
| 783 | return -ENOMEM; |
| 784 | } |
| 785 | wlist = *list; |
| 786 | |
| 787 | /* insert the widget */ |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 788 | dev_dbg(w->dapm->dev, "ASoC: added %s in widget list pos %d\n", |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 789 | w->name, wlist->num_widgets); |
| 790 | |
| 791 | wlist->widgets[wlist->num_widgets] = w; |
| 792 | wlist->num_widgets++; |
| 793 | return 1; |
| 794 | } |
| 795 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 796 | /* |
| 797 | * Recursively check for a completed path to an active or physically connected |
| 798 | * output widget. Returns number of complete paths. |
| 799 | */ |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 800 | static int is_connected_output_ep(struct snd_soc_dapm_widget *widget, |
| 801 | struct snd_soc_dapm_widget_list **list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 802 | { |
| 803 | struct snd_soc_dapm_path *path; |
| 804 | int con = 0; |
| 805 | |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 806 | if (widget->outputs >= 0) |
| 807 | return widget->outputs; |
| 808 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 809 | DAPM_UPDATE_STAT(widget, path_checks); |
| 810 | |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 811 | switch (widget->id) { |
| 812 | case snd_soc_dapm_supply: |
| 813 | case snd_soc_dapm_regulator_supply: |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 814 | case snd_soc_dapm_clock_supply: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 815 | return 0; |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 816 | default: |
| 817 | break; |
| 818 | } |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 819 | |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 820 | switch (widget->id) { |
| 821 | case snd_soc_dapm_adc: |
| 822 | case snd_soc_dapm_aif_out: |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 823 | case snd_soc_dapm_dai_out: |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 824 | if (widget->active) { |
| 825 | widget->outputs = snd_soc_dapm_suspend_check(widget); |
| 826 | return widget->outputs; |
| 827 | } |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 828 | default: |
| 829 | break; |
| 830 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 831 | |
| 832 | if (widget->connected) { |
| 833 | /* connected pin ? */ |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 834 | if (widget->id == snd_soc_dapm_output && !widget->ext) { |
| 835 | widget->outputs = snd_soc_dapm_suspend_check(widget); |
| 836 | return widget->outputs; |
| 837 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 838 | |
| 839 | /* connected jack or spk ? */ |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 840 | if (widget->id == snd_soc_dapm_hp || |
| 841 | widget->id == snd_soc_dapm_spk || |
| 842 | (widget->id == snd_soc_dapm_line && |
| 843 | !list_empty(&widget->sources))) { |
| 844 | widget->outputs = snd_soc_dapm_suspend_check(widget); |
| 845 | return widget->outputs; |
| 846 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | list_for_each_entry(path, &widget->sinks, list_source) { |
Mark Brown | e56235e | 2011-09-21 18:19:14 +0100 | [diff] [blame] | 850 | DAPM_UPDATE_STAT(widget, neighbour_checks); |
| 851 | |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 852 | if (path->weak) |
| 853 | continue; |
| 854 | |
Mark Brown | 8af294b | 2013-02-22 17:48:15 +0000 | [diff] [blame] | 855 | if (path->walking) |
| 856 | return 1; |
| 857 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 858 | if (path->walked) |
| 859 | continue; |
| 860 | |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 861 | trace_snd_soc_dapm_output_path(widget, path); |
| 862 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 863 | if (path->sink && path->connect) { |
| 864 | path->walked = 1; |
Mark Brown | 8af294b | 2013-02-22 17:48:15 +0000 | [diff] [blame] | 865 | path->walking = 1; |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 866 | |
| 867 | /* do we need to add this widget to the list ? */ |
| 868 | if (list) { |
| 869 | int err; |
| 870 | err = dapm_list_add_widget(list, path->sink); |
| 871 | if (err < 0) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 872 | dev_err(widget->dapm->dev, |
| 873 | "ASoC: could not add widget %s\n", |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 874 | widget->name); |
Mark Brown | 8af294b | 2013-02-22 17:48:15 +0000 | [diff] [blame] | 875 | path->walking = 0; |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 876 | return con; |
| 877 | } |
| 878 | } |
| 879 | |
| 880 | con += is_connected_output_ep(path->sink, list); |
Mark Brown | 8af294b | 2013-02-22 17:48:15 +0000 | [diff] [blame] | 881 | |
| 882 | path->walking = 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 883 | } |
| 884 | } |
| 885 | |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 886 | widget->outputs = con; |
| 887 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 888 | return con; |
| 889 | } |
| 890 | |
| 891 | /* |
| 892 | * Recursively check for a completed path to an active or physically connected |
| 893 | * input widget. Returns number of complete paths. |
| 894 | */ |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 895 | static int is_connected_input_ep(struct snd_soc_dapm_widget *widget, |
| 896 | struct snd_soc_dapm_widget_list **list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 897 | { |
| 898 | struct snd_soc_dapm_path *path; |
| 899 | int con = 0; |
| 900 | |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 901 | if (widget->inputs >= 0) |
| 902 | return widget->inputs; |
| 903 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 904 | DAPM_UPDATE_STAT(widget, path_checks); |
| 905 | |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 906 | switch (widget->id) { |
| 907 | case snd_soc_dapm_supply: |
| 908 | case snd_soc_dapm_regulator_supply: |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 909 | case snd_soc_dapm_clock_supply: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 910 | return 0; |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 911 | default: |
| 912 | break; |
| 913 | } |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 914 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 915 | /* active stream ? */ |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 916 | switch (widget->id) { |
| 917 | case snd_soc_dapm_dac: |
| 918 | case snd_soc_dapm_aif_in: |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 919 | case snd_soc_dapm_dai_in: |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 920 | if (widget->active) { |
| 921 | widget->inputs = snd_soc_dapm_suspend_check(widget); |
| 922 | return widget->inputs; |
| 923 | } |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 924 | default: |
| 925 | break; |
| 926 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 927 | |
| 928 | if (widget->connected) { |
| 929 | /* connected pin ? */ |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 930 | if (widget->id == snd_soc_dapm_input && !widget->ext) { |
| 931 | widget->inputs = snd_soc_dapm_suspend_check(widget); |
| 932 | return widget->inputs; |
| 933 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 934 | |
| 935 | /* connected VMID/Bias for lower pops */ |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 936 | if (widget->id == snd_soc_dapm_vmid) { |
| 937 | widget->inputs = snd_soc_dapm_suspend_check(widget); |
| 938 | return widget->inputs; |
| 939 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 940 | |
| 941 | /* connected jack ? */ |
Peter Ujfalusi | eaeae5d | 2009-09-30 09:27:24 +0300 | [diff] [blame] | 942 | if (widget->id == snd_soc_dapm_mic || |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 943 | (widget->id == snd_soc_dapm_line && |
| 944 | !list_empty(&widget->sinks))) { |
| 945 | widget->inputs = snd_soc_dapm_suspend_check(widget); |
| 946 | return widget->inputs; |
| 947 | } |
| 948 | |
Mark Brown | 1ab97c8 | 2011-11-27 16:21:51 +0000 | [diff] [blame] | 949 | /* signal generator */ |
| 950 | if (widget->id == snd_soc_dapm_siggen) { |
| 951 | widget->inputs = snd_soc_dapm_suspend_check(widget); |
| 952 | return widget->inputs; |
| 953 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | list_for_each_entry(path, &widget->sources, list_sink) { |
Mark Brown | e56235e | 2011-09-21 18:19:14 +0100 | [diff] [blame] | 957 | DAPM_UPDATE_STAT(widget, neighbour_checks); |
| 958 | |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 959 | if (path->weak) |
| 960 | continue; |
| 961 | |
Mark Brown | 8af294b | 2013-02-22 17:48:15 +0000 | [diff] [blame] | 962 | if (path->walking) |
| 963 | return 1; |
| 964 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 965 | if (path->walked) |
| 966 | continue; |
| 967 | |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 968 | trace_snd_soc_dapm_input_path(widget, path); |
| 969 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 970 | if (path->source && path->connect) { |
| 971 | path->walked = 1; |
Mark Brown | 8af294b | 2013-02-22 17:48:15 +0000 | [diff] [blame] | 972 | path->walking = 1; |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 973 | |
| 974 | /* do we need to add this widget to the list ? */ |
| 975 | if (list) { |
| 976 | int err; |
Liam Girdwood | 90c6ce0 | 2012-06-05 19:27:15 +0100 | [diff] [blame] | 977 | err = dapm_list_add_widget(list, path->source); |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 978 | if (err < 0) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 979 | dev_err(widget->dapm->dev, |
| 980 | "ASoC: could not add widget %s\n", |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 981 | widget->name); |
Mark Brown | 8af294b | 2013-02-22 17:48:15 +0000 | [diff] [blame] | 982 | path->walking = 0; |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 983 | return con; |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | con += is_connected_input_ep(path->source, list); |
Mark Brown | 8af294b | 2013-02-22 17:48:15 +0000 | [diff] [blame] | 988 | |
| 989 | path->walking = 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 993 | widget->inputs = con; |
| 994 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 995 | return con; |
| 996 | } |
| 997 | |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 998 | /** |
| 999 | * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets. |
| 1000 | * @dai: the soc DAI. |
| 1001 | * @stream: stream direction. |
| 1002 | * @list: list of active widgets for this stream. |
| 1003 | * |
| 1004 | * Queries DAPM graph as to whether an valid audio stream path exists for |
| 1005 | * the initial stream specified by name. This takes into account |
| 1006 | * current mixer and mux kcontrol settings. Creates list of valid widgets. |
| 1007 | * |
| 1008 | * Returns the number of valid paths or negative error. |
| 1009 | */ |
| 1010 | int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream, |
| 1011 | struct snd_soc_dapm_widget_list **list) |
| 1012 | { |
| 1013 | struct snd_soc_card *card = dai->card; |
| 1014 | int paths; |
| 1015 | |
| 1016 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
| 1017 | dapm_reset(card); |
| 1018 | |
Ryo Tsutsui | 1059ecf | 2013-04-01 12:50:01 +0100 | [diff] [blame] | 1019 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1020 | paths = is_connected_output_ep(dai->playback_widget, list); |
Ryo Tsutsui | 1059ecf | 2013-04-01 12:50:01 +0100 | [diff] [blame] | 1021 | dapm_clear_walk_output(&card->dapm, |
| 1022 | &dai->playback_widget->sinks); |
| 1023 | } else { |
Liam Girdwood | d298caa | 2012-06-01 18:03:00 +0100 | [diff] [blame] | 1024 | paths = is_connected_input_ep(dai->capture_widget, list); |
Ryo Tsutsui | 1059ecf | 2013-04-01 12:50:01 +0100 | [diff] [blame] | 1025 | dapm_clear_walk_input(&card->dapm, |
| 1026 | &dai->capture_widget->sources); |
| 1027 | } |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1028 | |
| 1029 | trace_snd_soc_dapm_connected(paths, stream); |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1030 | mutex_unlock(&card->dapm_mutex); |
| 1031 | |
| 1032 | return paths; |
| 1033 | } |
| 1034 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1035 | /* |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 1036 | * Handler for generic register modifier widget. |
| 1037 | */ |
| 1038 | int dapm_reg_event(struct snd_soc_dapm_widget *w, |
| 1039 | struct snd_kcontrol *kcontrol, int event) |
| 1040 | { |
| 1041 | unsigned int val; |
| 1042 | |
| 1043 | if (SND_SOC_DAPM_EVENT_ON(event)) |
| 1044 | val = w->on_val; |
| 1045 | else |
| 1046 | val = w->off_val; |
| 1047 | |
Liam Girdwood | 49575fb5 | 2012-03-06 18:16:19 +0000 | [diff] [blame] | 1048 | soc_widget_update_bits_locked(w, -(w->reg + 1), |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 1049 | w->mask << w->shift, val << w->shift); |
| 1050 | |
| 1051 | return 0; |
| 1052 | } |
Mark Brown | 1158941 | 2008-07-29 11:42:23 +0100 | [diff] [blame] | 1053 | EXPORT_SYMBOL_GPL(dapm_reg_event); |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 1054 | |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 1055 | /* |
| 1056 | * Handler for regulator supply widget. |
| 1057 | */ |
| 1058 | int dapm_regulator_event(struct snd_soc_dapm_widget *w, |
| 1059 | struct snd_kcontrol *kcontrol, int event) |
| 1060 | { |
Mark Brown | c05b84d | 2012-09-07 12:57:11 +0800 | [diff] [blame] | 1061 | int ret; |
| 1062 | |
| 1063 | if (SND_SOC_DAPM_EVENT_ON(event)) { |
| 1064 | if (w->invert & SND_SOC_DAPM_REGULATOR_BYPASS) { |
Mark Brown | 8784c77 | 2013-01-10 19:33:47 +0000 | [diff] [blame] | 1065 | ret = regulator_allow_bypass(w->regulator, false); |
Mark Brown | c05b84d | 2012-09-07 12:57:11 +0800 | [diff] [blame] | 1066 | if (ret != 0) |
| 1067 | dev_warn(w->dapm->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1068 | "ASoC: Failed to bypass %s: %d\n", |
Mark Brown | c05b84d | 2012-09-07 12:57:11 +0800 | [diff] [blame] | 1069 | w->name, ret); |
| 1070 | } |
| 1071 | |
Liam Girdwood | a3cc056 | 2012-03-09 17:20:16 +0000 | [diff] [blame] | 1072 | return regulator_enable(w->regulator); |
Mark Brown | c05b84d | 2012-09-07 12:57:11 +0800 | [diff] [blame] | 1073 | } else { |
| 1074 | if (w->invert & SND_SOC_DAPM_REGULATOR_BYPASS) { |
Mark Brown | 8784c77 | 2013-01-10 19:33:47 +0000 | [diff] [blame] | 1075 | ret = regulator_allow_bypass(w->regulator, true); |
Mark Brown | c05b84d | 2012-09-07 12:57:11 +0800 | [diff] [blame] | 1076 | if (ret != 0) |
| 1077 | dev_warn(w->dapm->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1078 | "ASoC: Failed to unbypass %s: %d\n", |
Mark Brown | c05b84d | 2012-09-07 12:57:11 +0800 | [diff] [blame] | 1079 | w->name, ret); |
| 1080 | } |
| 1081 | |
Liam Girdwood | a3cc056 | 2012-03-09 17:20:16 +0000 | [diff] [blame] | 1082 | return regulator_disable_deferred(w->regulator, w->shift); |
Mark Brown | c05b84d | 2012-09-07 12:57:11 +0800 | [diff] [blame] | 1083 | } |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 1084 | } |
| 1085 | EXPORT_SYMBOL_GPL(dapm_regulator_event); |
| 1086 | |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 1087 | /* |
| 1088 | * Handler for clock supply widget. |
| 1089 | */ |
| 1090 | int dapm_clock_event(struct snd_soc_dapm_widget *w, |
| 1091 | struct snd_kcontrol *kcontrol, int event) |
| 1092 | { |
| 1093 | if (!w->clk) |
| 1094 | return -EIO; |
| 1095 | |
Mark Brown | ec02995 | 2012-06-04 08:16:20 +0100 | [diff] [blame] | 1096 | #ifdef CONFIG_HAVE_CLK |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 1097 | if (SND_SOC_DAPM_EVENT_ON(event)) { |
Fabio Baltieri | 37c1b92 | 2013-04-30 16:09:52 +0200 | [diff] [blame] | 1098 | return clk_prepare_enable(w->clk); |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 1099 | } else { |
Fabio Baltieri | 37c1b92 | 2013-04-30 16:09:52 +0200 | [diff] [blame] | 1100 | clk_disable_unprepare(w->clk); |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 1101 | return 0; |
| 1102 | } |
Mark Brown | ec02995 | 2012-06-04 08:16:20 +0100 | [diff] [blame] | 1103 | #endif |
Marek Belisko | 98b3cf1 | 2012-07-12 23:00:16 +0200 | [diff] [blame] | 1104 | return 0; |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 1105 | } |
| 1106 | EXPORT_SYMBOL_GPL(dapm_clock_event); |
| 1107 | |
Mark Brown | d805002 | 2011-09-28 18:28:23 +0100 | [diff] [blame] | 1108 | static int dapm_widget_power_check(struct snd_soc_dapm_widget *w) |
| 1109 | { |
Mark Brown | 9b8a83b | 2011-10-04 22:15:59 +0100 | [diff] [blame] | 1110 | if (w->power_checked) |
| 1111 | return w->new_power; |
| 1112 | |
Mark Brown | d805002 | 2011-09-28 18:28:23 +0100 | [diff] [blame] | 1113 | if (w->force) |
Mark Brown | 9b8a83b | 2011-10-04 22:15:59 +0100 | [diff] [blame] | 1114 | w->new_power = 1; |
Mark Brown | d805002 | 2011-09-28 18:28:23 +0100 | [diff] [blame] | 1115 | else |
Mark Brown | 9b8a83b | 2011-10-04 22:15:59 +0100 | [diff] [blame] | 1116 | w->new_power = w->power_check(w); |
| 1117 | |
| 1118 | w->power_checked = true; |
| 1119 | |
| 1120 | return w->new_power; |
Mark Brown | d805002 | 2011-09-28 18:28:23 +0100 | [diff] [blame] | 1121 | } |
| 1122 | |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 1123 | /* Generic check to see if a widget should be powered. |
| 1124 | */ |
| 1125 | static int dapm_generic_check_power(struct snd_soc_dapm_widget *w) |
| 1126 | { |
| 1127 | int in, out; |
| 1128 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 1129 | DAPM_UPDATE_STAT(w, power_checks); |
| 1130 | |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1131 | in = is_connected_input_ep(w, NULL); |
Ryo Tsutsui | 1059ecf | 2013-04-01 12:50:01 +0100 | [diff] [blame] | 1132 | dapm_clear_walk_input(w->dapm, &w->sources); |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1133 | out = is_connected_output_ep(w, NULL); |
Ryo Tsutsui | 1059ecf | 2013-04-01 12:50:01 +0100 | [diff] [blame] | 1134 | dapm_clear_walk_output(w->dapm, &w->sinks); |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 1135 | return out != 0 && in != 0; |
| 1136 | } |
| 1137 | |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 1138 | /* Check to see if an ADC has power */ |
| 1139 | static int dapm_adc_check_power(struct snd_soc_dapm_widget *w) |
| 1140 | { |
| 1141 | int in; |
| 1142 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 1143 | DAPM_UPDATE_STAT(w, power_checks); |
| 1144 | |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 1145 | if (w->active) { |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1146 | in = is_connected_input_ep(w, NULL); |
Ryo Tsutsui | 1059ecf | 2013-04-01 12:50:01 +0100 | [diff] [blame] | 1147 | dapm_clear_walk_input(w->dapm, &w->sources); |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 1148 | return in != 0; |
| 1149 | } else { |
| 1150 | return dapm_generic_check_power(w); |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | /* Check to see if a DAC has power */ |
| 1155 | static int dapm_dac_check_power(struct snd_soc_dapm_widget *w) |
| 1156 | { |
| 1157 | int out; |
| 1158 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 1159 | DAPM_UPDATE_STAT(w, power_checks); |
| 1160 | |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 1161 | if (w->active) { |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1162 | out = is_connected_output_ep(w, NULL); |
Ryo Tsutsui | 1059ecf | 2013-04-01 12:50:01 +0100 | [diff] [blame] | 1163 | dapm_clear_walk_output(w->dapm, &w->sinks); |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 1164 | return out != 0; |
| 1165 | } else { |
| 1166 | return dapm_generic_check_power(w); |
| 1167 | } |
| 1168 | } |
| 1169 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1170 | /* Check to see if a power supply is needed */ |
| 1171 | static int dapm_supply_check_power(struct snd_soc_dapm_widget *w) |
| 1172 | { |
| 1173 | struct snd_soc_dapm_path *path; |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1174 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 1175 | DAPM_UPDATE_STAT(w, power_checks); |
| 1176 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1177 | /* Check if one of our outputs is connected */ |
| 1178 | list_for_each_entry(path, &w->sinks, list_source) { |
Mark Brown | a8fdac8 | 2011-09-28 18:20:26 +0100 | [diff] [blame] | 1179 | DAPM_UPDATE_STAT(w, neighbour_checks); |
| 1180 | |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 1181 | if (path->weak) |
| 1182 | continue; |
| 1183 | |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1184 | if (path->connected && |
| 1185 | !path->connected(path->source, path->sink)) |
| 1186 | continue; |
| 1187 | |
Mark Brown | 3017358 | 2011-02-11 11:42:19 +0000 | [diff] [blame] | 1188 | if (!path->sink) |
| 1189 | continue; |
| 1190 | |
Mark Brown | f68d7e1 | 2011-10-04 22:57:50 +0100 | [diff] [blame] | 1191 | if (dapm_widget_power_check(path->sink)) |
| 1192 | return 1; |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1193 | } |
| 1194 | |
Mark Brown | f68d7e1 | 2011-10-04 22:57:50 +0100 | [diff] [blame] | 1195 | return 0; |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1196 | } |
| 1197 | |
Mark Brown | 35c64bc | 2011-09-28 18:23:53 +0100 | [diff] [blame] | 1198 | static int dapm_always_on_check_power(struct snd_soc_dapm_widget *w) |
| 1199 | { |
| 1200 | return 1; |
| 1201 | } |
| 1202 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1203 | static int dapm_seq_compare(struct snd_soc_dapm_widget *a, |
| 1204 | struct snd_soc_dapm_widget *b, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1205 | bool power_up) |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1206 | { |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1207 | int *sort; |
| 1208 | |
| 1209 | if (power_up) |
| 1210 | sort = dapm_up_seq; |
| 1211 | else |
| 1212 | sort = dapm_down_seq; |
| 1213 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1214 | if (sort[a->id] != sort[b->id]) |
| 1215 | return sort[a->id] - sort[b->id]; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1216 | if (a->subseq != b->subseq) { |
| 1217 | if (power_up) |
| 1218 | return a->subseq - b->subseq; |
| 1219 | else |
| 1220 | return b->subseq - a->subseq; |
| 1221 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1222 | if (a->reg != b->reg) |
| 1223 | return a->reg - b->reg; |
Mark Brown | 84dab56 | 2010-11-12 15:28:42 +0000 | [diff] [blame] | 1224 | if (a->dapm != b->dapm) |
| 1225 | return (unsigned long)a->dapm - (unsigned long)b->dapm; |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1226 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1227 | return 0; |
| 1228 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1229 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1230 | /* Insert a widget in order into a DAPM power sequence. */ |
| 1231 | static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget, |
| 1232 | struct list_head *list, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1233 | bool power_up) |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1234 | { |
| 1235 | struct snd_soc_dapm_widget *w; |
| 1236 | |
| 1237 | list_for_each_entry(w, list, power_list) |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1238 | if (dapm_seq_compare(new_widget, w, power_up) < 0) { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1239 | list_add_tail(&new_widget->power_list, &w->power_list); |
| 1240 | return; |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1241 | } |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 1242 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1243 | list_add_tail(&new_widget->power_list, list); |
| 1244 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1245 | |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1246 | static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm, |
| 1247 | struct snd_soc_dapm_widget *w, int event) |
| 1248 | { |
| 1249 | struct snd_soc_card *card = dapm->card; |
| 1250 | const char *ev_name; |
| 1251 | int power, ret; |
| 1252 | |
| 1253 | switch (event) { |
| 1254 | case SND_SOC_DAPM_PRE_PMU: |
| 1255 | ev_name = "PRE_PMU"; |
| 1256 | power = 1; |
| 1257 | break; |
| 1258 | case SND_SOC_DAPM_POST_PMU: |
| 1259 | ev_name = "POST_PMU"; |
| 1260 | power = 1; |
| 1261 | break; |
| 1262 | case SND_SOC_DAPM_PRE_PMD: |
| 1263 | ev_name = "PRE_PMD"; |
| 1264 | power = 0; |
| 1265 | break; |
| 1266 | case SND_SOC_DAPM_POST_PMD: |
| 1267 | ev_name = "POST_PMD"; |
| 1268 | power = 0; |
| 1269 | break; |
Mark Brown | 8011412 | 2013-02-25 15:14:19 +0000 | [diff] [blame] | 1270 | case SND_SOC_DAPM_WILL_PMU: |
| 1271 | ev_name = "WILL_PMU"; |
| 1272 | power = 1; |
| 1273 | break; |
| 1274 | case SND_SOC_DAPM_WILL_PMD: |
| 1275 | ev_name = "WILL_PMD"; |
| 1276 | power = 0; |
| 1277 | break; |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1278 | default: |
| 1279 | BUG(); |
| 1280 | return; |
| 1281 | } |
| 1282 | |
| 1283 | if (w->power != power) |
| 1284 | return; |
| 1285 | |
| 1286 | if (w->event && (w->event_flags & event)) { |
| 1287 | pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n", |
| 1288 | w->name, ev_name); |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1289 | trace_snd_soc_dapm_widget_event_start(w, event); |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1290 | ret = w->event(w, NULL, event); |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1291 | trace_snd_soc_dapm_widget_event_done(w, event); |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1292 | if (ret < 0) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1293 | dev_err(dapm->dev, "ASoC: %s: %s event failed: %d\n", |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1294 | ev_name, w->name, ret); |
| 1295 | } |
| 1296 | } |
| 1297 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1298 | /* Apply the coalesced changes from a DAPM sequence */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1299 | static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm, |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1300 | struct list_head *pending) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1301 | { |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 1302 | struct snd_soc_card *card = dapm->card; |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1303 | struct snd_soc_dapm_widget *w; |
| 1304 | int reg, power; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1305 | unsigned int value = 0; |
| 1306 | unsigned int mask = 0; |
| 1307 | unsigned int cur_mask; |
| 1308 | |
| 1309 | reg = list_first_entry(pending, struct snd_soc_dapm_widget, |
| 1310 | power_list)->reg; |
| 1311 | |
| 1312 | list_for_each_entry(w, pending, power_list) { |
| 1313 | cur_mask = 1 << w->shift; |
| 1314 | BUG_ON(reg != w->reg); |
| 1315 | |
| 1316 | if (w->invert) |
| 1317 | power = !w->power; |
| 1318 | else |
| 1319 | power = w->power; |
| 1320 | |
| 1321 | mask |= cur_mask; |
| 1322 | if (power) |
| 1323 | value |= cur_mask; |
| 1324 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 1325 | pop_dbg(dapm->dev, card->pop_time, |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1326 | "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n", |
| 1327 | w->name, reg, value, mask); |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1328 | |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1329 | /* Check for events */ |
| 1330 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU); |
| 1331 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1332 | } |
| 1333 | |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1334 | if (reg >= 0) { |
Mark Brown | 29376bc | 2011-06-19 13:49:28 +0100 | [diff] [blame] | 1335 | /* Any widget will do, they should all be updating the |
| 1336 | * same register. |
| 1337 | */ |
| 1338 | w = list_first_entry(pending, struct snd_soc_dapm_widget, |
| 1339 | power_list); |
| 1340 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 1341 | pop_dbg(dapm->dev, card->pop_time, |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1342 | "pop test : Applying 0x%x/0x%x to %x in %dms\n", |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 1343 | value, mask, reg, card->pop_time); |
| 1344 | pop_wait(card->pop_time); |
Liam Girdwood | 49575fb5 | 2012-03-06 18:16:19 +0000 | [diff] [blame] | 1345 | soc_widget_update_bits_locked(w, reg, mask, value); |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | list_for_each_entry(w, pending, power_list) { |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1349 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU); |
| 1350 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD); |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1351 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1354 | /* Apply a DAPM power sequence. |
| 1355 | * |
| 1356 | * We walk over a pre-sorted list of widgets to apply power to. In |
| 1357 | * order to minimise the number of writes to the device required |
| 1358 | * multiple widgets will be updated in a single write where possible. |
| 1359 | * Currently anything that requires more than a single write is not |
| 1360 | * handled. |
| 1361 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1362 | static void dapm_seq_run(struct snd_soc_dapm_context *dapm, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1363 | struct list_head *list, int event, bool power_up) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1364 | { |
| 1365 | struct snd_soc_dapm_widget *w, *n; |
| 1366 | LIST_HEAD(pending); |
| 1367 | int cur_sort = -1; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1368 | int cur_subseq = -1; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1369 | int cur_reg = SND_SOC_NOPM; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1370 | struct snd_soc_dapm_context *cur_dapm = NULL; |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1371 | int ret, i; |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1372 | int *sort; |
| 1373 | |
| 1374 | if (power_up) |
| 1375 | sort = dapm_up_seq; |
| 1376 | else |
| 1377 | sort = dapm_down_seq; |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1378 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1379 | list_for_each_entry_safe(w, n, list, power_list) { |
| 1380 | ret = 0; |
| 1381 | |
| 1382 | /* Do we need to apply any queued changes? */ |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1383 | if (sort[w->id] != cur_sort || w->reg != cur_reg || |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1384 | w->dapm != cur_dapm || w->subseq != cur_subseq) { |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1385 | if (!list_empty(&pending)) |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1386 | dapm_seq_run_coalesced(cur_dapm, &pending); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1387 | |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1388 | if (cur_dapm && cur_dapm->seq_notifier) { |
| 1389 | for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++) |
| 1390 | if (sort[i] == cur_sort) |
| 1391 | cur_dapm->seq_notifier(cur_dapm, |
Mark Brown | f85a9e0 | 2011-01-26 21:41:28 +0000 | [diff] [blame] | 1392 | i, |
| 1393 | cur_subseq); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1396 | INIT_LIST_HEAD(&pending); |
| 1397 | cur_sort = -1; |
Mark Brown | b0b3e6f | 2011-07-16 10:55:08 +0900 | [diff] [blame] | 1398 | cur_subseq = INT_MIN; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1399 | cur_reg = SND_SOC_NOPM; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1400 | cur_dapm = NULL; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1401 | } |
| 1402 | |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1403 | switch (w->id) { |
| 1404 | case snd_soc_dapm_pre: |
| 1405 | if (!w->event) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1406 | list_for_each_entry_safe_continue(w, n, list, |
| 1407 | power_list); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1408 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1409 | if (event == SND_SOC_DAPM_STREAM_START) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1410 | ret = w->event(w, |
| 1411 | NULL, SND_SOC_DAPM_PRE_PMU); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1412 | else if (event == SND_SOC_DAPM_STREAM_STOP) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1413 | ret = w->event(w, |
| 1414 | NULL, SND_SOC_DAPM_PRE_PMD); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1415 | break; |
| 1416 | |
| 1417 | case snd_soc_dapm_post: |
| 1418 | if (!w->event) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1419 | list_for_each_entry_safe_continue(w, n, list, |
| 1420 | power_list); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1421 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1422 | if (event == SND_SOC_DAPM_STREAM_START) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1423 | ret = w->event(w, |
| 1424 | NULL, SND_SOC_DAPM_POST_PMU); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1425 | else if (event == SND_SOC_DAPM_STREAM_STOP) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1426 | ret = w->event(w, |
| 1427 | NULL, SND_SOC_DAPM_POST_PMD); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1428 | break; |
| 1429 | |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1430 | default: |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1431 | /* Queue it up for application */ |
| 1432 | cur_sort = sort[w->id]; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1433 | cur_subseq = w->subseq; |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1434 | cur_reg = w->reg; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1435 | cur_dapm = w->dapm; |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1436 | list_move(&w->power_list, &pending); |
| 1437 | break; |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1438 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1439 | |
| 1440 | if (ret < 0) |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 1441 | dev_err(w->dapm->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1442 | "ASoC: Failed to apply widget power: %d\n", ret); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1443 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1444 | |
| 1445 | if (!list_empty(&pending)) |
Mark Brown | 28e8680 | 2011-03-08 19:29:53 +0000 | [diff] [blame] | 1446 | dapm_seq_run_coalesced(cur_dapm, &pending); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1447 | |
| 1448 | if (cur_dapm && cur_dapm->seq_notifier) { |
| 1449 | for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++) |
| 1450 | if (sort[i] == cur_sort) |
| 1451 | cur_dapm->seq_notifier(cur_dapm, |
Mark Brown | f85a9e0 | 2011-01-26 21:41:28 +0000 | [diff] [blame] | 1452 | i, cur_subseq); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1453 | } |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1454 | } |
| 1455 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1456 | static void dapm_widget_update(struct snd_soc_dapm_context *dapm) |
| 1457 | { |
| 1458 | struct snd_soc_dapm_update *update = dapm->update; |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 1459 | struct snd_soc_dapm_widget_list *wlist; |
| 1460 | struct snd_soc_dapm_widget *w = NULL; |
| 1461 | unsigned int wi; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1462 | int ret; |
| 1463 | |
| 1464 | if (!update) |
| 1465 | return; |
| 1466 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 1467 | wlist = snd_kcontrol_chip(update->kcontrol); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1468 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 1469 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 1470 | w = wlist->widgets[wi]; |
| 1471 | |
| 1472 | if (w->event && (w->event_flags & SND_SOC_DAPM_PRE_REG)) { |
| 1473 | ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG); |
| 1474 | if (ret != 0) |
| 1475 | dev_err(dapm->dev, "ASoC: %s DAPM pre-event failed: %d\n", |
| 1476 | w->name, ret); |
| 1477 | } |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1478 | } |
| 1479 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 1480 | if (!w) |
| 1481 | return; |
| 1482 | |
Liam Girdwood | 49575fb5 | 2012-03-06 18:16:19 +0000 | [diff] [blame] | 1483 | ret = soc_widget_update_bits_locked(w, update->reg, update->mask, |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1484 | update->val); |
| 1485 | if (ret < 0) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1486 | dev_err(dapm->dev, "ASoC: %s DAPM update failed: %d\n", |
| 1487 | w->name, ret); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1488 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 1489 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 1490 | w = wlist->widgets[wi]; |
| 1491 | |
| 1492 | if (w->event && (w->event_flags & SND_SOC_DAPM_POST_REG)) { |
| 1493 | ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG); |
| 1494 | if (ret != 0) |
| 1495 | dev_err(dapm->dev, "ASoC: %s DAPM post-event failed: %d\n", |
| 1496 | w->name, ret); |
| 1497 | } |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1498 | } |
| 1499 | } |
| 1500 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1501 | /* Async callback run prior to DAPM sequences - brings to _PREPARE if |
| 1502 | * they're changing state. |
| 1503 | */ |
| 1504 | static void dapm_pre_sequence_async(void *data, async_cookie_t cookie) |
| 1505 | { |
| 1506 | struct snd_soc_dapm_context *d = data; |
| 1507 | int ret; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1508 | |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1509 | /* If we're off and we're not supposed to be go into STANDBY */ |
| 1510 | if (d->bias_level == SND_SOC_BIAS_OFF && |
| 1511 | d->target_bias_level != SND_SOC_BIAS_OFF) { |
Mark Brown | f1aac48 | 2011-12-05 15:17:06 +0000 | [diff] [blame] | 1512 | if (d->dev) |
| 1513 | pm_runtime_get_sync(d->dev); |
| 1514 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1515 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY); |
| 1516 | if (ret != 0) |
| 1517 | dev_err(d->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1518 | "ASoC: Failed to turn on bias: %d\n", ret); |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1519 | } |
| 1520 | |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1521 | /* Prepare for a STADDBY->ON or ON->STANDBY transition */ |
| 1522 | if (d->bias_level != d->target_bias_level) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1523 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE); |
| 1524 | if (ret != 0) |
| 1525 | dev_err(d->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1526 | "ASoC: Failed to prepare bias: %d\n", ret); |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1527 | } |
| 1528 | } |
| 1529 | |
| 1530 | /* Async callback run prior to DAPM sequences - brings to their final |
| 1531 | * state. |
| 1532 | */ |
| 1533 | static void dapm_post_sequence_async(void *data, async_cookie_t cookie) |
| 1534 | { |
| 1535 | struct snd_soc_dapm_context *d = data; |
| 1536 | int ret; |
| 1537 | |
| 1538 | /* If we just powered the last thing off drop to standby bias */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1539 | if (d->bias_level == SND_SOC_BIAS_PREPARE && |
| 1540 | (d->target_bias_level == SND_SOC_BIAS_STANDBY || |
| 1541 | d->target_bias_level == SND_SOC_BIAS_OFF)) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1542 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY); |
| 1543 | if (ret != 0) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1544 | dev_err(d->dev, "ASoC: Failed to apply standby bias: %d\n", |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1545 | ret); |
| 1546 | } |
| 1547 | |
| 1548 | /* If we're in standby and can support bias off then do that */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1549 | if (d->bias_level == SND_SOC_BIAS_STANDBY && |
| 1550 | d->target_bias_level == SND_SOC_BIAS_OFF) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1551 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF); |
| 1552 | if (ret != 0) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1553 | dev_err(d->dev, "ASoC: Failed to turn off bias: %d\n", |
| 1554 | ret); |
Mark Brown | f1aac48 | 2011-12-05 15:17:06 +0000 | [diff] [blame] | 1555 | |
| 1556 | if (d->dev) |
Mark Brown | fb644e9 | 2012-01-25 19:53:58 +0000 | [diff] [blame] | 1557 | pm_runtime_put(d->dev); |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | /* If we just powered up then move to active bias */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1561 | if (d->bias_level == SND_SOC_BIAS_PREPARE && |
| 1562 | d->target_bias_level == SND_SOC_BIAS_ON) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1563 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON); |
| 1564 | if (ret != 0) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1565 | dev_err(d->dev, "ASoC: Failed to apply active bias: %d\n", |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1566 | ret); |
| 1567 | } |
| 1568 | } |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1569 | |
Mark Brown | fe4fda5 | 2011-10-03 22:36:57 +0100 | [diff] [blame] | 1570 | static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget *peer, |
| 1571 | bool power, bool connect) |
| 1572 | { |
| 1573 | /* If a connection is being made or broken then that update |
| 1574 | * will have marked the peer dirty, otherwise the widgets are |
| 1575 | * not connected and this update has no impact. */ |
| 1576 | if (!connect) |
| 1577 | return; |
| 1578 | |
| 1579 | /* If the peer is already in the state we're moving to then we |
| 1580 | * won't have an impact on it. */ |
| 1581 | if (power != peer->power) |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 1582 | dapm_mark_dirty(peer, "peer state change"); |
Mark Brown | fe4fda5 | 2011-10-03 22:36:57 +0100 | [diff] [blame] | 1583 | } |
| 1584 | |
Mark Brown | 05623c4 | 2011-09-28 17:02:31 +0100 | [diff] [blame] | 1585 | static void dapm_widget_set_power(struct snd_soc_dapm_widget *w, bool power, |
| 1586 | struct list_head *up_list, |
| 1587 | struct list_head *down_list) |
| 1588 | { |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1589 | struct snd_soc_dapm_path *path; |
| 1590 | |
Mark Brown | 05623c4 | 2011-09-28 17:02:31 +0100 | [diff] [blame] | 1591 | if (w->power == power) |
| 1592 | return; |
| 1593 | |
| 1594 | trace_snd_soc_dapm_widget_power(w, power); |
| 1595 | |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1596 | /* If we changed our power state perhaps our neigbours changed |
Mark Brown | fe4fda5 | 2011-10-03 22:36:57 +0100 | [diff] [blame] | 1597 | * also. |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1598 | */ |
| 1599 | list_for_each_entry(path, &w->sources, list_sink) { |
| 1600 | if (path->source) { |
Mark Brown | fe4fda5 | 2011-10-03 22:36:57 +0100 | [diff] [blame] | 1601 | dapm_widget_set_peer_power(path->source, power, |
| 1602 | path->connect); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1603 | } |
| 1604 | } |
Mark Brown | f3bf3e4 | 2011-10-04 22:43:31 +0100 | [diff] [blame] | 1605 | switch (w->id) { |
| 1606 | case snd_soc_dapm_supply: |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 1607 | case snd_soc_dapm_regulator_supply: |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 1608 | case snd_soc_dapm_clock_supply: |
Mark Brown | f3bf3e4 | 2011-10-04 22:43:31 +0100 | [diff] [blame] | 1609 | /* Supplies can't affect their outputs, only their inputs */ |
| 1610 | break; |
| 1611 | default: |
| 1612 | list_for_each_entry(path, &w->sinks, list_source) { |
| 1613 | if (path->sink) { |
| 1614 | dapm_widget_set_peer_power(path->sink, power, |
| 1615 | path->connect); |
| 1616 | } |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1617 | } |
Mark Brown | f3bf3e4 | 2011-10-04 22:43:31 +0100 | [diff] [blame] | 1618 | break; |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1619 | } |
| 1620 | |
Mark Brown | 05623c4 | 2011-09-28 17:02:31 +0100 | [diff] [blame] | 1621 | if (power) |
| 1622 | dapm_seq_insert(w, up_list, true); |
| 1623 | else |
| 1624 | dapm_seq_insert(w, down_list, false); |
| 1625 | |
| 1626 | w->power = power; |
| 1627 | } |
| 1628 | |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1629 | static void dapm_power_one_widget(struct snd_soc_dapm_widget *w, |
| 1630 | struct list_head *up_list, |
| 1631 | struct list_head *down_list) |
| 1632 | { |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1633 | int power; |
| 1634 | |
| 1635 | switch (w->id) { |
| 1636 | case snd_soc_dapm_pre: |
| 1637 | dapm_seq_insert(w, down_list, false); |
| 1638 | break; |
| 1639 | case snd_soc_dapm_post: |
| 1640 | dapm_seq_insert(w, up_list, true); |
| 1641 | break; |
| 1642 | |
| 1643 | default: |
Mark Brown | d805002 | 2011-09-28 18:28:23 +0100 | [diff] [blame] | 1644 | power = dapm_widget_power_check(w); |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1645 | |
Mark Brown | 05623c4 | 2011-09-28 17:02:31 +0100 | [diff] [blame] | 1646 | dapm_widget_set_power(w, power, up_list, down_list); |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1647 | break; |
| 1648 | } |
| 1649 | } |
| 1650 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1651 | /* |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1652 | * Scan each dapm widget for complete audio path. |
| 1653 | * A complete path is a route that has valid endpoints i.e.:- |
| 1654 | * |
| 1655 | * o DAC to output pin. |
| 1656 | * o Input Pin to ADC. |
| 1657 | * o Input pin to Output pin (bypass, sidetone) |
| 1658 | * o DAC to ADC (loopback). |
| 1659 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1660 | static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1661 | { |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 1662 | struct snd_soc_card *card = dapm->card; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1663 | struct snd_soc_dapm_widget *w; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1664 | struct snd_soc_dapm_context *d; |
Mark Brown | 291f3bb | 2009-06-07 13:57:17 +0100 | [diff] [blame] | 1665 | LIST_HEAD(up_list); |
| 1666 | LIST_HEAD(down_list); |
Dan Williams | 2955b47 | 2012-07-09 19:33:25 -0700 | [diff] [blame] | 1667 | ASYNC_DOMAIN_EXCLUSIVE(async_domain); |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1668 | enum snd_soc_bias_level bias; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1669 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1670 | trace_snd_soc_dapm_start(card); |
| 1671 | |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1672 | list_for_each_entry(d, &card->dapm_list, list) { |
Mark Brown | 497098be | 2012-03-08 15:06:09 +0000 | [diff] [blame] | 1673 | if (d->idle_bias_off) |
| 1674 | d->target_bias_level = SND_SOC_BIAS_OFF; |
| 1675 | else |
| 1676 | d->target_bias_level = SND_SOC_BIAS_STANDBY; |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1677 | } |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1678 | |
Liam Girdwood | 6c120e1 | 2012-02-15 15:15:34 +0000 | [diff] [blame] | 1679 | dapm_reset(card); |
Mark Brown | 9b8a83b | 2011-10-04 22:15:59 +0100 | [diff] [blame] | 1680 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1681 | /* Check which widgets we need to power and store them in |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1682 | * lists indicating if they should be powered up or down. We |
| 1683 | * only check widgets that have been flagged as dirty but note |
| 1684 | * that new widgets may be added to the dirty list while we |
| 1685 | * iterate. |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1686 | */ |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1687 | list_for_each_entry(w, &card->dapm_dirty, dirty) { |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1688 | dapm_power_one_widget(w, &up_list, &down_list); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1689 | } |
| 1690 | |
Mark Brown | f9de6d7 | 2011-09-28 17:19:47 +0100 | [diff] [blame] | 1691 | list_for_each_entry(w, &card->widgets, list) { |
Mark Brown | 0ff97eb | 2012-07-20 17:29:34 +0100 | [diff] [blame] | 1692 | switch (w->id) { |
| 1693 | case snd_soc_dapm_pre: |
| 1694 | case snd_soc_dapm_post: |
| 1695 | /* These widgets always need to be powered */ |
| 1696 | break; |
| 1697 | default: |
| 1698 | list_del_init(&w->dirty); |
| 1699 | break; |
| 1700 | } |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1701 | |
Mark Brown | f9de6d7 | 2011-09-28 17:19:47 +0100 | [diff] [blame] | 1702 | if (w->power) { |
| 1703 | d = w->dapm; |
| 1704 | |
| 1705 | /* Supplies and micbiases only bring the |
| 1706 | * context up to STANDBY as unless something |
| 1707 | * else is active and passing audio they |
Mark Brown | afe6236 | 2012-01-25 19:55:22 +0000 | [diff] [blame] | 1708 | * generally don't require full power. Signal |
| 1709 | * generators are virtual pins and have no |
| 1710 | * power impact themselves. |
Mark Brown | f9de6d7 | 2011-09-28 17:19:47 +0100 | [diff] [blame] | 1711 | */ |
| 1712 | switch (w->id) { |
Mark Brown | afe6236 | 2012-01-25 19:55:22 +0000 | [diff] [blame] | 1713 | case snd_soc_dapm_siggen: |
| 1714 | break; |
Mark Brown | f9de6d7 | 2011-09-28 17:19:47 +0100 | [diff] [blame] | 1715 | case snd_soc_dapm_supply: |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 1716 | case snd_soc_dapm_regulator_supply: |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 1717 | case snd_soc_dapm_clock_supply: |
Mark Brown | f9de6d7 | 2011-09-28 17:19:47 +0100 | [diff] [blame] | 1718 | case snd_soc_dapm_micbias: |
| 1719 | if (d->target_bias_level < SND_SOC_BIAS_STANDBY) |
| 1720 | d->target_bias_level = SND_SOC_BIAS_STANDBY; |
| 1721 | break; |
| 1722 | default: |
| 1723 | d->target_bias_level = SND_SOC_BIAS_ON; |
| 1724 | break; |
| 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | } |
| 1729 | |
Mark Brown | 85a843c | 2011-09-21 21:29:47 +0100 | [diff] [blame] | 1730 | /* Force all contexts in the card to the same bias state if |
| 1731 | * they're not ground referenced. |
| 1732 | */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1733 | bias = SND_SOC_BIAS_OFF; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1734 | list_for_each_entry(d, &card->dapm_list, list) |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1735 | if (d->target_bias_level > bias) |
| 1736 | bias = d->target_bias_level; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1737 | list_for_each_entry(d, &card->dapm_list, list) |
Mark Brown | 85a843c | 2011-09-21 21:29:47 +0100 | [diff] [blame] | 1738 | if (!d->idle_bias_off) |
| 1739 | d->target_bias_level = bias; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1740 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 1741 | trace_snd_soc_dapm_walk_done(card); |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1742 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1743 | /* Run all the bias changes in parallel */ |
| 1744 | list_for_each_entry(d, &dapm->card->dapm_list, list) |
| 1745 | async_schedule_domain(dapm_pre_sequence_async, d, |
| 1746 | &async_domain); |
| 1747 | async_synchronize_full_domain(&async_domain); |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1748 | |
Lars-Peter Clausen | cf1f7c6 | 2013-05-23 00:12:53 +0200 | [diff] [blame] | 1749 | list_for_each_entry(w, &down_list, power_list) { |
Mark Brown | 8011412 | 2013-02-25 15:14:19 +0000 | [diff] [blame] | 1750 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_WILL_PMD); |
| 1751 | } |
| 1752 | |
Lars-Peter Clausen | cf1f7c6 | 2013-05-23 00:12:53 +0200 | [diff] [blame] | 1753 | list_for_each_entry(w, &up_list, power_list) { |
Mark Brown | 8011412 | 2013-02-25 15:14:19 +0000 | [diff] [blame] | 1754 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_WILL_PMU); |
| 1755 | } |
| 1756 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1757 | /* Power down widgets first; try to avoid amplifying pops. */ |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1758 | dapm_seq_run(dapm, &down_list, event, false); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1759 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1760 | dapm_widget_update(dapm); |
| 1761 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1762 | /* Now power up. */ |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1763 | dapm_seq_run(dapm, &up_list, event, true); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1764 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1765 | /* Run all the bias changes in parallel */ |
| 1766 | list_for_each_entry(d, &dapm->card->dapm_list, list) |
| 1767 | async_schedule_domain(dapm_post_sequence_async, d, |
| 1768 | &async_domain); |
| 1769 | async_synchronize_full_domain(&async_domain); |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1770 | |
Liam Girdwood | 8078d87 | 2012-02-15 15:15:35 +0000 | [diff] [blame] | 1771 | /* do we need to notify any clients that DAPM event is complete */ |
| 1772 | list_for_each_entry(d, &card->dapm_list, list) { |
| 1773 | if (d->stream_event) |
| 1774 | d->stream_event(d, event); |
| 1775 | } |
| 1776 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 1777 | pop_dbg(dapm->dev, card->pop_time, |
| 1778 | "DAPM sequencing finished, waiting %dms\n", card->pop_time); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 1779 | pop_wait(card->pop_time); |
Mark Brown | cb507e7 | 2009-07-08 18:54:57 +0100 | [diff] [blame] | 1780 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1781 | trace_snd_soc_dapm_done(card); |
| 1782 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1783 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1784 | } |
| 1785 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1786 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1787 | static ssize_t dapm_widget_power_read_file(struct file *file, |
| 1788 | char __user *user_buf, |
| 1789 | size_t count, loff_t *ppos) |
| 1790 | { |
| 1791 | struct snd_soc_dapm_widget *w = file->private_data; |
| 1792 | char *buf; |
| 1793 | int in, out; |
| 1794 | ssize_t ret; |
| 1795 | struct snd_soc_dapm_path *p = NULL; |
| 1796 | |
| 1797 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 1798 | if (!buf) |
| 1799 | return -ENOMEM; |
| 1800 | |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1801 | in = is_connected_input_ep(w, NULL); |
Ryo Tsutsui | 1059ecf | 2013-04-01 12:50:01 +0100 | [diff] [blame] | 1802 | dapm_clear_walk_input(w->dapm, &w->sources); |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1803 | out = is_connected_output_ep(w, NULL); |
Ryo Tsutsui | 1059ecf | 2013-04-01 12:50:01 +0100 | [diff] [blame] | 1804 | dapm_clear_walk_output(w->dapm, &w->sinks); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1805 | |
Mark Brown | f13ebad | 2012-03-03 18:01:01 +0000 | [diff] [blame] | 1806 | ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d", |
| 1807 | w->name, w->power ? "On" : "Off", |
| 1808 | w->force ? " (forced)" : "", in, out); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1809 | |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 1810 | if (w->reg >= 0) |
| 1811 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
| 1812 | " - R%d(0x%x) bit %d", |
| 1813 | w->reg, w->reg, w->shift); |
| 1814 | |
| 1815 | ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n"); |
| 1816 | |
Mark Brown | 3eef08b | 2009-09-14 16:49:00 +0100 | [diff] [blame] | 1817 | if (w->sname) |
| 1818 | ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n", |
| 1819 | w->sname, |
| 1820 | w->active ? "active" : "inactive"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1821 | |
| 1822 | list_for_each_entry(p, &w->sources, list_sink) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1823 | if (p->connected && !p->connected(w, p->sink)) |
| 1824 | continue; |
| 1825 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1826 | if (p->connect) |
| 1827 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
Dimitris Papastamos | 67f5ed6 | 2011-02-24 17:09:32 +0000 | [diff] [blame] | 1828 | " in \"%s\" \"%s\"\n", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1829 | p->name ? p->name : "static", |
| 1830 | p->source->name); |
| 1831 | } |
| 1832 | list_for_each_entry(p, &w->sinks, list_source) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1833 | if (p->connected && !p->connected(w, p->sink)) |
| 1834 | continue; |
| 1835 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1836 | if (p->connect) |
| 1837 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
Dimitris Papastamos | 67f5ed6 | 2011-02-24 17:09:32 +0000 | [diff] [blame] | 1838 | " out \"%s\" \"%s\"\n", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1839 | p->name ? p->name : "static", |
| 1840 | p->sink->name); |
| 1841 | } |
| 1842 | |
| 1843 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 1844 | |
| 1845 | kfree(buf); |
| 1846 | return ret; |
| 1847 | } |
| 1848 | |
| 1849 | static const struct file_operations dapm_widget_power_fops = { |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 1850 | .open = simple_open, |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1851 | .read = dapm_widget_power_read_file, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1852 | .llseek = default_llseek, |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1853 | }; |
| 1854 | |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 1855 | static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf, |
| 1856 | size_t count, loff_t *ppos) |
| 1857 | { |
| 1858 | struct snd_soc_dapm_context *dapm = file->private_data; |
| 1859 | char *level; |
| 1860 | |
| 1861 | switch (dapm->bias_level) { |
| 1862 | case SND_SOC_BIAS_ON: |
| 1863 | level = "On\n"; |
| 1864 | break; |
| 1865 | case SND_SOC_BIAS_PREPARE: |
| 1866 | level = "Prepare\n"; |
| 1867 | break; |
| 1868 | case SND_SOC_BIAS_STANDBY: |
| 1869 | level = "Standby\n"; |
| 1870 | break; |
| 1871 | case SND_SOC_BIAS_OFF: |
| 1872 | level = "Off\n"; |
| 1873 | break; |
| 1874 | default: |
| 1875 | BUG(); |
| 1876 | level = "Unknown\n"; |
| 1877 | break; |
| 1878 | } |
| 1879 | |
| 1880 | return simple_read_from_buffer(user_buf, count, ppos, level, |
| 1881 | strlen(level)); |
| 1882 | } |
| 1883 | |
| 1884 | static const struct file_operations dapm_bias_fops = { |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 1885 | .open = simple_open, |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 1886 | .read = dapm_bias_read_file, |
| 1887 | .llseek = default_llseek, |
| 1888 | }; |
| 1889 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1890 | void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, |
| 1891 | struct dentry *parent) |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1892 | { |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1893 | struct dentry *d; |
| 1894 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1895 | dapm->debugfs_dapm = debugfs_create_dir("dapm", parent); |
| 1896 | |
| 1897 | if (!dapm->debugfs_dapm) { |
Liam Girdwood | f1e90af | 2012-03-06 18:13:25 +0000 | [diff] [blame] | 1898 | dev_warn(dapm->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1899 | "ASoC: Failed to create DAPM debugfs directory\n"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1900 | return; |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1901 | } |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1902 | |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 1903 | d = debugfs_create_file("bias_level", 0444, |
| 1904 | dapm->debugfs_dapm, dapm, |
| 1905 | &dapm_bias_fops); |
| 1906 | if (!d) |
| 1907 | dev_warn(dapm->dev, |
| 1908 | "ASoC: Failed to create bias level debugfs file\n"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1909 | } |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1910 | |
| 1911 | static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w) |
| 1912 | { |
| 1913 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 1914 | struct dentry *d; |
| 1915 | |
| 1916 | if (!dapm->debugfs_dapm || !w->name) |
| 1917 | return; |
| 1918 | |
| 1919 | d = debugfs_create_file(w->name, 0444, |
| 1920 | dapm->debugfs_dapm, w, |
| 1921 | &dapm_widget_power_fops); |
| 1922 | if (!d) |
| 1923 | dev_warn(w->dapm->dev, |
| 1924 | "ASoC: Failed to create %s debugfs file\n", |
| 1925 | w->name); |
| 1926 | } |
| 1927 | |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 1928 | static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) |
| 1929 | { |
| 1930 | debugfs_remove_recursive(dapm->debugfs_dapm); |
| 1931 | } |
| 1932 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1933 | #else |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1934 | void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, |
| 1935 | struct dentry *parent) |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1936 | { |
| 1937 | } |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1938 | |
| 1939 | static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w) |
| 1940 | { |
| 1941 | } |
| 1942 | |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 1943 | static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) |
| 1944 | { |
| 1945 | } |
| 1946 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1947 | #endif |
| 1948 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1949 | /* test and update the power status of a mux widget */ |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 1950 | static int soc_dapm_mux_update_power(struct snd_soc_dapm_context *dapm, |
Liam Girdwood | 40f02cd | 2012-02-06 16:05:14 +0000 | [diff] [blame] | 1951 | struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1952 | { |
| 1953 | struct snd_soc_dapm_path *path; |
| 1954 | int found = 0; |
| 1955 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1956 | /* find dapm widget path assoc with kcontrol */ |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 1957 | list_for_each_entry(path, &dapm->card->paths, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1958 | if (path->kcontrol != kcontrol) |
| 1959 | continue; |
| 1960 | |
Richard Zhao | cb01e2b | 2008-10-07 08:05:20 +0800 | [diff] [blame] | 1961 | if (!path->name || !e->texts[mux]) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1962 | continue; |
| 1963 | |
| 1964 | found = 1; |
| 1965 | /* we now need to match the string in the enum to the path */ |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1966 | if (!(strcmp(path->name, e->texts[mux]))) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1967 | path->connect = 1; /* new connection */ |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 1968 | dapm_mark_dirty(path->source, "mux connection"); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1969 | } else { |
| 1970 | if (path->connect) |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 1971 | dapm_mark_dirty(path->source, |
| 1972 | "mux disconnection"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1973 | path->connect = 0; /* old connection must be powered down */ |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1974 | } |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 1975 | dapm_mark_dirty(path->sink, "mux change"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1976 | } |
| 1977 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 1978 | if (found) |
| 1979 | dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1980 | |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 1981 | return found; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1982 | } |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 1983 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 1984 | int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_context *dapm, |
| 1985 | struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e) |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 1986 | { |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 1987 | struct snd_soc_card *card = dapm->card; |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 1988 | int ret; |
| 1989 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 1990 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 1991 | ret = soc_dapm_mux_update_power(dapm, kcontrol, mux, e); |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 1992 | mutex_unlock(&card->dapm_mutex); |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 1993 | if (ret > 0) |
Lars-Peter Clausen | c3f48ae | 2013-07-24 15:27:36 +0200 | [diff] [blame] | 1994 | soc_dpcm_runtime_update(card); |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 1995 | return ret; |
| 1996 | } |
Liam Girdwood | 40f02cd | 2012-02-06 16:05:14 +0000 | [diff] [blame] | 1997 | EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1998 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1999 | /* test and update the power status of a mixer or switch widget */ |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2000 | static int soc_dapm_mixer_update_power(struct snd_soc_dapm_context *dapm, |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 2001 | struct snd_kcontrol *kcontrol, int connect) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2002 | { |
| 2003 | struct snd_soc_dapm_path *path; |
| 2004 | int found = 0; |
| 2005 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2006 | /* find dapm widget path assoc with kcontrol */ |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2007 | list_for_each_entry(path, &dapm->card->paths, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2008 | if (path->kcontrol != kcontrol) |
| 2009 | continue; |
| 2010 | |
| 2011 | /* found, now check type */ |
| 2012 | found = 1; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 2013 | path->connect = connect; |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 2014 | dapm_mark_dirty(path->source, "mixer connection"); |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2015 | dapm_mark_dirty(path->sink, "mixer update"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2016 | } |
| 2017 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2018 | if (found) |
| 2019 | dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2020 | |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2021 | return found; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2022 | } |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 2023 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2024 | int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_context *dapm, |
| 2025 | struct snd_kcontrol *kcontrol, int connect) |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 2026 | { |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2027 | struct snd_soc_card *card = dapm->card; |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 2028 | int ret; |
| 2029 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 2030 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2031 | ret = soc_dapm_mixer_update_power(dapm, kcontrol, connect); |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 2032 | mutex_unlock(&card->dapm_mutex); |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2033 | if (ret > 0) |
Lars-Peter Clausen | c3f48ae | 2013-07-24 15:27:36 +0200 | [diff] [blame] | 2034 | soc_dpcm_runtime_update(card); |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 2035 | return ret; |
| 2036 | } |
Liam Girdwood | 40f02cd | 2012-02-06 16:05:14 +0000 | [diff] [blame] | 2037 | EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2038 | |
| 2039 | /* show dapm widget status in sys fs */ |
| 2040 | static ssize_t dapm_widget_show(struct device *dev, |
| 2041 | struct device_attribute *attr, char *buf) |
| 2042 | { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 2043 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2044 | struct snd_soc_codec *codec =rtd->codec; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2045 | struct snd_soc_dapm_widget *w; |
| 2046 | int count = 0; |
| 2047 | char *state = "not set"; |
| 2048 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2049 | list_for_each_entry(w, &codec->card->widgets, list) { |
| 2050 | if (w->dapm != &codec->dapm) |
| 2051 | continue; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2052 | |
| 2053 | /* only display widgets that burnm power */ |
| 2054 | switch (w->id) { |
| 2055 | case snd_soc_dapm_hp: |
| 2056 | case snd_soc_dapm_mic: |
| 2057 | case snd_soc_dapm_spk: |
| 2058 | case snd_soc_dapm_line: |
| 2059 | case snd_soc_dapm_micbias: |
| 2060 | case snd_soc_dapm_dac: |
| 2061 | case snd_soc_dapm_adc: |
| 2062 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 2063 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2064 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 2065 | case snd_soc_dapm_mixer_named_ctl: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 2066 | case snd_soc_dapm_supply: |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 2067 | case snd_soc_dapm_regulator_supply: |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 2068 | case snd_soc_dapm_clock_supply: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2069 | if (w->name) |
| 2070 | count += sprintf(buf + count, "%s: %s\n", |
| 2071 | w->name, w->power ? "On":"Off"); |
| 2072 | break; |
| 2073 | default: |
| 2074 | break; |
| 2075 | } |
| 2076 | } |
| 2077 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2078 | switch (codec->dapm.bias_level) { |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 2079 | case SND_SOC_BIAS_ON: |
| 2080 | state = "On"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2081 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 2082 | case SND_SOC_BIAS_PREPARE: |
| 2083 | state = "Prepare"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2084 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 2085 | case SND_SOC_BIAS_STANDBY: |
| 2086 | state = "Standby"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2087 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 2088 | case SND_SOC_BIAS_OFF: |
| 2089 | state = "Off"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2090 | break; |
| 2091 | } |
| 2092 | count += sprintf(buf + count, "PM State: %s\n", state); |
| 2093 | |
| 2094 | return count; |
| 2095 | } |
| 2096 | |
| 2097 | static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL); |
| 2098 | |
| 2099 | int snd_soc_dapm_sys_add(struct device *dev) |
| 2100 | { |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 2101 | return device_create_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | static void snd_soc_dapm_sys_remove(struct device *dev) |
| 2105 | { |
Mark Brown | aef9084 | 2009-05-16 17:53:16 +0100 | [diff] [blame] | 2106 | device_remove_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2107 | } |
| 2108 | |
Lars-Peter Clausen | 8872293 | 2013-06-14 13:16:53 +0200 | [diff] [blame] | 2109 | static void dapm_free_path(struct snd_soc_dapm_path *path) |
| 2110 | { |
| 2111 | list_del(&path->list_sink); |
| 2112 | list_del(&path->list_source); |
| 2113 | list_del(&path->list); |
Lars-Peter Clausen | 8872293 | 2013-06-14 13:16:53 +0200 | [diff] [blame] | 2114 | kfree(path); |
| 2115 | } |
| 2116 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2117 | /* free all dapm widgets and resources */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2118 | static void dapm_free_widgets(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2119 | { |
| 2120 | struct snd_soc_dapm_widget *w, *next_w; |
| 2121 | struct snd_soc_dapm_path *p, *next_p; |
| 2122 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2123 | list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) { |
| 2124 | if (w->dapm != dapm) |
| 2125 | continue; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2126 | list_del(&w->list); |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 2127 | /* |
| 2128 | * remove source and sink paths associated to this widget. |
| 2129 | * While removing the path, remove reference to it from both |
| 2130 | * source and sink widgets so that path is removed only once. |
| 2131 | */ |
Lars-Peter Clausen | 8872293 | 2013-06-14 13:16:53 +0200 | [diff] [blame] | 2132 | list_for_each_entry_safe(p, next_p, &w->sources, list_sink) |
| 2133 | dapm_free_path(p); |
| 2134 | |
| 2135 | list_for_each_entry_safe(p, next_p, &w->sinks, list_source) |
| 2136 | dapm_free_path(p); |
| 2137 | |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 2138 | kfree(w->kcontrols); |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2139 | kfree(w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2140 | kfree(w); |
| 2141 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2142 | } |
| 2143 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2144 | static struct snd_soc_dapm_widget *dapm_find_widget( |
| 2145 | struct snd_soc_dapm_context *dapm, const char *pin, |
| 2146 | bool search_other_contexts) |
| 2147 | { |
| 2148 | struct snd_soc_dapm_widget *w; |
| 2149 | struct snd_soc_dapm_widget *fallback = NULL; |
| 2150 | |
| 2151 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 2152 | if (!strcmp(w->name, pin)) { |
| 2153 | if (w->dapm == dapm) |
| 2154 | return w; |
| 2155 | else |
| 2156 | fallback = w; |
| 2157 | } |
| 2158 | } |
| 2159 | |
| 2160 | if (search_other_contexts) |
| 2161 | return fallback; |
| 2162 | |
| 2163 | return NULL; |
| 2164 | } |
| 2165 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2166 | static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm, |
Mark Brown | 1649923 | 2009-01-07 18:25:13 +0000 | [diff] [blame] | 2167 | const char *pin, int status) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2168 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2169 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2170 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2171 | if (!w) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2172 | dev_err(dapm->dev, "ASoC: DAPM unknown pin %s\n", pin); |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2173 | return -EINVAL; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2174 | } |
| 2175 | |
Mark Brown | 1a8b2d9 | 2012-02-16 11:50:07 -0800 | [diff] [blame] | 2176 | if (w->connected != status) |
| 2177 | dapm_mark_dirty(w, "pin configuration"); |
| 2178 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2179 | w->connected = status; |
| 2180 | if (status == 0) |
| 2181 | w->force = 0; |
Mark Brown | 0d86733 | 2011-04-06 11:38:14 +0900 | [diff] [blame] | 2182 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2183 | return 0; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2184 | } |
| 2185 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2186 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2187 | * snd_soc_dapm_sync - scan and power dapm paths |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2188 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2189 | * |
| 2190 | * Walks all dapm audio paths and powers widgets according to their |
| 2191 | * stream or path usage. |
| 2192 | * |
| 2193 | * Returns 0 for success. |
| 2194 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2195 | int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2196 | { |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2197 | int ret; |
| 2198 | |
Mark Brown | 4f4c007 | 2011-10-07 14:29:19 +0100 | [diff] [blame] | 2199 | /* |
| 2200 | * Suppress early reports (eg, jacks syncing their state) to avoid |
| 2201 | * silly DAPM runs during card startup. |
| 2202 | */ |
| 2203 | if (!dapm->card || !dapm->card->instantiated) |
| 2204 | return 0; |
| 2205 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 2206 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2207 | ret = dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
| 2208 | mutex_unlock(&dapm->card->dapm_mutex); |
| 2209 | return ret; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2210 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2211 | EXPORT_SYMBOL_GPL(snd_soc_dapm_sync); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2212 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2213 | static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm, |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 2214 | const struct snd_soc_dapm_route *route) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2215 | { |
| 2216 | struct snd_soc_dapm_path *path; |
| 2217 | struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w; |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2218 | struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2219 | const char *sink; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 2220 | const char *control = route->control; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2221 | const char *source; |
| 2222 | char prefixed_sink[80]; |
| 2223 | char prefixed_source[80]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2224 | int ret = 0; |
| 2225 | |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 2226 | if (dapm->codec && dapm->codec->name_prefix) { |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2227 | snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s", |
| 2228 | dapm->codec->name_prefix, route->sink); |
| 2229 | sink = prefixed_sink; |
| 2230 | snprintf(prefixed_source, sizeof(prefixed_source), "%s %s", |
| 2231 | dapm->codec->name_prefix, route->source); |
| 2232 | source = prefixed_source; |
| 2233 | } else { |
| 2234 | sink = route->sink; |
| 2235 | source = route->source; |
| 2236 | } |
| 2237 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2238 | /* |
| 2239 | * find src and dest widgets over all widgets but favor a widget from |
| 2240 | * current DAPM context |
| 2241 | */ |
| 2242 | list_for_each_entry(w, &dapm->card->widgets, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2243 | if (!wsink && !(strcmp(w->name, sink))) { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2244 | wtsink = w; |
| 2245 | if (w->dapm == dapm) |
| 2246 | wsink = w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2247 | continue; |
| 2248 | } |
| 2249 | if (!wsource && !(strcmp(w->name, source))) { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2250 | wtsource = w; |
| 2251 | if (w->dapm == dapm) |
| 2252 | wsource = w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2253 | } |
| 2254 | } |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2255 | /* use widget from another DAPM context if not found from this */ |
| 2256 | if (!wsink) |
| 2257 | wsink = wtsink; |
| 2258 | if (!wsource) |
| 2259 | wsource = wtsource; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2260 | |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2261 | if (wsource == NULL) { |
| 2262 | dev_err(dapm->dev, "ASoC: no source widget found for %s\n", |
| 2263 | route->source); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2264 | return -ENODEV; |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2265 | } |
| 2266 | if (wsink == NULL) { |
| 2267 | dev_err(dapm->dev, "ASoC: no sink widget found for %s\n", |
| 2268 | route->sink); |
| 2269 | return -ENODEV; |
| 2270 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2271 | |
| 2272 | path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL); |
| 2273 | if (!path) |
| 2274 | return -ENOMEM; |
| 2275 | |
| 2276 | path->source = wsource; |
| 2277 | path->sink = wsink; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 2278 | path->connected = route->connected; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2279 | INIT_LIST_HEAD(&path->list); |
| 2280 | INIT_LIST_HEAD(&path->list_source); |
| 2281 | INIT_LIST_HEAD(&path->list_sink); |
| 2282 | |
| 2283 | /* check for external widgets */ |
| 2284 | if (wsink->id == snd_soc_dapm_input) { |
| 2285 | if (wsource->id == snd_soc_dapm_micbias || |
| 2286 | wsource->id == snd_soc_dapm_mic || |
Rongrong Cao | 087d53a | 2009-07-10 20:13:30 +0100 | [diff] [blame] | 2287 | wsource->id == snd_soc_dapm_line || |
| 2288 | wsource->id == snd_soc_dapm_output) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2289 | wsink->ext = 1; |
| 2290 | } |
| 2291 | if (wsource->id == snd_soc_dapm_output) { |
| 2292 | if (wsink->id == snd_soc_dapm_spk || |
| 2293 | wsink->id == snd_soc_dapm_hp || |
Seth Forshee | 1e39221 | 2007-04-16 15:36:42 +0200 | [diff] [blame] | 2294 | wsink->id == snd_soc_dapm_line || |
| 2295 | wsink->id == snd_soc_dapm_input) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2296 | wsource->ext = 1; |
| 2297 | } |
| 2298 | |
| 2299 | /* connect static paths */ |
| 2300 | if (control == NULL) { |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 2301 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2302 | list_add(&path->list_sink, &wsink->sources); |
| 2303 | list_add(&path->list_source, &wsource->sinks); |
| 2304 | path->connect = 1; |
| 2305 | return 0; |
| 2306 | } |
| 2307 | |
| 2308 | /* connect dynamic paths */ |
Lu Guanqun | dc2bea6 | 2011-04-20 16:00:36 +0800 | [diff] [blame] | 2309 | switch (wsink->id) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2310 | case snd_soc_dapm_adc: |
| 2311 | case snd_soc_dapm_dac: |
| 2312 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 2313 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2314 | case snd_soc_dapm_input: |
| 2315 | case snd_soc_dapm_output: |
Mark Brown | 1ab97c8 | 2011-11-27 16:21:51 +0000 | [diff] [blame] | 2316 | case snd_soc_dapm_siggen: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2317 | case snd_soc_dapm_micbias: |
| 2318 | case snd_soc_dapm_vmid: |
| 2319 | case snd_soc_dapm_pre: |
| 2320 | case snd_soc_dapm_post: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 2321 | case snd_soc_dapm_supply: |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 2322 | case snd_soc_dapm_regulator_supply: |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 2323 | case snd_soc_dapm_clock_supply: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 2324 | case snd_soc_dapm_aif_in: |
| 2325 | case snd_soc_dapm_aif_out: |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 2326 | case snd_soc_dapm_dai_in: |
| 2327 | case snd_soc_dapm_dai_out: |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 2328 | case snd_soc_dapm_dai_link: |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 2329 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2330 | list_add(&path->list_sink, &wsink->sources); |
| 2331 | list_add(&path->list_source, &wsource->sinks); |
| 2332 | path->connect = 1; |
| 2333 | return 0; |
| 2334 | case snd_soc_dapm_mux: |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 2335 | case snd_soc_dapm_virt_mux: |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2336 | case snd_soc_dapm_value_mux: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2337 | ret = dapm_connect_mux(dapm, wsource, wsink, path, control, |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 2338 | &wsink->kcontrol_news[0]); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2339 | if (ret != 0) |
| 2340 | goto err; |
| 2341 | break; |
| 2342 | case snd_soc_dapm_switch: |
| 2343 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 2344 | case snd_soc_dapm_mixer_named_ctl: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2345 | ret = dapm_connect_mixer(dapm, wsource, wsink, path, control); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2346 | if (ret != 0) |
| 2347 | goto err; |
| 2348 | break; |
| 2349 | case snd_soc_dapm_hp: |
| 2350 | case snd_soc_dapm_mic: |
| 2351 | case snd_soc_dapm_line: |
| 2352 | case snd_soc_dapm_spk: |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 2353 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2354 | list_add(&path->list_sink, &wsink->sources); |
| 2355 | list_add(&path->list_source, &wsource->sinks); |
| 2356 | path->connect = 0; |
| 2357 | return 0; |
| 2358 | } |
Mark Brown | fabd038 | 2012-07-05 17:20:06 +0100 | [diff] [blame] | 2359 | |
| 2360 | dapm_mark_dirty(wsource, "Route added"); |
| 2361 | dapm_mark_dirty(wsink, "Route added"); |
| 2362 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2363 | return 0; |
| 2364 | |
| 2365 | err: |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2366 | dev_warn(dapm->dev, "ASoC: no dapm match for %s --> %s --> %s\n", |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2367 | source, control, sink); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2368 | kfree(path); |
| 2369 | return ret; |
| 2370 | } |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2371 | |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2372 | static int snd_soc_dapm_del_route(struct snd_soc_dapm_context *dapm, |
| 2373 | const struct snd_soc_dapm_route *route) |
| 2374 | { |
| 2375 | struct snd_soc_dapm_path *path, *p; |
| 2376 | const char *sink; |
| 2377 | const char *source; |
| 2378 | char prefixed_sink[80]; |
| 2379 | char prefixed_source[80]; |
| 2380 | |
| 2381 | if (route->control) { |
| 2382 | dev_err(dapm->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2383 | "ASoC: Removal of routes with controls not supported\n"); |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2384 | return -EINVAL; |
| 2385 | } |
| 2386 | |
| 2387 | if (dapm->codec && dapm->codec->name_prefix) { |
| 2388 | snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s", |
| 2389 | dapm->codec->name_prefix, route->sink); |
| 2390 | sink = prefixed_sink; |
| 2391 | snprintf(prefixed_source, sizeof(prefixed_source), "%s %s", |
| 2392 | dapm->codec->name_prefix, route->source); |
| 2393 | source = prefixed_source; |
| 2394 | } else { |
| 2395 | sink = route->sink; |
| 2396 | source = route->source; |
| 2397 | } |
| 2398 | |
| 2399 | path = NULL; |
| 2400 | list_for_each_entry(p, &dapm->card->paths, list) { |
| 2401 | if (strcmp(p->source->name, source) != 0) |
| 2402 | continue; |
| 2403 | if (strcmp(p->sink->name, sink) != 0) |
| 2404 | continue; |
| 2405 | path = p; |
| 2406 | break; |
| 2407 | } |
| 2408 | |
| 2409 | if (path) { |
| 2410 | dapm_mark_dirty(path->source, "Route removed"); |
| 2411 | dapm_mark_dirty(path->sink, "Route removed"); |
| 2412 | |
Lars-Peter Clausen | 8872293 | 2013-06-14 13:16:53 +0200 | [diff] [blame] | 2413 | dapm_free_path(path); |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2414 | } else { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2415 | dev_warn(dapm->dev, "ASoC: Route %s->%s does not exist\n", |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2416 | source, sink); |
| 2417 | } |
| 2418 | |
| 2419 | return 0; |
| 2420 | } |
| 2421 | |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2422 | /** |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2423 | * snd_soc_dapm_add_routes - Add routes between DAPM widgets |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2424 | * @dapm: DAPM context |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2425 | * @route: audio routes |
| 2426 | * @num: number of routes |
| 2427 | * |
| 2428 | * Connects 2 dapm widgets together via a named audio path. The sink is |
| 2429 | * the widget receiving the audio signal, whilst the source is the sender |
| 2430 | * of the audio signal. |
| 2431 | * |
| 2432 | * Returns 0 for success else error. On error all resources can be freed |
| 2433 | * with a call to snd_soc_card_free(). |
| 2434 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2435 | int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm, |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2436 | const struct snd_soc_dapm_route *route, int num) |
| 2437 | { |
Mark Brown | 62d4a4b | 2012-06-22 12:21:49 +0100 | [diff] [blame] | 2438 | int i, r, ret = 0; |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2439 | |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2440 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2441 | for (i = 0; i < num; i++) { |
Mark Brown | 62d4a4b | 2012-06-22 12:21:49 +0100 | [diff] [blame] | 2442 | r = snd_soc_dapm_add_route(dapm, route); |
| 2443 | if (r < 0) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2444 | dev_err(dapm->dev, "ASoC: Failed to add route %s -> %s -> %s\n", |
| 2445 | route->source, |
| 2446 | route->control ? route->control : "direct", |
| 2447 | route->sink); |
Mark Brown | 62d4a4b | 2012-06-22 12:21:49 +0100 | [diff] [blame] | 2448 | ret = r; |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2449 | } |
| 2450 | route++; |
| 2451 | } |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2452 | mutex_unlock(&dapm->card->dapm_mutex); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2453 | |
Dan Carpenter | 60884c2 | 2012-04-13 22:25:43 +0300 | [diff] [blame] | 2454 | return ret; |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2455 | } |
| 2456 | EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes); |
| 2457 | |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2458 | /** |
| 2459 | * snd_soc_dapm_del_routes - Remove routes between DAPM widgets |
| 2460 | * @dapm: DAPM context |
| 2461 | * @route: audio routes |
| 2462 | * @num: number of routes |
| 2463 | * |
| 2464 | * Removes routes from the DAPM context. |
| 2465 | */ |
| 2466 | int snd_soc_dapm_del_routes(struct snd_soc_dapm_context *dapm, |
| 2467 | const struct snd_soc_dapm_route *route, int num) |
| 2468 | { |
| 2469 | int i, ret = 0; |
| 2470 | |
| 2471 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); |
| 2472 | for (i = 0; i < num; i++) { |
| 2473 | snd_soc_dapm_del_route(dapm, route); |
| 2474 | route++; |
| 2475 | } |
| 2476 | mutex_unlock(&dapm->card->dapm_mutex); |
| 2477 | |
| 2478 | return ret; |
| 2479 | } |
| 2480 | EXPORT_SYMBOL_GPL(snd_soc_dapm_del_routes); |
| 2481 | |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2482 | static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm, |
| 2483 | const struct snd_soc_dapm_route *route) |
| 2484 | { |
| 2485 | struct snd_soc_dapm_widget *source = dapm_find_widget(dapm, |
| 2486 | route->source, |
| 2487 | true); |
| 2488 | struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm, |
| 2489 | route->sink, |
| 2490 | true); |
| 2491 | struct snd_soc_dapm_path *path; |
| 2492 | int count = 0; |
| 2493 | |
| 2494 | if (!source) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2495 | dev_err(dapm->dev, "ASoC: Unable to find source %s for weak route\n", |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2496 | route->source); |
| 2497 | return -ENODEV; |
| 2498 | } |
| 2499 | |
| 2500 | if (!sink) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2501 | dev_err(dapm->dev, "ASoC: Unable to find sink %s for weak route\n", |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2502 | route->sink); |
| 2503 | return -ENODEV; |
| 2504 | } |
| 2505 | |
| 2506 | if (route->control || route->connected) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2507 | dev_warn(dapm->dev, "ASoC: Ignoring control for weak route %s->%s\n", |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2508 | route->source, route->sink); |
| 2509 | |
| 2510 | list_for_each_entry(path, &source->sinks, list_source) { |
| 2511 | if (path->sink == sink) { |
| 2512 | path->weak = 1; |
| 2513 | count++; |
| 2514 | } |
| 2515 | } |
| 2516 | |
| 2517 | if (count == 0) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2518 | dev_err(dapm->dev, "ASoC: No path found for weak route %s->%s\n", |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2519 | route->source, route->sink); |
| 2520 | if (count > 1) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2521 | dev_warn(dapm->dev, "ASoC: %d paths found for weak route %s->%s\n", |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2522 | count, route->source, route->sink); |
| 2523 | |
| 2524 | return 0; |
| 2525 | } |
| 2526 | |
| 2527 | /** |
| 2528 | * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak |
| 2529 | * @dapm: DAPM context |
| 2530 | * @route: audio routes |
| 2531 | * @num: number of routes |
| 2532 | * |
| 2533 | * Mark existing routes matching those specified in the passed array |
| 2534 | * as being weak, meaning that they are ignored for the purpose of |
| 2535 | * power decisions. The main intended use case is for sidetone paths |
| 2536 | * which couple audio between other independent paths if they are both |
| 2537 | * active in order to make the combination work better at the user |
| 2538 | * level but which aren't intended to be "used". |
| 2539 | * |
| 2540 | * Note that CODEC drivers should not use this as sidetone type paths |
| 2541 | * can frequently also be used as bypass paths. |
| 2542 | */ |
| 2543 | int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm, |
| 2544 | const struct snd_soc_dapm_route *route, int num) |
| 2545 | { |
| 2546 | int i, err; |
| 2547 | int ret = 0; |
| 2548 | |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2549 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2550 | for (i = 0; i < num; i++) { |
| 2551 | err = snd_soc_dapm_weak_route(dapm, route); |
| 2552 | if (err) |
| 2553 | ret = err; |
| 2554 | route++; |
| 2555 | } |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2556 | mutex_unlock(&dapm->card->dapm_mutex); |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2557 | |
| 2558 | return ret; |
| 2559 | } |
| 2560 | EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes); |
| 2561 | |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2562 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2563 | * snd_soc_dapm_new_widgets - add new dapm widgets |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2564 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2565 | * |
| 2566 | * Checks the codec for any new dapm widgets and creates them if found. |
| 2567 | * |
| 2568 | * Returns 0 for success. |
| 2569 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2570 | int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2571 | { |
| 2572 | struct snd_soc_dapm_widget *w; |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2573 | unsigned int val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2574 | |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2575 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); |
| 2576 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2577 | list_for_each_entry(w, &dapm->card->widgets, list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2578 | { |
| 2579 | if (w->new) |
| 2580 | continue; |
| 2581 | |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 2582 | if (w->num_kcontrols) { |
| 2583 | w->kcontrols = kzalloc(w->num_kcontrols * |
| 2584 | sizeof(struct snd_kcontrol *), |
| 2585 | GFP_KERNEL); |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2586 | if (!w->kcontrols) { |
| 2587 | mutex_unlock(&dapm->card->dapm_mutex); |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 2588 | return -ENOMEM; |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2589 | } |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 2590 | } |
| 2591 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2592 | switch(w->id) { |
| 2593 | case snd_soc_dapm_switch: |
| 2594 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 2595 | case snd_soc_dapm_mixer_named_ctl: |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 2596 | dapm_new_mixer(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2597 | break; |
| 2598 | case snd_soc_dapm_mux: |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 2599 | case snd_soc_dapm_virt_mux: |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2600 | case snd_soc_dapm_value_mux: |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 2601 | dapm_new_mux(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2602 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2603 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 2604 | case snd_soc_dapm_out_drv: |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 2605 | dapm_new_pga(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2606 | break; |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 2607 | default: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2608 | break; |
| 2609 | } |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2610 | |
| 2611 | /* Read the initial power state from the device */ |
| 2612 | if (w->reg >= 0) { |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 2613 | val = soc_widget_read(w, w->reg); |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2614 | val &= 1 << w->shift; |
| 2615 | if (w->invert) |
| 2616 | val = !val; |
| 2617 | |
| 2618 | if (val) |
| 2619 | w->power = 1; |
| 2620 | } |
| 2621 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2622 | w->new = 1; |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 2623 | |
Mark Brown | 7508b12 | 2011-10-05 12:09:12 +0100 | [diff] [blame] | 2624 | dapm_mark_dirty(w, "new widget"); |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 2625 | dapm_debugfs_add_widget(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2626 | } |
| 2627 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2628 | dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2629 | mutex_unlock(&dapm->card->dapm_mutex); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2630 | return 0; |
| 2631 | } |
| 2632 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets); |
| 2633 | |
| 2634 | /** |
| 2635 | * snd_soc_dapm_get_volsw - dapm mixer get callback |
| 2636 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2637 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2638 | * |
| 2639 | * Callback to get the value of a dapm mixer control. |
| 2640 | * |
| 2641 | * Returns 0 for success. |
| 2642 | */ |
| 2643 | int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, |
| 2644 | struct snd_ctl_elem_value *ucontrol) |
| 2645 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2646 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2647 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2648 | struct soc_mixer_control *mc = |
| 2649 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2650 | unsigned int reg = mc->reg; |
| 2651 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2652 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2653 | unsigned int mask = (1 << fls(max)) - 1; |
Benoît Thébaudeau | da602ab | 2012-07-03 20:18:17 +0200 | [diff] [blame] | 2654 | unsigned int invert = mc->invert; |
| 2655 | |
| 2656 | if (snd_soc_volsw_is_stereo(mc)) |
| 2657 | dev_warn(widget->dapm->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2658 | "ASoC: Control '%s' is stereo, which is not supported\n", |
Benoît Thébaudeau | da602ab | 2012-07-03 20:18:17 +0200 | [diff] [blame] | 2659 | kcontrol->id.name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2660 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2661 | ucontrol->value.integer.value[0] = |
| 2662 | (snd_soc_read(widget->codec, reg) >> shift) & mask; |
Benoît Thébaudeau | da602ab | 2012-07-03 20:18:17 +0200 | [diff] [blame] | 2663 | if (invert) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2664 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2665 | max - ucontrol->value.integer.value[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2666 | |
| 2667 | return 0; |
| 2668 | } |
| 2669 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw); |
| 2670 | |
| 2671 | /** |
| 2672 | * snd_soc_dapm_put_volsw - dapm mixer set callback |
| 2673 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2674 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2675 | * |
| 2676 | * Callback to set the value of a dapm mixer control. |
| 2677 | * |
| 2678 | * Returns 0 for success. |
| 2679 | */ |
| 2680 | int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, |
| 2681 | struct snd_ctl_elem_value *ucontrol) |
| 2682 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2683 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2684 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2685 | struct snd_soc_codec *codec = widget->codec; |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2686 | struct snd_soc_card *card = codec->card; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2687 | struct soc_mixer_control *mc = |
| 2688 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2689 | unsigned int reg = mc->reg; |
| 2690 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2691 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2692 | unsigned int mask = (1 << fls(max)) - 1; |
| 2693 | unsigned int invert = mc->invert; |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2694 | unsigned int val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2695 | int connect, change; |
| 2696 | struct snd_soc_dapm_update update; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2697 | |
Benoît Thébaudeau | da602ab | 2012-07-03 20:18:17 +0200 | [diff] [blame] | 2698 | if (snd_soc_volsw_is_stereo(mc)) |
| 2699 | dev_warn(widget->dapm->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2700 | "ASoC: Control '%s' is stereo, which is not supported\n", |
Benoît Thébaudeau | da602ab | 2012-07-03 20:18:17 +0200 | [diff] [blame] | 2701 | kcontrol->id.name); |
| 2702 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2703 | val = (ucontrol->value.integer.value[0] & mask); |
Benoît Thébaudeau | 8a72071 | 2012-06-18 22:41:28 +0200 | [diff] [blame] | 2704 | connect = !!val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2705 | |
| 2706 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2707 | val = max - val; |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2708 | mask = mask << shift; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2709 | val = val << shift; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2710 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 2711 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2712 | |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2713 | change = snd_soc_test_bits(widget->codec, reg, mask, val); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2714 | if (change) { |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2715 | update.kcontrol = kcontrol; |
| 2716 | update.reg = reg; |
| 2717 | update.mask = mask; |
| 2718 | update.val = val; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 2719 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2720 | widget->dapm->update = &update; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2721 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2722 | soc_dapm_mixer_update_power(widget->dapm, kcontrol, connect); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2723 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2724 | widget->dapm->update = NULL; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 2725 | } |
| 2726 | |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2727 | mutex_unlock(&card->dapm_mutex); |
Lars-Peter Clausen | 56a6783 | 2013-07-24 15:27:35 +0200 | [diff] [blame] | 2728 | return change; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2729 | } |
| 2730 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw); |
| 2731 | |
| 2732 | /** |
| 2733 | * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback |
| 2734 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2735 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2736 | * |
| 2737 | * Callback to get the value of a dapm enumerated double mixer control. |
| 2738 | * |
| 2739 | * Returns 0 for success. |
| 2740 | */ |
| 2741 | int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, |
| 2742 | struct snd_ctl_elem_value *ucontrol) |
| 2743 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2744 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2745 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2746 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 2747 | unsigned int val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2748 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2749 | val = snd_soc_read(widget->codec, e->reg); |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 2750 | ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & e->mask; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2751 | if (e->shift_l != e->shift_r) |
| 2752 | ucontrol->value.enumerated.item[1] = |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 2753 | (val >> e->shift_r) & e->mask; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2754 | |
| 2755 | return 0; |
| 2756 | } |
| 2757 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double); |
| 2758 | |
| 2759 | /** |
| 2760 | * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback |
| 2761 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2762 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2763 | * |
| 2764 | * Callback to set the value of a dapm enumerated double mixer control. |
| 2765 | * |
| 2766 | * Returns 0 for success. |
| 2767 | */ |
| 2768 | int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, |
| 2769 | struct snd_ctl_elem_value *ucontrol) |
| 2770 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2771 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2772 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2773 | struct snd_soc_codec *codec = widget->codec; |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2774 | struct snd_soc_card *card = codec->card; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2775 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2776 | unsigned int val, mux, change; |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 2777 | unsigned int mask; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2778 | struct snd_soc_dapm_update update; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2779 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2780 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2781 | return -EINVAL; |
| 2782 | mux = ucontrol->value.enumerated.item[0]; |
| 2783 | val = mux << e->shift_l; |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 2784 | mask = e->mask << e->shift_l; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2785 | if (e->shift_l != e->shift_r) { |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2786 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2787 | return -EINVAL; |
| 2788 | val |= ucontrol->value.enumerated.item[1] << e->shift_r; |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 2789 | mask |= e->mask << e->shift_r; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2790 | } |
| 2791 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 2792 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2793 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2794 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2795 | if (change) { |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2796 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2797 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2798 | update.kcontrol = kcontrol; |
| 2799 | update.reg = e->reg; |
| 2800 | update.mask = mask; |
| 2801 | update.val = val; |
| 2802 | widget->dapm->update = &update; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2803 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2804 | soc_dapm_mux_update_power(widget->dapm, kcontrol, mux, e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2805 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2806 | widget->dapm->update = NULL; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2807 | } |
| 2808 | |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2809 | mutex_unlock(&card->dapm_mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2810 | return change; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2811 | } |
| 2812 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double); |
| 2813 | |
| 2814 | /** |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2815 | * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux |
| 2816 | * @kcontrol: mixer control |
| 2817 | * @ucontrol: control element information |
| 2818 | * |
| 2819 | * Returns 0 for success. |
| 2820 | */ |
| 2821 | int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol, |
| 2822 | struct snd_ctl_elem_value *ucontrol) |
| 2823 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2824 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2825 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2826 | |
| 2827 | ucontrol->value.enumerated.item[0] = widget->value; |
| 2828 | |
| 2829 | return 0; |
| 2830 | } |
| 2831 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt); |
| 2832 | |
| 2833 | /** |
| 2834 | * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux |
| 2835 | * @kcontrol: mixer control |
| 2836 | * @ucontrol: control element information |
| 2837 | * |
| 2838 | * Returns 0 for success. |
| 2839 | */ |
| 2840 | int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol, |
| 2841 | struct snd_ctl_elem_value *ucontrol) |
| 2842 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2843 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2844 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2845 | struct snd_soc_codec *codec = widget->codec; |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2846 | struct snd_soc_card *card = codec->card; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2847 | struct soc_enum *e = |
| 2848 | (struct soc_enum *)kcontrol->private_value; |
| 2849 | int change; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2850 | |
| 2851 | if (ucontrol->value.enumerated.item[0] >= e->max) |
| 2852 | return -EINVAL; |
| 2853 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 2854 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2855 | |
| 2856 | change = widget->value != ucontrol->value.enumerated.item[0]; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2857 | if (change) { |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2858 | widget->value = ucontrol->value.enumerated.item[0]; |
| 2859 | soc_dapm_mux_update_power(widget->dapm, kcontrol, widget->value, e); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2860 | } |
| 2861 | |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2862 | mutex_unlock(&card->dapm_mutex); |
Lars-Peter Clausen | 56a6783 | 2013-07-24 15:27:35 +0200 | [diff] [blame] | 2863 | return change; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2864 | } |
| 2865 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt); |
| 2866 | |
| 2867 | /** |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2868 | * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get |
| 2869 | * callback |
| 2870 | * @kcontrol: mixer control |
| 2871 | * @ucontrol: control element information |
| 2872 | * |
| 2873 | * Callback to get the value of a dapm semi enumerated double mixer control. |
| 2874 | * |
| 2875 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2876 | * used for handling bitfield coded enumeration for example. |
| 2877 | * |
| 2878 | * Returns 0 for success. |
| 2879 | */ |
| 2880 | int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2881 | struct snd_ctl_elem_value *ucontrol) |
| 2882 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2883 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2884 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2885 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2886 | unsigned int reg_val, val, mux; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2887 | |
| 2888 | reg_val = snd_soc_read(widget->codec, e->reg); |
| 2889 | val = (reg_val >> e->shift_l) & e->mask; |
| 2890 | for (mux = 0; mux < e->max; mux++) { |
| 2891 | if (val == e->values[mux]) |
| 2892 | break; |
| 2893 | } |
| 2894 | ucontrol->value.enumerated.item[0] = mux; |
| 2895 | if (e->shift_l != e->shift_r) { |
| 2896 | val = (reg_val >> e->shift_r) & e->mask; |
| 2897 | for (mux = 0; mux < e->max; mux++) { |
| 2898 | if (val == e->values[mux]) |
| 2899 | break; |
| 2900 | } |
| 2901 | ucontrol->value.enumerated.item[1] = mux; |
| 2902 | } |
| 2903 | |
| 2904 | return 0; |
| 2905 | } |
| 2906 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double); |
| 2907 | |
| 2908 | /** |
| 2909 | * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set |
| 2910 | * callback |
| 2911 | * @kcontrol: mixer control |
| 2912 | * @ucontrol: control element information |
| 2913 | * |
| 2914 | * Callback to set the value of a dapm semi enumerated double mixer control. |
| 2915 | * |
| 2916 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2917 | * used for handling bitfield coded enumeration for example. |
| 2918 | * |
| 2919 | * Returns 0 for success. |
| 2920 | */ |
| 2921 | int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2922 | struct snd_ctl_elem_value *ucontrol) |
| 2923 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2924 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2925 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2926 | struct snd_soc_codec *codec = widget->codec; |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2927 | struct snd_soc_card *card = codec->card; |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2928 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2929 | unsigned int val, mux, change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2930 | unsigned int mask; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2931 | struct snd_soc_dapm_update update; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2932 | |
| 2933 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 2934 | return -EINVAL; |
| 2935 | mux = ucontrol->value.enumerated.item[0]; |
| 2936 | val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; |
| 2937 | mask = e->mask << e->shift_l; |
| 2938 | if (e->shift_l != e->shift_r) { |
| 2939 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
| 2940 | return -EINVAL; |
| 2941 | val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; |
| 2942 | mask |= e->mask << e->shift_r; |
| 2943 | } |
| 2944 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 2945 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2946 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2947 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2948 | if (change) { |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2949 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2950 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2951 | update.kcontrol = kcontrol; |
| 2952 | update.reg = e->reg; |
| 2953 | update.mask = mask; |
| 2954 | update.val = val; |
| 2955 | widget->dapm->update = &update; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2956 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2957 | soc_dapm_mux_update_power(widget->dapm, kcontrol, mux, e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2958 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame^] | 2959 | widget->dapm->update = NULL; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2960 | } |
| 2961 | |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2962 | mutex_unlock(&card->dapm_mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2963 | return change; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2964 | } |
| 2965 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double); |
| 2966 | |
| 2967 | /** |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2968 | * snd_soc_dapm_info_pin_switch - Info for a pin switch |
| 2969 | * |
| 2970 | * @kcontrol: mixer control |
| 2971 | * @uinfo: control element information |
| 2972 | * |
| 2973 | * Callback to provide information about a pin switch control. |
| 2974 | */ |
| 2975 | int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol, |
| 2976 | struct snd_ctl_elem_info *uinfo) |
| 2977 | { |
| 2978 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 2979 | uinfo->count = 1; |
| 2980 | uinfo->value.integer.min = 0; |
| 2981 | uinfo->value.integer.max = 1; |
| 2982 | |
| 2983 | return 0; |
| 2984 | } |
| 2985 | EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch); |
| 2986 | |
| 2987 | /** |
| 2988 | * snd_soc_dapm_get_pin_switch - Get information for a pin switch |
| 2989 | * |
| 2990 | * @kcontrol: mixer control |
| 2991 | * @ucontrol: Value |
| 2992 | */ |
| 2993 | int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol, |
| 2994 | struct snd_ctl_elem_value *ucontrol) |
| 2995 | { |
Mark Brown | 48a8c39 | 2012-02-14 17:11:15 -0800 | [diff] [blame] | 2996 | struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2997 | const char *pin = (const char *)kcontrol->private_value; |
| 2998 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 2999 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3000 | |
| 3001 | ucontrol->value.integer.value[0] = |
Mark Brown | 48a8c39 | 2012-02-14 17:11:15 -0800 | [diff] [blame] | 3002 | snd_soc_dapm_get_pin_status(&card->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3003 | |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3004 | mutex_unlock(&card->dapm_mutex); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3005 | |
| 3006 | return 0; |
| 3007 | } |
| 3008 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch); |
| 3009 | |
| 3010 | /** |
| 3011 | * snd_soc_dapm_put_pin_switch - Set information for a pin switch |
| 3012 | * |
| 3013 | * @kcontrol: mixer control |
| 3014 | * @ucontrol: Value |
| 3015 | */ |
| 3016 | int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol, |
| 3017 | struct snd_ctl_elem_value *ucontrol) |
| 3018 | { |
Mark Brown | 48a8c39 | 2012-02-14 17:11:15 -0800 | [diff] [blame] | 3019 | struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3020 | const char *pin = (const char *)kcontrol->private_value; |
| 3021 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 3022 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3023 | |
| 3024 | if (ucontrol->value.integer.value[0]) |
Mark Brown | 48a8c39 | 2012-02-14 17:11:15 -0800 | [diff] [blame] | 3025 | snd_soc_dapm_enable_pin(&card->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3026 | else |
Mark Brown | 48a8c39 | 2012-02-14 17:11:15 -0800 | [diff] [blame] | 3027 | snd_soc_dapm_disable_pin(&card->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3028 | |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3029 | mutex_unlock(&card->dapm_mutex); |
| 3030 | |
Mark Brown | 48a8c39 | 2012-02-14 17:11:15 -0800 | [diff] [blame] | 3031 | snd_soc_dapm_sync(&card->dapm); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3032 | return 0; |
| 3033 | } |
| 3034 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch); |
| 3035 | |
Mark Brown | 5ba06fc | 2012-02-16 11:07:13 -0800 | [diff] [blame] | 3036 | static struct snd_soc_dapm_widget * |
| 3037 | snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, |
| 3038 | const struct snd_soc_dapm_widget *widget) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3039 | { |
| 3040 | struct snd_soc_dapm_widget *w; |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 3041 | int ret; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3042 | |
| 3043 | if ((w = dapm_cnew_widget(widget)) == NULL) |
Mark Brown | 5ba06fc | 2012-02-16 11:07:13 -0800 | [diff] [blame] | 3044 | return NULL; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3045 | |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 3046 | switch (w->id) { |
| 3047 | case snd_soc_dapm_regulator_supply: |
Liam Girdwood | a3cc056 | 2012-03-09 17:20:16 +0000 | [diff] [blame] | 3048 | w->regulator = devm_regulator_get(dapm->dev, w->name); |
| 3049 | if (IS_ERR(w->regulator)) { |
| 3050 | ret = PTR_ERR(w->regulator); |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3051 | dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n", |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 3052 | w->name, ret); |
Mark Brown | 5ba06fc | 2012-02-16 11:07:13 -0800 | [diff] [blame] | 3053 | return NULL; |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 3054 | } |
Mark Brown | 8784c77 | 2013-01-10 19:33:47 +0000 | [diff] [blame] | 3055 | |
| 3056 | if (w->invert & SND_SOC_DAPM_REGULATOR_BYPASS) { |
| 3057 | ret = regulator_allow_bypass(w->regulator, true); |
| 3058 | if (ret != 0) |
| 3059 | dev_warn(w->dapm->dev, |
| 3060 | "ASoC: Failed to unbypass %s: %d\n", |
| 3061 | w->name, ret); |
| 3062 | } |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 3063 | break; |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 3064 | case snd_soc_dapm_clock_supply: |
Mark Brown | 165961e | 2012-06-05 10:44:23 +0100 | [diff] [blame] | 3065 | #ifdef CONFIG_CLKDEV_LOOKUP |
Mark Brown | 695594f1 | 2012-06-04 08:14:13 +0100 | [diff] [blame] | 3066 | w->clk = devm_clk_get(dapm->dev, w->name); |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 3067 | if (IS_ERR(w->clk)) { |
| 3068 | ret = PTR_ERR(w->clk); |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3069 | dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n", |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 3070 | w->name, ret); |
| 3071 | return NULL; |
| 3072 | } |
Mark Brown | ec02995 | 2012-06-04 08:16:20 +0100 | [diff] [blame] | 3073 | #else |
| 3074 | return NULL; |
| 3075 | #endif |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 3076 | break; |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 3077 | default: |
| 3078 | break; |
| 3079 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3080 | |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 3081 | if (dapm->codec && dapm->codec->name_prefix) |
Lars-Peter Clausen | 2b58107 | 2013-05-14 11:05:32 +0200 | [diff] [blame] | 3082 | w->name = kasprintf(GFP_KERNEL, "%s %s", |
| 3083 | dapm->codec->name_prefix, widget->name); |
| 3084 | else |
| 3085 | w->name = kasprintf(GFP_KERNEL, "%s", widget->name); |
| 3086 | |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 3087 | if (w->name == NULL) { |
| 3088 | kfree(w); |
Mark Brown | 5ba06fc | 2012-02-16 11:07:13 -0800 | [diff] [blame] | 3089 | return NULL; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 3090 | } |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 3091 | |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 3092 | switch (w->id) { |
| 3093 | case snd_soc_dapm_switch: |
| 3094 | case snd_soc_dapm_mixer: |
| 3095 | case snd_soc_dapm_mixer_named_ctl: |
| 3096 | w->power_check = dapm_generic_check_power; |
| 3097 | break; |
| 3098 | case snd_soc_dapm_mux: |
| 3099 | case snd_soc_dapm_virt_mux: |
| 3100 | case snd_soc_dapm_value_mux: |
| 3101 | w->power_check = dapm_generic_check_power; |
| 3102 | break; |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 3103 | case snd_soc_dapm_dai_out: |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 3104 | w->power_check = dapm_adc_check_power; |
| 3105 | break; |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 3106 | case snd_soc_dapm_dai_in: |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 3107 | w->power_check = dapm_dac_check_power; |
| 3108 | break; |
Mark Brown | 63c69a6 | 2013-07-18 22:03:01 +0100 | [diff] [blame] | 3109 | case snd_soc_dapm_adc: |
| 3110 | case snd_soc_dapm_aif_out: |
| 3111 | case snd_soc_dapm_dac: |
| 3112 | case snd_soc_dapm_aif_in: |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 3113 | case snd_soc_dapm_pga: |
| 3114 | case snd_soc_dapm_out_drv: |
| 3115 | case snd_soc_dapm_input: |
| 3116 | case snd_soc_dapm_output: |
| 3117 | case snd_soc_dapm_micbias: |
| 3118 | case snd_soc_dapm_spk: |
| 3119 | case snd_soc_dapm_hp: |
| 3120 | case snd_soc_dapm_mic: |
| 3121 | case snd_soc_dapm_line: |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3122 | case snd_soc_dapm_dai_link: |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 3123 | w->power_check = dapm_generic_check_power; |
| 3124 | break; |
| 3125 | case snd_soc_dapm_supply: |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 3126 | case snd_soc_dapm_regulator_supply: |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 3127 | case snd_soc_dapm_clock_supply: |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 3128 | w->power_check = dapm_supply_check_power; |
| 3129 | break; |
| 3130 | default: |
| 3131 | w->power_check = dapm_always_on_check_power; |
| 3132 | break; |
| 3133 | } |
| 3134 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3135 | w->dapm = dapm; |
| 3136 | w->codec = dapm->codec; |
Liam Girdwood | b795064 | 2011-07-04 22:10:52 +0100 | [diff] [blame] | 3137 | w->platform = dapm->platform; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3138 | INIT_LIST_HEAD(&w->sources); |
| 3139 | INIT_LIST_HEAD(&w->sinks); |
| 3140 | INIT_LIST_HEAD(&w->list); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 3141 | INIT_LIST_HEAD(&w->dirty); |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 3142 | list_add(&w->list, &dapm->card->widgets); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3143 | |
| 3144 | /* machine layer set ups unconnected pins and insertions */ |
| 3145 | w->connected = 1; |
Mark Brown | 5ba06fc | 2012-02-16 11:07:13 -0800 | [diff] [blame] | 3146 | return w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3147 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3148 | |
| 3149 | /** |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 3150 | * snd_soc_dapm_new_controls - create new dapm controls |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3151 | * @dapm: DAPM context |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 3152 | * @widget: widget array |
| 3153 | * @num: number of widgets |
| 3154 | * |
| 3155 | * Creates new DAPM controls based upon the templates. |
| 3156 | * |
| 3157 | * Returns 0 for success else error. |
| 3158 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3159 | int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm, |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 3160 | const struct snd_soc_dapm_widget *widget, |
| 3161 | int num) |
| 3162 | { |
Mark Brown | 5ba06fc | 2012-02-16 11:07:13 -0800 | [diff] [blame] | 3163 | struct snd_soc_dapm_widget *w; |
| 3164 | int i; |
Dan Carpenter | 60884c2 | 2012-04-13 22:25:43 +0300 | [diff] [blame] | 3165 | int ret = 0; |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 3166 | |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3167 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 3168 | for (i = 0; i < num; i++) { |
Mark Brown | 5ba06fc | 2012-02-16 11:07:13 -0800 | [diff] [blame] | 3169 | w = snd_soc_dapm_new_control(dapm, widget); |
| 3170 | if (!w) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 3171 | dev_err(dapm->dev, |
Mark Brown | 5ba06fc | 2012-02-16 11:07:13 -0800 | [diff] [blame] | 3172 | "ASoC: Failed to create DAPM control %s\n", |
| 3173 | widget->name); |
Dan Carpenter | 60884c2 | 2012-04-13 22:25:43 +0300 | [diff] [blame] | 3174 | ret = -ENOMEM; |
| 3175 | break; |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 3176 | } |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 3177 | widget++; |
| 3178 | } |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3179 | mutex_unlock(&dapm->card->dapm_mutex); |
Dan Carpenter | 60884c2 | 2012-04-13 22:25:43 +0300 | [diff] [blame] | 3180 | return ret; |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 3181 | } |
| 3182 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls); |
| 3183 | |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3184 | static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, |
| 3185 | struct snd_kcontrol *kcontrol, int event) |
| 3186 | { |
| 3187 | struct snd_soc_dapm_path *source_p, *sink_p; |
| 3188 | struct snd_soc_dai *source, *sink; |
| 3189 | const struct snd_soc_pcm_stream *config = w->params; |
| 3190 | struct snd_pcm_substream substream; |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3191 | struct snd_pcm_hw_params *params = NULL; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3192 | u64 fmt; |
| 3193 | int ret; |
| 3194 | |
| 3195 | BUG_ON(!config); |
| 3196 | BUG_ON(list_empty(&w->sources) || list_empty(&w->sinks)); |
| 3197 | |
| 3198 | /* We only support a single source and sink, pick the first */ |
| 3199 | source_p = list_first_entry(&w->sources, struct snd_soc_dapm_path, |
| 3200 | list_sink); |
| 3201 | sink_p = list_first_entry(&w->sinks, struct snd_soc_dapm_path, |
| 3202 | list_source); |
| 3203 | |
| 3204 | BUG_ON(!source_p || !sink_p); |
| 3205 | BUG_ON(!sink_p->source || !source_p->sink); |
| 3206 | BUG_ON(!source_p->source || !sink_p->sink); |
| 3207 | |
| 3208 | source = source_p->source->priv; |
| 3209 | sink = sink_p->sink->priv; |
| 3210 | |
| 3211 | /* Be a little careful as we don't want to overflow the mask array */ |
| 3212 | if (config->formats) { |
| 3213 | fmt = ffs(config->formats) - 1; |
| 3214 | } else { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3215 | dev_warn(w->dapm->dev, "ASoC: Invalid format %llx specified\n", |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3216 | config->formats); |
| 3217 | fmt = 0; |
| 3218 | } |
| 3219 | |
| 3220 | /* Currently very limited parameter selection */ |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3221 | params = kzalloc(sizeof(*params), GFP_KERNEL); |
| 3222 | if (!params) { |
| 3223 | ret = -ENOMEM; |
| 3224 | goto out; |
| 3225 | } |
| 3226 | snd_mask_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), fmt); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3227 | |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3228 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->min = |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3229 | config->rate_min; |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3230 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->max = |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3231 | config->rate_max; |
| 3232 | |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3233 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->min |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3234 | = config->channels_min; |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3235 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->max |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3236 | = config->channels_max; |
| 3237 | |
| 3238 | memset(&substream, 0, sizeof(substream)); |
| 3239 | |
| 3240 | switch (event) { |
| 3241 | case SND_SOC_DAPM_PRE_PMU: |
| 3242 | if (source->driver->ops && source->driver->ops->hw_params) { |
| 3243 | substream.stream = SNDRV_PCM_STREAM_CAPTURE; |
| 3244 | ret = source->driver->ops->hw_params(&substream, |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3245 | params, source); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3246 | if (ret != 0) { |
| 3247 | dev_err(source->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3248 | "ASoC: hw_params() failed: %d\n", ret); |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3249 | goto out; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3250 | } |
| 3251 | } |
| 3252 | |
| 3253 | if (sink->driver->ops && sink->driver->ops->hw_params) { |
| 3254 | substream.stream = SNDRV_PCM_STREAM_PLAYBACK; |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3255 | ret = sink->driver->ops->hw_params(&substream, params, |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3256 | sink); |
| 3257 | if (ret != 0) { |
| 3258 | dev_err(sink->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3259 | "ASoC: hw_params() failed: %d\n", ret); |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3260 | goto out; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3261 | } |
| 3262 | } |
| 3263 | break; |
| 3264 | |
| 3265 | case SND_SOC_DAPM_POST_PMU: |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 3266 | ret = snd_soc_dai_digital_mute(sink, 0, |
| 3267 | SNDRV_PCM_STREAM_PLAYBACK); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3268 | if (ret != 0 && ret != -ENOTSUPP) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3269 | dev_warn(sink->dev, "ASoC: Failed to unmute: %d\n", ret); |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3270 | ret = 0; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3271 | break; |
| 3272 | |
| 3273 | case SND_SOC_DAPM_PRE_PMD: |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 3274 | ret = snd_soc_dai_digital_mute(sink, 1, |
| 3275 | SNDRV_PCM_STREAM_PLAYBACK); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3276 | if (ret != 0 && ret != -ENOTSUPP) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3277 | dev_warn(sink->dev, "ASoC: Failed to mute: %d\n", ret); |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3278 | ret = 0; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3279 | break; |
| 3280 | |
| 3281 | default: |
| 3282 | BUG(); |
| 3283 | return -EINVAL; |
| 3284 | } |
| 3285 | |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3286 | out: |
| 3287 | kfree(params); |
| 3288 | return ret; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | int snd_soc_dapm_new_pcm(struct snd_soc_card *card, |
| 3292 | const struct snd_soc_pcm_stream *params, |
| 3293 | struct snd_soc_dapm_widget *source, |
| 3294 | struct snd_soc_dapm_widget *sink) |
| 3295 | { |
| 3296 | struct snd_soc_dapm_route routes[2]; |
| 3297 | struct snd_soc_dapm_widget template; |
| 3298 | struct snd_soc_dapm_widget *w; |
| 3299 | size_t len; |
| 3300 | char *link_name; |
| 3301 | |
| 3302 | len = strlen(source->name) + strlen(sink->name) + 2; |
| 3303 | link_name = devm_kzalloc(card->dev, len, GFP_KERNEL); |
| 3304 | if (!link_name) |
| 3305 | return -ENOMEM; |
| 3306 | snprintf(link_name, len, "%s-%s", source->name, sink->name); |
| 3307 | |
| 3308 | memset(&template, 0, sizeof(template)); |
| 3309 | template.reg = SND_SOC_NOPM; |
| 3310 | template.id = snd_soc_dapm_dai_link; |
| 3311 | template.name = link_name; |
| 3312 | template.event = snd_soc_dai_link_event; |
| 3313 | template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3314 | SND_SOC_DAPM_PRE_PMD; |
| 3315 | |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3316 | dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3317 | |
| 3318 | w = snd_soc_dapm_new_control(&card->dapm, &template); |
| 3319 | if (!w) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3320 | dev_err(card->dev, "ASoC: Failed to create %s widget\n", |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3321 | link_name); |
| 3322 | return -ENOMEM; |
| 3323 | } |
| 3324 | |
| 3325 | w->params = params; |
| 3326 | |
| 3327 | memset(&routes, 0, sizeof(routes)); |
| 3328 | |
| 3329 | routes[0].source = source->name; |
| 3330 | routes[0].sink = link_name; |
| 3331 | routes[1].source = link_name; |
| 3332 | routes[1].sink = sink->name; |
| 3333 | |
| 3334 | return snd_soc_dapm_add_routes(&card->dapm, routes, |
| 3335 | ARRAY_SIZE(routes)); |
| 3336 | } |
| 3337 | |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3338 | int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm, |
| 3339 | struct snd_soc_dai *dai) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3340 | { |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3341 | struct snd_soc_dapm_widget template; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3342 | struct snd_soc_dapm_widget *w; |
| 3343 | |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3344 | WARN_ON(dapm->dev != dai->dev); |
| 3345 | |
| 3346 | memset(&template, 0, sizeof(template)); |
| 3347 | template.reg = SND_SOC_NOPM; |
| 3348 | |
| 3349 | if (dai->driver->playback.stream_name) { |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 3350 | template.id = snd_soc_dapm_dai_in; |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3351 | template.name = dai->driver->playback.stream_name; |
| 3352 | template.sname = dai->driver->playback.stream_name; |
| 3353 | |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3354 | dev_dbg(dai->dev, "ASoC: adding %s widget\n", |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3355 | template.name); |
| 3356 | |
| 3357 | w = snd_soc_dapm_new_control(dapm, &template); |
| 3358 | if (!w) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3359 | dev_err(dapm->dev, "ASoC: Failed to create %s widget\n", |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3360 | dai->driver->playback.stream_name); |
| 3361 | } |
| 3362 | |
| 3363 | w->priv = dai; |
| 3364 | dai->playback_widget = w; |
| 3365 | } |
| 3366 | |
| 3367 | if (dai->driver->capture.stream_name) { |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 3368 | template.id = snd_soc_dapm_dai_out; |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3369 | template.name = dai->driver->capture.stream_name; |
| 3370 | template.sname = dai->driver->capture.stream_name; |
| 3371 | |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3372 | dev_dbg(dai->dev, "ASoC: adding %s widget\n", |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3373 | template.name); |
| 3374 | |
| 3375 | w = snd_soc_dapm_new_control(dapm, &template); |
| 3376 | if (!w) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3377 | dev_err(dapm->dev, "ASoC: Failed to create %s widget\n", |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3378 | dai->driver->capture.stream_name); |
| 3379 | } |
| 3380 | |
| 3381 | w->priv = dai; |
| 3382 | dai->capture_widget = w; |
| 3383 | } |
| 3384 | |
| 3385 | return 0; |
| 3386 | } |
| 3387 | |
| 3388 | int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card) |
| 3389 | { |
| 3390 | struct snd_soc_dapm_widget *dai_w, *w; |
| 3391 | struct snd_soc_dai *dai; |
| 3392 | struct snd_soc_dapm_route r; |
| 3393 | |
| 3394 | memset(&r, 0, sizeof(r)); |
| 3395 | |
| 3396 | /* For each DAI widget... */ |
| 3397 | list_for_each_entry(dai_w, &card->widgets, list) { |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 3398 | switch (dai_w->id) { |
| 3399 | case snd_soc_dapm_dai_in: |
| 3400 | case snd_soc_dapm_dai_out: |
| 3401 | break; |
| 3402 | default: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3403 | continue; |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 3404 | } |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3405 | |
| 3406 | dai = dai_w->priv; |
| 3407 | |
| 3408 | /* ...find all widgets with the same stream and link them */ |
| 3409 | list_for_each_entry(w, &card->widgets, list) { |
| 3410 | if (w->dapm != dai_w->dapm) |
| 3411 | continue; |
| 3412 | |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 3413 | switch (w->id) { |
| 3414 | case snd_soc_dapm_dai_in: |
| 3415 | case snd_soc_dapm_dai_out: |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3416 | continue; |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 3417 | default: |
| 3418 | break; |
| 3419 | } |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3420 | |
| 3421 | if (!w->sname) |
| 3422 | continue; |
| 3423 | |
| 3424 | if (dai->driver->playback.stream_name && |
| 3425 | strstr(w->sname, |
| 3426 | dai->driver->playback.stream_name)) { |
| 3427 | r.source = dai->playback_widget->name; |
| 3428 | r.sink = w->name; |
| 3429 | dev_dbg(dai->dev, "%s -> %s\n", |
| 3430 | r.source, r.sink); |
| 3431 | |
| 3432 | snd_soc_dapm_add_route(w->dapm, &r); |
| 3433 | } |
| 3434 | |
| 3435 | if (dai->driver->capture.stream_name && |
| 3436 | strstr(w->sname, |
| 3437 | dai->driver->capture.stream_name)) { |
| 3438 | r.source = w->name; |
| 3439 | r.sink = dai->capture_widget->name; |
| 3440 | dev_dbg(dai->dev, "%s -> %s\n", |
| 3441 | r.source, r.sink); |
| 3442 | |
| 3443 | snd_soc_dapm_add_route(w->dapm, &r); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3444 | } |
| 3445 | } |
| 3446 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3447 | |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3448 | return 0; |
| 3449 | } |
Liam Girdwood | 64a648c | 2011-07-25 11:15:15 +0100 | [diff] [blame] | 3450 | |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 3451 | static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, |
| 3452 | int event) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3453 | { |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 3454 | |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 3455 | struct snd_soc_dapm_widget *w_cpu, *w_codec; |
| 3456 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 3457 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 3458 | |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 3459 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 3460 | w_cpu = cpu_dai->playback_widget; |
| 3461 | w_codec = codec_dai->playback_widget; |
| 3462 | } else { |
| 3463 | w_cpu = cpu_dai->capture_widget; |
| 3464 | w_codec = codec_dai->capture_widget; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3465 | } |
| 3466 | |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 3467 | if (w_cpu) { |
| 3468 | |
| 3469 | dapm_mark_dirty(w_cpu, "stream event"); |
| 3470 | |
| 3471 | switch (event) { |
| 3472 | case SND_SOC_DAPM_STREAM_START: |
| 3473 | w_cpu->active = 1; |
| 3474 | break; |
| 3475 | case SND_SOC_DAPM_STREAM_STOP: |
| 3476 | w_cpu->active = 0; |
| 3477 | break; |
| 3478 | case SND_SOC_DAPM_STREAM_SUSPEND: |
| 3479 | case SND_SOC_DAPM_STREAM_RESUME: |
| 3480 | case SND_SOC_DAPM_STREAM_PAUSE_PUSH: |
| 3481 | case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: |
| 3482 | break; |
| 3483 | } |
| 3484 | } |
| 3485 | |
| 3486 | if (w_codec) { |
| 3487 | |
| 3488 | dapm_mark_dirty(w_codec, "stream event"); |
| 3489 | |
| 3490 | switch (event) { |
| 3491 | case SND_SOC_DAPM_STREAM_START: |
| 3492 | w_codec->active = 1; |
| 3493 | break; |
| 3494 | case SND_SOC_DAPM_STREAM_STOP: |
| 3495 | w_codec->active = 0; |
| 3496 | break; |
| 3497 | case SND_SOC_DAPM_STREAM_SUSPEND: |
| 3498 | case SND_SOC_DAPM_STREAM_RESUME: |
| 3499 | case SND_SOC_DAPM_STREAM_PAUSE_PUSH: |
| 3500 | case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: |
| 3501 | break; |
| 3502 | } |
| 3503 | } |
| 3504 | |
| 3505 | dapm_power_widgets(&rtd->card->dapm, event); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | /** |
| 3509 | * snd_soc_dapm_stream_event - send a stream event to the dapm core |
| 3510 | * @rtd: PCM runtime data |
| 3511 | * @stream: stream name |
| 3512 | * @event: stream event |
| 3513 | * |
| 3514 | * Sends a stream event to the dapm core. The core then makes any |
| 3515 | * necessary widget power changes. |
| 3516 | * |
| 3517 | * Returns 0 for success else error. |
| 3518 | */ |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 3519 | void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, |
| 3520 | int event) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3521 | { |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3522 | struct snd_soc_card *card = rtd->card; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3523 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 3524 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 3525 | soc_dapm_stream_event(rtd, stream, event); |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3526 | mutex_unlock(&card->dapm_mutex); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3527 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3528 | |
| 3529 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3530 | * snd_soc_dapm_enable_pin - enable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3531 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3532 | * @pin: pin name |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3533 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 3534 | * Enables input/output pin and its parents or children widgets iff there is |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3535 | * a valid audio route and active audio stream. |
| 3536 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 3537 | * do any widget power switching. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3538 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3539 | int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3540 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3541 | return snd_soc_dapm_set_pin(dapm, pin, 1); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3542 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3543 | EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3544 | |
| 3545 | /** |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 3546 | * snd_soc_dapm_force_enable_pin - force a pin to be enabled |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3547 | * @dapm: DAPM context |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 3548 | * @pin: pin name |
| 3549 | * |
| 3550 | * Enables input/output pin regardless of any other state. This is |
| 3551 | * intended for use with microphone bias supplies used in microphone |
| 3552 | * jack detection. |
| 3553 | * |
| 3554 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 3555 | * do any widget power switching. |
| 3556 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3557 | int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm, |
| 3558 | const char *pin) |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 3559 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3560 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 3561 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3562 | if (!w) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3563 | dev_err(dapm->dev, "ASoC: unknown pin %s\n", pin); |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3564 | return -EINVAL; |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 3565 | } |
| 3566 | |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3567 | dev_dbg(w->dapm->dev, "ASoC: force enable pin %s\n", pin); |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3568 | w->connected = 1; |
| 3569 | w->force = 1; |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 3570 | dapm_mark_dirty(w, "force enable"); |
Mark Brown | 0d86733 | 2011-04-06 11:38:14 +0900 | [diff] [blame] | 3571 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3572 | return 0; |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 3573 | } |
| 3574 | EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin); |
| 3575 | |
| 3576 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3577 | * snd_soc_dapm_disable_pin - disable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3578 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3579 | * @pin: pin name |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 3580 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 3581 | * Disables input/output pin and its parents or children widgets. |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3582 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 3583 | * do any widget power switching. |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 3584 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3585 | int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm, |
| 3586 | const char *pin) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3587 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3588 | return snd_soc_dapm_set_pin(dapm, pin, 0); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3589 | } |
| 3590 | EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin); |
| 3591 | |
| 3592 | /** |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 3593 | * snd_soc_dapm_nc_pin - permanently disable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3594 | * @dapm: DAPM context |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 3595 | * @pin: pin name |
| 3596 | * |
| 3597 | * Marks the specified pin as being not connected, disabling it along |
| 3598 | * any parent or child widgets. At present this is identical to |
| 3599 | * snd_soc_dapm_disable_pin() but in future it will be extended to do |
| 3600 | * additional things such as disabling controls which only affect |
| 3601 | * paths through the pin. |
| 3602 | * |
| 3603 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 3604 | * do any widget power switching. |
| 3605 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3606 | int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin) |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 3607 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3608 | return snd_soc_dapm_set_pin(dapm, pin, 0); |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 3609 | } |
| 3610 | EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin); |
| 3611 | |
| 3612 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3613 | * snd_soc_dapm_get_pin_status - get audio pin status |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3614 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3615 | * @pin: audio signal pin endpoint (or start point) |
| 3616 | * |
| 3617 | * Get audio pin status - connected or disconnected. |
| 3618 | * |
| 3619 | * Returns 1 for connected otherwise 0. |
| 3620 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3621 | int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm, |
| 3622 | const char *pin) |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 3623 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3624 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 3625 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3626 | if (w) |
| 3627 | return w->connected; |
Stephen Warren | a68b38a | 2011-04-19 15:25:11 -0600 | [diff] [blame] | 3628 | |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 3629 | return 0; |
| 3630 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3631 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 3632 | |
| 3633 | /** |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 3634 | * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3635 | * @dapm: DAPM context |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 3636 | * @pin: audio signal pin endpoint (or start point) |
| 3637 | * |
| 3638 | * Mark the given endpoint or pin as ignoring suspend. When the |
| 3639 | * system is disabled a path between two endpoints flagged as ignoring |
| 3640 | * suspend will not be disabled. The path must already be enabled via |
| 3641 | * normal means at suspend time, it will not be turned on if it was not |
| 3642 | * already enabled. |
| 3643 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3644 | int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm, |
| 3645 | const char *pin) |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 3646 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3647 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 3648 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3649 | if (!w) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3650 | dev_err(dapm->dev, "ASoC: unknown pin %s\n", pin); |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3651 | return -EINVAL; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 3652 | } |
| 3653 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3654 | w->ignore_suspend = 1; |
| 3655 | |
| 3656 | return 0; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 3657 | } |
| 3658 | EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend); |
| 3659 | |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 3660 | static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card *card, |
| 3661 | struct snd_soc_dapm_widget *w) |
| 3662 | { |
| 3663 | struct snd_soc_dapm_path *p; |
| 3664 | |
| 3665 | list_for_each_entry(p, &card->paths, list) { |
| 3666 | if ((p->source == w) || (p->sink == w)) { |
| 3667 | dev_dbg(card->dev, |
| 3668 | "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n", |
| 3669 | p->source->name, p->source->id, p->source->dapm, |
| 3670 | p->sink->name, p->sink->id, p->sink->dapm); |
| 3671 | |
| 3672 | /* Connected to something other than the codec */ |
| 3673 | if (p->source->dapm != p->sink->dapm) |
| 3674 | return true; |
| 3675 | /* |
| 3676 | * Loopback connection from codec external pin to |
| 3677 | * codec external pin |
| 3678 | */ |
| 3679 | if (p->sink->id == snd_soc_dapm_input) { |
| 3680 | switch (p->source->id) { |
| 3681 | case snd_soc_dapm_output: |
| 3682 | case snd_soc_dapm_micbias: |
| 3683 | return true; |
| 3684 | default: |
| 3685 | break; |
| 3686 | } |
| 3687 | } |
| 3688 | } |
| 3689 | } |
| 3690 | |
| 3691 | return false; |
| 3692 | } |
| 3693 | |
| 3694 | /** |
| 3695 | * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins |
| 3696 | * @codec: The codec whose pins should be processed |
| 3697 | * |
| 3698 | * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec |
| 3699 | * which are unused. Pins are used if they are connected externally to the |
| 3700 | * codec, whether that be to some other device, or a loop-back connection to |
| 3701 | * the codec itself. |
| 3702 | */ |
| 3703 | void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec) |
| 3704 | { |
| 3705 | struct snd_soc_card *card = codec->card; |
| 3706 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 3707 | struct snd_soc_dapm_widget *w; |
| 3708 | |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3709 | dev_dbg(codec->dev, "ASoC: Auto NC: DAPMs: card:%p codec:%p\n", |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 3710 | &card->dapm, &codec->dapm); |
| 3711 | |
| 3712 | list_for_each_entry(w, &card->widgets, list) { |
| 3713 | if (w->dapm != dapm) |
| 3714 | continue; |
| 3715 | switch (w->id) { |
| 3716 | case snd_soc_dapm_input: |
| 3717 | case snd_soc_dapm_output: |
| 3718 | case snd_soc_dapm_micbias: |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3719 | dev_dbg(codec->dev, "ASoC: Auto NC: Checking widget %s\n", |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 3720 | w->name); |
| 3721 | if (!snd_soc_dapm_widget_in_card_paths(card, w)) { |
Mark Brown | a094b80 | 2011-11-27 19:42:20 +0000 | [diff] [blame] | 3722 | dev_dbg(codec->dev, |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 3723 | "... Not in map; disabling\n"); |
| 3724 | snd_soc_dapm_nc_pin(dapm, w->name); |
| 3725 | } |
| 3726 | break; |
| 3727 | default: |
| 3728 | break; |
| 3729 | } |
| 3730 | } |
| 3731 | } |
| 3732 | |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 3733 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3734 | * snd_soc_dapm_free - free dapm resources |
Peter Ujfalusi | 728a522 | 2011-08-26 16:33:52 +0300 | [diff] [blame] | 3735 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3736 | * |
| 3737 | * Free all dapm widgets and resources. |
| 3738 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3739 | void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3740 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3741 | snd_soc_dapm_sys_remove(dapm->dev); |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 3742 | dapm_debugfs_cleanup(dapm); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3743 | dapm_free_widgets(dapm); |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 3744 | list_del(&dapm->list); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3745 | } |
| 3746 | EXPORT_SYMBOL_GPL(snd_soc_dapm_free); |
| 3747 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3748 | static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm) |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3749 | { |
Liam Girdwood | 01005a7 | 2012-07-06 16:57:05 +0100 | [diff] [blame] | 3750 | struct snd_soc_card *card = dapm->card; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3751 | struct snd_soc_dapm_widget *w; |
| 3752 | LIST_HEAD(down_list); |
| 3753 | int powerdown = 0; |
| 3754 | |
Liam Girdwood | 01005a7 | 2012-07-06 16:57:05 +0100 | [diff] [blame] | 3755 | mutex_lock(&card->dapm_mutex); |
| 3756 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 3757 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 3758 | if (w->dapm != dapm) |
| 3759 | continue; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3760 | if (w->power) { |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 3761 | dapm_seq_insert(w, &down_list, false); |
Mark Brown | c2caa4d | 2009-06-26 15:36:56 +0100 | [diff] [blame] | 3762 | w->power = 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3763 | powerdown = 1; |
| 3764 | } |
| 3765 | } |
| 3766 | |
| 3767 | /* If there were no widgets to power down we're already in |
| 3768 | * standby. |
| 3769 | */ |
| 3770 | if (powerdown) { |
Mark Brown | 7679e42 | 2012-02-22 15:52:56 +0000 | [diff] [blame] | 3771 | if (dapm->bias_level == SND_SOC_BIAS_ON) |
| 3772 | snd_soc_dapm_set_bias_level(dapm, |
| 3773 | SND_SOC_BIAS_PREPARE); |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 3774 | dapm_seq_run(dapm, &down_list, 0, false); |
Mark Brown | 7679e42 | 2012-02-22 15:52:56 +0000 | [diff] [blame] | 3775 | if (dapm->bias_level == SND_SOC_BIAS_PREPARE) |
| 3776 | snd_soc_dapm_set_bias_level(dapm, |
| 3777 | SND_SOC_BIAS_STANDBY); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3778 | } |
Liam Girdwood | 01005a7 | 2012-07-06 16:57:05 +0100 | [diff] [blame] | 3779 | |
| 3780 | mutex_unlock(&card->dapm_mutex); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3781 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3782 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3783 | /* |
| 3784 | * snd_soc_dapm_shutdown - callback for system shutdown |
| 3785 | */ |
| 3786 | void snd_soc_dapm_shutdown(struct snd_soc_card *card) |
| 3787 | { |
| 3788 | struct snd_soc_codec *codec; |
| 3789 | |
Misael Lopez Cruz | 445632a | 2012-11-08 12:03:12 -0600 | [diff] [blame] | 3790 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3791 | soc_dapm_shutdown_codec(&codec->dapm); |
Mark Brown | 7679e42 | 2012-02-22 15:52:56 +0000 | [diff] [blame] | 3792 | if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) |
| 3793 | snd_soc_dapm_set_bias_level(&codec->dapm, |
| 3794 | SND_SOC_BIAS_OFF); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3795 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3796 | } |
| 3797 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3798 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 3799 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3800 | MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC"); |
| 3801 | MODULE_LICENSE("GPL"); |