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