wm8995.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347
  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 const 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 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 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 SOC_ENUM_SINGLE_DECL(dmic_src1_enum, WM8995_POWER_MANAGEMENT_5,
  426. 8, dmic_src_text);
  427. static 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. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
  509. unsigned int reg;
  510. const char *clk;
  511. reg = snd_soc_read(codec, WM8995_CLOCKING_1);
  512. /* Check what we're currently using for CLK_SYS */
  513. if (reg & WM8995_SYSCLK_SRC)
  514. clk = "AIF2CLK";
  515. else
  516. clk = "AIF1CLK";
  517. return !strcmp(source->name, clk);
  518. }
  519. static int wm8995_put_class_w(struct snd_kcontrol *kcontrol,
  520. struct snd_ctl_elem_value *ucontrol)
  521. {
  522. struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol);
  523. int ret;
  524. ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
  525. wm8995_update_class_w(codec);
  526. return ret;
  527. }
  528. static int hp_supply_event(struct snd_soc_dapm_widget *w,
  529. struct snd_kcontrol *kcontrol, int event)
  530. {
  531. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  532. switch (event) {
  533. case SND_SOC_DAPM_PRE_PMU:
  534. /* Enable the headphone amp */
  535. snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1,
  536. WM8995_HPOUT1L_ENA_MASK |
  537. WM8995_HPOUT1R_ENA_MASK,
  538. WM8995_HPOUT1L_ENA |
  539. WM8995_HPOUT1R_ENA);
  540. /* Enable the second stage */
  541. snd_soc_update_bits(codec, WM8995_ANALOGUE_HP_1,
  542. WM8995_HPOUT1L_DLY_MASK |
  543. WM8995_HPOUT1R_DLY_MASK,
  544. WM8995_HPOUT1L_DLY |
  545. WM8995_HPOUT1R_DLY);
  546. break;
  547. case SND_SOC_DAPM_PRE_PMD:
  548. snd_soc_update_bits(codec, WM8995_CHARGE_PUMP_1,
  549. WM8995_CP_ENA_MASK, 0);
  550. break;
  551. }
  552. return 0;
  553. }
  554. static void dc_servo_cmd(struct snd_soc_codec *codec,
  555. unsigned int reg, unsigned int val, unsigned int mask)
  556. {
  557. int timeout = 10;
  558. dev_dbg(codec->dev, "%s: reg = %#x, val = %#x, mask = %#x\n",
  559. __func__, reg, val, mask);
  560. snd_soc_write(codec, reg, val);
  561. while (timeout--) {
  562. msleep(10);
  563. val = snd_soc_read(codec, WM8995_DC_SERVO_READBACK_0);
  564. if ((val & mask) == mask)
  565. return;
  566. }
  567. dev_err(codec->dev, "Timed out waiting for DC Servo\n");
  568. }
  569. static int hp_event(struct snd_soc_dapm_widget *w,
  570. struct snd_kcontrol *kcontrol, int event)
  571. {
  572. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  573. unsigned int reg;
  574. reg = snd_soc_read(codec, WM8995_ANALOGUE_HP_1);
  575. switch (event) {
  576. case SND_SOC_DAPM_POST_PMU:
  577. snd_soc_update_bits(codec, WM8995_CHARGE_PUMP_1,
  578. WM8995_CP_ENA_MASK, WM8995_CP_ENA);
  579. msleep(5);
  580. snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1,
  581. WM8995_HPOUT1L_ENA_MASK |
  582. WM8995_HPOUT1R_ENA_MASK,
  583. WM8995_HPOUT1L_ENA | WM8995_HPOUT1R_ENA);
  584. udelay(20);
  585. reg |= WM8995_HPOUT1L_DLY | WM8995_HPOUT1R_DLY;
  586. snd_soc_write(codec, WM8995_ANALOGUE_HP_1, reg);
  587. snd_soc_write(codec, WM8995_DC_SERVO_1, WM8995_DCS_ENA_CHAN_0 |
  588. WM8995_DCS_ENA_CHAN_1);
  589. dc_servo_cmd(codec, WM8995_DC_SERVO_2,
  590. WM8995_DCS_TRIG_STARTUP_0 |
  591. WM8995_DCS_TRIG_STARTUP_1,
  592. WM8995_DCS_TRIG_DAC_WR_0 |
  593. WM8995_DCS_TRIG_DAC_WR_1);
  594. reg |= WM8995_HPOUT1R_OUTP | WM8995_HPOUT1R_RMV_SHORT |
  595. WM8995_HPOUT1L_OUTP | WM8995_HPOUT1L_RMV_SHORT;
  596. snd_soc_write(codec, WM8995_ANALOGUE_HP_1, reg);
  597. break;
  598. case SND_SOC_DAPM_PRE_PMD:
  599. snd_soc_update_bits(codec, WM8995_ANALOGUE_HP_1,
  600. WM8995_HPOUT1L_OUTP_MASK |
  601. WM8995_HPOUT1R_OUTP_MASK |
  602. WM8995_HPOUT1L_RMV_SHORT_MASK |
  603. WM8995_HPOUT1R_RMV_SHORT_MASK, 0);
  604. snd_soc_update_bits(codec, WM8995_ANALOGUE_HP_1,
  605. WM8995_HPOUT1L_DLY_MASK |
  606. WM8995_HPOUT1R_DLY_MASK, 0);
  607. snd_soc_write(codec, WM8995_DC_SERVO_1, 0);
  608. snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1,
  609. WM8995_HPOUT1L_ENA_MASK |
  610. WM8995_HPOUT1R_ENA_MASK,
  611. 0);
  612. break;
  613. }
  614. return 0;
  615. }
  616. static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
  617. {
  618. struct wm8995_priv *wm8995;
  619. int rate;
  620. int reg1 = 0;
  621. int offset;
  622. wm8995 = snd_soc_codec_get_drvdata(codec);
  623. if (aif)
  624. offset = 4;
  625. else
  626. offset = 0;
  627. switch (wm8995->sysclk[aif]) {
  628. case WM8995_SYSCLK_MCLK1:
  629. rate = wm8995->mclk[0];
  630. break;
  631. case WM8995_SYSCLK_MCLK2:
  632. reg1 |= 0x8;
  633. rate = wm8995->mclk[1];
  634. break;
  635. case WM8995_SYSCLK_FLL1:
  636. reg1 |= 0x10;
  637. rate = wm8995->fll[0].out;
  638. break;
  639. case WM8995_SYSCLK_FLL2:
  640. reg1 |= 0x18;
  641. rate = wm8995->fll[1].out;
  642. break;
  643. default:
  644. return -EINVAL;
  645. }
  646. if (rate >= 13500000) {
  647. rate /= 2;
  648. reg1 |= WM8995_AIF1CLK_DIV;
  649. dev_dbg(codec->dev, "Dividing AIF%d clock to %dHz\n",
  650. aif + 1, rate);
  651. }
  652. wm8995->aifclk[aif] = rate;
  653. snd_soc_update_bits(codec, WM8995_AIF1_CLOCKING_1 + offset,
  654. WM8995_AIF1CLK_SRC_MASK | WM8995_AIF1CLK_DIV_MASK,
  655. reg1);
  656. return 0;
  657. }
  658. static int configure_clock(struct snd_soc_codec *codec)
  659. {
  660. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  661. struct wm8995_priv *wm8995;
  662. int change, new;
  663. wm8995 = snd_soc_codec_get_drvdata(codec);
  664. /* Bring up the AIF clocks first */
  665. configure_aif_clock(codec, 0);
  666. configure_aif_clock(codec, 1);
  667. /*
  668. * Then switch CLK_SYS over to the higher of them; a change
  669. * can only happen as a result of a clocking change which can
  670. * only be made outside of DAPM so we can safely redo the
  671. * clocking.
  672. */
  673. /* If they're equal it doesn't matter which is used */
  674. if (wm8995->aifclk[0] == wm8995->aifclk[1])
  675. return 0;
  676. if (wm8995->aifclk[0] < wm8995->aifclk[1])
  677. new = WM8995_SYSCLK_SRC;
  678. else
  679. new = 0;
  680. change = snd_soc_update_bits(codec, WM8995_CLOCKING_1,
  681. WM8995_SYSCLK_SRC_MASK, new);
  682. if (!change)
  683. return 0;
  684. snd_soc_dapm_sync(dapm);
  685. return 0;
  686. }
  687. static int clk_sys_event(struct snd_soc_dapm_widget *w,
  688. struct snd_kcontrol *kcontrol, int event)
  689. {
  690. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  691. switch (event) {
  692. case SND_SOC_DAPM_PRE_PMU:
  693. return configure_clock(codec);
  694. case SND_SOC_DAPM_POST_PMD:
  695. configure_clock(codec);
  696. break;
  697. }
  698. return 0;
  699. }
  700. static const char *sidetone_text[] = {
  701. "ADC/DMIC1", "DMIC2",
  702. };
  703. static SOC_ENUM_SINGLE_DECL(sidetone1_enum, WM8995_SIDETONE, 0, sidetone_text);
  704. static const struct snd_kcontrol_new sidetone1_mux =
  705. SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
  706. static SOC_ENUM_SINGLE_DECL(sidetone2_enum, WM8995_SIDETONE, 1, sidetone_text);
  707. static const struct snd_kcontrol_new sidetone2_mux =
  708. SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
  709. static const struct snd_kcontrol_new aif1adc1l_mix[] = {
  710. SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING,
  711. 1, 1, 0),
  712. SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING,
  713. 0, 1, 0),
  714. };
  715. static const struct snd_kcontrol_new aif1adc1r_mix[] = {
  716. SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING,
  717. 1, 1, 0),
  718. SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING,
  719. 0, 1, 0),
  720. };
  721. static const struct snd_kcontrol_new aif1adc2l_mix[] = {
  722. SOC_DAPM_SINGLE("DMIC Switch", WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING,
  723. 1, 1, 0),
  724. SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING,
  725. 0, 1, 0),
  726. };
  727. static const struct snd_kcontrol_new aif1adc2r_mix[] = {
  728. SOC_DAPM_SINGLE("DMIC Switch", WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING,
  729. 1, 1, 0),
  730. SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING,
  731. 0, 1, 0),
  732. };
  733. static const struct snd_kcontrol_new dac1l_mix[] = {
  734. WM8995_CLASS_W_SWITCH("Right Sidetone Switch", WM8995_DAC1_LEFT_MIXER_ROUTING,
  735. 5, 1, 0),
  736. WM8995_CLASS_W_SWITCH("Left Sidetone Switch", WM8995_DAC1_LEFT_MIXER_ROUTING,
  737. 4, 1, 0),
  738. WM8995_CLASS_W_SWITCH("AIF2 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING,
  739. 2, 1, 0),
  740. WM8995_CLASS_W_SWITCH("AIF1.2 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING,
  741. 1, 1, 0),
  742. WM8995_CLASS_W_SWITCH("AIF1.1 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING,
  743. 0, 1, 0),
  744. };
  745. static const struct snd_kcontrol_new dac1r_mix[] = {
  746. WM8995_CLASS_W_SWITCH("Right Sidetone Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING,
  747. 5, 1, 0),
  748. WM8995_CLASS_W_SWITCH("Left Sidetone Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING,
  749. 4, 1, 0),
  750. WM8995_CLASS_W_SWITCH("AIF2 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING,
  751. 2, 1, 0),
  752. WM8995_CLASS_W_SWITCH("AIF1.2 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING,
  753. 1, 1, 0),
  754. WM8995_CLASS_W_SWITCH("AIF1.1 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING,
  755. 0, 1, 0),
  756. };
  757. static const struct snd_kcontrol_new aif2dac2l_mix[] = {
  758. SOC_DAPM_SINGLE("Right Sidetone Switch", WM8995_DAC2_LEFT_MIXER_ROUTING,
  759. 5, 1, 0),
  760. SOC_DAPM_SINGLE("Left Sidetone Switch", WM8995_DAC2_LEFT_MIXER_ROUTING,
  761. 4, 1, 0),
  762. SOC_DAPM_SINGLE("AIF2 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING,
  763. 2, 1, 0),
  764. SOC_DAPM_SINGLE("AIF1.2 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING,
  765. 1, 1, 0),
  766. SOC_DAPM_SINGLE("AIF1.1 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING,
  767. 0, 1, 0),
  768. };
  769. static const struct snd_kcontrol_new aif2dac2r_mix[] = {
  770. SOC_DAPM_SINGLE("Right Sidetone Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING,
  771. 5, 1, 0),
  772. SOC_DAPM_SINGLE("Left Sidetone Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING,
  773. 4, 1, 0),
  774. SOC_DAPM_SINGLE("AIF2 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING,
  775. 2, 1, 0),
  776. SOC_DAPM_SINGLE("AIF1.2 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING,
  777. 1, 1, 0),
  778. SOC_DAPM_SINGLE("AIF1.1 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING,
  779. 0, 1, 0),
  780. };
  781. static const struct snd_kcontrol_new in1l_pga =
  782. SOC_DAPM_SINGLE("IN1L Switch", WM8995_POWER_MANAGEMENT_2, 5, 1, 0);
  783. static const struct snd_kcontrol_new in1r_pga =
  784. SOC_DAPM_SINGLE("IN1R Switch", WM8995_POWER_MANAGEMENT_2, 4, 1, 0);
  785. static const char *adc_mux_text[] = {
  786. "ADC",
  787. "DMIC",
  788. };
  789. static SOC_ENUM_SINGLE_VIRT_DECL(adc_enum, adc_mux_text);
  790. static const struct snd_kcontrol_new adcl_mux =
  791. SOC_DAPM_ENUM("ADCL Mux", adc_enum);
  792. static const struct snd_kcontrol_new adcr_mux =
  793. SOC_DAPM_ENUM("ADCR Mux", adc_enum);
  794. static const char *spk_src_text[] = {
  795. "DAC1L", "DAC1R", "DAC2L", "DAC2R"
  796. };
  797. static SOC_ENUM_SINGLE_DECL(spk1l_src_enum, WM8995_LEFT_PDM_SPEAKER_1,
  798. 0, spk_src_text);
  799. static SOC_ENUM_SINGLE_DECL(spk1r_src_enum, WM8995_RIGHT_PDM_SPEAKER_1,
  800. 0, spk_src_text);
  801. static SOC_ENUM_SINGLE_DECL(spk2l_src_enum, WM8995_LEFT_PDM_SPEAKER_2,
  802. 0, spk_src_text);
  803. static SOC_ENUM_SINGLE_DECL(spk2r_src_enum, WM8995_RIGHT_PDM_SPEAKER_2,
  804. 0, spk_src_text);
  805. static const struct snd_kcontrol_new spk1l_mux =
  806. SOC_DAPM_ENUM("SPK1L SRC", spk1l_src_enum);
  807. static const struct snd_kcontrol_new spk1r_mux =
  808. SOC_DAPM_ENUM("SPK1R SRC", spk1r_src_enum);
  809. static const struct snd_kcontrol_new spk2l_mux =
  810. SOC_DAPM_ENUM("SPK2L SRC", spk2l_src_enum);
  811. static const struct snd_kcontrol_new spk2r_mux =
  812. SOC_DAPM_ENUM("SPK2R SRC", spk2r_src_enum);
  813. static const struct snd_soc_dapm_widget wm8995_dapm_widgets[] = {
  814. SND_SOC_DAPM_INPUT("DMIC1DAT"),
  815. SND_SOC_DAPM_INPUT("DMIC2DAT"),
  816. SND_SOC_DAPM_INPUT("IN1L"),
  817. SND_SOC_DAPM_INPUT("IN1R"),
  818. SND_SOC_DAPM_MIXER("IN1L PGA", SND_SOC_NOPM, 0, 0,
  819. &in1l_pga, 1),
  820. SND_SOC_DAPM_MIXER("IN1R PGA", SND_SOC_NOPM, 0, 0,
  821. &in1r_pga, 1),
  822. SND_SOC_DAPM_SUPPLY("MICBIAS1", WM8995_POWER_MANAGEMENT_1, 8, 0,
  823. NULL, 0),
  824. SND_SOC_DAPM_SUPPLY("MICBIAS2", WM8995_POWER_MANAGEMENT_1, 9, 0,
  825. NULL, 0),
  826. SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8995_AIF1_CLOCKING_1, 0, 0, NULL, 0),
  827. SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8995_AIF2_CLOCKING_1, 0, 0, NULL, 0),
  828. SND_SOC_DAPM_SUPPLY("DSP1CLK", WM8995_CLOCKING_1, 3, 0, NULL, 0),
  829. SND_SOC_DAPM_SUPPLY("DSP2CLK", WM8995_CLOCKING_1, 2, 0, NULL, 0),
  830. SND_SOC_DAPM_SUPPLY("SYSDSPCLK", WM8995_CLOCKING_1, 1, 0, NULL, 0),
  831. SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
  832. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  833. SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", "AIF1 Capture", 0,
  834. WM8995_POWER_MANAGEMENT_3, 9, 0),
  835. SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", "AIF1 Capture", 0,
  836. WM8995_POWER_MANAGEMENT_3, 8, 0),
  837. SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", "AIF1 Capture", 0,
  838. SND_SOC_NOPM, 0, 0),
  839. SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", "AIF1 Capture",
  840. 0, WM8995_POWER_MANAGEMENT_3, 11, 0),
  841. SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", "AIF1 Capture",
  842. 0, WM8995_POWER_MANAGEMENT_3, 10, 0),
  843. SND_SOC_DAPM_MUX("ADCL Mux", SND_SOC_NOPM, 1, 0, &adcl_mux),
  844. SND_SOC_DAPM_MUX("ADCR Mux", SND_SOC_NOPM, 0, 0, &adcr_mux),
  845. SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8995_POWER_MANAGEMENT_3, 5, 0),
  846. SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8995_POWER_MANAGEMENT_3, 4, 0),
  847. SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8995_POWER_MANAGEMENT_3, 3, 0),
  848. SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8995_POWER_MANAGEMENT_3, 2, 0),
  849. SND_SOC_DAPM_ADC("ADCL", NULL, WM8995_POWER_MANAGEMENT_3, 1, 0),
  850. SND_SOC_DAPM_ADC("ADCR", NULL, WM8995_POWER_MANAGEMENT_3, 0, 0),
  851. SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
  852. aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
  853. SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
  854. aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
  855. SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
  856. aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
  857. SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
  858. aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
  859. SND_SOC_DAPM_AIF_IN("AIF1DAC1L", NULL, 0, WM8995_POWER_MANAGEMENT_4,
  860. 9, 0),
  861. SND_SOC_DAPM_AIF_IN("AIF1DAC1R", NULL, 0, WM8995_POWER_MANAGEMENT_4,
  862. 8, 0),
  863. SND_SOC_DAPM_AIF_IN("AIF1DACDAT", "AIF1 Playback", 0, SND_SOC_NOPM,
  864. 0, 0),
  865. SND_SOC_DAPM_AIF_IN("AIF1DAC2L", NULL, 0, WM8995_POWER_MANAGEMENT_4,
  866. 11, 0),
  867. SND_SOC_DAPM_AIF_IN("AIF1DAC2R", NULL, 0, WM8995_POWER_MANAGEMENT_4,
  868. 10, 0),
  869. SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
  870. aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
  871. SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
  872. aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
  873. SND_SOC_DAPM_DAC("DAC2L", NULL, WM8995_POWER_MANAGEMENT_4, 3, 0),
  874. SND_SOC_DAPM_DAC("DAC2R", NULL, WM8995_POWER_MANAGEMENT_4, 2, 0),
  875. SND_SOC_DAPM_DAC("DAC1L", NULL, WM8995_POWER_MANAGEMENT_4, 1, 0),
  876. SND_SOC_DAPM_DAC("DAC1R", NULL, WM8995_POWER_MANAGEMENT_4, 0, 0),
  877. SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0, dac1l_mix,
  878. ARRAY_SIZE(dac1l_mix)),
  879. SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0, dac1r_mix,
  880. ARRAY_SIZE(dac1r_mix)),
  881. SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
  882. SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
  883. SND_SOC_DAPM_PGA_E("Headphone PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
  884. hp_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  885. SND_SOC_DAPM_SUPPLY("Headphone Supply", SND_SOC_NOPM, 0, 0,
  886. hp_supply_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  887. SND_SOC_DAPM_MUX("SPK1L Driver", WM8995_LEFT_PDM_SPEAKER_1,
  888. 4, 0, &spk1l_mux),
  889. SND_SOC_DAPM_MUX("SPK1R Driver", WM8995_RIGHT_PDM_SPEAKER_1,
  890. 4, 0, &spk1r_mux),
  891. SND_SOC_DAPM_MUX("SPK2L Driver", WM8995_LEFT_PDM_SPEAKER_2,
  892. 4, 0, &spk2l_mux),
  893. SND_SOC_DAPM_MUX("SPK2R Driver", WM8995_RIGHT_PDM_SPEAKER_2,
  894. 4, 0, &spk2r_mux),
  895. SND_SOC_DAPM_SUPPLY("LDO2", WM8995_POWER_MANAGEMENT_2, 1, 0, NULL, 0),
  896. SND_SOC_DAPM_OUTPUT("HP1L"),
  897. SND_SOC_DAPM_OUTPUT("HP1R"),
  898. SND_SOC_DAPM_OUTPUT("SPK1L"),
  899. SND_SOC_DAPM_OUTPUT("SPK1R"),
  900. SND_SOC_DAPM_OUTPUT("SPK2L"),
  901. SND_SOC_DAPM_OUTPUT("SPK2R")
  902. };
  903. static const struct snd_soc_dapm_route wm8995_intercon[] = {
  904. { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
  905. { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
  906. { "DSP1CLK", NULL, "CLK_SYS" },
  907. { "DSP2CLK", NULL, "CLK_SYS" },
  908. { "SYSDSPCLK", NULL, "CLK_SYS" },
  909. { "AIF1ADC1L", NULL, "AIF1CLK" },
  910. { "AIF1ADC1L", NULL, "DSP1CLK" },
  911. { "AIF1ADC1R", NULL, "AIF1CLK" },
  912. { "AIF1ADC1R", NULL, "DSP1CLK" },
  913. { "AIF1ADC1R", NULL, "SYSDSPCLK" },
  914. { "AIF1ADC2L", NULL, "AIF1CLK" },
  915. { "AIF1ADC2L", NULL, "DSP1CLK" },
  916. { "AIF1ADC2R", NULL, "AIF1CLK" },
  917. { "AIF1ADC2R", NULL, "DSP1CLK" },
  918. { "AIF1ADC2R", NULL, "SYSDSPCLK" },
  919. { "DMIC1L", NULL, "DMIC1DAT" },
  920. { "DMIC1L", NULL, "CLK_SYS" },
  921. { "DMIC1R", NULL, "DMIC1DAT" },
  922. { "DMIC1R", NULL, "CLK_SYS" },
  923. { "DMIC2L", NULL, "DMIC2DAT" },
  924. { "DMIC2L", NULL, "CLK_SYS" },
  925. { "DMIC2R", NULL, "DMIC2DAT" },
  926. { "DMIC2R", NULL, "CLK_SYS" },
  927. { "ADCL", NULL, "AIF1CLK" },
  928. { "ADCL", NULL, "DSP1CLK" },
  929. { "ADCL", NULL, "SYSDSPCLK" },
  930. { "ADCR", NULL, "AIF1CLK" },
  931. { "ADCR", NULL, "DSP1CLK" },
  932. { "ADCR", NULL, "SYSDSPCLK" },
  933. { "IN1L PGA", "IN1L Switch", "IN1L" },
  934. { "IN1R PGA", "IN1R Switch", "IN1R" },
  935. { "IN1L PGA", NULL, "LDO2" },
  936. { "IN1R PGA", NULL, "LDO2" },
  937. { "ADCL", NULL, "IN1L PGA" },
  938. { "ADCR", NULL, "IN1R PGA" },
  939. { "ADCL Mux", "ADC", "ADCL" },
  940. { "ADCL Mux", "DMIC", "DMIC1L" },
  941. { "ADCR Mux", "ADC", "ADCR" },
  942. { "ADCR Mux", "DMIC", "DMIC1R" },
  943. /* AIF1 outputs */
  944. { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
  945. { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
  946. { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
  947. { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
  948. { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
  949. { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
  950. { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
  951. { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
  952. /* Sidetone */
  953. { "Left Sidetone", "ADC/DMIC1", "AIF1ADC1L" },
  954. { "Left Sidetone", "DMIC2", "AIF1ADC2L" },
  955. { "Right Sidetone", "ADC/DMIC1", "AIF1ADC1R" },
  956. { "Right Sidetone", "DMIC2", "AIF1ADC2R" },
  957. { "AIF1DAC1L", NULL, "AIF1CLK" },
  958. { "AIF1DAC1L", NULL, "DSP1CLK" },
  959. { "AIF1DAC1R", NULL, "AIF1CLK" },
  960. { "AIF1DAC1R", NULL, "DSP1CLK" },
  961. { "AIF1DAC1R", NULL, "SYSDSPCLK" },
  962. { "AIF1DAC2L", NULL, "AIF1CLK" },
  963. { "AIF1DAC2L", NULL, "DSP1CLK" },
  964. { "AIF1DAC2R", NULL, "AIF1CLK" },
  965. { "AIF1DAC2R", NULL, "DSP1CLK" },
  966. { "AIF1DAC2R", NULL, "SYSDSPCLK" },
  967. { "DAC1L", NULL, "AIF1CLK" },
  968. { "DAC1L", NULL, "DSP1CLK" },
  969. { "DAC1L", NULL, "SYSDSPCLK" },
  970. { "DAC1R", NULL, "AIF1CLK" },
  971. { "DAC1R", NULL, "DSP1CLK" },
  972. { "DAC1R", NULL, "SYSDSPCLK" },
  973. { "AIF1DAC1L", NULL, "AIF1DACDAT" },
  974. { "AIF1DAC1R", NULL, "AIF1DACDAT" },
  975. { "AIF1DAC2L", NULL, "AIF1DACDAT" },
  976. { "AIF1DAC2R", NULL, "AIF1DACDAT" },
  977. /* DAC1 inputs */
  978. { "DAC1L", NULL, "DAC1L Mixer" },
  979. { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
  980. { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
  981. { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
  982. { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
  983. { "DAC1R", NULL, "DAC1R Mixer" },
  984. { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
  985. { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
  986. { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
  987. { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
  988. /* DAC2/AIF2 outputs */
  989. { "DAC2L", NULL, "AIF2DAC2L Mixer" },
  990. { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
  991. { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
  992. { "DAC2R", NULL, "AIF2DAC2R Mixer" },
  993. { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
  994. { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
  995. /* Output stages */
  996. { "Headphone PGA", NULL, "DAC1L" },
  997. { "Headphone PGA", NULL, "DAC1R" },
  998. { "Headphone PGA", NULL, "DAC2L" },
  999. { "Headphone PGA", NULL, "DAC2R" },
  1000. { "Headphone PGA", NULL, "Headphone Supply" },
  1001. { "Headphone PGA", NULL, "CLK_SYS" },
  1002. { "Headphone PGA", NULL, "LDO2" },
  1003. { "HP1L", NULL, "Headphone PGA" },
  1004. { "HP1R", NULL, "Headphone PGA" },
  1005. { "SPK1L Driver", "DAC1L", "DAC1L" },
  1006. { "SPK1L Driver", "DAC1R", "DAC1R" },
  1007. { "SPK1L Driver", "DAC2L", "DAC2L" },
  1008. { "SPK1L Driver", "DAC2R", "DAC2R" },
  1009. { "SPK1L Driver", NULL, "CLK_SYS" },
  1010. { "SPK1R Driver", "DAC1L", "DAC1L" },
  1011. { "SPK1R Driver", "DAC1R", "DAC1R" },
  1012. { "SPK1R Driver", "DAC2L", "DAC2L" },
  1013. { "SPK1R Driver", "DAC2R", "DAC2R" },
  1014. { "SPK1R Driver", NULL, "CLK_SYS" },
  1015. { "SPK2L Driver", "DAC1L", "DAC1L" },
  1016. { "SPK2L Driver", "DAC1R", "DAC1R" },
  1017. { "SPK2L Driver", "DAC2L", "DAC2L" },
  1018. { "SPK2L Driver", "DAC2R", "DAC2R" },
  1019. { "SPK2L Driver", NULL, "CLK_SYS" },
  1020. { "SPK2R Driver", "DAC1L", "DAC1L" },
  1021. { "SPK2R Driver", "DAC1R", "DAC1R" },
  1022. { "SPK2R Driver", "DAC2L", "DAC2L" },
  1023. { "SPK2R Driver", "DAC2R", "DAC2R" },
  1024. { "SPK2R Driver", NULL, "CLK_SYS" },
  1025. { "SPK1L", NULL, "SPK1L Driver" },
  1026. { "SPK1R", NULL, "SPK1R Driver" },
  1027. { "SPK2L", NULL, "SPK2L Driver" },
  1028. { "SPK2R", NULL, "SPK2R Driver" }
  1029. };
  1030. static bool wm8995_readable(struct device *dev, unsigned int reg)
  1031. {
  1032. switch (reg) {
  1033. case WM8995_SOFTWARE_RESET:
  1034. case WM8995_POWER_MANAGEMENT_1:
  1035. case WM8995_POWER_MANAGEMENT_2:
  1036. case WM8995_POWER_MANAGEMENT_3:
  1037. case WM8995_POWER_MANAGEMENT_4:
  1038. case WM8995_POWER_MANAGEMENT_5:
  1039. case WM8995_LEFT_LINE_INPUT_1_VOLUME:
  1040. case WM8995_RIGHT_LINE_INPUT_1_VOLUME:
  1041. case WM8995_LEFT_LINE_INPUT_CONTROL:
  1042. case WM8995_DAC1_LEFT_VOLUME:
  1043. case WM8995_DAC1_RIGHT_VOLUME:
  1044. case WM8995_DAC2_LEFT_VOLUME:
  1045. case WM8995_DAC2_RIGHT_VOLUME:
  1046. case WM8995_OUTPUT_VOLUME_ZC_1:
  1047. case WM8995_MICBIAS_1:
  1048. case WM8995_MICBIAS_2:
  1049. case WM8995_LDO_1:
  1050. case WM8995_LDO_2:
  1051. case WM8995_ACCESSORY_DETECT_MODE1:
  1052. case WM8995_ACCESSORY_DETECT_MODE2:
  1053. case WM8995_HEADPHONE_DETECT1:
  1054. case WM8995_HEADPHONE_DETECT2:
  1055. case WM8995_MIC_DETECT_1:
  1056. case WM8995_MIC_DETECT_2:
  1057. case WM8995_CHARGE_PUMP_1:
  1058. case WM8995_CLASS_W_1:
  1059. case WM8995_DC_SERVO_1:
  1060. case WM8995_DC_SERVO_2:
  1061. case WM8995_DC_SERVO_3:
  1062. case WM8995_DC_SERVO_5:
  1063. case WM8995_DC_SERVO_6:
  1064. case WM8995_DC_SERVO_7:
  1065. case WM8995_DC_SERVO_READBACK_0:
  1066. case WM8995_ANALOGUE_HP_1:
  1067. case WM8995_ANALOGUE_HP_2:
  1068. case WM8995_CHIP_REVISION:
  1069. case WM8995_CONTROL_INTERFACE_1:
  1070. case WM8995_CONTROL_INTERFACE_2:
  1071. case WM8995_WRITE_SEQUENCER_CTRL_1:
  1072. case WM8995_WRITE_SEQUENCER_CTRL_2:
  1073. case WM8995_AIF1_CLOCKING_1:
  1074. case WM8995_AIF1_CLOCKING_2:
  1075. case WM8995_AIF2_CLOCKING_1:
  1076. case WM8995_AIF2_CLOCKING_2:
  1077. case WM8995_CLOCKING_1:
  1078. case WM8995_CLOCKING_2:
  1079. case WM8995_AIF1_RATE:
  1080. case WM8995_AIF2_RATE:
  1081. case WM8995_RATE_STATUS:
  1082. case WM8995_FLL1_CONTROL_1:
  1083. case WM8995_FLL1_CONTROL_2:
  1084. case WM8995_FLL1_CONTROL_3:
  1085. case WM8995_FLL1_CONTROL_4:
  1086. case WM8995_FLL1_CONTROL_5:
  1087. case WM8995_FLL2_CONTROL_1:
  1088. case WM8995_FLL2_CONTROL_2:
  1089. case WM8995_FLL2_CONTROL_3:
  1090. case WM8995_FLL2_CONTROL_4:
  1091. case WM8995_FLL2_CONTROL_5:
  1092. case WM8995_AIF1_CONTROL_1:
  1093. case WM8995_AIF1_CONTROL_2:
  1094. case WM8995_AIF1_MASTER_SLAVE:
  1095. case WM8995_AIF1_BCLK:
  1096. case WM8995_AIF1ADC_LRCLK:
  1097. case WM8995_AIF1DAC_LRCLK:
  1098. case WM8995_AIF1DAC_DATA:
  1099. case WM8995_AIF1ADC_DATA:
  1100. case WM8995_AIF2_CONTROL_1:
  1101. case WM8995_AIF2_CONTROL_2:
  1102. case WM8995_AIF2_MASTER_SLAVE:
  1103. case WM8995_AIF2_BCLK:
  1104. case WM8995_AIF2ADC_LRCLK:
  1105. case WM8995_AIF2DAC_LRCLK:
  1106. case WM8995_AIF2DAC_DATA:
  1107. case WM8995_AIF2ADC_DATA:
  1108. case WM8995_AIF1_ADC1_LEFT_VOLUME:
  1109. case WM8995_AIF1_ADC1_RIGHT_VOLUME:
  1110. case WM8995_AIF1_DAC1_LEFT_VOLUME:
  1111. case WM8995_AIF1_DAC1_RIGHT_VOLUME:
  1112. case WM8995_AIF1_ADC2_LEFT_VOLUME:
  1113. case WM8995_AIF1_ADC2_RIGHT_VOLUME:
  1114. case WM8995_AIF1_DAC2_LEFT_VOLUME:
  1115. case WM8995_AIF1_DAC2_RIGHT_VOLUME:
  1116. case WM8995_AIF1_ADC1_FILTERS:
  1117. case WM8995_AIF1_ADC2_FILTERS:
  1118. case WM8995_AIF1_DAC1_FILTERS_1:
  1119. case WM8995_AIF1_DAC1_FILTERS_2:
  1120. case WM8995_AIF1_DAC2_FILTERS_1:
  1121. case WM8995_AIF1_DAC2_FILTERS_2:
  1122. case WM8995_AIF1_DRC1_1:
  1123. case WM8995_AIF1_DRC1_2:
  1124. case WM8995_AIF1_DRC1_3:
  1125. case WM8995_AIF1_DRC1_4:
  1126. case WM8995_AIF1_DRC1_5:
  1127. case WM8995_AIF1_DRC2_1:
  1128. case WM8995_AIF1_DRC2_2:
  1129. case WM8995_AIF1_DRC2_3:
  1130. case WM8995_AIF1_DRC2_4:
  1131. case WM8995_AIF1_DRC2_5:
  1132. case WM8995_AIF1_DAC1_EQ_GAINS_1:
  1133. case WM8995_AIF1_DAC1_EQ_GAINS_2:
  1134. case WM8995_AIF1_DAC1_EQ_BAND_1_A:
  1135. case WM8995_AIF1_DAC1_EQ_BAND_1_B:
  1136. case WM8995_AIF1_DAC1_EQ_BAND_1_PG:
  1137. case WM8995_AIF1_DAC1_EQ_BAND_2_A:
  1138. case WM8995_AIF1_DAC1_EQ_BAND_2_B:
  1139. case WM8995_AIF1_DAC1_EQ_BAND_2_C:
  1140. case WM8995_AIF1_DAC1_EQ_BAND_2_PG:
  1141. case WM8995_AIF1_DAC1_EQ_BAND_3_A:
  1142. case WM8995_AIF1_DAC1_EQ_BAND_3_B:
  1143. case WM8995_AIF1_DAC1_EQ_BAND_3_C:
  1144. case WM8995_AIF1_DAC1_EQ_BAND_3_PG:
  1145. case WM8995_AIF1_DAC1_EQ_BAND_4_A:
  1146. case WM8995_AIF1_DAC1_EQ_BAND_4_B:
  1147. case WM8995_AIF1_DAC1_EQ_BAND_4_C:
  1148. case WM8995_AIF1_DAC1_EQ_BAND_4_PG:
  1149. case WM8995_AIF1_DAC1_EQ_BAND_5_A:
  1150. case WM8995_AIF1_DAC1_EQ_BAND_5_B:
  1151. case WM8995_AIF1_DAC1_EQ_BAND_5_PG:
  1152. case WM8995_AIF1_DAC2_EQ_GAINS_1:
  1153. case WM8995_AIF1_DAC2_EQ_GAINS_2:
  1154. case WM8995_AIF1_DAC2_EQ_BAND_1_A:
  1155. case WM8995_AIF1_DAC2_EQ_BAND_1_B:
  1156. case WM8995_AIF1_DAC2_EQ_BAND_1_PG:
  1157. case WM8995_AIF1_DAC2_EQ_BAND_2_A:
  1158. case WM8995_AIF1_DAC2_EQ_BAND_2_B:
  1159. case WM8995_AIF1_DAC2_EQ_BAND_2_C:
  1160. case WM8995_AIF1_DAC2_EQ_BAND_2_PG:
  1161. case WM8995_AIF1_DAC2_EQ_BAND_3_A:
  1162. case WM8995_AIF1_DAC2_EQ_BAND_3_B:
  1163. case WM8995_AIF1_DAC2_EQ_BAND_3_C:
  1164. case WM8995_AIF1_DAC2_EQ_BAND_3_PG:
  1165. case WM8995_AIF1_DAC2_EQ_BAND_4_A:
  1166. case WM8995_AIF1_DAC2_EQ_BAND_4_B:
  1167. case WM8995_AIF1_DAC2_EQ_BAND_4_C:
  1168. case WM8995_AIF1_DAC2_EQ_BAND_4_PG:
  1169. case WM8995_AIF1_DAC2_EQ_BAND_5_A:
  1170. case WM8995_AIF1_DAC2_EQ_BAND_5_B:
  1171. case WM8995_AIF1_DAC2_EQ_BAND_5_PG:
  1172. case WM8995_AIF2_ADC_LEFT_VOLUME:
  1173. case WM8995_AIF2_ADC_RIGHT_VOLUME:
  1174. case WM8995_AIF2_DAC_LEFT_VOLUME:
  1175. case WM8995_AIF2_DAC_RIGHT_VOLUME:
  1176. case WM8995_AIF2_ADC_FILTERS:
  1177. case WM8995_AIF2_DAC_FILTERS_1:
  1178. case WM8995_AIF2_DAC_FILTERS_2:
  1179. case WM8995_AIF2_DRC_1:
  1180. case WM8995_AIF2_DRC_2:
  1181. case WM8995_AIF2_DRC_3:
  1182. case WM8995_AIF2_DRC_4:
  1183. case WM8995_AIF2_DRC_5:
  1184. case WM8995_AIF2_EQ_GAINS_1:
  1185. case WM8995_AIF2_EQ_GAINS_2:
  1186. case WM8995_AIF2_EQ_BAND_1_A:
  1187. case WM8995_AIF2_EQ_BAND_1_B:
  1188. case WM8995_AIF2_EQ_BAND_1_PG:
  1189. case WM8995_AIF2_EQ_BAND_2_A:
  1190. case WM8995_AIF2_EQ_BAND_2_B:
  1191. case WM8995_AIF2_EQ_BAND_2_C:
  1192. case WM8995_AIF2_EQ_BAND_2_PG:
  1193. case WM8995_AIF2_EQ_BAND_3_A:
  1194. case WM8995_AIF2_EQ_BAND_3_B:
  1195. case WM8995_AIF2_EQ_BAND_3_C:
  1196. case WM8995_AIF2_EQ_BAND_3_PG:
  1197. case WM8995_AIF2_EQ_BAND_4_A:
  1198. case WM8995_AIF2_EQ_BAND_4_B:
  1199. case WM8995_AIF2_EQ_BAND_4_C:
  1200. case WM8995_AIF2_EQ_BAND_4_PG:
  1201. case WM8995_AIF2_EQ_BAND_5_A:
  1202. case WM8995_AIF2_EQ_BAND_5_B:
  1203. case WM8995_AIF2_EQ_BAND_5_PG:
  1204. case WM8995_DAC1_MIXER_VOLUMES:
  1205. case WM8995_DAC1_LEFT_MIXER_ROUTING:
  1206. case WM8995_DAC1_RIGHT_MIXER_ROUTING:
  1207. case WM8995_DAC2_MIXER_VOLUMES:
  1208. case WM8995_DAC2_LEFT_MIXER_ROUTING:
  1209. case WM8995_DAC2_RIGHT_MIXER_ROUTING:
  1210. case WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING:
  1211. case WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING:
  1212. case WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING:
  1213. case WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING:
  1214. case WM8995_DAC_SOFTMUTE:
  1215. case WM8995_OVERSAMPLING:
  1216. case WM8995_SIDETONE:
  1217. case WM8995_GPIO_1:
  1218. case WM8995_GPIO_2:
  1219. case WM8995_GPIO_3:
  1220. case WM8995_GPIO_4:
  1221. case WM8995_GPIO_5:
  1222. case WM8995_GPIO_6:
  1223. case WM8995_GPIO_7:
  1224. case WM8995_GPIO_8:
  1225. case WM8995_GPIO_9:
  1226. case WM8995_GPIO_10:
  1227. case WM8995_GPIO_11:
  1228. case WM8995_GPIO_12:
  1229. case WM8995_GPIO_13:
  1230. case WM8995_GPIO_14:
  1231. case WM8995_PULL_CONTROL_1:
  1232. case WM8995_PULL_CONTROL_2:
  1233. case WM8995_INTERRUPT_STATUS_1:
  1234. case WM8995_INTERRUPT_STATUS_2:
  1235. case WM8995_INTERRUPT_RAW_STATUS_2:
  1236. case WM8995_INTERRUPT_STATUS_1_MASK:
  1237. case WM8995_INTERRUPT_STATUS_2_MASK:
  1238. case WM8995_INTERRUPT_CONTROL:
  1239. case WM8995_LEFT_PDM_SPEAKER_1:
  1240. case WM8995_RIGHT_PDM_SPEAKER_1:
  1241. case WM8995_PDM_SPEAKER_1_MUTE_SEQUENCE:
  1242. case WM8995_LEFT_PDM_SPEAKER_2:
  1243. case WM8995_RIGHT_PDM_SPEAKER_2:
  1244. case WM8995_PDM_SPEAKER_2_MUTE_SEQUENCE:
  1245. return true;
  1246. default:
  1247. return false;
  1248. }
  1249. }
  1250. static bool wm8995_volatile(struct device *dev, unsigned int reg)
  1251. {
  1252. switch (reg) {
  1253. case WM8995_SOFTWARE_RESET:
  1254. case WM8995_DC_SERVO_READBACK_0:
  1255. case WM8995_INTERRUPT_STATUS_1:
  1256. case WM8995_INTERRUPT_STATUS_2:
  1257. case WM8995_INTERRUPT_CONTROL:
  1258. case WM8995_ACCESSORY_DETECT_MODE1:
  1259. case WM8995_ACCESSORY_DETECT_MODE2:
  1260. case WM8995_HEADPHONE_DETECT1:
  1261. case WM8995_HEADPHONE_DETECT2:
  1262. case WM8995_RATE_STATUS:
  1263. return true;
  1264. default:
  1265. return false;
  1266. }
  1267. }
  1268. static int wm8995_aif_mute(struct snd_soc_dai *dai, int mute)
  1269. {
  1270. struct snd_soc_codec *codec = dai->codec;
  1271. int mute_reg;
  1272. switch (dai->id) {
  1273. case 0:
  1274. mute_reg = WM8995_AIF1_DAC1_FILTERS_1;
  1275. break;
  1276. case 1:
  1277. mute_reg = WM8995_AIF2_DAC_FILTERS_1;
  1278. break;
  1279. default:
  1280. return -EINVAL;
  1281. }
  1282. snd_soc_update_bits(codec, mute_reg, WM8995_AIF1DAC1_MUTE_MASK,
  1283. !!mute << WM8995_AIF1DAC1_MUTE_SHIFT);
  1284. return 0;
  1285. }
  1286. static int wm8995_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  1287. {
  1288. struct snd_soc_codec *codec;
  1289. int master;
  1290. int aif;
  1291. codec = dai->codec;
  1292. master = 0;
  1293. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1294. case SND_SOC_DAIFMT_CBS_CFS:
  1295. break;
  1296. case SND_SOC_DAIFMT_CBM_CFM:
  1297. master = WM8995_AIF1_MSTR;
  1298. break;
  1299. default:
  1300. dev_err(dai->dev, "Unknown master/slave configuration\n");
  1301. return -EINVAL;
  1302. }
  1303. aif = 0;
  1304. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1305. case SND_SOC_DAIFMT_DSP_B:
  1306. aif |= WM8995_AIF1_LRCLK_INV;
  1307. case SND_SOC_DAIFMT_DSP_A:
  1308. aif |= (0x3 << WM8995_AIF1_FMT_SHIFT);
  1309. break;
  1310. case SND_SOC_DAIFMT_I2S:
  1311. aif |= (0x2 << WM8995_AIF1_FMT_SHIFT);
  1312. break;
  1313. case SND_SOC_DAIFMT_RIGHT_J:
  1314. break;
  1315. case SND_SOC_DAIFMT_LEFT_J:
  1316. aif |= (0x1 << WM8995_AIF1_FMT_SHIFT);
  1317. break;
  1318. default:
  1319. dev_err(dai->dev, "Unknown dai format\n");
  1320. return -EINVAL;
  1321. }
  1322. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1323. case SND_SOC_DAIFMT_DSP_A:
  1324. case SND_SOC_DAIFMT_DSP_B:
  1325. /* frame inversion not valid for DSP modes */
  1326. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  1327. case SND_SOC_DAIFMT_NB_NF:
  1328. break;
  1329. case SND_SOC_DAIFMT_IB_NF:
  1330. aif |= WM8995_AIF1_BCLK_INV;
  1331. break;
  1332. default:
  1333. return -EINVAL;
  1334. }
  1335. break;
  1336. case SND_SOC_DAIFMT_I2S:
  1337. case SND_SOC_DAIFMT_RIGHT_J:
  1338. case SND_SOC_DAIFMT_LEFT_J:
  1339. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  1340. case SND_SOC_DAIFMT_NB_NF:
  1341. break;
  1342. case SND_SOC_DAIFMT_IB_IF:
  1343. aif |= WM8995_AIF1_BCLK_INV | WM8995_AIF1_LRCLK_INV;
  1344. break;
  1345. case SND_SOC_DAIFMT_IB_NF:
  1346. aif |= WM8995_AIF1_BCLK_INV;
  1347. break;
  1348. case SND_SOC_DAIFMT_NB_IF:
  1349. aif |= WM8995_AIF1_LRCLK_INV;
  1350. break;
  1351. default:
  1352. return -EINVAL;
  1353. }
  1354. break;
  1355. default:
  1356. return -EINVAL;
  1357. }
  1358. snd_soc_update_bits(codec, WM8995_AIF1_CONTROL_1,
  1359. WM8995_AIF1_BCLK_INV_MASK |
  1360. WM8995_AIF1_LRCLK_INV_MASK |
  1361. WM8995_AIF1_FMT_MASK, aif);
  1362. snd_soc_update_bits(codec, WM8995_AIF1_MASTER_SLAVE,
  1363. WM8995_AIF1_MSTR_MASK, master);
  1364. return 0;
  1365. }
  1366. static const int srs[] = {
  1367. 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100,
  1368. 48000, 88200, 96000
  1369. };
  1370. static const int fs_ratios[] = {
  1371. -1 /* reserved */,
  1372. 128, 192, 256, 384, 512, 768, 1024, 1408, 1536
  1373. };
  1374. static const int bclk_divs[] = {
  1375. 10, 15, 20, 30, 40, 55, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480
  1376. };
  1377. static int wm8995_hw_params(struct snd_pcm_substream *substream,
  1378. struct snd_pcm_hw_params *params,
  1379. struct snd_soc_dai *dai)
  1380. {
  1381. struct snd_soc_codec *codec;
  1382. struct wm8995_priv *wm8995;
  1383. int aif1_reg;
  1384. int bclk_reg;
  1385. int lrclk_reg;
  1386. int rate_reg;
  1387. int bclk_rate;
  1388. int aif1;
  1389. int lrclk, bclk;
  1390. int i, rate_val, best, best_val, cur_val;
  1391. codec = dai->codec;
  1392. wm8995 = snd_soc_codec_get_drvdata(codec);
  1393. switch (dai->id) {
  1394. case 0:
  1395. aif1_reg = WM8995_AIF1_CONTROL_1;
  1396. bclk_reg = WM8995_AIF1_BCLK;
  1397. rate_reg = WM8995_AIF1_RATE;
  1398. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK /* ||
  1399. wm8995->lrclk_shared[0] */) {
  1400. lrclk_reg = WM8995_AIF1DAC_LRCLK;
  1401. } else {
  1402. lrclk_reg = WM8995_AIF1ADC_LRCLK;
  1403. dev_dbg(codec->dev, "AIF1 using split LRCLK\n");
  1404. }
  1405. break;
  1406. case 1:
  1407. aif1_reg = WM8995_AIF2_CONTROL_1;
  1408. bclk_reg = WM8995_AIF2_BCLK;
  1409. rate_reg = WM8995_AIF2_RATE;
  1410. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK /* ||
  1411. wm8995->lrclk_shared[1] */) {
  1412. lrclk_reg = WM8995_AIF2DAC_LRCLK;
  1413. } else {
  1414. lrclk_reg = WM8995_AIF2ADC_LRCLK;
  1415. dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
  1416. }
  1417. break;
  1418. default:
  1419. return -EINVAL;
  1420. }
  1421. bclk_rate = snd_soc_params_to_bclk(params);
  1422. if (bclk_rate < 0)
  1423. return bclk_rate;
  1424. aif1 = 0;
  1425. switch (params_width(params)) {
  1426. case 16:
  1427. break;
  1428. case 20:
  1429. aif1 |= (0x1 << WM8995_AIF1_WL_SHIFT);
  1430. break;
  1431. case 24:
  1432. aif1 |= (0x2 << WM8995_AIF1_WL_SHIFT);
  1433. break;
  1434. case 32:
  1435. aif1 |= (0x3 << WM8995_AIF1_WL_SHIFT);
  1436. break;
  1437. default:
  1438. dev_err(dai->dev, "Unsupported word length %u\n",
  1439. params_width(params));
  1440. return -EINVAL;
  1441. }
  1442. /* try to find a suitable sample rate */
  1443. for (i = 0; i < ARRAY_SIZE(srs); ++i)
  1444. if (srs[i] == params_rate(params))
  1445. break;
  1446. if (i == ARRAY_SIZE(srs)) {
  1447. dev_err(dai->dev, "Sample rate %d is not supported\n",
  1448. params_rate(params));
  1449. return -EINVAL;
  1450. }
  1451. rate_val = i << WM8995_AIF1_SR_SHIFT;
  1452. dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i]);
  1453. dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
  1454. dai->id + 1, wm8995->aifclk[dai->id], bclk_rate);
  1455. /* AIFCLK/fs ratio; look for a close match in either direction */
  1456. best = 1;
  1457. best_val = abs((fs_ratios[1] * params_rate(params))
  1458. - wm8995->aifclk[dai->id]);
  1459. for (i = 2; i < ARRAY_SIZE(fs_ratios); i++) {
  1460. cur_val = abs((fs_ratios[i] * params_rate(params))
  1461. - wm8995->aifclk[dai->id]);
  1462. if (cur_val >= best_val)
  1463. continue;
  1464. best = i;
  1465. best_val = cur_val;
  1466. }
  1467. rate_val |= best;
  1468. dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
  1469. dai->id + 1, fs_ratios[best]);
  1470. /*
  1471. * We may not get quite the right frequency if using
  1472. * approximate clocks so look for the closest match that is
  1473. * higher than the target (we need to ensure that there enough
  1474. * BCLKs to clock out the samples).
  1475. */
  1476. best = 0;
  1477. bclk = 0;
  1478. for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
  1479. cur_val = (wm8995->aifclk[dai->id] * 10 / bclk_divs[i]) - bclk_rate;
  1480. if (cur_val < 0) /* BCLK table is sorted */
  1481. break;
  1482. best = i;
  1483. }
  1484. bclk |= best << WM8995_AIF1_BCLK_DIV_SHIFT;
  1485. bclk_rate = wm8995->aifclk[dai->id] * 10 / bclk_divs[best];
  1486. dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
  1487. bclk_divs[best], bclk_rate);
  1488. lrclk = bclk_rate / params_rate(params);
  1489. dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
  1490. lrclk, bclk_rate / lrclk);
  1491. snd_soc_update_bits(codec, aif1_reg,
  1492. WM8995_AIF1_WL_MASK, aif1);
  1493. snd_soc_update_bits(codec, bclk_reg,
  1494. WM8995_AIF1_BCLK_DIV_MASK, bclk);
  1495. snd_soc_update_bits(codec, lrclk_reg,
  1496. WM8995_AIF1DAC_RATE_MASK, lrclk);
  1497. snd_soc_update_bits(codec, rate_reg,
  1498. WM8995_AIF1_SR_MASK |
  1499. WM8995_AIF1CLK_RATE_MASK, rate_val);
  1500. return 0;
  1501. }
  1502. static int wm8995_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
  1503. {
  1504. struct snd_soc_codec *codec = codec_dai->codec;
  1505. int reg, val, mask;
  1506. switch (codec_dai->id) {
  1507. case 0:
  1508. reg = WM8995_AIF1_MASTER_SLAVE;
  1509. mask = WM8995_AIF1_TRI;
  1510. break;
  1511. case 1:
  1512. reg = WM8995_AIF2_MASTER_SLAVE;
  1513. mask = WM8995_AIF2_TRI;
  1514. break;
  1515. case 2:
  1516. reg = WM8995_POWER_MANAGEMENT_5;
  1517. mask = WM8995_AIF3_TRI;
  1518. break;
  1519. default:
  1520. return -EINVAL;
  1521. }
  1522. if (tristate)
  1523. val = mask;
  1524. else
  1525. val = 0;
  1526. return snd_soc_update_bits(codec, reg, mask, val);
  1527. }
  1528. /* The size in bits of the FLL divide multiplied by 10
  1529. * to allow rounding later */
  1530. #define FIXED_FLL_SIZE ((1 << 16) * 10)
  1531. struct fll_div {
  1532. u16 outdiv;
  1533. u16 n;
  1534. u16 k;
  1535. u16 clk_ref_div;
  1536. u16 fll_fratio;
  1537. };
  1538. static int wm8995_get_fll_config(struct fll_div *fll,
  1539. int freq_in, int freq_out)
  1540. {
  1541. u64 Kpart;
  1542. unsigned int K, Ndiv, Nmod;
  1543. pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
  1544. /* Scale the input frequency down to <= 13.5MHz */
  1545. fll->clk_ref_div = 0;
  1546. while (freq_in > 13500000) {
  1547. fll->clk_ref_div++;
  1548. freq_in /= 2;
  1549. if (fll->clk_ref_div > 3)
  1550. return -EINVAL;
  1551. }
  1552. pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
  1553. /* Scale the output to give 90MHz<=Fvco<=100MHz */
  1554. fll->outdiv = 3;
  1555. while (freq_out * (fll->outdiv + 1) < 90000000) {
  1556. fll->outdiv++;
  1557. if (fll->outdiv > 63)
  1558. return -EINVAL;
  1559. }
  1560. freq_out *= fll->outdiv + 1;
  1561. pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
  1562. if (freq_in > 1000000) {
  1563. fll->fll_fratio = 0;
  1564. } else if (freq_in > 256000) {
  1565. fll->fll_fratio = 1;
  1566. freq_in *= 2;
  1567. } else if (freq_in > 128000) {
  1568. fll->fll_fratio = 2;
  1569. freq_in *= 4;
  1570. } else if (freq_in > 64000) {
  1571. fll->fll_fratio = 3;
  1572. freq_in *= 8;
  1573. } else {
  1574. fll->fll_fratio = 4;
  1575. freq_in *= 16;
  1576. }
  1577. pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
  1578. /* Now, calculate N.K */
  1579. Ndiv = freq_out / freq_in;
  1580. fll->n = Ndiv;
  1581. Nmod = freq_out % freq_in;
  1582. pr_debug("Nmod=%d\n", Nmod);
  1583. /* Calculate fractional part - scale up so we can round. */
  1584. Kpart = FIXED_FLL_SIZE * (long long)Nmod;
  1585. do_div(Kpart, freq_in);
  1586. K = Kpart & 0xFFFFFFFF;
  1587. if ((K % 10) >= 5)
  1588. K += 5;
  1589. /* Move down to proper range now rounding is done */
  1590. fll->k = K / 10;
  1591. pr_debug("N=%x K=%x\n", fll->n, fll->k);
  1592. return 0;
  1593. }
  1594. static int wm8995_set_fll(struct snd_soc_dai *dai, int id,
  1595. int src, unsigned int freq_in,
  1596. unsigned int freq_out)
  1597. {
  1598. struct snd_soc_codec *codec;
  1599. struct wm8995_priv *wm8995;
  1600. int reg_offset, ret;
  1601. struct fll_div fll;
  1602. u16 reg, aif1, aif2;
  1603. codec = dai->codec;
  1604. wm8995 = snd_soc_codec_get_drvdata(codec);
  1605. aif1 = snd_soc_read(codec, WM8995_AIF1_CLOCKING_1)
  1606. & WM8995_AIF1CLK_ENA;
  1607. aif2 = snd_soc_read(codec, WM8995_AIF2_CLOCKING_1)
  1608. & WM8995_AIF2CLK_ENA;
  1609. switch (id) {
  1610. case WM8995_FLL1:
  1611. reg_offset = 0;
  1612. id = 0;
  1613. break;
  1614. case WM8995_FLL2:
  1615. reg_offset = 0x20;
  1616. id = 1;
  1617. break;
  1618. default:
  1619. return -EINVAL;
  1620. }
  1621. switch (src) {
  1622. case 0:
  1623. /* Allow no source specification when stopping */
  1624. if (freq_out)
  1625. return -EINVAL;
  1626. break;
  1627. case WM8995_FLL_SRC_MCLK1:
  1628. case WM8995_FLL_SRC_MCLK2:
  1629. case WM8995_FLL_SRC_LRCLK:
  1630. case WM8995_FLL_SRC_BCLK:
  1631. break;
  1632. default:
  1633. return -EINVAL;
  1634. }
  1635. /* Are we changing anything? */
  1636. if (wm8995->fll[id].src == src &&
  1637. wm8995->fll[id].in == freq_in && wm8995->fll[id].out == freq_out)
  1638. return 0;
  1639. /* If we're stopping the FLL redo the old config - no
  1640. * registers will actually be written but we avoid GCC flow
  1641. * analysis bugs spewing warnings.
  1642. */
  1643. if (freq_out)
  1644. ret = wm8995_get_fll_config(&fll, freq_in, freq_out);
  1645. else
  1646. ret = wm8995_get_fll_config(&fll, wm8995->fll[id].in,
  1647. wm8995->fll[id].out);
  1648. if (ret < 0)
  1649. return ret;
  1650. /* Gate the AIF clocks while we reclock */
  1651. snd_soc_update_bits(codec, WM8995_AIF1_CLOCKING_1,
  1652. WM8995_AIF1CLK_ENA_MASK, 0);
  1653. snd_soc_update_bits(codec, WM8995_AIF2_CLOCKING_1,
  1654. WM8995_AIF2CLK_ENA_MASK, 0);
  1655. /* We always need to disable the FLL while reconfiguring */
  1656. snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_1 + reg_offset,
  1657. WM8995_FLL1_ENA_MASK, 0);
  1658. reg = (fll.outdiv << WM8995_FLL1_OUTDIV_SHIFT) |
  1659. (fll.fll_fratio << WM8995_FLL1_FRATIO_SHIFT);
  1660. snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_2 + reg_offset,
  1661. WM8995_FLL1_OUTDIV_MASK |
  1662. WM8995_FLL1_FRATIO_MASK, reg);
  1663. snd_soc_write(codec, WM8995_FLL1_CONTROL_3 + reg_offset, fll.k);
  1664. snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_4 + reg_offset,
  1665. WM8995_FLL1_N_MASK,
  1666. fll.n << WM8995_FLL1_N_SHIFT);
  1667. snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_5 + reg_offset,
  1668. WM8995_FLL1_REFCLK_DIV_MASK |
  1669. WM8995_FLL1_REFCLK_SRC_MASK,
  1670. (fll.clk_ref_div << WM8995_FLL1_REFCLK_DIV_SHIFT) |
  1671. (src - 1));
  1672. if (freq_out)
  1673. snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_1 + reg_offset,
  1674. WM8995_FLL1_ENA_MASK, WM8995_FLL1_ENA);
  1675. wm8995->fll[id].in = freq_in;
  1676. wm8995->fll[id].out = freq_out;
  1677. wm8995->fll[id].src = src;
  1678. /* Enable any gated AIF clocks */
  1679. snd_soc_update_bits(codec, WM8995_AIF1_CLOCKING_1,
  1680. WM8995_AIF1CLK_ENA_MASK, aif1);
  1681. snd_soc_update_bits(codec, WM8995_AIF2_CLOCKING_1,
  1682. WM8995_AIF2CLK_ENA_MASK, aif2);
  1683. configure_clock(codec);
  1684. return 0;
  1685. }
  1686. static int wm8995_set_dai_sysclk(struct snd_soc_dai *dai,
  1687. int clk_id, unsigned int freq, int dir)
  1688. {
  1689. struct snd_soc_codec *codec;
  1690. struct wm8995_priv *wm8995;
  1691. codec = dai->codec;
  1692. wm8995 = snd_soc_codec_get_drvdata(codec);
  1693. switch (dai->id) {
  1694. case 0:
  1695. case 1:
  1696. break;
  1697. default:
  1698. /* AIF3 shares clocking with AIF1/2 */
  1699. return -EINVAL;
  1700. }
  1701. switch (clk_id) {
  1702. case WM8995_SYSCLK_MCLK1:
  1703. wm8995->sysclk[dai->id] = WM8995_SYSCLK_MCLK1;
  1704. wm8995->mclk[0] = freq;
  1705. dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
  1706. dai->id + 1, freq);
  1707. break;
  1708. case WM8995_SYSCLK_MCLK2:
  1709. wm8995->sysclk[dai->id] = WM8995_SYSCLK_MCLK2;
  1710. wm8995->mclk[1] = freq;
  1711. dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
  1712. dai->id + 1, freq);
  1713. break;
  1714. case WM8995_SYSCLK_FLL1:
  1715. wm8995->sysclk[dai->id] = WM8995_SYSCLK_FLL1;
  1716. dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id + 1);
  1717. break;
  1718. case WM8995_SYSCLK_FLL2:
  1719. wm8995->sysclk[dai->id] = WM8995_SYSCLK_FLL2;
  1720. dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id + 1);
  1721. break;
  1722. case WM8995_SYSCLK_OPCLK:
  1723. default:
  1724. dev_err(dai->dev, "Unknown clock source %d\n", clk_id);
  1725. return -EINVAL;
  1726. }
  1727. configure_clock(codec);
  1728. return 0;
  1729. }
  1730. static int wm8995_set_bias_level(struct snd_soc_codec *codec,
  1731. enum snd_soc_bias_level level)
  1732. {
  1733. struct wm8995_priv *wm8995;
  1734. int ret;
  1735. wm8995 = snd_soc_codec_get_drvdata(codec);
  1736. switch (level) {
  1737. case SND_SOC_BIAS_ON:
  1738. case SND_SOC_BIAS_PREPARE:
  1739. break;
  1740. case SND_SOC_BIAS_STANDBY:
  1741. if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
  1742. ret = regulator_bulk_enable(ARRAY_SIZE(wm8995->supplies),
  1743. wm8995->supplies);
  1744. if (ret)
  1745. return ret;
  1746. ret = regcache_sync(wm8995->regmap);
  1747. if (ret) {
  1748. dev_err(codec->dev,
  1749. "Failed to sync cache: %d\n", ret);
  1750. return ret;
  1751. }
  1752. snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1,
  1753. WM8995_BG_ENA_MASK, WM8995_BG_ENA);
  1754. }
  1755. break;
  1756. case SND_SOC_BIAS_OFF:
  1757. snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1,
  1758. WM8995_BG_ENA_MASK, 0);
  1759. regulator_bulk_disable(ARRAY_SIZE(wm8995->supplies),
  1760. wm8995->supplies);
  1761. break;
  1762. }
  1763. return 0;
  1764. }
  1765. static int wm8995_remove(struct snd_soc_codec *codec)
  1766. {
  1767. struct wm8995_priv *wm8995;
  1768. int i;
  1769. wm8995 = snd_soc_codec_get_drvdata(codec);
  1770. for (i = 0; i < ARRAY_SIZE(wm8995->supplies); ++i)
  1771. regulator_unregister_notifier(wm8995->supplies[i].consumer,
  1772. &wm8995->disable_nb[i]);
  1773. regulator_bulk_free(ARRAY_SIZE(wm8995->supplies), wm8995->supplies);
  1774. return 0;
  1775. }
  1776. static int wm8995_probe(struct snd_soc_codec *codec)
  1777. {
  1778. struct wm8995_priv *wm8995;
  1779. int i;
  1780. int ret;
  1781. wm8995 = snd_soc_codec_get_drvdata(codec);
  1782. wm8995->codec = codec;
  1783. for (i = 0; i < ARRAY_SIZE(wm8995->supplies); i++)
  1784. wm8995->supplies[i].supply = wm8995_supply_names[i];
  1785. ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8995->supplies),
  1786. wm8995->supplies);
  1787. if (ret) {
  1788. dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
  1789. return ret;
  1790. }
  1791. wm8995->disable_nb[0].notifier_call = wm8995_regulator_event_0;
  1792. wm8995->disable_nb[1].notifier_call = wm8995_regulator_event_1;
  1793. wm8995->disable_nb[2].notifier_call = wm8995_regulator_event_2;
  1794. wm8995->disable_nb[3].notifier_call = wm8995_regulator_event_3;
  1795. wm8995->disable_nb[4].notifier_call = wm8995_regulator_event_4;
  1796. wm8995->disable_nb[5].notifier_call = wm8995_regulator_event_5;
  1797. wm8995->disable_nb[6].notifier_call = wm8995_regulator_event_6;
  1798. wm8995->disable_nb[7].notifier_call = wm8995_regulator_event_7;
  1799. /* This should really be moved into the regulator core */
  1800. for (i = 0; i < ARRAY_SIZE(wm8995->supplies); i++) {
  1801. ret = regulator_register_notifier(wm8995->supplies[i].consumer,
  1802. &wm8995->disable_nb[i]);
  1803. if (ret) {
  1804. dev_err(codec->dev,
  1805. "Failed to register regulator notifier: %d\n",
  1806. ret);
  1807. }
  1808. }
  1809. ret = regulator_bulk_enable(ARRAY_SIZE(wm8995->supplies),
  1810. wm8995->supplies);
  1811. if (ret) {
  1812. dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
  1813. goto err_reg_get;
  1814. }
  1815. ret = snd_soc_read(codec, WM8995_SOFTWARE_RESET);
  1816. if (ret < 0) {
  1817. dev_err(codec->dev, "Failed to read device ID: %d\n", ret);
  1818. goto err_reg_enable;
  1819. }
  1820. if (ret != 0x8995) {
  1821. dev_err(codec->dev, "Invalid device ID: %#x\n", ret);
  1822. ret = -EINVAL;
  1823. goto err_reg_enable;
  1824. }
  1825. ret = snd_soc_write(codec, WM8995_SOFTWARE_RESET, 0);
  1826. if (ret < 0) {
  1827. dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
  1828. goto err_reg_enable;
  1829. }
  1830. /* Latch volume updates (right only; we always do left then right). */
  1831. snd_soc_update_bits(codec, WM8995_AIF1_DAC1_RIGHT_VOLUME,
  1832. WM8995_AIF1DAC1_VU_MASK, WM8995_AIF1DAC1_VU);
  1833. snd_soc_update_bits(codec, WM8995_AIF1_DAC2_RIGHT_VOLUME,
  1834. WM8995_AIF1DAC2_VU_MASK, WM8995_AIF1DAC2_VU);
  1835. snd_soc_update_bits(codec, WM8995_AIF2_DAC_RIGHT_VOLUME,
  1836. WM8995_AIF2DAC_VU_MASK, WM8995_AIF2DAC_VU);
  1837. snd_soc_update_bits(codec, WM8995_AIF1_ADC1_RIGHT_VOLUME,
  1838. WM8995_AIF1ADC1_VU_MASK, WM8995_AIF1ADC1_VU);
  1839. snd_soc_update_bits(codec, WM8995_AIF1_ADC2_RIGHT_VOLUME,
  1840. WM8995_AIF1ADC2_VU_MASK, WM8995_AIF1ADC2_VU);
  1841. snd_soc_update_bits(codec, WM8995_AIF2_ADC_RIGHT_VOLUME,
  1842. WM8995_AIF2ADC_VU_MASK, WM8995_AIF1ADC2_VU);
  1843. snd_soc_update_bits(codec, WM8995_DAC1_RIGHT_VOLUME,
  1844. WM8995_DAC1_VU_MASK, WM8995_DAC1_VU);
  1845. snd_soc_update_bits(codec, WM8995_DAC2_RIGHT_VOLUME,
  1846. WM8995_DAC2_VU_MASK, WM8995_DAC2_VU);
  1847. snd_soc_update_bits(codec, WM8995_RIGHT_LINE_INPUT_1_VOLUME,
  1848. WM8995_IN1_VU_MASK, WM8995_IN1_VU);
  1849. wm8995_update_class_w(codec);
  1850. return 0;
  1851. err_reg_enable:
  1852. regulator_bulk_disable(ARRAY_SIZE(wm8995->supplies), wm8995->supplies);
  1853. err_reg_get:
  1854. regulator_bulk_free(ARRAY_SIZE(wm8995->supplies), wm8995->supplies);
  1855. return ret;
  1856. }
  1857. #define WM8995_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  1858. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
  1859. static const struct snd_soc_dai_ops wm8995_aif1_dai_ops = {
  1860. .set_sysclk = wm8995_set_dai_sysclk,
  1861. .set_fmt = wm8995_set_dai_fmt,
  1862. .hw_params = wm8995_hw_params,
  1863. .digital_mute = wm8995_aif_mute,
  1864. .set_pll = wm8995_set_fll,
  1865. .set_tristate = wm8995_set_tristate,
  1866. };
  1867. static const struct snd_soc_dai_ops wm8995_aif2_dai_ops = {
  1868. .set_sysclk = wm8995_set_dai_sysclk,
  1869. .set_fmt = wm8995_set_dai_fmt,
  1870. .hw_params = wm8995_hw_params,
  1871. .digital_mute = wm8995_aif_mute,
  1872. .set_pll = wm8995_set_fll,
  1873. .set_tristate = wm8995_set_tristate,
  1874. };
  1875. static const struct snd_soc_dai_ops wm8995_aif3_dai_ops = {
  1876. .set_tristate = wm8995_set_tristate,
  1877. };
  1878. static struct snd_soc_dai_driver wm8995_dai[] = {
  1879. {
  1880. .name = "wm8995-aif1",
  1881. .playback = {
  1882. .stream_name = "AIF1 Playback",
  1883. .channels_min = 2,
  1884. .channels_max = 2,
  1885. .rates = SNDRV_PCM_RATE_8000_96000,
  1886. .formats = WM8995_FORMATS
  1887. },
  1888. .capture = {
  1889. .stream_name = "AIF1 Capture",
  1890. .channels_min = 2,
  1891. .channels_max = 2,
  1892. .rates = SNDRV_PCM_RATE_8000_48000,
  1893. .formats = WM8995_FORMATS
  1894. },
  1895. .ops = &wm8995_aif1_dai_ops
  1896. },
  1897. {
  1898. .name = "wm8995-aif2",
  1899. .playback = {
  1900. .stream_name = "AIF2 Playback",
  1901. .channels_min = 2,
  1902. .channels_max = 2,
  1903. .rates = SNDRV_PCM_RATE_8000_96000,
  1904. .formats = WM8995_FORMATS
  1905. },
  1906. .capture = {
  1907. .stream_name = "AIF2 Capture",
  1908. .channels_min = 2,
  1909. .channels_max = 2,
  1910. .rates = SNDRV_PCM_RATE_8000_48000,
  1911. .formats = WM8995_FORMATS
  1912. },
  1913. .ops = &wm8995_aif2_dai_ops
  1914. },
  1915. {
  1916. .name = "wm8995-aif3",
  1917. .playback = {
  1918. .stream_name = "AIF3 Playback",
  1919. .channels_min = 2,
  1920. .channels_max = 2,
  1921. .rates = SNDRV_PCM_RATE_8000_96000,
  1922. .formats = WM8995_FORMATS
  1923. },
  1924. .capture = {
  1925. .stream_name = "AIF3 Capture",
  1926. .channels_min = 2,
  1927. .channels_max = 2,
  1928. .rates = SNDRV_PCM_RATE_8000_48000,
  1929. .formats = WM8995_FORMATS
  1930. },
  1931. .ops = &wm8995_aif3_dai_ops
  1932. }
  1933. };
  1934. static const struct snd_soc_codec_driver soc_codec_dev_wm8995 = {
  1935. .probe = wm8995_probe,
  1936. .remove = wm8995_remove,
  1937. .set_bias_level = wm8995_set_bias_level,
  1938. .idle_bias_off = true,
  1939. .component_driver = {
  1940. .controls = wm8995_snd_controls,
  1941. .num_controls = ARRAY_SIZE(wm8995_snd_controls),
  1942. .dapm_widgets = wm8995_dapm_widgets,
  1943. .num_dapm_widgets = ARRAY_SIZE(wm8995_dapm_widgets),
  1944. .dapm_routes = wm8995_intercon,
  1945. .num_dapm_routes = ARRAY_SIZE(wm8995_intercon),
  1946. },
  1947. };
  1948. static const struct regmap_config wm8995_regmap = {
  1949. .reg_bits = 16,
  1950. .val_bits = 16,
  1951. .max_register = WM8995_MAX_REGISTER,
  1952. .reg_defaults = wm8995_reg_defaults,
  1953. .num_reg_defaults = ARRAY_SIZE(wm8995_reg_defaults),
  1954. .volatile_reg = wm8995_volatile,
  1955. .readable_reg = wm8995_readable,
  1956. .cache_type = REGCACHE_RBTREE,
  1957. };
  1958. #if defined(CONFIG_SPI_MASTER)
  1959. static int wm8995_spi_probe(struct spi_device *spi)
  1960. {
  1961. struct wm8995_priv *wm8995;
  1962. int ret;
  1963. wm8995 = devm_kzalloc(&spi->dev, sizeof(*wm8995), GFP_KERNEL);
  1964. if (!wm8995)
  1965. return -ENOMEM;
  1966. spi_set_drvdata(spi, wm8995);
  1967. wm8995->regmap = devm_regmap_init_spi(spi, &wm8995_regmap);
  1968. if (IS_ERR(wm8995->regmap)) {
  1969. ret = PTR_ERR(wm8995->regmap);
  1970. dev_err(&spi->dev, "Failed to register regmap: %d\n", ret);
  1971. return ret;
  1972. }
  1973. ret = snd_soc_register_codec(&spi->dev,
  1974. &soc_codec_dev_wm8995, wm8995_dai,
  1975. ARRAY_SIZE(wm8995_dai));
  1976. return ret;
  1977. }
  1978. static int wm8995_spi_remove(struct spi_device *spi)
  1979. {
  1980. snd_soc_unregister_codec(&spi->dev);
  1981. return 0;
  1982. }
  1983. static struct spi_driver wm8995_spi_driver = {
  1984. .driver = {
  1985. .name = "wm8995",
  1986. },
  1987. .probe = wm8995_spi_probe,
  1988. .remove = wm8995_spi_remove
  1989. };
  1990. #endif
  1991. #if IS_ENABLED(CONFIG_I2C)
  1992. static int wm8995_i2c_probe(struct i2c_client *i2c,
  1993. const struct i2c_device_id *id)
  1994. {
  1995. struct wm8995_priv *wm8995;
  1996. int ret;
  1997. wm8995 = devm_kzalloc(&i2c->dev, sizeof(*wm8995), GFP_KERNEL);
  1998. if (!wm8995)
  1999. return -ENOMEM;
  2000. i2c_set_clientdata(i2c, wm8995);
  2001. wm8995->regmap = devm_regmap_init_i2c(i2c, &wm8995_regmap);
  2002. if (IS_ERR(wm8995->regmap)) {
  2003. ret = PTR_ERR(wm8995->regmap);
  2004. dev_err(&i2c->dev, "Failed to register regmap: %d\n", ret);
  2005. return ret;
  2006. }
  2007. ret = snd_soc_register_codec(&i2c->dev,
  2008. &soc_codec_dev_wm8995, wm8995_dai,
  2009. ARRAY_SIZE(wm8995_dai));
  2010. if (ret < 0)
  2011. dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret);
  2012. return ret;
  2013. }
  2014. static int wm8995_i2c_remove(struct i2c_client *client)
  2015. {
  2016. snd_soc_unregister_codec(&client->dev);
  2017. return 0;
  2018. }
  2019. static const struct i2c_device_id wm8995_i2c_id[] = {
  2020. {"wm8995", 0},
  2021. {}
  2022. };
  2023. MODULE_DEVICE_TABLE(i2c, wm8995_i2c_id);
  2024. static struct i2c_driver wm8995_i2c_driver = {
  2025. .driver = {
  2026. .name = "wm8995",
  2027. },
  2028. .probe = wm8995_i2c_probe,
  2029. .remove = wm8995_i2c_remove,
  2030. .id_table = wm8995_i2c_id
  2031. };
  2032. #endif
  2033. static int __init wm8995_modinit(void)
  2034. {
  2035. int ret = 0;
  2036. #if IS_ENABLED(CONFIG_I2C)
  2037. ret = i2c_add_driver(&wm8995_i2c_driver);
  2038. if (ret) {
  2039. printk(KERN_ERR "Failed to register wm8995 I2C driver: %d\n",
  2040. ret);
  2041. }
  2042. #endif
  2043. #if defined(CONFIG_SPI_MASTER)
  2044. ret = spi_register_driver(&wm8995_spi_driver);
  2045. if (ret) {
  2046. printk(KERN_ERR "Failed to register wm8995 SPI driver: %d\n",
  2047. ret);
  2048. }
  2049. #endif
  2050. return ret;
  2051. }
  2052. module_init(wm8995_modinit);
  2053. static void __exit wm8995_exit(void)
  2054. {
  2055. #if IS_ENABLED(CONFIG_I2C)
  2056. i2c_del_driver(&wm8995_i2c_driver);
  2057. #endif
  2058. #if defined(CONFIG_SPI_MASTER)
  2059. spi_unregister_driver(&wm8995_spi_driver);
  2060. #endif
  2061. }
  2062. module_exit(wm8995_exit);
  2063. MODULE_DESCRIPTION("ASoC WM8995 driver");
  2064. MODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>");
  2065. MODULE_LICENSE("GPL");