da7210.c 29 KB

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