da7210.c 16 KB

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