From patchwork Mon Sep 30 09:30:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 13815799 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A8397CF6497 for ; Mon, 30 Sep 2024 10:04:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+X2Z1whVBmZ9pEvWhFlRrTu0QrAjM3Rhzrqj1t1T+q8=; b=JoWFJs16SDdMa6gLdsZ8PVs6AQ lhvbkchq5WuD/M1U5eWw7Dxc1NJpTsPFSvsziccPE0yaIwf1nzoZBywM9RGBXwPPbw+AHlpQ+zeZa wKRZ1lQcEP55dzG0g9m61wvE8huQ9yJH4vwLUHUZnknOtNbp6ir1crQ1WQkrKIwKBP9vf7H3NJThT 9sx2vWD7nBDexOWg70DjfC4a7ph3YT9Izk+3TaLx3eKnTK6/e5IrSO5lq790t72ZfImqKn69pIKo9 k0rR9RTzNbSq9rx5KcFfOh+rMgsLTBX0YyUDx2Z8MBtO6TPI/w1cHVaexmbszq9yP60PqUv1Mt+Lb 8FB2KYHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1svDFu-0000000Gcim-21EI; Mon, 30 Sep 2024 10:03:50 +0000 Received: from mout.gmx.net ([212.227.15.15]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1svCkJ-0000000GXBK-0Ilz for linux-arm-kernel@lists.infradead.org; Mon, 30 Sep 2024 09:31:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1727688660; x=1728293460; i=wahrenst@gmx.net; bh=+X2Z1whVBmZ9pEvWhFlRrTu0QrAjM3Rhzrqj1t1T+q8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=tb3jlyCd87yYAEpScxETYGOSM2yGriatKyogQP0FW01x5A6iIt1ZRvy4rY3C9DAG 0PyJ1gbrIICB5/reMnn46JAWyHuTSfXAXKeu1hyli3WvoM0iIFUWxfEXu7oEDlasZ AFS7X3nKBUrgBEkWi+rYBcj0huyjIEqDYMaAQ63uRzaVYQ5j05Ro8NoccATOeBp9p jxVTbTVXeVgBURp8RVhAYOuzal456DcNUnzPPyPcSwVyTh9yBDxdMYc71kddz4ipg 4E8jT6VQArve5VS/K2rPfTsQntOWhpKk+4W8nSPIMd+OiRMS40vxTDbD30tkiPiRt qdhz9PJ3rDYlt3L6HQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from stefanw-SCHENKER ([37.4.248.43]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N6siz-1rprum3YVD-013Flj; Mon, 30 Sep 2024 11:30:59 +0200 From: Stefan Wahren To: Mark Brown , Carlos Song , Frank Li , Fabio Estevam , Shawn Guo Cc: linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org, "imx @ lists . linux . dev" , Pengutronix Kernel Team , Stefan Wahren Subject: [PATCH 1/3] spi: spi-fsl-lpspi: Adjust type of scldiv Date: Mon, 30 Sep 2024 11:30:54 +0200 Message-Id: <20240930093056.93418-2-wahrenst@gmx.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930093056.93418-1-wahrenst@gmx.net> References: <20240930093056.93418-1-wahrenst@gmx.net> MIME-Version: 1.0 X-Provags-ID: V03:K1:XTojNywJficBHKynfwbKw30/3unuVt9CLczbbmmR3ph54NfvtJf w+5dnQ9VXkzW1Y2h6DI71//BvPCeNNObNLwOjRkhz7F5Oq51KpJ6wkIdAwjdtU7FanePGR9 8Qg6RQOdDTUYMHtdEmCte65yOyLtG+hdVx1NVKL1mQ/nFdOs9wLRb/X+FP7nuteI68OGWFT q9bPY1XVPjlXNz9v+j2Hw== UI-OutboundReport: notjunk:1;M01:P0:pe1o77MfILQ=;yCsSTCn15ubxI+rn0svoqKG7UkW JPyazT1iKLP3TK/kRPvV6PpLN70T4KY8GFUKpfu7JduaYNcFp5YuCfFynevlo2gPnaEAg5yGS eepeMF5pvTqxnrdCMBdYLUtP4fs6mgKKpt1E8rVCe1xrn+MN7SHj/ChjuXM+lg21AqyfXKGJx wZkn9lVf/qQuKauk8EcU7qzddtufKa0d74mtzH4fqp7IRJcCMRaIMrNYay3VxtVOzUN9KoVE9 ld0BBjG6nqnEC505IjsKCer3Tc0RYig0jlQnqgT32pYS3MGDFzNIH92N3rgkINBd9362W3jPx Au9nDQOBMSeJHfiTPBLbvC+aTily1Rru0fzyoTdBI/Qwhww4eEAYIiRslhfFifJbJ/c6ajaiK sxsPOw2z3baG9zRnuXmIJLxSAvq/qQQHPZPPq/84ftfmT7B0KvaQ2s7+RTOX8PMAMD1yEcy9a h7piqnBwS4fgovwd8F9hd9CcTD8EZlT2JUKL3qaxsTuGJc6MkxHpMsQHTlgveMwdtBIOYi7HU J8L5tGpMW/l8UMrZtiFLiUVSRD6hjb03EuWMkZYyoIAu1jq0T2tHxILHLKLmwFeM7ySexjNgO 4gFJxBNLeveT37b0qkZ01x+uNZIs34L1skFEfYSrbxH0rz8wsiPXf1y5ZZ7e5WUGebxaGSrbu TIy5LtUmWi9Nki1WTobhFKaPrCJwzYrsz8FYm38I15U7Da0Zi1kEo1VFzleI1De1hT2Zzd3qm trv2qVg60iUG1fpHJBHpXOue7CGg2wm7Msl3IoCW3mHs2IHqK3jIWMOYa5O9jdn3YazNYBX8r oS1jykeuNRCQ941z2Ft+g8MQ== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240930_023111_431265_EA43ACAE X-CRM114-Status: GOOD ( 12.38 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The target value of scldiv is just a byte, but its calculation in fsl_lpspi_set_bitrate could be negative. So use an adequate type to store the result and avoid overflows. After that this needs range check adjustments, but this should make the code less opaque. Signed-off-by: Stefan Wahren Reviewed-by: Frank Li --- drivers/spi/spi-fsl-lpspi.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- 2.34.1 diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c index 977e8b55c82b..196cc68f2057 100644 --- a/drivers/spi/spi-fsl-lpspi.c +++ b/drivers/spi/spi-fsl-lpspi.c @@ -315,9 +315,10 @@ static void fsl_lpspi_set_watermark(struct fsl_lpspi_data *fsl_lpspi) static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi) { struct lpspi_config config = fsl_lpspi->config; - unsigned int perclk_rate, scldiv, div; + unsigned int perclk_rate, div; u8 prescale_max; u8 prescale; + int scldiv; perclk_rate = clk_get_rate(fsl_lpspi->clk_per); prescale_max = fsl_lpspi->devtype_data->prescale_max; @@ -338,13 +339,13 @@ static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi) for (prescale = 0; prescale <= prescale_max; prescale++) { scldiv = div / (1 << prescale) - 2; - if (scldiv < 256) { + if (scldiv >= 0 && scldiv < 256) { fsl_lpspi->config.prescale = prescale; break; } } - if (scldiv >= 256) + if (scldiv < 0 || scldiv >= 256) return -EINVAL; writel(scldiv | (scldiv << 8) | ((scldiv >> 1) << 16), From patchwork Mon Sep 30 09:30:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 13815801 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2C3E4CF64A3 for ; Mon, 30 Sep 2024 10:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nf/ETJAt3DuB7mJlqmFgDdvAKEEogr1B0AOf7y/e70Y=; b=ljY0cZ5IFP4WhGkn2XSTrv0NZf UUEYiUkZEzastYTqkT/HHsfrMhXoBTEwZOPiZKN3N+6Sh2F1QmjyWvJKXfBcsHzLNVDB0OMR+jUcT OIRdBFcDqRGbYQXBek2LLWPC2i0pdGw1Ziz09saMxZu1RmoqSglZrk5CjHEkAzUCxV8pzRX6bDfL3 vwS7OkGgcHEEg9v8mTq2dAY7eb38SngWVEDpQs7ampmLqW6pmxqoqRKcHMY9vYI8JmVtcw9MaPf6Z Tx3piAtuwPyPJmKKkaKEiSsoIQ+xorOiUxMeNxEknBbeLSm3PLC4N1PmJzSSrkogV01Lrjkb8zGbc ni4wqyQg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1svDFv-0000000Gcj7-0fEw; Mon, 30 Sep 2024 10:03:51 +0000 Received: from mout.gmx.net ([212.227.15.19]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1svCkJ-0000000GXBQ-0qB3 for linux-arm-kernel@lists.infradead.org; Mon, 30 Sep 2024 09:31:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1727688660; x=1728293460; i=wahrenst@gmx.net; bh=nf/ETJAt3DuB7mJlqmFgDdvAKEEogr1B0AOf7y/e70Y=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=QRW6Yj6V392IjFRucn5Yfg6u8F9PnXdWnYXwF0EtLP7rbIYbCWvJFwXfjPWryaCB XGZc2ah+evSmTH979ZZcZMyaFUgcNDynMm8YiFe6qR9bBotUayYwq3wHnQp49Sovj QbMPdlsKF4/WD7Grx+kMWuNMKXYTAZYyvz4VHbiWeoV75/GtppjEPzkg3+J4YBjfZ HBV1hmgzstMgqvq92j2T6Cj2EobHyBELmqECshGQf3QT5sWcbcbFFbioANuRDkq7K rdLZXpOPsw2v9ibfV8CmhBZ6rLPB4AicZOZ93MZgeOZXwefAhI+CW+azPAOkA3OJR +zouM/P77VsHOb1hzQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from stefanw-SCHENKER ([37.4.248.43]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MGyxN-1shi5P15H9-009DCx; Mon, 30 Sep 2024 11:31:00 +0200 From: Stefan Wahren To: Mark Brown , Carlos Song , Frank Li , Fabio Estevam , Shawn Guo Cc: linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org, "imx @ lists . linux . dev" , Pengutronix Kernel Team , Stefan Wahren Subject: [PATCH 2/3] spi: spi-fsl-lpspi: Fix specifiers in fsl_lpspi_set_bitrate Date: Mon, 30 Sep 2024 11:30:55 +0200 Message-Id: <20240930093056.93418-3-wahrenst@gmx.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930093056.93418-1-wahrenst@gmx.net> References: <20240930093056.93418-1-wahrenst@gmx.net> MIME-Version: 1.0 X-Provags-ID: V03:K1:Mu3FgyTvQcc2QnI8V3TQwr1QwpUjwgUn+zEFzJ1BkyhR+70I9zb IzOyaTFeHkDMq4Keaf3uQUyFwqA3+P+YbFGsyyIljq3pnqoSJKjKCQhqaOZqIOkloT8G8Go +ErxpXgUjCormnoGhYssSPmbwIKy5HvShrjluB5GA9oA6CCmd+9xqTBssyh7+j9XdV5neEf zgeG+G1oYfNLxeB9rZAtA== UI-OutboundReport: notjunk:1;M01:P0:yQbUhS798MI=;89qMK2L5FlKSGVc1pQ0PC6RXoeo 76AMNtPnTTBfXEAqszCKxPif+QNtHKO5hHCsA+a0sof2gUIzTySRn3fRI5C9uMARP4LD9tAHi lcVmCrE/49/0nAebkUySlwDbzZayVD9/17dPVvcnoPwuth/Qx/hkx4zCaOSWqR7i9/bEtz24f nVC4sxFvRsjk3Ib58xEJ8Cb6fSEgOF6Y69j3YmiXXOCi0hkYnJaguiDBaLCI/rReCQ13AwS35 xUhSADyqR1OCl/T37TpzIY3bLATp6Tp0hNbjRmsCv4vE6AlbSawlmMi+zAVYzOMVd32hqUOyR 8nhmw5xgG5k7P8j5SnYx7vv1C9cUlCALqv4GOFPRkwz2rY2JYCR+JKR237SZs98dPLG/J8Vc5 Xj84+OhHOtg82IceojISq/IVT/joGmKYgsQMLHSn1BbBAG3PcqrynN3HWsD7lEijjEqDn0gGw ANBgEeUHlgKLxTlH549znjLtvJlBmBHiK4tT6zJLR0CDczT3yeEjJ2MWPlgbiCGYTVZc8E/X5 qhmP09BtL/dOtnBT8wcbI0s+j/FXqchGmfzSLkJcQPEzgtXvuRn9zYY89zn4KNguCaOdLbx1/ lpiCnB1nTpzKVaG5tdv76rBC8OhRXMv2yhpKoonnmrpy1rpmrjwAF4kSAedeM3KtHjG0oA+De Xhi/jbNm0kExnBmn0uZ2Iqk8QwdtfnU7vShiVTFLCP7Bb2sYaXvCX4P9AxktmCKJVtSmQlBOP Ycu6aRxPkgWQ1rllYNSWy8weBESpbkgpzSQxky2sjqSkNhE4hHXwxVnT1icIgJwML30YA/SFn 0Imbi2/WYn//iOHcWex/Dyyw== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240930_023111_590775_738C6654 X-CRM114-Status: GOOD ( 10.60 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Most of the parameters are unsigned, so fix the used format specifiers in the debug message in fsl_lpspi_set_bitrate. Signed-off-by: Stefan Wahren Reviewed-by: Frank Li --- drivers/spi/spi-fsl-lpspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.34.1 diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c index 196cc68f2057..3b5aa91079ae 100644 --- a/drivers/spi/spi-fsl-lpspi.c +++ b/drivers/spi/spi-fsl-lpspi.c @@ -351,7 +351,7 @@ static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi) writel(scldiv | (scldiv << 8) | ((scldiv >> 1) << 16), fsl_lpspi->base + IMX7ULP_CCR); - dev_dbg(fsl_lpspi->dev, "perclk=%d, speed=%d, prescale=%d, scldiv=%d\n", + dev_dbg(fsl_lpspi->dev, "perclk=%u, speed=%u, prescale=%u, scldiv=%d\n", perclk_rate, config.speed_hz, prescale, scldiv); return 0; From patchwork Mon Sep 30 09:30:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 13815800 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 08E67CF64A0 for ; Mon, 30 Sep 2024 10:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=sY+L5lzlsetMV2bHl+NCJRDblGupsZADF4yHxFO+I+k=; b=qPTQ/1j8OLXvSS+xp/tLk6W/gZ XPjjLh2zRsGv3FHlpiNdpusXV9jgNa7ilZY5A3keO76/rKvcEZmsS74dpmKjH2Dy29eCdXiDicAET XJK37DMLZ0+eNqExi4bb2RLOVxupiWW+ILxkrxcBIFo4BmU1FreJnxnMG29mXV+jyRzRzGEAymh02 egxBLh+I5zG2qNe1pRhA3FJDPRB7c3Wk+C4zOYlTPvZNJ/NoMEbkae4ufHXI396c1K2BynS7uzyD5 SMMoRGER5knOC/4k/KcGmYMHl4cIaH5rgaTvWu6saAlf5c7lBLXzyWelgdpQstEYTcQ5UvEY4Kr1A M5+mnkkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1svDFt-0000000Gci2-2HhA; Mon, 30 Sep 2024 10:03:49 +0000 Received: from mout.gmx.net ([212.227.15.19]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1svCkI-0000000GXBD-3SSr for linux-arm-kernel@lists.infradead.org; Mon, 30 Sep 2024 09:31:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1727688660; x=1728293460; i=wahrenst@gmx.net; bh=sY+L5lzlsetMV2bHl+NCJRDblGupsZADF4yHxFO+I+k=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=oVdY7dwc9BLzk7RYbS36Vf+WD3fXEDR3XJNzqjkgPUtruZVRD0H0v6WK+vphbbAR GY4rjbChmACypZ2cvS7mSLUtsD0SCQDtcEf0/+oKZAW9jQNc3RLp/BrqPsIRN3zAG b33AvdkCSfE6C0ozw9/OiqCDRtRArZDRjhFocoNO/Om8K6aYKJy7UsfS0cPxf7/iU hFR01mD+ozQxjHlHp/mmWl+cvUvGVskNpiM5kHJ79WHV0DUuc3OIZhdApWR+yWpVn 804GtwmgHNTRYdiA11PR1gdNOUH6npzns6abdYFRag6ayWivVjbOtFzZETZ+inps8 d0c/XQRCjE6KRbEb5g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from stefanw-SCHENKER ([37.4.248.43]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N2E1M-1rtyeY2v8g-017OVO; Mon, 30 Sep 2024 11:31:00 +0200 From: Stefan Wahren To: Mark Brown , Carlos Song , Frank Li , Fabio Estevam , Shawn Guo Cc: linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org, "imx @ lists . linux . dev" , Pengutronix Kernel Team , Stefan Wahren Subject: [PATCH 3/3] spi: spi-fsl-lpspi: support effective_speed_hz Date: Mon, 30 Sep 2024 11:30:56 +0200 Message-Id: <20240930093056.93418-4-wahrenst@gmx.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930093056.93418-1-wahrenst@gmx.net> References: <20240930093056.93418-1-wahrenst@gmx.net> MIME-Version: 1.0 X-Provags-ID: V03:K1:FGHoyPznj8FacNxU9Nu//r0ysWw9iHPsxi0c3fBlj0Cz9lMJNh+ PYX5XAYLoSsKGGlI78Q3llcgWUBWIsDOfEVF7KNQ2/0BrsUD2KxabzALkj2gafXB4qFbdRH N/MfD9trPE04d5t0918vJU6STOvNbzVMcMcNLzDQQ+h4/XEF4twWMkTO8QnaAm5IYDdgNLZ Ii4jrq8rLjaAKebngs6WA== UI-OutboundReport: notjunk:1;M01:P0:MV8S/9v7k0k=;0bCwECx6vZKE15FgPUKn8Y/HMqw tWsMTaIKHY3bOxjsHcmzDDvI/qsJTqinUB+bnRXr1xk55/LlTr9SfpH4UF32yjEFPJIlFtpq5 5aNKG0mhtKpudyXPVqISpjRHpP8cPo0KV0gk/oPWgURNdkV1l9ZDw9Z9W5DGqtFepxJIOcXqv /KfGhKWj2aL6e+4ZRlg2C+iJhM+3iEgCIp3wiOjZnXqbnIAP1vNNXx8ZWvlnwkjUisf4kgA+g LTPBag83S6Ng35/eHjH4u3Ew6D8lrH8FspobOevgE89dnq+CNHbV6MV5vXdvTmtBWH1yGSC2s B7oS1GgdVMlb38/KAB8BaNC30ppFyD51+P+OY+8f74EqZmS6fI6zIsY982kUpGXjpCLWQt1qB R4Y3rQFXqenT9iQnM2Sfz+eva08wE6XMeF4uT/5AQtOjhdY++3IjBZeI/5titnDfe6mARUG8o m5F/KTZhXGfkhnQqi0Le9W4D6ULsZixPCa3NOSsSYAlGZEtOfFz8XiejoWE/REbNsFoBvEhta RAMRhN9C0GaMxdpLOXYrwKs5VrEeGDKA4ZtOJMuOdOVYQrEOds7tmqZkBrEaEgw96cG9gx45D TsJADn1abZRFSWfyaqp3IW4MfKiO5F6EymRj9tfhH3P4RbOKE1w2QBEzpNFMiBc8wELmyUdWb uPyZFU2O6gUqLMhNONa5jeugCF/ZhZm7+qyff8AqWCKCvanSfmBhmWoiEpqmko3rkRZFqw3Q3 QzzyoPq8j7abWKn4kH2fDw/ZWEcb3vN5fjMlChfzuRlTQzcbkjZC+W2h+aJgbTHPdHYEREKYC ulJbxMk8eyGNeqTD1BrzwHLA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240930_023111_169128_CD7AC1EB X-CRM114-Status: GOOD ( 10.08 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Setting spi_transfer->effective_speed_hz in transfer_one so that SPI client driver can use it. Signed-off-by: Stefan Wahren Reviewed-by: Frank Li --- drivers/spi/spi-fsl-lpspi.c | 6 ++++++ 1 file changed, 6 insertions(+) -- 2.34.1 diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c index 3b5aa91079ae..5d55ef4d4ba6 100644 --- a/drivers/spi/spi-fsl-lpspi.c +++ b/drivers/spi/spi-fsl-lpspi.c @@ -92,6 +92,7 @@ struct lpspi_config { u8 prescale; u16 mode; u32 speed_hz; + u32 effective_speed_hz; }; struct fsl_lpspi_data { @@ -351,6 +352,9 @@ static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi) writel(scldiv | (scldiv << 8) | ((scldiv >> 1) << 16), fsl_lpspi->base + IMX7ULP_CCR); + fsl_lpspi->config.effective_speed_hz = perclk_rate / (scldiv + 2) * + (1 << prescale); + dev_dbg(fsl_lpspi->dev, "perclk=%u, speed=%u, prescale=%u, scldiv=%d\n", perclk_rate, config.speed_hz, prescale, scldiv); @@ -750,6 +754,8 @@ static int fsl_lpspi_transfer_one(struct spi_controller *controller, if (ret < 0) return ret; + t->effective_speed_hz = fsl_lpspi->config.effective_speed_hz; + fsl_lpspi_set_cmd(fsl_lpspi); fsl_lpspi->is_first_byte = false;