diff options
Diffstat (limited to 'sound/firewire/digi00x')
-rw-r--r-- | sound/firewire/digi00x/amdtp-dot.c | 2 | ||||
-rw-r--r-- | sound/firewire/digi00x/digi00x-midi.c | 11 | ||||
-rw-r--r-- | sound/firewire/digi00x/digi00x-pcm.c | 64 | ||||
-rw-r--r-- | sound/firewire/digi00x/digi00x-stream.c | 183 | ||||
-rw-r--r-- | sound/firewire/digi00x/digi00x.h | 3 |
5 files changed, 117 insertions, 146 deletions
diff --git a/sound/firewire/digi00x/amdtp-dot.c b/sound/firewire/digi00x/amdtp-dot.c index 10c8803d7f19..45ff73d16074 100644 --- a/sound/firewire/digi00x/amdtp-dot.c +++ b/sound/firewire/digi00x/amdtp-dot.c @@ -127,7 +127,7 @@ int amdtp_dot_set_parameters(struct amdtp_stream *s, unsigned int rate, if (err < 0) return err; - s->fdf = AMDTP_FDF_AM824 | s->sfc; + s->ctx_data.rx.fdf = AMDTP_FDF_AM824 | s->sfc; p->pcm_channels = pcm_channels; diff --git a/sound/firewire/digi00x/digi00x-midi.c b/sound/firewire/digi00x/digi00x-midi.c index bf50a168087f..2b57ece89101 100644 --- a/sound/firewire/digi00x/digi00x-midi.c +++ b/sound/firewire/digi00x/digi00x-midi.c @@ -17,8 +17,13 @@ static int midi_open(struct snd_rawmidi_substream *substream) return err; mutex_lock(&dg00x->mutex); - dg00x->substreams_counter++; - err = snd_dg00x_stream_start_duplex(dg00x, 0); + err = snd_dg00x_stream_reserve_duplex(dg00x, 0); + if (err >= 0) { + ++dg00x->substreams_counter; + err = snd_dg00x_stream_start_duplex(dg00x); + if (err < 0) + --dg00x->substreams_counter; + } mutex_unlock(&dg00x->mutex); if (err < 0) snd_dg00x_stream_lock_release(dg00x); @@ -31,7 +36,7 @@ static int midi_close(struct snd_rawmidi_substream *substream) struct snd_dg00x *dg00x = substream->rmidi->private_data; mutex_lock(&dg00x->mutex); - dg00x->substreams_counter--; + --dg00x->substreams_counter; snd_dg00x_stream_stop_duplex(dg00x); mutex_unlock(&dg00x->mutex); diff --git a/sound/firewire/digi00x/digi00x-pcm.c b/sound/firewire/digi00x/digi00x-pcm.c index 4f637f227513..18e561b26625 100644 --- a/sound/firewire/digi00x/digi00x-pcm.c +++ b/sound/firewire/digi00x/digi00x-pcm.c @@ -154,8 +154,8 @@ static int pcm_close(struct snd_pcm_substream *substream) return 0; } -static int pcm_capture_hw_params(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *hw_params) +static int pcm_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) { struct snd_dg00x *dg00x = substream->private_data; int err; @@ -166,58 +166,26 @@ static int pcm_capture_hw_params(struct snd_pcm_substream *substream, return err; if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) { - mutex_lock(&dg00x->mutex); - dg00x->substreams_counter++; - mutex_unlock(&dg00x->mutex); - } + unsigned int rate = params_rate(hw_params); - return 0; -} - -static int pcm_playback_hw_params(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *hw_params) -{ - struct snd_dg00x *dg00x = substream->private_data; - int err; - - err = snd_pcm_lib_alloc_vmalloc_buffer(substream, - params_buffer_bytes(hw_params)); - if (err < 0) - return err; - - if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) { mutex_lock(&dg00x->mutex); - dg00x->substreams_counter++; + err = snd_dg00x_stream_reserve_duplex(dg00x, rate); + if (err >= 0) + ++dg00x->substreams_counter; mutex_unlock(&dg00x->mutex); } - return 0; -} - -static int pcm_capture_hw_free(struct snd_pcm_substream *substream) -{ - struct snd_dg00x *dg00x = substream->private_data; - - mutex_lock(&dg00x->mutex); - - if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) - dg00x->substreams_counter--; - - snd_dg00x_stream_stop_duplex(dg00x); - - mutex_unlock(&dg00x->mutex); - - return snd_pcm_lib_free_vmalloc_buffer(substream); + return err; } -static int pcm_playback_hw_free(struct snd_pcm_substream *substream) +static int pcm_hw_free(struct snd_pcm_substream *substream) { struct snd_dg00x *dg00x = substream->private_data; mutex_lock(&dg00x->mutex); if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) - dg00x->substreams_counter--; + --dg00x->substreams_counter; snd_dg00x_stream_stop_duplex(dg00x); @@ -229,12 +197,11 @@ static int pcm_playback_hw_free(struct snd_pcm_substream *substream) static int pcm_capture_prepare(struct snd_pcm_substream *substream) { struct snd_dg00x *dg00x = substream->private_data; - struct snd_pcm_runtime *runtime = substream->runtime; int err; mutex_lock(&dg00x->mutex); - err = snd_dg00x_stream_start_duplex(dg00x, runtime->rate); + err = snd_dg00x_stream_start_duplex(dg00x); if (err >= 0) amdtp_stream_pcm_prepare(&dg00x->tx_stream); @@ -246,12 +213,11 @@ static int pcm_capture_prepare(struct snd_pcm_substream *substream) static int pcm_playback_prepare(struct snd_pcm_substream *substream) { struct snd_dg00x *dg00x = substream->private_data; - struct snd_pcm_runtime *runtime = substream->runtime; int err; mutex_lock(&dg00x->mutex); - err = snd_dg00x_stream_start_duplex(dg00x, runtime->rate); + err = snd_dg00x_stream_start_duplex(dg00x); if (err >= 0) { amdtp_stream_pcm_prepare(&dg00x->rx_stream); amdtp_dot_reset(&dg00x->rx_stream); @@ -332,8 +298,8 @@ int snd_dg00x_create_pcm_devices(struct snd_dg00x *dg00x) .open = pcm_open, .close = pcm_close, .ioctl = snd_pcm_lib_ioctl, - .hw_params = pcm_capture_hw_params, - .hw_free = pcm_capture_hw_free, + .hw_params = pcm_hw_params, + .hw_free = pcm_hw_free, .prepare = pcm_capture_prepare, .trigger = pcm_capture_trigger, .pointer = pcm_capture_pointer, @@ -344,8 +310,8 @@ int snd_dg00x_create_pcm_devices(struct snd_dg00x *dg00x) .open = pcm_open, .close = pcm_close, .ioctl = snd_pcm_lib_ioctl, - .hw_params = pcm_playback_hw_params, - .hw_free = pcm_playback_hw_free, + .hw_params = pcm_hw_params, + .hw_free = pcm_hw_free, .prepare = pcm_playback_prepare, .trigger = pcm_playback_trigger, .pointer = pcm_playback_pointer, diff --git a/sound/firewire/digi00x/digi00x-stream.c b/sound/firewire/digi00x/digi00x-stream.c index ac8052c66b6f..3e77dbd3ee22 100644 --- a/sound/firewire/digi00x/digi00x-stream.c +++ b/sound/firewire/digi00x/digi00x-stream.c @@ -124,11 +124,25 @@ int snd_dg00x_stream_get_external_rate(struct snd_dg00x *dg00x, static void finish_session(struct snd_dg00x *dg00x) { - __be32 data = cpu_to_be32(0x00000003); + __be32 data; + + amdtp_stream_stop(&dg00x->tx_stream); + amdtp_stream_stop(&dg00x->rx_stream); + data = cpu_to_be32(0x00000003); snd_fw_transaction(dg00x->unit, TCODE_WRITE_QUADLET_REQUEST, DG00X_ADDR_BASE + DG00X_OFFSET_STREAMING_SET, &data, sizeof(data), 0); + + // Unregister isochronous channels for both direction. + data = 0; + snd_fw_transaction(dg00x->unit, TCODE_WRITE_QUADLET_REQUEST, + DG00X_ADDR_BASE + DG00X_OFFSET_ISOC_CHANNELS, + &data, sizeof(data), 0); + + // Just after finishing the session, the device may lost transmitting + // functionality for a short time. + msleep(50); } static int begin_session(struct snd_dg00x *dg00x) @@ -137,11 +151,20 @@ static int begin_session(struct snd_dg00x *dg00x) u32 curr; int err; + // Register isochronous channels for both direction. + data = cpu_to_be32((dg00x->tx_resources.channel << 16) | + dg00x->rx_resources.channel); + err = snd_fw_transaction(dg00x->unit, TCODE_WRITE_QUADLET_REQUEST, + DG00X_ADDR_BASE + DG00X_OFFSET_ISOC_CHANNELS, + &data, sizeof(data), 0); + if (err < 0) + return err; + err = snd_fw_transaction(dg00x->unit, TCODE_READ_QUADLET_REQUEST, DG00X_ADDR_BASE + DG00X_OFFSET_STREAMING_STATE, &data, sizeof(data), 0); if (err < 0) - goto error; + return err; curr = be32_to_cpu(data); if (curr == 0) @@ -156,39 +179,23 @@ static int begin_session(struct snd_dg00x *dg00x) DG00X_OFFSET_STREAMING_SET, &data, sizeof(data), 0); if (err < 0) - goto error; + break; msleep(20); curr--; } - return 0; -error: - finish_session(dg00x); return err; } -static void release_resources(struct snd_dg00x *dg00x) +static int keep_resources(struct snd_dg00x *dg00x, struct amdtp_stream *stream, + unsigned int rate) { - __be32 data = 0; - - /* Unregister isochronous channels for both direction. */ - snd_fw_transaction(dg00x->unit, TCODE_WRITE_QUADLET_REQUEST, - DG00X_ADDR_BASE + DG00X_OFFSET_ISOC_CHANNELS, - &data, sizeof(data), 0); - - /* Release isochronous resources. */ - fw_iso_resources_free(&dg00x->tx_resources); - fw_iso_resources_free(&dg00x->rx_resources); -} - -static int keep_resources(struct snd_dg00x *dg00x, unsigned int rate) -{ - unsigned int i; - __be32 data; + struct fw_iso_resources *resources; + int i; int err; - /* Check sampling rate. */ + // Check sampling rate. for (i = 0; i < SND_DG00X_RATE_COUNT; i++) { if (snd_dg00x_stream_rates[i] == rate) break; @@ -196,41 +203,19 @@ static int keep_resources(struct snd_dg00x *dg00x, unsigned int rate) if (i == SND_DG00X_RATE_COUNT) return -EINVAL; - /* Keep resources for out-stream. */ - err = amdtp_dot_set_parameters(&dg00x->rx_stream, rate, - snd_dg00x_stream_pcm_channels[i]); - if (err < 0) - return err; - err = fw_iso_resources_allocate(&dg00x->rx_resources, - amdtp_stream_get_max_payload(&dg00x->rx_stream), - fw_parent_device(dg00x->unit)->max_speed); - if (err < 0) - return err; + if (stream == &dg00x->tx_stream) + resources = &dg00x->tx_resources; + else + resources = &dg00x->rx_resources; - /* Keep resources for in-stream. */ - err = amdtp_dot_set_parameters(&dg00x->tx_stream, rate, + err = amdtp_dot_set_parameters(stream, rate, snd_dg00x_stream_pcm_channels[i]); if (err < 0) return err; - err = fw_iso_resources_allocate(&dg00x->tx_resources, - amdtp_stream_get_max_payload(&dg00x->tx_stream), - fw_parent_device(dg00x->unit)->max_speed); - if (err < 0) - goto error; - /* Register isochronous channels for both direction. */ - data = cpu_to_be32((dg00x->tx_resources.channel << 16) | - dg00x->rx_resources.channel); - err = snd_fw_transaction(dg00x->unit, TCODE_WRITE_QUADLET_REQUEST, - DG00X_ADDR_BASE + DG00X_OFFSET_ISOC_CHANNELS, - &data, sizeof(data), 0); - if (err < 0) - goto error; - - return 0; -error: - release_resources(dg00x); - return err; + return fw_iso_resources_allocate(resources, + amdtp_stream_get_max_payload(stream), + fw_parent_device(dg00x->unit)->max_speed); } int snd_dg00x_stream_init_duplex(struct snd_dg00x *dg00x) @@ -272,43 +257,68 @@ void snd_dg00x_stream_destroy_duplex(struct snd_dg00x *dg00x) fw_iso_resources_destroy(&dg00x->tx_resources); } -int snd_dg00x_stream_start_duplex(struct snd_dg00x *dg00x, unsigned int rate) +int snd_dg00x_stream_reserve_duplex(struct snd_dg00x *dg00x, unsigned int rate) { unsigned int curr_rate; - int err = 0; - - if (dg00x->substreams_counter == 0) - goto end; + int err; - /* Check current sampling rate. */ err = snd_dg00x_stream_get_local_rate(dg00x, &curr_rate); if (err < 0) - goto error; + return err; if (rate == 0) rate = curr_rate; - if (curr_rate != rate || - amdtp_streaming_error(&dg00x->tx_stream) || - amdtp_streaming_error(&dg00x->rx_stream)) { + + if (dg00x->substreams_counter == 0 || curr_rate != rate) { finish_session(dg00x); - amdtp_stream_stop(&dg00x->tx_stream); - amdtp_stream_stop(&dg00x->rx_stream); - release_resources(dg00x); - } + fw_iso_resources_free(&dg00x->tx_resources); + fw_iso_resources_free(&dg00x->rx_resources); - /* - * No packets are transmitted without receiving packets, reagardless of - * which source of clock is used. - */ - if (!amdtp_stream_running(&dg00x->rx_stream)) { err = snd_dg00x_stream_set_local_rate(dg00x, rate); if (err < 0) + return err; + + err = keep_resources(dg00x, &dg00x->rx_stream, rate); + if (err < 0) + return err; + + err = keep_resources(dg00x, &dg00x->tx_stream, rate); + if (err < 0) { + fw_iso_resources_free(&dg00x->rx_resources); + return err; + } + } + + return 0; +} + +int snd_dg00x_stream_start_duplex(struct snd_dg00x *dg00x) +{ + unsigned int generation = dg00x->rx_resources.generation; + int err = 0; + + if (dg00x->substreams_counter == 0) + return 0; + + if (amdtp_streaming_error(&dg00x->tx_stream) || + amdtp_streaming_error(&dg00x->rx_stream)) + finish_session(dg00x); + + if (generation != fw_parent_device(dg00x->unit)->card->generation) { + err = fw_iso_resources_update(&dg00x->tx_resources); + if (err < 0) goto error; - err = keep_resources(dg00x, rate); + err = fw_iso_resources_update(&dg00x->rx_resources); if (err < 0) goto error; + } + /* + * No packets are transmitted without receiving packets, reagardless of + * which source of clock is used. + */ + if (!amdtp_stream_running(&dg00x->rx_stream)) { err = begin_session(dg00x); if (err < 0) goto error; @@ -343,33 +353,22 @@ int snd_dg00x_stream_start_duplex(struct snd_dg00x *dg00x, unsigned int rate) goto error; } } -end: - return err; + + return 0; error: finish_session(dg00x); - amdtp_stream_stop(&dg00x->tx_stream); - amdtp_stream_stop(&dg00x->rx_stream); - release_resources(dg00x); - return err; } void snd_dg00x_stream_stop_duplex(struct snd_dg00x *dg00x) { - if (dg00x->substreams_counter > 0) - return; - - amdtp_stream_stop(&dg00x->tx_stream); - amdtp_stream_stop(&dg00x->rx_stream); - finish_session(dg00x); - release_resources(dg00x); + if (dg00x->substreams_counter == 0) { + finish_session(dg00x); - /* - * Just after finishing the session, the device may lost transmitting - * functionality for a short time. - */ - msleep(50); + fw_iso_resources_free(&dg00x->tx_resources); + fw_iso_resources_free(&dg00x->rx_resources); + } } void snd_dg00x_stream_update_duplex(struct snd_dg00x *dg00x) diff --git a/sound/firewire/digi00x/digi00x.h b/sound/firewire/digi00x/digi00x.h index 464e6d3d82a8..0994d191ccda 100644 --- a/sound/firewire/digi00x/digi00x.h +++ b/sound/firewire/digi00x/digi00x.h @@ -139,7 +139,8 @@ int snd_dg00x_stream_get_clock(struct snd_dg00x *dg00x, int snd_dg00x_stream_check_external_clock(struct snd_dg00x *dg00x, bool *detect); int snd_dg00x_stream_init_duplex(struct snd_dg00x *dg00x); -int snd_dg00x_stream_start_duplex(struct snd_dg00x *dg00x, unsigned int rate); +int snd_dg00x_stream_reserve_duplex(struct snd_dg00x *dg00x, unsigned int rate); +int snd_dg00x_stream_start_duplex(struct snd_dg00x *dg00x); void snd_dg00x_stream_stop_duplex(struct snd_dg00x *dg00x); void snd_dg00x_stream_update_duplex(struct snd_dg00x *dg00x); void snd_dg00x_stream_destroy_duplex(struct snd_dg00x *dg00x); |