From patchwork Wed Feb 4 07:58:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sonic zhang X-Patchwork-Id: 5775191 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 0E1F6BF440 for ; Wed, 4 Feb 2015 08:00:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F2162202E5 for ; Wed, 4 Feb 2015 08:00:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BF8D6202C8 for ; Wed, 4 Feb 2015 08:00:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751287AbbBDIAs (ORCPT ); Wed, 4 Feb 2015 03:00:48 -0500 Received: from mail-bn1bon0064.outbound.protection.outlook.com ([157.56.111.64]:51046 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752856AbbBDIAr (ORCPT ); Wed, 4 Feb 2015 03:00:47 -0500 Received: from CH1PR03CA003.namprd03.prod.outlook.com (10.255.156.148) by DM2PR0301MB0752.namprd03.prod.outlook.com (25.160.97.148) with Microsoft SMTP Server (TLS) id 15.1.75.20; Wed, 4 Feb 2015 08:00:45 +0000 Received: from BL2FFO11OLC002.protection.gbl (10.255.156.132) by CH1PR03CA003.outlook.office365.com (10.255.156.148) with Microsoft SMTP Server (TLS) id 15.1.75.20 via Frontend Transport; Wed, 4 Feb 2015 08:00:44 +0000 Received: from nwd2mta1.analog.com (137.71.25.55) by BL2FFO11OLC002.mail.protection.outlook.com (10.173.161.186) with Microsoft SMTP Server (TLS) id 15.1.87.10 via Frontend Transport; Wed, 4 Feb 2015 08:00:45 +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 t14804k1028469 (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 NWD2HUBCAS9.ad.analog.com (10.64.72.142) 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 t147xbgO011493; 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 17C563B00E8A; Tue, 3 Feb 2015 17:03:13 -0700 (MST) From: Sonic Zhang To: Dmitry Torokhov , CC: Michael Hennerich , , Sonic Zhang Subject: [PATCH] bfin_rotary: convert to use managed resources Date: Wed, 4 Feb 2015 15:58:06 +0800 Message-ID: <1423036686-31891-3-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: 130675104451154376; (52f37747-95c3-483a-bd05-08d153b03fac); () X-Forefront-Antispam-Report: CIP:137.71.25.55; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(55446002)(61266001)(77096005)(86362001)(50226001)(33646002)(50466002)(82202001)(229853001)(106466001)(47776003)(87936001)(36756003)(83322999)(6806004)(92566002)(48376002)(46102003)(19580395003)(19580405001)(2950100001)(76176999)(81442002)(73392002)(50986999)(87572001)(77156002)(76482003)(62966003)(73972006); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR0301MB0752; H:nwd2mta1.analog.com; FPR:; SPF:None; MLV:sfv; LANG:en; Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; 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: 04772EA191 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(401004)(400005); SRVR:DM2PR0301MB0752; X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2015 08:00:45.0686 (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 - remap rotary register physical address into kernel space in probe - replace kzalloc with devm_kzalloc - replace request_irq with devm_request_irq - remove memory free and irq free from the device remove function - use devm_input_allocate_device 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 | 64 ++++++++++++++------------ 5 files changed, 54 insertions(+), 30 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 defddca..3bc0018 100644 --- a/drivers/input/misc/bfin_rotary.c +++ b/drivers/input/misc/bfin_rotary.c @@ -95,11 +95,38 @@ static irqreturn_t bfin_rotary_isr(int irq, void *dev_id) 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; + rotary = devm_kzalloc(dev, sizeof(struct bfin_rot), GFP_KERNEL); + if (!rotary) { + dev_err(dev, "fail to malloc bfin_rot\n"); + return -ENOMEM; + } + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + rotary->base = devm_ioremap_resource(dev, res); + if (IS_ERR(rotary->base)) + return PTR_ERR(rotary->base); + + rotary->irq = platform_get_irq(pdev, 0); + if (rotary->irq < 0) { + dev_err(dev, "No rotary IRQ specified\n"); + return -ENOENT; + } + + error = devm_request_irq(dev, rotary->irq, bfin_rotary_isr, + 0, dev_name(&pdev->dev), pdev); + if (error) { + dev_err(dev, "unable to claim irq %d; error %d\n", + rotary->irq, error); + return error; + } + /* Basic validation */ if ((pdata->rotary_up_key && !pdata->rotary_down_key) || (!pdata->rotary_up_key && pdata->rotary_down_key)) { @@ -108,15 +135,14 @@ static int bfin_rotary_probe(struct platform_device *pdev) error = peripheral_request_list(pdata->pin_list, dev_name(&pdev->dev)); if (error) { - dev_err(&pdev->dev, "requesting peripherals failed\n"); + dev_err(dev, "requesting peripherals failed\n"); return error; } - rotary = kzalloc(sizeof(struct bfin_rot), GFP_KERNEL); - input = input_allocate_device(); - if (!rotary || !input) { + input = devm_input_allocate_device(dev); + if (!input) { error = -ENOMEM; - goto out1; + goto out; } rotary->input = input; @@ -126,10 +152,6 @@ static int bfin_rotary_probe(struct platform_device *pdev) rotary->button_key = pdata->rotary_button_key; rotary->rel_code = pdata->rotary_rel_code; - error = rotary->irq = platform_get_irq(pdev, 0); - if (error < 0) - goto out1; - input->name = pdev->name; input->phys = "bfin-rotary/input0"; input->dev.parent = &pdev->dev; @@ -155,20 +177,10 @@ static int bfin_rotary_probe(struct platform_device *pdev) __set_bit(rotary->button_key, input->keybit); } - error = request_irq(rotary->irq, bfin_rotary_isr, - 0, dev_name(&pdev->dev), pdev); - if (error) { - dev_err(&pdev->dev, - "unable to claim irq %d; error %d\n", - rotary->irq, error); - goto out1; - } - error = input_register_device(input); if (error) { - dev_err(&pdev->dev, - "unable to register input device (%d)\n", error); - goto out2; + dev_err(dev, "unable to register input device (%d)\n", error); + goto out; } if (pdata->rotary_button_key) @@ -193,11 +205,7 @@ static int bfin_rotary_probe(struct platform_device *pdev) return 0; -out2: - free_irq(rotary->irq, pdev); -out1: - input_free_device(input); - kfree(rotary); +out: peripheral_free_list(per_cnt); return error; @@ -211,12 +219,8 @@ static int bfin_rotary_remove(struct platform_device *pdev) writew(0, rotary->base + CNT_CONFIG_OFF); writew(0, rotary->base + CNT_IMASK_OFF); - free_irq(rotary->irq, pdev); - input_unregister_device(rotary->input); peripheral_free_list(pdata->pin_list); - kfree(rotary); - return 0; }