Skip to contentSkip to conversation

snd_usb_usx2y: use request_firmware() instead of snd_hw based firmware loading

PATCH In review Karsten Wiese 2 participants 2 messages Mar 7, 2006 – Mar 8, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 snd_usb_usx2y: use request_firmware() instead of snd_hw based firmware loading

Hi Takashi

This is one step to make hotplug work here on FC4 again. other things needed are updated firmwareloader, hotplug-scripts and us428control.

The new firmwareloader actually only needs to run once to unpack the firmware. The "make install" in alsa-firmware/usx2yloader puts the firmware into /lib/firmware then.

I got it here, but before submission:
Would you like to change and keep the alsa-tools/usx2yloader for that? Alternatively there could be a new "usx2y-fw-unpack" binary in alsa-firmware/usx2yloader and alsa-tools/usx2yloader would vanish.

Karsten

Use request_firmware() instead of snd_hw based firmware loading

Old method was a hack. New is standard.
You'll need updates to the hotplug infrastructure to use it.

Index: alsa-driver/usb/usx2y/usX2Yhwdep.patch
===================================================================
RCS file: /cvsroot/alsa/alsa-driver/usb/usx2y/usX2Yhwdep.patch,v retrieving revision 1.4

usb/usx2y/usX2Yhwdep.patch +7 -47
diff -U3 -r1.4 usX2Yhwdep.patch
@@ -1,5 +1,5 @@
---- ../../alsa-kernel/usb/usx2y/usX2Yhwdep.c	2005-11-13 15:21:59.000000000 +0100
-+++ usX2Yhwdep.c	2005-11-13 19:04:20.000000000 +0100
+--- ../../alsa-kernel/usb/usx2y/usX2Yhwdep.c	2006-03-07 14:07:46.000000000 +0100
++++ usX2Yhwdep.c	2006-03-07 15:28:44.000000000 +0100
 @@ -1,3 +1,14 @@
 +#include <linux/config.h>
 +#include <linux/version.h>
