Re: rc: ene_ir: few fixes

2013-07-15 Thread Maxim Levitsky
On Thu, Jul 11, 2013 at 3:29 AM, Maxim Levitsky  wrote:
> Any update?
>
> Best regards,
> Maxim Levitsky
>
>
> On Mon, 2013-07-08 at 03:22 +0300, Maxim Levitsky wrote:
>> Hi,
>>
>> Could you consider merging few fixes to my driver:
>>
>> 1. Fix accidently introduced error, that is the hardware is a bit unusual
>> in the way that it needs the interrupt number, and one of the recent patches
>> moved the irq number read to be too late for that.
>>
>> 2. I just now played with my remote that wakes the system, and noticed that
>> it wakes the system even if I disable the wake bit.
>> Just disable the device if wake is disabled, and this fixes the issue.
>>
>> 3. I noticed that debug prints from my driver don't work anymore,
>> and this is due to conversion to pr_dbg, which is in my opinion too 
>> restructive in
>> enabling it.
>> If you allow, I want to use pr_info instead.
>>
>> patch #1 should go to stable as well, as it outright breaks my driver.
>>
>> PS: I am very short on time, and I will be free in about month, after I pass
>> another round of exams.
>>
>> Best regards,
>>   Maxim Levitsky
>>
>
> --
> Best regards,
> Maxim Levitsky
>
> Visit my blog: http://maximlevitsky.wordpress.com
> Warning: Above blog contains rants.
>

Any update?

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: rc: ene_ir: few fixes

2013-07-10 Thread Maxim Levitsky
Any update?

Best regards,
Maxim Levitsky


On Mon, 2013-07-08 at 03:22 +0300, Maxim Levitsky wrote: 
> Hi,
> 
> Could you consider merging few fixes to my driver:
> 
> 1. Fix accidently introduced error, that is the hardware is a bit unusual
> in the way that it needs the interrupt number, and one of the recent patches
> moved the irq number read to be too late for that.
> 
> 2. I just now played with my remote that wakes the system, and noticed that
> it wakes the system even if I disable the wake bit.
> Just disable the device if wake is disabled, and this fixes the issue.
> 
> 3. I noticed that debug prints from my driver don't work anymore,
> and this is due to conversion to pr_dbg, which is in my opinion too 
> restructive in
> enabling it.
> If you allow, I want to use pr_info instead.
> 
> patch #1 should go to stable as well, as it outright breaks my driver.
> 
> PS: I am very short on time, and I will be free in about month, after I pass
> another round of exams.
> 
> Best regards,
>   Maxim Levitsky
> 

-- 
Best regards,
Maxim Levitsky

Visit my blog: http://maximlevitsky.wordpress.com
Warning: Above blog contains rants.

--
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


[PATCH 3/3] ene_ir: don't use pr_debug after all

2013-07-07 Thread Maxim Levitsky
This way to only way to get debug info is to use dynamic debug, but I left 
debugging
prints to debug hardware issues, and so I want this to be enabled by module 
param

Signed-off-by: Maxim Levitsky 
---
 drivers/media/rc/ene_ir.h |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/rc/ene_ir.h b/drivers/media/rc/ene_ir.h
index 6f978e8..a7911e3 100644
--- a/drivers/media/rc/ene_ir.h
+++ b/drivers/media/rc/ene_ir.h
@@ -185,7 +185,7 @@
 #define __dbg(level, format, ...)  \
 do {   \
if (debug >= level) \
-   pr_debug(format "\n", ## __VA_ARGS__);  \
+   pr_info(format "\n", ## __VA_ARGS__);   \
 } while (0)
 
 #define dbg(format, ...)   __dbg(1, format, ## __VA_ARGS__)
-- 
1.7.9.5

--
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


[PATCH 1/3] ene_ir: Fix interrupt line passthrough to hardware

2013-07-07 Thread Maxim Levitsky
While we can delay IRQ intialization, we need the interrupt number
right away because unusually hardware have programable interrupt number,
and thus we give it the number that was allocated by BIOS

Signed-off-by: Maxim Levitsky 
---
 drivers/media/rc/ene_ir.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/rc/ene_ir.c b/drivers/media/rc/ene_ir.c
index ee6c984..a9cf3a4 100644
--- a/drivers/media/rc/ene_ir.c
+++ b/drivers/media/rc/ene_ir.c
@@ -1022,6 +1022,8 @@ static int ene_probe(struct pnp_dev *pnp_dev, const 
struct pnp_device_id *id)
spin_lock_init(&dev->hw_lock);
 
dev->hw_io = pnp_port_start(pnp_dev, 0);
+   dev->irq = pnp_irq(pnp_dev, 0);
+
 
pnp_set_drvdata(pnp_dev, dev);
dev->pnp_dev = pnp_dev;
@@ -1085,7 +1087,6 @@ static int ene_probe(struct pnp_dev *pnp_dev, const 
struct pnp_device_id *id)
goto exit_unregister_device;
}
 
-   dev->irq = pnp_irq(pnp_dev, 0);
if (request_irq(dev->irq, ene_isr,
IRQF_SHARED, ENE_DRIVER_NAME, (void *)dev)) {
goto exit_release_hw_io;
-- 
1.7.9.5

--
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


rc: ene_ir: few fixes

2013-07-07 Thread Maxim Levitsky
Hi,

Could you consider merging few fixes to my driver:

1. Fix accidently introduced error, that is the hardware is a bit unusual
in the way that it needs the interrupt number, and one of the recent patches
moved the irq number read to be too late for that.

2. I just now played with my remote that wakes the system, and noticed that
it wakes the system even if I disable the wake bit.
Just disable the device if wake is disabled, and this fixes the issue.

3. I noticed that debug prints from my driver don't work anymore,
and this is due to conversion to pr_dbg, which is in my opinion too restructive 
in
enabling it.
If you allow, I want to use pr_info instead.

patch #1 should go to stable as well, as it outright breaks my driver.

PS: I am very short on time, and I will be free in about month, after I pass
another round of exams.

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


[PATCH 2/3] ene_ir: disable the device if wake is disabled It doesn't hurt and on my notebook despite clearing the wake flag the remote still wakes up the system. This way it doesn't

2013-07-07 Thread Maxim Levitsky
Signed-off-by: Maxim Levitsky 
---
 drivers/media/rc/ene_ir.c |   27 ---
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/drivers/media/rc/ene_ir.c b/drivers/media/rc/ene_ir.c
index a9cf3a4..61865ba 100644
--- a/drivers/media/rc/ene_ir.c
+++ b/drivers/media/rc/ene_ir.c
@@ -476,7 +476,7 @@ select_timeout:
 }
 
 /* Enable the device for receive */
-static void ene_rx_enable(struct ene_device *dev)
+static void ene_rx_enable_hw(struct ene_device *dev)
 {
u8 reg_value;
 
@@ -504,11 +504,17 @@ static void ene_rx_enable(struct ene_device *dev)
 
/* enter idle mode */
ir_raw_event_set_idle(dev->rdev, true);
+}
+
+/* Enable the device for receive - wrapper to track the state*/
+static void ene_rx_enable(struct ene_device *dev)
+{
+   ene_rx_enable_hw(dev);
dev->rx_enabled = true;
 }
 
 /* Disable the device receiver */
-static void ene_rx_disable(struct ene_device *dev)
+static void ene_rx_disable_hw(struct ene_device *dev)
 {
/* disable inputs */
ene_rx_enable_cir_engine(dev, false);
@@ -516,8 +522,13 @@ static void ene_rx_disable(struct ene_device *dev)
 
/* disable hardware IRQ and firmware flag */
ene_clear_reg_mask(dev, ENE_FW1, ENE_FW1_ENABLE | ENE_FW1_IRQ);
-
ir_raw_event_set_idle(dev->rdev, true);
+}
+
+/* Disable the device receiver - wrapper to track the state */
+static void ene_rx_disable(struct ene_device *dev)
+{
+   ene_rx_disable_hw(dev);
dev->rx_enabled = false;
 }
 
@@ -1123,9 +1134,8 @@ static void ene_remove(struct pnp_dev *pnp_dev)
 }
 
 /* enable wake on IR (wakes on specific button on original remote) */
-static void ene_enable_wake(struct ene_device *dev, int enable)
+static void ene_enable_wake(struct ene_device *dev, bool enable)
 {
-   enable = enable && device_may_wakeup(&dev->pnp_dev->dev);
dbg("wake on IR %s", enable ? "enabled" : "disabled");
ene_set_clear_reg_mask(dev, ENE_FW1, ENE_FW1_WAKE, enable);
 }
@@ -1134,9 +1144,12 @@ static void ene_enable_wake(struct ene_device *dev, int 
enable)
 static int ene_suspend(struct pnp_dev *pnp_dev, pm_message_t state)
 {
struct ene_device *dev = pnp_get_drvdata(pnp_dev);
-   ene_enable_wake(dev, true);
+   bool wake = device_may_wakeup(&dev->pnp_dev->dev);
+
+   if (!wake && dev->rx_enabled)
+   ene_rx_disable_hw(dev);
 
-   /* TODO: add support for wake pattern */
+   ene_enable_wake(dev, wake);
return 0;
 }
 
-- 
1.7.9.5

--
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: How to help with RTL2832U based TV?

2011-01-17 Thread Maxim Levitsky
On Sun, 2011-01-16 at 11:55 +0100, Keld Jørn Simonsen wrote:
> Antti Palosaari wrote Thu, 03 Dec 2009 13:48:01 -0800
> 
> > On 12/03/2009 10:09 PM, Peter Rasmussen wrote:
> > 
> > as mentioned in the welcome email of this list, but it isn't
> > apparent to
> > me what the status in Linux of using a device based on this chip is?
> > 
> > I have got today device having this chip (thanks to verkkokauppa.com for
> > sponsoring) and I am going to implement the driver. I am in hope I can
> > share some code from the old RTL2831U chip driver. I haven't looked
> > driver code yet nor taken any sniffs. I will do that during next week.
> 
> OK, what is the status of this now?
> It seems from the status page that it is not finished.
> 
> > Anyhow, there is Realtek released driver spreading over the net for that
> > chip, you can use it.
> 
> I tried to find this but without luck.
> Do you know where it can be found?
> 
> Anyway, I got the dongle to work via the following receipt:
> http://www.linuxin.dk/node/15583 (in Danish, but I think Google can
> translate it).
> 
> I would appreciate that this be in the kernel tree proper

I am doing a driver rewrite.
Don't know when I finish it though.
Could you tell me what tuner you have, and does your card also support
DVB-C?
(some Realtek cards also support Chinese DTMB, but even if yours does,
you probably won't be able to test it (unless you live there).

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 3/4] rc: conversion is to microseconds, not nanoseconds

2010-12-16 Thread Maxim Levitsky
On Thu, 2010-12-16 at 14:00 -0500, Jarod Wilson wrote:
> Fix a thinko, and move macro definition to a common header so it can be
> shared amongst all drivers, as ms to us conversion is something that
> multiple drivers need to do. We probably ought to have its inverse
> available as well.


Nope, at least ENE gets 'us' samples, that is 10^-6 seconds, and I
multiply that by 1000, and that gives nanoseconds (10^-9).
I have nothing against moving MS_TO_NS to common code of course.

Best regards,
Maxim Levitsky



> 
> Reported-by: David Härdeman 
> CC: Maxim Levitsky 
> Signed-off-by: Jarod Wilson 
> ---
>  drivers/media/rc/ene_ir.c |   16 
>  drivers/media/rc/ene_ir.h |2 --
>  drivers/media/rc/mceusb.c |7 +++
>  include/media/rc-core.h   |1 +
>  4 files changed, 12 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/media/rc/ene_ir.c b/drivers/media/rc/ene_ir.c
> index 80b3c31..1203d4f 100644
> --- a/drivers/media/rc/ene_ir.c
> +++ b/drivers/media/rc/ene_ir.c
> @@ -446,27 +446,27 @@ static void ene_rx_setup(struct ene_device *dev)
>  
>  select_timeout:
>   if (dev->rx_fan_input_inuse) {
> - dev->rdev->rx_resolution = MS_TO_NS(ENE_FW_SAMPLE_PERIOD_FAN);
> + dev->rdev->rx_resolution = MS_TO_US(ENE_FW_SAMPLE_PERIOD_FAN);
>  
>   /* Fan input doesn't support timeouts, it just ends the
>   input with a maximum sample */
>   dev->rdev->min_timeout = dev->rdev->max_timeout =
> - MS_TO_NS(ENE_FW_SMPL_BUF_FAN_MSK *
> + MS_TO_US(ENE_FW_SMPL_BUF_FAN_MSK *
>   ENE_FW_SAMPLE_PERIOD_FAN);
>   } else {
> - dev->rdev->rx_resolution = MS_TO_NS(sample_period);
> + dev->rdev->rx_resolution = MS_TO_US(sample_period);
>  
>   /* Theoreticly timeout is unlimited, but we cap it
>* because it was seen that on one device, it
>* would stop sending spaces after around 250 msec.
>* Besides, this is close to 2^32 anyway and timeout is u32.
>*/
> - dev->rdev->min_timeout = MS_TO_NS(127 * sample_period);
> - dev->rdev->max_timeout = MS_TO_NS(20);
> + dev->rdev->min_timeout = MS_TO_US(127 * sample_period);
> + dev->rdev->max_timeout = MS_TO_US(20);
>   }
>  
>   if (dev->hw_learning_and_tx_capable)
> - dev->rdev->tx_resolution = MS_TO_NS(sample_period);
> + dev->rdev->tx_resolution = MS_TO_US(sample_period);
>  
>   if (dev->rdev->timeout > dev->rdev->max_timeout)
>   dev->rdev->timeout = dev->rdev->max_timeout;
> @@ -801,7 +801,7 @@ static irqreturn_t ene_isr(int irq, void *data)
>  
>   dbg("RX: %d (%s)", hw_sample, pulse ? "pulse" : "space");
>  
> - ev.duration = MS_TO_NS(hw_sample);
> + ev.duration = MS_TO_US(hw_sample);
>   ev.pulse = pulse;
>   ir_raw_event_store_with_filter(dev->rdev, &ev);
>   }
> @@ -821,7 +821,7 @@ static void ene_setup_default_settings(struct ene_device 
> *dev)
>   dev->learning_mode_enabled = learning_mode_force;
>  
>   /* Set reasonable default timeout */
> - dev->rdev->timeout = MS_TO_NS(15);
> + dev->rdev->timeout = MS_TO_US(15);
>  }
>  
>  /* Upload all hardware settings at once. Used at load and resume time */
> diff --git a/drivers/media/rc/ene_ir.h b/drivers/media/rc/ene_ir.h
> index c179baf..337a41d 100644
> --- a/drivers/media/rc/ene_ir.h
> +++ b/drivers/media/rc/ene_ir.h
> @@ -201,8 +201,6 @@
>  #define dbg_verbose(format, ...) __dbg(2, format, ## __VA_ARGS__)
>  #define dbg_regs(format, ...)__dbg(3, format, ## __VA_ARGS__)
>  
> -#define MS_TO_NS(msec) ((msec) * 1000)
> -
>  struct ene_device {
>   struct pnp_dev *pnp_dev;
>   struct rc_dev *rdev;
> diff --git a/drivers/media/rc/mceusb.c b/drivers/media/rc/mceusb.c
> index 94b95d4..9c55e32 100644
> --- a/drivers/media/rc/mceusb.c
> +++ b/drivers/media/rc/mceusb.c
> @@ -48,7 +48,6 @@
>  #define USB_BUFLEN   32 /* USB reception buffer length */
>  #define USB_CTRL_MSG_SZ  2  /* Size of usb ctrl msg on gen1 hw */
>  #define MCE_G1_INIT_MSGS 40 /* Init messages on gen1 hw to throw out */
> -#define MS_TO_NS(msec)   ((msec) * 1000)
>  
>  /* MCE constants */
>  #define MCE_CMDBUF_SIZE  384  /* MCE Command buffer length */
> @@ -815,7 +814,7 @@ s

Re: rtl2832u support

2010-12-06 Thread Maxim Levitsky
On Mon, 2010-12-06 at 16:43 -0500, Alex Deucher wrote:
> On Mon, Dec 6, 2010 at 4:29 PM, Jan Hoogenraad
>  wrote:
> > I haven't seen any data sheets. At the other hand, Antti was able to create
> > a separated (tuner vs demod) driver, except for IR.
> >
> > http://linuxtv.org/hg/~anttip/rtl2831u/
> >
> > http://linuxtv.org/hg/~anttip/qt1010/
> >
> > I haven't seen a data sheet, but I doubt if it would be of more use than
> > using this example code.
> > My mail contacts (latest in may 2008) focused on getting the code to work
> > and on signing off the code.
> >
> > I'll give my mail contact a try, especially if you have questions that
> > cannot be found in the current code base.
> 
> FWIW, in my experience, working code is preferable to datasheets if
> you have to pick.  Often times datasheets are produced pre-silicon and
> aren't always updated properly with the final changes.
I completely agree with that.

however I miss few things in IR code
(it works with protocols the driver in-house decoding supports but fails
for others.)

And few other things.
Sure like I said, I can manage without them.
But if I had datasheets in addition to working code, it would be better.

Best regards,
Maxim Levitsky


> 
> Alex
> 
> >
> > Maxim Levitsky wrote:
> >>
> >> On Mon, 2010-12-06 at 16:45 +0100, Jan Hoogenraad wrote:
> >>>
> >>> Could the tree from
> >>>
> >>> http://linuxtv.org/hg/~jhoogenraad/rtl2831-r2
> >>>
> >>> which is really just an older version of the same code, go into staging
> >>> than as well ?
> >>
> >> Yes, but the problem is that due to shaddy license status of the
> >> 'windows' driver, I am afraid to look seriously at it.
> >> Up till now, I only experimented with IR code.
> >>
> >> Jan, since you have contacts with Realtek, maybe it would be possible to
> >> get datasheet for their hardware?
> >>
> >> And the above code is guaraneed not to work on my card because even
> >> their 'windows' driver v1.4 doesn't work here.
> >> Only 2.0 driver works.
> >>
> >> And you said that you couldn't seperate demod from bridge?
> >> Is that nessesary?
> >> I have seen few drivers that don't separate it in v4l source.
> >>
> >> Tuners are of course another story.
> >>
> >> Best regards,
> >>Maxim Levitsky
> >>
> >>
> >>>
> >>> For that one, I have the signoff by RealTek already.
> >>>
> >>> Mauro Carvalho Chehab wrote:
> >>>>
> >>>> Em 20-11-2010 20:37, Maxim Levitsky escreveu:
> >>>>
> >>>>>>> Do we have a common agreement that this driver can go to staging
> >>>>>>> as-is?
> >>>>>>>
> >>>>>>> If yes, I have patch ready, just need to know where to send it (It is
> >>>>>>> around 1 MB).
> >>>>
> >>>> Yes, if people is interested on later fixing the issues. As Antti said
> >>>> he already broke the driver into more consistent parts, maybe his tree
> >>>> may be an start.
> >>>>
> >>>>>
> >>>>> I would like to volunteer to clean up the driver for eventual merge.
> >>>>> At least I can start right away with low handing fruit.
> >>>>
> >>>> Ok, Seems fine for me.
> >>>>
> >>>>> I have took the driver from
> >>>>>
> >>>>>
> >>>>> http://www.turnovfree.net/~stybla/linux/v4l-dvb/lv5tdlx/20101102_RTL2832_2836_2840_LINUX+RC-Dongle.rar
> >>>>>
> >>>>>
> >>>>> And it looks very recent, so that means that Realtek actually continues
> >>>>> to develop it.
> >>>>
> >>>> The better would be to try to sync with Realtek to be sure that they'll
> >>>> continue to develop the upstream driver, after having it merged.
> >>>> Otherwise,
> >>>> someone will need to do the manual sync, and this can be very painful.
> >>>>
> >>>>> Greg KH, maybe you know how to contact Realteck to figure out the best
> >>>>> strategy in handling this code.
> >>>>>
> >>>>> Meanwhile, lets put that into staging.
> >>>>> (The above driver doesn't compile due to

Re: rtl2832u support

2010-12-06 Thread Maxim Levitsky
On Mon, 2010-12-06 at 16:45 +0100, Jan Hoogenraad wrote:
> Could the tree from
> 
> http://linuxtv.org/hg/~jhoogenraad/rtl2831-r2
> 
> which is really just an older version of the same code, go into staging
> than as well ?
Yes, but the problem is that due to shaddy license status of the
'windows' driver, I am afraid to look seriously at it.
Up till now, I only experimented with IR code.

Jan, since you have contacts with Realtek, maybe it would be possible to
get datasheet for their hardware?

And the above code is guaraneed not to work on my card because even
their 'windows' driver v1.4 doesn't work here.
Only 2.0 driver works.

And you said that you couldn't seperate demod from bridge?
Is that nessesary?
I have seen few drivers that don't separate it in v4l source.

Tuners are of course another story.

Best regards,
Maxim Levitsky


> 
> For that one, I have the signoff by RealTek already.
> 
> Mauro Carvalho Chehab wrote:
> > Em 20-11-2010 20:37, Maxim Levitsky escreveu:
> >
> >>>> Do we have a common agreement that this driver can go to staging as-is?
> >>>>
> >>>> If yes, I have patch ready, just need to know where to send it (It is 
> >>>> around 1 MB).
> >
> > Yes, if people is interested on later fixing the issues. As Antti said
> > he already broke the driver into more consistent parts, maybe his tree
> > may be an start.
> >
> >>
> >> I would like to volunteer to clean up the driver for eventual merge.
> >> At least I can start right away with low handing fruit.
> >
> > Ok, Seems fine for me.
> >
> >> I have took the driver from
> >>
> >> http://www.turnovfree.net/~stybla/linux/v4l-dvb/lv5tdlx/20101102_RTL2832_2836_2840_LINUX+RC-Dongle.rar
> >>
> >>
> >> And it looks very recent, so that means that Realtek actually continues
> >> to develop it.
> >
> > The better would be to try to sync with Realtek to be sure that they'll
> > continue to develop the upstream driver, after having it merged. Otherwise,
> > someone will need to do the manual sync, and this can be very painful.
> >
> >> Greg KH, maybe you know how to contact Realteck to figure out the best
> >> strategy in handling this code.
> >>
> >> Meanwhile, lets put that into staging.
> >> (The above driver doesn't compile due to changes in RC code, but it can
> >> be removed (that what I did for now) or ported to new rc-core which what
> >> I will do very soon).
> >
> > Just send the patches. The better is to submit them via linux-media, and 
> > say, at
> > a TODO file, that patches for it should be submitted to 
> > linux-me...@vger.kernel.org.
> > Something similar to drivers/staging/tm6000/TODO.
> >
> > Cheers,
> > Mauro
> > --
> > 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
> >
> 
> 


--
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


New developer for RTL2832U DVB device

2010-12-04 Thread Maxim Levitsky
Good day,

I would like to volunteer, to bring into the kernel, the support for
Realtek DVB hardware.

I need a word from Realtek about driver that is a direct port of windows
driver.

I need to know that if it is released under GPL compatible  licence,
which isn't clear today.

Also I would like to access to newer revisions of this driver to keep up
with the code, so that my future driver won't be out of date.

And I need datasheets. Datasheets will save me a lot of time, time I
would have to spend reverse engineering not obvious parts otherwise.

For example, while reworking IR support to use ir-core, I run info few
issues that are likely to be fixable using a different register setup.

I don't ming agreeing to non written NDA, that is you gave me datasheets
privately and ask me not to distribute them. I won't.
Actually I have few datasheets already obtained that way.

In this mail, I tried to CC few developers that have shown an interest
in this driver.

I also CCed few realtek employees whose addresses I could find in mail
archive. I really do hope for an answer (don't mind if it is private).

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: rtl2832u support

2010-11-26 Thread Maxim Levitsky
On Sun, 2010-11-21 at 00:37 +0200, Maxim Levitsky wrote:
> On Fri, 2010-11-19 at 09:36 +0200, Maxim Levitsky wrote:
> > On Wed, 2010-11-17 at 12:15 +0100, Damjan Marion wrote:
> > > On Oct 19, 2010, at 10:27 PM, Hans Verkuil wrote:
> > > > On Tuesday, October 19, 2010 21:26:13 Devin Heitmueller wrote:
> > > >> On Tue, Oct 19, 2010 at 1:42 PM, Damjan Marion 
> > > >>  wrote:
> > > >>> 
> > > >>> Hi,
> > > >>> 
> > > >>> Is there any special reason why driver for rtl2832u DVB-T receiver 
> > > >>> chipset is not included into v4l-dvb?
> > > >>> 
> > > >>> Realtek published source code under GPL:
> > > >>> 
> > > >>> MODULE_AUTHOR("Realtek");
> > > >>> MODULE_DESCRIPTION("Driver for the RTL2832U DVB-T / RTL2836 DTMB 
> > > >>> USB2.0 device");
> > > >>> MODULE_VERSION("1.4.2");
> > > >>> MODULE_LICENSE("GPL");
> > > >> 
> > > >> Unfortunately, in most cases much more is "required" than having a
> > > >> working driver under the GPL in order for it to be accepted upstream.
> > > >> In some cases it can mean a developer spending a few hours cleaning up
> > > >> whitespace and indentation, and in other cases it means significant
> > > >> work to the driver is required.
> > > >> 
> > > >> The position the LinuxTV team has taken is that they would rather have
> > > >> no upstream driver at all than to have a driver which doesn't have the
> > > >> right indentation or other aesthetic problems which has no bearing on
> > > >> how well the driver actually works.
> > > >> 
> > > >> This is one of the big reasons KernelLabs has tens of thousands of
> > > >> lines of code adding support for a variety of devices with many happy
> > > >> users (who are willing to go through the trouble to compile from
> > > >> source), but the code cannot be accepted upstream.  I just cannot find
> > > >> the time to do the "idiot work".
> > > > 
> > > > Bullshit. First of all these rules are those of the kernel community
> > > > as a whole and *not* linuxtv as such, and secondly you can upstream such
> > > > drivers in the staging tree. If you want to move it out of staging, then
> > > > it will take indeed more work since the quality requirements are higher
> > > > there.
> > > 
> > > 
> > > Do we have a common agreement that this driver can go to staging as-is?
> > > 
> > > If yes, I have patch ready, just need to know where to send it (It is 
> > > around 1 MB).
> 
> I would like to volunteer to clean up the driver for eventual merge.
> At least I can start right away with low handing fruit.
> 
> I have took the driver from
> 
> http://www.turnovfree.net/~stybla/linux/v4l-dvb/lv5tdlx/20101102_RTL2832_2836_2840_LINUX+RC-Dongle.rar
> 
> 
> And it looks very recent, so that means that Realtek actually continues
> to develop it.
> 
> Greg KH, maybe you know how to contact Realteck to figure out the best
> strategy in handling this code.
> 
> Meanwhile, lets put that into staging.
> (The above driver doesn't compile due to changes in RC code, but it can
> be removed (that what I did for now) or ported to new rc-core which what
> I will do very soon).
> 
> Best regards,
>   Maxim Levitsky

Anybody?

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: rtl2832u support

2010-11-20 Thread Maxim Levitsky
On Fri, 2010-11-19 at 09:36 +0200, Maxim Levitsky wrote:
> On Wed, 2010-11-17 at 12:15 +0100, Damjan Marion wrote:
> > On Oct 19, 2010, at 10:27 PM, Hans Verkuil wrote:
> > > On Tuesday, October 19, 2010 21:26:13 Devin Heitmueller wrote:
> > >> On Tue, Oct 19, 2010 at 1:42 PM, Damjan Marion  
> > >> wrote:
> > >>> 
> > >>> Hi,
> > >>> 
> > >>> Is there any special reason why driver for rtl2832u DVB-T receiver 
> > >>> chipset is not included into v4l-dvb?
> > >>> 
> > >>> Realtek published source code under GPL:
> > >>> 
> > >>> MODULE_AUTHOR("Realtek");
> > >>> MODULE_DESCRIPTION("Driver for the RTL2832U DVB-T / RTL2836 DTMB USB2.0 
> > >>> device");
> > >>> MODULE_VERSION("1.4.2");
> > >>> MODULE_LICENSE("GPL");
> > >> 
> > >> Unfortunately, in most cases much more is "required" than having a
> > >> working driver under the GPL in order for it to be accepted upstream.
> > >> In some cases it can mean a developer spending a few hours cleaning up
> > >> whitespace and indentation, and in other cases it means significant
> > >> work to the driver is required.
> > >> 
> > >> The position the LinuxTV team has taken is that they would rather have
> > >> no upstream driver at all than to have a driver which doesn't have the
> > >> right indentation or other aesthetic problems which has no bearing on
> > >> how well the driver actually works.
> > >> 
> > >> This is one of the big reasons KernelLabs has tens of thousands of
> > >> lines of code adding support for a variety of devices with many happy
> > >> users (who are willing to go through the trouble to compile from
> > >> source), but the code cannot be accepted upstream.  I just cannot find
> > >> the time to do the "idiot work".
> > > 
> > > Bullshit. First of all these rules are those of the kernel community
> > > as a whole and *not* linuxtv as such, and secondly you can upstream such
> > > drivers in the staging tree. If you want to move it out of staging, then
> > > it will take indeed more work since the quality requirements are higher
> > > there.
> > 
> > 
> > Do we have a common agreement that this driver can go to staging as-is?
> > 
> > If yes, I have patch ready, just need to know where to send it (It is 
> > around 1 MB).

I would like to volunteer to clean up the driver for eventual merge.
At least I can start right away with low handing fruit.

I have took the driver from

http://www.turnovfree.net/~stybla/linux/v4l-dvb/lv5tdlx/20101102_RTL2832_2836_2840_LINUX+RC-Dongle.rar


And it looks very recent, so that means that Realtek actually continues
to develop it.

Greg KH, maybe you know how to contact Realteck to figure out the best
strategy in handling this code.

Meanwhile, lets put that into staging.
(The above driver doesn't compile due to changes in RC code, but it can
be removed (that what I did for now) or ported to new rc-core which what
I will do very soon).

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: rtl2832u support

2010-11-18 Thread Maxim Levitsky
On Wed, 2010-11-17 at 12:15 +0100, Damjan Marion wrote:
> On Oct 19, 2010, at 10:27 PM, Hans Verkuil wrote:
> > On Tuesday, October 19, 2010 21:26:13 Devin Heitmueller wrote:
> >> On Tue, Oct 19, 2010 at 1:42 PM, Damjan Marion  
> >> wrote:
> >>> 
> >>> Hi,
> >>> 
> >>> Is there any special reason why driver for rtl2832u DVB-T receiver 
> >>> chipset is not included into v4l-dvb?
> >>> 
> >>> Realtek published source code under GPL:
> >>> 
> >>> MODULE_AUTHOR("Realtek");
> >>> MODULE_DESCRIPTION("Driver for the RTL2832U DVB-T / RTL2836 DTMB USB2.0 
> >>> device");
> >>> MODULE_VERSION("1.4.2");
> >>> MODULE_LICENSE("GPL");
> >> 
> >> Unfortunately, in most cases much more is "required" than having a
> >> working driver under the GPL in order for it to be accepted upstream.
> >> In some cases it can mean a developer spending a few hours cleaning up
> >> whitespace and indentation, and in other cases it means significant
> >> work to the driver is required.
> >> 
> >> The position the LinuxTV team has taken is that they would rather have
> >> no upstream driver at all than to have a driver which doesn't have the
> >> right indentation or other aesthetic problems which has no bearing on
> >> how well the driver actually works.
> >> 
> >> This is one of the big reasons KernelLabs has tens of thousands of
> >> lines of code adding support for a variety of devices with many happy
> >> users (who are willing to go through the trouble to compile from
> >> source), but the code cannot be accepted upstream.  I just cannot find
> >> the time to do the "idiot work".
> > 
> > Bullshit. First of all these rules are those of the kernel community
> > as a whole and *not* linuxtv as such, and secondly you can upstream such
> > drivers in the staging tree. If you want to move it out of staging, then
> > it will take indeed more work since the quality requirements are higher
> > there.
> 
> 
> Do we have a common agreement that this driver can go to staging as-is?
> 
> If yes, I have patch ready, just need to know where to send it (It is around 
> 1 MB).

I also bought that device few days ago.
Needless to say it works perfectly (better that in windows) with this
driver.

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


[PATCH] IR: initialize ir_raw_event in few more drivers

2010-10-24 Thread Maxim Levitsky
Few drivers still have assumption that ir_raw_event
consists of duration and pulse flag.
Fix that.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/dvb/siano/smsir.c  |2 +-
 drivers/media/video/cx23885/cx23888-ir.c |1 +
 drivers/media/video/cx25840/cx25840-ir.c |1 +
 3 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/media/dvb/siano/smsir.c b/drivers/media/dvb/siano/smsir.c
index d0e4639..a27c44a 100644
--- a/drivers/media/dvb/siano/smsir.c
+++ b/drivers/media/dvb/siano/smsir.c
@@ -40,7 +40,7 @@ void sms_ir_event(struct smscore_device_t *coredev, const 
char *buf, int len)
const s32 *samples = (const void *)buf;
 
for (i = 0; i < len >> 2; i++) {
-   struct ir_raw_event ev;
+   DEFINE_IR_RAW_EVENT(ev);
 
ev.duration = abs(samples[i]) * 1000; /* Convert to ns */
ev.pulse = (samples[i] > 0) ? false : true;
diff --git a/drivers/media/video/cx23885/cx23888-ir.c 
b/drivers/media/video/cx23885/cx23888-ir.c
index 2502a0a..e78e3e4 100644
--- a/drivers/media/video/cx23885/cx23888-ir.c
+++ b/drivers/media/video/cx23885/cx23888-ir.c
@@ -704,6 +704,7 @@ static int cx23888_ir_rx_read(struct v4l2_subdev *sd, u8 
*buf, size_t count,
if (v > IR_MAX_DURATION)
v = IR_MAX_DURATION;
 
+   init_ir_raw_event(&p->ir_core_data);
p->ir_core_data.pulse = u;
p->ir_core_data.duration = v;
 
diff --git a/drivers/media/video/cx25840/cx25840-ir.c 
b/drivers/media/video/cx25840/cx25840-ir.c
index c2b4c14..97a4e9b 100644
--- a/drivers/media/video/cx25840/cx25840-ir.c
+++ b/drivers/media/video/cx25840/cx25840-ir.c
@@ -706,6 +706,7 @@ static int cx25840_ir_rx_read(struct v4l2_subdev *sd, u8 
*buf, size_t count,
if (v > IR_MAX_DURATION)
v = IR_MAX_DURATION;
 
+   init_ir_raw_event(&p->ir_core_data);
p->ir_core_data.pulse = u;
p->ir_core_data.duration = v;
 
-- 
1.7.1

--
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 RFC] ir-rc5-decoder: don't wait for the end space to produce a code

2010-10-22 Thread Maxim Levitsky
On Fri, 2010-10-22 at 23:39 -0200, Mauro Carvalho Chehab wrote:
> Em 22-10-2010 23:25, Maxim Levitsky escreveu:
> > On Thu, 2010-10-21 at 11:56 -0200, Mauro Carvalho Chehab wrote:
> >> Em 21-10-2010 11:46, Jarod Wilson escreveu:
> >>> On Oct 20, 2010, at 1:18 PM, Mauro Carvalho Chehab wrote:
> >>>
> >>>> The RC5 decoding is complete at a BIT_END state. there's no reason
> >>>> to wait for the next space to produce a code.
> >>>
> >>> Well, if I'm reading things correctly here, I think the only true 
> >>> functional difference made to the decoder here was to skip the if
> >>> (ev.pulse) break; check in STATE_FINISHED, no? In other words, this looks 
> >>> like it was purely an issue with the receiver data parsing,
> >>> which was ending on a pulse instead of a space. I can make this guess in 
> >>> greater confidence having seen another patch somewhere that
> >>> implements a different buffer parsing routine for the polaris devices 
> >>> though... ;)
> >>
> >> This patch doesn't solve the Polaris issue ;)
> >>
> >> While I made it in the hope that it would fix Polaris (it ended by not 
> >> solving), I still think it can be kept, as
> >> it speeds up a little bit the RC-5 output, by not waiting for the last 
> >> space.
> >>
> >> I'll be forwarding soon the polaris decoder fixes patch, and another 
> >> mceusb patch I did,
> >> improving data decode on debug mode.
> >>
> >>> The mceusb portion of the patch is probably a worthwhile 
> >>> micro-optimization of its ir processing routine though -- 
> >>> don't call ir_raw_event_handle if there's no event to handle. Lemme just 
> >>> go ahead and merge that part via my staging tree, 
> >>> if you don't mind. (I've got a dozen or so IR patches that have been 
> >>> queueing up, planning on another pull req relatively soon).
> >>>
> >>
> >> Oh! I didn't notice that this went into the patch... for sure it doesn't 
> >> belong here.
> >> Yes, it is just a cleanup for mceusb. Feel free to split it, adding a 
> >> proper description for it
> >> and preserving my SOB.
> > 
> > No need in this patch.
> > My patch resolves the issue genericly by making the driver send the
> > timeout message at the end of the data among the current length of the
> > space (which will continue to grow).
> > 
> > Just make mceusb send the timeout sample.
> 
> 
> Hmm... now, a RC6(0) remote is also being decoded as a RC5 remote. Could this 
> be due to
> your patches?
Very unlikely.
Probably the remote is really RC5

RC5 and RC6 just differ too much.
And besides mceusb doesn't even send the timeouts yet.
Still you could revert and see if it helps.

The only patch that has any potential of breaking anything is the
'[PATCH 1/3] IR: extend ir_raw_event and do refactoring'

Note that I tried going the way this patch does.
And it really doesn't work.



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 RFC] ir-rc5-decoder: don't wait for the end space to produce a code

2010-10-22 Thread Maxim Levitsky
On Thu, 2010-10-21 at 11:56 -0200, Mauro Carvalho Chehab wrote:
> Em 21-10-2010 11:46, Jarod Wilson escreveu:
> > On Oct 20, 2010, at 1:18 PM, Mauro Carvalho Chehab wrote:
> > 
> >> The RC5 decoding is complete at a BIT_END state. there's no reason
> >> to wait for the next space to produce a code.
> > 
> > Well, if I'm reading things correctly here, I think the only true 
> > functional difference made to the decoder here was to skip the if
> > (ev.pulse) break; check in STATE_FINISHED, no? In other words, this looks 
> > like it was purely an issue with the receiver data parsing,
> > which was ending on a pulse instead of a space. I can make this guess in 
> > greater confidence having seen another patch somewhere that
> > implements a different buffer parsing routine for the polaris devices 
> > though... ;)
> 
> This patch doesn't solve the Polaris issue ;)
> 
> While I made it in the hope that it would fix Polaris (it ended by not 
> solving), I still think it can be kept, as
> it speeds up a little bit the RC-5 output, by not waiting for the last space.
> 
> I'll be forwarding soon the polaris decoder fixes patch, and another mceusb 
> patch I did,
> improving data decode on debug mode.
> 
> > The mceusb portion of the patch is probably a worthwhile micro-optimization 
> > of its ir processing routine though -- 
> > don't call ir_raw_event_handle if there's no event to handle. Lemme just go 
> > ahead and merge that part via my staging tree, 
> > if you don't mind. (I've got a dozen or so IR patches that have been 
> > queueing up, planning on another pull req relatively soon).
> > 
> 
> Oh! I didn't notice that this went into the patch... for sure it doesn't 
> belong here.
> Yes, it is just a cleanup for mceusb. Feel free to split it, adding a proper 
> description for it
> and preserving my SOB.

No need in this patch.
My patch resolves the issue genericly by making the driver send the
timeout message at the end of the data among the current length of the
space (which will continue to grow).

Just make mceusb send the timeout sample.

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 0/3] Remaining patches in my queue for IR

2010-10-21 Thread Maxim Levitsky
On Wed, 2010-10-20 at 14:40 -0400, Jarod Wilson wrote:
> On Sun, Oct 17, 2010 at 12:56:27AM +0200, Maxim Levitsky wrote:
> > Hi,
> > 
> > This series is rebased on top of media_tree/staging/v2.6.37 only.
> > Really this time, sorry for cheating, last time :-)
> > 
> > The first patch like we agreed extends the raw packets.
> > It touches all drivers (except imon as it isn't a raw IR driver).
> > Code is compile tested with all drivers, 
> > and run tested with ENE and all receiver protocols
> > (except the streamzap rc5 flavour)
> > Since it also moves timeouts to lirc bridge, at least streazap driver
> > should have its timeout gap support removed. I am afraid to break the code
> > if I do so.
> 
> I've tested both mceusb and streamzap with this patchset included, don't
> see any ill side-effects. Only issue I really saw was that the raw event
> init call was added somewhat superfluously to a number of drivers -- the
> rawir struct its initializing was already kzalloc'd, so we're just
> needlessly re-zero'ing it out again. Its not bad for clarity's sake, but
> does add some unnecessary inefficiency.
Yes, I somewhat agree.

On the other hand, I had an idea to add a magic field to ir_raw_event to
guard against uninitialized uses.
(something like the struct scatterlist).

Don't know it that is worth it.
Or that I sound like a typical supporter of OOP style of abstracting
everything because sometime at the future there will be need to change
it..

Anyway, as Andy pointed, note that few drivers became broken due to that
patch because these don't initialize the ir_raw_event.

I will send a patch tomorrow (I was very busy this week).

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 0/3] Remaining patches in my queue for IR

2010-10-16 Thread Maxim Levitsky
On Sat, 2010-10-16 at 20:36 -0400, Andy Walls wrote:
> On Sun, 2010-10-17 at 00:56 +0200, Maxim Levitsky wrote:
> > Hi,
> > 
> > This series is rebased on top of media_tree/staging/v2.6.37 only.
> > Really this time, sorry for cheating, last time :-)
> > 
> > The first patch like we agreed extends the raw packets.
> > It touches all drivers (except imon as it isn't a raw IR driver).
> 
> Will IR for the CX23885 and CX23888 still work given the changes?
> 
> Here's the relevant files that use struct ir_raw_event:
> 
> http://git.linuxtv.org/media_tree.git?a=blob;f=drivers/media/video/cx23885/cx23885-input.c;h=bb61870b8d6ed39d25c11aa676b55bd0a94dc235;hb=staging/v2.6.37
> http://git.linuxtv.org/media_tree.git?a=blob;f=drivers/media/video/cx25840/cx25840-ir.c;h=c2b4c14dc9ab533ff524b3e301235d6bdc92e2b9;hb=staging/v2.6.37
> http://git.linuxtv.org/media_tree.git?a=blob;f=drivers/media/video/cx23885/cx23888-ir.c;h=2502a0a6709783b8c01d5de639d759d097f0f1cd;hb=staging/v2.6.37
> 
> If needed, cx23885-input.c is where a fix can be made to ensure
> structure fields are properly zeroed until I have time to fix he lower
> level stuff.
> 
> Regards,
> Andy
Wasn't aware of this as I only looked at IR directory. Will grep the
sources for more drivers. 
Anyway the changes I propose are
straightforward, I shouldn't break the driver with it.
But of course if driver isn't updated it probably won't work.

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


[PATCH 1/3] IR: extend ir_raw_event and do refactoring

2010-10-16 Thread Maxim Levitsky
Add new event types for timeout & carrier report
Move timeout handling from ir_raw_event_store_with_filter to
ir-lirc-codec, where it is really needed.
Now lirc bridge ensures proper gap handling.
Extend lirc bridge for carrier & timeout reports

Note: all new ir_raw_event variables now should be initialized
like that: DEFINE_IR_RAW_EVENT(ev);

To clean an existing event, use init_ir_raw_event(&ev);

Signed-off-by: Maxim Levitsky 
Acked-by: Jarod Wilson 
---
 drivers/media/IR/ene_ir.c|4 +-
 drivers/media/IR/ir-core-priv.h  |   13 +++-
 drivers/media/IR/ir-jvc-decoder.c|5 +-
 drivers/media/IR/ir-lirc-codec.c |  128 --
 drivers/media/IR/ir-nec-decoder.c|5 +-
 drivers/media/IR/ir-raw-event.c  |   45 
 drivers/media/IR/ir-rc5-decoder.c|5 +-
 drivers/media/IR/ir-rc5-sz-decoder.c |5 +-
 drivers/media/IR/ir-rc6-decoder.c|5 +-
 drivers/media/IR/ir-sony-decoder.c   |5 +-
 drivers/media/IR/mceusb.c|3 +-
 drivers/media/IR/nuvoton-cir.c   |5 +-
 drivers/media/IR/streamzap.c |6 +-
 include/media/ir-core.h  |   40 +--
 14 files changed, 181 insertions(+), 93 deletions(-)

diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index 9f9afe7..8639621 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -697,7 +697,7 @@ static irqreturn_t ene_isr(int irq, void *data)
unsigned long flags;
irqreturn_t retval = IRQ_NONE;
struct ene_device *dev = (struct ene_device *)data;
-   struct ir_raw_event ev;
+   DEFINE_IR_RAW_EVENT(ev);
 
spin_lock_irqsave(&dev->hw_lock, flags);
 
@@ -898,7 +898,7 @@ static int ene_set_learning_mode(void *data, int enable)
 }
 
 /* outside interface: enable or disable idle mode */
