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