soc-core.c 94 KB

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