public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: James Hogan <james.hogan@imgtec.com>
To: Mauro Carvalho Chehab <m.chehab@samsung.com>
Cc: <linux-media@vger.kernel.org>, Jarod Wilson <jarod@redhat.com>
Subject: Re: [PATCH 06/11] media: rc: img-ir: add NEC decoder module
Date: Mon, 23 Dec 2013 11:30:45 +0000	[thread overview]
Message-ID: <52B81EE5.201@imgtec.com> (raw)
In-Reply-To: <20131222114901.3e5d7dae@samsung.com>

On 22/12/13 13:49, Mauro Carvalho Chehab wrote:
> Em Fri, 13 Dec 2013 15:12:54 +0000
> James Hogan <james.hogan@imgtec.com> escreveu:
>> +/* Convert NEC data to a scancode */
>> +static int img_ir_nec_scancode(int len, u64 raw, u64 protocols)
>> +{
>> +	unsigned int addr, addr_inv, data, data_inv;
>> +	int scancode;
>> +	/* a repeat code has no data */
>> +	if (!len)
>> +		return IMG_IR_REPEATCODE;
>> +	if (len != 32)
>> +		return IMG_IR_ERR_INVALID;
>> +	addr     = (raw >>  0) & 0xff;
>> +	addr_inv = (raw >>  8) & 0xff;
>> +	data     = (raw >> 16) & 0xff;
>> +	data_inv = (raw >> 24) & 0xff;
>> +	/* Validate data */
>> +	if ((data_inv ^ data) != 0xff)
>> +		return IMG_IR_ERR_INVALID;
>> +
>> +	if ((addr_inv ^ addr) != 0xff) {
>> +		/* Extended NEC */
>> +		scancode = addr     << 16 |
>> +			   addr_inv <<  8 |
>> +			   data;
>> +	} else {
>> +		/* Normal NEC */
>> +		scancode = addr << 8 |
>> +			   data;
>> +	}
> 
> There are some types of NEC extended that uses the full 32 bits as
> scancodes. Those are used at least on Apple and TiVo remote controllers.

Ooh, I hadn't spotted that patch. I'll make the necessary changes.

I notice that the scancode produced by the raw NEC decoder is the raw
non-bit-reversed version of the bits received, whereas for normal and
extended NEC the scancode fields are bit reversed. The TiVo keymap
appears to confirm that this is essentially backwards:

NEC:0xAAaaCCcc (AA=address, aa=not A, CC=command, cc=not command)

				bitrev(CCcc):
{ 0xa10c140b, KEY_NUMERIC_1 },	d028
{ 0xa10c940b, KEY_NUMERIC_2 },	d029
{ 0xa10c540b, KEY_NUMERIC_3 },	d02a
{ 0xa10cd40b, KEY_NUMERIC_4 },	d02b
{ 0xa10c340b, KEY_NUMERIC_5 },	d02c
{ 0xa10cb40b, KEY_NUMERIC_6 },	d02d
{ 0xa10c740b, KEY_NUMERIC_7 },	d02e
{ 0xa10cf40b, KEY_NUMERIC_8 },	d02f
{ 0x0085302f, KEY_NUMERIC_8 },
{ 0xa10c0c03, KEY_NUMERIC_9 },	c030
{ 0xa10c8c03, KEY_NUMERIC_0 },	c031

Clearly CC is supposed to be the LSB of the command.

Is it possible to reverse the bits in these scancode encodings (and of
course update the keymaps) or does this constitute a stable ABI that is
now too late to change?

IMO the following encoding would make much better sense for 32bit NEC
scancodes:
bits 31:16 = bitrev(AAaa)
bits 15:0  = bitrev(CCcc)

I.e. just bit reverse each 16bit half.

This puts the LSB of the command field in the LSB of the scancode which
I think is important, and treats the address field as a continuous
16bits (even though the extended NEC scancodes have address bytes
swapped for some reason - although for address it doesn't really
matter). If we assume the high byte of the address (aa) is always
non-zero, then the scancodes can be distinguished.

Cheers
James


  reply	other threads:[~2013-12-23 11:31 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-13 15:12 [PATCH 00/11] media: rc: ImgTec IR decoder driver James Hogan
2013-12-13 15:12 ` [PATCH 01/11] dt: binding: add binding for ImgTec IR block James Hogan
2013-12-22 10:56   ` Mauro Carvalho Chehab
2013-12-22 12:48   ` Tomasz Figa
2013-12-23 10:41     ` James Hogan
2013-12-13 15:12 ` [PATCH 02/11] media: rc: img-ir: add base driver James Hogan
2013-12-13 15:12 ` [PATCH 03/11] media: rc: img-ir: add raw driver James Hogan
2013-12-13 15:12 ` [PATCH 04/11] media: rc: img-ir: add hardware decoder driver James Hogan
2013-12-22 13:40   ` Mauro Carvalho Chehab
2013-12-23 13:17     ` James Hogan
2013-12-13 15:12 ` [PATCH 05/11] media: rc: img-ir: add to build James Hogan
2013-12-13 15:12 ` [PATCH 06/11] media: rc: img-ir: add NEC decoder module James Hogan
2013-12-22 13:49   ` Mauro Carvalho Chehab
2013-12-23 11:30     ` James Hogan [this message]
2013-12-13 15:12 ` [PATCH 07/11] media: rc: img-ir: add JVC " James Hogan
2013-12-13 15:12 ` [PATCH 08/11] media: rc: img-ir: add Sony " James Hogan
2013-12-13 15:12 ` [PATCH 09/11] media: rc: add Sharp infrared protocol James Hogan
2013-12-13 15:12 ` [PATCH 10/11] media: rc: img-ir: add Sharp decoder module James Hogan
2013-12-22 14:01   ` Mauro Carvalho Chehab
2013-12-23 12:04     ` James Hogan
2013-12-13 15:12 ` [PATCH 11/11] media: rc: img-ir: add Sanyo " James Hogan

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=52B81EE5.201@imgtec.com \
    --to=james.hogan@imgtec.com \
    --cc=jarod@redhat.com \
    --cc=linux-media@vger.kernel.org \
    --cc=m.chehab@samsung.com \
    /path/to/YOUR_REPLY

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

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