msm-pcm-voice-v2.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
  3. */
  4. #include <linux/init.h>
  5. #include <linux/err.h>
  6. #include <linux/module.h>
  7. #include <linux/time.h>
  8. #include <linux/wait.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/slab.h>
  11. #include <linux/dma-mapping.h>
  12. #include <sound/core.h>
  13. #include <sound/soc.h>
  14. #include <sound/soc-dapm.h>
  15. #include <sound/pcm.h>
  16. #include <sound/initval.h>
  17. #include <sound/control.h>
  18. #include <asm/dma.h>
  19. #include <linux/of_device.h>
  20. #include <dsp/q6voice.h>
  21. #include "msm-pcm-voice-v2.h"
  22. #define DRV_NAME "msm-pcm-voice-v2"
  23. static struct msm_voice voice_info[VOICE_SESSION_INDEX_MAX];
  24. static struct snd_pcm_hardware msm_pcm_hardware = {
  25. .info = (SNDRV_PCM_INFO_INTERLEAVED |
  26. SNDRV_PCM_INFO_PAUSE |
  27. SNDRV_PCM_INFO_RESUME),
  28. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  29. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
  30. .rate_min = 8000,
  31. .rate_max = 16000,
  32. .channels_min = 1,
  33. .channels_max = 1,
  34. .buffer_bytes_max = 4096 * 2,
  35. .period_bytes_min = 2048,
  36. .period_bytes_max = 4096,
  37. .periods_min = 2,
  38. .periods_max = 4,
  39. .fifo_size = 0,
  40. };
  41. static bool is_volte(struct msm_voice *pvolte)
  42. {
  43. if (pvolte == &voice_info[VOLTE_SESSION_INDEX])
  44. return true;
  45. else
  46. return false;
  47. }
  48. static bool is_voice2(struct msm_voice *pvoice2)
  49. {
  50. if (pvoice2 == &voice_info[VOICE2_SESSION_INDEX])
  51. return true;
  52. else
  53. return false;
  54. }
  55. static bool is_qchat(struct msm_voice *pqchat)
  56. {
  57. if (pqchat == &voice_info[QCHAT_SESSION_INDEX])
  58. return true;
  59. else
  60. return false;
  61. }
  62. static bool is_vowlan(struct msm_voice *pvowlan)
  63. {
  64. if (pvowlan == &voice_info[VOWLAN_SESSION_INDEX])
  65. return true;
  66. else
  67. return false;
  68. }
  69. static bool is_voicemmode1(struct msm_voice *pvoicemmode1)
  70. {
  71. if (pvoicemmode1 == &voice_info[VOICEMMODE1_INDEX])
  72. return true;
  73. else
  74. return false;
  75. }
  76. static bool is_voicemmode2(struct msm_voice *pvoicemmode2)
  77. {
  78. if (pvoicemmode2 == &voice_info[VOICEMMODE2_INDEX])
  79. return true;
  80. else
  81. return false;
  82. }
  83. static uint32_t get_session_id(struct msm_voice *pvoc)
  84. {
  85. uint32_t session_id = 0;
  86. if (is_volte(pvoc))
  87. session_id = voc_get_session_id(VOLTE_SESSION_NAME);
  88. else if (is_voice2(pvoc))
  89. session_id = voc_get_session_id(VOICE2_SESSION_NAME);
  90. else if (is_qchat(pvoc))
  91. session_id = voc_get_session_id(QCHAT_SESSION_NAME);
  92. else if (is_vowlan(pvoc))
  93. session_id = voc_get_session_id(VOWLAN_SESSION_NAME);
  94. else if (is_voicemmode1(pvoc))
  95. session_id = voc_get_session_id(VOICEMMODE1_NAME);
  96. else if (is_voicemmode2(pvoc))
  97. session_id = voc_get_session_id(VOICEMMODE2_NAME);
  98. else
  99. session_id = voc_get_session_id(VOICE_SESSION_NAME);
  100. return session_id;
  101. }
  102. static int msm_pcm_playback_prepare(struct snd_pcm_substream *substream)
  103. {
  104. struct snd_pcm_runtime *runtime = substream->runtime;
  105. struct msm_voice *prtd = runtime->private_data;
  106. pr_debug("%s\n", __func__);
  107. if (!prtd->playback_start)
  108. prtd->playback_start = 1;
  109. return 0;
  110. }
  111. static int msm_pcm_capture_prepare(struct snd_pcm_substream *substream)
  112. {
  113. struct snd_pcm_runtime *runtime = substream->runtime;
  114. struct msm_voice *prtd = runtime->private_data;
  115. pr_debug("%s\n", __func__);
  116. if (!prtd->capture_start)
  117. prtd->capture_start = 1;
  118. return 0;
  119. }
  120. static int msm_pcm_open(struct snd_pcm_substream *substream)
  121. {
  122. struct snd_pcm_runtime *runtime = substream->runtime;
  123. struct msm_voice *voice;
  124. if (!strncmp("VoLTE", substream->pcm->id, 5)) {
  125. voice = &voice_info[VOLTE_SESSION_INDEX];
  126. pr_debug("%s: Open VoLTE Substream Id=%s\n",
  127. __func__, substream->pcm->id);
  128. } else if (!strncmp("Voice2", substream->pcm->id, 6)) {
  129. voice = &voice_info[VOICE2_SESSION_INDEX];
  130. pr_debug("%s: Open Voice2 Substream Id=%s\n",
  131. __func__, substream->pcm->id);
  132. } else if (!strncmp("QCHAT", substream->pcm->id, 5)) {
  133. voice = &voice_info[QCHAT_SESSION_INDEX];
  134. pr_debug("%s: Open QCHAT Substream Id=%s\n",
  135. __func__, substream->pcm->id);
  136. } else if (!strncmp("VoWLAN", substream->pcm->id, 6)) {
  137. voice = &voice_info[VOWLAN_SESSION_INDEX];
  138. pr_debug("%s: Open VoWLAN Substream Id=%s\n",
  139. __func__, substream->pcm->id);
  140. } else if (!strncmp("VoiceMMode1", substream->pcm->id, 11)) {
  141. voice = &voice_info[VOICEMMODE1_INDEX];
  142. pr_debug("%s: Open VoiceMMode1 Substream Id=%s\n",
  143. __func__, substream->pcm->id);
  144. } else if (!strncmp("VoiceMMode2", substream->pcm->id, 11)) {
  145. voice = &voice_info[VOICEMMODE2_INDEX];
  146. pr_debug("%s: Open VoiceMMode2 Substream Id=%s\n",
  147. __func__, substream->pcm->id);
  148. } else {
  149. voice = &voice_info[VOICE_SESSION_INDEX];
  150. pr_debug("%s: Open VOICE Substream Id=%s\n",
  151. __func__, substream->pcm->id);
  152. }
  153. mutex_lock(&voice->lock);
  154. runtime->hw = msm_pcm_hardware;
  155. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  156. voice->playback_substream = substream;
  157. else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  158. voice->capture_substream = substream;
  159. voice->instance++;
  160. pr_debug("%s: Instance = %d, Stream ID = %s\n",
  161. __func__, voice->instance, substream->pcm->id);
  162. runtime->private_data = voice;
  163. mutex_unlock(&voice->lock);
  164. return 0;
  165. }
  166. static int msm_pcm_playback_close(struct snd_pcm_substream *substream)
  167. {
  168. struct snd_pcm_runtime *runtime = substream->runtime;
  169. struct msm_voice *prtd = runtime->private_data;
  170. pr_debug("%s\n", __func__);
  171. if (prtd->playback_start)
  172. prtd->playback_start = 0;
  173. prtd->playback_substream = NULL;
  174. return 0;
  175. }
  176. static int msm_pcm_capture_close(struct snd_pcm_substream *substream)
  177. {
  178. struct snd_pcm_runtime *runtime = substream->runtime;
  179. struct msm_voice *prtd = runtime->private_data;
  180. pr_debug("%s\n", __func__);
  181. if (prtd->capture_start)
  182. prtd->capture_start = 0;
  183. prtd->capture_substream = NULL;
  184. return 0;
  185. }
  186. static int msm_pcm_close(struct snd_pcm_substream *substream)
  187. {
  188. struct snd_pcm_runtime *runtime = substream->runtime;
  189. struct msm_voice *prtd = runtime->private_data;
  190. uint32_t session_id = 0;
  191. int ret = 0;
  192. mutex_lock(&prtd->lock);
  193. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  194. ret = msm_pcm_playback_close(substream);
  195. else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  196. ret = msm_pcm_capture_close(substream);
  197. prtd->instance--;
  198. if (!prtd->playback_start && !prtd->capture_start) {
  199. pr_debug("end voice call\n");
  200. session_id = get_session_id(prtd);
  201. if (session_id)
  202. voc_end_voice_call(session_id);
  203. }
  204. mutex_unlock(&prtd->lock);
  205. return ret;
  206. }
  207. static int msm_pcm_prepare(struct snd_pcm_substream *substream)
  208. {
  209. int ret = 0;
  210. struct snd_pcm_runtime *runtime = substream->runtime;
  211. struct msm_voice *prtd = runtime->private_data;
  212. uint32_t session_id = 0;
  213. mutex_lock(&prtd->lock);
  214. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  215. ret = msm_pcm_playback_prepare(substream);
  216. else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  217. ret = msm_pcm_capture_prepare(substream);
  218. if (prtd->playback_start && prtd->capture_start) {
  219. session_id = get_session_id(prtd);
  220. if (session_id)
  221. voc_start_voice_call(session_id);
  222. }
  223. mutex_unlock(&prtd->lock);
  224. return ret;
  225. }
  226. static int msm_pcm_hw_params(struct snd_pcm_substream *substream,
  227. struct snd_pcm_hw_params *params)
  228. {
  229. pr_debug("%s: Voice\n", __func__);
  230. snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
  231. return 0;
  232. }
  233. static int msm_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  234. {
  235. int ret = 0;
  236. struct snd_pcm_runtime *runtime = substream->runtime;
  237. struct msm_voice *prtd = runtime->private_data;
  238. uint32_t session_id = 0;
  239. pr_debug("%s: cmd = %d\n", __func__, cmd);
  240. session_id = get_session_id(prtd);
  241. switch (cmd) {
  242. case SNDRV_PCM_TRIGGER_START:
  243. case SNDRV_PCM_TRIGGER_STOP:
  244. pr_debug("Start & Stop Voice call not handled in Trigger.\n");
  245. break;
  246. case SNDRV_PCM_TRIGGER_RESUME:
  247. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  248. pr_debug("%s: resume call session_id = %d\n", __func__,
  249. session_id);
  250. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  251. ret = msm_pcm_playback_prepare(substream);
  252. else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  253. ret = msm_pcm_capture_prepare(substream);
  254. if (prtd->playback_start && prtd->capture_start) {
  255. if (session_id)
  256. voc_resume_voice_call(session_id);
  257. }
  258. break;
  259. case SNDRV_PCM_TRIGGER_SUSPEND:
  260. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  261. pr_debug("%s: pause call session_id=%d\n",
  262. __func__, session_id);
  263. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  264. if (prtd->playback_start)
  265. prtd->playback_start = 0;
  266. } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
  267. if (prtd->capture_start)
  268. prtd->capture_start = 0;
  269. }
  270. if (session_id)
  271. voc_standby_voice_call(session_id);
  272. break;
  273. default:
  274. ret = -EINVAL;
  275. break;
  276. }
  277. return ret;
  278. }
  279. static int msm_pcm_ioctl(struct snd_pcm_substream *substream,
  280. unsigned int cmd, void *arg)
  281. {
  282. struct snd_pcm_runtime *runtime = substream->runtime;
  283. struct msm_voice *prtd = runtime->private_data;
  284. uint32_t session_id = get_session_id(prtd);
  285. enum voice_lch_mode lch_mode;
  286. int ret = 0;
  287. switch (cmd) {
  288. case SNDRV_VOICE_IOCTL_LCH:
  289. if (copy_from_user(&lch_mode, (void *)arg,
  290. sizeof(enum voice_lch_mode))) {
  291. pr_err("%s: Copy from user failed, size %zd\n",
  292. __func__, sizeof(enum voice_lch_mode));
  293. ret = -EFAULT;
  294. break;
  295. }
  296. pr_debug("%s: %s lch_mode:%d\n",
  297. __func__, substream->pcm->id, lch_mode);
  298. switch (lch_mode) {
  299. case VOICE_LCH_START:
  300. case VOICE_LCH_STOP:
  301. ret = voc_set_lch(session_id, lch_mode);
  302. break;
  303. default:
  304. pr_err("%s: Invalid LCH MODE %d\n", __func__, lch_mode);
  305. ret = -EFAULT;
  306. }
  307. break;
  308. default:
  309. pr_debug("%s: Falling into default snd_lib_ioctl cmd 0x%x\n",
  310. __func__, cmd);
  311. ret = snd_pcm_lib_ioctl(substream, cmd, arg);
  312. break;
  313. }
  314. if (!ret)
  315. pr_debug("%s: ret %d\n", __func__, ret);
  316. else
  317. pr_err("%s: cmd 0x%x failed %d\n", __func__, cmd, ret);
  318. return ret;
  319. }
  320. static int msm_voice_sidetone_put(struct snd_kcontrol *kcontrol,
  321. struct snd_ctl_elem_value *ucontrol)
  322. {
  323. int ret;
  324. long value = ucontrol->value.integer.value[0];
  325. bool sidetone_enable = value;
  326. uint32_t session_id = ALL_SESSION_VSID;
  327. if (value < 0) {
  328. pr_err("%s: Invalid arguments sidetone enable %ld\n",
  329. __func__, value);
  330. ret = -EINVAL;
  331. return ret;
  332. }
  333. ret = voc_set_afe_sidetone(session_id, sidetone_enable);
  334. pr_debug("%s: AFE Sidetone enable=%d session_id=0x%x ret=%d\n",
  335. __func__, sidetone_enable, session_id, ret);
  336. return ret;
  337. }
  338. static int msm_voice_sidetone_get(struct snd_kcontrol *kcontrol,
  339. struct snd_ctl_elem_value *ucontrol)
  340. {
  341. ucontrol->value.integer.value[0] = voc_get_afe_sidetone();
  342. return 0;
  343. }
  344. static int msm_voice_gain_put(struct snd_kcontrol *kcontrol,
  345. struct snd_ctl_elem_value *ucontrol)
  346. {
  347. int ret = 0;
  348. int volume = ucontrol->value.integer.value[0];
  349. uint32_t session_id = ucontrol->value.integer.value[1];
  350. int ramp_duration = ucontrol->value.integer.value[2];
  351. if ((volume < 0) || (ramp_duration < 0)
  352. || (ramp_duration > MAX_RAMP_DURATION)) {
  353. pr_err(" %s Invalid arguments", __func__);
  354. ret = -EINVAL;
  355. goto done;
  356. }
  357. pr_debug("%s: volume: %d session_id: %#x ramp_duration: %d\n", __func__,
  358. volume, session_id, ramp_duration);
  359. voc_set_rx_vol_step(session_id, RX_PATH, volume, ramp_duration);
  360. done:
  361. return ret;
  362. }
  363. static int msm_voice_mute_put(struct snd_kcontrol *kcontrol,
  364. struct snd_ctl_elem_value *ucontrol)
  365. {
  366. int ret = 0;
  367. int mute = ucontrol->value.integer.value[0];
  368. uint32_t session_id = ucontrol->value.integer.value[1];
  369. int ramp_duration = ucontrol->value.integer.value[2];
  370. if ((mute < 0) || (mute > 1) || (ramp_duration < 0)
  371. || (ramp_duration > MAX_RAMP_DURATION)) {
  372. pr_err(" %s Invalid arguments", __func__);
  373. ret = -EINVAL;
  374. goto done;
  375. }
  376. pr_debug("%s: mute=%d session_id=%#x ramp_duration=%d\n", __func__,
  377. mute, session_id, ramp_duration);
  378. ret = voc_set_tx_mute(session_id, TX_PATH, mute, ramp_duration);
  379. done:
  380. return ret;
  381. }
  382. static int msm_voice_tx_device_mute_put(struct snd_kcontrol *kcontrol,
  383. struct snd_ctl_elem_value *ucontrol)
  384. {
  385. int ret = 0;
  386. int mute = ucontrol->value.integer.value[0];
  387. uint32_t session_id = ucontrol->value.integer.value[1];
  388. int ramp_duration = ucontrol->value.integer.value[2];
  389. if ((mute < 0) || (mute > 1) || (ramp_duration < 0) ||
  390. (ramp_duration > MAX_RAMP_DURATION)) {
  391. pr_err(" %s Invalid arguments", __func__);
  392. ret = -EINVAL;
  393. goto done;
  394. }
  395. pr_debug("%s: mute=%d session_id=%#x ramp_duration=%d\n", __func__,
  396. mute, session_id, ramp_duration);
  397. ret = voc_set_device_mute(session_id, VSS_IVOLUME_DIRECTION_TX,
  398. mute, ramp_duration);
  399. done:
  400. return ret;
  401. }
  402. static int msm_voice_rx_device_mute_put(struct snd_kcontrol *kcontrol,
  403. struct snd_ctl_elem_value *ucontrol)
  404. {
  405. int ret = 0;
  406. int mute = ucontrol->value.integer.value[0];
  407. uint32_t session_id = ucontrol->value.integer.value[1];
  408. int ramp_duration = ucontrol->value.integer.value[2];
  409. if ((mute < 0) || (mute > 1) || (ramp_duration < 0) ||
  410. (ramp_duration > MAX_RAMP_DURATION)) {
  411. pr_err(" %s Invalid arguments", __func__);
  412. ret = -EINVAL;
  413. goto done;
  414. }
  415. pr_debug("%s: mute=%d session_id=%#x ramp_duration=%d\n", __func__,
  416. mute, session_id, ramp_duration);
  417. voc_set_device_mute(session_id, VSS_IVOLUME_DIRECTION_RX,
  418. mute, ramp_duration);
  419. done:
  420. return ret;
  421. }
  422. static int msm_voice_mbd_get(struct snd_kcontrol *kcontrol,
  423. struct snd_ctl_elem_value *ucontrol)
  424. {
  425. ucontrol->value.integer.value[0] = voc_get_mbd_enable();
  426. return 0;
  427. }
  428. static int msm_voice_mbd_put(struct snd_kcontrol *kcontrol,
  429. struct snd_ctl_elem_value *ucontrol)
  430. {
  431. bool enable = ucontrol->value.integer.value[0];
  432. voc_set_mbd_enable(enable);
  433. return 0;
  434. }
  435. static const char * const tty_mode[] = {"OFF", "HCO", "VCO", "FULL"};
  436. static const struct soc_enum msm_tty_mode_enum[] = {
  437. SOC_ENUM_SINGLE_EXT(4, tty_mode),
  438. };
  439. static int msm_voice_tty_mode_get(struct snd_kcontrol *kcontrol,
  440. struct snd_ctl_elem_value *ucontrol)
  441. {
  442. ucontrol->value.integer.value[0] =
  443. voc_get_tty_mode(voc_get_session_id(VOICE_SESSION_NAME));
  444. return 0;
  445. }
  446. static int msm_voice_tty_mode_put(struct snd_kcontrol *kcontrol,
  447. struct snd_ctl_elem_value *ucontrol)
  448. {
  449. int tty_mode = ucontrol->value.integer.value[0];
  450. pr_debug("%s: tty_mode=%d\n", __func__, tty_mode);
  451. voc_set_tty_mode(voc_get_session_id(VOICE_SESSION_NAME), tty_mode);
  452. voc_set_tty_mode(voc_get_session_id(VOICE2_SESSION_NAME), tty_mode);
  453. voc_set_tty_mode(voc_get_session_id(VOLTE_SESSION_NAME), tty_mode);
  454. voc_set_tty_mode(voc_get_session_id(VOWLAN_SESSION_NAME), tty_mode);
  455. voc_set_tty_mode(voc_get_session_id(VOICEMMODE1_NAME), tty_mode);
  456. voc_set_tty_mode(voc_get_session_id(VOICEMMODE2_NAME), tty_mode);
  457. return 0;
  458. }
  459. static int msm_voice_slowtalk_put(struct snd_kcontrol *kcontrol,
  460. struct snd_ctl_elem_value *ucontrol)
  461. {
  462. int st_enable = ucontrol->value.integer.value[0];
  463. uint32_t session_id = ucontrol->value.integer.value[1];
  464. struct module_instance_info mod_inst_info;
  465. memset(&mod_inst_info, 0, sizeof(mod_inst_info));
  466. pr_debug("%s: st enable=%d session_id=%#x\n", __func__, st_enable,
  467. session_id);
  468. mod_inst_info.module_id = MODULE_ID_VOICE_MODULE_ST;
  469. mod_inst_info.instance_id = INSTANCE_ID_0;
  470. voc_set_pp_enable(session_id, mod_inst_info, st_enable);
  471. return 0;
  472. }
  473. static int msm_voice_hd_voice_put(struct snd_kcontrol *kcontrol,
  474. struct snd_ctl_elem_value *ucontrol)
  475. {
  476. int ret = 0;
  477. uint32_t hd_enable = ucontrol->value.integer.value[0];
  478. uint32_t session_id = ucontrol->value.integer.value[1];
  479. pr_debug("%s: HD Voice enable=%d session_id=%#x\n", __func__, hd_enable,
  480. session_id);
  481. ret = voc_set_hd_enable(session_id, hd_enable);
  482. return ret;
  483. }
  484. static int msm_voice_topology_disable_put(struct snd_kcontrol *kcontrol,
  485. struct snd_ctl_elem_value *ucontrol)
  486. {
  487. int ret = 0;
  488. int disable = ucontrol->value.integer.value[0];
  489. uint32_t session_id = ucontrol->value.integer.value[1];
  490. if ((disable < 0) || (disable > 1)) {
  491. pr_err(" %s Invalid arguments: %d\n", __func__, disable);
  492. ret = -EINVAL;
  493. goto done;
  494. }
  495. pr_debug("%s: disable = %d, session_id = %d\n", __func__, disable,
  496. session_id);
  497. ret = voc_disable_topology(session_id, disable);
  498. done:
  499. return ret;
  500. }
  501. static int msm_voice_cvd_version_info(struct snd_kcontrol *kcontrol,
  502. struct snd_ctl_elem_info *uinfo)
  503. {
  504. int ret = 0;
  505. pr_debug("%s:\n", __func__);
  506. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  507. uinfo->count = CVD_VERSION_STRING_MAX_SIZE;
  508. return ret;
  509. }
  510. static int msm_voice_cvd_version_get(struct snd_kcontrol *kcontrol,
  511. struct snd_ctl_elem_value *ucontrol)
  512. {
  513. char cvd_version[CVD_VERSION_STRING_MAX_SIZE] = CVD_VERSION_DEFAULT;
  514. int ret;
  515. pr_debug("%s:\n", __func__);
  516. ret = voc_get_cvd_version(cvd_version);
  517. if (ret)
  518. pr_err("%s: Error retrieving CVD version, error:%d\n",
  519. __func__, ret);
  520. memcpy(ucontrol->value.bytes.data, cvd_version, sizeof(cvd_version));
  521. return 0;
  522. }
  523. static struct snd_kcontrol_new msm_voice_controls[] = {
  524. SOC_SINGLE_MULTI_EXT("Voice Rx Device Mute", SND_SOC_NOPM, 0, VSID_MAX,
  525. 0, 3, NULL, msm_voice_rx_device_mute_put),
  526. SOC_SINGLE_MULTI_EXT("Voice Tx Device Mute", SND_SOC_NOPM, 0, VSID_MAX,
  527. 0, 3, NULL, msm_voice_tx_device_mute_put),
  528. SOC_SINGLE_MULTI_EXT("Voice Tx Mute", SND_SOC_NOPM, 0, VSID_MAX,
  529. 0, 3, NULL, msm_voice_mute_put),
  530. SOC_SINGLE_MULTI_EXT("Voice Rx Gain", SND_SOC_NOPM, 0, VSID_MAX, 0, 3,
  531. NULL, msm_voice_gain_put),
  532. SOC_ENUM_EXT("TTY Mode", msm_tty_mode_enum[0], msm_voice_tty_mode_get,
  533. msm_voice_tty_mode_put),
  534. SOC_SINGLE_MULTI_EXT("Slowtalk Enable", SND_SOC_NOPM, 0, VSID_MAX, 0, 2,
  535. NULL, msm_voice_slowtalk_put),
  536. SOC_SINGLE_MULTI_EXT("Voice Topology Disable", SND_SOC_NOPM, 0,
  537. VSID_MAX, 0, 2, NULL,
  538. msm_voice_topology_disable_put),
  539. SOC_SINGLE_MULTI_EXT("HD Voice Enable", SND_SOC_NOPM, 0, VSID_MAX, 0, 2,
  540. NULL, msm_voice_hd_voice_put),
  541. {
  542. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  543. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  544. .name = "CVD Version",
  545. .info = msm_voice_cvd_version_info,
  546. .get = msm_voice_cvd_version_get,
  547. },
  548. SOC_SINGLE_MULTI_EXT("Voice Sidetone Enable", SND_SOC_NOPM, 0, 1, 0, 1,
  549. msm_voice_sidetone_get, msm_voice_sidetone_put),
  550. SOC_SINGLE_BOOL_EXT("Voice Mic Break Enable", 0, msm_voice_mbd_get,
  551. msm_voice_mbd_put),
  552. };
  553. static const struct snd_pcm_ops msm_pcm_ops = {
  554. .open = msm_pcm_open,
  555. .hw_params = msm_pcm_hw_params,
  556. .close = msm_pcm_close,
  557. .prepare = msm_pcm_prepare,
  558. .trigger = msm_pcm_trigger,
  559. .ioctl = msm_pcm_ioctl,
  560. .compat_ioctl = msm_pcm_ioctl,
  561. };
  562. static int msm_asoc_pcm_new(struct snd_soc_pcm_runtime *rtd)
  563. {
  564. struct snd_card *card = rtd->card->snd_card;
  565. int ret = 0;
  566. if (!card->dev->coherent_dma_mask)
  567. card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
  568. return ret;
  569. }
  570. static int msm_pcm_voice_probe(struct snd_soc_component *component)
  571. {
  572. snd_soc_add_component_controls(component, msm_voice_controls,
  573. ARRAY_SIZE(msm_voice_controls));
  574. return 0;
  575. }
  576. static struct snd_soc_component_driver msm_soc_component = {
  577. .name = DRV_NAME,
  578. .ops = &msm_pcm_ops,
  579. .pcm_new = msm_asoc_pcm_new,
  580. .probe = msm_pcm_voice_probe,
  581. };
  582. static int msm_pcm_probe(struct platform_device *pdev)
  583. {
  584. int rc;
  585. bool destroy_cvd = false;
  586. const char *is_destroy_cvd = "qcom,destroy-cvd";
  587. if (!is_voc_initialized()) {
  588. pr_debug("%s: voice module not initialized yet, deferring probe()\n",
  589. __func__);
  590. rc = -EPROBE_DEFER;
  591. goto done;
  592. }
  593. rc = voc_alloc_cal_shared_memory();
  594. if (rc == -EPROBE_DEFER) {
  595. pr_debug("%s: memory allocation for calibration deferred %d\n",
  596. __func__, rc);
  597. goto done;
  598. } else if (rc < 0) {
  599. pr_err("%s: memory allocation for calibration failed %d\n",
  600. __func__, rc);
  601. }
  602. pr_debug("%s: dev name %s\n",
  603. __func__, dev_name(&pdev->dev));
  604. destroy_cvd = of_property_read_bool(pdev->dev.of_node,
  605. is_destroy_cvd);
  606. voc_set_destroy_cvd_flag(destroy_cvd);
  607. rc = snd_soc_register_component(&pdev->dev,
  608. &msm_soc_component,
  609. NULL, 0);
  610. done:
  611. return rc;
  612. }
  613. static int msm_pcm_remove(struct platform_device *pdev)
  614. {
  615. snd_soc_unregister_component(&pdev->dev);
  616. return 0;
  617. }
  618. static const struct of_device_id msm_voice_dt_match[] = {
  619. {.compatible = "qcom,msm-pcm-voice"},
  620. {}
  621. };
  622. MODULE_DEVICE_TABLE(of, msm_voice_dt_match);
  623. static struct platform_driver msm_pcm_driver = {
  624. .driver = {
  625. .name = "msm-pcm-voice",
  626. .owner = THIS_MODULE,
  627. .of_match_table = msm_voice_dt_match,
  628. },
  629. .probe = msm_pcm_probe,
  630. .remove = msm_pcm_remove,
  631. };
  632. int __init msm_pcm_voice_init(void)
  633. {
  634. int i = 0;
  635. memset(&voice_info, 0, sizeof(voice_info));
  636. for (i = 0; i < VOICE_SESSION_INDEX_MAX; i++)
  637. mutex_init(&voice_info[i].lock);
  638. return platform_driver_register(&msm_pcm_driver);
  639. }
  640. void msm_pcm_voice_exit(void)
  641. {
  642. platform_driver_unregister(&msm_pcm_driver);
  643. }
  644. MODULE_DESCRIPTION("Voice PCM module platform driver");
  645. MODULE_LICENSE("GPL v2");