Support for ESI Miditerminal 4140
PATCH 1/1 Support for ESI Miditerminal 4140
Hello,
Here is the patch to add support for the ESI Miditerminal 4140. Patch is against latest alsa-driver hg.
drivers/Kconfig +7 -0
@@ -43,3 +43,10 @@ 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 + Say 'Y' or 'M' to include support for Miditerminal 4140.
drivers/Makefile +2 -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 +obj-$(CONFIG_SND_MTS64) += snd-mts64.o include $(SND_TOPDIR)/alsa-kernel/drivers/Makefile
drivers/mts64.c new file +1157 -0
1,157 lines not on this page · raw message
At Mon, 24 Apr 2006 19:23:22 +0200,
Quoted 5 lines · Matthias Koenig
diff -r
4e7af6120ca7drivers/Kconfig
drivers/Kconfig config SND_PCSP · line 52
Quoted 10 lines
drivers/Kconfig +7
-0@@ -43,3 +43,10 @@ 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 + Say 'Y' or 'M' to include support for Miditerminal 4140.
A bit more explanative, please.
Quoted 3 lines
diff -r
4e7af6120ca7drivers/mts64.cdrivers/mts64.c new file +0
-0
...
drivers/mts64.c line 37
Quoted 2 lines
drivers/mts64.c new file +2
-0+static int index[SNDRV_CARDS ] =SNDRV_DEFAULT_IDX ; +static char * id[SNDRV_CARDS ] =SNDRV_DEFAULT_STR ;
Please use a normal C-style, char *id[].
drivers/mts64.c line 73
Quoted 12 lines
drivers/mts64.c new file +12
-0+struct mts64 { +spinlock_t lock; +struct snd_card * card; +snd_rawmidi_t * rmidi; +struct pardevice * pardev; +int pardev_claimed; + +int open_count; +int current_midi_output_port; +int current_midi_input_port; +unsigned char mode[MTS64_NUM_INPUT_PORTS ]; +snd_rawmidi_substream_t * midi_input_substream[MTS64_NUM_INPUT_PORTS ];
We removed xxx_t typedefs. Use struct instead.
Quoted 21 lines
drivers/mts64.c new file +21
-0+static int __devinit snd_mts64_create (struct snd_card * card, +struct pardevice * pardev, +struct mts64 ** rchip) +{ +struct mts64 * mts; +int i; + + *rchip =NULL ; + + mts =kzalloc (sizeof (struct mts64 ),GFP_KERNEL ); +if (mts ==NULL ) +return -ENOMEM ; + +/* Init chip specific data */ +spin_lock_init (&mts->lock); + mts->card = card; + mts->rmidi =NULL ;/* initialized later in mts64_attach */ + mts->pardev = pardev; + mts->pardev_claimed =0 ; + mts->open_count =0 ; + mts->current_midi_output_port =-1 ;
drivers/mts64.c line 115
Quoted 10 lines
drivers/mts64.c new file +10
-0+ mts->current_midi_input_port =-1 ; +for (i=0 ; i<MTS64_NUM_INPUT_PORTS ; ++i) + mts->mode[i] =0 ; +/* SMPTE */ + mts->smpte_switch =0 ; + mts->time[0 ] =0 ; + mts->time[1 ] =0 ; + mts->time[2 ] =0 ; + mts->time[3 ] =0 ; + mts->fps =0 ;
You can omit zero-initializations above.
drivers/mts64.c line 213
Quoted 12 lines
drivers/mts64.c new file +12
-0+/* waits for device ready +* +* Checks if BUSY (Bit 7 of status) is clear +* 1 device ready +* 0 failure +*/ +static int mts64_device_ready (struct parport * p) +{ +int i; +unsigned char c; + +for (i=0 ; i <0xffff ; ++i) {
Space after 'for' and spaces between '=' are preferred. Keep the coding style found in linux/Documentation/CodingStyle.
drivers/mts64.c line 216
Quoted 3 lines
drivers/mts64.c new file +3
-0+ c =parport_read_status (p); + c &=MTS64_STAT_BSY ; +if (c !=0 )return 1 ;
Break a line (and add a space after 'if').
Quoted 4 lines
drivers/mts64.c new file +4
-0+/* Init device (LED blinking startup magic) +* +* Returns: +* 1 init ok
drivers/mts64.c line 235
Quoted 10 lines
drivers/mts64.c new file +10
-0+* 0 failure +*/ +static int mts64_device_init (struct parport * p) +{ +int i; + +mts64_write_command (p,MTS64_CMD_RESET ); + +for (i=0 ; i <64 ; ++i) { +mdelay (100 );
Such a long delay in local_irq_disable()?
Quoted 8 lines
drivers/mts64.c new file +8
-0+/* +* Opens the device (set communication mode) and increases the +* reference count. +*/ +static int mts64_device_open (struct mts64 * mts) +{ +int i; +struct parport * p = mts->pardev->port;
drivers/mts64.c line 265
Quoted 10 lines
drivers/mts64.c new file +10
-0+ +if (mts->open_count ==0 ) { +for (i=0 ; i<5 ; ++i) +mts64_write_command (p,MTS64_CMD_COM_OPEN ); + } + + ++(mts->open_count); + +/* FIXME: Busy wait really necessary? */ +mdelay (50 );
Ditto. A too long delay in irq_disable context.
Quoted 11 lines
drivers/mts64.c new file +11
-0+ +return 0 ; +} + +/* +* Close device and decrement reference count. +*/ +static int mts64_device_close (struct mts64 * mts) +{ +int i; +struct parport * p = mts->pardev->port;
drivers/mts64.c line 286
Quoted 10 lines
drivers/mts64.c new file +10
-0+ + --(mts->open_count); +if (mts->open_count ==0 ) { +for (i=0 ; i<5 ; ++i) { +mts64_write_command (p,MTS64_CMD_COM_CLOSE1 ); +mts64_write_command (p,MTS64_CMD_COM_CLOSE2 ); + } + }else if (mts->open_count <0 ) { + mts->open_count =0 ; + }
Should omit braces for a single line after 'if'.
drivers/mts64.c line 289
Quoted 3 lines
drivers/mts64.c new file +3
-0+ +/* FIXME: Busy wait really necessary? */ +mdelay (500 );
A too long delay in irq_disable.
Quoted 8 lines
drivers/mts64.c new file +8
-0+ +return 0 ; +} + +/* map hardware port to substream number +* +* When reading a byte from the device, the device tells us +* on what port the byte is. This HW port has to be mapped to
drivers/mts64.c line 307
Quoted 10 lines
drivers/mts64.c new file +10
-0+* the midiport (substream number). +* substream 0-3 are Midiports 1-4 +* substream 4 is SMPTE Timecode +* The mapping is done by the table: +* HW | 0 | 1 | 2 | 3 | 4 +* SW | 0 | 1 | 4 | 2 | 3 +*/ +static unsigned char mts64_map_midi_input (unsigned char c) +{ +unsigned char map[] = {0 ,1 ,4 ,2 ,3 };
Should be static char array.
Quoted 12 lines
drivers/mts64.c new file +12
-0+ +return map[c]; +} + + +/* Probe parport for device +* +* Do we have a Miditerminal 4140 on parport? +* Returns: +* 1 device found +* 0 no device +*/
drivers/mts64.c line 329
Quoted 10 lines
drivers/mts64.c new file +10
-0+static int mts64_probe (struct parport * p) +{ +unsigned char c; + +mts64_smpte_stop (p); + +mts64_write_command (p,MTS64_CMD_PROBE ); + +/* FIXME */ +mdelay (50 );
Possible to replace with msleep()?
drivers/mts64.c line 335
Quoted 6 lines
drivers/mts64.c new file +6
-0+ + c =mts64_read (p); + + c &=0x00ff ; +if (c !=MTS64_CMD_PROBE )return 0 ; +else return 1 ;
Break lines.
drivers/mts64.c line 405
Quoted 10 lines
drivers/mts64.c new file +10
-0+static void mts64_smpte_start (struct parport * p, +unsigned char hours,unsigned char minutes, +unsigned char seconds,unsigned char frames, +unsigned char idx) +{ +unsigned char fps[5 ] = {MTS64_CMD_SMPTE_FPS_24 , +MTS64_CMD_SMPTE_FPS_25 , +MTS64_CMD_SMPTE_FPS_2997 , +MTS64_CMD_SMPTE_FPS_30D , +MTS64_CMD_SMPTE_FPS_30 };
Use a static array.
Quoted 5 lines
drivers/mts64.c new file +5
-0+/* Write a MIDI byte to midiport +* +* midiport ranges from 0-3 and maps to Ports 1-4 +* assumptions: communication mode is on +*
drivers/mts64.c line 464
Quoted 10 lines
drivers/mts64.c new file +10
-0+*/ +static void mts64_write_midi (struct mts64 * mts,unsigned char c, +int midiport) +{ +struct parport * p = mts->pardev->port; + +/* check current midiport */ +if (mts->current_midi_output_port != midiport) { +mts64_write_command (p, midiport); + }
Remove braces around a single if line.
drivers/mts64.c line 476
Quoted 12 lines
drivers/mts64.c new file +12
-0+ +/* write midi byte */ +mts64_write_data (p, c); +} + +/********************************************************************* +* Control elements +*********************************************************************/ + +/* SMPTE Switch */ +static int snd_mts64_ctl_smpte_switch_info (snd_kcontrol_t *kctl, +snd_ctl_elem_info_t * uinfo)
Use struct snd_kcontrol and struct snd_ctl_elem_info. (For checking the obsolete typedefs, comment out the inclusion of "typedefs.h" in adriver.h.)
drivers/mts64.c line 522
Quoted 2 lines
drivers/mts64.c new file +2
-0+ +static snd_kcontrol_new_t mts64_ctl_smpte_switch__devinitdata = {
Use struct snd_kcontrol_new.
Quoted 8 lines
drivers/mts64.c new file +8
-0+ .iface = SNDRV_CTL_ELEM_IFACE_RAWMIDI, + .name = "SMPTE Playback Switch", + .index = 0, + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, + .private_value = 0, + .info = snd_mts64_ctl_smpte_switch_info, + .get = snd_mts64_ctl_smpte_switch_get, + .put = snd_mts64_ctl_smpte_switch_put
drivers/mts64.c
Quoted 10 lines
drivers/mts64.c new file +10
-0+}; +/* FPS */ +static int snd_mts64_ctl_smpte_fps_info (snd_kcontrol_t * kctl, +snd_ctl_elem_info_t * uinfo) +{ +char * texts[5 ] = {"24" , +"25" , +"29.97" , +"30D" , +"30" };
Use a static array.
drivers/mts64.c line 901
Quoted 9 lines
drivers/mts64.c new file +9
-0+static void mts64_interrupt (int irq,void * private,struct pt_regs * r) +{ +struct mts64 * mts = ((struct snd_card *)private)->private_data; +unsigned long flags; +unsigned short ret; +unsigned char status, data; +snd_rawmidi_substream_t * substream; + +spin_lock_irqsave (mts->lock, flags);
You need to irqsave/restore in the interrupt handler.
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
Hi Takashi,
Thank you for review!
Quoted 2 lines · Takashi Iwai
At Mon, 24 Apr 2006 19:23:22 +0200,
Matthias Koenig wrote:
[...]
Quoted 8 lines
drivers/Kconfig config SND_PCSP · line 52
Quoted 6 lines
drivers/Kconfig +6
-0+config SND_MTS64 + tristate "ESI Miditerminal 4140 driver" + depends on SND && PARPORT + select SND_RAWMIDI + help + Say 'Y' or 'M' to include support for Miditerminal 4140.A bit more explanative, please.
Ok
Quoted 3 lines
Quoted 1 line
+static char* id[SNDRV_CARDS] =
SNDRV_DEFAULT_STR;Please use a normal C-style, char *id[].
Ok
Quoted 3 lines
drivers/mts64.c line 73
Quoted 1 line
drivers/mts64.c new file +1
-0+snd_rawmidi_substream_t * midi_input_substream[MTS64_NUM_INPUT_PORTS ];We removed
xxx_ttypedefs. Use struct instead.
Ok. Sorry, this has been already on my plan, I don't know why forgot about it.
[...]
Quoted 8 lines
drivers/mts64.c line 115
Quoted 6 lines
drivers/mts64.c new file +6
-0+ mts->smpte_switch =0 ; + mts->time[0 ] =0 ; + mts->time[1 ] =0 ; + mts->time[2 ] =0 ; + mts->time[3 ] =0 ; + mts->fps =0 ;You can omit zero-initializations above.
Ok
[...]
Quoted 2 lines
Space after 'for' and spaces between '=' are preferred. Keep the coding style found in linux/Documentation/CodingStyle.
Ok
Quoted 11 lines
drivers/mts64.c line 235
Quoted 8 lines
drivers/mts64.c new file +8
-0+static int mts64_device_init (struct parport * p) +{ +int i; + +mts64_write_command (p,MTS64_CMD_RESET ); + +for (i=0 ; i <64 ; ++i) { +mdelay (100 );Such a long delay in
local_irq_disable()?
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* FIXME: Busy wait really necessary? */ + mdelay(50);Ditto. A too long delay in
irq_disablecontext.
Yes, these long delays have caused me some bellyache.
I got the information about the device from reverse engineering the Windows driver and the delay times are exactly taken from there (actually there is a function which repeatedly calls KeStallExecutionProcessor with an argument of 50us until the given time is elapsed).
I will try to find a better solution. Maybe some additional state variable which will be triggered by a timer. Also most of the delays are happening in process context, so it might be possible to sleep. At least it will be possible for the open/close callbacks.
I'll rework those sections.
[...]
Quoted 5 lines
drivers/mts64.c line 286
Quoted 3 lines
drivers/mts64.c new file +3
-0+ }else if (mts->open_count <0 ) { + mts->open_count =0 ; + }Should omit braces for a single line after 'if'.
Ok
Quoted 5 lines
drivers/mts64.c line 289
Quoted 3 lines
drivers/mts64.c new file +3
-0+ +/* FIXME: Busy wait really necessary? */ +mdelay (500 );A too long delay in
irq_disable.
s.a.
[...]
Quoted 5 lines
drivers/mts64.c line 307
Quoted 3 lines
drivers/mts64.c new file +3
-0+static unsigned char mts64_map_midi_input (unsigned char c) +{ +unsigned char map[] = {0 ,1 ,4 ,2 ,3 };Should be static char array.
Ok
[...]
Quoted 4 lines
Quoted 4 lines
drivers/mts64.c new file +4
-0+static int mts64_probe (struct parport * p) +{ +unsigned char c; +
Quoted 8 lines
drivers/mts64.c line 329
Quoted 6 lines
drivers/mts64.c new file +6
-0+mts64_smpte_stop (p); + +mts64_write_command (p,MTS64_CMD_PROBE ); + +/* FIXME */ +mdelay (50 );Possible to replace with
msleep()?
This might be an option.
[...]
Quoted 4 lines
drivers/mts64.c line 335
Quoted 2 lines
drivers/mts64.c new file +2
-0+if (c !=MTS64_CMD_PROBE )return 0 ; +else return 1 ;Break lines.
Ok
Quoted 4 lines
Quoted 4 lines
drivers/mts64.c new file +4
-0+static void mts64_smpte_start (struct parport * p, +unsigned char hours,unsigned char minutes, +unsigned char seconds,unsigned char frames, +unsigned char idx)
Quoted 8 lines
drivers/mts64.c line 405
Quoted 6 lines
drivers/mts64.c new file +6
-0+{ +unsigned char fps[5 ] = {MTS64_CMD_SMPTE_FPS_24 , +MTS64_CMD_SMPTE_FPS_25 , +MTS64_CMD_SMPTE_FPS_2997 , +MTS64_CMD_SMPTE_FPS_30D , +MTS64_CMD_SMPTE_FPS_30 };Use a static array.
Ok
[...]
Quoted 6 lines
drivers/mts64.c line 464
Quoted 4 lines
drivers/mts64.c new file +4
-0+/* check current midiport */ +if (mts->current_midi_output_port != midiport) { +mts64_write_command (p, midiport); + }Remove braces around a single if line.
OK
[...]
Quoted 7 lines
drivers/mts64.c line 476
Quoted 3 lines
drivers/mts64.c new file +3
-0+/* SMPTE Switch */ +static int snd_mts64_ctl_smpte_switch_info (snd_kcontrol_t *kctl, +snd_ctl_elem_info_t * uinfo)Use struct
snd_kcontroland structsnd_ctl_elem_info. (For checking the obsolete typedefs, comment out the inclusion of "typedefs.h" inadriver.h.)
Ok, removed all typedefs
Quoted 5 lines
drivers/mts64.c line 522
Quoted 3 lines
drivers/mts64.c new file +2
-0+ +static snd_kcontrol_new_t mts64_ctl_smpte_switch__devinitdata = {Use struct
snd_kcontrol_new.
Ok
Quoted 13 lines
Quoted 13 lines
drivers/mts64.c new file +12
-0+ .iface = SNDRV_CTL_ELEM_IFACE_RAWMIDI, + .name = "SMPTE Playback Switch", + .index = 0, + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, + .private_value = 0, + .info = snd_mts64_ctl_smpte_switch_info, + .get = snd_mts64_ctl_smpte_switch_get, + .put = snd_mts64_ctl_smpte_switch_put +}; +/* FPS */ +static int snd_mts64_ctl_smpte_fps_info (snd_kcontrol_t * kctl, +snd_ctl_elem_info_t * uinfo)
Quoted 8 lines
drivers/mts64.c line 641
Quoted 6 lines
drivers/mts64.c new file +6
-0+{ +char * texts[5 ] = {"24" , +"25" , +"29.97" , +"30D" , +"30" };Use a static array.
OK
Quoted 12 lines
drivers/mts64.c line 901
Quoted 10 lines
drivers/mts64.c new file +9
-0+static void mts64_interrupt (int irq,void * private,struct pt_regs * r) +{ +struct mts64 * mts = ((struct snd_card *)private)->private_data; +unsigned long flags; +unsigned short ret; +unsigned char status, data; +snd_rawmidi_substream_t * substream; + +spin_lock_irqsave (mts->lock, flags);You need to irqsave/restore in the interrupt handler.
I'm not sure if I understand your point here.
This is what I already do. Do you mean "you _don't_ need to irqsave/restore ..."?
thanks,
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
At Tue, 25 Apr 2006 11:49:11 +0200,
Quoted 17 lines · Matthias Koenig
Quoted 12 lines
drivers/mts64.c line 235
Quoted 9 lines
drivers/mts64.c new file +8
-0+static int mts64_device_init (struct parport * p) +{ +int i; + +mts64_write_command (p,MTS64_CMD_RESET ); + +for (i=0 ; i <64 ; ++i) { +mdelay (100 );Such a long delay in
local_irq_disable()?Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* FIXME: Busy wait really necessary? */ + mdelay(50);Ditto. A too long delay in
irq_disablecontext.
Quoted 5 lines
Yes, these long delays have caused me some bellyache.
I got the information about the device from reverse engineering the Windows driver and the delay times are exactly taken from there (actually there is a function which repeatedly calls KeStallExecutionProcessor with an argument of 50us until the given time is elapsed).
Hm, but you call mdelay(50), not udelay(50).
I won't care about the latter case but mdelay(50) is definitely to be avoided.
Quoted 5 lines
I will try to find a better solution. Maybe some additional state variable which will be triggered by a timer. Also most of the delays are happening in process context, so it might be possible to sleep. At least it will be possible for the open/close callbacks.
I'll rework those sections.
If it's really mdelay(50), change spin_lock to mutex_lock and replace mdelay to msleep() -- at least, for open/close calls, where you can sleep safely.
Quoted 12 lines
Quoted 11 lines
drivers/mts64.c line 901
Quoted 9 lines
drivers/mts64.c new file +9
-0+static void mts64_interrupt (int irq,void * private,struct pt_regs * r) +{ +struct mts64 * mts = ((struct snd_card *)private)->private_data; +unsigned long flags; +unsigned short ret; +unsigned char status, data; +snd_rawmidi_substream_t * substream; + +spin_lock_irqsave (mts->lock, flags);You need to irqsave/restore in the interrupt handler.
Quoted 3 lines
I'm not sure if I understand your point here.
This is what I already do. Do you mean "you _don't_ need to irqsave/restore ..."?
Yep, exactly. Sorry for a typo :)
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
Quoted 11 lines · Takashi Iwai
At Tue, 25 Apr 2006 11:49:11 +0200,
Quoted 5 lines · Matthias Koenig
Yes, these long delays have caused me some bellyache.
I got the information about the device from reverse engineering the Windows driver and the delay times are exactly taken from there (actually there is a function which repeatedly calls KeStallExecutionProcessor with an argument of 50us until the given time is elapsed).Hm, but you call mdelay(50), not udelay(50).
I won't care about the latter case but mdelay(50) is definitely to be avoided.
Yes, it's 50ms of _total_ time to wait.
The Code does something like this (roughly translated to C):
void wait_some_time(long long interval) /* interval is in ms */
{
long long time = PcGetTimeInterval(0); /* Current time in 100ns ticks */
interval *= 10000; /* translate to 100ns ticks */
do {
KeStallExecutionProcessor(50); /* This is us */
} while (interval < PcGetTimeInterval(time));
}Quoted 3 lines
If it's really mdelay(50), change
spin_locktomutex_lockand replace mdelay tomsleep()-- at least, for open/close calls, where you can sleep safely.
I totally overlooked the following sentence in "Writing an ALSA Driver":
"The open and close callbacks of a rawmidi device are serialized with a mutex, and can sleep."
So, if I understand this correctly, there is already a mutex held by the ALSA core and it is guaranteed that there are no multiple accesses of open/close callbacks?
Hmm, then why should I hold an additional mutex?
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
You need to irqsave/restore in the interrupt handler.
I'm not sure if I understand your point here.
This is what I already do. Do you mean "you _don't_ need to irqsave/restore ..."?Yep, exactly. Sorry for a typo :)
Ok.
Thanks,
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
At Tue, 25 Apr 2006 14:17:03 +0200,
Quoted 30 lines · Matthias Koenig
Quoted 11 lines · Takashi Iwai
At Tue, 25 Apr 2006 11:49:11 +0200,
Quoted 5 lines · Matthias Koenig
Yes, these long delays have caused me some bellyache.
I got the information about the device from reverse engineering the Windows driver and the delay times are exactly taken from there (actually there is a function which repeatedly calls KeStallExecutionProcessor with an argument of 50us until the given time is elapsed).Hm, but you call mdelay(50), not udelay(50).
I won't care about the latter case but mdelay(50) is definitely to be avoided.Yes, it's 50ms of _total_ time to wait.
The Code does something like this (roughly translated to C):void
wait_some_time(long long interval)/* interval is in ms */{ long long time = PcGetTimeInterval(0); /* Current time in 100ns ticks */ interval *= 10000; /* translate to 100ns ticks */ do { KeStallExecutionProcessor(50); /* This is us */ } while (interval < PcGetTimeInterval(time)); }Quoted 3 lines
If it's really mdelay(50), change
spin_locktomutex_lockand replace mdelay tomsleep()-- at least, for open/close calls, where you can sleep safely.
Quoted 7 lines
I totally overlooked the following sentence in "Writing an ALSA Driver":
"The open and close callbacks of a rawmidi device are serialized with a mutex, and can sleep."So, if I understand this correctly, there is already a mutex held by the ALSA core and it is guaranteed that there are no multiple accesses of open/close callbacks?
The mutex belongs to the rawmidi device, so open/close is mutual as long as the same rawmidi device is used no matter which substream is used. It doesn't care open/close of another rawmidi device, though.
Quoted 1 line
Hmm, then why should I hold an additional mutex?
Well, I just thought of something as a replacement of mts->lock, but regarding open/close, yes, you can get rid of an extra mutex.
You might still need a spinlock somewhere, but definitely not together with mdelay().
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
Quoted 3 lines · Takashi Iwai
The mutex belongs to the rawmidi device, so open/close is mutual as long as the same rawmidi device is used no matter which substream is used. It doesn't care open/close of another rawmidi device, though.
Ah, thanks! This is the informationen I needed.
Quoted 7 lines
Quoted 1 line
Hmm, then why should I hold an additional mutex?
Well, I just thought of something as a replacement of
mts->lock, but regarding open/close, yes, you can get rid of an extra mutex.You might still need a spinlock somewhere, but definitely not together with
mdelay().
Yes, I decoupled now delay stuff from the spinlock sections and placed the spinlocks just near the HW access.
New patch for next turn will follow.
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