soc-dapm.c 62 KB

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