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.3 required=3.0 tests=BAYES_00, 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 866D5C433ED for ; Tue, 18 May 2021 11:40:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 627E061285 for ; Tue, 18 May 2021 11:40:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348816AbhERLmC (ORCPT ); Tue, 18 May 2021 07:42:02 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:38794 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348798AbhERLmA (ORCPT ); Tue, 18 May 2021 07:42:00 -0400 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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.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; > +}