soc-core.c 94 KB

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