1
2
3
4
5
6
7
8
9#ifndef SOUND_DICE_H_INCLUDED
10#define SOUND_DICE_H_INCLUDED
11
12#include <linux/compat.h>
13#include <linux/completion.h>
14#include <linux/delay.h>
15#include <linux/device.h>
16#include <linux/firewire.h>
17#include <linux/firewire-constants.h>
18#include <linux/jiffies.h>
19#include <linux/module.h>
20#include <linux/mod_devicetable.h>
21#include <linux/mutex.h>
22#include <linux/slab.h>
23#include <linux/spinlock.h>
24#include <linux/wait.h>
25#include <linux/sched/signal.h>
26
27#include <sound/control.h>
28#include <sound/core.h>
29#include <sound/firewire.h>
30#include <sound/hwdep.h>
31#include <sound/info.h>
32#include <sound/initval.h>
33#include <sound/pcm.h>
34#include <sound/pcm_params.h>
35#include <sound/rawmidi.h>
36
37#include "../amdtp-am824.h"
38#include "../iso-resources.h"
39#include "../lib.h"
40#include "dice-interface.h"
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63#define MAX_STREAMS 2
64
65enum snd_dice_rate_mode {
66 SND_DICE_RATE_MODE_LOW = 0,
67 SND_DICE_RATE_MODE_MIDDLE,
68 SND_DICE_RATE_MODE_HIGH,
69 SND_DICE_RATE_MODE_COUNT,
70};
71
72struct snd_dice;
73typedef int (*snd_dice_detect_formats_t)(struct snd_dice *dice);
74
75struct snd_dice {
76 struct snd_card *card;
77 struct fw_unit *unit;
78 spinlock_t lock;
79 struct mutex mutex;
80
81 bool registered;
82 struct delayed_work dwork;
83
84
85 unsigned int global_offset;
86 unsigned int rx_offset;
87 unsigned int tx_offset;
88 unsigned int sync_offset;
89 unsigned int rsrv_offset;
90
91 unsigned int clock_caps;
92 unsigned int tx_pcm_chs[MAX_STREAMS][SND_DICE_RATE_MODE_COUNT];
93 unsigned int rx_pcm_chs[MAX_STREAMS][SND_DICE_RATE_MODE_COUNT];
94 unsigned int tx_midi_ports[MAX_STREAMS];
95 unsigned int rx_midi_ports[MAX_STREAMS];
96 snd_dice_detect_formats_t detect_formats;
97
98 struct fw_address_handler notification_handler;
99 int owner_generation;
100 u32 notification_bits;
101
102
103 int dev_lock_count;
104 bool dev_lock_changed;
105 wait_queue_head_t hwdep_wait;
106
107
108 struct fw_iso_resources tx_resources[MAX_STREAMS];
109 struct fw_iso_resources rx_resources[MAX_STREAMS];
110 struct amdtp_stream tx_stream[MAX_STREAMS];
111 struct amdtp_stream rx_stream[MAX_STREAMS];
112 bool global_enabled;
113 struct completion clock_accepted;
114 unsigned int substreams_counter;
115};
116
117enum snd_dice_addr_type {
118 SND_DICE_ADDR_TYPE_PRIVATE,
119 SND_DICE_ADDR_TYPE_GLOBAL,
120 SND_DICE_ADDR_TYPE_TX,
121 SND_DICE_ADDR_TYPE_RX,
122 SND_DICE_ADDR_TYPE_SYNC,
123 SND_DICE_ADDR_TYPE_RSRV,
124};
125
126int snd_dice_transaction_write(struct snd_dice *dice,
127 enum snd_dice_addr_type type,
128 unsigned int offset,
129 void *buf, unsigned int len);
130int snd_dice_transaction_read(struct snd_dice *dice,
131 enum snd_dice_addr_type type, unsigned int offset,
132 void *buf, unsigned int len);
133
134static inline int snd_dice_transaction_write_global(struct snd_dice *dice,
135 unsigned int offset,
136 void *buf, unsigned int len)
137{
138 return snd_dice_transaction_write(dice,
139 SND_DICE_ADDR_TYPE_GLOBAL, offset,
140 buf, len);
141}
142static inline int snd_dice_transaction_read_global(struct snd_dice *dice,
143 unsigned int offset,
144 void *buf, unsigned int len)
145{
146 return snd_dice_transaction_read(dice,
147 SND_DICE_ADDR_TYPE_GLOBAL, offset,
148 buf, len);
149}
150static inline int snd_dice_transaction_write_tx(struct snd_dice *dice,
151 unsigned int offset,
152 void *buf, unsigned int len)
153{
154 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_TX, offset,
155 buf, len);
156}
157static inline int snd_dice_transaction_read_tx(struct snd_dice *dice,
158 unsigned int offset,
159 void *buf, unsigned int len)
160{
161 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_TX, offset,
162 buf, len);
163}
164static inline int snd_dice_transaction_write_rx(struct snd_dice *dice,
165 unsigned int offset,
166 void *buf, unsigned int len)
167{
168 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_RX, offset,
169 buf, len);
170}
171static inline int snd_dice_transaction_read_rx(struct snd_dice *dice,
172 unsigned int offset,
173 void *buf, unsigned int len)
174{
175 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_RX, offset,
176 buf, len);
177}
178static inline int snd_dice_transaction_write_sync(struct snd_dice *dice,
179 unsigned int offset,
180 void *buf, unsigned int len)
181{
182 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_SYNC, offset,
183 buf, len);
184}
185static inline int snd_dice_transaction_read_sync(struct snd_dice *dice,
186 unsigned int offset,
187 void *buf, unsigned int len)
188{
189 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_SYNC, offset,
190 buf, len);
191}
192
193int snd_dice_transaction_get_clock_source(struct snd_dice *dice,
194 unsigned int *source);
195int snd_dice_transaction_get_rate(struct snd_dice *dice, unsigned int *rate);
196int snd_dice_transaction_set_enable(struct snd_dice *dice);
197void snd_dice_transaction_clear_enable(struct snd_dice *dice);
198int snd_dice_transaction_init(struct snd_dice *dice);
199int snd_dice_transaction_reinit(struct snd_dice *dice);
200void snd_dice_transaction_destroy(struct snd_dice *dice);
201
202#define SND_DICE_RATES_COUNT 7
203extern const unsigned int snd_dice_rates[SND_DICE_RATES_COUNT];
204
205int snd_dice_stream_get_rate_mode(struct snd_dice *dice, unsigned int rate,
206 enum snd_dice_rate_mode *mode);
207int snd_dice_stream_start_duplex(struct snd_dice *dice);
208void snd_dice_stream_stop_duplex(struct snd_dice *dice);
209int snd_dice_stream_init_duplex(struct snd_dice *dice);
210void snd_dice_stream_destroy_duplex(struct snd_dice *dice);
211int snd_dice_stream_reserve_duplex(struct snd_dice *dice, unsigned int rate);
212void snd_dice_stream_update_duplex(struct snd_dice *dice);
213int snd_dice_stream_detect_current_formats(struct snd_dice *dice);
214
215int snd_dice_stream_lock_try(struct snd_dice *dice);
216void snd_dice_stream_lock_release(struct snd_dice *dice);
217
218int snd_dice_create_pcm(struct snd_dice *dice);
219
220int snd_dice_create_hwdep(struct snd_dice *dice);
221
222void snd_dice_create_proc(struct snd_dice *dice);
223
224int snd_dice_create_midi(struct snd_dice *dice);
225
226int snd_dice_detect_tcelectronic_formats(struct snd_dice *dice);
227int snd_dice_detect_alesis_formats(struct snd_dice *dice);
228int snd_dice_detect_extension_formats(struct snd_dice *dice);
229int snd_dice_detect_mytek_formats(struct snd_dice *dice);
230int snd_dice_detect_presonus_formats(struct snd_dice *dice);
231
232#endif
233