blob: 654e28a6669fe1bfe18e0410ff50a2f7d64a676d [file] [log] [blame]
Thomas Gleixnerda607e12019-05-29 16:57:59 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Takashi Sakamotob5b04332014-04-25 22:45:00 +09002/*
3 * fireworks.h - a part of driver for Fireworks based devices
4 *
5 * Copyright (c) 2009-2010 Clemens Ladisch
6 * Copyright (c) 2013-2014 Takashi Sakamoto
Takashi Sakamotob5b04332014-04-25 22:45:00 +09007 */
8#ifndef SOUND_FIREWORKS_H_INCLUDED
9#define SOUND_FIREWORKS_H_INCLUDED
10
11#include <linux/compat.h>
12#include <linux/device.h>
13#include <linux/firewire.h>
14#include <linux/firewire-constants.h>
15#include <linux/module.h>
16#include <linux/mod_devicetable.h>
17#include <linux/delay.h>
18#include <linux/slab.h>
Ingo Molnar174cd4b2017-02-02 19:15:33 +010019#include <linux/sched/signal.h>
Takashi Sakamotob5b04332014-04-25 22:45:00 +090020
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"
Takashi Sakamoto59558152015-09-19 11:21:55 +090032#include "../amdtp-am824.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
Takashi Sakamoto7d3c1d52016-03-31 08:47:06 +090068 bool registered;
69 struct delayed_work dwork;
70
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090071 /* for transaction */
72 u32 seqnum;
73 bool resp_addr_changable;
Takashi Sakamoto315fd412014-04-25 22:45:02 +090074
Takashi Sakamoto69702232014-04-25 22:45:05 +090075 /* for quirks */
76 bool is_af9;
Takashi Sakamoto18f5ed32015-08-05 09:21:05 +090077 bool is_fireworks3;
Takashi Sakamotod9cd0062014-04-25 22:45:06 +090078 u32 firmware_version;
Takashi Sakamoto69702232014-04-25 22:45:05 +090079
Takashi Sakamoto315fd412014-04-25 22:45:02 +090080 unsigned int midi_in_ports;
81 unsigned int midi_out_ports;
82
83 unsigned int supported_sampling_rate;
84 unsigned int pcm_capture_channels[SND_EFW_MULTIPLIER_MODES];
85 unsigned int pcm_playback_channels[SND_EFW_MULTIPLIER_MODES];
86
Takashi Sakamoto315fd412014-04-25 22:45:02 +090087 struct amdtp_stream tx_stream;
88 struct amdtp_stream rx_stream;
89 struct cmp_connection out_conn;
90 struct cmp_connection in_conn;
Takashi Sakamoto1dc59212019-06-12 17:44:08 +090091 unsigned int substreams_counter;
Takashi Sakamoto6a226832014-04-25 22:45:08 +090092
93 /* hardware metering parameters */
94 unsigned int phys_out;
95 unsigned int phys_in;
96 unsigned int phys_out_grp_count;
97 unsigned int phys_in_grp_count;
98 struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
99 struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
Takashi Sakamoto594ddce2014-04-25 22:45:12 +0900100
101 /* for uapi */
102 int dev_lock_count;
103 bool dev_lock_changed;
104 wait_queue_head_t hwdep_wait;
Takashi Sakamoto555e8a82014-04-25 22:45:13 +0900105
106 /* response queue */
107 u8 *resp_buf;
108 u8 *pull_ptr;
109 u8 *push_ptr;
Takashi Sakamotodb40eeb2019-08-04 15:21:31 +0900110
111 struct amdtp_domain domain;
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900112};
113
Takashi Sakamoto555e8a82014-04-25 22:45:13 +0900114int snd_efw_transaction_cmd(struct fw_unit *unit,
115 const void *cmd, unsigned int size);
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900116int snd_efw_transaction_run(struct fw_unit *unit,
117 const void *cmd, unsigned int cmd_size,
118 void *resp, unsigned int resp_size);
119int snd_efw_transaction_register(void);
120void snd_efw_transaction_unregister(void);
121void snd_efw_transaction_bus_reset(struct fw_unit *unit);
Takashi Sakamoto555e8a82014-04-25 22:45:13 +0900122void snd_efw_transaction_add_instance(struct snd_efw *efw);
123void snd_efw_transaction_remove_instance(struct snd_efw *efw);
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900124
125struct snd_efw_hwinfo {
126 u32 flags;
127 u32 guid_hi;
128 u32 guid_lo;
129 u32 type;
130 u32 version;
131 char vendor_name[HWINFO_NAME_SIZE_BYTES];
132 char model_name[HWINFO_NAME_SIZE_BYTES];
133 u32 supported_clocks;
134 u32 amdtp_rx_pcm_channels;
135 u32 amdtp_tx_pcm_channels;
136 u32 phys_out;
137 u32 phys_in;
138 u32 phys_out_grp_count;
139 struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
140 u32 phys_in_grp_count;
141 struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
142 u32 midi_out_ports;
143 u32 midi_in_ports;
144 u32 max_sample_rate;
145 u32 min_sample_rate;
146 u32 dsp_version;
147 u32 arm_version;
148 u32 mixer_playback_channels;
149 u32 mixer_capture_channels;
150 u32 fpga_version;
151 u32 amdtp_rx_pcm_channels_2x;
152 u32 amdtp_tx_pcm_channels_2x;
153 u32 amdtp_rx_pcm_channels_4x;
154 u32 amdtp_tx_pcm_channels_4x;
155 u32 reserved[16];
156} __packed;
157enum snd_efw_grp_type {
158 SND_EFW_CH_TYPE_ANALOG = 0,
159 SND_EFW_CH_TYPE_SPDIF = 1,
160 SND_EFW_CH_TYPE_ADAT = 2,
161 SND_EFW_CH_TYPE_SPDIF_OR_ADAT = 3,
162 SND_EFW_CH_TYPE_ANALOG_MIRRORING = 4,
163 SND_EFW_CH_TYPE_HEADPHONES = 5,
164 SND_EFW_CH_TYPE_I2S = 6,
165 SND_EFW_CH_TYPE_GUITAR = 7,
166 SND_EFW_CH_TYPE_PIEZO_GUITAR = 8,
167 SND_EFW_CH_TYPE_GUITAR_STRING = 9,
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900168 SND_EFW_CH_TYPE_DUMMY
169};
170struct snd_efw_phys_meters {
171 u32 status; /* guitar state/midi signal/clock input detect */
172 u32 reserved0;
173 u32 reserved1;
174 u32 reserved2;
175 u32 reserved3;
176 u32 out_meters;
177 u32 in_meters;
178 u32 reserved4;
179 u32 reserved5;
Gustavo A. R. Silva89ebe492020-05-07 13:52:45 -0500180 u32 values[];
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900181} __packed;
182enum snd_efw_clock_source {
183 SND_EFW_CLOCK_SOURCE_INTERNAL = 0,
184 SND_EFW_CLOCK_SOURCE_SYTMATCH = 1,
185 SND_EFW_CLOCK_SOURCE_WORDCLOCK = 2,
186 SND_EFW_CLOCK_SOURCE_SPDIF = 3,
187 SND_EFW_CLOCK_SOURCE_ADAT_1 = 4,
188 SND_EFW_CLOCK_SOURCE_ADAT_2 = 5,
189 SND_EFW_CLOCK_SOURCE_CONTINUOUS = 6 /* internal variable clock */
190};
191enum snd_efw_transport_mode {
192 SND_EFW_TRANSPORT_MODE_WINDOWS = 0,
193 SND_EFW_TRANSPORT_MODE_IEC61883 = 1,
194};
195int snd_efw_command_set_resp_addr(struct snd_efw *efw,
196 u16 addr_high, u32 addr_low);
Takashi Sakamoto93219d02014-05-28 00:14:39 +0900197int snd_efw_command_set_tx_mode(struct snd_efw *efw,
198 enum snd_efw_transport_mode mode);
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900199int snd_efw_command_get_hwinfo(struct snd_efw *efw,
200 struct snd_efw_hwinfo *hwinfo);
201int snd_efw_command_get_phys_meters(struct snd_efw *efw,
202 struct snd_efw_phys_meters *meters,
203 unsigned int len);
204int snd_efw_command_get_clock_source(struct snd_efw *efw,
205 enum snd_efw_clock_source *source);
206int snd_efw_command_get_sampling_rate(struct snd_efw *efw, unsigned int *rate);
207int snd_efw_command_set_sampling_rate(struct snd_efw *efw, unsigned int rate);
208
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900209int snd_efw_stream_init_duplex(struct snd_efw *efw);
Takashi Sakamotodd20e682019-10-07 20:05:18 +0900210int snd_efw_stream_reserve_duplex(struct snd_efw *efw, unsigned int rate,
Takashi Sakamoto659c6af2019-10-18 00:54:15 +0900211 unsigned int frames_per_period,
212 unsigned int frames_per_buffer);
Takashi Sakamoto3d725062019-06-12 17:44:11 +0900213int snd_efw_stream_start_duplex(struct snd_efw *efw);
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900214void snd_efw_stream_stop_duplex(struct snd_efw *efw);
215void snd_efw_stream_update_duplex(struct snd_efw *efw);
216void snd_efw_stream_destroy_duplex(struct snd_efw *efw);
Takashi Sakamoto594ddce2014-04-25 22:45:12 +0900217void snd_efw_stream_lock_changed(struct snd_efw *efw);
218int snd_efw_stream_lock_try(struct snd_efw *efw);
219void snd_efw_stream_lock_release(struct snd_efw *efw);
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900220
Takashi Sakamoto6a226832014-04-25 22:45:08 +0900221void snd_efw_proc_init(struct snd_efw *efw);
222
Takashi Sakamotoa63d3ff2014-04-25 22:45:09 +0900223int snd_efw_create_midi_devices(struct snd_efw *efw);
224
Takashi Sakamotoaa02bb62014-04-25 22:45:11 +0900225int snd_efw_create_pcm_devices(struct snd_efw *efw);
226int snd_efw_get_multiplier_mode(unsigned int sampling_rate, unsigned int *mode);
227
Takashi Sakamoto594ddce2014-04-25 22:45:12 +0900228int snd_efw_create_hwdep_device(struct snd_efw *efw);
229
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900230#define SND_EFW_DEV_ENTRY(vendor, model) \
231{ \
232 .match_flags = IEEE1394_MATCH_VENDOR_ID | \
233 IEEE1394_MATCH_MODEL_ID, \
234 .vendor_id = vendor,\
235 .model_id = model \
236}
237
238#endif