max98088.c 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131
  1. /*
  2. * max98088.c -- MAX98088 ALSA SoC Audio driver
  3. *
  4. * Copyright 2010 Maxim Integrated Products
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/moduleparam.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/delay.h>
  15. #include <linux/pm.h>
  16. #include <linux/i2c.h>
  17. #include <sound/core.h>
  18. #include <sound/pcm.h>
  19. #include <sound/pcm_params.h>
  20. #include <sound/soc.h>
  21. #include <sound/initval.h>
  22. #include <sound/tlv.h>
  23. #include <linux/slab.h>
  24. #include <asm/div64.h>
  25. #include <sound/max98088.h>
  26. #include "max98088.h"
  27. enum max98088_type {
  28. MAX98088,
  29. MAX98089,
  30. };
  31. struct max98088_cdata {
  32. unsigned int rate;
  33. unsigned int fmt;
  34. int eq_sel;
  35. };
  36. struct max98088_priv {
  37. enum max98088_type devtype;
  38. struct max98088_pdata *pdata;
  39. unsigned int sysclk;
  40. struct max98088_cdata dai[2];
  41. int eq_textcnt;
  42. const char **eq_texts;
  43. struct soc_enum eq_enum;
  44. u8 ina_state;
  45. u8 inb_state;
  46. unsigned int ex_mode;
  47. unsigned int digmic;
  48. unsigned int mic1pre;
  49. unsigned int mic2pre;
  50. unsigned int extmic_mode;
  51. };
  52. static const u8 max98088_reg[M98088_REG_CNT] = {
  53. 0x00, /* 00 IRQ status */
  54. 0x00, /* 01 MIC status */
  55. 0x00, /* 02 jack status */
  56. 0x00, /* 03 battery voltage */
  57. 0x00, /* 04 */
  58. 0x00, /* 05 */
  59. 0x00, /* 06 */
  60. 0x00, /* 07 */
  61. 0x00, /* 08 */
  62. 0x00, /* 09 */
  63. 0x00, /* 0A */
  64. 0x00, /* 0B */
  65. 0x00, /* 0C */
  66. 0x00, /* 0D */
  67. 0x00, /* 0E */
  68. 0x00, /* 0F interrupt enable */
  69. 0x00, /* 10 master clock */
  70. 0x00, /* 11 DAI1 clock mode */
  71. 0x00, /* 12 DAI1 clock control */
  72. 0x00, /* 13 DAI1 clock control */
  73. 0x00, /* 14 DAI1 format */
  74. 0x00, /* 15 DAI1 clock */
  75. 0x00, /* 16 DAI1 config */
  76. 0x00, /* 17 DAI1 TDM */
  77. 0x00, /* 18 DAI1 filters */
  78. 0x00, /* 19 DAI2 clock mode */
  79. 0x00, /* 1A DAI2 clock control */
  80. 0x00, /* 1B DAI2 clock control */
  81. 0x00, /* 1C DAI2 format */
  82. 0x00, /* 1D DAI2 clock */
  83. 0x00, /* 1E DAI2 config */
  84. 0x00, /* 1F DAI2 TDM */
  85. 0x00, /* 20 DAI2 filters */
  86. 0x00, /* 21 data config */
  87. 0x00, /* 22 DAC mixer */
  88. 0x00, /* 23 left ADC mixer */
  89. 0x00, /* 24 right ADC mixer */
  90. 0x00, /* 25 left HP mixer */
  91. 0x00, /* 26 right HP mixer */
  92. 0x00, /* 27 HP control */
  93. 0x00, /* 28 left REC mixer */
  94. 0x00, /* 29 right REC mixer */
  95. 0x00, /* 2A REC control */
  96. 0x00, /* 2B left SPK mixer */
  97. 0x00, /* 2C right SPK mixer */
  98. 0x00, /* 2D SPK control */
  99. 0x00, /* 2E sidetone */
  100. 0x00, /* 2F DAI1 playback level */
  101. 0x00, /* 30 DAI1 playback level */
  102. 0x00, /* 31 DAI2 playback level */
  103. 0x00, /* 32 DAI2 playbakc level */
  104. 0x00, /* 33 left ADC level */
  105. 0x00, /* 34 right ADC level */
  106. 0x00, /* 35 MIC1 level */
  107. 0x00, /* 36 MIC2 level */
  108. 0x00, /* 37 INA level */
  109. 0x00, /* 38 INB level */
  110. 0x00, /* 39 left HP volume */
  111. 0x00, /* 3A right HP volume */
  112. 0x00, /* 3B left REC volume */
  113. 0x00, /* 3C right REC volume */
  114. 0x00, /* 3D left SPK volume */
  115. 0x00, /* 3E right SPK volume */
  116. 0x00, /* 3F MIC config */
  117. 0x00, /* 40 MIC threshold */
  118. 0x00, /* 41 excursion limiter filter */
  119. 0x00, /* 42 excursion limiter threshold */
  120. 0x00, /* 43 ALC */
  121. 0x00, /* 44 power limiter threshold */
  122. 0x00, /* 45 power limiter config */
  123. 0x00, /* 46 distortion limiter config */
  124. 0x00, /* 47 audio input */
  125. 0x00, /* 48 microphone */
  126. 0x00, /* 49 level control */
  127. 0x00, /* 4A bypass switches */
  128. 0x00, /* 4B jack detect */
  129. 0x00, /* 4C input enable */
  130. 0x00, /* 4D output enable */
  131. 0xF0, /* 4E bias control */
  132. 0x00, /* 4F DAC power */
  133. 0x0F, /* 50 DAC power */
  134. 0x00, /* 51 system */
  135. 0x00, /* 52 DAI1 EQ1 */
  136. 0x00, /* 53 DAI1 EQ1 */
  137. 0x00, /* 54 DAI1 EQ1 */
  138. 0x00, /* 55 DAI1 EQ1 */
  139. 0x00, /* 56 DAI1 EQ1 */
  140. 0x00, /* 57 DAI1 EQ1 */
  141. 0x00, /* 58 DAI1 EQ1 */
  142. 0x00, /* 59 DAI1 EQ1 */
  143. 0x00, /* 5A DAI1 EQ1 */
  144. 0x00, /* 5B DAI1 EQ1 */
  145. 0x00, /* 5C DAI1 EQ2 */
  146. 0x00, /* 5D DAI1 EQ2 */
  147. 0x00, /* 5E DAI1 EQ2 */
  148. 0x00, /* 5F DAI1 EQ2 */
  149. 0x00, /* 60 DAI1 EQ2 */
  150. 0x00, /* 61 DAI1 EQ2 */
  151. 0x00, /* 62 DAI1 EQ2 */
  152. 0x00, /* 63 DAI1 EQ2 */
  153. 0x00, /* 64 DAI1 EQ2 */
  154. 0x00, /* 65 DAI1 EQ2 */
  155. 0x00, /* 66 DAI1 EQ3 */
  156. 0x00, /* 67 DAI1 EQ3 */
  157. 0x00, /* 68 DAI1 EQ3 */
  158. 0x00, /* 69 DAI1 EQ3 */
  159. 0x00, /* 6A DAI1 EQ3 */
  160. 0x00, /* 6B DAI1 EQ3 */
  161. 0x00, /* 6C DAI1 EQ3 */
  162. 0x00, /* 6D DAI1 EQ3 */
  163. 0x00, /* 6E DAI1 EQ3 */
  164. 0x00, /* 6F DAI1 EQ3 */
  165. 0x00, /* 70 DAI1 EQ4 */
  166. 0x00, /* 71 DAI1 EQ4 */
  167. 0x00, /* 72 DAI1 EQ4 */
  168. 0x00, /* 73 DAI1 EQ4 */
  169. 0x00, /* 74 DAI1 EQ4 */
  170. 0x00, /* 75 DAI1 EQ4 */
  171. 0x00, /* 76 DAI1 EQ4 */
  172. 0x00, /* 77 DAI1 EQ4 */
  173. 0x00, /* 78 DAI1 EQ4 */
  174. 0x00, /* 79 DAI1 EQ4 */
  175. 0x00, /* 7A DAI1 EQ5 */
  176. 0x00, /* 7B DAI1 EQ5 */
  177. 0x00, /* 7C DAI1 EQ5 */
  178. 0x00, /* 7D DAI1 EQ5 */
  179. 0x00, /* 7E DAI1 EQ5 */
  180. 0x00, /* 7F DAI1 EQ5 */
  181. 0x00, /* 80 DAI1 EQ5 */
  182. 0x00, /* 81 DAI1 EQ5 */
  183. 0x00, /* 82 DAI1 EQ5 */
  184. 0x00, /* 83 DAI1 EQ5 */
  185. 0x00, /* 84 DAI2 EQ1 */
  186. 0x00, /* 85 DAI2 EQ1 */
  187. 0x00, /* 86 DAI2 EQ1 */
  188. 0x00, /* 87 DAI2 EQ1 */
  189. 0x00, /* 88 DAI2 EQ1 */
  190. 0x00, /* 89 DAI2 EQ1 */
  191. 0x00, /* 8A DAI2 EQ1 */
  192. 0x00, /* 8B DAI2 EQ1 */
  193. 0x00, /* 8C DAI2 EQ1 */
  194. 0x00, /* 8D DAI2 EQ1 */
  195. 0x00, /* 8E DAI2 EQ2 */
  196. 0x00, /* 8F DAI2 EQ2 */
  197. 0x00, /* 90 DAI2 EQ2 */
  198. 0x00, /* 91 DAI2 EQ2 */
  199. 0x00, /* 92 DAI2 EQ2 */
  200. 0x00, /* 93 DAI2 EQ2 */
  201. 0x00, /* 94 DAI2 EQ2 */
  202. 0x00, /* 95 DAI2 EQ2 */
  203. 0x00, /* 96 DAI2 EQ2 */
  204. 0x00, /* 97 DAI2 EQ2 */
  205. 0x00, /* 98 DAI2 EQ3 */
  206. 0x00, /* 99 DAI2 EQ3 */
  207. 0x00, /* 9A DAI2 EQ3 */
  208. 0x00, /* 9B DAI2 EQ3 */
  209. 0x00, /* 9C DAI2 EQ3 */
  210. 0x00, /* 9D DAI2 EQ3 */
  211. 0x00, /* 9E DAI2 EQ3 */
  212. 0x00, /* 9F DAI2 EQ3 */
  213. 0x00, /* A0 DAI2 EQ3 */
  214. 0x00, /* A1 DAI2 EQ3 */
  215. 0x00, /* A2 DAI2 EQ4 */
  216. 0x00, /* A3 DAI2 EQ4 */
  217. 0x00, /* A4 DAI2 EQ4 */
  218. 0x00, /* A5 DAI2 EQ4 */
  219. 0x00, /* A6 DAI2 EQ4 */
  220. 0x00, /* A7 DAI2 EQ4 */
  221. 0x00, /* A8 DAI2 EQ4 */
  222. 0x00, /* A9 DAI2 EQ4 */
  223. 0x00, /* AA DAI2 EQ4 */
  224. 0x00, /* AB DAI2 EQ4 */
  225. 0x00, /* AC DAI2 EQ5 */
  226. 0x00, /* AD DAI2 EQ5 */
  227. 0x00, /* AE DAI2 EQ5 */
  228. 0x00, /* AF DAI2 EQ5 */
  229. 0x00, /* B0 DAI2 EQ5 */
  230. 0x00, /* B1 DAI2 EQ5 */
  231. 0x00, /* B2 DAI2 EQ5 */
  232. 0x00, /* B3 DAI2 EQ5 */
  233. 0x00, /* B4 DAI2 EQ5 */
  234. 0x00, /* B5 DAI2 EQ5 */
  235. 0x00, /* B6 DAI1 biquad */
  236. 0x00, /* B7 DAI1 biquad */
  237. 0x00, /* B8 DAI1 biquad */
  238. 0x00, /* B9 DAI1 biquad */
  239. 0x00, /* BA DAI1 biquad */
  240. 0x00, /* BB DAI1 biquad */
  241. 0x00, /* BC DAI1 biquad */
  242. 0x00, /* BD DAI1 biquad */
  243. 0x00, /* BE DAI1 biquad */
  244. 0x00, /* BF DAI1 biquad */
  245. 0x00, /* C0 DAI2 biquad */
  246. 0x00, /* C1 DAI2 biquad */
  247. 0x00, /* C2 DAI2 biquad */
  248. 0x00, /* C3 DAI2 biquad */
  249. 0x00, /* C4 DAI2 biquad */
  250. 0x00, /* C5 DAI2 biquad */
  251. 0x00, /* C6 DAI2 biquad */
  252. 0x00, /* C7 DAI2 biquad */
  253. 0x00, /* C8 DAI2 biquad */
  254. 0x00, /* C9 DAI2 biquad */
  255. 0x00, /* CA */
  256. 0x00, /* CB */
  257. 0x00, /* CC */
  258. 0x00, /* CD */
  259. 0x00, /* CE */
  260. 0x00, /* CF */
  261. 0x00, /* D0 */
  262. 0x00, /* D1 */
  263. 0x00, /* D2 */
  264. 0x00, /* D3 */
  265. 0x00, /* D4 */
  266. 0x00, /* D5 */
  267. 0x00, /* D6 */
  268. 0x00, /* D7 */
  269. 0x00, /* D8 */
  270. 0x00, /* D9 */
  271. 0x00, /* DA */
  272. 0x70, /* DB */
  273. 0x00, /* DC */
  274. 0x00, /* DD */
  275. 0x00, /* DE */
  276. 0x00, /* DF */
  277. 0x00, /* E0 */
  278. 0x00, /* E1 */
  279. 0x00, /* E2 */
  280. 0x00, /* E3 */
  281. 0x00, /* E4 */
  282. 0x00, /* E5 */
  283. 0x00, /* E6 */
  284. 0x00, /* E7 */
  285. 0x00, /* E8 */
  286. 0x00, /* E9 */
  287. 0x00, /* EA */
  288. 0x00, /* EB */
  289. 0x00, /* EC */
  290. 0x00, /* ED */
  291. 0x00, /* EE */
  292. 0x00, /* EF */
  293. 0x00, /* F0 */
  294. 0x00, /* F1 */
  295. 0x00, /* F2 */
  296. 0x00, /* F3 */
  297. 0x00, /* F4 */
  298. 0x00, /* F5 */
  299. 0x00, /* F6 */
  300. 0x00, /* F7 */
  301. 0x00, /* F8 */
  302. 0x00, /* F9 */
  303. 0x00, /* FA */
  304. 0x00, /* FB */
  305. 0x00, /* FC */
  306. 0x00, /* FD */
  307. 0x00, /* FE */
  308. 0x00, /* FF */
  309. };
  310. static struct {
  311. int readable;
  312. int writable;
  313. int vol;
  314. } max98088_access[M98088_REG_CNT] = {
  315. { 0xFF, 0xFF, 1 }, /* 00 IRQ status */
  316. { 0xFF, 0x00, 1 }, /* 01 MIC status */
  317. { 0xFF, 0x00, 1 }, /* 02 jack status */
  318. { 0x1F, 0x1F, 1 }, /* 03 battery voltage */
  319. { 0xFF, 0xFF, 0 }, /* 04 */
  320. { 0xFF, 0xFF, 0 }, /* 05 */
  321. { 0xFF, 0xFF, 0 }, /* 06 */
  322. { 0xFF, 0xFF, 0 }, /* 07 */
  323. { 0xFF, 0xFF, 0 }, /* 08 */
  324. { 0xFF, 0xFF, 0 }, /* 09 */
  325. { 0xFF, 0xFF, 0 }, /* 0A */
  326. { 0xFF, 0xFF, 0 }, /* 0B */
  327. { 0xFF, 0xFF, 0 }, /* 0C */
  328. { 0xFF, 0xFF, 0 }, /* 0D */
  329. { 0xFF, 0xFF, 0 }, /* 0E */
  330. { 0xFF, 0xFF, 0 }, /* 0F interrupt enable */
  331. { 0xFF, 0xFF, 0 }, /* 10 master clock */
  332. { 0xFF, 0xFF, 0 }, /* 11 DAI1 clock mode */
  333. { 0xFF, 0xFF, 0 }, /* 12 DAI1 clock control */
  334. { 0xFF, 0xFF, 0 }, /* 13 DAI1 clock control */
  335. { 0xFF, 0xFF, 0 }, /* 14 DAI1 format */
  336. { 0xFF, 0xFF, 0 }, /* 15 DAI1 clock */
  337. { 0xFF, 0xFF, 0 }, /* 16 DAI1 config */
  338. { 0xFF, 0xFF, 0 }, /* 17 DAI1 TDM */
  339. { 0xFF, 0xFF, 0 }, /* 18 DAI1 filters */
  340. { 0xFF, 0xFF, 0 }, /* 19 DAI2 clock mode */
  341. { 0xFF, 0xFF, 0 }, /* 1A DAI2 clock control */
  342. { 0xFF, 0xFF, 0 }, /* 1B DAI2 clock control */
  343. { 0xFF, 0xFF, 0 }, /* 1C DAI2 format */
  344. { 0xFF, 0xFF, 0 }, /* 1D DAI2 clock */
  345. { 0xFF, 0xFF, 0 }, /* 1E DAI2 config */
  346. { 0xFF, 0xFF, 0 }, /* 1F DAI2 TDM */
  347. { 0xFF, 0xFF, 0 }, /* 20 DAI2 filters */
  348. { 0xFF, 0xFF, 0 }, /* 21 data config */
  349. { 0xFF, 0xFF, 0 }, /* 22 DAC mixer */
  350. { 0xFF, 0xFF, 0 }, /* 23 left ADC mixer */
  351. { 0xFF, 0xFF, 0 }, /* 24 right ADC mixer */
  352. { 0xFF, 0xFF, 0 }, /* 25 left HP mixer */
  353. { 0xFF, 0xFF, 0 }, /* 26 right HP mixer */
  354. { 0xFF, 0xFF, 0 }, /* 27 HP control */
  355. { 0xFF, 0xFF, 0 }, /* 28 left REC mixer */
  356. { 0xFF, 0xFF, 0 }, /* 29 right REC mixer */
  357. { 0xFF, 0xFF, 0 }, /* 2A REC control */
  358. { 0xFF, 0xFF, 0 }, /* 2B left SPK mixer */
  359. { 0xFF, 0xFF, 0 }, /* 2C right SPK mixer */
  360. { 0xFF, 0xFF, 0 }, /* 2D SPK control */
  361. { 0xFF, 0xFF, 0 }, /* 2E sidetone */
  362. { 0xFF, 0xFF, 0 }, /* 2F DAI1 playback level */
  363. { 0xFF, 0xFF, 0 }, /* 30 DAI1 playback level */
  364. { 0xFF, 0xFF, 0 }, /* 31 DAI2 playback level */
  365. { 0xFF, 0xFF, 0 }, /* 32 DAI2 playbakc level */
  366. { 0xFF, 0xFF, 0 }, /* 33 left ADC level */
  367. { 0xFF, 0xFF, 0 }, /* 34 right ADC level */
  368. { 0xFF, 0xFF, 0 }, /* 35 MIC1 level */
  369. { 0xFF, 0xFF, 0 }, /* 36 MIC2 level */
  370. { 0xFF, 0xFF, 0 }, /* 37 INA level */
  371. { 0xFF, 0xFF, 0 }, /* 38 INB level */
  372. { 0xFF, 0xFF, 0 }, /* 39 left HP volume */
  373. { 0xFF, 0xFF, 0 }, /* 3A right HP volume */
  374. { 0xFF, 0xFF, 0 }, /* 3B left REC volume */
  375. { 0xFF, 0xFF, 0 }, /* 3C right REC volume */
  376. { 0xFF, 0xFF, 0 }, /* 3D left SPK volume */
  377. { 0xFF, 0xFF, 0 }, /* 3E right SPK volume */
  378. { 0xFF, 0xFF, 0 }, /* 3F MIC config */
  379. { 0xFF, 0xFF, 0 }, /* 40 MIC threshold */
  380. { 0xFF, 0xFF, 0 }, /* 41 excursion limiter filter */
  381. { 0xFF, 0xFF, 0 }, /* 42 excursion limiter threshold */
  382. { 0xFF, 0xFF, 0 }, /* 43 ALC */
  383. { 0xFF, 0xFF, 0 }, /* 44 power limiter threshold */
  384. { 0xFF, 0xFF, 0 }, /* 45 power limiter config */
  385. { 0xFF, 0xFF, 0 }, /* 46 distortion limiter config */
  386. { 0xFF, 0xFF, 0 }, /* 47 audio input */
  387. { 0xFF, 0xFF, 0 }, /* 48 microphone */
  388. { 0xFF, 0xFF, 0 }, /* 49 level control */
  389. { 0xFF, 0xFF, 0 }, /* 4A bypass switches */
  390. { 0xFF, 0xFF, 0 }, /* 4B jack detect */
  391. { 0xFF, 0xFF, 0 }, /* 4C input enable */
  392. { 0xFF, 0xFF, 0 }, /* 4D output enable */
  393. { 0xFF, 0xFF, 0 }, /* 4E bias control */
  394. { 0xFF, 0xFF, 0 }, /* 4F DAC power */
  395. { 0xFF, 0xFF, 0 }, /* 50 DAC power */
  396. { 0xFF, 0xFF, 0 }, /* 51 system */
  397. { 0xFF, 0xFF, 0 }, /* 52 DAI1 EQ1 */
  398. { 0xFF, 0xFF, 0 }, /* 53 DAI1 EQ1 */
  399. { 0xFF, 0xFF, 0 }, /* 54 DAI1 EQ1 */
  400. { 0xFF, 0xFF, 0 }, /* 55 DAI1 EQ1 */
  401. { 0xFF, 0xFF, 0 }, /* 56 DAI1 EQ1 */
  402. { 0xFF, 0xFF, 0 }, /* 57 DAI1 EQ1 */
  403. { 0xFF, 0xFF, 0 }, /* 58 DAI1 EQ1 */
  404. { 0xFF, 0xFF, 0 }, /* 59 DAI1 EQ1 */
  405. { 0xFF, 0xFF, 0 }, /* 5A DAI1 EQ1 */
  406. { 0xFF, 0xFF, 0 }, /* 5B DAI1 EQ1 */
  407. { 0xFF, 0xFF, 0 }, /* 5C DAI1 EQ2 */
  408. { 0xFF, 0xFF, 0 }, /* 5D DAI1 EQ2 */
  409. { 0xFF, 0xFF, 0 }, /* 5E DAI1 EQ2 */
  410. { 0xFF, 0xFF, 0 }, /* 5F DAI1 EQ2 */
  411. { 0xFF, 0xFF, 0 }, /* 60 DAI1 EQ2 */
  412. { 0xFF, 0xFF, 0 }, /* 61 DAI1 EQ2 */
  413. { 0xFF, 0xFF, 0 }, /* 62 DAI1 EQ2 */
  414. { 0xFF, 0xFF, 0 }, /* 63 DAI1 EQ2 */
  415. { 0xFF, 0xFF, 0 }, /* 64 DAI1 EQ2 */
  416. { 0xFF, 0xFF, 0 }, /* 65 DAI1 EQ2 */
  417. { 0xFF, 0xFF, 0 }, /* 66 DAI1 EQ3 */
  418. { 0xFF, 0xFF, 0 }, /* 67 DAI1 EQ3 */
  419. { 0xFF, 0xFF, 0 }, /* 68 DAI1 EQ3 */
  420. { 0xFF, 0xFF, 0 }, /* 69 DAI1 EQ3 */
  421. { 0xFF, 0xFF, 0 }, /* 6A DAI1 EQ3 */
  422. { 0xFF, 0xFF, 0 }, /* 6B DAI1 EQ3 */
  423. { 0xFF, 0xFF, 0 }, /* 6C DAI1 EQ3 */
  424. { 0xFF, 0xFF, 0 }, /* 6D DAI1 EQ3 */
  425. { 0xFF, 0xFF, 0 }, /* 6E DAI1 EQ3 */
  426. { 0xFF, 0xFF, 0 }, /* 6F DAI1 EQ3 */
  427. { 0xFF, 0xFF, 0 }, /* 70 DAI1 EQ4 */
  428. { 0xFF, 0xFF, 0 }, /* 71 DAI1 EQ4 */
  429. { 0xFF, 0xFF, 0 }, /* 72 DAI1 EQ4 */
  430. { 0xFF, 0xFF, 0 }, /* 73 DAI1 EQ4 */
  431. { 0xFF, 0xFF, 0 }, /* 74 DAI1 EQ4 */
  432. { 0xFF, 0xFF, 0 }, /* 75 DAI1 EQ4 */
  433. { 0xFF, 0xFF, 0 }, /* 76 DAI1 EQ4 */
  434. { 0xFF, 0xFF, 0 }, /* 77 DAI1 EQ4 */
  435. { 0xFF, 0xFF, 0 }, /* 78 DAI1 EQ4 */
  436. { 0xFF, 0xFF, 0 }, /* 79 DAI1 EQ4 */
  437. { 0xFF, 0xFF, 0 }, /* 7A DAI1 EQ5 */
  438. { 0xFF, 0xFF, 0 }, /* 7B DAI1 EQ5 */
  439. { 0xFF, 0xFF, 0 }, /* 7C DAI1 EQ5 */
  440. { 0xFF, 0xFF, 0 }, /* 7D DAI1 EQ5 */
  441. { 0xFF, 0xFF, 0 }, /* 7E DAI1 EQ5 */
  442. { 0xFF, 0xFF, 0 }, /* 7F DAI1 EQ5 */
  443. { 0xFF, 0xFF, 0 }, /* 80 DAI1 EQ5 */
  444. { 0xFF, 0xFF, 0 }, /* 81 DAI1 EQ5 */
  445. { 0xFF, 0xFF, 0 }, /* 82 DAI1 EQ5 */
  446. { 0xFF, 0xFF, 0 }, /* 83 DAI1 EQ5 */
  447. { 0xFF, 0xFF, 0 }, /* 84 DAI2 EQ1 */
  448. { 0xFF, 0xFF, 0 }, /* 85 DAI2 EQ1 */
  449. { 0xFF, 0xFF, 0 }, /* 86 DAI2 EQ1 */
  450. { 0xFF, 0xFF, 0 }, /* 87 DAI2 EQ1 */
  451. { 0xFF, 0xFF, 0 }, /* 88 DAI2 EQ1 */
  452. { 0xFF, 0xFF, 0 }, /* 89 DAI2 EQ1 */
  453. { 0xFF, 0xFF, 0 }, /* 8A DAI2 EQ1 */
  454. { 0xFF, 0xFF, 0 }, /* 8B DAI2 EQ1 */
  455. { 0xFF, 0xFF, 0 }, /* 8C DAI2 EQ1 */
  456. { 0xFF, 0xFF, 0 }, /* 8D DAI2 EQ1 */
  457. { 0xFF, 0xFF, 0 }, /* 8E DAI2 EQ2 */
  458. { 0xFF, 0xFF, 0 }, /* 8F DAI2 EQ2 */
  459. { 0xFF, 0xFF, 0 }, /* 90 DAI2 EQ2 */
  460. { 0xFF, 0xFF, 0 }, /* 91 DAI2 EQ2 */
  461. { 0xFF, 0xFF, 0 }, /* 92 DAI2 EQ2 */
  462. { 0xFF, 0xFF, 0 }, /* 93 DAI2 EQ2 */
  463. { 0xFF, 0xFF, 0 }, /* 94 DAI2 EQ2 */
  464. { 0xFF, 0xFF, 0 }, /* 95 DAI2 EQ2 */
  465. { 0xFF, 0xFF, 0 }, /* 96 DAI2 EQ2 */
  466. { 0xFF, 0xFF, 0 }, /* 97 DAI2 EQ2 */
  467. { 0xFF, 0xFF, 0 }, /* 98 DAI2 EQ3 */
  468. { 0xFF, 0xFF, 0 }, /* 99 DAI2 EQ3 */
  469. { 0xFF, 0xFF, 0 }, /* 9A DAI2 EQ3 */
  470. { 0xFF, 0xFF, 0 }, /* 9B DAI2 EQ3 */
  471. { 0xFF, 0xFF, 0 }, /* 9C DAI2 EQ3 */
  472. { 0xFF, 0xFF, 0 }, /* 9D DAI2 EQ3 */
  473. { 0xFF, 0xFF, 0 }, /* 9E DAI2 EQ3 */
  474. { 0xFF, 0xFF, 0 }, /* 9F DAI2 EQ3 */
  475. { 0xFF, 0xFF, 0 }, /* A0 DAI2 EQ3 */
  476. { 0xFF, 0xFF, 0 }, /* A1 DAI2 EQ3 */
  477. { 0xFF, 0xFF, 0 }, /* A2 DAI2 EQ4 */
  478. { 0xFF, 0xFF, 0 }, /* A3 DAI2 EQ4 */
  479. { 0xFF, 0xFF, 0 }, /* A4 DAI2 EQ4 */
  480. { 0xFF, 0xFF, 0 }, /* A5 DAI2 EQ4 */
  481. { 0xFF, 0xFF, 0 }, /* A6 DAI2 EQ4 */
  482. { 0xFF, 0xFF, 0 }, /* A7 DAI2 EQ4 */
  483. { 0xFF, 0xFF, 0 }, /* A8 DAI2 EQ4 */
  484. { 0xFF, 0xFF, 0 }, /* A9 DAI2 EQ4 */
  485. { 0xFF, 0xFF, 0 }, /* AA DAI2 EQ4 */
  486. { 0xFF, 0xFF, 0 }, /* AB DAI2 EQ4 */
  487. { 0xFF, 0xFF, 0 }, /* AC DAI2 EQ5 */
  488. { 0xFF, 0xFF, 0 }, /* AD DAI2 EQ5 */
  489. { 0xFF, 0xFF, 0 }, /* AE DAI2 EQ5 */
  490. { 0xFF, 0xFF, 0 }, /* AF DAI2 EQ5 */
  491. { 0xFF, 0xFF, 0 }, /* B0 DAI2 EQ5 */
  492. { 0xFF, 0xFF, 0 }, /* B1 DAI2 EQ5 */
  493. { 0xFF, 0xFF, 0 }, /* B2 DAI2 EQ5 */
  494. { 0xFF, 0xFF, 0 }, /* B3 DAI2 EQ5 */
  495. { 0xFF, 0xFF, 0 }, /* B4 DAI2 EQ5 */
  496. { 0xFF, 0xFF, 0 }, /* B5 DAI2 EQ5 */
  497. { 0xFF, 0xFF, 0 }, /* B6 DAI1 biquad */
  498. { 0xFF, 0xFF, 0 }, /* B7 DAI1 biquad */
  499. { 0xFF, 0xFF, 0 }, /* B8 DAI1 biquad */
  500. { 0xFF, 0xFF, 0 }, /* B9 DAI1 biquad */
  501. { 0xFF, 0xFF, 0 }, /* BA DAI1 biquad */
  502. { 0xFF, 0xFF, 0 }, /* BB DAI1 biquad */
  503. { 0xFF, 0xFF, 0 }, /* BC DAI1 biquad */
  504. { 0xFF, 0xFF, 0 }, /* BD DAI1 biquad */
  505. { 0xFF, 0xFF, 0 }, /* BE DAI1 biquad */
  506. { 0xFF, 0xFF, 0 }, /* BF DAI1 biquad */
  507. { 0xFF, 0xFF, 0 }, /* C0 DAI2 biquad */
  508. { 0xFF, 0xFF, 0 }, /* C1 DAI2 biquad */
  509. { 0xFF, 0xFF, 0 }, /* C2 DAI2 biquad */
  510. { 0xFF, 0xFF, 0 }, /* C3 DAI2 biquad */
  511. { 0xFF, 0xFF, 0 }, /* C4 DAI2 biquad */
  512. { 0xFF, 0xFF, 0 }, /* C5 DAI2 biquad */
  513. { 0xFF, 0xFF, 0 }, /* C6 DAI2 biquad */
  514. { 0xFF, 0xFF, 0 }, /* C7 DAI2 biquad */
  515. { 0xFF, 0xFF, 0 }, /* C8 DAI2 biquad */
  516. { 0xFF, 0xFF, 0 }, /* C9 DAI2 biquad */
  517. { 0x00, 0x00, 0 }, /* CA */
  518. { 0x00, 0x00, 0 }, /* CB */
  519. { 0x00, 0x00, 0 }, /* CC */
  520. { 0x00, 0x00, 0 }, /* CD */
  521. { 0x00, 0x00, 0 }, /* CE */
  522. { 0x00, 0x00, 0 }, /* CF */
  523. { 0x00, 0x00, 0 }, /* D0 */
  524. { 0x00, 0x00, 0 }, /* D1 */
  525. { 0x00, 0x00, 0 }, /* D2 */
  526. { 0x00, 0x00, 0 }, /* D3 */
  527. { 0x00, 0x00, 0 }, /* D4 */
  528. { 0x00, 0x00, 0 }, /* D5 */
  529. { 0x00, 0x00, 0 }, /* D6 */
  530. { 0x00, 0x00, 0 }, /* D7 */
  531. { 0x00, 0x00, 0 }, /* D8 */
  532. { 0x00, 0x00, 0 }, /* D9 */
  533. { 0x00, 0x00, 0 }, /* DA */
  534. { 0x00, 0x00, 0 }, /* DB */
  535. { 0x00, 0x00, 0 }, /* DC */
  536. { 0x00, 0x00, 0 }, /* DD */
  537. { 0x00, 0x00, 0 }, /* DE */
  538. { 0x00, 0x00, 0 }, /* DF */
  539. { 0x00, 0x00, 0 }, /* E0 */
  540. { 0x00, 0x00, 0 }, /* E1 */
  541. { 0x00, 0x00, 0 }, /* E2 */
  542. { 0x00, 0x00, 0 }, /* E3 */
  543. { 0x00, 0x00, 0 }, /* E4 */
  544. { 0x00, 0x00, 0 }, /* E5 */
  545. { 0x00, 0x00, 0 }, /* E6 */
  546. { 0x00, 0x00, 0 }, /* E7 */
  547. { 0x00, 0x00, 0 }, /* E8 */
  548. { 0x00, 0x00, 0 }, /* E9 */
  549. { 0x00, 0x00, 0 }, /* EA */
  550. { 0x00, 0x00, 0 }, /* EB */
  551. { 0x00, 0x00, 0 }, /* EC */
  552. { 0x00, 0x00, 0 }, /* ED */
  553. { 0x00, 0x00, 0 }, /* EE */
  554. { 0x00, 0x00, 0 }, /* EF */
  555. { 0x00, 0x00, 0 }, /* F0 */
  556. { 0x00, 0x00, 0 }, /* F1 */
  557. { 0x00, 0x00, 0 }, /* F2 */
  558. { 0x00, 0x00, 0 }, /* F3 */
  559. { 0x00, 0x00, 0 }, /* F4 */
  560. { 0x00, 0x00, 0 }, /* F5 */
  561. { 0x00, 0x00, 0 }, /* F6 */
  562. { 0x00, 0x00, 0 }, /* F7 */
  563. { 0x00, 0x00, 0 }, /* F8 */
  564. { 0x00, 0x00, 0 }, /* F9 */
  565. { 0x00, 0x00, 0 }, /* FA */
  566. { 0x00, 0x00, 0 }, /* FB */
  567. { 0x00, 0x00, 0 }, /* FC */
  568. { 0x00, 0x00, 0 }, /* FD */
  569. { 0x00, 0x00, 0 }, /* FE */
  570. { 0xFF, 0x00, 1 }, /* FF */
  571. };
  572. static int max98088_volatile_register(struct snd_soc_codec *codec, unsigned int reg)
  573. {
  574. return max98088_access[reg].vol;
  575. }
  576. /*
  577. * Load equalizer DSP coefficient configurations registers
  578. */
  579. static void m98088_eq_band(struct snd_soc_codec *codec, unsigned int dai,
  580. unsigned int band, u16 *coefs)
  581. {
  582. unsigned int eq_reg;
  583. unsigned int i;
  584. BUG_ON(band > 4);
  585. BUG_ON(dai > 1);
  586. /* Load the base register address */
  587. eq_reg = dai ? M98088_REG_84_DAI2_EQ_BASE : M98088_REG_52_DAI1_EQ_BASE;
  588. /* Add the band address offset, note adjustment for word address */
  589. eq_reg += band * (M98088_COEFS_PER_BAND << 1);
  590. /* Step through the registers and coefs */
  591. for (i = 0; i < M98088_COEFS_PER_BAND; i++) {
  592. snd_soc_write(codec, eq_reg++, M98088_BYTE1(coefs[i]));
  593. snd_soc_write(codec, eq_reg++, M98088_BYTE0(coefs[i]));
  594. }
  595. }
  596. /*
  597. * Excursion limiter modes
  598. */
  599. static const char *max98088_exmode_texts[] = {
  600. "Off", "100Hz", "400Hz", "600Hz", "800Hz", "1000Hz", "200-400Hz",
  601. "400-600Hz", "400-800Hz",
  602. };
  603. static const unsigned int max98088_exmode_values[] = {
  604. 0x00, 0x43, 0x10, 0x20, 0x30, 0x40, 0x11, 0x22, 0x32
  605. };
  606. static const struct soc_enum max98088_exmode_enum =
  607. SOC_VALUE_ENUM_SINGLE(M98088_REG_41_SPKDHP, 0, 127,
  608. ARRAY_SIZE(max98088_exmode_texts),
  609. max98088_exmode_texts,
  610. max98088_exmode_values);
  611. static const char *max98088_ex_thresh[] = { /* volts PP */
  612. "0.6", "1.2", "1.8", "2.4", "3.0", "3.6", "4.2", "4.8"};
  613. static const struct soc_enum max98088_ex_thresh_enum[] = {
  614. SOC_ENUM_SINGLE(M98088_REG_42_SPKDHP_THRESH, 0, 8,
  615. max98088_ex_thresh),
  616. };
  617. static const char *max98088_fltr_mode[] = {"Voice", "Music" };
  618. static const struct soc_enum max98088_filter_mode_enum[] = {
  619. SOC_ENUM_SINGLE(M98088_REG_18_DAI1_FILTERS, 7, 2, max98088_fltr_mode),
  620. };
  621. static const char *max98088_extmic_text[] = { "None", "MIC1", "MIC2" };
  622. static const struct soc_enum max98088_extmic_enum =
  623. SOC_ENUM_SINGLE(M98088_REG_48_CFG_MIC, 0, 3, max98088_extmic_text);
  624. static const struct snd_kcontrol_new max98088_extmic_mux =
  625. SOC_DAPM_ENUM("External MIC Mux", max98088_extmic_enum);
  626. static const char *max98088_dai1_fltr[] = {
  627. "Off", "fc=258/fs=16k", "fc=500/fs=16k",
  628. "fc=258/fs=8k", "fc=500/fs=8k", "fc=200"};
  629. static const struct soc_enum max98088_dai1_dac_filter_enum[] = {
  630. SOC_ENUM_SINGLE(M98088_REG_18_DAI1_FILTERS, 0, 6, max98088_dai1_fltr),
  631. };
  632. static const struct soc_enum max98088_dai1_adc_filter_enum[] = {
  633. SOC_ENUM_SINGLE(M98088_REG_18_DAI1_FILTERS, 4, 6, max98088_dai1_fltr),
  634. };
  635. static int max98088_mic1pre_set(struct snd_kcontrol *kcontrol,
  636. struct snd_ctl_elem_value *ucontrol)
  637. {
  638. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  639. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  640. unsigned int sel = ucontrol->value.integer.value[0];
  641. max98088->mic1pre = sel;
  642. snd_soc_update_bits(codec, M98088_REG_35_LVL_MIC1, M98088_MICPRE_MASK,
  643. (1+sel)<<M98088_MICPRE_SHIFT);
  644. return 0;
  645. }
  646. static int max98088_mic1pre_get(struct snd_kcontrol *kcontrol,
  647. struct snd_ctl_elem_value *ucontrol)
  648. {
  649. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  650. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  651. ucontrol->value.integer.value[0] = max98088->mic1pre;
  652. return 0;
  653. }
  654. static int max98088_mic2pre_set(struct snd_kcontrol *kcontrol,
  655. struct snd_ctl_elem_value *ucontrol)
  656. {
  657. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  658. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  659. unsigned int sel = ucontrol->value.integer.value[0];
  660. max98088->mic2pre = sel;
  661. snd_soc_update_bits(codec, M98088_REG_36_LVL_MIC2, M98088_MICPRE_MASK,
  662. (1+sel)<<M98088_MICPRE_SHIFT);
  663. return 0;
  664. }
  665. static int max98088_mic2pre_get(struct snd_kcontrol *kcontrol,
  666. struct snd_ctl_elem_value *ucontrol)
  667. {
  668. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  669. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  670. ucontrol->value.integer.value[0] = max98088->mic2pre;
  671. return 0;
  672. }
  673. static const unsigned int max98088_micboost_tlv[] = {
  674. TLV_DB_RANGE_HEAD(2),
  675. 0, 1, TLV_DB_SCALE_ITEM(0, 2000, 0),
  676. 2, 2, TLV_DB_SCALE_ITEM(3000, 0, 0),
  677. };
  678. static const struct snd_kcontrol_new max98088_snd_controls[] = {
  679. SOC_DOUBLE_R("Headphone Volume", M98088_REG_39_LVL_HP_L,
  680. M98088_REG_3A_LVL_HP_R, 0, 31, 0),
  681. SOC_DOUBLE_R("Speaker Volume", M98088_REG_3D_LVL_SPK_L,
  682. M98088_REG_3E_LVL_SPK_R, 0, 31, 0),
  683. SOC_DOUBLE_R("Receiver Volume", M98088_REG_3B_LVL_REC_L,
  684. M98088_REG_3C_LVL_REC_R, 0, 31, 0),
  685. SOC_DOUBLE_R("Headphone Switch", M98088_REG_39_LVL_HP_L,
  686. M98088_REG_3A_LVL_HP_R, 7, 1, 1),
  687. SOC_DOUBLE_R("Speaker Switch", M98088_REG_3D_LVL_SPK_L,
  688. M98088_REG_3E_LVL_SPK_R, 7, 1, 1),
  689. SOC_DOUBLE_R("Receiver Switch", M98088_REG_3B_LVL_REC_L,
  690. M98088_REG_3C_LVL_REC_R, 7, 1, 1),
  691. SOC_SINGLE("MIC1 Volume", M98088_REG_35_LVL_MIC1, 0, 31, 1),
  692. SOC_SINGLE("MIC2 Volume", M98088_REG_36_LVL_MIC2, 0, 31, 1),
  693. SOC_SINGLE_EXT_TLV("MIC1 Boost Volume",
  694. M98088_REG_35_LVL_MIC1, 5, 2, 0,
  695. max98088_mic1pre_get, max98088_mic1pre_set,
  696. max98088_micboost_tlv),
  697. SOC_SINGLE_EXT_TLV("MIC2 Boost Volume",
  698. M98088_REG_36_LVL_MIC2, 5, 2, 0,
  699. max98088_mic2pre_get, max98088_mic2pre_set,
  700. max98088_micboost_tlv),
  701. SOC_SINGLE("INA Volume", M98088_REG_37_LVL_INA, 0, 7, 1),
  702. SOC_SINGLE("INB Volume", M98088_REG_38_LVL_INB, 0, 7, 1),
  703. SOC_SINGLE("ADCL Volume", M98088_REG_33_LVL_ADC_L, 0, 15, 0),
  704. SOC_SINGLE("ADCR Volume", M98088_REG_34_LVL_ADC_R, 0, 15, 0),
  705. SOC_SINGLE("ADCL Boost Volume", M98088_REG_33_LVL_ADC_L, 4, 3, 0),
  706. SOC_SINGLE("ADCR Boost Volume", M98088_REG_34_LVL_ADC_R, 4, 3, 0),
  707. SOC_SINGLE("EQ1 Switch", M98088_REG_49_CFG_LEVEL, 0, 1, 0),
  708. SOC_SINGLE("EQ2 Switch", M98088_REG_49_CFG_LEVEL, 1, 1, 0),
  709. SOC_ENUM("EX Limiter Mode", max98088_exmode_enum),
  710. SOC_ENUM("EX Limiter Threshold", max98088_ex_thresh_enum),
  711. SOC_ENUM("DAI1 Filter Mode", max98088_filter_mode_enum),
  712. SOC_ENUM("DAI1 DAC Filter", max98088_dai1_dac_filter_enum),
  713. SOC_ENUM("DAI1 ADC Filter", max98088_dai1_adc_filter_enum),
  714. SOC_SINGLE("DAI2 DC Block Switch", M98088_REG_20_DAI2_FILTERS,
  715. 0, 1, 0),
  716. SOC_SINGLE("ALC Switch", M98088_REG_43_SPKALC_COMP, 7, 1, 0),
  717. SOC_SINGLE("ALC Threshold", M98088_REG_43_SPKALC_COMP, 0, 7, 0),
  718. SOC_SINGLE("ALC Multiband", M98088_REG_43_SPKALC_COMP, 3, 1, 0),
  719. SOC_SINGLE("ALC Release Time", M98088_REG_43_SPKALC_COMP, 4, 7, 0),
  720. SOC_SINGLE("PWR Limiter Threshold", M98088_REG_44_PWRLMT_CFG,
  721. 4, 15, 0),
  722. SOC_SINGLE("PWR Limiter Weight", M98088_REG_44_PWRLMT_CFG, 0, 7, 0),
  723. SOC_SINGLE("PWR Limiter Time1", M98088_REG_45_PWRLMT_TIME, 0, 15, 0),
  724. SOC_SINGLE("PWR Limiter Time2", M98088_REG_45_PWRLMT_TIME, 4, 15, 0),
  725. SOC_SINGLE("THD Limiter Threshold", M98088_REG_46_THDLMT_CFG, 4, 15, 0),
  726. SOC_SINGLE("THD Limiter Time", M98088_REG_46_THDLMT_CFG, 0, 7, 0),
  727. };
  728. /* Left speaker mixer switch */
  729. static const struct snd_kcontrol_new max98088_left_speaker_mixer_controls[] = {
  730. SOC_DAPM_SINGLE("Left DAC1 Switch", M98088_REG_2B_MIX_SPK_LEFT, 0, 1, 0),
  731. SOC_DAPM_SINGLE("Right DAC1 Switch", M98088_REG_2B_MIX_SPK_LEFT, 7, 1, 0),
  732. SOC_DAPM_SINGLE("Left DAC2 Switch", M98088_REG_2B_MIX_SPK_LEFT, 0, 1, 0),
  733. SOC_DAPM_SINGLE("Right DAC2 Switch", M98088_REG_2B_MIX_SPK_LEFT, 7, 1, 0),
  734. SOC_DAPM_SINGLE("MIC1 Switch", M98088_REG_2B_MIX_SPK_LEFT, 5, 1, 0),
  735. SOC_DAPM_SINGLE("MIC2 Switch", M98088_REG_2B_MIX_SPK_LEFT, 6, 1, 0),
  736. SOC_DAPM_SINGLE("INA1 Switch", M98088_REG_2B_MIX_SPK_LEFT, 1, 1, 0),
  737. SOC_DAPM_SINGLE("INA2 Switch", M98088_REG_2B_MIX_SPK_LEFT, 2, 1, 0),
  738. SOC_DAPM_SINGLE("INB1 Switch", M98088_REG_2B_MIX_SPK_LEFT, 3, 1, 0),
  739. SOC_DAPM_SINGLE("INB2 Switch", M98088_REG_2B_MIX_SPK_LEFT, 4, 1, 0),
  740. };
  741. /* Right speaker mixer switch */
  742. static const struct snd_kcontrol_new max98088_right_speaker_mixer_controls[] = {
  743. SOC_DAPM_SINGLE("Left DAC1 Switch", M98088_REG_2C_MIX_SPK_RIGHT, 7, 1, 0),
  744. SOC_DAPM_SINGLE("Right DAC1 Switch", M98088_REG_2C_MIX_SPK_RIGHT, 0, 1, 0),
  745. SOC_DAPM_SINGLE("Left DAC2 Switch", M98088_REG_2C_MIX_SPK_RIGHT, 7, 1, 0),
  746. SOC_DAPM_SINGLE("Right DAC2 Switch", M98088_REG_2C_MIX_SPK_RIGHT, 0, 1, 0),
  747. SOC_DAPM_SINGLE("MIC1 Switch", M98088_REG_2C_MIX_SPK_RIGHT, 5, 1, 0),
  748. SOC_DAPM_SINGLE("MIC2 Switch", M98088_REG_2C_MIX_SPK_RIGHT, 6, 1, 0),
  749. SOC_DAPM_SINGLE("INA1 Switch", M98088_REG_2C_MIX_SPK_RIGHT, 1, 1, 0),
  750. SOC_DAPM_SINGLE("INA2 Switch", M98088_REG_2C_MIX_SPK_RIGHT, 2, 1, 0),
  751. SOC_DAPM_SINGLE("INB1 Switch", M98088_REG_2C_MIX_SPK_RIGHT, 3, 1, 0),
  752. SOC_DAPM_SINGLE("INB2 Switch", M98088_REG_2C_MIX_SPK_RIGHT, 4, 1, 0),
  753. };
  754. /* Left headphone mixer switch */
  755. static const struct snd_kcontrol_new max98088_left_hp_mixer_controls[] = {
  756. SOC_DAPM_SINGLE("Left DAC1 Switch", M98088_REG_25_MIX_HP_LEFT, 0, 1, 0),
  757. SOC_DAPM_SINGLE("Right DAC1 Switch", M98088_REG_25_MIX_HP_LEFT, 7, 1, 0),
  758. SOC_DAPM_SINGLE("Left DAC2 Switch", M98088_REG_25_MIX_HP_LEFT, 0, 1, 0),
  759. SOC_DAPM_SINGLE("Right DAC2 Switch", M98088_REG_25_MIX_HP_LEFT, 7, 1, 0),
  760. SOC_DAPM_SINGLE("MIC1 Switch", M98088_REG_25_MIX_HP_LEFT, 5, 1, 0),
  761. SOC_DAPM_SINGLE("MIC2 Switch", M98088_REG_25_MIX_HP_LEFT, 6, 1, 0),
  762. SOC_DAPM_SINGLE("INA1 Switch", M98088_REG_25_MIX_HP_LEFT, 1, 1, 0),
  763. SOC_DAPM_SINGLE("INA2 Switch", M98088_REG_25_MIX_HP_LEFT, 2, 1, 0),
  764. SOC_DAPM_SINGLE("INB1 Switch", M98088_REG_25_MIX_HP_LEFT, 3, 1, 0),
  765. SOC_DAPM_SINGLE("INB2 Switch", M98088_REG_25_MIX_HP_LEFT, 4, 1, 0),
  766. };
  767. /* Right headphone mixer switch */
  768. static const struct snd_kcontrol_new max98088_right_hp_mixer_controls[] = {
  769. SOC_DAPM_SINGLE("Left DAC1 Switch", M98088_REG_26_MIX_HP_RIGHT, 7, 1, 0),
  770. SOC_DAPM_SINGLE("Right DAC1 Switch", M98088_REG_26_MIX_HP_RIGHT, 0, 1, 0),
  771. SOC_DAPM_SINGLE("Left DAC2 Switch", M98088_REG_26_MIX_HP_RIGHT, 7, 1, 0),
  772. SOC_DAPM_SINGLE("Right DAC2 Switch", M98088_REG_26_MIX_HP_RIGHT, 0, 1, 0),
  773. SOC_DAPM_SINGLE("MIC1 Switch", M98088_REG_26_MIX_HP_RIGHT, 5, 1, 0),
  774. SOC_DAPM_SINGLE("MIC2 Switch", M98088_REG_26_MIX_HP_RIGHT, 6, 1, 0),
  775. SOC_DAPM_SINGLE("INA1 Switch", M98088_REG_26_MIX_HP_RIGHT, 1, 1, 0),
  776. SOC_DAPM_SINGLE("INA2 Switch", M98088_REG_26_MIX_HP_RIGHT, 2, 1, 0),
  777. SOC_DAPM_SINGLE("INB1 Switch", M98088_REG_26_MIX_HP_RIGHT, 3, 1, 0),
  778. SOC_DAPM_SINGLE("INB2 Switch", M98088_REG_26_MIX_HP_RIGHT, 4, 1, 0),
  779. };
  780. /* Left earpiece/receiver mixer switch */
  781. static const struct snd_kcontrol_new max98088_left_rec_mixer_controls[] = {
  782. SOC_DAPM_SINGLE("Left DAC1 Switch", M98088_REG_28_MIX_REC_LEFT, 0, 1, 0),
  783. SOC_DAPM_SINGLE("Right DAC1 Switch", M98088_REG_28_MIX_REC_LEFT, 7, 1, 0),
  784. SOC_DAPM_SINGLE("Left DAC2 Switch", M98088_REG_28_MIX_REC_LEFT, 0, 1, 0),
  785. SOC_DAPM_SINGLE("Right DAC2 Switch", M98088_REG_28_MIX_REC_LEFT, 7, 1, 0),
  786. SOC_DAPM_SINGLE("MIC1 Switch", M98088_REG_28_MIX_REC_LEFT, 5, 1, 0),
  787. SOC_DAPM_SINGLE("MIC2 Switch", M98088_REG_28_MIX_REC_LEFT, 6, 1, 0),
  788. SOC_DAPM_SINGLE("INA1 Switch", M98088_REG_28_MIX_REC_LEFT, 1, 1, 0),
  789. SOC_DAPM_SINGLE("INA2 Switch", M98088_REG_28_MIX_REC_LEFT, 2, 1, 0),
  790. SOC_DAPM_SINGLE("INB1 Switch", M98088_REG_28_MIX_REC_LEFT, 3, 1, 0),
  791. SOC_DAPM_SINGLE("INB2 Switch", M98088_REG_28_MIX_REC_LEFT, 4, 1, 0),
  792. };
  793. /* Right earpiece/receiver mixer switch */
  794. static const struct snd_kcontrol_new max98088_right_rec_mixer_controls[] = {
  795. SOC_DAPM_SINGLE("Left DAC1 Switch", M98088_REG_29_MIX_REC_RIGHT, 7, 1, 0),
  796. SOC_DAPM_SINGLE("Right DAC1 Switch", M98088_REG_29_MIX_REC_RIGHT, 0, 1, 0),
  797. SOC_DAPM_SINGLE("Left DAC2 Switch", M98088_REG_29_MIX_REC_RIGHT, 7, 1, 0),
  798. SOC_DAPM_SINGLE("Right DAC2 Switch", M98088_REG_29_MIX_REC_RIGHT, 0, 1, 0),
  799. SOC_DAPM_SINGLE("MIC1 Switch", M98088_REG_29_MIX_REC_RIGHT, 5, 1, 0),
  800. SOC_DAPM_SINGLE("MIC2 Switch", M98088_REG_29_MIX_REC_RIGHT, 6, 1, 0),
  801. SOC_DAPM_SINGLE("INA1 Switch", M98088_REG_29_MIX_REC_RIGHT, 1, 1, 0),
  802. SOC_DAPM_SINGLE("INA2 Switch", M98088_REG_29_MIX_REC_RIGHT, 2, 1, 0),
  803. SOC_DAPM_SINGLE("INB1 Switch", M98088_REG_29_MIX_REC_RIGHT, 3, 1, 0),
  804. SOC_DAPM_SINGLE("INB2 Switch", M98088_REG_29_MIX_REC_RIGHT, 4, 1, 0),
  805. };
  806. /* Left ADC mixer switch */
  807. static const struct snd_kcontrol_new max98088_left_ADC_mixer_controls[] = {
  808. SOC_DAPM_SINGLE("MIC1 Switch", M98088_REG_23_MIX_ADC_LEFT, 7, 1, 0),
  809. SOC_DAPM_SINGLE("MIC2 Switch", M98088_REG_23_MIX_ADC_LEFT, 6, 1, 0),
  810. SOC_DAPM_SINGLE("INA1 Switch", M98088_REG_23_MIX_ADC_LEFT, 3, 1, 0),
  811. SOC_DAPM_SINGLE("INA2 Switch", M98088_REG_23_MIX_ADC_LEFT, 2, 1, 0),
  812. SOC_DAPM_SINGLE("INB1 Switch", M98088_REG_23_MIX_ADC_LEFT, 1, 1, 0),
  813. SOC_DAPM_SINGLE("INB2 Switch", M98088_REG_23_MIX_ADC_LEFT, 0, 1, 0),
  814. };
  815. /* Right ADC mixer switch */
  816. static const struct snd_kcontrol_new max98088_right_ADC_mixer_controls[] = {
  817. SOC_DAPM_SINGLE("MIC1 Switch", M98088_REG_24_MIX_ADC_RIGHT, 7, 1, 0),
  818. SOC_DAPM_SINGLE("MIC2 Switch", M98088_REG_24_MIX_ADC_RIGHT, 6, 1, 0),
  819. SOC_DAPM_SINGLE("INA1 Switch", M98088_REG_24_MIX_ADC_RIGHT, 3, 1, 0),
  820. SOC_DAPM_SINGLE("INA2 Switch", M98088_REG_24_MIX_ADC_RIGHT, 2, 1, 0),
  821. SOC_DAPM_SINGLE("INB1 Switch", M98088_REG_24_MIX_ADC_RIGHT, 1, 1, 0),
  822. SOC_DAPM_SINGLE("INB2 Switch", M98088_REG_24_MIX_ADC_RIGHT, 0, 1, 0),
  823. };
  824. static int max98088_mic_event(struct snd_soc_dapm_widget *w,
  825. struct snd_kcontrol *kcontrol, int event)
  826. {
  827. struct snd_soc_codec *codec = w->codec;
  828. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  829. switch (event) {
  830. case SND_SOC_DAPM_POST_PMU:
  831. if (w->reg == M98088_REG_35_LVL_MIC1) {
  832. snd_soc_update_bits(codec, w->reg, M98088_MICPRE_MASK,
  833. (1+max98088->mic1pre)<<M98088_MICPRE_SHIFT);
  834. } else {
  835. snd_soc_update_bits(codec, w->reg, M98088_MICPRE_MASK,
  836. (1+max98088->mic2pre)<<M98088_MICPRE_SHIFT);
  837. }
  838. break;
  839. case SND_SOC_DAPM_POST_PMD:
  840. snd_soc_update_bits(codec, w->reg, M98088_MICPRE_MASK, 0);
  841. break;
  842. default:
  843. return -EINVAL;
  844. }
  845. return 0;
  846. }
  847. /*
  848. * The line inputs are 2-channel stereo inputs with the left
  849. * and right channels sharing a common PGA power control signal.
  850. */
  851. static int max98088_line_pga(struct snd_soc_dapm_widget *w,
  852. int event, int line, u8 channel)
  853. {
  854. struct snd_soc_codec *codec = w->codec;
  855. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  856. u8 *state;
  857. BUG_ON(!((channel == 1) || (channel == 2)));
  858. switch (line) {
  859. case LINE_INA:
  860. state = &max98088->ina_state;
  861. break;
  862. case LINE_INB:
  863. state = &max98088->inb_state;
  864. break;
  865. default:
  866. return -EINVAL;
  867. }
  868. switch (event) {
  869. case SND_SOC_DAPM_POST_PMU:
  870. *state |= channel;
  871. snd_soc_update_bits(codec, w->reg,
  872. (1 << w->shift), (1 << w->shift));
  873. break;
  874. case SND_SOC_DAPM_POST_PMD:
  875. *state &= ~channel;
  876. if (*state == 0) {
  877. snd_soc_update_bits(codec, w->reg,
  878. (1 << w->shift), 0);
  879. }
  880. break;
  881. default:
  882. return -EINVAL;
  883. }
  884. return 0;
  885. }
  886. static int max98088_pga_ina1_event(struct snd_soc_dapm_widget *w,
  887. struct snd_kcontrol *k, int event)
  888. {
  889. return max98088_line_pga(w, event, LINE_INA, 1);
  890. }
  891. static int max98088_pga_ina2_event(struct snd_soc_dapm_widget *w,
  892. struct snd_kcontrol *k, int event)
  893. {
  894. return max98088_line_pga(w, event, LINE_INA, 2);
  895. }
  896. static int max98088_pga_inb1_event(struct snd_soc_dapm_widget *w,
  897. struct snd_kcontrol *k, int event)
  898. {
  899. return max98088_line_pga(w, event, LINE_INB, 1);
  900. }
  901. static int max98088_pga_inb2_event(struct snd_soc_dapm_widget *w,
  902. struct snd_kcontrol *k, int event)
  903. {
  904. return max98088_line_pga(w, event, LINE_INB, 2);
  905. }
  906. static const struct snd_soc_dapm_widget max98088_dapm_widgets[] = {
  907. SND_SOC_DAPM_ADC("ADCL", "HiFi Capture", M98088_REG_4C_PWR_EN_IN, 1, 0),
  908. SND_SOC_DAPM_ADC("ADCR", "HiFi Capture", M98088_REG_4C_PWR_EN_IN, 0, 0),
  909. SND_SOC_DAPM_DAC("DACL1", "HiFi Playback",
  910. M98088_REG_4D_PWR_EN_OUT, 1, 0),
  911. SND_SOC_DAPM_DAC("DACR1", "HiFi Playback",
  912. M98088_REG_4D_PWR_EN_OUT, 0, 0),
  913. SND_SOC_DAPM_DAC("DACL2", "Aux Playback",
  914. M98088_REG_4D_PWR_EN_OUT, 1, 0),
  915. SND_SOC_DAPM_DAC("DACR2", "Aux Playback",
  916. M98088_REG_4D_PWR_EN_OUT, 0, 0),
  917. SND_SOC_DAPM_PGA("HP Left Out", M98088_REG_4D_PWR_EN_OUT,
  918. 7, 0, NULL, 0),
  919. SND_SOC_DAPM_PGA("HP Right Out", M98088_REG_4D_PWR_EN_OUT,
  920. 6, 0, NULL, 0),
  921. SND_SOC_DAPM_PGA("SPK Left Out", M98088_REG_4D_PWR_EN_OUT,
  922. 5, 0, NULL, 0),
  923. SND_SOC_DAPM_PGA("SPK Right Out", M98088_REG_4D_PWR_EN_OUT,
  924. 4, 0, NULL, 0),
  925. SND_SOC_DAPM_PGA("REC Left Out", M98088_REG_4D_PWR_EN_OUT,
  926. 3, 0, NULL, 0),
  927. SND_SOC_DAPM_PGA("REC Right Out", M98088_REG_4D_PWR_EN_OUT,
  928. 2, 0, NULL, 0),
  929. SND_SOC_DAPM_MUX("External MIC", SND_SOC_NOPM, 0, 0,
  930. &max98088_extmic_mux),
  931. SND_SOC_DAPM_MIXER("Left HP Mixer", SND_SOC_NOPM, 0, 0,
  932. &max98088_left_hp_mixer_controls[0],
  933. ARRAY_SIZE(max98088_left_hp_mixer_controls)),
  934. SND_SOC_DAPM_MIXER("Right HP Mixer", SND_SOC_NOPM, 0, 0,
  935. &max98088_right_hp_mixer_controls[0],
  936. ARRAY_SIZE(max98088_right_hp_mixer_controls)),
  937. SND_SOC_DAPM_MIXER("Left SPK Mixer", SND_SOC_NOPM, 0, 0,
  938. &max98088_left_speaker_mixer_controls[0],
  939. ARRAY_SIZE(max98088_left_speaker_mixer_controls)),
  940. SND_SOC_DAPM_MIXER("Right SPK Mixer", SND_SOC_NOPM, 0, 0,
  941. &max98088_right_speaker_mixer_controls[0],
  942. ARRAY_SIZE(max98088_right_speaker_mixer_controls)),
  943. SND_SOC_DAPM_MIXER("Left REC Mixer", SND_SOC_NOPM, 0, 0,
  944. &max98088_left_rec_mixer_controls[0],
  945. ARRAY_SIZE(max98088_left_rec_mixer_controls)),
  946. SND_SOC_DAPM_MIXER("Right REC Mixer", SND_SOC_NOPM, 0, 0,
  947. &max98088_right_rec_mixer_controls[0],
  948. ARRAY_SIZE(max98088_right_rec_mixer_controls)),
  949. SND_SOC_DAPM_MIXER("Left ADC Mixer", SND_SOC_NOPM, 0, 0,
  950. &max98088_left_ADC_mixer_controls[0],
  951. ARRAY_SIZE(max98088_left_ADC_mixer_controls)),
  952. SND_SOC_DAPM_MIXER("Right ADC Mixer", SND_SOC_NOPM, 0, 0,
  953. &max98088_right_ADC_mixer_controls[0],
  954. ARRAY_SIZE(max98088_right_ADC_mixer_controls)),
  955. SND_SOC_DAPM_PGA_E("MIC1 Input", M98088_REG_35_LVL_MIC1,
  956. 5, 0, NULL, 0, max98088_mic_event,
  957. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  958. SND_SOC_DAPM_PGA_E("MIC2 Input", M98088_REG_36_LVL_MIC2,
  959. 5, 0, NULL, 0, max98088_mic_event,
  960. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  961. SND_SOC_DAPM_PGA_E("INA1 Input", M98088_REG_4C_PWR_EN_IN,
  962. 7, 0, NULL, 0, max98088_pga_ina1_event,
  963. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  964. SND_SOC_DAPM_PGA_E("INA2 Input", M98088_REG_4C_PWR_EN_IN,
  965. 7, 0, NULL, 0, max98088_pga_ina2_event,
  966. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  967. SND_SOC_DAPM_PGA_E("INB1 Input", M98088_REG_4C_PWR_EN_IN,
  968. 6, 0, NULL, 0, max98088_pga_inb1_event,
  969. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  970. SND_SOC_DAPM_PGA_E("INB2 Input", M98088_REG_4C_PWR_EN_IN,
  971. 6, 0, NULL, 0, max98088_pga_inb2_event,
  972. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  973. SND_SOC_DAPM_MICBIAS("MICBIAS", M98088_REG_4C_PWR_EN_IN, 3, 0),
  974. SND_SOC_DAPM_OUTPUT("HPL"),
  975. SND_SOC_DAPM_OUTPUT("HPR"),
  976. SND_SOC_DAPM_OUTPUT("SPKL"),
  977. SND_SOC_DAPM_OUTPUT("SPKR"),
  978. SND_SOC_DAPM_OUTPUT("RECL"),
  979. SND_SOC_DAPM_OUTPUT("RECR"),
  980. SND_SOC_DAPM_INPUT("MIC1"),
  981. SND_SOC_DAPM_INPUT("MIC2"),
  982. SND_SOC_DAPM_INPUT("INA1"),
  983. SND_SOC_DAPM_INPUT("INA2"),
  984. SND_SOC_DAPM_INPUT("INB1"),
  985. SND_SOC_DAPM_INPUT("INB2"),
  986. };
  987. static const struct snd_soc_dapm_route max98088_audio_map[] = {
  988. /* Left headphone output mixer */
  989. {"Left HP Mixer", "Left DAC1 Switch", "DACL1"},
  990. {"Left HP Mixer", "Left DAC2 Switch", "DACL2"},
  991. {"Left HP Mixer", "Right DAC1 Switch", "DACR1"},
  992. {"Left HP Mixer", "Right DAC2 Switch", "DACR2"},
  993. {"Left HP Mixer", "MIC1 Switch", "MIC1 Input"},
  994. {"Left HP Mixer", "MIC2 Switch", "MIC2 Input"},
  995. {"Left HP Mixer", "INA1 Switch", "INA1 Input"},
  996. {"Left HP Mixer", "INA2 Switch", "INA2 Input"},
  997. {"Left HP Mixer", "INB1 Switch", "INB1 Input"},
  998. {"Left HP Mixer", "INB2 Switch", "INB2 Input"},
  999. /* Right headphone output mixer */
  1000. {"Right HP Mixer", "Left DAC1 Switch", "DACL1"},
  1001. {"Right HP Mixer", "Left DAC2 Switch", "DACL2" },
  1002. {"Right HP Mixer", "Right DAC1 Switch", "DACR1"},
  1003. {"Right HP Mixer", "Right DAC2 Switch", "DACR2"},
  1004. {"Right HP Mixer", "MIC1 Switch", "MIC1 Input"},
  1005. {"Right HP Mixer", "MIC2 Switch", "MIC2 Input"},
  1006. {"Right HP Mixer", "INA1 Switch", "INA1 Input"},
  1007. {"Right HP Mixer", "INA2 Switch", "INA2 Input"},
  1008. {"Right HP Mixer", "INB1 Switch", "INB1 Input"},
  1009. {"Right HP Mixer", "INB2 Switch", "INB2 Input"},
  1010. /* Left speaker output mixer */
  1011. {"Left SPK Mixer", "Left DAC1 Switch", "DACL1"},
  1012. {"Left SPK Mixer", "Left DAC2 Switch", "DACL2"},
  1013. {"Left SPK Mixer", "Right DAC1 Switch", "DACR1"},
  1014. {"Left SPK Mixer", "Right DAC2 Switch", "DACR2"},
  1015. {"Left SPK Mixer", "MIC1 Switch", "MIC1 Input"},
  1016. {"Left SPK Mixer", "MIC2 Switch", "MIC2 Input"},
  1017. {"Left SPK Mixer", "INA1 Switch", "INA1 Input"},
  1018. {"Left SPK Mixer", "INA2 Switch", "INA2 Input"},
  1019. {"Left SPK Mixer", "INB1 Switch", "INB1 Input"},
  1020. {"Left SPK Mixer", "INB2 Switch", "INB2 Input"},
  1021. /* Right speaker output mixer */
  1022. {"Right SPK Mixer", "Left DAC1 Switch", "DACL1"},
  1023. {"Right SPK Mixer", "Left DAC2 Switch", "DACL2"},
  1024. {"Right SPK Mixer", "Right DAC1 Switch", "DACR1"},
  1025. {"Right SPK Mixer", "Right DAC2 Switch", "DACR2"},
  1026. {"Right SPK Mixer", "MIC1 Switch", "MIC1 Input"},
  1027. {"Right SPK Mixer", "MIC2 Switch", "MIC2 Input"},
  1028. {"Right SPK Mixer", "INA1 Switch", "INA1 Input"},
  1029. {"Right SPK Mixer", "INA2 Switch", "INA2 Input"},
  1030. {"Right SPK Mixer", "INB1 Switch", "INB1 Input"},
  1031. {"Right SPK Mixer", "INB2 Switch", "INB2 Input"},
  1032. /* Earpiece/Receiver output mixer */
  1033. {"Left REC Mixer", "Left DAC1 Switch", "DACL1"},
  1034. {"Left REC Mixer", "Left DAC2 Switch", "DACL2"},
  1035. {"Left REC Mixer", "Right DAC1 Switch", "DACR1"},
  1036. {"Left REC Mixer", "Right DAC2 Switch", "DACR2"},
  1037. {"Left REC Mixer", "MIC1 Switch", "MIC1 Input"},
  1038. {"Left REC Mixer", "MIC2 Switch", "MIC2 Input"},
  1039. {"Left REC Mixer", "INA1 Switch", "INA1 Input"},
  1040. {"Left REC Mixer", "INA2 Switch", "INA2 Input"},
  1041. {"Left REC Mixer", "INB1 Switch", "INB1 Input"},
  1042. {"Left REC Mixer", "INB2 Switch", "INB2 Input"},
  1043. /* Earpiece/Receiver output mixer */
  1044. {"Right REC Mixer", "Left DAC1 Switch", "DACL1"},
  1045. {"Right REC Mixer", "Left DAC2 Switch", "DACL2"},
  1046. {"Right REC Mixer", "Right DAC1 Switch", "DACR1"},
  1047. {"Right REC Mixer", "Right DAC2 Switch", "DACR2"},
  1048. {"Right REC Mixer", "MIC1 Switch", "MIC1 Input"},
  1049. {"Right REC Mixer", "MIC2 Switch", "MIC2 Input"},
  1050. {"Right REC Mixer", "INA1 Switch", "INA1 Input"},
  1051. {"Right REC Mixer", "INA2 Switch", "INA2 Input"},
  1052. {"Right REC Mixer", "INB1 Switch", "INB1 Input"},
  1053. {"Right REC Mixer", "INB2 Switch", "INB2 Input"},
  1054. {"HP Left Out", NULL, "Left HP Mixer"},
  1055. {"HP Right Out", NULL, "Right HP Mixer"},
  1056. {"SPK Left Out", NULL, "Left SPK Mixer"},
  1057. {"SPK Right Out", NULL, "Right SPK Mixer"},
  1058. {"REC Left Out", NULL, "Left REC Mixer"},
  1059. {"REC Right Out", NULL, "Right REC Mixer"},
  1060. {"HPL", NULL, "HP Left Out"},
  1061. {"HPR", NULL, "HP Right Out"},
  1062. {"SPKL", NULL, "SPK Left Out"},
  1063. {"SPKR", NULL, "SPK Right Out"},
  1064. {"RECL", NULL, "REC Left Out"},
  1065. {"RECR", NULL, "REC Right Out"},
  1066. /* Left ADC input mixer */
  1067. {"Left ADC Mixer", "MIC1 Switch", "MIC1 Input"},
  1068. {"Left ADC Mixer", "MIC2 Switch", "MIC2 Input"},
  1069. {"Left ADC Mixer", "INA1 Switch", "INA1 Input"},
  1070. {"Left ADC Mixer", "INA2 Switch", "INA2 Input"},
  1071. {"Left ADC Mixer", "INB1 Switch", "INB1 Input"},
  1072. {"Left ADC Mixer", "INB2 Switch", "INB2 Input"},
  1073. /* Right ADC input mixer */
  1074. {"Right ADC Mixer", "MIC1 Switch", "MIC1 Input"},
  1075. {"Right ADC Mixer", "MIC2 Switch", "MIC2 Input"},
  1076. {"Right ADC Mixer", "INA1 Switch", "INA1 Input"},
  1077. {"Right ADC Mixer", "INA2 Switch", "INA2 Input"},
  1078. {"Right ADC Mixer", "INB1 Switch", "INB1 Input"},
  1079. {"Right ADC Mixer", "INB2 Switch", "INB2 Input"},
  1080. /* Inputs */
  1081. {"ADCL", NULL, "Left ADC Mixer"},
  1082. {"ADCR", NULL, "Right ADC Mixer"},
  1083. {"INA1 Input", NULL, "INA1"},
  1084. {"INA2 Input", NULL, "INA2"},
  1085. {"INB1 Input", NULL, "INB1"},
  1086. {"INB2 Input", NULL, "INB2"},
  1087. {"MIC1 Input", NULL, "MIC1"},
  1088. {"MIC2 Input", NULL, "MIC2"},
  1089. };
  1090. /* codec mclk clock divider coefficients */
  1091. static const struct {
  1092. u32 rate;
  1093. u8 sr;
  1094. } rate_table[] = {
  1095. {8000, 0x10},
  1096. {11025, 0x20},
  1097. {16000, 0x30},
  1098. {22050, 0x40},
  1099. {24000, 0x50},
  1100. {32000, 0x60},
  1101. {44100, 0x70},
  1102. {48000, 0x80},
  1103. {88200, 0x90},
  1104. {96000, 0xA0},
  1105. };
  1106. static inline int rate_value(int rate, u8 *value)
  1107. {
  1108. int i;
  1109. for (i = 0; i < ARRAY_SIZE(rate_table); i++) {
  1110. if (rate_table[i].rate >= rate) {
  1111. *value = rate_table[i].sr;
  1112. return 0;
  1113. }
  1114. }
  1115. *value = rate_table[0].sr;
  1116. return -EINVAL;
  1117. }
  1118. static int max98088_dai1_hw_params(struct snd_pcm_substream *substream,
  1119. struct snd_pcm_hw_params *params,
  1120. struct snd_soc_dai *dai)
  1121. {
  1122. struct snd_soc_codec *codec = dai->codec;
  1123. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  1124. struct max98088_cdata *cdata;
  1125. unsigned long long ni;
  1126. unsigned int rate;
  1127. u8 regval;
  1128. cdata = &max98088->dai[0];
  1129. rate = params_rate(params);
  1130. switch (params_format(params)) {
  1131. case SNDRV_PCM_FORMAT_S16_LE:
  1132. snd_soc_update_bits(codec, M98088_REG_14_DAI1_FORMAT,
  1133. M98088_DAI_WS, 0);
  1134. break;
  1135. case SNDRV_PCM_FORMAT_S24_LE:
  1136. snd_soc_update_bits(codec, M98088_REG_14_DAI1_FORMAT,
  1137. M98088_DAI_WS, M98088_DAI_WS);
  1138. break;
  1139. default:
  1140. return -EINVAL;
  1141. }
  1142. snd_soc_update_bits(codec, M98088_REG_51_PWR_SYS, M98088_SHDNRUN, 0);
  1143. if (rate_value(rate, &regval))
  1144. return -EINVAL;
  1145. snd_soc_update_bits(codec, M98088_REG_11_DAI1_CLKMODE,
  1146. M98088_CLKMODE_MASK, regval);
  1147. cdata->rate = rate;
  1148. /* Configure NI when operating as master */
  1149. if (snd_soc_read(codec, M98088_REG_14_DAI1_FORMAT)
  1150. & M98088_DAI_MAS) {
  1151. if (max98088->sysclk == 0) {
  1152. dev_err(codec->dev, "Invalid system clock frequency\n");
  1153. return -EINVAL;
  1154. }
  1155. ni = 65536ULL * (rate < 50000 ? 96ULL : 48ULL)
  1156. * (unsigned long long int)rate;
  1157. do_div(ni, (unsigned long long int)max98088->sysclk);
  1158. snd_soc_write(codec, M98088_REG_12_DAI1_CLKCFG_HI,
  1159. (ni >> 8) & 0x7F);
  1160. snd_soc_write(codec, M98088_REG_13_DAI1_CLKCFG_LO,
  1161. ni & 0xFF);
  1162. }
  1163. /* Update sample rate mode */
  1164. if (rate < 50000)
  1165. snd_soc_update_bits(codec, M98088_REG_18_DAI1_FILTERS,
  1166. M98088_DAI_DHF, 0);
  1167. else
  1168. snd_soc_update_bits(codec, M98088_REG_18_DAI1_FILTERS,
  1169. M98088_DAI_DHF, M98088_DAI_DHF);
  1170. snd_soc_update_bits(codec, M98088_REG_51_PWR_SYS, M98088_SHDNRUN,
  1171. M98088_SHDNRUN);
  1172. return 0;
  1173. }
  1174. static int max98088_dai2_hw_params(struct snd_pcm_substream *substream,
  1175. struct snd_pcm_hw_params *params,
  1176. struct snd_soc_dai *dai)
  1177. {
  1178. struct snd_soc_codec *codec = dai->codec;
  1179. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  1180. struct max98088_cdata *cdata;
  1181. unsigned long long ni;
  1182. unsigned int rate;
  1183. u8 regval;
  1184. cdata = &max98088->dai[1];
  1185. rate = params_rate(params);
  1186. switch (params_format(params)) {
  1187. case SNDRV_PCM_FORMAT_S16_LE:
  1188. snd_soc_update_bits(codec, M98088_REG_1C_DAI2_FORMAT,
  1189. M98088_DAI_WS, 0);
  1190. break;
  1191. case SNDRV_PCM_FORMAT_S24_LE:
  1192. snd_soc_update_bits(codec, M98088_REG_1C_DAI2_FORMAT,
  1193. M98088_DAI_WS, M98088_DAI_WS);
  1194. break;
  1195. default:
  1196. return -EINVAL;
  1197. }
  1198. snd_soc_update_bits(codec, M98088_REG_51_PWR_SYS, M98088_SHDNRUN, 0);
  1199. if (rate_value(rate, &regval))
  1200. return -EINVAL;
  1201. snd_soc_update_bits(codec, M98088_REG_19_DAI2_CLKMODE,
  1202. M98088_CLKMODE_MASK, regval);
  1203. cdata->rate = rate;
  1204. /* Configure NI when operating as master */
  1205. if (snd_soc_read(codec, M98088_REG_1C_DAI2_FORMAT)
  1206. & M98088_DAI_MAS) {
  1207. if (max98088->sysclk == 0) {
  1208. dev_err(codec->dev, "Invalid system clock frequency\n");
  1209. return -EINVAL;
  1210. }
  1211. ni = 65536ULL * (rate < 50000 ? 96ULL : 48ULL)
  1212. * (unsigned long long int)rate;
  1213. do_div(ni, (unsigned long long int)max98088->sysclk);
  1214. snd_soc_write(codec, M98088_REG_1A_DAI2_CLKCFG_HI,
  1215. (ni >> 8) & 0x7F);
  1216. snd_soc_write(codec, M98088_REG_1B_DAI2_CLKCFG_LO,
  1217. ni & 0xFF);
  1218. }
  1219. /* Update sample rate mode */
  1220. if (rate < 50000)
  1221. snd_soc_update_bits(codec, M98088_REG_20_DAI2_FILTERS,
  1222. M98088_DAI_DHF, 0);
  1223. else
  1224. snd_soc_update_bits(codec, M98088_REG_20_DAI2_FILTERS,
  1225. M98088_DAI_DHF, M98088_DAI_DHF);
  1226. snd_soc_update_bits(codec, M98088_REG_51_PWR_SYS, M98088_SHDNRUN,
  1227. M98088_SHDNRUN);
  1228. return 0;
  1229. }
  1230. static int max98088_dai_set_sysclk(struct snd_soc_dai *dai,
  1231. int clk_id, unsigned int freq, int dir)
  1232. {
  1233. struct snd_soc_codec *codec = dai->codec;
  1234. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  1235. /* Requested clock frequency is already setup */
  1236. if (freq == max98088->sysclk)
  1237. return 0;
  1238. /* Setup clocks for slave mode, and using the PLL
  1239. * PSCLK = 0x01 (when master clk is 10MHz to 20MHz)
  1240. * 0x02 (when master clk is 20MHz to 30MHz)..
  1241. */
  1242. if ((freq >= 10000000) && (freq < 20000000)) {
  1243. snd_soc_write(codec, M98088_REG_10_SYS_CLK, 0x10);
  1244. } else if ((freq >= 20000000) && (freq < 30000000)) {
  1245. snd_soc_write(codec, M98088_REG_10_SYS_CLK, 0x20);
  1246. } else {
  1247. dev_err(codec->dev, "Invalid master clock frequency\n");
  1248. return -EINVAL;
  1249. }
  1250. if (snd_soc_read(codec, M98088_REG_51_PWR_SYS) & M98088_SHDNRUN) {
  1251. snd_soc_update_bits(codec, M98088_REG_51_PWR_SYS,
  1252. M98088_SHDNRUN, 0);
  1253. snd_soc_update_bits(codec, M98088_REG_51_PWR_SYS,
  1254. M98088_SHDNRUN, M98088_SHDNRUN);
  1255. }
  1256. dev_dbg(dai->dev, "Clock source is %d at %uHz\n", clk_id, freq);
  1257. max98088->sysclk = freq;
  1258. return 0;
  1259. }
  1260. static int max98088_dai1_set_fmt(struct snd_soc_dai *codec_dai,
  1261. unsigned int fmt)
  1262. {
  1263. struct snd_soc_codec *codec = codec_dai->codec;
  1264. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  1265. struct max98088_cdata *cdata;
  1266. u8 reg15val;
  1267. u8 reg14val = 0;
  1268. cdata = &max98088->dai[0];
  1269. if (fmt != cdata->fmt) {
  1270. cdata->fmt = fmt;
  1271. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1272. case SND_SOC_DAIFMT_CBS_CFS:
  1273. /* Slave mode PLL */
  1274. snd_soc_write(codec, M98088_REG_12_DAI1_CLKCFG_HI,
  1275. 0x80);
  1276. snd_soc_write(codec, M98088_REG_13_DAI1_CLKCFG_LO,
  1277. 0x00);
  1278. break;
  1279. case SND_SOC_DAIFMT_CBM_CFM:
  1280. /* Set to master mode */
  1281. reg14val |= M98088_DAI_MAS;
  1282. break;
  1283. case SND_SOC_DAIFMT_CBS_CFM:
  1284. case SND_SOC_DAIFMT_CBM_CFS:
  1285. default:
  1286. dev_err(codec->dev, "Clock mode unsupported");
  1287. return -EINVAL;
  1288. }
  1289. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1290. case SND_SOC_DAIFMT_I2S:
  1291. reg14val |= M98088_DAI_DLY;
  1292. break;
  1293. case SND_SOC_DAIFMT_LEFT_J:
  1294. break;
  1295. default:
  1296. return -EINVAL;
  1297. }
  1298. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  1299. case SND_SOC_DAIFMT_NB_NF:
  1300. break;
  1301. case SND_SOC_DAIFMT_NB_IF:
  1302. reg14val |= M98088_DAI_WCI;
  1303. break;
  1304. case SND_SOC_DAIFMT_IB_NF:
  1305. reg14val |= M98088_DAI_BCI;
  1306. break;
  1307. case SND_SOC_DAIFMT_IB_IF:
  1308. reg14val |= M98088_DAI_BCI|M98088_DAI_WCI;
  1309. break;
  1310. default:
  1311. return -EINVAL;
  1312. }
  1313. snd_soc_update_bits(codec, M98088_REG_14_DAI1_FORMAT,
  1314. M98088_DAI_MAS | M98088_DAI_DLY | M98088_DAI_BCI |
  1315. M98088_DAI_WCI, reg14val);
  1316. reg15val = M98088_DAI_BSEL64;
  1317. if (max98088->digmic)
  1318. reg15val |= M98088_DAI_OSR64;
  1319. snd_soc_write(codec, M98088_REG_15_DAI1_CLOCK, reg15val);
  1320. }
  1321. return 0;
  1322. }
  1323. static int max98088_dai2_set_fmt(struct snd_soc_dai *codec_dai,
  1324. unsigned int fmt)
  1325. {
  1326. struct snd_soc_codec *codec = codec_dai->codec;
  1327. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  1328. struct max98088_cdata *cdata;
  1329. u8 reg1Cval = 0;
  1330. cdata = &max98088->dai[1];
  1331. if (fmt != cdata->fmt) {
  1332. cdata->fmt = fmt;
  1333. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1334. case SND_SOC_DAIFMT_CBS_CFS:
  1335. /* Slave mode PLL */
  1336. snd_soc_write(codec, M98088_REG_1A_DAI2_CLKCFG_HI,
  1337. 0x80);
  1338. snd_soc_write(codec, M98088_REG_1B_DAI2_CLKCFG_LO,
  1339. 0x00);
  1340. break;
  1341. case SND_SOC_DAIFMT_CBM_CFM:
  1342. /* Set to master mode */
  1343. reg1Cval |= M98088_DAI_MAS;
  1344. break;
  1345. case SND_SOC_DAIFMT_CBS_CFM:
  1346. case SND_SOC_DAIFMT_CBM_CFS:
  1347. default:
  1348. dev_err(codec->dev, "Clock mode unsupported");
  1349. return -EINVAL;
  1350. }
  1351. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1352. case SND_SOC_DAIFMT_I2S:
  1353. reg1Cval |= M98088_DAI_DLY;
  1354. break;
  1355. case SND_SOC_DAIFMT_LEFT_J:
  1356. break;
  1357. default:
  1358. return -EINVAL;
  1359. }
  1360. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  1361. case SND_SOC_DAIFMT_NB_NF:
  1362. break;
  1363. case SND_SOC_DAIFMT_NB_IF:
  1364. reg1Cval |= M98088_DAI_WCI;
  1365. break;
  1366. case SND_SOC_DAIFMT_IB_NF:
  1367. reg1Cval |= M98088_DAI_BCI;
  1368. break;
  1369. case SND_SOC_DAIFMT_IB_IF:
  1370. reg1Cval |= M98088_DAI_BCI|M98088_DAI_WCI;
  1371. break;
  1372. default:
  1373. return -EINVAL;
  1374. }
  1375. snd_soc_update_bits(codec, M98088_REG_1C_DAI2_FORMAT,
  1376. M98088_DAI_MAS | M98088_DAI_DLY | M98088_DAI_BCI |
  1377. M98088_DAI_WCI, reg1Cval);
  1378. snd_soc_write(codec, M98088_REG_1D_DAI2_CLOCK,
  1379. M98088_DAI_BSEL64);
  1380. }
  1381. return 0;
  1382. }
  1383. static int max98088_dai1_digital_mute(struct snd_soc_dai *codec_dai, int mute)
  1384. {
  1385. struct snd_soc_codec *codec = codec_dai->codec;
  1386. int reg;
  1387. if (mute)
  1388. reg = M98088_DAI_MUTE;
  1389. else
  1390. reg = 0;
  1391. snd_soc_update_bits(codec, M98088_REG_2F_LVL_DAI1_PLAY,
  1392. M98088_DAI_MUTE_MASK, reg);
  1393. return 0;
  1394. }
  1395. static int max98088_dai2_digital_mute(struct snd_soc_dai *codec_dai, int mute)
  1396. {
  1397. struct snd_soc_codec *codec = codec_dai->codec;
  1398. int reg;
  1399. if (mute)
  1400. reg = M98088_DAI_MUTE;
  1401. else
  1402. reg = 0;
  1403. snd_soc_update_bits(codec, M98088_REG_31_LVL_DAI2_PLAY,
  1404. M98088_DAI_MUTE_MASK, reg);
  1405. return 0;
  1406. }
  1407. static void max98088_sync_cache(struct snd_soc_codec *codec)
  1408. {
  1409. u8 *reg_cache = codec->reg_cache;
  1410. int i;
  1411. if (!codec->cache_sync)
  1412. return;
  1413. codec->cache_only = 0;
  1414. /* write back cached values if they're writeable and
  1415. * different from the hardware default.
  1416. */
  1417. for (i = 1; i < codec->driver->reg_cache_size; i++) {
  1418. if (!max98088_access[i].writable)
  1419. continue;
  1420. if (reg_cache[i] == max98088_reg[i])
  1421. continue;
  1422. snd_soc_write(codec, i, reg_cache[i]);
  1423. }
  1424. codec->cache_sync = 0;
  1425. }
  1426. static int max98088_set_bias_level(struct snd_soc_codec *codec,
  1427. enum snd_soc_bias_level level)
  1428. {
  1429. switch (level) {
  1430. case SND_SOC_BIAS_ON:
  1431. break;
  1432. case SND_SOC_BIAS_PREPARE:
  1433. break;
  1434. case SND_SOC_BIAS_STANDBY:
  1435. if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
  1436. max98088_sync_cache(codec);
  1437. snd_soc_update_bits(codec, M98088_REG_4C_PWR_EN_IN,
  1438. M98088_MBEN, M98088_MBEN);
  1439. break;
  1440. case SND_SOC_BIAS_OFF:
  1441. snd_soc_update_bits(codec, M98088_REG_4C_PWR_EN_IN,
  1442. M98088_MBEN, 0);
  1443. codec->cache_sync = 1;
  1444. break;
  1445. }
  1446. codec->dapm.bias_level = level;
  1447. return 0;
  1448. }
  1449. #define MAX98088_RATES SNDRV_PCM_RATE_8000_96000
  1450. #define MAX98088_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE)
  1451. static const struct snd_soc_dai_ops max98088_dai1_ops = {
  1452. .set_sysclk = max98088_dai_set_sysclk,
  1453. .set_fmt = max98088_dai1_set_fmt,
  1454. .hw_params = max98088_dai1_hw_params,
  1455. .digital_mute = max98088_dai1_digital_mute,
  1456. };
  1457. static const struct snd_soc_dai_ops max98088_dai2_ops = {
  1458. .set_sysclk = max98088_dai_set_sysclk,
  1459. .set_fmt = max98088_dai2_set_fmt,
  1460. .hw_params = max98088_dai2_hw_params,
  1461. .digital_mute = max98088_dai2_digital_mute,
  1462. };
  1463. static struct snd_soc_dai_driver max98088_dai[] = {
  1464. {
  1465. .name = "HiFi",
  1466. .playback = {
  1467. .stream_name = "HiFi Playback",
  1468. .channels_min = 1,
  1469. .channels_max = 2,
  1470. .rates = MAX98088_RATES,
  1471. .formats = MAX98088_FORMATS,
  1472. },
  1473. .capture = {
  1474. .stream_name = "HiFi Capture",
  1475. .channels_min = 1,
  1476. .channels_max = 2,
  1477. .rates = MAX98088_RATES,
  1478. .formats = MAX98088_FORMATS,
  1479. },
  1480. .ops = &max98088_dai1_ops,
  1481. },
  1482. {
  1483. .name = "Aux",
  1484. .playback = {
  1485. .stream_name = "Aux Playback",
  1486. .channels_min = 1,
  1487. .channels_max = 2,
  1488. .rates = MAX98088_RATES,
  1489. .formats = MAX98088_FORMATS,
  1490. },
  1491. .ops = &max98088_dai2_ops,
  1492. }
  1493. };
  1494. static const char *eq_mode_name[] = {"EQ1 Mode", "EQ2 Mode"};
  1495. static int max98088_get_channel(struct snd_soc_codec *codec, const char *name)
  1496. {
  1497. int i;
  1498. for (i = 0; i < ARRAY_SIZE(eq_mode_name); i++)
  1499. if (strcmp(name, eq_mode_name[i]) == 0)
  1500. return i;
  1501. /* Shouldn't happen */
  1502. dev_err(codec->dev, "Bad EQ channel name '%s'\n", name);
  1503. return -EINVAL;
  1504. }
  1505. static void max98088_setup_eq1(struct snd_soc_codec *codec)
  1506. {
  1507. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  1508. struct max98088_pdata *pdata = max98088->pdata;
  1509. struct max98088_eq_cfg *coef_set;
  1510. int best, best_val, save, i, sel, fs;
  1511. struct max98088_cdata *cdata;
  1512. cdata = &max98088->dai[0];
  1513. if (!pdata || !max98088->eq_textcnt)
  1514. return;
  1515. /* Find the selected configuration with nearest sample rate */
  1516. fs = cdata->rate;
  1517. sel = cdata->eq_sel;
  1518. best = 0;
  1519. best_val = INT_MAX;
  1520. for (i = 0; i < pdata->eq_cfgcnt; i++) {
  1521. if (strcmp(pdata->eq_cfg[i].name, max98088->eq_texts[sel]) == 0 &&
  1522. abs(pdata->eq_cfg[i].rate - fs) < best_val) {
  1523. best = i;
  1524. best_val = abs(pdata->eq_cfg[i].rate - fs);
  1525. }
  1526. }
  1527. dev_dbg(codec->dev, "Selected %s/%dHz for %dHz sample rate\n",
  1528. pdata->eq_cfg[best].name,
  1529. pdata->eq_cfg[best].rate, fs);
  1530. /* Disable EQ while configuring, and save current on/off state */
  1531. save = snd_soc_read(codec, M98088_REG_49_CFG_LEVEL);
  1532. snd_soc_update_bits(codec, M98088_REG_49_CFG_LEVEL, M98088_EQ1EN, 0);
  1533. coef_set = &pdata->eq_cfg[sel];
  1534. m98088_eq_band(codec, 0, 0, coef_set->band1);
  1535. m98088_eq_band(codec, 0, 1, coef_set->band2);
  1536. m98088_eq_band(codec, 0, 2, coef_set->band3);
  1537. m98088_eq_band(codec, 0, 3, coef_set->band4);
  1538. m98088_eq_band(codec, 0, 4, coef_set->band5);
  1539. /* Restore the original on/off state */
  1540. snd_soc_update_bits(codec, M98088_REG_49_CFG_LEVEL, M98088_EQ1EN, save);
  1541. }
  1542. static void max98088_setup_eq2(struct snd_soc_codec *codec)
  1543. {
  1544. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  1545. struct max98088_pdata *pdata = max98088->pdata;
  1546. struct max98088_eq_cfg *coef_set;
  1547. int best, best_val, save, i, sel, fs;
  1548. struct max98088_cdata *cdata;
  1549. cdata = &max98088->dai[1];
  1550. if (!pdata || !max98088->eq_textcnt)
  1551. return;
  1552. /* Find the selected configuration with nearest sample rate */
  1553. fs = cdata->rate;
  1554. sel = cdata->eq_sel;
  1555. best = 0;
  1556. best_val = INT_MAX;
  1557. for (i = 0; i < pdata->eq_cfgcnt; i++) {
  1558. if (strcmp(pdata->eq_cfg[i].name, max98088->eq_texts[sel]) == 0 &&
  1559. abs(pdata->eq_cfg[i].rate - fs) < best_val) {
  1560. best = i;
  1561. best_val = abs(pdata->eq_cfg[i].rate - fs);
  1562. }
  1563. }
  1564. dev_dbg(codec->dev, "Selected %s/%dHz for %dHz sample rate\n",
  1565. pdata->eq_cfg[best].name,
  1566. pdata->eq_cfg[best].rate, fs);
  1567. /* Disable EQ while configuring, and save current on/off state */
  1568. save = snd_soc_read(codec, M98088_REG_49_CFG_LEVEL);
  1569. snd_soc_update_bits(codec, M98088_REG_49_CFG_LEVEL, M98088_EQ2EN, 0);
  1570. coef_set = &pdata->eq_cfg[sel];
  1571. m98088_eq_band(codec, 1, 0, coef_set->band1);
  1572. m98088_eq_band(codec, 1, 1, coef_set->band2);
  1573. m98088_eq_band(codec, 1, 2, coef_set->band3);
  1574. m98088_eq_band(codec, 1, 3, coef_set->band4);
  1575. m98088_eq_band(codec, 1, 4, coef_set->band5);
  1576. /* Restore the original on/off state */
  1577. snd_soc_update_bits(codec, M98088_REG_49_CFG_LEVEL, M98088_EQ2EN,
  1578. save);
  1579. }
  1580. static int max98088_put_eq_enum(struct snd_kcontrol *kcontrol,
  1581. struct snd_ctl_elem_value *ucontrol)
  1582. {
  1583. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1584. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  1585. struct max98088_pdata *pdata = max98088->pdata;
  1586. int channel = max98088_get_channel(codec, kcontrol->id.name);
  1587. struct max98088_cdata *cdata;
  1588. int sel = ucontrol->value.integer.value[0];
  1589. if (channel < 0)
  1590. return channel;
  1591. cdata = &max98088->dai[channel];
  1592. if (sel >= pdata->eq_cfgcnt)
  1593. return -EINVAL;
  1594. cdata->eq_sel = sel;
  1595. switch (channel) {
  1596. case 0:
  1597. max98088_setup_eq1(codec);
  1598. break;
  1599. case 1:
  1600. max98088_setup_eq2(codec);
  1601. break;
  1602. }
  1603. return 0;
  1604. }
  1605. static int max98088_get_eq_enum(struct snd_kcontrol *kcontrol,
  1606. struct snd_ctl_elem_value *ucontrol)
  1607. {
  1608. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1609. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  1610. int channel = max98088_get_channel(codec, kcontrol->id.name);
  1611. struct max98088_cdata *cdata;
  1612. if (channel < 0)
  1613. return channel;
  1614. cdata = &max98088->dai[channel];
  1615. ucontrol->value.enumerated.item[0] = cdata->eq_sel;
  1616. return 0;
  1617. }
  1618. static void max98088_handle_eq_pdata(struct snd_soc_codec *codec)
  1619. {
  1620. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  1621. struct max98088_pdata *pdata = max98088->pdata;
  1622. struct max98088_eq_cfg *cfg;
  1623. unsigned int cfgcnt;
  1624. int i, j;
  1625. const char **t;
  1626. int ret;
  1627. struct snd_kcontrol_new controls[] = {
  1628. SOC_ENUM_EXT((char *)eq_mode_name[0],
  1629. max98088->eq_enum,
  1630. max98088_get_eq_enum,
  1631. max98088_put_eq_enum),
  1632. SOC_ENUM_EXT((char *)eq_mode_name[1],
  1633. max98088->eq_enum,
  1634. max98088_get_eq_enum,
  1635. max98088_put_eq_enum),
  1636. };
  1637. BUILD_BUG_ON(ARRAY_SIZE(controls) != ARRAY_SIZE(eq_mode_name));
  1638. cfg = pdata->eq_cfg;
  1639. cfgcnt = pdata->eq_cfgcnt;
  1640. /* Setup an array of texts for the equalizer enum.
  1641. * This is based on Mark Brown's equalizer driver code.
  1642. */
  1643. max98088->eq_textcnt = 0;
  1644. max98088->eq_texts = NULL;
  1645. for (i = 0; i < cfgcnt; i++) {
  1646. for (j = 0; j < max98088->eq_textcnt; j++) {
  1647. if (strcmp(cfg[i].name, max98088->eq_texts[j]) == 0)
  1648. break;
  1649. }
  1650. if (j != max98088->eq_textcnt)
  1651. continue;
  1652. /* Expand the array */
  1653. t = krealloc(max98088->eq_texts,
  1654. sizeof(char *) * (max98088->eq_textcnt + 1),
  1655. GFP_KERNEL);
  1656. if (t == NULL)
  1657. continue;
  1658. /* Store the new entry */
  1659. t[max98088->eq_textcnt] = cfg[i].name;
  1660. max98088->eq_textcnt++;
  1661. max98088->eq_texts = t;
  1662. }
  1663. /* Now point the soc_enum to .texts array items */
  1664. max98088->eq_enum.texts = max98088->eq_texts;
  1665. max98088->eq_enum.max = max98088->eq_textcnt;
  1666. ret = snd_soc_add_codec_controls(codec, controls, ARRAY_SIZE(controls));
  1667. if (ret != 0)
  1668. dev_err(codec->dev, "Failed to add EQ control: %d\n", ret);
  1669. }
  1670. static void max98088_handle_pdata(struct snd_soc_codec *codec)
  1671. {
  1672. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  1673. struct max98088_pdata *pdata = max98088->pdata;
  1674. u8 regval = 0;
  1675. if (!pdata) {
  1676. dev_dbg(codec->dev, "No platform data\n");
  1677. return;
  1678. }
  1679. /* Configure mic for analog/digital mic mode */
  1680. if (pdata->digmic_left_mode)
  1681. regval |= M98088_DIGMIC_L;
  1682. if (pdata->digmic_right_mode)
  1683. regval |= M98088_DIGMIC_R;
  1684. max98088->digmic = (regval ? 1 : 0);
  1685. snd_soc_write(codec, M98088_REG_48_CFG_MIC, regval);
  1686. /* Configure receiver output */
  1687. regval = ((pdata->receiver_mode) ? M98088_REC_LINEMODE : 0);
  1688. snd_soc_update_bits(codec, M98088_REG_2A_MIC_REC_CNTL,
  1689. M98088_REC_LINEMODE_MASK, regval);
  1690. /* Configure equalizers */
  1691. if (pdata->eq_cfgcnt)
  1692. max98088_handle_eq_pdata(codec);
  1693. }
  1694. #ifdef CONFIG_PM
  1695. static int max98088_suspend(struct snd_soc_codec *codec)
  1696. {
  1697. max98088_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1698. return 0;
  1699. }
  1700. static int max98088_resume(struct snd_soc_codec *codec)
  1701. {
  1702. max98088_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1703. return 0;
  1704. }
  1705. #else
  1706. #define max98088_suspend NULL
  1707. #define max98088_resume NULL
  1708. #endif
  1709. static int max98088_probe(struct snd_soc_codec *codec)
  1710. {
  1711. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  1712. struct max98088_cdata *cdata;
  1713. int ret = 0;
  1714. codec->cache_sync = 1;
  1715. ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C);
  1716. if (ret != 0) {
  1717. dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
  1718. return ret;
  1719. }
  1720. /* initialize private data */
  1721. max98088->sysclk = (unsigned)-1;
  1722. max98088->eq_textcnt = 0;
  1723. cdata = &max98088->dai[0];
  1724. cdata->rate = (unsigned)-1;
  1725. cdata->fmt = (unsigned)-1;
  1726. cdata->eq_sel = 0;
  1727. cdata = &max98088->dai[1];
  1728. cdata->rate = (unsigned)-1;
  1729. cdata->fmt = (unsigned)-1;
  1730. cdata->eq_sel = 0;
  1731. max98088->ina_state = 0;
  1732. max98088->inb_state = 0;
  1733. max98088->ex_mode = 0;
  1734. max98088->digmic = 0;
  1735. max98088->mic1pre = 0;
  1736. max98088->mic2pre = 0;
  1737. ret = snd_soc_read(codec, M98088_REG_FF_REV_ID);
  1738. if (ret < 0) {
  1739. dev_err(codec->dev, "Failed to read device revision: %d\n",
  1740. ret);
  1741. goto err_access;
  1742. }
  1743. dev_info(codec->dev, "revision %c\n", ret - 0x40 + 'A');
  1744. snd_soc_write(codec, M98088_REG_51_PWR_SYS, M98088_PWRSV);
  1745. /* initialize registers cache to hardware default */
  1746. max98088_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1747. snd_soc_write(codec, M98088_REG_0F_IRQ_ENABLE, 0x00);
  1748. snd_soc_write(codec, M98088_REG_22_MIX_DAC,
  1749. M98088_DAI1L_TO_DACL|M98088_DAI2L_TO_DACL|
  1750. M98088_DAI1R_TO_DACR|M98088_DAI2R_TO_DACR);
  1751. snd_soc_write(codec, M98088_REG_4E_BIAS_CNTL, 0xF0);
  1752. snd_soc_write(codec, M98088_REG_50_DAC_BIAS2, 0x0F);
  1753. snd_soc_write(codec, M98088_REG_16_DAI1_IOCFG,
  1754. M98088_S1NORMAL|M98088_SDATA);
  1755. snd_soc_write(codec, M98088_REG_1E_DAI2_IOCFG,
  1756. M98088_S2NORMAL|M98088_SDATA);
  1757. max98088_handle_pdata(codec);
  1758. snd_soc_add_codec_controls(codec, max98088_snd_controls,
  1759. ARRAY_SIZE(max98088_snd_controls));
  1760. err_access:
  1761. return ret;
  1762. }
  1763. static int max98088_remove(struct snd_soc_codec *codec)
  1764. {
  1765. struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
  1766. max98088_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1767. kfree(max98088->eq_texts);
  1768. return 0;
  1769. }
  1770. static struct snd_soc_codec_driver soc_codec_dev_max98088 = {
  1771. .probe = max98088_probe,
  1772. .remove = max98088_remove,
  1773. .suspend = max98088_suspend,
  1774. .resume = max98088_resume,
  1775. .set_bias_level = max98088_set_bias_level,
  1776. .reg_cache_size = ARRAY_SIZE(max98088_reg),
  1777. .reg_word_size = sizeof(u8),
  1778. .reg_cache_default = max98088_reg,
  1779. .volatile_register = max98088_volatile_register,
  1780. .dapm_widgets = max98088_dapm_widgets,
  1781. .num_dapm_widgets = ARRAY_SIZE(max98088_dapm_widgets),
  1782. .dapm_routes = max98088_audio_map,
  1783. .num_dapm_routes = ARRAY_SIZE(max98088_audio_map),
  1784. };
  1785. static int max98088_i2c_probe(struct i2c_client *i2c,
  1786. const struct i2c_device_id *id)
  1787. {
  1788. struct max98088_priv *max98088;
  1789. int ret;
  1790. max98088 = devm_kzalloc(&i2c->dev, sizeof(struct max98088_priv),
  1791. GFP_KERNEL);
  1792. if (max98088 == NULL)
  1793. return -ENOMEM;
  1794. max98088->devtype = id->driver_data;
  1795. i2c_set_clientdata(i2c, max98088);
  1796. max98088->pdata = i2c->dev.platform_data;
  1797. ret = snd_soc_register_codec(&i2c->dev,
  1798. &soc_codec_dev_max98088, &max98088_dai[0], 2);
  1799. return ret;
  1800. }
  1801. static int __devexit max98088_i2c_remove(struct i2c_client *client)
  1802. {
  1803. snd_soc_unregister_codec(&client->dev);
  1804. return 0;
  1805. }
  1806. static const struct i2c_device_id max98088_i2c_id[] = {
  1807. { "max98088", MAX98088 },
  1808. { "max98089", MAX98089 },
  1809. { }
  1810. };
  1811. MODULE_DEVICE_TABLE(i2c, max98088_i2c_id);
  1812. static struct i2c_driver max98088_i2c_driver = {
  1813. .driver = {
  1814. .name = "max98088",
  1815. .owner = THIS_MODULE,
  1816. },
  1817. .probe = max98088_i2c_probe,
  1818. .remove = __devexit_p(max98088_i2c_remove),
  1819. .id_table = max98088_i2c_id,
  1820. };
  1821. static int __init max98088_init(void)
  1822. {
  1823. int ret;
  1824. ret = i2c_add_driver(&max98088_i2c_driver);
  1825. if (ret)
  1826. pr_err("Failed to register max98088 I2C driver: %d\n", ret);
  1827. return ret;
  1828. }
  1829. module_init(max98088_init);
  1830. static void __exit max98088_exit(void)
  1831. {
  1832. i2c_del_driver(&max98088_i2c_driver);
  1833. }
  1834. module_exit(max98088_exit);
  1835. MODULE_DESCRIPTION("ALSA SoC MAX98088 driver");
  1836. MODULE_AUTHOR("Peter Hsiang, Jesse Marroquin");
  1837. MODULE_LICENSE("GPL");