msm_hdmi_codec_rx.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
  3. */
  4. #include <linux/platform_device.h>
  5. #include <linux/slab.h>
  6. #include <linux/module.h>
  7. #include <linux/of_device.h>
  8. #include <linux/err.h>
  9. #include <sound/core.h>
  10. #include <sound/pcm.h>
  11. #include <sound/soc.h>
  12. #include <linux/msm_ext_display.h>
  13. #define DRV_NAME "HDMI_codec"
  14. #define MSM_EXT_DISP_PCM_RATES SNDRV_PCM_RATE_48000
  15. #define AUD_EXT_DISP_ACK_DISCONNECT (AUDIO_ACK_CONNECT ^ AUDIO_ACK_CONNECT)
  16. #define AUD_EXT_DISP_ACK_CONNECT (AUDIO_ACK_CONNECT)
  17. #define AUD_EXT_DISP_ACK_ENABLE (AUDIO_ACK_SET_ENABLE | AUDIO_ACK_ENABLE)
  18. #define SOC_EXT_DISP_AUDIO_TYPE(index) \
  19. static SOC_ENUM_SINGLE_DECL(ext_disp_audio_type##index, SND_SOC_NOPM, \
  20. index, ext_disp_audio_type_text)
  21. #define SOC_EXT_DISP_AUDIO_ACK_STATE(index) \
  22. static SOC_ENUM_SINGLE_DECL(ext_disp_audio_ack_state##index, \
  23. SND_SOC_NOPM, index, ext_disp_audio_ack_text)
  24. #define SWITCH_DP_CODEC(codec_info, codec_data, dai_id) \
  25. codec_info.type = EXT_DISPLAY_TYPE_DP; \
  26. codec_info.ctrl_id = codec_data->ctl[dai_id]; \
  27. codec_info.stream_id = codec_data->stream[dai_id]; \
  28. msm_ext_disp_select_audio_codec(codec_data->ext_disp_core_pdev, \
  29. &codec_info)
  30. enum {
  31. DP_STREAM0 = 0,
  32. DP_STREAM1,
  33. DP_STREAM_MAX,
  34. };
  35. enum {
  36. DP_DAI1 = 0,
  37. DP_DAI2,
  38. HDMI_DAI,
  39. DP_DAI_MAX,
  40. };
  41. static const char *const ext_disp_audio_type_text[] = {"None", "HDMI", "DP"};
  42. static const char *const ext_disp_audio_ack_text[] = {"Disconnect", "Connect",
  43. "Ack_Enable"};
  44. SOC_EXT_DISP_AUDIO_TYPE(0);
  45. SOC_EXT_DISP_AUDIO_ACK_STATE(0);
  46. SOC_EXT_DISP_AUDIO_TYPE(1);
  47. SOC_EXT_DISP_AUDIO_ACK_STATE(1);
  48. struct msm_ext_disp_audio_codec_rx_data {
  49. struct platform_device *ext_disp_core_pdev;
  50. struct msm_ext_disp_audio_codec_ops ext_disp_ops;
  51. int cable_status;
  52. struct mutex dp_ops_lock;
  53. int stream[DP_DAI_MAX];
  54. int ctl[DP_DAI_MAX];
  55. };
  56. static int msm_ext_disp_edid_ctl_info(struct snd_kcontrol *kcontrol,
  57. struct snd_ctl_elem_info *uinfo)
  58. {
  59. struct snd_soc_component *component =
  60. snd_soc_kcontrol_component(kcontrol);
  61. struct msm_ext_disp_audio_codec_rx_data *codec_data;
  62. struct msm_ext_disp_audio_edid_blk edid_blk;
  63. int rc = 0;
  64. struct msm_ext_disp_codec_id codec_info;
  65. int dai_id = kcontrol->private_value;
  66. codec_data = snd_soc_component_get_drvdata(component);
  67. if (!codec_data) {
  68. dev_err(component->dev, "%s: codec_data is NULL\n", __func__);
  69. return -EINVAL;
  70. }
  71. if (!codec_data->ext_disp_ops.get_audio_edid_blk) {
  72. dev_dbg(component->dev, "%s: get_audio_edid_blk() is NULL\n",
  73. __func__);
  74. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  75. uinfo->count = 0;
  76. return 0;
  77. }
  78. dev_dbg(component->dev, "%s: DP ctl id %d Stream id %d\n", __func__,
  79. codec_data->ctl[dai_id], codec_data->stream[dai_id]);
  80. mutex_lock(&codec_data->dp_ops_lock);
  81. SWITCH_DP_CODEC(codec_info, codec_data, dai_id);
  82. rc = codec_data->ext_disp_ops.get_audio_edid_blk(
  83. codec_data->ext_disp_core_pdev, &edid_blk);
  84. mutex_unlock(&codec_data->dp_ops_lock);
  85. if (rc >= 0) {
  86. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  87. uinfo->count = edid_blk.audio_data_blk_size +
  88. edid_blk.spk_alloc_data_blk_size;
  89. }
  90. dev_dbg(component->dev, "%s: count: %d\n", __func__, uinfo->count);
  91. return rc;
  92. }
  93. static int msm_ext_disp_edid_get(struct snd_kcontrol *kcontrol,
  94. struct snd_ctl_elem_value *ucontrol) {
  95. struct snd_soc_component *component =
  96. snd_soc_kcontrol_component(kcontrol);
  97. struct msm_ext_disp_audio_codec_rx_data *codec_data;
  98. struct msm_ext_disp_audio_edid_blk edid_blk;
  99. struct msm_ext_disp_codec_id codec_info;
  100. int rc = 0;
  101. int dai_id = kcontrol->private_value;
  102. codec_data = snd_soc_component_get_drvdata(component);
  103. if (!codec_data || !codec_data->ext_disp_ops.get_audio_edid_blk) {
  104. dev_err(component->dev, "%s: codec_data or get_audio_edid_blk() is NULL\n",
  105. __func__);
  106. return -EINVAL;
  107. }
  108. dev_dbg(component->dev, "%s: DP ctl id %d Stream id %d\n", __func__,
  109. codec_data->ctl[dai_id], codec_data->stream[dai_id]);
  110. mutex_lock(&codec_data->dp_ops_lock);
  111. SWITCH_DP_CODEC(codec_info, codec_data, dai_id);
  112. rc = codec_data->ext_disp_ops.get_audio_edid_blk(
  113. codec_data->ext_disp_core_pdev, &edid_blk);
  114. mutex_unlock(&codec_data->dp_ops_lock);
  115. if (rc >= 0) {
  116. if (sizeof(ucontrol->value.bytes.data) <
  117. (edid_blk.audio_data_blk_size +
  118. edid_blk.spk_alloc_data_blk_size)) {
  119. dev_err(component->dev,
  120. "%s: Not enough memory to copy EDID data\n",
  121. __func__);
  122. return -ENOMEM;
  123. }
  124. memcpy(ucontrol->value.bytes.data,
  125. edid_blk.audio_data_blk,
  126. edid_blk.audio_data_blk_size);
  127. memcpy((ucontrol->value.bytes.data +
  128. edid_blk.audio_data_blk_size),
  129. edid_blk.spk_alloc_data_blk,
  130. edid_blk.spk_alloc_data_blk_size);
  131. dev_dbg(component->dev, "%s: data_blk_size:%d, spk_alloc_data_blk_size:%d\n",
  132. __func__, edid_blk.audio_data_blk_size,
  133. edid_blk.spk_alloc_data_blk_size);
  134. }
  135. return rc;
  136. }
  137. static int msm_ext_disp_audio_type_get(struct snd_kcontrol *kcontrol,
  138. struct snd_ctl_elem_value *ucontrol)
  139. {
  140. struct snd_soc_component *component =
  141. snd_soc_kcontrol_component(kcontrol);
  142. struct msm_ext_disp_audio_codec_rx_data *codec_data;
  143. enum msm_ext_disp_cable_state cable_state;
  144. enum msm_ext_disp_type disp_type;
  145. struct msm_ext_disp_codec_id codec_info;
  146. int rc = 0;
  147. int dai_id = ((struct soc_enum *) kcontrol->private_value)->shift_l;
  148. codec_data = snd_soc_component_get_drvdata(component);
  149. if (!codec_data ||
  150. !codec_data->ext_disp_ops.get_audio_edid_blk ||
  151. !codec_data->ext_disp_ops.get_intf_id) {
  152. dev_err(component->dev, "%s: codec_data, get_audio_edid_blk() or get_intf_id is NULL\n",
  153. __func__);
  154. return -EINVAL;
  155. }
  156. dev_dbg(component->dev, "%s: DP ctl id %d Stream id %d\n", __func__,
  157. codec_data->ctl[dai_id], codec_data->stream[dai_id]);
  158. mutex_lock(&codec_data->dp_ops_lock);
  159. SWITCH_DP_CODEC(codec_info, codec_data, dai_id);
  160. cable_state = codec_data->ext_disp_ops.cable_status(
  161. codec_data->ext_disp_core_pdev, 1);
  162. if (cable_state < 0) {
  163. dev_err(component->dev, "%s: Error retrieving cable state from ext_disp, err:%d\n",
  164. __func__, cable_state);
  165. rc = cable_state;
  166. goto cable_err;
  167. }
  168. codec_data->cable_status = cable_state;
  169. if (cable_state == EXT_DISPLAY_CABLE_DISCONNECT) {
  170. dev_err(component->dev, "%s: Display cable disconnected\n",
  171. __func__);
  172. ucontrol->value.integer.value[0] = 0;
  173. rc = 0;
  174. goto cable_err;
  175. }
  176. disp_type = codec_data->ext_disp_ops.get_intf_id(
  177. codec_data->ext_disp_core_pdev);
  178. mutex_unlock(&codec_data->dp_ops_lock);
  179. if (disp_type >= 0) {
  180. switch (disp_type) {
  181. case EXT_DISPLAY_TYPE_DP:
  182. ucontrol->value.integer.value[0] = 2;
  183. rc = 0;
  184. break;
  185. case EXT_DISPLAY_TYPE_HDMI:
  186. ucontrol->value.integer.value[0] = 1;
  187. rc = 0;
  188. break;
  189. default:
  190. rc = -EINVAL;
  191. dev_err(component->dev, "%s: Invalid disp_type:%d\n",
  192. __func__, disp_type);
  193. goto done;
  194. }
  195. dev_dbg(component->dev, "%s: Display type: %d\n",
  196. __func__, disp_type);
  197. } else {
  198. dev_err(component->dev, "%s: Error retrieving disp_type from ext_disp, err:%d\n",
  199. __func__, disp_type);
  200. rc = disp_type;
  201. }
  202. return rc;
  203. cable_err:
  204. mutex_unlock(&codec_data->dp_ops_lock);
  205. done:
  206. return rc;
  207. }
  208. static int msm_ext_disp_audio_ack_set(struct snd_kcontrol *kcontrol,
  209. struct snd_ctl_elem_value *ucontrol)
  210. {
  211. struct snd_soc_component *component =
  212. snd_soc_kcontrol_component(kcontrol);
  213. struct msm_ext_disp_audio_codec_rx_data *codec_data;
  214. u32 ack_state = 0;
  215. struct msm_ext_disp_codec_id codec_info;
  216. int rc = 0;
  217. int dai_id = ((struct soc_enum *) kcontrol->private_value)->shift_l;
  218. codec_data = snd_soc_component_get_drvdata(component);
  219. if (!codec_data ||
  220. !codec_data->ext_disp_ops.acknowledge) {
  221. dev_err(component->dev,
  222. "%s: codec_data or ops acknowledge() is NULL\n",
  223. __func__);
  224. rc = -EINVAL;
  225. goto done;
  226. }
  227. dev_dbg(component->dev, "%s: DP ctl id %d Stream id %d\n", __func__,
  228. codec_data->ctl[dai_id], codec_data->stream[dai_id]);
  229. switch (ucontrol->value.enumerated.item[0]) {
  230. case 0:
  231. ack_state = AUD_EXT_DISP_ACK_DISCONNECT;
  232. break;
  233. case 1:
  234. ack_state = AUD_EXT_DISP_ACK_CONNECT;
  235. break;
  236. case 2:
  237. ack_state = AUD_EXT_DISP_ACK_ENABLE;
  238. break;
  239. default:
  240. rc = -EINVAL;
  241. dev_err(component->dev,
  242. "%s: invalid value %d for mixer ctl\n",
  243. __func__, ucontrol->value.enumerated.item[0]);
  244. goto done;
  245. }
  246. dev_dbg(component->dev, "%s: control %d, ack set value 0x%x\n",
  247. __func__, ucontrol->value.enumerated.item[0], ack_state);
  248. mutex_lock(&codec_data->dp_ops_lock);
  249. SWITCH_DP_CODEC(codec_info, codec_data, dai_id);
  250. rc = codec_data->ext_disp_ops.acknowledge(
  251. codec_data->ext_disp_core_pdev, ack_state);
  252. mutex_unlock(&codec_data->dp_ops_lock);
  253. if (rc < 0) {
  254. dev_err(component->dev, "%s: error from acknowledge(), err:%d\n",
  255. __func__, rc);
  256. }
  257. done:
  258. return rc;
  259. }
  260. static int msm_ext_disp_audio_device_set(struct snd_kcontrol *kcontrol,
  261. struct snd_ctl_elem_value *ucontrol)
  262. {
  263. struct snd_soc_component *component =
  264. snd_soc_kcontrol_component(kcontrol);
  265. struct msm_ext_disp_audio_codec_rx_data *codec_data;
  266. int rc = 0;
  267. int dai_id = ((struct soc_enum *) kcontrol->private_value)->shift_l;
  268. codec_data = snd_soc_component_get_drvdata(component);
  269. if (!codec_data) {
  270. dev_err(component->dev,
  271. "%s: codec_data or ops acknowledge() is NULL\n",
  272. __func__);
  273. rc = -EINVAL;
  274. goto done;
  275. }
  276. mutex_lock(&codec_data->dp_ops_lock);
  277. codec_data->ctl[dai_id] = ucontrol->value.enumerated.item[0];
  278. codec_data->stream[dai_id] = ucontrol->value.enumerated.item[1];
  279. mutex_unlock(&codec_data->dp_ops_lock);
  280. done:
  281. return rc;
  282. }
  283. static const struct snd_kcontrol_new msm_ext_disp_codec_rx_controls[] = {
  284. {
  285. .access = SNDRV_CTL_ELEM_ACCESS_READ |
  286. SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  287. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  288. .name = "HDMI EDID",
  289. .info = msm_ext_disp_edid_ctl_info,
  290. .get = msm_ext_disp_edid_get,
  291. .private_value = HDMI_DAI,
  292. },
  293. {
  294. .access = SNDRV_CTL_ELEM_ACCESS_READ |
  295. SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  296. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  297. .name = "Display Port EDID",
  298. .info = msm_ext_disp_edid_ctl_info,
  299. .get = msm_ext_disp_edid_get,
  300. .private_value = DP_DAI1,
  301. },
  302. {
  303. .access = SNDRV_CTL_ELEM_ACCESS_READ |
  304. SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  305. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  306. .name = "Display Port1 EDID",
  307. .info = msm_ext_disp_edid_ctl_info,
  308. .get = msm_ext_disp_edid_get,
  309. .private_value = DP_DAI2,
  310. },
  311. SOC_ENUM_EXT("External Display Type",
  312. ext_disp_audio_type0,
  313. msm_ext_disp_audio_type_get, NULL),
  314. SOC_ENUM_EXT("External Display1 Type",
  315. ext_disp_audio_type1,
  316. msm_ext_disp_audio_type_get, NULL),
  317. SOC_ENUM_EXT("External Display Audio Ack",
  318. ext_disp_audio_ack_state0,
  319. NULL, msm_ext_disp_audio_ack_set),
  320. SOC_ENUM_EXT("External Display1 Audio Ack",
  321. ext_disp_audio_ack_state1,
  322. NULL, msm_ext_disp_audio_ack_set),
  323. SOC_SINGLE_EXT("External Display Audio Device",
  324. SND_SOC_NOPM, DP_DAI1, DP_STREAM_MAX, 0,
  325. NULL, msm_ext_disp_audio_device_set),
  326. SOC_SINGLE_EXT("External Display1 Audio Device",
  327. SND_SOC_NOPM, DP_DAI2, DP_STREAM_MAX, 0,
  328. NULL, msm_ext_disp_audio_device_set),
  329. };
  330. static int msm_ext_disp_audio_codec_rx_dai_startup(
  331. struct snd_pcm_substream *substream,
  332. struct snd_soc_dai *dai)
  333. {
  334. int ret = 0;
  335. struct msm_ext_disp_codec_id codec_info;
  336. struct msm_ext_disp_audio_codec_rx_data *codec_data =
  337. dev_get_drvdata(dai->component->dev);
  338. if (!codec_data || !codec_data->ext_disp_ops.cable_status) {
  339. dev_err(dai->dev, "%s() codec_data or cable_status is null\n",
  340. __func__);
  341. return -EINVAL;
  342. }
  343. dev_dbg(dai->component->dev, "%s: DP ctl id %d Stream id %d\n",
  344. __func__,
  345. codec_data->ctl[dai->id], codec_data->stream[dai->id]);
  346. mutex_lock(&codec_data->dp_ops_lock);
  347. SWITCH_DP_CODEC(codec_info, codec_data, dai->id);
  348. codec_data->cable_status =
  349. codec_data->ext_disp_ops.cable_status(
  350. codec_data->ext_disp_core_pdev, 1);
  351. mutex_unlock(&codec_data->dp_ops_lock);
  352. if (codec_data->cable_status < 0) {
  353. dev_err(dai->dev,
  354. "%s() ext disp core is not ready (ret val = %d)\n",
  355. __func__, codec_data->cable_status);
  356. ret = codec_data->cable_status;
  357. } else if (!codec_data->cable_status) {
  358. dev_err(dai->dev,
  359. "%s() ext disp cable is not connected (ret val = %d)\n",
  360. __func__, codec_data->cable_status);
  361. ret = -ENODEV;
  362. }
  363. return ret;
  364. }
  365. static int msm_ext_disp_audio_codec_rx_dai_hw_params(
  366. struct snd_pcm_substream *substream,
  367. struct snd_pcm_hw_params *params,
  368. struct snd_soc_dai *dai)
  369. {
  370. u32 channel_allocation = 0;
  371. u32 level_shift = 0; /* 0dB */
  372. bool down_mix = 0;
  373. u32 num_channels = params_channels(params);
  374. struct msm_ext_disp_codec_id codec_info;
  375. int rc = 0;
  376. struct msm_ext_disp_audio_setup_params audio_setup_params = {0};
  377. struct msm_ext_disp_audio_codec_rx_data *codec_data =
  378. dev_get_drvdata(dai->component->dev);
  379. if (!codec_data || !codec_data->ext_disp_ops.audio_info_setup) {
  380. dev_err(dai->dev, "%s: codec_data or audio_info_setup is null\n",
  381. __func__);
  382. return -EINVAL;
  383. }
  384. dev_dbg(dai->component->dev, "%s: DP ctl id %d Stream id %d\n",
  385. __func__,
  386. codec_data->ctl[dai->id], codec_data->stream[dai->id]);
  387. if (codec_data->cable_status < 0) {
  388. dev_err_ratelimited(dai->dev,
  389. "%s() ext disp core is not ready (ret val = %d)\n",
  390. __func__, codec_data->cable_status);
  391. return codec_data->cable_status;
  392. } else if (!codec_data->cable_status) {
  393. dev_err_ratelimited(dai->dev,
  394. "%s() ext disp cable is not connected (ret val = %d)\n",
  395. __func__, codec_data->cable_status);
  396. return -ENODEV;
  397. }
  398. /*refer to HDMI spec CEA-861-E: Table 28 Audio InfoFrame Data Byte 4*/
  399. switch (num_channels) {
  400. case 2:
  401. channel_allocation = 0;
  402. break;
  403. case 3:
  404. channel_allocation = 0x02;/*default to FL/FR/FC*/
  405. audio_setup_params.sample_present = 0x3;
  406. break;
  407. case 4:
  408. channel_allocation = 0x06;/*default to FL/FR/FC/RC*/
  409. audio_setup_params.sample_present = 0x7;
  410. break;
  411. case 5:
  412. channel_allocation = 0x0A;/*default to FL/FR/FC/RR/RL*/
  413. audio_setup_params.sample_present = 0x7;
  414. break;
  415. case 6:
  416. channel_allocation = 0x0B;
  417. audio_setup_params.sample_present = 0x7;
  418. break;
  419. case 7:
  420. channel_allocation = 0x12;/*default to FL/FR/FC/RL/RR/RRC/RLC*/
  421. audio_setup_params.sample_present = 0xf;
  422. break;
  423. case 8:
  424. channel_allocation = 0x13;
  425. audio_setup_params.sample_present = 0xf;
  426. break;
  427. default:
  428. dev_err(dai->dev, "invalid Channels = %u\n", num_channels);
  429. return -EINVAL;
  430. }
  431. dev_dbg(dai->dev,
  432. "%s() num_ch %u samplerate %u channel_allocation = %u\n",
  433. __func__, num_channels, params_rate(params),
  434. channel_allocation);
  435. audio_setup_params.sample_rate_hz = params_rate(params);
  436. audio_setup_params.num_of_channels = num_channels;
  437. audio_setup_params.channel_allocation = channel_allocation;
  438. audio_setup_params.level_shift = level_shift;
  439. audio_setup_params.down_mix = down_mix;
  440. mutex_lock(&codec_data->dp_ops_lock);
  441. SWITCH_DP_CODEC(codec_info, codec_data, dai->id);
  442. rc = codec_data->ext_disp_ops.audio_info_setup(
  443. codec_data->ext_disp_core_pdev, &audio_setup_params);
  444. mutex_unlock(&codec_data->dp_ops_lock);
  445. if (rc < 0) {
  446. dev_err_ratelimited(dai->dev,
  447. "%s() ext disp core is not ready, rc: %d\n",
  448. __func__, rc);
  449. }
  450. return rc;
  451. }
  452. static void msm_ext_disp_audio_codec_rx_dai_shutdown(
  453. struct snd_pcm_substream *substream,
  454. struct snd_soc_dai *dai)
  455. {
  456. int rc = 0;
  457. struct msm_ext_disp_codec_id codec_info;
  458. struct msm_ext_disp_audio_codec_rx_data *codec_data =
  459. dev_get_drvdata(dai->component->dev);
  460. if (!codec_data || !codec_data->ext_disp_ops.teardown_done ||
  461. !codec_data->ext_disp_ops.cable_status) {
  462. dev_err(dai->dev, "%s: codec data or teardown_done or cable_status is null\n",
  463. __func__);
  464. return;
  465. }
  466. dev_dbg(dai->component->dev, "%s: DP ctl id %d Stream id %d\n",
  467. __func__,
  468. codec_data->ctl[dai->id], codec_data->stream[dai->id]);
  469. mutex_lock(&codec_data->dp_ops_lock);
  470. SWITCH_DP_CODEC(codec_info, codec_data, dai->id);
  471. rc = codec_data->ext_disp_ops.cable_status(
  472. codec_data->ext_disp_core_pdev, 0);
  473. if (rc < 0) {
  474. dev_err(dai->dev,
  475. "%s: ext disp core had problems releasing audio flag\n",
  476. __func__);
  477. }
  478. codec_data->ext_disp_ops.teardown_done(
  479. codec_data->ext_disp_core_pdev);
  480. mutex_unlock(&codec_data->dp_ops_lock);
  481. }
  482. static int msm_ext_disp_audio_codec_rx_probe(
  483. struct snd_soc_component *component)
  484. {
  485. struct msm_ext_disp_audio_codec_rx_data *codec_data;
  486. struct device_node *of_node_parent = NULL;
  487. codec_data = kzalloc(sizeof(struct msm_ext_disp_audio_codec_rx_data),
  488. GFP_KERNEL);
  489. if (!codec_data) {
  490. dev_err(component->dev, "%s(): fail to allocate dai data\n",
  491. __func__);
  492. return -ENOMEM;
  493. }
  494. of_node_parent = of_get_parent(component->dev->of_node);
  495. if (!of_node_parent) {
  496. dev_err(component->dev, "%s(): Parent device tree node not found\n",
  497. __func__);
  498. kfree(codec_data);
  499. return -ENODEV;
  500. }
  501. codec_data->ext_disp_core_pdev = of_find_device_by_node(of_node_parent);
  502. if (!codec_data->ext_disp_core_pdev) {
  503. dev_err(component->dev, "%s(): can't get parent pdev\n",
  504. __func__);
  505. kfree(codec_data);
  506. return -ENODEV;
  507. }
  508. if (msm_ext_disp_register_audio_codec(codec_data->ext_disp_core_pdev,
  509. &codec_data->ext_disp_ops)) {
  510. dev_err(component->dev, "%s(): can't register with ext disp core",
  511. __func__);
  512. kfree(codec_data);
  513. return -ENODEV;
  514. }
  515. mutex_init(&codec_data->dp_ops_lock);
  516. dev_set_drvdata(component->dev, codec_data);
  517. dev_dbg(component->dev, "%s(): registered %s with ext disp core\n",
  518. __func__, component->name);
  519. return 0;
  520. }
  521. static void msm_ext_disp_audio_codec_rx_remove(
  522. struct snd_soc_component *component)
  523. {
  524. struct msm_ext_disp_audio_codec_rx_data *codec_data;
  525. codec_data = dev_get_drvdata(component->dev);
  526. mutex_destroy(&codec_data->dp_ops_lock);
  527. kfree(codec_data);
  528. return;
  529. }
  530. static struct snd_soc_dai_ops msm_ext_disp_audio_codec_rx_dai_ops = {
  531. .startup = msm_ext_disp_audio_codec_rx_dai_startup,
  532. .hw_params = msm_ext_disp_audio_codec_rx_dai_hw_params,
  533. .shutdown = msm_ext_disp_audio_codec_rx_dai_shutdown
  534. };
  535. static struct snd_soc_dai_driver msm_ext_disp_audio_codec_rx_dais[] = {
  536. {
  537. .name = "msm_hdmi_audio_codec_rx_dai",
  538. .id = HDMI_DAI,
  539. .playback = {
  540. .stream_name = "HDMI Playback",
  541. .channels_min = 1,
  542. .channels_max = 8,
  543. .rate_min = 48000,
  544. .rate_max = 48000,
  545. .rates = MSM_EXT_DISP_PCM_RATES,
  546. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  547. },
  548. .ops = &msm_ext_disp_audio_codec_rx_dai_ops,
  549. },
  550. {
  551. .name = "msm_dp_audio_codec_rx_dai",
  552. .id = DP_DAI1,
  553. .playback = {
  554. .stream_name = "Display Port Playback",
  555. .channels_min = 1,
  556. .channels_max = 8,
  557. .rate_min = 48000,
  558. .rate_max = 192000,
  559. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |
  560. SNDRV_PCM_RATE_192000,
  561. .formats = SNDRV_PCM_FMTBIT_S16_LE |
  562. SNDRV_PCM_FMTBIT_S24_LE |
  563. SNDRV_PCM_FMTBIT_S24_3LE,
  564. },
  565. .ops = &msm_ext_disp_audio_codec_rx_dai_ops,
  566. },
  567. {
  568. .name = "msm_dp_audio_codec_rx1_dai",
  569. .id = DP_DAI2,
  570. .playback = {
  571. .stream_name = "Display Port1 Playback",
  572. .channels_min = 1,
  573. .channels_max = 8,
  574. .rate_min = 48000,
  575. .rate_max = 192000,
  576. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |
  577. SNDRV_PCM_RATE_192000,
  578. .formats = SNDRV_PCM_FMTBIT_S16_LE |
  579. SNDRV_PCM_FMTBIT_S24_LE |
  580. SNDRV_PCM_FMTBIT_S24_3LE,
  581. },
  582. .ops = &msm_ext_disp_audio_codec_rx_dai_ops,
  583. },
  584. };
  585. static const struct snd_soc_component_driver msm_ext_disp_codec_rx_driver = {
  586. .name = DRV_NAME,
  587. .probe = msm_ext_disp_audio_codec_rx_probe,
  588. .remove = msm_ext_disp_audio_codec_rx_remove,
  589. .controls = msm_ext_disp_codec_rx_controls,
  590. .num_controls = ARRAY_SIZE(msm_ext_disp_codec_rx_controls),
  591. };
  592. static int msm_ext_disp_audio_codec_rx_plat_probe(
  593. struct platform_device *pdev)
  594. {
  595. dev_dbg(&pdev->dev, "%s(): dev name %s\n", __func__,
  596. dev_name(&pdev->dev));
  597. return snd_soc_register_component(&pdev->dev,
  598. &msm_ext_disp_codec_rx_driver,
  599. msm_ext_disp_audio_codec_rx_dais,
  600. ARRAY_SIZE(msm_ext_disp_audio_codec_rx_dais));
  601. }
  602. static int msm_ext_disp_audio_codec_rx_plat_remove(
  603. struct platform_device *pdev)
  604. {
  605. snd_soc_unregister_component(&pdev->dev);
  606. return 0;
  607. }
  608. static const struct of_device_id msm_ext_disp_audio_codec_rx_dt_match[] = {
  609. { .compatible = "qcom,msm-ext-disp-audio-codec-rx", },
  610. {}
  611. };
  612. MODULE_DEVICE_TABLE(of, msm_ext_disp_audio_codec_rx_dt_match);
  613. static struct platform_driver msm_ext_disp_audio_codec_rx_driver = {
  614. .driver = {
  615. .name = "msm-ext-disp-audio-codec-rx",
  616. .owner = THIS_MODULE,
  617. .of_match_table = msm_ext_disp_audio_codec_rx_dt_match,
  618. },
  619. .probe = msm_ext_disp_audio_codec_rx_plat_probe,
  620. .remove = msm_ext_disp_audio_codec_rx_plat_remove,
  621. };
  622. static int __init msm_ext_disp_audio_codec_rx_init(void)
  623. {
  624. int rc = 0;
  625. rc = platform_driver_register(&msm_ext_disp_audio_codec_rx_driver);
  626. if (rc) {
  627. pr_err("%s: failed to register ext disp codec driver err:%d\n",
  628. __func__, rc);
  629. }
  630. return rc;
  631. }
  632. module_init(msm_ext_disp_audio_codec_rx_init);
  633. static void __exit msm_ext_disp_audio_codec_rx_exit(void)
  634. {
  635. platform_driver_unregister(&msm_ext_disp_audio_codec_rx_driver);
  636. }
  637. module_exit(msm_ext_disp_audio_codec_rx_exit);
  638. MODULE_DESCRIPTION("MSM External Display Audio CODEC Driver");
  639. MODULE_LICENSE("GPL v2");