-static void ene_rx_set_idle(void *data, int idle)
+static void ene_rx_set_idle(void *data, bool idle)
 {
struct ene_device *dev = (struct ene_device *)data;
 
diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index 6830580..81c936b 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -88,6 +88,12 @@ struct ir_raw_event_ctrl {
struct ir_input_dev *ir_dev;
struct lirc_driver *drv;
int carrier_low;
+
+   ktime_t gap_start;
+   u64 gap_duration;
+   bool gap;
+   bool send_timeout_reports;
+
} lirc;
 };
 
@@ -115,9 +121,14 @@ static inline void decrease_duration(struct ir_raw_event 
*ev, unsigned duration)
ev->duration -= duration;
 }
 
+/* Returns true if event is normal pulse/space event */
+static inline bool is_timing_event(struct ir_raw_event ev)
+{
+   return !ev.carrier_report && !ev.reset;
+}
+
 #define TO_US(duration)DIV_ROUND_CLOSEST((duration), 
1000)
 #define TO_STR(is_pulse)   ((is_pulse) ? "pulse" : "space")
-#define IS_RESET(ev)   (ev.duration == 0)
 /*
  * Routines from ir-sysfs.c - Meant to be called only internally inside
  * ir-core
diff --git a/drivers/media/IR/ir-jvc-decoder.c 
b/drivers/media/IR/ir-jvc-decoder.c
index 77a89c4..63dca6e 100644
--- a/drivers/media/IR/ir-jvc-decoder.c
+++ b/drivers/media/IR/ir-jvc-decoder.c
@@ -50,8 +50,9 @@ static int ir_jvc_decode(struct input_dev *input_dev, struct 
ir_raw_event ev)
if (!(ir_dev->raw->enabled_protocols & IR_TYPE_JVC))
return 0;
 
-   if (IS_RESET(ev)) {
-   data->state = STATE_INACTIVE;
+   if (!is_timing_event(ev)) {
+   if (ev.reset)
+   data->state = STATE_INACTIVE;
return 0;
}
 
diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/IR/ir-lirc-codec.c
index 20ac9a4..1d9c6b0 100644
--- a/drivers/media/IR/ir-lirc-codec.c
+++ b/drivers/media/IR/ir-lirc-codec.c
@@ -32,6 +32,7 @@
 static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
 {
struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+   struct lirc_codec *lirc = &ir_dev->raw->lirc;
int sample;
 
if (!(ir_dev->raw->enabled_protocols & IR_TYPE_LIRC))
@@ -40,21 +41,57 @@ static int ir_lirc_decode(struct input_dev *input_dev, 
struct ir_raw_event ev)
if (!ir_dev->raw->lirc.drv || !ir_dev->raw->lirc.drv->rbuf)
return -EINVAL;
 
-   if (IS_RESET(ev))
+   /* Packet start */
+   if (ev.reset)
return 0;
 
-   IR_dprintk(2, "LIRC data transfer started (%uus %s)\n",
-  TO_US(ev.duration), TO_STR(ev.pulse));
+   /* Carrier reports */
+   if (ev.carrier_report) {
+   sample = LIRC_FREQUENCY(ev.carrier);
+
+   /* Packet end */
+   } else if (ev.timeout) {
+

[PATCH 0/3] Remaining patches in my queue for IR

2010-10-16 Thread Maxim Levitsky
Hi,

This series is rebased on top of media_tree/staging/v2.6.37 only.
Really this time, sorry for cheating, last time :-)

The first patch like we agreed extends the raw packets.
It touches all drivers (except imon as it isn't a raw IR driver).
Code is compile tested with all drivers, 
and run tested with ENE and all receiver protocols
(except the streamzap rc5 flavour)
Since it also moves timeouts to lirc bridge, at least streazap driver
should have its timeout gap support removed. I am afraid to break the code
if I do so.

Other 2 patches are ENE specific, and don't touch anything else.

Please test other drivers.

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


[PATCH 3/3] IR: ene_ir: don't upload all settings on each TX packet.

2010-10-16 Thread Maxim Levitsky
This is just unnessesary, and now more logical

Also a lot of refactoring

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ene_ir.c |  474 +++-
 drivers/media/IR/ene_ir.h |6 +-
 2 files changed, 251 insertions(+), 229 deletions(-)

diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index 1962652..685db83 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -43,7 +43,7 @@
 #include "ene_ir.h"
 
 static int sample_period;
-static bool learning_mode;
+static bool learning_mode_force;
 static int debug;
 static bool txsim;
 
@@ -190,6 +190,145 @@ static int ene_hw_detect(struct ene_device *dev)
return 0;
 }
 
+/* Read properities of hw sample buffer */
+static void ene_rx_setup_hw_buffer(struct ene_device *dev)
+{
+   u16 tmp;
+
+   ene_rx_read_hw_pointer(dev);
+   dev->r_pointer = dev->w_pointer;
+
+   if (!dev->hw_extra_buffer) {
+   dev->buffer_len = ENE_FW_PACKET_SIZE * 2;
+   return;
+   }
+
+   tmp = ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER);
+   tmp |= ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER+1) << 8;
+   dev->extra_buf1_address = tmp;
+
+   dev->extra_buf1_len = ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER + 2);
+
+   tmp = ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER + 3);
+   tmp |= ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER + 4) << 8;
+   dev->extra_buf2_address = tmp;
+
+   dev->extra_buf2_len = ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER + 5);
+
+   dev->buffer_len = dev->extra_buf1_len + dev->extra_buf2_len + 8;
+
+   ene_notice("Hardware uses 2 extended buffers:");
+   ene_notice("  0x%04x - len : %d", dev->extra_buf1_address,
+   dev->extra_buf1_len);
+   ene_notice("  0x%04x - len : %d", dev->extra_buf2_address,
+   dev->extra_buf2_len);
+
+   ene_notice("Total buffer len = %d", dev->buffer_len);
+
+   if (dev->buffer_len > 64 || dev->buffer_len < 16)
+   goto error;
+
+   if (dev->extra_buf1_address > 0xFBFC ||
+   dev->extra_buf1_address < 0xEC00)
+   goto error;
+
+   if (dev->extra_buf2_address > 0xFBFC ||
+   dev->extra_buf2_address < 0xEC00)
+   goto error;
+
+   if (dev->r_pointer > dev->buffer_len)
+   goto error;
+
+   ene_set_reg_mask(dev, ENE_FW1, ENE_FW1_EXTRA_BUF_HND);
+   return;
+error:
+   ene_warn("Error validating extra buffers, device probably won't work");
+   dev->hw_extra_buffer = false;
+   ene_clear_reg_mask(dev, ENE_FW1, ENE_FW1_EXTRA_BUF_HND);
+}
+
+
+/* Restore the pointers to extra buffers - to make module reload work*/
+static void ene_rx_restore_hw_buffer(struct ene_device *dev)
+{
+   if (!dev->hw_extra_buffer)
+   return;
+
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 0,
+   dev->extra_buf1_address & 0xFF);
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 1,
+   dev->extra_buf1_address >> 8);
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 2, dev->extra_buf1_len);
+
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 3,
+   dev->extra_buf2_address & 0xFF);
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 4,
+   dev->extra_buf2_address >> 8);
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 5,
+   dev->extra_buf2_len);
+   ene_clear_reg_mask(dev, ENE_FW1, ENE_FW1_EXTRA_BUF_HND);
+}
+
+/* Read hardware write pointer */
+static void ene_rx_read_hw_pointer(struct ene_device *dev)
+{
+   if (dev->hw_extra_buffer)
+   dev->w_pointer = ene_read_reg(dev, ENE_FW_RX_POINTER);
+   else
+   dev->w_pointer = ene_read_reg(dev, ENE_FW2)
+   & ENE_FW2_BUF_WPTR ? 0 : ENE_FW_PACKET_SIZE;
+
+   dbg_verbose("RB: HW write pointer: %02x, driver read pointer: %02x",
+   dev->w_pointer, dev->r_pointer);
+}
+
+/* Gets address of next sample from HW ring buffer */
+static int ene_rx_get_sample_reg(struct ene_device *dev)
+{
+   int r_pointer;
+
+   if (dev->r_pointer == dev->w_pointer) {
+   dbg_verbose("RB: hit end, try update w_pointer");
+   ene_rx_read_hw_pointer(dev);
+   }
+
+   if (dev->r_pointer == dev->w_pointer) {
+   dbg_verbose("RB: end of data at %d", dev->r_pointer);
+   return 0;
+   }
+
+   dbg_verbose("RB: reading at offset %d", dev->r_pointer);
+   r_pointer = dev->r_pointe

[PATCH 2/3] IR: ene_ir: add support for carrier reports

2010-10-16 Thread Maxim Levitsky
Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ene_ir.c |   37 +
 1 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index 8639621..1962652 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -193,10 +193,11 @@ static int ene_hw_detect(struct ene_device *dev)
 /* Sense current received carrier */
 void ene_rx_sense_carrier(struct ene_device *dev)
 {
+   DEFINE_IR_RAW_EVENT(ev);
+
+   int carrier, duty_cycle;
int period = ene_read_reg(dev, ENE_CIRCAR_PRD);
int hperiod = ene_read_reg(dev, ENE_CIRCAR_HPRD);
-   int carrier, duty_cycle;
-
 
if (!(period & ENE_CIRCAR_PRD_VALID))
return;
@@ -209,13 +210,16 @@ void ene_rx_sense_carrier(struct ene_device *dev)
dbg("RX: hardware carrier period = %02x", period);
dbg("RX: hardware carrier pulse period = %02x", hperiod);
 
-
carrier = 200 / period;
duty_cycle = (hperiod * 100) / period;
dbg("RX: sensed carrier = %d Hz, duty cycle %d%%",
-   carrier, duty_cycle);
-
-   /* TODO: Send carrier & duty cycle to IR layer */
+   carrier, duty_cycle);
+   if (dev->carrier_detect_enabled) {
+   ev.carrier_report = true;
+   ev.carrier = carrier;
+   ev.duty_cycle = duty_cycle;
+   ir_raw_event_store(dev->idev, &ev);
+   }
 }
 
 /* this enables/disables the CIR RX engine */
@@ -724,7 +728,7 @@ static irqreturn_t ene_isr(int irq, void *data)
 
dbg_verbose("RX interrupt");
 
-   if (dev->carrier_detect_enabled || debug)
+   if (dev->hw_learning_and_tx_capable)
ene_rx_sense_carrier(dev);
 
/* On hardware that don't support extra buffer we need to trust
@@ -897,6 +901,23 @@ static int ene_set_learning_mode(void *data, int enable)
return 0;
 }
 
+static int ene_set_carrier_report(void *data, int enable)
+{
+   struct ene_device *dev = (struct ene_device *)data;
+   unsigned long flags;
+
+   if (enable == dev->carrier_detect_enabled)
+   return 0;
+
+   spin_lock_irqsave(&dev->hw_lock, flags);
+   dev->carrier_detect_enabled = enable;
+   ene_rx_disable(dev);
+   ene_rx_setup(dev);
+   ene_rx_enable(dev);
+   spin_unlock_irqrestore(&dev->hw_lock, flags);
+   return 0;
+}
+
 /* outside interface: enable or disable idle mode */
 static void ene_rx_set_idle(void *data, bool idle)
 {
@@ -1029,7 +1050,7 @@ static int ene_probe(struct pnp_dev *pnp_dev, const 
struct pnp_device_id *id)
ir_props->s_tx_mask = ene_set_tx_mask;
ir_props->s_tx_carrier = ene_set_tx_carrier;
ir_props->s_tx_duty_cycle = ene_set_tx_duty_cycle;
-   /* ir_props->s_carrier_report = ene_set_carrier_report; */
+   ir_props->s_carrier_report = ene_set_carrier_report;
}
 
ene_setup_hw_buffer(dev);
-- 
1.7.1

--
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


[PATCH 5/5] IR: ene_ir: don't upload all settings on each TX packet.

2010-10-16 Thread Maxim Levitsky
This is just unnessesary, and now more logical

Also lot of refactoring

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ene_ir.c |  474 +++-
 drivers/media/IR/ene_ir.h |6 +-
 2 files changed, 251 insertions(+), 229 deletions(-)

diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index 1962652..685db83 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -43,7 +43,7 @@
 #include "ene_ir.h"
 
 static int sample_period;
-static bool learning_mode;
+static bool learning_mode_force;
 static int debug;
 static bool txsim;
 
@@ -190,6 +190,145 @@ static int ene_hw_detect(struct ene_device *dev)
return 0;
 }
 
+/* Read properities of hw sample buffer */
+static void ene_rx_setup_hw_buffer(struct ene_device *dev)
+{
+   u16 tmp;
+
+   ene_rx_read_hw_pointer(dev);
+   dev->r_pointer = dev->w_pointer;
+
+   if (!dev->hw_extra_buffer) {
+   dev->buffer_len = ENE_FW_PACKET_SIZE * 2;
+   return;
+   }
+
+   tmp = ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER);
+   tmp |= ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER+1) << 8;
+   dev->extra_buf1_address = tmp;
+
+   dev->extra_buf1_len = ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER + 2);
+
+   tmp = ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER + 3);
+   tmp |= ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER + 4) << 8;
+   dev->extra_buf2_address = tmp;
+
+   dev->extra_buf2_len = ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER + 5);
+
+   dev->buffer_len = dev->extra_buf1_len + dev->extra_buf2_len + 8;
+
+   ene_notice("Hardware uses 2 extended buffers:");
+   ene_notice("  0x%04x - len : %d", dev->extra_buf1_address,
+   dev->extra_buf1_len);
+   ene_notice("  0x%04x - len : %d", dev->extra_buf2_address,
+   dev->extra_buf2_len);
+
+   ene_notice("Total buffer len = %d", dev->buffer_len);
+
+   if (dev->buffer_len > 64 || dev->buffer_len < 16)
+   goto error;
+
+   if (dev->extra_buf1_address > 0xFBFC ||
+   dev->extra_buf1_address < 0xEC00)
+   goto error;
+
+   if (dev->extra_buf2_address > 0xFBFC ||
+   dev->extra_buf2_address < 0xEC00)
+   goto error;
+
+   if (dev->r_pointer > dev->buffer_len)
+   goto error;
+
+   ene_set_reg_mask(dev, ENE_FW1, ENE_FW1_EXTRA_BUF_HND);
+   return;
+error:
+   ene_warn("Error validating extra buffers, device probably won't work");
+   dev->hw_extra_buffer = false;
+   ene_clear_reg_mask(dev, ENE_FW1, ENE_FW1_EXTRA_BUF_HND);
+}
+
+
+/* Restore the pointers to extra buffers - to make module reload work*/
+static void ene_rx_restore_hw_buffer(struct ene_device *dev)
+{
+   if (!dev->hw_extra_buffer)
+   return;
+
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 0,
+   dev->extra_buf1_address & 0xFF);
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 1,
+   dev->extra_buf1_address >> 8);
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 2, dev->extra_buf1_len);
+
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 3,
+   dev->extra_buf2_address & 0xFF);
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 4,
+   dev->extra_buf2_address >> 8);
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 5,
+   dev->extra_buf2_len);
+   ene_clear_reg_mask(dev, ENE_FW1, ENE_FW1_EXTRA_BUF_HND);
+}
+
+/* Read hardware write pointer */
+static void ene_rx_read_hw_pointer(struct ene_device *dev)
+{
+   if (dev->hw_extra_buffer)
+   dev->w_pointer = ene_read_reg(dev, ENE_FW_RX_POINTER);
+   else
+   dev->w_pointer = ene_read_reg(dev, ENE_FW2)
+   & ENE_FW2_BUF_WPTR ? 0 : ENE_FW_PACKET_SIZE;
+
+   dbg_verbose("RB: HW write pointer: %02x, driver read pointer: %02x",
+   dev->w_pointer, dev->r_pointer);
+}
+
+/* Gets address of next sample from HW ring buffer */
+static int ene_rx_get_sample_reg(struct ene_device *dev)
+{
+   int r_pointer;
+
+   if (dev->r_pointer == dev->w_pointer) {
+   dbg_verbose("RB: hit end, try update w_pointer");
+   ene_rx_read_hw_pointer(dev);
+   }
+
+   if (dev->r_pointer == dev->w_pointer) {
+   dbg_verbose("RB: end of data at %d", dev->r_pointer);
+   return 0;
+   }
+
+   dbg_verbose("RB: reading at offset %d", dev->r_pointer);
+   r_pointer = dev->r_pointe

Re: [PATCH 2/5] IR: extend ir_raw_event and do refactoring

2010-10-15 Thread Maxim Levitsky
On Sat, 2010-10-16 at 00:29 -0300, Mauro Carvalho Chehab wrote:
> Em 15-10-2010 13:06, Maxim Levitsky escreveu:
> > Add new event types for timeout & carrier report
> > Move timeout handling from ir_raw_event_store_with_filter to
> > ir-lirc-codec, where it is really needed.
> > Now lirc bridge ensures proper gap handling.
> > Extend lirc bridge for carrier & timeout reports
> > 
> > Note: all new ir_raw_event variables now should be initialized
> > like that: DEFINE_IR_RAW_EVENT(ev);
> > 
> > To clean an existing event, use init_ir_raw_event(&ev);
> > 
> > Signed-off-by: Maxim Levitsky 
> > Acked-by: Jarod Wilson 
> 
> 
> Applying patch 
> patches/lmml_257371_2_5_ir_extend_ir_raw_event_and_do_refactoring.patch
> patching file drivers/media/IR/ene_ir.c
> patching file drivers/media/IR/ir-core-priv.h
> Hunk #1 succeeded at 88 (offset 6 lines).
> Hunk #2 succeeded at 121 (offset 6 lines).
> patching file drivers/media/IR/ir-jvc-decoder.c
> patching file drivers/media/IR/ir-lirc-codec.c
> Hunk #3 FAILED at 139.
> Hunk #4 FAILED at 167.
> Hunk #7 succeeded at 330 (offset 3 lines).
> 2 out of 7 hunks FAILED -- rejects in file drivers/media/IR/ir-lirc-codec.c
> patching file drivers/media/IR/ir-nec-decoder.c
> patching file drivers/media/IR/ir-raw-event.c
> patching file drivers/media/IR/ir-rc5-decoder.c
> patching file drivers/media/IR/ir-rc6-decoder.c
> patching file drivers/media/IR/ir-sony-decoder.c
> patching file drivers/media/IR/mceusb.c
> patching file drivers/media/IR/streamzap.c
> Hunk #1 FAILED at 170.
> Hunk #2 FAILED at 215.
> Hunk #3 FAILED at 233.
> Hunk #4 succeeded at 373 (offset -139 lines).
> 3 out of 4 hunks FAILED -- rejects in file drivers/media/IR/streamzap.c
> patching file include/media/ir-core.h
> Hunk #3 succeeded at 165 (offset 1 line).
> Patch patches/lmml_257371_2_5_ir_extend_ir_raw_event_and_do_refactoring.patch 
> does not apply (enforce with -f)
> Patch didn't apply. Aborting
> 
> Too much fails for me... -EABORTING...
> 
> I won't apply this patch... there are two copies of it, and it has several 
> broken hunks.
> 
> 
> Please fix.

Not surprising as v4l tree got many changes and that patch touches many
places.

Will redo that really against the media_tree :-)
Sorry!

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 3/5] IR: ene_ir: few bugfixes

2010-10-15 Thread Maxim Levitsky
On Fri, 2010-10-15 at 16:02 -0400, Jarod Wilson wrote:
> On Fri, Oct 15, 2010 at 06:06:37PM +0200, Maxim Levitsky wrote:
> > This is a result of last round of debug with
> > Sami R .
> > 
> > Thank you Sami very much!
> > 
> > The biggest bug I fixed is that,
> > I was clobbering the CIRCFG register after it is setup
> > That wasn't a good idea really
> > 
> > And some small refactoring, etc.
> > 
> > Signed-off-by: Maxim Levitsky 
> > ---
> >  drivers/media/IR/ene_ir.c |   43 
> > ---
> >  1 files changed, 20 insertions(+), 23 deletions(-)
> > 
> > diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
> > index dc32509..8639621 100644
> > --- a/drivers/media/IR/ene_ir.c
> > +++ b/drivers/media/IR/ene_ir.c
> ...
> > @@ -282,6 +287,7 @@ static void ene_rx_setup(struct ene_device *dev)
> > ene_set_reg_mask(dev, ENE_CIRCFG, ENE_CIRCFG_CARR_DEMOD);
> >  
> > /* Enable carrier detection */
> > +   ene_write_reg(dev, ENE_CIRCAR_PULS, 0x63);
> 
> Looks sane, though I'd prefer to see symbolic bit names or some such thing
> here instead of 0x63. Not something to hold up the patch though.
> 
> Acked-by: Jarod Wilson 
> 
63 isn't a bitfileld, but rather two numbers.
3 is number of carrier pulses to skip, and 6 is number of carrier pulses
to average.

I have a note about that in header.

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


[PATCH 2/5] IR: extend ir_raw_event and do refactoring

2010-10-15 Thread Maxim Levitsky
Add new event types for timeout & carrier report
Move timeout handling from ir_raw_event_store_with_filter to
ir-lirc-codec, where it is really needed.
Now lirc bridge ensures proper gap handling.
Extend lirc bridge for carrier & timeout reports

Note: all new ir_raw_event variables now should be initialized
like that: DEFINE_IR_RAW_EVENT(ev);

To clean an existing event, use init_ir_raw_event(&ev);

Signed-off-by: Maxim Levitsky 
Acked-by: Jarod Wilson 
---
 drivers/media/IR/ene_ir.c  |4 +-
 drivers/media/IR/ir-core-priv.h|   13 -
 drivers/media/IR/ir-jvc-decoder.c  |5 +-
 drivers/media/IR/ir-lirc-codec.c   |  128 +---
 drivers/media/IR/ir-nec-decoder.c  |5 +-
 drivers/media/IR/ir-raw-event.c|   45 +
 drivers/media/IR/ir-rc5-decoder.c  |5 +-
 drivers/media/IR/ir-rc6-decoder.c  |5 +-
 drivers/media/IR/ir-sony-decoder.c |5 +-
 drivers/media/IR/mceusb.c  |3 +-
 drivers/media/IR/streamzap.c   |8 ++-
 include/media/ir-core.h|   40 ++--
 12 files changed, 176 insertions(+), 90 deletions(-)

diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index 7880d9c..dc32509 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -701,7 +701,7 @@ static irqreturn_t ene_isr(int irq, void *data)
unsigned long flags;
irqreturn_t retval = IRQ_NONE;
struct ene_device *dev = (struct ene_device *)data;
-   struct ir_raw_event ev;
+   DEFINE_IR_RAW_EVENT(ev);
 
spin_lock_irqsave(&dev->hw_lock, flags);
 
@@ -904,7 +904,7 @@ static int ene_set_learning_mode(void *data, int enable)
 }
 
 /* outside interface: enable or disable idle mode */
-static void ene_rx_set_idle(void *data, int idle)
+static void ene_rx_set_idle(void *data, bool idle)
 {
struct ene_device *dev = (struct ene_device *)data;
 
diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index 5d7e08f..2559e72 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -82,6 +82,12 @@ struct ir_raw_event_ctrl {
struct ir_input_dev *ir_dev;
struct lirc_driver *drv;
int carrier_low;
+
+   ktime_t gap_start;
+   u64 gap_duration;
+   bool gap;
+   bool send_timeout_reports;
+
} lirc;
 };
 
@@ -109,9 +115,14 @@ static inline void decrease_duration(struct ir_raw_event 
*ev, unsigned duration)
ev->duration -= duration;
 }
 
+/* Returns true if event is normal pulse/space event */
+static inline bool is_timing_event(struct ir_raw_event ev)
+{
+   return !ev.carrier_report && !ev.reset;
+}
+
 #define TO_US(duration)DIV_ROUND_CLOSEST((duration), 
1000)
 #define TO_STR(is_pulse)   ((is_pulse) ? "pulse" : "space")
-#define IS_RESET(ev)   (ev.duration == 0)
 /*
  * Routines from ir-sysfs.c - Meant to be called only internally inside
  * ir-core
diff --git a/drivers/media/IR/ir-jvc-decoder.c 
b/drivers/media/IR/ir-jvc-decoder.c
index 77a89c4..63dca6e 100644
--- a/drivers/media/IR/ir-jvc-decoder.c
+++ b/drivers/media/IR/ir-jvc-decoder.c
@@ -50,8 +50,9 @@ static int ir_jvc_decode(struct input_dev *input_dev, struct 
ir_raw_event ev)
if (!(ir_dev->raw->enabled_protocols & IR_TYPE_JVC))
return 0;
 
-   if (IS_RESET(ev)) {
-   data->state = STATE_INACTIVE;
+   if (!is_timing_event(ev)) {
+   if (ev.reset)
+   data->state = STATE_INACTIVE;
return 0;
}
 
diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/IR/ir-lirc-codec.c
index e63f757..9317be8 100644
--- a/drivers/media/IR/ir-lirc-codec.c
+++ b/drivers/media/IR/ir-lirc-codec.c
@@ -32,6 +32,7 @@
 static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
 {
struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+   struct lirc_codec *lirc = &ir_dev->raw->lirc;
int sample;
 
if (!(ir_dev->raw->enabled_protocols & IR_TYPE_LIRC))
@@ -40,21 +41,57 @@ static int ir_lirc_decode(struct input_dev *input_dev, 
struct ir_raw_event ev)
if (!ir_dev->raw->lirc.drv || !ir_dev->raw->lirc.drv->rbuf)
return -EINVAL;
 
-   if (IS_RESET(ev))
+   /* Packet start */
+   if (ev.reset)
return 0;
 
