0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef SOUND_DICE_H_INCLUDED
0010 #define SOUND_DICE_H_INCLUDED
0011
0012 #include <linux/compat.h>
0013 #include <linux/completion.h>
0014 #include <linux/delay.h>
0015 #include <linux/device.h>
0016 #include <linux/firewire.h>
0017 #include <linux/firewire-constants.h>
0018 #include <linux/jiffies.h>
0019 #include <linux/module.h>
0020 #include <linux/mod_devicetable.h>
0021 #include <linux/mutex.h>
0022 #include <linux/slab.h>
0023 #include <linux/spinlock.h>
0024 #include <linux/wait.h>
0025 #include <linux/sched/signal.h>
0026
0027 #include <sound/control.h>
0028 #include <sound/core.h>
0029 #include <sound/firewire.h>
0030 #include <sound/hwdep.h>
0031 #include <sound/info.h>
0032 #include <sound/initval.h>
0033 #include <sound/pcm.h>
0034 #include <sound/pcm_params.h>
0035 #include <sound/rawmidi.h>
0036
0037 #include "../amdtp-am824.h"
0038 #include "../iso-resources.h"
0039 #include "../lib.h"
0040 #include "dice-interface.h"
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 #define MAX_STREAMS 2
0064
0065 enum snd_dice_rate_mode {
0066 SND_DICE_RATE_MODE_LOW = 0,
0067 SND_DICE_RATE_MODE_MIDDLE,
0068 SND_DICE_RATE_MODE_HIGH,
0069 SND_DICE_RATE_MODE_COUNT,
0070 };
0071
0072 struct snd_dice;
0073 typedef int (*snd_dice_detect_formats_t)(struct snd_dice *dice);
0074
0075 struct snd_dice {
0076 struct snd_card *card;
0077 struct fw_unit *unit;
0078 spinlock_t lock;
0079 struct mutex mutex;
0080
0081
0082 unsigned int global_offset;
0083 unsigned int rx_offset;
0084 unsigned int tx_offset;
0085 unsigned int sync_offset;
0086 unsigned int rsrv_offset;
0087
0088 unsigned int clock_caps;
0089 unsigned int tx_pcm_chs[MAX_STREAMS][SND_DICE_RATE_MODE_COUNT];
0090 unsigned int rx_pcm_chs[MAX_STREAMS][SND_DICE_RATE_MODE_COUNT];
0091 unsigned int tx_midi_ports[MAX_STREAMS];
0092 unsigned int rx_midi_ports[MAX_STREAMS];
0093
0094 struct fw_address_handler notification_handler;
0095 int owner_generation;
0096 u32 notification_bits;
0097
0098
0099 int dev_lock_count;
0100 bool dev_lock_changed;
0101 wait_queue_head_t hwdep_wait;
0102
0103
0104 struct fw_iso_resources tx_resources[MAX_STREAMS];
0105 struct fw_iso_resources rx_resources[MAX_STREAMS];
0106 struct amdtp_stream tx_stream[MAX_STREAMS];
0107 struct amdtp_stream rx_stream[MAX_STREAMS];
0108 bool global_enabled:1;
0109 bool disable_double_pcm_frames:1;
0110 struct completion clock_accepted;
0111 unsigned int substreams_counter;
0112
0113 struct amdtp_domain domain;
0114 };
0115
0116 enum snd_dice_addr_type {
0117 SND_DICE_ADDR_TYPE_PRIVATE,
0118 SND_DICE_ADDR_TYPE_GLOBAL,
0119 SND_DICE_ADDR_TYPE_TX,
0120 SND_DICE_ADDR_TYPE_RX,
0121 SND_DICE_ADDR_TYPE_SYNC,
0122 SND_DICE_ADDR_TYPE_RSRV,
0123 };
0124
0125 int snd_dice_transaction_write(struct snd_dice *dice,
0126 enum snd_dice_addr_type type,
0127 unsigned int offset,
0128 void *buf, unsigned int len);
0129 int snd_dice_transaction_read(struct snd_dice *dice,
0130 enum snd_dice_addr_type type, unsigned int offset,
0131 void *buf, unsigned int len);
0132
0133 static inline int snd_dice_transaction_write_global(struct snd_dice *dice,
0134 unsigned int offset,
0135 void *buf, unsigned int len)
0136 {
0137 return snd_dice_transaction_write(dice,
0138 SND_DICE_ADDR_TYPE_GLOBAL, offset,
0139 buf, len);
0140 }
0141 static inline int snd_dice_transaction_read_global(struct snd_dice *dice,
0142 unsigned int offset,
0143 void *buf, unsigned int len)
0144 {
0145 return snd_dice_transaction_read(dice,
0146 SND_DICE_ADDR_TYPE_GLOBAL, offset,
0147 buf, len);
0148 }
0149 static inline int snd_dice_transaction_write_tx(struct snd_dice *dice,
0150 unsigned int offset,
0151 void *buf, unsigned int len)
0152 {
0153 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_TX, offset,
0154 buf, len);
0155 }
0156 static inline int snd_dice_transaction_read_tx(struct snd_dice *dice,
0157 unsigned int offset,
0158 void *buf, unsigned int len)
0159 {
0160 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_TX, offset,
0161 buf, len);
0162 }
0163 static inline int snd_dice_transaction_write_rx(struct snd_dice *dice,
0164 unsigned int offset,
0165 void *buf, unsigned int len)
0166 {
0167 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_RX, offset,
0168 buf, len);
0169 }
0170 static inline int snd_dice_transaction_read_rx(struct snd_dice *dice,
0171 unsigned int offset,
0172 void *buf, unsigned int len)
0173 {
0174 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_RX, offset,
0175 buf, len);
0176 }
0177 static inline int snd_dice_transaction_write_sync(struct snd_dice *dice,
0178 unsigned int offset,
0179 void *buf, unsigned int len)
0180 {
0181 return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_SYNC, offset,
0182 buf, len);
0183 }
0184 static inline int snd_dice_transaction_read_sync(struct snd_dice *dice,
0185 unsigned int offset,
0186 void *buf, unsigned int len)
0187 {
0188 return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_SYNC, offset,
0189 buf, len);
0190 }
0191
0192 int snd_dice_transaction_get_clock_source(struct snd_dice *dice,
0193 unsigned int *source);
0194 int snd_dice_transaction_get_rate(struct snd_dice *dice, unsigned int *rate);
0195 int snd_dice_transaction_set_enable(struct snd_dice *dice);
0196 void snd_dice_transaction_clear_enable(struct snd_dice *dice);
0197 int snd_dice_transaction_init(struct snd_dice *dice);
0198 int snd_dice_transaction_reinit(struct snd_dice *dice);
0199 void snd_dice_transaction_destroy(struct snd_dice *dice);
0200
0201 #define SND_DICE_RATES_COUNT 7
0202 extern const unsigned int snd_dice_rates[SND_DICE_RATES_COUNT];
0203
0204 int snd_dice_stream_get_rate_mode(struct snd_dice *dice, unsigned int rate,
0205 enum snd_dice_rate_mode *mode);
0206 int snd_dice_stream_start_duplex(struct snd_dice *dice);
0207 void snd_dice_stream_stop_duplex(struct snd_dice *dice);
0208 int snd_dice_stream_init_duplex(struct snd_dice *dice);
0209 void snd_dice_stream_destroy_duplex(struct snd_dice *dice);
0210 int snd_dice_stream_reserve_duplex(struct snd_dice *dice, unsigned int rate,
0211 unsigned int events_per_period,
0212 unsigned int events_per_buffer);
0213 void snd_dice_stream_update_duplex(struct snd_dice *dice);
0214 int snd_dice_stream_detect_current_formats(struct snd_dice *dice);
0215
0216 int snd_dice_stream_lock_try(struct snd_dice *dice);
0217 void snd_dice_stream_lock_release(struct snd_dice *dice);
0218
0219 int snd_dice_create_pcm(struct snd_dice *dice);
0220
0221 int snd_dice_create_hwdep(struct snd_dice *dice);
0222
0223 void snd_dice_create_proc(struct snd_dice *dice);
0224
0225 int snd_dice_create_midi(struct snd_dice *dice);
0226
0227 int snd_dice_detect_tcelectronic_formats(struct snd_dice *dice);
0228 int snd_dice_detect_alesis_formats(struct snd_dice *dice);
0229 int snd_dice_detect_alesis_mastercontrol_formats(struct snd_dice *dice);
0230 int snd_dice_detect_extension_formats(struct snd_dice *dice);
0231 int snd_dice_detect_mytek_formats(struct snd_dice *dice);
0232 int snd_dice_detect_presonus_formats(struct snd_dice *dice);
0233 int snd_dice_detect_harman_formats(struct snd_dice *dice);
0234
0235 #endif