blob: 4f0201a95222a2502ec438199fe9e78cad33b647 [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
Takashi Sakamoto555e8a82014-04-25 22:45:13 +090052extern unsigned int snd_efw_resp_buf_size;
53extern bool snd_efw_resp_buf_debug;
54
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090055struct snd_efw_phys_grp {
56 u8 type; /* see enum snd_efw_grp_type */
57 u8 count;
58} __packed;
Takashi Sakamotob5b04332014-04-25 22:45:00 +090059
60struct snd_efw {
61 struct snd_card *card;
62 struct fw_unit *unit;
63 int card_index;
64
65 struct mutex mutex;
66 spinlock_t lock;
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090067
68 /* for transaction */
69 u32 seqnum;
70 bool resp_addr_changable;
Takashi Sakamoto315fd412014-04-25 22:45:02 +090071
Takashi Sakamoto69702232014-04-25 22:45:05 +090072 /* for quirks */
73 bool is_af9;
Takashi Sakamotod9cd0062014-04-25 22:45:06 +090074 u32 firmware_version;
Takashi Sakamoto69702232014-04-25 22:45:05 +090075
Takashi Sakamoto315fd412014-04-25 22:45:02 +090076 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 *master;
84 struct amdtp_stream tx_stream;
85 struct amdtp_stream rx_stream;
86 struct cmp_connection out_conn;
87 struct cmp_connection in_conn;
88 atomic_t capture_substreams;
89 atomic_t playback_substreams;
Takashi Sakamoto6a226832014-04-25 22:45:08 +090090
91 /* hardware metering parameters */
92 unsigned int phys_out;
93 unsigned int phys_in;
94 unsigned int phys_out_grp_count;
95 unsigned int phys_in_grp_count;
96 struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
97 struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
Takashi Sakamoto594ddce2014-04-25 22:45:12 +090098
99 /* for uapi */
100 int dev_lock_count;
101 bool dev_lock_changed;
102 wait_queue_head_t hwdep_wait;
Takashi Sakamoto555e8a82014-04-25 22:45:13 +0900103
104 /* response queue */
105 u8 *resp_buf;
106 u8 *pull_ptr;
107 u8 *push_ptr;
108 unsigned int resp_queues;
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900109};
110
Takashi Sakamoto555e8a82014-04-25 22:45:13 +0900111int snd_efw_transaction_cmd(struct fw_unit *unit,
112 const void *cmd, unsigned int size);
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900113int snd_efw_transaction_run(struct fw_unit *unit,
114 const void *cmd, unsigned int cmd_size,
115 void *resp, unsigned int resp_size);
116int snd_efw_transaction_register(void);
117void snd_efw_transaction_unregister(void);
118void snd_efw_transaction_bus_reset(struct fw_unit *unit);
Takashi Sakamoto555e8a82014-04-25 22:45:13 +0900119void snd_efw_transaction_add_instance(struct snd_efw *efw);
120void snd_efw_transaction_remove_instance(struct snd_efw *efw);
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900121
122struct snd_efw_hwinfo {
123 u32 flags;
124 u32 guid_hi;
125 u32 guid_lo;
126 u32 type;
127 u32 version;
128 char vendor_name[HWINFO_NAME_SIZE_BYTES];
129 char model_name[HWINFO_NAME_SIZE_BYTES];
130 u32 supported_clocks;
131 u32 amdtp_rx_pcm_channels;
132 u32 amdtp_tx_pcm_channels;
133 u32 phys_out;
134 u32 phys_in;
135 u32 phys_out_grp_count;
136 struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
137 u32 phys_in_grp_count;
138 struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
139 u32 midi_out_ports;
140 u32 midi_in_ports;
141 u32 max_sample_rate;
142 u32 min_sample_rate;
143 u32 dsp_version;
144 u32 arm_version;
145 u32 mixer_playback_channels;
146 u32 mixer_capture_channels;
147 u32 fpga_version;
148 u32 amdtp_rx_pcm_channels_2x;
149 u32 amdtp_tx_pcm_channels_2x;
150 u32 amdtp_rx_pcm_channels_4x;
151 u32 amdtp_tx_pcm_channels_4x;
152 u32 reserved[16];
153} __packed;
154enum snd_efw_grp_type {
155 SND_EFW_CH_TYPE_ANALOG = 0,
156 SND_EFW_CH_TYPE_SPDIF = 1,
157 SND_EFW_CH_TYPE_ADAT = 2,
158 SND_EFW_CH_TYPE_SPDIF_OR_ADAT = 3,
159 SND_EFW_CH_TYPE_ANALOG_MIRRORING = 4,
160 SND_EFW_CH_TYPE_HEADPHONES = 5,
161 SND_EFW_CH_TYPE_I2S = 6,
162 SND_EFW_CH_TYPE_GUITAR = 7,
163 SND_EFW_CH_TYPE_PIEZO_GUITAR = 8,
164 SND_EFW_CH_TYPE_GUITAR_STRING = 9,
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900165 SND_EFW_CH_TYPE_DUMMY
166};
167struct snd_efw_phys_meters {
168 u32 status; /* guitar state/midi signal/clock input detect */
169 u32 reserved0;
170 u32 reserved1;
171 u32 reserved2;
172 u32 reserved3;
173 u32 out_meters;
174 u32 in_meters;
175 u32 reserved4;
176 u32 reserved5;
177 u32 values[0];
178} __packed;
179enum snd_efw_clock_source {
180 SND_EFW_CLOCK_SOURCE_INTERNAL = 0,
181 SND_EFW_CLOCK_SOURCE_SYTMATCH = 1,
182 SND_EFW_CLOCK_SOURCE_WORDCLOCK = 2,
183 SND_EFW_CLOCK_SOURCE_SPDIF = 3,
184 SND_EFW_CLOCK_SOURCE_ADAT_1 = 4,
185 SND_EFW_CLOCK_SOURCE_ADAT_2 = 5,
186 SND_EFW_CLOCK_SOURCE_CONTINUOUS = 6 /* internal variable clock */
187};
188enum snd_efw_transport_mode {
189 SND_EFW_TRANSPORT_MODE_WINDOWS = 0,
190 SND_EFW_TRANSPORT_MODE_IEC61883 = 1,
191};
192int snd_efw_command_set_resp_addr(struct snd_efw *efw,
193 u16 addr_high, u32 addr_low);
Takashi Sakamoto93219d02014-05-28 00:14:39 +0900194int snd_efw_command_set_tx_mode(struct snd_efw *efw,
195 enum snd_efw_transport_mode mode);
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900196int snd_efw_command_get_hwinfo(struct snd_efw *efw,
197 struct snd_efw_hwinfo *hwinfo);
198int snd_efw_command_get_phys_meters(struct snd_efw *efw,
199 struct snd_efw_phys_meters *meters,
200 unsigned int len);
201int snd_efw_command_get_clock_source(struct snd_efw *efw,
202 enum snd_efw_clock_source *source);
203int snd_efw_command_get_sampling_rate(struct snd_efw *efw, unsigned int *rate);
204int snd_efw_command_set_sampling_rate(struct snd_efw *efw, unsigned int rate);
205
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900206int snd_efw_stream_init_duplex(struct snd_efw *efw);
Takashi Sakamoto4a286d52014-05-28 00:14:40 +0900207int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate);
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900208void snd_efw_stream_stop_duplex(struct snd_efw *efw);
209void snd_efw_stream_update_duplex(struct snd_efw *efw);
210void snd_efw_stream_destroy_duplex(struct snd_efw *efw);
Takashi Sakamoto594ddce2014-04-25 22:45:12 +0900211void snd_efw_stream_lock_changed(struct snd_efw *efw);
212int snd_efw_stream_lock_try(struct snd_efw *efw);
213void snd_efw_stream_lock_release(struct snd_efw *efw);
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900214
Takashi Sakamoto6a226832014-04-25 22:45:08 +0900215void snd_efw_proc_init(struct snd_efw *efw);
216
Takashi Sakamotoa63d3ff2014-04-25 22:45:09 +0900217int snd_efw_create_midi_devices(struct snd_efw *efw);
218
Takashi Sakamotoaa02bb62014-04-25 22:45:11 +0900219int snd_efw_create_pcm_devices(struct snd_efw *efw);
220int snd_efw_get_multiplier_mode(unsigned int sampling_rate, unsigned int *mode);
221
Takashi Sakamoto594ddce2014-04-25 22:45:12 +0900222int snd_efw_create_hwdep_device(struct snd_efw *efw);
223
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900224#define SND_EFW_DEV_ENTRY(vendor, model) \
225{ \
226 .match_flags = IEEE1394_MATCH_VENDOR_ID | \
227 IEEE1394_MATCH_MODEL_ID, \
228 .vendor_id = vendor,\
229 .model_id = model \
230}
231
232#endif