From patchwork Tue Dec 24 00:58:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kunihiko Hayashi X-Patchwork-Id: 182423 Delivered-To: patch@linaro.org Received: by 2002:a92:a146:0:0:0:0:0 with SMTP id v67csp1083135ili; Mon, 23 Dec 2019 16:58:52 -0800 (PST) X-Google-Smtp-Source: APXvYqzQVmmY7xyaBw/Qrv3mMSvwT6ZVGB50g2uQipT7I1Dkgzh8KedXbN6Te6V/iRYSNulq4jJ2 X-Received: by 2002:a9d:4e92:: with SMTP id v18mr20854397otk.47.1577149131888; Mon, 23 Dec 2019 16:58:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577149131; cv=none; d=google.com; s=arc-20160816; b=GbEA50GOM6pA4Jyv0Q8IBEDZ5nA8aV5/qs89PQ77HOoR8Ohl7OyG1fRuNEB+urvOj9 60dp0QKWE7px0/MqdzG0XaM1vKsDSDjk8YwCuzs2U9gPh5NFAmgrXyB7eVSi0obVXgDr 4l5CF8PqhgKeOZ0aqsJCvBMTs3ANpjtGx9rT3RY+exRWHTaFW6ju1GFeDFk7kvoVV8Eq CJGKAP9oehQurThBDaTcDXmzjW/xX1vY19nYPfJeKdWr2uJWEolqKbDwl67htUfqv/ff uI2Pxeuwm5Rb0BMr3sUDR7hbv3ddXk7AbgN27htHSqWcDT8nbZxZxsd589yl2dwBpReR nJJw== 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; bh=UKUpmCCbfic5rHOAMFlJ9IezbN7zqjhgEIN/WK0PWT8=; b=Sl6+8otwB950UlwOm0F9z+lGO4Ym3O9T5fSpoc2UMQjFBRA0X4FqQ7KvMRL/Jkoadi XUaydKmp1KI5+qIZ6yZNhkgbc9qq/uiIMePvB3Tj++iBZG5Q+35gKyDnmiKtmUDPXa2d OiTDi6SGArbbYw/SrJBevR4Ac1J/hcqysuIkRbBvv0WU66OZoMq9OebHhzS/oZYOJQTj cUGVuqOfUFoqJLz+A/RSBBTGDGHY9CqdxOsaDfvCla8Bfg06lkeUKco3W+uxXNcJCpdD tz2tGTfYS6tMSOjBOsxNUibmHzzd1kaZlMLVnGnGNEF0st80/khMhxfwPQ9BrF2tCNTf Oejw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t17si2797245oth.149.2019.12.23.16.58.51; Mon, 23 Dec 2019 16:58:51 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727031AbfLXA6t (ORCPT + 27 others); Mon, 23 Dec 2019 19:58:49 -0500 Received: from mx.socionext.com ([202.248.49.38]:23630 "EHLO mx.socionext.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726877AbfLXA6r (ORCPT ); Mon, 23 Dec 2019 19:58:47 -0500 Received: from unknown (HELO kinkan-ex.css.socionext.com) ([172.31.9.52]) by mx.socionext.com with ESMTP; 24 Dec 2019 09:58:46 +0900 Received: from mail.mfilter.local (m-filter-1 [10.213.24.61]) by kinkan-ex.css.socionext.com (Postfix) with ESMTP id 36DD018008B; Tue, 24 Dec 2019 09:58:46 +0900 (JST) Received: from 172.31.9.51 (172.31.9.51) by m-FILTER with ESMTP; Tue, 24 Dec 2019 09:59:25 +0900 Received: from plum.e01.socionext.com (unknown [10.213.132.32]) by kinkan.css.socionext.com (Postfix) with ESMTP id 04B7B1A01CF; Tue, 24 Dec 2019 09:58:46 +0900 (JST) From: Kunihiko Hayashi To: Mark Brown , linux-spi@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Masahiro Yamada , Keiji Hayashibara , Masami Hiramatsu , Jassi Brar , Kunihiko Hayashi Subject: [PATCH 1/5] spi: uniphier: Fix FIFO threshold Date: Tue, 24 Dec 2019 09:58:23 +0900 Message-Id: <1577149107-30670-2-git-send-email-hayashi.kunihiko@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1577149107-30670-1-git-send-email-hayashi.kunihiko@socionext.com> References: <1577149107-30670-1-git-send-email-hayashi.kunihiko@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rx threshold means the value to inform the receiver when the number of words in Rx FIFO is equal to or more than the value. Similarly, Tx threshold means the value to inform the sender when the number of words in Tx FIFO is equal to or less than the value. The controller triggers the driver to start the transfer. In case of Rx, the driver wants to detect that the specified number of words N are in Rx FIFO, so the value of Rx threshold should be N. In case of Tx, the driver wants to detect that the same number of spaces as Rx are in Tx FIFO, so the value of Tx threshold should be (FIFO size - N). For example, in order for the driver to receive at least 3 words from Rx FIFO, set 3 to Rx threshold. +-+-+-+-+-+-+-+-+ | | | | | |*|*|*| +-+-+-+-+-+-+-+-+ In order for the driver to send at least 3 words to Tx FIFO, because it needs at least 3 spaces, set 8(FIFO size) - 3 = 5 to Tx threshold. +-+-+-+-+-+-+-+-+ |*|*|*|*|*| | | | +-+-+-+-+-+-+-+-+ This adds new function uniphier_spi_set_fifo_threshold() to set threshold value to the register. And more, FIFO counts by 'words', so this renames 'fill_bytes' with 'fill_words', and fixes the calculation using bytes_per_words. Fixes: 37ffab817098 ("spi: uniphier: introduce polling mode") Cc: Keiji Hayashibara Signed-off-by: Kunihiko Hayashi --- drivers/spi/spi-uniphier.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) -- 2.7.4 diff --git a/drivers/spi/spi-uniphier.c b/drivers/spi/spi-uniphier.c index 47cde186..ce9b301 100644 --- a/drivers/spi/spi-uniphier.c +++ b/drivers/spi/spi-uniphier.c @@ -290,25 +290,32 @@ static void uniphier_spi_recv(struct uniphier_spi_priv *priv) } } -static void uniphier_spi_fill_tx_fifo(struct uniphier_spi_priv *priv) +static void uniphier_spi_set_fifo_threshold(struct uniphier_spi_priv *priv, + unsigned int threshold) { - unsigned int fifo_threshold, fill_bytes; u32 val; - fifo_threshold = DIV_ROUND_UP(priv->rx_bytes, - bytes_per_word(priv->bits_per_word)); - fifo_threshold = min(fifo_threshold, SSI_FIFO_DEPTH); - - fill_bytes = fifo_threshold - (priv->rx_bytes - priv->tx_bytes); - - /* set fifo threshold */ val = readl(priv->base + SSI_FC); val &= ~(SSI_FC_TXFTH_MASK | SSI_FC_RXFTH_MASK); - val |= FIELD_PREP(SSI_FC_TXFTH_MASK, fifo_threshold); - val |= FIELD_PREP(SSI_FC_RXFTH_MASK, fifo_threshold); + val |= FIELD_PREP(SSI_FC_TXFTH_MASK, SSI_FIFO_DEPTH - threshold); + val |= FIELD_PREP(SSI_FC_RXFTH_MASK, threshold); writel(val, priv->base + SSI_FC); +} + +static void uniphier_spi_fill_tx_fifo(struct uniphier_spi_priv *priv) +{ + unsigned int fifo_threshold, fill_words; + unsigned int bpw = bytes_per_word(priv->bits_per_word); + + fifo_threshold = DIV_ROUND_UP(priv->rx_bytes, bpw); + fifo_threshold = min(fifo_threshold, SSI_FIFO_DEPTH); + + uniphier_spi_set_fifo_threshold(priv, fifo_threshold); + + fill_words = fifo_threshold - + DIV_ROUND_UP(priv->rx_bytes - priv->tx_bytes, bpw); - while (fill_bytes--) + while (fill_words--) uniphier_spi_send(priv); }