soc-core.c 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254
  1. /*
  2. * soc-core.c -- ALSA SoC Audio Layer
  3. *
  4. * Copyright 2005 Wolfson Microelectronics PLC.
  5. * Copyright 2005 Openedhand Ltd.
  6. * Copyright (C) 2010 Slimlogic Ltd.
  7. * Copyright (C) 2010 Texas Instruments Inc.
  8. *
  9. * Author: Liam Girdwood <lrg@slimlogic.co.uk>
  10. * with code, comments and ideas from :-
  11. * Richard Purdie <richard@openedhand.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. *
  18. * TODO:
  19. * o Add hw rules to enforce rates, etc.
  20. * o More testing with other codecs/machines.
  21. * o Add more codecs and platforms to ensure good API coverage.
  22. * o Support TDM on PCM and I2S
  23. */
  24. #include <linux/module.h>
  25. #include <linux/moduleparam.h>
  26. #include <linux/init.h>
  27. #include <linux/delay.h>
  28. #include <linux/pm.h>
  29. #include <linux/bitops.h>
  30. #include <linux/debugfs.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/ctype.h>
  33. #include <linux/slab.h>
  34. #include <linux/of.h>
  35. #include <sound/ac97_codec.h>
  36. #include <sound/core.h>
  37. #include <sound/jack.h>
  38. #include <sound/pcm.h>
  39. #include <sound/pcm_params.h>
  40. #include <sound/soc.h>
  41. #include <sound/soc-dpcm.h>
  42. #include <sound/initval.h>
  43. #define CREATE_TRACE_POINTS
  44. #include <trace/events/asoc.h>
  45. #define NAME_SIZE 32
  46. static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
  47. #ifdef CONFIG_DEBUG_FS
  48. struct dentry *snd_soc_debugfs_root;
  49. EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
  50. #endif
  51. static DEFINE_MUTEX(client_mutex);
  52. static LIST_HEAD(dai_list);
  53. static LIST_HEAD(platform_list);
  54. static LIST_HEAD(codec_list);
  55. /*
  56. * This is a timeout to do a DAPM powerdown after a stream is closed().
  57. * It can be used to eliminate pops between different playback streams, e.g.
  58. * between two audio tracks.
  59. */
  60. static int pmdown_time = 5000;
  61. module_param(pmdown_time, int, 0);
  62. MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
  63. /* returns the minimum number of bytes needed to represent
  64. * a particular given value */
  65. static int min_bytes_needed(unsigned long val)
  66. {
  67. int c = 0;
  68. int i;
  69. for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c)
  70. if (val & (1UL << i))
  71. break;
  72. c = (sizeof val * 8) - c;
  73. if (!c || (c % 8))
  74. c = (c + 8) / 8;
  75. else
  76. c /= 8;
  77. return c;
  78. }
  79. /* fill buf which is 'len' bytes with a formatted
  80. * string of the form 'reg: value\n' */
  81. static int format_register_str(struct snd_soc_codec *codec,
  82. unsigned int reg, char *buf, size_t len)
  83. {
  84. int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
  85. int regsize = codec->driver->reg_word_size * 2;
  86. int ret;
  87. char tmpbuf[len + 1];
  88. char regbuf[regsize + 1];
  89. /* since tmpbuf is allocated on the stack, warn the callers if they
  90. * try to abuse this function */
  91. WARN_ON(len > 63);
  92. /* +2 for ': ' and + 1 for '\n' */
  93. if (wordsize + regsize + 2 + 1 != len)
  94. return -EINVAL;
  95. ret = snd_soc_read(codec, reg);
  96. if (ret < 0) {
  97. memset(regbuf, 'X', regsize);
  98. regbuf[regsize] = '\0';
  99. } else {
  100. snprintf(regbuf, regsize + 1, "%.*x", regsize, ret);
  101. }
  102. /* prepare the buffer */
  103. snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf);
  104. /* copy it back to the caller without the '\0' */
  105. memcpy(buf, tmpbuf, len);
  106. return 0;
  107. }
  108. /* codec register dump */
  109. static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf,
  110. size_t count, loff_t pos)
  111. {
  112. int i, step = 1;
  113. int wordsize, regsize;
  114. int len;
  115. size_t total = 0;
  116. loff_t p = 0;
  117. wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
  118. regsize = codec->driver->reg_word_size * 2;
  119. len = wordsize + regsize + 2 + 1;
  120. if (!codec->driver->reg_cache_size)
  121. return 0;
  122. if (codec->driver->reg_cache_step)
  123. step = codec->driver->reg_cache_step;
  124. for (i = 0; i < codec->driver->reg_cache_size; i += step) {
  125. if (!snd_soc_codec_readable_register(codec, i))
  126. continue;
  127. if (codec->driver->display_register) {
  128. count += codec->driver->display_register(codec, buf + count,
  129. PAGE_SIZE - count, i);
  130. } else {
  131. /* only support larger than PAGE_SIZE bytes debugfs
  132. * entries for the default case */
  133. if (p >= pos) {
  134. if (total + len >= count - 1)
  135. break;
  136. format_register_str(codec, i, buf + total, len);
  137. total += len;
  138. }
  139. p += len;
  140. }
  141. }
  142. total = min(total, count - 1);
  143. return total;
  144. }
  145. static ssize_t codec_reg_show(struct device *dev,
  146. struct device_attribute *attr, char *buf)
  147. {
  148. struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
  149. return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0);
  150. }
  151. static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
  152. static ssize_t pmdown_time_show(struct device *dev,
  153. struct device_attribute *attr, char *buf)
  154. {
  155. struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
  156. return sprintf(buf, "%ld\n", rtd->pmdown_time);
  157. }
  158. static ssize_t pmdown_time_set(struct device *dev,
  159. struct device_attribute *attr,
  160. const char *buf, size_t count)
  161. {
  162. struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
  163. int ret;
  164. ret = strict_strtol(buf, 10, &rtd->pmdown_time);
  165. if (ret)
  166. return ret;
  167. return count;
  168. }
  169. static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
  170. #ifdef CONFIG_DEBUG_FS
  171. static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
  172. size_t count, loff_t *ppos)
  173. {
  174. ssize_t ret;
  175. struct snd_soc_codec *codec = file->private_data;
  176. char *buf;
  177. if (*ppos < 0 || !count)
  178. return -EINVAL;
  179. buf = kmalloc(count, GFP_KERNEL);
  180. if (!buf)
  181. return -ENOMEM;
  182. ret = soc_codec_reg_show(codec, buf, count, *ppos);
  183. if (ret >= 0) {
  184. if (copy_to_user(user_buf, buf, ret)) {
  185. kfree(buf);
  186. return -EFAULT;
  187. }
  188. *ppos += ret;
  189. }
  190. kfree(buf);
  191. return ret;
  192. }
  193. static ssize_t codec_reg_write_file(struct file *file,
  194. const char __user *user_buf, size_t count, loff_t *ppos)
  195. {
  196. char buf[32];
  197. size_t buf_size;
  198. char *start = buf;
  199. unsigned long reg, value;
  200. struct snd_soc_codec *codec = file->private_data;
  201. buf_size = min(count, (sizeof(buf)-1));
  202. if (copy_from_user(buf, user_buf, buf_size))
  203. return -EFAULT;
  204. buf[buf_size] = 0;
  205. while (*start == ' ')
  206. start++;
  207. reg = simple_strtoul(start, &start, 16);
  208. while (*start == ' ')
  209. start++;
  210. if (strict_strtoul(start, 16, &value))
  211. return -EINVAL;
  212. /* Userspace has been fiddling around behind the kernel's back */
  213. add_taint(TAINT_USER);
  214. snd_soc_write(codec, reg, value);
  215. return buf_size;
  216. }
  217. static const struct file_operations codec_reg_fops = {
  218. .open = simple_open,
  219. .read = codec_reg_read_file,
  220. .write = codec_reg_write_file,
  221. .llseek = default_llseek,
  222. };
  223. static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
  224. {
  225. struct dentry *debugfs_card_root = codec->card->debugfs_card_root;
  226. codec->debugfs_codec_root = debugfs_create_dir(codec->name,
  227. debugfs_card_root);
  228. if (!codec->debugfs_codec_root) {
  229. dev_warn(codec->dev, "ASoC: Failed to create codec debugfs"
  230. " directory\n");
  231. return;
  232. }
  233. debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root,
  234. &codec->cache_sync);
  235. debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root,
  236. &codec->cache_only);
  237. codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
  238. codec->debugfs_codec_root,
  239. codec, &codec_reg_fops);
  240. if (!codec->debugfs_reg)
  241. dev_warn(codec->dev, "ASoC: Failed to create codec register"
  242. " debugfs file\n");
  243. snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root);
  244. }
  245. static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
  246. {
  247. debugfs_remove_recursive(codec->debugfs_codec_root);
  248. }
  249. static void soc_init_platform_debugfs(struct snd_soc_platform *platform)
  250. {
  251. struct dentry *debugfs_card_root = platform->card->debugfs_card_root;
  252. platform->debugfs_platform_root = debugfs_create_dir(platform->name,
  253. debugfs_card_root);
  254. if (!platform->debugfs_platform_root) {
  255. dev_warn(platform->dev,
  256. "ASoC: Failed to create platform debugfs directory\n");
  257. return;
  258. }
  259. snd_soc_dapm_debugfs_init(&platform->dapm,
  260. platform->debugfs_platform_root);
  261. }
  262. static void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform)
  263. {
  264. debugfs_remove_recursive(platform->debugfs_platform_root);
  265. }
  266. static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
  267. size_t count, loff_t *ppos)
  268. {
  269. char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  270. ssize_t len, ret = 0;
  271. struct snd_soc_codec *codec;
  272. if (!buf)
  273. return -ENOMEM;
  274. list_for_each_entry(codec, &codec_list, list) {
  275. len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
  276. codec->name);
  277. if (len >= 0)
  278. ret += len;
  279. if (ret > PAGE_SIZE) {
  280. ret = PAGE_SIZE;
  281. break;
  282. }
  283. }
  284. if (ret >= 0)
  285. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  286. kfree(buf);
  287. return ret;
  288. }
  289. static const struct file_operations codec_list_fops = {
  290. .read = codec_list_read_file,
  291. .llseek = default_llseek,/* read accesses f_pos */
  292. };
  293. static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
  294. size_t count, loff_t *ppos)
  295. {
  296. char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  297. ssize_t len, ret = 0;
  298. struct snd_soc_dai *dai;
  299. if (!buf)
  300. return -ENOMEM;
  301. list_for_each_entry(dai, &dai_list, list) {
  302. len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name);
  303. if (len >= 0)
  304. ret += len;
  305. if (ret > PAGE_SIZE) {
  306. ret = PAGE_SIZE;
  307. break;
  308. }
  309. }
  310. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  311. kfree(buf);
  312. return ret;
  313. }
  314. static const struct file_operations dai_list_fops = {
  315. .read = dai_list_read_file,
  316. .llseek = default_llseek,/* read accesses f_pos */
  317. };
  318. static ssize_t platform_list_read_file(struct file *file,
  319. char __user *user_buf,
  320. size_t count, loff_t *ppos)
  321. {
  322. char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  323. ssize_t len, ret = 0;
  324. struct snd_soc_platform *platform;
  325. if (!buf)
  326. return -ENOMEM;
  327. list_for_each_entry(platform, &platform_list, list) {
  328. len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
  329. platform->name);
  330. if (len >= 0)
  331. ret += len;
  332. if (ret > PAGE_SIZE) {
  333. ret = PAGE_SIZE;
  334. break;
  335. }
  336. }
  337. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  338. kfree(buf);
  339. return ret;
  340. }
  341. static const struct file_operations platform_list_fops = {
  342. .read = platform_list_read_file,
  343. .llseek = default_llseek,/* read accesses f_pos */
  344. };
  345. static void soc_init_card_debugfs(struct snd_soc_card *card)
  346. {
  347. card->debugfs_card_root = debugfs_create_dir(card->name,
  348. snd_soc_debugfs_root);
  349. if (!card->debugfs_card_root) {
  350. dev_warn(card->dev,
  351. "ASoC: Failed to create card debugfs directory\n");
  352. return;
  353. }
  354. card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
  355. card->debugfs_card_root,
  356. &card->pop_time);
  357. if (!card->debugfs_pop_time)
  358. dev_warn(card->dev,
  359. "ASoC: Failed to create pop time debugfs file\n");
  360. }
  361. static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
  362. {
  363. debugfs_remove_recursive(card->debugfs_card_root);
  364. }
  365. #else
  366. static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
  367. {
  368. }
  369. static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
  370. {
  371. }
  372. static inline void soc_init_platform_debugfs(struct snd_soc_platform *platform)
  373. {
  374. }
  375. static inline void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform)
  376. {
  377. }
  378. static inline void soc_init_card_debugfs(struct snd_soc_card *card)
  379. {
  380. }
  381. static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
  382. {
  383. }
  384. #endif
  385. struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
  386. const char *dai_link, int stream)
  387. {
  388. int i;
  389. for (i = 0; i < card->num_links; i++) {
  390. if (card->rtd[i].dai_link->no_pcm &&
  391. !strcmp(card->rtd[i].dai_link->name, dai_link))
  392. return card->rtd[i].pcm->streams[stream].substream;
  393. }
  394. dev_dbg(card->dev, "ASoC: failed to find dai link %s\n", dai_link);
  395. return NULL;
  396. }
  397. EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream);
  398. struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
  399. const char *dai_link)
  400. {
  401. int i;
  402. for (i = 0; i < card->num_links; i++) {
  403. if (!strcmp(card->rtd[i].dai_link->name, dai_link))
  404. return &card->rtd[i];
  405. }
  406. dev_dbg(card->dev, "ASoC: failed to find rtd %s\n", dai_link);
  407. return NULL;
  408. }
  409. EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
  410. #ifdef CONFIG_SND_SOC_AC97_BUS
  411. /* unregister ac97 codec */
  412. static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
  413. {
  414. if (codec->ac97->dev.bus)
  415. device_unregister(&codec->ac97->dev);
  416. return 0;
  417. }
  418. /* stop no dev release warning */
  419. static void soc_ac97_device_release(struct device *dev){}
  420. /* register ac97 codec to bus */
  421. static int soc_ac97_dev_register(struct snd_soc_codec *codec)
  422. {
  423. int err;
  424. codec->ac97->dev.bus = &ac97_bus_type;
  425. codec->ac97->dev.parent = codec->card->dev;
  426. codec->ac97->dev.release = soc_ac97_device_release;
  427. dev_set_name(&codec->ac97->dev, "%d-%d:%s",
  428. codec->card->snd_card->number, 0, codec->name);
  429. err = device_register(&codec->ac97->dev);
  430. if (err < 0) {
  431. dev_err(codec->dev, "ASoC: Can't register ac97 bus\n");
  432. codec->ac97->dev.bus = NULL;
  433. return err;
  434. }
  435. return 0;
  436. }
  437. #endif
  438. #ifdef CONFIG_PM_SLEEP
  439. /* powers down audio subsystem for suspend */
  440. int snd_soc_suspend(struct device *dev)
  441. {
  442. struct snd_soc_card *card = dev_get_drvdata(dev);
  443. struct snd_soc_codec *codec;
  444. int i;
  445. /* If the initialization of this soc device failed, there is no codec
  446. * associated with it. Just bail out in this case.
  447. */
  448. if (list_empty(&card->codec_dev_list))
  449. return 0;
  450. /* Due to the resume being scheduled into a workqueue we could
  451. * suspend before that's finished - wait for it to complete.
  452. */
  453. snd_power_lock(card->snd_card);
  454. snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
  455. snd_power_unlock(card->snd_card);
  456. /* we're going to block userspace touching us until resume completes */
  457. snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
  458. /* mute any active DACs */
  459. for (i = 0; i < card->num_rtd; i++) {
  460. struct snd_soc_dai *dai = card->rtd[i].codec_dai;
  461. struct snd_soc_dai_driver *drv = dai->driver;
  462. if (card->rtd[i].dai_link->ignore_suspend)
  463. continue;
  464. if (drv->ops->digital_mute && dai->playback_active)
  465. drv->ops->digital_mute(dai, 1);
  466. }
  467. /* suspend all pcms */
  468. for (i = 0; i < card->num_rtd; i++) {
  469. if (card->rtd[i].dai_link->ignore_suspend)
  470. continue;
  471. snd_pcm_suspend_all(card->rtd[i].pcm);
  472. }
  473. if (card->suspend_pre)
  474. card->suspend_pre(card);
  475. for (i = 0; i < card->num_rtd; i++) {
  476. struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
  477. struct snd_soc_platform *platform = card->rtd[i].platform;
  478. if (card->rtd[i].dai_link->ignore_suspend)
  479. continue;
  480. if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control)
  481. cpu_dai->driver->suspend(cpu_dai);
  482. if (platform->driver->suspend && !platform->suspended) {
  483. platform->driver->suspend(cpu_dai);
  484. platform->suspended = 1;
  485. }
  486. }
  487. /* close any waiting streams and save state */
  488. for (i = 0; i < card->num_rtd; i++) {
  489. flush_delayed_work(&card->rtd[i].delayed_work);
  490. card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
  491. }
  492. for (i = 0; i < card->num_rtd; i++) {
  493. if (card->rtd[i].dai_link->ignore_suspend)
  494. continue;
  495. snd_soc_dapm_stream_event(&card->rtd[i],
  496. SNDRV_PCM_STREAM_PLAYBACK,
  497. SND_SOC_DAPM_STREAM_SUSPEND);
  498. snd_soc_dapm_stream_event(&card->rtd[i],
  499. SNDRV_PCM_STREAM_CAPTURE,
  500. SND_SOC_DAPM_STREAM_SUSPEND);
  501. }
  502. /* Recheck all analogue paths too */
  503. dapm_mark_io_dirty(&card->dapm);
  504. snd_soc_dapm_sync(&card->dapm);
  505. /* suspend all CODECs */
  506. list_for_each_entry(codec, &card->codec_dev_list, card_list) {
  507. /* If there are paths active then the CODEC will be held with
  508. * bias _ON and should not be suspended. */
  509. if (!codec->suspended && codec->driver->suspend) {
  510. switch (codec->dapm.bias_level) {
  511. case SND_SOC_BIAS_STANDBY:
  512. /*
  513. * If the CODEC is capable of idle
  514. * bias off then being in STANDBY
  515. * means it's doing something,
  516. * otherwise fall through.
  517. */
  518. if (codec->dapm.idle_bias_off) {
  519. dev_dbg(codec->dev,
  520. "ASoC: idle_bias_off CODEC on"
  521. " over suspend\n");
  522. break;
  523. }
  524. case SND_SOC_BIAS_OFF:
  525. codec->driver->suspend(codec);
  526. codec->suspended = 1;
  527. codec->cache_sync = 1;
  528. if (codec->using_regmap)
  529. regcache_mark_dirty(codec->control_data);
  530. break;
  531. default:
  532. dev_dbg(codec->dev, "ASoC: CODEC is on"
  533. " over suspend\n");
  534. break;
  535. }
  536. }
  537. }
  538. for (i = 0; i < card->num_rtd; i++) {
  539. struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
  540. if (card->rtd[i].dai_link->ignore_suspend)
  541. continue;
  542. if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
  543. cpu_dai->driver->suspend(cpu_dai);
  544. }
  545. if (card->suspend_post)
  546. card->suspend_post(card);
  547. return 0;
  548. }
  549. EXPORT_SYMBOL_GPL(snd_soc_suspend);
  550. /* deferred resume work, so resume can complete before we finished
  551. * setting our codec back up, which can be very slow on I2C
  552. */
  553. static void soc_resume_deferred(struct work_struct *work)
  554. {
  555. struct snd_soc_card *card =
  556. container_of(work, struct snd_soc_card, deferred_resume_work);
  557. struct snd_soc_codec *codec;
  558. int i;
  559. /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
  560. * so userspace apps are blocked from touching us
  561. */
  562. dev_dbg(card->dev, "ASoC: starting resume work\n");
  563. /* Bring us up into D2 so that DAPM starts enabling things */
  564. snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
  565. if (card->resume_pre)
  566. card->resume_pre(card);
  567. /* resume AC97 DAIs */
  568. for (i = 0; i < card->num_rtd; i++) {
  569. struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
  570. if (card->rtd[i].dai_link->ignore_suspend)
  571. continue;
  572. if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control)
  573. cpu_dai->driver->resume(cpu_dai);
  574. }
  575. list_for_each_entry(codec, &card->codec_dev_list, card_list) {
  576. /* If the CODEC was idle over suspend then it will have been
  577. * left with bias OFF or STANDBY and suspended so we must now
  578. * resume. Otherwise the suspend was suppressed.
  579. */
  580. if (codec->driver->resume && codec->suspended) {
  581. switch (codec->dapm.bias_level) {
  582. case SND_SOC_BIAS_STANDBY:
  583. case SND_SOC_BIAS_OFF:
  584. codec->driver->resume(codec);
  585. codec->suspended = 0;
  586. break;
  587. default:
  588. dev_dbg(codec->dev, "ASoC: CODEC was on over"
  589. " suspend\n");
  590. break;
  591. }
  592. }
  593. }
  594. for (i = 0; i < card->num_rtd; i++) {
  595. if (card->rtd[i].dai_link->ignore_suspend)
  596. continue;
  597. snd_soc_dapm_stream_event(&card->rtd[i],
  598. SNDRV_PCM_STREAM_PLAYBACK,
  599. SND_SOC_DAPM_STREAM_RESUME);
  600. snd_soc_dapm_stream_event(&card->rtd[i],
  601. SNDRV_PCM_STREAM_CAPTURE,
  602. SND_SOC_DAPM_STREAM_RESUME);
  603. }
  604. /* unmute any active DACs */
  605. for (i = 0; i < card->num_rtd; i++) {
  606. struct snd_soc_dai *dai = card->rtd[i].codec_dai;
  607. struct snd_soc_dai_driver *drv = dai->driver;
  608. if (card->rtd[i].dai_link->ignore_suspend)
  609. continue;
  610. if (drv->ops->digital_mute && dai->playback_active)
  611. drv->ops->digital_mute(dai, 0);
  612. }
  613. for (i = 0; i < card->num_rtd; i++) {
  614. struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
  615. struct snd_soc_platform *platform = card->rtd[i].platform;
  616. if (card->rtd[i].dai_link->ignore_suspend)
  617. continue;
  618. if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control)
  619. cpu_dai->driver->resume(cpu_dai);
  620. if (platform->driver->resume && platform->suspended) {
  621. platform->driver->resume(cpu_dai);
  622. platform->suspended = 0;
  623. }
  624. }
  625. if (card->resume_post)
  626. card->resume_post(card);
  627. dev_dbg(card->dev, "ASoC: resume work completed\n");
  628. /* userspace can access us now we are back as we were before */
  629. snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
  630. /* Recheck all analogue paths too */
  631. dapm_mark_io_dirty(&card->dapm);
  632. snd_soc_dapm_sync(&card->dapm);
  633. }
  634. /* powers up audio subsystem after a suspend */
  635. int snd_soc_resume(struct device *dev)
  636. {
  637. struct snd_soc_card *card = dev_get_drvdata(dev);
  638. int i, ac97_control = 0;
  639. /* If the initialization of this soc device failed, there is no codec
  640. * associated with it. Just bail out in this case.
  641. */
  642. if (list_empty(&card->codec_dev_list))
  643. return 0;
  644. /* AC97 devices might have other drivers hanging off them so
  645. * need to resume immediately. Other drivers don't have that
  646. * problem and may take a substantial amount of time to resume
  647. * due to I/O costs and anti-pop so handle them out of line.
  648. */
  649. for (i = 0; i < card->num_rtd; i++) {
  650. struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
  651. ac97_control |= cpu_dai->driver->ac97_control;
  652. }
  653. if (ac97_control) {
  654. dev_dbg(dev, "ASoC: Resuming AC97 immediately\n");
  655. soc_resume_deferred(&card->deferred_resume_work);
  656. } else {
  657. dev_dbg(dev, "ASoC: Scheduling resume work\n");
  658. if (!schedule_work(&card->deferred_resume_work))
  659. dev_err(dev, "ASoC: resume work item may be lost\n");
  660. }
  661. return 0;
  662. }
  663. EXPORT_SYMBOL_GPL(snd_soc_resume);
  664. #else
  665. #define snd_soc_suspend NULL
  666. #define snd_soc_resume NULL
  667. #endif
  668. static const struct snd_soc_dai_ops null_dai_ops = {
  669. };
  670. static int soc_bind_dai_link(struct snd_soc_card *card, int num)
  671. {
  672. struct snd_soc_dai_link *dai_link = &card->dai_link[num];
  673. struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
  674. struct snd_soc_codec *codec;
  675. struct snd_soc_platform *platform;
  676. struct snd_soc_dai *codec_dai, *cpu_dai;
  677. const char *platform_name;
  678. dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num);
  679. /* Find CPU DAI from registered DAIs*/
  680. list_for_each_entry(cpu_dai, &dai_list, list) {
  681. if (dai_link->cpu_of_node &&
  682. (cpu_dai->dev->of_node != dai_link->cpu_of_node))
  683. continue;
  684. if (dai_link->cpu_name &&
  685. strcmp(dev_name(cpu_dai->dev), dai_link->cpu_name))
  686. continue;
  687. if (dai_link->cpu_dai_name &&
  688. strcmp(cpu_dai->name, dai_link->cpu_dai_name))
  689. continue;
  690. rtd->cpu_dai = cpu_dai;
  691. }
  692. if (!rtd->cpu_dai) {
  693. dev_err(card->dev, "ASoC: CPU DAI %s not registered\n",
  694. dai_link->cpu_dai_name);
  695. return -EPROBE_DEFER;
  696. }
  697. /* Find CODEC from registered CODECs */
  698. list_for_each_entry(codec, &codec_list, list) {
  699. if (dai_link->codec_of_node) {
  700. if (codec->dev->of_node != dai_link->codec_of_node)
  701. continue;
  702. } else {
  703. if (strcmp(codec->name, dai_link->codec_name))
  704. continue;
  705. }
  706. rtd->codec = codec;
  707. /*
  708. * CODEC found, so find CODEC DAI from registered DAIs from
  709. * this CODEC
  710. */
  711. list_for_each_entry(codec_dai, &dai_list, list) {
  712. if (codec->dev == codec_dai->dev &&
  713. !strcmp(codec_dai->name,
  714. dai_link->codec_dai_name)) {
  715. rtd->codec_dai = codec_dai;
  716. }
  717. }
  718. if (!rtd->codec_dai) {
  719. dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
  720. dai_link->codec_dai_name);
  721. return -EPROBE_DEFER;
  722. }
  723. }
  724. if (!rtd->codec) {
  725. dev_err(card->dev, "ASoC: CODEC %s not registered\n",
  726. dai_link->codec_name);
  727. return -EPROBE_DEFER;
  728. }
  729. /* if there's no platform we match on the empty platform */
  730. platform_name = dai_link->platform_name;
  731. if (!platform_name && !dai_link->platform_of_node)
  732. platform_name = "snd-soc-dummy";
  733. /* find one from the set of registered platforms */
  734. list_for_each_entry(platform, &platform_list, list) {
  735. if (dai_link->platform_of_node) {
  736. if (platform->dev->of_node !=
  737. dai_link->platform_of_node)
  738. continue;
  739. } else {
  740. if (strcmp(platform->name, platform_name))
  741. continue;
  742. }
  743. rtd->platform = platform;
  744. }
  745. if (!rtd->platform) {
  746. dev_err(card->dev, "ASoC: platform %s not registered\n",
  747. dai_link->platform_name);
  748. return -EPROBE_DEFER;
  749. }
  750. card->num_rtd++;
  751. return 0;
  752. }
  753. static int soc_remove_platform(struct snd_soc_platform *platform)
  754. {
  755. int ret;
  756. if (platform->driver->remove) {
  757. ret = platform->driver->remove(platform);
  758. if (ret < 0)
  759. dev_err(platform->dev, "ASoC: failed to remove %d\n",
  760. ret);
  761. }
  762. /* Make sure all DAPM widgets are freed */
  763. snd_soc_dapm_free(&platform->dapm);
  764. soc_cleanup_platform_debugfs(platform);
  765. platform->probed = 0;
  766. list_del(&platform->card_list);
  767. module_put(platform->dev->driver->owner);
  768. return 0;
  769. }
  770. static void soc_remove_codec(struct snd_soc_codec *codec)
  771. {
  772. int err;
  773. if (codec->driver->remove) {
  774. err = codec->driver->remove(codec);
  775. if (err < 0)
  776. dev_err(codec->dev, "ASoC: failed to remove %d\n", err);
  777. }
  778. /* Make sure all DAPM widgets are freed */
  779. snd_soc_dapm_free(&codec->dapm);
  780. soc_cleanup_codec_debugfs(codec);
  781. codec->probed = 0;
  782. list_del(&codec->card_list);
  783. module_put(codec->dev->driver->owner);
  784. }
  785. static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order)
  786. {
  787. struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
  788. struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
  789. int err;
  790. /* unregister the rtd device */
  791. if (rtd->dev_registered) {
  792. device_remove_file(rtd->dev, &dev_attr_pmdown_time);
  793. device_remove_file(rtd->dev, &dev_attr_codec_reg);
  794. device_unregister(rtd->dev);
  795. rtd->dev_registered = 0;
  796. }
  797. /* remove the CODEC DAI */
  798. if (codec_dai && codec_dai->probed &&
  799. codec_dai->driver->remove_order == order) {
  800. if (codec_dai->driver->remove) {
  801. err = codec_dai->driver->remove(codec_dai);
  802. if (err < 0)
  803. dev_err(codec_dai->dev,
  804. "ASoC: failed to remove %s: %d\n",
  805. codec_dai->name, err);
  806. }
  807. codec_dai->probed = 0;
  808. list_del(&codec_dai->card_list);
  809. }
  810. /* remove the cpu_dai */
  811. if (cpu_dai && cpu_dai->probed &&
  812. cpu_dai->driver->remove_order == order) {
  813. if (cpu_dai->driver->remove) {
  814. err = cpu_dai->driver->remove(cpu_dai);
  815. if (err < 0)
  816. dev_err(cpu_dai->dev,
  817. "ASoC: failed to remove %s: %d\n",
  818. cpu_dai->name, err);
  819. }
  820. cpu_dai->probed = 0;
  821. list_del(&cpu_dai->card_list);
  822. if (!cpu_dai->codec) {
  823. snd_soc_dapm_free(&cpu_dai->dapm);
  824. module_put(cpu_dai->dev->driver->owner);
  825. }
  826. }
  827. }
  828. static void soc_remove_link_components(struct snd_soc_card *card, int num,
  829. int order)
  830. {
  831. struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
  832. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  833. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  834. struct snd_soc_platform *platform = rtd->platform;
  835. struct snd_soc_codec *codec;
  836. /* remove the platform */
  837. if (platform && platform->probed &&
  838. platform->driver->remove_order == order) {
  839. soc_remove_platform(platform);
  840. }
  841. /* remove the CODEC-side CODEC */
  842. if (codec_dai) {
  843. codec = codec_dai->codec;
  844. if (codec && codec->probed &&
  845. codec->driver->remove_order == order)
  846. soc_remove_codec(codec);
  847. }
  848. /* remove any CPU-side CODEC */
  849. if (cpu_dai) {
  850. codec = cpu_dai->codec;
  851. if (codec && codec->probed &&
  852. codec->driver->remove_order == order)
  853. soc_remove_codec(codec);
  854. }
  855. }
  856. static void soc_remove_dai_links(struct snd_soc_card *card)
  857. {
  858. int dai, order;
  859. for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
  860. order++) {
  861. for (dai = 0; dai < card->num_rtd; dai++)
  862. soc_remove_link_dais(card, dai, order);
  863. }
  864. for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
  865. order++) {
  866. for (dai = 0; dai < card->num_rtd; dai++)
  867. soc_remove_link_components(card, dai, order);
  868. }
  869. card->num_rtd = 0;
  870. }
  871. static void soc_set_name_prefix(struct snd_soc_card *card,
  872. struct snd_soc_codec *codec)
  873. {
  874. int i;
  875. if (card->codec_conf == NULL)
  876. return;
  877. for (i = 0; i < card->num_configs; i++) {
  878. struct snd_soc_codec_conf *map = &card->codec_conf[i];
  879. if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
  880. codec->name_prefix = map->name_prefix;
  881. break;
  882. }
  883. }
  884. }
  885. static int soc_probe_codec(struct snd_soc_card *card,
  886. struct snd_soc_codec *codec)
  887. {
  888. int ret = 0;
  889. const struct snd_soc_codec_driver *driver = codec->driver;
  890. struct snd_soc_dai *dai;
  891. codec->card = card;
  892. codec->dapm.card = card;
  893. soc_set_name_prefix(card, codec);
  894. if (!try_module_get(codec->dev->driver->owner))
  895. return -ENODEV;
  896. soc_init_codec_debugfs(codec);
  897. if (driver->dapm_widgets)
  898. snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets,
  899. driver->num_dapm_widgets);
  900. /* Create DAPM widgets for each DAI stream */
  901. list_for_each_entry(dai, &dai_list, list) {
  902. if (dai->dev != codec->dev)
  903. continue;
  904. snd_soc_dapm_new_dai_widgets(&codec->dapm, dai);
  905. }
  906. codec->dapm.idle_bias_off = driver->idle_bias_off;
  907. if (driver->probe) {
  908. ret = driver->probe(codec);
  909. if (ret < 0) {
  910. dev_err(codec->dev,
  911. "ASoC: failed to probe CODEC %d\n", ret);
  912. goto err_probe;
  913. }
  914. }
  915. /* If the driver didn't set I/O up try regmap */
  916. if (!codec->write && dev_get_regmap(codec->dev, NULL))
  917. snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
  918. if (driver->controls)
  919. snd_soc_add_codec_controls(codec, driver->controls,
  920. driver->num_controls);
  921. if (driver->dapm_routes)
  922. snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
  923. driver->num_dapm_routes);
  924. /* mark codec as probed and add to card codec list */
  925. codec->probed = 1;
  926. list_add(&codec->card_list, &card->codec_dev_list);
  927. list_add(&codec->dapm.list, &card->dapm_list);
  928. return 0;
  929. err_probe:
  930. soc_cleanup_codec_debugfs(codec);
  931. module_put(codec->dev->driver->owner);
  932. return ret;
  933. }
  934. static int soc_probe_platform(struct snd_soc_card *card,
  935. struct snd_soc_platform *platform)
  936. {
  937. int ret = 0;
  938. const struct snd_soc_platform_driver *driver = platform->driver;
  939. struct snd_soc_dai *dai;
  940. platform->card = card;
  941. platform->dapm.card = card;
  942. if (!try_module_get(platform->dev->driver->owner))
  943. return -ENODEV;
  944. soc_init_platform_debugfs(platform);
  945. if (driver->dapm_widgets)
  946. snd_soc_dapm_new_controls(&platform->dapm,
  947. driver->dapm_widgets, driver->num_dapm_widgets);
  948. /* Create DAPM widgets for each DAI stream */
  949. list_for_each_entry(dai, &dai_list, list) {
  950. if (dai->dev != platform->dev)
  951. continue;
  952. snd_soc_dapm_new_dai_widgets(&platform->dapm, dai);
  953. }
  954. platform->dapm.idle_bias_off = 1;
  955. if (driver->probe) {
  956. ret = driver->probe(platform);
  957. if (ret < 0) {
  958. dev_err(platform->dev,
  959. "ASoC: failed to probe platform %d\n", ret);
  960. goto err_probe;
  961. }
  962. }
  963. if (driver->controls)
  964. snd_soc_add_platform_controls(platform, driver->controls,
  965. driver->num_controls);
  966. if (driver->dapm_routes)
  967. snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes,
  968. driver->num_dapm_routes);
  969. /* mark platform as probed and add to card platform list */
  970. platform->probed = 1;
  971. list_add(&platform->card_list, &card->platform_dev_list);
  972. list_add(&platform->dapm.list, &card->dapm_list);
  973. return 0;
  974. err_probe:
  975. soc_cleanup_platform_debugfs(platform);
  976. module_put(platform->dev->driver->owner);
  977. return ret;
  978. }
  979. static void rtd_release(struct device *dev)
  980. {
  981. kfree(dev);
  982. }
  983. static int soc_post_component_init(struct snd_soc_card *card,
  984. struct snd_soc_codec *codec,
  985. int num, int dailess)
  986. {
  987. struct snd_soc_dai_link *dai_link = NULL;
  988. struct snd_soc_aux_dev *aux_dev = NULL;
  989. struct snd_soc_pcm_runtime *rtd;
  990. const char *temp, *name;
  991. int ret = 0;
  992. if (!dailess) {
  993. dai_link = &card->dai_link[num];
  994. rtd = &card->rtd[num];
  995. name = dai_link->name;
  996. } else {
  997. aux_dev = &card->aux_dev[num];
  998. rtd = &card->rtd_aux[num];
  999. name = aux_dev->name;
  1000. }
  1001. rtd->card = card;
  1002. /* Make sure all DAPM widgets are instantiated */
  1003. snd_soc_dapm_new_widgets(&codec->dapm);
  1004. /* machine controls, routes and widgets are not prefixed */
  1005. temp = codec->name_prefix;
  1006. codec->name_prefix = NULL;
  1007. /* do machine specific initialization */
  1008. if (!dailess && dai_link->init)
  1009. ret = dai_link->init(rtd);
  1010. else if (dailess && aux_dev->init)
  1011. ret = aux_dev->init(&codec->dapm);
  1012. if (ret < 0) {
  1013. dev_err(card->dev, "ASoC: failed to init %s: %d\n", name, ret);
  1014. return ret;
  1015. }
  1016. codec->name_prefix = temp;
  1017. /* register the rtd device */
  1018. rtd->codec = codec;
  1019. rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
  1020. if (!rtd->dev)
  1021. return -ENOMEM;
  1022. device_initialize(rtd->dev);
  1023. rtd->dev->parent = card->dev;
  1024. rtd->dev->release = rtd_release;
  1025. rtd->dev->init_name = name;
  1026. dev_set_drvdata(rtd->dev, rtd);
  1027. mutex_init(&rtd->pcm_mutex);
  1028. INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
  1029. INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
  1030. INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
  1031. INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
  1032. ret = device_add(rtd->dev);
  1033. if (ret < 0) {
  1034. /* calling put_device() here to free the rtd->dev */
  1035. put_device(rtd->dev);
  1036. dev_err(card->dev,
  1037. "ASoC: failed to register runtime device: %d\n", ret);
  1038. return ret;
  1039. }
  1040. rtd->dev_registered = 1;
  1041. /* add DAPM sysfs entries for this codec */
  1042. ret = snd_soc_dapm_sys_add(rtd->dev);
  1043. if (ret < 0)
  1044. dev_err(codec->dev,
  1045. "ASoC: failed to add codec dapm sysfs entries: %d\n", ret);
  1046. /* add codec sysfs entries */
  1047. ret = device_create_file(rtd->dev, &dev_attr_codec_reg);
  1048. if (ret < 0)
  1049. dev_err(codec->dev,
  1050. "ASoC: failed to add codec sysfs files: %d\n", ret);
  1051. #ifdef CONFIG_DEBUG_FS
  1052. /* add DPCM sysfs entries */
  1053. if (!dailess && !dai_link->dynamic)
  1054. goto out;
  1055. ret = soc_dpcm_debugfs_add(rtd);
  1056. if (ret < 0)
  1057. dev_err(rtd->dev, "ASoC: failed to add dpcm sysfs entries: %d\n", ret);
  1058. out:
  1059. #endif
  1060. return 0;
  1061. }
  1062. static int soc_probe_link_components(struct snd_soc_card *card, int num,
  1063. int order)
  1064. {
  1065. struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
  1066. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  1067. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  1068. struct snd_soc_platform *platform = rtd->platform;
  1069. int ret;
  1070. /* probe the CPU-side component, if it is a CODEC */
  1071. if (cpu_dai->codec &&
  1072. !cpu_dai->codec->probed &&
  1073. cpu_dai->codec->driver->probe_order == order) {
  1074. ret = soc_probe_codec(card, cpu_dai->codec);
  1075. if (ret < 0)
  1076. return ret;
  1077. }
  1078. /* probe the CODEC-side component */
  1079. if (!codec_dai->codec->probed &&
  1080. codec_dai->codec->driver->probe_order == order) {
  1081. ret = soc_probe_codec(card, codec_dai->codec);
  1082. if (ret < 0)
  1083. return ret;
  1084. }
  1085. /* probe the platform */
  1086. if (!platform->probed &&
  1087. platform->driver->probe_order == order) {
  1088. ret = soc_probe_platform(card, platform);
  1089. if (ret < 0)
  1090. return ret;
  1091. }
  1092. return 0;
  1093. }
  1094. static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
  1095. {
  1096. struct snd_soc_dai_link *dai_link = &card->dai_link[num];
  1097. struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
  1098. struct snd_soc_codec *codec = rtd->codec;
  1099. struct snd_soc_platform *platform = rtd->platform;
  1100. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  1101. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  1102. struct snd_soc_dapm_widget *play_w, *capture_w;
  1103. int ret;
  1104. dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n",
  1105. card->name, num, order);
  1106. /* config components */
  1107. cpu_dai->platform = platform;
  1108. codec_dai->card = card;
  1109. cpu_dai->card = card;
  1110. /* set default power off timeout */
  1111. rtd->pmdown_time = pmdown_time;
  1112. /* probe the cpu_dai */
  1113. if (!cpu_dai->probed &&
  1114. cpu_dai->driver->probe_order == order) {
  1115. if (!cpu_dai->codec) {
  1116. cpu_dai->dapm.card = card;
  1117. if (!try_module_get(cpu_dai->dev->driver->owner))
  1118. return -ENODEV;
  1119. list_add(&cpu_dai->dapm.list, &card->dapm_list);
  1120. snd_soc_dapm_new_dai_widgets(&cpu_dai->dapm, cpu_dai);
  1121. }
  1122. if (cpu_dai->driver->probe) {
  1123. ret = cpu_dai->driver->probe(cpu_dai);
  1124. if (ret < 0) {
  1125. dev_err(cpu_dai->dev,
  1126. "ASoC: failed to probe CPU DAI %s: %d\n",
  1127. cpu_dai->name, ret);
  1128. module_put(cpu_dai->dev->driver->owner);
  1129. return ret;
  1130. }
  1131. }
  1132. cpu_dai->probed = 1;
  1133. /* mark cpu_dai as probed and add to card dai list */
  1134. list_add(&cpu_dai->card_list, &card->dai_dev_list);
  1135. }
  1136. /* probe the CODEC DAI */
  1137. if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
  1138. if (codec_dai->driver->probe) {
  1139. ret = codec_dai->driver->probe(codec_dai);
  1140. if (ret < 0) {
  1141. dev_err(codec_dai->dev,
  1142. "ASoC: failed to probe CODEC DAI %s: %d\n",
  1143. codec_dai->name, ret);
  1144. return ret;
  1145. }
  1146. }
  1147. /* mark codec_dai as probed and add to card dai list */
  1148. codec_dai->probed = 1;
  1149. list_add(&codec_dai->card_list, &card->dai_dev_list);
  1150. }
  1151. /* complete DAI probe during last probe */
  1152. if (order != SND_SOC_COMP_ORDER_LAST)
  1153. return 0;
  1154. ret = soc_post_component_init(card, codec, num, 0);
  1155. if (ret)
  1156. return ret;
  1157. ret = device_create_file(rtd->dev, &dev_attr_pmdown_time);
  1158. if (ret < 0)
  1159. dev_warn(rtd->dev, "ASoC: failed to add pmdown_time sysfs: %d\n",
  1160. ret);
  1161. if (cpu_dai->driver->compress_dai) {
  1162. /*create compress_device"*/
  1163. ret = soc_new_compress(rtd, num);
  1164. if (ret < 0) {
  1165. dev_err(card->dev, "ASoC: can't create compress %s\n",
  1166. dai_link->stream_name);
  1167. return ret;
  1168. }
  1169. } else {
  1170. if (!dai_link->params) {
  1171. /* create the pcm */
  1172. ret = soc_new_pcm(rtd, num);
  1173. if (ret < 0) {
  1174. dev_err(card->dev, "ASoC: can't create pcm %s :%d\n",
  1175. dai_link->stream_name, ret);
  1176. return ret;
  1177. }
  1178. } else {
  1179. /* link the DAI widgets */
  1180. play_w = codec_dai->playback_widget;
  1181. capture_w = cpu_dai->capture_widget;
  1182. if (play_w && capture_w) {
  1183. ret = snd_soc_dapm_new_pcm(card, dai_link->params,
  1184. capture_w, play_w);
  1185. if (ret != 0) {
  1186. dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
  1187. play_w->name, capture_w->name, ret);
  1188. return ret;
  1189. }
  1190. }
  1191. play_w = cpu_dai->playback_widget;
  1192. capture_w = codec_dai->capture_widget;
  1193. if (play_w && capture_w) {
  1194. ret = snd_soc_dapm_new_pcm(card, dai_link->params,
  1195. capture_w, play_w);
  1196. if (ret != 0) {
  1197. dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
  1198. play_w->name, capture_w->name, ret);
  1199. return ret;
  1200. }
  1201. }
  1202. }
  1203. }
  1204. /* add platform data for AC97 devices */
  1205. if (rtd->codec_dai->driver->ac97_control)
  1206. snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
  1207. return 0;
  1208. }
  1209. #ifdef CONFIG_SND_SOC_AC97_BUS
  1210. static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
  1211. {
  1212. int ret;
  1213. /* Only instantiate AC97 if not already done by the adaptor
  1214. * for the generic AC97 subsystem.
  1215. */
  1216. if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
  1217. /*
  1218. * It is possible that the AC97 device is already registered to
  1219. * the device subsystem. This happens when the device is created
  1220. * via snd_ac97_mixer(). Currently only SoC codec that does so
  1221. * is the generic AC97 glue but others migh emerge.
  1222. *
  1223. * In those cases we don't try to register the device again.
  1224. */
  1225. if (!rtd->codec->ac97_created)
  1226. return 0;
  1227. ret = soc_ac97_dev_register(rtd->codec);
  1228. if (ret < 0) {
  1229. dev_err(rtd->codec->dev,
  1230. "ASoC: AC97 device register failed: %d\n", ret);
  1231. return ret;
  1232. }
  1233. rtd->codec->ac97_registered = 1;
  1234. }
  1235. return 0;
  1236. }
  1237. static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
  1238. {
  1239. if (codec->ac97_registered) {
  1240. soc_ac97_dev_unregister(codec);
  1241. codec->ac97_registered = 0;
  1242. }
  1243. }
  1244. #endif
  1245. static int soc_check_aux_dev(struct snd_soc_card *card, int num)
  1246. {
  1247. struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
  1248. struct snd_soc_codec *codec;
  1249. /* find CODEC from registered CODECs*/
  1250. list_for_each_entry(codec, &codec_list, list) {
  1251. if (!strcmp(codec->name, aux_dev->codec_name))
  1252. return 0;
  1253. }
  1254. dev_err(card->dev, "ASoC: %s not registered\n", aux_dev->codec_name);
  1255. return -EPROBE_DEFER;
  1256. }
  1257. static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
  1258. {
  1259. struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
  1260. struct snd_soc_codec *codec;
  1261. int ret = -ENODEV;
  1262. /* find CODEC from registered CODECs*/
  1263. list_for_each_entry(codec, &codec_list, list) {
  1264. if (!strcmp(codec->name, aux_dev->codec_name)) {
  1265. if (codec->probed) {
  1266. dev_err(codec->dev,
  1267. "ASoC: codec already probed");
  1268. ret = -EBUSY;
  1269. goto out;
  1270. }
  1271. goto found;
  1272. }
  1273. }
  1274. /* codec not found */
  1275. dev_err(card->dev, "ASoC: codec %s not found", aux_dev->codec_name);
  1276. return -EPROBE_DEFER;
  1277. found:
  1278. ret = soc_probe_codec(card, codec);
  1279. if (ret < 0)
  1280. return ret;
  1281. ret = soc_post_component_init(card, codec, num, 1);
  1282. out:
  1283. return ret;
  1284. }
  1285. static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
  1286. {
  1287. struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
  1288. struct snd_soc_codec *codec = rtd->codec;
  1289. /* unregister the rtd device */
  1290. if (rtd->dev_registered) {
  1291. device_remove_file(rtd->dev, &dev_attr_codec_reg);
  1292. device_del(rtd->dev);
  1293. rtd->dev_registered = 0;
  1294. }
  1295. if (codec && codec->probed)
  1296. soc_remove_codec(codec);
  1297. }
  1298. static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
  1299. enum snd_soc_compress_type compress_type)
  1300. {
  1301. int ret;
  1302. if (codec->cache_init)
  1303. return 0;
  1304. /* override the compress_type if necessary */
  1305. if (compress_type && codec->compress_type != compress_type)
  1306. codec->compress_type = compress_type;
  1307. ret = snd_soc_cache_init(codec);
  1308. if (ret < 0) {
  1309. dev_err(codec->dev, "ASoC: Failed to set cache compression"
  1310. " type: %d\n", ret);
  1311. return ret;
  1312. }
  1313. codec->cache_init = 1;
  1314. return 0;
  1315. }
  1316. static int snd_soc_instantiate_card(struct snd_soc_card *card)
  1317. {
  1318. struct snd_soc_codec *codec;
  1319. struct snd_soc_codec_conf *codec_conf;
  1320. enum snd_soc_compress_type compress_type;
  1321. struct snd_soc_dai_link *dai_link;
  1322. int ret, i, order, dai_fmt;
  1323. mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
  1324. /* bind DAIs */
  1325. for (i = 0; i < card->num_links; i++) {
  1326. ret = soc_bind_dai_link(card, i);
  1327. if (ret != 0)
  1328. goto base_error;
  1329. }
  1330. /* check aux_devs too */
  1331. for (i = 0; i < card->num_aux_devs; i++) {
  1332. ret = soc_check_aux_dev(card, i);
  1333. if (ret != 0)
  1334. goto base_error;
  1335. }
  1336. /* initialize the register cache for each available codec */
  1337. list_for_each_entry(codec, &codec_list, list) {
  1338. if (codec->cache_init)
  1339. continue;
  1340. /* by default we don't override the compress_type */
  1341. compress_type = 0;
  1342. /* check to see if we need to override the compress_type */
  1343. for (i = 0; i < card->num_configs; ++i) {
  1344. codec_conf = &card->codec_conf[i];
  1345. if (!strcmp(codec->name, codec_conf->dev_name)) {
  1346. compress_type = codec_conf->compress_type;
  1347. if (compress_type && compress_type
  1348. != codec->compress_type)
  1349. break;
  1350. }
  1351. }
  1352. ret = snd_soc_init_codec_cache(codec, compress_type);
  1353. if (ret < 0)
  1354. goto base_error;
  1355. }
  1356. /* card bind complete so register a sound card */
  1357. ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
  1358. card->owner, 0, &card->snd_card);
  1359. if (ret < 0) {
  1360. dev_err(card->dev, "ASoC: can't create sound card for"
  1361. " card %s: %d\n", card->name, ret);
  1362. goto base_error;
  1363. }
  1364. card->snd_card->dev = card->dev;
  1365. card->dapm.bias_level = SND_SOC_BIAS_OFF;
  1366. card->dapm.dev = card->dev;
  1367. card->dapm.card = card;
  1368. list_add(&card->dapm.list, &card->dapm_list);
  1369. #ifdef CONFIG_DEBUG_FS
  1370. snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
  1371. #endif
  1372. #ifdef CONFIG_PM_SLEEP
  1373. /* deferred resume work */
  1374. INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
  1375. #endif
  1376. if (card->dapm_widgets)
  1377. snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
  1378. card->num_dapm_widgets);
  1379. /* initialise the sound card only once */
  1380. if (card->probe) {
  1381. ret = card->probe(card);
  1382. if (ret < 0)
  1383. goto card_probe_error;
  1384. }
  1385. /* probe all components used by DAI links on this card */
  1386. for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
  1387. order++) {
  1388. for (i = 0; i < card->num_links; i++) {
  1389. ret = soc_probe_link_components(card, i, order);
  1390. if (ret < 0) {
  1391. dev_err(card->dev,
  1392. "ASoC: failed to instantiate card %d\n",
  1393. ret);
  1394. goto probe_dai_err;
  1395. }
  1396. }
  1397. }
  1398. /* probe all DAI links on this card */
  1399. for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
  1400. order++) {
  1401. for (i = 0; i < card->num_links; i++) {
  1402. ret = soc_probe_link_dais(card, i, order);
  1403. if (ret < 0) {
  1404. dev_err(card->dev,
  1405. "ASoC: failed to instantiate card %d\n",
  1406. ret);
  1407. goto probe_dai_err;
  1408. }
  1409. }
  1410. }
  1411. for (i = 0; i < card->num_aux_devs; i++) {
  1412. ret = soc_probe_aux_dev(card, i);
  1413. if (ret < 0) {
  1414. dev_err(card->dev,
  1415. "ASoC: failed to add auxiliary devices %d\n",
  1416. ret);
  1417. goto probe_aux_dev_err;
  1418. }
  1419. }
  1420. snd_soc_dapm_link_dai_widgets(card);
  1421. if (card->controls)
  1422. snd_soc_add_card_controls(card, card->controls, card->num_controls);
  1423. if (card->dapm_routes)
  1424. snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
  1425. card->num_dapm_routes);
  1426. snd_soc_dapm_new_widgets(&card->dapm);
  1427. for (i = 0; i < card->num_links; i++) {
  1428. dai_link = &card->dai_link[i];
  1429. dai_fmt = dai_link->dai_fmt;
  1430. if (dai_fmt) {
  1431. ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai,
  1432. dai_fmt);
  1433. if (ret != 0 && ret != -ENOTSUPP)
  1434. dev_warn(card->rtd[i].codec_dai->dev,
  1435. "ASoC: Failed to set DAI format: %d\n",
  1436. ret);
  1437. }
  1438. /* If this is a regular CPU link there will be a platform */
  1439. if (dai_fmt &&
  1440. (dai_link->platform_name || dai_link->platform_of_node)) {
  1441. ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
  1442. dai_fmt);
  1443. if (ret != 0 && ret != -ENOTSUPP)
  1444. dev_warn(card->rtd[i].cpu_dai->dev,
  1445. "ASoC: Failed to set DAI format: %d\n",
  1446. ret);
  1447. } else if (dai_fmt) {
  1448. /* Flip the polarity for the "CPU" end */
  1449. dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
  1450. switch (dai_link->dai_fmt &
  1451. SND_SOC_DAIFMT_MASTER_MASK) {
  1452. case SND_SOC_DAIFMT_CBM_CFM:
  1453. dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
  1454. break;
  1455. case SND_SOC_DAIFMT_CBM_CFS:
  1456. dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
  1457. break;
  1458. case SND_SOC_DAIFMT_CBS_CFM:
  1459. dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
  1460. break;
  1461. case SND_SOC_DAIFMT_CBS_CFS:
  1462. dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
  1463. break;
  1464. }
  1465. ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
  1466. dai_fmt);
  1467. if (ret != 0 && ret != -ENOTSUPP)
  1468. dev_warn(card->rtd[i].cpu_dai->dev,
  1469. "ASoC: Failed to set DAI format: %d\n",
  1470. ret);
  1471. }
  1472. }
  1473. snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
  1474. "%s", card->name);
  1475. snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
  1476. "%s", card->long_name ? card->long_name : card->name);
  1477. snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
  1478. "%s", card->driver_name ? card->driver_name : card->name);
  1479. for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
  1480. switch (card->snd_card->driver[i]) {
  1481. case '_':
  1482. case '-':
  1483. case '\0':
  1484. break;
  1485. default:
  1486. if (!isalnum(card->snd_card->driver[i]))
  1487. card->snd_card->driver[i] = '_';
  1488. break;
  1489. }
  1490. }
  1491. if (card->late_probe) {
  1492. ret = card->late_probe(card);
  1493. if (ret < 0) {
  1494. dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n",
  1495. card->name, ret);
  1496. goto probe_aux_dev_err;
  1497. }
  1498. }
  1499. snd_soc_dapm_new_widgets(&card->dapm);
  1500. if (card->fully_routed)
  1501. list_for_each_entry(codec, &card->codec_dev_list, card_list)
  1502. snd_soc_dapm_auto_nc_codec_pins(codec);
  1503. ret = snd_card_register(card->snd_card);
  1504. if (ret < 0) {
  1505. dev_err(card->dev, "ASoC: failed to register soundcard %d\n",
  1506. ret);
  1507. goto probe_aux_dev_err;
  1508. }
  1509. #ifdef CONFIG_SND_SOC_AC97_BUS
  1510. /* register any AC97 codecs */
  1511. for (i = 0; i < card->num_rtd; i++) {
  1512. ret = soc_register_ac97_dai_link(&card->rtd[i]);
  1513. if (ret < 0) {
  1514. dev_err(card->dev, "ASoC: failed to register AC97:"
  1515. " %d\n", ret);
  1516. while (--i >= 0)
  1517. soc_unregister_ac97_dai_link(card->rtd[i].codec);
  1518. goto probe_aux_dev_err;
  1519. }
  1520. }
  1521. #endif
  1522. card->instantiated = 1;
  1523. snd_soc_dapm_sync(&card->dapm);
  1524. mutex_unlock(&card->mutex);
  1525. return 0;
  1526. probe_aux_dev_err:
  1527. for (i = 0; i < card->num_aux_devs; i++)
  1528. soc_remove_aux_dev(card, i);
  1529. probe_dai_err:
  1530. soc_remove_dai_links(card);
  1531. card_probe_error:
  1532. if (card->remove)
  1533. card->remove(card);
  1534. snd_card_free(card->snd_card);
  1535. base_error:
  1536. mutex_unlock(&card->mutex);
  1537. return ret;
  1538. }
  1539. /* probes a new socdev */
  1540. static int soc_probe(struct platform_device *pdev)
  1541. {
  1542. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1543. /*
  1544. * no card, so machine driver should be registering card
  1545. * we should not be here in that case so ret error
  1546. */
  1547. if (!card)
  1548. return -EINVAL;
  1549. dev_warn(&pdev->dev,
  1550. "ASoC: machine %s should use snd_soc_register_card()\n",
  1551. card->name);
  1552. /* Bodge while we unpick instantiation */
  1553. card->dev = &pdev->dev;
  1554. return snd_soc_register_card(card);
  1555. }
  1556. static int soc_cleanup_card_resources(struct snd_soc_card *card)
  1557. {
  1558. int i;
  1559. /* make sure any delayed work runs */
  1560. for (i = 0; i < card->num_rtd; i++) {
  1561. struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
  1562. flush_delayed_work(&rtd->delayed_work);
  1563. }
  1564. /* remove auxiliary devices */
  1565. for (i = 0; i < card->num_aux_devs; i++)
  1566. soc_remove_aux_dev(card, i);
  1567. /* remove and free each DAI */
  1568. soc_remove_dai_links(card);
  1569. soc_cleanup_card_debugfs(card);
  1570. /* remove the card */
  1571. if (card->remove)
  1572. card->remove(card);
  1573. snd_soc_dapm_free(&card->dapm);
  1574. snd_card_free(card->snd_card);
  1575. return 0;
  1576. }
  1577. /* removes a socdev */
  1578. static int soc_remove(struct platform_device *pdev)
  1579. {
  1580. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1581. snd_soc_unregister_card(card);
  1582. return 0;
  1583. }
  1584. int snd_soc_poweroff(struct device *dev)
  1585. {
  1586. struct snd_soc_card *card = dev_get_drvdata(dev);
  1587. int i;
  1588. if (!card->instantiated)
  1589. return 0;
  1590. /* Flush out pmdown_time work - we actually do want to run it
  1591. * now, we're shutting down so no imminent restart. */
  1592. for (i = 0; i < card->num_rtd; i++) {
  1593. struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
  1594. flush_delayed_work(&rtd->delayed_work);
  1595. }
  1596. snd_soc_dapm_shutdown(card);
  1597. return 0;
  1598. }
  1599. EXPORT_SYMBOL_GPL(snd_soc_poweroff);
  1600. const struct dev_pm_ops snd_soc_pm_ops = {
  1601. .suspend = snd_soc_suspend,
  1602. .resume = snd_soc_resume,
  1603. .freeze = snd_soc_suspend,
  1604. .thaw = snd_soc_resume,
  1605. .poweroff = snd_soc_poweroff,
  1606. .restore = snd_soc_resume,
  1607. };
  1608. EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
  1609. /* ASoC platform driver */
  1610. static struct platform_driver soc_driver = {
  1611. .driver = {
  1612. .name = "soc-audio",
  1613. .owner = THIS_MODULE,
  1614. .pm = &snd_soc_pm_ops,
  1615. },
  1616. .probe = soc_probe,
  1617. .remove = soc_remove,
  1618. };
  1619. /**
  1620. * snd_soc_codec_volatile_register: Report if a register is volatile.
  1621. *
  1622. * @codec: CODEC to query.
  1623. * @reg: Register to query.
  1624. *
  1625. * Boolean function indiciating if a CODEC register is volatile.
  1626. */
  1627. int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
  1628. unsigned int reg)
  1629. {
  1630. if (codec->volatile_register)
  1631. return codec->volatile_register(codec, reg);
  1632. else
  1633. return 0;
  1634. }
  1635. EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
  1636. /**
  1637. * snd_soc_codec_readable_register: Report if a register is readable.
  1638. *
  1639. * @codec: CODEC to query.
  1640. * @reg: Register to query.
  1641. *
  1642. * Boolean function indicating if a CODEC register is readable.
  1643. */
  1644. int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
  1645. unsigned int reg)
  1646. {
  1647. if (codec->readable_register)
  1648. return codec->readable_register(codec, reg);
  1649. else
  1650. return 1;
  1651. }
  1652. EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register);
  1653. /**
  1654. * snd_soc_codec_writable_register: Report if a register is writable.
  1655. *
  1656. * @codec: CODEC to query.
  1657. * @reg: Register to query.
  1658. *
  1659. * Boolean function indicating if a CODEC register is writable.
  1660. */
  1661. int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
  1662. unsigned int reg)
  1663. {
  1664. if (codec->writable_register)
  1665. return codec->writable_register(codec, reg);
  1666. else
  1667. return 1;
  1668. }
  1669. EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register);
  1670. int snd_soc_platform_read(struct snd_soc_platform *platform,
  1671. unsigned int reg)
  1672. {
  1673. unsigned int ret;
  1674. if (!platform->driver->read) {
  1675. dev_err(platform->dev, "ASoC: platform has no read back\n");
  1676. return -1;
  1677. }
  1678. ret = platform->driver->read(platform, reg);
  1679. dev_dbg(platform->dev, "read %x => %x\n", reg, ret);
  1680. trace_snd_soc_preg_read(platform, reg, ret);
  1681. return ret;
  1682. }
  1683. EXPORT_SYMBOL_GPL(snd_soc_platform_read);
  1684. int snd_soc_platform_write(struct snd_soc_platform *platform,
  1685. unsigned int reg, unsigned int val)
  1686. {
  1687. if (!platform->driver->write) {
  1688. dev_err(platform->dev, "ASoC: platform has no write back\n");
  1689. return -1;
  1690. }
  1691. dev_dbg(platform->dev, "write %x = %x\n", reg, val);
  1692. trace_snd_soc_preg_write(platform, reg, val);
  1693. return platform->driver->write(platform, reg, val);
  1694. }
  1695. EXPORT_SYMBOL_GPL(snd_soc_platform_write);
  1696. /**
  1697. * snd_soc_new_ac97_codec - initailise AC97 device
  1698. * @codec: audio codec
  1699. * @ops: AC97 bus operations
  1700. * @num: AC97 codec number
  1701. *
  1702. * Initialises AC97 codec resources for use by ad-hoc devices only.
  1703. */
  1704. int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
  1705. struct snd_ac97_bus_ops *ops, int num)
  1706. {
  1707. mutex_lock(&codec->mutex);
  1708. codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
  1709. if (codec->ac97 == NULL) {
  1710. mutex_unlock(&codec->mutex);
  1711. return -ENOMEM;
  1712. }
  1713. codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
  1714. if (codec->ac97->bus == NULL) {
  1715. kfree(codec->ac97);
  1716. codec->ac97 = NULL;
  1717. mutex_unlock(&codec->mutex);
  1718. return -ENOMEM;
  1719. }
  1720. codec->ac97->bus->ops = ops;
  1721. codec->ac97->num = num;
  1722. /*
  1723. * Mark the AC97 device to be created by us. This way we ensure that the
  1724. * device will be registered with the device subsystem later on.
  1725. */
  1726. codec->ac97_created = 1;
  1727. mutex_unlock(&codec->mutex);
  1728. return 0;
  1729. }
  1730. EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
  1731. /**
  1732. * snd_soc_free_ac97_codec - free AC97 codec device
  1733. * @codec: audio codec
  1734. *
  1735. * Frees AC97 codec device resources.
  1736. */
  1737. void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
  1738. {
  1739. mutex_lock(&codec->mutex);
  1740. #ifdef CONFIG_SND_SOC_AC97_BUS
  1741. soc_unregister_ac97_dai_link(codec);
  1742. #endif
  1743. kfree(codec->ac97->bus);
  1744. kfree(codec->ac97);
  1745. codec->ac97 = NULL;
  1746. codec->ac97_created = 0;
  1747. mutex_unlock(&codec->mutex);
  1748. }
  1749. EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
  1750. unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
  1751. {
  1752. unsigned int ret;
  1753. ret = codec->read(codec, reg);
  1754. dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
  1755. trace_snd_soc_reg_read(codec, reg, ret);
  1756. return ret;
  1757. }
  1758. EXPORT_SYMBOL_GPL(snd_soc_read);
  1759. unsigned int snd_soc_write(struct snd_soc_codec *codec,
  1760. unsigned int reg, unsigned int val)
  1761. {
  1762. dev_dbg(codec->dev, "write %x = %x\n", reg, val);
  1763. trace_snd_soc_reg_write(codec, reg, val);
  1764. return codec->write(codec, reg, val);
  1765. }
  1766. EXPORT_SYMBOL_GPL(snd_soc_write);
  1767. unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
  1768. unsigned int reg, const void *data, size_t len)
  1769. {
  1770. return codec->bulk_write_raw(codec, reg, data, len);
  1771. }
  1772. EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw);
  1773. /**
  1774. * snd_soc_update_bits - update codec register bits
  1775. * @codec: audio codec
  1776. * @reg: codec register
  1777. * @mask: register mask
  1778. * @value: new value
  1779. *
  1780. * Writes new register value.
  1781. *
  1782. * Returns 1 for change, 0 for no change, or negative error code.
  1783. */
  1784. int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
  1785. unsigned int mask, unsigned int value)
  1786. {
  1787. bool change;
  1788. unsigned int old, new;
  1789. int ret;
  1790. if (codec->using_regmap) {
  1791. ret = regmap_update_bits_check(codec->control_data, reg,
  1792. mask, value, &change);
  1793. } else {
  1794. ret = snd_soc_read(codec, reg);
  1795. if (ret < 0)
  1796. return ret;
  1797. old = ret;
  1798. new = (old & ~mask) | (value & mask);
  1799. change = old != new;
  1800. if (change)
  1801. ret = snd_soc_write(codec, reg, new);
  1802. }
  1803. if (ret < 0)
  1804. return ret;
  1805. return change;
  1806. }
  1807. EXPORT_SYMBOL_GPL(snd_soc_update_bits);
  1808. /**
  1809. * snd_soc_update_bits_locked - update codec register bits
  1810. * @codec: audio codec
  1811. * @reg: codec register
  1812. * @mask: register mask
  1813. * @value: new value
  1814. *
  1815. * Writes new register value, and takes the codec mutex.
  1816. *
  1817. * Returns 1 for change else 0.
  1818. */
  1819. int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
  1820. unsigned short reg, unsigned int mask,
  1821. unsigned int value)
  1822. {
  1823. int change;
  1824. mutex_lock(&codec->mutex);
  1825. change = snd_soc_update_bits(codec, reg, mask, value);
  1826. mutex_unlock(&codec->mutex);
  1827. return change;
  1828. }
  1829. EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
  1830. /**
  1831. * snd_soc_test_bits - test register for change
  1832. * @codec: audio codec
  1833. * @reg: codec register
  1834. * @mask: register mask
  1835. * @value: new value
  1836. *
  1837. * Tests a register with a new value and checks if the new value is
  1838. * different from the old value.
  1839. *
  1840. * Returns 1 for change else 0.
  1841. */
  1842. int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
  1843. unsigned int mask, unsigned int value)
  1844. {
  1845. int change;
  1846. unsigned int old, new;
  1847. old = snd_soc_read(codec, reg);
  1848. new = (old & ~mask) | value;
  1849. change = old != new;
  1850. return change;
  1851. }
  1852. EXPORT_SYMBOL_GPL(snd_soc_test_bits);
  1853. /**
  1854. * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
  1855. * @substream: the pcm substream
  1856. * @hw: the hardware parameters
  1857. *
  1858. * Sets the substream runtime hardware parameters.
  1859. */
  1860. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  1861. const struct snd_pcm_hardware *hw)
  1862. {
  1863. struct snd_pcm_runtime *runtime = substream->runtime;
  1864. runtime->hw.info = hw->info;
  1865. runtime->hw.formats = hw->formats;
  1866. runtime->hw.period_bytes_min = hw->period_bytes_min;
  1867. runtime->hw.period_bytes_max = hw->period_bytes_max;
  1868. runtime->hw.periods_min = hw->periods_min;
  1869. runtime->hw.periods_max = hw->periods_max;
  1870. runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
  1871. runtime->hw.fifo_size = hw->fifo_size;
  1872. return 0;
  1873. }
  1874. EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
  1875. /**
  1876. * snd_soc_cnew - create new control
  1877. * @_template: control template
  1878. * @data: control private data
  1879. * @long_name: control long name
  1880. * @prefix: control name prefix
  1881. *
  1882. * Create a new mixer control from a template control.
  1883. *
  1884. * Returns 0 for success, else error.
  1885. */
  1886. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  1887. void *data, const char *long_name,
  1888. const char *prefix)
  1889. {
  1890. struct snd_kcontrol_new template;
  1891. struct snd_kcontrol *kcontrol;
  1892. char *name = NULL;
  1893. int name_len;
  1894. memcpy(&template, _template, sizeof(template));
  1895. template.index = 0;
  1896. if (!long_name)
  1897. long_name = template.name;
  1898. if (prefix) {
  1899. name_len = strlen(long_name) + strlen(prefix) + 2;
  1900. name = kmalloc(name_len, GFP_KERNEL);
  1901. if (!name)
  1902. return NULL;
  1903. snprintf(name, name_len, "%s %s", prefix, long_name);
  1904. template.name = name;
  1905. } else {
  1906. template.name = long_name;
  1907. }
  1908. kcontrol = snd_ctl_new1(&template, data);
  1909. kfree(name);
  1910. return kcontrol;
  1911. }
  1912. EXPORT_SYMBOL_GPL(snd_soc_cnew);
  1913. static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
  1914. const struct snd_kcontrol_new *controls, int num_controls,
  1915. const char *prefix, void *data)
  1916. {
  1917. int err, i;
  1918. for (i = 0; i < num_controls; i++) {
  1919. const struct snd_kcontrol_new *control = &controls[i];
  1920. err = snd_ctl_add(card, snd_soc_cnew(control, data,
  1921. control->name, prefix));
  1922. if (err < 0) {
  1923. dev_err(dev, "ASoC: Failed to add %s: %d\n",
  1924. control->name, err);
  1925. return err;
  1926. }
  1927. }
  1928. return 0;
  1929. }
  1930. /**
  1931. * snd_soc_add_codec_controls - add an array of controls to a codec.
  1932. * Convenience function to add a list of controls. Many codecs were
  1933. * duplicating this code.
  1934. *
  1935. * @codec: codec to add controls to
  1936. * @controls: array of controls to add
  1937. * @num_controls: number of elements in the array
  1938. *
  1939. * Return 0 for success, else error.
  1940. */
  1941. int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
  1942. const struct snd_kcontrol_new *controls, int num_controls)
  1943. {
  1944. struct snd_card *card = codec->card->snd_card;
  1945. return snd_soc_add_controls(card, codec->dev, controls, num_controls,
  1946. codec->name_prefix, codec);
  1947. }
  1948. EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls);
  1949. /**
  1950. * snd_soc_add_platform_controls - add an array of controls to a platform.
  1951. * Convenience function to add a list of controls.
  1952. *
  1953. * @platform: platform to add controls to
  1954. * @controls: array of controls to add
  1955. * @num_controls: number of elements in the array
  1956. *
  1957. * Return 0 for success, else error.
  1958. */
  1959. int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
  1960. const struct snd_kcontrol_new *controls, int num_controls)
  1961. {
  1962. struct snd_card *card = platform->card->snd_card;
  1963. return snd_soc_add_controls(card, platform->dev, controls, num_controls,
  1964. NULL, platform);
  1965. }
  1966. EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
  1967. /**
  1968. * snd_soc_add_card_controls - add an array of controls to a SoC card.
  1969. * Convenience function to add a list of controls.
  1970. *
  1971. * @soc_card: SoC card to add controls to
  1972. * @controls: array of controls to add
  1973. * @num_controls: number of elements in the array
  1974. *
  1975. * Return 0 for success, else error.
  1976. */
  1977. int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
  1978. const struct snd_kcontrol_new *controls, int num_controls)
  1979. {
  1980. struct snd_card *card = soc_card->snd_card;
  1981. return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
  1982. NULL, soc_card);
  1983. }
  1984. EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
  1985. /**
  1986. * snd_soc_add_dai_controls - add an array of controls to a DAI.
  1987. * Convienience function to add a list of controls.
  1988. *
  1989. * @dai: DAI to add controls to
  1990. * @controls: array of controls to add
  1991. * @num_controls: number of elements in the array
  1992. *
  1993. * Return 0 for success, else error.
  1994. */
  1995. int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
  1996. const struct snd_kcontrol_new *controls, int num_controls)
  1997. {
  1998. struct snd_card *card = dai->card->snd_card;
  1999. return snd_soc_add_controls(card, dai->dev, controls, num_controls,
  2000. NULL, dai);
  2001. }
  2002. EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
  2003. /**
  2004. * snd_soc_info_enum_double - enumerated double mixer info callback
  2005. * @kcontrol: mixer control
  2006. * @uinfo: control element information
  2007. *
  2008. * Callback to provide information about a double enumerated
  2009. * mixer control.
  2010. *
  2011. * Returns 0 for success.
  2012. */
  2013. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  2014. struct snd_ctl_elem_info *uinfo)
  2015. {
  2016. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2017. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2018. uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
  2019. uinfo->value.enumerated.items = e->max;
  2020. if (uinfo->value.enumerated.item > e->max - 1)
  2021. uinfo->value.enumerated.item = e->max - 1;
  2022. strcpy(uinfo->value.enumerated.name,
  2023. e->texts[uinfo->value.enumerated.item]);
  2024. return 0;
  2025. }
  2026. EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
  2027. /**
  2028. * snd_soc_get_enum_double - enumerated double mixer get callback
  2029. * @kcontrol: mixer control
  2030. * @ucontrol: control element information
  2031. *
  2032. * Callback to get the value of a double enumerated mixer.
  2033. *
  2034. * Returns 0 for success.
  2035. */
  2036. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  2037. struct snd_ctl_elem_value *ucontrol)
  2038. {
  2039. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2040. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2041. unsigned int val;
  2042. val = snd_soc_read(codec, e->reg);
  2043. ucontrol->value.enumerated.item[0]
  2044. = (val >> e->shift_l) & e->mask;
  2045. if (e->shift_l != e->shift_r)
  2046. ucontrol->value.enumerated.item[1] =
  2047. (val >> e->shift_r) & e->mask;
  2048. return 0;
  2049. }
  2050. EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
  2051. /**
  2052. * snd_soc_put_enum_double - enumerated double mixer put callback
  2053. * @kcontrol: mixer control
  2054. * @ucontrol: control element information
  2055. *
  2056. * Callback to set the value of a double enumerated mixer.
  2057. *
  2058. * Returns 0 for success.
  2059. */
  2060. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  2061. struct snd_ctl_elem_value *ucontrol)
  2062. {
  2063. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2064. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2065. unsigned int val;
  2066. unsigned int mask;
  2067. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  2068. return -EINVAL;
  2069. val = ucontrol->value.enumerated.item[0] << e->shift_l;
  2070. mask = e->mask << e->shift_l;
  2071. if (e->shift_l != e->shift_r) {
  2072. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  2073. return -EINVAL;
  2074. val |= ucontrol->value.enumerated.item[1] << e->shift_r;
  2075. mask |= e->mask << e->shift_r;
  2076. }
  2077. return snd_soc_update_bits_locked(codec, e->reg, mask, val);
  2078. }
  2079. EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
  2080. /**
  2081. * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
  2082. * @kcontrol: mixer control
  2083. * @ucontrol: control element information
  2084. *
  2085. * Callback to get the value of a double semi enumerated mixer.
  2086. *
  2087. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  2088. * used for handling bitfield coded enumeration for example.
  2089. *
  2090. * Returns 0 for success.
  2091. */
  2092. int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
  2093. struct snd_ctl_elem_value *ucontrol)
  2094. {
  2095. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2096. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2097. unsigned int reg_val, val, mux;
  2098. reg_val = snd_soc_read(codec, e->reg);
  2099. val = (reg_val >> e->shift_l) & e->mask;
  2100. for (mux = 0; mux < e->max; mux++) {
  2101. if (val == e->values[mux])
  2102. break;
  2103. }
  2104. ucontrol->value.enumerated.item[0] = mux;
  2105. if (e->shift_l != e->shift_r) {
  2106. val = (reg_val >> e->shift_r) & e->mask;
  2107. for (mux = 0; mux < e->max; mux++) {
  2108. if (val == e->values[mux])
  2109. break;
  2110. }
  2111. ucontrol->value.enumerated.item[1] = mux;
  2112. }
  2113. return 0;
  2114. }
  2115. EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
  2116. /**
  2117. * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
  2118. * @kcontrol: mixer control
  2119. * @ucontrol: control element information
  2120. *
  2121. * Callback to set the value of a double semi enumerated mixer.
  2122. *
  2123. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  2124. * used for handling bitfield coded enumeration for example.
  2125. *
  2126. * Returns 0 for success.
  2127. */
  2128. int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
  2129. struct snd_ctl_elem_value *ucontrol)
  2130. {
  2131. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2132. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2133. unsigned int val;
  2134. unsigned int mask;
  2135. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  2136. return -EINVAL;
  2137. val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
  2138. mask = e->mask << e->shift_l;
  2139. if (e->shift_l != e->shift_r) {
  2140. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  2141. return -EINVAL;
  2142. val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
  2143. mask |= e->mask << e->shift_r;
  2144. }
  2145. return snd_soc_update_bits_locked(codec, e->reg, mask, val);
  2146. }
  2147. EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
  2148. /**
  2149. * snd_soc_info_enum_ext - external enumerated single mixer info callback
  2150. * @kcontrol: mixer control
  2151. * @uinfo: control element information
  2152. *
  2153. * Callback to provide information about an external enumerated
  2154. * single mixer.
  2155. *
  2156. * Returns 0 for success.
  2157. */
  2158. int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
  2159. struct snd_ctl_elem_info *uinfo)
  2160. {
  2161. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2162. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2163. uinfo->count = 1;
  2164. uinfo->value.enumerated.items = e->max;
  2165. if (uinfo->value.enumerated.item > e->max - 1)
  2166. uinfo->value.enumerated.item = e->max - 1;
  2167. strcpy(uinfo->value.enumerated.name,
  2168. e->texts[uinfo->value.enumerated.item]);
  2169. return 0;
  2170. }
  2171. EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
  2172. /**
  2173. * snd_soc_info_volsw_ext - external single mixer info callback
  2174. * @kcontrol: mixer control
  2175. * @uinfo: control element information
  2176. *
  2177. * Callback to provide information about a single external mixer control.
  2178. *
  2179. * Returns 0 for success.
  2180. */
  2181. int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
  2182. struct snd_ctl_elem_info *uinfo)
  2183. {
  2184. int max = kcontrol->private_value;
  2185. if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
  2186. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2187. else
  2188. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2189. uinfo->count = 1;
  2190. uinfo->value.integer.min = 0;
  2191. uinfo->value.integer.max = max;
  2192. return 0;
  2193. }
  2194. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
  2195. /**
  2196. * snd_soc_info_volsw - single mixer info callback
  2197. * @kcontrol: mixer control
  2198. * @uinfo: control element information
  2199. *
  2200. * Callback to provide information about a single mixer control, or a double
  2201. * mixer control that spans 2 registers.
  2202. *
  2203. * Returns 0 for success.
  2204. */
  2205. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  2206. struct snd_ctl_elem_info *uinfo)
  2207. {
  2208. struct soc_mixer_control *mc =
  2209. (struct soc_mixer_control *)kcontrol->private_value;
  2210. int platform_max;
  2211. if (!mc->platform_max)
  2212. mc->platform_max = mc->max;
  2213. platform_max = mc->platform_max;
  2214. if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
  2215. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2216. else
  2217. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2218. uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
  2219. uinfo->value.integer.min = 0;
  2220. uinfo->value.integer.max = platform_max;
  2221. return 0;
  2222. }
  2223. EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
  2224. /**
  2225. * snd_soc_get_volsw - single mixer get callback
  2226. * @kcontrol: mixer control
  2227. * @ucontrol: control element information
  2228. *
  2229. * Callback to get the value of a single mixer control, or a double mixer
  2230. * control that spans 2 registers.
  2231. *
  2232. * Returns 0 for success.
  2233. */
  2234. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  2235. struct snd_ctl_elem_value *ucontrol)
  2236. {
  2237. struct soc_mixer_control *mc =
  2238. (struct soc_mixer_control *)kcontrol->private_value;
  2239. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2240. unsigned int reg = mc->reg;
  2241. unsigned int reg2 = mc->rreg;
  2242. unsigned int shift = mc->shift;
  2243. unsigned int rshift = mc->rshift;
  2244. int max = mc->max;
  2245. unsigned int mask = (1 << fls(max)) - 1;
  2246. unsigned int invert = mc->invert;
  2247. ucontrol->value.integer.value[0] =
  2248. (snd_soc_read(codec, reg) >> shift) & mask;
  2249. if (invert)
  2250. ucontrol->value.integer.value[0] =
  2251. max - ucontrol->value.integer.value[0];
  2252. if (snd_soc_volsw_is_stereo(mc)) {
  2253. if (reg == reg2)
  2254. ucontrol->value.integer.value[1] =
  2255. (snd_soc_read(codec, reg) >> rshift) & mask;
  2256. else
  2257. ucontrol->value.integer.value[1] =
  2258. (snd_soc_read(codec, reg2) >> shift) & mask;
  2259. if (invert)
  2260. ucontrol->value.integer.value[1] =
  2261. max - ucontrol->value.integer.value[1];
  2262. }
  2263. return 0;
  2264. }
  2265. EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
  2266. /**
  2267. * snd_soc_put_volsw - single mixer put callback
  2268. * @kcontrol: mixer control
  2269. * @ucontrol: control element information
  2270. *
  2271. * Callback to set the value of a single mixer control, or a double mixer
  2272. * control that spans 2 registers.
  2273. *
  2274. * Returns 0 for success.
  2275. */
  2276. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  2277. struct snd_ctl_elem_value *ucontrol)
  2278. {
  2279. struct soc_mixer_control *mc =
  2280. (struct soc_mixer_control *)kcontrol->private_value;
  2281. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2282. unsigned int reg = mc->reg;
  2283. unsigned int reg2 = mc->rreg;
  2284. unsigned int shift = mc->shift;
  2285. unsigned int rshift = mc->rshift;
  2286. int max = mc->max;
  2287. unsigned int mask = (1 << fls(max)) - 1;
  2288. unsigned int invert = mc->invert;
  2289. int err;
  2290. bool type_2r = 0;
  2291. unsigned int val2 = 0;
  2292. unsigned int val, val_mask;
  2293. val = (ucontrol->value.integer.value[0] & mask);
  2294. if (invert)
  2295. val = max - val;
  2296. val_mask = mask << shift;
  2297. val = val << shift;
  2298. if (snd_soc_volsw_is_stereo(mc)) {
  2299. val2 = (ucontrol->value.integer.value[1] & mask);
  2300. if (invert)
  2301. val2 = max - val2;
  2302. if (reg == reg2) {
  2303. val_mask |= mask << rshift;
  2304. val |= val2 << rshift;
  2305. } else {
  2306. val2 = val2 << shift;
  2307. type_2r = 1;
  2308. }
  2309. }
  2310. err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
  2311. if (err < 0)
  2312. return err;
  2313. if (type_2r)
  2314. err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
  2315. return err;
  2316. }
  2317. EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
  2318. /**
  2319. * snd_soc_get_volsw_sx - single mixer get callback
  2320. * @kcontrol: mixer control
  2321. * @ucontrol: control element information
  2322. *
  2323. * Callback to get the value of a single mixer control, or a double mixer
  2324. * control that spans 2 registers.
  2325. *
  2326. * Returns 0 for success.
  2327. */
  2328. int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
  2329. struct snd_ctl_elem_value *ucontrol)
  2330. {
  2331. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2332. struct soc_mixer_control *mc =
  2333. (struct soc_mixer_control *)kcontrol->private_value;
  2334. unsigned int reg = mc->reg;
  2335. unsigned int reg2 = mc->rreg;
  2336. unsigned int shift = mc->shift;
  2337. unsigned int rshift = mc->rshift;
  2338. int max = mc->max;
  2339. int min = mc->min;
  2340. int mask = (1 << (fls(min + max) - 1)) - 1;
  2341. ucontrol->value.integer.value[0] =
  2342. ((snd_soc_read(codec, reg) >> shift) - min) & mask;
  2343. if (snd_soc_volsw_is_stereo(mc))
  2344. ucontrol->value.integer.value[1] =
  2345. ((snd_soc_read(codec, reg2) >> rshift) - min) & mask;
  2346. return 0;
  2347. }
  2348. EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx);
  2349. /**
  2350. * snd_soc_put_volsw_sx - double mixer set callback
  2351. * @kcontrol: mixer control
  2352. * @uinfo: control element information
  2353. *
  2354. * Callback to set the value of a double mixer control that spans 2 registers.
  2355. *
  2356. * Returns 0 for success.
  2357. */
  2358. int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
  2359. struct snd_ctl_elem_value *ucontrol)
  2360. {
  2361. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2362. struct soc_mixer_control *mc =
  2363. (struct soc_mixer_control *)kcontrol->private_value;
  2364. unsigned int reg = mc->reg;
  2365. unsigned int reg2 = mc->rreg;
  2366. unsigned int shift = mc->shift;
  2367. unsigned int rshift = mc->rshift;
  2368. int max = mc->max;
  2369. int min = mc->min;
  2370. int mask = (1 << (fls(min + max) - 1)) - 1;
  2371. int err = 0;
  2372. unsigned short val, val_mask, val2 = 0;
  2373. val_mask = mask << shift;
  2374. val = (ucontrol->value.integer.value[0] + min) & mask;
  2375. val = val << shift;
  2376. err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
  2377. if (err < 0)
  2378. return err;
  2379. if (snd_soc_volsw_is_stereo(mc)) {
  2380. val_mask = mask << rshift;
  2381. val2 = (ucontrol->value.integer.value[1] + min) & mask;
  2382. val2 = val2 << rshift;
  2383. if (snd_soc_update_bits_locked(codec, reg2, val_mask, val2))
  2384. return err;
  2385. }
  2386. return 0;
  2387. }
  2388. EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);
  2389. /**
  2390. * snd_soc_info_volsw_s8 - signed mixer info callback
  2391. * @kcontrol: mixer control
  2392. * @uinfo: control element information
  2393. *
  2394. * Callback to provide information about a signed mixer control.
  2395. *
  2396. * Returns 0 for success.
  2397. */
  2398. int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
  2399. struct snd_ctl_elem_info *uinfo)
  2400. {
  2401. struct soc_mixer_control *mc =
  2402. (struct soc_mixer_control *)kcontrol->private_value;
  2403. int platform_max;
  2404. int min = mc->min;
  2405. if (!mc->platform_max)
  2406. mc->platform_max = mc->max;
  2407. platform_max = mc->platform_max;
  2408. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2409. uinfo->count = 2;
  2410. uinfo->value.integer.min = 0;
  2411. uinfo->value.integer.max = platform_max - min;
  2412. return 0;
  2413. }
  2414. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
  2415. /**
  2416. * snd_soc_get_volsw_s8 - signed mixer get callback
  2417. * @kcontrol: mixer control
  2418. * @ucontrol: control element information
  2419. *
  2420. * Callback to get the value of a signed mixer control.
  2421. *
  2422. * Returns 0 for success.
  2423. */
  2424. int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
  2425. struct snd_ctl_elem_value *ucontrol)
  2426. {
  2427. struct soc_mixer_control *mc =
  2428. (struct soc_mixer_control *)kcontrol->private_value;
  2429. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2430. unsigned int reg = mc->reg;
  2431. int min = mc->min;
  2432. int val = snd_soc_read(codec, reg);
  2433. ucontrol->value.integer.value[0] =
  2434. ((signed char)(val & 0xff))-min;
  2435. ucontrol->value.integer.value[1] =
  2436. ((signed char)((val >> 8) & 0xff))-min;
  2437. return 0;
  2438. }
  2439. EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
  2440. /**
  2441. * snd_soc_put_volsw_sgn - signed mixer put callback
  2442. * @kcontrol: mixer control
  2443. * @ucontrol: control element information
  2444. *
  2445. * Callback to set the value of a signed mixer control.
  2446. *
  2447. * Returns 0 for success.
  2448. */
  2449. int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
  2450. struct snd_ctl_elem_value *ucontrol)
  2451. {
  2452. struct soc_mixer_control *mc =
  2453. (struct soc_mixer_control *)kcontrol->private_value;
  2454. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2455. unsigned int reg = mc->reg;
  2456. int min = mc->min;
  2457. unsigned int val;
  2458. val = (ucontrol->value.integer.value[0]+min) & 0xff;
  2459. val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
  2460. return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
  2461. }
  2462. EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
  2463. /**
  2464. * snd_soc_info_volsw_range - single mixer info callback with range.
  2465. * @kcontrol: mixer control
  2466. * @uinfo: control element information
  2467. *
  2468. * Callback to provide information, within a range, about a single
  2469. * mixer control.
  2470. *
  2471. * returns 0 for success.
  2472. */
  2473. int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
  2474. struct snd_ctl_elem_info *uinfo)
  2475. {
  2476. struct soc_mixer_control *mc =
  2477. (struct soc_mixer_control *)kcontrol->private_value;
  2478. int platform_max;
  2479. int min = mc->min;
  2480. if (!mc->platform_max)
  2481. mc->platform_max = mc->max;
  2482. platform_max = mc->platform_max;
  2483. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2484. uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
  2485. uinfo->value.integer.min = 0;
  2486. uinfo->value.integer.max = platform_max - min;
  2487. return 0;
  2488. }
  2489. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range);
  2490. /**
  2491. * snd_soc_put_volsw_range - single mixer put value callback with range.
  2492. * @kcontrol: mixer control
  2493. * @ucontrol: control element information
  2494. *
  2495. * Callback to set the value, within a range, for a single mixer control.
  2496. *
  2497. * Returns 0 for success.
  2498. */
  2499. int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
  2500. struct snd_ctl_elem_value *ucontrol)
  2501. {
  2502. struct soc_mixer_control *mc =
  2503. (struct soc_mixer_control *)kcontrol->private_value;
  2504. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2505. unsigned int reg = mc->reg;
  2506. unsigned int rreg = mc->rreg;
  2507. unsigned int shift = mc->shift;
  2508. int min = mc->min;
  2509. int max = mc->max;
  2510. unsigned int mask = (1 << fls(max)) - 1;
  2511. unsigned int invert = mc->invert;
  2512. unsigned int val, val_mask;
  2513. int ret;
  2514. val = ((ucontrol->value.integer.value[0] + min) & mask);
  2515. if (invert)
  2516. val = max - val;
  2517. val_mask = mask << shift;
  2518. val = val << shift;
  2519. ret = snd_soc_update_bits_locked(codec, reg, val_mask, val);
  2520. if (ret != 0)
  2521. return ret;
  2522. if (snd_soc_volsw_is_stereo(mc)) {
  2523. val = ((ucontrol->value.integer.value[1] + min) & mask);
  2524. if (invert)
  2525. val = max - val;
  2526. val_mask = mask << shift;
  2527. val = val << shift;
  2528. ret = snd_soc_update_bits_locked(codec, rreg, val_mask, val);
  2529. }
  2530. return ret;
  2531. }
  2532. EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range);
  2533. /**
  2534. * snd_soc_get_volsw_range - single mixer get callback with range
  2535. * @kcontrol: mixer control
  2536. * @ucontrol: control element information
  2537. *
  2538. * Callback to get the value, within a range, of a single mixer control.
  2539. *
  2540. * Returns 0 for success.
  2541. */
  2542. int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
  2543. struct snd_ctl_elem_value *ucontrol)
  2544. {
  2545. struct soc_mixer_control *mc =
  2546. (struct soc_mixer_control *)kcontrol->private_value;
  2547. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2548. unsigned int reg = mc->reg;
  2549. unsigned int rreg = mc->rreg;
  2550. unsigned int shift = mc->shift;
  2551. int min = mc->min;
  2552. int max = mc->max;
  2553. unsigned int mask = (1 << fls(max)) - 1;
  2554. unsigned int invert = mc->invert;
  2555. ucontrol->value.integer.value[0] =
  2556. (snd_soc_read(codec, reg) >> shift) & mask;
  2557. if (invert)
  2558. ucontrol->value.integer.value[0] =
  2559. max - ucontrol->value.integer.value[0];
  2560. ucontrol->value.integer.value[0] =
  2561. ucontrol->value.integer.value[0] - min;
  2562. if (snd_soc_volsw_is_stereo(mc)) {
  2563. ucontrol->value.integer.value[1] =
  2564. (snd_soc_read(codec, rreg) >> shift) & mask;
  2565. if (invert)
  2566. ucontrol->value.integer.value[1] =
  2567. max - ucontrol->value.integer.value[1];
  2568. ucontrol->value.integer.value[1] =
  2569. ucontrol->value.integer.value[1] - min;
  2570. }
  2571. return 0;
  2572. }
  2573. EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);
  2574. /**
  2575. * snd_soc_limit_volume - Set new limit to an existing volume control.
  2576. *
  2577. * @codec: where to look for the control
  2578. * @name: Name of the control
  2579. * @max: new maximum limit
  2580. *
  2581. * Return 0 for success, else error.
  2582. */
  2583. int snd_soc_limit_volume(struct snd_soc_codec *codec,
  2584. const char *name, int max)
  2585. {
  2586. struct snd_card *card = codec->card->snd_card;
  2587. struct snd_kcontrol *kctl;
  2588. struct soc_mixer_control *mc;
  2589. int found = 0;
  2590. int ret = -EINVAL;
  2591. /* Sanity check for name and max */
  2592. if (unlikely(!name || max <= 0))
  2593. return -EINVAL;
  2594. list_for_each_entry(kctl, &card->controls, list) {
  2595. if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
  2596. found = 1;
  2597. break;
  2598. }
  2599. }
  2600. if (found) {
  2601. mc = (struct soc_mixer_control *)kctl->private_value;
  2602. if (max <= mc->max) {
  2603. mc->platform_max = max;
  2604. ret = 0;
  2605. }
  2606. }
  2607. return ret;
  2608. }
  2609. EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
  2610. int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
  2611. struct snd_ctl_elem_info *uinfo)
  2612. {
  2613. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2614. struct soc_bytes *params = (void *)kcontrol->private_value;
  2615. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  2616. uinfo->count = params->num_regs * codec->val_bytes;
  2617. return 0;
  2618. }
  2619. EXPORT_SYMBOL_GPL(snd_soc_bytes_info);
  2620. int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
  2621. struct snd_ctl_elem_value *ucontrol)
  2622. {
  2623. struct soc_bytes *params = (void *)kcontrol->private_value;
  2624. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2625. int ret;
  2626. if (codec->using_regmap)
  2627. ret = regmap_raw_read(codec->control_data, params->base,
  2628. ucontrol->value.bytes.data,
  2629. params->num_regs * codec->val_bytes);
  2630. else
  2631. ret = -EINVAL;
  2632. /* Hide any masked bytes to ensure consistent data reporting */
  2633. if (ret == 0 && params->mask) {
  2634. switch (codec->val_bytes) {
  2635. case 1:
  2636. ucontrol->value.bytes.data[0] &= ~params->mask;
  2637. break;
  2638. case 2:
  2639. ((u16 *)(&ucontrol->value.bytes.data))[0]
  2640. &= ~params->mask;
  2641. break;
  2642. case 4:
  2643. ((u32 *)(&ucontrol->value.bytes.data))[0]
  2644. &= ~params->mask;
  2645. break;
  2646. default:
  2647. return -EINVAL;
  2648. }
  2649. }
  2650. return ret;
  2651. }
  2652. EXPORT_SYMBOL_GPL(snd_soc_bytes_get);
  2653. int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
  2654. struct snd_ctl_elem_value *ucontrol)
  2655. {
  2656. struct soc_bytes *params = (void *)kcontrol->private_value;
  2657. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2658. int ret, len;
  2659. unsigned int val;
  2660. void *data;
  2661. if (!codec->using_regmap)
  2662. return -EINVAL;
  2663. data = ucontrol->value.bytes.data;
  2664. len = params->num_regs * codec->val_bytes;
  2665. /*
  2666. * If we've got a mask then we need to preserve the register
  2667. * bits. We shouldn't modify the incoming data so take a
  2668. * copy.
  2669. */
  2670. if (params->mask) {
  2671. ret = regmap_read(codec->control_data, params->base, &val);
  2672. if (ret != 0)
  2673. return ret;
  2674. val &= params->mask;
  2675. data = kmemdup(data, len, GFP_KERNEL);
  2676. if (!data)
  2677. return -ENOMEM;
  2678. switch (codec->val_bytes) {
  2679. case 1:
  2680. ((u8 *)data)[0] &= ~params->mask;
  2681. ((u8 *)data)[0] |= val;
  2682. break;
  2683. case 2:
  2684. ((u16 *)data)[0] &= cpu_to_be16(~params->mask);
  2685. ((u16 *)data)[0] |= cpu_to_be16(val);
  2686. break;
  2687. case 4:
  2688. ((u32 *)data)[0] &= cpu_to_be32(~params->mask);
  2689. ((u32 *)data)[0] |= cpu_to_be32(val);
  2690. break;
  2691. default:
  2692. return -EINVAL;
  2693. }
  2694. }
  2695. ret = regmap_raw_write(codec->control_data, params->base,
  2696. data, len);
  2697. if (params->mask)
  2698. kfree(data);
  2699. return ret;
  2700. }
  2701. EXPORT_SYMBOL_GPL(snd_soc_bytes_put);
  2702. /**
  2703. * snd_soc_info_xr_sx - signed multi register info callback
  2704. * @kcontrol: mreg control
  2705. * @uinfo: control element information
  2706. *
  2707. * Callback to provide information of a control that can
  2708. * span multiple codec registers which together
  2709. * forms a single signed value in a MSB/LSB manner.
  2710. *
  2711. * Returns 0 for success.
  2712. */
  2713. int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
  2714. struct snd_ctl_elem_info *uinfo)
  2715. {
  2716. struct soc_mreg_control *mc =
  2717. (struct soc_mreg_control *)kcontrol->private_value;
  2718. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2719. uinfo->count = 1;
  2720. uinfo->value.integer.min = mc->min;
  2721. uinfo->value.integer.max = mc->max;
  2722. return 0;
  2723. }
  2724. EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx);
  2725. /**
  2726. * snd_soc_get_xr_sx - signed multi register get callback
  2727. * @kcontrol: mreg control
  2728. * @ucontrol: control element information
  2729. *
  2730. * Callback to get the value of a control that can span
  2731. * multiple codec registers which together forms a single
  2732. * signed value in a MSB/LSB manner. The control supports
  2733. * specifying total no of bits used to allow for bitfields
  2734. * across the multiple codec registers.
  2735. *
  2736. * Returns 0 for success.
  2737. */
  2738. int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
  2739. struct snd_ctl_elem_value *ucontrol)
  2740. {
  2741. struct soc_mreg_control *mc =
  2742. (struct soc_mreg_control *)kcontrol->private_value;
  2743. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2744. unsigned int regbase = mc->regbase;
  2745. unsigned int regcount = mc->regcount;
  2746. unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE;
  2747. unsigned int regwmask = (1<<regwshift)-1;
  2748. unsigned int invert = mc->invert;
  2749. unsigned long mask = (1UL<<mc->nbits)-1;
  2750. long min = mc->min;
  2751. long max = mc->max;
  2752. long val = 0;
  2753. unsigned long regval;
  2754. unsigned int i;
  2755. for (i = 0; i < regcount; i++) {
  2756. regval = snd_soc_read(codec, regbase+i) & regwmask;
  2757. val |= regval << (regwshift*(regcount-i-1));
  2758. }
  2759. val &= mask;
  2760. if (min < 0 && val > max)
  2761. val |= ~mask;
  2762. if (invert)
  2763. val = max - val;
  2764. ucontrol->value.integer.value[0] = val;
  2765. return 0;
  2766. }
  2767. EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx);
  2768. /**
  2769. * snd_soc_put_xr_sx - signed multi register get callback
  2770. * @kcontrol: mreg control
  2771. * @ucontrol: control element information
  2772. *
  2773. * Callback to set the value of a control that can span
  2774. * multiple codec registers which together forms a single
  2775. * signed value in a MSB/LSB manner. The control supports
  2776. * specifying total no of bits used to allow for bitfields
  2777. * across the multiple codec registers.
  2778. *
  2779. * Returns 0 for success.
  2780. */
  2781. int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
  2782. struct snd_ctl_elem_value *ucontrol)
  2783. {
  2784. struct soc_mreg_control *mc =
  2785. (struct soc_mreg_control *)kcontrol->private_value;
  2786. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2787. unsigned int regbase = mc->regbase;
  2788. unsigned int regcount = mc->regcount;
  2789. unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE;
  2790. unsigned int regwmask = (1<<regwshift)-1;
  2791. unsigned int invert = mc->invert;
  2792. unsigned long mask = (1UL<<mc->nbits)-1;
  2793. long max = mc->max;
  2794. long val = ucontrol->value.integer.value[0];
  2795. unsigned int i, regval, regmask;
  2796. int err;
  2797. if (invert)
  2798. val = max - val;
  2799. val &= mask;
  2800. for (i = 0; i < regcount; i++) {
  2801. regval = (val >> (regwshift*(regcount-i-1))) & regwmask;
  2802. regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask;
  2803. err = snd_soc_update_bits_locked(codec, regbase+i,
  2804. regmask, regval);
  2805. if (err < 0)
  2806. return err;
  2807. }
  2808. return 0;
  2809. }
  2810. EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx);
  2811. /**
  2812. * snd_soc_get_strobe - strobe get callback
  2813. * @kcontrol: mixer control
  2814. * @ucontrol: control element information
  2815. *
  2816. * Callback get the value of a strobe mixer control.
  2817. *
  2818. * Returns 0 for success.
  2819. */
  2820. int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
  2821. struct snd_ctl_elem_value *ucontrol)
  2822. {
  2823. struct soc_mixer_control *mc =
  2824. (struct soc_mixer_control *)kcontrol->private_value;
  2825. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2826. unsigned int reg = mc->reg;
  2827. unsigned int shift = mc->shift;
  2828. unsigned int mask = 1 << shift;
  2829. unsigned int invert = mc->invert != 0;
  2830. unsigned int val = snd_soc_read(codec, reg) & mask;
  2831. if (shift != 0 && val != 0)
  2832. val = val >> shift;
  2833. ucontrol->value.enumerated.item[0] = val ^ invert;
  2834. return 0;
  2835. }
  2836. EXPORT_SYMBOL_GPL(snd_soc_get_strobe);
  2837. /**
  2838. * snd_soc_put_strobe - strobe put callback
  2839. * @kcontrol: mixer control
  2840. * @ucontrol: control element information
  2841. *
  2842. * Callback strobe a register bit to high then low (or the inverse)
  2843. * in one pass of a single mixer enum control.
  2844. *
  2845. * Returns 1 for success.
  2846. */
  2847. int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
  2848. struct snd_ctl_elem_value *ucontrol)
  2849. {
  2850. struct soc_mixer_control *mc =
  2851. (struct soc_mixer_control *)kcontrol->private_value;
  2852. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2853. unsigned int reg = mc->reg;
  2854. unsigned int shift = mc->shift;
  2855. unsigned int mask = 1 << shift;
  2856. unsigned int invert = mc->invert != 0;
  2857. unsigned int strobe = ucontrol->value.enumerated.item[0] != 0;
  2858. unsigned int val1 = (strobe ^ invert) ? mask : 0;
  2859. unsigned int val2 = (strobe ^ invert) ? 0 : mask;
  2860. int err;
  2861. err = snd_soc_update_bits_locked(codec, reg, mask, val1);
  2862. if (err < 0)
  2863. return err;
  2864. err = snd_soc_update_bits_locked(codec, reg, mask, val2);
  2865. return err;
  2866. }
  2867. EXPORT_SYMBOL_GPL(snd_soc_put_strobe);
  2868. /**
  2869. * snd_soc_dai_set_sysclk - configure DAI system or master clock.
  2870. * @dai: DAI
  2871. * @clk_id: DAI specific clock ID
  2872. * @freq: new clock frequency in Hz
  2873. * @dir: new clock direction - input/output.
  2874. *
  2875. * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
  2876. */
  2877. int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
  2878. unsigned int freq, int dir)
  2879. {
  2880. if (dai->driver && dai->driver->ops->set_sysclk)
  2881. return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
  2882. else if (dai->codec && dai->codec->driver->set_sysclk)
  2883. return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
  2884. freq, dir);
  2885. else
  2886. return -EINVAL;
  2887. }
  2888. EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
  2889. /**
  2890. * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
  2891. * @codec: CODEC
  2892. * @clk_id: DAI specific clock ID
  2893. * @source: Source for the clock
  2894. * @freq: new clock frequency in Hz
  2895. * @dir: new clock direction - input/output.
  2896. *
  2897. * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
  2898. */
  2899. int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
  2900. int source, unsigned int freq, int dir)
  2901. {
  2902. if (codec->driver->set_sysclk)
  2903. return codec->driver->set_sysclk(codec, clk_id, source,
  2904. freq, dir);
  2905. else
  2906. return -EINVAL;
  2907. }
  2908. EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
  2909. /**
  2910. * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
  2911. * @dai: DAI
  2912. * @div_id: DAI specific clock divider ID
  2913. * @div: new clock divisor.
  2914. *
  2915. * Configures the clock dividers. This is used to derive the best DAI bit and
  2916. * frame clocks from the system or master clock. It's best to set the DAI bit
  2917. * and frame clocks as low as possible to save system power.
  2918. */
  2919. int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
  2920. int div_id, int div)
  2921. {
  2922. if (dai->driver && dai->driver->ops->set_clkdiv)
  2923. return dai->driver->ops->set_clkdiv(dai, div_id, div);
  2924. else
  2925. return -EINVAL;
  2926. }
  2927. EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
  2928. /**
  2929. * snd_soc_dai_set_pll - configure DAI PLL.
  2930. * @dai: DAI
  2931. * @pll_id: DAI specific PLL ID
  2932. * @source: DAI specific source for the PLL
  2933. * @freq_in: PLL input clock frequency in Hz
  2934. * @freq_out: requested PLL output clock frequency in Hz
  2935. *
  2936. * Configures and enables PLL to generate output clock based on input clock.
  2937. */
  2938. int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
  2939. unsigned int freq_in, unsigned int freq_out)
  2940. {
  2941. if (dai->driver && dai->driver->ops->set_pll)
  2942. return dai->driver->ops->set_pll(dai, pll_id, source,
  2943. freq_in, freq_out);
  2944. else if (dai->codec && dai->codec->driver->set_pll)
  2945. return dai->codec->driver->set_pll(dai->codec, pll_id, source,
  2946. freq_in, freq_out);
  2947. else
  2948. return -EINVAL;
  2949. }
  2950. EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
  2951. /*
  2952. * snd_soc_codec_set_pll - configure codec PLL.
  2953. * @codec: CODEC
  2954. * @pll_id: DAI specific PLL ID
  2955. * @source: DAI specific source for the PLL
  2956. * @freq_in: PLL input clock frequency in Hz
  2957. * @freq_out: requested PLL output clock frequency in Hz
  2958. *
  2959. * Configures and enables PLL to generate output clock based on input clock.
  2960. */
  2961. int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
  2962. unsigned int freq_in, unsigned int freq_out)
  2963. {
  2964. if (codec->driver->set_pll)
  2965. return codec->driver->set_pll(codec, pll_id, source,
  2966. freq_in, freq_out);
  2967. else
  2968. return -EINVAL;
  2969. }
  2970. EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
  2971. /**
  2972. * snd_soc_dai_set_fmt - configure DAI hardware audio format.
  2973. * @dai: DAI
  2974. * @fmt: SND_SOC_DAIFMT_ format value.
  2975. *
  2976. * Configures the DAI hardware format and clocking.
  2977. */
  2978. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  2979. {
  2980. if (dai->driver == NULL)
  2981. return -EINVAL;
  2982. if (dai->driver->ops->set_fmt == NULL)
  2983. return -ENOTSUPP;
  2984. return dai->driver->ops->set_fmt(dai, fmt);
  2985. }
  2986. EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
  2987. /**
  2988. * snd_soc_dai_set_tdm_slot - configure DAI TDM.
  2989. * @dai: DAI
  2990. * @tx_mask: bitmask representing active TX slots.
  2991. * @rx_mask: bitmask representing active RX slots.
  2992. * @slots: Number of slots in use.
  2993. * @slot_width: Width in bits for each slot.
  2994. *
  2995. * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
  2996. * specific.
  2997. */
  2998. int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
  2999. unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
  3000. {
  3001. if (dai->driver && dai->driver->ops->set_tdm_slot)
  3002. return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
  3003. slots, slot_width);
  3004. else
  3005. return -EINVAL;
  3006. }
  3007. EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
  3008. /**
  3009. * snd_soc_dai_set_channel_map - configure DAI audio channel map
  3010. * @dai: DAI
  3011. * @tx_num: how many TX channels
  3012. * @tx_slot: pointer to an array which imply the TX slot number channel
  3013. * 0~num-1 uses
  3014. * @rx_num: how many RX channels
  3015. * @rx_slot: pointer to an array which imply the RX slot number channel
  3016. * 0~num-1 uses
  3017. *
  3018. * configure the relationship between channel number and TDM slot number.
  3019. */
  3020. int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
  3021. unsigned int tx_num, unsigned int *tx_slot,
  3022. unsigned int rx_num, unsigned int *rx_slot)
  3023. {
  3024. if (dai->driver && dai->driver->ops->set_channel_map)
  3025. return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
  3026. rx_num, rx_slot);
  3027. else
  3028. return -EINVAL;
  3029. }
  3030. EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
  3031. /**
  3032. * snd_soc_dai_set_tristate - configure DAI system or master clock.
  3033. * @dai: DAI
  3034. * @tristate: tristate enable
  3035. *
  3036. * Tristates the DAI so that others can use it.
  3037. */
  3038. int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
  3039. {
  3040. if (dai->driver && dai->driver->ops->set_tristate)
  3041. return dai->driver->ops->set_tristate(dai, tristate);
  3042. else
  3043. return -EINVAL;
  3044. }
  3045. EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
  3046. /**
  3047. * snd_soc_dai_digital_mute - configure DAI system or master clock.
  3048. * @dai: DAI
  3049. * @mute: mute enable
  3050. *
  3051. * Mutes the DAI DAC.
  3052. */
  3053. int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
  3054. {
  3055. if (dai->driver && dai->driver->ops->digital_mute)
  3056. return dai->driver->ops->digital_mute(dai, mute);
  3057. else
  3058. return -ENOTSUPP;
  3059. }
  3060. EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
  3061. /**
  3062. * snd_soc_register_card - Register a card with the ASoC core
  3063. *
  3064. * @card: Card to register
  3065. *
  3066. */
  3067. int snd_soc_register_card(struct snd_soc_card *card)
  3068. {
  3069. int i, ret;
  3070. if (!card->name || !card->dev)
  3071. return -EINVAL;
  3072. for (i = 0; i < card->num_links; i++) {
  3073. struct snd_soc_dai_link *link = &card->dai_link[i];
  3074. /*
  3075. * Codec must be specified by 1 of name or OF node,
  3076. * not both or neither.
  3077. */
  3078. if (!!link->codec_name == !!link->codec_of_node) {
  3079. dev_err(card->dev, "ASoC: Neither/both codec"
  3080. " name/of_node are set for %s\n", link->name);
  3081. return -EINVAL;
  3082. }
  3083. /* Codec DAI name must be specified */
  3084. if (!link->codec_dai_name) {
  3085. dev_err(card->dev, "ASoC: codec_dai_name not"
  3086. " set for %s\n", link->name);
  3087. return -EINVAL;
  3088. }
  3089. /*
  3090. * Platform may be specified by either name or OF node, but
  3091. * can be left unspecified, and a dummy platform will be used.
  3092. */
  3093. if (link->platform_name && link->platform_of_node) {
  3094. dev_err(card->dev, "ASoC: Both platform name/of_node"
  3095. " are set for %s\n", link->name);
  3096. return -EINVAL;
  3097. }
  3098. /*
  3099. * CPU device may be specified by either name or OF node, but
  3100. * can be left unspecified, and will be matched based on DAI
  3101. * name alone..
  3102. */
  3103. if (link->cpu_name && link->cpu_of_node) {
  3104. dev_err(card->dev, "ASoC: Neither/both "
  3105. "cpu name/of_node are set for %s\n",link->name);
  3106. return -EINVAL;
  3107. }
  3108. /*
  3109. * At least one of CPU DAI name or CPU device name/node must be
  3110. * specified
  3111. */
  3112. if (!link->cpu_dai_name &&
  3113. !(link->cpu_name || link->cpu_of_node)) {
  3114. dev_err(card->dev, "ASoC: Neither cpu_dai_name nor "
  3115. "cpu_name/of_node are set for %s\n", link->name);
  3116. return -EINVAL;
  3117. }
  3118. }
  3119. dev_set_drvdata(card->dev, card);
  3120. snd_soc_initialize_card_lists(card);
  3121. soc_init_card_debugfs(card);
  3122. card->rtd = devm_kzalloc(card->dev,
  3123. sizeof(struct snd_soc_pcm_runtime) *
  3124. (card->num_links + card->num_aux_devs),
  3125. GFP_KERNEL);
  3126. if (card->rtd == NULL)
  3127. return -ENOMEM;
  3128. card->num_rtd = 0;
  3129. card->rtd_aux = &card->rtd[card->num_links];
  3130. for (i = 0; i < card->num_links; i++)
  3131. card->rtd[i].dai_link = &card->dai_link[i];
  3132. INIT_LIST_HEAD(&card->list);
  3133. INIT_LIST_HEAD(&card->dapm_dirty);
  3134. card->instantiated = 0;
  3135. mutex_init(&card->mutex);
  3136. mutex_init(&card->dapm_mutex);
  3137. ret = snd_soc_instantiate_card(card);
  3138. if (ret != 0)
  3139. soc_cleanup_card_debugfs(card);
  3140. return ret;
  3141. }
  3142. EXPORT_SYMBOL_GPL(snd_soc_register_card);
  3143. /**
  3144. * snd_soc_unregister_card - Unregister a card with the ASoC core
  3145. *
  3146. * @card: Card to unregister
  3147. *
  3148. */
  3149. int snd_soc_unregister_card(struct snd_soc_card *card)
  3150. {
  3151. if (card->instantiated)
  3152. soc_cleanup_card_resources(card);
  3153. dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
  3154. return 0;
  3155. }
  3156. EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
  3157. /*
  3158. * Simplify DAI link configuration by removing ".-1" from device names
  3159. * and sanitizing names.
  3160. */
  3161. static char *fmt_single_name(struct device *dev, int *id)
  3162. {
  3163. char *found, name[NAME_SIZE];
  3164. int id1, id2;
  3165. if (dev_name(dev) == NULL)
  3166. return NULL;
  3167. strlcpy(name, dev_name(dev), NAME_SIZE);
  3168. /* are we a "%s.%d" name (platform and SPI components) */
  3169. found = strstr(name, dev->driver->name);
  3170. if (found) {
  3171. /* get ID */
  3172. if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
  3173. /* discard ID from name if ID == -1 */
  3174. if (*id == -1)
  3175. found[strlen(dev->driver->name)] = '\0';
  3176. }
  3177. } else {
  3178. /* I2C component devices are named "bus-addr" */
  3179. if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
  3180. char tmp[NAME_SIZE];
  3181. /* create unique ID number from I2C addr and bus */
  3182. *id = ((id1 & 0xffff) << 16) + id2;
  3183. /* sanitize component name for DAI link creation */
  3184. snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
  3185. strlcpy(name, tmp, NAME_SIZE);
  3186. } else
  3187. *id = 0;
  3188. }
  3189. return kstrdup(name, GFP_KERNEL);
  3190. }
  3191. /*
  3192. * Simplify DAI link naming for single devices with multiple DAIs by removing
  3193. * any ".-1" and using the DAI name (instead of device name).
  3194. */
  3195. static inline char *fmt_multiple_name(struct device *dev,
  3196. struct snd_soc_dai_driver *dai_drv)
  3197. {
  3198. if (dai_drv->name == NULL) {
  3199. dev_err(dev, "ASoC: error - multiple DAI %s registered with"
  3200. " no name\n", dev_name(dev));
  3201. return NULL;
  3202. }
  3203. return kstrdup(dai_drv->name, GFP_KERNEL);
  3204. }
  3205. /**
  3206. * snd_soc_register_dai - Register a DAI with the ASoC core
  3207. *
  3208. * @dai: DAI to register
  3209. */
  3210. int snd_soc_register_dai(struct device *dev,
  3211. struct snd_soc_dai_driver *dai_drv)
  3212. {
  3213. struct snd_soc_codec *codec;
  3214. struct snd_soc_dai *dai;
  3215. dev_dbg(dev, "ASoC: dai register %s\n", dev_name(dev));
  3216. dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
  3217. if (dai == NULL)
  3218. return -ENOMEM;
  3219. /* create DAI component name */
  3220. dai->name = fmt_single_name(dev, &dai->id);
  3221. if (dai->name == NULL) {
  3222. kfree(dai);
  3223. return -ENOMEM;
  3224. }
  3225. dai->dev = dev;
  3226. dai->driver = dai_drv;
  3227. dai->dapm.dev = dev;
  3228. if (!dai->driver->ops)
  3229. dai->driver->ops = &null_dai_ops;
  3230. mutex_lock(&client_mutex);
  3231. list_for_each_entry(codec, &codec_list, list) {
  3232. if (codec->dev == dev) {
  3233. dev_dbg(dev, "ASoC: Mapped DAI %s to CODEC %s\n",
  3234. dai->name, codec->name);
  3235. dai->codec = codec;
  3236. break;
  3237. }
  3238. }
  3239. if (!dai->codec)
  3240. dai->dapm.idle_bias_off = 1;
  3241. list_add(&dai->list, &dai_list);
  3242. mutex_unlock(&client_mutex);
  3243. dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
  3244. return 0;
  3245. }
  3246. EXPORT_SYMBOL_GPL(snd_soc_register_dai);
  3247. /**
  3248. * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
  3249. *
  3250. * @dai: DAI to unregister
  3251. */
  3252. void snd_soc_unregister_dai(struct device *dev)
  3253. {
  3254. struct snd_soc_dai *dai;
  3255. list_for_each_entry(dai, &dai_list, list) {
  3256. if (dev == dai->dev)
  3257. goto found;
  3258. }
  3259. return;
  3260. found:
  3261. mutex_lock(&client_mutex);
  3262. list_del(&dai->list);
  3263. mutex_unlock(&client_mutex);
  3264. dev_dbg(dev, "ASoC: Unregistered DAI '%s'\n", dai->name);
  3265. kfree(dai->name);
  3266. kfree(dai);
  3267. }
  3268. EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
  3269. /**
  3270. * snd_soc_register_dais - Register multiple DAIs with the ASoC core
  3271. *
  3272. * @dai: Array of DAIs to register
  3273. * @count: Number of DAIs
  3274. */
  3275. int snd_soc_register_dais(struct device *dev,
  3276. struct snd_soc_dai_driver *dai_drv, size_t count)
  3277. {
  3278. struct snd_soc_codec *codec;
  3279. struct snd_soc_dai *dai;
  3280. int i, ret = 0;
  3281. dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count);
  3282. for (i = 0; i < count; i++) {
  3283. dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
  3284. if (dai == NULL) {
  3285. ret = -ENOMEM;
  3286. goto err;
  3287. }
  3288. /* create DAI component name */
  3289. dai->name = fmt_multiple_name(dev, &dai_drv[i]);
  3290. if (dai->name == NULL) {
  3291. kfree(dai);
  3292. ret = -EINVAL;
  3293. goto err;
  3294. }
  3295. dai->dev = dev;
  3296. dai->driver = &dai_drv[i];
  3297. if (dai->driver->id)
  3298. dai->id = dai->driver->id;
  3299. else
  3300. dai->id = i;
  3301. dai->dapm.dev = dev;
  3302. if (!dai->driver->ops)
  3303. dai->driver->ops = &null_dai_ops;
  3304. mutex_lock(&client_mutex);
  3305. list_for_each_entry(codec, &codec_list, list) {
  3306. if (codec->dev == dev) {
  3307. dev_dbg(dev, "ASoC: Mapped DAI %s to "
  3308. "CODEC %s\n", dai->name, codec->name);
  3309. dai->codec = codec;
  3310. break;
  3311. }
  3312. }
  3313. if (!dai->codec)
  3314. dai->dapm.idle_bias_off = 1;
  3315. list_add(&dai->list, &dai_list);
  3316. mutex_unlock(&client_mutex);
  3317. dev_dbg(dai->dev, "ASoC: Registered DAI '%s'\n", dai->name);
  3318. }
  3319. return 0;
  3320. err:
  3321. for (i--; i >= 0; i--)
  3322. snd_soc_unregister_dai(dev);
  3323. return ret;
  3324. }
  3325. EXPORT_SYMBOL_GPL(snd_soc_register_dais);
  3326. /**
  3327. * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
  3328. *
  3329. * @dai: Array of DAIs to unregister
  3330. * @count: Number of DAIs
  3331. */
  3332. void snd_soc_unregister_dais(struct device *dev, size_t count)
  3333. {
  3334. int i;
  3335. for (i = 0; i < count; i++)
  3336. snd_soc_unregister_dai(dev);
  3337. }
  3338. EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
  3339. /**
  3340. * snd_soc_register_platform - Register a platform with the ASoC core
  3341. *
  3342. * @platform: platform to register
  3343. */
  3344. int snd_soc_register_platform(struct device *dev,
  3345. struct snd_soc_platform_driver *platform_drv)
  3346. {
  3347. struct snd_soc_platform *platform;
  3348. dev_dbg(dev, "ASoC: platform register %s\n", dev_name(dev));
  3349. platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
  3350. if (platform == NULL)
  3351. return -ENOMEM;
  3352. /* create platform component name */
  3353. platform->name = fmt_single_name(dev, &platform->id);
  3354. if (platform->name == NULL) {
  3355. kfree(platform);
  3356. return -ENOMEM;
  3357. }
  3358. platform->dev = dev;
  3359. platform->driver = platform_drv;
  3360. platform->dapm.dev = dev;
  3361. platform->dapm.platform = platform;
  3362. platform->dapm.stream_event = platform_drv->stream_event;
  3363. mutex_init(&platform->mutex);
  3364. mutex_lock(&client_mutex);
  3365. list_add(&platform->list, &platform_list);
  3366. mutex_unlock(&client_mutex);
  3367. dev_dbg(dev, "ASoC: Registered platform '%s'\n", platform->name);
  3368. return 0;
  3369. }
  3370. EXPORT_SYMBOL_GPL(snd_soc_register_platform);
  3371. /**
  3372. * snd_soc_unregister_platform - Unregister a platform from the ASoC core
  3373. *
  3374. * @platform: platform to unregister
  3375. */
  3376. void snd_soc_unregister_platform(struct device *dev)
  3377. {
  3378. struct snd_soc_platform *platform;
  3379. list_for_each_entry(platform, &platform_list, list) {
  3380. if (dev == platform->dev)
  3381. goto found;
  3382. }
  3383. return;
  3384. found:
  3385. mutex_lock(&client_mutex);
  3386. list_del(&platform->list);
  3387. mutex_unlock(&client_mutex);
  3388. dev_dbg(dev, "ASoC: Unregistered platform '%s'\n", platform->name);
  3389. kfree(platform->name);
  3390. kfree(platform);
  3391. }
  3392. EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
  3393. static u64 codec_format_map[] = {
  3394. SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
  3395. SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
  3396. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
  3397. SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
  3398. SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
  3399. SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
  3400. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
  3401. SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
  3402. SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
  3403. SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
  3404. SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
  3405. SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
  3406. SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
  3407. SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
  3408. SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
  3409. | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
  3410. };
  3411. /* Fix up the DAI formats for endianness: codecs don't actually see
  3412. * the endianness of the data but we're using the CPU format
  3413. * definitions which do need to include endianness so we ensure that
  3414. * codec DAIs always have both big and little endian variants set.
  3415. */
  3416. static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
  3417. {
  3418. int i;
  3419. for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
  3420. if (stream->formats & codec_format_map[i])
  3421. stream->formats |= codec_format_map[i];
  3422. }
  3423. /**
  3424. * snd_soc_register_codec - Register a codec with the ASoC core
  3425. *
  3426. * @codec: codec to register
  3427. */
  3428. int snd_soc_register_codec(struct device *dev,
  3429. const struct snd_soc_codec_driver *codec_drv,
  3430. struct snd_soc_dai_driver *dai_drv,
  3431. int num_dai)
  3432. {
  3433. size_t reg_size;
  3434. struct snd_soc_codec *codec;
  3435. int ret, i;
  3436. dev_dbg(dev, "codec register %s\n", dev_name(dev));
  3437. codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
  3438. if (codec == NULL)
  3439. return -ENOMEM;
  3440. /* create CODEC component name */
  3441. codec->name = fmt_single_name(dev, &codec->id);
  3442. if (codec->name == NULL) {
  3443. kfree(codec);
  3444. return -ENOMEM;
  3445. }
  3446. if (codec_drv->compress_type)
  3447. codec->compress_type = codec_drv->compress_type;
  3448. else
  3449. codec->compress_type = SND_SOC_FLAT_COMPRESSION;
  3450. codec->write = codec_drv->write;
  3451. codec->read = codec_drv->read;
  3452. codec->volatile_register = codec_drv->volatile_register;
  3453. codec->readable_register = codec_drv->readable_register;
  3454. codec->writable_register = codec_drv->writable_register;
  3455. codec->ignore_pmdown_time = codec_drv->ignore_pmdown_time;
  3456. codec->dapm.bias_level = SND_SOC_BIAS_OFF;
  3457. codec->dapm.dev = dev;
  3458. codec->dapm.codec = codec;
  3459. codec->dapm.seq_notifier = codec_drv->seq_notifier;
  3460. codec->dapm.stream_event = codec_drv->stream_event;
  3461. codec->dev = dev;
  3462. codec->driver = codec_drv;
  3463. codec->num_dai = num_dai;
  3464. mutex_init(&codec->mutex);
  3465. /* allocate CODEC register cache */
  3466. if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
  3467. reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
  3468. codec->reg_size = reg_size;
  3469. /* it is necessary to make a copy of the default register cache
  3470. * because in the case of using a compression type that requires
  3471. * the default register cache to be marked as the
  3472. * kernel might have freed the array by the time we initialize
  3473. * the cache.
  3474. */
  3475. if (codec_drv->reg_cache_default) {
  3476. codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
  3477. reg_size, GFP_KERNEL);
  3478. if (!codec->reg_def_copy) {
  3479. ret = -ENOMEM;
  3480. goto fail;
  3481. }
  3482. }
  3483. }
  3484. if (codec_drv->reg_access_size && codec_drv->reg_access_default) {
  3485. if (!codec->volatile_register)
  3486. codec->volatile_register = snd_soc_default_volatile_register;
  3487. if (!codec->readable_register)
  3488. codec->readable_register = snd_soc_default_readable_register;
  3489. if (!codec->writable_register)
  3490. codec->writable_register = snd_soc_default_writable_register;
  3491. }
  3492. for (i = 0; i < num_dai; i++) {
  3493. fixup_codec_formats(&dai_drv[i].playback);
  3494. fixup_codec_formats(&dai_drv[i].capture);
  3495. }
  3496. mutex_lock(&client_mutex);
  3497. list_add(&codec->list, &codec_list);
  3498. mutex_unlock(&client_mutex);
  3499. /* register any DAIs */
  3500. if (num_dai) {
  3501. ret = snd_soc_register_dais(dev, dai_drv, num_dai);
  3502. if (ret < 0)
  3503. dev_err(codec->dev, "ASoC: Failed to regster"
  3504. " DAIs: %d\n", ret);
  3505. }
  3506. dev_dbg(codec->dev, "ASoC: Registered codec '%s'\n", codec->name);
  3507. return 0;
  3508. fail:
  3509. kfree(codec->name);
  3510. kfree(codec);
  3511. return ret;
  3512. }
  3513. EXPORT_SYMBOL_GPL(snd_soc_register_codec);
  3514. /**
  3515. * snd_soc_unregister_codec - Unregister a codec from the ASoC core
  3516. *
  3517. * @codec: codec to unregister
  3518. */
  3519. void snd_soc_unregister_codec(struct device *dev)
  3520. {
  3521. struct snd_soc_codec *codec;
  3522. int i;
  3523. list_for_each_entry(codec, &codec_list, list) {
  3524. if (dev == codec->dev)
  3525. goto found;
  3526. }
  3527. return;
  3528. found:
  3529. if (codec->num_dai)
  3530. for (i = 0; i < codec->num_dai; i++)
  3531. snd_soc_unregister_dai(dev);
  3532. mutex_lock(&client_mutex);
  3533. list_del(&codec->list);
  3534. mutex_unlock(&client_mutex);
  3535. dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", codec->name);
  3536. snd_soc_cache_exit(codec);
  3537. kfree(codec->reg_def_copy);
  3538. kfree(codec->name);
  3539. kfree(codec);
  3540. }
  3541. EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
  3542. /* Retrieve a card's name from device tree */
  3543. int snd_soc_of_parse_card_name(struct snd_soc_card *card,
  3544. const char *propname)
  3545. {
  3546. struct device_node *np = card->dev->of_node;
  3547. int ret;
  3548. ret = of_property_read_string_index(np, propname, 0, &card->name);
  3549. /*
  3550. * EINVAL means the property does not exist. This is fine providing
  3551. * card->name was previously set, which is checked later in
  3552. * snd_soc_register_card.
  3553. */
  3554. if (ret < 0 && ret != -EINVAL) {
  3555. dev_err(card->dev,
  3556. "ASoC: Property '%s' could not be read: %d\n",
  3557. propname, ret);
  3558. return ret;
  3559. }
  3560. return 0;
  3561. }
  3562. EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
  3563. int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
  3564. const char *propname)
  3565. {
  3566. struct device_node *np = card->dev->of_node;
  3567. int num_routes;
  3568. struct snd_soc_dapm_route *routes;
  3569. int i, ret;
  3570. num_routes = of_property_count_strings(np, propname);
  3571. if (num_routes < 0 || num_routes & 1) {
  3572. dev_err(card->dev, "ASoC: Property '%s' does not exist or its"
  3573. " length is not even\n", propname);
  3574. return -EINVAL;
  3575. }
  3576. num_routes /= 2;
  3577. if (!num_routes) {
  3578. dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
  3579. propname);
  3580. return -EINVAL;
  3581. }
  3582. routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes),
  3583. GFP_KERNEL);
  3584. if (!routes) {
  3585. dev_err(card->dev,
  3586. "ASoC: Could not allocate DAPM route table\n");
  3587. return -EINVAL;
  3588. }
  3589. for (i = 0; i < num_routes; i++) {
  3590. ret = of_property_read_string_index(np, propname,
  3591. 2 * i, &routes[i].sink);
  3592. if (ret) {
  3593. dev_err(card->dev,
  3594. "ASoC: Property '%s' index %d could not be read: %d\n",
  3595. propname, 2 * i, ret);
  3596. kfree(routes);
  3597. return -EINVAL;
  3598. }
  3599. ret = of_property_read_string_index(np, propname,
  3600. (2 * i) + 1, &routes[i].source);
  3601. if (ret) {
  3602. dev_err(card->dev,
  3603. "ASoC: Property '%s' index %d could not be read: %d\n",
  3604. propname, (2 * i) + 1, ret);
  3605. kfree(routes);
  3606. return -EINVAL;
  3607. }
  3608. }
  3609. card->num_dapm_routes = num_routes;
  3610. card->dapm_routes = routes;
  3611. return 0;
  3612. }
  3613. EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
  3614. static int __init snd_soc_init(void)
  3615. {
  3616. #ifdef CONFIG_DEBUG_FS
  3617. snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
  3618. if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
  3619. pr_warn("ASoC: Failed to create debugfs directory\n");
  3620. snd_soc_debugfs_root = NULL;
  3621. }
  3622. if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
  3623. &codec_list_fops))
  3624. pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
  3625. if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
  3626. &dai_list_fops))
  3627. pr_warn("ASoC: Failed to create DAI list debugfs file\n");
  3628. if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
  3629. &platform_list_fops))
  3630. pr_warn("ASoC: Failed to create platform list debugfs file\n");
  3631. #endif
  3632. snd_soc_util_init();
  3633. return platform_driver_register(&soc_driver);
  3634. }
  3635. module_init(snd_soc_init);
  3636. static void __exit snd_soc_exit(void)
  3637. {
  3638. snd_soc_util_exit();
  3639. #ifdef CONFIG_DEBUG_FS
  3640. debugfs_remove_recursive(snd_soc_debugfs_root);
  3641. #endif
  3642. platform_driver_unregister(&soc_driver);
  3643. }
  3644. module_exit(snd_soc_exit);
  3645. /* Module information */
  3646. MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
  3647. MODULE_DESCRIPTION("ALSA SoC Core");
  3648. MODULE_LICENSE("GPL");
  3649. MODULE_ALIAS("platform:soc-audio");