msm-pcm-voice-v2.c 22 KB

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