From patchwork Mon Dec 4 17:33:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 173476 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2921853vqy; Mon, 4 Dec 2023 09:36:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IEFFIWRWZsCvGaGISbtyq4q25tHn9MZ4N10STs7KP90hecSVCxZ+RNYws1uQpJqj6+VGQlb X-Received: by 2002:a17:90b:2248:b0:286:a6bf:2a16 with SMTP id hk8-20020a17090b224800b00286a6bf2a16mr1700993pjb.51.1701711360836; Mon, 04 Dec 2023 09:36:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701711360; cv=none; d=google.com; s=arc-20160816; b=HjnklGReG2nC8j5UFCHvt0K7Wc5i0j155GlXpAts+OK8dif9lJYC5kUz7Evvl44FtK BvIRGhQwFJRvAlAeYjit8bkUTFXJea1+OzF8Z5UlHeAqS9XXnxtV/GJS2fMmNZZcZ02w X7C3w6zR4b7IJz0znSJnQcATpc3vQ7HdS4l6NZXvm0Fxr5iroyRwffM47I7yhWsZDMo5 Z3rfb7f2ogutcyDjvu3EmmYhstiFUv8pOsnn5TE4uC7zTDq/Lqi0vl7aXAsv1hWWE9E6 Qbam70X1ebXKHbYnfQXB89P15iA7x6tsTnvlMZh0VQe4twoDaNTzYTceIgJL6WoVFgT8 XSiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=98OsS81iJjdYUrIfnnQHE8YiK9lvPvbcglqw48PfjFs=; fh=0wGMUdoh1UE04GpAJkixe4SLWCT2iowob+poRBItjRU=; b=IJawNlEzYXEDlueuPDQVeWWoo3ZoHUOKvjtEmgHiaGuaemqsCLr5wF/pIIjkaPRsAU GTufZ0Q6Z6Nk50u2z1jenyCDh2HDr8ULZiNE3bUpUHcGy/V2RJxftno+0iMmUZILFaWv 73X+ws2ml3XaUVPR9XnY6vSgGtYfzuanMrdVloPAu3eT96G7dLsHAdYzt7EBLzW3XfqP sQ3hvouybQXTr78OKr/OKn9AdznwUD9rdjBVwQWH9ShZKTlrWH9ebCGkB6WYcBsxd+n9 H0ebCyzYBMU8jjWwqGjCif3hAmyi5pudl5A+UYuJhO3BRpZV1D2v6jK/xSDrJqjAGthy XGEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=Vf2jlxV2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id w10-20020a170902a70a00b001b973681493si7805749plq.16.2023.12.04.09.35.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:36:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=Vf2jlxV2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 8DD9F8058C7E; Mon, 4 Dec 2023 09:35:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233279AbjLDRfO (ORCPT + 99 others); Mon, 4 Dec 2023 12:35:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234951AbjLDRfE (ORCPT ); Mon, 4 Dec 2023 12:35:04 -0500 Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E9A9187 for ; Mon, 4 Dec 2023 09:35:10 -0800 (PST) Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3b84402923fso1176185b6e.0 for ; Mon, 04 Dec 2023 09:35:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1701711309; x=1702316109; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=98OsS81iJjdYUrIfnnQHE8YiK9lvPvbcglqw48PfjFs=; b=Vf2jlxV2tdLEracv5icB41+YhoaMg0csMVqjjn5oCpubGiykjPXSNUSUbLnIC+DnGQ PQ/bxseS8omyABCSKDikrlQsfJIlrAzo88/pAbcBhEA454UU5yXlnjGdXPjghraLfUD3 xphSQPyEyO1HwRtvXFsl2xbjqp/vKbkpTGZmmcOS97iifeIVEfGrYNnR3w2/R7u2hwei N25dc4Vckh2E5jnrJPFN/rGyA76t71XNnLhQ7pwfZ/I8DLz+WPkliDKUh8119PYG/kja yx4lrdZKA8ZDTfntdE5EnshHQ2a/i1y2sCqzUYH3vVX0+OyS3Pa6wOpC3n/Qqu2Ofu5Q y1Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701711309; x=1702316109; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=98OsS81iJjdYUrIfnnQHE8YiK9lvPvbcglqw48PfjFs=; b=Ms9SHV+PGw8yLhOe9yNOmuyaZ8nt28wu7mWhFVIIkULwN/g6L8lcY1gMQ8OV2lOnBk rIS26Zi2Y9mjaaUaIL/16lAIOj4bbqtxK3iCmnexc2uU+0aC9jsYYZuFdnqRrm4tSORJ 2DThqfQVrPDn+c94RDnktzUFOguTJikz9v7k/Q/2+wNCMmB1ZWp0h8HOn8nO7K5b1VU5 UWXnTQsZ6rRmW099THkiwpgmcU7eDNFz4fnVENU3K320CME+T4I54ZZoNAMTaw6KwYIj yrffKvmeTmMIdckYUutqAhfj+yJLosFK1MPI5UqQT+aZtZc7EeMFo8Dtd7qcvt+dFNTA TqPw== X-Gm-Message-State: AOJu0Yz9UbgJsPNoI2h1+KGtM3lq76m07GKvg7iQWwDMBBKl0Dry2qwR eS5zXXQZ0k6Gbmz8CbuE/Icoig== X-Received: by 2002:a9d:6e0f:0:b0:6d9:aac1:228 with SMTP id e15-20020a9d6e0f000000b006d9aac10228mr767563otr.40.1701711309599; Mon, 04 Dec 2023 09:35:09 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id b16-20020a9d5d10000000b006ce2fce83cbsm1956563oti.25.2023.12.04.09.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:35:09 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org Cc: David Lechner , Mark Brown , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , linux-kernel@vger.kernel.org Subject: [PATCH 1/9] spi: axi-spi-engine: return void from spi_engine_compile_message() Date: Mon, 4 Dec 2023 11:33:27 -0600 Message-ID: <20231204-axi-spi-engine-series-2-v1-1-063672323fce@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> References: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 04 Dec 2023 09:35:39 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784373692061569758 X-GMAIL-MSGID: 1784373692061569758 In the AXI SPI Engine driver, the spi_engine_compile_message() function does not return any error and none of the callers check the return value. So we can change the return type to void and drop the return 0. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index cbca783830ea..982b37ac3063 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -218,7 +218,7 @@ static void spi_engine_gen_cs(struct spi_engine_program *p, bool dry, spi_engine_program_add_cmd(p, dry, SPI_ENGINE_CMD_ASSERT(1, mask)); } -static int spi_engine_compile_message(struct spi_engine *spi_engine, +static void spi_engine_compile_message(struct spi_engine *spi_engine, struct spi_message *msg, bool dry, struct spi_engine_program *p) { struct spi_device *spi = msg->spi; @@ -273,8 +273,6 @@ static int spi_engine_compile_message(struct spi_engine *spi_engine, if (!keep_cs) spi_engine_gen_cs(p, dry, spi, false); - - return 0; } static void spi_engine_xfer_next(struct spi_message *msg, From patchwork Mon Dec 4 17:33:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 173475 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2921844vqy; Mon, 4 Dec 2023 09:36:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6LCeclzpv9watHoHJu8wYSXQ4RZR+ifxDjBNyTgHuB1/fdJZdsJbJgqlL5jMRkCU5YjJB X-Received: by 2002:a05:6a00:1bcc:b0:6ce:51b7:827c with SMTP id o12-20020a056a001bcc00b006ce51b7827cmr1188546pfw.22.1701711360828; Mon, 04 Dec 2023 09:36:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701711360; cv=none; d=google.com; s=arc-20160816; b=p7B2n7wAvrt5tiN0rXQXiDrKKXAl7D/7UHIgV1afRMfpX9ZPsH3biwM4BJvNi8eJF/ M9qlbWo+/s6b3DD6VYZacKF6gy1JQ/sDQiCdpr0jaI7BgSl9ev10qeDwti2f8paNTxkT sAbny8HfJbZS5Sn1xwi4q1Mpc34seRYCcixiE9yPDFXm/7MLgYrGq+r3sBW4j3Pna5ve DfdtoMDzB/lsqqLvY7oTYbw0Rqs6XlavOFPuGPPUN+HQHkdQcL4idLiSyxIxD0NN1Bkh V18G0WACV0HUB7/SxuBaFvC2worNvhU5FbLUWqHp2hdgz2adTQfSJuFX7tiry7WGUgWq q+fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8pv0Sz4KzlNYFahpj8BH/nxYNAhJ9uRGvkVtUS8FW+4=; fh=0wGMUdoh1UE04GpAJkixe4SLWCT2iowob+poRBItjRU=; b=jZkB+4cFspe83WwjYDNgV+AcHppqhyfIBszR143HXtCkgexJxbwTzojh3zcF2FOp1k qTV6CZ9IzETJtEcFQswgp8tL4KYQ7pDgQNrPCYWxGZt2kg+HD7010K4x+gT/GX1JBgVR mjKyzkp6TLcz/73qjtWDu55rMXbYQ/OIbRMLymjHe+NqEtQpENmZkvzH3KT09z8w++ko W+VKVMOMxNGjhS3vglVWZGeimPgfDDQ150ANPdgagkrE+bpzFH3G2JJ3PmgqCqKK60qj EGgoJAi26cL/OcE5bCGq2Amt3MwxQbztiHAhkbkbxqxwXzpXBX+AIxVMVcxJ8i6OC1d7 QK0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=JKwKrQyM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id h18-20020a056a00231200b0069347c30c78si8234557pfh.230.2023.12.04.09.36.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:36:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=JKwKrQyM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 2615B807B4A4; Mon, 4 Dec 2023 09:35:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235387AbjLDRfS (ORCPT + 99 others); Mon, 4 Dec 2023 12:35:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234968AbjLDRfG (ORCPT ); Mon, 4 Dec 2023 12:35:06 -0500 Received: from mail-oa1-x29.google.com (mail-oa1-x29.google.com [IPv6:2001:4860:4864:20::29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88BF3F3 for ; Mon, 4 Dec 2023 09:35:12 -0800 (PST) Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-1fb4ee3d548so395449fac.2 for ; Mon, 04 Dec 2023 09:35:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1701711311; x=1702316111; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8pv0Sz4KzlNYFahpj8BH/nxYNAhJ9uRGvkVtUS8FW+4=; b=JKwKrQyMs7k+9dJbDSGFVF7laLzGFiSRETaDr4sgOdJGIrLAu+CZODG2BlGyis0qyc s8/Gv14hOjBDqwpJigMXJ1Z0F8kDORBUBwDTefZ3KuX1nX4btCFaVVq969lOr3XQrmw+ q+0Qafi7I+ANip73ythSvYc1HZPIKjWkQyOI5DiNmxjgXtTkebbGgrmHX5VhdHsT8mC/ xWf+HVzTCgbtUSWtTI3EPnsvqERxMlgm1Pc5GGU2EUSEubZits7gDrZ8ftKFcrj/yphY 0tSbl8hhB5DOxr9JARiE0vbvMrQLOKA49w+arxEM5ScBqwRJRkC59kcebI/6CSpUBfYr B0RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701711311; x=1702316111; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8pv0Sz4KzlNYFahpj8BH/nxYNAhJ9uRGvkVtUS8FW+4=; b=qr65O4PpUFEpT0tw7kNTbvP/9KjsOV0Ih8+sun2cryy095kN04eTya74NBqpV0JXrK rqCzPnxjVdm0eAJzLQJWx/oT2Egwpq2+B5WR3NOTHNZdP8KMLl9u6Ca7zagzI/NUq49U 8fcQ3rfc+KuZns3AmmJT2oNuXLOTQN1Sr5MfAwNCIT305O6Fog28K2eBDO3xm4tZ5w6C X5TrwBGz1nTKl5E1VMVbv9QC/M52AEyV9qTtKfEsP3suHQXEQyVp7qYhJm3XsNw+ewZC AjfFyg4q7QJjh7did6V1BLq64cHMyVIrSBzJwzG47/fLYO7ANymD7VVxFKDzWI32YOWo U28Q== X-Gm-Message-State: AOJu0Yz0idn9phTrth2UnAYAEmLTMOHJi/pKyvz61qMzlZHBQqxt0gsq p35/yln7QvSCyxcVjWY6LaDdyw== X-Received: by 2002:a05:6871:54b:b0:1fb:75a:de7d with SMTP id t11-20020a056871054b00b001fb075ade7dmr5558431oal.107.1701711311231; Mon, 04 Dec 2023 09:35:11 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id b16-20020a9d5d10000000b006ce2fce83cbsm1956563oti.25.2023.12.04.09.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:35:10 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org Cc: David Lechner , Mark Brown , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , linux-kernel@vger.kernel.org Subject: [PATCH 2/9] spi: axi-spi-engine: populate xfer->effective_speed_hz Date: Mon, 4 Dec 2023 11:33:28 -0600 Message-ID: <20231204-axi-spi-engine-series-2-v1-2-063672323fce@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> References: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 04 Dec 2023 09:35:43 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784373691640036043 X-GMAIL-MSGID: 1784373691640036043 This adds a new spi_engine_precompile_message() function to the ADI AXI SPI Engine driver to populate the xfer->effective_speed_hz field since the SPI core doesn't/can't do this for us. This driver is already using spi_delay_to_ns() which depends on effective_speed_hz to get an accurate value in some cases. Having an effective_speed_hz value can also be used in future changes to simplify other code. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 982b37ac3063..ee7b904ae5cf 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -218,6 +218,27 @@ static void spi_engine_gen_cs(struct spi_engine_program *p, bool dry, spi_engine_program_add_cmd(p, dry, SPI_ENGINE_CMD_ASSERT(1, mask)); } +/* + * Performs precompile steps on the message. + * + * The SPI core does most of the message/transfer validation and filling in + * fields for us via __spi_validate(). This fixes up anything remaining not + * done there. + * + * NB: This is separate from spi_engine_compile_message() because the latter + * is called twice and would otherwise result in double-evaluation. + */ +static void spi_engine_precompile_message(struct spi_message *msg) +{ + unsigned int clk_div, max_hz = msg->spi->controller->max_speed_hz; + struct spi_transfer *xfer; + + list_for_each_entry(xfer, &msg->transfers, transfer_list) { + clk_div = DIV_ROUND_UP(max_hz, xfer->speed_hz); + xfer->effective_speed_hz = max_hz / min(clk_div, 256U); + } +} + static void spi_engine_compile_message(struct spi_engine *spi_engine, struct spi_message *msg, bool dry, struct spi_engine_program *p) { @@ -504,6 +525,8 @@ static int spi_engine_prepare_message(struct spi_controller *host, if (!st) return -ENOMEM; + spi_engine_precompile_message(msg); + p_dry.length = 0; spi_engine_compile_message(spi_engine, msg, true, &p_dry); From patchwork Mon Dec 4 17:33:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 173480 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2922012vqy; Mon, 4 Dec 2023 09:36:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEC8BJsNVOEOQwCUrYIZX09y2ROCz9U6iQJQQxMbMMcwVMZw+LtYNcUEc0YTr9zazzedfDg X-Received: by 2002:a05:6a00:1da4:b0:6ce:3835:812c with SMTP id z36-20020a056a001da400b006ce3835812cmr4057843pfw.65.1701711377983; Mon, 04 Dec 2023 09:36:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701711377; cv=none; d=google.com; s=arc-20160816; b=cOL/MDnXpguzcP5kEJ4D2OL/pXDfOqJIOqCsrknkJF3b/uQyzm+PrmzV65gFvAyXnI k6S5tffZdLNTkZ74jGbQcelQ/Dkrtmp+pRhf9aJSLw326a0uth/iP0y98Xs3tOZmbUda zhj1xtB/mUA+xM1MyjzzwS01CEeCo4/jiaGM5Gi11BmgIJYx//OX6j/Zm42aPc4c2Q37 wLnfydXNO1PKanjwDaEISfPWzvAs1GiZrpEkxOSa2gsOoQh401exS8Mx7hX4jxhwEPy1 PFk4KqCx9iHUkDABlDvnKAxXPZSmkpR7ZYTPQq381BshRCsIA27qlxhLTs3pRyTtNGF5 iy/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Kupm0qr6Q3RnoGuZ1Z7nDXeRsP45pYQV7G5LGdS88ts=; fh=0wGMUdoh1UE04GpAJkixe4SLWCT2iowob+poRBItjRU=; b=WjqaBK7z1h704bb43qqFyOuNflXexEp6PoKD7x3ZJ64nQDwzujtzAA4cWgJ2HiNSBU NAmRnEsumEPH/6Z1JcTT2bMno5ohIddtZpqRS85epj3iZPANSMNrU3nXjmKlpb0z/zz9 gLZtcrTV8363PzkNeQGA8WVCSfObdOWc0KsuR0a70OxnrtaA8V8V5av471ZfSNODr7pr /X0/sfwLhPhcPtpRfYLTiRbi3fRint93dexdImjMbyTyh+xp3NFN3cLNOqdkVK2TvmqC AztyryjY31Z1Upkqsiywk+sdH8g9kYgZHn0g0oLLiDMCC5L7vaxkAzuaGin5KCusrEgR jeag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=AUr+6Gr7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id fd6-20020a056a002e8600b006cd8db77f84si8141420pfb.274.2023.12.04.09.36.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:36:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=AUr+6Gr7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 32AEF80779B7; Mon, 4 Dec 2023 09:35:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235419AbjLDRfV (ORCPT + 99 others); Mon, 4 Dec 2023 12:35:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235350AbjLDRfG (ORCPT ); Mon, 4 Dec 2023 12:35:06 -0500 Received: from mail-oo1-xc2a.google.com (mail-oo1-xc2a.google.com [IPv6:2607:f8b0:4864:20::c2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50D2DCB for ; Mon, 4 Dec 2023 09:35:13 -0800 (PST) Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-58ceab7daddso1902685eaf.3 for ; Mon, 04 Dec 2023 09:35:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1701711312; x=1702316112; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Kupm0qr6Q3RnoGuZ1Z7nDXeRsP45pYQV7G5LGdS88ts=; b=AUr+6Gr7b5rgwTUziaNJyXuBJ5EdLiWL8AURdHFIv0z7wJfZW8l2HXkvUfohY1Ukjn wiQO2cQwEtk37GIXazHMawZsHVlVq3gEv1RzzQH7PzPsylco1o58QmjKRUQzHes3A4er /6A1w9l5v3wzznMUXVvmwXE4posmak1f3MDfVCKDqJlYMcGXt/qjClBaHMdCO6coA5RA pO+QlgIdNkUERrqqQ9OsTjVIvIhT3nDl1KtZrlOcxSG+HOULyTGSj+u8Dxh4bXDISTRU SAv5qGJUHhvT4lgAVTzl8pgSRcbI5VxllLEqmazRF9TFEfIc70QTheWyDsI2qB4RMqt0 sJIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701711312; x=1702316112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Kupm0qr6Q3RnoGuZ1Z7nDXeRsP45pYQV7G5LGdS88ts=; b=UVeRZy9DQut36Awc+dP8iLH0gar2+CXP4R0kJ3RxxSDpqbDGJfy4jh8U+wl8RwbyKa Mo9S9/LnCfWCg/m2JkMuT7C2rc1PPCASHrrApPS5hU4wHrJJYH0Q+/X5RczXrwGUHQXL wgjluW9UHpFsM4mgFVceMaVn/3cE+S83X3hSDdvbOaWNqOMWDWTu0/1G/KQL0L7a0oDy p+KvV6XlcmdscCEN/aNohHHY7hCkGt6wSwsYhOhn4YA1qR+luitNvKuPrvMvPaidw2fX NY0XXKfUvY8bNzYpgcbHLGp3PU5tzeXvD5JTyzmhF4zM7Rliw2WeYVeOvkWSLEbSjaRS aXyQ== X-Gm-Message-State: AOJu0YzbbmGuc9aVuFPdsqmE7nTMnhSL+n8m0Gp84Tzr5FWUv33hg/gW 41Ld9qni0cqEZV3dI1qABDyNfL3emwLieUci74E= X-Received: by 2002:a05:6820:2214:b0:58e:4c67:f35 with SMTP id cj20-20020a056820221400b0058e4c670f35mr2028968oob.0.1701711312694; Mon, 04 Dec 2023 09:35:12 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id b16-20020a9d5d10000000b006ce2fce83cbsm1956563oti.25.2023.12.04.09.35.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:35:12 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org Cc: David Lechner , Mark Brown , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , linux-kernel@vger.kernel.org Subject: [PATCH 3/9] spi: axi-spi-engine: remove spi_engine_get_clk_div() Date: Mon, 4 Dec 2023 11:33:29 -0600 Message-ID: <20231204-axi-spi-engine-series-2-v1-3-063672323fce@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> References: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 09:35:51 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784373710309078544 X-GMAIL-MSGID: 1784373710309078544 Now that host->max_speed_hz and xfer->effective_speed_hz are properly set, we can use them instead of having to do more complex calculations to get the clock divider for each transfer. This removes the spi_engine_get_clk_div() function and replaces it with just dividing the two clock rates. Since the hardware register value is the divider minus one, we need to subtract one. Subtracting one was previously done in the spi_engine_get_clk_div() function. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index ee7b904ae5cf..fa2264d630c3 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -140,21 +140,6 @@ static unsigned int spi_engine_get_config(struct spi_device *spi) return config; } -static unsigned int spi_engine_get_clk_div(struct spi_engine *spi_engine, - struct spi_device *spi, struct spi_transfer *xfer) -{ - unsigned int clk_div; - - clk_div = DIV_ROUND_UP(clk_get_rate(spi_engine->ref_clk), - xfer->speed_hz * 2); - if (clk_div > 255) - clk_div = 255; - else if (clk_div > 0) - clk_div -= 1; - - return clk_div; -} - static void spi_engine_gen_xfer(struct spi_engine_program *p, bool dry, struct spi_transfer *xfer) { @@ -243,6 +228,7 @@ static void spi_engine_compile_message(struct spi_engine *spi_engine, struct spi_message *msg, bool dry, struct spi_engine_program *p) { struct spi_device *spi = msg->spi; + struct spi_controller *host = spi->controller; struct spi_transfer *xfer; int clk_div, new_clk_div; bool keep_cs = false; @@ -258,12 +244,13 @@ static void spi_engine_compile_message(struct spi_engine *spi_engine, spi_engine_gen_cs(p, dry, spi, !xfer->cs_off); list_for_each_entry(xfer, &msg->transfers, transfer_list) { - new_clk_div = spi_engine_get_clk_div(spi_engine, spi, xfer); + new_clk_div = host->max_speed_hz / xfer->effective_speed_hz; if (new_clk_div != clk_div) { clk_div = new_clk_div; + /* actual divider used is register value + 1 */ spi_engine_program_add_cmd(p, dry, SPI_ENGINE_CMD_WRITE(SPI_ENGINE_CMD_REG_CLK_DIV, - clk_div)); + clk_div - 1)); } if (bits_per_word != xfer->bits_per_word) { @@ -274,7 +261,7 @@ static void spi_engine_compile_message(struct spi_engine *spi_engine, } spi_engine_gen_xfer(p, dry, xfer); - spi_engine_gen_sleep(p, dry, spi_engine, clk_div, xfer); + spi_engine_gen_sleep(p, dry, spi_engine, clk_div - 1, xfer); if (xfer->cs_change) { if (list_is_last(&xfer->transfer_list, &msg->transfers)) { From patchwork Mon Dec 4 17:33:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 173474 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2921807vqy; Mon, 4 Dec 2023 09:35:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJROPii1F3vMcEFp6VPcqszM7kh1AiWup53MkvxKvzYS8kLJg41ujJpDckiDrhm3LpKQZ3 X-Received: by 2002:a17:903:234f:b0:1d0:b789:d7b8 with SMTP id c15-20020a170903234f00b001d0b789d7b8mr888879plh.9.1701711356220; Mon, 04 Dec 2023 09:35:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701711356; cv=none; d=google.com; s=arc-20160816; b=Qg/UNZNr0uFVAEGGmMUnvyG/dz2ny0xjQTJFZa3+njb/P7oXlGSaDJr0mHM/x7HfUU mMtyIGHe+if6R0VEZK9H8pIm1oc4ZV/hMoQ6Sm67PMCJPpOP096zLloXqDKXZusyxykc wYKKDdoTLJBzfSSFAN794LLCilhyn2DSk3291eNbodha3ypBkEseQHtZS51j2OUWXxJZ 2NHTi5he7hsBIP9dyPb6LXAeII+oVqTIBxREZU6MjQXFtxqGWoCm7VSmE7kHPT9jEUTo xqcjG7/cJ9L7bMF4OjNdn2fAws7Zkt6SlZhaRaxPDJmw3I4DoytytbNDZTz5hSUa9ZIz AZpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3vE/Lazu2cf7B6o5i/hH3jypTqxe96xetp8QoO+SVLg=; fh=0wGMUdoh1UE04GpAJkixe4SLWCT2iowob+poRBItjRU=; b=to/m2rrVVfvH2lCIrGxvp9+jMtpZK54P1WtXTwoCMlxf7fW76esJ8jcp0n/lKs7AHx QMQsHoHJbvQjR5ZMegjO9oPmHJfo3+tQUMvST/TfzzvBQhG9al9YwxyLMXxV2nyxGLfq VgIME4bGHkw6MRzbQAch8Bs+iUtm8Eq0lVZQvQBXYr4Dx8KwfP/jH2Jc1ljnAVJiJdZC SFY1AoTq08Yr3GqQAf5tcQdWSvhPTXizF3TuhdJUOr/I4Eo/8i03ahgGZZfWoYiFO1Wa MulEWb0Mx2SzedPQkNuoLaAvW0LiOAUf93DW82Ny3yX5JKLcK9Z52pcL1UhwE4trkC9E bAhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=ajV2BD1J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id d20-20020a170902729400b001d08f22907dsi2705439pll.572.2023.12.04.09.35.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:35:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=ajV2BD1J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 4B91180966DD; Mon, 4 Dec 2023 09:35:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235440AbjLDRfY (ORCPT + 99 others); Mon, 4 Dec 2023 12:35:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230436AbjLDRfI (ORCPT ); Mon, 4 Dec 2023 12:35:08 -0500 Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACCB1D7 for ; Mon, 4 Dec 2023 09:35:14 -0800 (PST) Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6d8d28e4bbeso1175985a34.3 for ; Mon, 04 Dec 2023 09:35:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1701711314; x=1702316114; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3vE/Lazu2cf7B6o5i/hH3jypTqxe96xetp8QoO+SVLg=; b=ajV2BD1J/1CO3IP+n6TS34r5UbBoG50J9ZMMYgOmG320efWcd7mb1WM9Qwf8wc6Dt7 zEp3PQmVBD8T1H72lZtn0IwWIHZZKjGjWU1h+GUj9LNHmXv0wLSIVrLMhlTPpBD+T5Ay D6kiEzVKA9w6yd+qIY57Fo64JUqkIIW2xFxmiH+4FagfSI4Fz6a0dIhXcCayd7xnHzv8 FQScbKw6q7FNYX6AiH3EiLtomSnDJfjNLb3ik7DC8t+77yAJ3O7nC6ICm/HHSaNe+MZs v5r01R1UKQDSd7zxi111kvLzh6AIj9gnhHjkxs6dwqXApi2qpbxRKGFuJlPsQFiAz/rw EVQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701711314; x=1702316114; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3vE/Lazu2cf7B6o5i/hH3jypTqxe96xetp8QoO+SVLg=; b=n/2dQQEPNbmT5nvYG2m1I8EFu8dnXOous5BK8EPjNdS4l1Nvcj7NL3HswfmhZBQdHC kuiTKf/hEifT9W1ha5G4LAk7Ka9ZQVQ2WbH/7JIq1426TCVhyw+4bxe2WA+qvQTtZKzA A0cqngAwgTK2dNEbX96Nf9YSX6fhM0BjO/dTF4BIX4jV9Y8vSrqsji7b8gb18uIEoFcs zYgoHCTrchTwPgu3y/MySpuB//GNn/GIIBXUrZWS//Yofe0Uv3rLwDFwI6qohKApv0m6 qQXrOKVU5JhYHZhgukyg7hOnf4A3HTNHdVcApwIjg97XsPRWXioxwxxY4rjduk63Vnwi sjHQ== X-Gm-Message-State: AOJu0Yy0RQ8ACsOPCAgF8CWnSsd+dryoiJHwUko7eTTBJRK6RiQv9RMt fFGjSVzY9/5V58uxR9OO/MbeEvs3HXzgqxOc7CM= X-Received: by 2002:a9d:4b1a:0:b0:6d9:76cd:d6b8 with SMTP id q26-20020a9d4b1a000000b006d976cdd6b8mr2118498otf.68.1701711314085; Mon, 04 Dec 2023 09:35:14 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id b16-20020a9d5d10000000b006ce2fce83cbsm1956563oti.25.2023.12.04.09.35.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:35:13 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org Cc: David Lechner , Mark Brown , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , linux-kernel@vger.kernel.org Subject: [PATCH 4/9] spi: axi-spi-engine: fix sleep ticks calculation Date: Mon, 4 Dec 2023 11:33:30 -0600 Message-ID: <20231204-axi-spi-engine-series-2-v1-4-063672323fce@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> References: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 04 Dec 2023 09:35:49 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784373686960939476 X-GMAIL-MSGID: 1784373686960939476 This fixes the sleep ticks calculation when generating sleep instructions in the AXI SPI Engine driver. The previous calculation was ignoring delays less than one microsecond and missed a microsecond to second conversion factor. This fixes the first issue by not rounding to microseconds. Now that xfer->effective_speed_hz is guaranteed to be set correctly, we can use that to simplify the calculation. This new calculation replaces the old incorrect math. Also add unit suffix to the delay variable for clarity while we are touching this. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index fa2264d630c3..b3e72308fcc5 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -168,22 +168,17 @@ static void spi_engine_gen_xfer(struct spi_engine_program *p, bool dry, } static void spi_engine_gen_sleep(struct spi_engine_program *p, bool dry, - struct spi_engine *spi_engine, unsigned int clk_div, struct spi_transfer *xfer) { - unsigned int spi_clk = clk_get_rate(spi_engine->ref_clk); unsigned int t; - int delay; + int delay_ns; - delay = spi_delay_to_ns(&xfer->delay, xfer); - if (delay < 0) + delay_ns = spi_delay_to_ns(&xfer->delay, xfer); + if (delay_ns <= 0) return; - delay /= 1000; - if (delay == 0) - return; - - t = DIV_ROUND_UP(delay * spi_clk, (clk_div + 1) * 2); + /* rounding down since executing the instruction adds a couple of ticks delay */ + t = DIV_ROUND_DOWN_ULL((u64)delay_ns * xfer->effective_speed_hz, NSEC_PER_SEC); while (t) { unsigned int n = min(t, 256U); @@ -224,8 +219,8 @@ static void spi_engine_precompile_message(struct spi_message *msg) } } -static void spi_engine_compile_message(struct spi_engine *spi_engine, - struct spi_message *msg, bool dry, struct spi_engine_program *p) +static void spi_engine_compile_message(struct spi_message *msg, bool dry, + struct spi_engine_program *p) { struct spi_device *spi = msg->spi; struct spi_controller *host = spi->controller; @@ -261,7 +256,7 @@ static void spi_engine_compile_message(struct spi_engine *spi_engine, } spi_engine_gen_xfer(p, dry, xfer); - spi_engine_gen_sleep(p, dry, spi_engine, clk_div - 1, xfer); + spi_engine_gen_sleep(p, dry, xfer); if (xfer->cs_change) { if (list_is_last(&xfer->transfer_list, &msg->transfers)) { @@ -515,7 +510,7 @@ static int spi_engine_prepare_message(struct spi_controller *host, spi_engine_precompile_message(msg); p_dry.length = 0; - spi_engine_compile_message(spi_engine, msg, true, &p_dry); + spi_engine_compile_message(msg, true, &p_dry); size = sizeof(*p->instructions) * (p_dry.length + 1); p = kzalloc(sizeof(*p) + size, GFP_KERNEL); @@ -533,7 +528,7 @@ static int spi_engine_prepare_message(struct spi_controller *host, st->sync_id = ret; - spi_engine_compile_message(spi_engine, msg, false, p); + spi_engine_compile_message(msg, false, p); spi_engine_program_add_cmd(p, false, SPI_ENGINE_CMD_SYNC(st->sync_id)); From patchwork Mon Dec 4 17:33:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 173477 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2921884vqy; Mon, 4 Dec 2023 09:36:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEAgBqN7I4FagIAYjX3uPlG/Wvx5TiPATJ57hUQmfK0IWgYQ3uNI3JDBLoiPKP6QQuDkutw X-Received: by 2002:a17:902:db10:b0:1d0:c0f4:7c13 with SMTP id m16-20020a170902db1000b001d0c0f47c13mr412843plx.34.1701711363743; Mon, 04 Dec 2023 09:36:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701711363; cv=none; d=google.com; s=arc-20160816; b=rRAp6fIWVV61fp9GxmvXoNNnDpUTpj4qp98JSRUwDT76QQ/OvzfnAZxCTxdqAkl2nu Yja07mXXMmkwXk08mgqbjExC91ZKtwhz65qGBdzYRvVHCmjpOuil/FpWrmi6GfCswtuB DsoxVN7BwRYa1Can3scFSSZUYRdoRdAAXdnkbumXQAm8sWYeW/A4mEcfepwbjUOn8h+4 OtrBanZsn5Tq7lTNPREopEKB5hTa7iyddPknZetw0NJ4sDdP8ZuizULXAvlH7Y5QXIUR u90hSqZfvDIu6K/xt34XWZ51krjxOTsLTT44JsgRINsv8S+MsvW4DHttmVbBW6LFEVyw IJNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5N1ldpj7qSULABUcURbREEv+jtlrcm2xYn7c9FK6Esc=; fh=0wGMUdoh1UE04GpAJkixe4SLWCT2iowob+poRBItjRU=; b=RNt10V9ITu4bB2ri9W/roaKxKQkJNM0c29ODbo24rZcMjue7fjhFL0HUYQdBRTC6nQ aC37oQB3ncxgtvsvOBS9GnzhCH+w0W9onMWozBPO7NjAz1+cMIETpJtLexfUAJO8to4P jT5aaky/8hCCFMppAuGW58YP2tTBAx/oxTsigeI/z3PbC2RaVlnHUJ12llFa+sN0BeeL 1FjlIXXLff7trdpvgCtbx7SEJnlNOHT+aSzlGZ7VxldUC+BBaSAWOLFBGBE/9Elnc7Dp GZz7idc3RKdOdfs7cCOTNnPKDBSzgFqbPMg/R4yZ9riV7xwf2kN6hegkDZaZDavCdJ/O ofWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="t62f/93W"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id l5-20020a170903120500b001b9d180fd9asi8162468plh.121.2023.12.04.09.36.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:36:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="t62f/93W"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id A9EB3804C1AD; Mon, 4 Dec 2023 09:35:59 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235451AbjLDRf1 (ORCPT + 99 others); Mon, 4 Dec 2023 12:35:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231415AbjLDRfJ (ORCPT ); Mon, 4 Dec 2023 12:35:09 -0500 Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E64EEFA for ; Mon, 4 Dec 2023 09:35:15 -0800 (PST) Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-1f055438492so2703687fac.3 for ; Mon, 04 Dec 2023 09:35:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1701711315; x=1702316115; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5N1ldpj7qSULABUcURbREEv+jtlrcm2xYn7c9FK6Esc=; b=t62f/93WGiwsngUH2sUzn2zcoAvV7WrCN5iB23+MTgrEjXHEKSebP/lnImoIx9kuqs 5TQag0fbT9cAqx2KXOE3mUbiSD0wDPkWKFU5DGAggVlvuoW6ttFgbyoluBUSiaeUt1Y2 V0SsTKaKMLgHqCI0ERU7pdywfDnHQJZY4MZqr7bQpum0WcbFuk7aPc/BDVhydC9OOHeD QiQhOjkKiXdWXI7RMuf0+PyjEtqPAK+ML57Lhses+WlVEZ3270M3EYpP0nVilPMW1T/z Auy8gSLyLOEMQkrJyUF4DCOqbONgALYd4dK7AZ9LxJMOkOqVQI0W87VtvDN1Ei579qAA Cm9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701711315; x=1702316115; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5N1ldpj7qSULABUcURbREEv+jtlrcm2xYn7c9FK6Esc=; b=r69o3vJ/Fxkgwshf/AO19CBM+v1/bPsXTOKlYp9uMQsN2zQTK8ULetckaxRCW3i8O5 vXLd2GihcG1d9ZKqmRrRGPWGBY6n65bAH83syY7IpHExROmN10okrSw/MWG3ughUwFEz 1CEO2a92yfjda2aMAHW+9xk8QIxzWcxY557winIgRZ1XuHcWDzfBjDiWvw5yZAYzfwbg W7jiRR4kzhY+ZU7Fxg0wm5WUQ6T9l+txM6OhRHWz4KsinFGK8/AnSKUnnWpOG/aV8FIa CdqlHegCSiNrHRl9cjkcxwpuVn9LkEIDwEsog3SeJyMgYev5uOigk8cnnBtPSWAqLYt5 h1KQ== X-Gm-Message-State: AOJu0Yxi0pVDrdMIfMFIJX3LA7qHvk2Z2+LCeNaBZ5gRtfxocUv6u5HS fObDd5vYZiZXZ7Gsk6HiqEvc5kAInjNt6FZAmGc= X-Received: by 2002:a05:6870:558c:b0:1ef:b591:5733 with SMTP id qj12-20020a056870558c00b001efb5915733mr5110355oac.15.1701711315270; Mon, 04 Dec 2023 09:35:15 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id b16-20020a9d5d10000000b006ce2fce83cbsm1956563oti.25.2023.12.04.09.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:35:14 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org Cc: David Lechner , Mark Brown , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , linux-kernel@vger.kernel.org Subject: [PATCH 5/9] spi: axi-spi-engine: remove xfer arg from spi_engine_gen_sleep() Date: Mon, 4 Dec 2023 11:33:31 -0600 Message-ID: <20231204-axi-spi-engine-series-2-v1-5-063672323fce@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> References: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 04 Dec 2023 09:35:59 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784373694940997948 X-GMAIL-MSGID: 1784373694940997948 This replaces the xfer parameter of spi_engine_gen_sleep() in the AXI SPI Engine driver with parameters for the delay in nanoseconds and the SPI SCLK rate. This will allow this function to be used by callers in the future that do not have a spi_transfer struct. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index b3e72308fcc5..84ec37732d8b 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -168,17 +168,16 @@ static void spi_engine_gen_xfer(struct spi_engine_program *p, bool dry, } static void spi_engine_gen_sleep(struct spi_engine_program *p, bool dry, - struct spi_transfer *xfer) + int delay_ns, u32 sclk_hz) { unsigned int t; - int delay_ns; - delay_ns = spi_delay_to_ns(&xfer->delay, xfer); + /* negative delay indicates error, e.g. from spi_delay_to_ns() */ if (delay_ns <= 0) return; /* rounding down since executing the instruction adds a couple of ticks delay */ - t = DIV_ROUND_DOWN_ULL((u64)delay_ns * xfer->effective_speed_hz, NSEC_PER_SEC); + t = DIV_ROUND_DOWN_ULL((u64)delay_ns * sclk_hz, NSEC_PER_SEC); while (t) { unsigned int n = min(t, 256U); @@ -256,7 +255,8 @@ static void spi_engine_compile_message(struct spi_message *msg, bool dry, } spi_engine_gen_xfer(p, dry, xfer); - spi_engine_gen_sleep(p, dry, xfer); + spi_engine_gen_sleep(p, dry, spi_delay_to_ns(&xfer->delay, xfer), + xfer->effective_speed_hz); if (xfer->cs_change) { if (list_is_last(&xfer->transfer_list, &msg->transfers)) { From patchwork Mon Dec 4 17:33:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 173479 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2921932vqy; Mon, 4 Dec 2023 09:36:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvkUgrjwp51SUqfNDRU/agUbQa4Eur/Vh/6wLjSL5S79u6kCkvh4XUPGV7J9G9Y0jIpSJG X-Received: by 2002:a17:903:1c7:b0:1d0:9c53:9cca with SMTP id e7-20020a17090301c700b001d09c539ccamr2267824plh.96.1701711368601; Mon, 04 Dec 2023 09:36:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701711368; cv=none; d=google.com; s=arc-20160816; b=KmpGUt6mtsgbI/97WJQpY+OPQDManoNPk03vGvG/Kfgw3ylv0wDwCs6w8FrHOzyJht xjC5yu2/S9Z/L1ppbIl2Z4RpYJyuCwizjReAfTFhXGeQXGUuuWiN+w4xg/EbhVQ3439T g3/6/NZFIHHTIXU7gO5DwXBCM3NGKNCw1oXwIvkcVi8L1qfErepUfSbiHun4uktCoe8S Fca1uH2XC7BMFBfdeb0onHvundTrt7Q5uYodQgkxhTi5M+eIzR/nJgidG9iRl8ymdZRv TcNMAPFZX7667Nkgpj0yDFvjFK4Bk2QCqbx1XId+toqS6g8KgRqcmSz0BCM5vHZFhI2i u6ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UXeaz0oJETMI/MHvKzRwvujLRc0Q8q0D/J+Fpu3YNWU=; fh=0wGMUdoh1UE04GpAJkixe4SLWCT2iowob+poRBItjRU=; b=xgWGKPcVT1AdKFdemr03h7WJlUWSXId2drnav4R5A7di5pS32jdMjCylY0l4t4GlB4 GWADIRzRJlS/87Uz1vGIJNVUTs1K+SfSK8Pk7E2mIjUDBAgarn5caLAp1cXH1EHseuGR wKeN+oyIJiNlBwk9rsuyzLOhC71Wd310SVFB+RaKTeT1Jwzuc5XWV1STSOPZgNnvOGwa AVIoOQMCe9i9b2umkHcMTRqE0Zp2YKjTyTgBo9fz8nxfoBuavXs5BOrpVb8A5IvLGXjY 9Zu9sBfGgwRMk++n4rVDO5Z+rkUg7uFI6N7o/myWcoh2506ejJliNywGR9Nb6Mnie5Kk FY+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=PZiPpMir; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id bj3-20020a056a02018300b005c621de522csi8327215pgb.361.2023.12.04.09.36.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:36:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=PZiPpMir; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 47E3E805847D; Mon, 4 Dec 2023 09:36:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235478AbjLDRff (ORCPT + 99 others); Mon, 4 Dec 2023 12:35:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234957AbjLDRfK (ORCPT ); Mon, 4 Dec 2023 12:35:10 -0500 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E7DA102 for ; Mon, 4 Dec 2023 09:35:17 -0800 (PST) Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6d87cf8a297so794790a34.2 for ; Mon, 04 Dec 2023 09:35:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1701711316; x=1702316116; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UXeaz0oJETMI/MHvKzRwvujLRc0Q8q0D/J+Fpu3YNWU=; b=PZiPpMirR3Gl9heMvlIQieYCy8omL3SrUQrCIXXVPvaNxu+42Fgr18EInypPDF7pap ETWVE6h62+yDSFr2/kKoMFlrXDflNTSYun3pBy/IPY1n437caTImiQHixSGUcAegNy1J qOMc5Y6pCZbiEFC0jBpHD6vswNzh7T4Mw+ycKo+uK3NAuOw8dFdRSbZ78EWBgpILSDB3 lsItHaS1VlyHbfHQY8f39/j/9J5bwX2g4kqZQDKK3Z4qaJcfrXKj18ni6l+h4r0iE944 lSXFNUW5YXBUFvDkieUSpPGA+VDz9kDTE7YOO09R8rWbxtwXY6fI8leqI+WEyGx2kt8R xhMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701711316; x=1702316116; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UXeaz0oJETMI/MHvKzRwvujLRc0Q8q0D/J+Fpu3YNWU=; b=GCDHSvXVoceKMq9TGyFyxC3isauxaN9L5QxNd1733tUHHor8cJ4UqB61TvT+bB0tAm IsAAXbxxvzkYTs+e36UIqD6x1Y97KKj0Rat6BZpzN33OEFVH0Gz+zb4IJB/erW+k2VQm Too8bDiNOl6xADP50bn9UJ1zhgZsjSrjOff/eWjpmsYCr5RR1B93it+q7vBjx79lutvR l2D8GQbZJRm3Y0Xb+A6z45VeeMWTw3BWQWPz8NqzpppcQZ3ZLr+qVQFMkBOgUee7ELx0 kxu3jGUKaa4V9S8KXB5FN6NPEwhZS+h4ROQgt3f3UZfapkIwiJJ9GT1ioLG8l2V/b4Qm PpFQ== X-Gm-Message-State: AOJu0YwnhThKCh4JqQVlZqcwkMmMnvCmDeq7RYQGSxq3mlWfAX6DUQkb gWn1Z3LwpkhTJ/KbLSE1F18hi1v317qJBmwUbGs= X-Received: by 2002:a05:6830:660a:b0:6d8:74e2:94f3 with SMTP id cp10-20020a056830660a00b006d874e294f3mr2897548otb.57.1701711316259; Mon, 04 Dec 2023 09:35:16 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id b16-20020a9d5d10000000b006ce2fce83cbsm1956563oti.25.2023.12.04.09.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:35:15 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org Cc: David Lechner , Mark Brown , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , linux-kernel@vger.kernel.org Subject: [PATCH 6/9] spi: axi-spi-engine: implement xfer->cs_change_delay Date: Mon, 4 Dec 2023 11:33:32 -0600 Message-ID: <20231204-axi-spi-engine-series-2-v1-6-063672323fce@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> References: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 04 Dec 2023 09:36:02 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784373699786318880 X-GMAIL-MSGID: 1784373699786318880 This adds handling of xfer->cs_change_delay to the AXI SPI Engine driver. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 84ec37732d8b..3437829ef8b1 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -265,6 +265,10 @@ static void spi_engine_compile_message(struct spi_message *msg, bool dry, if (!xfer->cs_off) spi_engine_gen_cs(p, dry, spi, false); + spi_engine_gen_sleep(p, dry, spi_delay_to_ns( + &xfer->cs_change_delay, xfer), + xfer->effective_speed_hz); + if (!list_next_entry(xfer, transfer_list)->cs_off) spi_engine_gen_cs(p, dry, spi, true); } From patchwork Mon Dec 4 17:33:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 173478 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2921919vqy; Mon, 4 Dec 2023 09:36:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+N6e0AbZlgH2Yp867y0Wn7c3EUc04KRb3MWNyxeNEVqoAinLkdmmONkNwBf1jz3QNMK2j X-Received: by 2002:a05:6a21:789b:b0:18b:23db:3dfd with SMTP id bf27-20020a056a21789b00b0018b23db3dfdmr6347092pzc.36.1701711367543; Mon, 04 Dec 2023 09:36:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701711367; cv=none; d=google.com; s=arc-20160816; b=DOmlRcSkBb5TIGMb3+NY0HnIrY/qbbUoJjZMzwuXrFIbBaRMprIv12TbpCfhFWuJcU Wy+W2LQAku0qgLCfNNAhwNwF9UAZrHw/1+NSbjr6XtWSy0VxzxwC9/+koP5xAYu3qg/4 yz04DwABFtK/oza/yHuww/jU3mpGGQETMSF4She66gWM9BexN6+9A3G8wMk7pNdRqly6 YD4vFo0WKbwEGyxbBB70Hp8N0aCj3lWTwdivh4pSFNf8gkFHF+qzOOUuakHOKo+Evx7X 9PtHutBHaybBUyizRmwl5EEGh0dencVjU7hXnSwgvCOva9WJ2BgO8JywB8R8Kx3r1Sgj Cnvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ELMbPJ/Bj4zA9agSl3Q4pw6/j7PM/9NebqfxKhnmMvI=; fh=0wGMUdoh1UE04GpAJkixe4SLWCT2iowob+poRBItjRU=; b=o4lvcV70Lx+PVYWFF4rWBFqa3Us34NbgFpGvOt1C2xVvhfQK4hzORh92dH2MCz1ohr +vHQxdrTMuy+tvnR0OwFOh1jGggPsEFtoOz+YBw9wHeJOIFlMr9kku7+LWeqpXJzrSxt NDbOmY4o7sAcmaRiUfh9JoxV57B1Tc/0N/SY+m+9YvbCA3vJ8WDsMQNhvFQJ2qbXGiSg BxWt7u+YelhMwS/FXsCLfPdvwfU9twcLE+o5j1l7YzguBE+xsrY5f2KS/3GmeKF4fH1g 3xPy23QsHhM3unvCUr6OGUvDoorxTBotdJV9vuUAael2mWfgbGYLuipSo53T7gQ6MEMr TB+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=OurRTAy2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id z1-20020a63e101000000b005c67dd98b13si2814447pgh.314.2023.12.04.09.36.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:36:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=OurRTAy2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 71894805846F; Mon, 4 Dec 2023 09:36:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235401AbjLDRfb (ORCPT + 99 others); Mon, 4 Dec 2023 12:35:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230418AbjLDRfM (ORCPT ); Mon, 4 Dec 2023 12:35:12 -0500 Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99A04FF for ; Mon, 4 Dec 2023 09:35:18 -0800 (PST) Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-6d852e06b07so1659044a34.3 for ; Mon, 04 Dec 2023 09:35:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1701711318; x=1702316118; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ELMbPJ/Bj4zA9agSl3Q4pw6/j7PM/9NebqfxKhnmMvI=; b=OurRTAy2zoeSTxwWrdD6QQgXqylbWVvtku3UbpESXxggK0Ajxy+jAomAtFYlqnhkw/ HANVRaQagfVWm5wGuZEnmymwwixQz3+RO0/7TG0Sx4EuTVLjqC3GRN7yj6xu4sfyqJUv z68b3m4n8rGvjtS1/eaTmLhbPgyRb7UEHgneNSfQKzri/0V9CeUQKncdr14RPyY9Rwjo MWxC2llIhsXJey4BWclkviQNFTX+/yVNNu2rS2eoPJQBGZ4HjYZJH7xj/u6eTWFglDtg e3SkdZI32zayiq+w1yvDyfQD3EEHg5rjbAkHOY3erLQ9QaNC5ynRQ7JGkfBttMKsHoPC xZ4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701711318; x=1702316118; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ELMbPJ/Bj4zA9agSl3Q4pw6/j7PM/9NebqfxKhnmMvI=; b=gcEEAb2T+VUEcuaNLs5aiqZ7wpLDJZUF0nwz/Ad2EtwOPFhuAbTHb29rI7YLOOdR1m 2nYgLLEgs7b/JCX4UKrJGBBqcpTjiyzbiEM8ZFTDB1Y5qcokT91IyPFCPmJHhhvvRchR GUNNH4vykKHrRppbGyKmifi6xPiVwoWM50YgTSwBRleLjVzYpEwmgev0gH+4Ts2+1M9/ nGP8mG+uqKsKAa4OqwjN2JX3Y+YJBXBEzqAPA9YMkMdW7bOk8XiFTQIqrjrGebs6fFG6 WBDumvCNk7fW4c6mA8dF0RE3C3db9k+Zq1mUa5tOjwFTGOjbjt7JZmxMPKNGONkFH7Qb elVQ== X-Gm-Message-State: AOJu0YyXpe1kDmLeidPBRIvtbYVfFADv/JfZTiZ/se4pITUZKXQs9JMh nx+8kkWY1cLtR+wF7gqGH2zoqQ== X-Received: by 2002:a9d:768f:0:b0:6d8:7571:b6d9 with SMTP id j15-20020a9d768f000000b006d87571b6d9mr2147675otl.43.1701711317917; Mon, 04 Dec 2023 09:35:17 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id b16-20020a9d5d10000000b006ce2fce83cbsm1956563oti.25.2023.12.04.09.35.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:35:17 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org Cc: David Lechner , Mark Brown , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , linux-kernel@vger.kernel.org Subject: [PATCH 7/9] spi: axi-spi-engine: restore clkdiv at end of message Date: Mon, 4 Dec 2023 11:33:33 -0600 Message-ID: <20231204-axi-spi-engine-series-2-v1-7-063672323fce@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> References: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 04 Dec 2023 09:36:00 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784373698721014176 X-GMAIL-MSGID: 1784373698721014176 This modifies the ADI AXI SPI Engine driver to restore the clkdiv configuration register at the end of a SPI message. Having the clkdiv in a known state is needed to be able to add a new command in the future that only performs a delay without any SPI transfers. Furthermore having that state be the smallest possible divider will allow these delays to have the highest possible precision. Changing the initial value of clk_div from -1 to 1 is now possible because we know the function will always be called with a known clkdiv config register state. Making this change will also have the effect of not emitting a clkdiv configuration register instruction in cases where the maximum sclk rate is used. Having one less instruction to process reduces delays on the bus which will be beneficial when we implement offload support to enable reading data from devices at very high rates. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 3437829ef8b1..3798f96da586 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -228,7 +228,7 @@ static void spi_engine_compile_message(struct spi_message *msg, bool dry, bool keep_cs = false; u8 bits_per_word = 0; - clk_div = -1; + clk_div = 1; spi_engine_program_add_cmd(p, dry, SPI_ENGINE_CMD_WRITE(SPI_ENGINE_CMD_REG_CONFIG, @@ -280,6 +280,14 @@ static void spi_engine_compile_message(struct spi_message *msg, bool dry, if (!keep_cs) spi_engine_gen_cs(p, dry, spi, false); + + /* + * Restore clockdiv to default so that future gen_sleep commands don't + * have to be aware of the current register state. + */ + if (clk_div != 1) + spi_engine_program_add_cmd(p, dry, + SPI_ENGINE_CMD_WRITE(SPI_ENGINE_CMD_REG_CLK_DIV, 0)); } static void spi_engine_xfer_next(struct spi_message *msg, From patchwork Mon Dec 4 17:33:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 173481 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2922031vqy; Mon, 4 Dec 2023 09:36:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGOjBC7YCK/o/l3PGTpVptbeKvZstmLuhCyxgS343Oj7/6WhWf+dNqqtyzoLVEh34ieeChe X-Received: by 2002:a05:6a20:8f91:b0:18f:97c:8a39 with SMTP id k17-20020a056a208f9100b0018f097c8a39mr3854677pzj.100.1701711379719; Mon, 04 Dec 2023 09:36:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701711379; cv=none; d=google.com; s=arc-20160816; b=Qi9fToqDlwP2B2PfmpF4ow9LJcRmSkeq0RZmZXMY+8JU3iC90cm5Go0Wv7Da7gBOSj 95kr3xt8UieMRmkcwwL7tgIspQ5Vdt7rAt5YCPpSvrourVV/enTqYx9Ef/PtgGDFEwi7 GYk/h9NrxqaNduOKmS9ia9mmK/6Exb+GXFSubckg1gBDFE15XC14TbPVxiWdUrclzCiL PnUy25QpmJBx4o3DCdQ2fnav7NnrUGpcs3DQeBWJjvY4uPHX0cQiQG0m9GLpR2yKPa85 oZH7E61/BJqE3lkZmtqFAvc8D5PewnntpMrEbJrmKw6GOdlOZENh7TKql8cKeZ1W9AnQ MqFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+LzfPXnoh+csBX7vLMU59nOns526pWVt603zQVilgL4=; fh=0wGMUdoh1UE04GpAJkixe4SLWCT2iowob+poRBItjRU=; b=YCkpJrLQ5GE4qOiZj4CeK32p6Egvwpg664bVcXp55gbAKnNs/I5hwxMofgrAs7VWzo UlflFgWd5timwXdBfrdmupuXp0Dk2Yn9s9pkmMbu0Or2XR4LVeLjgFW3vNXXZQX63x0L xwvXmxjwsoEsdhok5emVWZnrIx5eHSHljLSqmbqtRt43gZTXg3gL6fVMJPGQ7xALTFVh uCftNdmVZ5xsjXM5rSm+znoS6+fWNErysQZ1txOy04+MF2r0KRJnUeoYYjzeMrcRZK1C LMESLpH62R9F+ARG2+qNoFxve7/Bp6739PpKhYdvdKMJfcpRBdRIDEJCpOoG8Y19k8AW +bvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=TfhmGU6l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id r5-20020a632045000000b005bd0f2c2671si8327186pgm.626.2023.12.04.09.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:36:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=TfhmGU6l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 7662E8058C7E; Mon, 4 Dec 2023 09:36:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235481AbjLDRfi (ORCPT + 99 others); Mon, 4 Dec 2023 12:35:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234970AbjLDRfN (ORCPT ); Mon, 4 Dec 2023 12:35:13 -0500 Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B664583 for ; Mon, 4 Dec 2023 09:35:19 -0800 (PST) Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-6d852e06b07so1659058a34.3 for ; Mon, 04 Dec 2023 09:35:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1701711319; x=1702316119; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+LzfPXnoh+csBX7vLMU59nOns526pWVt603zQVilgL4=; b=TfhmGU6lO6fg/noNszpMohBn1SHLq59i6u/ummWQ9YrTwimiP+vc11WmP1anJ7tAKl qS8q6JCAZhryqSnIeyd1+N/GKeoiEfbF1Stb8xx/uB0jBYAlGBOccjkd1KTDYDr3ibav EcN62nikiWeRCwHlfUHJE3U4xwCEx3sRGVB1ppY3bLDwifCegn0largtt0wtlPGBzd8e G20CFh4bwcg9/svlVG8O1q/lR2Ep7qhKEC9wCQ8swK6vZ7pamEXy9Cv3v/z3yxhF34I+ yJli6EJ+o2JDeABeuiQzYxDJ6JQ4nmRpYHBVGxtdiXh9A/SMYeDkBPBG8Dezq1mZ+vZr k31A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701711319; x=1702316119; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+LzfPXnoh+csBX7vLMU59nOns526pWVt603zQVilgL4=; b=DFAEhpK5QpFNLqFi4v29cH6FXsLRSR1Jo4cTPIZ510pTOVM159NkEFq6Kay+j6Kbr0 axWmi5Lh1Vcswzy3lWPjvSP51WER7MOK6GFOjIOC9IysXkLE6p5/Q2ru3dqJyFQUcUkv odDffhoAunRQIEHivpXRHjnTMddYbnCayqclHxSc6MadyEiM2FS/BxPwnKbnM+H9hsfh 6LZH2o0lZhoqD8NJUl1pk6k48fIWErnPmBi1PBBNe12kpY/oeCoztZkRcikA1a7iD/jG gYMJrUt/2RnsWWFBCIJHCTX7sOjyO8lQticu0KKQHQu2CsYPd2koNb3ppc0tr8vztbPB y9aw== X-Gm-Message-State: AOJu0YyflhOo11lTfssfhNP3HCmb9Lx/S1QXQrU/x2P15IxVmdYhbNjU frQFVD/EjuENFTuCRTYq5BJ79w== X-Received: by 2002:a9d:6e0f:0:b0:6d9:aac1:228 with SMTP id e15-20020a9d6e0f000000b006d9aac10228mr767736otr.40.1701711319036; Mon, 04 Dec 2023 09:35:19 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id b16-20020a9d5d10000000b006ce2fce83cbsm1956563oti.25.2023.12.04.09.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:35:18 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org Cc: David Lechner , Mark Brown , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , linux-kernel@vger.kernel.org Subject: [PATCH 8/9] spi: axi-spi-engine: remove delay from CS assertion Date: Mon, 4 Dec 2023 11:33:34 -0600 Message-ID: <20231204-axi-spi-engine-series-2-v1-8-063672323fce@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> References: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 04 Dec 2023 09:36:16 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784373711814295536 X-GMAIL-MSGID: 1784373711814295536 Now that the AXI SPI Engine driver has support for the various CS delays requested through struct spi_message, we don't need to add a separate delay to the CS assertion instruction. Otherwise, we end up with longer than requested delays. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 3798f96da586..78221715ba81 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -194,7 +194,7 @@ static void spi_engine_gen_cs(struct spi_engine_program *p, bool dry, if (assert) mask ^= BIT(spi_get_chipselect(spi, 0)); - spi_engine_program_add_cmd(p, dry, SPI_ENGINE_CMD_ASSERT(1, mask)); + spi_engine_program_add_cmd(p, dry, SPI_ENGINE_CMD_ASSERT(0, mask)); } /* From patchwork Mon Dec 4 17:33:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 173482 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2922029vqy; Mon, 4 Dec 2023 09:36:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVZ7rdL79mvugF4YJ6ye3CkVVL+R2rycC7cLsVHiihlJkZFEHsHJbSqRwjUERYjyRJ+NiR X-Received: by 2002:a05:6a00:2d19:b0:6ce:6837:4fde with SMTP id fa25-20020a056a002d1900b006ce68374fdemr121914pfb.47.1701711379098; Mon, 04 Dec 2023 09:36:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701711379; cv=none; d=google.com; s=arc-20160816; b=r7QeiqJG106W3qZBQ9kNPpgF/G7j3YVFrynuNPZt0JILvHc0s4X6j4OSXsqemng6Oo HdSsILA9uuwZq28P4YD+ftLjPGPUNqRxnlalRqw2DhpCMN0c0WvK2RwqIMYM+GlVBXn8 aRv3vQn+4OMS9ljj2qgskjRVU0NTsr4MosWU+iIOK27IVu1gPQAhPBHDcHCKZw25F4aM TENKrbk7tAh95GxuX9GlSzMxMkjE8yKY3vFubTnzpbdvb0t9hugCYlqhwD4Wld7WhPif WBjF/RbWlem7SJ1n/7rEC2q1rnxSsNOFbm7zvbts0xYuzMsiWwcNsO2TQ8771hSnb804 SVJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=V1aIuy5SeTUs79mZ/Wgm37bPfpq27TGELbh2YCbKj2w=; fh=GRROeNtucQPE8Xh4DNmNbCVm0YdyVGd8Gl7IJ84MALg=; b=VRldysQXQm+JJZ10kQu/J0d9Jokb6hxwoaup29AkjXA3l46H0fBGNIwDnHHNZI5MJR YD2aboJH73nCUZ1yJIcEHMblmX8hf+jeje1i/a8TNC5HoamVSFmfZn9uutjHrOfiSxpr hxFOtMYBChWkhY1Ey+kHeAgMElHzomXA06W41WU4VYoClZ5U7gz5gbagjMDlYHr6CSYE Q0jPwZxBEhVu8vVlEBltzV1DWQaV4udUdO9FhHB5p4mwYTwqh4ZPtVMQeqI30UpDoCCI w+06dXSmtOlNjPD4bVxViYQGSwrs0ocnlxJzelhMePhzcYRrEL1XHtKCcTM6wqWpaEph I8HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=O1qGjQQc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id w62-20020a636241000000b005c6763c095asi3243609pgb.331.2023.12.04.09.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:36:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=O1qGjQQc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 6FA558074794; Mon, 4 Dec 2023 09:36:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344834AbjLDRfm (ORCPT + 99 others); Mon, 4 Dec 2023 12:35:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234959AbjLDRfP (ORCPT ); Mon, 4 Dec 2023 12:35:15 -0500 Received: from mail-oo1-xc34.google.com (mail-oo1-xc34.google.com [IPv6:2607:f8b0:4864:20::c34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7464383 for ; Mon, 4 Dec 2023 09:35:21 -0800 (PST) Received: by mail-oo1-xc34.google.com with SMTP id 006d021491bc7-58cecfb4412so3228569eaf.3 for ; Mon, 04 Dec 2023 09:35:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1701711321; x=1702316121; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V1aIuy5SeTUs79mZ/Wgm37bPfpq27TGELbh2YCbKj2w=; b=O1qGjQQck8KBKxrN+E+zcvz1ey3tVvMplHwzsPj/sAaJ5e9Jlwjk29KqZXVOwrKb86 kpCyhXxANfZxfXq5fAVe3M+t+dYGISKCqNmicmeV+qP3W1tmy+gc38NYLh1BmSpCcrhc Vb23jW7qlq4K7HkQHy5/KN95UZaZYj4BRigdXLhbpjs4feCjQY+ZSCFbRPO4ZZ/NBMj5 2omL9KaxxEEWxAh8xgdTtM8E3U9rRowfIcE9n5GwEKslzu3s1GEAV3fzOdDJ3DdKOXAq EO3wignavy4RQ7VjCVxMtaIdvrvxCgeWVdHr35zpBDm94h8p+jSo2CUwZP/qeXpx7/zf PaOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701711321; x=1702316121; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V1aIuy5SeTUs79mZ/Wgm37bPfpq27TGELbh2YCbKj2w=; b=Bmia43hzSuGDYyZJxSVBgE/Ykh12KDV+kSh4tWnPb19VgQlP18YKNNcieNnMs+gKP4 0yFUtNRkXj8LeV8oP4BY7lwZugvnHpah6IqgoQfkhdz/nB2GbQu+zye/WOMhzCJU4cqL DEAYeupCobJ3iR0ml9vMyndnDSU3IZZQGHiXuiHsXzVkYbCjYz4lTXFMSvms/w1bDI3q xzrPoKpxBQXGSkT8u2x6+NFuRH4yQlh/cLYQxl886M3IavBIl1xakEdLGxomd9PpEVAF dpRGpixVGf238QUxjbKjVy/q62ZSc1eG0xh3rxNERhFY2PSh+0aGUV859px6too2yH9V 378g== X-Gm-Message-State: AOJu0Yw2lU9V5lnfSf6nW+z5S8Ouqpeg55QLUoEH+Vn++yh9EfMOxG9R NmMqlVvyp375VAmiNTrhLIuHWQ== X-Received: by 2002:a4a:a74d:0:b0:58e:1c48:1edc with SMTP id h13-20020a4aa74d000000b0058e1c481edcmr3597527oom.14.1701711320804; Mon, 04 Dec 2023 09:35:20 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id b16-20020a9d5d10000000b006ce2fce83cbsm1956563oti.25.2023.12.04.09.35.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:35:20 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org Cc: David Lechner , Mark Brown , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , linux-kernel@vger.kernel.org, Lars-Peter Clausen Subject: [PATCH 9/9] spi: axi-spi-engine: add watchdog timer Date: Mon, 4 Dec 2023 11:33:35 -0600 Message-ID: <20231204-axi-spi-engine-series-2-v1-9-063672323fce@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> References: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 09:36:02 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784373711353441538 X-GMAIL-MSGID: 1784373711353441538 If there is an issue with the AXI SPI Engine hardware a scheduled transfer might never be completed and spi_sync() will block forever. This due to the uninterruptible wait for completion waiting for the spi_finalize_current_message() that never comes. Add a watchdog timer that will abort a transfer 5 seconds after it has been started. This will potentially leave the hardware in a broken state but it allows software to recover and allow to better diagnose the underlying issue. Co-developed-by: Lars-Peter Clausen Signed-off-by: Lars-Peter Clausen Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 78221715ba81..58280dd1c901 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -13,6 +13,7 @@ #include #include #include +#include #define SPI_ENGINE_VERSION_MAJOR(x) ((x >> 16) & 0xff) #define SPI_ENGINE_VERSION_MINOR(x) ((x >> 8) & 0xff) @@ -114,6 +115,8 @@ struct spi_engine { void __iomem *base; struct ida sync_ida; + struct timer_list watchdog_timer; + struct spi_controller *controller; unsigned int int_enable; }; @@ -488,9 +491,11 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) struct spi_engine_message_state *st = msg->state; if (completed_id == st->sync_id) { - msg->status = 0; - msg->actual_length = msg->frame_length; - spi_finalize_current_message(host); + if (timer_delete_sync(&spi_engine->watchdog_timer)) { + msg->status = 0; + msg->actual_length = msg->frame_length; + spi_finalize_current_message(host); + } disable_int |= SPI_ENGINE_INT_SYNC; } } @@ -573,6 +578,8 @@ static int spi_engine_transfer_one_message(struct spi_controller *host, unsigned int int_enable = 0; unsigned long flags; + mod_timer(&spi_engine->watchdog_timer, jiffies + msecs_to_jiffies(5000)); + spin_lock_irqsave(&spi_engine->lock, flags); if (spi_engine_write_cmd_fifo(spi_engine, msg)) @@ -596,6 +603,20 @@ static int spi_engine_transfer_one_message(struct spi_controller *host, return 0; } +static void spi_engine_timeout(struct timer_list *timer) +{ + struct spi_engine *spi_engine = from_timer(spi_engine, timer, watchdog_timer); + struct spi_controller *host = spi_engine->controller; + + if (WARN_ON(!host->cur_msg)) + return; + + dev_err(&host->dev, + "Timeout occurred while waiting for transfer to complete. Hardware is probably broken.\n"); + host->cur_msg->status = -ETIMEDOUT; + spi_finalize_current_message(host); +} + static void spi_engine_release_hw(void *p) { struct spi_engine *spi_engine = p; @@ -625,6 +646,8 @@ static int spi_engine_probe(struct platform_device *pdev) spin_lock_init(&spi_engine->lock); ida_init(&spi_engine->sync_ida); + timer_setup(&spi_engine->watchdog_timer, spi_engine_timeout, TIMER_IRQSAFE); + spi_engine->controller = host; spi_engine->clk = devm_clk_get_enabled(&pdev->dev, "s_axi_aclk"); if (IS_ERR(spi_engine->clk))