From patchwork Thu Oct 4 13:31:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda Delgado X-Patchwork-Id: 978907 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=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JjnICHZr"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Bs1dYuEw"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::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 42Qv2D1hWxz9s8J for ; Thu, 4 Oct 2018 23:32:20 +1000 (AEST) 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:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=wlyA5tjT+rUODPRAmPl8diqwQyVygXruRql3UGgRXQk=; b=JjnICHZr4eJ0Y3 RPf8SMXT+MsrHxvAgbI7EqgWnw6tIoC/sBUFKu4kEfi7F6z+AgiQPIcOju343juT2MgIabG498Tn1 zXBPH9gHbtvQTQPa+jwkL/4gevFp654sqOsqxo0iL1YEj/ayuSwSWg+KOk1KoEr/exE9e61NbH9FG QMvu5nGVJ60Av7sOmFqrj1y90xN9+9qBZq0KKgS4Lc+VxECGxQ1SZoQHApBr4rF7+UeEr0UQxDX7G Obnzn6NRTyi0qUkR/0oxK3MzFEboJ6MnKFu01rb9TAAKuInS01FhFCZwKhBmC8P1MvMCQwziIPisq zxV93ZjLL0/RJ+Js1ccQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g83jc-0007YA-LH; Thu, 04 Oct 2018 13:32:08 +0000 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g83jY-0007Wv-AS for linux-mtd@lists.infradead.org; Thu, 04 Oct 2018 13:32:05 +0000 Received: by mail-ed1-x541.google.com with SMTP id b7-v6so1982064edd.9 for ; Thu, 04 Oct 2018 06:31:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=raX5qEj7fRXQ/iQULa01jf7rlvPVsAVNG0zX/XpZs5g=; b=Bs1dYuEw88RWdvlU/QKrnpxanvvHnNSDQFMCUNnhGfgzRk38FPRYfrPXesa9G65Oje fwRe9wYuwkFuMHMbDQVywWy0puErljO1BsdC14RW/NNTvwxWb8BfhHufi/Mu1zGHoLYQ XshtXDFHCNh6FQG9vZr3wBdxltd7ojT5Unb5R+5qLKhZgvqIsFpGjlwdYbC2Eum7HiIH 8aXlt8Ar4pCksyzMcwMdxcBJw5zGPfWZuLsjLjKqhniXvfjB6uU2uOECG84l4wNSln0I lw/LGF0zTqdtpiC3FODvL+vXK4M03SA7WeNws9RfG/dbLQZ+f4+YXFBCEqvhAkU3mhjQ pOqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=raX5qEj7fRXQ/iQULa01jf7rlvPVsAVNG0zX/XpZs5g=; b=rwZ8W6jhiQ76mhHLxl5vwextGibizQriVlH696Q6aWor0r9jlzT7YiGRQWaLYa7rlb qJQ/bZlYows+wfEJdkeubo/MZnuKueiJpfVIbXCpAck6md88Gpw7Bwda1mqts53HohRg Vl6ekN1xm+pqwBqPgfzy3efGoxwa4MxBym/HGY2+u1a9Uk/DvSlUkUm+RdrSXy6CtXrF AyVR8j7z1wKPaJAGwsEUQnPw2pPC7XkShGLGpiWFaGneI2HSTaSY0dl8GFa944IYhanI r013MzTD0gIDmCSEHe4EN6UFJv/VY1g46kXV4C43XsxVMd/5W7ajC8nipYjeVi2ZbE4W 7ozw== X-Gm-Message-State: ABuFfoh+PZvY7BpET2kh0J8tnR4rVO/i080PkPmGDbSCwmqUgSeb0gFf civr0F4tbyb+I8Ywk0qf+ufFHF6U X-Google-Smtp-Source: ACcGV62M0y9IvVduVqMidTLJ3pwy/KabW35fThv4AnQreLY6qMvmNnSKU/FK3nSUQoaLDqFSS28euA== X-Received: by 2002:a50:8a96:: with SMTP id j22-v6mr8461277edj.189.1538659910169; Thu, 04 Oct 2018 06:31:50 -0700 (PDT) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by smtp.gmail.com with ESMTPSA id c24-v6sm1440569ede.73.2018.10.04.06.31.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Oct 2018 06:31:49 -0700 (PDT) From: Ricardo Ribalda Delgado To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Zhouyang Jia , linux-mtd@lists.infradead.org, open list Subject: [PATCH v8 01/10] mtd: physmap_of: Release resources on error Date: Thu, 4 Oct 2018 15:31:46 +0200 Message-Id: <20181004133147.20215-1-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181004_063204_391562_A7A9B432 X-CRM114-Status: GOOD ( 16.84 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:541 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (ricardo.ribalda[at]gmail.com) -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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: Ricardo Ribalda Delgado Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org During probe, if there was an error the memory region and the memory map were not properly released.This can lead a system unusable if deferred probe is in use. Replace mem_request and map with devm_ioremap_resource Signed-off-by: Ricardo Ribalda Delgado --- drivers/mtd/maps/physmap_of_core.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/drivers/mtd/maps/physmap_of_core.c b/drivers/mtd/maps/physmap_of_core.c index 4129535b8e46..ed75f1781c37 100644 --- a/drivers/mtd/maps/physmap_of_core.c +++ b/drivers/mtd/maps/physmap_of_core.c @@ -31,7 +31,6 @@ struct of_flash_list { struct mtd_info *mtd; struct map_info map; - struct resource *res; }; struct of_flash { @@ -56,18 +55,10 @@ static int of_flash_remove(struct platform_device *dev) mtd_concat_destroy(info->cmtd); } - for (i = 0; i < info->list_size; i++) { + for (i = 0; i < info->list_size; i++) if (info->list[i].mtd) map_destroy(info->list[i].mtd); - if (info->list[i].map.virt) - iounmap(info->list[i].map.virt); - - if (info->list[i].res) { - release_resource(info->list[i].res); - kfree(info->list[i].res); - } - } return 0; } @@ -215,10 +206,11 @@ static int of_flash_probe(struct platform_device *dev) err = -EBUSY; res_size = resource_size(&res); - info->list[i].res = request_mem_region(res.start, res_size, - dev_name(&dev->dev)); - if (!info->list[i].res) + info->list[i].map.virt = devm_ioremap_resource(&dev->dev, &res); + if (IS_ERR(info->list[i].map.virt)){ + err = PTR_ERR(info->list[i].map.virt); goto err_out; + } err = -ENXIO; width = of_get_property(dp, "bank-width", NULL); @@ -246,15 +238,6 @@ static int of_flash_probe(struct platform_device *dev) if (err) goto err_out; - err = -ENOMEM; - info->list[i].map.virt = ioremap(info->list[i].map.phys, - info->list[i].map.size); - if (!info->list[i].map.virt) { - dev_err(&dev->dev, "Failed to ioremap() flash" - " region\n"); - goto err_out; - } - simple_map_init(&info->list[i].map); /* From patchwork Thu Oct 4 13:31:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda Delgado X-Patchwork-Id: 978908 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=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="iQY1YdM7"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="d8njSbzr"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::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 42Qv2j0Gjdz9s5c for ; Thu, 4 Oct 2018 23:32:45 +1000 (AEST) 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Ah1o55YGdG1KKzZ6eONVOl8BjccCgbaFbbG82D9dhMs=; b=iQY1YdM7WAUNuv psADa1eMYbbTo9ILSddhYxl729WZonfzDsfML+PIirXpng0zsZTIaRahVUGbXP+Il0WHw5gXvBcGF aE1BnUjcfm/fWnfY3x1U/oqs0kh98wH4CBfxdIMQERw+YUHXfQf4TJSdaxOdkrLEy7woAkEJE8Lpi 4L2XmkeXNJZDqYp0xM6/FsB8j+ybvJTZtuiFHXcQp5KARRoCoy6lKN8rAcfc4s4ECRB9KJy/Vsr3T +EGzM43/pk/6sxxAmVHqbmSDGMyObiYTBjmH4IS26b4SRvpHN/i6j6j5O+dD++RYW6u6I4y8+/bVP X4bgX7XU8vlJOLiaysSA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g83k1-0007iw-Qq; Thu, 04 Oct 2018 13:32:33 +0000 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g83jY-0007X2-Nj for linux-mtd@lists.infradead.org; Thu, 04 Oct 2018 13:32:06 +0000 Received: by mail-ed1-x542.google.com with SMTP id y20-v6so1911680eds.10 for ; Thu, 04 Oct 2018 06:31:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a8OYuIeRLOZOD3gBj1yZgyUI95bCP9S/q/SYm0AS0PY=; b=d8njSbzrNWI3roEkUO3JmJwQZku+GRlGISvrqQCnrArvYNLsQUbFaUAr1eGIsGQclx SlycDqzCDIy9CaHxdUZoe+jDSKDKz6YWVRstEIiVd7E8HLLjUo42G6tiIaZYv8V3Kqry +CTBamV48cB8uWGYJ4oiX4KekQH6ndcBZ0VxYccOnaAbolyBGvE0Z5mEIhhXn2QpKMca XKI7YZpWAwOGZcimhIVT882K9wtCQeFQm8uVh6Ws4AHi/147TAALgbz9WrSsZytyWenV 0PzwsuRpTw1ekp3MkgkJ2GM5gW4w3V8ZGhmvteCR2MazKZbaYsJZRp3TDqI7CkU71ntS Diwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a8OYuIeRLOZOD3gBj1yZgyUI95bCP9S/q/SYm0AS0PY=; b=OErJfGrOc+YTmTgjUL7g0xIZsJR04/OzZ8kot/bvn7iq9RT1M4fe9gbGntUUEnoV/y q5x796dh+0w3KQgstzbLSk9bqrsfTNbm8lbZyuxoTJH3hSQlllrcMkZ8h26euvNLy8i8 1JpONvm8PE+qqPBr1ot9/2/KiFP3NU4HCQ++IMoEQee5KHEY51OvwGIznDutDGupPt7j ca95LesNvklxwaHetTeJTZyHdsCdkUJEix1zPIFIGrxRWMEUOW9f6XggSkiTuuG948XV 9qTO5342FduaWxFbFiryUG5jaCMorsEvRfwQC4Yb5BGrkeWEeh1LIThmd0j7shRDOM6V 3UvQ== X-Gm-Message-State: ABuFfohG92YwOz5EZ0rulDibqr5b6ND2EGNvajNczy5+LRom4OZw7M3V xI8KZiQca2blGiGgYJ31bhI= X-Google-Smtp-Source: ACcGV61Qcx1+iaHjiaXCHpbexxi/i9K6YrW53cEbPLFYIfH9ftP6OhBN+41PztgOvnvz/99nBFxFSw== X-Received: by 2002:a50:c94b:: with SMTP id p11-v6mr8456596edh.6.1538659912373; Thu, 04 Oct 2018 06:31:52 -0700 (PDT) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by smtp.gmail.com with ESMTPSA id c24-v6sm1440569ede.73.2018.10.04.06.31.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Oct 2018 06:31:50 -0700 (PDT) From: Ricardo Ribalda Delgado To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Zhouyang Jia , linux-mtd@lists.infradead.org, open list Subject: [PATCH v8 10/10] mtd: maps: gpio-addr-flash: Add support for device-tree devices Date: Thu, 4 Oct 2018 15:31:47 +0200 Message-Id: <20181004133147.20215-2-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181004133147.20215-1-ricardo.ribalda@gmail.com> References: <20181004133147.20215-1-ricardo.ribalda@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181004_063204_784355_6B457C31 X-CRM114-Status: GOOD ( 23.53 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:542 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (ricardo.ribalda[at]gmail.com) -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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: Ricardo Ribalda Delgado Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Allow creating gpio-addr-flash via device-tree and not just via platform data. Mimic what physmap_of_versatile and physmap_of_gemini does to reduce code duplicity. Signed-off-by: Ricardo Ribalda Delgado --- drivers/mtd/maps/Kconfig | 8 +++ drivers/mtd/maps/Makefile | 3 +- drivers/mtd/maps/gpio-addr-flash.c | 91 ++++++++++++++++++------------ drivers/mtd/maps/gpio-addr-flash.h | 31 ++++++++++ drivers/mtd/maps/physmap_of_core.c | 5 ++ drivers/mtd/maps/physmap_of_gpio.c | 24 ++++++++ 6 files changed, 125 insertions(+), 37 deletions(-) create mode 100644 drivers/mtd/maps/gpio-addr-flash.h create mode 100644 drivers/mtd/maps/physmap_of_gpio.c diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig index afb36bff13a7..427143d42168 100644 --- a/drivers/mtd/maps/Kconfig +++ b/drivers/mtd/maps/Kconfig @@ -94,6 +94,14 @@ config MTD_PHYSMAP_OF_GEMINI platforms, some detection and setting up parallel mode on the external interface. +config MTD_PHYSMAP_OF_GPIO + bool "GPIO-assisted OF-based physical memory map handling" + depends on MTD_PHYSMAP_OF + depends on MTD_GPIO_ADDR + help + This provides some extra DT physmap parsing for flashes that are + partially physically addressed and assisted by GPIOs. + config MTD_PMC_MSP_EVM tristate "CFI Flash device mapped on PMC-Sierra MSP" depends on PMC_MSP && MTD_CFI diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile index 51acf1fec19b..c232ccf05bee 100644 --- a/drivers/mtd/maps/Makefile +++ b/drivers/mtd/maps/Makefile @@ -21,6 +21,7 @@ obj-$(CONFIG_MTD_PHYSMAP) += physmap.o physmap_of-objs-y += physmap_of_core.o physmap_of-objs-$(CONFIG_MTD_PHYSMAP_OF_VERSATILE) += physmap_of_versatile.o physmap_of-objs-$(CONFIG_MTD_PHYSMAP_OF_GEMINI) += physmap_of_gemini.o +physmap_of-objs-$(CONFIG_MTD_PHYSMAP_OF_GPIO) += physmap_of_gpio.o physmap_of-objs := $(physmap_of-objs-y) obj-$(CONFIG_MTD_PHYSMAP_OF) += physmap_of.o obj-$(CONFIG_MTD_PISMO) += pismo.o @@ -44,6 +45,6 @@ obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o obj-$(CONFIG_MTD_INTEL_VR_NOR) += intel_vr_nor.o obj-$(CONFIG_MTD_RBTX4939) += rbtx4939-flash.o obj-$(CONFIG_MTD_VMU) += vmu-flash.o -obj-$(CONFIG_MTD_GPIO_ADDR) += gpio-addr-flash.o +obj-$(CONFIG_MTD_GPIO_ADDR) += gpio-addr-flash.o obj-$(CONFIG_MTD_LATCH_ADDR) += latch-addr-flash.o obj-$(CONFIG_MTD_LANTIQ) += lantiq-flash.o diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c index a20e85aa770e..7837fc7b8de8 100644 --- a/drivers/mtd/maps/gpio-addr-flash.c +++ b/drivers/mtd/maps/gpio-addr-flash.c @@ -25,25 +25,25 @@ #include #include #include +#include "gpio-addr-flash.h" #define win_mask(x) ((BIT(x)) - 1) #define DRIVER_NAME "gpio-addr-flash" +#define gf_map_info_to_state(mi) ((struct async_state *)(mi)->map_priv_1) + /** - * struct async_state - keep GPIO flash state + * struct async_state_pdev - Async state platform device * @mtd: MTD state for this mapping * @map: MTD map state for this flash * @gpios: Struct containing the array of GPIO descriptors - * @gpio_values: cached GPIO values - * @win_order: dedicated memory size (if no GPIOs) + * @state: GPIO flash state */ -struct async_state { +struct async_state_pdev { struct mtd_info *mtd; struct map_info map; - struct gpio_descs *gpios; - unsigned int gpio_values; - unsigned int win_order; + struct async_state state; }; #define gf_map_info_to_state(mi) ((struct async_state *)(mi)->map_priv_1) @@ -174,6 +174,31 @@ static void gf_copy_to(struct map_info *map, unsigned long to, static const char * const part_probe_types[] = { "cmdlinepart", "RedBoot", NULL }; +int gpio_flash_probe_common(struct device *dev, struct async_state *state, + struct map_info *map) +{ + if (!is_power_of_2(map->size)) { + dev_err(dev, "Window size must be aligned\n"); + return -EIO; + } + + state->gpios = devm_gpiod_get_array(dev, "addr", GPIOD_OUT_LOW); + if (IS_ERR(state->gpios)) + return PTR_ERR(state->gpios); + + state->win_order = get_bitmask_order(map->size) - 1; + map->read = gf_read; + map->copy_from = gf_copy_from; + map->write = gf_write; + map->copy_to = gf_copy_to; + map->size = BIT(state->win_order + state->gpios->ndescs); + map->phys = NO_XIP; + map->map_priv_1 = (unsigned long)state; + + return 0; +} +EXPORT_SYMBOL(gpio_flash_probe_common); + /** * gpio_flash_probe() - setup a mapping for a GPIO assisted flash * @pdev: platform device @@ -210,7 +235,8 @@ static int gpio_flash_probe(struct platform_device *pdev) { struct physmap_flash_data *pdata; struct resource *memory; - struct async_state *state; + struct async_state_pdev *state_pdev; + int ret; pdata = dev_get_platdata(&pdev->dev); memory = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -218,40 +244,33 @@ static int gpio_flash_probe(struct platform_device *pdev) if (!memory) return -EINVAL; - state = devm_kzalloc(&pdev->dev, sizeof(*state), GFP_KERNEL); - if (!state) + state_pdev = devm_kzalloc(&pdev->dev, sizeof(*state_pdev), GFP_KERNEL); + if (!state_pdev) return -ENOMEM; - state->gpios = devm_gpiod_get_array(&pdev->dev, "addr", GPIOD_OUT_LOW); - if (IS_ERR(state->gpios)) - return PTR_ERR(state->gpios); - - state->win_order = get_bitmask_order(resource_size(memory)) - 1; + state_pdev->map.virt = devm_ioremap_resource(&pdev->dev, memory); + if (IS_ERR(state_pdev->map.virt)) + return PTR_ERR(state_pdev->map.virt); - state->map.name = DRIVER_NAME; - state->map.read = gf_read; - state->map.copy_from = gf_copy_from; - state->map.write = gf_write; - state->map.copy_to = gf_copy_to; - state->map.bankwidth = pdata->width; - state->map.size = BIT(state->win_order + state->gpios->ndescs); - state->map.virt = devm_ioremap_resource(&pdev->dev, memory); - if (IS_ERR(state->map.virt)) - return PTR_ERR(state->map.virt); + state_pdev->map.name = DRIVER_NAME; + state_pdev->map.bankwidth = pdata->width; + state_pdev->map.size = resource_size(memory); - state->map.phys = NO_XIP; - state->map.map_priv_1 = (unsigned long)state; + ret = gpio_flash_probe_common(&pdev->dev, &state_pdev->state, + &state_pdev->map); + if (ret) + return ret; - platform_set_drvdata(pdev, state); + platform_set_drvdata(pdev, state_pdev); dev_notice(&pdev->dev, "probing %d-bit flash bus\n", - state->map.bankwidth * 8); - state->mtd = do_map_probe(memory->name, &state->map); - if (!state->mtd) + state_pdev->map.bankwidth * 8); + state_pdev->mtd = do_map_probe(memory->name, &state_pdev->map); + if (!state_pdev->mtd) return -ENXIO; - state->mtd->dev.parent = &pdev->dev; + state_pdev->mtd->dev.parent = &pdev->dev; - mtd_device_parse_register(state->mtd, part_probe_types, NULL, + mtd_device_parse_register(state_pdev->mtd, part_probe_types, NULL, pdata->parts, pdata->nr_parts); return 0; @@ -259,10 +278,10 @@ static int gpio_flash_probe(struct platform_device *pdev) static int gpio_flash_remove(struct platform_device *pdev) { - struct async_state *state = platform_get_drvdata(pdev); + struct async_state_pdev *state_pdev = platform_get_drvdata(pdev); - mtd_device_unregister(state->mtd); - map_destroy(state->mtd); + mtd_device_unregister(state_pdev->mtd); + map_destroy(state_pdev->mtd); return 0; } diff --git a/drivers/mtd/maps/gpio-addr-flash.h b/drivers/mtd/maps/gpio-addr-flash.h new file mode 100644 index 000000000000..46d97a8031eb --- /dev/null +++ b/drivers/mtd/maps/gpio-addr-flash.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include +#include + +/** + * struct async_state - keep GPIO flash state + * @gpios: Struct containing the array of GPIO descriptors + * @gpio_values: cached GPIO values + * @win_order: dedicated memory size (if no GPIOs) + */ +struct async_state { + struct gpio_descs *gpios; + unsigned int gpio_values; + unsigned int win_order; +}; + +int gpio_flash_probe_common(struct device *dev, + struct async_state *state, + struct map_info *map); + +#ifdef CONFIG_MTD_PHYSMAP_OF_GPIO +int of_flash_probe_gpio(struct platform_device *pdev, struct device_node *np, + struct map_info *map); +#else +static inline +int of_flash_probe_gpio(struct platform_device *pdev, struct device_node *np, + struct map_info *map) +{ + return 0; +} +#endif diff --git a/drivers/mtd/maps/physmap_of_core.c b/drivers/mtd/maps/physmap_of_core.c index ed75f1781c37..1e9f2d6f77c3 100644 --- a/drivers/mtd/maps/physmap_of_core.c +++ b/drivers/mtd/maps/physmap_of_core.c @@ -27,6 +27,7 @@ #include #include "physmap_of_gemini.h" #include "physmap_of_versatile.h" +#include "gpio-addr-flash.h" struct of_flash_list { struct mtd_info *mtd; @@ -240,6 +241,10 @@ static int of_flash_probe(struct platform_device *dev) simple_map_init(&info->list[i].map); + err = of_flash_probe_gpio(dev, dp, &info->list[i].map); + if (err) + goto err_out; + /* * On some platforms (e.g. MPC5200) a direct 1:1 mapping * may cause problems with JFFS2 usage, as the local bus (LPB) diff --git a/drivers/mtd/maps/physmap_of_gpio.c b/drivers/mtd/maps/physmap_of_gpio.c new file mode 100644 index 000000000000..97e02737ed67 --- /dev/null +++ b/drivers/mtd/maps/physmap_of_gpio.c @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2018 Qtechnology A/S + * + * Ricardo Ribalda + * + */ +#include +#include "gpio-addr-flash.h" + +int of_flash_probe_gpio(struct platform_device *pdev, struct device_node *np, + struct map_info *map) +{ + struct async_state *state; + + if (!of_device_is_compatible(np, "mtd,gpio-addr-flash")) + return 0; + + state = devm_kzalloc(&pdev->dev, sizeof(*state), GFP_KERNEL); + if (!state) + return -ENOMEM; + + return gpio_flash_probe_common(&pdev->dev, state, map); +}