msm8x60.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  1. /* Copyright (c) 2010-2011, 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/moduleparam.h>
  16. #include <linux/time.h>
  17. #include <linux/wait.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/dma-mapping.h>
  20. #include <linux/msm_audio.h>
  21. #include <sound/core.h>
  22. #include <sound/soc.h>
  23. #include <sound/soc-dapm.h>
  24. #include <sound/pcm.h>
  25. #include <sound/tlv.h>
  26. #include <sound/initval.h>
  27. #include <sound/control.h>
  28. #include <sound/q6afe.h>
  29. #include <asm/dma.h>
  30. #include <asm/mach-types.h>
  31. #include <mach/qdsp6v2/audio_dev_ctl.h>
  32. #include <mach/qdsp6v2/q6voice.h>
  33. #define LOOPBACK_ENABLE 0x1
  34. #define LOOPBACK_DISABLE 0x0
  35. #include "msm8x60-pcm.h"
  36. static struct platform_device *msm_audio_snd_device;
  37. struct audio_locks the_locks;
  38. EXPORT_SYMBOL(the_locks);
  39. struct msm_volume msm_vol_ctl;
  40. EXPORT_SYMBOL(msm_vol_ctl);
  41. struct pcm_session session_route;
  42. EXPORT_SYMBOL(session_route);
  43. static struct snd_kcontrol_new snd_msm_controls[];
  44. char snddev_name[AUDIO_DEV_CTL_MAX_DEV][44];
  45. #define MSM_MAX_VOLUME 0x2000
  46. #define MSM_VOLUME_STEP ((MSM_MAX_VOLUME+17)/100) /* 17 added to avoid
  47. more deviation */
  48. static int device_index; /* Count of Device controls */
  49. static int simple_control; /* Count of simple controls*/
  50. static int src_dev;
  51. static int dst_dev;
  52. static int loopback_status;
  53. static int msm_scontrol_count_info(struct snd_kcontrol *kcontrol,
  54. struct snd_ctl_elem_info *uinfo)
  55. {
  56. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  57. uinfo->count = 1;
  58. return 0;
  59. }
  60. static int msm_scontrol_count_get(struct snd_kcontrol *kcontrol,
  61. struct snd_ctl_elem_value *ucontrol)
  62. {
  63. ucontrol->value.integer.value[0] = simple_control;
  64. return 0;
  65. }
  66. static int msm_v_call_info(struct snd_kcontrol *kcontrol,
  67. struct snd_ctl_elem_info *uinfo)
  68. {
  69. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  70. uinfo->count = 2; /* start, session_id */
  71. uinfo->value.integer.min = 0;
  72. uinfo->value.integer.max = SESSION_ID_BASE + MAX_VOC_SESSIONS;
  73. return 0;
  74. }
  75. static int msm_v_call_get(struct snd_kcontrol *kcontrol,
  76. struct snd_ctl_elem_value *ucontrol)
  77. {
  78. ucontrol->value.integer.value[0] = 0;
  79. ucontrol->value.integer.value[1] = 0;
  80. return 0;
  81. }
  82. static int msm_v_call_put(struct snd_kcontrol *kcontrol,
  83. struct snd_ctl_elem_value *ucontrol)
  84. {
  85. int start = ucontrol->value.integer.value[0];
  86. u32 session_id = ucontrol->value.integer.value[1];
  87. if ((session_id != 0) &&
  88. ((session_id < SESSION_ID_BASE) ||
  89. (session_id >= SESSION_ID_BASE + MAX_VOC_SESSIONS))) {
  90. pr_err("%s: Invalid session_id 0x%x\n", __func__, session_id);
  91. return -EINVAL;
  92. }
  93. if (start)
  94. broadcast_event(AUDDEV_EVT_START_VOICE, DEVICE_IGNORE,
  95. session_id);
  96. else
  97. broadcast_event(AUDDEV_EVT_END_VOICE, DEVICE_IGNORE,
  98. session_id);
  99. return 0;
  100. }
  101. static int msm_v_mute_info(struct snd_kcontrol *kcontrol,
  102. struct snd_ctl_elem_info *uinfo)
  103. {
  104. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  105. uinfo->count = 3; /* dir, mute, session_id */
  106. uinfo->value.integer.min = 0;
  107. uinfo->value.integer.max = SESSION_ID_BASE + MAX_VOC_SESSIONS;
  108. return 0;
  109. }
  110. static int msm_v_mute_get(struct snd_kcontrol *kcontrol,
  111. struct snd_ctl_elem_value *ucontrol)
  112. {
  113. ucontrol->value.integer.value[0] = 0;
  114. ucontrol->value.integer.value[1] = 0;
  115. ucontrol->value.integer.value[2] = 0;
  116. return 0;
  117. }
  118. static int msm_v_mute_put(struct snd_kcontrol *kcontrol,
  119. struct snd_ctl_elem_value *ucontrol)
  120. {
  121. int dir = ucontrol->value.integer.value[0];
  122. int mute = ucontrol->value.integer.value[1];
  123. u32 session_id = ucontrol->value.integer.value[2];
  124. if ((session_id != 0) &&
  125. ((session_id < SESSION_ID_BASE) ||
  126. (session_id >= SESSION_ID_BASE + MAX_VOC_SESSIONS))) {
  127. pr_err("%s: Invalid session_id 0x%x\n", __func__, session_id);
  128. return -EINVAL;
  129. }
  130. return msm_set_voice_mute(dir, mute, session_id);
  131. }
  132. static int msm_v_volume_info(struct snd_kcontrol *kcontrol,
  133. struct snd_ctl_elem_info *uinfo)
  134. {
  135. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  136. uinfo->count = 3; /* dir, volume, session_id */
  137. uinfo->value.integer.min = 0;
  138. uinfo->value.integer.max = SESSION_ID_BASE + MAX_VOC_SESSIONS;
  139. return 0;
  140. }
  141. static int msm_v_volume_get(struct snd_kcontrol *kcontrol,
  142. struct snd_ctl_elem_value *ucontrol)
  143. {
  144. ucontrol->value.integer.value[0] = 0;
  145. ucontrol->value.integer.value[1] = 0;
  146. ucontrol->value.integer.value[2] = 0;
  147. return 0;
  148. }
  149. static int msm_v_volume_put(struct snd_kcontrol *kcontrol,
  150. struct snd_ctl_elem_value *ucontrol)
  151. {
  152. int dir = ucontrol->value.integer.value[0];
  153. int volume = ucontrol->value.integer.value[1];
  154. u32 session_id = ucontrol->value.integer.value[2];
  155. if ((session_id != 0) &&
  156. ((session_id < SESSION_ID_BASE) ||
  157. (session_id >= SESSION_ID_BASE + MAX_VOC_SESSIONS))) {
  158. pr_err("%s: Invalid session_id 0x%x\n", __func__, session_id);
  159. return -EINVAL;
  160. }
  161. return msm_set_voice_vol(dir, volume, session_id);
  162. }
  163. static int msm_volume_info(struct snd_kcontrol *kcontrol,
  164. struct snd_ctl_elem_info *uinfo)
  165. {
  166. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  167. uinfo->count = 2; /* Volume */
  168. uinfo->value.integer.min = 0;
  169. uinfo->value.integer.max = 16383;
  170. return 0;
  171. }
  172. static int msm_volume_get(struct snd_kcontrol *kcontrol,
  173. struct snd_ctl_elem_value *ucontrol)
  174. {
  175. ucontrol->value.integer.value[0] = 0;
  176. return 0;
  177. }
  178. static int msm_volume_put(struct snd_kcontrol *kcontrol,
  179. struct snd_ctl_elem_value *ucontrol)
  180. {
  181. int ret = 0;
  182. int session_id = ucontrol->value.integer.value[0];
  183. int volume = ucontrol->value.integer.value[1];
  184. int factor = ucontrol->value.integer.value[2];
  185. u64 session_mask = 0;
  186. if (factor > 10000)
  187. return -EINVAL;
  188. if ((volume < 0) || (volume/factor > 100))
  189. return -EINVAL;
  190. volume = (MSM_VOLUME_STEP * volume);
  191. /* Convert back to original decimal point by removing the 10-base factor
  192. * and discard the fractional portion
  193. */
  194. volume = volume/factor;
  195. if (volume > MSM_MAX_VOLUME)
  196. volume = MSM_MAX_VOLUME;
  197. /* Only Decoder volume control supported */
  198. session_mask = (((u64)0x1) << session_id) << (MAX_BIT_PER_CLIENT * \
  199. ((int)AUDDEV_CLNT_DEC-1));
  200. msm_vol_ctl.volume = volume;
  201. pr_debug("%s:session_id %d, volume %d", __func__, session_id, volume);
  202. broadcast_event(AUDDEV_EVT_STREAM_VOL_CHG, DEVICE_IGNORE,
  203. session_mask);
  204. return ret;
  205. }
  206. static int msm_voice_info(struct snd_kcontrol *kcontrol,
  207. struct snd_ctl_elem_info *uinfo)
  208. {
  209. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  210. uinfo->count = 3; /* Device */
  211. uinfo->value.integer.min = 0;
  212. uinfo->value.integer.max = msm_snddev_devcount();
  213. return 0;
  214. }
  215. static int msm_voice_put(struct snd_kcontrol *kcontrol,
  216. struct snd_ctl_elem_value *ucontrol)
  217. {
  218. int rc = 0;
  219. uint32_t rx_dev_id;
  220. uint32_t tx_dev_id;
  221. struct msm_snddev_info *rx_dev_info;
  222. struct msm_snddev_info *tx_dev_info;
  223. int set = ucontrol->value.integer.value[2];
  224. u64 session_mask;
  225. if (!set)
  226. return -EPERM;
  227. /* Rx Device Routing */
  228. rx_dev_id = ucontrol->value.integer.value[0];
  229. rx_dev_info = audio_dev_ctrl_find_dev(rx_dev_id);
  230. if (IS_ERR(rx_dev_info)) {
  231. pr_err("%s:pass invalid dev_id\n", __func__);
  232. rc = PTR_ERR(rx_dev_info);
  233. return rc;
  234. }
  235. if (!(rx_dev_info->capability & SNDDEV_CAP_RX)) {
  236. pr_err("%s:First Dev is supposed to be RX\n", __func__);
  237. return -EFAULT;
  238. }
  239. pr_debug("%s:route cfg %d STREAM_VOICE_RX type\n",
  240. __func__, rx_dev_id);
  241. msm_set_voc_route(rx_dev_info, AUDIO_ROUTE_STREAM_VOICE_RX,
  242. rx_dev_id);
  243. session_mask = ((u64)0x1) << (MAX_BIT_PER_CLIENT * \
  244. ((int)AUDDEV_CLNT_VOC-1));
  245. broadcast_event(AUDDEV_EVT_DEV_CHG_VOICE, rx_dev_id, session_mask);
  246. /* Tx Device Routing */
  247. tx_dev_id = ucontrol->value.integer.value[1];
  248. tx_dev_info = audio_dev_ctrl_find_dev(tx_dev_id);
  249. if (IS_ERR(tx_dev_info)) {
  250. pr_err("%s:pass invalid dev_id\n", __func__);
  251. rc = PTR_ERR(tx_dev_info);
  252. return rc;
  253. }
  254. if (!(tx_dev_info->capability & SNDDEV_CAP_TX)) {
  255. pr_err("%s:Second Dev is supposed to be Tx\n", __func__);
  256. return -EFAULT;
  257. }
  258. pr_debug("%s:route cfg %d %d type\n",
  259. __func__, tx_dev_id, AUDIO_ROUTE_STREAM_VOICE_TX);
  260. msm_set_voc_route(tx_dev_info, AUDIO_ROUTE_STREAM_VOICE_TX,
  261. tx_dev_id);
  262. broadcast_event(AUDDEV_EVT_DEV_CHG_VOICE, tx_dev_id, session_mask);
  263. if (rx_dev_info->opened)
  264. broadcast_event(AUDDEV_EVT_DEV_RDY, rx_dev_id, session_mask);
  265. if (tx_dev_info->opened)
  266. broadcast_event(AUDDEV_EVT_DEV_RDY, tx_dev_id, session_mask);
  267. return rc;
  268. }
  269. static int msm_voice_get(struct snd_kcontrol *kcontrol,
  270. struct snd_ctl_elem_value *ucontrol)
  271. {
  272. ucontrol->value.integer.value[0] = 0;
  273. /* TODO: query Device list */
  274. return 0;
  275. }
  276. static int msm_device_info(struct snd_kcontrol *kcontrol,
  277. struct snd_ctl_elem_info *uinfo)
  278. {
  279. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  280. uinfo->count = 1; /* Device */
  281. uinfo->value.integer.min = 0;
  282. uinfo->value.integer.max = msm_snddev_devcount();
  283. return 0;
  284. }
  285. static int msm_device_put(struct snd_kcontrol *kcontrol,
  286. struct snd_ctl_elem_value *ucontrol)
  287. {
  288. int rc = 0;
  289. int set = 0;
  290. struct msm_audio_route_config route_cfg;
  291. struct msm_snddev_info *dev_info;
  292. struct msm_snddev_info *dst_dev_info;
  293. struct msm_snddev_info *src_dev_info;
  294. int tx_freq = 0;
  295. int rx_freq = 0;
  296. u32 set_freq = 0;
  297. set = ucontrol->value.integer.value[0];
  298. route_cfg.dev_id = ucontrol->id.numid - device_index;
  299. dev_info = audio_dev_ctrl_find_dev(route_cfg.dev_id);
  300. if (IS_ERR(dev_info)) {
  301. pr_err("%s:pass invalid dev_id\n", __func__);
  302. rc = PTR_ERR(dev_info);
  303. return rc;
  304. }
  305. pr_info("%s:device %s set %d\n", __func__, dev_info->name, set);
  306. if (set) {
  307. if (!dev_info->opened) {
  308. set_freq = dev_info->sample_rate;
  309. if (!msm_device_is_voice(route_cfg.dev_id)) {
  310. msm_get_voc_freq(&tx_freq, &rx_freq);
  311. if (dev_info->capability & SNDDEV_CAP_TX)
  312. set_freq = tx_freq;
  313. if (set_freq == 0)
  314. set_freq = dev_info->sample_rate;
  315. } else
  316. set_freq = dev_info->sample_rate;
  317. pr_err("%s:device freq =%d\n", __func__, set_freq);
  318. rc = dev_info->dev_ops.set_freq(dev_info, set_freq);
  319. if (rc < 0) {
  320. pr_err("%s:device freq failed!\n", __func__);
  321. return rc;
  322. }
  323. dev_info->set_sample_rate = rc;
  324. rc = 0;
  325. rc = dev_info->dev_ops.open(dev_info);
  326. if (rc < 0) {
  327. pr_err("%s:Enabling %s failed\n",
  328. __func__, dev_info->name);
  329. return rc;
  330. }
  331. dev_info->opened = 1;
  332. broadcast_event(AUDDEV_EVT_DEV_RDY, route_cfg.dev_id,
  333. SESSION_IGNORE);
  334. if ((route_cfg.dev_id == src_dev) ||
  335. (route_cfg.dev_id == dst_dev)) {
  336. dst_dev_info = audio_dev_ctrl_find_dev(
  337. dst_dev);
  338. if (IS_ERR(dst_dev_info)) {
  339. pr_err("dst_dev:%s:pass invalid"
  340. "dev_id\n", __func__);
  341. rc = PTR_ERR(dst_dev_info);
  342. return rc;
  343. }
  344. src_dev_info = audio_dev_ctrl_find_dev(
  345. src_dev);
  346. if (IS_ERR(src_dev_info)) {
  347. pr_err("src_dev:%s:pass invalid"
  348. "dev_id\n", __func__);
  349. rc = PTR_ERR(src_dev_info);
  350. return rc;
  351. }
  352. if ((dst_dev_info->opened) &&
  353. (src_dev_info->opened)) {
  354. pr_debug("%d: Enable afe_loopback\n",
  355. __LINE__);
  356. afe_loopback(LOOPBACK_ENABLE,
  357. dst_dev_info->copp_id,
  358. src_dev_info->copp_id);
  359. loopback_status = 1;
  360. }
  361. }
  362. }
  363. } else {
  364. if (dev_info->opened) {
  365. broadcast_event(AUDDEV_EVT_REL_PENDING,
  366. route_cfg.dev_id,
  367. SESSION_IGNORE);
  368. rc = dev_info->dev_ops.close(dev_info);
  369. if (rc < 0) {
  370. pr_err("%s:Snd device failed close!\n",
  371. __func__);
  372. return rc;
  373. } else {
  374. dev_info->opened = 0;
  375. broadcast_event(AUDDEV_EVT_DEV_RLS,
  376. route_cfg.dev_id,
  377. SESSION_IGNORE);
  378. }
  379. if (loopback_status == 1) {
  380. if ((route_cfg.dev_id == src_dev) ||
  381. (route_cfg.dev_id == dst_dev)) {
  382. dst_dev_info = audio_dev_ctrl_find_dev(
  383. dst_dev);
  384. if (IS_ERR(dst_dev_info)) {
  385. pr_err("dst_dev:%s:pass invalid"
  386. "dev_id\n", __func__);
  387. rc = PTR_ERR(dst_dev_info);
  388. return rc;
  389. }
  390. src_dev_info = audio_dev_ctrl_find_dev(
  391. src_dev);
  392. if (IS_ERR(src_dev_info)) {
  393. pr_err("src_dev:%s:pass invalid"
  394. "dev_id\n", __func__);
  395. rc = PTR_ERR(src_dev_info);
  396. return rc;
  397. }
  398. pr_debug("%d: Disable afe_loopback\n",
  399. __LINE__);
  400. afe_loopback(LOOPBACK_DISABLE,
  401. dst_dev_info->copp_id,
  402. src_dev_info->copp_id);
  403. loopback_status = 0;
  404. }
  405. }
  406. }
  407. }
  408. return rc;
  409. }
  410. static int msm_device_get(struct snd_kcontrol *kcontrol,
  411. struct snd_ctl_elem_value *ucontrol)
  412. {
  413. int rc = 0;
  414. struct msm_audio_route_config route_cfg;
  415. struct msm_snddev_info *dev_info;
  416. route_cfg.dev_id = ucontrol->id.numid - device_index;
  417. dev_info = audio_dev_ctrl_find_dev(route_cfg.dev_id);
  418. if (IS_ERR(dev_info)) {
  419. pr_err("%s:pass invalid dev_id\n", __func__);
  420. rc = PTR_ERR(dev_info);
  421. return rc;
  422. }
  423. ucontrol->value.integer.value[0] = dev_info->copp_id;
  424. ucontrol->value.integer.value[1] = dev_info->capability;
  425. return 0;
  426. }
  427. static int msm_route_info(struct snd_kcontrol *kcontrol,
  428. struct snd_ctl_elem_info *uinfo)
  429. {
  430. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  431. uinfo->count = 3; /* Device */
  432. uinfo->value.integer.min = 0;
  433. uinfo->value.integer.max = msm_snddev_devcount();
  434. return 0;
  435. }
  436. static int msm_route_get(struct snd_kcontrol *kcontrol,
  437. struct snd_ctl_elem_value *ucontrol)
  438. {
  439. ucontrol->value.integer.value[0] = 0;
  440. /* TODO: query Device list */
  441. return 0;
  442. }
  443. static int msm_route_put(struct snd_kcontrol *kcontrol,
  444. struct snd_ctl_elem_value *ucontrol)
  445. {
  446. int rc = 0;
  447. int enc_freq = 0;
  448. int requested_freq = 0;
  449. struct msm_audio_route_config route_cfg;
  450. struct msm_snddev_info *dev_info;
  451. int session_id = ucontrol->value.integer.value[0];
  452. int set = ucontrol->value.integer.value[2];
  453. u64 session_mask = 0;
  454. route_cfg.dev_id = ucontrol->value.integer.value[1];
  455. if (ucontrol->id.numid == 2)
  456. route_cfg.stream_type = AUDIO_ROUTE_STREAM_PLAYBACK;
  457. else
  458. route_cfg.stream_type = AUDIO_ROUTE_STREAM_REC;
  459. pr_debug("%s:route cfg %d %d type for popp %d\n",
  460. __func__, route_cfg.dev_id, route_cfg.stream_type, session_id);
  461. dev_info = audio_dev_ctrl_find_dev(route_cfg.dev_id);
  462. if (IS_ERR(dev_info)) {
  463. pr_err("%s:pass invalid dev_id\n", __func__);
  464. rc = PTR_ERR(dev_info);
  465. return rc;
  466. }
  467. if (route_cfg.stream_type == AUDIO_ROUTE_STREAM_PLAYBACK) {
  468. rc = msm_snddev_set_dec(session_id, dev_info->copp_id, set,
  469. dev_info->sample_rate, dev_info->channel_mode);
  470. session_mask =
  471. (((u64)0x1) << session_id) << (MAX_BIT_PER_CLIENT * \
  472. ((int)AUDDEV_CLNT_DEC-1));
  473. if (!set) {
  474. if (dev_info->opened)
  475. broadcast_event(AUDDEV_EVT_DEV_RLS,
  476. route_cfg.dev_id,
  477. session_mask);
  478. dev_info->sessions &= ~(session_mask);
  479. } else {
  480. dev_info->sessions = dev_info->sessions | session_mask;
  481. if (dev_info->opened)
  482. broadcast_event(AUDDEV_EVT_DEV_RDY,
  483. route_cfg.dev_id,
  484. session_mask);
  485. }
  486. } else {
  487. rc = msm_snddev_set_enc(session_id, dev_info->copp_id, set,
  488. dev_info->sample_rate, dev_info->channel_mode);
  489. session_mask =
  490. (((u64)0x1) << session_id) << (MAX_BIT_PER_CLIENT * \
  491. ((int)AUDDEV_CLNT_ENC-1));
  492. if (!set) {
  493. if (dev_info->opened)
  494. broadcast_event(AUDDEV_EVT_DEV_RLS,
  495. route_cfg.dev_id,
  496. session_mask);
  497. dev_info->sessions &= ~(session_mask);
  498. } else {
  499. dev_info->sessions = dev_info->sessions | session_mask;
  500. enc_freq = msm_snddev_get_enc_freq(session_id);
  501. requested_freq = enc_freq;
  502. if (enc_freq > 0) {
  503. rc = msm_snddev_request_freq(&enc_freq,
  504. session_id,
  505. SNDDEV_CAP_TX,
  506. AUDDEV_CLNT_ENC);
  507. pr_debug("%s:sample rate configured %d\
  508. sample rate requested %d \n",
  509. __func__, enc_freq, requested_freq);
  510. if ((rc <= 0) || (enc_freq != requested_freq)) {
  511. pr_debug("%s:msm_snddev_withdraw_freq\n",
  512. __func__);
  513. rc = msm_snddev_withdraw_freq
  514. (session_id,
  515. SNDDEV_CAP_TX, AUDDEV_CLNT_ENC);
  516. broadcast_event(AUDDEV_EVT_FREQ_CHG,
  517. route_cfg.dev_id,
  518. SESSION_IGNORE);
  519. }
  520. }
  521. if (dev_info->opened)
  522. broadcast_event(AUDDEV_EVT_DEV_RDY,
  523. route_cfg.dev_id,
  524. session_mask);
  525. }
  526. }
  527. if (rc < 0) {
  528. pr_err("%s:device could not be assigned!\n", __func__);
  529. return -EFAULT;
  530. }
  531. return rc;
  532. }
  533. static int msm_device_volume_info(struct snd_kcontrol *kcontrol,
  534. struct snd_ctl_elem_info *uinfo)
  535. {
  536. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  537. uinfo->count = 2;
  538. uinfo->value.integer.min = 0;
  539. uinfo->value.integer.max = 100;
  540. return 0;
  541. }
  542. static int msm_device_volume_get(struct snd_kcontrol *kcontrol,
  543. struct snd_ctl_elem_value *ucontrol)
  544. {
  545. struct msm_snddev_info *dev_info;
  546. int dev_id = ucontrol->value.integer.value[0];
  547. dev_info = audio_dev_ctrl_find_dev(dev_id);
  548. ucontrol->value.integer.value[0] = dev_info->dev_volume;
  549. return 0;
  550. }
  551. static int msm_device_volume_put(struct snd_kcontrol *kcontrol,
  552. struct snd_ctl_elem_value *ucontrol)
  553. {
  554. int rc = -EPERM;
  555. struct msm_snddev_info *dev_info;
  556. int dev_id = ucontrol->value.integer.value[0];
  557. int volume = ucontrol->value.integer.value[1];
  558. pr_debug("%s:dev_id = %d, volume = %d\n", __func__, dev_id, volume);
  559. dev_info = audio_dev_ctrl_find_dev(dev_id);
  560. if (IS_ERR(dev_info)) {
  561. rc = PTR_ERR(dev_info);
  562. pr_err("%s: audio_dev_ctrl_find_dev failed. %ld \n",
  563. __func__, PTR_ERR(dev_info));
  564. return rc;
  565. }
  566. pr_debug("%s:dev_name = %s dev_id = %d, volume = %d\n",
  567. __func__, dev_info->name, dev_id, volume);
  568. if (dev_info->dev_ops.set_device_volume)
  569. rc = dev_info->dev_ops.set_device_volume(dev_info, volume);
  570. else {
  571. pr_info("%s : device %s does not support device volume "
  572. "control.", __func__, dev_info->name);
  573. return -EPERM;
  574. }
  575. return rc;
  576. }
  577. static int msm_reset_info(struct snd_kcontrol *kcontrol,
  578. struct snd_ctl_elem_info *uinfo)
  579. {
  580. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  581. uinfo->count = 1;
  582. uinfo->value.integer.min = 0;
  583. uinfo->value.integer.max = 0;
  584. return 0;
  585. }
  586. static int msm_reset_get(struct snd_kcontrol *kcontrol,
  587. struct snd_ctl_elem_value *ucontrol)
  588. {
  589. ucontrol->value.integer.value[0] = 0;
  590. return 0;
  591. }
  592. static int msm_reset_put(struct snd_kcontrol *kcontrol,
  593. struct snd_ctl_elem_value *ucontrol)
  594. {
  595. pr_err("%s:Resetting all devices\n", __func__);
  596. return msm_reset_all_device();
  597. }
  598. static int msm_anc_info(struct snd_kcontrol *kcontrol,
  599. struct snd_ctl_elem_info *uinfo)
  600. {
  601. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  602. uinfo->count = 1;
  603. uinfo->value.integer.min = 0;
  604. uinfo->value.integer.max = 1;
  605. return 0;
  606. }
  607. static int msm_anc_get(struct snd_kcontrol *kcontrol,
  608. struct snd_ctl_elem_value *ucontrol)
  609. {
  610. ucontrol->value.integer.value[0] = 0;
  611. return 0;
  612. }
  613. static int msm_anc_put(struct snd_kcontrol *kcontrol,
  614. struct snd_ctl_elem_value *ucontrol)
  615. {
  616. int rc = -EPERM;
  617. struct msm_snddev_info *dev_info;
  618. int dev_id = ucontrol->value.integer.value[0];
  619. int enable = ucontrol->value.integer.value[1];
  620. pr_debug("%s: dev_id = %d, enable = %d\n", __func__, dev_id, enable);
  621. dev_info = audio_dev_ctrl_find_dev(dev_id);
  622. if (IS_ERR(dev_info)) {
  623. rc = PTR_ERR(dev_info);
  624. pr_err("%s: audio_dev_ctrl_find_dev failed. %ld\n",
  625. __func__, PTR_ERR(dev_info));
  626. return rc;
  627. }
  628. if (dev_info->dev_ops.enable_anc) {
  629. rc = dev_info->dev_ops.enable_anc(dev_info, enable);
  630. } else {
  631. pr_info("%s : device %s does not support anc control.",
  632. __func__, dev_info->name);
  633. return -EPERM;
  634. }
  635. return rc;
  636. }
  637. static int pcm_route_info(struct snd_kcontrol *kcontrol,
  638. struct snd_ctl_elem_info *uinfo)
  639. {
  640. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  641. /*
  642. * First parameter is session id ~ subdevice number
  643. * Second parameter is device id.
  644. */
  645. uinfo->count = 3;
  646. uinfo->value.integer.min = 0;
  647. uinfo->value.integer.max = msm_snddev_devcount();
  648. return 0;
  649. }
  650. static int pcm_route_get_rx(struct snd_kcontrol *kcontrol,
  651. struct snd_ctl_elem_value *ucontrol)
  652. {
  653. return 0;
  654. }
  655. static int pcm_route_get_tx(struct snd_kcontrol *kcontrol,
  656. struct snd_ctl_elem_value *ucontrol)
  657. {
  658. return 0;
  659. }
  660. static int pcm_route_put_rx(struct snd_kcontrol *kcontrol,
  661. struct snd_ctl_elem_value *ucontrol)
  662. {
  663. int session_id = 0;
  664. int set = 0;
  665. struct msm_audio_route_config route_cfg;
  666. struct msm_snddev_info *dev_info;
  667. u64 session_mask = 0;
  668. /*
  669. * session id is incremented by one and stored as session id 0
  670. * is being used by dsp currently. whereas user space would use
  671. * subdevice number as session id.
  672. */
  673. session_id = ucontrol->value.integer.value[0];
  674. route_cfg.dev_id = ucontrol->value.integer.value[1];
  675. set = ucontrol->value.integer.value[2];
  676. dev_info = audio_dev_ctrl_find_dev(route_cfg.dev_id);
  677. if (IS_ERR(dev_info)) {
  678. pr_err("pass invalid dev_id %d\n", route_cfg.dev_id);
  679. return PTR_ERR(dev_info);
  680. }
  681. if (!(dev_info->capability & SNDDEV_CAP_RX))
  682. return -EINVAL;
  683. session_mask =
  684. (((u64)0x1) << session_id) << (MAX_BIT_PER_CLIENT * \
  685. ((int)AUDDEV_CLNT_DEC-1));
  686. if (!set) {
  687. session_route.playback_session[session_id][dev_info->copp_id]
  688. = DEVICE_IGNORE;
  689. broadcast_event(AUDDEV_EVT_DEV_RLS,
  690. route_cfg.dev_id,
  691. session_mask);
  692. dev_info->sessions &= ~(session_mask);
  693. return 0;
  694. }
  695. pr_debug("%s:Routing playback session %d to %s\n",
  696. __func__, (session_id),
  697. dev_info->name);
  698. session_route.playback_session[session_id][dev_info->copp_id] =
  699. dev_info->copp_id;
  700. if (dev_info->opened) {
  701. dev_info->sessions = dev_info->sessions | session_mask;
  702. broadcast_event(AUDDEV_EVT_DEV_RDY,
  703. route_cfg.dev_id,
  704. session_mask);
  705. } else {
  706. broadcast_event(AUDDEV_EVT_DEV_RLS,
  707. route_cfg.dev_id,
  708. session_mask);
  709. dev_info->sessions &= ~(session_mask);
  710. }
  711. return 0;
  712. }
  713. static int pcm_route_put_tx(struct snd_kcontrol *kcontrol,
  714. struct snd_ctl_elem_value *ucontrol)
  715. {
  716. int session_id = 0;
  717. int set = 0;
  718. struct msm_audio_route_config route_cfg;
  719. struct msm_snddev_info *dev_info;
  720. u64 session_mask = 0;
  721. session_id = ucontrol->value.integer.value[0];
  722. route_cfg.dev_id = ucontrol->value.integer.value[1];
  723. set = ucontrol->value.integer.value[2];
  724. dev_info = audio_dev_ctrl_find_dev(route_cfg.dev_id);
  725. if (IS_ERR(dev_info)) {
  726. pr_err("pass invalid dev_id %d\n", route_cfg.dev_id);
  727. return PTR_ERR(dev_info);
  728. }
  729. pr_debug("%s:Routing capture session %d to %s\n", __func__,
  730. session_id,
  731. dev_info->name);
  732. if (!(dev_info->capability & SNDDEV_CAP_TX))
  733. return -EINVAL;
  734. session_mask =
  735. (((u64)0x1) << session_id) << (MAX_BIT_PER_CLIENT * \
  736. ((int)AUDDEV_CLNT_ENC-1));
  737. if (!set) {
  738. session_route.capture_session[session_id][dev_info->copp_id]
  739. = DEVICE_IGNORE;
  740. broadcast_event(AUDDEV_EVT_DEV_RLS,
  741. route_cfg.dev_id,
  742. session_mask);
  743. dev_info->sessions &= ~(session_mask);
  744. return 0;
  745. }
  746. session_route.capture_session[session_id][dev_info->copp_id] =
  747. dev_info->copp_id;
  748. if (dev_info->opened) {
  749. dev_info->sessions = dev_info->sessions | session_mask;
  750. broadcast_event(AUDDEV_EVT_DEV_RDY,
  751. route_cfg.dev_id,
  752. session_mask);
  753. } else {
  754. broadcast_event(AUDDEV_EVT_DEV_RLS,
  755. route_cfg.dev_id,
  756. session_mask);
  757. dev_info->sessions &= ~(session_mask);
  758. }
  759. return 0;
  760. }
  761. static int msm_loopback_info(struct snd_kcontrol *kcontrol,
  762. struct snd_ctl_elem_info *uinfo)
  763. {
  764. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  765. uinfo->count = 3;
  766. uinfo->value.integer.min = 0;
  767. uinfo->value.integer.max = msm_snddev_devcount();
  768. return 0;
  769. }
  770. static int msm_loopback_get(struct snd_kcontrol *kcontrol,
  771. struct snd_ctl_elem_value *ucontrol)
  772. {
  773. ucontrol->value.integer.value[0] = 0;
  774. return 0;
  775. }
  776. static int msm_loopback_put(struct snd_kcontrol *kcontrol,
  777. struct snd_ctl_elem_value *ucontrol)
  778. {
  779. int rc = 0;
  780. struct msm_snddev_info *src_dev_info = NULL; /* TX device */
  781. struct msm_snddev_info *dst_dev_info = NULL; /* RX device */
  782. int dst_dev_id = ucontrol->value.integer.value[0];
  783. int src_dev_id = ucontrol->value.integer.value[1];
  784. int set = ucontrol->value.integer.value[2];
  785. pr_debug("%s: dst=%d :src=%d set=%d\n", __func__,
  786. dst_dev_id, src_dev_id, set);
  787. dst_dev_info = audio_dev_ctrl_find_dev(dst_dev_id);
  788. if (IS_ERR(dst_dev_info)) {
  789. pr_err("dst_dev:%s:pass invalid dev_id\n", __func__);
  790. rc = PTR_ERR(dst_dev_info);
  791. return rc;
  792. }
  793. if (!(dst_dev_info->capability & SNDDEV_CAP_RX)) {
  794. pr_err("Destination device %d is not RX device\n",
  795. dst_dev_id);
  796. return -EFAULT;
  797. }
  798. src_dev_info = audio_dev_ctrl_find_dev(src_dev_id);
  799. if (IS_ERR(src_dev_info)) {
  800. pr_err("src_dev:%s:pass invalid dev_id\n", __func__);
  801. rc = PTR_ERR(src_dev_info);
  802. return rc;
  803. }
  804. if (!(src_dev_info->capability & SNDDEV_CAP_TX)) {
  805. pr_err("Source device %d is not TX device\n", src_dev_id);
  806. return -EFAULT;
  807. }
  808. if (set) {
  809. pr_debug("%s:%d:Enabling AFE_Loopback\n", __func__, __LINE__);
  810. src_dev = src_dev_id;
  811. dst_dev = dst_dev_id;
  812. loopback_status = 1;
  813. if ((dst_dev_info->opened) && (src_dev_info->opened))
  814. rc = afe_loopback(LOOPBACK_ENABLE,
  815. dst_dev_info->copp_id,
  816. src_dev_info->copp_id);
  817. } else {
  818. pr_debug("%s:%d:Disabling AFE_Loopback\n", __func__, __LINE__);
  819. src_dev = DEVICE_IGNORE;
  820. dst_dev = DEVICE_IGNORE;
  821. loopback_status = 0;
  822. rc = afe_loopback(LOOPBACK_DISABLE,
  823. dst_dev_info->copp_id,
  824. src_dev_info->copp_id);
  825. }
  826. return rc;
  827. }
  828. static int msm_device_mute_info(struct snd_kcontrol *kcontrol,
  829. struct snd_ctl_elem_info *uinfo)
  830. {
  831. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  832. uinfo->count = 2;
  833. uinfo->value.integer.min = 0;
  834. uinfo->value.integer.max = msm_snddev_devcount();
  835. return 0;
  836. }
  837. static int msm_device_mute_get(struct snd_kcontrol *kcontrol,
  838. struct snd_ctl_elem_value *ucontrol)
  839. {
  840. return 0;
  841. }
  842. static int msm_device_mute_put(struct snd_kcontrol *kcontrol,
  843. struct snd_ctl_elem_value *ucontrol)
  844. {
  845. int dev_id = ucontrol->value.integer.value[0];
  846. int mute = ucontrol->value.integer.value[1];
  847. struct msm_snddev_info *dev_info;
  848. int rc = 0;
  849. u16 gain = 0x2000;
  850. dev_info = audio_dev_ctrl_find_dev(dev_id);
  851. if (IS_ERR(dev_info)) {
  852. rc = PTR_ERR(dev_info);
  853. pr_err("%s: audio_dev_ctrl_find_dev failed. %ld\n",
  854. __func__, PTR_ERR(dev_info));
  855. return rc;
  856. }
  857. if (!(dev_info->capability & SNDDEV_CAP_TX)) {
  858. rc = -EINVAL;
  859. return rc;
  860. }
  861. if (mute)
  862. gain = 0;
  863. pr_debug("%s:dev_name = %s dev_id = %d, gain = %hX\n",
  864. __func__, dev_info->name, dev_id, gain);
  865. rc = afe_apply_gain(dev_info->copp_id, gain);
  866. if (rc < 0) {
  867. pr_err("%s : device %s not able to set device gain "
  868. "control.", __func__, dev_info->name);
  869. return rc;
  870. }
  871. pr_debug("Muting/Unmuting device id %d(%s)\n", dev_id, dev_info->name);
  872. return rc;
  873. }
  874. static int msm_voc_session_info(struct snd_kcontrol *kcontrol,
  875. struct snd_ctl_elem_info *uinfo)
  876. {
  877. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  878. uinfo->count = 1;
  879. uinfo->value.integer.min = 0;
  880. uinfo->value.integer.max = SESSION_ID_BASE + MAX_VOC_SESSIONS;
  881. return 0;
  882. }
  883. static int msm_voice_session_get(struct snd_kcontrol *kcontrol,
  884. struct snd_ctl_elem_value *ucontrol)
  885. {
  886. ucontrol->value.integer.value[0] =
  887. voice_get_session_id("Voice session");
  888. return 0;
  889. }
  890. static int msm_voip_session_get(struct snd_kcontrol *kcontrol,
  891. struct snd_ctl_elem_value *ucontrol)
  892. {
  893. ucontrol->value.integer.value[0] = voice_get_session_id("VoIP session");
  894. return 0;
  895. }
  896. static struct snd_kcontrol_new snd_dev_controls[AUDIO_DEV_CTL_MAX_DEV];
  897. static int snd_dev_ctl_index(int idx)
  898. {
  899. struct msm_snddev_info *dev_info;
  900. dev_info = audio_dev_ctrl_find_dev(idx);
  901. if (IS_ERR(dev_info)) {
  902. pr_err("%s:pass invalid dev_id\n", __func__);
  903. return PTR_ERR(dev_info);
  904. }
  905. if (sizeof(dev_info->name) <= 44)
  906. sprintf(&snddev_name[idx][0] , "%s", dev_info->name);
  907. snd_dev_controls[idx].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  908. snd_dev_controls[idx].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
  909. snd_dev_controls[idx].name = &snddev_name[idx][0];
  910. snd_dev_controls[idx].index = idx;
  911. snd_dev_controls[idx].info = msm_device_info;
  912. snd_dev_controls[idx].get = msm_device_get;
  913. snd_dev_controls[idx].put = msm_device_put;
  914. snd_dev_controls[idx].private_value = 0;
  915. return 0;
  916. }
  917. #define MSM_EXT(xname, fp_info, fp_get, fp_put, addr) \
  918. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  919. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  920. .name = xname, \
  921. .info = fp_info,\
  922. .get = fp_get, .put = fp_put, \
  923. .private_value = addr, \
  924. }
  925. /* If new controls are to be added which would be constant across the
  926. * different targets, please add to the structure
  927. * snd_msm_controls. Please do not add any controls to the structure
  928. * snd_msm_secondary_controls defined below unless they are msm8x60
  929. * specific.
  930. */
  931. static struct snd_kcontrol_new snd_msm_controls[] = {
  932. MSM_EXT("Count", msm_scontrol_count_info, msm_scontrol_count_get, \
  933. NULL, 0),
  934. MSM_EXT("Stream", msm_route_info, msm_route_get, \
  935. msm_route_put, 0),
  936. MSM_EXT("Record", msm_route_info, msm_route_get, \
  937. msm_route_put, 0),
  938. MSM_EXT("Voice", msm_voice_info, msm_voice_get, \
  939. msm_voice_put, 0),
  940. MSM_EXT("Volume", msm_volume_info, msm_volume_get, \
  941. msm_volume_put, 0),
  942. MSM_EXT("VoiceVolume", msm_v_volume_info, msm_v_volume_get, \
  943. msm_v_volume_put, 0),
  944. MSM_EXT("VoiceMute", msm_v_mute_info, msm_v_mute_get, \
  945. msm_v_mute_put, 0),
  946. MSM_EXT("Voice Call", msm_v_call_info, msm_v_call_get, \
  947. msm_v_call_put, 0),
  948. MSM_EXT("Device_Volume", msm_device_volume_info,
  949. msm_device_volume_get, msm_device_volume_put, 0),
  950. MSM_EXT("Reset", msm_reset_info,
  951. msm_reset_get, msm_reset_put, 0),
  952. MSM_EXT("ANC", msm_anc_info, msm_anc_get, msm_anc_put, 0),
  953. MSM_EXT("Device_Mute", msm_device_mute_info,
  954. msm_device_mute_get, msm_device_mute_put, 0),
  955. };
  956. static struct snd_kcontrol_new snd_msm_secondary_controls[] = {
  957. MSM_EXT("PCM Playback Sink",
  958. pcm_route_info, pcm_route_get_rx, pcm_route_put_rx, 0),
  959. MSM_EXT("PCM Capture Source",
  960. pcm_route_info, pcm_route_get_tx, pcm_route_put_tx, 0),
  961. MSM_EXT("Sound Device Loopback", msm_loopback_info,
  962. msm_loopback_get, msm_loopback_put, 0),
  963. MSM_EXT("VoiceVolume Ext",
  964. msm_v_volume_info, msm_v_volume_get, msm_v_volume_put, 0),
  965. MSM_EXT("VoiceMute Ext",
  966. msm_v_mute_info, msm_v_mute_get, msm_v_mute_put, 0),
  967. MSM_EXT("Voice Call Ext",
  968. msm_v_call_info, msm_v_call_get, msm_v_call_put, 0),
  969. MSM_EXT("Voice session",
  970. msm_voc_session_info, msm_voice_session_get, NULL, 0),
  971. MSM_EXT("VoIP session",
  972. msm_voc_session_info, msm_voip_session_get, NULL, 0),
  973. };
  974. static int msm_new_mixer(struct snd_soc_codec *codec)
  975. {
  976. unsigned int idx;
  977. int err;
  978. int dev_cnt;
  979. strcpy(codec->card->snd_card->mixername, "MSM Mixer");
  980. for (idx = 0; idx < ARRAY_SIZE(snd_msm_controls); idx++) {
  981. err = snd_ctl_add(codec->card->snd_card,
  982. snd_ctl_new1(&snd_msm_controls[idx],
  983. NULL));
  984. if (err < 0)
  985. pr_err("%s:ERR adding ctl\n", __func__);
  986. }
  987. for (idx = 0; idx < ARRAY_SIZE(snd_msm_secondary_controls); idx++) {
  988. err = snd_ctl_add(codec->card->snd_card,
  989. snd_ctl_new1(&snd_msm_secondary_controls[idx],
  990. NULL));
  991. if (err < 0)
  992. pr_err("%s:ERR adding secondary ctl\n", __func__);
  993. }
  994. dev_cnt = msm_snddev_devcount();
  995. for (idx = 0; idx < dev_cnt; idx++) {
  996. if (!snd_dev_ctl_index(idx)) {
  997. err = snd_ctl_add(codec->card->snd_card,
  998. snd_ctl_new1(&snd_dev_controls[idx],
  999. NULL));
  1000. if (err < 0)
  1001. pr_err("%s:ERR adding ctl\n", __func__);
  1002. } else
  1003. return 0;
  1004. }
  1005. simple_control = ARRAY_SIZE(snd_msm_controls)
  1006. + ARRAY_SIZE(snd_msm_secondary_controls);
  1007. device_index = simple_control + 1;
  1008. return 0;
  1009. }
  1010. static int msm_soc_dai_init(
  1011. struct snd_soc_pcm_runtime *rtd)
  1012. {
  1013. int ret = 0;
  1014. struct snd_soc_codec *codec = rtd->codec;
  1015. init_waitqueue_head(&the_locks.enable_wait);
  1016. init_waitqueue_head(&the_locks.eos_wait);
  1017. init_waitqueue_head(&the_locks.write_wait);
  1018. init_waitqueue_head(&the_locks.read_wait);
  1019. memset(&session_route, DEVICE_IGNORE, sizeof(struct pcm_session));
  1020. ret = msm_new_mixer(codec);
  1021. if (ret < 0)
  1022. pr_err("%s: ALSA MSM Mixer Fail\n", __func__);
  1023. return ret;
  1024. }
  1025. static struct snd_soc_dai_link msm_dai[] = {
  1026. {
  1027. .name = "MSM Primary I2S",
  1028. .stream_name = "DSP 1",
  1029. .cpu_dai_name = "msm-cpu-dai.0",
  1030. .platform_name = "msm-dsp-audio.0",
  1031. .codec_name = "msm-codec-dai.0",
  1032. .codec_dai_name = "msm-codec-dai",
  1033. .init = &msm_soc_dai_init,
  1034. },
  1035. #ifdef CONFIG_MSM_8x60_VOIP
  1036. {
  1037. .name = "MSM Primary Voip",
  1038. .stream_name = "MVS",
  1039. .cpu_dai_name = "mvs-cpu-dai.0",
  1040. .platform_name = "msm-mvs-audio.0",
  1041. .codec_name = "mvs-codec-dai.0",
  1042. .codec_dai_name = "mvs-codec-dai",
  1043. },
  1044. #endif
  1045. };
  1046. static struct snd_soc_card snd_soc_card_msm = {
  1047. .name = "msm-audio",
  1048. .dai_link = msm_dai,
  1049. .num_links = ARRAY_SIZE(msm_dai),
  1050. };
  1051. static int __init msm_audio_init(void)
  1052. {
  1053. int ret;
  1054. msm_audio_snd_device = platform_device_alloc("soc-audio", -1);
  1055. if (!msm_audio_snd_device)
  1056. return -ENOMEM;
  1057. platform_set_drvdata(msm_audio_snd_device, &snd_soc_card_msm);
  1058. ret = platform_device_add(msm_audio_snd_device);
  1059. if (ret) {
  1060. platform_device_put(msm_audio_snd_device);
  1061. return ret;
  1062. }
  1063. src_dev = DEVICE_IGNORE;
  1064. dst_dev = DEVICE_IGNORE;
  1065. return ret;
  1066. }
  1067. static void __exit msm_audio_exit(void)
  1068. {
  1069. platform_device_unregister(msm_audio_snd_device);
  1070. }
  1071. module_init(msm_audio_init);
  1072. module_exit(msm_audio_exit);
  1073. MODULE_DESCRIPTION("PCM module");
  1074. MODULE_LICENSE("GPL v2");