From: Takashi Iwai Subject: Re: [PATCH] Support for ESI Miditerminal 4140 Date: Mon, 24 Apr 2006 20:13:09 +0200 Message-ID: References: <87wtdeevlh.fsf@zebra.localdomain> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Return-path: In-Reply-To: <87wtdeevlh.fsf@zebra.localdomain> Sender: alsa-devel-admin@lists.sourceforge.net Errors-To: alsa-devel-admin@lists.sourceforge.net List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , List-Archive: To: Matthias Koenig Cc: alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org At Mon, 24 Apr 2006 19:23:22 +0200, Matthias Koenig wrote: > > diff -r 4e7af6120ca7 drivers/Kconfig > --- a/drivers/Kconfig Fri Apr 21 12:40:49 2006 +0200 > +++ b/drivers/Kconfig Mon Apr 24 19:17:13 2006 +0200 > @@ -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. > diff -r 4e7af6120ca7 drivers/mts64.c > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/drivers/mts64.c Mon Apr 24 19:17:13 2006 +0200 ... > +static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; > +static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; Please use a normal C-style, char *id[]. > +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. > +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; > + mts->current_midi_input_port = -1; > + for(i=0; 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. > +/* 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. > + c = parport_read_status(p); > + c &= MTS64_STAT_BSY; > + if(c != 0) return 1; Break a line (and add a space after 'if'). > +/* Init device (LED blinking startup magic) > + * > + * Returns: > + * 1 init ok > + * 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()? > +/* > + * 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; > + > + 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. > + > + return 0; > +} > + > +/* > + * Close device and decrement reference count. > + */ > +static int mts64_device_close(struct mts64* mts) > +{ > + int i; > + struct parport* p = mts->pardev->port; > + > + --(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'. > + > + /* FIXME: Busy wait really necessary? */ > + mdelay(500); A too long delay in irq_disable. > + > + 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 > + * 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. > + > + return map[c]; > +} > + > + > +/* Probe parport for device > + * > + * Do we have a Miditerminal 4140 on parport? > + * Returns: > + * 1 device found > + * 0 no device > + */ > +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()? > + > + c = mts64_read(p); > + > + c &= 0x00ff; > + if(c != MTS64_CMD_PROBE) return 0; > + else return 1; Break lines. > +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. > +/* Write a MIDI byte to midiport > + * > + * midiport ranges from 0-3 and maps to Ports 1-4 > + * assumptions: communication mode is on > + * > + */ > +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. > + > + /* 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.) > + > +static snd_kcontrol_new_t mts64_ctl_smpte_switch __devinitdata = { Use struct snd_kcontrol_new. > + .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) > +{ > + char* texts[5] = { "24", > + "25", > + "29.97", > + "30D", > + "30" }; Use a static array. > +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