From patchwork Fri Feb 28 23:17:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: James Hogan X-Patchwork-Id: 3744991 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 9559ABF13A for ; Fri, 28 Feb 2014 23:17:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 72AD920263 for ; Fri, 28 Feb 2014 23:17:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A72420225 for ; Fri, 28 Feb 2014 23:17:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752434AbaB1XRr (ORCPT ); Fri, 28 Feb 2014 18:17:47 -0500 Received: from mail-we0-f177.google.com ([74.125.82.177]:65159 "EHLO mail-we0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751876AbaB1XRp (ORCPT ); Fri, 28 Feb 2014 18:17:45 -0500 Received: by mail-we0-f177.google.com with SMTP id t61so1115969wes.36 for ; Fri, 28 Feb 2014 15:17:43 -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:mime-version:content-type :content-transfer-encoding; bh=hcoCjlB+9H41GZqi4h5bk3HAjwVBeZMC9kzBc4TgbKY=; b=MDNoojsr48xN+IJujMg7byidgsqKve2fWqaiTSmnTx5a3AO9YorqLXN8vewklskpye ABSzKLFn0E1shWC/8R5orD7xPXzNdbY5HrT8DSLZZiYgW6pi5HNATxM4Bdx3pP5LfPrC WZKAHrIY+KVY0WYeS66jMg2tew7z1USDXLs8IgVnjaS+IM+F5avGe/ZnSB2WrXsacVRD 6qneRtGFZXdr9uArXA4mu0Urax7s18XNKC/HAccoi9dvZ+gKT8BCHGgHZFHIt6WMSTRh XA4FCqA2/PM4+7nFzlfkIJNbGl12gQ964jJyAqBxg2Hg7bX2y4rFX3FrFSTh5eGYxVSx so7Q== X-Gm-Message-State: ALoCoQnsnsLr1Cy+mwzRnTwhgxZjbcHKZXWKmVFQrD/IQ/T3qgKNhpINAwZRwvWlTIp9ym7VtzS8 X-Received: by 10.194.85.75 with SMTP id f11mr5146895wjz.47.1393629463910; Fri, 28 Feb 2014 15:17:43 -0800 (PST) Received: from radagast.lan (jahogan.plus.com. [212.159.75.221]) by mx.google.com with ESMTPSA id dk9sm7934562wjb.4.2014.02.28.15.17.43 for (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128/128); Fri, 28 Feb 2014 15:17:43 -0800 (PST) From: James Hogan To: Mauro Carvalho Chehab , linux-media@vger.kernel.org Cc: James Hogan , =?UTF-8?q?Antti=20Sepp=C3=A4l=C3=A4?= Subject: [PATCH 5/5] rc-main: automatically refresh filter on protocol change Date: Fri, 28 Feb 2014 23:17:06 +0000 Message-Id: <1393629426-31341-6-git-send-email-james.hogan@imgtec.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1393629426-31341-1-git-send-email-james.hogan@imgtec.com> References: <1393629426-31341-1-git-send-email-james.hogan@imgtec.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, 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 When either of the normal or wakeup filter protocols are changed, refresh the corresponding scancode filter, i.e. try and set the same scancode filter with the new protocol. If that fails clear the filter instead. If no protocol was selected the filter is just cleared, and if no s_filter callback exists the filter is left unmodified. Similarly clear the filter mask when the filter is set if no protocol is currently selected. This simplifies driver code which no longer has to explicitly worry about modifying the filter on a protocol change. This also allows the change_wakeup_protocol callback to be omitted entirely if there is only a single available wakeup protocol at a time, since selecting no protocol will automatically clear the wakeup filter, disabling wakeup. Signed-off-by: James Hogan Cc: Mauro Carvalho Chehab Cc: Antti Seppälä Cc: linux-media@vger.kernel.org --- drivers/media/rc/rc-main.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index e6e3ec7..b1a6900 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c @@ -918,11 +918,12 @@ static ssize_t store_protocols(struct device *device, struct rc_filter_attribute *fattr = to_rc_filter_attr(mattr); bool enable, disable; const char *tmp; - u64 type; + u64 old_type, type; u64 mask; int rc, i, count = 0; ssize_t ret; int (*change_protocol)(struct rc_dev *dev, u64 *rc_type); + struct rc_scancode_filter local_filter, *filter; /* Device is being removed */ if (!dev) @@ -935,7 +936,8 @@ static ssize_t store_protocols(struct device *device, ret = -EINVAL; goto out; } - type = dev->enabled_protocols[fattr->type]; + old_type = dev->enabled_protocols[fattr->type]; + type = old_type; while ((tmp = strsep((char **) &data, " \n")) != NULL) { if (!*tmp) @@ -999,6 +1001,36 @@ static ssize_t store_protocols(struct device *device, IR_dprintk(1, "Current protocol(s): 0x%llx\n", (long long)type); + /* + * If the protocol is changed the filter needs updating. + * Try setting the same filter with the new protocol (if any). + * Fall back to clearing the filter. + */ + filter = &dev->scancode_filters[fattr->type]; + if (old_type != type && filter->mask) { + local_filter = *filter; + if (!type) { + /* no protocol => clear filter */ + ret = -1; + } else if (!dev->s_filter) { + /* generic filtering => accept any filter */ + ret = 0; + } else { + /* hardware filtering => try setting, otherwise clear */ + ret = dev->s_filter(dev, fattr->type, &local_filter); + } + if (ret < 0) { + /* clear the filter */ + local_filter.data = 0; + local_filter.mask = 0; + if (dev->s_filter) + dev->s_filter(dev, fattr->type, &local_filter); + } + + /* commit the new filter */ + *filter = local_filter; + } + ret = len; out: @@ -1096,6 +1128,11 @@ static ssize_t store_filter(struct device *device, local_filter.mask = val; else local_filter.data = val; + if (!dev->enabled_protocols[fattr->type] && local_filter.mask) { + /* refuse to set a filter unless a protocol is enabled */ + ret = -EINVAL; + goto unlock; + } if (dev->s_filter) { ret = dev->s_filter(dev, fattr->type, &local_filter); if (ret < 0)