tlv320aic23.c 17 KB

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