Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * ff-stream.c - a part of driver for RME Fireface series
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2015-2017 Takashi Sakamoto
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "ff.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #define CALLBACK_TIMEOUT_MS	200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) int snd_ff_stream_get_multiplier_mode(enum cip_sfc sfc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 				      enum snd_ff_stream_mode *mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	static const enum snd_ff_stream_mode modes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 		[CIP_SFC_32000] = SND_FF_STREAM_MODE_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 		[CIP_SFC_44100] = SND_FF_STREAM_MODE_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 		[CIP_SFC_48000] = SND_FF_STREAM_MODE_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 		[CIP_SFC_88200] = SND_FF_STREAM_MODE_MID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 		[CIP_SFC_96000] = SND_FF_STREAM_MODE_MID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		[CIP_SFC_176400] = SND_FF_STREAM_MODE_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 		[CIP_SFC_192000] = SND_FF_STREAM_MODE_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	if (sfc >= CIP_SFC_COUNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	*mode = modes[sfc];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static inline void finish_session(struct snd_ff *ff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	ff->spec->protocol->finish_session(ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	ff->spec->protocol->switch_fetching_mode(ff, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static int init_stream(struct snd_ff *ff, struct amdtp_stream *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct fw_iso_resources *resources;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	enum amdtp_stream_direction dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (s == &ff->tx_stream) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		resources = &ff->tx_resources;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		dir = AMDTP_IN_STREAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		resources = &ff->rx_resources;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		dir = AMDTP_OUT_STREAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	err = fw_iso_resources_init(resources, ff->unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	err = amdtp_ff_init(s, ff->unit, dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		fw_iso_resources_destroy(resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static void destroy_stream(struct snd_ff *ff, struct amdtp_stream *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	amdtp_stream_destroy(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (s == &ff->tx_stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		fw_iso_resources_destroy(&ff->tx_resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		fw_iso_resources_destroy(&ff->rx_resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) int snd_ff_stream_init_duplex(struct snd_ff *ff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	err = init_stream(ff, &ff->rx_stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	err = init_stream(ff, &ff->tx_stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		destroy_stream(ff, &ff->rx_stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	err = amdtp_domain_init(&ff->domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		destroy_stream(ff, &ff->rx_stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		destroy_stream(ff, &ff->tx_stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * This function should be called before starting streams or after stopping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * streams.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) void snd_ff_stream_destroy_duplex(struct snd_ff *ff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	amdtp_domain_destroy(&ff->domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	destroy_stream(ff, &ff->rx_stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	destroy_stream(ff, &ff->tx_stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) int snd_ff_stream_reserve_duplex(struct snd_ff *ff, unsigned int rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 				 unsigned int frames_per_period,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 				 unsigned int frames_per_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	unsigned int curr_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	enum snd_ff_clock_src src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	err = ff->spec->protocol->get_clock(ff, &curr_rate, &src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (ff->substreams_counter == 0 || curr_rate != rate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		enum snd_ff_stream_mode mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		amdtp_domain_stop(&ff->domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		finish_session(ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		fw_iso_resources_free(&ff->tx_resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		fw_iso_resources_free(&ff->rx_resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		for (i = 0; i < CIP_SFC_COUNT; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			if (amdtp_rate_table[i] == rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		if (i >= CIP_SFC_COUNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		err = snd_ff_stream_get_multiplier_mode(i, &mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		err = amdtp_ff_set_parameters(&ff->tx_stream, rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 					ff->spec->pcm_capture_channels[mode]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		err = amdtp_ff_set_parameters(&ff->rx_stream, rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 					ff->spec->pcm_playback_channels[mode]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		err = ff->spec->protocol->allocate_resources(ff, rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		err = amdtp_domain_set_events_per_period(&ff->domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 					frames_per_period, frames_per_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			fw_iso_resources_free(&ff->tx_resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			fw_iso_resources_free(&ff->rx_resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) int snd_ff_stream_start_duplex(struct snd_ff *ff, unsigned int rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (ff->substreams_counter == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (amdtp_streaming_error(&ff->tx_stream) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	    amdtp_streaming_error(&ff->rx_stream)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		amdtp_domain_stop(&ff->domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		finish_session(ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	 * Regardless of current source of clock signal, drivers transfer some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	 * packets. Then, the device transfers packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (!amdtp_stream_running(&ff->rx_stream)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		int spd = fw_parent_device(ff->unit)->max_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		err = ff->spec->protocol->begin_session(ff, rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		err = amdtp_domain_add_stream(&ff->domain, &ff->rx_stream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 					      ff->rx_resources.channel, spd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		err = amdtp_domain_add_stream(&ff->domain, &ff->tx_stream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 					      ff->tx_resources.channel, spd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		err = amdtp_domain_start(&ff->domain, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		if (!amdtp_stream_wait_callback(&ff->rx_stream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 						CALLBACK_TIMEOUT_MS) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		    !amdtp_stream_wait_callback(&ff->tx_stream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 						CALLBACK_TIMEOUT_MS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			err = -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		err = ff->spec->protocol->switch_fetching_mode(ff, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	amdtp_domain_stop(&ff->domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	finish_session(ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) void snd_ff_stream_stop_duplex(struct snd_ff *ff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (ff->substreams_counter == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		amdtp_domain_stop(&ff->domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		finish_session(ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		fw_iso_resources_free(&ff->tx_resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		fw_iso_resources_free(&ff->rx_resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) void snd_ff_stream_update_duplex(struct snd_ff *ff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	amdtp_domain_stop(&ff->domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	// The device discontinue to transfer packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	amdtp_stream_pcm_abort(&ff->tx_stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	amdtp_stream_pcm_abort(&ff->rx_stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) void snd_ff_stream_lock_changed(struct snd_ff *ff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	ff->dev_lock_changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	wake_up(&ff->hwdep_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) int snd_ff_stream_lock_try(struct snd_ff *ff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	spin_lock_irq(&ff->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	/* user land lock this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (ff->dev_lock_count < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	/* this is the first time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (ff->dev_lock_count++ == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		snd_ff_stream_lock_changed(ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	spin_unlock_irq(&ff->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) void snd_ff_stream_lock_release(struct snd_ff *ff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	spin_lock_irq(&ff->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (WARN_ON(ff->dev_lock_count <= 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	if (--ff->dev_lock_count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		snd_ff_stream_lock_changed(ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	spin_unlock_irq(&ff->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }