msm-dai-q6.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048
  1. /* Copyright (c) 2011-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/module.h>
  14. #include <linux/device.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/mfd/wcd9xxx/core.h>
  17. #include <linux/bitops.h>
  18. #include <linux/slab.h>
  19. #include <linux/clk.h>
  20. #include <sound/core.h>
  21. #include <sound/pcm.h>
  22. #include <sound/soc.h>
  23. #include <sound/apr_audio.h>
  24. #include <sound/q6afe.h>
  25. #include <sound/msm-dai-q6.h>
  26. #include <sound/pcm_params.h>
  27. #include <mach/clk.h>
  28. enum {
  29. STATUS_PORT_STARTED, /* track if AFE port has started */
  30. STATUS_MAX
  31. };
  32. struct msm_dai_q6_dai_data {
  33. DECLARE_BITMAP(status_mask, STATUS_MAX);
  34. u32 rate;
  35. u32 channels;
  36. u32 bitwidth;
  37. union afe_port_config port_config;
  38. };
  39. struct msm_dai_q6_mi2s_dai_config {
  40. u16 pdata_mi2s_lines;
  41. struct msm_dai_q6_dai_data mi2s_dai_data;
  42. };
  43. struct msm_dai_q6_mi2s_dai_data {
  44. struct msm_dai_q6_mi2s_dai_config tx_dai;
  45. struct msm_dai_q6_mi2s_dai_config rx_dai;
  46. struct snd_pcm_hw_constraint_list rate_constraint;
  47. struct snd_pcm_hw_constraint_list bitwidth_constraint;
  48. };
  49. static struct clk *pcm_clk;
  50. static struct clk *sec_pcm_clk;
  51. static DEFINE_MUTEX(aux_pcm_mutex);
  52. static int aux_pcm_count;
  53. static struct msm_dai_auxpcm_pdata *auxpcm_plat_data;
  54. static struct msm_dai_auxpcm_pdata *sec_auxpcm_plat_data;
  55. static int msm_dai_q6_mi2s_format_put(struct snd_kcontrol *kcontrol,
  56. struct snd_ctl_elem_value *ucontrol)
  57. {
  58. struct msm_dai_q6_dai_data *dai_data = kcontrol->private_data;
  59. int value = ucontrol->value.integer.value[0];
  60. dai_data->port_config.mi2s.format = value;
  61. pr_debug("%s: value = %d, channel = %d, line = %d\n",
  62. __func__, value, dai_data->port_config.mi2s.channel,
  63. dai_data->port_config.mi2s.line);
  64. return 0;
  65. }
  66. static int msm_dai_q6_mi2s_format_get(struct snd_kcontrol *kcontrol,
  67. struct snd_ctl_elem_value *ucontrol)
  68. {
  69. struct msm_dai_q6_dai_data *dai_data = kcontrol->private_data;
  70. ucontrol->value.integer.value[0] = dai_data->port_config.mi2s.format ;
  71. return 0;
  72. }
  73. /* MI2S format field for AFE_PORT_CMD_I2S_CONFIG command
  74. * 0: linear PCM
  75. * 1: non-linear PCM
  76. * 2: PCM data in IEC 60968 container
  77. * 3: compressed data in IEC 60958 container
  78. */
  79. static const char *mi2s_format[] = {
  80. "LPCM",
  81. "Compr",
  82. "LPCM-60958",
  83. "Compr-60958"};
  84. static const struct soc_enum mi2s_config_enum[] = {
  85. SOC_ENUM_SINGLE_EXT(4, mi2s_format),
  86. };
  87. static const struct snd_kcontrol_new mi2s_config_controls[] = {
  88. SOC_ENUM_EXT("MI2S RX Format", mi2s_config_enum[0],
  89. msm_dai_q6_mi2s_format_get,
  90. msm_dai_q6_mi2s_format_put),
  91. SOC_ENUM_EXT("SEC RX Format", mi2s_config_enum[0],
  92. msm_dai_q6_mi2s_format_get,
  93. msm_dai_q6_mi2s_format_put),
  94. SOC_ENUM_EXT("MI2S TX Format", mi2s_config_enum[0],
  95. msm_dai_q6_mi2s_format_get,
  96. msm_dai_q6_mi2s_format_put),
  97. };
  98. static u8 num_of_bits_set(u8 sd_line_mask)
  99. {
  100. u8 num_bits_set = 0;
  101. while (sd_line_mask) {
  102. num_bits_set++;
  103. sd_line_mask = sd_line_mask & (sd_line_mask - 1);
  104. }
  105. return num_bits_set;
  106. }
  107. static int msm_dai_q6_mi2s_startup(struct snd_pcm_substream *substream,
  108. struct snd_soc_dai *dai)
  109. {
  110. struct msm_dai_q6_mi2s_dai_data *mi2s_dai_data =
  111. dev_get_drvdata(dai->dev);
  112. dev_dbg(dai->dev, "%s: cnst list %p\n", __func__,
  113. mi2s_dai_data->rate_constraint.list);
  114. if (mi2s_dai_data->rate_constraint.list) {
  115. snd_pcm_hw_constraint_list(substream->runtime, 0,
  116. SNDRV_PCM_HW_PARAM_RATE,
  117. &mi2s_dai_data->rate_constraint);
  118. snd_pcm_hw_constraint_list(substream->runtime, 0,
  119. SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
  120. &mi2s_dai_data->bitwidth_constraint);
  121. }
  122. return 0;
  123. }
  124. static int msm_dai_q6_mi2s_hw_params(struct snd_pcm_substream *substream,
  125. struct snd_pcm_hw_params *params,
  126. struct snd_soc_dai *dai)
  127. {
  128. struct msm_dai_q6_mi2s_dai_data *mi2s_dai_data =
  129. dev_get_drvdata(dai->dev);
  130. struct msm_dai_q6_mi2s_dai_config *mi2s_dai_config =
  131. (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
  132. &mi2s_dai_data->rx_dai : &mi2s_dai_data->tx_dai);
  133. struct msm_dai_q6_dai_data *dai_data = &mi2s_dai_config->mi2s_dai_data;
  134. dai_data->channels = params_channels(params);
  135. switch (dai_data->channels) {
  136. case 8:
  137. case 7:
  138. if (mi2s_dai_config->pdata_mi2s_lines < AFE_I2S_8CHS)
  139. goto error_invalid_data;
  140. dai_data->port_config.mi2s.line = AFE_I2S_8CHS;
  141. break;
  142. case 6:
  143. case 5:
  144. if (mi2s_dai_config->pdata_mi2s_lines < AFE_I2S_6CHS)
  145. goto error_invalid_data;
  146. dai_data->port_config.mi2s.line = AFE_I2S_6CHS;
  147. break;
  148. case 4:
  149. case 3:
  150. if (mi2s_dai_config->pdata_mi2s_lines < AFE_I2S_QUAD01)
  151. goto error_invalid_data;
  152. if (mi2s_dai_config->pdata_mi2s_lines == AFE_I2S_QUAD23)
  153. dai_data->port_config.mi2s.line =
  154. mi2s_dai_config->pdata_mi2s_lines;
  155. else
  156. dai_data->port_config.mi2s.line = AFE_I2S_QUAD01;
  157. break;
  158. case 2:
  159. case 1:
  160. if (mi2s_dai_config->pdata_mi2s_lines < AFE_I2S_SD0)
  161. goto error_invalid_data;
  162. switch (mi2s_dai_config->pdata_mi2s_lines) {
  163. case AFE_I2S_SD0:
  164. case AFE_I2S_SD1:
  165. case AFE_I2S_SD2:
  166. case AFE_I2S_SD3:
  167. dai_data->port_config.mi2s.line =
  168. mi2s_dai_config->pdata_mi2s_lines;
  169. break;
  170. case AFE_I2S_QUAD01:
  171. case AFE_I2S_6CHS:
  172. case AFE_I2S_8CHS:
  173. dai_data->port_config.mi2s.line = AFE_I2S_SD0;
  174. break;
  175. case AFE_I2S_QUAD23:
  176. dai_data->port_config.mi2s.line = AFE_I2S_SD2;
  177. break;
  178. }
  179. if (dai_data->channels == 2)
  180. dai_data->port_config.mi2s.channel = MSM_AFE_STEREO;
  181. else
  182. dai_data->port_config.mi2s.channel = MSM_AFE_MONO;
  183. break;
  184. default:
  185. goto error_invalid_data;
  186. }
  187. dai_data->rate = params_rate(params);
  188. dai_data->port_config.mi2s.bitwidth = 16;
  189. dai_data->bitwidth = 16;
  190. if (!mi2s_dai_data->rate_constraint.list) {
  191. mi2s_dai_data->rate_constraint.list = &dai_data->rate;
  192. mi2s_dai_data->bitwidth_constraint.list = &dai_data->bitwidth;
  193. }
  194. pr_debug("%s: dai_data->channels = %d, line = %d\n", __func__,
  195. dai_data->channels, dai_data->port_config.mi2s.line);
  196. return 0;
  197. error_invalid_data:
  198. pr_err("%s: dai_data->channels = %d, line = %d\n", __func__,
  199. dai_data->channels, dai_data->port_config.mi2s.line);
  200. return -EINVAL;
  201. }
  202. static int msm_dai_q6_mi2s_get_lineconfig(u16 sd_lines, u16 *config_ptr,
  203. unsigned int *ch_cnt)
  204. {
  205. u8 num_of_sd_lines;
  206. num_of_sd_lines = num_of_bits_set(sd_lines);
  207. switch (num_of_sd_lines) {
  208. case 0:
  209. pr_debug("%s: no line is assigned\n", __func__);
  210. break;
  211. case 1:
  212. switch (sd_lines) {
  213. case MSM_MI2S_SD0:
  214. *config_ptr = AFE_I2S_SD0;
  215. break;
  216. case MSM_MI2S_SD1:
  217. *config_ptr = AFE_I2S_SD1;
  218. break;
  219. case MSM_MI2S_SD2:
  220. *config_ptr = AFE_I2S_SD2;
  221. break;
  222. case MSM_MI2S_SD3:
  223. *config_ptr = AFE_I2S_SD3;
  224. break;
  225. default:
  226. pr_err("%s: invalid SD line\n",
  227. __func__);
  228. goto error_invalid_data;
  229. }
  230. break;
  231. case 2:
  232. switch (sd_lines) {
  233. case MSM_MI2S_SD0 | MSM_MI2S_SD1:
  234. *config_ptr = AFE_I2S_QUAD01;
  235. break;
  236. case MSM_MI2S_SD2 | MSM_MI2S_SD3:
  237. *config_ptr = AFE_I2S_QUAD23;
  238. break;
  239. default:
  240. pr_err("%s: invalid SD line\n",
  241. __func__);
  242. goto error_invalid_data;
  243. }
  244. break;
  245. case 3:
  246. switch (sd_lines) {
  247. case MSM_MI2S_SD0 | MSM_MI2S_SD1 | MSM_MI2S_SD2:
  248. *config_ptr = AFE_I2S_6CHS;
  249. break;
  250. default:
  251. pr_err("%s: invalid SD lines\n",
  252. __func__);
  253. goto error_invalid_data;
  254. }
  255. break;
  256. case 4:
  257. switch (sd_lines) {
  258. case MSM_MI2S_SD0 | MSM_MI2S_SD1 | MSM_MI2S_SD2 | MSM_MI2S_SD3:
  259. *config_ptr = AFE_I2S_8CHS;
  260. break;
  261. default:
  262. pr_err("%s: invalid SD lines\n",
  263. __func__);
  264. goto error_invalid_data;
  265. }
  266. break;
  267. default:
  268. pr_err("%s: invalid SD lines\n", __func__);
  269. goto error_invalid_data;
  270. }
  271. *ch_cnt = num_of_sd_lines;
  272. return 0;
  273. error_invalid_data:
  274. return -EINVAL;
  275. }
  276. static int msm_dai_q6_mi2s_platform_data_validation(
  277. struct platform_device *pdev, struct snd_soc_dai_driver *dai_driver)
  278. {
  279. struct msm_dai_q6_mi2s_dai_data *dai_data = dev_get_drvdata(&pdev->dev);
  280. struct msm_mi2s_pdata *mi2s_pdata =
  281. (struct msm_mi2s_pdata *) pdev->dev.platform_data;
  282. u16 sdline_config;
  283. unsigned int ch_cnt;
  284. int rc = 0;
  285. if ((mi2s_pdata->rx_sd_lines & mi2s_pdata->tx_sd_lines) ||
  286. (!mi2s_pdata->rx_sd_lines && !mi2s_pdata->tx_sd_lines)) {
  287. dev_err(&pdev->dev,
  288. "error sd line conflict or no line assigned\n");
  289. rc = -EINVAL;
  290. goto rtn;
  291. }
  292. rc = msm_dai_q6_mi2s_get_lineconfig(mi2s_pdata->rx_sd_lines,
  293. &sdline_config, &ch_cnt);
  294. if (IS_ERR_VALUE(rc)) {
  295. dev_err(&pdev->dev, "invalid MI2S RX sd line config\n");
  296. goto rtn;
  297. }
  298. if (ch_cnt) {
  299. dai_data->rx_dai.mi2s_dai_data.port_config.mi2s.line =
  300. sdline_config;
  301. dai_data->rx_dai.pdata_mi2s_lines = sdline_config;
  302. dai_driver->playback.channels_min = 1;
  303. dai_driver->playback.channels_max = ch_cnt << 1;
  304. } else {
  305. dai_driver->playback.channels_min = 0;
  306. dai_driver->playback.channels_max = 0;
  307. }
  308. rc = msm_dai_q6_mi2s_get_lineconfig(mi2s_pdata->tx_sd_lines,
  309. &sdline_config, &ch_cnt);
  310. if (IS_ERR_VALUE(rc)) {
  311. dev_err(&pdev->dev, "invalid MI2S TX sd line config\n");
  312. goto rtn;
  313. }
  314. if (ch_cnt) {
  315. dai_data->tx_dai.mi2s_dai_data.port_config.mi2s.line =
  316. sdline_config;
  317. dai_data->tx_dai.pdata_mi2s_lines = sdline_config;
  318. dai_driver->capture.channels_min = 1;
  319. dai_driver->capture.channels_max = ch_cnt << 1;
  320. } else {
  321. dai_driver->capture.channels_min = 0;
  322. dai_driver->capture.channels_max = 0;
  323. }
  324. dev_info(&pdev->dev, "%s: playback sdline %x capture sdline %x\n",
  325. __func__, dai_data->rx_dai.pdata_mi2s_lines,
  326. dai_data->tx_dai.pdata_mi2s_lines);
  327. dev_info(&pdev->dev, "%s: playback ch_max %d capture ch_mx %d\n",
  328. __func__, dai_driver->playback.channels_max,
  329. dai_driver->capture.channels_max);
  330. rtn:
  331. return rc;
  332. }
  333. static int msm_dai_q6_mi2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  334. {
  335. struct msm_dai_q6_mi2s_dai_data *mi2s_dai_data =
  336. dev_get_drvdata(dai->dev);
  337. if (test_bit(STATUS_PORT_STARTED,
  338. mi2s_dai_data->rx_dai.mi2s_dai_data.status_mask) ||
  339. test_bit(STATUS_PORT_STARTED,
  340. mi2s_dai_data->tx_dai.mi2s_dai_data.status_mask)) {
  341. dev_err(dai->dev, "%s: err chg i2s mode while dai running",
  342. __func__);
  343. return -EPERM;
  344. }
  345. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  346. case SND_SOC_DAIFMT_CBS_CFS:
  347. mi2s_dai_data->rx_dai.mi2s_dai_data.port_config.mi2s.ws = 1;
  348. mi2s_dai_data->tx_dai.mi2s_dai_data.port_config.mi2s.ws = 1;
  349. break;
  350. case SND_SOC_DAIFMT_CBM_CFM:
  351. mi2s_dai_data->rx_dai.mi2s_dai_data.port_config.mi2s.ws = 0;
  352. mi2s_dai_data->tx_dai.mi2s_dai_data.port_config.mi2s.ws = 0;
  353. break;
  354. default:
  355. return -EINVAL;
  356. }
  357. return 0;
  358. }
  359. static int msm_dai_q6_mi2s_prepare(struct snd_pcm_substream *substream,
  360. struct snd_soc_dai *dai)
  361. {
  362. struct msm_dai_q6_mi2s_dai_data *mi2s_dai_data =
  363. dev_get_drvdata(dai->dev);
  364. struct msm_dai_q6_dai_data *dai_data =
  365. (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
  366. &mi2s_dai_data->rx_dai.mi2s_dai_data :
  367. &mi2s_dai_data->tx_dai.mi2s_dai_data);
  368. u16 port_id = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
  369. MI2S_RX : MI2S_TX);
  370. int rc = 0;
  371. if (!test_bit(STATUS_PORT_STARTED, dai_data->status_mask)) {
  372. /* PORT START should be set if prepare called in active state */
  373. rc = afe_port_start(port_id, &dai_data->port_config,
  374. dai_data->rate);
  375. if (IS_ERR_VALUE(rc))
  376. dev_err(dai->dev, "fail to open AFE port %x\n",
  377. dai->id);
  378. else
  379. set_bit(STATUS_PORT_STARTED,
  380. dai_data->status_mask);
  381. }
  382. return rc;
  383. }
  384. static void msm_dai_q6_mi2s_shutdown(struct snd_pcm_substream *substream,
  385. struct snd_soc_dai *dai)
  386. {
  387. struct msm_dai_q6_mi2s_dai_data *mi2s_dai_data =
  388. dev_get_drvdata(dai->dev);
  389. struct msm_dai_q6_dai_data *dai_data =
  390. (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
  391. &mi2s_dai_data->rx_dai.mi2s_dai_data :
  392. &mi2s_dai_data->tx_dai.mi2s_dai_data);
  393. u16 port_id = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
  394. MI2S_RX : MI2S_TX);
  395. int rc = 0;
  396. if (test_bit(STATUS_PORT_STARTED, dai_data->status_mask)) {
  397. rc = afe_close(port_id);
  398. if (IS_ERR_VALUE(rc))
  399. dev_err(dai->dev, "fail to close AFE port\n");
  400. clear_bit(STATUS_PORT_STARTED, dai_data->status_mask);
  401. }
  402. if (!test_bit(STATUS_PORT_STARTED,
  403. mi2s_dai_data->rx_dai.mi2s_dai_data.status_mask) &&
  404. !test_bit(STATUS_PORT_STARTED,
  405. mi2s_dai_data->rx_dai.mi2s_dai_data.status_mask)) {
  406. mi2s_dai_data->rate_constraint.list = NULL;
  407. mi2s_dai_data->bitwidth_constraint.list = NULL;
  408. }
  409. }
  410. static int msm_dai_q6_cdc_hw_params(struct snd_pcm_hw_params *params,
  411. struct snd_soc_dai *dai, int stream)
  412. {
  413. struct msm_dai_q6_dai_data *dai_data = dev_get_drvdata(dai->dev);
  414. dai_data->channels = params_channels(params);
  415. switch (dai_data->channels) {
  416. case 2:
  417. case 4:
  418. case 6:
  419. case 8:
  420. dai_data->port_config.mi2s.channel = MSM_AFE_STEREO;
  421. break;
  422. case 1:
  423. dai_data->port_config.mi2s.channel = MSM_AFE_MONO;
  424. break;
  425. default:
  426. return -EINVAL;
  427. break;
  428. }
  429. dai_data->rate = params_rate(params);
  430. dev_dbg(dai->dev, " channel %d sample rate %d entered\n",
  431. dai_data->channels, dai_data->rate);
  432. /* Q6 only supports 16 as now */
  433. dai_data->port_config.mi2s.bitwidth = 16;
  434. dai_data->port_config.mi2s.line = 1;
  435. return 0;
  436. }
  437. static int msm_dai_q6_cdc_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  438. {
  439. struct msm_dai_q6_dai_data *dai_data = dev_get_drvdata(dai->dev);
  440. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  441. case SND_SOC_DAIFMT_CBS_CFS:
  442. dai_data->port_config.mi2s.ws = 1; /* CPU is master */
  443. break;
  444. case SND_SOC_DAIFMT_CBM_CFM:
  445. dai_data->port_config.mi2s.ws = 0; /* CPU is slave */
  446. break;
  447. default:
  448. return -EINVAL;
  449. }
  450. return 0;
  451. }
  452. static int msm_dai_q6_slim_bus_hw_params(struct snd_pcm_hw_params *params,
  453. struct snd_soc_dai *dai, int stream)
  454. {
  455. struct msm_dai_q6_dai_data *dai_data = dev_get_drvdata(dai->dev);
  456. dai_data->channels = params_channels(params);
  457. dai_data->rate = params_rate(params);
  458. /* Q6 only supports 16 as now */
  459. dai_data->port_config.slim_sch.bit_width = 16;
  460. dai_data->port_config.slim_sch.data_format = 0;
  461. dai_data->port_config.slim_sch.num_channels = dai_data->channels;
  462. dai_data->port_config.slim_sch.reserved = 0;
  463. dev_dbg(dai->dev, "%s:slimbus_dev_id[%hu] bit_wd[%hu] format[%hu]\n"
  464. "num_channel %hu slave_ch_mapping[0] %hu\n"
  465. "slave_port_mapping[1] %hu slave_port_mapping[2] %hu\n"
  466. "slave_port_mapping[3] %hu\n sample_rate %d\n", __func__,
  467. dai_data->port_config.slim_sch.slimbus_dev_id,
  468. dai_data->port_config.slim_sch.bit_width,
  469. dai_data->port_config.slim_sch.data_format,
  470. dai_data->port_config.slim_sch.num_channels,
  471. dai_data->port_config.slim_sch.slave_ch_mapping[0],
  472. dai_data->port_config.slim_sch.slave_ch_mapping[1],
  473. dai_data->port_config.slim_sch.slave_ch_mapping[2],
  474. dai_data->port_config.slim_sch.slave_ch_mapping[3],
  475. dai_data->rate);
  476. return 0;
  477. }
  478. static int msm_dai_q6_bt_fm_hw_params(struct snd_pcm_hw_params *params,
  479. struct snd_soc_dai *dai, int stream)
  480. {
  481. struct msm_dai_q6_dai_data *dai_data = dev_get_drvdata(dai->dev);
  482. dai_data->channels = params_channels(params);
  483. dai_data->rate = params_rate(params);
  484. dev_dbg(dai->dev, "channels %d sample rate %d entered\n",
  485. dai_data->channels, dai_data->rate);
  486. memset(&dai_data->port_config, 0, sizeof(dai_data->port_config));
  487. return 0;
  488. }
  489. static int msm_dai_q6_auxpcm_hw_params(
  490. struct snd_pcm_substream *substream,
  491. struct snd_pcm_hw_params *params,
  492. struct snd_soc_dai *dai)
  493. {
  494. struct msm_dai_q6_dai_data *dai_data = dev_get_drvdata(dai->dev);
  495. struct msm_dai_auxpcm_pdata *auxpcm_pdata =
  496. (struct msm_dai_auxpcm_pdata *) dai->dev->platform_data;
  497. if (params_channels(params) != 1) {
  498. dev_err(dai->dev, "AUX PCM supports only mono stream\n");
  499. return -EINVAL;
  500. }
  501. dai_data->channels = params_channels(params);
  502. dai_data->rate = params_rate(params);
  503. switch (dai_data->rate) {
  504. case 8000:
  505. dai_data->port_config.pcm.mode = auxpcm_pdata->mode_8k.mode;
  506. dai_data->port_config.pcm.sync = auxpcm_pdata->mode_8k.sync;
  507. dai_data->port_config.pcm.frame = auxpcm_pdata->mode_8k.frame;
  508. dai_data->port_config.pcm.quant = auxpcm_pdata->mode_8k.quant;
  509. dai_data->port_config.pcm.slot = auxpcm_pdata->mode_8k.slot;
  510. dai_data->port_config.pcm.data = auxpcm_pdata->mode_8k.data;
  511. break;
  512. case 16000:
  513. dai_data->port_config.pcm.mode = auxpcm_pdata->mode_16k.mode;
  514. dai_data->port_config.pcm.sync = auxpcm_pdata->mode_16k.sync;
  515. dai_data->port_config.pcm.frame = auxpcm_pdata->mode_16k.frame;
  516. dai_data->port_config.pcm.quant = auxpcm_pdata->mode_16k.quant;
  517. dai_data->port_config.pcm.slot = auxpcm_pdata->mode_16k.slot;
  518. dai_data->port_config.pcm.data = auxpcm_pdata->mode_16k.data;
  519. break;
  520. default:
  521. dev_err(dai->dev, "AUX PCM supports only 8kHz and 16kHz sampling rate\n");
  522. return -EINVAL;
  523. }
  524. return 0;
  525. }
  526. static int msm_dai_q6_sec_auxpcm_hw_params(
  527. struct snd_pcm_substream *substream,
  528. struct snd_pcm_hw_params *params,
  529. struct snd_soc_dai *dai)
  530. {
  531. struct msm_dai_q6_dai_data *dai_data = dev_get_drvdata(dai->dev);
  532. struct msm_dai_auxpcm_pdata *auxpcm_pdata =
  533. (struct msm_dai_auxpcm_pdata *) dai->dev->platform_data;
  534. pr_debug("%s\n", __func__);
  535. if (params_channels(params) != 1) {
  536. dev_err(dai->dev, "SEC AUX PCM supports only mono stream\n");
  537. return -EINVAL;
  538. }
  539. dai_data->channels = params_channels(params);
  540. dai_data->rate = params_rate(params);
  541. switch (dai_data->rate) {
  542. case 8000:
  543. dai_data->port_config.pcm.mode = auxpcm_pdata->mode_8k.mode;
  544. dai_data->port_config.pcm.sync = auxpcm_pdata->mode_8k.sync;
  545. dai_data->port_config.pcm.frame = auxpcm_pdata->mode_8k.frame;
  546. dai_data->port_config.pcm.quant = auxpcm_pdata->mode_8k.quant;
  547. dai_data->port_config.pcm.slot = auxpcm_pdata->mode_8k.slot;
  548. dai_data->port_config.pcm.data = auxpcm_pdata->mode_8k.data;
  549. break;
  550. case 16000:
  551. dai_data->port_config.pcm.mode = auxpcm_pdata->mode_16k.mode;
  552. dai_data->port_config.pcm.sync = auxpcm_pdata->mode_16k.sync;
  553. dai_data->port_config.pcm.frame = auxpcm_pdata->mode_16k.frame;
  554. dai_data->port_config.pcm.quant = auxpcm_pdata->mode_16k.quant;
  555. dai_data->port_config.pcm.slot = auxpcm_pdata->mode_16k.slot;
  556. dai_data->port_config.pcm.data = auxpcm_pdata->mode_16k.data;
  557. break;
  558. default:
  559. dev_err(dai->dev, "AUX PCM supports only 8kHz and 16kHz sampling rate\n");
  560. return -EINVAL;
  561. }
  562. return 0;
  563. }
  564. static int msm_dai_q6_afe_rtproxy_hw_params(struct snd_pcm_hw_params *params,
  565. struct snd_soc_dai *dai)
  566. {
  567. struct msm_dai_q6_dai_data *dai_data = dev_get_drvdata(dai->dev);
  568. dai_data->rate = params_rate(params);
  569. dai_data->port_config.rtproxy.num_ch =
  570. params_channels(params);
  571. pr_debug("channel %d entered,dai_id: %d,rate: %d\n",
  572. dai_data->port_config.rtproxy.num_ch, dai->id, dai_data->rate);
  573. dai_data->port_config.rtproxy.bitwidth = 16; /* Q6 only supports 16 */
  574. dai_data->port_config.rtproxy.interleaved = 1;
  575. dai_data->port_config.rtproxy.frame_sz = params_period_bytes(params);
  576. dai_data->port_config.rtproxy.jitter =
  577. dai_data->port_config.rtproxy.frame_sz/2;
  578. dai_data->port_config.rtproxy.lw_mark = 0;
  579. dai_data->port_config.rtproxy.hw_mark = 0;
  580. dai_data->port_config.rtproxy.rsvd = 0;
  581. return 0;
  582. }
  583. static int msm_dai_q6_pseudo_hw_params(struct snd_pcm_hw_params *params,
  584. struct snd_soc_dai *dai)
  585. {
  586. struct msm_dai_q6_dai_data *dai_data = dev_get_drvdata(dai->dev);
  587. dai_data->rate = params_rate(params);
  588. dai_data->channels = params_channels(params) > 6 ?
  589. params_channels(params) : 6;
  590. dai_data->port_config.pseudo.bit_width = 16;
  591. dai_data->port_config.pseudo.num_channels =
  592. dai_data->channels;
  593. dai_data->port_config.pseudo.data_format = 0;
  594. dai_data->port_config.pseudo.timing_mode = 1;
  595. dai_data->port_config.pseudo.reserved = 16;
  596. return 0;
  597. }
  598. /* Current implementation assumes hw_param is called once
  599. * This may not be the case but what to do when ADM and AFE
  600. * port are already opened and parameter changes
  601. */
  602. static int msm_dai_q6_hw_params(struct snd_pcm_substream *substream,
  603. struct snd_pcm_hw_params *params,
  604. struct snd_soc_dai *dai)
  605. {
  606. int rc = 0;
  607. switch (dai->id) {
  608. case PRIMARY_I2S_TX:
  609. case PRIMARY_I2S_RX:
  610. case SECONDARY_I2S_RX:
  611. case SECONDARY_I2S_TX:
  612. rc = msm_dai_q6_cdc_hw_params(params, dai, substream->stream);
  613. break;
  614. case SLIMBUS_0_RX:
  615. case SLIMBUS_1_RX:
  616. case SLIMBUS_3_RX:
  617. case SLIMBUS_0_TX:
  618. case SLIMBUS_1_TX:
  619. case SLIMBUS_2_RX:
  620. case SLIMBUS_2_TX:
  621. case SLIMBUS_3_TX:
  622. case SLIMBUS_4_RX:
  623. case SLIMBUS_4_TX:
  624. rc = msm_dai_q6_slim_bus_hw_params(params, dai,
  625. substream->stream);
  626. break;
  627. case INT_BT_SCO_RX:
  628. case INT_BT_SCO_TX:
  629. case INT_FM_RX:
  630. case INT_FM_TX:
  631. rc = msm_dai_q6_bt_fm_hw_params(params, dai, substream->stream);
  632. break;
  633. case RT_PROXY_DAI_001_TX:
  634. case RT_PROXY_DAI_001_RX:
  635. case RT_PROXY_DAI_002_TX:
  636. case RT_PROXY_DAI_002_RX:
  637. rc = msm_dai_q6_afe_rtproxy_hw_params(params, dai);
  638. break;
  639. case PSEUDOPORT_01:
  640. rc = msm_dai_q6_pseudo_hw_params(params, dai);
  641. break;
  642. case VOICE_PLAYBACK_TX:
  643. case VOICE_RECORD_RX:
  644. case VOICE_RECORD_TX:
  645. rc = 0;
  646. break;
  647. default:
  648. dev_err(dai->dev, "invalid AFE port ID\n");
  649. rc = -EINVAL;
  650. break;
  651. }
  652. return rc;
  653. }
  654. static void msm_dai_q6_auxpcm_shutdown(struct snd_pcm_substream *substream,
  655. struct snd_soc_dai *dai)
  656. {
  657. int rc = 0;
  658. struct msm_dai_q6_dai_data *dai_data = dev_get_drvdata(dai->dev);
  659. mutex_lock(&aux_pcm_mutex);
  660. dev_dbg(dai->dev, "%s dai->id = %d", __func__, dai->id);
  661. if (!test_bit(STATUS_PORT_STARTED, dai_data->status_mask)) {
  662. mutex_unlock(&aux_pcm_mutex);
  663. return;
  664. }
  665. clear_bit(STATUS_PORT_STARTED, dai_data->status_mask);
  666. aux_pcm_count--;
  667. if (aux_pcm_count > 0) {
  668. dev_dbg(dai->dev, "%s(): dai->id %d aux_pcm_count = %d\n",
  669. __func__, dai->id, aux_pcm_count);
  670. mutex_unlock(&aux_pcm_mutex);
  671. return;
  672. } else if (aux_pcm_count < 0) {
  673. dev_err(dai->dev, "%s(): ERROR: dai->id %d"
  674. " aux_pcm_count = %d < 0\n",
  675. __func__, dai->id, aux_pcm_count);
  676. aux_pcm_count = 0;
  677. mutex_unlock(&aux_pcm_mutex);
  678. return;
  679. }
  680. pr_debug("%s: dai->id = %d aux_pcm_count = %d\n", __func__,
  681. dai->id, aux_pcm_count);
  682. clk_disable_unprepare(pcm_clk);
  683. rc = afe_close(PCM_RX); /* can block */
  684. if (IS_ERR_VALUE(rc))
  685. dev_err(dai->dev, "fail to close PCM_RX AFE port\n");
  686. rc = afe_close(PCM_TX);
  687. if (IS_ERR_VALUE(rc))
  688. dev_err(dai->dev, "fail to close AUX PCM TX port\n");
  689. mutex_unlock(&aux_pcm_mutex);
  690. }
  691. static void msm_dai_q6_sec_auxpcm_shutdown(struct snd_pcm_substream *substream,
  692. struct snd_soc_dai *dai)
  693. {
  694. int rc = 0;
  695. pr_debug("%s\n", __func__);
  696. mutex_lock(&aux_pcm_mutex);
  697. if (aux_pcm_count == 0) {
  698. dev_dbg(dai->dev, "%s(): dai->id %d aux_pcm_count is 0. Just"
  699. " return\n", __func__, dai->id);
  700. mutex_unlock(&aux_pcm_mutex);
  701. return;
  702. }
  703. aux_pcm_count--;
  704. if (aux_pcm_count > 0) {
  705. dev_dbg(dai->dev, "%s(): dai->id %d aux_pcm_count = %d\n",
  706. __func__, dai->id, aux_pcm_count);
  707. mutex_unlock(&aux_pcm_mutex);
  708. return;
  709. } else if (aux_pcm_count < 0) {
  710. dev_err(dai->dev, "%s(): ERROR: dai->id %d"
  711. " aux_pcm_count = %d < 0\n",
  712. __func__, dai->id, aux_pcm_count);
  713. aux_pcm_count = 0;
  714. mutex_unlock(&aux_pcm_mutex);
  715. return;
  716. }
  717. pr_debug("%s: dai->id = %d aux_pcm_count = %d\n", __func__,
  718. dai->id, aux_pcm_count);
  719. clk_disable_unprepare(sec_pcm_clk);
  720. rc = afe_close(SECONDARY_PCM_RX); /* can block */
  721. if (IS_ERR_VALUE(rc))
  722. dev_err(dai->dev, "fail to close PCM_RX AFE port\n");
  723. rc = afe_close(SECONDARY_PCM_TX);
  724. if (IS_ERR_VALUE(rc))
  725. dev_err(dai->dev, "fail to close AUX PCM TX port\n");
  726. mutex_unlock(&aux_pcm_mutex);
  727. }
  728. static void msm_dai_q6_shutdown(struct snd_pcm_substream *substream,
  729. struct snd_soc_dai *dai)
  730. {
  731. struct msm_dai_q6_dai_data *dai_data = dev_get_drvdata(dai->dev);
  732. int rc = 0;
  733. if (test_bit(STATUS_PORT_STARTED, dai_data->status_mask)) {
  734. switch (dai->id) {
  735. case VOICE_PLAYBACK_TX:
  736. case VOICE_RECORD_TX:
  737. case VOICE_RECORD_RX:
  738. pr_debug("%s, stop pseudo port:%d\n",
  739. __func__, dai->id);
  740. rc = afe_stop_pseudo_port(dai->id);
  741. break;
  742. default:
  743. rc = afe_close(dai->id); /* can block */
  744. break;
  745. }
  746. if (IS_ERR_VALUE(rc))
  747. dev_err(dai->dev, "fail to close AFE port\n");
  748. pr_debug("%s: dai_data->status_mask = %ld\n", __func__,
  749. *dai_data->status_mask);
  750. clear_bit(STATUS_PORT_STARTED, dai_data->status_mask);
  751. }
  752. }
  753. static int msm_dai_q6_auxpcm_prepare(struct snd_pcm_substream *substream,
  754. struct snd_soc_dai *dai)
  755. {
  756. struct msm_dai_q6_dai_data *dai_data = dev_get_drvdata(dai->dev);
  757. int rc = 0;
  758. struct msm_dai_auxpcm_pdata *auxpcm_pdata =
  759. (struct msm_dai_auxpcm_pdata *) dai->dev->platform_data;
  760. unsigned long pcm_clk_rate;
  761. mutex_lock(&aux_pcm_mutex);
  762. set_bit(STATUS_PORT_STARTED,
  763. dai_data->status_mask);
  764. dev_dbg(dai->dev, "%s dai->id = %d", __func__, dai->id);
  765. aux_pcm_count++;
  766. if (aux_pcm_count >= 2) {
  767. dev_dbg(dai->dev, "%s(): dai->id %d aux_pcm_count = %d >= 2\n",
  768. __func__, dai->id, aux_pcm_count);
  769. mutex_unlock(&aux_pcm_mutex);
  770. return 0;
  771. }
  772. pr_debug("%s:dai->id:%d aux_pcm_count = %d. opening afe\n",
  773. __func__, dai->id, aux_pcm_count);
  774. rc = afe_q6_interface_prepare();
  775. if (IS_ERR_VALUE(rc))
  776. dev_err(dai->dev, "fail to open AFE APR\n");
  777. /*
  778. * For AUX PCM Interface the below sequence of clk
  779. * settings and opening of afe port is a strict requirement.
  780. * afe_port_start is called to make sure to make sure the port
  781. * is open before deasserting the clock line. This is
  782. * required because pcm register is not written before
  783. * clock deassert. Hence the hw does not get updated with
  784. * new setting if the below clock assert/deasset and afe_port_start
  785. * sequence is not followed.
  786. */
  787. clk_reset(pcm_clk, CLK_RESET_ASSERT);
  788. afe_port_start(PCM_RX, &dai_data->port_config, dai_data->rate);
  789. afe_port_start(PCM_TX, &dai_data->port_config, dai_data->rate);
  790. if (dai_data->rate == 8000) {
  791. pcm_clk_rate = auxpcm_pdata->mode_8k.pcm_clk_rate;
  792. } else if (dai_data->rate == 16000) {
  793. pcm_clk_rate = auxpcm_pdata->mode_16k.pcm_clk_rate;
  794. } else {
  795. dev_err(dai->dev, "%s: Invalid AUX PCM rate %d\n", __func__,
  796. dai_data->rate);
  797. return -EINVAL;
  798. }
  799. rc = clk_set_rate(pcm_clk, pcm_clk_rate);
  800. if (rc < 0) {
  801. pr_err("%s: clk_set_rate failed\n", __func__);
  802. return rc;
  803. }
  804. clk_prepare_enable(pcm_clk);
  805. clk_reset(pcm_clk, CLK_RESET_DEASSERT);
  806. mutex_unlock(&aux_pcm_mutex);
  807. return rc;
  808. }
  809. static int msm_dai_q6_sec_auxpcm_prepare(struct snd_pcm_substream *substream,
  810. struct snd_soc_dai *dai)
  811. {
  812. struct msm_dai_q6_dai_data *dai_data = dev_get_drvdata(dai->dev);
  813. int rc = 0;
  814. struct msm_dai_auxpcm_pdata *auxpcm_pdata =
  815. (struct msm_dai_auxpcm_pdata *) dai->dev->platform_data;
  816. unsigned long pcm_clk_rate;
  817. pr_info("%s\n", __func__);
  818. mutex_lock(&aux_pcm_mutex);
  819. if (aux_pcm_count == 2) {
  820. dev_dbg(dai->dev, "%s(): dai->id %d aux_pcm_count is 2. Just"
  821. " return.\n", __func__, dai->id);
  822. mutex_unlock(&aux_pcm_mutex);
  823. return 0;
  824. } else if (aux_pcm_count > 2) {
  825. dev_err(dai->dev, "%s(): ERROR: dai->id %d"
  826. " aux_pcm_count = %d > 2\n",
  827. __func__, dai->id, aux_pcm_count);
  828. mutex_unlock(&aux_pcm_mutex);
  829. return 0;
  830. }
  831. aux_pcm_count++;
  832. if (aux_pcm_count == 2) {
  833. dev_dbg(dai->dev, "%s(): dai->id %d aux_pcm_count = %d after "
  834. " increment\n", __func__, dai->id, aux_pcm_count);
  835. mutex_unlock(&aux_pcm_mutex);
  836. return 0;
  837. }
  838. pr_debug("%s:dai->id:%d aux_pcm_count = %d. opening afe\n",
  839. __func__, dai->id, aux_pcm_count);
  840. rc = afe_q6_interface_prepare();
  841. if (IS_ERR_VALUE(rc))
  842. dev_err(dai->dev, "fail to open AFE APR\n");
  843. /*
  844. * For AUX PCM Interface the below sequence of clk
  845. * settings and opening of afe port is a strict requirement.
  846. * afe_port_start is called to make sure to make sure the port
  847. * is open before deasserting the clock line. This is
  848. * required because pcm register is not written before
  849. * clock deassert. Hence the hw does not get updated with
  850. * new setting if the below clock assert/deasset and afe_port_start
  851. * sequence is not followed.
  852. */
  853. clk_reset(sec_pcm_clk, CLK_RESET_ASSERT);
  854. afe_port_start(SECONDARY_PCM_RX, &dai_data->port_config,
  855. dai_data->rate);
  856. afe_port_start(SECONDARY_PCM_TX, &dai_data->port_config,
  857. dai_data->rate);
  858. if (dai_data->rate == 8000) {
  859. pcm_clk_rate = auxpcm_pdata->mode_8k.pcm_clk_rate;
  860. } else if (dai_data->rate == 16000) {
  861. pcm_clk_rate = auxpcm_pdata->mode_16k.pcm_clk_rate;
  862. } else {
  863. dev_err(dai->dev, "%s: Invalid AUX PCM rate %d\n", __func__,
  864. dai_data->rate);
  865. return -EINVAL;
  866. }
  867. rc = clk_set_rate(sec_pcm_clk, pcm_clk_rate);
  868. if (rc < 0) {
  869. pr_err("%s: clk_set_rate failed\n", __func__);
  870. return rc;
  871. }
  872. clk_prepare_enable(sec_pcm_clk);
  873. clk_reset(sec_pcm_clk, CLK_RESET_DEASSERT);
  874. mutex_unlock(&aux_pcm_mutex);
  875. return rc;
  876. }
  877. static int msm_dai_q6_prepare(struct snd_pcm_substream *substream,
  878. struct snd_soc_dai *dai)
  879. {
  880. struct msm_dai_q6_dai_data *dai_data = dev_get_drvdata(dai->dev);
  881. int rc = 0;
  882. if (!test_bit(STATUS_PORT_STARTED, dai_data->status_mask)) {
  883. switch (dai->id) {
  884. case VOICE_PLAYBACK_TX:
  885. case VOICE_RECORD_TX:
  886. case VOICE_RECORD_RX:
  887. rc = afe_start_pseudo_port(dai->id);
  888. break;
  889. default:
  890. rc = afe_port_start(dai->id, &dai_data->port_config,
  891. dai_data->rate);
  892. }
  893. if (IS_ERR_VALUE(rc))
  894. dev_err(dai->dev, "fail to open AFE port %x\n",
  895. dai->id);
  896. else
  897. set_bit(STATUS_PORT_STARTED,
  898. dai_data->status_mask);
  899. }
  900. return rc;
  901. }
  902. static int msm_dai_q6_auxpcm_trigger(struct snd_pcm_substream *substream,
  903. int cmd, struct snd_soc_dai *dai)
  904. {
  905. int rc = 0;
  906. pr_debug("%s:port:%d cmd:%d aux_pcm_count= %d",
  907. __func__, dai->id, cmd, aux_pcm_count);
  908. switch (cmd) {
  909. case SNDRV_PCM_TRIGGER_START:
  910. case SNDRV_PCM_TRIGGER_RESUME:
  911. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  912. /* afe_open will be called from prepare */
  913. return 0;
  914. case SNDRV_PCM_TRIGGER_STOP:
  915. case SNDRV_PCM_TRIGGER_SUSPEND:
  916. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  917. return 0;
  918. default:
  919. rc = -EINVAL;
  920. }
  921. return rc;
  922. }
  923. static int msm_dai_q6_dai_auxpcm_probe(struct snd_soc_dai *dai)
  924. {
  925. struct msm_dai_q6_dai_data *dai_data;
  926. int rc = 0;
  927. struct msm_dai_auxpcm_pdata *auxpcm_pdata =
  928. (struct msm_dai_auxpcm_pdata *) dai->dev->platform_data;
  929. mutex_lock(&aux_pcm_mutex);
  930. if (!auxpcm_plat_data)
  931. auxpcm_plat_data = auxpcm_pdata;
  932. else if (auxpcm_plat_data != auxpcm_pdata) {
  933. dev_err(dai->dev, "AUX PCM RX and TX devices does not have"
  934. " same platform data\n");
  935. return -EINVAL;
  936. }
  937. /*
  938. * The clk name for AUX PCM operation is passed as platform
  939. * data to the cpu driver, since cpu drive is unaware of any
  940. * boarc specific configuration.
  941. */
  942. if (!pcm_clk) {
  943. pcm_clk = clk_get(dai->dev, auxpcm_pdata->clk);
  944. if (IS_ERR(pcm_clk)) {
  945. pr_err("%s: could not get pcm_clk\n", __func__);
  946. pcm_clk = NULL;
  947. return -ENODEV;
  948. }
  949. }
  950. mutex_unlock(&aux_pcm_mutex);
  951. dai_data = kzalloc(sizeof(struct msm_dai_q6_dai_data), GFP_KERNEL);
  952. if (!dai_data) {
  953. dev_err(dai->dev, "DAI-%d: fail to allocate dai data\n",
  954. dai->id);
  955. rc = -ENOMEM;
  956. } else
  957. dev_set_drvdata(dai->dev, dai_data);
  958. pr_debug("%s : probe done for dai->id %d\n", __func__, dai->id);
  959. return rc;
  960. }
  961. static int msm_dai_q6_dai_sec_auxpcm_probe(struct snd_soc_dai *dai)
  962. {
  963. struct msm_dai_q6_dai_data *dai_data;
  964. int rc = 0;
  965. struct msm_dai_auxpcm_pdata *auxpcm_pdata =
  966. (struct msm_dai_auxpcm_pdata *) dai->dev->platform_data;
  967. pr_info("%s\n", __func__);
  968. mutex_lock(&aux_pcm_mutex);
  969. if (!sec_auxpcm_plat_data)
  970. sec_auxpcm_plat_data = auxpcm_pdata;
  971. else if (sec_auxpcm_plat_data != auxpcm_pdata) {
  972. dev_err(dai->dev, "AUX PCM RX and TX devices does not have"
  973. " same platform data sec_auxpcm_plat_data\n");
  974. return -EINVAL;
  975. }
  976. /*
  977. * The clk name for AUX PCM operation is passed as platform
  978. * data to the cpu driver, since cpu drive is unaware of any
  979. * boarc specific configuration.
  980. */
  981. if (!sec_pcm_clk) {
  982. sec_pcm_clk = clk_get(dai->dev, auxpcm_pdata->clk);
  983. if (IS_ERR(sec_pcm_clk)) {
  984. pr_err("%s: could not get sec_pcm_clk\n", __func__);
  985. sec_pcm_clk = NULL;
  986. return -ENODEV;
  987. }
  988. }
  989. mutex_unlock(&aux_pcm_mutex);
  990. dai_data = kzalloc(sizeof(struct msm_dai_q6_dai_data), GFP_KERNEL);
  991. if (!dai_data) {
  992. dev_err(dai->dev, "DAI-%d: fail to allocate dai data\n",
  993. dai->id);
  994. rc = -ENOMEM;
  995. } else
  996. dev_set_drvdata(dai->dev, dai_data);
  997. pr_debug("%s : probe done for dai->id %d\n", __func__, dai->id);
  998. return rc;
  999. }
  1000. static int msm_dai_q6_dai_auxpcm_remove(struct snd_soc_dai *dai)
  1001. {
  1002. struct msm_dai_q6_dai_data *dai_data;
  1003. int rc;
  1004. dai_data = dev_get_drvdata(dai->dev);
  1005. mutex_lock(&aux_pcm_mutex);
  1006. if (aux_pcm_count == 0) {
  1007. dev_dbg(dai->dev, "%s(): dai->id %d aux_pcm_count is 0. clean"
  1008. " up and return\n", __func__, dai->id);
  1009. goto done;
  1010. }
  1011. aux_pcm_count--;
  1012. if (aux_pcm_count > 0) {
  1013. dev_dbg(dai->dev, "%s(): dai->id %d aux_pcm_count = %d\n",
  1014. __func__, dai->id, aux_pcm_count);
  1015. goto done;
  1016. } else if (aux_pcm_count < 0) {
  1017. dev_err(dai->dev, "%s(): ERROR: dai->id %d"
  1018. " aux_pcm_count = %d < 0\n",
  1019. __func__, dai->id, aux_pcm_count);
  1020. goto done;
  1021. }
  1022. dev_dbg(dai->dev, "%s(): dai->id %d aux_pcm_count = %d."
  1023. "closing afe\n",
  1024. __func__, dai->id, aux_pcm_count);
  1025. rc = afe_close(PCM_RX); /* can block */
  1026. if (IS_ERR_VALUE(rc))
  1027. dev_err(dai->dev, "fail to close AUX PCM RX AFE port\n");
  1028. rc = afe_close(PCM_TX);
  1029. if (IS_ERR_VALUE(rc))
  1030. dev_err(dai->dev, "fail to close AUX PCM TX AFE port\n");
  1031. done:
  1032. kfree(dai_data);
  1033. snd_soc_unregister_dai(dai->dev);
  1034. mutex_unlock(&aux_pcm_mutex);
  1035. return 0;
  1036. }
  1037. static int msm_dai_q6_dai_sec_auxpcm_remove(struct snd_soc_dai *dai)
  1038. {
  1039. struct msm_dai_q6_dai_data *dai_data;
  1040. int rc;
  1041. pr_debug("%s\n", __func__);
  1042. dai_data = dev_get_drvdata(dai->dev);
  1043. mutex_lock(&aux_pcm_mutex);
  1044. if (aux_pcm_count == 0) {
  1045. dev_dbg(dai->dev, "%s(): dai->id %d aux_pcm_count is 0. clean"
  1046. " up and return\n", __func__, dai->id);
  1047. goto done;
  1048. }
  1049. aux_pcm_count--;
  1050. if (aux_pcm_count > 0) {
  1051. dev_dbg(dai->dev, "%s(): dai->id %d aux_pcm_count = %d\n",
  1052. __func__, dai->id, aux_pcm_count);
  1053. goto done;
  1054. } else if (aux_pcm_count < 0) {
  1055. dev_err(dai->dev, "%s(): ERROR: dai->id %d"
  1056. " aux_pcm_count = %d < 0\n",
  1057. __func__, dai->id, aux_pcm_count);
  1058. goto done;
  1059. }
  1060. dev_dbg(dai->dev, "%s(): dai->id %d aux_pcm_count = %d."
  1061. "closing afe\n",
  1062. __func__, dai->id, aux_pcm_count);
  1063. rc = afe_close(SECONDARY_PCM_RX); /* can block */
  1064. if (IS_ERR_VALUE(rc))
  1065. dev_err(dai->dev, "fail to close AUX PCM RX AFE port\n");
  1066. rc = afe_close(SECONDARY_PCM_TX);
  1067. if (IS_ERR_VALUE(rc))
  1068. dev_err(dai->dev, "fail to close AUX PCM TX AFE port\n");
  1069. done:
  1070. kfree(dai_data);
  1071. snd_soc_unregister_dai(dai->dev);
  1072. mutex_unlock(&aux_pcm_mutex);
  1073. return 0;
  1074. }
  1075. static int msm_dai_q6_dai_mi2s_probe(struct snd_soc_dai *dai)
  1076. {
  1077. struct msm_dai_q6_mi2s_dai_data *mi2s_dai_data =
  1078. dev_get_drvdata(dai->dev);
  1079. struct snd_kcontrol *kcontrol = NULL;
  1080. int rc = 0;
  1081. if (mi2s_dai_data->rx_dai.mi2s_dai_data.port_config.mi2s.line) {
  1082. kcontrol = snd_ctl_new1(&mi2s_config_controls[0],
  1083. &mi2s_dai_data->rx_dai.mi2s_dai_data);
  1084. rc = snd_ctl_add(dai->card->snd_card, kcontrol);
  1085. if (IS_ERR_VALUE(rc)) {
  1086. dev_err(dai->dev, "%s: err add RX fmt ctl\n", __func__);
  1087. goto rtn;
  1088. }
  1089. }
  1090. if (mi2s_dai_data->tx_dai.mi2s_dai_data.port_config.mi2s.line) {
  1091. rc = snd_ctl_add(dai->card->snd_card,
  1092. snd_ctl_new1(&mi2s_config_controls[2],
  1093. &mi2s_dai_data->tx_dai.mi2s_dai_data));
  1094. if (IS_ERR_VALUE(rc)) {
  1095. if (kcontrol)
  1096. snd_ctl_remove(dai->card->snd_card, kcontrol);
  1097. dev_err(dai->dev, "%s: err add TX fmt ctl\n", __func__);
  1098. }
  1099. }
  1100. rtn:
  1101. return rc;
  1102. }
  1103. static int msm_dai_q6_dai_mi2s_remove(struct snd_soc_dai *dai)
  1104. {
  1105. struct msm_dai_q6_mi2s_dai_data *mi2s_dai_data =
  1106. dev_get_drvdata(dai->dev);
  1107. int rc;
  1108. /* If AFE port is still up, close it */
  1109. if (test_bit(STATUS_PORT_STARTED,
  1110. mi2s_dai_data->rx_dai.mi2s_dai_data.status_mask)) {
  1111. rc = afe_close(MI2S_RX); /* can block */
  1112. if (IS_ERR_VALUE(rc))
  1113. dev_err(dai->dev, "fail to close MI2S_RX port\n");
  1114. clear_bit(STATUS_PORT_STARTED,
  1115. mi2s_dai_data->rx_dai.mi2s_dai_data.status_mask);
  1116. }
  1117. if (test_bit(STATUS_PORT_STARTED,
  1118. mi2s_dai_data->tx_dai.mi2s_dai_data.status_mask)) {
  1119. rc = afe_close(MI2S_TX); /* can block */
  1120. if (IS_ERR_VALUE(rc))
  1121. dev_err(dai->dev, "fail to close MI2S_TX port\n");
  1122. clear_bit(STATUS_PORT_STARTED,
  1123. mi2s_dai_data->tx_dai.mi2s_dai_data.status_mask);
  1124. }
  1125. kfree(mi2s_dai_data);
  1126. snd_soc_unregister_dai(dai->dev);
  1127. return 0;
  1128. }
  1129. static int msm_dai_q6_dai_probe(struct snd_soc_dai *dai)
  1130. {
  1131. struct msm_dai_q6_dai_data *dai_data;
  1132. int rc = 0;
  1133. const struct snd_kcontrol_new *kcontrol;
  1134. dai_data = kzalloc(sizeof(struct msm_dai_q6_dai_data),
  1135. GFP_KERNEL);
  1136. if (!dai_data) {
  1137. dev_err(dai->dev, "DAI-%d: fail to allocate dai data\n",
  1138. dai->id);
  1139. rc = -ENOMEM;
  1140. } else
  1141. dev_set_drvdata(dai->dev, dai_data);
  1142. if (dai->id == SECONDARY_I2S_RX) {
  1143. kcontrol = &mi2s_config_controls[1];
  1144. rc = snd_ctl_add(dai->card->snd_card,
  1145. snd_ctl_new1(kcontrol, dai_data));
  1146. }
  1147. return rc;
  1148. }
  1149. static int msm_dai_q6_dai_remove(struct snd_soc_dai *dai)
  1150. {
  1151. struct msm_dai_q6_dai_data *dai_data;
  1152. int rc;
  1153. dai_data = dev_get_drvdata(dai->dev);
  1154. /* If AFE port is still up, close it */
  1155. if (test_bit(STATUS_PORT_STARTED, dai_data->status_mask)) {
  1156. switch (dai->id) {
  1157. case VOICE_PLAYBACK_TX:
  1158. case VOICE_RECORD_TX:
  1159. case VOICE_RECORD_RX:
  1160. pr_debug("%s, stop pseudo port:%d\n",
  1161. __func__, dai->id);
  1162. rc = afe_stop_pseudo_port(dai->id);
  1163. break;
  1164. default:
  1165. rc = afe_close(dai->id); /* can block */
  1166. }
  1167. if (IS_ERR_VALUE(rc))
  1168. dev_err(dai->dev, "fail to close AFE port\n");
  1169. clear_bit(STATUS_PORT_STARTED, dai_data->status_mask);
  1170. }
  1171. kfree(dai_data);
  1172. snd_soc_unregister_dai(dai->dev);
  1173. return 0;
  1174. }
  1175. static int msm_dai_q6_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  1176. {
  1177. int rc = 0;
  1178. dev_dbg(dai->dev, "enter %s, id = %d fmt[%d]\n", __func__,
  1179. dai->id, fmt);
  1180. switch (dai->id) {
  1181. case PRIMARY_I2S_TX:
  1182. case PRIMARY_I2S_RX:
  1183. case SECONDARY_I2S_RX:
  1184. case SECONDARY_I2S_TX:
  1185. rc = msm_dai_q6_cdc_set_fmt(dai, fmt);
  1186. break;
  1187. default:
  1188. dev_err(dai->dev, "invalid cpu_dai set_fmt\n");
  1189. rc = -EINVAL;
  1190. break;
  1191. }
  1192. return rc;
  1193. }
  1194. static int msm_dai_q6_set_channel_map(struct snd_soc_dai *dai,
  1195. unsigned int tx_num, unsigned int *tx_slot,
  1196. unsigned int rx_num, unsigned int *rx_slot)
  1197. {
  1198. int rc = 0;
  1199. struct msm_dai_q6_dai_data *dai_data = dev_get_drvdata(dai->dev);
  1200. unsigned int i = 0;
  1201. dev_dbg(dai->dev, "%s: dai_id = %d\n", __func__, dai->id);
  1202. switch (dai->id) {
  1203. case SLIMBUS_0_RX:
  1204. case SLIMBUS_1_RX:
  1205. case SLIMBUS_2_RX:
  1206. case SLIMBUS_3_RX:
  1207. case SLIMBUS_4_RX:
  1208. /* channel number to be between 128 and 255. For RX port
  1209. * use channel numbers from 138 to 144, for TX port
  1210. * use channel numbers from 128 to 137
  1211. * For ports between MDM-APQ use channel numbers from 145
  1212. */
  1213. if (!rx_slot)
  1214. return -EINVAL;
  1215. for (i = 0; i < rx_num; i++) {
  1216. dai_data->port_config.slim_sch.slave_ch_mapping[i] =
  1217. rx_slot[i];
  1218. pr_debug("%s: find number of channels[%d] ch[%d]\n",
  1219. __func__, i,
  1220. rx_slot[i]);
  1221. }
  1222. dai_data->port_config.slim_sch.num_channels = rx_num;
  1223. pr_debug("%s:SLIMBUS_%d_RX cnt[%d] ch[%d %d]\n", __func__,
  1224. (dai->id - SLIMBUS_0_RX) / 2,
  1225. rx_num, dai_data->port_config.slim_sch.slave_ch_mapping[0],
  1226. dai_data->port_config.slim_sch.slave_ch_mapping[1]);
  1227. break;
  1228. case SLIMBUS_0_TX:
  1229. case SLIMBUS_1_TX:
  1230. case SLIMBUS_2_TX:
  1231. case SLIMBUS_3_TX:
  1232. case SLIMBUS_4_TX:
  1233. /* channel number to be between 128 and 255. For RX port
  1234. * use channel numbers from 138 to 144, for TX port
  1235. * use channel numbers from 128 to 137
  1236. * For ports between MDM-APQ use channel numbers from 145
  1237. */
  1238. if (!tx_slot)
  1239. return -EINVAL;
  1240. for (i = 0; i < tx_num; i++) {
  1241. dai_data->port_config.slim_sch.slave_ch_mapping[i] =
  1242. tx_slot[i];
  1243. pr_debug("%s: find number of channels[%d] ch[%d]\n",
  1244. __func__, i, tx_slot[i]);
  1245. }
  1246. dai_data->port_config.slim_sch.num_channels = tx_num;
  1247. pr_debug("%s:SLIMBUS_%d_TX cnt[%d] ch[%d %d]\n", __func__,
  1248. (dai->id - SLIMBUS_0_TX) / 2,
  1249. tx_num, dai_data->port_config.slim_sch.slave_ch_mapping[0],
  1250. dai_data->port_config.slim_sch.slave_ch_mapping[1]);
  1251. break;
  1252. default:
  1253. dev_err(dai->dev, "invalid cpu_dai set_fmt\n");
  1254. rc = -EINVAL;
  1255. break;
  1256. }
  1257. return rc;
  1258. }
  1259. static struct snd_soc_dai_ops msm_dai_q6_mi2s_ops = {
  1260. .startup = msm_dai_q6_mi2s_startup,
  1261. .prepare = msm_dai_q6_mi2s_prepare,
  1262. .hw_params = msm_dai_q6_mi2s_hw_params,
  1263. .shutdown = msm_dai_q6_mi2s_shutdown,
  1264. .set_fmt = msm_dai_q6_mi2s_set_fmt,
  1265. };
  1266. static struct snd_soc_dai_ops msm_dai_q6_ops = {
  1267. .prepare = msm_dai_q6_prepare,
  1268. .hw_params = msm_dai_q6_hw_params,
  1269. .shutdown = msm_dai_q6_shutdown,
  1270. .set_fmt = msm_dai_q6_set_fmt,
  1271. .set_channel_map = msm_dai_q6_set_channel_map,
  1272. };
  1273. static struct snd_soc_dai_ops msm_dai_q6_auxpcm_ops = {
  1274. .prepare = msm_dai_q6_auxpcm_prepare,
  1275. .trigger = msm_dai_q6_auxpcm_trigger,
  1276. .hw_params = msm_dai_q6_auxpcm_hw_params,
  1277. .shutdown = msm_dai_q6_auxpcm_shutdown,
  1278. };
  1279. static struct snd_soc_dai_ops msm_dai_q6_sec_auxpcm_ops = {
  1280. .prepare = msm_dai_q6_sec_auxpcm_prepare,
  1281. .trigger = msm_dai_q6_auxpcm_trigger,
  1282. .hw_params = msm_dai_q6_sec_auxpcm_hw_params,
  1283. .shutdown = msm_dai_q6_sec_auxpcm_shutdown,
  1284. };
  1285. static struct snd_soc_dai_driver msm_dai_q6_i2s_rx_dai = {
  1286. .playback = {
  1287. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
  1288. SNDRV_PCM_RATE_16000,
  1289. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1290. .channels_min = 1,
  1291. .channels_max = 4,
  1292. .rate_min = 8000,
  1293. .rate_max = 48000,
  1294. },
  1295. .ops = &msm_dai_q6_ops,
  1296. .probe = msm_dai_q6_dai_probe,
  1297. .remove = msm_dai_q6_dai_remove,
  1298. };
  1299. static struct snd_soc_dai_driver msm_dai_q6_i2s_tx_dai = {
  1300. .capture = {
  1301. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
  1302. SNDRV_PCM_RATE_16000,
  1303. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1304. .channels_min = 1,
  1305. .channels_max = 2,
  1306. .rate_min = 8000,
  1307. .rate_max = 48000,
  1308. },
  1309. .ops = &msm_dai_q6_ops,
  1310. .probe = msm_dai_q6_dai_probe,
  1311. .remove = msm_dai_q6_dai_remove,
  1312. };
  1313. static struct snd_soc_dai_driver msm_dai_q6_afe_rx_dai = {
  1314. .playback = {
  1315. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
  1316. SNDRV_PCM_RATE_16000,
  1317. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1318. .channels_min = 1,
  1319. .channels_max = 2,
  1320. .rate_min = 8000,
  1321. .rate_max = 48000,
  1322. },
  1323. .ops = &msm_dai_q6_ops,
  1324. .probe = msm_dai_q6_dai_probe,
  1325. .remove = msm_dai_q6_dai_remove,
  1326. };
  1327. static struct snd_soc_dai_driver msm_dai_q6_afe_tx_dai = {
  1328. .capture = {
  1329. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
  1330. SNDRV_PCM_RATE_16000,
  1331. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1332. .channels_min = 1,
  1333. .channels_max = 4,
  1334. .rate_min = 8000,
  1335. .rate_max = 48000,
  1336. },
  1337. .ops = &msm_dai_q6_ops,
  1338. .probe = msm_dai_q6_dai_probe,
  1339. .remove = msm_dai_q6_dai_remove,
  1340. };
  1341. static struct snd_soc_dai_driver msm_dai_q6_voice_playback_tx_dai = {
  1342. .playback = {
  1343. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
  1344. SNDRV_PCM_RATE_16000,
  1345. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1346. .channels_min = 1,
  1347. .channels_max = 2,
  1348. .rate_max = 48000,
  1349. .rate_min = 8000,
  1350. },
  1351. .ops = &msm_dai_q6_ops,
  1352. .probe = msm_dai_q6_dai_probe,
  1353. .remove = msm_dai_q6_dai_remove,
  1354. };
  1355. static struct snd_soc_dai_driver msm_dai_q6_slimbus_rx_dai = {
  1356. .playback = {
  1357. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
  1358. SNDRV_PCM_RATE_16000,
  1359. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1360. .channels_min = 1,
  1361. .channels_max = 2,
  1362. .rate_min = 8000,
  1363. .rate_max = 48000,
  1364. },
  1365. .ops = &msm_dai_q6_ops,
  1366. .probe = msm_dai_q6_dai_probe,
  1367. .remove = msm_dai_q6_dai_remove,
  1368. };
  1369. static struct snd_soc_dai_driver msm_dai_q6_slimbus_tx_dai = {
  1370. .capture = {
  1371. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
  1372. SNDRV_PCM_RATE_16000,
  1373. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1374. .channels_min = 1,
  1375. .channels_max = 2,
  1376. .rate_min = 8000,
  1377. .rate_max = 48000,
  1378. },
  1379. .ops = &msm_dai_q6_ops,
  1380. .probe = msm_dai_q6_dai_probe,
  1381. .remove = msm_dai_q6_dai_remove,
  1382. };
  1383. static struct snd_soc_dai_driver msm_dai_q6_incall_record_dai = {
  1384. .capture = {
  1385. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
  1386. SNDRV_PCM_RATE_16000,
  1387. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1388. .channels_min = 1,
  1389. .channels_max = 2,
  1390. .rate_min = 8000,
  1391. .rate_max = 48000,
  1392. },
  1393. .ops = &msm_dai_q6_ops,
  1394. .probe = msm_dai_q6_dai_probe,
  1395. .remove = msm_dai_q6_dai_remove,
  1396. };
  1397. static struct snd_soc_dai_driver msm_dai_q6_bt_sco_rx_dai = {
  1398. .playback = {
  1399. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
  1400. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1401. .channels_min = 1,
  1402. .channels_max = 1,
  1403. .rate_max = 16000,
  1404. .rate_min = 8000,
  1405. },
  1406. .ops = &msm_dai_q6_ops,
  1407. .probe = msm_dai_q6_dai_probe,
  1408. .remove = msm_dai_q6_dai_remove,
  1409. };
  1410. static struct snd_soc_dai_driver msm_dai_q6_bt_sco_tx_dai = {
  1411. .capture = {
  1412. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
  1413. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1414. .channels_min = 1,
  1415. .channels_max = 1,
  1416. .rate_max = 16000,
  1417. .rate_min = 8000,
  1418. },
  1419. .ops = &msm_dai_q6_ops,
  1420. .probe = msm_dai_q6_dai_probe,
  1421. .remove = msm_dai_q6_dai_remove,
  1422. };
  1423. static struct snd_soc_dai_driver msm_dai_q6_fm_rx_dai = {
  1424. .playback = {
  1425. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
  1426. SNDRV_PCM_RATE_16000,
  1427. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1428. .channels_min = 2,
  1429. .channels_max = 2,
  1430. .rate_max = 48000,
  1431. .rate_min = 8000,
  1432. },
  1433. .ops = &msm_dai_q6_ops,
  1434. .probe = msm_dai_q6_dai_probe,
  1435. .remove = msm_dai_q6_dai_remove,
  1436. };
  1437. static struct snd_soc_dai_driver msm_dai_q6_fm_tx_dai = {
  1438. .capture = {
  1439. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
  1440. SNDRV_PCM_RATE_16000,
  1441. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1442. .channels_min = 2,
  1443. .channels_max = 2,
  1444. .rate_max = 48000,
  1445. .rate_min = 8000,
  1446. },
  1447. .ops = &msm_dai_q6_ops,
  1448. .probe = msm_dai_q6_dai_probe,
  1449. .remove = msm_dai_q6_dai_remove,
  1450. };
  1451. static struct snd_soc_dai_driver msm_dai_q6_aux_pcm_rx_dai = {
  1452. .playback = {
  1453. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
  1454. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1455. .channels_min = 1,
  1456. .channels_max = 1,
  1457. .rate_max = 16000,
  1458. .rate_min = 8000,
  1459. },
  1460. .ops = &msm_dai_q6_auxpcm_ops,
  1461. .probe = msm_dai_q6_dai_auxpcm_probe,
  1462. .remove = msm_dai_q6_dai_auxpcm_remove,
  1463. };
  1464. static struct snd_soc_dai_driver msm_dai_q6_aux_pcm_tx_dai = {
  1465. .capture = {
  1466. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
  1467. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1468. .channels_min = 1,
  1469. .channels_max = 1,
  1470. .rate_max = 16000,
  1471. .rate_min = 8000,
  1472. },
  1473. .ops = &msm_dai_q6_auxpcm_ops,
  1474. .probe = msm_dai_q6_dai_auxpcm_probe,
  1475. .remove = msm_dai_q6_dai_auxpcm_remove,
  1476. };
  1477. static struct snd_soc_dai_driver msm_dai_q6_sec_aux_pcm_rx_dai = {
  1478. .playback = {
  1479. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
  1480. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1481. .channels_min = 1,
  1482. .channels_max = 1,
  1483. .rate_max = 16000,
  1484. .rate_min = 8000,
  1485. },
  1486. .ops = &msm_dai_q6_sec_auxpcm_ops,
  1487. .probe = msm_dai_q6_dai_sec_auxpcm_probe,
  1488. .remove = msm_dai_q6_dai_sec_auxpcm_remove,
  1489. };
  1490. static struct snd_soc_dai_driver msm_dai_q6_sec_aux_pcm_tx_dai = {
  1491. .capture = {
  1492. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
  1493. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1494. .channels_min = 1,
  1495. .channels_max = 1,
  1496. .rate_max = 16000,
  1497. .rate_min = 8000,
  1498. },
  1499. .ops = &msm_dai_q6_sec_auxpcm_ops,
  1500. .probe = msm_dai_q6_dai_sec_auxpcm_probe,
  1501. .remove = msm_dai_q6_dai_sec_auxpcm_remove,
  1502. };
  1503. /* Channel min and max are initialized base on platform data */
  1504. static struct snd_soc_dai_driver msm_dai_q6_mi2s_dai = {
  1505. .playback = {
  1506. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
  1507. SNDRV_PCM_RATE_16000,
  1508. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1509. .rate_min = 8000,
  1510. .rate_max = 48000,
  1511. },
  1512. .capture = {
  1513. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
  1514. SNDRV_PCM_RATE_16000,
  1515. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1516. .rate_min = 8000,
  1517. .rate_max = 48000,
  1518. },
  1519. .ops = &msm_dai_q6_mi2s_ops,
  1520. .probe = msm_dai_q6_dai_mi2s_probe,
  1521. .remove = msm_dai_q6_dai_mi2s_remove,
  1522. };
  1523. static struct snd_soc_dai_driver msm_dai_q6_slimbus_1_rx_dai = {
  1524. .playback = {
  1525. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
  1526. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1527. .channels_min = 1,
  1528. .channels_max = 1,
  1529. .rate_min = 8000,
  1530. .rate_max = 16000,
  1531. },
  1532. .ops = &msm_dai_q6_ops,
  1533. .probe = msm_dai_q6_dai_probe,
  1534. .remove = msm_dai_q6_dai_remove,
  1535. };
  1536. static struct snd_soc_dai_driver msm_dai_q6_slimbus_1_tx_dai = {
  1537. .capture = {
  1538. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
  1539. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1540. .channels_min = 1,
  1541. .channels_max = 1,
  1542. .rate_min = 8000,
  1543. .rate_max = 16000,
  1544. },
  1545. .ops = &msm_dai_q6_ops,
  1546. .probe = msm_dai_q6_dai_probe,
  1547. .remove = msm_dai_q6_dai_remove,
  1548. };
  1549. static struct snd_soc_dai_driver msm_dai_q6_slimbus_2_rx_dai = {
  1550. .playback = {
  1551. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
  1552. SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
  1553. SNDRV_PCM_RATE_192000,
  1554. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1555. .channels_min = 1,
  1556. .channels_max = 2,
  1557. .rate_min = 8000,
  1558. .rate_max = 192000,
  1559. },
  1560. .ops = &msm_dai_q6_ops,
  1561. .probe = msm_dai_q6_dai_probe,
  1562. .remove = msm_dai_q6_dai_remove,
  1563. };
  1564. static struct snd_soc_dai_driver msm_dai_q6_slimbus_2_tx_dai = {
  1565. .capture = {
  1566. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
  1567. SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
  1568. SNDRV_PCM_RATE_192000,
  1569. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1570. .channels_min = 1,
  1571. .channels_max = 8,
  1572. .rate_min = 8000,
  1573. .rate_max = 192000,
  1574. },
  1575. .ops = &msm_dai_q6_ops,
  1576. .probe = msm_dai_q6_dai_probe,
  1577. .remove = msm_dai_q6_dai_remove,
  1578. };
  1579. static struct snd_soc_dai_driver msm_dai_q6_slimbus_3_rx_dai = {
  1580. .playback = {
  1581. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
  1582. SNDRV_PCM_RATE_48000,
  1583. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1584. .channels_min = 1,
  1585. .channels_max = 2,
  1586. .rate_min = 8000,
  1587. .rate_max = 48000,
  1588. },
  1589. .ops = &msm_dai_q6_ops,
  1590. .probe = msm_dai_q6_dai_probe,
  1591. .remove = msm_dai_q6_dai_remove,
  1592. };
  1593. static struct snd_soc_dai_driver msm_dai_q6_pseudo_dai = {
  1594. .playback = {
  1595. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
  1596. SNDRV_PCM_RATE_48000,
  1597. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1598. .channels_min = 1,
  1599. .channels_max = 6,
  1600. .rate_min = 8000,
  1601. .rate_max = 48000,
  1602. },
  1603. .ops = &msm_dai_q6_ops,
  1604. .probe = msm_dai_q6_dai_probe,
  1605. .remove = msm_dai_q6_dai_remove,
  1606. };
  1607. /* To do: change to register DAIs as batch */
  1608. static __devinit int msm_dai_q6_dev_probe(struct platform_device *pdev)
  1609. {
  1610. int rc = 0;
  1611. dev_dbg(&pdev->dev, "dev name %s\n", dev_name(&pdev->dev));
  1612. switch (pdev->id) {
  1613. case PRIMARY_I2S_RX:
  1614. case SECONDARY_I2S_RX:
  1615. rc = snd_soc_register_dai(&pdev->dev, &msm_dai_q6_i2s_rx_dai);
  1616. break;
  1617. case PRIMARY_I2S_TX:
  1618. case SECONDARY_I2S_TX:
  1619. rc = snd_soc_register_dai(&pdev->dev, &msm_dai_q6_i2s_tx_dai);
  1620. break;
  1621. case PCM_RX:
  1622. rc = snd_soc_register_dai(&pdev->dev,
  1623. &msm_dai_q6_aux_pcm_rx_dai);
  1624. break;
  1625. case PCM_TX:
  1626. rc = snd_soc_register_dai(&pdev->dev,
  1627. &msm_dai_q6_aux_pcm_tx_dai);
  1628. break;
  1629. case SECONDARY_PCM_RX:
  1630. rc = snd_soc_register_dai(&pdev->dev,
  1631. &msm_dai_q6_sec_aux_pcm_rx_dai);
  1632. break;
  1633. case SECONDARY_PCM_TX:
  1634. rc = snd_soc_register_dai(&pdev->dev,
  1635. &msm_dai_q6_sec_aux_pcm_tx_dai);
  1636. break;
  1637. case SLIMBUS_0_RX:
  1638. case SLIMBUS_4_RX:
  1639. rc = snd_soc_register_dai(&pdev->dev,
  1640. &msm_dai_q6_slimbus_rx_dai);
  1641. break;
  1642. case SLIMBUS_0_TX:
  1643. case SLIMBUS_4_TX:
  1644. case SLIMBUS_3_TX:
  1645. rc = snd_soc_register_dai(&pdev->dev,
  1646. &msm_dai_q6_slimbus_tx_dai);
  1647. break;
  1648. case SLIMBUS_1_RX:
  1649. rc = snd_soc_register_dai(&pdev->dev,
  1650. &msm_dai_q6_slimbus_1_rx_dai);
  1651. break;
  1652. case SLIMBUS_1_TX:
  1653. rc = snd_soc_register_dai(&pdev->dev,
  1654. &msm_dai_q6_slimbus_1_tx_dai);
  1655. break;
  1656. case SLIMBUS_2_RX:
  1657. rc = snd_soc_register_dai(&pdev->dev,
  1658. &msm_dai_q6_slimbus_2_rx_dai);
  1659. break;
  1660. case SLIMBUS_2_TX:
  1661. rc = snd_soc_register_dai(&pdev->dev,
  1662. &msm_dai_q6_slimbus_2_tx_dai);
  1663. break;
  1664. case SLIMBUS_3_RX:
  1665. rc = snd_soc_register_dai(&pdev->dev,
  1666. &msm_dai_q6_slimbus_3_rx_dai);
  1667. break;
  1668. case INT_BT_SCO_RX:
  1669. rc = snd_soc_register_dai(&pdev->dev,
  1670. &msm_dai_q6_bt_sco_rx_dai);
  1671. break;
  1672. case INT_BT_SCO_TX:
  1673. rc = snd_soc_register_dai(&pdev->dev,
  1674. &msm_dai_q6_bt_sco_tx_dai);
  1675. break;
  1676. case INT_FM_RX:
  1677. rc = snd_soc_register_dai(&pdev->dev, &msm_dai_q6_fm_rx_dai);
  1678. break;
  1679. case INT_FM_TX:
  1680. rc = snd_soc_register_dai(&pdev->dev, &msm_dai_q6_fm_tx_dai);
  1681. break;
  1682. case RT_PROXY_DAI_001_RX:
  1683. case RT_PROXY_DAI_002_RX:
  1684. rc = snd_soc_register_dai(&pdev->dev, &msm_dai_q6_afe_rx_dai);
  1685. break;
  1686. case RT_PROXY_DAI_001_TX:
  1687. case RT_PROXY_DAI_002_TX:
  1688. rc = snd_soc_register_dai(&pdev->dev, &msm_dai_q6_afe_tx_dai);
  1689. break;
  1690. case VOICE_PLAYBACK_TX:
  1691. rc = snd_soc_register_dai(&pdev->dev,
  1692. &msm_dai_q6_voice_playback_tx_dai);
  1693. break;
  1694. case VOICE_RECORD_RX:
  1695. case VOICE_RECORD_TX:
  1696. rc = snd_soc_register_dai(&pdev->dev,
  1697. &msm_dai_q6_incall_record_dai);
  1698. break;
  1699. case PSEUDOPORT_01:
  1700. rc = snd_soc_register_dai(&pdev->dev,
  1701. &msm_dai_q6_pseudo_dai);
  1702. break;
  1703. default:
  1704. rc = -ENODEV;
  1705. break;
  1706. }
  1707. return rc;
  1708. }
  1709. static __devexit int msm_dai_q6_dev_remove(struct platform_device *pdev)
  1710. {
  1711. snd_soc_unregister_dai(&pdev->dev);
  1712. return 0;
  1713. }
  1714. static __devinit int msm_dai_q6_mi2s_dev_probe(struct platform_device *pdev)
  1715. {
  1716. struct msm_dai_q6_mi2s_dai_data *dai_data;
  1717. int rc = 0;
  1718. dev_dbg(&pdev->dev, "%s: pdev %p dev %p\n", __func__, pdev, &pdev->dev);
  1719. dai_data = kzalloc(sizeof(struct msm_dai_q6_mi2s_dai_data),
  1720. GFP_KERNEL);
  1721. if (!dai_data) {
  1722. dev_err(&pdev->dev, "fail to allocate dai data\n");
  1723. rc = -ENOMEM;
  1724. goto rtn;
  1725. } else
  1726. dev_set_drvdata(&pdev->dev, dai_data);
  1727. rc = msm_dai_q6_mi2s_platform_data_validation(pdev,
  1728. &msm_dai_q6_mi2s_dai);
  1729. if (IS_ERR_VALUE(rc))
  1730. goto err_pdata;
  1731. dai_data->rate_constraint.count = 1;
  1732. dai_data->bitwidth_constraint.count = 1;
  1733. rc = snd_soc_register_dai(&pdev->dev, &msm_dai_q6_mi2s_dai);
  1734. if (IS_ERR_VALUE(rc))
  1735. goto err_pdata;
  1736. return 0;
  1737. err_pdata:
  1738. dev_err(&pdev->dev, "fail to msm_dai_q6_mi2s_dev_probe\n");
  1739. kfree(dai_data);
  1740. rtn:
  1741. return rc;
  1742. }
  1743. static __devexit int msm_dai_q6_mi2s_dev_remove(struct platform_device *pdev)
  1744. {
  1745. snd_soc_unregister_dai(&pdev->dev);
  1746. return 0;
  1747. }
  1748. static struct platform_driver msm_dai_q6_driver = {
  1749. .probe = msm_dai_q6_dev_probe,
  1750. .remove = msm_dai_q6_dev_remove,
  1751. .driver = {
  1752. .name = "msm-dai-q6",
  1753. .owner = THIS_MODULE,
  1754. },
  1755. };
  1756. static struct platform_driver msm_dai_q6_mi2s_driver = {
  1757. .probe = msm_dai_q6_mi2s_dev_probe,
  1758. .remove = msm_dai_q6_mi2s_dev_remove,
  1759. .driver = {
  1760. .name = "msm-dai-q6-mi2s",
  1761. .owner = THIS_MODULE,
  1762. },
  1763. };
  1764. static int __init msm_dai_q6_init(void)
  1765. {
  1766. int rc1, rc2;
  1767. rc1 = platform_driver_register(&msm_dai_q6_mi2s_driver);
  1768. if (IS_ERR_VALUE(rc1))
  1769. pr_err("%s: fail to register mi2s dai driver\n", __func__);
  1770. rc2 = platform_driver_register(&msm_dai_q6_driver);
  1771. if (IS_ERR_VALUE(rc2))
  1772. pr_err("%s: fail to register mi2s dai driver\n", __func__);
  1773. return (IS_ERR_VALUE(rc1) && IS_ERR_VALUE(rc2)) ? -1 : 0;
  1774. }
  1775. module_init(msm_dai_q6_init);
  1776. static void __exit msm_dai_q6_exit(void)
  1777. {
  1778. platform_driver_unregister(&msm_dai_q6_driver);
  1779. }
  1780. module_exit(msm_dai_q6_exit);
  1781. /* Module information */
  1782. MODULE_DESCRIPTION("MSM DSP DAI driver");
  1783. MODULE_LICENSE("GPL v2");