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