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 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define SOUND_FIREWIRE_AMDTP_H_INCLUDED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <sound/asound.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "packets-buffer.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * enum cip_flags - describes details of the streaming protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * @CIP_NONBLOCKING: In non-blocking mode, each packet contains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *	sample_rate/8000 samples, with rounding up or down to adjust
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *	for clock skew and left-over fractional samples.  This should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *	be used if supported by the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * @CIP_BLOCKING: In blocking mode, each packet contains either zero or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *	SYT_INTERVAL samples, with these two types alternating so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *	the overall sample rate comes out right.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * @CIP_EMPTY_WITH_TAG0: Only for in-stream. Empty in-packets have TAG0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * @CIP_DBC_IS_END_EVENT: The value of dbc in an packet corresponds to the end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * of event in the packet. Out of IEC 61883.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * @CIP_WRONG_DBS: Only for in-stream. The value of dbs is wrong in in-packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *	The value of data_block_quadlets is used instead of reported value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * @CIP_SKIP_DBC_ZERO_CHECK: Only for in-stream.  Packets with zero in dbc is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *	skipped for detecting discontinuity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * @CIP_EMPTY_HAS_WRONG_DBC: Only for in-stream. The value of dbc in empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *	packet is wrong but the others are correct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * @CIP_JUMBO_PAYLOAD: Only for in-stream. The number of data blocks in an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *	packet is larger than IEC 61883-6 defines. Current implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *	allows 5 times as large as IEC 61883-6 defines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * @CIP_HEADER_WITHOUT_EOH: Only for in-stream. CIP Header doesn't include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *	valid EOH.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * @CIP_NO_HEADERS: a lack of headers in packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * @CIP_UNALIGHED_DBC: Only for in-stream. The value of dbc is not alighed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *	the value of current SYT_INTERVAL; e.g. initial value is not zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) enum cip_flags {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	CIP_NONBLOCKING		= 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	CIP_BLOCKING		= 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	CIP_EMPTY_WITH_TAG0	= 0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	CIP_DBC_IS_END_EVENT	= 0x04,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	CIP_WRONG_DBS		= 0x08,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	CIP_SKIP_DBC_ZERO_CHECK	= 0x10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	CIP_EMPTY_HAS_WRONG_DBC	= 0x20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	CIP_JUMBO_PAYLOAD	= 0x40,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	CIP_HEADER_WITHOUT_EOH	= 0x80,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	CIP_NO_HEADER		= 0x100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	CIP_UNALIGHED_DBC	= 0x200,
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * enum cip_sfc - supported Sampling Frequency Codes (SFCs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * @CIP_SFC_32000:   32,000 data blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * @CIP_SFC_44100:   44,100 data blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * @CIP_SFC_48000:   48,000 data blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * @CIP_SFC_88200:   88,200 data blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * @CIP_SFC_96000:   96,000 data blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * @CIP_SFC_176400: 176,400 data blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * @CIP_SFC_192000: 192,000 data blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * @CIP_SFC_COUNT: the number of supported SFCs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * These values are used to show nominal Sampling Frequency Code in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * Format Dependent Field (FDF) of AMDTP packet header. In IEC 61883-6:2002,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * this code means the number of events per second. Actually the code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * represents the number of data blocks transferred per second in an AMDTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * stream.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * In IEC 61883-6:2005, some extensions were added to support more types of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * data such as 'One Bit LInear Audio', therefore the meaning of SFC became
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * different depending on the types.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * Currently our implementation is compatible with IEC 61883-6:2002.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) enum cip_sfc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	CIP_SFC_32000  = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	CIP_SFC_44100  = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	CIP_SFC_48000  = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	CIP_SFC_88200  = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	CIP_SFC_96000  = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	CIP_SFC_176400 = 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	CIP_SFC_192000 = 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	CIP_SFC_COUNT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) struct fw_unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) struct fw_iso_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) struct snd_pcm_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) struct snd_pcm_runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) enum amdtp_stream_direction {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	AMDTP_OUT_STREAM = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	AMDTP_IN_STREAM
^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) struct pkt_desc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	u32 cycle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	u32 syt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	unsigned int data_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	unsigned int data_block_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	__be32 *ctx_payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct amdtp_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) typedef unsigned int (*amdtp_stream_process_ctx_payloads_t)(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 						struct amdtp_stream *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 						const struct pkt_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 						unsigned int packets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 						struct snd_pcm_substream *pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct amdtp_domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct amdtp_stream {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct fw_unit *unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	enum cip_flags flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	enum amdtp_stream_direction direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	/* For packet processing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	struct fw_iso_context *context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct iso_packets_buffer buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	unsigned int queue_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	int packet_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct pkt_desc *pkt_descs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	int tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			unsigned int ctx_header_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			// limit for payload of iso packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			unsigned int max_ctx_payload_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			// For quirks of CIP headers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			// Fixed interval of dbc between previos/current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			// packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			unsigned int dbc_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		} tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			// To calculate CIP data blocks and tstamp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			unsigned int transfer_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			unsigned int seq_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			// To generate CIP header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			unsigned int fdf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			int syt_override;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			// To generate constant hardware IRQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			unsigned int event_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			unsigned int events_per_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		} rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	} ctx_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	/* For CIP headers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	unsigned int source_node_id_field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	unsigned int data_block_quadlets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	unsigned int data_block_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	unsigned int sph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	unsigned int fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	/* Internal flags. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	enum cip_sfc sfc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	unsigned int syt_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	/* For a PCM substream processing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	struct snd_pcm_substream *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct work_struct period_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	snd_pcm_uframes_t pcm_buffer_pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	unsigned int pcm_period_pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	/* To wait for first packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	bool callbacked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	wait_queue_head_t callback_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	u32 start_cycle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	/* For backends to process data blocks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	void *protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	amdtp_stream_process_ctx_payloads_t process_ctx_payloads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	// For domain.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	int channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	int speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	struct amdtp_domain *domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		      enum amdtp_stream_direction dir, enum cip_flags flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		      unsigned int fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		      amdtp_stream_process_ctx_payloads_t process_ctx_payloads,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		      unsigned int protocol_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) void amdtp_stream_destroy(struct amdtp_stream *s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) int amdtp_stream_set_parameters(struct amdtp_stream *s, unsigned int rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 				unsigned int data_block_quadlets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) void amdtp_stream_update(struct amdtp_stream *s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) int amdtp_stream_add_pcm_hw_constraints(struct amdtp_stream *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 					struct snd_pcm_runtime *runtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) void amdtp_stream_pcm_prepare(struct amdtp_stream *s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) void amdtp_stream_pcm_abort(struct amdtp_stream *s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) extern const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) extern const unsigned int amdtp_rate_table[CIP_SFC_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  * amdtp_stream_running - check stream is running or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  * @s: the AMDTP stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * If this function returns true, the stream is running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static inline bool amdtp_stream_running(struct amdtp_stream *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	return !IS_ERR(s->context);
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  * amdtp_streaming_error - check for streaming error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  * @s: the AMDTP stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  * If this function returns true, the stream's packet queue has stopped due to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * an asynchronous error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static inline bool amdtp_streaming_error(struct amdtp_stream *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	return s->packet_index < 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  * amdtp_stream_pcm_running - check PCM substream is running or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * @s: the AMDTP stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  * If this function returns true, PCM substream in the AMDTP stream is running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	return !!s->pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)  * amdtp_stream_pcm_trigger - start/stop playback from a PCM device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  * @s: the AMDTP stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  * @pcm: the PCM device to be started, or %NULL to stop the current device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * Call this function on a running isochronous stream to enable the actual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  * transmission of PCM data.  This function should be called from the PCM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  * device's .trigger callback.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 					    struct snd_pcm_substream *pcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	WRITE_ONCE(s->pcm, pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	return sfc & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  * amdtp_stream_wait_callback - sleep till callbacked or timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * @s: the AMDTP stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  * @timeout: msec till timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * If this function return false, the AMDTP stream should be stopped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static inline bool amdtp_stream_wait_callback(struct amdtp_stream *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 					      unsigned int timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	return wait_event_timeout(s->callback_wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 				  s->callbacked == true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 				  msecs_to_jiffies(timeout)) > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct seq_desc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	unsigned int syt_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	unsigned int data_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct amdtp_domain {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	struct list_head streams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	unsigned int events_per_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	unsigned int events_per_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	struct amdtp_stream *irq_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	struct seq_desc *seq_descs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	unsigned int seq_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	unsigned int seq_tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	unsigned int data_block_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	unsigned int syt_offset_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	unsigned int last_syt_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) int amdtp_domain_init(struct amdtp_domain *d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) void amdtp_domain_destroy(struct amdtp_domain *d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) int amdtp_domain_add_stream(struct amdtp_domain *d, struct amdtp_stream *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			    int channel, int speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) int amdtp_domain_start(struct amdtp_domain *d, unsigned int ir_delay_cycle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) void amdtp_domain_stop(struct amdtp_domain *d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static inline int amdtp_domain_set_events_per_period(struct amdtp_domain *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 						unsigned int events_per_period,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 						unsigned int events_per_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	d->events_per_period = events_per_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	d->events_per_buffer = events_per_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) unsigned long amdtp_domain_stream_pcm_pointer(struct amdtp_domain *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 					      struct amdtp_stream *s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) int amdtp_domain_stream_pcm_ack(struct amdtp_domain *d, struct amdtp_stream *s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) #endif