adau1373.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410
  1. /*
  2. * Analog Devices ADAU1373 Audio Codec drive
  3. *
  4. * Copyright 2011 Analog Devices Inc.
  5. * Author: Lars-Peter Clausen <lars@metafoo.de>
  6. *
  7. * Licensed under the GPL-2 or later.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/delay.h>
  12. #include <linux/pm.h>
  13. #include <linux/i2c.h>
  14. #include <linux/slab.h>
  15. #include <linux/gcd.h>
  16. #include <sound/core.h>
  17. #include <sound/pcm.h>
  18. #include <sound/pcm_params.h>
  19. #include <sound/tlv.h>
  20. #include <sound/soc.h>
  21. #include <sound/adau1373.h>
  22. #include "adau1373.h"
  23. struct adau1373_dai {
  24. unsigned int clk_src;
  25. unsigned int sysclk;
  26. bool enable_src;
  27. bool master;
  28. };
  29. struct adau1373 {
  30. struct adau1373_dai dais[3];
  31. };
  32. #define ADAU1373_INPUT_MODE 0x00
  33. #define ADAU1373_AINL_CTRL(x) (0x01 + (x) * 2)
  34. #define ADAU1373_AINR_CTRL(x) (0x02 + (x) * 2)
  35. #define ADAU1373_LLINE_OUT(x) (0x9 + (x) * 2)
  36. #define ADAU1373_RLINE_OUT(x) (0xa + (x) * 2)
  37. #define ADAU1373_LSPK_OUT 0x0d
  38. #define ADAU1373_RSPK_OUT 0x0e
  39. #define ADAU1373_LHP_OUT 0x0f
  40. #define ADAU1373_RHP_OUT 0x10
  41. #define ADAU1373_ADC_GAIN 0x11
  42. #define ADAU1373_LADC_MIXER 0x12
  43. #define ADAU1373_RADC_MIXER 0x13
  44. #define ADAU1373_LLINE1_MIX 0x14
  45. #define ADAU1373_RLINE1_MIX 0x15
  46. #define ADAU1373_LLINE2_MIX 0x16
  47. #define ADAU1373_RLINE2_MIX 0x17
  48. #define ADAU1373_LSPK_MIX 0x18
  49. #define ADAU1373_RSPK_MIX 0x19
  50. #define ADAU1373_LHP_MIX 0x1a
  51. #define ADAU1373_RHP_MIX 0x1b
  52. #define ADAU1373_EP_MIX 0x1c
  53. #define ADAU1373_HP_CTRL 0x1d
  54. #define ADAU1373_HP_CTRL2 0x1e
  55. #define ADAU1373_LS_CTRL 0x1f
  56. #define ADAU1373_EP_CTRL 0x21
  57. #define ADAU1373_MICBIAS_CTRL1 0x22
  58. #define ADAU1373_MICBIAS_CTRL2 0x23
  59. #define ADAU1373_OUTPUT_CTRL 0x24
  60. #define ADAU1373_PWDN_CTRL1 0x25
  61. #define ADAU1373_PWDN_CTRL2 0x26
  62. #define ADAU1373_PWDN_CTRL3 0x27
  63. #define ADAU1373_DPLL_CTRL(x) (0x28 + (x) * 7)
  64. #define ADAU1373_PLL_CTRL1(x) (0x29 + (x) * 7)
  65. #define ADAU1373_PLL_CTRL2(x) (0x2a + (x) * 7)
  66. #define ADAU1373_PLL_CTRL3(x) (0x2b + (x) * 7)
  67. #define ADAU1373_PLL_CTRL4(x) (0x2c + (x) * 7)
  68. #define ADAU1373_PLL_CTRL5(x) (0x2d + (x) * 7)
  69. #define ADAU1373_PLL_CTRL6(x) (0x2e + (x) * 7)
  70. #define ADAU1373_PLL_CTRL7(x) (0x2f + (x) * 7)
  71. #define ADAU1373_HEADDECT 0x36
  72. #define ADAU1373_ADC_DAC_STATUS 0x37
  73. #define ADAU1373_ADC_CTRL 0x3c
  74. #define ADAU1373_DAI(x) (0x44 + (x))
  75. #define ADAU1373_CLK_SRC_DIV(x) (0x40 + (x) * 2)
  76. #define ADAU1373_BCLKDIV(x) (0x47 + (x))
  77. #define ADAU1373_SRC_RATIOA(x) (0x4a + (x) * 2)
  78. #define ADAU1373_SRC_RATIOB(x) (0x4b + (x) * 2)
  79. #define ADAU1373_DEEMP_CTRL 0x50
  80. #define ADAU1373_SRC_DAI_CTRL(x) (0x51 + (x))
  81. #define ADAU1373_DIN_MIX_CTRL(x) (0x56 + (x))
  82. #define ADAU1373_DOUT_MIX_CTRL(x) (0x5b + (x))
  83. #define ADAU1373_DAI_PBL_VOL(x) (0x62 + (x) * 2)
  84. #define ADAU1373_DAI_PBR_VOL(x) (0x63 + (x) * 2)
  85. #define ADAU1373_DAI_RECL_VOL(x) (0x68 + (x) * 2)
  86. #define ADAU1373_DAI_RECR_VOL(x) (0x69 + (x) * 2)
  87. #define ADAU1373_DAC1_PBL_VOL 0x6e
  88. #define ADAU1373_DAC1_PBR_VOL 0x6f
  89. #define ADAU1373_DAC2_PBL_VOL 0x70
  90. #define ADAU1373_DAC2_PBR_VOL 0x71
  91. #define ADAU1373_ADC_RECL_VOL 0x72
  92. #define ADAU1373_ADC_RECR_VOL 0x73
  93. #define ADAU1373_DMIC_RECL_VOL 0x74
  94. #define ADAU1373_DMIC_RECR_VOL 0x75
  95. #define ADAU1373_VOL_GAIN1 0x76
  96. #define ADAU1373_VOL_GAIN2 0x77
  97. #define ADAU1373_VOL_GAIN3 0x78
  98. #define ADAU1373_HPF_CTRL 0x7d
  99. #define ADAU1373_BASS1 0x7e
  100. #define ADAU1373_BASS2 0x7f
  101. #define ADAU1373_DRC(x) (0x80 + (x) * 0x10)
  102. #define ADAU1373_3D_CTRL1 0xc0
  103. #define ADAU1373_3D_CTRL2 0xc1
  104. #define ADAU1373_FDSP_SEL1 0xdc
  105. #define ADAU1373_FDSP_SEL2 0xdd
  106. #define ADAU1373_FDSP_SEL3 0xde
  107. #define ADAU1373_FDSP_SEL4 0xdf
  108. #define ADAU1373_DIGMICCTRL 0xe2
  109. #define ADAU1373_DIGEN 0xeb
  110. #define ADAU1373_SOFT_RESET 0xff
  111. #define ADAU1373_PLL_CTRL6_DPLL_BYPASS BIT(1)
  112. #define ADAU1373_PLL_CTRL6_PLL_EN BIT(0)
  113. #define ADAU1373_DAI_INVERT_BCLK BIT(7)
  114. #define ADAU1373_DAI_MASTER BIT(6)
  115. #define ADAU1373_DAI_INVERT_LRCLK BIT(4)
  116. #define ADAU1373_DAI_WLEN_16 0x0
  117. #define ADAU1373_DAI_WLEN_20 0x4
  118. #define ADAU1373_DAI_WLEN_24 0x8
  119. #define ADAU1373_DAI_WLEN_32 0xc
  120. #define ADAU1373_DAI_WLEN_MASK 0xc
  121. #define ADAU1373_DAI_FORMAT_RIGHT_J 0x0
  122. #define ADAU1373_DAI_FORMAT_LEFT_J 0x1
  123. #define ADAU1373_DAI_FORMAT_I2S 0x2
  124. #define ADAU1373_DAI_FORMAT_DSP 0x3
  125. #define ADAU1373_BCLKDIV_SOURCE BIT(5)
  126. #define ADAU1373_BCLKDIV_32 0x03
  127. #define ADAU1373_BCLKDIV_64 0x02
  128. #define ADAU1373_BCLKDIV_128 0x01
  129. #define ADAU1373_BCLKDIV_256 0x00
  130. #define ADAU1373_ADC_CTRL_PEAK_DETECT BIT(0)
  131. #define ADAU1373_ADC_CTRL_RESET BIT(1)
  132. #define ADAU1373_ADC_CTRL_RESET_FORCE BIT(2)
  133. #define ADAU1373_OUTPUT_CTRL_LDIFF BIT(3)
  134. #define ADAU1373_OUTPUT_CTRL_LNFBEN BIT(2)
  135. #define ADAU1373_PWDN_CTRL3_PWR_EN BIT(0)
  136. #define ADAU1373_EP_CTRL_MICBIAS1_OFFSET 4
  137. #define ADAU1373_EP_CTRL_MICBIAS2_OFFSET 2
  138. static const uint8_t adau1373_default_regs[] = {
  139. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00 */
  140. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  141. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10 */
  142. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  143. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20 */
  144. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
  145. 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* 0x30 */
  146. 0x00, 0x00, 0x00, 0x80, 0x00, 0x01, 0x00, 0x00,
  147. 0x00, 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x00, /* 0x40 */
  148. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  149. 0x00, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, /* 0x50 */
  150. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  151. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60 */
  152. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  153. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70 */
  154. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  155. 0x78, 0x18, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, /* 0x80 */
  156. 0x00, 0xc0, 0x88, 0x7a, 0xdf, 0x20, 0x00, 0x00,
  157. 0x78, 0x18, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, /* 0x90 */
  158. 0x00, 0xc0, 0x88, 0x7a, 0xdf, 0x20, 0x00, 0x00,
  159. 0x78, 0x18, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, /* 0xa0 */
  160. 0x00, 0xc0, 0x88, 0x7a, 0xdf, 0x20, 0x00, 0x00,
  161. 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0 */
  162. 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00,
  163. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 */
  164. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  165. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0 */
  166. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  167. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, /* 0xe0 */
  168. 0x00, 0x1f, 0x0f, 0x00, 0x00,
  169. };
  170. static const unsigned int adau1373_out_tlv[] = {
  171. TLV_DB_RANGE_HEAD(4),
  172. 0, 7, TLV_DB_SCALE_ITEM(-7900, 400, 1),
  173. 8, 15, TLV_DB_SCALE_ITEM(-4700, 300, 0),
  174. 16, 23, TLV_DB_SCALE_ITEM(-2300, 200, 0),
  175. 24, 31, TLV_DB_SCALE_ITEM(-700, 100, 0),
  176. };
  177. static const DECLARE_TLV_DB_MINMAX(adau1373_digital_tlv, -9563, 0);
  178. static const DECLARE_TLV_DB_SCALE(adau1373_in_pga_tlv, -1300, 100, 1);
  179. static const DECLARE_TLV_DB_SCALE(adau1373_ep_tlv, -600, 600, 1);
  180. static const DECLARE_TLV_DB_SCALE(adau1373_input_boost_tlv, 0, 2000, 0);
  181. static const DECLARE_TLV_DB_SCALE(adau1373_gain_boost_tlv, 0, 600, 0);
  182. static const DECLARE_TLV_DB_SCALE(adau1373_speaker_boost_tlv, 1200, 600, 0);
  183. static const char *adau1373_fdsp_sel_text[] = {
  184. "None",
  185. "Channel 1",
  186. "Channel 2",
  187. "Channel 3",
  188. "Channel 4",
  189. "Channel 5",
  190. };
  191. static const SOC_ENUM_SINGLE_DECL(adau1373_drc1_channel_enum,
  192. ADAU1373_FDSP_SEL1, 4, adau1373_fdsp_sel_text);
  193. static const SOC_ENUM_SINGLE_DECL(adau1373_drc2_channel_enum,
  194. ADAU1373_FDSP_SEL1, 0, adau1373_fdsp_sel_text);
  195. static const SOC_ENUM_SINGLE_DECL(adau1373_drc3_channel_enum,
  196. ADAU1373_FDSP_SEL2, 0, adau1373_fdsp_sel_text);
  197. static const SOC_ENUM_SINGLE_DECL(adau1373_hpf_channel_enum,
  198. ADAU1373_FDSP_SEL3, 0, adau1373_fdsp_sel_text);
  199. static const SOC_ENUM_SINGLE_DECL(adau1373_bass_channel_enum,
  200. ADAU1373_FDSP_SEL4, 4, adau1373_fdsp_sel_text);
  201. static const char *adau1373_hpf_cutoff_text[] = {
  202. "3.7Hz", "50Hz", "100Hz", "150Hz", "200Hz", "250Hz", "300Hz", "350Hz",
  203. "400Hz", "450Hz", "500Hz", "550Hz", "600Hz", "650Hz", "700Hz", "750Hz",
  204. "800Hz",
  205. };
  206. static const SOC_ENUM_SINGLE_DECL(adau1373_hpf_cutoff_enum,
  207. ADAU1373_HPF_CTRL, 3, adau1373_hpf_cutoff_text);
  208. static const char *adau1373_bass_lpf_cutoff_text[] = {
  209. "801Hz", "1001Hz",
  210. };
  211. static const char *adau1373_bass_clip_level_text[] = {
  212. "0.125", "0.250", "0.370", "0.500", "0.625", "0.750", "0.875",
  213. };
  214. static const unsigned int adau1373_bass_clip_level_values[] = {
  215. 1, 2, 3, 4, 5, 6, 7,
  216. };
  217. static const char *adau1373_bass_hpf_cutoff_text[] = {
  218. "158Hz", "232Hz", "347Hz", "520Hz",
  219. };
  220. static const unsigned int adau1373_bass_tlv[] = {
  221. TLV_DB_RANGE_HEAD(3),
  222. 0, 2, TLV_DB_SCALE_ITEM(-600, 600, 1),
  223. 3, 4, TLV_DB_SCALE_ITEM(950, 250, 0),
  224. 5, 7, TLV_DB_SCALE_ITEM(1400, 150, 0),
  225. };
  226. static const SOC_ENUM_SINGLE_DECL(adau1373_bass_lpf_cutoff_enum,
  227. ADAU1373_BASS1, 5, adau1373_bass_lpf_cutoff_text);
  228. static const SOC_VALUE_ENUM_SINGLE_DECL(adau1373_bass_clip_level_enum,
  229. ADAU1373_BASS1, 2, 7, adau1373_bass_clip_level_text,
  230. adau1373_bass_clip_level_values);
  231. static const SOC_ENUM_SINGLE_DECL(adau1373_bass_hpf_cutoff_enum,
  232. ADAU1373_BASS1, 0, adau1373_bass_hpf_cutoff_text);
  233. static const char *adau1373_3d_level_text[] = {
  234. "0%", "6.67%", "13.33%", "20%", "26.67%", "33.33%",
  235. "40%", "46.67%", "53.33%", "60%", "66.67%", "73.33%",
  236. "80%", "86.67", "99.33%", "100%"
  237. };
  238. static const char *adau1373_3d_cutoff_text[] = {
  239. "No 3D", "0.03125 fs", "0.04583 fs", "0.075 fs", "0.11458 fs",
  240. "0.16875 fs", "0.27083 fs"
  241. };
  242. static const SOC_ENUM_SINGLE_DECL(adau1373_3d_level_enum,
  243. ADAU1373_3D_CTRL1, 4, adau1373_3d_level_text);
  244. static const SOC_ENUM_SINGLE_DECL(adau1373_3d_cutoff_enum,
  245. ADAU1373_3D_CTRL1, 0, adau1373_3d_cutoff_text);
  246. static const unsigned int adau1373_3d_tlv[] = {
  247. TLV_DB_RANGE_HEAD(2),
  248. 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
  249. 1, 7, TLV_DB_LINEAR_ITEM(-1800, -120),
  250. };
  251. static const char *adau1373_lr_mux_text[] = {
  252. "Mute",
  253. "Right Channel (L+R)",
  254. "Left Channel (L+R)",
  255. "Stereo",
  256. };
  257. static const SOC_ENUM_SINGLE_DECL(adau1373_lineout1_lr_mux_enum,
  258. ADAU1373_OUTPUT_CTRL, 4, adau1373_lr_mux_text);
  259. static const SOC_ENUM_SINGLE_DECL(adau1373_lineout2_lr_mux_enum,
  260. ADAU1373_OUTPUT_CTRL, 6, adau1373_lr_mux_text);
  261. static const SOC_ENUM_SINGLE_DECL(adau1373_speaker_lr_mux_enum,
  262. ADAU1373_LS_CTRL, 4, adau1373_lr_mux_text);
  263. static const struct snd_kcontrol_new adau1373_controls[] = {
  264. SOC_DOUBLE_R_TLV("AIF1 Capture Volume", ADAU1373_DAI_RECL_VOL(0),
  265. ADAU1373_DAI_RECR_VOL(0), 0, 0xff, 1, adau1373_digital_tlv),
  266. SOC_DOUBLE_R_TLV("AIF2 Capture Volume", ADAU1373_DAI_RECL_VOL(1),
  267. ADAU1373_DAI_RECR_VOL(1), 0, 0xff, 1, adau1373_digital_tlv),
  268. SOC_DOUBLE_R_TLV("AIF3 Capture Volume", ADAU1373_DAI_RECL_VOL(2),
  269. ADAU1373_DAI_RECR_VOL(2), 0, 0xff, 1, adau1373_digital_tlv),
  270. SOC_DOUBLE_R_TLV("ADC Capture Volume", ADAU1373_ADC_RECL_VOL,
  271. ADAU1373_ADC_RECR_VOL, 0, 0xff, 1, adau1373_digital_tlv),
  272. SOC_DOUBLE_R_TLV("DMIC Capture Volume", ADAU1373_DMIC_RECL_VOL,
  273. ADAU1373_DMIC_RECR_VOL, 0, 0xff, 1, adau1373_digital_tlv),
  274. SOC_DOUBLE_R_TLV("AIF1 Playback Volume", ADAU1373_DAI_PBL_VOL(0),
  275. ADAU1373_DAI_PBR_VOL(0), 0, 0xff, 1, adau1373_digital_tlv),
  276. SOC_DOUBLE_R_TLV("AIF2 Playback Volume", ADAU1373_DAI_PBL_VOL(1),
  277. ADAU1373_DAI_PBR_VOL(1), 0, 0xff, 1, adau1373_digital_tlv),
  278. SOC_DOUBLE_R_TLV("AIF3 Playback Volume", ADAU1373_DAI_PBL_VOL(2),
  279. ADAU1373_DAI_PBR_VOL(2), 0, 0xff, 1, adau1373_digital_tlv),
  280. SOC_DOUBLE_R_TLV("DAC1 Playback Volume", ADAU1373_DAC1_PBL_VOL,
  281. ADAU1373_DAC1_PBR_VOL, 0, 0xff, 1, adau1373_digital_tlv),
  282. SOC_DOUBLE_R_TLV("DAC2 Playback Volume", ADAU1373_DAC2_PBL_VOL,
  283. ADAU1373_DAC2_PBR_VOL, 0, 0xff, 1, adau1373_digital_tlv),
  284. SOC_DOUBLE_R_TLV("Lineout1 Playback Volume", ADAU1373_LLINE_OUT(0),
  285. ADAU1373_RLINE_OUT(0), 0, 0x1f, 0, adau1373_out_tlv),
  286. SOC_DOUBLE_R_TLV("Speaker Playback Volume", ADAU1373_LSPK_OUT,
  287. ADAU1373_RSPK_OUT, 0, 0x1f, 0, adau1373_out_tlv),
  288. SOC_DOUBLE_R_TLV("Headphone Playback Volume", ADAU1373_LHP_OUT,
  289. ADAU1373_RHP_OUT, 0, 0x1f, 0, adau1373_out_tlv),
  290. SOC_DOUBLE_R_TLV("Input 1 Capture Volume", ADAU1373_AINL_CTRL(0),
  291. ADAU1373_AINR_CTRL(0), 0, 0x1f, 0, adau1373_in_pga_tlv),
  292. SOC_DOUBLE_R_TLV("Input 2 Capture Volume", ADAU1373_AINL_CTRL(1),
  293. ADAU1373_AINR_CTRL(1), 0, 0x1f, 0, adau1373_in_pga_tlv),
  294. SOC_DOUBLE_R_TLV("Input 3 Capture Volume", ADAU1373_AINL_CTRL(2),
  295. ADAU1373_AINR_CTRL(2), 0, 0x1f, 0, adau1373_in_pga_tlv),
  296. SOC_DOUBLE_R_TLV("Input 4 Capture Volume", ADAU1373_AINL_CTRL(3),
  297. ADAU1373_AINR_CTRL(3), 0, 0x1f, 0, adau1373_in_pga_tlv),
  298. SOC_SINGLE_TLV("Earpiece Playback Volume", ADAU1373_EP_CTRL, 0, 3, 0,
  299. adau1373_ep_tlv),
  300. SOC_DOUBLE_TLV("AIF3 Boost Playback Volume", ADAU1373_VOL_GAIN1, 4, 5,
  301. 1, 0, adau1373_gain_boost_tlv),
  302. SOC_DOUBLE_TLV("AIF2 Boost Playback Volume", ADAU1373_VOL_GAIN1, 2, 3,
  303. 1, 0, adau1373_gain_boost_tlv),
  304. SOC_DOUBLE_TLV("AIF1 Boost Playback Volume", ADAU1373_VOL_GAIN1, 0, 1,
  305. 1, 0, adau1373_gain_boost_tlv),
  306. SOC_DOUBLE_TLV("AIF3 Boost Capture Volume", ADAU1373_VOL_GAIN2, 4, 5,
  307. 1, 0, adau1373_gain_boost_tlv),
  308. SOC_DOUBLE_TLV("AIF2 Boost Capture Volume", ADAU1373_VOL_GAIN2, 2, 3,
  309. 1, 0, adau1373_gain_boost_tlv),
  310. SOC_DOUBLE_TLV("AIF1 Boost Capture Volume", ADAU1373_VOL_GAIN2, 0, 1,
  311. 1, 0, adau1373_gain_boost_tlv),
  312. SOC_DOUBLE_TLV("DMIC Boost Capture Volume", ADAU1373_VOL_GAIN3, 6, 7,
  313. 1, 0, adau1373_gain_boost_tlv),
  314. SOC_DOUBLE_TLV("ADC Boost Capture Volume", ADAU1373_VOL_GAIN3, 4, 5,
  315. 1, 0, adau1373_gain_boost_tlv),
  316. SOC_DOUBLE_TLV("DAC2 Boost Playback Volume", ADAU1373_VOL_GAIN3, 2, 3,
  317. 1, 0, adau1373_gain_boost_tlv),
  318. SOC_DOUBLE_TLV("DAC1 Boost Playback Volume", ADAU1373_VOL_GAIN3, 0, 1,
  319. 1, 0, adau1373_gain_boost_tlv),
  320. SOC_DOUBLE_TLV("Input 1 Boost Capture Volume", ADAU1373_ADC_GAIN, 0, 4,
  321. 1, 0, adau1373_input_boost_tlv),
  322. SOC_DOUBLE_TLV("Input 2 Boost Capture Volume", ADAU1373_ADC_GAIN, 1, 5,
  323. 1, 0, adau1373_input_boost_tlv),
  324. SOC_DOUBLE_TLV("Input 3 Boost Capture Volume", ADAU1373_ADC_GAIN, 2, 6,
  325. 1, 0, adau1373_input_boost_tlv),
  326. SOC_DOUBLE_TLV("Input 4 Boost Capture Volume", ADAU1373_ADC_GAIN, 3, 7,
  327. 1, 0, adau1373_input_boost_tlv),
  328. SOC_DOUBLE_TLV("Speaker Boost Playback Volume", ADAU1373_LS_CTRL, 2, 3,
  329. 1, 0, adau1373_speaker_boost_tlv),
  330. SOC_ENUM("Lineout1 LR Mux", adau1373_lineout1_lr_mux_enum),
  331. SOC_ENUM("Speaker LR Mux", adau1373_speaker_lr_mux_enum),
  332. SOC_ENUM("HPF Cutoff", adau1373_hpf_cutoff_enum),
  333. SOC_DOUBLE("HPF Switch", ADAU1373_HPF_CTRL, 1, 0, 1, 0),
  334. SOC_ENUM("HPF Channel", adau1373_hpf_channel_enum),
  335. SOC_ENUM("Bass HPF Cutoff", adau1373_bass_hpf_cutoff_enum),
  336. SOC_VALUE_ENUM("Bass Clip Level Threshold",
  337. adau1373_bass_clip_level_enum),
  338. SOC_ENUM("Bass LPF Cutoff", adau1373_bass_lpf_cutoff_enum),
  339. SOC_DOUBLE("Bass Playback Switch", ADAU1373_BASS2, 0, 1, 1, 0),
  340. SOC_SINGLE_TLV("Bass Playback Volume", ADAU1373_BASS2, 2, 7, 0,
  341. adau1373_bass_tlv),
  342. SOC_ENUM("Bass Channel", adau1373_bass_channel_enum),
  343. SOC_ENUM("3D Freq", adau1373_3d_cutoff_enum),
  344. SOC_ENUM("3D Level", adau1373_3d_level_enum),
  345. SOC_SINGLE("3D Playback Switch", ADAU1373_3D_CTRL2, 0, 1, 0),
  346. SOC_SINGLE_TLV("3D Playback Volume", ADAU1373_3D_CTRL2, 2, 7, 0,
  347. adau1373_3d_tlv),
  348. SOC_ENUM("3D Channel", adau1373_bass_channel_enum),
  349. SOC_SINGLE("Zero Cross Switch", ADAU1373_PWDN_CTRL3, 7, 1, 0),
  350. };
  351. static const struct snd_kcontrol_new adau1373_lineout2_controls[] = {
  352. SOC_DOUBLE_R_TLV("Lineout2 Playback Volume", ADAU1373_LLINE_OUT(1),
  353. ADAU1373_RLINE_OUT(1), 0, 0x1f, 0, adau1373_out_tlv),
  354. SOC_ENUM("Lineout2 LR Mux", adau1373_lineout2_lr_mux_enum),
  355. };
  356. static const struct snd_kcontrol_new adau1373_drc_controls[] = {
  357. SOC_ENUM("DRC1 Channel", adau1373_drc1_channel_enum),
  358. SOC_ENUM("DRC2 Channel", adau1373_drc2_channel_enum),
  359. SOC_ENUM("DRC3 Channel", adau1373_drc3_channel_enum),
  360. };
  361. static int adau1373_pll_event(struct snd_soc_dapm_widget *w,
  362. struct snd_kcontrol *kcontrol, int event)
  363. {
  364. struct snd_soc_codec *codec = w->codec;
  365. unsigned int pll_id = w->name[3] - '1';
  366. unsigned int val;
  367. if (SND_SOC_DAPM_EVENT_ON(event))
  368. val = ADAU1373_PLL_CTRL6_PLL_EN;
  369. else
  370. val = 0;
  371. snd_soc_update_bits(codec, ADAU1373_PLL_CTRL6(pll_id),
  372. ADAU1373_PLL_CTRL6_PLL_EN, val);
  373. if (SND_SOC_DAPM_EVENT_ON(event))
  374. mdelay(5);
  375. return 0;
  376. }
  377. static const char *adau1373_decimator_text[] = {
  378. "ADC",
  379. "DMIC1",
  380. };
  381. static const struct soc_enum adau1373_decimator_enum =
  382. SOC_ENUM_SINGLE(0, 0, 2, adau1373_decimator_text);
  383. static const struct snd_kcontrol_new adau1373_decimator_mux =
  384. SOC_DAPM_ENUM_VIRT("Decimator Mux", adau1373_decimator_enum);
  385. static const struct snd_kcontrol_new adau1373_left_adc_mixer_controls[] = {
  386. SOC_DAPM_SINGLE("DAC1 Switch", ADAU1373_LADC_MIXER, 4, 1, 0),
  387. SOC_DAPM_SINGLE("Input 4 Switch", ADAU1373_LADC_MIXER, 3, 1, 0),
  388. SOC_DAPM_SINGLE("Input 3 Switch", ADAU1373_LADC_MIXER, 2, 1, 0),
  389. SOC_DAPM_SINGLE("Input 2 Switch", ADAU1373_LADC_MIXER, 1, 1, 0),
  390. SOC_DAPM_SINGLE("Input 1 Switch", ADAU1373_LADC_MIXER, 0, 1, 0),
  391. };
  392. static const struct snd_kcontrol_new adau1373_right_adc_mixer_controls[] = {
  393. SOC_DAPM_SINGLE("DAC1 Switch", ADAU1373_RADC_MIXER, 4, 1, 0),
  394. SOC_DAPM_SINGLE("Input 4 Switch", ADAU1373_RADC_MIXER, 3, 1, 0),
  395. SOC_DAPM_SINGLE("Input 3 Switch", ADAU1373_RADC_MIXER, 2, 1, 0),
  396. SOC_DAPM_SINGLE("Input 2 Switch", ADAU1373_RADC_MIXER, 1, 1, 0),
  397. SOC_DAPM_SINGLE("Input 1 Switch", ADAU1373_RADC_MIXER, 0, 1, 0),
  398. };
  399. #define DECLARE_ADAU1373_OUTPUT_MIXER_CTRLS(_name, _reg) \
  400. const struct snd_kcontrol_new _name[] = { \
  401. SOC_DAPM_SINGLE("Left DAC2 Switch", _reg, 7, 1, 0), \
  402. SOC_DAPM_SINGLE("Right DAC2 Switch", _reg, 6, 1, 0), \
  403. SOC_DAPM_SINGLE("Left DAC1 Switch", _reg, 5, 1, 0), \
  404. SOC_DAPM_SINGLE("Right DAC1 Switch", _reg, 4, 1, 0), \
  405. SOC_DAPM_SINGLE("Input 4 Bypass Switch", _reg, 3, 1, 0), \
  406. SOC_DAPM_SINGLE("Input 3 Bypass Switch", _reg, 2, 1, 0), \
  407. SOC_DAPM_SINGLE("Input 2 Bypass Switch", _reg, 1, 1, 0), \
  408. SOC_DAPM_SINGLE("Input 1 Bypass Switch", _reg, 0, 1, 0), \
  409. }
  410. static DECLARE_ADAU1373_OUTPUT_MIXER_CTRLS(adau1373_left_line1_mixer_controls,
  411. ADAU1373_LLINE1_MIX);
  412. static DECLARE_ADAU1373_OUTPUT_MIXER_CTRLS(adau1373_right_line1_mixer_controls,
  413. ADAU1373_RLINE1_MIX);
  414. static DECLARE_ADAU1373_OUTPUT_MIXER_CTRLS(adau1373_left_line2_mixer_controls,
  415. ADAU1373_LLINE2_MIX);
  416. static DECLARE_ADAU1373_OUTPUT_MIXER_CTRLS(adau1373_right_line2_mixer_controls,
  417. ADAU1373_RLINE2_MIX);
  418. static DECLARE_ADAU1373_OUTPUT_MIXER_CTRLS(adau1373_left_spk_mixer_controls,
  419. ADAU1373_LSPK_MIX);
  420. static DECLARE_ADAU1373_OUTPUT_MIXER_CTRLS(adau1373_right_spk_mixer_controls,
  421. ADAU1373_RSPK_MIX);
  422. static DECLARE_ADAU1373_OUTPUT_MIXER_CTRLS(adau1373_ep_mixer_controls,
  423. ADAU1373_EP_MIX);
  424. static const struct snd_kcontrol_new adau1373_left_hp_mixer_controls[] = {
  425. SOC_DAPM_SINGLE("Left DAC1 Switch", ADAU1373_LHP_MIX, 5, 1, 0),
  426. SOC_DAPM_SINGLE("Left DAC2 Switch", ADAU1373_LHP_MIX, 4, 1, 0),
  427. SOC_DAPM_SINGLE("Input 4 Bypass Switch", ADAU1373_LHP_MIX, 3, 1, 0),
  428. SOC_DAPM_SINGLE("Input 3 Bypass Switch", ADAU1373_LHP_MIX, 2, 1, 0),
  429. SOC_DAPM_SINGLE("Input 2 Bypass Switch", ADAU1373_LHP_MIX, 1, 1, 0),
  430. SOC_DAPM_SINGLE("Input 1 Bypass Switch", ADAU1373_LHP_MIX, 0, 1, 0),
  431. };
  432. static const struct snd_kcontrol_new adau1373_right_hp_mixer_controls[] = {
  433. SOC_DAPM_SINGLE("Right DAC1 Switch", ADAU1373_RHP_MIX, 5, 1, 0),
  434. SOC_DAPM_SINGLE("Right DAC2 Switch", ADAU1373_RHP_MIX, 4, 1, 0),
  435. SOC_DAPM_SINGLE("Input 4 Bypass Switch", ADAU1373_RHP_MIX, 3, 1, 0),
  436. SOC_DAPM_SINGLE("Input 3 Bypass Switch", ADAU1373_RHP_MIX, 2, 1, 0),
  437. SOC_DAPM_SINGLE("Input 2 Bypass Switch", ADAU1373_RHP_MIX, 1, 1, 0),
  438. SOC_DAPM_SINGLE("Input 1 Bypass Switch", ADAU1373_RHP_MIX, 0, 1, 0),
  439. };
  440. #define DECLARE_ADAU1373_DSP_CHANNEL_MIXER_CTRLS(_name, _reg) \
  441. const struct snd_kcontrol_new _name[] = { \
  442. SOC_DAPM_SINGLE("DMIC2 Swapped Switch", _reg, 6, 1, 0), \
  443. SOC_DAPM_SINGLE("DMIC2 Switch", _reg, 5, 1, 0), \
  444. SOC_DAPM_SINGLE("ADC/DMIC1 Swapped Switch", _reg, 4, 1, 0), \
  445. SOC_DAPM_SINGLE("ADC/DMIC1 Switch", _reg, 3, 1, 0), \
  446. SOC_DAPM_SINGLE("AIF3 Switch", _reg, 2, 1, 0), \
  447. SOC_DAPM_SINGLE("AIF2 Switch", _reg, 1, 1, 0), \
  448. SOC_DAPM_SINGLE("AIF1 Switch", _reg, 0, 1, 0), \
  449. }
  450. static DECLARE_ADAU1373_DSP_CHANNEL_MIXER_CTRLS(adau1373_dsp_channel1_mixer_controls,
  451. ADAU1373_DIN_MIX_CTRL(0));
  452. static DECLARE_ADAU1373_DSP_CHANNEL_MIXER_CTRLS(adau1373_dsp_channel2_mixer_controls,
  453. ADAU1373_DIN_MIX_CTRL(1));
  454. static DECLARE_ADAU1373_DSP_CHANNEL_MIXER_CTRLS(adau1373_dsp_channel3_mixer_controls,
  455. ADAU1373_DIN_MIX_CTRL(2));
  456. static DECLARE_ADAU1373_DSP_CHANNEL_MIXER_CTRLS(adau1373_dsp_channel4_mixer_controls,
  457. ADAU1373_DIN_MIX_CTRL(3));
  458. static DECLARE_ADAU1373_DSP_CHANNEL_MIXER_CTRLS(adau1373_dsp_channel5_mixer_controls,
  459. ADAU1373_DIN_MIX_CTRL(4));
  460. #define DECLARE_ADAU1373_DSP_OUTPUT_MIXER_CTRLS(_name, _reg) \
  461. const struct snd_kcontrol_new _name[] = { \
  462. SOC_DAPM_SINGLE("DSP Channel5 Switch", _reg, 4, 1, 0), \
  463. SOC_DAPM_SINGLE("DSP Channel4 Switch", _reg, 3, 1, 0), \
  464. SOC_DAPM_SINGLE("DSP Channel3 Switch", _reg, 2, 1, 0), \
  465. SOC_DAPM_SINGLE("DSP Channel2 Switch", _reg, 1, 1, 0), \
  466. SOC_DAPM_SINGLE("DSP Channel1 Switch", _reg, 0, 1, 0), \
  467. }
  468. static DECLARE_ADAU1373_DSP_OUTPUT_MIXER_CTRLS(adau1373_aif1_mixer_controls,
  469. ADAU1373_DOUT_MIX_CTRL(0));
  470. static DECLARE_ADAU1373_DSP_OUTPUT_MIXER_CTRLS(adau1373_aif2_mixer_controls,
  471. ADAU1373_DOUT_MIX_CTRL(1));
  472. static DECLARE_ADAU1373_DSP_OUTPUT_MIXER_CTRLS(adau1373_aif3_mixer_controls,
  473. ADAU1373_DOUT_MIX_CTRL(2));
  474. static DECLARE_ADAU1373_DSP_OUTPUT_MIXER_CTRLS(adau1373_dac1_mixer_controls,
  475. ADAU1373_DOUT_MIX_CTRL(3));
  476. static DECLARE_ADAU1373_DSP_OUTPUT_MIXER_CTRLS(adau1373_dac2_mixer_controls,
  477. ADAU1373_DOUT_MIX_CTRL(4));
  478. static const struct snd_soc_dapm_widget adau1373_dapm_widgets[] = {
  479. /* Datasheet claims Left ADC is bit 6 and Right ADC is bit 7, but that
  480. * doesn't seem to be the case. */
  481. SND_SOC_DAPM_ADC("Left ADC", NULL, ADAU1373_PWDN_CTRL1, 7, 0),
  482. SND_SOC_DAPM_ADC("Right ADC", NULL, ADAU1373_PWDN_CTRL1, 6, 0),
  483. SND_SOC_DAPM_ADC("DMIC1", NULL, ADAU1373_DIGMICCTRL, 0, 0),
  484. SND_SOC_DAPM_ADC("DMIC2", NULL, ADAU1373_DIGMICCTRL, 2, 0),
  485. SND_SOC_DAPM_VIRT_MUX("Decimator Mux", SND_SOC_NOPM, 0, 0,
  486. &adau1373_decimator_mux),
  487. SND_SOC_DAPM_SUPPLY("MICBIAS2", ADAU1373_PWDN_CTRL1, 5, 0, NULL, 0),
  488. SND_SOC_DAPM_SUPPLY("MICBIAS1", ADAU1373_PWDN_CTRL1, 4, 0, NULL, 0),
  489. SND_SOC_DAPM_PGA("IN4PGA", ADAU1373_PWDN_CTRL1, 3, 0, NULL, 0),
  490. SND_SOC_DAPM_PGA("IN3PGA", ADAU1373_PWDN_CTRL1, 2, 0, NULL, 0),
  491. SND_SOC_DAPM_PGA("IN2PGA", ADAU1373_PWDN_CTRL1, 1, 0, NULL, 0),
  492. SND_SOC_DAPM_PGA("IN1PGA", ADAU1373_PWDN_CTRL1, 0, 0, NULL, 0),
  493. SND_SOC_DAPM_DAC("Left DAC2", NULL, ADAU1373_PWDN_CTRL2, 7, 0),
  494. SND_SOC_DAPM_DAC("Right DAC2", NULL, ADAU1373_PWDN_CTRL2, 6, 0),
  495. SND_SOC_DAPM_DAC("Left DAC1", NULL, ADAU1373_PWDN_CTRL2, 5, 0),
  496. SND_SOC_DAPM_DAC("Right DAC1", NULL, ADAU1373_PWDN_CTRL2, 4, 0),
  497. SOC_MIXER_ARRAY("Left ADC Mixer", SND_SOC_NOPM, 0, 0,
  498. adau1373_left_adc_mixer_controls),
  499. SOC_MIXER_ARRAY("Right ADC Mixer", SND_SOC_NOPM, 0, 0,
  500. adau1373_right_adc_mixer_controls),
  501. SOC_MIXER_ARRAY("Left Lineout2 Mixer", ADAU1373_PWDN_CTRL2, 3, 0,
  502. adau1373_left_line2_mixer_controls),
  503. SOC_MIXER_ARRAY("Right Lineout2 Mixer", ADAU1373_PWDN_CTRL2, 2, 0,
  504. adau1373_right_line2_mixer_controls),
  505. SOC_MIXER_ARRAY("Left Lineout1 Mixer", ADAU1373_PWDN_CTRL2, 1, 0,
  506. adau1373_left_line1_mixer_controls),
  507. SOC_MIXER_ARRAY("Right Lineout1 Mixer", ADAU1373_PWDN_CTRL2, 0, 0,
  508. adau1373_right_line1_mixer_controls),
  509. SOC_MIXER_ARRAY("Earpiece Mixer", ADAU1373_PWDN_CTRL3, 4, 0,
  510. adau1373_ep_mixer_controls),
  511. SOC_MIXER_ARRAY("Left Speaker Mixer", ADAU1373_PWDN_CTRL3, 3, 0,
  512. adau1373_left_spk_mixer_controls),
  513. SOC_MIXER_ARRAY("Right Speaker Mixer", ADAU1373_PWDN_CTRL3, 2, 0,
  514. adau1373_right_spk_mixer_controls),
  515. SOC_MIXER_ARRAY("Left Headphone Mixer", SND_SOC_NOPM, 0, 0,
  516. adau1373_left_hp_mixer_controls),
  517. SOC_MIXER_ARRAY("Right Headphone Mixer", SND_SOC_NOPM, 0, 0,
  518. adau1373_right_hp_mixer_controls),
  519. SND_SOC_DAPM_SUPPLY("Headphone Enable", ADAU1373_PWDN_CTRL3, 1, 0,
  520. NULL, 0),
  521. SND_SOC_DAPM_SUPPLY("AIF1 CLK", ADAU1373_SRC_DAI_CTRL(0), 0, 0,
  522. NULL, 0),
  523. SND_SOC_DAPM_SUPPLY("AIF2 CLK", ADAU1373_SRC_DAI_CTRL(1), 0, 0,
  524. NULL, 0),
  525. SND_SOC_DAPM_SUPPLY("AIF3 CLK", ADAU1373_SRC_DAI_CTRL(2), 0, 0,
  526. NULL, 0),
  527. SND_SOC_DAPM_SUPPLY("AIF1 IN SRC", ADAU1373_SRC_DAI_CTRL(0), 2, 0,
  528. NULL, 0),
  529. SND_SOC_DAPM_SUPPLY("AIF1 OUT SRC", ADAU1373_SRC_DAI_CTRL(0), 1, 0,
  530. NULL, 0),
  531. SND_SOC_DAPM_SUPPLY("AIF2 IN SRC", ADAU1373_SRC_DAI_CTRL(1), 2, 0,
  532. NULL, 0),
  533. SND_SOC_DAPM_SUPPLY("AIF2 OUT SRC", ADAU1373_SRC_DAI_CTRL(1), 1, 0,
  534. NULL, 0),
  535. SND_SOC_DAPM_SUPPLY("AIF3 IN SRC", ADAU1373_SRC_DAI_CTRL(2), 2, 0,
  536. NULL, 0),
  537. SND_SOC_DAPM_SUPPLY("AIF3 OUT SRC", ADAU1373_SRC_DAI_CTRL(2), 1, 0,
  538. NULL, 0),
  539. SND_SOC_DAPM_AIF_IN("AIF1 IN", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
  540. SND_SOC_DAPM_AIF_OUT("AIF1 OUT", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0),
  541. SND_SOC_DAPM_AIF_IN("AIF2 IN", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0),
  542. SND_SOC_DAPM_AIF_OUT("AIF2 OUT", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0),
  543. SND_SOC_DAPM_AIF_IN("AIF3 IN", "AIF3 Playback", 0, SND_SOC_NOPM, 0, 0),
  544. SND_SOC_DAPM_AIF_OUT("AIF3 OUT", "AIF3 Capture", 0, SND_SOC_NOPM, 0, 0),
  545. SOC_MIXER_ARRAY("DSP Channel1 Mixer", SND_SOC_NOPM, 0, 0,
  546. adau1373_dsp_channel1_mixer_controls),
  547. SOC_MIXER_ARRAY("DSP Channel2 Mixer", SND_SOC_NOPM, 0, 0,
  548. adau1373_dsp_channel2_mixer_controls),
  549. SOC_MIXER_ARRAY("DSP Channel3 Mixer", SND_SOC_NOPM, 0, 0,
  550. adau1373_dsp_channel3_mixer_controls),
  551. SOC_MIXER_ARRAY("DSP Channel4 Mixer", SND_SOC_NOPM, 0, 0,
  552. adau1373_dsp_channel4_mixer_controls),
  553. SOC_MIXER_ARRAY("DSP Channel5 Mixer", SND_SOC_NOPM, 0, 0,
  554. adau1373_dsp_channel5_mixer_controls),
  555. SOC_MIXER_ARRAY("AIF1 Mixer", SND_SOC_NOPM, 0, 0,
  556. adau1373_aif1_mixer_controls),
  557. SOC_MIXER_ARRAY("AIF2 Mixer", SND_SOC_NOPM, 0, 0,
  558. adau1373_aif2_mixer_controls),
  559. SOC_MIXER_ARRAY("AIF3 Mixer", SND_SOC_NOPM, 0, 0,
  560. adau1373_aif3_mixer_controls),
  561. SOC_MIXER_ARRAY("DAC1 Mixer", SND_SOC_NOPM, 0, 0,
  562. adau1373_dac1_mixer_controls),
  563. SOC_MIXER_ARRAY("DAC2 Mixer", SND_SOC_NOPM, 0, 0,
  564. adau1373_dac2_mixer_controls),
  565. SND_SOC_DAPM_SUPPLY("DSP", ADAU1373_DIGEN, 4, 0, NULL, 0),
  566. SND_SOC_DAPM_SUPPLY("Recording Engine B", ADAU1373_DIGEN, 3, 0, NULL, 0),
  567. SND_SOC_DAPM_SUPPLY("Recording Engine A", ADAU1373_DIGEN, 2, 0, NULL, 0),
  568. SND_SOC_DAPM_SUPPLY("Playback Engine B", ADAU1373_DIGEN, 1, 0, NULL, 0),
  569. SND_SOC_DAPM_SUPPLY("Playback Engine A", ADAU1373_DIGEN, 0, 0, NULL, 0),
  570. SND_SOC_DAPM_SUPPLY("PLL1", SND_SOC_NOPM, 0, 0, adau1373_pll_event,
  571. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  572. SND_SOC_DAPM_SUPPLY("PLL2", SND_SOC_NOPM, 0, 0, adau1373_pll_event,
  573. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  574. SND_SOC_DAPM_SUPPLY("SYSCLK1", ADAU1373_CLK_SRC_DIV(0), 7, 0, NULL, 0),
  575. SND_SOC_DAPM_SUPPLY("SYSCLK2", ADAU1373_CLK_SRC_DIV(1), 7, 0, NULL, 0),
  576. SND_SOC_DAPM_INPUT("AIN1L"),
  577. SND_SOC_DAPM_INPUT("AIN1R"),
  578. SND_SOC_DAPM_INPUT("AIN2L"),
  579. SND_SOC_DAPM_INPUT("AIN2R"),
  580. SND_SOC_DAPM_INPUT("AIN3L"),
  581. SND_SOC_DAPM_INPUT("AIN3R"),
  582. SND_SOC_DAPM_INPUT("AIN4L"),
  583. SND_SOC_DAPM_INPUT("AIN4R"),
  584. SND_SOC_DAPM_INPUT("DMIC1DAT"),
  585. SND_SOC_DAPM_INPUT("DMIC2DAT"),
  586. SND_SOC_DAPM_OUTPUT("LOUT1L"),
  587. SND_SOC_DAPM_OUTPUT("LOUT1R"),
  588. SND_SOC_DAPM_OUTPUT("LOUT2L"),
  589. SND_SOC_DAPM_OUTPUT("LOUT2R"),
  590. SND_SOC_DAPM_OUTPUT("HPL"),
  591. SND_SOC_DAPM_OUTPUT("HPR"),
  592. SND_SOC_DAPM_OUTPUT("SPKL"),
  593. SND_SOC_DAPM_OUTPUT("SPKR"),
  594. SND_SOC_DAPM_OUTPUT("EP"),
  595. };
  596. static int adau1373_check_aif_clk(struct snd_soc_dapm_widget *source,
  597. struct snd_soc_dapm_widget *sink)
  598. {
  599. struct snd_soc_codec *codec = source->codec;
  600. struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
  601. unsigned int dai;
  602. const char *clk;
  603. dai = sink->name[3] - '1';
  604. if (!adau1373->dais[dai].master)
  605. return 0;
  606. if (adau1373->dais[dai].clk_src == ADAU1373_CLK_SRC_PLL1)
  607. clk = "SYSCLK1";
  608. else
  609. clk = "SYSCLK2";
  610. return strcmp(source->name, clk) == 0;
  611. }
  612. static int adau1373_check_src(struct snd_soc_dapm_widget *source,
  613. struct snd_soc_dapm_widget *sink)
  614. {
  615. struct snd_soc_codec *codec = source->codec;
  616. struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
  617. unsigned int dai;
  618. dai = sink->name[3] - '1';
  619. return adau1373->dais[dai].enable_src;
  620. }
  621. #define DSP_CHANNEL_MIXER_ROUTES(_sink) \
  622. { _sink, "DMIC2 Swapped Switch", "DMIC2" }, \
  623. { _sink, "DMIC2 Switch", "DMIC2" }, \
  624. { _sink, "ADC/DMIC1 Swapped Switch", "Decimator Mux" }, \
  625. { _sink, "ADC/DMIC1 Switch", "Decimator Mux" }, \
  626. { _sink, "AIF1 Switch", "AIF1 IN" }, \
  627. { _sink, "AIF2 Switch", "AIF2 IN" }, \
  628. { _sink, "AIF3 Switch", "AIF3 IN" }
  629. #define DSP_OUTPUT_MIXER_ROUTES(_sink) \
  630. { _sink, "DSP Channel1 Switch", "DSP Channel1 Mixer" }, \
  631. { _sink, "DSP Channel2 Switch", "DSP Channel2 Mixer" }, \
  632. { _sink, "DSP Channel3 Switch", "DSP Channel3 Mixer" }, \
  633. { _sink, "DSP Channel4 Switch", "DSP Channel4 Mixer" }, \
  634. { _sink, "DSP Channel5 Switch", "DSP Channel5 Mixer" }
  635. #define LEFT_OUTPUT_MIXER_ROUTES(_sink) \
  636. { _sink, "Right DAC2 Switch", "Right DAC2" }, \
  637. { _sink, "Left DAC2 Switch", "Left DAC2" }, \
  638. { _sink, "Right DAC1 Switch", "Right DAC1" }, \
  639. { _sink, "Left DAC1 Switch", "Left DAC1" }, \
  640. { _sink, "Input 1 Bypass Switch", "IN1PGA" }, \
  641. { _sink, "Input 2 Bypass Switch", "IN2PGA" }, \
  642. { _sink, "Input 3 Bypass Switch", "IN3PGA" }, \
  643. { _sink, "Input 4 Bypass Switch", "IN4PGA" }
  644. #define RIGHT_OUTPUT_MIXER_ROUTES(_sink) \
  645. { _sink, "Right DAC2 Switch", "Right DAC2" }, \
  646. { _sink, "Left DAC2 Switch", "Left DAC2" }, \
  647. { _sink, "Right DAC1 Switch", "Right DAC1" }, \
  648. { _sink, "Left DAC1 Switch", "Left DAC1" }, \
  649. { _sink, "Input 1 Bypass Switch", "IN1PGA" }, \
  650. { _sink, "Input 2 Bypass Switch", "IN2PGA" }, \
  651. { _sink, "Input 3 Bypass Switch", "IN3PGA" }, \
  652. { _sink, "Input 4 Bypass Switch", "IN4PGA" }
  653. static const struct snd_soc_dapm_route adau1373_dapm_routes[] = {
  654. { "Left ADC Mixer", "DAC1 Switch", "Left DAC1" },
  655. { "Left ADC Mixer", "Input 1 Switch", "IN1PGA" },
  656. { "Left ADC Mixer", "Input 2 Switch", "IN2PGA" },
  657. { "Left ADC Mixer", "Input 3 Switch", "IN3PGA" },
  658. { "Left ADC Mixer", "Input 4 Switch", "IN4PGA" },
  659. { "Right ADC Mixer", "DAC1 Switch", "Right DAC1" },
  660. { "Right ADC Mixer", "Input 1 Switch", "IN1PGA" },
  661. { "Right ADC Mixer", "Input 2 Switch", "IN2PGA" },
  662. { "Right ADC Mixer", "Input 3 Switch", "IN3PGA" },
  663. { "Right ADC Mixer", "Input 4 Switch", "IN4PGA" },
  664. { "Left ADC", NULL, "Left ADC Mixer" },
  665. { "Right ADC", NULL, "Right ADC Mixer" },
  666. { "Decimator Mux", "ADC", "Left ADC" },
  667. { "Decimator Mux", "ADC", "Right ADC" },
  668. { "Decimator Mux", "DMIC1", "DMIC1" },
  669. DSP_CHANNEL_MIXER_ROUTES("DSP Channel1 Mixer"),
  670. DSP_CHANNEL_MIXER_ROUTES("DSP Channel2 Mixer"),
  671. DSP_CHANNEL_MIXER_ROUTES("DSP Channel3 Mixer"),
  672. DSP_CHANNEL_MIXER_ROUTES("DSP Channel4 Mixer"),
  673. DSP_CHANNEL_MIXER_ROUTES("DSP Channel5 Mixer"),
  674. DSP_OUTPUT_MIXER_ROUTES("AIF1 Mixer"),
  675. DSP_OUTPUT_MIXER_ROUTES("AIF2 Mixer"),
  676. DSP_OUTPUT_MIXER_ROUTES("AIF3 Mixer"),
  677. DSP_OUTPUT_MIXER_ROUTES("DAC1 Mixer"),
  678. DSP_OUTPUT_MIXER_ROUTES("DAC2 Mixer"),
  679. { "AIF1 OUT", NULL, "AIF1 Mixer" },
  680. { "AIF2 OUT", NULL, "AIF2 Mixer" },
  681. { "AIF3 OUT", NULL, "AIF3 Mixer" },
  682. { "Left DAC1", NULL, "DAC1 Mixer" },
  683. { "Right DAC1", NULL, "DAC1 Mixer" },
  684. { "Left DAC2", NULL, "DAC2 Mixer" },
  685. { "Right DAC2", NULL, "DAC2 Mixer" },
  686. LEFT_OUTPUT_MIXER_ROUTES("Left Lineout1 Mixer"),
  687. RIGHT_OUTPUT_MIXER_ROUTES("Right Lineout1 Mixer"),
  688. LEFT_OUTPUT_MIXER_ROUTES("Left Lineout2 Mixer"),
  689. RIGHT_OUTPUT_MIXER_ROUTES("Right Lineout2 Mixer"),
  690. LEFT_OUTPUT_MIXER_ROUTES("Left Speaker Mixer"),
  691. RIGHT_OUTPUT_MIXER_ROUTES("Right Speaker Mixer"),
  692. { "Left Headphone Mixer", "Left DAC2 Switch", "Left DAC2" },
  693. { "Left Headphone Mixer", "Left DAC1 Switch", "Left DAC1" },
  694. { "Left Headphone Mixer", "Input 1 Bypass Switch", "IN1PGA" },
  695. { "Left Headphone Mixer", "Input 2 Bypass Switch", "IN2PGA" },
  696. { "Left Headphone Mixer", "Input 3 Bypass Switch", "IN3PGA" },
  697. { "Left Headphone Mixer", "Input 4 Bypass Switch", "IN4PGA" },
  698. { "Right Headphone Mixer", "Right DAC2 Switch", "Right DAC2" },
  699. { "Right Headphone Mixer", "Right DAC1 Switch", "Right DAC1" },
  700. { "Right Headphone Mixer", "Input 1 Bypass Switch", "IN1PGA" },
  701. { "Right Headphone Mixer", "Input 2 Bypass Switch", "IN2PGA" },
  702. { "Right Headphone Mixer", "Input 3 Bypass Switch", "IN3PGA" },
  703. { "Right Headphone Mixer", "Input 4 Bypass Switch", "IN4PGA" },
  704. { "Left Headphone Mixer", NULL, "Headphone Enable" },
  705. { "Right Headphone Mixer", NULL, "Headphone Enable" },
  706. { "Earpiece Mixer", "Right DAC2 Switch", "Right DAC2" },
  707. { "Earpiece Mixer", "Left DAC2 Switch", "Left DAC2" },
  708. { "Earpiece Mixer", "Right DAC1 Switch", "Right DAC1" },
  709. { "Earpiece Mixer", "Left DAC1 Switch", "Left DAC1" },
  710. { "Earpiece Mixer", "Input 1 Bypass Switch", "IN1PGA" },
  711. { "Earpiece Mixer", "Input 2 Bypass Switch", "IN2PGA" },
  712. { "Earpiece Mixer", "Input 3 Bypass Switch", "IN3PGA" },
  713. { "Earpiece Mixer", "Input 4 Bypass Switch", "IN4PGA" },
  714. { "LOUT1L", NULL, "Left Lineout1 Mixer" },
  715. { "LOUT1R", NULL, "Right Lineout1 Mixer" },
  716. { "LOUT2L", NULL, "Left Lineout2 Mixer" },
  717. { "LOUT2R", NULL, "Right Lineout2 Mixer" },
  718. { "SPKL", NULL, "Left Speaker Mixer" },
  719. { "SPKR", NULL, "Right Speaker Mixer" },
  720. { "HPL", NULL, "Left Headphone Mixer" },
  721. { "HPR", NULL, "Right Headphone Mixer" },
  722. { "EP", NULL, "Earpiece Mixer" },
  723. { "IN1PGA", NULL, "AIN1L" },
  724. { "IN2PGA", NULL, "AIN2L" },
  725. { "IN3PGA", NULL, "AIN3L" },
  726. { "IN4PGA", NULL, "AIN4L" },
  727. { "IN1PGA", NULL, "AIN1R" },
  728. { "IN2PGA", NULL, "AIN2R" },
  729. { "IN3PGA", NULL, "AIN3R" },
  730. { "IN4PGA", NULL, "AIN4R" },
  731. { "SYSCLK1", NULL, "PLL1" },
  732. { "SYSCLK2", NULL, "PLL2" },
  733. { "Left DAC1", NULL, "SYSCLK1" },
  734. { "Right DAC1", NULL, "SYSCLK1" },
  735. { "Left DAC2", NULL, "SYSCLK1" },
  736. { "Right DAC2", NULL, "SYSCLK1" },
  737. { "Left ADC", NULL, "SYSCLK1" },
  738. { "Right ADC", NULL, "SYSCLK1" },
  739. { "DSP", NULL, "SYSCLK1" },
  740. { "AIF1 Mixer", NULL, "DSP" },
  741. { "AIF2 Mixer", NULL, "DSP" },
  742. { "AIF3 Mixer", NULL, "DSP" },
  743. { "DAC1 Mixer", NULL, "DSP" },
  744. { "DAC2 Mixer", NULL, "DSP" },
  745. { "DAC1 Mixer", NULL, "Playback Engine A" },
  746. { "DAC2 Mixer", NULL, "Playback Engine B" },
  747. { "Left ADC Mixer", NULL, "Recording Engine A" },
  748. { "Right ADC Mixer", NULL, "Recording Engine A" },
  749. { "AIF1 CLK", NULL, "SYSCLK1", adau1373_check_aif_clk },
  750. { "AIF2 CLK", NULL, "SYSCLK1", adau1373_check_aif_clk },
  751. { "AIF3 CLK", NULL, "SYSCLK1", adau1373_check_aif_clk },
  752. { "AIF1 CLK", NULL, "SYSCLK2", adau1373_check_aif_clk },
  753. { "AIF2 CLK", NULL, "SYSCLK2", adau1373_check_aif_clk },
  754. { "AIF3 CLK", NULL, "SYSCLK2", adau1373_check_aif_clk },
  755. { "AIF1 IN", NULL, "AIF1 CLK" },
  756. { "AIF1 OUT", NULL, "AIF1 CLK" },
  757. { "AIF2 IN", NULL, "AIF2 CLK" },
  758. { "AIF2 OUT", NULL, "AIF2 CLK" },
  759. { "AIF3 IN", NULL, "AIF3 CLK" },
  760. { "AIF3 OUT", NULL, "AIF3 CLK" },
  761. { "AIF1 IN", NULL, "AIF1 IN SRC", adau1373_check_src },
  762. { "AIF1 OUT", NULL, "AIF1 OUT SRC", adau1373_check_src },
  763. { "AIF2 IN", NULL, "AIF2 IN SRC", adau1373_check_src },
  764. { "AIF2 OUT", NULL, "AIF2 OUT SRC", adau1373_check_src },
  765. { "AIF3 IN", NULL, "AIF3 IN SRC", adau1373_check_src },
  766. { "AIF3 OUT", NULL, "AIF3 OUT SRC", adau1373_check_src },
  767. { "DMIC1", NULL, "DMIC1DAT" },
  768. { "DMIC1", NULL, "SYSCLK1" },
  769. { "DMIC1", NULL, "Recording Engine A" },
  770. { "DMIC2", NULL, "DMIC2DAT" },
  771. { "DMIC2", NULL, "SYSCLK1" },
  772. { "DMIC2", NULL, "Recording Engine B" },
  773. };
  774. static int adau1373_hw_params(struct snd_pcm_substream *substream,
  775. struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
  776. {
  777. struct snd_soc_codec *codec = dai->codec;
  778. struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
  779. struct adau1373_dai *adau1373_dai = &adau1373->dais[dai->id];
  780. unsigned int div;
  781. unsigned int freq;
  782. unsigned int ctrl;
  783. freq = adau1373_dai->sysclk;
  784. if (freq % params_rate(params) != 0)
  785. return -EINVAL;
  786. switch (freq / params_rate(params)) {
  787. case 1024: /* sysclk / 256 */
  788. div = 0;
  789. break;
  790. case 1536: /* 2/3 sysclk / 256 */
  791. div = 1;
  792. break;
  793. case 2048: /* 1/2 sysclk / 256 */
  794. div = 2;
  795. break;
  796. case 3072: /* 1/3 sysclk / 256 */
  797. div = 3;
  798. break;
  799. case 4096: /* 1/4 sysclk / 256 */
  800. div = 4;
  801. break;
  802. case 6144: /* 1/6 sysclk / 256 */
  803. div = 5;
  804. break;
  805. case 5632: /* 2/11 sysclk / 256 */
  806. div = 6;
  807. break;
  808. default:
  809. return -EINVAL;
  810. }
  811. adau1373_dai->enable_src = (div != 0);
  812. snd_soc_update_bits(codec, ADAU1373_BCLKDIV(dai->id),
  813. ~ADAU1373_BCLKDIV_SOURCE, (div << 2) | ADAU1373_BCLKDIV_64);
  814. switch (params_format(params)) {
  815. case SNDRV_PCM_FORMAT_S16_LE:
  816. ctrl = ADAU1373_DAI_WLEN_16;
  817. break;
  818. case SNDRV_PCM_FORMAT_S20_3LE:
  819. ctrl = ADAU1373_DAI_WLEN_20;
  820. break;
  821. case SNDRV_PCM_FORMAT_S24_LE:
  822. ctrl = ADAU1373_DAI_WLEN_24;
  823. break;
  824. case SNDRV_PCM_FORMAT_S32_LE:
  825. ctrl = ADAU1373_DAI_WLEN_32;
  826. break;
  827. default:
  828. return -EINVAL;
  829. }
  830. return snd_soc_update_bits(codec, ADAU1373_DAI(dai->id),
  831. ADAU1373_DAI_WLEN_MASK, ctrl);
  832. }
  833. static int adau1373_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  834. {
  835. struct snd_soc_codec *codec = dai->codec;
  836. struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
  837. struct adau1373_dai *adau1373_dai = &adau1373->dais[dai->id];
  838. unsigned int ctrl;
  839. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  840. case SND_SOC_DAIFMT_CBM_CFM:
  841. ctrl = ADAU1373_DAI_MASTER;
  842. adau1373_dai->master = true;
  843. break;
  844. case SND_SOC_DAIFMT_CBS_CFS:
  845. ctrl = 0;
  846. adau1373_dai->master = false;
  847. break;
  848. default:
  849. return -EINVAL;
  850. }
  851. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  852. case SND_SOC_DAIFMT_I2S:
  853. ctrl |= ADAU1373_DAI_FORMAT_I2S;
  854. break;
  855. case SND_SOC_DAIFMT_LEFT_J:
  856. ctrl |= ADAU1373_DAI_FORMAT_LEFT_J;
  857. break;
  858. case SND_SOC_DAIFMT_RIGHT_J:
  859. ctrl |= ADAU1373_DAI_FORMAT_RIGHT_J;
  860. break;
  861. case SND_SOC_DAIFMT_DSP_B:
  862. ctrl |= ADAU1373_DAI_FORMAT_DSP;
  863. break;
  864. default:
  865. return -EINVAL;
  866. }
  867. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  868. case SND_SOC_DAIFMT_NB_NF:
  869. break;
  870. case SND_SOC_DAIFMT_IB_NF:
  871. ctrl |= ADAU1373_DAI_INVERT_BCLK;
  872. break;
  873. case SND_SOC_DAIFMT_NB_IF:
  874. ctrl |= ADAU1373_DAI_INVERT_LRCLK;
  875. break;
  876. case SND_SOC_DAIFMT_IB_IF:
  877. ctrl |= ADAU1373_DAI_INVERT_LRCLK | ADAU1373_DAI_INVERT_BCLK;
  878. break;
  879. default:
  880. return -EINVAL;
  881. }
  882. snd_soc_update_bits(codec, ADAU1373_DAI(dai->id),
  883. ~ADAU1373_DAI_WLEN_MASK, ctrl);
  884. return 0;
  885. }
  886. static int adau1373_set_dai_sysclk(struct snd_soc_dai *dai,
  887. int clk_id, unsigned int freq, int dir)
  888. {
  889. struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(dai->codec);
  890. struct adau1373_dai *adau1373_dai = &adau1373->dais[dai->id];
  891. switch (clk_id) {
  892. case ADAU1373_CLK_SRC_PLL1:
  893. case ADAU1373_CLK_SRC_PLL2:
  894. break;
  895. default:
  896. return -EINVAL;
  897. }
  898. adau1373_dai->sysclk = freq;
  899. adau1373_dai->clk_src = clk_id;
  900. snd_soc_update_bits(dai->codec, ADAU1373_BCLKDIV(dai->id),
  901. ADAU1373_BCLKDIV_SOURCE, clk_id << 5);
  902. return 0;
  903. }
  904. static const struct snd_soc_dai_ops adau1373_dai_ops = {
  905. .hw_params = adau1373_hw_params,
  906. .set_sysclk = adau1373_set_dai_sysclk,
  907. .set_fmt = adau1373_set_dai_fmt,
  908. };
  909. #define ADAU1373_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  910. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
  911. static struct snd_soc_dai_driver adau1373_dai_driver[] = {
  912. {
  913. .id = 0,
  914. .name = "adau1373-aif1",
  915. .playback = {
  916. .stream_name = "AIF1 Playback",
  917. .channels_min = 2,
  918. .channels_max = 2,
  919. .rates = SNDRV_PCM_RATE_8000_48000,
  920. .formats = ADAU1373_FORMATS,
  921. },
  922. .capture = {
  923. .stream_name = "AIF1 Capture",
  924. .channels_min = 2,
  925. .channels_max = 2,
  926. .rates = SNDRV_PCM_RATE_8000_48000,
  927. .formats = ADAU1373_FORMATS,
  928. },
  929. .ops = &adau1373_dai_ops,
  930. .symmetric_rates = 1,
  931. },
  932. {
  933. .id = 1,
  934. .name = "adau1373-aif2",
  935. .playback = {
  936. .stream_name = "AIF2 Playback",
  937. .channels_min = 2,
  938. .channels_max = 2,
  939. .rates = SNDRV_PCM_RATE_8000_48000,
  940. .formats = ADAU1373_FORMATS,
  941. },
  942. .capture = {
  943. .stream_name = "AIF2 Capture",
  944. .channels_min = 2,
  945. .channels_max = 2,
  946. .rates = SNDRV_PCM_RATE_8000_48000,
  947. .formats = ADAU1373_FORMATS,
  948. },
  949. .ops = &adau1373_dai_ops,
  950. .symmetric_rates = 1,
  951. },
  952. {
  953. .id = 2,
  954. .name = "adau1373-aif3",
  955. .playback = {
  956. .stream_name = "AIF3 Playback",
  957. .channels_min = 2,
  958. .channels_max = 2,
  959. .rates = SNDRV_PCM_RATE_8000_48000,
  960. .formats = ADAU1373_FORMATS,
  961. },
  962. .capture = {
  963. .stream_name = "AIF3 Capture",
  964. .channels_min = 2,
  965. .channels_max = 2,
  966. .rates = SNDRV_PCM_RATE_8000_48000,
  967. .formats = ADAU1373_FORMATS,
  968. },
  969. .ops = &adau1373_dai_ops,
  970. .symmetric_rates = 1,
  971. },
  972. };
  973. static int adau1373_set_pll(struct snd_soc_codec *codec, int pll_id,
  974. int source, unsigned int freq_in, unsigned int freq_out)
  975. {
  976. unsigned int dpll_div = 0;
  977. unsigned int x, r, n, m, i, j, mode;
  978. switch (pll_id) {
  979. case ADAU1373_PLL1:
  980. case ADAU1373_PLL2:
  981. break;
  982. default:
  983. return -EINVAL;
  984. }
  985. switch (source) {
  986. case ADAU1373_PLL_SRC_BCLK1:
  987. case ADAU1373_PLL_SRC_BCLK2:
  988. case ADAU1373_PLL_SRC_BCLK3:
  989. case ADAU1373_PLL_SRC_LRCLK1:
  990. case ADAU1373_PLL_SRC_LRCLK2:
  991. case ADAU1373_PLL_SRC_LRCLK3:
  992. case ADAU1373_PLL_SRC_MCLK1:
  993. case ADAU1373_PLL_SRC_MCLK2:
  994. case ADAU1373_PLL_SRC_GPIO1:
  995. case ADAU1373_PLL_SRC_GPIO2:
  996. case ADAU1373_PLL_SRC_GPIO3:
  997. case ADAU1373_PLL_SRC_GPIO4:
  998. break;
  999. default:
  1000. return -EINVAL;
  1001. }
  1002. if (freq_in < 7813 || freq_in > 27000000)
  1003. return -EINVAL;
  1004. if (freq_out < 45158000 || freq_out > 49152000)
  1005. return -EINVAL;
  1006. /* APLL input needs to be >= 8Mhz, so in case freq_in is less we use the
  1007. * DPLL to get it there. DPLL_out = (DPLL_in / div) * 1024 */
  1008. while (freq_in < 8000000) {
  1009. freq_in *= 2;
  1010. dpll_div++;
  1011. }
  1012. if (freq_out % freq_in != 0) {
  1013. /* fout = fin * (r + (n/m)) / x */
  1014. x = DIV_ROUND_UP(freq_in, 13500000);
  1015. freq_in /= x;
  1016. r = freq_out / freq_in;
  1017. i = freq_out % freq_in;
  1018. j = gcd(i, freq_in);
  1019. n = i / j;
  1020. m = freq_in / j;
  1021. x--;
  1022. mode = 1;
  1023. } else {
  1024. /* fout = fin / r */
  1025. r = freq_out / freq_in;
  1026. n = 0;
  1027. m = 0;
  1028. x = 0;
  1029. mode = 0;
  1030. }
  1031. if (r < 2 || r > 8 || x > 3 || m > 0xffff || n > 0xffff)
  1032. return -EINVAL;
  1033. if (dpll_div) {
  1034. dpll_div = 11 - dpll_div;
  1035. snd_soc_update_bits(codec, ADAU1373_PLL_CTRL6(pll_id),
  1036. ADAU1373_PLL_CTRL6_DPLL_BYPASS, 0);
  1037. } else {
  1038. snd_soc_update_bits(codec, ADAU1373_PLL_CTRL6(pll_id),
  1039. ADAU1373_PLL_CTRL6_DPLL_BYPASS,
  1040. ADAU1373_PLL_CTRL6_DPLL_BYPASS);
  1041. }
  1042. snd_soc_write(codec, ADAU1373_DPLL_CTRL(pll_id),
  1043. (source << 4) | dpll_div);
  1044. snd_soc_write(codec, ADAU1373_PLL_CTRL1(pll_id), (m >> 8) & 0xff);
  1045. snd_soc_write(codec, ADAU1373_PLL_CTRL2(pll_id), m & 0xff);
  1046. snd_soc_write(codec, ADAU1373_PLL_CTRL3(pll_id), (n >> 8) & 0xff);
  1047. snd_soc_write(codec, ADAU1373_PLL_CTRL4(pll_id), n & 0xff);
  1048. snd_soc_write(codec, ADAU1373_PLL_CTRL5(pll_id),
  1049. (r << 3) | (x << 1) | mode);
  1050. /* Set sysclk to pll_rate / 4 */
  1051. snd_soc_update_bits(codec, ADAU1373_CLK_SRC_DIV(pll_id), 0x3f, 0x09);
  1052. return 0;
  1053. }
  1054. static void adau1373_load_drc_settings(struct snd_soc_codec *codec,
  1055. unsigned int nr, uint8_t *drc)
  1056. {
  1057. unsigned int i;
  1058. for (i = 0; i < ADAU1373_DRC_SIZE; ++i)
  1059. snd_soc_write(codec, ADAU1373_DRC(nr) + i, drc[i]);
  1060. }
  1061. static bool adau1373_valid_micbias(enum adau1373_micbias_voltage micbias)
  1062. {
  1063. switch (micbias) {
  1064. case ADAU1373_MICBIAS_2_9V:
  1065. case ADAU1373_MICBIAS_2_2V:
  1066. case ADAU1373_MICBIAS_2_6V:
  1067. case ADAU1373_MICBIAS_1_8V:
  1068. return true;
  1069. default:
  1070. break;
  1071. }
  1072. return false;
  1073. }
  1074. static int adau1373_probe(struct snd_soc_codec *codec)
  1075. {
  1076. struct adau1373_platform_data *pdata = codec->dev->platform_data;
  1077. bool lineout_differential = false;
  1078. unsigned int val;
  1079. int ret;
  1080. int i;
  1081. ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C);
  1082. if (ret) {
  1083. dev_err(codec->dev, "failed to set cache I/O: %d\n", ret);
  1084. return ret;
  1085. }
  1086. if (pdata) {
  1087. if (pdata->num_drc > ARRAY_SIZE(pdata->drc_setting))
  1088. return -EINVAL;
  1089. if (!adau1373_valid_micbias(pdata->micbias1) ||
  1090. !adau1373_valid_micbias(pdata->micbias2))
  1091. return -EINVAL;
  1092. for (i = 0; i < pdata->num_drc; ++i) {
  1093. adau1373_load_drc_settings(codec, i,
  1094. pdata->drc_setting[i]);
  1095. }
  1096. snd_soc_add_codec_controls(codec, adau1373_drc_controls,
  1097. pdata->num_drc);
  1098. val = 0;
  1099. for (i = 0; i < 4; ++i) {
  1100. if (pdata->input_differential[i])
  1101. val |= BIT(i);
  1102. }
  1103. snd_soc_write(codec, ADAU1373_INPUT_MODE, val);
  1104. val = 0;
  1105. if (pdata->lineout_differential)
  1106. val |= ADAU1373_OUTPUT_CTRL_LDIFF;
  1107. if (pdata->lineout_ground_sense)
  1108. val |= ADAU1373_OUTPUT_CTRL_LNFBEN;
  1109. snd_soc_write(codec, ADAU1373_OUTPUT_CTRL, val);
  1110. lineout_differential = pdata->lineout_differential;
  1111. snd_soc_write(codec, ADAU1373_EP_CTRL,
  1112. (pdata->micbias1 << ADAU1373_EP_CTRL_MICBIAS1_OFFSET) |
  1113. (pdata->micbias2 << ADAU1373_EP_CTRL_MICBIAS2_OFFSET));
  1114. }
  1115. if (!lineout_differential) {
  1116. snd_soc_add_codec_controls(codec, adau1373_lineout2_controls,
  1117. ARRAY_SIZE(adau1373_lineout2_controls));
  1118. }
  1119. snd_soc_write(codec, ADAU1373_ADC_CTRL,
  1120. ADAU1373_ADC_CTRL_RESET_FORCE | ADAU1373_ADC_CTRL_PEAK_DETECT);
  1121. return 0;
  1122. }
  1123. static int adau1373_set_bias_level(struct snd_soc_codec *codec,
  1124. enum snd_soc_bias_level level)
  1125. {
  1126. switch (level) {
  1127. case SND_SOC_BIAS_ON:
  1128. break;
  1129. case SND_SOC_BIAS_PREPARE:
  1130. break;
  1131. case SND_SOC_BIAS_STANDBY:
  1132. snd_soc_update_bits(codec, ADAU1373_PWDN_CTRL3,
  1133. ADAU1373_PWDN_CTRL3_PWR_EN, ADAU1373_PWDN_CTRL3_PWR_EN);
  1134. break;
  1135. case SND_SOC_BIAS_OFF:
  1136. snd_soc_update_bits(codec, ADAU1373_PWDN_CTRL3,
  1137. ADAU1373_PWDN_CTRL3_PWR_EN, 0);
  1138. break;
  1139. }
  1140. codec->dapm.bias_level = level;
  1141. return 0;
  1142. }
  1143. static int adau1373_remove(struct snd_soc_codec *codec)
  1144. {
  1145. adau1373_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1146. return 0;
  1147. }
  1148. static int adau1373_suspend(struct snd_soc_codec *codec)
  1149. {
  1150. return adau1373_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1151. }
  1152. static int adau1373_resume(struct snd_soc_codec *codec)
  1153. {
  1154. adau1373_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1155. snd_soc_cache_sync(codec);
  1156. return 0;
  1157. }
  1158. static struct snd_soc_codec_driver adau1373_codec_driver = {
  1159. .probe = adau1373_probe,
  1160. .remove = adau1373_remove,
  1161. .suspend = adau1373_suspend,
  1162. .resume = adau1373_resume,
  1163. .set_bias_level = adau1373_set_bias_level,
  1164. .idle_bias_off = true,
  1165. .reg_cache_size = ARRAY_SIZE(adau1373_default_regs),
  1166. .reg_cache_default = adau1373_default_regs,
  1167. .reg_word_size = sizeof(uint8_t),
  1168. .set_pll = adau1373_set_pll,
  1169. .controls = adau1373_controls,
  1170. .num_controls = ARRAY_SIZE(adau1373_controls),
  1171. .dapm_widgets = adau1373_dapm_widgets,
  1172. .num_dapm_widgets = ARRAY_SIZE(adau1373_dapm_widgets),
  1173. .dapm_routes = adau1373_dapm_routes,
  1174. .num_dapm_routes = ARRAY_SIZE(adau1373_dapm_routes),
  1175. };
  1176. static int __devinit adau1373_i2c_probe(struct i2c_client *client,
  1177. const struct i2c_device_id *id)
  1178. {
  1179. struct adau1373 *adau1373;
  1180. int ret;
  1181. adau1373 = devm_kzalloc(&client->dev, sizeof(*adau1373), GFP_KERNEL);
  1182. if (!adau1373)
  1183. return -ENOMEM;
  1184. dev_set_drvdata(&client->dev, adau1373);
  1185. ret = snd_soc_register_codec(&client->dev, &adau1373_codec_driver,
  1186. adau1373_dai_driver, ARRAY_SIZE(adau1373_dai_driver));
  1187. return ret;
  1188. }
  1189. static int __devexit adau1373_i2c_remove(struct i2c_client *client)
  1190. {
  1191. snd_soc_unregister_codec(&client->dev);
  1192. return 0;
  1193. }
  1194. static const struct i2c_device_id adau1373_i2c_id[] = {
  1195. { "adau1373", 0 },
  1196. { }
  1197. };
  1198. MODULE_DEVICE_TABLE(i2c, adau1373_i2c_id);
  1199. static struct i2c_driver adau1373_i2c_driver = {
  1200. .driver = {
  1201. .name = "adau1373",
  1202. .owner = THIS_MODULE,
  1203. },
  1204. .probe = adau1373_i2c_probe,
  1205. .remove = __devexit_p(adau1373_i2c_remove),
  1206. .id_table = adau1373_i2c_id,
  1207. };
  1208. static int __init adau1373_init(void)
  1209. {
  1210. return i2c_add_driver(&adau1373_i2c_driver);
  1211. }
  1212. module_init(adau1373_init);
  1213. static void __exit adau1373_exit(void)
  1214. {
  1215. i2c_del_driver(&adau1373_i2c_driver);
  1216. }
  1217. module_exit(adau1373_exit);
  1218. MODULE_DESCRIPTION("ASoC ADAU1373 driver");
  1219. MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
  1220. MODULE_LICENSE("GPL");