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