From patchwork Mon Aug 6 22:29:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 10558091 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C90EA174A for ; Mon, 6 Aug 2018 22:55:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B368A294DB for ; Mon, 6 Aug 2018 22:55:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A42C32984B; Mon, 6 Aug 2018 22:55:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2B0E5294DB for ; Mon, 6 Aug 2018 22:55:26 +0000 (UTC) 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=WNeziXYaeqXF1FZ3JnD0Q3sCdetIcOecDS+JfQ1oP1k=; b=ItsjrhrLPOlm5vstzmfoMn6TCo zvyKwcC5E9nIxqpEp4F8v44d22/RO0s/lTCSDgLndSyg7nzgZc3sWjUMr67nbGamfMf0hTg8iXonp x3Jg1IJc3UdYQBccx3kIE249+rPC4fBG8C5DKXesvOR8B0wbg4GR20by0VqzusUJ4c0sG/++owsMq Kz4JMkZ09r0Iayz2f6dH8i6uQmpT8qd6a17JKv7RERHlY7a5v/LZhjwGfQAJRDzuzoCQPKtz2GB2V 29h8oWy/Pf5a3rjb5dHxkbvXOepDfhPuY2Lpvj329fJz0pzbGaydgQfqgREy/Rt3C5qXPlBT8XwCV kHVjsi9w==; 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 1fmoPL-0006XJ-1M; Mon, 06 Aug 2018 22:55:23 +0000 Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fmo0Y-0005Ra-Pf; Mon, 06 Aug 2018 22:29:58 +0000 Received: by mail-lf1-x142.google.com with SMTP id u202-v6so10191531lff.9; Mon, 06 Aug 2018 15:29:36 -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; bh=/bFrJqpkYAXIA89qeP/MiX5sn2g+I7ZzvqYqwTt5+3M=; b=nyFSQZIgFoC06japxmtl4hUOpncO2u0KUo72C9x12Wj9nY9UKs2lwF8+2azFrfK/8D nsIG6bGMySqPaXcAaj5WeoQVO3N//DzjMQLTujsoCeN/RFbjFRC56y5wyPg6eSaWg4TA H90b+u0D8IBv2Uk7XfANBJmMxgjNlUnZojwsCaQvNj7Zm8ygtr3gxx+TetQuZ6xQLSu9 yiX4iJBWYErE8x/Rh1/lnxZW3S8HT7Xnqi7d4HxvBReiluc90NfPKDRrfrcSBPssu37u K377uup2Tnz9YVF5ZfvyiU9eFIfu1uihH+pPJ91QwMIZe9y78xmTUp7oiiZP+q91Ki+O JNWQ== 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; bh=/bFrJqpkYAXIA89qeP/MiX5sn2g+I7ZzvqYqwTt5+3M=; b=O7/6S7Bzw8ympAui0aLxmE/pSl64XbLEq0tyKV5nw3EFHw3pZjEcXXM01CI82KPad1 o6FfxIXyJBrUx2rZW3s0lEN03BDdzDB9A4Pdgw9WR4DZ50wAL42xIiDn8yd794Y8b6So 1kb63oz/BqRxk5lm683pXjo1NLHxUMtjN5BhHctyN6bRNy9Jg0XmD2chvWo6sAFqWnn6 nUG7+hLZ7gEYT0HloubVcXz6n1kAHTHNlhFIpNA2ScI6uh+fvinNVNZNEtFp/c1jkNDJ Tbu1M16S6L3QVlev7USllHcef8FXHYcTA3opFvE9p4/WcNbRhH0bcCfXom9nqGMFj1c1 uLrQ== X-Gm-Message-State: AOUpUlGm347zneZhE5RlgwmWcRoTR3CtuVGnHs0daRX6UpQu7Ly4KqLB +yYbfw897PjjeKgJtK0YOvE= X-Google-Smtp-Source: AAOMgpeICtnonekoALrQpCgO/KhPn3gCvsWVa6RcYpMYX0ddp0xVRxdUrLc5QM6Ser8285T1uhYRog== X-Received: by 2002:ac2:428f:: with SMTP id m15-v6mr12815358lfh.52.1533594574784; Mon, 06 Aug 2018 15:29:34 -0700 (PDT) Received: from z50.lan (93-181-165-181.internetia.net.pl. [93.181.165.181]) by smtp.gmail.com with ESMTPSA id o4-v6sm2438561ljc.67.2018.08.06.15.29.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Aug 2018 15:29:34 -0700 (PDT) From: Janusz Krzysztofik To: Boris Brezillon , Linus Walleij Subject: [RFC PATCH v2 05/12] mtd: rawnand: ams-delta: use GPIO API for data read/write Date: Tue, 7 Aug 2018 00:29:11 +0200 Message-Id: <20180806222918.12644-6-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180806222918.12644-1-jmkrzyszt@gmail.com> References: <20180718235710.18242-1-jmkrzyszt@gmail.com> <20180806222918.12644-1-jmkrzyszt@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180806_152947_169930_9FB877C4 X-CRM114-Status: GOOD ( 20.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-omap@vger.kernel.org, Jonathan Corbet , Tony Lindgren , Richard Weinberger , linux-gpio@vger.kernel.org, Aaro Koskinen , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Marek Vasut , Janusz Krzysztofik , linux-mtd@lists.infradead.org, Miquel Raynal , Brian Norris , David Woodhouse , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Don't readw()/writew() data directly from/to GPIO port which is under control of gpio-omap driver, use GPIO API instead. Degrade of performance on Amstrad Delta is completely not acceptable. The driver should work with any 8+-bit bidirectional GPIO port, not only OMAP. Signed-off-by: Janusz Krzysztofik Reviewed-by: Linus Walleij --- drivers/mtd/nand/raw/ams-delta.c | 97 ++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 59 deletions(-) diff --git a/drivers/mtd/nand/raw/ams-delta.c b/drivers/mtd/nand/raw/ams-delta.c index 09d6901fc94d..78996ddf82e0 100644 --- a/drivers/mtd/nand/raw/ams-delta.c +++ b/drivers/mtd/nand/raw/ams-delta.c @@ -24,13 +24,10 @@ #include #include #include -#include +#include -#include #include -#include - /* * MTD structure for E3 (Delta) */ @@ -44,7 +41,7 @@ struct ams_delta_nand { struct gpio_desc *gpiod_nwe; struct gpio_desc *gpiod_ale; struct gpio_desc *gpiod_cle; - void __iomem *io_base; + struct gpio_descs *data_gpiods; }; /* @@ -76,10 +73,14 @@ static void ams_delta_write_byte(struct mtd_info *mtd, u_char byte) { struct nand_chip *this = mtd_to_nand(mtd); struct ams_delta_nand *priv = nand_get_controller_data(this); - void __iomem *io_base = priv->io_base; + struct gpio_descs *data_gpiods = priv->data_gpiods; + unsigned long bits = byte; + int i; + + for (i = 0; i < data_gpiods->ndescs; i++) + gpiod_direction_output_raw(data_gpiods->desc[i], + test_bit(i, &bits)); - writew(0, io_base + OMAP_MPUIO_IO_CNTL); - writew(byte, this->IO_ADDR_W); gpiod_set_value(priv->gpiod_nwe, 0); ndelay(40); gpiod_set_value(priv->gpiod_nwe, 1); @@ -87,18 +88,28 @@ static void ams_delta_write_byte(struct mtd_info *mtd, u_char byte) static u_char ams_delta_read_byte(struct mtd_info *mtd) { - u_char res; struct nand_chip *this = mtd_to_nand(mtd); struct ams_delta_nand *priv = nand_get_controller_data(this); - void __iomem *io_base = priv->io_base; + struct gpio_descs *data_gpiods = priv->data_gpiods; + unsigned long bits = 0; + int i, value_array[data_gpiods->ndescs]; + + for (i = 0; i < data_gpiods->ndescs; i++) + gpiod_direction_input(data_gpiods->desc[i]); gpiod_set_value(priv->gpiod_nre, 0); ndelay(40); - writew(~0, io_base + OMAP_MPUIO_IO_CNTL); - res = readw(this->IO_ADDR_R); + + gpiod_get_raw_array_value(data_gpiods->ndescs, data_gpiods->desc, + value_array); + gpiod_set_value(priv->gpiod_nre, 1); - return res; + for (i = 0; i < data_gpiods->ndescs; i++) + if (value_array[i]) + __set_bit(i, &bits); + + return bits; } static void ams_delta_write_buf(struct mtd_info *mtd, const u_char *buf, @@ -159,14 +170,8 @@ static int ams_delta_init(struct platform_device *pdev) struct ams_delta_nand *priv; struct nand_chip *this; struct mtd_info *mtd; - struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - void __iomem *io_base; - struct gpio_descs *data_gpiods; int err = 0; - if (!res) - return -ENXIO; - /* Allocate memory for MTD device structure and private data */ priv = devm_kzalloc(&pdev->dev, sizeof(struct ams_delta_nand), GFP_KERNEL); @@ -179,25 +184,8 @@ static int ams_delta_init(struct platform_device *pdev) mtd = nand_to_mtd(this); mtd->dev.parent = &pdev->dev; - /* - * Don't try to request the memory region from here, - * it should have been already requested from the - * gpio-omap driver and requesting it again would fail. - */ - - io_base = ioremap(res->start, resource_size(res)); - if (io_base == NULL) { - dev_err(&pdev->dev, "ioremap failed\n"); - err = -EIO; - goto out_free; - } - - priv->io_base = io_base; nand_set_controller_data(this, priv); - /* Set address of NAND IO lines */ - this->IO_ADDR_R = io_base + OMAP_MPUIO_INPUT_LATCH; - this->IO_ADDR_W = io_base + OMAP_MPUIO_OUTPUT; this->read_byte = ams_delta_read_byte; this->write_buf = ams_delta_write_buf; this->read_buf = ams_delta_read_buf; @@ -207,7 +195,7 @@ static int ams_delta_init(struct platform_device *pdev) if (IS_ERR(priv->gpiod_rdy)) { err = PTR_ERR(priv->gpiod_rdy); dev_warn(&pdev->dev, "RDY GPIO request failed (%d)\n", err); - goto out_mtd; + return err; } if (priv->gpiod_rdy) @@ -225,66 +213,60 @@ static int ams_delta_init(struct platform_device *pdev) if (IS_ERR(priv->gpiod_nwp)) { err = PTR_ERR(priv->gpiod_nwp); dev_err(&pdev->dev, "NWP GPIO request failed (%d)\n", err); - goto out_mtd; + return err; } priv->gpiod_nce = devm_gpiod_get(&pdev->dev, "nce", GPIOD_OUT_HIGH); if (IS_ERR(priv->gpiod_nce)) { err = PTR_ERR(priv->gpiod_nce); dev_err(&pdev->dev, "NCE GPIO request failed (%d)\n", err); - goto out_mtd; + return err; } priv->gpiod_nre = devm_gpiod_get(&pdev->dev, "nre", GPIOD_OUT_HIGH); if (IS_ERR(priv->gpiod_nre)) { err = PTR_ERR(priv->gpiod_nre); dev_err(&pdev->dev, "NRE GPIO request failed (%d)\n", err); - goto out_mtd; + return err; } priv->gpiod_nwe = devm_gpiod_get(&pdev->dev, "nwe", GPIOD_OUT_HIGH); if (IS_ERR(priv->gpiod_nwe)) { err = PTR_ERR(priv->gpiod_nwe); dev_err(&pdev->dev, "NWE GPIO request failed (%d)\n", err); - goto out_mtd; + return err; } priv->gpiod_ale = devm_gpiod_get(&pdev->dev, "ale", GPIOD_OUT_LOW); if (IS_ERR(priv->gpiod_ale)) { err = PTR_ERR(priv->gpiod_ale); dev_err(&pdev->dev, "ALE GPIO request failed (%d)\n", err); - goto out_mtd; + return err; } priv->gpiod_cle = devm_gpiod_get(&pdev->dev, "cle", GPIOD_OUT_LOW); if (IS_ERR(priv->gpiod_cle)) { err = PTR_ERR(priv->gpiod_cle); dev_err(&pdev->dev, "CLE GPIO request failed (%d)\n", err); - goto out_mtd; + return err; } /* Request array of data pins, initialize them as input */ - data_gpiods = devm_gpiod_get_array(&pdev->dev, "data", GPIOD_IN); - if (IS_ERR(data_gpiods)) { - err = PTR_ERR(data_gpiods); + priv->data_gpiods = devm_gpiod_get_array(&pdev->dev, "data", GPIOD_IN); + if (IS_ERR(priv->data_gpiods)) { + err = PTR_ERR(priv->data_gpiods); dev_err(&pdev->dev, "data GPIO request failed: %d\n", err); - goto out_mtd; + return err; } /* Scan to find existence of the device */ err = nand_scan(mtd, 1); if (err) - goto out_mtd; + return err; /* Register the partitions */ mtd_device_register(mtd, partition_info, ARRAY_SIZE(partition_info)); - goto out; - - out_mtd: - iounmap(io_base); -out_free: - out: - return err; + return 0; } /* @@ -294,13 +276,10 @@ static int ams_delta_cleanup(struct platform_device *pdev) { struct ams_delta_nand *priv = platform_get_drvdata(pdev); struct mtd_info *mtd = nand_to_mtd(&priv->nand_chip); - void __iomem *io_base = priv->io_base; - /* Release resources, unregister device */ + /* Unregister device */ nand_release(mtd); - iounmap(io_base); - return 0; }