From: Ian Minett <ian_minett@creativelabs.com>
To: patch@alsa-project.org
Cc: alsa-devel@alsa-project.org, Ian Minett <ian_minett@creativelabs.com>
Subject: [PATCHv2.1-CA0132 HDA Codec 2/2] Add DSP loader code to CA0132 codec
Date: Fri, 10 Aug 2012 23:17:52 -0700 [thread overview]
Message-ID: <1344665872-15537-2-git-send-email-ian_minett@creativelabs.com> (raw)
In-Reply-To: <1344665872-15537-1-git-send-email-ian_minett@creativelabs.com>
From: Ian Minett <ian_minett@creativelabs.com>
Draft patch to add new DSP loader code, with calls to load_dsp_xxxx() functions.
Signed-off-by: Ian Minett <ian_minett@creativelabs.com>
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index 825f5b4..45dce9c 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -1952,22 +1952,13 @@ struct dma_engine {
unsigned short m_converter_format;
void *m_buffer_addr;
unsigned int m_buffer_size;
- unsigned int m_req_size;
- struct snd_pcm_substream *substream;
};
enum dma_state {
- DMA_STATE_RESET = 0,
- DMA_STATE_STOP = 1,
- DMA_STATE_RUN = 2
+ DMA_STATE_STOP = 0,
+ DMA_STATE_RUN = 1
};
-#define azx_pcm_open(a) (a->ops->open(a))
-#define azx_pcm_close(a) (a->ops->close(a))
-#define azx_pcm_prepare(a) (a->ops->prepare(a))
-#define azx_pcm_trigger(a, b) (a->ops->trigger(a, b))
-#define azx_pcm_hw_free(a) (a->ops->hw_free(a))
-
static int dma_convert_to_hda_format(
struct hda_stream_format *stream_format,
unsigned short *hda_format)
@@ -1986,113 +1977,6 @@ static int dma_convert_to_hda_format(
return 0;
}
-static int dma_init(
- struct hda_codec *codec,
- struct dma_engine **pp_dma,
- struct hda_stream_format *stream_format,
- unsigned short *format,
- unsigned int req_size)
-{
- struct dma_engine *dma;
- struct snd_pcm_substream *substream;
- struct snd_pcm *pcm;
- struct snd_pcm_runtime *runtime;
- unsigned int bits;
- snd_pcm_uframes_t frames;
-
- *pp_dma = NULL;
- dma = kzalloc(sizeof(*dma), GFP_KERNEL);
- memset((void *)dma, 0, sizeof(*dma));
-
- dma_convert_to_hda_format(stream_format, format);
- dma->m_converter_format = *format;
-
- dma->substream = NULL;
- pcm = codec->pcm_info->pcm;
- for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
- substream; substream = substream->next) {
- if (codec->pcm_info->pcm_type == HDA_PCM_TYPE_SPDIF)
- continue;
-
- if (!SUBSTREAM_BUSY(substream)) {
- dma->substream = substream;
- break;
- }
- }
-
- if (NULL == dma->substream) {
- kfree(dma);
- return -1;
- }
-
- runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
- memset((void *)runtime, 0, sizeof(*runtime));
- dma->substream->runtime = runtime;
- dma->substream->private_data = pcm->private_data;
-
- azx_pcm_open(dma->substream);
- req_size = req_size * 2;
- snd_pcm_lib_malloc_pages(dma->substream, req_size);
-
- runtime->rate = stream_format->sample_rate;
- runtime->channels = stream_format->number_channels;
- runtime->format = SNDRV_PCM_FORMAT_S32_LE;
- runtime->no_period_wakeup = 1;
-
- bits = snd_pcm_format_physical_width(runtime->format);
- runtime->sample_bits = bits;
- bits *= runtime->channels;
- runtime->frame_bits = bits;
- frames = 1;
- while (bits % 8 != 0) {
- bits *= 2;
- frames *= 2;
- }
- runtime->byte_align = bits / 8;
- runtime->min_align = frames;
- runtime->buffer_size = bytes_to_frames(runtime, req_size);
- runtime->period_size = runtime->buffer_size;
- dma->m_req_size = req_size;
- dma->codec = codec;
-
- *pp_dma = dma;
- CA0132_LOG("dma_init: succeeded.\n");
- return 0;
-}
-
-static int dma_prepare(struct dma_engine *dma)
-{
- struct snd_pcm_runtime *runtime;
- int err;
-
- CA0132_LOG("dma_prepare: begin\n");
- runtime = dma->substream->runtime;
-
- err = azx_pcm_prepare(dma->substream);
- if (err < 0)
- return -1;
-
- dma->m_buffer_size = snd_pcm_lib_buffer_bytes(dma->substream);
- dma->m_buffer_addr = runtime->dma_area;
-
- return 0;
-}
-
-static int dma_reset(struct dma_engine *dma)
-{
- struct snd_pcm_runtime *runtime = dma->substream->runtime;
-
- CA0132_LOG("dma_reset: begin\n");
- azx_pcm_hw_free(dma->substream);
- snd_pcm_lib_malloc_pages(dma->substream, dma->m_req_size);
-
- azx_pcm_prepare(dma->substream);
- dma->m_buffer_size = snd_pcm_lib_buffer_bytes(dma->substream);
- dma->m_buffer_addr = runtime->dma_area;
-
- return 0;
-}
-
static int dma_set_state(struct dma_engine *dma, enum dma_state state)
{
int cmd;
@@ -2100,9 +1984,6 @@ static int dma_set_state(struct dma_engine *dma, enum dma_state state)
CA0132_LOG("dma_set_state state=%d\n", state);
switch (state) {
- case DMA_STATE_RESET:
- dma_reset(dma);
- return 0;
case DMA_STATE_STOP:
cmd = SNDRV_PCM_TRIGGER_STOP;
break;
@@ -2113,9 +1994,7 @@ static int dma_set_state(struct dma_engine *dma, enum dma_state state)
return 0;
}
- azx_pcm_trigger(dma->substream, cmd);
-
- return 0;
+ return load_dsp_trigger(dma->codec->bus, cmd);
}
static unsigned int dma_get_buffer_size(struct dma_engine *dma)
@@ -2128,15 +2007,6 @@ static unsigned int *dma_get_buffer_addr(struct dma_engine *dma)
return dma->m_buffer_addr;
}
-static int dma_free_buffer(struct dma_engine *dma)
-{
- azx_pcm_hw_free(dma->substream);
- azx_pcm_close(dma->substream);
- kfree(dma->substream->runtime);
- dma->substream->runtime = NULL;
- return 0;
-}
-
static int dma_xfer(struct dma_engine *dma,
const unsigned int *data,
unsigned int count)
@@ -2160,13 +2030,6 @@ static unsigned int dma_get_stream_id(struct dma_engine *dma)
return spec->dsp_stream_id;
}
-static int dma_exit(struct dma_engine *dma)
-{
- CA0132_LOG("dma_exit\n");
- kfree(dma);
- return 0;
-}
-
/*
* CA0132 chip DSP image segment stuffs
*/
@@ -2384,7 +2247,6 @@ static int dspxfr_one_seg(struct hda_codec *codec,
}
CA0132_DSP_LOG("+++++ DMA complete");
dma_set_state(dma_engine, DMA_STATE_STOP);
- dma_set_state(dma_engine, DMA_STATE_RESET);
}
CTASSERT(run_size_words <= words_to_write);
@@ -2413,17 +2275,29 @@ static int dspxfr_image(struct hda_codec *codec,
struct dma_engine *dma_engine;
unsigned int dma_chan;
unsigned int port_map_mask;
- unsigned int buf_size;
CTASSERT(fls_data != NULL);
if (fls_data == NULL)
return -1;
- buf_size = ovly ? DSP_DMA_WRITE_BUFLEN_OVLY : DSP_DMA_WRITE_BUFLEN_INIT;
- status = dma_init(codec, &dma_engine, format, &hda_format, buf_size);
-
- if (FAILED(status))
- return -1;
+ dma_engine = kzalloc(sizeof(*dma_engine), GFP_KERNEL);
+ if (!dma_engine) {
+ status = -ENOMEM;
+ goto exit;
+ }
+ memset((void*)dma_engine, 0, sizeof(*dma_engine));
+
+ dma_engine->codec = codec;
+ dma_convert_to_hda_format(format, &hda_format);
+ dma_engine->m_converter_format = hda_format;
+ dma_engine->m_buffer_size =
+ ovly ? DSP_DMA_WRITE_BUFLEN_OVLY : DSP_DMA_WRITE_BUFLEN_INIT;
+ dma_engine->m_buffer_addr = kzalloc(dma_engine->m_buffer_size,
+ GFP_KERNEL);
+ if (!dma_engine->m_buffer_addr) {
+ status = -ENOMEM;
+ goto exit;
+ }
dma_chan = 0;
do {
@@ -2434,7 +2308,10 @@ static int dspxfr_image(struct hda_codec *codec,
break;
}
- status = dma_prepare(dma_engine);
+ status = load_dsp_prepare(codec->bus,
+ dma_engine->m_converter_format,
+ dma_engine->m_buffer_addr,
+ dma_engine->m_buffer_size);
if (FAILED(status))
break;
@@ -2495,15 +2372,9 @@ static int dspxfr_image(struct hda_codec *codec,
if (ovly && (dma_chan != INVALID_DMA_CHANNEL))
status = dspio_free_dma_chan(codec, dma_chan);
- status = dma_set_state(dma_engine, DMA_STATE_RESET);
- if (FAILED(status))
- status = FAIL_MSG(status, "dma set state Reset fail");
-
- status = dma_free_buffer(dma_engine);
- if (FAILED(status))
- status = FAIL_MSG(status, "dma free buffer fail");
-
- dma_exit(dma_engine);
+exit:
+ kfree(dma_engine->m_buffer_addr);
+ kfree(dma_engine);
return status;
}
--
1.7.4.1
next prev parent reply other threads:[~2012-08-11 6:17 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1342223070-25852-1-git-send-email-ian_minett@creativelabs.com>
2012-07-13 23:44 ` [PATCH - CA0132 HDA Codec 2/2] Change spin_lock()/unlock() to spin_lock_irqsave()/restore() in azx_pcm_trigger(). This prevents deadlock when an interrupt occurs, caused by chip->reg_lock contention ian_minett
2012-07-16 10:18 ` [PATCH - CA0132 HDA Codec 1/2] ALSA: Update Creative CA0132 codec to add DSP features Takashi Iwai
2012-07-25 18:01 ` [PATCHv2 " Ian Minett
2012-07-25 18:01 ` [PATCHv2 - CA0132 HDA Codec 2/2] Change spin_lock()/unlock() to spin_lock_irqsave()/restore() Ian Minett
2012-07-26 8:06 ` [PATCHv2 - CA0132 HDA Codec 1/2] ALSA: Update Creative CA0132 codec to add DSP features Takashi Iwai
[not found] ` <OF0CFC3DA9.A9100453-ON88257A48.006BF087-88257A48.006FCB42@cli.creative.com>
2012-07-28 5:57 ` Takashi Iwai
[not found] ` <OF301523C9.1A0D8E05-ON88257A4B.0074BC06-88257A4B.007D5630@cli.creative.com>
2012-07-31 15:15 ` Takashi Iwai
2012-08-01 2:38 ` Ian Minett
2012-08-01 5:48 ` Takashi Iwai
2012-08-04 3:29 ` Ian Minett
2012-08-04 7:29 ` Takashi Iwai
2012-08-08 0:27 ` Ian Minett
2012-08-08 7:22 ` Takashi Iwai
[not found] ` <1344665872-15537-1-git-send-email-ian_minett@creativelabs.com>
2012-08-11 6:17 ` Ian Minett [this message]
2012-08-11 7:12 ` [PATCHv2.1-CA0132 HDA Codec 2/2] Add DSP loader code to CA0132 codec Takashi Iwai
2012-08-13 23:04 ` Ian Minett
2012-08-15 5:50 ` [PATCHv2.1-CA0132 HDA Codec 1/1] Draft DSP loader update #2 Ian Minett
2012-08-15 7:06 ` Takashi Iwai
2012-08-22 1:36 ` Ian Minett
2012-08-22 13:39 ` Takashi Iwai
2012-08-11 7:19 ` [PATCHv2.1-CA0132 HDA Codec 1/2] Add DSP loader code to CA0132 codec Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1344665872-15537-2-git-send-email-ian_minett@creativelabs.com \
--to=ian_minett@creativelabs.com \
--cc=alsa-devel@alsa-project.org \
--cc=patch@alsa-project.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).