From patchwork Wed Jul 18 23:57:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 10533483 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5BD1D6020A for ; Wed, 18 Jul 2018 23:59:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48C9529924 for ; Wed, 18 Jul 2018 23:59:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BC2F29930; Wed, 18 Jul 2018 23:59:19 +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 9269F29924 for ; Wed, 18 Jul 2018 23:59:18 +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=hgGChY0sCfwbHqmSkNQUt9X3gQgq1O8RMfdIyLbK/ic=; b=o2k7SbmclCjXKrhA5m57lPwJNg RBhONmVpjGlf1AAC4mECtunSonY9LsmJAIU65nuD+t+IHmg29l7dI5MoZCYiaWflFf2DpjYu7JjE2 lfnABHUQzshySZdE13UJRWAgmgAuXtR1vydO5WmTTr/ZN0CyV5Pa9pjuiSd9Kke04nv0/A9/PUzxF Op8q9hlKIIdT85WztjpZlaCKHxkfbcmwE6BNdtxmEPdzNM8RAetKFVaXC9nKzg2rmYzY2q/EiVH5E ix89uLYCrDHD2AGIWH4trKI6aju2Xsuk+Zu/X/08Ti5JG2bOJanqflKSLZPs1J7/4OG9ffVudGnt9 1l5Qp/jQ==; 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 1ffwLj-0008Ad-3o; Wed, 18 Jul 2018 23:59:15 +0000 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ffwJd-0005nP-SR; Wed, 18 Jul 2018 23:57:12 +0000 Received: by mail-lj1-x242.google.com with SMTP id j19-v6so5603585ljc.7; Wed, 18 Jul 2018 16:57:02 -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=3XKuupnBNY0j4f8PnyiVgn0XIL1ETYrfOS2aLECZyzU=; b=tyFsGI8qYwOWZDq961kQ20o2H3IClKB5JUibFHqzN+d+NN8/UtYwbougAaSk8gnQHL DpUrRvH2BjRO8rTduGw3sI1aYonxAJ6S0dHlS8CO2WUD85b3cCNIH95b1o52PGUCle72 qVIL0t45B7v25MSrOiKXC/8V2JrP5fEuIh2ihA9hpM3hGYxUdImiP5Boc01jCsc8R0Co ZFBHMBFXp8UkXTg94ksoDJ8HV/FnMs+WWXu2Z4RJElCVn8aZfOYWRdqaMTw4fo0O5iVj AUuMsuq7DcKq5Cgv4nygYvKE/ywnIx8Z1NGkaHRit+rQad6GzYCFlzZ6ESrJq03ivRLc oxJQ== 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=3XKuupnBNY0j4f8PnyiVgn0XIL1ETYrfOS2aLECZyzU=; b=KsU2yWivyLQL6psAFbfrGmxgOVNcQq9S9tkTGORp9hbXClISJ1yV3HwIfWrMdP6vC6 YsgA9fQxMNm/myaaCbdKM9u38jIuik0UcYlPI6km1eiZ7zDmWyBfzMmI7W+3WfdnNvLW pHEwKRnt3O2MguEq94v1TjIwUCFIbYcoe1KVuc6xcsfT0RhSd0hty98R6lDNyhIvvTXR pWp2olmZMz4XXs/vs+M8TUk7QGu8v4KgtyF/NvNkalf6bQRyfFVD837g4yLGt5flQagn rnH5atJXNb6XW92L/vSbxID7OF9NXiQdagdzK2uSvyGQu+UkRhyU/hUNT2jl4PUENINV 0OHQ== X-Gm-Message-State: AOUpUlH27Tc5xdlqz3oO15b3bvQXEzKCUCtvFoYx5UuIH/47/ddkL6OM PAbbgCk4+9z0QuRZlN63EsY= X-Google-Smtp-Source: AAOMgpfPjigYXvKAL0ryICc8DoWIIQ09EswScp7vDya6SEnjTb1i24lJxYDamyWo8p3/kghFZieYvg== X-Received: by 2002:a2e:9f4d:: with SMTP id v13-v6mr5783528ljk.42.1531958221471; Wed, 18 Jul 2018 16:57:01 -0700 (PDT) Received: from z50.lan (93-181-165-181.internetia.net.pl. [93.181.165.181]) by smtp.gmail.com with ESMTPSA id h7-v6sm826584ljk.27.2018.07.18.16.56.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 16:57:00 -0700 (PDT) From: Janusz Krzysztofik To: Boris Brezillon , Miquel Raynal Subject: [RFC PATCH 8/8] mtd: rawnand: ams-delta: Use GPIO callbacks for data I/O Date: Thu, 19 Jul 2018 01:57:10 +0200 Message-Id: <20180718235710.18242-9-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180718235710.18242-1-jmkrzyszt@gmail.com> References: <20180718235710.18242-1-jmkrzyszt@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180718_165706_112987_FF665CAC X-CRM114-Status: GOOD ( 23.02 ) 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: Grygorii Strashko , Kevin Hilman , Tony Lindgren , Richard Weinberger , Linus Walleij , Aaro Koskinen , Artem Bityutskiy , linux-kernel@vger.kernel.org, Marek Vasut , linux-omap@vger.kernel.org, Janusz Krzysztofik , linux-mtd@lists.infradead.org, linux-gpio@vger.kernel.org, Santosh Shilimkar , 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 chip callbacks instead. Thanks to utilization of get/set_multiple() callbacks, performance degrade is minor for typical data transfers. The driver should now work with any 8+-bit bidirectional GPIO port, not only OMAP. Signed-off-by: Janusz Krzysztofik # Conflicts: # drivers/mtd/nand/raw/ams-delta.c --- arch/arm/mach-omap1/board-ams-delta.c | 11 ---- drivers/mtd/nand/raw/ams-delta.c | 119 +++++++++++++++------------------- 2 files changed, 52 insertions(+), 78 deletions(-) diff --git a/arch/arm/mach-omap1/board-ams-delta.c b/arch/arm/mach-omap1/board-ams-delta.c index 16f7bbe47607..08e732bc1cd2 100644 --- a/arch/arm/mach-omap1/board-ams-delta.c +++ b/arch/arm/mach-omap1/board-ams-delta.c @@ -321,20 +321,9 @@ struct modem_private_data { static struct modem_private_data modem_priv; -static struct resource ams_delta_nand_resources[] = { - [0] = { - .start = OMAP1_MPUIO_BASE, - .end = OMAP1_MPUIO_BASE + - OMAP_MPUIO_IO_CNTL + sizeof(u32) - 1, - .flags = IORESOURCE_MEM, - }, -}; - static struct platform_device ams_delta_nand_device = { .name = "ams-delta-nand", .id = -1, - .num_resources = ARRAY_SIZE(ams_delta_nand_resources), - .resource = ams_delta_nand_resources, }; #define OMAP_GPIO_LABEL "gpio-0-15" diff --git a/drivers/mtd/nand/raw/ams-delta.c b/drivers/mtd/nand/raw/ams-delta.c index bd501f385e78..8fac8d2a444a 100644 --- a/drivers/mtd/nand/raw/ams-delta.c +++ b/drivers/mtd/nand/raw/ams-delta.c @@ -25,13 +25,11 @@ #include #include #include -#include +#include #include #include -#include - /* * MTD structure for E3 (Delta) */ @@ -45,7 +43,9 @@ 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_chip *data_gpioc; + unsigned long data_mask; + int data_width; }; /* @@ -73,43 +73,55 @@ static const struct mtd_partition partition_info[] = { .size = 3 * SZ_256K }, }; -static void ams_delta_write_next_byte(struct ams_delta_nand *priv, u_char byte) +static void ams_delta_write_commit(struct ams_delta_nand *priv) { - struct nand_chip *this = &priv->nand_chip; - - writew(byte, this->IO_ADDR_W); gpiod_set_value(priv->gpiod_nwe, 0); ndelay(40); gpiod_set_value(priv->gpiod_nwe, 1); } +static void ams_delta_write_next_byte(struct ams_delta_nand *priv, u_char byte) +{ + struct gpio_chip *data_gpioc = priv->data_gpioc; + unsigned long bits = byte; + + data_gpioc->set_multiple(data_gpioc, &priv->data_mask, &bits); + + ams_delta_write_commit(priv); +} + static void ams_delta_write_first_byte(struct ams_delta_nand *priv, u_char byte) { - void __iomem *io_base = priv->io_base; + struct gpio_chip *data_gpioc = priv->data_gpioc; + unsigned long bits = byte; + int i; - writew(0, io_base + OMAP_MPUIO_IO_CNTL); + for (i = 0; i < priv->data_width; i++) + data_gpioc->direction_output(data_gpioc, i, test_bit(i, &bits)); - ams_delta_write_next_byte(priv, byte); + ams_delta_write_commit(priv); } static u_char ams_delta_read_next_byte(struct ams_delta_nand *priv) { - struct nand_chip *this = &priv->nand_chip; - u_char res; + struct gpio_chip *data_gpioc = priv->data_gpioc; + unsigned long bits; gpiod_set_value(priv->gpiod_nre, 0); ndelay(40); - res = readw(this->IO_ADDR_R); + data_gpioc->get_multiple(data_gpioc, &priv->data_mask, &bits); gpiod_set_value(priv->gpiod_nre, 1); - return res; + return bits; } static u_char ams_delta_read_first_byte(struct ams_delta_nand *priv) { - void __iomem *io_base = priv->io_base; + struct gpio_chip *data_gpioc = priv->data_gpioc; + int i; - writew(~0, io_base + OMAP_MPUIO_IO_CNTL); + for (i = 0; i < priv->data_width; i++) + data_gpioc->direction_input(data_gpioc, i); return ams_delta_read_next_byte(priv); } @@ -188,16 +200,11 @@ 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; struct gpio_chip *data_gpioc; unsigned long mask, bits; int i, 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); @@ -210,25 +217,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; @@ -238,7 +228,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) @@ -256,49 +246,49 @@ 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 output and set low */ data_gpiods = devm_gpiod_get_array(&pdev->dev, "data", GPIOD_OUT_LOW); if (IS_ERR(data_gpiods)) { err = PTR_ERR(data_gpiods); dev_err(&pdev->dev, "data GPIO request failed: %d\n", err); - goto out_mtd; + return err; } /* Use GPIO chip of first data GPIO pin descriptor */ @@ -312,7 +302,7 @@ static int ams_delta_init(struct platform_device *pdev) err = -EINVAL; dev_err(&pdev->dev, "data GPIO chip does not support get/set_multiple()\n"); - goto out_mtd; + return err; } /* Verify if get_multiple() returns all pins low as initialized above */ @@ -321,13 +311,13 @@ static int ams_delta_init(struct platform_device *pdev) if (err) { dev_err(&pdev->dev, "data GPIO chip get_multiple() failed: %d\n", err); - goto out_mtd; + return err; } if (bits) { err = -EINVAL; dev_err(&pdev->dev, "mismmatch of data GPIO initial value: %lu\n", bits); - goto out_mtd; + return err; } /* Verify each data GPIO pin */ @@ -337,7 +327,7 @@ static int ams_delta_init(struct platform_device *pdev) err = -EINVAL; dev_err(&pdev->dev, "GPIO chip mismatch of data bit %d\n", i); - goto out_mtd; + return err; } /* Require all pins active high (not inverted) */ @@ -346,7 +336,7 @@ static int ams_delta_init(struct platform_device *pdev) dev_err(&pdev->dev, "unsupported polarity of data GPIO bit %d\n", i); - goto out_mtd; + return err; } /* @@ -360,13 +350,13 @@ static int ams_delta_init(struct platform_device *pdev) dev_err(&pdev->dev, "data bit %d GPIO chip get() failed: %d\n", i, err); - goto out_mtd; + return err; } if (!err) { err = -EINVAL; dev_err(&pdev->dev, "mismatch of data GPIO bit %d value\n", i); - goto out_mtd; + return err; } /* @@ -379,14 +369,18 @@ static int ams_delta_init(struct platform_device *pdev) dev_err(&pdev->dev, "unsupported mode of data GPIO bit %d\n", i); - goto out_mtd; + return err; } } + priv->data_gpioc = data_gpioc; + priv->data_width = data_gpiods->ndescs; + priv->data_mask = (1 << data_gpiods->ndescs) - 1; + /* Scan to find existence of the device */ err = nand_scan(mtd, 1); if (err) - goto out_mtd; + return err; /* As soon as the device is found, release write protection */ gpiod_set_value(priv->gpiod_nwp, 1); @@ -394,13 +388,7 @@ static int ams_delta_init(struct platform_device *pdev) /* 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; } /* @@ -410,16 +398,13 @@ 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; /* Apply write protection */ gpiod_set_value(priv->gpiod_nwp, 0); - /* Release resources, unregister device */ + /* Unregister device */ nand_release(mtd); - iounmap(io_base); - return 0; }