Re: [PATCH 4/9] IR: add helper functions for ir input devices that send ir timing data in small chunks, and alternation between pulses and spaces isn't guaranteed.

2010-07-28 Thread Maxim Levitsky
On Wed, 2010-07-28 at 16:57 -0400, Jarod Wilson wrote: 
> On Wed, Jul 28, 2010 at 01:46:27PM -0400, Jarod Wilson wrote:
> > On Wed, Jul 28, 2010 at 06:14:06PM +0300, Maxim Levitsky wrote:
> > > Signed-off-by: Maxim Levitsky 
> > 
> > With the caveat of requiring an improved changelog, per Mauro's suggestion:
> > 
> > Acked-by: Jarod Wilson 
> > 
> > I suspect at least some of this code may be of use to the streamzap driver
> > as well (which I started looking at porting last night, despite my
> > insistence that I was going to work on lirc_zilog first...).
> 
> One other note: idle looks like it can happily exist as a bool instead of
> as an int, no?
> 

sure.

I have a problem with this code however, I just discovered.
I pretty much don't know how to solve it currently...

I just posted a mail about it.

Best regards,
Maxim Levitsky

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/9] IR: add helper functions for ir input devices that send ir timing data in small chunks, and alternation between pulses and spaces isn't guaranteed.

2010-07-28 Thread Jarod Wilson
On Wed, Jul 28, 2010 at 01:46:27PM -0400, Jarod Wilson wrote:
> On Wed, Jul 28, 2010 at 06:14:06PM +0300, Maxim Levitsky wrote:
> > Signed-off-by: Maxim Levitsky 
> 
> With the caveat of requiring an improved changelog, per Mauro's suggestion:
> 
> Acked-by: Jarod Wilson 
> 
> I suspect at least some of this code may be of use to the streamzap driver
> as well (which I started looking at porting last night, despite my
> insistence that I was going to work on lirc_zilog first...).

One other note: idle looks like it can happily exist as a bool instead of
as an int, no?

-- 
Jarod Wilson
ja...@redhat.com

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/9] IR: add helper functions for ir input devices that send ir timing data in small chunks, and alternation between pulses and spaces isn't guaranteed.

2010-07-28 Thread Jarod Wilson
On Wed, Jul 28, 2010 at 06:14:06PM +0300, Maxim Levitsky wrote:
> Signed-off-by: Maxim Levitsky 

With the caveat of requiring an improved changelog, per Mauro's suggestion:

Acked-by: Jarod Wilson 

I suspect at least some of this code may be of use to the streamzap driver
as well (which I started looking at porting last night, despite my
insistence that I was going to work on lirc_zilog first...).

-- 
Jarod Wilson
ja...@redhat.com

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/9] IR: add helper functions for ir input devices that send ir timing data in small chunks, and alternation between pulses and spaces isn't guaranteed.

2010-07-28 Thread Maxim Levitsky
On Wed, 2010-07-28 at 13:09 -0300, Mauro Carvalho Chehab wrote:
> Em 28-07-2010 12:14, Maxim Levitsky escreveu:
> 
> Please provide a smaller subject. Feel free to add a more detailed 
> description, but
> subjects longer then 74 bytes end by causing some troubles when using git 
> commands.
I didn't intend that, I just keep forgetting to add a newline between
subject and description..


