8fba87d83810defa5a2bbc99b4f572a5dc5722cf
[deliverable/linux.git] / sound / firewire / dice / dice.h
1 /*
2 * dice.h - a part of driver for Dice based devices
3 *
4 * Copyright (c) Clemens Ladisch
5 * Copyright (c) 2014 Takashi Sakamoto
6 *
7 * Licensed under the terms of the GNU General Public License, version 2.
8 */
9
10 #ifndef SOUND_DICE_H_INCLUDED
11 #define SOUND_DICE_H_INCLUDED
12
13 #include <linux/compat.h>
14 #include <linux/completion.h>
15 #include <linux/delay.h>
16 #include <linux/device.h>
17 #include <linux/firewire.h>
18 #include <linux/firewire-constants.h>
19 #include <linux/jiffies.h>
20 #include <linux/module.h>
21 #include <linux/mod_devicetable.h>
22 #include <linux/mutex.h>
23 #include <linux/slab.h>
24 #include <linux/spinlock.h>
25 #include <linux/wait.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 * This module support maximum 2 pairs of tx/rx isochronous streams for
44 * our convinience.
45 *
46 * In documents for ASICs called with a name of 'DICE':
47 * - ASIC for DICE II:
48 * - Maximum 2 tx and 4 rx are supported.
49 * - A packet supports maximum 16 data channels.
50 * - TCD2210/2210-E (so-called 'Dice Mini'):
51 * - Maximum 2 tx and 2 rx are supported.
52 * - A packet supports maximum 16 data channels.
53 * - TCD2220/2220-E (so-called 'Dice Jr.')
54 * - 2 tx and 2 rx are supported.
55 * - A packet supports maximum 16 data channels.
56 * - TCD3070-CH (so-called 'Dice III')
57 * - Maximum 2 tx and 2 rx are supported.
58 * - A packet supports maximum 32 data channels.
59 *
60 * For the above, MIDI conformant data channel is just on the first isochronous
61 * stream.
62 */
63 #define MAX_STREAMS 2
64
65 struct snd_dice {
66 struct snd_card *card;
67 struct fw_unit *unit;
68 spinlock_t lock;
69 struct mutex mutex;
70
71 bool registered;
72 struct delayed_work dwork;
73
74 /* Offsets for sub-addresses */
75 unsigned int global_offset;
76 unsigned int rx_offset;
77 unsigned int tx_offset;
78 unsigned int sync_offset;
79 unsigned int rsrv_offset;
80
81 unsigned int clock_caps;
82
83 struct fw_address_handler notification_handler;
84 int owner_generation;
85 u32 notification_bits;
86
87 /* For uapi */
88 int dev_lock_count; /* > 0 driver, < 0 userspace */
89 bool dev_lock_changed;
90 wait_queue_head_t hwdep_wait;
91
92 /* For streaming */
93 struct fw_iso_resources tx_resources[MAX_STREAMS];
94 struct fw_iso_resources rx_resources[MAX_STREAMS];
95 struct amdtp_stream tx_stream[MAX_STREAMS];
96 struct amdtp_stream rx_stream[MAX_STREAMS];
97 bool global_enabled;
98 struct completion clock_accepted;
99 unsigned int substreams_counter;
100 };
101
102 enum snd_dice_addr_type {
103 SND_DICE_ADDR_TYPE_PRIVATE,
104 SND_DICE_ADDR_TYPE_GLOBAL,
105 SND_DICE_ADDR_TYPE_TX,
106 SND_DICE_ADDR_TYPE_RX,
107 SND_DICE_ADDR_TYPE_SYNC,
108 SND_DICE_ADDR_TYPE_RSRV,
109 };
110
111 int snd_dice_transaction_write(struct snd_dice *dice,
112 enum snd_dice_addr_type type,
113 unsigned int offset,
114 void *buf, unsigned int len);
115 int snd_dice_transaction_read(struct snd_dice *dice,
116 enum snd_dice_addr_type type, unsigned int offset,
117 void *buf, unsigned int len);
118
119 static inline int snd_dice_transaction_write_global(struct snd_dice *dice,
120 unsigned int offset,
121 void *buf, unsigned int len)
122 {
123 return snd_dice_transaction_write(dice,
124 SND_DICE_ADDR_TYPE_GLOBAL, offset,
125 buf, len);
126 }
127 static inline int snd_dice_transaction_read_global(struct snd_dice *dice,
128 unsigned int offset,
129 void *buf, unsigned int len)
130 {
131 return snd_dice_transaction_read(dice,
132 SND_DICE_ADDR_TYPE_GLOBAL, offset,
133 buf, len);
134 }
135 static inline int snd_dice_transaction_write_tx(struct snd_dice *dice,
136 unsigned int offset,
137 void *buf, unsigned int len)
138 {
139 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_TX, offset,
140 buf, len);
141 }
142 static inline int snd_dice_transaction_read_tx(struct snd_dice *dice,
143 unsigned int offset,
144 void *buf, unsigned int len)
145 {
146 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_TX, offset,
147 buf, len);
148 }
149 static inline int snd_dice_transaction_write_rx(struct snd_dice *dice,
150 unsigned int offset,
151 void *buf, unsigned int len)
152 {
153 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_RX, offset,
154 buf, len);
155 }
156 static inline int snd_dice_transaction_read_rx(struct snd_dice *dice,
157 unsigned int offset,
158 void *buf, unsigned int len)
159 {
160 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_RX, offset,
161 buf, len);
162 }
163 static inline int snd_dice_transaction_write_sync(struct snd_dice *dice,
164 unsigned int offset,
165 void *buf, unsigned int len)
166 {
167 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_SYNC, offset,
168 buf, len);
169 }
170 static inline int snd_dice_transaction_read_sync(struct snd_dice *dice,
171 unsigned int offset,
172 void *buf, unsigned int len)
173 {
174 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_SYNC, offset,
175 buf, len);
176 }
177
178 int snd_dice_transaction_get_clock_source(struct snd_dice *dice,
179 unsigned int *source);
180 int snd_dice_transaction_get_rate(struct snd_dice *dice, unsigned int *rate);
181 int snd_dice_transaction_set_enable(struct snd_dice *dice);
182 void snd_dice_transaction_clear_enable(struct snd_dice *dice);
183 int snd_dice_transaction_init(struct snd_dice *dice);
184 int snd_dice_transaction_reinit(struct snd_dice *dice);
185 void snd_dice_transaction_destroy(struct snd_dice *dice);
186
187 #define SND_DICE_RATES_COUNT 7
188 extern const unsigned int snd_dice_rates[SND_DICE_RATES_COUNT];
189
190 int snd_dice_stream_start_duplex(struct snd_dice *dice, unsigned int rate);
191 void snd_dice_stream_stop_duplex(struct snd_dice *dice);
192 int snd_dice_stream_init_duplex(struct snd_dice *dice);
193 void snd_dice_stream_destroy_duplex(struct snd_dice *dice);
194 void snd_dice_stream_update_duplex(struct snd_dice *dice);
195
196 int snd_dice_stream_lock_try(struct snd_dice *dice);
197 void snd_dice_stream_lock_release(struct snd_dice *dice);
198
199 int snd_dice_create_pcm(struct snd_dice *dice);
200
201 int snd_dice_create_hwdep(struct snd_dice *dice);
202
203 void snd_dice_create_proc(struct snd_dice *dice);
204
205 int snd_dice_create_midi(struct snd_dice *dice);
206
207 #endif
This page took 0.057388 seconds and 4 git commands to generate.