soc-dapm.c 77 KB

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