soc-dapm.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151
  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(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. Signal
  1233. * generators are virtual pins and have no
  1234. * power impact themselves.
  1235. */
  1236. switch (w->id) {
  1237. case snd_soc_dapm_siggen:
  1238. break;
  1239. case snd_soc_dapm_supply:
  1240. case snd_soc_dapm_regulator_supply:
  1241. case snd_soc_dapm_micbias:
  1242. if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
  1243. d->target_bias_level = SND_SOC_BIAS_STANDBY;
  1244. break;
  1245. default:
  1246. d->target_bias_level = SND_SOC_BIAS_ON;
  1247. break;
  1248. }
  1249. }
  1250. }
  1251. /* If there are no DAPM widgets then try to figure out power from the
  1252. * event type.
  1253. */
  1254. if (!dapm->n_widgets) {
  1255. switch (event) {
  1256. case SND_SOC_DAPM_STREAM_START:
  1257. case SND_SOC_DAPM_STREAM_RESUME:
  1258. dapm->target_bias_level = SND_SOC_BIAS_ON;
  1259. break;
  1260. case SND_SOC_DAPM_STREAM_STOP:
  1261. if (dapm->codec && dapm->codec->active)
  1262. dapm->target_bias_level = SND_SOC_BIAS_ON;
  1263. else
  1264. dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
  1265. break;
  1266. case SND_SOC_DAPM_STREAM_SUSPEND:
  1267. dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
  1268. break;
  1269. case SND_SOC_DAPM_STREAM_NOP:
  1270. dapm->target_bias_level = dapm->bias_level;
  1271. break;
  1272. default:
  1273. break;
  1274. }
  1275. }
  1276. /* Force all contexts in the card to the same bias state if
  1277. * they're not ground referenced.
  1278. */
  1279. bias = SND_SOC_BIAS_OFF;
  1280. list_for_each_entry(d, &card->dapm_list, list)
  1281. if (d->target_bias_level > bias)
  1282. bias = d->target_bias_level;
  1283. list_for_each_entry(d, &card->dapm_list, list)
  1284. if (!d->idle_bias_off)
  1285. d->target_bias_level = bias;
  1286. trace_snd_soc_dapm_walk_done(card);
  1287. /* Run all the bias changes in parallel */
  1288. list_for_each_entry(d, &dapm->card->dapm_list, list)
  1289. async_schedule_domain(dapm_pre_sequence_async, d,
  1290. &async_domain);
  1291. async_synchronize_full_domain(&async_domain);
  1292. /* Power down widgets first; try to avoid amplifying pops. */
  1293. dapm_seq_run(dapm, &down_list, event, false);
  1294. dapm_widget_update(dapm);
  1295. /* Now power up. */
  1296. dapm_seq_run(dapm, &up_list, event, true);
  1297. /* Run all the bias changes in parallel */
  1298. list_for_each_entry(d, &dapm->card->dapm_list, list)
  1299. async_schedule_domain(dapm_post_sequence_async, d,
  1300. &async_domain);
  1301. async_synchronize_full_domain(&async_domain);
  1302. pop_dbg(dapm->dev, card->pop_time,
  1303. "DAPM sequencing finished, waiting %dms\n", card->pop_time);
  1304. pop_wait(card->pop_time);
  1305. trace_snd_soc_dapm_done(card);
  1306. return 0;
  1307. }
  1308. #ifdef CONFIG_DEBUG_FS
  1309. static int dapm_widget_power_open_file(struct inode *inode, struct file *file)
  1310. {
  1311. file->private_data = inode->i_private;
  1312. return 0;
  1313. }
  1314. static ssize_t dapm_widget_power_read_file(struct file *file,
  1315. char __user *user_buf,
  1316. size_t count, loff_t *ppos)
  1317. {
  1318. struct snd_soc_dapm_widget *w = file->private_data;
  1319. char *buf;
  1320. int in, out;
  1321. ssize_t ret;
  1322. struct snd_soc_dapm_path *p = NULL;
  1323. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  1324. if (!buf)
  1325. return -ENOMEM;
  1326. in = is_connected_input_ep(w);
  1327. dapm_clear_walk(w->dapm);
  1328. out = is_connected_output_ep(w);
  1329. dapm_clear_walk(w->dapm);
  1330. ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d",
  1331. w->name, w->power ? "On" : "Off", in, out);
  1332. if (w->reg >= 0)
  1333. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  1334. " - R%d(0x%x) bit %d",
  1335. w->reg, w->reg, w->shift);
  1336. ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
  1337. if (w->sname)
  1338. ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
  1339. w->sname,
  1340. w->active ? "active" : "inactive");
  1341. list_for_each_entry(p, &w->sources, list_sink) {
  1342. if (p->connected && !p->connected(w, p->sink))
  1343. continue;
  1344. if (p->connect)
  1345. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  1346. " in \"%s\" \"%s\"\n",
  1347. p->name ? p->name : "static",
  1348. p->source->name);
  1349. }
  1350. list_for_each_entry(p, &w->sinks, list_source) {
  1351. if (p->connected && !p->connected(w, p->sink))
  1352. continue;
  1353. if (p->connect)
  1354. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  1355. " out \"%s\" \"%s\"\n",
  1356. p->name ? p->name : "static",
  1357. p->sink->name);
  1358. }
  1359. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  1360. kfree(buf);
  1361. return ret;
  1362. }
  1363. static const struct file_operations dapm_widget_power_fops = {
  1364. .open = dapm_widget_power_open_file,
  1365. .read = dapm_widget_power_read_file,
  1366. .llseek = default_llseek,
  1367. };
  1368. static int dapm_bias_open_file(struct inode *inode, struct file *file)
  1369. {
  1370. file->private_data = inode->i_private;
  1371. return 0;
  1372. }
  1373. static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
  1374. size_t count, loff_t *ppos)
  1375. {
  1376. struct snd_soc_dapm_context *dapm = file->private_data;
  1377. char *level;
  1378. switch (dapm->bias_level) {
  1379. case SND_SOC_BIAS_ON:
  1380. level = "On\n";
  1381. break;
  1382. case SND_SOC_BIAS_PREPARE:
  1383. level = "Prepare\n";
  1384. break;
  1385. case SND_SOC_BIAS_STANDBY:
  1386. level = "Standby\n";
  1387. break;
  1388. case SND_SOC_BIAS_OFF:
  1389. level = "Off\n";
  1390. break;
  1391. default:
  1392. BUG();
  1393. level = "Unknown\n";
  1394. break;
  1395. }
  1396. return simple_read_from_buffer(user_buf, count, ppos, level,
  1397. strlen(level));
  1398. }
  1399. static const struct file_operations dapm_bias_fops = {
  1400. .open = dapm_bias_open_file,
  1401. .read = dapm_bias_read_file,
  1402. .llseek = default_llseek,
  1403. };
  1404. void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
  1405. struct dentry *parent)
  1406. {
  1407. struct dentry *d;
  1408. dapm->debugfs_dapm = debugfs_create_dir("dapm", parent);
  1409. if (!dapm->debugfs_dapm) {
  1410. printk(KERN_WARNING
  1411. "Failed to create DAPM debugfs directory\n");
  1412. return;
  1413. }
  1414. d = debugfs_create_file("bias_level", 0444,
  1415. dapm->debugfs_dapm, dapm,
  1416. &dapm_bias_fops);
  1417. if (!d)
  1418. dev_warn(dapm->dev,
  1419. "ASoC: Failed to create bias level debugfs file\n");
  1420. }
  1421. static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
  1422. {
  1423. struct snd_soc_dapm_context *dapm = w->dapm;
  1424. struct dentry *d;
  1425. if (!dapm->debugfs_dapm || !w->name)
  1426. return;
  1427. d = debugfs_create_file(w->name, 0444,
  1428. dapm->debugfs_dapm, w,
  1429. &dapm_widget_power_fops);
  1430. if (!d)
  1431. dev_warn(w->dapm->dev,
  1432. "ASoC: Failed to create %s debugfs file\n",
  1433. w->name);
  1434. }
  1435. static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
  1436. {
  1437. debugfs_remove_recursive(dapm->debugfs_dapm);
  1438. }
  1439. #else
  1440. void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
  1441. struct dentry *parent)
  1442. {
  1443. }
  1444. static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
  1445. {
  1446. }
  1447. static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
  1448. {
  1449. }
  1450. #endif
  1451. /* test and update the power status of a mux widget */
  1452. static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
  1453. struct snd_kcontrol *kcontrol, int change,
  1454. int mux, struct soc_enum *e)
  1455. {
  1456. struct snd_soc_dapm_path *path;
  1457. int found = 0;
  1458. if (widget->id != snd_soc_dapm_mux &&
  1459. widget->id != snd_soc_dapm_virt_mux &&
  1460. widget->id != snd_soc_dapm_value_mux)
  1461. return -ENODEV;
  1462. if (!change)
  1463. return 0;
  1464. /* find dapm widget path assoc with kcontrol */
  1465. list_for_each_entry(path, &widget->dapm->card->paths, list) {
  1466. if (path->kcontrol != kcontrol)
  1467. continue;
  1468. if (!path->name || !e->texts[mux])
  1469. continue;
  1470. found = 1;
  1471. /* we now need to match the string in the enum to the path */
  1472. if (!(strcmp(path->name, e->texts[mux]))) {
  1473. path->connect = 1; /* new connection */
  1474. dapm_mark_dirty(path->source, "mux connection");
  1475. } else {
  1476. if (path->connect)
  1477. dapm_mark_dirty(path->source,
  1478. "mux disconnection");
  1479. path->connect = 0; /* old connection must be powered down */
  1480. }
  1481. }
  1482. if (found) {
  1483. dapm_mark_dirty(widget, "mux change");
  1484. dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
  1485. }
  1486. return 0;
  1487. }
  1488. /* test and update the power status of a mixer or switch widget */
  1489. static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
  1490. struct snd_kcontrol *kcontrol, int connect)
  1491. {
  1492. struct snd_soc_dapm_path *path;
  1493. int found = 0;
  1494. if (widget->id != snd_soc_dapm_mixer &&
  1495. widget->id != snd_soc_dapm_mixer_named_ctl &&
  1496. widget->id != snd_soc_dapm_switch)
  1497. return -ENODEV;
  1498. /* find dapm widget path assoc with kcontrol */
  1499. list_for_each_entry(path, &widget->dapm->card->paths, list) {
  1500. if (path->kcontrol != kcontrol)
  1501. continue;
  1502. /* found, now check type */
  1503. found = 1;
  1504. path->connect = connect;
  1505. dapm_mark_dirty(path->source, "mixer connection");
  1506. }
  1507. if (found) {
  1508. dapm_mark_dirty(widget, "mixer update");
  1509. dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
  1510. }
  1511. return 0;
  1512. }
  1513. /* show dapm widget status in sys fs */
  1514. static ssize_t dapm_widget_show(struct device *dev,
  1515. struct device_attribute *attr, char *buf)
  1516. {
  1517. struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
  1518. struct snd_soc_codec *codec =rtd->codec;
  1519. struct snd_soc_dapm_widget *w;
  1520. int count = 0;
  1521. char *state = "not set";
  1522. list_for_each_entry(w, &codec->card->widgets, list) {
  1523. if (w->dapm != &codec->dapm)
  1524. continue;
  1525. /* only display widgets that burnm power */
  1526. switch (w->id) {
  1527. case snd_soc_dapm_hp:
  1528. case snd_soc_dapm_mic:
  1529. case snd_soc_dapm_spk:
  1530. case snd_soc_dapm_line:
  1531. case snd_soc_dapm_micbias:
  1532. case snd_soc_dapm_dac:
  1533. case snd_soc_dapm_adc:
  1534. case snd_soc_dapm_pga:
  1535. case snd_soc_dapm_out_drv:
  1536. case snd_soc_dapm_mixer:
  1537. case snd_soc_dapm_mixer_named_ctl:
  1538. case snd_soc_dapm_supply:
  1539. case snd_soc_dapm_regulator_supply:
  1540. if (w->name)
  1541. count += sprintf(buf + count, "%s: %s\n",
  1542. w->name, w->power ? "On":"Off");
  1543. break;
  1544. default:
  1545. break;
  1546. }
  1547. }
  1548. switch (codec->dapm.bias_level) {
  1549. case SND_SOC_BIAS_ON:
  1550. state = "On";
  1551. break;
  1552. case SND_SOC_BIAS_PREPARE:
  1553. state = "Prepare";
  1554. break;
  1555. case SND_SOC_BIAS_STANDBY:
  1556. state = "Standby";
  1557. break;
  1558. case SND_SOC_BIAS_OFF:
  1559. state = "Off";
  1560. break;
  1561. }
  1562. count += sprintf(buf + count, "PM State: %s\n", state);
  1563. return count;
  1564. }
  1565. static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
  1566. int snd_soc_dapm_sys_add(struct device *dev)
  1567. {
  1568. return device_create_file(dev, &dev_attr_dapm_widget);
  1569. }
  1570. static void snd_soc_dapm_sys_remove(struct device *dev)
  1571. {
  1572. device_remove_file(dev, &dev_attr_dapm_widget);
  1573. }
  1574. /* free all dapm widgets and resources */
  1575. static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
  1576. {
  1577. struct snd_soc_dapm_widget *w, *next_w;
  1578. struct snd_soc_dapm_path *p, *next_p;
  1579. list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
  1580. if (w->dapm != dapm)
  1581. continue;
  1582. list_del(&w->list);
  1583. /*
  1584. * remove source and sink paths associated to this widget.
  1585. * While removing the path, remove reference to it from both
  1586. * source and sink widgets so that path is removed only once.
  1587. */
  1588. list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
  1589. list_del(&p->list_sink);
  1590. list_del(&p->list_source);
  1591. list_del(&p->list);
  1592. kfree(p->long_name);
  1593. kfree(p);
  1594. }
  1595. list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
  1596. list_del(&p->list_sink);
  1597. list_del(&p->list_source);
  1598. list_del(&p->list);
  1599. kfree(p->long_name);
  1600. kfree(p);
  1601. }
  1602. kfree(w->kcontrols);
  1603. kfree(w->name);
  1604. kfree(w);
  1605. }
  1606. }
  1607. static struct snd_soc_dapm_widget *dapm_find_widget(
  1608. struct snd_soc_dapm_context *dapm, const char *pin,
  1609. bool search_other_contexts)
  1610. {
  1611. struct snd_soc_dapm_widget *w;
  1612. struct snd_soc_dapm_widget *fallback = NULL;
  1613. list_for_each_entry(w, &dapm->card->widgets, list) {
  1614. if (!strcmp(w->name, pin)) {
  1615. if (w->dapm == dapm)
  1616. return w;
  1617. else
  1618. fallback = w;
  1619. }
  1620. }
  1621. if (search_other_contexts)
  1622. return fallback;
  1623. return NULL;
  1624. }
  1625. static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
  1626. const char *pin, int status)
  1627. {
  1628. struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
  1629. if (!w) {
  1630. dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
  1631. return -EINVAL;
  1632. }
  1633. w->connected = status;
  1634. if (status == 0)
  1635. w->force = 0;
  1636. dapm_mark_dirty(w, "pin configuration");
  1637. return 0;
  1638. }
  1639. /**
  1640. * snd_soc_dapm_sync - scan and power dapm paths
  1641. * @dapm: DAPM context
  1642. *
  1643. * Walks all dapm audio paths and powers widgets according to their
  1644. * stream or path usage.
  1645. *
  1646. * Returns 0 for success.
  1647. */
  1648. int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
  1649. {
  1650. /*
  1651. * Suppress early reports (eg, jacks syncing their state) to avoid
  1652. * silly DAPM runs during card startup.
  1653. */
  1654. if (!dapm->card || !dapm->card->instantiated)
  1655. return 0;
  1656. return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
  1657. }
  1658. EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
  1659. static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
  1660. const struct snd_soc_dapm_route *route)
  1661. {
  1662. struct snd_soc_dapm_path *path;
  1663. struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
  1664. struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
  1665. const char *sink;
  1666. const char *control = route->control;
  1667. const char *source;
  1668. char prefixed_sink[80];
  1669. char prefixed_source[80];
  1670. int ret = 0;
  1671. if (dapm->codec && dapm->codec->name_prefix) {
  1672. snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
  1673. dapm->codec->name_prefix, route->sink);
  1674. sink = prefixed_sink;
  1675. snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
  1676. dapm->codec->name_prefix, route->source);
  1677. source = prefixed_source;
  1678. } else {
  1679. sink = route->sink;
  1680. source = route->source;
  1681. }
  1682. /*
  1683. * find src and dest widgets over all widgets but favor a widget from
  1684. * current DAPM context
  1685. */
  1686. list_for_each_entry(w, &dapm->card->widgets, list) {
  1687. if (!wsink && !(strcmp(w->name, sink))) {
  1688. wtsink = w;
  1689. if (w->dapm == dapm)
  1690. wsink = w;
  1691. continue;
  1692. }
  1693. if (!wsource && !(strcmp(w->name, source))) {
  1694. wtsource = w;
  1695. if (w->dapm == dapm)
  1696. wsource = w;
  1697. }
  1698. }
  1699. /* use widget from another DAPM context if not found from this */
  1700. if (!wsink)
  1701. wsink = wtsink;
  1702. if (!wsource)
  1703. wsource = wtsource;
  1704. if (wsource == NULL || wsink == NULL)
  1705. return -ENODEV;
  1706. path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
  1707. if (!path)
  1708. return -ENOMEM;
  1709. path->source = wsource;
  1710. path->sink = wsink;
  1711. path->connected = route->connected;
  1712. INIT_LIST_HEAD(&path->list);
  1713. INIT_LIST_HEAD(&path->list_source);
  1714. INIT_LIST_HEAD(&path->list_sink);
  1715. /* check for external widgets */
  1716. if (wsink->id == snd_soc_dapm_input) {
  1717. if (wsource->id == snd_soc_dapm_micbias ||
  1718. wsource->id == snd_soc_dapm_mic ||
  1719. wsource->id == snd_soc_dapm_line ||
  1720. wsource->id == snd_soc_dapm_output)
  1721. wsink->ext = 1;
  1722. }
  1723. if (wsource->id == snd_soc_dapm_output) {
  1724. if (wsink->id == snd_soc_dapm_spk ||
  1725. wsink->id == snd_soc_dapm_hp ||
  1726. wsink->id == snd_soc_dapm_line ||
  1727. wsink->id == snd_soc_dapm_input)
  1728. wsource->ext = 1;
  1729. }
  1730. /* connect static paths */
  1731. if (control == NULL) {
  1732. list_add(&path->list, &dapm->card->paths);
  1733. list_add(&path->list_sink, &wsink->sources);
  1734. list_add(&path->list_source, &wsource->sinks);
  1735. path->connect = 1;
  1736. return 0;
  1737. }
  1738. /* connect dynamic paths */
  1739. switch (wsink->id) {
  1740. case snd_soc_dapm_adc:
  1741. case snd_soc_dapm_dac:
  1742. case snd_soc_dapm_pga:
  1743. case snd_soc_dapm_out_drv:
  1744. case snd_soc_dapm_input:
  1745. case snd_soc_dapm_output:
  1746. case snd_soc_dapm_siggen:
  1747. case snd_soc_dapm_micbias:
  1748. case snd_soc_dapm_vmid:
  1749. case snd_soc_dapm_pre:
  1750. case snd_soc_dapm_post:
  1751. case snd_soc_dapm_supply:
  1752. case snd_soc_dapm_regulator_supply:
  1753. case snd_soc_dapm_aif_in:
  1754. case snd_soc_dapm_aif_out:
  1755. list_add(&path->list, &dapm->card->paths);
  1756. list_add(&path->list_sink, &wsink->sources);
  1757. list_add(&path->list_source, &wsource->sinks);
  1758. path->connect = 1;
  1759. return 0;
  1760. case snd_soc_dapm_mux:
  1761. case snd_soc_dapm_virt_mux:
  1762. case snd_soc_dapm_value_mux:
  1763. ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
  1764. &wsink->kcontrol_news[0]);
  1765. if (ret != 0)
  1766. goto err;
  1767. break;
  1768. case snd_soc_dapm_switch:
  1769. case snd_soc_dapm_mixer:
  1770. case snd_soc_dapm_mixer_named_ctl:
  1771. ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
  1772. if (ret != 0)
  1773. goto err;
  1774. break;
  1775. case snd_soc_dapm_hp:
  1776. case snd_soc_dapm_mic:
  1777. case snd_soc_dapm_line:
  1778. case snd_soc_dapm_spk:
  1779. list_add(&path->list, &dapm->card->paths);
  1780. list_add(&path->list_sink, &wsink->sources);
  1781. list_add(&path->list_source, &wsource->sinks);
  1782. path->connect = 0;
  1783. return 0;
  1784. }
  1785. return 0;
  1786. err:
  1787. dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n",
  1788. source, control, sink);
  1789. kfree(path);
  1790. return ret;
  1791. }
  1792. /**
  1793. * snd_soc_dapm_add_routes - Add routes between DAPM widgets
  1794. * @dapm: DAPM context
  1795. * @route: audio routes
  1796. * @num: number of routes
  1797. *
  1798. * Connects 2 dapm widgets together via a named audio path. The sink is
  1799. * the widget receiving the audio signal, whilst the source is the sender
  1800. * of the audio signal.
  1801. *
  1802. * Returns 0 for success else error. On error all resources can be freed
  1803. * with a call to snd_soc_card_free().
  1804. */
  1805. int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
  1806. const struct snd_soc_dapm_route *route, int num)
  1807. {
  1808. int i, ret;
  1809. for (i = 0; i < num; i++) {
  1810. ret = snd_soc_dapm_add_route(dapm, route);
  1811. if (ret < 0) {
  1812. dev_err(dapm->dev, "Failed to add route %s->%s\n",
  1813. route->source, route->sink);
  1814. return ret;
  1815. }
  1816. route++;
  1817. }
  1818. return 0;
  1819. }
  1820. EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
  1821. static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm,
  1822. const struct snd_soc_dapm_route *route)
  1823. {
  1824. struct snd_soc_dapm_widget *source = dapm_find_widget(dapm,
  1825. route->source,
  1826. true);
  1827. struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm,
  1828. route->sink,
  1829. true);
  1830. struct snd_soc_dapm_path *path;
  1831. int count = 0;
  1832. if (!source) {
  1833. dev_err(dapm->dev, "Unable to find source %s for weak route\n",
  1834. route->source);
  1835. return -ENODEV;
  1836. }
  1837. if (!sink) {
  1838. dev_err(dapm->dev, "Unable to find sink %s for weak route\n",
  1839. route->sink);
  1840. return -ENODEV;
  1841. }
  1842. if (route->control || route->connected)
  1843. dev_warn(dapm->dev, "Ignoring control for weak route %s->%s\n",
  1844. route->source, route->sink);
  1845. list_for_each_entry(path, &source->sinks, list_source) {
  1846. if (path->sink == sink) {
  1847. path->weak = 1;
  1848. count++;
  1849. }
  1850. }
  1851. if (count == 0)
  1852. dev_err(dapm->dev, "No path found for weak route %s->%s\n",
  1853. route->source, route->sink);
  1854. if (count > 1)
  1855. dev_warn(dapm->dev, "%d paths found for weak route %s->%s\n",
  1856. count, route->source, route->sink);
  1857. return 0;
  1858. }
  1859. /**
  1860. * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
  1861. * @dapm: DAPM context
  1862. * @route: audio routes
  1863. * @num: number of routes
  1864. *
  1865. * Mark existing routes matching those specified in the passed array
  1866. * as being weak, meaning that they are ignored for the purpose of
  1867. * power decisions. The main intended use case is for sidetone paths
  1868. * which couple audio between other independent paths if they are both
  1869. * active in order to make the combination work better at the user
  1870. * level but which aren't intended to be "used".
  1871. *
  1872. * Note that CODEC drivers should not use this as sidetone type paths
  1873. * can frequently also be used as bypass paths.
  1874. */
  1875. int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
  1876. const struct snd_soc_dapm_route *route, int num)
  1877. {
  1878. int i, err;
  1879. int ret = 0;
  1880. for (i = 0; i < num; i++) {
  1881. err = snd_soc_dapm_weak_route(dapm, route);
  1882. if (err)
  1883. ret = err;
  1884. route++;
  1885. }
  1886. return ret;
  1887. }
  1888. EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes);
  1889. /**
  1890. * snd_soc_dapm_new_widgets - add new dapm widgets
  1891. * @dapm: DAPM context
  1892. *
  1893. * Checks the codec for any new dapm widgets and creates them if found.
  1894. *
  1895. * Returns 0 for success.
  1896. */
  1897. int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
  1898. {
  1899. struct snd_soc_dapm_widget *w;
  1900. unsigned int val;
  1901. list_for_each_entry(w, &dapm->card->widgets, list)
  1902. {
  1903. if (w->new)
  1904. continue;
  1905. if (w->num_kcontrols) {
  1906. w->kcontrols = kzalloc(w->num_kcontrols *
  1907. sizeof(struct snd_kcontrol *),
  1908. GFP_KERNEL);
  1909. if (!w->kcontrols)
  1910. return -ENOMEM;
  1911. }
  1912. switch(w->id) {
  1913. case snd_soc_dapm_switch:
  1914. case snd_soc_dapm_mixer:
  1915. case snd_soc_dapm_mixer_named_ctl:
  1916. dapm_new_mixer(w);
  1917. break;
  1918. case snd_soc_dapm_mux:
  1919. case snd_soc_dapm_virt_mux:
  1920. case snd_soc_dapm_value_mux:
  1921. dapm_new_mux(w);
  1922. break;
  1923. case snd_soc_dapm_pga:
  1924. case snd_soc_dapm_out_drv:
  1925. dapm_new_pga(w);
  1926. break;
  1927. default:
  1928. break;
  1929. }
  1930. /* Read the initial power state from the device */
  1931. if (w->reg >= 0) {
  1932. val = soc_widget_read(w, w->reg);
  1933. val &= 1 << w->shift;
  1934. if (w->invert)
  1935. val = !val;
  1936. if (val)
  1937. w->power = 1;
  1938. }
  1939. w->new = 1;
  1940. dapm_mark_dirty(w, "new widget");
  1941. dapm_debugfs_add_widget(w);
  1942. }
  1943. dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
  1944. return 0;
  1945. }
  1946. EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
  1947. /**
  1948. * snd_soc_dapm_get_volsw - dapm mixer get callback
  1949. * @kcontrol: mixer control
  1950. * @ucontrol: control element information
  1951. *
  1952. * Callback to get the value of a dapm mixer control.
  1953. *
  1954. * Returns 0 for success.
  1955. */
  1956. int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
  1957. struct snd_ctl_elem_value *ucontrol)
  1958. {
  1959. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  1960. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  1961. struct soc_mixer_control *mc =
  1962. (struct soc_mixer_control *)kcontrol->private_value;
  1963. unsigned int reg = mc->reg;
  1964. unsigned int shift = mc->shift;
  1965. unsigned int rshift = mc->rshift;
  1966. int max = mc->max;
  1967. unsigned int invert = mc->invert;
  1968. unsigned int mask = (1 << fls(max)) - 1;
  1969. ucontrol->value.integer.value[0] =
  1970. (snd_soc_read(widget->codec, reg) >> shift) & mask;
  1971. if (shift != rshift)
  1972. ucontrol->value.integer.value[1] =
  1973. (snd_soc_read(widget->codec, reg) >> rshift) & mask;
  1974. if (invert) {
  1975. ucontrol->value.integer.value[0] =
  1976. max - ucontrol->value.integer.value[0];
  1977. if (shift != rshift)
  1978. ucontrol->value.integer.value[1] =
  1979. max - ucontrol->value.integer.value[1];
  1980. }
  1981. return 0;
  1982. }
  1983. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
  1984. /**
  1985. * snd_soc_dapm_put_volsw - dapm mixer set callback
  1986. * @kcontrol: mixer control
  1987. * @ucontrol: control element information
  1988. *
  1989. * Callback to set the value of a dapm mixer control.
  1990. *
  1991. * Returns 0 for success.
  1992. */
  1993. int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
  1994. struct snd_ctl_elem_value *ucontrol)
  1995. {
  1996. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  1997. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  1998. struct snd_soc_codec *codec = widget->codec;
  1999. struct soc_mixer_control *mc =
  2000. (struct soc_mixer_control *)kcontrol->private_value;
  2001. unsigned int reg = mc->reg;
  2002. unsigned int shift = mc->shift;
  2003. int max = mc->max;
  2004. unsigned int mask = (1 << fls(max)) - 1;
  2005. unsigned int invert = mc->invert;
  2006. unsigned int val;
  2007. int connect, change;
  2008. struct snd_soc_dapm_update update;
  2009. int wi;
  2010. val = (ucontrol->value.integer.value[0] & mask);
  2011. if (invert)
  2012. val = max - val;
  2013. mask = mask << shift;
  2014. val = val << shift;
  2015. if (val)
  2016. /* new connection */
  2017. connect = invert ? 0 : 1;
  2018. else
  2019. /* old connection must be powered down */
  2020. connect = invert ? 1 : 0;
  2021. mutex_lock(&codec->mutex);
  2022. change = snd_soc_test_bits(widget->codec, reg, mask, val);
  2023. if (change) {
  2024. for (wi = 0; wi < wlist->num_widgets; wi++) {
  2025. widget = wlist->widgets[wi];
  2026. widget->value = val;
  2027. update.kcontrol = kcontrol;
  2028. update.widget = widget;
  2029. update.reg = reg;
  2030. update.mask = mask;
  2031. update.val = val;
  2032. widget->dapm->update = &update;
  2033. dapm_mixer_update_power(widget, kcontrol, connect);
  2034. widget->dapm->update = NULL;
  2035. }
  2036. }
  2037. mutex_unlock(&codec->mutex);
  2038. return 0;
  2039. }
  2040. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
  2041. /**
  2042. * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
  2043. * @kcontrol: mixer control
  2044. * @ucontrol: control element information
  2045. *
  2046. * Callback to get the value of a dapm enumerated double mixer control.
  2047. *
  2048. * Returns 0 for success.
  2049. */
  2050. int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
  2051. struct snd_ctl_elem_value *ucontrol)
  2052. {
  2053. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  2054. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  2055. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2056. unsigned int val, bitmask;
  2057. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  2058. ;
  2059. val = snd_soc_read(widget->codec, e->reg);
  2060. ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
  2061. if (e->shift_l != e->shift_r)
  2062. ucontrol->value.enumerated.item[1] =
  2063. (val >> e->shift_r) & (bitmask - 1);
  2064. return 0;
  2065. }
  2066. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
  2067. /**
  2068. * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
  2069. * @kcontrol: mixer control
  2070. * @ucontrol: control element information
  2071. *
  2072. * Callback to set the value of a dapm enumerated double mixer control.
  2073. *
  2074. * Returns 0 for success.
  2075. */
  2076. int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
  2077. struct snd_ctl_elem_value *ucontrol)
  2078. {
  2079. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  2080. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  2081. struct snd_soc_codec *codec = widget->codec;
  2082. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2083. unsigned int val, mux, change;
  2084. unsigned int mask, bitmask;
  2085. struct snd_soc_dapm_update update;
  2086. int wi;
  2087. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  2088. ;
  2089. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  2090. return -EINVAL;
  2091. mux = ucontrol->value.enumerated.item[0];
  2092. val = mux << e->shift_l;
  2093. mask = (bitmask - 1) << e->shift_l;
  2094. if (e->shift_l != e->shift_r) {
  2095. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  2096. return -EINVAL;
  2097. val |= ucontrol->value.enumerated.item[1] << e->shift_r;
  2098. mask |= (bitmask - 1) << e->shift_r;
  2099. }
  2100. mutex_lock(&codec->mutex);
  2101. change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
  2102. if (change) {
  2103. for (wi = 0; wi < wlist->num_widgets; wi++) {
  2104. widget = wlist->widgets[wi];
  2105. widget->value = val;
  2106. update.kcontrol = kcontrol;
  2107. update.widget = widget;
  2108. update.reg = e->reg;
  2109. update.mask = mask;
  2110. update.val = val;
  2111. widget->dapm->update = &update;
  2112. dapm_mux_update_power(widget, kcontrol, change, mux, e);
  2113. widget->dapm->update = NULL;
  2114. }
  2115. }
  2116. mutex_unlock(&codec->mutex);
  2117. return change;
  2118. }
  2119. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
  2120. /**
  2121. * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
  2122. * @kcontrol: mixer control
  2123. * @ucontrol: control element information
  2124. *
  2125. * Returns 0 for success.
  2126. */
  2127. int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
  2128. struct snd_ctl_elem_value *ucontrol)
  2129. {
  2130. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  2131. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  2132. ucontrol->value.enumerated.item[0] = widget->value;
  2133. return 0;
  2134. }
  2135. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
  2136. /**
  2137. * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
  2138. * @kcontrol: mixer control
  2139. * @ucontrol: control element information
  2140. *
  2141. * Returns 0 for success.
  2142. */
  2143. int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
  2144. struct snd_ctl_elem_value *ucontrol)
  2145. {
  2146. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  2147. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  2148. struct snd_soc_codec *codec = widget->codec;
  2149. struct soc_enum *e =
  2150. (struct soc_enum *)kcontrol->private_value;
  2151. int change;
  2152. int ret = 0;
  2153. int wi;
  2154. if (ucontrol->value.enumerated.item[0] >= e->max)
  2155. return -EINVAL;
  2156. mutex_lock(&codec->mutex);
  2157. change = widget->value != ucontrol->value.enumerated.item[0];
  2158. if (change) {
  2159. for (wi = 0; wi < wlist->num_widgets; wi++) {
  2160. widget = wlist->widgets[wi];
  2161. widget->value = ucontrol->value.enumerated.item[0];
  2162. dapm_mux_update_power(widget, kcontrol, change,
  2163. widget->value, e);
  2164. }
  2165. }
  2166. mutex_unlock(&codec->mutex);
  2167. return ret;
  2168. }
  2169. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
  2170. /**
  2171. * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
  2172. * callback
  2173. * @kcontrol: mixer control
  2174. * @ucontrol: control element information
  2175. *
  2176. * Callback to get the value of a dapm semi enumerated double mixer control.
  2177. *
  2178. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  2179. * used for handling bitfield coded enumeration for example.
  2180. *
  2181. * Returns 0 for success.
  2182. */
  2183. int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
  2184. struct snd_ctl_elem_value *ucontrol)
  2185. {
  2186. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  2187. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  2188. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2189. unsigned int reg_val, val, mux;
  2190. reg_val = snd_soc_read(widget->codec, e->reg);
  2191. val = (reg_val >> e->shift_l) & e->mask;
  2192. for (mux = 0; mux < e->max; mux++) {
  2193. if (val == e->values[mux])
  2194. break;
  2195. }
  2196. ucontrol->value.enumerated.item[0] = mux;
  2197. if (e->shift_l != e->shift_r) {
  2198. val = (reg_val >> e->shift_r) & e->mask;
  2199. for (mux = 0; mux < e->max; mux++) {
  2200. if (val == e->values[mux])
  2201. break;
  2202. }
  2203. ucontrol->value.enumerated.item[1] = mux;
  2204. }
  2205. return 0;
  2206. }
  2207. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
  2208. /**
  2209. * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
  2210. * callback
  2211. * @kcontrol: mixer control
  2212. * @ucontrol: control element information
  2213. *
  2214. * Callback to set the value of a dapm semi enumerated double mixer control.
  2215. *
  2216. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  2217. * used for handling bitfield coded enumeration for example.
  2218. *
  2219. * Returns 0 for success.
  2220. */
  2221. int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
  2222. struct snd_ctl_elem_value *ucontrol)
  2223. {
  2224. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  2225. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  2226. struct snd_soc_codec *codec = widget->codec;
  2227. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2228. unsigned int val, mux, change;
  2229. unsigned int mask;
  2230. struct snd_soc_dapm_update update;
  2231. int wi;
  2232. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  2233. return -EINVAL;
  2234. mux = ucontrol->value.enumerated.item[0];
  2235. val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
  2236. mask = e->mask << e->shift_l;
  2237. if (e->shift_l != e->shift_r) {
  2238. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  2239. return -EINVAL;
  2240. val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
  2241. mask |= e->mask << e->shift_r;
  2242. }
  2243. mutex_lock(&codec->mutex);
  2244. change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
  2245. if (change) {
  2246. for (wi = 0; wi < wlist->num_widgets; wi++) {
  2247. widget = wlist->widgets[wi];
  2248. widget->value = val;
  2249. update.kcontrol = kcontrol;
  2250. update.widget = widget;
  2251. update.reg = e->reg;
  2252. update.mask = mask;
  2253. update.val = val;
  2254. widget->dapm->update = &update;
  2255. dapm_mux_update_power(widget, kcontrol, change, mux, e);
  2256. widget->dapm->update = NULL;
  2257. }
  2258. }
  2259. mutex_unlock(&codec->mutex);
  2260. return change;
  2261. }
  2262. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
  2263. /**
  2264. * snd_soc_dapm_info_pin_switch - Info for a pin switch
  2265. *
  2266. * @kcontrol: mixer control
  2267. * @uinfo: control element information
  2268. *
  2269. * Callback to provide information about a pin switch control.
  2270. */
  2271. int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
  2272. struct snd_ctl_elem_info *uinfo)
  2273. {
  2274. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2275. uinfo->count = 1;
  2276. uinfo->value.integer.min = 0;
  2277. uinfo->value.integer.max = 1;
  2278. return 0;
  2279. }
  2280. EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
  2281. /**
  2282. * snd_soc_dapm_get_pin_switch - Get information for a pin switch
  2283. *
  2284. * @kcontrol: mixer control
  2285. * @ucontrol: Value
  2286. */
  2287. int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
  2288. struct snd_ctl_elem_value *ucontrol)
  2289. {
  2290. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2291. const char *pin = (const char *)kcontrol->private_value;
  2292. mutex_lock(&codec->mutex);
  2293. ucontrol->value.integer.value[0] =
  2294. snd_soc_dapm_get_pin_status(&codec->dapm, pin);
  2295. mutex_unlock(&codec->mutex);
  2296. return 0;
  2297. }
  2298. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
  2299. /**
  2300. * snd_soc_dapm_put_pin_switch - Set information for a pin switch
  2301. *
  2302. * @kcontrol: mixer control
  2303. * @ucontrol: Value
  2304. */
  2305. int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
  2306. struct snd_ctl_elem_value *ucontrol)
  2307. {
  2308. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2309. const char *pin = (const char *)kcontrol->private_value;
  2310. mutex_lock(&codec->mutex);
  2311. if (ucontrol->value.integer.value[0])
  2312. snd_soc_dapm_enable_pin(&codec->dapm, pin);
  2313. else
  2314. snd_soc_dapm_disable_pin(&codec->dapm, pin);
  2315. snd_soc_dapm_sync(&codec->dapm);
  2316. mutex_unlock(&codec->mutex);
  2317. return 0;
  2318. }
  2319. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
  2320. /**
  2321. * snd_soc_dapm_new_control - create new dapm control
  2322. * @dapm: DAPM context
  2323. * @widget: widget template
  2324. *
  2325. * Creates a new dapm control based upon the template.
  2326. *
  2327. * Returns 0 for success else error.
  2328. */
  2329. int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
  2330. const struct snd_soc_dapm_widget *widget)
  2331. {
  2332. struct snd_soc_dapm_widget *w;
  2333. size_t name_len;
  2334. int ret;
  2335. if ((w = dapm_cnew_widget(widget)) == NULL)
  2336. return -ENOMEM;
  2337. switch (w->id) {
  2338. case snd_soc_dapm_regulator_supply:
  2339. w->priv = devm_regulator_get(dapm->dev, w->name);
  2340. if (IS_ERR(w->priv)) {
  2341. ret = PTR_ERR(w->priv);
  2342. dev_err(dapm->dev, "Failed to request %s: %d\n",
  2343. w->name, ret);
  2344. return ret;
  2345. }
  2346. break;
  2347. default:
  2348. break;
  2349. }
  2350. name_len = strlen(widget->name) + 1;
  2351. if (dapm->codec && dapm->codec->name_prefix)
  2352. name_len += 1 + strlen(dapm->codec->name_prefix);
  2353. w->name = kmalloc(name_len, GFP_KERNEL);
  2354. if (w->name == NULL) {
  2355. kfree(w);
  2356. return -ENOMEM;
  2357. }
  2358. if (dapm->codec && dapm->codec->name_prefix)
  2359. snprintf(w->name, name_len, "%s %s",
  2360. dapm->codec->name_prefix, widget->name);
  2361. else
  2362. snprintf(w->name, name_len, "%s", widget->name);
  2363. switch (w->id) {
  2364. case snd_soc_dapm_switch:
  2365. case snd_soc_dapm_mixer:
  2366. case snd_soc_dapm_mixer_named_ctl:
  2367. w->power_check = dapm_generic_check_power;
  2368. break;
  2369. case snd_soc_dapm_mux:
  2370. case snd_soc_dapm_virt_mux:
  2371. case snd_soc_dapm_value_mux:
  2372. w->power_check = dapm_generic_check_power;
  2373. break;
  2374. case snd_soc_dapm_adc:
  2375. case snd_soc_dapm_aif_out:
  2376. w->power_check = dapm_adc_check_power;
  2377. break;
  2378. case snd_soc_dapm_dac:
  2379. case snd_soc_dapm_aif_in:
  2380. w->power_check = dapm_dac_check_power;
  2381. break;
  2382. case snd_soc_dapm_pga:
  2383. case snd_soc_dapm_out_drv:
  2384. case snd_soc_dapm_input:
  2385. case snd_soc_dapm_output:
  2386. case snd_soc_dapm_micbias:
  2387. case snd_soc_dapm_spk:
  2388. case snd_soc_dapm_hp:
  2389. case snd_soc_dapm_mic:
  2390. case snd_soc_dapm_line:
  2391. w->power_check = dapm_generic_check_power;
  2392. break;
  2393. case snd_soc_dapm_supply:
  2394. case snd_soc_dapm_regulator_supply:
  2395. w->power_check = dapm_supply_check_power;
  2396. break;
  2397. default:
  2398. w->power_check = dapm_always_on_check_power;
  2399. break;
  2400. }
  2401. dapm->n_widgets++;
  2402. w->dapm = dapm;
  2403. w->codec = dapm->codec;
  2404. w->platform = dapm->platform;
  2405. INIT_LIST_HEAD(&w->sources);
  2406. INIT_LIST_HEAD(&w->sinks);
  2407. INIT_LIST_HEAD(&w->list);
  2408. INIT_LIST_HEAD(&w->dirty);
  2409. list_add(&w->list, &dapm->card->widgets);
  2410. /* machine layer set ups unconnected pins and insertions */
  2411. w->connected = 1;
  2412. return 0;
  2413. }
  2414. EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
  2415. /**
  2416. * snd_soc_dapm_new_controls - create new dapm controls
  2417. * @dapm: DAPM context
  2418. * @widget: widget array
  2419. * @num: number of widgets
  2420. *
  2421. * Creates new DAPM controls based upon the templates.
  2422. *
  2423. * Returns 0 for success else error.
  2424. */
  2425. int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
  2426. const struct snd_soc_dapm_widget *widget,
  2427. int num)
  2428. {
  2429. int i, ret;
  2430. for (i = 0; i < num; i++) {
  2431. ret = snd_soc_dapm_new_control(dapm, widget);
  2432. if (ret < 0) {
  2433. dev_err(dapm->dev,
  2434. "ASoC: Failed to create DAPM control %s: %d\n",
  2435. widget->name, ret);
  2436. return ret;
  2437. }
  2438. widget++;
  2439. }
  2440. return 0;
  2441. }
  2442. EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
  2443. static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
  2444. const char *stream, int event)
  2445. {
  2446. struct snd_soc_dapm_widget *w;
  2447. list_for_each_entry(w, &dapm->card->widgets, list)
  2448. {
  2449. if (!w->sname || w->dapm != dapm)
  2450. continue;
  2451. dev_vdbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n",
  2452. w->name, w->sname, stream, event);
  2453. if (strstr(w->sname, stream)) {
  2454. dapm_mark_dirty(w, "stream event");
  2455. switch(event) {
  2456. case SND_SOC_DAPM_STREAM_START:
  2457. w->active = 1;
  2458. break;
  2459. case SND_SOC_DAPM_STREAM_STOP:
  2460. w->active = 0;
  2461. break;
  2462. case SND_SOC_DAPM_STREAM_SUSPEND:
  2463. case SND_SOC_DAPM_STREAM_RESUME:
  2464. case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
  2465. case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
  2466. break;
  2467. }
  2468. }
  2469. }
  2470. dapm_power_widgets(dapm, event);
  2471. /* do we need to notify any clients that DAPM stream is complete */
  2472. if (dapm->stream_event)
  2473. dapm->stream_event(dapm, event);
  2474. }
  2475. /**
  2476. * snd_soc_dapm_stream_event - send a stream event to the dapm core
  2477. * @rtd: PCM runtime data
  2478. * @stream: stream name
  2479. * @event: stream event
  2480. *
  2481. * Sends a stream event to the dapm core. The core then makes any
  2482. * necessary widget power changes.
  2483. *
  2484. * Returns 0 for success else error.
  2485. */
  2486. int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
  2487. const char *stream, int event)
  2488. {
  2489. struct snd_soc_codec *codec = rtd->codec;
  2490. if (stream == NULL)
  2491. return 0;
  2492. mutex_lock(&codec->mutex);
  2493. soc_dapm_stream_event(&codec->dapm, stream, event);
  2494. mutex_unlock(&codec->mutex);
  2495. return 0;
  2496. }
  2497. /**
  2498. * snd_soc_dapm_enable_pin - enable pin.
  2499. * @dapm: DAPM context
  2500. * @pin: pin name
  2501. *
  2502. * Enables input/output pin and its parents or children widgets iff there is
  2503. * a valid audio route and active audio stream.
  2504. * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  2505. * do any widget power switching.
  2506. */
  2507. int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
  2508. {
  2509. return snd_soc_dapm_set_pin(dapm, pin, 1);
  2510. }
  2511. EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
  2512. /**
  2513. * snd_soc_dapm_force_enable_pin - force a pin to be enabled
  2514. * @dapm: DAPM context
  2515. * @pin: pin name
  2516. *
  2517. * Enables input/output pin regardless of any other state. This is
  2518. * intended for use with microphone bias supplies used in microphone
  2519. * jack detection.
  2520. *
  2521. * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  2522. * do any widget power switching.
  2523. */
  2524. int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
  2525. const char *pin)
  2526. {
  2527. struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
  2528. if (!w) {
  2529. dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
  2530. return -EINVAL;
  2531. }
  2532. dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin);
  2533. w->connected = 1;
  2534. w->force = 1;
  2535. dapm_mark_dirty(w, "force enable");
  2536. return 0;
  2537. }
  2538. EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
  2539. /**
  2540. * snd_soc_dapm_disable_pin - disable pin.
  2541. * @dapm: DAPM context
  2542. * @pin: pin name
  2543. *
  2544. * Disables input/output pin and its parents or children widgets.
  2545. * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  2546. * do any widget power switching.
  2547. */
  2548. int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
  2549. const char *pin)
  2550. {
  2551. return snd_soc_dapm_set_pin(dapm, pin, 0);
  2552. }
  2553. EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
  2554. /**
  2555. * snd_soc_dapm_nc_pin - permanently disable pin.
  2556. * @dapm: DAPM context
  2557. * @pin: pin name
  2558. *
  2559. * Marks the specified pin as being not connected, disabling it along
  2560. * any parent or child widgets. At present this is identical to
  2561. * snd_soc_dapm_disable_pin() but in future it will be extended to do
  2562. * additional things such as disabling controls which only affect
  2563. * paths through the pin.
  2564. *
  2565. * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  2566. * do any widget power switching.
  2567. */
  2568. int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
  2569. {
  2570. return snd_soc_dapm_set_pin(dapm, pin, 0);
  2571. }
  2572. EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
  2573. /**
  2574. * snd_soc_dapm_get_pin_status - get audio pin status
  2575. * @dapm: DAPM context
  2576. * @pin: audio signal pin endpoint (or start point)
  2577. *
  2578. * Get audio pin status - connected or disconnected.
  2579. *
  2580. * Returns 1 for connected otherwise 0.
  2581. */
  2582. int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
  2583. const char *pin)
  2584. {
  2585. struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
  2586. if (w)
  2587. return w->connected;
  2588. return 0;
  2589. }
  2590. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
  2591. /**
  2592. * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
  2593. * @dapm: DAPM context
  2594. * @pin: audio signal pin endpoint (or start point)
  2595. *
  2596. * Mark the given endpoint or pin as ignoring suspend. When the
  2597. * system is disabled a path between two endpoints flagged as ignoring
  2598. * suspend will not be disabled. The path must already be enabled via
  2599. * normal means at suspend time, it will not be turned on if it was not
  2600. * already enabled.
  2601. */
  2602. int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
  2603. const char *pin)
  2604. {
  2605. struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false);
  2606. if (!w) {
  2607. dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
  2608. return -EINVAL;
  2609. }
  2610. w->ignore_suspend = 1;
  2611. return 0;
  2612. }
  2613. EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
  2614. static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card *card,
  2615. struct snd_soc_dapm_widget *w)
  2616. {
  2617. struct snd_soc_dapm_path *p;
  2618. list_for_each_entry(p, &card->paths, list) {
  2619. if ((p->source == w) || (p->sink == w)) {
  2620. dev_dbg(card->dev,
  2621. "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
  2622. p->source->name, p->source->id, p->source->dapm,
  2623. p->sink->name, p->sink->id, p->sink->dapm);
  2624. /* Connected to something other than the codec */
  2625. if (p->source->dapm != p->sink->dapm)
  2626. return true;
  2627. /*
  2628. * Loopback connection from codec external pin to
  2629. * codec external pin
  2630. */
  2631. if (p->sink->id == snd_soc_dapm_input) {
  2632. switch (p->source->id) {
  2633. case snd_soc_dapm_output:
  2634. case snd_soc_dapm_micbias:
  2635. return true;
  2636. default:
  2637. break;
  2638. }
  2639. }
  2640. }
  2641. }
  2642. return false;
  2643. }
  2644. /**
  2645. * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
  2646. * @codec: The codec whose pins should be processed
  2647. *
  2648. * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
  2649. * which are unused. Pins are used if they are connected externally to the
  2650. * codec, whether that be to some other device, or a loop-back connection to
  2651. * the codec itself.
  2652. */
  2653. void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec)
  2654. {
  2655. struct snd_soc_card *card = codec->card;
  2656. struct snd_soc_dapm_context *dapm = &codec->dapm;
  2657. struct snd_soc_dapm_widget *w;
  2658. dev_dbg(codec->dev, "Auto NC: DAPMs: card:%p codec:%p\n",
  2659. &card->dapm, &codec->dapm);
  2660. list_for_each_entry(w, &card->widgets, list) {
  2661. if (w->dapm != dapm)
  2662. continue;
  2663. switch (w->id) {
  2664. case snd_soc_dapm_input:
  2665. case snd_soc_dapm_output:
  2666. case snd_soc_dapm_micbias:
  2667. dev_dbg(codec->dev, "Auto NC: Checking widget %s\n",
  2668. w->name);
  2669. if (!snd_soc_dapm_widget_in_card_paths(card, w)) {
  2670. dev_dbg(codec->dev,
  2671. "... Not in map; disabling\n");
  2672. snd_soc_dapm_nc_pin(dapm, w->name);
  2673. }
  2674. break;
  2675. default:
  2676. break;
  2677. }
  2678. }
  2679. }
  2680. /**
  2681. * snd_soc_dapm_free - free dapm resources
  2682. * @dapm: DAPM context
  2683. *
  2684. * Free all dapm widgets and resources.
  2685. */
  2686. void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
  2687. {
  2688. snd_soc_dapm_sys_remove(dapm->dev);
  2689. dapm_debugfs_cleanup(dapm);
  2690. dapm_free_widgets(dapm);
  2691. list_del(&dapm->list);
  2692. }
  2693. EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
  2694. static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
  2695. {
  2696. struct snd_soc_dapm_widget *w;
  2697. LIST_HEAD(down_list);
  2698. int powerdown = 0;
  2699. list_for_each_entry(w, &dapm->card->widgets, list) {
  2700. if (w->dapm != dapm)
  2701. continue;
  2702. if (w->power) {
  2703. dapm_seq_insert(w, &down_list, false);
  2704. w->power = 0;
  2705. powerdown = 1;
  2706. }
  2707. }
  2708. /* If there were no widgets to power down we're already in
  2709. * standby.
  2710. */
  2711. if (powerdown) {
  2712. snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_PREPARE);
  2713. dapm_seq_run(dapm, &down_list, 0, false);
  2714. snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_STANDBY);
  2715. }
  2716. }
  2717. /*
  2718. * snd_soc_dapm_shutdown - callback for system shutdown
  2719. */
  2720. void snd_soc_dapm_shutdown(struct snd_soc_card *card)
  2721. {
  2722. struct snd_soc_codec *codec;
  2723. list_for_each_entry(codec, &card->codec_dev_list, list) {
  2724. soc_dapm_shutdown_codec(&codec->dapm);
  2725. snd_soc_dapm_set_bias_level(&codec->dapm, SND_SOC_BIAS_OFF);
  2726. }
  2727. }
  2728. /* Module information */
  2729. MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
  2730. MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
  2731. MODULE_LICENSE("GPL");