soc-core.c 93 KB

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