From patchwork Thu Feb 6 19:59:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hogan X-Patchwork-Id: 3598211 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 03723C02E3 for ; Thu, 6 Feb 2014 20:00:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 22E7820114 for ; Thu, 6 Feb 2014 20:00:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 17CC020145 for ; Thu, 6 Feb 2014 20:00:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757018AbaBFUA3 (ORCPT ); Thu, 6 Feb 2014 15:00:29 -0500 Received: from mail-wi0-f180.google.com ([209.85.212.180]:45040 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756996AbaBFUAB (ORCPT ); Thu, 6 Feb 2014 15:00:01 -0500 Received: by mail-wi0-f180.google.com with SMTP id hm4so183838wib.13 for ; Thu, 06 Feb 2014 12:00:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=9O/pZ4gYZ/SrTrgi4QTZAefxUsDSajTIVHFCsZSENBs=; b=bpw3UlZethyDlWFiMSK/vhz979xb93RTiUumVuv0iHdwIg7po1/fVpX8EvrzfiApjZ g5+pE2oXOWuVC51W86/Ly0vap1d7htzz2kfFhG2Vpdv/rUmEtXSA6G8TaIjFWzleONiH +HfwOML1+LjIhzLrtLgONgSjkhQG8YEnUdpVQMNCFgh6spfr/Jl1uW6LxpA3KMOStC3K a4ja43kV4fB5Pq1naRIbsFL/ZTAuLYu2KIqDD9o+V+9KdUGs4BT4AIgrXhCv8AMYu1oz t+BMzy+3N9uaUOjG8Ia2IJkZwA0CLCf8KL9I3pfTz96XnIvxbmWGpZ55fPhP+74omoPQ jkHA== X-Gm-Message-State: ALoCoQkRRHp/Ukj/vpOqSBoe+ht1mivbosaxRfEbK7z2epBahFG4sFbeIbW1SO0AEPU+uWVT73dw X-Received: by 10.180.99.39 with SMTP id en7mr945750wib.10.1391716799927; Thu, 06 Feb 2014 11:59:59 -0800 (PST) Received: from radagast.lan (jahogan.plus.com. [212.159.75.221]) by mx.google.com with ESMTPSA id f3sm1493472wiv.2.2014.02.06.11.59.59 for (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128/128); Thu, 06 Feb 2014 11:59:59 -0800 (PST) From: James Hogan To: Mauro Carvalho Chehab , =?UTF-8?q?Antti=20Sepp=C3=A4l=C3=A4?= Cc: linux-media@vger.kernel.org, James Hogan Subject: [RFC 3/4] rc: ir-nec-decoder: add encode capability Date: Thu, 6 Feb 2014 19:59:22 +0000 Message-Id: <1391716763-2689-4-git-send-email-james.hogan@imgtec.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1391716763-2689-1-git-send-email-james.hogan@imgtec.com> References: <1391716763-2689-1-git-send-email-james.hogan@imgtec.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Add the capability to encode NEC scancodes as raw events. The scancode_to_raw is pretty much taken from the img-ir NEC filter() callback, and modulation uses the pulse distance helper added in a previous commit. Signed-off-by: James Hogan --- drivers/media/rc/ir-nec-decoder.c | 91 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/drivers/media/rc/ir-nec-decoder.c b/drivers/media/rc/ir-nec-decoder.c index 1bab7ea..5083ed6 100644 --- a/drivers/media/rc/ir-nec-decoder.c +++ b/drivers/media/rc/ir-nec-decoder.c @@ -203,9 +203,100 @@ static int ir_nec_decode(struct rc_dev *dev, struct ir_raw_event ev) return -EINVAL; } +/** + * ir_nec_scancode_to_raw() - encode an NEC scancode ready for modulation. + * @in: scancode filter describing a single NEC scancode. + * @raw: raw data to be modulated. + */ +static int ir_nec_scancode_to_raw(const struct rc_scancode_filter *in, + u32 *raw) +{ + unsigned int addr, addr_inv, data, data_inv; + + data = in->data & 0xff; + + if ((in->data | in->mask) & 0xff000000) { + /* 32-bit NEC (used by Apple and TiVo remotes) */ + /* scan encoding: aaAAddDD */ + if (in->mask != 0xffffffff) + return -EINVAL; + addr_inv = (in->data >> 24) & 0xff; + addr = (in->data >> 16) & 0xff; + data_inv = (in->data >> 8) & 0xff; + } else if ((in->data | in->mask) & 0x00ff0000) { + /* Extended NEC */ + /* scan encoding AAaaDD */ + if (in->mask != 0x00ffffff) + return -EINVAL; + addr = (in->data >> 16) & 0xff; + addr_inv = (in->data >> 8) & 0xff; + data_inv = data ^ 0xff; + } else { + /* Normal NEC */ + /* scan encoding: AADD */ + if (in->mask != 0x0000ffff) + return -EINVAL; + addr = (in->data >> 8) & 0xff; + addr_inv = addr ^ 0xff; + data_inv = data ^ 0xff; + } + + /* raw encoding: ddDDaaAA */ + *raw = data_inv << 24 | + data << 16 | + addr_inv << 8 | + addr; + return 0; +} + +static struct ir_raw_timings_pd ir_nec_timings = { + .header_pulse = NEC_HEADER_PULSE, + .header_space = NEC_HEADER_SPACE, + .bit_pulse = NEC_BIT_PULSE, + .bit_space[0] = NEC_BIT_0_SPACE, + .bit_space[1] = NEC_BIT_1_SPACE, + .trailer_pulse = NEC_TRAILER_PULSE, + .trailer_space = NEC_TRAILER_SPACE, + .msb_first = 0, +}; + +/** + * ir_nec_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 + * + * This function returns -EINVAL if the scancode filter is invalid or matches + * multiple scancodes. + */ +static int ir_nec_encode(u64 protocols, + const struct rc_scancode_filter *scancode, + struct ir_raw_event *events, unsigned int max) +{ + struct ir_raw_event *e = events; + int ret; + u32 raw; + + /* Convert a NEC scancode to raw NEC data */ + ret = ir_nec_scancode_to_raw(scancode, &raw); + if (ret < 0) + return ret; + + /* Modulate the raw data using a pulse distance modulation */ + ret = ir_raw_gen_pd(&e, max, &ir_nec_timings, NEC_NBITS, raw); + if (ret < 0) + return ret; + + return e - events; +} + static struct ir_raw_handler nec_handler = { .protocols = RC_BIT_NEC, .decode = ir_nec_decode, + .encode = ir_nec_encode, }; static int __init ir_nec_decode_init(void)