hdsp.c (c441bfb5f2866de71e092c1b9d866a65978dfe1a) hdsp.c (66c8f75919dd8561046a24430297c546c487cad9)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * ALSA driver for RME Hammerfall DSP audio interface(s)
4 *
5 * Copyright (c) 2002 Paul Davis
6 * Marcus Andersson
7 * Thomas Charbonnel
8 */

--- 275 unchanged lines hidden (view full) ---

284/* For H9632 cards */
285#define HDSP_Frequency128KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency0)
286#define HDSP_Frequency176_4KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1)
287#define HDSP_Frequency192KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
288/* RME says n = 104857600000000, but in the windows MADI driver, I see:
289 return 104857600000000 / rate; // 100 MHz
290 return 110100480000000 / rate; // 105 MHz
291*/
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * ALSA driver for RME Hammerfall DSP audio interface(s)
4 *
5 * Copyright (c) 2002 Paul Davis
6 * Marcus Andersson
7 * Thomas Charbonnel
8 */

--- 275 unchanged lines hidden (view full) ---

284/* For H9632 cards */
285#define HDSP_Frequency128KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency0)
286#define HDSP_Frequency176_4KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1)
287#define HDSP_Frequency192KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
288/* RME says n = 104857600000000, but in the windows MADI driver, I see:
289 return 104857600000000 / rate; // 100 MHz
290 return 110100480000000 / rate; // 105 MHz
291*/
292#define DDS_NUMERATOR 104857600000000ULL; /* = 2^20 * 10^8 */
292#define DDS_NUMERATOR 104857600000000ULL /* = 2^20 * 10^8 */
293
294#define hdsp_encode_latency(x) (((x)<<1) & HDSP_LatencyMask)
295#define hdsp_decode_latency(x) (((x) & HDSP_LatencyMask)>>1)
296
297#define hdsp_encode_spdif_in(x) (((x)&0x3)<<14)
298#define hdsp_decode_spdif_in(x) (((x)>>14)&0x3)
299
300/* Status Register bits */

--- 1012 unchanged lines hidden (view full) ---

