da7210.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  1. /*
  2. * DA7210 ALSA Soc codec driver
  3. *
  4. * Copyright (c) 2009 Dialog Semiconductor
  5. * Written by David Chen <Dajun.chen@diasemi.com>
  6. *
  7. * Copyright (C) 2009 Renesas Solutions Corp.
  8. * Cleanups by Kuninori Morimoto <morimoto.kuninori@renesas.com>
  9. *
  10. * Tested on SuperH Ecovec24 board with S16/S24 LE in 48KHz using I2S
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. */
  17. #include <linux/delay.h>
  18. #include <linux/i2c.h>
  19. #include <linux/slab.h>
  20. #include <linux/module.h>
  21. #include <sound/pcm.h>
  22. #include <sound/pcm_params.h>
  23. #include <sound/soc.h>
  24. #include <sound/initval.h>
  25. #include <sound/tlv.h>
  26. /* DA7210 register space */
  27. #define DA7210_CONTROL 0x01
  28. #define DA7210_STATUS 0x02
  29. #define DA7210_STARTUP1 0x03
  30. #define DA7210_STARTUP2 0x04
  31. #define DA7210_STARTUP3 0x05
  32. #define DA7210_MIC_L 0x07
  33. #define DA7210_MIC_R 0x08
  34. #define DA7210_AUX1_L 0x09
  35. #define DA7210_AUX1_R 0x0A
  36. #define DA7210_AUX2 0x0B
  37. #define DA7210_IN_GAIN 0x0C
  38. #define DA7210_INMIX_L 0x0D
  39. #define DA7210_INMIX_R 0x0E
  40. #define DA7210_ADC_HPF 0x0F
  41. #define DA7210_ADC 0x10
  42. #define DA7210_ADC_EQ1_2 0X11
  43. #define DA7210_ADC_EQ3_4 0x12
  44. #define DA7210_ADC_EQ5 0x13
  45. #define DA7210_DAC_HPF 0x14
  46. #define DA7210_DAC_L 0x15
  47. #define DA7210_DAC_R 0x16
  48. #define DA7210_DAC_SEL 0x17
  49. #define DA7210_SOFTMUTE 0x18
  50. #define DA7210_DAC_EQ1_2 0x19
  51. #define DA7210_DAC_EQ3_4 0x1A
  52. #define DA7210_DAC_EQ5 0x1B
  53. #define DA7210_OUTMIX_L 0x1C
  54. #define DA7210_OUTMIX_R 0x1D
  55. #define DA7210_OUT1_L 0x1E
  56. #define DA7210_OUT1_R 0x1F
  57. #define DA7210_OUT2 0x20
  58. #define DA7210_HP_L_VOL 0x21
  59. #define DA7210_HP_R_VOL 0x22
  60. #define DA7210_HP_CFG 0x23
  61. #define DA7210_ZERO_CROSS 0x24
  62. #define DA7210_DAI_SRC_SEL 0x25
  63. #define DA7210_DAI_CFG1 0x26
  64. #define DA7210_DAI_CFG3 0x28
  65. #define DA7210_PLL_DIV1 0x29
  66. #define DA7210_PLL_DIV2 0x2A
  67. #define DA7210_PLL_DIV3 0x2B
  68. #define DA7210_PLL 0x2C
  69. #define DA7210_ALC_MAX 0x83
  70. #define DA7210_ALC_MIN 0x84
  71. #define DA7210_ALC_NOIS 0x85
  72. #define DA7210_ALC_ATT 0x86
  73. #define DA7210_ALC_REL 0x87
  74. #define DA7210_ALC_DEL 0x88
  75. #define DA7210_A_HID_UNLOCK 0x8A
  76. #define DA7210_A_TEST_UNLOCK 0x8B
  77. #define DA7210_A_PLL1 0x90
  78. #define DA7210_A_CP_MODE 0xA7
  79. /* STARTUP1 bit fields */
  80. #define DA7210_SC_MST_EN (1 << 0)
  81. /* MIC_L bit fields */
  82. #define DA7210_MICBIAS_EN (1 << 6)
  83. #define DA7210_MIC_L_EN (1 << 7)
  84. /* MIC_R bit fields */
  85. #define DA7210_MIC_R_EN (1 << 7)
  86. /* INMIX_L bit fields */
  87. #define DA7210_IN_L_EN (1 << 7)
  88. /* INMIX_R bit fields */
  89. #define DA7210_IN_R_EN (1 << 7)
  90. /* ADC bit fields */
  91. #define DA7210_ADC_ALC_EN (1 << 0)
  92. #define DA7210_ADC_L_EN (1 << 3)
  93. #define DA7210_ADC_R_EN (1 << 7)
  94. /* DAC/ADC HPF fields */
  95. #define DA7210_VOICE_F0_MASK (0x7 << 4)
  96. #define DA7210_VOICE_F0_25 (1 << 4)
  97. #define DA7210_VOICE_EN (1 << 7)
  98. /* DAC_SEL bit fields */
  99. #define DA7210_DAC_L_SRC_DAI_L (4 << 0)
  100. #define DA7210_DAC_L_EN (1 << 3)
  101. #define DA7210_DAC_R_SRC_DAI_R (5 << 4)
  102. #define DA7210_DAC_R_EN (1 << 7)
  103. /* OUTMIX_L bit fields */
  104. #define DA7210_OUT_L_EN (1 << 7)
  105. /* OUTMIX_R bit fields */
  106. #define DA7210_OUT_R_EN (1 << 7)
  107. /* HP_CFG bit fields */
  108. #define DA7210_HP_2CAP_MODE (1 << 1)
  109. #define DA7210_HP_SENSE_EN (1 << 2)
  110. #define DA7210_HP_L_EN (1 << 3)
  111. #define DA7210_HP_MODE (1 << 6)
  112. #define DA7210_HP_R_EN (1 << 7)
  113. /* DAI_SRC_SEL bit fields */
  114. #define DA7210_DAI_OUT_L_SRC (6 << 0)
  115. #define DA7210_DAI_OUT_R_SRC (7 << 4)
  116. /* DAI_CFG1 bit fields */
  117. #define DA7210_DAI_WORD_S16_LE (0 << 0)
  118. #define DA7210_DAI_WORD_S20_3LE (1 << 0)
  119. #define DA7210_DAI_WORD_S24_LE (2 << 0)
  120. #define DA7210_DAI_WORD_S32_LE (3 << 0)
  121. #define DA7210_DAI_FLEN_64BIT (1 << 2)
  122. #define DA7210_DAI_MODE_SLAVE (0 << 7)
  123. #define DA7210_DAI_MODE_MASTER (1 << 7)
  124. /* DAI_CFG3 bit fields */
  125. #define DA7210_DAI_FORMAT_I2SMODE (0 << 0)
  126. #define DA7210_DAI_FORMAT_LEFT_J (1 << 0)
  127. #define DA7210_DAI_FORMAT_RIGHT_J (2 << 0)
  128. #define DA7210_DAI_OE (1 << 3)
  129. #define DA7210_DAI_EN (1 << 7)
  130. /*PLL_DIV3 bit fields */
  131. #define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4)
  132. #define DA7210_PLL_BYP (1 << 6)
  133. /* PLL bit fields */
  134. #define DA7210_PLL_FS_MASK (0xF << 0)
  135. #define DA7210_PLL_FS_8000 (0x1 << 0)
  136. #define DA7210_PLL_FS_11025 (0x2 << 0)
  137. #define DA7210_PLL_FS_12000 (0x3 << 0)
  138. #define DA7210_PLL_FS_16000 (0x5 << 0)
  139. #define DA7210_PLL_FS_22050 (0x6 << 0)
  140. #define DA7210_PLL_FS_24000 (0x7 << 0)
  141. #define DA7210_PLL_FS_32000 (0x9 << 0)
  142. #define DA7210_PLL_FS_44100 (0xA << 0)
  143. #define DA7210_PLL_FS_48000 (0xB << 0)
  144. #define DA7210_PLL_FS_88200 (0xE << 0)
  145. #define DA7210_PLL_FS_96000 (0xF << 0)
  146. #define DA7210_PLL_EN (0x1 << 7)
  147. /* SOFTMUTE bit fields */
  148. #define DA7210_RAMP_EN (1 << 6)
  149. /* CONTROL bit fields */
  150. #define DA7210_NOISE_SUP_EN (1 << 3)
  151. /* IN_GAIN bit fields */
  152. #define DA7210_INPGA_L_VOL (0x0F << 0)
  153. #define DA7210_INPGA_R_VOL (0xF0 << 0)
  154. /* ZERO_CROSS bit fields */
  155. #define DA7210_AUX1_L_ZC (1 << 0)
  156. #define DA7210_AUX1_R_ZC (1 << 1)
  157. #define DA7210_HP_L_ZC (1 << 6)
  158. #define DA7210_HP_R_ZC (1 << 7)
  159. /* AUX1_L bit fields */
  160. #define DA7210_AUX1_L_VOL (0x3F << 0)
  161. #define DA7210_AUX1_L_EN (1 << 7)
  162. /* AUX1_R bit fields */
  163. #define DA7210_AUX1_R_VOL (0x3F << 0)
  164. #define DA7210_AUX1_R_EN (1 << 7)
  165. /* AUX2 bit fields */
  166. #define DA7210_AUX2_EN (1 << 3)
  167. /* Minimum INPGA and AUX1 volume to enable noise suppression */
  168. #define DA7210_INPGA_MIN_VOL_NS 0x0A /* 10.5dB */
  169. #define DA7210_AUX1_MIN_VOL_NS 0x35 /* 6dB */
  170. /* OUT1_L bit fields */
  171. #define DA7210_OUT1_L_EN (1 << 7)
  172. /* OUT1_R bit fields */
  173. #define DA7210_OUT1_R_EN (1 << 7)
  174. /* OUT2 bit fields */
  175. #define DA7210_OUT2_OUTMIX_R (1 << 5)
  176. #define DA7210_OUT2_OUTMIX_L (1 << 6)
  177. #define DA7210_OUT2_EN (1 << 7)
  178. #define DA7210_VERSION "0.0.1"
  179. /*
  180. * Playback Volume
  181. *
  182. * max : 0x3F (+15.0 dB)
  183. * (1.5 dB step)
  184. * min : 0x11 (-54.0 dB)
  185. * mute : 0x10
  186. * reserved : 0x00 - 0x0F
  187. *
  188. * Reserved area are considered as "mute".
  189. */
  190. static const unsigned int hp_out_tlv[] = {
  191. TLV_DB_RANGE_HEAD(2),
  192. 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
  193. /* -54 dB to +15 dB */
  194. 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0),
  195. };
  196. static const unsigned int lineout_vol_tlv[] = {
  197. TLV_DB_RANGE_HEAD(2),
  198. 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
  199. /* -54dB to 15dB */
  200. 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0)
  201. };
  202. static const unsigned int mono_vol_tlv[] = {
  203. TLV_DB_RANGE_HEAD(2),
  204. 0x0, 0x2, TLV_DB_SCALE_ITEM(-1800, 0, 1),
  205. /* -18dB to 6dB */
  206. 0x3, 0x7, TLV_DB_SCALE_ITEM(-1800, 600, 0)
  207. };
  208. static const unsigned int aux1_vol_tlv[] = {
  209. TLV_DB_RANGE_HEAD(2),
  210. 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
  211. /* -48dB to 21dB */
  212. 0x11, 0x3f, TLV_DB_SCALE_ITEM(-4800, 150, 0)
  213. };
  214. static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0);
  215. static const DECLARE_TLV_DB_SCALE(adc_eq_master_gain_tlv, -1800, 600, 1);
  216. static const DECLARE_TLV_DB_SCALE(dac_gain_tlv, -7725, 75, 0);
  217. static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, -600, 600, 0);
  218. static const DECLARE_TLV_DB_SCALE(aux2_vol_tlv, -600, 600, 0);
  219. static const DECLARE_TLV_DB_SCALE(inpga_gain_tlv, -450, 150, 0);
  220. /* ADC and DAC high pass filter f0 value */
  221. static const char * const da7210_hpf_cutoff_txt[] = {
  222. "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi"
  223. };
  224. static const struct soc_enum da7210_dac_hpf_cutoff =
  225. SOC_ENUM_SINGLE(DA7210_DAC_HPF, 0, 4, da7210_hpf_cutoff_txt);
  226. static const struct soc_enum da7210_adc_hpf_cutoff =
  227. SOC_ENUM_SINGLE(DA7210_ADC_HPF, 0, 4, da7210_hpf_cutoff_txt);
  228. /* ADC and DAC voice (8kHz) high pass cutoff value */
  229. static const char * const da7210_vf_cutoff_txt[] = {
  230. "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
  231. };
  232. static const struct soc_enum da7210_dac_vf_cutoff =
  233. SOC_ENUM_SINGLE(DA7210_DAC_HPF, 4, 8, da7210_vf_cutoff_txt);
  234. static const struct soc_enum da7210_adc_vf_cutoff =
  235. SOC_ENUM_SINGLE(DA7210_ADC_HPF, 4, 8, da7210_vf_cutoff_txt);
  236. static const char *da7210_hp_mode_txt[] = {
  237. "Class H", "Class G"
  238. };
  239. static const struct soc_enum da7210_hp_mode_sel =
  240. SOC_ENUM_SINGLE(DA7210_HP_CFG, 0, 2, da7210_hp_mode_txt);
  241. /* ALC can be enabled only if noise suppression is disabled */
  242. static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol,
  243. struct snd_ctl_elem_value *ucontrol)
  244. {
  245. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  246. if (ucontrol->value.integer.value[0]) {
  247. /* Check if noise suppression is enabled */
  248. if (snd_soc_read(codec, DA7210_CONTROL) & DA7210_NOISE_SUP_EN) {
  249. dev_dbg(codec->dev,
  250. "Disable noise suppression to enable ALC\n");
  251. return -EINVAL;
  252. }
  253. }
  254. /* If all conditions are met or we are actually disabling ALC */
  255. return snd_soc_put_volsw(kcontrol, ucontrol);
  256. }
  257. /* Noise suppression can be enabled only if following conditions are met
  258. * ALC disabled
  259. * ZC enabled for HP and AUX1 PGA
  260. * INPGA_L_VOL and INPGA_R_VOL >= 10.5 dB
  261. * AUX1_L_VOL and AUX1_R_VOL >= 6 dB
  262. */
  263. static int da7210_put_noise_sup_sw(struct snd_kcontrol *kcontrol,
  264. struct snd_ctl_elem_value *ucontrol)
  265. {
  266. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  267. u8 val;
  268. if (ucontrol->value.integer.value[0]) {
  269. /* Check if ALC is enabled */
  270. if (snd_soc_read(codec, DA7210_ADC) & DA7210_ADC_ALC_EN)
  271. goto err;
  272. /* Check ZC for HP and AUX1 PGA */
  273. if ((snd_soc_read(codec, DA7210_ZERO_CROSS) &
  274. (DA7210_AUX1_L_ZC | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC |
  275. DA7210_HP_R_ZC)) != (DA7210_AUX1_L_ZC |
  276. DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | DA7210_HP_R_ZC))
  277. goto err;
  278. /* Check INPGA_L_VOL and INPGA_R_VOL */
  279. val = snd_soc_read(codec, DA7210_IN_GAIN);
  280. if (((val & DA7210_INPGA_L_VOL) < DA7210_INPGA_MIN_VOL_NS) ||
  281. (((val & DA7210_INPGA_R_VOL) >> 4) <
  282. DA7210_INPGA_MIN_VOL_NS))
  283. goto err;
  284. /* Check AUX1_L_VOL and AUX1_R_VOL */
  285. if (((snd_soc_read(codec, DA7210_AUX1_L) & DA7210_AUX1_L_VOL) <
  286. DA7210_AUX1_MIN_VOL_NS) ||
  287. ((snd_soc_read(codec, DA7210_AUX1_R) & DA7210_AUX1_R_VOL) <
  288. DA7210_AUX1_MIN_VOL_NS))
  289. goto err;
  290. }
  291. /* If all conditions are met or we are actually disabling Noise sup */
  292. return snd_soc_put_volsw(kcontrol, ucontrol);
  293. err:
  294. return -EINVAL;
  295. }
  296. static const struct snd_kcontrol_new da7210_snd_controls[] = {
  297. SOC_DOUBLE_R_TLV("HeadPhone Playback Volume",
  298. DA7210_HP_L_VOL, DA7210_HP_R_VOL,
  299. 0, 0x3F, 0, hp_out_tlv),
  300. SOC_DOUBLE_R_TLV("Digital Playback Volume",
  301. DA7210_DAC_L, DA7210_DAC_R,
  302. 0, 0x77, 1, dac_gain_tlv),
  303. SOC_DOUBLE_R_TLV("Lineout Playback Volume",
  304. DA7210_OUT1_L, DA7210_OUT1_R,
  305. 0, 0x3f, 0, lineout_vol_tlv),
  306. SOC_SINGLE_TLV("Mono Playback Volume", DA7210_OUT2, 0, 0x7, 0,
  307. mono_vol_tlv),
  308. SOC_DOUBLE_R_TLV("Mic Capture Volume",
  309. DA7210_MIC_L, DA7210_MIC_R,
  310. 0, 0x5, 0, mic_vol_tlv),
  311. SOC_DOUBLE_R_TLV("Aux1 Capture Volume",
  312. DA7210_AUX1_L, DA7210_AUX1_R,
  313. 0, 0x3f, 0, aux1_vol_tlv),
  314. SOC_SINGLE_TLV("Aux2 Capture Volume", DA7210_AUX2, 0, 0x3, 0,
  315. aux2_vol_tlv),
  316. SOC_DOUBLE_TLV("In PGA Capture Volume", DA7210_IN_GAIN, 0, 4, 0xF, 0,
  317. inpga_gain_tlv),
  318. /* DAC Equalizer controls */
  319. SOC_SINGLE("DAC EQ Switch", DA7210_DAC_EQ5, 7, 1, 0),
  320. SOC_SINGLE_TLV("DAC EQ1 Volume", DA7210_DAC_EQ1_2, 0, 0xf, 1,
  321. eq_gain_tlv),
  322. SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2, 4, 0xf, 1,
  323. eq_gain_tlv),
  324. SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4, 0, 0xf, 1,
  325. eq_gain_tlv),
  326. SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4, 4, 0xf, 1,
  327. eq_gain_tlv),
  328. SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5, 0, 0xf, 1,
  329. eq_gain_tlv),
  330. /* ADC Equalizer controls */
  331. SOC_SINGLE("ADC EQ Switch", DA7210_ADC_EQ5, 7, 1, 0),
  332. SOC_SINGLE_TLV("ADC EQ Master Volume", DA7210_ADC_EQ5, 4, 0x3,
  333. 1, adc_eq_master_gain_tlv),
  334. SOC_SINGLE_TLV("ADC EQ1 Volume", DA7210_ADC_EQ1_2, 0, 0xf, 1,
  335. eq_gain_tlv),
  336. SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2, 4, 0xf, 1,
  337. eq_gain_tlv),
  338. SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4, 0, 0xf, 1,
  339. eq_gain_tlv),
  340. SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4, 4, 0xf, 1,
  341. eq_gain_tlv),
  342. SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5, 0, 0xf, 1,
  343. eq_gain_tlv),
  344. SOC_SINGLE("DAC HPF Switch", DA7210_DAC_HPF, 3, 1, 0),
  345. SOC_ENUM("DAC HPF Cutoff", da7210_dac_hpf_cutoff),
  346. SOC_SINGLE("DAC Voice Mode Switch", DA7210_DAC_HPF, 7, 1, 0),
  347. SOC_ENUM("DAC Voice Cutoff", da7210_dac_vf_cutoff),
  348. SOC_SINGLE("ADC HPF Switch", DA7210_ADC_HPF, 3, 1, 0),
  349. SOC_ENUM("ADC HPF Cutoff", da7210_adc_hpf_cutoff),
  350. SOC_SINGLE("ADC Voice Mode Switch", DA7210_ADC_HPF, 7, 1, 0),
  351. SOC_ENUM("ADC Voice Cutoff", da7210_adc_vf_cutoff),
  352. /* Mute controls */
  353. SOC_DOUBLE_R("Mic Capture Switch", DA7210_MIC_L, DA7210_MIC_R, 3, 1, 0),
  354. SOC_SINGLE("Aux2 Capture Switch", DA7210_AUX2, 2, 1, 0),
  355. SOC_DOUBLE("ADC Capture Switch", DA7210_ADC, 2, 6, 1, 0),
  356. SOC_SINGLE("Digital Soft Mute Switch", DA7210_SOFTMUTE, 7, 1, 0),
  357. SOC_SINGLE("Digital Soft Mute Rate", DA7210_SOFTMUTE, 0, 0x7, 0),
  358. /* Zero cross controls */
  359. SOC_DOUBLE("Aux1 ZC Switch", DA7210_ZERO_CROSS, 0, 1, 1, 0),
  360. SOC_DOUBLE("In PGA ZC Switch", DA7210_ZERO_CROSS, 2, 3, 1, 0),
  361. SOC_DOUBLE("Lineout ZC Switch", DA7210_ZERO_CROSS, 4, 5, 1, 0),
  362. SOC_DOUBLE("Headphone ZC Switch", DA7210_ZERO_CROSS, 6, 7, 1, 0),
  363. SOC_ENUM("Headphone Class", da7210_hp_mode_sel),
  364. /* ALC controls */
  365. SOC_SINGLE_EXT("ALC Enable Switch", DA7210_ADC, 0, 1, 0,
  366. snd_soc_get_volsw, da7210_put_alc_sw),
  367. SOC_SINGLE("ALC Capture Max Volume", DA7210_ALC_MAX, 0, 0x3F, 0),
  368. SOC_SINGLE("ALC Capture Min Volume", DA7210_ALC_MIN, 0, 0x3F, 0),
  369. SOC_SINGLE("ALC Capture Noise Volume", DA7210_ALC_NOIS, 0, 0x3F, 0),
  370. SOC_SINGLE("ALC Capture Attack Rate", DA7210_ALC_ATT, 0, 0xFF, 0),
  371. SOC_SINGLE("ALC Capture Release Rate", DA7210_ALC_REL, 0, 0xFF, 0),
  372. SOC_SINGLE("ALC Capture Release Delay", DA7210_ALC_DEL, 0, 0xFF, 0),
  373. SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL, 3, 1,
  374. 0, snd_soc_get_volsw, da7210_put_noise_sup_sw),
  375. };
  376. /*
  377. * DAPM Controls
  378. *
  379. * Current DAPM implementation covers almost all codec components e.g. IOs,
  380. * mixers, PGAs,ADC and DAC.
  381. */
  382. /* In Mixer Left */
  383. static const struct snd_kcontrol_new da7210_dapm_inmixl_controls[] = {
  384. SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_L, 0, 1, 0),
  385. SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_L, 1, 1, 0),
  386. SOC_DAPM_SINGLE("Aux1 Left Switch", DA7210_INMIX_L, 2, 1, 0),
  387. SOC_DAPM_SINGLE("Aux2 Switch", DA7210_INMIX_L, 3, 1, 0),
  388. SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_INMIX_L, 4, 1, 0),
  389. };
  390. /* In Mixer Right */
  391. static const struct snd_kcontrol_new da7210_dapm_inmixr_controls[] = {
  392. SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_R, 0, 1, 0),
  393. SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_R, 1, 1, 0),
  394. SOC_DAPM_SINGLE("Aux1 Right Switch", DA7210_INMIX_R, 2, 1, 0),
  395. SOC_DAPM_SINGLE("Aux2 Switch", DA7210_INMIX_R, 3, 1, 0),
  396. SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_INMIX_R, 4, 1, 0),
  397. };
  398. /* Out Mixer Left */
  399. static const struct snd_kcontrol_new da7210_dapm_outmixl_controls[] = {
  400. SOC_DAPM_SINGLE("Aux1 Left Switch", DA7210_OUTMIX_L, 0, 1, 0),
  401. SOC_DAPM_SINGLE("Aux2 Switch", DA7210_OUTMIX_L, 1, 1, 0),
  402. SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUTMIX_L, 2, 1, 0),
  403. SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUTMIX_L, 3, 1, 0),
  404. SOC_DAPM_SINGLE("DAC Left Switch", DA7210_OUTMIX_L, 4, 1, 0),
  405. };
  406. /* Out Mixer Right */
  407. static const struct snd_kcontrol_new da7210_dapm_outmixr_controls[] = {
  408. SOC_DAPM_SINGLE("Aux1 Right Switch", DA7210_OUTMIX_R, 0, 1, 0),
  409. SOC_DAPM_SINGLE("Aux2 Switch", DA7210_OUTMIX_R, 1, 1, 0),
  410. SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUTMIX_R, 2, 1, 0),
  411. SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUTMIX_R, 3, 1, 0),
  412. SOC_DAPM_SINGLE("DAC Right Switch", DA7210_OUTMIX_R, 4, 1, 0),
  413. };
  414. /* Mono Mixer */
  415. static const struct snd_kcontrol_new da7210_dapm_monomix_controls[] = {
  416. SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUT2, 3, 1, 0),
  417. SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUT2, 4, 1, 0),
  418. SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_OUT2, 5, 1, 0),
  419. SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_OUT2, 6, 1, 0),
  420. };
  421. /* DAPM widgets */
  422. static const struct snd_soc_dapm_widget da7210_dapm_widgets[] = {
  423. /* Input Side */
  424. /* Input Lines */
  425. SND_SOC_DAPM_INPUT("MICL"),
  426. SND_SOC_DAPM_INPUT("MICR"),
  427. SND_SOC_DAPM_INPUT("AUX1L"),
  428. SND_SOC_DAPM_INPUT("AUX1R"),
  429. SND_SOC_DAPM_INPUT("AUX2"),
  430. /* Input PGAs */
  431. SND_SOC_DAPM_PGA("Mic Left", DA7210_STARTUP3, 0, 1, NULL, 0),
  432. SND_SOC_DAPM_PGA("Mic Right", DA7210_STARTUP3, 1, 1, NULL, 0),
  433. SND_SOC_DAPM_PGA("Aux1 Left", DA7210_STARTUP3, 2, 1, NULL, 0),
  434. SND_SOC_DAPM_PGA("Aux1 Right", DA7210_STARTUP3, 3, 1, NULL, 0),
  435. SND_SOC_DAPM_PGA("Aux2 Mono", DA7210_STARTUP3, 4, 1, NULL, 0),
  436. SND_SOC_DAPM_PGA("INPGA Left", DA7210_INMIX_L, 7, 0, NULL, 0),
  437. SND_SOC_DAPM_PGA("INPGA Right", DA7210_INMIX_R, 7, 0, NULL, 0),
  438. /* MICBIAS */
  439. SND_SOC_DAPM_SUPPLY("Mic Bias", DA7210_MIC_L, 6, 0, NULL, 0),
  440. /* Input Mixers */
  441. SND_SOC_DAPM_MIXER("In Mixer Left", SND_SOC_NOPM, 0, 0,
  442. &da7210_dapm_inmixl_controls[0],
  443. ARRAY_SIZE(da7210_dapm_inmixl_controls)),
  444. SND_SOC_DAPM_MIXER("In Mixer Right", SND_SOC_NOPM, 0, 0,
  445. &da7210_dapm_inmixr_controls[0],
  446. ARRAY_SIZE(da7210_dapm_inmixr_controls)),
  447. /* ADCs */
  448. SND_SOC_DAPM_ADC("ADC Left", "Capture", DA7210_STARTUP3, 5, 1),
  449. SND_SOC_DAPM_ADC("ADC Right", "Capture", DA7210_STARTUP3, 6, 1),
  450. /* Output Side */
  451. /* DACs */
  452. SND_SOC_DAPM_DAC("DAC Left", "Playback", DA7210_STARTUP2, 5, 1),
  453. SND_SOC_DAPM_DAC("DAC Right", "Playback", DA7210_STARTUP2, 6, 1),
  454. /* Output Mixers */
  455. SND_SOC_DAPM_MIXER("Out Mixer Left", SND_SOC_NOPM, 0, 0,
  456. &da7210_dapm_outmixl_controls[0],
  457. ARRAY_SIZE(da7210_dapm_outmixl_controls)),
  458. SND_SOC_DAPM_MIXER("Out Mixer Right", SND_SOC_NOPM, 0, 0,
  459. &da7210_dapm_outmixr_controls[0],
  460. ARRAY_SIZE(da7210_dapm_outmixr_controls)),
  461. SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0,
  462. &da7210_dapm_monomix_controls[0],
  463. ARRAY_SIZE(da7210_dapm_monomix_controls)),
  464. /* Output PGAs */
  465. SND_SOC_DAPM_PGA("OUTPGA Left Enable", DA7210_OUTMIX_L, 7, 0, NULL, 0),
  466. SND_SOC_DAPM_PGA("OUTPGA Right Enable", DA7210_OUTMIX_R, 7, 0, NULL, 0),
  467. SND_SOC_DAPM_PGA("Out1 Left", DA7210_STARTUP2, 0, 1, NULL, 0),
  468. SND_SOC_DAPM_PGA("Out1 Right", DA7210_STARTUP2, 1, 1, NULL, 0),
  469. SND_SOC_DAPM_PGA("Out2 Mono", DA7210_STARTUP2, 2, 1, NULL, 0),
  470. SND_SOC_DAPM_PGA("Headphone Left", DA7210_STARTUP2, 3, 1, NULL, 0),
  471. SND_SOC_DAPM_PGA("Headphone Right", DA7210_STARTUP2, 4, 1, NULL, 0),
  472. /* Output Lines */
  473. SND_SOC_DAPM_OUTPUT("OUT1L"),
  474. SND_SOC_DAPM_OUTPUT("OUT1R"),
  475. SND_SOC_DAPM_OUTPUT("HPL"),
  476. SND_SOC_DAPM_OUTPUT("HPR"),
  477. SND_SOC_DAPM_OUTPUT("OUT2"),
  478. };
  479. /* DAPM audio route definition */
  480. static const struct snd_soc_dapm_route da7210_audio_map[] = {
  481. /* Dest Connecting Widget source */
  482. /* Input path */
  483. {"Mic Left", NULL, "MICL"},
  484. {"Mic Right", NULL, "MICR"},
  485. {"Aux1 Left", NULL, "AUX1L"},
  486. {"Aux1 Right", NULL, "AUX1R"},
  487. {"Aux2 Mono", NULL, "AUX2"},
  488. {"In Mixer Left", "Mic Left Switch", "Mic Left"},
  489. {"In Mixer Left", "Mic Right Switch", "Mic Right"},
  490. {"In Mixer Left", "Aux1 Left Switch", "Aux1 Left"},
  491. {"In Mixer Left", "Aux2 Switch", "Aux2 Mono"},
  492. {"In Mixer Left", "Outmix Left Switch", "Out Mixer Left"},
  493. {"In Mixer Right", "Mic Right Switch", "Mic Right"},
  494. {"In Mixer Right", "Mic Left Switch", "Mic Left"},
  495. {"In Mixer Right", "Aux1 Right Switch", "Aux1 Right"},
  496. {"In Mixer Right", "Aux2 Switch", "Aux2 Mono"},
  497. {"In Mixer Right", "Outmix Right Switch", "Out Mixer Right"},
  498. {"INPGA Left", NULL, "In Mixer Left"},
  499. {"ADC Left", NULL, "INPGA Left"},
  500. {"INPGA Right", NULL, "In Mixer Right"},
  501. {"ADC Right", NULL, "INPGA Right"},
  502. /* Output path */
  503. {"Out Mixer Left", "Aux1 Left Switch", "Aux1 Left"},
  504. {"Out Mixer Left", "Aux2 Switch", "Aux2 Mono"},
  505. {"Out Mixer Left", "INPGA Left Switch", "INPGA Left"},
  506. {"Out Mixer Left", "INPGA Right Switch", "INPGA Right"},
  507. {"Out Mixer Left", "DAC Left Switch", "DAC Left"},
  508. {"Out Mixer Right", "Aux1 Right Switch", "Aux1 Right"},
  509. {"Out Mixer Right", "Aux2 Switch", "Aux2 Mono"},
  510. {"Out Mixer Right", "INPGA Right Switch", "INPGA Right"},
  511. {"Out Mixer Right", "INPGA Left Switch", "INPGA Left"},
  512. {"Out Mixer Right", "DAC Right Switch", "DAC Right"},
  513. {"Mono Mixer", "INPGA Right Switch", "INPGA Right"},
  514. {"Mono Mixer", "INPGA Left Switch", "INPGA Left"},
  515. {"Mono Mixer", "Outmix Right Switch", "Out Mixer Right"},
  516. {"Mono Mixer", "Outmix Left Switch", "Out Mixer Left"},
  517. {"OUTPGA Left Enable", NULL, "Out Mixer Left"},
  518. {"OUTPGA Right Enable", NULL, "Out Mixer Right"},
  519. {"Out1 Left", NULL, "OUTPGA Left Enable"},
  520. {"OUT1L", NULL, "Out1 Left"},
  521. {"Out1 Right", NULL, "OUTPGA Right Enable"},
  522. {"OUT1R", NULL, "Out1 Right"},
  523. {"Headphone Left", NULL, "OUTPGA Left Enable"},
  524. {"HPL", NULL, "Headphone Left"},
  525. {"Headphone Right", NULL, "OUTPGA Right Enable"},
  526. {"HPR", NULL, "Headphone Right"},
  527. {"Out2 Mono", NULL, "Mono Mixer"},
  528. {"OUT2", NULL, "Out2 Mono"},
  529. };
  530. /* Codec private data */
  531. struct da7210_priv {
  532. enum snd_soc_control_type control_type;
  533. };
  534. /*
  535. * Register cache
  536. */
  537. static const u8 da7210_reg[] = {
  538. 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R0 - R7 */
  539. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, /* R8 - RF */
  540. 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x54, /* R10 - R17 */
  541. 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R18 - R1F */
  542. 0x00, 0x00, 0x00, 0x02, 0x00, 0x76, 0x00, 0x00, /* R20 - R27 */
  543. 0x04, 0x00, 0x00, 0x30, 0x2A, 0x00, 0x40, 0x00, /* R28 - R2F */
  544. 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, /* R30 - R37 */
  545. 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, /* R38 - R3F */
  546. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R40 - R4F */
  547. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R48 - R4F */
  548. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R50 - R57 */
  549. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R58 - R5F */
  550. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R60 - R67 */
  551. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R68 - R6F */
  552. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R70 - R77 */
  553. 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x54, 0x00, /* R78 - R7F */
  554. 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, /* R80 - R87 */
  555. 0x00, /* R88 */
  556. };
  557. static int da7210_volatile_register(struct snd_soc_codec *codec,
  558. unsigned int reg)
  559. {
  560. switch (reg) {
  561. case DA7210_STATUS:
  562. return 1;
  563. default:
  564. return 0;
  565. }
  566. }
  567. /*
  568. * Set PCM DAI word length.
  569. */
  570. static int da7210_hw_params(struct snd_pcm_substream *substream,
  571. struct snd_pcm_hw_params *params,
  572. struct snd_soc_dai *dai)
  573. {
  574. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  575. struct snd_soc_codec *codec = rtd->codec;
  576. u32 dai_cfg1;
  577. u32 fs, bypass;
  578. /* set DAI source to Left and Right ADC */
  579. snd_soc_write(codec, DA7210_DAI_SRC_SEL,
  580. DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
  581. /* Enable DAI */
  582. snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
  583. dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1);
  584. switch (params_format(params)) {
  585. case SNDRV_PCM_FORMAT_S16_LE:
  586. dai_cfg1 |= DA7210_DAI_WORD_S16_LE;
  587. break;
  588. case SNDRV_PCM_FORMAT_S20_3LE:
  589. dai_cfg1 |= DA7210_DAI_WORD_S20_3LE;
  590. break;
  591. case SNDRV_PCM_FORMAT_S24_LE:
  592. dai_cfg1 |= DA7210_DAI_WORD_S24_LE;
  593. break;
  594. case SNDRV_PCM_FORMAT_S32_LE:
  595. dai_cfg1 |= DA7210_DAI_WORD_S32_LE;
  596. break;
  597. default:
  598. return -EINVAL;
  599. }
  600. snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
  601. switch (params_rate(params)) {
  602. case 8000:
  603. fs = DA7210_PLL_FS_8000;
  604. bypass = DA7210_PLL_BYP;
  605. break;
  606. case 11025:
  607. fs = DA7210_PLL_FS_11025;
  608. bypass = 0;
  609. break;
  610. case 12000:
  611. fs = DA7210_PLL_FS_12000;
  612. bypass = DA7210_PLL_BYP;
  613. break;
  614. case 16000:
  615. fs = DA7210_PLL_FS_16000;
  616. bypass = DA7210_PLL_BYP;
  617. break;
  618. case 22050:
  619. fs = DA7210_PLL_FS_22050;
  620. bypass = 0;
  621. break;
  622. case 32000:
  623. fs = DA7210_PLL_FS_32000;
  624. bypass = DA7210_PLL_BYP;
  625. break;
  626. case 44100:
  627. fs = DA7210_PLL_FS_44100;
  628. bypass = 0;
  629. break;
  630. case 48000:
  631. fs = DA7210_PLL_FS_48000;
  632. bypass = DA7210_PLL_BYP;
  633. break;
  634. case 88200:
  635. fs = DA7210_PLL_FS_88200;
  636. bypass = 0;
  637. break;
  638. case 96000:
  639. fs = DA7210_PLL_FS_96000;
  640. bypass = DA7210_PLL_BYP;
  641. break;
  642. default:
  643. return -EINVAL;
  644. }
  645. /* Disable active mode */
  646. snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
  647. snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
  648. snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass);
  649. /* Enable active mode */
  650. snd_soc_update_bits(codec, DA7210_STARTUP1,
  651. DA7210_SC_MST_EN, DA7210_SC_MST_EN);
  652. return 0;
  653. }
  654. /*
  655. * Set DAI mode and Format
  656. */
  657. static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
  658. {
  659. struct snd_soc_codec *codec = codec_dai->codec;
  660. u32 dai_cfg1;
  661. u32 dai_cfg3;
  662. dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1);
  663. dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3);
  664. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  665. case SND_SOC_DAIFMT_CBM_CFM:
  666. dai_cfg1 |= DA7210_DAI_MODE_MASTER;
  667. break;
  668. case SND_SOC_DAIFMT_CBS_CFS:
  669. dai_cfg1 |= DA7210_DAI_MODE_SLAVE;
  670. break;
  671. default:
  672. return -EINVAL;
  673. }
  674. /* FIXME
  675. *
  676. * It support I2S only now
  677. */
  678. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  679. case SND_SOC_DAIFMT_I2S:
  680. dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE;
  681. break;
  682. case SND_SOC_DAIFMT_LEFT_J:
  683. dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J;
  684. break;
  685. case SND_SOC_DAIFMT_RIGHT_J:
  686. dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J;
  687. break;
  688. default:
  689. return -EINVAL;
  690. }
  691. /* FIXME
  692. *
  693. * It support 64bit data transmission only now
  694. */
  695. dai_cfg1 |= DA7210_DAI_FLEN_64BIT;
  696. snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
  697. snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3);
  698. return 0;
  699. }
  700. static int da7210_mute(struct snd_soc_dai *dai, int mute)
  701. {
  702. struct snd_soc_codec *codec = dai->codec;
  703. u8 mute_reg = snd_soc_read(codec, DA7210_DAC_HPF) & 0xFB;
  704. if (mute)
  705. snd_soc_write(codec, DA7210_DAC_HPF, mute_reg | 0x4);
  706. else
  707. snd_soc_write(codec, DA7210_DAC_HPF, mute_reg);
  708. return 0;
  709. }
  710. #define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  711. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
  712. /* DAI operations */
  713. static const struct snd_soc_dai_ops da7210_dai_ops = {
  714. .hw_params = da7210_hw_params,
  715. .set_fmt = da7210_set_dai_fmt,
  716. .digital_mute = da7210_mute,
  717. };
  718. static struct snd_soc_dai_driver da7210_dai = {
  719. .name = "da7210-hifi",
  720. /* playback capabilities */
  721. .playback = {
  722. .stream_name = "Playback",
  723. .channels_min = 1,
  724. .channels_max = 2,
  725. .rates = SNDRV_PCM_RATE_8000_96000,
  726. .formats = DA7210_FORMATS,
  727. },
  728. /* capture capabilities */
  729. .capture = {
  730. .stream_name = "Capture",
  731. .channels_min = 1,
  732. .channels_max = 2,
  733. .rates = SNDRV_PCM_RATE_8000_96000,
  734. .formats = DA7210_FORMATS,
  735. },
  736. .ops = &da7210_dai_ops,
  737. .symmetric_rates = 1,
  738. };
  739. static int da7210_probe(struct snd_soc_codec *codec)
  740. {
  741. struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
  742. int ret;
  743. dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
  744. ret = snd_soc_codec_set_cache_io(codec, 8, 8, da7210->control_type);
  745. if (ret < 0) {
  746. dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
  747. return ret;
  748. }
  749. /* FIXME
  750. *
  751. * This driver use fixed value here
  752. * And below settings expects MCLK = 12.288MHz
  753. *
  754. * When you select different MCLK, please check...
  755. * DA7210_PLL_DIV1 val
  756. * DA7210_PLL_DIV2 val
  757. * DA7210_PLL_DIV3 val
  758. * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx
  759. */
  760. /*
  761. * make sure that DA7210 use bypass mode before start up
  762. */
  763. snd_soc_write(codec, DA7210_STARTUP1, 0);
  764. snd_soc_write(codec, DA7210_PLL_DIV3,
  765. DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
  766. /*
  767. * ADC settings
  768. */
  769. /* Enable Left & Right MIC PGA and Mic Bias */
  770. snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
  771. snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
  772. /* Enable Left and Right input PGA */
  773. snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN);
  774. snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN);
  775. /* Enable Left and Right ADC */
  776. snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN);
  777. /*
  778. * DAC settings
  779. */
  780. /* Enable Left and Right DAC */
  781. snd_soc_write(codec, DA7210_DAC_SEL,
  782. DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN |
  783. DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN);
  784. /* Enable Left and Right out PGA */
  785. snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN);
  786. snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN);
  787. /* Enable Left and Right HeadPhone PGA */
  788. snd_soc_write(codec, DA7210_HP_CFG,
  789. DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
  790. DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
  791. /* Enable ramp mode for DAC gain update */
  792. snd_soc_write(codec, DA7210_SOFTMUTE, DA7210_RAMP_EN);
  793. /*
  794. * For DA7210 codec, there are two ways to enable/disable analog IOs
  795. * and ADC/DAC,
  796. * (1) Using "Enable Bit" of register associated with that IO
  797. * (or ADC/DAC)
  798. * e.g. Mic Left can be enabled using bit 7 of MIC_L(0x7) reg
  799. *
  800. * (2) Using "Standby Bit" of STARTUP2 or STARTUP3 register
  801. * e.g. Mic left can be put to STANDBY using bit 0 of STARTUP3(0x5)
  802. *
  803. * Out of these two methods, the one using STANDBY bits is preferred
  804. * way to enable/disable individual blocks. This is because STANDBY
  805. * registers are part of system controller which allows system power
  806. * up/down in a controlled, pop-free manner. Also, as per application
  807. * note of DA7210, STANDBY register bits are only effective if a
  808. * particular IO (or ADC/DAC) is already enabled using enable/disable
  809. * register bits. Keeping these things in mind, current DAPM
  810. * implementation manipulates only STANDBY bits.
  811. *
  812. * Overall implementation can be outlined as below,
  813. *
  814. * - "Enable bit" of an IO or ADC/DAC is used to enable it in probe()
  815. * - "STANDBY bit" is controlled by DAPM
  816. */
  817. /* Enable Line out amplifiers */
  818. snd_soc_write(codec, DA7210_OUT1_L, DA7210_OUT1_L_EN);
  819. snd_soc_write(codec, DA7210_OUT1_R, DA7210_OUT1_R_EN);
  820. snd_soc_write(codec, DA7210_OUT2, DA7210_OUT2_EN |
  821. DA7210_OUT2_OUTMIX_L | DA7210_OUT2_OUTMIX_R);
  822. /* Enable Aux1 */
  823. snd_soc_write(codec, DA7210_AUX1_L, DA7210_AUX1_L_EN);
  824. snd_soc_write(codec, DA7210_AUX1_R, DA7210_AUX1_R_EN);
  825. /* Enable Aux2 */
  826. snd_soc_write(codec, DA7210_AUX2, DA7210_AUX2_EN);
  827. /* Diable PLL and bypass it */
  828. snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
  829. /*
  830. * If 48kHz sound came, it use bypass mode,
  831. * and when it is 44.1kHz, it use PLL.
  832. *
  833. * This time, this driver sets PLL always ON
  834. * and controls bypass/PLL mode by switching
  835. * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit.
  836. * see da7210_hw_params
  837. */
  838. snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
  839. snd_soc_write(codec, DA7210_PLL_DIV2, 0x99);
  840. snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A |
  841. DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
  842. snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
  843. /* As suggested by Dialog */
  844. snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x8B); /* unlock */
  845. snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0xB4);
  846. snd_soc_write(codec, DA7210_A_PLL1, 0x01);
  847. snd_soc_write(codec, DA7210_A_CP_MODE, 0x7C);
  848. snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x00); /* re-lock */
  849. snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0x00);
  850. /* Activate all enabled subsystem */
  851. snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
  852. dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
  853. return 0;
  854. }
  855. static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
  856. .probe = da7210_probe,
  857. .reg_cache_size = ARRAY_SIZE(da7210_reg),
  858. .reg_word_size = sizeof(u8),
  859. .reg_cache_default = da7210_reg,
  860. .volatile_register = da7210_volatile_register,
  861. .controls = da7210_snd_controls,
  862. .num_controls = ARRAY_SIZE(da7210_snd_controls),
  863. .dapm_widgets = da7210_dapm_widgets,
  864. .num_dapm_widgets = ARRAY_SIZE(da7210_dapm_widgets),
  865. .dapm_routes = da7210_audio_map,
  866. .num_dapm_routes = ARRAY_SIZE(da7210_audio_map),
  867. };
  868. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  869. static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
  870. const struct i2c_device_id *id)
  871. {
  872. struct da7210_priv *da7210;
  873. int ret;
  874. da7210 = devm_kzalloc(&i2c->dev, sizeof(struct da7210_priv),
  875. GFP_KERNEL);
  876. if (!da7210)
  877. return -ENOMEM;
  878. i2c_set_clientdata(i2c, da7210);
  879. da7210->control_type = SND_SOC_I2C;
  880. ret = snd_soc_register_codec(&i2c->dev,
  881. &soc_codec_dev_da7210, &da7210_dai, 1);
  882. return ret;
  883. }
  884. static int __devexit da7210_i2c_remove(struct i2c_client *client)
  885. {
  886. snd_soc_unregister_codec(&client->dev);
  887. return 0;
  888. }
  889. static const struct i2c_device_id da7210_i2c_id[] = {
  890. { "da7210", 0 },
  891. { }
  892. };
  893. MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
  894. /* I2C codec control layer */
  895. static struct i2c_driver da7210_i2c_driver = {
  896. .driver = {
  897. .name = "da7210-codec",
  898. .owner = THIS_MODULE,
  899. },
  900. .probe = da7210_i2c_probe,
  901. .remove = __devexit_p(da7210_i2c_remove),
  902. .id_table = da7210_i2c_id,
  903. };
  904. #endif
  905. static int __init da7210_modinit(void)
  906. {
  907. int ret = 0;
  908. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  909. ret = i2c_add_driver(&da7210_i2c_driver);
  910. #endif
  911. return ret;
  912. }
  913. module_init(da7210_modinit);
  914. static void __exit da7210_exit(void)
  915. {
  916. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  917. i2c_del_driver(&da7210_i2c_driver);
  918. #endif
  919. }
  920. module_exit(da7210_exit);
  921. MODULE_DESCRIPTION("ASoC DA7210 driver");
  922. MODULE_AUTHOR("David Chen, Kuninori Morimoto");
  923. MODULE_LICENSE("GPL");