soc-core.c 93 KB

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