-   IR_dprintk(2, "LIRC data transfer started (%uus %s)\n",
-  TO_US(ev.duration), TO_STR(ev.pulse));
+   /* Carrier reports */
+   if (ev.carrier_report) {
+   sample = LIRC_FREQUENCY(ev.carrier);
+
+   /* Packet end */
+   } else if (ev.timeout) {
+
+   if (lirc->gap)
+   return 0;
+
+   lirc->gap_start = ktime_g

[PATCH 2/7] IR: make sure we register the input device when it is safe to do so.

2010-10-15 Thread Maxim Levitsky
As soon as input device is registered, it might be accessed (and it is)
This can trigger a hardware interrupt that can access
not yet initialized ir->raw, (by sending a sample)

This can be reproduced by holding down a remote button and reloading the module.
And this always crashes the systems where hardware decides to send an interrupt
right at the moment it is enabled.

Signed-off-by: Maxim Levitsky 
Acked-by: Jarod Wilson 
---
 drivers/media/IR/ir-core-priv.h |1 +
 drivers/media/IR/ir-keytable.c  |2 ++
 drivers/media/IR/ir-sysfs.c |   27 +--
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index 761e7f4..5d7e08f 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -116,6 +116,7 @@ static inline void decrease_duration(struct ir_raw_event 
*ev, unsigned duration)
  * Routines from ir-sysfs.c - Meant to be called only internally inside
  * ir-core
  */
+int ir_register_input(struct input_dev *input_dev);
 
 int ir_register_class(struct input_dev *input_dev);
 void ir_unregister_class(struct input_dev *input_dev);
diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
index a3f0af3..1997812 100644
--- a/drivers/media/IR/ir-keytable.c
+++ b/drivers/media/IR/ir-keytable.c
@@ -505,6 +505,8 @@ int __ir_input_register(struct input_dev *input_dev,
goto out_event;
}
 
+   rc = ir_register_input(input_dev);
+
IR_dprintk(1, "Registered input device on %s for %s remote%s.\n",
   driver_name, rc_tab->name,
   (ir_dev->props && ir_dev->props->driver_type == 
RC_DRIVER_IR_RAW) ?
diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c
index 46d4246..ada2ec6 100644
--- a/drivers/media/IR/ir-sysfs.c
+++ b/drivers/media/IR/ir-sysfs.c
@@ -256,8 +256,6 @@ static struct device_type rc_dev_type = {
  */
 int ir_register_class(struct input_dev *input_dev)
 {
-   int rc;
-   const char *path;
struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
int devno = find_first_zero_bit(&ir_core_dev_number,
IRRCV_NUM_DEVICES);
@@ -266,17 +264,28 @@ int ir_register_class(struct input_dev *input_dev)
return devno;
 
ir_dev->dev.type = &rc_dev_type;
+   ir_dev->devno = devno;
 
ir_dev->dev.class = &ir_input_class;
ir_dev->dev.parent = input_dev->dev.parent;
+   input_dev->dev.parent = &ir_dev->dev;
dev_set_name(&ir_dev->dev, "rc%d", devno);
dev_set_drvdata(&ir_dev->dev, ir_dev);
-   rc = device_register(&ir_dev->dev);
-   if (rc)
-   return rc;
+   return  device_register(&ir_dev->dev);
+};
+
+/**
+ * ir_register_input - registers ir input device with input subsystem
+ * @input_dev: the struct input_dev descriptor of the device
+ */
+
+int ir_register_input(struct input_dev *input_dev)
+{
+   struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+   int rc;
+   const char *path;
 
 
-   input_dev->dev.parent = &ir_dev->dev;
rc = input_register_device(input_dev);
if (rc < 0) {
device_del(&ir_dev->dev);
@@ -292,11 +301,9 @@ int ir_register_class(struct input_dev *input_dev)
path ? path : "N/A");
kfree(path);
 
-   ir_dev->devno = devno;
-   set_bit(devno, &ir_core_dev_number);
-
+   set_bit(ir_dev->devno, &ir_core_dev_number);
return 0;
-};
+}
 
 /**
  * ir_unregister_class() - removes the sysfs for sysfs for
-- 
1.7.1

--
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


[PATCH 1/5] IR: extend and sort the MCE keymap

2010-10-15 Thread Maxim Levitsky
Add new keys, found on:

Toshiba Qosmio F50-10q.
Toshiba Qosmio X300
Toshiba A500-141

Also sort the keytable by scancode number as that makes sense
and alows easily to add new keycodes.

Thanks to:
Sami R 
Alexander Skiba 
Jordi Pelegrin 

For reports and testing.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/keymaps/rc-rc6-mce.c |   88 +
 1 files changed, 45 insertions(+), 43 deletions(-)

diff --git a/drivers/media/IR/keymaps/rc-rc6-mce.c 
b/drivers/media/IR/keymaps/rc-rc6-mce.c
index 39557ad..1b7adab 100644
--- a/drivers/media/IR/keymaps/rc-rc6-mce.c
+++ b/drivers/media/IR/keymaps/rc-rc6-mce.c
@@ -12,76 +12,78 @@
 #include 
 
 static struct ir_scancode rc6_mce[] = {
-   { 0x800f0415, KEY_REWIND },
-   { 0x800f0414, KEY_FASTFORWARD },
-   { 0x800f041b, KEY_PREVIOUS },
-   { 0x800f041a, KEY_NEXT },
 
+   { 0x800f0400, KEY_NUMERIC_0 },
+   { 0x800f0401, KEY_NUMERIC_1 },
+   { 0x800f0402, KEY_NUMERIC_2 },
+   { 0x800f0403, KEY_NUMERIC_3 },
+   { 0x800f0404, KEY_NUMERIC_4 },
+   { 0x800f0405, KEY_NUMERIC_5 },
+   { 0x800f0406, KEY_NUMERIC_6 },
+   { 0x800f0407, KEY_NUMERIC_7 },
+   { 0x800f0408, KEY_NUMERIC_8 },
+   { 0x800f0409, KEY_NUMERIC_9 },
+
+   { 0x800f040a, KEY_DELETE },
+   { 0x800f040b, KEY_ENTER },
+   { 0x800f040c, KEY_POWER },
+   { 0x800f040d, KEY_PROG1 },  /* Windows MCE button */
+   { 0x800f040e, KEY_MUTE },
+   { 0x800f040f, KEY_INFO },
+
+   { 0x800f0410, KEY_VOLUMEUP },
+   { 0x800f0411, KEY_VOLUMEDOWN },
+   { 0x800f0412, KEY_CHANNELUP },
+   { 0x800f0413, KEY_CHANNELDOWN },
+
+   { 0x800f0414, KEY_FASTFORWARD },
+   { 0x800f0415, KEY_REWIND },
{ 0x800f0416, KEY_PLAY },
+   { 0x800f0417, KEY_RECORD },
{ 0x800f0418, KEY_PAUSE },
{ 0x800f046e, KEY_PLAYPAUSE },
{ 0x800f0419, KEY_STOP },
-   { 0x800f0417, KEY_RECORD },
+   { 0x800f041a, KEY_NEXT },
+   { 0x800f041b, KEY_PREVIOUS },
+   { 0x800f041c, KEY_NUMERIC_POUND },
+   { 0x800f041d, KEY_NUMERIC_STAR },
 
{ 0x800f041e, KEY_UP },
{ 0x800f041f, KEY_DOWN },
{ 0x800f0420, KEY_LEFT },
{ 0x800f0421, KEY_RIGHT },
 
-   { 0x800f040b, KEY_ENTER },
{ 0x800f0422, KEY_OK },
{ 0x800f0423, KEY_EXIT },
-   { 0x800f040a, KEY_DELETE },
+   { 0x800f0424, KEY_DVD },
+   { 0x800f0425, KEY_TUNER },  /* LiveTV */
+   { 0x800f0426, KEY_EPG },/* Guide */
+   { 0x800f0427, KEY_ZOOM },   /* Aspect */
 
-   { 0x800f040e, KEY_MUTE },
-   { 0x800f0410, KEY_VOLUMEUP },
-   { 0x800f0411, KEY_VOLUMEDOWN },
-   { 0x800f0412, KEY_CHANNELUP },
-   { 0x800f0413, KEY_CHANNELDOWN },
{ 0x800f043a, KEY_BRIGHTNESSUP },
-   { 0x800f0480, KEY_BRIGHTNESSDOWN },
-
-   { 0x800f0401, KEY_NUMERIC_1 },
-   { 0x800f0402, KEY_NUMERIC_2 },
-   { 0x800f0403, KEY_NUMERIC_3 },
-   { 0x800f0404, KEY_NUMERIC_4 },
-   { 0x800f0405, KEY_NUMERIC_5 },
-   { 0x800f0406, KEY_NUMERIC_6 },
-   { 0x800f0407, KEY_NUMERIC_7 },
-   { 0x800f0408, KEY_NUMERIC_8 },
-   { 0x800f0409, KEY_NUMERIC_9 },
-   { 0x800f0400, KEY_NUMERIC_0 },
-
-   { 0x800f041d, KEY_NUMERIC_STAR },
-   { 0x800f041c, KEY_NUMERIC_POUND },
 
{ 0x800f0446, KEY_TV },
-   { 0x800f0447, KEY_AUDIO }, /* My Music */
-   { 0x800f0448, KEY_PVR }, /* RecordedTV */
+   { 0x800f0447, KEY_AUDIO },  /* My Music */
+   { 0x800f0448, KEY_PVR },/* RecordedTV */
{ 0x800f0449, KEY_CAMERA },
{ 0x800f044a, KEY_VIDEO },
-   { 0x800f0424, KEY_DVD },
-   { 0x800f0425, KEY_TUNER }, /* LiveTV */
-   { 0x800f0450, KEY_RADIO },
-
{ 0x800f044c, KEY_LANGUAGE },
-   { 0x800f0427, KEY_ZOOM }, /* Aspect */
+   { 0x800f044d, KEY_TITLE },
+   { 0x800f044e, KEY_PRINT },  /* Print - HP OEM version of remote */
 
+   { 0x800f0450, KEY_RADIO },
+
+   { 0x800f045a, KEY_SUBTITLE },   /* Caption/Teletext */
{ 0x800f045b, KEY_RED },
{ 0x800f045c, KEY_GREEN },
{ 0x800f045d, KEY_YELLOW },
{ 0x800f045e, KEY_BLUE },
 
-   { 0x800f040f, KEY_INFO },
-   { 0x800f0426, KEY_EPG }, /* Guide */
-   { 0x800f045a, KEY_SUBTITLE }, /* Caption/Teletext */
-   { 0x800f044d, KEY_TITLE },
-
-   { 0x800f044e, KEY_PRINT }, /* Print - HP OEM version of remote */
-
-   { 0x800f040c, KEY_POWER },
-   { 0x800f040d, KEY_PROG1 }, /* Windows MCE button */
+   { 0x800f046e, KEY_PLAYPAUSE },
+   { 0x800f046f, KEY_MEDIA },  /* Start media application (NEW) */
 
+   { 0x800f0480, KEY_BRIGHTNESSDOWN },
+   { 0x800f0481, KEY_PLAYPAUSE },
 };
 
 static struct rc_keymap rc6_mce_map = {
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message

[PATCH 4/5] IR: ene_ir: add support for carrier reports

2010-10-15 Thread Maxim Levitsky
Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ene_ir.c |   37 +
 1 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index 8639621..1962652 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -193,10 +193,11 @@ static int ene_hw_detect(struct ene_device *dev)
 /* Sense current received carrier */
 void ene_rx_sense_carrier(struct ene_device *dev)
 {
+   DEFINE_IR_RAW_EVENT(ev);
+
+   int carrier, duty_cycle;
int period = ene_read_reg(dev, ENE_CIRCAR_PRD);
int hperiod = ene_read_reg(dev, ENE_CIRCAR_HPRD);
-   int carrier, duty_cycle;
-
 
if (!(period & ENE_CIRCAR_PRD_VALID))
return;
@@ -209,13 +210,16 @@ void ene_rx_sense_carrier(struct ene_device *dev)
dbg("RX: hardware carrier period = %02x", period);
dbg("RX: hardware carrier pulse period = %02x", hperiod);
 
-
carrier = 200 / period;
duty_cycle = (hperiod * 100) / period;
dbg("RX: sensed carrier = %d Hz, duty cycle %d%%",
-   carrier, duty_cycle);
-
-   /* TODO: Send carrier & duty cycle to IR layer */
+   carrier, duty_cycle);
+   if (dev->carrier_detect_enabled) {
+   ev.carrier_report = true;
+   ev.carrier = carrier;
+   ev.duty_cycle = duty_cycle;
+   ir_raw_event_store(dev->idev, &ev);
+   }
 }
 
 /* this enables/disables the CIR RX engine */
@@ -724,7 +728,7 @@ static irqreturn_t ene_isr(int irq, void *data)
 
dbg_verbose("RX interrupt");
 
-   if (dev->carrier_detect_enabled || debug)
+   if (dev->hw_learning_and_tx_capable)
ene_rx_sense_carrier(dev);
 
/* On hardware that don't support extra buffer we need to trust
@@ -897,6 +901,23 @@ static int ene_set_learning_mode(void *data, int enable)
return 0;
 }
 
+static int ene_set_carrier_report(void *data, int enable)
+{
+   struct ene_device *dev = (struct ene_device *)data;
+   unsigned long flags;
+
+   if (enable == dev->carrier_detect_enabled)
+   return 0;
+
+   spin_lock_irqsave(&dev->hw_lock, flags);
+   dev->carrier_detect_enabled = enable;
+   ene_rx_disable(dev);
+   ene_rx_setup(dev);
+   ene_rx_enable(dev);
+   spin_unlock_irqrestore(&dev->hw_lock, flags);
+   return 0;
+}
+
 /* outside interface: enable or disable idle mode */
 static void ene_rx_set_idle(void *data, bool idle)
 {
@@ -1029,7 +1050,7 @@ static int ene_probe(struct pnp_dev *pnp_dev, const 
struct pnp_device_id *id)
ir_props->s_tx_mask = ene_set_tx_mask;
ir_props->s_tx_carrier = ene_set_tx_carrier;
ir_props->s_tx_duty_cycle = ene_set_tx_duty_cycle;
-   /* ir_props->s_carrier_report = ene_set_carrier_report; */
+   ir_props->s_carrier_report = ene_set_carrier_report;
}
 
ene_setup_hw_buffer(dev);
-- 
1.7.1

--
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


[PATCH 3/5] IR: ene_ir: few bugfixes

2010-10-15 Thread Maxim Levitsky
This is a result of last round of debug with
Sami R .

Thank you Sami very much!

The biggest bug I fixed is that,
I was clobbering the CIRCFG register after it is setup
That wasn't a good idea really

And some small refactoring, etc.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ene_ir.c |   43 ---
 1 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index dc32509..8639621 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -156,11 +156,12 @@ static int ene_hw_detect(struct ene_device *dev)
 
ene_notice("Firmware regs: %02x %02x", fw_reg1, fw_reg2);
 
-   dev->hw_use_gpio_0a = fw_reg2 & ENE_FW2_GP0A;
-   dev->hw_learning_and_tx_capable = fw_reg2 & ENE_FW2_LEARNING;
-   dev->hw_extra_buffer = fw_reg1 & ENE_FW1_HAS_EXTRA_BUF;
-   dev->hw_fan_input = dev->hw_learning_and_tx_capable &&
-   (fw_reg2 & ENE_FW2_FAN_INPUT);
+   dev->hw_use_gpio_0a = !!(fw_reg2 & ENE_FW2_GP0A);
+   dev->hw_learning_and_tx_capable = !!(fw_reg2 & ENE_FW2_LEARNING);
+   dev->hw_extra_buffer = !!(fw_reg1 & ENE_FW1_HAS_EXTRA_BUF);
+
+   if (dev->hw_learning_and_tx_capable)
+   dev->hw_fan_input = !!(fw_reg2 & ENE_FW2_FAN_INPUT);
 
ene_notice("Hardware features:");
 
@@ -255,6 +256,8 @@ static void ene_rx_setup(struct ene_device *dev)
dev->carrier_detect_enabled;
int sample_period_adjust = 0;
 
+   /* This selects RLC input and clears CFG2 settings */
+   ene_write_reg(dev, ENE_CIRCFG2, 0x00);
 
/* set sample period*/
if (sample_period == ENE_DEFAULT_SAMPLE_PERIOD)
@@ -268,7 +271,9 @@ static void ene_rx_setup(struct ene_device *dev)
if (dev->hw_revision < ENE_HW_C)
goto select_timeout;
 
-   if (learning_mode && dev->hw_learning_and_tx_capable) {
+   if (learning_mode) {
+
+   WARN_ON(!dev->hw_learning_and_tx_capable);
 
/* Enable the opposite of the normal input
That means that if GPIO40 is normally used, use GPIO0A
@@ -282,6 +287,7 @@ static void ene_rx_setup(struct ene_device *dev)
ene_set_reg_mask(dev, ENE_CIRCFG, ENE_CIRCFG_CARR_DEMOD);
 
/* Enable carrier detection */
+   ene_write_reg(dev, ENE_CIRCAR_PULS, 0x63);
ene_set_clear_reg_mask(dev, ENE_CIRCFG2, 
ENE_CIRCFG2_CARR_DETECT,
dev->carrier_detect_enabled || debug);
} else {
@@ -343,19 +349,9 @@ static void ene_rx_enable(struct ene_device *dev)
ene_write_reg(dev, ENE_IRQ, reg_value);
}
 
-   if (dev->hw_revision >= ENE_HW_C)
-   ene_write_reg(dev, ENE_CIRCAR_PULS, 0x63);
-
-   /* Enable the inputs */
-   ene_write_reg(dev, ENE_CIRCFG2, 0x00);
-
-   if (dev->rx_fan_input_inuse) {
-   ene_enable_cir_engine(dev, false);
-   ene_enable_fan_input(dev, true);
-   } else {
-   ene_enable_cir_engine(dev, true);
-   ene_enable_fan_input(dev, false);
-   }
+   /* Enable inputs */
+   ene_enable_fan_input(dev, dev->rx_fan_input_inuse);
+   ene_enable_cir_engine(dev, !dev->rx_fan_input_inuse);
 
/* ack any pending irqs - just in case */
ene_irq_status(dev);
@@ -793,12 +789,10 @@ static void ene_setup_settings(struct ene_device *dev)
dev->tx_period = 32;
dev->tx_duty_cycle = 50; /*%*/
dev->transmitter_mask = 0x03;
-
-   dev->learning_enabled =
-   (learning_mode && dev->hw_learning_and_tx_capable);
+   dev->learning_enabled = learning_mode;
 
/* Set reasonable default timeout */
-   dev->props->timeout = MS_TO_NS(15000);
+   dev->props->timeout = MS_TO_NS(15);
 }
 
 /* outside interface: called on first open*/
@@ -1015,6 +1009,9 @@ static int ene_probe(struct pnp_dev *pnp_dev, const 
struct pnp_device_id *id)
ene_warn("Simulation of TX activated");
}
 
+   if (!dev->hw_learning_and_tx_capable)
+   learning_mode = false;
+
ir_props->driver_type = RC_DRIVER_IR_RAW;
ir_props->allowed_protos = IR_TYPE_ALL;
ir_props->priv = dev;
-- 
1.7.1

--
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


[PATCH 0/8 V7] Many fixes for in-kernel decoding and for the ENE driver

2010-10-15 Thread Maxim Levitsky
Hi,

This is a rebased version against the media_tree staging/v2.6.37

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


[PATCH 5/7] IR: extend ir_raw_event and do refactoring

2010-10-15 Thread Maxim Levitsky
Add new event types for timeout & carrier report
Move timeout handling from ir_raw_event_store_with_filter to
ir-lirc-codec, where it is really needed.
Now lirc bridge ensures proper gap handling.
Extend lirc bridge for carrier & timeout reports

Note: all new ir_raw_event variables now should be initialized
like that: DEFINE_IR_RAW_EVENT(ev);

To clean an existing event, use init_ir_raw_event(&ev);

Signed-off-by: Maxim Levitsky 
Acked-by: Jarod Wilson 
---
 drivers/media/IR/ene_ir.c  |4 +-
 drivers/media/IR/ir-core-priv.h|   13 -
 drivers/media/IR/ir-jvc-decoder.c  |5 +-
 drivers/media/IR/ir-lirc-codec.c   |  128 +---
 drivers/media/IR/ir-nec-decoder.c  |5 +-
 drivers/media/IR/ir-raw-event.c|   45 +
 drivers/media/IR/ir-rc5-decoder.c  |5 +-
 drivers/media/IR/ir-rc6-decoder.c  |5 +-
 drivers/media/IR/ir-sony-decoder.c |5 +-
 drivers/media/IR/mceusb.c  |3 +-
 drivers/media/IR/streamzap.c   |8 ++-
 include/media/ir-core.h|   40 ++--
 12 files changed, 176 insertions(+), 90 deletions(-)

diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index 9f9afe7..8639621 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -697,7 +697,7 @@ static irqreturn_t ene_isr(int irq, void *data)
unsigned long flags;
irqreturn_t retval = IRQ_NONE;
struct ene_device *dev = (struct ene_device *)data;
-   struct ir_raw_event ev;
+   DEFINE_IR_RAW_EVENT(ev);
 
spin_lock_irqsave(&dev->hw_lock, flags);
 
@@ -898,7 +898,7 @@ static int ene_set_learning_mode(void *data, int enable)
 }
 
 /* outside interface: enable or disable idle mode */
-static void ene_rx_set_idle(void *data, int idle)
+static void ene_rx_set_idle(void *data, bool idle)
 {
struct ene_device *dev = (struct ene_device *)data;
 
diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index 5d7e08f..2559e72 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -82,6 +82,12 @@ struct ir_raw_event_ctrl {
struct ir_input_dev *ir_dev;
struct lirc_driver *drv;
int carrier_low;
+
+   ktime_t gap_start;
+   u64 gap_duration;
+   bool gap;
+   bool send_timeout_reports;
+
} lirc;
 };
 
@@ -109,9 +115,14 @@ static inline void decrease_duration(struct ir_raw_event 
*ev, unsigned duration)
ev->duration -= duration;
 }
 
+/* Returns true if event is normal pulse/space event */
+static inline bool is_timing_event(struct ir_raw_event ev)
+{
+   return !ev.carrier_report && !ev.reset;
+}
+
 #define TO_US(duration)DIV_ROUND_CLOSEST((duration), 
1000)
 #define TO_STR(is_pulse)   ((is_pulse) ? "pulse" : "space")
-#define IS_RESET(ev)   (ev.duration == 0)
 /*
  * Routines from ir-sysfs.c - Meant to be called only internally inside
  * ir-core
diff --git a/drivers/media/IR/ir-jvc-decoder.c 
b/drivers/media/IR/ir-jvc-decoder.c
index 77a89c4..63dca6e 100644
--- a/drivers/media/IR/ir-jvc-decoder.c
+++ b/drivers/media/IR/ir-jvc-decoder.c
@@ -50,8 +50,9 @@ static int ir_jvc_decode(struct input_dev *input_dev, struct 
ir_raw_event ev)
if (!(ir_dev->raw->enabled_protocols & IR_TYPE_JVC))
return 0;
 
-   if (IS_RESET(ev)) {
-   data->state = STATE_INACTIVE;
+   if (!is_timing_event(ev)) {
+   if (ev.reset)
+   data->state = STATE_INACTIVE;
return 0;
}
 
diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/IR/ir-lirc-codec.c
index e63f757..9317be8 100644
--- a/drivers/media/IR/ir-lirc-codec.c
+++ b/drivers/media/IR/ir-lirc-codec.c
@@ -32,6 +32,7 @@
 static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
 {
struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+   struct lirc_codec *lirc = &ir_dev->raw->lirc;
int sample;
 
if (!(ir_dev->raw->enabled_protocols & IR_TYPE_LIRC))
@@ -40,21 +41,57 @@ static int ir_lirc_decode(struct input_dev *input_dev, 
struct ir_raw_event ev)
if (!ir_dev->raw->lirc.drv || !ir_dev->raw->lirc.drv->rbuf)
return -EINVAL;
 
-   if (IS_RESET(ev))
+   /* Packet start */
+   if (ev.reset)
return 0;
 
-   IR_dprintk(2, "LIRC data transfer started (%uus %s)\n",
-  TO_US(ev.duration), TO_STR(ev.pulse));
+   /* Carrier reports */
+   if (ev.carrier_report) {
+   sample = LIRC_FREQUENCY(ev.carrier);
+
+   /* Packet end */
+   } else if (ev.timeout) {
+
+   if (lirc->gap)
+   return 0;
+
+   lirc->gap_start = ktime_g

[PATCH 6/7] IR: ene_ir: add support for carrier reports

2010-10-15 Thread Maxim Levitsky
Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ene_ir.c |   37 +
 1 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index 8639621..1962652 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -193,10 +193,11 @@ static int ene_hw_detect(struct ene_device *dev)
 /* Sense current received carrier */
 void ene_rx_sense_carrier(struct ene_device *dev)
 {
+   DEFINE_IR_RAW_EVENT(ev);
+
+   int carrier, duty_cycle;
int period = ene_read_reg(dev, ENE_CIRCAR_PRD);
int hperiod = ene_read_reg(dev, ENE_CIRCAR_HPRD);
-   int carrier, duty_cycle;
-
 
if (!(period & ENE_CIRCAR_PRD_VALID))
return;
@@ -209,13 +210,16 @@ void ene_rx_sense_carrier(struct ene_device *dev)
dbg("RX: hardware carrier period = %02x", period);
dbg("RX: hardware carrier pulse period = %02x", hperiod);
 
-
carrier = 200 / period;
duty_cycle = (hperiod * 100) / period;
dbg("RX: sensed carrier = %d Hz, duty cycle %d%%",
-   carrier, duty_cycle);
-
-   /* TODO: Send carrier & duty cycle to IR layer */
+   carrier, duty_cycle);
+   if (dev->carrier_detect_enabled) {
+   ev.carrier_report = true;
+   ev.carrier = carrier;
+   ev.duty_cycle = duty_cycle;
+   ir_raw_event_store(dev->idev, &ev);
+   }
 }
 
 /* this enables/disables the CIR RX engine */
@@ -724,7 +728,7 @@ static irqreturn_t ene_isr(int irq, void *data)
 
dbg_verbose("RX interrupt");
 
-   if (dev->carrier_detect_enabled || debug)
+   if (dev->hw_learning_and_tx_capable)
ene_rx_sense_carrier(dev);
 
/* On hardware that don't support extra buffer we need to trust
@@ -897,6 +901,23 @@ static int ene_set_learning_mode(void *data, int enable)
return 0;
 }
 
+static int ene_set_carrier_report(void *data, int enable)
+{
+   struct ene_device *dev = (struct ene_device *)data;
+   unsigned long flags;
+
+   if (enable == dev->carrier_detect_enabled)
+   return 0;
+
+   spin_lock_irqsave(&dev->hw_lock, flags);
+   dev->carrier_detect_enabled = enable;
+   ene_rx_disable(dev);
+   ene_rx_setup(dev);
+   ene_rx_enable(dev);
+   spin_unlock_irqrestore(&dev->hw_lock, flags);
+   return 0;
+}
+
 /* outside interface: enable or disable idle mode */
 static void ene_rx_set_idle(void *data, bool idle)
 {
@@ -1029,7 +1050,7 @@ static int ene_probe(struct pnp_dev *pnp_dev, const 
struct pnp_device_id *id)
ir_props->s_tx_mask = ene_set_tx_mask;
ir_props->s_tx_carrier = ene_set_tx_carrier;
ir_props->s_tx_duty_cycle = ene_set_tx_duty_cycle;
-   /* ir_props->s_carrier_report = ene_set_carrier_report; */
+   ir_props->s_carrier_report = ene_set_carrier_report;
}
 
ene_setup_hw_buffer(dev);
-- 
1.7.1

--
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


[PATCH 1/7] IR: plug races in IR raw thread.

2010-10-15 Thread Maxim Levitsky
Unfortunelly (my fault) the kernel thread that now handles IR processing
has classical races in regard to wakeup and stop.
This patch hopefully closes them all.
Tested with module reload running in a loop, while receiver is blasted
with IR data for 10 minutes.

Signed-off-by: Maxim Levitsky 
Acked-by: Jarod Wilson 
---
 drivers/media/IR/ir-core-priv.h |2 ++
 drivers/media/IR/ir-raw-event.c |   34 +-
 2 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index a85a8c7..761e7f4 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -17,6 +17,7 @@
 #define _IR_RAW_EVENT
 
 #include 
