wm8995.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416
  1. /*
  2. * wm8995.c -- WM8995 ALSA SoC Audio driver
  3. *
  4. * Copyright 2010 Wolfson Microelectronics plc
  5. *
  6. * Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
  7. *
  8. * Based on wm8994.c and wm_hubs.c by Mark Brown
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/moduleparam.h>
  16. #include <linux/init.h>
  17. #include <linux/delay.h>
  18. #include <linux/pm.h>
  19. #include <linux/i2c.h>
  20. #include <linux/regmap.h>
  21. #include <linux/spi/spi.h>
  22. #include <linux/regulator/consumer.h>
  23. #include <linux/slab.h>
  24. #include <sound/core.h>
  25. #include <sound/pcm.h>
  26. #include <sound/pcm_params.h>
  27. #include <sound/soc.h>
  28. #include <sound/soc-dapm.h>
  29. #include <sound/initval.h>
  30. #include <sound/tlv.h>
  31. #include "wm8995.h"
  32. #define WM8995_NUM_SUPPLIES 8
  33. static const char *wm8995_supply_names[WM8995_NUM_SUPPLIES] = {
  34. "DCVDD",
  35. "DBVDD1",
  36. "DBVDD2",
  37. "DBVDD3",
  38. "AVDD1",
  39. "AVDD2",
  40. "CPVDD",
  41. "MICVDD"
  42. };
  43. static struct reg_default wm8995_reg_defaults[] = {
  44. { 0, 0x8995 },
  45. { 5, 0x0100 },
  46. { 16, 0x000b },
  47. { 17, 0x000b },
  48. { 24, 0x02c0 },
  49. { 25, 0x02c0 },
  50. { 26, 0x02c0 },
  51. { 27, 0x02c0 },
  52. { 28, 0x000f },
  53. { 32, 0x0005 },
  54. { 33, 0x0005 },
  55. { 40, 0x0003 },
  56. { 41, 0x0013 },
  57. { 48, 0x0004 },
  58. { 56, 0x09f8 },
  59. { 64, 0x1f25 },
  60. { 69, 0x0004 },
  61. { 82, 0xaaaa },
  62. { 84, 0x2a2a },
  63. { 146, 0x0060 },
  64. { 256, 0x0002 },
  65. { 257, 0x8004 },
  66. { 520, 0x0010 },
  67. { 528, 0x0083 },
  68. { 529, 0x0083 },
  69. { 548, 0x0c80 },
  70. { 580, 0x0c80 },
  71. { 768, 0x4050 },
  72. { 769, 0x4000 },
  73. { 771, 0x0040 },
  74. { 772, 0x0040 },
  75. { 773, 0x0040 },
  76. { 774, 0x0004 },
  77. { 775, 0x0100 },
  78. { 784, 0x4050 },
  79. { 785, 0x4000 },
  80. { 787, 0x0040 },
  81. { 788, 0x0040 },
  82. { 789, 0x0040 },
  83. { 1024, 0x00c0 },
  84. { 1025, 0x00c0 },
  85. { 1026, 0x00c0 },
  86. { 1027, 0x00c0 },
  87. { 1028, 0x00c0 },
  88. { 1029, 0x00c0 },
  89. { 1030, 0x00c0 },
  90. { 1031, 0x00c0 },
  91. { 1056, 0x0200 },
  92. { 1057, 0x0010 },
  93. { 1058, 0x0200 },
  94. { 1059, 0x0010 },
  95. { 1088, 0x0098 },
  96. { 1089, 0x0845 },
  97. { 1104, 0x0098 },
  98. { 1105, 0x0845 },
  99. { 1152, 0x6318 },
  100. { 1153, 0x6300 },
  101. { 1154, 0x0fca },
  102. { 1155, 0x0400 },
  103. { 1156, 0x00d8 },
  104. { 1157, 0x1eb5 },
  105. { 1158, 0xf145 },
  106. { 1159, 0x0b75 },
  107. { 1160, 0x01c5 },
  108. { 1161, 0x1c58 },
  109. { 1162, 0xf373 },
  110. { 1163, 0x0a54 },
  111. { 1164, 0x0558 },
  112. { 1165, 0x168e },
  113. { 1166, 0xf829 },
  114. { 1167, 0x07ad },
  115. { 1168, 0x1103 },
  116. { 1169, 0x0564 },
  117. { 1170, 0x0559 },
  118. { 1171, 0x4000 },
  119. { 1184, 0x6318 },
  120. { 1185, 0x6300 },
  121. { 1186, 0x0fca },
  122. { 1187, 0x0400 },
  123. { 1188, 0x00d8 },
  124. { 1189, 0x1eb5 },
  125. { 1190, 0xf145 },
  126. { 1191, 0x0b75 },
  127. { 1192, 0x01c5 },
  128. { 1193, 0x1c58 },
  129. { 1194, 0xf373 },
  130. { 1195, 0x0a54 },
  131. { 1196, 0x0558 },
  132. { 1197, 0x168e },
  133. { 1198, 0xf829 },
  134. { 1199, 0x07ad },
  135. { 1200, 0x1103 },
  136. { 1201, 0x0564 },
  137. { 1202, 0x0559 },
  138. { 1203, 0x4000 },
  139. { 1280, 0x00c0 },
  140. { 1281, 0x00c0 },
  141. { 1282, 0x00c0 },
  142. { 1283, 0x00c0 },
  143. { 1312, 0x0200 },
  144. { 1313, 0x0010 },
  145. { 1344, 0x0098 },
  146. { 1345, 0x0845 },
  147. { 1408, 0x6318 },
  148. { 1409, 0x6300 },
  149. { 1410, 0x0fca },
  150. { 1411, 0x0400 },
  151. { 1412, 0x00d8 },
  152. { 1413, 0x1eb5 },
  153. { 1414, 0xf145 },
  154. { 1415, 0x0b75 },
  155. { 1416, 0x01c5 },
  156. { 1417, 0x1c58 },
  157. { 1418, 0xf373 },
  158. { 1419, 0x0a54 },
  159. { 1420, 0x0558 },
  160. { 1421, 0x168e },
  161. { 1422, 0xf829 },
  162. { 1423, 0x07ad },
  163. { 1424, 0x1103 },
  164. { 1425, 0x0564 },
  165. { 1426, 0x0559 },
  166. { 1427, 0x4000 },
  167. { 1568, 0x0002 },
  168. { 1792, 0xa100 },
  169. { 1793, 0xa101 },
  170. { 1794, 0xa101 },
  171. { 1795, 0xa101 },
  172. { 1796, 0xa101 },
  173. { 1797, 0xa101 },
  174. { 1798, 0xa101 },
  175. { 1799, 0xa101 },
  176. { 1800, 0xa101 },
  177. { 1801, 0xa101 },
  178. { 1802, 0xa101 },
  179. { 1803, 0xa101 },
  180. { 1804, 0xa101 },
  181. { 1805, 0xa101 },
  182. { 1825, 0x0055 },
  183. { 1848, 0x3fff },
  184. { 1849, 0x1fff },
  185. { 2049, 0x0001 },
  186. { 2050, 0x0069 },
  187. { 2056, 0x0002 },
  188. { 2057, 0x0003 },
  189. { 2058, 0x0069 },
  190. { 12288, 0x0001 },
  191. { 12289, 0x0001 },
  192. { 12291, 0x0006 },
  193. { 12292, 0x0040 },
  194. { 12293, 0x0001 },
  195. { 12294, 0x000f },
  196. { 12295, 0x0006 },
  197. { 12296, 0x0001 },
  198. { 12297, 0x0003 },
  199. { 12298, 0x0104 },
  200. { 12300, 0x0060 },
  201. { 12301, 0x0011 },
  202. { 12302, 0x0401 },
  203. { 12304, 0x0050 },
  204. { 12305, 0x0003 },
  205. { 12306, 0x0100 },
  206. { 12308, 0x0051 },
  207. { 12309, 0x0003 },
  208. { 12310, 0x0104 },
  209. { 12311, 0x000a },
  210. { 12312, 0x0060 },
  211. { 12313, 0x003b },
  212. { 12314, 0x0502 },
  213. { 12315, 0x0100 },
  214. { 12316, 0x2fff },
  215. { 12320, 0x2fff },
  216. { 12324, 0x2fff },
  217. { 12328, 0x2fff },
  218. { 12332, 0x2fff },
  219. { 12336, 0x2fff },
  220. { 12340, 0x2fff },
  221. { 12344, 0x2fff },
  222. { 12348, 0x2fff },
  223. { 12352, 0x0001 },
  224. { 12353, 0x0001 },
  225. { 12355, 0x0006 },
  226. { 12356, 0x0040 },
  227. { 12357, 0x0001 },
  228. { 12358, 0x000f },
  229. { 12359, 0x0006 },
  230. { 12360, 0x0001 },
  231. { 12361, 0x0003 },
  232. { 12362, 0x0104 },
  233. { 12364, 0x0060 },
  234. { 12365, 0x0011 },
  235. { 12366, 0x0401 },
  236. { 12368, 0x0050 },
  237. { 12369, 0x0003 },
  238. { 12370, 0x0100 },
  239. { 12372, 0x0060 },
  240. { 12373, 0x003b },
  241. { 12374, 0x0502 },
  242. { 12375, 0x0100 },
  243. { 12376, 0x2fff },
  244. { 12380, 0x2fff },
  245. { 12384, 0x2fff },
  246. { 12388, 0x2fff },
  247. { 12392, 0x2fff },
  248. { 12396, 0x2fff },
  249. { 12400, 0x2fff },
  250. { 12404, 0x2fff },
  251. { 12408, 0x2fff },
  252. { 12412, 0x2fff },
  253. { 12416, 0x0001 },
  254. { 12417, 0x0001 },
  255. { 12419, 0x0006 },
  256. { 12420, 0x0040 },
  257. { 12421, 0x0001 },
  258. { 12422, 0x000f },
  259. { 12423, 0x0006 },
  260. { 12424, 0x0001 },
  261. { 12425, 0x0003 },
  262. { 12426, 0x0106 },
  263. { 12428, 0x0061 },
  264. { 12429, 0x0011 },
  265. { 12430, 0x0401 },
  266. { 12432, 0x0050 },
  267. { 12433, 0x0003 },
  268. { 12434, 0x0102 },
  269. { 12436, 0x0051 },
  270. { 12437, 0x0003 },
  271. { 12438, 0x0106 },
  272. { 12439, 0x000a },
  273. { 12440, 0x0061 },
  274. { 12441, 0x003b },
  275. { 12442, 0x0502 },
  276. { 12443, 0x0100 },
  277. { 12444, 0x2fff },
  278. { 12448, 0x2fff },
  279. { 12452, 0x2fff },
  280. { 12456, 0x2fff },
  281. { 12460, 0x2fff },
  282. { 12464, 0x2fff },
  283. { 12468, 0x2fff },
  284. { 12472, 0x2fff },
  285. { 12476, 0x2fff },
  286. { 12480, 0x0001 },
  287. { 12481, 0x0001 },
  288. { 12483, 0x0006 },
  289. { 12484, 0x0040 },
  290. { 12485, 0x0001 },
  291. { 12486, 0x000f },
  292. { 12487, 0x0006 },
  293. { 12488, 0x0001 },
  294. { 12489, 0x0003 },
  295. { 12490, 0x0106 },
  296. { 12492, 0x0061 },
  297. { 12493, 0x0011 },
  298. { 12494, 0x0401 },
  299. { 12496, 0x0050 },
  300. { 12497, 0x0003 },
  301. { 12498, 0x0102 },
  302. { 12500, 0x0061 },
  303. { 12501, 0x003b },
  304. { 12502, 0x0502 },
  305. { 12503, 0x0100 },
  306. { 12504, 0x2fff },
  307. { 12508, 0x2fff },
  308. { 12512, 0x2fff },
  309. { 12516, 0x2fff },
  310. { 12520, 0x2fff },
  311. { 12524, 0x2fff },
  312. { 12528, 0x2fff },
  313. { 12532, 0x2fff },
  314. { 12536, 0x2fff },
  315. { 12540, 0x2fff },
  316. { 12544, 0x0060 },
  317. { 12546, 0x0601 },
  318. { 12548, 0x0050 },
  319. { 12550, 0x0100 },
  320. { 12552, 0x0001 },
  321. { 12554, 0x0104 },
  322. { 12555, 0x0100 },
  323. { 12556, 0x2fff },
  324. { 12560, 0x2fff },
  325. { 12564, 0x2fff },
  326. { 12568, 0x2fff },
  327. { 12572, 0x2fff },
  328. { 12576, 0x2fff },
  329. { 12580, 0x2fff },
  330. { 12584, 0x2fff },
  331. { 12588, 0x2fff },
  332. { 12592, 0x2fff },
  333. { 12596, 0x2fff },
  334. { 12600, 0x2fff },
  335. { 12604, 0x2fff },
  336. { 12608, 0x0061 },
  337. { 12610, 0x0601 },
  338. { 12612, 0x0050 },
  339. { 12614, 0x0102 },
  340. { 12616, 0x0001 },
  341. { 12618, 0x0106 },
  342. { 12619, 0x0100 },
  343. { 12620, 0x2fff },
  344. { 12624, 0x2fff },
  345. { 12628, 0x2fff },
  346. { 12632, 0x2fff },
  347. { 12636, 0x2fff },
  348. { 12640, 0x2fff },
  349. { 12644, 0x2fff },
  350. { 12648, 0x2fff },
  351. { 12652, 0x2fff },
  352. { 12656, 0x2fff },
  353. { 12660, 0x2fff },
  354. { 12664, 0x2fff },
  355. { 12668, 0x2fff },
  356. { 12672, 0x0060 },
  357. { 12674, 0x0601 },
  358. { 12676, 0x0061 },
  359. { 12678, 0x0601 },
  360. { 12680, 0x0050 },
  361. { 12682, 0x0300 },
  362. { 12684, 0x0001 },
  363. { 12686, 0x0304 },
  364. { 12688, 0x0040 },
  365. { 12690, 0x000f },
  366. { 12692, 0x0001 },
  367. { 12695, 0x0100 },
  368. };
  369. struct fll_config {
  370. int src;
  371. int in;
  372. int out;
  373. };
  374. struct wm8995_priv {
  375. struct regmap *regmap;
  376. int sysclk[2];
  377. int mclk[2];
  378. int aifclk[2];
  379. struct fll_config fll[2], fll_suspend[2];
  380. struct regulator_bulk_data supplies[WM8995_NUM_SUPPLIES];
  381. struct notifier_block disable_nb[WM8995_NUM_SUPPLIES];
  382. struct snd_soc_codec *codec;
  383. };
  384. /*
  385. * We can't use the same notifier block for more than one supply and
  386. * there's no way I can see to get from a callback to the caller
  387. * except container_of().
  388. */
  389. #define WM8995_REGULATOR_EVENT(n) \
  390. static int wm8995_regulator_event_##n(struct notifier_block *nb, \
  391. unsigned long event, void *data) \
  392. { \
  393. struct wm8995_priv *wm8995 = container_of(nb, struct wm8995_priv, \
  394. disable_nb[n]); \
  395. if (event & REGULATOR_EVENT_DISABLE) { \
  396. regcache_mark_dirty(wm8995->regmap); \
  397. } \
  398. return 0; \
  399. }
  400. WM8995_REGULATOR_EVENT(0)
  401. WM8995_REGULATOR_EVENT(1)
  402. WM8995_REGULATOR_EVENT(2)
  403. WM8995_REGULATOR_EVENT(3)
  404. WM8995_REGULATOR_EVENT(4)
  405. WM8995_REGULATOR_EVENT(5)
  406. WM8995_REGULATOR_EVENT(6)
  407. WM8995_REGULATOR_EVENT(7)
  408. static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
  409. static const DECLARE_TLV_DB_SCALE(in1lr_pga_tlv, -1650, 150, 0);
  410. static const DECLARE_TLV_DB_SCALE(in1l_boost_tlv, 0, 600, 0);
  411. static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -3600, 150, 0);
  412. static const char *in1l_text[] = {
  413. "Differential", "Single-ended IN1LN", "Single-ended IN1LP"
  414. };
  415. static const SOC_ENUM_SINGLE_DECL(in1l_enum, WM8995_LEFT_LINE_INPUT_CONTROL,
  416. 2, in1l_text);
  417. static const char *in1r_text[] = {
  418. "Differential", "Single-ended IN1RN", "Single-ended IN1RP"
  419. };
  420. static const SOC_ENUM_SINGLE_DECL(in1r_enum, WM8995_LEFT_LINE_INPUT_CONTROL,
  421. 0, in1r_text);
  422. static const char *dmic_src_text[] = {
  423. "DMICDAT1", "DMICDAT2", "DMICDAT3"
  424. };
  425. static const SOC_ENUM_SINGLE_DECL(dmic_src1_enum, WM8995_POWER_MANAGEMENT_5,
  426. 8, dmic_src_text);
  427. static const SOC_ENUM_SINGLE_DECL(dmic_src2_enum, WM8995_POWER_MANAGEMENT_5,
  428. 6, dmic_src_text);
  429. static const struct snd_kcontrol_new wm8995_snd_controls[] = {
  430. SOC_DOUBLE_R_TLV("DAC1 Volume", WM8995_DAC1_LEFT_VOLUME,
  431. WM8995_DAC1_RIGHT_VOLUME, 0, 96, 0, digital_tlv),
  432. SOC_DOUBLE_R("DAC1 Switch", WM8995_DAC1_LEFT_VOLUME,
  433. WM8995_DAC1_RIGHT_VOLUME, 9, 1, 1),
  434. SOC_DOUBLE_R_TLV("DAC2 Volume", WM8995_DAC2_LEFT_VOLUME,
  435. WM8995_DAC2_RIGHT_VOLUME, 0, 96, 0, digital_tlv),
  436. SOC_DOUBLE_R("DAC2 Switch", WM8995_DAC2_LEFT_VOLUME,
  437. WM8995_DAC2_RIGHT_VOLUME, 9, 1, 1),
  438. SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8995_AIF1_DAC1_LEFT_VOLUME,
  439. WM8995_AIF1_DAC1_RIGHT_VOLUME, 0, 96, 0, digital_tlv),
  440. SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8995_AIF1_DAC2_LEFT_VOLUME,
  441. WM8995_AIF1_DAC2_RIGHT_VOLUME, 0, 96, 0, digital_tlv),
  442. SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8995_AIF2_DAC_LEFT_VOLUME,
  443. WM8995_AIF2_DAC_RIGHT_VOLUME, 0, 96, 0, digital_tlv),
  444. SOC_DOUBLE_R_TLV("IN1LR Volume", WM8995_LEFT_LINE_INPUT_1_VOLUME,
  445. WM8995_RIGHT_LINE_INPUT_1_VOLUME, 0, 31, 0, in1lr_pga_tlv),
  446. SOC_SINGLE_TLV("IN1L Boost", WM8995_LEFT_LINE_INPUT_CONTROL,
  447. 4, 3, 0, in1l_boost_tlv),
  448. SOC_ENUM("IN1L Mode", in1l_enum),
  449. SOC_ENUM("IN1R Mode", in1r_enum),
  450. SOC_ENUM("DMIC1 SRC", dmic_src1_enum),
  451. SOC_ENUM("DMIC2 SRC", dmic_src2_enum),
  452. SOC_DOUBLE_TLV("DAC1 Sidetone Volume", WM8995_DAC1_MIXER_VOLUMES, 0, 5,
  453. 24, 0, sidetone_tlv),
  454. SOC_DOUBLE_TLV("DAC2 Sidetone Volume", WM8995_DAC2_MIXER_VOLUMES, 0, 5,
  455. 24, 0, sidetone_tlv),
  456. SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8995_AIF1_ADC1_LEFT_VOLUME,
  457. WM8995_AIF1_ADC1_RIGHT_VOLUME, 0, 96, 0, digital_tlv),
  458. SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8995_AIF1_ADC2_LEFT_VOLUME,
  459. WM8995_AIF1_ADC2_RIGHT_VOLUME, 0, 96, 0, digital_tlv),
  460. SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8995_AIF2_ADC_LEFT_VOLUME,
  461. WM8995_AIF2_ADC_RIGHT_VOLUME, 0, 96, 0, digital_tlv)
  462. };
  463. static void wm8995_update_class_w(struct snd_soc_codec *codec)
  464. {
  465. int enable = 1;
  466. int source = 0; /* GCC flow analysis can't track enable */
  467. int reg, reg_r;
  468. /* We also need the same setting for L/R and only one path */
  469. reg = snd_soc_read(codec, WM8995_DAC1_LEFT_MIXER_ROUTING);
  470. switch (reg) {
  471. case WM8995_AIF2DACL_TO_DAC1L:
  472. dev_dbg(codec->dev, "Class W source AIF2DAC\n");
  473. source = 2 << WM8995_CP_DYN_SRC_SEL_SHIFT;
  474. break;
  475. case WM8995_AIF1DAC2L_TO_DAC1L:
  476. dev_dbg(codec->dev, "Class W source AIF1DAC2\n");
  477. source = 1 << WM8995_CP_DYN_SRC_SEL_SHIFT;
  478. break;
  479. case WM8995_AIF1DAC1L_TO_DAC1L:
  480. dev_dbg(codec->dev, "Class W source AIF1DAC1\n");
  481. source = 0 << WM8995_CP_DYN_SRC_SEL_SHIFT;
  482. break;
  483. default:
  484. dev_dbg(codec->dev, "DAC mixer setting: %x\n", reg);
  485. enable = 0;
  486. break;
  487. }
  488. reg_r = snd_soc_read(codec, WM8995_DAC1_RIGHT_MIXER_ROUTING);
  489. if (reg_r != reg) {
  490. dev_dbg(codec->dev, "Left and right DAC mixers different\n");
  491. enable = 0;
  492. }
  493. if (enable) {
  494. dev_dbg(codec->dev, "Class W enabled\n");
  495. snd_soc_update_bits(codec, WM8995_CLASS_W_1,
  496. WM8995_CP_DYN_PWR_MASK |
  497. WM8995_CP_DYN_SRC_SEL_MASK,
  498. source | WM8995_CP_DYN_PWR);
  499. } else {
  500. dev_dbg(codec->dev, "Class W disabled\n");
  501. snd_soc_update_bits(codec, WM8995_CLASS_W_1,
  502. WM8995_CP_DYN_PWR_MASK, 0);
  503. }
  504. }
  505. static int check_clk_sys(struct snd_soc_dapm_widget *source,
  506. struct snd_soc_dapm_widget *sink)
  507. {
  508. unsigned int reg;
  509. const char *clk;
  510. reg = snd_soc_read(source->codec, WM8995_CLOCKING_1);
  511. /* Check what we're currently using for CLK_SYS */
  512. if (reg & WM8995_SYSCLK_SRC)
  513. clk = "AIF2CLK";
  514. else
  515. clk = "AIF1CLK";
  516. return !strcmp(source->name, clk);
  517. }
  518. static int wm8995_put_class_w(struct snd_kcontrol *kcontrol,
  519. struct snd_ctl_elem_value *ucontrol)
  520. {
  521. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  522. struct snd_soc_dapm_widget *w = wlist->widgets[0];
  523. struct snd_soc_codec *codec;
  524. int ret;
  525. codec = w->codec;
  526. ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
  527. wm8995_update_class_w(codec);
  528. return ret;
  529. }
  530. static int hp_supply_event(struct snd_soc_dapm_widget *w,
  531. struct snd_kcontrol *kcontrol, int event)
  532. {
  533. struct snd_soc_codec *codec;
  534. struct wm8995_priv *wm8995;
  535. codec = w->codec;
  536. wm8995 = snd_soc_codec_get_drvdata(codec);
  537. switch (event) {
  538. case SND_SOC_DAPM_PRE_PMU:
  539. /* Enable the headphone amp */
  540. snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1,
  541. WM8995_HPOUT1L_ENA_MASK |
  542. WM8995_HPOUT1R_ENA_MASK,
  543. WM8995_HPOUT1L_ENA |
  544. WM8995_HPOUT1R_ENA);
  545. /* Enable the second stage */
  546. snd_soc_update_bits(codec, WM8995_ANALOGUE_HP_1,
  547. WM8995_HPOUT1L_DLY_MASK |
  548. WM8995_HPOUT1R_DLY_MASK,
  549. WM8995_HPOUT1L_DLY |
  550. WM8995_HPOUT1R_DLY);
  551. break;
  552. case SND_SOC_DAPM_PRE_PMD:
  553. snd_soc_update_bits(codec, WM8995_CHARGE_PUMP_1,
  554. WM8995_CP_ENA_MASK, 0);
  555. break;
  556. }
  557. return 0;
  558. }
  559. static void dc_servo_cmd(struct snd_soc_codec *codec,
  560. unsigned int reg, unsigned int val, unsigned int mask)
  561. {
  562. int timeout = 10;
  563. dev_dbg(codec->dev, "%s: reg = %#x, val = %#x, mask = %#x\n",
  564. __func__, reg, val, mask);
  565. snd_soc_write(codec, reg, val);
  566. while (timeout--) {
  567. msleep(10);
  568. val = snd_soc_read(codec, WM8995_DC_SERVO_READBACK_0);
  569. if ((val & mask) == mask)
  570. return;
  571. }
  572. dev_err(codec->dev, "Timed out waiting for DC Servo\n");
  573. }
  574. static int hp_event(struct snd_soc_dapm_widget *w,
  575. struct snd_kcontrol *kcontrol, int event)
  576. {
  577. struct snd_soc_codec *codec;
  578. unsigned int reg;
  579. codec = w->codec;
  580. reg = snd_soc_read(codec, WM8995_ANALOGUE_HP_1);
  581. switch (event) {
  582. case SND_SOC_DAPM_POST_PMU:
  583. snd_soc_update_bits(codec, WM8995_CHARGE_PUMP_1,
  584. WM8995_CP_ENA_MASK, WM8995_CP_ENA);
  585. msleep(5);
  586. snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1,
  587. WM8995_HPOUT1L_ENA_MASK |
  588. WM8995_HPOUT1R_ENA_MASK,
  589. WM8995_HPOUT1L_ENA | WM8995_HPOUT1R_ENA);
  590. udelay(20);
  591. reg |= WM8995_HPOUT1L_DLY | WM8995_HPOUT1R_DLY;
  592. snd_soc_write(codec, WM8995_ANALOGUE_HP_1, reg);
  593. snd_soc_write(codec, WM8995_DC_SERVO_1, WM8995_DCS_ENA_CHAN_0 |
  594. WM8995_DCS_ENA_CHAN_1);
  595. dc_servo_cmd(codec, WM8995_DC_SERVO_2,
  596. WM8995_DCS_TRIG_STARTUP_0 |
  597. WM8995_DCS_TRIG_STARTUP_1,
  598. WM8995_DCS_TRIG_DAC_WR_0 |
  599. WM8995_DCS_TRIG_DAC_WR_1);
  600. reg |= WM8995_HPOUT1R_OUTP | WM8995_HPOUT1R_RMV_SHORT |
  601. WM8995_HPOUT1L_OUTP | WM8995_HPOUT1L_RMV_SHORT;
  602. snd_soc_write(codec, WM8995_ANALOGUE_HP_1, reg);
  603. break;
  604. case SND_SOC_DAPM_PRE_PMD:
  605. snd_soc_update_bits(codec, WM8995_ANALOGUE_HP_1,
  606. WM8995_HPOUT1L_OUTP_MASK |
  607. WM8995_HPOUT1R_OUTP_MASK |
  608. WM8995_HPOUT1L_RMV_SHORT_MASK |
  609. WM8995_HPOUT1R_RMV_SHORT_MASK, 0);
  610. snd_soc_update_bits(codec, WM8995_ANALOGUE_HP_1,
  611. WM8995_HPOUT1L_DLY_MASK |
  612. WM8995_HPOUT1R_DLY_MASK, 0);
  613. snd_soc_write(codec, WM8995_DC_SERVO_1, 0);
  614. snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1,
  615. WM8995_HPOUT1L_ENA_MASK |
  616. WM8995_HPOUT1R_ENA_MASK,
  617. 0);
  618. break;
  619. }
  620. return 0;
  621. }
  622. static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
  623. {
  624. struct wm8995_priv *wm8995;
  625. int rate;
  626. int reg1 = 0;
  627. int offset;
  628. wm8995 = snd_soc_codec_get_drvdata(codec);
  629. if (aif)
  630. offset = 4;
  631. else
  632. offset = 0;
  633. switch (wm8995->sysclk[aif]) {
  634. case WM8995_SYSCLK_MCLK1:
  635. rate = wm8995->mclk[0];
  636. break;
  637. case WM8995_SYSCLK_MCLK2:
  638. reg1 |= 0x8;
  639. rate = wm8995->mclk[1];
  640. break;
  641. case WM8995_SYSCLK_FLL1:
  642. reg1 |= 0x10;
  643. rate = wm8995->fll[0].out;
  644. break;
  645. case WM8995_SYSCLK_FLL2:
  646. reg1 |= 0x18;
  647. rate = wm8995->fll[1].out;
  648. break;
  649. default:
  650. return -EINVAL;
  651. }
  652. if (rate >= 13500000) {
  653. rate /= 2;
  654. reg1 |= WM8995_AIF1CLK_DIV;
  655. dev_dbg(codec->dev, "Dividing AIF%d clock to %dHz\n",
  656. aif + 1, rate);
  657. }
  658. wm8995->aifclk[aif] = rate;
  659. snd_soc_update_bits(codec, WM8995_AIF1_CLOCKING_1 + offset,
  660. WM8995_AIF1CLK_SRC_MASK | WM8995_AIF1CLK_DIV_MASK,
  661. reg1);
  662. return 0;
  663. }
  664. static int configure_clock(struct snd_soc_codec *codec)
  665. {
  666. struct wm8995_priv *wm8995;
  667. int change, new;
  668. wm8995 = snd_soc_codec_get_drvdata(codec);
  669. /* Bring up the AIF clocks first */
  670. configure_aif_clock(codec, 0);
  671. configure_aif_clock(codec, 1);
  672. /*
  673. * Then switch CLK_SYS over to the higher of them; a change
  674. * can only happen as a result of a clocking change which can
  675. * only be made outside of DAPM so we can safely redo the
  676. * clocking.
  677. */
  678. /* If they're equal it doesn't matter which is used */
  679. if (wm8995->aifclk[0] == wm8995->aifclk[1])
  680. return 0;
  681. if (wm8995->aifclk[0] < wm8995->aifclk[1])
  682. new = WM8995_SYSCLK_SRC;
  683. else
  684. new = 0;
  685. change = snd_soc_update_bits(codec, WM8995_CLOCKING_1,
  686. WM8995_SYSCLK_SRC_MASK, new);
  687. if (!change)
  688. return 0;
  689. snd_soc_dapm_sync(&codec->dapm);
  690. return 0;
  691. }
  692. static int clk_sys_event(struct snd_soc_dapm_widget *w,
  693. struct snd_kcontrol *kcontrol, int event)
  694. {
  695. struct snd_soc_codec *codec;
  696. codec = w->codec;
  697. switch (event) {
  698. case SND_SOC_DAPM_PRE_PMU:
  699. return configure_clock(codec);
  700. case SND_SOC_DAPM_POST_PMD:
  701. configure_clock(codec);
  702. break;
  703. }
  704. return 0;
  705. }
  706. static const char *sidetone_text[] = {
  707. "ADC/DMIC1", "DMIC2",
  708. };
  709. static const struct soc_enum sidetone1_enum =
  710. SOC_ENUM_SINGLE(WM8995_SIDETONE, 0, 2, sidetone_text);
  711. static const struct snd_kcontrol_new sidetone1_mux =
  712. SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
  713. static const struct soc_enum sidetone2_enum =
  714. SOC_ENUM_SINGLE(WM8995_SIDETONE, 1, 2, sidetone_text);
  715. static const struct snd_kcontrol_new sidetone2_mux =
  716. SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
  717. static const struct snd_kcontrol_new aif1adc1l_mix[] = {
  718. SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING,
  719. 1, 1, 0),
  720. SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING,
  721. 0, 1, 0),
  722. };
  723. static const struct snd_kcontrol_new aif1adc1r_mix[] = {
  724. SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING,
  725. 1, 1, 0),
  726. SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING,
  727. 0, 1, 0),
  728. };
  729. static const struct snd_kcontrol_new aif1adc2l_mix[] = {
  730. SOC_DAPM_SINGLE("DMIC Switch", WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING,
  731. 1, 1, 0),
  732. SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING,
  733. 0, 1, 0),
  734. };
  735. static const struct snd_kcontrol_new aif1adc2r_mix[] = {
  736. SOC_DAPM_SINGLE("DMIC Switch", WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING,
  737. 1, 1, 0),
  738. SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING,
  739. 0, 1, 0),
  740. };
  741. static const struct snd_kcontrol_new dac1l_mix[] = {
  742. WM8995_CLASS_W_SWITCH("Right Sidetone Switch", WM8995_DAC1_LEFT_MIXER_ROUTING,
  743. 5, 1, 0),
  744. WM8995_CLASS_W_SWITCH("Left Sidetone Switch", WM8995_DAC1_LEFT_MIXER_ROUTING,
  745. 4, 1, 0),
  746. WM8995_CLASS_W_SWITCH("AIF2 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING,
  747. 2, 1, 0),
  748. WM8995_CLASS_W_SWITCH("AIF1.2 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING,
  749. 1, 1, 0),
  750. WM8995_CLASS_W_SWITCH("AIF1.1 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING,
  751. 0, 1, 0),
  752. };
  753. static const struct snd_kcontrol_new dac1r_mix[] = {
  754. WM8995_CLASS_W_SWITCH("Right Sidetone Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING,
  755. 5, 1, 0),
  756. WM8995_CLASS_W_SWITCH("Left Sidetone Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING,
  757. 4, 1, 0),
  758. WM8995_CLASS_W_SWITCH("AIF2 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING,
  759. 2, 1, 0),
  760. WM8995_CLASS_W_SWITCH("AIF1.2 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING,
  761. 1, 1, 0),
  762. WM8995_CLASS_W_SWITCH("AIF1.1 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING,
  763. 0, 1, 0),
  764. };
  765. static const struct snd_kcontrol_new aif2dac2l_mix[] = {
  766. SOC_DAPM_SINGLE("Right Sidetone Switch", WM8995_DAC2_LEFT_MIXER_ROUTING,
  767. 5, 1, 0),
  768. SOC_DAPM_SINGLE("Left Sidetone Switch", WM8995_DAC2_LEFT_MIXER_ROUTING,
  769. 4, 1, 0),
  770. SOC_DAPM_SINGLE("AIF2 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING,
  771. 2, 1, 0),
  772. SOC_DAPM_SINGLE("AIF1.2 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING,
  773. 1, 1, 0),
  774. SOC_DAPM_SINGLE("AIF1.1 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING,
  775. 0, 1, 0),
  776. };
  777. static const struct snd_kcontrol_new aif2dac2r_mix[] = {
  778. SOC_DAPM_SINGLE("Right Sidetone Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING,
  779. 5, 1, 0),
  780. SOC_DAPM_SINGLE("Left Sidetone Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING,
  781. 4, 1, 0),
  782. SOC_DAPM_SINGLE("AIF2 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING,
  783. 2, 1, 0),
  784. SOC_DAPM_SINGLE("AIF1.2 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING,
  785. 1, 1, 0),
  786. SOC_DAPM_SINGLE("AIF1.1 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING,
  787. 0, 1, 0),
  788. };
  789. static const struct snd_kcontrol_new in1l_pga =
  790. SOC_DAPM_SINGLE("IN1L Switch", WM8995_POWER_MANAGEMENT_2, 5, 1, 0);
  791. static const struct snd_kcontrol_new in1r_pga =
  792. SOC_DAPM_SINGLE("IN1R Switch", WM8995_POWER_MANAGEMENT_2, 4, 1, 0);
  793. static const char *adc_mux_text[] = {
  794. "ADC",
  795. "DMIC",
  796. };
  797. static const struct soc_enum adc_enum =
  798. SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text);
  799. static const struct snd_kcontrol_new adcl_mux =
  800. SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
  801. static const struct snd_kcontrol_new adcr_mux =
  802. SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum);
  803. static const char *spk_src_text[] = {
  804. "DAC1L", "DAC1R", "DAC2L", "DAC2R"
  805. };
  806. static const SOC_ENUM_SINGLE_DECL(spk1l_src_enum, WM8995_LEFT_PDM_SPEAKER_1,
  807. 0, spk_src_text);
  808. static const SOC_ENUM_SINGLE_DECL(spk1r_src_enum, WM8995_RIGHT_PDM_SPEAKER_1,
  809. 0, spk_src_text);
  810. static const SOC_ENUM_SINGLE_DECL(spk2l_src_enum, WM8995_LEFT_PDM_SPEAKER_2,
  811. 0, spk_src_text);
  812. static const SOC_ENUM_SINGLE_DECL(spk2r_src_enum, WM8995_RIGHT_PDM_SPEAKER_2,
  813. 0, spk_src_text);
  814. static const struct snd_kcontrol_new spk1l_mux =
  815. SOC_DAPM_ENUM("SPK1L SRC", spk1l_src_enum);
  816. static const struct snd_kcontrol_new spk1r_mux =
  817. SOC_DAPM_ENUM("SPK1R SRC", spk1r_src_enum);
  818. static const struct snd_kcontrol_new spk2l_mux =
  819. SOC_DAPM_ENUM("SPK2L SRC", spk2l_src_enum);
  820. static const struct snd_kcontrol_new spk2r_mux =
  821. SOC_DAPM_ENUM("SPK2R SRC", spk2r_src_enum);
  822. static const struct snd_soc_dapm_widget wm8995_dapm_widgets[] = {
  823. SND_SOC_DAPM_INPUT("DMIC1DAT"),
  824. SND_SOC_DAPM_INPUT("DMIC2DAT"),
  825. SND_SOC_DAPM_INPUT("IN1L"),
  826. SND_SOC_DAPM_INPUT("IN1R"),
  827. SND_SOC_DAPM_MIXER("IN1L PGA", SND_SOC_NOPM, 0, 0,
  828. &in1l_pga, 1),
  829. SND_SOC_DAPM_MIXER("IN1R PGA", SND_SOC_NOPM, 0, 0,
  830. &in1r_pga, 1),
  831. SND_SOC_DAPM_SUPPLY("MICBIAS1", WM8995_POWER_MANAGEMENT_1, 8, 0,
  832. NULL, 0),
  833. SND_SOC_DAPM_SUPPLY("MICBIAS2", WM8995_POWER_MANAGEMENT_1, 9, 0,
  834. NULL, 0),
  835. SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8995_AIF1_CLOCKING_1, 0, 0, NULL, 0),
  836. SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8995_AIF2_CLOCKING_1, 0, 0, NULL, 0),
  837. SND_SOC_DAPM_SUPPLY("DSP1CLK", WM8995_CLOCKING_1, 3, 0, NULL, 0),
  838. SND_SOC_DAPM_SUPPLY("DSP2CLK", WM8995_CLOCKING_1, 2, 0, NULL, 0),
  839. SND_SOC_DAPM_SUPPLY("SYSDSPCLK", WM8995_CLOCKING_1, 1, 0, NULL, 0),
  840. SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
  841. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  842. SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", "AIF1 Capture", 0,
  843. WM8995_POWER_MANAGEMENT_3, 9, 0),
  844. SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", "AIF1 Capture", 0,
  845. WM8995_POWER_MANAGEMENT_3, 8, 0),
  846. SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", "AIF1 Capture", 0,
  847. SND_SOC_NOPM, 0, 0),
  848. SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", "AIF1 Capture",
  849. 0, WM8995_POWER_MANAGEMENT_3, 11, 0),
  850. SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", "AIF1 Capture",
  851. 0, WM8995_POWER_MANAGEMENT_3, 10, 0),
  852. SND_SOC_DAPM_VIRT_MUX("ADCL Mux", SND_SOC_NOPM, 1, 0,
  853. &adcl_mux),
  854. SND_SOC_DAPM_VIRT_MUX("ADCR Mux", SND_SOC_NOPM, 0, 0,
  855. &adcr_mux),
  856. SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8995_POWER_MANAGEMENT_3, 5, 0),
  857. SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8995_POWER_MANAGEMENT_3, 4, 0),
  858. SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8995_POWER_MANAGEMENT_3, 3, 0),
  859. SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8995_POWER_MANAGEMENT_3, 2, 0),
  860. SND_SOC_DAPM_ADC("ADCL", NULL, WM8995_POWER_MANAGEMENT_3, 1, 0),
  861. SND_SOC_DAPM_ADC("ADCR", NULL, WM8995_POWER_MANAGEMENT_3, 0, 0),
  862. SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
  863. aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
  864. SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
  865. aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
  866. SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
  867. aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
  868. SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
  869. aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
  870. SND_SOC_DAPM_AIF_IN("AIF1DAC1L", NULL, 0, WM8995_POWER_MANAGEMENT_4,
  871. 9, 0),
  872. SND_SOC_DAPM_AIF_IN("AIF1DAC1R", NULL, 0, WM8995_POWER_MANAGEMENT_4,
  873. 8, 0),
  874. SND_SOC_DAPM_AIF_IN("AIF1DACDAT", "AIF1 Playback", 0, SND_SOC_NOPM,
  875. 0, 0),
  876. SND_SOC_DAPM_AIF_IN("AIF1DAC2L", NULL, 0, WM8995_POWER_MANAGEMENT_4,
  877. 11, 0),
  878. SND_SOC_DAPM_AIF_IN("AIF1DAC2R", NULL, 0, WM8995_POWER_MANAGEMENT_4,
  879. 10, 0),
  880. SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
  881. aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
  882. SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
  883. aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
  884. SND_SOC_DAPM_DAC("DAC2L", NULL, WM8995_POWER_MANAGEMENT_4, 3, 0),
  885. SND_SOC_DAPM_DAC("DAC2R", NULL, WM8995_POWER_MANAGEMENT_4, 2, 0),
  886. SND_SOC_DAPM_DAC("DAC1L", NULL, WM8995_POWER_MANAGEMENT_4, 1, 0),
  887. SND_SOC_DAPM_DAC("DAC1R", NULL, WM8995_POWER_MANAGEMENT_4, 0, 0),
  888. SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0, dac1l_mix,
  889. ARRAY_SIZE(dac1l_mix)),
  890. SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0, dac1r_mix,
  891. ARRAY_SIZE(dac1r_mix)),
  892. SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
  893. SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
  894. SND_SOC_DAPM_PGA_E("Headphone PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
  895. hp_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  896. SND_SOC_DAPM_SUPPLY("Headphone Supply", SND_SOC_NOPM, 0, 0,
  897. hp_supply_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  898. SND_SOC_DAPM_MUX("SPK1L Driver", WM8995_LEFT_PDM_SPEAKER_1,
  899. 4, 0, &spk1l_mux),
  900. SND_SOC_DAPM_MUX("SPK1R Driver", WM8995_RIGHT_PDM_SPEAKER_1,
  901. 4, 0, &spk1r_mux),
  902. SND_SOC_DAPM_MUX("SPK2L Driver", WM8995_LEFT_PDM_SPEAKER_2,
  903. 4, 0, &spk2l_mux),
  904. SND_SOC_DAPM_MUX("SPK2R Driver", WM8995_RIGHT_PDM_SPEAKER_2,
  905. 4, 0, &spk2r_mux),
  906. SND_SOC_DAPM_SUPPLY("LDO2", WM8995_POWER_MANAGEMENT_2, 1, 0, NULL, 0),
  907. SND_SOC_DAPM_OUTPUT("HP1L"),
  908. SND_SOC_DAPM_OUTPUT("HP1R"),
  909. SND_SOC_DAPM_OUTPUT("SPK1L"),
  910. SND_SOC_DAPM_OUTPUT("SPK1R"),
  911. SND_SOC_DAPM_OUTPUT("SPK2L"),
  912. SND_SOC_DAPM_OUTPUT("SPK2R")
  913. };
  914. static const struct snd_soc_dapm_route wm8995_intercon[] = {
  915. { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
  916. { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
  917. { "DSP1CLK", NULL, "CLK_SYS" },
  918. { "DSP2CLK", NULL, "CLK_SYS" },
  919. { "SYSDSPCLK", NULL, "CLK_SYS" },
  920. { "AIF1ADC1L", NULL, "AIF1CLK" },
  921. { "AIF1ADC1L", NULL, "DSP1CLK" },
  922. { "AIF1ADC1R", NULL, "AIF1CLK" },
  923. { "AIF1ADC1R", NULL, "DSP1CLK" },
  924. { "AIF1ADC1R", NULL, "SYSDSPCLK" },
  925. { "AIF1ADC2L", NULL, "AIF1CLK" },
  926. { "AIF1ADC2L", NULL, "DSP1CLK" },
  927. { "AIF1ADC2R", NULL, "AIF1CLK" },
  928. { "AIF1ADC2R", NULL, "DSP1CLK" },
  929. { "AIF1ADC2R", NULL, "SYSDSPCLK" },
  930. { "DMIC1L", NULL, "DMIC1DAT" },
  931. { "DMIC1L", NULL, "CLK_SYS" },
  932. { "DMIC1R", NULL, "DMIC1DAT" },
  933. { "DMIC1R", NULL, "CLK_SYS" },
  934. { "DMIC2L", NULL, "DMIC2DAT" },
  935. { "DMIC2L", NULL, "CLK_SYS" },
  936. { "DMIC2R", NULL, "DMIC2DAT" },
  937. { "DMIC2R", NULL, "CLK_SYS" },
  938. { "ADCL", NULL, "AIF1CLK" },
  939. { "ADCL", NULL, "DSP1CLK" },
  940. { "ADCL", NULL, "SYSDSPCLK" },
  941. { "ADCR", NULL, "AIF1CLK" },
  942. { "ADCR", NULL, "DSP1CLK" },
  943. { "ADCR", NULL, "SYSDSPCLK" },
  944. { "IN1L PGA", "IN1L Switch", "IN1L" },
  945. { "IN1R PGA", "IN1R Switch", "IN1R" },
  946. { "IN1L PGA", NULL, "LDO2" },
  947. { "IN1R PGA", NULL, "LDO2" },
  948. { "ADCL", NULL, "IN1L PGA" },
  949. { "ADCR", NULL, "IN1R PGA" },
  950. { "ADCL Mux", "ADC", "ADCL" },
  951. { "ADCL Mux", "DMIC", "DMIC1L" },
  952. { "ADCR Mux", "ADC", "ADCR" },
  953. { "ADCR Mux", "DMIC", "DMIC1R" },
  954. /* AIF1 outputs */
  955. { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
  956. { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
  957. { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
  958. { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
  959. { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
  960. { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
  961. { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
  962. { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
  963. /* Sidetone */
  964. { "Left Sidetone", "ADC/DMIC1", "AIF1ADC1L" },
  965. { "Left Sidetone", "DMIC2", "AIF1ADC2L" },
  966. { "Right Sidetone", "ADC/DMIC1", "AIF1ADC1R" },
  967. { "Right Sidetone", "DMIC2", "AIF1ADC2R" },
  968. { "AIF1DAC1L", NULL, "AIF1CLK" },
  969. { "AIF1DAC1L", NULL, "DSP1CLK" },
  970. { "AIF1DAC1R", NULL, "AIF1CLK" },
  971. { "AIF1DAC1R", NULL, "DSP1CLK" },
  972. { "AIF1DAC1R", NULL, "SYSDSPCLK" },
  973. { "AIF1DAC2L", NULL, "AIF1CLK" },
  974. { "AIF1DAC2L", NULL, "DSP1CLK" },
  975. { "AIF1DAC2R", NULL, "AIF1CLK" },
  976. { "AIF1DAC2R", NULL, "DSP1CLK" },
  977. { "AIF1DAC2R", NULL, "SYSDSPCLK" },
  978. { "DAC1L", NULL, "AIF1CLK" },
  979. { "DAC1L", NULL, "DSP1CLK" },
  980. { "DAC1L", NULL, "SYSDSPCLK" },
  981. { "DAC1R", NULL, "AIF1CLK" },
  982. { "DAC1R", NULL, "DSP1CLK" },
  983. { "DAC1R", NULL, "SYSDSPCLK" },
  984. { "AIF1DAC1L", NULL, "AIF1DACDAT" },
  985. { "AIF1DAC1R", NULL, "AIF1DACDAT" },
  986. { "AIF1DAC2L", NULL, "AIF1DACDAT" },
  987. { "AIF1DAC2R", NULL, "AIF1DACDAT" },
  988. /* DAC1 inputs */
  989. { "DAC1L", NULL, "DAC1L Mixer" },
  990. { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
  991. { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
  992. { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
  993. { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
  994. { "DAC1R", NULL, "DAC1R Mixer" },
  995. { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
  996. { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
  997. { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
  998. { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
  999. /* DAC2/AIF2 outputs */
  1000. { "DAC2L", NULL, "AIF2DAC2L Mixer" },
  1001. { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
  1002. { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
  1003. { "DAC2R", NULL, "AIF2DAC2R Mixer" },
  1004. { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
  1005. { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
  1006. /* Output stages */
  1007. { "Headphone PGA", NULL, "DAC1L" },
  1008. { "Headphone PGA", NULL, "DAC1R" },
  1009. { "Headphone PGA", NULL, "DAC2L" },
  1010. { "Headphone PGA", NULL, "DAC2R" },
  1011. { "Headphone PGA", NULL, "Headphone Supply" },
  1012. { "Headphone PGA", NULL, "CLK_SYS" },
  1013. { "Headphone PGA", NULL, "LDO2" },
  1014. { "HP1L", NULL, "Headphone PGA" },
  1015. { "HP1R", NULL, "Headphone PGA" },
  1016. { "SPK1L Driver", "DAC1L", "DAC1L" },
  1017. { "SPK1L Driver", "DAC1R", "DAC1R" },
  1018. { "SPK1L Driver", "DAC2L", "DAC2L" },
  1019. { "SPK1L Driver", "DAC2R", "DAC2R" },
  1020. { "SPK1L Driver", NULL, "CLK_SYS" },
  1021. { "SPK1R Driver", "DAC1L", "DAC1L" },
  1022. { "SPK1R Driver", "DAC1R", "DAC1R" },
  1023. { "SPK1R Driver", "DAC2L", "DAC2L" },
  1024. { "SPK1R Driver", "DAC2R", "DAC2R" },
  1025. { "SPK1R Driver", NULL, "CLK_SYS" },
  1026. { "SPK2L Driver", "DAC1L", "DAC1L" },
  1027. { "SPK2L Driver", "DAC1R", "DAC1R" },
  1028. { "SPK2L Driver", "DAC2L", "DAC2L" },
  1029. { "SPK2L Driver", "DAC2R", "DAC2R" },
  1030. { "SPK2L Driver", NULL, "CLK_SYS" },
  1031. { "SPK2R Driver", "DAC1L", "DAC1L" },
  1032. { "SPK2R Driver", "DAC1R", "DAC1R" },
  1033. { "SPK2R Driver", "DAC2L", "DAC2L" },
  1034. { "SPK2R Driver", "DAC2R", "DAC2R" },
  1035. { "SPK2R Driver", NULL, "CLK_SYS" },
  1036. { "SPK1L", NULL, "SPK1L Driver" },
  1037. { "SPK1R", NULL, "SPK1R Driver" },
  1038. { "SPK2L", NULL, "SPK2L Driver" },
  1039. { "SPK2R", NULL, "SPK2R Driver" }
  1040. };
  1041. static bool wm8995_readable(struct device *dev, unsigned int reg)
  1042. {
  1043. switch (reg) {
  1044. case WM8995_SOFTWARE_RESET:
  1045. case WM8995_POWER_MANAGEMENT_1:
  1046. case WM8995_POWER_MANAGEMENT_2:
  1047. case WM8995_POWER_MANAGEMENT_3:
  1048. case WM8995_POWER_MANAGEMENT_4:
  1049. case WM8995_POWER_MANAGEMENT_5:
  1050. case WM8995_LEFT_LINE_INPUT_1_VOLUME:
  1051. case WM8995_RIGHT_LINE_INPUT_1_VOLUME:
  1052. case WM8995_LEFT_LINE_INPUT_CONTROL:
  1053. case WM8995_DAC1_LEFT_VOLUME:
  1054. case WM8995_DAC1_RIGHT_VOLUME:
  1055. case WM8995_DAC2_LEFT_VOLUME:
  1056. case WM8995_DAC2_RIGHT_VOLUME:
  1057. case WM8995_OUTPUT_VOLUME_ZC_1:
  1058. case WM8995_MICBIAS_1:
  1059. case WM8995_MICBIAS_2:
  1060. case WM8995_LDO_1:
  1061. case WM8995_LDO_2:
  1062. case WM8995_ACCESSORY_DETECT_MODE1:
  1063. case WM8995_ACCESSORY_DETECT_MODE2:
  1064. case WM8995_HEADPHONE_DETECT1:
  1065. case WM8995_HEADPHONE_DETECT2:
  1066. case WM8995_MIC_DETECT_1:
  1067. case WM8995_MIC_DETECT_2:
  1068. case WM8995_CHARGE_PUMP_1:
  1069. case WM8995_CLASS_W_1:
  1070. case WM8995_DC_SERVO_1:
  1071. case WM8995_DC_SERVO_2:
  1072. case WM8995_DC_SERVO_3:
  1073. case WM8995_DC_SERVO_5:
  1074. case WM8995_DC_SERVO_6:
  1075. case WM8995_DC_SERVO_7:
  1076. case WM8995_DC_SERVO_READBACK_0:
  1077. case WM8995_ANALOGUE_HP_1:
  1078. case WM8995_ANALOGUE_HP_2:
  1079. case WM8995_CHIP_REVISION:
  1080. case WM8995_CONTROL_INTERFACE_1:
  1081. case WM8995_CONTROL_INTERFACE_2:
  1082. case WM8995_WRITE_SEQUENCER_CTRL_1:
  1083. case WM8995_WRITE_SEQUENCER_CTRL_2:
  1084. case WM8995_AIF1_CLOCKING_1:
  1085. case WM8995_AIF1_CLOCKING_2:
  1086. case WM8995_AIF2_CLOCKING_1:
  1087. case WM8995_AIF2_CLOCKING_2:
  1088. case WM8995_CLOCKING_1:
  1089. case WM8995_CLOCKING_2:
  1090. case WM8995_AIF1_RATE:
  1091. case WM8995_AIF2_RATE:
  1092. case WM8995_RATE_STATUS:
  1093. case WM8995_FLL1_CONTROL_1:
  1094. case WM8995_FLL1_CONTROL_2:
  1095. case WM8995_FLL1_CONTROL_3:
  1096. case WM8995_FLL1_CONTROL_4:
  1097. case WM8995_FLL1_CONTROL_5:
  1098. case WM8995_FLL2_CONTROL_1:
  1099. case WM8995_FLL2_CONTROL_2:
  1100. case WM8995_FLL2_CONTROL_3:
  1101. case WM8995_FLL2_CONTROL_4:
  1102. case WM8995_FLL2_CONTROL_5:
  1103. case WM8995_AIF1_CONTROL_1:
  1104. case WM8995_AIF1_CONTROL_2:
  1105. case WM8995_AIF1_MASTER_SLAVE:
  1106. case WM8995_AIF1_BCLK:
  1107. case WM8995_AIF1ADC_LRCLK:
  1108. case WM8995_AIF1DAC_LRCLK:
  1109. case WM8995_AIF1DAC_DATA:
  1110. case WM8995_AIF1ADC_DATA:
  1111. case WM8995_AIF2_CONTROL_1:
  1112. case WM8995_AIF2_CONTROL_2:
  1113. case WM8995_AIF2_MASTER_SLAVE:
  1114. case WM8995_AIF2_BCLK:
  1115. case WM8995_AIF2ADC_LRCLK:
  1116. case WM8995_AIF2DAC_LRCLK:
  1117. case WM8995_AIF2DAC_DATA:
  1118. case WM8995_AIF2ADC_DATA:
  1119. case WM8995_AIF1_ADC1_LEFT_VOLUME:
  1120. case WM8995_AIF1_ADC1_RIGHT_VOLUME:
  1121. case WM8995_AIF1_DAC1_LEFT_VOLUME:
  1122. case WM8995_AIF1_DAC1_RIGHT_VOLUME:
  1123. case WM8995_AIF1_ADC2_LEFT_VOLUME:
  1124. case WM8995_AIF1_ADC2_RIGHT_VOLUME:
  1125. case WM8995_AIF1_DAC2_LEFT_VOLUME:
  1126. case WM8995_AIF1_DAC2_RIGHT_VOLUME:
  1127. case WM8995_AIF1_ADC1_FILTERS:
  1128. case WM8995_AIF1_ADC2_FILTERS:
  1129. case WM8995_AIF1_DAC1_FILTERS_1:
  1130. case WM8995_AIF1_DAC1_FILTERS_2:
  1131. case WM8995_AIF1_DAC2_FILTERS_1:
  1132. case WM8995_AIF1_DAC2_FILTERS_2:
  1133. case WM8995_AIF1_DRC1_1:
  1134. case WM8995_AIF1_DRC1_2:
  1135. case WM8995_AIF1_DRC1_3:
  1136. case WM8995_AIF1_DRC1_4:
  1137. case WM8995_AIF1_DRC1_5:
  1138. case WM8995_AIF1_DRC2_1:
  1139. case WM8995_AIF1_DRC2_2:
  1140. case WM8995_AIF1_DRC2_3:
  1141. case WM8995_AIF1_DRC2_4:
  1142. case WM8995_AIF1_DRC2_5:
  1143. case WM8995_AIF1_DAC1_EQ_GAINS_1:
  1144. case WM8995_AIF1_DAC1_EQ_GAINS_2:
  1145. case WM8995_AIF1_DAC1_EQ_BAND_1_A:
  1146. case WM8995_AIF1_DAC1_EQ_BAND_1_B:
  1147. case WM8995_AIF1_DAC1_EQ_BAND_1_PG:
  1148. case WM8995_AIF1_DAC1_EQ_BAND_2_A:
  1149. case WM8995_AIF1_DAC1_EQ_BAND_2_B:
  1150. case WM8995_AIF1_DAC1_EQ_BAND_2_C:
  1151. case WM8995_AIF1_DAC1_EQ_BAND_2_PG:
  1152. case WM8995_AIF1_DAC1_EQ_BAND_3_A:
  1153. case WM8995_AIF1_DAC1_EQ_BAND_3_B:
  1154. case WM8995_AIF1_DAC1_EQ_BAND_3_C:
  1155. case WM8995_AIF1_DAC1_EQ_BAND_3_PG:
  1156. case WM8995_AIF1_DAC1_EQ_BAND_4_A:
  1157. case WM8995_AIF1_DAC1_EQ_BAND_4_B:
  1158. case WM8995_AIF1_DAC1_EQ_BAND_4_C:
  1159. case WM8995_AIF1_DAC1_EQ_BAND_4_PG:
  1160. case WM8995_AIF1_DAC1_EQ_BAND_5_A:
  1161. case WM8995_AIF1_DAC1_EQ_BAND_5_B:
  1162. case WM8995_AIF1_DAC1_EQ_BAND_5_PG:
  1163. case WM8995_AIF1_DAC2_EQ_GAINS_1:
  1164. case WM8995_AIF1_DAC2_EQ_GAINS_2:
  1165. case WM8995_AIF1_DAC2_EQ_BAND_1_A:
  1166. case WM8995_AIF1_DAC2_EQ_BAND_1_B:
  1167. case WM8995_AIF1_DAC2_EQ_BAND_1_PG:
  1168. case WM8995_AIF1_DAC2_EQ_BAND_2_A:
  1169. case WM8995_AIF1_DAC2_EQ_BAND_2_B:
  1170. case WM8995_AIF1_DAC2_EQ_BAND_2_C:
  1171. case WM8995_AIF1_DAC2_EQ_BAND_2_PG:
  1172. case WM8995_AIF1_DAC2_EQ_BAND_3_A:
  1173. case WM8995_AIF1_DAC2_EQ_BAND_3_B:
  1174. case WM8995_AIF1_DAC2_EQ_BAND_3_C:
  1175. case WM8995_AIF1_DAC2_EQ_BAND_3_PG:
  1176. case WM8995_AIF1_DAC2_EQ_BAND_4_A:
  1177. case WM8995_AIF1_DAC2_EQ_BAND_4_B:
  1178. case WM8995_AIF1_DAC2_EQ_BAND_4_C:
  1179. case WM8995_AIF1_DAC2_EQ_BAND_4_PG:
  1180. case WM8995_AIF1_DAC2_EQ_BAND_5_A:
  1181. case WM8995_AIF1_DAC2_EQ_BAND_5_B:
  1182. case WM8995_AIF1_DAC2_EQ_BAND_5_PG:
  1183. case WM8995_AIF2_ADC_LEFT_VOLUME:
  1184. case WM8995_AIF2_ADC_RIGHT_VOLUME:
  1185. case WM8995_AIF2_DAC_LEFT_VOLUME:
  1186. case WM8995_AIF2_DAC_RIGHT_VOLUME:
  1187. case WM8995_AIF2_ADC_FILTERS:
  1188. case WM8995_AIF2_DAC_FILTERS_1:
  1189. case WM8995_AIF2_DAC_FILTERS_2:
  1190. case WM8995_AIF2_DRC_1:
  1191. case WM8995_AIF2_DRC_2:
  1192. case WM8995_AIF2_DRC_3:
  1193. case WM8995_AIF2_DRC_4:
  1194. case WM8995_AIF2_DRC_5:
  1195. case WM8995_AIF2_EQ_GAINS_1:
  1196. case WM8995_AIF2_EQ_GAINS_2:
  1197. case WM8995_AIF2_EQ_BAND_1_A:
  1198. case WM8995_AIF2_EQ_BAND_1_B:
  1199. case WM8995_AIF2_EQ_BAND_1_PG:
  1200. case WM8995_AIF2_EQ_BAND_2_A:
  1201. case WM8995_AIF2_EQ_BAND_2_B:
  1202. case WM8995_AIF2_EQ_BAND_2_C:
  1203. case WM8995_AIF2_EQ_BAND_2_PG:
  1204. case WM8995_AIF2_EQ_BAND_3_A:
  1205. case WM8995_AIF2_EQ_BAND_3_B:
  1206. case WM8995_AIF2_EQ_BAND_3_C:
  1207. case WM8995_AIF2_EQ_BAND_3_PG:
  1208. case WM8995_AIF2_EQ_BAND_4_A:
  1209. case WM8995_AIF2_EQ_BAND_4_B:
  1210. case WM8995_AIF2_EQ_BAND_4_C:
  1211. case WM8995_AIF2_EQ_BAND_4_PG:
  1212. case WM8995_AIF2_EQ_BAND_5_A:
  1213. case WM8995_AIF2_EQ_BAND_5_B:
  1214. case WM8995_AIF2_EQ_BAND_5_PG:
  1215. case WM8995_DAC1_MIXER_VOLUMES:
  1216. case WM8995_DAC1_LEFT_MIXER_ROUTING:
  1217. case WM8995_DAC1_RIGHT_MIXER_ROUTING:
  1218. case WM8995_DAC2_MIXER_VOLUMES:
  1219. case WM8995_DAC2_LEFT_MIXER_ROUTING:
  1220. case WM8995_DAC2_RIGHT_MIXER_ROUTING:
  1221. case WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING:
  1222. case WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING:
  1223. case WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING:
  1224. case WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING:
  1225. case WM8995_DAC_SOFTMUTE:
  1226. case WM8995_OVERSAMPLING:
  1227. case WM8995_SIDETONE:
  1228. case WM8995_GPIO_1:
  1229. case WM8995_GPIO_2:
  1230. case WM8995_GPIO_3:
  1231. case WM8995_GPIO_4:
  1232. case WM8995_GPIO_5:
  1233. case WM8995_GPIO_6:
  1234. case WM8995_GPIO_7:
  1235. case WM8995_GPIO_8:
  1236. case WM8995_GPIO_9:
  1237. case WM8995_GPIO_10:
  1238. case WM8995_GPIO_11:
  1239. case WM8995_GPIO_12:
  1240. case WM8995_GPIO_13:
  1241. case WM8995_GPIO_14:
  1242. case WM8995_PULL_CONTROL_1:
  1243. case WM8995_PULL_CONTROL_2:
  1244. case WM8995_INTERRUPT_STATUS_1:
  1245. case WM8995_INTERRUPT_STATUS_2:
  1246. case WM8995_INTERRUPT_RAW_STATUS_2:
  1247. case WM8995_INTERRUPT_STATUS_1_MASK:
  1248. case WM8995_INTERRUPT_STATUS_2_MASK:
  1249. case WM8995_INTERRUPT_CONTROL:
  1250. case WM8995_LEFT_PDM_SPEAKER_1:
  1251. case WM8995_RIGHT_PDM_SPEAKER_1:
  1252. case WM8995_PDM_SPEAKER_1_MUTE_SEQUENCE:
  1253. case WM8995_LEFT_PDM_SPEAKER_2:
  1254. case WM8995_RIGHT_PDM_SPEAKER_2:
  1255. case WM8995_PDM_SPEAKER_2_MUTE_SEQUENCE:
  1256. return true;
  1257. default:
  1258. return false;
  1259. }
  1260. }
  1261. static bool wm8995_volatile(struct device *dev, unsigned int reg)
  1262. {
  1263. switch (reg) {
  1264. case WM8995_SOFTWARE_RESET:
  1265. case WM8995_DC_SERVO_READBACK_0:
  1266. case WM8995_INTERRUPT_STATUS_1:
  1267. case WM8995_INTERRUPT_STATUS_2:
  1268. case WM8995_INTERRUPT_CONTROL:
  1269. case WM8995_ACCESSORY_DETECT_MODE1:
  1270. case WM8995_ACCESSORY_DETECT_MODE2:
  1271. case WM8995_HEADPHONE_DETECT1:
  1272. case WM8995_HEADPHONE_DETECT2:
  1273. case WM8995_RATE_STATUS:
  1274. return true;
  1275. default:
  1276. return false;
  1277. }
  1278. }
  1279. static int wm8995_aif_mute(struct snd_soc_dai *dai, int mute)
  1280. {
  1281. struct snd_soc_codec *codec = dai->codec;
  1282. int mute_reg;
  1283. switch (dai->id) {
  1284. case 0:
  1285. mute_reg = WM8995_AIF1_DAC1_FILTERS_1;
  1286. break;
  1287. case 1:
  1288. mute_reg = WM8995_AIF2_DAC_FILTERS_1;
  1289. break;
  1290. default:
  1291. return -EINVAL;
  1292. }
  1293. snd_soc_update_bits(codec, mute_reg, WM8995_AIF1DAC1_MUTE_MASK,
  1294. !!mute << WM8995_AIF1DAC1_MUTE_SHIFT);
  1295. return 0;
  1296. }
  1297. static int wm8995_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  1298. {
  1299. struct snd_soc_codec *codec;
  1300. int master;
  1301. int aif;
  1302. codec = dai->codec;
  1303. master = 0;
  1304. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1305. case SND_SOC_DAIFMT_CBS_CFS:
  1306. break;
  1307. case SND_SOC_DAIFMT_CBM_CFM:
  1308. master = WM8995_AIF1_MSTR;
  1309. break;
  1310. default:
  1311. dev_err(dai->dev, "Unknown master/slave configuration\n");
  1312. return -EINVAL;
  1313. }
  1314. aif = 0;
  1315. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1316. case SND_SOC_DAIFMT_DSP_B:
  1317. aif |= WM8995_AIF1_LRCLK_INV;
  1318. case SND_SOC_DAIFMT_DSP_A:
  1319. aif |= (0x3 << WM8995_AIF1_FMT_SHIFT);
  1320. break;
  1321. case SND_SOC_DAIFMT_I2S:
  1322. aif |= (0x2 << WM8995_AIF1_FMT_SHIFT);
  1323. break;
  1324. case SND_SOC_DAIFMT_RIGHT_J:
  1325. break;
  1326. case SND_SOC_DAIFMT_LEFT_J:
  1327. aif |= (0x1 << WM8995_AIF1_FMT_SHIFT);
  1328. break;
  1329. default:
  1330. dev_err(dai->dev, "Unknown dai format\n");
  1331. return -EINVAL;
  1332. }
  1333. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1334. case SND_SOC_DAIFMT_DSP_A:
  1335. case SND_SOC_DAIFMT_DSP_B:
  1336. /* frame inversion not valid for DSP modes */
  1337. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  1338. case SND_SOC_DAIFMT_NB_NF:
  1339. break;
  1340. case SND_SOC_DAIFMT_IB_NF:
  1341. aif |= WM8995_AIF1_BCLK_INV;
  1342. break;
  1343. default:
  1344. return -EINVAL;
  1345. }
  1346. break;
  1347. case SND_SOC_DAIFMT_I2S:
  1348. case SND_SOC_DAIFMT_RIGHT_J:
  1349. case SND_SOC_DAIFMT_LEFT_J:
  1350. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  1351. case SND_SOC_DAIFMT_NB_NF:
  1352. break;
  1353. case SND_SOC_DAIFMT_IB_IF:
  1354. aif |= WM8995_AIF1_BCLK_INV | WM8995_AIF1_LRCLK_INV;
  1355. break;
  1356. case SND_SOC_DAIFMT_IB_NF:
  1357. aif |= WM8995_AIF1_BCLK_INV;
  1358. break;
  1359. case SND_SOC_DAIFMT_NB_IF:
  1360. aif |= WM8995_AIF1_LRCLK_INV;
  1361. break;
  1362. default:
  1363. return -EINVAL;
  1364. }
  1365. break;
  1366. default:
  1367. return -EINVAL;
  1368. }
  1369. snd_soc_update_bits(codec, WM8995_AIF1_CONTROL_1,
  1370. WM8995_AIF1_BCLK_INV_MASK |
  1371. WM8995_AIF1_LRCLK_INV_MASK |
  1372. WM8995_AIF1_FMT_MASK, aif);
  1373. snd_soc_update_bits(codec, WM8995_AIF1_MASTER_SLAVE,
  1374. WM8995_AIF1_MSTR_MASK, master);
  1375. return 0;
  1376. }
  1377. static const int srs[] = {
  1378. 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100,
  1379. 48000, 88200, 96000
  1380. };
  1381. static const int fs_ratios[] = {
  1382. -1 /* reserved */,
  1383. 128, 192, 256, 384, 512, 768, 1024, 1408, 1536
  1384. };
  1385. static const int bclk_divs[] = {
  1386. 10, 15, 20, 30, 40, 55, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480
  1387. };
  1388. static int wm8995_hw_params(struct snd_pcm_substream *substream,
  1389. struct snd_pcm_hw_params *params,
  1390. struct snd_soc_dai *dai)
  1391. {
  1392. struct snd_soc_codec *codec;
  1393. struct wm8995_priv *wm8995;
  1394. int aif1_reg;
  1395. int bclk_reg;
  1396. int lrclk_reg;
  1397. int rate_reg;
  1398. int bclk_rate;
  1399. int aif1;
  1400. int lrclk, bclk;
  1401. int i, rate_val, best, best_val, cur_val;
  1402. codec = dai->codec;
  1403. wm8995 = snd_soc_codec_get_drvdata(codec);
  1404. switch (dai->id) {
  1405. case 0:
  1406. aif1_reg = WM8995_AIF1_CONTROL_1;
  1407. bclk_reg = WM8995_AIF1_BCLK;
  1408. rate_reg = WM8995_AIF1_RATE;
  1409. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK /* ||
  1410. wm8995->lrclk_shared[0] */) {
  1411. lrclk_reg = WM8995_AIF1DAC_LRCLK;
  1412. } else {
  1413. lrclk_reg = WM8995_AIF1ADC_LRCLK;
  1414. dev_dbg(codec->dev, "AIF1 using split LRCLK\n");
  1415. }
  1416. break;
  1417. case 1:
  1418. aif1_reg = WM8995_AIF2_CONTROL_1;
  1419. bclk_reg = WM8995_AIF2_BCLK;
  1420. rate_reg = WM8995_AIF2_RATE;
  1421. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK /* ||
  1422. wm8995->lrclk_shared[1] */) {
  1423. lrclk_reg = WM8995_AIF2DAC_LRCLK;
  1424. } else {
  1425. lrclk_reg = WM8995_AIF2ADC_LRCLK;
  1426. dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
  1427. }
  1428. break;
  1429. default:
  1430. return -EINVAL;
  1431. }
  1432. bclk_rate = snd_soc_params_to_bclk(params);
  1433. if (bclk_rate < 0)
  1434. return bclk_rate;
  1435. aif1 = 0;
  1436. switch (params_format(params)) {
  1437. case SNDRV_PCM_FORMAT_S16_LE:
  1438. break;
  1439. case SNDRV_PCM_FORMAT_S20_3LE:
  1440. aif1 |= (0x1 << WM8995_AIF1_WL_SHIFT);
  1441. break;
  1442. case SNDRV_PCM_FORMAT_S24_LE:
  1443. aif1 |= (0x2 << WM8995_AIF1_WL_SHIFT);
  1444. break;
  1445. case SNDRV_PCM_FORMAT_S32_LE:
  1446. aif1 |= (0x3 << WM8995_AIF1_WL_SHIFT);
  1447. break;
  1448. default:
  1449. dev_err(dai->dev, "Unsupported word length %u\n",
  1450. params_format(params));
  1451. return -EINVAL;
  1452. }
  1453. /* try to find a suitable sample rate */
  1454. for (i = 0; i < ARRAY_SIZE(srs); ++i)
  1455. if (srs[i] == params_rate(params))
  1456. break;
  1457. if (i == ARRAY_SIZE(srs)) {
  1458. dev_err(dai->dev, "Sample rate %d is not supported\n",
  1459. params_rate(params));
  1460. return -EINVAL;
  1461. }
  1462. rate_val = i << WM8995_AIF1_SR_SHIFT;
  1463. dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i]);
  1464. dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
  1465. dai->id + 1, wm8995->aifclk[dai->id], bclk_rate);
  1466. /* AIFCLK/fs ratio; look for a close match in either direction */
  1467. best = 1;
  1468. best_val = abs((fs_ratios[1] * params_rate(params))
  1469. - wm8995->aifclk[dai->id]);
  1470. for (i = 2; i < ARRAY_SIZE(fs_ratios); i++) {
  1471. cur_val = abs((fs_ratios[i] * params_rate(params))
  1472. - wm8995->aifclk[dai->id]);
  1473. if (cur_val >= best_val)
  1474. continue;
  1475. best = i;
  1476. best_val = cur_val;
  1477. }
  1478. rate_val |= best;
  1479. dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
  1480. dai->id + 1, fs_ratios[best]);
  1481. /*
  1482. * We may not get quite the right frequency if using
  1483. * approximate clocks so look for the closest match that is
  1484. * higher than the target (we need to ensure that there enough
  1485. * BCLKs to clock out the samples).
  1486. */
  1487. best = 0;
  1488. bclk = 0;
  1489. for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
  1490. cur_val = (wm8995->aifclk[dai->id] * 10 / bclk_divs[i]) - bclk_rate;
  1491. if (cur_val < 0) /* BCLK table is sorted */
  1492. break;
  1493. best = i;
  1494. }
  1495. bclk |= best << WM8995_AIF1_BCLK_DIV_SHIFT;
  1496. bclk_rate = wm8995->aifclk[dai->id] * 10 / bclk_divs[best];
  1497. dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
  1498. bclk_divs[best], bclk_rate);
  1499. lrclk = bclk_rate / params_rate(params);
  1500. dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
  1501. lrclk, bclk_rate / lrclk);
  1502. snd_soc_update_bits(codec, aif1_reg,
  1503. WM8995_AIF1_WL_MASK, aif1);
  1504. snd_soc_update_bits(codec, bclk_reg,
  1505. WM8995_AIF1_BCLK_DIV_MASK, bclk);
  1506. snd_soc_update_bits(codec, lrclk_reg,
  1507. WM8995_AIF1DAC_RATE_MASK, lrclk);
  1508. snd_soc_update_bits(codec, rate_reg,
  1509. WM8995_AIF1_SR_MASK |
  1510. WM8995_AIF1CLK_RATE_MASK, rate_val);
  1511. return 0;
  1512. }
  1513. static int wm8995_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
  1514. {
  1515. struct snd_soc_codec *codec = codec_dai->codec;
  1516. int reg, val, mask;
  1517. switch (codec_dai->id) {
  1518. case 0:
  1519. reg = WM8995_AIF1_MASTER_SLAVE;
  1520. mask = WM8995_AIF1_TRI;
  1521. break;
  1522. case 1:
  1523. reg = WM8995_AIF2_MASTER_SLAVE;
  1524. mask = WM8995_AIF2_TRI;
  1525. break;
  1526. case 2:
  1527. reg = WM8995_POWER_MANAGEMENT_5;
  1528. mask = WM8995_AIF3_TRI;
  1529. break;
  1530. default:
  1531. return -EINVAL;
  1532. }
  1533. if (tristate)
  1534. val = mask;
  1535. else
  1536. val = 0;
  1537. return snd_soc_update_bits(codec, reg, mask, val);
  1538. }
  1539. /* The size in bits of the FLL divide multiplied by 10
  1540. * to allow rounding later */
  1541. #define FIXED_FLL_SIZE ((1 << 16) * 10)
  1542. struct fll_div {
  1543. u16 outdiv;
  1544. u16 n;
  1545. u16 k;
  1546. u16 clk_ref_div;
  1547. u16 fll_fratio;
  1548. };
  1549. static int wm8995_get_fll_config(struct fll_div *fll,
  1550. int freq_in, int freq_out)
  1551. {
  1552. u64 Kpart;
  1553. unsigned int K, Ndiv, Nmod;
  1554. pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
  1555. /* Scale the input frequency down to <= 13.5MHz */
  1556. fll->clk_ref_div = 0;
  1557. while (freq_in > 13500000) {
  1558. fll->clk_ref_div++;
  1559. freq_in /= 2;
  1560. if (fll->clk_ref_div > 3)
  1561. return -EINVAL;
  1562. }
  1563. pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
  1564. /* Scale the output to give 90MHz<=Fvco<=100MHz */
  1565. fll->outdiv = 3;
  1566. while (freq_out * (fll->outdiv + 1) < 90000000) {
  1567. fll->outdiv++;
  1568. if (fll->outdiv > 63)
  1569. return -EINVAL;
  1570. }
  1571. freq_out *= fll->outdiv + 1;
  1572. pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
  1573. if (freq_in > 1000000) {
  1574. fll->fll_fratio = 0;
  1575. } else if (freq_in > 256000) {
  1576. fll->fll_fratio = 1;
  1577. freq_in *= 2;
  1578. } else if (freq_in > 128000) {
  1579. fll->fll_fratio = 2;
  1580. freq_in *= 4;
  1581. } else if (freq_in > 64000) {
  1582. fll->fll_fratio = 3;
  1583. freq_in *= 8;
  1584. } else {
  1585. fll->fll_fratio = 4;
  1586. freq_in *= 16;
  1587. }
  1588. pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
  1589. /* Now, calculate N.K */
  1590. Ndiv = freq_out / freq_in;
  1591. fll->n = Ndiv;
  1592. Nmod = freq_out % freq_in;
  1593. pr_debug("Nmod=%d\n", Nmod);
  1594. /* Calculate fractional part - scale up so we can round. */
  1595. Kpart = FIXED_FLL_SIZE * (long long)Nmod;
  1596. do_div(Kpart, freq_in);
  1597. K = Kpart & 0xFFFFFFFF;
  1598. if ((K % 10) >= 5)
  1599. K += 5;
  1600. /* Move down to proper range now rounding is done */
  1601. fll->k = K / 10;
  1602. pr_debug("N=%x K=%x\n", fll->n, fll->k);
  1603. return 0;
  1604. }
  1605. static int wm8995_set_fll(struct snd_soc_dai *dai, int id,
  1606. int src, unsigned int freq_in,
  1607. unsigned int freq_out)
  1608. {
  1609. struct snd_soc_codec *codec;
  1610. struct wm8995_priv *wm8995;
  1611. int reg_offset, ret;
  1612. struct fll_div fll;
  1613. u16 reg, aif1, aif2;
  1614. codec = dai->codec;
  1615. wm8995 = snd_soc_codec_get_drvdata(codec);
  1616. aif1 = snd_soc_read(codec, WM8995_AIF1_CLOCKING_1)
  1617. & WM8995_AIF1CLK_ENA;
  1618. aif2 = snd_soc_read(codec, WM8995_AIF2_CLOCKING_1)
  1619. & WM8995_AIF2CLK_ENA;
  1620. switch (id) {
  1621. case WM8995_FLL1:
  1622. reg_offset = 0;
  1623. id = 0;
  1624. break;
  1625. case WM8995_FLL2:
  1626. reg_offset = 0x20;
  1627. id = 1;
  1628. break;
  1629. default:
  1630. return -EINVAL;
  1631. }
  1632. switch (src) {
  1633. case 0:
  1634. /* Allow no source specification when stopping */
  1635. if (freq_out)
  1636. return -EINVAL;
  1637. break;
  1638. case WM8995_FLL_SRC_MCLK1:
  1639. case WM8995_FLL_SRC_MCLK2:
  1640. case WM8995_FLL_SRC_LRCLK:
  1641. case WM8995_FLL_SRC_BCLK:
  1642. break;
  1643. default:
  1644. return -EINVAL;
  1645. }
  1646. /* Are we changing anything? */
  1647. if (wm8995->fll[id].src == src &&
  1648. wm8995->fll[id].in == freq_in && wm8995->fll[id].out == freq_out)
  1649. return 0;
  1650. /* If we're stopping the FLL redo the old config - no
  1651. * registers will actually be written but we avoid GCC flow
  1652. * analysis bugs spewing warnings.
  1653. */
  1654. if (freq_out)
  1655. ret = wm8995_get_fll_config(&fll, freq_in, freq_out);
  1656. else
  1657. ret = wm8995_get_fll_config(&fll, wm8995->fll[id].in,
  1658. wm8995->fll[id].out);
  1659. if (ret < 0)
  1660. return ret;
  1661. /* Gate the AIF clocks while we reclock */
  1662. snd_soc_update_bits(codec, WM8995_AIF1_CLOCKING_1,
  1663. WM8995_AIF1CLK_ENA_MASK, 0);
  1664. snd_soc_update_bits(codec, WM8995_AIF2_CLOCKING_1,
  1665. WM8995_AIF2CLK_ENA_MASK, 0);
  1666. /* We always need to disable the FLL while reconfiguring */
  1667. snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_1 + reg_offset,
  1668. WM8995_FLL1_ENA_MASK, 0);
  1669. reg = (fll.outdiv << WM8995_FLL1_OUTDIV_SHIFT) |
  1670. (fll.fll_fratio << WM8995_FLL1_FRATIO_SHIFT);
  1671. snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_2 + reg_offset,
  1672. WM8995_FLL1_OUTDIV_MASK |
  1673. WM8995_FLL1_FRATIO_MASK, reg);
  1674. snd_soc_write(codec, WM8995_FLL1_CONTROL_3 + reg_offset, fll.k);
  1675. snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_4 + reg_offset,
  1676. WM8995_FLL1_N_MASK,
  1677. fll.n << WM8995_FLL1_N_SHIFT);
  1678. snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_5 + reg_offset,
  1679. WM8995_FLL1_REFCLK_DIV_MASK |
  1680. WM8995_FLL1_REFCLK_SRC_MASK,
  1681. (fll.clk_ref_div << WM8995_FLL1_REFCLK_DIV_SHIFT) |
  1682. (src - 1));
  1683. if (freq_out)
  1684. snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_1 + reg_offset,
  1685. WM8995_FLL1_ENA_MASK, WM8995_FLL1_ENA);
  1686. wm8995->fll[id].in = freq_in;
  1687. wm8995->fll[id].out = freq_out;
  1688. wm8995->fll[id].src = src;
  1689. /* Enable any gated AIF clocks */
  1690. snd_soc_update_bits(codec, WM8995_AIF1_CLOCKING_1,
  1691. WM8995_AIF1CLK_ENA_MASK, aif1);
  1692. snd_soc_update_bits(codec, WM8995_AIF2_CLOCKING_1,
  1693. WM8995_AIF2CLK_ENA_MASK, aif2);
  1694. configure_clock(codec);
  1695. return 0;
  1696. }
  1697. static int wm8995_set_dai_sysclk(struct snd_soc_dai *dai,
  1698. int clk_id, unsigned int freq, int dir)
  1699. {
  1700. struct snd_soc_codec *codec;
  1701. struct wm8995_priv *wm8995;
  1702. codec = dai->codec;
  1703. wm8995 = snd_soc_codec_get_drvdata(codec);
  1704. switch (dai->id) {
  1705. case 0:
  1706. case 1:
  1707. break;
  1708. default:
  1709. /* AIF3 shares clocking with AIF1/2 */
  1710. return -EINVAL;
  1711. }
  1712. switch (clk_id) {
  1713. case WM8995_SYSCLK_MCLK1:
  1714. wm8995->sysclk[dai->id] = WM8995_SYSCLK_MCLK1;
  1715. wm8995->mclk[0] = freq;
  1716. dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
  1717. dai->id + 1, freq);
  1718. break;
  1719. case WM8995_SYSCLK_MCLK2:
  1720. wm8995->sysclk[dai->id] = WM8995_SYSCLK_MCLK1;
  1721. wm8995->mclk[1] = freq;
  1722. dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
  1723. dai->id + 1, freq);
  1724. break;
  1725. case WM8995_SYSCLK_FLL1:
  1726. wm8995->sysclk[dai->id] = WM8995_SYSCLK_FLL1;
  1727. dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id + 1);
  1728. break;
  1729. case WM8995_SYSCLK_FLL2:
  1730. wm8995->sysclk[dai->id] = WM8995_SYSCLK_FLL2;
  1731. dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id + 1);
  1732. break;
  1733. case WM8995_SYSCLK_OPCLK:
  1734. default:
  1735. dev_err(dai->dev, "Unknown clock source %d\n", clk_id);
  1736. return -EINVAL;
  1737. }
  1738. configure_clock(codec);
  1739. return 0;
  1740. }
  1741. static int wm8995_set_bias_level(struct snd_soc_codec *codec,
  1742. enum snd_soc_bias_level level)
  1743. {
  1744. struct wm8995_priv *wm8995;
  1745. int ret;
  1746. wm8995 = snd_soc_codec_get_drvdata(codec);
  1747. switch (level) {
  1748. case SND_SOC_BIAS_ON:
  1749. case SND_SOC_BIAS_PREPARE:
  1750. break;
  1751. case SND_SOC_BIAS_STANDBY:
  1752. if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
  1753. ret = regulator_bulk_enable(ARRAY_SIZE(wm8995->supplies),
  1754. wm8995->supplies);
  1755. if (ret)
  1756. return ret;
  1757. ret = regcache_sync(wm8995->regmap);
  1758. if (ret) {
  1759. dev_err(codec->dev,
  1760. "Failed to sync cache: %d\n", ret);
  1761. return ret;
  1762. }
  1763. snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1,
  1764. WM8995_BG_ENA_MASK, WM8995_BG_ENA);
  1765. }
  1766. break;
  1767. case SND_SOC_BIAS_OFF:
  1768. snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1,
  1769. WM8995_BG_ENA_MASK, 0);
  1770. regulator_bulk_disable(ARRAY_SIZE(wm8995->supplies),
  1771. wm8995->supplies);
  1772. break;
  1773. }
  1774. codec->dapm.bias_level = level;
  1775. return 0;
  1776. }
  1777. #ifdef CONFIG_PM
  1778. static int wm8995_suspend(struct snd_soc_codec *codec)
  1779. {
  1780. wm8995_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1781. return 0;
  1782. }
  1783. static int wm8995_resume(struct snd_soc_codec *codec)
  1784. {
  1785. wm8995_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1786. return 0;
  1787. }
  1788. #else
  1789. #define wm8995_suspend NULL
  1790. #define wm8995_resume NULL
  1791. #endif
  1792. static int wm8995_remove(struct snd_soc_codec *codec)
  1793. {
  1794. struct wm8995_priv *wm8995;
  1795. int i;
  1796. wm8995 = snd_soc_codec_get_drvdata(codec);
  1797. wm8995_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1798. for (i = 0; i < ARRAY_SIZE(wm8995->supplies); ++i)
  1799. regulator_unregister_notifier(wm8995->supplies[i].consumer,
  1800. &wm8995->disable_nb[i]);
  1801. regulator_bulk_free(ARRAY_SIZE(wm8995->supplies), wm8995->supplies);
  1802. return 0;
  1803. }
  1804. static int wm8995_probe(struct snd_soc_codec *codec)
  1805. {
  1806. struct wm8995_priv *wm8995;
  1807. int i;
  1808. int ret;
  1809. wm8995 = snd_soc_codec_get_drvdata(codec);
  1810. wm8995->codec = codec;
  1811. codec->control_data = wm8995->regmap;
  1812. ret = snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
  1813. if (ret < 0) {
  1814. dev_err(codec->dev, "Failed to set cache i/o: %d\n", ret);
  1815. return ret;
  1816. }
  1817. for (i = 0; i < ARRAY_SIZE(wm8995->supplies); i++)
  1818. wm8995->supplies[i].supply = wm8995_supply_names[i];
  1819. ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8995->supplies),
  1820. wm8995->supplies);
  1821. if (ret) {
  1822. dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
  1823. return ret;
  1824. }
  1825. wm8995->disable_nb[0].notifier_call = wm8995_regulator_event_0;
  1826. wm8995->disable_nb[1].notifier_call = wm8995_regulator_event_1;
  1827. wm8995->disable_nb[2].notifier_call = wm8995_regulator_event_2;
  1828. wm8995->disable_nb[3].notifier_call = wm8995_regulator_event_3;
  1829. wm8995->disable_nb[4].notifier_call = wm8995_regulator_event_4;
  1830. wm8995->disable_nb[5].notifier_call = wm8995_regulator_event_5;
  1831. wm8995->disable_nb[6].notifier_call = wm8995_regulator_event_6;
  1832. wm8995->disable_nb[7].notifier_call = wm8995_regulator_event_7;
  1833. /* This should really be moved into the regulator core */
  1834. for (i = 0; i < ARRAY_SIZE(wm8995->supplies); i++) {
  1835. ret = regulator_register_notifier(wm8995->supplies[i].consumer,
  1836. &wm8995->disable_nb[i]);
  1837. if (ret) {
  1838. dev_err(codec->dev,
  1839. "Failed to register regulator notifier: %d\n",
  1840. ret);
  1841. }
  1842. }
  1843. ret = regulator_bulk_enable(ARRAY_SIZE(wm8995->supplies),
  1844. wm8995->supplies);
  1845. if (ret) {
  1846. dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
  1847. goto err_reg_get;
  1848. }
  1849. ret = snd_soc_read(codec, WM8995_SOFTWARE_RESET);
  1850. if (ret < 0) {
  1851. dev_err(codec->dev, "Failed to read device ID: %d\n", ret);
  1852. goto err_reg_enable;
  1853. }
  1854. if (ret != 0x8995) {
  1855. dev_err(codec->dev, "Invalid device ID: %#x\n", ret);
  1856. ret = -EINVAL;
  1857. goto err_reg_enable;
  1858. }
  1859. ret = snd_soc_write(codec, WM8995_SOFTWARE_RESET, 0);
  1860. if (ret < 0) {
  1861. dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
  1862. goto err_reg_enable;
  1863. }
  1864. wm8995_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1865. /* Latch volume updates (right only; we always do left then right). */
  1866. snd_soc_update_bits(codec, WM8995_AIF1_DAC1_RIGHT_VOLUME,
  1867. WM8995_AIF1DAC1_VU_MASK, WM8995_AIF1DAC1_VU);
  1868. snd_soc_update_bits(codec, WM8995_AIF1_DAC2_RIGHT_VOLUME,
  1869. WM8995_AIF1DAC2_VU_MASK, WM8995_AIF1DAC2_VU);
  1870. snd_soc_update_bits(codec, WM8995_AIF2_DAC_RIGHT_VOLUME,
  1871. WM8995_AIF2DAC_VU_MASK, WM8995_AIF2DAC_VU);
  1872. snd_soc_update_bits(codec, WM8995_AIF1_ADC1_RIGHT_VOLUME,
  1873. WM8995_AIF1ADC1_VU_MASK, WM8995_AIF1ADC1_VU);
  1874. snd_soc_update_bits(codec, WM8995_AIF1_ADC2_RIGHT_VOLUME,
  1875. WM8995_AIF1ADC2_VU_MASK, WM8995_AIF1ADC2_VU);
  1876. snd_soc_update_bits(codec, WM8995_AIF2_ADC_RIGHT_VOLUME,
  1877. WM8995_AIF2ADC_VU_MASK, WM8995_AIF1ADC2_VU);
  1878. snd_soc_update_bits(codec, WM8995_DAC1_RIGHT_VOLUME,
  1879. WM8995_DAC1_VU_MASK, WM8995_DAC1_VU);
  1880. snd_soc_update_bits(codec, WM8995_DAC2_RIGHT_VOLUME,
  1881. WM8995_DAC2_VU_MASK, WM8995_DAC2_VU);
  1882. snd_soc_update_bits(codec, WM8995_RIGHT_LINE_INPUT_1_VOLUME,
  1883. WM8995_IN1_VU_MASK, WM8995_IN1_VU);
  1884. wm8995_update_class_w(codec);
  1885. snd_soc_add_codec_controls(codec, wm8995_snd_controls,
  1886. ARRAY_SIZE(wm8995_snd_controls));
  1887. snd_soc_dapm_new_controls(&codec->dapm, wm8995_dapm_widgets,
  1888. ARRAY_SIZE(wm8995_dapm_widgets));
  1889. snd_soc_dapm_add_routes(&codec->dapm, wm8995_intercon,
  1890. ARRAY_SIZE(wm8995_intercon));
  1891. return 0;
  1892. err_reg_enable:
  1893. regulator_bulk_disable(ARRAY_SIZE(wm8995->supplies), wm8995->supplies);
  1894. err_reg_get:
  1895. regulator_bulk_free(ARRAY_SIZE(wm8995->supplies), wm8995->supplies);
  1896. return ret;
  1897. }
  1898. #define WM8995_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  1899. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
  1900. static const struct snd_soc_dai_ops wm8995_aif1_dai_ops = {
  1901. .set_sysclk = wm8995_set_dai_sysclk,
  1902. .set_fmt = wm8995_set_dai_fmt,
  1903. .hw_params = wm8995_hw_params,
  1904. .digital_mute = wm8995_aif_mute,
  1905. .set_pll = wm8995_set_fll,
  1906. .set_tristate = wm8995_set_tristate,
  1907. };
  1908. static const struct snd_soc_dai_ops wm8995_aif2_dai_ops = {
  1909. .set_sysclk = wm8995_set_dai_sysclk,
  1910. .set_fmt = wm8995_set_dai_fmt,
  1911. .hw_params = wm8995_hw_params,
  1912. .digital_mute = wm8995_aif_mute,
  1913. .set_pll = wm8995_set_fll,
  1914. .set_tristate = wm8995_set_tristate,
  1915. };
  1916. static const struct snd_soc_dai_ops wm8995_aif3_dai_ops = {
  1917. .set_tristate = wm8995_set_tristate,
  1918. };
  1919. static struct snd_soc_dai_driver wm8995_dai[] = {
  1920. {
  1921. .name = "wm8995-aif1",
  1922. .playback = {
  1923. .stream_name = "AIF1 Playback",
  1924. .channels_min = 2,
  1925. .channels_max = 2,
  1926. .rates = SNDRV_PCM_RATE_8000_96000,
  1927. .formats = WM8995_FORMATS
  1928. },
  1929. .capture = {
  1930. .stream_name = "AIF1 Capture",
  1931. .channels_min = 2,
  1932. .channels_max = 2,
  1933. .rates = SNDRV_PCM_RATE_8000_48000,
  1934. .formats = WM8995_FORMATS
  1935. },
  1936. .ops = &wm8995_aif1_dai_ops
  1937. },
  1938. {
  1939. .name = "wm8995-aif2",
  1940. .playback = {
  1941. .stream_name = "AIF2 Playback",
  1942. .channels_min = 2,
  1943. .channels_max = 2,
  1944. .rates = SNDRV_PCM_RATE_8000_96000,
  1945. .formats = WM8995_FORMATS
  1946. },
  1947. .capture = {
  1948. .stream_name = "AIF2 Capture",
  1949. .channels_min = 2,
  1950. .channels_max = 2,
  1951. .rates = SNDRV_PCM_RATE_8000_48000,
  1952. .formats = WM8995_FORMATS
  1953. },
  1954. .ops = &wm8995_aif2_dai_ops
  1955. },
  1956. {
  1957. .name = "wm8995-aif3",
  1958. .playback = {
  1959. .stream_name = "AIF3 Playback",
  1960. .channels_min = 2,
  1961. .channels_max = 2,
  1962. .rates = SNDRV_PCM_RATE_8000_96000,
  1963. .formats = WM8995_FORMATS
  1964. },
  1965. .capture = {
  1966. .stream_name = "AIF3 Capture",
  1967. .channels_min = 2,
  1968. .channels_max = 2,
  1969. .rates = SNDRV_PCM_RATE_8000_48000,
  1970. .formats = WM8995_FORMATS
  1971. },
  1972. .ops = &wm8995_aif3_dai_ops
  1973. }
  1974. };
  1975. static struct snd_soc_codec_driver soc_codec_dev_wm8995 = {
  1976. .probe = wm8995_probe,
  1977. .remove = wm8995_remove,
  1978. .suspend = wm8995_suspend,
  1979. .resume = wm8995_resume,
  1980. .set_bias_level = wm8995_set_bias_level,
  1981. .idle_bias_off = true,
  1982. };
  1983. static struct regmap_config wm8995_regmap = {
  1984. .reg_bits = 16,
  1985. .val_bits = 16,
  1986. .max_register = WM8995_MAX_REGISTER,
  1987. .reg_defaults = wm8995_reg_defaults,
  1988. .num_reg_defaults = ARRAY_SIZE(wm8995_reg_defaults),
  1989. .volatile_reg = wm8995_volatile,
  1990. .readable_reg = wm8995_readable,
  1991. .cache_type = REGCACHE_RBTREE,
  1992. };
  1993. #if defined(CONFIG_SPI_MASTER)
  1994. static int __devinit wm8995_spi_probe(struct spi_device *spi)
  1995. {
  1996. struct wm8995_priv *wm8995;
  1997. int ret;
  1998. wm8995 = kzalloc(sizeof *wm8995, GFP_KERNEL);
  1999. if (!wm8995)
  2000. return -ENOMEM;
  2001. spi_set_drvdata(spi, wm8995);
  2002. wm8995->regmap = regmap_init_spi(spi, &wm8995_regmap);
  2003. if (IS_ERR(wm8995->regmap)) {
  2004. ret = PTR_ERR(wm8995->regmap);
  2005. dev_err(&spi->dev, "Failed to register regmap: %d\n", ret);
  2006. goto err_alloc;
  2007. }
  2008. ret = snd_soc_register_codec(&spi->dev,
  2009. &soc_codec_dev_wm8995, wm8995_dai,
  2010. ARRAY_SIZE(wm8995_dai));
  2011. if (ret < 0)
  2012. goto err_regmap;
  2013. return ret;
  2014. err_regmap:
  2015. regmap_exit(wm8995->regmap);
  2016. err_alloc:
  2017. kfree(wm8995);
  2018. return ret;
  2019. }
  2020. static int __devexit wm8995_spi_remove(struct spi_device *spi)
  2021. {
  2022. struct wm8995_priv *wm8995 = spi_get_drvdata(spi);
  2023. snd_soc_unregister_codec(&spi->dev);
  2024. regmap_exit(wm8995->regmap);
  2025. kfree(wm8995);
  2026. return 0;
  2027. }
  2028. static struct spi_driver wm8995_spi_driver = {
  2029. .driver = {
  2030. .name = "wm8995",
  2031. .owner = THIS_MODULE,
  2032. },
  2033. .probe = wm8995_spi_probe,
  2034. .remove = __devexit_p(wm8995_spi_remove)
  2035. };
  2036. #endif
  2037. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  2038. static __devinit int wm8995_i2c_probe(struct i2c_client *i2c,
  2039. const struct i2c_device_id *id)
  2040. {
  2041. struct wm8995_priv *wm8995;
  2042. int ret;
  2043. wm8995 = kzalloc(sizeof *wm8995, GFP_KERNEL);
  2044. if (!wm8995)
  2045. return -ENOMEM;
  2046. i2c_set_clientdata(i2c, wm8995);
  2047. wm8995->regmap = regmap_init_i2c(i2c, &wm8995_regmap);
  2048. if (IS_ERR(wm8995->regmap)) {
  2049. ret = PTR_ERR(wm8995->regmap);
  2050. dev_err(&i2c->dev, "Failed to register regmap: %d\n", ret);
  2051. goto err_alloc;
  2052. }
  2053. ret = snd_soc_register_codec(&i2c->dev,
  2054. &soc_codec_dev_wm8995, wm8995_dai,
  2055. ARRAY_SIZE(wm8995_dai));
  2056. if (ret < 0) {
  2057. dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret);
  2058. goto err_regmap;
  2059. }
  2060. return ret;
  2061. err_regmap:
  2062. regmap_exit(wm8995->regmap);
  2063. err_alloc:
  2064. kfree(wm8995);
  2065. return ret;
  2066. }
  2067. static __devexit int wm8995_i2c_remove(struct i2c_client *client)
  2068. {
  2069. struct wm8995_priv *wm8995 = i2c_get_clientdata(client);
  2070. snd_soc_unregister_codec(&client->dev);
  2071. regmap_exit(wm8995->regmap);
  2072. kfree(wm8995);
  2073. return 0;
  2074. }
  2075. static const struct i2c_device_id wm8995_i2c_id[] = {
  2076. {"wm8995", 0},
  2077. {}
  2078. };
  2079. MODULE_DEVICE_TABLE(i2c, wm8995_i2c_id);
  2080. static struct i2c_driver wm8995_i2c_driver = {
  2081. .driver = {
  2082. .name = "wm8995",
  2083. .owner = THIS_MODULE,
  2084. },
  2085. .probe = wm8995_i2c_probe,
  2086. .remove = __devexit_p(wm8995_i2c_remove),
  2087. .id_table = wm8995_i2c_id
  2088. };
  2089. #endif
  2090. static int __init wm8995_modinit(void)
  2091. {
  2092. int ret = 0;
  2093. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  2094. ret = i2c_add_driver(&wm8995_i2c_driver);
  2095. if (ret) {
  2096. printk(KERN_ERR "Failed to register wm8995 I2C driver: %d\n",
  2097. ret);
  2098. }
  2099. #endif
  2100. #if defined(CONFIG_SPI_MASTER)
  2101. ret = spi_register_driver(&wm8995_spi_driver);
  2102. if (ret) {
  2103. printk(KERN_ERR "Failed to register wm8995 SPI driver: %d\n",
  2104. ret);
  2105. }
  2106. #endif
  2107. return ret;
  2108. }
  2109. module_init(wm8995_modinit);
  2110. static void __exit wm8995_exit(void)
  2111. {
  2112. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  2113. i2c_del_driver(&wm8995_i2c_driver);
  2114. #endif
  2115. #if defined(CONFIG_SPI_MASTER)
  2116. spi_unregister_driver(&wm8995_spi_driver);
  2117. #endif
  2118. }
  2119. module_exit(wm8995_exit);
  2120. MODULE_DESCRIPTION("ASoC WM8995 driver");
  2121. MODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>");
  2122. MODULE_LICENSE("GPL");