2 * bebob.h - a part of driver for BeBoB based devices
4 * Copyright (c) 2013-2014 Takashi Sakamoto
6 * Licensed under the terms of the GNU General Public License, version 2.
9 #ifndef SOUND_BEBOB_H_INCLUDED
10 #define SOUND_BEBOB_H_INCLUDED
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>
21 #include <sound/core.h>
22 #include <sound/initval.h>
26 #include "../packets-buffer.h"
27 #include "../iso-resources.h"
31 /* basic register addresses on DM1000/DM1100/DM1500 */
32 #define BEBOB_ADDR_REG_INFO 0xffffc8020000
33 #define BEBOB_ADDR_REG_REQ 0xffffc8021000
37 #define SND_BEBOB_STRM_FMT_ENTRIES 7
38 struct snd_bebob_stream_formation {
42 /* this is a lookup table for index of stream formations */
43 extern const unsigned int snd_bebob_rate_table[SND_BEBOB_STRM_FMT_ENTRIES];
46 struct snd_card *card;
53 unsigned int midi_input_ports;
54 unsigned int midi_output_ports;
56 struct amdtp_stream *master;
57 struct amdtp_stream tx_stream;
58 struct amdtp_stream rx_stream;
59 struct cmp_connection out_conn;
60 struct cmp_connection in_conn;
61 atomic_t capture_substreams;
62 atomic_t playback_substreams;
64 struct snd_bebob_stream_formation
65 tx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];
66 struct snd_bebob_stream_formation
67 rx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];
73 snd_bebob_read_block(struct fw_unit *unit, u64 addr, void *buf, int size)
75 return snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST,
76 BEBOB_ADDR_REG_INFO + addr,
81 snd_bebob_read_quad(struct fw_unit *unit, u64 addr, u32 *buf)
83 return snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
84 BEBOB_ADDR_REG_INFO + addr,
85 (void *)buf, sizeof(u32), 0);
89 * AVC command extensions, AV/C Unit and Subunit, Revision 17
90 * (Nov 2003, BridgeCo)
92 #define AVC_BRIDGECO_ADDR_BYTES 6
93 enum avc_bridgeco_plug_dir {
94 AVC_BRIDGECO_PLUG_DIR_IN = 0x00,
95 AVC_BRIDGECO_PLUG_DIR_OUT = 0x01
97 enum avc_bridgeco_plug_mode {
98 AVC_BRIDGECO_PLUG_MODE_UNIT = 0x00,
99 AVC_BRIDGECO_PLUG_MODE_SUBUNIT = 0x01,
100 AVC_BRIDGECO_PLUG_MODE_FUNCTION_BLOCK = 0x02
102 enum avc_bridgeco_plug_unit {
103 AVC_BRIDGECO_PLUG_UNIT_ISOC = 0x00,
104 AVC_BRIDGECO_PLUG_UNIT_EXT = 0x01,
105 AVC_BRIDGECO_PLUG_UNIT_ASYNC = 0x02
107 enum avc_bridgeco_plug_type {
108 AVC_BRIDGECO_PLUG_TYPE_ISOC = 0x00,
109 AVC_BRIDGECO_PLUG_TYPE_ASYNC = 0x01,
110 AVC_BRIDGECO_PLUG_TYPE_MIDI = 0x02,
111 AVC_BRIDGECO_PLUG_TYPE_SYNC = 0x03,
112 AVC_BRIDGECO_PLUG_TYPE_ANA = 0x04,
113 AVC_BRIDGECO_PLUG_TYPE_DIG = 0x05
116 avc_bridgeco_fill_unit_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],
117 enum avc_bridgeco_plug_dir dir,
118 enum avc_bridgeco_plug_unit unit,
121 buf[0] = 0xff; /* Unit */
123 buf[2] = AVC_BRIDGECO_PLUG_MODE_UNIT;
126 buf[5] = 0xff; /* reserved */
129 avc_bridgeco_fill_msu_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],
130 enum avc_bridgeco_plug_dir dir,
133 buf[0] = 0x60; /* Music subunit */
135 buf[2] = AVC_BRIDGECO_PLUG_MODE_SUBUNIT;
137 buf[4] = 0xff; /* reserved */
138 buf[5] = 0xff; /* reserved */
140 int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit,
141 u8 addr[AVC_BRIDGECO_ADDR_BYTES],
142 u8 *buf, unsigned int len);
143 int avc_bridgeco_get_plug_type(struct fw_unit *unit,
144 u8 addr[AVC_BRIDGECO_ADDR_BYTES],
145 enum avc_bridgeco_plug_type *type);
146 int avc_bridgeco_get_plug_section_type(struct fw_unit *unit,
147 u8 addr[AVC_BRIDGECO_ADDR_BYTES],
148 unsigned int id, u8 *type);
149 int avc_bridgeco_get_plug_input(struct fw_unit *unit,
150 u8 addr[AVC_BRIDGECO_ADDR_BYTES],
152 int avc_bridgeco_get_plug_strm_fmt(struct fw_unit *unit,
153 u8 addr[AVC_BRIDGECO_ADDR_BYTES], u8 *buf,
154 unsigned int *len, unsigned int eid);
156 /* for AMDTP streaming */
157 int snd_bebob_stream_get_rate(struct snd_bebob *bebob, unsigned int *rate);
158 int snd_bebob_stream_set_rate(struct snd_bebob *bebob, unsigned int rate);
159 int snd_bebob_stream_check_internal_clock(struct snd_bebob *bebob,
161 int snd_bebob_stream_discover(struct snd_bebob *bebob);
162 int snd_bebob_stream_map(struct snd_bebob *bebob,
163 struct amdtp_stream *stream);
164 int snd_bebob_stream_init_duplex(struct snd_bebob *bebob);
165 int snd_bebob_stream_start_duplex(struct snd_bebob *bebob, int rate);
166 void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob);
167 void snd_bebob_stream_update_duplex(struct snd_bebob *bebob);
168 void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob);
170 #define SND_BEBOB_DEV_ENTRY(vendor, model) \
172 .match_flags = IEEE1394_MATCH_VENDOR_ID | \
173 IEEE1394_MATCH_MODEL_ID, \
174 .vendor_id = vendor, \