tlv320aic23.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /*
  2. * ALSA SoC TLV320AIC23 codec driver
  3. *
  4. * Author: Arun KS, <arunks@mistralsolutions.com>
  5. * Copyright: (C) 2008 Mistral Solutions Pvt Ltd.,
  6. *
  7. * Based on sound/soc/codecs/wm8731.c by Richard Purdie
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * Notes:
  14. * The AIC23 is a driver for a low power stereo audio
  15. * codec tlv320aic23
  16. *
  17. * The machine layer should disable unsupported inputs/outputs by
  18. * snd_soc_dapm_disable_pin(codec, "LHPOUT"), etc.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/moduleparam.h>
  22. #include <linux/init.h>
  23. #include <linux/delay.h>
  24. #include <linux/pm.h>
  25. #include <linux/regmap.h>
  26. #include <linux/slab.h>
  27. #include <sound/core.h>
  28. #include <sound/pcm.h>
  29. #include <sound/pcm_params.h>
  30. #include <sound/soc.h>
  31. #include <sound/tlv.h>
  32. #include <sound/initval.h>
  33. #include "tlv320aic23.h"
  34. /*
  35. * AIC23 register cache
  36. */
  37. static const struct reg_default tlv320aic23_reg[] = {
  38. { 0, 0x0097 },
  39. { 1, 0x0097 },
  40. { 2, 0x00F9 },
  41. { 3, 0x00F9 },
  42. { 4, 0x001A },
  43. { 5, 0x0004 },
  44. { 6, 0x0007 },
  45. { 7, 0x0001 },
  46. { 8, 0x0020 },
  47. { 9, 0x0000 },
  48. };
  49. const struct regmap_config tlv320aic23_regmap = {
  50. .reg_bits = 7,
  51. .val_bits = 9,
  52. .max_register = TLV320AIC23_RESET,
  53. .reg_defaults = tlv320aic23_reg,
  54. .num_reg_defaults = ARRAY_SIZE(tlv320aic23_reg),
  55. .cache_type = REGCACHE_RBTREE,
  56. };
  57. EXPORT_SYMBOL(tlv320aic23_regmap);
  58. static const char *rec_src_text[] = { "Line", "Mic" };
  59. static const char *deemph_text[] = {"None", "32Khz", "44.1Khz", "48Khz"};
  60. static SOC_ENUM_SINGLE_DECL(rec_src_enum,
  61. TLV320AIC23_ANLG, 2, rec_src_text);
  62. static const struct snd_kcontrol_new tlv320aic23_rec_src_mux_controls =
  63. SOC_DAPM_ENUM("Input Select", rec_src_enum);
  64. static SOC_ENUM_SINGLE_DECL(tlv320aic23_rec_src,
  65. TLV320AIC23_ANLG, 2, rec_src_text);
  66. static SOC_ENUM_SINGLE_DECL(tlv320aic23_deemph,
  67. TLV320AIC23_DIGT, 1, deemph_text);
  68. static const DECLARE_TLV_DB_SCALE(out_gain_tlv, -12100, 100, 0);
  69. static const DECLARE_TLV_DB_SCALE(input_gain_tlv, -1725, 75, 0);
  70. static const DECLARE_TLV_DB_SCALE(sidetone_vol_tlv, -1800, 300, 0);
  71. static int snd_soc_tlv320aic23_put_volsw(struct snd_kcontrol *kcontrol,
  72. struct snd_ctl_elem_value *ucontrol)
  73. {
  74. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  75. u16 val, reg;
  76. val = (ucontrol->value.integer.value[0] & 0x07);
  77. /* linear conversion to userspace
  78. * 000 = -6db
  79. * 001 = -9db
  80. * 010 = -12db
  81. * 011 = -18db (Min)
  82. * 100 = 0db (Max)
  83. */
  84. val = (val >= 4) ? 4 : (3 - val);
  85. reg = snd_soc_read(codec, TLV320AIC23_ANLG) & (~0x1C0);
  86. snd_soc_write(codec, TLV320AIC23_ANLG, reg | (val << 6));
  87. return 0;
  88. }
  89. static int snd_soc_tlv320aic23_get_volsw(struct snd_kcontrol *kcontrol,
  90. struct snd_ctl_elem_value *ucontrol)
  91. {
  92. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  93. u16 val;
  94. val = snd_soc_read(codec, TLV320AIC23_ANLG) & (0x1C0);
  95. val = val >> 6;
  96. val = (val >= 4) ? 4 : (3 - val);
  97. ucontrol->value.integer.value[0] = val;
  98. return 0;
  99. }
  100. static const struct snd_kcontrol_new tlv320aic23_snd_controls[] = {
  101. SOC_DOUBLE_R_TLV("Digital Playback Volume", TLV320AIC23_LCHNVOL,
  102. TLV320AIC23_RCHNVOL, 0, 127, 0, out_gain_tlv),
  103. SOC_SINGLE("Digital Playback Switch", TLV320AIC23_DIGT, 3, 1, 1),
  104. SOC_DOUBLE_R("Line Input Switch", TLV320AIC23_LINVOL,
  105. TLV320AIC23_RINVOL, 7, 1, 0),
  106. SOC_DOUBLE_R_TLV("Line Input Volume", TLV320AIC23_LINVOL,
  107. TLV320AIC23_RINVOL, 0, 31, 0, input_gain_tlv),
  108. SOC_SINGLE("Mic Input Switch", TLV320AIC23_ANLG, 1, 1, 1),
  109. SOC_SINGLE("Mic Booster Switch", TLV320AIC23_ANLG, 0, 1, 0),
  110. SOC_SINGLE_EXT_TLV("Sidetone Volume", TLV320AIC23_ANLG, 6, 4, 0,
  111. snd_soc_tlv320aic23_get_volsw,
  112. snd_soc_tlv320aic23_put_volsw, sidetone_vol_tlv),
  113. SOC_ENUM("Playback De-emphasis", tlv320aic23_deemph),
  114. };
  115. /* PGA Mixer controls for Line and Mic switch */
  116. static const struct snd_kcontrol_new tlv320aic23_output_mixer_controls[] = {
  117. SOC_DAPM_SINGLE("Line Bypass Switch", TLV320AIC23_ANLG, 3, 1, 0),
  118. SOC_DAPM_SINGLE("Mic Sidetone Switch", TLV320AIC23_ANLG, 5, 1, 0),
  119. SOC_DAPM_SINGLE("Playback Switch", TLV320AIC23_ANLG, 4, 1, 0),
  120. };
  121. static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
  122. SND_SOC_DAPM_DAC("DAC", "Playback", TLV320AIC23_PWR, 3, 1),
  123. SND_SOC_DAPM_ADC("ADC", "Capture", TLV320AIC23_PWR, 2, 1),
  124. SND_SOC_DAPM_MUX("Capture Source", SND_SOC_NOPM, 0, 0,
  125. &tlv320aic23_rec_src_mux_controls),
  126. SND_SOC_DAPM_MIXER("Output Mixer", TLV320AIC23_PWR, 4, 1,
  127. &tlv320aic23_output_mixer_controls[0],
  128. ARRAY_SIZE(tlv320aic23_output_mixer_controls)),
  129. SND_SOC_DAPM_PGA("Line Input", TLV320AIC23_PWR, 0, 1, NULL, 0),
  130. SND_SOC_DAPM_PGA("Mic Input", TLV320AIC23_PWR, 1, 1, NULL, 0),
  131. SND_SOC_DAPM_OUTPUT("LHPOUT"),
  132. SND_SOC_DAPM_OUTPUT("RHPOUT"),
  133. SND_SOC_DAPM_OUTPUT("LOUT"),
  134. SND_SOC_DAPM_OUTPUT("ROUT"),
  135. SND_SOC_DAPM_INPUT("LLINEIN"),
  136. SND_SOC_DAPM_INPUT("RLINEIN"),
  137. SND_SOC_DAPM_INPUT("MICIN"),
  138. };
  139. static const struct snd_soc_dapm_route tlv320aic23_intercon[] = {
  140. /* Output Mixer */
  141. {"Output Mixer", "Line Bypass Switch", "Line Input"},
  142. {"Output Mixer", "Playback Switch", "DAC"},
  143. {"Output Mixer", "Mic Sidetone Switch", "Mic Input"},
  144. /* Outputs */
  145. {"RHPOUT", NULL, "Output Mixer"},
  146. {"LHPOUT", NULL, "Output Mixer"},
  147. {"LOUT", NULL, "Output Mixer"},
  148. {"ROUT", NULL, "Output Mixer"},
  149. /* Inputs */
  150. {"Line Input", "NULL", "LLINEIN"},
  151. {"Line Input", "NULL", "RLINEIN"},
  152. {"Mic Input", "NULL", "MICIN"},
  153. /* input mux */
  154. {"Capture Source", "Line", "Line Input"},
  155. {"Capture Source", "Mic", "Mic Input"},
  156. {"ADC", NULL, "Capture Source"},
  157. };
  158. /* AIC23 driver data */
  159. struct aic23 {
  160. struct regmap *regmap;
  161. int mclk;
  162. int requested_adc;
  163. int requested_dac;
  164. };
  165. /*
  166. * Common Crystals used
  167. * 11.2896 Mhz /128 = *88.2k /192 = 58.8k
  168. * 12.0000 Mhz /125 = *96k /136 = 88.235K
  169. * 12.2880 Mhz /128 = *96k /192 = 64k
  170. * 16.9344 Mhz /128 = 132.3k /192 = *88.2k
  171. * 18.4320 Mhz /128 = 144k /192 = *96k
  172. */
  173. /*
  174. * Normal BOSR 0-256/2 = 128, 1-384/2 = 192
  175. * USB BOSR 0-250/2 = 125, 1-272/2 = 136
  176. */
  177. static const int bosr_usb_divisor_table[] = {
  178. 128, 125, 192, 136
  179. };
  180. #define LOWER_GROUP ((1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<6) | (1<<7))
  181. #define UPPER_GROUP ((1<<8) | (1<<9) | (1<<10) | (1<<11) | (1<<15))
  182. static const unsigned short sr_valid_mask[] = {
  183. LOWER_GROUP|UPPER_GROUP, /* Normal, bosr - 0*/
  184. LOWER_GROUP, /* Usb, bosr - 0*/
  185. LOWER_GROUP|UPPER_GROUP, /* Normal, bosr - 1*/
  186. UPPER_GROUP, /* Usb, bosr - 1*/
  187. };
  188. /*
  189. * Every divisor is a factor of 11*12
  190. */
  191. #define SR_MULT (11*12)
  192. #define A(x) (SR_MULT/x)
  193. static const unsigned char sr_adc_mult_table[] = {
  194. A(2), A(2), A(12), A(12), 0, 0, A(3), A(1),
  195. A(2), A(2), A(11), A(11), 0, 0, 0, A(1)
  196. };
  197. static const unsigned char sr_dac_mult_table[] = {
  198. A(2), A(12), A(2), A(12), 0, 0, A(3), A(1),
  199. A(2), A(11), A(2), A(11), 0, 0, 0, A(1)
  200. };
  201. static unsigned get_score(int adc, int adc_l, int adc_h, int need_adc,
  202. int dac, int dac_l, int dac_h, int need_dac)
  203. {
  204. if ((adc >= adc_l) && (adc <= adc_h) &&
  205. (dac >= dac_l) && (dac <= dac_h)) {
  206. int diff_adc = need_adc - adc;
  207. int diff_dac = need_dac - dac;
  208. return abs(diff_adc) + abs(diff_dac);
  209. }
  210. return UINT_MAX;
  211. }
  212. static int find_rate(int mclk, u32 need_adc, u32 need_dac)
  213. {
  214. int i, j;
  215. int best_i = -1;
  216. int best_j = -1;
  217. int best_div = 0;
  218. unsigned best_score = UINT_MAX;
  219. int adc_l, adc_h, dac_l, dac_h;
  220. need_adc *= SR_MULT;
  221. need_dac *= SR_MULT;
  222. /*
  223. * rates given are +/- 1/32
  224. */
  225. adc_l = need_adc - (need_adc >> 5);
  226. adc_h = need_adc + (need_adc >> 5);
  227. dac_l = need_dac - (need_dac >> 5);
  228. dac_h = need_dac + (need_dac >> 5);
  229. for (i = 0; i < ARRAY_SIZE(bosr_usb_divisor_table); i++) {
  230. int base = mclk / bosr_usb_divisor_table[i];
  231. int mask = sr_valid_mask[i];
  232. for (j = 0; j < ARRAY_SIZE(sr_adc_mult_table);
  233. j++, mask >>= 1) {
  234. int adc;
  235. int dac;
  236. int score;
  237. if ((mask & 1) == 0)
  238. continue;
  239. adc = base * sr_adc_mult_table[j];
  240. dac = base * sr_dac_mult_table[j];
  241. score = get_score(adc, adc_l, adc_h, need_adc,
  242. dac, dac_l, dac_h, need_dac);
  243. if (best_score > score) {
  244. best_score = score;
  245. best_i = i;
  246. best_j = j;
  247. best_div = 0;
  248. }
  249. score = get_score((adc >> 1), adc_l, adc_h, need_adc,
  250. (dac >> 1), dac_l, dac_h, need_dac);
  251. /* prefer to have a /2 */
  252. if ((score != UINT_MAX) && (best_score >= score)) {
  253. best_score = score;
  254. best_i = i;
  255. best_j = j;
  256. best_div = 1;
  257. }
  258. }
  259. }
  260. return (best_j << 2) | best_i | (best_div << TLV320AIC23_CLKIN_SHIFT);
  261. }
  262. #ifdef DEBUG
  263. static void get_current_sample_rates(struct snd_soc_codec *codec, int mclk,
  264. u32 *sample_rate_adc, u32 *sample_rate_dac)
  265. {
  266. int src = snd_soc_read(codec, TLV320AIC23_SRATE);
  267. int sr = (src >> 2) & 0x0f;
  268. int val = (mclk / bosr_usb_divisor_table[src & 3]);
  269. int adc = (val * sr_adc_mult_table[sr]) / SR_MULT;
  270. int dac = (val * sr_dac_mult_table[sr]) / SR_MULT;
  271. if (src & TLV320AIC23_CLKIN_HALF) {
  272. adc >>= 1;
  273. dac >>= 1;
  274. }
  275. *sample_rate_adc = adc;
  276. *sample_rate_dac = dac;
  277. }
  278. #endif
  279. static int set_sample_rate_control(struct snd_soc_codec *codec, int mclk,
  280. u32 sample_rate_adc, u32 sample_rate_dac)
  281. {
  282. /* Search for the right sample rate */
  283. int data = find_rate(mclk, sample_rate_adc, sample_rate_dac);
  284. if (data < 0) {
  285. printk(KERN_ERR "%s:Invalid rate %u,%u requested\n",
  286. __func__, sample_rate_adc, sample_rate_dac);
  287. return -EINVAL;
  288. }
  289. snd_soc_write(codec, TLV320AIC23_SRATE, data);
  290. #ifdef DEBUG
  291. {
  292. u32 adc, dac;
  293. get_current_sample_rates(codec, mclk, &adc, &dac);
  294. printk(KERN_DEBUG "actual samplerate = %u,%u reg=%x\n",
  295. adc, dac, data);
  296. }
  297. #endif
  298. return 0;
  299. }
  300. static int tlv320aic23_hw_params(struct snd_pcm_substream *substream,
  301. struct snd_pcm_hw_params *params,
  302. struct snd_soc_dai *dai)
  303. {
  304. struct snd_soc_codec *codec = dai->codec;
  305. u16 iface_reg;
  306. int ret;
  307. struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec);
  308. u32 sample_rate_adc = aic23->requested_adc;
  309. u32 sample_rate_dac = aic23->requested_dac;
  310. u32 sample_rate = params_rate(params);
  311. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  312. aic23->requested_dac = sample_rate_dac = sample_rate;
  313. if (!sample_rate_adc)
  314. sample_rate_adc = sample_rate;
  315. } else {
  316. aic23->requested_adc = sample_rate_adc = sample_rate;
  317. if (!sample_rate_dac)
  318. sample_rate_dac = sample_rate;
  319. }
  320. ret = set_sample_rate_control(codec, aic23->mclk, sample_rate_adc,
  321. sample_rate_dac);
  322. if (ret < 0)
  323. return ret;
  324. iface_reg = snd_soc_read(codec, TLV320AIC23_DIGT_FMT) & ~(0x03 << 2);
  325. switch (params_width(params)) {
  326. case 16:
  327. break;
  328. case 20:
  329. iface_reg |= (0x01 << 2);
  330. break;
  331. case 24:
  332. iface_reg |= (0x02 << 2);
  333. break;
  334. case 32:
  335. iface_reg |= (0x03 << 2);
  336. break;
  337. }
  338. snd_soc_write(codec, TLV320AIC23_DIGT_FMT, iface_reg);
  339. return 0;
  340. }
  341. static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream,
  342. struct snd_soc_dai *dai)
  343. {
  344. struct snd_soc_codec *codec = dai->codec;
  345. /* set active */
  346. snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x0001);
  347. return 0;
  348. }
  349. static void tlv320aic23_shutdown(struct snd_pcm_substream *substream,
  350. struct snd_soc_dai *dai)
  351. {
  352. struct snd_soc_codec *codec = dai->codec;
  353. struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec);
  354. /* deactivate */
  355. if (!snd_soc_codec_is_active(codec)) {
  356. udelay(50);
  357. snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x0);
  358. }
  359. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  360. aic23->requested_dac = 0;
  361. else
  362. aic23->requested_adc = 0;
  363. }
  364. static int tlv320aic23_mute(struct snd_soc_dai *dai, int mute)
  365. {
  366. struct snd_soc_codec *codec = dai->codec;
  367. u16 reg;
  368. reg = snd_soc_read(codec, TLV320AIC23_DIGT);
  369. if (mute)
  370. reg |= TLV320AIC23_DACM_MUTE;
  371. else
  372. reg &= ~TLV320AIC23_DACM_MUTE;
  373. snd_soc_write(codec, TLV320AIC23_DIGT, reg);
  374. return 0;
  375. }
  376. static int tlv320aic23_set_dai_fmt(struct snd_soc_dai *codec_dai,
  377. unsigned int fmt)
  378. {
  379. struct snd_soc_codec *codec = codec_dai->codec;
  380. u16 iface_reg;
  381. iface_reg = snd_soc_read(codec, TLV320AIC23_DIGT_FMT) & (~0x03);
  382. /* set master/slave audio interface */
  383. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  384. case SND_SOC_DAIFMT_CBM_CFM:
  385. iface_reg |= TLV320AIC23_MS_MASTER;
  386. break;
  387. case SND_SOC_DAIFMT_CBS_CFS:
  388. iface_reg &= ~TLV320AIC23_MS_MASTER;
  389. break;
  390. default:
  391. return -EINVAL;
  392. }
  393. /* interface format */
  394. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  395. case SND_SOC_DAIFMT_I2S:
  396. iface_reg |= TLV320AIC23_FOR_I2S;
  397. break;
  398. case SND_SOC_DAIFMT_DSP_A:
  399. iface_reg |= TLV320AIC23_LRP_ON;
  400. case SND_SOC_DAIFMT_DSP_B:
  401. iface_reg |= TLV320AIC23_FOR_DSP;
  402. break;
  403. case SND_SOC_DAIFMT_RIGHT_J:
  404. break;
  405. case SND_SOC_DAIFMT_LEFT_J:
  406. iface_reg |= TLV320AIC23_FOR_LJUST;
  407. break;
  408. default:
  409. return -EINVAL;
  410. }
  411. snd_soc_write(codec, TLV320AIC23_DIGT_FMT, iface_reg);
  412. return 0;
  413. }
  414. static int tlv320aic23_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  415. int clk_id, unsigned int freq, int dir)
  416. {
  417. struct aic23 *aic23 = snd_soc_dai_get_drvdata(codec_dai);
  418. aic23->mclk = freq;
  419. return 0;
  420. }
  421. static int tlv320aic23_set_bias_level(struct snd_soc_codec *codec,
  422. enum snd_soc_bias_level level)
  423. {
  424. u16 reg = snd_soc_read(codec, TLV320AIC23_PWR) & 0x17f;
  425. switch (level) {
  426. case SND_SOC_BIAS_ON:
  427. /* vref/mid, osc on, dac unmute */
  428. reg &= ~(TLV320AIC23_DEVICE_PWR_OFF | TLV320AIC23_OSC_OFF | \
  429. TLV320AIC23_DAC_OFF);
  430. snd_soc_write(codec, TLV320AIC23_PWR, reg);
  431. break;
  432. case SND_SOC_BIAS_PREPARE:
  433. break;
  434. case SND_SOC_BIAS_STANDBY:
  435. /* everything off except vref/vmid, */
  436. snd_soc_write(codec, TLV320AIC23_PWR,
  437. reg | TLV320AIC23_CLK_OFF);
  438. break;
  439. case SND_SOC_BIAS_OFF:
  440. /* everything off, dac mute, inactive */
  441. snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x0);
  442. snd_soc_write(codec, TLV320AIC23_PWR, 0x1ff);
  443. break;
  444. }
  445. return 0;
  446. }
  447. #define AIC23_RATES SNDRV_PCM_RATE_8000_96000
  448. #define AIC23_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  449. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  450. static const struct snd_soc_dai_ops tlv320aic23_dai_ops = {
  451. .prepare = tlv320aic23_pcm_prepare,
  452. .hw_params = tlv320aic23_hw_params,
  453. .shutdown = tlv320aic23_shutdown,
  454. .digital_mute = tlv320aic23_mute,
  455. .set_fmt = tlv320aic23_set_dai_fmt,
  456. .set_sysclk = tlv320aic23_set_dai_sysclk,
  457. };
  458. static struct snd_soc_dai_driver tlv320aic23_dai = {
  459. .name = "tlv320aic23-hifi",
  460. .playback = {
  461. .stream_name = "Playback",
  462. .channels_min = 2,
  463. .channels_max = 2,
  464. .rates = AIC23_RATES,
  465. .formats = AIC23_FORMATS,},
  466. .capture = {
  467. .stream_name = "Capture",
  468. .channels_min = 2,
  469. .channels_max = 2,
  470. .rates = AIC23_RATES,
  471. .formats = AIC23_FORMATS,},
  472. .ops = &tlv320aic23_dai_ops,
  473. };
  474. static int tlv320aic23_resume(struct snd_soc_codec *codec)
  475. {
  476. struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec);
  477. regcache_mark_dirty(aic23->regmap);
  478. regcache_sync(aic23->regmap);
  479. return 0;
  480. }
  481. static int tlv320aic23_codec_probe(struct snd_soc_codec *codec)
  482. {
  483. /* Reset codec */
  484. snd_soc_write(codec, TLV320AIC23_RESET, 0);
  485. snd_soc_write(codec, TLV320AIC23_DIGT, TLV320AIC23_DEEMP_44K);
  486. /* Unmute input */
  487. snd_soc_update_bits(codec, TLV320AIC23_LINVOL,
  488. TLV320AIC23_LIM_MUTED, TLV320AIC23_LRS_ENABLED);
  489. snd_soc_update_bits(codec, TLV320AIC23_RINVOL,
  490. TLV320AIC23_LIM_MUTED, TLV320AIC23_LRS_ENABLED);
  491. snd_soc_update_bits(codec, TLV320AIC23_ANLG,
  492. TLV320AIC23_BYPASS_ON | TLV320AIC23_MICM_MUTED,
  493. 0);
  494. /* Default output volume */
  495. snd_soc_write(codec, TLV320AIC23_LCHNVOL,
  496. TLV320AIC23_DEFAULT_OUT_VOL & TLV320AIC23_OUT_VOL_MASK);
  497. snd_soc_write(codec, TLV320AIC23_RCHNVOL,
  498. TLV320AIC23_DEFAULT_OUT_VOL & TLV320AIC23_OUT_VOL_MASK);
  499. snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x1);
  500. return 0;
  501. }
  502. static struct snd_soc_codec_driver soc_codec_dev_tlv320aic23 = {
  503. .probe = tlv320aic23_codec_probe,
  504. .resume = tlv320aic23_resume,
  505. .set_bias_level = tlv320aic23_set_bias_level,
  506. .suspend_bias_off = true,
  507. .component_driver = {
  508. .controls = tlv320aic23_snd_controls,
  509. .num_controls = ARRAY_SIZE(tlv320aic23_snd_controls),
  510. .dapm_widgets = tlv320aic23_dapm_widgets,
  511. .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
  512. .dapm_routes = tlv320aic23_intercon,
  513. .num_dapm_routes = ARRAY_SIZE(tlv320aic23_intercon),
  514. },
  515. };
  516. int tlv320aic23_probe(struct device *dev, struct regmap *regmap)
  517. {
  518. struct aic23 *aic23;
  519. if (IS_ERR(regmap))
  520. return PTR_ERR(regmap);
  521. aic23 = devm_kzalloc(dev, sizeof(struct aic23), GFP_KERNEL);
  522. if (aic23 == NULL)
  523. return -ENOMEM;
  524. aic23->regmap = regmap;
  525. dev_set_drvdata(dev, aic23);
  526. return snd_soc_register_codec(dev, &soc_codec_dev_tlv320aic23,
  527. &tlv320aic23_dai, 1);
  528. }
  529. EXPORT_SYMBOL(tlv320aic23_probe);
  530. MODULE_DESCRIPTION("ASoC TLV320AIC23 codec driver");
  531. MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
  532. MODULE_LICENSE("GPL");