From patchwork Fri Mar 12 04:32:23 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: 85192 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 o2C4WpBr023539 for ; Fri, 12 Mar 2010 04:32:51 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752413Ab0CLEck (ORCPT ); Thu, 11 Mar 2010 23:32:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:62691 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751237Ab0CLEcj (ORCPT ); Thu, 11 Mar 2010 23:32:39 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2C4Wcq6023888 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 11 Mar 2010 23:32:38 -0500 Received: from [10.3.250.166] (vpn-250-166.phx2.redhat.com [10.3.250.166]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2C4WSbX015155 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 11 Mar 2010 23:32:33 -0500 Message-ID: <4B99C3D7.7000301@redhat.com> Date: Fri, 12 Mar 2010 01:32:23 -0300 From: Mauro Carvalho Chehab User-Agent: Thunderbird 2.0.0.22 (X11/20090609) MIME-Version: 1.0 To: Dmitry Torokhov CC: Linux Media Mailing List , linux-input@vger.kernel.org Subject: Re: [PATCH] V4L/DVB: ir: Add a link to associate /sys/class/ir/irrcv with the input device References: <4B99104B.3090307@redhat.com> <20100311175214.GB7467@core.coreip.homeip.net> In-Reply-To: <20100311175214.GB7467@core.coreip.homeip.net> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 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]); Fri, 12 Mar 2010 04:32:51 +0000 (UTC) diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c index 0903f53..c9c0a54 100644 --- a/drivers/media/IR/ir-keytable.c +++ b/drivers/media/IR/ir-keytable.c @@ -448,22 +448,15 @@ int ir_input_register(struct input_dev *input_dev, input_dev->setkeycode = ir_setkeycode; input_set_drvdata(input_dev, ir_dev); - rc = input_register_device(input_dev); - if (rc < 0) - goto err; - rc = ir_register_class(input_dev); - if (rc < 0) { - input_unregister_device(input_dev); + if (rc < 0) goto err; - } return 0; err: kfree(rc_tab->scan); kfree(ir_dev); - input_set_drvdata(input_dev, NULL); return rc; } EXPORT_SYMBOL_GPL(ir_input_register); @@ -492,7 +485,6 @@ void ir_input_unregister(struct input_dev *dev) ir_unregister_class(dev); kfree(ir_dev); - input_unregister_device(dev); } EXPORT_SYMBOL_GPL(ir_input_unregister); diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c index bf5fbcd..1bb011a 100644 --- a/drivers/media/IR/ir-sysfs.c +++ b/drivers/media/IR/ir-sysfs.c @@ -22,7 +22,15 @@ static unsigned long ir_core_dev_number; /* class for /sys/class/irrcv */ -static struct class *ir_input_class; +static char *ir_devnode(struct device *dev, mode_t *mode) +{ + return kasprintf(GFP_KERNEL, "irrcv/%s", dev_name(dev)); +} + +struct class ir_input_class = { + .name = "irrcv", + .devnode = ir_devnode, +}; /** * show_protocol() - shows the current IR protocol @@ -128,6 +136,20 @@ static struct attribute *ir_dev_attrs[] = { NULL, }; +static struct attribute_group ir_dev_attr_grp = { + .attrs =ir_dev_attrs, +}; + +static const struct attribute_group *ir_dev_attr_groups[] = { + &ir_dev_attr_grp, + NULL +}; + +static struct device_type ir_dev_type = { + .groups = ir_dev_attr_groups, +}; + + /** * ir_register_class() - creates the sysfs for /sys/class/irrcv/irrcv? * @input_dev: the struct input_dev descriptor of the device @@ -137,7 +159,7 @@ static struct attribute *ir_dev_attrs[] = { int ir_register_class(struct input_dev *input_dev) { int rc; - struct kobject *kobj; + const char *path; struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); int devno = find_first_zero_bit(&ir_core_dev_number, @@ -146,19 +168,31 @@ int ir_register_class(struct input_dev *input_dev) if (unlikely(devno < 0)) return devno; - ir_dev->attr.attrs = ir_dev_attrs; - ir_dev->class_dev = device_create(ir_input_class, NULL, - input_dev->dev.devt, ir_dev, - "irrcv%d", devno); - kobj = &ir_dev->class_dev->kobj; - - printk(KERN_WARNING "Creating IR device %s\n", kobject_name(kobj)); - rc = sysfs_create_group(kobj, &ir_dev->attr); - if (unlikely(rc < 0)) { - device_destroy(ir_input_class, input_dev->dev.devt); - return -ENOMEM; + ir_dev->dev.type = &ir_dev_type; + ir_dev->dev.class = &ir_input_class; + ir_dev->dev.parent = input_dev->dev.parent; + dev_set_name(&ir_dev->dev, "irrcv%d", devno); + rc = device_register(&ir_dev->dev); + if (rc) + return rc; + + + input_dev->dev.parent = &ir_dev->dev; + rc = input_register_device(input_dev); + if (rc < 0) { + device_del(&ir_dev->dev); + return rc; } + __module_get(THIS_MODULE); + + path = kobject_get_path(&input_dev->dev.kobj, GFP_KERNEL); + printk(KERN_INFO "%s: %s associated with sysfs %s\n", + dev_name(&ir_dev->dev), + input_dev->name ? input_dev->name : "Unspecified device", + path ? path : "N/A"); + kfree(path); + ir_dev->devno = devno; set_bit(devno, &ir_core_dev_number); @@ -175,16 +209,12 @@ int ir_register_class(struct input_dev *input_dev) void ir_unregister_class(struct input_dev *input_dev) { struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); - struct kobject *kobj; clear_bit(ir_dev->devno, &ir_core_dev_number); + input_unregister_device(input_dev); + device_del(&ir_dev->dev); - kobj = &ir_dev->class_dev->kobj; - - sysfs_remove_group(kobj, &ir_dev->attr); - device_destroy(ir_input_class, input_dev->dev.devt); - - kfree(ir_dev->attr.name); + module_put(THIS_MODULE); } /* @@ -193,10 +223,10 @@ void ir_unregister_class(struct input_dev *input_dev) static int __init ir_core_init(void) { - ir_input_class = class_create(THIS_MODULE, "irrcv"); - if (IS_ERR(ir_input_class)) { + int rc = class_register(&ir_input_class); + if (rc) { printk(KERN_ERR "ir_core: unable to register irrcv class\n"); - return PTR_ERR(ir_input_class); + return rc; } return 0; @@ -204,7 +234,7 @@ static int __init ir_core_init(void) static void __exit ir_core_exit(void) { - class_destroy(ir_input_class); + class_unregister(&ir_input_class); } module_init(ir_core_init); diff --git a/include/media/ir-core.h b/include/media/ir-core.h index 61c223b..ce9f347 100644 --- a/include/media/ir-core.h +++ b/include/media/ir-core.h @@ -47,11 +47,9 @@ struct ir_dev_props { struct ir_input_dev { - struct input_dev *dev; /* Input device*/ + struct device dev; /* device */ struct ir_scancode_table rc_tab; /* scan/key table */ unsigned long devno; /* device number */ - struct attribute_group attr; /* IR attributes */ - struct device *class_dev; /* virtual class dev */ const struct ir_dev_props *props; /* Device properties */ }; #define to_ir_input_dev(_attr) container_of(_attr, struct ir_input_dev, attr)