Skip to content

Commit

Permalink
sst: Change the SST driver PCM interface
Browse files Browse the repository at this point in the history
The PCM interface in SST driver is cmds only, this patch changes the interface to open, close and cmd interface.
This allows SST driver to keep easy track of handles open

Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Vinod Koul authored and Greg Kroah-Hartman committed Nov 20, 2010
1 parent 4856ab3 commit 6f6ffec
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 88 deletions.
8 changes: 7 additions & 1 deletion drivers/staging/intel_sst/intel_sst.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* and middleware.
* This file is shared between the SST and MAD drivers
*/
#include "intel_sst_ioctl.h"

#define SST_CARD_NAMES "intel_mid_card"

Expand Down Expand Up @@ -107,10 +108,15 @@ struct snd_pmic_ops {
int (*power_down_pmic) (void);
};

struct intel_sst_pcm_control {
int (*open) (struct snd_sst_params *str_param);
int (*device_control) (int cmd, void *arg);
int (*close) (unsigned int str_id);
};
struct intel_sst_card_ops {
char *module_name;
unsigned int vendor_id;
int (*control_set) (int control_element, void *value);
struct intel_sst_pcm_control *pcm_control;
struct snd_pmic_ops *scard_ops;
};

Expand Down
20 changes: 14 additions & 6 deletions drivers/staging/intel_sst/intel_sst_app_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,15 @@ static int intel_sst_check_device(void)
*/
int intel_sst_open(struct inode *i_node, struct file *file_ptr)
{
int retval = intel_sst_check_device();
if (retval)
return retval;
unsigned int retval;

mutex_lock(&sst_drv_ctx->stream_lock);
retval = intel_sst_check_device();
if (retval) {
mutex_unlock(&sst_drv_ctx->stream_lock);
return retval;
}

if (sst_drv_ctx->encoded_cnt < MAX_ENC_STREAM) {
struct ioctl_pvt_data *data =
kzalloc(sizeof(struct ioctl_pvt_data), GFP_KERNEL);
Expand Down Expand Up @@ -139,12 +143,16 @@ int intel_sst_open(struct inode *i_node, struct file *file_ptr)
*/
int intel_sst_open_cntrl(struct inode *i_node, struct file *file_ptr)
{
int retval = intel_sst_check_device();
if (retval)
return retval;
unsigned int retval;

/* audio manager open */
mutex_lock(&sst_drv_ctx->stream_lock);
retval = intel_sst_check_device();
if (retval) {
mutex_unlock(&sst_drv_ctx->stream_lock);
return retval;
}

if (sst_drv_ctx->am_cnt < MAX_AM_HANDLES) {
sst_drv_ctx->am_cnt++;
pr_debug("AM handle opened...\n");
Expand Down
4 changes: 2 additions & 2 deletions drivers/staging/intel_sst/intel_sst_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
* Common private declarations for SST
*/

#define SST_DRIVER_VERSION "1.2.05"
#define SST_VERSION_NUM 0x1205
#define SST_DRIVER_VERSION "1.2.09"
#define SST_VERSION_NUM 0x1209

/* driver names */
#define SST_DRV_NAME "intel_sst_driver"
Expand Down
118 changes: 78 additions & 40 deletions drivers/staging/intel_sst/intel_sst_drv_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,27 @@ void sst_process_mad_ops(struct work_struct *work)
}
return;
}

void send_intial_rx_timeslot(void)
{
if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID &&
sst_drv_ctx->rx_time_slot_status != RX_TIMESLOT_UNINIT
&& sst_drv_ctx->pmic_vendor != SND_NC)
sst_enable_rx_timeslot(sst_drv_ctx->rx_time_slot_status);
}

/*
* sst_control_set - Set Control params
* sst_open_pcm_stream - Open PCM interface
*
* @control_list: list of controls to be set
* @str_param: parameters of pcm stream
*
* This function is called by MID sound card driver to set
* SST/Sound card controls. This is registered with MID driver
* This function is called by MID sound card driver to open
* a new pcm interface
*/
int sst_control_set(int control_element, void *value)
int sst_open_pcm_stream(struct snd_sst_params *str_param)
{
int retval = 0, str_id = 0;
struct stream_info *stream;
struct stream_info *str_info;
int retval;

if (sst_drv_ctx->sst_state == SST_SUSPENDED) {
/*LPE is suspended, resume it before proceding*/
Expand All @@ -318,53 +327,76 @@ int sst_control_set(int control_element, void *value)
pr_err("FW download fail %x, abort\n", retval);
return retval;
}
if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID &&
sst_drv_ctx->rx_time_slot_status != RX_TIMESLOT_UNINIT
&& sst_drv_ctx->pmic_vendor != SND_NC)
sst_enable_rx_timeslot(
sst_drv_ctx->rx_time_slot_status);
send_intial_rx_timeslot();
}

