From patchwork Fri Feb 6 06:56:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 5788931 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8915A9F302 for ; Fri, 6 Feb 2015 06:56:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 953162015E for ; Fri, 6 Feb 2015 06:56:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AA4AC20155 for ; Fri, 6 Feb 2015 06:56:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754236AbbBFG4J (ORCPT ); Fri, 6 Feb 2015 01:56:09 -0500 Received: from mail-ig0-f179.google.com ([209.85.213.179]:37513 "EHLO mail-ig0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754090AbbBFG4I (ORCPT ); Fri, 6 Feb 2015 01:56:08 -0500 Received: by mail-ig0-f179.google.com with SMTP id l13so315695iga.0; Thu, 05 Feb 2015 22:56:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=DAtLABzggwb1OLJ8my3cGAkMnXeJ6DoYHN+tsFY3qd8=; b=zR8Nqd6TD+N2LCwHUwlQazZNUvWxzWQaBicLO8iuA+bsUUtc24zsjxVjUUvPmqw0nr /DGQkNm5c0VwzVWlenWdMEseNSRt/fmRQ+n9bu5W0VciVaF5KQs5Z+Bxtb2dBjcmfvSI U5QQ8vZxbv34iD/msBC87k3G/VnqwtJs0RD2bvisLI2KYo4obxLENiIf0p3AtjihvRdi DW9tznCHQ9eYBUfXFy1j8mrwjbgsF7gW6RBNb8CoLW+hcu2LleEVNQcm2UGLEzK1bX7v Ts5J2YhVqDdZ1pmClIvbAl56F31E+8K+4cXBP9rLo6B2cFTc8he+PBWP/is2QmxDgUwr Lt2g== X-Received: by 10.43.142.4 with SMTP id jg4mr6530019icc.42.1423205767567; Thu, 05 Feb 2015 22:56:07 -0800 (PST) Received: from dtor-ws ([2620:0:1000:1301:704d:a2ff:c2e1:c373]) by mx.google.com with ESMTPSA id s17sm37063igr.2.2015.02.05.22.56.05 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 05 Feb 2015 22:56:06 -0800 (PST) Date: Thu, 5 Feb 2015 22:56:03 -0800 From: Dmitry Torokhov To: Sonic Zhang Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFT/PATCH] Input: bfin_rotary - introduce open and close methods Message-ID: <20150206065603.GA40057@dtor-ws> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_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 Introduce open and close methods for the input device to postpone enabling the device until it is needed. Signed-off-by: Dmitry Torokhov Acked-by: Sonic Zhang --- Hi Sonic, Could you please tell me if the driver still works with this parch? Thanks! drivers/input/misc/bfin_rotary.c | 70 ++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/drivers/input/misc/bfin_rotary.c b/drivers/input/misc/bfin_rotary.c index 09d7612..1bc9409 100644 --- a/drivers/input/misc/bfin_rotary.c +++ b/drivers/input/misc/bfin_rotary.c @@ -35,6 +35,10 @@ struct bfin_rot { unsigned int down_key; unsigned int button_key; unsigned int rel_code; + + unsigned short mode; + unsigned short debounce; + unsigned short cnt_config; unsigned short cnt_imask; unsigned short cnt_debounce; @@ -94,6 +98,35 @@ static irqreturn_t bfin_rotary_isr(int irq, void *dev_id) return IRQ_HANDLED; } +static int bfin_rotary_open(struct input_dev *input) +{ + struct bfin_rot *rotary = input_get_drvdata(input); + unsigned short val; + + if (rotary->mode & ROT_DEBE) + writew(rotary->debounce & DPRESCALE, + rotary->base + CNT_DEBOUNCE_OFF); + + writew(rotary->mode & ~CNTE, rotary->base + CNT_CONFIG_OFF); + + val = UCIE | DCIE; + if (rotary->button_key) + val |= CZMIE; + writew(val, rotary->base + CNT_IMASK_OFF); + + writew(rotary->mode | CNTE, rotary->base + CNT_CONFIG_OFF); + + return 0; +} + +static void bfin_rotary_close(struct input_dev *input) +{ + struct bfin_rot *rotary = input_get_drvdata(input); + + writew(0, rotary->base + CNT_CONFIG_OFF); + writew(0, rotary->base + CNT_IMASK_OFF); +} + static void bfin_rotary_free_action(void *data) { peripheral_free_list(data); @@ -154,6 +187,9 @@ static int bfin_rotary_probe(struct platform_device *pdev) rotary->button_key = pdata->rotary_button_key; rotary->rel_code = pdata->rotary_rel_code; + rotary->mode = pdata->mode; + rotary->debounce = pdata->debounce; + input->name = pdev->name; input->phys = "bfin-rotary/input0"; input->dev.parent = &pdev->dev; @@ -165,6 +201,9 @@ static int bfin_rotary_probe(struct platform_device *pdev) input->id.product = 0x0001; input->id.version = 0x0100; + input->open = bfin_rotary_open; + input->close = bfin_rotary_close; + if (rotary->up_key) { __set_bit(EV_KEY, input->evbit); __set_bit(rotary->up_key, input->keybit); @@ -179,6 +218,9 @@ static int bfin_rotary_probe(struct platform_device *pdev) __set_bit(rotary->button_key, input->keybit); } + /* Quiesce the device before requesting irq */ + bfin_rotary_close(input); + rotary->irq = platform_get_irq(pdev, 0); if (rotary->irq < 0) { dev_err(dev, "No rotary IRQ specified\n"); @@ -199,39 +241,12 @@ static int bfin_rotary_probe(struct platform_device *pdev) return error; } - if (pdata->rotary_button_key) - writew(CZMIE, rotary->base + CNT_IMASK_OFF); - - if (pdata->mode & ROT_DEBE) - writew(pdata->debounce & DPRESCALE, - rotary->base + CNT_DEBOUNCE_OFF); - - if (pdata->mode) - writew(readw(rotary->base + CNT_CONFIG_OFF) | - (pdata->mode & ~CNTE), - rotary->base + CNT_CONFIG_OFF); - - writew(readw(rotary->base + CNT_IMASK_OFF) | UCIE | DCIE, - rotary->base + CNT_IMASK_OFF); - writew(readw(rotary->base + CNT_CONFIG_OFF) | CNTE, - rotary->base + CNT_CONFIG_OFF); - platform_set_drvdata(pdev, rotary); device_init_wakeup(&pdev->dev, 1); return 0; } -static int bfin_rotary_remove(struct platform_device *pdev) -{ - struct bfin_rot *rotary = platform_get_drvdata(pdev); - - writew(0, rotary->base + CNT_CONFIG_OFF); - writew(0, rotary->base + CNT_IMASK_OFF); - - return 0; -} - static int __maybe_unused bfin_rotary_suspend(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); @@ -270,7 +285,6 @@ static SIMPLE_DEV_PM_OPS(bfin_rotary_pm_ops, static struct platform_driver bfin_rotary_device_driver = { .probe = bfin_rotary_probe, - .remove = bfin_rotary_remove, .driver = { .name = "bfin-rotary", .pm = &bfin_rotary_pm_ops,