From patchwork Wed Jan 29 20:37:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 1231104 X-Patchwork-Delegate: vigneshr@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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=none (p=none dis=none) header.from=cogentembedded.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=i6LnqtX3; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=cogentembedded-com.20150623.gappssmtp.com header.i=@cogentembedded-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=USIxJxVF; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 487Ffs3zgYz9sPJ for ; Thu, 30 Jan 2020 07:37:57 +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:Date: Message-ID:References:To:From:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OS0Vf/PVHYokZgPBsHCk2kJTTi/x+TZIT5usoZu9DCE=; b=i6LnqtX3KgD+3O JXkPkMJ5tioP2ZB5UHT7qW3xXMHXePIa1K8L4S65QRXjmjiempNCG4lml9hX+WzXwVM+sm9x/kQYV 3fRYiOhBZX3WQMZIa1+Y9T3YD5+99D928VoL8OaOYGwOQn0R4rpnTcdPvw+RhnQWThEejvMPQsaAs ZFmtP2sA8iSPLfec2QzClr/ZsWklhoi80TNaBaJ7IZJpYXzSURNRs5alsVItJ5oHkr8hPdgnur4d0 Jkyk1r2+H0/l+zieMx1CWbmfLA25lheHy9ZHwkpb5oSm25DAuO9fc/5hS5RDMx0WwY+fT7ie126rT 6QSU5MhwtX4U7hS/QiBg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iwu5o-0003Ar-54; Wed, 29 Jan 2020 20:37:44 +0000 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iwu5l-0003AR-CK for linux-mtd@lists.infradead.org; Wed, 29 Jan 2020 20:37:42 +0000 Received: by mail-lj1-x242.google.com with SMTP id w1so857100ljh.5 for ; Wed, 29 Jan 2020 12:37:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cogentembedded-com.20150623.gappssmtp.com; s=20150623; h=subject:from:to:cc:references:organization:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=m3RECKwntzDqTHrGIrCHwsGgp0L7QbNk7gHMMiY5RtE=; b=USIxJxVFKX1+ZpD0oTocIrWB1W76/DCKGYPtm/KvxdnKauUCuf0L4+ySKsg5ATjF2W w+5U23tUVcjiMu7UKeYfOvqc3a2u50xQBIH+I7iVtOybL4ZsvlKIBZDvbyP8pmwACwPZ WCoSiZXC1kBbTdTTrPuEftphbN1tD9m4rb2ZlCxOpJLzKVESqT7A3Il1/RXSmlOB3qn7 Egw6ODW03HbEEAJXZUj1YSGiHtnvn9wdDJvGEqA0cV73km3VNIZq7OZLGD6JT9qbrFTb wyj8Jw3PITwoHqUPQ/orU4Mqo3SIYyVW4rqAm8xjk+sp/QGYCj6c/Zmn2rrWhhajsSnr +aCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=m3RECKwntzDqTHrGIrCHwsGgp0L7QbNk7gHMMiY5RtE=; b=CGPCGoGAbHcHAE73K+B3vxtX3Dk/a5OOmxOnSCvRBEgmpGnSM/WLWfZb68m8WKDXoP ip6cpTq8rYzmocysRecEPcRygzzwcjnOVYDFEjJRDFALa5RiPqx8eSL9C6Ldls78WDyM z7SWDcbvjpdn7s1xloD7QsoBITSNueefeSjVIG2E8WElNgfdL4YksB1MXZNHbUGTDhEV r9lLEC3lFRd9HMyKSIgp3m82dqiIQYbahYJW8Q2dXlKFS9pN0nRInR65r90TfUXjqK8Q m+H4wccdl+fWLEpQ3i+zFpD7S9nYKLhpMu38b91LV5+WvnriSCchwQlyaSXsBBtgsB5B cpGg== X-Gm-Message-State: APjAAAVArabMe3NWcxqUuxAmC0gDT1O97sJwagTH94aPsqSP8m8Jr643 aNtxnv/H7MYhzRJqPAs4u5jxuw== X-Google-Smtp-Source: APXvYqwhORU76VvjLUC+yTOz8SGQVtxKNIOYoGaI62yNo4K+SfZx0OZ3R0qCdjMP+K9UczsMt8wvYw== X-Received: by 2002:a2e:6815:: with SMTP id c21mr555951lja.10.1580330259633; Wed, 29 Jan 2020 12:37:39 -0800 (PST) Received: from wasted.cogentembedded.com ([2a00:1fa0:2b4:78de:120:879a:3c09:8a9d]) by smtp.gmail.com with ESMTPSA id g25sm1532600ljn.107.2020.01.29.12.37.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jan 2020 12:37:38 -0800 (PST) Subject: [PATCH RFT 1/2] mtd: hyperbus: move direct mapping setup to AM654 HBMC driver From: Sergei Shtylyov To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org References: Organization: Cogent Embedded Message-ID: <114b97fe-c800-7ff7-ce6a-b38085f44adc@cogentembedded.com> Date: Wed, 29 Jan 2020 23:37:37 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-MW X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200129_123741_421672_1076B447 X-CRM114-Status: GOOD ( 16.64 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:242 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dirk Behme Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The Hyperbus core expects that HyperFlash is always directly mapped for both read and write, but in reality this may not always be the case, e.g. Renesas RPC-IF has read only direct mapping. Move the code setting up the direct mapping from the Hyperbus core to thh TI AM554 HBMC driver. Signed-off-by: Sergei Shtylyov --- drivers/mtd/hyperbus/hbmc-am654.c | 12 ++++++++++++ drivers/mtd/hyperbus/hyperbus-core.c | 11 ----------- 2 files changed, 12 insertions(+), 11 deletions(-) Index: linux/drivers/mtd/hyperbus/hbmc-am654.c =================================================================== --- linux.orig/drivers/mtd/hyperbus/hbmc-am654.c +++ linux/drivers/mtd/hyperbus/hbmc-am654.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -57,8 +58,10 @@ static const struct hyperbus_ops am654_h static int am654_hbmc_probe(struct platform_device *pdev) { + struct device_node *np = pdev->dev.of_node; struct device *dev = &pdev->dev; struct am654_hbmc_priv *priv; + struct resource res; int ret; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); @@ -67,6 +70,10 @@ static int am654_hbmc_probe(struct platf platform_set_drvdata(pdev, priv); + ret = of_address_to_resource(np, 0, &res); + if (ret) + return ret; + if (of_property_read_bool(dev->of_node, "mux-controls")) { struct mux_control *control = devm_mux_control_get(dev, NULL); @@ -88,6 +95,11 @@ static int am654_hbmc_probe(struct platf goto disable_pm; } + priv->hbdev.map.size = resource_size(&res); + priv->hbdev.map.virt = devm_ioremap_resource(dev, &res); + if (IS_ERR(priv->hbdev.map.virt)) + return PTR_ERR(priv->hbdev.map.virt); + priv->ctlr.dev = dev; priv->ctlr.ops = &am654_hbmc_ops; priv->hbdev.ctlr = &priv->ctlr; Index: linux/drivers/mtd/hyperbus/hyperbus-core.c =================================================================== --- linux.orig/drivers/mtd/hyperbus/hyperbus-core.c +++ linux/drivers/mtd/hyperbus/hyperbus-core.c @@ -10,7 +10,6 @@ #include #include #include -#include #include static struct hyperbus_device *map_to_hbdev(struct map_info *map) @@ -62,7 +61,6 @@ int hyperbus_register_device(struct hype struct hyperbus_ctlr *ctlr; struct device_node *np; struct map_info *map; - struct resource res; struct device *dev; int ret; @@ -78,17 +76,8 @@ int hyperbus_register_device(struct hype hbdev->memtype = HYPERFLASH; - ret = of_address_to_resource(np, 0, &res); - if (ret) - return ret; - dev = ctlr->dev; map = &hbdev->map; - map->size = resource_size(&res); - map->virt = devm_ioremap_resource(dev, &res); - if (IS_ERR(map->virt)) - return PTR_ERR(map->virt); - map->name = dev_name(dev); map->bankwidth = 2; map->device_node = np; From patchwork Wed Jan 29 20:39:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 1231105 X-Patchwork-Delegate: vigneshr@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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=none (p=none dis=none) header.from=cogentembedded.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=PveessG5; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=cogentembedded-com.20150623.gappssmtp.com header.i=@cogentembedded-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=vVgIh4n/; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 487Fj95nHlz9sP6 for ; Thu, 30 Jan 2020 07:39:57 +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:Date: Message-ID:References:To:From:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yIxn8ES4NZtZZhAHU+SSAXuwy+DhVa92PlI0qxOjOxA=; b=PveessG5Ff6pIB 8Zw68PtyBFK0RhNtQFJ1a0ttAK/kyxKzMG7vuOdy8HLTwaH5vvJMfMoSSKRaLrJgmnpl2V7XI5Wh9 yzzJb0mnKXc7CGUDfc+tvEFZX1gYY9fZ6WtJpH9/X2n1k89eTsJylbZyA5Snt0Z7Oe+unmz6430kh nntr4dy8msu0xZHl57p1a0149wU8yKbrl18AkyOfb9KPNDuWLdbIjpc4yJI18FDmp3fiZE8nUHYgc XgpYCfkdhmNAzPWr0yse8n6t6uxBZatDS58F6NzXkZLo5sTSwmG+gbiFguqw0nAPTtyAvNWDKrk8M xvP43edW2+1e0tol1zsA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iwu7h-0003YL-Bf; Wed, 29 Jan 2020 20:39:41 +0000 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iwu7d-0003Xz-MD for linux-mtd@lists.infradead.org; Wed, 29 Jan 2020 20:39:39 +0000 Received: by mail-lj1-x242.google.com with SMTP id r19so877841ljg.3 for ; Wed, 29 Jan 2020 12:39:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cogentembedded-com.20150623.gappssmtp.com; s=20150623; h=subject:from:to:cc:references:organization:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=b1bHGYLQ5gQ/6Ai3tYNgg10rSzDIsVzfhquqU/7j8dU=; b=vVgIh4n/ejzGxghYm5oyCd7PXsaKxOwMiOrFWJ85jpfFD3XThy5pRRU83h5M+7fR3d uqDZ//26X7eRan8Rq7z/dl/l6CDqndBsKWGahTJd2hDY4nGzJxd3PifgLE69sFRrKEAd pot/cIdCnPvGaHz0HozU9x71Ud9TWZjWo8HRtT6MwT7g9aR9BxkcFfIIU0CIc7LocMoH zjNq3CicX5B2xkj+gcFp/CfvFRgKdD9bRABZZHy8Cn1QQXgELA+iO0386sst7UgxJRNc GeZXxffFoRSUesrKaMcFLWz/LZRgYuqz4wwkW9dkoEm+qvSM5y/2IYwCdQrdX/DB88Ko E8EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=b1bHGYLQ5gQ/6Ai3tYNgg10rSzDIsVzfhquqU/7j8dU=; b=RiONrcLDY1LHUpLhGN5PQE/MzHPaBcB4tmGQHLvVP5ULjY405JCke1l/skVGQ3KCyt KO/qWNfv3hrfbh+TUUyNGVyUMFk6Y06NBHcgJMdqCeykirqAsmkulgjlmaOXuVYQYJZh FxfR0xp9Cx11IJvK8FpdFfWk/xfg+AFKjjd2aiDbbyLvNQ3dEfRqm8d+bvYC0yh5KYJ9 4V/DWVxQj4edOCGF2myqrBP9VoeHCklivE5CC+Lg6Ye4vqU+fOGS4qXi3sDCwQMS6PeJ xzcO6qg+qn/TBeGJvX4qiWeyryBKRu/A9jGZ0/UpfFDOCoD6xU5Y6XzPUCYZXCSANA9y 6ZLw== X-Gm-Message-State: APjAAAW6oACq1jCvjaUqd6IOzORyRyleqrxCxKK4JQsSbbFdiIiTZo/V tUscC2DQCAe4BmhEnQQZ7AcuxQ== X-Google-Smtp-Source: APXvYqyNseBgiWRvfOPgTWlJeKdB7smcVIA1H38J6pD0sReFqkOH/JuOGc+aD1Y2eE9RUc/ArMl3Hw== X-Received: by 2002:a2e:b6ce:: with SMTP id m14mr541332ljo.99.1580330376034; Wed, 29 Jan 2020 12:39:36 -0800 (PST) Received: from wasted.cogentembedded.com ([2a00:1fa0:2b4:78de:120:879a:3c09:8a9d]) by smtp.gmail.com with ESMTPSA id u16sm1530062ljo.22.2020.01.29.12.39.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jan 2020 12:39:35 -0800 (PST) Subject: [PATCH RFT 0/2/2] mtd: hyperbus: add Renesas RPC-IF driver From: Sergei Shtylyov To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org References: Organization: Cogent Embedded Message-ID: Date: Wed, 29 Jan 2020 23:39:34 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-MW X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200129_123937_790222_D85A8851 X-CRM114-Status: GOOD ( 16.27 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:242 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dirk Behme Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add the HyperFLash driver for the Renesas RPC-IF. It's the "front end" driver using the "back end" APIs in the main driver to talk to the real hardware. Signed-off-by: Sergei Shtylyov Signed-off-by: Dirk Behme --- drivers/mtd/hyperbus/Kconfig | 6 + drivers/mtd/hyperbus/Makefile | 1 drivers/mtd/hyperbus/rpc-if.c | 162 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+) Index: linux/drivers/mtd/hyperbus/Kconfig =================================================================== --- linux.orig/drivers/mtd/hyperbus/Kconfig +++ linux/drivers/mtd/hyperbus/Kconfig @@ -22,4 +22,10 @@ config HBMC_AM654 This is the driver for HyperBus controller on TI's AM65x and other SoCs +config RPCIF_HYPERBUS + tristate "Renesas RPC-IF HyperBus driver" + depends on RENESAS_RPCIF + help + This option includes Renesas RPC-IF HyperFlash support. + endif # MTD_HYPERBUS Index: linux/drivers/mtd/hyperbus/Makefile =================================================================== --- linux.orig/drivers/mtd/hyperbus/Makefile +++ linux/drivers/mtd/hyperbus/Makefile @@ -2,3 +2,4 @@ obj-$(CONFIG_MTD_HYPERBUS) += hyperbus-core.o obj-$(CONFIG_HBMC_AM654) += hbmc-am654.o +obj-$(CONFIG_RPCIF_HYPERBUS) += rpc-if.o Index: linux/drivers/mtd/hyperbus/rpc-if.c =================================================================== --- /dev/null +++ linux/drivers/mtd/hyperbus/rpc-if.c @@ -0,0 +1,162 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Linux driver for RPC-IF HyperFlash + * + * Copyright (C) 2019 Cogent Embedded, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +struct rpcif_hyperbus { + struct rpcif rpc; + struct hyperbus_ctlr ctlr; + struct hyperbus_device hbdev; +}; + +static const struct rpcif_op rpcif_op_tmpl = { + .cmd = { + .buswidth = 8, + .ddr = true, + }, + .ocmd = { + .buswidth = 8, + .ddr = true, + }, + .addr = { + .nbytes = 1, + .buswidth = 8, + .ddr = true, + }, + .data = { + .buswidth = 8, + .ddr = true, + }, +}; + +static u16 rpcif_hb_read16(struct hyperbus_device *hbdev, unsigned long addr) +{ + struct rpcif_hyperbus *hyperbus = + container_of(hbdev, struct rpcif_hyperbus, hbdev); + struct rpcif_op op = rpcif_op_tmpl; + map_word data; + + op.cmd.opcode = 0xC0; + op.addr.val = addr >> 1; + op.dummy.buswidth = 1; + op.dummy.ncycles = 15; + op.data.dir = RPCIF_DATA_IN; + op.data.nbytes = 2; + op.data.buf.in = &data; + rpcif_prepare(&hyperbus->rpc, &op, NULL, NULL); // ? + rpcif_io_xfer(&hyperbus->rpc); + + return be16_to_cpu(data.x[0]); +} + +static void rpcif_hb_write16(struct hyperbus_device *hbdev, unsigned long addr, + u16 data) +{ + struct rpcif_hyperbus *hyperbus = + container_of(hbdev, struct rpcif_hyperbus, hbdev); + struct rpcif_op op = rpcif_op_tmpl; + + op.cmd.opcode = 0x40; + op.addr.val = addr >> 1; + op.data.dir = RPCIF_DATA_OUT; + op.data.nbytes = 2; + op.data.buf.out = &data; + cpu_to_be16s(&data); + rpcif_prepare(&hyperbus->rpc, &op, NULL, NULL); // ? + rpcif_io_xfer(&hyperbus->rpc); +} + +static void rpcif_hb_copy_from(struct hyperbus_device *hbdev, void *to, + unsigned long from, ssize_t len) +{ + struct rpcif_hyperbus *hyperbus = + container_of(hbdev, struct rpcif_hyperbus, hbdev); + struct rpcif_op op = rpcif_op_tmpl; + + op.cmd.opcode = 0xA0; + op.addr.val = from; + op.dummy.buswidth = 1; + op.dummy.ncycles = 15; + op.data.dir = RPCIF_DATA_IN; + op.data.nbytes = len; + op.data.buf.in = to; + rpcif_prepare(&hyperbus->rpc, &op, NULL, NULL); // ? + rpcif_dirmap_read(&hyperbus->rpc, from, len, to); +} + +static const struct hyperbus_ops rpcif_hb_ops = { + .read16 = rpcif_hb_read16, + .write16 = rpcif_hb_write16, + .copy_from = rpcif_hb_copy_from, +}; + +static int rpcif_hb_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct rpcif_hyperbus *hyperbus; + int status; + + hyperbus = devm_kzalloc(dev, sizeof(*hyperbus), GFP_KERNEL); + if (!hyperbus) + return -ENOMEM; + + rpcif_sw_init(&hyperbus->rpc, pdev->dev.parent); + + platform_set_drvdata(pdev, hyperbus); + + rpcif_enable_rpm(&hyperbus->rpc); + + rpcif_hw_init(&hyperbus->rpc, true); + + hyperbus->hbdev.map.size = hyperbus->rpc.size; + hyperbus->hbdev.map.virt = hyperbus->rpc.dirmap; + + hyperbus->ctlr.dev = dev; + hyperbus->ctlr.ops = &rpcif_hb_ops; + hyperbus->hbdev.ctlr = &hyperbus->ctlr; + hyperbus->hbdev.np = of_get_next_child(pdev->dev.parent->of_node, NULL); + status = hyperbus_register_device(&hyperbus->hbdev); + if (status) { + dev_err(dev, "failed to register device\n"); + rpcif_disable_rpm(&hyperbus->rpc); + } + + return status; +} + +static int rpcif_hb_remove(struct platform_device *pdev) +{ + struct rpcif_hyperbus *hyperbus = platform_get_drvdata(pdev); + int error = hyperbus_unregister_device(&hyperbus->hbdev); + struct rpcif *rpc = dev_get_drvdata(pdev->dev.parent); + + rpcif_disable_rpm(rpc); + return error; +} + +static struct platform_driver rpcif_platform_driver = { + .probe = rpcif_hb_probe, + .remove = rpcif_hb_remove, + .driver = { + .name = "rpc-if-hyperflash", + }, +}; + +module_platform_driver(rpcif_platform_driver); + +MODULE_DESCRIPTION("Renesas RPC-IF HyperFlash driver"); +MODULE_LICENSE("GPL v2");