diff options
author | Takashi Iwai <tiwai@suse.de> | 2018-04-03 11:34:57 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2018-04-07 07:07:05 -0400 |
commit | f7645bd636d06f64f3eadb63cf1c8145219fdc58 (patch) | |
tree | e9ed254ec66ef280f0127561d5aede51c2b1f391 | |
parent | a820ccbe21e8ce8e86c39cd1d3bc8c7d1cbb949b (diff) |
ALSA: usb-audio: Refactor clock finder helpers
There are lots of open-coded functions to find a clock source,
selector and multiplier. Now there are both v2 and v3, so six
variants.
This patch refactors the code to use a common helper for the main
loop, and define each validator function for each target.
There is no functional change.
Fixes: 9a2fe9b801f5 ("ALSA: usb: initial USB Audio Device Class 3.0 support")
Reviewed-by: Ruslan Bilovol <ruslan.bilovol@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | sound/usb/clock.c | 127 |
1 files changed, 53 insertions, 74 deletions
diff --git a/sound/usb/clock.c b/sound/usb/clock.c index ab39ccb974c6..27c2275a2505 100644 --- a/sound/usb/clock.c +++ b/sound/usb/clock.c | |||
@@ -35,105 +35,84 @@ | |||
35 | #include "clock.h" | 35 | #include "clock.h" |
36 | #include "quirks.h" | 36 | #include "quirks.h" |
37 | 37 | ||
38 | static struct uac_clock_source_descriptor * | 38 | static void *find_uac_clock_desc(struct usb_host_interface *iface, int id, |
39 | snd_usb_find_clock_source(struct usb_host_interface *ctrl_iface, | 39 | bool (*validator)(void *, int), u8 type) |
40 | int clock_id) | ||
41 | { | 40 | { |
42 | struct uac_clock_source_descriptor *cs = NULL; | 41 | void *cs = NULL; |
43 | 42 | ||
44 | while ((cs = snd_usb_find_csint_desc(ctrl_iface->extra, | 43 | while ((cs = snd_usb_find_csint_desc(iface->extra, iface->extralen, |
45 | ctrl_iface->extralen, | 44 | cs, type))) { |
46 | cs, UAC2_CLOCK_SOURCE))) { | 45 | if (validator(cs, id)) |
47 | if (cs->bLength >= sizeof(*cs) && cs->bClockID == clock_id) | ||
48 | return cs; | 46 | return cs; |
49 | } | 47 | } |
50 | 48 | ||
51 | return NULL; | 49 | return NULL; |
52 | } | 50 | } |
53 | 51 | ||
54 | static struct uac3_clock_source_descriptor * | 52 | static bool validate_clock_source_v2(void *p, int id) |
55 | snd_usb_find_clock_source_v3(struct usb_host_interface *ctrl_iface, | ||
56 | int clock_id) | ||
57 | { | 53 | { |
58 | struct uac3_clock_source_descriptor *cs = NULL; | 54 | struct uac_clock_source_descriptor *cs = p; |
59 | 55 | return cs->bLength >= sizeof(*cs) && cs->bClockID == id; | |
60 | while ((cs = snd_usb_find_csint_desc(ctrl_iface->extra, | ||
61 | ctrl_iface->extralen, | ||
62 | cs, UAC3_CLOCK_SOURCE))) { | ||
63 | if (cs->bClockID == clock_id) | ||
64 | return cs; | ||
65 | } | ||
66 | |||
67 | return NULL; | ||
68 | } | 56 | } |
69 | 57 | ||
70 | static struct uac_clock_selector_descriptor * | 58 | static bool validate_clock_source_v3(void *p, int id) |
71 | snd_usb_find_clock_selector(struct usb_host_interface *ctrl_iface, | ||
72 | int clock_id) | ||
73 | { | 59 | { |
74 | struct uac_clock_selector_descriptor *cs = NULL; | 60 | struct uac3_clock_source_descriptor *cs = p; |
75 | 61 | return cs->bClockID == id; | |
76 | while ((cs = snd_usb_find_csint_desc(ctrl_iface->extra, | ||
77 | ctrl_iface->extralen, | ||
78 | cs, UAC2_CLOCK_SELECTOR))) { | ||
79 | if (cs->bLength >= sizeof(*cs) && cs->bClockID == clock_id) { | ||
80 | if (cs->bLength < 5 + cs->bNrInPins) | ||
81 | return NULL; | ||
82 | return cs; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | return NULL; | ||
87 | } | 62 | } |
88 | 63 | ||
89 | static struct uac3_clock_selector_descriptor * | 64 | static bool validate_clock_selector_v2(void *p, int id) |
90 | snd_usb_find_clock_selector_v3(struct usb_host_interface *ctrl_iface, | ||
91 | int clock_id) | ||
92 | { | 65 | { |
93 | struct uac3_clock_selector_descriptor *cs = NULL; | 66 | struct uac_clock_selector_descriptor *cs = p; |
94 | 67 | return cs->bLength >= sizeof(*cs) && cs->bClockID == id && | |
95 | while ((cs = snd_usb_find_csint_desc(ctrl_iface->extra, | 68 | cs->bLength >= 5 + cs->bNrInPins; |
96 | ctrl_iface->extralen, | ||
97 | cs, UAC3_CLOCK_SELECTOR))) { | ||
98 | if (cs->bClockID == clock_id) | ||
99 | return cs; | ||
100 | } | ||
101 | |||
102 | return NULL; | ||
103 | } | 69 | } |
104 | 70 | ||
105 | static struct uac_clock_multiplier_descriptor * | 71 | static bool validate_clock_selector_v3(void *p, int id) |
106 | snd_usb_find_clock_multiplier(struct usb_host_interface *ctrl_iface, | ||
107 | int clock_id) | ||
108 | { | 72 | { |
109 | struct uac_clock_multiplier_descriptor *cs = NULL; | 73 | struct uac3_clock_selector_descriptor *cs = p; |
110 | 74 | return cs->bClockID == id; | |
111 | while ((cs = snd_usb_find_csint_desc(ctrl_iface->extra, | ||
112 | ctrl_iface->extralen, | ||
113 | cs, UAC2_CLOCK_MULTIPLIER))) { | ||
114 | if (cs->bLength >= sizeof(*cs) && cs->bClockID == clock_id) | ||
115 | return cs; | ||
116 | } | ||
117 | |||
118 | return NULL; | ||
119 | } | 75 | } |
120 | 76 | ||
121 | static struct uac3_clock_multiplier_descriptor * | 77 | static bool validate_clock_multiplier_v2(void *p, int id) |
122 | snd_usb_find_clock_multiplier_v3(struct usb_host_interface *ctrl_iface, | ||
123 | int clock_id) | ||
124 | { | 78 | { |
125 | struct uac3_clock_multiplier_descriptor *cs = NULL; | 79 | struct uac_clock_multiplier_descriptor *cs = p; |
80 | return cs->bLength >= sizeof(*cs) && cs->bClockID == id; | ||
81 | } | ||
126 | 82 | ||
127 | while ((cs = snd_usb_find_csint_desc(ctrl_iface->extra, | 83 | static bool validate_clock_multiplier_v3(void *p, int id) |
128 | ctrl_iface->extralen, | 84 | { |
129 | cs, UAC3_CLOCK_MULTIPLIER))) { | 85 | struct uac3_clock_multiplier_descriptor *cs = p; |
130 | if (cs->bClockID == clock_id) | 86 | return cs->bClockID == id; |
131 | return cs; | 87 | } |
132 | } | ||
133 | 88 | ||
134 | return NULL; | 89 | #define DEFINE_FIND_HELPER(name, obj, validator, type) \ |
90 | static obj *name(struct usb_host_interface *iface, int id) \ | ||
91 | { \ | ||
92 | return find_uac_clock_desc(iface, id, validator, type); \ | ||
135 | } | 93 | } |
136 | 94 | ||
95 | DEFINE_FIND_HELPER(snd_usb_find_clock_source, | ||
96 | struct uac_clock_source_descriptor, | ||
97 | validate_clock_source_v2, UAC2_CLOCK_SOURCE); | ||
98 | DEFINE_FIND_HELPER(snd_usb_find_clock_source_v3, | ||
99 | struct uac3_clock_source_descriptor, | ||
100 | validate_clock_source_v3, UAC3_CLOCK_SOURCE); | ||
101 | |||
102 | DEFINE_FIND_HELPER(snd_usb_find_clock_selector, | ||
103 | struct uac_clock_selector_descriptor, | ||
104 | validate_clock_selector_v2, UAC2_CLOCK_SELECTOR); | ||
105 | DEFINE_FIND_HELPER(snd_usb_find_clock_selector_v3, | ||
106 | struct uac3_clock_selector_descriptor, | ||
107 | validate_clock_selector_v3, UAC3_CLOCK_SELECTOR); | ||
108 | |||
109 | DEFINE_FIND_HELPER(snd_usb_find_clock_multiplier, | ||
110 | struct uac_clock_multiplier_descriptor, | ||
111 | validate_clock_multiplier_v2, UAC2_CLOCK_MULTIPLIER); | ||
112 | DEFINE_FIND_HELPER(snd_usb_find_clock_multiplier_v3, | ||
113 | struct uac3_clock_multiplier_descriptor, | ||
114 | validate_clock_multiplier_v3, UAC3_CLOCK_MULTIPLIER); | ||
115 | |||
137 | static int uac_clock_selector_get_val(struct snd_usb_audio *chip, int selector_id) | 116 | static int uac_clock_selector_get_val(struct snd_usb_audio *chip, int selector_id) |
138 | { | 117 | { |
139 | unsigned char buf; | 118 | unsigned char buf; |