From patchwork Tue Jun 14 23:29:26 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Fordham X-Patchwork-Id: 880482 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5ENTgDL011173 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 14 Jun 2011 23:30:03 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QWd36-00059z-D8; Tue, 14 Jun 2011 23:29:32 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QWd35-0002Vd-Vx; Tue, 14 Jun 2011 23:29:32 +0000 Received: from mail-bw0-f49.google.com ([209.85.214.49]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QWd33-0002VK-4P for linux-arm-kernel@lists.infradead.org; Tue, 14 Jun 2011 23:29:30 +0000 Received: by bwz1 with SMTP id 1so62032bwz.36 for ; Tue, 14 Jun 2011 16:29:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=gX9Wg5WViXF4T9dUwbfVt1atAQ13MSKUqZ5eDy2gREY=; b=GBslxIPajAh/fogJ3gK4DBO/c/t4KK+KLH0YWuDFRsUPMYuUKKPF4flpTFkZ312iDp BDvBUXTRiV47P/KW7vQM2HodlL7JJ+adK1wRlaWXPm4ukrccxFsJS5lPHmXPjGG3nFVl 3GofmDpqxLgXmRaTyxq3Vts2E95w+sQzwGZN0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=pnew4p3EQw2Sl50Yi/pWi0Bm3NUgcLS2FU4TdEz/1QGJJ3E/Q/i+pernhKynIWBsH0 utFrfrLZaZg1eU+fPNx0QYXuWXb3Y1//l+B2aNnAqEfpaGXXGxI2VrlzIBMzPDNXAaW8 lGhHGrp+QEhBfPFDByMcX7kEZ4B0OziEVho+A= MIME-Version: 1.0 Received: by 10.204.14.208 with SMTP id h16mr2465626bka.35.1308094166208; Tue, 14 Jun 2011 16:29:26 -0700 (PDT) Received: by 10.204.9.23 with HTTP; Tue, 14 Jun 2011 16:29:26 -0700 (PDT) Date: Tue, 14 Jun 2011 16:29:26 -0700 Message-ID: Subject: [MPCore Watchdog]: Convert from misc_dev to dynamic device node. From: Peter Fordham To: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110614_192929_577371_A4563521 X-CRM114-Status: GOOD ( 18.98 ) X-Spam-Score: -0.8 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.214.49 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is freemail (peter.fordham[at]gmail.com) -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 RFC_ABUSE_POST Both abuse and postmaster missing on sender domain 0.0 T_TO_NO_BRKTS_FREEMAIL T_TO_NO_BRKTS_FREEMAIL X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 14 Jun 2011 23:30:04 +0000 (UTC) The current MPCore watchdog driver uses a misc_dev device node. This patch changes it to use dynamically allocated device numbers. --- drivers/watchdog/mpcore_wdt.c | 48 +++++++++++++++++++++++++++++------------ 1 files changed, 34 insertions(+), 14 deletions(-) ret = request_irq(wdt->irq, mpcore_wdt_fire, IRQF_DISABLED, "mpcore_wdt", wdt); @@ -379,10 +379,24 @@ static int __devinit mpcore_wdt_probe(struct platform_device *dev) platform_set_drvdata(dev, wdt); mpcore_wdt_dev = dev; - return 0; + ret = cdev_add(&wdt->cdev, wdt->number, 1); + if (ret < 0) { + dev_printk(KERN_ERR, wdt->dev, "failed to add character device\n"); + goto err_cdev_add; + } + /* create /dev/watchdog + * we use udev to make the file + */ + wdt->class = class_create(THIS_MODULE,"watchdog"); + (void) device_create(wdt->class, wdt->dev, wdt->number,NULL,"watchdog"); + + return 0; + +err_cdev_add: + free_irq(wdt->irq, wdt); err_irq: - misc_deregister(&mpcore_wdt_miscdev); + unregister_chrdev_region (wdt->number, 1); err_misc: iounmap(wdt->base); err_free: @@ -395,9 +409,15 @@ static int __devexit mpcore_wdt_remove(struct platform_device *dev) { struct mpcore_wdt *wdt = platform_get_drvdata(dev); + device_destroy(wdt->class,wdt->number); + class_unregister(wdt->class); + class_destroy(wdt->class); + + cdev_del(&wdt->cdev); + platform_set_drvdata(dev, NULL); - misc_deregister(&mpcore_wdt_miscdev); + unregister_chrdev_region (wdt->number, 1); mpcore_wdt_dev = NULL; diff --git a/drivers/watchdog/mpcore_wdt.c b/drivers/watchdog/mpcore_wdt.c index 2b4af22..f6afc20 100644 --- a/drivers/watchdog/mpcore_wdt.c +++ b/drivers/watchdog/mpcore_wdt.c @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include @@ -42,6 +44,9 @@ struct mpcore_wdt { int irq; unsigned int perturb; char expect_close; + struct cdev cdev; + struct class *class; + dev_t number; }; static struct platform_device *mpcore_wdt_dev; @@ -318,12 +323,6 @@ static const struct file_operations mpcore_wdt_fops = { .release = mpcore_wdt_release, }; -static struct miscdevice mpcore_wdt_miscdev = { - .minor = WATCHDOG_MINOR, - .name = "watchdog", - .fops = &mpcore_wdt_fops, -}; - static int __devinit mpcore_wdt_probe(struct platform_device *dev) { struct mpcore_wdt *wdt; @@ -358,14 +357,15 @@ static int __devinit mpcore_wdt_probe(struct platform_device *dev) goto err_free; } - mpcore_wdt_miscdev.parent = &dev->dev; - ret = misc_register(&mpcore_wdt_miscdev); - if (ret) { + ret = alloc_chrdev_region(&wdt->number, 0, 1, "mpcore_wdt"); + if (ret < 0) { dev_printk(KERN_ERR, wdt->dev, - "cannot register miscdev on minor=%d (err=%d)\n", - WATCHDOG_MINOR, ret); + "cannot register with dynamic device number (err=%d)\n", -ret); goto err_misc; } + dev_printk(KERN_INFO, wdt->dev, "using device number %d, %d", MAJOR(wdt->number), MINOR(wdt->number)); + + cdev_init(&wdt->cdev, &mpcore_wdt_fops);