da7210.c 29 KB

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