2019-05-27 06:55:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-11-17 09:12:23 +00:00
|
|
|
/*
|
|
|
|
* Driver for audio on multifunction CS5535 companion device
|
|
|
|
* Copyright (C) Jaya Kumar
|
|
|
|
*
|
|
|
|
* Based on Jaroslav Kysela and Takashi Iwai's examples.
|
|
|
|
* This work was sponsored by CIS(M) Sdn Bhd.
|
|
|
|
*
|
|
|
|
* todo: add be fmt support, spdif, pm
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/control.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <sound/asoundef.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/ac97_codec.h>
|
|
|
|
#include "cs5535audio.h"
|
|
|
|
|
2017-08-12 15:31:17 +00:00
|
|
|
static const struct snd_pcm_hardware snd_cs5535audio_playback =
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
.info = (
|
|
|
|
SNDRV_PCM_INFO_MMAP |
|
|
|
|
SNDRV_PCM_INFO_INTERLEAVED |
|
|
|
|
SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
|
|
|
SNDRV_PCM_INFO_MMAP_VALID |
|
|
|
|
SNDRV_PCM_INFO_PAUSE |
|
2006-04-28 12:34:49 +00:00
|
|
|
SNDRV_PCM_INFO_RESUME
|
2005-11-17 09:12:23 +00:00
|
|
|
),
|
|
|
|
.formats = (
|
|
|
|
SNDRV_PCM_FMTBIT_S16_LE
|
|
|
|
),
|
|
|
|
.rates = (
|
|
|
|
SNDRV_PCM_RATE_CONTINUOUS |
|
|
|
|
SNDRV_PCM_RATE_8000_48000
|
|
|
|
),
|
|
|
|
.rate_min = 4000,
|
|
|
|
.rate_max = 48000,
|
|
|
|
.channels_min = 2,
|
|
|
|
.channels_max = 2,
|
|
|
|
.buffer_bytes_max = (128*1024),
|
|
|
|
.period_bytes_min = 64,
|
|
|
|
.period_bytes_max = (64*1024 - 16),
|
|
|
|
.periods_min = 1,
|
|
|
|
.periods_max = CS5535AUDIO_MAX_DESCRIPTORS,
|
|
|
|
.fifo_size = 0,
|
|
|
|
};
|
|
|
|
|
2017-08-12 15:31:17 +00:00
|
|
|
static const struct snd_pcm_hardware snd_cs5535audio_capture =
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
.info = (
|
|
|
|
SNDRV_PCM_INFO_MMAP |
|
|
|
|
SNDRV_PCM_INFO_INTERLEAVED |
|
|
|
|
SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
2007-08-13 15:37:55 +00:00
|
|
|
SNDRV_PCM_INFO_MMAP_VALID
|
2005-11-17 09:12:23 +00:00
|
|
|
),
|
|
|
|
.formats = (
|
|
|
|
SNDRV_PCM_FMTBIT_S16_LE
|
|
|
|
),
|
|
|
|
.rates = (
|
|
|
|
SNDRV_PCM_RATE_CONTINUOUS |
|
|
|
|
SNDRV_PCM_RATE_8000_48000
|
|
|
|
),
|
|
|
|
.rate_min = 4000,
|
|
|
|
.rate_max = 48000,
|
|
|
|
.channels_min = 2,
|
|
|
|
.channels_max = 2,
|
|
|
|
.buffer_bytes_max = (128*1024),
|
|
|
|
.period_bytes_min = 64,
|
|
|
|
.period_bytes_max = (64*1024 - 16),
|
|
|
|
.periods_min = 1,
|
|
|
|
.periods_max = CS5535AUDIO_MAX_DESCRIPTORS,
|
|
|
|
.fifo_size = 0,
|
|
|
|
};
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static int snd_cs5535audio_playback_open(struct snd_pcm_substream *substream)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
int err;
|
2005-11-17 13:56:21 +00:00
|
|
|
struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2005-11-17 09:12:23 +00:00
|
|
|
|
|
|
|
runtime->hw = snd_cs5535audio_playback;
|
2008-01-21 10:49:03 +00:00
|
|
|
runtime->hw.rates = cs5535au->ac97->rates[AC97_RATES_FRONT_DAC];
|
|
|
|
snd_pcm_limit_hw_rates(runtime);
|
2005-11-17 09:12:23 +00:00
|
|
|
cs5535au->playback_substream = substream;
|
|
|
|
runtime->private_data = &(cs5535au->dmas[CS5535AUDIO_DMA_PLAYBACK]);
|
|
|
|
if ((err = snd_pcm_hw_constraint_integer(runtime,
|
|
|
|
SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static int snd_cs5535audio_playback_close(struct snd_pcm_substream *substream)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CS5535AUDIO_DESC_LIST_SIZE \
|
2005-11-17 13:56:21 +00:00
|
|
|
PAGE_ALIGN(CS5535AUDIO_MAX_DESCRIPTORS * sizeof(struct cs5535audio_dma_desc))
|
2005-11-17 09:12:23 +00:00
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static int cs5535audio_build_dma_packets(struct cs5535audio *cs5535au,
|
|
|
|
struct cs5535audio_dma *dma,
|
|
|
|
struct snd_pcm_substream *substream,
|
|
|
|
unsigned int periods,
|
|
|
|
unsigned int period_bytes)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
u32 addr, desc_addr, jmpprd_addr;
|
2005-11-17 13:56:21 +00:00
|
|
|
struct cs5535audio_dma_desc *lastdesc;
|
2005-11-17 09:12:23 +00:00
|
|
|
|
|
|
|
if (periods > CS5535AUDIO_MAX_DESCRIPTORS)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (dma->desc_buf.area == NULL) {
|
|
|
|
if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
|
2019-11-05 15:18:55 +00:00
|
|
|
&cs5535au->pci->dev,
|
2005-11-17 09:12:23 +00:00
|
|
|
CS5535AUDIO_DESC_LIST_SIZE+1,
|
|
|
|
&dma->desc_buf) < 0)
|
|
|
|
return -ENOMEM;
|
|
|
|
dma->period_bytes = dma->periods = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dma->periods == periods && dma->period_bytes == period_bytes)
|
|
|
|
return 0;
|
|
|
|
|
2006-06-26 16:35:02 +00:00
|
|
|
/* the u32 cast is okay because in snd*create we successfully told
|
2005-11-17 09:12:23 +00:00
|
|
|
pci alloc that we're only 32 bit capable so the uppper will be 0 */
|
|
|
|
addr = (u32) substream->runtime->dma_addr;
|
|
|
|
desc_addr = (u32) dma->desc_buf.addr;
|
|
|
|
for (i = 0; i < periods; i++) {
|
2005-11-17 13:56:21 +00:00
|
|
|
struct cs5535audio_dma_desc *desc =
|
|
|
|
&((struct cs5535audio_dma_desc *) dma->desc_buf.area)[i];
|
2005-11-17 09:12:23 +00:00
|
|
|
desc->addr = cpu_to_le32(addr);
|
2011-11-20 20:57:49 +00:00
|
|
|
desc->size = cpu_to_le16(period_bytes);
|
2011-06-30 10:31:23 +00:00
|
|
|
desc->ctlreserved = cpu_to_le16(PRD_EOP);
|
2005-11-17 13:56:21 +00:00
|
|
|
desc_addr += sizeof(struct cs5535audio_dma_desc);
|
2005-11-17 09:12:23 +00:00
|
|
|
addr += period_bytes;
|
|
|
|
}
|
|
|
|
/* we reserved one dummy descriptor at the end to do the PRD jump */
|
2005-11-17 13:56:21 +00:00
|
|
|
lastdesc = &((struct cs5535audio_dma_desc *) dma->desc_buf.area)[periods];
|
2005-11-17 09:12:23 +00:00
|
|
|
lastdesc->addr = cpu_to_le32((u32) dma->desc_buf.addr);
|
|
|
|
lastdesc->size = 0;
|
2011-06-30 10:31:23 +00:00
|
|
|
lastdesc->ctlreserved = cpu_to_le16(PRD_JMP);
|
2018-07-25 15:59:26 +00:00
|
|
|
jmpprd_addr = (u32)dma->desc_buf.addr +
|
|
|
|
sizeof(struct cs5535audio_dma_desc) * periods;
|
2005-11-17 09:12:23 +00:00
|
|
|
|
2007-09-03 13:41:47 +00:00
|
|
|
dma->substream = substream;
|
2005-11-17 09:12:23 +00:00
|
|
|
dma->period_bytes = period_bytes;
|
|
|
|
dma->periods = periods;
|
|
|
|
spin_lock_irq(&cs5535au->reg_lock);
|
|
|
|
dma->ops->disable_dma(cs5535au);
|
|
|
|
dma->ops->setup_prd(cs5535au, jmpprd_addr);
|
|
|
|
spin_unlock_irq(&cs5535au->reg_lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static void cs5535audio_playback_enable_dma(struct cs5535audio *cs5535au)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
cs_writeb(cs5535au, ACC_BM0_CMD, BM_CTL_EN);
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static void cs5535audio_playback_disable_dma(struct cs5535audio *cs5535au)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
cs_writeb(cs5535au, ACC_BM0_CMD, 0);
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static void cs5535audio_playback_pause_dma(struct cs5535audio *cs5535au)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
cs_writeb(cs5535au, ACC_BM0_CMD, BM_CTL_PAUSE);
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static void cs5535audio_playback_setup_prd(struct cs5535audio *cs5535au,
|
|
|
|
u32 prd_addr)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
cs_writel(cs5535au, ACC_BM0_PRD, prd_addr);
|
|
|
|
}
|
|
|
|
|
2006-04-28 12:34:49 +00:00
|
|
|
static u32 cs5535audio_playback_read_prd(struct cs5535audio *cs5535au)
|
|
|
|
{
|
|
|
|
return cs_readl(cs5535au, ACC_BM0_PRD);
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static u32 cs5535audio_playback_read_dma_pntr(struct cs5535audio *cs5535au)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
return cs_readl(cs5535au, ACC_BM0_PNTR);
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static void cs5535audio_capture_enable_dma(struct cs5535audio *cs5535au)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
cs_writeb(cs5535au, ACC_BM1_CMD, BM_CTL_EN);
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static void cs5535audio_capture_disable_dma(struct cs5535audio *cs5535au)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
cs_writeb(cs5535au, ACC_BM1_CMD, 0);
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static void cs5535audio_capture_pause_dma(struct cs5535audio *cs5535au)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
cs_writeb(cs5535au, ACC_BM1_CMD, BM_CTL_PAUSE);
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static void cs5535audio_capture_setup_prd(struct cs5535audio *cs5535au,
|
|
|
|
u32 prd_addr)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
cs_writel(cs5535au, ACC_BM1_PRD, prd_addr);
|
|
|
|
}
|
|
|
|
|
2006-04-28 12:34:49 +00:00
|
|
|
static u32 cs5535audio_capture_read_prd(struct cs5535audio *cs5535au)
|
|
|
|
{
|
|
|
|
return cs_readl(cs5535au, ACC_BM1_PRD);
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static u32 cs5535audio_capture_read_dma_pntr(struct cs5535audio *cs5535au)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
return cs_readl(cs5535au, ACC_BM1_PNTR);
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static void cs5535audio_clear_dma_packets(struct cs5535audio *cs5535au,
|
|
|
|
struct cs5535audio_dma *dma,
|
|
|
|
struct snd_pcm_substream *substream)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
snd_dma_free_pages(&dma->desc_buf);
|
|
|
|
dma->desc_buf.area = NULL;
|
2007-09-03 13:41:47 +00:00
|
|
|
dma->substream = NULL;
|
2005-11-17 09:12:23 +00:00
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static int snd_cs5535audio_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *hw_params)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
2005-11-17 13:56:21 +00:00
|
|
|
struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
|
|
|
|
struct cs5535audio_dma *dma = substream->runtime->private_data;
|
2005-11-17 09:12:23 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = snd_pcm_lib_malloc_pages(substream,
|
|
|
|
params_buffer_bytes(hw_params));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
dma->buf_addr = substream->runtime->dma_addr;
|
|
|
|
dma->buf_bytes = params_buffer_bytes(hw_params);
|
|
|
|
|
|
|
|
err = cs5535audio_build_dma_packets(cs5535au, dma, substream,
|
2005-11-17 13:56:21 +00:00
|
|
|
params_periods(hw_params),
|
|
|
|
params_period_bytes(hw_params));
|
2008-11-05 22:30:08 +00:00
|
|
|
if (!err)
|
|
|
|
dma->pcm_open_flag = 1;
|
|
|
|
|
2005-11-17 09:12:23 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static int snd_cs5535audio_hw_free(struct snd_pcm_substream *substream)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
2005-11-17 13:56:21 +00:00
|
|
|
struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
|
|
|
|
struct cs5535audio_dma *dma = substream->runtime->private_data;
|
2005-11-17 09:12:23 +00:00
|
|
|
|
2008-11-05 22:30:08 +00:00
|
|
|
if (dma->pcm_open_flag) {
|
|
|
|
if (substream == cs5535au->playback_substream)
|
|
|
|
snd_ac97_update_power(cs5535au->ac97,
|
|
|
|
AC97_PCM_FRONT_DAC_RATE, 0);
|
|
|
|
else
|
|
|
|
snd_ac97_update_power(cs5535au->ac97,
|
|
|
|
AC97_PCM_LR_ADC_RATE, 0);
|
|
|
|
dma->pcm_open_flag = 0;
|
|
|
|
}
|
2005-11-17 09:12:23 +00:00
|
|
|
cs5535audio_clear_dma_packets(cs5535au, dma, substream);
|
|
|
|
return snd_pcm_lib_free_pages(substream);
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static int snd_cs5535audio_playback_prepare(struct snd_pcm_substream *substream)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
2005-11-17 13:56:21 +00:00
|
|
|
struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
|
2005-11-17 09:12:23 +00:00
|
|
|
return snd_ac97_set_rate(cs5535au->ac97, AC97_PCM_FRONT_DAC_RATE,
|
2005-11-17 13:56:21 +00:00
|
|
|
substream->runtime->rate);
|
2005-11-17 09:12:23 +00:00
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static int snd_cs5535audio_trigger(struct snd_pcm_substream *substream, int cmd)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
2005-11-17 13:56:21 +00:00
|
|
|
struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
|
|
|
|
struct cs5535audio_dma *dma = substream->runtime->private_data;
|
2005-11-17 09:15:37 +00:00
|
|
|
int err = 0;
|
2005-11-17 09:12:23 +00:00
|
|
|
|
2005-11-17 09:15:37 +00:00
|
|
|
spin_lock(&cs5535au->reg_lock);
|
2005-11-17 09:12:23 +00:00
|
|
|
switch (cmd) {
|
2005-11-17 09:15:37 +00:00
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
|
|
|
dma->ops->pause_dma(cs5535au);
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
|
|
|
dma->ops->enable_dma(cs5535au);
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
|
|
|
dma->ops->enable_dma(cs5535au);
|
|
|
|
break;
|
2006-04-28 12:34:49 +00:00
|
|
|
case SNDRV_PCM_TRIGGER_RESUME:
|
|
|
|
dma->ops->enable_dma(cs5535au);
|
|
|
|
break;
|
2005-11-17 09:15:37 +00:00
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
|
|
|
dma->ops->disable_dma(cs5535au);
|
|
|
|
break;
|
2006-04-28 12:34:49 +00:00
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
|
|
|
dma->ops->disable_dma(cs5535au);
|
|
|
|
break;
|
2005-11-17 09:15:37 +00:00
|
|
|
default:
|
2014-02-25 15:10:25 +00:00
|
|
|
dev_err(cs5535au->card->dev, "unhandled trigger\n");
|
2005-11-17 09:15:37 +00:00
|
|
|
err = -EINVAL;
|
|
|
|
break;
|
2005-11-17 09:12:23 +00:00
|
|
|
}
|
2005-11-17 09:15:37 +00:00
|
|
|
spin_unlock(&cs5535au->reg_lock);
|
|
|
|
return err;
|
2005-11-17 09:12:23 +00:00
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static snd_pcm_uframes_t snd_cs5535audio_pcm_pointer(struct snd_pcm_substream
|
2005-11-17 09:12:23 +00:00
|
|
|
*substream)
|
|
|
|
{
|
2005-11-17 13:56:21 +00:00
|
|
|
struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
|
2005-11-17 09:12:23 +00:00
|
|
|
u32 curdma;
|
2005-11-17 13:56:21 +00:00
|
|
|
struct cs5535audio_dma *dma;
|
2005-11-17 09:12:23 +00:00
|
|
|
|
|
|
|
dma = substream->runtime->private_data;
|
|
|
|
curdma = dma->ops->read_dma_pntr(cs5535au);
|
|
|
|
if (curdma < dma->buf_addr) {
|
2014-02-25 15:10:25 +00:00
|
|
|
dev_err(cs5535au->card->dev, "curdma=%x < %x bufaddr.\n",
|
2005-11-17 09:12:23 +00:00
|
|
|
curdma, dma->buf_addr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
curdma -= dma->buf_addr;
|
|
|
|
if (curdma >= dma->buf_bytes) {
|
2014-02-25 15:10:25 +00:00
|
|
|
dev_err(cs5535au->card->dev, "diff=%x >= %x buf_bytes.\n",
|
2005-11-17 09:12:23 +00:00
|
|
|
curdma, dma->buf_bytes);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return bytes_to_frames(substream->runtime, curdma);
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static int snd_cs5535audio_capture_open(struct snd_pcm_substream *substream)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
|
|
|
int err;
|
2005-11-17 13:56:21 +00:00
|
|
|
struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2005-11-17 09:12:23 +00:00
|
|
|
|
|
|
|
runtime->hw = snd_cs5535audio_capture;
|
2008-01-21 10:49:03 +00:00
|
|
|
runtime->hw.rates = cs5535au->ac97->rates[AC97_RATES_ADC];
|
|
|
|
snd_pcm_limit_hw_rates(runtime);
|
2005-11-17 09:12:23 +00:00
|
|
|
cs5535au->capture_substream = substream;
|
|
|
|
runtime->private_data = &(cs5535au->dmas[CS5535AUDIO_DMA_CAPTURE]);
|
|
|
|
if ((err = snd_pcm_hw_constraint_integer(runtime,
|
|
|
|
SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
|
|
|
|
return err;
|
2008-11-06 21:53:03 +00:00
|
|
|
olpc_capture_open(cs5535au->ac97);
|
2005-11-17 09:12:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static int snd_cs5535audio_capture_close(struct snd_pcm_substream *substream)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
2008-11-06 21:50:09 +00:00
|
|
|
struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
|
2008-11-06 21:53:03 +00:00
|
|
|
olpc_capture_close(cs5535au->ac97);
|
2005-11-17 09:12:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:56:21 +00:00
|
|
|
static int snd_cs5535audio_capture_prepare(struct snd_pcm_substream *substream)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
2005-11-17 13:56:21 +00:00
|
|
|
struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
|
2005-11-17 09:12:23 +00:00
|
|
|
return snd_ac97_set_rate(cs5535au->ac97, AC97_PCM_LR_ADC_RATE,
|
2005-11-17 13:56:21 +00:00
|
|
|
substream->runtime->rate);
|
2005-11-17 09:12:23 +00:00
|
|
|
}
|
|
|
|
|
2016-09-01 22:13:09 +00:00
|
|
|
static const struct snd_pcm_ops snd_cs5535audio_playback_ops = {
|
2005-11-17 09:12:23 +00:00
|
|
|
.open = snd_cs5535audio_playback_open,
|
|
|
|
.close = snd_cs5535audio_playback_close,
|
|
|
|
.ioctl = snd_pcm_lib_ioctl,
|
|
|
|
.hw_params = snd_cs5535audio_hw_params,
|
|
|
|
.hw_free = snd_cs5535audio_hw_free,
|
|
|
|
.prepare = snd_cs5535audio_playback_prepare,
|
|
|
|
.trigger = snd_cs5535audio_trigger,
|
|
|
|
.pointer = snd_cs5535audio_pcm_pointer,
|
|
|
|
};
|
|
|
|
|
2016-09-01 22:13:09 +00:00
|
|
|
static const struct snd_pcm_ops snd_cs5535audio_capture_ops = {
|
2005-11-17 09:12:23 +00:00
|
|
|
.open = snd_cs5535audio_capture_open,
|
|
|
|
.close = snd_cs5535audio_capture_close,
|
|
|
|
.ioctl = snd_pcm_lib_ioctl,
|
|
|
|
.hw_params = snd_cs5535audio_hw_params,
|
|
|
|
.hw_free = snd_cs5535audio_hw_free,
|
|
|
|
.prepare = snd_cs5535audio_capture_prepare,
|
|
|
|
.trigger = snd_cs5535audio_trigger,
|
|
|
|
.pointer = snd_cs5535audio_pcm_pointer,
|
|
|
|
};
|
|
|
|
|
2015-12-30 10:44:53 +00:00
|
|
|
static const struct cs5535audio_dma_ops snd_cs5535audio_playback_dma_ops = {
|
2005-11-17 09:12:23 +00:00
|
|
|
.type = CS5535AUDIO_DMA_PLAYBACK,
|
|
|
|
.enable_dma = cs5535audio_playback_enable_dma,
|
|
|
|
.disable_dma = cs5535audio_playback_disable_dma,
|
|
|
|
.setup_prd = cs5535audio_playback_setup_prd,
|
2006-04-28 12:34:49 +00:00
|
|
|
.read_prd = cs5535audio_playback_read_prd,
|
2005-11-17 09:12:23 +00:00
|
|
|
.pause_dma = cs5535audio_playback_pause_dma,
|
|
|
|
.read_dma_pntr = cs5535audio_playback_read_dma_pntr,
|
|
|
|
};
|
|
|
|
|
2015-12-30 10:44:53 +00:00
|
|
|
static const struct cs5535audio_dma_ops snd_cs5535audio_capture_dma_ops = {
|
2005-11-17 09:12:23 +00:00
|
|
|
.type = CS5535AUDIO_DMA_CAPTURE,
|
|
|
|
.enable_dma = cs5535audio_capture_enable_dma,
|
|
|
|
.disable_dma = cs5535audio_capture_disable_dma,
|
|
|
|
.setup_prd = cs5535audio_capture_setup_prd,
|
2006-04-28 12:34:49 +00:00
|
|
|
.read_prd = cs5535audio_capture_read_prd,
|
2005-11-17 09:12:23 +00:00
|
|
|
.pause_dma = cs5535audio_capture_pause_dma,
|
|
|
|
.read_dma_pntr = cs5535audio_capture_read_dma_pntr,
|
|
|
|
};
|
|
|
|
|
2012-12-06 17:35:10 +00:00
|
|
|
int snd_cs5535audio_pcm(struct cs5535audio *cs5535au)
|
2005-11-17 09:12:23 +00:00
|
|
|
{
|
2005-11-17 13:56:21 +00:00
|
|
|
struct snd_pcm *pcm;
|
2005-11-17 09:12:23 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = snd_pcm_new(cs5535au->card, "CS5535 Audio", 0, 1, 1, &pcm);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
cs5535au->dmas[CS5535AUDIO_DMA_PLAYBACK].ops =
|
|
|
|
&snd_cs5535audio_playback_dma_ops;
|
|
|
|
cs5535au->dmas[CS5535AUDIO_DMA_CAPTURE].ops =
|
|
|
|
&snd_cs5535audio_capture_dma_ops;
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
|
|
|
|
&snd_cs5535audio_playback_ops);
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
|
|
|
|
&snd_cs5535audio_capture_ops);
|
|
|
|
|
|
|
|
pcm->private_data = cs5535au;
|
|
|
|
pcm->info_flags = 0;
|
|
|
|
strcpy(pcm->name, "CS5535 Audio");
|
|
|
|
|
|
|
|
snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
|
2019-11-05 15:18:55 +00:00
|
|
|
&cs5535au->pci->dev,
|
|
|
|
64*1024, 128*1024);
|
2006-04-28 12:34:49 +00:00
|
|
|
cs5535au->pcm = pcm;
|
2005-11-17 09:12:23 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|