Staging: sst: Intel SST audio driver

This is the Intel SST audio driver.

As compared to the previous versions it has all the printks and other stuff
noted cleaned up and more hardware support. The Aava support is disabled in
this patch (is_aava resolves to 0) because the Aava board detection logic
is not yet upstream.

The driver itself is a combination of a traditional ALSA driver and a
hardware assisted offload driver which can play audio while the processor
is asleep but which can't do all the more interactive stuff.

In the general case most software would use the ALSA interface, but the
other interface is needed for certain classes of use such as music playback
on highly power consumption sensitive devices.

This is going to staging primarily because it depends upon the staging memrar
driver.

Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Signed-off-by: Harsha Priya <priya.harsha@intel.com>
[Merged together and tweaked for -next]
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
Vinod Koul
2010-10-05 16:25:17 +01:00
committed by Greg Kroah-Hartman
parent a747d4b817
commit fffa1cca3d
27 changed files with 12758 additions and 0 deletions
+2
View File
@@ -171,5 +171,7 @@ source "drivers/staging/bcm/Kconfig"
source "drivers/staging/ft1000/Kconfig"
source "drivers/staging/intel_sst/Kconfig"
endif # !STAGING_EXCLUDE_BUILD
endif # STAGING
+1
View File
@@ -66,3 +66,4 @@ obj-$(CONFIG_ATH6K_LEGACY) += ath6kl/
obj-$(CONFIG_USB_ENESTORAGE) += keucr/
obj-$(CONFIG_BCM_WIMAX) += bcm/
obj-$(CONFIG_FT1000) += ft1000/
obj-$(CONFIG_SND_INTEL_SST) += intel_sst/
+18
View File
@@ -0,0 +1,18 @@
config SND_INTEL_SST
tristate "Intel SST (LPE) Driver"
depends on X86 && INTEL_SCU_IPC
default n
help
Say Y here to include support for the Intel(R) MID SST DSP driver
On other PC platforms if you are unsure answer 'N'
config SND_INTELMID
tristate "Intel MID sound card driver"
select SND_PCM
select SND_SEQUENCER
select SND_JACK
depends on SND_INTEL_SST
default n
help
Say Y here to include support for the Intel(R) MID sound card driver
On other PC platforms if you are unsure answer 'N'
+7
View File
@@ -0,0 +1,7 @@
#
# Makefile for Intel MID Audio drivers
#
snd-intel-sst-objs := intel_sst.o intel_sst_ipc.o intel_sst_stream.o intel_sst_drv_interface.o intel_sst_dsp.o intel_sst_pvt.o intel_sst_stream_encoded.o intel_sst_app_interface.o
snd-intelmid-objs := intelmid.o intelmid_msic_control.o intelmid_ctrl.o intelmid_pvt.o intelmid_v0_control.o intelmid_v1_control.o intelmid_v2_control.o
obj-$(CONFIG_SND_INTEL_SST) += snd-intel-sst.o
obj-$(CONFIG_SND_INTELMID) += snd-intelmid.o
+12
View File
@@ -0,0 +1,12 @@
TODO
----
Get the memrar driver cleaned up and upstream (dependancy blocking SST)
Get the jack header entries accepted
Review the printks and kill off any left over ST_ERR: messages
Review the misc device ioctls for 32/64bit safety and sanity
Review the misc device ioctls for size safety depending on config and decide
if space/unused areas should be left
Anything the sound folks turn up on full review
File diff suppressed because it is too large Load Diff
+131
View File
@@ -0,0 +1,131 @@
#ifndef __INTEL_SST_H__
#define __INTEL_SST_H__
/*
* intel_sst.h - Intel SST Driver for audio engine
*
* Copyright (C) 2008-10 Intel Corporation
* 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 driver exposes the audio engine functionalities to the ALSA
* and middleware.
* This file is shared between the SST and MAD drivers
*/
#define SST_CARD_NAMES "intel_mid_card"
/* control list Pmic & Lpe */
/* Input controls */
enum port_status {
ACTIVATE = 1,
DEACTIVATE,
};
/* Card states */
enum sst_card_states {
SND_CARD_UN_INIT = 0,
SND_CARD_INIT_DONE,
};
enum sst_controls {
SST_SND_ALLOC = 0x1000,
SST_SND_PAUSE = 0x1001,
SST_SND_RESUME = 0x1002,
SST_SND_DROP = 0x1003,
SST_SND_FREE = 0x1004,
SST_SND_BUFFER_POINTER = 0x1005,
SST_SND_STREAM_INIT = 0x1006,
SST_SND_START = 0x1007,
SST_SND_STREAM_PROCESS = 0x1008,
SST_MAX_CONTROLS = 0x1008,
SST_CONTROL_BASE = 0x1000,
SST_ENABLE_RX_TIME_SLOT = 0x1009,
};
enum SND_CARDS {
SND_FS = 0,
SND_MX,
SND_NC,
SND_MSIC
};
struct pcm_stream_info {
int str_id;
void *mad_substream;
void (*period_elapsed) (void *mad_substream);
unsigned long long buffer_ptr;
int sfreq;
};
struct snd_pmic_ops {
int card_status;
int master_mute;
int num_channel;
int input_dev_id;
int mute_status;
int pb_on;
int cap_on;
int output_dev_id;
int (*set_input_dev) (u8 value);
int (*set_output_dev) (u8 value);
int (*set_mute) (int dev_id, u8 value);
int (*get_mute) (int dev_id, u8 *value);
int (*set_vol) (int dev_id, int value);
int (*get_vol) (int dev_id, int *value);
int (*init_card) (void);
int (*set_pcm_audio_params)
(int sfreq, int word_size , int num_channel);
int (*set_pcm_voice_params) (void);
int (*set_voice_port) (int status);
int (*set_audio_port) (int status);
int (*power_up_pmic_pb) (unsigned int port);
int (*power_up_pmic_cp) (unsigned int port);
int (*power_down_pmic_pb) (void);
int (*power_down_pmic_cp) (void);
int (*power_down_pmic) (void);
};
struct intel_sst_card_ops {
char *module_name;
unsigned int vendor_id;
int (*control_set) (int control_element, void *value);
struct snd_pmic_ops *scard_ops;
};
/* modified for generic access */
struct sc_reg_access {
u16 reg_addr;
u8 value;
u8 mask;
};
enum sc_reg_access_type {
PMIC_READ = 0,
PMIC_WRITE,
PMIC_READ_MODIFY,
};
int register_sst_card(struct intel_sst_card_ops *card);
void unregister_sst_card(struct intel_sst_card_ops *card);
#endif /* __INTEL_SST_H__ */
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,492 @@
/*
* intel_sst_interface.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)
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* 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 driver exposes the audio engine functionalities to the ALSA
* and middleware.
* Upper layer interfaces (MAD driver, MMF) to SST driver
*/
#include <linux/pci.h>
#include <linux/fs.h>
#include <linux/firmware.h>
#include "intel_sst.h"
#include "intel_sst_ioctl.h"
#include "intel_sst_fw_ipc.h"
#include "intel_sst_common.h"
/*
* sst_download_fw - download the audio firmware to DSP
*
* This function is called when the FW needs to be downloaded to SST DSP engine
*/
int sst_download_fw(void)
{
int retval;
const struct firmware *fw_sst;
const char *name;
if (sst_drv_ctx->sst_state != SST_UN_INIT)
return -EPERM;
if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID)
name = SST_FW_FILENAME_MRST;
else
name = SST_FW_FILENAME_MFLD;
pr_debug("sst: Downloading %s FW now...\n", name);
retval = request_firmware(&fw_sst, name, &sst_drv_ctx->pci->dev);
if (retval) {
pr_err("sst: request fw failed %d\n", retval);
return retval;
}
sst_drv_ctx->alloc_block[0].sst_id = FW_DWNL_ID;
sst_drv_ctx->alloc_block[0].ops_block.condition = false;
retval = sst_load_fw(fw_sst, NULL);
if (retval)
goto end_restore;
retval = sst_wait_timeout(sst_drv_ctx, &sst_drv_ctx->alloc_block[0]);
if (retval)
pr_err("sst: fw download failed %d\n" , retval);
end_restore:
release_firmware(fw_sst);
sst_drv_ctx->alloc_block[0].sst_id = BLOCK_UNINIT;
return retval;
}
/*
* sst_stalled - this function checks if the lpe is in stalled state
*/
int sst_stalled(void)
{
int retry = 1000;
int retval = -1;
while (retry) {
if (!sst_drv_ctx->lpe_stalled)
return 0;
/*wait for time and re-check*/
msleep(1);
retry--;
}
pr_debug("sst: in Stalled State\n");
return retval;
}
void free_stream_context(unsigned int str_id)
{
struct stream_info *stream;
if (!sst_validate_strid(str_id)) {
/* str_id is valid, so stream is alloacted */
stream = &sst_drv_ctx->streams[str_id];
if (stream->ops == STREAM_OPS_PLAYBACK ||
stream->ops == STREAM_OPS_PLAYBACK_DRM) {
sst_drv_ctx->pb_streams--;
if (sst_drv_ctx->pb_streams == 0)
sst_drv_ctx->scard_ops->power_down_pmic_pb();
} else if (stream->ops == STREAM_OPS_CAPTURE) {
sst_drv_ctx->cp_streams--;
if (sst_drv_ctx->cp_streams == 0)
sst_drv_ctx->scard_ops->power_down_pmic_cp();
}
if (sst_drv_ctx->pb_streams == 0
&& sst_drv_ctx->cp_streams == 0)
sst_drv_ctx->scard_ops->power_down_pmic();
if (sst_free_stream(str_id))
sst_clean_stream(&sst_drv_ctx->streams[str_id]);
}
}
/*
* sst_get_stream_allocated - this function gets a stream allocated with
* the given params
*
* @str_param : stream params
* @lib_dnld : pointer to pointer of lib downlaod struct
*
* This creates new stream id for a stream, in case lib is to be downloaded to
* DSP, it downloads that
*/
int sst_get_stream_allocated(struct snd_sst_params *str_param,
struct snd_sst_lib_download **lib_dnld)
{
int retval, str_id;
struct stream_info *str_info;
retval = sst_alloc_stream((char *) &str_param->sparams, str_param->ops,
str_param->codec, str_param->device_type);
if (retval < 0) {
pr_err("sst: sst_alloc_stream failed %d\n", retval);
return retval;
}
pr_debug("sst: Stream allocated %d\n", retval);
str_id = retval;
str_info = &sst_drv_ctx->streams[str_id];
/* Block the call for reply */
retval = sst_wait_interruptible_timeout(sst_drv_ctx,
&str_info->ctrl_blk, SST_BLOCK_TIMEOUT);
if ((retval != 0) || (str_info->ctrl_blk.ret_code != 0)) {
pr_debug("sst: FW alloc failed retval %d, ret_code %d\n",
retval, str_info->ctrl_blk.ret_code);
str_id = -str_info->ctrl_blk.ret_code; /*return error*/
*lib_dnld = str_info->ctrl_blk.data;
sst_clean_stream(str_info);
} else
pr_debug("sst: FW Stream allocated sucess\n");
return str_id; /*will ret either error (in above if) or correct str id*/
}
/*
* sst_get_sfreq - this function returns the frequency of the stream
*
* @str_param : stream params
*/
static int sst_get_sfreq(struct snd_sst_params *str_param)
{
switch (str_param->codec) {
case SST_CODEC_TYPE_PCM:
return 48000; /*str_param->sparams.uc.pcm_params.sfreq;*/
case SST_CODEC_TYPE_MP3:
return str_param->sparams.uc.mp3_params.sfreq;
case SST_CODEC_TYPE_AAC:
return str_param->sparams.uc.aac_params.sfreq;;
case SST_CODEC_TYPE_WMA9:
return str_param->sparams.uc.wma_params.sfreq;;
default:
return 0;
}
}
/*
* sst_get_stream - this function prepares for stream allocation
*
* @str_param : stream param
*/
int sst_get_stream(struct snd_sst_params *str_param)
{
int i, retval;
struct stream_info *str_info;
struct snd_sst_lib_download *lib_dnld;
/* stream is not allocated, we are allocating */
retval = sst_get_stream_allocated(str_param, &lib_dnld);
if (retval == -(SST_LIB_ERR_LIB_DNLD_REQUIRED)) {
/* codec download is required */
struct snd_sst_alloc_response *response;
pr_debug("sst: Codec is required.... trying that\n");
if (lib_dnld == NULL) {
pr_err("sst: lib download null!!! abort\n");
return -EIO;
}
i = sst_get_block_stream(sst_drv_ctx);
response = sst_drv_ctx->alloc_block[i].ops_block.data;
pr_debug("sst: alloc block allocated = %d\n", i);
if (i < 0) {
kfree(lib_dnld);
return -ENOMEM;
}
retval = sst_load_library(lib_dnld, str_param->ops);
kfree(lib_dnld);
sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
if (!retval) {
pr_debug("sst: codec was downloaded sucesfully\n");
retval = sst_get_stream_allocated(str_param, &lib_dnld);
if (retval <= 0)
goto err;
pr_debug("sst: Alloc done stream id %d\n", retval);
} else {
pr_debug("sst: codec download failed\n");
retval = -EIO;
goto err;
}
} else if (retval <= 0)
goto err;
/*else
set_port_params(str_param, str_param->ops);*/
/* store sampling freq */
str_info = &sst_drv_ctx->streams[retval];
str_info->sfreq = sst_get_sfreq(str_param);
/* power on the analog, if reqd */
if (str_param->ops == STREAM_OPS_PLAYBACK ||
str_param->ops == STREAM_OPS_PLAYBACK_DRM) {
if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID)
sst_drv_ctx->scard_ops->power_up_pmic_pb(
sst_drv_ctx->pmic_port_instance);
else
sst_drv_ctx->scard_ops->power_up_pmic_pb(
str_info->device);
/*Only if the playback is MP3 - Send a message*/
sst_drv_ctx->pb_streams++;
} else if (str_param->ops == STREAM_OPS_CAPTURE) {
sst_drv_ctx->scard_ops->power_up_pmic_cp(
sst_drv_ctx->pmic_port_instance);
/*Send a messageif not sent already*/
sst_drv_ctx->cp_streams++;
}
err:
return retval;
}
void sst_process_mad_ops(struct work_struct *work)
{
struct mad_ops_wq *mad_ops =
container_of(work, struct mad_ops_wq, wq);
int retval = 0;
switch (mad_ops->control_op) {
case SST_SND_PAUSE:
retval = sst_pause_stream(mad_ops->stream_id);
break;
case SST_SND_RESUME:
retval = sst_resume_stream(mad_ops->stream_id);
break;
case SST_SND_DROP:
/* retval = sst_drop_stream(mad_ops->stream_id);
*/ break;
case SST_SND_START:
pr_debug("SST Debug: start stream\n");
retval = sst_start_stream(mad_ops->stream_id);
break;
case SST_SND_STREAM_PROCESS:
pr_debug("sst: play/capt frames...\n");
break;
default:
pr_err("sst: wrong control_ops reported\n");
}
return;
}
/*
* sst_control_set - Set Control params
*
* @control_list: list of controls to be set
*
* This function is called by MID sound card driver to set
* SST/Sound card controls. This is registered with MID driver
*/
int sst_control_set(int control_element, void *value)
{
int retval = 0, str_id = 0;
struct stream_info *stream;
if (sst_drv_ctx->sst_state == SST_SUSPENDED) {
/*LPE is suspended, resume it before proceding*/
pr_debug("sst: Resuming from Suspended state\n");
retval = intel_sst_resume(sst_drv_ctx->pci);
if (retval) {
pr_err("sst: Resume Failed = %#x, abort\n", retval);
return retval;
}
}
if (sst_drv_ctx->sst_state == SST_UN_INIT) {
/* FW is not downloaded */
pr_debug("sst: DSP Downloading FW now...\n");
retval = sst_download_fw();
if (retval) {
pr_err("sst: 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);
}
switch (control_element) {
case SST_SND_ALLOC: {
struct snd_sst_params *str_param;
struct stream_info *str_info;
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++;
str_info = &sst_drv_ctx->streams[retval];
str_info->src = MAD_DRV;
break;
}
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;
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("sst: stream init called\n");
str_info = (struct pcm_stream_info *)value;
str_id = str_info->str_id;
retval = sst_validate_strid(str_id);
if (retval)
break;
stream = &sst_drv_ctx->streams[str_id];
pr_debug("sst: setting the period ptrs\n");
stream->pcm_substream = str_info->mad_substream;
stream->period_elapsed = str_info->period_elapsed;
stream->sfreq = str_info->sfreq;
stream->prev = stream->status;
stream->status = STREAM_INIT;
break;
}
case SST_SND_BUFFER_POINTER: {
struct pcm_stream_info *stream_info;
struct snd_sst_tstamp fw_tstamp = {0,};
struct stream_info *stream;
stream_info = (struct pcm_stream_info *)value;
str_id = stream_info->str_id;
retval = sst_validate_strid(str_id);
if (retval)
break;
stream = &sst_drv_ctx->streams[str_id];
if (!stream->pcm_substream)
break;
memcpy_fromio(&fw_tstamp,
((void *)(sst_drv_ctx->mailbox + SST_TIME_STAMP)
+(str_id * sizeof(fw_tstamp))),
sizeof(fw_tstamp));
pr_debug("sst: Pointer Query on strid = %d ops %d\n",
str_id, stream->ops);
if (stream->ops == STREAM_OPS_PLAYBACK)
stream_info->buffer_ptr = fw_tstamp.samples_rendered;
else
stream_info->buffer_ptr = fw_tstamp.samples_processed;
pr_debug("sst: Samples rendered = %llu, buffer ptr %llu\n",
fw_tstamp.samples_rendered, stream_info->buffer_ptr);
break;
}
case SST_ENABLE_RX_TIME_SLOT: {
int status = *(int *)value;
sst_drv_ctx->rx_time_slot_status = status ;
sst_enable_rx_timeslot(status);
break;
}
default:
/* Illegal case */
pr_warn("sst: illegal req\n");
return -EINVAL;
}
return retval;
}
struct intel_sst_card_ops sst_pmic_ops = {
.control_set = sst_control_set,
};
/*
* register_sst_card - function for sound card to register
*
* @card: pointer to structure of operations
*
* This function is called card driver loads and is ready for registration
*/
int register_sst_card(struct intel_sst_card_ops *card)
{
if (!sst_drv_ctx) {
pr_err("sst: No SST driver register card reject\n");
return -ENODEV;
}
if (!card || !card->module_name) {
pr_err("sst: Null Pointer Passed\n");
return -EINVAL;
}
if (sst_drv_ctx->pmic_state == SND_MAD_UN_INIT) {
/* register this driver */
if ((strncmp(SST_CARD_NAMES, card->module_name,
strlen(SST_CARD_NAMES))) == 0) {
sst_drv_ctx->pmic_vendor = card->vendor_id;
sst_drv_ctx->scard_ops = card->scard_ops;
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;
sst_drv_ctx->scard_ops->card_status = SND_CARD_UN_INIT;
return 0;
} else {
pr_err("sst: strcmp fail %s\n", card->module_name);
return -EINVAL;
}
} else {
/* already registered a driver */
pr_err("sst: Repeat for registeration..denied\n");
return -EBADRQC;
}
return 0;
}
EXPORT_SYMBOL_GPL(register_sst_card);
/*
* unregister_sst_card- function for sound card to un-register
*
* @card: pointer to structure of operations
*
* This function is called when card driver unloads
*/
void unregister_sst_card(struct intel_sst_card_ops *card)
{
if (sst_pmic_ops.control_set == card->control_set) {
/* unreg */
sst_pmic_ops.module_name = "";
sst_drv_ctx->pmic_state = SND_MAD_UN_INIT;
pr_debug("sst: Unregistered %s\n", card->module_name);
}
return;
}
EXPORT_SYMBOL_GPL(unregister_sst_card);
+486
View File
@@ -0,0 +1,486 @@
/*
* intel_sst_dsp.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 driver exposes the audio engine functionalities to the ALSA
* and middleware.
*
* This file contains all dsp controlling functions like firmware download,
* setting/resetting dsp cores, etc
*/
#include <linux/pci.h>
#include <linux/fs.h>
#include <linux/firmware.h>
#include "intel_sst.h"
#include "intel_sst_ioctl.h"
#include "intel_sst_fw_ipc.h"
#include "intel_sst_common.h"
/**
* intel_sst_reset_dsp_mrst - Resetting SST DSP
*
* This resets DSP in case of MRST platfroms
*/
static int intel_sst_reset_dsp_mrst(void)
{
union config_status_reg csr;
pr_debug("sst: Resetting the DSP in mrst\n");
csr.full = 0x3a2;
sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR);
csr.part.strb_cntr_rst = 0;
csr.part.run_stall = 0x1;
csr.part.bypass = 0x7;
csr.part.sst_reset = 0x1;
sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
return 0;
}
/**
* intel_sst_reset_dsp_medfield - Resetting SST DSP
*
* This resets DSP in case of Medfield platfroms
*/
static int intel_sst_reset_dsp_medfield(void)
{
union config_status_reg csr;
pr_debug("sst: Resetting the DSP in medfield\n");
csr.full = 0x048303E2;
sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
return 0;
}
/**
* sst_start_mrst - Start the SST DSP processor
*
* This starts the DSP in MRST platfroms
*/
static int sst_start_mrst(void)
{
union config_status_reg csr;
csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR);
csr.part.bypass = 0;
sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
csr.part.run_stall = 0;
csr.part.sst_reset = 0;
csr.part.strb_cntr_rst = 1;
pr_debug("sst: Setting SST to execute_mrst 0x%x\n", csr.full);
sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
return 0;
}
/**
* sst_start_medfield - Start the SST DSP processor
*
* This starts the DSP in MRST platfroms
*/
static int sst_start_medfield(void)
{
union config_status_reg csr;
csr.full = 0x04830062;
sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
csr.full = 0x04830063;
sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
csr.full = 0x04830061;
sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
pr_debug("sst: Starting the DSP_medfld\n");
return 0;
}
/**
* sst_parse_module - Parse audio FW modules
*
* @module: FW module header
*
* Parses modules that need to be placed in SST IRAM and DRAM
* returns error or 0 if module sizes are proper
*/
static int sst_parse_module(struct fw_module_header *module)
{
struct dma_block_info *block;
u32 count;
void __iomem *ram;
pr_debug("sst: module sign %s size %x blocks %x type %x\n",
module->signature, module->mod_size,
module->blocks, module->type);
pr_debug("sst: module entrypoint 0x%x\n", module->entry_point);
block = (void *)module + sizeof(*module);
for (count = 0; count < module->blocks; count++) {
if (block->size <= 0) {
pr_err("sst: block size invalid\n");
return -EINVAL;
}
switch (block->type) {
case SST_IRAM:
ram = sst_drv_ctx->iram;
break;
case SST_DRAM:
ram = sst_drv_ctx->dram;
break;
default:
pr_err("sst: wrong ram type0x%x in block0x%x\n",
block->type, count);
return -EINVAL;
}
memcpy_toio(ram + block->ram_offset,
(void *)block + sizeof(*block), block->size);
block = (void *)block + sizeof(*block) + block->size;
}
return 0;
}
/**
* sst_parse_fw_image - parse and load FW
*
* @sst_fw: pointer to audio fw
*
* This function is called to parse and download the FW image
*/
static int sst_parse_fw_image(const struct firmware *sst_fw)
{
struct fw_header *header;
u32 count;
int ret_val;
struct fw_module_header *module;
BUG_ON(!sst_fw);
/* Read the header information from the data pointer */
header = (struct fw_header *)sst_fw->data;
/* verify FW */
if ((strncmp(header->signature, SST_FW_SIGN, 4) != 0) ||
(sst_fw->size != header->file_size + sizeof(*header))) {
/* Invalid FW signature */
pr_err("sst: InvalidFW sign/filesize mismatch\n");
return -EINVAL;
}
pr_debug("sst: header sign=%s size=%x modules=%x fmt=%x size=%x\n",
header->signature, header->file_size, header->modules,
header->file_format, sizeof(*header));
module = (void *)sst_fw->data + sizeof(*header);
for (count = 0; count < header->modules; count++) {
/* module */
ret_val = sst_parse_module(module);
if (ret_val)
return ret_val;
module = (void *)module + sizeof(*module) + module->mod_size ;
}
return 0;
}
/**
* sst_load_fw - function to load FW into DSP
*
* @fw: Pointer to driver loaded FW
* @context: driver context
*
* This function is called by OS when the FW is loaded into kernel
*/
int sst_load_fw(const struct firmware *fw, void *context)
{
int ret_val;
pr_debug("sst: load_fw called\n");
BUG_ON(!fw);
if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID)
ret_val = intel_sst_reset_dsp_mrst();
else if (sst_drv_ctx->pci_id == SST_MFLD_PCI_ID)
ret_val = intel_sst_reset_dsp_medfield();
if (ret_val)
return ret_val;
ret_val = sst_parse_fw_image(fw);
if (ret_val)
return ret_val;
mutex_lock(&sst_drv_ctx->sst_lock);
sst_drv_ctx->sst_state = SST_FW_LOADED;
mutex_unlock(&sst_drv_ctx->sst_lock);
/* 7. ask scu to reset the bypass bits */
/* 8.bring sst out of reset */
if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID)
ret_val = sst_start_mrst();
else if (sst_drv_ctx->pci_id == SST_MFLD_PCI_ID)
ret_val = sst_start_medfield();
if (ret_val)
return ret_val;
pr_debug("sst: fw loaded successful!!!\n");
return ret_val;
}
/*This function is called when any codec/post processing library
needs to be downloaded*/
static int sst_download_library(const struct firmware *fw_lib,
struct snd_sst_lib_download_info *lib)
{
/* send IPC message and wait */
int i;
u8 pvt_id;
struct ipc_post *msg = NULL;
union config_status_reg csr;
struct snd_sst_str_type str_type = {0};
int retval = 0;
if (sst_create_large_msg(&msg))
return -ENOMEM;
pvt_id = sst_assign_pvt_id(sst_drv_ctx);
i = sst_get_block_stream(sst_drv_ctx);
pr_debug("sst: alloc block allocated = %d, pvt_id %d\n", i, pvt_id);
if (i < 0) {
kfree(msg);
return -ENOMEM;
}
sst_drv_ctx->alloc_block[i].sst_id = pvt_id;
sst_fill_header(&msg->header, IPC_IA_PREP_LIB_DNLD, 1, pvt_id);
msg->header.part.data = sizeof(u32) + sizeof(str_type);
str_type.codec_type = lib->dload_lib.lib_info.lib_type;
/*str_type.pvt_id = pvt_id;*/
memcpy(msg->mailbox_data, &msg->header, sizeof(u32));
memcpy(msg->mailbox_data + sizeof(u32), &str_type, sizeof(str_type));
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_timeout(sst_drv_ctx, &sst_drv_ctx->alloc_block[i]);
if (retval) {
/* error */
sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
pr_err("sst: Prep codec downloaded failed %d\n",
retval);
return -EIO;
}
pr_debug("sst: FW responded, ready for download now...\n");
/* downloading on success */
mutex_lock(&sst_drv_ctx->sst_lock);
sst_drv_ctx->sst_state = SST_FW_LOADED;
mutex_unlock(&sst_drv_ctx->sst_lock);
csr.full = readl(sst_drv_ctx->shim + SST_CSR);
csr.part.run_stall = 1;
sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR);
csr.part.bypass = 0x7;
sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
sst_parse_fw_image(fw_lib);
/* set the FW to running again */
csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR);
csr.part.bypass = 0x0;
sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR);
csr.part.run_stall = 0;
sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
/* send download complete and wait */
if (sst_create_large_msg(&msg)) {
sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
return -ENOMEM;
}
sst_fill_header(&msg->header, IPC_IA_LIB_DNLD_CMPLT, 1, pvt_id);
sst_drv_ctx->alloc_block[i].sst_id = pvt_id;
msg->header.part.data = sizeof(u32) + sizeof(*lib);
lib->pvt_id = pvt_id;
memcpy(msg->mailbox_data, &msg->header, sizeof(u32));
memcpy(msg->mailbox_data + sizeof(u32), lib, sizeof(*lib));
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: Waiting for FW response Download complete\n");
sst_drv_ctx->alloc_block[i].ops_block.condition = false;
retval = sst_wait_timeout(sst_drv_ctx, &sst_drv_ctx->alloc_block[i]);
if (retval) {
/* error */
mutex_lock(&sst_drv_ctx->sst_lock);
sst_drv_ctx->sst_state = SST_UN_INIT;
mutex_unlock(&sst_drv_ctx->sst_lock);
sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
return -EIO;
}
pr_debug("sst: FW sucess on Download complete\n");
sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
mutex_lock(&sst_drv_ctx->sst_lock);
sst_drv_ctx->sst_state = SST_FW_RUNNING;
mutex_unlock(&sst_drv_ctx->sst_lock);
return 0;
}
/* This function is called befoer downloading the codec/postprocessing
library is set for download to SST DSP*/
static int sst_validate_library(const struct firmware *fw_lib,
struct lib_slot_info *slot,
u32 *entry_point)
{
struct fw_header *header;
struct fw_module_header *module;
struct dma_block_info *block;
unsigned int n_blk, isize = 0, dsize = 0;
int err = 0;
header = (struct fw_header *)fw_lib->data;
if (header->modules != 1) {
pr_err("sst: Module no mismatch found\n ");
err = -EINVAL;
goto exit;
}
module = (void *)fw_lib->data + sizeof(*header);
*entry_point = module->entry_point;
pr_debug("sst: Module entry point 0x%x\n", *entry_point);
pr_debug("sst: Module Sign %s, Size 0x%x, Blocks 0x%x Type 0x%x\n",
module->signature, module->mod_size,
module->blocks, module->type);
block = (void *)module + sizeof(*module);
for (n_blk = 0; n_blk < module->blocks; n_blk++) {
switch (block->type) {
case SST_IRAM:
isize += block->size;
break;
case SST_DRAM:
dsize += block->size;
break;
default:
pr_err("sst: Invalid block type for 0x%x\n", n_blk);
err = -EINVAL;
goto exit;
}
block = (void *)block + sizeof(*block) + block->size;
}
if (isize > slot->iram_size || dsize > slot->dram_size) {
pr_err("sst: library exceeds size allocated\n");
err = -EINVAL;
goto exit;
} else
pr_debug("sst: Library is safe for download...\n");
pr_debug("sst: iram 0x%x, dram 0x%x, iram 0x%x, dram 0x%x\n",
isize, dsize, slot->iram_size, slot->dram_size);
exit:
return err;
}
/* This function is called when FW requests for a particular libary download
This function prepares the library to download*/
int sst_load_library(struct snd_sst_lib_download *lib, u8 ops)
{
char buf[20];
const char *type, *dir;
int len = 0, error = 0;
u32 entry_point;
const struct firmware *fw_lib;
struct snd_sst_lib_download_info dload_info = {{{0},},};
memset(buf, 0, sizeof(buf));
pr_debug("sst: Lib Type 0x%x, Slot 0x%x, ops 0x%x\n",
lib->lib_info.lib_type, lib->slot_info.slot_num, ops);
pr_debug("sst: Version 0x%x, name %s, caps 0x%x media type 0x%x\n",
lib->lib_info.lib_version, lib->lib_info.lib_name,
lib->lib_info.lib_caps, lib->lib_info.media_type);
pr_debug("sst: IRAM Size 0x%x, offset 0x%x\n",
lib->slot_info.iram_size, lib->slot_info.iram_offset);
pr_debug("sst: DRAM Size 0x%x, offset 0x%x\n",
lib->slot_info.dram_size, lib->slot_info.dram_offset);
switch (lib->lib_info.lib_type) {
case SST_CODEC_TYPE_MP3:
type = "mp3_";
break;
case SST_CODEC_TYPE_AAC:
type = "aac_";
break;
case SST_CODEC_TYPE_AACP:
type = "aac_v1_";
break;
case SST_CODEC_TYPE_eAACP:
type = "aac_v2_";
break;
case SST_CODEC_TYPE_WMA9:
type = "wma9_";
break;
default:
pr_err("sst: Invalid codec type\n");
error = -EINVAL;
goto wake;
}
if (ops == STREAM_OPS_CAPTURE)
dir = "enc_";
else
dir = "dec_";
len = strlen(type) + strlen(dir);
strncpy(buf, type, sizeof(buf)-1);
strncpy(buf + strlen(type), dir, sizeof(buf)-strlen(type)-1);
len += snprintf(buf + len, sizeof(buf) - len, "%d",
lib->slot_info.slot_num);
len += snprintf(buf + len, sizeof(buf) - len, ".bin");
pr_debug("sst: Requesting %s\n", buf);
error = request_firmware(&fw_lib, buf, &sst_drv_ctx->pci->dev);
if (error) {
pr_err("sst: library load failed %d\n", error);
goto wake;
}
error = sst_validate_library(fw_lib, &lib->slot_info, &entry_point);
if (error)
goto wake_free;
lib->mod_entry_pt = entry_point;
memcpy(&dload_info.dload_lib, lib, sizeof(*lib));
error = sst_download_library(fw_lib, &dload_info);
if (error)
goto wake_free;
/* lib is downloaded and init send alloc again */
pr_debug("sst: Library is downloaded now...\n");
wake_free:
/* sst_wake_up_alloc_block(sst_drv_ctx, pvt_id, error, NULL); */
release_firmware(fw_lib);
wake:
return error;
}
@@ -0,0 +1,393 @@
#ifndef __INTEL_SST_FW_IPC_H__
#define __INTEL_SST_FW_IPC_H__
/*
* intel_sst_fw_ipc.h - Intel SST Driver for audio engine
*
* Copyright (C) 2008-10 Intel Corporation
* Author: 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 driver exposes the audio engine functionalities to the ALSA
* and middleware.
* This file has definitions shared between the firmware and driver
*/
#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
#define MAX_LOOP_BACK_DWORDS 8
/* IPC base address and mailbox, timestamp offsets */
#define SST_MAILBOX_SIZE 0x0400
#define SST_MAILBOX_SEND 0x0000
#define SST_MAILBOX_RCV 0x0804
#define SST_TIME_STAMP 0x1800
#define SST_RESERVED_OFFSET 0x1A00
#define SST_CHEKPOINT_OFFSET 0x1C00
#define REPLY_MSG 0x80
/* Message ID's for IPC messages */
/* Bits B7: SST or IA/SC ; B6-B4: Msg Category; B3-B0: Msg Type */
/* I2L Firmware/Codec Download msgs */
#define IPC_IA_PREP_LIB_DNLD 0x01
#define IPC_IA_LIB_DNLD_CMPLT 0x02
#define IPC_IA_SET_PMIC_TYPE 0x03
#define IPC_IA_GET_FW_VERSION 0x04
#define IPC_IA_GET_FW_BUILD_INF 0x05
#define IPC_IA_GET_FW_INFO 0x06
/* I2L Codec Config/control msgs */
#define IPC_IA_SET_CODEC_PARAMS 0x10
#define IPC_IA_GET_CODEC_PARAMS 0x11
#define IPC_IA_SET_PPP_PARAMS 0x12
#define IPC_IA_GET_PPP_PARAMS 0x13
#define IPC_IA_PLAY_FRAMES 0x14
#define IPC_IA_CAPT_FRAMES 0x15
#define IPC_IA_PLAY_VOICE 0x16
#define IPC_IA_CAPT_VOICE 0x17
#define IPC_IA_DECODE_FRAMES 0x18
/* I2L Stream config/control msgs */
#define IPC_IA_ALLOC_STREAM 0x20 /* Allocate a stream ID */
#define IPC_IA_FREE_STREAM 0x21 /* Free the stream ID */
#define IPC_IA_SET_STREAM_PARAMS 0x22
#define IPC_IA_GET_STREAM_PARAMS 0x23
#define IPC_IA_PAUSE_STREAM 0x24
#define IPC_IA_RESUME_STREAM 0x25
#define IPC_IA_DROP_STREAM 0x26
#define IPC_IA_DRAIN_STREAM 0x27 /* Short msg with str_id */
#define IPC_IA_TARGET_DEV_SELECT 0x28
#define IPC_IA_CONTROL_ROUTING 0x29
#define IPC_IA_SET_STREAM_VOL 0x2A /*Vol for stream, pre mixer */
#define IPC_IA_GET_STREAM_VOL 0x2B
#define IPC_IA_SET_STREAM_MUTE 0x2C
#define IPC_IA_GET_STREAM_MUTE 0x2D
#define IPC_IA_ENABLE_RX_TIME_SLOT 0x2E /* Enable Rx time slot 0 or 1 */
#define IPC_IA_START_STREAM 0x30 /* Short msg with str_id */
/* Debug msgs */
#define IPC_IA_DBG_MEM_READ 0x40
#define IPC_IA_DBG_MEM_WRITE 0x41
#define IPC_IA_DBG_LOOP_BACK 0x42
/* L2I Firmware/Codec Download msgs */
#define IPC_IA_FW_INIT_CMPLT 0x81
#define IPC_IA_LPE_GETTING_STALLED 0x82
#define IPC_IA_LPE_UNSTALLED 0x83
/* L2I Codec Config/control msgs */
#define IPC_SST_GET_PLAY_FRAMES 0x90 /* Request IA more data */
#define IPC_SST_GET_CAPT_FRAMES 0x91 /* Request IA more data */
#define IPC_SST_BUF_UNDER_RUN 0x92 /* PB Under run and stopped */
#define IPC_SST_BUF_OVER_RUN 0x93 /* CAP Under run and stopped */
#define IPC_SST_DRAIN_END 0x94 /* PB Drain complete and stopped */
#define IPC_SST_CHNGE_SSP_PARAMS 0x95 /* PB SSP parameters changed */
#define IPC_SST_STREAM_PROCESS_FATAL_ERR 0x96/* error in processing a stream */
#define IPC_SST_PERIOD_ELAPSED 0x97 /* period elapsed */
#define IPC_IA_TARGET_DEV_CHNGD 0x98 /* error in processing a stream */
#define IPC_SST_ERROR_EVENT 0x99 /* Buffer over run occured */
/* L2S messages */
#define IPC_SC_DDR_LINK_UP 0xC0
#define IPC_SC_DDR_LINK_DOWN 0xC1
#define IPC_SC_SET_LPECLK_REQ 0xC2
#define IPC_SC_SSP_BIT_BANG 0xC3
/* L2I Error reporting msgs */
#define IPC_IA_MEM_ALLOC_FAIL 0xE0
#define IPC_IA_PROC_ERR 0xE1 /* error in processing a
stream can be used by playback and
capture modules */
/* L2I Debug msgs */
#define IPC_IA_PRINT_STRING 0xF0
/* Command Response or Acknowledge message to any IPC message will have
* same message ID and stream ID information which is sent.
* There is no specific Ack message ID. The data field is used as response
* meaning.
*/
enum ackData {
IPC_ACK_SUCCESS = 0,
IPC_ACK_FAILURE
};
enum sst_error_codes {
/* Error code,response to msgId: Description */
/* Common error codes */
SST_SUCCESS = 0, /* Success */
SST_ERR_INVALID_STREAM_ID, /* Invalid stream ID */
SST_ERR_INVALID_MSG_ID, /* Invalid message ID */
SST_ERR_INVALID_STREAM_OP, /* Invalid stream operation request */
SST_ERR_INVALID_PARAMS, /* Invalid params */
SST_ERR_INVALID_CODEC, /* Invalid codec type */
SST_ERR_INVALID_MEDIA_TYPE, /* Invalid media type */
SST_ERR_STREAM_ERR, /* ANY: Stream control or config or
processing error */
/* IPC specific error codes */
SST_IPC_ERR_CALL_BACK_NOT_REGD, /* Call back for msg not regd */
SST_IPC_ERR_STREAM_NOT_ALLOCATED, /* Stream is not allocated */
SST_IPC_ERR_STREAM_ALLOC_FAILED, /* ALLOC:Stream alloc failed */
SST_IPC_ERR_GET_STREAM_FAILED, /* ALLOC:Get stream id failed*/
SST_ERR_MOD_NOT_AVAIL, /* SET/GET: Mod(AEC/AGC/ALC) not available */
SST_ERR_MOD_DNLD_RQD, /* SET/GET: Mod(AEC/AGC/ALC) download required */
SST_ERR_STREAM_STOPPED, /* ANY: Stream is in stopped state */
SST_ERR_STREAM_IN_USE, /* ANY: Stream is already in use */
/* Capture specific error codes */
SST_CAP_ERR_INCMPLTE_CAPTURE_MSG,/* ANY:Incomplete message */
SST_CAP_ERR_CAPTURE_FAIL, /* ANY:Capture op failed */
SST_CAP_ERR_GET_DDR_NEW_SGLIST,
SST_CAP_ERR_UNDER_RUN, /* lack of input data */
SST_CAP_ERR_OVERFLOW, /* lack of output space */
/* Playback specific error codes*/
SST_PB_ERR_INCMPLTE_PLAY_MSG, /* ANY: Incomplete message */
SST_PB_ERR_PLAY_FAIL, /* ANY: Playback operation failed */
SST_PB_ERR_GET_DDR_NEW_SGLIST,
/* Codec manager specific error codes */
SST_LIB_ERR_LIB_DNLD_REQUIRED, /* ALLOC: Codec download required */
SST_LIB_ERR_LIB_NOT_SUPPORTED, /* Library is not supported */
/* Library manager specific error codes */
SST_SCC_ERR_PREP_DNLD_FAILED, /* Failed to prepare for codec download */
SST_SCC_ERR_LIB_DNLD_RES_FAILED, /* Lib download resume failed */
/* Scheduler specific error codes */
SST_SCH_ERR_FAIL, /* REPORT: */
/* DMA specific error codes */
SST_DMA_ERR_NO_CHNL_AVAILABLE, /* DMA Ch not available */
SST_DMA_ERR_INVALID_INPUT_PARAMS, /* Invalid input params */
SST_DMA_ERR_CHNL_ALREADY_SUSPENDED, /* Ch is suspended */
SST_DMA_ERR_CHNL_ALREADY_STARTED, /* Ch already started */
SST_DMA_ERR_CHNL_NOT_ENABLED, /* Ch not enabled */
SST_DMA_ERR_TRANSFER_FAILED, /* Transfer failed */
SST_SSP_ERR_ALREADY_ENABLED, /* REPORT: SSP already enabled */
SST_SSP_ERR_ALREADY_DISABLED, /* REPORT: SSP already disabled */
SST_SSP_ERR_NOT_INITIALIZED,
/* Other error codes */
SST_ERR_MOD_INIT_FAIL, /* Firmware Module init failed */
/* FW init error codes */
SST_RDR_ERR_IO_DEV_SEL_NOT_ALLOWED,
SST_RDR_ERR_ROUTE_ALREADY_STARTED,
SST_RDR_PREP_CODEC_DNLD_FAILED,
/* Memory debug error codes */
SST_ERR_DBG_MEM_READ_FAIL,
SST_ERR_DBG_MEM_WRITE_FAIL,
/* Decode error codes */
SST_ERR_DEC_NEED_INPUT_BUF,
};
enum dbg_mem_data_type {
/* Data type of debug read/write */
DATA_TYPE_U32,
DATA_TYPE_U16,
DATA_TYPE_U8,
};
/* CAUTION NOTE: All IPC message body must be multiple of 32 bits.*/
/* IPC Header */
union ipc_header {
struct {
u32 msg_id:8; /* Message ID - Max 256 Message Types */
u32 str_id:5;
u32 large:1; /* Large Message if large = 1 */
u32 reserved:2; /* Reserved for future use */
u32 data:14; /* Ack/Info for msg, size of msg in Mailbox */
u32 done:1; /* bit 30 */
u32 busy:1; /* bit 31 */
} part;
u32 full;
} __attribute__ ((packed));
/* Firmware build info */
struct sst_fw_build_info {
unsigned char date[16]; /* Firmware build date */
unsigned char time[16]; /* Firmware build time */
} __attribute__ ((packed));
struct ipc_header_fw_init {
struct snd_sst_fw_version fw_version;/* Firmware version details */
struct sst_fw_build_info build_info;
u16 result; /* Fw init result */
u8 module_id; /* Module ID in case of error */
u8 debug_info; /* Debug info from Module ID in case of fail */
} __attribute__ ((packed));
/* Address and size info of a frame buffer in DDR */
struct sst_address_info {
u32 addr; /* Address at IA */
u32 size; /* Size of the buffer */
} __attribute__ ((packed));
/* Time stamp */
struct snd_sst_tstamp {
u64 samples_processed;/* capture - data in DDR */
u64 samples_rendered;/* playback - data rendered */
u64 bytes_processed;/* bytes decoded or encoded */
u32 sampling_frequency;/* eg: 48000, 44100 */
u32 dma_base_address;/* DMA base address */
u16 dma_channel_no;/* DMA Channel used for the data transfer*/
u16 reserved;/* 32 bit alignment */
};
/* Frame info to play or capture */
struct sst_frame_info {
u16 num_entries; /* number of entries to follow */
u16 rsrvd;
struct sst_address_info addr[MAX_NUM_SCATTER_BUFFERS];
} __attribute__ ((packed));
/* Frames info for decode */
struct snd_sst_decode_info {
unsigned long long input_bytes_consumed;
unsigned long long output_bytes_produced;
struct sst_frame_info frames_in;
struct sst_frame_info frames_out;
} __attribute__ ((packed));
/* SST to IA print debug message*/
struct ipc_sst_ia_print_params {
u32 string_size;/* Max value is 160 */
u8 prt_string[160];/* Null terminated Char string */
} __attribute__ ((packed));
/* Voice data message */
struct snd_sst_voice_data {
u16 num_bytes;/* Number of valid voice data bytes */
u8 pcm_wd_size;/* 0=8 bit, 1=16 bit 2=32 bit */
u8 reserved;/* Reserved */
u8 voice_data_buf[0];/* Voice data buffer in bytes, little endian */
} __attribute__ ((packed));
/* SST to IA memory read debug message */
struct ipc_sst_ia_dbg_mem_rw {
u16 num_bytes;/* Maximum of MAX_DBG_RW_BYTES */
u16 data_type;/* enum: dbg_mem_data_type */
u32 address; /* Memory address of data memory of data_type */
u8 rw_bytes[MAX_DBG_RW_BYTES];/* Maximum of 64 bytes can be RW */
} __attribute__ ((packed));
struct ipc_sst_ia_dbg_loop_back {
u16 num_dwords; /* Maximum of MAX_DBG_RW_BYTES */
u16 increment_val;/* Increments dwords by this value, 0- no increment */
u32 lpbk_dwords[MAX_LOOP_BACK_DWORDS];/* Maximum of 8 dwords loopback */
} __attribute__ ((packed));
/* Stream type params struture for Alloc stream */
struct snd_sst_str_type {
u8 codec_type; /* Codec type */
u8 str_type; /* 1 = voice 2 = music */
u8 operation; /* Playback or Capture */
u8 protected_str; /* 0=Non DRM, 1=DRM */
u8 time_slots;
u8 reserved; /* Reserved */
u16 result; /* Result used for acknowledgment */
} __attribute__ ((packed));
/* Library info structure */
struct module_info {
u32 lib_version;
u32 lib_type;/*TBD- KLOCKWORK u8 lib_type;*/
u32 media_type;
u8 lib_name[12];
u32 lib_caps;
unsigned char b_date[16]; /* Lib build date */
unsigned char b_time[16]; /* Lib build time */
} __attribute__ ((packed));
/* Library slot info */
struct lib_slot_info {
u8 slot_num; /* 1 or 2 */
u8 reserved1;
u16 reserved2;
u32 iram_size; /* slot size in IRAM */
u32 dram_size; /* slot size in DRAM */
u32 iram_offset; /* starting offset of slot in IRAM */
u32 dram_offset; /* starting offset of slot in DRAM */
} __attribute__ ((packed));
struct snd_sst_lib_download {
struct module_info lib_info; /* library info type, capabilities etc */
struct lib_slot_info slot_info; /* slot info to be downloaded */
u32 mod_entry_pt;
};
struct snd_sst_lib_download_info {
struct snd_sst_lib_download dload_lib;
u16 result; /* Result used for acknowledgment */
u8 pvt_id; /* Private ID */
u8 reserved; /* for alignment */
};
/* Alloc stream params structure */
struct snd_sst_alloc_params {
struct snd_sst_str_type str_type;
struct snd_sst_stream_params stream_params;
};
struct snd_sst_fw_get_stream_params {
struct snd_sst_stream_params codec_params;
struct snd_sst_pmic_config pcm_params;
};
/* Alloc stream response message */
struct snd_sst_alloc_response {
struct snd_sst_str_type str_type; /* Stream type for allocation */
struct snd_sst_lib_download lib_dnld; /* Valid only for codec dnld */
};
/* Drop response */
struct snd_sst_drop_response {
u32 result;
u32 bytes;
};
/* CSV Voice call routing structure */
struct snd_sst_control_routing {
u8 control; /* 0=start, 1=Stop */
u8 reserved[3]; /* Reserved- for 32 bit alignment */
};
struct ipc_post {
struct list_head node;
union ipc_header header; /* driver specific */
char *mailbox_data;
};
#endif /* __INTEL_SST_FW_IPC_H__ */
+435
View File
@@ -0,0 +1,435 @@
#ifndef __INTEL_SST_IOCTL_H__
#define __INTEL_SST_IOCTL_H__
/*
* intel_sst_ioctl.h - Intel SST Driver for audio engine
*
* Copyright (C) 2008-10 Intel Corporation
* 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 defines all sst ioctls
*/
/* codec and post/pre processing related info */
#include <linux/types.h>
enum sst_codec_types {
/* AUDIO/MUSIC CODEC Type Definitions */
SST_CODEC_TYPE_UNKNOWN = 0,
SST_CODEC_TYPE_PCM, /* Pass through Audio codec */
SST_CODEC_TYPE_MP3,
SST_CODEC_TYPE_MP24,
SST_CODEC_TYPE_AAC,
SST_CODEC_TYPE_AACP,
SST_CODEC_TYPE_eAACP,
SST_CODEC_TYPE_WMA9,
SST_CODEC_TYPE_WMA10,
SST_CODEC_TYPE_WMA10P,
SST_CODEC_TYPE_RA,
SST_CODEC_TYPE_DDAC3,
SST_CODEC_TYPE_STEREO_TRUE_HD,
SST_CODEC_TYPE_STEREO_HD_PLUS,
/* VOICE CODEC Type Definitions */
SST_CODEC_TYPE_VOICE_PCM = 0x21, /* Pass through voice codec */
};
enum sst_algo_types {
SST_CODEC_SRC = 0x64,
SST_CODEC_MIXER = 0x65,
SST_CODEC_DOWN_MIXER = 0x66,
SST_CODEC_VOLUME_CONTROL = 0x67,
SST_CODEC_OEM1 = 0xC8,
SST_CODEC_OEM2 = 0xC9,
};
enum snd_sst_stream_ops {
STREAM_OPS_PLAYBACK = 0, /* Decode */
STREAM_OPS_CAPTURE, /* Encode */
STREAM_OPS_PLAYBACK_DRM, /* Play Audio/Voice */
STREAM_OPS_PLAYBACK_ALERT, /* Play Audio/Voice */
STREAM_OPS_CAPTURE_VOICE_CALL, /* CSV Voice recording */
};
enum stream_mode {
SST_STREAM_MODE_NONE = 0,
SST_STREAM_MODE_DNR = 1,
SST_STREAM_MODE_FNF = 2,
SST_STREAM_MODE_CAPTURE = 3
};
enum stream_type {
SST_STREAM_TYPE_NONE = 0,
SST_STREAM_TYPE_MUSIC = 1,
SST_STREAM_TYPE_NORMAL = 2,
SST_STREAM_TYPE_LONG_PB = 3,
SST_STREAM_TYPE_LOW_LATENCY = 4,
};
enum snd_sst_audio_device_type {
SND_SST_DEVICE_HEADSET = 1,
SND_SST_DEVICE_IHF,
SND_SST_DEVICE_VIBRA,
SND_SST_DEVICE_HAPTIC,
SND_SST_DEVICE_CAPTURE,
};
/* Firmware Version info */
struct snd_sst_fw_version {
__u8 build; /* build number*/
__u8 minor; /* minor number*/
__u8 major; /* major number*/
__u8 type; /* build type */
};
/* Port info structure */
struct snd_sst_port_info {
__u16 port_type;
__u16 reserved;
};
/* Mixer info structure */
struct snd_sst_mix_info {
__u16 max_streams;
__u16 reserved;
};
/* PCM Parameters */
struct snd_pcm_params {
__u16 codec; /* codec type */
__u8 num_chan; /* 1=Mono, 2=Stereo */
__u8 pcm_wd_sz; /* 16/24 - bit*/
__u32 reserved; /* Bitrate in bits per second */
__u32 sfreq; /* Sampling rate in Hz */
__u32 ring_buffer_size;
__u32 period_count; /* period elapsed in samples*/
__u32 ring_buffer_addr;
};
/* MP3 Music Parameters Message */
struct snd_mp3_params {
__u16 codec;
__u8 num_chan; /* 1=Mono, 2=Stereo */
__u8 pcm_wd_sz; /* 16/24 - bit*/
__u32 brate; /* Use the hard coded value. */
__u32 sfreq; /* Sampling freq eg. 8000, 441000, 48000 */
__u8 crc_check; /* crc_check - disable (0) or enable (1) */
__u8 op_align; /* op align 0- 16 bit, 1- MSB, 2 LSB*/
__u16 reserved; /* Unused */
};
#define AAC_BIT_STREAM_ADTS 0
#define AAC_BIT_STREAM_ADIF 1
#define AAC_BIT_STREAM_RAW 2
/* AAC Music Parameters Message */
struct snd_aac_params {
__u16 codec;
__u8 num_chan; /* 1=Mono, 2=Stereo*/
__u8 pcm_wd_sz; /* 16/24 - bit*/
__u32 brate;
__u32 sfreq; /* Sampling freq eg. 8000, 441000, 48000 */
__u32 aac_srate; /* Plain AAC decoder operating sample rate */
__u8 mpg_id; /* 0=MPEG-2, 1=MPEG-4 */
__u8 bs_format; /* input bit stream format adts=0, adif=1, raw=2 */
__u8 aac_profile; /* 0=Main Profile, 1=LC profile, 3=SSR profile */
__u8 ext_chl; /* No.of external channels */
__u8 aot; /* Audio object type. 1=Main , 2=LC , 3=SSR, 4=SBR*/
__u8 op_align; /* output alignment 0=16 bit , 1=MSB, 2= LSB align */
__u8 brate_type; /* 0=CBR, 1=VBR */
__u8 crc_check; /* crc check 0= disable, 1=enable */
__s8 bit_stream_format[8]; /* input bit stream format adts/adif/raw */
__u8 jstereo; /* Joint stereo Flag */
__u8 sbr_present; /* 1 = SBR Present, 0 = SBR absent, for RAW */
__u8 downsample; /* 1 = Downsampling ON, 0 = Downsampling OFF */
__u8 num_syntc_elems; /* 1- Mono/stereo, 0 - Dual Mono, 0 - for raw */
__s8 syntc_id[2]; /* 0 for ID_SCE(Dula Mono), -1 for raw */
__s8 syntc_tag[2]; /* raw - -1 and 0 -16 for rest of the streams */
__u8 pce_present; /* Flag. 1- present 0 - not present, for RAW */
__u8 sbr_type; /* sbr_type: 0-plain aac, 1-aac-v1, 2-aac-v2 */
__u8 outchmode; /*0- mono, 1-stereo, 2-dual mono 3-Parametric stereo */
__u8 ps_present;
};
/* WMA Music Parameters Message */
struct snd_wma_params {
__u16 codec;
__u8 num_chan; /* 1=Mono, 2=Stereo */
__u8 pcm_wd_sz; /* 16/24 - bit*/
__u32 brate; /* Use the hard coded value. */
__u32 sfreq; /* Sampling freq eg. 8000, 441000, 48000 */
__u32 channel_mask; /* Channel Mask */
__u16 format_tag; /* Format Tag */
__u16 block_align; /* packet size */
__u16 wma_encode_opt;/* Encoder option */
__u8 op_align; /* op align 0- 16 bit, 1- MSB, 2 LSB */
__u8 pcm_src; /* input pcm bit width */
};
/* Pre processing param structure */
struct snd_prp_params {
__u32 reserved; /* No pre-processing defined yet */
};
struct snd_params_block {
__u32 type; /*Type of the parameter*/
__u32 size; /*size of the parameters in the block*/
__u8 params[0]; /*Parameters of the algorithm*/
};
/* Pre and post processing params structure */
struct snd_ppp_params {
enum sst_algo_types algo_id;/* Post/Pre processing algorithm ID */
__u8 str_id; /*Only 5 bits used 0 - 31 are valid*/
__u8 enable; /* 0= disable, 1= enable*/
__u8 reserved;
__u32 size; /*Size of parameters for all blocks*/
struct snd_params_block params[0];
};
struct snd_sst_postproc_info {
__u32 src_min; /* Supported SRC Min sampling freq */
__u32 src_max; /* Supported SRC Max sampling freq */
__u8 src; /* 0=Not supported, 1=Supported */
__u8 bass_boost; /* 0=Not Supported, 1=Supported */
__u8 stereo_widening; /* 0=Not Supported, 1=Supported */
__u8 volume_control; /* 0=Not Supported, 1=Supported */
__s16 min_vol; /* Minimum value of Volume in dB */
__s16 max_vol; /* Maximum value of Volume in dB */
__u8 mute_control; /* 0=No Mute, 1=Mute */
__u8 reserved1;
__u16 reserved2;
};
/* pre processing Capability info structure */
struct snd_sst_prp_info {
__s16 min_vol; /* Minimum value of Volume in dB */
__s16 max_vol; /* Maximum value of Volume in dB */
__u8 volume_control; /* 0=Not Supported, 1=Supported */
__u8 reserved1; /* for 32 bit alignment */
__u16 reserved2; /* for 32 bit alignment */
} __attribute__ ((packed));
/*Pre / Post processing algorithms support*/
struct snd_sst_ppp_info {
__u32 src:1; /* 0=Not supported, 1=Supported */
__u32 mixer:1; /* 0=Not supported, 1=Supported */
__u32 volume_control:1; /* 0=Not Supported, 1=Supported */
__u32 mute_control:1; /* 0=Not Supported, 1=Supported */
__u32 anc:1; /* 0=Not Supported, 1=Supported */
__u32 side_tone:1; /* 0=Not Supported, 1=Supported */
__u32 dc_removal:1; /* 0=Not Supported, 1=Supported */
__u32 equalizer:1; /* 0=Not Supported, 1=Supported */
__u32 spkr_prot:1; /* 0=Not Supported, 1=Supported */
__u32 bass_boost:1; /* 0=Not Supported, 1=Supported */
__u32 stereo_widening:1;/* 0=Not Supported, 1=Supported */
__u32 rsvd1:21;
__u32 rsvd2;
};
/* Firmware capabilities info */
struct snd_sst_fw_info {
struct snd_sst_fw_version fw_version; /* Firmware version */
__u8 audio_codecs_supported[8]; /* Codecs supported by FW */
__u32 recommend_min_duration; /* Min duration for Lowpower Playback */
__u8 max_pcm_streams_supported; /* Max num of PCM streams supported */
__u8 max_enc_streams_supported; /* Max number of Encoded streams */
__u16 reserved; /* 32 bit alignment*/
struct snd_sst_ppp_info ppp_info; /* pre_processing mod cap info */
struct snd_sst_postproc_info pop_info; /* Post processing cap info*/
struct snd_sst_port_info port_info[3]; /* Port info */
struct snd_sst_mix_info mix_info;/* Mixer info */
__u32 min_input_buf; /* minmum i/p buffer for decode */
};
/* Codec params struture */
union snd_sst_codec_params {
struct snd_pcm_params pcm_params;
struct snd_mp3_params mp3_params;
struct snd_aac_params aac_params;
struct snd_wma_params wma_params;
};
struct snd_sst_stream_params {
union snd_sst_codec_params uc;
} __attribute__ ((packed));
struct snd_sst_params {
__u32 result;
__u32 stream_id;
__u8 codec;
__u8 ops;
__u8 stream_type;
__u8 device_type;
struct snd_sst_stream_params sparams;
};
struct snd_sst_vol {
__u32 stream_id;
__s32 volume;
__u32 ramp_duration;
__u32 ramp_type; /* Ramp type, default=0 */
};
struct snd_sst_mute {
__u32 stream_id;
__u32 mute;
};
/* ioctl related stuff here */
struct snd_sst_pmic_config {
__u32 sfreq; /* Sampling rate in Hz */
__u16 num_chan; /* Mono =1 or Stereo =2 */
__u16 pcm_wd_sz; /* Number of bits per sample */
} __attribute__ ((packed));
struct snd_sst_get_stream_params {
struct snd_sst_params codec_params;
struct snd_sst_pmic_config pcm_params;
};
enum snd_sst_target_type {
SND_SST_TARGET_PMIC = 1,
SND_SST_TARGET_LPE,
SND_SST_TARGET_MODEM,
SND_SST_TARGET_BT,
SND_SST_TARGET_FM,
SND_SST_TARGET_NONE,
};
enum snd_sst_device_type {
SND_SST_DEVICE_SSP = 1,
SND_SST_DEVICE_PCM,
SND_SST_DEVICE_OTHER,
};
enum snd_sst_device_mode {
SND_SST_DEV_MODE_PCM_MODE1 = 1, /*(16-bit word, bit-length frame sync)*/
SND_SST_DEV_MODE_PCM_MODE2,
SND_SST_DEV_MODE_PCM_MODE3,
SND_SST_DEV_MODE_PCM_MODE4_RIGHT_JUSTIFIED,
SND_SST_DEV_MODE_PCM_MODE4_LEFT_JUSTIFIED,
SND_SST_DEV_MODE_PCM_MODE4_I2S, /*(I2S mode, 16-bit words)*/
SND_SST_DEV_MODE_PCM_MODE5,
SND_SST_DEV_MODE_PCM_MODE6,
};
enum snd_sst_port_action {
SND_SST_PORT_PREPARE = 1,
SND_SST_PORT_ACTIVATE,
};
/* Target selection per device structure */
struct snd_sst_slot_info {
__u8 mix_enable; /* Mixer enable or disable */
__u8 device_type;
__u8 device_instance; /* 0, 1, 2 */
__u8 target_device;
__u16 target_sink;
__u8 slot[2];
__u8 master;
__u8 action;
__u8 device_mode;
__u8 reserved;
struct snd_sst_pmic_config pcm_params;
} __attribute__ ((packed));
#define SST_MAX_TARGET_DEVICES 3
/* Target device list structure */
struct snd_sst_target_device {
__u32 device_route;
struct snd_sst_slot_info devices[SST_MAX_TARGET_DEVICES];
} __attribute__ ((packed));
struct snd_sst_driver_info {
__u32 version; /* Version of the driver */
__u32 active_pcm_streams;
__u32 active_enc_streams;
__u32 max_pcm_streams;
__u32 max_enc_streams;
__u32 buf_per_stream;
};
enum snd_sst_buff_type {
SST_BUF_USER = 1,
SST_BUF_MMAP,
SST_BUF_RAR,
};
struct snd_sst_mmap_buff_entry {
unsigned int offset;
unsigned int size;
};
struct snd_sst_mmap_buffs {
unsigned int entries;
enum snd_sst_buff_type type;
struct snd_sst_mmap_buff_entry *buff;
};
struct snd_sst_buff_entry {
void *buffer;
unsigned int size;
};
struct snd_sst_buffs {
unsigned int entries;
__u8 type;
struct snd_sst_buff_entry *buff_entry;
};
struct snd_sst_dbufs {
unsigned long long input_bytes_consumed;
unsigned long long output_bytes_produced;
struct snd_sst_buffs *ibufs;
struct snd_sst_buffs *obufs;
};
/*IOCTL defined here */
/*SST MMF IOCTLS only */
#define SNDRV_SST_STREAM_SET_PARAMS _IOR('L', 0x00, \
struct snd_sst_stream_params *)
#define SNDRV_SST_STREAM_GET_PARAMS _IOWR('L', 0x01, \
struct snd_sst_get_stream_params *)
#define SNDRV_SST_STREAM_GET_TSTAMP _IOWR('L', 0x02, __u64 *)
#define SNDRV_SST_STREAM_DECODE _IOWR('L', 0x03, struct snd_sst_dbufs *)
#define SNDRV_SST_STREAM_BYTES_DECODED _IOWR('L', 0x04, __u64 *)
#define SNDRV_SST_STREAM_START _IO('A', 0x42)
#define SNDRV_SST_STREAM_DROP _IO('A', 0x43)
#define SNDRV_SST_STREAM_DRAIN _IO('A', 0x44)
#define SNDRV_SST_STREAM_PAUSE _IOW('A', 0x45, int)
#define SNDRV_SST_STREAM_RESUME _IO('A', 0x47)
#define SNDRV_SST_MMAP_PLAY _IOW('L', 0x05, struct snd_sst_mmap_buffs *)
#define SNDRV_SST_MMAP_CAPTURE _IOW('L', 0x06, struct snd_sst_mmap_buffs *)
/*SST common ioctls */
#define SNDRV_SST_DRIVER_INFO _IOR('L', 0x10, struct snd_sst_driver_info *)
#define SNDRV_SST_SET_VOL _IOW('L', 0x11, struct snd_sst_vol *)
#define SNDRV_SST_GET_VOL _IOW('L', 0x12, struct snd_sst_vol *)
#define SNDRV_SST_MUTE _IOW('L', 0x13, struct snd_sst_mute *)
/*AM Ioctly only */
#define SNDRV_SST_FW_INFO _IOR('L', 0x20, struct snd_sst_fw_info *)
#define SNDRV_SST_SET_TARGET_DEVICE _IOW('L', 0x21, \
struct snd_sst_target_device *)
#endif /* __INTEL_SST_IOCTL_H__ */
File diff suppressed because it is too large Load Diff
+311
View File
@@ -0,0 +1,311 @@
/*
* intel_sst_pvt.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 driver exposes the audio engine functionalities to the ALSA
* and middleware.
*
* This file contains all private functions
*/
#include <linux/pci.h>
#include <linux/fs.h>
#include <linux/firmware.h>
#include <linux/sched.h>
#include "intel_sst.h"
#include "intel_sst_ioctl.h"
#include "intel_sst_fw_ipc.h"
#include "intel_sst_common.h"
/*
* sst_get_block_stream - get a new block stream
*
* @sst_drv_ctx: Driver context structure
*
* This function assigns a block for the calls that dont have stream context yet
* the blocks are used for waiting on Firmware's response for any operation
* Should be called with stream lock held
*/
int sst_get_block_stream(struct intel_sst_drv *sst_drv_ctx)
{
int i;
for (i = 0; i < MAX_ACTIVE_STREAM; i++) {
if (sst_drv_ctx->alloc_block[i].sst_id == BLOCK_UNINIT) {
sst_drv_ctx->alloc_block[i].ops_block.condition = false;
sst_drv_ctx->alloc_block[i].ops_block.ret_code = 0;
sst_drv_ctx->alloc_block[i].sst_id = 0;
break;
}
}
if (i == MAX_ACTIVE_STREAM) {
pr_err("sst: max alloc_stream reached");
i = -EBUSY; /* active stream limit reached */
}
return i;
}
/*
* sst_wait_interruptible - wait on event
*
* @sst_drv_ctx: Driver context
* @block: Driver block to wait on
*
* This function waits without a timeout (and is interruptable) for a
* given block event
*/
int sst_wait_interruptible(struct intel_sst_drv *sst_drv_ctx,
struct sst_block *block)
{
int retval = 0;
if (!wait_event_interruptible(sst_drv_ctx->wait_queue,
block->condition)) {
/* event wake */
if (block->ret_code < 0) {
pr_err("sst: stream failed %d\n", block->ret_code);
retval = -EBUSY;
} else {
pr_debug("sst: event up\n");
retval = 0;
}
} else {
pr_err("sst: signal interrupted\n");
retval = -EINTR;
}
return retval;
}
/*
* sst_wait_interruptible_timeout - wait on event interruptable
*
* @sst_drv_ctx: Driver context
* @block: Driver block to wait on
* @timeout: time for wait on
*
* This function waits with a timeout value (and is interruptible) on a
* given block event
*/
int sst_wait_interruptible_timeout(
struct intel_sst_drv *sst_drv_ctx,
struct sst_block *block, int timeout)
{
int retval = 0;
pr_debug("sst: sst_wait_interruptible_timeout - waiting....\n");
if (wait_event_interruptible_timeout(sst_drv_ctx->wait_queue,
block->condition,
msecs_to_jiffies(timeout))) {
if (block->ret_code < 0)
pr_err("sst: stream failed %d\n", block->ret_code);
else
pr_debug("sst: event up\n");
retval = block->ret_code;
} else {
block->on = false;
pr_err("sst: timeout occured...\n");
/*setting firmware state as uninit so that the
firmware will get re-downloaded on next request
this is because firmare not responding for 5 sec
is equalant to some unrecoverable error of FW
sst_drv_ctx->sst_state = SST_UN_INIT;*/
retval = -EBUSY;
}
return retval;
}
/*
* sst_wait_timeout - wait on event for timeout
*
* @sst_drv_ctx: Driver context
* @block: Driver block to wait on
*
* This function waits with a timeout value (and is not interruptible) on a
* given block event
*/
int sst_wait_timeout(struct intel_sst_drv *sst_drv_ctx,
struct stream_alloc_block *block)
{
int retval = 0;
/* NOTE:
Observed that FW processes the alloc msg and replies even
before the alloc thread has finished execution */
pr_debug("sst: waiting for %x, condition %x\n",
block->sst_id, block->ops_block.condition);
if (wait_event_interruptible_timeout(sst_drv_ctx->wait_queue,
block->ops_block.condition,
msecs_to_jiffies(SST_BLOCK_TIMEOUT))) {
/* event wake */
pr_debug("sst: Event wake %x\n", block->ops_block.condition);
pr_debug("sst: message ret: %d\n", block->ops_block.ret_code);
retval = block->ops_block.ret_code;
} else {
block->ops_block.on = false;
pr_err("sst: Wait timed-out %x\n", block->ops_block.condition);
/* settign firmware state as uninit so that the
firmware will get redownloaded on next request
this is because firmare not responding for 5 sec
is equalant to some unrecoverable error of FW
sst_drv_ctx->sst_state = SST_UN_INIT;*/
retval = -EBUSY;
}
return retval;
}
/*
* sst_create_large_msg - create a large IPC message
*
* @arg: ipc message
*
* this function allocates structures to send a large message to the firmware
*/
int sst_create_large_msg(struct ipc_post **arg)
{
struct ipc_post *msg;
msg = kzalloc(sizeof(struct ipc_post), GFP_ATOMIC);
if (!msg) {
pr_err("sst: kzalloc msg failed\n");
return -ENOMEM;
}
msg->mailbox_data = kzalloc(SST_MAILBOX_SIZE, GFP_ATOMIC);
if (!msg->mailbox_data) {
kfree(msg);
pr_err("sst: kzalloc mailbox_data failed");
return -ENOMEM;
};
*arg = msg;
return 0;
}
/*
* sst_create_short_msg - create a short IPC message
*
* @arg: ipc message
*
* this function allocates structures to send a short message to the firmware
*/
int sst_create_short_msg(struct ipc_post **arg)
{
struct ipc_post *msg;
msg = kzalloc(sizeof(*msg), GFP_ATOMIC);
if (!msg) {
pr_err("sst: kzalloc msg failed\n");
return -ENOMEM;
}
msg->mailbox_data = NULL;
*arg = msg;
return 0;
}
/*
* sst_clean_stream - clean the stream context
*
* @stream: stream structure
*
* this function resets the stream contexts
* should be called in free
*/
void sst_clean_stream(struct stream_info *stream)
{
struct sst_stream_bufs *bufs = NULL, *_bufs;
stream->status = STREAM_UN_INIT;
stream->prev = STREAM_UN_INIT;
mutex_lock(&stream->lock);
list_for_each_entry_safe(bufs, _bufs, &stream->bufs, node) {
list_del(&bufs->node);
kfree(bufs);
}
mutex_unlock(&stream->lock);
if (stream->ops != STREAM_OPS_PLAYBACK_DRM)
kfree(stream->decode_ibuf);
}
/*
* sst_wake_up_alloc_block - wake up waiting block
*
* @sst_drv_ctx: Driver context
* @sst_id: stream id
* @status: status of wakeup
* @data: data pointer of wakeup
*
* This function wakes up a sleeping block event based on the response
*/
void sst_wake_up_alloc_block(struct intel_sst_drv *sst_drv_ctx,
u8 sst_id, int status, void *data)
{
int i;
/* Unblock with retval code */
for (i = 0; i < MAX_ACTIVE_STREAM; i++) {
if (sst_id == sst_drv_ctx->alloc_block[i].sst_id) {
sst_drv_ctx->alloc_block[i].ops_block.condition = true;
sst_drv_ctx->alloc_block[i].ops_block.ret_code = status;
sst_drv_ctx->alloc_block[i].ops_block.data = data;
wake_up(&sst_drv_ctx->wait_queue);
break;
}
}
}
/*
* sst_enable_rx_timeslot - Send msg to query for stream parameters
* @status: rx timeslot to be enabled
*
* This function is called when the RX timeslot is required to be enabled
*/
int sst_enable_rx_timeslot(int status)
{
int retval = 0;
struct ipc_post *msg = NULL;
if (sst_create_short_msg(&msg)) {
pr_err("sst: mem allocation failed\n");
return -ENOMEM;
}
pr_debug("sst: ipc message sending: ENABLE_RX_TIME_SLOT\n");
sst_fill_header(&msg->header, IPC_IA_ENABLE_RX_TIME_SLOT, 0, 0);
msg->header.part.data = status;
sst_drv_ctx->hs_info_blk.condition = false;
sst_drv_ctx->hs_info_blk.ret_code = 0;
sst_drv_ctx->hs_info_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,
&sst_drv_ctx->hs_info_blk, SST_BLOCK_TIMEOUT);
return retval;
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+186
View File
@@ -0,0 +1,186 @@
/*
* intelmid.h - Intel Sound card driver for MID
*
* Copyright (C) 2008-10 Intel Corp
* Authors: Harsha Priya <priya.harsha@intel.com>
* Vinod Koul <vinod.koul@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.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* ALSA driver header for Intel MAD chipset
*/
#ifndef __INTELMID_H
#define __INTELMID_H
#include <linux/time.h>
#define DRIVER_NAME_MFLD "msic_audio"
#define DRIVER_NAME_MRST "pmic_audio"
#define DRIVER_NAME "intelmid_audio"
#define PMIC_SOUND_IRQ_TYPE_MASK (1 << 15)
#define AUDINT_BASE (0xFFFFEFF8 + (6 * sizeof(u8)))
#define REG_IRQ
/* values #defined */
/* will differ for different hw - to be taken from config */
#define MAX_DEVICES 1
#define MIN_RATE 8000
#define MAX_RATE 48000
#define MAX_BUFFER (800*1024) /* for PCM */
#define MIN_BUFFER (800*1024)
#define MAX_PERIODS (1024*2)
#define MIN_PERIODS 1
#define MAX_PERIOD_BYTES MAX_BUFFER
#define MIN_PERIOD_BYTES 32
/*#define MIN_PERIOD_BYTES 160*/
#define MAX_MUTE 1
#define MIN_MUTE 0
#define MONO_CNTL 1
#define STEREO_CNTL 2
#define MIN_CHANNEL 1
#define MAX_CHANNEL_AMIC 2
#define MAX_CHANNEL_DMIC 4
#define FIFO_SIZE 0 /* fifo not being used */
#define INTEL_MAD "Intel MAD"
#define MAX_CTRL_MRST 7
#define MAX_CTRL_MFLD 2
#define MAX_CTRL 7
#define MAX_VENDORS 4
/* TODO +6 db */
#define MAX_VOL 64
/* TODO -57 db */
#define MIN_VOL 0
#define PLAYBACK_COUNT 1
#define CAPTURE_COUNT 1
extern int sst_card_vendor_id;
struct mad_jack {
struct snd_jack jack;
int jack_status;
struct timeval buttonpressed;
struct timeval buttonreleased;
};
struct mad_jack_msg_wq {
u8 intsts;
struct snd_intelmad *intelmaddata;
struct work_struct wq;
};
/**
* struct snd_intelmad - intelmad driver structure
*
* @card: ptr to the card details
* @card_index: sound card index
* @card_id: sound card id detected
* @sstdrv_ops: ptr to sst driver ops
* @pdev: ptr to platfrom device
* @irq: interrupt number detected
* @pmic_status: Device status of sound card
* @int_base: ptr to MMIO interrupt region
* @output_sel: device slected as o/p
* @input_sel: device slected as i/p
* @master_mute: master mute status
* @jack: jack status
* @playback_cnt: active pb streams
* @capture_cnt: active cp streams
* @mad_jack_msg: wq struct for jack interrupt processing
* @mad_jack_wq: wq for jack interrupt processing
* @jack_prev_state: Previos state of jack detected
* @cpu_id: current cpu id loaded for
*/
struct snd_intelmad {
struct snd_card *card; /* ptr to the card details */
int card_index;/* card index */
char *card_id; /* card id */
struct intel_sst_card_ops *sstdrv_ops;/* ptr to sst driver ops */
struct platform_device *pdev;
int irq;
int pmic_status;
void __iomem *int_base;
int output_sel;
int input_sel;
int master_mute;
struct mad_jack jack[4];
int playback_cnt;
int capture_cnt;
struct mad_jack_msg_wq mad_jack_msg;
struct workqueue_struct *mad_jack_wq;
u8 jack_prev_state;
unsigned int cpu_id;
};
struct snd_control_val {
int playback_vol_max;
int playback_vol_min;
int capture_vol_max;
int capture_vol_min;
};
struct mad_stream_pvt {
int stream_status;
int stream_ops;
struct snd_pcm_substream *substream;
struct pcm_stream_info stream_info;
ssize_t dbg_cum_bytes;
enum snd_sst_device_type device;
};
enum mad_drv_status {
INIT = 1,
STARTED,
RUNNING,
PAUSED,
DROPPED,
};
enum mad_pmic_status {
PMIC_UNINIT = 1,
PMIC_INIT,
};
enum _widget_ctrl {
OUTPUT_SEL = 1,
INPUT_SEL,
PLAYBACK_VOL,
PLAYBACK_MUTE,
CAPTURE_VOL,
CAPTURE_MUTE,
MASTER_MUTE
};
void period_elapsed(void *mad_substream);
int snd_intelmad_alloc_stream(struct snd_pcm_substream *substream);
int snd_intelmad_init_stream(struct snd_pcm_substream *substream);
int sst_sc_reg_access(struct sc_reg_access *sc_access,
int type, int num_val);
#define CPU_CHIP_LINCROFT 1 /* System running lincroft */
#define CPU_CHIP_PENWELL 2 /* System running penwell */
extern struct snd_control_val intelmad_ctrl_val[];
extern struct snd_kcontrol_new snd_intelmad_controls_mrst[];
extern struct snd_kcontrol_new snd_intelmad_controls_mfld[];
extern struct snd_pmic_ops *intelmad_vendor_ops[];
/* This is an enabler hook as the platform detection logic isn't yet
present and depends on some firmware and DMI support to detect AAVA
devices. It will vanish once the AAVA platform support is merged */
#define is_aava() 0
#endif /* __INTELMID_H */
File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More