Commit | Line | Data |
---|---|---|
fd6f4b0d TS |
1 | /* |
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> | |
ad9697ba | 23 | #include <sound/info.h> |
248b7802 | 24 | #include <sound/rawmidi.h> |
fbbebd2c TS |
25 | #include <sound/pcm.h> |
26 | #include <sound/pcm_params.h> | |
fd6f4b0d TS |
27 | |
28 | #include "../lib.h" | |
29 | #include "../fcp.h" | |
eb7b3a05 TS |
30 | #include "../packets-buffer.h" |
31 | #include "../iso-resources.h" | |
32 | #include "../amdtp.h" | |
33 | #include "../cmp.h" | |
fd6f4b0d TS |
34 | |
35 | /* basic register addresses on DM1000/DM1100/DM1500 */ | |
36 | #define BEBOB_ADDR_REG_INFO 0xffffc8020000 | |
37 | #define BEBOB_ADDR_REG_REQ 0xffffc8021000 | |
38 | ||
eb7b3a05 TS |
39 | struct snd_bebob; |
40 | ||
41 | #define SND_BEBOB_STRM_FMT_ENTRIES 7 | |
42 | struct snd_bebob_stream_formation { | |
43 | unsigned int pcm; | |
44 | unsigned int midi; | |
45 | }; | |
46 | /* this is a lookup table for index of stream formations */ | |
47 | extern const unsigned int snd_bebob_rate_table[SND_BEBOB_STRM_FMT_ENTRIES]; | |
48 | ||
fd6f4b0d TS |
49 | struct snd_bebob { |
50 | struct snd_card *card; | |
51 | struct fw_unit *unit; | |
52 | int card_index; | |
53 | ||
54 | struct mutex mutex; | |
55 | spinlock_t lock; | |
eb7b3a05 TS |
56 | |
57 | unsigned int midi_input_ports; | |
58 | unsigned int midi_output_ports; | |
59 | ||
b6bc8123 TS |
60 | /* for bus reset quirk */ |
61 | struct completion bus_reset; | |
62 | bool connected; | |
63 | ||
eb7b3a05 TS |
64 | struct amdtp_stream *master; |
65 | struct amdtp_stream tx_stream; | |
66 | struct amdtp_stream rx_stream; | |
67 | struct cmp_connection out_conn; | |
68 | struct cmp_connection in_conn; | |
69 | atomic_t capture_substreams; | |
70 | atomic_t playback_substreams; | |
71 | ||
72 | struct snd_bebob_stream_formation | |
73 | tx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES]; | |
74 | struct snd_bebob_stream_formation | |
75 | rx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES]; | |
76 | ||
77 | int sync_input_plug; | |
fd6f4b0d TS |
78 | }; |
79 | ||
80 | static inline int | |
81 | snd_bebob_read_block(struct fw_unit *unit, u64 addr, void *buf, int size) | |
82 | { | |
83 | return snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST, | |
84 | BEBOB_ADDR_REG_INFO + addr, | |
85 | buf, size, 0); | |
86 | } | |
87 | ||
88 | static inline int | |
89 | snd_bebob_read_quad(struct fw_unit *unit, u64 addr, u32 *buf) | |
90 | { | |
91 | return snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST, | |
92 | BEBOB_ADDR_REG_INFO + addr, | |
93 | (void *)buf, sizeof(u32), 0); | |
94 | } | |
95 | ||
eb7b3a05 TS |
96 | /* |
97 | * AVC command extensions, AV/C Unit and Subunit, Revision 17 | |
98 | * (Nov 2003, BridgeCo) | |
99 | */ | |
100 | #define AVC_BRIDGECO_ADDR_BYTES 6 | |
101 | enum avc_bridgeco_plug_dir { | |
102 | AVC_BRIDGECO_PLUG_DIR_IN = 0x00, | |
103 | AVC_BRIDGECO_PLUG_DIR_OUT = 0x01 | |
104 | }; | |
105 | enum avc_bridgeco_plug_mode { | |
106 | AVC_BRIDGECO_PLUG_MODE_UNIT = 0x00, | |
107 | AVC_BRIDGECO_PLUG_MODE_SUBUNIT = 0x01, | |
108 | AVC_BRIDGECO_PLUG_MODE_FUNCTION_BLOCK = 0x02 | |
109 | }; | |
110 | enum avc_bridgeco_plug_unit { | |
111 | AVC_BRIDGECO_PLUG_UNIT_ISOC = 0x00, | |
112 | AVC_BRIDGECO_PLUG_UNIT_EXT = 0x01, | |
113 | AVC_BRIDGECO_PLUG_UNIT_ASYNC = 0x02 | |
114 | }; | |
115 | enum avc_bridgeco_plug_type { | |
116 | AVC_BRIDGECO_PLUG_TYPE_ISOC = 0x00, | |
117 | AVC_BRIDGECO_PLUG_TYPE_ASYNC = 0x01, | |
118 | AVC_BRIDGECO_PLUG_TYPE_MIDI = 0x02, | |
119 | AVC_BRIDGECO_PLUG_TYPE_SYNC = 0x03, | |
120 | AVC_BRIDGECO_PLUG_TYPE_ANA = 0x04, | |
121 | AVC_BRIDGECO_PLUG_TYPE_DIG = 0x05 | |
122 | }; | |
123 | static inline void | |
124 | avc_bridgeco_fill_unit_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES], | |
125 | enum avc_bridgeco_plug_dir dir, | |
126 | enum avc_bridgeco_plug_unit unit, | |
127 | unsigned int pid) | |
128 | { | |
129 | buf[0] = 0xff; /* Unit */ | |
130 | buf[1] = dir; | |
131 | buf[2] = AVC_BRIDGECO_PLUG_MODE_UNIT; | |
132 | buf[3] = unit; | |
133 | buf[4] = 0xff & pid; | |
134 | buf[5] = 0xff; /* reserved */ | |
135 | } | |
136 | static inline void | |
137 | avc_bridgeco_fill_msu_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES], | |
138 | enum avc_bridgeco_plug_dir dir, | |
139 | unsigned int pid) | |
140 | { | |
141 | buf[0] = 0x60; /* Music subunit */ | |
142 | buf[1] = dir; | |
143 | buf[2] = AVC_BRIDGECO_PLUG_MODE_SUBUNIT; | |
144 | buf[3] = 0xff & pid; | |
145 | buf[4] = 0xff; /* reserved */ | |
146 | buf[5] = 0xff; /* reserved */ | |
147 | } | |
148 | int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit, | |
149 | u8 addr[AVC_BRIDGECO_ADDR_BYTES], | |
150 | u8 *buf, unsigned int len); | |
151 | int avc_bridgeco_get_plug_type(struct fw_unit *unit, | |
152 | u8 addr[AVC_BRIDGECO_ADDR_BYTES], | |
153 | enum avc_bridgeco_plug_type *type); | |
154 | int avc_bridgeco_get_plug_section_type(struct fw_unit *unit, | |
155 | u8 addr[AVC_BRIDGECO_ADDR_BYTES], | |
156 | unsigned int id, u8 *type); | |
157 | int avc_bridgeco_get_plug_input(struct fw_unit *unit, | |
158 | u8 addr[AVC_BRIDGECO_ADDR_BYTES], | |
159 | u8 input[7]); | |
160 | int avc_bridgeco_get_plug_strm_fmt(struct fw_unit *unit, | |
161 | u8 addr[AVC_BRIDGECO_ADDR_BYTES], u8 *buf, | |
162 | unsigned int *len, unsigned int eid); | |
163 | ||
164 | /* for AMDTP streaming */ | |
165 | int snd_bebob_stream_get_rate(struct snd_bebob *bebob, unsigned int *rate); | |
166 | int snd_bebob_stream_set_rate(struct snd_bebob *bebob, unsigned int rate); | |
167 | int snd_bebob_stream_check_internal_clock(struct snd_bebob *bebob, | |
168 | bool *internal); | |
169 | int snd_bebob_stream_discover(struct snd_bebob *bebob); | |
170 | int snd_bebob_stream_map(struct snd_bebob *bebob, | |
171 | struct amdtp_stream *stream); | |
172 | int snd_bebob_stream_init_duplex(struct snd_bebob *bebob); | |
173 | int snd_bebob_stream_start_duplex(struct snd_bebob *bebob, int rate); | |
174 | void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob); | |
175 | void snd_bebob_stream_update_duplex(struct snd_bebob *bebob); | |
176 | void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob); | |
177 | ||
ad9697ba TS |
178 | void snd_bebob_proc_init(struct snd_bebob *bebob); |
179 | ||
248b7802 TS |
180 | int snd_bebob_create_midi_devices(struct snd_bebob *bebob); |
181 | ||
fbbebd2c TS |
182 | int snd_bebob_create_pcm_devices(struct snd_bebob *bebob); |
183 | ||
fd6f4b0d TS |
184 | #define SND_BEBOB_DEV_ENTRY(vendor, model) \ |
185 | { \ | |
186 | .match_flags = IEEE1394_MATCH_VENDOR_ID | \ | |
187 | IEEE1394_MATCH_MODEL_ID, \ | |
188 | .vendor_id = vendor, \ | |
189 | .model_id = model, \ | |
190 | } | |
191 | ||
192 | #endif |