+#include 
 #include 
 
 struct ir_raw_handler {
@@ -33,6 +34,7 @@ struct ir_raw_handler {
 struct ir_raw_event_ctrl {
struct list_headlist;   /* to keep track of raw 
clients */
struct task_struct  *thread;
+   spinlock_t  lock;
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 */
diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
index 8e0e1b1..119b567 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/IR/ir-raw-event.c
@@ -39,22 +39,34 @@ static int ir_raw_event_thread(void *data)
struct ir_raw_event ev;
struct ir_raw_handler *handler;
struct ir_raw_event_ctrl *raw = (struct ir_raw_event_ctrl *)data;
+   int retval;
 
while (!kthread_should_stop()) {
-   try_to_freeze();
 
-   mutex_lock(&ir_raw_handler_lock);
+   spin_lock_irq(&raw->lock);
+   retval = kfifo_out(&raw->kfifo, &ev, sizeof(ev));
+
+   if (!retval) {
+   set_current_state(TASK_INTERRUPTIBLE);
 
-   while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) {
-   list_for_each_entry(handler, &ir_raw_handler_list, list)
-   handler->decode(raw->input_dev, ev);
-   raw->prev_ev = ev;
+   if (kthread_should_stop())
+   set_current_state(TASK_RUNNING);
+
+   spin_unlock_irq(&raw->lock);
+   schedule();
+   continue;
}
 
-   mutex_unlock(&ir_raw_handler_lock);
+   spin_unlock_irq(&raw->lock);
 
-   set_current_state(TASK_INTERRUPTIBLE);
-   schedule();
+
+   BUG_ON(retval != sizeof(ev));
+
+   mutex_lock(&ir_raw_handler_lock);
+   list_for_each_entry(handler, &ir_raw_handler_list, list)
+   handler->decode(raw->input_dev, ev);
+   raw->prev_ev = ev;
+   mutex_unlock(&ir_raw_handler_lock);
}
 
return 0;
@@ -232,11 +244,14 @@ EXPORT_SYMBOL_GPL(ir_raw_event_set_idle);
 void ir_raw_event_handle(struct input_dev *input_dev)
 {
struct ir_input_dev *ir = input_get_drvdata(input_dev);
+   unsigned long flags;
 
if (!ir->raw)
return;
 
+   spin_lock_irqsave(&ir->raw->lock, flags);
wake_up_process(ir->raw->thread);
+   spin_unlock_irqrestore(&ir->raw->lock, flags);
 }
 EXPORT_SYMBOL_GPL(ir_raw_event_handle);
 
@@ -275,6 +290,7 @@ int ir_raw_event_register(struct input_dev *input_dev)
return rc;
}
 
+   spin_lock_init(&ir->raw->lock);
ir->raw->thread = kthread_run(ir_raw_event_thread, ir->raw,
"rc%u",  (unsigned int)ir->devno);
 
-- 
1.7.1

--
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


[PATCH 7/7] IR: ene_ir: don't upload all settings on each TX packet.

2010-10-15 Thread Maxim Levitsky
This is just unnessesary, and now more logical

Also lot of refactoring

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ene_ir.c |  474 +++-
 drivers/media/IR/ene_ir.h |6 +-
 2 files changed, 251 insertions(+), 229 deletions(-)

diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index 1962652..685db83 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -43,7 +43,7 @@
 #include "ene_ir.h"
 
 static int sample_period;
-static bool learning_mode;
+static bool learning_mode_force;
 static int debug;
 static bool txsim;
 
@@ -190,6 +190,145 @@ static int ene_hw_detect(struct ene_device *dev)
return 0;
 }
 
+/* Read properities of hw sample buffer */
+static void ene_rx_setup_hw_buffer(struct ene_device *dev)
+{
+   u16 tmp;
+
+   ene_rx_read_hw_pointer(dev);
+   dev->r_pointer = dev->w_pointer;
+
+   if (!dev->hw_extra_buffer) {
+   dev->buffer_len = ENE_FW_PACKET_SIZE * 2;
+   return;
+   }
+
+   tmp = ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER);
+   tmp |= ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER+1) << 8;
+   dev->extra_buf1_address = tmp;
+
+   dev->extra_buf1_len = ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER + 2);
+
+   tmp = ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER + 3);
+   tmp |= ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER + 4) << 8;
+   dev->extra_buf2_address = tmp;
+
+   dev->extra_buf2_len = ene_read_reg(dev, ENE_FW_SAMPLE_BUFFER + 5);
+
+   dev->buffer_len = dev->extra_buf1_len + dev->extra_buf2_len + 8;
+
+   ene_notice("Hardware uses 2 extended buffers:");
+   ene_notice("  0x%04x - len : %d", dev->extra_buf1_address,
+   dev->extra_buf1_len);
+   ene_notice("  0x%04x - len : %d", dev->extra_buf2_address,
+   dev->extra_buf2_len);
+
+   ene_notice("Total buffer len = %d", dev->buffer_len);
+
+   if (dev->buffer_len > 64 || dev->buffer_len < 16)
+   goto error;
+
+   if (dev->extra_buf1_address > 0xFBFC ||
+   dev->extra_buf1_address < 0xEC00)
+   goto error;
+
+   if (dev->extra_buf2_address > 0xFBFC ||
+   dev->extra_buf2_address < 0xEC00)
+   goto error;
+
+   if (dev->r_pointer > dev->buffer_len)
+   goto error;
+
+   ene_set_reg_mask(dev, ENE_FW1, ENE_FW1_EXTRA_BUF_HND);
+   return;
+error:
+   ene_warn("Error validating extra buffers, device probably won't work");
+   dev->hw_extra_buffer = false;
+   ene_clear_reg_mask(dev, ENE_FW1, ENE_FW1_EXTRA_BUF_HND);
+}
+
+
+/* Restore the pointers to extra buffers - to make module reload work*/
+static void ene_rx_restore_hw_buffer(struct ene_device *dev)
+{
+   if (!dev->hw_extra_buffer)
+   return;
+
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 0,
+   dev->extra_buf1_address & 0xFF);
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 1,
+   dev->extra_buf1_address >> 8);
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 2, dev->extra_buf1_len);
+
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 3,
+   dev->extra_buf2_address & 0xFF);
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 4,
+   dev->extra_buf2_address >> 8);
+   ene_write_reg(dev, ENE_FW_SAMPLE_BUFFER + 5,
+   dev->extra_buf2_len);
+   ene_clear_reg_mask(dev, ENE_FW1, ENE_FW1_EXTRA_BUF_HND);
+}
+
+/* Read hardware write pointer */
+static void ene_rx_read_hw_pointer(struct ene_device *dev)
+{
+   if (dev->hw_extra_buffer)
+   dev->w_pointer = ene_read_reg(dev, ENE_FW_RX_POINTER);
+   else
+   dev->w_pointer = ene_read_reg(dev, ENE_FW2)
+   & ENE_FW2_BUF_WPTR ? 0 : ENE_FW_PACKET_SIZE;
+
+   dbg_verbose("RB: HW write pointer: %02x, driver read pointer: %02x",
+   dev->w_pointer, dev->r_pointer);
+}
+
+/* Gets address of next sample from HW ring buffer */
+static int ene_rx_get_sample_reg(struct ene_device *dev)
+{
+   int r_pointer;
+
+   if (dev->r_pointer == dev->w_pointer) {
+   dbg_verbose("RB: hit end, try update w_pointer");
+   ene_rx_read_hw_pointer(dev);
+   }
+
+   if (dev->r_pointer == dev->w_pointer) {
+   dbg_verbose("RB: end of data at %d", dev->r_pointer);
+   return 0;
+   }
+
+   dbg_verbose("RB: reading at offset %d", dev->r_pointer);
+   r_pointer = dev->r_pointe

[PATCH 3/7] IR: extend an sort the MCE keymap

2010-10-15 Thread Maxim Levitsky
Add new keys, found on:

Toshiba Qosmio F50-10q.
Toshiba Qosmio X300
Toshiba A500-141

Also sort the keytable by scancode number as that makes sense
and alows easily to add new keycodes.

Thanks to:
Sami R 
Alexander Skiba 
Jordi Pelegrin 

For reports and testing.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/keymaps/rc-rc6-mce.c |   88 +
 1 files changed, 45 insertions(+), 43 deletions(-)

diff --git a/drivers/media/IR/keymaps/rc-rc6-mce.c 
b/drivers/media/IR/keymaps/rc-rc6-mce.c
index 39557ad..1b7adab 100644
--- a/drivers/media/IR/keymaps/rc-rc6-mce.c
+++ b/drivers/media/IR/keymaps/rc-rc6-mce.c
@@ -12,76 +12,78 @@
 #include 
 
 static struct ir_scancode rc6_mce[] = {
-   { 0x800f0415, KEY_REWIND },
-   { 0x800f0414, KEY_FASTFORWARD },
-   { 0x800f041b, KEY_PREVIOUS },
-   { 0x800f041a, KEY_NEXT },
 
+   { 0x800f0400, KEY_NUMERIC_0 },
+   { 0x800f0401, KEY_NUMERIC_1 },
+   { 0x800f0402, KEY_NUMERIC_2 },
+   { 0x800f0403, KEY_NUMERIC_3 },
+   { 0x800f0404, KEY_NUMERIC_4 },
+   { 0x800f0405, KEY_NUMERIC_5 },
+   { 0x800f0406, KEY_NUMERIC_6 },
+   { 0x800f0407, KEY_NUMERIC_7 },
+   { 0x800f0408, KEY_NUMERIC_8 },
+   { 0x800f0409, KEY_NUMERIC_9 },
+
+   { 0x800f040a, KEY_DELETE },
+   { 0x800f040b, KEY_ENTER },
+   { 0x800f040c, KEY_POWER },
+   { 0x800f040d, KEY_PROG1 },  /* Windows MCE button */
+   { 0x800f040e, KEY_MUTE },
+   { 0x800f040f, KEY_INFO },
+
+   { 0x800f0410, KEY_VOLUMEUP },
+   { 0x800f0411, KEY_VOLUMEDOWN },
+   { 0x800f0412, KEY_CHANNELUP },
+   { 0x800f0413, KEY_CHANNELDOWN },
+
+   { 0x800f0414, KEY_FASTFORWARD },
+   { 0x800f0415, KEY_REWIND },
{ 0x800f0416, KEY_PLAY },
+   { 0x800f0417, KEY_RECORD },
{ 0x800f0418, KEY_PAUSE },
{ 0x800f046e, KEY_PLAYPAUSE },
{ 0x800f0419, KEY_STOP },
-   { 0x800f0417, KEY_RECORD },
+   { 0x800f041a, KEY_NEXT },
+   { 0x800f041b, KEY_PREVIOUS },
+   { 0x800f041c, KEY_NUMERIC_POUND },
+   { 0x800f041d, KEY_NUMERIC_STAR },
 
{ 0x800f041e, KEY_UP },
{ 0x800f041f, KEY_DOWN },
{ 0x800f0420, KEY_LEFT },
{ 0x800f0421, KEY_RIGHT },
 
-   { 0x800f040b, KEY_ENTER },
{ 0x800f0422, KEY_OK },
{ 0x800f0423, KEY_EXIT },
-   { 0x800f040a, KEY_DELETE },
+   { 0x800f0424, KEY_DVD },
+   { 0x800f0425, KEY_TUNER },  /* LiveTV */
+   { 0x800f0426, KEY_EPG },/* Guide */
+   { 0x800f0427, KEY_ZOOM },   /* Aspect */
 
-   { 0x800f040e, KEY_MUTE },
-   { 0x800f0410, KEY_VOLUMEUP },
-   { 0x800f0411, KEY_VOLUMEDOWN },
-   { 0x800f0412, KEY_CHANNELUP },
-   { 0x800f0413, KEY_CHANNELDOWN },
{ 0x800f043a, KEY_BRIGHTNESSUP },
-   { 0x800f0480, KEY_BRIGHTNESSDOWN },
-
-   { 0x800f0401, KEY_NUMERIC_1 },
-   { 0x800f0402, KEY_NUMERIC_2 },
-   { 0x800f0403, KEY_NUMERIC_3 },
-   { 0x800f0404, KEY_NUMERIC_4 },
-   { 0x800f0405, KEY_NUMERIC_5 },
-   { 0x800f0406, KEY_NUMERIC_6 },
-   { 0x800f0407, KEY_NUMERIC_7 },
-   { 0x800f0408, KEY_NUMERIC_8 },
-   { 0x800f0409, KEY_NUMERIC_9 },
-   { 0x800f0400, KEY_NUMERIC_0 },
-
-   { 0x800f041d, KEY_NUMERIC_STAR },
-   { 0x800f041c, KEY_NUMERIC_POUND },
 
{ 0x800f0446, KEY_TV },
-   { 0x800f0447, KEY_AUDIO }, /* My Music */
-   { 0x800f0448, KEY_PVR }, /* RecordedTV */
+   { 0x800f0447, KEY_AUDIO },  /* My Music */
+   { 0x800f0448, KEY_PVR },/* RecordedTV */
{ 0x800f0449, KEY_CAMERA },
{ 0x800f044a, KEY_VIDEO },
-   { 0x800f0424, KEY_DVD },
-   { 0x800f0425, KEY_TUNER }, /* LiveTV */
-   { 0x800f0450, KEY_RADIO },
-
{ 0x800f044c, KEY_LANGUAGE },
-   { 0x800f0427, KEY_ZOOM }, /* Aspect */
+   { 0x800f044d, KEY_TITLE },
+   { 0x800f044e, KEY_PRINT },  /* Print - HP OEM version of remote */
 
+   { 0x800f0450, KEY_RADIO },
+
+   { 0x800f045a, KEY_SUBTITLE },   /* Caption/Teletext */
{ 0x800f045b, KEY_RED },
{ 0x800f045c, KEY_GREEN },
{ 0x800f045d, KEY_YELLOW },
{ 0x800f045e, KEY_BLUE },
 
-   { 0x800f040f, KEY_INFO },
-   { 0x800f0426, KEY_EPG }, /* Guide */
-   { 0x800f045a, KEY_SUBTITLE }, /* Caption/Teletext */
-   { 0x800f044d, KEY_TITLE },
-
-   { 0x800f044e, KEY_PRINT }, /* Print - HP OEM version of remote */
-
-   { 0x800f040c, KEY_POWER },
-   { 0x800f040d, KEY_PROG1 }, /* Windows MCE button */
+   { 0x800f046e, KEY_PLAYPAUSE },
+   { 0x800f046f, KEY_MEDIA },  /* Start media application (NEW) */
 
+   { 0x800f0480, KEY_BRIGHTNESSDOWN },
+   { 0x800f0481, KEY_PLAYPAUSE },
 };
 
 static struct rc_keymap rc6_mce_map = {
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message

Re: [PATCH 0/8 V5] Many fixes for in-kernel decoding and for the ENE driver

2010-10-13 Thread Maxim Levitsky
On Tue, 2010-09-07 at 00:26 +0300, Maxim Levitsky wrote:
> Hi,
> 
> Here is full overview of my patches:
> 
> Patch #1 fixes races in ir thread.
> It fixes the case when ktherad_stop waits forever for the thread.
> This happens on module unload and therefore it never finishes.
> Sorry for introducing this bug.
> 
> Patch #2, fixes a crash on my module load.
> It happens because ir core initializes the input device a bit early,
> therefore it could be accessed while still not set up.
> 
> Patch #3 fixes a small typo in lirc code that makes it impossible to use tx 
> duty cycle setting.
> 
> Patch #4 fixes a problem seen on my system that results in stuck down forever 
> key.
> 
> Patch #5 adds few keys to MCE keymap that were found on laptop of an user I 
> tested this driver with
> 
> Patch #6, is a combined update ti my driver. It contains lot of refactoring 
> thanks to docs I have now,
> and lot of fixes, and supports latest version of firmware (and I have 4 users 
> asking for that)
> It is quite huge, but it would be a tedios job to break it up. This can't 
> introduce regressions
> because the ene_ir was never released. In addition to that it was tested by 
> me and another two users.
> 
> Patch #7 the really only patch that touches drivers I don't have does touch 
> the ir-core.
> It is quite small, and it adds a proper solution to dilema about what to do 
> with huge space between keypresses.
> Now this space is just truncated by the driver with timeout flag.
> The lirc codec then ensures that right sample is send to the lircd.
> Please review and test it.
> 
> Patch #8 is very simple. It just builds on top of patch #7 and adds carrier 
> reports to ene driver.
> 

Any update?
Should I resent these (didn't change anything I think).
What about other work that conflicts with this?
What are the plans for (very close) merge window?

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 5/8] IR: extend MCE keymap.

2010-09-10 Thread Maxim Levitsky
On Thu, 2010-09-09 at 21:37 -0400, Jarod Wilson wrote: 
> On Thu, Sep 9, 2010 at 8:40 PM, Maxim Levitsky  
> wrote:
> > On Wed, 2010-09-08 at 10:47 -0400, Jarod Wilson wrote:
> >> On Mon, Sep 6, 2010 at 5:26 PM, Maxim Levitsky  
> >> wrote:
> >> > These keys are found on remote bundled with
> >> > Toshiba Qosmio F50-10q.
> >> >
> >> > Found and tested by, Sami R 
> >> >
> >> > Signed-off-by: Maxim Levitsky 
> >> > ---
> >> >  drivers/media/IR/keymaps/rc-rc6-mce.c |3 +++
> >> >  1 files changed, 3 insertions(+), 0 deletions(-)
> >
> > Tommorow I will resend that patch with even more scancodes.
> 
> Saw the discussion on irc. Feel your pain big-time on the X server
> limitation on keycodes. Its put a big damper on efforts to add native
> support to mythtv. Peter Hutterer's libXi2 cookbook tutorials talk a
> good game about how libXi2 supports 32-bit keycodes, but neglects to
> mention that the X server still gobbles up anything above 248 or 255
> or whatever it is, and remedying that is no small task. :(
> 
> I think for mythtv, we're going to end up having a daemon process with
> elevated privs that reads directly from input devices to get around
> this annoyance, until such time as the annoyance is gone.


Btw, indeed Xi2 still doesn't pass > 248 keycodes, just tested that with
-git versions of X stack from about 2 months ago.
However this can be fixed relatively easily.
Maybe even I could do that.

The big problem is however about ability to map extended keycodes to
actions, thing that should be provided by XKB2, which we will see
probably when DNF is released on Phantom console...
Also this will need lots of changes in toolkits.
Thats the problem I don't have resources to fix.

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 0/8 V5] Many fixes for in-kernel decoding and for the ENE driver

2010-09-10 Thread Maxim Levitsky
On Thu, 2010-09-09 at 22:01 -0400, Jarod Wilson wrote: 
> On Thu, Sep 09, 2010 at 12:34:27AM -0400, Jarod Wilson wrote:
> ...
> > >> For now, I've applied patches 3, 4 and 5, as it is nice to have Jarod's 
> > >> review also.
> > >
> > > I've finally got them all applied atop current media_tree staging/v2.6.37,
> > > though none of the streamzap bits in patch 7 are applicable any longer.
> > > Will try to get through looking and commenting (and testing) of the rest
> > > of them tonight.
> > 
> > Also had to make a minor addition to the rc5-sz decoder (same change
> > as in the other decoders). Almost have all the requisite test kernels
> > for David's, Maxim's and Dmitry's patchsets built and installed, wish
> > my laptop was faster... Probably would have been faster to use a lab
> > box and copy data over. Oh well. So functional testing to hopefully
> > commence tomorrow morning.
> 
> Wuff. None of the three builds is at all stable on my laptop, but I can't
> actually point the finger at any of the three patchsets, since I'm getting
> spontaneous lockups doing nothing at all before even plugging in a
> receiver. I did however get occasional periods of a non-panicking (not
> starting X seems to help a lot). Initial results:
> 

Btw, my printk blackbox patch could help you a lot.
I can't count how many times it helped me.
I just enable softlockup, hardlockup, and nmi watchdog, and let system
panic on oopses, and reboot. Or if you have hardware reboot button, you
can just use it. The point is that most BIOSES don't clear the ram, and
I take advantage of that.

Recently in an attempt to make it reserve only small portion of memory
(before I would use mem=) I also made this work out of box.

After a reboot, to get crash dmesg, just do
sudo cat /sys/kernel/debug/printk/crash_dmesg | strings

Note that kernel contains now a ramoops module that does similar things.
It doesn't reserve the memory automatically, and (this is the reason I
still don't use it) is only called by kernel to save oopses/panicks.
It should be enough though too, but my patch actually places the printk
buffer itself in the fixed area in the ram.


Best regards,
Maxim Levitsky
commit 8f1c423046c22dad6aaeca04bfcb0ab301843c36
Author: Maxim Levitsky 
Date:   Sat Jul 31 13:43:03 2010 +0300

printk: Allow to fix the physical address of printk buffer

Allows to put printk buffer at fixed location of ram (default 128M).

    If debugfs is enabled, log of last boot is copied into
system ram, and can be accessed via debugfs, for example
cat /sys/kernel/debug/printk/crash_dmesg

Signed-off-by: Maxim Levitsky 

diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h
index ef292c7..a6eaf40 100644
--- a/arch/x86/include/asm/setup.h
+++ b/arch/x86/include/asm/setup.h
@@ -46,6 +46,7 @@ extern unsigned long saved_video_mode;
 extern void reserve_standard_io_resources(void);
 extern void i386_reserve_resources(void);
 extern void setup_default_timer_irq(void);
+extern void early_reserve_printk_buffer(void);
 
 #ifdef CONFIG_X86_MRST
 extern void x86_mrst_early_setup(void);
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index c3a4fbb..6fbf2a0 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -843,6 +843,7 @@ void __init setup_arch(char **cmdline_p)
 
 	/* after early param, so could get panic from serial */
 	reserve_early_setup_data();
+	early_reserve_printk_buffer();
 
 	if (acpi_mps_check()) {
 #ifdef CONFIG_X86_LOCAL_APIC
diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index 3ba6e06..8854a91 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -106,7 +106,6 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
 
 		if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
 			return NULL;
-		WARN_ON_ONCE(is_ram);
 	}
 
 	/*
diff --git a/kernel/printk.c b/kernel/printk.c
index 8fe465a..a6fff63 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -41,6 +41,7 @@
 #include 
 
 #include 
+#include 
 
 /*
  * for_each_console() allows you to iterate on each console
@@ -167,6 +168,7 @@ void log_buf_kexec_setup(void)
 }
 #endif
 
+#ifndef CONFIG_HWMEM_PRINTK
 static int __init log_buf_len_setup(char *str)
 {
 	unsigned size = memparse(str, &str);
@@ -207,6 +209,93 @@ out:
 }
 
 __setup("log_buf_len=", log_buf_len_setup);
+#endif
+
+#ifdef CONFIG_HWMEM_PRINTK
+
+char *old_log_buf;
+struct debugfs_blob_wrapper crash_dmesg_wrapper;
+static unsigned int printk_phys_address = CONFIG_HWMEM_PRINTK_DEFAULT_ADDRESS;
+
+
+static int __init printk_address_setup(char *p)
+{
+	char *tmp;
+
+	if (!strncmp(p, "off", 3))
+		printk_phys_address = 0;
+	else
+		printk_phys_address = memparse(p, &

Re: [PATCH 5/8] IR: extend MCE keymap.

2010-09-09 Thread Maxim Levitsky
On Wed, 2010-09-08 at 10:47 -0400, Jarod Wilson wrote: 
> On Mon, Sep 6, 2010 at 5:26 PM, Maxim Levitsky  
> wrote:
> > These keys are found on remote bundled with
> > Toshiba Qosmio F50-10q.
> >
> > Found and tested by, Sami R 
> >
> > Signed-off-by: Maxim Levitsky 
> > ---
> >  drivers/media/IR/keymaps/rc-rc6-mce.c |3 +++
> >  1 files changed, 3 insertions(+), 0 deletions(-)

Tommorow I will resend that patch with even more scancodes.

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 1/5] rc-code: merge and rename ir-core

2010-09-09 Thread Maxim Levitsky
On Wed, 2010-09-08 at 23:12 +0200, David Härdeman wrote: 
> On Wed, Sep 08, 2010 at 11:10:40AM -0400, Andy Walls wrote:
> > Tag files and a decent editor are all one needs for full code 
> > navigation.  The kernel makefile already has a tags target to make the 
> > tags file.  
> 
> If you like to use tags, it won't be affected by many or few files so 
> it's not an argument for either approach. 
> 
> > Smaller files make for better logical isolation of functions,limiting 
> > visibilty/scope, 
> 
> Limiting visibility so that you'll have to add explicit declarations to 
> ir-core-priv.h for inter-file function calls and functions that would 
> otherwise be unnecessary (ir_raw_get_allowed_protocols() for example) 
> doesn't sound like an advantage to me.
> 
> > and faster compilation of a file (but maybe at the expense of link 
> > time).  
> 
> *sigh* compile times on my laptop:
> 
> rc-core.o 0.558s
> 
> ir-functions.o0.321s
> ir-sysfs.o0.251s
> ir-raw-event.o0.397s
> rc-map.o  0.265s

I personally don't care much about this.
I use Kscope all the time :-)

However I do care and like very much this patchset because I also would
like to have a per remote input device, and this is first step towards
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 0/8 V5] Many fixes for in-kernel decoding and for the ENE driver

2010-09-06 Thread Maxim Levitsky
On Mon, 2010-09-06 at 23:56 +0200, David Härdeman wrote: 
> On Tue, Sep 07, 2010 at 12:26:05AM +0300, Maxim Levitsky wrote:
> > Hi,
> > 
> > Here is full overview of my patches:
> 
> What changed from V4?
Nothing other that 2 build fixes that I forgot to include.
I also cced linux-media because I was asked to.

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


[PATCH 7/8] IR: extend ir_raw_event and do refactoring

2010-09-06 Thread Maxim Levitsky
Add new event types for timeout & carrier report
Move timeout handling from ir_raw_event_store_with_filter to
ir-lirc-codec, where it is really needed.
Now lirc bridge ensures proper gap handling.
Extend lirc bridge for carrier & timeout reports

Note: all new ir_raw_event variables now should be initialized
like that: DEFINE_IR_RAW_EVENT(ev);

To clean an existing event, use init_ir_raw_event(&ev);

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ene_ir.c  |4 +-
 drivers/media/IR/ir-core-priv.h|   13 ++-
 drivers/media/IR/ir-jvc-decoder.c  |5 +-
 drivers/media/IR/ir-lirc-codec.c   |   78 +++-
 drivers/media/IR/ir-nec-decoder.c  |5 +-
 drivers/media/IR/ir-raw-event.c|   45 +++-
 drivers/media/IR/ir-rc5-decoder.c  |5 +-
 drivers/media/IR/ir-rc6-decoder.c  |5 +-
 drivers/media/IR/ir-sony-decoder.c |5 +-
 drivers/media/IR/mceusb.c  |3 +-
 drivers/media/IR/streamzap.c   |8 ++-
 include/media/ir-core.h|   40 ---
 12 files changed, 153 insertions(+), 63 deletions(-)

diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index 7880d9c..dc32509 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -701,7 +701,7 @@ static irqreturn_t ene_isr(int irq, void *data)
unsigned long flags;
irqreturn_t retval = IRQ_NONE;
struct ene_device *dev = (struct ene_device *)data;
-   struct ir_raw_event ev;
+   DEFINE_IR_RAW_EVENT(ev);
 
spin_lock_irqsave(&dev->hw_lock, flags);
 
@@ -904,7 +904,7 @@ static int ene_set_learning_mode(void *data, int enable)
 }
 
 /* outside interface: enable or disable idle mode */
-static void ene_rx_set_idle(void *data, int idle)
+static void ene_rx_set_idle(void *data, bool idle)
 {
struct ene_device *dev = (struct ene_device *)data;
 
diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index 5d7e08f..2559e72 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -82,6 +82,12 @@ struct ir_raw_event_ctrl {
struct ir_input_dev *ir_dev;
struct lirc_driver *drv;
int carrier_low;
+
+   ktime_t gap_start;
+   u64 gap_duration;
+   bool gap;
+   bool send_timeout_reports;
+
} lirc;
 };
 
@@ -109,9 +115,14 @@ static inline void decrease_duration(struct ir_raw_event 
*ev, unsigned duration)
ev->duration -= duration;
 }
 
+/* Returns true if event is normal pulse/space event */
+static inline bool is_timing_event(struct ir_raw_event ev)
+{
+   return !ev.carrier_report && !ev.reset;
+}
+
 #define TO_US(duration)DIV_ROUND_CLOSEST((duration), 
1000)
 #define TO_STR(is_pulse)   ((is_pulse) ? "pulse" : "space")
-#define IS_RESET(ev)   (ev.duration == 0)
 /*
  * Routines from ir-sysfs.c - Meant to be called only internally inside
  * ir-core
diff --git a/drivers/media/IR/ir-jvc-decoder.c 
b/drivers/media/IR/ir-jvc-decoder.c
index 77a89c4..63dca6e 100644
--- a/drivers/media/IR/ir-jvc-decoder.c
+++ b/drivers/media/IR/ir-jvc-decoder.c
@@ -50,8 +50,9 @@ static int ir_jvc_decode(struct input_dev *input_dev, struct 
ir_raw_event ev)
if (!(ir_dev->raw->enabled_protocols & IR_TYPE_JVC))
return 0;
 
-   if (IS_RESET(ev)) {
-   data->state = STATE_INACTIVE;
+   if (!is_timing_event(ev)) {
+   if (ev.reset)
+   data->state = STATE_INACTIVE;
return 0;
}
 
diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/IR/ir-lirc-codec.c
index e63f757..0f40bc2 100644
--- a/drivers/media/IR/ir-lirc-codec.c
+++ b/drivers/media/IR/ir-lirc-codec.c
@@ -32,6 +32,7 @@
 static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
 {
struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+   struct lirc_codec *lirc = &ir_dev->raw->lirc;
int sample;
 
if (!(ir_dev->raw->enabled_protocols & IR_TYPE_LIRC))
@@ -40,21 +41,57 @@ static int ir_lirc_decode(struct input_dev *input_dev, 
struct ir_raw_event ev)
if (!ir_dev->raw->lirc.drv || !ir_dev->raw->lirc.drv->rbuf)
return -EINVAL;
 
-   if (IS_RESET(ev))
+   /* Packet start */
+   if (ev.reset)
return 0;
 
-   IR_dprintk(2, "LIRC data transfer started (%uus %s)\n",
-  TO_US(ev.duration), TO_STR(ev.pulse));
+   /* Carrier reports */
+   if (ev.carrier_report) {
+   sample = LIRC_FREQUENCY(ev.carrier);
+
+   /* Packet end */
+   } else if (ev.timeout) {
+
+   if (lirc->gap)
+   return 0;
+
+   lirc->gap_start = ktime_g

[PATCH 8/8] IR: ene_ir: add support for carrier reports

2010-09-06 Thread Maxim Levitsky
Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ene_ir.c |   37 +
 1 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index dc32509..f1ee153 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -192,10 +192,11 @@ static int ene_hw_detect(struct ene_device *dev)
 /* Sense current received carrier */
 void ene_rx_sense_carrier(struct ene_device *dev)
 {
+   DEFINE_IR_RAW_EVENT(ev);
+
+   int carrier, duty_cycle;
int period = ene_read_reg(dev, ENE_CIRCAR_PRD);
int hperiod = ene_read_reg(dev, ENE_CIRCAR_HPRD);
-   int carrier, duty_cycle;
-
 
if (!(period & ENE_CIRCAR_PRD_VALID))
return;
@@ -208,13 +209,16 @@ void ene_rx_sense_carrier(struct ene_device *dev)
dbg("RX: hardware carrier period = %02x", period);
dbg("RX: hardware carrier pulse period = %02x", hperiod);
 
-
carrier = 200 / period;
duty_cycle = (hperiod * 100) / period;
dbg("RX: sensed carrier = %d Hz, duty cycle %d%%",
-   carrier, duty_cycle);
-
-   /* TODO: Send carrier & duty cycle to IR layer */
+   carrier, duty_cycle);
+   if (dev->carrier_detect_enabled) {
+   ev.carrier_report = true;
+   ev.carrier = carrier;
+   ev.duty_cycle = duty_cycle;
+   ir_raw_event_store(dev->idev, &ev);
+   }
 }
 
 /* this enables/disables the CIR RX engine */
@@ -728,7 +732,7 @@ static irqreturn_t ene_isr(int irq, void *data)
 
dbg_verbose("RX interrupt");
 
-   if (dev->carrier_detect_enabled || debug)
+   if (dev->hw_learning_and_tx_capable)
ene_rx_sense_carrier(dev);
 
/* On hardware that don't support extra buffer we need to trust
@@ -903,6 +907,23 @@ static int ene_set_learning_mode(void *data, int enable)
return 0;
 }
 
+static int ene_set_carrier_report(void *data, int enable)
+{
+   struct ene_device *dev = (struct ene_device *)data;
+   unsigned long flags;
+
+   if (enable == dev->carrier_detect_enabled)
+   return 0;
+
+   spin_lock_irqsave(&dev->hw_lock, flags);
+   dev->carrier_detect_enabled = enable;
+   ene_rx_disable(dev);
+   ene_rx_setup(dev);
+   ene_rx_enable(dev);
+   spin_unlock_irqrestore(&dev->hw_lock, flags);
+   return 0;
+}
+
 /* outside interface: enable or disable idle mode */
 static void ene_rx_set_idle(void *data, bool idle)
 {
@@ -1032,7 +1053,7 @@ static int ene_probe(struct pnp_dev *pnp_dev, const 
struct pnp_device_id *id)
ir_props->s_tx_mask = ene_set_tx_mask;
ir_props->s_tx_carrier = ene_set_tx_carrier;
ir_props->s_tx_duty_cycle = ene_set_tx_duty_cycle;
-   /* ir_props->s_carrier_report = ene_set_carrier_report; */
+   ir_props->s_carrier_report = ene_set_carrier_report;
}
 
ene_setup_hw_buffer(dev);
-- 
1.7.0.4

--
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


[PATCH 5/8] IR: extend MCE keymap.

2010-09-06 Thread Maxim Levitsky
These keys are found on remote bundled with
Toshiba Qosmio F50-10q.

Found and tested by, Sami R 

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/keymaps/rc-rc6-mce.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/media/IR/keymaps/rc-rc6-mce.c 
b/drivers/media/IR/keymaps/rc-rc6-mce.c
index 64264f7..39557ad 100644
--- a/drivers/media/IR/keymaps/rc-rc6-mce.c
+++ b/drivers/media/IR/keymaps/rc-rc6-mce.c
@@ -19,6 +19,7 @@ static struct ir_scancode rc6_mce[] = {
 
{ 0x800f0416, KEY_PLAY },
{ 0x800f0418, KEY_PAUSE },
+   { 0x800f046e, KEY_PLAYPAUSE },
{ 0x800f0419, KEY_STOP },
{ 0x800f0417, KEY_RECORD },
 
@@ -37,6 +38,8 @@ static struct ir_scancode rc6_mce[] = {
{ 0x800f0411, KEY_VOLUMEDOWN },
{ 0x800f0412, KEY_CHANNELUP },
{ 0x800f0413, KEY_CHANNELDOWN },
+   { 0x800f043a, KEY_BRIGHTNESSUP },
+   { 0x800f0480, KEY_BRIGHTNESSDOWN },
 
{ 0x800f0401, KEY_NUMERIC_1 },
{ 0x800f0402, KEY_NUMERIC_2 },
-- 
1.7.0.4

--
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


[PATCH 2/8] IR: make sure we register the input device when it is safe to do so.

2010-09-06 Thread Maxim Levitsky
As soon as input device is registered, it might be accessed (and it is)
This can trigger a hardware interrupt that can access
not yet initialized ir->raw, (by sending a sample)

This can be reproduced by holding down a remote button and reloading the module.
And this always crashes the systems where hardware decides to send an interrupt
right at the moment it is enabled.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-core-priv.h |1 +
 drivers/media/IR/ir-keytable.c  |2 ++
 drivers/media/IR/ir-sysfs.c |   27 +--
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index 761e7f4..5d7e08f 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -116,6 +116,7 @@ static inline void decrease_duration(struct ir_raw_event 
*ev, unsigned duration)
  * Routines from ir-sysfs.c - Meant to be called only internally inside
  * ir-core
  */
+int ir_register_input(struct input_dev *input_dev);
 
 int ir_register_class(struct input_dev *input_dev);
 void ir_unregister_class(struct input_dev *input_dev);
diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
index 51dbc67..0917535 100644
--- a/drivers/media/IR/ir-keytable.c
+++ b/drivers/media/IR/ir-keytable.c
@@ -505,6 +505,8 @@ int __ir_input_register(struct input_dev *input_dev,
goto out_event;
}
 
+   rc = ir_register_input(input_dev);
+
IR_dprintk(1, "Registered input device on %s for %s remote%s.\n",
   driver_name, rc_tab->name,
   (ir_dev->props && ir_dev->props->driver_type == 
RC_DRIVER_IR_RAW) ?
diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c
index 96dafc4..c0075f1 100644
--- a/drivers/media/IR/ir-sysfs.c
+++ b/drivers/media/IR/ir-sysfs.c
@@ -251,8 +251,6 @@ static struct device_type rc_dev_type = {
  */
 int ir_register_class(struct input_dev *input_dev)
 {
-   int rc;
-   const char *path;
struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
int devno = find_first_zero_bit(&ir_core_dev_number,
IRRCV_NUM_DEVICES);
@@ -261,17 +259,28 @@ int ir_register_class(struct input_dev *input_dev)
return devno;
 
ir_dev->dev.type = &rc_dev_type;
+   ir_dev->devno = devno;
 
ir_dev->dev.class = &ir_input_class;
ir_dev->dev.parent = input_dev->dev.parent;
+   input_dev->dev.parent = &ir_dev->dev;
dev_set_name(&ir_dev->dev, "rc%d", devno);
dev_set_drvdata(&ir_dev->dev, ir_dev);
-   rc = device_register(&ir_dev->dev);
-   if (rc)
-   return rc;
+   return  device_register(&ir_dev->dev);
+};
+
+/**
+ * ir_register_input - registers ir input device with input subsystem
+ * @input_dev: the struct input_dev descriptor of the device
+ */
+
+int ir_register_input(struct input_dev *input_dev)
+{
+   struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+   int rc;
+   const char *path;
 
 
-   input_dev->dev.parent = &ir_dev->dev;
rc = input_register_device(input_dev);
if (rc < 0) {
device_del(&ir_dev->dev);
@@ -287,11 +296,9 @@ int ir_register_class(struct input_dev *input_dev)
path ? path : "N/A");
kfree(path);
 
-   ir_dev->devno = devno;
-   set_bit(devno, &ir_core_dev_number);
-
+   set_bit(ir_dev->devno, &ir_core_dev_number);
return 0;
-};
+}
 
 /**
  * ir_unregister_class() - removes the sysfs for sysfs for
-- 
1.7.0.4

--
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


[PATCH 3/8] IR: fix duty cycle capability

2010-09-06 Thread Maxim Levitsky
Due to typo lirc bridge enabled wrong capability.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-lirc-codec.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/IR/ir-lirc-codec.c
index 77b5946..e63f757 100644
--- a/drivers/media/IR/ir-lirc-codec.c
+++ b/drivers/media/IR/ir-lirc-codec.c
@@ -267,7 +267,7 @@ static int ir_lirc_register(struct input_dev *input_dev)
features |= LIRC_CAN_SET_SEND_CARRIER;
 
if (ir_dev->props->s_tx_duty_cycle)
-   features |= LIRC_CAN_SET_REC_DUTY_CYCLE;
+   features |= LIRC_CAN_SET_SEND_DUTY_CYCLE;
}
 
if (ir_dev->props->s_rx_carrier_range)
-- 
1.7.0.4

--
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


[PATCH 4/8] IR: fix keys beeing stuck down forever.

2010-09-06 Thread Maxim Levitsky
The logic in ir_timer_keyup was inverted.

In case that values aren't equal,
the meaning of the time_is_after_eq_jiffies(ir->keyup_jiffies) is that
ir->keyup_jiffies is after the the jiffies or equally that
that jiffies are before the the ir->keyup_jiffies which is
exactly the situation we want to avoid (that the timeout is in the future)
Confusing Eh?

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-keytable.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
index 0917535..a8fd777 100644
--- a/drivers/media/IR/ir-keytable.c
+++ b/drivers/media/IR/ir-keytable.c
@@ -319,7 +319,7 @@ static void ir_timer_keyup(unsigned long cookie)
 * a keyup event might follow immediately after the keydown.
 */
spin_lock_irqsave(&ir->keylock, flags);
-   if (time_is_after_eq_jiffies(ir->keyup_jiffies))
+   if (time_is_before_eq_jiffies(ir->keyup_jiffies))
ir_keyup(ir);
spin_unlock_irqrestore(&ir->keylock, flags);
 }
-- 
1.7.0.4

--
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


[PATCH 0/8 V5] Many fixes for in-kernel decoding and for the ENE driver

2010-09-06 Thread Maxim Levitsky
Hi,

Here is full overview of my patches:

Patch #1 fixes races in ir thread.
It fixes the case when ktherad_stop waits forever for the thread.
This happens on module unload and therefore it never finishes.
Sorry for introducing this bug.

Patch #2, fixes a crash on my module load.
It happens because ir core initializes the input device a bit early,
therefore it could be accessed while still not set up.

Patch #3 fixes a small typo in lirc code that makes it impossible to use tx 
duty cycle setting.

Patch #4 fixes a problem seen on my system that results in stuck down forever 
key.

Patch #5 adds few keys to MCE keymap that were found on laptop of an user I 
tested this driver with

Patch #6, is a combined update ti my driver. It contains lot of refactoring 
thanks to docs I have now,
and lot of fixes, and supports latest version of firmware (and I have 4 users 
asking for that)
It is quite huge, but it would be a tedios job to break it up. This can't 
introduce regressions
because the ene_ir was never released. In addition to that it was tested by me 
and another two users.

Patch #7 the really only patch that touches drivers I don't have does touch the 
ir-core.
It is quite small, and it adds a proper solution to dilema about what to do 
with huge space between keypresses.
Now this space is just truncated by the driver with timeout flag.
The lirc codec then ensures that right sample is send to the lircd.
Please review and test it.

Patch #8 is very simple. It just builds on top of patch #7 and adds carrier 
reports to ene driver.


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


[PATCH 1/8] IR: plug races in IR raw thread.

2010-09-06 Thread Maxim Levitsky
Unfortunelly (my fault) the kernel thread that now handles IR processing
has classical races in regard to wakeup and stop.
This patch hopefully closes them all.
Tested with module reload running in a loop, while receiver is blasted
with IR data for 10 minutes.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-core-priv.h |2 ++
 drivers/media/IR/ir-raw-event.c |   34 +-
 2 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index a85a8c7..761e7f4 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -17,6 +17,7 @@
 #define _IR_RAW_EVENT
 
 #include 
+#include 
 #include 
 
 struct ir_raw_handler {
@@ -33,6 +34,7 @@ struct ir_raw_handler {
 struct ir_raw_event_ctrl {
struct list_headlist;   /* to keep track of raw 
clients */
struct task_struct  *thread;
+   spinlock_t  lock;
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 */
diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
index 43094e7..56797be 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/IR/ir-raw-event.c
@@ -39,22 +39,34 @@ static int ir_raw_event_thread(void *data)
struct ir_raw_event ev;
struct ir_raw_handler *handler;
struct ir_raw_event_ctrl *raw = (struct ir_raw_event_ctrl *)data;
+   int retval;
 
while (!kthread_should_stop()) {
-   try_to_freeze();
 
-   mutex_lock(&ir_raw_handler_lock);
+   spin_lock_irq(&raw->lock);
+   retval = kfifo_out(&raw->kfifo, &ev, sizeof(ev));
+
+   if (!retval) {
+   set_current_state(TASK_INTERRUPTIBLE);
 
-   while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) {
-   list_for_each_entry(handler, &ir_raw_handler_list, list)
-   handler->decode(raw->input_dev, ev);
-   raw->prev_ev = ev;
+   if (kthread_should_stop())
+   set_current_state(TASK_RUNNING);
+
+   spin_unlock_irq(&raw->lock);
+   schedule();
+   continue;
}
 
-   mutex_unlock(&ir_raw_handler_lock);
+   spin_unlock_irq(&raw->lock);
 
-   set_current_state(TASK_INTERRUPTIBLE);
-   schedule();
+
+   BUG_ON(retval != sizeof(ev));
+
+   mutex_lock(&ir_raw_handler_lock);
+   list_for_each_entry(handler, &ir_raw_handler_list, list)
+   handler->decode(raw->input_dev, ev);
+   raw->prev_ev = ev;
+   mutex_unlock(&ir_raw_handler_lock);
}
 
return 0;
@@ -232,11 +244,14 @@ EXPORT_SYMBOL_GPL(ir_raw_event_set_idle);
 void ir_raw_event_handle(struct input_dev *input_dev)
 {
struct ir_input_dev *ir = input_get_drvdata(input_dev);
+   unsigned long flags;
 
if (!ir->raw)
return;
 
+   spin_lock_irqsave(&ir->raw->lock, flags);
wake_up_process(ir->raw->thread);
+   spin_unlock_irqrestore(&ir->raw->lock, flags);
 }
 EXPORT_SYMBOL_GPL(ir_raw_event_handle);
 
@@ -275,6 +290,7 @@ int ir_raw_event_register(struct input_dev *input_dev)
return rc;
}
 
+   spin_lock_init(&ir->raw->lock);
ir->raw->thread = kthread_run(ir_raw_event_thread, ir->raw,
"rc%u",  (unsigned int)ir->devno);
 
-- 
1.7.0.4

--
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 7/8] IR: extend ir_raw_event and do refactoring

2010-09-05 Thread Maxim Levitsky
On Sun, 2010-09-05 at 23:23 +0200, David Härdeman wrote: 
> Comments inline...
> 
> On Sun, Sep 05, 2010 at 02:23:02AM +0300, Maxim Levitsky wrote:
> > Add new event types for timeout & carrier report
> > Move timeout handling from ir_raw_event_store_with_filter to
> > ir-lirc-codec, where it is really needed.
> > Now lirc bridge ensures proper gap handling.
> > Extend lirc bridge for carrier & timeout reports
> > 
> > Note: all new ir_raw_event variables now should be initialized
> > like that: DEFINE_RC_RAW_EVENT(ev);
> > 
> > To clean an existing event, use init_ir_raw_event(&ev);
> > 
> > Signed-off-by: Maxim Levitsky 
> > ---
> >  drivers/media/IR/ene_ir.c  |2 +-
> >  drivers/media/IR/ir-core-priv.h|   11 +-
> >  drivers/media/IR/ir-jvc-decoder.c  |5 +-
> >  drivers/media/IR/ir-lirc-codec.c   |   78 
> > +++-
> >  drivers/media/IR/ir-nec-decoder.c  |5 +-
> >  drivers/media/IR/ir-raw-event.c|   43 +++-
> >  drivers/media/IR/ir-rc5-decoder.c  |5 +-
> >  drivers/media/IR/ir-rc6-decoder.c  |5 +-
> >  drivers/media/IR/ir-sony-decoder.c |5 +-
> >  drivers/media/IR/mceusb.c  |3 +-
> >  drivers/media/IR/streamzap.c   |8 ++-
> >  include/media/ir-core.h|   35 ++--
> >  12 files changed, 146 insertions(+), 59 deletions(-)
> > 
> > diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
> > index 7880d9c..5ebafb5 100644
> > --- a/drivers/media/IR/ene_ir.c
> > +++ b/drivers/media/IR/ene_ir.c
> > @@ -701,7 +701,7 @@ static irqreturn_t ene_isr(int irq, void *data)
> > unsigned long flags;
> > irqreturn_t retval = IRQ_NONE;
> > struct ene_device *dev = (struct ene_device *)data;
> > -   struct ir_raw_event ev;
> > +   DEFINE_RC_RAW_EVENT(ev);
> >  
> > spin_lock_irqsave(&dev->hw_lock, flags);
> >  
> > diff --git a/drivers/media/IR/ir-core-priv.h 
> > b/drivers/media/IR/ir-core-priv.h
> > index 5d7e08f..a287373 100644
> > --- a/drivers/media/IR/ir-core-priv.h
> > +++ b/drivers/media/IR/ir-core-priv.h
> > @@ -82,6 +82,10 @@ struct ir_raw_event_ctrl {
> > struct ir_input_dev *ir_dev;
> > struct lirc_driver *drv;
> > int carrier_low;
> > +   ktime_t timeout_start;
> > +   bool timeout;
> > +   bool send_timeout_reports;
> > +
> > } lirc;
> >  };
> >  
> > @@ -109,9 +113,14 @@ static inline void decrease_duration(struct 
> > ir_raw_event *ev, unsigned duration)
> > ev->duration -= duration;
> >  }
> >  
> > +/* Returns true if event is normal pulse/space event */
> > +static inline bool is_timing_event(struct ir_raw_event ev)
> > +{
> > +   return !ev.carrier_report && !ev.reset;
> > +}
> > +
> >  #define TO_US(duration)DIV_ROUND_CLOSEST((duration), 
> > 1000)
> >  #define TO_STR(is_pulse)   ((is_pulse) ? "pulse" : "space")
> > -#define IS_RESET(ev)   (ev.duration == 0)
> >  /*
> >   * Routines from ir-sysfs.c - Meant to be called only internally inside
> >   * ir-core
> > diff --git a/drivers/media/IR/ir-jvc-decoder.c 
> > b/drivers/media/IR/ir-jvc-decoder.c
> > index 77a89c4..63dca6e 100644
> > --- a/drivers/media/IR/ir-jvc-decoder.c
> > +++ b/drivers/media/IR/ir-jvc-decoder.c
> > @@ -50,8 +50,9 @@ static int ir_jvc_decode(struct input_dev *input_dev, 
> > struct ir_raw_event ev)
> > if (!(ir_dev->raw->enabled_protocols & IR_TYPE_JVC))
> > return 0;
> >  
> > -   if (IS_RESET(ev)) {
> > -   data->state = STATE_INACTIVE;
> > +   if (!is_timing_event(ev)) {
> > +   if (ev.reset)
> > +   data->state = STATE_INACTIVE;
> > return 0;
> > }
> >  
> > diff --git a/drivers/media/IR/ir-lirc-codec.c 
> > b/drivers/media/IR/ir-lirc-codec.c
> > index e63f757..15112db 100644
> > --- a/drivers/media/IR/ir-lirc-codec.c
> > +++ b/drivers/media/IR/ir-lirc-codec.c
> > @@ -32,6 +32,7 @@
> >  static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event 
> > ev)
> >  {
> > struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
> > +   struct lirc_codec *lirc = &ir_dev->raw->lirc;
> > int sample;
> >  
> > if (!(ir_dev->raw-&g

Re: [PATCH 0/8 V3] Many fixes for in-kernel decoding and for the ENE driver

2010-09-05 Thread Maxim Levitsky
On Sun, 2010-09-05 at 23:06 +0200, David Härdeman wrote: 
> On Sun, Sep 05, 2010 at 02:22:55AM +0300, Maxim Levitsky wrote:
> > Hi,
> > 
> > This is next version of my patchset.
> > I addressed the comments from David Härdeman,   
> > And in addition to that did a lot of cleanups in the ENE driver.
> > This includes new idle mode support that doesn't need 75 ms sample period.
> > Timeouts are now handled in much cleaner way.
> > Refactoring, even better register names, stale comments updated, some 
> > spelling errors
> > were fixed.
> > 
> > Any comments are welcome!
> 
> Out patchsets conflict. Depending on which order Mauro wishes to merge 
> them one of us will have to rebase. If mine is merged first, patch 2/8 
> in your set should not be necessary.
Btw, I really welcome your patches.
Indeed we need to resolve this.
I hope to see this patchset in 2.6.36, because without it there are just
too many bugs.

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 6/7] IR: extend ir_raw_event and do refactoring

2010-09-02 Thread Maxim Levitsky
On Thu, 2010-09-02 at 22:56 +0200, David Härdeman wrote: 
> On Mon, Aug 30, 2010 at 11:52:26AM +0300, Maxim Levitsky wrote:
> > Add new event types for timeout & carrier report
> > Move timeout handling from ir_raw_event_store_with_filter to
> > ir-lirc-codec, where it is really needed.
> 
> Yes, but it still might make more sense to keep the timeout handling in 
> ir_raw_event_store_with_filter so that all decoders get the same data 
> from rc-core?
I don't want any timeouts in rc-core. There is just an IR packet that
starts optionally with a reset and ends with a timeout bit.
I have also nothing against renaming reset/timeout to start/stop.

rc-core really shouldn't care about consistent pulse/space ordering.
Its lirc that needs it.

Also in the future I think I should make the
ir_raw_event_store_with_filter the default submit function for all
drivers, and then I could drop that silly '_with_filter" thing
(Couldn't think for a better name for this function...)

> 
> > Now lirc bridge ensures proper gap handling.
> > Extend lirc bridge for carrier & timeout reports
> > 
> > Note: all new ir_raw_event variables now should be initialized
> > like that:
> > struct ir_raw_event ev = ir_new_event;
> 
> Wouldn't DEFINE_RAW_EVENT(ev); be more in line with the kernel coding 
> style? (cf. DEFINE_MUTEX, DEFINE_SPINLOCK, etc).
Of course, nothing against that.


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


[PATCH 7/7] ENE: add support for carrier reports

2010-08-30 Thread Maxim Levitsky
Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ene_ir.c |   47 +++-
 1 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index c7bbbca..dfb822b 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -224,6 +224,7 @@ void ene_rx_sense_carrier(struct ene_device *dev)
 {
int period = ene_read_reg(dev, ENE_CIRCAR_PRD);
int hperiod = ene_read_reg(dev, ENE_CIRCAR_HPRD);
+   struct ir_raw_event ev = ir_new_event;
int carrier, duty_cycle;
 
 
@@ -238,19 +239,23 @@ void ene_rx_sense_carrier(struct ene_device *dev)
dbg("RX: hardware carrier period = %02x", period);
dbg("RX: hardware carrier pulse period = %02x", hperiod);
 
-
carrier = 200 / period;
duty_cycle = (hperiod * 100) / period;
dbg("RX: sensed carrier = %d Hz, duty cycle %d%%",
-   carrier, duty_cycle);
-
-   /* TODO: Send carrier & duty cycle to IR layer */
+   carrier, duty_cycle);
+   if (dev->carrier_detect_enabled) {
+   ev.carrier_report = true;
+   ev.carrier = carrier;
+   ev.duty_cycle = duty_cycle;
+   ir_raw_event_store(dev->idev, &ev);
+   }
 }
 
 /* determine which input to use*/
 static void ene_rx_set_inputs(struct ene_device *dev)
 {
-   int learning_mode = dev->learning_enabled;
+   int learning_mode = dev->learning_enabled ||
+   dev->carrier_detect_enabled;
 
dbg("RX: setup receiver, learning mode = %d", learning_mode);
 
@@ -281,9 +286,17 @@ static void ene_rx_set_inputs(struct ene_device *dev)
ene_enable_cir_engine(dev, true);
ene_select_rx_input(dev, !dev->hw_use_gpio_0a);
 
-   /* Enable carrier detection & demodulation */
+   /* Enable demodulation */
ene_set_reg_mask(dev, ENE_CIRCFG, ENE_CIRCFG_CARR_DEMOD);
-   ene_set_reg_mask(dev, ENE_CIRCFG2, ENE_CIRCFG2_CARR_DETECT);
+
+   /* Enable carrier detect if asked to */
+   if (dev->carrier_detect_enabled || debug)
+   ene_set_reg_mask(dev, ENE_CIRCFG2,
+   ENE_CIRCFG2_CARR_DETECT);
+   else
+   ene_clear_reg_mask(dev, ENE_CIRCFG2,
+   ENE_CIRCFG2_CARR_DETECT);
+
 
 
/* disable learning mode */
@@ -726,7 +739,7 @@ static irqreturn_t ene_isr(int irq, void *data)
 
dbg_verbose("RX interrupt");
 
-   if (dev->carrier_detect_enabled || debug)
+   if (dev->hw_learning_and_tx_capable)
ene_rx_sense_carrier(dev);
 
/* On hardware that don't support extra buffer we need to trust
@@ -796,7 +809,6 @@ static void ene_setup_settings(struct ene_device *dev)
let user set it with LIRC_SET_REC_CARRIER */
dev->learning_enabled =
(learning_mode && dev->hw_learning_and_tx_capable);
-
 }
 
 /* outside interface: called on first open*/
