soc-dapm.c 61 KB

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