soc-core.c 93 KB

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