From patchwork Wed Jun 11 08:56:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 31723 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f198.google.com (mail-ig0-f198.google.com [209.85.213.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 825CF203C2 for ; Wed, 11 Jun 2014 08:58:50 +0000 (UTC) Received: by mail-ig0-f198.google.com with SMTP id uq10sf1773740igb.5 for ; Wed, 11 Jun 2014 01:58:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=iSVyMQFIkRy19qOms1x5v/ucQVtz2hcEUyZlZQKKd7w=; b=JtF3W/G3Xnb06Spt4BqNcIFz9FIfcMkQl6enl4uvOj+E6bPPAs6TaiTxoCHE490LKh ZukieOb91ENEdX9AGXQTd0kLDVS9H4c23on9vUZFl4Ijnj3HtfAq4tjRkXR/U70HnEhF 1bkhV1ATKvVovqB5SA4Y3C8CaqTLPKc2UX1nZdbTuxS5G2j7oeX6Zu+W+jVB/BOkVeAC bGISS0LGlIAyFRQQhZw1OlwQQpXhVQBdkZdhWvV+dkA6TPLb57wQQ+fRMFSpw+V32sEs b6YnfyvK/HkitGaHBnxafV9Fx1BLPopsLcrZ2mw6Tbg+IbjsX6X0i5OgaeWg9obIWE/t SQmA== X-Gm-Message-State: ALoCoQm+QZjqzwKmBkYX/f8q3bb+NFvpEIhGhg7aXz2q0r7krTsxogTwZWLUp5Slgth/lQ73R5XA X-Received: by 10.43.66.6 with SMTP id xo6mr6068692icb.33.1402477130123; Wed, 11 Jun 2014 01:58:50 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.25.171 with SMTP id 40ls2514721qgt.85.gmail; Wed, 11 Jun 2014 01:58:50 -0700 (PDT) X-Received: by 10.58.230.101 with SMTP id sx5mr26234290vec.10.1402477130007; Wed, 11 Jun 2014 01:58:50 -0700 (PDT) Received: from mail-ve0-f170.google.com (mail-ve0-f170.google.com [209.85.128.170]) by mx.google.com with ESMTPS id o10si13999918vdo.29.2014.06.11.01.58.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Jun 2014 01:58:49 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.170 as permitted sender) client-ip=209.85.128.170; Received: by mail-ve0-f170.google.com with SMTP id oz11so5644815veb.1 for ; Wed, 11 Jun 2014 01:58:49 -0700 (PDT) X-Received: by 10.52.12.129 with SMTP id y1mr381497vdb.59.1402477129886; Wed, 11 Jun 2014 01:58:49 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.54.6 with SMTP id vs6csp286463vcb; Wed, 11 Jun 2014 01:58:49 -0700 (PDT) X-Received: by 10.66.228.133 with SMTP id si5mr12148552pac.48.1402477129083; Wed, 11 Jun 2014 01:58:49 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ba10si37358542pbd.48.2014.06.11.01.58.48; Wed, 11 Jun 2014 01:58:48 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753270AbaFKI6n (ORCPT + 27 others); Wed, 11 Jun 2014 04:58:43 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:56333 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753620AbaFKI6b (ORCPT ); Wed, 11 Jun 2014 04:58:31 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id s5B8vu9b027750; Wed, 11 Jun 2014 03:57:56 -0500 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s5B8vuJQ008802; Wed, 11 Jun 2014 03:57:56 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.174.1; Wed, 11 Jun 2014 03:57:56 -0500 Received: from localhost.localdomain (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s5B8uiSr020510; Wed, 11 Jun 2014 03:57:53 -0500 From: Roger Quadros To: , , CC: , , , , , , , , , Roger Quadros Subject: [PATCH 19/36] mtd: onenand: omap: Use devres managed resources Date: Wed, 11 Jun 2014 11:56:24 +0300 Message-ID: <1402477001-31132-20-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1402477001-31132-1-git-send-email-rogerq@ti.com> References: <1402477001-31132-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: rogerq@ti.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Use devres managed resources for Memory, GPIO and Interrupt resources. 0 is a valid gpio, so use gpio_is_valid() to check for valid gpio number. Signed-off-by: Roger Quadros --- drivers/mtd/onenand/omap2.c | 92 ++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 59 deletions(-) diff --git a/drivers/mtd/onenand/omap2.c b/drivers/mtd/onenand/omap2.c index 238dd7a..b6a9ec0 100644 --- a/drivers/mtd/onenand/omap2.c +++ b/drivers/mtd/onenand/omap2.c @@ -38,8 +38,7 @@ #include #include #include -#include - +#include #include #define DRIVER_NAME "omap2-onenand" @@ -835,6 +834,7 @@ static int omap2_onenand_probe(struct platform_device *pdev) int r; struct resource *res; struct mtd_part_parser_data ppdata = {}; + struct device *dev = &pdev->dev; pdata = dev_get_platdata(&pdev->dev); if (pdata == NULL) { @@ -842,7 +842,7 @@ static int omap2_onenand_probe(struct platform_device *pdev) return -ENODEV; } - c = kzalloc(sizeof(struct omap2_onenand), GFP_KERNEL); + c = devm_kzalloc(dev, sizeof(struct omap2_onenand), GFP_KERNEL); if (!c) return -ENOMEM; @@ -855,50 +855,40 @@ static int omap2_onenand_probe(struct platform_device *pdev) c->dma_channel = pdata->dma_channel; if (c->dma_channel < 0) { /* if -1, don't use DMA */ - c->gpio_irq = 0; + c->gpio_irq = -EINVAL; } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (res == NULL) { - r = -EINVAL; - dev_err(&pdev->dev, "error getting memory resource\n"); - goto err_kfree; - } + c->onenand.base = devm_ioremap_resource(dev, res); + if (IS_ERR(c->onenand.base)) + return PTR_ERR(c->onenand.base); c->phys_base = res->start; c->mem_size = resource_size(res); - if (request_mem_region(c->phys_base, c->mem_size, - pdev->dev.driver->name) == NULL) { - dev_err(&pdev->dev, "Cannot reserve memory region at 0x%08lx, size: 0x%x\n", - c->phys_base, c->mem_size); - r = -EBUSY; - goto err_kfree; - } - c->onenand.base = ioremap(c->phys_base, c->mem_size); - if (c->onenand.base == NULL) { - r = -ENOMEM; - goto err_release_mem_region; - } - r = omap2_onenand_setup(c); - if (r < 0) { - dev_err(&pdev->dev, "setup failed:%d\n", r); - goto err_iounmap; - } + if (r) + return -ENODEV; - if (c->gpio_irq) { - if ((r = gpio_request(c->gpio_irq, "OneNAND irq")) < 0) { - dev_err(&pdev->dev, "Failed to request GPIO%d for " - "OneNAND\n", c->gpio_irq); - goto err_iounmap; - } - gpio_direction_input(c->gpio_irq); + if (gpio_is_valid(c->gpio_irq)) { + r = devm_gpio_request(dev, c->gpio_irq, "OneNAND irq"); + if (r) { + dev_err(dev, "Failed to request GPIO %d", + c->gpio_irq); + return r; + } + + gpio_direction_input(c->gpio_irq); - if ((r = request_irq(gpio_to_irq(c->gpio_irq), - omap2_onenand_interrupt, IRQF_TRIGGER_RISING, - pdev->dev.driver->name, c)) < 0) - goto err_release_gpio; + r = devm_request_irq(dev, gpio_to_irq(c->gpio_irq), + omap2_onenand_interrupt, + IRQF_TRIGGER_RISING, + pdev->dev.driver->name, c); + if (r) { + dev_err(dev, "failed to request IRQ %d:%d\n", + c->gpio_irq, r); + return r; + } } if (c->dma_channel >= 0) { @@ -915,9 +905,8 @@ static int omap2_onenand_probe(struct platform_device *pdev) omap_set_dma_dest_burst_mode(c->dma_channel, OMAP_DMA_DATA_BURST_8); } else { - dev_info(&pdev->dev, - "failed to allocate DMA for OneNAND, " - "using PIO instead\n"); + dev_info(dev, + "failed to allocate DMA for OneNAND, using PIO instead\n"); c->dma_channel = -1; } } @@ -947,8 +936,11 @@ static int omap2_onenand_probe(struct platform_device *pdev) if (pdata->skip_initial_unlocking) this->options |= ONENAND_SKIP_INITIAL_UNLOCKING; - if ((r = onenand_scan(&c->mtd, 1)) < 0) + r = onenand_scan(&c->mtd, 1); + if (r) { + dev_err(dev, "OneNAND scan failed :%d\n", r); goto err_release_dma; + } ppdata.of_node = pdata->of_node; r = mtd_device_parse_register(&c->mtd, NULL, &ppdata, @@ -966,17 +958,6 @@ err_release_onenand: err_release_dma: if (c->dma_channel != -1) omap_free_dma(c->dma_channel); - if (c->gpio_irq) - free_irq(gpio_to_irq(c->gpio_irq), c); -err_release_gpio: - if (c->gpio_irq) - gpio_free(c->gpio_irq); -err_iounmap: - iounmap(c->onenand.base); -err_release_mem_region: - release_mem_region(c->phys_base, c->mem_size); -err_kfree: - kfree(c); return r; } @@ -989,13 +970,6 @@ static int omap2_onenand_remove(struct platform_device *pdev) if (c->dma_channel != -1) omap_free_dma(c->dma_channel); omap2_onenand_shutdown(pdev); - if (c->gpio_irq) { - free_irq(gpio_to_irq(c->gpio_irq), c); - gpio_free(c->gpio_irq); - } - iounmap(c->onenand.base); - release_mem_region(c->phys_base, c->mem_size); - kfree(c); return 0; }