soc-dapm.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515
  1. /*
  2. * soc-dapm.c -- ALSA SoC Dynamic Audio Power Management
  3. *
  4. * Copyright 2005 Wolfson Microelectronics PLC.
  5. * Author: Liam Girdwood <lrg@slimlogic.co.uk>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * Features:
  13. * o Changes power status of internal codec blocks depending on the
  14. * dynamic configuration of codec internal audio paths and active
  15. * DACs/ADCs.
  16. * o Platform power domain - can support external components i.e. amps and
  17. * mic/meadphone insertion events.
  18. * o Automatic Mic Bias support
  19. * o Jack insertion power event initiation - e.g. hp insertion will enable
  20. * sinks, dacs, etc
  21. * o Delayed powerdown of audio susbsystem to reduce pops between a quick
  22. * device reopen.
  23. *
  24. * Todo:
  25. * o DAPM power change sequencing - allow for configurable per
  26. * codec sequences.
  27. * o Support for analogue bias optimisation.
  28. * o Support for reduced codec oversampling rates.
  29. * o Support for reduced codec bias currents.
  30. */
  31. #include <linux/module.h>
  32. #include <linux/moduleparam.h>
  33. #include <linux/init.h>
  34. #include <linux/async.h>
  35. #include <linux/delay.h>
  36. #include <linux/pm.h>
  37. #include <linux/bitops.h>
  38. #include <linux/platform_device.h>
  39. #include <linux/jiffies.h>
  40. #include <linux/debugfs.h>
  41. #include <linux/slab.h>
  42. #include <sound/core.h>
  43. #include <sound/pcm.h>
  44. #include <sound/pcm_params.h>
  45. #include <sound/soc.h>
  46. #include <sound/initval.h>
  47. #include <trace/events/asoc.h>
  48. /* dapm power sequences - make this per codec in the future */
  49. static int dapm_up_seq[] = {
  50. [snd_soc_dapm_pre] = 0,
  51. [snd_soc_dapm_supply] = 1,
  52. [snd_soc_dapm_micbias] = 2,
  53. [snd_soc_dapm_aif_in] = 3,
  54. [snd_soc_dapm_aif_out] = 3,
  55. [snd_soc_dapm_mic] = 4,
  56. [snd_soc_dapm_mux] = 5,
  57. [snd_soc_dapm_virt_mux] = 5,
  58. [snd_soc_dapm_value_mux] = 5,
  59. [snd_soc_dapm_dac] = 6,
  60. [snd_soc_dapm_mixer] = 7,
  61. [snd_soc_dapm_mixer_named_ctl] = 7,
  62. [snd_soc_dapm_pga] = 8,
  63. [snd_soc_dapm_adc] = 9,
  64. [snd_soc_dapm_out_drv] = 10,
  65. [snd_soc_dapm_hp] = 10,
  66. [snd_soc_dapm_spk] = 10,
  67. [snd_soc_dapm_post] = 11,
  68. };
  69. static int dapm_down_seq[] = {
  70. [snd_soc_dapm_pre] = 0,
  71. [snd_soc_dapm_adc] = 1,
  72. [snd_soc_dapm_hp] = 2,
  73. [snd_soc_dapm_spk] = 2,
  74. [snd_soc_dapm_out_drv] = 2,
  75. [snd_soc_dapm_pga] = 4,
  76. [snd_soc_dapm_mixer_named_ctl] = 5,
  77. [snd_soc_dapm_mixer] = 5,
  78. [snd_soc_dapm_dac] = 6,
  79. [snd_soc_dapm_mic] = 7,
  80. [snd_soc_dapm_micbias] = 8,
  81. [snd_soc_dapm_mux] = 9,
  82. [snd_soc_dapm_virt_mux] = 9,
  83. [snd_soc_dapm_value_mux] = 9,
  84. [snd_soc_dapm_aif_in] = 10,
  85. [snd_soc_dapm_aif_out] = 10,
  86. [snd_soc_dapm_supply] = 11,
  87. [snd_soc_dapm_post] = 12,
  88. };
  89. static void pop_wait(u32 pop_time)
  90. {
  91. if (pop_time)
  92. schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
  93. }
  94. static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...)
  95. {
  96. va_list args;
  97. char *buf;
  98. if (!pop_time)
  99. return;
  100. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  101. if (buf == NULL)
  102. return;
  103. va_start(args, fmt);
  104. vsnprintf(buf, PAGE_SIZE, fmt, args);
  105. dev_info(dev, "%s", buf);
  106. va_end(args);
  107. kfree(buf);
  108. }
  109. /* create a new dapm widget */
  110. static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
  111. const struct snd_soc_dapm_widget *_widget)
  112. {
  113. return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
  114. }
  115. /**
  116. * snd_soc_dapm_set_bias_level - set the bias level for the system
  117. * @dapm: DAPM context
  118. * @level: level to configure
  119. *
  120. * Configure the bias (power) levels for the SoC audio device.
  121. *
  122. * Returns 0 for success else error.
  123. */
  124. static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm,
  125. enum snd_soc_bias_level level)
  126. {
  127. struct snd_soc_card *card = dapm->card;
  128. int ret = 0;
  129. switch (level) {
  130. case SND_SOC_BIAS_ON:
  131. dev_dbg(dapm->dev, "Setting full bias\n");
  132. break;
  133. case SND_SOC_BIAS_PREPARE:
  134. dev_dbg(dapm->dev, "Setting bias prepare\n");
  135. break;
  136. case SND_SOC_BIAS_STANDBY:
  137. dev_dbg(dapm->dev, "Setting standby bias\n");
  138. break;
  139. case SND_SOC_BIAS_OFF:
  140. dev_dbg(dapm->dev, "Setting bias off\n");
  141. break;
  142. default:
  143. dev_err(dapm->dev, "Setting invalid bias %d\n", level);
  144. return -EINVAL;
  145. }
  146. trace_snd_soc_bias_level_start(card, level);
  147. if (card && card->set_bias_level)
  148. ret = card->set_bias_level(card, level);
  149. if (ret == 0) {
  150. if (dapm->codec && dapm->codec->driver->set_bias_level)
  151. ret = dapm->codec->driver->set_bias_level(dapm->codec, level);
  152. else
  153. dapm->bias_level = level;
  154. }
  155. if (ret == 0) {
  156. if (card && card->set_bias_level_post)
  157. ret = card->set_bias_level_post(card, level);
  158. }
  159. trace_snd_soc_bias_level_done(card, level);
  160. return ret;
  161. }
  162. /* set up initial codec paths */
  163. static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
  164. struct snd_soc_dapm_path *p, int i)
  165. {
  166. switch (w->id) {
  167. case snd_soc_dapm_switch:
  168. case snd_soc_dapm_mixer:
  169. case snd_soc_dapm_mixer_named_ctl: {
  170. int val;
  171. struct soc_mixer_control *mc = (struct soc_mixer_control *)
  172. w->kcontrols[i].private_value;
  173. unsigned int reg = mc->reg;
  174. unsigned int shift = mc->shift;
  175. int max = mc->max;
  176. unsigned int mask = (1 << fls(max)) - 1;
  177. unsigned int invert = mc->invert;
  178. val = snd_soc_read(w->codec, reg);
  179. val = (val >> shift) & mask;
  180. if ((invert && !val) || (!invert && val))
  181. p->connect = 1;
  182. else
  183. p->connect = 0;
  184. }
  185. break;
  186. case snd_soc_dapm_mux: {
  187. struct soc_enum *e = (struct soc_enum *)w->kcontrols[i].private_value;
  188. int val, item, bitmask;
  189. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  190. ;
  191. val = snd_soc_read(w->codec, e->reg);
  192. item = (val >> e->shift_l) & (bitmask - 1);
  193. p->connect = 0;
  194. for (i = 0; i < e->max; i++) {
  195. if (!(strcmp(p->name, e->texts[i])) && item == i)
  196. p->connect = 1;
  197. }
  198. }
  199. break;
  200. case snd_soc_dapm_virt_mux: {
  201. struct soc_enum *e = (struct soc_enum *)w->kcontrols[i].private_value;
  202. p->connect = 0;
  203. /* since a virtual mux has no backing registers to
  204. * decide which path to connect, it will try to match
  205. * with the first enumeration. This is to ensure
  206. * that the default mux choice (the first) will be
  207. * correctly powered up during initialization.
  208. */
  209. if (!strcmp(p->name, e->texts[0]))
  210. p->connect = 1;
  211. }
  212. break;
  213. case snd_soc_dapm_value_mux: {
  214. struct soc_enum *e = (struct soc_enum *)
  215. w->kcontrols[i].private_value;
  216. int val, item;
  217. val = snd_soc_read(w->codec, e->reg);
  218. val = (val >> e->shift_l) & e->mask;
  219. for (item = 0; item < e->max; item++) {
  220. if (val == e->values[item])
  221. break;
  222. }
  223. p->connect = 0;
  224. for (i = 0; i < e->max; i++) {
  225. if (!(strcmp(p->name, e->texts[i])) && item == i)
  226. p->connect = 1;
  227. }
  228. }
  229. break;
  230. /* does not effect routing - always connected */
  231. case snd_soc_dapm_pga:
  232. case snd_soc_dapm_out_drv:
  233. case snd_soc_dapm_output:
  234. case snd_soc_dapm_adc:
  235. case snd_soc_dapm_input:
  236. case snd_soc_dapm_dac:
  237. case snd_soc_dapm_micbias:
  238. case snd_soc_dapm_vmid:
  239. case snd_soc_dapm_supply:
  240. case snd_soc_dapm_aif_in:
  241. case snd_soc_dapm_aif_out:
  242. p->connect = 1;
  243. break;
  244. /* does effect routing - dynamically connected */
  245. case snd_soc_dapm_hp:
  246. case snd_soc_dapm_mic:
  247. case snd_soc_dapm_spk:
  248. case snd_soc_dapm_line:
  249. case snd_soc_dapm_pre:
  250. case snd_soc_dapm_post:
  251. p->connect = 0;
  252. break;
  253. }
  254. }
  255. /* connect mux widget to its interconnecting audio paths */
  256. static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
  257. struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
  258. struct snd_soc_dapm_path *path, const char *control_name,
  259. const struct snd_kcontrol_new *kcontrol)
  260. {
  261. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  262. int i;
  263. for (i = 0; i < e->max; i++) {
  264. if (!(strcmp(control_name, e->texts[i]))) {
  265. list_add(&path->list, &dapm->card->paths);
  266. list_add(&path->list_sink, &dest->sources);
  267. list_add(&path->list_source, &src->sinks);
  268. path->name = (char*)e->texts[i];
  269. dapm_set_path_status(dest, path, 0);
  270. return 0;
  271. }
  272. }
  273. return -ENODEV;
  274. }
  275. /* connect mixer widget to its interconnecting audio paths */
  276. static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
  277. struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
  278. struct snd_soc_dapm_path *path, const char *control_name)
  279. {
  280. int i;
  281. /* search for mixer kcontrol */
  282. for (i = 0; i < dest->num_kcontrols; i++) {
  283. if (!strcmp(control_name, dest->kcontrols[i].name)) {
  284. list_add(&path->list, &dapm->card->paths);
  285. list_add(&path->list_sink, &dest->sources);
  286. list_add(&path->list_source, &src->sinks);
  287. path->name = dest->kcontrols[i].name;
  288. dapm_set_path_status(dest, path, i);
  289. return 0;
  290. }
  291. }
  292. return -ENODEV;
  293. }
  294. /* update dapm codec register bits */
  295. static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
  296. {
  297. int change, power;
  298. unsigned int old, new;
  299. struct snd_soc_codec *codec = widget->codec;
  300. struct snd_soc_dapm_context *dapm = widget->dapm;
  301. struct snd_soc_card *card = dapm->card;
  302. /* check for valid widgets */
  303. if (widget->reg < 0 || widget->id == snd_soc_dapm_input ||
  304. widget->id == snd_soc_dapm_output ||
  305. widget->id == snd_soc_dapm_hp ||
  306. widget->id == snd_soc_dapm_mic ||
  307. widget->id == snd_soc_dapm_line ||
  308. widget->id == snd_soc_dapm_spk)
  309. return 0;
  310. power = widget->power;
  311. if (widget->invert)
  312. power = (power ? 0:1);
  313. old = snd_soc_read(codec, widget->reg);
  314. new = (old & ~(0x1 << widget->shift)) | (power << widget->shift);
  315. change = old != new;
  316. if (change) {
  317. pop_dbg(dapm->dev, card->pop_time,
  318. "pop test %s : %s in %d ms\n",
  319. widget->name, widget->power ? "on" : "off",
  320. card->pop_time);
  321. pop_wait(card->pop_time);
  322. snd_soc_write(codec, widget->reg, new);
  323. }
  324. dev_dbg(dapm->dev, "reg %x old %x new %x change %d\n", widget->reg,
  325. old, new, change);
  326. return change;
  327. }
  328. /* create new dapm mixer control */
  329. static int dapm_new_mixer(struct snd_soc_dapm_context *dapm,
  330. struct snd_soc_dapm_widget *w)
  331. {
  332. int i, ret = 0;
  333. size_t name_len, prefix_len;
  334. struct snd_soc_dapm_path *path;
  335. struct snd_card *card = dapm->card->snd_card;
  336. const char *prefix;
  337. if (dapm->codec)
  338. prefix = dapm->codec->name_prefix;
  339. else
  340. prefix = NULL;
  341. if (prefix)
  342. prefix_len = strlen(prefix) + 1;
  343. else
  344. prefix_len = 0;
  345. /* add kcontrol */
  346. for (i = 0; i < w->num_kcontrols; i++) {
  347. /* match name */
  348. list_for_each_entry(path, &w->sources, list_sink) {
  349. /* mixer/mux paths name must match control name */
  350. if (path->name != (char*)w->kcontrols[i].name)
  351. continue;
  352. /* add dapm control with long name.
  353. * for dapm_mixer this is the concatenation of the
  354. * mixer and kcontrol name.
  355. * for dapm_mixer_named_ctl this is simply the
  356. * kcontrol name.
  357. */
  358. name_len = strlen(w->kcontrols[i].name) + 1;
  359. if (w->id != snd_soc_dapm_mixer_named_ctl)
  360. name_len += 1 + strlen(w->name);
  361. path->long_name = kmalloc(name_len, GFP_KERNEL);
  362. if (path->long_name == NULL)
  363. return -ENOMEM;
  364. switch (w->id) {
  365. default:
  366. /* The control will get a prefix from
  367. * the control creation process but
  368. * we're also using the same prefix
  369. * for widgets so cut the prefix off
  370. * the front of the widget name.
  371. */
  372. snprintf(path->long_name, name_len, "%s %s",
  373. w->name + prefix_len,
  374. w->kcontrols[i].name);
  375. break;
  376. case snd_soc_dapm_mixer_named_ctl:
  377. snprintf(path->long_name, name_len, "%s",
  378. w->kcontrols[i].name);
  379. break;
  380. }
  381. path->long_name[name_len - 1] = '\0';
  382. path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w,
  383. path->long_name, prefix);
  384. ret = snd_ctl_add(card, path->kcontrol);
  385. if (ret < 0) {
  386. dev_err(dapm->dev,
  387. "asoc: failed to add dapm kcontrol %s: %d\n",
  388. path->long_name, ret);
  389. kfree(path->long_name);
  390. path->long_name = NULL;
  391. return ret;
  392. }
  393. }
  394. }
  395. return ret;
  396. }
  397. /* create new dapm mux control */
  398. static int dapm_new_mux(struct snd_soc_dapm_context *dapm,
  399. struct snd_soc_dapm_widget *w)
  400. {
  401. struct snd_soc_dapm_path *path = NULL;
  402. struct snd_kcontrol *kcontrol;
  403. struct snd_card *card = dapm->card->snd_card;
  404. const char *prefix;
  405. size_t prefix_len;
  406. int ret = 0;
  407. if (!w->num_kcontrols) {
  408. dev_err(dapm->dev, "asoc: mux %s has no controls\n", w->name);
  409. return -EINVAL;
  410. }
  411. if (dapm->codec)
  412. prefix = dapm->codec->name_prefix;
  413. else
  414. prefix = NULL;
  415. if (prefix)
  416. prefix_len = strlen(prefix) + 1;
  417. else
  418. prefix_len = 0;
  419. /* The control will get a prefix from the control creation
  420. * process but we're also using the same prefix for widgets so
  421. * cut the prefix off the front of the widget name.
  422. */
  423. kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name + prefix_len,
  424. prefix);
  425. ret = snd_ctl_add(card, kcontrol);
  426. if (ret < 0)
  427. goto err;
  428. list_for_each_entry(path, &w->sources, list_sink)
  429. path->kcontrol = kcontrol;
  430. return ret;
  431. err:
  432. dev_err(dapm->dev, "asoc: failed to add kcontrol %s\n", w->name);
  433. return ret;
  434. }
  435. /* create new dapm volume control */
  436. static int dapm_new_pga(struct snd_soc_dapm_context *dapm,
  437. struct snd_soc_dapm_widget *w)
  438. {
  439. if (w->num_kcontrols)
  440. dev_err(w->dapm->dev,
  441. "asoc: PGA controls not supported: '%s'\n", w->name);
  442. return 0;
  443. }
  444. /* reset 'walked' bit for each dapm path */
  445. static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm)
  446. {
  447. struct snd_soc_dapm_path *p;
  448. list_for_each_entry(p, &dapm->card->paths, list)
  449. p->walked = 0;
  450. }
  451. /* We implement power down on suspend by checking the power state of
  452. * the ALSA card - when we are suspending the ALSA state for the card
  453. * is set to D3.
  454. */
  455. static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
  456. {
  457. int level = snd_power_get_state(widget->dapm->card->snd_card);
  458. switch (level) {
  459. case SNDRV_CTL_POWER_D3hot:
  460. case SNDRV_CTL_POWER_D3cold:
  461. if (widget->ignore_suspend)
  462. dev_dbg(widget->dapm->dev, "%s ignoring suspend\n",
  463. widget->name);
  464. return widget->ignore_suspend;
  465. default:
  466. return 1;
  467. }
  468. }
  469. /*
  470. * Recursively check for a completed path to an active or physically connected
  471. * output widget. Returns number of complete paths.
  472. */
  473. static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
  474. {
  475. struct snd_soc_dapm_path *path;
  476. int con = 0;
  477. if (widget->id == snd_soc_dapm_supply)
  478. return 0;
  479. switch (widget->id) {
  480. case snd_soc_dapm_adc:
  481. case snd_soc_dapm_aif_out:
  482. if (widget->active)
  483. return snd_soc_dapm_suspend_check(widget);
  484. default:
  485. break;
  486. }
  487. if (widget->connected) {
  488. /* connected pin ? */
  489. if (widget->id == snd_soc_dapm_output && !widget->ext)
  490. return snd_soc_dapm_suspend_check(widget);
  491. /* connected jack or spk ? */
  492. if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
  493. (widget->id == snd_soc_dapm_line && !list_empty(&widget->sources)))
  494. return snd_soc_dapm_suspend_check(widget);
  495. }
  496. list_for_each_entry(path, &widget->sinks, list_source) {
  497. if (path->walked)
  498. continue;
  499. if (path->sink && path->connect) {
  500. path->walked = 1;
  501. con += is_connected_output_ep(path->sink);
  502. }
  503. }
  504. return con;
  505. }
  506. /*
  507. * Recursively check for a completed path to an active or physically connected
  508. * input widget. Returns number of complete paths.
  509. */
  510. static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
  511. {
  512. struct snd_soc_dapm_path *path;
  513. int con = 0;
  514. if (widget->id == snd_soc_dapm_supply)
  515. return 0;
  516. /* active stream ? */
  517. switch (widget->id) {
  518. case snd_soc_dapm_dac:
  519. case snd_soc_dapm_aif_in:
  520. if (widget->active)
  521. return snd_soc_dapm_suspend_check(widget);
  522. default:
  523. break;
  524. }
  525. if (widget->connected) {
  526. /* connected pin ? */
  527. if (widget->id == snd_soc_dapm_input && !widget->ext)
  528. return snd_soc_dapm_suspend_check(widget);
  529. /* connected VMID/Bias for lower pops */
  530. if (widget->id == snd_soc_dapm_vmid)
  531. return snd_soc_dapm_suspend_check(widget);
  532. /* connected jack ? */
  533. if (widget->id == snd_soc_dapm_mic ||
  534. (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks)))
  535. return snd_soc_dapm_suspend_check(widget);
  536. }
  537. list_for_each_entry(path, &widget->sources, list_sink) {
  538. if (path->walked)
  539. continue;
  540. if (path->source && path->connect) {
  541. path->walked = 1;
  542. con += is_connected_input_ep(path->source);
  543. }
  544. }
  545. return con;
  546. }
  547. /*
  548. * Handler for generic register modifier widget.
  549. */
  550. int dapm_reg_event(struct snd_soc_dapm_widget *w,
  551. struct snd_kcontrol *kcontrol, int event)
  552. {
  553. unsigned int val;
  554. if (SND_SOC_DAPM_EVENT_ON(event))
  555. val = w->on_val;
  556. else
  557. val = w->off_val;
  558. snd_soc_update_bits(w->codec, -(w->reg + 1),
  559. w->mask << w->shift, val << w->shift);
  560. return 0;
  561. }
  562. EXPORT_SYMBOL_GPL(dapm_reg_event);
  563. /* Standard power change method, used to apply power changes to most
  564. * widgets.
  565. */
  566. static int dapm_generic_apply_power(struct snd_soc_dapm_widget *w)
  567. {
  568. int ret;
  569. /* call any power change event handlers */
  570. if (w->event)
  571. dev_dbg(w->dapm->dev, "power %s event for %s flags %x\n",
  572. w->power ? "on" : "off",
  573. w->name, w->event_flags);
  574. /* power up pre event */
  575. if (w->power && w->event &&
  576. (w->event_flags & SND_SOC_DAPM_PRE_PMU)) {
  577. ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU);
  578. if (ret < 0)
  579. return ret;
  580. }
  581. /* power down pre event */
  582. if (!w->power && w->event &&
  583. (w->event_flags & SND_SOC_DAPM_PRE_PMD)) {
  584. ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD);
  585. if (ret < 0)
  586. return ret;
  587. }
  588. dapm_update_bits(w);
  589. /* power up post event */
  590. if (w->power && w->event &&
  591. (w->event_flags & SND_SOC_DAPM_POST_PMU)) {
  592. ret = w->event(w,
  593. NULL, SND_SOC_DAPM_POST_PMU);
  594. if (ret < 0)
  595. return ret;
  596. }
  597. /* power down post event */
  598. if (!w->power && w->event &&
  599. (w->event_flags & SND_SOC_DAPM_POST_PMD)) {
  600. ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD);
  601. if (ret < 0)
  602. return ret;
  603. }
  604. return 0;
  605. }
  606. /* Generic check to see if a widget should be powered.
  607. */
  608. static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
  609. {
  610. int in, out;
  611. in = is_connected_input_ep(w);
  612. dapm_clear_walk(w->dapm);
  613. out = is_connected_output_ep(w);
  614. dapm_clear_walk(w->dapm);
  615. return out != 0 && in != 0;
  616. }
  617. /* Check to see if an ADC has power */
  618. static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
  619. {
  620. int in;
  621. if (w->active) {
  622. in = is_connected_input_ep(w);
  623. dapm_clear_walk(w->dapm);
  624. return in != 0;
  625. } else {
  626. return dapm_generic_check_power(w);
  627. }
  628. }
  629. /* Check to see if a DAC has power */
  630. static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
  631. {
  632. int out;
  633. if (w->active) {
  634. out = is_connected_output_ep(w);
  635. dapm_clear_walk(w->dapm);
  636. return out != 0;
  637. } else {
  638. return dapm_generic_check_power(w);
  639. }
  640. }
  641. /* Check to see if a power supply is needed */
  642. static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
  643. {
  644. struct snd_soc_dapm_path *path;
  645. int power = 0;
  646. /* Check if one of our outputs is connected */
  647. list_for_each_entry(path, &w->sinks, list_source) {
  648. if (path->connected &&
  649. !path->connected(path->source, path->sink))
  650. continue;
  651. if (!path->sink)
  652. continue;
  653. if (path->sink->force) {
  654. power = 1;
  655. break;
  656. }
  657. if (path->sink->power_check &&
  658. path->sink->power_check(path->sink)) {
  659. power = 1;
  660. break;
  661. }
  662. }
  663. dapm_clear_walk(w->dapm);
  664. return power;
  665. }
  666. static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
  667. struct snd_soc_dapm_widget *b,
  668. bool power_up)
  669. {
  670. int *sort;
  671. if (power_up)
  672. sort = dapm_up_seq;
  673. else
  674. sort = dapm_down_seq;
  675. if (sort[a->id] != sort[b->id])
  676. return sort[a->id] - sort[b->id];
  677. if (a->subseq != b->subseq) {
  678. if (power_up)
  679. return a->subseq - b->subseq;
  680. else
  681. return b->subseq - a->subseq;
  682. }
  683. if (a->reg != b->reg)
  684. return a->reg - b->reg;
  685. if (a->dapm != b->dapm)
  686. return (unsigned long)a->dapm - (unsigned long)b->dapm;
  687. return 0;
  688. }
  689. /* Insert a widget in order into a DAPM power sequence. */
  690. static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
  691. struct list_head *list,
  692. bool power_up)
  693. {
  694. struct snd_soc_dapm_widget *w;
  695. list_for_each_entry(w, list, power_list)
  696. if (dapm_seq_compare(new_widget, w, power_up) < 0) {
  697. list_add_tail(&new_widget->power_list, &w->power_list);
  698. return;
  699. }
  700. list_add_tail(&new_widget->power_list, list);
  701. }
  702. static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm,
  703. struct snd_soc_dapm_widget *w, int event)
  704. {
  705. struct snd_soc_card *card = dapm->card;
  706. const char *ev_name;
  707. int power, ret;
  708. switch (event) {
  709. case SND_SOC_DAPM_PRE_PMU:
  710. ev_name = "PRE_PMU";
  711. power = 1;
  712. break;
  713. case SND_SOC_DAPM_POST_PMU:
  714. ev_name = "POST_PMU";
  715. power = 1;
  716. break;
  717. case SND_SOC_DAPM_PRE_PMD:
  718. ev_name = "PRE_PMD";
  719. power = 0;
  720. break;
  721. case SND_SOC_DAPM_POST_PMD:
  722. ev_name = "POST_PMD";
  723. power = 0;
  724. break;
  725. default:
  726. BUG();
  727. return;
  728. }
  729. if (w->power != power)
  730. return;
  731. if (w->event && (w->event_flags & event)) {
  732. pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n",
  733. w->name, ev_name);
  734. trace_snd_soc_dapm_widget_event_start(w, event);
  735. ret = w->event(w, NULL, event);
  736. trace_snd_soc_dapm_widget_event_done(w, event);
  737. if (ret < 0)
  738. pr_err("%s: %s event failed: %d\n",
  739. ev_name, w->name, ret);
  740. }
  741. }
  742. /* Apply the coalesced changes from a DAPM sequence */
  743. static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
  744. struct list_head *pending)
  745. {
  746. struct snd_soc_card *card = dapm->card;
  747. struct snd_soc_dapm_widget *w;
  748. int reg, power;
  749. unsigned int value = 0;
  750. unsigned int mask = 0;
  751. unsigned int cur_mask;
  752. reg = list_first_entry(pending, struct snd_soc_dapm_widget,
  753. power_list)->reg;
  754. list_for_each_entry(w, pending, power_list) {
  755. cur_mask = 1 << w->shift;
  756. BUG_ON(reg != w->reg);
  757. if (w->invert)
  758. power = !w->power;
  759. else
  760. power = w->power;
  761. mask |= cur_mask;
  762. if (power)
  763. value |= cur_mask;
  764. pop_dbg(dapm->dev, card->pop_time,
  765. "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
  766. w->name, reg, value, mask);
  767. /* Check for events */
  768. dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU);
  769. dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD);
  770. }
  771. if (reg >= 0) {
  772. pop_dbg(dapm->dev, card->pop_time,
  773. "pop test : Applying 0x%x/0x%x to %x in %dms\n",
  774. value, mask, reg, card->pop_time);
  775. pop_wait(card->pop_time);
  776. snd_soc_update_bits(dapm->codec, reg, mask, value);
  777. }
  778. list_for_each_entry(w, pending, power_list) {
  779. dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
  780. dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
  781. }
  782. }
  783. /* Apply a DAPM power sequence.
  784. *
  785. * We walk over a pre-sorted list of widgets to apply power to. In
  786. * order to minimise the number of writes to the device required
  787. * multiple widgets will be updated in a single write where possible.
  788. * Currently anything that requires more than a single write is not
  789. * handled.
  790. */
  791. static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
  792. struct list_head *list, int event, bool power_up)
  793. {
  794. struct snd_soc_dapm_widget *w, *n;
  795. LIST_HEAD(pending);
  796. int cur_sort = -1;
  797. int cur_subseq = -1;
  798. int cur_reg = SND_SOC_NOPM;
  799. struct snd_soc_dapm_context *cur_dapm = NULL;
  800. int ret, i;
  801. int *sort;
  802. if (power_up)
  803. sort = dapm_up_seq;
  804. else
  805. sort = dapm_down_seq;
  806. list_for_each_entry_safe(w, n, list, power_list) {
  807. ret = 0;
  808. /* Do we need to apply any queued changes? */
  809. if (sort[w->id] != cur_sort || w->reg != cur_reg ||
  810. w->dapm != cur_dapm || w->subseq != cur_subseq) {
  811. if (!list_empty(&pending))
  812. dapm_seq_run_coalesced(cur_dapm, &pending);
  813. if (cur_dapm && cur_dapm->seq_notifier) {
  814. for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
  815. if (sort[i] == cur_sort)
  816. cur_dapm->seq_notifier(cur_dapm,
  817. i,
  818. cur_subseq);
  819. }
  820. INIT_LIST_HEAD(&pending);
  821. cur_sort = -1;
  822. cur_subseq = -1;
  823. cur_reg = SND_SOC_NOPM;
  824. cur_dapm = NULL;
  825. }
  826. switch (w->id) {
  827. case snd_soc_dapm_pre:
  828. if (!w->event)
  829. list_for_each_entry_safe_continue(w, n, list,
  830. power_list);
  831. if (event == SND_SOC_DAPM_STREAM_START)
  832. ret = w->event(w,
  833. NULL, SND_SOC_DAPM_PRE_PMU);
  834. else if (event == SND_SOC_DAPM_STREAM_STOP)
  835. ret = w->event(w,
  836. NULL, SND_SOC_DAPM_PRE_PMD);
  837. break;
  838. case snd_soc_dapm_post:
  839. if (!w->event)
  840. list_for_each_entry_safe_continue(w, n, list,
  841. power_list);
  842. if (event == SND_SOC_DAPM_STREAM_START)
  843. ret = w->event(w,
  844. NULL, SND_SOC_DAPM_POST_PMU);
  845. else if (event == SND_SOC_DAPM_STREAM_STOP)
  846. ret = w->event(w,
  847. NULL, SND_SOC_DAPM_POST_PMD);
  848. break;
  849. case snd_soc_dapm_input:
  850. case snd_soc_dapm_output:
  851. case snd_soc_dapm_hp:
  852. case snd_soc_dapm_mic:
  853. case snd_soc_dapm_line:
  854. case snd_soc_dapm_spk:
  855. /* No register support currently */
  856. ret = dapm_generic_apply_power(w);
  857. break;
  858. default:
  859. /* Queue it up for application */
  860. cur_sort = sort[w->id];
  861. cur_subseq = w->subseq;
  862. cur_reg = w->reg;
  863. cur_dapm = w->dapm;
  864. list_move(&w->power_list, &pending);
  865. break;
  866. }
  867. if (ret < 0)
  868. dev_err(w->dapm->dev,
  869. "Failed to apply widget power: %d\n", ret);
  870. }
  871. if (!list_empty(&pending))
  872. dapm_seq_run_coalesced(cur_dapm, &pending);
  873. if (cur_dapm && cur_dapm->seq_notifier) {
  874. for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
  875. if (sort[i] == cur_sort)
  876. cur_dapm->seq_notifier(cur_dapm,
  877. i, cur_subseq);
  878. }
  879. }
  880. static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
  881. {
  882. struct snd_soc_dapm_update *update = dapm->update;
  883. struct snd_soc_dapm_widget *w;
  884. int ret;
  885. if (!update)
  886. return;
  887. w = update->widget;
  888. if (w->event &&
  889. (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
  890. ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
  891. if (ret != 0)
  892. pr_err("%s DAPM pre-event failed: %d\n",
  893. w->name, ret);
  894. }
  895. ret = snd_soc_update_bits(w->codec, update->reg, update->mask,
  896. update->val);
  897. if (ret < 0)
  898. pr_err("%s DAPM update failed: %d\n", w->name, ret);
  899. if (w->event &&
  900. (w->event_flags & SND_SOC_DAPM_POST_REG)) {
  901. ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
  902. if (ret != 0)
  903. pr_err("%s DAPM post-event failed: %d\n",
  904. w->name, ret);
  905. }
  906. }
  907. /* Async callback run prior to DAPM sequences - brings to _PREPARE if
  908. * they're changing state.
  909. */
  910. static void dapm_pre_sequence_async(void *data, async_cookie_t cookie)
  911. {
  912. struct snd_soc_dapm_context *d = data;
  913. int ret;
  914. if (d->dev_power && d->bias_level == SND_SOC_BIAS_OFF) {
  915. ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
  916. if (ret != 0)
  917. dev_err(d->dev,
  918. "Failed to turn on bias: %d\n", ret);
  919. }
  920. /* If we're changing to all on or all off then prepare */
  921. if ((d->dev_power && d->bias_level == SND_SOC_BIAS_STANDBY) ||
  922. (!d->dev_power && d->bias_level == SND_SOC_BIAS_ON)) {
  923. ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE);
  924. if (ret != 0)
  925. dev_err(d->dev,
  926. "Failed to prepare bias: %d\n", ret);
  927. }
  928. }
  929. /* Async callback run prior to DAPM sequences - brings to their final
  930. * state.
  931. */
  932. static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
  933. {
  934. struct snd_soc_dapm_context *d = data;
  935. int ret;
  936. /* If we just powered the last thing off drop to standby bias */
  937. if (d->bias_level == SND_SOC_BIAS_PREPARE && !d->dev_power) {
  938. ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
  939. if (ret != 0)
  940. dev_err(d->dev, "Failed to apply standby bias: %d\n",
  941. ret);
  942. }
  943. /* If we're in standby and can support bias off then do that */
  944. if (d->bias_level == SND_SOC_BIAS_STANDBY && d->idle_bias_off) {
  945. ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF);
  946. if (ret != 0)
  947. dev_err(d->dev, "Failed to turn off bias: %d\n", ret);
  948. }
  949. /* If we just powered up then move to active bias */
  950. if (d->bias_level == SND_SOC_BIAS_PREPARE && d->dev_power) {
  951. ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON);
  952. if (ret != 0)
  953. dev_err(d->dev, "Failed to apply active bias: %d\n",
  954. ret);
  955. }
  956. }
  957. /*
  958. * Scan each dapm widget for complete audio path.
  959. * A complete path is a route that has valid endpoints i.e.:-
  960. *
  961. * o DAC to output pin.
  962. * o Input Pin to ADC.
  963. * o Input pin to Output pin (bypass, sidetone)
  964. * o DAC to ADC (loopback).
  965. */
  966. static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
  967. {
  968. struct snd_soc_card *card = dapm->card;
  969. struct snd_soc_dapm_widget *w;
  970. struct snd_soc_dapm_context *d;
  971. LIST_HEAD(up_list);
  972. LIST_HEAD(down_list);
  973. LIST_HEAD(async_domain);
  974. int power;
  975. trace_snd_soc_dapm_start(card);
  976. list_for_each_entry(d, &card->dapm_list, list)
  977. if (d->n_widgets)
  978. d->dev_power = 0;
  979. /* Check which widgets we need to power and store them in
  980. * lists indicating if they should be powered up or down.
  981. */
  982. list_for_each_entry(w, &card->widgets, list) {
  983. switch (w->id) {
  984. case snd_soc_dapm_pre:
  985. dapm_seq_insert(w, &down_list, false);
  986. break;
  987. case snd_soc_dapm_post:
  988. dapm_seq_insert(w, &up_list, true);
  989. break;
  990. default:
  991. if (!w->power_check)
  992. continue;
  993. if (!w->force)
  994. power = w->power_check(w);
  995. else
  996. power = 1;
  997. if (power)
  998. w->dapm->dev_power = 1;
  999. if (w->power == power)
  1000. continue;
  1001. trace_snd_soc_dapm_widget_power(w, power);
  1002. if (power)
  1003. dapm_seq_insert(w, &up_list, true);
  1004. else
  1005. dapm_seq_insert(w, &down_list, false);
  1006. w->power = power;
  1007. break;
  1008. }
  1009. }
  1010. /* If there are no DAPM widgets then try to figure out power from the
  1011. * event type.
  1012. */
  1013. if (!dapm->n_widgets) {
  1014. switch (event) {
  1015. case SND_SOC_DAPM_STREAM_START:
  1016. case SND_SOC_DAPM_STREAM_RESUME:
  1017. dapm->dev_power = 1;
  1018. break;
  1019. case SND_SOC_DAPM_STREAM_STOP:
  1020. dapm->dev_power = !!dapm->codec->active;
  1021. break;
  1022. case SND_SOC_DAPM_STREAM_SUSPEND:
  1023. dapm->dev_power = 0;
  1024. break;
  1025. case SND_SOC_DAPM_STREAM_NOP:
  1026. switch (dapm->bias_level) {
  1027. case SND_SOC_BIAS_STANDBY:
  1028. case SND_SOC_BIAS_OFF:
  1029. dapm->dev_power = 0;
  1030. break;
  1031. default:
  1032. dapm->dev_power = 1;
  1033. break;
  1034. }
  1035. break;
  1036. default:
  1037. break;
  1038. }
  1039. }
  1040. /* Run all the bias changes in parallel */
  1041. list_for_each_entry(d, &dapm->card->dapm_list, list)
  1042. async_schedule_domain(dapm_pre_sequence_async, d,
  1043. &async_domain);
  1044. async_synchronize_full_domain(&async_domain);
  1045. /* Power down widgets first; try to avoid amplifying pops. */
  1046. dapm_seq_run(dapm, &down_list, event, false);
  1047. dapm_widget_update(dapm);
  1048. /* Now power up. */
  1049. dapm_seq_run(dapm, &up_list, event, true);
  1050. /* Run all the bias changes in parallel */
  1051. list_for_each_entry(d, &dapm->card->dapm_list, list)
  1052. async_schedule_domain(dapm_post_sequence_async, d,
  1053. &async_domain);
  1054. async_synchronize_full_domain(&async_domain);
  1055. pop_dbg(dapm->dev, card->pop_time,
  1056. "DAPM sequencing finished, waiting %dms\n", card->pop_time);
  1057. pop_wait(card->pop_time);
  1058. trace_snd_soc_dapm_done(card);
  1059. return 0;
  1060. }
  1061. #ifdef CONFIG_DEBUG_FS
  1062. static int dapm_widget_power_open_file(struct inode *inode, struct file *file)
  1063. {
  1064. file->private_data = inode->i_private;
  1065. return 0;
  1066. }
  1067. static ssize_t dapm_widget_power_read_file(struct file *file,
  1068. char __user *user_buf,
  1069. size_t count, loff_t *ppos)
  1070. {
  1071. struct snd_soc_dapm_widget *w = file->private_data;
  1072. char *buf;
  1073. int in, out;
  1074. ssize_t ret;
  1075. struct snd_soc_dapm_path *p = NULL;
  1076. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  1077. if (!buf)
  1078. return -ENOMEM;
  1079. in = is_connected_input_ep(w);
  1080. dapm_clear_walk(w->dapm);
  1081. out = is_connected_output_ep(w);
  1082. dapm_clear_walk(w->dapm);
  1083. ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d",
  1084. w->name, w->power ? "On" : "Off", in, out);
  1085. if (w->reg >= 0)
  1086. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  1087. " - R%d(0x%x) bit %d",
  1088. w->reg, w->reg, w->shift);
  1089. ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
  1090. if (w->sname)
  1091. ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
  1092. w->sname,
  1093. w->active ? "active" : "inactive");
  1094. list_for_each_entry(p, &w->sources, list_sink) {
  1095. if (p->connected && !p->connected(w, p->sink))
  1096. continue;
  1097. if (p->connect)
  1098. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  1099. " in \"%s\" \"%s\"\n",
  1100. p->name ? p->name : "static",
  1101. p->source->name);
  1102. }
  1103. list_for_each_entry(p, &w->sinks, list_source) {
  1104. if (p->connected && !p->connected(w, p->sink))
  1105. continue;
  1106. if (p->connect)
  1107. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  1108. " out \"%s\" \"%s\"\n",
  1109. p->name ? p->name : "static",
  1110. p->sink->name);
  1111. }
  1112. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  1113. kfree(buf);
  1114. return ret;
  1115. }
  1116. static const struct file_operations dapm_widget_power_fops = {
  1117. .open = dapm_widget_power_open_file,
  1118. .read = dapm_widget_power_read_file,
  1119. .llseek = default_llseek,
  1120. };
  1121. void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm)
  1122. {
  1123. struct snd_soc_dapm_widget *w;
  1124. struct dentry *d;
  1125. if (!dapm->debugfs_dapm)
  1126. return;
  1127. list_for_each_entry(w, &dapm->card->widgets, list) {
  1128. if (!w->name || w->dapm != dapm)
  1129. continue;
  1130. d = debugfs_create_file(w->name, 0444,
  1131. dapm->debugfs_dapm, w,
  1132. &dapm_widget_power_fops);
  1133. if (!d)
  1134. dev_warn(w->dapm->dev,
  1135. "ASoC: Failed to create %s debugfs file\n",
  1136. w->name);
  1137. }
  1138. }
  1139. #else
  1140. void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm)
  1141. {
  1142. }
  1143. #endif
  1144. /* test and update the power status of a mux widget */
  1145. static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
  1146. struct snd_kcontrol *kcontrol, int change,
  1147. int mux, struct soc_enum *e)
  1148. {
  1149. struct snd_soc_dapm_path *path;
  1150. int found = 0;
  1151. if (widget->id != snd_soc_dapm_mux &&
  1152. widget->id != snd_soc_dapm_virt_mux &&
  1153. widget->id != snd_soc_dapm_value_mux)
  1154. return -ENODEV;
  1155. if (!change)
  1156. return 0;
  1157. /* find dapm widget path assoc with kcontrol */
  1158. list_for_each_entry(path, &widget->dapm->card->paths, list) {
  1159. if (path->kcontrol != kcontrol)
  1160. continue;
  1161. if (!path->name || !e->texts[mux])
  1162. continue;
  1163. found = 1;
  1164. /* we now need to match the string in the enum to the path */
  1165. if (!(strcmp(path->name, e->texts[mux])))
  1166. path->connect = 1; /* new connection */
  1167. else
  1168. path->connect = 0; /* old connection must be powered down */
  1169. }
  1170. if (found)
  1171. dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
  1172. return 0;
  1173. }
  1174. /* test and update the power status of a mixer or switch widget */
  1175. static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
  1176. struct snd_kcontrol *kcontrol, int connect)
  1177. {
  1178. struct snd_soc_dapm_path *path;
  1179. int found = 0;
  1180. if (widget->id != snd_soc_dapm_mixer &&
  1181. widget->id != snd_soc_dapm_mixer_named_ctl &&
  1182. widget->id != snd_soc_dapm_switch)
  1183. return -ENODEV;
  1184. /* find dapm widget path assoc with kcontrol */
  1185. list_for_each_entry(path, &widget->dapm->card->paths, list) {
  1186. if (path->kcontrol != kcontrol)
  1187. continue;
  1188. /* found, now check type */
  1189. found = 1;
  1190. path->connect = connect;
  1191. break;
  1192. }
  1193. if (found)
  1194. dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
  1195. return 0;
  1196. }
  1197. /* show dapm widget status in sys fs */
  1198. static ssize_t dapm_widget_show(struct device *dev,
  1199. struct device_attribute *attr, char *buf)
  1200. {
  1201. struct snd_soc_pcm_runtime *rtd =
  1202. container_of(dev, struct snd_soc_pcm_runtime, dev);
  1203. struct snd_soc_codec *codec =rtd->codec;
  1204. struct snd_soc_dapm_widget *w;
  1205. int count = 0;
  1206. char *state = "not set";
  1207. list_for_each_entry(w, &codec->card->widgets, list) {
  1208. if (w->dapm != &codec->dapm)
  1209. continue;
  1210. /* only display widgets that burnm power */
  1211. switch (w->id) {
  1212. case snd_soc_dapm_hp:
  1213. case snd_soc_dapm_mic:
  1214. case snd_soc_dapm_spk:
  1215. case snd_soc_dapm_line:
  1216. case snd_soc_dapm_micbias:
  1217. case snd_soc_dapm_dac:
  1218. case snd_soc_dapm_adc:
  1219. case snd_soc_dapm_pga:
  1220. case snd_soc_dapm_out_drv:
  1221. case snd_soc_dapm_mixer:
  1222. case snd_soc_dapm_mixer_named_ctl:
  1223. case snd_soc_dapm_supply:
  1224. if (w->name)
  1225. count += sprintf(buf + count, "%s: %s\n",
  1226. w->name, w->power ? "On":"Off");
  1227. break;
  1228. default:
  1229. break;
  1230. }
  1231. }
  1232. switch (codec->dapm.bias_level) {
  1233. case SND_SOC_BIAS_ON:
  1234. state = "On";
  1235. break;
  1236. case SND_SOC_BIAS_PREPARE:
  1237. state = "Prepare";
  1238. break;
  1239. case SND_SOC_BIAS_STANDBY:
  1240. state = "Standby";
  1241. break;
  1242. case SND_SOC_BIAS_OFF:
  1243. state = "Off";
  1244. break;
  1245. }
  1246. count += sprintf(buf + count, "PM State: %s\n", state);
  1247. return count;
  1248. }
  1249. static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
  1250. int snd_soc_dapm_sys_add(struct device *dev)
  1251. {
  1252. return device_create_file(dev, &dev_attr_dapm_widget);
  1253. }
  1254. static void snd_soc_dapm_sys_remove(struct device *dev)
  1255. {
  1256. device_remove_file(dev, &dev_attr_dapm_widget);
  1257. }
  1258. /* free all dapm widgets and resources */
  1259. static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
  1260. {
  1261. struct snd_soc_dapm_widget *w, *next_w;
  1262. struct snd_soc_dapm_path *p, *next_p;
  1263. list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
  1264. if (w->dapm != dapm)
  1265. continue;
  1266. list_del(&w->list);
  1267. /*
  1268. * remove source and sink paths associated to this widget.
  1269. * While removing the path, remove reference to it from both
  1270. * source and sink widgets so that path is removed only once.
  1271. */
  1272. list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
  1273. list_del(&p->list_sink);
  1274. list_del(&p->list_source);
  1275. list_del(&p->list);
  1276. kfree(p->long_name);
  1277. kfree(p);
  1278. }
  1279. list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
  1280. list_del(&p->list_sink);
  1281. list_del(&p->list_source);
  1282. list_del(&p->list);
  1283. kfree(p->long_name);
  1284. kfree(p);
  1285. }
  1286. kfree(w->name);
  1287. kfree(w);
  1288. }
  1289. }
  1290. static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
  1291. const char *pin, int status)
  1292. {
  1293. struct snd_soc_dapm_widget *w;
  1294. list_for_each_entry(w, &dapm->card->widgets, list) {
  1295. if (w->dapm != dapm)
  1296. continue;
  1297. if (!strcmp(w->name, pin)) {
  1298. dev_dbg(w->dapm->dev, "dapm: pin %s = %d\n",
  1299. pin, status);
  1300. w->connected = status;
  1301. /* Allow disabling of forced pins */
  1302. if (status == 0)
  1303. w->force = 0;
  1304. return 0;
  1305. }
  1306. }
  1307. dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
  1308. return -EINVAL;
  1309. }
  1310. /**
  1311. * snd_soc_dapm_sync - scan and power dapm paths
  1312. * @dapm: DAPM context
  1313. *
  1314. * Walks all dapm audio paths and powers widgets according to their
  1315. * stream or path usage.
  1316. *
  1317. * Returns 0 for success.
  1318. */
  1319. int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
  1320. {
  1321. return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
  1322. }
  1323. EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
  1324. static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
  1325. const struct snd_soc_dapm_route *route)
  1326. {
  1327. struct snd_soc_dapm_path *path;
  1328. struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
  1329. struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
  1330. const char *sink;
  1331. const char *control = route->control;
  1332. const char *source;
  1333. char prefixed_sink[80];
  1334. char prefixed_source[80];
  1335. int ret = 0;
  1336. if (dapm->codec && dapm->codec->name_prefix) {
  1337. snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
  1338. dapm->codec->name_prefix, route->sink);
  1339. sink = prefixed_sink;
  1340. snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
  1341. dapm->codec->name_prefix, route->source);
  1342. source = prefixed_source;
  1343. } else {
  1344. sink = route->sink;
  1345. source = route->source;
  1346. }
  1347. /*
  1348. * find src and dest widgets over all widgets but favor a widget from
  1349. * current DAPM context
  1350. */
  1351. list_for_each_entry(w, &dapm->card->widgets, list) {
  1352. if (!wsink && !(strcmp(w->name, sink))) {
  1353. wtsink = w;
  1354. if (w->dapm == dapm)
  1355. wsink = w;
  1356. continue;
  1357. }
  1358. if (!wsource && !(strcmp(w->name, source))) {
  1359. wtsource = w;
  1360. if (w->dapm == dapm)
  1361. wsource = w;
  1362. }
  1363. }
  1364. /* use widget from another DAPM context if not found from this */
  1365. if (!wsink)
  1366. wsink = wtsink;
  1367. if (!wsource)
  1368. wsource = wtsource;
  1369. if (wsource == NULL || wsink == NULL)
  1370. return -ENODEV;
  1371. path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
  1372. if (!path)
  1373. return -ENOMEM;
  1374. path->source = wsource;
  1375. path->sink = wsink;
  1376. path->connected = route->connected;
  1377. INIT_LIST_HEAD(&path->list);
  1378. INIT_LIST_HEAD(&path->list_source);
  1379. INIT_LIST_HEAD(&path->list_sink);
  1380. /* check for external widgets */
  1381. if (wsink->id == snd_soc_dapm_input) {
  1382. if (wsource->id == snd_soc_dapm_micbias ||
  1383. wsource->id == snd_soc_dapm_mic ||
  1384. wsource->id == snd_soc_dapm_line ||
  1385. wsource->id == snd_soc_dapm_output)
  1386. wsink->ext = 1;
  1387. }
  1388. if (wsource->id == snd_soc_dapm_output) {
  1389. if (wsink->id == snd_soc_dapm_spk ||
  1390. wsink->id == snd_soc_dapm_hp ||
  1391. wsink->id == snd_soc_dapm_line ||
  1392. wsink->id == snd_soc_dapm_input)
  1393. wsource->ext = 1;
  1394. }
  1395. /* connect static paths */
  1396. if (control == NULL) {
  1397. list_add(&path->list, &dapm->card->paths);
  1398. list_add(&path->list_sink, &wsink->sources);
  1399. list_add(&path->list_source, &wsource->sinks);
  1400. path->connect = 1;
  1401. return 0;
  1402. }
  1403. /* connect dynamic paths */
  1404. switch(wsink->id) {
  1405. case snd_soc_dapm_adc:
  1406. case snd_soc_dapm_dac:
  1407. case snd_soc_dapm_pga:
  1408. case snd_soc_dapm_out_drv:
  1409. case snd_soc_dapm_input:
  1410. case snd_soc_dapm_output:
  1411. case snd_soc_dapm_micbias:
  1412. case snd_soc_dapm_vmid:
  1413. case snd_soc_dapm_pre:
  1414. case snd_soc_dapm_post:
  1415. case snd_soc_dapm_supply:
  1416. case snd_soc_dapm_aif_in:
  1417. case snd_soc_dapm_aif_out:
  1418. list_add(&path->list, &dapm->card->paths);
  1419. list_add(&path->list_sink, &wsink->sources);
  1420. list_add(&path->list_source, &wsource->sinks);
  1421. path->connect = 1;
  1422. return 0;
  1423. case snd_soc_dapm_mux:
  1424. case snd_soc_dapm_virt_mux:
  1425. case snd_soc_dapm_value_mux:
  1426. ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
  1427. &wsink->kcontrols[0]);
  1428. if (ret != 0)
  1429. goto err;
  1430. break;
  1431. case snd_soc_dapm_switch:
  1432. case snd_soc_dapm_mixer:
  1433. case snd_soc_dapm_mixer_named_ctl:
  1434. ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
  1435. if (ret != 0)
  1436. goto err;
  1437. break;
  1438. case snd_soc_dapm_hp:
  1439. case snd_soc_dapm_mic:
  1440. case snd_soc_dapm_line:
  1441. case snd_soc_dapm_spk:
  1442. list_add(&path->list, &dapm->card->paths);
  1443. list_add(&path->list_sink, &wsink->sources);
  1444. list_add(&path->list_source, &wsource->sinks);
  1445. path->connect = 0;
  1446. return 0;
  1447. }
  1448. return 0;
  1449. err:
  1450. dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n",
  1451. source, control, sink);
  1452. kfree(path);
  1453. return ret;
  1454. }
  1455. /**
  1456. * snd_soc_dapm_add_routes - Add routes between DAPM widgets
  1457. * @dapm: DAPM context
  1458. * @route: audio routes
  1459. * @num: number of routes
  1460. *
  1461. * Connects 2 dapm widgets together via a named audio path. The sink is
  1462. * the widget receiving the audio signal, whilst the source is the sender
  1463. * of the audio signal.
  1464. *
  1465. * Returns 0 for success else error. On error all resources can be freed
  1466. * with a call to snd_soc_card_free().
  1467. */
  1468. int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
  1469. const struct snd_soc_dapm_route *route, int num)
  1470. {
  1471. int i, ret;
  1472. for (i = 0; i < num; i++) {
  1473. ret = snd_soc_dapm_add_route(dapm, route);
  1474. if (ret < 0) {
  1475. dev_err(dapm->dev, "Failed to add route %s->%s\n",
  1476. route->source, route->sink);
  1477. return ret;
  1478. }
  1479. route++;
  1480. }
  1481. return 0;
  1482. }
  1483. EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
  1484. /**
  1485. * snd_soc_dapm_new_widgets - add new dapm widgets
  1486. * @dapm: DAPM context
  1487. *
  1488. * Checks the codec for any new dapm widgets and creates them if found.
  1489. *
  1490. * Returns 0 for success.
  1491. */
  1492. int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
  1493. {
  1494. struct snd_soc_dapm_widget *w;
  1495. unsigned int val;
  1496. list_for_each_entry(w, &dapm->card->widgets, list)
  1497. {
  1498. if (w->new)
  1499. continue;
  1500. switch(w->id) {
  1501. case snd_soc_dapm_switch:
  1502. case snd_soc_dapm_mixer:
  1503. case snd_soc_dapm_mixer_named_ctl:
  1504. w->power_check = dapm_generic_check_power;
  1505. dapm_new_mixer(dapm, w);
  1506. break;
  1507. case snd_soc_dapm_mux:
  1508. case snd_soc_dapm_virt_mux:
  1509. case snd_soc_dapm_value_mux:
  1510. w->power_check = dapm_generic_check_power;
  1511. dapm_new_mux(dapm, w);
  1512. break;
  1513. case snd_soc_dapm_adc:
  1514. case snd_soc_dapm_aif_out:
  1515. w->power_check = dapm_adc_check_power;
  1516. break;
  1517. case snd_soc_dapm_dac:
  1518. case snd_soc_dapm_aif_in:
  1519. w->power_check = dapm_dac_check_power;
  1520. break;
  1521. case snd_soc_dapm_pga:
  1522. case snd_soc_dapm_out_drv:
  1523. w->power_check = dapm_generic_check_power;
  1524. dapm_new_pga(dapm, w);
  1525. break;
  1526. case snd_soc_dapm_input:
  1527. case snd_soc_dapm_output:
  1528. case snd_soc_dapm_micbias:
  1529. case snd_soc_dapm_spk:
  1530. case snd_soc_dapm_hp:
  1531. case snd_soc_dapm_mic:
  1532. case snd_soc_dapm_line:
  1533. w->power_check = dapm_generic_check_power;
  1534. break;
  1535. case snd_soc_dapm_supply:
  1536. w->power_check = dapm_supply_check_power;
  1537. case snd_soc_dapm_vmid:
  1538. case snd_soc_dapm_pre:
  1539. case snd_soc_dapm_post:
  1540. break;
  1541. }
  1542. /* Read the initial power state from the device */
  1543. if (w->reg >= 0) {
  1544. val = snd_soc_read(w->codec, w->reg);
  1545. val &= 1 << w->shift;
  1546. if (w->invert)
  1547. val = !val;
  1548. if (val)
  1549. w->power = 1;
  1550. }
  1551. w->new = 1;
  1552. }
  1553. dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
  1554. return 0;
  1555. }
  1556. EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
  1557. /**
  1558. * snd_soc_dapm_get_volsw - dapm mixer get callback
  1559. * @kcontrol: mixer control
  1560. * @ucontrol: control element information
  1561. *
  1562. * Callback to get the value of a dapm mixer control.
  1563. *
  1564. * Returns 0 for success.
  1565. */
  1566. int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
  1567. struct snd_ctl_elem_value *ucontrol)
  1568. {
  1569. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1570. struct soc_mixer_control *mc =
  1571. (struct soc_mixer_control *)kcontrol->private_value;
  1572. unsigned int reg = mc->reg;
  1573. unsigned int shift = mc->shift;
  1574. unsigned int rshift = mc->rshift;
  1575. int max = mc->max;
  1576. unsigned int invert = mc->invert;
  1577. unsigned int mask = (1 << fls(max)) - 1;
  1578. ucontrol->value.integer.value[0] =
  1579. (snd_soc_read(widget->codec, reg) >> shift) & mask;
  1580. if (shift != rshift)
  1581. ucontrol->value.integer.value[1] =
  1582. (snd_soc_read(widget->codec, reg) >> rshift) & mask;
  1583. if (invert) {
  1584. ucontrol->value.integer.value[0] =
  1585. max - ucontrol->value.integer.value[0];
  1586. if (shift != rshift)
  1587. ucontrol->value.integer.value[1] =
  1588. max - ucontrol->value.integer.value[1];
  1589. }
  1590. return 0;
  1591. }
  1592. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
  1593. /**
  1594. * snd_soc_dapm_put_volsw - dapm mixer set callback
  1595. * @kcontrol: mixer control
  1596. * @ucontrol: control element information
  1597. *
  1598. * Callback to set the value of a dapm mixer control.
  1599. *
  1600. * Returns 0 for success.
  1601. */
  1602. int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
  1603. struct snd_ctl_elem_value *ucontrol)
  1604. {
  1605. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1606. struct soc_mixer_control *mc =
  1607. (struct soc_mixer_control *)kcontrol->private_value;
  1608. unsigned int reg = mc->reg;
  1609. unsigned int shift = mc->shift;
  1610. int max = mc->max;
  1611. unsigned int mask = (1 << fls(max)) - 1;
  1612. unsigned int invert = mc->invert;
  1613. unsigned int val;
  1614. int connect, change;
  1615. struct snd_soc_dapm_update update;
  1616. val = (ucontrol->value.integer.value[0] & mask);
  1617. if (invert)
  1618. val = max - val;
  1619. mask = mask << shift;
  1620. val = val << shift;
  1621. mutex_lock(&widget->codec->mutex);
  1622. widget->value = val;
  1623. change = snd_soc_test_bits(widget->codec, reg, mask, val);
  1624. if (change) {
  1625. if (val)
  1626. /* new connection */
  1627. connect = invert ? 0:1;
  1628. else
  1629. /* old connection must be powered down */
  1630. connect = invert ? 1:0;
  1631. update.kcontrol = kcontrol;
  1632. update.widget = widget;
  1633. update.reg = reg;
  1634. update.mask = mask;
  1635. update.val = val;
  1636. widget->dapm->update = &update;
  1637. dapm_mixer_update_power(widget, kcontrol, connect);
  1638. widget->dapm->update = NULL;
  1639. }
  1640. mutex_unlock(&widget->codec->mutex);
  1641. return 0;
  1642. }
  1643. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
  1644. /**
  1645. * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
  1646. * @kcontrol: mixer control
  1647. * @ucontrol: control element information
  1648. *
  1649. * Callback to get the value of a dapm enumerated double mixer control.
  1650. *
  1651. * Returns 0 for success.
  1652. */
  1653. int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
  1654. struct snd_ctl_elem_value *ucontrol)
  1655. {
  1656. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1657. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1658. unsigned int val, bitmask;
  1659. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  1660. ;
  1661. val = snd_soc_read(widget->codec, e->reg);
  1662. ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
  1663. if (e->shift_l != e->shift_r)
  1664. ucontrol->value.enumerated.item[1] =
  1665. (val >> e->shift_r) & (bitmask - 1);
  1666. return 0;
  1667. }
  1668. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
  1669. /**
  1670. * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
  1671. * @kcontrol: mixer control
  1672. * @ucontrol: control element information
  1673. *
  1674. * Callback to set the value of a dapm enumerated double mixer control.
  1675. *
  1676. * Returns 0 for success.
  1677. */
  1678. int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
  1679. struct snd_ctl_elem_value *ucontrol)
  1680. {
  1681. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1682. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1683. unsigned int val, mux, change;
  1684. unsigned int mask, bitmask;
  1685. struct snd_soc_dapm_update update;
  1686. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  1687. ;
  1688. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  1689. return -EINVAL;
  1690. mux = ucontrol->value.enumerated.item[0];
  1691. val = mux << e->shift_l;
  1692. mask = (bitmask - 1) << e->shift_l;
  1693. if (e->shift_l != e->shift_r) {
  1694. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  1695. return -EINVAL;
  1696. val |= ucontrol->value.enumerated.item[1] << e->shift_r;
  1697. mask |= (bitmask - 1) << e->shift_r;
  1698. }
  1699. mutex_lock(&widget->codec->mutex);
  1700. widget->value = val;
  1701. change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
  1702. update.kcontrol = kcontrol;
  1703. update.widget = widget;
  1704. update.reg = e->reg;
  1705. update.mask = mask;
  1706. update.val = val;
  1707. widget->dapm->update = &update;
  1708. dapm_mux_update_power(widget, kcontrol, change, mux, e);
  1709. widget->dapm->update = NULL;
  1710. mutex_unlock(&widget->codec->mutex);
  1711. return change;
  1712. }
  1713. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
  1714. /**
  1715. * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
  1716. * @kcontrol: mixer control
  1717. * @ucontrol: control element information
  1718. *
  1719. * Returns 0 for success.
  1720. */
  1721. int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
  1722. struct snd_ctl_elem_value *ucontrol)
  1723. {
  1724. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1725. ucontrol->value.enumerated.item[0] = widget->value;
  1726. return 0;
  1727. }
  1728. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
  1729. /**
  1730. * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
  1731. * @kcontrol: mixer control
  1732. * @ucontrol: control element information
  1733. *
  1734. * Returns 0 for success.
  1735. */
  1736. int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
  1737. struct snd_ctl_elem_value *ucontrol)
  1738. {
  1739. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1740. struct soc_enum *e =
  1741. (struct soc_enum *)kcontrol->private_value;
  1742. int change;
  1743. int ret = 0;
  1744. if (ucontrol->value.enumerated.item[0] >= e->max)
  1745. return -EINVAL;
  1746. mutex_lock(&widget->codec->mutex);
  1747. change = widget->value != ucontrol->value.enumerated.item[0];
  1748. widget->value = ucontrol->value.enumerated.item[0];
  1749. dapm_mux_update_power(widget, kcontrol, change, widget->value, e);
  1750. mutex_unlock(&widget->codec->mutex);
  1751. return ret;
  1752. }
  1753. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
  1754. /**
  1755. * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
  1756. * callback
  1757. * @kcontrol: mixer control
  1758. * @ucontrol: control element information
  1759. *
  1760. * Callback to get the value of a dapm semi enumerated double mixer control.
  1761. *
  1762. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  1763. * used for handling bitfield coded enumeration for example.
  1764. *
  1765. * Returns 0 for success.
  1766. */
  1767. int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
  1768. struct snd_ctl_elem_value *ucontrol)
  1769. {
  1770. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1771. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1772. unsigned int reg_val, val, mux;
  1773. reg_val = snd_soc_read(widget->codec, e->reg);
  1774. val = (reg_val >> e->shift_l) & e->mask;
  1775. for (mux = 0; mux < e->max; mux++) {
  1776. if (val == e->values[mux])
  1777. break;
  1778. }
  1779. ucontrol->value.enumerated.item[0] = mux;
  1780. if (e->shift_l != e->shift_r) {
  1781. val = (reg_val >> e->shift_r) & e->mask;
  1782. for (mux = 0; mux < e->max; mux++) {
  1783. if (val == e->values[mux])
  1784. break;
  1785. }
  1786. ucontrol->value.enumerated.item[1] = mux;
  1787. }
  1788. return 0;
  1789. }
  1790. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
  1791. /**
  1792. * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
  1793. * callback
  1794. * @kcontrol: mixer control
  1795. * @ucontrol: control element information
  1796. *
  1797. * Callback to set the value of a dapm semi enumerated double mixer control.
  1798. *
  1799. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  1800. * used for handling bitfield coded enumeration for example.
  1801. *
  1802. * Returns 0 for success.
  1803. */
  1804. int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
  1805. struct snd_ctl_elem_value *ucontrol)
  1806. {
  1807. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1808. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1809. unsigned int val, mux, change;
  1810. unsigned int mask;
  1811. struct snd_soc_dapm_update update;
  1812. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  1813. return -EINVAL;
  1814. mux = ucontrol->value.enumerated.item[0];
  1815. val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
  1816. mask = e->mask << e->shift_l;
  1817. if (e->shift_l != e->shift_r) {
  1818. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  1819. return -EINVAL;
  1820. val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
  1821. mask |= e->mask << e->shift_r;
  1822. }
  1823. mutex_lock(&widget->codec->mutex);
  1824. widget->value = val;
  1825. change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
  1826. update.kcontrol = kcontrol;
  1827. update.widget = widget;
  1828. update.reg = e->reg;
  1829. update.mask = mask;
  1830. update.val = val;
  1831. widget->dapm->update = &update;
  1832. dapm_mux_update_power(widget, kcontrol, change, mux, e);
  1833. widget->dapm->update = NULL;
  1834. mutex_unlock(&widget->codec->mutex);
  1835. return change;
  1836. }
  1837. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
  1838. /**
  1839. * snd_soc_dapm_info_pin_switch - Info for a pin switch
  1840. *
  1841. * @kcontrol: mixer control
  1842. * @uinfo: control element information
  1843. *
  1844. * Callback to provide information about a pin switch control.
  1845. */
  1846. int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
  1847. struct snd_ctl_elem_info *uinfo)
  1848. {
  1849. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1850. uinfo->count = 1;
  1851. uinfo->value.integer.min = 0;
  1852. uinfo->value.integer.max = 1;
  1853. return 0;
  1854. }
  1855. EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
  1856. /**
  1857. * snd_soc_dapm_get_pin_switch - Get information for a pin switch
  1858. *
  1859. * @kcontrol: mixer control
  1860. * @ucontrol: Value
  1861. */
  1862. int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
  1863. struct snd_ctl_elem_value *ucontrol)
  1864. {
  1865. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1866. const char *pin = (const char *)kcontrol->private_value;
  1867. mutex_lock(&codec->mutex);
  1868. ucontrol->value.integer.value[0] =
  1869. snd_soc_dapm_get_pin_status(&codec->dapm, pin);
  1870. mutex_unlock(&codec->mutex);
  1871. return 0;
  1872. }
  1873. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
  1874. /**
  1875. * snd_soc_dapm_put_pin_switch - Set information for a pin switch
  1876. *
  1877. * @kcontrol: mixer control
  1878. * @ucontrol: Value
  1879. */
  1880. int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
  1881. struct snd_ctl_elem_value *ucontrol)
  1882. {
  1883. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1884. const char *pin = (const char *)kcontrol->private_value;
  1885. mutex_lock(&codec->mutex);
  1886. if (ucontrol->value.integer.value[0])
  1887. snd_soc_dapm_enable_pin(&codec->dapm, pin);
  1888. else
  1889. snd_soc_dapm_disable_pin(&codec->dapm, pin);
  1890. snd_soc_dapm_sync(&codec->dapm);
  1891. mutex_unlock(&codec->mutex);
  1892. return 0;
  1893. }
  1894. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
  1895. /**
  1896. * snd_soc_dapm_new_control - create new dapm control
  1897. * @dapm: DAPM context
  1898. * @widget: widget template
  1899. *
  1900. * Creates a new dapm control based upon the template.
  1901. *
  1902. * Returns 0 for success else error.
  1903. */
  1904. int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
  1905. const struct snd_soc_dapm_widget *widget)
  1906. {
  1907. struct snd_soc_dapm_widget *w;
  1908. size_t name_len;
  1909. if ((w = dapm_cnew_widget(widget)) == NULL)
  1910. return -ENOMEM;
  1911. name_len = strlen(widget->name) + 1;
  1912. if (dapm->codec && dapm->codec->name_prefix)
  1913. name_len += 1 + strlen(dapm->codec->name_prefix);
  1914. w->name = kmalloc(name_len, GFP_KERNEL);
  1915. if (w->name == NULL) {
  1916. kfree(w);
  1917. return -ENOMEM;
  1918. }
  1919. if (dapm->codec && dapm->codec->name_prefix)
  1920. snprintf(w->name, name_len, "%s %s",
  1921. dapm->codec->name_prefix, widget->name);
  1922. else
  1923. snprintf(w->name, name_len, "%s", widget->name);
  1924. dapm->n_widgets++;
  1925. w->dapm = dapm;
  1926. w->codec = dapm->codec;
  1927. INIT_LIST_HEAD(&w->sources);
  1928. INIT_LIST_HEAD(&w->sinks);
  1929. INIT_LIST_HEAD(&w->list);
  1930. list_add(&w->list, &dapm->card->widgets);
  1931. /* machine layer set ups unconnected pins and insertions */
  1932. w->connected = 1;
  1933. return 0;
  1934. }
  1935. EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
  1936. /**
  1937. * snd_soc_dapm_new_controls - create new dapm controls
  1938. * @dapm: DAPM context
  1939. * @widget: widget array
  1940. * @num: number of widgets
  1941. *
  1942. * Creates new DAPM controls based upon the templates.
  1943. *
  1944. * Returns 0 for success else error.
  1945. */
  1946. int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
  1947. const struct snd_soc_dapm_widget *widget,
  1948. int num)
  1949. {
  1950. int i, ret;
  1951. for (i = 0; i < num; i++) {
  1952. ret = snd_soc_dapm_new_control(dapm, widget);
  1953. if (ret < 0) {
  1954. dev_err(dapm->dev,
  1955. "ASoC: Failed to create DAPM control %s: %d\n",
  1956. widget->name, ret);
  1957. return ret;
  1958. }
  1959. widget++;
  1960. }
  1961. return 0;
  1962. }
  1963. EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
  1964. static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
  1965. const char *stream, int event)
  1966. {
  1967. struct snd_soc_dapm_widget *w;
  1968. list_for_each_entry(w, &dapm->card->widgets, list)
  1969. {
  1970. if (!w->sname || w->dapm != dapm)
  1971. continue;
  1972. dev_dbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n",
  1973. w->name, w->sname, stream, event);
  1974. if (strstr(w->sname, stream)) {
  1975. switch(event) {
  1976. case SND_SOC_DAPM_STREAM_START:
  1977. w->active = 1;
  1978. break;
  1979. case SND_SOC_DAPM_STREAM_STOP:
  1980. w->active = 0;
  1981. break;
  1982. case SND_SOC_DAPM_STREAM_SUSPEND:
  1983. case SND_SOC_DAPM_STREAM_RESUME:
  1984. case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
  1985. case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
  1986. break;
  1987. }
  1988. }
  1989. }
  1990. dapm_power_widgets(dapm, event);
  1991. }
  1992. /**
  1993. * snd_soc_dapm_stream_event - send a stream event to the dapm core
  1994. * @rtd: PCM runtime data
  1995. * @stream: stream name
  1996. * @event: stream event
  1997. *
  1998. * Sends a stream event to the dapm core. The core then makes any
  1999. * necessary widget power changes.
  2000. *
  2001. * Returns 0 for success else error.
  2002. */
  2003. int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
  2004. const char *stream, int event)
  2005. {
  2006. struct snd_soc_codec *codec = rtd->codec;
  2007. if (stream == NULL)
  2008. return 0;
  2009. mutex_lock(&codec->mutex);
  2010. soc_dapm_stream_event(&codec->dapm, stream, event);
  2011. mutex_unlock(&codec->mutex);
  2012. return 0;
  2013. }
  2014. /**
  2015. * snd_soc_dapm_enable_pin - enable pin.
  2016. * @dapm: DAPM context
  2017. * @pin: pin name
  2018. *
  2019. * Enables input/output pin and its parents or children widgets iff there is
  2020. * a valid audio route and active audio stream.
  2021. * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  2022. * do any widget power switching.
  2023. */
  2024. int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
  2025. {
  2026. return snd_soc_dapm_set_pin(dapm, pin, 1);
  2027. }
  2028. EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
  2029. /**
  2030. * snd_soc_dapm_force_enable_pin - force a pin to be enabled
  2031. * @dapm: DAPM context
  2032. * @pin: pin name
  2033. *
  2034. * Enables input/output pin regardless of any other state. This is
  2035. * intended for use with microphone bias supplies used in microphone
  2036. * jack detection.
  2037. *
  2038. * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  2039. * do any widget power switching.
  2040. */
  2041. int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
  2042. const char *pin)
  2043. {
  2044. struct snd_soc_dapm_widget *w;
  2045. list_for_each_entry(w, &dapm->card->widgets, list) {
  2046. if (w->dapm != dapm)
  2047. continue;
  2048. if (!strcmp(w->name, pin)) {
  2049. dev_dbg(w->dapm->dev,
  2050. "dapm: force enable pin %s\n", pin);
  2051. w->connected = 1;
  2052. w->force = 1;
  2053. return 0;
  2054. }
  2055. }
  2056. dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
  2057. return -EINVAL;
  2058. }
  2059. EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
  2060. /**
  2061. * snd_soc_dapm_disable_pin - disable pin.
  2062. * @dapm: DAPM context
  2063. * @pin: pin name
  2064. *
  2065. * Disables input/output pin and its parents or children widgets.
  2066. * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  2067. * do any widget power switching.
  2068. */
  2069. int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
  2070. const char *pin)
  2071. {
  2072. return snd_soc_dapm_set_pin(dapm, pin, 0);
  2073. }
  2074. EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
  2075. /**
  2076. * snd_soc_dapm_nc_pin - permanently disable pin.
  2077. * @dapm: DAPM context
  2078. * @pin: pin name
  2079. *
  2080. * Marks the specified pin as being not connected, disabling it along
  2081. * any parent or child widgets. At present this is identical to
  2082. * snd_soc_dapm_disable_pin() but in future it will be extended to do
  2083. * additional things such as disabling controls which only affect
  2084. * paths through the pin.
  2085. *
  2086. * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  2087. * do any widget power switching.
  2088. */
  2089. int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
  2090. {
  2091. return snd_soc_dapm_set_pin(dapm, pin, 0);
  2092. }
  2093. EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
  2094. /**
  2095. * snd_soc_dapm_get_pin_status - get audio pin status
  2096. * @dapm: DAPM context
  2097. * @pin: audio signal pin endpoint (or start point)
  2098. *
  2099. * Get audio pin status - connected or disconnected.
  2100. *
  2101. * Returns 1 for connected otherwise 0.
  2102. */
  2103. int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
  2104. const char *pin)
  2105. {
  2106. struct snd_soc_dapm_widget *w;
  2107. list_for_each_entry(w, &dapm->card->widgets, list) {
  2108. if (w->dapm != dapm)
  2109. continue;
  2110. if (!strcmp(w->name, pin))
  2111. return w->connected;
  2112. }
  2113. return 0;
  2114. }
  2115. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
  2116. /**
  2117. * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
  2118. * @dapm: DAPM context
  2119. * @pin: audio signal pin endpoint (or start point)
  2120. *
  2121. * Mark the given endpoint or pin as ignoring suspend. When the
  2122. * system is disabled a path between two endpoints flagged as ignoring
  2123. * suspend will not be disabled. The path must already be enabled via
  2124. * normal means at suspend time, it will not be turned on if it was not
  2125. * already enabled.
  2126. */
  2127. int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
  2128. const char *pin)
  2129. {
  2130. struct snd_soc_dapm_widget *w;
  2131. list_for_each_entry(w, &dapm->card->widgets, list) {
  2132. if (w->dapm != dapm)
  2133. continue;
  2134. if (!strcmp(w->name, pin)) {
  2135. w->ignore_suspend = 1;
  2136. return 0;
  2137. }
  2138. }
  2139. dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
  2140. return -EINVAL;
  2141. }
  2142. EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
  2143. /**
  2144. * snd_soc_dapm_free - free dapm resources
  2145. * @card: SoC device
  2146. *
  2147. * Free all dapm widgets and resources.
  2148. */
  2149. void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
  2150. {
  2151. snd_soc_dapm_sys_remove(dapm->dev);
  2152. dapm_free_widgets(dapm);
  2153. list_del(&dapm->list);
  2154. }
  2155. EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
  2156. static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
  2157. {
  2158. struct snd_soc_dapm_widget *w;
  2159. LIST_HEAD(down_list);
  2160. int powerdown = 0;
  2161. list_for_each_entry(w, &dapm->card->widgets, list) {
  2162. if (w->dapm != dapm)
  2163. continue;
  2164. if (w->power) {
  2165. dapm_seq_insert(w, &down_list, false);
  2166. w->power = 0;
  2167. powerdown = 1;
  2168. }
  2169. }
  2170. /* If there were no widgets to power down we're already in
  2171. * standby.
  2172. */
  2173. if (powerdown) {
  2174. snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_PREPARE);
  2175. dapm_seq_run(dapm, &down_list, 0, false);
  2176. snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_STANDBY);
  2177. }
  2178. }
  2179. /*
  2180. * snd_soc_dapm_shutdown - callback for system shutdown
  2181. */
  2182. void snd_soc_dapm_shutdown(struct snd_soc_card *card)
  2183. {
  2184. struct snd_soc_codec *codec;
  2185. list_for_each_entry(codec, &card->codec_dev_list, list) {
  2186. soc_dapm_shutdown_codec(&codec->dapm);
  2187. snd_soc_dapm_set_bias_level(&codec->dapm, SND_SOC_BIAS_OFF);
  2188. }
  2189. }
  2190. /* Module information */
  2191. MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
  2192. MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
  2193. MODULE_LICENSE("GPL");