@@ -902,6 +914,21 @@ static int ene_set_learning_mode(void *data, int enable)
return 0;
 }
 
+static int ene_set_carrier_report(void *data, int enable)
+{
+   struct ene_device *dev = (struct ene_device *)data;
+   unsigned long flags;
+
+   if (enable == dev->carrier_detect_enabled)
+   return 0;
+
+   spin_lock_irqsave(&dev->hw_lock, flags);
+   dev->carrier_detect_enabled = enable;
+   ene_rx_set_inputs(dev);
+   spin_unlock_irqrestore(&dev->hw_lock, flags);
+   return 0;
+}
+
 /* outside interface: enable or disable idle mode */
 static void ene_rx_set_idle(void *data, int idle)
 {
@@ -1043,7 +1070,7 @@ static int ene_probe(struct pnp_dev *pnp_dev, const 
struct pnp_device_id *id)
ir_props->s_tx_carrier = ene_set_tx_carrier;
ir_props->s_tx_duty_cycle = ene_set_tx_duty_cycle;
ir_props->tx_resolution = sample_period * 1000;
-   /* ir_props->s_carrier_report = ene_set_carrier_report; */
+   ir_props->s_carrier_report = ene_set_carrier_report;
}
 
 
-- 
1.7.0.4

--
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


[PATCH 5/7] ene_ir: updates

2010-08-30 Thread Maxim Levitsky
* Add support for newer firmware versions with different
buffer format. Makes hardware work for many users

* Register name updates + refactoring

* Lots of fixes as a result of full testing


Every feature of the driver is now well tested.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ene_ir.c |  795 +++--
 drivers/media/IR/ene_ir.h |  223 -
 2 files changed, 618 insertions(+), 400 deletions(-)

diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index 5447750..8e3e0c8 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -1,5 +1,5 @@
 /*
- * driver for ENE KB3926 B/C/D CIR (pnp id: ENE0XXX)
+ * driver for ENE KB3926 B/C/D/E/F CIR (pnp id: ENE0XXX)
  *
  * Copyright (C) 2010 Maxim Levitsky 
  *
@@ -17,6 +17,17 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  * USA
+ *
+ * Special thanks to:
+ *   Sami R.  for lot of help in debbuging and therefore
+ *bringing to life suppport for transmition & learning mode.
+ *
+ *   Charlie Andrews  for lots of help in
+ *   bringing up the support of new firmware buffer that is popular
+ *   on latest notebooks
+ *
+ *   ENE for partial device documentation
+ *
  */
 
 #include 
@@ -33,49 +44,49 @@
 
 
 static int sample_period = -1;
-static int enable_idle = 1;
-static int input = 1;
+static bool enable_idle = true;
+static bool learning_mode;
 static int debug;
-static int txsim;
+static bool txsim;
 
-static int ene_irq_status(struct ene_device *dev);
+static void ene_set_reg_addr(struct ene_device *dev, u16 reg)
+{
+   outb(reg >> 8, dev->hw_io + ENE_ADDR_HI);
+   outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO);
+}
 
 /* read a hardware register */
-static u8 ene_hw_read_reg(struct ene_device *dev, u16 reg)
+static u8 ene_read_reg(struct ene_device *dev, u16 reg)
 {
u8 retval;
-   outb(reg >> 8, dev->hw_io + ENE_ADDR_HI);
-   outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO);
+   ene_set_reg_addr(dev, reg);
retval = inb(dev->hw_io + ENE_IO);
-
-   ene_dbg_verbose("reg %04x == %02x", reg, retval);
+   dbg_regs("reg %04x == %02x", reg, retval);
return retval;
 }
 
 /* write a hardware register */
-static void ene_hw_write_reg(struct ene_device *dev, u16 reg, u8 value)
+static void ene_write_reg(struct ene_device *dev, u16 reg, u8 value)
 {
-   outb(reg >> 8, dev->hw_io + ENE_ADDR_HI);
-   outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO);
+   dbg_regs("reg %04x <- %02x", reg, value);
+   ene_set_reg_addr(dev, reg);
outb(value, dev->hw_io + ENE_IO);
-
-   ene_dbg_verbose("reg %04x <- %02x", reg, value);
 }
 
-/* change specific bits in hardware register */
-static void ene_hw_write_reg_mask(struct ene_device *dev,
- u16 reg, u8 value, u8 mask)
+/* Set bits in hardware register */
+static void ene_set_reg_mask(struct ene_device *dev, u16 reg, u8 mask)
 {
-   u8 regvalue;
-
-   outb(reg >> 8, dev->hw_io + ENE_ADDR_HI);
-   outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO);
-
-   regvalue = inb(dev->hw_io + ENE_IO) & ~mask;
-   regvalue |= (value & mask);
-   outb(regvalue, dev->hw_io + ENE_IO);
+   dbg_regs("reg %04x |= %02x", reg, mask);
+   ene_set_reg_addr(dev, reg);
+   outb(inb(dev->hw_io + ENE_IO) | mask, dev->hw_io + ENE_IO);
+}
 
-   ene_dbg_verbose("reg %04x <- %02x (mask=%02x)", reg, value, mask);
+/* Clear bits in hardware register */
+static void ene_clear_reg_mask(struct ene_device *dev, u16 reg, u8 mask)
+{
+   dbg_regs("reg %04x &= ~%02x ", reg, mask);
+   ene_set_reg_addr(dev, reg);
+   outb(inb(dev->hw_io + ENE_IO) & ~mask, dev->hw_io + ENE_IO);
 }
 
 /* detect hardware features */
@@ -83,22 +94,19 @@ static int ene_hw_detect(struct ene_device *dev)
 {
u8 chip_major, chip_minor;
u8 hw_revision, old_ver;
-   u8 tmp;
-   u8 fw_capabilities;
+   u8 fw_reg2, fw_reg1;
int pll_freq;
 
-   tmp = ene_hw_read_reg(dev, ENE_HW_UNK);
-   ene_hw_write_reg(dev, ENE_HW_UNK, tmp & ~ENE_HW_UNK_CLR);
-
-   chip_major = ene_hw_read_reg(dev, ENE_HW_VER_MAJOR);
-   chip_minor = ene_hw_read_reg(dev, ENE_HW_VER_MINOR);
+   ene_clear_reg_mask(dev, ENE_HW_UNK, ENE_HW_UNK_CLR);
+   chip_major = ene_read_reg(dev, ENE_HW_VER_MAJOR);
+   chip_minor = ene_read_reg(dev, ENE_HW_VER_MINOR);
+   ene_set_reg_mask(dev, ENE_HW_UNK, ENE_HW_UNK_CLR);
 
-   ene_hw_write_reg(dev, ENE_HW_UNK, tmp);
-   hw_revision = ene_hw_read_reg(dev, ENE_HW_VERSION);
-   old_ver = ene_hw_read_reg(dev, ENE_HW_VER_OLD);
+   hw_revision = ene_read_reg(dev, ENE_HW_VERSION);
+   old_ver = ene_read_reg(dev, 

[PATCH 6/7] IR: extend ir_raw_event and do refactoring

2010-08-30 Thread Maxim Levitsky
Add new event types for timeout & carrier report
Move timeout handling from ir_raw_event_store_with_filter to
ir-lirc-codec, where it is really needed.
Now lirc bridge ensures proper gap handling.
Extend lirc bridge for carrier & timeout reports

Note: all new ir_raw_event variables now should be initialized
like that:
struct ir_raw_event ev = ir_new_event;

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ene_ir.c  |2 +-
 drivers/media/IR/ene_ir.h  |2 +-
 drivers/media/IR/ir-core-priv.h|   11 +-
 drivers/media/IR/ir-jvc-decoder.c  |5 ++-
 drivers/media/IR/ir-lirc-codec.c   |   66 
 drivers/media/IR/ir-nec-decoder.c  |5 ++-
 drivers/media/IR/ir-raw-event.c|   41 +-
 drivers/media/IR/ir-rc5-decoder.c  |5 ++-
 drivers/media/IR/ir-rc6-decoder.c  |5 ++-
 drivers/media/IR/ir-sony-decoder.c |5 ++-
 drivers/media/IR/mceusb.c  |2 +-
 drivers/media/IR/streamzap.c   |6 ++--
 include/media/ir-core.h|   26 --
 13 files changed, 121 insertions(+), 60 deletions(-)

diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index 8e3e0c8..c7bbbca 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -699,7 +699,7 @@ static irqreturn_t ene_isr(int irq, void *data)
unsigned long flags;
irqreturn_t retval = IRQ_NONE;
struct ene_device *dev = (struct ene_device *)data;
-   struct ir_raw_event ev;
+   struct ir_raw_event ev = ir_new_event;
 
spin_lock_irqsave(&dev->hw_lock, flags);
 
diff --git a/drivers/media/IR/ene_ir.h b/drivers/media/IR/ene_ir.h
index 69a0ae0..27b2eb0 100644
--- a/drivers/media/IR/ene_ir.h
+++ b/drivers/media/IR/ene_ir.h
@@ -188,7 +188,7 @@
  *  And there is nothing to change this setting
  */
 
-#define ENE_MAXGAP (0xFFF * 0x61)
+#define ENE_MAXGAP 2
 #define ENE_MINGAP (127 * sample_period)
 
 
/**/
diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index 5d7e08f..a287373 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -82,6 +82,10 @@ struct ir_raw_event_ctrl {
struct ir_input_dev *ir_dev;
struct lirc_driver *drv;
int carrier_low;
+   ktime_t timeout_start;
+   bool timeout;
+   bool send_timeout_reports;
+
} lirc;
 };
 
@@ -109,9 +113,14 @@ static inline void decrease_duration(struct ir_raw_event 
*ev, unsigned duration)
ev->duration -= duration;
 }
 
+/* Returns true if event is normal pulse/space event */
+static inline bool is_timing_event(struct ir_raw_event ev)
+{
+   return !ev.carrier_report && !ev.reset;
+}
+
 #define TO_US(duration)DIV_ROUND_CLOSEST((duration), 
1000)
 #define TO_STR(is_pulse)   ((is_pulse) ? "pulse" : "space")
-#define IS_RESET(ev)   (ev.duration == 0)
 /*
  * Routines from ir-sysfs.c - Meant to be called only internally inside
  * ir-core
diff --git a/drivers/media/IR/ir-jvc-decoder.c 
b/drivers/media/IR/ir-jvc-decoder.c
index 77a89c4..63dca6e 100644
--- a/drivers/media/IR/ir-jvc-decoder.c
+++ b/drivers/media/IR/ir-jvc-decoder.c
@@ -50,8 +50,9 @@ static int ir_jvc_decode(struct input_dev *input_dev, struct 
ir_raw_event ev)
if (!(ir_dev->raw->enabled_protocols & IR_TYPE_JVC))
return 0;
 
-   if (IS_RESET(ev)) {
-   data->state = STATE_INACTIVE;
+   if (!is_timing_event(ev)) {
+   if (ev.reset)
+   data->state = STATE_INACTIVE;
return 0;
}
 
diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/IR/ir-lirc-codec.c
index e63f757..e6ca7a3 100644
--- a/drivers/media/IR/ir-lirc-codec.c
+++ b/drivers/media/IR/ir-lirc-codec.c
@@ -32,7 +32,9 @@
 static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
 {
struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+   struct lirc_codec *lirc = &ir_dev->raw->lirc;
int sample;
+   int duration_msec;
 
if (!(ir_dev->raw->enabled_protocols & IR_TYPE_LIRC))
return 0;
@@ -40,21 +42,56 @@ static int ir_lirc_decode(struct input_dev *input_dev, 
struct ir_raw_event ev)
if (!ir_dev->raw->lirc.drv || !ir_dev->raw->lirc.drv->rbuf)
return -EINVAL;
 
-   if (IS_RESET(ev))
+   duration_msec = DIV_ROUND_CLOSEST(ev.duration, 1000);
+
+   if (ev.reset)
return 0;
 
-   IR_dprintk(2, "LIRC data transfer started (%uus %s)\n",
-  TO_US(ev.duration), TO_STR(ev.pulse));
+   if (ev.carrier_report) {
+   /* TODO:

[PATCH 4/7] IR: fix keys beeing stuck down forever.

2010-08-30 Thread Maxim Levitsky
The logic in ir_timer_keyup was inverted.

In case that values aren't equal,
the meaning of the time_is_after_eq_jiffies(ir->keyup_jiffies) is that
ir->keyup_jiffies is after the the jiffies or equally that
that jiffies are before the the ir->keyup_jiffies which is
exactly the situation we want to avoid (that the timeout is in the future)
Confusing Eh?

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-keytable.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
index 3f0dd80..b5addb8 100644
--- a/drivers/media/IR/ir-keytable.c
+++ b/drivers/media/IR/ir-keytable.c
@@ -319,7 +319,7 @@ static void ir_timer_keyup(unsigned long cookie)
 * a keyup event might follow immediately after the keydown.
 */
spin_lock_irqsave(&ir->keylock, flags);
-   if (time_is_after_eq_jiffies(ir->keyup_jiffies))
+   if (time_is_before_eq_jiffies(ir->keyup_jiffies))
ir_keyup(ir);
spin_unlock_irqrestore(&ir->keylock, flags);
 }
-- 
1.7.0.4

--
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


[PATCH 1/7] IR: plug races in handling threads.

2010-08-30 Thread Maxim Levitsky
Unfortunelly (my fault) the kernel thread that now handles IR processing
has classical races in regard to wakeup and stop.
This patch hopefully closes them all.
Tested with module reload running in a loop, while receiver is blasted
with IR data for 10 minutes.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-core-priv.h |2 ++
 drivers/media/IR/ir-raw-event.c |   34 +-
 2 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index a85a8c7..761e7f4 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -17,6 +17,7 @@
 #define _IR_RAW_EVENT
 
 #include 
+#include 
 #include 
 
 struct ir_raw_handler {
@@ -33,6 +34,7 @@ struct ir_raw_handler {
 struct ir_raw_event_ctrl {
struct list_headlist;   /* to keep track of raw 
clients */
struct task_struct  *thread;
+   spinlock_t  lock;
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 */
diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
index 43094e7..56797be 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/IR/ir-raw-event.c
@@ -39,22 +39,34 @@ static int ir_raw_event_thread(void *data)
struct ir_raw_event ev;
struct ir_raw_handler *handler;
struct ir_raw_event_ctrl *raw = (struct ir_raw_event_ctrl *)data;
+   int retval;
 
while (!kthread_should_stop()) {
-   try_to_freeze();
 
-   mutex_lock(&ir_raw_handler_lock);
+   spin_lock_irq(&raw->lock);
+   retval = kfifo_out(&raw->kfifo, &ev, sizeof(ev));
+
+   if (!retval) {
+   set_current_state(TASK_INTERRUPTIBLE);
 
-   while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) {
-   list_for_each_entry(handler, &ir_raw_handler_list, list)
-   handler->decode(raw->input_dev, ev);
-   raw->prev_ev = ev;
+   if (kthread_should_stop())
+   set_current_state(TASK_RUNNING);
+
+   spin_unlock_irq(&raw->lock);
+   schedule();
+   continue;
}
 
-   mutex_unlock(&ir_raw_handler_lock);
+   spin_unlock_irq(&raw->lock);
 
-   set_current_state(TASK_INTERRUPTIBLE);
-   schedule();
+
+   BUG_ON(retval != sizeof(ev));
+
+   mutex_lock(&ir_raw_handler_lock);
+   list_for_each_entry(handler, &ir_raw_handler_list, list)
+   handler->decode(raw->input_dev, ev);
+   raw->prev_ev = ev;
+   mutex_unlock(&ir_raw_handler_lock);
}
 
return 0;
@@ -232,11 +244,14 @@ EXPORT_SYMBOL_GPL(ir_raw_event_set_idle);
 void ir_raw_event_handle(struct input_dev *input_dev)
 {
struct ir_input_dev *ir = input_get_drvdata(input_dev);
+   unsigned long flags;
 
if (!ir->raw)
return;
 
+   spin_lock_irqsave(&ir->raw->lock, flags);
wake_up_process(ir->raw->thread);
+   spin_unlock_irqrestore(&ir->raw->lock, flags);
 }
 EXPORT_SYMBOL_GPL(ir_raw_event_handle);
 
@@ -275,6 +290,7 @@ int ir_raw_event_register(struct input_dev *input_dev)
return rc;
}
 
+   spin_lock_init(&ir->raw->lock);
ir->raw->thread = kthread_run(ir_raw_event_thread, ir->raw,
"rc%u",  (unsigned int)ir->devno);
 
-- 
1.7.0.4

--
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


[PATCH 2/7] IR: make sure we register input device when it safe to do so.

2010-08-30 Thread Maxim Levitsky
As soon as input device is registered, it might be accessed (and it is)
This can trigger hardware interrupts for example that in turn
can access not yet initialized ir->raw.
Can be reproduced by holding down a remote button and reloading the module.
And always crashes the systems where hardware decides to send and interrupt
right at the moment it is enabled.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-core-priv.h |1 +
 drivers/media/IR/ir-keytable.c  |2 ++
 drivers/media/IR/ir-sysfs.c |   27 +--
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index 761e7f4..5d7e08f 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -116,6 +116,7 @@ static inline void decrease_duration(struct ir_raw_event 
*ev, unsigned duration)
  * Routines from ir-sysfs.c - Meant to be called only internally inside
  * ir-core
  */
+int ir_register_input(struct input_dev *input_dev);
 
 int ir_register_class(struct input_dev *input_dev);
 void ir_unregister_class(struct input_dev *input_dev);
diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
index 7e82a9d..3f0dd80 100644
--- a/drivers/media/IR/ir-keytable.c
+++ b/drivers/media/IR/ir-keytable.c
@@ -505,6 +505,8 @@ int __ir_input_register(struct input_dev *input_dev,
goto out_event;
}
 
+   rc = ir_register_input(input_dev);
+
IR_dprintk(1, "Registered input device on %s for %s remote%s.\n",
   driver_name, rc_tab->name,
   (ir_dev->props && ir_dev->props->driver_type == 
RC_DRIVER_IR_RAW) ?
diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c
index 96dafc4..c0075f1 100644
--- a/drivers/media/IR/ir-sysfs.c
+++ b/drivers/media/IR/ir-sysfs.c
@@ -251,8 +251,6 @@ static struct device_type rc_dev_type = {
  */
 int ir_register_class(struct input_dev *input_dev)
 {
-   int rc;
-   const char *path;
struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
int devno = find_first_zero_bit(&ir_core_dev_number,
IRRCV_NUM_DEVICES);
@@ -261,17 +259,28 @@ int ir_register_class(struct input_dev *input_dev)
return devno;
 
ir_dev->dev.type = &rc_dev_type;
+   ir_dev->devno = devno;
 
ir_dev->dev.class = &ir_input_class;
ir_dev->dev.parent = input_dev->dev.parent;
+   input_dev->dev.parent = &ir_dev->dev;
dev_set_name(&ir_dev->dev, "rc%d", devno);
dev_set_drvdata(&ir_dev->dev, ir_dev);
-   rc = device_register(&ir_dev->dev);
-   if (rc)
-   return rc;
+   return  device_register(&ir_dev->dev);
+};
+
+/**
+ * ir_register_input - registers ir input device with input subsystem
+ * @input_dev: the struct input_dev descriptor of the device
+ */
+
+int ir_register_input(struct input_dev *input_dev)
+{
+   struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+   int rc;
+   const char *path;
 
 
-   input_dev->dev.parent = &ir_dev->dev;
rc = input_register_device(input_dev);
if (rc < 0) {
device_del(&ir_dev->dev);
@@ -287,11 +296,9 @@ int ir_register_class(struct input_dev *input_dev)
path ? path : "N/A");
kfree(path);
 
-   ir_dev->devno = devno;
-   set_bit(devno, &ir_core_dev_number);
-
+   set_bit(ir_dev->devno, &ir_core_dev_number);
return 0;
-};
+}
 
 /**
  * ir_unregister_class() - removes the sysfs for sysfs for
-- 
1.7.0.4

--
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


[PATCH 3/7] IR: fix duty cycle capability

2010-08-30 Thread Maxim Levitsky
Due to typo lirc bridge enabled wrong capability.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-lirc-codec.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/IR/ir-lirc-codec.c
index 77b5946..e63f757 100644
--- a/drivers/media/IR/ir-lirc-codec.c
+++ b/drivers/media/IR/ir-lirc-codec.c
@@ -267,7 +267,7 @@ static int ir_lirc_register(struct input_dev *input_dev)
features |= LIRC_CAN_SET_SEND_CARRIER;
 
if (ir_dev->props->s_tx_duty_cycle)
-   features |= LIRC_CAN_SET_REC_DUTY_CYCLE;
+   features |= LIRC_CAN_SET_SEND_DUTY_CYCLE;
}
 
if (ir_dev->props->s_rx_carrier_range)
-- 
1.7.0.4

--
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


Many fixes for in-kernel decoding + ENE driver

2010-08-30 Thread Maxim Levitsky
Hi,

I did a lot of debug work on this, including a debug session with two users.
I was able to test and fix support for all features ene driver supports.

The patch #1 fixes a bug I introduced
The patch #2 fixes a nasty bug that crashes the system
The patch #3 fixes another small bug in my code
The patch #4 fixes a nasty but that appears as a stuck down forever key

The patch #5 adds a lot of bugfixes, refactoring and support for latest firmware
that without it driver dosn't work.
Driver is fully tested, and works.

in the patch #6 I finally decided to extend ir_raw_event, and encode additional
flags to it. This way I can signal the decoders about last space and yet not
show it up on lirc interface.
Timeout hangling is now moved in lirc bridge where it belongs.
While at it, I also added support for carrier report events,
and patch #6 adds that support to ene driver (tested too).

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: Remote that breaks current system

2010-08-16 Thread Maxim Levitsky
On Mon, 2010-08-16 at 00:04 -0400, Jarod Wilson wrote: 
> On Thu, Aug 12, 2010 at 2:46 AM, Christoph Bartelmus  
> wrote:
> ...
> >> So I spent a while beating on things the past few nights for giggles
> >> (and for a sanity break from "vacation" with too many kids...). I
> >> ended up doing a rather large amount of somewhat invasive work to the
> >> streamzap driver itself, but the end result is functional in-kernel
> >> decoding, and lirc userspace decode continues to behave correctly. RFC
> >> patch here:
> >>
> >> http://wilsonet.com/jarod/ir-core/IR-streamzap-in-kernel-decode.patch
> >>
> >> Core changes to streamzap.c itself:
> >>
> >> - had to enable reporting of a long space at the conclusion of each
> >> signal (which is what the lirc driver would do w/timeout_enabled set),
> >> otherwise I kept having issues with key bounce and/or old data being
> >> buffered (i.e., press up, cursor moves up. push down, cursor moves up
> >> then down, press left, it moves down, then left, etc.). Still not
> >> quite sure what the real problem is there, the lirc userspace decoder
> >> has no problems with it either way.
> >>
> >> - removed streamzap's internal delay buffer, as the ir-core kfifo
> >> seems to provide the necessary signal buffering just fine by itself.
> >> Can't see any significant difference in decode performance either
> >> in-kernel or via lirc with it removed, anyway. (Christoph, can you
> >> perhaps expand a bit on why the delay buffer was originally needed/how
> >> to reproduce the problem it was intended to solve? Maybe I'm just not
> >> triggering it yet.)
> >
> > Should be fine. Current lircd with timeout support shouldn't have a
> > problem with that anymore. I was already thinking of suggesting to remove
> > the delay buffer.
> 
> Cool, sounds like a plan then, I'll go ahead with it.
> 
> >> Other fun stuff to note:
> >>
> >> - currently, loading up an rc5-sz decoder unconditionally, have
> >> considered only auto-loading it from the streamzap driver itself. Its
> >> a copy of the rc5 decoder with relatively minor tweaks to deal with
> >> the extra bit and resulting slightly different bit layout. Might
> >> actually be possible to merge back into the rc5 decoder itself,
> >> haven't really looked into that yet (should be entirely doable if
> >> there's an easy way to figure out early on if we need to grab 14
> >> bits).
> >
> > There is no way until you see the 14th bit.
> 
> Hm. Was afraid of that. I gave it a shot to see if I could make that
> work, pretty shaky results. About 2/3 of the keys get decoded as
> 15-bit streamzap, the other 1/3 get decoded as 14-bit RC5, and don't
> match anything in the keytable (and often duplicate one another). So
> it looks like at least for the time being, a separate parallel decoder
> is the way to go. I'm thinking that I like the approach of only
> explicitly loading it from the streamzap driver though.

Just one minor nitpick.
You could 'use' the original RC5 decoder, but add a knob to it to make
it accept 15 bits instead of 14.
However, this will require some interface changes.


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] IR: ene_ir: problems in unwinding on probe

2010-08-12 Thread Maxim Levitsky
On Thu, 2010-08-12 at 18:19 +0200, Dan Carpenter wrote: 
> On Thu, Aug 12, 2010 at 05:35:04PM +0300, Maxim Levitsky wrote:
> > On Thu, 2010-08-12 at 09:46 +0200, Dan Carpenter wrote: 
> > > There were a couple issues here.  If the allocation failed for "dev"
> > > then it would lead to a NULL dereference.  If request_irq() or
> > > request_region() failed it would release the irq and the region even
> > > though they were not successfully aquired.
> > > 
> > > Signed-off-by: Dan Carpenter 
> > 
> > I don't think this is needed.
> > I just alloc all the stuff, and if one of allocations fail, I free them
> > all. {k}free on NULL pointer is perfectly legal.
> > 
> > Same about IO and IRQ.
> > IRQ0 and IO 0 isn't valid, and I do test that in error path.
> > 
> >
> 
> Here is the original code:
> 
> Here is where we set "dev".
> 
>785  dev = kzalloc(sizeof(struct ene_device), GFP_KERNEL);
>786  
>787  if (!input_dev || !ir_props || !dev)
>788  goto error;
> 
>   [snip]
> 
> Here is where we set the IO and IRQ:
> 
>800  dev->hw_io = pnp_port_start(pnp_dev, 0);
>801  dev->irq = pnp_irq(pnp_dev, 0);
> 
>   [snip]
> 
> Here is where the request_region() and request_irq() are.
> 
>806  if (!request_region(dev->hw_io, ENE_MAX_IO, ENE_DRIVER_NAME))
>807  goto error;
>808  
>809  if (request_irq(dev->irq, ene_isr, 
>810  IRQF_SHARED, ENE_DRIVER_NAME, (void *)dev))
>811  goto error;
> 
>   [snip]
> 
> Here is the error label:
> 
>897  error:
>898  if (dev->irq)
>   
> 
>   Oops!  The allocation of dev failed and this is a NULL
>   dereference.
> 
>899  free_irq(dev->irq, dev);
> 
>   Oops!  Request region failed and dev->irq is non-zero but
>   request_irq() hasn't been called.
> 
>900  if (dev->hw_io)
>901  release_region(dev->hw_io, ENE_MAX_IO);
> 
>   Oops! dev->hw_io is non-zero but request_region() failed and so
>   we just released someone else's region.


Ok, this is something different.
To be honest I was in hurry when I prepared the patch, so I didn't look
at this.
The intent was correct, and untill you pointed that out I somehow
assumed that error patch does what I supposed it to do... well...
In few days I will switch back to this driver and fix this problem.
I also have quite a lot of work to do in this driver now that I have
some hardware documentation (register renames are the fun part...).

So thanks for catching this.

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] IR: ene_ir: problems in unwinding on probe

2010-08-12 Thread Maxim Levitsky
On Thu, 2010-08-12 at 09:46 +0200, Dan Carpenter wrote: 
> There were a couple issues here.  If the allocation failed for "dev"
> then it would lead to a NULL dereference.  If request_irq() or
> request_region() failed it would release the irq and the region even
> though they were not successfully aquired.
> 
> Signed-off-by: Dan Carpenter 

I don't think this is needed.
I just alloc all the stuff, and if one of allocations fail, I free them
all. {k}free on NULL pointer is perfectly legal.

Same about IO and IRQ.
IRQ0 and IO 0 isn't valid, and I do test that in error path.


Best regards,
Maxim Levitsky


> 
> diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
> index 5447750..8e5e964 100644
> --- a/drivers/media/IR/ene_ir.c
> +++ b/drivers/media/IR/ene_ir.c
> @@ -781,21 +781,24 @@ static int ene_probe(struct pnp_dev *pnp_dev, const 
> struct pnp_device_id *id)
>  
>   /* allocate memory */
>   input_dev = input_allocate_device();
> + if (!input_dev)
> + goto err_out;
>   ir_props = kzalloc(sizeof(struct ir_dev_props), GFP_KERNEL);
> + if (!ir_props)
> + goto err_input_dev;
>   dev = kzalloc(sizeof(struct ene_device), GFP_KERNEL);
> -
> - if (!input_dev || !ir_props || !dev)
> - goto error;
> + if (!dev)
> + goto err_ir_props;
>  
>   /* validate resources */
>   error = -ENODEV;
>  
>   if (!pnp_port_valid(pnp_dev, 0) ||
>   pnp_port_len(pnp_dev, 0) < ENE_MAX_IO)
> - goto error;
> + goto err_dev;
>  
>   if (!pnp_irq_valid(pnp_dev, 0))
> - goto error;
> + goto err_dev;
>  
>   dev->hw_io = pnp_port_start(pnp_dev, 0);
>   dev->irq = pnp_irq(pnp_dev, 0);
> @@ -804,11 +807,11 @@ static int ene_probe(struct pnp_dev *pnp_dev, const 
> struct pnp_device_id *id)
>   /* claim the resources */
>   error = -EBUSY;
>   if (!request_region(dev->hw_io, ENE_MAX_IO, ENE_DRIVER_NAME))
> - goto error;
> + goto err_dev;
>  
>   if (request_irq(dev->irq, ene_isr,
>   IRQF_SHARED, ENE_DRIVER_NAME, (void *)dev))
> - goto error;
> + goto err_region;
>  
>   pnp_set_drvdata(pnp_dev, dev);
>   dev->pnp_dev = pnp_dev;
> @@ -816,7 +819,7 @@ static int ene_probe(struct pnp_dev *pnp_dev, const 
> struct pnp_device_id *id)
>   /* detect hardware version and features */
>   error = ene_hw_detect(dev);
>   if (error)
> - goto error;
> + goto err_irq;
>  
>   ene_setup_settings(dev);
>  
> @@ -889,20 +892,22 @@ static int ene_probe(struct pnp_dev *pnp_dev, const 
> struct pnp_device_id *id)
>   error = -ENODEV;
>   if (ir_input_register(input_dev, RC_MAP_RC6_MCE, ir_props,
>   ENE_DRIVER_NAME))
> - goto error;
> -
> + goto err_irq;
>  
>   ene_printk(KERN_NOTICE, "driver has been succesfully loaded\n");
>   return 0;
> -error:
> - if (dev->irq)
> - free_irq(dev->irq, dev);
> - if (dev->hw_io)
> - release_region(dev->hw_io, ENE_MAX_IO);
>  
> - input_free_device(input_dev);
> - kfree(ir_props);
> +err_irq:
> + free_irq(dev->irq, dev);
> +err_region:
> + release_region(dev->hw_io, ENE_MAX_IO);
> +err_dev:
>   kfree(dev);
> +err_ir_props:
> + kfree(ir_props);
> +err_input_dev:
> + input_free_device(input_dev);
> +err_out:
>   return error;
>  }
>  


--
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 09/13] IR: add helper function for hardware with small o/b buffer.

2010-08-02 Thread Maxim Levitsky
On Sun, 2010-08-01 at 22:11 -0400, Andy Walls wrote: 
> On Sat, 2010-07-31 at 17:59 +0300, Maxim Levitsky wrote:
> > Some ir input devices have small buffer, and interrupt the host
> > each time it is full (or half full)
> > 
> > Add a helper that automaticly handles timeouts, and also
> > automaticly merges samples of same time (space-space)
> > Such samples might be placed by hardware because size of
> > sample in the buffer is small (a byte for example).
> > 
> > Also remove constness from ir_dev_props, because it now contains timeout
> > settings that driver might want to change
> > 
> > Signed-off-by: Maxim Levitsky 
> > Acked-by: Jarod Wilson 
> 
> Hi Maxim and Jarod,
> 
> I've started looking at this patch, and patch 10/13, to work with them
> and build upon them.  I have some comments, below:
> 
> 
> > ---
> >  drivers/media/IR/ir-core-priv.h |1 +
> >  drivers/media/IR/ir-keytable.c  |2 +-
> >  drivers/media/IR/ir-raw-event.c |   84 
> > +++
> >  include/media/ir-core.h |   23 +-
> >  4 files changed, 106 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/media/IR/ir-core-priv.h 
> > b/drivers/media/IR/ir-core-priv.h
> > index be68172..8053e3b 100644
> > --- a/drivers/media/IR/ir-core-priv.h
> > +++ b/drivers/media/IR/ir-core-priv.h
> > @@ -41,6 +41,7 @@ struct ir_raw_event_ctrl {
> >  
> > /* raw decoder state follows */
> > struct ir_raw_event prev_ev;
> > +   struct ir_raw_event this_ev;
> > struct nec_dec {
> > int state;
> > unsigned count;
> > 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 d0c18db..43094e7 100644
> > --- a/drivers/media/IR/ir-raw-event.c
> > +++ b/drivers/media/IR/ir-raw-event.c
> > @@ -140,6 +140,90 @@ 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) works
> > + * in similiar manner to ir_raw_event_store_edge.
> > + * This routine is intended for devices with limited internal buffer
> > + * It automerges samples of same type, and handles timeouts
> > + */
> 
> I think this comment might need to explain the filtering being performed
> a little more explicitly, because "handles timeouts" wasn't enough to go
> on.
> 
> >From what I can tell, it performs
> 
>   a. space aggrregation
>   b. auto "idle" of the receiver and some state
>   c. gap measurment and gap space event generation
>   d, decoder reset at the end of the gap
> 
> (For my needs, c. is very useful, and a. & d. don't hurt.)
> 
> What is idle supposed to do for hardware that provides interrupts?
In my case, I can program hardware not to interrupt host until it has
a sample that isn't a overflow sample
Exaplanation what overflow sample is:
Hardware stores samples in small 8 bytes buffer, and has a  flag which
half of this buffer to read.
Each sample is 8 bits, out of which 7 are timing and 8th is pulse/space.
So larger sample is sample period * 127.
If hardware wants to send larger sample, it sends this sample, and
another.
When I enable idle mode, it won't send sample with 127 within them.
Note that this is only supported on my receiver. Newer receivers don't
have that function, but rather stop sending samples on their own after
about 250 ms.



> 
> Aside from asking the hardware driver to do something, idle otherwise
> appears to be used to keep track of being in a gap or not.
> Did I get that all right?
Yes of course.

> 

Re: [PATCH 13/13] IR: Port ene driver to new IR subsystem and enable it.

2010-07-31 Thread Maxim Levitsky
On Sat, 2010-07-31 at 17:53 -0400, Jon Smirl wrote: 
> On Sat, Jul 31, 2010 at 2:51 PM, Andy Walls  wrote:
> > On Sat, 2010-07-31 at 14:14 -0400, Jon Smirl wrote:
> >> On Sat, Jul 31, 2010 at 1:47 PM, Christoph Bartelmus  
> >> wrote:
> >> > Hi Jon,
> >> >
> >> > on 31 Jul 10 at 12:25, Jon Smirl wrote:
> >> >> On Sat, Jul 31, 2010 at 11:12 AM, Andy Walls 
> >> >> wrote:
> >> >>> I think you won't be able to fix the problem conclusively either way.  
> >> >>> A
> >> >>> lot of how the chip's clocks should be programmed depends on how the
> >> >>> GPIOs are used and what crystal is used.
> >> >>>
> >> >>> I suspect many designers will use some reference design layout from 
> >> >>> ENE,
> >> >>> but it won't be good in every case.  The wire-up of the ENE of various
> >> >>> motherboards is likely something you'll have to live with as unknowns.
> >> >>>
> >> >>> This is a case where looser tolerances in the in kernel decoders could
> >> >>> reduce this driver's complexity and/or get rid of arbitrary fudge
> >> >>> factors in the driver.
> >> >
> >> >> The tolerances are as loose as they can be. The NEC protocol uses
> >> >> pulses that are 4% longer than JVC. The decoders allow errors up to 2%
> >> >> (50% of 4%).  The crystals used in electronics are accurate to
> >> >> 0.0001%+.
> >> >
> >> > But the standard IR receivers are far from being accurate enough to allow
> >> > tolerance windows of only 2%.
> >> > I'm surprised that this works for you. LIRC uses a standard tolerance of
> >> > 30% / 100 us and even this is not enough sometimes.
> >> >
> >> > For the NEC protocol one signal consists of 22 individual pulses at 
> >> > 38kHz.
> >> > If the receiver just misses one pulse, you already have an error of 1/22
> >> >> 4%.
> >>
> >> There are different types of errors. The decoders can take large
> >> variations in bit times. The problem is with cumulative errors. In
> >> this case the error had accumulated up to 450us in the lead pulse.
> >> That's just too big of an error
> >
> > Hi Jon,
> >
> > Hmmm.  Leader marks are, by protocol design, there to give time for the
> > receiver's AGC to settle.  We should make it OK to miss somewhat large
> > portions of leader marks.  I'm not sure what the harm is in accepting
> > too long of a leader mark, but I'm pretty sure a leader mark that is too
> > long will always be due to systematic error and not noise errors.
> >
> > However, if we know we have systematic errors caused by unknowns, we
> > should be designing and implementing a decoding system that reasonably
> > deals with those systematic errors.  Again the part of the system almost
> > completely out of our control is the remote controls, and we *have no
> > control* over systematic errors introduced by remotes.
> 
> We haven't encountered remotes with systematic errors. If remotes had
> large errors in them they wouldn't be able to reliably control their
> target devices. Find a remote that won't work with the protocol
> engines and a reasonably accurate receiver.
> 
> >
> > Obviously we want to reduce or eliminate systematic errors by
> > determining the unknowns and undoing their effects or by compensating
> > for their overall effect.  But in the case of the ENE receiver driver,
> > you didn't seem to like the Maxim's software compensation for the
> > systematic receiver errors.
> 
> I would be happier if we could track down the source of the error
> instead of sticking a bandaid on at the end of the process.
This isn't a bandaid.
Windows driver programs the period to 52 but treats it as a 50.
(I don't do that because I set period to 75 - otherwise leading pulse of
NEC/JVC is almost missing. I know the reason for that, and it isn't
important).




> 
> >> and caused the JVC code to be
> >> misclassified as NEC.
> >
> > I still have not heard why we need protocol discrimination/classifcation
> > in the kernel.  Doing discrimination between two protocols with such
> > close timings is whose requirement again?
> 
> If we don't do protocol engines we have to revert back to raw
> recording and having everyone train the system with their remotes. The
> goal is to eliminate the training step. We would also have to have
> large files (LIRC configs) for building the keymaps and a new API to
> deal with them. With the engines the key presses are identified by
> short strings.
> 
> A use case: install mythtv, add an IR receiver. Myth UI says to set
> your universal remote to a Motorola DVR profile. Remote works - no
> training step needed.
> 
> LIRC has protocol engines too. irrecord first tries to fit the remote
> into a protocol engine. If it can't it reverts to raw mode. Let's
> analyze those cases where lirc ends up in raw mode and see if we can
> figure out what's going wrong.
> 
> For example I know of two things that will trip up irrecord that are
> fixed in the kernel system
> 1) the ene driver. we know now it had a 4% error in the reported periods
No it doesn't
It even works if leading large pulse is

Re: [PATCH 13/13] IR: Port ene driver to new IR subsystem and enable it.

2010-07-31 Thread Maxim Levitsky
On Sat, 2010-07-31 at 12:25 -0400, Jon Smirl wrote: 
> On Sat, Jul 31, 2010 at 11:12 AM, Andy Walls  wrote:
> > I think you won't be able to fix the problem conclusively either way.  A
> > lot of how the chip's clocks should be programmed depends on how the
> > GPIOs are used and what crystal is used.
> >
> > I suspect many designers will use some reference design layout from ENE,
> > but it won't be good in every case.  The wire-up of the ENE of various
> > motherboards is likely something you'll have to live with as unknowns.
> >
> > This is a case where looser tolerances in the in kernel decoders could
> > reduce this driver's complexity and/or get rid of arbitrary fudge
> > factors in the driver.
> 
> The tolerances are as loose as they can be. The NEC protocol uses
> pulses that are 4% longer than JVC. The decoders allow errors up to 2%
> (50% of 4%).  The crystals used in electronics are accurate to
> 0.0001%+.  The 4% error in this driver is because the hardware is not
> being programmed accurately. This needs to be fixed in the driver and
> not in the upper layers.
> 
> How is sample period being computed, where is the complete source to
> this driver?
> 
>dev->tx_period = 32;
> 
> Where is sample_period computed?
> 
> @@ -672,13 +583,25 @@ static irqreturn_t ene_isr(int irq, void *data)
>pulse = !(hw_value & ENE_SAMPLE_SPC_MASK);
>hw_value &= ENE_SAMPLE_VALUE_MASK;
>hw_sample = hw_value * sample_period;
> +
> +   if (dev->rx_period_adjust) {
> +   hw_sample *= (100 - dev->rx_period_adjust);
> +   hw_sample /= 100;
> +   }
>}
> 
> I suspect sample_period is set to 32us. For 32.768Mhz the period needs
> to be 30.5us. I don't see the code for how it was computed.
> 
> You have to be careful with rounding errors when doing this type of
> computation. What looks like a minor error can amplify into a large
> error. Sometimes I do the math in 64b ints just to keep the round off
> errors from accumulating.  Instead of doing the math in calculator and
> plugging in 32. Use #defines and do the math in the
There is no reason to worry about rounding here.

hw_sample is maximum of 127 * 50, so when I muliply by 100 I get exact
result.
Then I do one divide.

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 13/13] IR: Port ene driver to new IR subsystem and enable it.

