soc-core.c 93 KB

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