blob: fa2d7f9e2dc394e3ffdeb21ea40bea096bffec31 [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 Sakamoto5cd1d3f2014-12-09 00:10:42 +090035/* This is an arbitrary number for convinience. */
36#define SND_OXFW_STREAM_FORMAT_ENTRIES 10
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +090037struct snd_oxfw {
38 struct snd_card *card;
39 struct fw_unit *unit;
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +090040 struct mutex mutex;
Takashi Sakamoto05588d32014-12-09 00:10:48 +090041 spinlock_t lock;
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +090042
Takashi Sakamoto6c292302016-03-31 08:47:07 +090043 bool registered;
44 struct delayed_work dwork;
45
Takashi Sakamoto13f3a462015-09-20 21:18:55 +090046 bool wrong_dbs;
Takashi Sakamotob0ac0002014-12-09 00:10:46 +090047 bool has_output;
Takashi Sakamoto06a42a72020-01-13 16:34:17 +090048 bool has_input;
Takashi Sakamotob0ac0002014-12-09 00:10:46 +090049 u8 *tx_stream_formats[SND_OXFW_STREAM_FORMAT_ENTRIES];
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +090050 u8 *rx_stream_formats[SND_OXFW_STREAM_FORMAT_ENTRIES];
51 bool assumed;
Takashi Sakamotob0ac0002014-12-09 00:10:46 +090052 struct cmp_connection out_conn;
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +090053 struct cmp_connection in_conn;
Takashi Sakamotob0ac0002014-12-09 00:10:46 +090054 struct amdtp_stream tx_stream;
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +090055 struct amdtp_stream rx_stream;
Takashi Sakamoto4a0a0472019-06-12 17:44:20 +090056 unsigned int substreams_count;
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +090057
Takashi Sakamoto05588d32014-12-09 00:10:48 +090058 unsigned int midi_input_ports;
59 unsigned int midi_output_ports;
60
Takashi Sakamoto8985f4a2014-12-09 00:10:49 +090061 int dev_lock_count;
62 bool dev_lock_changed;
63 wait_queue_head_t hwdep_wait;
Takashi Sakamoto27e66632015-12-15 23:56:20 +090064
65 const struct ieee1394_device_id *entry;
Takashi Sakamotoc582cc62015-12-16 20:37:54 +090066 void *spec;
Takashi Sakamotoac5d7782019-08-04 15:21:32 +090067
68 struct amdtp_domain domain;
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +090069};
70
Takashi Sakamoto5b59d8092014-12-09 00:10:41 +090071/*
72 * AV/C Stream Format Information Specification 1.1 Working Draft
73 * (Apr 2005, 1394TA)
74 */
75int avc_stream_set_format(struct fw_unit *unit, enum avc_general_plug_dir dir,
76 unsigned int pid, u8 *format, unsigned int len);
77int avc_stream_get_format(struct fw_unit *unit,
78 enum avc_general_plug_dir dir, unsigned int pid,
79 u8 *buf, unsigned int *len, unsigned int eid);
80static inline int
81avc_stream_get_format_single(struct fw_unit *unit,
82 enum avc_general_plug_dir dir, unsigned int pid,
83 u8 *buf, unsigned int *len)
84{
85 return avc_stream_get_format(unit, dir, pid, buf, len, 0xff);
86}
87static inline int
88avc_stream_get_format_list(struct fw_unit *unit,
89 enum avc_general_plug_dir dir, unsigned int pid,
90 u8 *buf, unsigned int *len,
91 unsigned int eid)
92{
93 return avc_stream_get_format(unit, dir, pid, buf, len, eid);
94}
95
96/*
97 * AV/C Digital Interface Command Set General Specification 4.2
98 * (Sep 2004, 1394TA)
99 */
100int avc_general_inquiry_sig_fmt(struct fw_unit *unit, unsigned int rate,
101 enum avc_general_plug_dir dir,
102 unsigned short pid);
103
Takashi Sakamoto779f0db2019-06-12 17:44:19 +0900104int snd_oxfw_stream_init_duplex(struct snd_oxfw *oxfw);
Takashi Sakamoto4f380d02019-06-12 17:44:21 +0900105int snd_oxfw_stream_reserve_duplex(struct snd_oxfw *oxfw,
106 struct amdtp_stream *stream,
Takashi Sakamoto1d6a7222019-10-07 20:05:19 +0900107 unsigned int rate, unsigned int pcm_channels,
Takashi Sakamoto3299d2a2019-10-18 00:54:16 +0900108 unsigned int frames_per_period,
109 unsigned int frames_per_buffer);
Takashi Sakamoto4f380d02019-06-12 17:44:21 +0900110int snd_oxfw_stream_start_duplex(struct snd_oxfw *oxfw);
Takashi Sakamoto779f0db2019-06-12 17:44:19 +0900111void snd_oxfw_stream_stop_duplex(struct snd_oxfw *oxfw);
112void snd_oxfw_stream_destroy_duplex(struct snd_oxfw *oxfw);
113void snd_oxfw_stream_update_duplex(struct snd_oxfw *oxfw);
Takashi Sakamoto3713d932014-11-29 00:59:28 +0900114
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +0900115struct snd_oxfw_stream_formation {
116 unsigned int rate;
117 unsigned int pcm;
118 unsigned int midi;
119};
120int snd_oxfw_stream_parse_format(u8 *format,
121 struct snd_oxfw_stream_formation *formation);
122int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw,
123 enum avc_general_plug_dir dir,
124 struct snd_oxfw_stream_formation *formation);
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900125
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +0900126int snd_oxfw_stream_discover(struct snd_oxfw *oxfw);
127
Takashi Sakamoto8985f4a2014-12-09 00:10:49 +0900128void snd_oxfw_stream_lock_changed(struct snd_oxfw *oxfw);
129int snd_oxfw_stream_lock_try(struct snd_oxfw *oxfw);
130void snd_oxfw_stream_lock_release(struct snd_oxfw *oxfw);
131
Takashi Sakamoto3713d932014-11-29 00:59:28 +0900132int snd_oxfw_create_pcm(struct snd_oxfw *oxfw);
Takashi Sakamoto31514bf2014-11-29 00:59:29 +0900133
Takashi Sakamoto3c961012014-12-09 00:10:43 +0900134void snd_oxfw_proc_init(struct snd_oxfw *oxfw);
Takashi Sakamoto05588d32014-12-09 00:10:48 +0900135
136int snd_oxfw_create_midi(struct snd_oxfw *oxfw);
Takashi Sakamoto8985f4a2014-12-09 00:10:49 +0900137
138int snd_oxfw_create_hwdep(struct snd_oxfw *oxfw);
Takashi Sakamoto29aa09a2015-12-15 23:56:18 +0900139
Takashi Sakamoto3e2f4572015-12-16 20:37:56 +0900140int snd_oxfw_add_spkr(struct snd_oxfw *oxfw, bool is_lacie);
Takashi Sakamoto3f471522015-12-22 09:15:39 +0900141int snd_oxfw_scs1x_add(struct snd_oxfw *oxfw);
Takashi Sakamotoe3315b42015-12-22 09:15:40 +0900142void snd_oxfw_scs1x_update(struct snd_oxfw *oxfw);