1313 int i;
1314 unsigned char buf[128];
1315
1316 /* Output is not interrupt driven */
1317
1318 spin_lock_irqsave (&hmidi->lock, flags);
1319 if (hmidi->output) {
1320 if (!snd_rawmidi_transmit_empty (hmidi->output)) {
293
294#define hdsp_encode_latency(x) (((x)<<1) & HDSP_LatencyMask)
295#define hdsp_decode_latency(x) (((x) & HDSP_LatencyMask)>>1)
296
297#define hdsp_encode_spdif_in(x) (((x)&0x3)<<14)
298#define hdsp_decode_spdif_in(x) (((x)>>14)&0x3)
299
300/* Status Register bits */

--- 1012 unchanged lines hidden (view full) ---

1313 int i;
1314 unsigned char buf[128];
1315
1316 /* Output is not interrupt driven */
1317
1318 spin_lock_irqsave (&hmidi->lock, flags);
1319 if (hmidi->output) {
1320 if (!snd_rawmidi_transmit_empty (hmidi->output)) {
1321 if ((n_pending = snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id)) > 0) {
1321 n_pending = snd_hdsp_midi_output_possible(hmidi->hdsp, hmidi->id);
1322 if (n_pending > 0) {
1322 if (n_pending > (int)sizeof (buf))
1323 n_pending = sizeof (buf);
1324
1323 if (n_pending > (int)sizeof (buf))
1324 n_pending = sizeof (buf);
1325
1325 if ((to_write = snd_rawmidi_transmit (hmidi->output, buf, n_pending)) > 0) {
1326 to_write = snd_rawmidi_transmit(hmidi->output, buf, n_pending);
1327 if (to_write > 0) {
1326 for (i = 0; i < to_write; ++i)
1327 snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
1328 }
1329 }
1330 }
1331 }
1332 spin_unlock_irqrestore (&hmidi->lock, flags);
1333 return 0;
1334}
1335
1336static int snd_hdsp_midi_input_read (struct hdsp_midi *hmidi)
1337{
1338 unsigned char buf[128]; /* this buffer is designed to match the MIDI input FIFO size */
1339 unsigned long flags;
1340 int n_pending;
1341 int i;
1342
1343 spin_lock_irqsave (&hmidi->lock, flags);
1328 for (i = 0; i < to_write; ++i)
1329 snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
1330 }
1331 }
1332 }
1333 }
1334 spin_unlock_irqrestore (&hmidi->lock, flags);
1335 return 0;
1336}
1337
1338static int snd_hdsp_midi_input_read (struct hdsp_midi *hmidi)
1339{
1340 unsigned char buf[128]; /* this buffer is designed to match the MIDI input FIFO size */
1341 unsigned long flags;
1342 int n_pending;
1343 int i;
1344
1345 spin_lock_irqsave (&hmidi->lock, flags);
1344 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
1346 n_pending = snd_hdsp_midi_input_available(hmidi->hdsp, hmidi->id);
1347 if (n_pending > 0) {
1345 if (hmidi->input) {
1346 if (n_pending > (int)sizeof (buf))
1347 n_pending = sizeof (buf);
1348 for (i = 0; i < n_pending; ++i)
1349 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1350 if (n_pending)
1351 snd_rawmidi_receive (hmidi->input, buf, n_pending);
1352 } else {

--- 1964 unchanged lines hidden (view full) ---

3317 err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_rpm_controls[idx], hdsp));
3318 if (err < 0)
3319 return err;
3320 }
3321 return 0;
3322 }
3323
3324 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) {
1348 if (hmidi->input) {
1349 if (n_pending > (int)sizeof (buf))
1350 n_pending = sizeof (buf);
1351 for (i = 0; i < n_pending; ++i)
1352 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1353 if (n_pending)
1354 snd_rawmidi_receive (hmidi->input, buf, n_pending);
1355 } else {

--- 1964 unchanged lines hidden (view full) ---

3320 err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_rpm_controls[idx], hdsp));
3321 if (err < 0)
3322 return err;
3323 }
3324 return 0;
3325 }
3326
3327 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) {
3325 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0)
3328 kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp);
3329 err = snd_ctl_add(card, kctl);
3330 if (err < 0)
3326 return err;
3327 if (idx == 1) /* IEC958 (S/PDIF) Stream */
3328 hdsp->spdif_ctl = kctl;
3329 }
3330
3331 /* ADAT SyncCheck status */
3332 snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
3333 snd_hdsp_adat_sync_check.index = 1;
3331 return err;
3332 if (idx == 1) /* IEC958 (S/PDIF) Stream */
3333 hdsp->spdif_ctl = kctl;
3334 }
3335
3336 /* ADAT SyncCheck status */
3337 snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
3338 snd_hdsp_adat_sync_check.index = 1;
3334 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3339 kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp);
3340 err = snd_ctl_add(card, kctl);
3341 if (err < 0)
3335 return err;
3336 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3337 for (idx = 1; idx < 3; ++idx) {
3338 snd_hdsp_adat_sync_check.index = idx+1;
3342 return err;
3343 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3344 for (idx = 1; idx < 3; ++idx) {
3345 snd_hdsp_adat_sync_check.index = idx+1;
3339 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3346 kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp);
3347 err = snd_ctl_add(card, kctl);
3348 if (err < 0)
3340 return err;
3341 }
3342 }
3343
3344 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3345 if (hdsp->io_type == H9632) {
3346 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
3349 return err;
3350 }
3351 }
3352
3353 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3354 if (hdsp->io_type == H9632) {
3355 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
3347 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0)
3356 kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp);
3357 err = snd_ctl_add(card, kctl);
3358 if (err < 0)
3348 return err;
3349 }
3350 }
3351
3352 /* Output loopback controls for H9632 cards */
3353 if (hdsp->io_type == H9632) {
3354 snd_hdsp_loopback_control.count = hdsp->max_channels;
3355 kctl = snd_ctl_new1(&snd_hdsp_loopback_control, hdsp);
3356 if (kctl == NULL)
3357 return -ENOMEM;
3358 err = snd_ctl_add(card, kctl);
3359 if (err < 0)
3360 return err;
3361 }
3362
3363 /* AEB control for H96xx card */
3364 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3359 return err;
3360 }
3361 }
3362
3363 /* Output loopback controls for H9632 cards */
3364 if (hdsp->io_type == H9632) {
3365 snd_hdsp_loopback_control.count = hdsp->max_channels;
3366 kctl = snd_ctl_new1(&snd_hdsp_loopback_control, hdsp);
3367 if (kctl == NULL)
3368 return -ENOMEM;
3369 err = snd_ctl_add(card, kctl);
3370 if (err < 0)
3371 return err;
3372 }
3373
3374 /* AEB control for H96xx card */
3375 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3365 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0)
3366 return err;
3376 kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp);
3377 err = snd_ctl_add(card, kctl);
3378 if (err < 0)
3379 return err;
3367 }
3368
3369 return 0;
3370}
3371
3372/*------------------------------------------------------------
3373 /proc interface
3374 ------------------------------------------------------------*/

