spi: tegra114: initialize native chip selects inactive
Subsystems (3)
PATCH v4 1/1 spi: tegra114: initialize native chip selects inactive
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.
If an enabled child shares a chip select with disabled ones, its polarity takes priority. If only disabled children use a chip select and they disagree, warn and leave the line inactive high.
---
v4:
- Let an enabled child's polarity take priority over disabled children on the same chip select (Jon Hunter, Mark Brown).
- Warn when only disabled children use a chip select and they disagree on polarity.
- Link to v3: https://lore.kernel.org/all/[email protected]/
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 | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
drivers/spi/spi-tegra114.c +49 -0
@@ -1301,6 +1301,9 @@ static int tegra_spi_probe(struct platform_device *pdev)struct resource *r;int ret, spi_irq;int bus_num; +u32 conflicting_cs; +u32 enabled_child_cs_polarity =0 , disabled_child_cs_low =0 , disabled_child_cs_high =0 ; +u32 enabled_cs_mask =0 ; host =devm_spi_alloc_host (&pdev->dev,sizeof (*tspi));if (!host) {
@@ -1395,6 +1398,52 @@ 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. An enabled child on the +* same CS takes priority. +*/ +for_each_child_of_node_scoped (pdev->dev.of_node, np) { +u32 cs; +u32 polarity_bitmask; +u32 cs_polarity =0 ; + +if (of_property_read_u32 (np,"reg" , &cs)) +continue ; + +if (cs >=MAX_CHIP_SELECT ) +continue ; + + polarity_bitmask =SPI_CS_POL_INACTIVE (cs); +if (!of_property_read_bool (np,"spi-cs-high" )) + cs_polarity = polarity_bitmask; + +if (of_device_is_available (np)) { + enabled_cs_mask |= polarity_bitmask; + enabled_child_cs_polarity |= cs_polarity; + }else { +if (cs_polarity) + disabled_child_cs_low |= polarity_bitmask; +else + disabled_child_cs_high |= polarity_bitmask; + } + } + conflicting_cs = disabled_child_cs_low & disabled_child_cs_high & ~enabled_cs_mask; +for (u32 cs =0 ; cs <MAX_CHIP_SELECT ; cs++) { +if (SPI_CS_POL_INACTIVE (cs) & conflicting_cs) +dev_warn (&pdev->dev, +"Conflicting CS polarity on disabled nodes at cs %u\n" , cs); + } + + tspi->def_command1_reg |= enabled_child_cs_polarity | + (disabled_child_cs_low & ~enabled_cs_mask);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 );
Signature · 1 line
2.52.0
Mark Brown
maintainerQuoted 1 line · Abraham Zukor
spi: tegra114: initialize native chip selects inactive
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.4
Thanks!
[1/1] spi: tegra114: initialize native chip selects inactive
https://git.kernel.org/broonie/spi/c/f8334fdfd858
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark