public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jarod Wilson <jwilson@redhat.com>
To: Jonathan Corbet <corbet@lwn.net>
Cc: linux-kernel@vger.kernel.org, Jarod Wilson <jarod@redhat.com>,
	Janne Grunau <j@jannau.net>,
	Christoph Bartelmus <lirc@bartelmus.de>
Subject: Re: [PATCH 02/18] lirc serial port receiver/transmitter device driver
Date: Wed, 10 Sep 2008 13:40:18 -0400	[thread overview]
Message-ID: <200809101340.19254.jwilson@redhat.com> (raw)
In-Reply-To: <20080909101422.329bd351@bike.lwn.net>

On Tuesday 09 September 2008 12:14:22 Jonathan Corbet wrote:
> > +#ifdef LIRC_SERIAL_IRDEO
> > +static int type = LIRC_IRDEO;
> > +#elif defined(LIRC_SERIAL_IRDEO_REMOTE)
> > +static int type = LIRC_IRDEO_REMOTE;
> > +#elif defined(LIRC_SERIAL_ANIMAX)
> > +static int type = LIRC_ANIMAX;
> > +#elif defined(LIRC_SERIAL_IGOR)
> > +static int type = LIRC_IGOR;
> > +#elif defined(LIRC_SERIAL_NSLU2)
> > +static int type = LIRC_NSLU2;
> > +#else
> > +static int type = LIRC_HOMEBREW;
> > +#endif
>
> So where do all these LIRC_SERIAL_* macros come from?  I can't really tell
> what this bunch of ifdeffery is doing or how one might influence it.

Bleah. I believe these get passed in when building lirc userspace and drivers 
together, when manually selected the specific type of serial receiver you have 
in lirc's menu-driven configuration tool thingy...

In other words, they do us absolutely no good here. We just build for the 
default type (LIRC_HOMEBREW), and users can override the type as necessary via 
the 'type' module parameter. I'll nuke that chunk.

