From patchwork Fri Aug 31 09:21:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ludovic Desroches X-Patchwork-Id: 1391841 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 9414D3FC85 for ; Fri, 31 Aug 2012 09:26:18 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T7NQx-0004TD-Mu; Fri, 31 Aug 2012 09:22:36 +0000 Received: from eusmtp01.atmel.com ([212.144.249.242]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T7NQg-0004QP-AE for linux-arm-kernel@lists.infradead.org; Fri, 31 Aug 2012 09:22:19 +0000 Received: from HNOCHT02.corp.atmel.com (10.161.30.162) by eusmtp01.atmel.com (10.161.101.30) with Microsoft SMTP Server (TLS) id 14.2.318.1; Fri, 31 Aug 2012 11:23:34 +0200 Received: from ibiza.rfo.atmel.com (10.159.245.197) by HNOCHT02.corp.atmel.com (10.161.30.160) with Microsoft SMTP Server (TLS) id 14.2.318.1; Fri, 31 Aug 2012 11:22:11 +0200 From: To: , , Subject: [PATCH 1/8] i2c: at91: use managed resources Date: Fri, 31 Aug 2012 11:21:17 +0200 Message-ID: <1346404884-18451-2-git-send-email-ludovic.desroches@atmel.com> X-Mailer: git-send-email 1.7.11.3 In-Reply-To: <1346404884-18451-1-git-send-email-ludovic.desroches@atmel.com> References: <1346404884-18451-1-git-send-email-ludovic.desroches@atmel.com> MIME-Version: 1.0 X-Originating-IP: [10.159.245.197] X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.1 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: plagnioj@jcrosoft.com, n.voss@weinmann.de, nicolas.ferre@atmel.com, Ludovic Desroches X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 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 From: Ludovic Desroches Use managed resources to ease the cleanup. Signed-off-by: Ludovic Desroches Acked-by: Nikolaus Voss --- drivers/i2c/busses/i2c-at91.c | 85 +++++++++++++------------------------------ 1 file changed, 25 insertions(+), 60 deletions(-) diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c index 2b8b2c2..08aaee7 100644 --- a/drivers/i2c/busses/i2c-at91.c +++ b/drivers/i2c/busses/i2c-at91.c @@ -326,61 +326,49 @@ static struct i2c_algorithm at91_twi_algorithm = { static int __devinit at91_twi_probe(struct platform_device *pdev) { struct at91_twi_dev *dev; - struct resource *mem, *ioarea; - int irq, rc; + struct resource *mem; + int rc; + + dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + if (!dev) + return -ENOMEM; + init_completion(&dev->cmd_complete); + dev->dev = &pdev->dev; mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!mem) return -ENODEV; - irq = platform_get_irq(pdev, 0); - if (irq < 0) - return irq; - - ioarea = request_mem_region(mem->start, resource_size(mem), pdev->name); - if (!ioarea) + dev->base = devm_request_and_ioremap(&pdev->dev, mem); + if (!dev->base) return -EBUSY; - dev = kzalloc(sizeof(*dev), GFP_KERNEL); - if (!dev) { - rc = -ENOMEM; - goto err_release_region; + dev->irq = platform_get_irq(pdev, 0); + if (dev->irq < 0) + return dev->irq; + + rc = devm_request_irq(&pdev->dev, dev->irq, atmel_twi_interrupt, 0, + dev_name(dev->dev), dev); + if (rc) { + dev_err(dev->dev, "Cannot get irq %d: %d\n", dev->irq, rc); + return rc; } if (pdev->id_entry) dev->ip_id = pdev->id_entry->driver_data; - init_completion(&dev->cmd_complete); - - dev->dev = &pdev->dev; - dev->irq = irq; platform_set_drvdata(pdev, dev); - dev->clk = clk_get(dev->dev, NULL); + dev->clk = devm_clk_get(dev->dev, NULL); if (IS_ERR(dev->clk)) { dev_err(dev->dev, "no clock defined\n"); - rc = -ENODEV; - goto err_free_mem; - } - clk_prepare(dev->clk); - clk_enable(dev->clk); - - dev->base = ioremap(mem->start, resource_size(mem)); - if (!dev->base) { - rc = -EBUSY; - goto err_mem_ioremap; + return -ENODEV; } + clk_prepare_enable(dev->clk); at91_calc_twi_clock(dev, TWI_CLK_HZ); at91_init_twi_bus(dev); - rc = request_irq(dev->irq, atmel_twi_interrupt, 0, - dev_name(dev->dev), dev); - if (rc) { - dev_err(dev->dev, "Cannot get irq %d: %d\n", dev->irq, rc); - goto err_unuse_clocks; - } - snprintf(dev->adapter.name, sizeof(dev->adapter.name), "AT91"); i2c_set_adapdata(&dev->adapter, dev); dev->adapter.owner = THIS_MODULE; @@ -394,44 +382,21 @@ static int __devinit at91_twi_probe(struct platform_device *pdev) if (rc) { dev_err(dev->dev, "Adapter %s registration failed\n", dev->adapter.name); - goto err_free_irq; + clk_disable_unprepare(dev->clk); + return rc; } dev_info(dev->dev, "AT91 i2c bus driver.\n"); return 0; - -err_free_irq: - free_irq(dev->irq, dev); -err_unuse_clocks: - iounmap(dev->base); -err_mem_ioremap: - clk_disable(dev->clk); - clk_unprepare(dev->clk); - clk_put(dev->clk); -err_free_mem: - kfree(dev); -err_release_region: - release_mem_region(mem->start, resource_size(mem)); - - return rc; } static int __devexit at91_twi_remove(struct platform_device *pdev) { struct at91_twi_dev *dev = platform_get_drvdata(pdev); - struct resource *mem; int rc; rc = i2c_del_adapter(&dev->adapter); - clk_disable(dev->clk); - clk_unprepare(dev->clk); - clk_put(dev->clk); - free_irq(dev->irq, dev); - iounmap(dev->base); - kfree(dev); - - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); - release_mem_region(mem->start, resource_size(mem)); + clk_disable_unprepare(dev->clk); return rc; }