Commit a6970bb1 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: gus: Convert to the new PCM ops

Replace the copy and the silence ops with the new PCM ops.
For simplifying the code a bit, two local helpers are introduced here:
get_bpos() and playback_copy_ack().
Reviewed-by: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 0925e6b2
...@@ -353,26 +353,25 @@ static int snd_gf1_pcm_poke_block(struct snd_gus_card *gus, unsigned char *buf, ...@@ -353,26 +353,25 @@ static int snd_gf1_pcm_poke_block(struct snd_gus_card *gus, unsigned char *buf,
return 0; return 0;
} }
static int snd_gf1_pcm_playback_copy(struct snd_pcm_substream *substream, static int get_bpos(struct gus_pcm_private *pcmp, int voice, unsigned int pos,
int voice, unsigned int len)
snd_pcm_uframes_t pos,
void __user *src,
snd_pcm_uframes_t count)
{ {
struct snd_pcm_runtime *runtime = substream->runtime; unsigned int bpos = pos + (voice * (pcmp->dma_size / 2));
struct gus_pcm_private *pcmp = runtime->private_data;
struct snd_gus_card *gus = pcmp->gus;
unsigned int bpos, len;
int w16, invert;
bpos = samples_to_bytes(runtime, pos) + (voice * (pcmp->dma_size / 2));
len = samples_to_bytes(runtime, count);
if (snd_BUG_ON(bpos > pcmp->dma_size)) if (snd_BUG_ON(bpos > pcmp->dma_size))
return -EIO; return -EIO;
if (snd_BUG_ON(bpos + len > pcmp->dma_size)) if (snd_BUG_ON(bpos + len > pcmp->dma_size))
return -EIO; return -EIO;
if (copy_from_user(runtime->dma_area + bpos, src, len)) return bpos;
return -EFAULT; }
static int playback_copy_ack(struct snd_pcm_substream *substream,
unsigned int bpos, unsigned int len)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct gus_pcm_private *pcmp = runtime->private_data;
struct snd_gus_card *gus = pcmp->gus;
int w16, invert;
if (len > 32) if (len > 32)
return snd_gf1_pcm_block_change(substream, bpos, return snd_gf1_pcm_block_change(substream, bpos,
pcmp->memory + bpos, len); pcmp->memory + bpos, len);
...@@ -383,33 +382,54 @@ static int snd_gf1_pcm_playback_copy(struct snd_pcm_substream *substream, ...@@ -383,33 +382,54 @@ static int snd_gf1_pcm_playback_copy(struct snd_pcm_substream *substream,
pcmp->memory + bpos, len, w16, invert); pcmp->memory + bpos, len, w16, invert);
} }
static int snd_gf1_pcm_playback_copy(struct snd_pcm_substream *substream,
int voice, unsigned long pos,
void __user *src, unsigned long count)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct gus_pcm_private *pcmp = runtime->private_data;
unsigned int len = count;
int bpos;
bpos = get_bpos(pcmp, voice, pos, len);
if (bpos < 0)
return pos;
if (copy_from_user(runtime->dma_area + bpos, src, len))
return -EFAULT;
return playback_copy_ack(substream, bpos, len);
}
static int snd_gf1_pcm_playback_copy_kernel(struct snd_pcm_substream *substream,
int voice, unsigned long pos,
void *src, unsigned long count)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct gus_pcm_private *pcmp = runtime->private_data;
unsigned int len = count;
int bpos;
bpos = get_bpos(pcmp, voice, pos, len);
if (bpos < 0)
return pos;
memcpy(runtime->dma_area + bpos, src, len);
return playback_copy_ack(substream, bpos, len);
}
static int snd_gf1_pcm_playback_silence(struct snd_pcm_substream *substream, static int snd_gf1_pcm_playback_silence(struct snd_pcm_substream *substream,
int voice, int voice, unsigned long pos,
snd_pcm_uframes_t pos, unsigned long count)
snd_pcm_uframes_t count)
{ {
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
struct gus_pcm_private *pcmp = runtime->private_data; struct gus_pcm_private *pcmp = runtime->private_data;
struct snd_gus_card *gus = pcmp->gus; unsigned int len = count;
unsigned int bpos, len; int bpos;
int w16, invert;
bpos = samples_to_bytes(runtime, pos) + (voice * (pcmp->dma_size / 2)); bpos = get_bpos(pcmp, voice, pos, len);
len = samples_to_bytes(runtime, count); if (bpos < 0)
if (snd_BUG_ON(bpos > pcmp->dma_size)) return pos;
return -EIO;
if (snd_BUG_ON(bpos + len > pcmp->dma_size))
return -EIO;
snd_pcm_format_set_silence(runtime->format, runtime->dma_area + bpos, snd_pcm_format_set_silence(runtime->format, runtime->dma_area + bpos,
count); bytes_to_samples(runtime, count));
if (len > 32) return playback_copy_ack(substream, bpos, len);
return snd_gf1_pcm_block_change(substream, bpos,
pcmp->memory + bpos, len);
w16 = (snd_pcm_format_width(runtime->format) == 16);
invert = snd_pcm_format_unsigned(runtime->format);
return snd_gf1_pcm_poke_block(gus, runtime->dma_area + bpos,
pcmp->memory + bpos, len, w16, invert);
} }
static int snd_gf1_pcm_playback_hw_params(struct snd_pcm_substream *substream, static int snd_gf1_pcm_playback_hw_params(struct snd_pcm_substream *substream,
...@@ -831,8 +851,9 @@ static struct snd_pcm_ops snd_gf1_pcm_playback_ops = { ...@@ -831,8 +851,9 @@ static struct snd_pcm_ops snd_gf1_pcm_playback_ops = {
.prepare = snd_gf1_pcm_playback_prepare, .prepare = snd_gf1_pcm_playback_prepare,
.trigger = snd_gf1_pcm_playback_trigger, .trigger = snd_gf1_pcm_playback_trigger,
.pointer = snd_gf1_pcm_playback_pointer, .pointer = snd_gf1_pcm_playback_pointer,
.copy = snd_gf1_pcm_playback_copy, .copy_user = snd_gf1_pcm_playback_copy,
.silence = snd_gf1_pcm_playback_silence, .copy_kernel = snd_gf1_pcm_playback_copy_kernel,
.fill_silence = snd_gf1_pcm_playback_silence,
}; };
static struct snd_pcm_ops snd_gf1_pcm_capture_ops = { static struct snd_pcm_ops snd_gf1_pcm_capture_ops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment