blob: eef7ad89fd4e16dfdf2dedc8d80e1f9339607f46 [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 Sakamotobde8a8f2014-04-25 22:45:01 +090025
Takashi Sakamoto315fd412014-04-25 22:45:02 +090026#include "../packets-buffer.h"
27#include "../iso-resources.h"
28#include "../amdtp.h"
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090029#include "../cmp.h"
30#include "../lib.h"
31
Takashi Sakamoto315fd412014-04-25 22:45:02 +090032#define SND_EFW_MAX_MIDI_OUT_PORTS 2
33#define SND_EFW_MAX_MIDI_IN_PORTS 2
34
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090035#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
48struct snd_efw_phys_grp {
49 u8 type; /* see enum snd_efw_grp_type */
50 u8 count;
51} __packed;
Takashi Sakamotob5b04332014-04-25 22:45:00 +090052
53struct 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;
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090060
61 /* for transaction */
62 u32 seqnum;
63 bool resp_addr_changable;
Takashi Sakamoto315fd412014-04-25 22:45:02 +090064
Takashi Sakamoto69702232014-04-25 22:45:05 +090065 /* for quirks */
66 bool is_af9;
Takashi Sakamotod9cd0062014-04-25 22:45:06 +090067 u32 firmware_version;
Takashi Sakamoto69702232014-04-25 22:45:05 +090068
Takashi Sakamoto315fd412014-04-25 22:45:02 +090069 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;
Takashi Sakamoto6a226832014-04-25 22:45:08 +090083
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];
Takashi Sakamotob5b04332014-04-25 22:45:00 +090091};
92
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090093struct 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};
102int snd_efw_transaction_run(struct fw_unit *unit,
103 const void *cmd, unsigned int cmd_size,
104 void *resp, unsigned int resp_size);
105int snd_efw_transaction_register(void);
106void snd_efw_transaction_unregister(void);
107void snd_efw_transaction_bus_reset(struct fw_unit *unit);
108
109struct 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;
141enum 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};
155struct 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;
167enum 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};
176enum snd_efw_transport_mode {
177 SND_EFW_TRANSPORT_MODE_WINDOWS = 0,
178 SND_EFW_TRANSPORT_MODE_IEC61883 = 1,
179};
180int snd_efw_command_set_resp_addr(struct snd_efw *efw,
181 u16 addr_high, u32 addr_low);
182int snd_efw_command_set_tx_mode(struct snd_efw *efw, unsigned int mode);
183int snd_efw_command_get_hwinfo(struct snd_efw *efw,
184 struct snd_efw_hwinfo *hwinfo);
185int snd_efw_command_get_phys_meters(struct snd_efw *efw,
186 struct snd_efw_phys_meters *meters,
187 unsigned int len);
188int snd_efw_command_get_clock_source(struct snd_efw *efw,
189 enum snd_efw_clock_source *source);
190int snd_efw_command_get_sampling_rate(struct snd_efw *efw, unsigned int *rate);
191int snd_efw_command_set_sampling_rate(struct snd_efw *efw, unsigned int rate);
192
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900193int snd_efw_stream_init_duplex(struct snd_efw *efw);
194int snd_efw_stream_start_duplex(struct snd_efw *efw, int sampling_rate);
195void snd_efw_stream_stop_duplex(struct snd_efw *efw);
196void snd_efw_stream_update_duplex(struct snd_efw *efw);
197void snd_efw_stream_destroy_duplex(struct snd_efw *efw);
198
Takashi Sakamoto6a226832014-04-25 22:45:08 +0900199void snd_efw_proc_init(struct snd_efw *efw);
200
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900201#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