Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4317888imm; Mon, 15 Oct 2018 12:41:30 -0700 (PDT) X-Google-Smtp-Source: ACcGV60sqQRtiucMlk8nrvbQ1Ri9K9K/lmL7ie0EPgvkiTycEYlRHTOkWrD0mBl+3Nud4a3BfV1I X-Received: by 2002:a17:902:788d:: with SMTP id q13-v6mr17554810pll.329.1539632490419; Mon, 15 Oct 2018 12:41:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539632490; cv=none; d=google.com; s=arc-20160816; b=YFokiUhzVk1ztjPTdFcKabCwDcjSCF8BD11VwHUS9K8Rn7ZCYJSGhA62v3D9WGJUyd hbfJfZ4CowtViMPLJGH6xnUINvjIUFmNrL5Zm4B8//n5LjwUyE5D2oC9u8kBuL7mzTNn yMp615W/dLJJYJ1qSdWJwT3U9Oi/hpnBxKPaKdfDpXd+HeNshayD4E0tuaoVoLm7FwMs WeYesSEGezCoSQFxExXlitjhvzMzZmUXsebL45zZb767NFQb2W2ds+oMeyQDp5Nsa0Ci kTAZnKP0jl84kSrkSWJENROaQYSeP+EtHnnwGkgOlZwFhXcJ9XwceLhH7tQyjTSjOvsD IHmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=/9NWfrU4yyCrkQpP563ooDYYnrLgUrU0Qz4OZakKBuY=; b=E9VI5zL0iUWe4ufufLw9Xn7oeDMJFpJXhQOLp9lRTDVUmyXhYsmn/o45dKciZ+kdRp 6+v6Qx1biq58Mlz1Py/YT83Kgz4y4PTPH6XQXrDTWYC5d6t83REnBVnWm/EwDAE+Nj10 lRgn2DXmiEohGp5qgAeTBer/QpW3Kg5G0UHzXvBcoF1DjxjtKmg5CAx5LFL3ubtPQ5yz OBScVCv0akbpiE/I8uQkAQNFr081c2FWeGxEhjMEroLZX8Rivy7h59efxsK67XMLPEVH /Fyq5awZ3U2DNE1KlxKwyfkW9q/07g3CPo2vYFt44Vcgy2WR+bWkgA8tdh1E4qTuedjY GiPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mxX6Icv5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r12-v6si11226990plo.269.2018.10.15.12.41.15; Mon, 15 Oct 2018 12:41:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mxX6Icv5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726977AbeJPD0p (ORCPT + 99 others); Mon, 15 Oct 2018 23:26:45 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:36069 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726713AbeJPD0p (ORCPT ); Mon, 15 Oct 2018 23:26:45 -0400 Received: by mail-lj1-f193.google.com with SMTP id p89-v6so18624289ljb.3 for ; Mon, 15 Oct 2018 12:40:04 -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=/9NWfrU4yyCrkQpP563ooDYYnrLgUrU0Qz4OZakKBuY=; b=mxX6Icv5oBLfOKQswoyZSRq4tPAm3cvvcaxSHIfl6T9q7GS0NlQJgbwvb7ouIBlbMp /yt86LKjzt92gQMgZuIN9dgcUqhxlejRByRKSOwT1Gq5v+Uk3Ec0RE73/qL1I1efNszl TSPd38Ep/rqBehziGdHF+hbnlSXWyBi24NfczpdK/KIdYj4PmqGRazqwazmbHRfjzcfP rF3JB3xJBnHm8304gh43RopFdaHekjENO00jzxy5zrHU3bxzhkP3NukIWmJWJrUuFslG a+4JHCHcQpKwe8yjTO8TVhMQDV/fVf7R4Xcxjvkg0orbqhA2Ir0EY2nuZzVQHSaOCkDa phAA== 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=/9NWfrU4yyCrkQpP563ooDYYnrLgUrU0Qz4OZakKBuY=; b=ofowdOG10CXl3XlKFdIFH5yNhvHUiDRNMP617xCz4r6KHxtHWjw/YMvR5edC74PI5H yoEeRCV01YpkzrtYe6a7Ph/4eZEus+5Em9M8t5OAfSA3H3e6a26iGG01J6oWZJ0AJTV/ 1HtjYT/5pcH88s5JxOJ4NJuHdQ8A3B4KkrBar178rFSimH2b3M5LQUipgpfhQVEhcgll 9/laYYgN0OWly0wB/s4zp+R2CU71JJkjSmo71Tikg1DzmbYydpeKH0+qeyAKW8wqL7XM A1WEp2+i/k43Siy65rNaeCe/zaLwq8z/jEpJO0800g9ew3eOnM7QGXjRD8Dcv2LU6+dI CViQ== X-Gm-Message-State: ABuFfogWAGc5IFMJ7ArIzZrKltBK0/x3HgdKA3kiYgVl/xpgNZIkrIFm V1iGO/XvJ6Yi/M8tCEb9Odk= X-Received: by 2002:a2e:92ca:: with SMTP id k10-v6mr11742168ljh.103.1539632403957; Mon, 15 Oct 2018 12:40:03 -0700 (PDT) Received: from z50.lan (93-181-165-181.internetia.net.pl. [93.181.165.181]) by smtp.gmail.com with ESMTPSA id l3-v6sm2658830lji.60.2018.10.15.12.40.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 12:40:03 -0700 (PDT) From: Janusz Krzysztofik To: Boris Brezillon , Miquel Raynal Cc: Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [PATCH v3 1/3] mtd: rawnand: Provide helper for polling GPIO R/B pin Date: Mon, 15 Oct 2018 21:41:28 +0200 Message-Id: <20181015194130.21764-1-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181012204101.26274-1-jmkrzyszt@gmail.com> References: <20181012204101.26274-1-jmkrzyszt@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Each controller driver having access to NAND R/B pin over GPIO would have to reimplement the polling loop otherwise. Suggested-by: Boris Brezillon Signed-off-by: Janusz Krzysztofik Reviewed-by: Boris Brezillon --- Changelog: v3: - don't surround added code with #ifdef CONFIG_GPIOLIB - sugeested by Boris Brezillon - thanks, - drop inadequate comment on calling ->exec_op() recursively - catched by Boris Brezillon, thanks, - drop redundant commend from header file - suggensted by Boris Brezillon - thanks, - update comment on waiting for R/B pin rather than command completion v2: New patch - v1 consisted of only one patch reusing legacy helper drivers/mtd/nand/raw/nand_base.c | 31 +++++++++++++++++++++++++++++++ include/linux/mtd/rawnand.h | 4 ++++ 2 files changed, 35 insertions(+) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 05bd0779fe9b..0d5a2dc59b8d 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -45,6 +45,7 @@ #include #include #include +#include #include "internals.h" @@ -531,6 +532,36 @@ int nand_soft_waitrdy(struct nand_chip *chip, unsigned long timeout_ms) }; EXPORT_SYMBOL_GPL(nand_soft_waitrdy); +/** + * nand_gpio_waitrdy - Poll R/B GPIO pin until ready + * @chip: NAND chip structure + * @gpiod: GPIO descriptor of R/B pin + * @timeout_ms: Timeout in ms + * + * Poll the R/B GPIO pin until it becomes ready. If that does not happen + * whitin the specified timeout, -ETIMEDOUT is returned. + * + * This helper is intended to be used when the controller has access to the + * NAND R/B pin over GPIO. + * + * Return 0 if the R/B pin indicates chip is ready, a negative error otherwise. + */ +int nand_gpio_waitrdy(struct nand_chip *chip, struct gpio_desc *gpiod, + unsigned long timeout_ms) +{ + /* Wait until R/B pin indicates chip is ready or timeout occurs */ + timeout_ms = jiffies + msecs_to_jiffies(timeout_ms); + do { + if (gpiod_get_value_cansleep(gpiod)) + return 0; + + cond_resched(); + } while (time_before(jiffies, timeout_ms)); + + return gpiod_get_value_cansleep(gpiod) ? 0 : -ETIMEDOUT; +}; +EXPORT_SYMBOL_GPL(nand_gpio_waitrdy); + /** * panic_nand_get_device - [GENERIC] Get chip for selected access * @chip: the nand chip descriptor diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index e10b126e148f..4e91a70ede10 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1346,4 +1346,8 @@ void nand_release(struct nand_chip *chip); */ int nand_soft_waitrdy(struct nand_chip *chip, unsigned long timeout_ms); +struct gpio_desc; +int nand_gpio_waitrdy(struct nand_chip *chip, struct gpio_desc *gpiod, + unsigned long timeout_ms); + #endif /* __LINUX_MTD_RAWNAND_H */ -- 2.16.4