From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_2 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF22EC43460 for ; Tue, 18 May 2021 11:42:27 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8FABD610A2 for ; Tue, 18 May 2021 11:42:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FABD610A2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=dqW8NB5sUXOFIE2wNnM8xCdXr88ZifOIfb2t3VlrdCo=; b=pFx9Z93pEhBAMqrxqBw61xD8R DKzjLFxoMudKzf6aCW8wRsnwvmjkR9iT9REg+vqExW7cgJZYrTtl0BxALZGoHpFMUxzVbDfsyf9N0 TxBTv+ZehMNR0PhkCMLIxbp2J3/kpoz39Gy7VJEnDM2UwVESajNEcvijMpY9aeUSY0VqYgz2It+Db d/q+YunnX+7hPZ0PfJ/LxuYUu8wwHZx4UD6/JryZaPRp+8+gclbKscylqwY/Ey1Mzvr/6CQqzVni2 XKorRT+u/Nx1AFyY3+PeFMzoUPRk5OiqD74BaYBNj81ruUqo1GIqEsCIG97wqtJHUscZBFG1vR3Ob 79HczDehA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1liy5h-000bWe-8B; Tue, 18 May 2021 11:40:49 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1liy5d-000bVz-Mx; Tue, 18 May 2021 11:40:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To: From:Date:Sender:Reply-To:Content-ID:Content-Description; bh=WWBEoYzugaTrnU8hDN3B22Le21dJzKYPbeNi3V5Idvc=; b=dD23tYW5JK48QxLykNPgdWJG0y hhlZRg66R/8nEdv2+2DIvhq7aSUbbJ1yMlDnW2FfgDpp0bBHggMkA2bLLD0utVn+lSk/xhj2Ut2C5 oFRuXDfaRnRYEKauJwCE/cSBCjs98ERi2QOlES7bvM74GqSS4u1rKZzR+vysyQ4c2u+6DQm3kJ8ei +6ROp3mzddrDq1SykLgzvM3XC2yQixsFQzWTwf3HoKu+3Jg3bR8TG58Fnc94uXpDuKoItN8CKPJrN IH4g5Tn+weEcDvr8f9JQ5kMRuFWWkcIMBKvWQFpLiMSpB4zYdZC/tPcXGLqGjfK9PhG5mSa8wYXe1 dKZ9hJMA==; Received: from bhuna.collabora.co.uk ([46.235.227.227]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1liy5b-00Ebso-4m; Tue, 18 May 2021 11:40:44 +0000 Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: bbrezillon) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 9B4561F42F6C; Tue, 18 May 2021 12:40:41 +0100 (BST) Date: Tue, 18 May 2021 13:40:37 +0200 From: Boris Brezillon To: Cc: Mark Brown , Miquel Raynal , Vignesh Raghavendra , Alexandre Torgue , , , , , Subject: Re: [PATCH v3 1/3] spi: spi-mem: add automatic poll status functions Message-ID: <20210518134037.0e5839b0@collabora.com> In-Reply-To: <20210518093951.23136-2-patrice.chotard@foss.st.com> References: <20210518093951.23136-1-patrice.chotard@foss.st.com> <20210518093951.23136-2-patrice.chotard@foss.st.com> Organization: Collabora X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210518_044043_349547_EF4B4471 X-CRM114-Status: GOOD ( 16.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 18 May 2021 11:39:49 +0200 wrote: > +/** > + * spi_mem_poll_status() - Poll memory device status > + * @mem: SPI memory device > + * @op: the memory operation to execute > + * @mask: status bitmask to ckeck > + * @match: (status & mask) expected value > + * @initial_delay_us: delay in us before starting to poll > + * @polling_delay_us: time to sleep between reads in us > + * @timeout_ms: timeout in milliseconds > + * > + * This function send a polling status request to the controller driver > + * > + * Return: 0 in case of success, -ETIMEDOUT in case of error, > + * -EOPNOTSUPP if not supported. > + */ > +int spi_mem_poll_status(struct spi_mem *mem, > + const struct spi_mem_op *op, > + u16 mask, u16 match, > + unsigned long initial_delay_us, > + unsigned long polling_delay_us, > + u16 timeout_ms) > +{ > + struct spi_controller *ctlr = mem->spi->controller; > + int ret = -EOPNOTSUPP; > + int read_status_ret; > + u16 status; > + > + if (op->data.nbytes < 1 || op->data.nbytes > 2) > + return -EINVAL; We should also make sure this is a read operation. > + > + if (ctlr->mem_ops && ctlr->mem_ops->poll_status) { > + ret = spi_mem_access_start(mem); > + if (ret) > + return ret; > + > + ret = ctlr->mem_ops->poll_status(mem, op, mask, match, > + initial_delay_us, polling_delay_us, > + timeout_ms); > + > + spi_mem_access_end(mem); > + } > + > + if (ret == -EOPNOTSUPP) { > + if (!spi_mem_supports_op(mem, op)) > + return ret; > + > + if (initial_delay_us < 10) > + udelay(initial_delay_us); > + else > + usleep_range((initial_delay_us >> 2) + 1, > + initial_delay_us); > + > + ret = read_poll_timeout(spi_mem_read_status, read_status_ret, > + (read_status_ret || ((status) & mask) == match), > + polling_delay_us, timeout_ms * 1000, false, mem, > + op, &status); > + if (read_status_ret) > + return read_status_ret; > + } > + > + return ret; > +} _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel