From patchwork Wed Feb 4 07:58:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sonic zhang X-Patchwork-Id: 5775201 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9FC6EBF440 for ; Wed, 4 Feb 2015 08:00:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BD83F202B8 for ; Wed, 4 Feb 2015 08:00:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B468E202AE for ; Wed, 4 Feb 2015 08:00:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754011AbbBDIAr (ORCPT ); Wed, 4 Feb 2015 03:00:47 -0500 Received: from mail-bn1bon0091.outbound.protection.outlook.com ([157.56.111.91]:16292 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751287AbbBDIAr (ORCPT ); Wed, 4 Feb 2015 03:00:47 -0500 Received: from BN3PR0301CA0022.namprd03.prod.outlook.com (25.160.180.160) by BN1PR0301MB0737.namprd03.prod.outlook.com (25.160.78.144) with Microsoft SMTP Server (TLS) id 15.1.75.20; Wed, 4 Feb 2015 08:00:45 +0000 Received: from BN1AFFO11FD005.protection.gbl (2a01:111:f400:7c10::148) by BN3PR0301CA0022.outlook.office365.com (2a01:111:e400:4000::32) with Microsoft SMTP Server (TLS) id 15.1.75.20 via Frontend Transport; Wed, 4 Feb 2015 08:00:45 +0000 Received: from nwd2mta1.analog.com (137.71.25.55) by BN1AFFO11FD005.mail.protection.outlook.com (10.58.52.65) with Microsoft SMTP Server (TLS) id 15.1.87.10 via Frontend Transport; Wed, 4 Feb 2015 08:00:44 +0000 Received: from NWD2HUBCAS8.ad.analog.com (nwd2hubcas8.ad.analog.com [10.64.72.141]) by nwd2mta1.analog.com (8.13.8/8.13.8) with ESMTP id t14804DC028468 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Wed, 4 Feb 2015 00:00:04 -0800 Received: from zeus.spd.analog.com (10.64.82.11) by NWD2HUBCAS8.ad.analog.com (10.64.72.141) with Microsoft SMTP Server id 14.3.210.2; Wed, 4 Feb 2015 02:59:39 -0500 Received: from linux.site ([10.99.22.20]) by zeus.spd.analog.com (8.14.6/8.14.6) with ESMTP id t147xbfC011492; Wed, 4 Feb 2015 02:59:38 -0500 Received: from nine.ad.analog.com (unknown [10.99.24.95]) by linux.site (Postfix) with ESMTP id 0C0D83B00E89; Tue, 3 Feb 2015 17:03:13 -0700 (MST) From: Sonic Zhang To: Dmitry Torokhov , CC: Michael Hennerich , , Sonic Zhang Subject: [PATCH v3 3/3] bfin_rotary: replace bfin specific MMR function with generic IO function Date: Wed, 4 Feb 2015 15:58:05 +0800 Message-ID: <1423036686-31891-2-git-send-email-sonic.adi@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1423036686-31891-1-git-send-email-sonic.adi@gmail.com> References: <1423036686-31891-1-git-send-email-sonic.adi@gmail.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Matching-Connectors: 130675104450615807; (52f37747-95c3-483a-bd05-08d153b03fac); () Received-SPF: SoftFail (protection.outlook.com: domain of transitioning gmail.com discourages use of 137.71.25.55 as permitted sender) Authentication-Results: spf=softfail (sender IP is 137.71.25.55) smtp.mailfrom=sonic.adi@gmail.com; vger.kernel.org; dkim=none (message not signed) header.d=none; X-Forefront-Antispam-Report: CIP:137.71.25.55; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(76176999)(50986999)(33646002)(87936001)(76482003)(62966003)(229853001)(77156002)(36756003)(92566002)(82202001)(55446002)(48376002)(87572001)(61266001)(77096005)(2950100001)(47776003)(106466001)(105596002)(73972006)(86362001)(81442002)(73392002)(46102003)(83322999)(50226001)(19580395003)(6806004)(50466002)(19580405001)(41533002); DIR:OUT; SFP:1101; SCL:1; SRVR:BN1PR0301MB0737; H:nwd2mta1.analog.com; FPR:; SPF:SoftFail; MLV:sfv; LANG:en; X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:BN1PR0301MB0737; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004); SRVR:BN1PR0301MB0737; X-Forefront-PRVS: 04772EA191 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(401004)(400005); SRVR:BN1PR0301MB0737; X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2015 08:00:44.9523 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[137.71.25.55] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN1PR0301MB0737 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.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,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 From: Sonic Zhang - use readw and writew to access rotary MMRs - remap rotary register physical address into kernel space in probe v2-changes: - replace kzalloc with devm_kzalloc - replace request_irq with devm_request_irq - remove memory free and irq free from the device remove function v3-changes: - move managed resources to a separate patch Signed-off-by: Sonic Zhang --- drivers/input/misc/bfin_rotary.c | 53 ++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/drivers/input/misc/bfin_rotary.c b/drivers/input/misc/bfin_rotary.c index dd62fc9..defddca 100644 --- a/drivers/input/misc/bfin_rotary.c +++ b/drivers/input/misc/bfin_rotary.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -16,8 +17,18 @@ #include +#define CNT_CONFIG_OFF 0 /* CNT Config Offset */ +#define CNT_IMASK_OFF 4 /* CNT Interrupt Mask Offset */ +#define CNT_STATUS_OFF 8 /* CNT Status Offset */ +#define CNT_COMMAND_OFF 12 /* CNT Command Offset */ +#define CNT_DEBOUNCE_OFF 16 /* CNT Debounce Offset */ +#define CNT_COUNTER_OFF 20 /* CNT Counter Offset */ +#define CNT_MAX_OFF 24 /* CNT Maximum Count Offset */ +#define CNT_MIN_OFF 28 /* CNT Minimum Count Offset */ + struct bfin_rot { struct input_dev *input; + void __iomem *base; int irq; unsigned int up_key; unsigned int down_key; @@ -56,14 +67,14 @@ static irqreturn_t bfin_rotary_isr(int irq, void *dev_id) struct bfin_rot *rotary = platform_get_drvdata(pdev); int delta; - switch (bfin_read_CNT_STATUS()) { + switch (readw(rotary->base + CNT_STATUS_OFF)) { case ICII: break; case UCII: case DCII: - delta = bfin_read_CNT_COUNTER(); + delta = readl(rotary->base + CNT_COUNTER_OFF); if (delta) report_rotary_event(rotary, delta); break; @@ -76,8 +87,8 @@ static irqreturn_t bfin_rotary_isr(int irq, void *dev_id) break; } - bfin_write_CNT_COMMAND(W1LCNT_ZERO); /* Clear COUNTER */ - bfin_write_CNT_STATUS(-1); /* Clear STATUS */ + writew(W1LCNT_ZERO, rotary->base + CNT_COMMAND_OFF); /* Clear COUNTER */ + writew(-1, rotary->base + CNT_STATUS_OFF); /* Clear STATUS */ return IRQ_HANDLED; } @@ -161,17 +172,21 @@ static int bfin_rotary_probe(struct platform_device *pdev) } if (pdata->rotary_button_key) - bfin_write_CNT_IMASK(CZMIE); + writew(CZMIE, rotary->base + CNT_IMASK_OFF); if (pdata->mode & ROT_DEBE) - bfin_write_CNT_DEBOUNCE(pdata->debounce & DPRESCALE); + writew(pdata->debounce & DPRESCALE, + rotary->base + CNT_DEBOUNCE_OFF); if (pdata->mode) - bfin_write_CNT_CONFIG(bfin_read_CNT_CONFIG() | - (pdata->mode & ~CNTE)); + writew(readw(rotary->base + CNT_CONFIG_OFF) | + (pdata->mode & ~CNTE), + rotary->base + CNT_CONFIG_OFF); - bfin_write_CNT_IMASK(bfin_read_CNT_IMASK() | UCIE | DCIE); - bfin_write_CNT_CONFIG(bfin_read_CNT_CONFIG() | CNTE); + 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); @@ -193,8 +208,8 @@ static int bfin_rotary_remove(struct platform_device *pdev) struct bfin_rotary_platform_data *pdata = dev_get_platdata(&pdev->dev); struct bfin_rot *rotary = platform_get_drvdata(pdev); - bfin_write_CNT_CONFIG(0); - bfin_write_CNT_IMASK(0); + writew(0, rotary->base + CNT_CONFIG_OFF); + writew(0, rotary->base + CNT_IMASK_OFF); free_irq(rotary->irq, pdev); input_unregister_device(rotary->input); @@ -211,9 +226,9 @@ static int bfin_rotary_suspend(struct device *dev) struct platform_device *pdev = to_platform_device(dev); struct bfin_rot *rotary = platform_get_drvdata(pdev); - rotary->cnt_config = bfin_read_CNT_CONFIG(); - rotary->cnt_imask = bfin_read_CNT_IMASK(); - rotary->cnt_debounce = bfin_read_CNT_DEBOUNCE(); + rotary->cnt_config = readw(rotary->base + CNT_CONFIG_OFF); + rotary->cnt_imask = readw(rotary->base + CNT_IMASK_OFF); + rotary->cnt_debounce = readw(rotary->base + CNT_DEBOUNCE_OFF); if (device_may_wakeup(&pdev->dev)) enable_irq_wake(rotary->irq); @@ -226,15 +241,15 @@ static int bfin_rotary_resume(struct device *dev) struct platform_device *pdev = to_platform_device(dev); struct bfin_rot *rotary = platform_get_drvdata(pdev); - bfin_write_CNT_DEBOUNCE(rotary->cnt_debounce); - bfin_write_CNT_IMASK(rotary->cnt_imask); - bfin_write_CNT_CONFIG(rotary->cnt_config & ~CNTE); + writew(rotary->cnt_debounce, rotary->base + CNT_DEBOUNCE_OFF); + writew(rotary->cnt_imask, rotary->base + CNT_IMASK_OFF); + writew(rotary->cnt_config & ~CNTE, rotary->base + CNT_CONFIG_OFF); if (device_may_wakeup(&pdev->dev)) disable_irq_wake(rotary->irq); if (rotary->cnt_config & CNTE) - bfin_write_CNT_CONFIG(rotary->cnt_config); + writew(rotary->cnt_config, rotary->base + CNT_CONFIG_OFF); return 0; }