--- 562 unchanged lines hidden (view full) ---

3937 int channel)
3938
3939{
3940 int mapped_channel;
3941
3942 if (snd_BUG_ON(channel < 0 || channel >= hdsp->max_channels))
3943 return NULL;
3944
3380 }
3381
3382 return 0;
3383}
3384
3385/*------------------------------------------------------------
3386 /proc interface
3387 ------------------------------------------------------------*/

--- 562 unchanged lines hidden (view full) ---

3950 int channel)
3951
3952{
3953 int mapped_channel;
3954
3955 if (snd_BUG_ON(channel < 0 || channel >= hdsp->max_channels))
3956 return NULL;
3957
3945 if ((mapped_channel = hdsp->channel_map[channel]) < 0)
3958 mapped_channel = hdsp->channel_map[channel];
3959 if (mapped_channel < 0)
3946 return NULL;
3947
3948 if (stream == SNDRV_PCM_STREAM_CAPTURE)
3949 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3950 else
3951 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3952}
3953

--- 155 unchanged lines hidden (view full) ---

4109 spin_unlock_irq(&hdsp->lock);
4110 }
4111
4112 /* how to make sure that the rate matches an externally-set one ?
4113 */
4114
4115 spin_lock_irq(&hdsp->lock);
4116 if (! hdsp->clock_source_locked) {
3960 return NULL;
3961
3962 if (stream == SNDRV_PCM_STREAM_CAPTURE)
3963 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3964 else
3965 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3966}
3967

--- 155 unchanged lines hidden (view full) ---

