blob: 36419ca12d6fcb4b6fa6990a4a8f95f1b7289c50 [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 Sakamotobde8a8f2014-04-25 22:45:01 +090027
Takashi Sakamoto315fd412014-04-25 22:45:02 +090028#include "../packets-buffer.h"
29#include "../iso-resources.h"
30#include "../amdtp.h"
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090031#include "../cmp.h"
32#include "../lib.h"
33
Takashi Sakamoto315fd412014-04-25 22:45:02 +090034#define SND_EFW_MAX_MIDI_OUT_PORTS 2
35#define SND_EFW_MAX_MIDI_IN_PORTS 2
36
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090037#define SND_EFW_MULTIPLIER_MODES 3
38#define HWINFO_NAME_SIZE_BYTES 32
39#define HWINFO_MAX_CAPS_GROUPS 8
40
41/*
42 * This should be greater than maximum bytes for EFW response content.
43 * Currently response against command for isochronous channel mapping is
44 * confirmed to be the maximum one. But for flexibility, use maximum data
45 * payload for asynchronous primary packets at S100 (Cable base rate) in
46 * IEEE Std 1394-1995.
47 */
48#define SND_EFW_RESPONSE_MAXIMUM_BYTES 0x200U
49
50struct snd_efw_phys_grp {
51 u8 type; /* see enum snd_efw_grp_type */
52 u8 count;
53} __packed;
Takashi Sakamotob5b04332014-04-25 22:45:00 +090054
55struct snd_efw {
56 struct snd_card *card;
57 struct fw_unit *unit;
58 int card_index;
59
60 struct mutex mutex;
61 spinlock_t lock;
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090062
63 /* for transaction */
64 u32 seqnum;
65 bool resp_addr_changable;
Takashi Sakamoto315fd412014-04-25 22:45:02 +090066
Takashi Sakamoto69702232014-04-25 22:45:05 +090067 /* for quirks */
68 bool is_af9;
Takashi Sakamotod9cd0062014-04-25 22:45:06 +090069 u32 firmware_version;
Takashi Sakamoto69702232014-04-25 22:45:05 +090070
Takashi Sakamoto315fd412014-04-25 22:45:02 +090071 unsigned int midi_in_ports;
72 unsigned int midi_out_ports;
73
74 unsigned int supported_sampling_rate;
75 unsigned int pcm_capture_channels[SND_EFW_MULTIPLIER_MODES];
76 unsigned int pcm_playback_channels[SND_EFW_MULTIPLIER_MODES];
77
78 struct amdtp_stream *master;
79 struct amdtp_stream tx_stream;
80 struct amdtp_stream rx_stream;
81 struct cmp_connection out_conn;
82 struct cmp_connection in_conn;
83 atomic_t capture_substreams;
84 atomic_t playback_substreams;
Takashi Sakamoto6a226832014-04-25 22:45:08 +090085
86 /* hardware metering parameters */
87 unsigned int phys_out;
88 unsigned int phys_in;
89 unsigned int phys_out_grp_count;
90 unsigned int phys_in_grp_count;
91 struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
92 struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
Takashi Sakamotob5b04332014-04-25 22:45:00 +090093};
94
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090095struct snd_efw_transaction {
96 __be32 length;
97 __be32 version;
98 __be32 seqnum;
99 __be32 category;
100 __be32 command;
101 __be32 status;
102 __be32 params[0];
103};
104int snd_efw_transaction_run(struct fw_unit *unit,
105 const void *cmd, unsigned int cmd_size,
106 void *resp, unsigned int resp_size);
107int snd_efw_transaction_register(void);
108void snd_efw_transaction_unregister(void);
109void snd_efw_transaction_bus_reset(struct fw_unit *unit);
110
111struct snd_efw_hwinfo {
112 u32 flags;
113 u32 guid_hi;
114 u32 guid_lo;
115 u32 type;
116 u32 version;
117 char vendor_name[HWINFO_NAME_SIZE_BYTES];
118 char model_name[HWINFO_NAME_SIZE_BYTES];
119 u32 supported_clocks;
120 u32 amdtp_rx_pcm_channels;
121 u32 amdtp_tx_pcm_channels;
122 u32 phys_out;
123 u32 phys_in;
124 u32 phys_out_grp_count;
125 struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
126 u32 phys_in_grp_count;
127 struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
128 u32 midi_out_ports;
129 u32 midi_in_ports;
130 u32 max_sample_rate;
131 u32 min_sample_rate;
132 u32 dsp_version;
133 u32 arm_version;
134 u32 mixer_playback_channels;
135 u32 mixer_capture_channels;
136 u32 fpga_version;
137 u32 amdtp_rx_pcm_channels_2x;
138 u32 amdtp_tx_pcm_channels_2x;
139 u32 amdtp_rx_pcm_channels_4x;
140 u32 amdtp_tx_pcm_channels_4x;
141 u32 reserved[16];
142} __packed;
143enum snd_efw_grp_type {
144 SND_EFW_CH_TYPE_ANALOG = 0,
145 SND_EFW_CH_TYPE_SPDIF = 1,
146 SND_EFW_CH_TYPE_ADAT = 2,
147 SND_EFW_CH_TYPE_SPDIF_OR_ADAT = 3,
148 SND_EFW_CH_TYPE_ANALOG_MIRRORING = 4,
149 SND_EFW_CH_TYPE_HEADPHONES = 5,
150 SND_EFW_CH_TYPE_I2S = 6,
151 SND_EFW_CH_TYPE_GUITAR = 7,
152 SND_EFW_CH_TYPE_PIEZO_GUITAR = 8,
153 SND_EFW_CH_TYPE_GUITAR_STRING = 9,
154 SND_EFW_CH_TYPE_VIRTUAL = 0x10000,
155 SND_EFW_CH_TYPE_DUMMY
156};
157struct snd_efw_phys_meters {
158 u32 status; /* guitar state/midi signal/clock input detect */
159 u32 reserved0;
160 u32 reserved1;
161 u32 reserved2;
162 u32 reserved3;
163 u32 out_meters;
164 u32 in_meters;
165 u32 reserved4;
166 u32 reserved5;
167 u32 values[0];
168} __packed;
169enum snd_efw_clock_source {
170 SND_EFW_CLOCK_SOURCE_INTERNAL = 0,
171 SND_EFW_CLOCK_SOURCE_SYTMATCH = 1,
172 SND_EFW_CLOCK_SOURCE_WORDCLOCK = 2,
173 SND_EFW_CLOCK_SOURCE_SPDIF = 3,
174 SND_EFW_CLOCK_SOURCE_ADAT_1 = 4,
175 SND_EFW_CLOCK_SOURCE_ADAT_2 = 5,
176 SND_EFW_CLOCK_SOURCE_CONTINUOUS = 6 /* internal variable clock */
177};
178enum snd_efw_transport_mode {
179 SND_EFW_TRANSPORT_MODE_WINDOWS = 0,
180 SND_EFW_TRANSPORT_MODE_IEC61883 = 1,
181};
182int snd_efw_command_set_resp_addr(struct snd_efw *efw,
183 u16 addr_high, u32 addr_low);
184int snd_efw_command_set_tx_mode(struct snd_efw *efw, unsigned int mode);
185int snd_efw_command_get_hwinfo(struct snd_efw *efw,
186 struct snd_efw_hwinfo *hwinfo);
187int snd_efw_command_get_phys_meters(struct snd_efw *efw,
188 struct snd_efw_phys_meters *meters,
189 unsigned int len);
190int snd_efw_command_get_clock_source(struct snd_efw *efw,
191 enum snd_efw_clock_source *source);
192int snd_efw_command_get_sampling_rate(struct snd_efw *efw, unsigned int *rate);
193int snd_efw_command_set_sampling_rate(struct snd_efw *efw, unsigned int rate);
194
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900195int snd_efw_stream_init_duplex(struct snd_efw *efw);
196int snd_efw_stream_start_duplex(struct snd_efw *efw, int sampling_rate);
197void snd_efw_stream_stop_duplex(struct snd_efw *efw);
198void snd_efw_stream_update_duplex(struct snd_efw *efw);
199void snd_efw_stream_destroy_duplex(struct snd_efw *efw);
200
Takashi Sakamoto6a226832014-04-25 22:45:08 +0900201void snd_efw_proc_init(struct snd_efw *efw);
202
Takashi Sakamotoa63d3ff2014-04-25 22:45:09 +0900203int snd_efw_create_midi_devices(struct snd_efw *efw);
204
Takashi Sakamotoaa02bb62014-04-25 22:45:11 +0900205int snd_efw_create_pcm_devices(struct snd_efw *efw);
206int snd_efw_get_multiplier_mode(unsigned int sampling_rate, unsigned int *mode);
207
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900208#define SND_EFW_DEV_ENTRY(vendor, model) \
209{ \
210 .match_flags = IEEE1394_MATCH_VENDOR_ID | \
211 IEEE1394_MATCH_MODEL_ID, \
212 .vendor_id = vendor,\
213 .model_id = model \
214}
215
216#endif