From patchwork Sun Jan 26 21:50:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QW50dGkgU2VwcMOkbMOk?= X-Patchwork-Id: 3540161 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 35AB19F391 for ; Sun, 26 Jan 2014 21:51:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 622B920122 for ; Sun, 26 Jan 2014 21:51:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 688B220117 for ; Sun, 26 Jan 2014 21:51:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753474AbaAZVvP (ORCPT ); Sun, 26 Jan 2014 16:51:15 -0500 Received: from mail-la0-f51.google.com ([209.85.215.51]:34329 "EHLO mail-la0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753125AbaAZVvO (ORCPT ); Sun, 26 Jan 2014 16:51:14 -0500 Received: by mail-la0-f51.google.com with SMTP id c6so4003319lan.10 for ; Sun, 26 Jan 2014 13:51:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=BBrsgvs9ug7Td4Tjhtojlm11REQq67XCevhqO7f0fZA=; b=KUzUEBU6hEj0RO1JiDOD0sr6OAMTOEuk7LHqcSNkdoXdvCbatOOSQWdXGgcPlEjc2h UUSGhfZ4m5TmjEL9yGdZNmfulcSS1BPBni33A7g4TGTjjz/OEmz23K/DU16oDHDgHdaj tZY5Mc33ZnZWRqGO4FFJCEv32ndhHEXiWPjkyKTBFRASSkjF+9UG1XL8AcS5yPqyVJCh lhArHGQDZOPlz5WSfL+XyaYKnbW8ATi0OZbA/aIGEnEq0FK8+XMFA8lw0zzNbH0byq9x 6WhR4+5Y3tcidSxfeDG4aVYEZoztdHlr8vb537MrK5H/WcWP7Y0nOciCR3GpZrxObZuX afDQ== X-Received: by 10.112.13.169 with SMTP id i9mr5632lbc.73.1390773073162; Sun, 26 Jan 2014 13:51:13 -0800 (PST) Received: from pixie.elisa-laajakaista.fi (a88-114-92-24.elisa-laajakaista.fi. [88.114.92.24]) by mx.google.com with ESMTPSA id h7sm9767468lbj.1.2014.01.26.13.51.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jan 2014 13:51:12 -0800 (PST) From: =?UTF-8?q?Antti=20Sepp=C3=A4l=C3=A4?= To: linux-media@vger.kernel.org Cc: Mauro Carvalho Chehab , Sean Young , =?UTF-8?q?Antti=20Sepp=C3=A4l=C3=A4?= Subject: [RFCv2 PATCH 5/5] winbond-cir: Add support for reading/writing wakeup scancodes via sysfs Date: Sun, 26 Jan 2014 23:50:26 +0200 Message-Id: <1390773026-567-6-git-send-email-a.seppala@gmail.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1390773026-567-1-git-send-email-a.seppala@gmail.com> References: <1390773026-567-1-git-send-email-a.seppala@gmail.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=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 This patch adds support for reading/writing wakeup scancodes via sysfs to nuvoton-cir hardware. The existing mechanism of setting wakeup scancodes by using module parameters is left untouched. If set the module parameters function as default values for sysfs files. Signed-off-by: Antti Seppälä --- drivers/media/rc/winbond-cir.c | 66 ++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c index 904baf4..c63a56e 100644 --- a/drivers/media/rc/winbond-cir.c +++ b/drivers/media/rc/winbond-cir.c @@ -683,6 +683,29 @@ wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count) return count; } +static int wbcir_wakeup_codes(struct rc_dev *dev, + struct list_head *wakeup_code_list, int write) +{ + u32 value = 0x800F040C; + struct rc_wakeup_code *code; + if (write) { + code = list_first_entry_or_null(wakeup_code_list, + struct rc_wakeup_code, + list_item); + if (code) + value = code->value; + + wake_sc = value; + } else { + code = kmalloc(sizeof(struct rc_wakeup_code), GFP_KERNEL); + if (!code) + return -ENOMEM; + code->value = wake_sc; + list_add_tail(&code->list_item, wakeup_code_list); + } + return 0; +} + /***************************************************************************** * * SETUP/INIT/SUSPEND/RESUME FUNCTIONS @@ -708,12 +731,11 @@ wbcir_shutdown(struct pnp_dev *device) goto finish; } - switch (protocol) { - case IR_PROTOCOL_RC5: + if (data->dev->enabled_wake_protos & RC_BIT_RC5) { if (wake_sc > 0xFFF) { do_wake = false; dev_err(dev, "RC5 - Invalid wake scancode\n"); - break; + goto finish; } /* Mask = 13 bits, ex toggle */ @@ -726,13 +748,11 @@ wbcir_shutdown(struct pnp_dev *device) if (!(wake_sc & 0x0040)) /* 2nd start bit */ match[1] |= 0x10; - break; - - case IR_PROTOCOL_NEC: + } else if (data->dev->enabled_wake_protos & RC_BIT_NEC) { if (wake_sc > 0xFFFFFF) { do_wake = false; dev_err(dev, "NEC - Invalid wake scancode\n"); - break; + goto finish; } mask[0] = mask[1] = mask[2] = mask[3] = 0xFF; @@ -745,16 +765,12 @@ wbcir_shutdown(struct pnp_dev *device) match[2] = bitrev8((wake_sc & 0xFF0000) >> 16); else match[2] = ~match[3]; - - break; - - case IR_PROTOCOL_RC6: - + } else if (data->dev->enabled_wake_protos & RC_BIT_RC6_0) { if (wake_rc6mode == 0) { if (wake_sc > 0xFFFF) { do_wake = false; dev_err(dev, "RC6 - Invalid wake scancode\n"); - break; + goto finish; } /* Command */ @@ -810,7 +826,7 @@ wbcir_shutdown(struct pnp_dev *device) } else { do_wake = false; dev_err(dev, "RC6 - Invalid wake scancode\n"); - break; + goto finish; } /* Header */ @@ -824,11 +840,8 @@ wbcir_shutdown(struct pnp_dev *device) dev_err(dev, "RC6 - Invalid wake mode\n"); } - break; - - default: + } else { do_wake = false; - break; } finish: @@ -1077,12 +1090,29 @@ wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id) data->dev->s_carrier_report = wbcir_set_carrier_report; data->dev->s_tx_mask = wbcir_txmask; data->dev->s_tx_carrier = wbcir_txcarrier; + data->dev->s_wakeup_codes = wbcir_wakeup_codes; data->dev->tx_ir = wbcir_tx; data->dev->priv = data; data->dev->dev.parent = &device->dev; data->dev->timeout = MS_TO_NS(100); data->dev->rx_resolution = US_TO_NS(2); data->dev->allowed_protos = RC_BIT_ALL; + data->dev->allowed_wake_protos = RC_BIT_RC5 | RC_BIT_RC6_0 | RC_BIT_NEC; + /* Utilize default protocol from module parameter */ + switch (protocol) { + case IR_PROTOCOL_RC5: + data->dev->enabled_wake_protos = RC_BIT_RC5; + break; + case IR_PROTOCOL_RC6: + data->dev->enabled_wake_protos = RC_BIT_RC6_0; + break; + case IR_PROTOCOL_NEC: + data->dev->enabled_wake_protos = RC_BIT_NEC; + break; + default: + data->dev->enabled_wake_protos = RC_BIT_NONE; + break; + } err = rc_register_device(data->dev); if (err)