improvements
This commit is contained in:
parent
bbbfb7e985
commit
f50b96f459
144
us144mkii.c
144
us144mkii.c
|
|
@ -26,7 +26,7 @@ MODULE_LICENSE("GPL");
|
||||||
*/
|
*/
|
||||||
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
|
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
|
||||||
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
|
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
|
||||||
static bool enable[SNDRV_CARDS] = {1, [1 ...(SNDRV_CARDS - 1)] = 0};
|
static bool enable[SNDRV_CARDS] = { 1, [1 ...(SNDRV_CARDS - 1)] = 0 };
|
||||||
static int dev_idx;
|
static int dev_idx;
|
||||||
|
|
||||||
static int tascam_probe(struct usb_interface *intf,
|
static int tascam_probe(struct usb_interface *intf,
|
||||||
|
|
@ -35,13 +35,15 @@ 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) {
|
void tascam_free_urbs(struct tascam_card *tascam)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
usb_kill_anchored_urbs(&tascam->playback_anchor);
|
usb_kill_anchored_urbs(&tascam->playback_anchor);
|
||||||
for (i = 0; i < NUM_PLAYBACK_URBS; i++) {
|
for (i = 0; i < NUM_PLAYBACK_URBS; i++) {
|
||||||
if (tascam->playback_urbs[i]) {
|
if (tascam->playback_urbs[i]) {
|
||||||
usb_free_coherent(tascam->dev, tascam->playback_urb_alloc_size,
|
usb_free_coherent(
|
||||||
|
tascam->dev, tascam->playback_urb_alloc_size,
|
||||||
tascam->playback_urbs[i]->transfer_buffer,
|
tascam->playback_urbs[i]->transfer_buffer,
|
||||||
tascam->playback_urbs[i]->transfer_dma);
|
tascam->playback_urbs[i]->transfer_dma);
|
||||||
usb_free_urb(tascam->playback_urbs[i]);
|
usb_free_urb(tascam->playback_urbs[i]);
|
||||||
|
|
@ -52,7 +54,8 @@ void tascam_free_urbs(struct tascam_card *tascam) {
|
||||||
usb_kill_anchored_urbs(&tascam->feedback_anchor);
|
usb_kill_anchored_urbs(&tascam->feedback_anchor);
|
||||||
for (i = 0; i < NUM_FEEDBACK_URBS; i++) {
|
for (i = 0; i < NUM_FEEDBACK_URBS; i++) {
|
||||||
if (tascam->feedback_urbs[i]) {
|
if (tascam->feedback_urbs[i]) {
|
||||||
usb_free_coherent(tascam->dev, tascam->feedback_urb_alloc_size,
|
usb_free_coherent(
|
||||||
|
tascam->dev, tascam->feedback_urb_alloc_size,
|
||||||
tascam->feedback_urbs[i]->transfer_buffer,
|
tascam->feedback_urbs[i]->transfer_buffer,
|
||||||
tascam->feedback_urbs[i]->transfer_dma);
|
tascam->feedback_urbs[i]->transfer_dma);
|
||||||
usb_free_urb(tascam->feedback_urbs[i]);
|
usb_free_urb(tascam->feedback_urbs[i]);
|
||||||
|
|
@ -63,7 +66,8 @@ void tascam_free_urbs(struct tascam_card *tascam) {
|
||||||
usb_kill_anchored_urbs(&tascam->capture_anchor);
|
usb_kill_anchored_urbs(&tascam->capture_anchor);
|
||||||
for (i = 0; i < NUM_CAPTURE_URBS; i++) {
|
for (i = 0; i < NUM_CAPTURE_URBS; i++) {
|
||||||
if (tascam->capture_urbs[i]) {
|
if (tascam->capture_urbs[i]) {
|
||||||
usb_free_coherent(tascam->dev, tascam->capture_urb_alloc_size,
|
usb_free_coherent(
|
||||||
|
tascam->dev, tascam->capture_urb_alloc_size,
|
||||||
tascam->capture_urbs[i]->transfer_buffer,
|
tascam->capture_urbs[i]->transfer_buffer,
|
||||||
tascam->capture_urbs[i]->transfer_dma);
|
tascam->capture_urbs[i]->transfer_dma);
|
||||||
usb_free_urb(tascam->capture_urbs[i]);
|
usb_free_urb(tascam->capture_urbs[i]);
|
||||||
|
|
@ -74,7 +78,8 @@ void tascam_free_urbs(struct tascam_card *tascam) {
|
||||||
usb_kill_anchored_urbs(&tascam->midi_in_anchor);
|
usb_kill_anchored_urbs(&tascam->midi_in_anchor);
|
||||||
for (i = 0; i < NUM_MIDI_IN_URBS; i++) {
|
for (i = 0; i < NUM_MIDI_IN_URBS; i++) {
|
||||||
if (tascam->midi_in_urbs[i]) {
|
if (tascam->midi_in_urbs[i]) {
|
||||||
usb_free_coherent(tascam->dev, MIDI_IN_BUF_SIZE,
|
usb_free_coherent(
|
||||||
|
tascam->dev, MIDI_IN_BUF_SIZE,
|
||||||
tascam->midi_in_urbs[i]->transfer_buffer,
|
tascam->midi_in_urbs[i]->transfer_buffer,
|
||||||
tascam->midi_in_urbs[i]->transfer_dma);
|
tascam->midi_in_urbs[i]->transfer_dma);
|
||||||
usb_free_urb(tascam->midi_in_urbs[i]);
|
usb_free_urb(tascam->midi_in_urbs[i]);
|
||||||
|
|
@ -85,7 +90,8 @@ void tascam_free_urbs(struct tascam_card *tascam) {
|
||||||
usb_kill_anchored_urbs(&tascam->midi_out_anchor);
|
usb_kill_anchored_urbs(&tascam->midi_out_anchor);
|
||||||
for (i = 0; i < NUM_MIDI_OUT_URBS; i++) {
|
for (i = 0; i < NUM_MIDI_OUT_URBS; i++) {
|
||||||
if (tascam->midi_out_urbs[i]) {
|
if (tascam->midi_out_urbs[i]) {
|
||||||
usb_free_coherent(tascam->dev, MIDI_OUT_BUF_SIZE,
|
usb_free_coherent(
|
||||||
|
tascam->dev, MIDI_OUT_BUF_SIZE,
|
||||||
tascam->midi_out_urbs[i]->transfer_buffer,
|
tascam->midi_out_urbs[i]->transfer_buffer,
|
||||||
tascam->midi_out_urbs[i]->transfer_dma);
|
tascam->midi_out_urbs[i]->transfer_dma);
|
||||||
usb_free_urb(tascam->midi_out_urbs[i]);
|
usb_free_urb(tascam->midi_out_urbs[i]);
|
||||||
|
|
@ -103,22 +109,25 @@ void tascam_free_urbs(struct tascam_card *tascam) {
|
||||||
tascam->capture_ring_buffer = NULL;
|
tascam->capture_ring_buffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tascam_alloc_urbs(struct tascam_card *tascam) {
|
int tascam_alloc_urbs(struct tascam_card *tascam)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
size_t max_packet_size;
|
size_t max_packet_size;
|
||||||
|
|
||||||
max_packet_size = ((96000 / 8000) + 2) * BYTES_PER_FRAME;
|
max_packet_size = ((96000 / 8000) + 2) * BYTES_PER_FRAME;
|
||||||
tascam->playback_urb_alloc_size = 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;
|
||||||
|
|
@ -131,23 +140,26 @@ int tascam_alloc_urbs(struct tascam_card *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 =
|
||||||
|
usb_rcvisocpipe(tascam->dev, EP_PLAYBACK_FEEDBACK);
|
||||||
f_urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
|
f_urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
|
||||||
f_urb->interval = 4;
|
f_urb->interval = 4;
|
||||||
f_urb->context = tascam;
|
f_urb->context = tascam;
|
||||||
|
|
@ -162,15 +174,16 @@ int tascam_alloc_urbs(struct tascam_card *tascam) {
|
||||||
goto error;
|
goto error;
|
||||||
tascam->capture_urbs[i] = c_urb;
|
tascam->capture_urbs[i] = c_urb;
|
||||||
|
|
||||||
c_urb->transfer_buffer =
|
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,
|
||||||
|
tascam->capture_urb_alloc_size,
|
||||||
capture_urb_complete, tascam);
|
capture_urb_complete, tascam);
|
||||||
c_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
c_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
||||||
}
|
}
|
||||||
|
|
@ -182,8 +195,9 @@ int tascam_alloc_urbs(struct tascam_card *tascam) {
|
||||||
if (!m_urb)
|
if (!m_urb)
|
||||||
goto error;
|
goto error;
|
||||||
tascam->midi_in_urbs[i] = m_urb;
|
tascam->midi_in_urbs[i] = m_urb;
|
||||||
m_urb->transfer_buffer = 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,
|
||||||
|
GFP_KERNEL, &m_urb->transfer_dma);
|
||||||
if (!m_urb->transfer_buffer)
|
if (!m_urb->transfer_buffer)
|
||||||
goto error;
|
goto error;
|
||||||
usb_fill_bulk_urb(m_urb, tascam->dev,
|
usb_fill_bulk_urb(m_urb, tascam->dev,
|
||||||
|
|
@ -199,18 +213,21 @@ int tascam_alloc_urbs(struct tascam_card *tascam) {
|
||||||
if (!m_urb)
|
if (!m_urb)
|
||||||
goto error;
|
goto error;
|
||||||
tascam->midi_out_urbs[i] = m_urb;
|
tascam->midi_out_urbs[i] = m_urb;
|
||||||
m_urb->transfer_buffer = 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,
|
||||||
|
GFP_KERNEL, &m_urb->transfer_dma);
|
||||||
if (!m_urb->transfer_buffer)
|
if (!m_urb->transfer_buffer)
|
||||||
goto error;
|
goto error;
|
||||||
usb_fill_bulk_urb(m_urb, tascam->dev,
|
usb_fill_bulk_urb(m_urb, tascam->dev,
|
||||||
usb_sndbulkpipe(tascam->dev, EP_MIDI_OUT),
|
usb_sndbulkpipe(tascam->dev, EP_MIDI_OUT),
|
||||||
m_urb->transfer_buffer, 0, /* length set later */
|
m_urb->transfer_buffer,
|
||||||
|
0, /* length set later */
|
||||||
tascam_midi_out_urb_complete, tascam);
|
tascam_midi_out_urb_complete, tascam);
|
||||||
m_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
m_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
tascam->capture_ring_buffer = kmalloc(CAPTURE_RING_BUFFER_SIZE, GFP_KERNEL);
|
tascam->capture_ring_buffer =
|
||||||
|
kmalloc(CAPTURE_RING_BUFFER_SIZE, GFP_KERNEL);
|
||||||
if (!tascam->capture_ring_buffer)
|
if (!tascam->capture_ring_buffer)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
|
@ -241,7 +258,8 @@ error:
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tascam_stop_work_handler(struct work_struct *work) {
|
void tascam_stop_work_handler(struct work_struct *work)
|
||||||
|
{
|
||||||
struct tascam_card *tascam =
|
struct tascam_card *tascam =
|
||||||
container_of(work, struct tascam_card, stop_work);
|
container_of(work, struct tascam_card, stop_work);
|
||||||
|
|
||||||
|
|
@ -260,7 +278,8 @@ 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) {
|
||||||
|
|
@ -283,7 +302,8 @@ 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)
|
||||||
|
|
@ -315,7 +335,8 @@ 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);
|
struct tascam_card *tascam = usb_get_intfdata(intf);
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
|
@ -330,26 +351,31 @@ static int tascam_resume(struct usb_interface *intf) {
|
||||||
*/
|
*/
|
||||||
err = usb_set_interface(tascam->dev, 0, 1);
|
err = usb_set_interface(tascam->dev, 0, 1);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
dev_err(&intf->dev, "resume: failed to set alt setting on intf 0: %d\n",
|
dev_err(&intf->dev,
|
||||||
|
"resume: failed to set alt setting on intf 0: %d\n",
|
||||||
err);
|
err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
err = usb_set_interface(tascam->dev, 1, 1);
|
err = usb_set_interface(tascam->dev, 1, 1);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
dev_err(&intf->dev, "resume: failed to set alt setting on intf 1: %d\n",
|
dev_err(&intf->dev,
|
||||||
|
"resume: failed to set alt setting on intf 1: %d\n",
|
||||||
err);
|
err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Re-configure the sample rate if one was previously active */
|
/* Re-configure the sample rate if one was previously active */
|
||||||
if (tascam->current_rate > 0)
|
if (tascam->current_rate > 0)
|
||||||
us144mkii_configure_device_for_rate(tascam, 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);
|
||||||
|
|
@ -373,15 +399,18 @@ 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 usb_device *dev = interface_to_usbdev(intf);
|
||||||
struct snd_card *card;
|
struct snd_card *card;
|
||||||
struct tascam_card *tascam;
|
struct tascam_card *tascam;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
char *handshake_buf __free(kfree);
|
char *handshake_buf __free(kfree);
|
||||||
|
|
||||||
if (dev->speed != USB_SPEED_HIGH)
|
if (dev->speed != USB_SPEED_HIGH)
|
||||||
dev_info(&dev->dev,
|
dev_info(
|
||||||
|
&dev->dev,
|
||||||
"Device is connected to a USB 1.1 port, this is not supported.\n");
|
"Device is connected to a USB 1.1 port, this is not supported.\n");
|
||||||
|
|
||||||
if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
|
if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
|
||||||
|
|
@ -407,9 +436,10 @@ static int tascam_probe(struct usb_interface *intf,
|
||||||
if (!handshake_buf)
|
if (!handshake_buf)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
err = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), VENDOR_REQ_MODE_CONTROL,
|
err = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
|
||||||
RT_D2H_VENDOR_DEV, MODE_VAL_HANDSHAKE_READ, 0x0000,
|
VENDOR_REQ_MODE_CONTROL, RT_D2H_VENDOR_DEV,
|
||||||
handshake_buf, 1, USB_CTRL_TIMEOUT_MS);
|
MODE_VAL_HANDSHAKE_READ, 0x0000, handshake_buf, 1,
|
||||||
|
USB_CTRL_TIMEOUT_MS);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
dev_err(&dev->dev, "Handshake read failed with %d\n", err);
|
dev_err(&dev->dev, "Handshake read failed with %d\n", err);
|
||||||
return err;
|
return err;
|
||||||
|
|
@ -417,19 +447,24 @@ static int tascam_probe(struct usb_interface *intf,
|
||||||
|
|
||||||
if (handshake_buf[0] != 0x12 && handshake_buf[0] != 0x16 &&
|
if (handshake_buf[0] != 0x12 && handshake_buf[0] != 0x16 &&
|
||||||
handshake_buf[0] != 0x30) {
|
handshake_buf[0] != 0x30) {
|
||||||
dev_err(&dev->dev, "Unexpected handshake value: 0x%x\n", handshake_buf[0]);
|
dev_err(&dev->dev, "Unexpected handshake value: 0x%x\n",
|
||||||
|
handshake_buf[0]);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = usb_set_interface(dev, 0, 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 0: %d\n", err);
|
dev_err(&dev->dev,
|
||||||
|
"Failed to set alt setting 1 on interface 0: %d\n",
|
||||||
|
err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = usb_set_interface(dev, 1, 1);
|
err = usb_set_interface(dev, 1, 1);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
dev_err(&dev->dev, "Failed to set alt setting 1 on interface 1: %d\n", err);
|
dev_err(&dev->dev,
|
||||||
|
"Failed to set alt setting 1 on interface 1: %d\n",
|
||||||
|
err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -460,6 +495,7 @@ static int tascam_probe(struct usb_interface *intf,
|
||||||
INIT_WORK(&tascam->stop_work, tascam_stop_work_handler);
|
INIT_WORK(&tascam->stop_work, tascam_stop_work_handler);
|
||||||
INIT_WORK(&tascam->stop_pcm_work, tascam_stop_pcm_work_handler);
|
INIT_WORK(&tascam->stop_pcm_work, tascam_stop_pcm_work_handler);
|
||||||
INIT_WORK(&tascam->capture_work, tascam_capture_work_handler);
|
INIT_WORK(&tascam->capture_work, tascam_capture_work_handler);
|
||||||
|
init_completion(&tascam->midi_out_drain_completion);
|
||||||
|
|
||||||
if (kfifo_alloc(&tascam->midi_in_fifo, MIDI_IN_FIFO_SIZE, GFP_KERNEL)) {
|
if (kfifo_alloc(&tascam->midi_in_fifo, MIDI_IN_FIFO_SIZE, GFP_KERNEL)) {
|
||||||
snd_card_free(card);
|
snd_card_free(card);
|
||||||
|
|
@ -468,11 +504,14 @@ static int tascam_probe(struct usb_interface *intf,
|
||||||
|
|
||||||
strscpy(card->driver, DRIVER_NAME, sizeof(card->driver));
|
strscpy(card->driver, DRIVER_NAME, sizeof(card->driver));
|
||||||
if (dev->descriptor.idProduct == USB_PID_TASCAM_US144) {
|
if (dev->descriptor.idProduct == USB_PID_TASCAM_US144) {
|
||||||
strscpy(card->shortname, "TASCAM US-144", sizeof(card->shortname));
|
strscpy(card->shortname, "TASCAM US-144",
|
||||||
|
sizeof(card->shortname));
|
||||||
} else if (dev->descriptor.idProduct == USB_PID_TASCAM_US144MKII) {
|
} else if (dev->descriptor.idProduct == USB_PID_TASCAM_US144MKII) {
|
||||||
strscpy(card->shortname, "TASCAM US-144MKII", sizeof(card->shortname));
|
strscpy(card->shortname, "TASCAM US-144MKII",
|
||||||
|
sizeof(card->shortname));
|
||||||
} else {
|
} else {
|
||||||
strscpy(card->shortname, "TASCAM Unknown", sizeof(card->shortname));
|
strscpy(card->shortname, "TASCAM Unknown",
|
||||||
|
sizeof(card->shortname));
|
||||||
}
|
}
|
||||||
snprintf(card->longname, sizeof(card->longname), "%s (%04x:%04x) at %s",
|
snprintf(card->longname, sizeof(card->longname), "%s (%04x:%04x) at %s",
|
||||||
card->shortname, USB_VID_TASCAM, dev->descriptor.idProduct,
|
card->shortname, USB_VID_TASCAM, dev->descriptor.idProduct,
|
||||||
|
|
@ -523,14 +562,14 @@ 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) {
|
||||||
|
|
||||||
/* Ensure all deferred work is complete before freeing resources */
|
/* Ensure all deferred work is complete before freeing resources */
|
||||||
snd_card_disconnect(tascam->card);
|
snd_card_disconnect(tascam->card);
|
||||||
cancel_work_sync(&tascam->stop_work);
|
cancel_work_sync(&tascam->stop_work);
|
||||||
|
|
@ -552,9 +591,10 @@ static void tascam_disconnect(struct usb_interface *intf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct usb_device_id tascam_usb_ids[] = {
|
static const struct usb_device_id tascam_usb_ids[] = {
|
||||||
{USB_DEVICE(USB_VID_TASCAM, USB_PID_TASCAM_US144)},
|
{ USB_DEVICE(USB_VID_TASCAM, USB_PID_TASCAM_US144) },
|
||||||
{USB_DEVICE(USB_VID_TASCAM, USB_PID_TASCAM_US144MKII)},
|
{ USB_DEVICE(USB_VID_TASCAM, USB_PID_TASCAM_US144MKII) },
|
||||||
{/* Terminating entry */}};
|
{ /* Terminating entry */ }
|
||||||
|
};
|
||||||
MODULE_DEVICE_TABLE(usb, tascam_usb_ids);
|
MODULE_DEVICE_TABLE(usb, tascam_usb_ids);
|
||||||
|
|
||||||
static struct usb_driver tascam_alsa_driver = {
|
static struct usb_driver tascam_alsa_driver = {
|
||||||
|
|
|
||||||
|
|
@ -261,6 +261,7 @@ struct tascam_card {
|
||||||
unsigned long midi_out_urbs_in_flight;
|
unsigned long midi_out_urbs_in_flight;
|
||||||
u8 midi_running_status;
|
u8 midi_running_status;
|
||||||
struct timer_list error_timer;
|
struct timer_list error_timer;
|
||||||
|
struct completion midi_out_drain_completion;
|
||||||
|
|
||||||
/* --- Feedback Sync State --- */
|
/* --- Feedback Sync State --- */
|
||||||
unsigned int feedback_accumulator_pattern[FEEDBACK_ACCUMULATOR_SIZE];
|
unsigned int feedback_accumulator_pattern[FEEDBACK_ACCUMULATOR_SIZE];
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@
|
||||||
*
|
*
|
||||||
* 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;
|
||||||
|
|
@ -31,7 +32,8 @@ 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;
|
||||||
|
|
@ -47,7 +49,8 @@ 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;
|
||||||
|
|
@ -69,7 +72,8 @@ static int tascam_capture_prepare(struct snd_pcm_substream *substream) {
|
||||||
* Return: The current capture pointer position in frames.
|
* Return: The current capture pointer position in frames.
|
||||||
*/
|
*/
|
||||||
static snd_pcm_uframes_t
|
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 tascam_card *tascam = snd_pcm_substream_chip(substream);
|
||||||
struct snd_pcm_runtime *runtime = substream->runtime;
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
||||||
u64 pos;
|
u64 pos;
|
||||||
|
|
@ -84,6 +88,7 @@ tascam_capture_pointer(struct snd_pcm_substream *substream) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,7 +119,8 @@ 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,
|
||||||
|
|
@ -125,7 +131,7 @@ static void decode_tascam_capture_block(const u8 *src_block, s32 *dst_block) {
|
||||||
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];
|
||||||
|
|
@ -149,7 +155,8 @@ static void decode_tascam_capture_block(const u8 *src_block, s32 *dst_block) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tascam_capture_work_handler(struct work_struct *work) {
|
void tascam_capture_work_handler(struct work_struct *work)
|
||||||
|
{
|
||||||
struct tascam_card *tascam =
|
struct tascam_card *tascam =
|
||||||
container_of(work, struct tascam_card, capture_work);
|
container_of(work, struct tascam_card, capture_work);
|
||||||
struct snd_pcm_substream *substream = tascam->capture_substream;
|
struct snd_pcm_substream *substream = tascam->capture_substream;
|
||||||
|
|
@ -176,24 +183,36 @@ void tascam_capture_work_handler(struct work_struct *work) {
|
||||||
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) {
|
||||||
|
memcpy(raw_block,
|
||||||
|
tascam->capture_ring_buffer +
|
||||||
|
read_ptr,
|
||||||
RAW_BYTES_PER_DECODE_BLOCK);
|
RAW_BYTES_PER_DECODE_BLOCK);
|
||||||
} else {
|
} else {
|
||||||
memcpy(raw_block, tascam->capture_ring_buffer + read_ptr,
|
memcpy(raw_block,
|
||||||
|
tascam->capture_ring_buffer +
|
||||||
|
read_ptr,
|
||||||
|
bytes_to_end);
|
||||||
|
memcpy(raw_block + bytes_to_end,
|
||||||
|
tascam->capture_ring_buffer,
|
||||||
|
RAW_BYTES_PER_DECODE_BLOCK -
|
||||||
bytes_to_end);
|
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 =
|
tascam->capture_ring_buffer_read_ptr =
|
||||||
(read_ptr + RAW_BYTES_PER_DECODE_BLOCK) % CAPTURE_RING_BUFFER_SIZE;
|
(read_ptr +
|
||||||
|
RAW_BYTES_PER_DECODE_BLOCK) %
|
||||||
|
CAPTURE_RING_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -201,7 +220,8 @@ void tascam_capture_work_handler(struct work_struct *work) {
|
||||||
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);
|
||||||
|
|
@ -211,26 +231,39 @@ void tascam_capture_work_handler(struct work_struct *work) {
|
||||||
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,
|
||||||
|
tascam->driver_capture_pos);
|
||||||
|
s32 *routed_frame_start =
|
||||||
|
routed_block +
|
||||||
|
(f * NUM_CHANNELS);
|
||||||
int c;
|
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) {
|
void capture_urb_complete(struct urb *urb)
|
||||||
|
{
|
||||||
struct tascam_card *tascam = urb->context;
|
struct tascam_card *tascam = urb->context;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
|
@ -238,7 +271,8 @@ void capture_urb_complete(struct urb *urb) {
|
||||||
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,
|
||||||
|
"Capture URB failed: %d\n",
|
||||||
urb->status);
|
urb->status);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
@ -255,17 +289,20 @@ void capture_urb_complete(struct urb *urb) {
|
||||||
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->transfer_buffer + bytes_to_end,
|
||||||
urb->actual_length - bytes_to_end);
|
urb->actual_length - bytes_to_end);
|
||||||
} else {
|
} else {
|
||||||
memcpy(tascam->capture_ring_buffer + write_ptr, urb->transfer_buffer,
|
memcpy(tascam->capture_ring_buffer + write_ptr,
|
||||||
|
urb->transfer_buffer,
|
||||||
urb->actual_length);
|
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);
|
||||||
|
|
@ -276,10 +313,12 @@ void capture_urb_complete(struct urb *urb) {
|
||||||
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",
|
||||||
|
ret);
|
||||||
usb_unanchor_urb(urb);
|
usb_unanchor_urb(urb);
|
||||||
usb_put_urb(urb);
|
usb_put_urb(urb);
|
||||||
atomic_dec(&tascam->active_urbs); /* Decrement on failed resubmission */
|
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,7 +33,8 @@ 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,10 +50,14 @@ 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);
|
||||||
|
val = tascam->line_out_source;
|
||||||
|
ucontrol->value.enumerated.item[0] = val;
|
||||||
return 0;
|
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);
|
||||||
|
if (tascam->line_out_source != ucontrol->value.enumerated.item[0]) {
|
||||||
tascam->line_out_source = ucontrol->value.enumerated.item[0];
|
tascam->line_out_source = ucontrol->value.enumerated.item[0];
|
||||||
return 1;
|
changed = 1;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -109,10 +119,14 @@ 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);
|
||||||
|
val = tascam->digital_out_source;
|
||||||
|
ucontrol->value.enumerated.item[0] = val;
|
||||||
return 0;
|
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);
|
||||||
|
if (tascam->digital_out_source != ucontrol->value.enumerated.item[0]) {
|
||||||
tascam->digital_out_source = ucontrol->value.enumerated.item[0];
|
tascam->digital_out_source = ucontrol->value.enumerated.item[0];
|
||||||
return 1;
|
changed = 1;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -170,7 +189,8 @@ 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,10 +207,14 @@ 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);
|
||||||
|
val = tascam->capture_12_source;
|
||||||
|
ucontrol->value.enumerated.item[0] = val;
|
||||||
return 0;
|
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);
|
||||||
|
if (tascam->capture_12_source != ucontrol->value.enumerated.item[0]) {
|
||||||
tascam->capture_12_source = ucontrol->value.enumerated.item[0];
|
tascam->capture_12_source = ucontrol->value.enumerated.item[0];
|
||||||
return 1;
|
changed = 1;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -249,10 +278,14 @@ 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);
|
||||||
|
val = tascam->capture_34_source;
|
||||||
|
ucontrol->value.enumerated.item[0] = val;
|
||||||
return 0;
|
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);
|
||||||
|
if (tascam->capture_34_source != ucontrol->value.enumerated.item[0]) {
|
||||||
tascam->capture_34_source = ucontrol->value.enumerated.item[0];
|
tascam->capture_34_source = ucontrol->value.enumerated.item[0];
|
||||||
return 1;
|
changed = 1;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -309,7 +347,8 @@ static const struct snd_kcontrol_new tascam_capture_34_control = {
|
||||||
* Return: 0 on success.
|
* Return: 0 on success.
|
||||||
*/
|
*/
|
||||||
static int tascam_samplerate_info(struct snd_kcontrol *kcontrol,
|
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->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
||||||
uinfo->count = 1;
|
uinfo->count = 1;
|
||||||
uinfo->value.integer.min = 0;
|
uinfo->value.integer.min = 0;
|
||||||
|
|
@ -330,25 +369,29 @@ 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 *tascam =
|
||||||
(struct tascam_card *)snd_kcontrol_chip(kcontrol);
|
(struct tascam_card *)snd_kcontrol_chip(kcontrol);
|
||||||
u8 *buf __free(kfree);
|
u8 *buf __free(kfree);
|
||||||
int err;
|
int err;
|
||||||
u32 rate = 0;
|
u32 rate = 0;
|
||||||
|
|
||||||
|
guard(spinlock_irqsave)(&tascam->lock);
|
||||||
if (tascam->current_rate > 0) {
|
if (tascam->current_rate > 0) {
|
||||||
ucontrol->value.integer.value[0] = tascam->current_rate;
|
ucontrol->value.integer.value[0] = tascam->current_rate;
|
||||||
return 0;
|
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);
|
||||||
|
|
@ -371,11 +414,12 @@ static const struct snd_kcontrol_new tascam_samplerate_control = {
|
||||||
.access = SNDRV_CTL_ELEM_ACCESS_READ,
|
.access = SNDRV_CTL_ELEM_ACCESS_READ,
|
||||||
};
|
};
|
||||||
|
|
||||||
int tascam_create_controls(struct tascam_card *tascam) {
|
int tascam_create_controls(struct tascam_card *tascam)
|
||||||
|
{
|
||||||
int err;
|
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,
|
||||||
|
|
|
||||||
101
us144mkii_midi.c
101
us144mkii_midi.c
|
|
@ -11,7 +11,8 @@
|
||||||
* the kfifo, processes it by stripping protocol-specific padding bytes, and
|
* the kfifo, processes it by stripping protocol-specific padding bytes, and
|
||||||
* passes the clean MIDI data to the ALSA rawmidi subsystem.
|
* passes the clean MIDI data to the ALSA rawmidi subsystem.
|
||||||
*/
|
*/
|
||||||
static void tascam_midi_in_work_handler(struct work_struct *work) {
|
static void tascam_midi_in_work_handler(struct work_struct *work)
|
||||||
|
{
|
||||||
struct tascam_card *tascam =
|
struct tascam_card *tascam =
|
||||||
container_of(work, struct tascam_card, midi_in_work);
|
container_of(work, struct tascam_card, midi_in_work);
|
||||||
u8 buf[9];
|
u8 buf[9];
|
||||||
|
|
@ -30,18 +31,21 @@ static void tascam_midi_in_work_handler(struct work_struct *work) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
void tascam_midi_in_urb_complete(struct urb *urb)
|
||||||
|
{
|
||||||
struct tascam_card *tascam = urb->context;
|
struct tascam_card *tascam = urb->context;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (urb->status) {
|
if (urb->status) {
|
||||||
if (urb->status != -ENOENT && urb->status != -ECONNRESET &&
|
if (urb->status != -ENOENT && urb->status != -ECONNRESET &&
|
||||||
urb->status != -ESHUTDOWN && urb->status != -EPROTO) {
|
urb->status != -ESHUTDOWN && urb->status != -EPROTO) {
|
||||||
dev_err_ratelimited(tascam->card->dev, "MIDI IN URB failed: status %d\n",
|
dev_err_ratelimited(tascam->card->dev,
|
||||||
|
"MIDI IN URB failed: status %d\n",
|
||||||
urb->status);
|
urb->status);
|
||||||
}
|
}
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -58,8 +62,8 @@ void tascam_midi_in_urb_complete(struct urb *urb) {
|
||||||
usb_anchor_urb(urb, &tascam->midi_in_anchor);
|
usb_anchor_urb(urb, &tascam->midi_in_anchor);
|
||||||
ret = usb_submit_urb(urb, GFP_ATOMIC);
|
ret = usb_submit_urb(urb, GFP_ATOMIC);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
dev_err(tascam->card->dev, "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);
|
||||||
}
|
}
|
||||||
|
|
@ -76,7 +80,8 @@ 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;
|
||||||
|
|
@ -89,7 +94,8 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,7 +110,8 @@ 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;
|
struct tascam_card *tascam = substream->rmidi->private_data;
|
||||||
int i, err;
|
int i, err;
|
||||||
|
|
||||||
|
|
@ -117,12 +124,16 @@ static void tascam_midi_in_trigger(struct snd_rawmidi_substream *substream,
|
||||||
|
|
||||||
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);
|
||||||
|
err = usb_submit_urb(tascam->midi_in_urbs[i],
|
||||||
|
GFP_KERNEL);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
dev_err(tascam->card->dev, "Failed to submit MIDI IN URB %d: %d\n", i,
|
dev_err(tascam->card->dev,
|
||||||
err);
|
"Failed to submit MIDI IN URB %d: %d\n",
|
||||||
usb_unanchor_urb(tascam->midi_in_urbs[i]);
|
i, err);
|
||||||
|
usb_unanchor_urb(
|
||||||
|
tascam->midi_in_urbs[i]);
|
||||||
usb_put_urb(tascam->midi_in_urbs[i]);
|
usb_put_urb(tascam->midi_in_urbs[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -147,14 +158,16 @@ static const struct snd_rawmidi_ops tascam_midi_in_ops = {
|
||||||
.trigger = tascam_midi_in_trigger,
|
.trigger = tascam_midi_in_trigger,
|
||||||
};
|
};
|
||||||
|
|
||||||
void tascam_midi_out_urb_complete(struct urb *urb) {
|
void tascam_midi_out_urb_complete(struct urb *urb)
|
||||||
|
{
|
||||||
struct tascam_card *tascam = urb->context;
|
struct tascam_card *tascam = urb->context;
|
||||||
int i, urb_index = -1;
|
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,
|
||||||
|
"MIDI OUT URB failed: %d\n",
|
||||||
urb->status);
|
urb->status);
|
||||||
}
|
}
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -171,7 +184,8 @@ void tascam_midi_out_urb_complete(struct urb *urb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
|
"Unknown MIDI OUT URB completed!\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -197,7 +211,8 @@ out:
|
||||||
* This function pulls as many bytes as will fit into one packet from the
|
* This function pulls as many bytes as will fit into one packet from the
|
||||||
* ALSA buffer and sends them.
|
* ALSA buffer and sends them.
|
||||||
*/
|
*/
|
||||||
static void tascam_midi_out_work_handler(struct work_struct *work) {
|
static void tascam_midi_out_work_handler(struct work_struct *work)
|
||||||
|
{
|
||||||
struct tascam_card *tascam =
|
struct tascam_card *tascam =
|
||||||
container_of(work, struct tascam_card, midi_out_work);
|
container_of(work, struct tascam_card, midi_out_work);
|
||||||
struct snd_rawmidi_substream *substream = tascam->midi_out_substream;
|
struct snd_rawmidi_substream *substream = tascam->midi_out_substream;
|
||||||
|
|
@ -206,7 +221,7 @@ static void tascam_midi_out_work_handler(struct work_struct *work) {
|
||||||
if (!substream || !atomic_read(&tascam->midi_out_active))
|
if (!substream || !atomic_read(&tascam->midi_out_active))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (snd_rawmidi_transmit_peek(substream, (u8[]){0}, 1) == 1) {
|
while (snd_rawmidi_transmit_peek(substream, (u8[]){ 0 }, 1) == 1) {
|
||||||
int urb_index;
|
int urb_index;
|
||||||
struct urb *urb;
|
struct urb *urb;
|
||||||
u8 *buf;
|
u8 *buf;
|
||||||
|
|
@ -217,26 +232,29 @@ static void tascam_midi_out_work_handler(struct work_struct *work) {
|
||||||
|
|
||||||
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(
|
||||||
|
i,
|
||||||
|
&tascam->midi_out_urbs_in_flight)) {
|
||||||
urb_index = i;
|
urb_index = i;
|
||||||
break;
|
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,
|
||||||
|
9 - bytes_to_send);
|
||||||
buf[8] = 0x00;
|
buf[8] = 0x00;
|
||||||
|
|
||||||
set_bit(urb_index, &tascam->midi_out_urbs_in_flight);
|
set_bit(urb_index, &tascam->midi_out_urbs_in_flight);
|
||||||
|
|
@ -246,11 +264,14 @@ static void tascam_midi_out_work_handler(struct work_struct *work) {
|
||||||
usb_get_urb(urb);
|
usb_get_urb(urb);
|
||||||
usb_anchor_urb(urb, &tascam->midi_out_anchor);
|
usb_anchor_urb(urb, &tascam->midi_out_anchor);
|
||||||
if (usb_submit_urb(urb, GFP_KERNEL) < 0) {
|
if (usb_submit_urb(urb, GFP_KERNEL) < 0) {
|
||||||
dev_err_ratelimited(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",
|
||||||
|
urb_index);
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
usb_unanchor_urb(urb);
|
usb_unanchor_urb(urb);
|
||||||
usb_put_urb(urb);
|
usb_put_urb(urb);
|
||||||
|
|
@ -268,7 +289,8 @@ 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;
|
||||||
|
|
@ -283,7 +305,8 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -294,7 +317,8 @@ static int tascam_midi_out_close(struct snd_rawmidi_substream *substream) {
|
||||||
* This function cancels any pending MIDI output work and kills all
|
* This function cancels any pending MIDI output work and kills all
|
||||||
* anchored MIDI output URBs, ensuring all data is sent or discarded.
|
* anchored MIDI output URBs, ensuring all data is sent or discarded.
|
||||||
*/
|
*/
|
||||||
static void tascam_midi_out_drain(struct snd_rawmidi_substream *substream) {
|
static void tascam_midi_out_drain(struct snd_rawmidi_substream *substream)
|
||||||
|
{
|
||||||
struct tascam_card *tascam = substream->rmidi->private_data;
|
struct tascam_card *tascam = substream->rmidi->private_data;
|
||||||
bool in_flight = true;
|
bool in_flight = true;
|
||||||
|
|
||||||
|
|
@ -323,7 +347,8 @@ 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) {
|
||||||
|
|
@ -347,15 +372,17 @@ static const struct snd_rawmidi_ops tascam_midi_out_ops = {
|
||||||
.drain = tascam_midi_out_drain,
|
.drain = tascam_midi_out_drain,
|
||||||
};
|
};
|
||||||
|
|
||||||
int tascam_create_midi(struct tascam_card *tascam) {
|
int tascam_create_midi(struct tascam_card *tascam)
|
||||||
|
{
|
||||||
int err;
|
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",
|
||||||
|
sizeof(tascam->rmidi->name));
|
||||||
tascam->rmidi->private_data = tascam;
|
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,
|
||||||
|
|
|
||||||
137
us144mkii_pcm.c
137
us144mkii_pcm.c
|
|
@ -15,7 +15,8 @@
|
||||||
* 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)
|
||||||
|
|
@ -53,7 +54,8 @@ const struct snd_pcm_hardware tascam_pcm_hw = {
|
||||||
|
|
||||||
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;
|
size_t f;
|
||||||
const u8 *src_12, *src_34;
|
const u8 *src_12, *src_34;
|
||||||
u8 *dst_line, *dst_digital;
|
u8 *dst_line, *dst_digital;
|
||||||
|
|
@ -80,7 +82,8 @@ void process_playback_routing_us144mkii(struct tascam_card *tascam,
|
||||||
|
|
||||||
void process_capture_routing_us144mkii(struct tascam_card *tascam,
|
void process_capture_routing_us144mkii(struct tascam_card *tascam,
|
||||||
const s32 *decoded_block,
|
const s32 *decoded_block,
|
||||||
s32 *routed_block) {
|
s32 *routed_block)
|
||||||
|
{
|
||||||
int f;
|
int f;
|
||||||
const s32 *src_frame;
|
const s32 *src_frame;
|
||||||
s32 *dst_frame;
|
s32 *dst_frame;
|
||||||
|
|
@ -109,17 +112,18 @@ void process_capture_routing_us144mkii(struct tascam_card *tascam,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int us144mkii_configure_device_for_rate(struct tascam_card *tascam, int rate) {
|
int us144mkii_configure_device_for_rate(struct tascam_card *tascam, int rate)
|
||||||
|
{
|
||||||
struct usb_device *dev = tascam->dev;
|
struct usb_device *dev = tascam->dev;
|
||||||
u8 *rate_payload_buf;
|
|
||||||
u16 rate_vendor_wValue;
|
u16 rate_vendor_wValue;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
const u8 *current_payload_src;
|
const u8 *current_payload_src;
|
||||||
|
u8 *rate_payload_buf __free(kfree);
|
||||||
|
|
||||||
static const u8 payload_44100[] = {0x44, 0xac, 0x00};
|
static const u8 payload_44100[] = { 0x44, 0xac, 0x00 };
|
||||||
static const u8 payload_48000[] = {0x80, 0xbb, 0x00};
|
static const u8 payload_48000[] = { 0x80, 0xbb, 0x00 };
|
||||||
static const u8 payload_88200[] = {0x88, 0x58, 0x01};
|
static const u8 payload_88200[] = { 0x88, 0x58, 0x01 };
|
||||||
static const u8 payload_96000[] = {0x00, 0x77, 0x01};
|
static const u8 payload_96000[] = { 0x00, 0x77, 0x01 };
|
||||||
|
|
||||||
switch (rate) {
|
switch (rate) {
|
||||||
case 44100:
|
case 44100:
|
||||||
|
|
@ -139,7 +143,8 @@ int us144mkii_configure_device_for_rate(struct tascam_card *tascam, int rate) {
|
||||||
rate_vendor_wValue = REG_ADDR_RATE_96000;
|
rate_vendor_wValue = REG_ADDR_RATE_96000;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dev_err(&dev->dev, "Unsupported sample rate %d for configuration\n", rate);
|
dev_err(&dev->dev,
|
||||||
|
"Unsupported sample rate %d for configuration\n", rate);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,64 +154,73 @@ int us144mkii_configure_device_for_rate(struct tascam_card *tascam, int rate) {
|
||||||
|
|
||||||
dev_info(&dev->dev, "Configuring device for %d Hz\n", rate);
|
dev_info(&dev->dev, "Configuring device for %d Hz\n", rate);
|
||||||
|
|
||||||
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_MODE_CONTROL,
|
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
||||||
RT_H2D_VENDOR_DEV, MODE_VAL_CONFIG, 0x0000, NULL, 0,
|
VENDOR_REQ_MODE_CONTROL, RT_H2D_VENDOR_DEV,
|
||||||
|
MODE_VAL_CONFIG, 0x0000, NULL, 0,
|
||||||
USB_CTRL_TIMEOUT_MS);
|
USB_CTRL_TIMEOUT_MS);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
|
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
|
||||||
RT_H2D_CLASS_EP, UAC_SAMPLING_FREQ_CONTROL, EP_AUDIO_IN,
|
RT_H2D_CLASS_EP, UAC_SAMPLING_FREQ_CONTROL,
|
||||||
rate_payload_buf, 3, USB_CTRL_TIMEOUT_MS);
|
EP_AUDIO_IN, rate_payload_buf, 3,
|
||||||
|
USB_CTRL_TIMEOUT_MS);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
|
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
|
||||||
RT_H2D_CLASS_EP, UAC_SAMPLING_FREQ_CONTROL,
|
RT_H2D_CLASS_EP, UAC_SAMPLING_FREQ_CONTROL,
|
||||||
EP_AUDIO_OUT, rate_payload_buf, 3, USB_CTRL_TIMEOUT_MS);
|
EP_AUDIO_OUT, rate_payload_buf, 3,
|
||||||
|
USB_CTRL_TIMEOUT_MS);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_REGISTER_WRITE,
|
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
||||||
RT_H2D_VENDOR_DEV, REG_ADDR_UNKNOWN_0D, REG_VAL_ENABLE,
|
VENDOR_REQ_REGISTER_WRITE, RT_H2D_VENDOR_DEV,
|
||||||
NULL, 0, USB_CTRL_TIMEOUT_MS);
|
REG_ADDR_UNKNOWN_0D, REG_VAL_ENABLE, NULL, 0,
|
||||||
|
USB_CTRL_TIMEOUT_MS);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_REGISTER_WRITE,
|
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
||||||
RT_H2D_VENDOR_DEV, REG_ADDR_UNKNOWN_0E, REG_VAL_ENABLE,
|
VENDOR_REQ_REGISTER_WRITE, RT_H2D_VENDOR_DEV,
|
||||||
NULL, 0, USB_CTRL_TIMEOUT_MS);
|
REG_ADDR_UNKNOWN_0E, REG_VAL_ENABLE, NULL, 0,
|
||||||
|
USB_CTRL_TIMEOUT_MS);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_REGISTER_WRITE,
|
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
||||||
RT_H2D_VENDOR_DEV, REG_ADDR_UNKNOWN_0F, REG_VAL_ENABLE,
|
VENDOR_REQ_REGISTER_WRITE, RT_H2D_VENDOR_DEV,
|
||||||
NULL, 0, USB_CTRL_TIMEOUT_MS);
|
REG_ADDR_UNKNOWN_0F, REG_VAL_ENABLE, NULL, 0,
|
||||||
|
USB_CTRL_TIMEOUT_MS);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_REGISTER_WRITE,
|
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
||||||
RT_H2D_VENDOR_DEV, rate_vendor_wValue, REG_VAL_ENABLE,
|
VENDOR_REQ_REGISTER_WRITE, RT_H2D_VENDOR_DEV,
|
||||||
NULL, 0, USB_CTRL_TIMEOUT_MS);
|
rate_vendor_wValue, REG_VAL_ENABLE, NULL, 0,
|
||||||
|
USB_CTRL_TIMEOUT_MS);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_REGISTER_WRITE,
|
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
||||||
RT_H2D_VENDOR_DEV, REG_ADDR_UNKNOWN_11, REG_VAL_ENABLE,
|
VENDOR_REQ_REGISTER_WRITE, RT_H2D_VENDOR_DEV,
|
||||||
NULL, 0, USB_CTRL_TIMEOUT_MS);
|
REG_ADDR_UNKNOWN_11, REG_VAL_ENABLE, NULL, 0,
|
||||||
|
USB_CTRL_TIMEOUT_MS);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), VENDOR_REQ_MODE_CONTROL,
|
err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
||||||
RT_H2D_VENDOR_DEV, MODE_VAL_STREAM_START, 0x0000, NULL,
|
VENDOR_REQ_MODE_CONTROL, RT_H2D_VENDOR_DEV,
|
||||||
0, USB_CTRL_TIMEOUT_MS);
|
MODE_VAL_STREAM_START, 0x0000, NULL, 0,
|
||||||
|
USB_CTRL_TIMEOUT_MS);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
kfree(rate_payload_buf);
|
|
||||||
return 0;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tascam_pcm_hw_params(struct snd_pcm_substream *substream,
|
int tascam_pcm_hw_params(struct snd_pcm_substream *substream,
|
||||||
struct snd_pcm_hw_params *params) {
|
struct snd_pcm_hw_params *params)
|
||||||
|
{
|
||||||
struct tascam_card *tascam = snd_pcm_substream_chip(substream);
|
struct tascam_card *tascam = snd_pcm_substream_chip(substream);
|
||||||
int err;
|
int err;
|
||||||
unsigned int rate = params_rate(params);
|
unsigned int rate = params_rate(params);
|
||||||
|
|
@ -220,11 +234,12 @@ int tascam_pcm_hw_params(struct snd_pcm_substream *substream,
|
||||||
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++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
int target_sum =
|
int target_sum = tascam->fpo.sample_rate_khz -
|
||||||
tascam->fpo.sample_rate_khz - tascam->fpo.feedback_offset + i;
|
tascam->fpo.feedback_offset + i;
|
||||||
fpoInitPattern(8, tascam->fpo.full_frame_patterns[i], initial_value,
|
fpoInitPattern(8, tascam->fpo.full_frame_patterns[i],
|
||||||
target_sum);
|
initial_value, target_sum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -240,9 +255,13 @@ int tascam_pcm_hw_params(struct snd_pcm_substream *substream,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tascam_pcm_hw_free(struct snd_pcm_substream *substream) { return 0; }
|
int tascam_pcm_hw_free(struct snd_pcm_substream *substream)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int tascam_pcm_trigger(struct snd_pcm_substream *substream, int cmd) {
|
int tascam_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
|
||||||
|
{
|
||||||
struct tascam_card *tascam = snd_pcm_substream_chip(substream);
|
struct tascam_card *tascam = snd_pcm_substream_chip(substream);
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -277,14 +296,17 @@ int tascam_pcm_trigger(struct snd_pcm_substream *substream, int cmd) {
|
||||||
|
|
||||||
if (do_start) {
|
if (do_start) {
|
||||||
if (atomic_read(&tascam->active_urbs) > 0) {
|
if (atomic_read(&tascam->active_urbs) > 0) {
|
||||||
dev_WARN(tascam->card->dev, "Cannot start, URBs still active.\n");
|
dev_WARN(tascam->card->dev,
|
||||||
|
"Cannot start, URBs still active.\n");
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < NUM_FEEDBACK_URBS; i++) {
|
for (i = 0; i < NUM_FEEDBACK_URBS; i++) {
|
||||||
usb_get_urb(tascam->feedback_urbs[i]);
|
usb_get_urb(tascam->feedback_urbs[i]);
|
||||||
usb_anchor_urb(tascam->feedback_urbs[i], &tascam->feedback_anchor);
|
usb_anchor_urb(tascam->feedback_urbs[i],
|
||||||
err = usb_submit_urb(tascam->feedback_urbs[i], GFP_ATOMIC);
|
&tascam->feedback_anchor);
|
||||||
|
err = usb_submit_urb(tascam->feedback_urbs[i],
|
||||||
|
GFP_ATOMIC);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
usb_unanchor_urb(tascam->feedback_urbs[i]);
|
usb_unanchor_urb(tascam->feedback_urbs[i]);
|
||||||
usb_put_urb(tascam->feedback_urbs[i]);
|
usb_put_urb(tascam->feedback_urbs[i]);
|
||||||
|
|
@ -295,8 +317,10 @@ int tascam_pcm_trigger(struct snd_pcm_substream *substream, int cmd) {
|
||||||
}
|
}
|
||||||
for (i = 0; i < NUM_PLAYBACK_URBS; i++) {
|
for (i = 0; i < NUM_PLAYBACK_URBS; i++) {
|
||||||
usb_get_urb(tascam->playback_urbs[i]);
|
usb_get_urb(tascam->playback_urbs[i]);
|
||||||
usb_anchor_urb(tascam->playback_urbs[i], &tascam->playback_anchor);
|
usb_anchor_urb(tascam->playback_urbs[i],
|
||||||
err = usb_submit_urb(tascam->playback_urbs[i], GFP_ATOMIC);
|
&tascam->playback_anchor);
|
||||||
|
err = usb_submit_urb(tascam->playback_urbs[i],
|
||||||
|
GFP_ATOMIC);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
usb_unanchor_urb(tascam->playback_urbs[i]);
|
usb_unanchor_urb(tascam->playback_urbs[i]);
|
||||||
usb_put_urb(tascam->playback_urbs[i]);
|
usb_put_urb(tascam->playback_urbs[i]);
|
||||||
|
|
@ -307,8 +331,10 @@ int tascam_pcm_trigger(struct snd_pcm_substream *substream, int cmd) {
|
||||||
}
|
}
|
||||||
for (i = 0; i < NUM_CAPTURE_URBS; i++) {
|
for (i = 0; i < NUM_CAPTURE_URBS; i++) {
|
||||||
usb_get_urb(tascam->capture_urbs[i]);
|
usb_get_urb(tascam->capture_urbs[i]);
|
||||||
usb_anchor_urb(tascam->capture_urbs[i], &tascam->capture_anchor);
|
usb_anchor_urb(tascam->capture_urbs[i],
|
||||||
err = usb_submit_urb(tascam->capture_urbs[i], GFP_ATOMIC);
|
&tascam->capture_anchor);
|
||||||
|
err = usb_submit_urb(tascam->capture_urbs[i],
|
||||||
|
GFP_ATOMIC);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
usb_unanchor_urb(tascam->capture_urbs[i]);
|
usb_unanchor_urb(tascam->capture_urbs[i]);
|
||||||
usb_put_urb(tascam->capture_urbs[i]);
|
usb_put_urb(tascam->capture_urbs[i]);
|
||||||
|
|
@ -319,9 +345,9 @@ int tascam_pcm_trigger(struct snd_pcm_substream *substream, int cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
start_rollback:
|
start_rollback:
|
||||||
dev_err(tascam->card->dev, "Failed to submit URBs to start stream: %d\n",
|
dev_err(tascam->card->dev,
|
||||||
err);
|
"Failed to submit URBs to start stream: %d\n", err);
|
||||||
do_stop = true;
|
do_stop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -331,7 +357,8 @@ int tascam_pcm_trigger(struct snd_pcm_substream *substream, int cmd) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tascam_init_pcm(struct snd_pcm *pcm) {
|
int tascam_init_pcm(struct snd_pcm *pcm)
|
||||||
|
{
|
||||||
struct tascam_card *tascam = pcm->private_data;
|
struct tascam_card *tascam = pcm->private_data;
|
||||||
|
|
||||||
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &tascam_playback_ops);
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &tascam_playback_ops);
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@
|
||||||
*
|
*
|
||||||
* 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;
|
||||||
|
|
@ -31,7 +32,8 @@ 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;
|
||||||
|
|
@ -49,7 +51,8 @@ static int tascam_playback_close(struct snd_pcm_substream *substream) {
|
||||||
*
|
*
|
||||||
* Return: 0 on success.
|
* Return: 0 on success.
|
||||||
*/
|
*/
|
||||||
static int tascam_playback_prepare(struct snd_pcm_substream *substream) {
|
static int tascam_playback_prepare(struct snd_pcm_substream *substream)
|
||||||
|
{
|
||||||
struct tascam_card *tascam = snd_pcm_substream_chip(substream);
|
struct tascam_card *tascam = snd_pcm_substream_chip(substream);
|
||||||
struct snd_pcm_runtime *runtime = substream->runtime;
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
||||||
int i, u;
|
int i, u;
|
||||||
|
|
@ -67,16 +70,19 @@ static int tascam_playback_prepare(struct snd_pcm_substream *substream) {
|
||||||
|
|
||||||
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 =
|
||||||
|
FEEDBACK_URB_PACKETS * FEEDBACK_PACKET_SIZE;
|
||||||
for (j = 0; j < FEEDBACK_URB_PACKETS; j++) {
|
for (j = 0; j < FEEDBACK_URB_PACKETS; j++) {
|
||||||
f_urb->iso_frame_desc[j].offset = j * FEEDBACK_PACKET_SIZE;
|
f_urb->iso_frame_desc[j].offset =
|
||||||
|
j * FEEDBACK_PACKET_SIZE;
|
||||||
f_urb->iso_frame_desc[j].length = FEEDBACK_PACKET_SIZE;
|
f_urb->iso_frame_desc[j].length = FEEDBACK_PACKET_SIZE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -87,12 +93,15 @@ static int tascam_playback_prepare(struct snd_pcm_substream *substream) {
|
||||||
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,
|
||||||
|
tascam->playback_urb_alloc_size);
|
||||||
urb->transfer_buffer_length = total_bytes_in_urb;
|
urb->transfer_buffer_length = total_bytes_in_urb;
|
||||||
urb->number_of_packets = PLAYBACK_URB_PACKETS;
|
urb->number_of_packets = PLAYBACK_URB_PACKETS;
|
||||||
for (i = 0; i < PLAYBACK_URB_PACKETS; i++) {
|
for (i = 0; i < PLAYBACK_URB_PACKETS; i++) {
|
||||||
urb->iso_frame_desc[i].offset = i * nominal_bytes_per_packet;
|
urb->iso_frame_desc[i].offset =
|
||||||
urb->iso_frame_desc[i].length = nominal_bytes_per_packet;
|
i * nominal_bytes_per_packet;
|
||||||
|
urb->iso_frame_desc[i].length =
|
||||||
|
nominal_bytes_per_packet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,7 +118,8 @@ static int tascam_playback_prepare(struct snd_pcm_substream *substream) {
|
||||||
* Return: The current playback pointer position in frames.
|
* Return: The current playback pointer position in frames.
|
||||||
*/
|
*/
|
||||||
static snd_pcm_uframes_t
|
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 tascam_card *tascam = snd_pcm_substream_chip(substream);
|
||||||
struct snd_pcm_runtime *runtime = substream->runtime;
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
||||||
u64 pos;
|
u64 pos;
|
||||||
|
|
@ -124,6 +134,7 @@ tascam_playback_pointer(struct snd_pcm_substream *substream) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,7 +156,8 @@ const struct snd_pcm_ops tascam_playback_ops = {
|
||||||
.pointer = tascam_playback_pointer,
|
.pointer = tascam_playback_pointer,
|
||||||
};
|
};
|
||||||
|
|
||||||
void playback_urb_complete(struct urb *urb) {
|
void playback_urb_complete(struct urb *urb)
|
||||||
|
{
|
||||||
struct tascam_card *tascam = urb->context;
|
struct tascam_card *tascam = urb->context;
|
||||||
struct snd_pcm_substream *substream;
|
struct snd_pcm_substream *substream;
|
||||||
struct snd_pcm_runtime *runtime;
|
struct snd_pcm_runtime *runtime;
|
||||||
|
|
@ -157,7 +169,8 @@ void playback_urb_complete(struct urb *urb) {
|
||||||
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, "Playback URB failed: %d\n",
|
dev_err_ratelimited(tascam->card->dev,
|
||||||
|
"Playback URB failed: %d\n",
|
||||||
urb->status);
|
urb->status);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
@ -177,10 +190,12 @@ void playback_urb_complete(struct urb *urb) {
|
||||||
size_t bytes_for_packet;
|
size_t bytes_for_packet;
|
||||||
|
|
||||||
if (tascam->feedback_synced) {
|
if (tascam->feedback_synced) {
|
||||||
frames_for_packet = tascam->feedback_accumulator_pattern
|
frames_for_packet =
|
||||||
|
tascam->feedback_accumulator_pattern
|
||||||
[tascam->feedback_pattern_out_idx];
|
[tascam->feedback_pattern_out_idx];
|
||||||
tascam->feedback_pattern_out_idx =
|
tascam->feedback_pattern_out_idx =
|
||||||
(tascam->feedback_pattern_out_idx + 1) % FEEDBACK_ACCUMULATOR_SIZE;
|
(tascam->feedback_pattern_out_idx + 1) %
|
||||||
|
FEEDBACK_ACCUMULATOR_SIZE;
|
||||||
} else {
|
} else {
|
||||||
frames_for_packet = runtime->rate / 8000;
|
frames_for_packet = runtime->rate / 8000;
|
||||||
}
|
}
|
||||||
|
|
@ -203,18 +218,21 @@ void playback_urb_complete(struct urb *urb) {
|
||||||
|
|
||||||
/* Handle ring buffer wrap-around */
|
/* Handle ring buffer wrap-around */
|
||||||
if (offset_frames + frames_to_copy > runtime->buffer_size) {
|
if (offset_frames + frames_to_copy > runtime->buffer_size) {
|
||||||
size_t first_chunk_bytes =
|
size_t first_chunk_bytes = frames_to_bytes(
|
||||||
frames_to_bytes(runtime, runtime->buffer_size - offset_frames);
|
runtime, runtime->buffer_size - offset_frames);
|
||||||
size_t second_chunk_bytes = total_bytes_for_urb - first_chunk_bytes;
|
size_t second_chunk_bytes =
|
||||||
|
total_bytes_for_urb - first_chunk_bytes;
|
||||||
|
|
||||||
memcpy(dst_buf,
|
memcpy(dst_buf,
|
||||||
runtime->dma_area + frames_to_bytes(runtime, offset_frames),
|
runtime->dma_area +
|
||||||
|
frames_to_bytes(runtime, offset_frames),
|
||||||
first_chunk_bytes);
|
first_chunk_bytes);
|
||||||
memcpy(dst_buf + first_chunk_bytes, runtime->dma_area,
|
memcpy(dst_buf + first_chunk_bytes, runtime->dma_area,
|
||||||
second_chunk_bytes);
|
second_chunk_bytes);
|
||||||
} else {
|
} else {
|
||||||
memcpy(dst_buf,
|
memcpy(dst_buf,
|
||||||
runtime->dma_area + frames_to_bytes(runtime, offset_frames),
|
runtime->dma_area +
|
||||||
|
frames_to_bytes(runtime, offset_frames),
|
||||||
total_bytes_for_urb);
|
total_bytes_for_urb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -228,16 +246,19 @@ void playback_urb_complete(struct urb *urb) {
|
||||||
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 playback URB: %d\n", ret);
|
"Failed to resubmit playback URB: %d\n",
|
||||||
|
ret);
|
||||||
usb_unanchor_urb(urb);
|
usb_unanchor_urb(urb);
|
||||||
usb_put_urb(urb);
|
usb_put_urb(urb);
|
||||||
atomic_dec(&tascam->active_urbs); /* Decrement on failed resubmission */
|
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) {
|
void feedback_urb_complete(struct urb *urb)
|
||||||
|
{
|
||||||
struct tascam_card *tascam = urb->context;
|
struct tascam_card *tascam = urb->context;
|
||||||
struct snd_pcm_substream *playback_ss, *capture_ss;
|
struct snd_pcm_substream *playback_ss, *capture_ss;
|
||||||
struct snd_pcm_runtime *playback_rt, *capture_rt;
|
struct snd_pcm_runtime *playback_rt, *capture_rt;
|
||||||
|
|
@ -250,9 +271,11 @@ void feedback_urb_complete(struct urb *urb) {
|
||||||
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,
|
||||||
|
"Feedback URB failed: %d\n",
|
||||||
urb->status);
|
urb->status);
|
||||||
atomic_dec(&tascam->active_urbs); /* Decrement on failed resubmission */
|
atomic_dec(
|
||||||
|
&tascam->active_urbs); /* Decrement on failed resubmission */
|
||||||
}
|
}
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
@ -280,39 +303,50 @@ void feedback_urb_complete(struct urb *urb) {
|
||||||
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].status == 0 &&
|
||||||
urb->iso_frame_desc[p].actual_length >= 1);
|
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.base_feedback_value +
|
||||||
tascam->fpo.feedback_offset;
|
tascam->fpo.feedback_offset;
|
||||||
int pattern_idx;
|
int pattern_idx;
|
||||||
|
|
||||||
if (delta < 0) {
|
if (delta < 0) {
|
||||||
pattern_idx = 0; // Clamp to the lowest pattern
|
pattern_idx =
|
||||||
|
0; // Clamp to the lowest pattern
|
||||||
} else if (delta >= 5) {
|
} else if (delta >= 5) {
|
||||||
pattern_idx = 4; // Clamp to the highest pattern
|
pattern_idx =
|
||||||
|
4; // Clamp to the highest pattern
|
||||||
} else {
|
} else {
|
||||||
pattern_idx = delta;
|
pattern_idx = delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
pattern = tascam->fpo.full_frame_patterns[pattern_idx];
|
pattern =
|
||||||
|
tascam->fpo
|
||||||
|
.full_frame_patterns[pattern_idx];
|
||||||
tascam->feedback_consecutive_errors = 0;
|
tascam->feedback_consecutive_errors = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
unsigned int in_idx =
|
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
|
||||||
|
[in_idx] = pattern[i];
|
||||||
total_frames_in_urb += pattern[i];
|
total_frames_in_urb += pattern[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned int nominal_frames = playback_rt->rate / 8000;
|
unsigned int nominal_frames =
|
||||||
|
playback_rt->rate / 8000;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (tascam->feedback_synced) {
|
if (tascam->feedback_synced) {
|
||||||
|
|
@ -321,34 +355,42 @@ void feedback_urb_complete(struct urb *urb) {
|
||||||
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->stop_pcm_work);
|
||||||
tascam->feedback_synced = false;
|
tascam->feedback_synced = false;
|
||||||
goto continue_unlock;
|
goto continue_unlock;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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] = nominal_frames;
|
tascam->feedback_accumulator_pattern
|
||||||
|
[in_idx] = nominal_frames;
|
||||||
total_frames_in_urb += nominal_frames;
|
total_frames_in_urb += nominal_frames;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tascam->feedback_pattern_in_idx =
|
tascam->feedback_pattern_in_idx =
|
||||||
(tascam->feedback_pattern_in_idx + 8) % FEEDBACK_ACCUMULATOR_SIZE;
|
(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 <
|
||||||
(FEEDBACK_ACCUMULATOR_SIZE / 2);
|
(FEEDBACK_ACCUMULATOR_SIZE / 2);
|
||||||
bool was_behind = (old_in_idx - out_idx) % FEEDBACK_ACCUMULATOR_SIZE >=
|
bool was_behind = (old_in_idx - out_idx) %
|
||||||
|
FEEDBACK_ACCUMULATOR_SIZE >=
|
||||||
(FEEDBACK_ACCUMULATOR_SIZE / 2);
|
(FEEDBACK_ACCUMULATOR_SIZE / 2);
|
||||||
|
|
||||||
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,
|
||||||
|
"Sync Acquired! (in: %u, out: %u)\n",
|
||||||
new_in_idx, out_idx);
|
new_in_idx, out_idx);
|
||||||
tascam->feedback_synced = true;
|
tascam->feedback_synced = true;
|
||||||
tascam->feedback_consecutive_errors = 0;
|
tascam->feedback_consecutive_errors = 0;
|
||||||
|
|
@ -358,12 +400,14 @@ void feedback_urb_complete(struct urb *urb) {
|
||||||
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;
|
||||||
|
|
@ -374,10 +418,13 @@ void feedback_urb_complete(struct urb *urb) {
|
||||||
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) {
|
||||||
|
tascam->last_capture_period_pos =
|
||||||
|
current_capture_period;
|
||||||
capture_period_elapsed = true;
|
capture_period_elapsed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -395,7 +442,8 @@ continue_unlock:
|
||||||
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",
|
||||||
|
ret);
|
||||||
usb_unanchor_urb(urb);
|
usb_unanchor_urb(urb);
|
||||||
usb_put_urb(urb);
|
usb_put_urb(urb);
|
||||||
}
|
}
|
||||||
|
|
@ -403,7 +451,8 @@ out:
|
||||||
usb_put_urb(urb);
|
usb_put_urb(urb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tascam_stop_pcm_work_handler(struct work_struct *work) {
|
void tascam_stop_pcm_work_handler(struct work_struct *work)
|
||||||
|
{
|
||||||
struct tascam_card *tascam =
|
struct tascam_card *tascam =
|
||||||
container_of(work, struct tascam_card, stop_pcm_work);
|
container_of(work, struct tascam_card, stop_pcm_work);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue