From patchwork Wed Jan 24 10:06:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 865277 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="inwPnvEA"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zRLSQ0Clyz9s9Y for ; Wed, 24 Jan 2018 21:07:17 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VWns/HfFsacbVsUoMC4O9Ur6jOJMzTrwZ0DysVuNFwE=; b=inwPnvEA1HWwcx lL0Mcvxa6hpoUNYMw5F/g3eNvFqfKdv0KsVcWaexfK7O1ehaxVexvs1/26So4Wvl5iZ73lkuXf6gs 1w4ECAMOXwWyHEBVSUCld9ZTppGH3eGkPiqyb6697m1zh43j0zs96xUL6mD13r/C/qJjLG+VO1hD7 xY1/ewEK+hNHL4GozaiZU4eZ6KyMaL3+0CEwsf+tjvGqYBV4p9x3kpL1YMIyPzXpZp4F/WbplSOFV L79oL8DNdjYKDGnvjkv+IskD0yZa/Wm2q+ZzeMH/0ScCLF9LrNOXha7/VgJpEstcuXHul7VWI4oAG OPdrJrqwFWIQHg0BlAlA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eeHxa-00077t-IZ; Wed, 24 Jan 2018 10:07:14 +0000 Received: from eddie.linux-mips.org ([148.251.95.138] helo=cvs.linux-mips.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eeHxW-00076a-Ip for linux-mtd@lists.infradead.org; Wed, 24 Jan 2018 10:07:12 +0000 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23990474AbeAXKG61aDAV (ORCPT ); Wed, 24 Jan 2018 11:06:58 +0100 Date: Wed, 24 Jan 2018 11:06:57 +0100 From: Ladislav Michl To: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [PATCH v2 1/3] devres: Move devm_ioremap_resource() out of device.h Message-ID: <20180124100657.GB19593@lenoch> References: <20180124100604.GA19593@lenoch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180124100604.GA19593@lenoch> User-Agent: Mutt/1.9.2 (2017-12-15) X-Spam-Note: CRM114 invocation failed X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [148.251.95.138 listed in list.dnswl.org] -0.0 T_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] 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kate Stewart , Tom Lendacky , Lorenzo Pieralisi , Boris Brezillon , Greg Kroah-Hartman , Dmitry Torokhov , Wei Yongjun , Philippe Ombredanne , Bjorn Helgaas , Thomas Gleixner , Borislav Petkov , Ingo Molnar Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Move devm_ioremap_resource() out of device.h into io.h to be consistent with similar APIs. Signed-off-by: Ladislav Michl --- Changes: - v2: new patch include/linux/device.h | 2 -- include/linux/io.h | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/include/linux/device.h b/include/linux/device.h index 4d88b6b9cda9..c9fcee2f5b91 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -683,8 +683,6 @@ extern unsigned long devm_get_free_pages(struct device *dev, gfp_t gfp_mask, unsigned int order); extern void devm_free_pages(struct device *dev, unsigned long addr); -void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); - /* allows to add/remove a custom action to devres stack */ int devm_add_action(struct device *dev, void (*action)(void *), void *data); void devm_remove_action(struct device *dev, void (*action)(void *), void *data); diff --git a/include/linux/io.h b/include/linux/io.h index 32e30e8fb9db..2aea3363bfb2 100644 --- a/include/linux/io.h +++ b/include/linux/io.h @@ -79,6 +79,7 @@ void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset, resource_size_t size); void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset, resource_size_t size); +void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); void devm_iounmap(struct device *dev, void __iomem *addr); int check_signature(const volatile void __iomem *io_addr, const unsigned char *signature, int length); From patchwork Wed Jan 24 10:07:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 865278 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jgMcCPcB"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zRLTV35fvz9s72 for ; Wed, 24 Jan 2018 21:08:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=289fTee16dtamKNnodaYzST11jNd4deNAr4SFCQbJLw=; b=jgMcCPcB6AVW1j UA/eGwQV5YRkh8cKeyLOVWN20p1v28xiX7y42nL3/SoLc6ZfddmHdkt9asR6H4HuW8ZEde6IDBcrj xLg9OhXBvSphQR38B9jmg0dus5Z2TBq5g25OpUUX7fv97QWX4z4yrmS98rQSckYX3Qx+RHzPzqIv3 kFmDir99NtF3GWtM45GbTpPedsBDgDRNyrbQL+2f5WlCQW1pHeoFp1nZ5LDBjKW1sUYjOlPHsHkiD FqZ5ENXc8wt+xCAfVTiYVKow5xunfcCoNNniFHkt84ScsDV36P++bQCUs/QmaKOG8bCpKdBN1HNrM XEIf2xqDGddQDGFIU00A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eeHyU-0007OD-QN; Wed, 24 Jan 2018 10:08:10 +0000 Received: from eddie.linux-mips.org ([148.251.95.138] helo=cvs.linux-mips.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eeHyR-0007Nl-TY for linux-mtd@lists.infradead.org; Wed, 24 Jan 2018 10:08:09 +0000 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23991025AbeAXKH4IwC-V (ORCPT ); Wed, 24 Jan 2018 11:07:56 +0100 Date: Wed, 24 Jan 2018 11:07:54 +0100 From: Ladislav Michl To: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [PATCH v2 2/3] devres: Add devm_ioremap_shared_resource() Message-ID: <20180124100754.GC19593@lenoch> References: <20180124100604.GA19593@lenoch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180124100604.GA19593@lenoch> User-Agent: Mutt/1.9.2 (2017-12-15) X-Spam-Note: CRM114 invocation failed X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [148.251.95.138 listed in list.dnswl.org] -0.0 T_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] 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kate Stewart , Tom Lendacky , Lorenzo Pieralisi , Boris Brezillon , Greg Kroah-Hartman , Dmitry Torokhov , Wei Yongjun , Philippe Ombredanne , Bjorn Helgaas , Thomas Gleixner , Borislav Petkov , Ingo Molnar Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Implement managed ioremap function for shared resources. Signed-off-by: Ladislav Michl --- Changes: - v2: Rebased on top of PATCH v2 1/3 include/linux/io.h | 8 +++++++- lib/devres.c | 22 ++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/include/linux/io.h b/include/linux/io.h index 2aea3363bfb2..2b9eb48e0f49 100644 --- a/include/linux/io.h +++ b/include/linux/io.h @@ -79,10 +79,16 @@ void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset, resource_size_t size); void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset, resource_size_t size); -void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); +#define devm_ioremap_resource(dev, res) \ + __devm_ioremap_resource(dev, res, false) +#define devm_ioremap_shared_resource(dev, res) \ + __devm_ioremap_resource(dev, res, true) +void __iomem *__devm_ioremap_resource(struct device *dev, struct resource *res, + bool shared); void devm_iounmap(struct device *dev, void __iomem *addr); int check_signature(const volatile void __iomem *io_addr, const unsigned char *signature, int length); + void devm_ioremap_release(struct device *dev, void *res); void *devm_memremap(struct device *dev, resource_size_t offset, diff --git a/lib/devres.c b/lib/devres.c index 5f2aedd58bc5..7711ff40a572 100644 --- a/lib/devres.c +++ b/lib/devres.c @@ -22,6 +22,9 @@ static int devm_ioremap_match(struct device *dev, void *res, void *match_data) * @size: Size of map * * Managed ioremap(). Map is automatically unmapped on driver detach. + * + * When possible, use devm_ioremap_resource() or + * devm_ioremap_shared_resource() instead. */ void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, resource_size_t size) @@ -116,13 +119,14 @@ void devm_iounmap(struct device *dev, void __iomem *addr) EXPORT_SYMBOL(devm_iounmap); /** - * devm_ioremap_resource() - check, request region, and ioremap resource + * __devm_ioremap_resource() - check, request region, and ioremap resource * @dev: generic device to handle the resource for * @res: resource to be handled + * @shared: region is not requested when true * - * Checks that a resource is a valid memory region, requests the memory - * region and ioremaps it. All operations are managed and will be undone - * on driver detach. + * Checks that a resource is a valid memory region, eventually requests the + * memory region and ioremaps it. All operations are managed and will be + * undone on driver detach. * * Returns a pointer to the remapped memory or an ERR_PTR() encoded error code * on failure. Usage example: @@ -132,7 +136,8 @@ EXPORT_SYMBOL(devm_iounmap); * if (IS_ERR(base)) * return PTR_ERR(base); */ -void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) +void __iomem *__devm_ioremap_resource(struct device *dev, struct resource *res, + bool shared) { resource_size_t size; const char *name; @@ -148,7 +153,7 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) size = resource_size(res); name = res->name ?: dev_name(dev); - if (!devm_request_mem_region(dev, res->start, size, name)) { + if (!shared && !devm_request_mem_region(dev, res->start, size, name)) { dev_err(dev, "can't request region for resource %pR\n", res); return IOMEM_ERR_PTR(-EBUSY); } @@ -156,13 +161,14 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) dest_ptr = devm_ioremap(dev, res->start, size); if (!dest_ptr) { dev_err(dev, "ioremap failed for resource %pR\n", res); - devm_release_mem_region(dev, res->start, size); + if (!shared) + devm_release_mem_region(dev, res->start, size); dest_ptr = IOMEM_ERR_PTR(-ENOMEM); } return dest_ptr; } -EXPORT_SYMBOL(devm_ioremap_resource); +EXPORT_SYMBOL(__devm_ioremap_resource); #ifdef CONFIG_HAS_IOPORT_MAP /* From patchwork Wed Jan 24 10:08:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 865279 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="McPk+Ptg"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zRLTy6ppqz9s9Y for ; Wed, 24 Jan 2018 21:08:38 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xOyTqmaxYJJMQX6y5Tg2rryzNCv7R+l0waF7rYDYKlA=; b=McPk+PtgSpAx7w iZ3LpZVBk4dS3YfykF3faugq09d0ZF1RBzzYN7Xhf6DMpd13BQWvBye8ABNjbj4B5WEIx+Y1Y8F2f JAvGNvOMXujYIshoERWGneUUzh6UR2wcthtSfHb1MbQwWONMhdtGvqtSwo4YjuINBEF+tiM8u5kvp AxbxdnfL7fnarozRSJIk+TiZuYoFzBXq1i+plitye2YzN5NDpRUk34eqaq6PeX45ZqWcxp8A7hKy7 V9oT+4ri1DTxVaGb+vCnRDVvj+EpDPfKbwQYgUrawKFleC6uIL8QFB3e3xiQjDpLjPnh0GXtLADiB O8/wLeO/+4fRTISFAyRQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eeHyt-0007dF-Co; Wed, 24 Jan 2018 10:08:35 +0000 Received: from eddie.linux-mips.org ([148.251.95.138] helo=cvs.linux-mips.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eeHyq-0007Nl-2G for linux-mtd@lists.infradead.org; Wed, 24 Jan 2018 10:08:33 +0000 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23992821AbeAXKIaWZvDV (ORCPT ); Wed, 24 Jan 2018 11:08:30 +0100 Date: Wed, 24 Jan 2018 11:08:28 +0100 From: Ladislav Michl To: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [PATCH v2 3/3] mtd: nand: davinci: Use devm_ioremap_shared_resource() Message-ID: <20180124100828.GD19593@lenoch> References: <20180124100604.GA19593@lenoch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180124100604.GA19593@lenoch> User-Agent: Mutt/1.9.2 (2017-12-15) X-Spam-Note: CRM114 invocation failed X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [148.251.95.138 listed in list.dnswl.org] -0.0 T_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] 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kate Stewart , Tom Lendacky , Lorenzo Pieralisi , Boris Brezillon , Greg Kroah-Hartman , Dmitry Torokhov , Wei Yongjun , Philippe Ombredanne , Bjorn Helgaas , Thomas Gleixner , Borislav Petkov , Ingo Molnar Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Simplify error handling by using devm_ioremap_shared_resource(). Signed-off-by: Ladislav Michl --- Changes: - v2: None drivers/mtd/nand/davinci_nand.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c index ccc8c43abcff..9b6f06b177b9 100644 --- a/drivers/mtd/nand/davinci_nand.c +++ b/drivers/mtd/nand/davinci_nand.c @@ -612,10 +612,8 @@ static int nand_davinci_probe(struct platform_device *pdev) { struct davinci_nand_pdata *pdata; struct davinci_nand_info *info; - struct resource *res1; - struct resource *res2; + struct resource *res; void __iomem *vaddr; - void __iomem *base; int ret; uint32_t val; struct mtd_info *mtd; @@ -638,14 +636,8 @@ static int nand_davinci_probe(struct platform_device *pdev) platform_set_drvdata(pdev, info); - res1 = platform_get_resource(pdev, IORESOURCE_MEM, 0); - res2 = platform_get_resource(pdev, IORESOURCE_MEM, 1); - if (!res1 || !res2) { - dev_err(&pdev->dev, "resource missing\n"); - return -EINVAL; - } - - vaddr = devm_ioremap_resource(&pdev->dev, res1); + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + vaddr = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(vaddr)) return PTR_ERR(vaddr); @@ -655,14 +647,12 @@ static int nand_davinci_probe(struct platform_device *pdev) * by AEMIF, so we cannot request it twice, just ioremap. * The AEMIF and NAND drivers not use the same registers in this range. */ - base = devm_ioremap(&pdev->dev, res2->start, resource_size(res2)); - if (!base) { - dev_err(&pdev->dev, "ioremap failed for resource %pR\n", res2); - return -EADDRNOTAVAIL; - } + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); + info->base = devm_ioremap_shared_resource(&pdev->dev, res); + if (IS_ERR(info->base)) + return PTR_ERR(info->base); info->dev = &pdev->dev; - info->base = base; info->vaddr = vaddr; mtd = nand_to_mtd(&info->chip);