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