max98095.c 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400
  1. /*
  2. * max98095.c -- MAX98095 ALSA SoC Audio driver
  3. *
  4. * Copyright 2011 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/max98095.h>
  26. #include "max98095.h"
  27. enum max98095_type {
  28. MAX98095,
  29. };
  30. struct max98095_cdata {
  31. unsigned int rate;
  32. unsigned int fmt;
  33. int eq_sel;
  34. int bq_sel;
  35. };
  36. struct max98095_priv {
  37. enum max98095_type devtype;
  38. struct max98095_pdata *pdata;
  39. unsigned int sysclk;
  40. struct max98095_cdata dai[3];
  41. const char **eq_texts;
  42. const char **bq_texts;
  43. struct soc_enum eq_enum;
  44. struct soc_enum bq_enum;
  45. int eq_textcnt;
  46. int bq_textcnt;
  47. u8 lin_state;
  48. unsigned int mic1pre;
  49. unsigned int mic2pre;
  50. };
  51. static const u8 max98095_reg_def[M98095_REG_CNT] = {
  52. 0x00, /* 00 */
  53. 0x00, /* 01 */
  54. 0x00, /* 02 */
  55. 0x00, /* 03 */
  56. 0x00, /* 04 */
  57. 0x00, /* 05 */
  58. 0x00, /* 06 */
  59. 0x00, /* 07 */
  60. 0x00, /* 08 */
  61. 0x00, /* 09 */
  62. 0x00, /* 0A */
  63. 0x00, /* 0B */
  64. 0x00, /* 0C */
  65. 0x00, /* 0D */
  66. 0x00, /* 0E */
  67. 0x00, /* 0F */
  68. 0x00, /* 10 */
  69. 0x00, /* 11 */
  70. 0x00, /* 12 */
  71. 0x00, /* 13 */
  72. 0x00, /* 14 */
  73. 0x00, /* 15 */
  74. 0x00, /* 16 */
  75. 0x00, /* 17 */
  76. 0x00, /* 18 */
  77. 0x00, /* 19 */
  78. 0x00, /* 1A */
  79. 0x00, /* 1B */
  80. 0x00, /* 1C */
  81. 0x00, /* 1D */
  82. 0x00, /* 1E */
  83. 0x00, /* 1F */
  84. 0x00, /* 20 */
  85. 0x00, /* 21 */
  86. 0x00, /* 22 */
  87. 0x00, /* 23 */
  88. 0x00, /* 24 */
  89. 0x00, /* 25 */
  90. 0x00, /* 26 */
  91. 0x00, /* 27 */
  92. 0x00, /* 28 */
  93. 0x00, /* 29 */
  94. 0x00, /* 2A */
  95. 0x00, /* 2B */
  96. 0x00, /* 2C */
  97. 0x00, /* 2D */
  98. 0x00, /* 2E */
  99. 0x00, /* 2F */
  100. 0x00, /* 30 */
  101. 0x00, /* 31 */
  102. 0x00, /* 32 */
  103. 0x00, /* 33 */
  104. 0x00, /* 34 */
  105. 0x00, /* 35 */
  106. 0x00, /* 36 */
  107. 0x00, /* 37 */
  108. 0x00, /* 38 */
  109. 0x00, /* 39 */
  110. 0x00, /* 3A */
  111. 0x00, /* 3B */
  112. 0x00, /* 3C */
  113. 0x00, /* 3D */
  114. 0x00, /* 3E */
  115. 0x00, /* 3F */
  116. 0x00, /* 40 */
  117. 0x00, /* 41 */
  118. 0x00, /* 42 */
  119. 0x00, /* 43 */
  120. 0x00, /* 44 */
  121. 0x00, /* 45 */
  122. 0x00, /* 46 */
  123. 0x00, /* 47 */
  124. 0x00, /* 48 */
  125. 0x00, /* 49 */
  126. 0x00, /* 4A */
  127. 0x00, /* 4B */
  128. 0x00, /* 4C */
  129. 0x00, /* 4D */
  130. 0x00, /* 4E */
  131. 0x00, /* 4F */
  132. 0x00, /* 50 */
  133. 0x00, /* 51 */
  134. 0x00, /* 52 */
  135. 0x00, /* 53 */
  136. 0x00, /* 54 */
  137. 0x00, /* 55 */
  138. 0x00, /* 56 */
  139. 0x00, /* 57 */
  140. 0x00, /* 58 */
  141. 0x00, /* 59 */
  142. 0x00, /* 5A */
  143. 0x00, /* 5B */
  144. 0x00, /* 5C */
  145. 0x00, /* 5D */
  146. 0x00, /* 5E */
  147. 0x00, /* 5F */
  148. 0x00, /* 60 */
  149. 0x00, /* 61 */
  150. 0x00, /* 62 */
  151. 0x00, /* 63 */
  152. 0x00, /* 64 */
  153. 0x00, /* 65 */
  154. 0x00, /* 66 */
  155. 0x00, /* 67 */
  156. 0x00, /* 68 */
  157. 0x00, /* 69 */
  158. 0x00, /* 6A */
  159. 0x00, /* 6B */
  160. 0x00, /* 6C */
  161. 0x00, /* 6D */
  162. 0x00, /* 6E */
  163. 0x00, /* 6F */
  164. 0x00, /* 70 */
  165. 0x00, /* 71 */
  166. 0x00, /* 72 */
  167. 0x00, /* 73 */
  168. 0x00, /* 74 */
  169. 0x00, /* 75 */
  170. 0x00, /* 76 */
  171. 0x00, /* 77 */
  172. 0x00, /* 78 */
  173. 0x00, /* 79 */
  174. 0x00, /* 7A */
  175. 0x00, /* 7B */
  176. 0x00, /* 7C */
  177. 0x00, /* 7D */
  178. 0x00, /* 7E */
  179. 0x00, /* 7F */
  180. 0x00, /* 80 */
  181. 0x00, /* 81 */
  182. 0x00, /* 82 */
  183. 0x00, /* 83 */
  184. 0x00, /* 84 */
  185. 0x00, /* 85 */
  186. 0x00, /* 86 */
  187. 0x00, /* 87 */
  188. 0x00, /* 88 */
  189. 0x00, /* 89 */
  190. 0x00, /* 8A */
  191. 0x00, /* 8B */
  192. 0x00, /* 8C */
  193. 0x00, /* 8D */
  194. 0x00, /* 8E */
  195. 0x00, /* 8F */
  196. 0x00, /* 90 */
  197. 0x00, /* 91 */
  198. 0x30, /* 92 */
  199. 0xF0, /* 93 */
  200. 0x00, /* 94 */
  201. 0x00, /* 95 */
  202. 0x3F, /* 96 */
  203. 0x00, /* 97 */
  204. 0x00, /* 98 */
  205. 0x00, /* 99 */
  206. 0x00, /* 9A */
  207. 0x00, /* 9B */
  208. 0x00, /* 9C */
  209. 0x00, /* 9D */
  210. 0x00, /* 9E */
  211. 0x00, /* 9F */
  212. 0x00, /* A0 */
  213. 0x00, /* A1 */
  214. 0x00, /* A2 */
  215. 0x00, /* A3 */
  216. 0x00, /* A4 */
  217. 0x00, /* A5 */
  218. 0x00, /* A6 */
  219. 0x00, /* A7 */
  220. 0x00, /* A8 */
  221. 0x00, /* A9 */
  222. 0x00, /* AA */
  223. 0x00, /* AB */
  224. 0x00, /* AC */
  225. 0x00, /* AD */
  226. 0x00, /* AE */
  227. 0x00, /* AF */
  228. 0x00, /* B0 */
  229. 0x00, /* B1 */
  230. 0x00, /* B2 */
  231. 0x00, /* B3 */
  232. 0x00, /* B4 */
  233. 0x00, /* B5 */
  234. 0x00, /* B6 */
  235. 0x00, /* B7 */
  236. 0x00, /* B8 */
  237. 0x00, /* B9 */
  238. 0x00, /* BA */
  239. 0x00, /* BB */
  240. 0x00, /* BC */
  241. 0x00, /* BD */
  242. 0x00, /* BE */
  243. 0x00, /* BF */
  244. 0x00, /* C0 */
  245. 0x00, /* C1 */
  246. 0x00, /* C2 */
  247. 0x00, /* C3 */
  248. 0x00, /* C4 */
  249. 0x00, /* C5 */
  250. 0x00, /* C6 */
  251. 0x00, /* C7 */
  252. 0x00, /* C8 */
  253. 0x00, /* C9 */
  254. 0x00, /* CA */
  255. 0x00, /* CB */
  256. 0x00, /* CC */
  257. 0x00, /* CD */
  258. 0x00, /* CE */
  259. 0x00, /* CF */
  260. 0x00, /* D0 */
  261. 0x00, /* D1 */
  262. 0x00, /* D2 */
  263. 0x00, /* D3 */
  264. 0x00, /* D4 */
  265. 0x00, /* D5 */
  266. 0x00, /* D6 */
  267. 0x00, /* D7 */
  268. 0x00, /* D8 */
  269. 0x00, /* D9 */
  270. 0x00, /* DA */
  271. 0x00, /* DB */
  272. 0x00, /* DC */
  273. 0x00, /* DD */
  274. 0x00, /* DE */
  275. 0x00, /* DF */
  276. 0x00, /* E0 */
  277. 0x00, /* E1 */
  278. 0x00, /* E2 */
  279. 0x00, /* E3 */
  280. 0x00, /* E4 */
  281. 0x00, /* E5 */
  282. 0x00, /* E6 */
  283. 0x00, /* E7 */
  284. 0x00, /* E8 */
  285. 0x00, /* E9 */
  286. 0x00, /* EA */
  287. 0x00, /* EB */
  288. 0x00, /* EC */
  289. 0x00, /* ED */
  290. 0x00, /* EE */
  291. 0x00, /* EF */
  292. 0x00, /* F0 */
  293. 0x00, /* F1 */
  294. 0x00, /* F2 */
  295. 0x00, /* F3 */
  296. 0x00, /* F4 */
  297. 0x00, /* F5 */
  298. 0x00, /* F6 */
  299. 0x00, /* F7 */
  300. 0x00, /* F8 */
  301. 0x00, /* F9 */
  302. 0x00, /* FA */
  303. 0x00, /* FB */
  304. 0x00, /* FC */
  305. 0x00, /* FD */
  306. 0x00, /* FE */
  307. 0x00, /* FF */
  308. };
  309. static struct {
  310. int readable;
  311. int writable;
  312. } max98095_access[M98095_REG_CNT] = {
  313. { 0x00, 0x00 }, /* 00 */
  314. { 0xFF, 0x00 }, /* 01 */
  315. { 0xFF, 0x00 }, /* 02 */
  316. { 0xFF, 0x00 }, /* 03 */
  317. { 0xFF, 0x00 }, /* 04 */
  318. { 0xFF, 0x00 }, /* 05 */
  319. { 0xFF, 0x00 }, /* 06 */
  320. { 0xFF, 0x00 }, /* 07 */
  321. { 0xFF, 0x00 }, /* 08 */
  322. { 0xFF, 0x00 }, /* 09 */
  323. { 0xFF, 0x00 }, /* 0A */
  324. { 0xFF, 0x00 }, /* 0B */
  325. { 0xFF, 0x00 }, /* 0C */
  326. { 0xFF, 0x00 }, /* 0D */
  327. { 0xFF, 0x00 }, /* 0E */
  328. { 0xFF, 0x9F }, /* 0F */
  329. { 0xFF, 0xFF }, /* 10 */
  330. { 0xFF, 0xFF }, /* 11 */
  331. { 0xFF, 0xFF }, /* 12 */
  332. { 0xFF, 0xFF }, /* 13 */
  333. { 0xFF, 0xFF }, /* 14 */
  334. { 0xFF, 0xFF }, /* 15 */
  335. { 0xFF, 0xFF }, /* 16 */
  336. { 0xFF, 0xFF }, /* 17 */
  337. { 0xFF, 0xFF }, /* 18 */
  338. { 0xFF, 0xFF }, /* 19 */
  339. { 0xFF, 0xFF }, /* 1A */
  340. { 0xFF, 0xFF }, /* 1B */
  341. { 0xFF, 0xFF }, /* 1C */
  342. { 0xFF, 0xFF }, /* 1D */
  343. { 0xFF, 0x77 }, /* 1E */
  344. { 0xFF, 0x77 }, /* 1F */
  345. { 0xFF, 0x77 }, /* 20 */
  346. { 0xFF, 0x77 }, /* 21 */
  347. { 0xFF, 0x77 }, /* 22 */
  348. { 0xFF, 0x77 }, /* 23 */
  349. { 0xFF, 0xFF }, /* 24 */
  350. { 0xFF, 0x7F }, /* 25 */
  351. { 0xFF, 0x31 }, /* 26 */
  352. { 0xFF, 0xFF }, /* 27 */
  353. { 0xFF, 0xFF }, /* 28 */
  354. { 0xFF, 0xFF }, /* 29 */
  355. { 0xFF, 0xF7 }, /* 2A */
  356. { 0xFF, 0x2F }, /* 2B */
  357. { 0xFF, 0xEF }, /* 2C */
  358. { 0xFF, 0xFF }, /* 2D */
  359. { 0xFF, 0xFF }, /* 2E */
  360. { 0xFF, 0xFF }, /* 2F */
  361. { 0xFF, 0xFF }, /* 30 */
  362. { 0xFF, 0xFF }, /* 31 */
  363. { 0xFF, 0xFF }, /* 32 */
  364. { 0xFF, 0xFF }, /* 33 */
  365. { 0xFF, 0xF7 }, /* 34 */
  366. { 0xFF, 0x2F }, /* 35 */
  367. { 0xFF, 0xCF }, /* 36 */
  368. { 0xFF, 0xFF }, /* 37 */
  369. { 0xFF, 0xFF }, /* 38 */
  370. { 0xFF, 0xFF }, /* 39 */
  371. { 0xFF, 0xFF }, /* 3A */
  372. { 0xFF, 0xFF }, /* 3B */
  373. { 0xFF, 0xFF }, /* 3C */
  374. { 0xFF, 0xFF }, /* 3D */
  375. { 0xFF, 0xF7 }, /* 3E */
  376. { 0xFF, 0x2F }, /* 3F */
  377. { 0xFF, 0xCF }, /* 40 */
  378. { 0xFF, 0xFF }, /* 41 */
  379. { 0xFF, 0x77 }, /* 42 */
  380. { 0xFF, 0xFF }, /* 43 */
  381. { 0xFF, 0xFF }, /* 44 */
  382. { 0xFF, 0xFF }, /* 45 */
  383. { 0xFF, 0xFF }, /* 46 */
  384. { 0xFF, 0xFF }, /* 47 */
  385. { 0xFF, 0xFF }, /* 48 */
  386. { 0xFF, 0x0F }, /* 49 */
  387. { 0xFF, 0xFF }, /* 4A */
  388. { 0xFF, 0xFF }, /* 4B */
  389. { 0xFF, 0x3F }, /* 4C */
  390. { 0xFF, 0x3F }, /* 4D */
  391. { 0xFF, 0x3F }, /* 4E */
  392. { 0xFF, 0xFF }, /* 4F */
  393. { 0xFF, 0x7F }, /* 50 */
  394. { 0xFF, 0x7F }, /* 51 */
  395. { 0xFF, 0x0F }, /* 52 */
  396. { 0xFF, 0x3F }, /* 53 */
  397. { 0xFF, 0x3F }, /* 54 */
  398. { 0xFF, 0x3F }, /* 55 */
  399. { 0xFF, 0xFF }, /* 56 */
  400. { 0xFF, 0xFF }, /* 57 */
  401. { 0xFF, 0xBF }, /* 58 */
  402. { 0xFF, 0x1F }, /* 59 */
  403. { 0xFF, 0xBF }, /* 5A */
  404. { 0xFF, 0x1F }, /* 5B */
  405. { 0xFF, 0xBF }, /* 5C */
  406. { 0xFF, 0x3F }, /* 5D */
  407. { 0xFF, 0x3F }, /* 5E */
  408. { 0xFF, 0x7F }, /* 5F */
  409. { 0xFF, 0x7F }, /* 60 */
  410. { 0xFF, 0x47 }, /* 61 */
  411. { 0xFF, 0x9F }, /* 62 */
  412. { 0xFF, 0x9F }, /* 63 */
  413. { 0xFF, 0x9F }, /* 64 */
  414. { 0xFF, 0x9F }, /* 65 */
  415. { 0xFF, 0x9F }, /* 66 */
  416. { 0xFF, 0xBF }, /* 67 */
  417. { 0xFF, 0xBF }, /* 68 */
  418. { 0xFF, 0xFF }, /* 69 */
  419. { 0xFF, 0xFF }, /* 6A */
  420. { 0xFF, 0x7F }, /* 6B */
  421. { 0xFF, 0xF7 }, /* 6C */
  422. { 0xFF, 0xFF }, /* 6D */
  423. { 0xFF, 0xFF }, /* 6E */
  424. { 0xFF, 0x1F }, /* 6F */
  425. { 0xFF, 0xF7 }, /* 70 */
  426. { 0xFF, 0xFF }, /* 71 */
  427. { 0xFF, 0xFF }, /* 72 */
  428. { 0xFF, 0x1F }, /* 73 */
  429. { 0xFF, 0xF7 }, /* 74 */
  430. { 0xFF, 0xFF }, /* 75 */
  431. { 0xFF, 0xFF }, /* 76 */
  432. { 0xFF, 0x1F }, /* 77 */
  433. { 0xFF, 0xF7 }, /* 78 */
  434. { 0xFF, 0xFF }, /* 79 */
  435. { 0xFF, 0xFF }, /* 7A */
  436. { 0xFF, 0x1F }, /* 7B */
  437. { 0xFF, 0xF7 }, /* 7C */
  438. { 0xFF, 0xFF }, /* 7D */
  439. { 0xFF, 0xFF }, /* 7E */
  440. { 0xFF, 0x1F }, /* 7F */
  441. { 0xFF, 0xF7 }, /* 80 */
  442. { 0xFF, 0xFF }, /* 81 */
  443. { 0xFF, 0xFF }, /* 82 */
  444. { 0xFF, 0x1F }, /* 83 */
  445. { 0xFF, 0x7F }, /* 84 */
  446. { 0xFF, 0x0F }, /* 85 */
  447. { 0xFF, 0xD8 }, /* 86 */
  448. { 0xFF, 0xFF }, /* 87 */
  449. { 0xFF, 0xEF }, /* 88 */
  450. { 0xFF, 0xFE }, /* 89 */
  451. { 0xFF, 0xFE }, /* 8A */
  452. { 0xFF, 0xFF }, /* 8B */
  453. { 0xFF, 0xFF }, /* 8C */
  454. { 0xFF, 0x3F }, /* 8D */
  455. { 0xFF, 0xFF }, /* 8E */
  456. { 0xFF, 0x3F }, /* 8F */
  457. { 0xFF, 0x8F }, /* 90 */
  458. { 0xFF, 0xFF }, /* 91 */
  459. { 0xFF, 0x3F }, /* 92 */
  460. { 0xFF, 0xFF }, /* 93 */
  461. { 0xFF, 0xFF }, /* 94 */
  462. { 0xFF, 0x0F }, /* 95 */
  463. { 0xFF, 0x3F }, /* 96 */
  464. { 0xFF, 0x8C }, /* 97 */
  465. { 0x00, 0x00 }, /* 98 */
  466. { 0x00, 0x00 }, /* 99 */
  467. { 0x00, 0x00 }, /* 9A */
  468. { 0x00, 0x00 }, /* 9B */
  469. { 0x00, 0x00 }, /* 9C */
  470. { 0x00, 0x00 }, /* 9D */
  471. { 0x00, 0x00 }, /* 9E */
  472. { 0x00, 0x00 }, /* 9F */
  473. { 0x00, 0x00 }, /* A0 */
  474. { 0x00, 0x00 }, /* A1 */
  475. { 0x00, 0x00 }, /* A2 */
  476. { 0x00, 0x00 }, /* A3 */
  477. { 0x00, 0x00 }, /* A4 */
  478. { 0x00, 0x00 }, /* A5 */
  479. { 0x00, 0x00 }, /* A6 */
  480. { 0x00, 0x00 }, /* A7 */
  481. { 0x00, 0x00 }, /* A8 */
  482. { 0x00, 0x00 }, /* A9 */
  483. { 0x00, 0x00 }, /* AA */
  484. { 0x00, 0x00 }, /* AB */
  485. { 0x00, 0x00 }, /* AC */
  486. { 0x00, 0x00 }, /* AD */
  487. { 0x00, 0x00 }, /* AE */
  488. { 0x00, 0x00 }, /* AF */
  489. { 0x00, 0x00 }, /* B0 */
  490. { 0x00, 0x00 }, /* B1 */
  491. { 0x00, 0x00 }, /* B2 */
  492. { 0x00, 0x00 }, /* B3 */
  493. { 0x00, 0x00 }, /* B4 */
  494. { 0x00, 0x00 }, /* B5 */
  495. { 0x00, 0x00 }, /* B6 */
  496. { 0x00, 0x00 }, /* B7 */
  497. { 0x00, 0x00 }, /* B8 */
  498. { 0x00, 0x00 }, /* B9 */
  499. { 0x00, 0x00 }, /* BA */
  500. { 0x00, 0x00 }, /* BB */
  501. { 0x00, 0x00 }, /* BC */
  502. { 0x00, 0x00 }, /* BD */
  503. { 0x00, 0x00 }, /* BE */
  504. { 0x00, 0x00 }, /* BF */
  505. { 0x00, 0x00 }, /* C0 */
  506. { 0x00, 0x00 }, /* C1 */
  507. { 0x00, 0x00 }, /* C2 */
  508. { 0x00, 0x00 }, /* C3 */
  509. { 0x00, 0x00 }, /* C4 */
  510. { 0x00, 0x00 }, /* C5 */
  511. { 0x00, 0x00 }, /* C6 */
  512. { 0x00, 0x00 }, /* C7 */
  513. { 0x00, 0x00 }, /* C8 */
  514. { 0x00, 0x00 }, /* C9 */
  515. { 0x00, 0x00 }, /* CA */
  516. { 0x00, 0x00 }, /* CB */
  517. { 0x00, 0x00 }, /* CC */
  518. { 0x00, 0x00 }, /* CD */
  519. { 0x00, 0x00 }, /* CE */
  520. { 0x00, 0x00 }, /* CF */
  521. { 0x00, 0x00 }, /* D0 */
  522. { 0x00, 0x00 }, /* D1 */
  523. { 0x00, 0x00 }, /* D2 */
  524. { 0x00, 0x00 }, /* D3 */
  525. { 0x00, 0x00 }, /* D4 */
  526. { 0x00, 0x00 }, /* D5 */
  527. { 0x00, 0x00 }, /* D6 */
  528. { 0x00, 0x00 }, /* D7 */
  529. { 0x00, 0x00 }, /* D8 */
  530. { 0x00, 0x00 }, /* D9 */
  531. { 0x00, 0x00 }, /* DA */
  532. { 0x00, 0x00 }, /* DB */
  533. { 0x00, 0x00 }, /* DC */
  534. { 0x00, 0x00 }, /* DD */
  535. { 0x00, 0x00 }, /* DE */
  536. { 0x00, 0x00 }, /* DF */
  537. { 0x00, 0x00 }, /* E0 */
  538. { 0x00, 0x00 }, /* E1 */
  539. { 0x00, 0x00 }, /* E2 */
  540. { 0x00, 0x00 }, /* E3 */
  541. { 0x00, 0x00 }, /* E4 */
  542. { 0x00, 0x00 }, /* E5 */
  543. { 0x00, 0x00 }, /* E6 */
  544. { 0x00, 0x00 }, /* E7 */
  545. { 0x00, 0x00 }, /* E8 */
  546. { 0x00, 0x00 }, /* E9 */
  547. { 0x00, 0x00 }, /* EA */
  548. { 0x00, 0x00 }, /* EB */
  549. { 0x00, 0x00 }, /* EC */
  550. { 0x00, 0x00 }, /* ED */
  551. { 0x00, 0x00 }, /* EE */
  552. { 0x00, 0x00 }, /* EF */
  553. { 0x00, 0x00 }, /* F0 */
  554. { 0x00, 0x00 }, /* F1 */
  555. { 0x00, 0x00 }, /* F2 */
  556. { 0x00, 0x00 }, /* F3 */
  557. { 0x00, 0x00 }, /* F4 */
  558. { 0x00, 0x00 }, /* F5 */
  559. { 0x00, 0x00 }, /* F6 */
  560. { 0x00, 0x00 }, /* F7 */
  561. { 0x00, 0x00 }, /* F8 */
  562. { 0x00, 0x00 }, /* F9 */
  563. { 0x00, 0x00 }, /* FA */
  564. { 0x00, 0x00 }, /* FB */
  565. { 0x00, 0x00 }, /* FC */
  566. { 0x00, 0x00 }, /* FD */
  567. { 0x00, 0x00 }, /* FE */
  568. { 0xFF, 0x00 }, /* FF */
  569. };
  570. static int max98095_readable(struct snd_soc_codec *codec, unsigned int reg)
  571. {
  572. if (reg >= M98095_REG_CNT)
  573. return 0;
  574. return max98095_access[reg].readable != 0;
  575. }
  576. static int max98095_volatile(struct snd_soc_codec *codec, unsigned int reg)
  577. {
  578. if (reg > M98095_REG_MAX_CACHED)
  579. return 1;
  580. switch (reg) {
  581. case M98095_000_HOST_DATA:
  582. case M98095_001_HOST_INT_STS:
  583. case M98095_002_HOST_RSP_STS:
  584. case M98095_003_HOST_CMD_STS:
  585. case M98095_004_CODEC_STS:
  586. case M98095_005_DAI1_ALC_STS:
  587. case M98095_006_DAI2_ALC_STS:
  588. case M98095_007_JACK_AUTO_STS:
  589. case M98095_008_JACK_MANUAL_STS:
  590. case M98095_009_JACK_VBAT_STS:
  591. case M98095_00A_ACC_ADC_STS:
  592. case M98095_00B_MIC_NG_AGC_STS:
  593. case M98095_00C_SPK_L_VOLT_STS:
  594. case M98095_00D_SPK_R_VOLT_STS:
  595. case M98095_00E_TEMP_SENSOR_STS:
  596. return 1;
  597. }
  598. return 0;
  599. }
  600. /*
  601. * Filter coefficients are in a separate register segment
  602. * and they share the address space of the normal registers.
  603. * The coefficient registers do not need or share the cache.
  604. */
  605. static int max98095_hw_write(struct snd_soc_codec *codec, unsigned int reg,
  606. unsigned int value)
  607. {
  608. int ret;
  609. codec->cache_bypass = 1;
  610. ret = snd_soc_write(codec, reg, value);
  611. codec->cache_bypass = 0;
  612. return ret ? -EIO : 0;
  613. }
  614. /*
  615. * Load equalizer DSP coefficient configurations registers
  616. */
  617. static void m98095_eq_band(struct snd_soc_codec *codec, unsigned int dai,
  618. unsigned int band, u16 *coefs)
  619. {
  620. unsigned int eq_reg;
  621. unsigned int i;
  622. BUG_ON(band > 4);
  623. BUG_ON(dai > 1);
  624. /* Load the base register address */
  625. eq_reg = dai ? M98095_142_DAI2_EQ_BASE : M98095_110_DAI1_EQ_BASE;
  626. /* Add the band address offset, note adjustment for word address */
  627. eq_reg += band * (M98095_COEFS_PER_BAND << 1);
  628. /* Step through the registers and coefs */
  629. for (i = 0; i < M98095_COEFS_PER_BAND; i++) {
  630. max98095_hw_write(codec, eq_reg++, M98095_BYTE1(coefs[i]));
  631. max98095_hw_write(codec, eq_reg++, M98095_BYTE0(coefs[i]));
  632. }
  633. }
  634. /*
  635. * Load biquad filter coefficient configurations registers
  636. */
  637. static void m98095_biquad_band(struct snd_soc_codec *codec, unsigned int dai,
  638. unsigned int band, u16 *coefs)
  639. {
  640. unsigned int bq_reg;
  641. unsigned int i;
  642. BUG_ON(band > 1);
  643. BUG_ON(dai > 1);
  644. /* Load the base register address */
  645. bq_reg = dai ? M98095_17E_DAI2_BQ_BASE : M98095_174_DAI1_BQ_BASE;
  646. /* Add the band address offset, note adjustment for word address */
  647. bq_reg += band * (M98095_COEFS_PER_BAND << 1);
  648. /* Step through the registers and coefs */
  649. for (i = 0; i < M98095_COEFS_PER_BAND; i++) {
  650. max98095_hw_write(codec, bq_reg++, M98095_BYTE1(coefs[i]));
  651. max98095_hw_write(codec, bq_reg++, M98095_BYTE0(coefs[i]));
  652. }
  653. }
  654. static const char * const max98095_fltr_mode[] = { "Voice", "Music" };
  655. static const struct soc_enum max98095_dai1_filter_mode_enum[] = {
  656. SOC_ENUM_SINGLE(M98095_02E_DAI1_FILTERS, 7, 2, max98095_fltr_mode),
  657. };
  658. static const struct soc_enum max98095_dai2_filter_mode_enum[] = {
  659. SOC_ENUM_SINGLE(M98095_038_DAI2_FILTERS, 7, 2, max98095_fltr_mode),
  660. };
  661. static const char * const max98095_extmic_text[] = { "None", "MIC1", "MIC2" };
  662. static const struct soc_enum max98095_extmic_enum =
  663. SOC_ENUM_SINGLE(M98095_087_CFG_MIC, 0, 3, max98095_extmic_text);
  664. static const struct snd_kcontrol_new max98095_extmic_mux =
  665. SOC_DAPM_ENUM("External MIC Mux", max98095_extmic_enum);
  666. static const char * const max98095_linein_text[] = { "INA", "INB" };
  667. static const struct soc_enum max98095_linein_enum =
  668. SOC_ENUM_SINGLE(M98095_086_CFG_LINE, 6, 2, max98095_linein_text);
  669. static const struct snd_kcontrol_new max98095_linein_mux =
  670. SOC_DAPM_ENUM("Linein Input Mux", max98095_linein_enum);
  671. static const char * const max98095_line_mode_text[] = {
  672. "Stereo", "Differential"};
  673. static const struct soc_enum max98095_linein_mode_enum =
  674. SOC_ENUM_SINGLE(M98095_086_CFG_LINE, 7, 2, max98095_line_mode_text);
  675. static const struct soc_enum max98095_lineout_mode_enum =
  676. SOC_ENUM_SINGLE(M98095_086_CFG_LINE, 4, 2, max98095_line_mode_text);
  677. static const char * const max98095_dai_fltr[] = {
  678. "Off", "Elliptical-HPF-16k", "Butterworth-HPF-16k",
  679. "Elliptical-HPF-8k", "Butterworth-HPF-8k", "Butterworth-HPF-Fs/240"};
  680. static const struct soc_enum max98095_dai1_dac_filter_enum[] = {
  681. SOC_ENUM_SINGLE(M98095_02E_DAI1_FILTERS, 0, 6, max98095_dai_fltr),
  682. };
  683. static const struct soc_enum max98095_dai2_dac_filter_enum[] = {
  684. SOC_ENUM_SINGLE(M98095_038_DAI2_FILTERS, 0, 6, max98095_dai_fltr),
  685. };
  686. static const struct soc_enum max98095_dai3_dac_filter_enum[] = {
  687. SOC_ENUM_SINGLE(M98095_042_DAI3_FILTERS, 0, 6, max98095_dai_fltr),
  688. };
  689. static int max98095_mic1pre_set(struct snd_kcontrol *kcontrol,
  690. struct snd_ctl_elem_value *ucontrol)
  691. {
  692. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  693. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  694. unsigned int sel = ucontrol->value.integer.value[0];
  695. max98095->mic1pre = sel;
  696. snd_soc_update_bits(codec, M98095_05F_LVL_MIC1, M98095_MICPRE_MASK,
  697. (1+sel)<<M98095_MICPRE_SHIFT);
  698. return 0;
  699. }
  700. static int max98095_mic1pre_get(struct snd_kcontrol *kcontrol,
  701. struct snd_ctl_elem_value *ucontrol)
  702. {
  703. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  704. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  705. ucontrol->value.integer.value[0] = max98095->mic1pre;
  706. return 0;
  707. }
  708. static int max98095_mic2pre_set(struct snd_kcontrol *kcontrol,
  709. struct snd_ctl_elem_value *ucontrol)
  710. {
  711. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  712. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  713. unsigned int sel = ucontrol->value.integer.value[0];
  714. max98095->mic2pre = sel;
  715. snd_soc_update_bits(codec, M98095_060_LVL_MIC2, M98095_MICPRE_MASK,
  716. (1+sel)<<M98095_MICPRE_SHIFT);
  717. return 0;
  718. }
  719. static int max98095_mic2pre_get(struct snd_kcontrol *kcontrol,
  720. struct snd_ctl_elem_value *ucontrol)
  721. {
  722. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  723. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  724. ucontrol->value.integer.value[0] = max98095->mic2pre;
  725. return 0;
  726. }
  727. static const unsigned int max98095_micboost_tlv[] = {
  728. TLV_DB_RANGE_HEAD(2),
  729. 0, 1, TLV_DB_SCALE_ITEM(0, 2000, 0),
  730. 2, 2, TLV_DB_SCALE_ITEM(3000, 0, 0),
  731. };
  732. static const DECLARE_TLV_DB_SCALE(max98095_mic_tlv, 0, 100, 0);
  733. static const DECLARE_TLV_DB_SCALE(max98095_adc_tlv, -1200, 100, 0);
  734. static const DECLARE_TLV_DB_SCALE(max98095_adcboost_tlv, 0, 600, 0);
  735. static const unsigned int max98095_hp_tlv[] = {
  736. TLV_DB_RANGE_HEAD(5),
  737. 0, 6, TLV_DB_SCALE_ITEM(-6700, 400, 0),
  738. 7, 14, TLV_DB_SCALE_ITEM(-4000, 300, 0),
  739. 15, 21, TLV_DB_SCALE_ITEM(-1700, 200, 0),
  740. 22, 27, TLV_DB_SCALE_ITEM(-400, 100, 0),
  741. 28, 31, TLV_DB_SCALE_ITEM(150, 50, 0),
  742. };
  743. static const unsigned int max98095_spk_tlv[] = {
  744. TLV_DB_RANGE_HEAD(4),
  745. 0, 10, TLV_DB_SCALE_ITEM(-5900, 400, 0),
  746. 11, 18, TLV_DB_SCALE_ITEM(-1700, 200, 0),
  747. 19, 27, TLV_DB_SCALE_ITEM(-200, 100, 0),
  748. 28, 39, TLV_DB_SCALE_ITEM(650, 50, 0),
  749. };
  750. static const unsigned int max98095_rcv_lout_tlv[] = {
  751. TLV_DB_RANGE_HEAD(5),
  752. 0, 6, TLV_DB_SCALE_ITEM(-6200, 400, 0),
  753. 7, 14, TLV_DB_SCALE_ITEM(-3500, 300, 0),
  754. 15, 21, TLV_DB_SCALE_ITEM(-1200, 200, 0),
  755. 22, 27, TLV_DB_SCALE_ITEM(100, 100, 0),
  756. 28, 31, TLV_DB_SCALE_ITEM(650, 50, 0),
  757. };
  758. static const unsigned int max98095_lin_tlv[] = {
  759. TLV_DB_RANGE_HEAD(3),
  760. 0, 2, TLV_DB_SCALE_ITEM(-600, 300, 0),
  761. 3, 3, TLV_DB_SCALE_ITEM(300, 1100, 0),
  762. 4, 5, TLV_DB_SCALE_ITEM(1400, 600, 0),
  763. };
  764. static const struct snd_kcontrol_new max98095_snd_controls[] = {
  765. SOC_DOUBLE_R_TLV("Headphone Volume", M98095_064_LVL_HP_L,
  766. M98095_065_LVL_HP_R, 0, 31, 0, max98095_hp_tlv),
  767. SOC_DOUBLE_R_TLV("Speaker Volume", M98095_067_LVL_SPK_L,
  768. M98095_068_LVL_SPK_R, 0, 39, 0, max98095_spk_tlv),
  769. SOC_SINGLE_TLV("Receiver Volume", M98095_066_LVL_RCV,
  770. 0, 31, 0, max98095_rcv_lout_tlv),
  771. SOC_DOUBLE_R_TLV("Lineout Volume", M98095_062_LVL_LINEOUT1,
  772. M98095_063_LVL_LINEOUT2, 0, 31, 0, max98095_rcv_lout_tlv),
  773. SOC_DOUBLE_R("Headphone Switch", M98095_064_LVL_HP_L,
  774. M98095_065_LVL_HP_R, 7, 1, 1),
  775. SOC_DOUBLE_R("Speaker Switch", M98095_067_LVL_SPK_L,
  776. M98095_068_LVL_SPK_R, 7, 1, 1),
  777. SOC_SINGLE("Receiver Switch", M98095_066_LVL_RCV, 7, 1, 1),
  778. SOC_DOUBLE_R("Lineout Switch", M98095_062_LVL_LINEOUT1,
  779. M98095_063_LVL_LINEOUT2, 7, 1, 1),
  780. SOC_SINGLE_TLV("MIC1 Volume", M98095_05F_LVL_MIC1, 0, 20, 1,
  781. max98095_mic_tlv),
  782. SOC_SINGLE_TLV("MIC2 Volume", M98095_060_LVL_MIC2, 0, 20, 1,
  783. max98095_mic_tlv),
  784. SOC_SINGLE_EXT_TLV("MIC1 Boost Volume",
  785. M98095_05F_LVL_MIC1, 5, 2, 0,
  786. max98095_mic1pre_get, max98095_mic1pre_set,
  787. max98095_micboost_tlv),
  788. SOC_SINGLE_EXT_TLV("MIC2 Boost Volume",
  789. M98095_060_LVL_MIC2, 5, 2, 0,
  790. max98095_mic2pre_get, max98095_mic2pre_set,
  791. max98095_micboost_tlv),
  792. SOC_SINGLE_TLV("Linein Volume", M98095_061_LVL_LINEIN, 0, 5, 1,
  793. max98095_lin_tlv),
  794. SOC_SINGLE_TLV("ADCL Volume", M98095_05D_LVL_ADC_L, 0, 15, 1,
  795. max98095_adc_tlv),
  796. SOC_SINGLE_TLV("ADCR Volume", M98095_05E_LVL_ADC_R, 0, 15, 1,
  797. max98095_adc_tlv),
  798. SOC_SINGLE_TLV("ADCL Boost Volume", M98095_05D_LVL_ADC_L, 4, 3, 0,
  799. max98095_adcboost_tlv),
  800. SOC_SINGLE_TLV("ADCR Boost Volume", M98095_05E_LVL_ADC_R, 4, 3, 0,
  801. max98095_adcboost_tlv),
  802. SOC_SINGLE("EQ1 Switch", M98095_088_CFG_LEVEL, 0, 1, 0),
  803. SOC_SINGLE("EQ2 Switch", M98095_088_CFG_LEVEL, 1, 1, 0),
  804. SOC_SINGLE("Biquad1 Switch", M98095_088_CFG_LEVEL, 2, 1, 0),
  805. SOC_SINGLE("Biquad2 Switch", M98095_088_CFG_LEVEL, 3, 1, 0),
  806. SOC_ENUM("DAI1 Filter Mode", max98095_dai1_filter_mode_enum),
  807. SOC_ENUM("DAI2 Filter Mode", max98095_dai2_filter_mode_enum),
  808. SOC_ENUM("DAI1 DAC Filter", max98095_dai1_dac_filter_enum),
  809. SOC_ENUM("DAI2 DAC Filter", max98095_dai2_dac_filter_enum),
  810. SOC_ENUM("DAI3 DAC Filter", max98095_dai3_dac_filter_enum),
  811. SOC_ENUM("Linein Mode", max98095_linein_mode_enum),
  812. SOC_ENUM("Lineout Mode", max98095_lineout_mode_enum),
  813. };
  814. /* Left speaker mixer switch */
  815. static const struct snd_kcontrol_new max98095_left_speaker_mixer_controls[] = {
  816. SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_050_MIX_SPK_LEFT, 0, 1, 0),
  817. SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_050_MIX_SPK_LEFT, 6, 1, 0),
  818. SOC_DAPM_SINGLE("Mono DAC2 Switch", M98095_050_MIX_SPK_LEFT, 3, 1, 0),
  819. SOC_DAPM_SINGLE("Mono DAC3 Switch", M98095_050_MIX_SPK_LEFT, 3, 1, 0),
  820. SOC_DAPM_SINGLE("MIC1 Switch", M98095_050_MIX_SPK_LEFT, 4, 1, 0),
  821. SOC_DAPM_SINGLE("MIC2 Switch", M98095_050_MIX_SPK_LEFT, 5, 1, 0),
  822. SOC_DAPM_SINGLE("IN1 Switch", M98095_050_MIX_SPK_LEFT, 1, 1, 0),
  823. SOC_DAPM_SINGLE("IN2 Switch", M98095_050_MIX_SPK_LEFT, 2, 1, 0),
  824. };
  825. /* Right speaker mixer switch */
  826. static const struct snd_kcontrol_new max98095_right_speaker_mixer_controls[] = {
  827. SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_051_MIX_SPK_RIGHT, 6, 1, 0),
  828. SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_051_MIX_SPK_RIGHT, 0, 1, 0),
  829. SOC_DAPM_SINGLE("Mono DAC2 Switch", M98095_051_MIX_SPK_RIGHT, 3, 1, 0),
  830. SOC_DAPM_SINGLE("Mono DAC3 Switch", M98095_051_MIX_SPK_RIGHT, 3, 1, 0),
  831. SOC_DAPM_SINGLE("MIC1 Switch", M98095_051_MIX_SPK_RIGHT, 5, 1, 0),
  832. SOC_DAPM_SINGLE("MIC2 Switch", M98095_051_MIX_SPK_RIGHT, 4, 1, 0),
  833. SOC_DAPM_SINGLE("IN1 Switch", M98095_051_MIX_SPK_RIGHT, 1, 1, 0),
  834. SOC_DAPM_SINGLE("IN2 Switch", M98095_051_MIX_SPK_RIGHT, 2, 1, 0),
  835. };
  836. /* Left headphone mixer switch */
  837. static const struct snd_kcontrol_new max98095_left_hp_mixer_controls[] = {
  838. SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_04C_MIX_HP_LEFT, 0, 1, 0),
  839. SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_04C_MIX_HP_LEFT, 5, 1, 0),
  840. SOC_DAPM_SINGLE("MIC1 Switch", M98095_04C_MIX_HP_LEFT, 3, 1, 0),
  841. SOC_DAPM_SINGLE("MIC2 Switch", M98095_04C_MIX_HP_LEFT, 4, 1, 0),
  842. SOC_DAPM_SINGLE("IN1 Switch", M98095_04C_MIX_HP_LEFT, 1, 1, 0),
  843. SOC_DAPM_SINGLE("IN2 Switch", M98095_04C_MIX_HP_LEFT, 2, 1, 0),
  844. };
  845. /* Right headphone mixer switch */
  846. static const struct snd_kcontrol_new max98095_right_hp_mixer_controls[] = {
  847. SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_04D_MIX_HP_RIGHT, 5, 1, 0),
  848. SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_04D_MIX_HP_RIGHT, 0, 1, 0),
  849. SOC_DAPM_SINGLE("MIC1 Switch", M98095_04D_MIX_HP_RIGHT, 3, 1, 0),
  850. SOC_DAPM_SINGLE("MIC2 Switch", M98095_04D_MIX_HP_RIGHT, 4, 1, 0),
  851. SOC_DAPM_SINGLE("IN1 Switch", M98095_04D_MIX_HP_RIGHT, 1, 1, 0),
  852. SOC_DAPM_SINGLE("IN2 Switch", M98095_04D_MIX_HP_RIGHT, 2, 1, 0),
  853. };
  854. /* Receiver earpiece mixer switch */
  855. static const struct snd_kcontrol_new max98095_mono_rcv_mixer_controls[] = {
  856. SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_04F_MIX_RCV, 0, 1, 0),
  857. SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_04F_MIX_RCV, 5, 1, 0),
  858. SOC_DAPM_SINGLE("MIC1 Switch", M98095_04F_MIX_RCV, 3, 1, 0),
  859. SOC_DAPM_SINGLE("MIC2 Switch", M98095_04F_MIX_RCV, 4, 1, 0),
  860. SOC_DAPM_SINGLE("IN1 Switch", M98095_04F_MIX_RCV, 1, 1, 0),
  861. SOC_DAPM_SINGLE("IN2 Switch", M98095_04F_MIX_RCV, 2, 1, 0),
  862. };
  863. /* Left lineout mixer switch */
  864. static const struct snd_kcontrol_new max98095_left_lineout_mixer_controls[] = {
  865. SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_053_MIX_LINEOUT1, 5, 1, 0),
  866. SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_053_MIX_LINEOUT1, 0, 1, 0),
  867. SOC_DAPM_SINGLE("MIC1 Switch", M98095_053_MIX_LINEOUT1, 3, 1, 0),
  868. SOC_DAPM_SINGLE("MIC2 Switch", M98095_053_MIX_LINEOUT1, 4, 1, 0),
  869. SOC_DAPM_SINGLE("IN1 Switch", M98095_053_MIX_LINEOUT1, 1, 1, 0),
  870. SOC_DAPM_SINGLE("IN2 Switch", M98095_053_MIX_LINEOUT1, 2, 1, 0),
  871. };
  872. /* Right lineout mixer switch */
  873. static const struct snd_kcontrol_new max98095_right_lineout_mixer_controls[] = {
  874. SOC_DAPM_SINGLE("Left DAC1 Switch", M98095_054_MIX_LINEOUT2, 0, 1, 0),
  875. SOC_DAPM_SINGLE("Right DAC1 Switch", M98095_054_MIX_LINEOUT2, 5, 1, 0),
  876. SOC_DAPM_SINGLE("MIC1 Switch", M98095_054_MIX_LINEOUT2, 3, 1, 0),
  877. SOC_DAPM_SINGLE("MIC2 Switch", M98095_054_MIX_LINEOUT2, 4, 1, 0),
  878. SOC_DAPM_SINGLE("IN1 Switch", M98095_054_MIX_LINEOUT2, 1, 1, 0),
  879. SOC_DAPM_SINGLE("IN2 Switch", M98095_054_MIX_LINEOUT2, 2, 1, 0),
  880. };
  881. /* Left ADC mixer switch */
  882. static const struct snd_kcontrol_new max98095_left_ADC_mixer_controls[] = {
  883. SOC_DAPM_SINGLE("MIC1 Switch", M98095_04A_MIX_ADC_LEFT, 7, 1, 0),
  884. SOC_DAPM_SINGLE("MIC2 Switch", M98095_04A_MIX_ADC_LEFT, 6, 1, 0),
  885. SOC_DAPM_SINGLE("IN1 Switch", M98095_04A_MIX_ADC_LEFT, 3, 1, 0),
  886. SOC_DAPM_SINGLE("IN2 Switch", M98095_04A_MIX_ADC_LEFT, 2, 1, 0),
  887. };
  888. /* Right ADC mixer switch */
  889. static const struct snd_kcontrol_new max98095_right_ADC_mixer_controls[] = {
  890. SOC_DAPM_SINGLE("MIC1 Switch", M98095_04B_MIX_ADC_RIGHT, 7, 1, 0),
  891. SOC_DAPM_SINGLE("MIC2 Switch", M98095_04B_MIX_ADC_RIGHT, 6, 1, 0),
  892. SOC_DAPM_SINGLE("IN1 Switch", M98095_04B_MIX_ADC_RIGHT, 3, 1, 0),
  893. SOC_DAPM_SINGLE("IN2 Switch", M98095_04B_MIX_ADC_RIGHT, 2, 1, 0),
  894. };
  895. static int max98095_mic_event(struct snd_soc_dapm_widget *w,
  896. struct snd_kcontrol *kcontrol, int event)
  897. {
  898. struct snd_soc_codec *codec = w->codec;
  899. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  900. switch (event) {
  901. case SND_SOC_DAPM_POST_PMU:
  902. if (w->reg == M98095_05F_LVL_MIC1) {
  903. snd_soc_update_bits(codec, w->reg, M98095_MICPRE_MASK,
  904. (1+max98095->mic1pre)<<M98095_MICPRE_SHIFT);
  905. } else {
  906. snd_soc_update_bits(codec, w->reg, M98095_MICPRE_MASK,
  907. (1+max98095->mic2pre)<<M98095_MICPRE_SHIFT);
  908. }
  909. break;
  910. case SND_SOC_DAPM_POST_PMD:
  911. snd_soc_update_bits(codec, w->reg, M98095_MICPRE_MASK, 0);
  912. break;
  913. default:
  914. return -EINVAL;
  915. }
  916. return 0;
  917. }
  918. /*
  919. * The line inputs are stereo inputs with the left and right
  920. * channels sharing a common PGA power control signal.
  921. */
  922. static int max98095_line_pga(struct snd_soc_dapm_widget *w,
  923. int event, u8 channel)
  924. {
  925. struct snd_soc_codec *codec = w->codec;
  926. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  927. u8 *state;
  928. BUG_ON(!((channel == 1) || (channel == 2)));
  929. state = &max98095->lin_state;
  930. switch (event) {
  931. case SND_SOC_DAPM_POST_PMU:
  932. *state |= channel;
  933. snd_soc_update_bits(codec, w->reg,
  934. (1 << w->shift), (1 << w->shift));
  935. break;
  936. case SND_SOC_DAPM_POST_PMD:
  937. *state &= ~channel;
  938. if (*state == 0) {
  939. snd_soc_update_bits(codec, w->reg,
  940. (1 << w->shift), 0);
  941. }
  942. break;
  943. default:
  944. return -EINVAL;
  945. }
  946. return 0;
  947. }
  948. static int max98095_pga_in1_event(struct snd_soc_dapm_widget *w,
  949. struct snd_kcontrol *k, int event)
  950. {
  951. return max98095_line_pga(w, event, 1);
  952. }
  953. static int max98095_pga_in2_event(struct snd_soc_dapm_widget *w,
  954. struct snd_kcontrol *k, int event)
  955. {
  956. return max98095_line_pga(w, event, 2);
  957. }
  958. /*
  959. * The stereo line out mixer outputs to two stereo line outs.
  960. * The 2nd pair has a separate set of enables.
  961. */
  962. static int max98095_lineout_event(struct snd_soc_dapm_widget *w,
  963. struct snd_kcontrol *kcontrol, int event)
  964. {
  965. struct snd_soc_codec *codec = w->codec;
  966. switch (event) {
  967. case SND_SOC_DAPM_POST_PMU:
  968. snd_soc_update_bits(codec, w->reg,
  969. (1 << (w->shift+2)), (1 << (w->shift+2)));
  970. break;
  971. case SND_SOC_DAPM_POST_PMD:
  972. snd_soc_update_bits(codec, w->reg,
  973. (1 << (w->shift+2)), 0);
  974. break;
  975. default:
  976. return -EINVAL;
  977. }
  978. return 0;
  979. }
  980. static const struct snd_soc_dapm_widget max98095_dapm_widgets[] = {
  981. SND_SOC_DAPM_ADC("ADCL", "HiFi Capture", M98095_090_PWR_EN_IN, 0, 0),
  982. SND_SOC_DAPM_ADC("ADCR", "HiFi Capture", M98095_090_PWR_EN_IN, 1, 0),
  983. SND_SOC_DAPM_DAC("DACL1", "HiFi Playback",
  984. M98095_091_PWR_EN_OUT, 0, 0),
  985. SND_SOC_DAPM_DAC("DACR1", "HiFi Playback",
  986. M98095_091_PWR_EN_OUT, 1, 0),
  987. SND_SOC_DAPM_DAC("DACM2", "Aux Playback",
  988. M98095_091_PWR_EN_OUT, 2, 0),
  989. SND_SOC_DAPM_DAC("DACM3", "Voice Playback",
  990. M98095_091_PWR_EN_OUT, 2, 0),
  991. SND_SOC_DAPM_PGA("HP Left Out", M98095_091_PWR_EN_OUT,
  992. 6, 0, NULL, 0),
  993. SND_SOC_DAPM_PGA("HP Right Out", M98095_091_PWR_EN_OUT,
  994. 7, 0, NULL, 0),
  995. SND_SOC_DAPM_PGA("SPK Left Out", M98095_091_PWR_EN_OUT,
  996. 4, 0, NULL, 0),
  997. SND_SOC_DAPM_PGA("SPK Right Out", M98095_091_PWR_EN_OUT,
  998. 5, 0, NULL, 0),
  999. SND_SOC_DAPM_PGA("RCV Mono Out", M98095_091_PWR_EN_OUT,
  1000. 3, 0, NULL, 0),
  1001. SND_SOC_DAPM_PGA_E("LINE Left Out", M98095_092_PWR_EN_OUT,
  1002. 0, 0, NULL, 0, max98095_lineout_event, SND_SOC_DAPM_PRE_PMD),
  1003. SND_SOC_DAPM_PGA_E("LINE Right Out", M98095_092_PWR_EN_OUT,
  1004. 1, 0, NULL, 0, max98095_lineout_event, SND_SOC_DAPM_PRE_PMD),
  1005. SND_SOC_DAPM_MUX("External MIC", SND_SOC_NOPM, 0, 0,
  1006. &max98095_extmic_mux),
  1007. SND_SOC_DAPM_MUX("Linein Mux", SND_SOC_NOPM, 0, 0,
  1008. &max98095_linein_mux),
  1009. SND_SOC_DAPM_MIXER("Left Headphone Mixer", SND_SOC_NOPM, 0, 0,
  1010. &max98095_left_hp_mixer_controls[0],
  1011. ARRAY_SIZE(max98095_left_hp_mixer_controls)),
  1012. SND_SOC_DAPM_MIXER("Right Headphone Mixer", SND_SOC_NOPM, 0, 0,
  1013. &max98095_right_hp_mixer_controls[0],
  1014. ARRAY_SIZE(max98095_right_hp_mixer_controls)),
  1015. SND_SOC_DAPM_MIXER("Left Speaker Mixer", SND_SOC_NOPM, 0, 0,
  1016. &max98095_left_speaker_mixer_controls[0],
  1017. ARRAY_SIZE(max98095_left_speaker_mixer_controls)),
  1018. SND_SOC_DAPM_MIXER("Right Speaker Mixer", SND_SOC_NOPM, 0, 0,
  1019. &max98095_right_speaker_mixer_controls[0],
  1020. ARRAY_SIZE(max98095_right_speaker_mixer_controls)),
  1021. SND_SOC_DAPM_MIXER("Receiver Mixer", SND_SOC_NOPM, 0, 0,
  1022. &max98095_mono_rcv_mixer_controls[0],
  1023. ARRAY_SIZE(max98095_mono_rcv_mixer_controls)),
  1024. SND_SOC_DAPM_MIXER("Left Lineout Mixer", SND_SOC_NOPM, 0, 0,
  1025. &max98095_left_lineout_mixer_controls[0],
  1026. ARRAY_SIZE(max98095_left_lineout_mixer_controls)),
  1027. SND_SOC_DAPM_MIXER("Right Lineout Mixer", SND_SOC_NOPM, 0, 0,
  1028. &max98095_right_lineout_mixer_controls[0],
  1029. ARRAY_SIZE(max98095_right_lineout_mixer_controls)),
  1030. SND_SOC_DAPM_MIXER("Left ADC Mixer", SND_SOC_NOPM, 0, 0,
  1031. &max98095_left_ADC_mixer_controls[0],
  1032. ARRAY_SIZE(max98095_left_ADC_mixer_controls)),
  1033. SND_SOC_DAPM_MIXER("Right ADC Mixer", SND_SOC_NOPM, 0, 0,
  1034. &max98095_right_ADC_mixer_controls[0],
  1035. ARRAY_SIZE(max98095_right_ADC_mixer_controls)),
  1036. SND_SOC_DAPM_PGA_E("MIC1 Input", M98095_05F_LVL_MIC1,
  1037. 5, 0, NULL, 0, max98095_mic_event,
  1038. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  1039. SND_SOC_DAPM_PGA_E("MIC2 Input", M98095_060_LVL_MIC2,
  1040. 5, 0, NULL, 0, max98095_mic_event,
  1041. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  1042. SND_SOC_DAPM_PGA_E("IN1 Input", M98095_090_PWR_EN_IN,
  1043. 7, 0, NULL, 0, max98095_pga_in1_event,
  1044. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  1045. SND_SOC_DAPM_PGA_E("IN2 Input", M98095_090_PWR_EN_IN,
  1046. 7, 0, NULL, 0, max98095_pga_in2_event,
  1047. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  1048. SND_SOC_DAPM_MICBIAS("MICBIAS1", M98095_090_PWR_EN_IN, 2, 0),
  1049. SND_SOC_DAPM_MICBIAS("MICBIAS2", M98095_090_PWR_EN_IN, 3, 0),
  1050. SND_SOC_DAPM_OUTPUT("HPL"),
  1051. SND_SOC_DAPM_OUTPUT("HPR"),
  1052. SND_SOC_DAPM_OUTPUT("SPKL"),
  1053. SND_SOC_DAPM_OUTPUT("SPKR"),
  1054. SND_SOC_DAPM_OUTPUT("RCV"),
  1055. SND_SOC_DAPM_OUTPUT("OUT1"),
  1056. SND_SOC_DAPM_OUTPUT("OUT2"),
  1057. SND_SOC_DAPM_OUTPUT("OUT3"),
  1058. SND_SOC_DAPM_OUTPUT("OUT4"),
  1059. SND_SOC_DAPM_INPUT("MIC1"),
  1060. SND_SOC_DAPM_INPUT("MIC2"),
  1061. SND_SOC_DAPM_INPUT("INA1"),
  1062. SND_SOC_DAPM_INPUT("INA2"),
  1063. SND_SOC_DAPM_INPUT("INB1"),
  1064. SND_SOC_DAPM_INPUT("INB2"),
  1065. };
  1066. static const struct snd_soc_dapm_route max98095_audio_map[] = {
  1067. /* Left headphone output mixer */
  1068. {"Left Headphone Mixer", "Left DAC1 Switch", "DACL1"},
  1069. {"Left Headphone Mixer", "Right DAC1 Switch", "DACR1"},
  1070. {"Left Headphone Mixer", "MIC1 Switch", "MIC1 Input"},
  1071. {"Left Headphone Mixer", "MIC2 Switch", "MIC2 Input"},
  1072. {"Left Headphone Mixer", "IN1 Switch", "IN1 Input"},
  1073. {"Left Headphone Mixer", "IN2 Switch", "IN2 Input"},
  1074. /* Right headphone output mixer */
  1075. {"Right Headphone Mixer", "Left DAC1 Switch", "DACL1"},
  1076. {"Right Headphone Mixer", "Right DAC1 Switch", "DACR1"},
  1077. {"Right Headphone Mixer", "MIC1 Switch", "MIC1 Input"},
  1078. {"Right Headphone Mixer", "MIC2 Switch", "MIC2 Input"},
  1079. {"Right Headphone Mixer", "IN1 Switch", "IN1 Input"},
  1080. {"Right Headphone Mixer", "IN2 Switch", "IN2 Input"},
  1081. /* Left speaker output mixer */
  1082. {"Left Speaker Mixer", "Left DAC1 Switch", "DACL1"},
  1083. {"Left Speaker Mixer", "Right DAC1 Switch", "DACR1"},
  1084. {"Left Speaker Mixer", "Mono DAC2 Switch", "DACM2"},
  1085. {"Left Speaker Mixer", "Mono DAC3 Switch", "DACM3"},
  1086. {"Left Speaker Mixer", "MIC1 Switch", "MIC1 Input"},
  1087. {"Left Speaker Mixer", "MIC2 Switch", "MIC2 Input"},
  1088. {"Left Speaker Mixer", "IN1 Switch", "IN1 Input"},
  1089. {"Left Speaker Mixer", "IN2 Switch", "IN2 Input"},
  1090. /* Right speaker output mixer */
  1091. {"Right Speaker Mixer", "Left DAC1 Switch", "DACL1"},
  1092. {"Right Speaker Mixer", "Right DAC1 Switch", "DACR1"},
  1093. {"Right Speaker Mixer", "Mono DAC2 Switch", "DACM2"},
  1094. {"Right Speaker Mixer", "Mono DAC3 Switch", "DACM3"},
  1095. {"Right Speaker Mixer", "MIC1 Switch", "MIC1 Input"},
  1096. {"Right Speaker Mixer", "MIC2 Switch", "MIC2 Input"},
  1097. {"Right Speaker Mixer", "IN1 Switch", "IN1 Input"},
  1098. {"Right Speaker Mixer", "IN2 Switch", "IN2 Input"},
  1099. /* Earpiece/Receiver output mixer */
  1100. {"Receiver Mixer", "Left DAC1 Switch", "DACL1"},
  1101. {"Receiver Mixer", "Right DAC1 Switch", "DACR1"},
  1102. {"Receiver Mixer", "MIC1 Switch", "MIC1 Input"},
  1103. {"Receiver Mixer", "MIC2 Switch", "MIC2 Input"},
  1104. {"Receiver Mixer", "IN1 Switch", "IN1 Input"},
  1105. {"Receiver Mixer", "IN2 Switch", "IN2 Input"},
  1106. /* Left Lineout output mixer */
  1107. {"Left Lineout Mixer", "Left DAC1 Switch", "DACL1"},
  1108. {"Left Lineout Mixer", "Right DAC1 Switch", "DACR1"},
  1109. {"Left Lineout Mixer", "MIC1 Switch", "MIC1 Input"},
  1110. {"Left Lineout Mixer", "MIC2 Switch", "MIC2 Input"},
  1111. {"Left Lineout Mixer", "IN1 Switch", "IN1 Input"},
  1112. {"Left Lineout Mixer", "IN2 Switch", "IN2 Input"},
  1113. /* Right lineout output mixer */
  1114. {"Right Lineout Mixer", "Left DAC1 Switch", "DACL1"},
  1115. {"Right Lineout Mixer", "Right DAC1 Switch", "DACR1"},
  1116. {"Right Lineout Mixer", "MIC1 Switch", "MIC1 Input"},
  1117. {"Right Lineout Mixer", "MIC2 Switch", "MIC2 Input"},
  1118. {"Right Lineout Mixer", "IN1 Switch", "IN1 Input"},
  1119. {"Right Lineout Mixer", "IN2 Switch", "IN2 Input"},
  1120. {"HP Left Out", NULL, "Left Headphone Mixer"},
  1121. {"HP Right Out", NULL, "Right Headphone Mixer"},
  1122. {"SPK Left Out", NULL, "Left Speaker Mixer"},
  1123. {"SPK Right Out", NULL, "Right Speaker Mixer"},
  1124. {"RCV Mono Out", NULL, "Receiver Mixer"},
  1125. {"LINE Left Out", NULL, "Left Lineout Mixer"},
  1126. {"LINE Right Out", NULL, "Right Lineout Mixer"},
  1127. {"HPL", NULL, "HP Left Out"},
  1128. {"HPR", NULL, "HP Right Out"},
  1129. {"SPKL", NULL, "SPK Left Out"},
  1130. {"SPKR", NULL, "SPK Right Out"},
  1131. {"RCV", NULL, "RCV Mono Out"},
  1132. {"OUT1", NULL, "LINE Left Out"},
  1133. {"OUT2", NULL, "LINE Right Out"},
  1134. {"OUT3", NULL, "LINE Left Out"},
  1135. {"OUT4", NULL, "LINE Right Out"},
  1136. /* Left ADC input mixer */
  1137. {"Left ADC Mixer", "MIC1 Switch", "MIC1 Input"},
  1138. {"Left ADC Mixer", "MIC2 Switch", "MIC2 Input"},
  1139. {"Left ADC Mixer", "IN1 Switch", "IN1 Input"},
  1140. {"Left ADC Mixer", "IN2 Switch", "IN2 Input"},
  1141. /* Right ADC input mixer */
  1142. {"Right ADC Mixer", "MIC1 Switch", "MIC1 Input"},
  1143. {"Right ADC Mixer", "MIC2 Switch", "MIC2 Input"},
  1144. {"Right ADC Mixer", "IN1 Switch", "IN1 Input"},
  1145. {"Right ADC Mixer", "IN2 Switch", "IN2 Input"},
  1146. /* Inputs */
  1147. {"ADCL", NULL, "Left ADC Mixer"},
  1148. {"ADCR", NULL, "Right ADC Mixer"},
  1149. {"IN1 Input", NULL, "INA1"},
  1150. {"IN2 Input", NULL, "INA2"},
  1151. {"MIC1 Input", NULL, "MIC1"},
  1152. {"MIC2 Input", NULL, "MIC2"},
  1153. };
  1154. static int max98095_add_widgets(struct snd_soc_codec *codec)
  1155. {
  1156. snd_soc_add_codec_controls(codec, max98095_snd_controls,
  1157. ARRAY_SIZE(max98095_snd_controls));
  1158. return 0;
  1159. }
  1160. /* codec mclk clock divider coefficients */
  1161. static const struct {
  1162. u32 rate;
  1163. u8 sr;
  1164. } rate_table[] = {
  1165. {8000, 0x01},
  1166. {11025, 0x02},
  1167. {16000, 0x03},
  1168. {22050, 0x04},
  1169. {24000, 0x05},
  1170. {32000, 0x06},
  1171. {44100, 0x07},
  1172. {48000, 0x08},
  1173. {88200, 0x09},
  1174. {96000, 0x0A},
  1175. };
  1176. static int rate_value(int rate, u8 *value)
  1177. {
  1178. int i;
  1179. for (i = 0; i < ARRAY_SIZE(rate_table); i++) {
  1180. if (rate_table[i].rate >= rate) {
  1181. *value = rate_table[i].sr;
  1182. return 0;
  1183. }
  1184. }
  1185. *value = rate_table[0].sr;
  1186. return -EINVAL;
  1187. }
  1188. static int max98095_dai1_hw_params(struct snd_pcm_substream *substream,
  1189. struct snd_pcm_hw_params *params,
  1190. struct snd_soc_dai *dai)
  1191. {
  1192. struct snd_soc_codec *codec = dai->codec;
  1193. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  1194. struct max98095_cdata *cdata;
  1195. unsigned long long ni;
  1196. unsigned int rate;
  1197. u8 regval;
  1198. cdata = &max98095->dai[0];
  1199. rate = params_rate(params);
  1200. switch (params_format(params)) {
  1201. case SNDRV_PCM_FORMAT_S16_LE:
  1202. snd_soc_update_bits(codec, M98095_02A_DAI1_FORMAT,
  1203. M98095_DAI_WS, 0);
  1204. break;
  1205. case SNDRV_PCM_FORMAT_S24_LE:
  1206. snd_soc_update_bits(codec, M98095_02A_DAI1_FORMAT,
  1207. M98095_DAI_WS, M98095_DAI_WS);
  1208. break;
  1209. default:
  1210. return -EINVAL;
  1211. }
  1212. if (rate_value(rate, &regval))
  1213. return -EINVAL;
  1214. snd_soc_update_bits(codec, M98095_027_DAI1_CLKMODE,
  1215. M98095_CLKMODE_MASK, regval);
  1216. cdata->rate = rate;
  1217. /* Configure NI when operating as master */
  1218. if (snd_soc_read(codec, M98095_02A_DAI1_FORMAT) & M98095_DAI_MAS) {
  1219. if (max98095->sysclk == 0) {
  1220. dev_err(codec->dev, "Invalid system clock frequency\n");
  1221. return -EINVAL;
  1222. }
  1223. ni = 65536ULL * (rate < 50000 ? 96ULL : 48ULL)
  1224. * (unsigned long long int)rate;
  1225. do_div(ni, (unsigned long long int)max98095->sysclk);
  1226. snd_soc_write(codec, M98095_028_DAI1_CLKCFG_HI,
  1227. (ni >> 8) & 0x7F);
  1228. snd_soc_write(codec, M98095_029_DAI1_CLKCFG_LO,
  1229. ni & 0xFF);
  1230. }
  1231. /* Update sample rate mode */
  1232. if (rate < 50000)
  1233. snd_soc_update_bits(codec, M98095_02E_DAI1_FILTERS,
  1234. M98095_DAI_DHF, 0);
  1235. else
  1236. snd_soc_update_bits(codec, M98095_02E_DAI1_FILTERS,
  1237. M98095_DAI_DHF, M98095_DAI_DHF);
  1238. return 0;
  1239. }
  1240. static int max98095_dai2_hw_params(struct snd_pcm_substream *substream,
  1241. struct snd_pcm_hw_params *params,
  1242. struct snd_soc_dai *dai)
  1243. {
  1244. struct snd_soc_codec *codec = dai->codec;
  1245. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  1246. struct max98095_cdata *cdata;
  1247. unsigned long long ni;
  1248. unsigned int rate;
  1249. u8 regval;
  1250. cdata = &max98095->dai[1];
  1251. rate = params_rate(params);
  1252. switch (params_format(params)) {
  1253. case SNDRV_PCM_FORMAT_S16_LE:
  1254. snd_soc_update_bits(codec, M98095_034_DAI2_FORMAT,
  1255. M98095_DAI_WS, 0);
  1256. break;
  1257. case SNDRV_PCM_FORMAT_S24_LE:
  1258. snd_soc_update_bits(codec, M98095_034_DAI2_FORMAT,
  1259. M98095_DAI_WS, M98095_DAI_WS);
  1260. break;
  1261. default:
  1262. return -EINVAL;
  1263. }
  1264. if (rate_value(rate, &regval))
  1265. return -EINVAL;
  1266. snd_soc_update_bits(codec, M98095_031_DAI2_CLKMODE,
  1267. M98095_CLKMODE_MASK, regval);
  1268. cdata->rate = rate;
  1269. /* Configure NI when operating as master */
  1270. if (snd_soc_read(codec, M98095_034_DAI2_FORMAT) & M98095_DAI_MAS) {
  1271. if (max98095->sysclk == 0) {
  1272. dev_err(codec->dev, "Invalid system clock frequency\n");
  1273. return -EINVAL;
  1274. }
  1275. ni = 65536ULL * (rate < 50000 ? 96ULL : 48ULL)
  1276. * (unsigned long long int)rate;
  1277. do_div(ni, (unsigned long long int)max98095->sysclk);
  1278. snd_soc_write(codec, M98095_032_DAI2_CLKCFG_HI,
  1279. (ni >> 8) & 0x7F);
  1280. snd_soc_write(codec, M98095_033_DAI2_CLKCFG_LO,
  1281. ni & 0xFF);
  1282. }
  1283. /* Update sample rate mode */
  1284. if (rate < 50000)
  1285. snd_soc_update_bits(codec, M98095_038_DAI2_FILTERS,
  1286. M98095_DAI_DHF, 0);
  1287. else
  1288. snd_soc_update_bits(codec, M98095_038_DAI2_FILTERS,
  1289. M98095_DAI_DHF, M98095_DAI_DHF);
  1290. return 0;
  1291. }
  1292. static int max98095_dai3_hw_params(struct snd_pcm_substream *substream,
  1293. struct snd_pcm_hw_params *params,
  1294. struct snd_soc_dai *dai)
  1295. {
  1296. struct snd_soc_codec *codec = dai->codec;
  1297. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  1298. struct max98095_cdata *cdata;
  1299. unsigned long long ni;
  1300. unsigned int rate;
  1301. u8 regval;
  1302. cdata = &max98095->dai[2];
  1303. rate = params_rate(params);
  1304. switch (params_format(params)) {
  1305. case SNDRV_PCM_FORMAT_S16_LE:
  1306. snd_soc_update_bits(codec, M98095_03E_DAI3_FORMAT,
  1307. M98095_DAI_WS, 0);
  1308. break;
  1309. case SNDRV_PCM_FORMAT_S24_LE:
  1310. snd_soc_update_bits(codec, M98095_03E_DAI3_FORMAT,
  1311. M98095_DAI_WS, M98095_DAI_WS);
  1312. break;
  1313. default:
  1314. return -EINVAL;
  1315. }
  1316. if (rate_value(rate, &regval))
  1317. return -EINVAL;
  1318. snd_soc_update_bits(codec, M98095_03B_DAI3_CLKMODE,
  1319. M98095_CLKMODE_MASK, regval);
  1320. cdata->rate = rate;
  1321. /* Configure NI when operating as master */
  1322. if (snd_soc_read(codec, M98095_03E_DAI3_FORMAT) & M98095_DAI_MAS) {
  1323. if (max98095->sysclk == 0) {
  1324. dev_err(codec->dev, "Invalid system clock frequency\n");
  1325. return -EINVAL;
  1326. }
  1327. ni = 65536ULL * (rate < 50000 ? 96ULL : 48ULL)
  1328. * (unsigned long long int)rate;
  1329. do_div(ni, (unsigned long long int)max98095->sysclk);
  1330. snd_soc_write(codec, M98095_03C_DAI3_CLKCFG_HI,
  1331. (ni >> 8) & 0x7F);
  1332. snd_soc_write(codec, M98095_03D_DAI3_CLKCFG_LO,
  1333. ni & 0xFF);
  1334. }
  1335. /* Update sample rate mode */
  1336. if (rate < 50000)
  1337. snd_soc_update_bits(codec, M98095_042_DAI3_FILTERS,
  1338. M98095_DAI_DHF, 0);
  1339. else
  1340. snd_soc_update_bits(codec, M98095_042_DAI3_FILTERS,
  1341. M98095_DAI_DHF, M98095_DAI_DHF);
  1342. return 0;
  1343. }
  1344. static int max98095_dai_set_sysclk(struct snd_soc_dai *dai,
  1345. int clk_id, unsigned int freq, int dir)
  1346. {
  1347. struct snd_soc_codec *codec = dai->codec;
  1348. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  1349. /* Requested clock frequency is already setup */
  1350. if (freq == max98095->sysclk)
  1351. return 0;
  1352. /* Setup clocks for slave mode, and using the PLL
  1353. * PSCLK = 0x01 (when master clk is 10MHz to 20MHz)
  1354. * 0x02 (when master clk is 20MHz to 40MHz)..
  1355. * 0x03 (when master clk is 40MHz to 60MHz)..
  1356. */
  1357. if ((freq >= 10000000) && (freq < 20000000)) {
  1358. snd_soc_write(codec, M98095_026_SYS_CLK, 0x10);
  1359. } else if ((freq >= 20000000) && (freq < 40000000)) {
  1360. snd_soc_write(codec, M98095_026_SYS_CLK, 0x20);
  1361. } else if ((freq >= 40000000) && (freq < 60000000)) {
  1362. snd_soc_write(codec, M98095_026_SYS_CLK, 0x30);
  1363. } else {
  1364. dev_err(codec->dev, "Invalid master clock frequency\n");
  1365. return -EINVAL;
  1366. }
  1367. dev_dbg(dai->dev, "Clock source is %d at %uHz\n", clk_id, freq);
  1368. max98095->sysclk = freq;
  1369. return 0;
  1370. }
  1371. static int max98095_dai1_set_fmt(struct snd_soc_dai *codec_dai,
  1372. unsigned int fmt)
  1373. {
  1374. struct snd_soc_codec *codec = codec_dai->codec;
  1375. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  1376. struct max98095_cdata *cdata;
  1377. u8 regval = 0;
  1378. cdata = &max98095->dai[0];
  1379. if (fmt != cdata->fmt) {
  1380. cdata->fmt = fmt;
  1381. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1382. case SND_SOC_DAIFMT_CBS_CFS:
  1383. /* Slave mode PLL */
  1384. snd_soc_write(codec, M98095_028_DAI1_CLKCFG_HI,
  1385. 0x80);
  1386. snd_soc_write(codec, M98095_029_DAI1_CLKCFG_LO,
  1387. 0x00);
  1388. break;
  1389. case SND_SOC_DAIFMT_CBM_CFM:
  1390. /* Set to master mode */
  1391. regval |= M98095_DAI_MAS;
  1392. break;
  1393. case SND_SOC_DAIFMT_CBS_CFM:
  1394. case SND_SOC_DAIFMT_CBM_CFS:
  1395. default:
  1396. dev_err(codec->dev, "Clock mode unsupported");
  1397. return -EINVAL;
  1398. }
  1399. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1400. case SND_SOC_DAIFMT_I2S:
  1401. regval |= M98095_DAI_DLY;
  1402. break;
  1403. case SND_SOC_DAIFMT_LEFT_J:
  1404. break;
  1405. default:
  1406. return -EINVAL;
  1407. }
  1408. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  1409. case SND_SOC_DAIFMT_NB_NF:
  1410. break;
  1411. case SND_SOC_DAIFMT_NB_IF:
  1412. regval |= M98095_DAI_WCI;
  1413. break;
  1414. case SND_SOC_DAIFMT_IB_NF:
  1415. regval |= M98095_DAI_BCI;
  1416. break;
  1417. case SND_SOC_DAIFMT_IB_IF:
  1418. regval |= M98095_DAI_BCI|M98095_DAI_WCI;
  1419. break;
  1420. default:
  1421. return -EINVAL;
  1422. }
  1423. snd_soc_update_bits(codec, M98095_02A_DAI1_FORMAT,
  1424. M98095_DAI_MAS | M98095_DAI_DLY | M98095_DAI_BCI |
  1425. M98095_DAI_WCI, regval);
  1426. snd_soc_write(codec, M98095_02B_DAI1_CLOCK, M98095_DAI_BSEL64);
  1427. }
  1428. return 0;
  1429. }
  1430. static int max98095_dai2_set_fmt(struct snd_soc_dai *codec_dai,
  1431. unsigned int fmt)
  1432. {
  1433. struct snd_soc_codec *codec = codec_dai->codec;
  1434. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  1435. struct max98095_cdata *cdata;
  1436. u8 regval = 0;
  1437. cdata = &max98095->dai[1];
  1438. if (fmt != cdata->fmt) {
  1439. cdata->fmt = fmt;
  1440. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1441. case SND_SOC_DAIFMT_CBS_CFS:
  1442. /* Slave mode PLL */
  1443. snd_soc_write(codec, M98095_032_DAI2_CLKCFG_HI,
  1444. 0x80);
  1445. snd_soc_write(codec, M98095_033_DAI2_CLKCFG_LO,
  1446. 0x00);
  1447. break;
  1448. case SND_SOC_DAIFMT_CBM_CFM:
  1449. /* Set to master mode */
  1450. regval |= M98095_DAI_MAS;
  1451. break;
  1452. case SND_SOC_DAIFMT_CBS_CFM:
  1453. case SND_SOC_DAIFMT_CBM_CFS:
  1454. default:
  1455. dev_err(codec->dev, "Clock mode unsupported");
  1456. return -EINVAL;
  1457. }
  1458. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1459. case SND_SOC_DAIFMT_I2S:
  1460. regval |= M98095_DAI_DLY;
  1461. break;
  1462. case SND_SOC_DAIFMT_LEFT_J:
  1463. break;
  1464. default:
  1465. return -EINVAL;
  1466. }
  1467. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  1468. case SND_SOC_DAIFMT_NB_NF:
  1469. break;
  1470. case SND_SOC_DAIFMT_NB_IF:
  1471. regval |= M98095_DAI_WCI;
  1472. break;
  1473. case SND_SOC_DAIFMT_IB_NF:
  1474. regval |= M98095_DAI_BCI;
  1475. break;
  1476. case SND_SOC_DAIFMT_IB_IF:
  1477. regval |= M98095_DAI_BCI|M98095_DAI_WCI;
  1478. break;
  1479. default:
  1480. return -EINVAL;
  1481. }
  1482. snd_soc_update_bits(codec, M98095_034_DAI2_FORMAT,
  1483. M98095_DAI_MAS | M98095_DAI_DLY | M98095_DAI_BCI |
  1484. M98095_DAI_WCI, regval);
  1485. snd_soc_write(codec, M98095_035_DAI2_CLOCK,
  1486. M98095_DAI_BSEL64);
  1487. }
  1488. return 0;
  1489. }
  1490. static int max98095_dai3_set_fmt(struct snd_soc_dai *codec_dai,
  1491. unsigned int fmt)
  1492. {
  1493. struct snd_soc_codec *codec = codec_dai->codec;
  1494. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  1495. struct max98095_cdata *cdata;
  1496. u8 regval = 0;
  1497. cdata = &max98095->dai[2];
  1498. if (fmt != cdata->fmt) {
  1499. cdata->fmt = fmt;
  1500. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1501. case SND_SOC_DAIFMT_CBS_CFS:
  1502. /* Slave mode PLL */
  1503. snd_soc_write(codec, M98095_03C_DAI3_CLKCFG_HI,
  1504. 0x80);
  1505. snd_soc_write(codec, M98095_03D_DAI3_CLKCFG_LO,
  1506. 0x00);
  1507. break;
  1508. case SND_SOC_DAIFMT_CBM_CFM:
  1509. /* Set to master mode */
  1510. regval |= M98095_DAI_MAS;
  1511. break;
  1512. case SND_SOC_DAIFMT_CBS_CFM:
  1513. case SND_SOC_DAIFMT_CBM_CFS:
  1514. default:
  1515. dev_err(codec->dev, "Clock mode unsupported");
  1516. return -EINVAL;
  1517. }
  1518. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1519. case SND_SOC_DAIFMT_I2S:
  1520. regval |= M98095_DAI_DLY;
  1521. break;
  1522. case SND_SOC_DAIFMT_LEFT_J:
  1523. break;
  1524. default:
  1525. return -EINVAL;
  1526. }
  1527. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  1528. case SND_SOC_DAIFMT_NB_NF:
  1529. break;
  1530. case SND_SOC_DAIFMT_NB_IF:
  1531. regval |= M98095_DAI_WCI;
  1532. break;
  1533. case SND_SOC_DAIFMT_IB_NF:
  1534. regval |= M98095_DAI_BCI;
  1535. break;
  1536. case SND_SOC_DAIFMT_IB_IF:
  1537. regval |= M98095_DAI_BCI|M98095_DAI_WCI;
  1538. break;
  1539. default:
  1540. return -EINVAL;
  1541. }
  1542. snd_soc_update_bits(codec, M98095_03E_DAI3_FORMAT,
  1543. M98095_DAI_MAS | M98095_DAI_DLY | M98095_DAI_BCI |
  1544. M98095_DAI_WCI, regval);
  1545. snd_soc_write(codec, M98095_03F_DAI3_CLOCK,
  1546. M98095_DAI_BSEL64);
  1547. }
  1548. return 0;
  1549. }
  1550. static int max98095_set_bias_level(struct snd_soc_codec *codec,
  1551. enum snd_soc_bias_level level)
  1552. {
  1553. int ret;
  1554. switch (level) {
  1555. case SND_SOC_BIAS_ON:
  1556. break;
  1557. case SND_SOC_BIAS_PREPARE:
  1558. break;
  1559. case SND_SOC_BIAS_STANDBY:
  1560. if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
  1561. ret = snd_soc_cache_sync(codec);
  1562. if (ret != 0) {
  1563. dev_err(codec->dev, "Failed to sync cache: %d\n", ret);
  1564. return ret;
  1565. }
  1566. }
  1567. snd_soc_update_bits(codec, M98095_090_PWR_EN_IN,
  1568. M98095_MBEN, M98095_MBEN);
  1569. break;
  1570. case SND_SOC_BIAS_OFF:
  1571. snd_soc_update_bits(codec, M98095_090_PWR_EN_IN,
  1572. M98095_MBEN, 0);
  1573. codec->cache_sync = 1;
  1574. break;
  1575. }
  1576. codec->dapm.bias_level = level;
  1577. return 0;
  1578. }
  1579. #define MAX98095_RATES SNDRV_PCM_RATE_8000_96000
  1580. #define MAX98095_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE)
  1581. static const struct snd_soc_dai_ops max98095_dai1_ops = {
  1582. .set_sysclk = max98095_dai_set_sysclk,
  1583. .set_fmt = max98095_dai1_set_fmt,
  1584. .hw_params = max98095_dai1_hw_params,
  1585. };
  1586. static const struct snd_soc_dai_ops max98095_dai2_ops = {
  1587. .set_sysclk = max98095_dai_set_sysclk,
  1588. .set_fmt = max98095_dai2_set_fmt,
  1589. .hw_params = max98095_dai2_hw_params,
  1590. };
  1591. static const struct snd_soc_dai_ops max98095_dai3_ops = {
  1592. .set_sysclk = max98095_dai_set_sysclk,
  1593. .set_fmt = max98095_dai3_set_fmt,
  1594. .hw_params = max98095_dai3_hw_params,
  1595. };
  1596. static struct snd_soc_dai_driver max98095_dai[] = {
  1597. {
  1598. .name = "HiFi",
  1599. .playback = {
  1600. .stream_name = "HiFi Playback",
  1601. .channels_min = 1,
  1602. .channels_max = 2,
  1603. .rates = MAX98095_RATES,
  1604. .formats = MAX98095_FORMATS,
  1605. },
  1606. .capture = {
  1607. .stream_name = "HiFi Capture",
  1608. .channels_min = 1,
  1609. .channels_max = 2,
  1610. .rates = MAX98095_RATES,
  1611. .formats = MAX98095_FORMATS,
  1612. },
  1613. .ops = &max98095_dai1_ops,
  1614. },
  1615. {
  1616. .name = "Aux",
  1617. .playback = {
  1618. .stream_name = "Aux Playback",
  1619. .channels_min = 1,
  1620. .channels_max = 1,
  1621. .rates = MAX98095_RATES,
  1622. .formats = MAX98095_FORMATS,
  1623. },
  1624. .ops = &max98095_dai2_ops,
  1625. },
  1626. {
  1627. .name = "Voice",
  1628. .playback = {
  1629. .stream_name = "Voice Playback",
  1630. .channels_min = 1,
  1631. .channels_max = 1,
  1632. .rates = MAX98095_RATES,
  1633. .formats = MAX98095_FORMATS,
  1634. },
  1635. .ops = &max98095_dai3_ops,
  1636. }
  1637. };
  1638. static int max98095_get_eq_channel(const char *name)
  1639. {
  1640. if (strcmp(name, "EQ1 Mode") == 0)
  1641. return 0;
  1642. if (strcmp(name, "EQ2 Mode") == 0)
  1643. return 1;
  1644. return -EINVAL;
  1645. }
  1646. static int max98095_put_eq_enum(struct snd_kcontrol *kcontrol,
  1647. struct snd_ctl_elem_value *ucontrol)
  1648. {
  1649. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1650. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  1651. struct max98095_pdata *pdata = max98095->pdata;
  1652. int channel = max98095_get_eq_channel(kcontrol->id.name);
  1653. struct max98095_cdata *cdata;
  1654. unsigned int sel = ucontrol->value.integer.value[0];
  1655. struct max98095_eq_cfg *coef_set;
  1656. int fs, best, best_val, i;
  1657. int regmask, regsave;
  1658. BUG_ON(channel > 1);
  1659. if (!pdata || !max98095->eq_textcnt)
  1660. return 0;
  1661. if (sel >= pdata->eq_cfgcnt)
  1662. return -EINVAL;
  1663. cdata = &max98095->dai[channel];
  1664. cdata->eq_sel = sel;
  1665. fs = cdata->rate;
  1666. /* Find the selected configuration with nearest sample rate */
  1667. best = 0;
  1668. best_val = INT_MAX;
  1669. for (i = 0; i < pdata->eq_cfgcnt; i++) {
  1670. if (strcmp(pdata->eq_cfg[i].name, max98095->eq_texts[sel]) == 0 &&
  1671. abs(pdata->eq_cfg[i].rate - fs) < best_val) {
  1672. best = i;
  1673. best_val = abs(pdata->eq_cfg[i].rate - fs);
  1674. }
  1675. }
  1676. dev_dbg(codec->dev, "Selected %s/%dHz for %dHz sample rate\n",
  1677. pdata->eq_cfg[best].name,
  1678. pdata->eq_cfg[best].rate, fs);
  1679. coef_set = &pdata->eq_cfg[best];
  1680. regmask = (channel == 0) ? M98095_EQ1EN : M98095_EQ2EN;
  1681. /* Disable filter while configuring, and save current on/off state */
  1682. regsave = snd_soc_read(codec, M98095_088_CFG_LEVEL);
  1683. snd_soc_update_bits(codec, M98095_088_CFG_LEVEL, regmask, 0);
  1684. mutex_lock(&codec->mutex);
  1685. snd_soc_update_bits(codec, M98095_00F_HOST_CFG, M98095_SEG, M98095_SEG);
  1686. m98095_eq_band(codec, channel, 0, coef_set->band1);
  1687. m98095_eq_band(codec, channel, 1, coef_set->band2);
  1688. m98095_eq_band(codec, channel, 2, coef_set->band3);
  1689. m98095_eq_band(codec, channel, 3, coef_set->band4);
  1690. m98095_eq_band(codec, channel, 4, coef_set->band5);
  1691. snd_soc_update_bits(codec, M98095_00F_HOST_CFG, M98095_SEG, 0);
  1692. mutex_unlock(&codec->mutex);
  1693. /* Restore the original on/off state */
  1694. snd_soc_update_bits(codec, M98095_088_CFG_LEVEL, regmask, regsave);
  1695. return 0;
  1696. }
  1697. static int max98095_get_eq_enum(struct snd_kcontrol *kcontrol,
  1698. struct snd_ctl_elem_value *ucontrol)
  1699. {
  1700. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1701. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  1702. int channel = max98095_get_eq_channel(kcontrol->id.name);
  1703. struct max98095_cdata *cdata;
  1704. cdata = &max98095->dai[channel];
  1705. ucontrol->value.enumerated.item[0] = cdata->eq_sel;
  1706. return 0;
  1707. }
  1708. static void max98095_handle_eq_pdata(struct snd_soc_codec *codec)
  1709. {
  1710. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  1711. struct max98095_pdata *pdata = max98095->pdata;
  1712. struct max98095_eq_cfg *cfg;
  1713. unsigned int cfgcnt;
  1714. int i, j;
  1715. const char **t;
  1716. int ret;
  1717. struct snd_kcontrol_new controls[] = {
  1718. SOC_ENUM_EXT("EQ1 Mode",
  1719. max98095->eq_enum,
  1720. max98095_get_eq_enum,
  1721. max98095_put_eq_enum),
  1722. SOC_ENUM_EXT("EQ2 Mode",
  1723. max98095->eq_enum,
  1724. max98095_get_eq_enum,
  1725. max98095_put_eq_enum),
  1726. };
  1727. cfg = pdata->eq_cfg;
  1728. cfgcnt = pdata->eq_cfgcnt;
  1729. /* Setup an array of texts for the equalizer enum.
  1730. * This is based on Mark Brown's equalizer driver code.
  1731. */
  1732. max98095->eq_textcnt = 0;
  1733. max98095->eq_texts = NULL;
  1734. for (i = 0; i < cfgcnt; i++) {
  1735. for (j = 0; j < max98095->eq_textcnt; j++) {
  1736. if (strcmp(cfg[i].name, max98095->eq_texts[j]) == 0)
  1737. break;
  1738. }
  1739. if (j != max98095->eq_textcnt)
  1740. continue;
  1741. /* Expand the array */
  1742. t = krealloc(max98095->eq_texts,
  1743. sizeof(char *) * (max98095->eq_textcnt + 1),
  1744. GFP_KERNEL);
  1745. if (t == NULL)
  1746. continue;
  1747. /* Store the new entry */
  1748. t[max98095->eq_textcnt] = cfg[i].name;
  1749. max98095->eq_textcnt++;
  1750. max98095->eq_texts = t;
  1751. }
  1752. /* Now point the soc_enum to .texts array items */
  1753. max98095->eq_enum.texts = max98095->eq_texts;
  1754. max98095->eq_enum.max = max98095->eq_textcnt;
  1755. ret = snd_soc_add_codec_controls(codec, controls, ARRAY_SIZE(controls));
  1756. if (ret != 0)
  1757. dev_err(codec->dev, "Failed to add EQ control: %d\n", ret);
  1758. }
  1759. static const char *bq_mode_name[] = {"Biquad1 Mode", "Biquad2 Mode"};
  1760. static int max98095_get_bq_channel(struct snd_soc_codec *codec,
  1761. const char *name)
  1762. {
  1763. int i;
  1764. for (i = 0; i < ARRAY_SIZE(bq_mode_name); i++)
  1765. if (strcmp(name, bq_mode_name[i]) == 0)
  1766. return i;
  1767. /* Shouldn't happen */
  1768. dev_err(codec->dev, "Bad biquad channel name '%s'\n", name);
  1769. return -EINVAL;
  1770. }
  1771. static int max98095_put_bq_enum(struct snd_kcontrol *kcontrol,
  1772. struct snd_ctl_elem_value *ucontrol)
  1773. {
  1774. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1775. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  1776. struct max98095_pdata *pdata = max98095->pdata;
  1777. int channel = max98095_get_bq_channel(codec, kcontrol->id.name);
  1778. struct max98095_cdata *cdata;
  1779. unsigned int sel = ucontrol->value.integer.value[0];
  1780. struct max98095_biquad_cfg *coef_set;
  1781. int fs, best, best_val, i;
  1782. int regmask, regsave;
  1783. if (channel < 0)
  1784. return channel;
  1785. if (!pdata || !max98095->bq_textcnt)
  1786. return 0;
  1787. if (sel >= pdata->bq_cfgcnt)
  1788. return -EINVAL;
  1789. cdata = &max98095->dai[channel];
  1790. cdata->bq_sel = sel;
  1791. fs = cdata->rate;
  1792. /* Find the selected configuration with nearest sample rate */
  1793. best = 0;
  1794. best_val = INT_MAX;
  1795. for (i = 0; i < pdata->bq_cfgcnt; i++) {
  1796. if (strcmp(pdata->bq_cfg[i].name, max98095->bq_texts[sel]) == 0 &&
  1797. abs(pdata->bq_cfg[i].rate - fs) < best_val) {
  1798. best = i;
  1799. best_val = abs(pdata->bq_cfg[i].rate - fs);
  1800. }
  1801. }
  1802. dev_dbg(codec->dev, "Selected %s/%dHz for %dHz sample rate\n",
  1803. pdata->bq_cfg[best].name,
  1804. pdata->bq_cfg[best].rate, fs);
  1805. coef_set = &pdata->bq_cfg[best];
  1806. regmask = (channel == 0) ? M98095_BQ1EN : M98095_BQ2EN;
  1807. /* Disable filter while configuring, and save current on/off state */
  1808. regsave = snd_soc_read(codec, M98095_088_CFG_LEVEL);
  1809. snd_soc_update_bits(codec, M98095_088_CFG_LEVEL, regmask, 0);
  1810. mutex_lock(&codec->mutex);
  1811. snd_soc_update_bits(codec, M98095_00F_HOST_CFG, M98095_SEG, M98095_SEG);
  1812. m98095_biquad_band(codec, channel, 0, coef_set->band1);
  1813. m98095_biquad_band(codec, channel, 1, coef_set->band2);
  1814. snd_soc_update_bits(codec, M98095_00F_HOST_CFG, M98095_SEG, 0);
  1815. mutex_unlock(&codec->mutex);
  1816. /* Restore the original on/off state */
  1817. snd_soc_update_bits(codec, M98095_088_CFG_LEVEL, regmask, regsave);
  1818. return 0;
  1819. }
  1820. static int max98095_get_bq_enum(struct snd_kcontrol *kcontrol,
  1821. struct snd_ctl_elem_value *ucontrol)
  1822. {
  1823. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1824. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  1825. int channel = max98095_get_bq_channel(codec, kcontrol->id.name);
  1826. struct max98095_cdata *cdata;
  1827. if (channel < 0)
  1828. return channel;
  1829. cdata = &max98095->dai[channel];
  1830. ucontrol->value.enumerated.item[0] = cdata->bq_sel;
  1831. return 0;
  1832. }
  1833. static void max98095_handle_bq_pdata(struct snd_soc_codec *codec)
  1834. {
  1835. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  1836. struct max98095_pdata *pdata = max98095->pdata;
  1837. struct max98095_biquad_cfg *cfg;
  1838. unsigned int cfgcnt;
  1839. int i, j;
  1840. const char **t;
  1841. int ret;
  1842. struct snd_kcontrol_new controls[] = {
  1843. SOC_ENUM_EXT((char *)bq_mode_name[0],
  1844. max98095->bq_enum,
  1845. max98095_get_bq_enum,
  1846. max98095_put_bq_enum),
  1847. SOC_ENUM_EXT((char *)bq_mode_name[1],
  1848. max98095->bq_enum,
  1849. max98095_get_bq_enum,
  1850. max98095_put_bq_enum),
  1851. };
  1852. BUILD_BUG_ON(ARRAY_SIZE(controls) != ARRAY_SIZE(bq_mode_name));
  1853. cfg = pdata->bq_cfg;
  1854. cfgcnt = pdata->bq_cfgcnt;
  1855. /* Setup an array of texts for the biquad enum.
  1856. * This is based on Mark Brown's equalizer driver code.
  1857. */
  1858. max98095->bq_textcnt = 0;
  1859. max98095->bq_texts = NULL;
  1860. for (i = 0; i < cfgcnt; i++) {
  1861. for (j = 0; j < max98095->bq_textcnt; j++) {
  1862. if (strcmp(cfg[i].name, max98095->bq_texts[j]) == 0)
  1863. break;
  1864. }
  1865. if (j != max98095->bq_textcnt)
  1866. continue;
  1867. /* Expand the array */
  1868. t = krealloc(max98095->bq_texts,
  1869. sizeof(char *) * (max98095->bq_textcnt + 1),
  1870. GFP_KERNEL);
  1871. if (t == NULL)
  1872. continue;
  1873. /* Store the new entry */
  1874. t[max98095->bq_textcnt] = cfg[i].name;
  1875. max98095->bq_textcnt++;
  1876. max98095->bq_texts = t;
  1877. }
  1878. /* Now point the soc_enum to .texts array items */
  1879. max98095->bq_enum.texts = max98095->bq_texts;
  1880. max98095->bq_enum.max = max98095->bq_textcnt;
  1881. ret = snd_soc_add_codec_controls(codec, controls, ARRAY_SIZE(controls));
  1882. if (ret != 0)
  1883. dev_err(codec->dev, "Failed to add Biquad control: %d\n", ret);
  1884. }
  1885. static void max98095_handle_pdata(struct snd_soc_codec *codec)
  1886. {
  1887. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  1888. struct max98095_pdata *pdata = max98095->pdata;
  1889. u8 regval = 0;
  1890. if (!pdata) {
  1891. dev_dbg(codec->dev, "No platform data\n");
  1892. return;
  1893. }
  1894. /* Configure mic for analog/digital mic mode */
  1895. if (pdata->digmic_left_mode)
  1896. regval |= M98095_DIGMIC_L;
  1897. if (pdata->digmic_right_mode)
  1898. regval |= M98095_DIGMIC_R;
  1899. snd_soc_write(codec, M98095_087_CFG_MIC, regval);
  1900. /* Configure equalizers */
  1901. if (pdata->eq_cfgcnt)
  1902. max98095_handle_eq_pdata(codec);
  1903. /* Configure bi-quad filters */
  1904. if (pdata->bq_cfgcnt)
  1905. max98095_handle_bq_pdata(codec);
  1906. }
  1907. #ifdef CONFIG_PM
  1908. static int max98095_suspend(struct snd_soc_codec *codec)
  1909. {
  1910. max98095_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1911. return 0;
  1912. }
  1913. static int max98095_resume(struct snd_soc_codec *codec)
  1914. {
  1915. max98095_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1916. return 0;
  1917. }
  1918. #else
  1919. #define max98095_suspend NULL
  1920. #define max98095_resume NULL
  1921. #endif
  1922. static int max98095_reset(struct snd_soc_codec *codec)
  1923. {
  1924. int i, ret;
  1925. /* Gracefully reset the DSP core and the codec hardware
  1926. * in a proper sequence */
  1927. ret = snd_soc_write(codec, M98095_00F_HOST_CFG, 0);
  1928. if (ret < 0) {
  1929. dev_err(codec->dev, "Failed to reset DSP: %d\n", ret);
  1930. return ret;
  1931. }
  1932. ret = snd_soc_write(codec, M98095_097_PWR_SYS, 0);
  1933. if (ret < 0) {
  1934. dev_err(codec->dev, "Failed to reset codec: %d\n", ret);
  1935. return ret;
  1936. }
  1937. /* Reset to hardware default for registers, as there is not
  1938. * a soft reset hardware control register */
  1939. for (i = M98095_010_HOST_INT_CFG; i < M98095_REG_MAX_CACHED; i++) {
  1940. ret = snd_soc_write(codec, i, max98095_reg_def[i]);
  1941. if (ret < 0) {
  1942. dev_err(codec->dev, "Failed to reset: %d\n", ret);
  1943. return ret;
  1944. }
  1945. }
  1946. return ret;
  1947. }
  1948. static int max98095_probe(struct snd_soc_codec *codec)
  1949. {
  1950. struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
  1951. struct max98095_cdata *cdata;
  1952. int ret = 0;
  1953. ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C);
  1954. if (ret != 0) {
  1955. dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
  1956. return ret;
  1957. }
  1958. /* reset the codec, the DSP core, and disable all interrupts */
  1959. max98095_reset(codec);
  1960. /* initialize private data */
  1961. max98095->sysclk = (unsigned)-1;
  1962. max98095->eq_textcnt = 0;
  1963. max98095->bq_textcnt = 0;
  1964. cdata = &max98095->dai[0];
  1965. cdata->rate = (unsigned)-1;
  1966. cdata->fmt = (unsigned)-1;
  1967. cdata->eq_sel = 0;
  1968. cdata->bq_sel = 0;
  1969. cdata = &max98095->dai[1];
  1970. cdata->rate = (unsigned)-1;
  1971. cdata->fmt = (unsigned)-1;
  1972. cdata->eq_sel = 0;
  1973. cdata->bq_sel = 0;
  1974. cdata = &max98095->dai[2];
  1975. cdata->rate = (unsigned)-1;
  1976. cdata->fmt = (unsigned)-1;
  1977. cdata->eq_sel = 0;
  1978. cdata->bq_sel = 0;
  1979. max98095->lin_state = 0;
  1980. max98095->mic1pre = 0;
  1981. max98095->mic2pre = 0;
  1982. ret = snd_soc_read(codec, M98095_0FF_REV_ID);
  1983. if (ret < 0) {
  1984. dev_err(codec->dev, "Failure reading hardware revision: %d\n",
  1985. ret);
  1986. goto err_access;
  1987. }
  1988. dev_info(codec->dev, "Hardware revision: %c\n", ret - 0x40 + 'A');
  1989. snd_soc_write(codec, M98095_097_PWR_SYS, M98095_PWRSV);
  1990. /* initialize registers cache to hardware default */
  1991. max98095_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1992. snd_soc_write(codec, M98095_048_MIX_DAC_LR,
  1993. M98095_DAI1L_TO_DACL|M98095_DAI1R_TO_DACR);
  1994. snd_soc_write(codec, M98095_049_MIX_DAC_M,
  1995. M98095_DAI2M_TO_DACM|M98095_DAI3M_TO_DACM);
  1996. snd_soc_write(codec, M98095_092_PWR_EN_OUT, M98095_SPK_SPREADSPECTRUM);
  1997. snd_soc_write(codec, M98095_045_CFG_DSP, M98095_DSPNORMAL);
  1998. snd_soc_write(codec, M98095_04E_CFG_HP, M98095_HPNORMAL);
  1999. snd_soc_write(codec, M98095_02C_DAI1_IOCFG,
  2000. M98095_S1NORMAL|M98095_SDATA);
  2001. snd_soc_write(codec, M98095_036_DAI2_IOCFG,
  2002. M98095_S2NORMAL|M98095_SDATA);
  2003. snd_soc_write(codec, M98095_040_DAI3_IOCFG,
  2004. M98095_S3NORMAL|M98095_SDATA);
  2005. max98095_handle_pdata(codec);
  2006. /* take the codec out of the shut down */
  2007. snd_soc_update_bits(codec, M98095_097_PWR_SYS, M98095_SHDNRUN,
  2008. M98095_SHDNRUN);
  2009. max98095_add_widgets(codec);
  2010. err_access:
  2011. return ret;
  2012. }
  2013. static int max98095_remove(struct snd_soc_codec *codec)
  2014. {
  2015. max98095_set_bias_level(codec, SND_SOC_BIAS_OFF);
  2016. return 0;
  2017. }
  2018. static struct snd_soc_codec_driver soc_codec_dev_max98095 = {
  2019. .probe = max98095_probe,
  2020. .remove = max98095_remove,
  2021. .suspend = max98095_suspend,
  2022. .resume = max98095_resume,
  2023. .set_bias_level = max98095_set_bias_level,
  2024. .reg_cache_size = ARRAY_SIZE(max98095_reg_def),
  2025. .reg_word_size = sizeof(u8),
  2026. .reg_cache_default = max98095_reg_def,
  2027. .readable_register = max98095_readable,
  2028. .volatile_register = max98095_volatile,
  2029. .dapm_widgets = max98095_dapm_widgets,
  2030. .num_dapm_widgets = ARRAY_SIZE(max98095_dapm_widgets),
  2031. .dapm_routes = max98095_audio_map,
  2032. .num_dapm_routes = ARRAY_SIZE(max98095_audio_map),
  2033. };
  2034. static int max98095_i2c_probe(struct i2c_client *i2c,
  2035. const struct i2c_device_id *id)
  2036. {
  2037. struct max98095_priv *max98095;
  2038. int ret;
  2039. max98095 = devm_kzalloc(&i2c->dev, sizeof(struct max98095_priv),
  2040. GFP_KERNEL);
  2041. if (max98095 == NULL)
  2042. return -ENOMEM;
  2043. max98095->devtype = id->driver_data;
  2044. i2c_set_clientdata(i2c, max98095);
  2045. max98095->pdata = i2c->dev.platform_data;
  2046. ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_max98095,
  2047. max98095_dai, ARRAY_SIZE(max98095_dai));
  2048. return ret;
  2049. }
  2050. static int __devexit max98095_i2c_remove(struct i2c_client *client)
  2051. {
  2052. snd_soc_unregister_codec(&client->dev);
  2053. return 0;
  2054. }
  2055. static const struct i2c_device_id max98095_i2c_id[] = {
  2056. { "max98095", MAX98095 },
  2057. { }
  2058. };
  2059. MODULE_DEVICE_TABLE(i2c, max98095_i2c_id);
  2060. static struct i2c_driver max98095_i2c_driver = {
  2061. .driver = {
  2062. .name = "max98095",
  2063. .owner = THIS_MODULE,
  2064. },
  2065. .probe = max98095_i2c_probe,
  2066. .remove = __devexit_p(max98095_i2c_remove),
  2067. .id_table = max98095_i2c_id,
  2068. };
  2069. static int __init max98095_init(void)
  2070. {
  2071. int ret;
  2072. ret = i2c_add_driver(&max98095_i2c_driver);
  2073. if (ret)
  2074. pr_err("Failed to register max98095 I2C driver: %d\n", ret);
  2075. return ret;
  2076. }
  2077. module_init(max98095_init);
  2078. static void __exit max98095_exit(void)
  2079. {
  2080. i2c_del_driver(&max98095_i2c_driver);
  2081. }
  2082. module_exit(max98095_exit);
  2083. MODULE_DESCRIPTION("ALSA SoC MAX98095 driver");
  2084. MODULE_AUTHOR("Peter Hsiang");
  2085. MODULE_LICENSE("GPL");