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