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