tas5720.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /*
  2. * tas5720.c - ALSA SoC Texas Instruments TAS5720 Mono Audio Amplifier
  3. *
  4. * Copyright (C)2015-2016 Texas Instruments Incorporated - http://www.ti.com
  5. *
  6. * Author: Andreas Dannenberg <dannenberg@ti.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/errno.h>
  19. #include <linux/device.h>
  20. #include <linux/i2c.h>
  21. #include <linux/pm_runtime.h>
  22. #include <linux/regmap.h>
  23. #include <linux/slab.h>
  24. #include <linux/regulator/consumer.h>
  25. #include <linux/delay.h>
  26. #include <sound/pcm.h>
  27. #include <sound/pcm_params.h>
  28. #include <sound/soc.h>
  29. #include <sound/soc-dapm.h>
  30. #include <sound/tlv.h>
  31. #include "tas5720.h"
  32. /* Define how often to check (and clear) the fault status register (in ms) */
  33. #define TAS5720_FAULT_CHECK_INTERVAL 200
  34. static const char * const tas5720_supply_names[] = {
  35. "dvdd", /* Digital power supply. Connect to 3.3-V supply. */
  36. "pvdd", /* Class-D amp and analog power supply (connected). */
  37. };
  38. #define TAS5720_NUM_SUPPLIES ARRAY_SIZE(tas5720_supply_names)
  39. struct tas5720_data {
  40. struct snd_soc_codec *codec;
  41. struct regmap *regmap;
  42. struct i2c_client *tas5720_client;
  43. struct regulator_bulk_data supplies[TAS5720_NUM_SUPPLIES];
  44. struct delayed_work fault_check_work;
  45. unsigned int last_fault;
  46. };
  47. static int tas5720_hw_params(struct snd_pcm_substream *substream,
  48. struct snd_pcm_hw_params *params,
  49. struct snd_soc_dai *dai)
  50. {
  51. struct snd_soc_codec *codec = dai->codec;
  52. unsigned int rate = params_rate(params);
  53. bool ssz_ds;
  54. int ret;
  55. switch (rate) {
  56. case 44100:
  57. case 48000:
  58. ssz_ds = false;
  59. break;
  60. case 88200:
  61. case 96000:
  62. ssz_ds = true;
  63. break;
  64. default:
  65. dev_err(codec->dev, "unsupported sample rate: %u\n", rate);
  66. return -EINVAL;
  67. }
  68. ret = snd_soc_update_bits(codec, TAS5720_DIGITAL_CTRL1_REG,
  69. TAS5720_SSZ_DS, ssz_ds);
  70. if (ret < 0) {
  71. dev_err(codec->dev, "error setting sample rate: %d\n", ret);
  72. return ret;
  73. }
  74. return 0;
  75. }
  76. static int tas5720_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  77. {
  78. struct snd_soc_codec *codec = dai->codec;
  79. u8 serial_format;
  80. int ret;
  81. if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) {
  82. dev_vdbg(codec->dev, "DAI Format master is not found\n");
  83. return -EINVAL;
  84. }
  85. switch (fmt & (SND_SOC_DAIFMT_FORMAT_MASK |
  86. SND_SOC_DAIFMT_INV_MASK)) {
  87. case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF):
  88. /* 1st data bit occur one BCLK cycle after the frame sync */
  89. serial_format = TAS5720_SAIF_I2S;
  90. break;
  91. case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF):
  92. /*
  93. * Note that although the TAS5720 does not have a dedicated DSP
  94. * mode it doesn't care about the LRCLK duty cycle during TDM
  95. * operation. Therefore we can use the device's I2S mode with
  96. * its delaying of the 1st data bit to receive DSP_A formatted
  97. * data. See device datasheet for additional details.
  98. */
  99. serial_format = TAS5720_SAIF_I2S;
  100. break;
  101. case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF):
  102. /*
  103. * Similar to DSP_A, we can use the fact that the TAS5720 does
  104. * not care about the LRCLK duty cycle during TDM to receive
  105. * DSP_B formatted data in LEFTJ mode (no delaying of the 1st
  106. * data bit).
  107. */
  108. serial_format = TAS5720_SAIF_LEFTJ;
  109. break;
  110. case (SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF):
  111. /* No delay after the frame sync */
  112. serial_format = TAS5720_SAIF_LEFTJ;
  113. break;
  114. default:
  115. dev_vdbg(codec->dev, "DAI Format is not found\n");
  116. return -EINVAL;
  117. }
  118. ret = snd_soc_update_bits(codec, TAS5720_DIGITAL_CTRL1_REG,
  119. TAS5720_SAIF_FORMAT_MASK,
  120. serial_format);
  121. if (ret < 0) {
  122. dev_err(codec->dev, "error setting SAIF format: %d\n", ret);
  123. return ret;
  124. }
  125. return 0;
  126. }
  127. static int tas5720_set_dai_tdm_slot(struct snd_soc_dai *dai,
  128. unsigned int tx_mask, unsigned int rx_mask,
  129. int slots, int slot_width)
  130. {
  131. struct snd_soc_codec *codec = dai->codec;
  132. unsigned int first_slot;
  133. int ret;
  134. if (!tx_mask) {
  135. dev_err(codec->dev, "tx masks must not be 0\n");
  136. return -EINVAL;
  137. }
  138. /*
  139. * Determine the first slot that is being requested. We will only
  140. * use the first slot that is found since the TAS5720 is a mono
  141. * amplifier.
  142. */
  143. first_slot = __ffs(tx_mask);
  144. if (first_slot > 7) {
  145. dev_err(codec->dev, "slot selection out of bounds (%u)\n",
  146. first_slot);
  147. return -EINVAL;
  148. }
  149. /* Enable manual TDM slot selection (instead of I2C ID based) */
  150. ret = snd_soc_update_bits(codec, TAS5720_DIGITAL_CTRL1_REG,
  151. TAS5720_TDM_CFG_SRC, TAS5720_TDM_CFG_SRC);
  152. if (ret < 0)
  153. goto error_snd_soc_update_bits;
  154. /* Configure the TDM slot to process audio from */
  155. ret = snd_soc_update_bits(codec, TAS5720_DIGITAL_CTRL2_REG,
  156. TAS5720_TDM_SLOT_SEL_MASK, first_slot);
  157. if (ret < 0)
  158. goto error_snd_soc_update_bits;
  159. return 0;
  160. error_snd_soc_update_bits:
  161. dev_err(codec->dev, "error configuring TDM mode: %d\n", ret);
  162. return ret;
  163. }
  164. static int tas5720_mute(struct snd_soc_dai *dai, int mute)
  165. {
  166. struct snd_soc_codec *codec = dai->codec;
  167. int ret;
  168. ret = snd_soc_update_bits(codec, TAS5720_DIGITAL_CTRL2_REG,
  169. TAS5720_MUTE, mute ? TAS5720_MUTE : 0);
  170. if (ret < 0) {
  171. dev_err(codec->dev, "error (un-)muting device: %d\n", ret);
  172. return ret;
  173. }
  174. return 0;
  175. }
  176. static void tas5720_fault_check_work(struct work_struct *work)
  177. {
  178. struct tas5720_data *tas5720 = container_of(work, struct tas5720_data,
  179. fault_check_work.work);
  180. struct device *dev = tas5720->codec->dev;
  181. unsigned int curr_fault;
  182. int ret;
  183. ret = regmap_read(tas5720->regmap, TAS5720_FAULT_REG, &curr_fault);
  184. if (ret < 0) {
  185. dev_err(dev, "failed to read FAULT register: %d\n", ret);
  186. goto out;
  187. }
  188. /* Check/handle all errors except SAIF clock errors */
  189. curr_fault &= TAS5720_OCE | TAS5720_DCE | TAS5720_OTE;
  190. /*
  191. * Only flag errors once for a given occurrence. This is needed as
  192. * the TAS5720 will take time clearing the fault condition internally
  193. * during which we don't want to bombard the system with the same
  194. * error message over and over.
  195. */
  196. if ((curr_fault & TAS5720_OCE) && !(tas5720->last_fault & TAS5720_OCE))
  197. dev_crit(dev, "experienced an over current hardware fault\n");
  198. if ((curr_fault & TAS5720_DCE) && !(tas5720->last_fault & TAS5720_DCE))
  199. dev_crit(dev, "experienced a DC detection fault\n");
  200. if ((curr_fault & TAS5720_OTE) && !(tas5720->last_fault & TAS5720_OTE))
  201. dev_crit(dev, "experienced an over temperature fault\n");
  202. /* Store current fault value so we can detect any changes next time */
  203. tas5720->last_fault = curr_fault;
  204. if (!curr_fault)
  205. goto out;
  206. /*
  207. * Periodically toggle SDZ (shutdown bit) H->L->H to clear any latching
  208. * faults as long as a fault condition persists. Always going through
  209. * the full sequence no matter the first return value to minimizes
  210. * chances for the device to end up in shutdown mode.
  211. */
  212. ret = regmap_write_bits(tas5720->regmap, TAS5720_POWER_CTRL_REG,
  213. TAS5720_SDZ, 0);
  214. if (ret < 0)
  215. dev_err(dev, "failed to write POWER_CTRL register: %d\n", ret);
  216. ret = regmap_write_bits(tas5720->regmap, TAS5720_POWER_CTRL_REG,
  217. TAS5720_SDZ, TAS5720_SDZ);
  218. if (ret < 0)
  219. dev_err(dev, "failed to write POWER_CTRL register: %d\n", ret);
  220. out:
  221. /* Schedule the next fault check at the specified interval */
  222. schedule_delayed_work(&tas5720->fault_check_work,
  223. msecs_to_jiffies(TAS5720_FAULT_CHECK_INTERVAL));
  224. }
  225. static int tas5720_codec_probe(struct snd_soc_codec *codec)
  226. {
  227. struct tas5720_data *tas5720 = snd_soc_codec_get_drvdata(codec);
  228. unsigned int device_id;
  229. int ret;
  230. tas5720->codec = codec;
  231. ret = regulator_bulk_enable(ARRAY_SIZE(tas5720->supplies),
  232. tas5720->supplies);
  233. if (ret != 0) {
  234. dev_err(codec->dev, "failed to enable supplies: %d\n", ret);
  235. return ret;
  236. }
  237. ret = regmap_read(tas5720->regmap, TAS5720_DEVICE_ID_REG, &device_id);
  238. if (ret < 0) {
  239. dev_err(codec->dev, "failed to read device ID register: %d\n",
  240. ret);
  241. goto probe_fail;
  242. }
  243. if (device_id != TAS5720_DEVICE_ID) {
  244. dev_err(codec->dev, "wrong device ID. expected: %u read: %u\n",
  245. TAS5720_DEVICE_ID, device_id);
  246. ret = -ENODEV;
  247. goto probe_fail;
  248. }
  249. /* Set device to mute */
  250. ret = snd_soc_update_bits(codec, TAS5720_DIGITAL_CTRL2_REG,
  251. TAS5720_MUTE, TAS5720_MUTE);
  252. if (ret < 0)
  253. goto error_snd_soc_update_bits;
  254. /*
  255. * Enter shutdown mode - our default when not playing audio - to
  256. * minimize current consumption. On the TAS5720 there is no real down
  257. * side doing so as all device registers are preserved and the wakeup
  258. * of the codec is rather quick which we do using a dapm widget.
  259. */
  260. ret = snd_soc_update_bits(codec, TAS5720_POWER_CTRL_REG,
  261. TAS5720_SDZ, 0);
  262. if (ret < 0)
  263. goto error_snd_soc_update_bits;
  264. INIT_DELAYED_WORK(&tas5720->fault_check_work, tas5720_fault_check_work);
  265. return 0;
  266. error_snd_soc_update_bits:
  267. dev_err(codec->dev, "error configuring device registers: %d\n", ret);
  268. probe_fail:
  269. regulator_bulk_disable(ARRAY_SIZE(tas5720->supplies),
  270. tas5720->supplies);
  271. return ret;
  272. }
  273. static int tas5720_codec_remove(struct snd_soc_codec *codec)
  274. {
  275. struct tas5720_data *tas5720 = snd_soc_codec_get_drvdata(codec);
  276. int ret;
  277. cancel_delayed_work_sync(&tas5720->fault_check_work);
  278. ret = regulator_bulk_disable(ARRAY_SIZE(tas5720->supplies),
  279. tas5720->supplies);
  280. if (ret < 0)
  281. dev_err(codec->dev, "failed to disable supplies: %d\n", ret);
  282. return ret;
  283. };
  284. static int tas5720_dac_event(struct snd_soc_dapm_widget *w,
  285. struct snd_kcontrol *kcontrol, int event)
  286. {
  287. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  288. struct tas5720_data *tas5720 = snd_soc_codec_get_drvdata(codec);
  289. int ret;
  290. if (event & SND_SOC_DAPM_POST_PMU) {
  291. /* Take TAS5720 out of shutdown mode */
  292. ret = snd_soc_update_bits(codec, TAS5720_POWER_CTRL_REG,
  293. TAS5720_SDZ, TAS5720_SDZ);
  294. if (ret < 0) {
  295. dev_err(codec->dev, "error waking codec: %d\n", ret);
  296. return ret;
  297. }
  298. /*
  299. * Observe codec shutdown-to-active time. The datasheet only
  300. * lists a nominal value however just use-it as-is without
  301. * additional padding to minimize the delay introduced in
  302. * starting to play audio (actually there is other setup done
  303. * by the ASoC framework that will provide additional delays,
  304. * so we should always be safe).
  305. */
  306. msleep(25);
  307. /* Turn on TAS5720 periodic fault checking/handling */
  308. tas5720->last_fault = 0;
  309. schedule_delayed_work(&tas5720->fault_check_work,
  310. msecs_to_jiffies(TAS5720_FAULT_CHECK_INTERVAL));
  311. } else if (event & SND_SOC_DAPM_PRE_PMD) {
  312. /* Disable TAS5720 periodic fault checking/handling */
  313. cancel_delayed_work_sync(&tas5720->fault_check_work);
  314. /* Place TAS5720 in shutdown mode to minimize current draw */
  315. ret = snd_soc_update_bits(codec, TAS5720_POWER_CTRL_REG,
  316. TAS5720_SDZ, 0);
  317. if (ret < 0) {
  318. dev_err(codec->dev, "error shutting down codec: %d\n",
  319. ret);
  320. return ret;
  321. }
  322. }
  323. return 0;
  324. }
  325. #ifdef CONFIG_PM
  326. static int tas5720_suspend(struct snd_soc_codec *codec)
  327. {
  328. struct tas5720_data *tas5720 = snd_soc_codec_get_drvdata(codec);
  329. int ret;
  330. regcache_cache_only(tas5720->regmap, true);
  331. regcache_mark_dirty(tas5720->regmap);
  332. ret = regulator_bulk_disable(ARRAY_SIZE(tas5720->supplies),
  333. tas5720->supplies);
  334. if (ret < 0)
  335. dev_err(codec->dev, "failed to disable supplies: %d\n", ret);
  336. return ret;
  337. }
  338. static int tas5720_resume(struct snd_soc_codec *codec)
  339. {
  340. struct tas5720_data *tas5720 = snd_soc_codec_get_drvdata(codec);
  341. int ret;
  342. ret = regulator_bulk_enable(ARRAY_SIZE(tas5720->supplies),
  343. tas5720->supplies);
  344. if (ret < 0) {
  345. dev_err(codec->dev, "failed to enable supplies: %d\n", ret);
  346. return ret;
  347. }
  348. regcache_cache_only(tas5720->regmap, false);
  349. ret = regcache_sync(tas5720->regmap);
  350. if (ret < 0) {
  351. dev_err(codec->dev, "failed to sync regcache: %d\n", ret);
  352. return ret;
  353. }
  354. return 0;
  355. }
  356. #else
  357. #define tas5720_suspend NULL
  358. #define tas5720_resume NULL
  359. #endif
  360. static bool tas5720_is_volatile_reg(struct device *dev, unsigned int reg)
  361. {
  362. switch (reg) {
  363. case TAS5720_DEVICE_ID_REG:
  364. case TAS5720_FAULT_REG:
  365. return true;
  366. default:
  367. return false;
  368. }
  369. }
  370. static const struct regmap_config tas5720_regmap_config = {
  371. .reg_bits = 8,
  372. .val_bits = 8,
  373. .max_register = TAS5720_MAX_REG,
  374. .cache_type = REGCACHE_RBTREE,
  375. .volatile_reg = tas5720_is_volatile_reg,
  376. };
  377. /*
  378. * DAC analog gain. There are four discrete values to select from, ranging
  379. * from 19.2 dB to 26.3dB.
  380. */
  381. static const DECLARE_TLV_DB_RANGE(dac_analog_tlv,
  382. 0x0, 0x0, TLV_DB_SCALE_ITEM(1920, 0, 0),
  383. 0x1, 0x1, TLV_DB_SCALE_ITEM(2070, 0, 0),
  384. 0x2, 0x2, TLV_DB_SCALE_ITEM(2350, 0, 0),
  385. 0x3, 0x3, TLV_DB_SCALE_ITEM(2630, 0, 0),
  386. );
  387. /*
  388. * DAC digital volumes. From -103.5 to 24 dB in 0.5 dB steps. Note that
  389. * setting the gain below -100 dB (register value <0x7) is effectively a MUTE
  390. * as per device datasheet.
  391. */
  392. static DECLARE_TLV_DB_SCALE(dac_tlv, -10350, 50, 0);
  393. static const struct snd_kcontrol_new tas5720_snd_controls[] = {
  394. SOC_SINGLE_TLV("Speaker Driver Playback Volume",
  395. TAS5720_VOLUME_CTRL_REG, 0, 0xff, 0, dac_tlv),
  396. SOC_SINGLE_TLV("Speaker Driver Analog Gain", TAS5720_ANALOG_CTRL_REG,
  397. TAS5720_ANALOG_GAIN_SHIFT, 3, 0, dac_analog_tlv),
  398. };
  399. static const struct snd_soc_dapm_widget tas5720_dapm_widgets[] = {
  400. SND_SOC_DAPM_AIF_IN("DAC IN", "Playback", 0, SND_SOC_NOPM, 0, 0),
  401. SND_SOC_DAPM_DAC_E("DAC", NULL, SND_SOC_NOPM, 0, 0, tas5720_dac_event,
  402. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  403. SND_SOC_DAPM_OUTPUT("OUT")
  404. };
  405. static const struct snd_soc_dapm_route tas5720_audio_map[] = {
  406. { "DAC", NULL, "DAC IN" },
  407. { "OUT", NULL, "DAC" },
  408. };
  409. static struct snd_soc_codec_driver soc_codec_dev_tas5720 = {
  410. .probe = tas5720_codec_probe,
  411. .remove = tas5720_codec_remove,
  412. .suspend = tas5720_suspend,
  413. .resume = tas5720_resume,
  414. .component_driver = {
  415. .controls = tas5720_snd_controls,
  416. .num_controls = ARRAY_SIZE(tas5720_snd_controls),
  417. .dapm_widgets = tas5720_dapm_widgets,
  418. .num_dapm_widgets = ARRAY_SIZE(tas5720_dapm_widgets),
  419. .dapm_routes = tas5720_audio_map,
  420. .num_dapm_routes = ARRAY_SIZE(tas5720_audio_map),
  421. },
  422. };
  423. /* PCM rates supported by the TAS5720 driver */
  424. #define TAS5720_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
  425. SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
  426. /* Formats supported by TAS5720 driver */
  427. #define TAS5720_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S18_3LE |\
  428. SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE)
  429. static struct snd_soc_dai_ops tas5720_speaker_dai_ops = {
  430. .hw_params = tas5720_hw_params,
  431. .set_fmt = tas5720_set_dai_fmt,
  432. .set_tdm_slot = tas5720_set_dai_tdm_slot,
  433. .digital_mute = tas5720_mute,
  434. };
  435. /*
  436. * TAS5720 DAI structure
  437. *
  438. * Note that were are advertising .playback.channels_max = 2 despite this being
  439. * a mono amplifier. The reason for that is that some serial ports such as TI's
  440. * McASP module have a minimum number of channels (2) that they can output.
  441. * Advertising more channels than we have will allow us to interface with such
  442. * a serial port without really any negative side effects as the TAS5720 will
  443. * simply ignore any extra channel(s) asides from the one channel that is
  444. * configured to be played back.
  445. */
  446. static struct snd_soc_dai_driver tas5720_dai[] = {
  447. {
  448. .name = "tas5720-amplifier",
  449. .playback = {
  450. .stream_name = "Playback",
  451. .channels_min = 1,
  452. .channels_max = 2,
  453. .rates = TAS5720_RATES,
  454. .formats = TAS5720_FORMATS,
  455. },
  456. .ops = &tas5720_speaker_dai_ops,
  457. },
  458. };
  459. static int tas5720_probe(struct i2c_client *client,
  460. const struct i2c_device_id *id)
  461. {
  462. struct device *dev = &client->dev;
  463. struct tas5720_data *data;
  464. int ret;
  465. int i;
  466. data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
  467. if (!data)
  468. return -ENOMEM;
  469. data->tas5720_client = client;
  470. data->regmap = devm_regmap_init_i2c(client, &tas5720_regmap_config);
  471. if (IS_ERR(data->regmap)) {
  472. ret = PTR_ERR(data->regmap);
  473. dev_err(dev, "failed to allocate register map: %d\n", ret);
  474. return ret;
  475. }
  476. for (i = 0; i < ARRAY_SIZE(data->supplies); i++)
  477. data->supplies[i].supply = tas5720_supply_names[i];
  478. ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->supplies),
  479. data->supplies);
  480. if (ret != 0) {
  481. dev_err(dev, "failed to request supplies: %d\n", ret);
  482. return ret;
  483. }
  484. dev_set_drvdata(dev, data);
  485. ret = snd_soc_register_codec(&client->dev,
  486. &soc_codec_dev_tas5720,
  487. tas5720_dai, ARRAY_SIZE(tas5720_dai));
  488. if (ret < 0) {
  489. dev_err(dev, "failed to register codec: %d\n", ret);
  490. return ret;
  491. }
  492. return 0;
  493. }
  494. static int tas5720_remove(struct i2c_client *client)
  495. {
  496. struct device *dev = &client->dev;
  497. snd_soc_unregister_codec(dev);
  498. return 0;
  499. }
  500. static const struct i2c_device_id tas5720_id[] = {
  501. { "tas5720", 0 },
  502. { }
  503. };
  504. MODULE_DEVICE_TABLE(i2c, tas5720_id);
  505. #if IS_ENABLED(CONFIG_OF)
  506. static const struct of_device_id tas5720_of_match[] = {
  507. { .compatible = "ti,tas5720", },
  508. { },
  509. };
  510. MODULE_DEVICE_TABLE(of, tas5720_of_match);
  511. #endif
  512. static struct i2c_driver tas5720_i2c_driver = {
  513. .driver = {
  514. .name = "tas5720",
  515. .of_match_table = of_match_ptr(tas5720_of_match),
  516. },
  517. .probe = tas5720_probe,
  518. .remove = tas5720_remove,
  519. .id_table = tas5720_id,
  520. };
  521. module_i2c_driver(tas5720_i2c_driver);
  522. MODULE_AUTHOR("Andreas Dannenberg <dannenberg@ti.com>");
  523. MODULE_DESCRIPTION("TAS5720 Audio amplifier driver");
  524. MODULE_LICENSE("GPL");