Skip to content

Commit 79289e2

Browse files
committed
ALSA: usb-audio: Refer to chip->usb_id for quirks and MIDI creation
This is a preliminary patch for the later change to allow a better quirk ID management. In the current USB-audio code, there are a few places looking at usb_device idVendor and idProduct fields directly even though we have already a static member in snd_usb_audio.usb_id. This patch modifies such codes to refer to the latter field. For achieving this, two slightly intensive changes have been done: - The snd_usb_audio object is set/reset via dev_getdrv() for the given USB device; it's needed for minimizing the changes for some existing quirks that take only usb_device object. - __snd_usbmidi_create() is introduced to receive the pre-given usb_id argument. The exported snd_usbmidi_create() is unchanged by calling this new function internally. Signed-off-by: Takashi Iwai <[email protected]>
1 parent 3ec622f commit 79289e2

File tree

5 files changed

+50
-27
lines changed

5 files changed

+50
-27
lines changed

sound/usb/card.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int
171171
if ((altsd->bInterfaceClass == USB_CLASS_AUDIO ||
172172
altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) &&
173173
altsd->bInterfaceSubClass == USB_SUBCLASS_MIDISTREAMING) {
174-
int err = snd_usbmidi_create(chip->card, iface,
175-
&chip->midi_list, NULL);
174+
int err = __snd_usbmidi_create(chip->card, iface,
175+
&chip->midi_list, NULL,
176+
chip->usb_id);
176177
if (err < 0) {
177178
dev_err(&dev->dev,
178179
"%u:%d: cannot create sequencer device\n",
@@ -311,6 +312,7 @@ static int snd_usb_audio_free(struct snd_usb_audio *chip)
311312
snd_usb_endpoint_free(ep);
312313

313314
mutex_destroy(&chip->mutex);
315+
dev_set_drvdata(&chip->dev->dev, NULL);
314316
kfree(chip);
315317
return 0;
316318
}
@@ -484,7 +486,7 @@ static int usb_audio_probe(struct usb_interface *intf,
484486
if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum)
485487
return -ENXIO;
486488

487-
err = snd_usb_apply_boot_quirk(dev, intf, quirk);
489+
err = snd_usb_apply_boot_quirk(dev, intf, quirk, id);
488490
if (err < 0)
489491
return err;
490492

@@ -503,6 +505,7 @@ static int usb_audio_probe(struct usb_interface *intf,
503505
goto __error;
504506
}
505507
chip = usb_chip[i];
508+
dev_set_drvdata(&dev->dev, chip);
506509
atomic_inc(&chip->active); /* avoid autopm */
507510
break;
508511
}

sound/usb/midi.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,10 +2320,11 @@ EXPORT_SYMBOL(snd_usbmidi_resume);
23202320
/*
23212321
* Creates and registers everything needed for a MIDI streaming interface.
23222322
*/
2323-
int snd_usbmidi_create(struct snd_card *card,
2324-
struct usb_interface *iface,
2325-
struct list_head *midi_list,
2326-
const struct snd_usb_audio_quirk *quirk)
2323+
int __snd_usbmidi_create(struct snd_card *card,
2324+
struct usb_interface *iface,
2325+
struct list_head *midi_list,
2326+
const struct snd_usb_audio_quirk *quirk,
2327+
unsigned int usb_id)
23272328
{
23282329
struct snd_usb_midi *umidi;
23292330
struct snd_usb_midi_endpoint_info endpoints[MIDI_MAX_ENDPOINTS];
@@ -2341,8 +2342,10 @@ int snd_usbmidi_create(struct snd_card *card,
23412342
spin_lock_init(&umidi->disc_lock);
23422343
init_rwsem(&umidi->disc_rwsem);
23432344
mutex_init(&umidi->mutex);
2344-
umidi->usb_id = USB_ID(le16_to_cpu(umidi->dev->descriptor.idVendor),
2345+
if (!usb_id)
2346+
usb_id = USB_ID(le16_to_cpu(umidi->dev->descriptor.idVendor),
23452347
le16_to_cpu(umidi->dev->descriptor.idProduct));
2348+
umidi->usb_id = usb_id;
23462349
setup_timer(&umidi->error_timer, snd_usbmidi_error_timer,
23472350
(unsigned long)umidi);
23482351

@@ -2464,4 +2467,4 @@ int snd_usbmidi_create(struct snd_card *card,
24642467
list_add_tail(&umidi->list, midi_list);
24652468
return 0;
24662469
}
2467-
EXPORT_SYMBOL(snd_usbmidi_create);
2470+
EXPORT_SYMBOL(__snd_usbmidi_create);

sound/usb/midi.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,20 @@ struct snd_usb_midi_endpoint_info {
3939

4040
/* for QUIRK_MIDI_AKAI, data is NULL */
4141

42-
int snd_usbmidi_create(struct snd_card *card,
42+
int __snd_usbmidi_create(struct snd_card *card,
43+
struct usb_interface *iface,
44+
struct list_head *midi_list,
45+
const struct snd_usb_audio_quirk *quirk,
46+
unsigned int usb_id);
47+
48+
static inline int snd_usbmidi_create(struct snd_card *card,
4349
struct usb_interface *iface,
4450
struct list_head *midi_list,
45-
const struct snd_usb_audio_quirk *quirk);
51+
const struct snd_usb_audio_quirk *quirk)
52+
{
53+
return __snd_usbmidi_create(card, iface, midi_list, quirk, 0);
54+
}
55+
4656
void snd_usbmidi_input_stop(struct list_head *p);
4757
void snd_usbmidi_input_start(struct list_head *p);
4858
void snd_usbmidi_disconnect(struct list_head *p);

sound/usb/quirks.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,9 @@ static int create_uaxx_quirk(struct snd_usb_audio *chip,
446446
const struct snd_usb_audio_quirk *quirk =
447447
chip->usb_id == USB_ID(0x0582, 0x002b)
448448
? &ua700_quirk : &uaxx_quirk;
449-
return snd_usbmidi_create(chip->card, iface,
450-
&chip->midi_list, quirk);
449+
return __snd_usbmidi_create(chip->card, iface,
450+
&chip->midi_list, quirk,
451+
chip->usb_id);
451452
}
452453

453454
if (altsd->bNumEndpoints != 1)
@@ -974,11 +975,9 @@ int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
974975

975976
int snd_usb_apply_boot_quirk(struct usb_device *dev,
976977
struct usb_interface *intf,
977-
const struct snd_usb_audio_quirk *quirk)
978+
const struct snd_usb_audio_quirk *quirk,
979+
unsigned int id)
978980
{
979-
u32 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
980-
le16_to_cpu(dev->descriptor.idProduct));
981-
982981
switch (id) {
983982
case USB_ID(0x041e, 0x3000):
984983
/* SB Extigy needs special boot-up sequence */
@@ -1182,7 +1181,7 @@ void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep)
11821181
* "Playback Design" products send bogus feedback data at the start
11831182
* of the stream. Ignore them.
11841183
*/
1185-
if ((le16_to_cpu(ep->chip->dev->descriptor.idVendor) == 0x23ba) &&
1184+
if (USB_ID_VENDOR(ep->chip->usb_id) == 0x23ba &&
11861185
ep->type == SND_USB_ENDPOINT_TYPE_SYNC)
11871186
ep->skip_packets = 4;
11881187

@@ -1201,51 +1200,58 @@ void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep)
12011200

12021201
void snd_usb_set_interface_quirk(struct usb_device *dev)
12031202
{
1203+
struct snd_usb_audio *chip = dev_get_drvdata(&dev->dev);
1204+
1205+
if (!chip)
1206+
return;
12041207
/*
12051208
* "Playback Design" products need a 50ms delay after setting the
12061209
* USB interface.
12071210
*/
1208-
switch (le16_to_cpu(dev->descriptor.idVendor)) {
1211+
switch (USB_ID_VENDOR(chip->usb_id)) {
12091212
case 0x23ba: /* Playback Design */
12101213
case 0x0644: /* TEAC Corp. */
12111214
mdelay(50);
12121215
break;
12131216
}
12141217
}
12151218

1219+
/* quirk applied after snd_usb_ctl_msg(); not applied during boot quirks */
12161220
void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
12171221
__u8 request, __u8 requesttype, __u16 value,
12181222
__u16 index, void *data, __u16 size)
12191223
{
1224+
struct snd_usb_audio *chip = dev_get_drvdata(&dev->dev);
1225+
1226+
if (!chip)
1227+
return;
12201228
/*
12211229
* "Playback Design" products need a 20ms delay after each
12221230
* class compliant request
12231231
*/
1224-
if ((le16_to_cpu(dev->descriptor.idVendor) == 0x23ba) &&
1232+
if (USB_ID_VENDOR(chip->usb_id) == 0x23ba &&
12251233
(requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
12261234
mdelay(20);
12271235

12281236
/*
12291237
* "TEAC Corp." products need a 20ms delay after each
12301238
* class compliant request
12311239
*/
1232-
if ((le16_to_cpu(dev->descriptor.idVendor) == 0x0644) &&
1240+
if (USB_ID_VENDOR(chip->usb_id) == 0x0644 &&
12331241
(requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
12341242
mdelay(20);
12351243

12361244
/* Marantz/Denon devices with USB DAC functionality need a delay
12371245
* after each class compliant request
12381246
*/
1239-
if (is_marantz_denon_dac(USB_ID(le16_to_cpu(dev->descriptor.idVendor),
1240-
le16_to_cpu(dev->descriptor.idProduct)))
1247+
if (is_marantz_denon_dac(chip->usb_id)
12411248
&& (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
12421249
mdelay(20);
12431250

12441251
/* Zoom R16/24 needs a tiny delay here, otherwise requests like
12451252
* get/set frequency return as failed despite actually succeeding.
12461253
*/
1247-
if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1686) &&
1248-
(le16_to_cpu(dev->descriptor.idProduct) == 0x00dd) &&
1254+
if (chip->usb_id == USB_ID(0x1686, 0x00dd) &&
12491255
(requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
12501256
mdelay(1);
12511257
}
@@ -1262,7 +1268,7 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
12621268
unsigned int sample_bytes)
12631269
{
12641270
/* Playback Designs */
1265-
if (le16_to_cpu(chip->dev->descriptor.idVendor) == 0x23ba) {
1271+
if (USB_ID_VENDOR(chip->usb_id) == 0x23ba) {
12661272
switch (fp->altsetting) {
12671273
case 1:
12681274
fp->dsd_dop = true;

sound/usb/quirks.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
1616

1717
int snd_usb_apply_boot_quirk(struct usb_device *dev,
1818
struct usb_interface *intf,
19-
const struct snd_usb_audio_quirk *quirk);
19+
const struct snd_usb_audio_quirk *quirk,
20+
unsigned int usb_id);
2021

2122
void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
2223
struct audioformat *fmt);

0 commit comments

Comments
 (0)