/* * fireworks_stream.c - a part of driver for Fireworks based devices * * Copyright (c) 2013-2014 Takashi Sakamoto * * Licensed under the terms of the GNU General Public License, version 2. */ #include "./fireworks.h" #define CALLBACK_TIMEOUT 100 static int init_stream(struct snd_efw *efw, struct amdtp_stream *stream) { struct cmp_connection *conn; enum cmp_direction c_dir; enum amdtp_stream_direction s_dir; int err; if (stream == &efw->tx_stream) { conn = &efw->out_conn; c_dir = CMP_OUTPUT; s_dir = AMDTP_IN_STREAM; } else { conn = &efw->in_conn; c_dir = CMP_INPUT; s_dir = AMDTP_OUT_STREAM; } err = cmp_connection_init(conn, efw->unit, c_dir, 0); if (err < 0) goto end; err = amdtp_am824_init(stream, efw->unit, s_dir, CIP_BLOCKING); if (err < 0) { amdtp_stream_destroy(stream); cmp_connection_destroy(conn); } end: return err; } static void stop_stream(struct snd_efw *efw, struct amdtp_stream *stream) { amdtp_stream_pcm_abort(stream); amdtp_stream_stop(stream); if (stream == &efw->tx_stream) cmp_connection_break(&efw->out_conn); else cmp_connection_break(&efw->in_conn); } static int start_stream(struct snd_efw *efw, struct amdtp_stream *stream, unsigned int sampling_rate) { struct cmp_connection *conn; unsigned int mode, pcm_channels, midi_ports; int err; err = snd_efw_get_multiplier_mode(sampling_rate, &mode); if (err < 0) goto end; if (stream == &efw->tx_stream) { conn = &efw->out_conn; pcm_channels = efw->pcm_capture_channels[mode]; midi_ports = efw->midi_out_ports; } else { conn = &efw->in_conn; pcm_channels = efw->pcm_playback_channels[mode]; midi_ports = efw->midi_in_ports; } err = amdtp_am824_set_parameters(stream, sampling_rate, pcm_channels, midi_ports, false); if (err < 0) goto end; /* establish connection via CMP */ err = cmp_connection_establish(conn, amdtp_stream_get_max_payload(stream)); if (err < 0) goto end; /* start amdtp stream */ err = amdtp_stream_start(stream, conn->resources.channel, conn->speed); if (err < 0) { stop_stream(efw, stream); goto end; } /* wait first callback */ if (!amdtp_stream_wait_callback(stream, CALLBACK_TIMEOUT)) { stop_stream(efw, stream); err = -ETIMEDOUT; } end: return err; } /* * This function should be called before starting the stream or after stopping * the streams. */ static void destroy_stream(struct snd_efw *efw, struct amdtp_stream *stream) { struct cmp_connection *conn; if (stream == &efw->tx_stream) conn = &efw->out_conn; else conn = &efw->in_conn; amdtp_stream_destroy(stream); cmp_connection_destroy(conn); } static int check_connection_used_by_others(struct snd_efw *efw, struct amdtp_stream *s) { struct cmp_connection *conn; bool used; int err; if (s == &efw->tx_stream) conn = &efw->out_conn; else conn = &efw->in_conn; err = cmp_connection_check_used(conn, &used); if ((err >= 0) && used && !amdtp_stream_running(s)) { dev_err(&efw->unit->device, "Connection established by others: %cPCR[%d]\n", (conn->direction == CMP_OUTPUT) ? 'o' : 'i', conn->pcr_index); err = -EBUSY; } return err; } int snd_efw_stream_init_duplex(struct snd_efw *efw) { int err; err = init_stream(efw, &efw->tx_stream); if (err < 0) goto end; /* Fireworks transmits NODATA packets with TAG0. */ efw->tx_stream.flags |= CIP_EMPTY_WITH_TAG0; /* Fireworks has its own meaning for dbc. */ efw->tx_stream.flags |= CIP_DBC_IS_END_EVENT; /* Fireworks reset dbc at bus reset. */ efw->tx_stream.flags |= CIP_SKIP_DBC_ZERO_CHECK; /* * But Recent firmwares starts packets with non-zero dbc. * Driver version 5.7.6 installs firmware version 5.7.3. */ if (efw->is_fireworks3 && (efw->firmware_version == 0x5070000 || efw->firmware_version == 0x5070300 || efw->firmware_version == 0x5080000)) efw->tx_stream.tx_first_dbc = 0x02; /* AudioFire9 always reports wrong dbs. */ if (efw->is_af9) efw->tx_stream.flags |= CIP_WRONG_DBS; /* Firmware version 5.5 reports fixed interval for dbc. */ if (efw->firmware_version == 0x5050000) efw->tx_stream.tx_dbc_interval = 8; err = init_stream(efw, &efw->rx_stream); if (err < 0) { destroy_stream(efw, &efw->tx_stream); goto end; } /* set IEC61883 compliant mode (actually not fully compliant...) */ err = snd_efw_command_set_tx_mode(efw, SND_EFW_TRANSPORT_MODE_IEC61883); if (err < 0) { destroy_stream(efw, &efw->tx_stream); destroy_stream(efw, &efw->rx_stream); } end: return err; } int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate) { unsigned int curr_rate; int err = 0; /* Need no substreams */ if (efw->playback_substreams == 0 && efw->capture_substreams == 0) goto end; /* * Considering JACK/FFADO streaming: * TODO: This can be removed hwdep functionality becomes popular. */ err = check_connection_used_by_others(efw, &efw->rx_stream); if (err < 0) goto end; /* packet queueing error */ if (amdtp_streaming_error(&efw->tx_stream)) stop_stream(efw, &efw->tx_stream); if (amdtp_streaming_error(&efw->rx_stream)) stop_stream(efw, &efw->rx_stream); /* stop streams if rate is different */ err = snd_efw_command_get_sampling_rate(efw, &curr_rate); if (err < 0) goto end; if (rate == 0) rate = curr_rate; if (rate != curr_rate) { stop_stream(efw, &efw->tx_stream); stop_stream(efw, &efw->rx_stream); } /* master should be always running */ if (!amdtp_stream_running(&efw->rx_stream)) { err = snd_efw_command_set_sampling_rate(efw, rate); if (err < 0) goto end; err = start_stream(efw, &efw->rx_stream, rate); if (err < 0) { dev_err(&efw->unit->device, "fail to start AMDTP master stream:%d\n", err); goto end; } } /* start slave if needed */ if (efw->capture_substreams > 0 && !amdtp_stream_running(&efw->tx_stream)) { err = start_stream(efw, &efw->tx_stream, rate); if (err < 0) { dev_err(&efw->unit->device, "fail to start AMDTP slave stream:%d\n", err); stop_stream(efw, &efw->rx_stream); } } end: return err; } void snd_efw_stream_stop_duplex(struct snd_efw *efw) { if (efw->capture_substreams == 0) { stop_stream(efw, &efw->tx_stream); if (efw->playback_substreams == 0) stop_stream(efw, &efw->rx_stream); } } void snd_efw_stream_update_duplex(struct snd_efw *efw) { if (cmp_connection_update(&efw->out_conn) < 0 || cmp_connection_update(&efw->in_conn) < 0) { stop_stream(efw, &efw->rx_stream); stop_stream(efw, &efw->tx_stream); } else { amdtp_stream_update(&efw->rx_stream); amdtp_stream_update(&efw->tx_stream); } } void snd_efw_stream_destroy_duplex(struct snd_efw *efw) { destroy_stream(efw, &efw->rx_stream); destroy_stream(efw, &efw->tx_stream); } void snd_efw_stream_lock_changed(struct snd_efw *efw) { efw->dev_lock_changed = true; wake_up(&efw->hwdep_wait); } int snd_efw_stream_lock_try(struct snd_efw *efw) { int err; spin_lock_irq(&efw->lock); /* user land lock this */ if (efw->dev_lock_count < 0) { err = -EBUSY; goto end; } /* this is the first time */ if (efw->dev_lock_count++ == 0) snd_efw_stream_lock_changed(efw); err = 0; end: spin_unlock_irq(&efw->lock); return err; } void snd_efw_stream_lock_release(struct snd_efw *efw) { spin_lock_irq(&efw->lock); if (WARN_ON(efw->dev_lock_count <= 0)) goto end; if (--efw->dev_lock_count == 0) snd_efw_stream_lock_changed(efw); end: spin_unlock_irq(&efw->lock); } gi/linux/net-next.git/plain/include/sound/ak4117.h?id=b2d60415684663d9dfc616ed97a6f78b3c73c29a'>plain -rw-r--r--ak4531_codec.h3173logplain -rw-r--r--ak4641.h622logplain -rw-r--r--ak4xxx-adda.h3416logplain -rw-r--r--alc5623.h497logplain -rw-r--r--asequencer.h3670logplain -rw-r--r--asound.h1285logplain -rw-r--r--asoundef.h17098logplain -rw-r--r--atmel-abdac.h639logplain -rw-r--r--atmel-ac97c.h1342logplain -rw-r--r--compress_driver.h6772logplain -rw-r--r--control.h8704logplain -rw-r--r--core.h14380logplain -rw-r--r--cs35l33.h1034logplain -rw-r--r--cs35l34.h887logplain -rw-r--r--cs4231-regs.h8480logplain -rw-r--r--cs4271.h1417logplain -rw-r--r--cs42l52.h738logplain -rw-r--r--cs42l56.h1192logplain -rw-r--r--cs42l73.h507logplain -rw-r--r--cs8403.h8833logplain -rw-r--r--cs8427.h10649logplain -rw-r--r--da7213.h1178logplain -rw-r--r--da7218.h2681logplain -rw-r--r--da7219-aad.h2476logplain -rw-r--r--da7219.h1064logplain -rw-r--r--da9055.h914logplain -rw-r--r--designware_i2s.h2249logplain -rw-r--r--dmaengine_pcm.h6157logplain -rw-r--r--emu10k1.h91396logplain -rw-r--r--emu10k1_synth.h1382logplain -rw-r--r--emu8000.h4109logplain -rw-r--r--emu8000_reg.h10459logplain -rw-r--r--emux_legacy.h5503logplain -rw-r--r--emux_synth.h7649logplain -rw-r--r--es1688.h3618logplain -rw-r--r--gus.h20691logplain -rw-r--r--hda_chmap.h2621logplain -rw-r--r--hda_hwdep.h1412logplain -rw-r--r--hda_i915.h1645logplain -rw-r--r--hda_register.h9475logplain -rw-r--r--hda_regmap.h6714logplain -rw-r--r--hda_verbs.h17130logplain -rw-r--r--hdaudio.h18455logplain -rw-r--r--hdaudio_ext.h7119logplain -rw-r--r--hdmi-codec.h2290logplain -rw-r--r--hwdep.h2624logplain -rw-r--r--i2c.h3555logplain -rw-r--r--info.h7584logplain