static int snd_us428ctls_mmap(snd_hwdep_t * hw, struct file *filp, struct vm_area_struct *area)
{
unsigned long size = (unsigned long)(area->vm_end - area->vm_start);
- usX2Ydev_t *us428 = (usX2Ydev_t*)hw->private_data;
+ usX2Ydev_t *us428 = hw->private_data;
// FIXME this hwdep interface is used twice: fpga download and mmap for controlling Lights etc. Maybe better using 2 hwdep devs?
// so as long as the device isn't fully initialised yet we return -EBUSY here.
- if (!(((usX2Ydev_t*)hw->private_data)->chip_status & USX2Y_STAT_CHIP_INIT))
+ if (!(us428->chip_status & USX2Y_STAT_CHIP_INIT))
return -EBUSY;
/* if userspace tries to mmap beyond end of our buffer, fail */
- if (size > ((PAGE_SIZE - 1 + sizeof(us428ctls_sharedmem_t)) / PAGE_SIZE) * PAGE_SIZE) {
+ if (size > PAGE_ALIGN(sizeof(us428ctls_sharedmem_t))) {
snd_printd( "%lu > %lu\n", size, (unsigned long)sizeof(us428ctls_sharedmem_t));
return -EINVAL;
}
static unsigned int snd_us428ctls_poll(snd_hwdep_t *hw, struct file *file, poll_table *wait)
{
unsigned int mask = 0;
- usX2Ydev_t *us428 = (usX2Ydev_t*)hw->private_data;
+ usX2Ydev_t *us428 = hw->private_data;
us428ctls_sharedmem_t *shm = us428->us428ctls_sharedmem;
if (us428->chip_status & USX2Y_STAT_CHIP_HUP)
return POLLHUP;
[USX2Y_TYPE_224] = "us224",
[USX2Y_TYPE_428] = "us428",
};
+ usX2Ydev_t *us428 = hw->private_data;
int id = -1;
- switch (le16_to_cpu(((usX2Ydev_t*)hw->private_data)->chip.dev->descriptor.idProduct)) {
+ switch (le16_to_cpu(us428->chip.dev->descriptor.idProduct)) {
case USB_ID_US122:
id = USX2Y_TYPE_122;
break;
return -ENODEV;
strcpy(info->id, type_ids[id]);
info->num_dsps = 2; // 0: Prepad Data, 1: FPGA Code
- if (((usX2Ydev_t*)hw->private_data)->chip_status & USX2Y_STAT_CHIP_INIT)
+ if (us428->chip_status & USX2Y_STAT_CHIP_INIT)
info->chip_ready = 1;
info->version = USX2Y_DRIVER_VERSION;
return 0;
static inline int usX2Y_usbframe_complete(snd_usX2Y_substream_t *capsubs, snd_usX2Y_substream_t *playbacksubs, int frame)
{
int err, state;
- {
- struct urb *urb = playbacksubs->completed_urb;
-
- state = atomic_read(&playbacksubs->state);
- if (NULL != urb) {
- if (state == state_RUNNING)
- usX2Y_urb_play_retire(playbacksubs, urb);
- else
- if (state >= state_PRERUNNING) {
- atomic_inc(&playbacksubs->state);
- }
- } else {
- switch (state) {
- case state_STARTING1:
- urb = playbacksubs->urb[0];
+ struct urb *urb = playbacksubs->completed_urb;
+
+ state = atomic_read(&playbacksubs->state);
+ if (NULL != urb) {
+ if (state == state_RUNNING)
+ usX2Y_urb_play_retire(playbacksubs, urb);
+ else
+ if (state >= state_PRERUNNING)
atomic_inc(&playbacksubs->state);
- break;
- case state_STARTING2:
- urb = playbacksubs->urb[1];
- atomic_inc(&playbacksubs->state);
- break;
- }
- }
- if (urb) {
- if ((err = usX2Y_urb_play_prepare(playbacksubs, capsubs->completed_urb, urb)) ||
- (err = usX2Y_urb_submit(playbacksubs, urb, frame))) {
- return err;
- }
+ } else {
+ switch (state) {
+ case state_STARTING1:
+ urb = playbacksubs->urb[0];
+ atomic_inc(&playbacksubs->state);
+ break;
+ case state_STARTING2:
+ urb = playbacksubs->urb[1];
+ atomic_inc(&playbacksubs->state);
+ break;
}
-
- playbacksubs->completed_urb = NULL;
}
+ if (urb) {
+ if ((err = usX2Y_urb_play_prepare(playbacksubs, capsubs->completed_urb, urb)) ||
+ (err = usX2Y_urb_submit(playbacksubs, urb, frame)))
+ return err;
+ }
+
+ playbacksubs->completed_urb = NULL;
+
state = atomic_read(&capsubs->state);
if (state >= state_PREPARED) {
if (state == state_RUNNING) {
if ((err = usX2Y_urb_capt_retire(capsubs)))
return err;
- } else
- if (state >= state_PRERUNNING) {
- atomic_inc(&capsubs->state);
- }
+ } else if (state >= state_PRERUNNING)
+ atomic_inc(&capsubs->state);
if ((err = usX2Y_urb_submit(capsubs, capsubs->completed_urb, frame)))
return err;
}
}
/* allocate and initialize data urbs */
for (i = 0; i < NRURBS; i++) {
- struct urb** purb = subs->urb + i;
+ struct urb **purb = subs->urb + i;
if (*purb) {
usb_kill_urb(*purb);
continue;
goto start;
}
usX2Y->wait_iso_frame = -1;
+
start:
- {
- usX2Y_subs_startup(subs);
- for (i = 0; i < NRURBS; i++) {
- struct urb *urb = subs->urb[i];
- if (usb_pipein(urb->pipe)) {
- unsigned long pack;
- if (0 == i)
- atomic_set(&subs->state, state_STARTING3);
- urb->dev = usX2Y->chip.dev;
- urb->transfer_flags = URB_ISO_ASAP;
- for (pack = 0; pack < nr_of_packs(); pack++) {
- urb->iso_frame_desc[pack].offset = subs->maxpacksize * pack;
- urb->iso_frame_desc[pack].length = subs->maxpacksize;
- }
- urb->transfer_buffer_length = subs->maxpacksize * nr_of_packs();
- if ((err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
- snd_printk (KERN_ERR "cannot submit datapipe for urb %d, err = %d\n", i, err);
- err = -EPIPE;
- goto cleanup;
- } else {
- if (0 > usX2Y->wait_iso_frame)
- usX2Y->wait_iso_frame = urb->start_frame;
- }
- urb->transfer_flags = 0;
+ usX2Y_subs_startup(subs);
+ for (i = 0; i < NRURBS; i++) {
+ struct urb *urb = subs->urb[i];
+ if (usb_pipein(urb->pipe)) {
+ unsigned long pack;
+ if (0 == i)
+ atomic_set(&subs->state, state_STARTING3);
+ urb->dev = usX2Y->chip.dev;
+ urb->transfer_flags = URB_ISO_ASAP;
+ for (pack = 0; pack < nr_of_packs(); pack++) {
+ urb->iso_frame_desc[pack].offset = subs->maxpacksize * pack;
+ urb->iso_frame_desc[pack].length = subs->maxpacksize;
+ }
+ urb->transfer_buffer_length = subs->maxpacksize * nr_of_packs();
+ if ((err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
+ snd_printk (KERN_ERR "cannot submit datapipe for urb %d, err = %d\n", i, err);
+ err = -EPIPE;
+ goto cleanup;
} else {
- atomic_set(&subs->state, state_STARTING1);
- break;
+ if (0 > usX2Y->wait_iso_frame)
+ usX2Y->wait_iso_frame = urb->start_frame;
}
+ urb->transfer_flags = 0;
+ } else {
+ atomic_set(&subs->state, state_STARTING1);
+ break;
}
- err = 0;
- wait_event(usX2Y->prepare_wait_queue, NULL == usX2Y->prepare_subs);
- if (atomic_read(&subs->state) != state_PREPARED) {
- err = -EPIPE;
- }
+ }
+ err = 0;
+ wait_event(usX2Y->prepare_wait_queue, NULL == usX2Y->prepare_subs);
+ if (atomic_read(&subs->state) != state_PREPARED)
+ err = -EPIPE;
- cleanup:
- if (err) {
- usX2Y_subs_startup_finish(usX2Y);
- usX2Y_clients_stop(usX2Y); // something is completely wroong > stop evrything
- }
+ cleanup:
+ if (err) {
+ usX2Y_subs_startup_finish(usX2Y);
+ usX2Y_clients_stop(usX2Y); // something is completely wroong > stop evrything
}
return err;
}
struct s_c2 *ra = rate == 48000 ? SetRate48000 : SetRate44100;
if (usX2Y->rate != rate) {
- us = kmalloc(sizeof(*us) + sizeof(struct urb*) * NOOF_SETRATE_URBS, GFP_KERNEL);
+ us = kzalloc(sizeof(*us) + sizeof(struct urb*) * NOOF_SETRATE_URBS, GFP_KERNEL);
if (NULL == us) {
err = -ENOMEM;
goto cleanup;
}
- memset(us, 0, sizeof(*us) + sizeof(struct urb*) * NOOF_SETRATE_URBS);
- usbdata = kmalloc(sizeof(int)*NOOF_SETRATE_URBS, GFP_KERNEL);
+ usbdata = kmalloc(sizeof(int) * NOOF_SETRATE_URBS, GFP_KERNEL);
if (NULL == usbdata) {
err = -ENOMEM;
goto cleanup;
usX2Y->US04 = NULL;
kfree(usbdata);
kfree(us);
- if (!err) {
+ if (!err)
usX2Y->rate = rate;
- }
}
}
int err = 0;
unsigned int rate = params_rate(hw_params);
snd_pcm_format_t format = params_format(hw_params);
- snd_printdd("snd_usX2Y_hw_params(%p, %p)\n", substream, hw_params);
-
- { // all pcm substreams off one usX2Y have to operate at the same rate & format
snd_card_t *card = substream->pstr->pcm->card;
struct list_head *list;
- list_for_each(list, &card->devices) {
- snd_device_t *dev;
- snd_pcm_t *pcm;
- int s;
- dev = snd_device(list);
- if (dev->type != SNDRV_DEV_PCM)
- continue;
- pcm = dev->device_data;
- for (s = 0; s < 2; ++s) {
- snd_pcm_substream_t *test_substream;
- test_substream = pcm->streams[s].substream;
- if (test_substream && test_substream != substream &&
- test_substream->runtime &&
- ((test_substream->runtime->format &&
- test_substream->runtime->format != format) ||
- (test_substream->runtime->rate &&
- test_substream->runtime->rate != rate)))
- return -EINVAL;
- }
+
+ snd_printdd("snd_usX2Y_hw_params(%p, %p)\n", substream, hw_params);
+ // all pcm substreams off one usX2Y have to operate at the same rate & format
+ list_for_each(list, &card->devices) {
+ snd_device_t *dev;
+ snd_pcm_t *pcm;
+ int s;
+ dev = snd_device(list);
+ if (dev->type != SNDRV_DEV_PCM)
+ continue;
+ pcm = dev->device_data;
+ for (s = 0; s < 2; ++s) {
+ snd_pcm_substream_t *test_substream;
+ test_substream = pcm->streams[s].substream;
+ if (test_substream && test_substream != substream &&
+ test_substream->runtime &&
+ ((test_substream->runtime->format &&
+ test_substream->runtime->format != format) ||
+ (test_substream->runtime->rate &&
+ test_substream->runtime->rate != rate)))
+ return -EINVAL;
}
}
if (0 > (err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)))) {
if (NULL != urb) {
if (state == state_RUNNING)
usX2Y_urb_play_retire(playbacksubs, urb);
- else
- if (state >= state_PRERUNNING) {
- atomic_inc(&playbacksubs->state);
- }
+ else if (state >= state_PRERUNNING)
+ atomic_inc(&playbacksubs->state);
} else {
switch (state) {
case state_STARTING1:
if (state == state_RUNNING) {
if ((err = usX2Y_usbpcm_urb_capt_retire(capsubs)))
return err;
- } else {
- if (state >= state_PRERUNNING)
- atomic_inc(&capsubs->state);
- }
+ } else if (state >= state_PRERUNNING)
+ atomic_inc(&capsubs->state);
usX2Y_usbpcm_urb_capt_iso_advance(capsubs, capsubs->completed_urb);
if (NULL != capsubs2)
usX2Y_usbpcm_urb_capt_iso_advance(NULL, capsubs2->completed_urb);
/* allocate and initialize data urbs */
for (i = 0; i < NRURBS; i++) {
- struct urb** purb = subs->urb + i;
+ struct urb **purb = subs->urb + i;
if (*purb) {
usb_kill_urb(*purb);
continue;
{
snd_pcm_runtime_t *runtime = substream->runtime;
snd_usX2Y_substream_t *subs = (snd_usX2Y_substream_t *)runtime->private_data;
- int err = 0;
- snd_printd("\n");
+
subs->pcm_substream = NULL;
- return err;
+ return 0;
}
static int snd_usX2Y_hwdep_pcm_mmap(snd_hwdep_t * hw, struct file *filp, struct vm_area_struct *area)
{
unsigned long size = (unsigned long)(area->vm_end - area->vm_start);
- usX2Ydev_t *usX2Y = (usX2Ydev_t*)hw->private_data;
+ usX2Ydev_t *usX2Y = hw->private_data;
- if (!(((usX2Ydev_t*)hw->private_data)->chip_status & USX2Y_STAT_CHIP_INIT))
+ if (!(usX2Y->chip_status & USX2Y_STAT_CHIP_INIT))
return -EBUSY;
/* if userspace tries to mmap beyond end of our buffer, fail */
}
area->vm_ops = &snd_usX2Y_hwdep_pcm_vm_ops;
area->vm_flags |= VM_RESERVED;
- snd_printd("vm_flags=0x%lX\n", area->vm_flags);
area->vm_private_data = hw->private_data;
return 0;
}
static void snd_usX2Y_hwdep_pcm_private_free(snd_hwdep_t *hwdep)
{
- usX2Ydev_t *usX2Y = (usX2Ydev_t *)hwdep->private_data;
+ usX2Ydev_t *usX2Y = hwdep->private_data;
if (NULL != usX2Y->hwdep_pcm_shm)
snd_free_pages(usX2Y->hwdep_pcm_shm, sizeof(snd_usX2Y_hwdep_pcm_shm_t));
}
if (1 != nr_of_packs())
return 0;
- if ((err = snd_hwdep_new(card, SND_USX2Y_USBPCM_ID, 1, &hw)) < 0) {
- snd_printd("\n");
+ if ((err = snd_hwdep_new(card, SND_USX2Y_USBPCM_ID, 1, &hw)) < 0)
return err;
- }
+
hw->iface = SNDRV_HWDEP_IFACE_USX2Y_PCM;
hw->private_data = usX2Y(card);
hw->private_free = snd_usX2Y_hwdep_pcm_private_free;