sst-atom-controls.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543
  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. 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
  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 ? 1 : 0;
  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_CODEC0] = SST_SWM_IN_CODEC0,
  453. [SST_IP_CODEC1] = SST_SWM_IN_CODEC1,
  454. [SST_IP_LOOP0] = SST_SWM_IN_SPROT_LOOP,
  455. [SST_IP_LOOP1] = SST_SWM_IN_MEDIA_LOOP1,
  456. [SST_IP_LOOP2] = SST_SWM_IN_MEDIA_LOOP2,
  457. [SST_IP_PCM0] = SST_SWM_IN_PCM0,
  458. [SST_IP_PCM1] = SST_SWM_IN_PCM1,
  459. [SST_IP_MEDIA0] = SST_SWM_IN_MEDIA0,
  460. [SST_IP_MEDIA1] = SST_SWM_IN_MEDIA1,
  461. [SST_IP_MEDIA2] = SST_SWM_IN_MEDIA2,
  462. [SST_IP_MEDIA3] = SST_SWM_IN_MEDIA3,
  463. };
  464. /**
  465. * fill_swm_input - fill in the SWM input ids given the register
  466. *
  467. * The register value is a bit-field inicated which mixer inputs are ON. Use the
  468. * lookup table to get the input-id and fill it in the structure.
  469. */
  470. static int fill_swm_input(struct snd_soc_component *cmpnt,
  471. struct swm_input_ids *swm_input, unsigned int reg)
  472. {
  473. uint i, is_set, nb_inputs = 0;
  474. u16 input_loc_id;
  475. dev_dbg(cmpnt->dev, "reg: %#x\n", reg);
  476. for (i = 0; i < SST_SWM_INPUT_COUNT; i++) {
  477. is_set = reg & BIT(i);
  478. if (!is_set)
  479. continue;
  480. input_loc_id = swm_mixer_input_ids[i];
  481. SST_FILL_DESTINATION(2, swm_input->input_id,
  482. input_loc_id, SST_DEFAULT_MODULE_ID);
  483. nb_inputs++;
  484. swm_input++;
  485. dev_dbg(cmpnt->dev, "input id: %#x, nb_inputs: %d\n",
  486. input_loc_id, nb_inputs);
  487. if (nb_inputs == SST_CMD_SWM_MAX_INPUTS) {
  488. dev_warn(cmpnt->dev, "SET_SWM cmd max inputs reached");
  489. break;
  490. }
  491. }
  492. return nb_inputs;
  493. }
  494. /**
  495. * called with lock held
  496. */
  497. static int sst_set_pipe_gain(struct sst_ids *ids,
  498. struct sst_data *drv, int mute)
  499. {
  500. int ret = 0;
  501. struct sst_gain_mixer_control *mc;
  502. struct sst_gain_value *gv;
  503. struct sst_module *gain = NULL;
  504. list_for_each_entry(gain, &ids->gain_list, node) {
  505. struct snd_kcontrol *kctl = gain->kctl;
  506. dev_dbg(&drv->pdev->dev, "control name=%s\n", kctl->id.name);
  507. mc = (void *)kctl->private_value;
  508. gv = mc->gain_val;
  509. ret = sst_send_gain_cmd(drv, gv, mc->task_id,
  510. mc->pipe_id | mc->instance_id, mc->module_id, mute);
  511. if (ret)
  512. return ret;
  513. }
  514. return ret;
  515. }
  516. static int sst_swm_mixer_event(struct snd_soc_dapm_widget *w,
  517. struct snd_kcontrol *k, int event)
  518. {
  519. struct sst_cmd_set_swm cmd;
  520. struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
  521. struct sst_data *drv = snd_soc_component_get_drvdata(cmpnt);
  522. struct sst_ids *ids = w->priv;
  523. bool set_mixer = false;
  524. struct soc_mixer_control *mc;
  525. int val = 0;
  526. int i = 0;
  527. dev_dbg(cmpnt->dev, "widget = %s\n", w->name);
  528. /*
  529. * Identify which mixer input is on and send the bitmap of the
  530. * inputs as an IPC to the DSP.
  531. */
  532. for (i = 0; i < w->num_kcontrols; i++) {
  533. if (dapm_kcontrol_get_value(w->kcontrols[i])) {
  534. mc = (struct soc_mixer_control *)(w->kcontrols[i])->private_value;
  535. val |= 1 << mc->shift;
  536. }
  537. }
  538. dev_dbg(cmpnt->dev, "val = %#x\n", val);
  539. switch (event) {
  540. case SND_SOC_DAPM_PRE_PMU:
  541. case SND_SOC_DAPM_POST_PMD:
  542. set_mixer = true;
  543. break;
  544. case SND_SOC_DAPM_POST_REG:
  545. if (w->power)
  546. set_mixer = true;
  547. break;
  548. default:
  549. set_mixer = false;
  550. }
  551. if (set_mixer == false)
  552. return 0;
  553. if (SND_SOC_DAPM_EVENT_ON(event) ||
  554. event == SND_SOC_DAPM_POST_REG)
  555. cmd.switch_state = SST_SWM_ON;
  556. else
  557. cmd.switch_state = SST_SWM_OFF;
  558. SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
  559. /* MMX_SET_SWM == SBA_SET_SWM */
  560. cmd.header.command_id = SBA_SET_SWM;
  561. SST_FILL_DESTINATION(2, cmd.output_id,
  562. ids->location_id, SST_DEFAULT_MODULE_ID);
  563. cmd.nb_inputs = fill_swm_input(cmpnt, &cmd.input[0], val);
  564. cmd.header.length = offsetof(struct sst_cmd_set_swm, input)
  565. - sizeof(struct sst_dsp_header)
  566. + (cmd.nb_inputs * sizeof(cmd.input[0]));
  567. return sst_fill_and_send_cmd(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
  568. ids->task_id, 0, &cmd,
  569. sizeof(cmd.header) + cmd.header.length);
  570. }
  571. /* SBA mixers - 16 inputs */
  572. #define SST_SBA_DECLARE_MIX_CONTROLS(kctl_name) \
  573. static const struct snd_kcontrol_new kctl_name[] = { \
  574. SOC_DAPM_SINGLE("codec_in0 Switch", SND_SOC_NOPM, SST_IP_CODEC0, 1, 0), \
  575. SOC_DAPM_SINGLE("codec_in1 Switch", SND_SOC_NOPM, SST_IP_CODEC1, 1, 0), \
  576. SOC_DAPM_SINGLE("sprot_loop_in Switch", SND_SOC_NOPM, SST_IP_LOOP0, 1, 0), \
  577. SOC_DAPM_SINGLE("media_loop1_in Switch", SND_SOC_NOPM, SST_IP_LOOP1, 1, 0), \
  578. SOC_DAPM_SINGLE("media_loop2_in Switch", SND_SOC_NOPM, SST_IP_LOOP2, 1, 0), \
  579. SOC_DAPM_SINGLE("pcm0_in Switch", SND_SOC_NOPM, SST_IP_PCM0, 1, 0), \
  580. SOC_DAPM_SINGLE("pcm1_in Switch", SND_SOC_NOPM, SST_IP_PCM1, 1, 0), \
  581. }
  582. #define SST_SBA_MIXER_GRAPH_MAP(mix_name) \
  583. { mix_name, "codec_in0 Switch", "codec_in0" }, \
  584. { mix_name, "codec_in1 Switch", "codec_in1" }, \
  585. { mix_name, "sprot_loop_in Switch", "sprot_loop_in" }, \
  586. { mix_name, "media_loop1_in Switch", "media_loop1_in" }, \
  587. { mix_name, "media_loop2_in Switch", "media_loop2_in" }, \
  588. { mix_name, "pcm0_in Switch", "pcm0_in" }, \
  589. { mix_name, "pcm1_in Switch", "pcm1_in" }
  590. #define SST_MMX_DECLARE_MIX_CONTROLS(kctl_name) \
  591. static const struct snd_kcontrol_new kctl_name[] = { \
  592. SOC_DAPM_SINGLE("media0_in Switch", SND_SOC_NOPM, SST_IP_MEDIA0, 1, 0), \
  593. SOC_DAPM_SINGLE("media1_in Switch", SND_SOC_NOPM, SST_IP_MEDIA1, 1, 0), \
  594. SOC_DAPM_SINGLE("media2_in Switch", SND_SOC_NOPM, SST_IP_MEDIA2, 1, 0), \
  595. SOC_DAPM_SINGLE("media3_in Switch", SND_SOC_NOPM, SST_IP_MEDIA3, 1, 0), \
  596. }
  597. SST_MMX_DECLARE_MIX_CONTROLS(sst_mix_media0_controls);
  598. SST_MMX_DECLARE_MIX_CONTROLS(sst_mix_media1_controls);
  599. /* 18 SBA mixers */
  600. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_pcm0_controls);
  601. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_pcm1_controls);
  602. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_pcm2_controls);
  603. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_sprot_l0_controls);
  604. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_media_l1_controls);
  605. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_media_l2_controls);
  606. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_voip_controls);
  607. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_codec0_controls);
  608. SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_codec1_controls);
  609. /*
  610. * sst_handle_vb_timer - Start/Stop the DSP scheduler
  611. *
  612. * The DSP expects first cmd to be SBA_VB_START, so at first startup send
  613. * that.
  614. * DSP expects last cmd to be SBA_VB_IDLE, so at last shutdown send that.
  615. *
  616. * Do refcount internally so that we send command only at first start
  617. * and last end. Since SST driver does its own ref count, invoke sst's
  618. * power ops always!
  619. */
  620. int sst_handle_vb_timer(struct snd_soc_dai *dai, bool enable)
  621. {
  622. int ret = 0;
  623. struct sst_cmd_generic cmd;
  624. struct sst_data *drv = snd_soc_dai_get_drvdata(dai);
  625. static int timer_usage;
  626. if (enable)
  627. cmd.header.command_id = SBA_VB_START;
  628. else
  629. cmd.header.command_id = SBA_IDLE;
  630. dev_dbg(dai->dev, "enable=%u, usage=%d\n", enable, timer_usage);
  631. SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
  632. cmd.header.length = 0;
  633. if (enable) {
  634. ret = sst->ops->power(sst->dev, true);
  635. if (ret < 0)
  636. return ret;
  637. }
  638. mutex_lock(&drv->lock);
  639. if (enable)
  640. timer_usage++;
  641. else
  642. timer_usage--;
  643. /*
  644. * Send the command only if this call is the first enable or last
  645. * disable
  646. */
  647. if ((enable && (timer_usage == 1)) ||
  648. (!enable && (timer_usage == 0))) {
  649. ret = sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_CMD,
  650. SST_FLAG_BLOCKED, SST_TASK_SBA, 0, &cmd,
  651. sizeof(cmd.header) + cmd.header.length);
  652. if (ret && enable) {
  653. timer_usage--;
  654. enable = false;
  655. }
  656. }
  657. mutex_unlock(&drv->lock);
  658. if (!enable)
  659. sst->ops->power(sst->dev, false);
  660. return ret;
  661. }
  662. int sst_fill_ssp_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
  663. unsigned int rx_mask, int slots, int slot_width)
  664. {
  665. struct sst_data *ctx = snd_soc_dai_get_drvdata(dai);
  666. ctx->ssp_cmd.nb_slots = slots;
  667. ctx->ssp_cmd.active_tx_slot_map = tx_mask;
  668. ctx->ssp_cmd.active_rx_slot_map = rx_mask;
  669. ctx->ssp_cmd.nb_bits_per_slots = slot_width;
  670. return 0;
  671. }
  672. static int sst_get_frame_sync_polarity(struct snd_soc_dai *dai,
  673. unsigned int fmt)
  674. {
  675. int format;
  676. format = fmt & SND_SOC_DAIFMT_INV_MASK;
  677. dev_dbg(dai->dev, "Enter:%s, format=%x\n", __func__, format);
  678. switch (format) {
  679. case SND_SOC_DAIFMT_NB_NF:
  680. return SSP_FS_ACTIVE_LOW;
  681. case SND_SOC_DAIFMT_NB_IF:
  682. return SSP_FS_ACTIVE_HIGH;
  683. case SND_SOC_DAIFMT_IB_IF:
  684. return SSP_FS_ACTIVE_LOW;
  685. case SND_SOC_DAIFMT_IB_NF:
  686. return SSP_FS_ACTIVE_HIGH;
  687. default:
  688. dev_err(dai->dev, "Invalid frame sync polarity %d\n", format);
  689. }
  690. return -EINVAL;
  691. }
  692. static int sst_get_ssp_mode(struct snd_soc_dai *dai, unsigned int fmt)
  693. {
  694. int format;
  695. format = (fmt & SND_SOC_DAIFMT_MASTER_MASK);
  696. dev_dbg(dai->dev, "Enter:%s, format=%x\n", __func__, format);
  697. switch (format) {
  698. case SND_SOC_DAIFMT_CBS_CFS:
  699. return SSP_MODE_MASTER;
  700. case SND_SOC_DAIFMT_CBM_CFM:
  701. return SSP_MODE_SLAVE;
  702. default:
  703. dev_err(dai->dev, "Invalid ssp protocol: %d\n", format);
  704. }
  705. return -EINVAL;
  706. }
  707. int sst_fill_ssp_config(struct snd_soc_dai *dai, unsigned int fmt)
  708. {
  709. unsigned int mode;
  710. int fs_polarity;
  711. struct sst_data *ctx = snd_soc_dai_get_drvdata(dai);
  712. mode = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
  713. switch (mode) {
  714. case SND_SOC_DAIFMT_DSP_B:
  715. ctx->ssp_cmd.ssp_protocol = SSP_MODE_PCM;
  716. ctx->ssp_cmd.mode = sst_get_ssp_mode(dai, fmt) | (SSP_PCM_MODE_NETWORK << 1);
  717. ctx->ssp_cmd.start_delay = 0;
  718. ctx->ssp_cmd.data_polarity = 1;
  719. ctx->ssp_cmd.frame_sync_width = 1;
  720. break;
  721. case SND_SOC_DAIFMT_DSP_A:
  722. ctx->ssp_cmd.ssp_protocol = SSP_MODE_PCM;
  723. ctx->ssp_cmd.mode = sst_get_ssp_mode(dai, fmt) | (SSP_PCM_MODE_NETWORK << 1);
  724. ctx->ssp_cmd.start_delay = 1;
  725. ctx->ssp_cmd.data_polarity = 1;
  726. ctx->ssp_cmd.frame_sync_width = 1;
  727. break;
  728. case SND_SOC_DAIFMT_I2S:
  729. ctx->ssp_cmd.ssp_protocol = SSP_MODE_I2S;
  730. ctx->ssp_cmd.mode = sst_get_ssp_mode(dai, fmt) | (SSP_PCM_MODE_NORMAL << 1);
  731. ctx->ssp_cmd.start_delay = 1;
  732. ctx->ssp_cmd.data_polarity = 0;
  733. ctx->ssp_cmd.frame_sync_width = ctx->ssp_cmd.nb_bits_per_slots;
  734. break;
  735. case SND_SOC_DAIFMT_LEFT_J:
  736. ctx->ssp_cmd.ssp_protocol = SSP_MODE_I2S;
  737. ctx->ssp_cmd.mode = sst_get_ssp_mode(dai, fmt) | (SSP_PCM_MODE_NORMAL << 1);
  738. ctx->ssp_cmd.start_delay = 0;
  739. ctx->ssp_cmd.data_polarity = 0;
  740. ctx->ssp_cmd.frame_sync_width = ctx->ssp_cmd.nb_bits_per_slots;
  741. break;
  742. default:
  743. dev_dbg(dai->dev, "using default ssp configs\n");
  744. }
  745. fs_polarity = sst_get_frame_sync_polarity(dai, fmt);
  746. if (fs_polarity < 0)
  747. return fs_polarity;
  748. ctx->ssp_cmd.frame_sync_polarity = fs_polarity;
  749. return 0;
  750. }
  751. /**
  752. * sst_ssp_config - contains SSP configuration for media UC
  753. * this can be overwritten by set_dai_xxx APIs
  754. */
  755. static const struct sst_ssp_config sst_ssp_configs = {
  756. .ssp_id = SSP_CODEC,
  757. .bits_per_slot = 24,
  758. .slots = 4,
  759. .ssp_mode = SSP_MODE_MASTER,
  760. .pcm_mode = SSP_PCM_MODE_NETWORK,
  761. .duplex = SSP_DUPLEX,
  762. .ssp_protocol = SSP_MODE_PCM,
  763. .fs_width = 1,
  764. .fs_frequency = SSP_FS_48_KHZ,
  765. .active_slot_map = 0xF,
  766. .start_delay = 0,
  767. .frame_sync_polarity = SSP_FS_ACTIVE_HIGH,
  768. .data_polarity = 1,
  769. };
  770. void sst_fill_ssp_defaults(struct snd_soc_dai *dai)
  771. {
  772. const struct sst_ssp_config *config;
  773. struct sst_data *ctx = snd_soc_dai_get_drvdata(dai);
  774. config = &sst_ssp_configs;
  775. ctx->ssp_cmd.selection = config->ssp_id;
  776. ctx->ssp_cmd.nb_bits_per_slots = config->bits_per_slot;
  777. ctx->ssp_cmd.nb_slots = config->slots;
  778. ctx->ssp_cmd.mode = config->ssp_mode | (config->pcm_mode << 1);
  779. ctx->ssp_cmd.duplex = config->duplex;
  780. ctx->ssp_cmd.active_tx_slot_map = config->active_slot_map;
  781. ctx->ssp_cmd.active_rx_slot_map = config->active_slot_map;
  782. ctx->ssp_cmd.frame_sync_frequency = config->fs_frequency;
  783. ctx->ssp_cmd.frame_sync_polarity = config->frame_sync_polarity;
  784. ctx->ssp_cmd.data_polarity = config->data_polarity;
  785. ctx->ssp_cmd.frame_sync_width = config->fs_width;
  786. ctx->ssp_cmd.ssp_protocol = config->ssp_protocol;
  787. ctx->ssp_cmd.start_delay = config->start_delay;
  788. ctx->ssp_cmd.reserved1 = ctx->ssp_cmd.reserved2 = 0xFF;
  789. }
  790. int send_ssp_cmd(struct snd_soc_dai *dai, const char *id, bool enable)
  791. {
  792. struct sst_data *drv = snd_soc_dai_get_drvdata(dai);
  793. const struct sst_ssp_config *config;
  794. dev_info(dai->dev, "Enter: enable=%d port_name=%s\n", enable, id);
  795. SST_FILL_DEFAULT_DESTINATION(drv->ssp_cmd.header.dst);
  796. drv->ssp_cmd.header.command_id = SBA_HW_SET_SSP;
  797. drv->ssp_cmd.header.length = sizeof(struct sst_cmd_sba_hw_set_ssp)
  798. - sizeof(struct sst_dsp_header);
  799. config = &sst_ssp_configs;
  800. dev_dbg(dai->dev, "ssp_id: %u\n", config->ssp_id);
  801. if (enable)
  802. drv->ssp_cmd.switch_state = SST_SWITCH_ON;
  803. else
  804. drv->ssp_cmd.switch_state = SST_SWITCH_OFF;
  805. return sst_fill_and_send_cmd(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
  806. SST_TASK_SBA, 0, &drv->ssp_cmd,
  807. sizeof(drv->ssp_cmd.header) + drv->ssp_cmd.header.length);
  808. }
  809. static int sst_set_be_modules(struct snd_soc_dapm_widget *w,
  810. struct snd_kcontrol *k, int event)
  811. {
  812. int ret = 0;
  813. struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
  814. struct sst_data *drv = snd_soc_component_get_drvdata(c);
  815. dev_dbg(c->dev, "Enter: widget=%s\n", w->name);
  816. if (SND_SOC_DAPM_EVENT_ON(event)) {
  817. ret = sst_send_slot_map(drv);
  818. if (ret)
  819. return ret;
  820. ret = sst_send_pipe_module_params(w, k);
  821. }
  822. return ret;
  823. }
  824. static int sst_set_media_path(struct snd_soc_dapm_widget *w,
  825. struct snd_kcontrol *k, int event)
  826. {
  827. int ret = 0;
  828. struct sst_cmd_set_media_path cmd;
  829. struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
  830. struct sst_data *drv = snd_soc_component_get_drvdata(c);
  831. struct sst_ids *ids = w->priv;
  832. dev_dbg(c->dev, "widget=%s\n", w->name);
  833. dev_dbg(c->dev, "task=%u, location=%#x\n",
  834. ids->task_id, ids->location_id);
  835. if (SND_SOC_DAPM_EVENT_ON(event))
  836. cmd.switch_state = SST_PATH_ON;
  837. else
  838. cmd.switch_state = SST_PATH_OFF;
  839. SST_FILL_DESTINATION(2, cmd.header.dst,
  840. ids->location_id, SST_DEFAULT_MODULE_ID);
  841. /* MMX_SET_MEDIA_PATH == SBA_SET_MEDIA_PATH */
  842. cmd.header.command_id = MMX_SET_MEDIA_PATH;
  843. cmd.header.length = sizeof(struct sst_cmd_set_media_path)
  844. - sizeof(struct sst_dsp_header);
  845. ret = sst_fill_and_send_cmd(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
  846. ids->task_id, 0, &cmd,
  847. sizeof(cmd.header) + cmd.header.length);
  848. if (ret)
  849. return ret;
  850. if (SND_SOC_DAPM_EVENT_ON(event))
  851. ret = sst_send_pipe_module_params(w, k);
  852. return ret;
  853. }
  854. static int sst_set_media_loop(struct snd_soc_dapm_widget *w,
  855. struct snd_kcontrol *k, int event)
  856. {
  857. int ret = 0;
  858. struct sst_cmd_sba_set_media_loop_map cmd;
  859. struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
  860. struct sst_data *drv = snd_soc_component_get_drvdata(c);
  861. struct sst_ids *ids = w->priv;
  862. dev_dbg(c->dev, "Enter:widget=%s\n", w->name);
  863. if (SND_SOC_DAPM_EVENT_ON(event))
  864. cmd.switch_state = SST_SWITCH_ON;
  865. else
  866. cmd.switch_state = SST_SWITCH_OFF;
  867. SST_FILL_DESTINATION(2, cmd.header.dst,
  868. ids->location_id, SST_DEFAULT_MODULE_ID);
  869. cmd.header.command_id = SBA_SET_MEDIA_LOOP_MAP;
  870. cmd.header.length = sizeof(struct sst_cmd_sba_set_media_loop_map)
  871. - sizeof(struct sst_dsp_header);
  872. cmd.param.part.cfg.rate = 2; /* 48khz */
  873. cmd.param.part.cfg.format = ids->format; /* stereo/Mono */
  874. cmd.param.part.cfg.s_length = 1; /* 24bit left justified */
  875. cmd.map = 0; /* Algo sequence: Gain - DRP - FIR - IIR */
  876. ret = sst_fill_and_send_cmd(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
  877. SST_TASK_SBA, 0, &cmd,
  878. sizeof(cmd.header) + cmd.header.length);
  879. if (ret)
  880. return ret;
  881. if (SND_SOC_DAPM_EVENT_ON(event))
  882. ret = sst_send_pipe_module_params(w, k);
  883. return ret;
  884. }
  885. static const struct snd_soc_dapm_widget sst_dapm_widgets[] = {
  886. SST_AIF_IN("codec_in0", sst_set_be_modules),
  887. SST_AIF_IN("codec_in1", sst_set_be_modules),
  888. SST_AIF_OUT("codec_out0", sst_set_be_modules),
  889. SST_AIF_OUT("codec_out1", sst_set_be_modules),
  890. /* Media Paths */
  891. /* MediaX IN paths are set via ALLOC, so no SET_MEDIA_PATH command */
  892. SST_PATH_INPUT("media0_in", SST_TASK_MMX, SST_SWM_IN_MEDIA0, sst_generic_modules_event),
  893. SST_PATH_INPUT("media1_in", SST_TASK_MMX, SST_SWM_IN_MEDIA1, NULL),
  894. SST_PATH_INPUT("media2_in", SST_TASK_MMX, SST_SWM_IN_MEDIA2, sst_set_media_path),
  895. SST_PATH_INPUT("media3_in", SST_TASK_MMX, SST_SWM_IN_MEDIA3, NULL),
  896. SST_PATH_OUTPUT("media0_out", SST_TASK_MMX, SST_SWM_OUT_MEDIA0, sst_set_media_path),
  897. SST_PATH_OUTPUT("media1_out", SST_TASK_MMX, SST_SWM_OUT_MEDIA1, sst_set_media_path),
  898. /* SBA PCM Paths */
  899. SST_PATH_INPUT("pcm0_in", SST_TASK_SBA, SST_SWM_IN_PCM0, sst_set_media_path),
  900. SST_PATH_INPUT("pcm1_in", SST_TASK_SBA, SST_SWM_IN_PCM1, sst_set_media_path),
  901. SST_PATH_OUTPUT("pcm0_out", SST_TASK_SBA, SST_SWM_OUT_PCM0, sst_set_media_path),
  902. SST_PATH_OUTPUT("pcm1_out", SST_TASK_SBA, SST_SWM_OUT_PCM1, sst_set_media_path),
  903. SST_PATH_OUTPUT("pcm2_out", SST_TASK_SBA, SST_SWM_OUT_PCM2, sst_set_media_path),
  904. /* SBA Loops */
  905. SST_PATH_INPUT("sprot_loop_in", SST_TASK_SBA, SST_SWM_IN_SPROT_LOOP, NULL),
  906. SST_PATH_INPUT("media_loop1_in", SST_TASK_SBA, SST_SWM_IN_MEDIA_LOOP1, NULL),
  907. SST_PATH_INPUT("media_loop2_in", SST_TASK_SBA, SST_SWM_IN_MEDIA_LOOP2, NULL),
  908. SST_PATH_MEDIA_LOOP_OUTPUT("sprot_loop_out", SST_TASK_SBA, SST_SWM_OUT_SPROT_LOOP, SST_FMT_MONO, sst_set_media_loop),
  909. SST_PATH_MEDIA_LOOP_OUTPUT("media_loop1_out", SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP1, SST_FMT_MONO, sst_set_media_loop),
  910. SST_PATH_MEDIA_LOOP_OUTPUT("media_loop2_out", SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP2, SST_FMT_STEREO, sst_set_media_loop),
  911. /* Media Mixers */
  912. SST_SWM_MIXER("media0_out mix 0", SND_SOC_NOPM, SST_TASK_MMX, SST_SWM_OUT_MEDIA0,
  913. sst_mix_media0_controls, sst_swm_mixer_event),
  914. SST_SWM_MIXER("media1_out mix 0", SND_SOC_NOPM, SST_TASK_MMX, SST_SWM_OUT_MEDIA1,
  915. sst_mix_media1_controls, sst_swm_mixer_event),
  916. /* SBA PCM mixers */
  917. SST_SWM_MIXER("pcm0_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_PCM0,
  918. sst_mix_pcm0_controls, sst_swm_mixer_event),
  919. SST_SWM_MIXER("pcm1_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_PCM1,
  920. sst_mix_pcm1_controls, sst_swm_mixer_event),
  921. SST_SWM_MIXER("pcm2_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_PCM2,
  922. sst_mix_pcm2_controls, sst_swm_mixer_event),
  923. /* SBA Loop mixers */
  924. SST_SWM_MIXER("sprot_loop_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_SPROT_LOOP,
  925. sst_mix_sprot_l0_controls, sst_swm_mixer_event),
  926. SST_SWM_MIXER("media_loop1_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP1,
  927. sst_mix_media_l1_controls, sst_swm_mixer_event),
  928. SST_SWM_MIXER("media_loop2_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP2,
  929. sst_mix_media_l2_controls, sst_swm_mixer_event),
  930. /* SBA Backend mixers */
  931. SST_SWM_MIXER("codec_out0 mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_CODEC0,
  932. sst_mix_codec0_controls, sst_swm_mixer_event),
  933. SST_SWM_MIXER("codec_out1 mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_CODEC1,
  934. sst_mix_codec1_controls, sst_swm_mixer_event),
  935. };
  936. static const struct snd_soc_dapm_route intercon[] = {
  937. {"media0_in", NULL, "Compress Playback"},
  938. {"media1_in", NULL, "Headset Playback"},
  939. {"media2_in", NULL, "pcm0_out"},
  940. {"media0_out mix 0", "media0_in Switch", "media0_in"},
  941. {"media0_out mix 0", "media1_in Switch", "media1_in"},
  942. {"media0_out mix 0", "media2_in Switch", "media2_in"},
  943. {"media0_out mix 0", "media3_in Switch", "media3_in"},
  944. {"media1_out mix 0", "media0_in Switch", "media0_in"},
  945. {"media1_out mix 0", "media1_in Switch", "media1_in"},
  946. {"media1_out mix 0", "media2_in Switch", "media2_in"},
  947. {"media1_out mix 0", "media3_in Switch", "media3_in"},
  948. {"media0_out", NULL, "media0_out mix 0"},
  949. {"media1_out", NULL, "media1_out mix 0"},
  950. {"pcm0_in", NULL, "media0_out"},
  951. {"pcm1_in", NULL, "media1_out"},
  952. {"Headset Capture", NULL, "pcm1_out"},
  953. {"Headset Capture", NULL, "pcm2_out"},
  954. {"pcm0_out", NULL, "pcm0_out mix 0"},
  955. SST_SBA_MIXER_GRAPH_MAP("pcm0_out mix 0"),
  956. {"pcm1_out", NULL, "pcm1_out mix 0"},
  957. SST_SBA_MIXER_GRAPH_MAP("pcm1_out mix 0"),
  958. {"pcm2_out", NULL, "pcm2_out mix 0"},
  959. SST_SBA_MIXER_GRAPH_MAP("pcm2_out mix 0"),
  960. {"media_loop1_in", NULL, "media_loop1_out"},
  961. {"media_loop1_out", NULL, "media_loop1_out mix 0"},
  962. SST_SBA_MIXER_GRAPH_MAP("media_loop1_out mix 0"),
  963. {"media_loop2_in", NULL, "media_loop2_out"},
  964. {"media_loop2_out", NULL, "media_loop2_out mix 0"},
  965. SST_SBA_MIXER_GRAPH_MAP("media_loop2_out mix 0"),
  966. {"sprot_loop_in", NULL, "sprot_loop_out"},
  967. {"sprot_loop_out", NULL, "sprot_loop_out mix 0"},
  968. SST_SBA_MIXER_GRAPH_MAP("sprot_loop_out mix 0"),
  969. {"codec_out0", NULL, "codec_out0 mix 0"},
  970. SST_SBA_MIXER_GRAPH_MAP("codec_out0 mix 0"),
  971. {"codec_out1", NULL, "codec_out1 mix 0"},
  972. SST_SBA_MIXER_GRAPH_MAP("codec_out1 mix 0"),
  973. };
  974. static const char * const slot_names[] = {
  975. "none",
  976. "slot 0", "slot 1", "slot 2", "slot 3",
  977. "slot 4", "slot 5", "slot 6", "slot 7", /* not supported by FW */
  978. };
  979. static const char * const channel_names[] = {
  980. "none",
  981. "codec_out0_0", "codec_out0_1", "codec_out1_0", "codec_out1_1",
  982. "codec_out2_0", "codec_out2_1", "codec_out3_0", "codec_out3_1", /* not supported by FW */
  983. };
  984. #define SST_INTERLEAVER(xpname, slot_name, slotno) \
  985. SST_SSP_SLOT_CTL(xpname, "tx interleaver", slot_name, slotno, true, \
  986. channel_names, sst_slot_get, sst_slot_put)
  987. #define SST_DEINTERLEAVER(xpname, channel_name, channel_no) \
  988. SST_SSP_SLOT_CTL(xpname, "rx deinterleaver", channel_name, channel_no, false, \
  989. slot_names, sst_slot_get, sst_slot_put)
  990. static const struct snd_kcontrol_new sst_slot_controls[] = {
  991. SST_INTERLEAVER("codec_out", "slot 0", 0),
  992. SST_INTERLEAVER("codec_out", "slot 1", 1),
  993. SST_INTERLEAVER("codec_out", "slot 2", 2),
  994. SST_INTERLEAVER("codec_out", "slot 3", 3),
  995. SST_DEINTERLEAVER("codec_in", "codec_in0_0", 0),
  996. SST_DEINTERLEAVER("codec_in", "codec_in0_1", 1),
  997. SST_DEINTERLEAVER("codec_in", "codec_in1_0", 2),
  998. SST_DEINTERLEAVER("codec_in", "codec_in1_1", 3),
  999. };
  1000. /* Gain helper with min/max set */
  1001. #define SST_GAIN(name, path_id, task_id, instance, gain_var) \
  1002. SST_GAIN_KCONTROLS(name, "Gain", SST_GAIN_MIN_VALUE, SST_GAIN_MAX_VALUE, \
  1003. SST_GAIN_TC_MIN, SST_GAIN_TC_MAX, \
  1004. sst_gain_get, sst_gain_put, \
  1005. SST_MODULE_ID_GAIN_CELL, path_id, instance, task_id, \
  1006. sst_gain_tlv_common, gain_var)
  1007. #define SST_VOLUME(name, path_id, task_id, instance, gain_var) \
  1008. SST_GAIN_KCONTROLS(name, "Volume", SST_GAIN_MIN_VALUE, SST_GAIN_MAX_VALUE, \
  1009. SST_GAIN_TC_MIN, SST_GAIN_TC_MAX, \
  1010. sst_gain_get, sst_gain_put, \
  1011. SST_MODULE_ID_VOLUME, path_id, instance, task_id, \
  1012. sst_gain_tlv_common, gain_var)
  1013. static struct sst_gain_value sst_gains[];
  1014. static const struct snd_kcontrol_new sst_gain_controls[] = {
  1015. SST_GAIN("media0_in", SST_PATH_INDEX_MEDIA0_IN, SST_TASK_MMX, 0, &sst_gains[0]),
  1016. SST_GAIN("media1_in", SST_PATH_INDEX_MEDIA1_IN, SST_TASK_MMX, 0, &sst_gains[1]),
  1017. SST_GAIN("media2_in", SST_PATH_INDEX_MEDIA2_IN, SST_TASK_MMX, 0, &sst_gains[2]),
  1018. SST_GAIN("media3_in", SST_PATH_INDEX_MEDIA3_IN, SST_TASK_MMX, 0, &sst_gains[3]),
  1019. SST_GAIN("pcm0_in", SST_PATH_INDEX_PCM0_IN, SST_TASK_SBA, 0, &sst_gains[4]),
  1020. SST_GAIN("pcm1_in", SST_PATH_INDEX_PCM1_IN, SST_TASK_SBA, 0, &sst_gains[5]),
  1021. SST_GAIN("pcm1_out", SST_PATH_INDEX_PCM1_OUT, SST_TASK_SBA, 0, &sst_gains[6]),
  1022. SST_GAIN("pcm2_out", SST_PATH_INDEX_PCM2_OUT, SST_TASK_SBA, 0, &sst_gains[7]),
  1023. SST_GAIN("codec_in0", SST_PATH_INDEX_CODEC_IN0, SST_TASK_SBA, 0, &sst_gains[8]),
  1024. SST_GAIN("codec_in1", SST_PATH_INDEX_CODEC_IN1, SST_TASK_SBA, 0, &sst_gains[9]),
  1025. SST_GAIN("codec_out0", SST_PATH_INDEX_CODEC_OUT0, SST_TASK_SBA, 0, &sst_gains[10]),
  1026. SST_GAIN("codec_out1", SST_PATH_INDEX_CODEC_OUT1, SST_TASK_SBA, 0, &sst_gains[11]),
  1027. SST_GAIN("media_loop1_out", SST_PATH_INDEX_MEDIA_LOOP1_OUT, SST_TASK_SBA, 0, &sst_gains[12]),
  1028. SST_GAIN("media_loop2_out", SST_PATH_INDEX_MEDIA_LOOP2_OUT, SST_TASK_SBA, 0, &sst_gains[13]),
  1029. SST_GAIN("sprot_loop_out", SST_PATH_INDEX_SPROT_LOOP_OUT, SST_TASK_SBA, 0, &sst_gains[14]),
  1030. SST_VOLUME("media0_in", SST_PATH_INDEX_MEDIA0_IN, SST_TASK_MMX, 0, &sst_gains[15]),
  1031. };
  1032. #define SST_GAIN_NUM_CONTROLS 3
  1033. /* the SST_GAIN macro above will create three alsa controls for each
  1034. * instance invoked, gain, mute and ramp duration, which use the same gain
  1035. * cell sst_gain to keep track of data
  1036. * To calculate number of gain cell instances we need to device by 3 in
  1037. * below caulcation for gain cell memory.
  1038. * This gets rid of static number and issues while adding new controls
  1039. */
  1040. static struct sst_gain_value sst_gains[ARRAY_SIZE(sst_gain_controls)/SST_GAIN_NUM_CONTROLS];
  1041. static const struct snd_kcontrol_new sst_algo_controls[] = {
  1042. SST_ALGO_KCONTROL_BYTES("media_loop1_out", "fir", 272, SST_MODULE_ID_FIR_24,
  1043. SST_PATH_INDEX_MEDIA_LOOP1_OUT, 0, SST_TASK_SBA, SBA_VB_SET_FIR),
  1044. SST_ALGO_KCONTROL_BYTES("media_loop1_out", "iir", 300, SST_MODULE_ID_IIR_24,
  1045. SST_PATH_INDEX_MEDIA_LOOP1_OUT, 0, SST_TASK_SBA, SBA_VB_SET_IIR),
  1046. SST_ALGO_KCONTROL_BYTES("media_loop1_out", "mdrp", 286, SST_MODULE_ID_MDRP,
  1047. SST_PATH_INDEX_MEDIA_LOOP1_OUT, 0, SST_TASK_SBA, SBA_SET_MDRP),
  1048. SST_ALGO_KCONTROL_BYTES("media_loop2_out", "fir", 272, SST_MODULE_ID_FIR_24,
  1049. SST_PATH_INDEX_MEDIA_LOOP2_OUT, 0, SST_TASK_SBA, SBA_VB_SET_FIR),
  1050. SST_ALGO_KCONTROL_BYTES("media_loop2_out", "iir", 300, SST_MODULE_ID_IIR_24,
  1051. SST_PATH_INDEX_MEDIA_LOOP2_OUT, 0, SST_TASK_SBA, SBA_VB_SET_IIR),
  1052. SST_ALGO_KCONTROL_BYTES("media_loop2_out", "mdrp", 286, SST_MODULE_ID_MDRP,
  1053. SST_PATH_INDEX_MEDIA_LOOP2_OUT, 0, SST_TASK_SBA, SBA_SET_MDRP),
  1054. SST_ALGO_KCONTROL_BYTES("sprot_loop_out", "lpro", 192, SST_MODULE_ID_SPROT,
  1055. SST_PATH_INDEX_SPROT_LOOP_OUT, 0, SST_TASK_SBA, SBA_VB_LPRO),
  1056. SST_ALGO_KCONTROL_BYTES("codec_in0", "dcr", 52, SST_MODULE_ID_FILT_DCR,
  1057. SST_PATH_INDEX_CODEC_IN0, 0, SST_TASK_SBA, SBA_VB_SET_IIR),
  1058. SST_ALGO_KCONTROL_BYTES("codec_in1", "dcr", 52, SST_MODULE_ID_FILT_DCR,
  1059. SST_PATH_INDEX_CODEC_IN1, 0, SST_TASK_SBA, SBA_VB_SET_IIR),
  1060. };
  1061. static int sst_algo_control_init(struct device *dev)
  1062. {
  1063. int i = 0;
  1064. struct sst_algo_control *bc;
  1065. /*allocate space to cache the algo parameters in the driver*/
  1066. for (i = 0; i < ARRAY_SIZE(sst_algo_controls); i++) {
  1067. bc = (struct sst_algo_control *)sst_algo_controls[i].private_value;
  1068. bc->params = devm_kzalloc(dev, bc->max, GFP_KERNEL);
  1069. if (bc->params == NULL)
  1070. return -ENOMEM;
  1071. }
  1072. return 0;
  1073. }
  1074. static bool is_sst_dapm_widget(struct snd_soc_dapm_widget *w)
  1075. {
  1076. switch (w->id) {
  1077. case snd_soc_dapm_pga:
  1078. case snd_soc_dapm_aif_in:
  1079. case snd_soc_dapm_aif_out:
  1080. case snd_soc_dapm_input:
  1081. case snd_soc_dapm_output:
  1082. case snd_soc_dapm_mixer:
  1083. return true;
  1084. default:
  1085. return false;
  1086. }
  1087. }
  1088. /**
  1089. * sst_send_pipe_gains - send gains for the front-end DAIs
  1090. *
  1091. * The gains in the pipes connected to the front-ends are muted/unmuted
  1092. * automatically via the digital_mute() DAPM callback. This function sends the
  1093. * gains for the front-end pipes.
  1094. */
  1095. int sst_send_pipe_gains(struct snd_soc_dai *dai, int stream, int mute)
  1096. {
  1097. struct sst_data *drv = snd_soc_dai_get_drvdata(dai);
  1098. struct snd_soc_dapm_widget *w;
  1099. struct snd_soc_dapm_path *p = NULL;
  1100. dev_dbg(dai->dev, "enter, dai-name=%s dir=%d\n", dai->name, stream);
  1101. if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
  1102. dev_dbg(dai->dev, "Stream name=%s\n",
  1103. dai->playback_widget->name);
  1104. w = dai->playback_widget;
  1105. list_for_each_entry(p, &w->sinks, list_source) {
  1106. if (p->connected && !p->connected(w, p->sink))
  1107. continue;
  1108. if (p->connect && p->sink->power &&
  1109. is_sst_dapm_widget(p->sink)) {
  1110. struct sst_ids *ids = p->sink->priv;
  1111. dev_dbg(dai->dev, "send gains for widget=%s\n",
  1112. p->sink->name);
  1113. mutex_lock(&drv->lock);
  1114. sst_set_pipe_gain(ids, drv, mute);
  1115. mutex_unlock(&drv->lock);
  1116. }
  1117. }
  1118. } else {
  1119. dev_dbg(dai->dev, "Stream name=%s\n",
  1120. dai->capture_widget->name);
  1121. w = dai->capture_widget;
  1122. list_for_each_entry(p, &w->sources, list_sink) {
  1123. if (p->connected && !p->connected(w, p->sink))
  1124. continue;
  1125. if (p->connect && p->source->power &&
  1126. is_sst_dapm_widget(p->source)) {
  1127. struct sst_ids *ids = p->source->priv;
  1128. dev_dbg(dai->dev, "send gain for widget=%s\n",
  1129. p->source->name);
  1130. mutex_lock(&drv->lock);
  1131. sst_set_pipe_gain(ids, drv, mute);
  1132. mutex_unlock(&drv->lock);
  1133. }
  1134. }
  1135. }
  1136. return 0;
  1137. }
  1138. /**
  1139. * sst_fill_module_list - populate the list of modules/gains for a pipe
  1140. *
  1141. *
  1142. * Fills the widget pointer in the kcontrol private data, and also fills the
  1143. * kcontrol pointer in the widget private data.
  1144. *
  1145. * Widget pointer is used to send the algo/gain in the .put() handler if the
  1146. * widget is powerd on.
  1147. *
  1148. * Kcontrol pointer is used to send the algo/gain in the widget power ON/OFF
  1149. * event handler. Each widget (pipe) has multiple algos stored in the algo_list.
  1150. */
  1151. static int sst_fill_module_list(struct snd_kcontrol *kctl,
  1152. struct snd_soc_dapm_widget *w, int type)
  1153. {
  1154. struct sst_module *module = NULL;
  1155. struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
  1156. struct sst_ids *ids = w->priv;
  1157. int ret = 0;
  1158. module = devm_kzalloc(c->dev, sizeof(*module), GFP_KERNEL);
  1159. if (!module)
  1160. return -ENOMEM;
  1161. if (type == SST_MODULE_GAIN) {
  1162. struct sst_gain_mixer_control *mc = (void *)kctl->private_value;
  1163. mc->w = w;
  1164. module->kctl = kctl;
  1165. list_add_tail(&module->node, &ids->gain_list);
  1166. } else if (type == SST_MODULE_ALGO) {
  1167. struct sst_algo_control *bc = (void *)kctl->private_value;
  1168. bc->w = w;
  1169. module->kctl = kctl;
  1170. list_add_tail(&module->node, &ids->algo_list);
  1171. } else {
  1172. dev_err(c->dev, "invoked for unknown type %d module %s",
  1173. type, kctl->id.name);
  1174. ret = -EINVAL;
  1175. }
  1176. return ret;
  1177. }
  1178. /**
  1179. * sst_fill_widget_module_info - fill list of gains/algos for the pipe
  1180. * @widget: pipe modelled as a DAPM widget
  1181. *
  1182. * Fill the list of gains/algos for the widget by looking at all the card
  1183. * controls and comparing the name of the widget with the first part of control
  1184. * name. First part of control name contains the pipe name (widget name).
  1185. */
  1186. static int sst_fill_widget_module_info(struct snd_soc_dapm_widget *w,
  1187. struct snd_soc_platform *platform)
  1188. {
  1189. struct snd_kcontrol *kctl;
  1190. int index, ret = 0;
  1191. struct snd_card *card = platform->component.card->snd_card;
  1192. char *idx;
  1193. down_read(&card->controls_rwsem);
  1194. list_for_each_entry(kctl, &card->controls, list) {
  1195. idx = strstr(kctl->id.name, " ");
  1196. if (idx == NULL)
  1197. continue;
  1198. index = strlen(kctl->id.name) - strlen(idx);
  1199. if (strstr(kctl->id.name, "Volume") &&
  1200. !strncmp(kctl->id.name, w->name, index))
  1201. ret = sst_fill_module_list(kctl, w, SST_MODULE_GAIN);
  1202. else if (strstr(kctl->id.name, "params") &&
  1203. !strncmp(kctl->id.name, w->name, index))
  1204. ret = sst_fill_module_list(kctl, w, SST_MODULE_ALGO);
  1205. else if (strstr(kctl->id.name, "Switch") &&
  1206. !strncmp(kctl->id.name, w->name, index) &&
  1207. strstr(kctl->id.name, "Gain")) {
  1208. struct sst_gain_mixer_control *mc =
  1209. (void *)kctl->private_value;
  1210. mc->w = w;
  1211. } else if (strstr(kctl->id.name, "interleaver") &&
  1212. !strncmp(kctl->id.name, w->name, index)) {
  1213. struct sst_enum *e = (void *)kctl->private_value;
  1214. e->w = w;
  1215. } else if (strstr(kctl->id.name, "deinterleaver") &&
  1216. !strncmp(kctl->id.name, w->name, index)) {
  1217. struct sst_enum *e = (void *)kctl->private_value;
  1218. e->w = w;
  1219. }
  1220. if (ret < 0) {
  1221. up_read(&card->controls_rwsem);
  1222. return ret;
  1223. }
  1224. }
  1225. up_read(&card->controls_rwsem);
  1226. return 0;
  1227. }
  1228. /**
  1229. * sst_fill_linked_widgets - fill the parent pointer for the linked widget
  1230. */
  1231. static void sst_fill_linked_widgets(struct snd_soc_platform *platform,
  1232. struct sst_ids *ids)
  1233. {
  1234. struct snd_soc_dapm_widget *w;
  1235. unsigned int len = strlen(ids->parent_wname);
  1236. list_for_each_entry(w, &platform->component.card->widgets, list) {
  1237. if (!strncmp(ids->parent_wname, w->name, len)) {
  1238. ids->parent_w = w;
  1239. break;
  1240. }
  1241. }
  1242. }
  1243. /**
  1244. * sst_map_modules_to_pipe - fill algo/gains list for all pipes
  1245. */
  1246. static int sst_map_modules_to_pipe(struct snd_soc_platform *platform)
  1247. {
  1248. struct snd_soc_dapm_widget *w;
  1249. int ret = 0;
  1250. list_for_each_entry(w, &platform->component.card->widgets, list) {
  1251. if (is_sst_dapm_widget(w) && (w->priv)) {
  1252. struct sst_ids *ids = w->priv;
  1253. dev_dbg(platform->dev, "widget type=%d name=%s\n",
  1254. w->id, w->name);
  1255. INIT_LIST_HEAD(&ids->algo_list);
  1256. INIT_LIST_HEAD(&ids->gain_list);
  1257. ret = sst_fill_widget_module_info(w, platform);
  1258. if (ret < 0)
  1259. return ret;
  1260. /* fill linked widgets */
  1261. if (ids->parent_wname != NULL)
  1262. sst_fill_linked_widgets(platform, ids);
  1263. }
  1264. }
  1265. return 0;
  1266. }
  1267. int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
  1268. {
  1269. int i, ret = 0;
  1270. struct snd_soc_dapm_context *dapm =
  1271. snd_soc_component_get_dapm(&platform->component);
  1272. struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
  1273. unsigned int gains = ARRAY_SIZE(sst_gain_controls)/3;
  1274. drv->byte_stream = devm_kzalloc(platform->dev,
  1275. SST_MAX_BIN_BYTES, GFP_KERNEL);
  1276. if (!drv->byte_stream)
  1277. return -ENOMEM;
  1278. snd_soc_dapm_new_controls(dapm, sst_dapm_widgets,
  1279. ARRAY_SIZE(sst_dapm_widgets));
  1280. snd_soc_dapm_add_routes(dapm, intercon,
  1281. ARRAY_SIZE(intercon));
  1282. snd_soc_dapm_new_widgets(dapm->card);
  1283. for (i = 0; i < gains; i++) {
  1284. sst_gains[i].mute = SST_GAIN_MUTE_DEFAULT;
  1285. sst_gains[i].l_gain = SST_GAIN_VOLUME_DEFAULT;
  1286. sst_gains[i].r_gain = SST_GAIN_VOLUME_DEFAULT;
  1287. sst_gains[i].ramp_duration = SST_GAIN_RAMP_DURATION_DEFAULT;
  1288. }
  1289. ret = snd_soc_add_platform_controls(platform, sst_gain_controls,
  1290. ARRAY_SIZE(sst_gain_controls));
  1291. if (ret)
  1292. return ret;
  1293. /* Initialize algo control params */
  1294. ret = sst_algo_control_init(platform->dev);
  1295. if (ret)
  1296. return ret;
  1297. ret = snd_soc_add_platform_controls(platform, sst_algo_controls,
  1298. ARRAY_SIZE(sst_algo_controls));
  1299. if (ret)
  1300. return ret;
  1301. ret = snd_soc_add_platform_controls(platform, sst_slot_controls,
  1302. ARRAY_SIZE(sst_slot_controls));
  1303. if (ret)
  1304. return ret;
  1305. ret = sst_map_modules_to_pipe(platform);
  1306. return ret;
  1307. }