> 
> It would be nice to have a good description on this patch, as it provides a 
> method
> for working around troubles found on problematic devices.
> 
> > Signed-off-by: Maxim Levitsky 
> > ---
> >  drivers/media/IR/ir-core-priv.h |1 +
> >  drivers/media/IR/ir-keytable.c  |2 +-
> >  drivers/media/IR/ir-raw-event.c |   86 
> > +++
> >  include/media/ir-core.h |   24 +-
> >  4 files changed, 109 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/media/IR/ir-core-priv.h 
> > b/drivers/media/IR/ir-core-priv.h
> > index 8ce80e4..3eafdb7 100644
> > --- a/drivers/media/IR/ir-core-priv.h
> > +++ b/drivers/media/IR/ir-core-priv.h
> > @@ -36,6 +36,7 @@ struct ir_raw_event_ctrl {
> > struct kfifokfifo;  /* fifo for the 
> > pulse/space durations */
> > ktime_t last_event; /* when last event 
> > occurred */
> > enum raw_event_type last_type;  /* last event type */
> > +   struct ir_raw_event current_sample; /* sample that is not 
> > yet pushed to fifo */
> > struct input_dev*input_dev; /* pointer to the 
> > parent input_dev */
> > u64 enabled_protocols; /* enabled raw 
> > protocol decoders */
> >  
> > diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
> > index 94a8577..34b9c07 100644
> > --- a/drivers/media/IR/ir-keytable.c
> > +++ b/drivers/media/IR/ir-keytable.c
> > @@ -428,7 +428,7 @@ static void ir_close(struct input_dev *input_dev)
> >   */
> >  int __ir_input_register(struct input_dev *input_dev,
> >   const struct ir_scancode_table *rc_tab,
> > - const struct ir_dev_props *props,
> > + struct ir_dev_props *props,
> >   const char *driver_name)
> >  {
> > struct ir_input_dev *ir_dev;
> 
> Hmm... why are you removing "const" from ir_dev_props? This change seems 
> unrelated
> with the patch description.
Because I add new field 'timeout' I intend to change it in runtime by
the driver.


Best regards,
Maxim Levitsky  


> 
> > diff --git a/drivers/media/IR/ir-raw-event.c 
> > b/drivers/media/IR/ir-raw-event.c
> > index c6a80b3..bdf2ed8 100644
> > --- a/drivers/media/IR/ir-raw-event.c
> > +++ b/drivers/media/IR/ir-raw-event.c
> > @@ -129,6 +129,92 @@ int ir_raw_event_store_edge(struct input_dev 
> > *input_dev, enum raw_event_type typ
> >  EXPORT_SYMBOL_GPL(ir_raw_event_store_edge);
> >  
> >  /**
> > + * ir_raw_event_store_with_filter() - pass next pulse/space to decoders 
> > with some processing
> > + * @input_dev: the struct input_dev device descriptor
> > + * @type:  the type of the event that has occurred
> > + *
> > + * This routine (which may be called from an interrupt context) is used to
> > + * store the beginning of an ir pulse or space (or the start/end of ir
> > + * reception) for the raw ir decoding state machines.\
> > + * This routine is intended for devices with limited internal buffer
> > + * It automerges samples of same type, and handles timeouts
> > + */
> > +int ir_raw_event_store_with_filter(struct input_dev *input_dev,
> > +   struct ir_raw_event *ev)
> > +{
> > +   struct ir_input_dev *ir = input_get_drvdata(input_dev);
> > +   struct ir_raw_event_ctrl *raw = ir->raw;
> > +
> > +   if (!ir->raw || !ir->props)
> > +   return -EINVAL;
> > +
> > +   /* Ignore spaces in idle mode */
> > +   if (ir->idle && !ev->pulse)
> > +   return 0;
> > +   else if (ir->idle)
> > +   ir_raw_event_set_idle(input_dev, 0);
> > +
> > +   if (!raw->current_sample.duration) {
> > +   raw->current_sample = *ev;
> > +   } else if (ev->pulse == raw->current_sample.pulse) {
> > +   raw->current_sample.duration += ev->duration;
> > +   } else {
> > +   ir_raw_event_store(input_dev, &raw->current_sample);
> > +   raw->current_sample = *ev;
> > +   }
> > +
> > +   /* Enter idle mode if nessesary */
> > +   if (!ev->pulse && ir->props->timeout &&
> > +   raw->current_sample.duration >= ir->props->timeout)
> > +   ir_raw_event_set_idle(input_dev, 1);
> > +   return 0;
> > +}
> > +EXPORT_SYMBOL_GPL(ir_raw_event_store_with_filter);
> > +
> > +
> > +void ir_raw_event_set_idle(struct input_dev *input_dev, int idle)
> > +{
> > +   struct ir_input_dev *ir = input_get_drvdata(input_dev);
> > +   struct ir_raw_event_ctrl *raw = ir->raw;
> > +   ktime_t now;
> > +   u64 delta;
> > +
> > +   if (!ir->props)
> 

Re: [PATCH 4/9] IR: add helper functions for ir input devices that send ir timing data in small chunks, and alternation between pulses and spaces isn't guaranteed.

2010-07-28 Thread Mauro Carvalho Chehab
Em 28-07-2010 12:14, Maxim Levitsky escreveu:

Please provide a smaller subject. Feel free to add a more detailed description, 
but
subjects longer then 74 bytes end by causing some troubles when using git 
commands.

It would be nice to have a good description on this patch, as it provides a 
method
for working around troubles found on problematic devices.

> Signed-off-by: Maxim Levitsky 
> ---
>  drivers/media/IR/ir-core-priv.h |1 +
>  drivers/media/IR/ir-keytable.c  |2 +-
>  drivers/media/IR/ir-raw-event.c |   86 
> +++
>  include/media/ir-core.h |   24 +-
>  4 files changed, 109 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
> index 8ce80e4..3eafdb7 100644
> --- a/drivers/media/IR/ir-core-priv.h
> +++ b/drivers/media/IR/ir-core-priv.h
> @@ -36,6 +36,7 @@ struct ir_raw_event_ctrl {
>   struct kfifokfifo;  /* fifo for the 
> pulse/space durations */
>   ktime_t last_event; /* when last event 
> occurred */
>   enum raw_event_type last_type;  /* last event type */
> + struct ir_raw_event current_sample; /* sample that is not 
> yet pushed to fifo */
>   struct input_dev*input_dev; /* pointer to the 
> parent input_dev */
>   u64 enabled_protocols; /* enabled raw 
> protocol decoders */
>  
> diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
> index 94a8577..34b9c07 100644
> --- a/drivers/media/IR/ir-keytable.c
> +++ b/drivers/media/IR/ir-keytable.c
> @@ -428,7 +428,7 @@ static void ir_close(struct input_dev *input_dev)
>   */
>  int __ir_input_register(struct input_dev *input_dev,
> const struct ir_scancode_table *rc_tab,
> -   const struct ir_dev_props *props,
> +   struct ir_dev_props *props,
> const char *driver_name)
>  {
>   struct ir_input_dev *ir_dev;

Hmm... why are you removing "const" from ir_dev_props? This change seems 
unrelated
with the patch description.

> diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
> index c6a80b3..bdf2ed8 100644
> --- a/drivers/media/IR/ir-raw-event.c
> +++ b/drivers/media/IR/ir-raw-event.c
> @@ -129,6 +129,92 @@ int ir_raw_event_store_edge(struct input_dev *input_dev, 
> enum raw_event_type typ
>  EXPORT_SYMBOL_GPL(ir_raw_event_store_edge);
>  
>  /**
> + * ir_raw_event_store_with_filter() - pass next pulse/space to decoders with 
> some processing
> + * @input_dev:   the struct input_dev device descriptor
> + * @type:the type of the event that has occurred
> + *
> + * This routine (which may be called from an interrupt context) is used to
> + * store the beginning of an ir pulse or space (or the start/end of ir
> + * reception) for the raw ir decoding state machines.\
> + * This routine is intended for devices with limited internal buffer
> + * It automerges samples of same type, and handles timeouts
> + */
> +int ir_raw_event_store_with_filter(struct input_dev *input_dev,
> + struct ir_raw_event *ev)
> +{
> + struct ir_input_dev *ir = input_get_drvdata(input_dev);
> + struct ir_raw_event_ctrl *raw = ir->raw;
> +
> + if (!ir->raw || !ir->props)
> + return -EINVAL;
> +
> + /* Ignore spaces in idle mode */
> + if (ir->idle && !ev->pulse)
> + return 0;
> + else if (ir->idle)
> + ir_raw_event_set_idle(input_dev, 0);
> +
> + if (!raw->current_sample.duration) {
> + raw->current_sample = *ev;
> + } else if (ev->pulse == raw->current_sample.pulse) {
> + raw->current_sample.duration += ev->duration;
> + } else {
> + ir_raw_event_store(input_dev, &raw->current_sample);
> + raw->current_sample = *ev;
> + }
> +
> + /* Enter idle mode if nessesary */
> + if (!ev->pulse && ir->props->timeout &&
> + raw->current_sample.duration >= ir->props->timeout)
> + ir_raw_event_set_idle(input_dev, 1);
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(ir_raw_event_store_with_filter);
> +
> +
> +void ir_raw_event_set_idle(struct input_dev *input_dev, int idle)
> +{
> + struct ir_input_dev *ir = input_get_drvdata(input_dev);
> + struct ir_raw_event_ctrl *raw = ir->raw;
> + ktime_t now;
> + u64 delta;
> +
> + if (!ir->props)
> + return;
> +
> + if (!ir->raw)
> + goto out;
> +
> + if (idle) {
> + IR_dprintk(2, "enter idle mode\n");
> + raw->last_event = ktime_get();
> + } else {
> + IR_dprintk(2, "exit idle mode\n");
> +
> + now = ktime_get();
> + delta = ktime_to_ns(ktime_sub(now, ir->raw->last_event));
> +
> + WARN_ON(raw->current_sample.pulse);
> +
> +  

[PATCH 4/9] IR: add helper functions for ir input devices that send ir timing data in small chunks, and alternation between pulses and spaces isn't guaranteed.

2010-07-28 Thread Maxim Levitsky
Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-core-priv.h |1 +
 drivers/media/IR/ir-keytable.c  |2 +-
 drivers/media/IR/ir-raw-event.c |   86 +++
 include/media/ir-core.h |   24 +-
 4 files changed, 109 insertions(+), 4 deletions(-)

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index 8ce80e4..3eafdb7 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -36,6 +36,7 @@ struct ir_raw_event_ctrl {
struct kfifokfifo;  /* fifo for the 
pulse/space durations */
ktime_t last_event; /* when last event 
occurred */
enum raw_event_type last_type;  /* last event type */
+   struct ir_raw_event current_sample; /* sample that is not 
yet pushed to fifo */
struct input_dev*input_dev; /* pointer to the 
parent input_dev */
u64 enabled_protocols; /* enabled raw 
protocol decoders */
 
diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
index 94a8577..34b9c07 100644
--- a/drivers/media/IR/ir-keytable.c
+++ b/drivers/media/IR/ir-keytable.c
@@ -428,7 +428,7 @@ static void ir_close(struct input_dev *input_dev)
  */
 int __ir_input_register(struct input_dev *input_dev,
  const struct ir_scancode_table *rc_tab,
- const struct ir_dev_props *props,
+ struct ir_dev_props *props,
  const char *driver_name)
 {
struct ir_input_dev *ir_dev;
diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
index c6a80b3..bdf2ed8 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/IR/ir-raw-event.c
@@ -129,6 +129,92 @@ int ir_raw_event_store_edge(struct input_dev *input_dev, 
enum raw_event_type typ
 EXPORT_SYMBOL_GPL(ir_raw_event_store_edge);
 
 /**
+ * ir_raw_event_store_with_filter() - pass next pulse/space to decoders with 
some processing
+ * @input_dev: the struct input_dev device descriptor
+ * @type:  the type of the event that has occurred
+ *
+ * This routine (which may be called from an interrupt context) is used to
+ * store the beginning of an ir pulse or space (or the start/end of ir
+ * reception) for the raw ir decoding state machines.\
+ * This routine is intended for devices with limited internal buffer
+ * It automerges samples of same type, and handles timeouts
+ */
+int ir_raw_event_store_with_filter(struct input_dev *input_dev,
+   struct ir_raw_event *ev)
+{
+   struct ir_input_dev *ir = input_get_drvdata(input_dev);
+   struct ir_raw_event_ctrl *raw = ir->raw;
+
+   if (!ir->raw || !ir->props)
+   return -EINVAL;
+
+   /* Ignore spaces in idle mode */
+   if (ir->idle && !ev->pulse)
+   return 0;
+   else if (ir->idle)
+   ir_raw_event_set_idle(input_dev, 0);
+
+   if (!raw->current_sample.duration) {
+   raw->current_sample = *ev;
+   } else if (ev->pulse == raw->current_sample.pulse) {
+   raw->current_sample.duration += ev->duration;
+   } else {
+   ir_raw_event_store(input_dev, &raw->current_sample);
+   raw->current_sample = *ev;
+   }
+
+   /* Enter idle mode if nessesary */
+   if (!ev->pulse && ir->props->timeout &&
+   raw->current_sample.duration >= ir->props->timeout)
+   ir_raw_event_set_idle(input_dev, 1);
+   return 0;
+}
+EXPORT_SYMBOL_GPL(ir_raw_event_store_with_filter);
+
+
+void ir_raw_event_set_idle(struct input_dev *input_dev, int idle)
+{
+   struct ir_input_dev *ir = input_get_drvdata(input_dev);
+   struct ir_raw_event_ctrl *raw = ir->raw;
+   ktime_t now;
+   u64 delta;
+
+   if (!ir->props)
+   return;
+
+   if (!ir->raw)
+   goto out;
+
+   if (idle) {
+   IR_dprintk(2, "enter idle mode\n");
+   raw->last_event = ktime_get();
+   } else {
+   IR_dprintk(2, "exit idle mode\n");
+
+   now = ktime_get();
+   delta = ktime_to_ns(ktime_sub(now, ir->raw->last_event));
+
+   WARN_ON(raw->current_sample.pulse);
+
+   raw->current_sample.duration =
+   min(raw->current_sample.duration + delta,
+   (u64)IR_MAX_DURATION);
+
+   ir_raw_event_store(input_dev, &raw->current_sample);
+
+   if (raw->current_sample.duration == IR_MAX_DURATION)
+   ir_raw_event_reset(input_dev);
+
+   raw->current_sample.duration = 0;
+   }
+out:
+   if (ir->props->s_idle)
+   ir->props->s_idle(ir->props->priv, idle);
+   ir->idle = idle;
+}
+EXPORT_SYMBOL_GPL(ir_raw_event_set_idle);
+
+/**
  * i