From patchwork Thu Feb 5 07:30:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sonic zhang X-Patchwork-Id: 5782661 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 F0175BF440 for ; Thu, 5 Feb 2015 07:47:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CBA4820221 for ; Thu, 5 Feb 2015 07:47:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F0F6520218 for ; Thu, 5 Feb 2015 07:47:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756425AbbBEHru (ORCPT ); Thu, 5 Feb 2015 02:47:50 -0500 Received: from mail-by2on0077.outbound.protection.outlook.com ([207.46.100.77]:6176 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752683AbbBEHrt (ORCPT ); Thu, 5 Feb 2015 02:47:49 -0500 Received: from BY2PR03CA059.namprd03.prod.outlook.com (10.141.249.32) by DM2PR0301MB0752.namprd03.prod.outlook.com (25.160.97.148) with Microsoft SMTP Server (TLS) id 15.1.75.20; Thu, 5 Feb 2015 07:33:15 +0000 Received: from BN1AFFO11FD008.protection.gbl (2a01:111:f400:7c10::185) by BY2PR03CA059.outlook.office365.com (2a01:111:e400:2c5d::32) with Microsoft SMTP Server (TLS) id 15.1.87.13 via Frontend Transport; Thu, 5 Feb 2015 07:33:14 +0000 Received: from nwd2mta1.analog.com (137.71.25.55) by BN1AFFO11FD008.mail.protection.outlook.com (10.58.52.68) with Microsoft SMTP Server (TLS) id 15.1.87.10 via Frontend Transport; Thu, 5 Feb 2015 07:33:14 +0000 Received: from NWD2HUBCAS9.ad.analog.com (nwd2hubcas9.ad.analog.com [10.64.72.142]) by nwd2mta1.analog.com (8.13.8/8.13.8) with ESMTP id t157WZNE004883 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Wed, 4 Feb 2015 23:32:35 -0800 Received: from zeus.spd.analog.com (10.64.82.11) by NWD2HUBCAS9.ad.analog.com (10.64.72.142) with Microsoft SMTP Server id 14.3.210.2; Thu, 5 Feb 2015 02:32:21 -0500 Received: from linux.site ([10.99.22.20]) by zeus.spd.analog.com (8.14.6/8.14.6) with ESMTP id t157WIQw029122; Thu, 5 Feb 2015 02:32:19 -0500 Received: from nine.ad.analog.com (unknown [10.99.24.95]) by linux.site (Postfix) with ESMTP id 8AC0D3B00E7A; Wed, 4 Feb 2015 16:35:55 -0700 (MST) From: Sonic Zhang To: Dmitry Torokhov , CC: Michael Hennerich , , Sonic Zhang Subject: [PATCH v4 3/3] bfin_rotary: replace bfin specific MMR function with generic IO function Date: Thu, 5 Feb 2015 15:30:38 +0800 Message-ID: <1423121438-11940-1-git-send-email-sonic.adi@gmail.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Matching-Connectors: 130675951947553954; (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)(77096005)(50226001)(55446002)(82202001)(229853001)(105596002)(92566002)(106466001)(50466002)(47776003)(83322999)(87936001)(36756003)(6806004)(33646002)(48376002)(86362001)(19580405001)(19580395003)(46102003)(575784001)(73392002)(50986999)(87572001)(81442002)(62966003)(77156002)(73972006)(76482003)(41533002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR0301MB0752; H:nwd2mta1.analog.com; FPR:; SPF:SoftFail; MLV:sfv; LANG:en; X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB0752; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004); SRVR:DM2PR0301MB0752; X-Forefront-PRVS: 0478C23FE0 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(401004)(400005); SRVR:DM2PR0301MB0752; X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2015 07:33:14.6461 (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: DM2PR0301MB0752 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 v4-changes: - remap rotary register physical address into kernel space in probe Signed-off-by: Sonic Zhang --- arch/blackfin/mach-bf527/boards/ad7160eval.c | 5 +++ arch/blackfin/mach-bf527/boards/ezkit.c | 5 +++ arch/blackfin/mach-bf548/boards/ezkit.c | 5 +++ arch/blackfin/mach-bf609/boards/ezkit.c | 5 +++ drivers/input/misc/bfin_rotary.c | 62 ++++++++++++++++++-------- 5 files changed, 63 insertions(+), 19 deletions(-) diff --git a/arch/blackfin/mach-bf527/boards/ad7160eval.c b/arch/blackfin/mach-bf527/boards/ad7160eval.c index 029a050..68f2a8a 100644 --- a/arch/blackfin/mach-bf527/boards/ad7160eval.c +++ b/arch/blackfin/mach-bf527/boards/ad7160eval.c @@ -688,6 +688,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = { static struct resource bfin_rotary_resources[] = { { + .start = CNT_CONFIG, + .end = CNT_CONFIG + 0xff, + .flags = IORESOURCE_MEM, + }, + { .start = IRQ_CNT, .end = IRQ_CNT, .flags = IORESOURCE_IRQ, diff --git a/arch/blackfin/mach-bf527/boards/ezkit.c b/arch/blackfin/mach-bf527/boards/ezkit.c index cc80c5b..d4219e8 100644 --- a/arch/blackfin/mach-bf527/boards/ezkit.c +++ b/arch/blackfin/mach-bf527/boards/ezkit.c @@ -1114,6 +1114,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = { static struct resource bfin_rotary_resources[] = { { + .start = CNT_CONFIG, + .end = CNT_CONFIG + 0xff, + .flags = IORESOURCE_MEM, + }, + { .start = IRQ_CNT, .end = IRQ_CNT, .flags = IORESOURCE_IRQ, diff --git a/arch/blackfin/mach-bf548/boards/ezkit.c b/arch/blackfin/mach-bf548/boards/ezkit.c index 8f70f83..4204b98 100644 --- a/arch/blackfin/mach-bf548/boards/ezkit.c +++ b/arch/blackfin/mach-bf548/boards/ezkit.c @@ -173,6 +173,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = { static struct resource bfin_rotary_resources[] = { { + .start = CNT_CONFIG, + .end = CNT_CONFIG + 0xff, + .flags = IORESOURCE_MEM, + }, + { .start = IRQ_CNT, .end = IRQ_CNT, .flags = IORESOURCE_IRQ, diff --git a/arch/blackfin/mach-bf609/boards/ezkit.c b/arch/blackfin/mach-bf609/boards/ezkit.c index f9dc64d..7f9fc27 100644 --- a/arch/blackfin/mach-bf609/boards/ezkit.c +++ b/arch/blackfin/mach-bf609/boards/ezkit.c @@ -88,6 +88,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = { static struct resource bfin_rotary_resources[] = { { + .start = CNT_CONFIG, + .end = CNT_CONFIG + 0xff, + .flags = IORESOURCE_MEM, + }, + { .start = IRQ_CNT, .end = IRQ_CNT, .flags = IORESOURCE_IRQ, diff --git a/drivers/input/misc/bfin_rotary.c b/drivers/input/misc/bfin_rotary.c index dd62fc9..ba0db7e 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,16 +87,18 @@ 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; } static int bfin_rotary_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; struct bfin_rotary_platform_data *pdata = dev_get_platdata(&pdev->dev); struct bfin_rot *rotary; + struct resource *res; struct input_dev *input; int error; @@ -108,6 +121,13 @@ static int bfin_rotary_probe(struct platform_device *pdev) goto out1; } + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + rotary->base = devm_ioremap_resource(dev, res); + if (IS_ERR(rotary->base)) { + error = PTR_ERR(rotary->base); + goto out1; + } + rotary->input = input; rotary->up_key = pdata->rotary_up_key; @@ -161,17 +181,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 +217,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 +235,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 +250,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; }