sst-atom-controls.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565
  1. /*
  2. * sst-atom-controls.c - Intel MID Platform driver DPCM ALSA controls for Mrfld
  3. *
  4. * Copyright (C) 2013-14 Intel Corp
  5. * Author: Omair Mohammed Abdullah <omair.m.abdullah@intel.com>
  6. * Vinod Koul <vinod.koul@intel.com>
  7. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; version 2 of the License.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * In the dpcm driver modelling when a particular FE/BE/Mixer/Pipe is active
  19. * we forward the settings and parameters, rest we keep the values in
  20. * driver and forward when DAPM enables them
  21. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  22. */
  23. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  24. #include <linux/slab.h>
  25. #include <sound/soc.h>
  26. #include <sound/tlv.h>
  27. #include "sst-mfld-platform.h"
  28. #include "sst-atom-controls.h"
  29. static int sst_fill_byte_control(struct sst_data *drv,
  30. u8 ipc_msg, u8 block,
  31. u8 task_id, u8 pipe_id,
  32. u16 len, void *cmd_data)
  33. {
  34. struct snd_sst_bytes_v2 *byte_data = drv->byte_stream;
  35. byte_data->type = SST_CMD_BYTES_SET;
  36. byte_data->ipc_msg = ipc_msg;
  37. byte_data->block = block;
  38. byte_data->task_id = task_id;
  39. byte_data->pipe_id = pipe_id;
  40. if (len > SST_MAX_BIN_BYTES - sizeof(*byte_data)) {
  41. dev_err(&drv->pdev->dev, "command length too big (%u)", len);
  42. return -EINVAL;
  43. }
  44. byte_data->len = len;
  45. memcpy(byte_data->bytes, cmd_data, len);
  46. print_hex_dump_bytes("writing to lpe: ", DUMP_PREFIX_OFFSET,
  47. byte_data, len + sizeof(*byte_data));
  48. return 0;
  49. }
  50. static int sst_fill_and_send_cmd_unlocked(struct sst_data *drv,
  51. u8 ipc_msg, u8 block, u8 task_id, u8 pipe_id,
  52. void *cmd_data, u16 len)
  53. {
  54. int ret = 0;
  55. ret = sst_fill_byte_control(drv, ipc_msg,
  56. block, task_id, pipe_id, len, cmd_data);
  57. if (ret < 0)
  58. return ret;
  59. return sst->ops->send_byte_stream(sst->dev, drv->byte_stream);
  60. }
  61. /**
  62. * sst_fill_and_send_cmd - generate the IPC message and send it to the FW
  63. * @ipc_msg: type of IPC (CMD, SET_PARAMS, GET_PARAMS)
  64. * @cmd_data: the IPC payload
  65. */
  66. static int sst_fill_and_send_cmd(struct sst_data *drv,
  67. u8 ipc_msg, u8 block, u8 task_id, u8 pipe_id,
  68. void *cmd_data, u16 len)
  69. {
  70. int ret;
  71. mutex_lock(&drv->lock);
  72. ret = sst_fill_and_send_cmd_unlocked(drv, ipc_msg, block,
  73. task_id, pipe_id, cmd_data, len);
  74. mutex_unlock(&drv->lock);
  75. return ret;
  76. }
  77. /**
  78. * tx map value is a bitfield where each bit represents a FW channel
  79. *
  80. * 3 2 1 0 # 0 = codec0, 1 = codec1
  81. * RLRLRLRL # 3, 4 = reserved
  82. *
  83. * e.g. slot 0 rx map = 00001100b -> data from slot 0 goes into codec_in1 L,R
  84. */
  85. static u8 sst_ssp_tx_map[SST_MAX_TDM_SLOTS] = {
  86. 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, /* default rx map */
  87. };
  88. /**
  89. * rx map value is a bitfield where each bit represents a slot
  90. *
  91. * 76543210 # 0 = slot 0, 1 = slot 1
  92. *
  93. * e.g. codec1_0 tx map = 00000101b -> data from codec_out1_0 goes into slot 0, 2
  94. */
  95. static u8 sst_ssp_rx_map[SST_MAX_TDM_SLOTS] = {
  96. 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, /* default tx map */
  97. };
  98. /**
  99. * NOTE: this is invoked with lock held
  100. */
  101. static int sst_send_slot_map(struct sst_data *drv)
  102. {
  103. struct sst_param_sba_ssp_slot_map cmd;
  104. SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
  105. cmd.header.command_id = SBA_SET_SSP_SLOT_MAP;
  106. cmd.header.length = sizeof(struct sst_param_sba_ssp_slot_map)
  107. - sizeof(struct sst_dsp_header);
  108. cmd.param_id = SBA_SET_SSP_SLOT_MAP;
  109. cmd.param_len = sizeof(cmd.rx_slot_map) + sizeof(cmd.tx_slot_map)
  110. + sizeof(cmd.ssp_index);
  111. cmd.ssp_index = SSP_CODEC;
  112. memcpy(cmd.rx_slot_map, &sst_ssp_tx_map[0], sizeof(cmd.rx_slot_map));
  113. memcpy(cmd.tx_slot_map, &sst_ssp_rx_map[0], sizeof(cmd.tx_slot_map));
  114. return sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_SET_PARAMS,
  115. SST_FLAG_BLOCKED, SST_TASK_SBA, 0, &cmd,
  116. sizeof(cmd.header) + cmd.header.length);
  117. }
  118. static int sst_slot_enum_info(struct snd_kcontrol *kcontrol,
  119. struct snd_ctl_elem_info *uinfo)
  120. {
  121. struct sst_enum *e = (struct sst_enum *)kcontrol->private_value;
  122. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  123. uinfo->count = 1;
  124. uinfo->value.enumerated.items = e->max;
  125. if (uinfo->value.enumerated.item > e->max - 1)
  126. uinfo->value.enumerated.item = e->max - 1;
  127. strcpy(uinfo->value.enumerated.name,
  128. e->texts[uinfo->value.enumerated.item]);
  129. return 0;
  130. }
  131. /**
  132. * sst_slot_get - get the status of the interleaver/deinterleaver control
  133. *
  134. * Searches the map where the control status is stored, and gets the
  135. * channel/slot which is currently set for this enumerated control. Since it is
  136. * an enumerated control, there is only one possible value.
  137. */
  138. static int sst_slot_get(struct snd_kcontrol *kcontrol,
  139. struct snd_ctl_elem_value *ucontrol)
  140. {
  141. struct sst_enum *e = (void *)kcontrol->private_value;
  142. struct snd_soc_component *c = snd_kcontrol_chip(kcontrol);
  143. struct sst_data *drv = snd_soc_component_get_drvdata(c);
  144. unsigned int ctl_no = e->reg;
  145. unsigned int is_tx = e->tx;
  146. unsigned int val, mux;
  147. u8 *map = is_tx ? sst_ssp_rx_map : sst_ssp_tx_map;
  148. mutex_lock(&drv->lock);
  149. val = 1 << ctl_no;
  150. /* search which slot/channel has this bit set - there should be only one */
  151. for (mux = e->max; mux > 0; mux--)
  152. if (map[mux - 1] & val)
  153. break;
  154. ucontrol->value.enumerated.item[0] = mux;
  155. mutex_unlock(&drv->lock);
  156. dev_dbg(c->dev, "%s - %s map = %#x\n",
  157. is_tx ? "tx channel" : "rx slot",
  158. e->texts[mux], mux ? map[mux - 1] : -1);
  159. return 0;
  160. }
  161. /* sst_check_and_send_slot_map - helper for checking power state and sending
  162. * slot map cmd
  163. *
  164. * called with lock held
  165. */
  166. static int sst_check_and_send_slot_map(struct sst_data *drv, struct snd_kcontrol *kcontrol)
  167. {
  168. struct sst_enum *e = (void *)kcontrol->private_value;
  169. int ret = 0;
  170. if (e->w && e->w->power)
  171. ret = sst_send_slot_map(drv);
  172. else if (!e->w)
  173. dev_err(&drv->pdev->dev, "Slot control: %s doesn't have DAPM widget!!!\n",
  174. kcontrol->id.name);
  175. return ret;
  176. }
  177. /**
  178. * sst_slot_put - set the status of interleaver/deinterleaver control
  179. *
  180. * (de)interleaver controls are defined in opposite sense to be user-friendly
  181. *
  182. * Instead of the enum value being the value written to the register, it is the
  183. * register address; and the kcontrol number (register num) is the value written
  184. * to the register. This is so that there can be only one value for each
  185. * slot/channel since there is only one control for each slot/channel.
  186. *
  187. * This means that whenever an enum is set, we need to clear the bit
  188. * for that kcontrol_no for all the interleaver OR deinterleaver registers
  189. */
  190. static int sst_slot_put(struct snd_kcontrol *kcontrol,
  191. struct snd_ctl_elem_value *ucontrol)
  192. {
  193. struct snd_soc_component *c = snd_soc_kcontrol_component(kcontrol);
  194. struct sst_data *drv = snd_soc_component_get_drvdata(c);
  195. struct sst_enum *e = (void *)kcontrol->private_value;
  196. int i, ret = 0;
  197. unsigned int ctl_no = e->reg;
  198. unsigned int is_tx = e->tx;
  199. unsigned int slot_channel_no;
  200. unsigned int val, mux;
  201. u8 *map;
  202. map = is_tx ? sst_ssp_rx_map : sst_ssp_tx_map;
  203. val = 1 << ctl_no;
  204. mux = ucontrol->value.enumerated.item[0];
  205. if (mux > e->max - 1)
  206. return -EINVAL;
  207. mutex_lock(&drv->lock);
  208. /* first clear all registers of this bit */
  209. for (i = 0; i < e->max; i++)
  210. map[i] &= ~val;
  211. if (mux == 0) {
  212. /* kctl set to 'none' and we reset the bits so send IPC */
  213. ret = sst_check_and_send_slot_map(drv, kcontrol);
  214. mutex_unlock(&drv->lock);
  215. return ret;
  216. }
  217. /* offset by one to take "None" into account */
  218. slot_channel_no = mux - 1;
  219. map[slot_channel_no] |= val;
  220. dev_dbg(c->dev, "%s %s map = %#x\n",
  221. is_tx ? "tx channel" : "rx slot",
  222. e->texts[mux], map[slot_channel_no]);
  223. ret = sst_check_and_send_slot_map(drv, kcontrol);
  224. mutex_unlock(&drv->lock);
  225. return ret;
  226. }
  227. static int sst_send_algo_cmd(struct sst_data *drv,
  228. struct sst_algo_control *bc)
  229. {
  230. int len, ret = 0;
  231. struct sst_cmd_set_params *cmd;
  232. /*bc->max includes sizeof algos + length field*/
  233. len = sizeof(cmd->dst) + sizeof(cmd->command_id) + bc->max;
  234. cmd = kzalloc(len, GFP_KERNEL);
  235. if (cmd == NULL)
  236. return -ENOMEM;
  237. SST_FILL_DESTINATION(2, cmd->dst, bc->pipe_id, bc->module_id);
  238. cmd->command_id = bc->cmd_id;
  239. memcpy(cmd->params, bc->params, bc->max);
  240. ret = sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_SET_PARAMS,
  241. SST_FLAG_BLOCKED, bc->task_id, 0, cmd, len);
  242. kfree(cmd);
  243. return ret;
  244. }
  245. /**
  246. * sst_find_and_send_pipe_algo - send all the algo parameters for a pipe
  247. *
  248. * The algos which are in each pipeline are sent to the firmware one by one
  249. *
  250. * Called with lock held
  251. */
  252. static int sst_find_and_send_pipe_algo(struct sst_data *drv,
  253. const char *pipe, struct sst_ids *ids)
  254. {
  255. int ret = 0;
  256. struct sst_algo_control *bc;
  257. struct sst_module *algo = NULL;
  258. dev_dbg(&drv->pdev->dev, "Enter: widget=%s\n", pipe);
  259. list_for_each_entry(algo, &ids->algo_list, node) {
  260. bc = (void *)algo->kctl->private_value;
  261. dev_dbg(&drv->pdev->dev, "Found algo control name=%s pipe=%s\n",
  262. algo->kctl->id.name, pipe);
  263. ret = sst_send_algo_cmd(drv, bc);
  264. if (ret)
  265. return ret;
  266. }
  267. return ret;
  268. }
  269. static int sst_algo_bytes_ctl_info(struct snd_kcontrol *kcontrol,
  270. struct snd_ctl_elem_info *uinfo)
  271. {
  272. struct sst_algo_control *bc = (void *)kcontrol->private_value;
  273. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  274. uinfo->count = bc->max;
  275. return 0;
  276. }
  277. static int sst_algo_control_get(struct snd_kcontrol *kcontrol,
  278. struct snd_ctl_elem_value *ucontrol)
  279. {
  280. struct sst_algo_control *bc = (void *)kcontrol->private_value;
  281. struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
  282. switch (bc->type) {
  283. case SST_ALGO_PARAMS:
  284. memcpy(ucontrol->value.bytes.data, bc->params, bc->max);
  285. break;
  286. default:
  287. dev_err(component->dev, "Invalid Input- algo type:%d\n",
  288. bc->type);
  289. return -EINVAL;
  290. }
  291. return 0;
  292. }
  293. static int sst_algo_control_set(struct snd_kcontrol *kcontrol,
  294. struct snd_ctl_elem_value *ucontrol)
  295. {
  296. int ret = 0;
  297. struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol);
  298. struct sst_data *drv = snd_soc_component_get_drvdata(cmpnt);
  299. struct sst_algo_control *bc = (void *)kcontrol->private_value;
  300. dev_dbg(cmpnt->dev, "control_name=%s\n", kcontrol->id.name);
  301. mutex_lock(&drv->lock);
  302. switch (bc->type) {
  303. case SST_ALGO_PARAMS:
  304. memcpy(bc->params, ucontrol->value.bytes.data, bc->max);
  305. break;
  306. default:
  307. mutex_unlock(&drv->lock);
  308. dev_err(cmpnt->dev, "Invalid Input- algo type:%d\n",
  309. bc->type);
  310. return -EINVAL;
  311. }
  312. /*if pipe is enabled, need to send the algo params from here*/
  313. if (bc->w && bc->w->power)
  314. ret = sst_send_algo_cmd(drv, bc);
  315. mutex_unlock(&drv->lock);
  316. return ret;
  317. }
  318. static int sst_gain_ctl_info(struct snd_kcontrol *kcontrol,
  319. struct snd_ctl_elem_info *uinfo)
  320. {
  321. struct sst_gain_mixer_control *mc = (void *)kcontrol->private_value;
  322. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  323. uinfo->count = mc->stereo ? 2 : 1;
  324. uinfo->value.integer.min = mc->min;
  325. uinfo->value.integer.max = mc->max;
  326. return 0;
  327. }
  328. /**
  329. * sst_send_gain_cmd - send the gain algorithm IPC to the FW
  330. * @gv: the stored value of gain (also contains rampduration)
  331. * @mute: flag that indicates whether this was called from the
  332. * digital_mute callback or directly. If called from the
  333. * digital_mute callback, module will be muted/unmuted based on this
  334. * flag. The flag is always 0 if called directly.
  335. *
  336. * Called with sst_data.lock held
  337. *
  338. * The user-set gain value is sent only if the user-controllable 'mute' control
  339. * is OFF (indicated by gv->mute). Otherwise, the mute value (MIN value) is
  340. * sent.
  341. */
  342. static int sst_send_gain_cmd(struct sst_data *drv, struct sst_gain_value *gv,
  343. u16 task_id, u16 loc_id, u16 module_id, int mute)
  344. {
  345. struct sst_cmd_set_gain_dual cmd;
  346. dev_dbg(&drv->pdev->dev, "Enter\n");
  347. cmd.header.command_id = MMX_SET_GAIN;
  348. SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
  349. cmd.gain_cell_num = 1;
  350. if (mute || gv->mute) {
  351. cmd.cell_gains[0].cell_gain_left = SST_GAIN_MIN_VALUE;
  352. cmd.cell_gains[0].cell_gain_right = SST_GAIN_MIN_VALUE;
  353. } else {
  354. cmd.cell_gains[0].cell_gain_left = gv->l_gain;
  355. cmd.cell_gains[0].cell_gain_right = gv->r_gain;
  356. }
  357. SST_FILL_DESTINATION(2, cmd.cell_gains[0].dest,
  358. loc_id, module_id);
  359. cmd.cell_gains[0].gain_time_constant = gv->ramp_duration;
  360. cmd.header.length = sizeof(struct sst_cmd_set_gain_dual)
  361. - sizeof(struct sst_dsp_header);
  362. /* we are with lock held, so call the unlocked api to send */
  363. return sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_SET_PARAMS,
  364. SST_FLAG_BLOCKED, task_id, 0, &cmd,
  365. sizeof(cmd.header) + cmd.header.length);
  366. }
  367. static int sst_gain_get(struct snd_kcontrol *kcontrol,
  368. struct snd_ctl_elem_value *ucontrol)
  369. {
  370. struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
  371. struct sst_gain_mixer_control *mc = (void *)kcontrol->private_value;
  372. struct sst_gain_value *gv = mc->gain_val;
  373. switch (mc->type) {
  374. case SST_GAIN_TLV:
  375. ucontrol->value.integer.value[0] = gv->l_gain;
  376. ucontrol->value.integer.value[1] = gv->r_gain;
  377. break;
  378. case SST_GAIN_MUTE:
  379. ucontrol->value.integer.value[0] = gv->mute ? 0 : 1;
  380. break;
  381. case SST_GAIN_RAMP_DURATION:
  382. ucontrol->value.integer.value[0] = gv->ramp_duration;
  383. break;
  384. default:
  385. dev_err(component->dev, "Invalid Input- gain type:%d\n",
  386. mc->type);
  387. return -EINVAL;
  388. }
  389. return 0;
  390. }
  391. static int sst_gain_put(struct snd_kcontrol *kcontrol,
  392. struct snd_ctl_elem_value *ucontrol)
  393. {
  394. int ret = 0;
  395. struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol);
  396. struct sst_data *drv = snd_soc_component_get_drvdata(cmpnt);
  397. struct sst_gain_mixer_control *mc = (void *)kcontrol->private_value;
  398. struct sst_gain_value *gv = mc->gain_val;
  399. mutex_lock(&drv->lock);
  400. switch (mc->type) {
  401. case SST_GAIN_TLV:
  402. gv->l_gain = ucontrol->value.integer.value[0];
  403. gv->r_gain = ucontrol->value.integer.value[1];
  404. dev_dbg(cmpnt->dev, "%s: Volume %d, %d\n",
  405. mc->pname, gv->l_gain, gv->r_gain);
  406. break;
  407. case SST_GAIN_MUTE:
  408. gv->mute = !ucontrol->value.integer.value[0];
  409. dev_dbg(cmpnt->dev, "%s: Mute %d\n", mc->pname, gv->mute);
  410. break;
  411. case SST_GAIN_RAMP_DURATION:
  412. gv->ramp_duration = ucontrol->value.integer.value[0];
  413. dev_dbg(cmpnt->dev, "%s: Ramp Delay%d\n",
  414. mc->pname, gv->ramp_duration);
  415. break;
  416. default:
  417. mutex_unlock(&drv->lock);
  418. dev_err(cmpnt->dev, "Invalid Input- gain type:%d\n",
  419. mc->type);
  420. return -EINVAL;
  421. }
  422. if (mc->w && mc->w->power)
  423. ret = sst_send_gain_cmd(drv, gv, mc->task_id,
  424. mc->pipe_id | mc->instance_id, mc->module_id, 0);
  425. mutex_unlock(&drv->lock);
  426. return ret;
  427. }
  428. static int sst_set_pipe_gain(struct sst_ids *ids,
  429. struct sst_data *drv, int mute);
  430. static int sst_send_pipe_module_params(struct snd_soc_dapm_widget *w,
  431. struct snd_kcontrol *kcontrol)
  432. {
  433. struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
  434. struct sst_data *drv = snd_soc_component_get_drvdata(c);
  435. struct sst_ids *ids = w->priv;
  436. mutex_lock(&drv->lock);
  437. sst_find_and_send_pipe_algo(drv, w->name, ids);
  438. sst_set_pipe_gain(ids, drv, 0);
  439. mutex_unlock(&drv->lock);
  440. return 0;
  441. }
  442. static int sst_generic_modules_event(struct snd_soc_dapm_widget *w,
  443. struct snd_kcontrol *k, int event)
  444. {
  445. if (SND_SOC_DAPM_EVENT_ON(event))
  446. return sst_send_pipe_module_params(w, k);
  447. return 0;
  448. }
  449. static const DECLARE_TLV_DB_SCALE(sst_gain_tlv_common, SST_GAIN_MIN_VALUE * 10, 10, 0);
  450. /* Look up table to convert MIXER SW bit regs to SWM inputs */
  451. static const uint swm_mixer_input_ids[SST_SWM_INPUT_COUNT] = {
  452. [SST_IP_MODEM] = SST_SWM_IN_MODEM,
  453. [SST_IP_CODEC0] = SST_SWM_IN_CODEC0,
  454. [SST_IP_CODEC1] = SST_SWM_IN_CODEC1,
  455. [SST_IP_LOOP0] = SST_SWM_IN_SPROT_LOOP,
  456. [SST_IP_LOOP1] = SST_SWM_IN_MEDIA_LOOP1,
  457. [SST_IP_LOOP2] = SST_SWM_IN_MEDIA_LOOP2,
  458. [SST_IP_PCM0] = SST_SWM_IN_PCM0,
  459. [SST_IP_PCM1] = SST_SWM_IN_PCM1,
  460. [SST_IP_MEDIA0] = SST_SWM_IN_MEDIA0,
  461. [SST_IP_MEDIA1] = SST_SWM_IN_MEDIA1,
  462. [SST_IP_MEDIA2] = SST_SWM_IN_MEDIA2,
  463. [SST_IP_MEDIA3] = SST_SWM_IN_MEDIA3,
  464. };
  465. /**
  466. * fill_swm_input - fill in the SWM input ids given the register
  467. *
  468. * The register value is a bit-field inicated which mixer inputs are ON. Use the
  469. * lookup table to get the input-id and fill it in the structure.
  470. */
  471. static int fill_swm_input(struct snd_soc_component *cmpnt,
  472. struct swm_input_ids *swm_input, unsigned int reg)
  473. {
  474. uint i, is_set, nb_inputs = 0;
  475. u16 input_loc_id;
  476. dev_dbg(cmpnt->dev, "reg: %#x\n", reg);
  477. for (i = 0; i < SST_SWM_INPUT_COUNT; i++) {
  478. is_set = reg & BIT(i);
  479. if (!is_set)
  480. continue;
  481. input_loc_id = swm_mixer_input_ids[i];
  482. SST_FILL_DESTINATION(2, swm_input->input_id,
  483. input_loc_id, SST_DEFAULT_MODULE_ID);
  484. nb_inputs++;
  485. swm_input++;
  486. dev_dbg(cmpnt->dev, "input id: %#x, nb_inputs: %d\n",
  487. input_loc_id, nb_inputs);
  488. if (nb_inputs == SST_CMD_SWM_MAX_INPUTS) {
  489. dev_warn(cmpnt->dev, "SET_SWM cmd max inputs reached");
  490. break;
  491. }
  492. }
  493. return nb_inputs;
  494. }
  495. /**
  496. * called with lock held
  497. */
  498. static int sst_set_pipe_gain(struct sst_ids *ids,
  499. struct sst_data *drv, int mute)
  500. {
  501. int ret = 0;
  502. struct sst_gain_mixer_control *mc;
  503. struct sst_gain_value *gv;
  504. struct sst_module *gain = NULL;
  505. list_for_each_entry(gain, &ids->gain_list, node) {
  506. struct snd_kcontrol *kctl = gain->kctl;
  507. dev_dbg(&drv->pdev->dev, "control name=%s\n", kctl->id.name);
  508. mc = (void *)kctl->private_value;
  509. gv = mc->gain_val;
  510. ret = sst_send_gain_cmd(drv, gv, mc->task_id,
  511. mc->pipe_id | mc->instance_id, mc->module_id, mute);
  512. if (ret)
  513. return ret;
  514. }
  515. return ret;
  516. }
  517. static int sst_swm_mixer_event(struct snd_soc_dapm_widget *w,
  518. struct snd_kcontrol *k, int event)
  519. {
  520. struct sst_cmd_set_swm cmd;
  521. struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
  522. struct sst_data *drv = snd_soc_component_get_drvdata(cmpnt);
  523. struct sst_ids *ids = w->priv;
  524. bool set_mixer = false;
  525. struct soc_mixer_control *mc;
  526. int val = 0;
  527. int i = 0;
  528. dev_dbg(cmpnt->dev, "widget = %s\n", w->name);
  529. /*
  530. * Identify which mixer input is on and send the bitmap of the
  531. * inputs as an IPC to the DSP.
  532. */
  533. for (i = 0; i < w->num_kcontrols; i++) {
  534. if (dapm_kcontrol_get_value(w->kcontrols[i])) {
  535. mc = (struct soc_mixer_control *)(w->kcontrols[i])->private_value;
  536. val |= 1 << mc->shift;
  537. }
  538. }
  539. dev_dbg(cmpnt->dev, "val = %#x\n", val);
  540. switch (event) {
  541. case SND_SOC_DAPM_PRE_PMU:
  542. case SND_SOC_DAPM_POST_PMD:
  543. set_mixer = true;
  544. break;
  545. case SND_SOC_DAPM_POST_REG:
  546. if (w->power)
  547. set_mixer = true;
  548. break;
  549. default:
  550. set_mixer = false;
  551. }
  552. if (set_mixer == false)
  553. return 0;
  554. if (SND_SOC_DAPM_EVENT_ON(event) ||
  555. event == SND_SOC_DAPM_POST_REG)
  556. cmd.switch_state = SST_SWM_ON;
  557. else
  558. cmd.switch_state = SST_SWM_OFF;
  559. SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
  560. /* MMX_SET_SWM == SBA_SET_SWM */
  561. cmd.header.command_id = SBA_SET_SWM;
  562. SST_FILL_DESTINATION(2, cmd.output_id,
  563. ids->location_id, SST_DEFAULT_MODULE_ID);
  564. cmd.nb_inputs = fill_swm_input(cmpnt, &cmd.input[0], val);
  565. cmd.header.length = offsetof(struct sst_cmd_set_swm, input)
  566. - sizeof(struct sst_dsp_header)
  567. + (cmd.nb_inputs * sizeof(cmd.input[0]));
  568. return sst_fill_and_send_cmd(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
  569. ids->task_id, 0, &cmd,
  570. sizeof(cmd.header) + cmd.header.length);
  571. }
  572. /* SBA mixers - 16 inputs */
  573. #define SST_SBA_DECLARE_MIX_CONTROLS(kctl_name) \
  574. static const struct snd_kcontrol_new kctl_name[] = { \
  575. SOC_DAPM_SINGLE("modem_in Switch", SND_SOC_NOPM, SST_IP_MODEM, 1, 0), \
  576. SOC_DAPM_SINGLE("codec_in0 Switch", SND_SOC_NOPM, SST_IP_CODEC0, 1, 0), \
  577. SOC_DAPM_SINGLE("codec_in1 Switch", SND_SOC_NOPM, SST_IP_CODEC1, 1, 0), \
  578. SOC_DAPM_SINGLE("sprot_loop_in Switch", SND_SOC_NOPM, SST_IP_LOOP0, 1, 0), \
  579. SOC_DAPM_SINGLE("media_loop1_in Switch", SND_SOC_NOPM, SST_IP_LOOP1, 1, 0), \
  580. SOC_DAPM_SINGLE("media_loop2_in Switch", SND_SOC_NOPM, SST_IP_LOOP2, 1, 0), \
  581. SOC_DAPM_SINGLE("pcm0_in Switch", SND_SOC_NOPM, SST_IP_PCM0, 1, 0), \
  582. SOC_DAPM_SINGLE("pcm1_in Switch", SND_SOC_NOPM, SST_IP_PCM1, 1, 0), \
  583. }
  584. #define SST_SBA_MIXER_GRAPH_MAP(mix_name) \
  585. { mix_name, "modem_in Switch", "modem_in" }, \
  586. { mix_name, "codec_in0 Switch", "codec_in0" }, \
  587. { mix_name, "codec_in1 Switch", "codec_in1" }, \
  588. { mix_name, "sprot_loop_in Switch", "sprot_loop_in" }, \
  589. { mix_name, "media_loop1_in Switch", "media_loop1_in" }, \
  590. { mix_name, "media_loop2_in Switch", "media_loop2_in" }, \
  591. { mix_name, "pcm0_in Switch", "pcm0_in" }, \
  592. { mix_name, "pcm1_in Switch", "pcm1_in" }
  593. #define SST_MMX_DECLARE_MIX_CONTROLS(kctl_name) \
  594. static const struct snd_kcontrol_new kctl_name[] = { \
  595. SOC_DAPM_SINGLE("media0_in Switch", SND_SOC_NOPM, SST_IP_MEDIA0, 1, 0), \
  596. SOC_DAPM_SINGLE("media1_in Switch", SND_SOC_NOPM, SST_IP_MEDIA1, 1, 0), \
  597. SOC_DAPM_SINGLE("media2_in Switch", SND_SOC_NOPM, SST_IP_MEDIA2, 1, 0), \
  598. SOC_DAPM_SINGLE("media3_in Switch", SND_SOC_NOPM, SST_IP_MEDIA3, 1, 0), \
  599. }
  600. SST_MMX_DECLARE_MIX_CONTROLS(sst_mix_media0_controls);
  601. SST_MMX_DECLARE_MIX_CONTROLS(sst_mix_media1_controls);
  602. /* 18 SBA mixers */
  603. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_pcm0_controls);
  604. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_pcm1_controls);
  605. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_pcm2_controls);
  606. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_sprot_l0_controls);
  607. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_media_l1_controls);
  608. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_media_l2_controls);
  609. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_voip_controls);
  610. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_codec0_controls);
  611. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_codec1_controls);
  612. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_modem_controls);
  613. /*
  614. * sst_handle_vb_timer - Start/Stop the DSP scheduler
  615. *
  616. * The DSP expects first cmd to be SBA_VB_START, so at first startup send
  617. * that.
  618. * DSP expects last cmd to be SBA_VB_IDLE, so at last shutdown send that.
  619. *
  620. * Do refcount internally so that we send command only at first start
  621. * and last end. Since SST driver does its own ref count, invoke sst's
  622. * power ops always!
  623. */
  624. int sst_handle_vb_timer(struct snd_soc_dai *dai, bool enable)
  625. {
  626. int ret = 0;
  627. struct sst_cmd_generic cmd;
  628. struct sst_data *drv = snd_soc_dai_get_drvdata(dai);
  629. static int timer_usage;
  630. if (enable)
  631. cmd.header.command_id = SBA_VB_START;
  632. else
  633. cmd.header.command_id = SBA_IDLE;
  634. dev_dbg(dai->dev, "enable=%u, usage=%d\n", enable, timer_usage);
  635. SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
  636. cmd.header.length = 0;
  637. if (enable) {
  638. ret = sst->ops->power(sst->dev, true);
  639. if (ret < 0)
  640. return ret;
  641. }
  642. mutex_lock(&drv->lock);
  643. if (enable)
  644. timer_usage++;
  645. else
  646. timer_usage--;
  647. /*
  648. * Send the command only if this call is the first enable or last
  649. * disable
  650. */
  651. if ((enable && (timer_usage == 1)) ||
  652. (!enable && (timer_usage == 0))) {
  653. ret = sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_CMD,
  654. SST_FLAG_BLOCKED, SST_TASK_SBA, 0, &cmd,
  655. sizeof(cmd.header) + cmd.header.length);
  656. if (ret && enable) {
  657. timer_usage--;
  658. enable = false;
  659. }
  660. }
  661. mutex_unlock(&drv->lock);
  662. if (!enable)
  663. sst->ops->power(sst->dev, false);
  664. return ret;
  665. }
  666. int sst_fill_ssp_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
  667. unsigned int rx_mask, int slots, int slot_width)
  668. {
  669. struct sst_data *ctx = snd_soc_dai_get_drvdata(dai);
  670. ctx->ssp_cmd.nb_slots = slots;
  671. ctx->ssp_cmd.active_tx_slot_map = tx_mask;
  672. ctx->ssp_cmd.active_rx_slot_map = rx_mask;
  673. ctx->ssp_cmd.nb_bits_per_slots = slot_width;
  674. return 0;
  675. }
  676. static int sst_get_frame_sync_polarity(struct snd_soc_dai *dai,
  677. unsigned int fmt)
  678. {
  679. int format;
  680. format = fmt & SND_SOC_DAIFMT_INV_MASK;
  681. dev_dbg(dai->dev, "Enter:%s, format=%x\n", __func__, format);
  682. switch (format) {
  683. case SND_SOC_DAIFMT_NB_NF:
  684. return SSP_FS_ACTIVE_LOW;
  685. case SND_SOC_DAIFMT_NB_IF:
  686. return SSP_FS_ACTIVE_HIGH;
  687. case SND_SOC_DAIFMT_IB_IF:
  688. return SSP_FS_ACTIVE_LOW;
  689. case SND_SOC_DAIFMT_IB_NF:
  690. return SSP_FS_ACTIVE_HIGH;
  691. default:
  692. dev_err(dai->dev, "Invalid frame sync polarity %d\n", format);
  693. }
  694. return -EINVAL;
  695. }
  696. static int sst_get_ssp_mode(struct snd_soc_dai *dai, unsigned int fmt)
  697. {
  698. int format;
  699. format = (fmt & SND_SOC_DAIFMT_MASTER_MASK);
  700. dev_dbg(dai->dev, "Enter:%s, format=%x\n", __func__, format);
  701. switch (format) {
  702. case SND_SOC_DAIFMT_CBS_CFS:
  703. return SSP_MODE_MASTER;
  704. case SND_SOC_DAIFMT_CBM_CFM:
  705. return SSP_MODE_SLAVE;
  706. default:
  707. dev_err(dai->dev, "Invalid ssp protocol: %d\n", format);
  708. }
  709. return -EINVAL;
  710. }
  711. int sst_fill_ssp_config(struct snd_soc_dai *dai, unsigned int fmt)
  712. {
  713. unsigned int mode;
  714. int fs_polarity;
  715. struct sst_data *ctx = snd_soc_dai_get_drvdata(dai);
  716. mode = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
  717. switch (mode) {
  718. case SND_SOC_DAIFMT_DSP_B:
  719. ctx->ssp_cmd.ssp_protocol = SSP_MODE_PCM;
  720. ctx->ssp_cmd.mode = sst_get_ssp_mode(dai, fmt) | (SSP_PCM_MODE_NETWORK << 1);
  721. ctx->ssp_cmd.start_delay = 0;
  722. ctx->ssp_cmd.data_polarity = 1;
  723. ctx->ssp_cmd.frame_sync_width = 1;
  724. break;
  725. case SND_SOC_DAIFMT_DSP_A:
  726. ctx->ssp_cmd.ssp_protocol = SSP_MODE_PCM;
  727. ctx->ssp_cmd.mode = sst_get_ssp_mode(dai, fmt) | (SSP_PCM_MODE_NETWORK << 1);
  728. ctx->ssp_cmd.start_delay = 1;
  729. ctx->ssp_cmd.data_polarity = 1;
  730. ctx->ssp_cmd.frame_sync_width = 1;
  731. break;
  732. case SND_SOC_DAIFMT_I2S:
  733. ctx->ssp_cmd.ssp_protocol = SSP_MODE_I2S;
  734. ctx->ssp_cmd.mode = sst_get_ssp_mode(dai, fmt) | (SSP_PCM_MODE_NORMAL << 1);
  735. ctx->ssp_cmd.start_delay = 1;
  736. ctx->ssp_cmd.data_polarity = 0;
  737. ctx->ssp_cmd.frame_sync_width = ctx->ssp_cmd.nb_bits_per_slots;
  738. break;
  739. case SND_SOC_DAIFMT_LEFT_J:
  740. ctx->ssp_cmd.ssp_protocol = SSP_MODE_I2S;
  741. ctx->ssp_cmd.mode = sst_get_ssp_mode(dai, fmt) | (SSP_PCM_MODE_NORMAL << 1);
  742. ctx->ssp_cmd.start_delay = 0;
  743. ctx->ssp_cmd.data_polarity = 0;
  744. ctx->ssp_cmd.frame_sync_width = ctx->ssp_cmd.nb_bits_per_slots;
  745. break;
  746. default:
  747. dev_dbg(dai->dev, "using default ssp configs\n");
  748. }
  749. fs_polarity = sst_get_frame_sync_polarity(dai, fmt);
  750. if (fs_polarity < 0)
  751. return fs_polarity;
  752. ctx->ssp_cmd.frame_sync_polarity = fs_polarity;
  753. return 0;
  754. }
  755. /**
  756. * sst_ssp_config - contains SSP configuration for media UC
  757. * this can be overwritten by set_dai_xxx APIs
  758. */
  759. static const struct sst_ssp_config sst_ssp_configs = {
  760. .ssp_id = SSP_CODEC,
  761. .bits_per_slot = 24,
  762. .slots = 4,
  763. .ssp_mode = SSP_MODE_MASTER,
  764. .pcm_mode = SSP_PCM_MODE_NETWORK,
  765. .duplex = SSP_DUPLEX,
  766. .ssp_protocol = SSP_MODE_PCM,
  767. .fs_width = 1,
  768. .fs_frequency = SSP_FS_48_KHZ,
  769. .active_slot_map = 0xF,
  770. .start_delay = 0,
  771. .frame_sync_polarity = SSP_FS_ACTIVE_HIGH,
  772. .data_polarity = 1,
  773. };
  774. void sst_fill_ssp_defaults(struct snd_soc_dai *dai)
  775. {
  776. const struct sst_ssp_config *config;
  777. struct sst_data *ctx = snd_soc_dai_get_drvdata(dai);
  778. config = &sst_ssp_configs;
  779. ctx->ssp_cmd.selection = config->ssp_id;
  780. ctx->ssp_cmd.nb_bits_per_slots = config->bits_per_slot;
  781. ctx->ssp_cmd.nb_slots = config->slots;
  782. ctx->ssp_cmd.mode = config->ssp_mode | (config->pcm_mode << 1);
  783. ctx->ssp_cmd.duplex = config->duplex;
  784. ctx->ssp_cmd.active_tx_slot_map = config->active_slot_map;
  785. ctx->ssp_cmd.active_rx_slot_map = config->active_slot_map;
  786. ctx->ssp_cmd.frame_sync_frequency = config->fs_frequency;
  787. ctx->ssp_cmd.frame_sync_polarity = config->frame_sync_polarity;
  788. ctx->ssp_cmd.data_polarity = config->data_polarity;
  789. ctx->ssp_cmd.frame_sync_width = config->fs_width;
  790. ctx->ssp_cmd.ssp_protocol = config->ssp_protocol;
  791. ctx->ssp_cmd.start_delay = config->start_delay;
  792. ctx->ssp_cmd.reserved1 = ctx->ssp_cmd.reserved2 = 0xFF;
  793. }
  794. int send_ssp_cmd(struct snd_soc_dai *dai, const char *id, bool enable)
  795. {
  796. struct sst_data *drv = snd_soc_dai_get_drvdata(dai);
  797. int ssp_id;
  798. dev_info(dai->dev, "Enter: enable=%d port_name=%s\n", enable, id);
  799. if (strcmp(id, "ssp0-port") == 0)
  800. ssp_id = SSP_MODEM;
  801. else if (strcmp(id, "ssp2-port") == 0)
  802. ssp_id = SSP_CODEC;
  803. else {
  804. dev_dbg(dai->dev, "port %s is not supported\n", id);
  805. return -1;
  806. }
  807. SST_FILL_DEFAULT_DESTINATION(drv->ssp_cmd.header.dst);
  808. drv->ssp_cmd.header.command_id = SBA_HW_SET_SSP;
  809. drv->ssp_cmd.header.length = sizeof(struct sst_cmd_sba_hw_set_ssp)
  810. - sizeof(struct sst_dsp_header);
  811. drv->ssp_cmd.selection = ssp_id;
  812. dev_dbg(dai->dev, "ssp_id: %u\n", ssp_id);
  813. if (enable)
  814. drv->ssp_cmd.switch_state = SST_SWITCH_ON;
  815. else
  816. drv->ssp_cmd.switch_state = SST_SWITCH_OFF;
  817. return sst_fill_and_send_cmd(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
  818. SST_TASK_SBA, 0, &drv->ssp_cmd,
  819. sizeof(drv->ssp_cmd.header) + drv->ssp_cmd.header.length);
  820. }
  821. static int sst_set_be_modules(struct snd_soc_dapm_widget *w,
  822. struct snd_kcontrol *k, int event)
  823. {
  824. int ret = 0;
  825. struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
  826. struct sst_data *drv = snd_soc_component_get_drvdata(c);
  827. dev_dbg(c->dev, "Enter: widget=%s\n", w->name);
  828. if (SND_SOC_DAPM_EVENT_ON(event)) {
  829. ret = sst_send_slot_map(drv);
  830. if (ret)
  831. return ret;
  832. ret = sst_send_pipe_module_params(w, k);
  833. }
  834. return ret;
  835. }
  836. static int sst_set_media_path(struct snd_soc_dapm_widget *w,
  837. struct snd_kcontrol *k, int event)
  838. {
  839. int ret = 0;
  840. struct sst_cmd_set_media_path cmd;
  841. struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
  842. struct sst_data *drv = snd_soc_component_get_drvdata(c);
  843. struct sst_ids *ids = w->priv;
  844. dev_dbg(c->dev, "widget=%s\n", w->name);
  845. dev_dbg(c->dev, "task=%u, location=%#x\n",
  846. ids->task_id, ids->location_id);
  847. if (SND_SOC_DAPM_EVENT_ON(event))
  848. cmd.switch_state = SST_PATH_ON;
  849. else
  850. cmd.switch_state = SST_PATH_OFF;
  851. SST_FILL_DESTINATION(2, cmd.header.dst,
  852. ids->location_id, SST_DEFAULT_MODULE_ID);
  853. /* MMX_SET_MEDIA_PATH == SBA_SET_MEDIA_PATH */
  854. cmd.header.command_id = MMX_SET_MEDIA_PATH;
  855. cmd.header.length = sizeof(struct sst_cmd_set_media_path)
  856. - sizeof(struct sst_dsp_header);
  857. ret = sst_fill_and_send_cmd(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
  858. ids->task_id, 0, &cmd,
  859. sizeof(cmd.header) + cmd.header.length);
  860. if (ret)
  861. return ret;
  862. if (SND_SOC_DAPM_EVENT_ON(event))
  863. ret = sst_send_pipe_module_params(w, k);
  864. return ret;
  865. }
  866. static int sst_set_media_loop(struct snd_soc_dapm_widget *w,
  867. struct snd_kcontrol *k, int event)
  868. {
  869. int ret = 0;
  870. struct sst_cmd_sba_set_media_loop_map cmd;
  871. struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
  872. struct sst_data *drv = snd_soc_component_get_drvdata(c);
  873. struct sst_ids *ids = w->priv;
  874. dev_dbg(c->dev, "Enter:widget=%s\n", w->name);
  875. if (SND_SOC_DAPM_EVENT_ON(event))
  876. cmd.switch_state = SST_SWITCH_ON;
  877. else
  878. cmd.switch_state = SST_SWITCH_OFF;
  879. SST_FILL_DESTINATION(2, cmd.header.dst,
  880. ids->location_id, SST_DEFAULT_MODULE_ID);
  881. cmd.header.command_id = SBA_SET_MEDIA_LOOP_MAP;
  882. cmd.header.length = sizeof(struct sst_cmd_sba_set_media_loop_map)
  883. - sizeof(struct sst_dsp_header);
  884. cmd.param.part.cfg.rate = 2; /* 48khz */
  885. cmd.param.part.cfg.format = ids->format; /* stereo/Mono */
  886. cmd.param.part.cfg.s_length = 1; /* 24bit left justified */
  887. cmd.map = 0; /* Algo sequence: Gain - DRP - FIR - IIR */
  888. ret = sst_fill_and_send_cmd(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
  889. SST_TASK_SBA, 0, &cmd,
  890. sizeof(cmd.header) + cmd.header.length);
  891. if (ret)
  892. return ret;
  893. if (SND_SOC_DAPM_EVENT_ON(event))
  894. ret = sst_send_pipe_module_params(w, k);
  895. return ret;
  896. }
  897. static const struct snd_soc_dapm_widget sst_dapm_widgets[] = {
  898. SST_AIF_IN("modem_in", sst_set_be_modules),
  899. SST_AIF_IN("codec_in0", sst_set_be_modules),
  900. SST_AIF_IN("codec_in1", sst_set_be_modules),
  901. SST_AIF_OUT("modem_out", sst_set_be_modules),
  902. SST_AIF_OUT("codec_out0", sst_set_be_modules),
  903. SST_AIF_OUT("codec_out1", sst_set_be_modules),
  904. /* Media Paths */
  905. /* MediaX IN paths are set via ALLOC, so no SET_MEDIA_PATH command */
  906. SST_PATH_INPUT("media0_in", SST_TASK_MMX, SST_SWM_IN_MEDIA0, sst_generic_modules_event),
  907. SST_PATH_INPUT("media1_in", SST_TASK_MMX, SST_SWM_IN_MEDIA1, NULL),
  908. SST_PATH_INPUT("media2_in", SST_TASK_MMX, SST_SWM_IN_MEDIA2, sst_set_media_path),
  909. SST_PATH_INPUT("media3_in", SST_TASK_MMX, SST_SWM_IN_MEDIA3, NULL),
  910. SST_PATH_OUTPUT("media0_out", SST_TASK_MMX, SST_SWM_OUT_MEDIA0, sst_set_media_path),
  911. SST_PATH_OUTPUT("media1_out", SST_TASK_MMX, SST_SWM_OUT_MEDIA1, sst_set_media_path),
  912. /* SBA PCM Paths */
  913. SST_PATH_INPUT("pcm0_in", SST_TASK_SBA, SST_SWM_IN_PCM0, sst_set_media_path),
  914. SST_PATH_INPUT("pcm1_in", SST_TASK_SBA, SST_SWM_IN_PCM1, sst_set_media_path),
  915. SST_PATH_OUTPUT("pcm0_out", SST_TASK_SBA, SST_SWM_OUT_PCM0, sst_set_media_path),
  916. SST_PATH_OUTPUT("pcm1_out", SST_TASK_SBA, SST_SWM_OUT_PCM1, sst_set_media_path),
  917. SST_PATH_OUTPUT("pcm2_out", SST_TASK_SBA, SST_SWM_OUT_PCM2, sst_set_media_path),
  918. /* SBA Loops */
  919. SST_PATH_INPUT("sprot_loop_in", SST_TASK_SBA, SST_SWM_IN_SPROT_LOOP, NULL),
  920. SST_PATH_INPUT("media_loop1_in", SST_TASK_SBA, SST_SWM_IN_MEDIA_LOOP1, NULL),
  921. SST_PATH_INPUT("media_loop2_in", SST_TASK_SBA, SST_SWM_IN_MEDIA_LOOP2, NULL),
  922. SST_PATH_MEDIA_LOOP_OUTPUT("sprot_loop_out", SST_TASK_SBA, SST_SWM_OUT_SPROT_LOOP, SST_FMT_MONO, sst_set_media_loop),
  923. SST_PATH_MEDIA_LOOP_OUTPUT("media_loop1_out", SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP1, SST_FMT_MONO, sst_set_media_loop),
  924. SST_PATH_MEDIA_LOOP_OUTPUT("media_loop2_out", SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP2, SST_FMT_STEREO, sst_set_media_loop),
  925. /* Media Mixers */
  926. SST_SWM_MIXER("media0_out mix 0", SND_SOC_NOPM, SST_TASK_MMX, SST_SWM_OUT_MEDIA0,
  927. sst_mix_media0_controls, sst_swm_mixer_event),
  928. SST_SWM_MIXER("media1_out mix 0", SND_SOC_NOPM, SST_TASK_MMX, SST_SWM_OUT_MEDIA1,
  929. sst_mix_media1_controls, sst_swm_mixer_event),
  930. /* SBA PCM mixers */
  931. SST_SWM_MIXER("pcm0_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_PCM0,
  932. sst_mix_pcm0_controls, sst_swm_mixer_event),
  933. SST_SWM_MIXER("pcm1_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_PCM1,
  934. sst_mix_pcm1_controls, sst_swm_mixer_event),
  935. SST_SWM_MIXER("pcm2_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_PCM2,
  936. sst_mix_pcm2_controls, sst_swm_mixer_event),
  937. /* SBA Loop mixers */
  938. SST_SWM_MIXER("sprot_loop_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_SPROT_LOOP,
  939. sst_mix_sprot_l0_controls, sst_swm_mixer_event),
  940. SST_SWM_MIXER("media_loop1_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP1,
  941. sst_mix_media_l1_controls, sst_swm_mixer_event),
  942. SST_SWM_MIXER("media_loop2_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP2,
  943. sst_mix_media_l2_controls, sst_swm_mixer_event),
  944. /* SBA Backend mixers */
  945. SST_SWM_MIXER("codec_out0 mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_CODEC0,
  946. sst_mix_codec0_controls, sst_swm_mixer_event),
  947. SST_SWM_MIXER("codec_out1 mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_CODEC1,
  948. sst_mix_codec1_controls, sst_swm_mixer_event),
  949. SST_SWM_MIXER("modem_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_MODEM,
  950. sst_mix_modem_controls, sst_swm_mixer_event),
  951. };
  952. static const struct snd_soc_dapm_route intercon[] = {
  953. {"media0_in", NULL, "Compress Playback"},
  954. {"media1_in", NULL, "Headset Playback"},
  955. {"media2_in", NULL, "pcm0_out"},
  956. {"media3_in", NULL, "Deepbuffer Playback"},
  957. {"media0_out mix 0", "media0_in Switch", "media0_in"},
  958. {"media0_out mix 0", "media1_in Switch", "media1_in"},
  959. {"media0_out mix 0", "media2_in Switch", "media2_in"},
  960. {"media0_out mix 0", "media3_in Switch", "media3_in"},
  961. {"media1_out mix 0", "media0_in Switch", "media0_in"},
  962. {"media1_out mix 0", "media1_in Switch", "media1_in"},
  963. {"media1_out mix 0", "media2_in Switch", "media2_in"},
  964. {"media1_out mix 0", "media3_in Switch", "media3_in"},
  965. {"media0_out", NULL, "media0_out mix 0"},
  966. {"media1_out", NULL, "media1_out mix 0"},
  967. {"pcm0_in", NULL, "media0_out"},
  968. {"pcm1_in", NULL, "media1_out"},
  969. {"Headset Capture", NULL, "pcm1_out"},
  970. {"Headset Capture", NULL, "pcm2_out"},
  971. {"pcm0_out", NULL, "pcm0_out mix 0"},
  972. SST_SBA_MIXER_GRAPH_MAP("pcm0_out mix 0"),
  973. {"pcm1_out", NULL, "pcm1_out mix 0"},
  974. SST_SBA_MIXER_GRAPH_MAP("pcm1_out mix 0"),
  975. {"pcm2_out", NULL, "pcm2_out mix 0"},
  976. SST_SBA_MIXER_GRAPH_MAP("pcm2_out mix 0"),
  977. {"media_loop1_in", NULL, "media_loop1_out"},
  978. {"media_loop1_out", NULL, "media_loop1_out mix 0"},
  979. SST_SBA_MIXER_GRAPH_MAP("media_loop1_out mix 0"),
  980. {"media_loop2_in", NULL, "media_loop2_out"},
  981. {"media_loop2_out", NULL, "media_loop2_out mix 0"},
  982. SST_SBA_MIXER_GRAPH_MAP("media_loop2_out mix 0"),
  983. {"sprot_loop_in", NULL, "sprot_loop_out"},
  984. {"sprot_loop_out", NULL, "sprot_loop_out mix 0"},
  985. SST_SBA_MIXER_GRAPH_MAP("sprot_loop_out mix 0"),
  986. {"codec_out0", NULL, "codec_out0 mix 0"},
  987. SST_SBA_MIXER_GRAPH_MAP("codec_out0 mix 0"),
  988. {"codec_out1", NULL, "codec_out1 mix 0"},
  989. SST_SBA_MIXER_GRAPH_MAP("codec_out1 mix 0"),
  990. {"modem_out", NULL, "modem_out mix 0"},
  991. SST_SBA_MIXER_GRAPH_MAP("modem_out mix 0"),
  992. };
  993. static const char * const slot_names[] = {
  994. "none",
  995. "slot 0", "slot 1", "slot 2", "slot 3",
  996. "slot 4", "slot 5", "slot 6", "slot 7", /* not supported by FW */
  997. };
  998. static const char * const channel_names[] = {
  999. "none",
  1000. "codec_out0_0", "codec_out0_1", "codec_out1_0", "codec_out1_1",
  1001. "codec_out2_0", "codec_out2_1", "codec_out3_0", "codec_out3_1", /* not supported by FW */
  1002. };
  1003. #define SST_INTERLEAVER(xpname, slot_name, slotno) \
  1004. SST_SSP_SLOT_CTL(xpname, "tx interleaver", slot_name, slotno, true, \
  1005. channel_names, sst_slot_get, sst_slot_put)
  1006. #define SST_DEINTERLEAVER(xpname, channel_name, channel_no) \
  1007. SST_SSP_SLOT_CTL(xpname, "rx deinterleaver", channel_name, channel_no, false, \
  1008. slot_names, sst_slot_get, sst_slot_put)
  1009. static const struct snd_kcontrol_new sst_slot_controls[] = {
  1010. SST_INTERLEAVER("codec_out", "slot 0", 0),
  1011. SST_INTERLEAVER("codec_out", "slot 1", 1),
  1012. SST_INTERLEAVER("codec_out", "slot 2", 2),
  1013. SST_INTERLEAVER("codec_out", "slot 3", 3),
  1014. SST_DEINTERLEAVER("codec_in", "codec_in0_0", 0),
  1015. SST_DEINTERLEAVER("codec_in", "codec_in0_1", 1),
  1016. SST_DEINTERLEAVER("codec_in", "codec_in1_0", 2),
  1017. SST_DEINTERLEAVER("codec_in", "codec_in1_1", 3),
  1018. };
  1019. /* Gain helper with min/max set */
  1020. #define SST_GAIN(name, path_id, task_id, instance, gain_var) \
  1021. SST_GAIN_KCONTROLS(name, "Gain", SST_GAIN_MIN_VALUE, SST_GAIN_MAX_VALUE, \
  1022. SST_GAIN_TC_MIN, SST_GAIN_TC_MAX, \
  1023. sst_gain_get, sst_gain_put, \
  1024. SST_MODULE_ID_GAIN_CELL, path_id, instance, task_id, \
  1025. sst_gain_tlv_common, gain_var)
  1026. #define SST_VOLUME(name, path_id, task_id, instance, gain_var) \
  1027. SST_GAIN_KCONTROLS(name, "Volume", SST_GAIN_MIN_VALUE, SST_GAIN_MAX_VALUE, \
  1028. SST_GAIN_TC_MIN, SST_GAIN_TC_MAX, \
  1029. sst_gain_get, sst_gain_put, \
  1030. SST_MODULE_ID_VOLUME, path_id, instance, task_id, \
  1031. sst_gain_tlv_common, gain_var)
  1032. static struct sst_gain_value sst_gains[];
  1033. static const struct snd_kcontrol_new sst_gain_controls[] = {
  1034. SST_GAIN("media0_in", SST_PATH_INDEX_MEDIA0_IN, SST_TASK_MMX, 0, &sst_gains[0]),
  1035. SST_GAIN("media1_in", SST_PATH_INDEX_MEDIA1_IN, SST_TASK_MMX, 0, &sst_gains[1]),
  1036. SST_GAIN("media2_in", SST_PATH_INDEX_MEDIA2_IN, SST_TASK_MMX, 0, &sst_gains[2]),
  1037. SST_GAIN("media3_in", SST_PATH_INDEX_MEDIA3_IN, SST_TASK_MMX, 0, &sst_gains[3]),
  1038. SST_GAIN("pcm0_in", SST_PATH_INDEX_PCM0_IN, SST_TASK_SBA, 0, &sst_gains[4]),
  1039. SST_GAIN("pcm1_in", SST_PATH_INDEX_PCM1_IN, SST_TASK_SBA, 0, &sst_gains[5]),
  1040. SST_GAIN("pcm1_out", SST_PATH_INDEX_PCM1_OUT, SST_TASK_SBA, 0, &sst_gains[6]),
  1041. SST_GAIN("pcm2_out", SST_PATH_INDEX_PCM2_OUT, SST_TASK_SBA, 0, &sst_gains[7]),
  1042. SST_GAIN("codec_in0", SST_PATH_INDEX_CODEC_IN0, SST_TASK_SBA, 0, &sst_gains[8]),
  1043. SST_GAIN("codec_in1", SST_PATH_INDEX_CODEC_IN1, SST_TASK_SBA, 0, &sst_gains[9]),
  1044. SST_GAIN("codec_out0", SST_PATH_INDEX_CODEC_OUT0, SST_TASK_SBA, 0, &sst_gains[10]),
  1045. SST_GAIN("codec_out1", SST_PATH_INDEX_CODEC_OUT1, SST_TASK_SBA, 0, &sst_gains[11]),
  1046. SST_GAIN("media_loop1_out", SST_PATH_INDEX_MEDIA_LOOP1_OUT, SST_TASK_SBA, 0, &sst_gains[12]),
  1047. SST_GAIN("media_loop2_out", SST_PATH_INDEX_MEDIA_LOOP2_OUT, SST_TASK_SBA, 0, &sst_gains[13]),
  1048. SST_GAIN("sprot_loop_out", SST_PATH_INDEX_SPROT_LOOP_OUT, SST_TASK_SBA, 0, &sst_gains[14]),
  1049. SST_VOLUME("media0_in", SST_PATH_INDEX_MEDIA0_IN, SST_TASK_MMX, 0, &sst_gains[15]),
  1050. SST_GAIN("modem_in", SST_PATH_INDEX_MODEM_IN, SST_TASK_SBA, 0, &sst_gains[16]),
  1051. SST_GAIN("modem_out", SST_PATH_INDEX_MODEM_OUT, SST_TASK_SBA, 0, &sst_gains[17]),
  1052. };
  1053. #define SST_GAIN_NUM_CONTROLS 3
  1054. /* the SST_GAIN macro above will create three alsa controls for each
  1055. * instance invoked, gain, mute and ramp duration, which use the same gain
  1056. * cell sst_gain to keep track of data
  1057. * To calculate number of gain cell instances we need to device by 3 in
  1058. * below caulcation for gain cell memory.
  1059. * This gets rid of static number and issues while adding new controls
  1060. */
  1061. static struct sst_gain_value sst_gains[ARRAY_SIZE(sst_gain_controls)/SST_GAIN_NUM_CONTROLS];
  1062. static const struct snd_kcontrol_new sst_algo_controls[] = {
  1063. SST_ALGO_KCONTROL_BYTES("media_loop1_out", "fir", 272, SST_MODULE_ID_FIR_24,
  1064. SST_PATH_INDEX_MEDIA_LOOP1_OUT, 0, SST_TASK_SBA, SBA_VB_SET_FIR),
  1065. SST_ALGO_KCONTROL_BYTES("media_loop1_out", "iir", 300, SST_MODULE_ID_IIR_24,
  1066. SST_PATH_INDEX_MEDIA_LOOP1_OUT, 0, SST_TASK_SBA, SBA_VB_SET_IIR),
  1067. SST_ALGO_KCONTROL_BYTES("media_loop1_out", "mdrp", 286, SST_MODULE_ID_MDRP,
  1068. SST_PATH_INDEX_MEDIA_LOOP1_OUT, 0, SST_TASK_SBA, SBA_SET_MDRP),
  1069. SST_ALGO_KCONTROL_BYTES("media_loop2_out", "fir", 272, SST_MODULE_ID_FIR_24,
  1070. SST_PATH_INDEX_MEDIA_LOOP2_OUT, 0, SST_TASK_SBA, SBA_VB_SET_FIR),
  1071. SST_ALGO_KCONTROL_BYTES("media_loop2_out", "iir", 300, SST_MODULE_ID_IIR_24,
  1072. SST_PATH_INDEX_MEDIA_LOOP2_OUT, 0, SST_TASK_SBA, SBA_VB_SET_IIR),
  1073. SST_ALGO_KCONTROL_BYTES("media_loop2_out", "mdrp", 286, SST_MODULE_ID_MDRP,
  1074. SST_PATH_INDEX_MEDIA_LOOP2_OUT, 0, SST_TASK_SBA, SBA_SET_MDRP),
  1075. SST_ALGO_KCONTROL_BYTES("sprot_loop_out", "lpro", 192, SST_MODULE_ID_SPROT,
  1076. SST_PATH_INDEX_SPROT_LOOP_OUT, 0, SST_TASK_SBA, SBA_VB_LPRO),
  1077. SST_ALGO_KCONTROL_BYTES("codec_in0", "dcr", 52, SST_MODULE_ID_FILT_DCR,
  1078. SST_PATH_INDEX_CODEC_IN0, 0, SST_TASK_SBA, SBA_VB_SET_IIR),
  1079. SST_ALGO_KCONTROL_BYTES("codec_in1", "dcr", 52, SST_MODULE_ID_FILT_DCR,
  1080. SST_PATH_INDEX_CODEC_IN1, 0, SST_TASK_SBA, SBA_VB_SET_IIR),
  1081. };
  1082. static int sst_algo_control_init(struct device *dev)
  1083. {
  1084. int i = 0;
  1085. struct sst_algo_control *bc;
  1086. /*allocate space to cache the algo parameters in the driver*/
  1087. for (i = 0; i < ARRAY_SIZE(sst_algo_controls); i++) {
  1088. bc = (struct sst_algo_control *)sst_algo_controls[i].private_value;
  1089. bc->params = devm_kzalloc(dev, bc->max, GFP_KERNEL);
  1090. if (bc->params == NULL)
  1091. return -ENOMEM;
  1092. }
  1093. return 0;
  1094. }
  1095. static bool is_sst_dapm_widget(struct snd_soc_dapm_widget *w)
  1096. {
  1097. switch (w->id) {
  1098. case snd_soc_dapm_pga:
  1099. case snd_soc_dapm_aif_in:
  1100. case snd_soc_dapm_aif_out:
  1101. case snd_soc_dapm_input:
  1102. case snd_soc_dapm_output:
  1103. case snd_soc_dapm_mixer:
  1104. return true;
  1105. default:
  1106. return false;
  1107. }
  1108. }
  1109. /**
  1110. * sst_send_pipe_gains - send gains for the front-end DAIs
  1111. *
  1112. * The gains in the pipes connected to the front-ends are muted/unmuted
  1113. * automatically via the digital_mute() DAPM callback. This function sends the
  1114. * gains for the front-end pipes.
  1115. */
  1116. int sst_send_pipe_gains(struct snd_soc_dai *dai, int stream, int mute)
  1117. {
  1118. struct sst_data *drv = snd_soc_dai_get_drvdata(dai);
  1119. struct snd_soc_dapm_widget *w;
  1120. struct snd_soc_dapm_path *p = NULL;
  1121. dev_dbg(dai->dev, "enter, dai-name=%s dir=%d\n", dai->name, stream);
  1122. if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
  1123. dev_dbg(dai->dev, "Stream name=%s\n",
  1124. dai->playback_widget->name);
  1125. w = dai->playback_widget;
  1126. snd_soc_dapm_widget_for_each_sink_path(w, p) {
  1127. if (p->connected && !p->connected(w, p->sink))
  1128. continue;
  1129. if (p->connect && p->sink->power &&
  1130. is_sst_dapm_widget(p->sink)) {
  1131. struct sst_ids *ids = p->sink->priv;
  1132. dev_dbg(dai->dev, "send gains for widget=%s\n",
  1133. p->sink->name);
  1134. mutex_lock(&drv->lock);
  1135. sst_set_pipe_gain(ids, drv, mute);
  1136. mutex_unlock(&drv->lock);
  1137. }
  1138. }
  1139. } else {
  1140. dev_dbg(dai->dev, "Stream name=%s\n",
  1141. dai->capture_widget->name);
  1142. w = dai->capture_widget;
  1143. snd_soc_dapm_widget_for_each_source_path(w, p) {
  1144. if (p->connected && !p->connected(w, p->sink))
  1145. continue;
  1146. if (p->connect && p->source->power &&
  1147. is_sst_dapm_widget(p->source)) {
  1148. struct sst_ids *ids = p->source->priv;
  1149. dev_dbg(dai->dev, "send gain for widget=%s\n",
  1150. p->source->name);
  1151. mutex_lock(&drv->lock);
  1152. sst_set_pipe_gain(ids, drv, mute);
  1153. mutex_unlock(&drv->lock);
  1154. }
  1155. }
  1156. }
  1157. return 0;
  1158. }
  1159. /**
  1160. * sst_fill_module_list - populate the list of modules/gains for a pipe
  1161. *
  1162. *
  1163. * Fills the widget pointer in the kcontrol private data, and also fills the
  1164. * kcontrol pointer in the widget private data.
  1165. *
  1166. * Widget pointer is used to send the algo/gain in the .put() handler if the
  1167. * widget is powerd on.
  1168. *
  1169. * Kcontrol pointer is used to send the algo/gain in the widget power ON/OFF
  1170. * event handler. Each widget (pipe) has multiple algos stored in the algo_list.
  1171. */
  1172. static int sst_fill_module_list(struct snd_kcontrol *kctl,
  1173. struct snd_soc_dapm_widget *w, int type)
  1174. {
  1175. struct sst_module *module = NULL;
  1176. struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
  1177. struct sst_ids *ids = w->priv;
  1178. int ret = 0;
  1179. module = devm_kzalloc(c->dev, sizeof(*module), GFP_KERNEL);
  1180. if (!module)
  1181. return -ENOMEM;
  1182. if (type == SST_MODULE_GAIN) {
  1183. struct sst_gain_mixer_control *mc = (void *)kctl->private_value;
  1184. mc->w = w;
  1185. module->kctl = kctl;
  1186. list_add_tail(&module->node, &ids->gain_list);
  1187. } else if (type == SST_MODULE_ALGO) {
  1188. struct sst_algo_control *bc = (void *)kctl->private_value;
  1189. bc->w = w;
  1190. module->kctl = kctl;
  1191. list_add_tail(&module->node, &ids->algo_list);
  1192. } else {
  1193. dev_err(c->dev, "invoked for unknown type %d module %s",
  1194. type, kctl->id.name);
  1195. ret = -EINVAL;
  1196. }
  1197. return ret;
  1198. }
  1199. /**
  1200. * sst_fill_widget_module_info - fill list of gains/algos for the pipe
  1201. * @widget: pipe modelled as a DAPM widget
  1202. *
  1203. * Fill the list of gains/algos for the widget by looking at all the card
  1204. * controls and comparing the name of the widget with the first part of control
  1205. * name. First part of control name contains the pipe name (widget name).
  1206. */
  1207. static int sst_fill_widget_module_info(struct snd_soc_dapm_widget *w,
  1208. struct snd_soc_platform *platform)
  1209. {
  1210. struct snd_kcontrol *kctl;
  1211. int index, ret = 0;
  1212. struct snd_card *card = platform->component.card->snd_card;
  1213. char *idx;
  1214. down_read(&card->controls_rwsem);
  1215. list_for_each_entry(kctl, &card->controls, list) {
  1216. idx = strchr(kctl->id.name, ' ');
  1217. if (idx == NULL)
  1218. continue;
  1219. index = idx - (char*)kctl->id.name;
  1220. if (strncmp(kctl->id.name, w->name, index))
  1221. continue;
  1222. if (strstr(kctl->id.name, "Volume"))
  1223. ret = sst_fill_module_list(kctl, w, SST_MODULE_GAIN);
  1224. else if (strstr(kctl->id.name, "params"))
  1225. ret = sst_fill_module_list(kctl, w, SST_MODULE_ALGO);
  1226. else if (strstr(kctl->id.name, "Switch") &&
  1227. strstr(kctl->id.name, "Gain")) {
  1228. struct sst_gain_mixer_control *mc =
  1229. (void *)kctl->private_value;
  1230. mc->w = w;
  1231. } else if (strstr(kctl->id.name, "interleaver")) {
  1232. struct sst_enum *e = (void *)kctl->private_value;
  1233. e->w = w;
  1234. } else if (strstr(kctl->id.name, "deinterleaver")) {
  1235. struct sst_enum *e = (void *)kctl->private_value;
  1236. e->w = w;
  1237. }
  1238. if (ret < 0) {
  1239. up_read(&card->controls_rwsem);
  1240. return ret;
  1241. }
  1242. }
  1243. up_read(&card->controls_rwsem);
  1244. return 0;
  1245. }
  1246. /**
  1247. * sst_fill_linked_widgets - fill the parent pointer for the linked widget
  1248. */
  1249. static void sst_fill_linked_widgets(struct snd_soc_platform *platform,
  1250. struct sst_ids *ids)
  1251. {
  1252. struct snd_soc_dapm_widget *w;
  1253. unsigned int len = strlen(ids->parent_wname);
  1254. list_for_each_entry(w, &platform->component.card->widgets, list) {
  1255. if (!strncmp(ids->parent_wname, w->name, len)) {
  1256. ids->parent_w = w;
  1257. break;
  1258. }
  1259. }
  1260. }
  1261. /**
  1262. * sst_map_modules_to_pipe - fill algo/gains list for all pipes
  1263. */
  1264. static int sst_map_modules_to_pipe(struct snd_soc_platform *platform)
  1265. {
  1266. struct snd_soc_dapm_widget *w;
  1267. int ret = 0;
  1268. list_for_each_entry(w, &platform->component.card->widgets, list) {
  1269. if (is_sst_dapm_widget(w) && (w->priv)) {
  1270. struct sst_ids *ids = w->priv;
  1271. dev_dbg(platform->dev, "widget type=%d name=%s\n",
  1272. w->id, w->name);
  1273. INIT_LIST_HEAD(&ids->algo_list);
  1274. INIT_LIST_HEAD(&ids->gain_list);
  1275. ret = sst_fill_widget_module_info(w, platform);
  1276. if (ret < 0)
  1277. return ret;
  1278. /* fill linked widgets */
  1279. if (ids->parent_wname != NULL)
  1280. sst_fill_linked_widgets(platform, ids);
  1281. }
  1282. }
  1283. return 0;
  1284. }
  1285. int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
  1286. {
  1287. int i, ret = 0;
  1288. struct snd_soc_dapm_context *dapm =
  1289. snd_soc_component_get_dapm(&platform->component);
  1290. struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
  1291. unsigned int gains = ARRAY_SIZE(sst_gain_controls)/3;
  1292. drv->byte_stream = devm_kzalloc(platform->dev,
  1293. SST_MAX_BIN_BYTES, GFP_KERNEL);
  1294. if (!drv->byte_stream)
  1295. return -ENOMEM;
  1296. snd_soc_dapm_new_controls(dapm, sst_dapm_widgets,
  1297. ARRAY_SIZE(sst_dapm_widgets));
  1298. snd_soc_dapm_add_routes(dapm, intercon,
  1299. ARRAY_SIZE(intercon));
  1300. snd_soc_dapm_new_widgets(dapm->card);
  1301. for (i = 0; i < gains; i++) {
  1302. sst_gains[i].mute = SST_GAIN_MUTE_DEFAULT;
  1303. sst_gains[i].l_gain = SST_GAIN_VOLUME_DEFAULT;
  1304. sst_gains[i].r_gain = SST_GAIN_VOLUME_DEFAULT;
  1305. sst_gains[i].ramp_duration = SST_GAIN_RAMP_DURATION_DEFAULT;
  1306. }
  1307. ret = snd_soc_add_platform_controls(platform, sst_gain_controls,
  1308. ARRAY_SIZE(sst_gain_controls));
  1309. if (ret)
  1310. return ret;
  1311. /* Initialize algo control params */
  1312. ret = sst_algo_control_init(platform->dev);
  1313. if (ret)
  1314. return ret;
  1315. ret = snd_soc_add_platform_controls(platform, sst_algo_controls,
  1316. ARRAY_SIZE(sst_algo_controls));
  1317. if (ret)
  1318. return ret;
  1319. ret = snd_soc_add_platform_controls(platform, sst_slot_controls,
  1320. ARRAY_SIZE(sst_slot_controls));
  1321. if (ret)
  1322. return ret;
  1323. ret = sst_map_modules_to_pipe(platform);
  1324. return ret;
  1325. }