cs42l73.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456
  1. /*
  2. * cs42l73.c -- CS42L73 ALSA Soc Audio driver
  3. *
  4. * Copyright 2011 Cirrus Logic, Inc.
  5. *
  6. * Authors: Georgi Vlaev, Nucleus Systems Ltd, <joe@nucleusys.com>
  7. * Brian Austin, Cirrus Logic Inc, <brian.austin@cirrus.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. */
  14. #include <linux/module.h>
  15. #include <linux/moduleparam.h>
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/delay.h>
  19. #include <linux/pm.h>
  20. #include <linux/i2c.h>
  21. #include <linux/regmap.h>
  22. #include <linux/slab.h>
  23. #include <sound/core.h>
  24. #include <sound/pcm.h>
  25. #include <sound/pcm_params.h>
  26. #include <sound/soc.h>
  27. #include <sound/soc-dapm.h>
  28. #include <sound/initval.h>
  29. #include <sound/tlv.h>
  30. #include "cs42l73.h"
  31. struct sp_config {
  32. u8 spc, mmcc, spfs;
  33. u32 srate;
  34. };
  35. struct cs42l73_private {
  36. struct sp_config config[3];
  37. struct regmap *regmap;
  38. u32 sysclk;
  39. u8 mclksel;
  40. u32 mclk;
  41. };
  42. static const struct reg_default cs42l73_reg_defaults[] = {
  43. { 1, 0x42 }, /* r01 - Device ID A&B */
  44. { 2, 0xA7 }, /* r02 - Device ID C&D */
  45. { 3, 0x30 }, /* r03 - Device ID E */
  46. { 6, 0xF1 }, /* r06 - Power Ctl 1 */
  47. { 7, 0xDF }, /* r07 - Power Ctl 2 */
  48. { 8, 0x3F }, /* r08 - Power Ctl 3 */
  49. { 9, 0x50 }, /* r09 - Charge Pump Freq */
  50. { 10, 0x53 }, /* r0A - Output Load MicBias Short Detect */
  51. { 11, 0x00 }, /* r0B - DMIC Master Clock Ctl */
  52. { 12, 0x00 }, /* r0C - Aux PCM Ctl */
  53. { 13, 0x15 }, /* r0D - Aux PCM Master Clock Ctl */
  54. { 14, 0x00 }, /* r0E - Audio PCM Ctl */
  55. { 15, 0x15 }, /* r0F - Audio PCM Master Clock Ctl */
  56. { 16, 0x00 }, /* r10 - Voice PCM Ctl */
  57. { 17, 0x15 }, /* r11 - Voice PCM Master Clock Ctl */
  58. { 18, 0x00 }, /* r12 - Voice/Aux Sample Rate */
  59. { 19, 0x06 }, /* r13 - Misc I/O Path Ctl */
  60. { 20, 0x00 }, /* r14 - ADC Input Path Ctl */
  61. { 21, 0x00 }, /* r15 - MICA Preamp, PGA Volume */
  62. { 22, 0x00 }, /* r16 - MICB Preamp, PGA Volume */
  63. { 23, 0x00 }, /* r17 - Input Path A Digital Volume */
  64. { 24, 0x00 }, /* r18 - Input Path B Digital Volume */
  65. { 25, 0x00 }, /* r19 - Playback Digital Ctl */
  66. { 26, 0x00 }, /* r1A - HP/LO Left Digital Volume */
  67. { 27, 0x00 }, /* r1B - HP/LO Right Digital Volume */
  68. { 28, 0x00 }, /* r1C - Speakerphone Digital Volume */
  69. { 29, 0x00 }, /* r1D - Ear/SPKLO Digital Volume */
  70. { 30, 0x00 }, /* r1E - HP Left Analog Volume */
  71. { 31, 0x00 }, /* r1F - HP Right Analog Volume */
  72. { 32, 0x00 }, /* r20 - LO Left Analog Volume */
  73. { 33, 0x00 }, /* r21 - LO Right Analog Volume */
  74. { 34, 0x00 }, /* r22 - Stereo Input Path Advisory Volume */
  75. { 35, 0x00 }, /* r23 - Aux PCM Input Advisory Volume */
  76. { 36, 0x00 }, /* r24 - Audio PCM Input Advisory Volume */
  77. { 37, 0x00 }, /* r25 - Voice PCM Input Advisory Volume */
  78. { 38, 0x00 }, /* r26 - Limiter Attack Rate HP/LO */
  79. { 39, 0x7F }, /* r27 - Limter Ctl, Release Rate HP/LO */
  80. { 40, 0x00 }, /* r28 - Limter Threshold HP/LO */
  81. { 41, 0x00 }, /* r29 - Limiter Attack Rate Speakerphone */
  82. { 42, 0x3F }, /* r2A - Limter Ctl, Release Rate Speakerphone */
  83. { 43, 0x00 }, /* r2B - Limter Threshold Speakerphone */
  84. { 44, 0x00 }, /* r2C - Limiter Attack Rate Ear/SPKLO */
  85. { 45, 0x3F }, /* r2D - Limter Ctl, Release Rate Ear/SPKLO */
  86. { 46, 0x00 }, /* r2E - Limter Threshold Ear/SPKLO */
  87. { 47, 0x00 }, /* r2F - ALC Enable, Attack Rate Left/Right */
  88. { 48, 0x3F }, /* r30 - ALC Release Rate Left/Right */
  89. { 49, 0x00 }, /* r31 - ALC Threshold Left/Right */
  90. { 50, 0x00 }, /* r32 - Noise Gate Ctl Left/Right */
  91. { 51, 0x00 }, /* r33 - ALC/NG Misc Ctl */
  92. { 52, 0x18 }, /* r34 - Mixer Ctl */
  93. { 53, 0x3F }, /* r35 - HP/LO Left Mixer Input Path Volume */
  94. { 54, 0x3F }, /* r36 - HP/LO Right Mixer Input Path Volume */
  95. { 55, 0x3F }, /* r37 - HP/LO Left Mixer Aux PCM Volume */
  96. { 56, 0x3F }, /* r38 - HP/LO Right Mixer Aux PCM Volume */
  97. { 57, 0x3F }, /* r39 - HP/LO Left Mixer Audio PCM Volume */
  98. { 58, 0x3F }, /* r3A - HP/LO Right Mixer Audio PCM Volume */
  99. { 59, 0x3F }, /* r3B - HP/LO Left Mixer Voice PCM Mono Volume */
  100. { 60, 0x3F }, /* r3C - HP/LO Right Mixer Voice PCM Mono Volume */
  101. { 61, 0x3F }, /* r3D - Aux PCM Left Mixer Input Path Volume */
  102. { 62, 0x3F }, /* r3E - Aux PCM Right Mixer Input Path Volume */
  103. { 63, 0x3F }, /* r3F - Aux PCM Left Mixer Volume */
  104. { 64, 0x3F }, /* r40 - Aux PCM Left Mixer Volume */
  105. { 65, 0x3F }, /* r41 - Aux PCM Left Mixer Audio PCM L Volume */
  106. { 66, 0x3F }, /* r42 - Aux PCM Right Mixer Audio PCM R Volume */
  107. { 67, 0x3F }, /* r43 - Aux PCM Left Mixer Voice PCM Volume */
  108. { 68, 0x3F }, /* r44 - Aux PCM Right Mixer Voice PCM Volume */
  109. { 69, 0x3F }, /* r45 - Audio PCM Left Input Path Volume */
  110. { 70, 0x3F }, /* r46 - Audio PCM Right Input Path Volume */
  111. { 71, 0x3F }, /* r47 - Audio PCM Left Mixer Aux PCM L Volume */
  112. { 72, 0x3F }, /* r48 - Audio PCM Right Mixer Aux PCM R Volume */
  113. { 73, 0x3F }, /* r49 - Audio PCM Left Mixer Volume */
  114. { 74, 0x3F }, /* r4A - Audio PCM Right Mixer Volume */
  115. { 75, 0x3F }, /* r4B - Audio PCM Left Mixer Voice PCM Volume */
  116. { 76, 0x3F }, /* r4C - Audio PCM Right Mixer Voice PCM Volume */
  117. { 77, 0x3F }, /* r4D - Voice PCM Left Input Path Volume */
  118. { 78, 0x3F }, /* r4E - Voice PCM Right Input Path Volume */
  119. { 79, 0x3F }, /* r4F - Voice PCM Left Mixer Aux PCM L Volume */
  120. { 80, 0x3F }, /* r50 - Voice PCM Right Mixer Aux PCM R Volume */
  121. { 81, 0x3F }, /* r51 - Voice PCM Left Mixer Audio PCM L Volume */
  122. { 82, 0x3F }, /* r52 - Voice PCM Right Mixer Audio PCM R Volume */
  123. { 83, 0x3F }, /* r53 - Voice PCM Left Mixer Voice PCM Volume */
  124. { 84, 0x3F }, /* r54 - Voice PCM Right Mixer Voice PCM Volume */
  125. { 85, 0xAA }, /* r55 - Mono Mixer Ctl */
  126. { 86, 0x3F }, /* r56 - SPK Mono Mixer Input Path Volume */
  127. { 87, 0x3F }, /* r57 - SPK Mono Mixer Aux PCM Mono/L/R Volume */
  128. { 88, 0x3F }, /* r58 - SPK Mono Mixer Audio PCM Mono/L/R Volume */
  129. { 89, 0x3F }, /* r59 - SPK Mono Mixer Voice PCM Mono Volume */
  130. { 90, 0x3F }, /* r5A - SPKLO Mono Mixer Input Path Mono Volume */
  131. { 91, 0x3F }, /* r5B - SPKLO Mono Mixer Aux Mono/L/R Volume */
  132. { 92, 0x3F }, /* r5C - SPKLO Mono Mixer Audio Mono/L/R Volume */
  133. { 93, 0x3F }, /* r5D - SPKLO Mono Mixer Voice Mono Volume */
  134. { 94, 0x00 }, /* r5E - Interrupt Mask 1 */
  135. { 95, 0x00 }, /* r5F - Interrupt Mask 2 */
  136. };
  137. static bool cs42l73_volatile_register(struct device *dev, unsigned int reg)
  138. {
  139. switch (reg) {
  140. case CS42L73_IS1:
  141. case CS42L73_IS2:
  142. return true;
  143. default:
  144. return false;
  145. }
  146. }
  147. static bool cs42l73_readable_register(struct device *dev, unsigned int reg)
  148. {
  149. switch (reg) {
  150. case CS42L73_DEVID_AB:
  151. case CS42L73_DEVID_CD:
  152. case CS42L73_DEVID_E:
  153. case CS42L73_REVID:
  154. case CS42L73_PWRCTL1:
  155. case CS42L73_PWRCTL2:
  156. case CS42L73_PWRCTL3:
  157. case CS42L73_CPFCHC:
  158. case CS42L73_OLMBMSDC:
  159. case CS42L73_DMMCC:
  160. case CS42L73_XSPC:
  161. case CS42L73_XSPMMCC:
  162. case CS42L73_ASPC:
  163. case CS42L73_ASPMMCC:
  164. case CS42L73_VSPC:
  165. case CS42L73_VSPMMCC:
  166. case CS42L73_VXSPFS:
  167. case CS42L73_MIOPC:
  168. case CS42L73_ADCIPC:
  169. case CS42L73_MICAPREPGAAVOL:
  170. case CS42L73_MICBPREPGABVOL:
  171. case CS42L73_IPADVOL:
  172. case CS42L73_IPBDVOL:
  173. case CS42L73_PBDC:
  174. case CS42L73_HLADVOL:
  175. case CS42L73_HLBDVOL:
  176. case CS42L73_SPKDVOL:
  177. case CS42L73_ESLDVOL:
  178. case CS42L73_HPAAVOL:
  179. case CS42L73_HPBAVOL:
  180. case CS42L73_LOAAVOL:
  181. case CS42L73_LOBAVOL:
  182. case CS42L73_STRINV:
  183. case CS42L73_XSPINV:
  184. case CS42L73_ASPINV:
  185. case CS42L73_VSPINV:
  186. case CS42L73_LIMARATEHL:
  187. case CS42L73_LIMRRATEHL:
  188. case CS42L73_LMAXHL:
  189. case CS42L73_LIMARATESPK:
  190. case CS42L73_LIMRRATESPK:
  191. case CS42L73_LMAXSPK:
  192. case CS42L73_LIMARATEESL:
  193. case CS42L73_LIMRRATEESL:
  194. case CS42L73_LMAXESL:
  195. case CS42L73_ALCARATE:
  196. case CS42L73_ALCRRATE:
  197. case CS42L73_ALCMINMAX:
  198. case CS42L73_NGCAB:
  199. case CS42L73_ALCNGMC:
  200. case CS42L73_MIXERCTL:
  201. case CS42L73_HLAIPAA:
  202. case CS42L73_HLBIPBA:
  203. case CS42L73_HLAXSPAA:
  204. case CS42L73_HLBXSPBA:
  205. case CS42L73_HLAASPAA:
  206. case CS42L73_HLBASPBA:
  207. case CS42L73_HLAVSPMA:
  208. case CS42L73_HLBVSPMA:
  209. case CS42L73_XSPAIPAA:
  210. case CS42L73_XSPBIPBA:
  211. case CS42L73_XSPAXSPAA:
  212. case CS42L73_XSPBXSPBA:
  213. case CS42L73_XSPAASPAA:
  214. case CS42L73_XSPAASPBA:
  215. case CS42L73_XSPAVSPMA:
  216. case CS42L73_XSPBVSPMA:
  217. case CS42L73_ASPAIPAA:
  218. case CS42L73_ASPBIPBA:
  219. case CS42L73_ASPAXSPAA:
  220. case CS42L73_ASPBXSPBA:
  221. case CS42L73_ASPAASPAA:
  222. case CS42L73_ASPBASPBA:
  223. case CS42L73_ASPAVSPMA:
  224. case CS42L73_ASPBVSPMA:
  225. case CS42L73_VSPAIPAA:
  226. case CS42L73_VSPBIPBA:
  227. case CS42L73_VSPAXSPAA:
  228. case CS42L73_VSPBXSPBA:
  229. case CS42L73_VSPAASPAA:
  230. case CS42L73_VSPBASPBA:
  231. case CS42L73_VSPAVSPMA:
  232. case CS42L73_VSPBVSPMA:
  233. case CS42L73_MMIXCTL:
  234. case CS42L73_SPKMIPMA:
  235. case CS42L73_SPKMXSPA:
  236. case CS42L73_SPKMASPA:
  237. case CS42L73_SPKMVSPMA:
  238. case CS42L73_ESLMIPMA:
  239. case CS42L73_ESLMXSPA:
  240. case CS42L73_ESLMASPA:
  241. case CS42L73_ESLMVSPMA:
  242. case CS42L73_IM1:
  243. case CS42L73_IM2:
  244. return true;
  245. default:
  246. return false;
  247. }
  248. }
  249. static const unsigned int hpaloa_tlv[] = {
  250. TLV_DB_RANGE_HEAD(2),
  251. 0, 13, TLV_DB_SCALE_ITEM(-7600, 200, 0),
  252. 14, 75, TLV_DB_SCALE_ITEM(-4900, 100, 0),
  253. };
  254. static DECLARE_TLV_DB_SCALE(adc_boost_tlv, 0, 2500, 0);
  255. static DECLARE_TLV_DB_SCALE(hl_tlv, -10200, 50, 0);
  256. static DECLARE_TLV_DB_SCALE(ipd_tlv, -9600, 100, 0);
  257. static DECLARE_TLV_DB_SCALE(micpga_tlv, -600, 50, 0);
  258. static const unsigned int limiter_tlv[] = {
  259. TLV_DB_RANGE_HEAD(2),
  260. 0, 2, TLV_DB_SCALE_ITEM(-3000, 600, 0),
  261. 3, 7, TLV_DB_SCALE_ITEM(-1200, 300, 0),
  262. };
  263. static const DECLARE_TLV_DB_SCALE(attn_tlv, -6300, 100, 1);
  264. static const char * const cs42l73_pgaa_text[] = { "Line A", "Mic 1" };
  265. static const char * const cs42l73_pgab_text[] = { "Line B", "Mic 2" };
  266. static const struct soc_enum pgaa_enum =
  267. SOC_ENUM_SINGLE(CS42L73_ADCIPC, 3,
  268. ARRAY_SIZE(cs42l73_pgaa_text), cs42l73_pgaa_text);
  269. static const struct soc_enum pgab_enum =
  270. SOC_ENUM_SINGLE(CS42L73_ADCIPC, 7,
  271. ARRAY_SIZE(cs42l73_pgab_text), cs42l73_pgab_text);
  272. static const struct snd_kcontrol_new pgaa_mux =
  273. SOC_DAPM_ENUM("Left Analog Input Capture Mux", pgaa_enum);
  274. static const struct snd_kcontrol_new pgab_mux =
  275. SOC_DAPM_ENUM("Right Analog Input Capture Mux", pgab_enum);
  276. static const struct snd_kcontrol_new input_left_mixer[] = {
  277. SOC_DAPM_SINGLE("ADC Left Input", CS42L73_PWRCTL1,
  278. 5, 1, 1),
  279. SOC_DAPM_SINGLE("DMIC Left Input", CS42L73_PWRCTL1,
  280. 4, 1, 1),
  281. };
  282. static const struct snd_kcontrol_new input_right_mixer[] = {
  283. SOC_DAPM_SINGLE("ADC Right Input", CS42L73_PWRCTL1,
  284. 7, 1, 1),
  285. SOC_DAPM_SINGLE("DMIC Right Input", CS42L73_PWRCTL1,
  286. 6, 1, 1),
  287. };
  288. static const char * const cs42l73_ng_delay_text[] = {
  289. "50ms", "100ms", "150ms", "200ms" };
  290. static const struct soc_enum ng_delay_enum =
  291. SOC_ENUM_SINGLE(CS42L73_NGCAB, 0,
  292. ARRAY_SIZE(cs42l73_ng_delay_text), cs42l73_ng_delay_text);
  293. static const char * const charge_pump_freq_text[] = {
  294. "0", "1", "2", "3", "4",
  295. "5", "6", "7", "8", "9",
  296. "10", "11", "12", "13", "14", "15" };
  297. static const struct soc_enum charge_pump_enum =
  298. SOC_ENUM_SINGLE(CS42L73_CPFCHC, 4,
  299. ARRAY_SIZE(charge_pump_freq_text), charge_pump_freq_text);
  300. static const char * const cs42l73_mono_mix_texts[] = {
  301. "Left", "Right", "Mono Mix"};
  302. static const unsigned int cs42l73_mono_mix_values[] = { 0, 1, 2 };
  303. static const struct soc_enum spk_asp_enum =
  304. SOC_VALUE_ENUM_SINGLE(CS42L73_MMIXCTL, 6, 3,
  305. ARRAY_SIZE(cs42l73_mono_mix_texts),
  306. cs42l73_mono_mix_texts,
  307. cs42l73_mono_mix_values);
  308. static const struct snd_kcontrol_new spk_asp_mixer =
  309. SOC_DAPM_ENUM("Route", spk_asp_enum);
  310. static const struct soc_enum spk_xsp_enum =
  311. SOC_VALUE_ENUM_SINGLE(CS42L73_MMIXCTL, 4, 3,
  312. ARRAY_SIZE(cs42l73_mono_mix_texts),
  313. cs42l73_mono_mix_texts,
  314. cs42l73_mono_mix_values);
  315. static const struct snd_kcontrol_new spk_xsp_mixer =
  316. SOC_DAPM_ENUM("Route", spk_xsp_enum);
  317. static const struct soc_enum esl_asp_enum =
  318. SOC_VALUE_ENUM_SINGLE(CS42L73_MMIXCTL, 2, 3,
  319. ARRAY_SIZE(cs42l73_mono_mix_texts),
  320. cs42l73_mono_mix_texts,
  321. cs42l73_mono_mix_values);
  322. static const struct snd_kcontrol_new esl_asp_mixer =
  323. SOC_DAPM_ENUM("Route", esl_asp_enum);
  324. static const struct soc_enum esl_xsp_enum =
  325. SOC_VALUE_ENUM_SINGLE(CS42L73_MMIXCTL, 0, 3,
  326. ARRAY_SIZE(cs42l73_mono_mix_texts),
  327. cs42l73_mono_mix_texts,
  328. cs42l73_mono_mix_values);
  329. static const struct snd_kcontrol_new esl_xsp_mixer =
  330. SOC_DAPM_ENUM("Route", esl_xsp_enum);
  331. static const char * const cs42l73_ip_swap_text[] = {
  332. "Stereo", "Mono A", "Mono B", "Swap A-B"};
  333. static const struct soc_enum ip_swap_enum =
  334. SOC_ENUM_SINGLE(CS42L73_MIOPC, 6,
  335. ARRAY_SIZE(cs42l73_ip_swap_text), cs42l73_ip_swap_text);
  336. static const char * const cs42l73_spo_mixer_text[] = {"Mono", "Stereo"};
  337. static const struct soc_enum vsp_output_mux_enum =
  338. SOC_ENUM_SINGLE(CS42L73_MIXERCTL, 5,
  339. ARRAY_SIZE(cs42l73_spo_mixer_text), cs42l73_spo_mixer_text);
  340. static const struct soc_enum xsp_output_mux_enum =
  341. SOC_ENUM_SINGLE(CS42L73_MIXERCTL, 4,
  342. ARRAY_SIZE(cs42l73_spo_mixer_text), cs42l73_spo_mixer_text);
  343. static const struct snd_kcontrol_new vsp_output_mux =
  344. SOC_DAPM_ENUM("Route", vsp_output_mux_enum);
  345. static const struct snd_kcontrol_new xsp_output_mux =
  346. SOC_DAPM_ENUM("Route", xsp_output_mux_enum);
  347. static const struct snd_kcontrol_new hp_amp_ctl =
  348. SOC_DAPM_SINGLE("Switch", CS42L73_PWRCTL3, 0, 1, 1);
  349. static const struct snd_kcontrol_new lo_amp_ctl =
  350. SOC_DAPM_SINGLE("Switch", CS42L73_PWRCTL3, 1, 1, 1);
  351. static const struct snd_kcontrol_new spk_amp_ctl =
  352. SOC_DAPM_SINGLE("Switch", CS42L73_PWRCTL3, 2, 1, 1);
  353. static const struct snd_kcontrol_new spklo_amp_ctl =
  354. SOC_DAPM_SINGLE("Switch", CS42L73_PWRCTL3, 4, 1, 1);
  355. static const struct snd_kcontrol_new ear_amp_ctl =
  356. SOC_DAPM_SINGLE("Switch", CS42L73_PWRCTL3, 3, 1, 1);
  357. static const struct snd_kcontrol_new cs42l73_snd_controls[] = {
  358. SOC_DOUBLE_R_SX_TLV("Headphone Analog Playback Volume",
  359. CS42L73_HPAAVOL, CS42L73_HPBAVOL, 7,
  360. 0xffffffC1, 0x0C, hpaloa_tlv),
  361. SOC_DOUBLE_R_SX_TLV("LineOut Analog Playback Volume", CS42L73_LOAAVOL,
  362. CS42L73_LOBAVOL, 7, 0xffffffC1, 0x0C, hpaloa_tlv),
  363. SOC_DOUBLE_R_SX_TLV("Input PGA Analog Volume", CS42L73_MICAPREPGAAVOL,
  364. CS42L73_MICBPREPGABVOL, 5, 0xffffff35,
  365. 0x34, micpga_tlv),
  366. SOC_DOUBLE_R("MIC Preamp Switch", CS42L73_MICAPREPGAAVOL,
  367. CS42L73_MICBPREPGABVOL, 6, 1, 1),
  368. SOC_DOUBLE_R_SX_TLV("Input Path Digital Volume", CS42L73_IPADVOL,
  369. CS42L73_IPBDVOL, 7, 0xffffffA0, 0xA0, ipd_tlv),
  370. SOC_DOUBLE_R_SX_TLV("HL Digital Playback Volume",
  371. CS42L73_HLADVOL, CS42L73_HLBDVOL, 7, 0xffffffE5,
  372. 0xE4, hl_tlv),
  373. SOC_SINGLE_TLV("ADC A Boost Volume",
  374. CS42L73_ADCIPC, 2, 0x01, 1, adc_boost_tlv),
  375. SOC_SINGLE_TLV("ADC B Boost Volume",
  376. CS42L73_ADCIPC, 6, 0x01, 1, adc_boost_tlv),
  377. SOC_SINGLE_TLV("Speakerphone Digital Playback Volume",
  378. CS42L73_SPKDVOL, 0, 0xE4, 1, hl_tlv),
  379. SOC_SINGLE_TLV("Ear Speaker Digital Playback Volume",
  380. CS42L73_ESLDVOL, 0, 0xE4, 1, hl_tlv),
  381. SOC_DOUBLE_R("Headphone Analog Playback Switch", CS42L73_HPAAVOL,
  382. CS42L73_HPBAVOL, 7, 1, 1),
  383. SOC_DOUBLE_R("LineOut Analog Playback Switch", CS42L73_LOAAVOL,
  384. CS42L73_LOBAVOL, 7, 1, 1),
  385. SOC_DOUBLE("Input Path Digital Switch", CS42L73_ADCIPC, 0, 4, 1, 1),
  386. SOC_DOUBLE("HL Digital Playback Switch", CS42L73_PBDC, 0,
  387. 1, 1, 1),
  388. SOC_SINGLE("Speakerphone Digital Playback Switch", CS42L73_PBDC, 2, 1,
  389. 1),
  390. SOC_SINGLE("Ear Speaker Digital Playback Switch", CS42L73_PBDC, 3, 1,
  391. 1),
  392. SOC_SINGLE("PGA Soft-Ramp Switch", CS42L73_MIOPC, 3, 1, 0),
  393. SOC_SINGLE("Analog Zero Cross Switch", CS42L73_MIOPC, 2, 1, 0),
  394. SOC_SINGLE("Digital Soft-Ramp Switch", CS42L73_MIOPC, 1, 1, 0),
  395. SOC_SINGLE("Analog Output Soft-Ramp Switch", CS42L73_MIOPC, 0, 1, 0),
  396. SOC_DOUBLE("ADC Signal Polarity Switch", CS42L73_ADCIPC, 1, 5, 1,
  397. 0),
  398. SOC_SINGLE("HL Limiter Attack Rate", CS42L73_LIMARATEHL, 0, 0x3F,
  399. 0),
  400. SOC_SINGLE("HL Limiter Release Rate", CS42L73_LIMRRATEHL, 0,
  401. 0x3F, 0),
  402. SOC_SINGLE("HL Limiter Switch", CS42L73_LIMRRATEHL, 7, 1, 0),
  403. SOC_SINGLE("HL Limiter All Channels Switch", CS42L73_LIMRRATEHL, 6, 1,
  404. 0),
  405. SOC_SINGLE_TLV("HL Limiter Max Threshold Volume", CS42L73_LMAXHL, 5, 7,
  406. 1, limiter_tlv),
  407. SOC_SINGLE_TLV("HL Limiter Cushion Volume", CS42L73_LMAXHL, 2, 7, 1,
  408. limiter_tlv),
  409. SOC_SINGLE("SPK Limiter Attack Rate Volume", CS42L73_LIMARATESPK, 0,
  410. 0x3F, 0),
  411. SOC_SINGLE("SPK Limiter Release Rate Volume", CS42L73_LIMRRATESPK, 0,
  412. 0x3F, 0),
  413. SOC_SINGLE("SPK Limiter Switch", CS42L73_LIMRRATESPK, 7, 1, 0),
  414. SOC_SINGLE("SPK Limiter All Channels Switch", CS42L73_LIMRRATESPK,
  415. 6, 1, 0),
  416. SOC_SINGLE_TLV("SPK Limiter Max Threshold Volume", CS42L73_LMAXSPK, 5,
  417. 7, 1, limiter_tlv),
  418. SOC_SINGLE_TLV("SPK Limiter Cushion Volume", CS42L73_LMAXSPK, 2, 7, 1,
  419. limiter_tlv),
  420. SOC_SINGLE("ESL Limiter Attack Rate Volume", CS42L73_LIMARATEESL, 0,
  421. 0x3F, 0),
  422. SOC_SINGLE("ESL Limiter Release Rate Volume", CS42L73_LIMRRATEESL, 0,
  423. 0x3F, 0),
  424. SOC_SINGLE("ESL Limiter Switch", CS42L73_LIMRRATEESL, 7, 1, 0),
  425. SOC_SINGLE_TLV("ESL Limiter Max Threshold Volume", CS42L73_LMAXESL, 5,
  426. 7, 1, limiter_tlv),
  427. SOC_SINGLE_TLV("ESL Limiter Cushion Volume", CS42L73_LMAXESL, 2, 7, 1,
  428. limiter_tlv),
  429. SOC_SINGLE("ALC Attack Rate Volume", CS42L73_ALCARATE, 0, 0x3F, 0),
  430. SOC_SINGLE("ALC Release Rate Volume", CS42L73_ALCRRATE, 0, 0x3F, 0),
  431. SOC_DOUBLE("ALC Switch", CS42L73_ALCARATE, 6, 7, 1, 0),
  432. SOC_SINGLE_TLV("ALC Max Threshold Volume", CS42L73_ALCMINMAX, 5, 7, 0,
  433. limiter_tlv),
  434. SOC_SINGLE_TLV("ALC Min Threshold Volume", CS42L73_ALCMINMAX, 2, 7, 0,
  435. limiter_tlv),
  436. SOC_DOUBLE("NG Enable Switch", CS42L73_NGCAB, 6, 7, 1, 0),
  437. SOC_SINGLE("NG Boost Switch", CS42L73_NGCAB, 5, 1, 0),
  438. /*
  439. NG Threshold depends on NG_BOOTSAB, which selects
  440. between two threshold scales in decibels.
  441. Set linear values for now ..
  442. */
  443. SOC_SINGLE("NG Threshold", CS42L73_NGCAB, 2, 7, 0),
  444. SOC_ENUM("NG Delay", ng_delay_enum),
  445. SOC_ENUM("Charge Pump Frequency", charge_pump_enum),
  446. SOC_DOUBLE_R_TLV("XSP-IP Volume",
  447. CS42L73_XSPAIPAA, CS42L73_XSPBIPBA, 0, 0x3F, 1,
  448. attn_tlv),
  449. SOC_DOUBLE_R_TLV("XSP-XSP Volume",
  450. CS42L73_XSPAXSPAA, CS42L73_XSPBXSPBA, 0, 0x3F, 1,
  451. attn_tlv),
  452. SOC_DOUBLE_R_TLV("XSP-ASP Volume",
  453. CS42L73_XSPAASPAA, CS42L73_XSPAASPBA, 0, 0x3F, 1,
  454. attn_tlv),
  455. SOC_DOUBLE_R_TLV("XSP-VSP Volume",
  456. CS42L73_XSPAVSPMA, CS42L73_XSPBVSPMA, 0, 0x3F, 1,
  457. attn_tlv),
  458. SOC_DOUBLE_R_TLV("ASP-IP Volume",
  459. CS42L73_ASPAIPAA, CS42L73_ASPBIPBA, 0, 0x3F, 1,
  460. attn_tlv),
  461. SOC_DOUBLE_R_TLV("ASP-XSP Volume",
  462. CS42L73_ASPAXSPAA, CS42L73_ASPBXSPBA, 0, 0x3F, 1,
  463. attn_tlv),
  464. SOC_DOUBLE_R_TLV("ASP-ASP Volume",
  465. CS42L73_ASPAASPAA, CS42L73_ASPBASPBA, 0, 0x3F, 1,
  466. attn_tlv),
  467. SOC_DOUBLE_R_TLV("ASP-VSP Volume",
  468. CS42L73_ASPAVSPMA, CS42L73_ASPBVSPMA, 0, 0x3F, 1,
  469. attn_tlv),
  470. SOC_DOUBLE_R_TLV("VSP-IP Volume",
  471. CS42L73_VSPAIPAA, CS42L73_VSPBIPBA, 0, 0x3F, 1,
  472. attn_tlv),
  473. SOC_DOUBLE_R_TLV("VSP-XSP Volume",
  474. CS42L73_VSPAXSPAA, CS42L73_VSPBXSPBA, 0, 0x3F, 1,
  475. attn_tlv),
  476. SOC_DOUBLE_R_TLV("VSP-ASP Volume",
  477. CS42L73_VSPAASPAA, CS42L73_VSPBASPBA, 0, 0x3F, 1,
  478. attn_tlv),
  479. SOC_DOUBLE_R_TLV("VSP-VSP Volume",
  480. CS42L73_VSPAVSPMA, CS42L73_VSPBVSPMA, 0, 0x3F, 1,
  481. attn_tlv),
  482. SOC_DOUBLE_R_TLV("HL-IP Volume",
  483. CS42L73_HLAIPAA, CS42L73_HLBIPBA, 0, 0x3F, 1,
  484. attn_tlv),
  485. SOC_DOUBLE_R_TLV("HL-XSP Volume",
  486. CS42L73_HLAXSPAA, CS42L73_HLBXSPBA, 0, 0x3F, 1,
  487. attn_tlv),
  488. SOC_DOUBLE_R_TLV("HL-ASP Volume",
  489. CS42L73_HLAASPAA, CS42L73_HLBASPBA, 0, 0x3F, 1,
  490. attn_tlv),
  491. SOC_DOUBLE_R_TLV("HL-VSP Volume",
  492. CS42L73_HLAVSPMA, CS42L73_HLBVSPMA, 0, 0x3F, 1,
  493. attn_tlv),
  494. SOC_SINGLE_TLV("SPK-IP Mono Volume",
  495. CS42L73_SPKMIPMA, 0, 0x3F, 1, attn_tlv),
  496. SOC_SINGLE_TLV("SPK-XSP Mono Volume",
  497. CS42L73_SPKMXSPA, 0, 0x3F, 1, attn_tlv),
  498. SOC_SINGLE_TLV("SPK-ASP Mono Volume",
  499. CS42L73_SPKMASPA, 0, 0x3F, 1, attn_tlv),
  500. SOC_SINGLE_TLV("SPK-VSP Mono Volume",
  501. CS42L73_SPKMVSPMA, 0, 0x3F, 1, attn_tlv),
  502. SOC_SINGLE_TLV("ESL-IP Mono Volume",
  503. CS42L73_ESLMIPMA, 0, 0x3F, 1, attn_tlv),
  504. SOC_SINGLE_TLV("ESL-XSP Mono Volume",
  505. CS42L73_ESLMXSPA, 0, 0x3F, 1, attn_tlv),
  506. SOC_SINGLE_TLV("ESL-ASP Mono Volume",
  507. CS42L73_ESLMASPA, 0, 0x3F, 1, attn_tlv),
  508. SOC_SINGLE_TLV("ESL-VSP Mono Volume",
  509. CS42L73_ESLMVSPMA, 0, 0x3F, 1, attn_tlv),
  510. SOC_ENUM("IP Digital Swap/Mono Select", ip_swap_enum),
  511. SOC_ENUM("VSPOUT Mono/Stereo Select", vsp_output_mux_enum),
  512. SOC_ENUM("XSPOUT Mono/Stereo Select", xsp_output_mux_enum),
  513. };
  514. static const struct snd_soc_dapm_widget cs42l73_dapm_widgets[] = {
  515. SND_SOC_DAPM_INPUT("LINEINA"),
  516. SND_SOC_DAPM_INPUT("LINEINB"),
  517. SND_SOC_DAPM_INPUT("MIC1"),
  518. SND_SOC_DAPM_SUPPLY("MIC1 Bias", CS42L73_PWRCTL2, 6, 1, NULL, 0),
  519. SND_SOC_DAPM_INPUT("MIC2"),
  520. SND_SOC_DAPM_SUPPLY("MIC2 Bias", CS42L73_PWRCTL2, 7, 1, NULL, 0),
  521. SND_SOC_DAPM_AIF_OUT("XSPOUTL", "XSP Capture", 0,
  522. CS42L73_PWRCTL2, 1, 1),
  523. SND_SOC_DAPM_AIF_OUT("XSPOUTR", "XSP Capture", 0,
  524. CS42L73_PWRCTL2, 1, 1),
  525. SND_SOC_DAPM_AIF_OUT("ASPOUTL", "ASP Capture", 0,
  526. CS42L73_PWRCTL2, 3, 1),
  527. SND_SOC_DAPM_AIF_OUT("ASPOUTR", "ASP Capture", 0,
  528. CS42L73_PWRCTL2, 3, 1),
  529. SND_SOC_DAPM_AIF_OUT("VSPOUTL", "VSP Capture", 0,
  530. CS42L73_PWRCTL2, 4, 1),
  531. SND_SOC_DAPM_AIF_OUT("VSPOUTR", "VSP Capture", 0,
  532. CS42L73_PWRCTL2, 4, 1),
  533. SND_SOC_DAPM_PGA("PGA Left", SND_SOC_NOPM, 0, 0, NULL, 0),
  534. SND_SOC_DAPM_PGA("PGA Right", SND_SOC_NOPM, 0, 0, NULL, 0),
  535. SND_SOC_DAPM_MUX("PGA Left Mux", SND_SOC_NOPM, 0, 0, &pgaa_mux),
  536. SND_SOC_DAPM_MUX("PGA Right Mux", SND_SOC_NOPM, 0, 0, &pgab_mux),
  537. SND_SOC_DAPM_ADC("ADC Left", NULL, CS42L73_PWRCTL1, 7, 1),
  538. SND_SOC_DAPM_ADC("ADC Right", NULL, CS42L73_PWRCTL1, 5, 1),
  539. SND_SOC_DAPM_ADC("DMIC Left", NULL, CS42L73_PWRCTL1, 6, 1),
  540. SND_SOC_DAPM_ADC("DMIC Right", NULL, CS42L73_PWRCTL1, 4, 1),
  541. SND_SOC_DAPM_MIXER_NAMED_CTL("Input Left Capture", SND_SOC_NOPM,
  542. 0, 0, input_left_mixer,
  543. ARRAY_SIZE(input_left_mixer)),
  544. SND_SOC_DAPM_MIXER_NAMED_CTL("Input Right Capture", SND_SOC_NOPM,
  545. 0, 0, input_right_mixer,
  546. ARRAY_SIZE(input_right_mixer)),
  547. SND_SOC_DAPM_MIXER("ASPL Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
  548. SND_SOC_DAPM_MIXER("ASPR Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
  549. SND_SOC_DAPM_MIXER("XSPL Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
  550. SND_SOC_DAPM_MIXER("XSPR Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
  551. SND_SOC_DAPM_MIXER("VSPL Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
  552. SND_SOC_DAPM_MIXER("VSPR Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
  553. SND_SOC_DAPM_AIF_IN("XSPINL", "XSP Playback", 0,
  554. CS42L73_PWRCTL2, 0, 1),
  555. SND_SOC_DAPM_AIF_IN("XSPINR", "XSP Playback", 0,
  556. CS42L73_PWRCTL2, 0, 1),
  557. SND_SOC_DAPM_AIF_IN("XSPINM", "XSP Playback", 0,
  558. CS42L73_PWRCTL2, 0, 1),
  559. SND_SOC_DAPM_AIF_IN("ASPINL", "ASP Playback", 0,
  560. CS42L73_PWRCTL2, 2, 1),
  561. SND_SOC_DAPM_AIF_IN("ASPINR", "ASP Playback", 0,
  562. CS42L73_PWRCTL2, 2, 1),
  563. SND_SOC_DAPM_AIF_IN("ASPINM", "ASP Playback", 0,
  564. CS42L73_PWRCTL2, 2, 1),
  565. SND_SOC_DAPM_AIF_IN("VSPIN", "VSP Playback", 0,
  566. CS42L73_PWRCTL2, 4, 1),
  567. SND_SOC_DAPM_MIXER("HL Left Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
  568. SND_SOC_DAPM_MIXER("HL Right Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
  569. SND_SOC_DAPM_MIXER("SPK Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
  570. SND_SOC_DAPM_MIXER("ESL Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
  571. SND_SOC_DAPM_MUX("ESL-XSP Mux", SND_SOC_NOPM,
  572. 0, 0, &esl_xsp_mixer),
  573. SND_SOC_DAPM_MUX("ESL-ASP Mux", SND_SOC_NOPM,
  574. 0, 0, &esl_asp_mixer),
  575. SND_SOC_DAPM_MUX("SPK-ASP Mux", SND_SOC_NOPM,
  576. 0, 0, &spk_asp_mixer),
  577. SND_SOC_DAPM_MUX("SPK-XSP Mux", SND_SOC_NOPM,
  578. 0, 0, &spk_xsp_mixer),
  579. SND_SOC_DAPM_PGA("HL Left DAC", SND_SOC_NOPM, 0, 0, NULL, 0),
  580. SND_SOC_DAPM_PGA("HL Right DAC", SND_SOC_NOPM, 0, 0, NULL, 0),
  581. SND_SOC_DAPM_PGA("SPK DAC", SND_SOC_NOPM, 0, 0, NULL, 0),
  582. SND_SOC_DAPM_PGA("ESL DAC", SND_SOC_NOPM, 0, 0, NULL, 0),
  583. SND_SOC_DAPM_SWITCH("HP Amp", CS42L73_PWRCTL3, 0, 1,
  584. &hp_amp_ctl),
  585. SND_SOC_DAPM_SWITCH("LO Amp", CS42L73_PWRCTL3, 1, 1,
  586. &lo_amp_ctl),
  587. SND_SOC_DAPM_SWITCH("SPK Amp", CS42L73_PWRCTL3, 2, 1,
  588. &spk_amp_ctl),
  589. SND_SOC_DAPM_SWITCH("EAR Amp", CS42L73_PWRCTL3, 3, 1,
  590. &ear_amp_ctl),
  591. SND_SOC_DAPM_SWITCH("SPKLO Amp", CS42L73_PWRCTL3, 4, 1,
  592. &spklo_amp_ctl),
  593. SND_SOC_DAPM_OUTPUT("HPOUTA"),
  594. SND_SOC_DAPM_OUTPUT("HPOUTB"),
  595. SND_SOC_DAPM_OUTPUT("LINEOUTA"),
  596. SND_SOC_DAPM_OUTPUT("LINEOUTB"),
  597. SND_SOC_DAPM_OUTPUT("EAROUT"),
  598. SND_SOC_DAPM_OUTPUT("SPKOUT"),
  599. SND_SOC_DAPM_OUTPUT("SPKLINEOUT"),
  600. };
  601. static const struct snd_soc_dapm_route cs42l73_audio_map[] = {
  602. /* SPKLO EARSPK Paths */
  603. {"EAROUT", NULL, "EAR Amp"},
  604. {"SPKLINEOUT", NULL, "SPKLO Amp"},
  605. {"EAR Amp", "Switch", "ESL DAC"},
  606. {"SPKLO Amp", "Switch", "ESL DAC"},
  607. {"ESL DAC", "ESL-ASP Mono Volume", "ESL Mixer"},
  608. {"ESL DAC", "ESL-XSP Mono Volume", "ESL Mixer"},
  609. {"ESL DAC", "ESL-VSP Mono Volume", "VSPIN"},
  610. /* Loopback */
  611. {"ESL DAC", "ESL-IP Mono Volume", "Input Left Capture"},
  612. {"ESL DAC", "ESL-IP Mono Volume", "Input Right Capture"},
  613. {"ESL Mixer", NULL, "ESL-ASP Mux"},
  614. {"ESL Mixer", NULL, "ESL-XSP Mux"},
  615. {"ESL-ASP Mux", "Left", "ASPINL"},
  616. {"ESL-ASP Mux", "Right", "ASPINR"},
  617. {"ESL-ASP Mux", "Mono Mix", "ASPINM"},
  618. {"ESL-XSP Mux", "Left", "XSPINL"},
  619. {"ESL-XSP Mux", "Right", "XSPINR"},
  620. {"ESL-XSP Mux", "Mono Mix", "XSPINM"},
  621. /* Speakerphone Paths */
  622. {"SPKOUT", NULL, "SPK Amp"},
  623. {"SPK Amp", "Switch", "SPK DAC"},
  624. {"SPK DAC", "SPK-ASP Mono Volume", "SPK Mixer"},
  625. {"SPK DAC", "SPK-XSP Mono Volume", "SPK Mixer"},
  626. {"SPK DAC", "SPK-VSP Mono Volume", "VSPIN"},
  627. /* Loopback */
  628. {"SPK DAC", "SPK-IP Mono Volume", "Input Left Capture"},
  629. {"SPK DAC", "SPK-IP Mono Volume", "Input Right Capture"},
  630. {"SPK Mixer", NULL, "SPK-ASP Mux"},
  631. {"SPK Mixer", NULL, "SPK-XSP Mux"},
  632. {"SPK-ASP Mux", "Left", "ASPINL"},
  633. {"SPK-ASP Mux", "Mono Mix", "ASPINM"},
  634. {"SPK-ASP Mux", "Right", "ASPINR"},
  635. {"SPK-XSP Mux", "Left", "XSPINL"},
  636. {"SPK-XSP Mux", "Mono Mix", "XSPINM"},
  637. {"SPK-XSP Mux", "Right", "XSPINR"},
  638. /* HP LineOUT Paths */
  639. {"HPOUTA", NULL, "HP Amp"},
  640. {"HPOUTB", NULL, "HP Amp"},
  641. {"LINEOUTA", NULL, "LO Amp"},
  642. {"LINEOUTB", NULL, "LO Amp"},
  643. {"HP Amp", "Switch", "HL Left DAC"},
  644. {"HP Amp", "Switch", "HL Right DAC"},
  645. {"LO Amp", "Switch", "HL Left DAC"},
  646. {"LO Amp", "Switch", "HL Right DAC"},
  647. {"HL Left DAC", "HL-XSP Volume", "HL Left Mixer"},
  648. {"HL Right DAC", "HL-XSP Volume", "HL Right Mixer"},
  649. {"HL Left DAC", "HL-ASP Volume", "HL Left Mixer"},
  650. {"HL Right DAC", "HL-ASP Volume", "HL Right Mixer"},
  651. {"HL Left DAC", "HL-VSP Volume", "HL Left Mixer"},
  652. {"HL Right DAC", "HL-VSP Volume", "HL Right Mixer"},
  653. /* Loopback */
  654. {"HL Left DAC", "HL-IP Volume", "HL Left Mixer"},
  655. {"HL Right DAC", "HL-IP Volume", "HL Right Mixer"},
  656. {"HL Left Mixer", NULL, "Input Left Capture"},
  657. {"HL Right Mixer", NULL, "Input Right Capture"},
  658. {"HL Left Mixer", NULL, "ASPINL"},
  659. {"HL Right Mixer", NULL, "ASPINR"},
  660. {"HL Left Mixer", NULL, "XSPINL"},
  661. {"HL Right Mixer", NULL, "XSPINR"},
  662. {"HL Left Mixer", NULL, "VSPIN"},
  663. {"HL Right Mixer", NULL, "VSPIN"},
  664. /* Capture Paths */
  665. {"MIC1", NULL, "MIC1 Bias"},
  666. {"PGA Left Mux", "Mic 1", "MIC1"},
  667. {"MIC2", NULL, "MIC2 Bias"},
  668. {"PGA Right Mux", "Mic 2", "MIC2"},
  669. {"PGA Left Mux", "Line A", "LINEINA"},
  670. {"PGA Right Mux", "Line B", "LINEINB"},
  671. {"PGA Left", NULL, "PGA Left Mux"},
  672. {"PGA Right", NULL, "PGA Right Mux"},
  673. {"ADC Left", NULL, "PGA Left"},
  674. {"ADC Right", NULL, "PGA Right"},
  675. {"Input Left Capture", "ADC Left Input", "ADC Left"},
  676. {"Input Right Capture", "ADC Right Input", "ADC Right"},
  677. {"Input Left Capture", "DMIC Left Input", "DMIC Left"},
  678. {"Input Right Capture", "DMIC Right Input", "DMIC Right"},
  679. /* Audio Capture */
  680. {"ASPL Output Mixer", NULL, "Input Left Capture"},
  681. {"ASPR Output Mixer", NULL, "Input Right Capture"},
  682. {"ASPOUTL", "ASP-IP Volume", "ASPL Output Mixer"},
  683. {"ASPOUTR", "ASP-IP Volume", "ASPR Output Mixer"},
  684. /* Auxillary Capture */
  685. {"XSPL Output Mixer", NULL, "Input Left Capture"},
  686. {"XSPR Output Mixer", NULL, "Input Right Capture"},
  687. {"XSPOUTL", "XSP-IP Volume", "XSPL Output Mixer"},
  688. {"XSPOUTR", "XSP-IP Volume", "XSPR Output Mixer"},
  689. {"XSPOUTL", NULL, "XSPL Output Mixer"},
  690. {"XSPOUTR", NULL, "XSPR Output Mixer"},
  691. /* Voice Capture */
  692. {"VSPL Output Mixer", NULL, "Input Left Capture"},
  693. {"VSPR Output Mixer", NULL, "Input Left Capture"},
  694. {"VSPOUTL", "VSP-IP Volume", "VSPL Output Mixer"},
  695. {"VSPOUTR", "VSP-IP Volume", "VSPR Output Mixer"},
  696. {"VSPOUTL", NULL, "VSPL Output Mixer"},
  697. {"VSPOUTR", NULL, "VSPR Output Mixer"},
  698. };
  699. struct cs42l73_mclk_div {
  700. u32 mclk;
  701. u32 srate;
  702. u8 mmcc;
  703. };
  704. static struct cs42l73_mclk_div cs42l73_mclk_coeffs[] = {
  705. /* MCLK, Sample Rate, xMMCC[5:0] */
  706. {5644800, 11025, 0x30},
  707. {5644800, 22050, 0x20},
  708. {5644800, 44100, 0x10},
  709. {6000000, 8000, 0x39},
  710. {6000000, 11025, 0x33},
  711. {6000000, 12000, 0x31},
  712. {6000000, 16000, 0x29},
  713. {6000000, 22050, 0x23},
  714. {6000000, 24000, 0x21},
  715. {6000000, 32000, 0x19},
  716. {6000000, 44100, 0x13},
  717. {6000000, 48000, 0x11},
  718. {6144000, 8000, 0x38},
  719. {6144000, 12000, 0x30},
  720. {6144000, 16000, 0x28},
  721. {6144000, 24000, 0x20},
  722. {6144000, 32000, 0x18},
  723. {6144000, 48000, 0x10},
  724. {6500000, 8000, 0x3C},
  725. {6500000, 11025, 0x35},
  726. {6500000, 12000, 0x34},
  727. {6500000, 16000, 0x2C},
  728. {6500000, 22050, 0x25},
  729. {6500000, 24000, 0x24},
  730. {6500000, 32000, 0x1C},
  731. {6500000, 44100, 0x15},
  732. {6500000, 48000, 0x14},
  733. {6400000, 8000, 0x3E},
  734. {6400000, 11025, 0x37},
  735. {6400000, 12000, 0x36},
  736. {6400000, 16000, 0x2E},
  737. {6400000, 22050, 0x27},
  738. {6400000, 24000, 0x26},
  739. {6400000, 32000, 0x1E},
  740. {6400000, 44100, 0x17},
  741. {6400000, 48000, 0x16},
  742. };
  743. struct cs42l73_mclkx_div {
  744. u32 mclkx;
  745. u8 ratio;
  746. u8 mclkdiv;
  747. };
  748. static struct cs42l73_mclkx_div cs42l73_mclkx_coeffs[] = {
  749. {5644800, 1, 0}, /* 5644800 */
  750. {6000000, 1, 0}, /* 6000000 */
  751. {6144000, 1, 0}, /* 6144000 */
  752. {11289600, 2, 2}, /* 5644800 */
  753. {12288000, 2, 2}, /* 6144000 */
  754. {12000000, 2, 2}, /* 6000000 */
  755. {13000000, 2, 2}, /* 6500000 */
  756. {19200000, 3, 3}, /* 6400000 */
  757. {24000000, 4, 4}, /* 6000000 */
  758. {26000000, 4, 4}, /* 6500000 */
  759. {38400000, 6, 5} /* 6400000 */
  760. };
  761. static int cs42l73_get_mclkx_coeff(int mclkx)
  762. {
  763. int i;
  764. for (i = 0; i < ARRAY_SIZE(cs42l73_mclkx_coeffs); i++) {
  765. if (cs42l73_mclkx_coeffs[i].mclkx == mclkx)
  766. return i;
  767. }
  768. return -EINVAL;
  769. }
  770. static int cs42l73_get_mclk_coeff(int mclk, int srate)
  771. {
  772. int i;
  773. for (i = 0; i < ARRAY_SIZE(cs42l73_mclk_coeffs); i++) {
  774. if (cs42l73_mclk_coeffs[i].mclk == mclk &&
  775. cs42l73_mclk_coeffs[i].srate == srate)
  776. return i;
  777. }
  778. return -EINVAL;
  779. }
  780. static int cs42l73_set_mclk(struct snd_soc_dai *dai, unsigned int freq)
  781. {
  782. struct snd_soc_codec *codec = dai->codec;
  783. struct cs42l73_private *priv = snd_soc_codec_get_drvdata(codec);
  784. int mclkx_coeff;
  785. u32 mclk = 0;
  786. u8 dmmcc = 0;
  787. /* MCLKX -> MCLK */
  788. mclkx_coeff = cs42l73_get_mclkx_coeff(freq);
  789. if (mclkx_coeff < 0)
  790. return mclkx_coeff;
  791. mclk = cs42l73_mclkx_coeffs[mclkx_coeff].mclkx /
  792. cs42l73_mclkx_coeffs[mclkx_coeff].ratio;
  793. dev_dbg(codec->dev, "MCLK%u %u <-> internal MCLK %u\n",
  794. priv->mclksel + 1, cs42l73_mclkx_coeffs[mclkx_coeff].mclkx,
  795. mclk);
  796. dmmcc = (priv->mclksel << 4) |
  797. (cs42l73_mclkx_coeffs[mclkx_coeff].mclkdiv << 1);
  798. snd_soc_write(codec, CS42L73_DMMCC, dmmcc);
  799. priv->sysclk = mclkx_coeff;
  800. priv->mclk = mclk;
  801. return 0;
  802. }
  803. static int cs42l73_set_sysclk(struct snd_soc_dai *dai,
  804. int clk_id, unsigned int freq, int dir)
  805. {
  806. struct snd_soc_codec *codec = dai->codec;
  807. struct cs42l73_private *priv = snd_soc_codec_get_drvdata(codec);
  808. switch (clk_id) {
  809. case CS42L73_CLKID_MCLK1:
  810. break;
  811. case CS42L73_CLKID_MCLK2:
  812. break;
  813. default:
  814. return -EINVAL;
  815. }
  816. if ((cs42l73_set_mclk(dai, freq)) < 0) {
  817. dev_err(codec->dev, "Unable to set MCLK for dai %s\n",
  818. dai->name);
  819. return -EINVAL;
  820. }
  821. priv->mclksel = clk_id;
  822. return 0;
  823. }
  824. static int cs42l73_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
  825. {
  826. struct snd_soc_codec *codec = codec_dai->codec;
  827. struct cs42l73_private *priv = snd_soc_codec_get_drvdata(codec);
  828. u8 id = codec_dai->id;
  829. unsigned int inv, format;
  830. u8 spc, mmcc;
  831. spc = snd_soc_read(codec, CS42L73_SPC(id));
  832. mmcc = snd_soc_read(codec, CS42L73_MMCC(id));
  833. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  834. case SND_SOC_DAIFMT_CBM_CFM:
  835. mmcc |= MS_MASTER;
  836. break;
  837. case SND_SOC_DAIFMT_CBS_CFS:
  838. mmcc &= ~MS_MASTER;
  839. break;
  840. default:
  841. return -EINVAL;
  842. }
  843. format = (fmt & SND_SOC_DAIFMT_FORMAT_MASK);
  844. inv = (fmt & SND_SOC_DAIFMT_INV_MASK);
  845. switch (format) {
  846. case SND_SOC_DAIFMT_I2S:
  847. spc &= ~SPDIF_PCM;
  848. break;
  849. case SND_SOC_DAIFMT_DSP_A:
  850. case SND_SOC_DAIFMT_DSP_B:
  851. if (mmcc & MS_MASTER) {
  852. dev_err(codec->dev,
  853. "PCM format in slave mode only\n");
  854. return -EINVAL;
  855. }
  856. if (id == CS42L73_ASP) {
  857. dev_err(codec->dev,
  858. "PCM format is not supported on ASP port\n");
  859. return -EINVAL;
  860. }
  861. spc |= SPDIF_PCM;
  862. break;
  863. default:
  864. return -EINVAL;
  865. }
  866. if (spc & SPDIF_PCM) {
  867. /* Clear PCM mode, clear PCM_BIT_ORDER bit for MSB->LSB */
  868. spc &= ~(PCM_MODE_MASK | PCM_BIT_ORDER);
  869. switch (format) {
  870. case SND_SOC_DAIFMT_DSP_B:
  871. if (inv == SND_SOC_DAIFMT_IB_IF)
  872. spc |= PCM_MODE0;
  873. if (inv == SND_SOC_DAIFMT_IB_NF)
  874. spc |= PCM_MODE1;
  875. break;
  876. case SND_SOC_DAIFMT_DSP_A:
  877. if (inv == SND_SOC_DAIFMT_IB_IF)
  878. spc |= PCM_MODE1;
  879. break;
  880. default:
  881. return -EINVAL;
  882. }
  883. }
  884. priv->config[id].spc = spc;
  885. priv->config[id].mmcc = mmcc;
  886. return 0;
  887. }
  888. static u32 cs42l73_asrc_rates[] = {
  889. 8000, 11025, 12000, 16000, 22050,
  890. 24000, 32000, 44100, 48000
  891. };
  892. static unsigned int cs42l73_get_xspfs_coeff(u32 rate)
  893. {
  894. int i;
  895. for (i = 0; i < ARRAY_SIZE(cs42l73_asrc_rates); i++) {
  896. if (cs42l73_asrc_rates[i] == rate)
  897. return i + 1;
  898. }
  899. return 0; /* 0 = Don't know */
  900. }
  901. static void cs42l73_update_asrc(struct snd_soc_codec *codec, int id, int srate)
  902. {
  903. u8 spfs = 0;
  904. if (srate > 0)
  905. spfs = cs42l73_get_xspfs_coeff(srate);
  906. switch (id) {
  907. case CS42L73_XSP:
  908. snd_soc_update_bits(codec, CS42L73_VXSPFS, 0x0f, spfs);
  909. break;
  910. case CS42L73_ASP:
  911. snd_soc_update_bits(codec, CS42L73_ASPC, 0x3c, spfs << 2);
  912. break;
  913. case CS42L73_VSP:
  914. snd_soc_update_bits(codec, CS42L73_VXSPFS, 0xf0, spfs << 4);
  915. break;
  916. default:
  917. break;
  918. }
  919. }
  920. static int cs42l73_pcm_hw_params(struct snd_pcm_substream *substream,
  921. struct snd_pcm_hw_params *params,
  922. struct snd_soc_dai *dai)
  923. {
  924. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  925. struct snd_soc_codec *codec = rtd->codec;
  926. struct cs42l73_private *priv = snd_soc_codec_get_drvdata(codec);
  927. int id = dai->id;
  928. int mclk_coeff;
  929. int srate = params_rate(params);
  930. if (priv->config[id].mmcc & MS_MASTER) {
  931. /* CS42L73 Master */
  932. /* MCLK -> srate */
  933. mclk_coeff =
  934. cs42l73_get_mclk_coeff(priv->mclk, srate);
  935. if (mclk_coeff < 0)
  936. return -EINVAL;
  937. dev_dbg(codec->dev,
  938. "DAI[%d]: MCLK %u, srate %u, MMCC[5:0] = %x\n",
  939. id, priv->mclk, srate,
  940. cs42l73_mclk_coeffs[mclk_coeff].mmcc);
  941. priv->config[id].mmcc &= 0xC0;
  942. priv->config[id].mmcc |= cs42l73_mclk_coeffs[mclk_coeff].mmcc;
  943. priv->config[id].spc &= 0xFC;
  944. priv->config[id].spc |= MCK_SCLK_MCLK;
  945. } else {
  946. /* CS42L73 Slave */
  947. priv->config[id].spc &= 0xFC;
  948. priv->config[id].spc |= MCK_SCLK_64FS;
  949. }
  950. /* Update ASRCs */
  951. priv->config[id].srate = srate;
  952. snd_soc_write(codec, CS42L73_SPC(id), priv->config[id].spc);
  953. snd_soc_write(codec, CS42L73_MMCC(id), priv->config[id].mmcc);
  954. cs42l73_update_asrc(codec, id, srate);
  955. return 0;
  956. }
  957. static int cs42l73_set_bias_level(struct snd_soc_codec *codec,
  958. enum snd_soc_bias_level level)
  959. {
  960. struct cs42l73_private *cs42l73 = snd_soc_codec_get_drvdata(codec);
  961. switch (level) {
  962. case SND_SOC_BIAS_ON:
  963. snd_soc_update_bits(codec, CS42L73_DMMCC, MCLKDIS, 0);
  964. snd_soc_update_bits(codec, CS42L73_PWRCTL1, PDN, 0);
  965. break;
  966. case SND_SOC_BIAS_PREPARE:
  967. break;
  968. case SND_SOC_BIAS_STANDBY:
  969. if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
  970. regcache_cache_only(cs42l73->regmap, false);
  971. regcache_sync(cs42l73->regmap);
  972. }
  973. snd_soc_update_bits(codec, CS42L73_PWRCTL1, PDN, 1);
  974. break;
  975. case SND_SOC_BIAS_OFF:
  976. snd_soc_update_bits(codec, CS42L73_PWRCTL1, PDN, 1);
  977. snd_soc_update_bits(codec, CS42L73_DMMCC, MCLKDIS, 1);
  978. break;
  979. }
  980. codec->dapm.bias_level = level;
  981. return 0;
  982. }
  983. static int cs42l73_set_tristate(struct snd_soc_dai *dai, int tristate)
  984. {
  985. struct snd_soc_codec *codec = dai->codec;
  986. int id = dai->id;
  987. return snd_soc_update_bits(codec, CS42L73_SPC(id),
  988. 0x7F, tristate << 7);
  989. }
  990. static struct snd_pcm_hw_constraint_list constraints_12_24 = {
  991. .count = ARRAY_SIZE(cs42l73_asrc_rates),
  992. .list = cs42l73_asrc_rates,
  993. };
  994. static int cs42l73_pcm_startup(struct snd_pcm_substream *substream,
  995. struct snd_soc_dai *dai)
  996. {
  997. snd_pcm_hw_constraint_list(substream->runtime, 0,
  998. SNDRV_PCM_HW_PARAM_RATE,
  999. &constraints_12_24);
  1000. return 0;
  1001. }
  1002. /* SNDRV_PCM_RATE_KNOT -> 12000, 24000 Hz, limit with constraint list */
  1003. #define CS42L73_RATES (SNDRV_PCM_RATE_8000_48000 | SNDRV_PCM_RATE_KNOT)
  1004. #define CS42L73_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  1005. SNDRV_PCM_FMTBIT_S24_LE)
  1006. static const struct snd_soc_dai_ops cs42l73_ops = {
  1007. .startup = cs42l73_pcm_startup,
  1008. .hw_params = cs42l73_pcm_hw_params,
  1009. .set_fmt = cs42l73_set_dai_fmt,
  1010. .set_sysclk = cs42l73_set_sysclk,
  1011. .set_tristate = cs42l73_set_tristate,
  1012. };
  1013. static struct snd_soc_dai_driver cs42l73_dai[] = {
  1014. {
  1015. .name = "cs42l73-xsp",
  1016. .id = CS42L73_XSP,
  1017. .playback = {
  1018. .stream_name = "XSP Playback",
  1019. .channels_min = 1,
  1020. .channels_max = 2,
  1021. .rates = CS42L73_RATES,
  1022. .formats = CS42L73_FORMATS,
  1023. },
  1024. .capture = {
  1025. .stream_name = "XSP Capture",
  1026. .channels_min = 1,
  1027. .channels_max = 2,
  1028. .rates = CS42L73_RATES,
  1029. .formats = CS42L73_FORMATS,
  1030. },
  1031. .ops = &cs42l73_ops,
  1032. .symmetric_rates = 1,
  1033. },
  1034. {
  1035. .name = "cs42l73-asp",
  1036. .id = CS42L73_ASP,
  1037. .playback = {
  1038. .stream_name = "ASP Playback",
  1039. .channels_min = 2,
  1040. .channels_max = 2,
  1041. .rates = CS42L73_RATES,
  1042. .formats = CS42L73_FORMATS,
  1043. },
  1044. .capture = {
  1045. .stream_name = "ASP Capture",
  1046. .channels_min = 2,
  1047. .channels_max = 2,
  1048. .rates = CS42L73_RATES,
  1049. .formats = CS42L73_FORMATS,
  1050. },
  1051. .ops = &cs42l73_ops,
  1052. .symmetric_rates = 1,
  1053. },
  1054. {
  1055. .name = "cs42l73-vsp",
  1056. .id = CS42L73_VSP,
  1057. .playback = {
  1058. .stream_name = "VSP Playback",
  1059. .channels_min = 1,
  1060. .channels_max = 2,
  1061. .rates = CS42L73_RATES,
  1062. .formats = CS42L73_FORMATS,
  1063. },
  1064. .capture = {
  1065. .stream_name = "VSP Capture",
  1066. .channels_min = 1,
  1067. .channels_max = 2,
  1068. .rates = CS42L73_RATES,
  1069. .formats = CS42L73_FORMATS,
  1070. },
  1071. .ops = &cs42l73_ops,
  1072. .symmetric_rates = 1,
  1073. }
  1074. };
  1075. static int cs42l73_suspend(struct snd_soc_codec *codec)
  1076. {
  1077. cs42l73_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1078. return 0;
  1079. }
  1080. static int cs42l73_resume(struct snd_soc_codec *codec)
  1081. {
  1082. cs42l73_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1083. return 0;
  1084. }
  1085. static int cs42l73_probe(struct snd_soc_codec *codec)
  1086. {
  1087. int ret;
  1088. struct cs42l73_private *cs42l73 = snd_soc_codec_get_drvdata(codec);
  1089. codec->control_data = cs42l73->regmap;
  1090. ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
  1091. if (ret < 0) {
  1092. dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
  1093. return ret;
  1094. }
  1095. regcache_cache_only(cs42l73->regmap, true);
  1096. cs42l73_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1097. cs42l73->mclksel = CS42L73_CLKID_MCLK1; /* MCLK1 as master clk */
  1098. cs42l73->mclk = 0;
  1099. return ret;
  1100. }
  1101. static int cs42l73_remove(struct snd_soc_codec *codec)
  1102. {
  1103. cs42l73_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1104. return 0;
  1105. }
  1106. static struct snd_soc_codec_driver soc_codec_dev_cs42l73 = {
  1107. .probe = cs42l73_probe,
  1108. .remove = cs42l73_remove,
  1109. .suspend = cs42l73_suspend,
  1110. .resume = cs42l73_resume,
  1111. .set_bias_level = cs42l73_set_bias_level,
  1112. .dapm_widgets = cs42l73_dapm_widgets,
  1113. .num_dapm_widgets = ARRAY_SIZE(cs42l73_dapm_widgets),
  1114. .dapm_routes = cs42l73_audio_map,
  1115. .num_dapm_routes = ARRAY_SIZE(cs42l73_audio_map),
  1116. .controls = cs42l73_snd_controls,
  1117. .num_controls = ARRAY_SIZE(cs42l73_snd_controls),
  1118. };
  1119. static struct regmap_config cs42l73_regmap = {
  1120. .reg_bits = 8,
  1121. .val_bits = 8,
  1122. .max_register = CS42L73_MAX_REGISTER,
  1123. .reg_defaults = cs42l73_reg_defaults,
  1124. .num_reg_defaults = ARRAY_SIZE(cs42l73_reg_defaults),
  1125. .volatile_reg = cs42l73_volatile_register,
  1126. .readable_reg = cs42l73_readable_register,
  1127. .cache_type = REGCACHE_RBTREE,
  1128. };
  1129. static __devinit int cs42l73_i2c_probe(struct i2c_client *i2c_client,
  1130. const struct i2c_device_id *id)
  1131. {
  1132. struct cs42l73_private *cs42l73;
  1133. int ret;
  1134. unsigned int devid = 0;
  1135. unsigned int reg;
  1136. cs42l73 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs42l73_private),
  1137. GFP_KERNEL);
  1138. if (!cs42l73) {
  1139. dev_err(&i2c_client->dev, "could not allocate codec\n");
  1140. return -ENOMEM;
  1141. }
  1142. i2c_set_clientdata(i2c_client, cs42l73);
  1143. cs42l73->regmap = regmap_init_i2c(i2c_client, &cs42l73_regmap);
  1144. if (IS_ERR(cs42l73->regmap)) {
  1145. ret = PTR_ERR(cs42l73->regmap);
  1146. dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret);
  1147. goto err;
  1148. }
  1149. /* initialize codec */
  1150. ret = regmap_read(cs42l73->regmap, CS42L73_DEVID_AB, &reg);
  1151. devid = (reg & 0xFF) << 12;
  1152. ret = regmap_read(cs42l73->regmap, CS42L73_DEVID_CD, &reg);
  1153. devid |= (reg & 0xFF) << 4;
  1154. ret = regmap_read(cs42l73->regmap, CS42L73_DEVID_E, &reg);
  1155. devid |= (reg & 0xF0) >> 4;
  1156. if (devid != CS42L73_DEVID) {
  1157. ret = -ENODEV;
  1158. dev_err(&i2c_client->dev,
  1159. "CS42L73 Device ID (%X). Expected %X\n",
  1160. devid, CS42L73_DEVID);
  1161. goto err_regmap;
  1162. }
  1163. ret = regmap_read(cs42l73->regmap, CS42L73_REVID, &reg);
  1164. if (ret < 0) {
  1165. dev_err(&i2c_client->dev, "Get Revision ID failed\n");
  1166. goto err_regmap;
  1167. }
  1168. dev_info(&i2c_client->dev,
  1169. "Cirrus Logic CS42L73, Revision: %02X\n", reg & 0xFF);
  1170. regcache_cache_only(cs42l73->regmap, true);
  1171. ret = snd_soc_register_codec(&i2c_client->dev,
  1172. &soc_codec_dev_cs42l73, cs42l73_dai,
  1173. ARRAY_SIZE(cs42l73_dai));
  1174. if (ret < 0)
  1175. goto err_regmap;
  1176. return 0;
  1177. err_regmap:
  1178. regmap_exit(cs42l73->regmap);
  1179. err:
  1180. return ret;
  1181. }
  1182. static __devexit int cs42l73_i2c_remove(struct i2c_client *client)
  1183. {
  1184. struct cs42l73_private *cs42l73 = i2c_get_clientdata(client);
  1185. snd_soc_unregister_codec(&client->dev);
  1186. regmap_exit(cs42l73->regmap);
  1187. return 0;
  1188. }
  1189. static const struct i2c_device_id cs42l73_id[] = {
  1190. {"cs42l73", 0},
  1191. {}
  1192. };
  1193. MODULE_DEVICE_TABLE(i2c, cs42l73_id);
  1194. static struct i2c_driver cs42l73_i2c_driver = {
  1195. .driver = {
  1196. .name = "cs42l73",
  1197. .owner = THIS_MODULE,
  1198. },
  1199. .id_table = cs42l73_id,
  1200. .probe = cs42l73_i2c_probe,
  1201. .remove = __devexit_p(cs42l73_i2c_remove),
  1202. };
  1203. static int __init cs42l73_modinit(void)
  1204. {
  1205. int ret;
  1206. ret = i2c_add_driver(&cs42l73_i2c_driver);
  1207. if (ret != 0) {
  1208. pr_err("Failed to register CS42L73 I2C driver: %d\n", ret);
  1209. return ret;
  1210. }
  1211. return 0;
  1212. }
  1213. module_init(cs42l73_modinit);
  1214. static void __exit cs42l73_exit(void)
  1215. {
  1216. i2c_del_driver(&cs42l73_i2c_driver);
  1217. }
  1218. module_exit(cs42l73_exit);
  1219. MODULE_DESCRIPTION("ASoC CS42L73 driver");
  1220. MODULE_AUTHOR("Georgi Vlaev, Nucleus Systems Ltd, <joe@nucleusys.com>");
  1221. MODULE_AUTHOR("Brian Austin, Cirrus Logic Inc, <brian.austin@cirrus.com>");
  1222. MODULE_LICENSE("GPL");