4123 spin_unlock_irq(&hdsp->lock);
4124 }
4125
4126 /* how to make sure that the rate matches an externally-set one ?
4127 */
4128
4129 spin_lock_irq(&hdsp->lock);
4130 if (! hdsp->clock_source_locked) {
4117 if ((err = hdsp_set_rate(hdsp, params_rate(params), 0)) < 0) {
4131 err = hdsp_set_rate(hdsp, params_rate(params), 0);
4132 if (err < 0) {
4118 spin_unlock_irq(&hdsp->lock);
4119 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
4120 return err;
4121 }
4122 }
4123 spin_unlock_irq(&hdsp->lock);
4124
4133 spin_unlock_irq(&hdsp->lock);
4134 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
4135 return err;
4136 }
4137 }
4138 spin_unlock_irq(&hdsp->lock);
4139
4125 if ((err = hdsp_set_interrupt_interval(hdsp, params_period_size(params))) < 0) {
4140 err = hdsp_set_interrupt_interval(hdsp, params_period_size(params));
4141 if (err < 0) {
4126 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
4127 return err;
4128 }
4129
4130 return 0;
4131}
4132
4133static int snd_hdsp_channel_info(struct snd_pcm_substream *substream,

--- 715 unchanged lines hidden (view full) ---

4849 break;
4850 }
4851 case SNDRV_HDSP_IOCTL_GET_VERSION: {
4852 struct hdsp_version hdsp_version;
4853 int err;
4854
4855 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4856 if (hdsp->io_type == Undefined) {
4142 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
4143 return err;
4144 }
4145
4146 return 0;
4147}
4148
4149static int snd_hdsp_channel_info(struct snd_pcm_substream *substream,

--- 715 unchanged lines hidden (view full) ---

4865 break;
4866 }
4867 case SNDRV_HDSP_IOCTL_GET_VERSION: {
4868 struct hdsp_version hdsp_version;
4869 int err;
4870
4871 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4872 if (hdsp->io_type == Undefined) {
4857 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4873 err = hdsp_get_iobox_version(hdsp);
4874 if (err < 0)
4858 return err;
4859 }
4860 memset(&hdsp_version, 0, sizeof(hdsp_version));
4861 hdsp_version.io_type = hdsp->io_type;
4862 hdsp_version.firmware_rev = hdsp->firmware_rev;
4875 return err;
4876 }
4877 memset(&hdsp_version, 0, sizeof(hdsp_version));
4878 hdsp_version.io_type = hdsp->io_type;
4879 hdsp_version.firmware_rev = hdsp->firmware_rev;
4863 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version))))
4880 err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version));
4881 if (err < 0)
4864 return -EFAULT;
4865 break;
4866 }
4867 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: {
4868 struct hdsp_firmware firmware;
4869 u32 __user *firmware_data;
4870 int err;
4871

--- 23 unchanged lines hidden (view full) ---

4895 HDSP_FIRMWARE_SIZE)) {
4896 vfree(hdsp->fw_uploaded);
4897 hdsp->fw_uploaded = NULL;
4898 return -EFAULT;
4899 }
4900
4901 hdsp->state |= HDSP_FirmwareCached;
4902
4882 return -EFAULT;
4883 break;
4884 }
4885 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: {
4886 struct hdsp_firmware firmware;
4887 u32 __user *firmware_data;
4888 int err;
4889

--- 23 unchanged lines hidden (view full) ---

4913 HDSP_FIRMWARE_SIZE)) {
4914 vfree(hdsp->fw_uploaded);
4915 hdsp->fw_uploaded = NULL;
4916 return -EFAULT;
4917 }
4918
4919 hdsp->state |= HDSP_FirmwareCached;
4920
4903 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4921 err = snd_hdsp_load_firmware_from_cache(hdsp);
4922 if (err < 0)
4904 return err;
4905
4906 if (!(hdsp->state & HDSP_InitializationComplete)) {
4923 return err;
4924
4925 if (!(hdsp->state & HDSP_InitializationComplete)) {
4907 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4926 err = snd_hdsp_enable_io(hdsp);
4927 if (err < 0)
4908 return err;
4909
4910 snd_hdsp_initialize_channels(hdsp);
4911 snd_hdsp_initialize_midi_flush(hdsp);
4912
4928 return err;
4929
4930 snd_hdsp_initialize_channels(hdsp);
4931 snd_hdsp_initialize_midi_flush(hdsp);
4932
4913 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4933 err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp);
4934 if (err < 0) {
4914 dev_err(hdsp->card->dev,
4915 "error creating alsa devices\n");
4916 return err;
4917 }
4918 }
4919 break;
4920 }
4921 case SNDRV_HDSP_IOCTL_GET_MIXER: {

--- 33 unchanged lines hidden (view full) ---

4955 .copy_kernel = snd_hdsp_capture_copy_kernel,
4956};
4957
4958static int snd_hdsp_create_hwdep(struct snd_card *card, struct hdsp *hdsp)
4959{
4960 struct snd_hwdep *hw;
4961 int err;
4962
4935 dev_err(hdsp->card->dev,
4936 "error creating alsa devices\n");
4937 return err;
4938 }
4939 }
4940 break;
4941 }
4942 case SNDRV_HDSP_IOCTL_GET_MIXER: {

--- 33 unchanged lines hidden (view full) ---

4976 .copy_kernel = snd_hdsp_capture_copy_kernel,
4977};
4978
4979static int snd_hdsp_create_hwdep(struct snd_card *card, struct hdsp *hdsp)
4980{
4981 struct snd_hwdep *hw;
4982 int err;
4983
4963 if ((err = snd_hwdep_new(card, "HDSP hwdep", 0, &hw)) < 0)
4984 err = snd_hwdep_new(card, "HDSP hwdep", 0, &hw);
4985 if (err < 0)
4964 return err;
4965
4966 hdsp->hwdep = hw;
4967 hw->private_data = hdsp;
4968 strcpy(hw->name, "HDSP hwdep interface");
4969
4970 hw->ops.ioctl = snd_hdsp_hwdep_ioctl;
4971 hw->ops.ioctl_compat = snd_hdsp_hwdep_ioctl;
4972
4973 return 0;
4974}
4975
4976static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp)
4977{
4978 struct snd_pcm *pcm;
4979 int err;
4980
4986 return err;
4987
4988 hdsp->hwdep = hw;
4989 hw->private_data = hdsp;
4990 strcpy(hw->name, "HDSP hwdep interface");
4991
4992 hw->ops.ioctl = snd_hdsp_hwdep_ioctl;
4993 hw->ops.ioctl_compat = snd_hdsp_hwdep_ioctl;
4994
4995 return 0;
4996}
4997
4998static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp)
4999{
5000 struct snd_pcm *pcm;
5001 int err;
5002
4981 if ((err = snd_pcm_new(card, hdsp->card_name, 0, 1, 1, &pcm)) < 0)
5003 err = snd_pcm_new(card, hdsp->card_name, 0, 1, 1, &pcm);
5004 if (err < 0)
4982 return err;
4983
4984 hdsp->pcm = pcm;
4985 pcm->private_data = hdsp;
4986 strcpy(pcm->name, hdsp->card_name);
4987
4988 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_hdsp_playback_ops);
4989 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_hdsp_capture_ops);

