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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33F1AC433F5 for ; Sat, 9 Oct 2021 15:05:08 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C479160F6C for ; Sat, 9 Oct 2021 15:05:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C479160F6C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=rock-chips.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5EBE58366A; Sat, 9 Oct 2021 17:05:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=rock-chips.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 6C18383670; Sat, 9 Oct 2021 17:05:03 +0200 (CEST) Received: from regular1.263xmail.com (regular1.263xmail.com [211.150.70.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D139583663 for ; Sat, 9 Oct 2021 17:04:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=rock-chips.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=kever.yang@rock-chips.com Received: from localhost (unknown [192.168.167.16]) by regular1.263xmail.com (Postfix) with ESMTP id 8F0991453 for ; Sat, 9 Oct 2021 23:04:49 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-SKE-CHECKED: 1 X-ABS-CHECKED: 1 X-ANTISPAM-LEVEL: 2 Received: from [192.168.0.110] (unknown [112.49.233.219]) by smtp.263.net (postfix) whith ESMTP id P16456T140480306206464S1633791889754937_; Sat, 09 Oct 2021 23:04:50 +0800 (CST) X-IP-DOMAINF: 1 X-RL-SENDER: kever.yang@rock-chips.com X-SENDER: yk@rock-chips.com X-LOGIN-NAME: kever.yang@rock-chips.com X-FST-TO: sjg@chromium.org X-RCPT-COUNT: 5 X-LOCAL-RCPT-COUNT: 1 X-SENDER-IP: 112.49.233.219 X-ATTACHMENT-NUM: 0 X-UNIQUE-TAG: <81b3c9c7ea70003af886d218691dda2b> X-System-Flag: 0 Subject: Re: [PATCH v3 2/2] spi: rockchip_sfc: Using read_poll To: Jon Lin , jagan@amarulasolutions.com Cc: u-boot@lists.denx.de, macromorgan@hotmail.com, sjg@chromium.org References: <20210917211424.v3.1.I2ce354b421327523e663c63063c3393415ff3dae@changeid> <20210917211424.v3.2.I39fc8d543272bfcd9b5e8a06a4ca93d390595e49@changeid> From: Kever Yang Message-ID: <8948d64b-1247-010b-55a5-ca19a1eead9b@rock-chips.com> Date: Sat, 9 Oct 2021 23:04:48 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210917211424.v3.2.I39fc8d543272bfcd9b5e8a06a4ca93d390595e49@changeid> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On 2021/9/17 下午9:14, Jon Lin wrote: > Using read_poll logic. > > Tested-by: Chris Morgan > Signed-off-by: Jon Lin Reviewed-by: Kever Yang Thanks, - Kever > --- > > (no changes since v2) > > Changes in v2: > - Fix assigned but never used return error codes > > drivers/spi/rockchip_sfc.c | 67 ++++++++++++++++++++------------------ > 1 file changed, 35 insertions(+), 32 deletions(-) > > diff --git a/drivers/spi/rockchip_sfc.c b/drivers/spi/rockchip_sfc.c > index 94222df5ce..e098addddc 100644 > --- a/drivers/spi/rockchip_sfc.c > +++ b/drivers/spi/rockchip_sfc.c > @@ -285,33 +285,38 @@ err_init: > return ret; > } > > -static inline int rockchip_sfc_get_fifo_level(struct rockchip_sfc *sfc, int wr) > +static int rockchip_sfc_wait_txfifo_ready(struct rockchip_sfc *sfc, u32 timeout_us) > { > - u32 fsr = readl(sfc->regbase + SFC_FSR); > - int level; > + int ret = 0; > + u32 status; > > - if (wr) > - level = (fsr & SFC_FSR_TXLV_MASK) >> SFC_FSR_TXLV_SHIFT; > - else > - level = (fsr & SFC_FSR_RXLV_MASK) >> SFC_FSR_RXLV_SHIFT; > + ret = readl_poll_timeout(sfc->regbase + SFC_FSR, status, > + status & SFC_FSR_TXLV_MASK, > + timeout_us); > + if (ret) { > + dev_dbg(sfc->dev, "sfc wait tx fifo timeout\n"); > + > + return -ETIMEDOUT; > + } > > - return level; > + return (status & SFC_FSR_TXLV_MASK) >> SFC_FSR_TXLV_SHIFT; > } > > -static int rockchip_sfc_wait_fifo_ready(struct rockchip_sfc *sfc, int wr, u32 timeout) > +static int rockchip_sfc_wait_rxfifo_ready(struct rockchip_sfc *sfc, u32 timeout_us) > { > - unsigned long tbase = get_timer(0); > - int level; > + int ret = 0; > + u32 status; > > - while (!(level = rockchip_sfc_get_fifo_level(sfc, wr))) { > - if (get_timer(tbase) > timeout) { > - debug("%s fifo timeout\n", wr ? "write" : "read"); > - return -ETIMEDOUT; > - } > - udelay(1); > + ret = readl_poll_timeout(sfc->regbase + SFC_FSR, status, > + status & SFC_FSR_RXLV_MASK, > + timeout_us); > + if (ret) { > + dev_dbg(sfc->dev, "sfc wait rx fifo timeout\n"); > + > + return -ETIMEDOUT; > } > > - return level; > + return (status & SFC_FSR_RXLV_MASK) >> SFC_FSR_RXLV_SHIFT; > } > > static void rockchip_sfc_adjust_op_work(struct spi_mem_op *op) > @@ -429,7 +434,7 @@ static int rockchip_sfc_write_fifo(struct rockchip_sfc *sfc, const u8 *buf, int > > dwords = len >> 2; > while (dwords) { > - tx_level = rockchip_sfc_wait_fifo_ready(sfc, SFC_CMD_DIR_WR, 1000); > + tx_level = rockchip_sfc_wait_txfifo_ready(sfc, 1000); > if (tx_level < 0) > return tx_level; > write_words = min_t(u32, tx_level, dwords); > @@ -440,7 +445,7 @@ static int rockchip_sfc_write_fifo(struct rockchip_sfc *sfc, const u8 *buf, int > > /* write the rest non word aligned bytes */ > if (bytes) { > - tx_level = rockchip_sfc_wait_fifo_ready(sfc, SFC_CMD_DIR_WR, 1000); > + tx_level = rockchip_sfc_wait_txfifo_ready(sfc, 1000); > if (tx_level < 0) > return tx_level; > memcpy(&tmp, buf, bytes); > @@ -461,7 +466,7 @@ static int rockchip_sfc_read_fifo(struct rockchip_sfc *sfc, u8 *buf, int len) > /* word aligned access only */ > dwords = len >> 2; > while (dwords) { > - rx_level = rockchip_sfc_wait_fifo_ready(sfc, SFC_CMD_DIR_RD, 1000); > + rx_level = rockchip_sfc_wait_rxfifo_ready(sfc, 1000); > if (rx_level < 0) > return rx_level; > read_words = min_t(u32, rx_level, dwords); > @@ -472,7 +477,7 @@ static int rockchip_sfc_read_fifo(struct rockchip_sfc *sfc, u8 *buf, int len) > > /* read the rest non word aligned bytes */ > if (bytes) { > - rx_level = rockchip_sfc_wait_fifo_ready(sfc, SFC_CMD_DIR_RD, 1000); > + rx_level = rockchip_sfc_wait_rxfifo_ready(sfc, 1000); > if (rx_level < 0) > return rx_level; > tmp = readl(sfc->regbase + SFC_DATA); > @@ -533,19 +538,17 @@ static int rockchip_sfc_xfer_data_dma(struct rockchip_sfc *sfc, > > static int rockchip_sfc_xfer_done(struct rockchip_sfc *sfc, u32 timeout_us) > { > - unsigned long tbase = get_timer(0); > int ret = 0; > - u32 timeout = timeout_us; > - > - while (readl(sfc->regbase + SFC_SR) & SFC_SR_IS_BUSY) { > - if (get_timer(tbase) > timeout) { > - printf("wait sfc idle timeout\n"); > - rockchip_sfc_reset(sfc); > + u32 status; > > - return -ETIMEDOUT; > - } > + ret = readl_poll_timeout(sfc->regbase + SFC_SR, status, > + !(status & SFC_SR_IS_BUSY), > + timeout_us); > + if (ret) { > + dev_err(sfc->dev, "wait sfc idle timeout\n"); > + rockchip_sfc_reset(sfc); > > - udelay(1); > + ret = -EIO; > } > > return ret;