sst-atom-controls.c 49 KB

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