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