GUI fixes

This commit is contained in:
serifpersia 2025-08-05 18:32:06 +02:00 committed by Šerif Rami
parent 1f8b9c3fd9
commit 81c133fb52
12 changed files with 1723 additions and 1672 deletions

View File

@ -14,6 +14,7 @@ This driver is under active development.
### 📝 To-Do & Known Limitations ### 📝 To-Do & Known Limitations
* Find Bugs, if possible improve performance/stablity * Find Bugs, if possible improve performance/stablity
* *MIDI IN/OUT works only in active audio streaming(DAW ALSA/JACK or browser audio) * *MIDI IN/OUT works only in active audio streaming(DAW ALSA/JACK or browser audio)
* Non MKII US-144 needs testing to see if the driver will work with it.
## Installation and Usage ## Installation and Usage

View File

@ -2,8 +2,9 @@
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <vector>
AlsaController::AlsaController(const std::string& target_card_name) AlsaController::AlsaController(const std::vector<std::string>& target_card_names)
{ {
int card = -1; int card = -1;
if (snd_card_next(&card) < 0 || card < 0) { if (snd_card_next(&card) < 0 || card < 0) {
@ -14,14 +15,24 @@ AlsaController::AlsaController(const std::string& target_card_name)
while (card >= 0) { while (card >= 0) {
char* long_name = nullptr; char* long_name = nullptr;
snd_card_get_longname(card, &long_name); snd_card_get_longname(card, &long_name);
if (long_name && std::string(long_name).find(target_card_name) != std::string::npos) { if (long_name) {
bool found_match_and_freed = false;
for (const auto& name : target_card_names) {
if (std::string(long_name).find(name) != std::string::npos) {
m_card_num = card; m_card_num = card;
m_card_id_str = "hw:" + std::to_string(card); m_card_id_str = "hw:" + std::to_string(card);
m_card_found = true; m_card_found = true;
free(long_name); free(long_name);
found_match_and_freed = true;
break; break;
} }
if (long_name) free(long_name); }
if (!found_match_and_freed) {
free(long_name);
}
}
if (m_card_found) break;
if (snd_card_next(&card) < 0) { if (snd_card_next(&card) < 0) {
break; break;
@ -29,7 +40,7 @@ AlsaController::AlsaController(const std::string& target_card_name)
} }
if (!m_card_found) { if (!m_card_found) {
std::cerr << "Target sound card '" << target_card_name << "' not found." << std::endl; std::cerr << "Target sound card(s) not found." << std::endl;
} }
} }

View File

@ -3,11 +3,12 @@
#include <string> #include <string>
#include <optional> #include <optional>
#include <vector>
class AlsaController class AlsaController
{ {
public: public:
AlsaController(const std::string& target_card_name = "US-144MKII"); AlsaController(const std::vector<std::string>& target_card_names = {"US-144MKII", "US-144"});
std::optional<std::string> getCardId() const; std::optional<std::string> getCardId() const;
int getCardNumber() const; int getCardNumber() const;

View File

@ -84,7 +84,7 @@ MainWindow::MainWindow(QWidget *parent)
, m_aboutDialog(nullptr) , m_aboutDialog(nullptr)
{ {
if (!m_alsa.isCardFound()) { if (!m_alsa.isCardFound()) {
QMessageBox::critical(this, "Error", "TASCAM US-144MKII Not Found.\nPlease ensure the device is connected and the 'us144mkii' driver is loaded."); QMessageBox::critical(this, "Error", "TASCAM US-144/US-144MKII Not Found.\nPlease ensure the device is connected and the 'us144mkii' driver is loaded.");
QTimer::singleShot(0, this, &QWidget::close); QTimer::singleShot(0, this, &QWidget::close);
return; return;
} }

View File

@ -16,8 +16,8 @@ MODULE_LICENSE("GPL");
* These parameters allow users to configure how the ALSA sound card * These parameters allow users to configure how the ALSA sound card
* for the TASCAM US-144MKII is instantiated. * for the TASCAM US-144MKII is instantiated.
* *
* @param index: Array of integers specifying the ALSA card index for each device. * @param index: Array of integers specifying the ALSA card index for each
* Defaults to -1 (automatic). * device. Defaults to -1 (automatic).
* @param id: Array of strings specifying the ALSA card ID for each device. * @param id: Array of strings specifying the ALSA card ID for each device.
* Defaults to "US144MKII". * Defaults to "US144MKII".
* @param enable: Array of booleans to enable or disable each device. * @param enable: Array of booleans to enable or disable each device.
@ -26,7 +26,7 @@ MODULE_LICENSE("GPL");
*/ */
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
static bool enable[SNDRV_CARDS] = { 1, [1 ...(SNDRV_CARDS - 1)] = 0 }; static bool enable[SNDRV_CARDS] = {1, [1 ...(SNDRV_CARDS - 1)] = 0};
static int dev_idx; static int dev_idx;
static struct usb_driver tascam_alsa_driver; static struct usb_driver tascam_alsa_driver;
@ -50,8 +50,7 @@ static int tascam_resume(struct usb_interface *intf);
* Return: The number of bytes written to the buffer. * Return: The number of bytes written to the buffer.
*/ */
static ssize_t driver_version_show(struct device *dev, static ssize_t driver_version_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf) {
{
return sysfs_emit(buf, "%s\n", DRIVER_VERSION); return sysfs_emit(buf, "%s\n", DRIVER_VERSION);
} }
static DEVICE_ATTR_RO(driver_version); static DEVICE_ATTR_RO(driver_version);
@ -64,15 +63,13 @@ static DEVICE_ATTR_RO(driver_version);
* capture, and MIDI URBs, along with their transfer buffers and the * capture, and MIDI URBs, along with their transfer buffers and the
* capture ring/decode buffers. * capture ring/decode buffers.
*/ */
void tascam_free_urbs(struct tascam_card *tascam) void tascam_free_urbs(struct tascam_card *tascam) {
{
int i; int i;
usb_kill_anchored_urbs(&tascam->playback_anchor); usb_kill_anchored_urbs(&tascam->playback_anchor);
for (i = 0; i < NUM_PLAYBACK_URBS; i++) { for (i = 0; i < NUM_PLAYBACK_URBS; i++) {
if (tascam->playback_urbs[i]) { if (tascam->playback_urbs[i]) {
usb_free_coherent( usb_free_coherent(tascam->dev, tascam->playback_urb_alloc_size,
tascam->dev, tascam->playback_urb_alloc_size,
tascam->playback_urbs[i]->transfer_buffer, tascam->playback_urbs[i]->transfer_buffer,
tascam->playback_urbs[i]->transfer_dma); tascam->playback_urbs[i]->transfer_dma);
usb_free_urb(tascam->playback_urbs[i]); usb_free_urb(tascam->playback_urbs[i]);
@ -83,8 +80,7 @@ void tascam_free_urbs(struct tascam_card *tascam)
usb_kill_anchored_urbs(&tascam->feedback_anchor); usb_kill_anchored_urbs(&tascam->feedback_anchor);
for (i = 0; i < NUM_FEEDBACK_URBS; i++) { for (i = 0; i < NUM_FEEDBACK_URBS; i++) {
if (tascam->feedback_urbs[i]) { if (tascam->feedback_urbs[i]) {
usb_free_coherent( usb_free_coherent(tascam->dev, tascam->feedback_urb_alloc_size,
tascam->dev, tascam->feedback_urb_alloc_size,
tascam->feedback_urbs[i]->transfer_buffer, tascam->feedback_urbs[i]->transfer_buffer,
tascam->feedback_urbs[i]->transfer_dma); tascam->feedback_urbs[i]->transfer_dma);
usb_free_urb(tascam->feedback_urbs[i]); usb_free_urb(tascam->feedback_urbs[i]);
@ -95,8 +91,7 @@ void tascam_free_urbs(struct tascam_card *tascam)
usb_kill_anchored_urbs(&tascam->capture_anchor); usb_kill_anchored_urbs(&tascam->capture_anchor);
for (i = 0; i < NUM_CAPTURE_URBS; i++) { for (i = 0; i < NUM_CAPTURE_URBS; i++) {
if (tascam->capture_urbs[i]) { if (tascam->capture_urbs[i]) {
usb_free_coherent( usb_free_coherent(tascam->dev, tascam->capture_urb_alloc_size,
tascam->dev, tascam->capture_urb_alloc_size,
tascam->capture_urbs[i]->transfer_buffer, tascam->capture_urbs[i]->transfer_buffer,
tascam->capture_urbs[i]->transfer_dma); tascam->capture_urbs[i]->transfer_dma);
usb_free_urb(tascam->capture_urbs[i]); usb_free_urb(tascam->capture_urbs[i]);
@ -107,8 +102,7 @@ void tascam_free_urbs(struct tascam_card *tascam)
usb_kill_anchored_urbs(&tascam->midi_in_anchor); usb_kill_anchored_urbs(&tascam->midi_in_anchor);
for (i = 0; i < NUM_MIDI_IN_URBS; i++) { for (i = 0; i < NUM_MIDI_IN_URBS; i++) {
if (tascam->midi_in_urbs[i]) { if (tascam->midi_in_urbs[i]) {
usb_free_coherent( usb_free_coherent(tascam->dev, MIDI_IN_BUF_SIZE,
tascam->dev, MIDI_IN_BUF_SIZE,
tascam->midi_in_urbs[i]->transfer_buffer, tascam->midi_in_urbs[i]->transfer_buffer,
tascam->midi_in_urbs[i]->transfer_dma); tascam->midi_in_urbs[i]->transfer_dma);
usb_free_urb(tascam->midi_in_urbs[i]); usb_free_urb(tascam->midi_in_urbs[i]);
@ -119,8 +113,7 @@ void tascam_free_urbs(struct tascam_card *tascam)
usb_kill_anchored_urbs(&tascam->midi_out_anchor); usb_kill_anchored_urbs(&tascam->midi_out_anchor);
for (i = 0; i < NUM_MIDI_OUT_URBS; i++) { for (i = 0; i < NUM_MIDI_OUT_URBS; i++) {
if (tascam->midi_out_urbs[i]) { if (tascam->midi_out_urbs[i]) {
usb_free_coherent( usb_free_coherent(tascam->dev, MIDI_OUT_BUF_SIZE,
tascam->dev, MIDI_OUT_BUF_SIZE,
tascam->midi_out_urbs[i]->transfer_buffer, tascam->midi_out_urbs[i]->transfer_buffer,
tascam->midi_out_urbs[i]->transfer_dma); tascam->midi_out_urbs[i]->transfer_dma);
usb_free_urb(tascam->midi_out_urbs[i]); usb_free_urb(tascam->midi_out_urbs[i]);
@ -149,25 +142,22 @@ void tascam_free_urbs(struct tascam_card *tascam)
* *
* Return: 0 on success, or a negative error code on failure. * Return: 0 on success, or a negative error code on failure.
*/ */
int tascam_alloc_urbs(struct tascam_card *tascam) int tascam_alloc_urbs(struct tascam_card *tascam) {
{
int i; int i;
size_t max_packet_size; size_t max_packet_size;
max_packet_size = ((96000 / 8000) + 2) * BYTES_PER_FRAME; max_packet_size = ((96000 / 8000) + 2) * BYTES_PER_FRAME;
tascam->playback_urb_alloc_size = tascam->playback_urb_alloc_size = max_packet_size * PLAYBACK_URB_PACKETS;
max_packet_size * PLAYBACK_URB_PACKETS;
for (i = 0; i < NUM_PLAYBACK_URBS; i++) { for (i = 0; i < NUM_PLAYBACK_URBS; i++) {
struct urb *urb = struct urb *urb = usb_alloc_urb(PLAYBACK_URB_PACKETS, GFP_KERNEL);
usb_alloc_urb(PLAYBACK_URB_PACKETS, GFP_KERNEL);
if (!urb) if (!urb)
goto error; goto error;
tascam->playback_urbs[i] = urb; tascam->playback_urbs[i] = urb;
urb->transfer_buffer = usb_alloc_coherent( urb->transfer_buffer =
tascam->dev, tascam->playback_urb_alloc_size, usb_alloc_coherent(tascam->dev, tascam->playback_urb_alloc_size,
GFP_KERNEL, &urb->transfer_dma); GFP_KERNEL, &urb->transfer_dma);
if (!urb->transfer_buffer) if (!urb->transfer_buffer)
goto error; goto error;
@ -180,26 +170,23 @@ int tascam_alloc_urbs(struct tascam_card *tascam)
urb->complete = playback_urb_complete; urb->complete = playback_urb_complete;
} }
tascam->feedback_urb_alloc_size = tascam->feedback_urb_alloc_size = FEEDBACK_PACKET_SIZE * MAX_FEEDBACK_PACKETS;
FEEDBACK_PACKET_SIZE * MAX_FEEDBACK_PACKETS;
for (i = 0; i < NUM_FEEDBACK_URBS; i++) { for (i = 0; i < NUM_FEEDBACK_URBS; i++) {
struct urb *f_urb = struct urb *f_urb = usb_alloc_urb(MAX_FEEDBACK_PACKETS, GFP_KERNEL);
usb_alloc_urb(MAX_FEEDBACK_PACKETS, GFP_KERNEL);
if (!f_urb) if (!f_urb)
goto error; goto error;
tascam->feedback_urbs[i] = f_urb; tascam->feedback_urbs[i] = f_urb;
f_urb->transfer_buffer = usb_alloc_coherent( f_urb->transfer_buffer =
tascam->dev, tascam->feedback_urb_alloc_size, usb_alloc_coherent(tascam->dev, tascam->feedback_urb_alloc_size,
GFP_KERNEL, &f_urb->transfer_dma); GFP_KERNEL, &f_urb->transfer_dma);
if (!f_urb->transfer_buffer) if (!f_urb->transfer_buffer)
goto error; goto error;
f_urb->dev = tascam->dev; f_urb->dev = tascam->dev;
f_urb->pipe = f_urb->pipe = usb_rcvisocpipe(tascam->dev, EP_PLAYBACK_FEEDBACK);
usb_rcvisocpipe(tascam->dev, EP_PLAYBACK_FEEDBACK);
f_urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; f_urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
f_urb->interval = 4; f_urb->interval = 4;
f_urb->context = tascam; f_urb->context = tascam;
@ -214,16 +201,15 @@ int tascam_alloc_urbs(struct tascam_card *tascam)
goto error; goto error;
tascam->capture_urbs[i] = c_urb; tascam->capture_urbs[i] = c_urb;
c_urb->transfer_buffer = usb_alloc_coherent( c_urb->transfer_buffer =
tascam->dev, tascam->capture_urb_alloc_size, GFP_KERNEL, usb_alloc_coherent(tascam->dev, tascam->capture_urb_alloc_size,
&c_urb->transfer_dma); GFP_KERNEL, &c_urb->transfer_dma);
if (!c_urb->transfer_buffer) if (!c_urb->transfer_buffer)
goto error; goto error;
usb_fill_bulk_urb(c_urb, tascam->dev, usb_fill_bulk_urb(c_urb, tascam->dev,
usb_rcvbulkpipe(tascam->dev, EP_AUDIO_IN), usb_rcvbulkpipe(tascam->dev, EP_AUDIO_IN),
c_urb->transfer_buffer, c_urb->transfer_buffer, tascam->capture_urb_alloc_size,
tascam->capture_urb_alloc_size,
capture_urb_complete, tascam); capture_urb_complete, tascam);
c_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; c_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
} }
@ -235,9 +221,8 @@ int tascam_alloc_urbs(struct tascam_card *tascam)
if (!m_urb) if (!m_urb)
goto error; goto error;
tascam->midi_in_urbs[i] = m_urb; tascam->midi_in_urbs[i] = m_urb;
m_urb->transfer_buffer = m_urb->transfer_buffer = usb_alloc_coherent(
usb_alloc_coherent(tascam->dev, MIDI_IN_BUF_SIZE, tascam->dev, MIDI_IN_BUF_SIZE, GFP_KERNEL, &m_urb->transfer_dma);
GFP_KERNEL, &m_urb->transfer_dma);
if (!m_urb->transfer_buffer) if (!m_urb->transfer_buffer)
goto error; goto error;
usb_fill_bulk_urb(m_urb, tascam->dev, usb_fill_bulk_urb(m_urb, tascam->dev,
@ -253,21 +238,18 @@ int tascam_alloc_urbs(struct tascam_card *tascam)
if (!m_urb) if (!m_urb)
goto error; goto error;
tascam->midi_out_urbs[i] = m_urb; tascam->midi_out_urbs[i] = m_urb;
m_urb->transfer_buffer = m_urb->transfer_buffer = usb_alloc_coherent(
usb_alloc_coherent(tascam->dev, MIDI_OUT_BUF_SIZE, tascam->dev, MIDI_OUT_BUF_SIZE, GFP_KERNEL, &m_urb->transfer_dma);
GFP_KERNEL, &m_urb->transfer_dma);
if (!m_urb->transfer_buffer) if (!m_urb->transfer_buffer)
goto error; goto error;
usb_fill_bulk_urb(m_urb, tascam->dev, usb_fill_bulk_urb(m_urb, tascam->dev,
usb_sndbulkpipe(tascam->dev, EP_MIDI_OUT), usb_sndbulkpipe(tascam->dev, EP_MIDI_OUT),
m_urb->transfer_buffer, m_urb->transfer_buffer, 0, /* length set later */
0, /* length set later */
tascam_midi_out_urb_complete, tascam); tascam_midi_out_urb_complete, tascam);
m_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; m_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
} }
tascam->capture_ring_buffer = tascam->capture_ring_buffer = kmalloc(CAPTURE_RING_BUFFER_SIZE, GFP_KERNEL);
kmalloc(CAPTURE_RING_BUFFER_SIZE, GFP_KERNEL);
if (!tascam->capture_ring_buffer) if (!tascam->capture_ring_buffer)
goto error; goto error;
@ -303,8 +285,7 @@ error:
return -ENOMEM; return -ENOMEM;
} }
void tascam_stop_work_handler(struct work_struct *work) void tascam_stop_work_handler(struct work_struct *work) {
{
struct tascam_card *tascam = struct tascam_card *tascam =
container_of(work, struct tascam_card, stop_work); container_of(work, struct tascam_card, stop_work);
@ -316,15 +297,15 @@ void tascam_stop_work_handler(struct work_struct *work)
} }
/** /**
* tascam_card_private_free() - Frees private data associated with the sound card. * tascam_card_private_free() - Frees private data associated with the sound
* card.
* @card: Pointer to the ALSA sound card instance. * @card: Pointer to the ALSA sound card instance.
* *
* This function is called when the sound card is being freed. It releases * This function is called when the sound card is being freed. It releases
* resources allocated for the tascam_card structure, including the MIDI * resources allocated for the tascam_card structure, including the MIDI
* input FIFO and decrements the USB device reference count. * input FIFO and decrements the USB device reference count.
*/ */
static void tascam_card_private_free(struct snd_card *card) static void tascam_card_private_free(struct snd_card *card) {
{
struct tascam_card *tascam = card->private_data; struct tascam_card *tascam = card->private_data;
if (tascam) { if (tascam) {
@ -347,8 +328,7 @@ static void tascam_card_private_free(struct snd_card *card)
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_suspend(struct usb_interface *intf, pm_message_t message) static int tascam_suspend(struct usb_interface *intf, pm_message_t message) {
{
struct tascam_card *tascam = usb_get_intfdata(intf); struct tascam_card *tascam = usb_get_intfdata(intf);
int err; int err;
@ -391,8 +371,7 @@ static int tascam_suspend(struct usb_interface *intf, pm_message_t message)
0, /* size */ 0, /* size */
1000); /* timeout */ 1000); /* timeout */
if (err < 0) if (err < 0)
dev_err(&intf->dev, "failed to send deep sleep command: %d\n", dev_err(&intf->dev, "failed to send deep sleep command: %d\n", err);
err);
return 0; return 0;
} }
@ -401,14 +380,13 @@ static int tascam_suspend(struct usb_interface *intf, pm_message_t message)
* tascam_resume() - Handles device resumption from suspend. * tascam_resume() - Handles device resumption from suspend.
* @intf: The USB interface being resumed. * @intf: The USB interface being resumed.
* *
* This function is called when the device resumes from suspend. It re-establishes * This function is called when the device resumes from suspend. It
* the active USB interface settings and re-configures the sample rate if it * re-establishes the active USB interface settings and re-configures the sample
* was previously active. * rate if it was previously active.
* *
* Return: 0 on success, or a negative error code on failure. * Return: 0 on success, or a negative error code on failure.
*/ */
static int tascam_resume(struct usb_interface *intf) static int tascam_resume(struct usb_interface *intf) {
{
struct tascam_card *tascam = usb_get_intfdata(intf); struct tascam_card *tascam = usb_get_intfdata(intf);
int err; int err;
@ -423,23 +401,20 @@ static int tascam_resume(struct usb_interface *intf)
*/ */
err = usb_set_interface(tascam->dev, 0, 1); err = usb_set_interface(tascam->dev, 0, 1);
if (err < 0) { if (err < 0) {
dev_err(&intf->dev, dev_err(&intf->dev, "resume: failed to set alt setting on intf 0: %d\n",
"resume: failed to set alt setting on intf 0: %d\n",
err); err);
return err; return err;
} }
err = usb_set_interface(tascam->dev, 1, 1); err = usb_set_interface(tascam->dev, 1, 1);
if (err < 0) { if (err < 0) {
dev_err(&intf->dev, dev_err(&intf->dev, "resume: failed to set alt setting on intf 1: %d\n",
"resume: failed to set alt setting on intf 1: %d\n",
err); err);
return err; return err;
} }
/* Re-configure the sample rate if one was previously active */ /* Re-configure the sample rate if one was previously active */
if (tascam->current_rate > 0) if (tascam->current_rate > 0)
us144mkii_configure_device_for_rate(tascam, us144mkii_configure_device_for_rate(tascam, tascam->current_rate);
tascam->current_rate);
return 0; return 0;
} }
@ -460,8 +435,7 @@ static int tascam_resume(struct usb_interface *intf)
* Return: 0 on success, or a negative error code on failure. * Return: 0 on success, or a negative error code on failure.
*/ */
static int tascam_probe(struct usb_interface *intf, static int tascam_probe(struct usb_interface *intf,
const struct usb_device_id *usb_id) const struct usb_device_id *usb_id) {
{
struct usb_device *dev = interface_to_usbdev(intf); struct usb_device *dev = interface_to_usbdev(intf);
struct snd_card *card; struct snd_card *card;
struct tascam_card *tascam; struct tascam_card *tascam;
@ -469,8 +443,7 @@ static int tascam_probe(struct usb_interface *intf,
char *handshake_buf; char *handshake_buf;
if (dev->speed != USB_SPEED_HIGH) if (dev->speed != USB_SPEED_HIGH)
dev_info( dev_info(&dev->dev,
&dev->dev,
"Device is connected to a USB 1.1 port, this is not supported.\n"); "Device is connected to a USB 1.1 port, this is not supported.\n");
if (intf->cur_altsetting->desc.bInterfaceNumber == 1) { if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
@ -496,10 +469,9 @@ static int tascam_probe(struct usb_interface *intf,
if (!handshake_buf) if (!handshake_buf)
return -ENOMEM; return -ENOMEM;
err = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), err = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), VENDOR_REQ_MODE_CONTROL,
VENDOR_REQ_MODE_CONTROL, RT_D2H_VENDOR_DEV, RT_D2H_VENDOR_DEV, MODE_VAL_HANDSHAKE_READ, 0x0000,
MODE_VAL_HANDSHAKE_READ, 0x0000, handshake_buf, 1, handshake_buf, 1, USB_CTRL_TIMEOUT_MS);
USB_CTRL_TIMEOUT_MS);
if (err < 0) { if (err < 0) {
dev_err(&dev->dev, "Handshake read failed with %d\n", err); dev_err(&dev->dev, "Handshake read failed with %d\n", err);
kfree(handshake_buf); kfree(handshake_buf);
@ -508,8 +480,7 @@ static int tascam_probe(struct usb_interface *intf,
if (handshake_buf[0] != 0x12 && handshake_buf[0] != 0x16 && if (handshake_buf[0] != 0x12 && handshake_buf[0] != 0x16 &&
handshake_buf[0] != 0x30) { handshake_buf[0] != 0x30) {
dev_err(&dev->dev, "Unexpected handshake value: 0x%x\n", dev_err(&dev->dev, "Unexpected handshake value: 0x%x\n", handshake_buf[0]);
handshake_buf[0]);
kfree(handshake_buf); kfree(handshake_buf);
return -ENODEV; return -ENODEV;
} }
@ -517,17 +488,13 @@ static int tascam_probe(struct usb_interface *intf,
err = usb_set_interface(dev, 0, 1); err = usb_set_interface(dev, 0, 1);
if (err < 0) { if (err < 0) {
dev_err(&dev->dev, dev_err(&dev->dev, "Failed to set alt setting 1 on interface 0: %d\n", err);
"Failed to set alt setting 1 on interface 0: %d\n",
err);
return err; return err;
} }
err = usb_set_interface(dev, 1, 1); err = usb_set_interface(dev, 1, 1);
if (err < 0) { if (err < 0) {
dev_err(&dev->dev, dev_err(&dev->dev, "Failed to set alt setting 1 on interface 1: %d\n", err);
"Failed to set alt setting 1 on interface 1: %d\n",
err);
return err; return err;
} }
@ -561,9 +528,9 @@ static int tascam_probe(struct usb_interface *intf,
strscpy(card->driver, DRIVER_NAME, sizeof(card->driver)); strscpy(card->driver, DRIVER_NAME, sizeof(card->driver));
if (dev->descriptor.idProduct == USB_PID_TASCAM_US144) { if (dev->descriptor.idProduct == USB_PID_TASCAM_US144) {
strscpy(card->shortname, "TASCAM US144", sizeof(card->shortname)); strscpy(card->shortname, "TASCAM US-144", sizeof(card->shortname));
} else if (dev->descriptor.idProduct == USB_PID_TASCAM_US144MKII) { } else if (dev->descriptor.idProduct == USB_PID_TASCAM_US144MKII) {
strscpy(card->shortname, "TASCAM US144MKII", sizeof(card->shortname)); strscpy(card->shortname, "TASCAM US-144MKII", sizeof(card->shortname));
} else { } else {
strscpy(card->shortname, "TASCAM Unknown", sizeof(card->shortname)); strscpy(card->shortname, "TASCAM Unknown", sizeof(card->shortname));
} }
@ -573,8 +540,7 @@ static int tascam_probe(struct usb_interface *intf,
err = device_create_file(&dev->dev, &dev_attr_driver_version); err = device_create_file(&dev->dev, &dev_attr_driver_version);
if (err < 0) if (err < 0)
dev_warn(&dev->dev, dev_warn(&dev->dev, "could not create driver_version attribute, err: %d\n",
"could not create driver_version attribute, err: %d\n",
err); err);
err = snd_pcm_new(card, "US144MKII PCM", 0, 1, 1, &tascam->pcm); err = snd_pcm_new(card, "US144MKII PCM", 0, 1, 1, &tascam->pcm);
@ -621,8 +587,7 @@ free_card:
* It cleans up all allocated resources, including killing URBs, freeing * It cleans up all allocated resources, including killing URBs, freeing
* the sound card, and releasing memory. * the sound card, and releasing memory.
*/ */
static void tascam_disconnect(struct usb_interface *intf) static void tascam_disconnect(struct usb_interface *intf) {
{
struct tascam_card *tascam = usb_get_intfdata(intf); struct tascam_card *tascam = usb_get_intfdata(intf);
if (!tascam) if (!tascam)
@ -644,10 +609,9 @@ static void tascam_disconnect(struct usb_interface *intf)
} }
static const struct usb_device_id tascam_usb_ids[] = { 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_US144)},
{ USB_DEVICE(USB_VID_TASCAM, USB_PID_TASCAM_US144MKII) }, {USB_DEVICE(USB_VID_TASCAM, USB_PID_TASCAM_US144MKII)},
{ /* Terminating entry */ } {/* Terminating entry */}};
};
MODULE_DEVICE_TABLE(usb, tascam_usb_ids); MODULE_DEVICE_TABLE(usb, tascam_usb_ids);
static struct usb_driver tascam_alsa_driver = { static struct usb_driver tascam_alsa_driver = {

View File

@ -4,17 +4,17 @@
#ifndef __US144MKII_H #ifndef __US144MKII_H
#define __US144MKII_H #define __US144MKII_H
#include <linux/kfifo.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/kfifo.h> #include <sound/control.h>
#include <sound/core.h> #include <sound/core.h>
#include <sound/initval.h>
#include <sound/pcm.h> #include <sound/pcm.h>
#include <sound/rawmidi.h> #include <sound/rawmidi.h>
#include <sound/initval.h>
#include <sound/control.h>
#define DRIVER_NAME "us144mkii" #define DRIVER_NAME "us144mkii"
#define DRIVER_VERSION "1.7.4" #define DRIVER_VERSION "1.7.5"
/* --- USB Device Identification --- */ /* --- USB Device Identification --- */
#define USB_VID_TASCAM 0x0644 #define USB_VID_TASCAM 0x0644
@ -152,17 +152,23 @@ enum tascam_register {
* @active_urbs: Atomic counter for active URBs. * @active_urbs: Atomic counter for active URBs.
* @current_rate: Currently configured sample rate of the device. * @current_rate: Currently configured sample rate of the device.
* @line_out_source: Source for Line Outputs (0: Playback 1-2, 1: Playback 3-4). * @line_out_source: Source for Line Outputs (0: Playback 1-2, 1: Playback 3-4).
* @digital_out_source: Source for Digital Outputs (0: Playback 1-2, 1: Playback 3-4). * @digital_out_source: Source for Digital Outputs (0: Playback 1-2, 1: Playback
* @capture_12_source: Source for Capture channels 1-2 (0: Analog In, 1: Digital In). * 3-4).
* @capture_34_source: Source for Capture channels 3-4 (0: Analog In, 1: Digital In). * @capture_12_source: Source for Capture channels 1-2 (0: Analog In, 1: Digital
* In).
* @capture_34_source: Source for Capture channels 3-4 (0: Analog In, 1: Digital
* In).
* *
* @feedback_accumulator_pattern: Stores the calculated frames per packet for feedback. * @feedback_accumulator_pattern: Stores the calculated frames per packet for
* feedback.
* @feedback_pattern_out_idx: Read index for feedback_accumulator_pattern. * @feedback_pattern_out_idx: Read index for feedback_accumulator_pattern.
* @feedback_pattern_in_idx: Write index for feedback_accumulator_pattern. * @feedback_pattern_in_idx: Write index for feedback_accumulator_pattern.
* @feedback_synced: Flag indicating if feedback is synced. * @feedback_synced: Flag indicating if feedback is synced.
* @feedback_consecutive_errors: Counter for consecutive feedback errors. * @feedback_consecutive_errors: Counter for consecutive feedback errors.
* @feedback_urb_skip_count: Number of feedback URBs to skip initially for stabilization. * @feedback_urb_skip_count: Number of feedback URBs to skip initially for
* @feedback_patterns: Pointer to the current feedback patterns based on sample rate. * stabilization.
* @feedback_patterns: Pointer to the current feedback patterns based on sample
* rate.
* @feedback_base_value: Base value for feedback pattern lookup. * @feedback_base_value: Base value for feedback pattern lookup.
* @feedback_max_value: Max value for feedback pattern lookup. * @feedback_max_value: Max value for feedback pattern lookup.
* *
@ -277,9 +283,9 @@ int tascam_alloc_urbs(struct tascam_card *tascam);
* tascam_stop_work_handler() - Work handler to stop all active streams. * tascam_stop_work_handler() - Work handler to stop all active streams.
* @work: Pointer to the work_struct. * @work: Pointer to the work_struct.
* *
* This function is scheduled to stop all active URBs (playback, feedback, capture) * This function is scheduled to stop all active URBs (playback, feedback,
* and reset the active_urbs counter. It is used to gracefully stop streams * capture) and reset the active_urbs counter. It is used to gracefully stop
* from a workqueue context. * streams from a workqueue context.
*/ */
void tascam_stop_work_handler(struct work_struct *work); void tascam_stop_work_handler(struct work_struct *work);
@ -318,7 +324,8 @@ int tascam_create_midi(struct tascam_card *tascam);
/* us144mkii_controls.c */ /* us144mkii_controls.c */
/** /**
* tascam_create_controls() - Creates and adds ALSA mixer controls for the device. * tascam_create_controls() - Creates and adds ALSA mixer controls for the
* device.
* @tascam: The driver instance. * @tascam: The driver instance.
* *
* This function registers custom ALSA controls for managing audio routing * This function registers custom ALSA controls for managing audio routing

View File

@ -12,8 +12,7 @@
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_capture_open(struct snd_pcm_substream *substream) static int tascam_capture_open(struct snd_pcm_substream *substream) {
{
struct tascam_card *tascam = snd_pcm_substream_chip(substream); struct tascam_card *tascam = snd_pcm_substream_chip(substream);
substream->runtime->hw = tascam_pcm_hw; substream->runtime->hw = tascam_pcm_hw;
@ -32,8 +31,7 @@ static int tascam_capture_open(struct snd_pcm_substream *substream)
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_capture_close(struct snd_pcm_substream *substream) static int tascam_capture_close(struct snd_pcm_substream *substream) {
{
struct tascam_card *tascam = snd_pcm_substream_chip(substream); struct tascam_card *tascam = snd_pcm_substream_chip(substream);
tascam->capture_substream = NULL; tascam->capture_substream = NULL;
@ -49,8 +47,7 @@ static int tascam_capture_close(struct snd_pcm_substream *substream)
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_capture_prepare(struct snd_pcm_substream *substream) static int tascam_capture_prepare(struct snd_pcm_substream *substream) {
{
struct tascam_card *tascam = snd_pcm_substream_chip(substream); struct tascam_card *tascam = snd_pcm_substream_chip(substream);
tascam->driver_capture_pos = 0; tascam->driver_capture_pos = 0;
@ -71,8 +68,8 @@ static int tascam_capture_prepare(struct snd_pcm_substream *substream)
* *
* Return: The current capture pointer position in frames. * Return: The current capture pointer position in frames.
*/ */
static snd_pcm_uframes_t tascam_capture_pointer(struct snd_pcm_substream *substream) static snd_pcm_uframes_t
{ tascam_capture_pointer(struct snd_pcm_substream *substream) {
struct tascam_card *tascam = snd_pcm_substream_chip(substream); struct tascam_card *tascam = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
u64 pos; u64 pos;
@ -85,10 +82,8 @@ static snd_pcm_uframes_t tascam_capture_pointer(struct snd_pcm_substream *substr
pos = tascam->capture_frames_processed; pos = tascam->capture_frames_processed;
spin_unlock_irqrestore(&tascam->lock, flags); spin_unlock_irqrestore(&tascam->lock, flags);
u64 remainder = do_div(pos, runtime->buffer_size); u64 remainder = do_div(pos, runtime->buffer_size);
return runtime ? remainder : 0; return runtime ? remainder : 0;
} }
/** /**
@ -118,11 +113,12 @@ const struct snd_pcm_ops tascam_capture_ops = {
* demultiplexes the bits from the raw block into 8 frames of 4-channel, * demultiplexes the bits from the raw block into 8 frames of 4-channel,
* 24-bit audio (stored in 32-bit containers). * 24-bit audio (stored in 32-bit containers).
*/ */
static void decode_tascam_capture_block(const u8 *src_block, s32 *dst_block) static void decode_tascam_capture_block(const u8 *src_block, s32 *dst_block) {
{
int frame, bit; int frame, bit;
memset(dst_block, 0, FRAMES_PER_DECODE_BLOCK * DECODED_CHANNELS_PER_FRAME * DECODED_SAMPLE_SIZE); memset(dst_block, 0,
FRAMES_PER_DECODE_BLOCK * DECODED_CHANNELS_PER_FRAME *
DECODED_SAMPLE_SIZE);
for (frame = 0; frame < FRAMES_PER_DECODE_BLOCK; ++frame) { for (frame = 0; frame < FRAMES_PER_DECODE_BLOCK; ++frame) {
const u8 *p_src_frame_base = src_block + frame * 64; const u8 *p_src_frame_base = src_block + frame * 64;
@ -161,9 +157,9 @@ static void decode_tascam_capture_block(const u8 *src_block, s32 *dst_block)
* copies the final audio data into the ALSA capture ring buffer. This offloads * copies the final audio data into the ALSA capture ring buffer. This offloads
* * the CPU-intensive decoding from the time-sensitive URB completion handlers. * * the CPU-intensive decoding from the time-sensitive URB completion handlers.
*/ */
void tascam_capture_work_handler(struct work_struct *work) void tascam_capture_work_handler(struct work_struct *work) {
{ struct tascam_card *tascam =
struct tascam_card *tascam = container_of(work, struct tascam_card, capture_work); container_of(work, struct tascam_card, capture_work);
struct snd_pcm_substream *substream = tascam->capture_substream; struct snd_pcm_substream *substream = tascam->capture_substream;
struct snd_pcm_runtime *runtime; struct snd_pcm_runtime *runtime;
unsigned long flags; unsigned long flags;
@ -176,7 +172,8 @@ void tascam_capture_work_handler(struct work_struct *work)
runtime = substream->runtime; runtime = substream->runtime;
if (!raw_block || !decoded_block || !routed_block) { if (!raw_block || !decoded_block || !routed_block) {
dev_err(tascam->card->dev, "Capture decode/routing buffers not allocated!\n"); dev_err(tascam->card->dev,
"Capture decode/routing buffers not allocated!\n");
return; return;
} }
@ -187,15 +184,19 @@ void tascam_capture_work_handler(struct work_struct *work)
spin_lock_irqsave(&tascam->lock, flags); spin_lock_irqsave(&tascam->lock, flags);
write_ptr = tascam->capture_ring_buffer_write_ptr; write_ptr = tascam->capture_ring_buffer_write_ptr;
read_ptr = tascam->capture_ring_buffer_read_ptr; read_ptr = tascam->capture_ring_buffer_read_ptr;
available_data = (write_ptr >= read_ptr) ? (write_ptr - read_ptr) : (CAPTURE_RING_BUFFER_SIZE - read_ptr + write_ptr); available_data = (write_ptr >= read_ptr)
? (write_ptr - read_ptr)
: (CAPTURE_RING_BUFFER_SIZE - read_ptr + write_ptr);
can_process = (available_data >= RAW_BYTES_PER_DECODE_BLOCK); can_process = (available_data >= RAW_BYTES_PER_DECODE_BLOCK);
if (can_process) { if (can_process) {
size_t i; size_t i;
for (i = 0; i < RAW_BYTES_PER_DECODE_BLOCK; i++) for (i = 0; i < RAW_BYTES_PER_DECODE_BLOCK; i++)
raw_block[i] = tascam->capture_ring_buffer[(read_ptr + i) % CAPTURE_RING_BUFFER_SIZE]; raw_block[i] = tascam->capture_ring_buffer[(read_ptr + i) %
tascam->capture_ring_buffer_read_ptr = (read_ptr + RAW_BYTES_PER_DECODE_BLOCK) % CAPTURE_RING_BUFFER_SIZE; CAPTURE_RING_BUFFER_SIZE];
tascam->capture_ring_buffer_read_ptr =
(read_ptr + RAW_BYTES_PER_DECODE_BLOCK) % CAPTURE_RING_BUFFER_SIZE;
} }
spin_unlock_irqrestore(&tascam->lock, flags); spin_unlock_irqrestore(&tascam->lock, flags);
@ -210,7 +211,9 @@ void tascam_capture_work_handler(struct work_struct *work)
int f; int f;
for (f = 0; f < FRAMES_PER_DECODE_BLOCK; ++f) { for (f = 0; f < FRAMES_PER_DECODE_BLOCK; ++f) {
u8 *dst_frame_start = runtime->dma_area + frames_to_bytes(runtime, tascam->driver_capture_pos); u8 *dst_frame_start =
runtime->dma_area +
frames_to_bytes(runtime, tascam->driver_capture_pos);
s32 *routed_frame_start = routed_block + (f * NUM_CHANNELS); s32 *routed_frame_start = routed_block + (f * NUM_CHANNELS);
int c; int c;
@ -221,7 +224,8 @@ void tascam_capture_work_handler(struct work_struct *work)
memcpy(dst_channel, ((char *)src_channel_s32) + 1, 3); memcpy(dst_channel, ((char *)src_channel_s32) + 1, 3);
} }
tascam->driver_capture_pos = (tascam->driver_capture_pos + 1) % runtime->buffer_size; tascam->driver_capture_pos =
(tascam->driver_capture_pos + 1) % runtime->buffer_size;
} }
} }
spin_unlock_irqrestore(&tascam->lock, flags); spin_unlock_irqrestore(&tascam->lock, flags);
@ -236,16 +240,17 @@ void tascam_capture_work_handler(struct work_struct *work)
* into an intermediate ring buffer and then schedules the workqueue to process * into an intermediate ring buffer and then schedules the workqueue to process
* it. It then resubmits the URB to receive more data. * it. It then resubmits the URB to receive more data.
*/ */
void capture_urb_complete(struct urb *urb) void capture_urb_complete(struct urb *urb) {
{
struct tascam_card *tascam = urb->context; struct tascam_card *tascam = urb->context;
int ret; int ret;
unsigned long flags; unsigned long flags;
if (urb->status) { if (urb->status) {
if (urb->status != -ENOENT && urb->status != -ECONNRESET && urb->status != -ESHUTDOWN && if (urb->status != -ENOENT && urb->status != -ECONNRESET &&
urb->status != -ENODEV && urb->status != -EPROTO) urb->status != -ESHUTDOWN && urb->status != -ENODEV &&
dev_err_ratelimited(tascam->card->dev, "Capture URB failed: %d\n", urb->status); urb->status != -EPROTO)
dev_err_ratelimited(tascam->card->dev, "Capture URB failed: %d\n",
urb->status);
goto out; goto out;
} }
if (!tascam || !atomic_read(&tascam->capture_active)) if (!tascam || !atomic_read(&tascam->capture_active))
@ -271,7 +276,8 @@ void capture_urb_complete(struct urb *urb)
usb_anchor_urb(urb, &tascam->capture_anchor); usb_anchor_urb(urb, &tascam->capture_anchor);
ret = usb_submit_urb(urb, GFP_ATOMIC); ret = usb_submit_urb(urb, GFP_ATOMIC);
if (ret < 0) { if (ret < 0) {
dev_err_ratelimited(tascam->card->dev, "Failed to resubmit capture URB: %d\n", ret); dev_err_ratelimited(tascam->card->dev,
"Failed to resubmit capture URB: %d\n", ret);
usb_unanchor_urb(urb); usb_unanchor_urb(urb);
usb_put_urb(urb); usb_put_urb(urb);
} }

View File

@ -9,7 +9,8 @@
* Used by ALSA kcontrol elements to provide user-friendly names for * Used by ALSA kcontrol elements to provide user-friendly names for
* the playback routing options (e.g., "Playback 1-2", "Playback 3-4"). * the playback routing options (e.g., "Playback 1-2", "Playback 3-4").
*/ */
static const char * const playback_source_texts[] = {"Playback 1-2", "Playback 3-4"}; static const char *const playback_source_texts[] = {"Playback 1-2",
"Playback 3-4"};
/** /**
* @brief Text descriptions for capture input source options. * @brief Text descriptions for capture input source options.
@ -17,20 +18,22 @@ static const char * const playback_source_texts[] = {"Playback 1-2", "Playback 3
* Used by ALSA kcontrol elements to provide user-friendly names for * Used by ALSA kcontrol elements to provide user-friendly names for
* the capture routing options (e.g., "Analog In", "Digital In"). * the capture routing options (e.g., "Analog In", "Digital In").
*/ */
static const char * const capture_source_texts[] = {"Analog In", "Digital In"}; static const char *const capture_source_texts[] = {"Analog In", "Digital In"};
/** /**
* tascam_playback_source_info() - ALSA control info callback for playback source. * tascam_playback_source_info() - ALSA control info callback for playback
* source.
* @kcontrol: The ALSA kcontrol instance. * @kcontrol: The ALSA kcontrol instance.
* @uinfo: The ALSA control element info structure to fill. * @uinfo: The ALSA control element info structure to fill.
* *
* This function provides information about the enumerated playback source * This function provides information about the enumerated playback source
* control, including its type, count, and available items (Playback 1-2, Playback 3-4). * control, including its type, count, and available items (Playback 1-2,
* Playback 3-4).
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_playback_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) static int tascam_playback_source_info(struct snd_kcontrol *kcontrol,
{ struct snd_ctl_elem_info *uinfo) {
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
uinfo->count = 1; uinfo->count = 1;
uinfo->value.enumerated.items = 2; uinfo->value.enumerated.items = 2;
@ -53,8 +56,8 @@ static int tascam_playback_source_info(struct snd_kcontrol *kcontrol, struct snd
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_line_out_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) static int tascam_line_out_get(struct snd_kcontrol *kcontrol,
{ struct snd_ctl_elem_value *ucontrol) {
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol); struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
ucontrol->value.enumerated.item[0] = tascam->line_out_source; ucontrol->value.enumerated.item[0] = tascam->line_out_source;
@ -72,8 +75,8 @@ static int tascam_line_out_get(struct snd_kcontrol *kcontrol, struct snd_ctl_ele
* *
* Return: 1 if the value was changed, 0 if unchanged, or a negative error code. * Return: 1 if the value was changed, 0 if unchanged, or a negative error code.
*/ */
static int tascam_line_out_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) static int tascam_line_out_put(struct snd_kcontrol *kcontrol,
{ struct snd_ctl_elem_value *ucontrol) {
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol); struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
if (ucontrol->value.enumerated.item[0] > 1) if (ucontrol->value.enumerated.item[0] > 1)
@ -90,15 +93,20 @@ static int tascam_line_out_put(struct snd_kcontrol *kcontrol, struct snd_ctl_ele
* This defines a new ALSA mixer control named "Line OUTPUTS Source" that allows * This defines a new ALSA mixer control named "Line OUTPUTS Source" that allows
* the user to select between "Playback 1-2" and "Playback 3-4" for the analog * the user to select between "Playback 1-2" and "Playback 3-4" for the analog
* line outputs of the device. It uses the `tascam_playback_source_info` for * line outputs of the device. It uses the `tascam_playback_source_info` for
* information and `tascam_line_out_get`/`tascam_line_out_put` for value handling. * information and `tascam_line_out_get`/`tascam_line_out_put` for value
* handling.
*/ */
static const struct snd_kcontrol_new tascam_line_out_control = { static const struct snd_kcontrol_new tascam_line_out_control = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Line OUTPUTS Source", .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.info = tascam_playback_source_info, .get = tascam_line_out_get, .put = tascam_line_out_put, .name = "Line OUTPUTS Source",
.info = tascam_playback_source_info,
.get = tascam_line_out_get,
.put = tascam_line_out_put,
}; };
/** /**
* tascam_digital_out_get() - ALSA control get callback for Digital Outputs Source. * tascam_digital_out_get() - ALSA control get callback for Digital Outputs
* Source.
* @kcontrol: The ALSA kcontrol instance. * @kcontrol: The ALSA kcontrol instance.
* @ucontrol: The ALSA control element value structure to fill. * @ucontrol: The ALSA control element value structure to fill.
* *
@ -108,8 +116,8 @@ static const struct snd_kcontrol_new tascam_line_out_control = {
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_digital_out_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) static int tascam_digital_out_get(struct snd_kcontrol *kcontrol,
{ struct snd_ctl_elem_value *ucontrol) {
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol); struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
ucontrol->value.enumerated.item[0] = tascam->digital_out_source; ucontrol->value.enumerated.item[0] = tascam->digital_out_source;
@ -117,7 +125,8 @@ static int tascam_digital_out_get(struct snd_kcontrol *kcontrol, struct snd_ctl_
} }
/** /**
* tascam_digital_out_put() - ALSA control put callback for Digital Outputs Source. * tascam_digital_out_put() - ALSA control put callback for Digital Outputs
* Source.
* @kcontrol: The ALSA kcontrol instance. * @kcontrol: The ALSA kcontrol instance.
* @ucontrol: The ALSA control element value structure containing the new value. * @ucontrol: The ALSA control element value structure containing the new value.
* *
@ -127,8 +136,8 @@ static int tascam_digital_out_get(struct snd_kcontrol *kcontrol, struct snd_ctl_
* *
* Return: 1 if the value was changed, 0 if unchanged, or a negative error code. * Return: 1 if the value was changed, 0 if unchanged, or a negative error code.
*/ */
static int tascam_digital_out_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) static int tascam_digital_out_put(struct snd_kcontrol *kcontrol,
{ struct snd_ctl_elem_value *ucontrol) {
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol); struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
if (ucontrol->value.enumerated.item[0] > 1) if (ucontrol->value.enumerated.item[0] > 1)
@ -140,16 +149,21 @@ static int tascam_digital_out_put(struct snd_kcontrol *kcontrol, struct snd_ctl_
} }
/** /**
* tascam_digital_out_control - ALSA kcontrol definition for Digital Outputs Source. * tascam_digital_out_control - ALSA kcontrol definition for Digital Outputs
* Source.
* *
* This defines a new ALSA mixer control named "Digital OUTPUTS Source" that allows * This defines a new ALSA mixer control named "Digital OUTPUTS Source" that
* the user to select between "Playback 1-2" and "Playback 3-4" for the digital * allows the user to select between "Playback 1-2" and "Playback 3-4" for the
* outputs of the device. It uses the `tascam_playback_source_info` for * digital outputs of the device. It uses the `tascam_playback_source_info` for
* information and `tascam_digital_out_get`/`tascam_digital_out_put` for value handling. * information and `tascam_digital_out_get`/`tascam_digital_out_put` for value
* handling.
*/ */
static const struct snd_kcontrol_new tascam_digital_out_control = { static const struct snd_kcontrol_new tascam_digital_out_control = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Digital OUTPUTS Source", .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.info = tascam_playback_source_info, .get = tascam_digital_out_get, .put = tascam_digital_out_put, .name = "Digital OUTPUTS Source",
.info = tascam_playback_source_info,
.get = tascam_digital_out_get,
.put = tascam_digital_out_put,
}; };
/** /**
@ -158,12 +172,13 @@ static const struct snd_kcontrol_new tascam_digital_out_control = {
* @uinfo: The ALSA control element info structure to fill. * @uinfo: The ALSA control element info structure to fill.
* *
* This function provides information about the enumerated capture source * This function provides information about the enumerated capture source
* control, including its type, count, and available items (Analog In, Digital In). * control, including its type, count, and available items (Analog In, Digital
* In).
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_capture_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) static int tascam_capture_source_info(struct snd_kcontrol *kcontrol,
{ struct snd_ctl_elem_info *uinfo) {
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
uinfo->count = 1; uinfo->count = 1;
uinfo->value.enumerated.items = 2; uinfo->value.enumerated.items = 2;
@ -176,18 +191,19 @@ static int tascam_capture_source_info(struct snd_kcontrol *kcontrol, struct snd_
} }
/** /**
* tascam_capture_12_get() - ALSA control get callback for Capture channels 1 and 2 Source. * tascam_capture_12_get() - ALSA control get callback for Capture channels 1
* and 2 Source.
* @kcontrol: The ALSA kcontrol instance. * @kcontrol: The ALSA kcontrol instance.
* @ucontrol: The ALSA control element value structure to fill. * @ucontrol: The ALSA control element value structure to fill.
* *
* This function retrieves the current selection for the Capture channels 1 and 2 source * This function retrieves the current selection for the Capture channels 1 and
* (Analog In or Digital In) from the driver's private data and populates * 2 source (Analog In or Digital In) from the driver's private data and
* the ALSA control element value. * populates the ALSA control element value.
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_capture_12_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) static int tascam_capture_12_get(struct snd_kcontrol *kcontrol,
{ struct snd_ctl_elem_value *ucontrol) {
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol); struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
ucontrol->value.enumerated.item[0] = tascam->capture_12_source; ucontrol->value.enumerated.item[0] = tascam->capture_12_source;
@ -195,18 +211,19 @@ static int tascam_capture_12_get(struct snd_kcontrol *kcontrol, struct snd_ctl_e
} }
/** /**
* tascam_capture_12_put() - ALSA control put callback for Capture channels 1 and 2 Source. * tascam_capture_12_put() - ALSA control put callback for Capture channels 1
* and 2 Source.
* @kcontrol: The ALSA kcontrol instance. * @kcontrol: The ALSA kcontrol instance.
* @ucontrol: The ALSA control element value structure containing the new value. * @ucontrol: The ALSA control element value structure containing the new value.
* *
* This function sets the Capture channels 1 and 2 source (Analog In or Digital In) * This function sets the Capture channels 1 and 2 source (Analog In or Digital
* based on the user's selection from the ALSA control element. It validates * In) based on the user's selection from the ALSA control element. It validates
* the input and updates the driver's private data. * the input and updates the driver's private data.
* *
* Return: 1 if the value was changed, 0 if unchanged, or a negative error code. * Return: 1 if the value was changed, 0 if unchanged, or a negative error code.
*/ */
static int tascam_capture_12_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) static int tascam_capture_12_put(struct snd_kcontrol *kcontrol,
{ struct snd_ctl_elem_value *ucontrol) {
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol); struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
if (ucontrol->value.enumerated.item[0] > 1) if (ucontrol->value.enumerated.item[0] > 1)
@ -218,31 +235,37 @@ static int tascam_capture_12_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
} }
/** /**
* tascam_capture_12_control - ALSA kcontrol definition for Capture channels 1 and 2 Source. * tascam_capture_12_control - ALSA kcontrol definition for Capture channels 1
* and 2 Source.
* *
* This defines a new ALSA mixer control named "ch1 and ch2 Source" that allows * This defines a new ALSA mixer control named "ch1 and ch2 Source" that allows
* the user to select between "Analog In" and "Digital In" for the first two * the user to select between "Analog In" and "Digital In" for the first two
* capture channels of the device. It uses the `tascam_capture_source_info` for * capture channels of the device. It uses the `tascam_capture_source_info` for
* information and `tascam_capture_12_get`/`tascam_capture_12_put` for value handling. * information and `tascam_capture_12_get`/`tascam_capture_12_put` for value
* handling.
*/ */
static const struct snd_kcontrol_new tascam_capture_12_control = { static const struct snd_kcontrol_new tascam_capture_12_control = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "ch1 and ch2 Source", .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.info = tascam_capture_source_info, .get = tascam_capture_12_get, .put = tascam_capture_12_put, .name = "ch1 and ch2 Source",
.info = tascam_capture_source_info,
.get = tascam_capture_12_get,
.put = tascam_capture_12_put,
}; };
/** /**
* tascam_capture_34_get() - ALSA control get callback for Capture channels 3 and 4 Source. * tascam_capture_34_get() - ALSA control get callback for Capture channels 3
* and 4 Source.
* @kcontrol: The ALSA kcontrol instance. * @kcontrol: The ALSA kcontrol instance.
* @ucontrol: The ALSA control element value structure to fill. * @ucontrol: The ALSA control element value structure to fill.
* *
* This function retrieves the current selection for the Capture channels 3 and 4 source * This function retrieves the current selection for the Capture channels 3 and
* (Analog In or Digital In) from the driver's private data and populates * 4 source (Analog In or Digital In) from the driver's private data and
* the ALSA control element value. * populates the ALSA control element value.
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_capture_34_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) static int tascam_capture_34_get(struct snd_kcontrol *kcontrol,
{ struct snd_ctl_elem_value *ucontrol) {
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol); struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
ucontrol->value.enumerated.item[0] = tascam->capture_34_source; ucontrol->value.enumerated.item[0] = tascam->capture_34_source;
@ -250,18 +273,19 @@ static int tascam_capture_34_get(struct snd_kcontrol *kcontrol, struct snd_ctl_e
} }
/** /**
* tascam_capture_34_put() - ALSA control put callback for Capture channels 3 and 4 Source. * tascam_capture_34_put() - ALSA control put callback for Capture channels 3
* and 4 Source.
* @kcontrol: The ALSA kcontrol instance. * @kcontrol: The ALSA kcontrol instance.
* @ucontrol: The ALSA control element value structure containing the new value. * @ucontrol: The ALSA control element value structure containing the new value.
* *
* This function sets the Capture channels 3 and 4 source (Analog In or Digital In) * This function sets the Capture channels 3 and 4 source (Analog In or Digital
* based on the user's selection from the ALSA control element. It validates * In) based on the user's selection from the ALSA control element. It validates
* the input and updates the driver's private data. * the input and updates the driver's private data.
* *
* Return: 1 if the value was changed, 0 if unchanged, or a negative error code. * Return: 1 if the value was changed, 0 if unchanged, or a negative error code.
*/ */
static int tascam_capture_34_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) static int tascam_capture_34_put(struct snd_kcontrol *kcontrol,
{ struct snd_ctl_elem_value *ucontrol) {
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol); struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
if (ucontrol->value.enumerated.item[0] > 1) if (ucontrol->value.enumerated.item[0] > 1)
@ -273,16 +297,21 @@ static int tascam_capture_34_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
} }
/** /**
* tascam_capture_34_control - ALSA kcontrol definition for Capture channels 3 and 4 Source. * tascam_capture_34_control - ALSA kcontrol definition for Capture channels 3
* and 4 Source.
* *
* This defines a new ALSA mixer control named "ch3 and ch4 Source" that allows * This defines a new ALSA mixer control named "ch3 and ch4 Source" that allows
* the user to select between "Analog In" and "Digital In" for the third and fourth * the user to select between "Analog In" and "Digital In" for the third and
* capture channels of the device. It uses the `tascam_capture_source_info` for * fourth capture channels of the device. It uses the
* information and `tascam_capture_34_get`/`tascam_capture_34_put` for value handling. * `tascam_capture_source_info` for information and
* `tascam_capture_34_get`/`tascam_capture_34_put` for value handling.
*/ */
static const struct snd_kcontrol_new tascam_capture_34_control = { static const struct snd_kcontrol_new tascam_capture_34_control = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "ch3 and ch4 Source", .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.info = tascam_capture_source_info, .get = tascam_capture_34_get, .put = tascam_capture_34_put, .name = "ch3 and ch4 Source",
.info = tascam_capture_source_info,
.get = tascam_capture_34_get,
.put = tascam_capture_34_put,
}; };
/** /**
@ -295,8 +324,8 @@ static const struct snd_kcontrol_new tascam_capture_34_control = {
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_samplerate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) static int tascam_samplerate_info(struct snd_kcontrol *kcontrol,
{ struct snd_ctl_elem_info *uinfo) {
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1; uinfo->count = 1;
uinfo->value.integer.min = 0; uinfo->value.integer.min = 0;
@ -311,13 +340,15 @@ static int tascam_samplerate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_
* *
* This function retrieves the current sample rate from the device via a USB * This function retrieves the current sample rate from the device via a USB
* control message and populates the ALSA control element value. If the rate * control message and populates the ALSA control element value. If the rate
* is already known (i.e., `current_rate` is set), it returns that value directly. * is already known (i.e., `current_rate` is set), it returns that value
* directly.
* *
* Return: 0 on success, or a negative error code on failure. * Return: 0 on success, or a negative error code on failure.
*/ */
static int tascam_samplerate_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) static int tascam_samplerate_get(struct snd_kcontrol *kcontrol,
{ struct snd_ctl_elem_value *ucontrol) {
struct tascam_card *tascam = (struct tascam_card *)snd_kcontrol_chip(kcontrol); struct tascam_card *tascam =
(struct tascam_card *)snd_kcontrol_chip(kcontrol);
u8 *buf; u8 *buf;
int err; int err;
u32 rate = 0; u32 rate = 0;
@ -332,9 +363,8 @@ static int tascam_samplerate_get(struct snd_kcontrol *kcontrol, struct snd_ctl_e
return -ENOMEM; return -ENOMEM;
err = usb_control_msg(tascam->dev, usb_rcvctrlpipe(tascam->dev, 0), err = usb_control_msg(tascam->dev, usb_rcvctrlpipe(tascam->dev, 0),
UAC_GET_CUR, RT_D2H_CLASS_EP, UAC_GET_CUR, RT_D2H_CLASS_EP, UAC_SAMPLING_FREQ_CONTROL,
UAC_SAMPLING_FREQ_CONTROL, EP_AUDIO_IN, EP_AUDIO_IN, buf, 3, USB_CTRL_TIMEOUT_MS);
buf, 3, USB_CTRL_TIMEOUT_MS);
if (err >= 3) if (err >= 3)
rate = buf[0] | (buf[1] << 8) | (buf[2] << 16); rate = buf[0] | (buf[1] << 8) | (buf[2] << 16);
@ -359,7 +389,8 @@ static const struct snd_kcontrol_new tascam_samplerate_control = {
}; };
/** /**
* tascam_create_controls() - Creates and adds ALSA mixer controls for the device. * tascam_create_controls() - Creates and adds ALSA mixer controls for the
* device.
* @tascam: The driver instance. * @tascam: The driver instance.
* *
* This function registers custom ALSA controls for managing audio routing * This function registers custom ALSA controls for managing audio routing
@ -368,24 +399,28 @@ static const struct snd_kcontrol_new tascam_samplerate_control = {
* *
* Return: 0 on success, or a negative error code on failure. * Return: 0 on success, or a negative error code on failure.
*/ */
int tascam_create_controls(struct tascam_card *tascam) int tascam_create_controls(struct tascam_card *tascam) {
{
int err; int err;
err = snd_ctl_add(tascam->card, snd_ctl_new1(&tascam_line_out_control, tascam)); err =
snd_ctl_add(tascam->card, snd_ctl_new1(&tascam_line_out_control, tascam));
if (err < 0) if (err < 0)
return err; return err;
err = snd_ctl_add(tascam->card, snd_ctl_new1(&tascam_digital_out_control, tascam)); err = snd_ctl_add(tascam->card,
snd_ctl_new1(&tascam_digital_out_control, tascam));
if (err < 0) if (err < 0)
return err; return err;
err = snd_ctl_add(tascam->card, snd_ctl_new1(&tascam_capture_12_control, tascam)); err = snd_ctl_add(tascam->card,
snd_ctl_new1(&tascam_capture_12_control, tascam));
if (err < 0) if (err < 0)
return err; return err;
err = snd_ctl_add(tascam->card, snd_ctl_new1(&tascam_capture_34_control, tascam)); err = snd_ctl_add(tascam->card,
snd_ctl_new1(&tascam_capture_34_control, tascam));
if (err < 0) if (err < 0)
return err; return err;
err = snd_ctl_add(tascam->card, snd_ctl_new1(&tascam_samplerate_control, tascam)); err = snd_ctl_add(tascam->card,
snd_ctl_new1(&tascam_samplerate_control, tascam));
if (err < 0) if (err < 0)
return err; return err;

View File

@ -11,9 +11,9 @@
* the kfifo, processes it by stripping protocol-specific padding bytes, and * the kfifo, processes it by stripping protocol-specific padding bytes, and
* passes the clean MIDI data to the ALSA rawmidi subsystem. * passes the clean MIDI data to the ALSA rawmidi subsystem.
*/ */
static void tascam_midi_in_work_handler(struct work_struct *work) static void tascam_midi_in_work_handler(struct work_struct *work) {
{ struct tascam_card *tascam =
struct tascam_card *tascam = container_of(work, struct tascam_card, midi_in_work); container_of(work, struct tascam_card, midi_in_work);
u8 buf[MIDI_IN_BUF_SIZE]; u8 buf[MIDI_IN_BUF_SIZE];
unsigned int len; unsigned int len;
int i; int i;
@ -22,8 +22,8 @@ static void tascam_midi_in_work_handler(struct work_struct *work)
return; return;
while (!kfifo_is_empty(&tascam->midi_in_fifo)) { while (!kfifo_is_empty(&tascam->midi_in_fifo)) {
len = kfifo_out_spinlocked(&tascam->midi_in_fifo, len = kfifo_out_spinlocked(&tascam->midi_in_fifo, buf, sizeof(buf),
buf, sizeof(buf), &tascam->midi_in_lock); &tascam->midi_in_lock);
if (len == 0) if (len == 0)
continue; continue;
@ -54,25 +54,22 @@ static void tascam_midi_in_work_handler(struct work_struct *work)
* USB endpoint into a kfifo and schedules a work item to process it later, * USB endpoint into a kfifo and schedules a work item to process it later,
* ensuring the interrupt handler remains fast. * ensuring the interrupt handler remains fast.
*/ */
void tascam_midi_in_urb_complete(struct urb *urb) void tascam_midi_in_urb_complete(struct urb *urb) {
{
struct tascam_card *tascam = urb->context; struct tascam_card *tascam = urb->context;
int ret; int ret;
if (urb->status) { if (urb->status) {
if (urb->status != -ENOENT && urb->status != -ECONNRESET && if (urb->status != -ENOENT && urb->status != -ECONNRESET &&
urb->status != -ESHUTDOWN && urb->status != -EPROTO) urb->status != -ESHUTDOWN && urb->status != -EPROTO)
dev_err_ratelimited(tascam->card->dev, dev_err_ratelimited(tascam->card->dev, "MIDI IN URB failed: status %d\n",
"MIDI IN URB failed: status %d\n",
urb->status); urb->status);
goto out; goto out;
} }
if (tascam && atomic_read(&tascam->midi_in_active) && urb->actual_length > 0) { if (tascam && atomic_read(&tascam->midi_in_active) &&
kfifo_in_spinlocked(&tascam->midi_in_fifo, urb->actual_length > 0) {
urb->transfer_buffer, kfifo_in_spinlocked(&tascam->midi_in_fifo, urb->transfer_buffer,
urb->actual_length, urb->actual_length, &tascam->midi_in_lock);
&tascam->midi_in_lock);
schedule_work(&tascam->midi_in_work); schedule_work(&tascam->midi_in_work);
} }
@ -80,8 +77,8 @@ void tascam_midi_in_urb_complete(struct urb *urb)
usb_anchor_urb(urb, &tascam->midi_in_anchor); usb_anchor_urb(urb, &tascam->midi_in_anchor);
ret = usb_submit_urb(urb, GFP_ATOMIC); ret = usb_submit_urb(urb, GFP_ATOMIC);
if (ret < 0) { if (ret < 0) {
dev_err(tascam->card->dev, dev_err(tascam->card->dev, "Failed to resubmit MIDI IN URB: error %d\n",
"Failed to resubmit MIDI IN URB: error %d\n", ret); ret);
usb_unanchor_urb(urb); usb_unanchor_urb(urb);
usb_put_urb(urb); usb_put_urb(urb);
} }
@ -98,8 +95,7 @@ out:
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_midi_in_open(struct snd_rawmidi_substream *substream) static int tascam_midi_in_open(struct snd_rawmidi_substream *substream) {
{
struct tascam_card *tascam = substream->rmidi->private_data; struct tascam_card *tascam = substream->rmidi->private_data;
tascam->midi_in_substream = substream; tascam->midi_in_substream = substream;
@ -112,8 +108,7 @@ static int tascam_midi_in_open(struct snd_rawmidi_substream *substream)
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_midi_in_close(struct snd_rawmidi_substream *substream) static int tascam_midi_in_close(struct snd_rawmidi_substream *substream) {
{
return 0; return 0;
} }
@ -122,13 +117,13 @@ static int tascam_midi_in_close(struct snd_rawmidi_substream *substream)
* @substream: The ALSA rawmidi substream. * @substream: The ALSA rawmidi substream.
* @up: Boolean indicating whether to start (1) or stop (0) the stream. * @up: Boolean indicating whether to start (1) or stop (0) the stream.
* *
* This function starts or stops the MIDI input URBs based on the 'up' parameter. * This function starts or stops the MIDI input URBs based on the 'up'
* When starting, it resets the kfifo and submits all MIDI input URBs. * parameter. When starting, it resets the kfifo and submits all MIDI input
* When stopping, it kills all anchored MIDI input URBs and cancels the * URBs. When stopping, it kills all anchored MIDI input URBs and cancels the
* associated workqueue. * associated workqueue.
*/ */
static void tascam_midi_in_trigger(struct snd_rawmidi_substream *substream, int up) static void tascam_midi_in_trigger(struct snd_rawmidi_substream *substream,
{ int up) {
struct tascam_card *tascam = substream->rmidi->private_data; struct tascam_card *tascam = substream->rmidi->private_data;
int i, err; int i, err;
unsigned long flags; unsigned long flags;
@ -144,7 +139,8 @@ static void tascam_midi_in_trigger(struct snd_rawmidi_substream *substream, int
usb_anchor_urb(tascam->midi_in_urbs[i], &tascam->midi_in_anchor); usb_anchor_urb(tascam->midi_in_urbs[i], &tascam->midi_in_anchor);
err = usb_submit_urb(tascam->midi_in_urbs[i], GFP_KERNEL); err = usb_submit_urb(tascam->midi_in_urbs[i], GFP_KERNEL);
if (err < 0) { if (err < 0) {
dev_err(tascam->card->dev, "Failed to submit MIDI IN URB %d: %d\n", i, err); dev_err(tascam->card->dev, "Failed to submit MIDI IN URB %d: %d\n", i,
err);
usb_unanchor_urb(tascam->midi_in_urbs[i]); usb_unanchor_urb(tascam->midi_in_urbs[i]);
usb_put_urb(tascam->midi_in_urbs[i]); usb_put_urb(tascam->midi_in_urbs[i]);
} }
@ -161,8 +157,8 @@ static void tascam_midi_in_trigger(struct snd_rawmidi_substream *substream, int
/** /**
* tascam_midi_in_ops - ALSA rawmidi operations for MIDI input. * tascam_midi_in_ops - ALSA rawmidi operations for MIDI input.
* *
* This structure defines the callback functions for MIDI input stream operations, * This structure defines the callback functions for MIDI input stream
* including open, close, and trigger. * operations, including open, close, and trigger.
*/ */
static const struct snd_rawmidi_ops tascam_midi_in_ops = { static const struct snd_rawmidi_ops tascam_midi_in_ops = {
.open = tascam_midi_in_open, .open = tascam_midi_in_open,
@ -179,15 +175,16 @@ static const struct snd_rawmidi_ops tascam_midi_in_ops = {
* send any more data waiting in the ALSA buffer. This is a safe, non-blocking * send any more data waiting in the ALSA buffer. This is a safe, non-blocking
* way to continue the data transmission chain. * way to continue the data transmission chain.
*/ */
void tascam_midi_out_urb_complete(struct urb *urb) void tascam_midi_out_urb_complete(struct urb *urb) {
{
struct tascam_card *tascam = urb->context; struct tascam_card *tascam = urb->context;
unsigned long flags; unsigned long flags;
int i, urb_index = -1; int i, urb_index = -1;
if (urb->status) { if (urb->status) {
if (urb->status != -ENOENT && urb->status != -ECONNRESET && urb->status != -ESHUTDOWN) if (urb->status != -ENOENT && urb->status != -ECONNRESET &&
dev_err_ratelimited(tascam->card->dev, "MIDI OUT URB failed: %d\n", urb->status); urb->status != -ESHUTDOWN)
dev_err_ratelimited(tascam->card->dev, "MIDI OUT URB failed: %d\n",
urb->status);
} }
if (!tascam) if (!tascam)
@ -225,8 +222,7 @@ out:
* This function pulls as many bytes as will fit into one packet from the * This function pulls as many bytes as will fit into one packet from the
* ALSA buffer and sends them. * ALSA buffer and sends them.
*/ */
static void tascam_midi_out_work_handler(struct work_struct *work) static void tascam_midi_out_work_handler(struct work_struct *work) {
{
struct tascam_card *tascam = struct tascam_card *tascam =
container_of(work, struct tascam_card, midi_out_work); container_of(work, struct tascam_card, midi_out_work);
struct snd_rawmidi_substream *substream = tascam->midi_out_substream; struct snd_rawmidi_substream *substream = tascam->midi_out_substream;
@ -235,7 +231,7 @@ static void tascam_midi_out_work_handler(struct work_struct *work)
if (!substream || !atomic_read(&tascam->midi_out_active)) if (!substream || !atomic_read(&tascam->midi_out_active))
return; return;
while (snd_rawmidi_transmit_peek(substream, (u8[]){ 0 }, 1) == 1) { while (snd_rawmidi_transmit_peek(substream, (u8[]){0}, 1) == 1) {
unsigned long flags; unsigned long flags;
int urb_index; int urb_index;
struct urb *urb; struct urb *urb;
@ -277,12 +273,10 @@ static void tascam_midi_out_work_handler(struct work_struct *work)
usb_get_urb(urb); usb_get_urb(urb);
usb_anchor_urb(urb, &tascam->midi_out_anchor); usb_anchor_urb(urb, &tascam->midi_out_anchor);
if (usb_submit_urb(urb, GFP_KERNEL) < 0) { if (usb_submit_urb(urb, GFP_KERNEL) < 0) {
dev_err_ratelimited( dev_err_ratelimited(tascam->card->dev,
tascam->card->dev,
"Failed to submit MIDI OUT URB %d\n", urb_index); "Failed to submit MIDI OUT URB %d\n", urb_index);
spin_lock_irqsave(&tascam->midi_out_lock, flags); spin_lock_irqsave(&tascam->midi_out_lock, flags);
clear_bit(urb_index, clear_bit(urb_index, &tascam->midi_out_urbs_in_flight);
&tascam->midi_out_urbs_in_flight);
spin_unlock_irqrestore(&tascam->midi_out_lock, flags); spin_unlock_irqrestore(&tascam->midi_out_lock, flags);
usb_unanchor_urb(urb); usb_unanchor_urb(urb);
usb_put_urb(urb); usb_put_urb(urb);
@ -291,7 +285,6 @@ static void tascam_midi_out_work_handler(struct work_struct *work)
} }
} }
/** /**
* tascam_midi_out_open() - Opens the MIDI output substream. * tascam_midi_out_open() - Opens the MIDI output substream.
* @substream: The ALSA rawmidi substream to open. * @substream: The ALSA rawmidi substream to open.
@ -301,8 +294,7 @@ static void tascam_midi_out_work_handler(struct work_struct *work)
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_midi_out_open(struct snd_rawmidi_substream *substream) static int tascam_midi_out_open(struct snd_rawmidi_substream *substream) {
{
struct tascam_card *tascam = substream->rmidi->private_data; struct tascam_card *tascam = substream->rmidi->private_data;
tascam->midi_out_substream = substream; tascam->midi_out_substream = substream;
@ -317,8 +309,7 @@ static int tascam_midi_out_open(struct snd_rawmidi_substream *substream)
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_midi_out_close(struct snd_rawmidi_substream *substream) static int tascam_midi_out_close(struct snd_rawmidi_substream *substream) {
{
return 0; return 0;
} }
@ -329,8 +320,7 @@ static int tascam_midi_out_close(struct snd_rawmidi_substream *substream)
* This function cancels any pending MIDI output work and kills all * This function cancels any pending MIDI output work and kills all
* anchored MIDI output URBs, ensuring all data is sent or discarded. * anchored MIDI output URBs, ensuring all data is sent or discarded.
*/ */
static void tascam_midi_out_drain(struct snd_rawmidi_substream *substream) static void tascam_midi_out_drain(struct snd_rawmidi_substream *substream) {
{
struct tascam_card *tascam = substream->rmidi->private_data; struct tascam_card *tascam = substream->rmidi->private_data;
cancel_work_sync(&tascam->midi_out_work); cancel_work_sync(&tascam->midi_out_work);
@ -345,8 +335,8 @@ static void tascam_midi_out_drain(struct snd_rawmidi_substream *substream)
* This function starts or stops the MIDI output workqueue based on the * This function starts or stops the MIDI output workqueue based on the
* 'up' parameter. * 'up' parameter.
*/ */
static void tascam_midi_out_trigger(struct snd_rawmidi_substream *substream, int up) static void tascam_midi_out_trigger(struct snd_rawmidi_substream *substream,
{ int up) {
struct tascam_card *tascam = substream->rmidi->private_data; struct tascam_card *tascam = substream->rmidi->private_data;
if (up) { if (up) {
@ -360,8 +350,8 @@ static void tascam_midi_out_trigger(struct snd_rawmidi_substream *substream, int
/** /**
* tascam_midi_out_ops - ALSA rawmidi operations for MIDI output. * tascam_midi_out_ops - ALSA rawmidi operations for MIDI output.
* *
* This structure defines the callback functions for MIDI output stream operations, * This structure defines the callback functions for MIDI output stream
* including open, close, trigger, and drain. * operations, including open, close, trigger, and drain.
*/ */
static const struct snd_rawmidi_ops tascam_midi_out_ops = { static const struct snd_rawmidi_ops tascam_midi_out_ops = {
.open = tascam_midi_out_open, .open = tascam_midi_out_open,
@ -376,19 +366,21 @@ static const struct snd_rawmidi_ops tascam_midi_out_ops = {
* *
* Return: 0 on success, or a negative error code on failure. * Return: 0 on success, or a negative error code on failure.
*/ */
int tascam_create_midi(struct tascam_card *tascam) int tascam_create_midi(struct tascam_card *tascam) {
{
int err; int err;
err = snd_rawmidi_new(tascam->card, "US144MKII MIDI", 0, 1, 1, &tascam->rmidi); err =
snd_rawmidi_new(tascam->card, "US144MKII MIDI", 0, 1, 1, &tascam->rmidi);
if (err < 0) if (err < 0)
return err; return err;
strscpy(tascam->rmidi->name, "US144MKII MIDI", sizeof(tascam->rmidi->name)); strscpy(tascam->rmidi->name, "US144MKII MIDI", sizeof(tascam->rmidi->name));
tascam->rmidi->private_data = tascam; tascam->rmidi->private_data = tascam;
snd_rawmidi_set_ops(tascam->rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &tascam_midi_in_ops); snd_rawmidi_set_ops(tascam->rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
snd_rawmidi_set_ops(tascam->rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &tascam_midi_out_ops); &tascam_midi_in_ops);
snd_rawmidi_set_ops(tascam->rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
&tascam_midi_out_ops);
tascam->rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT | tascam->rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT |
SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_OUTPUT |

View File

@ -15,34 +15,28 @@
* which helps the driver adjust the packet size dynamically to match the * which helps the driver adjust the packet size dynamically to match the
* device's consumption rate. * device's consumption rate.
*/ */
static const unsigned int patterns_48khz[5][8] = { static const unsigned int patterns_48khz[5][8] = {{5, 6, 6, 6, 6, 6, 6, 6},
{5, 6, 6, 6, 6, 6, 6, 6},
{6, 6, 6, 6, 6, 6, 6, 6}, {6, 6, 6, 6, 6, 6, 6, 6},
{6, 6, 6, 6, 6, 6, 6, 6}, {6, 6, 6, 6, 6, 6, 6, 6},
{6, 6, 6, 7, 6, 6, 6, 6}, {6, 6, 6, 7, 6, 6, 6, 6},
{7, 6, 6, 7, 6, 6, 7, 6} {7, 6, 6, 7, 6, 6, 7, 6}};
};
static const unsigned int patterns_96khz[5][8] = { static const unsigned int patterns_96khz[5][8] = {
{11, 12, 12, 12, 12, 12, 12, 12}, {11, 12, 12, 12, 12, 12, 12, 12},
{12, 12, 12, 12, 12, 12, 12, 12}, {12, 12, 12, 12, 12, 12, 12, 12},
{12, 12, 12, 12, 12, 12, 12, 12}, {12, 12, 12, 12, 12, 12, 12, 12},
{12, 12, 13, 12, 12, 12, 12, 12}, {12, 12, 13, 12, 12, 12, 12, 12},
{13, 12, 12, 13, 12, 12, 13, 12} {13, 12, 12, 13, 12, 12, 13, 12}};
};
static const unsigned int patterns_88khz[5][8] = { static const unsigned int patterns_88khz[5][8] = {
{10, 11, 11, 11, 11, 11, 11, 11}, {10, 11, 11, 11, 11, 11, 11, 11},
{11, 11, 11, 11, 11, 11, 11, 11}, {11, 11, 11, 11, 11, 11, 11, 11},
{11, 11, 11, 11, 11, 11, 11, 11}, {11, 11, 11, 11, 11, 11, 11, 11},
{11, 11, 12, 11, 11, 11, 11, 11}, {11, 11, 12, 11, 11, 11, 11, 11},
{12, 11, 11, 12, 11, 11, 12, 11} {12, 11, 11, 12, 11, 11, 12, 11}};
}; static const unsigned int patterns_44khz[5][8] = {{5, 5, 5, 5, 5, 5, 5, 6},
static const unsigned int patterns_44khz[5][8] = {
{5, 5, 5, 5, 5, 5, 5, 6},
{5, 5, 5, 6, 5, 5, 5, 6}, {5, 5, 5, 6, 5, 5, 5, 6},
{5, 5, 6, 5, 6, 5, 5, 6}, {5, 5, 6, 5, 6, 5, 5, 6},
{5, 6, 5, 6, 5, 6, 5, 6}, {5, 6, 5, 6, 5, 6, 5, 6},
{6, 6, 6, 6, 6, 6, 6, 5} {6, 6, 6, 6, 6, 6, 6, 5}};
};
const struct snd_pcm_hardware tascam_pcm_hw = { const struct snd_pcm_hardware tascam_pcm_hw = {
.info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
@ -51,13 +45,15 @@ const struct snd_pcm_hardware tascam_pcm_hw = {
.formats = SNDRV_PCM_FMTBIT_S24_3LE, .formats = SNDRV_PCM_FMTBIT_S24_3LE,
.rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000), SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000),
.rate_min = 44100, .rate_max = 96000, .rate_min = 44100,
.rate_max = 96000,
.channels_min = NUM_CHANNELS, .channels_min = NUM_CHANNELS,
.channels_max = NUM_CHANNELS, .channels_max = NUM_CHANNELS,
.buffer_bytes_max = 1024 * 1024, .buffer_bytes_max = 1024 * 1024,
.period_bytes_min = 48 * BYTES_PER_FRAME, .period_bytes_min = 48 * BYTES_PER_FRAME,
.period_bytes_max = 1024 * BYTES_PER_FRAME, .period_bytes_max = 1024 * BYTES_PER_FRAME,
.periods_min = 2, .periods_max = 1024, .periods_min = 2,
.periods_max = 1024,
}; };
/** /**
@ -68,9 +64,8 @@ const struct snd_pcm_hardware tascam_pcm_hw = {
* @frames: Number of frames to process. * @frames: Number of frames to process.
*/ */
void process_playback_routing_us144mkii(struct tascam_card *tascam, void process_playback_routing_us144mkii(struct tascam_card *tascam,
const u8 *src_buffer, const u8 *src_buffer, u8 *dst_buffer,
u8 *dst_buffer, size_t frames) size_t frames) {
{
size_t f; size_t f;
const u8 *src_12, *src_34; const u8 *src_12, *src_34;
u8 *dst_line, *dst_digital; u8 *dst_line, *dst_digital;
@ -103,8 +98,7 @@ void process_playback_routing_us144mkii(struct tascam_card *tascam,
*/ */
void process_capture_routing_us144mkii(struct tascam_card *tascam, void process_capture_routing_us144mkii(struct tascam_card *tascam,
const s32 *decoded_block, const s32 *decoded_block,
s32 *routed_block) s32 *routed_block) {
{
int f; int f;
const s32 *src_frame; const s32 *src_frame;
s32 *dst_frame; s32 *dst_frame;
@ -143,8 +137,7 @@ void process_capture_routing_us144mkii(struct tascam_card *tascam,
* *
* Return: 0 on success, or a negative error code on failure. * Return: 0 on success, or a negative error code on failure.
*/ */
int us144mkii_configure_device_for_rate(struct tascam_card *tascam, int rate) int us144mkii_configure_device_for_rate(struct tascam_card *tascam, int rate) {
{
struct usb_device *dev = tascam->dev; struct usb_device *dev = tascam->dev;
u8 *rate_payload_buf; u8 *rate_payload_buf;
u16 rate_vendor_wValue; u16 rate_vendor_wValue;
@ -184,31 +177,49 @@ int us144mkii_configure_device_for_rate(struct tascam_card *tascam, int rate)
dev_info(&dev->dev, "Configuring device for %d Hz\n", rate); dev_info(&dev->dev, "Configuring device for %d Hz\n", rate);
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_MODE_CONTROL, RT_H2D_VENDOR_DEV, MODE_VAL_CONFIG, 0x0000, NULL, 0, USB_CTRL_TIMEOUT_MS); err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_MODE_CONTROL,
RT_H2D_VENDOR_DEV, MODE_VAL_CONFIG, 0x0000, NULL, 0,
USB_CTRL_TIMEOUT_MS);
if (err < 0) if (err < 0)
goto fail; 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); 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) if (err < 0)
goto fail; 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, USB_CTRL_TIMEOUT_MS); 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, USB_CTRL_TIMEOUT_MS);
if (err < 0) if (err < 0)
goto fail; goto fail;
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_REGISTER_WRITE, RT_H2D_VENDOR_DEV, REG_ADDR_UNKNOWN_0D, REG_VAL_ENABLE, NULL, 0, USB_CTRL_TIMEOUT_MS); err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_REGISTER_WRITE,
RT_H2D_VENDOR_DEV, REG_ADDR_UNKNOWN_0D, REG_VAL_ENABLE,
NULL, 0, USB_CTRL_TIMEOUT_MS);
if (err < 0) if (err < 0)
goto fail; goto fail;
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_REGISTER_WRITE, RT_H2D_VENDOR_DEV, REG_ADDR_UNKNOWN_0E, REG_VAL_ENABLE, NULL, 0, USB_CTRL_TIMEOUT_MS); err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_REGISTER_WRITE,
RT_H2D_VENDOR_DEV, REG_ADDR_UNKNOWN_0E, REG_VAL_ENABLE,
NULL, 0, USB_CTRL_TIMEOUT_MS);
if (err < 0) if (err < 0)
goto fail; goto fail;
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_REGISTER_WRITE, RT_H2D_VENDOR_DEV, REG_ADDR_UNKNOWN_0F, REG_VAL_ENABLE, NULL, 0, USB_CTRL_TIMEOUT_MS); err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_REGISTER_WRITE,
RT_H2D_VENDOR_DEV, REG_ADDR_UNKNOWN_0F, REG_VAL_ENABLE,
NULL, 0, USB_CTRL_TIMEOUT_MS);
if (err < 0) if (err < 0)
goto fail; goto fail;
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_REGISTER_WRITE, RT_H2D_VENDOR_DEV, rate_vendor_wValue, REG_VAL_ENABLE, NULL, 0, USB_CTRL_TIMEOUT_MS); err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_REGISTER_WRITE,
RT_H2D_VENDOR_DEV, rate_vendor_wValue, REG_VAL_ENABLE,
NULL, 0, USB_CTRL_TIMEOUT_MS);
if (err < 0) if (err < 0)
goto fail; goto fail;
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_REGISTER_WRITE, RT_H2D_VENDOR_DEV, REG_ADDR_UNKNOWN_11, REG_VAL_ENABLE, NULL, 0, USB_CTRL_TIMEOUT_MS); err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_REGISTER_WRITE,
RT_H2D_VENDOR_DEV, REG_ADDR_UNKNOWN_11, REG_VAL_ENABLE,
NULL, 0, USB_CTRL_TIMEOUT_MS);
if (err < 0) if (err < 0)
goto fail; goto fail;
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_MODE_CONTROL, RT_H2D_VENDOR_DEV, MODE_VAL_STREAM_START, 0x0000, NULL, 0, USB_CTRL_TIMEOUT_MS); err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_MODE_CONTROL,
RT_H2D_VENDOR_DEV, MODE_VAL_STREAM_START, 0x0000, NULL,
0, USB_CTRL_TIMEOUT_MS);
if (err < 0) if (err < 0)
goto fail; goto fail;
@ -216,7 +227,8 @@ int us144mkii_configure_device_for_rate(struct tascam_card *tascam, int rate)
return 0; return 0;
fail: fail:
dev_err(&dev->dev, "Device configuration failed at rate %d with error %d\n", rate, err); dev_err(&dev->dev, "Device configuration failed at rate %d with error %d\n",
rate, err);
kfree(rate_payload_buf); kfree(rate_payload_buf);
return err; return err;
} }
@ -234,8 +246,7 @@ fail:
* Return: 0 on success, or a negative error code on failure. * Return: 0 on success, or a negative error code on failure.
*/ */
int tascam_pcm_hw_params(struct snd_pcm_substream *substream, int tascam_pcm_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params) struct snd_pcm_hw_params *params) {
{
struct tascam_card *tascam = snd_pcm_substream_chip(substream); struct tascam_card *tascam = snd_pcm_substream_chip(substream);
int err; int err;
unsigned int rate = params_rate(params); unsigned int rate = params_rate(params);
@ -291,16 +302,15 @@ int tascam_pcm_hw_params(struct snd_pcm_substream *substream,
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
int tascam_pcm_hw_free(struct snd_pcm_substream *substream) int tascam_pcm_hw_free(struct snd_pcm_substream *substream) {
{
return snd_pcm_lib_free_pages(substream); return snd_pcm_lib_free_pages(substream);
} }
/** /**
* tascam_pcm_trigger() - Triggers the start or stop of PCM streams. * tascam_pcm_trigger() - Triggers the start or stop of PCM streams.
* @substream: The ALSA PCM substream. * @substream: The ALSA PCM substream.
* @cmd: The trigger command (e.g., SNDRV_PCM_TRIGGER_START, SNDRV_PCM_TRIGGER_STOP). * @cmd: The trigger command (e.g., SNDRV_PCM_TRIGGER_START,
* SNDRV_PCM_TRIGGER_STOP).
* *
* This function handles starting and stopping of playback and capture streams * This function handles starting and stopping of playback and capture streams
* by submitting or killing the associated URBs. It ensures that both streams * by submitting or killing the associated URBs. It ensures that both streams
@ -308,8 +318,7 @@ int tascam_pcm_hw_free(struct snd_pcm_substream *substream)
* *
* Return: 0 on success, or a negative error code on failure. * Return: 0 on success, or a negative error code on failure.
*/ */
int tascam_pcm_trigger(struct snd_pcm_substream *substream, int cmd) int tascam_pcm_trigger(struct snd_pcm_substream *substream, int cmd) {
{
struct tascam_card *tascam = snd_pcm_substream_chip(substream); struct tascam_card *tascam = snd_pcm_substream_chip(substream);
unsigned long flags; unsigned long flags;
int err = 0; int err = 0;
@ -383,8 +392,9 @@ int tascam_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
} }
return 0; return 0;
start_rollback: start_rollback:
dev_err(tascam->card->dev, "Failed to submit URBs to start stream: %d\n", err); dev_err(tascam->card->dev, "Failed to submit URBs to start stream: %d\n",
err);
do_stop = true; do_stop = true;
} }
@ -404,15 +414,13 @@ start_rollback:
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
int tascam_init_pcm(struct snd_pcm *pcm) int tascam_init_pcm(struct snd_pcm *pcm) {
{
struct tascam_card *tascam = pcm->private_data; struct tascam_card *tascam = pcm->private_data;
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &tascam_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &tascam_playback_ops);
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &tascam_capture_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &tascam_capture_ops);
snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
tascam->dev->dev.parent, tascam->dev->dev.parent, 64 * 1024,
64 * 1024,
tascam_pcm_hw.buffer_bytes_max); tascam_pcm_hw.buffer_bytes_max);
INIT_WORK(&tascam->capture_work, tascam_capture_work_handler); INIT_WORK(&tascam->capture_work, tascam_capture_work_handler);

View File

@ -96,7 +96,9 @@ int us144mkii_configure_device_for_rate(struct tascam_card *tascam, int rate);
* @dst_buffer: Buffer to be filled for the USB device. * @dst_buffer: Buffer to be filled for the USB device.
* @frames: Number of frames to process. * @frames: Number of frames to process.
*/ */
void process_playback_routing_us144mkii(struct tascam_card *tascam, const u8 *src_buffer, u8 *dst_buffer, size_t frames); 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 * process_capture_routing_us144mkii() - Apply capture routing matrix
@ -104,7 +106,9 @@ void process_playback_routing_us144mkii(struct tascam_card *tascam, const u8 *sr
* @decoded_block: Buffer containing 4 channels of S32LE decoded audio. * @decoded_block: Buffer containing 4 channels of S32LE decoded audio.
* @routed_block: Buffer to be filled for ALSA. * @routed_block: Buffer to be filled for ALSA.
*/ */
void process_capture_routing_us144mkii(struct tascam_card *tascam, const s32 *decoded_block, s32 *routed_block); 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. * tascam_pcm_hw_params() - Configures hardware parameters for PCM streams.
@ -118,7 +122,8 @@ void process_capture_routing_us144mkii(struct tascam_card *tascam, const s32 *de
* *
* Return: 0 on success, or a negative error code on failure. * Return: 0 on success, or a negative error code on failure.
*/ */
int tascam_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params); int tascam_pcm_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params);
/** /**
* tascam_pcm_hw_free() - Frees hardware parameters for PCM streams. * tascam_pcm_hw_free() - Frees hardware parameters for PCM streams.
@ -133,7 +138,8 @@ int tascam_pcm_hw_free(struct snd_pcm_substream *substream);
/** /**
* tascam_pcm_trigger() - Triggers the start or stop of PCM streams. * tascam_pcm_trigger() - Triggers the start or stop of PCM streams.
* @substream: The ALSA PCM substream. * @substream: The ALSA PCM substream.
* @cmd: The trigger command (e.g., SNDRV_PCM_TRIGGER_START, SNDRV_PCM_TRIGGER_STOP). * @cmd: The trigger command (e.g., SNDRV_PCM_TRIGGER_START,
* SNDRV_PCM_TRIGGER_STOP).
* *
* This function handles starting and stopping of playback and capture streams * This function handles starting and stopping of playback and capture streams
* by submitting or killing the associated URBs. It ensures that both streams * by submitting or killing the associated URBs. It ensures that both streams

View File

@ -12,8 +12,7 @@
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_playback_open(struct snd_pcm_substream *substream) static int tascam_playback_open(struct snd_pcm_substream *substream) {
{
struct tascam_card *tascam = snd_pcm_substream_chip(substream); struct tascam_card *tascam = snd_pcm_substream_chip(substream);
substream->runtime->hw = tascam_pcm_hw; substream->runtime->hw = tascam_pcm_hw;
@ -32,8 +31,7 @@ static int tascam_playback_open(struct snd_pcm_substream *substream)
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_playback_close(struct snd_pcm_substream *substream) static int tascam_playback_close(struct snd_pcm_substream *substream) {
{
struct tascam_card *tascam = snd_pcm_substream_chip(substream); struct tascam_card *tascam = snd_pcm_substream_chip(substream);
tascam->playback_substream = NULL; tascam->playback_substream = NULL;
@ -51,8 +49,7 @@ static int tascam_playback_close(struct snd_pcm_substream *substream)
* *
* Return: 0 on success. * Return: 0 on success.
*/ */
static int tascam_playback_prepare(struct snd_pcm_substream *substream) static int tascam_playback_prepare(struct snd_pcm_substream *substream) {
{
struct tascam_card *tascam = snd_pcm_substream_chip(substream); struct tascam_card *tascam = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
int i, u; int i, u;
@ -114,8 +111,8 @@ static int tascam_playback_prepare(struct snd_pcm_substream *substream)
* *
* Return: The current playback pointer position in frames. * Return: The current playback pointer position in frames.
*/ */
static snd_pcm_uframes_t tascam_playback_pointer(struct snd_pcm_substream *substream) static snd_pcm_uframes_t
{ tascam_playback_pointer(struct snd_pcm_substream *substream) {
struct tascam_card *tascam = snd_pcm_substream_chip(substream); struct tascam_card *tascam = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
u64 pos; u64 pos;
@ -159,8 +156,7 @@ const struct snd_pcm_ops tascam_playback_ops = {
* copies the audio data from the ALSA ring buffer (applying routing), and * copies the audio data from the ALSA ring buffer (applying routing), and
* resubmits the URB. * resubmits the URB.
*/ */
void playback_urb_complete(struct urb *urb) void playback_urb_complete(struct urb *urb) {
{
struct tascam_card *tascam = urb->context; struct tascam_card *tascam = urb->context;
struct snd_pcm_substream *substream; struct snd_pcm_substream *substream;
struct snd_pcm_runtime *runtime; struct snd_pcm_runtime *runtime;
@ -172,9 +168,10 @@ void playback_urb_complete(struct urb *urb)
int ret, i; int ret, i;
if (urb->status) { if (urb->status) {
if (urb->status != -ENOENT && urb->status != -ECONNRESET && urb->status != -ESHUTDOWN && if (urb->status != -ENOENT && urb->status != -ECONNRESET &&
urb->status != -ENODEV) urb->status != -ESHUTDOWN && urb->status != -ENODEV)
dev_err_ratelimited(tascam->card->dev, "Playback URB failed: %d\n", urb->status); dev_err_ratelimited(tascam->card->dev, "Playback URB failed: %d\n",
urb->status);
goto out; goto out;
} }
if (!tascam || !atomic_read(&tascam->playback_active)) if (!tascam || !atomic_read(&tascam->playback_active))
@ -192,8 +189,11 @@ void playback_urb_complete(struct urb *urb)
size_t bytes_for_packet; size_t bytes_for_packet;
if (tascam->feedback_synced) { if (tascam->feedback_synced) {
frames_for_packet = tascam->feedback_accumulator_pattern[tascam->feedback_pattern_out_idx]; frames_for_packet =
tascam->feedback_pattern_out_idx = (tascam->feedback_pattern_out_idx + 1) % FEEDBACK_ACCUMULATOR_SIZE; tascam
->feedback_accumulator_pattern[tascam->feedback_pattern_out_idx];
tascam->feedback_pattern_out_idx =
(tascam->feedback_pattern_out_idx + 1) % FEEDBACK_ACCUMULATOR_SIZE;
} else { } else {
frames_for_packet = runtime->rate / 8000; frames_for_packet = runtime->rate / 8000;
} }
@ -207,7 +207,8 @@ void playback_urb_complete(struct urb *urb)
offset_frames = tascam->driver_playback_pos; offset_frames = tascam->driver_playback_pos;
frames_to_copy = bytes_to_frames(runtime, total_bytes_for_urb); frames_to_copy = bytes_to_frames(runtime, total_bytes_for_urb);
tascam->driver_playback_pos = (offset_frames + frames_to_copy) % runtime->buffer_size; tascam->driver_playback_pos =
(offset_frames + frames_to_copy) % runtime->buffer_size;
spin_unlock_irqrestore(&tascam->lock, flags); spin_unlock_irqrestore(&tascam->lock, flags);
@ -217,17 +218,20 @@ void playback_urb_complete(struct urb *urb)
/* Handle ring buffer wrap-around */ /* Handle ring buffer wrap-around */
if (offset_frames + frames_to_copy > runtime->buffer_size) { if (offset_frames + frames_to_copy > runtime->buffer_size) {
size_t first_chunk_bytes = frames_to_bytes(runtime, runtime->buffer_size - offset_frames); size_t first_chunk_bytes =
frames_to_bytes(runtime, runtime->buffer_size - offset_frames);
size_t second_chunk_bytes = total_bytes_for_urb - first_chunk_bytes; size_t second_chunk_bytes = total_bytes_for_urb - first_chunk_bytes;
memcpy(dst_buf, src_buf, first_chunk_bytes); memcpy(dst_buf, src_buf, first_chunk_bytes);
memcpy(dst_buf + first_chunk_bytes, runtime->dma_area, second_chunk_bytes); memcpy(dst_buf + first_chunk_bytes, runtime->dma_area,
second_chunk_bytes);
} else { } else {
memcpy(dst_buf, src_buf, total_bytes_for_urb); memcpy(dst_buf, src_buf, total_bytes_for_urb);
} }
/* Apply routing to the contiguous data in our routing buffer */ /* Apply routing to the contiguous data in our routing buffer */
process_playback_routing_us144mkii(tascam, dst_buf, dst_buf, frames_to_copy); process_playback_routing_us144mkii(tascam, dst_buf, dst_buf,
frames_to_copy);
memcpy(urb->transfer_buffer, dst_buf, total_bytes_for_urb); memcpy(urb->transfer_buffer, dst_buf, total_bytes_for_urb);
} }
@ -236,7 +240,8 @@ void playback_urb_complete(struct urb *urb)
usb_anchor_urb(urb, &tascam->playback_anchor); usb_anchor_urb(urb, &tascam->playback_anchor);
ret = usb_submit_urb(urb, GFP_ATOMIC); ret = usb_submit_urb(urb, GFP_ATOMIC);
if (ret < 0) { if (ret < 0) {
dev_err_ratelimited(tascam->card->dev, "Failed to resubmit playback URB: %d\n", ret); dev_err_ratelimited(tascam->card->dev,
"Failed to resubmit playback URB: %d\n", ret);
usb_unanchor_urb(urb); usb_unanchor_urb(urb);
usb_put_urb(urb); usb_put_urb(urb);
} }
@ -255,8 +260,7 @@ out:
* streams in sync. It then calls snd_pcm_period_elapsed if necessary and * streams in sync. It then calls snd_pcm_period_elapsed if necessary and
* resubmits itself. * resubmits itself.
*/ */
void feedback_urb_complete(struct urb *urb) void feedback_urb_complete(struct urb *urb) {
{
struct tascam_card *tascam = urb->context; struct tascam_card *tascam = urb->context;
struct snd_pcm_substream *playback_ss, *capture_ss; struct snd_pcm_substream *playback_ss, *capture_ss;
struct snd_pcm_runtime *playback_rt, *capture_rt; struct snd_pcm_runtime *playback_rt, *capture_rt;
@ -268,9 +272,10 @@ void feedback_urb_complete(struct urb *urb)
bool capture_period_elapsed = false; bool capture_period_elapsed = false;
if (urb->status) { if (urb->status) {
if (urb->status != -ENOENT && urb->status != -ECONNRESET && urb->status != -ESHUTDOWN && if (urb->status != -ENOENT && urb->status != -ECONNRESET &&
urb->status != -ENODEV) urb->status != -ESHUTDOWN && urb->status != -ENODEV)
dev_err_ratelimited(tascam->card->dev, "Feedback URB failed: %d\n", urb->status); dev_err_ratelimited(tascam->card->dev, "Feedback URB failed: %d\n",
urb->status);
goto out; goto out;
} }
if (!tascam || !atomic_read(&tascam->playback_active)) if (!tascam || !atomic_read(&tascam->playback_active))
@ -300,16 +305,20 @@ void feedback_urb_complete(struct urb *urb)
urb->iso_frame_desc[p].actual_length >= 1); urb->iso_frame_desc[p].actual_length >= 1);
if (packet_ok) if (packet_ok)
feedback_value = *((u8 *)urb->transfer_buffer + urb->iso_frame_desc[p].offset); feedback_value =
*((u8 *)urb->transfer_buffer + urb->iso_frame_desc[p].offset);
if (packet_ok && feedback_value >= tascam->feedback_base_value && if (packet_ok && feedback_value >= tascam->feedback_base_value &&
feedback_value <= tascam->feedback_max_value) { feedback_value <= tascam->feedback_max_value) {
pattern = tascam->feedback_patterns[feedback_value - tascam->feedback_base_value]; pattern =
tascam
->feedback_patterns[feedback_value - tascam->feedback_base_value];
tascam->feedback_consecutive_errors = 0; tascam->feedback_consecutive_errors = 0;
int i; int i;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
unsigned int in_idx = (tascam->feedback_pattern_in_idx + i) % FEEDBACK_ACCUMULATOR_SIZE; unsigned int in_idx =
(tascam->feedback_pattern_in_idx + i) % FEEDBACK_ACCUMULATOR_SIZE;
tascam->feedback_accumulator_pattern[in_idx] = pattern[i]; tascam->feedback_accumulator_pattern[in_idx] = pattern[i];
total_frames_in_urb += pattern[i]; total_frames_in_urb += pattern[i];
@ -320,8 +329,10 @@ void feedback_urb_complete(struct urb *urb)
if (tascam->feedback_synced) { if (tascam->feedback_synced) {
tascam->feedback_consecutive_errors++; tascam->feedback_consecutive_errors++;
if (tascam->feedback_consecutive_errors > FEEDBACK_SYNC_LOSS_THRESHOLD) { if (tascam->feedback_consecutive_errors >
dev_err(tascam->card->dev, "Fatal: Feedback sync lost. Stopping stream.\n"); FEEDBACK_SYNC_LOSS_THRESHOLD) {
dev_err(tascam->card->dev,
"Fatal: Feedback sync lost. Stopping stream.\n");
if (playback_ss) if (playback_ss)
snd_pcm_stop(playback_ss, SNDRV_PCM_STATE_XRUN); snd_pcm_stop(playback_ss, SNDRV_PCM_STATE_XRUN);
if (capture_ss) if (capture_ss)
@ -331,24 +342,29 @@ void feedback_urb_complete(struct urb *urb)
} }
} }
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
unsigned int in_idx = (tascam->feedback_pattern_in_idx + i) % FEEDBACK_ACCUMULATOR_SIZE; unsigned int in_idx =
(tascam->feedback_pattern_in_idx + i) % FEEDBACK_ACCUMULATOR_SIZE;
tascam->feedback_accumulator_pattern[in_idx] = nominal_frames; tascam->feedback_accumulator_pattern[in_idx] = nominal_frames;
total_frames_in_urb += nominal_frames; total_frames_in_urb += nominal_frames;
} }
} }
tascam->feedback_pattern_in_idx = (tascam->feedback_pattern_in_idx + 8) % FEEDBACK_ACCUMULATOR_SIZE; tascam->feedback_pattern_in_idx =
(tascam->feedback_pattern_in_idx + 8) % FEEDBACK_ACCUMULATOR_SIZE;
} }
new_in_idx = tascam->feedback_pattern_in_idx; new_in_idx = tascam->feedback_pattern_in_idx;
if (!tascam->feedback_synced) { if (!tascam->feedback_synced) {
unsigned int out_idx = tascam->feedback_pattern_out_idx; unsigned int out_idx = tascam->feedback_pattern_out_idx;
bool is_ahead = (new_in_idx - out_idx) % FEEDBACK_ACCUMULATOR_SIZE < (FEEDBACK_ACCUMULATOR_SIZE / 2); bool is_ahead = (new_in_idx - out_idx) % FEEDBACK_ACCUMULATOR_SIZE <
bool was_behind = (old_in_idx - out_idx) % FEEDBACK_ACCUMULATOR_SIZE >= (FEEDBACK_ACCUMULATOR_SIZE / 2); (FEEDBACK_ACCUMULATOR_SIZE / 2);
bool was_behind = (old_in_idx - out_idx) % FEEDBACK_ACCUMULATOR_SIZE >=
(FEEDBACK_ACCUMULATOR_SIZE / 2);
if (is_ahead && was_behind) { if (is_ahead && was_behind) {
dev_dbg(tascam->card->dev, "Sync Acquired! (in: %u, out: %u)\n", new_in_idx, out_idx); dev_dbg(tascam->card->dev, "Sync Acquired! (in: %u, out: %u)\n",
new_in_idx, out_idx);
tascam->feedback_synced = true; tascam->feedback_synced = true;
tascam->feedback_consecutive_errors = 0; tascam->feedback_consecutive_errors = 0;
} }
@ -361,7 +377,8 @@ void feedback_urb_complete(struct urb *urb)
} }
if (playback_rt->period_size > 0) { if (playback_rt->period_size > 0) {
u64 current_period = div_u64(tascam->playback_frames_consumed, playback_rt->period_size); u64 current_period =
div_u64(tascam->playback_frames_consumed, playback_rt->period_size);
if (current_period > tascam->last_period_pos) { if (current_period > tascam->last_period_pos) {
tascam->last_period_pos = current_period; tascam->last_period_pos = current_period;
@ -369,8 +386,10 @@ void feedback_urb_complete(struct urb *urb)
} }
} }
if (atomic_read(&tascam->capture_active) && capture_rt && capture_rt->period_size > 0) { if (atomic_read(&tascam->capture_active) && capture_rt &&
u64 current_capture_period = div_u64(tascam->capture_frames_processed, capture_rt->period_size); capture_rt->period_size > 0) {
u64 current_capture_period =
div_u64(tascam->capture_frames_processed, capture_rt->period_size);
if (current_capture_period > tascam->last_capture_period_pos) { if (current_capture_period > tascam->last_capture_period_pos) {
tascam->last_capture_period_pos = current_capture_period; tascam->last_capture_period_pos = current_capture_period;
@ -391,7 +410,8 @@ unlock_and_continue:
usb_anchor_urb(urb, &tascam->feedback_anchor); usb_anchor_urb(urb, &tascam->feedback_anchor);
ret = usb_submit_urb(urb, GFP_ATOMIC); ret = usb_submit_urb(urb, GFP_ATOMIC);
if (ret < 0) { if (ret < 0) {
dev_err_ratelimited(tascam->card->dev, "Failed to resubmit feedback URB: %d\n", ret); dev_err_ratelimited(tascam->card->dev,
"Failed to resubmit feedback URB: %d\n", ret);
usb_unanchor_urb(urb); usb_unanchor_urb(urb);
usb_put_urb(urb); usb_put_urb(urb);
} }