blob: 1520854b76d7866deb98a6e1de371d42038b45fb [file] [log] [blame]
Takashi Sakamotofd6f4b0d2014-04-25 22:45:14 +09001/*
2 * bebob.h - a part of driver for BeBoB based devices
3 *
4 * Copyright (c) 2013-2014 Takashi Sakamoto
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9#ifndef SOUND_BEBOB_H_INCLUDED
10#define SOUND_BEBOB_H_INCLUDED
11
12#include <linux/compat.h>
13#include <linux/device.h>
14#include <linux/firewire.h>
15#include <linux/firewire-constants.h>
16#include <linux/module.h>
17#include <linux/mod_devicetable.h>
18#include <linux/delay.h>
19#include <linux/slab.h>
20
21#include <sound/core.h>
22#include <sound/initval.h>
Takashi Sakamotoad9697b2014-04-25 22:45:17 +090023#include <sound/info.h>
Takashi Sakamoto248b7802014-04-25 22:45:18 +090024#include <sound/rawmidi.h>
Takashi Sakamotofbbebd22014-04-25 22:45:19 +090025#include <sound/pcm.h>
26#include <sound/pcm_params.h>
Takashi Sakamoto618eabe2014-04-25 22:45:20 +090027#include <sound/firewire.h>
28#include <sound/hwdep.h>
Takashi Sakamotofd6f4b0d2014-04-25 22:45:14 +090029
30#include "../lib.h"
31#include "../fcp.h"
Takashi Sakamotoeb7b3a02014-04-25 22:45:15 +090032#include "../packets-buffer.h"
33#include "../iso-resources.h"
34#include "../amdtp.h"
35#include "../cmp.h"
Takashi Sakamotofd6f4b0d2014-04-25 22:45:14 +090036
37/* basic register addresses on DM1000/DM1100/DM1500 */
Takashi Sakamoto9b5f0ed2014-05-28 00:14:42 +090038#define BEBOB_ADDR_REG_INFO 0xffffc8020000ULL
39#define BEBOB_ADDR_REG_REQ 0xffffc8021000ULL
Takashi Sakamotofd6f4b0d2014-04-25 22:45:14 +090040
Takashi Sakamotoeb7b3a02014-04-25 22:45:15 +090041struct snd_bebob;
42
43#define SND_BEBOB_STRM_FMT_ENTRIES 7
44struct snd_bebob_stream_formation {
45 unsigned int pcm;
46 unsigned int midi;
47};
48/* this is a lookup table for index of stream formations */
49extern const unsigned int snd_bebob_rate_table[SND_BEBOB_STRM_FMT_ENTRIES];
50
Takashi Sakamoto1fc95222014-04-25 22:45:21 +090051/* device specific operations */
Takashi Sakamoto13a4f422015-06-14 12:49:28 +090052enum snd_bebob_clock_type {
53 SND_BEBOB_CLOCK_TYPE_INTERNAL = 0,
54 SND_BEBOB_CLOCK_TYPE_EXTERNAL,
55 SND_BEBOB_CLOCK_TYPE_SYT,
56};
Takashi Sakamoto1fc95222014-04-25 22:45:21 +090057struct snd_bebob_clock_spec {
58 unsigned int num;
Takashi Iwaie7ced412014-10-21 08:26:10 +020059 const char *const *labels;
Takashi Sakamoto13a4f422015-06-14 12:49:28 +090060 enum snd_bebob_clock_type *types;
Takashi Sakamoto1fc95222014-04-25 22:45:21 +090061 int (*get)(struct snd_bebob *bebob, unsigned int *id);
62};
63struct snd_bebob_rate_spec {
64 int (*get)(struct snd_bebob *bebob, unsigned int *rate);
65 int (*set)(struct snd_bebob *bebob, unsigned int rate);
66};
67struct snd_bebob_meter_spec {
68 unsigned int num;
Takashi Iwaie7ced412014-10-21 08:26:10 +020069 const char *const *labels;
Takashi Sakamoto1fc95222014-04-25 22:45:21 +090070 int (*get)(struct snd_bebob *bebob, u32 *target, unsigned int size);
71};
72struct snd_bebob_spec {
73 struct snd_bebob_clock_spec *clock;
74 struct snd_bebob_rate_spec *rate;
75 struct snd_bebob_meter_spec *meter;
76};
77
Takashi Sakamotofd6f4b0d2014-04-25 22:45:14 +090078struct snd_bebob {
79 struct snd_card *card;
80 struct fw_unit *unit;
81 int card_index;
82
83 struct mutex mutex;
84 spinlock_t lock;
Takashi Sakamotoeb7b3a02014-04-25 22:45:15 +090085
Takashi Sakamoto1fc95222014-04-25 22:45:21 +090086 const struct snd_bebob_spec *spec;
87
Takashi Sakamotoeb7b3a02014-04-25 22:45:15 +090088 unsigned int midi_input_ports;
89 unsigned int midi_output_ports;
90
Takashi Sakamotob6bc8122014-04-25 22:45:16 +090091 /* for bus reset quirk */
92 struct completion bus_reset;
93 bool connected;
94
Takashi Sakamotoeb7b3a02014-04-25 22:45:15 +090095 struct amdtp_stream *master;
96 struct amdtp_stream tx_stream;
97 struct amdtp_stream rx_stream;
98 struct cmp_connection out_conn;
99 struct cmp_connection in_conn;
100 atomic_t capture_substreams;
101 atomic_t playback_substreams;
102
103 struct snd_bebob_stream_formation
104 tx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];
105 struct snd_bebob_stream_formation
106 rx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];
107
108 int sync_input_plug;
Takashi Sakamoto618eabe2014-04-25 22:45:20 +0900109
110 /* for uapi */
111 int dev_lock_count;
112 bool dev_lock_changed;
113 wait_queue_head_t hwdep_wait;
Takashi Sakamoto3149ac42014-04-25 22:45:26 +0900114
115 /* for M-Audio special devices */
116 void *maudio_special_quirk;
Takashi Sakamoto9b1ee0b2014-04-25 22:45:30 +0900117 bool deferred_registration;
Takashi Sakamoto7b4d7dc2015-06-14 12:49:33 +0900118
119 /* For BeBoB version quirk. */
120 unsigned int version;
Takashi Sakamotofd6f4b0d2014-04-25 22:45:14 +0900121};
122
123static inline int
124snd_bebob_read_block(struct fw_unit *unit, u64 addr, void *buf, int size)
125{
126 return snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST,
127 BEBOB_ADDR_REG_INFO + addr,
128 buf, size, 0);
129}
130
131static inline int
132snd_bebob_read_quad(struct fw_unit *unit, u64 addr, u32 *buf)
133{
134 return snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
135 BEBOB_ADDR_REG_INFO + addr,
136 (void *)buf, sizeof(u32), 0);
137}
138
Takashi Sakamoto1fc95222014-04-25 22:45:21 +0900139/* AV/C Audio Subunit Specification 1.0 (Oct 2000, 1394TA) */
140int avc_audio_set_selector(struct fw_unit *unit, unsigned int subunit_id,
141 unsigned int fb_id, unsigned int num);
142int avc_audio_get_selector(struct fw_unit *unit, unsigned int subunit_id,
143 unsigned int fb_id, unsigned int *num);
144
Takashi Sakamotoeb7b3a02014-04-25 22:45:15 +0900145/*
146 * AVC command extensions, AV/C Unit and Subunit, Revision 17
147 * (Nov 2003, BridgeCo)
148 */
149#define AVC_BRIDGECO_ADDR_BYTES 6
150enum avc_bridgeco_plug_dir {
151 AVC_BRIDGECO_PLUG_DIR_IN = 0x00,
152 AVC_BRIDGECO_PLUG_DIR_OUT = 0x01
153};
154enum avc_bridgeco_plug_mode {
155 AVC_BRIDGECO_PLUG_MODE_UNIT = 0x00,
156 AVC_BRIDGECO_PLUG_MODE_SUBUNIT = 0x01,
157 AVC_BRIDGECO_PLUG_MODE_FUNCTION_BLOCK = 0x02
158};
159enum avc_bridgeco_plug_unit {
160 AVC_BRIDGECO_PLUG_UNIT_ISOC = 0x00,
161 AVC_BRIDGECO_PLUG_UNIT_EXT = 0x01,
162 AVC_BRIDGECO_PLUG_UNIT_ASYNC = 0x02
163};
164enum avc_bridgeco_plug_type {
165 AVC_BRIDGECO_PLUG_TYPE_ISOC = 0x00,
166 AVC_BRIDGECO_PLUG_TYPE_ASYNC = 0x01,
167 AVC_BRIDGECO_PLUG_TYPE_MIDI = 0x02,
168 AVC_BRIDGECO_PLUG_TYPE_SYNC = 0x03,
169 AVC_BRIDGECO_PLUG_TYPE_ANA = 0x04,
Takashi Sakamoto5a668812015-06-14 12:49:27 +0900170 AVC_BRIDGECO_PLUG_TYPE_DIG = 0x05,
171 AVC_BRIDGECO_PLUG_TYPE_ADDITION = 0x06
Takashi Sakamotoeb7b3a02014-04-25 22:45:15 +0900172};
173static inline void
174avc_bridgeco_fill_unit_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],
175 enum avc_bridgeco_plug_dir dir,
176 enum avc_bridgeco_plug_unit unit,
177 unsigned int pid)
178{
179 buf[0] = 0xff; /* Unit */
180 buf[1] = dir;
181 buf[2] = AVC_BRIDGECO_PLUG_MODE_UNIT;
182 buf[3] = unit;
183 buf[4] = 0xff & pid;
184 buf[5] = 0xff; /* reserved */
185}
186static inline void
187avc_bridgeco_fill_msu_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],
188 enum avc_bridgeco_plug_dir dir,
189 unsigned int pid)
190{
191 buf[0] = 0x60; /* Music subunit */
192 buf[1] = dir;
193 buf[2] = AVC_BRIDGECO_PLUG_MODE_SUBUNIT;
194 buf[3] = 0xff & pid;
195 buf[4] = 0xff; /* reserved */
196 buf[5] = 0xff; /* reserved */
197}
198int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit,
199 u8 addr[AVC_BRIDGECO_ADDR_BYTES],
200 u8 *buf, unsigned int len);
201int avc_bridgeco_get_plug_type(struct fw_unit *unit,
202 u8 addr[AVC_BRIDGECO_ADDR_BYTES],
203 enum avc_bridgeco_plug_type *type);
204int avc_bridgeco_get_plug_section_type(struct fw_unit *unit,
205 u8 addr[AVC_BRIDGECO_ADDR_BYTES],
206 unsigned int id, u8 *type);
207int avc_bridgeco_get_plug_input(struct fw_unit *unit,
208 u8 addr[AVC_BRIDGECO_ADDR_BYTES],
209 u8 input[7]);
210int avc_bridgeco_get_plug_strm_fmt(struct fw_unit *unit,
211 u8 addr[AVC_BRIDGECO_ADDR_BYTES], u8 *buf,
212 unsigned int *len, unsigned int eid);
213
214/* for AMDTP streaming */
215int snd_bebob_stream_get_rate(struct snd_bebob *bebob, unsigned int *rate);
216int snd_bebob_stream_set_rate(struct snd_bebob *bebob, unsigned int rate);
Takashi Sakamoto3e254b12015-06-14 12:49:30 +0900217int snd_bebob_stream_get_clock_src(struct snd_bebob *bebob,
218 enum snd_bebob_clock_type *src);
Takashi Sakamotoeb7b3a02014-04-25 22:45:15 +0900219int snd_bebob_stream_discover(struct snd_bebob *bebob);
Takashi Sakamotoeb7b3a02014-04-25 22:45:15 +0900220int snd_bebob_stream_init_duplex(struct snd_bebob *bebob);
Takashi Sakamoto4a286d52014-05-28 00:14:40 +0900221int snd_bebob_stream_start_duplex(struct snd_bebob *bebob, unsigned int rate);
Takashi Sakamotoeb7b3a02014-04-25 22:45:15 +0900222void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob);
223void snd_bebob_stream_update_duplex(struct snd_bebob *bebob);
224void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob);
225
Takashi Sakamoto618eabe2014-04-25 22:45:20 +0900226void snd_bebob_stream_lock_changed(struct snd_bebob *bebob);
227int snd_bebob_stream_lock_try(struct snd_bebob *bebob);
228void snd_bebob_stream_lock_release(struct snd_bebob *bebob);
229
Takashi Sakamotoad9697b2014-04-25 22:45:17 +0900230void snd_bebob_proc_init(struct snd_bebob *bebob);
231
Takashi Sakamoto248b7802014-04-25 22:45:18 +0900232int snd_bebob_create_midi_devices(struct snd_bebob *bebob);
233
Takashi Sakamotofbbebd22014-04-25 22:45:19 +0900234int snd_bebob_create_pcm_devices(struct snd_bebob *bebob);
235
Takashi Sakamoto618eabe2014-04-25 22:45:20 +0900236int snd_bebob_create_hwdep_device(struct snd_bebob *bebob);
237
Takashi Sakamoto326b9ca2014-04-25 22:45:22 +0900238/* model specific operations */
239extern struct snd_bebob_spec phase88_rack_spec;
240extern struct snd_bebob_spec phase24_series_spec;
Takashi Sakamoto8ac98a32014-04-25 22:45:23 +0900241extern struct snd_bebob_spec yamaha_go_spec;
Takashi Sakamoto25784ec2014-04-25 22:45:24 +0900242extern struct snd_bebob_spec saffirepro_26_spec;
243extern struct snd_bebob_spec saffirepro_10_spec;
244extern struct snd_bebob_spec saffire_le_spec;
245extern struct snd_bebob_spec saffire_spec;
Takashi Sakamoto9076c222014-04-25 22:45:25 +0900246extern struct snd_bebob_spec maudio_fw410_spec;
247extern struct snd_bebob_spec maudio_audiophile_spec;
248extern struct snd_bebob_spec maudio_solo_spec;
249extern struct snd_bebob_spec maudio_ozonic_spec;
250extern struct snd_bebob_spec maudio_nrv10_spec;
Takashi Sakamoto3149ac42014-04-25 22:45:26 +0900251extern struct snd_bebob_spec maudio_special_spec;
252int snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814);
Takashi Sakamotoa2b2a772014-04-25 22:45:29 +0900253int snd_bebob_maudio_load_firmware(struct fw_unit *unit);
Takashi Sakamoto326b9ca2014-04-25 22:45:22 +0900254
Takashi Sakamoto1fc95222014-04-25 22:45:21 +0900255#define SND_BEBOB_DEV_ENTRY(vendor, model, data) \
Takashi Sakamotofd6f4b0d2014-04-25 22:45:14 +0900256{ \
257 .match_flags = IEEE1394_MATCH_VENDOR_ID | \
258 IEEE1394_MATCH_MODEL_ID, \
259 .vendor_id = vendor, \
260 .model_id = model, \
Takashi Sakamoto1fc95222014-04-25 22:45:21 +0900261 .driver_data = (kernel_ulong_t)data \
Takashi Sakamotofd6f4b0d2014-04-25 22:45:14 +0900262}
263
264#endif