--- 89 unchanged lines hidden (view full) ---

5079 snd_hdsp_flush_midi_input (hdsp, 0);
5080 snd_hdsp_flush_midi_input (hdsp, 1);
5081}
5082
5083static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp)
5084{
5085 int err;
5086
5005 return err;
5006
5007 hdsp->pcm = pcm;
5008 pcm->private_data = hdsp;
5009 strcpy(pcm->name, hdsp->card_name);
5010
5011 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_hdsp_playback_ops);
5012 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_hdsp_capture_ops);

--- 89 unchanged lines hidden (view full) ---

5102 snd_hdsp_flush_midi_input (hdsp, 0);
5103 snd_hdsp_flush_midi_input (hdsp, 1);
5104}
5105
5106static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp)
5107{
5108 int err;
5109
5087 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
5110 err = snd_hdsp_create_pcm(card, hdsp);
5111 if (err < 0) {
5088 dev_err(card->dev,
5089 "Error creating pcm interface\n");
5090 return err;
5091 }
5092
5093
5112 dev_err(card->dev,
5113 "Error creating pcm interface\n");
5114 return err;
5115 }
5116
5117
5094 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
5118 err = snd_hdsp_create_midi(card, hdsp, 0);
5119 if (err < 0) {
5095 dev_err(card->dev,
5096 "Error creating first midi interface\n");
5097 return err;
5098 }
5099
5100 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
5120 dev_err(card->dev,
5121 "Error creating first midi interface\n");
5122 return err;
5123 }
5124
5125 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
5101 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
5126 err = snd_hdsp_create_midi(card, hdsp, 1);
5127 if (err < 0) {
5102 dev_err(card->dev,
5103 "Error creating second midi interface\n");
5104 return err;
5105 }
5106 }
5107
5128 dev_err(card->dev,
5129 "Error creating second midi interface\n");
5130 return err;
5131 }
5132 }
5133
5108 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
5134 err = snd_hdsp_create_controls(card, hdsp);
5135 if (err < 0) {
5109 dev_err(card->dev,
5110 "Error creating ctl interface\n");
5111 return err;
5112 }
5113
5114 snd_hdsp_proc_init(hdsp);
5115
5116 hdsp->system_sample_rate = -1;
5117 hdsp->playback_pid = -1;
5118 hdsp->capture_pid = -1;
5119 hdsp->capture_substream = NULL;
5120 hdsp->playback_substream = NULL;
5121
5136 dev_err(card->dev,
5137 "Error creating ctl interface\n");
5138 return err;
5139 }
5140
5141 snd_hdsp_proc_init(hdsp);
5142
5143 hdsp->system_sample_rate = -1;
5144 hdsp->playback_pid = -1;
5145 hdsp->capture_pid = -1;
5146 hdsp->capture_substream = NULL;
5147 hdsp->playback_substream = NULL;
5148
5122 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
5149 err = snd_hdsp_set_defaults(hdsp);
5150 if (err < 0) {
5123 dev_err(card->dev,
5124 "Error setting default values\n");
5125 return err;
5126 }
5127
5128 if (!(hdsp->state & HDSP_InitializationComplete)) {
5129 strcpy(card->shortname, "Hammerfall DSP");
5130 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5131 hdsp->port, hdsp->irq);
5132
5151 dev_err(card->dev,
5152 "Error setting default values\n");
5153 return err;
5154 }
5155
5156 if (!(hdsp->state & HDSP_InitializationComplete)) {
5157 strcpy(card->shortname, "Hammerfall DSP");
5158 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5159 hdsp->port, hdsp->irq);
5160
5133 if ((err = snd_card_register(card)) < 0) {
5161 err = snd_card_register(card);
5162 if (err < 0) {
5134 dev_err(card->dev,
5135 "error registering card\n");
5136 return err;
5137 }
5138 hdsp->state |= HDSP_InitializationComplete;
5139 }
5140
5141 return 0;

