soc-dapm.c 62 KB

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