2010-07-31 Thread Maxim Levitsky
On Sat, 2010-07-31 at 12:25 -0400, Jon Smirl wrote: 
> On Sat, Jul 31, 2010 at 11:12 AM, Andy Walls  wrote:
> > I think you won't be able to fix the problem conclusively either way.  A
> > lot of how the chip's clocks should be programmed depends on how the
> > GPIOs are used and what crystal is used.
> >
> > I suspect many designers will use some reference design layout from ENE,
> > but it won't be good in every case.  The wire-up of the ENE of various
> > motherboards is likely something you'll have to live with as unknowns.
> >
> > This is a case where looser tolerances in the in kernel decoders could
> > reduce this driver's complexity and/or get rid of arbitrary fudge
> > factors in the driver.
> 
> The tolerances are as loose as they can be. The NEC protocol uses
> pulses that are 4% longer than JVC. The decoders allow errors up to 2%
> (50% of 4%).  The crystals used in electronics are accurate to
> 0.0001%+.  The 4% error in this driver is because the hardware is not
> being programmed accurately. This needs to be fixed in the driver and
> not in the upper layers.

Let me explain again.

I get samples in 4 byte buffer. each sample is a count of sample
periods.
Sample period is programmed into hardware, at 'ENE_CIR_SAMPLE_PERIOD'
(it is in us)

Default sample period is 50 us.

The error source isn't 'electronics' fault.
The device is microprocessor.
I don't read the samples 'directly' from hardware, but rather from ram
of that microprocessor.
I don't know how it samples the input.
A expiration of sample period might just cause a IRQ inside that
microprocessor, and it can't process it instantly. That is probably the
source of the delay.
Or something like that.

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


[PATCH 08/13] IR: Allow not to compile keymaps in.

2010-07-31 Thread Maxim Levitsky
Currently, ir device registration fails if keymap requested by driver is not 
found.
Fix that by always compiling in the empty keymap, and using it as a failback.

Signed-off-by: Maxim Levitsky 
Acked-by: Jarod Wilson 
---
 drivers/media/IR/ir-core-priv.h |3 +-
 drivers/media/IR/ir-sysfs.c |2 +
 drivers/media/IR/keymaps/Makefile   |1 -
 drivers/media/IR/keymaps/rc-empty.c |   44 ---
 drivers/media/IR/rc-map.c   |   23 ++
 include/media/ir-core.h |8 -
 6 files changed, 33 insertions(+), 48 deletions(-)
 delete mode 100644 drivers/media/IR/keymaps/rc-empty.c

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index 502d477..be68172 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -126,7 +126,8 @@ int ir_raw_handler_register(struct ir_raw_handler 
*ir_raw_handler);
 void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler);
 void ir_raw_init(void);
 
-
+int ir_rcmap_init(void);
+void ir_rcmap_cleanup(void);
 /*
  * Decoder initialization code
  *
diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c
index a841e51..936dff8 100644
--- a/drivers/media/IR/ir-sysfs.c
+++ b/drivers/media/IR/ir-sysfs.c
@@ -341,6 +341,7 @@ static int __init ir_core_init(void)
 
/* Initialize/load the decoders/keymap code that will be used */
ir_raw_init();
+   ir_rcmap_init();
 
return 0;
 }
@@ -348,6 +349,7 @@ static int __init ir_core_init(void)
 static void __exit ir_core_exit(void)
 {
class_unregister(&ir_input_class);
+   ir_rcmap_cleanup();
 }
 
 module_init(ir_core_init);
diff --git a/drivers/media/IR/keymaps/Makefile 
b/drivers/media/IR/keymaps/Makefile
index 86d3d1f..24992cd 100644
--- a/drivers/media/IR/keymaps/Makefile
+++ b/drivers/media/IR/keymaps/Makefile
@@ -17,7 +17,6 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
rc-dm1105-nec.o \
rc-dntv-live-dvb-t.o \
rc-dntv-live-dvbt-pro.o \
-   rc-empty.o \
rc-em-terratec.o \
rc-encore-enltv2.o \
rc-encore-enltv.o \
diff --git a/drivers/media/IR/keymaps/rc-empty.c 
b/drivers/media/IR/keymaps/rc-empty.c
deleted file mode 100644
index 3b338d8..000
--- a/drivers/media/IR/keymaps/rc-empty.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/* empty.h - Keytable for empty Remote Controller
- *
- * keymap imported from ir-keymaps.c
- *
- * Copyright (c) 2010 by Mauro Carvalho Chehab 
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#include 
-
-/* empty keytable, can be used as placeholder for not-yet created keytables */
-
-static struct ir_scancode empty[] = {
-   { 0x2a, KEY_COFFEE },
-};
-
-static struct rc_keymap empty_map = {
-   .map = {
-   .scan= empty,
-   .size= ARRAY_SIZE(empty),
-   .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */
-   .name= RC_MAP_EMPTY,
-   }
-};
-
-static int __init init_rc_map_empty(void)
-{
-   return ir_register_map(&empty_map);
-}
-
-static void __exit exit_rc_map_empty(void)
-{
-   ir_unregister_map(&empty_map);
-}
-
-module_init(init_rc_map_empty)
-module_exit(exit_rc_map_empty)
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Mauro Carvalho Chehab ");
diff --git a/drivers/media/IR/rc-map.c b/drivers/media/IR/rc-map.c
index 46a8f15..689143f 100644
--- a/drivers/media/IR/rc-map.c
+++ b/drivers/media/IR/rc-map.c
@@ -82,3 +82,26 @@ void ir_unregister_map(struct rc_keymap *map)
 }
 EXPORT_SYMBOL_GPL(ir_unregister_map);
 
