sst-atom-controls.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539
  1. /*
  2. * sst-atom-controls.c - Intel MID Platform driver DPCM ALSA controls for Mrfld
  3. *
  4. * Copyright (C) 2013-14 Intel Corp
  5. * Author: Omair Mohammed Abdullah <omair.m.abdullah@intel.com>
  6. * Vinod Koul <vinod.koul@intel.com>
  7. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; version 2 of the License.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * In the dpcm driver modelling when a particular FE/BE/Mixer/Pipe is active
  19. * we forward the settings and parameters, rest we keep the values in
  20. * driver and forward when DAPM enables them
  21. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  22. */
  23. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  24. #include <linux/slab.h>
  25. #include <sound/soc.h>
  26. #include <sound/tlv.h>
  27. #include "sst-mfld-platform.h"
  28. #include "sst-atom-controls.h"
  29. static int sst_fill_byte_control(struct sst_data *drv,
  30. u8 ipc_msg, u8 block,
  31. u8 task_id, u8 pipe_id,
  32. u16 len, void *cmd_data)
  33. {
  34. struct snd_sst_bytes_v2 *byte_data = drv->byte_stream;
  35. byte_data->type = SST_CMD_BYTES_SET;
  36. byte_data->ipc_msg = ipc_msg;
  37. byte_data->block = block;
  38. byte_data->task_id = task_id;
  39. byte_data->pipe_id = pipe_id;
  40. if (len > SST_MAX_BIN_BYTES - sizeof(*byte_data)) {
  41. dev_err(&drv->pdev->dev, "command length too big (%u)", len);
  42. return -EINVAL;
  43. }
  44. byte_data->len = len;
  45. memcpy(byte_data->bytes, cmd_data, len);
  46. print_hex_dump_bytes("writing to lpe: ", DUMP_PREFIX_OFFSET,
  47. byte_data, len + sizeof(*byte_data));
  48. return 0;
  49. }
  50. static int sst_fill_and_send_cmd_unlocked(struct sst_data *drv,
  51. u8 ipc_msg, u8 block, u8 task_id, u8 pipe_id,
  52. void *cmd_data, u16 len)
  53. {
  54. int ret = 0;
  55. ret = sst_fill_byte_control(drv, ipc_msg,
  56. block, task_id, pipe_id, len, cmd_data);
  57. if (ret < 0)
  58. return ret;
  59. return sst->ops->send_byte_stream(sst->dev, drv->byte_stream);
  60. }
  61. /**
  62. * sst_fill_and_send_cmd - generate the IPC message and send it to the FW
  63. * @ipc_msg: type of IPC (CMD, SET_PARAMS, GET_PARAMS)
  64. * @cmd_data: the IPC payload
  65. */
  66. static int sst_fill_and_send_cmd(struct sst_data *drv,
  67. u8 ipc_msg, u8 block, u8 task_id, u8 pipe_id,
  68. void *cmd_data, u16 len)
  69. {
  70. int ret;
  71. mutex_lock(&drv->lock);
  72. ret = sst_fill_and_send_cmd_unlocked(drv, ipc_msg, block,
  73. task_id, pipe_id, cmd_data, len);
  74. mutex_unlock(&drv->lock);
  75. return ret;
  76. }
  77. /**
  78. * tx map value is a bitfield where each bit represents a FW channel
  79. *
  80. * 3 2 1 0 # 0 = codec0, 1 = codec1
  81. * RLRLRLRL # 3, 4 = reserved
  82. *
  83. * e.g. slot 0 rx map = 00001100b -> data from slot 0 goes into codec_in1 L,R
  84. */
  85. static u8 sst_ssp_tx_map[SST_MAX_TDM_SLOTS] = {
  86. 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, /* default rx map */
  87. };
  88. /**
  89. * rx map value is a bitfield where each bit represents a slot
  90. *
  91. * 76543210 # 0 = slot 0, 1 = slot 1
  92. *
  93. * e.g. codec1_0 tx map = 00000101b -> data from codec_out1_0 goes into slot 0, 2
  94. */
  95. static u8 sst_ssp_rx_map[SST_MAX_TDM_SLOTS] = {
  96. 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, /* default tx map */
  97. };
  98. /**
  99. * NOTE: this is invoked with lock held
  100. */
  101. static int sst_send_slot_map(struct sst_data *drv)
  102. {
  103. struct sst_param_sba_ssp_slot_map cmd;
  104. SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
  105. cmd.header.command_id = SBA_SET_SSP_SLOT_MAP;
  106. cmd.header.length = sizeof(struct sst_param_sba_ssp_slot_map)
  107. - sizeof(struct sst_dsp_header);
  108. cmd.param_id = SBA_SET_SSP_SLOT_MAP;
  109. cmd.param_len = sizeof(cmd.rx_slot_map) + sizeof(cmd.tx_slot_map)
  110. + sizeof(cmd.ssp_index);
  111. cmd.ssp_index = SSP_CODEC;
  112. memcpy(cmd.rx_slot_map, &sst_ssp_tx_map[0], sizeof(cmd.rx_slot_map));
  113. memcpy(cmd.tx_slot_map, &sst_ssp_rx_map[0], sizeof(cmd.tx_slot_map));
  114. return sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_SET_PARAMS,
  115. SST_FLAG_BLOCKED, SST_TASK_SBA, 0, &cmd,
  116. sizeof(cmd.header) + cmd.header.length);
  117. }
  118. static int sst_slot_enum_info(struct snd_kcontrol *kcontrol,
  119. struct snd_ctl_elem_info *uinfo)
  120. {
  121. struct sst_enum *e = (struct sst_enum *)kcontrol->private_value;
  122. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  123. uinfo->count = 1;
  124. uinfo->value.enumerated.items = e->max;
  125. if (uinfo->value.enumerated.item > e->max - 1)
  126. uinfo->value.enumerated.item = e->max - 1;
  127. strcpy(uinfo->value.enumerated.name,
  128. e->texts[uinfo->value.enumerated.item]);
  129. return 0;
  130. }
  131. /**
  132. * sst_slot_get - get the status of the interleaver/deinterleaver control
  133. *
  134. * Searches the map where the control status is stored, and gets the
  135. * channel/slot which is currently set for this enumerated control. Since it is
  136. * an enumerated control, there is only one possible value.
  137. */
  138. static int sst_slot_get(struct snd_kcontrol *kcontrol,
  139. struct snd_ctl_elem_value *ucontrol)
  140. {
  141. struct sst_enum *e = (void *)kcontrol->private_value;
  142. struct snd_soc_component *c = snd_kcontrol_chip(kcontrol);
  143. struct sst_data *drv = snd_soc_component_get_drvdata(c);
  144. unsigned int ctl_no = e->reg;
  145. unsigned int is_tx = e->tx;
  146. unsigned int val, mux;
  147. u8 *map = is_tx ? sst_ssp_rx_map : sst_ssp_tx_map;
  148. mutex_lock(&drv->lock);
  149. val = 1 << ctl_no;
  150. /* search which slot/channel has this bit set - there should be only one */
  151. for (mux = e->max; mux > 0; mux--)
  152. if (map[mux - 1] & val)
  153. break;
  154. ucontrol->value.enumerated.item[0] = mux;
  155. mutex_unlock(&drv->lock);
  156. dev_dbg(c->dev, "%s - %s map = %#x\n",
  157. is_tx ? "tx channel" : "rx slot",
  158. e->texts[mux], mux ? map[mux - 1] : -1);
  159. return 0;
  160. }
  161. /* sst_check_and_send_slot_map - helper for checking power state and sending
  162. * slot map cmd
  163. *
  164. * called with lock held
  165. */
  166. static int sst_check_and_send_slot_map(struct sst_data *drv, struct snd_kcontrol *kcontrol)
  167. {
  168. struct sst_enum *e = (void *)kcontrol->private_value;
  169. int ret = 0;
  170. if (e->w && e->w->power)
  171. ret = sst_send_slot_map(drv);
  172. else
  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. snd_soc_dapm_widget_for_each_sink_path(w, p) {
  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. snd_soc_dapm_widget_for_each_source_path(w, p) {
  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 = strchr(kctl->id.name, ' ');
  1196. if (idx == NULL)
  1197. continue;
  1198. index = idx - (char*)kctl->id.name;
  1199. if (strncmp(kctl->id.name, w->name, index))
  1200. continue;
  1201. if (strstr(kctl->id.name, "Volume"))
  1202. ret = sst_fill_module_list(kctl, w, SST_MODULE_GAIN);
  1203. else if (strstr(kctl->id.name, "params"))
  1204. ret = sst_fill_module_list(kctl, w, SST_MODULE_ALGO);
  1205. else if (strstr(kctl->id.name, "Switch") &&
  1206. strstr(kctl->id.name, "Gain")) {
  1207. struct sst_gain_mixer_control *mc =
  1208. (void *)kctl->private_value;
  1209. mc->w = w;
  1210. } else if (strstr(kctl->id.name, "interleaver")) {
  1211. struct sst_enum *e = (void *)kctl->private_value;
  1212. e->w = w;
  1213. } else if (strstr(kctl->id.name, "deinterleaver")) {
  1214. struct sst_enum *e = (void *)kctl->private_value;
  1215. e->w = w;
  1216. }
  1217. if (ret < 0) {
  1218. up_read(&card->controls_rwsem);
  1219. return ret;
  1220. }
  1221. }
  1222. up_read(&card->controls_rwsem);
  1223. return 0;
  1224. }
  1225. /**
  1226. * sst_fill_linked_widgets - fill the parent pointer for the linked widget
  1227. */
  1228. static void sst_fill_linked_widgets(struct snd_soc_platform *platform,
  1229. struct sst_ids *ids)
  1230. {
  1231. struct snd_soc_dapm_widget *w;
  1232. unsigned int len = strlen(ids->parent_wname);
  1233. list_for_each_entry(w, &platform->component.card->widgets, list) {
  1234. if (!strncmp(ids->parent_wname, w->name, len)) {
  1235. ids->parent_w = w;
  1236. break;
  1237. }
  1238. }
  1239. }
  1240. /**
  1241. * sst_map_modules_to_pipe - fill algo/gains list for all pipes
  1242. */
  1243. static int sst_map_modules_to_pipe(struct snd_soc_platform *platform)
  1244. {
  1245. struct snd_soc_dapm_widget *w;
  1246. int ret = 0;
  1247. list_for_each_entry(w, &platform->component.card->widgets, list) {
  1248. if (is_sst_dapm_widget(w) && (w->priv)) {
  1249. struct sst_ids *ids = w->priv;
  1250. dev_dbg(platform->dev, "widget type=%d name=%s\n",
  1251. w->id, w->name);
  1252. INIT_LIST_HEAD(&ids->algo_list);
  1253. INIT_LIST_HEAD(&ids->gain_list);
  1254. ret = sst_fill_widget_module_info(w, platform);
  1255. if (ret < 0)
  1256. return ret;
  1257. /* fill linked widgets */
  1258. if (ids->parent_wname != NULL)
  1259. sst_fill_linked_widgets(platform, ids);
  1260. }
  1261. }
  1262. return 0;
  1263. }
  1264. int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
  1265. {
  1266. int i, ret = 0;
  1267. struct snd_soc_dapm_context *dapm =
  1268. snd_soc_component_get_dapm(&platform->component);
  1269. struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
  1270. unsigned int gains = ARRAY_SIZE(sst_gain_controls)/3;
  1271. drv->byte_stream = devm_kzalloc(platform->dev,
  1272. SST_MAX_BIN_BYTES, GFP_KERNEL);
  1273. if (!drv->byte_stream)
  1274. return -ENOMEM;
  1275. snd_soc_dapm_new_controls(dapm, sst_dapm_widgets,
  1276. ARRAY_SIZE(sst_dapm_widgets));
  1277. snd_soc_dapm_add_routes(dapm, intercon,
  1278. ARRAY_SIZE(intercon));
  1279. snd_soc_dapm_new_widgets(dapm->card);
  1280. for (i = 0; i < gains; i++) {
  1281. sst_gains[i].mute = SST_GAIN_MUTE_DEFAULT;
  1282. sst_gains[i].l_gain = SST_GAIN_VOLUME_DEFAULT;
  1283. sst_gains[i].r_gain = SST_GAIN_VOLUME_DEFAULT;
  1284. sst_gains[i].ramp_duration = SST_GAIN_RAMP_DURATION_DEFAULT;
  1285. }
  1286. ret = snd_soc_add_platform_controls(platform, sst_gain_controls,
  1287. ARRAY_SIZE(sst_gain_controls));
  1288. if (ret)
  1289. return ret;
  1290. /* Initialize algo control params */
  1291. ret = sst_algo_control_init(platform->dev);
  1292. if (ret)
  1293. return ret;
  1294. ret = snd_soc_add_platform_controls(platform, sst_algo_controls,
  1295. ARRAY_SIZE(sst_algo_controls));
  1296. if (ret)
  1297. return ret;
  1298. ret = snd_soc_add_platform_controls(platform, sst_slot_controls,
  1299. ARRAY_SIZE(sst_slot_controls));
  1300. if (ret)
  1301. return ret;
  1302. ret = sst_map_modules_to_pipe(platform);
  1303. return ret;
  1304. }