xref: /openbmc/linux/sound/firewire/bebob/bebob.h (revision 36d1a672)
1da607e19SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2fd6f4b0dSTakashi Sakamoto /*
3fd6f4b0dSTakashi Sakamoto  * bebob.h - a part of driver for BeBoB based devices
4fd6f4b0dSTakashi Sakamoto  *
5fd6f4b0dSTakashi Sakamoto  * Copyright (c) 2013-2014 Takashi Sakamoto
6fd6f4b0dSTakashi Sakamoto  */
7fd6f4b0dSTakashi Sakamoto 
8fd6f4b0dSTakashi Sakamoto #ifndef SOUND_BEBOB_H_INCLUDED
9fd6f4b0dSTakashi Sakamoto #define SOUND_BEBOB_H_INCLUDED
10fd6f4b0dSTakashi Sakamoto 
11fd6f4b0dSTakashi Sakamoto #include <linux/compat.h>
12fd6f4b0dSTakashi Sakamoto #include <linux/device.h>
13fd6f4b0dSTakashi Sakamoto #include <linux/firewire.h>
14fd6f4b0dSTakashi Sakamoto #include <linux/firewire-constants.h>
15fd6f4b0dSTakashi Sakamoto #include <linux/module.h>
16fd6f4b0dSTakashi Sakamoto #include <linux/mod_devicetable.h>
17fd6f4b0dSTakashi Sakamoto #include <linux/delay.h>
18fd6f4b0dSTakashi Sakamoto #include <linux/slab.h>
19174cd4b1SIngo Molnar #include <linux/sched/signal.h>
20fd6f4b0dSTakashi Sakamoto 
21fd6f4b0dSTakashi Sakamoto #include <sound/core.h>
22fd6f4b0dSTakashi Sakamoto #include <sound/initval.h>
23ad9697baSTakashi Sakamoto #include <sound/info.h>
24248b7802STakashi Sakamoto #include <sound/rawmidi.h>
25fbbebd2cSTakashi Sakamoto #include <sound/pcm.h>
26fbbebd2cSTakashi Sakamoto #include <sound/pcm_params.h>
27618eabeaSTakashi Sakamoto #include <sound/firewire.h>
28618eabeaSTakashi Sakamoto #include <sound/hwdep.h>
29fd6f4b0dSTakashi Sakamoto 
30fd6f4b0dSTakashi Sakamoto #include "../lib.h"
31fd6f4b0dSTakashi Sakamoto #include "../fcp.h"
32eb7b3a05STakashi Sakamoto #include "../packets-buffer.h"
33eb7b3a05STakashi Sakamoto #include "../iso-resources.h"
345955815eSTakashi Sakamoto #include "../amdtp-am824.h"
35eb7b3a05STakashi Sakamoto #include "../cmp.h"
36fd6f4b0dSTakashi Sakamoto 
37fd6f4b0dSTakashi Sakamoto /* basic register addresses on DM1000/DM1100/DM1500 */
389b5f0edfSTakashi Sakamoto #define BEBOB_ADDR_REG_INFO	0xffffc8020000ULL
399b5f0edfSTakashi Sakamoto #define BEBOB_ADDR_REG_REQ	0xffffc8021000ULL
40fd6f4b0dSTakashi Sakamoto 
41eb7b3a05STakashi Sakamoto struct snd_bebob;
42eb7b3a05STakashi Sakamoto 
43eb7b3a05STakashi Sakamoto #define SND_BEBOB_STRM_FMT_ENTRIES	7
44eb7b3a05STakashi Sakamoto struct snd_bebob_stream_formation {
45eb7b3a05STakashi Sakamoto 	unsigned int pcm;
46eb7b3a05STakashi Sakamoto 	unsigned int midi;
47eb7b3a05STakashi Sakamoto };
48eb7b3a05STakashi Sakamoto /* this is a lookup table for index of stream formations */
49eb7b3a05STakashi Sakamoto extern const unsigned int snd_bebob_rate_table[SND_BEBOB_STRM_FMT_ENTRIES];
50eb7b3a05STakashi Sakamoto 
511fc9522aSTakashi Sakamoto /* device specific operations */
5213a4f420STakashi Sakamoto enum snd_bebob_clock_type {
5313a4f420STakashi Sakamoto 	SND_BEBOB_CLOCK_TYPE_INTERNAL = 0,
5413a4f420STakashi Sakamoto 	SND_BEBOB_CLOCK_TYPE_EXTERNAL,
5513a4f420STakashi Sakamoto 	SND_BEBOB_CLOCK_TYPE_SYT,
5613a4f420STakashi Sakamoto };
571fc9522aSTakashi Sakamoto struct snd_bebob_clock_spec {
581fc9522aSTakashi Sakamoto 	unsigned int num;
59e7ced413STakashi Iwai 	const char *const *labels;
60782fbec7STakashi Sakamoto 	const enum snd_bebob_clock_type *types;
611fc9522aSTakashi Sakamoto 	int (*get)(struct snd_bebob *bebob, unsigned int *id);
621fc9522aSTakashi Sakamoto };
631fc9522aSTakashi Sakamoto struct snd_bebob_rate_spec {
641fc9522aSTakashi Sakamoto 	int (*get)(struct snd_bebob *bebob, unsigned int *rate);
651fc9522aSTakashi Sakamoto 	int (*set)(struct snd_bebob *bebob, unsigned int rate);
661fc9522aSTakashi Sakamoto };
671fc9522aSTakashi Sakamoto struct snd_bebob_meter_spec {
681fc9522aSTakashi Sakamoto 	unsigned int num;
69e7ced413STakashi Iwai 	const char *const *labels;
701fc9522aSTakashi Sakamoto 	int (*get)(struct snd_bebob *bebob, u32 *target, unsigned int size);
711fc9522aSTakashi Sakamoto };
721fc9522aSTakashi Sakamoto struct snd_bebob_spec {
736b9866c8SJulia Lawall 	const struct snd_bebob_clock_spec *clock;
746b9866c8SJulia Lawall 	const struct snd_bebob_rate_spec *rate;
756b9866c8SJulia Lawall 	const struct snd_bebob_meter_spec *meter;
761fc9522aSTakashi Sakamoto };
771fc9522aSTakashi Sakamoto 
7893cd12d6STakashi Sakamoto enum snd_bebob_quirk {
79*36d1a672SColin Ian King 	SND_BEBOB_QUIRK_INITIAL_DISCONTINUOUS_DBC = (1 << 0),
80*36d1a672SColin Ian King 	SND_BEBOB_QUIRK_WRONG_DBC		  = (1 << 1),
8193cd12d6STakashi Sakamoto };
8293cd12d6STakashi Sakamoto 
83fd6f4b0dSTakashi Sakamoto struct snd_bebob {
84fd6f4b0dSTakashi Sakamoto 	struct snd_card *card;
85fd6f4b0dSTakashi Sakamoto 	struct fw_unit *unit;
86fd6f4b0dSTakashi Sakamoto 	int card_index;
87fd6f4b0dSTakashi Sakamoto 
88fd6f4b0dSTakashi Sakamoto 	struct mutex mutex;
89fd6f4b0dSTakashi Sakamoto 	spinlock_t lock;
90eb7b3a05STakashi Sakamoto 
911fc9522aSTakashi Sakamoto 	const struct snd_bebob_spec *spec;
9293cd12d6STakashi Sakamoto 	unsigned int quirks;	// Combination of snd_bebob_quirk enumerations.
931fc9522aSTakashi Sakamoto 
94eb7b3a05STakashi Sakamoto 	unsigned int midi_input_ports;
95eb7b3a05STakashi Sakamoto 	unsigned int midi_output_ports;
96eb7b3a05STakashi Sakamoto 
97eb7b3a05STakashi Sakamoto 	struct amdtp_stream tx_stream;
98eb7b3a05STakashi Sakamoto 	struct amdtp_stream rx_stream;
99eb7b3a05STakashi Sakamoto 	struct cmp_connection out_conn;
100eb7b3a05STakashi Sakamoto 	struct cmp_connection in_conn;
1014fd6c6c7STakashi Sakamoto 	unsigned int substreams_counter;
102eb7b3a05STakashi Sakamoto 
103eb7b3a05STakashi Sakamoto 	struct snd_bebob_stream_formation
104eb7b3a05STakashi Sakamoto 		tx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];
105eb7b3a05STakashi Sakamoto 	struct snd_bebob_stream_formation
106eb7b3a05STakashi Sakamoto 		rx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];
107eb7b3a05STakashi Sakamoto 
108eb7b3a05STakashi Sakamoto 	int sync_input_plug;
109618eabeaSTakashi Sakamoto 
110618eabeaSTakashi Sakamoto 	/* for uapi */
111618eabeaSTakashi Sakamoto 	int dev_lock_count;
112618eabeaSTakashi Sakamoto 	bool dev_lock_changed;
113618eabeaSTakashi Sakamoto 	wait_queue_head_t hwdep_wait;
1143149ac48STakashi Sakamoto 
1153149ac48STakashi Sakamoto 	/* for M-Audio special devices */
1163149ac48STakashi Sakamoto 	void *maudio_special_quirk;
1177b4d7dcfSTakashi Sakamoto 
118b0db4d51STakashi Sakamoto 	struct amdtp_domain domain;
119fd6f4b0dSTakashi Sakamoto };
120fd6f4b0dSTakashi Sakamoto 
121fd6f4b0dSTakashi Sakamoto static inline int
snd_bebob_read_block(struct fw_unit * unit,u64 addr,void * buf,int size)122fd6f4b0dSTakashi Sakamoto snd_bebob_read_block(struct fw_unit *unit, u64 addr, void *buf, int size)
123fd6f4b0dSTakashi Sakamoto {
124fd6f4b0dSTakashi Sakamoto 	return snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST,
125fd6f4b0dSTakashi Sakamoto 				  BEBOB_ADDR_REG_INFO + addr,
126fd6f4b0dSTakashi Sakamoto 				  buf, size, 0);
127fd6f4b0dSTakashi Sakamoto }
128fd6f4b0dSTakashi Sakamoto 
129fd6f4b0dSTakashi Sakamoto static inline int
snd_bebob_read_quad(struct fw_unit * unit,u64 addr,u32 * buf)130fd6f4b0dSTakashi Sakamoto snd_bebob_read_quad(struct fw_unit *unit, u64 addr, u32 *buf)
131fd6f4b0dSTakashi Sakamoto {
132fd6f4b0dSTakashi Sakamoto 	return snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
133fd6f4b0dSTakashi Sakamoto 				  BEBOB_ADDR_REG_INFO + addr,
134fd6f4b0dSTakashi Sakamoto 				  (void *)buf, sizeof(u32), 0);
135fd6f4b0dSTakashi Sakamoto }
136fd6f4b0dSTakashi Sakamoto 
1371fc9522aSTakashi Sakamoto /* AV/C Audio Subunit Specification 1.0 (Oct 2000, 1394TA) */
1381fc9522aSTakashi Sakamoto int avc_audio_set_selector(struct fw_unit *unit, unsigned int subunit_id,
1391fc9522aSTakashi Sakamoto 			   unsigned int fb_id, unsigned int num);
1401fc9522aSTakashi Sakamoto int avc_audio_get_selector(struct fw_unit *unit, unsigned  int subunit_id,
1411fc9522aSTakashi Sakamoto 			   unsigned int fb_id, unsigned int *num);
1421fc9522aSTakashi Sakamoto 
143eb7b3a05STakashi Sakamoto /*
144eb7b3a05STakashi Sakamoto  * AVC command extensions, AV/C Unit and Subunit, Revision 17
145eb7b3a05STakashi Sakamoto  * (Nov 2003, BridgeCo)
146eb7b3a05STakashi Sakamoto  */
147eb7b3a05STakashi Sakamoto #define	AVC_BRIDGECO_ADDR_BYTES	6
148eb7b3a05STakashi Sakamoto enum avc_bridgeco_plug_dir {
149eb7b3a05STakashi Sakamoto 	AVC_BRIDGECO_PLUG_DIR_IN	= 0x00,
150eb7b3a05STakashi Sakamoto 	AVC_BRIDGECO_PLUG_DIR_OUT	= 0x01
151eb7b3a05STakashi Sakamoto };
152eb7b3a05STakashi Sakamoto enum avc_bridgeco_plug_mode {
153eb7b3a05STakashi Sakamoto 	AVC_BRIDGECO_PLUG_MODE_UNIT		= 0x00,
154eb7b3a05STakashi Sakamoto 	AVC_BRIDGECO_PLUG_MODE_SUBUNIT		= 0x01,
155eb7b3a05STakashi Sakamoto 	AVC_BRIDGECO_PLUG_MODE_FUNCTION_BLOCK	= 0x02
156eb7b3a05STakashi Sakamoto };
157eb7b3a05STakashi Sakamoto enum avc_bridgeco_plug_unit {
158eb7b3a05STakashi Sakamoto 	AVC_BRIDGECO_PLUG_UNIT_ISOC	= 0x00,
159eb7b3a05STakashi Sakamoto 	AVC_BRIDGECO_PLUG_UNIT_EXT	= 0x01,
160eb7b3a05STakashi Sakamoto 	AVC_BRIDGECO_PLUG_UNIT_ASYNC	= 0x02
161eb7b3a05STakashi Sakamoto };
162eb7b3a05STakashi Sakamoto enum avc_bridgeco_plug_type {
163eb7b3a05STakashi Sakamoto 	AVC_BRIDGECO_PLUG_TYPE_ISOC	= 0x00,
164eb7b3a05STakashi Sakamoto 	AVC_BRIDGECO_PLUG_TYPE_ASYNC	= 0x01,
165eb7b3a05STakashi Sakamoto 	AVC_BRIDGECO_PLUG_TYPE_MIDI	= 0x02,
166eb7b3a05STakashi Sakamoto 	AVC_BRIDGECO_PLUG_TYPE_SYNC	= 0x03,
167eb7b3a05STakashi Sakamoto 	AVC_BRIDGECO_PLUG_TYPE_ANA	= 0x04,
1685a668812STakashi Sakamoto 	AVC_BRIDGECO_PLUG_TYPE_DIG	= 0x05,
1695a668812STakashi Sakamoto 	AVC_BRIDGECO_PLUG_TYPE_ADDITION	= 0x06
170eb7b3a05STakashi Sakamoto };
171eb7b3a05STakashi Sakamoto static inline void
avc_bridgeco_fill_unit_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],enum avc_bridgeco_plug_dir dir,enum avc_bridgeco_plug_unit unit,unsigned int pid)172eb7b3a05STakashi Sakamoto avc_bridgeco_fill_unit_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],
173eb7b3a05STakashi Sakamoto 			    enum avc_bridgeco_plug_dir dir,
174eb7b3a05STakashi Sakamoto 			    enum avc_bridgeco_plug_unit unit,
175eb7b3a05STakashi Sakamoto 			    unsigned int pid)
176eb7b3a05STakashi Sakamoto {
177eb7b3a05STakashi Sakamoto 	buf[0] = 0xff;	/* Unit */
178eb7b3a05STakashi Sakamoto 	buf[1] = dir;
179eb7b3a05STakashi Sakamoto 	buf[2] = AVC_BRIDGECO_PLUG_MODE_UNIT;
180eb7b3a05STakashi Sakamoto 	buf[3] = unit;
181eb7b3a05STakashi Sakamoto 	buf[4] = 0xff & pid;
182eb7b3a05STakashi Sakamoto 	buf[5] = 0xff;	/* reserved */
183eb7b3a05STakashi Sakamoto }
184eb7b3a05STakashi Sakamoto static inline void
avc_bridgeco_fill_msu_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],enum avc_bridgeco_plug_dir dir,unsigned int pid)185eb7b3a05STakashi Sakamoto avc_bridgeco_fill_msu_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],
186eb7b3a05STakashi Sakamoto 			   enum avc_bridgeco_plug_dir dir,
187eb7b3a05STakashi Sakamoto 			   unsigned int pid)
188eb7b3a05STakashi Sakamoto {
189eb7b3a05STakashi Sakamoto 	buf[0] = 0x60;	/* Music subunit */
190eb7b3a05STakashi Sakamoto 	buf[1] = dir;
191eb7b3a05STakashi Sakamoto 	buf[2] = AVC_BRIDGECO_PLUG_MODE_SUBUNIT;
192eb7b3a05STakashi Sakamoto 	buf[3] = 0xff & pid;
193eb7b3a05STakashi Sakamoto 	buf[4] = 0xff;	/* reserved */
194eb7b3a05STakashi Sakamoto 	buf[5] = 0xff;	/* reserved */
195eb7b3a05STakashi Sakamoto }
196eb7b3a05STakashi Sakamoto int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit,
197eb7b3a05STakashi Sakamoto 				 u8 addr[AVC_BRIDGECO_ADDR_BYTES],
198eb7b3a05STakashi Sakamoto 				 u8 *buf, unsigned int len);
199eb7b3a05STakashi Sakamoto int avc_bridgeco_get_plug_type(struct fw_unit *unit,
200eb7b3a05STakashi Sakamoto 			       u8 addr[AVC_BRIDGECO_ADDR_BYTES],
201eb7b3a05STakashi Sakamoto 			       enum avc_bridgeco_plug_type *type);
2025c6ea94fSTakashi Sakamoto int avc_bridgeco_get_plug_ch_count(struct fw_unit *unit, u8 addr[AVC_BRIDGECO_ADDR_BYTES],
2035c6ea94fSTakashi Sakamoto 				   unsigned int *ch_count);
204eb7b3a05STakashi Sakamoto int avc_bridgeco_get_plug_section_type(struct fw_unit *unit,
205eb7b3a05STakashi Sakamoto 				       u8 addr[AVC_BRIDGECO_ADDR_BYTES],
206eb7b3a05STakashi Sakamoto 				       unsigned int id, u8 *type);
207eb7b3a05STakashi Sakamoto int avc_bridgeco_get_plug_input(struct fw_unit *unit,
208eb7b3a05STakashi Sakamoto 				u8 addr[AVC_BRIDGECO_ADDR_BYTES],
209eb7b3a05STakashi Sakamoto 				u8 input[7]);
210eb7b3a05STakashi Sakamoto int avc_bridgeco_get_plug_strm_fmt(struct fw_unit *unit,
211eb7b3a05STakashi Sakamoto 				   u8 addr[AVC_BRIDGECO_ADDR_BYTES], u8 *buf,
212eb7b3a05STakashi Sakamoto 				   unsigned int *len, unsigned int eid);
213eb7b3a05STakashi Sakamoto 
214eb7b3a05STakashi Sakamoto /* for AMDTP streaming */
215eb7b3a05STakashi Sakamoto int snd_bebob_stream_get_rate(struct snd_bebob *bebob, unsigned int *rate);
216eb7b3a05STakashi Sakamoto int snd_bebob_stream_set_rate(struct snd_bebob *bebob, unsigned int rate);
2173e254b16STakashi Sakamoto int snd_bebob_stream_get_clock_src(struct snd_bebob *bebob,
2183e254b16STakashi Sakamoto 				   enum snd_bebob_clock_type *src);
219eb7b3a05STakashi Sakamoto int snd_bebob_stream_discover(struct snd_bebob *bebob);
220eb7b3a05STakashi Sakamoto int snd_bebob_stream_init_duplex(struct snd_bebob *bebob);
2218737209fSTakashi Sakamoto int snd_bebob_stream_reserve_duplex(struct snd_bebob *bebob, unsigned int rate,
2221fde7a44STakashi Sakamoto 				    unsigned int frames_per_period,
2231fde7a44STakashi Sakamoto 				    unsigned int frames_per_buffer);
224ac2888b9STakashi Sakamoto int snd_bebob_stream_start_duplex(struct snd_bebob *bebob);
225eb7b3a05STakashi Sakamoto void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob);
226eb7b3a05STakashi Sakamoto void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob);
227eb7b3a05STakashi Sakamoto 
228618eabeaSTakashi Sakamoto void snd_bebob_stream_lock_changed(struct snd_bebob *bebob);
229618eabeaSTakashi Sakamoto int snd_bebob_stream_lock_try(struct snd_bebob *bebob);
230618eabeaSTakashi Sakamoto void snd_bebob_stream_lock_release(struct snd_bebob *bebob);
231618eabeaSTakashi Sakamoto 
232ad9697baSTakashi Sakamoto void snd_bebob_proc_init(struct snd_bebob *bebob);
233ad9697baSTakashi Sakamoto 
234248b7802STakashi Sakamoto int snd_bebob_create_midi_devices(struct snd_bebob *bebob);
235248b7802STakashi Sakamoto 
236fbbebd2cSTakashi Sakamoto int snd_bebob_create_pcm_devices(struct snd_bebob *bebob);
237fbbebd2cSTakashi Sakamoto 
238618eabeaSTakashi Sakamoto int snd_bebob_create_hwdep_device(struct snd_bebob *bebob);
239618eabeaSTakashi Sakamoto 
240326b9cacSTakashi Sakamoto /* model specific operations */
2416b9866c8SJulia Lawall extern const struct snd_bebob_spec phase88_rack_spec;
242e15c282eSTakashi Sakamoto extern const struct snd_bebob_spec yamaha_terratec_spec;
2436b9866c8SJulia Lawall extern const struct snd_bebob_spec saffirepro_26_spec;
2446b9866c8SJulia Lawall extern const struct snd_bebob_spec saffirepro_10_spec;
2456b9866c8SJulia Lawall extern const struct snd_bebob_spec saffire_le_spec;
2466b9866c8SJulia Lawall extern const struct snd_bebob_spec saffire_spec;
2476b9866c8SJulia Lawall extern const struct snd_bebob_spec maudio_fw410_spec;
2486b9866c8SJulia Lawall extern const struct snd_bebob_spec maudio_audiophile_spec;
2496b9866c8SJulia Lawall extern const struct snd_bebob_spec maudio_solo_spec;
2506b9866c8SJulia Lawall extern const struct snd_bebob_spec maudio_ozonic_spec;
2516b9866c8SJulia Lawall extern const struct snd_bebob_spec maudio_nrv10_spec;
2526b9866c8SJulia Lawall extern const struct snd_bebob_spec maudio_special_spec;
2533149ac48STakashi Sakamoto int snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814);
254a2b2a779STakashi Sakamoto int snd_bebob_maudio_load_firmware(struct fw_unit *unit);
255326b9cacSTakashi Sakamoto 
256fd6f4b0dSTakashi Sakamoto #endif
257