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