switch (control_element) {
case SST_SND_ALLOC: {
struct snd_sst_params *str_param;
struct stream_info *str_info;
if (!str_param)
return -EINVAL;

str_param = (struct snd_sst_params *)value;
BUG_ON(!str_param);
retval = sst_get_stream(str_param);
if (retval >= 0)
sst_drv_ctx->stream_cnt++;
retval = sst_get_stream(str_param);
if (retval > 0) {
sst_drv_ctx->stream_cnt++;
str_info = &sst_drv_ctx->streams[retval];
str_info->src = MAD_DRV;
break;
}
return retval;
}

/*
* sst_close_pcm_stream - Close PCM interface
*
* @str_id: stream id to be closed
*
* This function is called by MID sound card driver to close
* an existing pcm interface
*/
int sst_close_pcm_stream(unsigned int str_id)
{
struct stream_info *stream;

pr_debug("sst: stream free called\n");
if (sst_validate_strid(str_id))
return -EINVAL;
stream = &sst_drv_ctx->streams[str_id];
free_stream_context(str_id);
stream->pcm_substream = NULL;
stream->status = STREAM_UN_INIT;
stream->period_elapsed = NULL;
sst_drv_ctx->stream_cnt--;
pr_debug("sst: will call runtime put now\n");
return 0;
}

/*
* sst_device_control - Set Control params
*
* @cmd: control cmd to be set
* @arg: command argument
*
* This function is called by MID sound card driver to set
* SST/Sound card controls for an opened stream.
* This is registered with MID driver
*/
int sst_device_control(int cmd, void *arg)
{
int retval = 0, str_id = 0;

switch (cmd) {
case SST_SND_PAUSE:
case SST_SND_RESUME:
case SST_SND_DROP:
case SST_SND_START:
sst_drv_ctx->mad_ops.control_op = control_element;
sst_drv_ctx->mad_ops.stream_id = *(int *)value;
sst_drv_ctx->mad_ops.control_op = cmd;
sst_drv_ctx->mad_ops.stream_id = *(int *)arg;
queue_work(sst_drv_ctx->mad_wq, &sst_drv_ctx->mad_ops.wq);
break;

case SST_SND_FREE:
str_id = *(int *)value;
stream = &sst_drv_ctx->streams[str_id];
free_stream_context(str_id);
stream->pcm_substream = NULL;
stream->status = STREAM_UN_INIT;
stream->period_elapsed = NULL;
sst_drv_ctx->stream_cnt--;
break;

case SST_SND_STREAM_INIT: {
struct pcm_stream_info *str_info;
struct stream_info *stream;

pr_debug("stream init called\n");
str_info = (struct pcm_stream_info *)value;
str_info = (struct pcm_stream_info *)arg;
str_id = str_info->str_id;
retval = sst_validate_strid(str_id);
if (retval)
Expand All @@ -386,7 +418,7 @@ int sst_control_set(int control_element, void *value)
struct stream_info *stream;


stream_info = (struct pcm_stream_info *)value;
stream_info = (struct pcm_stream_info *)arg;
str_id = stream_info->str_id;
retval = sst_validate_strid(str_id);
if (retval)
Expand All @@ -412,7 +444,7 @@ int sst_control_set(int control_element, void *value)
break;
}
case SST_ENABLE_RX_TIME_SLOT: {
int status = *(int *)value;
int status = *(int *)arg;
sst_drv_ctx->rx_time_slot_status = status ;
sst_enable_rx_timeslot(status);
break;
Expand All @@ -427,8 +459,14 @@ int sst_control_set(int control_element, void *value)
}


struct intel_sst_pcm_control pcm_ops = {
.open = sst_open_pcm_stream,
.device_control = sst_device_control,
.close = sst_close_pcm_stream,
};

struct intel_sst_card_ops sst_pmic_ops = {
.control_set = sst_control_set,
.pcm_control = &pcm_ops,
};

/*
Expand Down Expand Up @@ -458,7 +496,7 @@ int register_sst_card(struct intel_sst_card_ops *card)
sst_pmic_ops.module_name = card->module_name;
sst_drv_ctx->pmic_state = SND_MAD_INIT_DONE;
sst_drv_ctx->rx_time_slot_status = 0; /*default AMIC*/
card->control_set = sst_pmic_ops.control_set;
card->pcm_control = sst_pmic_ops.pcm_control;
sst_drv_ctx->scard_ops->card_status = SND_CARD_UN_INIT;
return 0;
} else {
Expand All @@ -484,7 +522,7 @@ EXPORT_SYMBOL_GPL(register_sst_card);
*/
void unregister_sst_card(struct intel_sst_card_ops *card)
{
if (sst_pmic_ops.control_set == card->control_set) {
if (sst_pmic_ops.pcm_control == card->pcm_control) {
/* unreg */
sst_pmic_ops.module_name = "";
sst_drv_ctx->pmic_state = SND_MAD_UN_INIT;
Expand Down
1 change: 1 addition & 0 deletions drivers/staging/intel_sst/intel_sst_fw_ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/

#define MAX_NUM_STREAMS_MRST 3
#define MAX_NUM_STREAMS_MFLD 6
#define MAX_NUM_STREAMS 6
#define MAX_DBG_RW_BYTES 80
#define MAX_NUM_SCATTER_BUFFERS 8
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/intel_sst/intel_sst_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*/
int sst_check_device_type(u32 device, u32 num_chan, u32 *pcm_slot)
{
if (device >= MAX_NUM_STREAMS) {
if (device > MAX_NUM_STREAMS_MFLD) {
pr_debug("device type invalid %d\n", device);
return -EINVAL;
}
Expand Down
9 changes: 5 additions & 4 deletions drivers/staging/intel_sst/intel_sst_stream_encoded.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
#include <linux/syscalls.h>
#include <linux/firmware.h>
#include <linux/sched.h>
#include <linux/rar_register.h>
#ifdef CONFIG_MRST_RAR_HANDLER
#include "../../../drivers/staging/memrar/memrar.h"
#include <linux/rar_register.h>
#include "../memrar/memrar.h"
#endif
#include "intel_sst_ioctl.h"
#include "intel_sst.h"
Expand Down Expand Up @@ -880,13 +880,13 @@ static int sst_send_decode_mess(int str_id, struct stream_info *str_info,
return retval;
}

#ifdef CONFIG_MRST_RAR_HANDLER
static int sst_prepare_input_buffers_rar(struct stream_info *str_info,
struct snd_sst_dbufs *dbufs,
int *input_index, int *in_copied,
int *input_index_valid_size, int *new_entry_flag)
{
int retval = 0;
#ifdef CONFIG_MRST_RAR_HANDLER
int i;

if (str_info->ops == STREAM_OPS_PLAYBACK_DRM) {
Expand Down Expand Up @@ -921,9 +921,10 @@ static int sst_prepare_input_buffers_rar(struct stream_info *str_info,
str_info->decode_ibuf_type = dbufs->ibufs->type;
*in_copied = str_info->decode_isize;
}
#endif
return retval;
}
#endif

/*This function is used to prepare the kernel input buffers with contents
before sending for decode*/
static int sst_prepare_input_buffers(struct stream_info *str_info,
Expand Down
Loading

0 comments on commit 6f6ffec

Please sign in to comment.