aboutsummaryrefslogtreecommitdiffstats
path: root/sound/firewire
diff options
context:
space:
mode:
authorClemens Ladisch <clemens@ladisch.de>2011-09-04 16:15:44 -0400
committerClemens Ladisch <clemens@ladisch.de>2013-10-20 16:07:57 -0400
commit20b65dd040ce38e2bc0fa3cae13b954c865b61fe (patch)
tree27b8ae49b43b2b6b4e6635128936ebfcfd20d75c /sound/firewire
parent9dd81e3143b57d1bf7e8377ab29b86090baa55a8 (diff)
ALSA: firewire: introduce amdtp_out_stream_running()
Introduce the helper function amdtp_out_stream_running(). This makes many checks in amdtp.c clearer and frees the device drivers from having to track this with a separate variable. Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Diffstat (limited to 'sound/firewire')
-rw-r--r--sound/firewire/amdtp.c10
-rw-r--r--sound/firewire/amdtp.h6
-rw-r--r--sound/firewire/dice.c17
-rw-r--r--sound/firewire/speakers.c8
4 files changed, 18 insertions, 23 deletions
diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
index efb2e2947ce7..d56b8e736b7d 100644
--- a/sound/firewire/amdtp.c
+++ b/sound/firewire/amdtp.c
@@ -59,7 +59,7 @@ EXPORT_SYMBOL(amdtp_out_stream_init);
59 */ 59 */
60void amdtp_out_stream_destroy(struct amdtp_out_stream *s) 60void amdtp_out_stream_destroy(struct amdtp_out_stream *s)
61{ 61{
62 WARN_ON(!IS_ERR(s->context)); 62 WARN_ON(amdtp_out_stream_running(s));
63 mutex_destroy(&s->mutex); 63 mutex_destroy(&s->mutex);
64 fw_unit_put(s->unit); 64 fw_unit_put(s->unit);
65} 65}
@@ -89,7 +89,7 @@ void amdtp_out_stream_set_rate(struct amdtp_out_stream *s, unsigned int rate)
89 }; 89 };
90 unsigned int sfc; 90 unsigned int sfc;
91 91
92 if (WARN_ON(!IS_ERR(s->context))) 92 if (WARN_ON(amdtp_out_stream_running(s)))
93 return; 93 return;
94 94
95 for (sfc = 0; sfc < ARRAY_SIZE(rate_info); ++sfc) 95 for (sfc = 0; sfc < ARRAY_SIZE(rate_info); ++sfc)
@@ -145,7 +145,7 @@ static void amdtp_write_s32(struct amdtp_out_stream *s,
145void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s, 145void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
146 snd_pcm_format_t format) 146 snd_pcm_format_t format)
147{ 147{
148 if (WARN_ON(!IS_ERR(s->context))) 148 if (WARN_ON(amdtp_out_stream_running(s)))
149 return; 149 return;
150 150
151 switch (format) { 151 switch (format) {
@@ -481,7 +481,7 @@ int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed)
481 481
482 mutex_lock(&s->mutex); 482 mutex_lock(&s->mutex);
483 483
484 if (WARN_ON(!IS_ERR(s->context) || 484 if (WARN_ON(amdtp_out_stream_running(s) ||
485 (!s->pcm_channels && !s->midi_ports))) { 485 (!s->pcm_channels && !s->midi_ports))) {
486 err = -EBADFD; 486 err = -EBADFD;
487 goto err_unlock; 487 goto err_unlock;
@@ -577,7 +577,7 @@ void amdtp_out_stream_stop(struct amdtp_out_stream *s)
577{ 577{
578 mutex_lock(&s->mutex); 578 mutex_lock(&s->mutex);
579 579
580 if (IS_ERR(s->context)) { 580 if (!amdtp_out_stream_running(s)) {
581 mutex_unlock(&s->mutex); 581 mutex_unlock(&s->mutex);
582 return; 582 return;
583 } 583 }
diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
index fd4ce3030279..28b1bf5891e6 100644
--- a/sound/firewire/amdtp.h
+++ b/sound/firewire/amdtp.h
@@ -1,6 +1,7 @@
1#ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED 1#ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED
2#define SOUND_FIREWIRE_AMDTP_H_INCLUDED 2#define SOUND_FIREWIRE_AMDTP_H_INCLUDED
3 3
4#include <linux/err.h>
4#include <linux/interrupt.h> 5#include <linux/interrupt.h>
5#include <linux/mutex.h> 6#include <linux/mutex.h>
6#include "packets-buffer.h" 7#include "packets-buffer.h"
@@ -92,6 +93,11 @@ void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s);
92unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s); 93unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s);
93void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s); 94void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s);
94 95
96static inline bool amdtp_out_stream_running(struct amdtp_out_stream *s)
97{
98 return !IS_ERR(s->context);
99}
100
95/** 101/**
96 * amdtp_out_stream_set_pcm - configure format of PCM samples 102 * amdtp_out_stream_set_pcm - configure format of PCM samples
97 * @s: the AMDTP output stream to be configured 103 * @s: the AMDTP output stream to be configured
diff --git a/sound/firewire/dice.c b/sound/firewire/dice.c
index ef04089bde7f..3591aebd1bb7 100644
--- a/sound/firewire/dice.c
+++ b/sound/firewire/dice.c
@@ -246,7 +246,6 @@ struct dice {
246 int dev_lock_count; /* > 0 driver, < 0 userspace */ 246 int dev_lock_count; /* > 0 driver, < 0 userspace */
247 bool dev_lock_changed; 247 bool dev_lock_changed;
248 bool global_enabled; 248 bool global_enabled;
249 bool stream_running;
250 wait_queue_head_t hwdep_wait; 249 wait_queue_head_t hwdep_wait;
251 u32 notification_bits; 250 u32 notification_bits;
252 struct snd_pcm_substream *pcm; 251 struct snd_pcm_substream *pcm;
@@ -654,7 +653,7 @@ static int dice_stream_start_packets(struct dice *dice)
654{ 653{
655 int err; 654 int err;
656 655
657 if (dice->stream_running) 656 if (amdtp_out_stream_running(&dice->stream))
658 return 0; 657 return 0;
659 658
660 err = amdtp_out_stream_start(&dice->stream, dice->resources.channel, 659 err = amdtp_out_stream_start(&dice->stream, dice->resources.channel,
@@ -668,8 +667,6 @@ static int dice_stream_start_packets(struct dice *dice)
668 return err; 667 return err;
669 } 668 }
670 669
671 dice->stream_running = true;
672
673 return 0; 670 return 0;
674} 671}
675 672
@@ -712,14 +709,10 @@ error:
712 709
713static void dice_stream_stop_packets(struct dice *dice) 710static void dice_stream_stop_packets(struct dice *dice)
714{ 711{
715 if (!dice->stream_running) 712 if (amdtp_out_stream_running(&dice->stream)) {
716 return; 713 dice_enable_clear(dice);
717 714 amdtp_out_stream_stop(&dice->stream);
718 dice_enable_clear(dice); 715 }
719
720 amdtp_out_stream_stop(&dice->stream);
721
722 dice->stream_running = false;
723} 716}
724 717
725static void dice_stream_stop(struct dice *dice) 718static void dice_stream_stop(struct dice *dice)
diff --git a/sound/firewire/speakers.c b/sound/firewire/speakers.c
index 2c6386503940..0ac56304baff 100644
--- a/sound/firewire/speakers.c
+++ b/sound/firewire/speakers.c
@@ -53,7 +53,6 @@ struct fwspk {
53 struct mutex mutex; 53 struct mutex mutex;
54 struct cmp_connection connection; 54 struct cmp_connection connection;
55 struct amdtp_out_stream stream; 55 struct amdtp_out_stream stream;
56 bool stream_running;
57 bool mute; 56 bool mute;
58 s16 volume[6]; 57 s16 volume[6];
59 s16 volume_min; 58 s16 volume_min;
@@ -189,10 +188,9 @@ static int fwspk_close(struct snd_pcm_substream *substream)
189 188
190static void fwspk_stop_stream(struct fwspk *fwspk) 189static void fwspk_stop_stream(struct fwspk *fwspk)
191{ 190{
192 if (fwspk->stream_running) { 191 if (amdtp_out_stream_running(&fwspk->stream)) {
193 amdtp_out_stream_stop(&fwspk->stream); 192 amdtp_out_stream_stop(&fwspk->stream);
194 cmp_connection_break(&fwspk->connection); 193 cmp_connection_break(&fwspk->connection);
195 fwspk->stream_running = false;
196 } 194 }
197} 195}
198 196
@@ -286,7 +284,7 @@ static int fwspk_prepare(struct snd_pcm_substream *substream)
286 if (amdtp_out_streaming_error(&fwspk->stream)) 284 if (amdtp_out_streaming_error(&fwspk->stream))
287 fwspk_stop_stream(fwspk); 285 fwspk_stop_stream(fwspk);
288 286
289 if (!fwspk->stream_running) { 287 if (!amdtp_out_stream_running(&fwspk->stream)) {
290 err = cmp_connection_establish(&fwspk->connection, 288 err = cmp_connection_establish(&fwspk->connection,
291 amdtp_out_stream_get_max_payload(&fwspk->stream)); 289 amdtp_out_stream_get_max_payload(&fwspk->stream));
292 if (err < 0) 290 if (err < 0)
@@ -297,8 +295,6 @@ static int fwspk_prepare(struct snd_pcm_substream *substream)
297 fwspk->connection.speed); 295 fwspk->connection.speed);
298 if (err < 0) 296 if (err < 0)
299 goto err_connection; 297 goto err_connection;
300
301 fwspk->stream_running = true;
302 } 298 }
303 299
304 mutex_unlock(&fwspk->mutex); 300 mutex_unlock(&fwspk->mutex);