Commit 7a75c0d1 authored by Mark Brown's avatar Mark Brown

Merge branch 'topic/compress' of...

Merge branch 'topic/compress' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound into asoc-adsp
parents 546ad3d0 a4f2d87c
...@@ -68,6 +68,7 @@ struct snd_compr_runtime { ...@@ -68,6 +68,7 @@ struct snd_compr_runtime {
* @ops: pointer to DSP callbacks * @ops: pointer to DSP callbacks
* @runtime: pointer to runtime structure * @runtime: pointer to runtime structure
* @device: device pointer * @device: device pointer
* @error_work: delayed work used when closing the stream due to an error
* @direction: stream direction, playback/recording * @direction: stream direction, playback/recording
* @metadata_set: metadata set flag, true when set * @metadata_set: metadata set flag, true when set
* @next_track: has userspace signal next track transition, true when set * @next_track: has userspace signal next track transition, true when set
...@@ -78,6 +79,7 @@ struct snd_compr_stream { ...@@ -78,6 +79,7 @@ struct snd_compr_stream {
struct snd_compr_ops *ops; struct snd_compr_ops *ops;
struct snd_compr_runtime *runtime; struct snd_compr_runtime *runtime;
struct snd_compr *device; struct snd_compr *device;
struct delayed_work error_work;
enum snd_compr_direction direction; enum snd_compr_direction direction;
bool metadata_set; bool metadata_set;
bool next_track; bool next_track;
...@@ -187,4 +189,7 @@ static inline void snd_compr_drain_notify(struct snd_compr_stream *stream) ...@@ -187,4 +189,7 @@ static inline void snd_compr_drain_notify(struct snd_compr_stream *stream)
wake_up(&stream->runtime->sleep); wake_up(&stream->runtime->sleep);
} }
int snd_compr_stop_error(struct snd_compr_stream *stream,
snd_pcm_state_t state);
#endif #endif
...@@ -67,6 +67,8 @@ struct snd_compr_file { ...@@ -67,6 +67,8 @@ struct snd_compr_file {
struct snd_compr_stream stream; struct snd_compr_stream stream;
}; };
static void error_delayed_work(struct work_struct *work);
/* /*
* a note on stream states used: * a note on stream states used:
* we use following states in the compressed core * we use following states in the compressed core
...@@ -123,6 +125,9 @@ static int snd_compr_open(struct inode *inode, struct file *f) ...@@ -123,6 +125,9 @@ static int snd_compr_open(struct inode *inode, struct file *f)
snd_card_unref(compr->card); snd_card_unref(compr->card);
return -ENOMEM; return -ENOMEM;
} }
INIT_DELAYED_WORK(&data->stream.error_work, error_delayed_work);
data->stream.ops = compr->ops; data->stream.ops = compr->ops;
data->stream.direction = dirn; data->stream.direction = dirn;
data->stream.private_data = compr->private_data; data->stream.private_data = compr->private_data;
...@@ -153,6 +158,8 @@ static int snd_compr_free(struct inode *inode, struct file *f) ...@@ -153,6 +158,8 @@ static int snd_compr_free(struct inode *inode, struct file *f)
struct snd_compr_file *data = f->private_data; struct snd_compr_file *data = f->private_data;
struct snd_compr_runtime *runtime = data->stream.runtime; struct snd_compr_runtime *runtime = data->stream.runtime;
cancel_delayed_work_sync(&data->stream.error_work);
switch (runtime->state) { switch (runtime->state) {
case SNDRV_PCM_STATE_RUNNING: case SNDRV_PCM_STATE_RUNNING:
case SNDRV_PCM_STATE_DRAINING: case SNDRV_PCM_STATE_DRAINING:
...@@ -237,6 +244,15 @@ snd_compr_ioctl_avail(struct snd_compr_stream *stream, unsigned long arg) ...@@ -237,6 +244,15 @@ snd_compr_ioctl_avail(struct snd_compr_stream *stream, unsigned long arg)
avail = snd_compr_calc_avail(stream, &ioctl_avail); avail = snd_compr_calc_avail(stream, &ioctl_avail);
ioctl_avail.avail = avail; ioctl_avail.avail = avail;
switch (stream->runtime->state) {
case SNDRV_PCM_STATE_OPEN:
return -EBADFD;
case SNDRV_PCM_STATE_XRUN:
return -EPIPE;
default:
break;
}
if (copy_to_user((__u64 __user *)arg, if (copy_to_user((__u64 __user *)arg,
&ioctl_avail, sizeof(ioctl_avail))) &ioctl_avail, sizeof(ioctl_avail)))
return -EFAULT; return -EFAULT;
...@@ -346,11 +362,13 @@ static ssize_t snd_compr_read(struct file *f, char __user *buf, ...@@ -346,11 +362,13 @@ static ssize_t snd_compr_read(struct file *f, char __user *buf,
switch (stream->runtime->state) { switch (stream->runtime->state) {
case SNDRV_PCM_STATE_OPEN: case SNDRV_PCM_STATE_OPEN:
case SNDRV_PCM_STATE_PREPARED: case SNDRV_PCM_STATE_PREPARED:
case SNDRV_PCM_STATE_XRUN:
case SNDRV_PCM_STATE_SUSPENDED: case SNDRV_PCM_STATE_SUSPENDED:
case SNDRV_PCM_STATE_DISCONNECTED: case SNDRV_PCM_STATE_DISCONNECTED:
retval = -EBADFD; retval = -EBADFD;
goto out; goto out;
case SNDRV_PCM_STATE_XRUN:
retval = -EPIPE;
goto out;
} }
avail = snd_compr_get_avail(stream); avail = snd_compr_get_avail(stream);
...@@ -399,10 +417,16 @@ static unsigned int snd_compr_poll(struct file *f, poll_table *wait) ...@@ -399,10 +417,16 @@ static unsigned int snd_compr_poll(struct file *f, poll_table *wait)
stream = &data->stream; stream = &data->stream;
mutex_lock(&stream->device->lock); mutex_lock(&stream->device->lock);
if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
switch (stream->runtime->state) {
case SNDRV_PCM_STATE_OPEN:
case SNDRV_PCM_STATE_XRUN:
retval = snd_compr_get_poll(stream) | POLLERR; retval = snd_compr_get_poll(stream) | POLLERR;
goto out; goto out;
default:
break;
} }
poll_wait(f, &stream->runtime->sleep, wait); poll_wait(f, &stream->runtime->sleep, wait);
avail = snd_compr_get_avail(stream); avail = snd_compr_get_avail(stream);
...@@ -697,6 +721,45 @@ static int snd_compr_stop(struct snd_compr_stream *stream) ...@@ -697,6 +721,45 @@ static int snd_compr_stop(struct snd_compr_stream *stream)
return retval; return retval;
} }
static void error_delayed_work(struct work_struct *work)
{
struct snd_compr_stream *stream;
stream = container_of(work, struct snd_compr_stream, error_work.work);
mutex_lock(&stream->device->lock);
stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP);
wake_up(&stream->runtime->sleep);
mutex_unlock(&stream->device->lock);
}
/*
* snd_compr_stop_error: Report a fatal error on a stream
* @stream: pointer to stream
* @state: state to transition the stream to
*
* Stop the stream and set its state.
*
* Should be called with compressed device lock held.
*/
int snd_compr_stop_error(struct snd_compr_stream *stream,
snd_pcm_state_t state)
{
if (stream->runtime->state == state)
return 0;
stream->runtime->state = state;
pr_debug("Changing state to: %d\n", state);
queue_delayed_work(system_power_efficient_wq, &stream->error_work, 0);
return 0;
}
EXPORT_SYMBOL_GPL(snd_compr_stop_error);
static int snd_compress_wait_for_drain(struct snd_compr_stream *stream) static int snd_compress_wait_for_drain(struct snd_compr_stream *stream)
{ {
int ret; int ret;
......
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