From patchwork Thu Oct 4 14:29:41 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: 978960 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="gzxITS4v"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="rbtwD4IB"; 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 42QwJy506Wz9s7W for ; Fri, 5 Oct 2018 00:30:10 +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=VmykvR/op9N511HJ9d6xRyLAQIKzIhLVxVHVuhumZ0Y=; b=gzxITS4vpTeflg 2TLJmRLm61QGupJu7TQkoSL/QYgb5SacyqwGFE7IT9DjdlvKUAJj5ZUUELsC0CBeUSkokWkLCxTUY MKKl+kk7XQcwX6DvF68GeQ+NwmN8mOTVu9wpXMsXi1ETxa30YHV1Svb38n3qCN9xnENtr+65auGPF gCoi4e61yBaJZ6unbXWB1qDEJbn4/PnYxSUzeJwUEthUoVhr85JLyiN266mX8C2UtnRvKMvie4wH9 jndGy7kwr6yGpB0IkLqijhqSQM7nO8hnZ+GY4/wdxiDsqjVxjYV9u04rh7helaNxN0QZO0QPzwhAu wFP0B1CsGsDIlT+aKHTQ==; 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 1g84dd-000799-28; Thu, 04 Oct 2018 14:30:01 +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 1g84dZ-000785-73 for linux-mtd@lists.infradead.org; Thu, 04 Oct 2018 14:29:58 +0000 Received: by mail-ed1-x542.google.com with SMTP id f38-v6so8742006edd.8 for ; Thu, 04 Oct 2018 07:29:46 -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=RlGjeXvjSkgA9ZE6YC/H1m5aigBd7dElYUI6fpZSv/8=; b=rbtwD4IBzCggWgsSr3+/FDqo1Bc2X2gVB/N+PSogg/hjrWNlZrYeznab0lS2YHhELz WUpv3c/i8ndzSoCGzaOh8PzL5wdAlnIsuXlvlKyhwJ32dtzAI5BS/OL9vdFQxIsY27Cf lLAltxre+aSH3+36AO5SF/upSC0AjViIKukKVlTt40Oxg8rKjjl9fHcYT02rxmuKub3N Z1ZySNUHLF+9auNHUz6qXTayqId/hb5XtvWJzV2POK+GR3YDByAUyZ2DXxP63JQH40Qv WBpep2S1UAz9RtGW1SE4pERXINMPlmTiU+c/EelV8t+O2m+m5GiwHAOFf22ZubfxI0SD e3vQ== 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=RlGjeXvjSkgA9ZE6YC/H1m5aigBd7dElYUI6fpZSv/8=; b=c4PLfMois8WlbWy9qU+UP28dUixpnkHO5nA410lJEOfVPsCJfGQbuCu6SRKkwapLom 0Xc4IrUyE28GwTJduz6lIqnFtiiiqF7bM96rjX6ZXU5LY5QqL5Zz2mCoeoJL2mgVlIj1 MWaz1Ypq7fSt0lnENi6uX139pvk0zejtybGbX2zIfe7LWJQjAXiVwvtbcFquZl7udHBz xY1nsGyOti3YNkPonf4cMVNgTV1y6GcG4EDQFvBPnlEfVcGSpcQkNDrCJRBrtXNLqDTC ykA7RSAHCULyvm/ZJcDOVslXkRM6p/kMdhmH4qxLsl9xqgJyohn+sk8+aklnMISsU5ip S6qA== X-Gm-Message-State: ABuFfogUdFaPapWbxdfn4kR7DoASiNZEytSRz60PWz2M4MWI/GXVDvmZ Yu0xcmEuf+jFmoDeTll1kX4= X-Google-Smtp-Source: ACcGV63ScYQDLmo5mhPN58Q0WiSThhY7s8ka1mDaedQl3d8tXHrBYYOqR4DMWz4s5gYLlZXt/cqdGQ== X-Received: by 2002:aa7:c60d:: with SMTP id h13-v6mr3853914edq.9.1538663385535; Thu, 04 Oct 2018 07:29:45 -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 j15-v6sm892228ejy.3.2018.10.04.07.29.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Oct 2018 07:29:43 -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 v10 09/10] dt-binding: mtd: Document gpio-addr-flash Date: Thu, 4 Oct 2018 16:29:41 +0200 Message-Id: <20181004142942.11887-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_072957_283113_7EBCF2BC X-CRM114-Status: GOOD ( 12.78 ) 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 , devicetree@vger.kernel.org Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add documentation for gpio-addr-flash. This binding allow creating flash devices that are paged using GPIOs. Cc: devicetree@vger.kernel.org Reviewed-by: Rob Herring Signed-off-by: Ricardo Ribalda Delgado --- Documentation/devicetree/bindings/mtd/mtd-physmap.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/mtd/mtd-physmap.txt b/Documentation/devicetree/bindings/mtd/mtd-physmap.txt index 232fa12e90ef..7df0dcaccb7d 100644 --- a/Documentation/devicetree/bindings/mtd/mtd-physmap.txt +++ b/Documentation/devicetree/bindings/mtd/mtd-physmap.txt @@ -29,6 +29,8 @@ file systems on embedded devices. - use-advanced-sector-protection: boolean to enable support for the advanced sector protection (Spansion: PPB - Persistent Protection Bits) locking. + - addr-gpios : (optional) List of GPIO descriptors that will be used to + address the MSBs address lines. The order goes from LSB to MSB. For JEDEC compatible devices, the following additional properties are defined: From patchwork Thu Oct 4 14:29:42 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: 978961 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="sSBnQ83L"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="exxcIjED"; 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 42QwKZ1rP6z9s9J for ; Fri, 5 Oct 2018 00:30:42 +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=n8GMaEmUe+IcNBVM2scMCQQ61v6+pTWns1vEqfMNSA8=; b=sSBnQ83LIOFopM STMWd1Q697gsjhyfgoplvjeYRIzwlICL/DNrd5LqZYQsqMBaLD2U/vJ1xE7QgG0CO6sqJrJMV6KG6 DKdVJBZtGB95CrEjR1eG3/sW0p13BNp/298GnEa2fpj2W7Rc+oMXsVpSuh57adiXkOGB6hMRFGVNR KDrdWGLUJsaXrXXHpM6VH4cUNj0xrd0W9ajNsIzLokX3vHS1pTqCFHfAjDXJ+Qf572V/T0Y1RUGju uHM46YvK7YfxDqJ5GJiXqs9hDWFqgKEbdbmqVye/pnNa89p6lIBoLKbFUS8M4r07xgBOfCOhM7zkF XWV6jTpFqHEvTCfR2/cQ==; 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 1g84e9-00008m-Pq; Thu, 04 Oct 2018 14:30:33 +0000 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g84db-00078C-E8 for linux-mtd@lists.infradead.org; Thu, 04 Oct 2018 14:30:01 +0000 Received: by mail-ed1-x543.google.com with SMTP id c1-v6so8744184ede.5 for ; Thu, 04 Oct 2018 07:29:49 -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=/yIQe6URbLgBIjwymEFKnL7tXSDi9bh6QvjjpT+YqZ4=; b=exxcIjEDl1+NKNDhtbGIxUEEMQp2Uo7YjZXJe/vtMYg4N7Gr8QwHLG2lqB/j0vVvre Yvg6cN12tAsJ0CPoaYt/arLZlbRboIP6qabddjht1BjBrRiFW2OwthNfuwaZoc8pJpKY WDRKAkKUN6fNHFF90R3a7cwX//lsSrtas/akA5yEfuWXrlDaJYAxwubPDgo0yaRYLwYu KW2+6mMlHnP+mYekMy6AMCUb39nwE3LLFE2uGBljmns2Bz1OK748D3fd5EZp+gmAIXnw QhJdSFanhtPWpTOsa/icm2GjwgUFVsMtyP0V7OJSQ5rhzVC4pYqK6R4UsyQccgke2epI LiXw== 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=/yIQe6URbLgBIjwymEFKnL7tXSDi9bh6QvjjpT+YqZ4=; b=rLe5ULKV8Ln0ca5bt6jyZR00J1nrs9aSJpM/BlGkeor3TXDrGj+ZCDxlmBsUzPJetJ h1c4uIdVtExdaT1RwqXwQwKoPeiDW/BflAe5vaRdEkgyY1MoZQb5BHrOKl5U3LdMySqU fSw8W39SvDcZSa4fbCBRryB9FcDD/diNxNYMS8jRy9kajiqa0x7ZgT9gcH/C7IczXtTN Qkm4QG9MALYjBemue60vUvW0IltMooBsMmGscl2xu5YUJ2RpIYkQEXUDgc8DxYbTYNHk VXXcuEZM6vESJjbv2ktHbwTiz15/7FS3KsivU2WgqMXeAhek1+OBdbT5dJEKbvk09/+o 6vtQ== X-Gm-Message-State: ABuFfojrKwr8HByhWDvFvdV76nhl11It0eD6+LvLlNZHSNwO+v7Y6+y6 BYDytRlp7nuyxi8hsfdSw1o= X-Google-Smtp-Source: ACcGV61nFiwJ4yUr7AGd3jaRaNl1BF17tPJh+GV5/EHqbbWLCOUDvsufRNJZm6gLllMGsZu4k/omSQ== X-Received: by 2002:a17:906:446:: with SMTP id e6-v6mr6876286eja.167.1538663387555; Thu, 04 Oct 2018 07:29:47 -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 j15-v6sm892228ejy.3.2018.10.04.07.29.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Oct 2018 07:29:46 -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 v10 10/10] mtd: maps: gpio-addr-flash: Add support for device-tree devices Date: Thu, 4 Oct 2018 16:29:42 +0200 Message-Id: <20181004142942.11887-2-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181004142942.11887-1-ricardo.ribalda@gmail.com> References: <20181004142942.11887-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_072959_476235_41800CF6 X-CRM114-Status: GOOD ( 23.22 ) 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:543 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 | 95 +++++++++++++++++++----------- drivers/mtd/maps/gpio-addr-flash.h | 34 +++++++++++ drivers/mtd/maps/physmap_of_core.c | 5 ++ drivers/mtd/maps/physmap_of_gpio.c | 21 +++++++ 6 files changed, 129 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..0d1f66aedf77 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,35 @@ 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_optional(dev, "addr", + GPIOD_OUT_LOW); + if (!state->gpios) + return 0; + + 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 +239,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 +248,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 +282,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..443577f7fdfd --- /dev/null +++ b/drivers/mtd/maps/gpio-addr-flash.h @@ -0,0 +1,34 @@ +/* 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) +{ + if (of_find_property(np, "addr-gpios", NULL)) + return -EINVAL; + + return 0; +} +#endif diff --git a/drivers/mtd/maps/physmap_of_core.c b/drivers/mtd/maps/physmap_of_core.c index ece605d78c21..c187b6ff873d 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..c84c5e96e592 --- /dev/null +++ b/drivers/mtd/maps/physmap_of_gpio.c @@ -0,0 +1,21 @@ +// 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; + + state = devm_kzalloc(&pdev->dev, sizeof(*state), GFP_KERNEL); + if (!state) + return -ENOMEM; + + return gpio_flash_probe_common(&pdev->dev, state, map); +}