ALSA: usb-audio: Add driver for TASCAM US-144MKII
v6 cover ALSA: usb-audio: Add driver for TASCAM US-144MKII
This is v6 of the patch series to add a new driver for the TASCAM US-144MKII USB audio interface.
Changes in v6:
- Addressed open brace cosmetic standards for scoped_guard() calls.
- Added lost default values for digital in/out kcontrols.
Changes in v5:
- Addressed u64 remainder in Patch 2/7.
- Refactored guard() calls for spinlocks to scoped_guard() for ones that got missed(hopefully all).
Changes in v4:
- Removing leading spaces from #defines as requested.
- Renaming fpoInitPattern to fpo_init_pattern.
- Removing unnecessary kfree() calls.
- Replacing manual lock/unlock patterns with scoped_guard().
Changes in v3
- Corrected v2 invalid patches order
The v2 submission included mix of patches for v2 that were unusable. These new patches are valid now.
Changes in v2:
- Patch 1: Dropped blank line, initialized __free(kfree) variable to NULL, and fixed struct tascam_card indentation.
- Patch 2: Corrected indentation in us144mkii.h.
- Patch 3: Changed fpoInitPattern to fpo_init_pattern (snake_case), initialized __free(kfree) variable, and replaced guard(spinlock_irqsave) with scoped_guard().
- Patch 5: Updated control names to standard "Playback Source" and "Capture Source" formats, and initialized __free(kfree) variable to NULL.
- Patch 6: Re-organized code style alignments into previous patches.
- Patch 7: Fixed trailing whitespace warning.
Šerif Rami (7):
ALSA: usb-audio: Add initial driver for TASCAM US-144MKII
ALSA: usb-audio: us144mkii: Add PCM core infrastructure
ALSA: usb-audio: us144mkii: Implement audio playback and feedback
ALSA: usb-audio: us144mkii: Implement audio capture and decoding
ALSA: usb-audio: us144mkii: Add MIDI support and mixer controls
ALSA: usb-audio: us144mkii: Add deep sleep command
ALSA: usb-audio: Add infrastructure for TASCAM US-144MKII
sound/usb/Kconfig | 12 + sound/usb/usx2y/Makefile | 2 + sound/usb/usx2y/us122l.c | 6 - sound/usb/usx2y/us144mkii.c | 620 +++++++++++++++++++++++++++ sound/usb/usx2y/us144mkii.h | 368 ++++++++++++++++ sound/usb/usx2y/us144mkii_capture.c | 319 ++++++++++++++ sound/usb/usx2y/us144mkii_controls.c | 444 +++++++++++++++++++ sound/usb/usx2y/us144mkii_midi.c | 399 +++++++++++++++++ sound/usb/usx2y/us144mkii_pcm.c | 370 ++++++++++++++++ sound/usb/usx2y/us144mkii_pcm.h | 165 +++++++ sound/usb/usx2y/us144mkii_playback.c | 456 ++++++++++++++++++++ 11 files changed, 3155 insertions(+), 6 deletions(-) create mode 100644 sound/usb/usx2y/us144mkii.c create mode 100644 sound/usb/usx2y/us144mkii.h create mode 100644 sound/usb/usx2y/us144mkii_capture.c create mode 100644 sound/usb/usx2y/us144mkii_controls.c create mode 100644 sound/usb/usx2y/us144mkii_midi.c create mode 100644 sound/usb/usx2y/us144mkii_pcm.c create mode 100644 sound/usb/usx2y/us144mkii_pcm.h create mode 100644 sound/usb/usx2y/us144mkii_playback.c
base-commit: e8e4f3c242cc26de9d69bd8b3a678d1e50980abe
Signature · 1 line
2.39.5
PATCH v6 1/7 ALSA: usb-audio: Add initial driver for TASCAM US-144MKII
This patch introduces a new driver for the TASCAM US-144MKII USB audio/MIDI interface.
It includes the basic driver structure for probing and disconnecting from the USB device. It correctly identifies the device using its VID/PID, performs the necessary initial handshake, and sets the required USB interface alternate settings to prepare the device for operation.
At this point, no ALSA devices (PCM or MIDI) are created. This commit forms the foundational skeleton upon which audio and MIDI functionality will be built.
--- sound/usb/usx2y/us144mkii.c | 250 ++++++++++++++++++++++++++++++++++++ sound/usb/usx2y/us144mkii.h | 38 ++++++ 2 files changed, 288 insertions(+) create mode 100644 sound/usb/usx2y/us144mkii.c create mode 100644 sound/usb/usx2y/us144mkii.h
sound/usb/usx2y/us144mkii.c new file +250 -0
@@ -0,0 +1,250 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (c) 2025 Šerif Rami <[email protected]> +/* +* ALSA Driver for TASCAM US-144MKII Audio Interface +*/ + +#include "us144mkii.h" + +MODULE_AUTHOR ("Šerif Rami <[email protected]>" ); +MODULE_DESCRIPTION ("ALSA Driver for TASCAM US-144MKII" ); +MODULE_LICENSE ("GPL" ); + +/** +* @brief Module parameters for ALSA card instantiation. +* +* These parameters allow users to configure how the ALSA sound card +* for the TASCAM US-144MKII is instantiated. +* +* @param index: Array of integers specifying the ALSA card index for each +* device. Defaults to -1 (automatic). +* @param id: Array of strings specifying the ALSA card ID for each device. +* Defaults to "US144MKII". +* @param enable: Array of booleans to enable or disable each device. +* Defaults to {1, 0, ..., 0} (first device enabled). +* @param dev_idx: Internal counter for probed TASCAM devices. +*/ +static int index[SNDRV_CARDS ] =SNDRV_DEFAULT_IDX ; +static char *id[SNDRV_CARDS ] =SNDRV_DEFAULT_STR ; +static bool enable[SNDRV_CARDS ] = {1 , [1 ...(SNDRV_CARDS -1 )] =0 }; +static int dev_idx; + +static int tascam_probe (struct usb_interface *intf, +const struct usb_device_id *usb_id); +static void tascam_disconnect (struct usb_interface *intf); +static int tascam_suspend (struct usb_interface *intf,pm_message_t message); +static int tascam_resume (struct usb_interface *intf); + +/** +* tascam_card_private_free() - Frees private data for the sound card. +* card. +* @card: Pointer to the ALSA sound card instance. +* +* This function is called when the sound card is being freed. It releases +* the reference to the USB device. +*/ +static void tascam_card_private_free (struct snd_card *card) +{ +struct tascam_card *tascam = card->private_data; + +if (tascam && tascam->dev) { +usb_put_dev (tascam->dev); + tascam->dev =NULL ; + } +} + +/** +* tascam_probe() - Probes for the TASCAM US-144MKII device. +* @intf: The USB interface being probed. +* @usb_id: The USB device ID. +* +* This function is the entry point for the USB driver on device match. +* is found. It performs initial device setup, including: +* - Checking for the second interface (MIDI) and associating it. +* - Performing a vendor-specific handshake with the device. +* - Setting alternate settings for USB interfaces. +* - Creating and registering the ALSA sound card. +* +* Return: 0 on success, or a negative error code on failure. +*/ +static int tascam_probe (struct usb_interface *intf, +const struct usb_device_id *usb_id) +{ +struct usb_device *dev =interface_to_usbdev (intf); +struct snd_card *card; +struct tascam_card *tascam; +int err; + char *handshake_buf __free(kfree) = NULL; + +if (dev->speed !=USB_SPEED_HIGH ) +dev_info ( + &dev->dev, +"Device is connected to a USB 1.1 port, this is not supported.\n" ); + +/* The device has two interfaces; we drive both from this driver. */ +if (intf->cur_altsetting->desc.bInterfaceNumber ==1 ) { + tascam =usb_get_intfdata (usb_ifnum_to_if (dev,0 )); +if (tascam) { +usb_set_intfdata (intf, tascam); + tascam->iface1 = intf; + } +return 0 ;/* Let the core handle this interface */ + } + +if (dev_idx >=SNDRV_CARDS ) { +dev_err (&dev->dev,"Too many TASCAM devices present" ); +return -ENODEV ; + } + +if (!enable[dev_idx]) { +dev_info (&dev->dev,"TASCAM US-144MKII device disabled" ); +return -ENOENT ; + } + + handshake_buf =kmalloc (1 ,GFP_KERNEL ); +if (!handshake_buf) +return -ENOMEM ; + +/* Perform vendor-specific handshake */ + err =usb_control_msg (dev,usb_rcvctrlpipe (dev,0 ), +VENDOR_REQ_MODE_CONTROL ,RT_D2H_VENDOR_DEV , +MODE_VAL_HANDSHAKE_READ ,0x0000 , handshake_buf,1 , +USB_CTRL_TIMEOUT_MS ); +if (err <0 ) { +dev_err (&dev->dev,"Handshake read failed with %d\n" , err); +return err; + } + +if (handshake_buf[0 ] !=0x12 && handshake_buf[0 ] !=0x16 && + handshake_buf[0 ] !=0x30 ) { +dev_err (&dev->dev,"Unexpected handshake value: 0x%x\n" , + handshake_buf[0 ]); +return -ENODEV ; + } + +/* Set alternate settings to enable audio/MIDI endpoints */ + err =usb_set_interface (dev,0 ,1 ); +if (err <0 ) { +dev_err (&dev->dev, +"Failed to set alt setting 1 on interface 0: %d\n" , + err); +return err; + } + + err =usb_set_interface (dev,1 ,1 ); +if (err <0 ) { +dev_err (&dev->dev, +"Failed to set alt setting 1 on interface 1: %d\n" , + err); +return err; + } + + err =snd_card_new (&dev->dev, index[dev_idx], id[dev_idx],THIS_MODULE , +sizeof (struct tascam_card ), &card); +if (err <0 ) { +dev_err (&dev->dev,"Failed to create sound card instance\n" ); +return err; + } + + tascam = card->private_data; + card->private_free = tascam_card_private_free; + tascam->dev =usb_get_dev (dev); + tascam->card = card; + tascam->iface0 = intf; + tascam->digital_out_source =1 ; + tascam->capture_34_source =1 ; + +strscpy (card->driver,DRIVER_NAME ,sizeof (card->driver)); +if (dev->descriptor.idProduct ==USB_PID_TASCAM_US144 ) { +strscpy (card->shortname,"TASCAM US-144" , +sizeof (card->shortname)); + }else if (dev->descriptor.idProduct ==USB_PID_TASCAM_US144MKII ) { +strscpy (card->shortname,"TASCAM US-144MKII" , +sizeof (card->shortname)); + }else { +strscpy (card->shortname,"TASCAM Unknown" , +sizeof (card->shortname)); + } +snprintf (card->longname,sizeof (card->longname),"%s (%04x:%04x) at %s" , + card->shortname,USB_VID_TASCAM , dev->descriptor.idProduct, +dev_name (&dev->dev)); + + err =snd_card_register (card); +if (err <0 ) + goto free_card; + +usb_set_intfdata (intf, tascam); + + dev_idx++; +return 0 ; + +free_card: +snd_card_free (card); +return err; +} + +/** +* tascam_disconnect() - Disconnects the TASCAM US-144MKII device. +* @intf: The USB interface being disconnected. +* +* This function is called when the device is disconnected from the system. +* It cleans up all allocated resources by freeing the sound card. +*/ +static void tascam_disconnect (struct usb_interface *intf) +{ +struct tascam_card *tascam =usb_get_intfdata (intf); + +if (!tascam) +return ; + +if (intf->cur_altsetting->desc.bInterfaceNumber ==0 ) { +snd_card_disconnect (tascam->card); +snd_card_free (tascam->card); + dev_idx--; + } +} + +/** +* tascam_suspend() - Handles device suspension. +* @intf: The USB interface being suspended. +* @message: Power management message. +* +* This function is a stub for handling device suspension. +* +* Return: 0 on success. +*/ +static int tascam_suspend (struct usb_interface *intf,pm_message_t message) +{ +return 0 ; +} + +/** +* tascam_resume() - Handles device resumption from suspend. +* @intf: The USB interface being resumed. +* +* This function is a stub for handling device resumption. +* +* Return: 0 on success. +*/ +static int tascam_resume (struct usb_interface *intf) +{ +return 0 ; +} + +static const struct usb_device_id tascam_usb_ids[] = { + {USB_DEVICE (USB_VID_TASCAM ,USB_PID_TASCAM_US144 ) }, + {USB_DEVICE (USB_VID_TASCAM ,USB_PID_TASCAM_US144MKII ) }, + {/* Terminating entry */ } +}; +MODULE_DEVICE_TABLE (usb, tascam_usb_ids); + +static struct usb_driver tascam_alsa_driver = { + .name =DRIVER_NAME , + .probe = tascam_probe, + .disconnect = tascam_disconnect, + .suspend = tascam_suspend, + .resume = tascam_resume, + .id_table = tascam_usb_ids, +}; + +module_usb_driver (tascam_alsa_driver);
sound/usb/usx2y/us144mkii.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +// Copyright (c) 2025 Šerif Rami <[email protected]> + +#ifndef __US144MKII_H +#define __US144MKII_H + +#include <linux/usb.h> +#include <sound/core.h> +#include <sound/initval.h> + +#define DRIVER_NAME "us144mkii" + +/* --- USB Device Identification --- */ +#define USB_VID_TASCAM 0x0644 +#define USB_PID_TASCAM_US144 0x800f +#define USB_PID_TASCAM_US144MKII 0x8020 + +/* --- USB Control Message Protocol --- */ +#define RT_D2H_VENDOR_DEV (USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_DEVICE) +#define VENDOR_REQ_MODE_CONTROL 0x49 +#define MODE_VAL_HANDSHAKE_READ 0x0000 +#define USB_CTRL_TIMEOUT_MS 1000 + +/** +* struct tascam_card - Driver data structure for TASCAM US-144MKII. +* @dev: Pointer to the USB device. +* @iface0: Pointer to USB interface 0 (audio). +* @iface1: Pointer to USB interface 1 (MIDI). +* @card: Pointer to the ALSA sound card instance. +*/ +struct tascam_card { +struct usb_device *dev; +struct usb_interface *iface0; +struct usb_interface *iface1; +struct snd_card *card; +}; + +#endif /* __US144MKII_H */
Signature · 1 line
2.39.5
Re: [PATCH v6 1/7] ALSA: usb-audio: Add initial driver for TASCAM US-144MKII
Quoted 1 line
This patch introduces …
…
Quoted 2 lines
+++
b/sound/usb/usx2y/us144mkii.c(quoted diff) +0
-0@@ -0,0 +1,248 @@
…
Quoted 3 lines
sound/usb/usx2y/us144mkii.c new file +3
-0+static int tascam_probe (struct usb_interface *intf, +const struct usb_device_id *usb_id) +{
…
Quoted 3 lines
sound/usb/usx2y/us144mkii.c new file +3
-0+ char *handshake_buf __free(kfree) = NULL; + +if (dev->speed !=USB_SPEED_HIGH )
…
sound/usb/usx2y/us144mkii.c line 104
Quoted 1 line
sound/usb/usx2y/us144mkii.c new file +1
-0+ handshake_buf =kmalloc (1 ,GFP_KERNEL );
…
Can another software design option become more attractive? May the scope be reduced for such a variable?
Regards,
Markus
PATCH v6 2/7 ALSA: usb-audio: us144mkii: Add PCM core infrastructure
In reply to Šerif RamiThis patch adds the ALSA PCM device infrastructure. It creates a new PCM device with one playback and one capture stream.
The hardware capabilities (formats, rates, channels) are defined in tascam_pcm_hw. The core PCM operations (snd_pcm_ops) for both playback and capture are implemented, including open, close, hw_params, prepare, and pointer callbacks.
The trigger callback is a stub for now. This commit allows user-space applications to interact with the ALSA device, but no audio will be streamed yet.
--- sound/usb/usx2y/us144mkii.c | 20 ++++- sound/usb/usx2y/us144mkii.h | 46 +++++++++++- sound/usb/usx2y/us144mkii_capture.c | 107 +++++++++++++++++++++++++++ sound/usb/usx2y/us144mkii_pcm.c | 78 +++++++++++++++++++ sound/usb/usx2y/us144mkii_pcm.h | 76 +++++++++++++++++++ sound/usb/usx2y/us144mkii_playback.c | 107 +++++++++++++++++++++++++++ 6 files changed, 428 insertions(+), 6 deletions(-) create mode 100644 sound/usb/usx2y/us144mkii_capture.c create mode 100644 sound/usb/usx2y/us144mkii_pcm.c create mode 100644 sound/usb/usx2y/us144mkii_pcm.h create mode 100644 sound/usb/usx2y/us144mkii_playback.c
sound/usb/usx2y/us144mkii.c +16 -4
@@ -22,7 +22,7 @@ MODULE_LICENSE("GPL");* Defaults to "US144MKII". * @param enable: Array of booleans to enable or disable each device. * Defaults to {1, 0, ..., 0} (first device enabled). -* @param dev_idx: Internal counter for probed TASCAM devices. +* @param dev_idx: Internal counter for the number of TASCAM devices probed. */ static int index[SNDRV_CARDS ] =SNDRV_DEFAULT_IDX ;static char *id[SNDRV_CARDS ] =SNDRV_DEFAULT_STR ;
@@ -36,7 +36,7 @@ static int tascam_suspend(struct usb_interface *intf, pm_message_t message);static int tascam_resume (struct usb_interface *intf);/** -* tascam_card_private_free() - Frees private data for the sound card. +* tascam_card_private_free() - Frees private data associated with the sound * card. * @card: Pointer to the ALSA sound card instance. *
@@ -58,12 +58,12 @@ static void tascam_card_private_free(struct snd_card *card)* @intf: The USB interface being probed. * @usb_id: The USB device ID. * -* This function is the entry point for the USB driver on device match. +* This function is the entry point for the USB driver when a matching device * is found. It performs initial device setup, including: * - Checking for the second interface (MIDI) and associating it. * - Performing a vendor-specific handshake with the device. * - Setting alternate settings for USB interfaces. -* - Creating and registering the ALSA sound card. +* - Creating and registering the ALSA sound card and PCM device. * * Return: 0 on success, or a negative error code on failure. */
@@ -154,6 +154,18 @@ static int tascam_probe(struct usb_interface *intf, tascam->digital_out_source =1 ; tascam->capture_34_source =1 ; +spin_lock_init (&tascam->lock); + + err =snd_pcm_new (card,"US144MKII PCM" ,0 ,1 ,1 , &tascam->pcm); +if (err <0 ) + goto free_card; + tascam->pcm->private_data = tascam; +strscpy (tascam->pcm->name,"US144MKII PCM" ,sizeof (tascam->pcm->name)); + + err =tascam_init_pcm (tascam->pcm); +if (err <0 ) + goto free_card; +strscpy (card->driver,DRIVER_NAME ,sizeof (card->driver));if (dev->descriptor.idProduct ==USB_PID_TASCAM_US144 ) { strscpy(card->shortname, "TASCAM US-144",
sound/usb/usx2y/us144mkii.h +44 -2
62 lines not on this page · raw message
sound/usb/usx2y/us144mkii_capture.c new file +107 -0
107 lines not on this page · raw message
sound/usb/usx2y/us144mkii_pcm.c new file +78 -0
78 lines not on this page · raw message
sound/usb/usx2y/us144mkii_pcm.h new file +76 -0
76 lines not on this page · raw message
sound/usb/usx2y/us144mkii_playback.c new file +107 -0
107 lines not on this page · raw message
Signature · 1 line
2.39.5
PATCH v6 3/7 ALSA: usb-audio: us144mkii: Implement audio playback and feedback
In reply to Šerif RamiThis patch implements the full audio playback data path. It introduces the allocation, submission, and completion handling for isochronous playback and feedback URBs.
The feedback URB completion handler is the core of the driver's clocking mechanism. It reads the number of samples consumed by the device and uses a pattern-based algorithm to adjust the size of outgoing playback packets. This keeps the host and device synchronized and prevents xruns.
The patch also adds the necessary vendor and UAC control messages to configure the device's sample rate. The PCM trigger is updated to start and stop the playback and feedback URBs. Basic suspend and resume handlers are included to manage stream state across power cycles.
--- sound/usb/usx2y/us144mkii.c | 171 ++++++++++++- sound/usb/usx2y/us144mkii.h | 180 ++++++++++++-- sound/usb/usx2y/us144mkii_capture.c | 1 + sound/usb/usx2y/us144mkii_pcm.c | 223 ++++++++++++++++- sound/usb/usx2y/us144mkii_pcm.h | 64 ++++- sound/usb/usx2y/us144mkii_playback.c | 351 ++++++++++++++++++++++++++- 6 files changed, 963 insertions(+), 27 deletions(-)
sound/usb/usx2y/us144mkii.c +167 -4
@@ -35,6 +35,110 @@ static void tascam_disconnect(struct usb_interface *intf);static int tascam_suspend (struct usb_interface *intf,pm_message_t message);static int tascam_resume (struct usb_interface *intf); +void tascam_free_urbs (struct tascam_card *tascam) +{ +int i; + +usb_kill_anchored_urbs (&tascam->playback_anchor); +for (i =0 ; i <NUM_PLAYBACK_URBS ; i++) { +if (tascam->playback_urbs[i]) { +usb_free_coherent ( + tascam->dev, tascam->playback_urb_alloc_size, + tascam->playback_urbs[i]->transfer_buffer, + tascam->playback_urbs[i]->transfer_dma); +usb_free_urb (tascam->playback_urbs[i]); + tascam->playback_urbs[i] =NULL ; + } + } + +usb_kill_anchored_urbs (&tascam->feedback_anchor); +for (i =0 ; i <NUM_FEEDBACK_URBS ; i++) { +if (tascam->feedback_urbs[i]) { +usb_free_coherent ( + tascam->dev, tascam->feedback_urb_alloc_size, + tascam->feedback_urbs[i]->transfer_buffer, + tascam->feedback_urbs[i]->transfer_dma); +usb_free_urb (tascam->feedback_urbs[i]); + tascam->feedback_urbs[i] =NULL ; + } + } +} + +int tascam_alloc_urbs (struct tascam_card *tascam) +{ +int i; +size_t max_packet_size; + + max_packet_size = ((96000 /8000 ) +2 ) *BYTES_PER_FRAME ; + tascam->playback_urb_alloc_size = + max_packet_size *PLAYBACK_URB_PACKETS ; + +for (i =0 ; i <NUM_PLAYBACK_URBS ; i++) { +struct urb *urb = +usb_alloc_urb (PLAYBACK_URB_PACKETS ,GFP_KERNEL ); + +if (!urb) + goto error; + tascam->playback_urbs[i] = urb; + + urb->transfer_buffer =usb_alloc_coherent ( + tascam->dev, tascam->playback_urb_alloc_size, +GFP_KERNEL , &urb->transfer_dma); +if (!urb->transfer_buffer) + goto error; + + urb->dev = tascam->dev; + urb->pipe =usb_sndisocpipe (tascam->dev,EP_AUDIO_OUT ); + urb->transfer_flags =URB_ISO_ASAP |URB_NO_TRANSFER_DMA_MAP ; + urb->interval =1 ; + urb->context = tascam; + urb->complete = playback_urb_complete; + } + + tascam->feedback_urb_alloc_size = +FEEDBACK_PACKET_SIZE *FEEDBACK_URB_PACKETS ; + +for (i =0 ; i <NUM_FEEDBACK_URBS ; i++) { +struct urb *f_urb = +usb_alloc_urb (FEEDBACK_URB_PACKETS ,GFP_KERNEL ); + +if (!f_urb) + goto error; + tascam->feedback_urbs[i] = f_urb; + + f_urb->transfer_buffer =usb_alloc_coherent ( + tascam->dev, tascam->feedback_urb_alloc_size, +GFP_KERNEL , &f_urb->transfer_dma); +if (!f_urb->transfer_buffer) + goto error; + + f_urb->dev = tascam->dev; + f_urb->pipe = +usb_rcvisocpipe (tascam->dev,EP_PLAYBACK_FEEDBACK ); + f_urb->transfer_flags =URB_ISO_ASAP |URB_NO_TRANSFER_DMA_MAP ; + f_urb->interval =4 ; + f_urb->context = tascam; + f_urb->complete = feedback_urb_complete; + } + +return 0 ; + +error: +dev_err (tascam->card->dev,"Failed to allocate URBs\n" ); +tascam_free_urbs (tascam); +return -ENOMEM ; +} + +void tascam_stop_work_handler (struct work_struct *work) +{ +struct tascam_card *tascam = + container_of(work, struct tascam_card, stop_work); + +usb_kill_anchored_urbs (&tascam->playback_anchor); +usb_kill_anchored_urbs (&tascam->feedback_anchor); +atomic_set (&tascam->active_urbs,0 ); +} +/** * tascam_card_private_free() - Frees private data associated with the sound * card.
@@ -64,6 +168,7 @@ static void tascam_card_private_free(struct snd_card *card)* - Performing a vendor-specific handshake with the device. * - Setting alternate settings for USB interfaces. * - Creating and registering the ALSA sound card and PCM device. +* - Allocating and initializing URBs for audio transfers. * * Return: 0 on success, or a negative error code on failure. */
@@ -155,6 +260,11 @@ static int tascam_probe(struct usb_interface *intf, tascam->capture_34_source =1 ;spin_lock_init (&tascam->lock); +init_usb_anchor (&tascam->playback_anchor); +init_usb_anchor (&tascam->feedback_anchor); + +INIT_WORK (&tascam->stop_work, tascam_stop_work_handler); +INIT_WORK (&tascam->stop_pcm_work, tascam_stop_pcm_work_handler); err =snd_pcm_new (card,"US144MKII PCM" ,0 ,1 ,1 , &tascam->pcm);if (err <0 )
@@ -166,6 +276,10 @@ static int tascam_probe(struct usb_interface *intf,if (err <0 ) goto free_card; + err =tascam_alloc_urbs (tascam); +if (err <0 ) + goto free_card; +strscpy (card->driver,DRIVER_NAME ,sizeof (card->driver));if (dev->descriptor.idProduct ==USB_PID_TASCAM_US144 ) { strscpy(card->shortname, "TASCAM US-144",
@@ -191,6 +305,7 @@ static int tascam_probe(struct usb_interface *intf,return 0 ; free_card: +tascam_free_urbs (tascam);snd_card_free (card);return err; }
@@ -200,7 +315,8 @@ static int tascam_probe(struct usb_interface *intf,* @intf: The USB interface being disconnected. * * This function is called when the device is disconnected from the system. -* It cleans up all allocated resources by freeing the sound card. +* It cleans up all allocated resources by freeing the sound card, which in +* turn triggers freeing of URBs and other resources. */ static void tascam_disconnect (struct usb_interface *intf) {
@@ -211,6 +327,9 @@ static void tascam_disconnect(struct usb_interface *intf)if (intf->cur_altsetting->desc.bInterfaceNumber ==0 ) {snd_card_disconnect (tascam->card); +cancel_work_sync (&tascam->stop_work); +cancel_work_sync (&tascam->stop_pcm_work); +tascam_free_urbs (tascam);snd_card_free (tascam->card); dev_idx--; }
@@ -221,12 +340,25 @@ static void tascam_disconnect(struct usb_interface *intf)* @intf: The USB interface being suspended. * @message: Power management message. * -* This function is a stub for handling device suspension. +* This function is called when the device is suspended. It stops all active +* streams and kills all URBs. * * Return: 0 on success. */ static int tascam_suspend (struct usb_interface *intf,pm_message_t message) { +struct tascam_card *tascam =usb_get_intfdata (intf); + +if (!tascam) +return 0 ; + +snd_pcm_suspend_all (tascam->pcm); + +cancel_work_sync (&tascam->stop_work); +cancel_work_sync (&tascam->stop_pcm_work); +usb_kill_anchored_urbs (&tascam->playback_anchor); +usb_kill_anchored_urbs (&tascam->feedback_anchor); +return 0 ; }
@@ -234,12 +366,43 @@ static int tascam_suspend(struct usb_interface *intf, pm_message_t message)* tascam_resume() - Handles device resumption from suspend. * @intf: The USB interface being resumed. * -* This function is a stub for handling device resumption. +* This function is called when the device resumes from suspend. It +* re-establishes the active USB interface settings and re-configures the sample +* rate if it was previously active. * -* Return: 0 on success. +* Return: 0 on success, or a negative error code on failure. */ static int tascam_resume (struct usb_interface *intf) { +struct tascam_card *tascam =usb_get_intfdata (intf); +int err; + +if (!tascam) +return 0 ; + +dev_info (&intf->dev,"resuming TASCAM US-144MKII\n" ); + +/* Re-establish the active USB interface settings. */ + err =usb_set_interface (tascam->dev,0 ,1 ); +if (err <0 ) { +dev_err (&intf->dev, +"resume: failed to set alt setting on intf 0: %d\n" , + err); +return err; + } + err =usb_set_interface (tascam->dev,1 ,1 ); +if (err <0 ) { +dev_err (&intf->dev, +"resume: failed to set alt setting on intf 1: %d\n" , + err); +return err; + } + +/* Re-configure the sample rate if one was previously active */ +if (tascam->current_rate >0 ) +us144mkii_configure_device_for_rate (tascam, + tascam->current_rate); +return 0 ; }
sound/usb/usx2y/us144mkii.h +162 -18
233 lines not on this page · raw message
sound/usb/usx2y/us144mkii_capture.c +1 -0
@@ -55,6 +55,7 @@ static int tascam_capture_prepare(struct snd_pcm_substream *substream) tascam->driver_capture_pos =0 ; tascam->capture_frames_processed =0 ; + tascam->last_capture_period_pos =0 ;return 0 ; }
sound/usb/usx2y/us144mkii_pcm.c +222 -1
261 lines not on this page · raw message
sound/usb/usx2y/us144mkii_pcm.h +61 -3
88 lines not on this page · raw message
sound/usb/usx2y/us144mkii_playback.c +350 -1
369 lines not on this page · raw message
Signature · 1 line
2.39.5
PATCH v6 4/7 ALSA: usb-audio: us144mkii: Implement audio capture and decoding
In reply to Šerif RamiThis patch adds the full audio capture data path. It allocates and manages bulk URBs to receive audio data from the device.
The incoming data is in a custom multiplexed format. A workqueue is used to offload the decoding process from the interrupt context. The capture_urb_complete handler copies raw data into a ring buffer and schedules the work. The tascam_capture_work_handler then reads from this buffer, decodes the data into standard S32_LE samples, and copies it to the ALSA capture buffer.
The PCM trigger is updated to manage the submission of capture URBs, and the feedback handler now also advances the capture stream pointer to keep it synchronized with playback.
--- sound/usb/usx2y/us144mkii.c | 73 ++++++++++ sound/usb/usx2y/us144mkii.h | 44 +++++- sound/usb/usx2y/us144mkii_capture.c | 213 +++++++++++++++++++++++++++- sound/usb/usx2y/us144mkii_pcm.c | 30 ++++ sound/usb/usx2y/us144mkii_pcm.h | 35 ++++- 5 files changed, 387 insertions(+), 8 deletions(-)
sound/usb/usx2y/us144mkii.c +73 -0
@@ -62,6 +62,27 @@ void tascam_free_urbs(struct tascam_card *tascam) tascam->feedback_urbs[i] =NULL ; } } + +usb_kill_anchored_urbs (&tascam->capture_anchor); +for (i =0 ; i <NUM_CAPTURE_URBS ; i++) { +if (tascam->capture_urbs[i]) { +usb_free_coherent ( + tascam->dev, tascam->capture_urb_alloc_size, + tascam->capture_urbs[i]->transfer_buffer, + tascam->capture_urbs[i]->transfer_dma); +usb_free_urb (tascam->capture_urbs[i]); + tascam->capture_urbs[i] =NULL ; + } + } + +kfree (tascam->capture_routing_buffer); + tascam->capture_routing_buffer =NULL ; +kfree (tascam->capture_decode_dst_block); + tascam->capture_decode_dst_block =NULL ; +kfree (tascam->capture_decode_raw_block); + tascam->capture_decode_raw_block =NULL ; +kfree (tascam->capture_ring_buffer); + tascam->capture_ring_buffer =NULL ; }int tascam_alloc_urbs (struct tascam_card *tascam)
@@ -121,6 +142,52 @@ int tascam_alloc_urbs(struct tascam_card *tascam) f_urb->complete = feedback_urb_complete; } + tascam->capture_urb_alloc_size =CAPTURE_URB_SIZE ; +for (i =0 ; i <NUM_CAPTURE_URBS ; i++) { +struct urb *c_urb =usb_alloc_urb (0 ,GFP_KERNEL ); + +if (!c_urb) + goto error; + tascam->capture_urbs[i] = c_urb; + + c_urb->transfer_buffer =usb_alloc_coherent ( + tascam->dev, tascam->capture_urb_alloc_size,GFP_KERNEL , + &c_urb->transfer_dma); +if (!c_urb->transfer_buffer) + goto error; + +usb_fill_bulk_urb (c_urb, tascam->dev, +usb_rcvbulkpipe (tascam->dev,EP_AUDIO_IN ), + c_urb->transfer_buffer, + tascam->capture_urb_alloc_size, + capture_urb_complete, tascam); + c_urb->transfer_flags |=URB_NO_TRANSFER_DMA_MAP ; + } + + tascam->capture_ring_buffer = +kmalloc (CAPTURE_RING_BUFFER_SIZE ,GFP_KERNEL ); +if (!tascam->capture_ring_buffer) + goto error; + + tascam->capture_decode_raw_block = +kmalloc (RAW_BYTES_PER_DECODE_BLOCK ,GFP_KERNEL ); +if (!tascam->capture_decode_raw_block) + goto error; + + tascam->capture_decode_dst_block = +kmalloc (FRAMES_PER_DECODE_BLOCK *DECODED_CHANNELS_PER_FRAME * +DECODED_SAMPLE_SIZE , +GFP_KERNEL ); +if (!tascam->capture_decode_dst_block) + goto error; + + tascam->capture_routing_buffer = +kmalloc (FRAMES_PER_DECODE_BLOCK *DECODED_CHANNELS_PER_FRAME * +DECODED_SAMPLE_SIZE , +GFP_KERNEL ); +if (!tascam->capture_routing_buffer) + goto error; +return 0 ; error:
@@ -136,6 +203,7 @@ void tascam_stop_work_handler(struct work_struct *work)usb_kill_anchored_urbs (&tascam->playback_anchor);usb_kill_anchored_urbs (&tascam->feedback_anchor); +usb_kill_anchored_urbs (&tascam->capture_anchor);atomic_set (&tascam->active_urbs,0 ); }
@@ -261,10 +329,12 @@ static int tascam_probe(struct usb_interface *intf,spin_lock_init (&tascam->lock);init_usb_anchor (&tascam->playback_anchor); +init_usb_anchor (&tascam->capture_anchor);init_usb_anchor (&tascam->feedback_anchor);INIT_WORK (&tascam->stop_work, tascam_stop_work_handler);INIT_WORK (&tascam->stop_pcm_work, tascam_stop_pcm_work_handler); +INIT_WORK (&tascam->capture_work, tascam_capture_work_handler); err =snd_pcm_new (card,"US144MKII PCM" ,0 ,1 ,1 , &tascam->pcm);if (err <0 )
@@ -328,6 +398,7 @@ static void tascam_disconnect(struct usb_interface *intf)if (intf->cur_altsetting->desc.bInterfaceNumber ==0 ) {snd_card_disconnect (tascam->card);cancel_work_sync (&tascam->stop_work); +cancel_work_sync (&tascam->capture_work);cancel_work_sync (&tascam->stop_pcm_work);tascam_free_urbs (tascam);snd_card_free (tascam->card);
@@ -355,8 +426,10 @@ static int tascam_suspend(struct usb_interface *intf, pm_message_t message)snd_pcm_suspend_all (tascam->pcm);cancel_work_sync (&tascam->stop_work); +cancel_work_sync (&tascam->capture_work);cancel_work_sync (&tascam->stop_pcm_work);usb_kill_anchored_urbs (&tascam->playback_anchor); +usb_kill_anchored_urbs (&tascam->capture_anchor);usb_kill_anchored_urbs (&tascam->feedback_anchor);return 0 ;
sound/usb/usx2y/us144mkii.h +39 -5
123 lines not on this page · raw message
sound/usb/usx2y/us144mkii_capture.c +212 -1
228 lines not on this page · raw message
sound/usb/usx2y/us144mkii_pcm.c +30 -0
@@ -61,6 +61,16 @@ void process_playback_routing_us144mkii(struct tascam_card *tascam,memcpy (dst_buffer, src_buffer, frames *BYTES_PER_FRAME ); } +void process_capture_routing_us144mkii (struct tascam_card *tascam, +const s32 *decoded_block, +s32 *routed_block) +{ +/* This is a stub. Routing will be added in a later commit. */ +memcpy (routed_block, decoded_block, +FRAMES_PER_DECODE_BLOCK *DECODED_CHANNELS_PER_FRAME * +DECODED_SAMPLE_SIZE ); +} +int us144mkii_configure_device_for_rate (struct tascam_card *tascam,int rate) {struct usb_device *dev = tascam->dev;
@@ -109,6 +119,12 @@ int us144mkii_configure_device_for_rate(struct tascam_card *tascam, int rate) USB_CTRL_TIMEOUT_MS);if (err <0 ) goto fail; + err =usb_control_msg (dev,usb_sndctrlpipe (dev,0 ),UAC_SET_CUR , +RT_H2D_CLASS_EP ,UAC_SAMPLING_FREQ_CONTROL , +EP_AUDIO_IN , rate_payload_buf,3 , +USB_CTRL_TIMEOUT_MS ); +if (err <0 ) + goto fail; err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR, RT_H2D_CLASS_EP, UAC_SAMPLING_FREQ_CONTROL, EP_AUDIO_OUT, rate_payload_buf, 3,
@@ -270,6 +286,20 @@ int tascam_pcm_trigger(struct snd_pcm_substream *substream, int cmd) }atomic_inc (&tascam->active_urbs); } +for (i =0 ; i <NUM_CAPTURE_URBS ; i++) { +usb_get_urb (tascam->capture_urbs[i]); +usb_anchor_urb (tascam->capture_urbs[i], + &tascam->capture_anchor); + err =usb_submit_urb (tascam->capture_urbs[i], +GFP_ATOMIC ); +if (err <0 ) { +usb_unanchor_urb (tascam->capture_urbs[i]); +usb_put_urb (tascam->capture_urbs[i]); +atomic_dec (&tascam->active_urbs); + goto start_rollback; + } +atomic_inc (&tascam->active_urbs); + }return 0 ; start_rollback:
sound/usb/usx2y/us144mkii_pcm.h +33 -2
@@ -51,6 +51,16 @@ void playback_urb_complete(struct urb *urb);*/ void feedback_urb_complete (struct urb *urb); +/** +* capture_urb_complete() - Completion handler for capture bulk URBs. +* @urb: the completed URB +* +* This function runs in interrupt context. It copies the received raw data +* into an intermediate ring buffer and then schedules the workqueue to process +* it. It then resubmits the URB to receive more data. +*/ +void capture_urb_complete (struct urb *urb); +/** * tascam_stop_pcm_work_handler() - Work handler to stop PCM streams. * @work: Pointer to the work_struct.
@@ -64,8 +74,8 @@ void tascam_stop_pcm_work_handler(struct work_struct *work);* tascam_init_pcm() - Initializes the ALSA PCM device. * @pcm: Pointer to the ALSA PCM device to initialize. * -* This function sets up the PCM operations and preallocates pages for the -* PCM buffer. +* This function sets up the PCM operations, adds ALSA controls for routing +* and sample rate, and preallocates pages for the PCM buffer. * * Return: 0 on success, or a negative error code on failure. */
@@ -94,6 +104,16 @@ void process_playback_routing_us144mkii(struct tascam_card *tascam, const u8 *src_buffer, u8 *dst_buffer, size_t frames); +/** +* process_capture_routing_us144mkii() - Apply capture routing matrix +* @tascam: The driver instance. +* @decoded_block: Buffer containing 4 channels of S32LE decoded audio. +* @routed_block: Buffer to be filled for ALSA. +*/ +void process_capture_routing_us144mkii (struct tascam_card *tascam, +const s32 *decoded_block, +s32 *routed_block); +/** * tascam_pcm_hw_params() - Configures hardware parameters for PCM streams. * @substream: The ALSA PCM substream.
@@ -131,4 +151,15 @@ int tascam_pcm_hw_free(struct snd_pcm_substream *substream);*/ int tascam_pcm_trigger (struct snd_pcm_substream *substream,int cmd); +/** +* tascam_capture_work_handler() - Deferred work for processing capture data. +* @work: the work_struct instance +* +* This function runs in a kernel thread context, not an IRQ context. It reads +* raw data from the capture ring buffer, decodes it, applies routing, and +* copies the final audio data into the ALSA capture ring buffer. This offloads +* the CPU-intensive decoding from the time-sensitive URB completion handlers. +*/ +void tascam_capture_work_handler (struct work_struct *work); +#endif /* __US144MKII_PCM_H */
Signature · 1 line
2.39.5
PATCH v6 5/7 ALSA: usb-audio: us144mkii: Add MIDI support and mixer controls
In reply to Šerif RamiThis patch adds the remaining features to the driver: MIDI I/O and ALSA mixer controls.
A raw MIDI device is created, supporting one input and one output port. The implementation handles the device-specific 9-byte packet format for both sending and receiving MIDI data, using bulk URBs and workqueues for processing.
ALSA kcontrols are added to the mixer interface, allowing user-space control over the audio routing matrix (e.g., selecting analog/digital sources for capture channels, and routing playback streams to different outputs). A read-only control to display the current sample rate is also included.
Finally, the stub routing functions are replaced with the full logic to apply the user-selected mixer settings to the audio streams.
With this commit, the driver is feature-complete.
--- sound/usb/usx2y/us144mkii.c | 303 ++++++++++++------ sound/usb/usx2y/us144mkii.h | 127 +++++++- sound/usb/usx2y/us144mkii_controls.c | 444 +++++++++++++++++++++++++++ sound/usb/usx2y/us144mkii_midi.c | 399 ++++++++++++++++++++++++ sound/usb/usx2y/us144mkii_pcm.c | 55 +++- 5 files changed, 1218 insertions(+), 110 deletions(-) create mode 100644 sound/usb/usx2y/us144mkii_controls.c create mode 100644 sound/usb/usx2y/us144mkii_midi.c
sound/usb/usx2y/us144mkii.c +209 -94
@@ -75,6 +75,30 @@ void tascam_free_urbs(struct tascam_card *tascam) } } +usb_kill_anchored_urbs (&tascam->midi_in_anchor); +for (i =0 ; i <NUM_MIDI_IN_URBS ; i++) { +if (tascam->midi_in_urbs[i]) { +usb_free_coherent ( + tascam->dev,MIDI_IN_BUF_SIZE , + tascam->midi_in_urbs[i]->transfer_buffer, + tascam->midi_in_urbs[i]->transfer_dma); +usb_free_urb (tascam->midi_in_urbs[i]); + tascam->midi_in_urbs[i] =NULL ; + } + } + +usb_kill_anchored_urbs (&tascam->midi_out_anchor); +for (i =0 ; i <NUM_MIDI_OUT_URBS ; i++) { +if (tascam->midi_out_urbs[i]) { +usb_free_coherent ( + tascam->dev,MIDI_OUT_BUF_SIZE , + tascam->midi_out_urbs[i]->transfer_buffer, + tascam->midi_out_urbs[i]->transfer_dma); +usb_free_urb (tascam->midi_out_urbs[i]); + tascam->midi_out_urbs[i] =NULL ; + } + } +kfree (tascam->capture_routing_buffer); tascam->capture_routing_buffer =NULL ;kfree (tascam->capture_decode_dst_block);
@@ -164,6 +188,44 @@ int tascam_alloc_urbs(struct tascam_card *tascam) c_urb->transfer_flags |=URB_NO_TRANSFER_DMA_MAP ; } +/* MIDI URB and buffer allocation */ +for (i =0 ; i <NUM_MIDI_IN_URBS ; i++) { +struct urb *m_urb =usb_alloc_urb (0 ,GFP_KERNEL ); + +if (!m_urb) + goto error; + tascam->midi_in_urbs[i] = m_urb; + m_urb->transfer_buffer = +usb_alloc_coherent (tascam->dev,MIDI_IN_BUF_SIZE , +GFP_KERNEL , &m_urb->transfer_dma); +if (!m_urb->transfer_buffer) + goto error; +usb_fill_bulk_urb (m_urb, tascam->dev, +usb_rcvbulkpipe (tascam->dev,EP_MIDI_IN ), + m_urb->transfer_buffer,MIDI_IN_BUF_SIZE , + tascam_midi_in_urb_complete, tascam); + m_urb->transfer_flags |=URB_NO_TRANSFER_DMA_MAP ; + } + +for (i =0 ; i <NUM_MIDI_OUT_URBS ; i++) { +struct urb *m_urb =usb_alloc_urb (0 ,GFP_KERNEL ); + +if (!m_urb) + goto error; + tascam->midi_out_urbs[i] = m_urb; + m_urb->transfer_buffer = +usb_alloc_coherent (tascam->dev,MIDI_OUT_BUF_SIZE , +GFP_KERNEL , &m_urb->transfer_dma); +if (!m_urb->transfer_buffer) + goto error; +usb_fill_bulk_urb (m_urb, tascam->dev, +usb_sndbulkpipe (tascam->dev,EP_MIDI_OUT ), + m_urb->transfer_buffer, +0 ,/* length set later */ + tascam_midi_out_urb_complete, tascam); + m_urb->transfer_flags |=URB_NO_TRANSFER_DMA_MAP ; + } + tascam->capture_ring_buffer =kmalloc (CAPTURE_RING_BUFFER_SIZE ,GFP_KERNEL );if (!tascam->capture_ring_buffer)
@@ -213,16 +275,112 @@ void tascam_stop_work_handler(struct work_struct *work)* @card: Pointer to the ALSA sound card instance. * * This function is called when the sound card is being freed. It releases -* the reference to the USB device. +* resources allocated for the tascam_card structure, including the MIDI +* input FIFO and decrements the USB device reference count. */ static void tascam_card_private_free (struct snd_card *card) {struct tascam_card *tascam = card->private_data; -if (tascam && tascam->dev) { -usb_put_dev (tascam->dev); - tascam->dev =NULL ; +if (tascam) { +kfifo_free (&tascam->midi_in_fifo); +if (tascam->dev) { +usb_put_dev (tascam->dev); + tascam->dev =NULL ; + } + } +} + +/** +* tascam_suspend() - Handles device suspension. +* @intf: The USB interface being suspended. +* @message: Power management message. +* +* This function is called when the device is suspended. It stops all active +* streams, kills all URBs, and sends a vendor-specific deep sleep command +* to the device to ensure a stable low-power state. +* +* Return: 0 on success. +*/ +static int tascam_suspend (struct usb_interface *intf,pm_message_t message) +{ +struct tascam_card *tascam =usb_get_intfdata (intf); + +if (!tascam) +return 0 ; + +snd_pcm_suspend_all (tascam->pcm); + +cancel_work_sync (&tascam->stop_work); +cancel_work_sync (&tascam->capture_work); +cancel_work_sync (&tascam->midi_in_work); +cancel_work_sync (&tascam->midi_out_work); +cancel_work_sync (&tascam->stop_pcm_work); +usb_kill_anchored_urbs (&tascam->playback_anchor); +usb_kill_anchored_urbs (&tascam->capture_anchor); +usb_kill_anchored_urbs (&tascam->feedback_anchor); +usb_kill_anchored_urbs (&tascam->midi_in_anchor); +usb_kill_anchored_urbs (&tascam->midi_out_anchor); + +return 0 ; +} + +/** +* tascam_resume() - Handles device resumption from suspend. +* @intf: The USB interface being resumed. +* +* This function is called when the device resumes from suspend. It +* re-establishes the active USB interface settings and re-configures the sample +* rate if it was previously active. +* +* Return: 0 on success, or a negative error code on failure. +*/ +static int tascam_resume (struct usb_interface *intf) +{ +struct tascam_card *tascam =usb_get_intfdata (intf); +int err; + +if (!tascam) +return 0 ; + +dev_info (&intf->dev,"resuming TASCAM US-144MKII\n" ); + +/* +* The device requires a full re-initialization sequence upon resume. +* First, re-establish the active USB interface settings. +*/ + err =usb_set_interface (tascam->dev,0 ,1 ); +if (err <0 ) { +dev_err (&intf->dev, +"resume: failed to set alt setting on intf 0: %d\n" , + err); +return err; } + err =usb_set_interface (tascam->dev,1 ,1 ); +if (err <0 ) { +dev_err (&intf->dev, +"resume: failed to set alt setting on intf 1: %d\n" , + err); +return err; + } + +/* Re-configure the sample rate if one was previously active */ +if (tascam->current_rate >0 ) +us144mkii_configure_device_for_rate (tascam, + tascam->current_rate); + +return 0 ; +} + +static void tascam_error_timer (struct timer_list *t) +{ +struct tascam_card *tascam = + container_of(t, struct tascam_card, error_timer); + +if (atomic_read (&tascam->midi_in_active)) +schedule_work (&tascam->midi_in_work); +if (atomic_read (&tascam->midi_out_active)) +schedule_work (&tascam->midi_out_work); }/**
@@ -235,8 +393,8 @@ static void tascam_card_private_free(struct snd_card *card)* - Checking for the second interface (MIDI) and associating it. * - Performing a vendor-specific handshake with the device. * - Setting alternate settings for USB interfaces. -* - Creating and registering the ALSA sound card and PCM device. -* - Allocating and initializing URBs for audio transfers. +* - Creating and registering the ALSA sound card, PCM device, and MIDI device. +* - Allocating and initializing URBs for audio and MIDI transfers. * * Return: 0 on success, or a negative error code on failure. */
@@ -328,27 +486,25 @@ static int tascam_probe(struct usb_interface *intf, tascam->capture_34_source =1 ;spin_lock_init (&tascam->lock); +spin_lock_init (&tascam->midi_in_lock); +spin_lock_init (&tascam->midi_out_lock);init_usb_anchor (&tascam->playback_anchor);init_usb_anchor (&tascam->capture_anchor);init_usb_anchor (&tascam->feedback_anchor); +init_usb_anchor (&tascam->midi_in_anchor); +init_usb_anchor (&tascam->midi_out_anchor); + +timer_setup (&tascam->error_timer, tascam_error_timer,0 );INIT_WORK (&tascam->stop_work, tascam_stop_work_handler);INIT_WORK (&tascam->stop_pcm_work, tascam_stop_pcm_work_handler);INIT_WORK (&tascam->capture_work, tascam_capture_work_handler); +init_completion (&tascam->midi_out_drain_completion); - err =snd_pcm_new (card,"US144MKII PCM" ,0 ,1 ,1 , &tascam->pcm); -if (err <0 ) - goto free_card; - tascam->pcm->private_data = tascam; -strscpy (tascam->pcm->name,"US144MKII PCM" ,sizeof (tascam->pcm->name)); - - err =tascam_init_pcm (tascam->pcm); -if (err <0 ) - goto free_card; - - err =tascam_alloc_urbs (tascam); -if (err <0 ) - goto free_card; +if (kfifo_alloc (&tascam->midi_in_fifo,MIDI_IN_FIFO_SIZE ,GFP_KERNEL )) { +snd_card_free (card); +return -ENOMEM ; + }strscpy (card->driver,DRIVER_NAME ,sizeof (card->driver));if (dev->descriptor.idProduct ==USB_PID_TASCAM_US144 ) {
@@ -365,6 +521,28 @@ static int tascam_probe(struct usb_interface *intf, card->shortname,USB_VID_TASCAM , dev->descriptor.idProduct, dev_name(&dev->dev)); + err =snd_pcm_new (card,"US144MKII PCM" ,0 ,1 ,1 , &tascam->pcm); +if (err <0 ) + goto free_card; + tascam->pcm->private_data = tascam; +strscpy (tascam->pcm->name,"US144MKII PCM" ,sizeof (tascam->pcm->name)); + + err =tascam_init_pcm (tascam->pcm); +if (err <0 ) + goto free_card; + + err =tascam_create_midi (tascam); +if (err <0 ) + goto free_card; + + err =tascam_create_controls (tascam); +if (err <0 ) + goto free_card; + + err =tascam_alloc_urbs (tascam); +if (err <0 ) + goto free_card; + err =snd_card_register (card);if (err <0 ) goto free_card;
@@ -385,8 +563,8 @@ static int tascam_probe(struct usb_interface *intf,* @intf: The USB interface being disconnected. * * This function is called when the device is disconnected from the system. -* It cleans up all allocated resources by freeing the sound card, which in -* turn triggers freeing of URBs and other resources. +* It cleans up all allocated resources, including killing URBs, freeing +* the sound card, and releasing memory. */ static void tascam_disconnect (struct usb_interface *intf) {
@@ -396,89 +574,26 @@ static void tascam_disconnect(struct usb_interface *intf)return ;if (intf->cur_altsetting->desc.bInterfaceNumber ==0 ) { +/* Ensure all deferred work is complete before freeing resources */ snd_card_disconnect (tascam->card);cancel_work_sync (&tascam->stop_work);cancel_work_sync (&tascam->capture_work); +cancel_work_sync (&tascam->midi_in_work); +cancel_work_sync (&tascam->midi_out_work);cancel_work_sync (&tascam->stop_pcm_work); + +usb_kill_anchored_urbs (&tascam->playback_anchor); +usb_kill_anchored_urbs (&tascam->capture_anchor); +usb_kill_anchored_urbs (&tascam->feedback_anchor); +usb_kill_anchored_urbs (&tascam->midi_in_anchor); +usb_kill_anchored_urbs (&tascam->midi_out_anchor); +timer_delete_sync (&tascam->error_timer);tascam_free_urbs (tascam);snd_card_free (tascam->card); dev_idx--; } } -/** -* tascam_suspend() - Handles device suspension. -* @intf: The USB interface being suspended. -* @message: Power management message. -* -* This function is called when the device is suspended. It stops all active -* streams and kills all URBs. -* -* Return: 0 on success. -*/ -static int tascam_suspend (struct usb_interface *intf,pm_message_t message) -{ -struct tascam_card *tascam =usb_get_intfdata (intf); - -if (!tascam) -return 0 ; - -snd_pcm_suspend_all (tascam->pcm); - -cancel_work_sync (&tascam->stop_work); -cancel_work_sync (&tascam->capture_work); -cancel_work_sync (&tascam->stop_pcm_work); -usb_kill_anchored_urbs (&tascam->playback_anchor); -usb_kill_anchored_urbs (&tascam->capture_anchor); -usb_kill_anchored_urbs (&tascam->feedback_anchor); - -return 0 ; -} - -/** -* tascam_resume() - Handles device resumption from suspend. -* @intf: The USB interface being resumed. -* -* This function is called when the device resumes from suspend. It -* re-establishes the active USB interface settings and re-configures the sample -* rate if it was previously active. -* -* Return: 0 on success, or a negative error code on failure. -*/ -static int tascam_resume (struct usb_interface *intf) -{ -struct tascam_card *tascam =usb_get_intfdata (intf); -int err; - -if (!tascam) -return 0 ; - -dev_info (&intf->dev,"resuming TASCAM US-144MKII\n" ); - -/* Re-establish the active USB interface settings. */ - err =usb_set_interface (tascam->dev,0 ,1 ); -if (err <0 ) { -dev_err (&intf->dev, -"resume: failed to set alt setting on intf 0: %d\n" , - err); -return err; - } - err =usb_set_interface (tascam->dev,1 ,1 ); -if (err <0 ) { -dev_err (&intf->dev, -"resume: failed to set alt setting on intf 1: %d\n" , - err); -return err; - } - -/* Re-configure the sample rate if one was previously active */ -if (tascam->current_rate >0 ) -us144mkii_configure_device_for_rate (tascam, - tascam->current_rate); - -return 0 ; -} -static const struct usb_device_id tascam_usb_ids[] = { {USB_DEVICE (USB_VID_TASCAM ,USB_PID_TASCAM_US144 ) }, {USB_DEVICE (USB_VID_TASCAM ,USB_PID_TASCAM_US144MKII ) },
sound/usb/usx2y/us144mkii.h +118 -9
237 lines not on this page · raw message
sound/usb/usx2y/us144mkii_controls.c new file +444 -0
444 lines not on this page · raw message
sound/usb/usx2y/us144mkii_midi.c new file +399 -0
399 lines not on this page · raw message
sound/usb/usx2y/us144mkii_pcm.c +48 -7
67 lines not on this page · raw message
Signature · 1 line
2.39.5
PATCH v6 6/7 ALSA: usb-audio: us144mkii: Add deep sleep command
In reply to Šerif RamiAdd a deep sleep vendor command to be sent during suspend, allowing the device to enter a lower power state.
--- sound/usb/usx2y/us144mkii.c | 7 +++++++ sound/usb/usx2y/us144mkii.h | 1 + 2 files changed, 8 insertions(+)
sound/usb/usx2y/us144mkii.c +7 -0
@@ -322,6 +322,13 @@ static int tascam_suspend(struct usb_interface *intf, pm_message_t message)usb_kill_anchored_urbs (&tascam->midi_in_anchor);usb_kill_anchored_urbs (&tascam->midi_out_anchor); +dev_info (&intf->dev,"sending deep sleep command\n" ); +int err =usb_control_msg (tascam->dev,usb_sndctrlpipe (tascam->dev,0 ), +VENDOR_REQ_DEEP_SLEEP ,RT_H2D_VENDOR_DEV , +0x0000 ,0x0000 ,NULL ,0 ,USB_CTRL_TIMEOUT_MS ); +if (err <0 ) +dev_err (&intf->dev,"deep sleep command failed: %d\n" , err); +return 0 ; }
sound/usb/usx2y/us144mkii.h +1 -0
@@ -46,6 +46,7 @@ enum uac_control_selector {enum tascam_vendor_request {VENDOR_REQ_REGISTER_WRITE =0x41 , +VENDOR_REQ_DEEP_SLEEP =0x44 ,VENDOR_REQ_MODE_CONTROL =0x49 , };
Signature · 1 line
2.39.5
PATCH v6 7/7 ALSA: usb-audio: Add infrastructure for TASCAM US-144MKII
In reply to Šerif RamiThis commit adds Kconfig and Makefile entries for TASCAM US-144MKII USB audio/MIDI interface support. It includes the configuration option and links new driver files.
The Kconfig entry for US-144MKII is added. The Makefile is updated to compile new driver components.
The US-122L driver's device ID table is adjusted to remove the US-144MKII entry, as it will now be handled by its dedicated driver.
--- sound/usb/Kconfig | 12 ++++++++++++ sound/usb/usx2y/Makefile | 2 ++ sound/usb/usx2y/us122l.c | 6 ------ 3 files changed, 14 insertions(+), 6 deletions(-)
sound/usb/Kconfig +12 -0
@@ -117,6 +117,18 @@ config SND_USB_US122L To compile this driver as a module, choose M here: the module will be called snd-usb-us122l. +config SND_USB_US144MKII + tristate "Tascam US-144MKII USB driver" + depends on X86 || COMPILE_TEST + select SND_RAWMIDI + select SND_PCM + help + Say Y here to include support for Tascam US-144MKII USB Audio/MIDI + interface. + + To compile this driver as a module, choose M here: the module + will be called snd-usb-us144mkii. + config SND_USB_6FIRE tristate "TerraTec DMX 6Fire USB" select FW_LOADER
sound/usb/usx2y/Makefile +2 -0
@@ -1,6 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 snd-usb-usx2y-y := usbusx2y.o usX2Yhwdep.o usx2yhwdeppcm.o snd-usb-us122l-y := us122l.o +snd-usb-us144mkii-y := us144mkii.o us144mkii_pcm.o us144mkii_playback.o us144mkii_capture.o us144mkii_midi.o us144mkii_controls.o obj-$(CONFIG_SND_USB_USX2Y) += snd-usb-usx2y.o obj-$(CONFIG_SND_USB_US122L) += snd-usb-us122l.o +obj-$(CONFIG_SND_USB_US144MKII) += snd-usb-us144mkii.o
sound/usb/usx2y/us122l.c +0 -6
@@ -686,12 +686,6 @@ static const struct usb_device_id snd_us122l_usb_id_table[] = { .idVendor = 0x0644, .idProduct = USB_ID_US122MKII }, - { - .match_flags = USB_DEVICE_ID_MATCH_DEVICE, - .idVendor = 0x0644, - .idProduct = USB_ID_US144MKII, - .driver_info = US122L_FLAG_US144 - }, {/* terminator */ } };MODULE_DEVICE_TABLE (usb, snd_us122l_usb_id_table);
Signature · 1 line
2.39.5
Takashi Iwai
AppliedQuoted 36 lines · Šerif Rami
This is v6 of the patch series to add a new driver for the TASCAM US-144MKII USB audio interface.
Changes in v6:
- Addressed open brace cosmetic standards forscoped_guard()calls.
- Added lost default values for digital in/out kcontrols.Changes in v5:
- Addressed u64 remainder in Patch 2/7.
- Refactoredguard()calls for spinlocks toscoped_guard()for ones that got missed(hopefully all).Changes in v4:
- Removing leading spaces from #defines as requested.
- Renaming fpoInitPattern tofpo_init_pattern.
- Removing unnecessarykfree()calls.
- Replacing manual lock/unlock patterns withscoped_guard().Changes in v3
- Corrected v2 invalid patches order
The v2 submission included mix of patches for v2 that were unusable. These new patches are valid now.Changes in v2:
- Patch 1: Dropped blank line, initialized__free(kfree)variable to NULL, and fixedstruct tascam_cardindentation.
- Patch 2: Corrected indentation inus144mkii.h.
- Patch 3: ChangedfpoInitPatterntofpo_init_pattern(snake_case), initialized__free(kfree)variable, and replacedguard(spinlock_irqsave)withscoped_guard().
- Patch 5: Updated control names to standard "Playback Source" and "Capture Source" formats, and initialized__free(kfree)variable to NULL.
- Patch 6: Re-organized code style alignments into previous patches.
- Patch 7: Fixed trailing whitespace warning.
Quoted 8 lines
Šerif Rami (7):
ALSA: usb-audio: Add initial driver for TASCAM US-144MKII
ALSA: usb-audio: us144mkii: Add PCM core infrastructure
ALSA: usb-audio: us144mkii: Implement audio playback and feedback
ALSA: usb-audio: us144mkii: Implement audio capture and decoding
ALSA: usb-audio: us144mkii: Add MIDI support and mixer controls
ALSA: usb-audio: us144mkii: Add deep sleep command
ALSA: usb-audio: Add infrastructure for TASCAM US-144MKII
Applied to for-next branch now.
thanks,
Takashi