forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
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.
....@@ -351,23 +337,18 @@
351337 {
352338 struct usb_device *usbdev = line6->usbdev;
353339 int ret;
354
- unsigned char *len;
340
+ u8 len;
355341 unsigned count;
356342
357343 if (address > 0xffff || datalen > 0xff)
358344 return -EINVAL;
359345
360
- len = kmalloc(sizeof(*len), GFP_KERNEL);
361
- if (!len)
362
- return -ENOMEM;
363
-
364346 /* 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) {
347
+ ret = usb_control_msg_send(usbdev, 0, 0x67,
348
+ USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
349
+ (datalen << 8) | 0x21, address, NULL, 0,
350
+ LINE6_TIMEOUT, GFP_KERNEL);
351
+ if (ret) {
371352 dev_err(line6->ifcdev, "read request failed (error %d)\n", ret);
372353 goto exit;
373354 }
....@@ -376,45 +357,42 @@
376357 for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
377358 mdelay(LINE6_READ_WRITE_STATUS_DELAY);
378359
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) {
360
+ ret = usb_control_msg_recv(usbdev, 0, 0x67,
361
+ USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
362
+ 0x0012, 0x0000, &len, 1,
363
+ LINE6_TIMEOUT, GFP_KERNEL);
364
+ if (ret) {
385365 dev_err(line6->ifcdev,
386366 "receive length failed (error %d)\n", ret);
387367 goto exit;
388368 }
389369
390
- if (*len != 0xff)
370
+ if (len != 0xff)
391371 break;
392372 }
393373
394374 ret = -EIO;
395
- if (*len == 0xff) {
375
+ if (len == 0xff) {
396376 dev_err(line6->ifcdev, "read failed after %d retries\n",
397377 count);
398378 goto exit;
399
- } else if (*len != datalen) {
379
+ } else if (len != datalen) {
400380 /* should be equal or something went wrong */
401381 dev_err(line6->ifcdev,
402382 "length mismatch (expected %d, got %d)\n",
403
- (int)datalen, (int)*len);
383
+ (int)datalen, len);
404384 goto exit;
405385 }
406386
407387 /* 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)
388
+ ret = usb_control_msg_recv(usbdev, 0, 0x67,
389
+ USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
390
+ 0x0013, 0x0000, data, datalen, LINE6_TIMEOUT,
391
+ GFP_KERNEL);
392
+ if (ret)
414393 dev_err(line6->ifcdev, "read failed (error %d)\n", ret);
415394
416395 exit:
417
- kfree(len);
418396 return ret;
419397 }
420398 EXPORT_SYMBOL_GPL(line6_read_data);
....@@ -433,16 +411,15 @@
433411 if (address > 0xffff || datalen > 0xffff)
434412 return -EINVAL;
435413
436
- status = kmalloc(sizeof(*status), GFP_KERNEL);
414
+ status = kmalloc(1, GFP_KERNEL);
437415 if (!status)
438416 return -ENOMEM;
439417
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) {
418
+ ret = usb_control_msg_send(usbdev, 0, 0x67,
419
+ USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
420
+ 0x0022, address, data, datalen, LINE6_TIMEOUT,
421
+ GFP_KERNEL);
422
+ if (ret) {
446423 dev_err(line6->ifcdev,
447424 "write request failed (error %d)\n", ret);
448425 goto exit;
....@@ -451,14 +428,11 @@
451428 for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
452429 mdelay(LINE6_READ_WRITE_STATUS_DELAY);
453430
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) {
431
+ ret = usb_control_msg_recv(usbdev, 0, 0x67,
432
+ USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
433
+ 0x0012, 0x0000, status, 1, LINE6_TIMEOUT,
434
+ GFP_KERNEL);
435
+ if (ret) {
462436 dev_err(line6->ifcdev,
463437 "receiving status failed (error %d)\n", ret);
464438 goto exit;
....@@ -565,6 +539,7 @@
565539 /* NOTE: hwdep layer provides atomicity here */
566540
567541 line6->messages.active = 1;
542
+ line6->messages.nonblock = file->f_flags & O_NONBLOCK ? 1 : 0;
568543
569544 return 0;
570545 }
....@@ -593,6 +568,9 @@
593568
594569 while (kfifo_len(&line6->messages.fifo) == 0) {
595570 mutex_unlock(&line6->messages.read_lock);
571
+
572
+ if (line6->messages.nonblock)
573
+ return -EAGAIN;
596574
597575 rv = wait_event_interruptible(
598576 line6->messages.wait_queue,
....@@ -641,11 +619,27 @@
641619 return rv;
642620 }
643621
622
+static __poll_t
623
+line6_hwdep_poll(struct snd_hwdep *hwdep, struct file *file, poll_table *wait)
624
+{
625
+ __poll_t rv;
626
+ struct usb_line6 *line6 = hwdep->private_data;
627
+
628
+ poll_wait(file, &line6->messages.wait_queue, wait);
629
+
630
+ mutex_lock(&line6->messages.read_lock);
631
+ rv = kfifo_len(&line6->messages.fifo) == 0 ? 0 : EPOLLIN | EPOLLRDNORM;
632
+ mutex_unlock(&line6->messages.read_lock);
633
+
634
+ return rv;
635
+}
636
+
644637 static const struct snd_hwdep_ops hwdep_ops = {
645638 .open = line6_hwdep_open,
646639 .release = line6_hwdep_release,
647640 .read = line6_hwdep_read,
648641 .write = line6_hwdep_write,
642
+ .poll = line6_hwdep_poll,
649643 };
650644
651645 /* Insert into circular buffer */
....@@ -875,10 +869,8 @@
875869 if (line6->properties->capabilities & LINE6_CAP_CONTROL)
876870 line6_stop_listen(line6);
877871
878
- if (line6pcm != NULL) {
879
- snd_pcm_suspend_all(line6pcm->pcm);
872
+ if (line6pcm != NULL)
880873 line6pcm->flags = 0;
881
- }
882874
883875 return 0;
884876 }