> > +
> > +static struct lirc_serial hardware[] = {
> > +	/* home-brew receiver/transmitter */
> > +	{
> > +		UART_MSR_DCD,
> > +		UART_MSR_DDCD,
> > +		UART_MCR_RTS|UART_MCR_OUT2|UART_MCR_DTR,
> > +		UART_MCR_RTS|UART_MCR_OUT2,
> > +		send_pulse_homebrew,
> > +		send_space_homebrew,
> > +		(
> > +#ifdef LIRC_SERIAL_TRANSMITTER
> > +		 LIRC_CAN_SET_SEND_DUTY_CYCLE|
> > +		 LIRC_CAN_SET_SEND_CARRIER|
> > +		 LIRC_CAN_SEND_PULSE|
> > +#endif
> > +		 LIRC_CAN_REC_MODE2)
> > +	},
>
> It would be really nice to use the .field=value structure initialization
> conventions here.

Indeed. Done.

> > +#if defined(__i386__)
> > +/*
> > +  From:
> > +  Linux I/O port programming mini-HOWTO
> > +  Author: Riku Saikkonen <Riku.Saikkonen@hut.fi>
> > +  v, 28 December 1997
> > +
> > +  [...]
> > +  Actually, a port I/O instruction on most ports in the 0-0x3ff range
> > +  takes almost exactly 1 microsecond, so if you're, for example,using
> > +  the parallel port directly, just do additional inb()s from that port
> > +  to delay.
> > +  [...]
> > +*/
> > +/* transmitter latency 1.5625us 0x1.90 - this figure arrived at from
> > + * comment above plus trimming to match actual measured frequency.
> > + * This will be sensitive to cpu speed, though hopefully most of the
> > 1.5us + * is spent in the uart access.  Still - for reference test
> > machine was a + * 1.13GHz Athlon system - Steve
> > + */
> > +
> > +/* changed from 400 to 450 as this works better on slower machines;
> > +   faster machines will use the rdtsc code anyway */
> > +
> > +#define LIRC_SERIAL_TRANSMITTER_LATENCY 450
> > +
> > +#else
> > +
> > +/* does anybody have information on other platforms ? */
> > +/* 256 = 1<<8 */
> > +#define LIRC_SERIAL_TRANSMITTER_LATENCY 256
> > +
> > +#endif  /* __i386__ */
>
> This is a little scary.  Maybe hrtimers would be a better way of handling
> your timing issues?

Sounds plausible, will look into it. Of course, this partially hinges on the 
USE_RDTSC bits, more comments just a little ways down...

> > +static inline unsigned int sinp(int offset)
> > +{
> > +#if defined(LIRC_ALLOW_MMAPPED_IO)
> > +	if (iommap != 0) {
> > +		/* the register is memory-mapped */
> > +		offset <<= ioshift;
> > +		return readb(io + offset);
> > +	}
> > +#endif
> > +	return inb(io + offset);
> > +}
>
> This all looks like a reimplementation of ioport_map() and the associated
> ioread*() and iowrite*() functions...?

Probably. Will see about using those instead.

> > +#ifdef USE_RDTSC
> > +/* Version that uses Pentium rdtsc instruction to measure clocks */
> > +
> > +/* This version does sub-microsecond timing using rdtsc instruction,
> > + * and does away with the fudged LIRC_SERIAL_TRANSMITTER_LATENCY
> > + * Implicitly i586 architecture...  - Steve
> > + */
> > +
> > +static inline long send_pulse_homebrew_softcarrier(unsigned long length)
> > +{
> > +	int flag;
> > +	unsigned long target, start, now;
> > +
> > +	/* Get going quick as we can */
> > +	rdtscl(start); on();
> > +	/* Convert length from microseconds to clocks */
> > +	length *= conv_us_to_clocks;
> > +	/* And loop till time is up - flipping at right intervals */
> > +	now = start;
> > +	target = pulse_width;
> > +	flag = 1;
> > +	while ((now-start) < length) {
> > +		/* Delay till flip time */
> > +		do {
> > +			rdtscl(now);
> > +		} while ((now-start) < target);
>
> This looks like a hard busy wait, without even an occasional, polite,
> cpu_relax() call.  There's got to be a better way?
>
> The i2c code has the result of a lot of bit-banging work, I wonder if
> there's something there which could be helpful here.

Hrm... So at some point in the past, there was an "#if defined(rdtscl)" in the 
lirc_serial.c code that triggered USE_RDTSC being defined. At the moment, 
there's nothing defining it (I probably overzealously nuked it during clean-
up), so we're not even touching the above code. However, this is supposed to 
be the "better" code path wrt producing a reliable waveform, at least on 
platforms with rdtscl... Will have to do some investigating... This actually 
affects whether or not we bother with hrtimers as suggested above too, as 
LIRC_SERIAL_TRANSMITTER_LATENCY is not used at all in the USE_RDTSC case.

> > +static irqreturn_t irq_handler(int i, void *blah)
> > +{
> > +	struct timeval tv;
> > +	int status, counter, dcd;
> > +	long deltv;
> > +	int data;
> > +	static int last_dcd = -1;
> > +
> > +	if ((sinp(UART_IIR) & UART_IIR_NO_INT)) {
> > +		/* not our interrupt */
> > +		return IRQ_RETVAL(IRQ_NONE);
> > +	}
>
> That should just be IRQ_NONE, no?

Yeah, looks like it. Done.

> > +static void hardware_init_port(void)
> > +{
> > +	unsigned long flags;
> > +	local_irq_save(flags);
>
> That won't help you if an interrupt is handled by another processor.  This
> needs proper locking, methinks.

Yeah, working on implementing locking right now.

> Nothing in this function does anything to assure itself that the port
> actually exists and is the right kind of hardware.  Maybe that can't really
> be done with this kind of device?

We should probably try to make sure the port actually exists, but I don't 
think there's a whole lot (if anything) we can do as far as verifying the 
device itself.

> > +static int init_port(void)
> > +{
>
>  ...
>
> > +	if (sense == -1) {
> > +		/* wait 1/2 sec for the power supply */
> > +
> > +		set_current_state(TASK_INTERRUPTIBLE);
> > +		schedule_timeout(HZ/2);
>
> msleep(), maybe?

Yeah, looks like it.

> > +static int set_use_inc(void *data)
> > +{
> > +	int result;
> > +	unsigned long flags;
> > +
> > +	/* Init read buffer. */
> > +	if (lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN) < 0)
> > +		return -ENOMEM;
> > +
> > +	/* initialize timestamp */
> > +	do_gettimeofday(&lasttv);
> > +
> > +	result = request_irq(irq, irq_handler,
> > +			   IRQF_DISABLED | (share_irq ? IRQF_SHARED : 0),
> > +			   LIRC_DRIVER_NAME, (void *)&hardware);
> > +
> > +	switch (result) {
> > +	case -EBUSY:
> > +		printk(KERN_ERR LIRC_DRIVER_NAME ": IRQ %d busy\n", irq);
> > +		lirc_buffer_free(&rbuf);
> > +		return -EBUSY;
> > +	case -EINVAL:
> > +		printk(KERN_ERR LIRC_DRIVER_NAME
> > +		       ": Bad irq number or handler\n");
> > +		lirc_buffer_free(&rbuf);
> > +		return -EINVAL;
> > +	default:
> > +		dprintk("Interrupt %d, port %04x obtained\n", irq,
> > io);
> > +		break;
> > +	};
> > +
> > +	local_irq_save(flags);
> > +
> > +	/* Set DLAB 0. */
> > +	soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
> > +
> > +	soutp(UART_IER, sinp(UART_IER)|UART_IER_MSI);
> > +
> > +	local_irq_restore(flags);
> > +
> > +	return 0;
> > +}
>
> OK, so set_use_inc() really is just an open() function.  It still seems
> like a strange duplication.

Going to let the duplication be for the moment, since I don't know the history 
behind why there's duplication, and there are enough other mountains to climb 
first... :)

> Again, local_irq_save() seems insufficient here.  You need a lock to
> serialize access to the hardware.

Will do.

-- 
Jarod Wilson
jarod@redhat.com


  parent reply	other threads:[~2008-09-10 17:42 UTC|newest]

Thread overview: 111+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-09  4:05 [PATCH 0/18] linux infrared remote control drivers Jarod Wilson
2008-09-09  4:05 ` [PATCH 01/18] lirc core device driver infrastructure Jarod Wilson
2008-09-09  4:05   ` [PATCH 02/18] lirc serial port receiver/transmitter device driver Jarod Wilson
2008-09-09  4:05     ` [PATCH 03/18] lirc driver for 1st-gen Media Center Ed. USB IR transceivers Jarod Wilson
2008-09-09  4:05       ` [PATCH 04/18] lirc driver for 2nd-gen and later " Jarod Wilson
2008-09-09  4:05         ` [PATCH 05/18] lirc driver for i2c-based IR receivers Jarod Wilson
2008-09-09  4:05           ` [PATCH 06/18] lirc driver for the ATI USB RF remote receiver Jarod Wilson
2008-09-09  4:05             ` [PATCH 07/18] lirc driver for the CommandIR USB Transceiver Jarod Wilson
2008-09-09  4:05               ` [PATCH 08/18] lirc driver for the Soundgraph IMON IR Receivers Jarod Wilson
2008-09-09  4:05                 ` [PATCH 09/18] lirc driver for the Streamzap PC Receiver Jarod Wilson
2008-09-09  4:05                   ` [PATCH 10/18] lirc driver for Igor Cesko's USB IR receiver Jarod Wilson
2008-09-09  4:05                     ` [PATCH 11/18] lirc driver for the Technotrend " Jarod Wilson
2008-09-09  4:05                       ` [PATCH 12/18] lirc driver for the Sasem OnAir and Dign HV5 receivers Jarod Wilson
2008-09-09  4:05                         ` [PATCH 13/18] lirc driver for ITE8709 CIR port receiver Jarod Wilson
2008-09-09  4:05                           ` [PATCH 14/18] lirc driver for the ITE IT87xx CIR Port receivers Jarod Wilson
2008-09-09  4:06                             ` [PATCH 15/18] lirc driver for the SIR IrDA port Jarod Wilson
2008-09-09  4:06                               ` [PATCH 16/18] lirc driver for the IR interface on BT829-based hardware Jarod Wilson
2008-09-09  4:06                                 ` [PATCH 17/18] lirc driver for homebrew parallel port receivers Jarod Wilson
2008-09-09  4:06                                   ` [PATCH 18/18] lirc driver for the zilog/haupauge IR transceiver Jarod Wilson
2008-09-09  4:06                                     ` Jarod Wilson
2008-09-11 15:22                   ` [PATCH 09/18] lirc driver for the Streamzap PC Receiver Jonathan Corbet
2008-09-10 21:02                 ` [PATCH 08/18] lirc driver for the Soundgraph IMON IR Receivers Jonathan Corbet
2008-09-10 21:23                   ` Janne Grunau
2008-09-11  3:22                     ` Jarod Wilson
2008-09-22 21:47                   ` Jarod Wilson
2008-09-24 20:21                     ` Jarod Wilson
2008-09-10 17:09               ` [PATCH 07/18] lirc driver for the CommandIR USB Transceiver Jonathan Corbet
2008-09-11 18:24                 ` Christoph Bartelmus
     [not found]                   ` <1221159005.13683.34.camel@minimatt>
2008-09-11 19:03                     ` Jarod Wilson
2008-09-11 19:14                     ` Janne Grunau
2008-09-25 15:21                 ` Jarod Wilson
2008-09-10  9:58             ` [PATCH 06/18] lirc driver for the ATI USB RF remote receiver Ville Syrjälä
2008-09-10 13:05               ` Jarod Wilson
2008-09-10 13:14                 ` Christoph Hellwig
2008-09-10 13:37                   ` Jon Smirl
2008-09-10 14:30                     ` Dmitry Torokhov
2008-09-10 13:44                   ` Janne Grunau
2008-09-10 14:13                     ` Jarod Wilson
2008-09-10 14:19                     ` Christoph Hellwig
2008-09-10 14:08                 ` Ville Syrjälä
2008-09-10 14:37                   ` Dmitry Torokhov
2008-09-09  4:13           ` [PATCH 05/18] lirc driver for i2c-based IR receivers Jarod Wilson
2008-09-10 15:42           ` Jonathan Corbet
2008-09-09 23:30         ` [PATCH 04/18] lirc driver for 2nd-gen and later Media Center Ed. USB IR transceivers Jonathan Corbet
2008-09-10  0:36           ` Janne Grunau
2008-09-11  9:21           ` Adrian Bunk
2008-09-09 19:21       ` [PATCH 03/18] lirc driver for 1st-gen " Jonathan Corbet
2008-09-09 23:59         ` Janne Grunau
2008-09-10  1:39           ` Jarod Wilson
2008-09-10  0:04         ` Janne Grunau
2008-09-09 16:14     ` [PATCH 02/18] lirc serial port receiver/transmitter device driver Jonathan Corbet
2008-09-09 19:51       ` Stefan Lippers-Hollmann
2008-09-09 19:56         ` Jarod Wilson
2008-09-10 17:40       ` Jarod Wilson [this message]
2008-09-09  7:40   ` [PATCH 01/18] lirc core device driver infrastructure Sebastian Siewior
2008-09-09  9:53     ` Janne Grunau
2008-09-09 12:33       ` Sebastian Siewior
2008-09-09 13:10         ` Janne Grunau
2008-09-11 16:41       ` Christoph Bartelmus
2008-09-09 11:13     ` Alan Cox
2008-09-09 13:27     ` Stefan Richter
2008-09-09 17:03     ` Jarod Wilson
2008-09-11 18:30       ` Christoph Bartelmus
2008-09-11 19:09         ` Jarod Wilson
2008-09-13  7:21           ` Christoph Bartelmus
2008-09-09  9:46   ` Andi Kleen
2008-09-09 11:35     ` Janne Grunau
2008-09-09 13:03       ` Andi Kleen
2008-09-09 13:20         ` Janne Grunau
2008-09-12 16:46           ` Greg KH
2008-09-09 13:01   ` Christoph Hellwig
2008-09-10 12:24     ` Janne Grunau
2008-09-10 12:29       ` Christoph Hellwig
2008-09-10 12:45         ` Janne Grunau
2008-09-11 18:03       ` Christoph Bartelmus
2008-09-11 19:18         ` Janne Grunau
2008-09-12  0:16     ` Janne Grunau
2008-09-12  8:33       ` Christoph Hellwig
2008-09-12 14:51         ` Jarod Wilson
2008-09-09 15:33   ` Jonathan Corbet
2008-09-12  0:12     ` Janne Grunau
2008-09-10 13:08   ` Dmitry Torokhov
2008-09-11  8:47     ` Gerd Hoffmann
2008-09-11 21:28       ` Maxim Levitsky
2008-09-13  7:20         ` Christoph Bartelmus
2008-09-12  4:44       ` Dmitry Torokhov
2008-09-09  4:36 ` [PATCH 0/18] linux infrared remote control drivers Chris Wedgwood
2008-09-09  7:06 ` Alexey Dobriyan
2008-09-09  8:32   ` Janne Grunau
2008-09-09 12:46 ` Christoph Hellwig
2008-09-09 15:23   ` Jarod Wilson
2008-09-09 18:27     ` Lennart Sorensen
2008-09-09 18:34       ` Jarod Wilson
2008-09-09 15:34   ` Jon Smirl
  -- strict thread matches above, loose matches on Subject: below --
2008-09-11 19:49 [PATCH 02/18] lirc serial port receiver/transmitter device driver Stefan Bauer
2008-09-12 16:24 ` Jarod Wilson
2008-09-13  0:26   ` Janne Grunau
2008-09-13  8:41     ` Stefan Bauer
2008-09-15  3:55       ` Jarod Wilson
2008-09-15 18:20         ` Jarod Wilson
2008-09-16  4:08           ` Jarod Wilson
2008-09-18 14:00             ` Jarod Wilson
2008-09-19 18:05             ` Stefan Bauer
2008-09-19 18:26               ` Janne Grunau
2008-09-19 18:53                 ` Stefan Bauer
2008-09-19 19:24                   ` Janne Grunau
2008-09-20  0:10                   ` Janne Grunau
2008-09-26 19:42                     ` Stefan Bauer
2008-09-19 18:54                 ` Jarod Wilson
2008-09-19 19:12                   ` Stefan Bauer
2008-09-13  7:09   ` Christoph Bartelmus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200809101340.19254.jwilson@redhat.com \
    --to=jwilson@redhat.com \
    --cc=corbet@lwn.net \
    --cc=j@jannau.net \
    --cc=jarod@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lirc@bartelmus.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox