ak4671.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /*
  2. * ak4671.c -- audio driver for AK4671
  3. *
  4. * Copyright (C) 2009 Samsung Electronics Co.Ltd
  5. * Author: Joonyoung Shim <jy0922.shim@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/i2c.h>
  16. #include <linux/delay.h>
  17. #include <linux/slab.h>
  18. #include <sound/soc.h>
  19. #include <sound/initval.h>
  20. #include <sound/tlv.h>
  21. #include "ak4671.h"
  22. /* codec private data */
  23. struct ak4671_priv {
  24. enum snd_soc_control_type control_type;
  25. };
  26. /* ak4671 register cache & default register settings */
  27. static const u8 ak4671_reg[AK4671_CACHEREGNUM] = {
  28. 0x00, /* AK4671_AD_DA_POWER_MANAGEMENT (0x00) */
  29. 0xf6, /* AK4671_PLL_MODE_SELECT0 (0x01) */
  30. 0x00, /* AK4671_PLL_MODE_SELECT1 (0x02) */
  31. 0x02, /* AK4671_FORMAT_SELECT (0x03) */
  32. 0x00, /* AK4671_MIC_SIGNAL_SELECT (0x04) */
  33. 0x55, /* AK4671_MIC_AMP_GAIN (0x05) */
  34. 0x00, /* AK4671_MIXING_POWER_MANAGEMENT0 (0x06) */
  35. 0x00, /* AK4671_MIXING_POWER_MANAGEMENT1 (0x07) */
  36. 0xb5, /* AK4671_OUTPUT_VOLUME_CONTROL (0x08) */
  37. 0x00, /* AK4671_LOUT1_SIGNAL_SELECT (0x09) */
  38. 0x00, /* AK4671_ROUT1_SIGNAL_SELECT (0x0a) */
  39. 0x00, /* AK4671_LOUT2_SIGNAL_SELECT (0x0b) */
  40. 0x00, /* AK4671_ROUT2_SIGNAL_SELECT (0x0c) */
  41. 0x00, /* AK4671_LOUT3_SIGNAL_SELECT (0x0d) */
  42. 0x00, /* AK4671_ROUT3_SIGNAL_SELECT (0x0e) */
  43. 0x00, /* AK4671_LOUT1_POWER_MANAGERMENT (0x0f) */
  44. 0x00, /* AK4671_LOUT2_POWER_MANAGERMENT (0x10) */
  45. 0x80, /* AK4671_LOUT3_POWER_MANAGERMENT (0x11) */
  46. 0x91, /* AK4671_LCH_INPUT_VOLUME_CONTROL (0x12) */
  47. 0x91, /* AK4671_RCH_INPUT_VOLUME_CONTROL (0x13) */
  48. 0xe1, /* AK4671_ALC_REFERENCE_SELECT (0x14) */
  49. 0x00, /* AK4671_DIGITAL_MIXING_CONTROL (0x15) */
  50. 0x00, /* AK4671_ALC_TIMER_SELECT (0x16) */
  51. 0x00, /* AK4671_ALC_MODE_CONTROL (0x17) */
  52. 0x02, /* AK4671_MODE_CONTROL1 (0x18) */
  53. 0x01, /* AK4671_MODE_CONTROL2 (0x19) */
  54. 0x18, /* AK4671_LCH_OUTPUT_VOLUME_CONTROL (0x1a) */
  55. 0x18, /* AK4671_RCH_OUTPUT_VOLUME_CONTROL (0x1b) */
  56. 0x00, /* AK4671_SIDETONE_A_CONTROL (0x1c) */
  57. 0x02, /* AK4671_DIGITAL_FILTER_SELECT (0x1d) */
  58. 0x00, /* AK4671_FIL3_COEFFICIENT0 (0x1e) */
  59. 0x00, /* AK4671_FIL3_COEFFICIENT1 (0x1f) */
  60. 0x00, /* AK4671_FIL3_COEFFICIENT2 (0x20) */
  61. 0x00, /* AK4671_FIL3_COEFFICIENT3 (0x21) */
  62. 0x00, /* AK4671_EQ_COEFFICIENT0 (0x22) */
  63. 0x00, /* AK4671_EQ_COEFFICIENT1 (0x23) */
  64. 0x00, /* AK4671_EQ_COEFFICIENT2 (0x24) */
  65. 0x00, /* AK4671_EQ_COEFFICIENT3 (0x25) */
  66. 0x00, /* AK4671_EQ_COEFFICIENT4 (0x26) */
  67. 0x00, /* AK4671_EQ_COEFFICIENT5 (0x27) */
  68. 0xa9, /* AK4671_FIL1_COEFFICIENT0 (0x28) */
  69. 0x1f, /* AK4671_FIL1_COEFFICIENT1 (0x29) */
  70. 0xad, /* AK4671_FIL1_COEFFICIENT2 (0x2a) */
  71. 0x20, /* AK4671_FIL1_COEFFICIENT3 (0x2b) */
  72. 0x00, /* AK4671_FIL2_COEFFICIENT0 (0x2c) */
  73. 0x00, /* AK4671_FIL2_COEFFICIENT1 (0x2d) */
  74. 0x00, /* AK4671_FIL2_COEFFICIENT2 (0x2e) */
  75. 0x00, /* AK4671_FIL2_COEFFICIENT3 (0x2f) */
  76. 0x00, /* AK4671_DIGITAL_FILTER_SELECT2 (0x30) */
  77. 0x00, /* this register not used */
  78. 0x00, /* AK4671_E1_COEFFICIENT0 (0x32) */
  79. 0x00, /* AK4671_E1_COEFFICIENT1 (0x33) */
  80. 0x00, /* AK4671_E1_COEFFICIENT2 (0x34) */
  81. 0x00, /* AK4671_E1_COEFFICIENT3 (0x35) */
  82. 0x00, /* AK4671_E1_COEFFICIENT4 (0x36) */
  83. 0x00, /* AK4671_E1_COEFFICIENT5 (0x37) */
  84. 0x00, /* AK4671_E2_COEFFICIENT0 (0x38) */
  85. 0x00, /* AK4671_E2_COEFFICIENT1 (0x39) */
  86. 0x00, /* AK4671_E2_COEFFICIENT2 (0x3a) */
  87. 0x00, /* AK4671_E2_COEFFICIENT3 (0x3b) */
  88. 0x00, /* AK4671_E2_COEFFICIENT4 (0x3c) */
  89. 0x00, /* AK4671_E2_COEFFICIENT5 (0x3d) */
  90. 0x00, /* AK4671_E3_COEFFICIENT0 (0x3e) */
  91. 0x00, /* AK4671_E3_COEFFICIENT1 (0x3f) */
  92. 0x00, /* AK4671_E3_COEFFICIENT2 (0x40) */
  93. 0x00, /* AK4671_E3_COEFFICIENT3 (0x41) */
  94. 0x00, /* AK4671_E3_COEFFICIENT4 (0x42) */
  95. 0x00, /* AK4671_E3_COEFFICIENT5 (0x43) */
  96. 0x00, /* AK4671_E4_COEFFICIENT0 (0x44) */
  97. 0x00, /* AK4671_E4_COEFFICIENT1 (0x45) */
  98. 0x00, /* AK4671_E4_COEFFICIENT2 (0x46) */
  99. 0x00, /* AK4671_E4_COEFFICIENT3 (0x47) */
  100. 0x00, /* AK4671_E4_COEFFICIENT4 (0x48) */
  101. 0x00, /* AK4671_E4_COEFFICIENT5 (0x49) */
  102. 0x00, /* AK4671_E5_COEFFICIENT0 (0x4a) */
  103. 0x00, /* AK4671_E5_COEFFICIENT1 (0x4b) */
  104. 0x00, /* AK4671_E5_COEFFICIENT2 (0x4c) */
  105. 0x00, /* AK4671_E5_COEFFICIENT3 (0x4d) */
  106. 0x00, /* AK4671_E5_COEFFICIENT4 (0x4e) */
  107. 0x00, /* AK4671_E5_COEFFICIENT5 (0x4f) */
  108. 0x88, /* AK4671_EQ_CONTROL_250HZ_100HZ (0x50) */
  109. 0x88, /* AK4671_EQ_CONTROL_3500HZ_1KHZ (0x51) */
  110. 0x08, /* AK4671_EQ_CONTRO_10KHZ (0x52) */
  111. 0x00, /* AK4671_PCM_IF_CONTROL0 (0x53) */
  112. 0x00, /* AK4671_PCM_IF_CONTROL1 (0x54) */
  113. 0x00, /* AK4671_PCM_IF_CONTROL2 (0x55) */
  114. 0x18, /* AK4671_DIGITAL_VOLUME_B_CONTROL (0x56) */
  115. 0x18, /* AK4671_DIGITAL_VOLUME_C_CONTROL (0x57) */
  116. 0x00, /* AK4671_SIDETONE_VOLUME_CONTROL (0x58) */
  117. 0x00, /* AK4671_DIGITAL_MIXING_CONTROL2 (0x59) */
  118. 0x00, /* AK4671_SAR_ADC_CONTROL (0x5a) */
  119. };
  120. /*
  121. * LOUT1/ROUT1 output volume control:
  122. * from -24 to 6 dB in 6 dB steps (mute instead of -30 dB)
  123. */
  124. static DECLARE_TLV_DB_SCALE(out1_tlv, -3000, 600, 1);
  125. /*
  126. * LOUT2/ROUT2 output volume control:
  127. * from -33 to 6 dB in 3 dB steps (mute instead of -33 dB)
  128. */
  129. static DECLARE_TLV_DB_SCALE(out2_tlv, -3300, 300, 1);
  130. /*
  131. * LOUT3/ROUT3 output volume control:
  132. * from -6 to 3 dB in 3 dB steps
  133. */
  134. static DECLARE_TLV_DB_SCALE(out3_tlv, -600, 300, 0);
  135. /*
  136. * Mic amp gain control:
  137. * from -15 to 30 dB in 3 dB steps
  138. * REVISIT: The actual min value(0x01) is -12 dB and the reg value 0x00 is not
  139. * available
  140. */
  141. static DECLARE_TLV_DB_SCALE(mic_amp_tlv, -1500, 300, 0);
  142. static const struct snd_kcontrol_new ak4671_snd_controls[] = {
  143. /* Common playback gain controls */
  144. SOC_SINGLE_TLV("Line Output1 Playback Volume",
  145. AK4671_OUTPUT_VOLUME_CONTROL, 0, 0x6, 0, out1_tlv),
  146. SOC_SINGLE_TLV("Headphone Output2 Playback Volume",
  147. AK4671_OUTPUT_VOLUME_CONTROL, 4, 0xd, 0, out2_tlv),
  148. SOC_SINGLE_TLV("Line Output3 Playback Volume",
  149. AK4671_LOUT3_POWER_MANAGERMENT, 6, 0x3, 0, out3_tlv),
  150. /* Common capture gain controls */
  151. SOC_DOUBLE_TLV("Mic Amp Capture Volume",
  152. AK4671_MIC_AMP_GAIN, 0, 4, 0xf, 0, mic_amp_tlv),
  153. };
  154. /* event handlers */
  155. static int ak4671_out2_event(struct snd_soc_dapm_widget *w,
  156. struct snd_kcontrol *kcontrol, int event)
  157. {
  158. struct snd_soc_codec *codec = w->codec;
  159. switch (event) {
  160. case SND_SOC_DAPM_POST_PMU:
  161. snd_soc_update_bits(codec, AK4671_LOUT2_POWER_MANAGERMENT,
  162. AK4671_MUTEN, AK4671_MUTEN);
  163. break;
  164. case SND_SOC_DAPM_PRE_PMD:
  165. snd_soc_update_bits(codec, AK4671_LOUT2_POWER_MANAGERMENT,
  166. AK4671_MUTEN, 0);
  167. break;
  168. }
  169. return 0;
  170. }
  171. /* Output Mixers */
  172. static const struct snd_kcontrol_new ak4671_lout1_mixer_controls[] = {
  173. SOC_DAPM_SINGLE("DACL", AK4671_LOUT1_SIGNAL_SELECT, 0, 1, 0),
  174. SOC_DAPM_SINGLE("LINL1", AK4671_LOUT1_SIGNAL_SELECT, 1, 1, 0),
  175. SOC_DAPM_SINGLE("LINL2", AK4671_LOUT1_SIGNAL_SELECT, 2, 1, 0),
  176. SOC_DAPM_SINGLE("LINL3", AK4671_LOUT1_SIGNAL_SELECT, 3, 1, 0),
  177. SOC_DAPM_SINGLE("LINL4", AK4671_LOUT1_SIGNAL_SELECT, 4, 1, 0),
  178. SOC_DAPM_SINGLE("LOOPL", AK4671_LOUT1_SIGNAL_SELECT, 5, 1, 0),
  179. };
  180. static const struct snd_kcontrol_new ak4671_rout1_mixer_controls[] = {
  181. SOC_DAPM_SINGLE("DACR", AK4671_ROUT1_SIGNAL_SELECT, 0, 1, 0),
  182. SOC_DAPM_SINGLE("RINR1", AK4671_ROUT1_SIGNAL_SELECT, 1, 1, 0),
  183. SOC_DAPM_SINGLE("RINR2", AK4671_ROUT1_SIGNAL_SELECT, 2, 1, 0),
  184. SOC_DAPM_SINGLE("RINR3", AK4671_ROUT1_SIGNAL_SELECT, 3, 1, 0),
  185. SOC_DAPM_SINGLE("RINR4", AK4671_ROUT1_SIGNAL_SELECT, 4, 1, 0),
  186. SOC_DAPM_SINGLE("LOOPR", AK4671_ROUT1_SIGNAL_SELECT, 5, 1, 0),
  187. };
  188. static const struct snd_kcontrol_new ak4671_lout2_mixer_controls[] = {
  189. SOC_DAPM_SINGLE("DACHL", AK4671_LOUT2_SIGNAL_SELECT, 0, 1, 0),
  190. SOC_DAPM_SINGLE("LINH1", AK4671_LOUT2_SIGNAL_SELECT, 1, 1, 0),
  191. SOC_DAPM_SINGLE("LINH2", AK4671_LOUT2_SIGNAL_SELECT, 2, 1, 0),
  192. SOC_DAPM_SINGLE("LINH3", AK4671_LOUT2_SIGNAL_SELECT, 3, 1, 0),
  193. SOC_DAPM_SINGLE("LINH4", AK4671_LOUT2_SIGNAL_SELECT, 4, 1, 0),
  194. SOC_DAPM_SINGLE("LOOPHL", AK4671_LOUT2_SIGNAL_SELECT, 5, 1, 0),
  195. };
  196. static const struct snd_kcontrol_new ak4671_rout2_mixer_controls[] = {
  197. SOC_DAPM_SINGLE("DACHR", AK4671_ROUT2_SIGNAL_SELECT, 0, 1, 0),
  198. SOC_DAPM_SINGLE("RINH1", AK4671_ROUT2_SIGNAL_SELECT, 1, 1, 0),
  199. SOC_DAPM_SINGLE("RINH2", AK4671_ROUT2_SIGNAL_SELECT, 2, 1, 0),
  200. SOC_DAPM_SINGLE("RINH3", AK4671_ROUT2_SIGNAL_SELECT, 3, 1, 0),
  201. SOC_DAPM_SINGLE("RINH4", AK4671_ROUT2_SIGNAL_SELECT, 4, 1, 0),
  202. SOC_DAPM_SINGLE("LOOPHR", AK4671_ROUT2_SIGNAL_SELECT, 5, 1, 0),
  203. };
  204. static const struct snd_kcontrol_new ak4671_lout3_mixer_controls[] = {
  205. SOC_DAPM_SINGLE("DACSL", AK4671_LOUT3_SIGNAL_SELECT, 0, 1, 0),
  206. SOC_DAPM_SINGLE("LINS1", AK4671_LOUT3_SIGNAL_SELECT, 1, 1, 0),
  207. SOC_DAPM_SINGLE("LINS2", AK4671_LOUT3_SIGNAL_SELECT, 2, 1, 0),
  208. SOC_DAPM_SINGLE("LINS3", AK4671_LOUT3_SIGNAL_SELECT, 3, 1, 0),
  209. SOC_DAPM_SINGLE("LINS4", AK4671_LOUT3_SIGNAL_SELECT, 4, 1, 0),
  210. SOC_DAPM_SINGLE("LOOPSL", AK4671_LOUT3_SIGNAL_SELECT, 5, 1, 0),
  211. };
  212. static const struct snd_kcontrol_new ak4671_rout3_mixer_controls[] = {
  213. SOC_DAPM_SINGLE("DACSR", AK4671_ROUT3_SIGNAL_SELECT, 0, 1, 0),
  214. SOC_DAPM_SINGLE("RINS1", AK4671_ROUT3_SIGNAL_SELECT, 1, 1, 0),
  215. SOC_DAPM_SINGLE("RINS2", AK4671_ROUT3_SIGNAL_SELECT, 2, 1, 0),
  216. SOC_DAPM_SINGLE("RINS3", AK4671_ROUT3_SIGNAL_SELECT, 3, 1, 0),
  217. SOC_DAPM_SINGLE("RINS4", AK4671_ROUT3_SIGNAL_SELECT, 4, 1, 0),
  218. SOC_DAPM_SINGLE("LOOPSR", AK4671_ROUT3_SIGNAL_SELECT, 5, 1, 0),
  219. };
  220. /* Input MUXs */
  221. static const char *ak4671_lin_mux_texts[] =
  222. {"LIN1", "LIN2", "LIN3", "LIN4"};
  223. static const struct soc_enum ak4671_lin_mux_enum =
  224. SOC_ENUM_SINGLE(AK4671_MIC_SIGNAL_SELECT, 0,
  225. ARRAY_SIZE(ak4671_lin_mux_texts),
  226. ak4671_lin_mux_texts);
  227. static const struct snd_kcontrol_new ak4671_lin_mux_control =
  228. SOC_DAPM_ENUM("Route", ak4671_lin_mux_enum);
  229. static const char *ak4671_rin_mux_texts[] =
  230. {"RIN1", "RIN2", "RIN3", "RIN4"};
  231. static const struct soc_enum ak4671_rin_mux_enum =
  232. SOC_ENUM_SINGLE(AK4671_MIC_SIGNAL_SELECT, 2,
  233. ARRAY_SIZE(ak4671_rin_mux_texts),
  234. ak4671_rin_mux_texts);
  235. static const struct snd_kcontrol_new ak4671_rin_mux_control =
  236. SOC_DAPM_ENUM("Route", ak4671_rin_mux_enum);
  237. static const struct snd_soc_dapm_widget ak4671_dapm_widgets[] = {
  238. /* Inputs */
  239. SND_SOC_DAPM_INPUT("LIN1"),
  240. SND_SOC_DAPM_INPUT("RIN1"),
  241. SND_SOC_DAPM_INPUT("LIN2"),
  242. SND_SOC_DAPM_INPUT("RIN2"),
  243. SND_SOC_DAPM_INPUT("LIN3"),
  244. SND_SOC_DAPM_INPUT("RIN3"),
  245. SND_SOC_DAPM_INPUT("LIN4"),
  246. SND_SOC_DAPM_INPUT("RIN4"),
  247. /* Outputs */
  248. SND_SOC_DAPM_OUTPUT("LOUT1"),
  249. SND_SOC_DAPM_OUTPUT("ROUT1"),
  250. SND_SOC_DAPM_OUTPUT("LOUT2"),
  251. SND_SOC_DAPM_OUTPUT("ROUT2"),
  252. SND_SOC_DAPM_OUTPUT("LOUT3"),
  253. SND_SOC_DAPM_OUTPUT("ROUT3"),
  254. /* DAC */
  255. SND_SOC_DAPM_DAC("DAC Left", "Left HiFi Playback",
  256. AK4671_AD_DA_POWER_MANAGEMENT, 6, 0),
  257. SND_SOC_DAPM_DAC("DAC Right", "Right HiFi Playback",
  258. AK4671_AD_DA_POWER_MANAGEMENT, 7, 0),
  259. /* ADC */
  260. SND_SOC_DAPM_ADC("ADC Left", "Left HiFi Capture",
  261. AK4671_AD_DA_POWER_MANAGEMENT, 4, 0),
  262. SND_SOC_DAPM_ADC("ADC Right", "Right HiFi Capture",
  263. AK4671_AD_DA_POWER_MANAGEMENT, 5, 0),
  264. /* PGA */
  265. SND_SOC_DAPM_PGA("LOUT2 Mix Amp",
  266. AK4671_LOUT2_POWER_MANAGERMENT, 5, 0, NULL, 0),
  267. SND_SOC_DAPM_PGA("ROUT2 Mix Amp",
  268. AK4671_LOUT2_POWER_MANAGERMENT, 6, 0, NULL, 0),
  269. SND_SOC_DAPM_PGA("LIN1 Mixing Circuit",
  270. AK4671_MIXING_POWER_MANAGEMENT1, 0, 0, NULL, 0),
  271. SND_SOC_DAPM_PGA("RIN1 Mixing Circuit",
  272. AK4671_MIXING_POWER_MANAGEMENT1, 1, 0, NULL, 0),
  273. SND_SOC_DAPM_PGA("LIN2 Mixing Circuit",
  274. AK4671_MIXING_POWER_MANAGEMENT1, 2, 0, NULL, 0),
  275. SND_SOC_DAPM_PGA("RIN2 Mixing Circuit",
  276. AK4671_MIXING_POWER_MANAGEMENT1, 3, 0, NULL, 0),
  277. SND_SOC_DAPM_PGA("LIN3 Mixing Circuit",
  278. AK4671_MIXING_POWER_MANAGEMENT1, 4, 0, NULL, 0),
  279. SND_SOC_DAPM_PGA("RIN3 Mixing Circuit",
  280. AK4671_MIXING_POWER_MANAGEMENT1, 5, 0, NULL, 0),
  281. SND_SOC_DAPM_PGA("LIN4 Mixing Circuit",
  282. AK4671_MIXING_POWER_MANAGEMENT1, 6, 0, NULL, 0),
  283. SND_SOC_DAPM_PGA("RIN4 Mixing Circuit",
  284. AK4671_MIXING_POWER_MANAGEMENT1, 7, 0, NULL, 0),
  285. /* Output Mixers */
  286. SND_SOC_DAPM_MIXER("LOUT1 Mixer", AK4671_LOUT1_POWER_MANAGERMENT, 0, 0,
  287. &ak4671_lout1_mixer_controls[0],
  288. ARRAY_SIZE(ak4671_lout1_mixer_controls)),
  289. SND_SOC_DAPM_MIXER("ROUT1 Mixer", AK4671_LOUT1_POWER_MANAGERMENT, 1, 0,
  290. &ak4671_rout1_mixer_controls[0],
  291. ARRAY_SIZE(ak4671_rout1_mixer_controls)),
  292. SND_SOC_DAPM_MIXER_E("LOUT2 Mixer", AK4671_LOUT2_POWER_MANAGERMENT,
  293. 0, 0, &ak4671_lout2_mixer_controls[0],
  294. ARRAY_SIZE(ak4671_lout2_mixer_controls),
  295. ak4671_out2_event,
  296. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_PRE_PMD),
  297. SND_SOC_DAPM_MIXER_E("ROUT2 Mixer", AK4671_LOUT2_POWER_MANAGERMENT,
  298. 1, 0, &ak4671_rout2_mixer_controls[0],
  299. ARRAY_SIZE(ak4671_rout2_mixer_controls),
  300. ak4671_out2_event,
  301. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_PRE_PMD),
  302. SND_SOC_DAPM_MIXER("LOUT3 Mixer", AK4671_LOUT3_POWER_MANAGERMENT, 0, 0,
  303. &ak4671_lout3_mixer_controls[0],
  304. ARRAY_SIZE(ak4671_lout3_mixer_controls)),
  305. SND_SOC_DAPM_MIXER("ROUT3 Mixer", AK4671_LOUT3_POWER_MANAGERMENT, 1, 0,
  306. &ak4671_rout3_mixer_controls[0],
  307. ARRAY_SIZE(ak4671_rout3_mixer_controls)),
  308. /* Input MUXs */
  309. SND_SOC_DAPM_MUX("LIN MUX", AK4671_AD_DA_POWER_MANAGEMENT, 2, 0,
  310. &ak4671_lin_mux_control),
  311. SND_SOC_DAPM_MUX("RIN MUX", AK4671_AD_DA_POWER_MANAGEMENT, 3, 0,
  312. &ak4671_rin_mux_control),
  313. /* Mic Power */
  314. SND_SOC_DAPM_MICBIAS("Mic Bias", AK4671_AD_DA_POWER_MANAGEMENT, 1, 0),
  315. /* Supply */
  316. SND_SOC_DAPM_SUPPLY("PMPLL", AK4671_PLL_MODE_SELECT1, 0, 0, NULL, 0),
  317. };
  318. static const struct snd_soc_dapm_route ak4671_intercon[] = {
  319. {"DAC Left", "NULL", "PMPLL"},
  320. {"DAC Right", "NULL", "PMPLL"},
  321. {"ADC Left", "NULL", "PMPLL"},
  322. {"ADC Right", "NULL", "PMPLL"},
  323. /* Outputs */
  324. {"LOUT1", "NULL", "LOUT1 Mixer"},
  325. {"ROUT1", "NULL", "ROUT1 Mixer"},
  326. {"LOUT2", "NULL", "LOUT2 Mix Amp"},
  327. {"ROUT2", "NULL", "ROUT2 Mix Amp"},
  328. {"LOUT3", "NULL", "LOUT3 Mixer"},
  329. {"ROUT3", "NULL", "ROUT3 Mixer"},
  330. {"LOUT1 Mixer", "DACL", "DAC Left"},
  331. {"ROUT1 Mixer", "DACR", "DAC Right"},
  332. {"LOUT2 Mixer", "DACHL", "DAC Left"},
  333. {"ROUT2 Mixer", "DACHR", "DAC Right"},
  334. {"LOUT2 Mix Amp", "NULL", "LOUT2 Mixer"},
  335. {"ROUT2 Mix Amp", "NULL", "ROUT2 Mixer"},
  336. {"LOUT3 Mixer", "DACSL", "DAC Left"},
  337. {"ROUT3 Mixer", "DACSR", "DAC Right"},
  338. /* Inputs */
  339. {"LIN MUX", "LIN1", "LIN1"},
  340. {"LIN MUX", "LIN2", "LIN2"},
  341. {"LIN MUX", "LIN3", "LIN3"},
  342. {"LIN MUX", "LIN4", "LIN4"},
  343. {"RIN MUX", "RIN1", "RIN1"},
  344. {"RIN MUX", "RIN2", "RIN2"},
  345. {"RIN MUX", "RIN3", "RIN3"},
  346. {"RIN MUX", "RIN4", "RIN4"},
  347. {"LIN1", NULL, "Mic Bias"},
  348. {"RIN1", NULL, "Mic Bias"},
  349. {"LIN2", NULL, "Mic Bias"},
  350. {"RIN2", NULL, "Mic Bias"},
  351. {"ADC Left", "NULL", "LIN MUX"},
  352. {"ADC Right", "NULL", "RIN MUX"},
  353. /* Analog Loops */
  354. {"LIN1 Mixing Circuit", "NULL", "LIN1"},
  355. {"RIN1 Mixing Circuit", "NULL", "RIN1"},
  356. {"LIN2 Mixing Circuit", "NULL", "LIN2"},
  357. {"RIN2 Mixing Circuit", "NULL", "RIN2"},
  358. {"LIN3 Mixing Circuit", "NULL", "LIN3"},
  359. {"RIN3 Mixing Circuit", "NULL", "RIN3"},
  360. {"LIN4 Mixing Circuit", "NULL", "LIN4"},
  361. {"RIN4 Mixing Circuit", "NULL", "RIN4"},
  362. {"LOUT1 Mixer", "LINL1", "LIN1 Mixing Circuit"},
  363. {"ROUT1 Mixer", "RINR1", "RIN1 Mixing Circuit"},
  364. {"LOUT2 Mixer", "LINH1", "LIN1 Mixing Circuit"},
  365. {"ROUT2 Mixer", "RINH1", "RIN1 Mixing Circuit"},
  366. {"LOUT3 Mixer", "LINS1", "LIN1 Mixing Circuit"},
  367. {"ROUT3 Mixer", "RINS1", "RIN1 Mixing Circuit"},
  368. {"LOUT1 Mixer", "LINL2", "LIN2 Mixing Circuit"},
  369. {"ROUT1 Mixer", "RINR2", "RIN2 Mixing Circuit"},
  370. {"LOUT2 Mixer", "LINH2", "LIN2 Mixing Circuit"},
  371. {"ROUT2 Mixer", "RINH2", "RIN2 Mixing Circuit"},
  372. {"LOUT3 Mixer", "LINS2", "LIN2 Mixing Circuit"},
  373. {"ROUT3 Mixer", "RINS2", "RIN2 Mixing Circuit"},
  374. {"LOUT1 Mixer", "LINL3", "LIN3 Mixing Circuit"},
  375. {"ROUT1 Mixer", "RINR3", "RIN3 Mixing Circuit"},
  376. {"LOUT2 Mixer", "LINH3", "LIN3 Mixing Circuit"},
  377. {"ROUT2 Mixer", "RINH3", "RIN3 Mixing Circuit"},
  378. {"LOUT3 Mixer", "LINS3", "LIN3 Mixing Circuit"},
  379. {"ROUT3 Mixer", "RINS3", "RIN3 Mixing Circuit"},
  380. {"LOUT1 Mixer", "LINL4", "LIN4 Mixing Circuit"},
  381. {"ROUT1 Mixer", "RINR4", "RIN4 Mixing Circuit"},
  382. {"LOUT2 Mixer", "LINH4", "LIN4 Mixing Circuit"},
  383. {"ROUT2 Mixer", "RINH4", "RIN4 Mixing Circuit"},
  384. {"LOUT3 Mixer", "LINS4", "LIN4 Mixing Circuit"},
  385. {"ROUT3 Mixer", "RINS4", "RIN4 Mixing Circuit"},
  386. };
  387. static int ak4671_hw_params(struct snd_pcm_substream *substream,
  388. struct snd_pcm_hw_params *params,
  389. struct snd_soc_dai *dai)
  390. {
  391. struct snd_soc_codec *codec = dai->codec;
  392. u8 fs;
  393. fs = snd_soc_read(codec, AK4671_PLL_MODE_SELECT0);
  394. fs &= ~AK4671_FS;
  395. switch (params_rate(params)) {
  396. case 8000:
  397. fs |= AK4671_FS_8KHZ;
  398. break;
  399. case 12000:
  400. fs |= AK4671_FS_12KHZ;
  401. break;
  402. case 16000:
  403. fs |= AK4671_FS_16KHZ;
  404. break;
  405. case 24000:
  406. fs |= AK4671_FS_24KHZ;
  407. break;
  408. case 11025:
  409. fs |= AK4671_FS_11_025KHZ;
  410. break;
  411. case 22050:
  412. fs |= AK4671_FS_22_05KHZ;
  413. break;
  414. case 32000:
  415. fs |= AK4671_FS_32KHZ;
  416. break;
  417. case 44100:
  418. fs |= AK4671_FS_44_1KHZ;
  419. break;
  420. case 48000:
  421. fs |= AK4671_FS_48KHZ;
  422. break;
  423. default:
  424. return -EINVAL;
  425. }
  426. snd_soc_write(codec, AK4671_PLL_MODE_SELECT0, fs);
  427. return 0;
  428. }
  429. static int ak4671_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
  430. unsigned int freq, int dir)
  431. {
  432. struct snd_soc_codec *codec = dai->codec;
  433. u8 pll;
  434. pll = snd_soc_read(codec, AK4671_PLL_MODE_SELECT0);
  435. pll &= ~AK4671_PLL;
  436. switch (freq) {
  437. case 11289600:
  438. pll |= AK4671_PLL_11_2896MHZ;
  439. break;
  440. case 12000000:
  441. pll |= AK4671_PLL_12MHZ;
  442. break;
  443. case 12288000:
  444. pll |= AK4671_PLL_12_288MHZ;
  445. break;
  446. case 13000000:
  447. pll |= AK4671_PLL_13MHZ;
  448. break;
  449. case 13500000:
  450. pll |= AK4671_PLL_13_5MHZ;
  451. break;
  452. case 19200000:
  453. pll |= AK4671_PLL_19_2MHZ;
  454. break;
  455. case 24000000:
  456. pll |= AK4671_PLL_24MHZ;
  457. break;
  458. case 26000000:
  459. pll |= AK4671_PLL_26MHZ;
  460. break;
  461. case 27000000:
  462. pll |= AK4671_PLL_27MHZ;
  463. break;
  464. default:
  465. return -EINVAL;
  466. }
  467. snd_soc_write(codec, AK4671_PLL_MODE_SELECT0, pll);
  468. return 0;
  469. }
  470. static int ak4671_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  471. {
  472. struct snd_soc_codec *codec = dai->codec;
  473. u8 mode;
  474. u8 format;
  475. /* set master/slave audio interface */
  476. mode = snd_soc_read(codec, AK4671_PLL_MODE_SELECT1);
  477. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  478. case SND_SOC_DAIFMT_CBM_CFM:
  479. mode |= AK4671_M_S;
  480. break;
  481. case SND_SOC_DAIFMT_CBM_CFS:
  482. mode &= ~(AK4671_M_S);
  483. break;
  484. default:
  485. return -EINVAL;
  486. }
  487. /* interface format */
  488. format = snd_soc_read(codec, AK4671_FORMAT_SELECT);
  489. format &= ~AK4671_DIF;
  490. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  491. case SND_SOC_DAIFMT_I2S:
  492. format |= AK4671_DIF_I2S_MODE;
  493. break;
  494. case SND_SOC_DAIFMT_LEFT_J:
  495. format |= AK4671_DIF_MSB_MODE;
  496. break;
  497. case SND_SOC_DAIFMT_DSP_A:
  498. format |= AK4671_DIF_DSP_MODE;
  499. format |= AK4671_BCKP;
  500. format |= AK4671_MSBS;
  501. break;
  502. default:
  503. return -EINVAL;
  504. }
  505. /* set mode and format */
  506. snd_soc_write(codec, AK4671_PLL_MODE_SELECT1, mode);
  507. snd_soc_write(codec, AK4671_FORMAT_SELECT, format);
  508. return 0;
  509. }
  510. static int ak4671_set_bias_level(struct snd_soc_codec *codec,
  511. enum snd_soc_bias_level level)
  512. {
  513. switch (level) {
  514. case SND_SOC_BIAS_ON:
  515. case SND_SOC_BIAS_PREPARE:
  516. case SND_SOC_BIAS_STANDBY:
  517. snd_soc_update_bits(codec, AK4671_AD_DA_POWER_MANAGEMENT,
  518. AK4671_PMVCM, AK4671_PMVCM);
  519. break;
  520. case SND_SOC_BIAS_OFF:
  521. snd_soc_write(codec, AK4671_AD_DA_POWER_MANAGEMENT, 0x00);
  522. break;
  523. }
  524. codec->dapm.bias_level = level;
  525. return 0;
  526. }
  527. #define AK4671_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
  528. SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
  529. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
  530. SNDRV_PCM_RATE_48000)
  531. #define AK4671_FORMATS SNDRV_PCM_FMTBIT_S16_LE
  532. static const struct snd_soc_dai_ops ak4671_dai_ops = {
  533. .hw_params = ak4671_hw_params,
  534. .set_sysclk = ak4671_set_dai_sysclk,
  535. .set_fmt = ak4671_set_dai_fmt,
  536. };
  537. static struct snd_soc_dai_driver ak4671_dai = {
  538. .name = "ak4671-hifi",
  539. .playback = {
  540. .stream_name = "Playback",
  541. .channels_min = 1,
  542. .channels_max = 2,
  543. .rates = AK4671_RATES,
  544. .formats = AK4671_FORMATS,},
  545. .capture = {
  546. .stream_name = "Capture",
  547. .channels_min = 1,
  548. .channels_max = 2,
  549. .rates = AK4671_RATES,
  550. .formats = AK4671_FORMATS,},
  551. .ops = &ak4671_dai_ops,
  552. };
  553. static int ak4671_probe(struct snd_soc_codec *codec)
  554. {
  555. struct ak4671_priv *ak4671 = snd_soc_codec_get_drvdata(codec);
  556. int ret;
  557. ret = snd_soc_codec_set_cache_io(codec, 8, 8, ak4671->control_type);
  558. if (ret < 0) {
  559. dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
  560. return ret;
  561. }
  562. snd_soc_add_codec_controls(codec, ak4671_snd_controls,
  563. ARRAY_SIZE(ak4671_snd_controls));
  564. ak4671_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  565. return ret;
  566. }
  567. static int ak4671_remove(struct snd_soc_codec *codec)
  568. {
  569. ak4671_set_bias_level(codec, SND_SOC_BIAS_OFF);
  570. return 0;
  571. }
  572. static struct snd_soc_codec_driver soc_codec_dev_ak4671 = {
  573. .probe = ak4671_probe,
  574. .remove = ak4671_remove,
  575. .set_bias_level = ak4671_set_bias_level,
  576. .reg_cache_size = AK4671_CACHEREGNUM,
  577. .reg_word_size = sizeof(u8),
  578. .reg_cache_default = ak4671_reg,
  579. .dapm_widgets = ak4671_dapm_widgets,
  580. .num_dapm_widgets = ARRAY_SIZE(ak4671_dapm_widgets),
  581. .dapm_routes = ak4671_intercon,
  582. .num_dapm_routes = ARRAY_SIZE(ak4671_intercon),
  583. };
  584. static int __devinit ak4671_i2c_probe(struct i2c_client *client,
  585. const struct i2c_device_id *id)
  586. {
  587. struct ak4671_priv *ak4671;
  588. int ret;
  589. ak4671 = devm_kzalloc(&client->dev, sizeof(struct ak4671_priv),
  590. GFP_KERNEL);
  591. if (ak4671 == NULL)
  592. return -ENOMEM;
  593. i2c_set_clientdata(client, ak4671);
  594. ak4671->control_type = SND_SOC_I2C;
  595. ret = snd_soc_register_codec(&client->dev,
  596. &soc_codec_dev_ak4671, &ak4671_dai, 1);
  597. return ret;
  598. }
  599. static __devexit int ak4671_i2c_remove(struct i2c_client *client)
  600. {
  601. snd_soc_unregister_codec(&client->dev);
  602. return 0;
  603. }
  604. static const struct i2c_device_id ak4671_i2c_id[] = {
  605. { "ak4671", 0 },
  606. { }
  607. };
  608. MODULE_DEVICE_TABLE(i2c, ak4671_i2c_id);
  609. static struct i2c_driver ak4671_i2c_driver = {
  610. .driver = {
  611. .name = "ak4671-codec",
  612. .owner = THIS_MODULE,
  613. },
  614. .probe = ak4671_i2c_probe,
  615. .remove = __devexit_p(ak4671_i2c_remove),
  616. .id_table = ak4671_i2c_id,
  617. };
  618. static int __init ak4671_modinit(void)
  619. {
  620. return i2c_add_driver(&ak4671_i2c_driver);
  621. }
  622. module_init(ak4671_modinit);
  623. static void __exit ak4671_exit(void)
  624. {
  625. i2c_del_driver(&ak4671_i2c_driver);
  626. }
  627. module_exit(ak4671_exit);
  628. MODULE_DESCRIPTION("ASoC AK4671 codec driver");
  629. MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
  630. MODULE_LICENSE("GPL");