soc-core.c 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227
  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. WARN(codec->dapm.idle_bias_off &&
  915. codec->dapm.bias_level != SND_SOC_BIAS_OFF,
  916. "codec %s can not start from non-off bias"
  917. " with idle_bias_off==1\n", codec->name);
  918. }
  919. /* If the driver didn't set I/O up try regmap */
  920. if (!codec->write && dev_get_regmap(codec->dev, NULL))
  921. snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
  922. if (driver->controls)
  923. snd_soc_add_codec_controls(codec, driver->controls,
  924. driver->num_controls);
  925. if (driver->dapm_routes)
  926. snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
  927. driver->num_dapm_routes);
  928. /* mark codec as probed and add to card codec list */
  929. codec->probed = 1;
  930. list_add(&codec->card_list, &card->codec_dev_list);
  931. list_add(&codec->dapm.list, &card->dapm_list);
  932. return 0;
  933. err_probe:
  934. soc_cleanup_codec_debugfs(codec);
  935. module_put(codec->dev->driver->owner);
  936. return ret;
  937. }
  938. static int soc_probe_platform(struct snd_soc_card *card,
  939. struct snd_soc_platform *platform)
  940. {
  941. int ret = 0;
  942. const struct snd_soc_platform_driver *driver = platform->driver;
  943. struct snd_soc_dai *dai;
  944. platform->card = card;
  945. platform->dapm.card = card;
  946. if (!try_module_get(platform->dev->driver->owner))
  947. return -ENODEV;
  948. soc_init_platform_debugfs(platform);
  949. if (driver->dapm_widgets)
  950. snd_soc_dapm_new_controls(&platform->dapm,
  951. driver->dapm_widgets, driver->num_dapm_widgets);
  952. /* Create DAPM widgets for each DAI stream */
  953. list_for_each_entry(dai, &dai_list, list) {
  954. if (dai->dev != platform->dev)
  955. continue;
  956. snd_soc_dapm_new_dai_widgets(&platform->dapm, dai);
  957. }
  958. platform->dapm.idle_bias_off = 1;
  959. if (driver->probe) {
  960. ret = driver->probe(platform);
  961. if (ret < 0) {
  962. dev_err(platform->dev,
  963. "ASoC: failed to probe platform %d\n", ret);
  964. goto err_probe;
  965. }
  966. }
  967. if (driver->controls)
  968. snd_soc_add_platform_controls(platform, driver->controls,
  969. driver->num_controls);
  970. if (driver->dapm_routes)
  971. snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes,
  972. driver->num_dapm_routes);
  973. /* mark platform as probed and add to card platform list */
  974. platform->probed = 1;
  975. list_add(&platform->card_list, &card->platform_dev_list);
  976. list_add(&platform->dapm.list, &card->dapm_list);
  977. return 0;
  978. err_probe:
  979. soc_cleanup_platform_debugfs(platform);
  980. module_put(platform->dev->driver->owner);
  981. return ret;
  982. }
  983. static void rtd_release(struct device *dev)
  984. {
  985. kfree(dev);
  986. }
  987. static int soc_post_component_init(struct snd_soc_card *card,
  988. struct snd_soc_codec *codec,
  989. int num, int dailess)
  990. {
  991. struct snd_soc_dai_link *dai_link = NULL;
  992. struct snd_soc_aux_dev *aux_dev = NULL;
  993. struct snd_soc_pcm_runtime *rtd;
  994. const char *temp, *name;
  995. int ret = 0;
  996. if (!dailess) {
  997. dai_link = &card->dai_link[num];
  998. rtd = &card->rtd[num];
  999. name = dai_link->name;
  1000. } else {
  1001. aux_dev = &card->aux_dev[num];
  1002. rtd = &card->rtd_aux[num];
  1003. name = aux_dev->name;
  1004. }
  1005. rtd->card = card;
  1006. /* Make sure all DAPM widgets are instantiated */
  1007. snd_soc_dapm_new_widgets(&codec->dapm);
  1008. /* machine controls, routes and widgets are not prefixed */
  1009. temp = codec->name_prefix;
  1010. codec->name_prefix = NULL;
  1011. /* do machine specific initialization */
  1012. if (!dailess && dai_link->init)
  1013. ret = dai_link->init(rtd);
  1014. else if (dailess && aux_dev->init)
  1015. ret = aux_dev->init(&codec->dapm);
  1016. if (ret < 0) {
  1017. dev_err(card->dev, "ASoC: failed to init %s: %d\n", name, ret);
  1018. return ret;
  1019. }
  1020. codec->name_prefix = temp;
  1021. /* register the rtd device */
  1022. rtd->codec = codec;
  1023. rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
  1024. if (!rtd->dev)
  1025. return -ENOMEM;
  1026. device_initialize(rtd->dev);
  1027. rtd->dev->parent = card->dev;
  1028. rtd->dev->release = rtd_release;
  1029. rtd->dev->init_name = name;
  1030. dev_set_drvdata(rtd->dev, rtd);
  1031. mutex_init(&rtd->pcm_mutex);
  1032. INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
  1033. INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
  1034. INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
  1035. INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
  1036. ret = device_add(rtd->dev);
  1037. if (ret < 0) {
  1038. dev_err(card->dev,
  1039. "ASoC: failed to register runtime device: %d\n", ret);
  1040. return ret;
  1041. }
  1042. rtd->dev_registered = 1;
  1043. /* add DAPM sysfs entries for this codec */
  1044. ret = snd_soc_dapm_sys_add(rtd->dev);
  1045. if (ret < 0)
  1046. dev_err(codec->dev,
  1047. "ASoC: failed to add codec dapm sysfs entries: %d\n", ret);
  1048. /* add codec sysfs entries */
  1049. ret = device_create_file(rtd->dev, &dev_attr_codec_reg);
  1050. if (ret < 0)
  1051. dev_err(codec->dev,
  1052. "ASoC: failed to add codec sysfs files: %d\n", ret);
  1053. #ifdef CONFIG_DEBUG_FS
  1054. /* add DPCM sysfs entries */
  1055. if (!dailess && !dai_link->dynamic)
  1056. goto out;
  1057. ret = soc_dpcm_debugfs_add(rtd);
  1058. if (ret < 0)
  1059. dev_err(rtd->dev, "ASoC: failed to add dpcm sysfs entries: %d\n", ret);
  1060. out:
  1061. #endif
  1062. return 0;
  1063. }
  1064. static int soc_probe_link_components(struct snd_soc_card *card, int num,
  1065. int order)
  1066. {
  1067. struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
  1068. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  1069. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  1070. struct snd_soc_platform *platform = rtd->platform;
  1071. int ret;
  1072. /* probe the CPU-side component, if it is a CODEC */
  1073. if (cpu_dai->codec &&
  1074. !cpu_dai->codec->probed &&
  1075. cpu_dai->codec->driver->probe_order == order) {
  1076. ret = soc_probe_codec(card, cpu_dai->codec);
  1077. if (ret < 0)
  1078. return ret;
  1079. }
  1080. /* probe the CODEC-side component */
  1081. if (!codec_dai->codec->probed &&
  1082. codec_dai->codec->driver->probe_order == order) {
  1083. ret = soc_probe_codec(card, codec_dai->codec);
  1084. if (ret < 0)
  1085. return ret;
  1086. }
  1087. /* probe the platform */
  1088. if (!platform->probed &&
  1089. platform->driver->probe_order == order) {
  1090. ret = soc_probe_platform(card, platform);
  1091. if (ret < 0)
  1092. return ret;
  1093. }
  1094. return 0;
  1095. }
  1096. static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
  1097. {
  1098. struct snd_soc_dai_link *dai_link = &card->dai_link[num];
  1099. struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
  1100. struct snd_soc_codec *codec = rtd->codec;
  1101. struct snd_soc_platform *platform = rtd->platform;
  1102. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  1103. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  1104. struct snd_soc_dapm_widget *play_w, *capture_w;
  1105. int ret;
  1106. dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n",
  1107. card->name, num, order);
  1108. /* config components */
  1109. cpu_dai->platform = platform;
  1110. codec_dai->card = card;
  1111. cpu_dai->card = card;
  1112. /* set default power off timeout */
  1113. rtd->pmdown_time = pmdown_time;
  1114. /* probe the cpu_dai */
  1115. if (!cpu_dai->probed &&
  1116. cpu_dai->driver->probe_order == order) {
  1117. if (!cpu_dai->codec) {
  1118. cpu_dai->dapm.card = card;
  1119. if (!try_module_get(cpu_dai->dev->driver->owner))
  1120. return -ENODEV;
  1121. list_add(&cpu_dai->dapm.list, &card->dapm_list);
  1122. snd_soc_dapm_new_dai_widgets(&cpu_dai->dapm, cpu_dai);
  1123. }
  1124. if (cpu_dai->driver->probe) {
  1125. ret = cpu_dai->driver->probe(cpu_dai);
  1126. if (ret < 0) {
  1127. dev_err(cpu_dai->dev,
  1128. "ASoC: failed to probe CPU DAI %s: %d\n",
  1129. cpu_dai->name, ret);
  1130. module_put(cpu_dai->dev->driver->owner);
  1131. return ret;
  1132. }
  1133. }
  1134. cpu_dai->probed = 1;
  1135. /* mark cpu_dai as probed and add to card dai list */
  1136. list_add(&cpu_dai->card_list, &card->dai_dev_list);
  1137. }
  1138. /* probe the CODEC DAI */
  1139. if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
  1140. if (codec_dai->driver->probe) {
  1141. ret = codec_dai->driver->probe(codec_dai);
  1142. if (ret < 0) {
  1143. dev_err(codec_dai->dev,
  1144. "ASoC: failed to probe CODEC DAI %s: %d\n",
  1145. codec_dai->name, ret);
  1146. return ret;
  1147. }
  1148. }
  1149. /* mark codec_dai as probed and add to card dai list */
  1150. codec_dai->probed = 1;
  1151. list_add(&codec_dai->card_list, &card->dai_dev_list);
  1152. }
  1153. /* complete DAI probe during last probe */
  1154. if (order != SND_SOC_COMP_ORDER_LAST)
  1155. return 0;
  1156. ret = soc_post_component_init(card, codec, num, 0);
  1157. if (ret)
  1158. return ret;
  1159. ret = device_create_file(rtd->dev, &dev_attr_pmdown_time);
  1160. if (ret < 0)
  1161. dev_warn(rtd->dev, "ASoC: failed to add pmdown_time sysfs: %d\n",
  1162. ret);
  1163. if (cpu_dai->driver->compress_dai) {
  1164. /*create compress_device"*/
  1165. ret = soc_new_compress(rtd, num);
  1166. if (ret < 0) {
  1167. dev_err(card->dev, "ASoC: can't create compress %s\n",
  1168. dai_link->stream_name);
  1169. return ret;
  1170. }
  1171. } else {
  1172. if (!dai_link->params) {
  1173. /* create the pcm */
  1174. ret = soc_new_pcm(rtd, num);
  1175. if (ret < 0) {
  1176. dev_err(card->dev, "ASoC: can't create pcm %s :%d\n",
  1177. dai_link->stream_name, ret);
  1178. return ret;
  1179. }
  1180. } else {
  1181. /* link the DAI widgets */
  1182. play_w = codec_dai->playback_widget;
  1183. capture_w = cpu_dai->capture_widget;
  1184. if (play_w && capture_w) {
  1185. ret = snd_soc_dapm_new_pcm(card, dai_link->params,
  1186. capture_w, play_w);
  1187. if (ret != 0) {
  1188. dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
  1189. play_w->name, capture_w->name, ret);
  1190. return ret;
  1191. }
  1192. }
  1193. play_w = cpu_dai->playback_widget;
  1194. capture_w = codec_dai->capture_widget;
  1195. if (play_w && capture_w) {
  1196. ret = snd_soc_dapm_new_pcm(card, dai_link->params,
  1197. capture_w, play_w);
  1198. if (ret != 0) {
  1199. dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
  1200. play_w->name, capture_w->name, ret);
  1201. return ret;
  1202. }
  1203. }
  1204. }
  1205. }
  1206. /* add platform data for AC97 devices */
  1207. if (rtd->codec_dai->driver->ac97_control)
  1208. snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
  1209. return 0;
  1210. }
  1211. #ifdef CONFIG_SND_SOC_AC97_BUS
  1212. static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
  1213. {
  1214. int ret;
  1215. /* Only instantiate AC97 if not already done by the adaptor
  1216. * for the generic AC97 subsystem.
  1217. */
  1218. if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
  1219. /*
  1220. * It is possible that the AC97 device is already registered to
  1221. * the device subsystem. This happens when the device is created
  1222. * via snd_ac97_mixer(). Currently only SoC codec that does so
  1223. * is the generic AC97 glue but others migh emerge.
  1224. *
  1225. * In those cases we don't try to register the device again.
  1226. */
  1227. if (!rtd->codec->ac97_created)
  1228. return 0;
  1229. ret = soc_ac97_dev_register(rtd->codec);
  1230. if (ret < 0) {
  1231. dev_err(rtd->codec->dev,
  1232. "ASoC: AC97 device register failed: %d\n", ret);
  1233. return ret;
  1234. }
  1235. rtd->codec->ac97_registered = 1;
  1236. }
  1237. return 0;
  1238. }
  1239. static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
  1240. {
  1241. if (codec->ac97_registered) {
  1242. soc_ac97_dev_unregister(codec);
  1243. codec->ac97_registered = 0;
  1244. }
  1245. }
  1246. #endif
  1247. static int soc_check_aux_dev(struct snd_soc_card *card, int num)
  1248. {
  1249. struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
  1250. struct snd_soc_codec *codec;
  1251. /* find CODEC from registered CODECs*/
  1252. list_for_each_entry(codec, &codec_list, list) {
  1253. if (!strcmp(codec->name, aux_dev->codec_name))
  1254. return 0;
  1255. }
  1256. dev_err(card->dev, "ASoC: %s not registered\n", aux_dev->codec_name);
  1257. return -EPROBE_DEFER;
  1258. }
  1259. static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
  1260. {
  1261. struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
  1262. struct snd_soc_codec *codec;
  1263. int ret = -ENODEV;
  1264. /* find CODEC from registered CODECs*/
  1265. list_for_each_entry(codec, &codec_list, list) {
  1266. if (!strcmp(codec->name, aux_dev->codec_name)) {
  1267. if (codec->probed) {
  1268. dev_err(codec->dev,
  1269. "ASoC: codec already probed");
  1270. ret = -EBUSY;
  1271. goto out;
  1272. }
  1273. goto found;
  1274. }
  1275. }
  1276. /* codec not found */
  1277. dev_err(card->dev, "ASoC: codec %s not found", aux_dev->codec_name);
  1278. return -EPROBE_DEFER;
  1279. found:
  1280. ret = soc_probe_codec(card, codec);
  1281. if (ret < 0)
  1282. return ret;
  1283. ret = soc_post_component_init(card, codec, num, 1);
  1284. out:
  1285. return ret;
  1286. }
  1287. static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
  1288. {
  1289. struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
  1290. struct snd_soc_codec *codec = rtd->codec;
  1291. /* unregister the rtd device */
  1292. if (rtd->dev_registered) {
  1293. device_remove_file(rtd->dev, &dev_attr_codec_reg);
  1294. device_del(rtd->dev);
  1295. rtd->dev_registered = 0;
  1296. }
  1297. if (codec && codec->probed)
  1298. soc_remove_codec(codec);
  1299. }
  1300. static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
  1301. enum snd_soc_compress_type compress_type)
  1302. {
  1303. int ret;
  1304. if (codec->cache_init)
  1305. return 0;
  1306. /* override the compress_type if necessary */
  1307. if (compress_type && codec->compress_type != compress_type)
  1308. codec->compress_type = compress_type;
  1309. ret = snd_soc_cache_init(codec);
  1310. if (ret < 0) {
  1311. dev_err(codec->dev, "ASoC: Failed to set cache compression"
  1312. " type: %d\n", ret);
  1313. return ret;
  1314. }
  1315. codec->cache_init = 1;
  1316. return 0;
  1317. }
  1318. static int snd_soc_instantiate_card(struct snd_soc_card *card)
  1319. {
  1320. struct snd_soc_codec *codec;
  1321. struct snd_soc_codec_conf *codec_conf;
  1322. enum snd_soc_compress_type compress_type;
  1323. struct snd_soc_dai_link *dai_link;
  1324. int ret, i, order, dai_fmt;
  1325. mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
  1326. /* bind DAIs */
  1327. for (i = 0; i < card->num_links; i++) {
  1328. ret = soc_bind_dai_link(card, i);
  1329. if (ret != 0)
  1330. goto base_error;
  1331. }
  1332. /* check aux_devs too */
  1333. for (i = 0; i < card->num_aux_devs; i++) {
  1334. ret = soc_check_aux_dev(card, i);
  1335. if (ret != 0)
  1336. goto base_error;
  1337. }
  1338. /* initialize the register cache for each available codec */
  1339. list_for_each_entry(codec, &codec_list, list) {
  1340. if (codec->cache_init)
  1341. continue;
  1342. /* by default we don't override the compress_type */
  1343. compress_type = 0;
  1344. /* check to see if we need to override the compress_type */
  1345. for (i = 0; i < card->num_configs; ++i) {
  1346. codec_conf = &card->codec_conf[i];
  1347. if (!strcmp(codec->name, codec_conf->dev_name)) {
  1348. compress_type = codec_conf->compress_type;
  1349. if (compress_type && compress_type
  1350. != codec->compress_type)
  1351. break;
  1352. }
  1353. }
  1354. ret = snd_soc_init_codec_cache(codec, compress_type);
  1355. if (ret < 0)
  1356. goto base_error;
  1357. }
  1358. /* card bind complete so register a sound card */
  1359. ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
  1360. card->owner, 0, &card->snd_card);
  1361. if (ret < 0) {
  1362. dev_err(card->dev, "ASoC: can't create sound card for"
  1363. " card %s: %d\n", card->name, ret);
  1364. goto base_error;
  1365. }
  1366. card->snd_card->dev = card->dev;
  1367. card->dapm.bias_level = SND_SOC_BIAS_OFF;
  1368. card->dapm.dev = card->dev;
  1369. card->dapm.card = card;
  1370. list_add(&card->dapm.list, &card->dapm_list);
  1371. #ifdef CONFIG_DEBUG_FS
  1372. snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
  1373. #endif
  1374. #ifdef CONFIG_PM_SLEEP
  1375. /* deferred resume work */
  1376. INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
  1377. #endif
  1378. if (card->dapm_widgets)
  1379. snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
  1380. card->num_dapm_widgets);
  1381. /* initialise the sound card only once */
  1382. if (card->probe) {
  1383. ret = card->probe(card);
  1384. if (ret < 0)
  1385. goto card_probe_error;
  1386. }
  1387. /* probe all components used by DAI links on this card */
  1388. for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
  1389. order++) {
  1390. for (i = 0; i < card->num_links; i++) {
  1391. ret = soc_probe_link_components(card, i, order);
  1392. if (ret < 0) {
  1393. dev_err(card->dev,
  1394. "ASoC: failed to instantiate card %d\n",
  1395. ret);
  1396. goto probe_dai_err;
  1397. }
  1398. }
  1399. }
  1400. /* probe all DAI links on this card */
  1401. for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
  1402. order++) {
  1403. for (i = 0; i < card->num_links; i++) {
  1404. ret = soc_probe_link_dais(card, i, order);
  1405. if (ret < 0) {
  1406. dev_err(card->dev,
  1407. "ASoC: failed to instantiate card %d\n",
  1408. ret);
  1409. goto probe_dai_err;
  1410. }
  1411. }
  1412. }
  1413. for (i = 0; i < card->num_aux_devs; i++) {
  1414. ret = soc_probe_aux_dev(card, i);
  1415. if (ret < 0) {
  1416. dev_err(card->dev,
  1417. "ASoC: failed to add auxiliary devices %d\n",
  1418. ret);
  1419. goto probe_aux_dev_err;
  1420. }
  1421. }
  1422. snd_soc_dapm_link_dai_widgets(card);
  1423. if (card->controls)
  1424. snd_soc_add_card_controls(card, card->controls, card->num_controls);
  1425. if (card->dapm_routes)
  1426. snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
  1427. card->num_dapm_routes);
  1428. snd_soc_dapm_new_widgets(&card->dapm);
  1429. for (i = 0; i < card->num_links; i++) {
  1430. dai_link = &card->dai_link[i];
  1431. dai_fmt = dai_link->dai_fmt;
  1432. if (dai_fmt) {
  1433. ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai,
  1434. dai_fmt);
  1435. if (ret != 0 && ret != -ENOTSUPP)
  1436. dev_warn(card->rtd[i].codec_dai->dev,
  1437. "ASoC: Failed to set DAI format: %d\n",
  1438. ret);
  1439. }
  1440. /* If this is a regular CPU link there will be a platform */
  1441. if (dai_fmt &&
  1442. (dai_link->platform_name || dai_link->platform_of_node)) {
  1443. ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
  1444. dai_fmt);
  1445. if (ret != 0 && ret != -ENOTSUPP)
  1446. dev_warn(card->rtd[i].cpu_dai->dev,
  1447. "ASoC: Failed to set DAI format: %d\n",
  1448. ret);
  1449. } else if (dai_fmt) {
  1450. /* Flip the polarity for the "CPU" end */
  1451. dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
  1452. switch (dai_link->dai_fmt &
  1453. SND_SOC_DAIFMT_MASTER_MASK) {
  1454. case SND_SOC_DAIFMT_CBM_CFM:
  1455. dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
  1456. break;
  1457. case SND_SOC_DAIFMT_CBM_CFS:
  1458. dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
  1459. break;
  1460. case SND_SOC_DAIFMT_CBS_CFM:
  1461. dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
  1462. break;
  1463. case SND_SOC_DAIFMT_CBS_CFS:
  1464. dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
  1465. break;
  1466. }
  1467. ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
  1468. dai_fmt);
  1469. if (ret != 0 && ret != -ENOTSUPP)
  1470. dev_warn(card->rtd[i].cpu_dai->dev,
  1471. "ASoC: Failed to set DAI format: %d\n",
  1472. ret);
  1473. }
  1474. }
  1475. snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
  1476. "%s", card->name);
  1477. snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
  1478. "%s", card->long_name ? card->long_name : card->name);
  1479. snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
  1480. "%s", card->driver_name ? card->driver_name : card->name);
  1481. for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
  1482. switch (card->snd_card->driver[i]) {
  1483. case '_':
  1484. case '-':
  1485. case '\0':
  1486. break;
  1487. default:
  1488. if (!isalnum(card->snd_card->driver[i]))
  1489. card->snd_card->driver[i] = '_';
  1490. break;
  1491. }
  1492. }
  1493. if (card->late_probe) {
  1494. ret = card->late_probe(card);
  1495. if (ret < 0) {
  1496. dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n",
  1497. card->name, ret);
  1498. goto probe_aux_dev_err;
  1499. }
  1500. }
  1501. snd_soc_dapm_new_widgets(&card->dapm);
  1502. if (card->fully_routed)
  1503. list_for_each_entry(codec, &card->codec_dev_list, card_list)
  1504. snd_soc_dapm_auto_nc_codec_pins(codec);
  1505. ret = snd_card_register(card->snd_card);
  1506. if (ret < 0) {
  1507. dev_err(card->dev, "ASoC: failed to register soundcard %d\n",
  1508. ret);
  1509. goto probe_aux_dev_err;
  1510. }
  1511. #ifdef CONFIG_SND_SOC_AC97_BUS
  1512. /* register any AC97 codecs */
  1513. for (i = 0; i < card->num_rtd; i++) {
  1514. ret = soc_register_ac97_dai_link(&card->rtd[i]);
  1515. if (ret < 0) {
  1516. dev_err(card->dev, "ASoC: failed to register AC97:"
  1517. " %d\n", ret);
  1518. while (--i >= 0)
  1519. soc_unregister_ac97_dai_link(card->rtd[i].codec);
  1520. goto probe_aux_dev_err;
  1521. }
  1522. }
  1523. #endif
  1524. card->instantiated = 1;
  1525. snd_soc_dapm_sync(&card->dapm);
  1526. mutex_unlock(&card->mutex);
  1527. return 0;
  1528. probe_aux_dev_err:
  1529. for (i = 0; i < card->num_aux_devs; i++)
  1530. soc_remove_aux_dev(card, i);
  1531. probe_dai_err:
  1532. soc_remove_dai_links(card);
  1533. card_probe_error:
  1534. if (card->remove)
  1535. card->remove(card);
  1536. snd_card_free(card->snd_card);
  1537. base_error:
  1538. mutex_unlock(&card->mutex);
  1539. return ret;
  1540. }
  1541. /* probes a new socdev */
  1542. static int soc_probe(struct platform_device *pdev)
  1543. {
  1544. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1545. /*
  1546. * no card, so machine driver should be registering card
  1547. * we should not be here in that case so ret error
  1548. */
  1549. if (!card)
  1550. return -EINVAL;
  1551. dev_warn(&pdev->dev,
  1552. "ASoC: machine %s should use snd_soc_register_card()\n",
  1553. card->name);
  1554. /* Bodge while we unpick instantiation */
  1555. card->dev = &pdev->dev;
  1556. return snd_soc_register_card(card);
  1557. }
  1558. static int soc_cleanup_card_resources(struct snd_soc_card *card)
  1559. {
  1560. int i;
  1561. /* make sure any delayed work runs */
  1562. for (i = 0; i < card->num_rtd; i++) {
  1563. struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
  1564. flush_delayed_work(&rtd->delayed_work);
  1565. }
  1566. /* remove auxiliary devices */
  1567. for (i = 0; i < card->num_aux_devs; i++)
  1568. soc_remove_aux_dev(card, i);
  1569. /* remove and free each DAI */
  1570. soc_remove_dai_links(card);
  1571. soc_cleanup_card_debugfs(card);
  1572. /* remove the card */
  1573. if (card->remove)
  1574. card->remove(card);
  1575. snd_soc_dapm_free(&card->dapm);
  1576. snd_card_free(card->snd_card);
  1577. return 0;
  1578. }
  1579. /* removes a socdev */
  1580. static int soc_remove(struct platform_device *pdev)
  1581. {
  1582. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1583. snd_soc_unregister_card(card);
  1584. return 0;
  1585. }
  1586. int snd_soc_poweroff(struct device *dev)
  1587. {
  1588. struct snd_soc_card *card = dev_get_drvdata(dev);
  1589. int i;
  1590. if (!card->instantiated)
  1591. return 0;
  1592. /* Flush out pmdown_time work - we actually do want to run it
  1593. * now, we're shutting down so no imminent restart. */
  1594. for (i = 0; i < card->num_rtd; i++) {
  1595. struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
  1596. flush_delayed_work(&rtd->delayed_work);
  1597. }
  1598. snd_soc_dapm_shutdown(card);
  1599. return 0;
  1600. }
  1601. EXPORT_SYMBOL_GPL(snd_soc_poweroff);
  1602. const struct dev_pm_ops snd_soc_pm_ops = {
  1603. .suspend = snd_soc_suspend,
  1604. .resume = snd_soc_resume,
  1605. .freeze = snd_soc_suspend,
  1606. .thaw = snd_soc_resume,
  1607. .poweroff = snd_soc_poweroff,
  1608. .restore = snd_soc_resume,
  1609. };
  1610. EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
  1611. /* ASoC platform driver */
  1612. static struct platform_driver soc_driver = {
  1613. .driver = {
  1614. .name = "soc-audio",
  1615. .owner = THIS_MODULE,
  1616. .pm = &snd_soc_pm_ops,
  1617. },
  1618. .probe = soc_probe,
  1619. .remove = soc_remove,
  1620. };
  1621. /**
  1622. * snd_soc_codec_volatile_register: Report if a register is volatile.
  1623. *
  1624. * @codec: CODEC to query.
  1625. * @reg: Register to query.
  1626. *
  1627. * Boolean function indiciating if a CODEC register is volatile.
  1628. */
  1629. int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
  1630. unsigned int reg)
  1631. {
  1632. if (codec->volatile_register)
  1633. return codec->volatile_register(codec, reg);
  1634. else
  1635. return 0;
  1636. }
  1637. EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
  1638. /**
  1639. * snd_soc_codec_readable_register: Report if a register is readable.
  1640. *
  1641. * @codec: CODEC to query.
  1642. * @reg: Register to query.
  1643. *
  1644. * Boolean function indicating if a CODEC register is readable.
  1645. */
  1646. int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
  1647. unsigned int reg)
  1648. {
  1649. if (codec->readable_register)
  1650. return codec->readable_register(codec, reg);
  1651. else
  1652. return 1;
  1653. }
  1654. EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register);
  1655. /**
  1656. * snd_soc_codec_writable_register: Report if a register is writable.
  1657. *
  1658. * @codec: CODEC to query.
  1659. * @reg: Register to query.
  1660. *
  1661. * Boolean function indicating if a CODEC register is writable.
  1662. */
  1663. int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
  1664. unsigned int reg)
  1665. {
  1666. if (codec->writable_register)
  1667. return codec->writable_register(codec, reg);
  1668. else
  1669. return 1;
  1670. }
  1671. EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register);
  1672. int snd_soc_platform_read(struct snd_soc_platform *platform,
  1673. unsigned int reg)
  1674. {
  1675. unsigned int ret;
  1676. if (!platform->driver->read) {
  1677. dev_err(platform->dev, "ASoC: platform has no read back\n");
  1678. return -1;
  1679. }
  1680. ret = platform->driver->read(platform, reg);
  1681. dev_dbg(platform->dev, "read %x => %x\n", reg, ret);
  1682. trace_snd_soc_preg_read(platform, reg, ret);
  1683. return ret;
  1684. }
  1685. EXPORT_SYMBOL_GPL(snd_soc_platform_read);
  1686. int snd_soc_platform_write(struct snd_soc_platform *platform,
  1687. unsigned int reg, unsigned int val)
  1688. {
  1689. if (!platform->driver->write) {
  1690. dev_err(platform->dev, "ASoC: platform has no write back\n");
  1691. return -1;
  1692. }
  1693. dev_dbg(platform->dev, "write %x = %x\n", reg, val);
  1694. trace_snd_soc_preg_write(platform, reg, val);
  1695. return platform->driver->write(platform, reg, val);
  1696. }
  1697. EXPORT_SYMBOL_GPL(snd_soc_platform_write);
  1698. /**
  1699. * snd_soc_new_ac97_codec - initailise AC97 device
  1700. * @codec: audio codec
  1701. * @ops: AC97 bus operations
  1702. * @num: AC97 codec number
  1703. *
  1704. * Initialises AC97 codec resources for use by ad-hoc devices only.
  1705. */
  1706. int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
  1707. struct snd_ac97_bus_ops *ops, int num)
  1708. {
  1709. mutex_lock(&codec->mutex);
  1710. codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
  1711. if (codec->ac97 == NULL) {
  1712. mutex_unlock(&codec->mutex);
  1713. return -ENOMEM;
  1714. }
  1715. codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
  1716. if (codec->ac97->bus == NULL) {
  1717. kfree(codec->ac97);
  1718. codec->ac97 = NULL;
  1719. mutex_unlock(&codec->mutex);
  1720. return -ENOMEM;
  1721. }
  1722. codec->ac97->bus->ops = ops;
  1723. codec->ac97->num = num;
  1724. /*
  1725. * Mark the AC97 device to be created by us. This way we ensure that the
  1726. * device will be registered with the device subsystem later on.
  1727. */
  1728. codec->ac97_created = 1;
  1729. mutex_unlock(&codec->mutex);
  1730. return 0;
  1731. }
  1732. EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
  1733. /**
  1734. * snd_soc_free_ac97_codec - free AC97 codec device
  1735. * @codec: audio codec
  1736. *
  1737. * Frees AC97 codec device resources.
  1738. */
  1739. void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
  1740. {
  1741. mutex_lock(&codec->mutex);
  1742. #ifdef CONFIG_SND_SOC_AC97_BUS
  1743. soc_unregister_ac97_dai_link(codec);
  1744. #endif
  1745. kfree(codec->ac97->bus);
  1746. kfree(codec->ac97);
  1747. codec->ac97 = NULL;
  1748. codec->ac97_created = 0;
  1749. mutex_unlock(&codec->mutex);
  1750. }
  1751. EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
  1752. unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
  1753. {
  1754. unsigned int ret;
  1755. ret = codec->read(codec, reg);
  1756. dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
  1757. trace_snd_soc_reg_read(codec, reg, ret);
  1758. return ret;
  1759. }
  1760. EXPORT_SYMBOL_GPL(snd_soc_read);
  1761. unsigned int snd_soc_write(struct snd_soc_codec *codec,
  1762. unsigned int reg, unsigned int val)
  1763. {
  1764. dev_dbg(codec->dev, "write %x = %x\n", reg, val);
  1765. trace_snd_soc_reg_write(codec, reg, val);
  1766. return codec->write(codec, reg, val);
  1767. }
  1768. EXPORT_SYMBOL_GPL(snd_soc_write);
  1769. unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
  1770. unsigned int reg, const void *data, size_t len)
  1771. {
  1772. return codec->bulk_write_raw(codec, reg, data, len);
  1773. }
  1774. EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw);
  1775. /**
  1776. * snd_soc_update_bits - update codec register bits
  1777. * @codec: audio codec
  1778. * @reg: codec register
  1779. * @mask: register mask
  1780. * @value: new value
  1781. *
  1782. * Writes new register value.
  1783. *
  1784. * Returns 1 for change, 0 for no change, or negative error code.
  1785. */
  1786. int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
  1787. unsigned int mask, unsigned int value)
  1788. {
  1789. bool change;
  1790. unsigned int old, new;
  1791. int ret;
  1792. if (codec->using_regmap) {
  1793. ret = regmap_update_bits_check(codec->control_data, reg,
  1794. mask, value, &change);
  1795. } else {
  1796. ret = snd_soc_read(codec, reg);
  1797. if (ret < 0)
  1798. return ret;
  1799. old = ret;
  1800. new = (old & ~mask) | (value & mask);
  1801. change = old != new;
  1802. if (change)
  1803. ret = snd_soc_write(codec, reg, new);
  1804. }
  1805. if (ret < 0)
  1806. return ret;
  1807. return change;
  1808. }
  1809. EXPORT_SYMBOL_GPL(snd_soc_update_bits);
  1810. /**
  1811. * snd_soc_update_bits_locked - update codec register bits
  1812. * @codec: audio codec
  1813. * @reg: codec register
  1814. * @mask: register mask
  1815. * @value: new value
  1816. *
  1817. * Writes new register value, and takes the codec mutex.
  1818. *
  1819. * Returns 1 for change else 0.
  1820. */
  1821. int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
  1822. unsigned short reg, unsigned int mask,
  1823. unsigned int value)
  1824. {
  1825. int change;
  1826. mutex_lock(&codec->mutex);
  1827. change = snd_soc_update_bits(codec, reg, mask, value);
  1828. mutex_unlock(&codec->mutex);
  1829. return change;
  1830. }
  1831. EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
  1832. /**
  1833. * snd_soc_test_bits - test register for change
  1834. * @codec: audio codec
  1835. * @reg: codec register
  1836. * @mask: register mask
  1837. * @value: new value
  1838. *
  1839. * Tests a register with a new value and checks if the new value is
  1840. * different from the old value.
  1841. *
  1842. * Returns 1 for change else 0.
  1843. */
  1844. int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
  1845. unsigned int mask, unsigned int value)
  1846. {
  1847. int change;
  1848. unsigned int old, new;
  1849. old = snd_soc_read(codec, reg);
  1850. new = (old & ~mask) | value;
  1851. change = old != new;
  1852. return change;
  1853. }
  1854. EXPORT_SYMBOL_GPL(snd_soc_test_bits);
  1855. /**
  1856. * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
  1857. * @substream: the pcm substream
  1858. * @hw: the hardware parameters
  1859. *
  1860. * Sets the substream runtime hardware parameters.
  1861. */
  1862. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  1863. const struct snd_pcm_hardware *hw)
  1864. {
  1865. struct snd_pcm_runtime *runtime = substream->runtime;
  1866. runtime->hw.info = hw->info;
  1867. runtime->hw.formats = hw->formats;
  1868. runtime->hw.period_bytes_min = hw->period_bytes_min;
  1869. runtime->hw.period_bytes_max = hw->period_bytes_max;
  1870. runtime->hw.periods_min = hw->periods_min;
  1871. runtime->hw.periods_max = hw->periods_max;
  1872. runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
  1873. runtime->hw.fifo_size = hw->fifo_size;
  1874. return 0;
  1875. }
  1876. EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
  1877. /**
  1878. * snd_soc_cnew - create new control
  1879. * @_template: control template
  1880. * @data: control private data
  1881. * @long_name: control long name
  1882. * @prefix: control name prefix
  1883. *
  1884. * Create a new mixer control from a template control.
  1885. *
  1886. * Returns 0 for success, else error.
  1887. */
  1888. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  1889. void *data, const char *long_name,
  1890. const char *prefix)
  1891. {
  1892. struct snd_kcontrol_new template;
  1893. struct snd_kcontrol *kcontrol;
  1894. char *name = NULL;
  1895. int name_len;
  1896. memcpy(&template, _template, sizeof(template));
  1897. template.index = 0;
  1898. if (!long_name)
  1899. long_name = template.name;
  1900. if (prefix) {
  1901. name_len = strlen(long_name) + strlen(prefix) + 2;
  1902. name = kmalloc(name_len, GFP_KERNEL);
  1903. if (!name)
  1904. return NULL;
  1905. snprintf(name, name_len, "%s %s", prefix, long_name);
  1906. template.name = name;
  1907. } else {
  1908. template.name = long_name;
  1909. }
  1910. kcontrol = snd_ctl_new1(&template, data);
  1911. kfree(name);
  1912. return kcontrol;
  1913. }
  1914. EXPORT_SYMBOL_GPL(snd_soc_cnew);
  1915. static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
  1916. const struct snd_kcontrol_new *controls, int num_controls,
  1917. const char *prefix, void *data)
  1918. {
  1919. int err, i;
  1920. for (i = 0; i < num_controls; i++) {
  1921. const struct snd_kcontrol_new *control = &controls[i];
  1922. err = snd_ctl_add(card, snd_soc_cnew(control, data,
  1923. control->name, prefix));
  1924. if (err < 0) {
  1925. dev_err(dev, "ASoC: Failed to add %s: %d\n",
  1926. control->name, err);
  1927. return err;
  1928. }
  1929. }
  1930. return 0;
  1931. }
  1932. /**
  1933. * snd_soc_add_codec_controls - add an array of controls to a codec.
  1934. * Convenience function to add a list of controls. Many codecs were
  1935. * duplicating this code.
  1936. *
  1937. * @codec: codec to add controls to
  1938. * @controls: array of controls to add
  1939. * @num_controls: number of elements in the array
  1940. *
  1941. * Return 0 for success, else error.
  1942. */
  1943. int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
  1944. const struct snd_kcontrol_new *controls, int num_controls)
  1945. {
  1946. struct snd_card *card = codec->card->snd_card;
  1947. return snd_soc_add_controls(card, codec->dev, controls, num_controls,
  1948. codec->name_prefix, codec);
  1949. }
  1950. EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls);
  1951. /**
  1952. * snd_soc_add_platform_controls - add an array of controls to a platform.
  1953. * Convenience function to add a list of controls.
  1954. *
  1955. * @platform: platform to add controls to
  1956. * @controls: array of controls to add
  1957. * @num_controls: number of elements in the array
  1958. *
  1959. * Return 0 for success, else error.
  1960. */
  1961. int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
  1962. const struct snd_kcontrol_new *controls, int num_controls)
  1963. {
  1964. struct snd_card *card = platform->card->snd_card;
  1965. return snd_soc_add_controls(card, platform->dev, controls, num_controls,
  1966. NULL, platform);
  1967. }
  1968. EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
  1969. /**
  1970. * snd_soc_add_card_controls - add an array of controls to a SoC card.
  1971. * Convenience function to add a list of controls.
  1972. *
  1973. * @soc_card: SoC card to add controls to
  1974. * @controls: array of controls to add
  1975. * @num_controls: number of elements in the array
  1976. *
  1977. * Return 0 for success, else error.
  1978. */
  1979. int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
  1980. const struct snd_kcontrol_new *controls, int num_controls)
  1981. {
  1982. struct snd_card *card = soc_card->snd_card;
  1983. return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
  1984. NULL, soc_card);
  1985. }
  1986. EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
  1987. /**
  1988. * snd_soc_add_dai_controls - add an array of controls to a DAI.
  1989. * Convienience function to add a list of controls.
  1990. *
  1991. * @dai: DAI to add controls to
  1992. * @controls: array of controls to add
  1993. * @num_controls: number of elements in the array
  1994. *
  1995. * Return 0 for success, else error.
  1996. */
  1997. int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
  1998. const struct snd_kcontrol_new *controls, int num_controls)
  1999. {
  2000. struct snd_card *card = dai->card->snd_card;
  2001. return snd_soc_add_controls(card, dai->dev, controls, num_controls,
  2002. NULL, dai);
  2003. }
  2004. EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
  2005. /**
  2006. * snd_soc_info_enum_double - enumerated double mixer info callback
  2007. * @kcontrol: mixer control
  2008. * @uinfo: control element information
  2009. *
  2010. * Callback to provide information about a double enumerated
  2011. * mixer control.
  2012. *
  2013. * Returns 0 for success.
  2014. */
  2015. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  2016. struct snd_ctl_elem_info *uinfo)
  2017. {
  2018. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2019. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2020. uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
  2021. uinfo->value.enumerated.items = e->max;
  2022. if (uinfo->value.enumerated.item > e->max - 1)
  2023. uinfo->value.enumerated.item = e->max - 1;
  2024. strcpy(uinfo->value.enumerated.name,
  2025. e->texts[uinfo->value.enumerated.item]);
  2026. return 0;
  2027. }
  2028. EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
  2029. /**
  2030. * snd_soc_get_enum_double - enumerated double mixer get callback
  2031. * @kcontrol: mixer control
  2032. * @ucontrol: control element information
  2033. *
  2034. * Callback to get the value of a double enumerated mixer.
  2035. *
  2036. * Returns 0 for success.
  2037. */
  2038. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  2039. struct snd_ctl_elem_value *ucontrol)
  2040. {
  2041. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2042. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2043. unsigned int val;
  2044. val = snd_soc_read(codec, e->reg);
  2045. ucontrol->value.enumerated.item[0]
  2046. = (val >> e->shift_l) & e->mask;
  2047. if (e->shift_l != e->shift_r)
  2048. ucontrol->value.enumerated.item[1] =
  2049. (val >> e->shift_r) & e->mask;
  2050. return 0;
  2051. }
  2052. EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
  2053. /**
  2054. * snd_soc_put_enum_double - enumerated double mixer put callback
  2055. * @kcontrol: mixer control
  2056. * @ucontrol: control element information
  2057. *
  2058. * Callback to set the value of a double enumerated mixer.
  2059. *
  2060. * Returns 0 for success.
  2061. */
  2062. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  2063. struct snd_ctl_elem_value *ucontrol)
  2064. {
  2065. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2066. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2067. unsigned int val;
  2068. unsigned int mask;
  2069. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  2070. return -EINVAL;
  2071. val = ucontrol->value.enumerated.item[0] << e->shift_l;
  2072. mask = e->mask << e->shift_l;
  2073. if (e->shift_l != e->shift_r) {
  2074. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  2075. return -EINVAL;
  2076. val |= ucontrol->value.enumerated.item[1] << e->shift_r;
  2077. mask |= e->mask << e->shift_r;
  2078. }
  2079. return snd_soc_update_bits_locked(codec, e->reg, mask, val);
  2080. }
  2081. EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
  2082. /**
  2083. * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
  2084. * @kcontrol: mixer control
  2085. * @ucontrol: control element information
  2086. *
  2087. * Callback to get the value of a double semi enumerated mixer.
  2088. *
  2089. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  2090. * used for handling bitfield coded enumeration for example.
  2091. *
  2092. * Returns 0 for success.
  2093. */
  2094. int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
  2095. struct snd_ctl_elem_value *ucontrol)
  2096. {
  2097. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2098. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2099. unsigned int reg_val, val, mux;
  2100. reg_val = snd_soc_read(codec, e->reg);
  2101. val = (reg_val >> e->shift_l) & e->mask;
  2102. for (mux = 0; mux < e->max; mux++) {
  2103. if (val == e->values[mux])
  2104. break;
  2105. }
  2106. ucontrol->value.enumerated.item[0] = mux;
  2107. if (e->shift_l != e->shift_r) {
  2108. val = (reg_val >> e->shift_r) & e->mask;
  2109. for (mux = 0; mux < e->max; mux++) {
  2110. if (val == e->values[mux])
  2111. break;
  2112. }
  2113. ucontrol->value.enumerated.item[1] = mux;
  2114. }
  2115. return 0;
  2116. }
  2117. EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
  2118. /**
  2119. * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
  2120. * @kcontrol: mixer control
  2121. * @ucontrol: control element information
  2122. *
  2123. * Callback to set the value of a double semi enumerated mixer.
  2124. *
  2125. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  2126. * used for handling bitfield coded enumeration for example.
  2127. *
  2128. * Returns 0 for success.
  2129. */
  2130. int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
  2131. struct snd_ctl_elem_value *ucontrol)
  2132. {
  2133. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2134. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2135. unsigned int val;
  2136. unsigned int mask;
  2137. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  2138. return -EINVAL;
  2139. val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
  2140. mask = e->mask << e->shift_l;
  2141. if (e->shift_l != e->shift_r) {
  2142. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  2143. return -EINVAL;
  2144. val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
  2145. mask |= e->mask << e->shift_r;
  2146. }
  2147. return snd_soc_update_bits_locked(codec, e->reg, mask, val);
  2148. }
  2149. EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
  2150. /**
  2151. * snd_soc_info_enum_ext - external enumerated single mixer info callback
  2152. * @kcontrol: mixer control
  2153. * @uinfo: control element information
  2154. *
  2155. * Callback to provide information about an external enumerated
  2156. * single mixer.
  2157. *
  2158. * Returns 0 for success.
  2159. */
  2160. int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
  2161. struct snd_ctl_elem_info *uinfo)
  2162. {
  2163. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2164. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2165. uinfo->count = 1;
  2166. uinfo->value.enumerated.items = e->max;
  2167. if (uinfo->value.enumerated.item > e->max - 1)
  2168. uinfo->value.enumerated.item = e->max - 1;
  2169. strcpy(uinfo->value.enumerated.name,
  2170. e->texts[uinfo->value.enumerated.item]);
  2171. return 0;
  2172. }
  2173. EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
  2174. /**
  2175. * snd_soc_info_volsw_ext - external single mixer info callback
  2176. * @kcontrol: mixer control
  2177. * @uinfo: control element information
  2178. *
  2179. * Callback to provide information about a single external mixer control.
  2180. *
  2181. * Returns 0 for success.
  2182. */
  2183. int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
  2184. struct snd_ctl_elem_info *uinfo)
  2185. {
  2186. int max = kcontrol->private_value;
  2187. if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
  2188. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2189. else
  2190. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2191. uinfo->count = 1;
  2192. uinfo->value.integer.min = 0;
  2193. uinfo->value.integer.max = max;
  2194. return 0;
  2195. }
  2196. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
  2197. /**
  2198. * snd_soc_info_volsw - single mixer info callback
  2199. * @kcontrol: mixer control
  2200. * @uinfo: control element information
  2201. *
  2202. * Callback to provide information about a single mixer control, or a double
  2203. * mixer control that spans 2 registers.
  2204. *
  2205. * Returns 0 for success.
  2206. */
  2207. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  2208. struct snd_ctl_elem_info *uinfo)
  2209. {
  2210. struct soc_mixer_control *mc =
  2211. (struct soc_mixer_control *)kcontrol->private_value;
  2212. int platform_max;
  2213. if (!mc->platform_max)
  2214. mc->platform_max = mc->max;
  2215. platform_max = mc->platform_max;
  2216. if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
  2217. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2218. else
  2219. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2220. uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
  2221. uinfo->value.integer.min = 0;
  2222. uinfo->value.integer.max = platform_max;
  2223. return 0;
  2224. }
  2225. EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
  2226. /**
  2227. * snd_soc_get_volsw - single mixer get callback
  2228. * @kcontrol: mixer control
  2229. * @ucontrol: control element information
  2230. *
  2231. * Callback to get the value of a single mixer control, or a double mixer
  2232. * control that spans 2 registers.
  2233. *
  2234. * Returns 0 for success.
  2235. */
  2236. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  2237. struct snd_ctl_elem_value *ucontrol)
  2238. {
  2239. struct soc_mixer_control *mc =
  2240. (struct soc_mixer_control *)kcontrol->private_value;
  2241. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2242. unsigned int reg = mc->reg;
  2243. unsigned int reg2 = mc->rreg;
  2244. unsigned int shift = mc->shift;
  2245. unsigned int rshift = mc->rshift;
  2246. int max = mc->max;
  2247. unsigned int mask = (1 << fls(max)) - 1;
  2248. unsigned int invert = mc->invert;
  2249. ucontrol->value.integer.value[0] =
  2250. (snd_soc_read(codec, reg) >> shift) & mask;
  2251. if (invert)
  2252. ucontrol->value.integer.value[0] =
  2253. max - ucontrol->value.integer.value[0];
  2254. if (snd_soc_volsw_is_stereo(mc)) {
  2255. if (reg == reg2)
  2256. ucontrol->value.integer.value[1] =
  2257. (snd_soc_read(codec, reg) >> rshift) & mask;
  2258. else
  2259. ucontrol->value.integer.value[1] =
  2260. (snd_soc_read(codec, reg2) >> shift) & mask;
  2261. if (invert)
  2262. ucontrol->value.integer.value[1] =
  2263. max - ucontrol->value.integer.value[1];
  2264. }
  2265. return 0;
  2266. }
  2267. EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
  2268. /**
  2269. * snd_soc_put_volsw - single mixer put callback
  2270. * @kcontrol: mixer control
  2271. * @ucontrol: control element information
  2272. *
  2273. * Callback to set the value of a single mixer control, or a double mixer
  2274. * control that spans 2 registers.
  2275. *
  2276. * Returns 0 for success.
  2277. */
  2278. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  2279. struct snd_ctl_elem_value *ucontrol)
  2280. {
  2281. struct soc_mixer_control *mc =
  2282. (struct soc_mixer_control *)kcontrol->private_value;
  2283. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2284. unsigned int reg = mc->reg;
  2285. unsigned int reg2 = mc->rreg;
  2286. unsigned int shift = mc->shift;
  2287. unsigned int rshift = mc->rshift;
  2288. int max = mc->max;
  2289. unsigned int mask = (1 << fls(max)) - 1;
  2290. unsigned int invert = mc->invert;
  2291. int err;
  2292. bool type_2r = 0;
  2293. unsigned int val2 = 0;
  2294. unsigned int val, val_mask;
  2295. val = (ucontrol->value.integer.value[0] & mask);
  2296. if (invert)
  2297. val = max - val;
  2298. val_mask = mask << shift;
  2299. val = val << shift;
  2300. if (snd_soc_volsw_is_stereo(mc)) {
  2301. val2 = (ucontrol->value.integer.value[1] & mask);
  2302. if (invert)
  2303. val2 = max - val2;
  2304. if (reg == reg2) {
  2305. val_mask |= mask << rshift;
  2306. val |= val2 << rshift;
  2307. } else {
  2308. val2 = val2 << shift;
  2309. type_2r = 1;
  2310. }
  2311. }
  2312. err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
  2313. if (err < 0)
  2314. return err;
  2315. if (type_2r)
  2316. err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
  2317. return err;
  2318. }
  2319. EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
  2320. /**
  2321. * snd_soc_get_volsw_sx - single mixer get callback
  2322. * @kcontrol: mixer control
  2323. * @ucontrol: control element information
  2324. *
  2325. * Callback to get the value of a single mixer control, or a double mixer
  2326. * control that spans 2 registers.
  2327. *
  2328. * Returns 0 for success.
  2329. */
  2330. int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
  2331. struct snd_ctl_elem_value *ucontrol)
  2332. {
  2333. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2334. struct soc_mixer_control *mc =
  2335. (struct soc_mixer_control *)kcontrol->private_value;
  2336. unsigned int reg = mc->reg;
  2337. unsigned int reg2 = mc->rreg;
  2338. unsigned int shift = mc->shift;
  2339. unsigned int rshift = mc->rshift;
  2340. int max = mc->max;
  2341. int min = mc->min;
  2342. int mask = (1 << (fls(min + max) - 1)) - 1;
  2343. ucontrol->value.integer.value[0] =
  2344. ((snd_soc_read(codec, reg) >> shift) - min) & mask;
  2345. if (snd_soc_volsw_is_stereo(mc))
  2346. ucontrol->value.integer.value[1] =
  2347. ((snd_soc_read(codec, reg2) >> rshift) - min) & mask;
  2348. return 0;
  2349. }
  2350. EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx);
  2351. /**
  2352. * snd_soc_put_volsw_sx - double mixer set callback
  2353. * @kcontrol: mixer control
  2354. * @uinfo: control element information
  2355. *
  2356. * Callback to set the value of a double mixer control that spans 2 registers.
  2357. *
  2358. * Returns 0 for success.
  2359. */
  2360. int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
  2361. struct snd_ctl_elem_value *ucontrol)
  2362. {
  2363. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2364. struct soc_mixer_control *mc =
  2365. (struct soc_mixer_control *)kcontrol->private_value;
  2366. unsigned int reg = mc->reg;
  2367. unsigned int reg2 = mc->rreg;
  2368. unsigned int shift = mc->shift;
  2369. unsigned int rshift = mc->rshift;
  2370. int max = mc->max;
  2371. int min = mc->min;
  2372. int mask = (1 << (fls(min + max) - 1)) - 1;
  2373. int err = 0;
  2374. unsigned short val, val_mask, val2 = 0;
  2375. val_mask = mask << shift;
  2376. val = (ucontrol->value.integer.value[0] + min) & mask;
  2377. val = val << shift;
  2378. err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
  2379. if (err < 0)
  2380. return err;
  2381. if (snd_soc_volsw_is_stereo(mc)) {
  2382. val_mask = mask << rshift;
  2383. val2 = (ucontrol->value.integer.value[1] + min) & mask;
  2384. val2 = val2 << rshift;
  2385. if (snd_soc_update_bits_locked(codec, reg2, val_mask, val2))
  2386. return err;
  2387. }
  2388. return 0;
  2389. }
  2390. EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);
  2391. /**
  2392. * snd_soc_info_volsw_s8 - signed mixer info callback
  2393. * @kcontrol: mixer control
  2394. * @uinfo: control element information
  2395. *
  2396. * Callback to provide information about a signed mixer control.
  2397. *
  2398. * Returns 0 for success.
  2399. */
  2400. int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
  2401. struct snd_ctl_elem_info *uinfo)
  2402. {
  2403. struct soc_mixer_control *mc =
  2404. (struct soc_mixer_control *)kcontrol->private_value;
  2405. int platform_max;
  2406. int min = mc->min;
  2407. if (!mc->platform_max)
  2408. mc->platform_max = mc->max;
  2409. platform_max = mc->platform_max;
  2410. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2411. uinfo->count = 2;
  2412. uinfo->value.integer.min = 0;
  2413. uinfo->value.integer.max = platform_max - min;
  2414. return 0;
  2415. }
  2416. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
  2417. /**
  2418. * snd_soc_get_volsw_s8 - signed mixer get callback
  2419. * @kcontrol: mixer control
  2420. * @ucontrol: control element information
  2421. *
  2422. * Callback to get the value of a signed mixer control.
  2423. *
  2424. * Returns 0 for success.
  2425. */
  2426. int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
  2427. struct snd_ctl_elem_value *ucontrol)
  2428. {
  2429. struct soc_mixer_control *mc =
  2430. (struct soc_mixer_control *)kcontrol->private_value;
  2431. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2432. unsigned int reg = mc->reg;
  2433. int min = mc->min;
  2434. int val = snd_soc_read(codec, reg);
  2435. ucontrol->value.integer.value[0] =
  2436. ((signed char)(val & 0xff))-min;
  2437. ucontrol->value.integer.value[1] =
  2438. ((signed char)((val >> 8) & 0xff))-min;
  2439. return 0;
  2440. }
  2441. EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
  2442. /**
  2443. * snd_soc_put_volsw_sgn - signed mixer put callback
  2444. * @kcontrol: mixer control
  2445. * @ucontrol: control element information
  2446. *
  2447. * Callback to set the value of a signed mixer control.
  2448. *
  2449. * Returns 0 for success.
  2450. */
  2451. int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
  2452. struct snd_ctl_elem_value *ucontrol)
  2453. {
  2454. struct soc_mixer_control *mc =
  2455. (struct soc_mixer_control *)kcontrol->private_value;
  2456. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2457. unsigned int reg = mc->reg;
  2458. int min = mc->min;
  2459. unsigned int val;
  2460. val = (ucontrol->value.integer.value[0]+min) & 0xff;
  2461. val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
  2462. return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
  2463. }
  2464. EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
  2465. /**
  2466. * snd_soc_info_volsw_range - single mixer info callback with range.
  2467. * @kcontrol: mixer control
  2468. * @uinfo: control element information
  2469. *
  2470. * Callback to provide information, within a range, about a single
  2471. * mixer control.
  2472. *
  2473. * returns 0 for success.
  2474. */
  2475. int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
  2476. struct snd_ctl_elem_info *uinfo)
  2477. {
  2478. struct soc_mixer_control *mc =
  2479. (struct soc_mixer_control *)kcontrol->private_value;
  2480. int platform_max;
  2481. int min = mc->min;
  2482. if (!mc->platform_max)
  2483. mc->platform_max = mc->max;
  2484. platform_max = mc->platform_max;
  2485. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2486. uinfo->count = 1;
  2487. uinfo->value.integer.min = 0;
  2488. uinfo->value.integer.max = platform_max - min;
  2489. return 0;
  2490. }
  2491. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range);
  2492. /**
  2493. * snd_soc_put_volsw_range - single mixer put value callback with range.
  2494. * @kcontrol: mixer control
  2495. * @ucontrol: control element information
  2496. *
  2497. * Callback to set the value, within a range, for a single mixer control.
  2498. *
  2499. * Returns 0 for success.
  2500. */
  2501. int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
  2502. struct snd_ctl_elem_value *ucontrol)
  2503. {
  2504. struct soc_mixer_control *mc =
  2505. (struct soc_mixer_control *)kcontrol->private_value;
  2506. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2507. unsigned int reg = mc->reg;
  2508. unsigned int shift = mc->shift;
  2509. int min = mc->min;
  2510. int max = mc->max;
  2511. unsigned int mask = (1 << fls(max)) - 1;
  2512. unsigned int invert = mc->invert;
  2513. unsigned int val, val_mask;
  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. return snd_soc_update_bits_locked(codec, reg, val_mask, val);
  2520. }
  2521. EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range);
  2522. /**
  2523. * snd_soc_get_volsw_range - single mixer get callback with range
  2524. * @kcontrol: mixer control
  2525. * @ucontrol: control element information
  2526. *
  2527. * Callback to get the value, within a range, of a single mixer control.
  2528. *
  2529. * Returns 0 for success.
  2530. */
  2531. int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
  2532. struct snd_ctl_elem_value *ucontrol)
  2533. {
  2534. struct soc_mixer_control *mc =
  2535. (struct soc_mixer_control *)kcontrol->private_value;
  2536. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2537. unsigned int reg = mc->reg;
  2538. unsigned int shift = mc->shift;
  2539. int min = mc->min;
  2540. int max = mc->max;
  2541. unsigned int mask = (1 << fls(max)) - 1;
  2542. unsigned int invert = mc->invert;
  2543. ucontrol->value.integer.value[0] =
  2544. (snd_soc_read(codec, reg) >> shift) & mask;
  2545. if (invert)
  2546. ucontrol->value.integer.value[0] =
  2547. max - ucontrol->value.integer.value[0];
  2548. ucontrol->value.integer.value[0] =
  2549. ucontrol->value.integer.value[0] - min;
  2550. return 0;
  2551. }
  2552. EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);
  2553. /**
  2554. * snd_soc_limit_volume - Set new limit to an existing volume control.
  2555. *
  2556. * @codec: where to look for the control
  2557. * @name: Name of the control
  2558. * @max: new maximum limit
  2559. *
  2560. * Return 0 for success, else error.
  2561. */
  2562. int snd_soc_limit_volume(struct snd_soc_codec *codec,
  2563. const char *name, int max)
  2564. {
  2565. struct snd_card *card = codec->card->snd_card;
  2566. struct snd_kcontrol *kctl;
  2567. struct soc_mixer_control *mc;
  2568. int found = 0;
  2569. int ret = -EINVAL;
  2570. /* Sanity check for name and max */
  2571. if (unlikely(!name || max <= 0))
  2572. return -EINVAL;
  2573. list_for_each_entry(kctl, &card->controls, list) {
  2574. if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
  2575. found = 1;
  2576. break;
  2577. }
  2578. }
  2579. if (found) {
  2580. mc = (struct soc_mixer_control *)kctl->private_value;
  2581. if (max <= mc->max) {
  2582. mc->platform_max = max;
  2583. ret = 0;
  2584. }
  2585. }
  2586. return ret;
  2587. }
  2588. EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
  2589. int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
  2590. struct snd_ctl_elem_info *uinfo)
  2591. {
  2592. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2593. struct soc_bytes *params = (void *)kcontrol->private_value;
  2594. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  2595. uinfo->count = params->num_regs * codec->val_bytes;
  2596. return 0;
  2597. }
  2598. EXPORT_SYMBOL_GPL(snd_soc_bytes_info);
  2599. int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
  2600. struct snd_ctl_elem_value *ucontrol)
  2601. {
  2602. struct soc_bytes *params = (void *)kcontrol->private_value;
  2603. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2604. int ret;
  2605. if (codec->using_regmap)
  2606. ret = regmap_raw_read(codec->control_data, params->base,
  2607. ucontrol->value.bytes.data,
  2608. params->num_regs * codec->val_bytes);
  2609. else
  2610. ret = -EINVAL;
  2611. /* Hide any masked bytes to ensure consistent data reporting */
  2612. if (ret == 0 && params->mask) {
  2613. switch (codec->val_bytes) {
  2614. case 1:
  2615. ucontrol->value.bytes.data[0] &= ~params->mask;
  2616. break;
  2617. case 2:
  2618. ((u16 *)(&ucontrol->value.bytes.data))[0]
  2619. &= ~params->mask;
  2620. break;
  2621. case 4:
  2622. ((u32 *)(&ucontrol->value.bytes.data))[0]
  2623. &= ~params->mask;
  2624. break;
  2625. default:
  2626. return -EINVAL;
  2627. }
  2628. }
  2629. return ret;
  2630. }
  2631. EXPORT_SYMBOL_GPL(snd_soc_bytes_get);
  2632. int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
  2633. struct snd_ctl_elem_value *ucontrol)
  2634. {
  2635. struct soc_bytes *params = (void *)kcontrol->private_value;
  2636. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2637. int ret, len;
  2638. unsigned int val;
  2639. void *data;
  2640. if (!codec->using_regmap)
  2641. return -EINVAL;
  2642. len = params->num_regs * codec->val_bytes;
  2643. data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA);
  2644. if (!data)
  2645. return -ENOMEM;
  2646. /*
  2647. * If we've got a mask then we need to preserve the register
  2648. * bits. We shouldn't modify the incoming data so take a
  2649. * copy.
  2650. */
  2651. if (params->mask) {
  2652. ret = regmap_read(codec->control_data, params->base, &val);
  2653. if (ret != 0)
  2654. return ret;
  2655. val &= params->mask;
  2656. switch (codec->val_bytes) {
  2657. case 1:
  2658. ((u8 *)data)[0] &= ~params->mask;
  2659. ((u8 *)data)[0] |= val;
  2660. break;
  2661. case 2:
  2662. ((u16 *)data)[0] &= cpu_to_be16(~params->mask);
  2663. ((u16 *)data)[0] |= cpu_to_be16(val);
  2664. break;
  2665. case 4:
  2666. ((u32 *)data)[0] &= cpu_to_be32(~params->mask);
  2667. ((u32 *)data)[0] |= cpu_to_be32(val);
  2668. break;
  2669. default:
  2670. return -EINVAL;
  2671. }
  2672. }
  2673. ret = regmap_raw_write(codec->control_data, params->base,
  2674. data, len);
  2675. kfree(data);
  2676. return ret;
  2677. }
  2678. EXPORT_SYMBOL_GPL(snd_soc_bytes_put);
  2679. /**
  2680. * snd_soc_info_xr_sx - signed multi register info callback
  2681. * @kcontrol: mreg control
  2682. * @uinfo: control element information
  2683. *
  2684. * Callback to provide information of a control that can
  2685. * span multiple codec registers which together
  2686. * forms a single signed value in a MSB/LSB manner.
  2687. *
  2688. * Returns 0 for success.
  2689. */
  2690. int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
  2691. struct snd_ctl_elem_info *uinfo)
  2692. {
  2693. struct soc_mreg_control *mc =
  2694. (struct soc_mreg_control *)kcontrol->private_value;
  2695. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2696. uinfo->count = 1;
  2697. uinfo->value.integer.min = mc->min;
  2698. uinfo->value.integer.max = mc->max;
  2699. return 0;
  2700. }
  2701. EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx);
  2702. /**
  2703. * snd_soc_get_xr_sx - signed multi register get callback
  2704. * @kcontrol: mreg control
  2705. * @ucontrol: control element information
  2706. *
  2707. * Callback to get the value of a control that can span
  2708. * multiple codec registers which together forms a single
  2709. * signed value in a MSB/LSB manner. The control supports
  2710. * specifying total no of bits used to allow for bitfields
  2711. * across the multiple codec registers.
  2712. *
  2713. * Returns 0 for success.
  2714. */
  2715. int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
  2716. struct snd_ctl_elem_value *ucontrol)
  2717. {
  2718. struct soc_mreg_control *mc =
  2719. (struct soc_mreg_control *)kcontrol->private_value;
  2720. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2721. unsigned int regbase = mc->regbase;
  2722. unsigned int regcount = mc->regcount;
  2723. unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE;
  2724. unsigned int regwmask = (1<<regwshift)-1;
  2725. unsigned int invert = mc->invert;
  2726. unsigned long mask = (1UL<<mc->nbits)-1;
  2727. long min = mc->min;
  2728. long max = mc->max;
  2729. long val = 0;
  2730. unsigned long regval;
  2731. unsigned int i;
  2732. for (i = 0; i < regcount; i++) {
  2733. regval = snd_soc_read(codec, regbase+i) & regwmask;
  2734. val |= regval << (regwshift*(regcount-i-1));
  2735. }
  2736. val &= mask;
  2737. if (min < 0 && val > max)
  2738. val |= ~mask;
  2739. if (invert)
  2740. val = max - val;
  2741. ucontrol->value.integer.value[0] = val;
  2742. return 0;
  2743. }
  2744. EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx);
  2745. /**
  2746. * snd_soc_put_xr_sx - signed multi register get callback
  2747. * @kcontrol: mreg control
  2748. * @ucontrol: control element information
  2749. *
  2750. * Callback to set the value of a control that can span
  2751. * multiple codec registers which together forms a single
  2752. * signed value in a MSB/LSB manner. The control supports
  2753. * specifying total no of bits used to allow for bitfields
  2754. * across the multiple codec registers.
  2755. *
  2756. * Returns 0 for success.
  2757. */
  2758. int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
  2759. struct snd_ctl_elem_value *ucontrol)
  2760. {
  2761. struct soc_mreg_control *mc =
  2762. (struct soc_mreg_control *)kcontrol->private_value;
  2763. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2764. unsigned int regbase = mc->regbase;
  2765. unsigned int regcount = mc->regcount;
  2766. unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE;
  2767. unsigned int regwmask = (1<<regwshift)-1;
  2768. unsigned int invert = mc->invert;
  2769. unsigned long mask = (1UL<<mc->nbits)-1;
  2770. long max = mc->max;
  2771. long val = ucontrol->value.integer.value[0];
  2772. unsigned int i, regval, regmask;
  2773. int err;
  2774. if (invert)
  2775. val = max - val;
  2776. val &= mask;
  2777. for (i = 0; i < regcount; i++) {
  2778. regval = (val >> (regwshift*(regcount-i-1))) & regwmask;
  2779. regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask;
  2780. err = snd_soc_update_bits_locked(codec, regbase+i,
  2781. regmask, regval);
  2782. if (err < 0)
  2783. return err;
  2784. }
  2785. return 0;
  2786. }
  2787. EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx);
  2788. /**
  2789. * snd_soc_get_strobe - strobe get callback
  2790. * @kcontrol: mixer control
  2791. * @ucontrol: control element information
  2792. *
  2793. * Callback get the value of a strobe mixer control.
  2794. *
  2795. * Returns 0 for success.
  2796. */
  2797. int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
  2798. struct snd_ctl_elem_value *ucontrol)
  2799. {
  2800. struct soc_mixer_control *mc =
  2801. (struct soc_mixer_control *)kcontrol->private_value;
  2802. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2803. unsigned int reg = mc->reg;
  2804. unsigned int shift = mc->shift;
  2805. unsigned int mask = 1 << shift;
  2806. unsigned int invert = mc->invert != 0;
  2807. unsigned int val = snd_soc_read(codec, reg) & mask;
  2808. if (shift != 0 && val != 0)
  2809. val = val >> shift;
  2810. ucontrol->value.enumerated.item[0] = val ^ invert;
  2811. return 0;
  2812. }
  2813. EXPORT_SYMBOL_GPL(snd_soc_get_strobe);
  2814. /**
  2815. * snd_soc_put_strobe - strobe put callback
  2816. * @kcontrol: mixer control
  2817. * @ucontrol: control element information
  2818. *
  2819. * Callback strobe a register bit to high then low (or the inverse)
  2820. * in one pass of a single mixer enum control.
  2821. *
  2822. * Returns 1 for success.
  2823. */
  2824. int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
  2825. struct snd_ctl_elem_value *ucontrol)
  2826. {
  2827. struct soc_mixer_control *mc =
  2828. (struct soc_mixer_control *)kcontrol->private_value;
  2829. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2830. unsigned int reg = mc->reg;
  2831. unsigned int shift = mc->shift;
  2832. unsigned int mask = 1 << shift;
  2833. unsigned int invert = mc->invert != 0;
  2834. unsigned int strobe = ucontrol->value.enumerated.item[0] != 0;
  2835. unsigned int val1 = (strobe ^ invert) ? mask : 0;
  2836. unsigned int val2 = (strobe ^ invert) ? 0 : mask;
  2837. int err;
  2838. err = snd_soc_update_bits_locked(codec, reg, mask, val1);
  2839. if (err < 0)
  2840. return err;
  2841. err = snd_soc_update_bits_locked(codec, reg, mask, val2);
  2842. return err;
  2843. }
  2844. EXPORT_SYMBOL_GPL(snd_soc_put_strobe);
  2845. /**
  2846. * snd_soc_dai_set_sysclk - configure DAI system or master clock.
  2847. * @dai: DAI
  2848. * @clk_id: DAI specific clock ID
  2849. * @freq: new clock frequency in Hz
  2850. * @dir: new clock direction - input/output.
  2851. *
  2852. * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
  2853. */
  2854. int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
  2855. unsigned int freq, int dir)
  2856. {
  2857. if (dai->driver && dai->driver->ops->set_sysclk)
  2858. return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
  2859. else if (dai->codec && dai->codec->driver->set_sysclk)
  2860. return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
  2861. freq, dir);
  2862. else
  2863. return -EINVAL;
  2864. }
  2865. EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
  2866. /**
  2867. * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
  2868. * @codec: CODEC
  2869. * @clk_id: DAI specific clock ID
  2870. * @source: Source for the clock
  2871. * @freq: new clock frequency in Hz
  2872. * @dir: new clock direction - input/output.
  2873. *
  2874. * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
  2875. */
  2876. int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
  2877. int source, unsigned int freq, int dir)
  2878. {
  2879. if (codec->driver->set_sysclk)
  2880. return codec->driver->set_sysclk(codec, clk_id, source,
  2881. freq, dir);
  2882. else
  2883. return -EINVAL;
  2884. }
  2885. EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
  2886. /**
  2887. * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
  2888. * @dai: DAI
  2889. * @div_id: DAI specific clock divider ID
  2890. * @div: new clock divisor.
  2891. *
  2892. * Configures the clock dividers. This is used to derive the best DAI bit and
  2893. * frame clocks from the system or master clock. It's best to set the DAI bit
  2894. * and frame clocks as low as possible to save system power.
  2895. */
  2896. int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
  2897. int div_id, int div)
  2898. {
  2899. if (dai->driver && dai->driver->ops->set_clkdiv)
  2900. return dai->driver->ops->set_clkdiv(dai, div_id, div);
  2901. else
  2902. return -EINVAL;
  2903. }
  2904. EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
  2905. /**
  2906. * snd_soc_dai_set_pll - configure DAI PLL.
  2907. * @dai: DAI
  2908. * @pll_id: DAI specific PLL ID
  2909. * @source: DAI specific source for the PLL
  2910. * @freq_in: PLL input clock frequency in Hz
  2911. * @freq_out: requested PLL output clock frequency in Hz
  2912. *
  2913. * Configures and enables PLL to generate output clock based on input clock.
  2914. */
  2915. int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
  2916. unsigned int freq_in, unsigned int freq_out)
  2917. {
  2918. if (dai->driver && dai->driver->ops->set_pll)
  2919. return dai->driver->ops->set_pll(dai, pll_id, source,
  2920. freq_in, freq_out);
  2921. else if (dai->codec && dai->codec->driver->set_pll)
  2922. return dai->codec->driver->set_pll(dai->codec, pll_id, source,
  2923. freq_in, freq_out);
  2924. else
  2925. return -EINVAL;
  2926. }
  2927. EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
  2928. /*
  2929. * snd_soc_codec_set_pll - configure codec PLL.
  2930. * @codec: CODEC
  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_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
  2939. unsigned int freq_in, unsigned int freq_out)
  2940. {
  2941. if (codec->driver->set_pll)
  2942. return codec->driver->set_pll(codec, pll_id, source,
  2943. freq_in, freq_out);
  2944. else
  2945. return -EINVAL;
  2946. }
  2947. EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
  2948. /**
  2949. * snd_soc_dai_set_fmt - configure DAI hardware audio format.
  2950. * @dai: DAI
  2951. * @fmt: SND_SOC_DAIFMT_ format value.
  2952. *
  2953. * Configures the DAI hardware format and clocking.
  2954. */
  2955. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  2956. {
  2957. if (dai->driver == NULL)
  2958. return -EINVAL;
  2959. if (dai->driver->ops->set_fmt == NULL)
  2960. return -ENOTSUPP;
  2961. return dai->driver->ops->set_fmt(dai, fmt);
  2962. }
  2963. EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
  2964. /**
  2965. * snd_soc_dai_set_tdm_slot - configure DAI TDM.
  2966. * @dai: DAI
  2967. * @tx_mask: bitmask representing active TX slots.
  2968. * @rx_mask: bitmask representing active RX slots.
  2969. * @slots: Number of slots in use.
  2970. * @slot_width: Width in bits for each slot.
  2971. *
  2972. * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
  2973. * specific.
  2974. */
  2975. int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
  2976. unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
  2977. {
  2978. if (dai->driver && dai->driver->ops->set_tdm_slot)
  2979. return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
  2980. slots, slot_width);
  2981. else
  2982. return -EINVAL;
  2983. }
  2984. EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
  2985. /**
  2986. * snd_soc_dai_set_channel_map - configure DAI audio channel map
  2987. * @dai: DAI
  2988. * @tx_num: how many TX channels
  2989. * @tx_slot: pointer to an array which imply the TX slot number channel
  2990. * 0~num-1 uses
  2991. * @rx_num: how many RX channels
  2992. * @rx_slot: pointer to an array which imply the RX slot number channel
  2993. * 0~num-1 uses
  2994. *
  2995. * configure the relationship between channel number and TDM slot number.
  2996. */
  2997. int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
  2998. unsigned int tx_num, unsigned int *tx_slot,
  2999. unsigned int rx_num, unsigned int *rx_slot)
  3000. {
  3001. if (dai->driver && dai->driver->ops->set_channel_map)
  3002. return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
  3003. rx_num, rx_slot);
  3004. else
  3005. return -EINVAL;
  3006. }
  3007. EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
  3008. /**
  3009. * snd_soc_dai_set_tristate - configure DAI system or master clock.
  3010. * @dai: DAI
  3011. * @tristate: tristate enable
  3012. *
  3013. * Tristates the DAI so that others can use it.
  3014. */
  3015. int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
  3016. {
  3017. if (dai->driver && dai->driver->ops->set_tristate)
  3018. return dai->driver->ops->set_tristate(dai, tristate);
  3019. else
  3020. return -EINVAL;
  3021. }
  3022. EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
  3023. /**
  3024. * snd_soc_dai_digital_mute - configure DAI system or master clock.
  3025. * @dai: DAI
  3026. * @mute: mute enable
  3027. *
  3028. * Mutes the DAI DAC.
  3029. */
  3030. int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
  3031. {
  3032. if (dai->driver && dai->driver->ops->digital_mute)
  3033. return dai->driver->ops->digital_mute(dai, mute);
  3034. else
  3035. return -ENOTSUPP;
  3036. }
  3037. EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
  3038. /**
  3039. * snd_soc_register_card - Register a card with the ASoC core
  3040. *
  3041. * @card: Card to register
  3042. *
  3043. */
  3044. int snd_soc_register_card(struct snd_soc_card *card)
  3045. {
  3046. int i, ret;
  3047. if (!card->name || !card->dev)
  3048. return -EINVAL;
  3049. for (i = 0; i < card->num_links; i++) {
  3050. struct snd_soc_dai_link *link = &card->dai_link[i];
  3051. /*
  3052. * Codec must be specified by 1 of name or OF node,
  3053. * not both or neither.
  3054. */
  3055. if (!!link->codec_name == !!link->codec_of_node) {
  3056. dev_err(card->dev, "ASoC: Neither/both codec"
  3057. " name/of_node are set for %s\n", link->name);
  3058. return -EINVAL;
  3059. }
  3060. /* Codec DAI name must be specified */
  3061. if (!link->codec_dai_name) {
  3062. dev_err(card->dev, "ASoC: codec_dai_name not"
  3063. " set for %s\n", link->name);
  3064. return -EINVAL;
  3065. }
  3066. /*
  3067. * Platform may be specified by either name or OF node, but
  3068. * can be left unspecified, and a dummy platform will be used.
  3069. */
  3070. if (link->platform_name && link->platform_of_node) {
  3071. dev_err(card->dev, "ASoC: Both platform name/of_node"
  3072. " are set for %s\n", link->name);
  3073. return -EINVAL;
  3074. }
  3075. /*
  3076. * CPU device may be specified by either name or OF node, but
  3077. * can be left unspecified, and will be matched based on DAI
  3078. * name alone..
  3079. */
  3080. if (link->cpu_name && link->cpu_of_node) {
  3081. dev_err(card->dev, "ASoC: Neither/both "
  3082. "cpu name/of_node are set for %s\n",link->name);
  3083. return -EINVAL;
  3084. }
  3085. /*
  3086. * At least one of CPU DAI name or CPU device name/node must be
  3087. * specified
  3088. */
  3089. if (!link->cpu_dai_name &&
  3090. !(link->cpu_name || link->cpu_of_node)) {
  3091. dev_err(card->dev, "ASoC: Neither cpu_dai_name nor "
  3092. "cpu_name/of_node are set for %s\n", link->name);
  3093. return -EINVAL;
  3094. }
  3095. }
  3096. dev_set_drvdata(card->dev, card);
  3097. snd_soc_initialize_card_lists(card);
  3098. soc_init_card_debugfs(card);
  3099. card->rtd = devm_kzalloc(card->dev,
  3100. sizeof(struct snd_soc_pcm_runtime) *
  3101. (card->num_links + card->num_aux_devs),
  3102. GFP_KERNEL);
  3103. if (card->rtd == NULL)
  3104. return -ENOMEM;
  3105. card->num_rtd = 0;
  3106. card->rtd_aux = &card->rtd[card->num_links];
  3107. for (i = 0; i < card->num_links; i++)
  3108. card->rtd[i].dai_link = &card->dai_link[i];
  3109. INIT_LIST_HEAD(&card->list);
  3110. INIT_LIST_HEAD(&card->dapm_dirty);
  3111. card->instantiated = 0;
  3112. mutex_init(&card->mutex);
  3113. mutex_init(&card->dapm_mutex);
  3114. ret = snd_soc_instantiate_card(card);
  3115. if (ret != 0)
  3116. soc_cleanup_card_debugfs(card);
  3117. return ret;
  3118. }
  3119. EXPORT_SYMBOL_GPL(snd_soc_register_card);
  3120. /**
  3121. * snd_soc_unregister_card - Unregister a card with the ASoC core
  3122. *
  3123. * @card: Card to unregister
  3124. *
  3125. */
  3126. int snd_soc_unregister_card(struct snd_soc_card *card)
  3127. {
  3128. if (card->instantiated)
  3129. soc_cleanup_card_resources(card);
  3130. dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
  3131. return 0;
  3132. }
  3133. EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
  3134. /*
  3135. * Simplify DAI link configuration by removing ".-1" from device names
  3136. * and sanitizing names.
  3137. */
  3138. static char *fmt_single_name(struct device *dev, int *id)
  3139. {
  3140. char *found, name[NAME_SIZE];
  3141. int id1, id2;
  3142. if (dev_name(dev) == NULL)
  3143. return NULL;
  3144. strlcpy(name, dev_name(dev), NAME_SIZE);
  3145. /* are we a "%s.%d" name (platform and SPI components) */
  3146. found = strstr(name, dev->driver->name);
  3147. if (found) {
  3148. /* get ID */
  3149. if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
  3150. /* discard ID from name if ID == -1 */
  3151. if (*id == -1)
  3152. found[strlen(dev->driver->name)] = '\0';
  3153. }
  3154. } else {
  3155. /* I2C component devices are named "bus-addr" */
  3156. if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
  3157. char tmp[NAME_SIZE];
  3158. /* create unique ID number from I2C addr and bus */
  3159. *id = ((id1 & 0xffff) << 16) + id2;
  3160. /* sanitize component name for DAI link creation */
  3161. snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
  3162. strlcpy(name, tmp, NAME_SIZE);
  3163. } else
  3164. *id = 0;
  3165. }
  3166. return kstrdup(name, GFP_KERNEL);
  3167. }
  3168. /*
  3169. * Simplify DAI link naming for single devices with multiple DAIs by removing
  3170. * any ".-1" and using the DAI name (instead of device name).
  3171. */
  3172. static inline char *fmt_multiple_name(struct device *dev,
  3173. struct snd_soc_dai_driver *dai_drv)
  3174. {
  3175. if (dai_drv->name == NULL) {
  3176. dev_err(dev, "ASoC: error - multiple DAI %s registered with"
  3177. " no name\n", dev_name(dev));
  3178. return NULL;
  3179. }
  3180. return kstrdup(dai_drv->name, GFP_KERNEL);
  3181. }
  3182. /**
  3183. * snd_soc_register_dai - Register a DAI with the ASoC core
  3184. *
  3185. * @dai: DAI to register
  3186. */
  3187. int snd_soc_register_dai(struct device *dev,
  3188. struct snd_soc_dai_driver *dai_drv)
  3189. {
  3190. struct snd_soc_codec *codec;
  3191. struct snd_soc_dai *dai;
  3192. dev_dbg(dev, "ASoC: dai register %s\n", dev_name(dev));
  3193. dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
  3194. if (dai == NULL)
  3195. return -ENOMEM;
  3196. /* create DAI component name */
  3197. dai->name = fmt_single_name(dev, &dai->id);
  3198. if (dai->name == NULL) {
  3199. kfree(dai);
  3200. return -ENOMEM;
  3201. }
  3202. dai->dev = dev;
  3203. dai->driver = dai_drv;
  3204. dai->dapm.dev = dev;
  3205. if (!dai->driver->ops)
  3206. dai->driver->ops = &null_dai_ops;
  3207. mutex_lock(&client_mutex);
  3208. list_for_each_entry(codec, &codec_list, list) {
  3209. if (codec->dev == dev) {
  3210. dev_dbg(dev, "ASoC: Mapped DAI %s to CODEC %s\n",
  3211. dai->name, codec->name);
  3212. dai->codec = codec;
  3213. break;
  3214. }
  3215. }
  3216. if (!dai->codec)
  3217. dai->dapm.idle_bias_off = 1;
  3218. list_add(&dai->list, &dai_list);
  3219. mutex_unlock(&client_mutex);
  3220. dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
  3221. return 0;
  3222. }
  3223. EXPORT_SYMBOL_GPL(snd_soc_register_dai);
  3224. /**
  3225. * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
  3226. *
  3227. * @dai: DAI to unregister
  3228. */
  3229. void snd_soc_unregister_dai(struct device *dev)
  3230. {
  3231. struct snd_soc_dai *dai;
  3232. list_for_each_entry(dai, &dai_list, list) {
  3233. if (dev == dai->dev)
  3234. goto found;
  3235. }
  3236. return;
  3237. found:
  3238. mutex_lock(&client_mutex);
  3239. list_del(&dai->list);
  3240. mutex_unlock(&client_mutex);
  3241. dev_dbg(dev, "ASoC: Unregistered DAI '%s'\n", dai->name);
  3242. kfree(dai->name);
  3243. kfree(dai);
  3244. }
  3245. EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
  3246. /**
  3247. * snd_soc_register_dais - Register multiple DAIs with the ASoC core
  3248. *
  3249. * @dai: Array of DAIs to register
  3250. * @count: Number of DAIs
  3251. */
  3252. int snd_soc_register_dais(struct device *dev,
  3253. struct snd_soc_dai_driver *dai_drv, size_t count)
  3254. {
  3255. struct snd_soc_codec *codec;
  3256. struct snd_soc_dai *dai;
  3257. int i, ret = 0;
  3258. dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count);
  3259. for (i = 0; i < count; i++) {
  3260. dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
  3261. if (dai == NULL) {
  3262. ret = -ENOMEM;
  3263. goto err;
  3264. }
  3265. /* create DAI component name */
  3266. dai->name = fmt_multiple_name(dev, &dai_drv[i]);
  3267. if (dai->name == NULL) {
  3268. kfree(dai);
  3269. ret = -EINVAL;
  3270. goto err;
  3271. }
  3272. dai->dev = dev;
  3273. dai->driver = &dai_drv[i];
  3274. if (dai->driver->id)
  3275. dai->id = dai->driver->id;
  3276. else
  3277. dai->id = i;
  3278. dai->dapm.dev = dev;
  3279. if (!dai->driver->ops)
  3280. dai->driver->ops = &null_dai_ops;
  3281. mutex_lock(&client_mutex);
  3282. list_for_each_entry(codec, &codec_list, list) {
  3283. if (codec->dev == dev) {
  3284. dev_dbg(dev, "ASoC: Mapped DAI %s to "
  3285. "CODEC %s\n", dai->name, codec->name);
  3286. dai->codec = codec;
  3287. break;
  3288. }
  3289. }
  3290. if (!dai->codec)
  3291. dai->dapm.idle_bias_off = 1;
  3292. list_add(&dai->list, &dai_list);
  3293. mutex_unlock(&client_mutex);
  3294. dev_dbg(dai->dev, "ASoC: Registered DAI '%s'\n", dai->name);
  3295. }
  3296. return 0;
  3297. err:
  3298. for (i--; i >= 0; i--)
  3299. snd_soc_unregister_dai(dev);
  3300. return ret;
  3301. }
  3302. EXPORT_SYMBOL_GPL(snd_soc_register_dais);
  3303. /**
  3304. * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
  3305. *
  3306. * @dai: Array of DAIs to unregister
  3307. * @count: Number of DAIs
  3308. */
  3309. void snd_soc_unregister_dais(struct device *dev, size_t count)
  3310. {
  3311. int i;
  3312. for (i = 0; i < count; i++)
  3313. snd_soc_unregister_dai(dev);
  3314. }
  3315. EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
  3316. /**
  3317. * snd_soc_register_platform - Register a platform with the ASoC core
  3318. *
  3319. * @platform: platform to register
  3320. */
  3321. int snd_soc_register_platform(struct device *dev,
  3322. struct snd_soc_platform_driver *platform_drv)
  3323. {
  3324. struct snd_soc_platform *platform;
  3325. dev_dbg(dev, "ASoC: platform register %s\n", dev_name(dev));
  3326. platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
  3327. if (platform == NULL)
  3328. return -ENOMEM;
  3329. /* create platform component name */
  3330. platform->name = fmt_single_name(dev, &platform->id);
  3331. if (platform->name == NULL) {
  3332. kfree(platform);
  3333. return -ENOMEM;
  3334. }
  3335. platform->dev = dev;
  3336. platform->driver = platform_drv;
  3337. platform->dapm.dev = dev;
  3338. platform->dapm.platform = platform;
  3339. platform->dapm.stream_event = platform_drv->stream_event;
  3340. mutex_init(&platform->mutex);
  3341. mutex_lock(&client_mutex);
  3342. list_add(&platform->list, &platform_list);
  3343. mutex_unlock(&client_mutex);
  3344. dev_dbg(dev, "ASoC: Registered platform '%s'\n", platform->name);
  3345. return 0;
  3346. }
  3347. EXPORT_SYMBOL_GPL(snd_soc_register_platform);
  3348. /**
  3349. * snd_soc_unregister_platform - Unregister a platform from the ASoC core
  3350. *
  3351. * @platform: platform to unregister
  3352. */
  3353. void snd_soc_unregister_platform(struct device *dev)
  3354. {
  3355. struct snd_soc_platform *platform;
  3356. list_for_each_entry(platform, &platform_list, list) {
  3357. if (dev == platform->dev)
  3358. goto found;
  3359. }
  3360. return;
  3361. found:
  3362. mutex_lock(&client_mutex);
  3363. list_del(&platform->list);
  3364. mutex_unlock(&client_mutex);
  3365. dev_dbg(dev, "ASoC: Unregistered platform '%s'\n", platform->name);
  3366. kfree(platform->name);
  3367. kfree(platform);
  3368. }
  3369. EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
  3370. static u64 codec_format_map[] = {
  3371. SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
  3372. SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
  3373. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
  3374. SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
  3375. SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
  3376. SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
  3377. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
  3378. SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
  3379. SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
  3380. SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
  3381. SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
  3382. SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
  3383. SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
  3384. SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
  3385. SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
  3386. | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
  3387. };
  3388. /* Fix up the DAI formats for endianness: codecs don't actually see
  3389. * the endianness of the data but we're using the CPU format
  3390. * definitions which do need to include endianness so we ensure that
  3391. * codec DAIs always have both big and little endian variants set.
  3392. */
  3393. static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
  3394. {
  3395. int i;
  3396. for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
  3397. if (stream->formats & codec_format_map[i])
  3398. stream->formats |= codec_format_map[i];
  3399. }
  3400. /**
  3401. * snd_soc_register_codec - Register a codec with the ASoC core
  3402. *
  3403. * @codec: codec to register
  3404. */
  3405. int snd_soc_register_codec(struct device *dev,
  3406. const struct snd_soc_codec_driver *codec_drv,
  3407. struct snd_soc_dai_driver *dai_drv,
  3408. int num_dai)
  3409. {
  3410. size_t reg_size;
  3411. struct snd_soc_codec *codec;
  3412. int ret, i;
  3413. dev_dbg(dev, "codec register %s\n", dev_name(dev));
  3414. codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
  3415. if (codec == NULL)
  3416. return -ENOMEM;
  3417. /* create CODEC component name */
  3418. codec->name = fmt_single_name(dev, &codec->id);
  3419. if (codec->name == NULL) {
  3420. kfree(codec);
  3421. return -ENOMEM;
  3422. }
  3423. if (codec_drv->compress_type)
  3424. codec->compress_type = codec_drv->compress_type;
  3425. else
  3426. codec->compress_type = SND_SOC_FLAT_COMPRESSION;
  3427. codec->write = codec_drv->write;
  3428. codec->read = codec_drv->read;
  3429. codec->volatile_register = codec_drv->volatile_register;
  3430. codec->readable_register = codec_drv->readable_register;
  3431. codec->writable_register = codec_drv->writable_register;
  3432. codec->ignore_pmdown_time = codec_drv->ignore_pmdown_time;
  3433. codec->dapm.bias_level = SND_SOC_BIAS_OFF;
  3434. codec->dapm.dev = dev;
  3435. codec->dapm.codec = codec;
  3436. codec->dapm.seq_notifier = codec_drv->seq_notifier;
  3437. codec->dapm.stream_event = codec_drv->stream_event;
  3438. codec->dev = dev;
  3439. codec->driver = codec_drv;
  3440. codec->num_dai = num_dai;
  3441. mutex_init(&codec->mutex);
  3442. /* allocate CODEC register cache */
  3443. if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
  3444. reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
  3445. codec->reg_size = reg_size;
  3446. /* it is necessary to make a copy of the default register cache
  3447. * because in the case of using a compression type that requires
  3448. * the default register cache to be marked as the
  3449. * kernel might have freed the array by the time we initialize
  3450. * the cache.
  3451. */
  3452. if (codec_drv->reg_cache_default) {
  3453. codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
  3454. reg_size, GFP_KERNEL);
  3455. if (!codec->reg_def_copy) {
  3456. ret = -ENOMEM;
  3457. goto fail;
  3458. }
  3459. }
  3460. }
  3461. if (codec_drv->reg_access_size && codec_drv->reg_access_default) {
  3462. if (!codec->volatile_register)
  3463. codec->volatile_register = snd_soc_default_volatile_register;
  3464. if (!codec->readable_register)
  3465. codec->readable_register = snd_soc_default_readable_register;
  3466. if (!codec->writable_register)
  3467. codec->writable_register = snd_soc_default_writable_register;
  3468. }
  3469. for (i = 0; i < num_dai; i++) {
  3470. fixup_codec_formats(&dai_drv[i].playback);
  3471. fixup_codec_formats(&dai_drv[i].capture);
  3472. }
  3473. mutex_lock(&client_mutex);
  3474. list_add(&codec->list, &codec_list);
  3475. mutex_unlock(&client_mutex);
  3476. /* register any DAIs */
  3477. if (num_dai) {
  3478. ret = snd_soc_register_dais(dev, dai_drv, num_dai);
  3479. if (ret < 0)
  3480. dev_err(codec->dev, "ASoC: Failed to regster"
  3481. " DAIs: %d\n", ret);
  3482. }
  3483. dev_dbg(codec->dev, "ASoC: Registered codec '%s'\n", codec->name);
  3484. return 0;
  3485. fail:
  3486. kfree(codec->name);
  3487. kfree(codec);
  3488. return ret;
  3489. }
  3490. EXPORT_SYMBOL_GPL(snd_soc_register_codec);
  3491. /**
  3492. * snd_soc_unregister_codec - Unregister a codec from the ASoC core
  3493. *
  3494. * @codec: codec to unregister
  3495. */
  3496. void snd_soc_unregister_codec(struct device *dev)
  3497. {
  3498. struct snd_soc_codec *codec;
  3499. int i;
  3500. list_for_each_entry(codec, &codec_list, list) {
  3501. if (dev == codec->dev)
  3502. goto found;
  3503. }
  3504. return;
  3505. found:
  3506. if (codec->num_dai)
  3507. for (i = 0; i < codec->num_dai; i++)
  3508. snd_soc_unregister_dai(dev);
  3509. mutex_lock(&client_mutex);
  3510. list_del(&codec->list);
  3511. mutex_unlock(&client_mutex);
  3512. dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", codec->name);
  3513. snd_soc_cache_exit(codec);
  3514. kfree(codec->reg_def_copy);
  3515. kfree(codec->name);
  3516. kfree(codec);
  3517. }
  3518. EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
  3519. /* Retrieve a card's name from device tree */
  3520. int snd_soc_of_parse_card_name(struct snd_soc_card *card,
  3521. const char *propname)
  3522. {
  3523. struct device_node *np = card->dev->of_node;
  3524. int ret;
  3525. ret = of_property_read_string_index(np, propname, 0, &card->name);
  3526. /*
  3527. * EINVAL means the property does not exist. This is fine providing
  3528. * card->name was previously set, which is checked later in
  3529. * snd_soc_register_card.
  3530. */
  3531. if (ret < 0 && ret != -EINVAL) {
  3532. dev_err(card->dev,
  3533. "ASoC: Property '%s' could not be read: %d\n",
  3534. propname, ret);
  3535. return ret;
  3536. }
  3537. return 0;
  3538. }
  3539. EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
  3540. int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
  3541. const char *propname)
  3542. {
  3543. struct device_node *np = card->dev->of_node;
  3544. int num_routes;
  3545. struct snd_soc_dapm_route *routes;
  3546. int i, ret;
  3547. num_routes = of_property_count_strings(np, propname);
  3548. if (num_routes < 0 || num_routes & 1) {
  3549. dev_err(card->dev, "ASoC: Property '%s' does not exist or its"
  3550. " length is not even\n", propname);
  3551. return -EINVAL;
  3552. }
  3553. num_routes /= 2;
  3554. if (!num_routes) {
  3555. dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
  3556. propname);
  3557. return -EINVAL;
  3558. }
  3559. routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes),
  3560. GFP_KERNEL);
  3561. if (!routes) {
  3562. dev_err(card->dev,
  3563. "ASoC: Could not allocate DAPM route table\n");
  3564. return -EINVAL;
  3565. }
  3566. for (i = 0; i < num_routes; i++) {
  3567. ret = of_property_read_string_index(np, propname,
  3568. 2 * i, &routes[i].sink);
  3569. if (ret) {
  3570. dev_err(card->dev,
  3571. "ASoC: Property '%s' index %d could not be read: %d\n",
  3572. propname, 2 * i, ret);
  3573. kfree(routes);
  3574. return -EINVAL;
  3575. }
  3576. ret = of_property_read_string_index(np, propname,
  3577. (2 * i) + 1, &routes[i].source);
  3578. if (ret) {
  3579. dev_err(card->dev,
  3580. "ASoC: Property '%s' index %d could not be read: %d\n",
  3581. propname, (2 * i) + 1, ret);
  3582. kfree(routes);
  3583. return -EINVAL;
  3584. }
  3585. }
  3586. card->num_dapm_routes = num_routes;
  3587. card->dapm_routes = routes;
  3588. return 0;
  3589. }
  3590. EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
  3591. static int __init snd_soc_init(void)
  3592. {
  3593. #ifdef CONFIG_DEBUG_FS
  3594. snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
  3595. if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
  3596. pr_warn("ASoC: Failed to create debugfs directory\n");
  3597. snd_soc_debugfs_root = NULL;
  3598. }
  3599. if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
  3600. &codec_list_fops))
  3601. pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
  3602. if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
  3603. &dai_list_fops))
  3604. pr_warn("ASoC: Failed to create DAI list debugfs file\n");
  3605. if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
  3606. &platform_list_fops))
  3607. pr_warn("ASoC: Failed to create platform list debugfs file\n");
  3608. #endif
  3609. snd_soc_util_init();
  3610. return platform_driver_register(&soc_driver);
  3611. }
  3612. module_init(snd_soc_init);
  3613. static void __exit snd_soc_exit(void)
  3614. {
  3615. snd_soc_util_exit();
  3616. #ifdef CONFIG_DEBUG_FS
  3617. debugfs_remove_recursive(snd_soc_debugfs_root);
  3618. #endif
  3619. platform_driver_unregister(&soc_driver);
  3620. }
  3621. module_exit(snd_soc_exit);
  3622. /* Module information */
  3623. MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
  3624. MODULE_DESCRIPTION("ALSA SoC Core");
  3625. MODULE_LICENSE("GPL");
  3626. MODULE_ALIAS("platform:soc-audio");