aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/rme9652/hdspm.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/rme9652/hdspm.c')
-rw-r--r--sound/pci/rme9652/hdspm.c153
1 files changed, 83 insertions, 70 deletions
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index 493e3946756f..6e2f7ef7ddb1 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -1241,10 +1241,30 @@ static int hdspm_external_sample_rate(struct hdspm *hdspm)
1241 return rate; 1241 return rate;
1242} 1242}
1243 1243
1244/* return latency in samples per period */
1245static int hdspm_get_latency(struct hdspm *hdspm)
1246{
1247 int n;
1248
1249 n = hdspm_decode_latency(hdspm->control_register);
1250
1251 /* Special case for new RME cards with 32 samples period size.
1252 * The three latency bits in the control register
1253 * (HDSP_LatencyMask) encode latency values of 64 samples as
1254 * 0, 128 samples as 1 ... 4096 samples as 6. For old cards, 7
1255 * denotes 8192 samples, but on new cards like RayDAT or AIO,
1256 * it corresponds to 32 samples.
1257 */
1258 if ((7 == n) && (RayDAT == hdspm->io_type || AIO == hdspm->io_type))
1259 n = -1;
1260
1261 return 1 << (n + 6);
1262}
1263
1244/* Latency function */ 1264/* Latency function */
1245static inline void hdspm_compute_period_size(struct hdspm *hdspm) 1265static inline void hdspm_compute_period_size(struct hdspm *hdspm)
1246{ 1266{
1247 hdspm->period_bytes = 1 << ((hdspm_decode_latency(hdspm->control_register) + 8)); 1267 hdspm->period_bytes = 4 * hdspm_get_latency(hdspm);
1248} 1268}
1249 1269
1250 1270
@@ -1303,12 +1323,27 @@ static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames)
1303 1323
1304 spin_lock_irq(&s->lock); 1324 spin_lock_irq(&s->lock);
1305 1325
1306 frames >>= 7; 1326 if (32 == frames) {
1307 n = 0; 1327 /* Special case for new RME cards like RayDAT/AIO which
1308 while (frames) { 1328 * support period sizes of 32 samples. Since latency is
1309 n++; 1329 * encoded in the three bits of HDSP_LatencyMask, we can only
1310 frames >>= 1; 1330 * have values from 0 .. 7. While 0 still means 64 samples and
1331 * 6 represents 4096 samples on all cards, 7 represents 8192
1332 * on older cards and 32 samples on new cards.
1333 *
1334 * In other words, period size in samples is calculated by
1335 * 2^(n+6) with n ranging from 0 .. 7.
1336 */
1337 n = 7;
1338 } else {
1339 frames >>= 7;
1340 n = 0;
1341 while (frames) {
1342 n++;
1343 frames >>= 1;
1344 }
1311 } 1345 }
1346
1312 s->control_register &= ~HDSPM_LatencyMask; 1347 s->control_register &= ~HDSPM_LatencyMask;
1313 s->control_register |= hdspm_encode_latency(n); 1348 s->control_register |= hdspm_encode_latency(n);
1314 1349
@@ -4801,8 +4836,7 @@ snd_hdspm_proc_read_madi(struct snd_info_entry * entry,
4801 4836
4802 snd_iprintf(buffer, "--- Settings ---\n"); 4837 snd_iprintf(buffer, "--- Settings ---\n");
4803 4838
4804 x = 1 << (6 + hdspm_decode_latency(hdspm->control_register & 4839 x = hdspm_get_latency(hdspm);
4805 HDSPM_LatencyMask));
4806 4840
4807 snd_iprintf(buffer, 4841 snd_iprintf(buffer,
4808 "Size (Latency): %d samples (2 periods of %lu bytes)\n", 4842 "Size (Latency): %d samples (2 periods of %lu bytes)\n",
@@ -4965,8 +4999,7 @@ snd_hdspm_proc_read_aes32(struct snd_info_entry * entry,
4965 4999
4966 snd_iprintf(buffer, "--- Settings ---\n"); 5000 snd_iprintf(buffer, "--- Settings ---\n");
4967 5001
4968 x = 1 << (6 + hdspm_decode_latency(hdspm->control_register & 5002 x = hdspm_get_latency(hdspm);
4969 HDSPM_LatencyMask));
4970 5003
4971 snd_iprintf(buffer, 5004 snd_iprintf(buffer,
4972 "Size (Latency): %d samples (2 periods of %lu bytes)\n", 5005 "Size (Latency): %d samples (2 periods of %lu bytes)\n",
@@ -5672,19 +5705,6 @@ static int snd_hdspm_prepare(struct snd_pcm_substream *substream)
5672 return 0; 5705 return 0;
5673} 5706}
5674 5707
5675static unsigned int period_sizes_old[] = {
5676 64, 128, 256, 512, 1024, 2048, 4096
5677};
5678
5679static unsigned int period_sizes_new[] = {
5680 32, 64, 128, 256, 512, 1024, 2048, 4096
5681};
5682
5683/* RayDAT and AIO always have a buffer of 16384 samples per channel */
5684static unsigned int raydat_aio_buffer_sizes[] = {
5685 16384
5686};
5687
5688static struct snd_pcm_hardware snd_hdspm_playback_subinfo = { 5708static struct snd_pcm_hardware snd_hdspm_playback_subinfo = {
5689 .info = (SNDRV_PCM_INFO_MMAP | 5709 .info = (SNDRV_PCM_INFO_MMAP |
5690 SNDRV_PCM_INFO_MMAP_VALID | 5710 SNDRV_PCM_INFO_MMAP_VALID |
@@ -5703,8 +5723,8 @@ static struct snd_pcm_hardware snd_hdspm_playback_subinfo = {
5703 .channels_max = HDSPM_MAX_CHANNELS, 5723 .channels_max = HDSPM_MAX_CHANNELS,
5704 .buffer_bytes_max = 5724 .buffer_bytes_max =
5705 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS, 5725 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
5706 .period_bytes_min = (64 * 4), 5726 .period_bytes_min = (32 * 4),
5707 .period_bytes_max = (4096 * 4) * HDSPM_MAX_CHANNELS, 5727 .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS,
5708 .periods_min = 2, 5728 .periods_min = 2,
5709 .periods_max = 512, 5729 .periods_max = 512,
5710 .fifo_size = 0 5730 .fifo_size = 0
@@ -5728,31 +5748,13 @@ static struct snd_pcm_hardware snd_hdspm_capture_subinfo = {
5728 .channels_max = HDSPM_MAX_CHANNELS, 5748 .channels_max = HDSPM_MAX_CHANNELS,
5729 .buffer_bytes_max = 5749 .buffer_bytes_max =
5730 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS, 5750 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
5731 .period_bytes_min = (64 * 4), 5751 .period_bytes_min = (32 * 4),
5732 .period_bytes_max = (4096 * 4) * HDSPM_MAX_CHANNELS, 5752 .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS,
5733 .periods_min = 2, 5753 .periods_min = 2,
5734 .periods_max = 512, 5754 .periods_max = 512,
5735 .fifo_size = 0 5755 .fifo_size = 0
5736}; 5756};
5737 5757
5738static struct snd_pcm_hw_constraint_list hw_constraints_period_sizes_old = {
5739 .count = ARRAY_SIZE(period_sizes_old),
5740 .list = period_sizes_old,
5741 .mask = 0
5742};
5743
5744static struct snd_pcm_hw_constraint_list hw_constraints_period_sizes_new = {
5745 .count = ARRAY_SIZE(period_sizes_new),
5746 .list = period_sizes_new,
5747 .mask = 0
5748};
5749
5750static struct snd_pcm_hw_constraint_list hw_constraints_raydat_io_buffer = {
5751 .count = ARRAY_SIZE(raydat_aio_buffer_sizes),
5752 .list = raydat_aio_buffer_sizes,
5753 .mask = 0
5754};
5755
5756static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params, 5758static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params,
5757 struct snd_pcm_hw_rule *rule) 5759 struct snd_pcm_hw_rule *rule)
5758{ 5760{
@@ -5953,26 +5955,29 @@ static int snd_hdspm_playback_open(struct snd_pcm_substream *substream)
5953 spin_unlock_irq(&hdspm->lock); 5955 spin_unlock_irq(&hdspm->lock);
5954 5956
5955 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); 5957 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
5958 snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
5956 5959
5957 switch (hdspm->io_type) { 5960 switch (hdspm->io_type) {
5958 case AIO: 5961 case AIO:
5959 case RayDAT: 5962 case RayDAT:
5960 snd_pcm_hw_constraint_list(runtime, 0, 5963 snd_pcm_hw_constraint_minmax(runtime,
5961 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 5964 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
5962 &hw_constraints_period_sizes_new); 5965 32, 4096);
5963 snd_pcm_hw_constraint_list(runtime, 0, 5966 /* RayDAT & AIO have a fixed buffer of 16384 samples per channel */
5964 SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 5967 snd_pcm_hw_constraint_minmax(runtime,
5965 &hw_constraints_raydat_io_buffer); 5968 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
5966 5969 16384, 16384);
5967 break; 5970 break;
5968 5971
5969 default: 5972 default:
5970 snd_pcm_hw_constraint_list(runtime, 0, 5973 snd_pcm_hw_constraint_minmax(runtime,
5971 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 5974 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
5972 &hw_constraints_period_sizes_old); 5975 64, 8192);
5976 break;
5973 } 5977 }
5974 5978
5975 if (AES32 == hdspm->io_type) { 5979 if (AES32 == hdspm->io_type) {
5980 runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
5976 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 5981 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
5977 &hdspm_hw_constraints_aes32_sample_rates); 5982 &hdspm_hw_constraints_aes32_sample_rates);
5978 } else { 5983 } else {
@@ -6025,24 +6030,28 @@ static int snd_hdspm_capture_open(struct snd_pcm_substream *substream)
6025 spin_unlock_irq(&hdspm->lock); 6030 spin_unlock_irq(&hdspm->lock);
6026 6031
6027 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); 6032 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
6033 snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
6034
6028 switch (hdspm->io_type) { 6035 switch (hdspm->io_type) {
6029 case AIO: 6036 case AIO:
6030 case RayDAT: 6037 case RayDAT:
6031 snd_pcm_hw_constraint_list(runtime, 0, 6038 snd_pcm_hw_constraint_minmax(runtime,
6032 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 6039 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6033 &hw_constraints_period_sizes_new); 6040 32, 4096);
6034 snd_pcm_hw_constraint_list(runtime, 0, 6041 snd_pcm_hw_constraint_minmax(runtime,
6035 SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 6042 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
6036 &hw_constraints_raydat_io_buffer); 6043 16384, 16384);
6037 break; 6044 break;
6038 6045
6039 default: 6046 default:
6040 snd_pcm_hw_constraint_list(runtime, 0, 6047 snd_pcm_hw_constraint_minmax(runtime,
6041 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 6048 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6042 &hw_constraints_period_sizes_old); 6049 64, 8192);
6050 break;
6043 } 6051 }
6044 6052
6045 if (AES32 == hdspm->io_type) { 6053 if (AES32 == hdspm->io_type) {
6054 runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
6046 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 6055 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6047 &hdspm_hw_constraints_aes32_sample_rates); 6056 &hdspm_hw_constraints_aes32_sample_rates);
6048 } else { 6057 } else {
@@ -6088,7 +6097,7 @@ static inline int copy_u32_le(void __user *dest, void __iomem *src)
6088} 6097}
6089 6098
6090static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, 6099static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
6091 unsigned int cmd, unsigned long __user arg) 6100 unsigned int cmd, unsigned long arg)
6092{ 6101{
6093 void __user *argp = (void __user *)arg; 6102 void __user *argp = (void __user *)arg;
6094 struct hdspm *hdspm = hw->private_data; 6103 struct hdspm *hdspm = hw->private_data;
@@ -6213,11 +6222,13 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
6213 info.line_out = hdspm_line_out(hdspm); 6222 info.line_out = hdspm_line_out(hdspm);
6214 info.passthru = 0; 6223 info.passthru = 0;
6215 spin_unlock_irq(&hdspm->lock); 6224 spin_unlock_irq(&hdspm->lock);
6216 if (copy_to_user((void __user *) arg, &info, sizeof(info))) 6225 if (copy_to_user(argp, &info, sizeof(info)))
6217 return -EFAULT; 6226 return -EFAULT;
6218 break; 6227 break;
6219 6228
6220 case SNDRV_HDSPM_IOCTL_GET_STATUS: 6229 case SNDRV_HDSPM_IOCTL_GET_STATUS:
6230 memset(&status, 0, sizeof(status));
6231
6221 status.card_type = hdspm->io_type; 6232 status.card_type = hdspm->io_type;
6222 6233
6223 status.autosync_source = hdspm_autosync_ref(hdspm); 6234 status.autosync_source = hdspm_autosync_ref(hdspm);
@@ -6250,13 +6261,15 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
6250 break; 6261 break;
6251 } 6262 }
6252 6263
6253 if (copy_to_user((void __user *) arg, &status, sizeof(status))) 6264 if (copy_to_user(argp, &status, sizeof(status)))
6254 return -EFAULT; 6265 return -EFAULT;
6255 6266
6256 6267
6257 break; 6268 break;
6258 6269
6259 case SNDRV_HDSPM_IOCTL_GET_VERSION: 6270 case SNDRV_HDSPM_IOCTL_GET_VERSION:
6271 memset(&hdspm_version, 0, sizeof(hdspm_version));
6272
6260 hdspm_version.card_type = hdspm->io_type; 6273 hdspm_version.card_type = hdspm->io_type;
6261 strncpy(hdspm_version.cardname, hdspm->card_name, 6274 strncpy(hdspm_version.cardname, hdspm->card_name,
6262 sizeof(hdspm_version.cardname)); 6275 sizeof(hdspm_version.cardname));
@@ -6267,13 +6280,13 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
6267 if (hdspm->tco) 6280 if (hdspm->tco)
6268 hdspm_version.addons |= HDSPM_ADDON_TCO; 6281 hdspm_version.addons |= HDSPM_ADDON_TCO;
6269 6282
6270 if (copy_to_user((void __user *) arg, &hdspm_version, 6283 if (copy_to_user(argp, &hdspm_version,
6271 sizeof(hdspm_version))) 6284 sizeof(hdspm_version)))
6272 return -EFAULT; 6285 return -EFAULT;
6273 break; 6286 break;
6274 6287
6275 case SNDRV_HDSPM_IOCTL_GET_MIXER: 6288 case SNDRV_HDSPM_IOCTL_GET_MIXER:
6276 if (copy_from_user(&mixer, (void __user *)arg, sizeof(mixer))) 6289 if (copy_from_user(&mixer, argp, sizeof(mixer)))
6277 return -EFAULT; 6290 return -EFAULT;
6278 if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer, 6291 if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer,
6279 sizeof(struct hdspm_mixer))) 6292 sizeof(struct hdspm_mixer)))