From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94483EEC0 for ; Wed, 26 Aug 2026 00:05:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787702741; cv=none; b=lVDDLGKxWekHJod1aFGWpFc9qoLhwR6xlOYWkYSpbLKUrGYlabWTQX0zHYWLq5tmwCYwYCAsYMsGAP/syQvuqvjWzd+WGQg/apXu8/DYtCw2uZk/ey0F2xiLowg+tIn2Ei6HOcX6qo0vSLg+IprZ0E2P+YdADSbzUMC2VQSVZno= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787702741; c=relaxed/simple; bh=rt83UHicrKw7lr4xO0XXvIXqk2CwSJUfqCAq2gx1VxE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=IQTKKP/j07osBYVKkztVDILImpKLJUqCpCSQ5bXrtEs8lI2osOZtZ4zRhwb9zZkzC3blfxxN+pniJLCMJGvfzDK2H1fyc8cG7fnGWlWCUo7wl/yY6kB/cEyeLeWGxcCNCpd/pLlqDwf/CU+ZRpCqcnXhcDtnSCFwxT36jyFkkTk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=maticrobots.com; spf=pass smtp.mailfrom=matician.com; dkim=pass (2048-bit key) header.d=maticrobots.com header.i=@maticrobots.com header.b=GkPyJ2jk; arc=none smtp.client-ip=209.85.215.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=maticrobots.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=matician.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=maticrobots.com header.i=@maticrobots.com header.b="GkPyJ2jk" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-cc1bc88a20eso406461a12.3 for ; Tue, 25 Aug 2026 17:05:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maticrobots.com; s=google; t=1787702740; x=1788307540; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=cSqeNF7Pcjc0PjDHs0LlnCxF9PEmfZ8hQZhY1ZU8wAk=; b=GkPyJ2jkM+NyMk0YTpEEChnPQN7HPFGpJZTYX8UooPIBfwqvFCjkzWdk5sJTsvi142 UirVtjC2/4851tynopetgcLjV576f2aarbADsL9obWtvBIj0utRz0XBVDdMCMKMos8uE EvZLIgVjGXiIrLDcIRRjBfpCj51KyPXqvCVebnHhu89Ckwg+dviYTfWDljYxsGGlG10e MPICXc1of9Hs9Fpc3P03pzDCnN+K3bEhkt8h5XuNPiAaUWy4sjsMPeQO0ChHPqkBYx2/ wCwDJznxkWLsNHgzrXU9w6cNuYxD9O2gi6Vnc1niZ6RPMMP761T6EU9QQV1LAU/FJqcN WYJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787702740; x=1788307540; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=cSqeNF7Pcjc0PjDHs0LlnCxF9PEmfZ8hQZhY1ZU8wAk=; b=OPhWyRWBDcjTSSEz7/xmp+fuzcbxgeLy0Z6Ao9nmWZ/NJrrBjkBlGkKA+HjBmx07K2 3ceE2JjNt63CDRvbkzRa6hW0aJua86k1qICce2DqM5qC0KXmmkBTmfiT5kqNp5Zj/Ck+ ptGHquA6tss1VHGF4oo6R2Y+qGssmtstA6ze/DZt+xi1l3NRDe9ysyS7P7zFewCncMg4 2PkNvNL5W9+MG8TusXAhKus/krO4UYedA/gBbBm3fsoJhLEt+leg0IGFWw1JedyEGqRo T3Qj0o/oRAzZeOzFVCiCrXtonrvkypoBb/58pGsXxCtOhB7scfMu98gdzVdfNfOs+7y0 nC/A== X-Forwarded-Encrypted: i=1; AHgh+RqC2GEO5atG+Acvs3MEJmQM3MAlbLdB5spmZCvKGbZ6ThKT03LmO+CHbuBIbx08+yhXus/7CqlNizNfWao=@vger.kernel.org X-Gm-Message-State: AFuF++k5mBnJAKWPwrlKNa4VQw4yHSAZXTWWzoOEaKO3Ha60lwTycPMz JtKYalj5yvB3MBFg6kJZYltQjU+ue4yEItUrmJC6PNh0skWQOzbw+alU4WLfw69Di/w= X-Gm-Gg: AR+sD12h8Ek64xF3iIM4fj7QDltw4rdFHD+0oQeXo2TSr72nJrF4uXFVFlouZBR3bqj Fy1kDOwxptr94VpjnldMATqsDMpDNYOxrQ2RSOzPFHgAupJz3ffTrpikzWHKpUEg0NFBCpCt4y+ oQ75mTAH8RwHxMSrewAtNA2+ESVjZVu058q28VPrqRmWxiKl1lmyvtht5ZDFHj61tIZHEAMZW77 Tzdv3Ro9slu4zqGzKwuKxGRiRfV4Tv0QAOWzjkd34VDDKOigcfuR/Ru3uUSENYRTXyE5FVOZqbE XLf+6nNd9NU3y8RtRHrD1P1vOr0ND+XxfsmZjDnT0WBZqR0loShLxx6Yh/5jBsA4hbSAm31U9kz x8zqbrVFxrkFxb1+Cst3cf3BPPZ4Vmj0WWz0ch9PttltcQy6kMM4DTLQ/kere3no9G9RavR0Eew XRMj8zkGl8Z37Im2HuXxPerv806oTQ+lzCCIZU2vQL2n4kgS/tibQ6NdhkEjJKnm8WDNniDmtW3 qb69nmVfA83qM6+Xo8VVWxBvomDAOb7t3vaVJioVogfstuE X-Received: by 2002:a05:6a21:9202:b0:3c3:64cb:9b99 with SMTP id adf61e73a8af0-3cf76283ed6mr4541841637.6.1787702739862; Tue, 25 Aug 2026 17:05:39 -0700 (PDT) Received: from abeMaticDesktop.1020marsh.offices.matician.com ([2600:1700:471:807f:6b81:bc26:604c:6f42]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3283d9e4ba6sm2442772eec.26.2026.08.25.17.05.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 17:05:39 -0700 (PDT) From: Abraham Zukor To: Mark Brown , Laxman Dewangan Cc: Mikko Perttunen , Thierry Reding , Jonathan Hunter , linux-spi@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, Abraham Zukor Subject: [PATCH v3] spi: tegra114: initialize native chip selects inactive Date: Tue, 25 Aug 2026 17:05:17 -0700 Message-ID: <20260826000517.631736-1-abe@maticrobots.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit tegra_spi_probe() initializes SPI_COMMAND1 with only SPI_M_S, leaving CS_POL_INACTIVE clear for every chip select. This drives every native active-low chip select low until tegra_spi_setup() runs for that device. SPI children are registered and probed one at a time. A synchronous probe of an earlier child can therefore transfer while a later child's chip select is still asserted. On a Tegra234 system with active-low devices on CS0 and CS1, this caused both devices to be selected when the CS1 device probed first. Its initialization then intermittently failed. A logic analyzer showed CS0 remained low throughout the CS1 transfer and went high only after the CS1 probe failed. Walk the controller's device tree children before SPI_COMMAND1 is written and set CS_POL_INACTIVE for each valid chip select without spi-cs-high. That way the line is already deasserted when the first child transfers and does not change level when setup runs. Disabled children are walked too. The core only registers available children, so tegra_spi_setup() never runs for a disabled one and probe is the only chance to park its chip select at the level its hardware needs. Fixes: f333a331adfa ("spi/tegra114: add spi driver") Assisted-by: Claude:Opus-5 Signed-off-by: Abraham Zukor --- v3: - Drop the cs-gpios check; programming an unused native chip select does not affect a device using a GPIO chip select. - Split the compound condition into separate checks for readability. - Retest on a Jetson Orin Nano with CS1 disabled. The old module left CS1 asserted, while the patched module parked both chip selects inactive. v2: - Derive the inactive level per chip select from the device tree instead of setting the whole CS_POL_INACTIVE field, which is incorrect for an active-high or mixed-polarity bus. drivers/spi/spi-tegra114.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/spi/spi-tegra114.c b/drivers/spi/spi-tegra114.c index aa44ffd09e61..463bb7e61b6e 100644 --- a/drivers/spi/spi-tegra114.c +++ b/drivers/spi/spi-tegra114.c @@ -1395,6 +1395,32 @@ static int tegra_spi_probe(struct platform_device *pdev) udelay(2); reset_control_deassert(tspi->rst); tspi->def_command1_reg = SPI_M_S; + + /* + * SPI_COMMAND1 is written before any child is registered, so a chip + * select with CS_POL_INACTIVE clear stays asserted until + * tegra_spi_setup() runs for that device. Program the level the + * device tree asks for up front instead. + * + * Disabled children are included deliberately. The core never + * registers them, so this is the only chance to park their chip + * select at the level their hardware needs. + */ + for_each_child_of_node_scoped(pdev->dev.of_node, np) { + u32 cs; + + if (of_property_read_bool(np, "spi-cs-high")) + continue; + + if (of_property_read_u32(np, "reg", &cs)) + continue; + + if (cs >= MAX_CHIP_SELECT) + continue; + + tspi->def_command1_reg |= SPI_CS_POL_INACTIVE(cs); + } + tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1); tspi->spi_cs_timing1 = tegra_spi_readl(tspi, SPI_CS_TIMING1); tspi->spi_cs_timing2 = tegra_spi_readl(tspi, SPI_CS_TIMING2); -- 2.54.0