162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
262306a36Sopenharmony_ci#ifndef _UAPI_SOUND_FIREWIRE_H_INCLUDED
362306a36Sopenharmony_ci#define _UAPI_SOUND_FIREWIRE_H_INCLUDED
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/ioctl.h>
662306a36Sopenharmony_ci#include <linux/types.h>
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci/* events can be read() from the hwdep device */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#define SNDRV_FIREWIRE_EVENT_LOCK_STATUS	0x000010cc
1162306a36Sopenharmony_ci#define SNDRV_FIREWIRE_EVENT_DICE_NOTIFICATION	0xd1ce004e
1262306a36Sopenharmony_ci#define SNDRV_FIREWIRE_EVENT_EFW_RESPONSE	0x4e617475
1362306a36Sopenharmony_ci#define SNDRV_FIREWIRE_EVENT_DIGI00X_MESSAGE	0x746e736c
1462306a36Sopenharmony_ci#define SNDRV_FIREWIRE_EVENT_MOTU_NOTIFICATION	0x64776479
1562306a36Sopenharmony_ci#define SNDRV_FIREWIRE_EVENT_TASCAM_CONTROL	0x7473636d
1662306a36Sopenharmony_ci#define SNDRV_FIREWIRE_EVENT_MOTU_REGISTER_DSP_CHANGE	0x4d545244
1762306a36Sopenharmony_ci#define SNDRV_FIREWIRE_EVENT_FF400_MESSAGE	0x4f6c6761
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_cistruct snd_firewire_event_common {
2062306a36Sopenharmony_ci	unsigned int type; /* SNDRV_FIREWIRE_EVENT_xxx */
2162306a36Sopenharmony_ci};
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_cistruct snd_firewire_event_lock_status {
2462306a36Sopenharmony_ci	unsigned int type;
2562306a36Sopenharmony_ci	unsigned int status; /* 0/1 = unlocked/locked */
2662306a36Sopenharmony_ci};
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_cistruct snd_firewire_event_dice_notification {
2962306a36Sopenharmony_ci	unsigned int type;
3062306a36Sopenharmony_ci	unsigned int notification; /* DICE-specific bits */
3162306a36Sopenharmony_ci};
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#define SND_EFW_TRANSACTION_USER_SEQNUM_MAX	((__u32)((__u16)~0) - 1)
3462306a36Sopenharmony_ci/* each field should be in big endian */
3562306a36Sopenharmony_cistruct snd_efw_transaction {
3662306a36Sopenharmony_ci	__be32 length;
3762306a36Sopenharmony_ci	__be32 version;
3862306a36Sopenharmony_ci	__be32 seqnum;
3962306a36Sopenharmony_ci	__be32 category;
4062306a36Sopenharmony_ci	__be32 command;
4162306a36Sopenharmony_ci	__be32 status;
4262306a36Sopenharmony_ci	__be32 params[];
4362306a36Sopenharmony_ci};
4462306a36Sopenharmony_cistruct snd_firewire_event_efw_response {
4562306a36Sopenharmony_ci	unsigned int type;
4662306a36Sopenharmony_ci	__be32 response[];	/* some responses */
4762306a36Sopenharmony_ci};
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_cistruct snd_firewire_event_digi00x_message {
5062306a36Sopenharmony_ci	unsigned int type;
5162306a36Sopenharmony_ci	__u32 message;	/* Digi00x-specific message */
5262306a36Sopenharmony_ci};
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistruct snd_firewire_event_motu_notification {
5562306a36Sopenharmony_ci	unsigned int type;
5662306a36Sopenharmony_ci	__u32 message;	/* MOTU-specific bits. */
5762306a36Sopenharmony_ci};
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_cistruct snd_firewire_tascam_change {
6062306a36Sopenharmony_ci	unsigned int index;
6162306a36Sopenharmony_ci	__be32 before;
6262306a36Sopenharmony_ci	__be32 after;
6362306a36Sopenharmony_ci};
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_cistruct snd_firewire_event_tascam_control {
6662306a36Sopenharmony_ci	unsigned int type;
6762306a36Sopenharmony_ci	struct snd_firewire_tascam_change changes[];
6862306a36Sopenharmony_ci};
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_cistruct snd_firewire_event_motu_register_dsp_change {
7162306a36Sopenharmony_ci	unsigned int type;
7262306a36Sopenharmony_ci	__u32 count;		/* The number of changes. */
7362306a36Sopenharmony_ci	__u32 changes[];	/* Encoded event for change of register DSP. */
7462306a36Sopenharmony_ci};
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci/**
7762306a36Sopenharmony_ci * struct snd_firewire_event_ff400_message - the container for message from Fireface 400 when
7862306a36Sopenharmony_ci *					     operating hardware knob.
7962306a36Sopenharmony_ci *
8062306a36Sopenharmony_ci * @type: Fixed to SNDRV_FIREWIRE_EVENT_FF400_MESSAGE.
8162306a36Sopenharmony_ci * @message_count: The number of messages.
8262306a36Sopenharmony_ci * @messages.message: The messages expressing hardware knob operation.
8362306a36Sopenharmony_ci * @messages.tstamp: The isochronous cycle at which the request subaction of asynchronous
8462306a36Sopenharmony_ci *		     transaction was sent to deliver the message. It has 16 bit unsigned integer
8562306a36Sopenharmony_ci *		     value. The higher 3 bits of value expresses the lower three bits of second
8662306a36Sopenharmony_ci *		     field in the format of CYCLE_TIME, up to 7. The rest 13 bits expresses cycle
8762306a36Sopenharmony_ci *		     field up to 7999.
8862306a36Sopenharmony_ci *
8962306a36Sopenharmony_ci * The structure expresses message transmitted by Fireface 400 when operating hardware knob.
9062306a36Sopenharmony_ci */
9162306a36Sopenharmony_cistruct snd_firewire_event_ff400_message {
9262306a36Sopenharmony_ci	unsigned int type;
9362306a36Sopenharmony_ci	unsigned int message_count;
9462306a36Sopenharmony_ci	struct {
9562306a36Sopenharmony_ci		__u32 message;
9662306a36Sopenharmony_ci		__u32 tstamp;
9762306a36Sopenharmony_ci	} messages[];
9862306a36Sopenharmony_ci};
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ciunion snd_firewire_event {
10162306a36Sopenharmony_ci	struct snd_firewire_event_common            common;
10262306a36Sopenharmony_ci	struct snd_firewire_event_lock_status       lock_status;
10362306a36Sopenharmony_ci	struct snd_firewire_event_dice_notification dice_notification;
10462306a36Sopenharmony_ci	struct snd_firewire_event_efw_response      efw_response;
10562306a36Sopenharmony_ci	struct snd_firewire_event_digi00x_message   digi00x_message;
10662306a36Sopenharmony_ci	struct snd_firewire_event_tascam_control    tascam_control;
10762306a36Sopenharmony_ci	struct snd_firewire_event_motu_notification motu_notification;
10862306a36Sopenharmony_ci	struct snd_firewire_event_motu_register_dsp_change motu_register_dsp_change;
10962306a36Sopenharmony_ci	struct snd_firewire_event_ff400_message	    ff400_message;
11062306a36Sopenharmony_ci};
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci#define SNDRV_FIREWIRE_IOCTL_GET_INFO _IOR('H', 0xf8, struct snd_firewire_get_info)
11462306a36Sopenharmony_ci#define SNDRV_FIREWIRE_IOCTL_LOCK      _IO('H', 0xf9)
11562306a36Sopenharmony_ci#define SNDRV_FIREWIRE_IOCTL_UNLOCK    _IO('H', 0xfa)
11662306a36Sopenharmony_ci#define SNDRV_FIREWIRE_IOCTL_TASCAM_STATE _IOR('H', 0xfb, struct snd_firewire_tascam_state)
11762306a36Sopenharmony_ci#define SNDRV_FIREWIRE_IOCTL_MOTU_REGISTER_DSP_METER	_IOR('H', 0xfc, struct snd_firewire_motu_register_dsp_meter)
11862306a36Sopenharmony_ci#define SNDRV_FIREWIRE_IOCTL_MOTU_COMMAND_DSP_METER	_IOR('H', 0xfd, struct snd_firewire_motu_command_dsp_meter)
11962306a36Sopenharmony_ci#define SNDRV_FIREWIRE_IOCTL_MOTU_REGISTER_DSP_PARAMETER	_IOR('H', 0xfe, struct snd_firewire_motu_register_dsp_parameter)
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci#define SNDRV_FIREWIRE_TYPE_DICE	1
12262306a36Sopenharmony_ci#define SNDRV_FIREWIRE_TYPE_FIREWORKS	2
12362306a36Sopenharmony_ci#define SNDRV_FIREWIRE_TYPE_BEBOB	3
12462306a36Sopenharmony_ci#define SNDRV_FIREWIRE_TYPE_OXFW	4
12562306a36Sopenharmony_ci#define SNDRV_FIREWIRE_TYPE_DIGI00X	5
12662306a36Sopenharmony_ci#define SNDRV_FIREWIRE_TYPE_TASCAM	6
12762306a36Sopenharmony_ci#define SNDRV_FIREWIRE_TYPE_MOTU	7
12862306a36Sopenharmony_ci#define SNDRV_FIREWIRE_TYPE_FIREFACE	8
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_cistruct snd_firewire_get_info {
13162306a36Sopenharmony_ci	unsigned int type; /* SNDRV_FIREWIRE_TYPE_xxx */
13262306a36Sopenharmony_ci	unsigned int card; /* same as fw_cdev_get_info.card */
13362306a36Sopenharmony_ci	unsigned char guid[8];
13462306a36Sopenharmony_ci	char device_name[16]; /* device node in /dev */
13562306a36Sopenharmony_ci};
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci/*
13862306a36Sopenharmony_ci * SNDRV_FIREWIRE_IOCTL_LOCK prevents the driver from streaming.
13962306a36Sopenharmony_ci * Returns -EBUSY if the driver is already streaming.
14062306a36Sopenharmony_ci */
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci#define SNDRV_FIREWIRE_TASCAM_STATE_COUNT	64
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_cistruct snd_firewire_tascam_state {
14562306a36Sopenharmony_ci	__be32 data[SNDRV_FIREWIRE_TASCAM_STATE_COUNT];
14662306a36Sopenharmony_ci};
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci/*
14962306a36Sopenharmony_ci * In below MOTU models, software is allowed to control their DSP by accessing to registers.
15062306a36Sopenharmony_ci *  - 828mk2
15162306a36Sopenharmony_ci *  - 896hd
15262306a36Sopenharmony_ci *  - Traveler
15362306a36Sopenharmony_ci *  - 8 pre
15462306a36Sopenharmony_ci *  - Ultralite
15562306a36Sopenharmony_ci *  - 4 pre
15662306a36Sopenharmony_ci *  - Audio Express
15762306a36Sopenharmony_ci *
15862306a36Sopenharmony_ci * On the other hand, the status of DSP is split into specific messages included in the sequence of
15962306a36Sopenharmony_ci * isochronous packet. ALSA firewire-motu driver gathers the messages and allow userspace applications
16062306a36Sopenharmony_ci * to read it via ioctl. In 828mk2, 896hd, and Traveler, hardware meter for all of physical inputs
16162306a36Sopenharmony_ci * are put into the message, while one pair of physical outputs is selected. The selection is done by
16262306a36Sopenharmony_ci * LSB one byte in asynchronous write quadlet transaction to 0x'ffff'f000'0b2c.
16362306a36Sopenharmony_ci *
16462306a36Sopenharmony_ci * I note that V3HD/V4HD uses asynchronous transaction for the purpose. The destination address is
16562306a36Sopenharmony_ci * registered to 0x'ffff'f000'0b38 and '0b3c by asynchronous write quadlet request. The size of
16662306a36Sopenharmony_ci * message differs between 23 and 51 quadlets. For the case, the number of mixer bus can be extended
16762306a36Sopenharmony_ci * up to 12.
16862306a36Sopenharmony_ci */
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci#define SNDRV_FIREWIRE_MOTU_REGISTER_DSP_METER_INPUT_COUNT	24
17162306a36Sopenharmony_ci#define SNDRV_FIREWIRE_MOTU_REGISTER_DSP_METER_OUTPUT_COUNT	24
17262306a36Sopenharmony_ci#define SNDRV_FIREWIRE_MOTU_REGISTER_DSP_METER_COUNT \
17362306a36Sopenharmony_ci	(SNDRV_FIREWIRE_MOTU_REGISTER_DSP_METER_INPUT_COUNT + SNDRV_FIREWIRE_MOTU_REGISTER_DSP_METER_OUTPUT_COUNT)
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci/**
17662306a36Sopenharmony_ci * struct snd_firewire_motu_register_dsp_meter - the container for meter information in DSP
17762306a36Sopenharmony_ci *						 controlled by register access
17862306a36Sopenharmony_ci * @data: Signal level meters. The mapping between position and input/output channel is
17962306a36Sopenharmony_ci *	  model-dependent.
18062306a36Sopenharmony_ci *
18162306a36Sopenharmony_ci * The structure expresses the part of DSP status for hardware meter. The u8 storage includes linear
18262306a36Sopenharmony_ci * value for audio signal level between 0x00 and 0x7f.
18362306a36Sopenharmony_ci */
18462306a36Sopenharmony_cistruct snd_firewire_motu_register_dsp_meter {
18562306a36Sopenharmony_ci	__u8 data[SNDRV_FIREWIRE_MOTU_REGISTER_DSP_METER_COUNT];
18662306a36Sopenharmony_ci};
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci#define SNDRV_FIREWIRE_MOTU_REGISTER_DSP_MIXER_COUNT		4
18962306a36Sopenharmony_ci#define SNDRV_FIREWIRE_MOTU_REGISTER_DSP_MIXER_SRC_COUNT	20
19062306a36Sopenharmony_ci#define SNDRV_FIREWIRE_MOTU_REGISTER_DSP_INPUT_COUNT		10
19162306a36Sopenharmony_ci#define SNDRV_FIREWIRE_MOTU_REGISTER_DSP_ALIGNED_INPUT_COUNT	(SNDRV_FIREWIRE_MOTU_REGISTER_DSP_INPUT_COUNT + 2)
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci/**
19462306a36Sopenharmony_ci * snd_firewire_motu_register_dsp_parameter - the container for parameters of DSP controlled
19562306a36Sopenharmony_ci *					      by register access.
19662306a36Sopenharmony_ci * @mixer.source.gain: The gain of source to mixer.
19762306a36Sopenharmony_ci * @mixer.source.pan: The L/R balance of source to mixer.
19862306a36Sopenharmony_ci * @mixer.source.flag: The flag of source to mixer, including mute, solo.
19962306a36Sopenharmony_ci * @mixer.source.paired_balance: The L/R balance of paired source to mixer, only for 4 pre and
20062306a36Sopenharmony_ci *				 Audio Express.
20162306a36Sopenharmony_ci * @mixer.source.paired_width: The width of paired source to mixer, only for 4 pre and
20262306a36Sopenharmony_ci *			       Audio Express.
20362306a36Sopenharmony_ci * @mixer.output.paired_volume: The volume of paired output from mixer.
20462306a36Sopenharmony_ci * @mixer.output.paired_flag: The flag of paired output from mixer.
20562306a36Sopenharmony_ci * @output.main_paired_volume: The volume of paired main output.
20662306a36Sopenharmony_ci * @output.hp_paired_volume: The volume of paired hp output.
20762306a36Sopenharmony_ci * @output.hp_paired_assignment: The source assigned to paired hp output.
20862306a36Sopenharmony_ci * @output.reserved: Padding for 32 bit alignment for future extension.
20962306a36Sopenharmony_ci * @line_input.boost_flag: The flags of boost for line inputs, only for 828mk2 and Traveler.
21062306a36Sopenharmony_ci * @line_input.nominal_level_flag: The flags of nominal level for line inputs, only for 828mk2 and
21162306a36Sopenharmony_ci *				   Traveler.
21262306a36Sopenharmony_ci * @line_input.reserved: Padding for 32 bit alignment for future extension.
21362306a36Sopenharmony_ci * @input.gain_and_invert: The value including gain and invert for input, only for Ultralite, 4 pre
21462306a36Sopenharmony_ci *			   and Audio Express.
21562306a36Sopenharmony_ci * @input.flag: The flag of input; e.g. jack detection, phantom power, and pad, only for Ultralite,
21662306a36Sopenharmony_ci *		4 pre and Audio express.
21762306a36Sopenharmony_ci * @reserved: Padding so that the size of structure is kept to 512 byte, but for future extension.
21862306a36Sopenharmony_ci *
21962306a36Sopenharmony_ci * The structure expresses the set of parameters for DSP controlled by register access.
22062306a36Sopenharmony_ci */
22162306a36Sopenharmony_cistruct snd_firewire_motu_register_dsp_parameter {
22262306a36Sopenharmony_ci	struct {
22362306a36Sopenharmony_ci		struct {
22462306a36Sopenharmony_ci			__u8 gain[SNDRV_FIREWIRE_MOTU_REGISTER_DSP_MIXER_SRC_COUNT];
22562306a36Sopenharmony_ci			__u8 pan[SNDRV_FIREWIRE_MOTU_REGISTER_DSP_MIXER_SRC_COUNT];
22662306a36Sopenharmony_ci			__u8 flag[SNDRV_FIREWIRE_MOTU_REGISTER_DSP_MIXER_SRC_COUNT];
22762306a36Sopenharmony_ci			__u8 paired_balance[SNDRV_FIREWIRE_MOTU_REGISTER_DSP_MIXER_SRC_COUNT];
22862306a36Sopenharmony_ci			__u8 paired_width[SNDRV_FIREWIRE_MOTU_REGISTER_DSP_MIXER_SRC_COUNT];
22962306a36Sopenharmony_ci		} source[SNDRV_FIREWIRE_MOTU_REGISTER_DSP_MIXER_COUNT];
23062306a36Sopenharmony_ci		struct {
23162306a36Sopenharmony_ci			__u8 paired_volume[SNDRV_FIREWIRE_MOTU_REGISTER_DSP_MIXER_COUNT];
23262306a36Sopenharmony_ci			__u8 paired_flag[SNDRV_FIREWIRE_MOTU_REGISTER_DSP_MIXER_COUNT];
23362306a36Sopenharmony_ci		} output;
23462306a36Sopenharmony_ci	} mixer;
23562306a36Sopenharmony_ci	struct {
23662306a36Sopenharmony_ci		__u8 main_paired_volume;
23762306a36Sopenharmony_ci		__u8 hp_paired_volume;
23862306a36Sopenharmony_ci		__u8 hp_paired_assignment;
23962306a36Sopenharmony_ci		__u8 reserved[5];
24062306a36Sopenharmony_ci	} output;
24162306a36Sopenharmony_ci	struct {
24262306a36Sopenharmony_ci		__u8 boost_flag;
24362306a36Sopenharmony_ci		__u8 nominal_level_flag;
24462306a36Sopenharmony_ci		__u8 reserved[6];
24562306a36Sopenharmony_ci	} line_input;
24662306a36Sopenharmony_ci	struct {
24762306a36Sopenharmony_ci		__u8 gain_and_invert[SNDRV_FIREWIRE_MOTU_REGISTER_DSP_ALIGNED_INPUT_COUNT];
24862306a36Sopenharmony_ci		__u8 flag[SNDRV_FIREWIRE_MOTU_REGISTER_DSP_ALIGNED_INPUT_COUNT];
24962306a36Sopenharmony_ci	} input;
25062306a36Sopenharmony_ci	__u8 reserved[64];
25162306a36Sopenharmony_ci};
25262306a36Sopenharmony_ci
25362306a36Sopenharmony_ci/*
25462306a36Sopenharmony_ci * In below MOTU models, software is allowed to control their DSP by command in frame of
25562306a36Sopenharmony_ci * asynchronous transaction to 0x'ffff'0001'0000:
25662306a36Sopenharmony_ci *
25762306a36Sopenharmony_ci *  - 828 mk3 (FireWire only and Hybrid)
25862306a36Sopenharmony_ci *  - 896 mk3 (FireWire only and Hybrid)
25962306a36Sopenharmony_ci *  - Ultralite mk3 (FireWire only and Hybrid)
26062306a36Sopenharmony_ci *  - Traveler mk3
26162306a36Sopenharmony_ci *  - Track 16
26262306a36Sopenharmony_ci *
26362306a36Sopenharmony_ci * On the other hand, the states of hardware meter is split into specific messages included in the
26462306a36Sopenharmony_ci * sequence of isochronous packet. ALSA firewire-motu driver gathers the message and allow userspace
26562306a36Sopenharmony_ci * application to read it via ioctl.
26662306a36Sopenharmony_ci */
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ci#define SNDRV_FIREWIRE_MOTU_COMMAND_DSP_METER_COUNT	400
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_ci/**
27162306a36Sopenharmony_ci * struct snd_firewire_motu_command_dsp_meter - the container for meter information in DSP
27262306a36Sopenharmony_ci *						controlled by command
27362306a36Sopenharmony_ci * @data: Signal level meters. The mapping between position and signal channel is model-dependent.
27462306a36Sopenharmony_ci *
27562306a36Sopenharmony_ci * The structure expresses the part of DSP status for hardware meter. The 32 bit storage is
27662306a36Sopenharmony_ci * estimated to include IEEE 764 32 bit single precision floating point (binary32) value. It is
27762306a36Sopenharmony_ci * expected to be linear value (not logarithm) for audio signal level between 0.0 and +1.0.
27862306a36Sopenharmony_ci */
27962306a36Sopenharmony_cistruct snd_firewire_motu_command_dsp_meter {
28062306a36Sopenharmony_ci#ifdef __KERNEL__
28162306a36Sopenharmony_ci	__u32 data[SNDRV_FIREWIRE_MOTU_COMMAND_DSP_METER_COUNT];
28262306a36Sopenharmony_ci#else
28362306a36Sopenharmony_ci	float data[SNDRV_FIREWIRE_MOTU_COMMAND_DSP_METER_COUNT];
28462306a36Sopenharmony_ci#endif
28562306a36Sopenharmony_ci};
28662306a36Sopenharmony_ci
28762306a36Sopenharmony_ci#endif /* _UAPI_SOUND_FIREWIRE_H_INCLUDED */
288