From patchwork Thu Apr 8 19:37:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 91485 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o38JbhXU028842 for ; Thu, 8 Apr 2010 19:37:49 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933535Ab0DHThi (ORCPT ); Thu, 8 Apr 2010 15:37:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20854 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933150Ab0DHThg (ORCPT ); Thu, 8 Apr 2010 15:37:36 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o38JbZYS000799 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 8 Apr 2010 15:37:35 -0400 Received: from pedra (vpn-10-98.rdu.redhat.com [10.11.10.98]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o38JbQNG019431 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 8 Apr 2010 15:37:34 -0400 Date: Thu, 8 Apr 2010 16:37:17 -0300 From: Mauro Carvalho Chehab To: linux-input@vger.kernel.org, Linux Media Mailing List Subject: [PATCH 5/8] V4L/DVB: ir-core: properly present the supported and current protocols Message-ID: <20100408163717.7d193308@pedra> In-Reply-To: References: Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 08 Apr 2010 19:37:50 +0000 (UTC) diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c index efde912..9d132d0 100644 --- a/drivers/media/IR/ir-sysfs.c +++ b/drivers/media/IR/ir-sysfs.c @@ -55,13 +55,13 @@ static ssize_t show_protocol(struct device *d, if (ir_type == IR_TYPE_UNKNOWN) s = "Unknown"; else if (ir_type == IR_TYPE_RC5) - s = "RC-5"; + s = "rc-5"; else if (ir_type == IR_TYPE_PD) - s = "Pulse/distance"; + s = "pulse-distance"; else if (ir_type == IR_TYPE_NEC) - s = "NEC"; + s = "nec"; else - s = "Other"; + s = "other"; return sprintf(buf, "%s\n", s); } @@ -85,23 +85,22 @@ static ssize_t store_protocol(struct device *d, size_t len) { struct ir_input_dev *ir_dev = dev_get_drvdata(d); - u64 ir_type = IR_TYPE_UNKNOWN; + u64 ir_type = 0; int rc = -EINVAL; unsigned long flags; char *buf; - buf = strsep((char **) &data, "\n"); + while (buf = strsep((char **) &data, " \n")) { + if (!strcasecmp(buf, "rc-5") || !strcasecmp(buf, "rc5")) + ir_type |= IR_TYPE_RC5; + if (!strcasecmp(buf, "pd") || !strcasecmp(buf, "pulse-distance")) + ir_type |= IR_TYPE_PD; + if (!strcasecmp(buf, "nec")) + ir_type |= IR_TYPE_NEC; + } - if (!strcasecmp(buf, "rc-5") || !strcasecmp(buf, "rc5")) - ir_type = IR_TYPE_RC5; - else if (!strcasecmp(buf, "pd")) - ir_type = IR_TYPE_PD; - else if (!strcasecmp(buf, "nec")) - ir_type = IR_TYPE_NEC; - - if (ir_type == IR_TYPE_UNKNOWN) { - IR_dprintk(1, "Error setting protocol to %lld\n", - (long long)ir_type); + if (!ir_type) { + IR_dprintk(1, "Unknown protocol\n"); return -EINVAL; } @@ -119,12 +118,34 @@ static ssize_t store_protocol(struct device *d, ir_dev->rc_tab.ir_type = ir_type; spin_unlock_irqrestore(&ir_dev->rc_tab.lock, flags); - IR_dprintk(1, "Current protocol is %lld\n", + IR_dprintk(1, "Current protocol(s) is(are) %lld\n", (long long)ir_type); return len; } +static ssize_t show_supported_protocols(struct device *d, + struct device_attribute *mattr, char *buf) +{ + char *orgbuf = buf; + struct ir_input_dev *ir_dev = dev_get_drvdata(d); + + /* FIXME: doesn't support multiple protocols at the same time */ + if (ir_dev->props->allowed_protos == IR_TYPE_UNKNOWN) + buf += sprintf(buf, "unknown "); + if (ir_dev->props->allowed_protos & IR_TYPE_RC5) + buf += sprintf(buf, "rc-5 "); + if (ir_dev->props->allowed_protos & IR_TYPE_PD) + buf += sprintf(buf, "pulse-distance "); + if (ir_dev->props->allowed_protos & IR_TYPE_NEC) + buf += sprintf(buf, "nec "); + if (buf == orgbuf) + buf += sprintf(buf, "other "); + + buf += sprintf(buf - 1, "\n"); + + return buf - orgbuf; +} #define ADD_HOTPLUG_VAR(fmt, val...) \ do { \ @@ -148,11 +169,15 @@ static int ir_dev_uevent(struct device *device, struct kobj_uevent_env *env) /* * Static device attribute struct with the sysfs attributes for IR's */ -static DEVICE_ATTR(current_protocol, S_IRUGO | S_IWUSR, +static DEVICE_ATTR(protocol, S_IRUGO | S_IWUSR, show_protocol, store_protocol); +static DEVICE_ATTR(supported_protocols, S_IRUGO | S_IWUSR, + show_supported_protocols, NULL); + static struct attribute *ir_hw_dev_attrs[] = { - &dev_attr_current_protocol.attr, + &dev_attr_protocol.attr, + &dev_attr_supported_protocols.attr, NULL, };