Skip to contentSkip to conversation

alsa-driver: Support for ESI Miditerminal 4140 (#3)

PATCH In review Matthias Koenig 2 participants 6 messages May 2, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 alsa-driver: Support for ESI Miditerminal 4140 (#3)

Add support for the ESI Miditerminal 4140 to alsa-driver.

---

The third iteration includes the suggested fixes by Takashi:
http://article.gmane.org/gmane.linux.alsa.devel/35147

The spinlock calls have been reworked in open/close callbacks:
In the open callback, we don't need to protect the HW access, because this HW open is only necessary on _first_ open. There aren't any IRQs from the device, _before_ the device is opened (= is in communication mode). So it should be safe to omit the spinlock here.
Of course, this doesn't count for the close callback, because in this case there can be some IRQ while we are in the HW close procedure.

I removed all local_irq_disable etc. calls in device startup/probe, since there are no races and all HW access should be safe.

Some locking has been added to the get/put callbacks
of the control elements as "Writing an ALSA driver" states that these are non atomic. In most cases a spin_lock should be adequate because the accessed members of the protected structure are not accessed in the IRQ handler.

Thanks!

PS: I added Jaroslav and Lee to CC.

drivers/Kconfig +13 -0
diff -r 4e7af6120ca7 drivers/Kconfig
@@ -43,3 +43,16 @@ config SND_PCSP
 	  You can compile this as a module, which will be called snd-pcsp.
 
 	  You don't need this driver if you only want your computer to beep.
+
+config SND_MTS64
+	tristate "ESI Miditerminal 4140 driver"
+	depends on SND && PARPORT
+	select SND_RAWMIDI
+	help
+	  The ESI Miditerminal 4140 is a 4 In 4 Out MIDI Interface with 
+          additional SMPTE Timecode capabilities for the parallel port.
+
+	  Say 'Y' to include support for this device.
+
+	  To compile this driver as a module, chose 'M' here: the module 
+          will be called snd-mts64.
drivers/Makefile +2 -1
diff -r 4e7af6120ca7 drivers/Makefile
@@ -10,12 +10,13 @@ snd-serialmidi-objs := serialmidi.o
 snd-serialmidi-objs := serialmidi.o
 snd-aloop-objs := aloop.o
 snd-portman2x4-objs := portman2x4.o
+snd-mts64-objs := mts64.o
 
 obj-$(CONFIG_SND) += pcsp/
 
 obj-$(CONFIG_SND_SERIALMIDI) += snd-serialmidi.o
 obj-$(CONFIG_SND_LOOPBACK) += snd-aloop.o
-obj-$(CONFIG_SND_PORTMAN2X4) += snd-portman2x4.o
+obj-$(CONFIG_SND_MTS64) += snd-mts64.o
 
 include $(SND_TOPDIR)/alsa-kernel/drivers/Makefile
 
drivers/mts64.c new file +1090 -0

1,090 lines not on this page · raw message

#1 lore raw

At Tue, 02 May 2006 12:54:44 +0200,

Quoted 6 lines · Matthias Koenig

Some locking has been added to the get/put callbacks
of the control elements as "Writing an ALSA driver" states that these are non atomic. In most cases a spin_lock should be adequate because the accessed members of the protected structure are not accessed in the IRQ handler.

The problem is not the member field to be accessed but just a spinlock. mts->lock is still held in snd_mts64_interrupt(), so a spin_lock() would cause a deadlock. You should use spin_lock_irq() in get/put callbacks.

Otherwise, only a couple of minor glitches as below:

drivers/Makefile snd-serialmidi-objs := serialmidi.o · line 18

Quoted 13 lines
drivers/Makefile +1 -1
@@ -10,12 +10,13 @@ snd-serialmidi-objs := serialmidi.o
 snd-serialmidi-objs := serialmidi.o
 snd-aloop-objs := aloop.o
 snd-portman2x4-objs := portman2x4.o
+snd-mts64-objs := mts64.o
 
 obj-$(CONFIG_SND) += pcsp/
 
 obj-$(CONFIG_SND_SERIALMIDI) += snd-serialmidi.o
 obj-$(CONFIG_SND_LOOPBACK) += snd-aloop.o
-obj-$(CONFIG_SND_PORTMAN2X4) += snd-portman2x4.o

I guess it's not intentional?

drivers/Makefile snd-serialmidi-objs := serialmidi.o

Quoted 6 lines
drivers/Makefile +6 -0
+obj-$(CONFIG_SND_MTS64) += snd-mts64.o
+static int __devinit snd_mts64_ctl_create(struct snd_card *card, 
+					  struct mts64 *mts) 
+{
+	int err, i;
+	struct snd_kcontrol_new *control[] = {

Make it static.

Quoted 1 line

+static int __devinit snd_mts64_probe(struct platform_device *pdev)

(snip)

drivers/Makefile

Quoted 11 lines
drivers/Makefile +11 -0
+	pardev = parport_register_device(p,                   /* port */
+					 DRIVER_NAME,         /* name */
+					 NULL,                /* preempt */
+					 NULL,                /* wakeup */
+					 snd_mts64_interrupt, /* ISR */
+					 PARPORT_DEV_EXCL,    /* flags */
+					 (void *)card);       /* private */
+	if (pardev == NULL) {
+		snd_printd("Cannot register pardevice\n");
+		err = -EIO;
+		goto __err;

This error path is problematic, unfortunately, because card->private_data isn't initialized yet. So, don't set card->private_free yet to avoid the access to mts and mts->pardev.

drivers/Makefile

Quoted 4 lines
drivers/Makefile +4 -0
+	}
+
+	if ((err = snd_mts64_create(card, pardev, &mts)) < 0) {
+		snd_printd("Cannot create main component\n");

Release pardev manually here (since private_free doesn't work)...

drivers/Makefile

Quoted 3 lines
drivers/Makefile +3 -0
+		goto __err;
+	}
+	card->private_data = mts;

... and set card->private_free here.

Thanks,

Takashi

-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

#2 lore raw
Quoted 4 lines · Takashi Iwai

The problem is not the member field to be accessed but just a spinlock. mts->lock is still held in snd_mts64_interrupt(), so a spin_lock() would cause a deadlock. You should use spin_lock_irq() in get/put callbacks.

Uh uh, thanks for pointing this out.

Quoted 11 lines

Otherwise, only a couple of minor glitches as below:

Quoted 8 lines
drivers/Makefile +1 -0
@@ -10,12 +10,13 @@ snd-serialmidi-objs := serialmidi.o
 snd-serialmidi-objs := serialmidi.o
 snd-aloop-objs := aloop.o
 snd-portman2x4-objs := portman2x4.o
+snd-mts64-objs := mts64.o
 
Quoted 7 lines

drivers/Makefile snd-serialmidi-objs := serialmidi.o · line 18

Quoted 5 lines
drivers/Makefile +0 -1
 obj-$(CONFIG_SND) += pcsp/
 
 obj-$(CONFIG_SND_SERIALMIDI) += snd-serialmidi.o
 obj-$(CONFIG_SND_LOOPBACK) += snd-aloop.o
-obj-$(CONFIG_SND_PORTMAN2X4) += snd-portman2x4.o

I guess it's not intentional?

Oops, this shouldn't have happened.

Quoted 8 lines

drivers/Makefile snd-serialmidi-objs := serialmidi.o

Quoted 6 lines
drivers/Makefile +6 -0
+obj-$(CONFIG_SND_MTS64) += snd-mts64.o
+static int __devinit snd_mts64_ctl_create(struct snd_card *card, 
+					  struct mts64 *mts) 
+{
+	int err, i;
+	struct snd_kcontrol_new *control[] = {

Make it static.

Ok

Quoted 26 lines
Quoted 1 line

+static int __devinit snd_mts64_probe(struct platform_device *pdev)

(snip)

drivers/Makefile

Quoted 11 lines
drivers/Makefile +11 -0
+	pardev = parport_register_device(p,                   /* port */
+					 DRIVER_NAME,         /* name */
+					 NULL,                /* preempt */
+					 NULL,                /* wakeup */
+					 snd_mts64_interrupt, /* ISR */
+					 PARPORT_DEV_EXCL,    /* flags */
+					 (void *)card);       /* private */
+	if (pardev == NULL) {
+		snd_printd("Cannot register pardevice\n");
+		err = -EIO;
+		goto __err;

This error path is problematic, unfortunately, because card->private_data isn't initialized yet. So, don't set card->private_free yet to avoid the access to mts and mts->pardev.

drivers/Makefile

Quoted 4 lines
drivers/Makefile +4 -0
+	}
+
+	if ((err = snd_mts64_create(card, pardev, &mts)) < 0) {
+		snd_printd("Cannot create main component\n");

Release pardev manually here (since private_free doesn't work)...

Quoted 5 lines

drivers/Makefile

Quoted 3 lines
drivers/Makefile +3 -0
+		goto __err;
+	}
+	card->private_data = mts;

... and set card->private_free here.

Ok.

I appended the new patch to this mail, I hope this is Ok.

Thanks,
Matthias

PS: I removed Lee from CC, since he seems to be still on travel and his mailbox is bouncing due to overflow.

drivers/Kconfig +13 -0
diff -r 4e7af6120ca7 drivers/Kconfig
@@ -43,3 +43,16 @@ config SND_PCSP
 	  You can compile this as a module, which will be called snd-pcsp.
 
 	  You don't need this driver if you only want your computer to beep.
+
+config SND_MTS64
+	tristate "ESI Miditerminal 4140 driver"
+	depends on SND && PARPORT
+	select SND_RAWMIDI
+	help
+	  The ESI Miditerminal 4140 is a 4 In 4 Out MIDI Interface with 
+          additional SMPTE Timecode capabilities for the parallel port.
+
+	  Say 'Y' to include support for this device.
+
+	  To compile this driver as a module, chose 'M' here: the module 
+          will be called snd-mts64.
drivers/Makefile +2 -0
diff -r 4e7af6120ca7 drivers/Makefile
@@ -10,12 +10,14 @@ snd-serialmidi-objs := serialmidi.o
 snd-serialmidi-objs := serialmidi.o
 snd-aloop-objs := aloop.o
 snd-portman2x4-objs := portman2x4.o
+snd-mts64-objs := mts64.o
 
 obj-$(CONFIG_SND) += pcsp/
 
 obj-$(CONFIG_SND_SERIALMIDI) += snd-serialmidi.o
 obj-$(CONFIG_SND_LOOPBACK) += snd-aloop.o
 obj-$(CONFIG_SND_PORTMAN2X4) += snd-portman2x4.o
+obj-$(CONFIG_SND_MTS64) += snd-mts64.o
 
 include $(SND_TOPDIR)/alsa-kernel/drivers/Makefile
 
drivers/mts64.c new file +1091 -0

1,091 lines not on this page · raw message

#3 lore raw

At Tue, 02 May 2006 15:24:44 +0200,

Quoted 2 lines · Matthias Koenig

I appended the new patch to this mail, I hope this is Ok.

Last but not least: spin_lock(mts->lock) ==> spin_lock(&mts->lock)

Don't worry, I'll fix them by myself before committing the patch :)

Thanks,

Takashi

-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

#4 lore raw
Quoted 2 lines · Takashi Iwai

Last but not least: spin_lock(mts->lock) ==> spin_lock(&mts->lock)

Oh, this is really wrong at all places from the beginning and strangely enough I didn't get any compilation error.

Quoted 1 line

Don't worry, I'll fix them by myself before committing the patch :)

Takashi, thank you very much for review and help!

Matthias

-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

#5 lore raw

At Tue, 02 May 2006 16:25:00 +0200,

Quoted 7 lines · Matthias Koenig
Quoted 2 lines · Takashi Iwai

Last but not least: spin_lock(mts->lock) ==> spin_lock(&mts->lock)

Oh, this is really wrong at all places from the beginning and strangely enough I didn't get any compilation error.

You compiled with a UP kernel where spinlock is nothing but a place holder.

Takashi

-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642