soc-core.c 94 KB

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