soc-dapm.c 77 KB

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