--- 4 unchanged lines hidden (view full) ---

5146{
5147 const char *fwfile;
5148 const struct firmware *fw;
5149 int err;
5150
5151 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
5152 return 0;
5153 if (hdsp->io_type == Undefined) {
5163 dev_err(card->dev,
5164 "error registering card\n");
5165 return err;
5166 }
5167 hdsp->state |= HDSP_InitializationComplete;
5168 }
5169
5170 return 0;

--- 4 unchanged lines hidden (view full) ---

5175{
5176 const char *fwfile;
5177 const struct firmware *fw;
5178 int err;
5179
5180 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
5181 return 0;
5182 if (hdsp->io_type == Undefined) {
5154 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
5183 err = hdsp_get_iobox_version(hdsp);
5184 if (err < 0)
5155 return err;
5156 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
5157 return 0;
5158 }
5159
5160 /* caution: max length of firmware filename is 30! */
5161 switch (hdsp->io_type) {
5162 case RPM:

--- 29 unchanged lines hidden (view full) ---

5192 release_firmware(fw);
5193 return -EINVAL;
5194 }
5195
5196 hdsp->firmware = fw;
5197
5198 hdsp->state |= HDSP_FirmwareCached;
5199
5185 return err;
5186 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
5187 return 0;
5188 }
5189
5190 /* caution: max length of firmware filename is 30! */
5191 switch (hdsp->io_type) {
5192 case RPM:

--- 29 unchanged lines hidden (view full) ---

5222 release_firmware(fw);
5223 return -EINVAL;
5224 }
5225
5226 hdsp->firmware = fw;
5227
5228 hdsp->state |= HDSP_FirmwareCached;
5229
5200 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
5230 err = snd_hdsp_load_firmware_from_cache(hdsp);
5231 if (err < 0)
5201 return err;
5202
5203 if (!(hdsp->state & HDSP_InitializationComplete)) {
5232 return err;
5233
5234 if (!(hdsp->state & HDSP_InitializationComplete)) {
5204 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
5235 err = snd_hdsp_enable_io(hdsp);
5236 if (err < 0)
5205 return err;
5206
5237 return err;
5238
5207 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) {
5239 err = snd_hdsp_create_hwdep(hdsp->card, hdsp);
5240 if (err < 0) {
5208 dev_err(hdsp->card->dev,
5209 "error creating hwdep device\n");
5210 return err;
5211 }
5212 snd_hdsp_initialize_channels(hdsp);
5213 snd_hdsp_initialize_midi_flush(hdsp);
5241 dev_err(hdsp->card->dev,
5242 "error creating hwdep device\n");
5243 return err;
5244 }
5245 snd_hdsp_initialize_channels(hdsp);
5246 snd_hdsp_initialize_midi_flush(hdsp);
5214 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
5247 err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp);
5248 if (err < 0) {
5215 dev_err(hdsp->card->dev,
5216 "error creating alsa devices\n");
5217 return err;
5218 }
5219 }
5220 return 0;
5221}
5222

