blob: e6c07857f4755fb1963d09ae2091f66f5ffef0f3 [file] [log] [blame]
Takashi Sakamoto7c2d4c02014-11-29 00:59:13 +09001/*
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>
Takashi Sakamotoa113ff82014-12-09 00:10:39 +090035#include <sound/rawmidi.h>
Takashi Sakamoto7c2d4c02014-11-29 00:59:13 +090036
Takashi Sakamoto59558152015-09-19 11:21:55 +090037#include "../amdtp-am824.h"
Takashi Sakamoto7c2d4c02014-11-29 00:59:13 +090038#include "../iso-resources.h"
39#include "../lib.h"
40#include "dice-interface.h"
41
Takashi Sakamoto8ae25b762016-03-07 22:35:42 +090042/*
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
Takashi Sakamoto7c2d4c02014-11-29 00:59:13 +090065struct snd_dice {
66 struct snd_card *card;
67 struct fw_unit *unit;
68 spinlock_t lock;
69 struct mutex mutex;
70
Takashi Sakamotob59fb192015-12-31 13:58:12 +090071 bool registered;
72 struct delayed_work dwork;
73
Takashi Sakamoto7c2d4c02014-11-29 00:59:13 +090074 /* 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;
Takashi Sakamoto9a028432014-12-09 00:10:36 +090082
Takashi Sakamoto7c2d4c02014-11-29 00:59:13 +090083 struct fw_address_handler notification_handler;
84 int owner_generation;
Takashi Sakamoto9a028432014-12-09 00:10:36 +090085 u32 notification_bits;
86
87 /* For uapi */
Takashi Sakamoto7c2d4c02014-11-29 00:59:13 +090088 int dev_lock_count; /* > 0 driver, < 0 userspace */
89 bool dev_lock_changed;
Takashi Sakamoto9a028432014-12-09 00:10:36 +090090 wait_queue_head_t hwdep_wait;
91
92 /* For streaming */
Takashi Sakamoto8ae25b762016-03-07 22:35:42 +090093 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];
Takashi Sakamoto7c2d4c02014-11-29 00:59:13 +090097 bool global_enabled;
98 struct completion clock_accepted;
Takashi Sakamoto9a028432014-12-09 00:10:36 +090099 unsigned int substreams_counter;
Takashi Sakamoto7cafc652016-03-07 22:35:45 +0900100
101 bool force_two_pcms;
Takashi Sakamoto7c2d4c02014-11-29 00:59:13 +0900102};
103
104enum snd_dice_addr_type {
105 SND_DICE_ADDR_TYPE_PRIVATE,
106 SND_DICE_ADDR_TYPE_GLOBAL,
107 SND_DICE_ADDR_TYPE_TX,
108 SND_DICE_ADDR_TYPE_RX,
109 SND_DICE_ADDR_TYPE_SYNC,
110 SND_DICE_ADDR_TYPE_RSRV,
111};
112
113int snd_dice_transaction_write(struct snd_dice *dice,
114 enum snd_dice_addr_type type,
115 unsigned int offset,
116 void *buf, unsigned int len);
117int snd_dice_transaction_read(struct snd_dice *dice,
118 enum snd_dice_addr_type type, unsigned int offset,
119 void *buf, unsigned int len);
120
121static inline int snd_dice_transaction_write_global(struct snd_dice *dice,
122 unsigned int offset,
123 void *buf, unsigned int len)
124{
125 return snd_dice_transaction_write(dice,
126 SND_DICE_ADDR_TYPE_GLOBAL, offset,
127 buf, len);
128}
129static inline int snd_dice_transaction_read_global(struct snd_dice *dice,
130 unsigned int offset,
131 void *buf, unsigned int len)
132{
133 return snd_dice_transaction_read(dice,
134 SND_DICE_ADDR_TYPE_GLOBAL, offset,
135 buf, len);
136}
137static inline int snd_dice_transaction_write_tx(struct snd_dice *dice,
138 unsigned int offset,
139 void *buf, unsigned int len)
140{
141 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_TX, offset,
142 buf, len);
143}
144static inline int snd_dice_transaction_read_tx(struct snd_dice *dice,
145 unsigned int offset,
146 void *buf, unsigned int len)
147{
148 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_TX, offset,
149 buf, len);
150}
151static inline int snd_dice_transaction_write_rx(struct snd_dice *dice,
152 unsigned int offset,
153 void *buf, unsigned int len)
154{
155 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_RX, offset,
156 buf, len);
157}
158static inline int snd_dice_transaction_read_rx(struct snd_dice *dice,
159 unsigned int offset,
160 void *buf, unsigned int len)
161{
162 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_RX, offset,
163 buf, len);
164}
165static inline int snd_dice_transaction_write_sync(struct snd_dice *dice,
166 unsigned int offset,
167 void *buf, unsigned int len)
168{
169 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_SYNC, offset,
170 buf, len);
171}
172static inline int snd_dice_transaction_read_sync(struct snd_dice *dice,
173 unsigned int offset,
174 void *buf, unsigned int len)
175{
176 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_SYNC, offset,
177 buf, len);
178}
179
Takashi Sakamoto7c2d4c02014-11-29 00:59:13 +0900180int snd_dice_transaction_get_clock_source(struct snd_dice *dice,
181 unsigned int *source);
Takashi Sakamoto7c2d4c02014-11-29 00:59:13 +0900182int snd_dice_transaction_get_rate(struct snd_dice *dice, unsigned int *rate);
183int snd_dice_transaction_set_enable(struct snd_dice *dice);
184void snd_dice_transaction_clear_enable(struct snd_dice *dice);
185int snd_dice_transaction_init(struct snd_dice *dice);
186int snd_dice_transaction_reinit(struct snd_dice *dice);
187void snd_dice_transaction_destroy(struct snd_dice *dice);
188
189#define SND_DICE_RATES_COUNT 7
190extern const unsigned int snd_dice_rates[SND_DICE_RATES_COUNT];
191
Takashi Sakamoto9a028432014-12-09 00:10:36 +0900192int snd_dice_stream_start_duplex(struct snd_dice *dice, unsigned int rate);
193void snd_dice_stream_stop_duplex(struct snd_dice *dice);
194int snd_dice_stream_init_duplex(struct snd_dice *dice);
195void snd_dice_stream_destroy_duplex(struct snd_dice *dice);
196void snd_dice_stream_update_duplex(struct snd_dice *dice);
Takashi Sakamoto6eb6c812014-11-29 00:59:14 +0900197
198int snd_dice_stream_lock_try(struct snd_dice *dice);
199void snd_dice_stream_lock_release(struct snd_dice *dice);
200
Takashi Sakamotoc50fb912014-11-29 00:59:15 +0900201int snd_dice_create_pcm(struct snd_dice *dice);
202
Takashi Sakamoto19af57b2014-11-29 00:59:16 +0900203int snd_dice_create_hwdep(struct snd_dice *dice);
204
Takashi Sakamoto04d426a2014-11-29 00:59:17 +0900205void snd_dice_create_proc(struct snd_dice *dice);
206
Takashi Sakamotoa113ff82014-12-09 00:10:39 +0900207int snd_dice_create_midi(struct snd_dice *dice);
208
Takashi Sakamoto7c2d4c02014-11-29 00:59:13 +0900209#endif