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