Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | /*
* intel_sst_stream.c - Intel SST Driver for audio engine
*
* Copyright (C) 2008-10 Intel Corp
* Authors: Vinod Koul <vinod.koul@intel.com>
* Harsha Priya <priya.harsha@intel.com>
* Dharageswari R <dharageswari.r@intel.com>
* KP Jeeja <jeeja.kp@intel.com>
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* This file contains the stream operations of SST driver
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/pci.h>
#include <linux/firmware.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include "intel_sst_ioctl.h"
#include "intel_sst.h"
#include "intel_sst_fw_ipc.h"
#include "intel_sst_common.h"
/*
* sst_check_device_type - Check the medfield device type
*
* @device: Device to be checked
* @num_ch: Number of channels queried
* @pcm_slot: slot to be enabled for this device
*
* This checks the deivce against the map and calculates pcm_slot value
*/
int sst_check_device_type(u32 device, u32 num_chan, u32 *pcm_slot)
{
if (device >= MAX_NUM_STREAMS_MFLD) {
pr_debug("device type invalid %d\n", device);
return -EINVAL;
}
if (sst_drv_ctx->streams[device].status == STREAM_UN_INIT) {
if (device == SND_SST_DEVICE_VIBRA && num_chan == 1)
*pcm_slot = 0x10;
else if (device == SND_SST_DEVICE_HAPTIC && num_chan == 1)
*pcm_slot = 0x20;
else if (device == SND_SST_DEVICE_IHF && num_chan == 1)
*pcm_slot = 0x04;
else if (device == SND_SST_DEVICE_IHF && num_chan == 2)
*pcm_slot = 0x0C;
else if (device == SND_SST_DEVICE_HEADSET && num_chan == 1)
*pcm_slot = 0x01;
else if (device == SND_SST_DEVICE_HEADSET && num_chan == 2)
*pcm_slot = 0x03;
else if (device == SND_SST_DEVICE_CAPTURE && num_chan == 1)
*pcm_slot = 0x01;
else if (device == SND_SST_DEVICE_CAPTURE && num_chan == 2)
*pcm_slot = 0x03;
else if (device == SND_SST_DEVICE_CAPTURE && num_chan == 3)
*pcm_slot = 0x07;
else if (device == SND_SST_DEVICE_CAPTURE && num_chan == 4)
*pcm_slot = 0x0F;
else if (device == SND_SST_DEVICE_CAPTURE && num_chan > 4)
*pcm_slot = 0x1F;
else {
pr_debug("No condition satisfied.. ret err\n");
return -EINVAL;
}
} else {
pr_debug("this stream state is not uni-init, is %d\n",
sst_drv_ctx->streams[device].status);
return -EBADRQC;
}
pr_debug("returning slot %x\n", *pcm_slot);
return 0;
}
/**
* get_mrst_stream_id - gets a new stream id for use
*
* This functions searches the current streams and allocated an empty stream
* lock stream_lock required to be held before calling this
*/
static unsigned int get_mrst_stream_id(void)
{
int i;
for (i = 1; i <= MAX_NUM_STREAMS_MRST; i++) {
if (sst_drv_ctx->streams[i].status == STREAM_UN_INIT)
return i;
}
pr_debug("Didn't find empty stream for mrst\n");
return -EBUSY;
}
/**
* sst_alloc_stream - Send msg for a new stream ID
*
* @params: stream params
* @stream_ops: operation of stream PB/capture
* @codec: codec for stream
* @device: device stream to be allocated for
*
* This function is called by any function which wants to start
* a new stream. This also check if a stream exists which is idle
* it initializes idle stream id to this request
*/
int sst_alloc_stream(char *params, unsigned int stream_ops,
u8 codec, unsigned int device)
{
struct ipc_post *msg = NULL;
struct snd_sst_alloc_params alloc_param;
unsigned int pcm_slot = 0, num_ch;
int str_id;
struct snd_sst_stream_params *sparams;
struct stream_info *str_info;
pr_debug("SST DBG:entering sst_alloc_stream\n");
pr_debug("SST DBG:%d %d %d\n", stream_ops, codec, device);
BUG_ON(!params);
sparams = (struct snd_sst_stream_params *)params;
num_ch = sparams->uc.pcm_params.num_chan;
/*check the device type*/
if (sst_drv_ctx->pci_id == SST_MFLD_PCI_ID) {
if (sst_check_device_type(device, num_ch, &pcm_slot))
return -EINVAL;
mutex_lock(&sst_drv_ctx->stream_lock);
str_id = device;
mutex_unlock(&sst_drv_ctx->stream_lock);
pr_debug("SST_DBG: slot %x\n", pcm_slot);
} else {
mutex_lock(&sst_drv_ctx->stream_lock);
str_id = get_mrst_stream_id();
mutex_unlock(&sst_drv_ctx->stream_lock);
if (str_id <= 0)
return -EBUSY;
}
/*allocate device type context*/
sst_init_stream(&sst_drv_ctx->streams[str_id], codec,
str_id, stream_ops, pcm_slot, device);
/* send msg to FW to allocate a stream */
if (sst_create_large_msg(&msg))
return -ENOMEM;
sst_fill_header(&msg->header, IPC_IA_ALLOC_STREAM, 1, str_id);
msg->header.part.data = sizeof(alloc_param) + sizeof(u32);
alloc_param.str_type.codec_type = codec;
alloc_param.str_type.str_type = SST_STREAM_TYPE_MUSIC;
alloc_param.str_type.operation = stream_ops;
alloc_param.str_type.protected_str = 0; /* non drm */
alloc_param.str_type.time_slots = pcm_slot;
alloc_param.str_type.result = alloc_param.str_type.reserved = 0;
memcpy(&alloc_param.stream_params, params,
sizeof(struct snd_sst_stream_params));
memcpy(msg->mailbox_data, &msg->header, sizeof(u32));
memcpy(msg->mailbox_data + sizeof(u32), &alloc_param,
sizeof(alloc_param));
str_info = &sst_drv_ctx->streams[str_id];
str_info->ctrl_blk.condition = false;
str_info->ctrl_blk.ret_code = 0;
str_info->ctrl_blk.on = true;
spin_lock(&sst_drv_ctx->list_spin_lock);
list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list);
spin_unlock(&sst_drv_ctx->list_spin_lock);
sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
pr_debug("SST DBG:alloc stream done\n");
return str_id;
}
/*
* sst_alloc_stream_response - process alloc reply
*
* @str_id: stream id for which the stream has been allocated
* @resp the stream response from firware
*
* This function is called by firmware as a response to stream allcoation
* request
*/
int sst_alloc_stream_response(unsigned int str_id,
struct snd_sst_alloc_response *resp)
{
int retval = 0;
struct stream_info *str_info;
struct snd_sst_lib_download *lib_dnld;
pr_debug("SST DEBUG: stream number given = %d\n", str_id);
str_info = &sst_drv_ctx->streams[str_id];
if (resp->str_type.result == SST_LIB_ERR_LIB_DNLD_REQUIRED) {
lib_dnld = kzalloc(sizeof(*lib_dnld), GFP_KERNEL);
memcpy(lib_dnld, &resp->lib_dnld, sizeof(*lib_dnld));
} else
lib_dnld = NULL;
if (str_info->ctrl_blk.on == true) {
str_info->ctrl_blk.on = false;
str_info->ctrl_blk.data = lib_dnld;
str_info->ctrl_blk.condition = true;
str_info->ctrl_blk.ret_code = resp->str_type.result;
pr_debug("SST DEBUG: sst_alloc_stream_response: waking up.\n");
wake_up(&sst_drv_ctx->wait_queue);
}
return retval;
}
/**
* sst_get_fw_info - Send msg to query for firmware configurations
* @info: out param that holds the firmare configurations
*
* This function is called when the firmware configurations are queiried for
*/
int sst_get_fw_info(struct snd_sst_fw_info *info)
{
int retval = 0;
struct ipc_post *msg = NULL;
pr_debug("SST DBG:sst_get_fw_info called\n");
if (sst_create_short_msg(&msg)) {
pr_err("SST ERR: message creation failed\n");
return -ENOMEM;
}
sst_fill_header(&msg->header, IPC_IA_GET_FW_INFO, 0, 0);
sst_drv_ctx->fw_info_blk.condition = false;
sst_drv_ctx->fw_info_blk.ret_code = 0;
sst_drv_ctx->fw_info_blk.on = true;
sst_drv_ctx->fw_info_blk.data = info;
spin_lock(&sst_drv_ctx->list_spin_lock);
list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list);
spin_unlock(&sst_drv_ctx->list_spin_lock);
sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
retval = sst_wait_interruptible_timeout(sst_drv_ctx,
&sst_drv_ctx->fw_info_blk, SST_BLOCK_TIMEOUT);
if (retval) {
pr_err("SST ERR: error in fw_info = %d\n", retval);
retval = -EIO;
}
return retval;
}
/**
* sst_pause_stream - Send msg for a pausing stream
* @str_id: stream ID
*
* This function is called by any function which wants to pause
* an already running stream.
*/
int sst_start_stream(int str_id)
{
int retval = 0;
struct ipc_post *msg = NULL;
struct stream_info *str_info;
pr_debug("sst_start_stream for %d\n", str_id);
retval = sst_validate_strid(str_id);
if (retval)
return retval;
str_info = &sst_drv_ctx->streams[str_id];
if (str_info->status != STREAM_INIT)
return -EBADRQC;
if (sst_create_short_msg(&msg))
return -ENOMEM;
sst_fill_header(&msg->header, IPC_IA_START_STREAM, 0, str_id);
spin_lock(&sst_drv_ctx->list_spin_lock);
list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list);
spin_unlock(&sst_drv_ctx->list_spin_lock);
sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
return retval;
}
/*
* sst_pause_stream - Send msg for a pausing stream
* @str_id: stream ID
*
* This function is called by any function which wants to pause
* an already running stream.
*/
int sst_pause_stream(int str_id)
{
int retval = 0;
struct ipc_post *msg = NULL;
struct stream_info *str_info;
pr_debug("SST DBG:sst_pause_stream for %d\n", str_id);
retval = sst_validate_strid(str_id);
if (retval)
return retval;
str_info = &sst_drv_ctx->streams[str_id];
if (str_info->status == STREAM_PAUSED)
return 0;
if (str_info->status == STREAM_RUNNING ||
str_info->status == STREAM_INIT) {
if (str_info->prev == STREAM_UN_INIT)
return -EBADRQC;
if (str_info->ctrl_blk.on == true) {
pr_err("SST ERR: control path is in use\n");
return -EINVAL;
}
if (sst_create_short_msg(&msg))
return -ENOMEM;
sst_fill_header(&msg->header, IPC_IA_PAUSE_STREAM, 0, str_id);
str_info->ctrl_blk.condition = false;
str_info->ctrl_blk.ret_code = 0;
str_info->ctrl_blk.on = true;
spin_lock(&sst_drv_ctx->list_spin_lock);
list_add_tail(&msg->node,
&sst_drv_ctx->ipc_dispatch_list);
spin_unlock(&sst_drv_ctx->list_spin_lock);
sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
retval = sst_wait_interruptible_timeout(sst_drv_ctx,
&str_info->ctrl_blk, SST_BLOCK_TIMEOUT);
if (retval == 0) {
str_info->prev = str_info->status;
str_info->status = STREAM_PAUSED;
} else if (retval == SST_ERR_INVALID_STREAM_ID) {
retval = -EINVAL;
mutex_lock(&sst_drv_ctx->stream_lock);
sst_clean_stream(str_info);
mutex_unlock(&sst_drv_ctx->stream_lock);
}
} else {
retval = -EBADRQC;
pr_err("SST ERR: BADQRC for stream\n");
}
return retval;
}
/**
* sst_resume_stream - Send msg for resuming stream
* @str_id: stream ID
*
* This function is called by any function which wants to resume
* an already paused stream.
*/
int sst_resume_stream(int str_id)
{
int retval = 0;
struct ipc_post *msg = NULL;
struct stream_info *str_info;
pr_debug("SST DBG:sst_resume_stream for %d\n", str_id);
retval = sst_validate_strid(str_id);
if (retval)
return retval;
str_info = &sst_drv_ctx->streams[str_id];
if (str_info->status == STREAM_RUNNING)
return 0;
if (str_info->status == STREAM_PAUSED) {
if (str_info->ctrl_blk.on == true) {
pr_err("SST ERR: control path in use\n");
return -EINVAL;
}
if (sst_create_short_msg(&msg)) {
pr_err("SST ERR: mem allocation failed\n");
return -ENOMEM;
}
sst_fill_header(&msg->header, IPC_IA_RESUME_STREAM, 0, str_id);
str_info->ctrl_blk.condition = false;
str_info->ctrl_blk.ret_code = 0;
str_info->ctrl_blk.on = true;
spin_lock(&sst_drv_ctx->list_spin_lock);
list_add_tail(&msg->node,
&sst_drv_ctx->ipc_dispatch_list);
spin_unlock(&sst_drv_ctx->list_spin_lock);
sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
retval = sst_wait_interruptible_timeout(sst_drv_ctx,
&str_info->ctrl_blk, SST_BLOCK_TIMEOUT);
if (!retval) {
if (str_info->prev == STREAM_RUNNING)
str_info->status = STREAM_RUNNING;
else
str_info->status = STREAM_INIT;
str_info->prev = STREAM_PAUSED;
} else if (retval == -SST_ERR_INVALID_STREAM_ID) {
retval = -EINVAL;
mutex_lock(&sst_drv_ctx->stream_lock);
sst_clean_stream(str_info);
mutex_unlock(&sst_drv_ctx->stream_lock);
}
} else {
retval = -EBADRQC;
pr_err("SST ERR: BADQRC for stream\n");
}
return retval;
}
/**
* sst_drop_stream - Send msg for stopping stream
* @str_id: stream ID
*
* This function is called by any function which wants to stop
* a stream.
*/
int sst_drop_stream(int str_id)
{
int retval = 0;
struct ipc_post *msg = NULL;
struct sst_stream_bufs *bufs = NULL, *_bufs;
struct stream_info *str_info;
pr_debug("SST DBG:sst_drop_stream for %d\n", str_id);
retval = sst_validate_strid(str_id);
if (retval)
return retval;
str_info = &sst_drv_ctx->streams[str_id];
if (str_info->status != STREAM_UN_INIT &&
str_info->status != STREAM_DECODE) {
if (str_info->ctrl_blk.on == true) {
pr_err("SST ERR: control path in use\n");
return -EINVAL;
}
if (sst_create_short_msg(&msg)) {
pr_err("SST ERR: mem allocation failed\n");
return -ENOMEM;
}
sst_fill_header(&msg->header, IPC_IA_DROP_STREAM, 0, str_id);
str_info->ctrl_blk.condition = false;
str_info->ctrl_blk.ret_code = 0;
str_info->ctrl_blk.on = true;
spin_lock(&sst_drv_ctx->list_spin_lock);
list_add_tail(&msg->node,
&sst_drv_ctx->ipc_dispatch_list);
spin_unlock(&sst_drv_ctx->list_spin_lock);
sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
retval = sst_wait_interruptible_timeout(sst_drv_ctx,
&str_info->ctrl_blk, SST_BLOCK_TIMEOUT);
if (!retval) {
pr_debug("SST DBG:drop success\n");
str_info->prev = STREAM_UN_INIT;
str_info->status = STREAM_INIT;
if (str_info->src != MAD_DRV) {
mutex_lock(&str_info->lock);
list_for_each_entry_safe(bufs, _bufs,
&str_info->bufs, node) {
list_del(&bufs->node);
kfree(bufs);
}
mutex_unlock(&str_info->lock);
}
str_info->cumm_bytes += str_info->curr_bytes;
} else if (retval == -SST_ERR_INVALID_STREAM_ID) {
retval = -EINVAL;
mutex_lock(&sst_drv_ctx->stream_lock);
sst_clean_stream(str_info);
mutex_unlock(&sst_drv_ctx->stream_lock);
}
if (str_info->data_blk.on == true) {
str_info->data_blk.condition = true;
str_info->data_blk.ret_code = retval;
wake_up(&sst_drv_ctx->wait_queue);
}
} else {
retval = -EBADRQC;
pr_err("SST ERR: BADQRC for stream\n");
}
return retval;
}
/**
* sst_drain_stream - Send msg for draining stream
* @str_id: stream ID
*
* This function is called by any function which wants to drain
* a stream.
*/
int sst_drain_stream(int str_id)
{
int retval = 0;
struct ipc_post *msg = NULL;
struct stream_info *str_info;
pr_debug("SST DBG:sst_drain_stream for %d\n", str_id);
retval = sst_validate_strid(str_id);
if (retval)
return retval;
str_info = &sst_drv_ctx->streams[str_id];
if (str_info->status != STREAM_RUNNING &&
str_info->status != STREAM_INIT &&
str_info->status != STREAM_PAUSED) {
pr_err("SST ERR: BADQRC for stream = %d\n",
str_info->status);
return -EBADRQC;
}
if (str_info->status == STREAM_INIT) {
if (sst_create_short_msg(&msg)) {
pr_err("SST ERR: mem allocation failed\n");
return -ENOMEM;
}
sst_fill_header(&msg->header, IPC_IA_DRAIN_STREAM, 0, str_id);
spin_lock(&sst_drv_ctx->list_spin_lock);
list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list);
spin_unlock(&sst_drv_ctx->list_spin_lock);
sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
} else
str_info->need_draining = true;
str_info->data_blk.condition = false;
str_info->data_blk.ret_code = 0;
str_info->data_blk.on = true;
retval = sst_wait_interruptible(sst_drv_ctx, &str_info->data_blk);
str_info->need_draining = false;
return retval;
}
/**
* sst_free_stream - Frees a stream
* @str_id: stream ID
*
* This function is called by any function which wants to free
* a stream.
*/
int sst_free_stream(int str_id)
{
int retval = 0;
struct ipc_post *msg = NULL;
struct stream_info *str_info;
pr_debug("SST DBG:sst_free_stream for %d\n", str_id);
retval = sst_validate_strid(str_id);
if (retval)
return retval;
str_info = &sst_drv_ctx->streams[str_id];
if (str_info->status != STREAM_UN_INIT) {
if (sst_create_short_msg(&msg)) {
pr_err("SST ERR: mem allocation failed\n");
return -ENOMEM;
}
sst_fill_header(&msg->header, IPC_IA_FREE_STREAM, 0, str_id);
spin_lock(&sst_drv_ctx->list_spin_lock);
list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list);
spin_unlock(&sst_drv_ctx->list_spin_lock);
sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
str_info->prev = str_info->status;
str_info->status = STREAM_UN_INIT;
if (str_info->data_blk.on == true) {
str_info->data_blk.condition = true;
str_info->data_blk.ret_code = 0;
wake_up(&sst_drv_ctx->wait_queue);
}
str_info->data_blk.on = true;
str_info->data_blk.condition = false;
retval = sst_wait_interruptible_timeout(sst_drv_ctx,
&str_info->ctrl_blk, SST_BLOCK_TIMEOUT);
pr_debug("wait for free returned %d\n", retval);
msleep(100);
mutex_lock(&sst_drv_ctx->stream_lock);
sst_clean_stream(str_info);
mutex_unlock(&sst_drv_ctx->stream_lock);
pr_debug("SST DBG:Stream freed\n");
} else {
retval = -EBADRQC;
pr_debug("SST DBG:BADQRC for stream\n");
}
return retval;
}
|