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: 3835891 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 065DBBF540 for ; Fri, 14 Mar 2014 23:07:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0ED9F202A7 for ; Fri, 14 Mar 2014 23:07:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1FD4520279 for ; Fri, 14 Mar 2014 23:07:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755926AbaCNXHR (ORCPT ); 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-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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)