--- 52 unchanged lines hidden (view full) ---

5275 hdsp->card_name = "RME HDSP 9652";
5276 is_9652 = 1;
5277 } else {
5278 hdsp->card_name = "RME HDSP 9632";
5279 hdsp->max_channels = 16;
5280 is_9632 = 1;
5281 }
5282
5249 dev_err(hdsp->card->dev,
5250 "error creating alsa devices\n");
5251 return err;
5252 }
5253 }
5254 return 0;
5255}
5256

--- 52 unchanged lines hidden (view full) ---

5309 hdsp->card_name = "RME HDSP 9652";
5310 is_9652 = 1;
5311 } else {
5312 hdsp->card_name = "RME HDSP 9632";
5313 hdsp->max_channels = 16;
5314 is_9632 = 1;
5315 }
5316
5283 if ((err = pci_enable_device(pci)) < 0)
5317 err = pci_enable_device(pci);
5318 if (err < 0)
5284 return err;
5285
5286 pci_set_master(hdsp->pci);
5287
5319 return err;
5320
5321 pci_set_master(hdsp->pci);
5322
5288 if ((err = pci_request_regions(pci, "hdsp")) < 0)
5323 err = pci_request_regions(pci, "hdsp");
5324 if (err < 0)
5289 return err;
5290 hdsp->port = pci_resource_start(pci, 0);
5325 return err;
5326 hdsp->port = pci_resource_start(pci, 0);
5291 if ((hdsp->iobase = ioremap(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
5327 hdsp->iobase = ioremap(hdsp->port, HDSP_IO_EXTENT);
5328 if (!hdsp->iobase) {
5292 dev_err(hdsp->card->dev, "unable to remap region 0x%lx-0x%lx\n",
5293 hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
5294 return -EBUSY;
5295 }
5296
5297 if (request_irq(pci->irq, snd_hdsp_interrupt, IRQF_SHARED,
5298 KBUILD_MODNAME, hdsp)) {
5299 dev_err(hdsp->card->dev, "unable to use IRQ %d\n", pci->irq);
5300 return -EBUSY;
5301 }
5302
5303 hdsp->irq = pci->irq;
5304 card->sync_irq = hdsp->irq;
5305 hdsp->precise_ptr = 0;
5306 hdsp->use_midi_work = 1;
5307 hdsp->dds_value = 0;
5308
5329 dev_err(hdsp->card->dev, "unable to remap region 0x%lx-0x%lx\n",
5330 hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
5331 return -EBUSY;
5332 }
5333
5334 if (request_irq(pci->irq, snd_hdsp_interrupt, IRQF_SHARED,
5335 KBUILD_MODNAME, hdsp)) {
5336 dev_err(hdsp->card->dev, "unable to use IRQ %d\n", pci->irq);
5337 return -EBUSY;
5338 }
5339
5340 hdsp->irq = pci->irq;
5341 card->sync_irq = hdsp->irq;
5342 hdsp->precise_ptr = 0;
5343 hdsp->use_midi_work = 1;
5344 hdsp->dds_value = 0;
5345
5309 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0)
5346 err = snd_hdsp_initialize_memory(hdsp);
5347 if (err < 0)
5310 return err;
5311
5312 if (!is_9652 && !is_9632) {
5313 /* we wait a maximum of 10 seconds to let freshly
5314 * inserted cardbus cards do their hardware init */
5315 err = hdsp_wait_for_iobox(hdsp, 1000, 10);
5316
5317 if (err < 0)
5318 return err;
5319
5320 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
5348 return err;
5349
5350 if (!is_9652 && !is_9632) {
5351 /* we wait a maximum of 10 seconds to let freshly
5352 * inserted cardbus cards do their hardware init */
5353 err = hdsp_wait_for_iobox(hdsp, 1000, 10);
5354
5355 if (err < 0)
5356 return err;
5357
5358 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
5321 if ((err = hdsp_request_fw_loader(hdsp)) < 0)
5359 err = hdsp_request_fw_loader(hdsp);
5360 if (err < 0)
5322 /* we don't fail as this can happen
5323 if userspace is not ready for
5324 firmware upload
5325 */
5326 dev_err(hdsp->card->dev,
5327 "couldn't get firmware from userspace. try using hdsploader\n");
5328 else
5329 /* init is complete, we return */
5330 return 0;
5331 /* we defer initialization */
5332 dev_info(hdsp->card->dev,
5333 "card initialization pending : waiting for firmware\n");
5361 /* we don't fail as this can happen
5362 if userspace is not ready for
5363 firmware upload
5364 */
5365 dev_err(hdsp->card->dev,
5366 "couldn't get firmware from userspace. try using hdsploader\n");
5367 else
5368 /* init is complete, we return */
5369 return 0;
5370 /* we defer initialization */
5371 dev_info(hdsp->card->dev,
5372 "card initialization pending : waiting for firmware\n");
5334 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5373 err = snd_hdsp_create_hwdep(card, hdsp);
5374 if (err < 0)
5335 return err;
5336 return 0;
5337 } else {
5338 dev_info(hdsp->card->dev,
5339 "Firmware already present, initializing card.\n");
5340 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2)
5341 hdsp->io_type = RPM;
5342 else if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
5343 hdsp->io_type = Multiface;
5344 else
5345 hdsp->io_type = Digiface;
5346 }
5347 }
5348
5375 return err;
5376 return 0;
5377 } else {
5378 dev_info(hdsp->card->dev,
5379 "Firmware already present, initializing card.\n");
5380 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2)
5381 hdsp->io_type = RPM;
5382 else if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
5383 hdsp->io_type = Multiface;
5384 else
5385 hdsp->io_type = Digiface;
5386 }
5387 }
5388
5349 if ((err = snd_hdsp_enable_io(hdsp)) != 0)
5389 err = snd_hdsp_enable_io(hdsp);
5390 if (err)
5350 return err;
5351
5352 if (is_9652)
5353 hdsp->io_type = H9652;
5354
5355 if (is_9632)
5356 hdsp->io_type = H9632;
5357
5391 return err;
5392
5393 if (is_9652)
5394 hdsp->io_type = H9652;
5395
5396 if (is_9632)
5397 hdsp->io_type = H9632;
5398
5358 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5399 err = snd_hdsp_create_hwdep(card, hdsp);
5400 if (err < 0)
5359 return err;
5360
5361 snd_hdsp_initialize_channels(hdsp);
5362 snd_hdsp_initialize_midi_flush(hdsp);
5363
5364 hdsp->state |= HDSP_FirmwareLoaded;
5365
5401 return err;
5402
5403 snd_hdsp_initialize_channels(hdsp);
5404 snd_hdsp_initialize_midi_flush(hdsp);
5405
5406 hdsp->state |= HDSP_FirmwareLoaded;
5407
5366 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0)
5408 err = snd_hdsp_create_alsa_devices(card, hdsp);
5409 if (err < 0)
5367 return err;
5368
5369 return 0;
5370}
5371
5372static int snd_hdsp_free(struct hdsp *hdsp)
5373{
5374 if (hdsp->port) {

--- 86 unchanged lines hidden ---
5410 return err;
5411
5412 return 0;
5413}
5414
5415static int snd_hdsp_free(struct hdsp *hdsp)
5416{
5417 if (hdsp->port) {

--- 86 unchanged lines hidden ---