ALSA: dice: Support for non SYT-Match sampling clock source mode
[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
36 #include "../amdtp.h"
37 #include "../iso-resources.h"
38 #include "../lib.h"
39 #include "dice-interface.h"
40
41 struct snd_dice {
42 struct snd_card *card;
43 struct fw_unit *unit;
44 spinlock_t lock;
45 struct mutex mutex;
46
47 /* Offsets for sub-addresses */
48 unsigned int global_offset;
49 unsigned int rx_offset;
50 unsigned int tx_offset;
51 unsigned int sync_offset;
52 unsigned int rsrv_offset;
53
54 unsigned int clock_caps;
55 unsigned int tx_channels[3];
56 unsigned int rx_channels[3];
57 unsigned int tx_midi_ports[3];
58 unsigned int rx_midi_ports[3];
59
60 struct fw_address_handler notification_handler;
61 int owner_generation;
62 u32 notification_bits;
63
64 /* For uapi */
65 int dev_lock_count; /* > 0 driver, < 0 userspace */
66 bool dev_lock_changed;
67 wait_queue_head_t hwdep_wait;
68
69 /* For streaming */
70 struct fw_iso_resources tx_resources;
71 struct fw_iso_resources rx_resources;
72 struct amdtp_stream tx_stream;
73 struct amdtp_stream rx_stream;
74 bool global_enabled;
75 struct completion clock_accepted;
76 unsigned int substreams_counter;
77 };
78
79 enum snd_dice_addr_type {
80 SND_DICE_ADDR_TYPE_PRIVATE,
81 SND_DICE_ADDR_TYPE_GLOBAL,
82 SND_DICE_ADDR_TYPE_TX,
83 SND_DICE_ADDR_TYPE_RX,
84 SND_DICE_ADDR_TYPE_SYNC,
85 SND_DICE_ADDR_TYPE_RSRV,
86 };
87
88 int snd_dice_transaction_write(struct snd_dice *dice,
89 enum snd_dice_addr_type type,
90 unsigned int offset,
91 void *buf, unsigned int len);
92 int snd_dice_transaction_read(struct snd_dice *dice,
93 enum snd_dice_addr_type type, unsigned int offset,
94 void *buf, unsigned int len);
95
96 static inline int snd_dice_transaction_write_global(struct snd_dice *dice,
97 unsigned int offset,
98 void *buf, unsigned int len)
99 {
100 return snd_dice_transaction_write(dice,
101 SND_DICE_ADDR_TYPE_GLOBAL, offset,
102 buf, len);
103 }
104 static inline int snd_dice_transaction_read_global(struct snd_dice *dice,
105 unsigned int offset,
106 void *buf, unsigned int len)
107 {
108 return snd_dice_transaction_read(dice,
109 SND_DICE_ADDR_TYPE_GLOBAL, offset,
110 buf, len);
111 }
112 static inline int snd_dice_transaction_write_tx(struct snd_dice *dice,
113 unsigned int offset,
114 void *buf, unsigned int len)
115 {
116 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_TX, offset,
117 buf, len);
118 }
119 static inline int snd_dice_transaction_read_tx(struct snd_dice *dice,
120 unsigned int offset,
121 void *buf, unsigned int len)
122 {
123 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_TX, offset,
124 buf, len);
125 }
126 static inline int snd_dice_transaction_write_rx(struct snd_dice *dice,
127 unsigned int offset,
128 void *buf, unsigned int len)
129 {
130 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_RX, offset,
131 buf, len);
132 }
133 static inline int snd_dice_transaction_read_rx(struct snd_dice *dice,
134 unsigned int offset,
135 void *buf, unsigned int len)
136 {
137 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_RX, offset,
138 buf, len);
139 }
140 static inline int snd_dice_transaction_write_sync(struct snd_dice *dice,
141 unsigned int offset,
142 void *buf, unsigned int len)
143 {
144 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_SYNC, offset,
145 buf, len);
146 }
147 static inline int snd_dice_transaction_read_sync(struct snd_dice *dice,
148 unsigned int offset,
149 void *buf, unsigned int len)
150 {
151 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_SYNC, offset,
152 buf, len);
153 }
154
155 int snd_dice_transaction_get_clock_source(struct snd_dice *dice,
156 unsigned int *source);
157 int snd_dice_transaction_set_rate(struct snd_dice *dice, unsigned int rate);
158 int snd_dice_transaction_get_rate(struct snd_dice *dice, unsigned int *rate);
159 int snd_dice_transaction_set_enable(struct snd_dice *dice);
160 void snd_dice_transaction_clear_enable(struct snd_dice *dice);
161 int snd_dice_transaction_init(struct snd_dice *dice);
162 int snd_dice_transaction_reinit(struct snd_dice *dice);
163 void snd_dice_transaction_destroy(struct snd_dice *dice);
164
165 #define SND_DICE_RATES_COUNT 7
166 extern const unsigned int snd_dice_rates[SND_DICE_RATES_COUNT];
167
168 int snd_dice_stream_get_rate_mode(struct snd_dice *dice,
169 unsigned int rate, unsigned int *mode);
170
171 int snd_dice_stream_start_duplex(struct snd_dice *dice, unsigned int rate);
172 void snd_dice_stream_stop_duplex(struct snd_dice *dice);
173 int snd_dice_stream_init_duplex(struct snd_dice *dice);
174 void snd_dice_stream_destroy_duplex(struct snd_dice *dice);
175 void snd_dice_stream_update_duplex(struct snd_dice *dice);
176
177 int snd_dice_stream_lock_try(struct snd_dice *dice);
178 void snd_dice_stream_lock_release(struct snd_dice *dice);
179
180 int snd_dice_create_pcm(struct snd_dice *dice);
181
182 int snd_dice_create_hwdep(struct snd_dice *dice);
183
184 void snd_dice_create_proc(struct snd_dice *dice);
185
186 #endif
This page took 0.033897 seconds and 5 git commands to generate.