rt1019.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. //
  3. // rt1019.c -- RT1019 ALSA SoC audio amplifier driver
  4. // Author: Jack Yu <[email protected]>
  5. //
  6. // Copyright(c) 2021 Realtek Semiconductor Corp.
  7. //
  8. //
  9. #include <linux/acpi.h>
  10. #include <linux/fs.h>
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/init.h>
  14. #include <linux/delay.h>
  15. #include <linux/pm.h>
  16. #include <linux/regmap.h>
  17. #include <linux/i2c.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/firmware.h>
  20. #include <linux/gpio.h>
  21. #include <sound/core.h>
  22. #include <sound/pcm.h>
  23. #include <sound/pcm_params.h>
  24. #include <sound/soc.h>
  25. #include <sound/soc-dapm.h>
  26. #include <sound/initval.h>
  27. #include <sound/tlv.h>
  28. #include "rl6231.h"
  29. #include "rt1019.h"
  30. static const struct reg_default rt1019_reg[] = {
  31. { 0x0000, 0x00 },
  32. { 0x0011, 0x04 },
  33. { 0x0013, 0x00 },
  34. { 0x0019, 0x30 },
  35. { 0x001b, 0x01 },
  36. { 0x005c, 0x00 },
  37. { 0x005e, 0x10 },
  38. { 0x005f, 0xec },
  39. { 0x0061, 0x10 },
  40. { 0x0062, 0x19 },
  41. { 0x0066, 0x08 },
  42. { 0x0100, 0x80 },
  43. { 0x0100, 0x51 },
  44. { 0x0102, 0x23 },
  45. { 0x0311, 0x00 },
  46. { 0x0312, 0x3e },
  47. { 0x0313, 0x86 },
  48. { 0x0400, 0x03 },
  49. { 0x0401, 0x02 },
  50. { 0x0402, 0x01 },
  51. { 0x0504, 0xff },
  52. { 0x0505, 0x24 },
  53. { 0x0b00, 0x50 },
  54. { 0x0b01, 0xc3 },
  55. };
  56. static bool rt1019_volatile_register(struct device *dev, unsigned int reg)
  57. {
  58. switch (reg) {
  59. case RT1019_PWR_STRP_2:
  60. case RT1019_VER_ID:
  61. case RT1019_VEND_ID_1:
  62. case RT1019_VEND_ID_2:
  63. case RT1019_DEV_ID_1:
  64. case RT1019_DEV_ID_2:
  65. return true;
  66. default:
  67. return false;
  68. }
  69. }
  70. static bool rt1019_readable_register(struct device *dev, unsigned int reg)
  71. {
  72. switch (reg) {
  73. case RT1019_RESET:
  74. case RT1019_IDS_CTRL:
  75. case RT1019_ASEL_CTRL:
  76. case RT1019_PWR_STRP_2:
  77. case RT1019_BEEP_TONE:
  78. case RT1019_VER_ID:
  79. case RT1019_VEND_ID_1:
  80. case RT1019_VEND_ID_2:
  81. case RT1019_DEV_ID_1:
  82. case RT1019_DEV_ID_2:
  83. case RT1019_SDB_CTRL:
  84. case RT1019_CLK_TREE_1:
  85. case RT1019_CLK_TREE_2:
  86. case RT1019_CLK_TREE_3:
  87. case RT1019_PLL_1:
  88. case RT1019_PLL_2:
  89. case RT1019_PLL_3:
  90. case RT1019_TDM_1:
  91. case RT1019_TDM_2:
  92. case RT1019_TDM_3:
  93. case RT1019_DMIX_MONO_1:
  94. case RT1019_DMIX_MONO_2:
  95. case RT1019_BEEP_1:
  96. case RT1019_BEEP_2:
  97. return true;
  98. default:
  99. return false;
  100. }
  101. }
  102. static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -9525, 75, 0);
  103. static const char * const rt1019_din_source_select[] = {
  104. "Left",
  105. "Right",
  106. "Left + Right average",
  107. };
  108. static SOC_ENUM_SINGLE_DECL(rt1019_mono_lr_sel, RT1019_IDS_CTRL, 0,
  109. rt1019_din_source_select);
  110. static const struct snd_kcontrol_new rt1019_snd_controls[] = {
  111. SOC_SINGLE_TLV("DAC Playback Volume", RT1019_DMIX_MONO_1, 0,
  112. 127, 0, dac_vol_tlv),
  113. SOC_ENUM("Mono LR Select", rt1019_mono_lr_sel),
  114. };
  115. static int r1019_dac_event(struct snd_soc_dapm_widget *w,
  116. struct snd_kcontrol *kcontrol, int event)
  117. {
  118. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  119. switch (event) {
  120. case SND_SOC_DAPM_PRE_PMU:
  121. snd_soc_component_write(component, RT1019_SDB_CTRL, 0xb);
  122. break;
  123. case SND_SOC_DAPM_POST_PMD:
  124. snd_soc_component_write(component, RT1019_SDB_CTRL, 0xa);
  125. break;
  126. default:
  127. break;
  128. }
  129. return 0;
  130. }
  131. static const struct snd_soc_dapm_widget rt1019_dapm_widgets[] = {
  132. SND_SOC_DAPM_AIF_IN("AIFRX", "AIF Playback", 0, SND_SOC_NOPM, 0, 0),
  133. SND_SOC_DAPM_DAC_E("DAC", NULL, SND_SOC_NOPM, 0, 0,
  134. r1019_dac_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  135. SND_SOC_DAPM_OUTPUT("SPO"),
  136. };
  137. static const struct snd_soc_dapm_route rt1019_dapm_routes[] = {
  138. { "DAC", NULL, "AIFRX" },
  139. { "SPO", NULL, "DAC" },
  140. };
  141. static int rt1019_hw_params(struct snd_pcm_substream *substream,
  142. struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
  143. {
  144. struct snd_soc_component *component = dai->component;
  145. struct rt1019_priv *rt1019 = snd_soc_component_get_drvdata(component);
  146. int pre_div, bclk_ms, frame_size;
  147. unsigned int val_len = 0, sys_div_da_filter = 0;
  148. unsigned int sys_dac_osr = 0, sys_fifo_clk = 0;
  149. unsigned int sys_clk_cal = 0, sys_asrc_in = 0;
  150. rt1019->lrck = params_rate(params);
  151. pre_div = rl6231_get_clk_info(rt1019->sysclk, rt1019->lrck);
  152. if (pre_div < 0) {
  153. dev_err(component->dev, "Unsupported clock setting\n");
  154. return -EINVAL;
  155. }
  156. frame_size = snd_soc_params_to_frame_size(params);
  157. if (frame_size < 0) {
  158. dev_err(component->dev, "Unsupported frame size: %d\n", frame_size);
  159. return -EINVAL;
  160. }
  161. bclk_ms = frame_size > 32;
  162. rt1019->bclk = rt1019->lrck * (32 << bclk_ms);
  163. dev_dbg(dai->dev, "bclk is %dHz and lrck is %dHz\n",
  164. rt1019->bclk, rt1019->lrck);
  165. dev_dbg(dai->dev, "bclk_ms is %d and pre_div is %d for iis %d\n",
  166. bclk_ms, pre_div, dai->id);
  167. switch (pre_div) {
  168. case 0:
  169. sys_div_da_filter = RT1019_SYS_DIV_DA_FIL_DIV1;
  170. sys_dac_osr = RT1019_SYS_DA_OSR_DIV1;
  171. sys_asrc_in = RT1019_ASRC_256FS_DIV1;
  172. sys_fifo_clk = RT1019_SEL_FIFO_DIV1;
  173. sys_clk_cal = RT1019_SEL_CLK_CAL_DIV1;
  174. break;
  175. case 1:
  176. sys_div_da_filter = RT1019_SYS_DIV_DA_FIL_DIV2;
  177. sys_dac_osr = RT1019_SYS_DA_OSR_DIV2;
  178. sys_asrc_in = RT1019_ASRC_256FS_DIV2;
  179. sys_fifo_clk = RT1019_SEL_FIFO_DIV2;
  180. sys_clk_cal = RT1019_SEL_CLK_CAL_DIV2;
  181. break;
  182. case 3:
  183. sys_div_da_filter = RT1019_SYS_DIV_DA_FIL_DIV4;
  184. sys_dac_osr = RT1019_SYS_DA_OSR_DIV4;
  185. sys_asrc_in = RT1019_ASRC_256FS_DIV4;
  186. sys_fifo_clk = RT1019_SEL_FIFO_DIV4;
  187. sys_clk_cal = RT1019_SEL_CLK_CAL_DIV4;
  188. break;
  189. default:
  190. return -EINVAL;
  191. }
  192. switch (params_width(params)) {
  193. case 16:
  194. break;
  195. case 20:
  196. val_len = RT1019_I2S_DL_20;
  197. break;
  198. case 24:
  199. val_len = RT1019_I2S_DL_24;
  200. break;
  201. case 32:
  202. val_len = RT1019_I2S_DL_32;
  203. break;
  204. case 8:
  205. val_len = RT1019_I2S_DL_8;
  206. break;
  207. default:
  208. return -EINVAL;
  209. }
  210. snd_soc_component_update_bits(component, RT1019_TDM_2, RT1019_I2S_DL_MASK,
  211. val_len);
  212. snd_soc_component_update_bits(component, RT1019_CLK_TREE_1,
  213. RT1019_SEL_FIFO_MASK, sys_fifo_clk);
  214. snd_soc_component_update_bits(component, RT1019_CLK_TREE_2,
  215. RT1019_SYS_DIV_DA_FIL_MASK | RT1019_SYS_DA_OSR_MASK |
  216. RT1019_ASRC_256FS_MASK, sys_div_da_filter | sys_dac_osr |
  217. sys_asrc_in);
  218. snd_soc_component_update_bits(component, RT1019_CLK_TREE_3,
  219. RT1019_SEL_CLK_CAL_MASK, sys_clk_cal);
  220. return 0;
  221. }
  222. static int rt1019_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  223. {
  224. struct snd_soc_component *component = dai->component;
  225. unsigned int reg_val = 0, reg_val2 = 0;
  226. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  227. case SND_SOC_DAIFMT_NB_NF:
  228. break;
  229. case SND_SOC_DAIFMT_IB_NF:
  230. reg_val2 |= RT1019_TDM_BCLK_INV;
  231. break;
  232. default:
  233. return -EINVAL;
  234. }
  235. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  236. case SND_SOC_DAIFMT_I2S:
  237. break;
  238. case SND_SOC_DAIFMT_LEFT_J:
  239. reg_val |= RT1019_I2S_DF_LEFT;
  240. break;
  241. case SND_SOC_DAIFMT_DSP_A:
  242. reg_val |= RT1019_I2S_DF_PCM_A_R;
  243. break;
  244. case SND_SOC_DAIFMT_DSP_B:
  245. reg_val |= RT1019_I2S_DF_PCM_B_R;
  246. break;
  247. default:
  248. return -EINVAL;
  249. }
  250. snd_soc_component_update_bits(component, RT1019_TDM_2,
  251. RT1019_I2S_DF_MASK, reg_val);
  252. snd_soc_component_update_bits(component, RT1019_TDM_1,
  253. RT1019_TDM_BCLK_MASK, reg_val2);
  254. return 0;
  255. }
  256. static int rt1019_set_dai_sysclk(struct snd_soc_dai *dai,
  257. int clk_id, unsigned int freq, int dir)
  258. {
  259. struct snd_soc_component *component = dai->component;
  260. struct rt1019_priv *rt1019 = snd_soc_component_get_drvdata(component);
  261. unsigned int reg_val = 0;
  262. if (freq == rt1019->sysclk && clk_id == rt1019->sysclk_src)
  263. return 0;
  264. switch (clk_id) {
  265. case RT1019_SCLK_S_BCLK:
  266. reg_val |= RT1019_CLK_SYS_PRE_SEL_BCLK;
  267. break;
  268. case RT1019_SCLK_S_PLL:
  269. reg_val |= RT1019_CLK_SYS_PRE_SEL_PLL;
  270. break;
  271. default:
  272. dev_err(component->dev, "Invalid clock id (%d)\n", clk_id);
  273. return -EINVAL;
  274. }
  275. rt1019->sysclk = freq;
  276. rt1019->sysclk_src = clk_id;
  277. dev_dbg(dai->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id);
  278. snd_soc_component_update_bits(component, RT1019_CLK_TREE_1,
  279. RT1019_CLK_SYS_PRE_SEL_MASK, reg_val);
  280. return 0;
  281. }
  282. static int rt1019_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source,
  283. unsigned int freq_in, unsigned int freq_out)
  284. {
  285. struct snd_soc_component *component = dai->component;
  286. struct rt1019_priv *rt1019 = snd_soc_component_get_drvdata(component);
  287. struct rl6231_pll_code pll_code;
  288. int ret;
  289. if (!freq_in || !freq_out) {
  290. dev_dbg(component->dev, "PLL disabled\n");
  291. rt1019->pll_in = 0;
  292. rt1019->pll_out = 0;
  293. return 0;
  294. }
  295. if (source == rt1019->pll_src && freq_in == rt1019->pll_in &&
  296. freq_out == rt1019->pll_out)
  297. return 0;
  298. switch (source) {
  299. case RT1019_PLL_S_BCLK:
  300. snd_soc_component_update_bits(component, RT1019_CLK_TREE_1,
  301. RT1019_PLL_SRC_MASK, RT1019_PLL_SRC_SEL_BCLK);
  302. break;
  303. case RT1019_PLL_S_RC25M:
  304. snd_soc_component_update_bits(component, RT1019_CLK_TREE_1,
  305. RT1019_PLL_SRC_MASK, RT1019_PLL_SRC_SEL_RC);
  306. break;
  307. default:
  308. dev_err(component->dev, "Unknown PLL source %d\n", source);
  309. return -EINVAL;
  310. }
  311. ret = rl6231_pll_calc(freq_in, freq_out, &pll_code);
  312. if (ret < 0) {
  313. dev_err(component->dev, "Unsupported input clock %d\n", freq_in);
  314. return ret;
  315. }
  316. dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n",
  317. pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code),
  318. pll_code.n_code, pll_code.k_code);
  319. snd_soc_component_update_bits(component, RT1019_PWR_STRP_2,
  320. RT1019_AUTO_BITS_SEL_MASK | RT1019_AUTO_CLK_SEL_MASK,
  321. RT1019_AUTO_BITS_SEL_MANU | RT1019_AUTO_CLK_SEL_MANU);
  322. snd_soc_component_update_bits(component, RT1019_PLL_1,
  323. RT1019_PLL_M_MASK | RT1019_PLL_M_BP_MASK | RT1019_PLL_Q_8_8_MASK,
  324. ((pll_code.m_bp ? 0 : pll_code.m_code) << RT1019_PLL_M_SFT) |
  325. (pll_code.m_bp << RT1019_PLL_M_BP_SFT) |
  326. ((pll_code.n_code >> 8) & RT1019_PLL_Q_8_8_MASK));
  327. snd_soc_component_update_bits(component, RT1019_PLL_2,
  328. RT1019_PLL_Q_7_0_MASK, pll_code.n_code & RT1019_PLL_Q_7_0_MASK);
  329. snd_soc_component_update_bits(component, RT1019_PLL_3,
  330. RT1019_PLL_K_MASK, pll_code.k_code);
  331. rt1019->pll_in = freq_in;
  332. rt1019->pll_out = freq_out;
  333. rt1019->pll_src = source;
  334. return 0;
  335. }
  336. static int rt1019_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
  337. unsigned int rx_mask, int slots, int slot_width)
  338. {
  339. struct snd_soc_component *component = dai->component;
  340. unsigned int cn = 0, cl = 0, rx_slotnum;
  341. int ret = 0, first_bit;
  342. switch (slots) {
  343. case 4:
  344. cn = RT1019_I2S_TX_4CH;
  345. break;
  346. case 6:
  347. cn = RT1019_I2S_TX_6CH;
  348. break;
  349. case 8:
  350. cn = RT1019_I2S_TX_8CH;
  351. break;
  352. case 2:
  353. break;
  354. default:
  355. return -EINVAL;
  356. }
  357. switch (slot_width) {
  358. case 20:
  359. cl = RT1019_TDM_CL_20;
  360. break;
  361. case 24:
  362. cl = RT1019_TDM_CL_24;
  363. break;
  364. case 32:
  365. cl = RT1019_TDM_CL_32;
  366. break;
  367. case 8:
  368. cl = RT1019_TDM_CL_8;
  369. break;
  370. case 16:
  371. break;
  372. default:
  373. return -EINVAL;
  374. }
  375. /* Rx slot configuration */
  376. rx_slotnum = hweight_long(rx_mask);
  377. if (rx_slotnum != 1) {
  378. ret = -EINVAL;
  379. dev_err(component->dev, "too many rx slots or zero slot\n");
  380. goto _set_tdm_err_;
  381. }
  382. /* This is an assumption that the system sends stereo audio to the
  383. * amplifier typically. And the stereo audio is placed in slot 0/2/4/6
  384. * as the starting slot. The users could select the channel from
  385. * L/R/L+R by "Mono LR Select" control.
  386. */
  387. first_bit = __ffs(rx_mask);
  388. switch (first_bit) {
  389. case 0:
  390. case 2:
  391. case 4:
  392. case 6:
  393. snd_soc_component_update_bits(component,
  394. RT1019_TDM_3,
  395. RT1019_TDM_I2S_TX_L_DAC1_1_MASK |
  396. RT1019_TDM_I2S_TX_R_DAC1_1_MASK,
  397. (first_bit << RT1019_TDM_I2S_TX_L_DAC1_1_SFT) |
  398. ((first_bit + 1) << RT1019_TDM_I2S_TX_R_DAC1_1_SFT));
  399. break;
  400. case 1:
  401. case 3:
  402. case 5:
  403. case 7:
  404. snd_soc_component_update_bits(component,
  405. RT1019_TDM_3,
  406. RT1019_TDM_I2S_TX_L_DAC1_1_MASK |
  407. RT1019_TDM_I2S_TX_R_DAC1_1_MASK,
  408. ((first_bit - 1) << RT1019_TDM_I2S_TX_L_DAC1_1_SFT) |
  409. (first_bit << RT1019_TDM_I2S_TX_R_DAC1_1_SFT));
  410. break;
  411. default:
  412. ret = -EINVAL;
  413. goto _set_tdm_err_;
  414. }
  415. snd_soc_component_update_bits(component, RT1019_TDM_1,
  416. RT1019_TDM_CL_MASK, cl);
  417. snd_soc_component_update_bits(component, RT1019_TDM_2,
  418. RT1019_I2S_CH_TX_MASK, cn);
  419. _set_tdm_err_:
  420. return ret;
  421. }
  422. static int rt1019_probe(struct snd_soc_component *component)
  423. {
  424. struct rt1019_priv *rt1019 = snd_soc_component_get_drvdata(component);
  425. rt1019->component = component;
  426. snd_soc_component_write(component, RT1019_SDB_CTRL, 0xa);
  427. return 0;
  428. }
  429. #define RT1019_STEREO_RATES SNDRV_PCM_RATE_8000_192000
  430. #define RT1019_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  431. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
  432. static const struct snd_soc_dai_ops rt1019_aif_dai_ops = {
  433. .hw_params = rt1019_hw_params,
  434. .set_fmt = rt1019_set_dai_fmt,
  435. .set_sysclk = rt1019_set_dai_sysclk,
  436. .set_pll = rt1019_set_dai_pll,
  437. .set_tdm_slot = rt1019_set_tdm_slot,
  438. };
  439. static struct snd_soc_dai_driver rt1019_dai[] = {
  440. {
  441. .name = "rt1019-aif",
  442. .id = 0,
  443. .playback = {
  444. .stream_name = "AIF Playback",
  445. .channels_min = 1,
  446. .channels_max = 2,
  447. .rates = RT1019_STEREO_RATES,
  448. .formats = RT1019_FORMATS,
  449. },
  450. .ops = &rt1019_aif_dai_ops,
  451. }
  452. };
  453. static const struct snd_soc_component_driver soc_component_dev_rt1019 = {
  454. .probe = rt1019_probe,
  455. .controls = rt1019_snd_controls,
  456. .num_controls = ARRAY_SIZE(rt1019_snd_controls),
  457. .dapm_widgets = rt1019_dapm_widgets,
  458. .num_dapm_widgets = ARRAY_SIZE(rt1019_dapm_widgets),
  459. .dapm_routes = rt1019_dapm_routes,
  460. .num_dapm_routes = ARRAY_SIZE(rt1019_dapm_routes),
  461. .endianness = 1,
  462. };
  463. static const struct regmap_config rt1019_regmap = {
  464. .reg_bits = 16,
  465. .val_bits = 8,
  466. .use_single_read = true,
  467. .use_single_write = true,
  468. .max_register = RT1019_BEEP_2,
  469. .volatile_reg = rt1019_volatile_register,
  470. .readable_reg = rt1019_readable_register,
  471. .cache_type = REGCACHE_RBTREE,
  472. .reg_defaults = rt1019_reg,
  473. .num_reg_defaults = ARRAY_SIZE(rt1019_reg),
  474. };
  475. static const struct i2c_device_id rt1019_i2c_id[] = {
  476. { "rt1019", 0 },
  477. { }
  478. };
  479. MODULE_DEVICE_TABLE(i2c, rt1019_i2c_id);
  480. static const struct of_device_id rt1019_of_match[] = {
  481. { .compatible = "realtek,rt1019", },
  482. {},
  483. };
  484. MODULE_DEVICE_TABLE(of, rt1019_of_match);
  485. #ifdef CONFIG_ACPI
  486. static const struct acpi_device_id rt1019_acpi_match[] = {
  487. { "10EC1019", 0},
  488. { },
  489. };
  490. MODULE_DEVICE_TABLE(acpi, rt1019_acpi_match);
  491. #endif
  492. static int rt1019_i2c_probe(struct i2c_client *i2c)
  493. {
  494. struct rt1019_priv *rt1019;
  495. int ret;
  496. unsigned int val, val2, dev_id;
  497. rt1019 = devm_kzalloc(&i2c->dev, sizeof(struct rt1019_priv),
  498. GFP_KERNEL);
  499. if (!rt1019)
  500. return -ENOMEM;
  501. i2c_set_clientdata(i2c, rt1019);
  502. rt1019->regmap = devm_regmap_init_i2c(i2c, &rt1019_regmap);
  503. if (IS_ERR(rt1019->regmap)) {
  504. ret = PTR_ERR(rt1019->regmap);
  505. dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
  506. ret);
  507. return ret;
  508. }
  509. regmap_read(rt1019->regmap, RT1019_DEV_ID_1, &val);
  510. regmap_read(rt1019->regmap, RT1019_DEV_ID_2, &val2);
  511. dev_id = val << 8 | val2;
  512. if (dev_id != RT1019_DEVICE_ID_VAL && dev_id != RT1019_DEVICE_ID_VAL2) {
  513. dev_err(&i2c->dev,
  514. "Device with ID register 0x%x is not rt1019\n", dev_id);
  515. return -ENODEV;
  516. }
  517. return devm_snd_soc_register_component(&i2c->dev,
  518. &soc_component_dev_rt1019, rt1019_dai, ARRAY_SIZE(rt1019_dai));
  519. }
  520. static struct i2c_driver rt1019_i2c_driver = {
  521. .driver = {
  522. .name = "rt1019",
  523. .of_match_table = of_match_ptr(rt1019_of_match),
  524. .acpi_match_table = ACPI_PTR(rt1019_acpi_match),
  525. },
  526. .probe_new = rt1019_i2c_probe,
  527. .id_table = rt1019_i2c_id,
  528. };
  529. module_i2c_driver(rt1019_i2c_driver);
  530. MODULE_DESCRIPTION("ASoC RT1019 driver");
  531. MODULE_AUTHOR("Jack Yu <[email protected]>");
  532. MODULE_LICENSE("GPL v2");