xref: /linux/sound/firewire/fireworks/fireworks.h (revision fab183d632628381b466a41479489541ac0e29a0)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * fireworks.h - a part of driver for Fireworks based devices
4  *
5  * Copyright (c) 2009-2010 Clemens Ladisch
6  * Copyright (c) 2013-2014 Takashi Sakamoto
7  */
8 #ifndef SOUND_FIREWORKS_H_INCLUDED
9 #define SOUND_FIREWORKS_H_INCLUDED
10 
11 #include <linux/compat.h>
12 #include <linux/device.h>
13 #include <linux/firewire.h>
14 #include <linux/firewire-constants.h>
15 #include <linux/module.h>
16 #include <linux/delay.h>
17 #include <linux/slab.h>
18 #include <linux/sched/signal.h>
19 
20 #include <sound/core.h>
21 #include <sound/initval.h>
22 #include <sound/pcm.h>
23 #include <sound/info.h>
24 #include <sound/rawmidi.h>
25 #include <sound/pcm_params.h>
26 #include <sound/firewire.h>
27 #include <sound/hwdep.h>
28 
29 #include "../packets-buffer.h"
30 #include "../iso-resources.h"
31 #include "../amdtp-am824.h"
32 #include "../cmp.h"
33 #include "../lib.h"
34 
35 #define SND_EFW_MAX_MIDI_OUT_PORTS	2
36 #define SND_EFW_MAX_MIDI_IN_PORTS	2
37 
38 #define SND_EFW_MULTIPLIER_MODES	3
39 #define HWINFO_NAME_SIZE_BYTES		32
40 #define HWINFO_MAX_CAPS_GROUPS		8
41 
42 /*
43  * This should be greater than maximum bytes for EFW response content.
44  * Currently response against command for isochronous channel mapping is
45  * confirmed to be the maximum one. But for flexibility, use maximum data
46  * payload for asynchronous primary packets at S100 (Cable base rate) in
47  * IEEE Std 1394-1995.
48  */
49 #define SND_EFW_RESPONSE_MAXIMUM_BYTES	0x200U
50 
51 extern unsigned int snd_efw_resp_buf_size;
52 extern bool snd_efw_resp_buf_debug;
53 
54 struct snd_efw_phys_grp {
55 	u8 type;	/* see enum snd_efw_grp_type */
56 	u8 count;
57 } __packed;
58 
59 struct snd_efw {
60 	struct snd_card *card;
61 	struct fw_unit *unit;
62 	int card_index;
63 
64 	struct mutex mutex;
65 	spinlock_t lock;
66 
67 	/* for transaction */
68 	u32 seqnum;
69 	bool resp_addr_changable;
70 
71 	/* for quirks */
72 	bool is_af9;
73 	bool is_fireworks3;
74 	u32 firmware_version;
75 
76 	unsigned int midi_in_ports;
77 	unsigned int midi_out_ports;
78 
79 	unsigned int supported_sampling_rate;
80 	unsigned int pcm_capture_channels[SND_EFW_MULTIPLIER_MODES];
81 	unsigned int pcm_playback_channels[SND_EFW_MULTIPLIER_MODES];
82 
83 	struct amdtp_stream tx_stream;
84 	struct amdtp_stream rx_stream;
85 	struct cmp_connection out_conn;
86 	struct cmp_connection in_conn;
87 	unsigned int substreams_counter;
88 
89 	/* hardware metering parameters */
90 	unsigned int phys_out;
91 	unsigned int phys_in;
92 	unsigned int phys_out_grp_count;
93 	unsigned int phys_in_grp_count;
94 	struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
95 	struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
96 
97 	/* for uapi */
98 	int dev_lock_count;
99 	bool dev_lock_changed;
100 	wait_queue_head_t hwdep_wait;
101 
102 	/* response queue */
103 	u8 *resp_buf;
104 	u8 *pull_ptr;
105 	u8 *push_ptr;
106 
107 	struct amdtp_domain domain;
108 };
109 
110 int snd_efw_transaction_cmd(struct fw_unit *unit,
111 			    const void *cmd, unsigned int size);
112 int snd_efw_transaction_run(struct fw_unit *unit,
113 			    const void *cmd, unsigned int cmd_size,
114 			    void *resp, unsigned int resp_size);
115 int snd_efw_transaction_register(void);
116 void snd_efw_transaction_unregister(void);
117 void snd_efw_transaction_bus_reset(struct fw_unit *unit);
118 void snd_efw_transaction_add_instance(struct snd_efw *efw);
119 void snd_efw_transaction_remove_instance(struct snd_efw *efw);
120 
121 struct snd_efw_hwinfo {
122 	u32 flags;
123 	u32 guid_hi;
124 	u32 guid_lo;
125 	u32 type;
126 	u32 version;
127 	char vendor_name[HWINFO_NAME_SIZE_BYTES];
128 	char model_name[HWINFO_NAME_SIZE_BYTES];
129 	u32 supported_clocks;
130 	u32 amdtp_rx_pcm_channels;
131 	u32 amdtp_tx_pcm_channels;
132 	u32 phys_out;
133 	u32 phys_in;
134 	u32 phys_out_grp_count;
135 	struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
136 	u32 phys_in_grp_count;
137 	struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
138 	u32 midi_out_ports;
139 	u32 midi_in_ports;
140 	u32 max_sample_rate;
141 	u32 min_sample_rate;
142 	u32 dsp_version;
143 	u32 arm_version;
144 	u32 mixer_playback_channels;
145 	u32 mixer_capture_channels;
146 	u32 fpga_version;
147 	u32 amdtp_rx_pcm_channels_2x;
148 	u32 amdtp_tx_pcm_channels_2x;
149 	u32 amdtp_rx_pcm_channels_4x;
150 	u32 amdtp_tx_pcm_channels_4x;
151 	u32 reserved[16];
152 } __packed;
153 enum snd_efw_grp_type {
154 	SND_EFW_CH_TYPE_ANALOG			= 0,
155 	SND_EFW_CH_TYPE_SPDIF			= 1,
156 	SND_EFW_CH_TYPE_ADAT			= 2,
157 	SND_EFW_CH_TYPE_SPDIF_OR_ADAT		= 3,
158 	SND_EFW_CH_TYPE_ANALOG_MIRRORING	= 4,
159 	SND_EFW_CH_TYPE_HEADPHONES		= 5,
160 	SND_EFW_CH_TYPE_I2S			= 6,
161 	SND_EFW_CH_TYPE_GUITAR			= 7,
162 	SND_EFW_CH_TYPE_PIEZO_GUITAR		= 8,
163 	SND_EFW_CH_TYPE_GUITAR_STRING		= 9,
164 	SND_EFW_CH_TYPE_DUMMY
165 };
166 struct snd_efw_phys_meters {
167 	u32 status;	/* guitar state/midi signal/clock input detect */
168 	u32 reserved0;
169 	u32 reserved1;
170 	u32 reserved2;
171 	u32 reserved3;
172 	u32 out_meters;
173 	u32 in_meters;
174 	u32 reserved4;
175 	u32 reserved5;
176 	u32 values[];
177 } __packed;
178 enum snd_efw_clock_source {
179 	SND_EFW_CLOCK_SOURCE_INTERNAL	= 0,
180 	// Unused.
181 	SND_EFW_CLOCK_SOURCE_WORDCLOCK	= 2,
182 	SND_EFW_CLOCK_SOURCE_SPDIF	= 3,
183 	SND_EFW_CLOCK_SOURCE_ADAT_1	= 4,
184 	SND_EFW_CLOCK_SOURCE_ADAT_2	= 5,
185 	SND_EFW_CLOCK_SOURCE_CONTINUOUS	= 6	/* internal variable clock */
186 };
187 enum snd_efw_transport_mode {
188 	SND_EFW_TRANSPORT_MODE_WINDOWS	= 0,
189 	SND_EFW_TRANSPORT_MODE_IEC61883	= 1,
190 };
191 int snd_efw_command_set_resp_addr(struct snd_efw *efw,
192 				  u16 addr_high, u32 addr_low);
193 int snd_efw_command_set_tx_mode(struct snd_efw *efw,
194 				enum snd_efw_transport_mode mode);
195 int snd_efw_command_get_hwinfo(struct snd_efw *efw,
196 			       struct snd_efw_hwinfo *hwinfo);
197 int snd_efw_command_get_phys_meters(struct snd_efw *efw,
198 				    struct snd_efw_phys_meters *meters,
199 				    unsigned int len);
200 int snd_efw_command_get_clock_source(struct snd_efw *efw,
201 				     enum snd_efw_clock_source *source);
202 int snd_efw_command_get_sampling_rate(struct snd_efw *efw, unsigned int *rate);
203 int snd_efw_command_set_sampling_rate(struct snd_efw *efw, unsigned int rate);
204 
205 int snd_efw_stream_init_duplex(struct snd_efw *efw);
206 int snd_efw_stream_reserve_duplex(struct snd_efw *efw, unsigned int rate,
207 				  unsigned int frames_per_period,
208 				  unsigned int frames_per_buffer);
209 int snd_efw_stream_start_duplex(struct snd_efw *efw);
210 void snd_efw_stream_stop_duplex(struct snd_efw *efw);
211 void snd_efw_stream_update_duplex(struct snd_efw *efw);
212 void snd_efw_stream_destroy_duplex(struct snd_efw *efw);
213 void snd_efw_stream_lock_changed(struct snd_efw *efw);
214 int snd_efw_stream_lock_try(struct snd_efw *efw);
215 void snd_efw_stream_lock_release(struct snd_efw *efw);
216 
217 void snd_efw_proc_init(struct snd_efw *efw);
218 
219 int snd_efw_create_midi_devices(struct snd_efw *efw);
220 
221 int snd_efw_create_pcm_devices(struct snd_efw *efw);
222 int snd_efw_get_multiplier_mode(unsigned int sampling_rate, unsigned int *mode);
223 
224 int snd_efw_create_hwdep_device(struct snd_efw *efw);
225 
226 #endif
227