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.h - 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) #ifndef SOUND_FIREFACE_H_INCLUDED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #define SOUND_FIREFACE_H_INCLUDED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/firewire.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/firewire-constants.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/mod_devicetable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <sound/info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <sound/rawmidi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <sound/pcm_params.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <sound/hwdep.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <sound/firewire.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include "../lib.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "../amdtp-stream.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include "../iso-resources.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define SND_FF_MAXIMIM_MIDI_QUADS	9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define SND_FF_IN_MIDI_PORTS		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define SND_FF_OUT_MIDI_PORTS		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) enum snd_ff_unit_version {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	SND_FF_UNIT_VERSION_FF800	= 0x000001,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	SND_FF_UNIT_VERSION_FF400	= 0x000002,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	SND_FF_UNIT_VERSION_UFX		= 0x000003,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	SND_FF_UNIT_VERSION_UCX		= 0x000004,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	SND_FF_UNIT_VERSION_802		= 0x000005,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) enum snd_ff_stream_mode {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	SND_FF_STREAM_MODE_LOW = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	SND_FF_STREAM_MODE_MID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	SND_FF_STREAM_MODE_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	SND_FF_STREAM_MODE_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) struct snd_ff_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) struct snd_ff_spec {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	const unsigned int pcm_capture_channels[SND_FF_STREAM_MODE_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	const unsigned int pcm_playback_channels[SND_FF_STREAM_MODE_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	unsigned int midi_in_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	unsigned int midi_out_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	const struct snd_ff_protocol *protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	u64 midi_high_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	u8 midi_addr_range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	u64 midi_rx_addrs[SND_FF_OUT_MIDI_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) struct snd_ff {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct fw_unit *unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	bool registered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct delayed_work dwork;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	enum snd_ff_unit_version unit_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	const struct snd_ff_spec *spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	/* To handle MIDI tx. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct snd_rawmidi_substream *tx_midi_substreams[SND_FF_IN_MIDI_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct fw_address_handler async_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	/* TO handle MIDI rx. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct snd_rawmidi_substream *rx_midi_substreams[SND_FF_OUT_MIDI_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	bool on_sysex[SND_FF_OUT_MIDI_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	__le32 msg_buf[SND_FF_OUT_MIDI_PORTS][SND_FF_MAXIMIM_MIDI_QUADS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct work_struct rx_midi_work[SND_FF_OUT_MIDI_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct fw_transaction transactions[SND_FF_OUT_MIDI_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	ktime_t next_ktime[SND_FF_OUT_MIDI_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	bool rx_midi_error[SND_FF_OUT_MIDI_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	unsigned int rx_bytes[SND_FF_OUT_MIDI_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	unsigned int substreams_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct amdtp_stream tx_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct amdtp_stream rx_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct fw_iso_resources tx_resources;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct fw_iso_resources rx_resources;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	int dev_lock_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	bool dev_lock_changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	wait_queue_head_t hwdep_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct amdtp_domain domain;
^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) enum snd_ff_clock_src {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	SND_FF_CLOCK_SRC_INTERNAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	SND_FF_CLOCK_SRC_SPDIF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	SND_FF_CLOCK_SRC_ADAT1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	SND_FF_CLOCK_SRC_ADAT2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	SND_FF_CLOCK_SRC_WORD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	SND_FF_CLOCK_SRC_LTC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	/* TODO: perhaps TCO exists. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct snd_ff_protocol {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	void (*handle_midi_msg)(struct snd_ff *ff, unsigned int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 				__le32 *buf, size_t length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	int (*fill_midi_msg)(struct snd_ff *ff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			     struct snd_rawmidi_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			     unsigned int port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	int (*get_clock)(struct snd_ff *ff, unsigned int *rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			 enum snd_ff_clock_src *src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	int (*switch_fetching_mode)(struct snd_ff *ff, bool enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	int (*allocate_resources)(struct snd_ff *ff, unsigned int rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	int (*begin_session)(struct snd_ff *ff, unsigned int rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	void (*finish_session)(struct snd_ff *ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	void (*dump_status)(struct snd_ff *ff, struct snd_info_buffer *buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) extern const struct snd_ff_protocol snd_ff_protocol_ff800;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) extern const struct snd_ff_protocol snd_ff_protocol_ff400;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) extern const struct snd_ff_protocol snd_ff_protocol_latter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int snd_ff_transaction_register(struct snd_ff *ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int snd_ff_transaction_reregister(struct snd_ff *ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) void snd_ff_transaction_unregister(struct snd_ff *ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int amdtp_ff_set_parameters(struct amdtp_stream *s, unsigned int rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			    unsigned int pcm_channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) int amdtp_ff_add_pcm_hw_constraints(struct amdtp_stream *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 				    struct snd_pcm_runtime *runtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) int amdtp_ff_init(struct amdtp_stream *s, struct fw_unit *unit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		  enum amdtp_stream_direction dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int snd_ff_stream_get_multiplier_mode(enum cip_sfc sfc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 				      enum snd_ff_stream_mode *mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) int snd_ff_stream_init_duplex(struct snd_ff *ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) void snd_ff_stream_destroy_duplex(struct snd_ff *ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) int snd_ff_stream_reserve_duplex(struct snd_ff *ff, unsigned int rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 				 unsigned int frames_per_period,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				 unsigned int frames_per_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) int snd_ff_stream_start_duplex(struct snd_ff *ff, unsigned int rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) void snd_ff_stream_stop_duplex(struct snd_ff *ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) void snd_ff_stream_update_duplex(struct snd_ff *ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) void snd_ff_stream_lock_changed(struct snd_ff *ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int snd_ff_stream_lock_try(struct snd_ff *ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) void snd_ff_stream_lock_release(struct snd_ff *ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) void snd_ff_proc_init(struct snd_ff *ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) const char *snd_ff_proc_get_clk_label(enum snd_ff_clock_src src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) int snd_ff_create_midi_devices(struct snd_ff *ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) int snd_ff_create_pcm_devices(struct snd_ff *ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int snd_ff_create_hwdep_devices(struct snd_ff *ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #endif