From nobody Mon Feb 9 01:25:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E27CEC4167B for ; Mon, 4 Dec 2023 17:35:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235365AbjLDRfP (ORCPT ); Mon, 4 Dec 2023 12:35:15 -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-Google-Smtp-Source: AGHT+IHg4kzcTZPdowMqqYULC4Xk7Q2T1h9G0+l78eNSUSIGdCPrDTXYGvub/SVq0Dprt3xJgcdH6w== 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 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Michael Hennerich Acked-by: Nuno Sa --- 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-eng= ine.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)); } =20 -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 =3D msg->spi; @@ -273,8 +273,6 @@ static int spi_engine_compile_message(struct spi_engine= *spi_engine, =20 if (!keep_cs) spi_engine_gen_cs(p, dry, spi, false); - - return 0; } =20 static void spi_engine_xfer_next(struct spi_message *msg, --=20 2.43.0 From nobody Mon Feb 9 01:25:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52A34C4167B for ; Mon, 4 Dec 2023 17:35:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235400AbjLDRfU (ORCPT ); Mon, 4 Dec 2023 12:35:20 -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-Google-Smtp-Source: AGHT+IE5mZIXudGi6l7bGmA++q9TgAs/PhXMb1/fKQ7Ycnr8NW3MMYZ8DmVrknbpKNkBAWV+ZYC+Pg== 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 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Michael Hennerich Acked-by: Nuno Sa --- 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-eng= ine.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_progra= m *p, bool dry, spi_engine_program_add_cmd(p, dry, SPI_ENGINE_CMD_ASSERT(1, mask)); } =20 +/* + * 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 latt= er + * 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 =3D msg->spi->controller->max_speed_hz; + struct spi_transfer *xfer; + + list_for_each_entry(xfer, &msg->transfers, transfer_list) { + clk_div =3D DIV_ROUND_UP(max_hz, xfer->speed_hz); + xfer->effective_speed_hz =3D 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_contro= ller *host, if (!st) return -ENOMEM; =20 + spi_engine_precompile_message(msg); + p_dry.length =3D 0; spi_engine_compile_message(spi_engine, msg, true, &p_dry); =20 --=20 2.43.0 From nobody Mon Feb 9 01:25:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82F5EC4167B for ; Mon, 4 Dec 2023 17:35:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235428AbjLDRfW (ORCPT ); Mon, 4 Dec 2023 12:35:22 -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-Google-Smtp-Source: AGHT+IFUKMvyDr3pCqBprdVy+wT0uIcEmQdfHX9XEOYbbBzlirNTiThCnIRkYtJ5czxdwXlpiSb1wQ== 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 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Michael Hennerich Acked-by: Nuno Sa --- 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-eng= ine.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_d= evice *spi) return config; } =20 -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 =3D DIV_ROUND_UP(clk_get_rate(spi_engine->ref_clk), - xfer->speed_hz * 2); - if (clk_div > 255) - clk_div =3D 255; - else if (clk_div > 0) - clk_div -=3D 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_engin= e *spi_engine, struct spi_message *msg, bool dry, struct spi_engine_program *p) { struct spi_device *spi =3D msg->spi; + struct spi_controller *host =3D spi->controller; struct spi_transfer *xfer; int clk_div, new_clk_div; bool keep_cs =3D false; @@ -258,12 +244,13 @@ static void spi_engine_compile_message(struct spi_eng= ine *spi_engine, spi_engine_gen_cs(p, dry, spi, !xfer->cs_off); =20 list_for_each_entry(xfer, &msg->transfers, transfer_list) { - new_clk_div =3D spi_engine_get_clk_div(spi_engine, spi, xfer); + new_clk_div =3D host->max_speed_hz / xfer->effective_speed_hz; if (new_clk_div !=3D clk_div) { clk_div =3D 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)); } =20 if (bits_per_word !=3D xfer->bits_per_word) { @@ -274,7 +261,7 @@ static void spi_engine_compile_message(struct spi_engin= e *spi_engine, } =20 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); =20 if (xfer->cs_change) { if (list_is_last(&xfer->transfer_list, &msg->transfers)) { --=20 2.43.0 From nobody Mon Feb 9 01:25:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24958C4167B for ; Mon, 4 Dec 2023 17:35:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235445AbjLDRfZ (ORCPT ); Mon, 4 Dec 2023 12:35:25 -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-Google-Smtp-Source: AGHT+IEJDbU4/GFS0r8bfZ90Qi/bwXcMtxkv0WvUFlfaUtDNJ+ir6BlFpRM7qCksKlWxLLK8oUOm1Q== 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 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Michael Hennerich Acked-by: Nuno Sa --- 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-eng= ine.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_pro= gram *p, bool dry, } =20 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 =3D clk_get_rate(spi_engine->ref_clk); unsigned int t; - int delay; + int delay_ns; =20 - delay =3D spi_delay_to_ns(&xfer->delay, xfer); - if (delay < 0) + delay_ns =3D spi_delay_to_ns(&xfer->delay, xfer); + if (delay_ns <=3D 0) return; - delay /=3D 1000; =20 - if (delay =3D=3D 0) - return; - - t =3D DIV_ROUND_UP(delay * spi_clk, (clk_div + 1) * 2); + /* rounding down since executing the instruction adds a couple of ticks d= elay */ + t =3D DIV_ROUND_DOWN_ULL((u64)delay_ns * xfer->effective_speed_hz, NSEC_P= ER_SEC); while (t) { unsigned int n =3D min(t, 256U); =20 @@ -224,8 +219,8 @@ static void spi_engine_precompile_message(struct spi_me= ssage *msg) } } =20 -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 =3D msg->spi; struct spi_controller *host =3D spi->controller; @@ -261,7 +256,7 @@ static void spi_engine_compile_message(struct spi_engin= e *spi_engine, } =20 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); =20 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_contro= ller *host, spi_engine_precompile_message(msg); =20 p_dry.length =3D 0; - spi_engine_compile_message(spi_engine, msg, true, &p_dry); + spi_engine_compile_message(msg, true, &p_dry); =20 size =3D sizeof(*p->instructions) * (p_dry.length + 1); p =3D kzalloc(sizeof(*p) + size, GFP_KERNEL); @@ -533,7 +528,7 @@ static int spi_engine_prepare_message(struct spi_contro= ller *host, =20 st->sync_id =3D ret; =20 - spi_engine_compile_message(spi_engine, msg, false, p); + spi_engine_compile_message(msg, false, p); =20 spi_engine_program_add_cmd(p, false, SPI_ENGINE_CMD_SYNC(st->sync_id)); =20 --=20 2.43.0 From nobody Mon Feb 9 01:25:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88EB4C4167B for ; Mon, 4 Dec 2023 17:35:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235460AbjLDRf3 (ORCPT ); Mon, 4 Dec 2023 12:35:29 -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-Google-Smtp-Source: AGHT+IFLgXbrPDcQ7k5zqmLeFlbqKW1SnS++SSir5JVeArkwx/BhZ+D10yN+nLAvf36eks4VoFaqhA== 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 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Michael Hennerich Acked-by: Nuno Sa --- 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-eng= ine.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_pro= gram *p, bool dry, } =20 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; =20 - delay_ns =3D spi_delay_to_ns(&xfer->delay, xfer); + /* negative delay indicates error, e.g. from spi_delay_to_ns() */ if (delay_ns <=3D 0) return; =20 /* rounding down since executing the instruction adds a couple of ticks d= elay */ - t =3D DIV_ROUND_DOWN_ULL((u64)delay_ns * xfer->effective_speed_hz, NSEC_P= ER_SEC); + t =3D DIV_ROUND_DOWN_ULL((u64)delay_ns * sclk_hz, NSEC_PER_SEC); while (t) { unsigned int n =3D min(t, 256U); =20 @@ -256,7 +255,8 @@ static void spi_engine_compile_message(struct spi_messa= ge *msg, bool dry, } =20 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); =20 if (xfer->cs_change) { if (list_is_last(&xfer->transfer_list, &msg->transfers)) { --=20 2.43.0 From nobody Mon Feb 9 01:25:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 235CDC4167B for ; Mon, 4 Dec 2023 17:35:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229488AbjLDRff (ORCPT ); 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-Google-Smtp-Source: AGHT+IEbHY8B3HhnvuqLpnt7QMdgLQokFYwpaYG6qQiY3g06vhxSnhXGbt+H28bPcfWacemrIuX9Hw== 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 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds handling of xfer->cs_change_delay to the AXI SPI Engine driver. Signed-off-by: David Lechner Acked-by: Michael Hennerich Acked-by: Nuno Sa --- 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-eng= ine.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_mess= age *msg, bool dry, if (!xfer->cs_off) spi_engine_gen_cs(p, dry, spi, false); =20 + 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); } --=20 2.43.0 From nobody Mon Feb 9 01:25:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB522C4167B for ; Mon, 4 Dec 2023 17:35:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235450AbjLDRfd (ORCPT ); Mon, 4 Dec 2023 12:35:33 -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-Google-Smtp-Source: AGHT+IE/yqFGcXWPTu15sUzxJUaPpuQBk/n79TXrMWam1gnscCWERXd110HIkAly/WudmFOVbxPZIQ== 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 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Michael Hennerich Acked-by: Nuno Sa --- 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-eng= ine.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_messa= ge *msg, bool dry, bool keep_cs =3D false; u8 bits_per_word =3D 0; =20 - clk_div =3D -1; + clk_div =3D 1; =20 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_mess= age *msg, bool dry, =20 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 !=3D 1) + spi_engine_program_add_cmd(p, dry, + SPI_ENGINE_CMD_WRITE(SPI_ENGINE_CMD_REG_CLK_DIV, 0)); } =20 static void spi_engine_xfer_next(struct spi_message *msg, --=20 2.43.0 From nobody Mon Feb 9 01:25:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD820C4167B for ; Mon, 4 Dec 2023 17:35:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343927AbjLDRfk (ORCPT ); Mon, 4 Dec 2023 12:35:40 -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-Google-Smtp-Source: AGHT+IGtOaPvxIOHnyH/580dDNDubjZltu2MPm85XIWMx0R7RIPtoorikJI9IsraRZQp8KMwdoeMMA== 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 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Michael Hennerich Acked-by: Nuno Sa --- 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-eng= ine.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 ^=3D BIT(spi_get_chipselect(spi, 0)); =20 - 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)); } =20 /* --=20 2.43.0 From nobody Mon Feb 9 01:25:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60BFCC10DC1 for ; Mon, 4 Dec 2023 17:36:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345288AbjLDRfo (ORCPT ); Mon, 4 Dec 2023 12:35:44 -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-Google-Smtp-Source: AGHT+IHXDcDPc2B0XlNkOLtuhxBFl/ugWTs/NVcBkSAXUlvE/EH+riGhVdxMKsBfxh4ipH0a9WeQ7A== 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 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Michael Hennerich Acked-by: Nuno Sa --- 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-eng= ine.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 =20 #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 { =20 void __iomem *base; struct ida sync_ida; + struct timer_list watchdog_timer; + struct spi_controller *controller; =20 unsigned int int_enable; }; @@ -488,9 +491,11 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) struct spi_engine_message_state *st =3D msg->state; =20 if (completed_id =3D=3D st->sync_id) { - msg->status =3D 0; - msg->actual_length =3D msg->frame_length; - spi_finalize_current_message(host); + if (timer_delete_sync(&spi_engine->watchdog_timer)) { + msg->status =3D 0; + msg->actual_length =3D msg->frame_length; + spi_finalize_current_message(host); + } disable_int |=3D SPI_ENGINE_INT_SYNC; } } @@ -573,6 +578,8 @@ static int spi_engine_transfer_one_message(struct spi_c= ontroller *host, unsigned int int_enable =3D 0; unsigned long flags; =20 + mod_timer(&spi_engine->watchdog_timer, jiffies + msecs_to_jiffies(5000)); + spin_lock_irqsave(&spi_engine->lock, flags); =20 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; } =20 +static void spi_engine_timeout(struct timer_list *timer) +{ + struct spi_engine *spi_engine =3D from_timer(spi_engine, timer, watchdog_= timer); + struct spi_controller *host =3D spi_engine->controller; + + if (WARN_ON(!host->cur_msg)) + return; + + dev_err(&host->dev, + "Timeout occurred while waiting for transfer to complete. Hardware is pr= obably broken.\n"); + host->cur_msg->status =3D -ETIMEDOUT; + spi_finalize_current_message(host); +} + static void spi_engine_release_hw(void *p) { struct spi_engine *spi_engine =3D p; @@ -625,6 +646,8 @@ static int spi_engine_probe(struct platform_device *pde= v) =20 spin_lock_init(&spi_engine->lock); ida_init(&spi_engine->sync_ida); + timer_setup(&spi_engine->watchdog_timer, spi_engine_timeout, TIMER_IRQSAF= E); + spi_engine->controller =3D host; =20 spi_engine->clk =3D devm_clk_get_enabled(&pdev->dev, "s_axi_aclk"); if (IS_ERR(spi_engine->clk)) --=20 2.43.0