From patchwork Sat Oct 3 20:23:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Shtylyov X-Patchwork-Id: 1376376 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=2001:8b0:10b:1231::1; helo=merlin.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; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=oya2pdsq; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=vfE7UOCB; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (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 4C3rbl51TYz9ryj for ; Sun, 4 Oct 2020 15:39:15 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Date:Message-ID:To:Subject: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=JKKWL88FHTPnGCkLSjbjWV4egHJosG5sadgRGoHCupc=; b=oya2pdsqzuV3FL62XrZIEEK2GR 4ZpUVdmg8ptnXekL92UN9P27GIAkJm5ygOJXUBpmpRwtzs3Jb+WnyCaleYSngU4O9xmr4+bCWMC97 D440tC9iTCSKdMIXlXXAFY1nVQ22qwvJ/cyyznLaJfw8OGKPBtDYhTOqv0sho/lDuD0ABxjiNVaiJ mrRMBcVnM9PEgP05jE2Vb4ge7zyh/LY4NC5lgx5f+giF+6F4BWtuV9Gcbngy1JiqCqAmJjmlIcM31 diOP1cWoTAzLXGENkQsXFqbueEhRbjWEK112tAFs/vwdtkp8tXSG7T/aWb4hDDhxcAPyocQya5eJm 6lvO67ug==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kOvmi-00035A-BO; Sun, 04 Oct 2020 04:38:08 +0000 Received: from mail-ej1-x642.google.com ([2a00:1450:4864:20::642]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kOvmf-00032s-3n for linux-mtd@lists.infradead.org; Sun, 04 Oct 2020 04:38:06 +0000 Received: by mail-ej1-x642.google.com with SMTP id u8so7182820ejg.1 for ; Sat, 03 Oct 2020 21:38:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:organization:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=akTjh5s829ygXWoLmGMPPyqwgdYuKiafWToy1Z3aBbA=; b=vfE7UOCBXMr9wQmjEpQrMLk8DJz6xsIR2fGVD6IAV4lyz2E5g/TS9t60RFzqDltRId rsbzH0XdYFHq1I/l8V2aWhJnCYbabyiixZ9h6xUr+7sOcICCq3CH2BqIN9bH18xqg0+f ttAnbPKkw8EZIQZOaA1gREJUW51C06ZXSf/GbFxpt26uVA9HIQj1aT1fdS1AMU4PIo02 CNyBIjrg8/CzkXVgl1it1Wj1bBjuDoJWnm9uhShZRev+keaxJjhAiZavTz/JjeMGpMo3 VUAZJnAPVHjlQNgnJ2x0CzU38eCZYsRbIJ3zAVonPb2NGYryPqo4Wm1mlZAtWnlSmdke OwLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:organization:message-id:date :user-agent:mime-version:content-language:content-transfer-encoding; bh=akTjh5s829ygXWoLmGMPPyqwgdYuKiafWToy1Z3aBbA=; b=tL+PzrrY0cP6/nc1sGAnTrbYbnf6ruUvwokdcBWokZaLBr9ZdAIciOoWDmfD59Homh xPT0v1/ld1jmVo3jf1xEHhuHKPbpwqBF+gjnAq46Nl/uT1a0yT+k5un/Qm22aoPCvMSU 2OMPtFv88l9TJ3Q8sF6U6oxSbt4KD12/7CiMilZp8SGsNtreCMp/vz+4/SJjTBtesOG/ dP04Bo3vdzE2SSoh9t7aPjkVNb8tqMBcaYjcqmWJMmedWS3mDOIt90vuja/rFARIRqxt Dqw1sS5qF1jv9lX2g2819M1HpG5N3gehBx6KDM3tt6pQxVPoyBuYH/+b8T504Fc4PtDi F/pg== X-Gm-Message-State: AOAM533OO0tJtL6I/h36/T5xvx+UncjvBZhpNs4fv1bivc+QVKnhmP5A vaYQGLTuHm3ROCwAyLfX9hGdVYnikSo= X-Google-Smtp-Source: ABdhPJwOxPe2Ie3wSw2JAqfu5jH0+22e0zK01W6kn0l2zu+DBM8ytLxgr+305jnhnW+RauTLYi1wjA== X-Received: by 2002:a05:6512:338e:: with SMTP id h14mr2668520lfg.422.1601756602417; Sat, 03 Oct 2020 13:23:22 -0700 (PDT) Received: from wasted.cogentembedded.com ([2a00:1fa0:4263:86b1:7b03:4405:a50:ae1c]) by smtp.gmail.com with ESMTPSA id v13sm2325056lfo.30.2020.10.03.13.23.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Oct 2020 13:23:21 -0700 (PDT) From: Sergei Shtylyov Subject: [PATCH v3] mtd: hyperbus: add Renesas RPC-IF driver To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org Organization: Brain-dead Software Message-ID: <78abb851-2beb-fe7d-87e5-ce58ee877d35@gmail.com> Date: Sat, 3 Oct 2020 23:23:20 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Content-Language: en-MW X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201004_003805_180458_A0AEE1B9 X-CRM114-Status: GOOD ( 27.45 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 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:642 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [sergei.shtylyov[at]gmail.com] -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_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -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 From: Sergei Shtylyov 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 --- This patch is against the 'mtd/next' branch of the MTD 'linux.git' repo. Changes in version 3: - factored out rpcif_hb_prepare_read() out of the read16() and copy_from() driver methods and rpcif_hb_prepare_write() out of the write16() method; - added #define's fo the HyperBus command bits to the HyperBus header file, made use of them in the driver; - removed #ifndef CONFIG_MTD_CFI_BE_BYTE_SWAP fromn the driver; convertged the 'select' line to 'depends on' line inm the Kconfig option; - added CONFIG_COMPILE_TEST to the 'depends on' line of the driver's Kconfig option; - changed HyperFlash to HyperBus in the driver's Kconfig option's help text; - killed a stray space before the declaration of the 'struct rpcif_hyperbus'. Changes in version 2: - added 'select MTD_CFI_ADV_OPTIONS' to the Kconfig entry, added #ifndef CONFIG_MTD_CFI_BE_BYTE_SWAP #error in the driver, and removed be16_to_cpu() call in the read16() method; - zeroed the target and burst type bits of the HyperBus command codes; - passed the address of 16-bit entity to rpcif_prepare() in the copy_from() method; - added an empty line between rpcif_prepare() and rpcif_drirmap_read() calls in the copy_from() method; - renamed rpcif_io_xfer() to rpcif_manual_xfer(); - removed the C++ style comments to rpcif_prepare() calls; - removed dev_err() call from the probe() method; - renamed the 'status' local variable to 'error' in the probe() method; - extended the driver copyright to this year. drivers/mtd/hyperbus/Kconfig | 7 + drivers/mtd/hyperbus/Makefile | 1 drivers/mtd/hyperbus/rpc-if.c | 170 ++++++++++++++++++++++++++++++++++++++++++ include/linux/mtd/hyperbus.h | 11 ++ 4 files changed, 189 insertions(+) Index: linux/drivers/mtd/hyperbus/Kconfig =================================================================== --- linux.orig/drivers/mtd/hyperbus/Kconfig +++ linux/drivers/mtd/hyperbus/Kconfig @@ -22,4 +22,11 @@ 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 || COMPILE_TEST + depends on MTD_CFI_BE_BYTE_SWAP + help + This option includes Renesas RPC-IF HyperBus 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,170 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Linux driver for RPC-IF HyperFlash + * + * Copyright (C) 2019-2020 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 void rpcif_hb_prepare_read(struct rpcif *rpc, void *to, + unsigned long from, ssize_t len) +{ + struct rpcif_op op = rpcif_op_tmpl; + + op.cmd.opcode = HYPERBUS_RW_READ | HYPERBUS_AS_MEM; + op.addr.val = from >> 1; + 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(rpc, &op, NULL, NULL); +} + +static void rpcif_hb_prepare_write(struct rpcif *rpc, unsigned long to, + void *from, ssize_t len) +{ + struct rpcif_op op = rpcif_op_tmpl; + + op.cmd.opcode = HYPERBUS_RW_WRITE | HYPERBUS_AS_MEM; + op.addr.val = to >> 1; + op.data.dir = RPCIF_DATA_OUT; + op.data.nbytes = len; + op.data.buf.out = from; + + rpcif_prepare(rpc, &op, NULL, NULL); +} + +static u16 rpcif_hb_read16(struct hyperbus_device *hbdev, unsigned long addr) +{ + struct rpcif_hyperbus *hyperbus = + container_of(hbdev, struct rpcif_hyperbus, hbdev); + map_word data; + + rpcif_hb_prepare_read(&hyperbus->rpc, &data, addr, 2); + + rpcif_manual_xfer(&hyperbus->rpc); + + return 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); + + rpcif_hb_prepare_write(&hyperbus->rpc, addr, &data, 2); + + rpcif_manual_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); + + rpcif_hb_prepare_read(&hyperbus->rpc, to, from, len); + + 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 error; + + 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); + error = hyperbus_register_device(&hyperbus->hbdev); + if (error) + rpcif_disable_rpm(&hyperbus->rpc); + + return error; +} + +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"); Index: linux/include/linux/mtd/hyperbus.h =================================================================== --- linux.orig/include/linux/mtd/hyperbus.h +++ linux/include/linux/mtd/hyperbus.h @@ -8,6 +8,17 @@ #include +/* HyperBus command bits */ +#define HYPERBUS_RW 0x80 /* R/W# */ +#define HYPERBUS_RW_WRITE 0 +#define HYPERBUS_RW_READ 0x80 +#define HYPERBUS_AS 0x40 /* Address Space */ +#define HYPERBUS_AS_MEM 0 +#define HYPERBUS_AS_REG 0x40 +#define HYPERBUS_BT 0x20 /* Burst Type */ +#define HYPERBUS_BT_WRAPPED 0 +#define HYPERBUS_BT_LINEAR 0x20 + enum hyperbus_memtype { HYPERFLASH, HYPERRAM,