+
+static struct ir_scancode empty[] = {
+   { 0x2a, KEY_COFFEE },
+};
+
+static struct rc_keymap empty_map = {
+   .map = {
+   .scan= empty,
+   .size= ARRAY_SIZE(empty),
+   .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */
+   .name= RC_MAP_EMPTY,
+   }
+};
+
+int ir_rcmap_init(void)
+{
+   return ir_register_map(&empty_map);
+}
+
+void ir_rcmap_cleanup(void)
+{
+   ir_unregister_map(&empty_map);
+}
diff --git a/include/media/ir-core.h b/include/media/ir-core.h
index 513e60d..197d05a 100644
--- a/include/media/ir-core.h
+++ b/include/media/ir-core.h
@@ -110,8 +110,12 @@ static inline int ir_input_register(struct input_dev *dev,
return -EINVAL;
 
ir_codes = get_rc_map(map_name);
-   if (!ir_codes)
-   return -EINVAL;
+   if (!ir_codes) {
+   ir_codes = get_rc_map(RC_MAP_EMPTY);
+
+   if (!ir_codes)
+   return -EINVAL;
+   }
 
rc = 

[PATCH 09/13] IR: add helper function for hardware with small o/b buffer.

2010-07-31 Thread Maxim Levitsky
Some ir input devices have small buffer, and interrupt the host
each time it is full (or half full)

Add a helper that automaticly handles timeouts, and also
automaticly merges samples of same time (space-space)
Such samples might be placed by hardware because size of
sample in the buffer is small (a byte for example).

Also remove constness from ir_dev_props, because it now contains timeout
settings that driver might want to change

Signed-off-by: Maxim Levitsky 
Acked-by: Jarod Wilson 
---
 drivers/media/IR/ir-core-priv.h |1 +
 drivers/media/IR/ir-keytable.c  |2 +-
 drivers/media/IR/ir-raw-event.c |   84 +++
 include/media/ir-core.h |   23 +-
 4 files changed, 106 insertions(+), 4 deletions(-)

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index be68172..8053e3b 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -41,6 +41,7 @@ struct ir_raw_event_ctrl {
 
/* raw decoder state follows */
struct ir_raw_event prev_ev;
+   struct ir_raw_event this_ev;
struct nec_dec {
int state;
unsigned count;
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 d0c18db..43094e7 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/IR/ir-raw-event.c
@@ -140,6 +140,90 @@ 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) works
+ * in similiar manner to ir_raw_event_store_edge.
+ * 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 (!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->this_ev.duration) {
+   raw->this_ev = *ev;
+   } else if (ev->pulse == raw->this_ev.pulse) {
+   raw->this_ev.duration += ev->duration;
+   } else {
+   ir_raw_event_store(input_dev, &raw->this_ev);
+   raw->this_ev = *ev;
+   }
+
+   /* Enter idle mode if nessesary */
+   if (!ev->pulse && ir->props->timeout &&
+   raw->this_ev.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->this_ev.pulse);
+
+   raw->this_ev.duration =
+   min(raw->this_ev.duration + delta,
+   (u64)IR_MAX_DURATION);
+
+   ir_raw_event_store(input_dev, &raw->this_ev);
+
+   if (raw->this_ev.duration == IR_MAX_DURATION)
+   ir_raw_event_reset(input_dev);
+
+   raw->this_ev.duration = 0;
+   }
+out:
+   if (ir->props->s_idle)
+   ir->props->s_idle(ir->pro

[PATCH 13/13] IR: Port ene driver to new IR subsystem and enable it.

2010-07-31 Thread Maxim Levitsky
Signed-off-by: Maxim Levitsky 
---
 MAINTAINERS   |6 +
 drivers/media/IR/Kconfig  |   14 +
 drivers/media/IR/Makefile |1 +
 drivers/media/IR/ene_ir.c |  595 +
 drivers/media/IR/ene_ir.h |   51 ++---
 5 files changed, 265 insertions(+), 402 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 56a36d7..587785a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2188,6 +2188,12 @@ F:   drivers/misc/cb710/
 F: drivers/mmc/host/cb710-mmc.*
 F: include/linux/cb710.h
 
+ENE KB2426 (ENE0100/ENE020XX) INFRARED RECEIVER
+M: Maxim Levitsky 
+S: Maintained
+F: drivers/media/IR/ene_ir.c
+F: drivers/media/IR/ene_ir.h
+
 EPSON 1355 FRAMEBUFFER DRIVER
 M: Christopher Hoover 
 M: Christopher Hoover 
diff --git a/drivers/media/IR/Kconfig b/drivers/media/IR/Kconfig
index fc48a3f..3f62bf9 100644
--- a/drivers/media/IR/Kconfig
+++ b/drivers/media/IR/Kconfig
@@ -105,4 +105,18 @@ config IR_MCEUSB
   To compile this driver as a module, choose M here: the
   module will be called mceusb.
 
+config IR_ENE
+   tristate "ENE eHome Receiver/Transciever (pnp id: ENE0100/ENE02xxx)"
+   depends on PNP
+   depends on IR_CORE
+   ---help---
+  Say Y here to enable support for integrated infrared receiver
+  /transciever made by ENE.
+
+  You can see if you have it by looking at lspnp output.
+  Output should include ENE0100 ENE0200 or something similiar.
+
+  To compile this driver as a module, choose M here: the
+  module will be called ene_ir.
+
 endif #IR_CORE
diff --git a/drivers/media/IR/Makefile b/drivers/media/IR/Makefile
index 2ae4f3a..3262a68 100644
--- a/drivers/media/IR/Makefile
+++ b/drivers/media/IR/Makefile
@@ -16,3 +16,4 @@ obj-$(CONFIG_IR_LIRC_CODEC) += ir-lirc-codec.o
 # stand-alone IR receivers/transmitters
 obj-$(CONFIG_IR_IMON) += imon.o
 obj-$(CONFIG_IR_MCEUSB) += mceusb.o
+obj-$(CONFIG_IR_ENE) += ene_ir.o
diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index 9d11caf..5447750 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -1,5 +1,5 @@
 /*
- * driver for ENE KB3926 B/C/D CIR (also known as ENE0100/ENE0200/ENE0201)
+ * driver for ENE KB3926 B/C/D CIR (pnp id: ENE0XXX)
  *
  * Copyright (C) 2010 Maxim Levitsky 
  *
@@ -25,20 +25,20 @@
 #include 
 #include 
 #include 
-#include 
-#include "lirc_ene0100.h"
+#include 
+#include 
+#include 
+#include 
+#include "ene_ir.h"
 
 
 static int sample_period = -1;
 static int enable_idle = 1;
-static int enable_duty_carrier;
 static int input = 1;
 static int debug;
 static int txsim;
 
-static void ene_rx_set_idle(struct ene_device *dev, int idle);
 static int ene_irq_status(struct ene_device *dev);
-static void ene_send_sample(struct ene_device *dev, unsigned long sample);
 
 /* read a hardware register */
 static u8 ene_hw_read_reg(struct ene_device *dev, u16 reg)
@@ -85,6 +85,7 @@ static int ene_hw_detect(struct ene_device *dev)
u8 hw_revision, old_ver;
u8 tmp;
u8 fw_capabilities;
+   int pll_freq;
 
tmp = ene_hw_read_reg(dev, ENE_HW_UNK);
ene_hw_write_reg(dev, ENE_HW_UNK, tmp & ~ENE_HW_UNK_CLR);
@@ -96,6 +97,17 @@ static int ene_hw_detect(struct ene_device *dev)
hw_revision = ene_hw_read_reg(dev, ENE_HW_VERSION);
old_ver = ene_hw_read_reg(dev, ENE_HW_VER_OLD);
 
+   pll_freq = (ene_hw_read_reg(dev, ENE_PLLFRH) << 4) +
+   (ene_hw_read_reg(dev, ENE_PLLFRL) >> 4);
+
+   if (pll_freq != 1000)
+   dev->rx_period_adjust = 4;
+   else
+   dev->rx_period_adjust = 2;
+
+
+   ene_printk(KERN_NOTICE, "PLL freq = %d\n", pll_freq);
+
if (hw_revision == 0xFF) {
 
ene_printk(KERN_WARNING, "device seems to be disabled\n");
@@ -160,7 +172,7 @@ static int ene_hw_detect(struct ene_device *dev)
 }
 
 /* this enables/disables IR input via gpio40*/
-static void ene_enable_gpio40_recieve(struct ene_device *dev, int enable)
+static void ene_enable_gpio40_receive(struct ene_device *dev, int enable)
 {
ene_hw_write_reg_mask(dev, ENE_CIR_CONF2, enable ?
  0 : ENE_CIR_CONF2_GPIO40DIS,
@@ -168,13 +180,13 @@ static void ene_enable_gpio40_recieve(struct ene_device 
*dev, int enable)
 }
 
 /* this enables/disables IR via standard input */
-static void ene_enable_normal_recieve(struct ene_device *dev, int enable)
+static void ene_enable_normal_receive(struct ene_device *dev, int enable)
 {
ene_hw_write_reg(dev, ENE_CIR_CONF1, enable ? ENE_CIR_CONF1_RX_ON : 0);
 }
 
 /* this enables/disables IR input via unused fan tachtometer input */
-static void ene_enable_fan_recieve(struct ene_device *dev, int enable)
+static void ene_enable_fan_receive(struct ene_device *dev, int enable)
 {
if (!enable)
e

[PATCH 10/13] IR: extend interfaces to support more device settings

2010-07-31 Thread Maxim Levitsky
LIRC: add new IOCTL that enables learning mode (wide band receiver)
Still missing features: carrier report & timeout reports.
Will need to pack these into ir_raw_event


Signed-off-by: Maxim Levitsky 
---
 .../DocBook/v4l/lirc_device_interface.xml  |   16 +++
 drivers/media/IR/ir-core-priv.h|1 +
 drivers/media/IR/ir-lirc-codec.c   |  112 
 include/media/ir-core.h|   12 ++-
 include/media/lirc.h   |5 +-
 5 files changed, 125 insertions(+), 21 deletions(-)

diff --git a/Documentation/DocBook/v4l/lirc_device_interface.xml 
b/Documentation/DocBook/v4l/lirc_device_interface.xml
index 0413234..68134c0 100644
--- a/Documentation/DocBook/v4l/lirc_device_interface.xml
+++ b/Documentation/DocBook/v4l/lirc_device_interface.xml
@@ -229,6 +229,22 @@ on working with the default settings initially.
   and LIRC_SETUP_END. Drivers can also choose to ignore these 
ioctls.
 
   
+  
+LIRC_SET_WIDEBAND_RECEIVER
+
+  Some receivers are equipped with special wide band receiver which 
is intended
+  to be used to learn output of existing remote.
+  Calling that ioctl with (1) will enable it, and with (0) disable it.
+  This might be useful of receivers that have otherwise narrow band 
receiver
+  that prevents them to be used with some remotes.
+  Wide band receiver might also be more precise
+  On the other hand its disadvantage it usually reduced range of reception.
+  Note: wide band receiver might be implictly enabled if you enable
+  carrier reports. In that case it will be disabled as soon as you disable
+  carrier reports. Trying to disable wide band receiver while carrier
+  reports are active will do nothing.
+
+  
 
 
 
diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index 8053e3b..a85a8c7 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -79,6 +79,7 @@ struct ir_raw_event_ctrl {
struct lirc_codec {
struct ir_input_dev *ir_dev;
struct lirc_driver *drv;
+   int carrier_low;
} lirc;
 };
 
diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/IR/ir-lirc-codec.c
index 8ca01fd..77b5946 100644
--- a/drivers/media/IR/ir-lirc-codec.c
+++ b/drivers/media/IR/ir-lirc-codec.c
@@ -46,7 +46,6 @@ static int ir_lirc_decode(struct input_dev *input_dev, struct 
ir_raw_event ev)
IR_dprintk(2, "LIRC data transfer started (%uus %s)\n",
   TO_US(ev.duration), TO_STR(ev.pulse));
 
-
sample = ev.duration / 1000;
if (ev.pulse)
sample |= PULSE_BIT;
@@ -96,13 +95,14 @@ out:
return ret;
 }
 
-static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long 
arg)
+static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
+   unsigned long __user arg)
 {
struct lirc_codec *lirc;
struct ir_input_dev *ir_dev;
int ret = 0;
void *drv_data;
-   unsigned long val;
+   unsigned long val = 0;
 
lirc = lirc_get_pdata(filep);
if (!lirc)
@@ -114,47 +114,106 @@ static long ir_lirc_ioctl(struct file *filep, unsigned 
int cmd, unsigned long ar
 
drv_data = ir_dev->props->priv;
 
-   switch (cmd) {
-   case LIRC_SET_TRANSMITTER_MASK:
+   if (_IOC_DIR(cmd) & _IOC_WRITE) {
ret = get_user(val, (unsigned long *)arg);
if (ret)
return ret;
+   }
+
+   switch (cmd) {
+
+   /* legacy support */
+   case LIRC_GET_SEND_MODE:
+   val = LIRC_CAN_SEND_PULSE & LIRC_CAN_SEND_MASK;
+   break;
+
+   case LIRC_SET_SEND_MODE:
+   if (val != (LIRC_MODE_PULSE & LIRC_CAN_SEND_MASK))
+   return -EINVAL;
+   break;
 
-   if (ir_dev->props && ir_dev->props->s_tx_mask)
+   /* TX settings */
+   case LIRC_SET_TRANSMITTER_MASK:
+   if (ir_dev->props->s_tx_mask)
ret = ir_dev->props->s_tx_mask(drv_data, (u32)val);
else
return -EINVAL;
break;
 
case LIRC_SET_SEND_CARRIER:
-   ret = get_user(val, (unsigned long *)arg);
-   if (ret)
-   return ret;
-
-   if (ir_dev->props && ir_dev->props->s_tx_carrier)
+   if (ir_dev->props->s_tx_carrier)
ir_dev->props->s_tx_carrier(drv_data, (u32)val);
else
return -EINVAL;
break;
 
-   case LIRC_GET_SEND_MODE:
-   val = LIRC_CAN_SEND_PULSE & LIRC_CAN_SEND_MASK;
-   ret = put_user(val, (unsigned long *)arg);
+   case LIRC_SET_SEND_D

[PATCH 11/13] IR: report unknown scancodes the in-kernel decoders found.

2010-07-31 Thread Maxim Levitsky
This way it is possible to use evtest to create keymap for unknown remote.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-keytable.c |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
index 34b9c07..ba7678a 100644
--- a/drivers/media/IR/ir-keytable.c
+++ b/drivers/media/IR/ir-keytable.c
@@ -339,6 +339,8 @@ void ir_repeat(struct input_dev *dev)
 
spin_lock_irqsave(&ir->keylock, flags);
 
+   input_event(dev, EV_MSC, MSC_SCAN, ir->last_scancode);
+
if (!ir->keypressed)
goto out;
 
@@ -370,6 +372,8 @@ void ir_keydown(struct input_dev *dev, int scancode, u8 
toggle)
 
spin_lock_irqsave(&ir->keylock, flags);
 
+   input_event(dev, EV_MSC, MSC_SCAN, scancode);
+
/* Repeat event? */
if (ir->keypressed &&
ir->last_scancode == scancode &&
@@ -383,9 +387,11 @@ void ir_keydown(struct input_dev *dev, int scancode, u8 
toggle)
ir->last_toggle = toggle;
ir->last_keycode = keycode;
 
+
if (keycode == KEY_RESERVED)
goto out;
 
+
/* Register a keypress */
ir->keypressed = true;
IR_dprintk(1, "%s: key down event, key 0x%04x, scancode 0x%04x\n",
@@ -480,6 +486,8 @@ int __ir_input_register(struct input_dev *input_dev,
 
set_bit(EV_KEY, input_dev->evbit);
set_bit(EV_REP, input_dev->evbit);
+   set_bit(EV_MSC, input_dev->evbit);
+   set_bit(MSC_SCAN, input_dev->mscbit);
 
if (ir_setkeytable(input_dev, &ir_dev->rc_tab, rc_tab)) {
rc = -ENOMEM;
-- 
1.7.0.4

--
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


[PATCH 07/13] IR: NECX: support repeat

2010-07-31 Thread Maxim Levitsky
This adds support for repeat detecting for NECX variant
Tested with uneversal remote

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-core-priv.h   |2 ++
 drivers/media/IR/ir-nec-decoder.c |   23 +--
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index 84c7a9a..502d477 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -45,6 +45,8 @@ struct ir_raw_event_ctrl {
int state;
unsigned count;
u32 bits;
+   bool is_nec_x;
+   bool necx_repeat;
} nec;
struct rc5_dec {
int state;
diff --git a/drivers/media/IR/ir-nec-decoder.c 
b/drivers/media/IR/ir-nec-decoder.c
index 1c0cf03..d597421 100644
--- a/drivers/media/IR/ir-nec-decoder.c
+++ b/drivers/media/IR/ir-nec-decoder.c
@@ -26,6 +26,7 @@
 #define NEC_BIT_1_SPACE(3  * NEC_UNIT)
 #defineNEC_TRAILER_PULSE   (1  * NEC_UNIT)
 #defineNEC_TRAILER_SPACE   (10 * NEC_UNIT) /* even longer in 
reality */
+#define NECX_REPEAT_BITS   1
 
 enum nec_state {
STATE_INACTIVE,
@@ -67,8 +68,12 @@ static int ir_nec_decode(struct input_dev *input_dev, struct 
ir_raw_event ev)
if (!ev.pulse)
break;
 
-   if (!eq_margin(ev.duration, NEC_HEADER_PULSE, NEC_UNIT / 2) &&
-   !eq_margin(ev.duration, NECX_HEADER_PULSE, NEC_UNIT / 2))
+   if (eq_margin(ev.duration, NEC_HEADER_PULSE, NEC_UNIT / 2)) {
+   data->is_nec_x = false;
+   data->necx_repeat = false;
+   } else if (eq_margin(ev.duration, NECX_HEADER_PULSE, NEC_UNIT / 
2))
+   data->is_nec_x = true;
+   else
break;
 
data->count = 0;
@@ -105,6 +110,17 @@ static int ir_nec_decode(struct input_dev *input_dev, 
struct ir_raw_event ev)
if (ev.pulse)
break;
 
+   if (data->necx_repeat && data->count == NECX_REPEAT_BITS &&
+   geq_margin(ev.duration,
+   NEC_TRAILER_SPACE, NEC_UNIT / 2)) {
+   IR_dprintk(1, "Repeat last key\n");
+   ir_repeat(input_dev);
+   data->state = STATE_INACTIVE;
+   return 0;
+
+   } else if (data->count > NECX_REPEAT_BITS)
+   data->necx_repeat = false;
+
data->bits <<= 1;
if (eq_margin(ev.duration, NEC_BIT_1_SPACE, NEC_UNIT / 2))
data->bits |= 1;
@@ -159,6 +175,9 @@ static int ir_nec_decode(struct input_dev *input_dev, 
struct ir_raw_event ev)
IR_dprintk(1, "NEC scancode 0x%04x\n", scancode);
}
 
+   if (data->is_nec_x)
+   data->necx_repeat = true;
+
ir_keydown(input_dev, scancode, 0);
data->state = STATE_INACTIVE;
return 0;
-- 
1.7.0.4

--
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


[PATCH 06/13] IR: nec decoder: fix repeat.

2010-07-31 Thread Maxim Levitsky
Repeat space is 4 units, not 8.
Current code would never trigger a repeat.

However that isn't true for NECX, so repeat there
must be handled differently.

Signed-off-by: Maxim Levitsky 
Reviewed-by: Andy Walls 
---
 drivers/media/IR/ir-nec-decoder.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/media/IR/ir-nec-decoder.c 
b/drivers/media/IR/ir-nec-decoder.c
index 52e0f37..1c0cf03 100644
--- a/drivers/media/IR/ir-nec-decoder.c
+++ b/drivers/media/IR/ir-nec-decoder.c
@@ -20,7 +20,7 @@
 #define NEC_HEADER_PULSE   (16 * NEC_UNIT)
 #define NECX_HEADER_PULSE  (8  * NEC_UNIT) /* Less common NEC variant */
 #define NEC_HEADER_SPACE   (8  * NEC_UNIT)
-#define NEC_REPEAT_SPACE   (8  * NEC_UNIT)
+#define NEC_REPEAT_SPACE   (4  * NEC_UNIT)
 #define NEC_BIT_PULSE  (1  * NEC_UNIT)
 #define NEC_BIT_0_SPACE(1  * NEC_UNIT)
 #define NEC_BIT_1_SPACE(3  * NEC_UNIT)
-- 
1.7.0.4

--
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


[PATCH 05/13] IR: JVC: make repeat work

2010-07-31 Thread Maxim Levitsky
Currently, jvc decoder will attempt misdetect next press as a repeat
of last keypress, therefore second keypress isn't detected.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-jvc-decoder.c |   14 +-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/drivers/media/IR/ir-jvc-decoder.c 
b/drivers/media/IR/ir-jvc-decoder.c
index 8894d8b..77a89c4 100644
--- a/drivers/media/IR/ir-jvc-decoder.c
+++ b/drivers/media/IR/ir-jvc-decoder.c
@@ -32,6 +32,7 @@ enum jvc_state {
STATE_BIT_SPACE,
STATE_TRAILER_PULSE,
STATE_TRAILER_SPACE,
+   STATE_CHECK_REPEAT,
 };
 
 /**
@@ -60,6 +61,7 @@ static int ir_jvc_decode(struct input_dev *input_dev, struct 
ir_raw_event ev)
IR_dprintk(2, "JVC decode started at state %d (%uus %s)\n",
   data->state, TO_US(ev.duration), TO_STR(ev.pulse));
 
+again:
switch (data->state) {
 
case STATE_INACTIVE:
@@ -149,8 +151,18 @@ static int ir_jvc_decode(struct input_dev *input_dev, 
struct ir_raw_event ev)
}
 
data->count = 0;
-   data->state = STATE_BIT_PULSE;
+   data->state = STATE_CHECK_REPEAT;
return 0;
+
+   case STATE_CHECK_REPEAT:
+   if (!ev.pulse)
+   break;
+
+   if (eq_margin(ev.duration, JVC_HEADER_PULSE, JVC_UNIT / 2))
+   data->state = STATE_INACTIVE;
+  else
+   data->state = STATE_BIT_PULSE;
+   goto again;
}
 
 out:
-- 
1.7.0.4

--
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


[PATCH 03/13] IR: replace spinlock with mutex.

2010-07-31 Thread Maxim Levitsky
Some handlers (lirc for example) allocates memory on initialization,
doing so in atomic context is cumbersome.
Fixes warning about sleeping function in atomic context.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-raw-event.c |   28 ++--
 1 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
index 51f65da..9d5c029 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/IR/ir-raw-event.c
@@ -13,7 +13,7 @@
  */
 
 #include 
-#include 
+#include 
 #include 
 #include "ir-core-priv.h"
 
@@ -24,7 +24,7 @@
 static LIST_HEAD(ir_raw_client_list);
 
 /* Used to handle IR raw handler extensions */
-static DEFINE_SPINLOCK(ir_raw_handler_lock);
+static DEFINE_MUTEX(ir_raw_handler_lock);
 static LIST_HEAD(ir_raw_handler_list);
 static u64 available_protocols;
 
@@ -41,10 +41,10 @@ static void ir_raw_event_work(struct work_struct *work)
container_of(work, struct ir_raw_event_ctrl, rx_work);
 
while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) {
-   spin_lock(&ir_raw_handler_lock);
+   mutex_lock(&ir_raw_handler_lock);
list_for_each_entry(handler, &ir_raw_handler_list, list)
handler->decode(raw->input_dev, ev);
-   spin_unlock(&ir_raw_handler_lock);
+   mutex_unlock(&ir_raw_handler_lock);
raw->prev_ev = ev;
}
 }
@@ -150,9 +150,9 @@ u64
 ir_raw_get_allowed_protocols()
 {
u64 protocols;
-   spin_lock(&ir_raw_handler_lock);
+   mutex_lock(&ir_raw_handler_lock);
protocols = available_protocols;
-   spin_unlock(&ir_raw_handler_lock);
+   mutex_unlock(&ir_raw_handler_lock);
return protocols;
 }
 
@@ -180,12 +180,12 @@ int ir_raw_event_register(struct input_dev *input_dev)
return rc;
}
 
-   spin_lock(&ir_raw_handler_lock);
+   mutex_lock(&ir_raw_handler_lock);
list_add_tail(&ir->raw->list, &ir_raw_client_list);
list_for_each_entry(handler, &ir_raw_handler_list, list)
if (handler->raw_register)
handler->raw_register(ir->raw->input_dev);
-   spin_unlock(&ir_raw_handler_lock);
+   mutex_unlock(&ir_raw_handler_lock);
 
return 0;
 }
@@ -200,12 +200,12 @@ void ir_raw_event_unregister(struct input_dev *input_dev)
 
cancel_work_sync(&ir->raw->rx_work);
 
-   spin_lock(&ir_raw_handler_lock);
+   mutex_lock(&ir_raw_handler_lock);
list_del(&ir->raw->list);
list_for_each_entry(handler, &ir_raw_handler_list, list)
if (handler->raw_unregister)
handler->raw_unregister(ir->raw->input_dev);
-   spin_unlock(&ir_raw_handler_lock);
+   mutex_unlock(&ir_raw_handler_lock);
 
kfifo_free(&ir->raw->kfifo);
kfree(ir->raw);
@@ -220,13 +220,13 @@ int ir_raw_handler_register(struct ir_raw_handler 
*ir_raw_handler)
 {
struct ir_raw_event_ctrl *raw;
 
-   spin_lock(&ir_raw_handler_lock);
+   mutex_lock(&ir_raw_handler_lock);
list_add_tail(&ir_raw_handler->list, &ir_raw_handler_list);
if (ir_raw_handler->raw_register)
list_for_each_entry(raw, &ir_raw_client_list, list)
ir_raw_handler->raw_register(raw->input_dev);
available_protocols |= ir_raw_handler->protocols;
-   spin_unlock(&ir_raw_handler_lock);
+   mutex_unlock(&ir_raw_handler_lock);
 
return 0;
 }
@@ -236,13 +236,13 @@ void ir_raw_handler_unregister(struct ir_raw_handler 
*ir_raw_handler)
 {
struct ir_raw_event_ctrl *raw;
 
-   spin_lock(&ir_raw_handler_lock);
+   mutex_lock(&ir_raw_handler_lock);
list_del(&ir_raw_handler->list);
if (ir_raw_handler->raw_unregister)
list_for_each_entry(raw, &ir_raw_client_list, list)
ir_raw_handler->raw_unregister(raw->input_dev);
available_protocols &= ~ir_raw_handler->protocols;
-   spin_unlock(&ir_raw_handler_lock);
+   mutex_unlock(&ir_raw_handler_lock);
 }
 EXPORT_SYMBOL(ir_raw_handler_unregister);
 
-- 
1.7.0.4

--
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


[PATCH 04/13] IR: replace workqueue with kthread

2010-07-31 Thread Maxim Levitsky
It is perfectly possible to have ir_raw_event_work
running concurently on two cpus, thus we must protect
it from that situation.

This stems from the fact that if hardware sends short packets of samples
we might end up queueing the work item more times that nessesary.

Such job isn't well suited for a workqueue, so use a kernel thread.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-core-priv.h |2 +-
 drivers/media/IR/ir-raw-event.c |   42 --
 2 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index dc26e2b..84c7a9a 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -32,7 +32,7 @@ struct ir_raw_handler {
 
 struct ir_raw_event_ctrl {
struct list_headlist;   /* to keep track of raw 
clients */
-   struct work_struct  rx_work;/* for the rx decoding 
workqueue */
+   struct task_struct  *thread;
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 */
diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
index 9d5c029..d0c18db 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/IR/ir-raw-event.c
@@ -12,9 +12,10 @@
  *  GNU General Public License for more details.
  */
 
-#include 
+#include 
 #include 
 #include 
+#include 
 #include "ir-core-priv.h"
 
 /* Define the max number of pulse/space transitions to buffer */
@@ -33,20 +34,30 @@ static u64 available_protocols;
 static struct work_struct wq_load;
 #endif
 
-static void ir_raw_event_work(struct work_struct *work)
+static int ir_raw_event_thread(void *data)
 {
struct ir_raw_event ev;
struct ir_raw_handler *handler;
-   struct ir_raw_event_ctrl *raw =
-   container_of(work, struct ir_raw_event_ctrl, rx_work);
+   struct ir_raw_event_ctrl *raw = (struct ir_raw_event_ctrl *)data;
+
+   while (!kthread_should_stop()) {
+   try_to_freeze();
 
-   while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) {
mutex_lock(&ir_raw_handler_lock);
-   list_for_each_entry(handler, &ir_raw_handler_list, list)
-   handler->decode(raw->input_dev, ev);
+
+   while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) {
+   list_for_each_entry(handler, &ir_raw_handler_list, list)
+   handler->decode(raw->input_dev, ev);
+   raw->prev_ev = ev;
+   }
+
mutex_unlock(&ir_raw_handler_lock);
-   raw->prev_ev = ev;
+
+   set_current_state(TASK_INTERRUPTIBLE);
+   schedule();
}
+
+   return 0;
 }
 
 /**
@@ -141,7 +152,7 @@ void ir_raw_event_handle(struct input_dev *input_dev)
if (!ir->raw)
return;
 
-   schedule_work(&ir->raw->rx_work);
+   wake_up_process(ir->raw->thread);
 }
 EXPORT_SYMBOL_GPL(ir_raw_event_handle);
 
@@ -170,7 +181,7 @@ int ir_raw_event_register(struct input_dev *input_dev)
return -ENOMEM;
 
ir->raw->input_dev = input_dev;
-   INIT_WORK(&ir->raw->rx_work, ir_raw_event_work);
+
ir->raw->enabled_protocols = ~0;
rc = kfifo_alloc(&ir->raw->kfifo, sizeof(s64) * MAX_IR_EVENT_SIZE,
 GFP_KERNEL);
@@ -180,6 +191,15 @@ int ir_raw_event_register(struct input_dev *input_dev)
return rc;
}
 
+   ir->raw->thread = kthread_run(ir_raw_event_thread, ir->raw,
+   "rc%u",  (unsigned int)ir->devno);
+
+   if (IS_ERR(ir->raw->thread)) {
+   kfree(ir->raw);
+   ir->raw = NULL;
+   return PTR_ERR(ir->raw->thread);
+   }
+
mutex_lock(&ir_raw_handler_lock);
list_add_tail(&ir->raw->list, &ir_raw_client_list);
list_for_each_entry(handler, &ir_raw_handler_list, list)
@@ -198,7 +218,7 @@ void ir_raw_event_unregister(struct input_dev *input_dev)
if (!ir->raw)
return;
 
-   cancel_work_sync(&ir->raw->rx_work);
+   kthread_stop(ir->raw->thread);
 
mutex_lock(&ir_raw_handler_lock);
list_del(&ir->raw->list);
-- 
1.7.0.4

--
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


[PATCH 02/13] IR: minor fixes:

2010-07-31 Thread Maxim Levitsky
* lirc: Don't propagate reset event to userspace
* lirc: Remove strange logic from lirc that would make first sample always be 
pulse
* Make TO_US macro actualy print what it should.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-core-priv.h  |4 +---
 drivers/media/IR/ir-lirc-codec.c |   14 --
 drivers/media/IR/ir-raw-event.c  |3 +++
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index babd520..dc26e2b 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -76,7 +76,6 @@ struct ir_raw_event_ctrl {
struct lirc_codec {
struct ir_input_dev *ir_dev;
struct lirc_driver *drv;
-   int lircdata;
} lirc;
 };
 
@@ -104,10 +103,9 @@ static inline void decrease_duration(struct ir_raw_event 
*ev, unsigned duration)
ev->duration -= duration;
 }
 
-#define TO_US(duration)(((duration) + 500) / 1000)
+#define TO_US(duration)DIV_ROUND_CLOSEST((duration), 
1000)
 #define TO_STR(is_pulse)   ((is_pulse) ? "pulse" : "space")
 #define IS_RESET(ev)   (ev.duration == 0)
-
 /*
  * Routines from ir-sysfs.c - Meant to be called only internally inside
  * ir-core
diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/IR/ir-lirc-codec.c
index 3ba482d..8ca01fd 100644
--- a/drivers/media/IR/ir-lirc-codec.c
+++ b/drivers/media/IR/ir-lirc-codec.c
@@ -32,6 +32,7 @@
 static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
 {
struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+   int sample;
 
if (!(ir_dev->raw->enabled_protocols & IR_TYPE_LIRC))
return 0;
@@ -39,18 +40,21 @@ static int ir_lirc_decode(struct input_dev *input_dev, 
struct ir_raw_event ev)
if (!ir_dev->raw->lirc.drv || !ir_dev->raw->lirc.drv->rbuf)
return -EINVAL;
 
+   if (IS_RESET(ev))
+   return 0;
+
IR_dprintk(2, "LIRC data transfer started (%uus %s)\n",
   TO_US(ev.duration), TO_STR(ev.pulse));
 
-   ir_dev->raw->lirc.lircdata += ev.duration / 1000;
+
+   sample = ev.duration / 1000;
if (ev.pulse)
-   ir_dev->raw->lirc.lircdata |= PULSE_BIT;
+   sample |= PULSE_BIT;
 
lirc_buffer_write(ir_dev->raw->lirc.drv->rbuf,
- (unsigned char *) &ir_dev->raw->lirc.lircdata);
+ (unsigned char *) &sample);
wake_up(&ir_dev->raw->lirc.drv->rbuf->wait_poll);
 
-   ir_dev->raw->lirc.lircdata = 0;
 
return 0;
 }
@@ -224,8 +228,6 @@ static int ir_lirc_register(struct input_dev *input_dev)
 
ir_dev->raw->lirc.drv = drv;
ir_dev->raw->lirc.ir_dev = ir_dev;
-   ir_dev->raw->lirc.lircdata = PULSE_MASK;
-
return 0;
 
 lirc_register_failed:
diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
index 6f192ef..51f65da 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/IR/ir-raw-event.c
@@ -66,6 +66,9 @@ int ir_raw_event_store(struct input_dev *input_dev, struct 
ir_raw_event *ev)
if (!ir->raw)
return -EINVAL;
 
+   IR_dprintk(2, "sample: (05%dus %s)\n",
+   TO_US(ev->duration), TO_STR(ev->pulse));
+
if (kfifo_in(&ir->raw->kfifo, ev, sizeof(*ev)) != sizeof(*ev))
return -ENOMEM;
 
-- 
1.7.0.4

--
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


[PATCH 01/13] IR: Kconfig fixes

2010-07-31 Thread Maxim Levitsky
Move IR drives below separate menu.
This allows to disable them.
Also correct a typo.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/Kconfig |   10 +++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/media/IR/Kconfig b/drivers/media/IR/Kconfig
index e557ae0..fc48a3f 100644
--- a/drivers/media/IR/Kconfig
+++ b/drivers/media/IR/Kconfig
@@ -1,8 +1,10 @@
-config IR_CORE
-   tristate
+menuconfig IR_CORE
+   tristate "Infrared remote controller adapters"
depends on INPUT
default INPUT
 
+if IR_CORE
+
 config VIDEO_IR
tristate
depends on IR_CORE
@@ -16,7 +18,7 @@ config LIRC
   Enable this option to build the Linux Infrared Remote
   Control (LIRC) core device interface driver. The LIRC
   interface passes raw IR to and from userspace, where the
-  LIRC daemon handles protocol decoding for IR reception ann
+  LIRC daemon handles protocol decoding for IR reception and
   encoding for IR transmitting (aka "blasting").
 
 source "drivers/media/IR/keymaps/Kconfig"
@@ -102,3 +104,5 @@ config IR_MCEUSB
 
   To compile this driver as a module, choose M here: the
   module will be called mceusb.
+
+endif #IR_CORE
-- 
1.7.0.4

--
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


[PATCH 0/9 v4] IR: few fixes, additions and ENE driver

2010-07-31 Thread Maxim Levitsky

Hi,

4th revision of my patches below:

Changes:

* more carefull repeat support in NECX protocol
* added documentation for wide band mode ioctl
* fix for 64 bit divide
* updated summary of patches, and preserved few
* Acked/Reviewed by tags you gave me.

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 13/13] IR: Port ene driver to new IR subsystem and enable it.

2010-07-31 Thread Maxim Levitsky
On Sat, 2010-07-31 at 10:37 -0400, Jon Smirl wrote: 
> On Sat, Jul 31, 2010 at 10:28 AM, Maxim Levitsky
>  wrote:
> > On Sat, 2010-07-31 at 09:55 -0400, Andy Walls wrote:
> >> On Fri, 2010-07-30 at 15:45 +0300, Maxim Levitsky wrote:
> >> > On Fri, 2010-07-30 at 08:07 -0400, Jon Smirl wrote:
> >> > > On Fri, Jul 30, 2010 at 8:02 AM, Jon Smirl  wrote:
> >> > > > On Fri, Jul 30, 2010 at 7:54 AM, Maxim Levitsky 
> >> > > >  wrote:
> >>
> >> >
> >> > > >
> >> > > > +   pll_freq = (ene_hw_read_reg(dev, ENE_PLLFRH) << 4) +
> >> > > > +   (ene_hw_read_reg(dev, ENE_PLLFRL) >> 2);
> >> > >
> >> >
> >> >
> >> > > I can understand the shift of the high bits, but that shift of the low
> >> > > bits is unlikely.  A manual would tell us if it is right.
> >> > >
> >> > This shift is correct (according to datasheet, which contains mostly
> >> > useless info, but it does dociment this reg briefly.)
> >>
> >> The KB3700 series datasheet indicates that the value from ENE_PLLFRL
> >> should be shifted by >> 4 bits, not by >> 2.  Of course, the KB3700
> >> isn't the exact same chip.
> > You are right about that, thanks!
> 
> I looked at KB3700 manual. It says it is trying to make a 32Mhz clock
> by multiplying 32.768Khz * 1000.
> 
> 32,768 * 1000 = 32.768Mhz is a 2.4% error.
> 
> When you are computing the timings of the pulses did you assume a
> 32Mhz clock? It looks like the clock is actuall 32.768Mhz.
No, I just take the samples hardware give me.
Lets just leave this as is.


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 13/13] IR: Port ene driver to new IR subsystem and enable it.

2010-07-31 Thread Maxim Levitsky
On Sat, 2010-07-31 at 09:55 -0400, Andy Walls wrote: 
> On Fri, 2010-07-30 at 15:45 +0300, Maxim Levitsky wrote:
> > On Fri, 2010-07-30 at 08:07 -0400, Jon Smirl wrote: 
> > > On Fri, Jul 30, 2010 at 8:02 AM, Jon Smirl  wrote:
> > > > On Fri, Jul 30, 2010 at 7:54 AM, Maxim Levitsky 
> > > >  wrote:
> 
> > 
> > > >
> > > > +   pll_freq = (ene_hw_read_reg(dev, ENE_PLLFRH) << 4) +
> > > > +   (ene_hw_read_reg(dev, ENE_PLLFRL) >> 2);
> > > 
> > 
> > 
> > > I can understand the shift of the high bits, but that shift of the low
> > > bits is unlikely.  A manual would tell us if it is right.
> > > 
> > This shift is correct (according to datasheet, which contains mostly
> > useless info, but it does dociment this reg briefly.)
> 
> The KB3700 series datasheet indicates that the value from ENE_PLLFRL
> should be shifted by >> 4 bits, not by >> 2.  Of course, the KB3700
> isn't the exact same chip.
You are right about that, thanks!

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 10/13] IR: extend interfaces to support more device settings LIRC: add new IOCTL that enables learning mode (wide band receiver)

2010-07-31 Thread Maxim Levitsky
On Sat, 2010-07-31 at 10:10 +0200, Christoph Bartelmus wrote: 
> Hi Maxim,
> 
> on 31 Jul 10 at 01:01, Maxim Levitsky wrote:
> > On Fri, 2010-07-30 at 23:22 +0200, Christoph Bartelmus wrote:
> [...]
> >>> +#define LIRC_SET_WIDEBAND_RECEIVER _IOW('i', 0x0023, __u32)
> >>
> >> If you really want this new ioctl, then it should be clarified how it
> >> behaves in relation to LIRC_SET_MEASURE_CARRIER_MODE.
> 
> > In my opinion, I won't need the LIRC_SET_MEASURE_CARRIER_MODE,
> > I would just optionally turn that on in learning mode.
> > You disagree, and since that is not important (besides TX and learning
> > features are present only at fraction of ENE devices. The only user I
> > did the debugging with, doesn't seem to want to help debug that code
> > anymore...)
> >
> > But anyway, in current state I want these features to be independent.
> > Driver will enable learning mode if it have to.
> 
> Please avoid the term "learning mode" as to you it probably means  
> something different than to me.
> 
> >
> > I'll add the documentation.
> 
> >>
> >> Do you have to enable the wide-band receiver explicitly before you can
> >> enable carrier reports or does enabling carrier reports implicitly switch
> >> to the wide-band receiver?
> > I would implicitly switch the learning mode on, untill user turns off
> > the carrier reports.
> 
> You mean that you'll implicitly switch on the wide-band receiver. Ok.
> 
> >>
> >> What happens if carrier mode is enabled and you explicitly turn off the
> >> wide-band receiver?
> > Wouldn't it be better to have one ioctl for both after all?
> 
> There may be hardware that allows carrier measurement but does not have a  
> wide-band receiver. And there may be hardware that does have a wide-band  
> receiver but does not allow carrier measurement. irrecord needs to be able  
> to distinguish these cases, so we need separate ioctls.
> 
> I'd say: carrier reports may switch on the wide-band reciever implicitly.  
> In that case the wide-band receiver cannot be switched off explicitly  
> until carrier reports are disabled again. It just needs to be documented.

No problem.

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 10/13] IR: extend interfaces to support more device settings LIRC: add new IOCTL that enables learning mode (wide band receiver)

2010-07-30 Thread Maxim Levitsky
On Fri, 2010-07-30 at 23:22 +0200, Christoph Bartelmus wrote: 
> Hi!
> 
> Maxim Levitsky "maximlevit...@gmail.com" wrote:
> 
> > Still missing features: carrier report & timeout reports.
> > Will need to pack these into ir_raw_event
> 
> 
> Hm, this patch changes the LIRC interface but I can't see the according  
> patch to the documentation.
> 
> [...]
> >   * @tx_ir: transmit IR
> >   * @s_idle: optional: enable/disable hardware idle mode, upon which,
> > +<<<<<<< current
> >   * device doesn't interrupt host untill it sees IR data
> > +===
> 
> Huh?
:-)


> 
> > +   device doesn't interrupt host untill it sees IR data
> > + * @s_learning_mode: enable wide band receiver used for learning
> +>>>>>>>> patched
> 
> s/untill/until/
> 
> [...]
> >  #define LIRC_CAN_MEASURE_CARRIER  0x0200
> > +#define LIRC_CAN_HAVE_WIDEBAND_RECEIVER   0x0400
> 
> LIRC_CAN_USE_WIDEBAND_RECEIVER

OK. 
> 
> [...]
> > @@ -145,7 +146,7 @@
> >   * if enabled from the next key press on the driver will send
> >   * LIRC_MODE2_FREQUENCY packets
> >   */
> > -#define LIRC_SET_MEASURE_CARRIER_MODE  _IOW('i', 0x001d, __u32)
> > +#define LIRC_SET_MEASURE_CARRIER_MODE  _IOW('i', 0x001d, __u32)
> >
> >  /*
> >   * to set a range use
> > @@ -162,4 +163,6 @@
> >  #define LIRC_SETUP_START   _IO('i', 0x0021)
> >  #define LIRC_SETUP_END _IO('i', 0x0022)
> >
> > +#define LIRC_SET_WIDEBAND_RECEIVER _IOW('i', 0x0023, __u32)
> 
> If you really want this new ioctl, then it should be clarified how it  
> behaves in relation to LIRC_SET_MEASURE_CARRIER_MODE.

In my opinion, I won't need the LIRC_SET_MEASURE_CARRIER_MODE,
I would just optionally turn that on in learning mode.
You disagree, and since that is not important (besides TX and learning
features are present only at fraction of ENE devices. The only user I
did the debugging with, doesn't seem to want to help debug that code
anymore...)

But anyway, in current state I want these features to be independent.
Driver will enable learning mode if it have to.

I'll add the documentation.



> 
> Do you have to enable the wide-band receiver explicitly before you can  
> enable carrier reports or does enabling carrier reports implicitly switch  
> to the wide-band receiver?
I would implicitly switch the learning mode on, untill user turns off
the carrier reports.

> 
> What happens if carrier mode is enabled and you explicitly turn off the  
> wide-band receiver?
Wouldn't it be better to have one ioctl for both after all?

> 
> And while we're at interface stuff:
> Do we really need LIRC_SETUP_START and LIRC_SETUP_END? It is only used  
> once in lircd during startup.
I don't think so.

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 0/9 v3] IR: few fixes, additions and ENE driver

2010-07-30 Thread Maxim Levitsky
On Fri, 2010-07-30 at 16:33 -0300, Mauro Carvalho Chehab wrote: 
> Em 30-07-2010 08:38, Maxim Levitsky escreveu:
> > Hi,
> > 
> > This is mostly same patchset.
> > 
> > I addressed the comments of Andy Walls.
> > 
> > Now IR decoding is done by a separate thread, and this fixes
> > the race, and unnesesary performance loss due to it.
> > 
> > Best regards,
> > Maxim Levitsky
> > 
> 
> Hmm... some change at this changeset is trying to divide a 64 bits integer
> at the LIRC driver. This is causing the following error:
> 
> Jul 30 16:45:23 agua kernel: [23834.179871] lirc_dev: IR Remote Control 
> driver registered, major 251 
> Jul 30 16:45:23 agua kernel: [23834.181884] ir_lirc_codec: Unknown symbol 
> __udivdi3 (err 0)
> 
> you should, instead use do_div for doing that. Another fix would be to define 
> the timeout
> constants as int or u32.
I know about that, but forgot, sorry.

Sure, will do.

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 06/13] IR: nec decoder: fix repeat.

2010-07-30 Thread Maxim Levitsky
On Fri, 2010-07-30 at 16:36 -0300, Mauro Carvalho Chehab wrote: 
> Em 30-07-2010 08:38, Maxim Levitsky escreveu:
> > Repeat space is 4 units, not 8.
> > Current code would never trigger a repeat.
> 
> Yes, this fixed the issue:
> 
> Jul 30 16:53:52 agua kernel: [24343.507577] ir_getkeycode: unknown key for 
> scancode 0x0009
> Jul 30 16:53:52 agua kernel: [24343.507588] ir_nec_decode: Repeat last key
> Jul 30 16:53:52 agua kernel: [24343.507590] ir_nec_decode: NEC scancode 0x0009
> Jul 30 16:53:52 agua kernel: [24343.507592] ir_getkeycode: unknown key for 
> scancode 0x0009
> Jul 30 16:53:52 agua kernel: [24343.507595] ir_nec_decode: Repeat last key
> Jul 30 16:53:52 agua kernel: [24343.724242] ir_nec_decode: NEC scancode 0x0009
> Jul 30 16:53:52 agua kernel: [24343.724246] ir_getkeycode: unknown key for 
> scancode 0x0009
> Jul 30 16:53:52 agua kernel: [24343.724257] ir_nec_decode: Repeat last key
> Jul 30 16:53:52 agua kernel: [24343.724259] ir_nec_decode: NEC scancode 0x0009
> Jul 30 16:53:52 agua kernel: [24343.724261] ir_getkeycode: unknown key for 
> scancode 0x0009
> Jul 30 16:53:52 agua kernel: [24343.724264] ir_nec_decode: Repeat last key
> Jul 30 16:53:53 agua kernel: [24343.937576] ir_nec_decode: NEC scancode 0x0009
> Jul 30 16:53:53 agua kernel: [24343.937580] ir_getkeycode: unknown key for 
> scancode 0x0009
> Jul 30 16:53:53 agua kernel: [24343.937592] ir_nec_decode: Repeat last key
> Jul 30 16:53:53 agua kernel: [24343.937594] ir_nec_decode: NEC scancode 0x0009
> Jul 30 16:53:53 agua kernel: [24343.937596] ir_getkeycode: unknown key for 
> scancode 0x0009
> Jul 30 16:53:53 agua kernel: [24343.937599] ir_nec_decode: Repeat last key
> 
> > 
> > However that isn't true for NECX, so repeat there
> > must be handled differently.
> > 
> > Signed-off-by: Maxim Levitsky 
> 
> Please preserve Andy's reviewed-by: when re-submitting a patch.

Yep, sorry about that!
Although, if I change a patch, I shouldn't preserve signed-off,
reviewed-by, lines, right?

Best regards,
Maxim Levitsky


> 
> > ---
> >  drivers/media/IR/ir-nec-decoder.c |2 +-
> >  1 files changed, 1 insertions(+), 1 deletions(-)
> > 
> > diff --git a/drivers/media/IR/ir-nec-decoder.c 
> > b/drivers/media/IR/ir-nec-decoder.c
> > index 52e0f37..1c0cf03 100644
> > --- a/drivers/media/IR/ir-nec-decoder.c
> > +++ b/drivers/media/IR/ir-nec-decoder.c
> > @@ -20,7 +20,7 @@
> >  #define NEC_HEADER_PULSE   (16 * NEC_UNIT)
> >  #define NECX_HEADER_PULSE  (8  * NEC_UNIT) /* Less common NEC variant */
> >  #define NEC_HEADER_SPACE   (8  * NEC_UNIT)
> > -#define NEC_REPEAT_SPACE   (8  * NEC_UNIT)
> > +#define NEC_REPEAT_SPACE   (4  * NEC_UNIT)
> >  #define NEC_BIT_PULSE  (1  * NEC_UNIT)
> >  #define NEC_BIT_0_SPACE(1  * NEC_UNIT)
> >  #define NEC_BIT_1_SPACE(3  * NEC_UNIT)
> 


--
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 13/13] IR: Port ene driver to new IR subsystem and enable it.

2010-07-30 Thread Maxim Levitsky
On Fri, 2010-07-30 at 08:07 -0400, Jon Smirl wrote: 
> On Fri, Jul 30, 2010 at 8:02 AM, Jon Smirl  wrote:
> > On Fri, Jul 30, 2010 at 7:54 AM, Maxim Levitsky  
> > wrote:
> >> On Fri, 2010-07-30 at 07:51 -0400, Jon Smirl wrote:
> >>> On Fri, Jul 30, 2010 at 7:36 AM, Maxim Levitsky  
> >>> wrote:
> >>> > On Thu, 2010-07-29 at 23:46 -0400, Andy Walls wrote:
> >>> >> On Thu, 2010-07-29 at 22:39 -0400, Jon Smirl wrote:
> >>> >> > On Thu, Jul 29, 2010 at 10:17 PM, Maxim Levitsky
> >>> >> >  wrote:
> >>> >> > > note that error_adjustment module option is added.
> >>> >> > > This allows to reduce input samples by a percent.
> >>> >> > > This makes input on my system more correct.
> >>> >> > >
> >>> >> > > Default is 4% as it works best here.
> >>> >> > >
> >>> >> > > Note that only normal input is adjusted. I don't know
> >>> >> > > what adjustments to apply to fan tachometer input.
> >>> >> > > Maybe it is accurate already.
> >>> >> >
> >>> >> > Do you have the manual for the ENE chip in English? or do you read 
> >>> >> > Chinese?
> >>> >>
> >>> >> The datasheet for a similar chip, the KB3700, is out there in English,
> >>> >> but it doesn't have CIR.
> >>> >>
> >>> >> You might find these links mildly interesting:
> >>> >>
> >>> >> http://www.coreboot.org/Embedded_controller
> >>> >> http://wiki.laptop.org/go/Embedded_controller
> >>> >> http://lists.laptop.org/pipermail/openec/2008-July/000108.html
> >>> >
> >>> > Nope, I have read that.
> >>> >>
> >>> >> Regards,
> >>> >> Andy
> >>> >>
> >>> >> > Maybe you can figure out why the readings are off by 4%. I suspect
> >>> >> > that someone has set a clock divider wrong when programming the chip.
> >>> >> > For example setting the divider for a 25Mhz clock when the clock is
> >>> >> > actually 26Mhz would cause the error you are seeing. Or they just 
> >>> >> > made
> >>> >> > a mistake in computing the divisor. It is probably a bug in the BIOS
> >>> >> > of your laptop.  If that's the case you could add a quirk in the
> >>> >> > system boot code to fix the register setting.
> >>> >
> >>> > I figured out how windows driver compensates for the offset, and do the
> >>> > same in my driver. I think the problem is solved.
> >>> >
> >>>
> >>> Should that be a <= or >= instead of !=?
> >>> +   if (pll_freq != 1000)
> >>
> >> This is how its done in windows driver.
> >
> > That doesn't mean it is bug free.

This PLL frequency is likely to be chip internal frequency.
And windows driver doesn't touch it.
Its embedded controller, so I don't want to touch things I am not sure
about.

> >
> > Experimenting with changing the PLL frequency register may correct the
> > error.  Try taking 96% of pll_freq and write it back into these
> > register. This would be easy to fix with a manual. The root problem is
> > almost certainly a bug in the way the PLLs were programmed.
> >
> > I don't like putting in fudge factors like the 4% correction. What
> > happens if a later version of the hardware has fixed firmware? I
> > normal user is never going to figure out that they need to change the
> > fudge factor.
I don't think that is a hardware bug, rather a limitation.

Lets leave it as is.
I will soon publish the driver on launchpad or something like that and
try to contact users I debugged that driver with, and then see what
ranges PLL register takes.



> >
> > +   pll_freq = (ene_hw_read_reg(dev, ENE_PLLFRH) << 4) +
> > +   (ene_hw_read_reg(dev, ENE_PLLFRL) >> 2);
> 


> I can understand the shift of the high bits, but that shift of the low
> bits is unlikely.  A manual would tell us if it is right.
> 
This shift is correct (according to datasheet, which contains mostly
useless info, but it does dociment this reg briefly.)


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 13/13] IR: Port ene driver to new IR subsystem and enable it.

2010-07-30 Thread Maxim Levitsky
On Fri, 2010-07-30 at 07:51 -0400, Jon Smirl wrote: 
> On Fri, Jul 30, 2010 at 7:36 AM, Maxim Levitsky  
> wrote:
> > On Thu, 2010-07-29 at 23:46 -0400, Andy Walls wrote:
> >> On Thu, 2010-07-29 at 22:39 -0400, Jon Smirl wrote:
> >> > On Thu, Jul 29, 2010 at 10:17 PM, Maxim Levitsky
> >> >  wrote:
> >> > > note that error_adjustment module option is added.
> >> > > This allows to reduce input samples by a percent.
> >> > > This makes input on my system more correct.
> >> > >
> >> > > Default is 4% as it works best here.
> >> > >
> >> > > Note that only normal input is adjusted. I don't know
> >> > > what adjustments to apply to fan tachometer input.
> >> > > Maybe it is accurate already.
> >> >
> >> > Do you have the manual for the ENE chip in English? or do you read 
> >> > Chinese?
> >>
> >> The datasheet for a similar chip, the KB3700, is out there in English,
> >> but it doesn't have CIR.
> >>
> >> You might find these links mildly interesting:
> >>
> >> http://www.coreboot.org/Embedded_controller
> >> http://wiki.laptop.org/go/Embedded_controller
> >> http://lists.laptop.org/pipermail/openec/2008-July/000108.html
> >
> > Nope, I have read that.
> >>
> >> Regards,
> >> Andy
> >>
> >> > Maybe you can figure out why the readings are off by 4%. I suspect
> >> > that someone has set a clock divider wrong when programming the chip.
> >> > For example setting the divider for a 25Mhz clock when the clock is
> >> > actually 26Mhz would cause the error you are seeing. Or they just made
> >> > a mistake in computing the divisor. It is probably a bug in the BIOS
> >> > of your laptop.  If that's the case you could add a quirk in the
> >> > system boot code to fix the register setting.
> >
> > I figured out how windows driver compensates for the offset, and do the
> > same in my driver. I think the problem is solved.
> >
> 
> Should that be a <= or >= instead of !=?
> +   if (pll_freq != 1000)

This is how its done in windows driver. 
> 
> Programming the PLL wrong would cause the 4% error.
> 
>hw_revision = ene_hw_read_reg(dev, ENE_HW_VERSION);
>old_ver = ene_hw_read_reg(dev, ENE_HW_VER_OLD);
> 
> +   pll_freq = (ene_hw_read_reg(dev, ENE_PLLFRH) << 4) +
> +   (ene_hw_read_reg(dev, ENE_PLLFRL) >> 2);
> +
> +   if (pll_freq != 1000)
> +   dev->rx_period_adjust = 4;
> +   else
> +   dev->rx_period_adjust = 2;
> +
> +
> +   ene_printk(KERN_NOTICE, "PLL freq = %d\n", pll_freq);
> +
>if (hw_revision == 0xFF) {
> 
> 
> 
> >
> > 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


[PATCH 13/13] IR: Port ene driver to new IR subsystem and enable it.

2010-07-30 Thread Maxim Levitsky
Signed-off-by: Maxim Levitsky 
---
 MAINTAINERS   |6 +
 drivers/media/IR/Kconfig  |   14 +
 drivers/media/IR/Makefile |1 +
 drivers/media/IR/ene_ir.c |  595 +
 drivers/media/IR/ene_ir.h |   51 ++---
 5 files changed, 265 insertions(+), 402 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 56a36d7..587785a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2188,6 +2188,12 @@ F:   drivers/misc/cb710/
 F: drivers/mmc/host/cb710-mmc.*
 F: include/linux/cb710.h
 
+ENE KB2426 (ENE0100/ENE020XX) INFRARED RECEIVER
+M: Maxim Levitsky 
+S: Maintained
+F: drivers/media/IR/ene_ir.c
+F: drivers/media/IR/ene_ir.h
+
 EPSON 1355 FRAMEBUFFER DRIVER
 M: Christopher Hoover 
 M: Christopher Hoover 
diff --git a/drivers/media/IR/Kconfig b/drivers/media/IR/Kconfig
index fc48a3f..3f62bf9 100644
--- a/drivers/media/IR/Kconfig
+++ b/drivers/media/IR/Kconfig
@@ -105,4 +105,18 @@ config IR_MCEUSB
   To compile this driver as a module, choose M here: the
   module will be called mceusb.
 
+config IR_ENE
+   tristate "ENE eHome Receiver/Transciever (pnp id: ENE0100/ENE02xxx)"
+   depends on PNP
+   depends on IR_CORE
+   ---help---
+  Say Y here to enable support for integrated infrared receiver
+  /transciever made by ENE.
+
+  You can see if you have it by looking at lspnp output.
+  Output should include ENE0100 ENE0200 or something similiar.
+
+  To compile this driver as a module, choose M here: the
+  module will be called ene_ir.
+
 endif #IR_CORE
diff --git a/drivers/media/IR/Makefile b/drivers/media/IR/Makefile
index 2ae4f3a..3262a68 100644
--- a/drivers/media/IR/Makefile
+++ b/drivers/media/IR/Makefile
@@ -16,3 +16,4 @@ obj-$(CONFIG_IR_LIRC_CODEC) += ir-lirc-codec.o
 # stand-alone IR receivers/transmitters
 obj-$(CONFIG_IR_IMON) += imon.o
 obj-$(CONFIG_IR_MCEUSB) += mceusb.o
+obj-$(CONFIG_IR_ENE) += ene_ir.o
diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
index 9d11caf..de1e5c4 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/IR/ene_ir.c
@@ -1,5 +1,5 @@
 /*
- * driver for ENE KB3926 B/C/D CIR (also known as ENE0100/ENE0200/ENE0201)
+ * driver for ENE KB3926 B/C/D CIR (pnp id: ENE0XXX)
  *
  * Copyright (C) 2010 Maxim Levitsky 
  *
@@ -25,20 +25,20 @@
 #include 
 #include 
 #include 
-#include 
-#include "lirc_ene0100.h"
+#include 
+#include 
+#include 
+#include 
+#include "ene_ir.h"
 
 
 static int sample_period = -1;
 static int enable_idle = 1;
-static int enable_duty_carrier;
 static int input = 1;
 static int debug;
 static int txsim;
 
-static void ene_rx_set_idle(struct ene_device *dev, int idle);
 static int ene_irq_status(struct ene_device *dev);
-static void ene_send_sample(struct ene_device *dev, unsigned long sample);
 
 /* read a hardware register */
 static u8 ene_hw_read_reg(struct ene_device *dev, u16 reg)
@@ -85,6 +85,7 @@ static int ene_hw_detect(struct ene_device *dev)
u8 hw_revision, old_ver;
u8 tmp;
u8 fw_capabilities;
+   int pll_freq;
 
tmp = ene_hw_read_reg(dev, ENE_HW_UNK);
ene_hw_write_reg(dev, ENE_HW_UNK, tmp & ~ENE_HW_UNK_CLR);
@@ -96,6 +97,17 @@ static int ene_hw_detect(struct ene_device *dev)
hw_revision = ene_hw_read_reg(dev, ENE_HW_VERSION);
old_ver = ene_hw_read_reg(dev, ENE_HW_VER_OLD);
 
+   pll_freq = (ene_hw_read_reg(dev, ENE_PLLFRH) << 4) +
+   (ene_hw_read_reg(dev, ENE_PLLFRL) >> 2);
+
+   if (pll_freq != 1000)
+   dev->rx_period_adjust = 4;
+   else
+   dev->rx_period_adjust = 2;
+
+
+   ene_printk(KERN_NOTICE, "PLL freq = %d\n", pll_freq);
+
if (hw_revision == 0xFF) {
 
ene_printk(KERN_WARNING, "device seems to be disabled\n");
@@ -160,7 +172,7 @@ static int ene_hw_detect(struct ene_device *dev)
 }
 
 /* this enables/disables IR input via gpio40*/
-static void ene_enable_gpio40_recieve(struct ene_device *dev, int enable)
+static void ene_enable_gpio40_receive(struct ene_device *dev, int enable)
 {
ene_hw_write_reg_mask(dev, ENE_CIR_CONF2, enable ?
  0 : ENE_CIR_CONF2_GPIO40DIS,
@@ -168,13 +180,13 @@ static void ene_enable_gpio40_recieve(struct ene_device 
*dev, int enable)
 }
 
 /* this enables/disables IR via standard input */
-static void ene_enable_normal_recieve(struct ene_device *dev, int enable)
+static void ene_enable_normal_receive(struct ene_device *dev, int enable)
 {
ene_hw_write_reg(dev, ENE_CIR_CONF1, enable ? ENE_CIR_CONF1_RX_ON : 0);
 }
 
 /* this enables/disables IR input via unused fan tachtometer input */
-static void ene_enable_fan_recieve(struct ene_device *dev, int enable)
+static void ene_enable_fan_receive(struct ene_device *dev, int enable)
 {
if (!enable)
e

[PATCH 10/13] IR: extend interfaces to support more device settings LIRC: add new IOCTL that enables learning mode (wide band receiver)

2010-07-30 Thread Maxim Levitsky
Still missing features: carrier report & timeout reports.
Will need to pack these into ir_raw_event


Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-core-priv.h  |1 +
 drivers/media/IR/ir-lirc-codec.c |  112 +++---
 include/media/ir-core.h  |   14 +
 include/media/lirc.h |5 ++-
 4 files changed, 112 insertions(+), 20 deletions(-)

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index 30ff52c..52253b4 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -78,6 +78,7 @@ struct ir_raw_event_ctrl {
struct lirc_codec {
struct ir_input_dev *ir_dev;
struct lirc_driver *drv;
+   int carrier_low;
} lirc;
 };
 
diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/IR/ir-lirc-codec.c
index 8ca01fd..5d5150f 100644
--- a/drivers/media/IR/ir-lirc-codec.c
+++ b/drivers/media/IR/ir-lirc-codec.c
@@ -46,7 +46,6 @@ static int ir_lirc_decode(struct input_dev *input_dev, struct 
ir_raw_event ev)
IR_dprintk(2, "LIRC data transfer started (%uus %s)\n",
   TO_US(ev.duration), TO_STR(ev.pulse));
 
-
sample = ev.duration / 1000;
if (ev.pulse)
sample |= PULSE_BIT;
@@ -96,13 +95,14 @@ out:
return ret;
 }
 
-static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long 
arg)
+static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
+   unsigned long __user arg)
 {
struct lirc_codec *lirc;
struct ir_input_dev *ir_dev;
int ret = 0;
void *drv_data;
-   unsigned long val;
+   unsigned long val = 0;
 
lirc = lirc_get_pdata(filep);
if (!lirc)
@@ -114,47 +114,106 @@ static long ir_lirc_ioctl(struct file *filep, unsigned 
int cmd, unsigned long ar
 
drv_data = ir_dev->props->priv;
 
-   switch (cmd) {
-   case LIRC_SET_TRANSMITTER_MASK:
+   if (_IOC_DIR(cmd) & _IOC_WRITE) {
ret = get_user(val, (unsigned long *)arg);
if (ret)
return ret;
+   }
+
+   switch (cmd) {
+
+   /* legacy support */
+   case LIRC_GET_SEND_MODE:
+   val = LIRC_CAN_SEND_PULSE & LIRC_CAN_SEND_MASK;
+   break;
+
+   case LIRC_SET_SEND_MODE:
+   if (val != (LIRC_MODE_PULSE & LIRC_CAN_SEND_MASK))
+   return -EINVAL;
+   break;
 
-   if (ir_dev->props && ir_dev->props->s_tx_mask)
+   /* TX settings */
+   case LIRC_SET_TRANSMITTER_MASK:
+   if (ir_dev->props->s_tx_mask)
ret = ir_dev->props->s_tx_mask(drv_data, (u32)val);
else
return -EINVAL;
break;
 
case LIRC_SET_SEND_CARRIER:
-   ret = get_user(val, (unsigned long *)arg);
-   if (ret)
-   return ret;
-
-   if (ir_dev->props && ir_dev->props->s_tx_carrier)
+   if (ir_dev->props->s_tx_carrier)
ir_dev->props->s_tx_carrier(drv_data, (u32)val);
else
return -EINVAL;
break;
 
-   case LIRC_GET_SEND_MODE:
-   val = LIRC_CAN_SEND_PULSE & LIRC_CAN_SEND_MASK;
-   ret = put_user(val, (unsigned long *)arg);
+   case LIRC_SET_SEND_DUTY_CYCLE:
+   if (!ir_dev->props->s_tx_duty_cycle)
+   return -ENOSYS;
+
+   if (val <= 0 || val >= 100)
+   return -EINVAL;
+
+   ir_dev->props->s_tx_duty_cycle(ir_dev->props->priv, val);
break;
 
-   case LIRC_SET_SEND_MODE:
-   ret = get_user(val, (unsigned long *)arg);
-   if (ret)
-   return ret;
+   /* RX settings */
+   case LIRC_SET_REC_CARRIER:
+   if (ir_dev->props->s_rx_carrier_range)
+   ret = ir_dev->props->s_rx_carrier_range(
+   ir_dev->props->priv,
+   ir_dev->raw->lirc.carrier_low, val);
+   else
+   return -ENOSYS;
 
-   if (val != (LIRC_MODE_PULSE & LIRC_CAN_SEND_MASK))
+   if (!ret)
+   ir_dev->raw->lirc.carrier_low = 0;
+   break;
+
+   case LIRC_SET_REC_CARRIER_RANGE:
+   if (val >= 0)
+   ir_dev->raw->lirc.carrier_low = val;
+   break;
+
+
+   case LIRC_GET_REC_RESOLUTION:
+   val = ir_dev->props->rx_resolution;
+   break;
+
+   case LIRC_SET_WIDEBAND_RECEIVER:
+   if (ir_dev-&g

[PATCH 11/13] IR: report unknown scancodes the in-kernel decoders found.

2010-07-30 Thread Maxim Levitsky
This way it is possible to use evtest to create keymap for unknown remote.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-keytable.c |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
index 34b9c07..ba7678a 100644
--- a/drivers/media/IR/ir-keytable.c
+++ b/drivers/media/IR/ir-keytable.c
@@ -339,6 +339,8 @@ void ir_repeat(struct input_dev *dev)
 
spin_lock_irqsave(&ir->keylock, flags);
 
+   input_event(dev, EV_MSC, MSC_SCAN, ir->last_scancode);
+
if (!ir->keypressed)
goto out;
 
@@ -370,6 +372,8 @@ void ir_keydown(struct input_dev *dev, int scancode, u8 
toggle)
 
spin_lock_irqsave(&ir->keylock, flags);
 
+   input_event(dev, EV_MSC, MSC_SCAN, scancode);
+
/* Repeat event? */
if (ir->keypressed &&
ir->last_scancode == scancode &&
@@ -383,9 +387,11 @@ void ir_keydown(struct input_dev *dev, int scancode, u8 
toggle)
ir->last_toggle = toggle;
ir->last_keycode = keycode;
 
+
if (keycode == KEY_RESERVED)
goto out;
 
+
/* Register a keypress */
ir->keypressed = true;
IR_dprintk(1, "%s: key down event, key 0x%04x, scancode 0x%04x\n",
@@ -480,6 +486,8 @@ int __ir_input_register(struct input_dev *input_dev,
 
set_bit(EV_KEY, input_dev->evbit);
set_bit(EV_REP, input_dev->evbit);
+   set_bit(EV_MSC, input_dev->evbit);
+   set_bit(MSC_SCAN, input_dev->mscbit);
 
if (ir_setkeytable(input_dev, &ir_dev->rc_tab, rc_tab)) {
rc = -ENOMEM;
-- 
1.7.0.4

--
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


[PATCH 09/13] IR: add helper function for hardware with small o/b buffer.

2010-07-30 Thread Maxim Levitsky
Some ir input devices have small buffer, and interrupt the host
each time it is full (or half full)

Add a helper that automaticly handles timeouts, and also
automaticly merges samples of same time (space-space)
Such samples might be placed by hardware because size of
sample in the buffer is small (a byte for example).

Also remove constness from ir_dev_props, because it now contains timeout
settings that driver might want to change

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 |   84 +++
 include/media/ir-core.h |   23 +-
 4 files changed, 106 insertions(+), 4 deletions(-)

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index e9c3cce..30ff52c 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -41,6 +41,7 @@ struct ir_raw_event_ctrl {
 
/* raw decoder state follows */
struct ir_raw_event prev_ev;
+   struct ir_raw_event this_ev;
struct nec_dec {
int state;
unsigned count;
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 d0c18db..43094e7 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/IR/ir-raw-event.c
@@ -140,6 +140,90 @@ 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) works
+ * in similiar manner to ir_raw_event_store_edge.
+ * 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 (!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->this_ev.duration) {
+   raw->this_ev = *ev;
+   } else if (ev->pulse == raw->this_ev.pulse) {
+   raw->this_ev.duration += ev->duration;
+   } else {
+   ir_raw_event_store(input_dev, &raw->this_ev);
+   raw->this_ev = *ev;
+   }
+
+   /* Enter idle mode if nessesary */
+   if (!ev->pulse && ir->props->timeout &&
+   raw->this_ev.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->this_ev.pulse);
+
+   raw->this_ev.duration =
+   min(raw->this_ev.duration + delta,
+   (u64)IR_MAX_DURATION);
+
+   ir_raw_event_store(input_dev, &raw->this_ev);
+
+   if (raw->this_ev.duration == IR_MAX_DURATION)
+   ir_raw_event_reset(input_dev);
+
+   raw->this_ev.duration = 0;
+   }
+out:
+   if (ir->props->s_idle)
+   ir->props->s_idle(ir->props->priv, idle);
+  

[PATCH 07/13] IR: NECX: support repeat

2010-07-30 Thread Maxim Levitsky
This adds support for repeat detecting for NECX variant
Tested with uneversal remote

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-core-priv.h   |1 +
 drivers/media/IR/ir-nec-decoder.c |   16 ++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index 84c7a9a..08383b9 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -45,6 +45,7 @@ struct ir_raw_event_ctrl {
int state;
unsigned count;
u32 bits;
+   bool is_nec_x;
} nec;
struct rc5_dec {
int state;
diff --git a/drivers/media/IR/ir-nec-decoder.c 
b/drivers/media/IR/ir-nec-decoder.c
index 1c0cf03..59127b1 100644
--- a/drivers/media/IR/ir-nec-decoder.c
+++ b/drivers/media/IR/ir-nec-decoder.c
@@ -26,6 +26,7 @@
 #define NEC_BIT_1_SPACE(3  * NEC_UNIT)
 #defineNEC_TRAILER_PULSE   (1  * NEC_UNIT)
 #defineNEC_TRAILER_SPACE   (10 * NEC_UNIT) /* even longer in 
reality */
+#define NECX_REPEAT_BITS   1
 
 enum nec_state {
STATE_INACTIVE,
@@ -67,8 +68,11 @@ static int ir_nec_decode(struct input_dev *input_dev, struct 
ir_raw_event ev)
if (!ev.pulse)
break;
 
-   if (!eq_margin(ev.duration, NEC_HEADER_PULSE, NEC_UNIT / 2) &&
-   !eq_margin(ev.duration, NECX_HEADER_PULSE, NEC_UNIT / 2))
+   if (eq_margin(ev.duration, NEC_HEADER_PULSE, NEC_UNIT / 2))
+   data->is_nec_x = false;
+   else if (eq_margin(ev.duration, NECX_HEADER_PULSE, NEC_UNIT / 
2))
+   data->is_nec_x = true;
+   else
break;
 
data->count = 0;
@@ -105,6 +109,14 @@ static int ir_nec_decode(struct input_dev *input_dev, 
struct ir_raw_event ev)
if (ev.pulse)
break;
 
+   if (geq_margin(ev.duration, NEC_TRAILER_SPACE, NEC_UNIT / 2) &&
+   data->is_nec_x && data->count == NECX_REPEAT_BITS) {
+   IR_dprintk(1, "Repeat last key\n");
+   ir_repeat(input_dev);
+   data->state = STATE_INACTIVE;
+   return 0;
+   }
+
data->bits <<= 1;
if (eq_margin(ev.duration, NEC_BIT_1_SPACE, NEC_UNIT / 2))
data->bits |= 1;
-- 
1.7.0.4

--
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


[PATCH 08/13] IR: Allow not to compile keymaps in.

2010-07-30 Thread Maxim Levitsky
Currently, ir device registration fails if keymap requested by driver is not 
found.
Fix that by always compiling in the empty keymap, and using it as a failback.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-core-priv.h |3 +-
 drivers/media/IR/ir-sysfs.c |2 +
 drivers/media/IR/keymaps/Makefile   |1 -
 drivers/media/IR/keymaps/rc-empty.c |   44 ---
 drivers/media/IR/rc-map.c   |   23 ++
 include/media/ir-core.h |8 -
 6 files changed, 33 insertions(+), 48 deletions(-)
 delete mode 100644 drivers/media/IR/keymaps/rc-empty.c

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index 08383b9..e9c3cce 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -125,7 +125,8 @@ int ir_raw_handler_register(struct ir_raw_handler 
*ir_raw_handler);
 void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler);
 void ir_raw_init(void);
 
-
+int ir_rcmap_init(void);
+void ir_rcmap_cleanup(void);
 /*
  * Decoder initialization code
  *
diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c
index a841e51..936dff8 100644
--- a/drivers/media/IR/ir-sysfs.c
+++ b/drivers/media/IR/ir-sysfs.c
@@ -341,6 +341,7 @@ static int __init ir_core_init(void)
 
/* Initialize/load the decoders/keymap code that will be used */
ir_raw_init();
+   ir_rcmap_init();
 
return 0;
 }
@@ -348,6 +349,7 @@ static int __init ir_core_init(void)
 static void __exit ir_core_exit(void)
 {
class_unregister(&ir_input_class);
+   ir_rcmap_cleanup();
 }
 
 module_init(ir_core_init);
diff --git a/drivers/media/IR/keymaps/Makefile 
b/drivers/media/IR/keymaps/Makefile
index 86d3d1f..24992cd 100644
--- a/drivers/media/IR/keymaps/Makefile
+++ b/drivers/media/IR/keymaps/Makefile
@@ -17,7 +17,6 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
rc-dm1105-nec.o \
rc-dntv-live-dvb-t.o \
rc-dntv-live-dvbt-pro.o \
-   rc-empty.o \
rc-em-terratec.o \
rc-encore-enltv2.o \
rc-encore-enltv.o \
diff --git a/drivers/media/IR/keymaps/rc-empty.c 
b/drivers/media/IR/keymaps/rc-empty.c
deleted file mode 100644
index 3b338d8..000
--- a/drivers/media/IR/keymaps/rc-empty.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/* empty.h - Keytable for empty Remote Controller
- *
- * keymap imported from ir-keymaps.c
- *
- * Copyright (c) 2010 by Mauro Carvalho Chehab 
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#include 
-
-/* empty keytable, can be used as placeholder for not-yet created keytables */
-
-static struct ir_scancode empty[] = {
-   { 0x2a, KEY_COFFEE },
-};
-
-static struct rc_keymap empty_map = {
-   .map = {
-   .scan= empty,
-   .size= ARRAY_SIZE(empty),
-   .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */
-   .name= RC_MAP_EMPTY,
-   }
-};
-
-static int __init init_rc_map_empty(void)
-{
-   return ir_register_map(&empty_map);
-}
-
-static void __exit exit_rc_map_empty(void)
-{
-   ir_unregister_map(&empty_map);
-}
-
-module_init(init_rc_map_empty)
-module_exit(exit_rc_map_empty)
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Mauro Carvalho Chehab ");
diff --git a/drivers/media/IR/rc-map.c b/drivers/media/IR/rc-map.c
index 46a8f15..689143f 100644
--- a/drivers/media/IR/rc-map.c
+++ b/drivers/media/IR/rc-map.c
@@ -82,3 +82,26 @@ void ir_unregister_map(struct rc_keymap *map)
 }
 EXPORT_SYMBOL_GPL(ir_unregister_map);
 
+
+static struct ir_scancode empty[] = {
+   { 0x2a, KEY_COFFEE },
+};
+
+static struct rc_keymap empty_map = {
+   .map = {
+   .scan= empty,
+   .size= ARRAY_SIZE(empty),
+   .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */
+   .name= RC_MAP_EMPTY,
+   }
+};
+
+int ir_rcmap_init(void)
+{
+   return ir_register_map(&empty_map);
+}
+
+void ir_rcmap_cleanup(void)
+{
+   ir_unregister_map(&empty_map);
+}
diff --git a/include/media/ir-core.h b/include/media/ir-core.h
index 513e60d..197d05a 100644
--- a/include/media/ir-core.h
+++ b/include/media/ir-core.h
@@ -110,8 +110,12 @@ static inline int ir_input_register(struct input_dev *dev,
return -EINVAL;
 
ir_codes = get_rc_map(map_name);
-   if (!ir_codes)
-   return -EINVAL;
+   if (!ir_codes) {
+   ir_codes = get_rc_map(RC_MAP_EMPTY);
+
+   if (!ir_codes)
+   return -EINVAL;
+   }
 
rc = __ir_input_register(dev, ir_co

[PATCH 06/13] IR: nec decoder: fix repeat.

2010-07-30 Thread Maxim Levitsky
Repeat space is 4 units, not 8.
Current code would never trigger a repeat.

However that isn't true for NECX, so repeat there
must be handled differently.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-nec-decoder.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/media/IR/ir-nec-decoder.c 
b/drivers/media/IR/ir-nec-decoder.c
index 52e0f37..1c0cf03 100644
--- a/drivers/media/IR/ir-nec-decoder.c
+++ b/drivers/media/IR/ir-nec-decoder.c
@@ -20,7 +20,7 @@
 #define NEC_HEADER_PULSE   (16 * NEC_UNIT)
 #define NECX_HEADER_PULSE  (8  * NEC_UNIT) /* Less common NEC variant */
 #define NEC_HEADER_SPACE   (8  * NEC_UNIT)
-#define NEC_REPEAT_SPACE   (8  * NEC_UNIT)
+#define NEC_REPEAT_SPACE   (4  * NEC_UNIT)
 #define NEC_BIT_PULSE  (1  * NEC_UNIT)
 #define NEC_BIT_0_SPACE(1  * NEC_UNIT)
 #define NEC_BIT_1_SPACE(3  * NEC_UNIT)
-- 
1.7.0.4

--
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


[PATCH 04/13] IR: fix locking in ir_raw_event_work

2010-07-30 Thread Maxim Levitsky
It is prefectly possible to have ir_raw_event_work
running concurently on two cpus, thus we must protect
it from that situation.

Just switch to a thread that we wake up as soon as we have data.
This also ensures that this thread doesn't run unnessesarly.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-core-priv.h |2 +-
 drivers/media/IR/ir-raw-event.c |   42 --
 2 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index dc26e2b..84c7a9a 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -32,7 +32,7 @@ struct ir_raw_handler {
 
 struct ir_raw_event_ctrl {
struct list_headlist;   /* to keep track of raw 
clients */
-   struct work_struct  rx_work;/* for the rx decoding 
workqueue */
+   struct task_struct  *thread;
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 */
diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
index 9d5c029..d0c18db 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/IR/ir-raw-event.c
@@ -12,9 +12,10 @@
  *  GNU General Public License for more details.
  */
 
-#include 
+#include 
 #include 
 #include 
+#include 
 #include "ir-core-priv.h"
 
 /* Define the max number of pulse/space transitions to buffer */
@@ -33,20 +34,30 @@ static u64 available_protocols;
 static struct work_struct wq_load;
 #endif
 
-static void ir_raw_event_work(struct work_struct *work)
+static int ir_raw_event_thread(void *data)
 {
struct ir_raw_event ev;
struct ir_raw_handler *handler;
-   struct ir_raw_event_ctrl *raw =
-   container_of(work, struct ir_raw_event_ctrl, rx_work);
+   struct ir_raw_event_ctrl *raw = (struct ir_raw_event_ctrl *)data;
+
+   while (!kthread_should_stop()) {
+   try_to_freeze();
 
-   while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) {
mutex_lock(&ir_raw_handler_lock);
-   list_for_each_entry(handler, &ir_raw_handler_list, list)
-   handler->decode(raw->input_dev, ev);
+
+   while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) {
+   list_for_each_entry(handler, &ir_raw_handler_list, list)
+   handler->decode(raw->input_dev, ev);
+   raw->prev_ev = ev;
+   }
+
mutex_unlock(&ir_raw_handler_lock);
-   raw->prev_ev = ev;
+
+   set_current_state(TASK_INTERRUPTIBLE);
+   schedule();
}
+
+   return 0;
 }
 
 /**
@@ -141,7 +152,7 @@ void ir_raw_event_handle(struct input_dev *input_dev)
if (!ir->raw)
return;
 
-   schedule_work(&ir->raw->rx_work);
+   wake_up_process(ir->raw->thread);
 }
 EXPORT_SYMBOL_GPL(ir_raw_event_handle);
 
@@ -170,7 +181,7 @@ int ir_raw_event_register(struct input_dev *input_dev)
return -ENOMEM;
 
ir->raw->input_dev = input_dev;
-   INIT_WORK(&ir->raw->rx_work, ir_raw_event_work);
+
ir->raw->enabled_protocols = ~0;
rc = kfifo_alloc(&ir->raw->kfifo, sizeof(s64) * MAX_IR_EVENT_SIZE,
 GFP_KERNEL);
@@ -180,6 +191,15 @@ int ir_raw_event_register(struct input_dev *input_dev)
return rc;
}
 
+   ir->raw->thread = kthread_run(ir_raw_event_thread, ir->raw,
+   "rc%u",  (unsigned int)ir->devno);
+
+   if (IS_ERR(ir->raw->thread)) {
+   kfree(ir->raw);
+   ir->raw = NULL;
+   return PTR_ERR(ir->raw->thread);
+   }
+
mutex_lock(&ir_raw_handler_lock);
list_add_tail(&ir->raw->list, &ir_raw_client_list);
list_for_each_entry(handler, &ir_raw_handler_list, list)
@@ -198,7 +218,7 @@ void ir_raw_event_unregister(struct input_dev *input_dev)
if (!ir->raw)
return;
 
-   cancel_work_sync(&ir->raw->rx_work);
+   kthread_stop(ir->raw->thread);
 
mutex_lock(&ir_raw_handler_lock);
list_del(&ir->raw->list);
-- 
1.7.0.4

--
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


[PATCH 05/13] IR: JVC: make repeat work

2010-07-30 Thread Maxim Levitsky
Currently, jvc decoder will attempt misdetect next press as a repeat
of last keypress, therefore second keypress isn't detected.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-jvc-decoder.c |   14 +-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/drivers/media/IR/ir-jvc-decoder.c 
b/drivers/media/IR/ir-jvc-decoder.c
index 8894d8b..77a89c4 100644
--- a/drivers/media/IR/ir-jvc-decoder.c
+++ b/drivers/media/IR/ir-jvc-decoder.c
@@ -32,6 +32,7 @@ enum jvc_state {
STATE_BIT_SPACE,
STATE_TRAILER_PULSE,
STATE_TRAILER_SPACE,
+   STATE_CHECK_REPEAT,
 };
 
 /**
@@ -60,6 +61,7 @@ static int ir_jvc_decode(struct input_dev *input_dev, struct 
ir_raw_event ev)
IR_dprintk(2, "JVC decode started at state %d (%uus %s)\n",
   data->state, TO_US(ev.duration), TO_STR(ev.pulse));
 
+again:
switch (data->state) {
 
case STATE_INACTIVE:
@@ -149,8 +151,18 @@ static int ir_jvc_decode(struct input_dev *input_dev, 
struct ir_raw_event ev)
}
 
data->count = 0;
-   data->state = STATE_BIT_PULSE;
+   data->state = STATE_CHECK_REPEAT;
return 0;
+
+   case STATE_CHECK_REPEAT:
+   if (!ev.pulse)
+   break;
+
+   if (eq_margin(ev.duration, JVC_HEADER_PULSE, JVC_UNIT / 2))
+   data->state = STATE_INACTIVE;
+  else
+   data->state = STATE_BIT_PULSE;
+   goto again;
}
 
 out:
-- 
1.7.0.4

--
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


[PATCH 03/13] IR: replace spinlock with mutex.

2010-07-30 Thread Maxim Levitsky
Some handlers (lirc for example) allocates memory on initialization,
doing so in atomic context is cumbersome.
Fixes warning about sleeping function in atomic context.

Signed-off-by: Maxim Levitsky 
---
 drivers/media/IR/ir-raw-event.c |   28 ++--
 1 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
index 51f65da..9d5c029 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/IR/ir-raw-event.c
@@ -13,7 +13,7 @@
  */
 
 #include 
-#include 
+#include 
 #include 
 #include "ir-core-priv.h"
 
@@ -24,7 +24,7 @@
 static LIST_HEAD(ir_raw_client_list);
 
 /* Used to handle IR raw handler extensions */
-static DEFINE_SPINLOCK(ir_raw_handler_lock);
+static DEFINE_MUTEX(ir_raw_handler_lock);
 static LIST_HEAD(ir_raw_handler_list);
 static u64 available_protocols;
 
@@ -41,10 +41,10 @@ static void ir_raw_event_work(struct work_struct *work)
container_of(work, struct ir_raw_event_ctrl, rx_work);
 
while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) {
-   spin_lock(&ir_raw_handler_lock);
+   mutex_lock(&ir_raw_handler_lock);
list_for_each_entry(handler, &ir_raw_handler_list, list)
handler->decode(raw->input_dev, ev);
-   spin_unlock(&ir_raw_handler_lock);
+   mutex_unlock(&ir_raw_handler_lock);
raw->prev_ev = ev;
}
 }
@@ -150,9 +150,9 @@ u64
 ir_raw_get_allowed_protocols()
 {
u64 protocols;
-   spin_lock(&ir_raw_handler_lock);
+   mutex_lock(&ir_raw_handler_lock);
protocols = available_protocols;
-   spin_unlock(&ir_raw_handler_lock);
+   mutex_unlock(&ir_raw_handler_lock);
return protocols;
 }
 
@@ -180,12 +180,12 @@ int ir_raw_event_register(struct input_dev *input_dev)
return rc;
}
 
-   spin_lock(&ir_raw_handler_lock);
+   mutex_lock(&ir_raw_handler_lock);
list_add_tail(&ir->raw->list, &ir_raw_client_list);
list_for_each_entry(handler, &ir_raw_handler_list, list)
if (handler->raw_register)
handler->raw_register(ir->raw->input_dev);
-   spin_unlock(&ir_raw_handler_lock);
+   mutex_unlock(&ir_raw_handler_lock);
 
return 0;
 }
@@ -200,12 +200,12 @@ void ir_raw_event_unregister(struct input_dev *input_dev)
 
cancel_work_sync(&ir->raw->rx_work);
 
-   spin_lock(&ir_raw_handler_lock);
+   mutex_lock(&ir_raw_handler_lock);
list_del(&ir->raw->list);
list_for_each_entry(handler, &ir_raw_handler_list, list)
if (handler->raw_unregister)
handler->raw_unregister(ir->raw->input_dev);
-   spin_unlock(&ir_raw_handler_lock);
+   mutex_unlock(&ir_raw_handler_lock);
 
kfifo_free(&ir->raw->kfifo);
kfree(ir->raw);
@@ -220,13 +220,13 @@ int ir_raw_handler_register(struct ir_raw_handler 
*ir_raw_handler)
 {
struct ir_raw_event_ctrl *raw;
 
-   spin_lock(&ir_raw_handler_lock);
+   mutex_lock(&ir_raw_handler_lock);
list_add_tail(&ir_raw_handler->list, &ir_raw_handler_list);
if (ir_raw_handler->raw_register)
list_for_each_entry(raw, &ir_raw_client_list, list)
ir_raw_handler->raw_register(raw->input_dev);
available_protocols |= ir_raw_handler->protocols;
-   spin_unlock(&ir_raw_handler_lock);
+   mutex_unlock(&ir_raw_handler_lock);
 
return 0;
 }
@@ -236,13 +236,13 @@ void ir_raw_handler_unregister(struct ir_raw_handler 
*ir_raw_handler)
 {
struct ir_raw_event_ctrl *raw;
 
-   spin_lock(&ir_raw_handler_lock);
+   mutex_lock(&ir_raw_handler_lock);
list_del(&ir_raw_handler->list);
if (ir_raw_handler->raw_unregister)
list_for_each_entry(raw, &ir_raw_client_list, list)
ir_raw_handler->raw_unregister(raw->input_dev);
available_protocols &= ~ir_raw_handler->protocols;
-   spin_unlock(&ir_raw_handler_lock);
+   mutex_unlock(&ir_raw_handler_lock);
 }
 EXPORT_SYMBOL(ir_raw_handler_unregister);
 
-- 
1.7.0.4

--
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


  1   2   >