blob: 07aa0d25e1002e171dde3cfed4cbcb94e009ec3c [file] [log] [blame]
Thomas Gleixnerda607e12019-05-29 16:57:59 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +09002/*
3 * oxfw.h - a part of driver for OXFW970/971 based devices
4 *
5 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +09006 */
7
8#include <linux/device.h>
9#include <linux/firewire.h>
10#include <linux/firewire-constants.h>
11#include <linux/module.h>
12#include <linux/mod_devicetable.h>
13#include <linux/mutex.h>
14#include <linux/slab.h>
Takashi Sakamoto8985f4a2014-12-09 00:10:49 +090015#include <linux/compat.h>
Ingo Molnar174cd4b2017-02-02 19:15:33 +010016#include <linux/sched/signal.h>
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +090017
18#include <sound/control.h>
19#include <sound/core.h>
20#include <sound/initval.h>
21#include <sound/pcm.h>
22#include <sound/pcm_params.h>
Takashi Sakamoto3c961012014-12-09 00:10:43 +090023#include <sound/info.h>
Takashi Sakamoto05588d32014-12-09 00:10:48 +090024#include <sound/rawmidi.h>
Takashi Sakamoto8985f4a2014-12-09 00:10:49 +090025#include <sound/firewire.h>
26#include <sound/hwdep.h>
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +090027
28#include "../lib.h"
29#include "../fcp.h"
30#include "../packets-buffer.h"
31#include "../iso-resources.h"
Takashi Sakamoto59558152015-09-19 11:21:55 +090032#include "../amdtp-am824.h"
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +090033#include "../cmp.h"
34
Takashi Sakamotoa092f002021-05-18 17:45:54 +090035enum snd_oxfw_quirk {
36 // Postpone transferring packets during handling asynchronous transaction. As a result,
37 // next isochronous packet includes more events than one packet can include.
38 SND_OXFW_QUIRK_JUMBO_PAYLOAD = 0x01,
39};
40
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +090041/* This is an arbitrary number for convinience. */
42#define SND_OXFW_STREAM_FORMAT_ENTRIES 10
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +090043struct snd_oxfw {
44 struct snd_card *card;
45 struct fw_unit *unit;
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +090046 struct mutex mutex;
Takashi Sakamoto05588d32014-12-09 00:10:48 +090047 spinlock_t lock;
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +090048
Takashi Sakamoto6c292302016-03-31 08:47:07 +090049 bool registered;
50 struct delayed_work dwork;
51
Takashi Sakamotoa092f002021-05-18 17:45:54 +090052 // The combination of snd_oxfw_quirk enumeration-constants.
53 unsigned int quirks;
Takashi Sakamoto13f3a462015-09-20 21:18:55 +090054 bool wrong_dbs;
Takashi Sakamotob0ac0002014-12-09 00:10:46 +090055 bool has_output;
Takashi Sakamoto06a42a72020-01-13 16:34:17 +090056 bool has_input;
Takashi Sakamotob0ac0002014-12-09 00:10:46 +090057 u8 *tx_stream_formats[SND_OXFW_STREAM_FORMAT_ENTRIES];
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +090058 u8 *rx_stream_formats[SND_OXFW_STREAM_FORMAT_ENTRIES];
59 bool assumed;
Takashi Sakamotob0ac0002014-12-09 00:10:46 +090060 struct cmp_connection out_conn;
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +090061 struct cmp_connection in_conn;
Takashi Sakamotob0ac0002014-12-09 00:10:46 +090062 struct amdtp_stream tx_stream;
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +090063 struct amdtp_stream rx_stream;
Takashi Sakamoto4a0a0472019-06-12 17:44:20 +090064 unsigned int substreams_count;
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +090065
Takashi Sakamoto05588d32014-12-09 00:10:48 +090066 unsigned int midi_input_ports;
67 unsigned int midi_output_ports;
68
Takashi Sakamoto8985f4a2014-12-09 00:10:49 +090069 int dev_lock_count;
70 bool dev_lock_changed;
71 wait_queue_head_t hwdep_wait;
Takashi Sakamoto27e66632015-12-15 23:56:20 +090072
73 const struct ieee1394_device_id *entry;
Takashi Sakamotoc582cc62015-12-16 20:37:54 +090074 void *spec;
Takashi Sakamotoac5d7782019-08-04 15:21:32 +090075
76 struct amdtp_domain domain;
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +090077};
78
Takashi Sakamoto5b59d8092014-12-09 00:10:41 +090079/*
80 * AV/C Stream Format Information Specification 1.1 Working Draft
81 * (Apr 2005, 1394TA)
82 */
83int avc_stream_set_format(struct fw_unit *unit, enum avc_general_plug_dir dir,
84 unsigned int pid, u8 *format, unsigned int len);
85int avc_stream_get_format(struct fw_unit *unit,
86 enum avc_general_plug_dir dir, unsigned int pid,
87 u8 *buf, unsigned int *len, unsigned int eid);
88static inline int
89avc_stream_get_format_single(struct fw_unit *unit,
90 enum avc_general_plug_dir dir, unsigned int pid,
91 u8 *buf, unsigned int *len)
92{
93 return avc_stream_get_format(unit, dir, pid, buf, len, 0xff);
94}
95static inline int
96avc_stream_get_format_list(struct fw_unit *unit,
97 enum avc_general_plug_dir dir, unsigned int pid,
98 u8 *buf, unsigned int *len,
99 unsigned int eid)
100{
101 return avc_stream_get_format(unit, dir, pid, buf, len, eid);
102}
103
104/*
105 * AV/C Digital Interface Command Set General Specification 4.2
106 * (Sep 2004, 1394TA)
107 */
108int avc_general_inquiry_sig_fmt(struct fw_unit *unit, unsigned int rate,
109 enum avc_general_plug_dir dir,
110 unsigned short pid);
111
Takashi Sakamoto779f0db2019-06-12 17:44:19 +0900112int snd_oxfw_stream_init_duplex(struct snd_oxfw *oxfw);
Takashi Sakamoto4f380d02019-06-12 17:44:21 +0900113int snd_oxfw_stream_reserve_duplex(struct snd_oxfw *oxfw,
114 struct amdtp_stream *stream,
Takashi Sakamoto1d6a7222019-10-07 20:05:19 +0900115 unsigned int rate, unsigned int pcm_channels,
Takashi Sakamoto3299d2a2019-10-18 00:54:16 +0900116 unsigned int frames_per_period,
117 unsigned int frames_per_buffer);
Takashi Sakamoto4f380d02019-06-12 17:44:21 +0900118int snd_oxfw_stream_start_duplex(struct snd_oxfw *oxfw);
Takashi Sakamoto779f0db2019-06-12 17:44:19 +0900119void snd_oxfw_stream_stop_duplex(struct snd_oxfw *oxfw);
120void snd_oxfw_stream_destroy_duplex(struct snd_oxfw *oxfw);
121void snd_oxfw_stream_update_duplex(struct snd_oxfw *oxfw);
Takashi Sakamoto3713d932014-11-29 00:59:28 +0900122
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +0900123struct snd_oxfw_stream_formation {
124 unsigned int rate;
125 unsigned int pcm;
126 unsigned int midi;
127};
128int snd_oxfw_stream_parse_format(u8 *format,
129 struct snd_oxfw_stream_formation *formation);
130int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw,
131 enum avc_general_plug_dir dir,
132 struct snd_oxfw_stream_formation *formation);
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900133
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +0900134int snd_oxfw_stream_discover(struct snd_oxfw *oxfw);
135
Takashi Sakamoto8985f4a2014-12-09 00:10:49 +0900136void snd_oxfw_stream_lock_changed(struct snd_oxfw *oxfw);
137int snd_oxfw_stream_lock_try(struct snd_oxfw *oxfw);
138void snd_oxfw_stream_lock_release(struct snd_oxfw *oxfw);
139
Takashi Sakamoto3713d932014-11-29 00:59:28 +0900140int snd_oxfw_create_pcm(struct snd_oxfw *oxfw);
Takashi Sakamoto31514bf2014-11-29 00:59:29 +0900141
Takashi Sakamoto3c961012014-12-09 00:10:43 +0900142void snd_oxfw_proc_init(struct snd_oxfw *oxfw);
Takashi Sakamoto05588d32014-12-09 00:10:48 +0900143
144int snd_oxfw_create_midi(struct snd_oxfw *oxfw);
Takashi Sakamoto8985f4a2014-12-09 00:10:49 +0900145
146int snd_oxfw_create_hwdep(struct snd_oxfw *oxfw);
Takashi Sakamoto29aa09a2015-12-15 23:56:18 +0900147
Takashi Sakamoto3e2f4572015-12-16 20:37:56 +0900148int snd_oxfw_add_spkr(struct snd_oxfw *oxfw, bool is_lacie);
Takashi Sakamoto3f471522015-12-22 09:15:39 +0900149int snd_oxfw_scs1x_add(struct snd_oxfw *oxfw);
Takashi Sakamotoe3315b42015-12-22 09:15:40 +0900150void snd_oxfw_scs1x_update(struct snd_oxfw *oxfw);