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