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