adau1781.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. /*
  2. * Driver for ADAU1781/ADAU1781 codec
  3. *
  4. * Copyright 2011-2013 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/i2c.h>
  12. #include <linux/spi/spi.h>
  13. #include <linux/slab.h>
  14. #include <sound/core.h>
  15. #include <sound/pcm.h>
  16. #include <sound/pcm_params.h>
  17. #include <sound/soc.h>
  18. #include <sound/tlv.h>
  19. #include <linux/platform_data/adau17x1.h>
  20. #include "adau17x1.h"
  21. #include "adau1781.h"
  22. #define ADAU1781_DMIC_BEEP_CTRL 0x4008
  23. #define ADAU1781_LEFT_PGA 0x400e
  24. #define ADAU1781_RIGHT_PGA 0x400f
  25. #define ADAU1781_LEFT_PLAYBACK_MIXER 0x401c
  26. #define ADAU1781_RIGHT_PLAYBACK_MIXER 0x401e
  27. #define ADAU1781_MONO_PLAYBACK_MIXER 0x401f
  28. #define ADAU1781_LEFT_LINEOUT 0x4025
  29. #define ADAU1781_RIGHT_LINEOUT 0x4026
  30. #define ADAU1781_SPEAKER 0x4027
  31. #define ADAU1781_BEEP_ZC 0x4028
  32. #define ADAU1781_DEJITTER 0x4032
  33. #define ADAU1781_DIG_PWDN0 0x4080
  34. #define ADAU1781_DIG_PWDN1 0x4081
  35. #define ADAU1781_INPUT_DIFFERNTIAL BIT(3)
  36. #define ADAU1381_FIRMWARE "adau1381.bin"
  37. #define ADAU1781_FIRMWARE "adau1781.bin"
  38. static const struct reg_default adau1781_reg_defaults[] = {
  39. { ADAU1781_DMIC_BEEP_CTRL, 0x00 },
  40. { ADAU1781_LEFT_PGA, 0xc7 },
  41. { ADAU1781_RIGHT_PGA, 0xc7 },
  42. { ADAU1781_LEFT_PLAYBACK_MIXER, 0x00 },
  43. { ADAU1781_RIGHT_PLAYBACK_MIXER, 0x00 },
  44. { ADAU1781_MONO_PLAYBACK_MIXER, 0x00 },
  45. { ADAU1781_LEFT_LINEOUT, 0x00 },
  46. { ADAU1781_RIGHT_LINEOUT, 0x00 },
  47. { ADAU1781_SPEAKER, 0x00 },
  48. { ADAU1781_BEEP_ZC, 0x19 },
  49. { ADAU1781_DEJITTER, 0x60 },
  50. { ADAU1781_DIG_PWDN1, 0x0c },
  51. { ADAU1781_DIG_PWDN1, 0x00 },
  52. { ADAU17X1_CLOCK_CONTROL, 0x00 },
  53. { ADAU17X1_PLL_CONTROL, 0x00 },
  54. { ADAU17X1_REC_POWER_MGMT, 0x00 },
  55. { ADAU17X1_MICBIAS, 0x04 },
  56. { ADAU17X1_SERIAL_PORT0, 0x00 },
  57. { ADAU17X1_SERIAL_PORT1, 0x00 },
  58. { ADAU17X1_CONVERTER0, 0x00 },
  59. { ADAU17X1_CONVERTER1, 0x00 },
  60. { ADAU17X1_LEFT_INPUT_DIGITAL_VOL, 0x00 },
  61. { ADAU17X1_RIGHT_INPUT_DIGITAL_VOL, 0x00 },
  62. { ADAU17X1_ADC_CONTROL, 0x00 },
  63. { ADAU17X1_PLAY_POWER_MGMT, 0x00 },
  64. { ADAU17X1_DAC_CONTROL0, 0x00 },
  65. { ADAU17X1_DAC_CONTROL1, 0x00 },
  66. { ADAU17X1_DAC_CONTROL2, 0x00 },
  67. { ADAU17X1_SERIAL_PORT_PAD, 0x00 },
  68. { ADAU17X1_CONTROL_PORT_PAD0, 0x00 },
  69. { ADAU17X1_CONTROL_PORT_PAD1, 0x00 },
  70. { ADAU17X1_DSP_SAMPLING_RATE, 0x01 },
  71. { ADAU17X1_SERIAL_INPUT_ROUTE, 0x00 },
  72. { ADAU17X1_SERIAL_OUTPUT_ROUTE, 0x00 },
  73. { ADAU17X1_DSP_ENABLE, 0x00 },
  74. { ADAU17X1_DSP_RUN, 0x00 },
  75. { ADAU17X1_SERIAL_SAMPLING_RATE, 0x00 },
  76. };
  77. static const DECLARE_TLV_DB_SCALE(adau1781_speaker_tlv, 0, 200, 0);
  78. static const DECLARE_TLV_DB_RANGE(adau1781_pga_tlv,
  79. 0, 1, TLV_DB_SCALE_ITEM(0, 600, 0),
  80. 2, 3, TLV_DB_SCALE_ITEM(1000, 400, 0),
  81. 4, 4, TLV_DB_SCALE_ITEM(1700, 0, 0),
  82. 5, 7, TLV_DB_SCALE_ITEM(2000, 600, 0)
  83. );
  84. static const DECLARE_TLV_DB_RANGE(adau1781_beep_tlv,
  85. 0, 1, TLV_DB_SCALE_ITEM(0, 600, 0),
  86. 2, 3, TLV_DB_SCALE_ITEM(1000, 400, 0),
  87. 4, 4, TLV_DB_SCALE_ITEM(-2300, 0, 0),
  88. 5, 7, TLV_DB_SCALE_ITEM(2000, 600, 0)
  89. );
  90. static const DECLARE_TLV_DB_SCALE(adau1781_sidetone_tlv, -1800, 300, 1);
  91. static const char * const adau1781_speaker_bias_select_text[] = {
  92. "Normal operation", "Power saving", "Enhanced performance",
  93. };
  94. static const char * const adau1781_bias_select_text[] = {
  95. "Normal operation", "Extreme power saving", "Power saving",
  96. "Enhanced performance",
  97. };
  98. static SOC_ENUM_SINGLE_DECL(adau1781_adc_bias_enum,
  99. ADAU17X1_REC_POWER_MGMT, 3, adau1781_bias_select_text);
  100. static SOC_ENUM_SINGLE_DECL(adau1781_speaker_bias_enum,
  101. ADAU17X1_PLAY_POWER_MGMT, 6, adau1781_speaker_bias_select_text);
  102. static SOC_ENUM_SINGLE_DECL(adau1781_dac_bias_enum,
  103. ADAU17X1_PLAY_POWER_MGMT, 4, adau1781_bias_select_text);
  104. static SOC_ENUM_SINGLE_DECL(adau1781_playback_bias_enum,
  105. ADAU17X1_PLAY_POWER_MGMT, 2, adau1781_bias_select_text);
  106. static SOC_ENUM_SINGLE_DECL(adau1781_capture_bias_enum,
  107. ADAU17X1_REC_POWER_MGMT, 1, adau1781_bias_select_text);
  108. static const struct snd_kcontrol_new adau1781_controls[] = {
  109. SOC_SINGLE_TLV("Beep Capture Volume", ADAU1781_DMIC_BEEP_CTRL, 0, 7, 0,
  110. adau1781_beep_tlv),
  111. SOC_DOUBLE_R_TLV("PGA Capture Volume", ADAU1781_LEFT_PGA,
  112. ADAU1781_RIGHT_PGA, 5, 7, 0, adau1781_pga_tlv),
  113. SOC_DOUBLE_R("PGA Capture Switch", ADAU1781_LEFT_PGA,
  114. ADAU1781_RIGHT_PGA, 1, 1, 0),
  115. SOC_DOUBLE_R("Lineout Playback Switch", ADAU1781_LEFT_LINEOUT,
  116. ADAU1781_RIGHT_LINEOUT, 1, 1, 0),
  117. SOC_SINGLE("Beep ZC Switch", ADAU1781_BEEP_ZC, 0, 1, 0),
  118. SOC_SINGLE("Mono Playback Switch", ADAU1781_MONO_PLAYBACK_MIXER,
  119. 0, 1, 0),
  120. SOC_SINGLE_TLV("Mono Playback Volume", ADAU1781_SPEAKER, 6, 3, 0,
  121. adau1781_speaker_tlv),
  122. SOC_ENUM("ADC Bias", adau1781_adc_bias_enum),
  123. SOC_ENUM("DAC Bias", adau1781_dac_bias_enum),
  124. SOC_ENUM("Capture Bias", adau1781_capture_bias_enum),
  125. SOC_ENUM("Playback Bias", adau1781_playback_bias_enum),
  126. SOC_ENUM("Speaker Bias", adau1781_speaker_bias_enum),
  127. };
  128. static const struct snd_kcontrol_new adau1781_beep_mixer_controls[] = {
  129. SOC_DAPM_SINGLE("Beep Capture Switch", ADAU1781_DMIC_BEEP_CTRL,
  130. 3, 1, 0),
  131. };
  132. static const struct snd_kcontrol_new adau1781_left_mixer_controls[] = {
  133. SOC_DAPM_SINGLE_AUTODISABLE("Switch",
  134. ADAU1781_LEFT_PLAYBACK_MIXER, 5, 1, 0),
  135. SOC_DAPM_SINGLE_TLV("Beep Playback Volume",
  136. ADAU1781_LEFT_PLAYBACK_MIXER, 1, 8, 0, adau1781_sidetone_tlv),
  137. };
  138. static const struct snd_kcontrol_new adau1781_right_mixer_controls[] = {
  139. SOC_DAPM_SINGLE_AUTODISABLE("Switch",
  140. ADAU1781_RIGHT_PLAYBACK_MIXER, 6, 1, 0),
  141. SOC_DAPM_SINGLE_TLV("Beep Playback Volume",
  142. ADAU1781_LEFT_PLAYBACK_MIXER, 1, 8, 0, adau1781_sidetone_tlv),
  143. };
  144. static const struct snd_kcontrol_new adau1781_mono_mixer_controls[] = {
  145. SOC_DAPM_SINGLE_AUTODISABLE("Left Switch",
  146. ADAU1781_MONO_PLAYBACK_MIXER, 7, 1, 0),
  147. SOC_DAPM_SINGLE_AUTODISABLE("Right Switch",
  148. ADAU1781_MONO_PLAYBACK_MIXER, 6, 1, 0),
  149. SOC_DAPM_SINGLE_TLV("Beep Playback Volume",
  150. ADAU1781_MONO_PLAYBACK_MIXER, 2, 8, 0, adau1781_sidetone_tlv),
  151. };
  152. static int adau1781_dejitter_fixup(struct snd_soc_dapm_widget *w,
  153. struct snd_kcontrol *kcontrol, int event)
  154. {
  155. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  156. struct adau *adau = snd_soc_codec_get_drvdata(codec);
  157. /* After any power changes have been made the dejitter circuit
  158. * has to be reinitialized. */
  159. regmap_write(adau->regmap, ADAU1781_DEJITTER, 0);
  160. if (!adau->master)
  161. regmap_write(adau->regmap, ADAU1781_DEJITTER, 5);
  162. return 0;
  163. }
  164. static const struct snd_soc_dapm_widget adau1781_dapm_widgets[] = {
  165. SND_SOC_DAPM_PGA("Left PGA", ADAU1781_LEFT_PGA, 0, 0, NULL, 0),
  166. SND_SOC_DAPM_PGA("Right PGA", ADAU1781_RIGHT_PGA, 0, 0, NULL, 0),
  167. SND_SOC_DAPM_OUT_DRV("Speaker", ADAU1781_SPEAKER, 0, 0, NULL, 0),
  168. SOC_MIXER_NAMED_CTL_ARRAY("Beep Mixer", ADAU17X1_MICBIAS, 4, 0,
  169. adau1781_beep_mixer_controls),
  170. SOC_MIXER_ARRAY("Left Lineout Mixer", SND_SOC_NOPM, 0, 0,
  171. adau1781_left_mixer_controls),
  172. SOC_MIXER_ARRAY("Right Lineout Mixer", SND_SOC_NOPM, 0, 0,
  173. adau1781_right_mixer_controls),
  174. SOC_MIXER_ARRAY("Mono Mixer", SND_SOC_NOPM, 0, 0,
  175. adau1781_mono_mixer_controls),
  176. SND_SOC_DAPM_SUPPLY("Serial Input Routing", ADAU1781_DIG_PWDN0,
  177. 2, 0, NULL, 0),
  178. SND_SOC_DAPM_SUPPLY("Serial Output Routing", ADAU1781_DIG_PWDN0,
  179. 3, 0, NULL, 0),
  180. SND_SOC_DAPM_SUPPLY("Clock Domain Transfer", ADAU1781_DIG_PWDN0,
  181. 5, 0, NULL, 0),
  182. SND_SOC_DAPM_SUPPLY("Serial Ports", ADAU1781_DIG_PWDN0, 4, 0, NULL, 0),
  183. SND_SOC_DAPM_SUPPLY("ADC Engine", ADAU1781_DIG_PWDN0, 7, 0, NULL, 0),
  184. SND_SOC_DAPM_SUPPLY("DAC Engine", ADAU1781_DIG_PWDN1, 0, 0, NULL, 0),
  185. SND_SOC_DAPM_SUPPLY("Digital Mic", ADAU1781_DIG_PWDN1, 1, 0, NULL, 0),
  186. SND_SOC_DAPM_SUPPLY("Sound Engine", ADAU1781_DIG_PWDN0, 0, 0, NULL, 0),
  187. SND_SOC_DAPM_SUPPLY_S("SYSCLK", 1, ADAU1781_DIG_PWDN0, 1, 0, NULL, 0),
  188. SND_SOC_DAPM_SUPPLY("Zero Crossing Detector", ADAU1781_DIG_PWDN1, 2, 0,
  189. NULL, 0),
  190. SND_SOC_DAPM_POST("Dejitter fixup", adau1781_dejitter_fixup),
  191. SND_SOC_DAPM_INPUT("BEEP"),
  192. SND_SOC_DAPM_OUTPUT("AOUTL"),
  193. SND_SOC_DAPM_OUTPUT("AOUTR"),
  194. SND_SOC_DAPM_OUTPUT("SP"),
  195. SND_SOC_DAPM_INPUT("LMIC"),
  196. SND_SOC_DAPM_INPUT("RMIC"),
  197. };
  198. static const struct snd_soc_dapm_route adau1781_dapm_routes[] = {
  199. { "Left Lineout Mixer", NULL, "Left Playback Enable" },
  200. { "Right Lineout Mixer", NULL, "Right Playback Enable" },
  201. { "Left Lineout Mixer", "Beep Playback Volume", "Beep Mixer" },
  202. { "Left Lineout Mixer", "Switch", "Left DAC" },
  203. { "Right Lineout Mixer", "Beep Playback Volume", "Beep Mixer" },
  204. { "Right Lineout Mixer", "Switch", "Right DAC" },
  205. { "Mono Mixer", "Beep Playback Volume", "Beep Mixer" },
  206. { "Mono Mixer", "Right Switch", "Right DAC" },
  207. { "Mono Mixer", "Left Switch", "Left DAC" },
  208. { "Speaker", NULL, "Mono Mixer" },
  209. { "Mono Mixer", NULL, "SYSCLK" },
  210. { "Left Lineout Mixer", NULL, "SYSCLK" },
  211. { "Left Lineout Mixer", NULL, "SYSCLK" },
  212. { "Beep Mixer", "Beep Capture Switch", "BEEP" },
  213. { "Beep Mixer", NULL, "Zero Crossing Detector" },
  214. { "Left DAC", NULL, "DAC Engine" },
  215. { "Right DAC", NULL, "DAC Engine" },
  216. { "Sound Engine", NULL, "SYSCLK" },
  217. { "DSP", NULL, "Sound Engine" },
  218. { "Left Decimator", NULL, "ADC Engine" },
  219. { "Right Decimator", NULL, "ADC Engine" },
  220. { "AIFCLK", NULL, "SYSCLK" },
  221. { "Playback", NULL, "Serial Input Routing" },
  222. { "Playback", NULL, "Serial Ports" },
  223. { "Playback", NULL, "Clock Domain Transfer" },
  224. { "Capture", NULL, "Serial Output Routing" },
  225. { "Capture", NULL, "Serial Ports" },
  226. { "Capture", NULL, "Clock Domain Transfer" },
  227. { "AOUTL", NULL, "Left Lineout Mixer" },
  228. { "AOUTR", NULL, "Right Lineout Mixer" },
  229. { "SP", NULL, "Speaker" },
  230. };
  231. static const struct snd_soc_dapm_route adau1781_adc_dapm_routes[] = {
  232. { "Left PGA", NULL, "LMIC" },
  233. { "Right PGA", NULL, "RMIC" },
  234. { "Left Decimator", NULL, "Left PGA" },
  235. { "Right Decimator", NULL, "Right PGA" },
  236. };
  237. static const char * const adau1781_dmic_select_text[] = {
  238. "DMIC1", "DMIC2",
  239. };
  240. static SOC_ENUM_SINGLE_VIRT_DECL(adau1781_dmic_select_enum,
  241. adau1781_dmic_select_text);
  242. static const struct snd_kcontrol_new adau1781_dmic_mux =
  243. SOC_DAPM_ENUM("DMIC Select", adau1781_dmic_select_enum);
  244. static const struct snd_soc_dapm_widget adau1781_dmic_dapm_widgets[] = {
  245. SND_SOC_DAPM_MUX("DMIC Select", SND_SOC_NOPM, 0, 0, &adau1781_dmic_mux),
  246. SND_SOC_DAPM_ADC("DMIC1", NULL, ADAU1781_DMIC_BEEP_CTRL, 4, 0),
  247. SND_SOC_DAPM_ADC("DMIC2", NULL, ADAU1781_DMIC_BEEP_CTRL, 5, 0),
  248. };
  249. static const struct snd_soc_dapm_route adau1781_dmic_dapm_routes[] = {
  250. { "DMIC1", NULL, "LMIC" },
  251. { "DMIC2", NULL, "RMIC" },
  252. { "DMIC1", NULL, "Digital Mic" },
  253. { "DMIC2", NULL, "Digital Mic" },
  254. { "DMIC Select", "DMIC1", "DMIC1" },
  255. { "DMIC Select", "DMIC2", "DMIC2" },
  256. { "Left Decimator", NULL, "DMIC Select" },
  257. { "Right Decimator", NULL, "DMIC Select" },
  258. };
  259. static int adau1781_set_bias_level(struct snd_soc_codec *codec,
  260. enum snd_soc_bias_level level)
  261. {
  262. struct adau *adau = snd_soc_codec_get_drvdata(codec);
  263. switch (level) {
  264. case SND_SOC_BIAS_ON:
  265. break;
  266. case SND_SOC_BIAS_PREPARE:
  267. break;
  268. case SND_SOC_BIAS_STANDBY:
  269. regmap_update_bits(adau->regmap, ADAU17X1_CLOCK_CONTROL,
  270. ADAU17X1_CLOCK_CONTROL_SYSCLK_EN,
  271. ADAU17X1_CLOCK_CONTROL_SYSCLK_EN);
  272. /* Precharge */
  273. regmap_update_bits(adau->regmap, ADAU1781_DIG_PWDN1, 0x8, 0x8);
  274. break;
  275. case SND_SOC_BIAS_OFF:
  276. regmap_update_bits(adau->regmap, ADAU1781_DIG_PWDN1, 0xc, 0x0);
  277. regmap_update_bits(adau->regmap, ADAU17X1_CLOCK_CONTROL,
  278. ADAU17X1_CLOCK_CONTROL_SYSCLK_EN, 0);
  279. break;
  280. }
  281. return 0;
  282. }
  283. static bool adau1781_readable_register(struct device *dev, unsigned int reg)
  284. {
  285. switch (reg) {
  286. case ADAU1781_DMIC_BEEP_CTRL:
  287. case ADAU1781_LEFT_PGA:
  288. case ADAU1781_RIGHT_PGA:
  289. case ADAU1781_LEFT_PLAYBACK_MIXER:
  290. case ADAU1781_RIGHT_PLAYBACK_MIXER:
  291. case ADAU1781_MONO_PLAYBACK_MIXER:
  292. case ADAU1781_LEFT_LINEOUT:
  293. case ADAU1781_RIGHT_LINEOUT:
  294. case ADAU1781_SPEAKER:
  295. case ADAU1781_BEEP_ZC:
  296. case ADAU1781_DEJITTER:
  297. case ADAU1781_DIG_PWDN0:
  298. case ADAU1781_DIG_PWDN1:
  299. return true;
  300. default:
  301. break;
  302. }
  303. return adau17x1_readable_register(dev, reg);
  304. }
  305. static int adau1781_set_input_mode(struct adau *adau, unsigned int reg,
  306. bool differential)
  307. {
  308. unsigned int val;
  309. if (differential)
  310. val = ADAU1781_INPUT_DIFFERNTIAL;
  311. else
  312. val = 0;
  313. return regmap_update_bits(adau->regmap, reg,
  314. ADAU1781_INPUT_DIFFERNTIAL, val);
  315. }
  316. static int adau1781_codec_probe(struct snd_soc_codec *codec)
  317. {
  318. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  319. struct adau1781_platform_data *pdata = dev_get_platdata(codec->dev);
  320. struct adau *adau = snd_soc_codec_get_drvdata(codec);
  321. int ret;
  322. ret = adau17x1_add_widgets(codec);
  323. if (ret)
  324. return ret;
  325. if (pdata) {
  326. ret = adau1781_set_input_mode(adau, ADAU1781_LEFT_PGA,
  327. pdata->left_input_differential);
  328. if (ret)
  329. return ret;
  330. ret = adau1781_set_input_mode(adau, ADAU1781_RIGHT_PGA,
  331. pdata->right_input_differential);
  332. if (ret)
  333. return ret;
  334. }
  335. if (pdata && pdata->use_dmic) {
  336. ret = snd_soc_dapm_new_controls(dapm,
  337. adau1781_dmic_dapm_widgets,
  338. ARRAY_SIZE(adau1781_dmic_dapm_widgets));
  339. if (ret)
  340. return ret;
  341. ret = snd_soc_dapm_add_routes(dapm, adau1781_dmic_dapm_routes,
  342. ARRAY_SIZE(adau1781_dmic_dapm_routes));
  343. if (ret)
  344. return ret;
  345. } else {
  346. ret = snd_soc_dapm_add_routes(dapm, adau1781_adc_dapm_routes,
  347. ARRAY_SIZE(adau1781_adc_dapm_routes));
  348. if (ret)
  349. return ret;
  350. }
  351. ret = adau17x1_add_routes(codec);
  352. if (ret < 0)
  353. return ret;
  354. return 0;
  355. }
  356. static const struct snd_soc_codec_driver adau1781_codec_driver = {
  357. .probe = adau1781_codec_probe,
  358. .resume = adau17x1_resume,
  359. .set_bias_level = adau1781_set_bias_level,
  360. .suspend_bias_off = true,
  361. .controls = adau1781_controls,
  362. .num_controls = ARRAY_SIZE(adau1781_controls),
  363. .dapm_widgets = adau1781_dapm_widgets,
  364. .num_dapm_widgets = ARRAY_SIZE(adau1781_dapm_widgets),
  365. .dapm_routes = adau1781_dapm_routes,
  366. .num_dapm_routes = ARRAY_SIZE(adau1781_dapm_routes),
  367. };
  368. #define ADAU1781_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \
  369. SNDRV_PCM_FMTBIT_S32_LE)
  370. static struct snd_soc_dai_driver adau1781_dai_driver = {
  371. .name = "adau-hifi",
  372. .playback = {
  373. .stream_name = "Playback",
  374. .channels_min = 2,
  375. .channels_max = 8,
  376. .rates = SNDRV_PCM_RATE_8000_96000,
  377. .formats = ADAU1781_FORMATS,
  378. },
  379. .capture = {
  380. .stream_name = "Capture",
  381. .channels_min = 2,
  382. .channels_max = 8,
  383. .rates = SNDRV_PCM_RATE_8000_96000,
  384. .formats = ADAU1781_FORMATS,
  385. },
  386. .ops = &adau17x1_dai_ops,
  387. };
  388. const struct regmap_config adau1781_regmap_config = {
  389. .val_bits = 8,
  390. .reg_bits = 16,
  391. .max_register = 0x40f8,
  392. .reg_defaults = adau1781_reg_defaults,
  393. .num_reg_defaults = ARRAY_SIZE(adau1781_reg_defaults),
  394. .readable_reg = adau1781_readable_register,
  395. .volatile_reg = adau17x1_volatile_register,
  396. .precious_reg = adau17x1_precious_register,
  397. .cache_type = REGCACHE_RBTREE,
  398. };
  399. EXPORT_SYMBOL_GPL(adau1781_regmap_config);
  400. int adau1781_probe(struct device *dev, struct regmap *regmap,
  401. enum adau17x1_type type, void (*switch_mode)(struct device *dev))
  402. {
  403. const char *firmware_name;
  404. int ret;
  405. switch (type) {
  406. case ADAU1381:
  407. firmware_name = ADAU1381_FIRMWARE;
  408. break;
  409. case ADAU1781:
  410. firmware_name = ADAU1781_FIRMWARE;
  411. break;
  412. default:
  413. return -EINVAL;
  414. }
  415. ret = adau17x1_probe(dev, regmap, type, switch_mode, firmware_name);
  416. if (ret)
  417. return ret;
  418. return snd_soc_register_codec(dev, &adau1781_codec_driver,
  419. &adau1781_dai_driver, 1);
  420. }
  421. EXPORT_SYMBOL_GPL(adau1781_probe);
  422. MODULE_DESCRIPTION("ASoC ADAU1381/ADAU1781 driver");
  423. MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
  424. MODULE_LICENSE("GPL");