blob: 4aaf2dce5ec8709bc52e723c0cac2a52ce733481 [file] [log] [blame]
Takashi Sakamotob5b04332014-04-25 22:45:00 +09001/*
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>
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090023#include <sound/pcm.h>
Takashi Sakamoto6a226832014-04-25 22:45:08 +090024#include <sound/info.h>
Takashi Sakamotoa63d3ff2014-04-25 22:45:09 +090025#include <sound/rawmidi.h>
Takashi Sakamotoaa02bb62014-04-25 22:45:11 +090026#include <sound/pcm_params.h>
Takashi Sakamoto594ddce2014-04-25 22:45:12 +090027#include <sound/firewire.h>
28#include <sound/hwdep.h>
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090029
Takashi Sakamoto315fd412014-04-25 22:45:02 +090030#include "../packets-buffer.h"
31#include "../iso-resources.h"
32#include "../amdtp.h"
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090033#include "../cmp.h"
34#include "../lib.h"
35
Takashi Sakamoto315fd412014-04-25 22:45:02 +090036#define SND_EFW_MAX_MIDI_OUT_PORTS 2
37#define SND_EFW_MAX_MIDI_IN_PORTS 2
38
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090039#define SND_EFW_MULTIPLIER_MODES 3
40#define HWINFO_NAME_SIZE_BYTES 32
41#define HWINFO_MAX_CAPS_GROUPS 8
42
43/*
44 * This should be greater than maximum bytes for EFW response content.
45 * Currently response against command for isochronous channel mapping is
46 * confirmed to be the maximum one. But for flexibility, use maximum data
47 * payload for asynchronous primary packets at S100 (Cable base rate) in
48 * IEEE Std 1394-1995.
49 */
50#define SND_EFW_RESPONSE_MAXIMUM_BYTES 0x200U
51
52struct snd_efw_phys_grp {
53 u8 type; /* see enum snd_efw_grp_type */
54 u8 count;
55} __packed;
Takashi Sakamotob5b04332014-04-25 22:45:00 +090056
57struct snd_efw {
58 struct snd_card *card;
59 struct fw_unit *unit;
60 int card_index;
61
62 struct mutex mutex;
63 spinlock_t lock;
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090064
65 /* for transaction */
66 u32 seqnum;
67 bool resp_addr_changable;
Takashi Sakamoto315fd412014-04-25 22:45:02 +090068
Takashi Sakamoto69702232014-04-25 22:45:05 +090069 /* for quirks */
70 bool is_af9;
Takashi Sakamotod9cd0062014-04-25 22:45:06 +090071 u32 firmware_version;
Takashi Sakamoto69702232014-04-25 22:45:05 +090072
Takashi Sakamoto315fd412014-04-25 22:45:02 +090073 unsigned int midi_in_ports;
74 unsigned int midi_out_ports;
75
76 unsigned int supported_sampling_rate;
77 unsigned int pcm_capture_channels[SND_EFW_MULTIPLIER_MODES];
78 unsigned int pcm_playback_channels[SND_EFW_MULTIPLIER_MODES];
79
80 struct amdtp_stream *master;
81 struct amdtp_stream tx_stream;
82 struct amdtp_stream rx_stream;
83 struct cmp_connection out_conn;
84 struct cmp_connection in_conn;
85 atomic_t capture_substreams;
86 atomic_t playback_substreams;
Takashi Sakamoto6a226832014-04-25 22:45:08 +090087
88 /* hardware metering parameters */
89 unsigned int phys_out;
90 unsigned int phys_in;
91 unsigned int phys_out_grp_count;
92 unsigned int phys_in_grp_count;
93 struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
94 struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
Takashi Sakamoto594ddce2014-04-25 22:45:12 +090095
96 /* for uapi */
97 int dev_lock_count;
98 bool dev_lock_changed;
99 wait_queue_head_t hwdep_wait;
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900100};
101
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900102struct snd_efw_transaction {
103 __be32 length;
104 __be32 version;
105 __be32 seqnum;
106 __be32 category;
107 __be32 command;
108 __be32 status;
109 __be32 params[0];
110};
111int snd_efw_transaction_run(struct fw_unit *unit,
112 const void *cmd, unsigned int cmd_size,
113 void *resp, unsigned int resp_size);
114int snd_efw_transaction_register(void);
115void snd_efw_transaction_unregister(void);
116void snd_efw_transaction_bus_reset(struct fw_unit *unit);
117
118struct snd_efw_hwinfo {
119 u32 flags;
120 u32 guid_hi;
121 u32 guid_lo;
122 u32 type;
123 u32 version;
124 char vendor_name[HWINFO_NAME_SIZE_BYTES];
125 char model_name[HWINFO_NAME_SIZE_BYTES];
126 u32 supported_clocks;
127 u32 amdtp_rx_pcm_channels;
128 u32 amdtp_tx_pcm_channels;
129 u32 phys_out;
130 u32 phys_in;
131 u32 phys_out_grp_count;
132 struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
133 u32 phys_in_grp_count;
134 struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
135 u32 midi_out_ports;
136 u32 midi_in_ports;
137 u32 max_sample_rate;
138 u32 min_sample_rate;
139 u32 dsp_version;
140 u32 arm_version;
141 u32 mixer_playback_channels;
142 u32 mixer_capture_channels;
143 u32 fpga_version;
144 u32 amdtp_rx_pcm_channels_2x;
145 u32 amdtp_tx_pcm_channels_2x;
146 u32 amdtp_rx_pcm_channels_4x;
147 u32 amdtp_tx_pcm_channels_4x;
148 u32 reserved[16];
149} __packed;
150enum snd_efw_grp_type {
151 SND_EFW_CH_TYPE_ANALOG = 0,
152 SND_EFW_CH_TYPE_SPDIF = 1,
153 SND_EFW_CH_TYPE_ADAT = 2,
154 SND_EFW_CH_TYPE_SPDIF_OR_ADAT = 3,
155 SND_EFW_CH_TYPE_ANALOG_MIRRORING = 4,
156 SND_EFW_CH_TYPE_HEADPHONES = 5,
157 SND_EFW_CH_TYPE_I2S = 6,
158 SND_EFW_CH_TYPE_GUITAR = 7,
159 SND_EFW_CH_TYPE_PIEZO_GUITAR = 8,
160 SND_EFW_CH_TYPE_GUITAR_STRING = 9,
161 SND_EFW_CH_TYPE_VIRTUAL = 0x10000,
162 SND_EFW_CH_TYPE_DUMMY
163};
164struct snd_efw_phys_meters {
165 u32 status; /* guitar state/midi signal/clock input detect */
166 u32 reserved0;
167 u32 reserved1;
168 u32 reserved2;
169 u32 reserved3;
170 u32 out_meters;
171 u32 in_meters;
172 u32 reserved4;
173 u32 reserved5;
174 u32 values[0];
175} __packed;
176enum snd_efw_clock_source {
177 SND_EFW_CLOCK_SOURCE_INTERNAL = 0,
178 SND_EFW_CLOCK_SOURCE_SYTMATCH = 1,
179 SND_EFW_CLOCK_SOURCE_WORDCLOCK = 2,
180 SND_EFW_CLOCK_SOURCE_SPDIF = 3,
181 SND_EFW_CLOCK_SOURCE_ADAT_1 = 4,
182 SND_EFW_CLOCK_SOURCE_ADAT_2 = 5,
183 SND_EFW_CLOCK_SOURCE_CONTINUOUS = 6 /* internal variable clock */
184};
185enum snd_efw_transport_mode {
186 SND_EFW_TRANSPORT_MODE_WINDOWS = 0,
187 SND_EFW_TRANSPORT_MODE_IEC61883 = 1,
188};
189int snd_efw_command_set_resp_addr(struct snd_efw *efw,
190 u16 addr_high, u32 addr_low);
191int snd_efw_command_set_tx_mode(struct snd_efw *efw, unsigned int mode);
192int snd_efw_command_get_hwinfo(struct snd_efw *efw,
193 struct snd_efw_hwinfo *hwinfo);
194int snd_efw_command_get_phys_meters(struct snd_efw *efw,
195 struct snd_efw_phys_meters *meters,
196 unsigned int len);
197int snd_efw_command_get_clock_source(struct snd_efw *efw,
198 enum snd_efw_clock_source *source);
199int snd_efw_command_get_sampling_rate(struct snd_efw *efw, unsigned int *rate);
200int snd_efw_command_set_sampling_rate(struct snd_efw *efw, unsigned int rate);
201
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900202int snd_efw_stream_init_duplex(struct snd_efw *efw);
203int snd_efw_stream_start_duplex(struct snd_efw *efw, int sampling_rate);
204void snd_efw_stream_stop_duplex(struct snd_efw *efw);
205void snd_efw_stream_update_duplex(struct snd_efw *efw);
206void snd_efw_stream_destroy_duplex(struct snd_efw *efw);
Takashi Sakamoto594ddce2014-04-25 22:45:12 +0900207void snd_efw_stream_lock_changed(struct snd_efw *efw);
208int snd_efw_stream_lock_try(struct snd_efw *efw);
209void snd_efw_stream_lock_release(struct snd_efw *efw);
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900210
Takashi Sakamoto6a226832014-04-25 22:45:08 +0900211void snd_efw_proc_init(struct snd_efw *efw);
212
Takashi Sakamotoa63d3ff2014-04-25 22:45:09 +0900213int snd_efw_create_midi_devices(struct snd_efw *efw);
214
Takashi Sakamotoaa02bb62014-04-25 22:45:11 +0900215int snd_efw_create_pcm_devices(struct snd_efw *efw);
216int snd_efw_get_multiplier_mode(unsigned int sampling_rate, unsigned int *mode);
217
Takashi Sakamoto594ddce2014-04-25 22:45:12 +0900218int snd_efw_create_hwdep_device(struct snd_efw *efw);
219
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900220#define SND_EFW_DEV_ENTRY(vendor, model) \
221{ \
222 .match_flags = IEEE1394_MATCH_VENDOR_ID | \
223 IEEE1394_MATCH_MODEL_ID, \
224 .vendor_id = vendor,\
225 .model_id = model \
226}
227
228#endif