soc-core.c 108 KB

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