From patchwork Fri Mar 14 23:04:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: James Hogan X-Patchwork-Id: 23100 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1WObCG-0003L6-Do; Sat, 15 Mar 2014 00:07:24 +0100 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.72/mailfrontend-5) with esmtp id 1WObCE-0005l3-70; Sat, 15 Mar 2014 00:07:24 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755926AbaCNXHR (ORCPT + 1 other); Fri, 14 Mar 2014 19:07:17 -0400 Received: from mail-wg0-f48.google.com ([74.125.82.48]:48025 "EHLO mail-wg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755097AbaCNXHD (ORCPT ); Fri, 14 Mar 2014 19:07:03 -0400 Received: by mail-wg0-f48.google.com with SMTP id l18so2676657wgh.31 for ; Fri, 14 Mar 2014 16:07:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=SE/p41R2sOtkKbaPCOAGv0T3j0QpbnJu1BIBsv+/8qE=; b=aRcg++Z6WS4RIatQYxmTu0O3qSyoLsOCU/oEzub8L60vqSMfJTR8Hjpss7/ypG8wCR avP2cGsdVlMieShaMDUM+mtWZ/6/OakjOvUOpZI8tzjfNceb+B352F3cIzhgTvdDhlfq SHl7Mz26drvAKccPmQ3DQ551rVDis51LSzwJhErA3AnvYMiNvG03STUyHVDaUPmTdUgh cm29tnz+NVyCyxnRbFrX9quPZpTaDzKahvh1Cw1lVsLTyBv/ZyC2du5tGnVCav+FqPPa y5U6zkgJL0JEWUIz42fJ4BuQdUHpW1DxjNmz/UIFa1e8IX9NskJUkRuq/Qh9Sie3vh92 yK0w== X-Gm-Message-State: ALoCoQmRLz5UUYd30IYeJRpy6Ztx78HN9cGoQCccRNgz9QnC/FnHSPNigll13Ddzwj6zrL/7Py1V X-Received: by 10.181.13.82 with SMTP id ew18mr416567wid.22.1394838422290; Fri, 14 Mar 2014 16:07:02 -0700 (PDT) Received: from localhost.localdomain (jahogan.plus.com. [212.159.75.221]) by mx.google.com with ESMTPSA id dd3sm17220342wjb.9.2014.03.14.16.07.00 for (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128/128); Fri, 14 Mar 2014 16:07:01 -0700 (PDT) From: James Hogan To: Mauro Carvalho Chehab , =?UTF-8?q?Antti=20Sepp=C3=A4l=C3=A4?= Cc: linux-media@vger.kernel.org, James Hogan , =?UTF-8?q?David=20H=C3=A4rdeman?= Subject: [PATCH v2 6/9] rc: ir-rc5-sz-decoder: Add ir encoding support Date: Fri, 14 Mar 2014 23:04:16 +0000 Message-Id: <1394838259-14260-7-git-send-email-james@albanarts.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1394838259-14260-1-git-send-email-james@albanarts.com> References: <1394838259-14260-1-git-send-email-james@albanarts.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2014.3.14.230021 X-PMX-Spam: Gauge=IIIIIIIII, Probability=9%, Report=' HTML_NO_HTTP 0.1, MULTIPLE_RCPTS 0.1, HTML_00_10 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, CT_TEXT_PLAIN_UTF8_CAPS 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_FROM 0, __HAS_HTML 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __HIGHBITS 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __MULTIPLE_RCPTS_CC_X2 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __URI_NO_WWW 0, __URI_NS , __YOUTUBE_RCVD 0' From: Antti Seppälä The encoding in rc5-sz first inserts a pulse and then simply utilizes the generic Manchester encoder available in rc-core. Signed-off-by: Antti Seppälä Signed-off-by: James Hogan Cc: Mauro Carvalho Chehab Cc: David Härdeman --- Changes in v2 (James Hogan): - Turn ir_rc5_sz_encode() comment into kerneldoc and update to reflect new API, with the -ENOBUFS return value for when the buffer is full and only a partial message was encoded. - Be more flexible around accepted scancode masks, as long as all the important bits are set (0x2fff) and none of the unimportant bits are set in the data. Also mask off the unimportant bits before passing to ir_raw_gen_manchester(). - Explicitly enable leader bit in Manchester modulation timings. --- drivers/media/rc/ir-rc5-sz-decoder.c | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/media/rc/ir-rc5-sz-decoder.c b/drivers/media/rc/ir-rc5-sz-decoder.c index dc18b74..a342a4f 100644 --- a/drivers/media/rc/ir-rc5-sz-decoder.c +++ b/drivers/media/rc/ir-rc5-sz-decoder.c @@ -127,9 +127,54 @@ out: return -EINVAL; } +static struct ir_raw_timings_manchester ir_rc5_sz_timings = { + .leader = 1, + .pulse_space_start = 0, + .clock = RC5_UNIT, + .trailer_space = RC5_UNIT * 10, +}; + +/** + * ir_rc5_sz_encode() - Encode a scancode as a stream of raw events + * + * @protocols: allowed protocols + * @scancode: scancode filter describing scancode (helps distinguish between + * protocol subtypes when scancode is ambiguous) + * @events: array of raw ir events to write into + * @max: maximum size of @events + * + * Returns: The number of events written. + * -ENOBUFS if there isn't enough space in the array to fit the + * encoding. In this case all @max events will have been written. + * -EINVAL if the scancode is ambiguous or invalid. + */ +static int ir_rc5_sz_encode(u64 protocols, + const struct rc_scancode_filter *scancode, + struct ir_raw_event *events, unsigned int max) +{ + int ret; + struct ir_raw_event *e = events; + + /* all important bits of scancode should be set in mask */ + if (~scancode->mask & 0x2fff) + return -EINVAL; + /* extra bits in mask should be zero in data */ + if (scancode->mask & scancode->data & ~0x2fff) + return -EINVAL; + + /* RC5-SZ scancode is raw enough for Manchester as it is */ + ret = ir_raw_gen_manchester(&e, max, &ir_rc5_sz_timings, RC5_SZ_NBITS, + scancode->data & 0x2fff); + if (ret < 0) + return ret; + + return e - events; +} + static struct ir_raw_handler rc5_sz_handler = { .protocols = RC_BIT_RC5_SZ, .decode = ir_rc5_sz_decode, + .encode = ir_rc5_sz_encode, }; static int __init ir_rc5_sz_decode_init(void)