da7210.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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_STATUS 0x02
  28. #define DA7210_STARTUP1 0x03
  29. #define DA7210_MIC_L 0x07
  30. #define DA7210_MIC_R 0x08
  31. #define DA7210_INMIX_L 0x0D
  32. #define DA7210_INMIX_R 0x0E
  33. #define DA7210_ADC_HPF 0x0F
  34. #define DA7210_ADC 0x10
  35. #define DA7210_DAC_HPF 0x14
  36. #define DA7210_DAC_L 0x15
  37. #define DA7210_DAC_R 0x16
  38. #define DA7210_DAC_SEL 0x17
  39. #define DA7210_OUTMIX_L 0x1C
  40. #define DA7210_OUTMIX_R 0x1D
  41. #define DA7210_HP_L_VOL 0x21
  42. #define DA7210_HP_R_VOL 0x22
  43. #define DA7210_HP_CFG 0x23
  44. #define DA7210_DAI_SRC_SEL 0x25
  45. #define DA7210_DAI_CFG1 0x26
  46. #define DA7210_DAI_CFG3 0x28
  47. #define DA7210_PLL_DIV1 0x29
  48. #define DA7210_PLL_DIV2 0x2A
  49. #define DA7210_PLL_DIV3 0x2B
  50. #define DA7210_PLL 0x2C
  51. #define DA7210_A_HID_UNLOCK 0x8A
  52. #define DA7210_A_TEST_UNLOCK 0x8B
  53. #define DA7210_A_PLL1 0x90
  54. #define DA7210_A_CP_MODE 0xA7
  55. /* STARTUP1 bit fields */
  56. #define DA7210_SC_MST_EN (1 << 0)
  57. /* MIC_L bit fields */
  58. #define DA7210_MICBIAS_EN (1 << 6)
  59. #define DA7210_MIC_L_EN (1 << 7)
  60. /* MIC_R bit fields */
  61. #define DA7210_MIC_R_EN (1 << 7)
  62. /* INMIX_L bit fields */
  63. #define DA7210_IN_L_EN (1 << 7)
  64. /* INMIX_R bit fields */
  65. #define DA7210_IN_R_EN (1 << 7)
  66. /* ADC bit fields */
  67. #define DA7210_ADC_L_EN (1 << 3)
  68. #define DA7210_ADC_R_EN (1 << 7)
  69. /* DAC/ADC HPF fields */
  70. #define DA7210_VOICE_F0_MASK (0x7 << 4)
  71. #define DA7210_VOICE_F0_25 (1 << 4)
  72. #define DA7210_VOICE_EN (1 << 7)
  73. /* DAC_SEL bit fields */
  74. #define DA7210_DAC_L_SRC_DAI_L (4 << 0)
  75. #define DA7210_DAC_L_EN (1 << 3)
  76. #define DA7210_DAC_R_SRC_DAI_R (5 << 4)
  77. #define DA7210_DAC_R_EN (1 << 7)
  78. /* OUTMIX_L bit fields */
  79. #define DA7210_OUT_L_EN (1 << 7)
  80. /* OUTMIX_R bit fields */
  81. #define DA7210_OUT_R_EN (1 << 7)
  82. /* HP_CFG bit fields */
  83. #define DA7210_HP_2CAP_MODE (1 << 1)
  84. #define DA7210_HP_SENSE_EN (1 << 2)
  85. #define DA7210_HP_L_EN (1 << 3)
  86. #define DA7210_HP_MODE (1 << 6)
  87. #define DA7210_HP_R_EN (1 << 7)
  88. /* DAI_SRC_SEL bit fields */
  89. #define DA7210_DAI_OUT_L_SRC (6 << 0)
  90. #define DA7210_DAI_OUT_R_SRC (7 << 4)
  91. /* DAI_CFG1 bit fields */
  92. #define DA7210_DAI_WORD_S16_LE (0 << 0)
  93. #define DA7210_DAI_WORD_S20_3LE (1 << 0)
  94. #define DA7210_DAI_WORD_S24_LE (2 << 0)
  95. #define DA7210_DAI_WORD_S32_LE (3 << 0)
  96. #define DA7210_DAI_FLEN_64BIT (1 << 2)
  97. #define DA7210_DAI_MODE_SLAVE (0 << 7)
  98. #define DA7210_DAI_MODE_MASTER (1 << 7)
  99. /* DAI_CFG3 bit fields */
  100. #define DA7210_DAI_FORMAT_I2SMODE (0 << 0)
  101. #define DA7210_DAI_FORMAT_LEFT_J (1 << 0)
  102. #define DA7210_DAI_FORMAT_RIGHT_J (2 << 0)
  103. #define DA7210_DAI_OE (1 << 3)
  104. #define DA7210_DAI_EN (1 << 7)
  105. /*PLL_DIV3 bit fields */
  106. #define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4)
  107. #define DA7210_PLL_BYP (1 << 6)
  108. /* PLL bit fields */
  109. #define DA7210_PLL_FS_MASK (0xF << 0)
  110. #define DA7210_PLL_FS_8000 (0x1 << 0)
  111. #define DA7210_PLL_FS_11025 (0x2 << 0)
  112. #define DA7210_PLL_FS_12000 (0x3 << 0)
  113. #define DA7210_PLL_FS_16000 (0x5 << 0)
  114. #define DA7210_PLL_FS_22050 (0x6 << 0)
  115. #define DA7210_PLL_FS_24000 (0x7 << 0)
  116. #define DA7210_PLL_FS_32000 (0x9 << 0)
  117. #define DA7210_PLL_FS_44100 (0xA << 0)
  118. #define DA7210_PLL_FS_48000 (0xB << 0)
  119. #define DA7210_PLL_FS_88200 (0xE << 0)
  120. #define DA7210_PLL_FS_96000 (0xF << 0)
  121. #define DA7210_PLL_EN (0x1 << 7)
  122. #define DA7210_VERSION "0.0.1"
  123. /*
  124. * Playback Volume
  125. *
  126. * max : 0x3F (+15.0 dB)
  127. * (1.5 dB step)
  128. * min : 0x11 (-54.0 dB)
  129. * mute : 0x10
  130. * reserved : 0x00 - 0x0F
  131. *
  132. * ** FIXME **
  133. *
  134. * Reserved area are considered as "mute".
  135. * -> min = -79.5 dB
  136. */
  137. static const DECLARE_TLV_DB_SCALE(hp_out_tlv, -7950, 150, 1);
  138. static const struct snd_kcontrol_new da7210_snd_controls[] = {
  139. SOC_DOUBLE_R_TLV("HeadPhone Playback Volume",
  140. DA7210_HP_L_VOL, DA7210_HP_R_VOL,
  141. 0, 0x3F, 0, hp_out_tlv),
  142. };
  143. /* Codec private data */
  144. struct da7210_priv {
  145. enum snd_soc_control_type control_type;
  146. };
  147. /*
  148. * Register cache
  149. */
  150. static const u8 da7210_reg[] = {
  151. 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R0 - R7 */
  152. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, /* R8 - RF */
  153. 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x54, /* R10 - R17 */
  154. 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R18 - R1F */
  155. 0x00, 0x00, 0x00, 0x02, 0x00, 0x76, 0x00, 0x00, /* R20 - R27 */
  156. 0x04, 0x00, 0x00, 0x30, 0x2A, 0x00, 0x40, 0x00, /* R28 - R2F */
  157. 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, /* R30 - R37 */
  158. 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, /* R38 - R3F */
  159. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R40 - R4F */
  160. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R48 - R4F */
  161. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R50 - R57 */
  162. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R58 - R5F */
  163. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R60 - R67 */
  164. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R68 - R6F */
  165. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R70 - R77 */
  166. 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x54, 0x00, /* R78 - R7F */
  167. 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, /* R80 - R87 */
  168. 0x00, /* R88 */
  169. };
  170. static int da7210_volatile_register(struct snd_soc_codec *codec,
  171. unsigned int reg)
  172. {
  173. switch (reg) {
  174. case DA7210_STATUS:
  175. return 1;
  176. default:
  177. return 0;
  178. }
  179. }
  180. static int da7210_startup(struct snd_pcm_substream *substream,
  181. struct snd_soc_dai *dai)
  182. {
  183. int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
  184. struct snd_soc_codec *codec = dai->codec;
  185. if (is_play) {
  186. /* Enable Out */
  187. snd_soc_update_bits(codec, DA7210_OUTMIX_L, 0x1F, 0x10);
  188. snd_soc_update_bits(codec, DA7210_OUTMIX_R, 0x1F, 0x10);
  189. } else {
  190. /* Volume 7 */
  191. snd_soc_update_bits(codec, DA7210_MIC_L, 0x7, 0x7);
  192. snd_soc_update_bits(codec, DA7210_MIC_R, 0x7, 0x7);
  193. /* Enable Mic */
  194. snd_soc_update_bits(codec, DA7210_INMIX_L, 0x1F, 0x1);
  195. snd_soc_update_bits(codec, DA7210_INMIX_R, 0x1F, 0x1);
  196. }
  197. return 0;
  198. }
  199. /*
  200. * Set PCM DAI word length.
  201. */
  202. static int da7210_hw_params(struct snd_pcm_substream *substream,
  203. struct snd_pcm_hw_params *params,
  204. struct snd_soc_dai *dai)
  205. {
  206. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  207. struct snd_soc_codec *codec = rtd->codec;
  208. u32 dai_cfg1;
  209. u32 hpf_reg, hpf_mask, hpf_value;
  210. u32 fs, bypass;
  211. /* set DAI source to Left and Right ADC */
  212. snd_soc_write(codec, DA7210_DAI_SRC_SEL,
  213. DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
  214. /* Enable DAI */
  215. snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
  216. dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1);
  217. switch (params_format(params)) {
  218. case SNDRV_PCM_FORMAT_S16_LE:
  219. dai_cfg1 |= DA7210_DAI_WORD_S16_LE;
  220. break;
  221. case SNDRV_PCM_FORMAT_S20_3LE:
  222. dai_cfg1 |= DA7210_DAI_WORD_S20_3LE;
  223. break;
  224. case SNDRV_PCM_FORMAT_S24_LE:
  225. dai_cfg1 |= DA7210_DAI_WORD_S24_LE;
  226. break;
  227. case SNDRV_PCM_FORMAT_S32_LE:
  228. dai_cfg1 |= DA7210_DAI_WORD_S32_LE;
  229. break;
  230. default:
  231. return -EINVAL;
  232. }
  233. snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
  234. hpf_reg = (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) ?
  235. DA7210_DAC_HPF : DA7210_ADC_HPF;
  236. switch (params_rate(params)) {
  237. case 8000:
  238. fs = DA7210_PLL_FS_8000;
  239. hpf_mask = DA7210_VOICE_F0_MASK | DA7210_VOICE_EN;
  240. hpf_value = DA7210_VOICE_F0_25 | DA7210_VOICE_EN;
  241. bypass = DA7210_PLL_BYP;
  242. break;
  243. case 11025:
  244. fs = DA7210_PLL_FS_11025;
  245. hpf_mask = DA7210_VOICE_F0_MASK | DA7210_VOICE_EN;
  246. hpf_value = DA7210_VOICE_F0_25 | DA7210_VOICE_EN;
  247. bypass = 0;
  248. break;
  249. case 12000:
  250. fs = DA7210_PLL_FS_12000;
  251. hpf_mask = DA7210_VOICE_F0_MASK | DA7210_VOICE_EN;
  252. hpf_value = DA7210_VOICE_F0_25 | DA7210_VOICE_EN;
  253. bypass = DA7210_PLL_BYP;
  254. break;
  255. case 16000:
  256. fs = DA7210_PLL_FS_16000;
  257. hpf_mask = DA7210_VOICE_F0_MASK | DA7210_VOICE_EN;
  258. hpf_value = DA7210_VOICE_F0_25 | DA7210_VOICE_EN;
  259. bypass = DA7210_PLL_BYP;
  260. break;
  261. case 22050:
  262. fs = DA7210_PLL_FS_22050;
  263. hpf_mask = DA7210_VOICE_EN;
  264. hpf_value = 0;
  265. bypass = 0;
  266. break;
  267. case 32000:
  268. fs = DA7210_PLL_FS_32000;
  269. hpf_mask = DA7210_VOICE_EN;
  270. hpf_value = 0;
  271. bypass = DA7210_PLL_BYP;
  272. break;
  273. case 44100:
  274. fs = DA7210_PLL_FS_44100;
  275. hpf_mask = DA7210_VOICE_EN;
  276. hpf_value = 0;
  277. bypass = 0;
  278. break;
  279. case 48000:
  280. fs = DA7210_PLL_FS_48000;
  281. hpf_mask = DA7210_VOICE_EN;
  282. hpf_value = 0;
  283. bypass = DA7210_PLL_BYP;
  284. break;
  285. case 88200:
  286. fs = DA7210_PLL_FS_88200;
  287. hpf_mask = DA7210_VOICE_EN;
  288. hpf_value = 0;
  289. bypass = 0;
  290. break;
  291. case 96000:
  292. fs = DA7210_PLL_FS_96000;
  293. hpf_mask = DA7210_VOICE_EN;
  294. hpf_value = 0;
  295. bypass = DA7210_PLL_BYP;
  296. break;
  297. default:
  298. return -EINVAL;
  299. }
  300. /* Disable active mode */
  301. snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
  302. snd_soc_update_bits(codec, hpf_reg, hpf_mask, hpf_value);
  303. snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
  304. snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass);
  305. /* Enable active mode */
  306. snd_soc_update_bits(codec, DA7210_STARTUP1,
  307. DA7210_SC_MST_EN, DA7210_SC_MST_EN);
  308. return 0;
  309. }
  310. /*
  311. * Set DAI mode and Format
  312. */
  313. static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
  314. {
  315. struct snd_soc_codec *codec = codec_dai->codec;
  316. u32 dai_cfg1;
  317. u32 dai_cfg3;
  318. dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1);
  319. dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3);
  320. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  321. case SND_SOC_DAIFMT_CBM_CFM:
  322. dai_cfg1 |= DA7210_DAI_MODE_MASTER;
  323. break;
  324. case SND_SOC_DAIFMT_CBS_CFS:
  325. dai_cfg1 |= DA7210_DAI_MODE_SLAVE;
  326. break;
  327. default:
  328. return -EINVAL;
  329. }
  330. /* FIXME
  331. *
  332. * It support I2S only now
  333. */
  334. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  335. case SND_SOC_DAIFMT_I2S:
  336. dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE;
  337. break;
  338. case SND_SOC_DAIFMT_LEFT_J:
  339. dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J;
  340. break;
  341. case SND_SOC_DAIFMT_RIGHT_J:
  342. dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J;
  343. break;
  344. default:
  345. return -EINVAL;
  346. }
  347. /* FIXME
  348. *
  349. * It support 64bit data transmission only now
  350. */
  351. dai_cfg1 |= DA7210_DAI_FLEN_64BIT;
  352. snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
  353. snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3);
  354. return 0;
  355. }
  356. #define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  357. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
  358. /* DAI operations */
  359. static struct snd_soc_dai_ops da7210_dai_ops = {
  360. .startup = da7210_startup,
  361. .hw_params = da7210_hw_params,
  362. .set_fmt = da7210_set_dai_fmt,
  363. };
  364. static struct snd_soc_dai_driver da7210_dai = {
  365. .name = "da7210-hifi",
  366. /* playback capabilities */
  367. .playback = {
  368. .stream_name = "Playback",
  369. .channels_min = 1,
  370. .channels_max = 2,
  371. .rates = SNDRV_PCM_RATE_8000_96000,
  372. .formats = DA7210_FORMATS,
  373. },
  374. /* capture capabilities */
  375. .capture = {
  376. .stream_name = "Capture",
  377. .channels_min = 1,
  378. .channels_max = 2,
  379. .rates = SNDRV_PCM_RATE_8000_96000,
  380. .formats = DA7210_FORMATS,
  381. },
  382. .ops = &da7210_dai_ops,
  383. .symmetric_rates = 1,
  384. };
  385. static int da7210_probe(struct snd_soc_codec *codec)
  386. {
  387. struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
  388. int ret;
  389. dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
  390. ret = snd_soc_codec_set_cache_io(codec, 8, 8, da7210->control_type);
  391. if (ret < 0) {
  392. dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
  393. return ret;
  394. }
  395. /* FIXME
  396. *
  397. * This driver use fixed value here
  398. * And below settings expects MCLK = 12.288MHz
  399. *
  400. * When you select different MCLK, please check...
  401. * DA7210_PLL_DIV1 val
  402. * DA7210_PLL_DIV2 val
  403. * DA7210_PLL_DIV3 val
  404. * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx
  405. */
  406. /*
  407. * make sure that DA7210 use bypass mode before start up
  408. */
  409. snd_soc_write(codec, DA7210_STARTUP1, 0);
  410. snd_soc_write(codec, DA7210_PLL_DIV3,
  411. DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
  412. /*
  413. * ADC settings
  414. */
  415. /* Enable Left & Right MIC PGA and Mic Bias */
  416. snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
  417. snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
  418. /* Enable Left and Right input PGA */
  419. snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN);
  420. snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN);
  421. /* Enable Left and Right ADC */
  422. snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN);
  423. /*
  424. * DAC settings
  425. */
  426. /* Enable Left and Right DAC */
  427. snd_soc_write(codec, DA7210_DAC_SEL,
  428. DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN |
  429. DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN);
  430. /* Enable Left and Right out PGA */
  431. snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN);
  432. snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN);
  433. /* Enable Left and Right HeadPhone PGA */
  434. snd_soc_write(codec, DA7210_HP_CFG,
  435. DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
  436. DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
  437. /* Diable PLL and bypass it */
  438. snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
  439. /*
  440. * If 48kHz sound came, it use bypass mode,
  441. * and when it is 44.1kHz, it use PLL.
  442. *
  443. * This time, this driver sets PLL always ON
  444. * and controls bypass/PLL mode by switching
  445. * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit.
  446. * see da7210_hw_params
  447. */
  448. snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
  449. snd_soc_write(codec, DA7210_PLL_DIV2, 0x99);
  450. snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A |
  451. DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
  452. snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
  453. /* As suggested by Dialog */
  454. snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x8B); /* unlock */
  455. snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0xB4);
  456. snd_soc_write(codec, DA7210_A_PLL1, 0x01);
  457. snd_soc_write(codec, DA7210_A_CP_MODE, 0x7C);
  458. snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x00); /* re-lock */
  459. snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0x00);
  460. /* Activate all enabled subsystem */
  461. snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
  462. dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
  463. return 0;
  464. }
  465. static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
  466. .probe = da7210_probe,
  467. .reg_cache_size = ARRAY_SIZE(da7210_reg),
  468. .reg_word_size = sizeof(u8),
  469. .reg_cache_default = da7210_reg,
  470. .volatile_register = da7210_volatile_register,
  471. .controls = da7210_snd_controls,
  472. .num_controls = ARRAY_SIZE(da7210_snd_controls),
  473. };
  474. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  475. static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
  476. const struct i2c_device_id *id)
  477. {
  478. struct da7210_priv *da7210;
  479. int ret;
  480. da7210 = kzalloc(sizeof(struct da7210_priv), GFP_KERNEL);
  481. if (!da7210)
  482. return -ENOMEM;
  483. i2c_set_clientdata(i2c, da7210);
  484. da7210->control_type = SND_SOC_I2C;
  485. ret = snd_soc_register_codec(&i2c->dev,
  486. &soc_codec_dev_da7210, &da7210_dai, 1);
  487. if (ret < 0)
  488. kfree(da7210);
  489. return ret;
  490. }
  491. static int __devexit da7210_i2c_remove(struct i2c_client *client)
  492. {
  493. snd_soc_unregister_codec(&client->dev);
  494. kfree(i2c_get_clientdata(client));
  495. return 0;
  496. }
  497. static const struct i2c_device_id da7210_i2c_id[] = {
  498. { "da7210", 0 },
  499. { }
  500. };
  501. MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
  502. /* I2C codec control layer */
  503. static struct i2c_driver da7210_i2c_driver = {
  504. .driver = {
  505. .name = "da7210-codec",
  506. .owner = THIS_MODULE,
  507. },
  508. .probe = da7210_i2c_probe,
  509. .remove = __devexit_p(da7210_i2c_remove),
  510. .id_table = da7210_i2c_id,
  511. };
  512. #endif
  513. static int __init da7210_modinit(void)
  514. {
  515. int ret = 0;
  516. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  517. ret = i2c_add_driver(&da7210_i2c_driver);
  518. #endif
  519. return ret;
  520. }
  521. module_init(da7210_modinit);
  522. static void __exit da7210_exit(void)
  523. {
  524. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  525. i2c_del_driver(&da7210_i2c_driver);
  526. #endif
  527. }
  528. module_exit(da7210_exit);
  529. MODULE_DESCRIPTION("ASoC DA7210 driver");
  530. MODULE_AUTHOR("David Chen, Kuninori Morimoto");
  531. MODULE_LICENSE("GPL");