forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/sound/usb/line6/driver.c
....@@ -1,12 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Line 6 Linux USB driver
34 *
45 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License as
8
- * published by the Free Software Foundation, version 2.
9
- *
106 */
117
128 #include <linux/kernel.h>
....@@ -101,7 +97,7 @@
10197 /*
10298 Send raw message in pieces of wMaxPacketSize bytes.
10399 */
104
-static int line6_send_raw_message(struct usb_line6 *line6, const char *buffer,
100
+int line6_send_raw_message(struct usb_line6 *line6, const char *buffer,
105101 int size)
106102 {
107103 int i, done = 0;
....@@ -136,6 +132,7 @@
136132
137133 return done;
138134 }
135
+EXPORT_SYMBOL_GPL(line6_send_raw_message);
139136
140137 /*
141138 Notification of completion of asynchronous request transmission.
....@@ -194,17 +191,6 @@
194191 kfree(msg);
195192 return retval;
196193 }
197
-
198
-/*
199
- Setup and start timer.
200
-*/
201
-void line6_start_timer(struct timer_list *timer, unsigned long msecs,
202
- void (*function)(struct timer_list *t))
203
-{
204
- timer->function = function;
205
- mod_timer(timer, jiffies + msecs_to_jiffies(msecs));
206
-}
207
-EXPORT_SYMBOL_GPL(line6_start_timer);
208194
209195 /*
210196 Asynchronously send raw message.
....@@ -318,7 +304,8 @@
318304 for (;;) {
319305 done =
320306 line6_midibuf_read(mb, line6->buffer_message,
321
- LINE6_MIDI_MESSAGE_MAXLEN);
307
+ LINE6_MIDI_MESSAGE_MAXLEN,
308
+ LINE6_MIDIBUF_READ_RX);
322309
323310 if (done <= 0)
324311 break;
....@@ -351,23 +338,18 @@
351338 {
352339 struct usb_device *usbdev = line6->usbdev;
353340 int ret;
354
- unsigned char *len;
341
+ u8 len;
355342 unsigned count;
356343
357344 if (address > 0xffff || datalen > 0xff)
358345 return -EINVAL;
359346
360
- len = kmalloc(sizeof(*len), GFP_KERNEL);
361
- if (!len)
362
- return -ENOMEM;
363
-
364347 /* query the serial number: */
365
- ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
366
- USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
367
- (datalen << 8) | 0x21, address,
368
- NULL, 0, LINE6_TIMEOUT);
369
-
370
- if (ret < 0) {
348
+ ret = usb_control_msg_send(usbdev, 0, 0x67,
349
+ USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
350
+ (datalen << 8) | 0x21, address, NULL, 0,
351
+ LINE6_TIMEOUT, GFP_KERNEL);
352
+ if (ret) {
371353 dev_err(line6->ifcdev, "read request failed (error %d)\n", ret);
372354 goto exit;
373355 }
....@@ -376,45 +358,42 @@
376358 for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
377359 mdelay(LINE6_READ_WRITE_STATUS_DELAY);
378360
379
- ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
380
- USB_TYPE_VENDOR | USB_RECIP_DEVICE |
381
- USB_DIR_IN,
382
- 0x0012, 0x0000, len, 1,
383
- LINE6_TIMEOUT);
384
- if (ret < 0) {
361
+ ret = usb_control_msg_recv(usbdev, 0, 0x67,
362
+ USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
363
+ 0x0012, 0x0000, &len, 1,
364
+ LINE6_TIMEOUT, GFP_KERNEL);
365
+ if (ret) {
385366 dev_err(line6->ifcdev,
386367 "receive length failed (error %d)\n", ret);
387368 goto exit;
388369 }
389370
390
- if (*len != 0xff)
371
+ if (len != 0xff)
391372 break;
392373 }
393374
394375 ret = -EIO;
395
- if (*len == 0xff) {
376
+ if (len == 0xff) {
396377 dev_err(line6->ifcdev, "read failed after %d retries\n",
397378 count);
398379 goto exit;
399
- } else if (*len != datalen) {
380
+ } else if (len != datalen) {
400381 /* should be equal or something went wrong */
401382 dev_err(line6->ifcdev,
402383 "length mismatch (expected %d, got %d)\n",
403
- (int)datalen, (int)*len);
384
+ (int)datalen, len);
404385 goto exit;
405386 }
406387
407388 /* receive the result: */
408
- ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
409
- USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
410
- 0x0013, 0x0000, data, datalen,
411
- LINE6_TIMEOUT);
412
-
413
- if (ret < 0)
389
+ ret = usb_control_msg_recv(usbdev, 0, 0x67,
390
+ USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
391
+ 0x0013, 0x0000, data, datalen, LINE6_TIMEOUT,
392
+ GFP_KERNEL);
393
+ if (ret)
414394 dev_err(line6->ifcdev, "read failed (error %d)\n", ret);
415395
416396 exit:
417
- kfree(len);
418397 return ret;
419398 }
420399 EXPORT_SYMBOL_GPL(line6_read_data);
....@@ -433,16 +412,15 @@
433412 if (address > 0xffff || datalen > 0xffff)
434413 return -EINVAL;
435414
436
- status = kmalloc(sizeof(*status), GFP_KERNEL);
415
+ status = kmalloc(1, GFP_KERNEL);
437416 if (!status)
438417 return -ENOMEM;
439418
440
- ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
441
- USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
442
- 0x0022, address, data, datalen,
443
- LINE6_TIMEOUT);
444
-
445
- if (ret < 0) {
419
+ ret = usb_control_msg_send(usbdev, 0, 0x67,
420
+ USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
421
+ 0x0022, address, data, datalen, LINE6_TIMEOUT,
422
+ GFP_KERNEL);
423
+ if (ret) {
446424 dev_err(line6->ifcdev,
447425 "write request failed (error %d)\n", ret);
448426 goto exit;
....@@ -451,14 +429,11 @@
451429 for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
452430 mdelay(LINE6_READ_WRITE_STATUS_DELAY);
453431
454
- ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
455
- 0x67,
456
- USB_TYPE_VENDOR | USB_RECIP_DEVICE |
457
- USB_DIR_IN,
458
- 0x0012, 0x0000,
459
- status, 1, LINE6_TIMEOUT);
460
-
461
- if (ret < 0) {
432
+ ret = usb_control_msg_recv(usbdev, 0, 0x67,
433
+ USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
434
+ 0x0012, 0x0000, status, 1, LINE6_TIMEOUT,
435
+ GFP_KERNEL);
436
+ if (ret) {
462437 dev_err(line6->ifcdev,
463438 "receiving status failed (error %d)\n", ret);
464439 goto exit;
....@@ -565,6 +540,7 @@
565540 /* NOTE: hwdep layer provides atomicity here */
566541
567542 line6->messages.active = 1;
543
+ line6->messages.nonblock = file->f_flags & O_NONBLOCK ? 1 : 0;
568544
569545 return 0;
570546 }
....@@ -593,6 +569,9 @@
593569
594570 while (kfifo_len(&line6->messages.fifo) == 0) {
595571 mutex_unlock(&line6->messages.read_lock);
572
+
573
+ if (line6->messages.nonblock)
574
+ return -EAGAIN;
596575
597576 rv = wait_event_interruptible(
598577 line6->messages.wait_queue,
....@@ -641,11 +620,27 @@
641620 return rv;
642621 }
643622
623
+static __poll_t
624
+line6_hwdep_poll(struct snd_hwdep *hwdep, struct file *file, poll_table *wait)
625
+{
626
+ __poll_t rv;
627
+ struct usb_line6 *line6 = hwdep->private_data;
628
+
629
+ poll_wait(file, &line6->messages.wait_queue, wait);
630
+
631
+ mutex_lock(&line6->messages.read_lock);
632
+ rv = kfifo_len(&line6->messages.fifo) == 0 ? 0 : EPOLLIN | EPOLLRDNORM;
633
+ mutex_unlock(&line6->messages.read_lock);
634
+
635
+ return rv;
636
+}
637
+
644638 static const struct snd_hwdep_ops hwdep_ops = {
645639 .open = line6_hwdep_open,
646640 .release = line6_hwdep_release,
647641 .read = line6_hwdep_read,
648642 .write = line6_hwdep_write,
643
+ .poll = line6_hwdep_poll,
649644 };
650645
651646 /* Insert into circular buffer */
....@@ -875,10 +870,8 @@
875870 if (line6->properties->capabilities & LINE6_CAP_CONTROL)
876871 line6_stop_listen(line6);
877872
878
- if (line6pcm != NULL) {
879
- snd_pcm_suspend_all(line6pcm->pcm);
873
+ if (line6pcm != NULL)
880874 line6pcm->flags = 0;
881
- }
882875
883876 return 0;
884877 }