@@ -15,8 +15,8 @@
  /*
   * Driver for Tascam US-X2Y USB soundcards
   *
-@@ -34,7 +45,13 @@
- int usX2Y_hwdep_pcm_new(struct snd_card *card);
+@@ -33,7 +44,13 @@
+ 
  
  
 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
@@ -29,7 +29,7 @@
  {
  	unsigned long offset;
  	struct page * page;
-@@ -46,7 +63,11 @@
+@@ -45,7 +62,11 @@
  		   (address - area->vm_start) >> PAGE_SHIFT,
  		   address);
  	
@@ -41,7 +41,7 @@
  	offset += address - area->vm_start;
  	snd_assert((offset % PAGE_SIZE) == 0, return NOPAGE_OOM);
  	vaddr = (char*)((struct usX2Ydev *)area->vm_private_data)->us428ctls_sharedmem + offset;
-@@ -54,10 +75,20 @@
+@@ -53,10 +74,20 @@
  	get_page(page);
  	snd_printdd( "vaddr=%p made us428ctls_vm_nopage() return %p; offset=%lX\n", vaddr, page, offset);
  
@@ -62,7 +62,7 @@
  }
  
  static struct vm_operations_struct us428ctls_vm_ops = {
-@@ -88,8 +119,14 @@
+@@ -86,8 +117,14 @@
  		us428->us428ctls_sharedmem->CtlSnapShotLast = -2;
  	}
  	area->vm_ops = &us428ctls_vm_ops;
@@ -77,43 +77,3 @@
  	return 0;
  }
  
-@@ -131,7 +168,11 @@
- 	struct usX2Ydev	*us428 = hw->private_data;
- 	int id = -1;
- 
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
- 	switch (le16_to_cpu(us428->chip.dev->descriptor.idProduct)) {
-+#else
-+	switch (((struct usX2Ydev*)hw->private_data)->chip.dev->descriptor.idProduct) {
-+#endif
- 	case USB_ID_US122:
- 		id = USX2Y_TYPE_122;
- 		break;
-@@ -183,9 +224,15 @@
- 	};
- 	struct usb_device *dev = usX2Y(card)->chip.dev;
- 	struct usb_interface *iface = usb_ifnum_to_if(dev, 0);
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
- 	struct snd_usb_audio_quirk *quirk =
- 		le16_to_cpu(dev->descriptor.idProduct) == USB_ID_US428 ?
- 		&quirk_2 : &quirk_1;
-+#else
-+	struct snd_usb_audio_quirk *quirk =
-+		dev->descriptor.idProduct == USB_ID_US428 ?
-+		&quirk_2 : &quirk_1;
-+#endif
- 
- 	snd_printdd("usX2Y_create_usbmidi \n");
- 	return snd_usb_create_midi_interface(&usX2Y(card)->chip, iface, quirk);
-@@ -231,7 +278,11 @@
- 		if (err)
- 			snd_printk(KERN_ERR "usb_set_interface error \n");
- 		else
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 12)
- 			err = usb_bulk_msg(dev, usb_sndbulkpipe(dev, 2), buf, dsp->length, &lret, 6000);
-+#else
-+			err = usb_bulk_msg(dev, usb_sndbulkpipe(dev, 2), buf, dsp->length, &lret, 6 * HZ);
-+#endif
- 		kfree(buf);
- 	}
- 	if (err)

Index: alsa-driver/usb/usx2y/usbusx2y.patch
===================================================================
RCS file: /cvsroot/alsa/alsa-driver/usb/usx2y/usbusx2y.patch,v retrieving revision 1.6

usb/usx2y/usbusx2y.patch +28 -32

129 lines not on this page · raw message

Index: alsa-kernel/usb/usx2y/usX2Yhwdep.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/usb/usx2y/usX2Yhwdep.c,v retrieving revision 1.10

usb/usx2y/usX2Yhwdep.c +1 -150

175 lines not on this page · raw message

Index: alsa-kernel/usb/usx2y/usbusx2y.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/usb/usx2y/usbusx2y.c,v retrieving revision 1.16

usb/usx2y/usbusx2y.c +177 -10

227 lines not on this page · raw message

#1 lore raw

At Tue, 7 Mar 2006 16:56:23 +0100,

Quoted 7 lines · Karsten Wiese

Hi Takashi

This is one step to make hotplug work here on FC4 again. other things needed are updated firmwareloader, hotplug-scripts and us428control.

Quoted 8 lines

The new firmwareloader actually only needs to run once to unpack the firmware. The "make install" in alsa-firmware/usx2yloader puts the firmware into /lib/firmware then.

I got it here, but before submission:
Would you like to change and keep the alsa-tools/usx2yloader for that? Alternatively there could be a new "usx2y-fw-unpack" binary in alsa-firmware/usx2yloader and alsa-tools/usx2yloader would vanish.

It's a good question. Currently, request_firmware() isn't perfect since it doesn't work when the driver is built-in. Also, old kernels don't support firmware interface, too. So, it's not so bad to keep the old hwdep loader. If the size metters, we can ifdef them.

Quoted 6 lines
usb/usx2y/usbusx2y.c +6 -0
+static int usX2Y_create_alsa_devices(struct snd_card *card)
+{
+	int err;
+
+	do {
+		if ((err = usX2Y_create_usbmidi(card)) < 0) {

usb/usx2y/usbusx2y.c line 431

Quoted 10 lines
usb/usx2y/usbusx2y.c +10 -0
+			snd_printk(KERN_ERR "usX2Y_create_alsa_devices: usX2Y_create_usbmidi error %i \n", err);
+			break;
+		}
+		if ((err = usX2Y_audio_create(card)) < 0) 
+			break;
+		if ((err = usX2Y_hwdep_pcm_new(card)) < 0)
+			break;
+		if ((err = snd_card_register(card)) < 0)
+			break;
+	} while (0);

This do-while should be removed. It's used for macros but not suitable for plain codes. Replace break with a simple "return err".

usb/usx2y/usbusx2y.c line 473

Quoted 7 lines
usb/usx2y/usbusx2y.c +7 -0
+static int usX2Y_fw_load(struct usb_device* device, struct usb_interface *intf, int type_id, const char *fmt)
+{
+	char buf[32];
+        const struct firmware *fw;
+	int lret, err;
+
+	sprintf(buf, fmt, usX2Y_type_ids[type_id]);

Any reason to use a temporary buffer for the same string?

usb/usx2y/usbusx2y.c line 481

Quoted 8 lines
usb/usx2y/usbusx2y.c +8 -0
+
+        if ((err = request_firmware(&fw, buf, &intf->dev))) {
+		printk(KERN_ERR
+		       "%s: Firmware %s not available\n", __FUNCTION__, buf);
+		return err;
+	}
+	{
+		char *buf = kmalloc(fw->size, GFP_KERNEL);

Avoid unnecessary block, and don't use the same variable name...

Thanks,

Takashi

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642