forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/usb/line6/pod.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/slab.h>
....@@ -39,11 +35,9 @@
3935 Stages of POD startup procedure
4036 */
4137 enum {
42
- POD_STARTUP_INIT = 1,
4338 POD_STARTUP_VERSIONREQ,
44
- POD_STARTUP_WORKQUEUE,
4539 POD_STARTUP_SETUP,
46
- POD_STARTUP_LAST = POD_STARTUP_SETUP - 1
40
+ POD_STARTUP_DONE,
4741 };
4842
4943 enum {
....@@ -63,12 +57,6 @@
6357 /* Instrument monitor level */
6458 int monitor_level;
6559
66
- /* Timer for device initialization */
67
- struct timer_list startup_timer;
68
-
69
- /* Work handler for device initialization */
70
- struct work_struct startup_work;
71
-
7260 /* Current progress in startup procedure */
7361 int startup_progress;
7462
....@@ -81,6 +69,8 @@
8169 /* Device ID */
8270 int device_id;
8371 };
72
+
73
+#define line6_to_pod(x) container_of(x, struct usb_line6_pod, line6)
8474
8575 #define POD_SYSEX_CODE 3
8676
....@@ -120,7 +110,7 @@
120110 POD_BUSY_MIDISEND
121111 };
122112
123
-static struct snd_ratden pod_ratden = {
113
+static const struct snd_ratden pod_ratden = {
124114 .num_min = 78125,
125115 .num_max = 78125,
126116 .num_step = 1,
....@@ -173,10 +163,6 @@
173163 0xf2, 0x7e, 0x7f, 0x06, 0x02
174164 };
175165
176
-/* forward declarations: */
177
-static void pod_startup2(struct timer_list *t);
178
-static void pod_startup3(struct usb_line6_pod *pod);
179
-
180166 static char *pod_alloc_sysex_buffer(struct usb_line6_pod *pod, int code,
181167 int size)
182168 {
....@@ -189,14 +175,17 @@
189175 */
190176 static void line6_pod_process_message(struct usb_line6 *line6)
191177 {
192
- struct usb_line6_pod *pod = (struct usb_line6_pod *) line6;
178
+ struct usb_line6_pod *pod = line6_to_pod(line6);
193179 const unsigned char *buf = pod->line6.buffer_message;
194180
195181 if (memcmp(buf, pod_version_header, sizeof(pod_version_header)) == 0) {
196182 pod->firmware_version = buf[13] * 100 + buf[14] * 10 + buf[15];
197183 pod->device_id = ((int)buf[8] << 16) | ((int)buf[9] << 8) |
198184 (int) buf[10];
199
- pod_startup3(pod);
185
+ if (pod->startup_progress == POD_STARTUP_VERSIONREQ) {
186
+ pod->startup_progress = POD_STARTUP_SETUP;
187
+ schedule_delayed_work(&line6->startup_work, 0);
188
+ }
200189 return;
201190 }
202191
....@@ -281,46 +270,27 @@
281270 context). After the last one has finished, the device is ready to use.
282271 */
283272
284
-static void pod_startup1(struct usb_line6_pod *pod)
273
+static void pod_startup(struct usb_line6 *line6)
285274 {
286
- CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_INIT);
275
+ struct usb_line6_pod *pod = line6_to_pod(line6);
287276
288
- /* delay startup procedure: */
289
- line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2);
290
-}
277
+ switch (pod->startup_progress) {
278
+ case POD_STARTUP_VERSIONREQ:
279
+ /* request firmware version: */
280
+ line6_version_request_async(line6);
281
+ break;
282
+ case POD_STARTUP_SETUP:
283
+ /* serial number: */
284
+ line6_read_serial_number(&pod->line6, &pod->serial_number);
291285
292
-static void pod_startup2(struct timer_list *t)
293
-{
294
- struct usb_line6_pod *pod = from_timer(pod, t, startup_timer);
295
- struct usb_line6 *line6 = &pod->line6;
296
-
297
- CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_VERSIONREQ);
298
-
299
- /* request firmware version: */
300
- line6_version_request_async(line6);
301
-}
302
-
303
-static void pod_startup3(struct usb_line6_pod *pod)
304
-{
305
- CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_WORKQUEUE);
306
-
307
- /* schedule work for global work queue: */
308
- schedule_work(&pod->startup_work);
309
-}
310
-
311
-static void pod_startup4(struct work_struct *work)
312
-{
313
- struct usb_line6_pod *pod =
314
- container_of(work, struct usb_line6_pod, startup_work);
315
- struct usb_line6 *line6 = &pod->line6;
316
-
317
- CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_SETUP);
318
-
319
- /* serial number: */
320
- line6_read_serial_number(&pod->line6, &pod->serial_number);
321
-
322
- /* ALSA audio interface: */
323
- snd_card_register(line6->card);
286
+ /* ALSA audio interface: */
287
+ if (snd_card_register(line6->card))
288
+ dev_err(line6->ifcdev, "Failed to register POD card.\n");
289
+ pod->startup_progress = POD_STARTUP_DONE;
290
+ break;
291
+ default:
292
+ break;
293
+ }
324294 }
325295
326296 /* POD special files: */
....@@ -356,7 +326,7 @@
356326 struct snd_ctl_elem_value *ucontrol)
357327 {
358328 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
359
- struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6;
329
+ struct usb_line6_pod *pod = line6_to_pod(line6pcm->line6);
360330
361331 ucontrol->value.integer.value[0] = pod->monitor_level;
362332 return 0;
....@@ -367,7 +337,7 @@
367337 struct snd_ctl_elem_value *ucontrol)
368338 {
369339 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
370
- struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6;
340
+ struct usb_line6_pod *pod = line6_to_pod(line6pcm->line6);
371341
372342 if (ucontrol->value.integer.value[0] == pod->monitor_level)
373343 return 0;
....@@ -390,30 +360,16 @@
390360 };
391361
392362 /*
393
- POD device disconnected.
394
-*/
395
-static void line6_pod_disconnect(struct usb_line6 *line6)
396
-{
397
- struct usb_line6_pod *pod = (struct usb_line6_pod *)line6;
398
-
399
- del_timer_sync(&pod->startup_timer);
400
- cancel_work_sync(&pod->startup_work);
401
-}
402
-
403
-/*
404363 Try to init POD device.
405364 */
406365 static int pod_init(struct usb_line6 *line6,
407366 const struct usb_device_id *id)
408367 {
409368 int err;
410
- struct usb_line6_pod *pod = (struct usb_line6_pod *) line6;
369
+ struct usb_line6_pod *pod = line6_to_pod(line6);
411370
412371 line6->process_message = line6_pod_process_message;
413
- line6->disconnect = line6_pod_disconnect;
414
-
415
- timer_setup(&pod->startup_timer, NULL, 0);
416
- INIT_WORK(&pod->startup_work, pod_startup4);
372
+ line6->startup = pod_startup;
417373
418374 /* create sysfs entries: */
419375 err = snd_card_add_dev_attr(line6->card, &pod_dev_attr_group);
....@@ -441,7 +397,8 @@
441397 pod->monitor_level = POD_SYSTEM_INVALID;
442398
443399 /* initiate startup procedure: */
444
- pod_startup1(pod);
400
+ schedule_delayed_work(&line6->startup_work,
401
+ msecs_to_jiffies(POD_STARTUP_DELAY));
445402 }
446403
447404 return 0;