Merge pull request #4 from serifpersia/alsa-patch-set
for alsa subsystem
This commit is contained in:
commit
da22db278d
|
|
@ -119,7 +119,7 @@ void MainWindow::initUi() {
|
||||||
auto *infoGrid = new QGridLayout();
|
auto *infoGrid = new QGridLayout();
|
||||||
infoGrid->setSpacing(5);
|
infoGrid->setSpacing(5);
|
||||||
const QMap<QString, QString> infoData = {
|
const QMap<QString, QString> infoData = {
|
||||||
{"Driver Version:", "driver_version"}, {"Device:", "device"},
|
{"Device:", "device"},
|
||||||
{"Sample Width:", "sample_width"}, {"Sample Rate:", "sample_rate"}
|
{"Sample Width:", "sample_width"}, {"Sample Rate:", "sample_rate"}
|
||||||
};
|
};
|
||||||
int row = 0;
|
int row = 0;
|
||||||
|
|
@ -178,11 +178,7 @@ void MainWindow::initUi() {
|
||||||
auto *aboutButton = new QPushButton("About");
|
auto *aboutButton = new QPushButton("About");
|
||||||
aboutButton->setFixedSize(100, 30);
|
aboutButton->setFixedSize(100, 30);
|
||||||
connect(aboutButton, &QPushButton::clicked, this, &MainWindow::showAboutDialog);
|
connect(aboutButton, &QPushButton::clicked, this, &MainWindow::showAboutDialog);
|
||||||
auto *exitButton = new QPushButton("Exit");
|
|
||||||
exitButton->setFixedSize(100, 30);
|
|
||||||
connect(exitButton, &QPushButton::clicked, this, &QWidget::close);
|
|
||||||
buttonLayout->addWidget(aboutButton);
|
buttonLayout->addWidget(aboutButton);
|
||||||
buttonLayout->addWidget(exitButton);
|
|
||||||
middlePanel->addLayout(buttonLayout);
|
middlePanel->addLayout(buttonLayout);
|
||||||
|
|
||||||
topLevelLayout->addLayout(leftPanel, 1);
|
topLevelLayout->addLayout(leftPanel, 1);
|
||||||
|
|
@ -195,7 +191,6 @@ void MainWindow::initUi() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::loadDynamicSettings() {
|
void MainWindow::loadDynamicSettings() {
|
||||||
m_infoLabels["driver_version"]->setText(QString::fromStdString(m_alsa.readSysfsAttr("driver_version")));
|
|
||||||
m_infoLabels["device"]->setText("US-144 MKII");
|
m_infoLabels["device"]->setText("US-144 MKII");
|
||||||
m_infoLabels["sample_width"]->setText("24 bits");
|
m_infoLabels["sample_width"]->setText("24 bits");
|
||||||
|
|
||||||
|
|
@ -261,20 +256,15 @@ void MainWindow::showAboutDialog() {
|
||||||
auto *textLabel = new QLabel(m_aboutDialog);
|
auto *textLabel = new QLabel(m_aboutDialog);
|
||||||
textLabel->setTextFormat(Qt::RichText);
|
textLabel->setTextFormat(Qt::RichText);
|
||||||
textLabel->setOpenExternalLinks(true);
|
textLabel->setOpenExternalLinks(true);
|
||||||
textLabel->setText(QString("<b>TASCAM US-144MKII Control Panel</b><br>"
|
textLabel->setText(QString("<b>TASCAM US-144MKII Control Panel</b><br>"
|
||||||
"Driver Version: %1<br><br>"
|
"Copyright @serifpersia 2025<br><br>"
|
||||||
"Copyright @serifpersia 2025<br><br>"
|
"This application provides a graphical interface to control the TASCAM US-144MKII audio interface on Linux. "
|
||||||
"This application provides a graphical interface to control the TASCAM US-144MKII audio interface on Linux. "
|
"It utilizes the 'us144mkii' ALSA driver.<br><br>"
|
||||||
"It utilizes the 'us144mkii' ALSA driver.<br><br>"
|
"For more information, bug reports, and contributions, please visit the GitHub repository:<br>"
|
||||||
"For more information, bug reports, and contributions, please visit the GitHub repository:<br>"
|
"<a href='https://github.com/serifpersia/us144mkii'>https://github.com/serifpersia/us144mkii</a>"));
|
||||||
"<a href='https://github.com/serifpersia/us144mkii'>https://github.com/serifpersia/us144mkii</a>").arg(m_infoLabels["driver_version"]->text()));
|
|
||||||
textLabel->setWordWrap(true);
|
textLabel->setWordWrap(true);
|
||||||
|
|
||||||
auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
|
|
||||||
connect(buttonBox, &QDialogButtonBox::rejected, m_aboutDialog, &QDialog::close);
|
|
||||||
|
|
||||||
layout->addWidget(textLabel);
|
layout->addWidget(textLabel);
|
||||||
layout->addWidget(buttonBox);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_aboutDialog->show();
|
m_aboutDialog->show();
|
||||||
|
|
|
||||||
851
us144mkii.c
851
us144mkii.c
|
|
@ -26,266 +26,247 @@ 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;
|
|
||||||
|
|
||||||
/* --- Forward Declarations --- */
|
|
||||||
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);
|
||||||
static void tascam_disconnect(struct usb_interface *intf);
|
static void tascam_disconnect(struct usb_interface *intf);
|
||||||
static int tascam_suspend(struct usb_interface *intf, pm_message_t message);
|
static int tascam_suspend(struct usb_interface *intf, pm_message_t message);
|
||||||
static int tascam_resume(struct usb_interface *intf);
|
static int tascam_resume(struct usb_interface *intf);
|
||||||
|
|
||||||
/**
|
void tascam_free_urbs(struct tascam_card *tascam)
|
||||||
* driver_version_show() - Sysfs attribute to display the driver version.
|
{
|
||||||
* @dev: Pointer to the device structure.
|
int i;
|
||||||
* @attr: Pointer to the device attribute structure.
|
|
||||||
* @buf: Buffer to write the version string into.
|
|
||||||
*
|
|
||||||
* This function is a sysfs callback that provides the current driver version
|
|
||||||
* string to user-space when the 'driver_version' attribute is read.
|
|
||||||
*
|
|
||||||
* Return: The number of bytes written to the buffer.
|
|
||||||
*/
|
|
||||||
static ssize_t driver_version_show(struct device *dev,
|
|
||||||
struct device_attribute *attr, char *buf) {
|
|
||||||
return sysfs_emit(buf, "%s\n", DRIVER_VERSION);
|
|
||||||
}
|
|
||||||
static DEVICE_ATTR_RO(driver_version);
|
|
||||||
|
|
||||||
/**
|
usb_kill_anchored_urbs(&tascam->playback_anchor);
|
||||||
* tascam_free_urbs() - Free all allocated URBs and associated buffers.
|
for (i = 0; i < NUM_PLAYBACK_URBS; i++) {
|
||||||
* @tascam: the tascam_card instance
|
if (tascam->playback_urbs[i]) {
|
||||||
*
|
usb_free_coherent(
|
||||||
* This function kills, unlinks, and frees all playback, feedback,
|
tascam->dev, tascam->playback_urb_alloc_size,
|
||||||
* capture, and MIDI URBs, along with their transfer buffers and the
|
tascam->playback_urbs[i]->transfer_buffer,
|
||||||
* capture ring/decode buffers.
|
tascam->playback_urbs[i]->transfer_dma);
|
||||||
*/
|
usb_free_urb(tascam->playback_urbs[i]);
|
||||||
void tascam_free_urbs(struct tascam_card *tascam) {
|
tascam->playback_urbs[i] = NULL;
|
||||||
int i;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
usb_kill_anchored_urbs(&tascam->playback_anchor);
|
usb_kill_anchored_urbs(&tascam->feedback_anchor);
|
||||||
for (i = 0; i < NUM_PLAYBACK_URBS; i++) {
|
for (i = 0; i < NUM_FEEDBACK_URBS; i++) {
|
||||||
if (tascam->playback_urbs[i]) {
|
if (tascam->feedback_urbs[i]) {
|
||||||
usb_free_coherent(tascam->dev, tascam->playback_urb_alloc_size,
|
usb_free_coherent(
|
||||||
tascam->playback_urbs[i]->transfer_buffer,
|
tascam->dev, tascam->feedback_urb_alloc_size,
|
||||||
tascam->playback_urbs[i]->transfer_dma);
|
tascam->feedback_urbs[i]->transfer_buffer,
|
||||||
usb_free_urb(tascam->playback_urbs[i]);
|
tascam->feedback_urbs[i]->transfer_dma);
|
||||||
tascam->playback_urbs[i] = NULL;
|
usb_free_urb(tascam->feedback_urbs[i]);
|
||||||
}
|
tascam->feedback_urbs[i] = NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
usb_kill_anchored_urbs(&tascam->feedback_anchor);
|
usb_kill_anchored_urbs(&tascam->capture_anchor);
|
||||||
for (i = 0; i < NUM_FEEDBACK_URBS; i++) {
|
for (i = 0; i < NUM_CAPTURE_URBS; i++) {
|
||||||
if (tascam->feedback_urbs[i]) {
|
if (tascam->capture_urbs[i]) {
|
||||||
usb_free_coherent(tascam->dev, tascam->feedback_urb_alloc_size,
|
usb_free_coherent(
|
||||||
tascam->feedback_urbs[i]->transfer_buffer,
|
tascam->dev, tascam->capture_urb_alloc_size,
|
||||||
tascam->feedback_urbs[i]->transfer_dma);
|
tascam->capture_urbs[i]->transfer_buffer,
|
||||||
usb_free_urb(tascam->feedback_urbs[i]);
|
tascam->capture_urbs[i]->transfer_dma);
|
||||||
tascam->feedback_urbs[i] = NULL;
|
usb_free_urb(tascam->capture_urbs[i]);
|
||||||
}
|
tascam->capture_urbs[i] = NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
usb_kill_anchored_urbs(&tascam->capture_anchor);
|
usb_kill_anchored_urbs(&tascam->midi_in_anchor);
|
||||||
for (i = 0; i < NUM_CAPTURE_URBS; i++) {
|
for (i = 0; i < NUM_MIDI_IN_URBS; i++) {
|
||||||
if (tascam->capture_urbs[i]) {
|
if (tascam->midi_in_urbs[i]) {
|
||||||
usb_free_coherent(tascam->dev, tascam->capture_urb_alloc_size,
|
usb_free_coherent(
|
||||||
tascam->capture_urbs[i]->transfer_buffer,
|
tascam->dev, MIDI_IN_BUF_SIZE,
|
||||||
tascam->capture_urbs[i]->transfer_dma);
|
tascam->midi_in_urbs[i]->transfer_buffer,
|
||||||
usb_free_urb(tascam->capture_urbs[i]);
|
tascam->midi_in_urbs[i]->transfer_dma);
|
||||||
tascam->capture_urbs[i] = NULL;
|
usb_free_urb(tascam->midi_in_urbs[i]);
|
||||||
}
|
tascam->midi_in_urbs[i] = NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
usb_kill_anchored_urbs(&tascam->midi_in_anchor);
|
usb_kill_anchored_urbs(&tascam->midi_out_anchor);
|
||||||
for (i = 0; i < NUM_MIDI_IN_URBS; i++) {
|
for (i = 0; i < NUM_MIDI_OUT_URBS; i++) {
|
||||||
if (tascam->midi_in_urbs[i]) {
|
if (tascam->midi_out_urbs[i]) {
|
||||||
usb_free_coherent(tascam->dev, MIDI_IN_BUF_SIZE,
|
usb_free_coherent(
|
||||||
tascam->midi_in_urbs[i]->transfer_buffer,
|
tascam->dev, MIDI_OUT_BUF_SIZE,
|
||||||
tascam->midi_in_urbs[i]->transfer_dma);
|
tascam->midi_out_urbs[i]->transfer_buffer,
|
||||||
usb_free_urb(tascam->midi_in_urbs[i]);
|
tascam->midi_out_urbs[i]->transfer_dma);
|
||||||
tascam->midi_in_urbs[i] = NULL;
|
usb_free_urb(tascam->midi_out_urbs[i]);
|
||||||
}
|
tascam->midi_out_urbs[i] = NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
usb_kill_anchored_urbs(&tascam->midi_out_anchor);
|
kfree(tascam->capture_routing_buffer);
|
||||||
for (i = 0; i < NUM_MIDI_OUT_URBS; i++) {
|
tascam->capture_routing_buffer = NULL;
|
||||||
if (tascam->midi_out_urbs[i]) {
|
kfree(tascam->capture_decode_dst_block);
|
||||||
usb_free_coherent(tascam->dev, MIDI_OUT_BUF_SIZE,
|
tascam->capture_decode_dst_block = NULL;
|
||||||
tascam->midi_out_urbs[i]->transfer_buffer,
|
kfree(tascam->capture_decode_raw_block);
|
||||||
tascam->midi_out_urbs[i]->transfer_dma);
|
tascam->capture_decode_raw_block = NULL;
|
||||||
usb_free_urb(tascam->midi_out_urbs[i]);
|
kfree(tascam->capture_ring_buffer);
|
||||||
tascam->midi_out_urbs[i] = NULL;
|
tascam->capture_ring_buffer = NULL;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
kfree(tascam->capture_routing_buffer);
|
|
||||||
tascam->capture_routing_buffer = NULL;
|
|
||||||
kfree(tascam->capture_decode_dst_block);
|
|
||||||
tascam->capture_decode_dst_block = NULL;
|
|
||||||
kfree(tascam->capture_decode_raw_block);
|
|
||||||
tascam->capture_decode_raw_block = NULL;
|
|
||||||
kfree(tascam->capture_ring_buffer);
|
|
||||||
tascam->capture_ring_buffer = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
int tascam_alloc_urbs(struct tascam_card *tascam)
|
||||||
* tascam_alloc_urbs() - Allocate all URBs and associated buffers.
|
{
|
||||||
* @tascam: the tascam_card instance
|
int i;
|
||||||
*
|
size_t max_packet_size;
|
||||||
* This function allocates and initializes all URBs for playback, feedback,
|
|
||||||
* capture, and MIDI, as well as the necessary buffers for data processing.
|
|
||||||
*
|
|
||||||
* Return: 0 on success, or a negative error code on failure.
|
|
||||||
*/
|
|
||||||
int tascam_alloc_urbs(struct tascam_card *tascam) {
|
|
||||||
int i;
|
|
||||||
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 = max_packet_size * PLAYBACK_URB_PACKETS;
|
tascam->playback_urb_alloc_size =
|
||||||
|
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 = usb_alloc_urb(PLAYBACK_URB_PACKETS, GFP_KERNEL);
|
struct urb *urb =
|
||||||
|
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 =
|
urb->transfer_buffer = usb_alloc_coherent(
|
||||||
usb_alloc_coherent(tascam->dev, tascam->playback_urb_alloc_size,
|
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;
|
||||||
|
|
||||||
urb->dev = tascam->dev;
|
urb->dev = tascam->dev;
|
||||||
urb->pipe = usb_sndisocpipe(tascam->dev, EP_AUDIO_OUT);
|
urb->pipe = usb_sndisocpipe(tascam->dev, EP_AUDIO_OUT);
|
||||||
urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
|
urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
|
||||||
urb->interval = 1;
|
urb->interval = 1;
|
||||||
urb->context = tascam;
|
urb->context = tascam;
|
||||||
urb->complete = playback_urb_complete;
|
urb->complete = playback_urb_complete;
|
||||||
}
|
}
|
||||||
|
|
||||||
tascam->feedback_urb_alloc_size = FEEDBACK_PACKET_SIZE * FEEDBACK_URB_PACKETS;
|
tascam->feedback_urb_alloc_size =
|
||||||
|
FEEDBACK_PACKET_SIZE * FEEDBACK_URB_PACKETS;
|
||||||
|
|
||||||
for (i = 0; i < NUM_FEEDBACK_URBS; i++) {
|
for (i = 0; i < NUM_FEEDBACK_URBS; i++) {
|
||||||
struct urb *f_urb = usb_alloc_urb(FEEDBACK_URB_PACKETS, GFP_KERNEL);
|
struct urb *f_urb =
|
||||||
|
usb_alloc_urb(FEEDBACK_URB_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 =
|
f_urb->transfer_buffer = usb_alloc_coherent(
|
||||||
usb_alloc_coherent(tascam->dev, tascam->feedback_urb_alloc_size,
|
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 = usb_rcvisocpipe(tascam->dev, EP_PLAYBACK_FEEDBACK);
|
f_urb->pipe =
|
||||||
f_urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
|
usb_rcvisocpipe(tascam->dev, EP_PLAYBACK_FEEDBACK);
|
||||||
f_urb->interval = 4;
|
f_urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
|
||||||
f_urb->context = tascam;
|
f_urb->interval = 4;
|
||||||
f_urb->complete = feedback_urb_complete;
|
f_urb->context = tascam;
|
||||||
}
|
f_urb->complete = feedback_urb_complete;
|
||||||
|
}
|
||||||
|
|
||||||
tascam->capture_urb_alloc_size = CAPTURE_URB_SIZE;
|
tascam->capture_urb_alloc_size = CAPTURE_URB_SIZE;
|
||||||
for (i = 0; i < NUM_CAPTURE_URBS; i++) {
|
for (i = 0; i < NUM_CAPTURE_URBS; i++) {
|
||||||
struct urb *c_urb = usb_alloc_urb(0, GFP_KERNEL);
|
struct urb *c_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||||
|
|
||||||
if (!c_urb)
|
if (!c_urb)
|
||||||
goto error;
|
goto error;
|
||||||
tascam->capture_urbs[i] = c_urb;
|
tascam->capture_urbs[i] = c_urb;
|
||||||
|
|
||||||
c_urb->transfer_buffer =
|
c_urb->transfer_buffer = usb_alloc_coherent(
|
||||||
usb_alloc_coherent(tascam->dev, tascam->capture_urb_alloc_size,
|
tascam->dev, tascam->capture_urb_alloc_size, GFP_KERNEL,
|
||||||
GFP_KERNEL, &c_urb->transfer_dma);
|
&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, tascam->capture_urb_alloc_size,
|
c_urb->transfer_buffer,
|
||||||
capture_urb_complete, tascam);
|
tascam->capture_urb_alloc_size,
|
||||||
c_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
capture_urb_complete, tascam);
|
||||||
}
|
c_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
||||||
|
}
|
||||||
|
|
||||||
/* MIDI URB and buffer allocation */
|
/* MIDI URB and buffer allocation */
|
||||||
for (i = 0; i < NUM_MIDI_IN_URBS; i++) {
|
for (i = 0; i < NUM_MIDI_IN_URBS; i++) {
|
||||||
struct urb *m_urb = usb_alloc_urb(0, GFP_KERNEL);
|
struct urb *m_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||||
|
|
||||||
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 = usb_alloc_coherent(
|
m_urb->transfer_buffer =
|
||||||
tascam->dev, MIDI_IN_BUF_SIZE, GFP_KERNEL, &m_urb->transfer_dma);
|
usb_alloc_coherent(tascam->dev, MIDI_IN_BUF_SIZE,
|
||||||
if (!m_urb->transfer_buffer)
|
GFP_KERNEL, &m_urb->transfer_dma);
|
||||||
goto error;
|
if (!m_urb->transfer_buffer)
|
||||||
usb_fill_bulk_urb(m_urb, tascam->dev,
|
goto error;
|
||||||
usb_rcvbulkpipe(tascam->dev, EP_MIDI_IN),
|
usb_fill_bulk_urb(m_urb, tascam->dev,
|
||||||
m_urb->transfer_buffer, MIDI_IN_BUF_SIZE,
|
usb_rcvbulkpipe(tascam->dev, EP_MIDI_IN),
|
||||||
tascam_midi_in_urb_complete, tascam);
|
m_urb->transfer_buffer, MIDI_IN_BUF_SIZE,
|
||||||
m_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
tascam_midi_in_urb_complete, tascam);
|
||||||
}
|
m_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < NUM_MIDI_OUT_URBS; i++) {
|
for (i = 0; i < NUM_MIDI_OUT_URBS; i++) {
|
||||||
struct urb *m_urb = usb_alloc_urb(0, GFP_KERNEL);
|
struct urb *m_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||||
|
|
||||||
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 = usb_alloc_coherent(
|
m_urb->transfer_buffer =
|
||||||
tascam->dev, MIDI_OUT_BUF_SIZE, GFP_KERNEL, &m_urb->transfer_dma);
|
usb_alloc_coherent(tascam->dev, MIDI_OUT_BUF_SIZE,
|
||||||
if (!m_urb->transfer_buffer)
|
GFP_KERNEL, &m_urb->transfer_dma);
|
||||||
goto error;
|
if (!m_urb->transfer_buffer)
|
||||||
usb_fill_bulk_urb(m_urb, tascam->dev,
|
goto error;
|
||||||
usb_sndbulkpipe(tascam->dev, EP_MIDI_OUT),
|
usb_fill_bulk_urb(m_urb, tascam->dev,
|
||||||
m_urb->transfer_buffer, 0, /* length set later */
|
usb_sndbulkpipe(tascam->dev, EP_MIDI_OUT),
|
||||||
tascam_midi_out_urb_complete, tascam);
|
m_urb->transfer_buffer,
|
||||||
m_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
0, /* length set later */
|
||||||
}
|
tascam_midi_out_urb_complete, tascam);
|
||||||
|
m_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
||||||
|
}
|
||||||
|
|
||||||
tascam->capture_ring_buffer = kmalloc(CAPTURE_RING_BUFFER_SIZE, GFP_KERNEL);
|
tascam->capture_ring_buffer =
|
||||||
if (!tascam->capture_ring_buffer)
|
kmalloc(CAPTURE_RING_BUFFER_SIZE, GFP_KERNEL);
|
||||||
goto error;
|
if (!tascam->capture_ring_buffer)
|
||||||
|
goto error;
|
||||||
|
|
||||||
tascam->capture_decode_raw_block =
|
tascam->capture_decode_raw_block =
|
||||||
kmalloc(RAW_BYTES_PER_DECODE_BLOCK, GFP_KERNEL);
|
kmalloc(RAW_BYTES_PER_DECODE_BLOCK, GFP_KERNEL);
|
||||||
if (!tascam->capture_decode_raw_block)
|
if (!tascam->capture_decode_raw_block)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
tascam->capture_decode_dst_block =
|
tascam->capture_decode_dst_block =
|
||||||
kmalloc(FRAMES_PER_DECODE_BLOCK * DECODED_CHANNELS_PER_FRAME *
|
kmalloc(FRAMES_PER_DECODE_BLOCK * DECODED_CHANNELS_PER_FRAME *
|
||||||
DECODED_SAMPLE_SIZE,
|
DECODED_SAMPLE_SIZE,
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!tascam->capture_decode_dst_block)
|
if (!tascam->capture_decode_dst_block)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
tascam->capture_routing_buffer =
|
tascam->capture_routing_buffer =
|
||||||
kmalloc(FRAMES_PER_DECODE_BLOCK * DECODED_CHANNELS_PER_FRAME *
|
kmalloc(FRAMES_PER_DECODE_BLOCK * DECODED_CHANNELS_PER_FRAME *
|
||||||
DECODED_SAMPLE_SIZE,
|
DECODED_SAMPLE_SIZE,
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!tascam->capture_routing_buffer)
|
if (!tascam->capture_routing_buffer)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
dev_err(tascam->card->dev, "Failed to allocate URBs\n");
|
dev_err(tascam->card->dev, "Failed to allocate URBs\n");
|
||||||
tascam_free_urbs(tascam);
|
tascam_free_urbs(tascam);
|
||||||
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 =
|
{
|
||||||
container_of(work, struct tascam_card, stop_work);
|
struct tascam_card *tascam =
|
||||||
|
container_of(work, struct tascam_card, stop_work);
|
||||||
|
|
||||||
usb_kill_anchored_urbs(&tascam->playback_anchor);
|
usb_kill_anchored_urbs(&tascam->playback_anchor);
|
||||||
usb_kill_anchored_urbs(&tascam->feedback_anchor);
|
usb_kill_anchored_urbs(&tascam->feedback_anchor);
|
||||||
usb_kill_anchored_urbs(&tascam->capture_anchor);
|
usb_kill_anchored_urbs(&tascam->capture_anchor);
|
||||||
atomic_set(&tascam->active_urbs, 0);
|
atomic_set(&tascam->active_urbs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -297,16 +278,17 @@ void tascam_stop_work_handler(struct work_struct *work) {
|
||||||
* 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) {
|
||||||
kfifo_free(&tascam->midi_in_fifo);
|
kfifo_free(&tascam->midi_in_fifo);
|
||||||
if (tascam->dev) {
|
if (tascam->dev) {
|
||||||
usb_put_dev(tascam->dev);
|
usb_put_dev(tascam->dev);
|
||||||
tascam->dev = NULL;
|
tascam->dev = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -320,26 +302,34 @@ 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);
|
||||||
|
|
||||||
if (!tascam)
|
if (!tascam)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
snd_pcm_suspend_all(tascam->pcm);
|
snd_pcm_suspend_all(tascam->pcm);
|
||||||
|
|
||||||
cancel_work_sync(&tascam->stop_work);
|
cancel_work_sync(&tascam->stop_work);
|
||||||
cancel_work_sync(&tascam->capture_work);
|
cancel_work_sync(&tascam->capture_work);
|
||||||
cancel_work_sync(&tascam->midi_in_work);
|
cancel_work_sync(&tascam->midi_in_work);
|
||||||
cancel_work_sync(&tascam->midi_out_work);
|
cancel_work_sync(&tascam->midi_out_work);
|
||||||
cancel_work_sync(&tascam->stop_pcm_work);
|
cancel_work_sync(&tascam->stop_pcm_work);
|
||||||
usb_kill_anchored_urbs(&tascam->playback_anchor);
|
usb_kill_anchored_urbs(&tascam->playback_anchor);
|
||||||
usb_kill_anchored_urbs(&tascam->capture_anchor);
|
usb_kill_anchored_urbs(&tascam->capture_anchor);
|
||||||
usb_kill_anchored_urbs(&tascam->feedback_anchor);
|
usb_kill_anchored_urbs(&tascam->feedback_anchor);
|
||||||
usb_kill_anchored_urbs(&tascam->midi_in_anchor);
|
usb_kill_anchored_urbs(&tascam->midi_in_anchor);
|
||||||
usb_kill_anchored_urbs(&tascam->midi_out_anchor);
|
usb_kill_anchored_urbs(&tascam->midi_out_anchor);
|
||||||
|
|
||||||
return 0;
|
dev_info(&intf->dev, "sending deep sleep command\n");
|
||||||
|
int err = usb_control_msg(tascam->dev, usb_sndctrlpipe(tascam->dev, 0),
|
||||||
|
VENDOR_REQ_DEEP_SLEEP, RT_H2D_VENDOR_DEV,
|
||||||
|
0x0000, 0x0000, NULL, 0, USB_CTRL_TIMEOUT_MS);
|
||||||
|
if (err < 0)
|
||||||
|
dev_err(&intf->dev, "deep sleep command failed: %d\n", err);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -352,46 +342,52 @@ static int tascam_suspend(struct usb_interface *intf, pm_message_t message) {
|
||||||
*
|
*
|
||||||
* 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);
|
{
|
||||||
int err;
|
struct tascam_card *tascam = usb_get_intfdata(intf);
|
||||||
|
int err;
|
||||||
|
|
||||||
if (!tascam)
|
if (!tascam)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
dev_info(&intf->dev, "resuming TASCAM US-144MKII\n");
|
dev_info(&intf->dev, "resuming TASCAM US-144MKII\n");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The device requires a full re-initialization sequence upon resume.
|
* The device requires a full re-initialization sequence upon resume.
|
||||||
* First, re-establish the active USB interface settings.
|
* First, re-establish the active USB interface settings.
|
||||||
*/
|
*/
|
||||||
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, "resume: failed to set alt setting on intf 0: %d\n",
|
dev_err(&intf->dev,
|
||||||
err);
|
"resume: failed to set alt setting on intf 0: %d\n",
|
||||||
return err;
|
err);
|
||||||
}
|
return err;
|
||||||
err = usb_set_interface(tascam->dev, 1, 1);
|
}
|
||||||
if (err < 0) {
|
err = usb_set_interface(tascam->dev, 1, 1);
|
||||||
dev_err(&intf->dev, "resume: failed to set alt setting on intf 1: %d\n",
|
if (err < 0) {
|
||||||
err);
|
dev_err(&intf->dev,
|
||||||
return err;
|
"resume: failed to set alt setting on intf 1: %d\n",
|
||||||
}
|
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, tascam->current_rate);
|
us144mkii_configure_device_for_rate(tascam,
|
||||||
|
tascam->current_rate);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tascam_error_timer(struct timer_list *t) {
|
static void tascam_error_timer(struct timer_list *t)
|
||||||
struct tascam_card *tascam = container_of(t, struct tascam_card, error_timer);
|
{
|
||||||
|
struct tascam_card *tascam =
|
||||||
|
container_of(t, struct tascam_card, error_timer);
|
||||||
|
|
||||||
if (atomic_read(&tascam->midi_in_active))
|
if (atomic_read(&tascam->midi_in_active))
|
||||||
schedule_work(&tascam->midi_in_work);
|
schedule_work(&tascam->midi_in_work);
|
||||||
if (atomic_read(&tascam->midi_out_active))
|
if (atomic_read(&tascam->midi_out_active))
|
||||||
schedule_work(&tascam->midi_out_work);
|
schedule_work(&tascam->midi_out_work);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -410,149 +406,159 @@ static void tascam_error_timer(struct timer_list *t) {
|
||||||
* 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 snd_card *card;
|
struct usb_device *dev = interface_to_usbdev(intf);
|
||||||
struct tascam_card *tascam;
|
struct snd_card *card;
|
||||||
int err;
|
struct tascam_card *tascam;
|
||||||
char *handshake_buf __free(kfree);
|
int err;
|
||||||
|
|
||||||
if (dev->speed != USB_SPEED_HIGH)
|
char *handshake_buf __free(kfree);
|
||||||
dev_info(&dev->dev,
|
|
||||||
"Device is connected to a USB 1.1 port, this is not supported.\n");
|
|
||||||
|
|
||||||
if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
|
if (dev->speed != USB_SPEED_HIGH)
|
||||||
tascam = usb_get_intfdata(usb_ifnum_to_if(dev, 0));
|
dev_info(
|
||||||
if (tascam) {
|
&dev->dev,
|
||||||
usb_set_intfdata(intf, tascam);
|
"Device is connected to a USB 1.1 port, this is not supported.\n");
|
||||||
tascam->iface1 = intf;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dev_idx >= SNDRV_CARDS) {
|
if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
|
||||||
dev_err(&dev->dev, "Too many TASCAM devices present");
|
tascam = usb_get_intfdata(usb_ifnum_to_if(dev, 0));
|
||||||
return -ENODEV;
|
if (tascam) {
|
||||||
}
|
usb_set_intfdata(intf, tascam);
|
||||||
|
tascam->iface1 = intf;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!enable[dev_idx]) {
|
if (dev_idx >= SNDRV_CARDS) {
|
||||||
dev_info(&dev->dev, "TASCAM US-144MKII device disabled");
|
dev_err(&dev->dev, "Too many TASCAM devices present");
|
||||||
return -ENOENT;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
handshake_buf = kmalloc(1, GFP_KERNEL);
|
if (!enable[dev_idx]) {
|
||||||
if (!handshake_buf)
|
dev_info(&dev->dev, "TASCAM US-144MKII device disabled");
|
||||||
return -ENOMEM;
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
err = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), VENDOR_REQ_MODE_CONTROL,
|
handshake_buf = kmalloc(1, GFP_KERNEL);
|
||||||
RT_D2H_VENDOR_DEV, MODE_VAL_HANDSHAKE_READ, 0x0000,
|
if (!handshake_buf)
|
||||||
handshake_buf, 1, USB_CTRL_TIMEOUT_MS);
|
return -ENOMEM;
|
||||||
if (err < 0) {
|
|
||||||
dev_err(&dev->dev, "Handshake read failed with %d\n", err);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (handshake_buf[0] != 0x12 && handshake_buf[0] != 0x16 &&
|
err = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
|
||||||
handshake_buf[0] != 0x30) {
|
VENDOR_REQ_MODE_CONTROL, RT_D2H_VENDOR_DEV,
|
||||||
dev_err(&dev->dev, "Unexpected handshake value: 0x%x\n", handshake_buf[0]);
|
MODE_VAL_HANDSHAKE_READ, 0x0000, handshake_buf, 1,
|
||||||
return -ENODEV;
|
USB_CTRL_TIMEOUT_MS);
|
||||||
}
|
if (err < 0) {
|
||||||
|
dev_err(&dev->dev, "Handshake read failed with %d\n", err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
err = usb_set_interface(dev, 0, 1);
|
if (handshake_buf[0] != 0x12 && handshake_buf[0] != 0x16 &&
|
||||||
if (err < 0) {
|
handshake_buf[0] != 0x30) {
|
||||||
dev_err(&dev->dev, "Failed to set alt setting 1 on interface 0: %d\n", err);
|
dev_err(&dev->dev, "Unexpected handshake value: 0x%x\n",
|
||||||
return err;
|
handshake_buf[0]);
|
||||||
}
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
err = usb_set_interface(dev, 1, 1);
|
err = usb_set_interface(dev, 0, 1);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
dev_err(&dev->dev, "Failed to set alt setting 1 on interface 1: %d\n", err);
|
dev_err(&dev->dev,
|
||||||
return err;
|
"Failed to set alt setting 1 on interface 0: %d\n",
|
||||||
}
|
err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
err = snd_card_new(&dev->dev, index[dev_idx], id[dev_idx], THIS_MODULE,
|
err = usb_set_interface(dev, 1, 1);
|
||||||
sizeof(struct tascam_card), &card);
|
if (err < 0) {
|
||||||
if (err < 0) {
|
dev_err(&dev->dev,
|
||||||
dev_err(&dev->dev, "Failed to create sound card instance\n");
|
"Failed to set alt setting 1 on interface 1: %d\n",
|
||||||
return err;
|
err);
|
||||||
}
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
tascam = card->private_data;
|
err = snd_card_new(&dev->dev, index[dev_idx], id[dev_idx], THIS_MODULE,
|
||||||
card->private_free = tascam_card_private_free;
|
sizeof(struct tascam_card), &card);
|
||||||
tascam->dev = usb_get_dev(dev);
|
if (err < 0) {
|
||||||
tascam->card = card;
|
dev_err(&dev->dev, "Failed to create sound card instance\n");
|
||||||
tascam->iface0 = intf;
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
spin_lock_init(&tascam->lock);
|
tascam = card->private_data;
|
||||||
spin_lock_init(&tascam->midi_in_lock);
|
card->private_free = tascam_card_private_free;
|
||||||
spin_lock_init(&tascam->midi_out_lock);
|
tascam->dev = usb_get_dev(dev);
|
||||||
init_usb_anchor(&tascam->playback_anchor);
|
tascam->card = card;
|
||||||
init_usb_anchor(&tascam->capture_anchor);
|
tascam->iface0 = intf;
|
||||||
init_usb_anchor(&tascam->feedback_anchor);
|
|
||||||
init_usb_anchor(&tascam->midi_in_anchor);
|
|
||||||
init_usb_anchor(&tascam->midi_out_anchor);
|
|
||||||
|
|
||||||
timer_setup(&tascam->error_timer, tascam_error_timer, 0);
|
spin_lock_init(&tascam->lock);
|
||||||
|
spin_lock_init(&tascam->midi_in_lock);
|
||||||
|
spin_lock_init(&tascam->midi_out_lock);
|
||||||
|
init_usb_anchor(&tascam->playback_anchor);
|
||||||
|
init_usb_anchor(&tascam->capture_anchor);
|
||||||
|
init_usb_anchor(&tascam->feedback_anchor);
|
||||||
|
init_usb_anchor(&tascam->midi_in_anchor);
|
||||||
|
init_usb_anchor(&tascam->midi_out_anchor);
|
||||||
|
|
||||||
INIT_WORK(&tascam->stop_work, tascam_stop_work_handler);
|
timer_setup(&tascam->error_timer, tascam_error_timer, 0);
|
||||||
INIT_WORK(&tascam->stop_pcm_work, tascam_stop_pcm_work_handler);
|
|
||||||
|
|
||||||
if (kfifo_alloc(&tascam->midi_in_fifo, MIDI_IN_FIFO_SIZE, GFP_KERNEL)) {
|
INIT_WORK(&tascam->stop_work, tascam_stop_work_handler);
|
||||||
snd_card_free(card);
|
INIT_WORK(&tascam->stop_pcm_work, tascam_stop_pcm_work_handler);
|
||||||
return -ENOMEM;
|
INIT_WORK(&tascam->capture_work, tascam_capture_work_handler);
|
||||||
}
|
init_completion(&tascam->midi_out_drain_completion);
|
||||||
|
|
||||||
strscpy(card->driver, DRIVER_NAME, sizeof(card->driver));
|
if (kfifo_alloc(&tascam->midi_in_fifo, MIDI_IN_FIFO_SIZE, GFP_KERNEL)) {
|
||||||
if (dev->descriptor.idProduct == USB_PID_TASCAM_US144) {
|
snd_card_free(card);
|
||||||
strscpy(card->shortname, "TASCAM US-144", sizeof(card->shortname));
|
return -ENOMEM;
|
||||||
} else if (dev->descriptor.idProduct == USB_PID_TASCAM_US144MKII) {
|
}
|
||||||
strscpy(card->shortname, "TASCAM US-144MKII", sizeof(card->shortname));
|
|
||||||
} else {
|
|
||||||
strscpy(card->shortname, "TASCAM Unknown", sizeof(card->shortname));
|
|
||||||
}
|
|
||||||
snprintf(card->longname, sizeof(card->longname), "%s (%04x:%04x) at %s",
|
|
||||||
card->shortname, USB_VID_TASCAM, dev->descriptor.idProduct,
|
|
||||||
dev_name(&dev->dev));
|
|
||||||
|
|
||||||
err = device_create_file(&dev->dev, &dev_attr_driver_version);
|
strscpy(card->driver, DRIVER_NAME, sizeof(card->driver));
|
||||||
if (err < 0)
|
if (dev->descriptor.idProduct == USB_PID_TASCAM_US144) {
|
||||||
dev_warn(&dev->dev, "could not create driver_version attribute, err: %d\n",
|
strscpy(card->shortname, "TASCAM US-144",
|
||||||
err);
|
sizeof(card->shortname));
|
||||||
|
} else if (dev->descriptor.idProduct == USB_PID_TASCAM_US144MKII) {
|
||||||
|
strscpy(card->shortname, "TASCAM US-144MKII",
|
||||||
|
sizeof(card->shortname));
|
||||||
|
} else {
|
||||||
|
strscpy(card->shortname, "TASCAM Unknown",
|
||||||
|
sizeof(card->shortname));
|
||||||
|
}
|
||||||
|
snprintf(card->longname, sizeof(card->longname), "%s (%04x:%04x) at %s",
|
||||||
|
card->shortname, USB_VID_TASCAM, dev->descriptor.idProduct,
|
||||||
|
dev_name(&dev->dev));
|
||||||
|
|
||||||
err = snd_pcm_new(card, "US144MKII PCM", 0, 1, 1, &tascam->pcm);
|
err = snd_pcm_new(card, "US144MKII PCM", 0, 1, 1, &tascam->pcm);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto free_card;
|
goto free_card;
|
||||||
tascam->pcm->private_data = tascam;
|
tascam->pcm->private_data = tascam;
|
||||||
strscpy(tascam->pcm->name, "US144MKII PCM", sizeof(tascam->pcm->name));
|
strscpy(tascam->pcm->name, "US144MKII PCM", sizeof(tascam->pcm->name));
|
||||||
|
|
||||||
err = tascam_init_pcm(tascam->pcm);
|
err = tascam_init_pcm(tascam->pcm);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto free_card;
|
goto free_card;
|
||||||
|
|
||||||
err = tascam_create_midi(tascam);
|
err = tascam_create_midi(tascam);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto free_card;
|
goto free_card;
|
||||||
|
|
||||||
err = tascam_create_controls(tascam);
|
err = tascam_create_controls(tascam);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto free_card;
|
goto free_card;
|
||||||
|
|
||||||
err = tascam_alloc_urbs(tascam);
|
err = tascam_alloc_urbs(tascam);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto free_card;
|
goto free_card;
|
||||||
|
|
||||||
err = snd_card_register(card);
|
err = snd_card_register(card);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto free_card;
|
goto free_card;
|
||||||
|
|
||||||
usb_set_intfdata(intf, tascam);
|
usb_set_intfdata(intf, tascam);
|
||||||
|
|
||||||
dev_idx++;
|
dev_idx++;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
free_card:
|
free_card:
|
||||||
snd_card_free(card);
|
tascam_free_urbs(tascam);
|
||||||
return err;
|
snd_card_free(card);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -563,47 +569,48 @@ 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)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
|
if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
|
||||||
device_remove_file(&tascam->dev->dev, &dev_attr_driver_version);
|
/* Ensure all deferred work is complete before freeing resources */
|
||||||
|
snd_card_disconnect(tascam->card);
|
||||||
|
cancel_work_sync(&tascam->stop_work);
|
||||||
|
cancel_work_sync(&tascam->capture_work);
|
||||||
|
cancel_work_sync(&tascam->midi_in_work);
|
||||||
|
cancel_work_sync(&tascam->midi_out_work);
|
||||||
|
cancel_work_sync(&tascam->stop_pcm_work);
|
||||||
|
|
||||||
/* Ensure all deferred work is complete before freeing resources */
|
usb_kill_anchored_urbs(&tascam->playback_anchor);
|
||||||
snd_card_disconnect(tascam->card);
|
usb_kill_anchored_urbs(&tascam->capture_anchor);
|
||||||
cancel_work_sync(&tascam->stop_work);
|
usb_kill_anchored_urbs(&tascam->feedback_anchor);
|
||||||
cancel_work_sync(&tascam->capture_work);
|
usb_kill_anchored_urbs(&tascam->midi_in_anchor);
|
||||||
cancel_work_sync(&tascam->midi_in_work);
|
usb_kill_anchored_urbs(&tascam->midi_out_anchor);
|
||||||
cancel_work_sync(&tascam->midi_out_work);
|
timer_delete_sync(&tascam->error_timer);
|
||||||
cancel_work_sync(&tascam->stop_pcm_work);
|
tascam_free_urbs(tascam);
|
||||||
|
snd_card_free(tascam->card);
|
||||||
usb_kill_anchored_urbs(&tascam->playback_anchor);
|
dev_idx--;
|
||||||
usb_kill_anchored_urbs(&tascam->capture_anchor);
|
}
|
||||||
usb_kill_anchored_urbs(&tascam->feedback_anchor);
|
|
||||||
usb_kill_anchored_urbs(&tascam->midi_in_anchor);
|
|
||||||
usb_kill_anchored_urbs(&tascam->midi_out_anchor);
|
|
||||||
timer_delete_sync(&tascam->error_timer);
|
|
||||||
snd_card_free(tascam->card);
|
|
||||||
dev_idx--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = {
|
||||||
.name = DRIVER_NAME,
|
.name = DRIVER_NAME,
|
||||||
.probe = tascam_probe,
|
.probe = tascam_probe,
|
||||||
.disconnect = tascam_disconnect,
|
.disconnect = tascam_disconnect,
|
||||||
.suspend = tascam_suspend,
|
.suspend = tascam_suspend,
|
||||||
.resume = tascam_resume,
|
.resume = tascam_resume,
|
||||||
.id_table = tascam_usb_ids,
|
.id_table = tascam_usb_ids,
|
||||||
};
|
};
|
||||||
|
|
||||||
module_usb_driver(tascam_alsa_driver);
|
module_usb_driver(tascam_alsa_driver);
|
||||||
|
|
|
||||||
246
us144mkii.h
246
us144mkii.h
|
|
@ -36,36 +36,37 @@
|
||||||
#define RT_D2H_VENDOR_DEV (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE)
|
#define RT_D2H_VENDOR_DEV (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE)
|
||||||
|
|
||||||
enum uac_request {
|
enum uac_request {
|
||||||
UAC_SET_CUR = 0x01,
|
UAC_SET_CUR = 0x01,
|
||||||
UAC_GET_CUR = 0x81,
|
UAC_GET_CUR = 0x81,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum uac_control_selector {
|
enum uac_control_selector {
|
||||||
UAC_SAMPLING_FREQ_CONTROL = 0x0100,
|
UAC_SAMPLING_FREQ_CONTROL = 0x0100,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum tascam_vendor_request {
|
enum tascam_vendor_request {
|
||||||
VENDOR_REQ_REGISTER_WRITE = 0x41,
|
VENDOR_REQ_REGISTER_WRITE = 0x41,
|
||||||
VENDOR_REQ_MODE_CONTROL = 0x49,
|
VENDOR_REQ_DEEP_SLEEP = 0x44,
|
||||||
|
VENDOR_REQ_MODE_CONTROL = 0x49,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum tascam_mode_value {
|
enum tascam_mode_value {
|
||||||
MODE_VAL_HANDSHAKE_READ = 0x0000,
|
MODE_VAL_HANDSHAKE_READ = 0x0000,
|
||||||
MODE_VAL_CONFIG = 0x0010,
|
MODE_VAL_CONFIG = 0x0010,
|
||||||
MODE_VAL_STREAM_START = 0x0030,
|
MODE_VAL_STREAM_START = 0x0030,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define HANDSHAKE_SUCCESS_VAL 0x12
|
#define HANDSHAKE_SUCCESS_VAL 0x12
|
||||||
|
|
||||||
enum tascam_register {
|
enum tascam_register {
|
||||||
REG_ADDR_UNKNOWN_0D = 0x0d04,
|
REG_ADDR_UNKNOWN_0D = 0x0d04,
|
||||||
REG_ADDR_UNKNOWN_0E = 0x0e00,
|
REG_ADDR_UNKNOWN_0E = 0x0e00,
|
||||||
REG_ADDR_UNKNOWN_0F = 0x0f00,
|
REG_ADDR_UNKNOWN_0F = 0x0f00,
|
||||||
REG_ADDR_RATE_44100 = 0x1000,
|
REG_ADDR_RATE_44100 = 0x1000,
|
||||||
REG_ADDR_RATE_48000 = 0x1002,
|
REG_ADDR_RATE_48000 = 0x1002,
|
||||||
REG_ADDR_RATE_88200 = 0x1008,
|
REG_ADDR_RATE_88200 = 0x1008,
|
||||||
REG_ADDR_RATE_96000 = 0x100a,
|
REG_ADDR_RATE_96000 = 0x100a,
|
||||||
REG_ADDR_UNKNOWN_11 = 0x110b,
|
REG_ADDR_UNKNOWN_11 = 0x110b,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define REG_VAL_ENABLE 0x0101
|
#define REG_VAL_ENABLE 0x0101
|
||||||
|
|
@ -99,6 +100,27 @@ enum tascam_register {
|
||||||
#define FRAMES_PER_DECODE_BLOCK 8
|
#define FRAMES_PER_DECODE_BLOCK 8
|
||||||
#define RAW_BYTES_PER_DECODE_BLOCK 512
|
#define RAW_BYTES_PER_DECODE_BLOCK 512
|
||||||
|
|
||||||
|
/**
|
||||||
|
* struct us144mkii_frame_pattern_observer - State for dynamic feedback
|
||||||
|
* patterns.
|
||||||
|
* @sample_rate_khz: The current sample rate in kHz.
|
||||||
|
* @base_feedback_value: The nominal feedback value for the current rate.
|
||||||
|
* @feedback_offset: An offset to align the feedback value range.
|
||||||
|
* @full_frame_patterns: A 2D array of pre-calculated packet size patterns.
|
||||||
|
* @current_index: The current index into the pattern array.
|
||||||
|
* @previous_index: The previous index, used for state tracking.
|
||||||
|
* @sync_locked: A flag indicating if the pattern has locked to the stream.
|
||||||
|
*/
|
||||||
|
struct us144mkii_frame_pattern_observer {
|
||||||
|
unsigned int sample_rate_khz;
|
||||||
|
unsigned int base_feedback_value;
|
||||||
|
int feedback_offset;
|
||||||
|
unsigned int full_frame_patterns[5][8];
|
||||||
|
unsigned int current_index;
|
||||||
|
unsigned int previous_index;
|
||||||
|
bool sync_locked;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct tascam_card - Main driver data structure for the TASCAM US-144MKII.
|
* struct tascam_card - Main driver data structure for the TASCAM US-144MKII.
|
||||||
* @dev: Pointer to the USB device.
|
* @dev: Pointer to the USB device.
|
||||||
|
|
@ -117,7 +139,6 @@ enum tascam_register {
|
||||||
* @playback_frames_consumed: Total frames consumed by playback.
|
* @playback_frames_consumed: Total frames consumed by playback.
|
||||||
* @driver_playback_pos: Current position in the ALSA playback buffer (frames).
|
* @driver_playback_pos: Current position in the ALSA playback buffer (frames).
|
||||||
* @last_period_pos: Last reported period position for playback.
|
* @last_period_pos: Last reported period position for playback.
|
||||||
* @playback_routing_buffer: Intermediate buffer for playback routing.
|
|
||||||
*
|
*
|
||||||
* @capture_substream: Pointer to the active capture PCM substream.
|
* @capture_substream: Pointer to the active capture PCM substream.
|
||||||
* @capture_urbs: Array of URBs for capture.
|
* @capture_urbs: Array of URBs for capture.
|
||||||
|
|
@ -134,20 +155,23 @@ enum tascam_register {
|
||||||
* @capture_routing_buffer: Intermediate buffer for capture routing.
|
* @capture_routing_buffer: Intermediate buffer for capture routing.
|
||||||
* @capture_work: Work struct for deferred capture processing.
|
* @capture_work: Work struct for deferred capture processing.
|
||||||
* @stop_work: Work struct for deferred stream stopping.
|
* @stop_work: Work struct for deferred stream stopping.
|
||||||
|
* @stop_pcm_work: Work struct for stopping PCM due to a fatal error (e.g.
|
||||||
|
* xrun).
|
||||||
*
|
*
|
||||||
* @midi_in_substream: Pointer to the active MIDI input substream.
|
* @midi_in_substream: Pointer to the active MIDI input substream.
|
||||||
* @midi_out_substream: Pointer to the active MIDI output substream.
|
* @midi_out_substream: Pointer to the active MIDI output substream.
|
||||||
* @midi_in_urbs: Array of URBs for MIDI input.
|
* @midi_in_urbs: Array of URBs for MIDI input.
|
||||||
|
* @midi_out_urbs: Array of URBs for MIDI output.
|
||||||
* @midi_in_active: Atomic flag indicating if MIDI input is active.
|
* @midi_in_active: Atomic flag indicating if MIDI input is active.
|
||||||
|
* @midi_out_active: Atomic flag indicating if MIDI output is active.
|
||||||
* @midi_in_fifo: FIFO for raw MIDI input data.
|
* @midi_in_fifo: FIFO for raw MIDI input data.
|
||||||
* @midi_in_work: Work struct for deferred MIDI input processing.
|
* @midi_in_work: Work struct for deferred MIDI input processing.
|
||||||
* @midi_in_lock: Spinlock for MIDI input FIFO.
|
|
||||||
* @midi_out_urbs: Array of URBs for MIDI output.
|
|
||||||
* @midi_out_active: Atomic flag indicating if MIDI output is active.
|
|
||||||
* @midi_out_work: Work struct for deferred MIDI output processing.
|
* @midi_out_work: Work struct for deferred MIDI output processing.
|
||||||
* @midi_out_urbs_in_flight: Bitmap of MIDI output URBs currently in flight.
|
* @midi_in_lock: Spinlock for MIDI input FIFO.
|
||||||
* @midi_out_lock: Spinlock for MIDI output.
|
* @midi_out_lock: Spinlock for MIDI output.
|
||||||
|
* @midi_out_urbs_in_flight: Bitmap of MIDI output URBs currently in flight.
|
||||||
* @midi_running_status: Stores the last MIDI status byte for running status.
|
* @midi_running_status: Stores the last MIDI status byte for running status.
|
||||||
|
* @error_timer: Timer for MIDI error retry logic.
|
||||||
*
|
*
|
||||||
* @lock: Main spinlock for protecting shared driver state.
|
* @lock: Main spinlock for protecting shared driver state.
|
||||||
* @active_urbs: Atomic counter for active URBs.
|
* @active_urbs: Atomic counter for active URBs.
|
||||||
|
|
@ -177,109 +201,93 @@ enum tascam_register {
|
||||||
* @midi_out_anchor: USB anchor for MIDI output URBs.
|
* @midi_out_anchor: USB anchor for MIDI output URBs.
|
||||||
*/
|
*/
|
||||||
struct tascam_card {
|
struct tascam_card {
|
||||||
/* --- Hot Path Data (frequently accessed, especially in IRQ/workqueue) --- */
|
/* --- Core device pointers --- */
|
||||||
spinlock_t lock; // Main lock, highly contended
|
struct usb_device *dev;
|
||||||
atomic_t playback_active;
|
struct usb_interface *iface0;
|
||||||
atomic_t capture_active;
|
struct usb_interface *iface1;
|
||||||
atomic_t active_urbs; // Also frequently updated
|
struct snd_card *card;
|
||||||
|
struct snd_pcm *pcm;
|
||||||
|
struct snd_rawmidi *rmidi;
|
||||||
|
|
||||||
// Playback state (updated by feedback_urb_complete and playback_urb_complete)
|
/* --- PCM Substreams --- */
|
||||||
u64 playback_frames_consumed;
|
struct snd_pcm_substream *playback_substream;
|
||||||
snd_pcm_uframes_t driver_playback_pos;
|
struct snd_pcm_substream *capture_substream;
|
||||||
u64 last_period_pos;
|
|
||||||
|
|
||||||
// Capture state (updated by feedback_urb_complete and capture_urb_complete)
|
/* --- URBs and Anchors --- */
|
||||||
snd_pcm_uframes_t driver_capture_pos;
|
struct urb *playback_urbs[NUM_PLAYBACK_URBS];
|
||||||
u64 capture_frames_processed;
|
size_t playback_urb_alloc_size;
|
||||||
u64 last_capture_period_pos;
|
struct urb *feedback_urbs[NUM_FEEDBACK_URBS];
|
||||||
|
size_t feedback_urb_alloc_size;
|
||||||
|
struct urb *capture_urbs[NUM_CAPTURE_URBS];
|
||||||
|
size_t capture_urb_alloc_size;
|
||||||
|
struct urb *midi_in_urbs[NUM_MIDI_IN_URBS];
|
||||||
|
struct urb *midi_out_urbs[NUM_MIDI_OUT_URBS];
|
||||||
|
struct usb_anchor playback_anchor;
|
||||||
|
struct usb_anchor capture_anchor;
|
||||||
|
struct usb_anchor feedback_anchor;
|
||||||
|
struct usb_anchor midi_in_anchor;
|
||||||
|
struct usb_anchor midi_out_anchor;
|
||||||
|
|
||||||
// Feedback related (critical for audio sync)
|
/* --- Stream State --- */
|
||||||
unsigned int feedback_accumulator_pattern[FEEDBACK_ACCUMULATOR_SIZE];
|
spinlock_t lock;
|
||||||
unsigned int feedback_pattern_out_idx;
|
atomic_t playback_active;
|
||||||
unsigned int feedback_pattern_in_idx;
|
atomic_t capture_active;
|
||||||
bool feedback_synced;
|
atomic_t active_urbs;
|
||||||
unsigned int feedback_consecutive_errors;
|
int current_rate;
|
||||||
unsigned int feedback_urb_skip_count;
|
|
||||||
|
|
||||||
struct us144mkii_frame_pattern_observer {
|
/* --- Playback State --- */
|
||||||
unsigned int sample_rate_khz;
|
u64 playback_frames_consumed;
|
||||||
unsigned int base_feedback_value;
|
snd_pcm_uframes_t driver_playback_pos;
|
||||||
int feedback_offset;
|
u64 last_period_pos;
|
||||||
unsigned int full_frame_patterns[5][8];
|
|
||||||
unsigned int current_index;
|
|
||||||
unsigned int previous_index;
|
|
||||||
bool sync_locked;
|
|
||||||
} fpo;
|
|
||||||
|
|
||||||
// MIDI state (frequently accessed in MIDI handlers)
|
/* --- Capture State --- */
|
||||||
atomic_t midi_in_active;
|
u64 capture_frames_processed;
|
||||||
atomic_t midi_out_active;
|
snd_pcm_uframes_t driver_capture_pos;
|
||||||
spinlock_t midi_in_lock;
|
u64 last_capture_period_pos;
|
||||||
spinlock_t midi_out_lock;
|
u8 *capture_ring_buffer;
|
||||||
unsigned long midi_out_urbs_in_flight;
|
size_t capture_ring_buffer_read_ptr;
|
||||||
u8 midi_running_status;
|
size_t capture_ring_buffer_write_ptr;
|
||||||
bool in_sysex;
|
u8 *capture_decode_raw_block;
|
||||||
struct timer_list error_timer; // Timer for MIDI error retry
|
s32 *capture_decode_dst_block;
|
||||||
|
s32 *capture_routing_buffer;
|
||||||
|
|
||||||
int current_rate; // Also accessed frequently, moved up
|
/* --- MIDI State --- */
|
||||||
|
struct snd_rawmidi_substream *midi_in_substream;
|
||||||
|
struct snd_rawmidi_substream *midi_out_substream;
|
||||||
|
atomic_t midi_in_active;
|
||||||
|
atomic_t midi_out_active;
|
||||||
|
struct kfifo midi_in_fifo;
|
||||||
|
spinlock_t midi_in_lock;
|
||||||
|
spinlock_t midi_out_lock;
|
||||||
|
unsigned long midi_out_urbs_in_flight;
|
||||||
|
u8 midi_running_status;
|
||||||
|
struct timer_list error_timer;
|
||||||
|
struct completion midi_out_drain_completion;
|
||||||
|
|
||||||
/* --- Less Hot Data (pointers, configuration, work structs) --- */
|
/* --- Feedback Sync State --- */
|
||||||
struct usb_device *dev;
|
unsigned int feedback_accumulator_pattern[FEEDBACK_ACCUMULATOR_SIZE];
|
||||||
struct usb_interface *iface0;
|
unsigned int feedback_pattern_out_idx;
|
||||||
struct usb_interface *iface1;
|
unsigned int feedback_pattern_in_idx;
|
||||||
struct snd_card *card;
|
bool feedback_synced;
|
||||||
struct snd_pcm *pcm;
|
unsigned int feedback_consecutive_errors;
|
||||||
struct snd_rawmidi *rmidi;
|
unsigned int feedback_urb_skip_count;
|
||||||
|
struct us144mkii_frame_pattern_observer fpo;
|
||||||
|
|
||||||
// Substream pointers
|
/* --- Workqueues --- */
|
||||||
struct snd_pcm_substream *playback_substream;
|
struct work_struct stop_work;
|
||||||
struct snd_pcm_substream *capture_substream;
|
struct work_struct stop_pcm_work;
|
||||||
struct snd_rawmidi_substream *midi_in_substream;
|
struct work_struct capture_work;
|
||||||
struct snd_rawmidi_substream *midi_out_substream;
|
struct work_struct midi_in_work;
|
||||||
|
struct work_struct midi_out_work;
|
||||||
|
|
||||||
// URB arrays and sizes
|
/* --- Mixer/Routing State --- */
|
||||||
struct urb *playback_urbs[NUM_PLAYBACK_URBS];
|
unsigned int line_out_source;
|
||||||
size_t playback_urb_alloc_size;
|
unsigned int digital_out_source;
|
||||||
struct urb *feedback_urbs[NUM_FEEDBACK_URBS];
|
unsigned int capture_12_source;
|
||||||
size_t feedback_urb_alloc_size;
|
unsigned int capture_34_source;
|
||||||
struct urb *capture_urbs[NUM_CAPTURE_URBS];
|
|
||||||
size_t capture_urb_alloc_size;
|
|
||||||
struct urb *midi_in_urbs[NUM_MIDI_IN_URBS];
|
|
||||||
struct urb *midi_out_urbs[NUM_MIDI_OUT_URBS];
|
|
||||||
|
|
||||||
// Buffers (pointers to external allocations)
|
|
||||||
u8 *capture_ring_buffer;
|
|
||||||
size_t capture_ring_buffer_read_ptr;
|
|
||||||
size_t capture_ring_buffer_write_ptr;
|
|
||||||
u8 *capture_decode_raw_block;
|
|
||||||
s32 *capture_decode_dst_block;
|
|
||||||
s32 *capture_routing_buffer;
|
|
||||||
|
|
||||||
// Work structs
|
|
||||||
struct work_struct capture_work;
|
|
||||||
struct work_struct stop_work;
|
|
||||||
struct work_struct stop_pcm_work;
|
|
||||||
struct work_struct midi_in_work;
|
|
||||||
struct work_struct midi_out_work;
|
|
||||||
|
|
||||||
// FIFOs
|
|
||||||
struct kfifo midi_in_fifo;
|
|
||||||
|
|
||||||
// Routing Matrix settings
|
|
||||||
unsigned int line_out_source;
|
|
||||||
unsigned int digital_out_source;
|
|
||||||
unsigned int capture_12_source;
|
|
||||||
unsigned int capture_34_source;
|
|
||||||
|
|
||||||
// USB anchors
|
|
||||||
struct usb_anchor playback_anchor;
|
|
||||||
struct usb_anchor capture_anchor;
|
|
||||||
struct usb_anchor feedback_anchor;
|
|
||||||
struct usb_anchor midi_in_anchor;
|
|
||||||
struct usb_anchor midi_out_anchor;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* main */
|
/* main.c */
|
||||||
/**
|
/**
|
||||||
* tascam_free_urbs() - Free all allocated URBs and associated buffers.
|
* tascam_free_urbs() - Free all allocated URBs and associated buffers.
|
||||||
* @tascam: the tascam_card instance
|
* @tascam: the tascam_card instance
|
||||||
|
|
@ -306,20 +314,10 @@ int tascam_alloc_urbs(struct tascam_card *tascam);
|
||||||
* @work: Pointer to the work_struct.
|
* @work: Pointer to the work_struct.
|
||||||
*
|
*
|
||||||
* This function is scheduled to stop all active URBs (playback, feedback,
|
* This function is scheduled to stop all active URBs (playback, feedback,
|
||||||
* capture) and reset the active_urbs counter. It is used to gracefully stop
|
* capture) and reset the active_urbs counter.
|
||||||
* streams from a workqueue context.
|
|
||||||
*/
|
*/
|
||||||
void tascam_stop_work_handler(struct work_struct *work);
|
void tascam_stop_work_handler(struct work_struct *work);
|
||||||
|
|
||||||
/**
|
|
||||||
* tascam_stop_pcm_work_handler() - Work handler to stop PCM streams.
|
|
||||||
* @work: Pointer to the work_struct.
|
|
||||||
*
|
|
||||||
* This function is scheduled to stop PCM streams (playback and capture)
|
|
||||||
* from a workqueue context, avoiding blocking operations in interrupt context.
|
|
||||||
*/
|
|
||||||
void tascam_stop_pcm_work_handler(struct work_struct *work);
|
|
||||||
|
|
||||||
/* us144mkii_pcm.h */
|
/* us144mkii_pcm.h */
|
||||||
#include "us144mkii_pcm.h"
|
#include "us144mkii_pcm.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,15 @@
|
||||||
*
|
*
|
||||||
* 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;
|
||||||
tascam->capture_substream = substream;
|
tascam->capture_substream = substream;
|
||||||
atomic_set(&tascam->capture_active, 0);
|
atomic_set(&tascam->capture_active, 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -31,12 +32,13 @@ 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;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -47,16 +49,17 @@ 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;
|
||||||
tascam->capture_frames_processed = 0;
|
tascam->capture_frames_processed = 0;
|
||||||
tascam->last_capture_period_pos = 0;
|
tascam->last_capture_period_pos = 0;
|
||||||
tascam->capture_ring_buffer_read_ptr = 0;
|
tascam->capture_ring_buffer_read_ptr = 0;
|
||||||
tascam->capture_ring_buffer_write_ptr = 0;
|
tascam->capture_ring_buffer_write_ptr = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -69,22 +72,24 @@ 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
|
static snd_pcm_uframes_t
|
||||||
tascam_capture_pointer(struct snd_pcm_substream *substream) {
|
tascam_capture_pointer(struct snd_pcm_substream *substream)
|
||||||
struct tascam_card *tascam = snd_pcm_substream_chip(substream);
|
{
|
||||||
struct snd_pcm_runtime *runtime = substream->runtime;
|
struct tascam_card *tascam = snd_pcm_substream_chip(substream);
|
||||||
u64 pos;
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
||||||
|
u64 pos;
|
||||||
|
|
||||||
if (!atomic_read(&tascam->capture_active))
|
if (!atomic_read(&tascam->capture_active))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
guard(spinlock_irqsave)(&tascam->lock);
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
pos = tascam->capture_frames_processed;
|
pos = tascam->capture_frames_processed;
|
||||||
|
|
||||||
if (runtime->buffer_size == 0)
|
if (runtime->buffer_size == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
u64 remainder = do_div(pos, runtime->buffer_size);
|
u64 remainder = do_div(pos, runtime->buffer_size);
|
||||||
return runtime ? remainder : 0;
|
|
||||||
|
return runtime ? remainder : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -95,14 +100,14 @@ tascam_capture_pointer(struct snd_pcm_substream *substream) {
|
||||||
* trigger, and pointer.
|
* trigger, and pointer.
|
||||||
*/
|
*/
|
||||||
const struct snd_pcm_ops tascam_capture_ops = {
|
const struct snd_pcm_ops tascam_capture_ops = {
|
||||||
.open = tascam_capture_open,
|
.open = tascam_capture_open,
|
||||||
.close = tascam_capture_close,
|
.close = tascam_capture_close,
|
||||||
.ioctl = snd_pcm_lib_ioctl,
|
.ioctl = snd_pcm_lib_ioctl,
|
||||||
.hw_params = tascam_pcm_hw_params,
|
.hw_params = tascam_pcm_hw_params,
|
||||||
.hw_free = tascam_pcm_hw_free,
|
.hw_free = tascam_pcm_hw_free,
|
||||||
.prepare = tascam_capture_prepare,
|
.prepare = tascam_capture_prepare,
|
||||||
.trigger = tascam_pcm_trigger,
|
.trigger = tascam_pcm_trigger,
|
||||||
.pointer = tascam_capture_pointer,
|
.pointer = tascam_capture_pointer,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -114,190 +119,207 @@ 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,
|
memset(dst_block, 0,
|
||||||
FRAMES_PER_DECODE_BLOCK * DECODED_CHANNELS_PER_FRAME *
|
FRAMES_PER_DECODE_BLOCK * DECODED_CHANNELS_PER_FRAME *
|
||||||
DECODED_SAMPLE_SIZE);
|
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;
|
||||||
s32 *p_dst_frame = dst_block + frame * 4;
|
s32 *p_dst_frame = dst_block + frame * 4;
|
||||||
|
|
||||||
s32 ch[4] = {0};
|
s32 ch[4] = { 0 };
|
||||||
|
|
||||||
for (bit = 0; bit < 24; ++bit) {
|
for (bit = 0; bit < 24; ++bit) {
|
||||||
u8 byte1 = p_src_frame_base[bit];
|
u8 byte1 = p_src_frame_base[bit];
|
||||||
u8 byte2 = p_src_frame_base[bit + 32];
|
u8 byte2 = p_src_frame_base[bit + 32];
|
||||||
|
|
||||||
ch[0] = (ch[0] << 1) | (byte1 & 1);
|
ch[0] = (ch[0] << 1) | (byte1 & 1);
|
||||||
ch[2] = (ch[2] << 1) | ((byte1 >> 1) & 1);
|
ch[2] = (ch[2] << 1) | ((byte1 >> 1) & 1);
|
||||||
|
|
||||||
ch[1] = (ch[1] << 1) | (byte2 & 1);
|
ch[1] = (ch[1] << 1) | (byte2 & 1);
|
||||||
ch[3] = (ch[3] << 1) | ((byte2 >> 1) & 1);
|
ch[3] = (ch[3] << 1) | ((byte2 >> 1) & 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The result is a 24-bit sample. Shift left by 8 to align it to
|
* The result is a 24-bit sample. Shift left by 8 to align it to
|
||||||
* the most significant bits of a 32-bit integer (S32_LE format).
|
* the most significant bits of a 32-bit integer (S32_LE format).
|
||||||
*/
|
*/
|
||||||
p_dst_frame[0] = ch[0] << 8;
|
p_dst_frame[0] = ch[0] << 8;
|
||||||
p_dst_frame[1] = ch[1] << 8;
|
p_dst_frame[1] = ch[1] << 8;
|
||||||
p_dst_frame[2] = ch[2] << 8;
|
p_dst_frame[2] = ch[2] << 8;
|
||||||
p_dst_frame[3] = ch[3] << 8;
|
p_dst_frame[3] = ch[3] << 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void tascam_capture_work_handler(struct work_struct *work)
|
||||||
* tascam_capture_work_handler() - Deferred work for processing capture data.
|
{
|
||||||
* @work: the work_struct instance
|
struct tascam_card *tascam =
|
||||||
*
|
container_of(work, struct tascam_card, capture_work);
|
||||||
* This function runs in a kernel thread context, not an IRQ context. It reads
|
struct snd_pcm_substream *substream = tascam->capture_substream;
|
||||||
* raw data from the capture ring buffer, decodes it, applies routing, and
|
struct snd_pcm_runtime *runtime;
|
||||||
* copies the final audio data into the ALSA capture ring buffer. This offloads
|
u8 *raw_block = tascam->capture_decode_raw_block;
|
||||||
* * the CPU-intensive decoding from the time-sensitive URB completion handlers.
|
s32 *decoded_block = tascam->capture_decode_dst_block;
|
||||||
*/
|
s32 *routed_block = tascam->capture_routing_buffer;
|
||||||
void tascam_capture_work_handler(struct work_struct *work) {
|
|
||||||
struct tascam_card *tascam =
|
|
||||||
container_of(work, struct tascam_card, capture_work);
|
|
||||||
struct snd_pcm_substream *substream = tascam->capture_substream;
|
|
||||||
struct snd_pcm_runtime *runtime;
|
|
||||||
u8 *raw_block = tascam->capture_decode_raw_block;
|
|
||||||
s32 *decoded_block = tascam->capture_decode_dst_block;
|
|
||||||
s32 *routed_block = tascam->capture_routing_buffer;
|
|
||||||
|
|
||||||
if (!substream || !substream->runtime)
|
if (!substream || !substream->runtime)
|
||||||
return;
|
return;
|
||||||
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,
|
dev_err(tascam->card->dev,
|
||||||
"Capture decode/routing buffers not allocated!\n");
|
"Capture decode/routing buffers not allocated!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (atomic_read(&tascam->capture_active)) {
|
while (atomic_read(&tascam->capture_active)) {
|
||||||
size_t write_ptr, read_ptr, available_data;
|
size_t write_ptr, read_ptr, available_data;
|
||||||
bool can_process;
|
bool can_process;
|
||||||
|
|
||||||
{
|
{
|
||||||
guard(spinlock_irqsave)(&tascam->lock);
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
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)
|
available_data = (write_ptr >= read_ptr) ?
|
||||||
? (write_ptr - read_ptr)
|
(write_ptr - read_ptr) :
|
||||||
: (CAPTURE_RING_BUFFER_SIZE - read_ptr + write_ptr);
|
(CAPTURE_RING_BUFFER_SIZE -
|
||||||
can_process = (available_data >= RAW_BYTES_PER_DECODE_BLOCK);
|
read_ptr + write_ptr);
|
||||||
|
can_process =
|
||||||
|
(available_data >= RAW_BYTES_PER_DECODE_BLOCK);
|
||||||
|
|
||||||
if (can_process) {
|
if (can_process) {
|
||||||
size_t bytes_to_end = CAPTURE_RING_BUFFER_SIZE - read_ptr;
|
size_t bytes_to_end =
|
||||||
if (bytes_to_end >= RAW_BYTES_PER_DECODE_BLOCK) {
|
CAPTURE_RING_BUFFER_SIZE - read_ptr;
|
||||||
memcpy(raw_block, tascam->capture_ring_buffer + read_ptr,
|
if (bytes_to_end >=
|
||||||
RAW_BYTES_PER_DECODE_BLOCK);
|
RAW_BYTES_PER_DECODE_BLOCK) {
|
||||||
} else {
|
memcpy(raw_block,
|
||||||
memcpy(raw_block, tascam->capture_ring_buffer + read_ptr,
|
tascam->capture_ring_buffer +
|
||||||
bytes_to_end);
|
read_ptr,
|
||||||
memcpy(raw_block + bytes_to_end, tascam->capture_ring_buffer,
|
RAW_BYTES_PER_DECODE_BLOCK);
|
||||||
RAW_BYTES_PER_DECODE_BLOCK - bytes_to_end);
|
} else {
|
||||||
}
|
memcpy(raw_block,
|
||||||
tascam->capture_ring_buffer_read_ptr =
|
tascam->capture_ring_buffer +
|
||||||
(read_ptr + RAW_BYTES_PER_DECODE_BLOCK) % CAPTURE_RING_BUFFER_SIZE;
|
read_ptr,
|
||||||
}
|
bytes_to_end);
|
||||||
}
|
memcpy(raw_block + bytes_to_end,
|
||||||
|
tascam->capture_ring_buffer,
|
||||||
|
RAW_BYTES_PER_DECODE_BLOCK -
|
||||||
|
bytes_to_end);
|
||||||
|
}
|
||||||
|
tascam->capture_ring_buffer_read_ptr =
|
||||||
|
(read_ptr +
|
||||||
|
RAW_BYTES_PER_DECODE_BLOCK) %
|
||||||
|
CAPTURE_RING_BUFFER_SIZE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!can_process)
|
if (!can_process)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
decode_tascam_capture_block(raw_block, decoded_block);
|
decode_tascam_capture_block(raw_block, decoded_block);
|
||||||
process_capture_routing_us144mkii(tascam, decoded_block, routed_block);
|
process_capture_routing_us144mkii(tascam, decoded_block,
|
||||||
|
routed_block);
|
||||||
|
|
||||||
{
|
{
|
||||||
guard(spinlock_irqsave)(&tascam->lock);
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
if (atomic_read(&tascam->capture_active)) {
|
if (atomic_read(&tascam->capture_active)) {
|
||||||
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 =
|
u8 *dst_frame_start =
|
||||||
runtime->dma_area +
|
runtime->dma_area +
|
||||||
frames_to_bytes(runtime, tascam->driver_capture_pos);
|
frames_to_bytes(
|
||||||
s32 *routed_frame_start = routed_block + (f * NUM_CHANNELS);
|
runtime,
|
||||||
int c;
|
tascam->driver_capture_pos);
|
||||||
|
s32 *routed_frame_start =
|
||||||
|
routed_block +
|
||||||
|
(f * NUM_CHANNELS);
|
||||||
|
int c;
|
||||||
|
|
||||||
for (c = 0; c < NUM_CHANNELS; c++) {
|
for (c = 0; c < NUM_CHANNELS; c++) {
|
||||||
u8 *dst_channel = dst_frame_start + (c * BYTES_PER_SAMPLE);
|
u8 *dst_channel =
|
||||||
s32 *src_channel_s32 = routed_frame_start + c;
|
dst_frame_start +
|
||||||
|
(c * BYTES_PER_SAMPLE);
|
||||||
|
s32 *src_channel_s32 =
|
||||||
|
routed_frame_start + c;
|
||||||
|
|
||||||
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 =
|
||||||
(tascam->driver_capture_pos + 1) % runtime->buffer_size;
|
(tascam->driver_capture_pos +
|
||||||
}
|
1) %
|
||||||
}
|
runtime->buffer_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void capture_urb_complete(struct urb *urb)
|
||||||
* capture_urb_complete() - Completion handler for capture bulk URBs.
|
{
|
||||||
* @urb: the completed URB
|
struct tascam_card *tascam = urb->context;
|
||||||
*
|
int ret;
|
||||||
* This function runs in interrupt context. It copies the received raw data
|
|
||||||
* into an intermediate ring buffer and then schedules the workqueue to process
|
|
||||||
* it. It then resubmits the URB to receive more data.
|
|
||||||
*/
|
|
||||||
void capture_urb_complete(struct urb *urb) {
|
|
||||||
struct tascam_card *tascam = urb->context;
|
|
||||||
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 != -ENODEV &&
|
urb->status != -ESHUTDOWN && urb->status != -ENODEV &&
|
||||||
urb->status != -EPROTO)
|
urb->status != -EPROTO)
|
||||||
dev_err_ratelimited(tascam->card->dev, "Capture URB failed: %d\n",
|
dev_err_ratelimited(tascam->card->dev,
|
||||||
urb->status);
|
"Capture URB failed: %d\n",
|
||||||
goto out;
|
urb->status);
|
||||||
}
|
goto out;
|
||||||
if (!tascam || !atomic_read(&tascam->capture_active))
|
}
|
||||||
goto out;
|
if (!tascam || !atomic_read(&tascam->capture_active))
|
||||||
|
goto out;
|
||||||
|
|
||||||
if (urb->actual_length > 0) {
|
if (urb->actual_length > 0) {
|
||||||
size_t write_ptr;
|
size_t write_ptr;
|
||||||
size_t bytes_to_end;
|
size_t bytes_to_end;
|
||||||
|
|
||||||
{
|
{
|
||||||
guard(spinlock_irqsave)(&tascam->lock);
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
write_ptr = tascam->capture_ring_buffer_write_ptr;
|
write_ptr = tascam->capture_ring_buffer_write_ptr;
|
||||||
bytes_to_end = CAPTURE_RING_BUFFER_SIZE - write_ptr;
|
bytes_to_end = CAPTURE_RING_BUFFER_SIZE - write_ptr;
|
||||||
|
|
||||||
if (urb->actual_length > bytes_to_end) {
|
if (urb->actual_length > bytes_to_end) {
|
||||||
memcpy(tascam->capture_ring_buffer + write_ptr, urb->transfer_buffer,
|
memcpy(tascam->capture_ring_buffer + write_ptr,
|
||||||
bytes_to_end);
|
urb->transfer_buffer, bytes_to_end);
|
||||||
memcpy(tascam->capture_ring_buffer, urb->transfer_buffer + bytes_to_end,
|
memcpy(tascam->capture_ring_buffer,
|
||||||
urb->actual_length - bytes_to_end);
|
urb->transfer_buffer + bytes_to_end,
|
||||||
} else {
|
urb->actual_length - bytes_to_end);
|
||||||
memcpy(tascam->capture_ring_buffer + write_ptr, urb->transfer_buffer,
|
} else {
|
||||||
urb->actual_length);
|
memcpy(tascam->capture_ring_buffer + write_ptr,
|
||||||
}
|
urb->transfer_buffer,
|
||||||
|
urb->actual_length);
|
||||||
|
}
|
||||||
|
|
||||||
tascam->capture_ring_buffer_write_ptr =
|
tascam->capture_ring_buffer_write_ptr =
|
||||||
(write_ptr + urb->actual_length) % CAPTURE_RING_BUFFER_SIZE;
|
(write_ptr + urb->actual_length) %
|
||||||
}
|
CAPTURE_RING_BUFFER_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
schedule_work(&tascam->capture_work);
|
schedule_work(&tascam->capture_work);
|
||||||
}
|
}
|
||||||
|
|
||||||
usb_get_urb(urb);
|
usb_get_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,
|
dev_err_ratelimited(tascam->card->dev,
|
||||||
"Failed to resubmit capture URB: %d\n", ret);
|
"Failed to resubmit capture URB: %d\n",
|
||||||
usb_unanchor_urb(urb);
|
ret);
|
||||||
usb_put_urb(urb);
|
usb_unanchor_urb(urb);
|
||||||
atomic_dec(&tascam->active_urbs); /* Decrement on failed resubmission */
|
usb_put_urb(urb);
|
||||||
}
|
atomic_dec(
|
||||||
|
&tascam->active_urbs); /* Decrement on failed resubmission */
|
||||||
|
}
|
||||||
out:
|
out:
|
||||||
usb_put_urb(urb);
|
usb_put_urb(urb);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +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",
|
static const char *const playback_source_texts[] = { "Playback 1-2",
|
||||||
"Playback 3-4"};
|
"Playback 3-4" };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Text descriptions for capture input source options.
|
* @brief Text descriptions for capture input source options.
|
||||||
|
|
@ -18,7 +18,7 @@ static const char *const playback_source_texts[] = {"Playback 1-2",
|
||||||
* 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
|
* tascam_playback_source_info() - ALSA control info callback for playback
|
||||||
|
|
@ -33,8 +33,9 @@ static const char *const capture_source_texts[] = {"Analog In", "Digital In"};
|
||||||
* Return: 0 on success.
|
* Return: 0 on success.
|
||||||
*/
|
*/
|
||||||
static int tascam_playback_source_info(struct snd_kcontrol *kcontrol,
|
static int tascam_playback_source_info(struct snd_kcontrol *kcontrol,
|
||||||
struct snd_ctl_elem_info *uinfo) {
|
struct snd_ctl_elem_info *uinfo)
|
||||||
return snd_ctl_enum_info(uinfo, 1, 2, playback_source_texts);
|
{
|
||||||
|
return snd_ctl_enum_info(uinfo, 1, 2, playback_source_texts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -49,11 +50,15 @@ static int tascam_playback_source_info(struct snd_kcontrol *kcontrol,
|
||||||
* Return: 0 on success.
|
* Return: 0 on success.
|
||||||
*/
|
*/
|
||||||
static int tascam_line_out_get(struct snd_kcontrol *kcontrol,
|
static int tascam_line_out_get(struct snd_kcontrol *kcontrol,
|
||||||
struct snd_ctl_elem_value *ucontrol) {
|
struct snd_ctl_elem_value *ucontrol)
|
||||||
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
|
{
|
||||||
|
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
|
||||||
|
int val;
|
||||||
|
|
||||||
ucontrol->value.enumerated.item[0] = tascam->line_out_source;
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
return 0;
|
val = tascam->line_out_source;
|
||||||
|
ucontrol->value.enumerated.item[0] = val;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -68,15 +73,20 @@ static int tascam_line_out_get(struct snd_kcontrol *kcontrol,
|
||||||
* 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,
|
static int tascam_line_out_put(struct snd_kcontrol *kcontrol,
|
||||||
struct snd_ctl_elem_value *ucontrol) {
|
struct snd_ctl_elem_value *ucontrol)
|
||||||
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
|
{
|
||||||
|
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
|
||||||
|
int changed = 0;
|
||||||
|
|
||||||
if (ucontrol->value.enumerated.item[0] > 1)
|
if (ucontrol->value.enumerated.item[0] > 1)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (tascam->line_out_source == ucontrol->value.enumerated.item[0])
|
|
||||||
return 0;
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
tascam->line_out_source = ucontrol->value.enumerated.item[0];
|
if (tascam->line_out_source != ucontrol->value.enumerated.item[0]) {
|
||||||
return 1;
|
tascam->line_out_source = ucontrol->value.enumerated.item[0];
|
||||||
|
changed = 1;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -89,11 +99,11 @@ static int tascam_line_out_put(struct snd_kcontrol *kcontrol,
|
||||||
* handling.
|
* 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,
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
||||||
.name = "Line OUTPUTS Source",
|
.name = "Line OUTPUTS Source",
|
||||||
.info = tascam_playback_source_info,
|
.info = tascam_playback_source_info,
|
||||||
.get = tascam_line_out_get,
|
.get = tascam_line_out_get,
|
||||||
.put = tascam_line_out_put,
|
.put = tascam_line_out_put,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -109,11 +119,15 @@ 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,
|
static int tascam_digital_out_get(struct snd_kcontrol *kcontrol,
|
||||||
struct snd_ctl_elem_value *ucontrol) {
|
struct snd_ctl_elem_value *ucontrol)
|
||||||
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
|
{
|
||||||
|
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
|
||||||
|
int val;
|
||||||
|
|
||||||
ucontrol->value.enumerated.item[0] = tascam->digital_out_source;
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
return 0;
|
val = tascam->digital_out_source;
|
||||||
|
ucontrol->value.enumerated.item[0] = val;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -129,15 +143,20 @@ static int tascam_digital_out_get(struct snd_kcontrol *kcontrol,
|
||||||
* 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,
|
static int tascam_digital_out_put(struct snd_kcontrol *kcontrol,
|
||||||
struct snd_ctl_elem_value *ucontrol) {
|
struct snd_ctl_elem_value *ucontrol)
|
||||||
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
|
{
|
||||||
|
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
|
||||||
|
int changed = 0;
|
||||||
|
|
||||||
if (ucontrol->value.enumerated.item[0] > 1)
|
if (ucontrol->value.enumerated.item[0] > 1)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (tascam->digital_out_source == ucontrol->value.enumerated.item[0])
|
|
||||||
return 0;
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
tascam->digital_out_source = ucontrol->value.enumerated.item[0];
|
if (tascam->digital_out_source != ucontrol->value.enumerated.item[0]) {
|
||||||
return 1;
|
tascam->digital_out_source = ucontrol->value.enumerated.item[0];
|
||||||
|
changed = 1;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -151,11 +170,11 @@ static int tascam_digital_out_put(struct snd_kcontrol *kcontrol,
|
||||||
* handling.
|
* 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,
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
||||||
.name = "Digital OUTPUTS Source",
|
.name = "Digital OUTPUTS Source",
|
||||||
.info = tascam_playback_source_info,
|
.info = tascam_playback_source_info,
|
||||||
.get = tascam_digital_out_get,
|
.get = tascam_digital_out_get,
|
||||||
.put = tascam_digital_out_put,
|
.put = tascam_digital_out_put,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -170,8 +189,9 @@ static const struct snd_kcontrol_new tascam_digital_out_control = {
|
||||||
* Return: 0 on success.
|
* Return: 0 on success.
|
||||||
*/
|
*/
|
||||||
static int tascam_capture_source_info(struct snd_kcontrol *kcontrol,
|
static int tascam_capture_source_info(struct snd_kcontrol *kcontrol,
|
||||||
struct snd_ctl_elem_info *uinfo) {
|
struct snd_ctl_elem_info *uinfo)
|
||||||
return snd_ctl_enum_info(uinfo, 1, 2, capture_source_texts);
|
{
|
||||||
|
return snd_ctl_enum_info(uinfo, 1, 2, capture_source_texts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -187,11 +207,15 @@ static int tascam_capture_source_info(struct snd_kcontrol *kcontrol,
|
||||||
* Return: 0 on success.
|
* Return: 0 on success.
|
||||||
*/
|
*/
|
||||||
static int tascam_capture_12_get(struct snd_kcontrol *kcontrol,
|
static int tascam_capture_12_get(struct snd_kcontrol *kcontrol,
|
||||||
struct snd_ctl_elem_value *ucontrol) {
|
struct snd_ctl_elem_value *ucontrol)
|
||||||
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
|
{
|
||||||
|
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
|
||||||
|
int val;
|
||||||
|
|
||||||
ucontrol->value.enumerated.item[0] = tascam->capture_12_source;
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
return 0;
|
val = tascam->capture_12_source;
|
||||||
|
ucontrol->value.enumerated.item[0] = val;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -207,15 +231,20 @@ static int tascam_capture_12_get(struct snd_kcontrol *kcontrol,
|
||||||
* 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,
|
static int tascam_capture_12_put(struct snd_kcontrol *kcontrol,
|
||||||
struct snd_ctl_elem_value *ucontrol) {
|
struct snd_ctl_elem_value *ucontrol)
|
||||||
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
|
{
|
||||||
|
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
|
||||||
|
int changed = 0;
|
||||||
|
|
||||||
if (ucontrol->value.enumerated.item[0] > 1)
|
if (ucontrol->value.enumerated.item[0] > 1)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (tascam->capture_12_source == ucontrol->value.enumerated.item[0])
|
|
||||||
return 0;
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
tascam->capture_12_source = ucontrol->value.enumerated.item[0];
|
if (tascam->capture_12_source != ucontrol->value.enumerated.item[0]) {
|
||||||
return 1;
|
tascam->capture_12_source = ucontrol->value.enumerated.item[0];
|
||||||
|
changed = 1;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -229,11 +258,11 @@ static int tascam_capture_12_put(struct snd_kcontrol *kcontrol,
|
||||||
* handling.
|
* 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,
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
||||||
.name = "ch1 and ch2 Source",
|
.name = "ch1 and ch2 Source",
|
||||||
.info = tascam_capture_source_info,
|
.info = tascam_capture_source_info,
|
||||||
.get = tascam_capture_12_get,
|
.get = tascam_capture_12_get,
|
||||||
.put = tascam_capture_12_put,
|
.put = tascam_capture_12_put,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -249,11 +278,15 @@ static const struct snd_kcontrol_new tascam_capture_12_control = {
|
||||||
* Return: 0 on success.
|
* Return: 0 on success.
|
||||||
*/
|
*/
|
||||||
static int tascam_capture_34_get(struct snd_kcontrol *kcontrol,
|
static int tascam_capture_34_get(struct snd_kcontrol *kcontrol,
|
||||||
struct snd_ctl_elem_value *ucontrol) {
|
struct snd_ctl_elem_value *ucontrol)
|
||||||
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
|
{
|
||||||
|
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
|
||||||
|
int val;
|
||||||
|
|
||||||
ucontrol->value.enumerated.item[0] = tascam->capture_34_source;
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
return 0;
|
val = tascam->capture_34_source;
|
||||||
|
ucontrol->value.enumerated.item[0] = val;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -269,15 +302,20 @@ static int tascam_capture_34_get(struct snd_kcontrol *kcontrol,
|
||||||
* 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,
|
static int tascam_capture_34_put(struct snd_kcontrol *kcontrol,
|
||||||
struct snd_ctl_elem_value *ucontrol) {
|
struct snd_ctl_elem_value *ucontrol)
|
||||||
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
|
{
|
||||||
|
struct tascam_card *tascam = snd_kcontrol_chip(kcontrol);
|
||||||
|
int changed = 0;
|
||||||
|
|
||||||
if (ucontrol->value.enumerated.item[0] > 1)
|
if (ucontrol->value.enumerated.item[0] > 1)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (tascam->capture_34_source == ucontrol->value.enumerated.item[0])
|
|
||||||
return 0;
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
tascam->capture_34_source = ucontrol->value.enumerated.item[0];
|
if (tascam->capture_34_source != ucontrol->value.enumerated.item[0]) {
|
||||||
return 1;
|
tascam->capture_34_source = ucontrol->value.enumerated.item[0];
|
||||||
|
changed = 1;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -291,11 +329,11 @@ static int tascam_capture_34_put(struct snd_kcontrol *kcontrol,
|
||||||
* `tascam_capture_34_get`/`tascam_capture_34_put` for value handling.
|
* `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,
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
||||||
.name = "ch3 and ch4 Source",
|
.name = "ch3 and ch4 Source",
|
||||||
.info = tascam_capture_source_info,
|
.info = tascam_capture_source_info,
|
||||||
.get = tascam_capture_34_get,
|
.get = tascam_capture_34_get,
|
||||||
.put = tascam_capture_34_put,
|
.put = tascam_capture_34_put,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -309,12 +347,13 @@ 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,
|
static int tascam_samplerate_info(struct snd_kcontrol *kcontrol,
|
||||||
struct snd_ctl_elem_info *uinfo) {
|
struct snd_ctl_elem_info *uinfo)
|
||||||
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
{
|
||||||
uinfo->count = 1;
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
||||||
uinfo->value.integer.min = 0;
|
uinfo->count = 1;
|
||||||
uinfo->value.integer.max = 96000;
|
uinfo->value.integer.min = 0;
|
||||||
return 0;
|
uinfo->value.integer.max = 96000;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -330,31 +369,35 @@ static int tascam_samplerate_info(struct snd_kcontrol *kcontrol,
|
||||||
* 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,
|
static int tascam_samplerate_get(struct snd_kcontrol *kcontrol,
|
||||||
struct snd_ctl_elem_value *ucontrol) {
|
struct snd_ctl_elem_value *ucontrol)
|
||||||
struct tascam_card *tascam =
|
{
|
||||||
(struct tascam_card *)snd_kcontrol_chip(kcontrol);
|
struct tascam_card *tascam =
|
||||||
u8 *buf __free(kfree);
|
(struct tascam_card *)snd_kcontrol_chip(kcontrol);
|
||||||
int err;
|
u8 *buf __free(kfree);
|
||||||
u32 rate = 0;
|
int err;
|
||||||
|
u32 rate = 0;
|
||||||
|
|
||||||
if (tascam->current_rate > 0) {
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
ucontrol->value.integer.value[0] = tascam->current_rate;
|
if (tascam->current_rate > 0) {
|
||||||
return 0;
|
ucontrol->value.integer.value[0] = tascam->current_rate;
|
||||||
}
|
return 0;
|
||||||
|
}
|
||||||
|
// Lock is released here before kmalloc and usb_control_msg
|
||||||
|
|
||||||
buf = kmalloc(3, GFP_KERNEL);
|
buf = kmalloc(3, GFP_KERNEL);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
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_SAMPLING_FREQ_CONTROL,
|
UAC_GET_CUR, RT_D2H_CLASS_EP,
|
||||||
EP_AUDIO_IN, buf, 3, USB_CTRL_TIMEOUT_MS);
|
UAC_SAMPLING_FREQ_CONTROL, EP_AUDIO_IN, 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);
|
||||||
|
|
||||||
ucontrol->value.integer.value[0] = rate;
|
ucontrol->value.integer.value[0] = rate;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -364,48 +407,38 @@ static int tascam_samplerate_get(struct snd_kcontrol *kcontrol,
|
||||||
* the current sample rate of the device. It is a read-only control.
|
* the current sample rate of the device. It is a read-only control.
|
||||||
*/
|
*/
|
||||||
static const struct snd_kcontrol_new tascam_samplerate_control = {
|
static const struct snd_kcontrol_new tascam_samplerate_control = {
|
||||||
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
||||||
.name = "Sample Rate",
|
.name = "Sample Rate",
|
||||||
.info = tascam_samplerate_info,
|
.info = tascam_samplerate_info,
|
||||||
.get = tascam_samplerate_get,
|
.get = tascam_samplerate_get,
|
||||||
.access = SNDRV_CTL_ELEM_ACCESS_READ,
|
.access = SNDRV_CTL_ELEM_ACCESS_READ,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
int tascam_create_controls(struct tascam_card *tascam)
|
||||||
* tascam_create_controls() - Creates and adds ALSA mixer controls for the
|
{
|
||||||
* device.
|
int err;
|
||||||
* @tascam: The driver instance.
|
|
||||||
*
|
|
||||||
* This function registers custom ALSA controls for managing audio routing
|
|
||||||
* (line out source, digital out source, capture 1-2 source, capture 3-4 source)
|
|
||||||
* and displaying the current sample rate.
|
|
||||||
*
|
|
||||||
* Return: 0 on success, or a negative error code on failure.
|
|
||||||
*/
|
|
||||||
int tascam_create_controls(struct tascam_card *tascam) {
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err =
|
err = snd_ctl_add(tascam->card,
|
||||||
snd_ctl_add(tascam->card, snd_ctl_new1(&tascam_line_out_control, tascam));
|
snd_ctl_new1(&tascam_line_out_control, tascam));
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
err = snd_ctl_add(tascam->card,
|
err = snd_ctl_add(tascam->card,
|
||||||
snd_ctl_new1(&tascam_digital_out_control, tascam));
|
snd_ctl_new1(&tascam_digital_out_control, tascam));
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
err = snd_ctl_add(tascam->card,
|
err = snd_ctl_add(tascam->card,
|
||||||
snd_ctl_new1(&tascam_capture_12_control, tascam));
|
snd_ctl_new1(&tascam_capture_12_control, tascam));
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
err = snd_ctl_add(tascam->card,
|
err = snd_ctl_add(tascam->card,
|
||||||
snd_ctl_new1(&tascam_capture_34_control, tascam));
|
snd_ctl_new1(&tascam_capture_34_control, tascam));
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
err = snd_ctl_add(tascam->card,
|
err = snd_ctl_add(tascam->card,
|
||||||
snd_ctl_new1(&tascam_samplerate_control, tascam));
|
snd_ctl_new1(&tascam_samplerate_control, tascam));
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
482
us144mkii_midi.c
482
us144mkii_midi.c
|
|
@ -11,68 +11,64 @@
|
||||||
* 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 =
|
{
|
||||||
container_of(work, struct tascam_card, midi_in_work);
|
struct tascam_card *tascam =
|
||||||
u8 buf[9];
|
container_of(work, struct tascam_card, midi_in_work);
|
||||||
u8 clean_buf[8];
|
u8 buf[9];
|
||||||
unsigned int count, clean_count;
|
u8 clean_buf[8];
|
||||||
|
unsigned int count, clean_count;
|
||||||
|
|
||||||
if (!tascam->midi_in_substream)
|
if (!tascam->midi_in_substream)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (kfifo_out_spinlocked(&tascam->midi_in_fifo, buf, sizeof(buf),
|
while (kfifo_out_spinlocked(&tascam->midi_in_fifo, buf, sizeof(buf),
|
||||||
&tascam->midi_in_lock) == sizeof(buf)) {
|
&tascam->midi_in_lock) == sizeof(buf)) {
|
||||||
clean_count = 0;
|
clean_count = 0;
|
||||||
for (count = 0; count < 8; ++count) {
|
for (count = 0; count < 8; ++count) {
|
||||||
if (buf[count] != 0xfd)
|
if (buf[count] != 0xfd)
|
||||||
clean_buf[clean_count++] = buf[count];
|
clean_buf[clean_count++] = buf[count];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clean_count > 0)
|
if (clean_count > 0)
|
||||||
snd_rawmidi_receive(tascam->midi_in_substream, clean_buf, clean_count);
|
snd_rawmidi_receive(tascam->midi_in_substream,
|
||||||
}
|
clean_buf, clean_count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void tascam_midi_in_urb_complete(struct urb *urb)
|
||||||
* tascam_midi_in_urb_complete() - Completion handler for MIDI IN URBs
|
{
|
||||||
* @urb: The completed URB.
|
struct tascam_card *tascam = urb->context;
|
||||||
*
|
int ret;
|
||||||
* This function runs in interrupt context. It places the raw data from the
|
|
||||||
* USB endpoint into a kfifo and schedules a work item to process it later,
|
|
||||||
* ensuring the interrupt handler remains fast.
|
|
||||||
*/
|
|
||||||
void tascam_midi_in_urb_complete(struct urb *urb) {
|
|
||||||
struct tascam_card *tascam = urb->context;
|
|
||||||
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, "MIDI IN URB failed: status %d\n",
|
dev_err_ratelimited(tascam->card->dev,
|
||||||
urb->status);
|
"MIDI IN URB failed: status %d\n",
|
||||||
}
|
urb->status);
|
||||||
goto out;
|
}
|
||||||
}
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (tascam && atomic_read(&tascam->midi_in_active) &&
|
if (tascam && atomic_read(&tascam->midi_in_active) &&
|
||||||
urb->actual_length > 0) {
|
urb->actual_length > 0) {
|
||||||
kfifo_in_spinlocked(&tascam->midi_in_fifo, urb->transfer_buffer,
|
kfifo_in_spinlocked(&tascam->midi_in_fifo, urb->transfer_buffer,
|
||||||
urb->actual_length, &tascam->midi_in_lock);
|
urb->actual_length, &tascam->midi_in_lock);
|
||||||
schedule_work(&tascam->midi_in_work);
|
schedule_work(&tascam->midi_in_work);
|
||||||
}
|
}
|
||||||
|
|
||||||
usb_get_urb(urb);
|
usb_get_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, "Failed to resubmit MIDI IN URB: error %d\n",
|
dev_err(tascam->card->dev,
|
||||||
ret);
|
"Failed to resubmit MIDI IN URB: error %d\n", ret);
|
||||||
usb_unanchor_urb(urb);
|
usb_unanchor_urb(urb);
|
||||||
usb_put_urb(urb);
|
usb_put_urb(urb);
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
usb_put_urb(urb);
|
usb_put_urb(urb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -84,11 +80,12 @@ 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;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -97,8 +94,9 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -112,35 +110,40 @@ static int tascam_midi_in_close(struct snd_rawmidi_substream *substream) {
|
||||||
* associated workqueue.
|
* associated workqueue.
|
||||||
*/
|
*/
|
||||||
static void tascam_midi_in_trigger(struct snd_rawmidi_substream *substream,
|
static void tascam_midi_in_trigger(struct snd_rawmidi_substream *substream,
|
||||||
int up) {
|
int up)
|
||||||
struct tascam_card *tascam = substream->rmidi->private_data;
|
{
|
||||||
int i, err;
|
struct tascam_card *tascam = substream->rmidi->private_data;
|
||||||
|
int i, err;
|
||||||
|
|
||||||
if (up) {
|
if (up) {
|
||||||
if (atomic_xchg(&tascam->midi_in_active, 1) == 0) {
|
if (atomic_xchg(&tascam->midi_in_active, 1) == 0) {
|
||||||
{
|
{
|
||||||
guard(spinlock_irqsave)(&tascam->midi_in_lock);
|
guard(spinlock_irqsave)(&tascam->midi_in_lock);
|
||||||
kfifo_reset(&tascam->midi_in_fifo);
|
kfifo_reset(&tascam->midi_in_fifo);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < NUM_MIDI_IN_URBS; i++) {
|
for (i = 0; i < NUM_MIDI_IN_URBS; i++) {
|
||||||
usb_get_urb(tascam->midi_in_urbs[i]);
|
usb_get_urb(tascam->midi_in_urbs[i]);
|
||||||
usb_anchor_urb(tascam->midi_in_urbs[i], &tascam->midi_in_anchor);
|
usb_anchor_urb(tascam->midi_in_urbs[i],
|
||||||
err = usb_submit_urb(tascam->midi_in_urbs[i], GFP_KERNEL);
|
&tascam->midi_in_anchor);
|
||||||
if (err < 0) {
|
err = usb_submit_urb(tascam->midi_in_urbs[i],
|
||||||
dev_err(tascam->card->dev, "Failed to submit MIDI IN URB %d: %d\n", i,
|
GFP_KERNEL);
|
||||||
err);
|
if (err < 0) {
|
||||||
usb_unanchor_urb(tascam->midi_in_urbs[i]);
|
dev_err(tascam->card->dev,
|
||||||
usb_put_urb(tascam->midi_in_urbs[i]);
|
"Failed to submit MIDI IN URB %d: %d\n",
|
||||||
}
|
i, err);
|
||||||
}
|
usb_unanchor_urb(
|
||||||
}
|
tascam->midi_in_urbs[i]);
|
||||||
} else {
|
usb_put_urb(tascam->midi_in_urbs[i]);
|
||||||
if (atomic_xchg(&tascam->midi_in_active, 0) == 1) {
|
}
|
||||||
usb_kill_anchored_urbs(&tascam->midi_in_anchor);
|
}
|
||||||
cancel_work_sync(&tascam->midi_in_work);
|
}
|
||||||
}
|
} else {
|
||||||
}
|
if (atomic_xchg(&tascam->midi_in_active, 0) == 1) {
|
||||||
|
usb_kill_anchored_urbs(&tascam->midi_in_anchor);
|
||||||
|
cancel_work_sync(&tascam->midi_in_work);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -150,58 +153,52 @@ static void tascam_midi_in_trigger(struct snd_rawmidi_substream *substream,
|
||||||
* operations, 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,
|
||||||
.close = tascam_midi_in_close,
|
.close = tascam_midi_in_close,
|
||||||
.trigger = tascam_midi_in_trigger,
|
.trigger = tascam_midi_in_trigger,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
void tascam_midi_out_urb_complete(struct urb *urb)
|
||||||
* tascam_midi_out_urb_complete() - Completion handler for MIDI OUT bulk URB.
|
{
|
||||||
* @urb: The completed URB.
|
struct tascam_card *tascam = urb->context;
|
||||||
*
|
int i, urb_index = -1;
|
||||||
* This function runs in interrupt context. It marks the output URB as no
|
|
||||||
* longer in-flight. It then re-schedules the work handler to check for and
|
|
||||||
* send any more data waiting in the ALSA buffer. This is a safe, non-blocking
|
|
||||||
* way to continue the data transmission chain.
|
|
||||||
*/
|
|
||||||
void tascam_midi_out_urb_complete(struct urb *urb) {
|
|
||||||
struct tascam_card *tascam = urb->context;
|
|
||||||
int i, urb_index = -1;
|
|
||||||
|
|
||||||
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 != -ESHUTDOWN) {
|
||||||
dev_err_ratelimited(tascam->card->dev, "MIDI OUT URB failed: %d\n",
|
dev_err_ratelimited(tascam->card->dev,
|
||||||
urb->status);
|
"MIDI OUT URB failed: %d\n",
|
||||||
}
|
urb->status);
|
||||||
goto out;
|
}
|
||||||
}
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (!tascam)
|
if (!tascam)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
for (i = 0; i < NUM_MIDI_OUT_URBS; i++) {
|
for (i = 0; i < NUM_MIDI_OUT_URBS; i++) {
|
||||||
if (tascam->midi_out_urbs[i] == urb) {
|
if (tascam->midi_out_urbs[i] == urb) {
|
||||||
urb_index = i;
|
urb_index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (urb_index < 0) {
|
if (urb_index < 0) {
|
||||||
dev_err_ratelimited(tascam->card->dev, "Unknown MIDI OUT URB completed!\n");
|
dev_err_ratelimited(tascam->card->dev,
|
||||||
goto out;
|
"Unknown MIDI OUT URB completed!\n");
|
||||||
}
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
guard(spinlock_irqsave)(&tascam->midi_out_lock);
|
guard(spinlock_irqsave)(&tascam->midi_out_lock);
|
||||||
clear_bit(urb_index, &tascam->midi_out_urbs_in_flight);
|
clear_bit(urb_index, &tascam->midi_out_urbs_in_flight);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atomic_read(&tascam->midi_out_active))
|
if (atomic_read(&tascam->midi_out_active))
|
||||||
schedule_work(&tascam->midi_out_work);
|
schedule_work(&tascam->midi_out_work);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
usb_put_urb(urb);
|
usb_put_urb(urb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -214,66 +211,73 @@ 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 =
|
{
|
||||||
container_of(work, struct tascam_card, midi_out_work);
|
struct tascam_card *tascam =
|
||||||
struct snd_rawmidi_substream *substream = tascam->midi_out_substream;
|
container_of(work, struct tascam_card, midi_out_work);
|
||||||
int i;
|
struct snd_rawmidi_substream *substream = tascam->midi_out_substream;
|
||||||
|
int i;
|
||||||
|
|
||||||
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) {
|
||||||
int urb_index;
|
int urb_index;
|
||||||
struct urb *urb;
|
struct urb *urb;
|
||||||
u8 *buf;
|
u8 *buf;
|
||||||
int bytes_to_send;
|
int bytes_to_send;
|
||||||
|
|
||||||
{
|
{
|
||||||
guard(spinlock_irqsave)(&tascam->midi_out_lock);
|
guard(spinlock_irqsave)(&tascam->midi_out_lock);
|
||||||
|
|
||||||
urb_index = -1;
|
urb_index = -1;
|
||||||
for (i = 0; i < NUM_MIDI_OUT_URBS; i++) {
|
for (i = 0; i < NUM_MIDI_OUT_URBS; i++) {
|
||||||
if (!test_bit(i, &tascam->midi_out_urbs_in_flight)) {
|
if (!test_bit(
|
||||||
urb_index = i;
|
i,
|
||||||
break;
|
&tascam->midi_out_urbs_in_flight)) {
|
||||||
}
|
urb_index = i;
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (urb_index < 0) {
|
if (urb_index < 0)
|
||||||
return; /* No free URBs, will be rescheduled by completion handler */
|
return; /* No free URBs, will be rescheduled by
|
||||||
}
|
* completion handler
|
||||||
|
*/
|
||||||
|
|
||||||
urb = tascam->midi_out_urbs[urb_index];
|
urb = tascam->midi_out_urbs[urb_index];
|
||||||
buf = urb->transfer_buffer;
|
buf = urb->transfer_buffer;
|
||||||
bytes_to_send = snd_rawmidi_transmit(substream, buf, 8);
|
bytes_to_send = snd_rawmidi_transmit(substream, buf, 8);
|
||||||
|
|
||||||
if (bytes_to_send <= 0) {
|
if (bytes_to_send <= 0)
|
||||||
break; /* No more data */
|
break; /* No more data */
|
||||||
}
|
|
||||||
|
|
||||||
if (bytes_to_send < 9)
|
if (bytes_to_send < 9)
|
||||||
memset(buf + bytes_to_send, 0xfd, 9 - bytes_to_send);
|
memset(buf + bytes_to_send, 0xfd,
|
||||||
buf[8] = 0x00;
|
9 - bytes_to_send);
|
||||||
|
buf[8] = 0x00;
|
||||||
|
|
||||||
set_bit(urb_index, &tascam->midi_out_urbs_in_flight);
|
set_bit(urb_index, &tascam->midi_out_urbs_in_flight);
|
||||||
urb->transfer_buffer_length = 9;
|
urb->transfer_buffer_length = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
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(tascam->card->dev,
|
dev_err_ratelimited(
|
||||||
"Failed to submit MIDI OUT URB %d\n", urb_index);
|
tascam->card->dev,
|
||||||
{
|
"Failed to submit MIDI OUT URB %d\n",
|
||||||
guard(spinlock_irqsave)(&tascam->midi_out_lock);
|
urb_index);
|
||||||
clear_bit(urb_index, &tascam->midi_out_urbs_in_flight);
|
{
|
||||||
}
|
guard(spinlock_irqsave)(&tascam->midi_out_lock);
|
||||||
usb_unanchor_urb(urb);
|
clear_bit(urb_index,
|
||||||
usb_put_urb(urb);
|
&tascam->midi_out_urbs_in_flight);
|
||||||
break; /* Stop on error */
|
}
|
||||||
}
|
usb_unanchor_urb(urb);
|
||||||
}
|
usb_put_urb(urb);
|
||||||
|
break; /* Stop on error */
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -285,13 +289,14 @@ 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;
|
||||||
/* Initialize the running status state for the packet packer. */
|
/* Initialize the running status state for the packet packer. */
|
||||||
tascam->midi_running_status = 0;
|
tascam->midi_running_status = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -300,8 +305,9 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -311,24 +317,25 @@ 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;
|
{
|
||||||
bool in_flight = true;
|
struct tascam_card *tascam = substream->rmidi->private_data;
|
||||||
|
bool in_flight = true;
|
||||||
|
|
||||||
while (in_flight) {
|
while (in_flight) {
|
||||||
in_flight = false;
|
in_flight = false;
|
||||||
for (int i = 0; i < NUM_MIDI_OUT_URBS; i++) {
|
for (int i = 0; i < NUM_MIDI_OUT_URBS; i++) {
|
||||||
if (test_bit(i, &tascam->midi_out_urbs_in_flight)) {
|
if (test_bit(i, &tascam->midi_out_urbs_in_flight)) {
|
||||||
in_flight = true;
|
in_flight = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (in_flight)
|
if (in_flight)
|
||||||
schedule_timeout_uninterruptible(1);
|
schedule_timeout_uninterruptible(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel_work_sync(&tascam->midi_out_work);
|
cancel_work_sync(&tascam->midi_out_work);
|
||||||
usb_kill_anchored_urbs(&tascam->midi_out_anchor);
|
usb_kill_anchored_urbs(&tascam->midi_out_anchor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -340,15 +347,16 @@ static void tascam_midi_out_drain(struct snd_rawmidi_substream *substream) {
|
||||||
* 'up' parameter.
|
* 'up' parameter.
|
||||||
*/
|
*/
|
||||||
static void tascam_midi_out_trigger(struct snd_rawmidi_substream *substream,
|
static void tascam_midi_out_trigger(struct snd_rawmidi_substream *substream,
|
||||||
int up) {
|
int up)
|
||||||
struct tascam_card *tascam = substream->rmidi->private_data;
|
{
|
||||||
|
struct tascam_card *tascam = substream->rmidi->private_data;
|
||||||
|
|
||||||
if (up) {
|
if (up) {
|
||||||
atomic_set(&tascam->midi_out_active, 1);
|
atomic_set(&tascam->midi_out_active, 1);
|
||||||
schedule_work(&tascam->midi_out_work);
|
schedule_work(&tascam->midi_out_work);
|
||||||
} else {
|
} else {
|
||||||
atomic_set(&tascam->midi_out_active, 0);
|
atomic_set(&tascam->midi_out_active, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -358,40 +366,36 @@ static void tascam_midi_out_trigger(struct snd_rawmidi_substream *substream,
|
||||||
* operations, 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,
|
||||||
.close = tascam_midi_out_close,
|
.close = tascam_midi_out_close,
|
||||||
.trigger = tascam_midi_out_trigger,
|
.trigger = tascam_midi_out_trigger,
|
||||||
.drain = tascam_midi_out_drain,
|
.drain = tascam_midi_out_drain,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
int tascam_create_midi(struct tascam_card *tascam)
|
||||||
* tascam_create_midi() - Create and initialize the ALSA rawmidi device.
|
{
|
||||||
* @tascam: The driver instance.
|
int err;
|
||||||
*
|
|
||||||
* Return: 0 on success, or a negative error code on failure.
|
|
||||||
*/
|
|
||||||
int tascam_create_midi(struct tascam_card *tascam) {
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err =
|
err = snd_rawmidi_new(tascam->card, "US144MKII MIDI", 0, 1, 1,
|
||||||
snd_rawmidi_new(tascam->card, "US144MKII MIDI", 0, 1, 1, &tascam->rmidi);
|
&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",
|
||||||
tascam->rmidi->private_data = tascam;
|
sizeof(tascam->rmidi->name));
|
||||||
|
tascam->rmidi->private_data = tascam;
|
||||||
|
|
||||||
snd_rawmidi_set_ops(tascam->rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
|
snd_rawmidi_set_ops(tascam->rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
|
||||||
&tascam_midi_in_ops);
|
&tascam_midi_in_ops);
|
||||||
snd_rawmidi_set_ops(tascam->rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
|
snd_rawmidi_set_ops(tascam->rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
|
||||||
&tascam_midi_out_ops);
|
&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 |
|
||||||
SNDRV_RAWMIDI_INFO_DUPLEX;
|
SNDRV_RAWMIDI_INFO_DUPLEX;
|
||||||
|
|
||||||
INIT_WORK(&tascam->midi_in_work, tascam_midi_in_work_handler);
|
INIT_WORK(&tascam->midi_in_work, tascam_midi_in_work_handler);
|
||||||
INIT_WORK(&tascam->midi_out_work, tascam_midi_out_work_handler);
|
INIT_WORK(&tascam->midi_out_work, tascam_midi_out_work_handler);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
666
us144mkii_pcm.c
666
us144mkii_pcm.c
|
|
@ -15,401 +15,359 @@
|
||||||
* as evenly as possible.
|
* as evenly as possible.
|
||||||
*/
|
*/
|
||||||
static void fpoInitPattern(unsigned int size, unsigned int *pattern_array,
|
static void fpoInitPattern(unsigned int size, unsigned int *pattern_array,
|
||||||
unsigned int initial_value, int target_sum) {
|
unsigned int initial_value, int target_sum)
|
||||||
int diff, i;
|
{
|
||||||
|
int diff, i;
|
||||||
|
|
||||||
if (!size)
|
if (!size)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < size; ++i)
|
for (i = 0; i < size; ++i)
|
||||||
pattern_array[i] = initial_value;
|
pattern_array[i] = initial_value;
|
||||||
|
|
||||||
diff = target_sum - (size * initial_value);
|
diff = target_sum - (size * initial_value);
|
||||||
for (i = 0; i < abs(diff); ++i) {
|
for (i = 0; i < abs(diff); ++i) {
|
||||||
if (diff > 0)
|
if (diff > 0)
|
||||||
pattern_array[i]++;
|
pattern_array[i]++;
|
||||||
else
|
else
|
||||||
pattern_array[i]--;
|
pattern_array[i]--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Rate-to-Packet Fixing Data
|
|
||||||
*
|
|
||||||
* These static arrays define the number of audio frames per USB isochronous
|
|
||||||
* packet for various sample rates. This data is crucial for maintaining
|
|
||||||
* audio synchronization and preventing xruns, as the device's feedback
|
|
||||||
* mechanism indicates how many samples it has consumed.
|
|
||||||
*
|
|
||||||
* The patterns are indexed by a feedback value received from the device,
|
|
||||||
* which helps the driver adjust the packet size dynamically to match the
|
|
||||||
* device's consumption rate.
|
|
||||||
*/
|
|
||||||
|
|
||||||
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 |
|
||||||
SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID |
|
SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID |
|
||||||
SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME),
|
SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME),
|
||||||
.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_min = 44100,
|
||||||
.rate_max = 96000,
|
.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_min = 2,
|
||||||
.periods_max = 1024,
|
.periods_max = 1024,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* process_playback_routing_us144mkii() - Apply playback routing matrix
|
|
||||||
* @tascam: The driver instance.
|
|
||||||
* @src_buffer: Buffer containing 4 channels of S24_3LE audio from ALSA.
|
|
||||||
* @dst_buffer: Buffer to be filled for the USB device.
|
|
||||||
* @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, u8 *dst_buffer,
|
const u8 *src_buffer, u8 *dst_buffer,
|
||||||
size_t frames) {
|
size_t frames)
|
||||||
size_t f;
|
{
|
||||||
const u8 *src_12, *src_34;
|
size_t f;
|
||||||
u8 *dst_line, *dst_digital;
|
const u8 *src_12, *src_34;
|
||||||
|
u8 *dst_line, *dst_digital;
|
||||||
|
|
||||||
for (f = 0; f < frames; ++f) {
|
for (f = 0; f < frames; ++f) {
|
||||||
src_12 = src_buffer + f * BYTES_PER_FRAME;
|
src_12 = src_buffer + f * BYTES_PER_FRAME;
|
||||||
src_34 = src_12 + (2 * BYTES_PER_SAMPLE);
|
src_34 = src_12 + (2 * BYTES_PER_SAMPLE);
|
||||||
dst_line = dst_buffer + f * BYTES_PER_FRAME;
|
dst_line = dst_buffer + f * BYTES_PER_FRAME;
|
||||||
dst_digital = dst_line + (2 * BYTES_PER_SAMPLE);
|
dst_digital = dst_line + (2 * BYTES_PER_SAMPLE);
|
||||||
|
|
||||||
/* LINE OUTPUTS (ch1/2 on device) */
|
/* LINE OUTPUTS (ch1/2 on device) */
|
||||||
if (tascam->line_out_source == 0) /* "ch1 and ch2" */
|
if (tascam->line_out_source == 0) /* "ch1 and ch2" */
|
||||||
memcpy(dst_line, src_12, 2 * BYTES_PER_SAMPLE);
|
memcpy(dst_line, src_12, 2 * BYTES_PER_SAMPLE);
|
||||||
else /* "ch3 and ch4" */
|
else /* "ch3 and ch4" */
|
||||||
memcpy(dst_line, src_34, 2 * BYTES_PER_SAMPLE);
|
memcpy(dst_line, src_34, 2 * BYTES_PER_SAMPLE);
|
||||||
|
|
||||||
/* DIGITAL OUTPUTS (ch3/4 on device) */
|
/* DIGITAL OUTPUTS (ch3/4 on device) */
|
||||||
if (tascam->digital_out_source == 0) /* "ch1 and ch2" */
|
if (tascam->digital_out_source == 0) /* "ch1 and ch2" */
|
||||||
memcpy(dst_digital, src_12, 2 * BYTES_PER_SAMPLE);
|
memcpy(dst_digital, src_12, 2 * BYTES_PER_SAMPLE);
|
||||||
else /* "ch3 and ch4" */
|
else /* "ch3 and ch4" */
|
||||||
memcpy(dst_digital, src_34, 2 * BYTES_PER_SAMPLE);
|
memcpy(dst_digital, src_34, 2 * BYTES_PER_SAMPLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* process_capture_routing_us144mkii() - Apply capture routing matrix
|
|
||||||
* @tascam: The driver instance.
|
|
||||||
* @decoded_block: Buffer containing 4 channels of S32LE decoded audio.
|
|
||||||
* @routed_block: Buffer to be filled for ALSA.
|
|
||||||
*/
|
|
||||||
void process_capture_routing_us144mkii(struct tascam_card *tascam,
|
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;
|
{
|
||||||
const s32 *src_frame;
|
int f;
|
||||||
s32 *dst_frame;
|
const s32 *src_frame;
|
||||||
|
s32 *dst_frame;
|
||||||
|
|
||||||
for (f = 0; f < FRAMES_PER_DECODE_BLOCK; f++) {
|
for (f = 0; f < FRAMES_PER_DECODE_BLOCK; f++) {
|
||||||
src_frame = decoded_block + (f * DECODED_CHANNELS_PER_FRAME);
|
src_frame = decoded_block + (f * DECODED_CHANNELS_PER_FRAME);
|
||||||
dst_frame = routed_block + (f * DECODED_CHANNELS_PER_FRAME);
|
dst_frame = routed_block + (f * DECODED_CHANNELS_PER_FRAME);
|
||||||
|
|
||||||
/* ch1 and ch2 Source */
|
/* ch1 and ch2 Source */
|
||||||
if (tascam->capture_12_source == 0) { /* analog inputs */
|
if (tascam->capture_12_source == 0) { /* analog inputs */
|
||||||
dst_frame[0] = src_frame[0]; /* Analog L */
|
dst_frame[0] = src_frame[0]; /* Analog L */
|
||||||
dst_frame[1] = src_frame[1]; /* Analog R */
|
dst_frame[1] = src_frame[1]; /* Analog R */
|
||||||
} else { /* digital inputs */
|
} else { /* digital inputs */
|
||||||
dst_frame[0] = src_frame[2]; /* Digital L */
|
dst_frame[0] = src_frame[2]; /* Digital L */
|
||||||
dst_frame[1] = src_frame[3]; /* Digital R */
|
dst_frame[1] = src_frame[3]; /* Digital R */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ch3 and ch4 Source */
|
/* ch3 and ch4 Source */
|
||||||
if (tascam->capture_34_source == 0) { /* analog inputs */
|
if (tascam->capture_34_source == 0) { /* analog inputs */
|
||||||
dst_frame[2] = src_frame[0]; /* Analog L (Duplicate) */
|
dst_frame[2] = src_frame[0]; /* Analog L (Duplicate) */
|
||||||
dst_frame[3] = src_frame[1]; /* Analog R (Duplicate) */
|
dst_frame[3] = src_frame[1]; /* Analog R (Duplicate) */
|
||||||
} else { /* digital inputs */
|
} else { /* digital inputs */
|
||||||
dst_frame[2] = src_frame[2]; /* Digital L */
|
dst_frame[2] = src_frame[2]; /* Digital L */
|
||||||
dst_frame[3] = src_frame[3]; /* Digital R */
|
dst_frame[3] = src_frame[3]; /* Digital R */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
int us144mkii_configure_device_for_rate(struct tascam_card *tascam, int rate)
|
||||||
* us144mkii_configure_device_for_rate() - Set sample rate via USB control msgs
|
{
|
||||||
* @tascam: the tascam_card instance
|
struct usb_device *dev = tascam->dev;
|
||||||
* @rate: the target sample rate (e.g., 44100, 96000)
|
u16 rate_vendor_wValue;
|
||||||
*
|
int err = 0;
|
||||||
* This function sends a sequence of vendor-specific and UAC control messages
|
const u8 *current_payload_src;
|
||||||
* to configure the device hardware for the specified sample rate.
|
|
||||||
*
|
|
||||||
* Return: 0 on success, or a negative error code on failure.
|
|
||||||
*/
|
|
||||||
int us144mkii_configure_device_for_rate(struct tascam_card *tascam, int rate) {
|
|
||||||
struct usb_device *dev = tascam->dev;
|
|
||||||
u8 *rate_payload_buf;
|
|
||||||
u16 rate_vendor_wValue;
|
|
||||||
int err = 0;
|
|
||||||
const u8 *current_payload_src;
|
|
||||||
|
|
||||||
static const u8 payload_44100[] = {0x44, 0xac, 0x00};
|
u8 *rate_payload_buf __free(kfree);
|
||||||
static const u8 payload_48000[] = {0x80, 0xbb, 0x00};
|
|
||||||
static const u8 payload_88200[] = {0x88, 0x58, 0x01};
|
|
||||||
static const u8 payload_96000[] = {0x00, 0x77, 0x01};
|
|
||||||
|
|
||||||
switch (rate) {
|
static const u8 payload_44100[] = { 0x44, 0xac, 0x00 };
|
||||||
case 44100:
|
static const u8 payload_48000[] = { 0x80, 0xbb, 0x00 };
|
||||||
current_payload_src = payload_44100;
|
static const u8 payload_88200[] = { 0x88, 0x58, 0x01 };
|
||||||
rate_vendor_wValue = REG_ADDR_RATE_44100;
|
static const u8 payload_96000[] = { 0x00, 0x77, 0x01 };
|
||||||
break;
|
|
||||||
case 48000:
|
|
||||||
current_payload_src = payload_48000;
|
|
||||||
rate_vendor_wValue = REG_ADDR_RATE_48000;
|
|
||||||
break;
|
|
||||||
case 88200:
|
|
||||||
current_payload_src = payload_88200;
|
|
||||||
rate_vendor_wValue = REG_ADDR_RATE_88200;
|
|
||||||
break;
|
|
||||||
case 96000:
|
|
||||||
current_payload_src = payload_96000;
|
|
||||||
rate_vendor_wValue = REG_ADDR_RATE_96000;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dev_err(&dev->dev, "Unsupported sample rate %d for configuration\n", rate);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
rate_payload_buf = kmemdup(current_payload_src, 3, GFP_KERNEL);
|
switch (rate) {
|
||||||
if (!rate_payload_buf)
|
case 44100:
|
||||||
return -ENOMEM;
|
current_payload_src = payload_44100;
|
||||||
|
rate_vendor_wValue = REG_ADDR_RATE_44100;
|
||||||
|
break;
|
||||||
|
case 48000:
|
||||||
|
current_payload_src = payload_48000;
|
||||||
|
rate_vendor_wValue = REG_ADDR_RATE_48000;
|
||||||
|
break;
|
||||||
|
case 88200:
|
||||||
|
current_payload_src = payload_88200;
|
||||||
|
rate_vendor_wValue = REG_ADDR_RATE_88200;
|
||||||
|
break;
|
||||||
|
case 96000:
|
||||||
|
current_payload_src = payload_96000;
|
||||||
|
rate_vendor_wValue = REG_ADDR_RATE_96000;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dev_err(&dev->dev,
|
||||||
|
"Unsupported sample rate %d for configuration\n", rate);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
dev_info(&dev->dev, "Configuring device for %d Hz\n", rate);
|
rate_payload_buf = kmemdup(current_payload_src, 3, GFP_KERNEL);
|
||||||
|
if (!rate_payload_buf)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_MODE_CONTROL,
|
dev_info(&dev->dev, "Configuring device for %d Hz\n", rate);
|
||||||
RT_H2D_VENDOR_DEV, MODE_VAL_CONFIG, 0x0000, NULL, 0,
|
|
||||||
USB_CTRL_TIMEOUT_MS);
|
|
||||||
if (err < 0)
|
|
||||||
goto fail;
|
|
||||||
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
|
|
||||||
RT_H2D_CLASS_EP, UAC_SAMPLING_FREQ_CONTROL, EP_AUDIO_IN,
|
|
||||||
rate_payload_buf, 3, USB_CTRL_TIMEOUT_MS);
|
|
||||||
if (err < 0)
|
|
||||||
goto fail;
|
|
||||||
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
|
|
||||||
RT_H2D_CLASS_EP, UAC_SAMPLING_FREQ_CONTROL,
|
|
||||||
EP_AUDIO_OUT, rate_payload_buf, 3, USB_CTRL_TIMEOUT_MS);
|
|
||||||
if (err < 0)
|
|
||||||
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);
|
|
||||||
if (err < 0)
|
|
||||||
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);
|
|
||||||
if (err < 0)
|
|
||||||
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);
|
|
||||||
if (err < 0)
|
|
||||||
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);
|
|
||||||
if (err < 0)
|
|
||||||
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);
|
|
||||||
if (err < 0)
|
|
||||||
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);
|
|
||||||
if (err < 0)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
kfree(rate_payload_buf);
|
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
||||||
return 0;
|
VENDOR_REQ_MODE_CONTROL, RT_H2D_VENDOR_DEV,
|
||||||
|
MODE_VAL_CONFIG, 0x0000, NULL, 0,
|
||||||
|
USB_CTRL_TIMEOUT_MS);
|
||||||
|
if (err < 0)
|
||||||
|
goto fail;
|
||||||
|
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
|
||||||
|
RT_H2D_CLASS_EP, UAC_SAMPLING_FREQ_CONTROL,
|
||||||
|
EP_AUDIO_IN, rate_payload_buf, 3,
|
||||||
|
USB_CTRL_TIMEOUT_MS);
|
||||||
|
if (err < 0)
|
||||||
|
goto fail;
|
||||||
|
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
|
||||||
|
RT_H2D_CLASS_EP, UAC_SAMPLING_FREQ_CONTROL,
|
||||||
|
EP_AUDIO_OUT, rate_payload_buf, 3,
|
||||||
|
USB_CTRL_TIMEOUT_MS);
|
||||||
|
if (err < 0)
|
||||||
|
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);
|
||||||
|
if (err < 0)
|
||||||
|
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);
|
||||||
|
if (err < 0)
|
||||||
|
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);
|
||||||
|
if (err < 0)
|
||||||
|
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);
|
||||||
|
if (err < 0)
|
||||||
|
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);
|
||||||
|
if (err < 0)
|
||||||
|
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);
|
||||||
|
if (err < 0)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
dev_err(&dev->dev, "Device configuration failed at rate %d with error %d\n",
|
dev_err(&dev->dev,
|
||||||
rate, err);
|
"Device configuration failed at rate %d with error %d\n", rate,
|
||||||
kfree(rate_payload_buf);
|
err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* tascam_pcm_hw_params() - Configures hardware parameters for PCM streams.
|
|
||||||
* @substream: The ALSA PCM substream.
|
|
||||||
* @params: The hardware parameters to apply.
|
|
||||||
*
|
|
||||||
* This function allocates pages for the PCM buffer and, for playback streams,
|
|
||||||
* selects the appropriate feedback patterns based on the requested sample rate.
|
|
||||||
* It also configures the device hardware for the selected sample rate if it
|
|
||||||
* has changed.
|
|
||||||
*
|
|
||||||
* 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);
|
{
|
||||||
int err;
|
struct tascam_card *tascam = snd_pcm_substream_chip(substream);
|
||||||
unsigned int rate = params_rate(params);
|
int err;
|
||||||
|
unsigned int rate = params_rate(params);
|
||||||
|
|
||||||
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
|
||||||
tascam->fpo.sample_rate_khz = rate / 1000;
|
tascam->fpo.sample_rate_khz = rate / 1000;
|
||||||
tascam->fpo.base_feedback_value = tascam->fpo.sample_rate_khz;
|
tascam->fpo.base_feedback_value = tascam->fpo.sample_rate_khz;
|
||||||
tascam->fpo.feedback_offset = 2;
|
tascam->fpo.feedback_offset = 2;
|
||||||
tascam->fpo.current_index = 0;
|
tascam->fpo.current_index = 0;
|
||||||
tascam->fpo.previous_index = 0;
|
tascam->fpo.previous_index = 0;
|
||||||
tascam->fpo.sync_locked = false;
|
tascam->fpo.sync_locked = false;
|
||||||
|
|
||||||
unsigned int initial_value = tascam->fpo.sample_rate_khz / 8;
|
unsigned int initial_value = tascam->fpo.sample_rate_khz / 8;
|
||||||
for (int i = 0; i < 5; i++) {
|
|
||||||
int target_sum =
|
|
||||||
tascam->fpo.sample_rate_khz - tascam->fpo.feedback_offset + i;
|
|
||||||
fpoInitPattern(8, tascam->fpo.full_frame_patterns[i], initial_value,
|
|
||||||
target_sum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tascam->current_rate != rate) {
|
for (int i = 0; i < 5; i++) {
|
||||||
err = us144mkii_configure_device_for_rate(tascam, rate);
|
int target_sum = tascam->fpo.sample_rate_khz -
|
||||||
if (err < 0) {
|
tascam->fpo.feedback_offset + i;
|
||||||
tascam->current_rate = 0;
|
fpoInitPattern(8, tascam->fpo.full_frame_patterns[i],
|
||||||
return err;
|
initial_value, target_sum);
|
||||||
}
|
}
|
||||||
tascam->current_rate = rate;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
if (tascam->current_rate != rate) {
|
||||||
|
err = us144mkii_configure_device_for_rate(tascam, rate);
|
||||||
|
if (err < 0) {
|
||||||
|
tascam->current_rate = 0;
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
tascam->current_rate = rate;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
int tascam_pcm_hw_free(struct snd_pcm_substream *substream)
|
||||||
* tascam_pcm_hw_free() - Frees hardware parameters for PCM streams.
|
{
|
||||||
* @substream: The ALSA PCM substream.
|
return 0;
|
||||||
*
|
|
||||||
* This function frees the pages allocated for the PCM buffer.
|
|
||||||
*
|
|
||||||
* Return: 0 on success.
|
|
||||||
*/
|
|
||||||
int tascam_pcm_hw_free(struct snd_pcm_substream *substream) { return 0; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* tascam_pcm_trigger() - Triggers the start or stop of PCM streams.
|
|
||||||
* @substream: The ALSA PCM substream.
|
|
||||||
* @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
|
|
||||||
* by submitting or killing the associated URBs. It ensures that both streams
|
|
||||||
* are started/stopped together.
|
|
||||||
*
|
|
||||||
* Return: 0 on success, or a negative error code on failure.
|
|
||||||
*/
|
|
||||||
int tascam_pcm_trigger(struct snd_pcm_substream *substream, int cmd) {
|
|
||||||
struct tascam_card *tascam = snd_pcm_substream_chip(substream);
|
|
||||||
int err = 0;
|
|
||||||
int i;
|
|
||||||
bool do_start = false;
|
|
||||||
bool do_stop = false;
|
|
||||||
|
|
||||||
{
|
|
||||||
guard(spinlock_irqsave)(&tascam->lock);
|
|
||||||
switch (cmd) {
|
|
||||||
case SNDRV_PCM_TRIGGER_START:
|
|
||||||
case SNDRV_PCM_TRIGGER_RESUME:
|
|
||||||
if (!atomic_read(&tascam->playback_active)) {
|
|
||||||
atomic_set(&tascam->playback_active, 1);
|
|
||||||
atomic_set(&tascam->capture_active, 1);
|
|
||||||
do_start = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SNDRV_PCM_TRIGGER_STOP:
|
|
||||||
case SNDRV_PCM_TRIGGER_SUSPEND:
|
|
||||||
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
|
||||||
if (atomic_read(&tascam->playback_active)) {
|
|
||||||
atomic_set(&tascam->playback_active, 0);
|
|
||||||
atomic_set(&tascam->capture_active, 0);
|
|
||||||
do_stop = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
err = -EINVAL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (do_start) {
|
|
||||||
if (atomic_read(&tascam->active_urbs) > 0) {
|
|
||||||
dev_WARN(tascam->card->dev, "Cannot start, URBs still active.\n");
|
|
||||||
return -EAGAIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < NUM_FEEDBACK_URBS; i++) {
|
|
||||||
usb_get_urb(tascam->feedback_urbs[i]);
|
|
||||||
usb_anchor_urb(tascam->feedback_urbs[i], &tascam->feedback_anchor);
|
|
||||||
err = usb_submit_urb(tascam->feedback_urbs[i], GFP_ATOMIC);
|
|
||||||
if (err < 0) {
|
|
||||||
usb_unanchor_urb(tascam->feedback_urbs[i]);
|
|
||||||
usb_put_urb(tascam->feedback_urbs[i]);
|
|
||||||
atomic_dec(&tascam->active_urbs);
|
|
||||||
goto start_rollback;
|
|
||||||
}
|
|
||||||
atomic_inc(&tascam->active_urbs);
|
|
||||||
}
|
|
||||||
for (i = 0; i < NUM_PLAYBACK_URBS; i++) {
|
|
||||||
usb_get_urb(tascam->playback_urbs[i]);
|
|
||||||
usb_anchor_urb(tascam->playback_urbs[i], &tascam->playback_anchor);
|
|
||||||
err = usb_submit_urb(tascam->playback_urbs[i], GFP_ATOMIC);
|
|
||||||
if (err < 0) {
|
|
||||||
usb_unanchor_urb(tascam->playback_urbs[i]);
|
|
||||||
usb_put_urb(tascam->playback_urbs[i]);
|
|
||||||
atomic_dec(&tascam->active_urbs);
|
|
||||||
goto start_rollback;
|
|
||||||
}
|
|
||||||
atomic_inc(&tascam->active_urbs);
|
|
||||||
}
|
|
||||||
for (i = 0; i < NUM_CAPTURE_URBS; i++) {
|
|
||||||
usb_get_urb(tascam->capture_urbs[i]);
|
|
||||||
usb_anchor_urb(tascam->capture_urbs[i], &tascam->capture_anchor);
|
|
||||||
err = usb_submit_urb(tascam->capture_urbs[i], GFP_ATOMIC);
|
|
||||||
if (err < 0) {
|
|
||||||
usb_unanchor_urb(tascam->capture_urbs[i]);
|
|
||||||
usb_put_urb(tascam->capture_urbs[i]);
|
|
||||||
atomic_dec(&tascam->active_urbs);
|
|
||||||
goto start_rollback;
|
|
||||||
}
|
|
||||||
atomic_inc(&tascam->active_urbs);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
start_rollback:
|
|
||||||
dev_err(tascam->card->dev, "Failed to submit URBs to start stream: %d\n",
|
|
||||||
err);
|
|
||||||
do_stop = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (do_stop)
|
|
||||||
schedule_work(&tascam->stop_work);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int tascam_init_pcm(struct snd_pcm *pcm) {
|
int tascam_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
|
||||||
struct tascam_card *tascam = pcm->private_data;
|
{
|
||||||
|
struct tascam_card *tascam = snd_pcm_substream_chip(substream);
|
||||||
|
int err = 0;
|
||||||
|
int i;
|
||||||
|
bool do_start = false;
|
||||||
|
bool do_stop = false;
|
||||||
|
|
||||||
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &tascam_playback_ops);
|
{
|
||||||
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &tascam_capture_ops);
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
|
switch (cmd) {
|
||||||
|
case SNDRV_PCM_TRIGGER_START:
|
||||||
|
case SNDRV_PCM_TRIGGER_RESUME:
|
||||||
|
if (!atomic_read(&tascam->playback_active)) {
|
||||||
|
atomic_set(&tascam->playback_active, 1);
|
||||||
|
atomic_set(&tascam->capture_active, 1);
|
||||||
|
do_start = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SNDRV_PCM_TRIGGER_STOP:
|
||||||
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
||||||
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
||||||
|
if (atomic_read(&tascam->playback_active)) {
|
||||||
|
atomic_set(&tascam->playback_active, 0);
|
||||||
|
atomic_set(&tascam->capture_active, 0);
|
||||||
|
do_stop = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
err = -EINVAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
|
if (do_start) {
|
||||||
tascam->dev->dev.parent, 64 * 1024,
|
if (atomic_read(&tascam->active_urbs) > 0) {
|
||||||
tascam_pcm_hw.buffer_bytes_max);
|
dev_WARN(tascam->card->dev,
|
||||||
|
"Cannot start, URBs still active.\n");
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
INIT_WORK(&tascam->capture_work, tascam_capture_work_handler);
|
for (i = 0; i < NUM_FEEDBACK_URBS; i++) {
|
||||||
|
usb_get_urb(tascam->feedback_urbs[i]);
|
||||||
|
usb_anchor_urb(tascam->feedback_urbs[i],
|
||||||
|
&tascam->feedback_anchor);
|
||||||
|
err = usb_submit_urb(tascam->feedback_urbs[i],
|
||||||
|
GFP_ATOMIC);
|
||||||
|
if (err < 0) {
|
||||||
|
usb_unanchor_urb(tascam->feedback_urbs[i]);
|
||||||
|
usb_put_urb(tascam->feedback_urbs[i]);
|
||||||
|
atomic_dec(&tascam->active_urbs);
|
||||||
|
goto start_rollback;
|
||||||
|
}
|
||||||
|
atomic_inc(&tascam->active_urbs);
|
||||||
|
}
|
||||||
|
for (i = 0; i < NUM_PLAYBACK_URBS; i++) {
|
||||||
|
usb_get_urb(tascam->playback_urbs[i]);
|
||||||
|
usb_anchor_urb(tascam->playback_urbs[i],
|
||||||
|
&tascam->playback_anchor);
|
||||||
|
err = usb_submit_urb(tascam->playback_urbs[i],
|
||||||
|
GFP_ATOMIC);
|
||||||
|
if (err < 0) {
|
||||||
|
usb_unanchor_urb(tascam->playback_urbs[i]);
|
||||||
|
usb_put_urb(tascam->playback_urbs[i]);
|
||||||
|
atomic_dec(&tascam->active_urbs);
|
||||||
|
goto start_rollback;
|
||||||
|
}
|
||||||
|
atomic_inc(&tascam->active_urbs);
|
||||||
|
}
|
||||||
|
for (i = 0; i < NUM_CAPTURE_URBS; i++) {
|
||||||
|
usb_get_urb(tascam->capture_urbs[i]);
|
||||||
|
usb_anchor_urb(tascam->capture_urbs[i],
|
||||||
|
&tascam->capture_anchor);
|
||||||
|
err = usb_submit_urb(tascam->capture_urbs[i],
|
||||||
|
GFP_ATOMIC);
|
||||||
|
if (err < 0) {
|
||||||
|
usb_unanchor_urb(tascam->capture_urbs[i]);
|
||||||
|
usb_put_urb(tascam->capture_urbs[i]);
|
||||||
|
atomic_dec(&tascam->active_urbs);
|
||||||
|
goto start_rollback;
|
||||||
|
}
|
||||||
|
atomic_inc(&tascam->active_urbs);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
start_rollback:
|
||||||
|
dev_err(tascam->card->dev,
|
||||||
|
"Failed to submit URBs to start stream: %d\n", err);
|
||||||
|
do_stop = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (do_stop)
|
||||||
|
schedule_work(&tascam->stop_work);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tascam_init_pcm(struct snd_pcm *pcm)
|
||||||
|
{
|
||||||
|
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_CAPTURE, &tascam_capture_ops);
|
||||||
|
|
||||||
|
snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
|
||||||
|
tascam->dev->dev.parent, 64 * 1024,
|
||||||
|
tascam_pcm_hw.buffer_bytes_max);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,18 +17,14 @@ extern const struct snd_pcm_hardware tascam_pcm_hw;
|
||||||
/**
|
/**
|
||||||
* tascam_playback_ops - ALSA PCM operations for playback.
|
* tascam_playback_ops - ALSA PCM operations for playback.
|
||||||
*
|
*
|
||||||
* This structure defines the callback functions for playback stream operations,
|
* This structure defines the callback functions for playback stream operations.
|
||||||
* including open, close, ioctl, hardware parameters, hardware free, prepare,
|
|
||||||
* trigger, and pointer.
|
|
||||||
*/
|
*/
|
||||||
extern const struct snd_pcm_ops tascam_playback_ops;
|
extern const struct snd_pcm_ops tascam_playback_ops;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tascam_capture_ops - ALSA PCM operations for capture.
|
* tascam_capture_ops - ALSA PCM operations for capture.
|
||||||
*
|
*
|
||||||
* This structure defines the callback functions for capture stream operations,
|
* This structure defines the callback functions for capture stream operations.
|
||||||
* including open, close, ioctl, hardware parameters, hardware free, prepare,
|
|
||||||
* trigger, and pointer.
|
|
||||||
*/
|
*/
|
||||||
extern const struct snd_pcm_ops tascam_capture_ops;
|
extern const struct snd_pcm_ops tascam_capture_ops;
|
||||||
|
|
||||||
|
|
@ -38,8 +34,7 @@ extern const struct snd_pcm_ops tascam_capture_ops;
|
||||||
*
|
*
|
||||||
* This function runs in interrupt context. It calculates the number of bytes
|
* This function runs in interrupt context. It calculates the number of bytes
|
||||||
* to send in the next set of packets based on the feedback-driven clock,
|
* to send in the next set of packets based on the feedback-driven clock,
|
||||||
* copies the audio data from the ALSA ring buffer (applying routing), and
|
* copies the audio data from the ALSA ring buffer, and resubmits the URB.
|
||||||
* resubmits the URB.
|
|
||||||
*/
|
*/
|
||||||
void playback_urb_complete(struct urb *urb);
|
void playback_urb_complete(struct urb *urb);
|
||||||
|
|
||||||
|
|
@ -67,45 +62,13 @@ void feedback_urb_complete(struct urb *urb);
|
||||||
void capture_urb_complete(struct urb *urb);
|
void capture_urb_complete(struct urb *urb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* prepare_playback_urb() - Prepares and submits a playback URB.
|
* tascam_stop_pcm_work_handler() - Work handler to stop PCM streams.
|
||||||
* @tascam: the tascam_card instance
|
* @work: Pointer to the work_struct.
|
||||||
*
|
*
|
||||||
* This function gets a free playback URB, calculates the number of frames to
|
* This function is scheduled to stop PCM streams (playback and capture)
|
||||||
* send based on the feedback accumulator, copies audio data from the ALSA
|
* from a workqueue context, avoiding blocking operations in interrupt context.
|
||||||
* ring buffer, applies routing, and submits the URB.
|
|
||||||
*/
|
*/
|
||||||
void prepare_playback_urb(struct tascam_card *tascam);
|
void tascam_stop_pcm_work_handler(struct work_struct *work);
|
||||||
|
|
||||||
/**
|
|
||||||
* feedback_urb_complete() - Completion handler for feedback isochronous URBs.
|
|
||||||
* @urb: the completed URB
|
|
||||||
*
|
|
||||||
* This is the master clock for the driver. It runs in interrupt context.
|
|
||||||
* It reads the feedback value from the device, which indicates how many
|
|
||||||
* samples the device has consumed. This information is used to adjust the
|
|
||||||
* playback rate and to advance the capture stream pointer, keeping both
|
|
||||||
* streams in sync. It then calls snd_pcm_period_elapsed if necessary and
|
|
||||||
* resubmits itself.
|
|
||||||
*/
|
|
||||||
void feedback_urb_complete(struct urb *urb);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* retire_capture_urb() - Completion handler for capture bulk URBs.
|
|
||||||
* @urb: the completed URB
|
|
||||||
*
|
|
||||||
* This function runs in interrupt context. It copies the received raw data
|
|
||||||
* into an intermediate ring buffer and then schedules the workqueue to process
|
|
||||||
* it. It then calls prepare_capture_urb() to submit the next URB.
|
|
||||||
*/
|
|
||||||
void retire_capture_urb(struct urb *urb);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* prepare_capture_urb() - Prepares and submits a capture URB.
|
|
||||||
* @tascam: the tascam_card instance
|
|
||||||
*
|
|
||||||
* This function gets a free capture URB from the anchor and submits it.
|
|
||||||
*/
|
|
||||||
void prepare_capture_urb(struct tascam_card *tascam);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tascam_init_pcm() - Initializes the ALSA PCM device.
|
* tascam_init_pcm() - Initializes the ALSA PCM device.
|
||||||
|
|
@ -138,8 +101,8 @@ int us144mkii_configure_device_for_rate(struct tascam_card *tascam, int rate);
|
||||||
* @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, u8 *dst_buffer,
|
const u8 *src_buffer, u8 *dst_buffer,
|
||||||
size_t frames);
|
size_t frames);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* process_capture_routing_us144mkii() - Apply capture routing matrix
|
* process_capture_routing_us144mkii() - Apply capture routing matrix
|
||||||
|
|
@ -148,8 +111,8 @@ void process_playback_routing_us144mkii(struct tascam_card *tascam,
|
||||||
* @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,
|
void process_capture_routing_us144mkii(struct tascam_card *tascam,
|
||||||
const s32 *decoded_block,
|
const s32 *decoded_block,
|
||||||
s32 *routed_block);
|
s32 *routed_block);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tascam_pcm_hw_params() - Configures hardware parameters for PCM streams.
|
* tascam_pcm_hw_params() - Configures hardware parameters for PCM streams.
|
||||||
|
|
@ -164,13 +127,13 @@ 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 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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tascam_pcm_hw_free() - Frees hardware parameters for PCM streams.
|
* tascam_pcm_hw_free() - Frees hardware parameters for PCM streams.
|
||||||
* @substream: The ALSA PCM substream.
|
* @substream: The ALSA PCM substream.
|
||||||
*
|
*
|
||||||
* This function frees the pages allocated for the PCM buffer.
|
* This function is a stub for freeing hardware-related resources.
|
||||||
*
|
*
|
||||||
* Return: 0 on success.
|
* Return: 0 on success.
|
||||||
*/
|
*/
|
||||||
|
|
@ -179,12 +142,10 @@ 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,
|
* @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.
|
||||||
* are started/stopped together.
|
|
||||||
*
|
*
|
||||||
* Return: 0 on success, or a negative error code on failure.
|
* Return: 0 on success, or a negative error code on failure.
|
||||||
*/
|
*/
|
||||||
|
|
@ -197,7 +158,7 @@ int tascam_pcm_trigger(struct snd_pcm_substream *substream, int cmd);
|
||||||
* This function runs in a kernel thread context, not an IRQ context. It reads
|
* This function runs in a kernel thread context, not an IRQ context. It reads
|
||||||
* raw data from the capture ring buffer, decodes it, applies routing, and
|
* raw data from the capture ring buffer, decodes it, applies routing, and
|
||||||
* copies the final audio data into the ALSA capture ring buffer. This offloads
|
* 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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,15 @@
|
||||||
*
|
*
|
||||||
* 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;
|
||||||
tascam->playback_substream = substream;
|
tascam->playback_substream = substream;
|
||||||
atomic_set(&tascam->playback_active, 0);
|
atomic_set(&tascam->playback_active, 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -31,12 +32,13 @@ 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;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -45,58 +47,65 @@ static int tascam_playback_close(struct snd_pcm_substream *substream) {
|
||||||
*
|
*
|
||||||
* This function initializes playback-related counters and flags, and configures
|
* This function initializes playback-related counters and flags, and configures
|
||||||
* the playback URBs with appropriate packet sizes based on the nominal frame
|
* the playback URBs with appropriate packet sizes based on the nominal frame
|
||||||
* rate and feedback accumulator.
|
* rate.
|
||||||
*
|
*
|
||||||
* 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 snd_pcm_runtime *runtime = substream->runtime;
|
struct tascam_card *tascam = snd_pcm_substream_chip(substream);
|
||||||
int i, u;
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
||||||
size_t nominal_frames_per_packet, nominal_bytes_per_packet;
|
int i, u;
|
||||||
size_t total_bytes_in_urb;
|
size_t nominal_frames_per_packet, nominal_bytes_per_packet;
|
||||||
|
size_t total_bytes_in_urb;
|
||||||
|
|
||||||
tascam->driver_playback_pos = 0;
|
tascam->driver_playback_pos = 0;
|
||||||
tascam->playback_frames_consumed = 0;
|
tascam->playback_frames_consumed = 0;
|
||||||
tascam->last_period_pos = 0;
|
tascam->last_period_pos = 0;
|
||||||
tascam->feedback_pattern_in_idx = 0;
|
tascam->feedback_pattern_in_idx = 0;
|
||||||
tascam->feedback_pattern_out_idx = 0;
|
tascam->feedback_pattern_out_idx = 0;
|
||||||
tascam->feedback_synced = false;
|
tascam->feedback_synced = false;
|
||||||
tascam->feedback_consecutive_errors = 0;
|
tascam->feedback_consecutive_errors = 0;
|
||||||
tascam->feedback_urb_skip_count = NUM_FEEDBACK_URBS;
|
tascam->feedback_urb_skip_count = NUM_FEEDBACK_URBS;
|
||||||
|
|
||||||
nominal_frames_per_packet = runtime->rate / 8000;
|
nominal_frames_per_packet = runtime->rate / 8000;
|
||||||
for (i = 0; i < FEEDBACK_ACCUMULATOR_SIZE; i++)
|
for (i = 0; i < FEEDBACK_ACCUMULATOR_SIZE; i++)
|
||||||
tascam->feedback_accumulator_pattern[i] = nominal_frames_per_packet;
|
tascam->feedback_accumulator_pattern[i] =
|
||||||
|
nominal_frames_per_packet;
|
||||||
|
|
||||||
for (i = 0; i < NUM_FEEDBACK_URBS; i++) {
|
for (i = 0; i < NUM_FEEDBACK_URBS; i++) {
|
||||||
struct urb *f_urb = tascam->feedback_urbs[i];
|
struct urb *f_urb = tascam->feedback_urbs[i];
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
f_urb->number_of_packets = FEEDBACK_URB_PACKETS;
|
f_urb->number_of_packets = FEEDBACK_URB_PACKETS;
|
||||||
f_urb->transfer_buffer_length = FEEDBACK_URB_PACKETS * FEEDBACK_PACKET_SIZE;
|
f_urb->transfer_buffer_length =
|
||||||
for (j = 0; j < FEEDBACK_URB_PACKETS; j++) {
|
FEEDBACK_URB_PACKETS * FEEDBACK_PACKET_SIZE;
|
||||||
f_urb->iso_frame_desc[j].offset = j * FEEDBACK_PACKET_SIZE;
|
for (j = 0; j < FEEDBACK_URB_PACKETS; j++) {
|
||||||
f_urb->iso_frame_desc[j].length = FEEDBACK_PACKET_SIZE;
|
f_urb->iso_frame_desc[j].offset =
|
||||||
}
|
j * FEEDBACK_PACKET_SIZE;
|
||||||
}
|
f_urb->iso_frame_desc[j].length = FEEDBACK_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nominal_bytes_per_packet = nominal_frames_per_packet * BYTES_PER_FRAME;
|
nominal_bytes_per_packet = nominal_frames_per_packet * BYTES_PER_FRAME;
|
||||||
total_bytes_in_urb = nominal_bytes_per_packet * PLAYBACK_URB_PACKETS;
|
total_bytes_in_urb = nominal_bytes_per_packet * PLAYBACK_URB_PACKETS;
|
||||||
|
|
||||||
for (u = 0; u < NUM_PLAYBACK_URBS; u++) {
|
for (u = 0; u < NUM_PLAYBACK_URBS; u++) {
|
||||||
struct urb *urb = tascam->playback_urbs[u];
|
struct urb *urb = tascam->playback_urbs[u];
|
||||||
|
|
||||||
memset(urb->transfer_buffer, 0, tascam->playback_urb_alloc_size);
|
memset(urb->transfer_buffer, 0,
|
||||||
urb->transfer_buffer_length = total_bytes_in_urb;
|
tascam->playback_urb_alloc_size);
|
||||||
urb->number_of_packets = PLAYBACK_URB_PACKETS;
|
urb->transfer_buffer_length = total_bytes_in_urb;
|
||||||
for (i = 0; i < PLAYBACK_URB_PACKETS; i++) {
|
urb->number_of_packets = PLAYBACK_URB_PACKETS;
|
||||||
urb->iso_frame_desc[i].offset = i * nominal_bytes_per_packet;
|
for (i = 0; i < PLAYBACK_URB_PACKETS; i++) {
|
||||||
urb->iso_frame_desc[i].length = nominal_bytes_per_packet;
|
urb->iso_frame_desc[i].offset =
|
||||||
}
|
i * nominal_bytes_per_packet;
|
||||||
}
|
urb->iso_frame_desc[i].length =
|
||||||
|
nominal_bytes_per_packet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -109,22 +118,24 @@ 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
|
static snd_pcm_uframes_t
|
||||||
tascam_playback_pointer(struct snd_pcm_substream *substream) {
|
tascam_playback_pointer(struct snd_pcm_substream *substream)
|
||||||
struct tascam_card *tascam = snd_pcm_substream_chip(substream);
|
{
|
||||||
struct snd_pcm_runtime *runtime = substream->runtime;
|
struct tascam_card *tascam = snd_pcm_substream_chip(substream);
|
||||||
u64 pos;
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
||||||
|
u64 pos;
|
||||||
|
|
||||||
if (!atomic_read(&tascam->playback_active))
|
if (!atomic_read(&tascam->playback_active))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
guard(spinlock_irqsave)(&tascam->lock);
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
pos = tascam->playback_frames_consumed;
|
pos = tascam->playback_frames_consumed;
|
||||||
|
|
||||||
if (runtime->buffer_size == 0)
|
if (runtime->buffer_size == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
u64 remainder = do_div(pos, runtime->buffer_size);
|
u64 remainder = do_div(pos, runtime->buffer_size);
|
||||||
return runtime ? remainder : 0;
|
|
||||||
|
return runtime ? remainder : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -135,309 +146,318 @@ tascam_playback_pointer(struct snd_pcm_substream *substream) {
|
||||||
* trigger, and pointer.
|
* trigger, and pointer.
|
||||||
*/
|
*/
|
||||||
const struct snd_pcm_ops tascam_playback_ops = {
|
const struct snd_pcm_ops tascam_playback_ops = {
|
||||||
.open = tascam_playback_open,
|
.open = tascam_playback_open,
|
||||||
.close = tascam_playback_close,
|
.close = tascam_playback_close,
|
||||||
.ioctl = snd_pcm_lib_ioctl,
|
.ioctl = snd_pcm_lib_ioctl,
|
||||||
.hw_params = tascam_pcm_hw_params,
|
.hw_params = tascam_pcm_hw_params,
|
||||||
.hw_free = tascam_pcm_hw_free,
|
.hw_free = tascam_pcm_hw_free,
|
||||||
.prepare = tascam_playback_prepare,
|
.prepare = tascam_playback_prepare,
|
||||||
.trigger = tascam_pcm_trigger,
|
.trigger = tascam_pcm_trigger,
|
||||||
.pointer = tascam_playback_pointer,
|
.pointer = tascam_playback_pointer,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
void playback_urb_complete(struct urb *urb)
|
||||||
* playback_urb_complete() - Completion handler for playback isochronous URBs.
|
{
|
||||||
* @urb: the completed URB
|
struct tascam_card *tascam = urb->context;
|
||||||
*
|
struct snd_pcm_substream *substream;
|
||||||
* This function runs in interrupt context. It calculates the number of bytes
|
struct snd_pcm_runtime *runtime;
|
||||||
* to send in the next set of packets based on the feedback-driven clock,
|
size_t total_bytes_for_urb = 0;
|
||||||
* copies the audio data from the ALSA ring buffer (applying routing), and
|
snd_pcm_uframes_t offset_frames;
|
||||||
* resubmits the URB.
|
snd_pcm_uframes_t frames_to_copy;
|
||||||
*/
|
int ret, i;
|
||||||
void playback_urb_complete(struct urb *urb) {
|
|
||||||
struct tascam_card *tascam = urb->context;
|
|
||||||
struct snd_pcm_substream *substream;
|
|
||||||
struct snd_pcm_runtime *runtime;
|
|
||||||
|
|
||||||
size_t total_bytes_for_urb = 0;
|
if (urb->status) {
|
||||||
snd_pcm_uframes_t offset_frames;
|
if (urb->status != -ENOENT && urb->status != -ECONNRESET &&
|
||||||
snd_pcm_uframes_t frames_to_copy;
|
urb->status != -ESHUTDOWN && urb->status != -ENODEV)
|
||||||
int ret, i;
|
dev_err_ratelimited(tascam->card->dev,
|
||||||
|
"Playback URB failed: %d\n",
|
||||||
|
urb->status);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
if (!tascam || !atomic_read(&tascam->playback_active))
|
||||||
|
goto out;
|
||||||
|
|
||||||
if (urb->status) {
|
substream = tascam->playback_substream;
|
||||||
if (urb->status != -ENOENT && urb->status != -ECONNRESET &&
|
if (!substream || !substream->runtime)
|
||||||
urb->status != -ESHUTDOWN && urb->status != -ENODEV)
|
goto out;
|
||||||
dev_err_ratelimited(tascam->card->dev, "Playback URB failed: %d\n",
|
runtime = substream->runtime;
|
||||||
urb->status);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
if (!tascam || !atomic_read(&tascam->playback_active))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
substream = tascam->playback_substream;
|
{
|
||||||
if (!substream || !substream->runtime)
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
goto out;
|
|
||||||
runtime = substream->runtime;
|
|
||||||
|
|
||||||
{
|
for (i = 0; i < urb->number_of_packets; i++) {
|
||||||
guard(spinlock_irqsave)(&tascam->lock);
|
unsigned int frames_for_packet;
|
||||||
|
size_t bytes_for_packet;
|
||||||
|
|
||||||
for (i = 0; i < urb->number_of_packets; i++) {
|
if (tascam->feedback_synced) {
|
||||||
unsigned int frames_for_packet;
|
frames_for_packet =
|
||||||
size_t bytes_for_packet;
|
tascam->feedback_accumulator_pattern
|
||||||
|
[tascam->feedback_pattern_out_idx];
|
||||||
|
tascam->feedback_pattern_out_idx =
|
||||||
|
(tascam->feedback_pattern_out_idx + 1) %
|
||||||
|
FEEDBACK_ACCUMULATOR_SIZE;
|
||||||
|
} else {
|
||||||
|
frames_for_packet = runtime->rate / 8000;
|
||||||
|
}
|
||||||
|
bytes_for_packet = frames_for_packet * BYTES_PER_FRAME;
|
||||||
|
|
||||||
if (tascam->feedback_synced) {
|
urb->iso_frame_desc[i].offset = total_bytes_for_urb;
|
||||||
frames_for_packet = tascam->feedback_accumulator_pattern
|
urb->iso_frame_desc[i].length = bytes_for_packet;
|
||||||
[tascam->feedback_pattern_out_idx];
|
total_bytes_for_urb += bytes_for_packet;
|
||||||
tascam->feedback_pattern_out_idx =
|
}
|
||||||
(tascam->feedback_pattern_out_idx + 1) % FEEDBACK_ACCUMULATOR_SIZE;
|
urb->transfer_buffer_length = total_bytes_for_urb;
|
||||||
} else {
|
|
||||||
frames_for_packet = runtime->rate / 8000;
|
|
||||||
}
|
|
||||||
bytes_for_packet = frames_for_packet * BYTES_PER_FRAME;
|
|
||||||
|
|
||||||
urb->iso_frame_desc[i].offset = total_bytes_for_urb;
|
offset_frames = tascam->driver_playback_pos;
|
||||||
urb->iso_frame_desc[i].length = bytes_for_packet;
|
frames_to_copy = bytes_to_frames(runtime, total_bytes_for_urb);
|
||||||
total_bytes_for_urb += bytes_for_packet;
|
tascam->driver_playback_pos =
|
||||||
}
|
(offset_frames + frames_to_copy) % runtime->buffer_size;
|
||||||
urb->transfer_buffer_length = total_bytes_for_urb;
|
}
|
||||||
|
|
||||||
offset_frames = tascam->driver_playback_pos;
|
if (total_bytes_for_urb > 0) {
|
||||||
frames_to_copy = bytes_to_frames(runtime, total_bytes_for_urb);
|
u8 *dst_buf = urb->transfer_buffer;
|
||||||
tascam->driver_playback_pos =
|
|
||||||
(offset_frames + frames_to_copy) % runtime->buffer_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (total_bytes_for_urb > 0) {
|
/* Handle ring buffer wrap-around */
|
||||||
u8 *dst_buf = urb->transfer_buffer;
|
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 second_chunk_bytes =
|
||||||
|
total_bytes_for_urb - first_chunk_bytes;
|
||||||
|
|
||||||
/* Handle ring buffer wrap-around */
|
memcpy(dst_buf,
|
||||||
if (offset_frames + frames_to_copy > runtime->buffer_size) {
|
runtime->dma_area +
|
||||||
size_t first_chunk_bytes =
|
frames_to_bytes(runtime, offset_frames),
|
||||||
frames_to_bytes(runtime, runtime->buffer_size - offset_frames);
|
first_chunk_bytes);
|
||||||
size_t second_chunk_bytes = total_bytes_for_urb - first_chunk_bytes;
|
memcpy(dst_buf + first_chunk_bytes, runtime->dma_area,
|
||||||
|
second_chunk_bytes);
|
||||||
|
} else {
|
||||||
|
memcpy(dst_buf,
|
||||||
|
runtime->dma_area +
|
||||||
|
frames_to_bytes(runtime, offset_frames),
|
||||||
|
total_bytes_for_urb);
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(dst_buf,
|
process_playback_routing_us144mkii(tascam, dst_buf, dst_buf,
|
||||||
runtime->dma_area + frames_to_bytes(runtime, offset_frames),
|
frames_to_copy);
|
||||||
first_chunk_bytes);
|
}
|
||||||
memcpy(dst_buf + first_chunk_bytes, runtime->dma_area,
|
|
||||||
second_chunk_bytes);
|
|
||||||
} else {
|
|
||||||
memcpy(dst_buf,
|
|
||||||
runtime->dma_area + frames_to_bytes(runtime, offset_frames),
|
|
||||||
total_bytes_for_urb);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Apply routing to the contiguous data in our routing buffer */
|
urb->dev = tascam->dev;
|
||||||
process_playback_routing_us144mkii(tascam, dst_buf, dst_buf,
|
usb_get_urb(urb);
|
||||||
frames_to_copy);
|
usb_anchor_urb(urb, &tascam->playback_anchor);
|
||||||
}
|
ret = usb_submit_urb(urb, GFP_ATOMIC);
|
||||||
|
if (ret < 0) {
|
||||||
urb->dev = tascam->dev;
|
dev_err_ratelimited(tascam->card->dev,
|
||||||
usb_get_urb(urb);
|
"Failed to resubmit playback URB: %d\n",
|
||||||
usb_anchor_urb(urb, &tascam->playback_anchor);
|
ret);
|
||||||
ret = usb_submit_urb(urb, GFP_ATOMIC);
|
usb_unanchor_urb(urb);
|
||||||
if (ret < 0) {
|
usb_put_urb(urb);
|
||||||
dev_err_ratelimited(tascam->card->dev,
|
atomic_dec(
|
||||||
"Failed to resubmit playback URB: %d\n", ret);
|
&tascam->active_urbs); /* Decrement on failed resubmission */
|
||||||
usb_unanchor_urb(urb);
|
}
|
||||||
usb_put_urb(urb);
|
|
||||||
atomic_dec(&tascam->active_urbs); /* Decrement on failed resubmission */
|
|
||||||
}
|
|
||||||
out:
|
out:
|
||||||
usb_put_urb(urb);
|
usb_put_urb(urb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void feedback_urb_complete(struct urb *urb)
|
||||||
* feedback_urb_complete() - Completion handler for feedback isochronous URBs.
|
{
|
||||||
* @urb: the completed URB
|
struct tascam_card *tascam = urb->context;
|
||||||
*
|
struct snd_pcm_substream *playback_ss, *capture_ss;
|
||||||
* This is the master clock for the driver. It runs in interrupt context.
|
struct snd_pcm_runtime *playback_rt, *capture_rt;
|
||||||
* It reads the feedback value from the device, which indicates how many
|
u64 total_frames_in_urb = 0;
|
||||||
* samples the device has consumed. This information is used to adjust the
|
int ret, p;
|
||||||
* playback rate and to advance the capture stream pointer, keeping both
|
unsigned int old_in_idx, new_in_idx;
|
||||||
* streams in sync. It then calls snd_pcm_period_elapsed if necessary and
|
bool playback_period_elapsed = false;
|
||||||
* resubmits itself.
|
bool capture_period_elapsed = false;
|
||||||
*/
|
|
||||||
void feedback_urb_complete(struct urb *urb) {
|
|
||||||
struct tascam_card *tascam = urb->context;
|
|
||||||
struct snd_pcm_substream *playback_ss, *capture_ss;
|
|
||||||
struct snd_pcm_runtime *playback_rt, *capture_rt;
|
|
||||||
u64 total_frames_in_urb = 0;
|
|
||||||
int ret, p;
|
|
||||||
unsigned int old_in_idx, new_in_idx;
|
|
||||||
bool playback_period_elapsed = false;
|
|
||||||
bool capture_period_elapsed = false;
|
|
||||||
|
|
||||||
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 != -ENODEV) {
|
urb->status != -ESHUTDOWN && urb->status != -ENODEV) {
|
||||||
dev_err_ratelimited(tascam->card->dev, "Feedback URB failed: %d\n",
|
dev_err_ratelimited(tascam->card->dev,
|
||||||
urb->status);
|
"Feedback URB failed: %d\n",
|
||||||
atomic_dec(&tascam->active_urbs); /* Decrement on failed resubmission */
|
urb->status);
|
||||||
}
|
atomic_dec(
|
||||||
goto out;
|
&tascam->active_urbs); /* Decrement on failed resubmission */
|
||||||
}
|
}
|
||||||
if (!tascam || !atomic_read(&tascam->playback_active))
|
goto out;
|
||||||
goto out;
|
}
|
||||||
|
if (!tascam || !atomic_read(&tascam->playback_active))
|
||||||
|
goto out;
|
||||||
|
|
||||||
playback_ss = tascam->playback_substream;
|
playback_ss = tascam->playback_substream;
|
||||||
if (!playback_ss || !playback_ss->runtime)
|
if (!playback_ss || !playback_ss->runtime)
|
||||||
goto out;
|
goto out;
|
||||||
playback_rt = playback_ss->runtime;
|
playback_rt = playback_ss->runtime;
|
||||||
|
|
||||||
capture_ss = tascam->capture_substream;
|
capture_ss = tascam->capture_substream;
|
||||||
capture_rt = capture_ss ? capture_ss->runtime : NULL;
|
capture_rt = capture_ss ? capture_ss->runtime : NULL;
|
||||||
|
|
||||||
{
|
{
|
||||||
guard(spinlock_irqsave)(&tascam->lock);
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
|
|
||||||
if (tascam->feedback_urb_skip_count > 0) {
|
if (tascam->feedback_urb_skip_count > 0) {
|
||||||
tascam->feedback_urb_skip_count--;
|
tascam->feedback_urb_skip_count--;
|
||||||
goto continue_unlock;
|
goto continue_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
old_in_idx = tascam->feedback_pattern_in_idx;
|
old_in_idx = tascam->feedback_pattern_in_idx;
|
||||||
|
|
||||||
for (p = 0; p < urb->number_of_packets; p++) {
|
for (p = 0; p < urb->number_of_packets; p++) {
|
||||||
u8 feedback_value = 0;
|
u8 feedback_value = 0;
|
||||||
const unsigned int *pattern;
|
const unsigned int *pattern;
|
||||||
bool packet_ok = (urb->iso_frame_desc[p].status == 0 &&
|
bool packet_ok =
|
||||||
urb->iso_frame_desc[p].actual_length >= 1);
|
(urb->iso_frame_desc[p].status == 0 &&
|
||||||
|
urb->iso_frame_desc[p].actual_length >= 1);
|
||||||
|
|
||||||
if (packet_ok)
|
if (packet_ok)
|
||||||
feedback_value =
|
feedback_value =
|
||||||
*((u8 *)urb->transfer_buffer + urb->iso_frame_desc[p].offset);
|
*((u8 *)urb->transfer_buffer +
|
||||||
|
urb->iso_frame_desc[p].offset);
|
||||||
|
|
||||||
if (packet_ok) {
|
if (packet_ok) {
|
||||||
int delta = feedback_value - tascam->fpo.base_feedback_value +
|
int delta = feedback_value -
|
||||||
tascam->fpo.feedback_offset;
|
tascam->fpo.base_feedback_value +
|
||||||
int pattern_idx;
|
tascam->fpo.feedback_offset;
|
||||||
|
int pattern_idx;
|
||||||
|
|
||||||
if (delta < 0) {
|
if (delta < 0) {
|
||||||
pattern_idx = 0; // Clamp to the lowest pattern
|
pattern_idx =
|
||||||
} else if (delta >= 5) {
|
0; // Clamp to the lowest pattern
|
||||||
pattern_idx = 4; // Clamp to the highest pattern
|
} else if (delta >= 5) {
|
||||||
} else {
|
pattern_idx =
|
||||||
pattern_idx = delta;
|
4; // Clamp to the highest pattern
|
||||||
}
|
} else {
|
||||||
|
pattern_idx = delta;
|
||||||
|
}
|
||||||
|
|
||||||
pattern = tascam->fpo.full_frame_patterns[pattern_idx];
|
pattern =
|
||||||
tascam->feedback_consecutive_errors = 0;
|
tascam->fpo
|
||||||
int i;
|
.full_frame_patterns[pattern_idx];
|
||||||
|
tascam->feedback_consecutive_errors = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
unsigned int in_idx =
|
unsigned int in_idx =
|
||||||
(tascam->feedback_pattern_in_idx + i) % FEEDBACK_ACCUMULATOR_SIZE;
|
(tascam->feedback_pattern_in_idx +
|
||||||
|
i) %
|
||||||
|
FEEDBACK_ACCUMULATOR_SIZE;
|
||||||
|
|
||||||
tascam->feedback_accumulator_pattern[in_idx] = pattern[i];
|
tascam->feedback_accumulator_pattern
|
||||||
total_frames_in_urb += pattern[i];
|
[in_idx] = pattern[i];
|
||||||
}
|
total_frames_in_urb += pattern[i];
|
||||||
} else {
|
}
|
||||||
unsigned int nominal_frames = playback_rt->rate / 8000;
|
} else {
|
||||||
int i;
|
unsigned int nominal_frames =
|
||||||
|
playback_rt->rate / 8000;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (tascam->feedback_synced) {
|
if (tascam->feedback_synced) {
|
||||||
tascam->feedback_consecutive_errors++;
|
tascam->feedback_consecutive_errors++;
|
||||||
if (tascam->feedback_consecutive_errors >
|
if (tascam->feedback_consecutive_errors >
|
||||||
FEEDBACK_SYNC_LOSS_THRESHOLD) {
|
FEEDBACK_SYNC_LOSS_THRESHOLD) {
|
||||||
dev_err(tascam->card->dev,
|
dev_err(tascam->card->dev,
|
||||||
"Fatal: Feedback sync lost. Stopping stream.\n");
|
"Fatal: Feedback sync lost. Stopping stream.\n");
|
||||||
schedule_work(&tascam->stop_pcm_work);
|
schedule_work(
|
||||||
tascam->feedback_synced = false;
|
&tascam->stop_pcm_work);
|
||||||
goto continue_unlock;
|
tascam->feedback_synced = false;
|
||||||
}
|
goto continue_unlock;
|
||||||
}
|
}
|
||||||
for (i = 0; i < 8; i++) {
|
}
|
||||||
unsigned int in_idx =
|
for (i = 0; i < 8; i++) {
|
||||||
(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
|
||||||
total_frames_in_urb += nominal_frames;
|
[in_idx] = 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 <
|
bool is_ahead = (new_in_idx - out_idx) %
|
||||||
(FEEDBACK_ACCUMULATOR_SIZE / 2);
|
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",
|
dev_dbg(tascam->card->dev,
|
||||||
new_in_idx, out_idx);
|
"Sync Acquired! (in: %u, out: %u)\n",
|
||||||
tascam->feedback_synced = true;
|
new_in_idx, out_idx);
|
||||||
tascam->feedback_consecutive_errors = 0;
|
tascam->feedback_synced = true;
|
||||||
}
|
tascam->feedback_consecutive_errors = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (total_frames_in_urb > 0) {
|
if (total_frames_in_urb > 0) {
|
||||||
tascam->playback_frames_consumed += total_frames_in_urb;
|
tascam->playback_frames_consumed += total_frames_in_urb;
|
||||||
if (atomic_read(&tascam->capture_active))
|
if (atomic_read(&tascam->capture_active))
|
||||||
tascam->capture_frames_processed += total_frames_in_urb;
|
tascam->capture_frames_processed +=
|
||||||
}
|
total_frames_in_urb;
|
||||||
|
}
|
||||||
|
|
||||||
if (playback_rt->period_size > 0) {
|
if (playback_rt->period_size > 0) {
|
||||||
u64 current_period =
|
u64 current_period =
|
||||||
div_u64(tascam->playback_frames_consumed, playback_rt->period_size);
|
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;
|
||||||
playback_period_elapsed = true;
|
playback_period_elapsed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atomic_read(&tascam->capture_active) && capture_rt &&
|
if (atomic_read(&tascam->capture_active) && capture_rt &&
|
||||||
capture_rt->period_size > 0) {
|
capture_rt->period_size > 0) {
|
||||||
u64 current_capture_period =
|
u64 current_capture_period =
|
||||||
div_u64(tascam->capture_frames_processed, capture_rt->period_size);
|
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 = current_capture_period;
|
tascam->last_capture_period_pos) {
|
||||||
capture_period_elapsed = true;
|
tascam->last_capture_period_pos =
|
||||||
}
|
current_capture_period;
|
||||||
}
|
capture_period_elapsed = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
continue_unlock:
|
continue_unlock:
|
||||||
if (playback_period_elapsed)
|
if (playback_period_elapsed)
|
||||||
snd_pcm_period_elapsed(playback_ss);
|
snd_pcm_period_elapsed(playback_ss);
|
||||||
if (capture_period_elapsed)
|
if (capture_period_elapsed)
|
||||||
snd_pcm_period_elapsed(capture_ss);
|
snd_pcm_period_elapsed(capture_ss);
|
||||||
|
|
||||||
urb->dev = tascam->dev;
|
urb->dev = tascam->dev;
|
||||||
usb_get_urb(urb);
|
usb_get_urb(urb);
|
||||||
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,
|
dev_err_ratelimited(tascam->card->dev,
|
||||||
"Failed to resubmit feedback URB: %d\n", ret);
|
"Failed to resubmit feedback URB: %d\n",
|
||||||
usb_unanchor_urb(urb);
|
ret);
|
||||||
usb_put_urb(urb);
|
usb_unanchor_urb(urb);
|
||||||
}
|
usb_put_urb(urb);
|
||||||
|
}
|
||||||
out:
|
out:
|
||||||
usb_put_urb(urb);
|
usb_put_urb(urb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void tascam_stop_pcm_work_handler(struct work_struct *work)
|
||||||
* tascam_stop_pcm_work_handler() - Work handler to stop PCM streams.
|
{
|
||||||
* @work: Pointer to the work_struct.
|
struct tascam_card *tascam =
|
||||||
*
|
container_of(work, struct tascam_card, stop_pcm_work);
|
||||||
* This function is scheduled to stop PCM streams (playback and capture)
|
|
||||||
* from a workqueue context, avoiding blocking operations in interrupt context.
|
|
||||||
*/
|
|
||||||
void tascam_stop_pcm_work_handler(struct work_struct *work) {
|
|
||||||
struct tascam_card *tascam =
|
|
||||||
container_of(work, struct tascam_card, stop_pcm_work);
|
|
||||||
|
|
||||||
if (tascam->playback_substream)
|
if (tascam->playback_substream)
|
||||||
snd_pcm_stop(tascam->playback_substream, SNDRV_PCM_STATE_XRUN);
|
snd_pcm_stop(tascam->playback_substream, SNDRV_PCM_STATE_XRUN);
|
||||||
if (tascam->capture_substream)
|
if (tascam->capture_substream)
|
||||||
snd_pcm_stop(tascam->capture_substream, SNDRV_PCM_STATE_XRUN);
|
snd_pcm_stop(tascam->capture_substream, SNDRV_PCM_STATE_XRUN);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue