xref: /openbmc/linux/sound/firewire/oxfw/oxfw.h (revision a4ce4337)
1da607e19SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2e2786ca6STakashi Sakamoto /*
3e2786ca6STakashi Sakamoto  * oxfw.h - a part of driver for OXFW970/971 based devices
4e2786ca6STakashi Sakamoto  *
5e2786ca6STakashi Sakamoto  * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
6e2786ca6STakashi Sakamoto  */
7e2786ca6STakashi Sakamoto 
8e2786ca6STakashi Sakamoto #include <linux/device.h>
9e2786ca6STakashi Sakamoto #include <linux/firewire.h>
10e2786ca6STakashi Sakamoto #include <linux/firewire-constants.h>
11e2786ca6STakashi Sakamoto #include <linux/module.h>
12e2786ca6STakashi Sakamoto #include <linux/mod_devicetable.h>
13e2786ca6STakashi Sakamoto #include <linux/mutex.h>
14e2786ca6STakashi Sakamoto #include <linux/slab.h>
158985f4acSTakashi Sakamoto #include <linux/compat.h>
16174cd4b1SIngo Molnar #include <linux/sched/signal.h>
17e2786ca6STakashi Sakamoto 
18e2786ca6STakashi Sakamoto #include <sound/control.h>
19e2786ca6STakashi Sakamoto #include <sound/core.h>
20e2786ca6STakashi Sakamoto #include <sound/initval.h>
21e2786ca6STakashi Sakamoto #include <sound/pcm.h>
22e2786ca6STakashi Sakamoto #include <sound/pcm_params.h>
233c96101fSTakashi Sakamoto #include <sound/info.h>
2405588d34STakashi Sakamoto #include <sound/rawmidi.h>
258985f4acSTakashi Sakamoto #include <sound/firewire.h>
268985f4acSTakashi Sakamoto #include <sound/hwdep.h>
27e2786ca6STakashi Sakamoto 
28e2786ca6STakashi Sakamoto #include "../lib.h"
29e2786ca6STakashi Sakamoto #include "../fcp.h"
30e2786ca6STakashi Sakamoto #include "../packets-buffer.h"
31e2786ca6STakashi Sakamoto #include "../iso-resources.h"
325955815eSTakashi Sakamoto #include "../amdtp-am824.h"
33e2786ca6STakashi Sakamoto #include "../cmp.h"
34e2786ca6STakashi Sakamoto 
35a092f000STakashi Sakamoto enum snd_oxfw_quirk {
36a092f000STakashi Sakamoto 	// Postpone transferring packets during handling asynchronous transaction. As a result,
37a092f000STakashi Sakamoto 	// next isochronous packet includes more events than one packet can include.
38a092f000STakashi Sakamoto 	SND_OXFW_QUIRK_JUMBO_PAYLOAD = 0x01,
39a6f91693STakashi Sakamoto 	// The dbs field of CIP header in tx packet is wrong.
40a6f91693STakashi Sakamoto 	SND_OXFW_QUIRK_WRONG_DBS = 0x02,
4107a35edcSTakashi Sakamoto 	// Blocking transmission mode is used.
4207a35edcSTakashi Sakamoto 	SND_OXFW_QUIRK_BLOCKING_TRANSMISSION = 0x04,
43b566e972STakashi Sakamoto 	// Stanton SCS1.d and SCS1.m support unique transaction.
44b566e972STakashi Sakamoto 	SND_OXFW_QUIRK_SCS_TRANSACTION = 0x08,
4567bb66d3STakashi Sakamoto 	// Apogee Duet FireWire ignores data blocks in packet with NO_INFO for audio data
4667bb66d3STakashi Sakamoto 	// processing, while output level meter moves. Any value in syt field of packet takes
4767bb66d3STakashi Sakamoto 	// the device to process audio data even if the value is invalid in a point of
4867bb66d3STakashi Sakamoto 	// IEC 61883-1/6.
4967bb66d3STakashi Sakamoto 	SND_OXFW_QUIRK_IGNORE_NO_INFO_PACKET = 0x10,
50*a4ce4337STakashi Sakamoto 	// Loud Technologies Mackie Onyx 1640i seems to configure OXFW971 ASIC so that it decides
51*a4ce4337STakashi Sakamoto 	// event frequency according to events in received isochronous packets. The device looks to
52*a4ce4337STakashi Sakamoto 	// performs media clock recovery voluntarily. In the recovery, the packets with NO_INFO
53*a4ce4337STakashi Sakamoto 	// are ignored, thus driver should transfer packets with timestamp.
54*a4ce4337STakashi Sakamoto 	SND_OXFW_QUIRK_VOLUNTARY_RECOVERY = 0x20,
55a092f000STakashi Sakamoto };
56a092f000STakashi Sakamoto 
575cd1d3f4STakashi Sakamoto /* This is an arbitrary number for convinience. */
585cd1d3f4STakashi Sakamoto #define	SND_OXFW_STREAM_FORMAT_ENTRIES	10
59e2786ca6STakashi Sakamoto struct snd_oxfw {
60e2786ca6STakashi Sakamoto 	struct snd_card *card;
61e2786ca6STakashi Sakamoto 	struct fw_unit *unit;
62e2786ca6STakashi Sakamoto 	struct mutex mutex;
6305588d34STakashi Sakamoto 	spinlock_t lock;
645cd1d3f4STakashi Sakamoto 
65a092f000STakashi Sakamoto 	// The combination of snd_oxfw_quirk enumeration-constants.
66a092f000STakashi Sakamoto 	unsigned int quirks;
67b0ac0009STakashi Sakamoto 	bool has_output;
6806a42a74STakashi Sakamoto 	bool has_input;
69b0ac0009STakashi Sakamoto 	u8 *tx_stream_formats[SND_OXFW_STREAM_FORMAT_ENTRIES];
705cd1d3f4STakashi Sakamoto 	u8 *rx_stream_formats[SND_OXFW_STREAM_FORMAT_ENTRIES];
715cd1d3f4STakashi Sakamoto 	bool assumed;
72b0ac0009STakashi Sakamoto 	struct cmp_connection out_conn;
73e2786ca6STakashi Sakamoto 	struct cmp_connection in_conn;
74b0ac0009STakashi Sakamoto 	struct amdtp_stream tx_stream;
75e2786ca6STakashi Sakamoto 	struct amdtp_stream rx_stream;
764a0a0472STakashi Sakamoto 	unsigned int substreams_count;
775cd1d3f4STakashi Sakamoto 
7805588d34STakashi Sakamoto 	unsigned int midi_input_ports;
7905588d34STakashi Sakamoto 	unsigned int midi_output_ports;
8005588d34STakashi Sakamoto 
818985f4acSTakashi Sakamoto 	int dev_lock_count;
828985f4acSTakashi Sakamoto 	bool dev_lock_changed;
838985f4acSTakashi Sakamoto 	wait_queue_head_t hwdep_wait;
8427e66635STakashi Sakamoto 
85c582cc66STakashi Sakamoto 	void *spec;
86ac5d7786STakashi Sakamoto 
87ac5d7786STakashi Sakamoto 	struct amdtp_domain domain;
88e2786ca6STakashi Sakamoto };
89e2786ca6STakashi Sakamoto 
905b59d809STakashi Sakamoto /*
915b59d809STakashi Sakamoto  * AV/C Stream Format Information Specification 1.1 Working Draft
925b59d809STakashi Sakamoto  * (Apr 2005, 1394TA)
935b59d809STakashi Sakamoto  */
945b59d809STakashi Sakamoto int avc_stream_set_format(struct fw_unit *unit, enum avc_general_plug_dir dir,
955b59d809STakashi Sakamoto 			  unsigned int pid, u8 *format, unsigned int len);
965b59d809STakashi Sakamoto int avc_stream_get_format(struct fw_unit *unit,
975b59d809STakashi Sakamoto 			  enum avc_general_plug_dir dir, unsigned int pid,
985b59d809STakashi Sakamoto 			  u8 *buf, unsigned int *len, unsigned int eid);
995b59d809STakashi Sakamoto static inline int
avc_stream_get_format_single(struct fw_unit * unit,enum avc_general_plug_dir dir,unsigned int pid,u8 * buf,unsigned int * len)1005b59d809STakashi Sakamoto avc_stream_get_format_single(struct fw_unit *unit,
1015b59d809STakashi Sakamoto 			     enum avc_general_plug_dir dir, unsigned int pid,
1025b59d809STakashi Sakamoto 			     u8 *buf, unsigned int *len)
1035b59d809STakashi Sakamoto {
1045b59d809STakashi Sakamoto 	return avc_stream_get_format(unit, dir, pid, buf, len, 0xff);
1055b59d809STakashi Sakamoto }
1065b59d809STakashi Sakamoto static inline int
avc_stream_get_format_list(struct fw_unit * unit,enum avc_general_plug_dir dir,unsigned int pid,u8 * buf,unsigned int * len,unsigned int eid)1075b59d809STakashi Sakamoto avc_stream_get_format_list(struct fw_unit *unit,
1085b59d809STakashi Sakamoto 			   enum avc_general_plug_dir dir, unsigned int pid,
1095b59d809STakashi Sakamoto 			   u8 *buf, unsigned int *len,
1105b59d809STakashi Sakamoto 			   unsigned int eid)
1115b59d809STakashi Sakamoto {
1125b59d809STakashi Sakamoto 	return avc_stream_get_format(unit, dir, pid, buf, len, eid);
1135b59d809STakashi Sakamoto }
1145b59d809STakashi Sakamoto 
1155b59d809STakashi Sakamoto /*
1165b59d809STakashi Sakamoto  * AV/C Digital Interface Command Set General Specification 4.2
1175b59d809STakashi Sakamoto  * (Sep 2004, 1394TA)
1185b59d809STakashi Sakamoto  */
1195b59d809STakashi Sakamoto int avc_general_inquiry_sig_fmt(struct fw_unit *unit, unsigned int rate,
1205b59d809STakashi Sakamoto 				enum avc_general_plug_dir dir,
1215b59d809STakashi Sakamoto 				unsigned short pid);
1225b59d809STakashi Sakamoto 
123779f0dbaSTakashi Sakamoto int snd_oxfw_stream_init_duplex(struct snd_oxfw *oxfw);
1244f380d00STakashi Sakamoto int snd_oxfw_stream_reserve_duplex(struct snd_oxfw *oxfw,
125b0ac0009STakashi Sakamoto 				   struct amdtp_stream *stream,
1261d6a722cSTakashi Sakamoto 				   unsigned int rate, unsigned int pcm_channels,
1273299d2a0STakashi Sakamoto 				   unsigned int frames_per_period,
1283299d2a0STakashi Sakamoto 				   unsigned int frames_per_buffer);
1294f380d00STakashi Sakamoto int snd_oxfw_stream_start_duplex(struct snd_oxfw *oxfw);
130779f0dbaSTakashi Sakamoto void snd_oxfw_stream_stop_duplex(struct snd_oxfw *oxfw);
131779f0dbaSTakashi Sakamoto void snd_oxfw_stream_destroy_duplex(struct snd_oxfw *oxfw);
132779f0dbaSTakashi Sakamoto void snd_oxfw_stream_update_duplex(struct snd_oxfw *oxfw);
1333713d93aSTakashi Sakamoto 
1345cd1d3f4STakashi Sakamoto struct snd_oxfw_stream_formation {
1355cd1d3f4STakashi Sakamoto 	unsigned int rate;
1365cd1d3f4STakashi Sakamoto 	unsigned int pcm;
1375cd1d3f4STakashi Sakamoto 	unsigned int midi;
1385cd1d3f4STakashi Sakamoto };
1395cd1d3f4STakashi Sakamoto int snd_oxfw_stream_parse_format(u8 *format,
1405cd1d3f4STakashi Sakamoto 				 struct snd_oxfw_stream_formation *formation);
1415cd1d3f4STakashi Sakamoto int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw,
1425cd1d3f4STakashi Sakamoto 				enum avc_general_plug_dir dir,
1435cd1d3f4STakashi Sakamoto 				struct snd_oxfw_stream_formation *formation);
144b0ac0009STakashi Sakamoto 
1455cd1d3f4STakashi Sakamoto int snd_oxfw_stream_discover(struct snd_oxfw *oxfw);
1465cd1d3f4STakashi Sakamoto 
1478985f4acSTakashi Sakamoto void snd_oxfw_stream_lock_changed(struct snd_oxfw *oxfw);
1488985f4acSTakashi Sakamoto int snd_oxfw_stream_lock_try(struct snd_oxfw *oxfw);
1498985f4acSTakashi Sakamoto void snd_oxfw_stream_lock_release(struct snd_oxfw *oxfw);
1508985f4acSTakashi Sakamoto 
1513713d93aSTakashi Sakamoto int snd_oxfw_create_pcm(struct snd_oxfw *oxfw);
15231514bfbSTakashi Sakamoto 
1533c96101fSTakashi Sakamoto void snd_oxfw_proc_init(struct snd_oxfw *oxfw);
15405588d34STakashi Sakamoto 
15505588d34STakashi Sakamoto int snd_oxfw_create_midi(struct snd_oxfw *oxfw);
1568985f4acSTakashi Sakamoto 
1578985f4acSTakashi Sakamoto int snd_oxfw_create_hwdep(struct snd_oxfw *oxfw);
15829aa09acSTakashi Sakamoto 
1593e2f4570STakashi Sakamoto int snd_oxfw_add_spkr(struct snd_oxfw *oxfw, bool is_lacie);
1603f47152aSTakashi Sakamoto int snd_oxfw_scs1x_add(struct snd_oxfw *oxfw);
161e3315b43STakashi Sakamoto void snd_oxfw_scs1x_update(struct snd_oxfw *oxfw);
162