Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * TC Applied Technologies Digital Interface Communications Engine driver |
| 3 | * |
| 4 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> |
| 5 | * Licensed under the terms of the GNU General Public License, version 2. |
| 6 | */ |
| 7 | |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 8 | #include "dice.h" |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 9 | |
| 10 | MODULE_DESCRIPTION("DICE driver"); |
| 11 | MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); |
| 12 | MODULE_LICENSE("GPL v2"); |
| 13 | |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 14 | static int dice_rate_constraint(struct snd_pcm_hw_params *params, |
| 15 | struct snd_pcm_hw_rule *rule) |
| 16 | { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 17 | struct snd_dice *dice = rule->private; |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 18 | |
| 19 | const struct snd_interval *c = |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 20 | hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_CHANNELS); |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 21 | struct snd_interval *r = |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 22 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 23 | struct snd_interval rates = { |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 24 | .min = UINT_MAX, .max = 0, .integer = 1 |
| 25 | }; |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 26 | unsigned int i, rate, mode, *pcm_channels = dice->rx_channels; |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 27 | |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 28 | for (i = 0; i < ARRAY_SIZE(snd_dice_rates); ++i) { |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 29 | rate = snd_dice_rates[i]; |
| 30 | if (snd_dice_stream_get_rate_mode(dice, rate, &mode) < 0) |
| 31 | continue; |
| 32 | |
| 33 | if (!snd_interval_test(c, pcm_channels[mode])) |
| 34 | continue; |
| 35 | |
| 36 | rates.min = min(rates.min, rate); |
| 37 | rates.max = max(rates.max, rate); |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 38 | } |
| 39 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 40 | return snd_interval_refine(r, &rates); |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static int dice_channels_constraint(struct snd_pcm_hw_params *params, |
| 44 | struct snd_pcm_hw_rule *rule) |
| 45 | { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 46 | struct snd_dice *dice = rule->private; |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 47 | |
| 48 | const struct snd_interval *r = |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 49 | hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_RATE); |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 50 | struct snd_interval *c = |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 51 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 52 | struct snd_interval channels = { |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 53 | .min = UINT_MAX, .max = 0, .integer = 1 |
| 54 | }; |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 55 | unsigned int i, rate, mode, *pcm_channels = dice->rx_channels; |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 56 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 57 | for (i = 0; i < ARRAY_SIZE(snd_dice_rates); ++i) { |
| 58 | rate = snd_dice_rates[i]; |
| 59 | if (snd_dice_stream_get_rate_mode(dice, rate, &mode) < 0) |
| 60 | continue; |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 61 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 62 | if (!snd_interval_test(r, rate)) |
| 63 | continue; |
| 64 | |
| 65 | channels.min = min(channels.min, pcm_channels[mode]); |
| 66 | channels.max = max(channels.max, pcm_channels[mode]); |
| 67 | } |
| 68 | |
| 69 | return snd_interval_refine(c, &channels); |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 72 | static int dice_open(struct snd_pcm_substream *substream) |
| 73 | { |
| 74 | static const struct snd_pcm_hardware hardware = { |
| 75 | .info = SNDRV_PCM_INFO_MMAP | |
| 76 | SNDRV_PCM_INFO_MMAP_VALID | |
| 77 | SNDRV_PCM_INFO_BATCH | |
| 78 | SNDRV_PCM_INFO_INTERLEAVED | |
| 79 | SNDRV_PCM_INFO_BLOCK_TRANSFER, |
| 80 | .formats = AMDTP_OUT_PCM_FORMAT_BITS, |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 81 | .channels_min = UINT_MAX, |
| 82 | .channels_max = 0, |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 83 | .buffer_bytes_max = 16 * 1024 * 1024, |
| 84 | .period_bytes_min = 1, |
| 85 | .period_bytes_max = UINT_MAX, |
| 86 | .periods_min = 1, |
| 87 | .periods_max = UINT_MAX, |
| 88 | }; |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 89 | struct snd_dice *dice = substream->private_data; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 90 | struct snd_pcm_runtime *runtime = substream->runtime; |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 91 | unsigned int i; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 92 | int err; |
| 93 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 94 | err = snd_dice_stream_lock_try(dice); |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 95 | if (err < 0) |
| 96 | goto error; |
| 97 | |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 98 | runtime->hw = hardware; |
Clemens Ladisch | 341682c | 2011-09-04 22:12:06 +0200 | [diff] [blame] | 99 | |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 100 | for (i = 0; i < ARRAY_SIZE(snd_dice_rates); ++i) |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 101 | if (dice->clock_caps & (1 << i)) |
| 102 | runtime->hw.rates |= |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 103 | snd_pcm_rate_to_rate_bit(snd_dice_rates[i]); |
Clemens Ladisch | 341682c | 2011-09-04 22:12:06 +0200 | [diff] [blame] | 104 | snd_pcm_limit_hw_rates(runtime); |
| 105 | |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 106 | for (i = 0; i < 3; ++i) |
| 107 | if (dice->rx_channels[i]) { |
| 108 | runtime->hw.channels_min = min(runtime->hw.channels_min, |
| 109 | dice->rx_channels[i]); |
| 110 | runtime->hw.channels_max = max(runtime->hw.channels_max, |
| 111 | dice->rx_channels[i]); |
| 112 | } |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 113 | |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 114 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 115 | dice_rate_constraint, dice, |
| 116 | SNDRV_PCM_HW_PARAM_CHANNELS, -1); |
| 117 | if (err < 0) |
| 118 | goto err_lock; |
| 119 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 120 | dice_channels_constraint, dice, |
| 121 | SNDRV_PCM_HW_PARAM_RATE, -1); |
| 122 | if (err < 0) |
| 123 | goto err_lock; |
Clemens Ladisch | a7304e3 | 2011-09-04 22:16:10 +0200 | [diff] [blame] | 124 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 125 | err = amdtp_stream_add_pcm_hw_constraints(&dice->rx_stream, runtime); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 126 | if (err < 0) |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 127 | goto err_lock; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 128 | |
| 129 | return 0; |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 130 | |
| 131 | err_lock: |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 132 | snd_dice_stream_lock_release(dice); |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 133 | error: |
| 134 | return err; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static int dice_close(struct snd_pcm_substream *substream) |
| 138 | { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 139 | struct snd_dice *dice = substream->private_data; |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 140 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 141 | snd_dice_stream_lock_release(dice); |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 142 | |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 143 | return 0; |
| 144 | } |
| 145 | |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 146 | static int dice_hw_params(struct snd_pcm_substream *substream, |
| 147 | struct snd_pcm_hw_params *hw_params) |
| 148 | { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 149 | struct snd_dice *dice = substream->private_data; |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 150 | unsigned int mode, rate, channels, i; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 151 | int err; |
| 152 | |
| 153 | mutex_lock(&dice->mutex); |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 154 | snd_dice_stream_stop(dice); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 155 | mutex_unlock(&dice->mutex); |
| 156 | |
| 157 | err = snd_pcm_lib_alloc_vmalloc_buffer(substream, |
| 158 | params_buffer_bytes(hw_params)); |
| 159 | if (err < 0) |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 160 | return err; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 161 | |
Takashi Sakamoto | 10550be | 2014-04-25 22:44:51 +0900 | [diff] [blame] | 162 | rate = params_rate(hw_params); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 163 | err = snd_dice_transaction_set_rate(dice, rate); |
Clemens Ladisch | 4edeb83 | 2011-12-04 22:07:01 +0100 | [diff] [blame] | 164 | if (err < 0) |
| 165 | return err; |
| 166 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 167 | err = snd_dice_stream_get_rate_mode(dice, rate, &mode); |
| 168 | if (err < 0) |
| 169 | return err; |
| 170 | |
Takashi Sakamoto | 10550be | 2014-04-25 22:44:51 +0900 | [diff] [blame] | 171 | /* |
Takashi Sakamoto | 65845f2 | 2014-08-29 13:40:45 +0900 | [diff] [blame] | 172 | * At 176.4/192.0 kHz, Dice has a quirk to transfer two PCM frames in |
| 173 | * one data block of AMDTP packet. Thus sampling transfer frequency is |
| 174 | * a half of PCM sampling frequency, i.e. PCM frames at 192.0 kHz are |
| 175 | * transferred on AMDTP packets at 96 kHz. Two successive samples of a |
| 176 | * channel are stored consecutively in the packet. This quirk is called |
| 177 | * as 'Dual Wire'. |
| 178 | * For this quirk, blocking mode is required and PCM buffer size should |
| 179 | * be aligned to SYT_INTERVAL. |
Takashi Sakamoto | 10550be | 2014-04-25 22:44:51 +0900 | [diff] [blame] | 180 | */ |
| 181 | channels = params_channels(hw_params); |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 182 | if (mode > 1) { |
Takashi Sakamoto | 10550be | 2014-04-25 22:44:51 +0900 | [diff] [blame] | 183 | if (channels > AMDTP_MAX_CHANNELS_FOR_PCM / 2) { |
| 184 | err = -ENOSYS; |
| 185 | return err; |
| 186 | } |
| 187 | |
Takashi Sakamoto | 10550be | 2014-04-25 22:44:51 +0900 | [diff] [blame] | 188 | rate /= 2; |
| 189 | channels *= 2; |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 190 | dice->rx_stream.double_pcm_frames = true; |
Takashi Sakamoto | 65845f2 | 2014-08-29 13:40:45 +0900 | [diff] [blame] | 191 | } else { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 192 | dice->rx_stream.double_pcm_frames = false; |
Takashi Sakamoto | 10550be | 2014-04-25 22:44:51 +0900 | [diff] [blame] | 193 | } |
| 194 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 195 | amdtp_stream_set_parameters(&dice->rx_stream, rate, channels, |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 196 | dice->rx_midi_ports[mode]); |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 197 | if (mode > 4) { |
Takashi Sakamoto | 1033eb5 | 2014-08-29 13:40:44 +0900 | [diff] [blame] | 198 | channels /= 2; |
| 199 | |
| 200 | for (i = 0; i < channels; i++) { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 201 | dice->rx_stream.pcm_positions[i] = i * 2; |
| 202 | dice->rx_stream.pcm_positions[i + channels] = i * 2 + 1; |
Takashi Sakamoto | 1033eb5 | 2014-08-29 13:40:44 +0900 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 206 | amdtp_stream_set_pcm_format(&dice->rx_stream, |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 207 | params_format(hw_params)); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 208 | |
| 209 | return 0; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | static int dice_hw_free(struct snd_pcm_substream *substream) |
| 213 | { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 214 | struct snd_dice *dice = substream->private_data; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 215 | |
| 216 | mutex_lock(&dice->mutex); |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 217 | snd_dice_stream_stop(dice); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 218 | mutex_unlock(&dice->mutex); |
| 219 | |
| 220 | return snd_pcm_lib_free_vmalloc_buffer(substream); |
| 221 | } |
| 222 | |
| 223 | static int dice_prepare(struct snd_pcm_substream *substream) |
| 224 | { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 225 | struct snd_dice *dice = substream->private_data; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 226 | int err; |
| 227 | |
| 228 | mutex_lock(&dice->mutex); |
| 229 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 230 | if (amdtp_streaming_error(&dice->rx_stream)) |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 231 | snd_dice_stream_stop_packets(dice); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 232 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 233 | err = snd_dice_stream_start(dice); |
Clemens Ladisch | 6abce9e | 2011-09-04 22:11:14 +0200 | [diff] [blame] | 234 | if (err < 0) { |
| 235 | mutex_unlock(&dice->mutex); |
| 236 | return err; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | mutex_unlock(&dice->mutex); |
| 240 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 241 | amdtp_stream_pcm_prepare(&dice->rx_stream); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 242 | |
| 243 | return 0; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | static int dice_trigger(struct snd_pcm_substream *substream, int cmd) |
| 247 | { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 248 | struct snd_dice *dice = substream->private_data; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 249 | struct snd_pcm_substream *pcm; |
| 250 | |
| 251 | switch (cmd) { |
| 252 | case SNDRV_PCM_TRIGGER_START: |
| 253 | pcm = substream; |
| 254 | break; |
| 255 | case SNDRV_PCM_TRIGGER_STOP: |
| 256 | pcm = NULL; |
| 257 | break; |
| 258 | default: |
| 259 | return -EINVAL; |
| 260 | } |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 261 | amdtp_stream_pcm_trigger(&dice->rx_stream, pcm); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 262 | |
| 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | static snd_pcm_uframes_t dice_pointer(struct snd_pcm_substream *substream) |
| 267 | { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 268 | struct snd_dice *dice = substream->private_data; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 269 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 270 | return amdtp_stream_pcm_pointer(&dice->rx_stream); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 271 | } |
| 272 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 273 | static int dice_create_pcm(struct snd_dice *dice) |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 274 | { |
| 275 | static struct snd_pcm_ops ops = { |
| 276 | .open = dice_open, |
| 277 | .close = dice_close, |
| 278 | .ioctl = snd_pcm_lib_ioctl, |
| 279 | .hw_params = dice_hw_params, |
| 280 | .hw_free = dice_hw_free, |
| 281 | .prepare = dice_prepare, |
| 282 | .trigger = dice_trigger, |
| 283 | .pointer = dice_pointer, |
| 284 | .page = snd_pcm_lib_get_vmalloc_page, |
| 285 | .mmap = snd_pcm_lib_mmap_vmalloc, |
| 286 | }; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 287 | struct snd_pcm *pcm; |
| 288 | int err; |
| 289 | |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 290 | err = snd_pcm_new(dice->card, "DICE", 0, 1, 0, &pcm); |
| 291 | if (err < 0) |
| 292 | return err; |
| 293 | pcm->private_data = dice; |
| 294 | strcpy(pcm->name, dice->card->shortname); |
Clemens Ladisch | 8709f1e | 2011-10-11 17:51:16 +0200 | [diff] [blame] | 295 | pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->ops = &ops; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 300 | static long dice_hwdep_read(struct snd_hwdep *hwdep, char __user *buf, |
| 301 | long count, loff_t *offset) |
| 302 | { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 303 | struct snd_dice *dice = hwdep->private_data; |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 304 | DEFINE_WAIT(wait); |
| 305 | union snd_firewire_event event; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 306 | |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 307 | spin_lock_irq(&dice->lock); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 308 | |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 309 | while (!dice->dev_lock_changed && dice->notification_bits == 0) { |
| 310 | prepare_to_wait(&dice->hwdep_wait, &wait, TASK_INTERRUPTIBLE); |
| 311 | spin_unlock_irq(&dice->lock); |
| 312 | schedule(); |
| 313 | finish_wait(&dice->hwdep_wait, &wait); |
| 314 | if (signal_pending(current)) |
| 315 | return -ERESTARTSYS; |
| 316 | spin_lock_irq(&dice->lock); |
| 317 | } |
| 318 | |
| 319 | memset(&event, 0, sizeof(event)); |
| 320 | if (dice->dev_lock_changed) { |
| 321 | event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS; |
| 322 | event.lock_status.status = dice->dev_lock_count > 0; |
| 323 | dice->dev_lock_changed = false; |
| 324 | |
Takashi Sakamoto | 81fc5ad | 2014-11-29 00:59:10 +0900 | [diff] [blame] | 325 | count = min_t(long, count, sizeof(event.lock_status)); |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 326 | } else { |
Takashi Sakamoto | 81fc5ad | 2014-11-29 00:59:10 +0900 | [diff] [blame] | 327 | event.dice_notification.type = |
| 328 | SNDRV_FIREWIRE_EVENT_DICE_NOTIFICATION; |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 329 | event.dice_notification.notification = dice->notification_bits; |
| 330 | dice->notification_bits = 0; |
| 331 | |
Takashi Sakamoto | 81fc5ad | 2014-11-29 00:59:10 +0900 | [diff] [blame] | 332 | count = min_t(long, count, sizeof(event.dice_notification)); |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | spin_unlock_irq(&dice->lock); |
| 336 | |
| 337 | if (copy_to_user(buf, &event, count)) |
| 338 | return -EFAULT; |
| 339 | |
| 340 | return count; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | static unsigned int dice_hwdep_poll(struct snd_hwdep *hwdep, struct file *file, |
| 344 | poll_table *wait) |
| 345 | { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 346 | struct snd_dice *dice = hwdep->private_data; |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 347 | unsigned int events; |
| 348 | |
| 349 | poll_wait(file, &dice->hwdep_wait, wait); |
| 350 | |
| 351 | spin_lock_irq(&dice->lock); |
| 352 | if (dice->dev_lock_changed || dice->notification_bits != 0) |
| 353 | events = POLLIN | POLLRDNORM; |
| 354 | else |
| 355 | events = 0; |
| 356 | spin_unlock_irq(&dice->lock); |
| 357 | |
| 358 | return events; |
| 359 | } |
| 360 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 361 | static int dice_hwdep_get_info(struct snd_dice *dice, void __user *arg) |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 362 | { |
| 363 | struct fw_device *dev = fw_parent_device(dice->unit); |
| 364 | struct snd_firewire_get_info info; |
| 365 | |
| 366 | memset(&info, 0, sizeof(info)); |
| 367 | info.type = SNDRV_FIREWIRE_TYPE_DICE; |
| 368 | info.card = dev->card->index; |
| 369 | *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]); |
| 370 | *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]); |
| 371 | strlcpy(info.device_name, dev_name(&dev->device), |
| 372 | sizeof(info.device_name)); |
| 373 | |
| 374 | if (copy_to_user(arg, &info, sizeof(info))) |
| 375 | return -EFAULT; |
| 376 | |
| 377 | return 0; |
| 378 | } |
| 379 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 380 | static int dice_hwdep_lock(struct snd_dice *dice) |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 381 | { |
| 382 | int err; |
| 383 | |
| 384 | spin_lock_irq(&dice->lock); |
| 385 | |
| 386 | if (dice->dev_lock_count == 0) { |
| 387 | dice->dev_lock_count = -1; |
| 388 | err = 0; |
| 389 | } else { |
| 390 | err = -EBUSY; |
| 391 | } |
| 392 | |
| 393 | spin_unlock_irq(&dice->lock); |
| 394 | |
| 395 | return err; |
| 396 | } |
| 397 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 398 | static int dice_hwdep_unlock(struct snd_dice *dice) |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 399 | { |
| 400 | int err; |
| 401 | |
| 402 | spin_lock_irq(&dice->lock); |
| 403 | |
| 404 | if (dice->dev_lock_count == -1) { |
| 405 | dice->dev_lock_count = 0; |
| 406 | err = 0; |
| 407 | } else { |
| 408 | err = -EBADFD; |
| 409 | } |
| 410 | |
| 411 | spin_unlock_irq(&dice->lock); |
| 412 | |
| 413 | return err; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 414 | } |
| 415 | |
Clemens Ladisch | 9dd81e3 | 2011-09-04 22:14:54 +0200 | [diff] [blame] | 416 | static int dice_hwdep_release(struct snd_hwdep *hwdep, struct file *file) |
| 417 | { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 418 | struct snd_dice *dice = hwdep->private_data; |
Clemens Ladisch | 9dd81e3 | 2011-09-04 22:14:54 +0200 | [diff] [blame] | 419 | |
| 420 | spin_lock_irq(&dice->lock); |
| 421 | if (dice->dev_lock_count == -1) |
| 422 | dice->dev_lock_count = 0; |
| 423 | spin_unlock_irq(&dice->lock); |
| 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 428 | static int dice_hwdep_ioctl(struct snd_hwdep *hwdep, struct file *file, |
| 429 | unsigned int cmd, unsigned long arg) |
| 430 | { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 431 | struct snd_dice *dice = hwdep->private_data; |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 432 | |
| 433 | switch (cmd) { |
| 434 | case SNDRV_FIREWIRE_IOCTL_GET_INFO: |
| 435 | return dice_hwdep_get_info(dice, (void __user *)arg); |
| 436 | case SNDRV_FIREWIRE_IOCTL_LOCK: |
| 437 | return dice_hwdep_lock(dice); |
| 438 | case SNDRV_FIREWIRE_IOCTL_UNLOCK: |
| 439 | return dice_hwdep_unlock(dice); |
| 440 | default: |
| 441 | return -ENOIOCTLCMD; |
| 442 | } |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 443 | } |
| 444 | |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 445 | #ifdef CONFIG_COMPAT |
| 446 | static int dice_hwdep_compat_ioctl(struct snd_hwdep *hwdep, struct file *file, |
| 447 | unsigned int cmd, unsigned long arg) |
| 448 | { |
| 449 | return dice_hwdep_ioctl(hwdep, file, cmd, |
| 450 | (unsigned long)compat_ptr(arg)); |
| 451 | } |
| 452 | #else |
| 453 | #define dice_hwdep_compat_ioctl NULL |
| 454 | #endif |
| 455 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 456 | static int dice_create_hwdep(struct snd_dice *dice) |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 457 | { |
| 458 | static const struct snd_hwdep_ops ops = { |
| 459 | .read = dice_hwdep_read, |
Clemens Ladisch | 9dd81e3 | 2011-09-04 22:14:54 +0200 | [diff] [blame] | 460 | .release = dice_hwdep_release, |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 461 | .poll = dice_hwdep_poll, |
| 462 | .ioctl = dice_hwdep_ioctl, |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 463 | .ioctl_compat = dice_hwdep_compat_ioctl, |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 464 | }; |
| 465 | struct snd_hwdep *hwdep; |
| 466 | int err; |
| 467 | |
| 468 | err = snd_hwdep_new(dice->card, "DICE", 0, &hwdep); |
| 469 | if (err < 0) |
| 470 | return err; |
| 471 | strcpy(hwdep->name, "DICE"); |
| 472 | hwdep->iface = SNDRV_HWDEP_IFACE_FW_DICE; |
| 473 | hwdep->ops = ops; |
| 474 | hwdep->private_data = dice; |
| 475 | hwdep->exclusive = true; |
| 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 480 | static int dice_proc_read_mem(struct snd_dice *dice, void *buffer, |
Clemens Ladisch | c614475 | 2012-01-05 22:36:08 +0100 | [diff] [blame] | 481 | unsigned int offset_q, unsigned int quadlets) |
| 482 | { |
| 483 | unsigned int i; |
| 484 | int err; |
| 485 | |
| 486 | err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST, |
| 487 | DICE_PRIVATE_SPACE + 4 * offset_q, |
| 488 | buffer, 4 * quadlets, 0); |
| 489 | if (err < 0) |
| 490 | return err; |
| 491 | |
| 492 | for (i = 0; i < quadlets; ++i) |
| 493 | be32_to_cpus(&((u32 *)buffer)[i]); |
| 494 | |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | static const char *str_from_array(const char *const strs[], unsigned int count, |
| 499 | unsigned int i) |
| 500 | { |
| 501 | if (i < count) |
| 502 | return strs[i]; |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 503 | |
| 504 | return "(unknown)"; |
Clemens Ladisch | c614475 | 2012-01-05 22:36:08 +0100 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | static void dice_proc_fixup_string(char *s, unsigned int size) |
| 508 | { |
| 509 | unsigned int i; |
| 510 | |
| 511 | for (i = 0; i < size; i += 4) |
| 512 | cpu_to_le32s((u32 *)(s + i)); |
| 513 | |
| 514 | for (i = 0; i < size - 2; ++i) { |
| 515 | if (s[i] == '\0') |
| 516 | return; |
| 517 | if (s[i] == '\\' && s[i + 1] == '\\') { |
| 518 | s[i + 2] = '\0'; |
| 519 | return; |
| 520 | } |
| 521 | } |
| 522 | s[size - 1] = '\0'; |
| 523 | } |
| 524 | |
| 525 | static void dice_proc_read(struct snd_info_entry *entry, |
| 526 | struct snd_info_buffer *buffer) |
| 527 | { |
| 528 | static const char *const section_names[5] = { |
| 529 | "global", "tx", "rx", "ext_sync", "unused2" |
| 530 | }; |
| 531 | static const char *const clock_sources[] = { |
| 532 | "aes1", "aes2", "aes3", "aes4", "aes", "adat", "tdif", |
| 533 | "wc", "arx1", "arx2", "arx3", "arx4", "internal" |
| 534 | }; |
| 535 | static const char *const rates[] = { |
| 536 | "32000", "44100", "48000", "88200", "96000", "176400", "192000", |
| 537 | "any low", "any mid", "any high", "none" |
| 538 | }; |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 539 | struct snd_dice *dice = entry->private_data; |
Clemens Ladisch | c614475 | 2012-01-05 22:36:08 +0100 | [diff] [blame] | 540 | u32 sections[ARRAY_SIZE(section_names) * 2]; |
| 541 | struct { |
| 542 | u32 number; |
| 543 | u32 size; |
| 544 | } tx_rx_header; |
| 545 | union { |
| 546 | struct { |
| 547 | u32 owner_hi, owner_lo; |
| 548 | u32 notification; |
| 549 | char nick_name[NICK_NAME_SIZE]; |
| 550 | u32 clock_select; |
| 551 | u32 enable; |
| 552 | u32 status; |
| 553 | u32 extended_status; |
| 554 | u32 sample_rate; |
| 555 | u32 version; |
| 556 | u32 clock_caps; |
| 557 | char clock_source_names[CLOCK_SOURCE_NAMES_SIZE]; |
| 558 | } global; |
| 559 | struct { |
| 560 | u32 iso; |
| 561 | u32 number_audio; |
| 562 | u32 number_midi; |
| 563 | u32 speed; |
| 564 | char names[TX_NAMES_SIZE]; |
| 565 | u32 ac3_caps; |
| 566 | u32 ac3_enable; |
| 567 | } tx; |
| 568 | struct { |
| 569 | u32 iso; |
| 570 | u32 seq_start; |
| 571 | u32 number_audio; |
| 572 | u32 number_midi; |
| 573 | char names[RX_NAMES_SIZE]; |
| 574 | u32 ac3_caps; |
| 575 | u32 ac3_enable; |
| 576 | } rx; |
| 577 | struct { |
| 578 | u32 clock_source; |
| 579 | u32 locked; |
| 580 | u32 rate; |
| 581 | u32 adat_user_data; |
| 582 | } ext_sync; |
| 583 | } buf; |
| 584 | unsigned int quadlets, stream, i; |
| 585 | |
| 586 | if (dice_proc_read_mem(dice, sections, 0, ARRAY_SIZE(sections)) < 0) |
| 587 | return; |
| 588 | snd_iprintf(buffer, "sections:\n"); |
| 589 | for (i = 0; i < ARRAY_SIZE(section_names); ++i) |
| 590 | snd_iprintf(buffer, " %s: offset %u, size %u\n", |
| 591 | section_names[i], |
| 592 | sections[i * 2], sections[i * 2 + 1]); |
| 593 | |
| 594 | quadlets = min_t(u32, sections[1], sizeof(buf.global) / 4); |
| 595 | if (dice_proc_read_mem(dice, &buf.global, sections[0], quadlets) < 0) |
| 596 | return; |
| 597 | snd_iprintf(buffer, "global:\n"); |
| 598 | snd_iprintf(buffer, " owner: %04x:%04x%08x\n", |
| 599 | buf.global.owner_hi >> 16, |
| 600 | buf.global.owner_hi & 0xffff, buf.global.owner_lo); |
| 601 | snd_iprintf(buffer, " notification: %08x\n", buf.global.notification); |
| 602 | dice_proc_fixup_string(buf.global.nick_name, NICK_NAME_SIZE); |
| 603 | snd_iprintf(buffer, " nick name: %s\n", buf.global.nick_name); |
| 604 | snd_iprintf(buffer, " clock select: %s %s\n", |
| 605 | str_from_array(clock_sources, ARRAY_SIZE(clock_sources), |
| 606 | buf.global.clock_select & CLOCK_SOURCE_MASK), |
| 607 | str_from_array(rates, ARRAY_SIZE(rates), |
| 608 | (buf.global.clock_select & CLOCK_RATE_MASK) |
| 609 | >> CLOCK_RATE_SHIFT)); |
| 610 | snd_iprintf(buffer, " enable: %u\n", buf.global.enable); |
| 611 | snd_iprintf(buffer, " status: %slocked %s\n", |
| 612 | buf.global.status & STATUS_SOURCE_LOCKED ? "" : "un", |
| 613 | str_from_array(rates, ARRAY_SIZE(rates), |
| 614 | (buf.global.status & |
| 615 | STATUS_NOMINAL_RATE_MASK) |
| 616 | >> CLOCK_RATE_SHIFT)); |
| 617 | snd_iprintf(buffer, " ext status: %08x\n", buf.global.extended_status); |
| 618 | snd_iprintf(buffer, " sample rate: %u\n", buf.global.sample_rate); |
| 619 | snd_iprintf(buffer, " version: %u.%u.%u.%u\n", |
| 620 | (buf.global.version >> 24) & 0xff, |
| 621 | (buf.global.version >> 16) & 0xff, |
| 622 | (buf.global.version >> 8) & 0xff, |
| 623 | (buf.global.version >> 0) & 0xff); |
| 624 | if (quadlets >= 90) { |
| 625 | snd_iprintf(buffer, " clock caps:"); |
| 626 | for (i = 0; i <= 6; ++i) |
| 627 | if (buf.global.clock_caps & (1 << i)) |
| 628 | snd_iprintf(buffer, " %s", rates[i]); |
| 629 | for (i = 0; i <= 12; ++i) |
| 630 | if (buf.global.clock_caps & (1 << (16 + i))) |
| 631 | snd_iprintf(buffer, " %s", clock_sources[i]); |
| 632 | snd_iprintf(buffer, "\n"); |
| 633 | dice_proc_fixup_string(buf.global.clock_source_names, |
| 634 | CLOCK_SOURCE_NAMES_SIZE); |
| 635 | snd_iprintf(buffer, " clock source names: %s\n", |
| 636 | buf.global.clock_source_names); |
| 637 | } |
| 638 | |
| 639 | if (dice_proc_read_mem(dice, &tx_rx_header, sections[2], 2) < 0) |
| 640 | return; |
Dan Carpenter | 4d6ff25 | 2013-11-29 11:14:09 +0300 | [diff] [blame] | 641 | quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.tx) / 4); |
Clemens Ladisch | c614475 | 2012-01-05 22:36:08 +0100 | [diff] [blame] | 642 | for (stream = 0; stream < tx_rx_header.number; ++stream) { |
| 643 | if (dice_proc_read_mem(dice, &buf.tx, sections[2] + 2 + |
| 644 | stream * tx_rx_header.size, |
| 645 | quadlets) < 0) |
| 646 | break; |
| 647 | snd_iprintf(buffer, "tx %u:\n", stream); |
| 648 | snd_iprintf(buffer, " iso channel: %d\n", (int)buf.tx.iso); |
| 649 | snd_iprintf(buffer, " audio channels: %u\n", |
| 650 | buf.tx.number_audio); |
| 651 | snd_iprintf(buffer, " midi ports: %u\n", buf.tx.number_midi); |
| 652 | snd_iprintf(buffer, " speed: S%u\n", 100u << buf.tx.speed); |
| 653 | if (quadlets >= 68) { |
| 654 | dice_proc_fixup_string(buf.tx.names, TX_NAMES_SIZE); |
| 655 | snd_iprintf(buffer, " names: %s\n", buf.tx.names); |
| 656 | } |
| 657 | if (quadlets >= 70) { |
| 658 | snd_iprintf(buffer, " ac3 caps: %08x\n", |
| 659 | buf.tx.ac3_caps); |
| 660 | snd_iprintf(buffer, " ac3 enable: %08x\n", |
| 661 | buf.tx.ac3_enable); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | if (dice_proc_read_mem(dice, &tx_rx_header, sections[4], 2) < 0) |
| 666 | return; |
Dan Carpenter | 4d6ff25 | 2013-11-29 11:14:09 +0300 | [diff] [blame] | 667 | quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.rx) / 4); |
Clemens Ladisch | c614475 | 2012-01-05 22:36:08 +0100 | [diff] [blame] | 668 | for (stream = 0; stream < tx_rx_header.number; ++stream) { |
| 669 | if (dice_proc_read_mem(dice, &buf.rx, sections[4] + 2 + |
| 670 | stream * tx_rx_header.size, |
| 671 | quadlets) < 0) |
| 672 | break; |
| 673 | snd_iprintf(buffer, "rx %u:\n", stream); |
| 674 | snd_iprintf(buffer, " iso channel: %d\n", (int)buf.rx.iso); |
Clemens Ladisch | ed7e482 | 2012-01-22 16:46:23 +0100 | [diff] [blame] | 675 | snd_iprintf(buffer, " sequence start: %u\n", buf.rx.seq_start); |
Clemens Ladisch | c614475 | 2012-01-05 22:36:08 +0100 | [diff] [blame] | 676 | snd_iprintf(buffer, " audio channels: %u\n", |
| 677 | buf.rx.number_audio); |
| 678 | snd_iprintf(buffer, " midi ports: %u\n", buf.rx.number_midi); |
| 679 | if (quadlets >= 68) { |
| 680 | dice_proc_fixup_string(buf.rx.names, RX_NAMES_SIZE); |
| 681 | snd_iprintf(buffer, " names: %s\n", buf.rx.names); |
| 682 | } |
| 683 | if (quadlets >= 70) { |
| 684 | snd_iprintf(buffer, " ac3 caps: %08x\n", |
| 685 | buf.rx.ac3_caps); |
| 686 | snd_iprintf(buffer, " ac3 enable: %08x\n", |
| 687 | buf.rx.ac3_enable); |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | quadlets = min_t(u32, sections[7], sizeof(buf.ext_sync) / 4); |
| 692 | if (quadlets >= 4) { |
| 693 | if (dice_proc_read_mem(dice, &buf.ext_sync, |
| 694 | sections[6], 4) < 0) |
| 695 | return; |
| 696 | snd_iprintf(buffer, "ext status:\n"); |
| 697 | snd_iprintf(buffer, " clock source: %s\n", |
| 698 | str_from_array(clock_sources, |
| 699 | ARRAY_SIZE(clock_sources), |
| 700 | buf.ext_sync.clock_source)); |
| 701 | snd_iprintf(buffer, " locked: %u\n", buf.ext_sync.locked); |
| 702 | snd_iprintf(buffer, " rate: %s\n", |
| 703 | str_from_array(rates, ARRAY_SIZE(rates), |
| 704 | buf.ext_sync.rate)); |
| 705 | snd_iprintf(buffer, " adat user data: "); |
| 706 | if (buf.ext_sync.adat_user_data & ADAT_USER_DATA_NO_DATA) |
| 707 | snd_iprintf(buffer, "-\n"); |
| 708 | else |
| 709 | snd_iprintf(buffer, "%x\n", |
| 710 | buf.ext_sync.adat_user_data); |
| 711 | } |
| 712 | } |
| 713 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 714 | static void dice_create_proc(struct snd_dice *dice) |
Clemens Ladisch | c614475 | 2012-01-05 22:36:08 +0100 | [diff] [blame] | 715 | { |
| 716 | struct snd_info_entry *entry; |
| 717 | |
| 718 | if (!snd_card_proc_new(dice->card, "dice", &entry)) |
| 719 | snd_info_set_text_ops(entry, dice, dice_proc_read); |
| 720 | } |
| 721 | |
Clemens Ladisch | a471fcd | 2012-02-13 21:55:13 +0100 | [diff] [blame] | 722 | #define OUI_WEISS 0x001c6a |
| 723 | |
| 724 | #define DICE_CATEGORY_ID 0x04 |
| 725 | #define WEISS_CATEGORY_ID 0x00 |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 726 | |
| 727 | static int dice_interface_check(struct fw_unit *unit) |
| 728 | { |
| 729 | static const int min_values[10] = { |
| 730 | 10, 0x64 / 4, |
| 731 | 10, 0x18 / 4, |
| 732 | 10, 0x18 / 4, |
| 733 | 0, 0, |
| 734 | 0, 0, |
| 735 | }; |
| 736 | struct fw_device *device = fw_parent_device(unit); |
| 737 | struct fw_csr_iterator it; |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 738 | int key, val, vendor = -1, model = -1, err; |
Clemens Ladisch | a471fcd | 2012-02-13 21:55:13 +0100 | [diff] [blame] | 739 | unsigned int category, i; |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 740 | __be32 *pointers, value; |
Clemens Ladisch | b20be8d | 2013-10-15 20:26:05 +0200 | [diff] [blame] | 741 | __be32 tx_data[4]; |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 742 | __be32 version; |
| 743 | |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 744 | pointers = kmalloc_array(ARRAY_SIZE(min_values), sizeof(__be32), |
| 745 | GFP_KERNEL); |
| 746 | if (pointers == NULL) |
| 747 | return -ENOMEM; |
| 748 | |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 749 | /* |
| 750 | * Check that GUID and unit directory are constructed according to DICE |
| 751 | * rules, i.e., that the specifier ID is the GUID's OUI, and that the |
Clemens Ladisch | a471fcd | 2012-02-13 21:55:13 +0100 | [diff] [blame] | 752 | * GUID chip ID consists of the 8-bit category ID, the 10-bit product |
| 753 | * ID, and a 22-bit serial number. |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 754 | */ |
| 755 | fw_csr_iterator_init(&it, unit->directory); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 756 | while (fw_csr_iterator_next(&it, &key, &val)) { |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 757 | switch (key) { |
| 758 | case CSR_SPECIFIER_ID: |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 759 | vendor = val; |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 760 | break; |
| 761 | case CSR_MODEL: |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 762 | model = val; |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 763 | break; |
| 764 | } |
| 765 | } |
Clemens Ladisch | a471fcd | 2012-02-13 21:55:13 +0100 | [diff] [blame] | 766 | if (vendor == OUI_WEISS) |
| 767 | category = WEISS_CATEGORY_ID; |
| 768 | else |
| 769 | category = DICE_CATEGORY_ID; |
| 770 | if (device->config_rom[3] != ((vendor << 8) | category) || |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 771 | device->config_rom[4] >> 22 != model) { |
| 772 | err = -ENODEV; |
| 773 | goto end; |
| 774 | } |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 775 | |
| 776 | /* |
| 777 | * Check that the sub address spaces exist and are located inside the |
| 778 | * private address space. The minimum values are chosen so that all |
| 779 | * minimally required registers are included. |
| 780 | */ |
| 781 | err = snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST, |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 782 | DICE_PRIVATE_SPACE, pointers, |
| 783 | sizeof(__be32) * ARRAY_SIZE(min_values), 0); |
| 784 | if (err < 0) { |
| 785 | err = -ENODEV; |
| 786 | goto end; |
| 787 | } |
| 788 | for (i = 0; i < ARRAY_SIZE(min_values); ++i) { |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 789 | value = be32_to_cpu(pointers[i]); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 790 | if (value < min_values[i] || value >= 0x40000) { |
| 791 | err = -ENODEV; |
| 792 | goto end; |
| 793 | } |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 794 | } |
| 795 | |
Clemens Ladisch | b20be8d | 2013-10-15 20:26:05 +0200 | [diff] [blame] | 796 | /* We support playback only. Let capture devices be handled by FFADO. */ |
| 797 | err = snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST, |
| 798 | DICE_PRIVATE_SPACE + |
| 799 | be32_to_cpu(pointers[2]) * 4, |
| 800 | tx_data, sizeof(tx_data), 0); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 801 | if (err < 0 || (tx_data[0] && tx_data[3])) { |
| 802 | err = -ENODEV; |
| 803 | goto end; |
| 804 | } |
Clemens Ladisch | b20be8d | 2013-10-15 20:26:05 +0200 | [diff] [blame] | 805 | |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 806 | /* |
| 807 | * Check that the implemented DICE driver specification major version |
| 808 | * number matches. |
| 809 | */ |
| 810 | err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST, |
| 811 | DICE_PRIVATE_SPACE + |
| 812 | be32_to_cpu(pointers[0]) * 4 + GLOBAL_VERSION, |
Clemens Ladisch | 1b70485 | 2011-09-04 22:17:38 +0200 | [diff] [blame] | 813 | &version, 4, 0); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 814 | if (err < 0) { |
| 815 | err = -ENODEV; |
| 816 | goto end; |
| 817 | } |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 818 | if ((version & cpu_to_be32(0xff000000)) != cpu_to_be32(0x01000000)) { |
| 819 | dev_err(&unit->device, |
| 820 | "unknown DICE version: 0x%08x\n", be32_to_cpu(version)); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 821 | err = -ENODEV; |
| 822 | goto end; |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 823 | } |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 824 | end: |
| 825 | return err; |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 826 | } |
| 827 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 828 | static int highest_supported_mode_rate(struct snd_dice *dice, |
| 829 | unsigned int mode, unsigned int *rate) |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 830 | { |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 831 | unsigned int i, m; |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 832 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 833 | for (i = ARRAY_SIZE(snd_dice_rates); i > 0; i--) { |
| 834 | *rate = snd_dice_rates[i - 1]; |
| 835 | if (snd_dice_stream_get_rate_mode(dice, *rate, &m) < 0) |
| 836 | continue; |
| 837 | if (mode == m) |
| 838 | break; |
| 839 | } |
| 840 | if (i == 0) |
| 841 | return -EINVAL; |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 842 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 843 | return 0; |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 844 | } |
| 845 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 846 | static int dice_read_mode_params(struct snd_dice *dice, unsigned int mode) |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 847 | { |
| 848 | __be32 values[2]; |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 849 | unsigned int rate; |
| 850 | int err; |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 851 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 852 | if (highest_supported_mode_rate(dice, mode, &rate) < 0) { |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 853 | dice->rx_channels[mode] = 0; |
| 854 | dice->rx_midi_ports[mode] = 0; |
| 855 | return 0; |
| 856 | } |
| 857 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 858 | err = snd_dice_transaction_set_rate(dice, rate); |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 859 | if (err < 0) |
| 860 | return err; |
| 861 | |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 862 | err = snd_dice_transaction_read_rx(dice, RX_NUMBER_AUDIO, |
| 863 | values, sizeof(values)); |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 864 | if (err < 0) |
| 865 | return err; |
| 866 | |
| 867 | dice->rx_channels[mode] = be32_to_cpu(values[0]); |
| 868 | dice->rx_midi_ports[mode] = be32_to_cpu(values[1]); |
| 869 | |
| 870 | return 0; |
| 871 | } |
| 872 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 873 | static int dice_read_params(struct snd_dice *dice) |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 874 | { |
Clemens Ladisch | a030199 | 2011-12-04 21:47:00 +0100 | [diff] [blame] | 875 | __be32 value; |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 876 | int mode, err; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 877 | |
Clemens Ladisch | a030199 | 2011-12-04 21:47:00 +0100 | [diff] [blame] | 878 | /* some very old firmwares don't tell about their clock support */ |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 879 | if (dice->clock_caps > 0) { |
| 880 | err = snd_dice_transaction_read_global(dice, |
| 881 | GLOBAL_CLOCK_CAPABILITIES, |
| 882 | &value, 4); |
Clemens Ladisch | a030199 | 2011-12-04 21:47:00 +0100 | [diff] [blame] | 883 | if (err < 0) |
| 884 | return err; |
| 885 | dice->clock_caps = be32_to_cpu(value); |
| 886 | } else { |
| 887 | /* this should be supported by any device */ |
| 888 | dice->clock_caps = CLOCK_CAP_RATE_44100 | |
| 889 | CLOCK_CAP_RATE_48000 | |
| 890 | CLOCK_CAP_SOURCE_ARX1 | |
| 891 | CLOCK_CAP_SOURCE_INTERNAL; |
| 892 | } |
| 893 | |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 894 | for (mode = 2; mode >= 0; --mode) { |
| 895 | err = dice_read_mode_params(dice, mode); |
| 896 | if (err < 0) |
| 897 | return err; |
| 898 | } |
| 899 | |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 900 | return 0; |
| 901 | } |
| 902 | |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 903 | static void dice_card_strings(struct snd_dice *dice) |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 904 | { |
| 905 | struct snd_card *card = dice->card; |
| 906 | struct fw_device *dev = fw_parent_device(dice->unit); |
| 907 | char vendor[32], model[32]; |
| 908 | unsigned int i; |
| 909 | int err; |
| 910 | |
| 911 | strcpy(card->driver, "DICE"); |
| 912 | |
| 913 | strcpy(card->shortname, "DICE"); |
| 914 | BUILD_BUG_ON(NICK_NAME_SIZE < sizeof(card->shortname)); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 915 | err = snd_dice_transaction_read_global(dice, GLOBAL_NICK_NAME, |
| 916 | card->shortname, |
| 917 | sizeof(card->shortname)); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 918 | if (err >= 0) { |
| 919 | /* DICE strings are returned in "always-wrong" endianness */ |
| 920 | BUILD_BUG_ON(sizeof(card->shortname) % 4 != 0); |
| 921 | for (i = 0; i < sizeof(card->shortname); i += 4) |
| 922 | swab32s((u32 *)&card->shortname[i]); |
| 923 | card->shortname[sizeof(card->shortname) - 1] = '\0'; |
| 924 | } |
| 925 | |
| 926 | strcpy(vendor, "?"); |
| 927 | fw_csr_string(dev->config_rom + 5, CSR_VENDOR, vendor, sizeof(vendor)); |
| 928 | strcpy(model, "?"); |
| 929 | fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model)); |
| 930 | snprintf(card->longname, sizeof(card->longname), |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 931 | "%s %s (serial %u) at %s, S%d", |
| 932 | vendor, model, dev->config_rom[4] & 0x3fffff, |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 933 | dev_name(&dice->unit->device), 100 << dev->max_speed); |
| 934 | |
| 935 | strcpy(card->mixername, "DICE"); |
| 936 | } |
| 937 | |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 938 | static void dice_card_free(struct snd_card *card) |
| 939 | { |
| 940 | struct snd_dice *dice = card->private_data; |
| 941 | |
| 942 | snd_dice_transaction_destroy(dice); |
| 943 | mutex_destroy(&dice->mutex); |
| 944 | } |
| 945 | |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 946 | static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id) |
| 947 | { |
| 948 | struct snd_card *card; |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 949 | struct snd_dice *dice; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 950 | int err; |
| 951 | |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 952 | err = dice_interface_check(unit); |
| 953 | if (err < 0) |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 954 | goto end; |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 955 | |
Takashi Iwai | 06b45f0 | 2014-01-29 14:23:55 +0100 | [diff] [blame] | 956 | err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, |
| 957 | sizeof(*dice), &card); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 958 | if (err < 0) |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 959 | goto end; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 960 | |
| 961 | dice = card->private_data; |
| 962 | dice->card = card; |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 963 | dice->unit = unit; |
| 964 | card->private_free = dice_card_free; |
| 965 | |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 966 | spin_lock_init(&dice->lock); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 967 | mutex_init(&dice->mutex); |
Clemens Ladisch | 15a75c8 | 2011-12-04 22:23:59 +0100 | [diff] [blame] | 968 | init_completion(&dice->clock_accepted); |
Clemens Ladisch | 0c29c91 | 2011-09-04 22:14:15 +0200 | [diff] [blame] | 969 | init_waitqueue_head(&dice->hwdep_wait); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 970 | |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 971 | err = snd_dice_transaction_init(dice); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 972 | if (err < 0) |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 973 | goto error; |
Clemens Ladisch | 5ea4018 | 2011-12-05 22:09:42 +0100 | [diff] [blame] | 974 | |
| 975 | err = dice_read_params(dice); |
| 976 | if (err < 0) |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 977 | goto error; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 978 | |
| 979 | dice_card_strings(dice); |
| 980 | |
| 981 | err = dice_create_pcm(dice); |
| 982 | if (err < 0) |
| 983 | goto error; |
| 984 | |
| 985 | err = dice_create_hwdep(dice); |
| 986 | if (err < 0) |
| 987 | goto error; |
| 988 | |
Clemens Ladisch | c614475 | 2012-01-05 22:36:08 +0100 | [diff] [blame] | 989 | dice_create_proc(dice); |
| 990 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 991 | err = snd_dice_stream_init(dice); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 992 | if (err < 0) |
| 993 | goto error; |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 994 | |
| 995 | err = snd_card_register(card); |
| 996 | if (err < 0) { |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 997 | snd_dice_stream_destroy(dice); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 998 | goto error; |
| 999 | } |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 1000 | |
| 1001 | dev_set_drvdata(&unit->device, dice); |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 1002 | end: |
| 1003 | return err; |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 1004 | error: |
| 1005 | snd_card_free(card); |
| 1006 | return err; |
| 1007 | } |
| 1008 | |
| 1009 | static void dice_remove(struct fw_unit *unit) |
| 1010 | { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 1011 | struct snd_dice *dice = dev_get_drvdata(&unit->device); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 1012 | |
| 1013 | snd_card_disconnect(dice->card); |
| 1014 | |
Stefan Richter | a8c558f | 2011-08-27 20:05:15 +0200 | [diff] [blame] | 1015 | mutex_lock(&dice->mutex); |
| 1016 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 1017 | snd_dice_stream_destroy(dice); |
Clemens Ladisch | 4ed31f20 | 2011-09-04 22:13:09 +0200 | [diff] [blame] | 1018 | |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 1019 | mutex_unlock(&dice->mutex); |
| 1020 | |
| 1021 | snd_card_free_when_closed(dice->card); |
| 1022 | } |
| 1023 | |
| 1024 | static void dice_bus_reset(struct fw_unit *unit) |
| 1025 | { |
Takashi Sakamoto | 732d153 | 2014-11-29 00:59:11 +0900 | [diff] [blame] | 1026 | struct snd_dice *dice = dev_get_drvdata(&unit->device); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 1027 | |
Takashi Sakamoto | 7c2d4c0 | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 1028 | /* The handler address register becomes initialized. */ |
| 1029 | snd_dice_transaction_reinit(dice); |
| 1030 | |
Stefan Richter | a8c558f | 2011-08-27 20:05:15 +0200 | [diff] [blame] | 1031 | mutex_lock(&dice->mutex); |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame^] | 1032 | snd_dice_stream_update(dice); |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 1033 | mutex_unlock(&dice->mutex); |
| 1034 | } |
| 1035 | |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 1036 | #define DICE_INTERFACE 0x000001 |
| 1037 | |
| 1038 | static const struct ieee1394_device_id dice_id_table[] = { |
| 1039 | { |
Clemens Ladisch | cbab328 | 2011-09-04 22:16:02 +0200 | [diff] [blame] | 1040 | .match_flags = IEEE1394_MATCH_VERSION, |
| 1041 | .version = DICE_INTERFACE, |
Clemens Ladisch | 82fbb4f | 2011-09-04 22:04:49 +0200 | [diff] [blame] | 1042 | }, |
| 1043 | { } |
| 1044 | }; |
| 1045 | MODULE_DEVICE_TABLE(ieee1394, dice_id_table); |
| 1046 | |
| 1047 | static struct fw_driver dice_driver = { |
| 1048 | .driver = { |
| 1049 | .owner = THIS_MODULE, |
| 1050 | .name = KBUILD_MODNAME, |
| 1051 | .bus = &fw_bus_type, |
| 1052 | }, |
| 1053 | .probe = dice_probe, |
| 1054 | .update = dice_bus_reset, |
| 1055 | .remove = dice_remove, |
| 1056 | .id_table = dice_id_table, |
| 1057 | }; |
| 1058 | |
| 1059 | static int __init alsa_dice_init(void) |
| 1060 | { |
| 1061 | return driver_register(&dice_driver.driver); |
| 1062 | } |
| 1063 | |
| 1064 | static void __exit alsa_dice_exit(void) |
| 1065 | { |
| 1066 | driver_unregister(&dice_driver.driver); |
| 1067 | } |
| 1068 | |
| 1069 | module_init(alsa_dice_init); |
| 1070 | module_exit(alsa_dice_exit); |