Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtio: support 24000 rate #4

Open
wants to merge 1 commit into
base: virtio-snd
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/uapi/linux/virtio_snd.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ enum {
VIRTIO_SND_PCM_RATE_11025,
VIRTIO_SND_PCM_RATE_16000,
VIRTIO_SND_PCM_RATE_22050,
VIRTIO_SND_PCM_RATE_24000,
VIRTIO_SND_PCM_RATE_32000,
VIRTIO_SND_PCM_RATE_44100,
VIRTIO_SND_PCM_RATE_48000,
Expand All @@ -184,6 +185,7 @@ enum {
VIRTIO_SND_PCM_RATEBIT_11025 = VIRTIO_SND_PCM_RATEBIT(11025),
VIRTIO_SND_PCM_RATEBIT_16000 = VIRTIO_SND_PCM_RATEBIT(16000),
VIRTIO_SND_PCM_RATEBIT_22050 = VIRTIO_SND_PCM_RATEBIT(22050),
VIRTIO_SND_PCM_RATEBIT_24000 = VIRTIO_SND_PCM_RATEBIT(24000),
VIRTIO_SND_PCM_RATEBIT_32000 = VIRTIO_SND_PCM_RATEBIT(32000),
VIRTIO_SND_PCM_RATEBIT_44100 = VIRTIO_SND_PCM_RATEBIT(44100),
VIRTIO_SND_PCM_RATEBIT_48000 = VIRTIO_SND_PCM_RATEBIT(48000),
Expand Down
46 changes: 31 additions & 15 deletions sound/virtio/virtio_snd.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ struct viosnd_pcm_stream {
struct viosnd_pcm *pcm;

struct snd_pcm_hardware hw;
struct snd_pcm_hw_constraint_list rate_list;
struct snd_pcm_substream *substream;
u8 nchmaps;

Expand Down Expand Up @@ -851,6 +852,9 @@ static int viosnd_pcm_open(struct snd_pcm_substream *substream)

substream->runtime->hw = stream->hw;

snd_pcm_hw_constraint_list(substream->runtime, 0,
SNDRV_PCM_HW_PARAM_RATE, &stream->rate_list);

return 0;
}

Expand Down Expand Up @@ -902,6 +906,7 @@ static int viosnd_pcm_hw_params(struct snd_pcm_substream *substream,
{ 11025, VIRTIO_SND_PCM_RATE_11025 },
{ 16000, VIRTIO_SND_PCM_RATE_16000 },
{ 22050, VIRTIO_SND_PCM_RATE_22050 },
{ 24000, VIRTIO_SND_PCM_RATE_24000 },
{ 32000, VIRTIO_SND_PCM_RATE_32000 },
{ 44100, VIRTIO_SND_PCM_RATE_44100 },
{ 48000, VIRTIO_SND_PCM_RATE_48000 },
Expand Down Expand Up @@ -1352,23 +1357,24 @@ viosnd_pcm_stream_configure(struct viosnd_pcm *pcm,

static const struct {
u32 vio_bit;
u64 alsa_bit;
unsigned int rate;
} ratemap[] = {
{ VIRTIO_SND_PCM_RATEBIT_8000, SNDRV_PCM_RATE_8000, 8000 },
{ VIRTIO_SND_PCM_RATEBIT_11025, SNDRV_PCM_RATE_11025, 11025 },
{ VIRTIO_SND_PCM_RATEBIT_16000, SNDRV_PCM_RATE_16000, 16000 },
{ VIRTIO_SND_PCM_RATEBIT_22050, SNDRV_PCM_RATE_22050, 22050 },
{ VIRTIO_SND_PCM_RATEBIT_32000, SNDRV_PCM_RATE_32000, 32000 },
{ VIRTIO_SND_PCM_RATEBIT_44100, SNDRV_PCM_RATE_44100, 44100 },
{ VIRTIO_SND_PCM_RATEBIT_48000, SNDRV_PCM_RATE_48000, 48000 },
{ VIRTIO_SND_PCM_RATEBIT_64000, SNDRV_PCM_RATE_64000, 64000 },
{ VIRTIO_SND_PCM_RATEBIT_88200, SNDRV_PCM_RATE_88200, 88200 },
{ VIRTIO_SND_PCM_RATEBIT_96000, SNDRV_PCM_RATE_96000, 96000 },
{ VIRTIO_SND_PCM_RATEBIT_176400, SNDRV_PCM_RATE_176400,
176400 },
{ VIRTIO_SND_PCM_RATEBIT_192000, SNDRV_PCM_RATE_192000, 192000 }
{ VIRTIO_SND_PCM_RATEBIT_8000, 8000 },
{ VIRTIO_SND_PCM_RATEBIT_11025, 11025 },
{ VIRTIO_SND_PCM_RATEBIT_16000, 16000 },
{ VIRTIO_SND_PCM_RATEBIT_22050, 22050 },
{ VIRTIO_SND_PCM_RATEBIT_24000, 24000 },
{ VIRTIO_SND_PCM_RATEBIT_32000, 32000 },
{ VIRTIO_SND_PCM_RATEBIT_44100, 44100 },
{ VIRTIO_SND_PCM_RATEBIT_48000, 48000 },
{ VIRTIO_SND_PCM_RATEBIT_64000, 64000 },
{ VIRTIO_SND_PCM_RATEBIT_88200, 88200 },
{ VIRTIO_SND_PCM_RATEBIT_96000, 96000 },
{ VIRTIO_SND_PCM_RATEBIT_176400, 176400 },
{ VIRTIO_SND_PCM_RATEBIT_192000, 192000 }
};
unsigned int* vio_rate_list = NULL;
unsigned int vio_rate_count = 0;

struct device *dev = &pcm->ctx->vdev->dev;
struct viosnd_pcm_stream *stream;
Expand All @@ -1385,6 +1391,10 @@ viosnd_pcm_stream_configure(struct viosnd_pcm *pcm,
if (!stream)
return ERR_PTR(-ENOMEM);

vio_rate_list = devm_kzalloc(dev, (sizeof(unsigned int) * ARRAY_SIZE(ratemap)), GFP_KERNEL);
if (!vio_rate_list)
return ERR_PTR(-ENOMEM);

stream->pcm = pcm;
stream->nchmaps = desc->nchmaps;
spin_lock_init(&stream->thread_lock);
Expand Down Expand Up @@ -1430,7 +1440,10 @@ viosnd_pcm_stream_configure(struct viosnd_pcm *pcm,
if (stream->hw.rate_max < ratemap[i].rate)
stream->hw.rate_max = ratemap[i].rate;

stream->hw.rates |= ratemap[i].alsa_bit;
stream->hw.rates = SNDRV_PCM_RATE_KNOT;

vio_rate_list[vio_rate_count] = ratemap[i].rate;
vio_rate_count++;
}
}

Expand All @@ -1446,6 +1459,9 @@ viosnd_pcm_stream_configure(struct viosnd_pcm *pcm,
(sample_size_max * desc->channels_max * stream->hw.rate_max);
buffer_size_max /= 2;

stream->rate_list.list = vio_rate_list;
stream->rate_list.count = vio_rate_count;

stream->hw.channels_min = desc->channels_min;
stream->hw.channels_max = desc->channels_max;
stream->hw.buffer_bytes_max = buffer_size_max;
Expand Down