soc-core.c 94 KB

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