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