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