Compare

d5a821f66047c2effd06147b84775f9b2ce0f4aa..8980bc573ae2d2b9d86d76aeb86c76e1597070bf

spi: tegra114: assert CS GPIO for every transfer in a message

The driver provides its own transfer_one_message() and therefore drives
the chip-select GPIO itself rather than through the SPI core. The GPIO is
asserted only in the is_first_of_msg path of
tegra_spi_setup_transfer_one(), but tegra_spi_transfer_end() deasserts it
whenever a transfer has cs_change set. For a multi-transfer message whose
earlier transfers request cs_change -- for example a register read that
sends the address in one transfer and clocks the data back in the next --
the CS GPIO is released after the first transfer and never re-asserted,
so the remaining transfers are clocked with chip-select inactive and the
peripheral never drives the bus.

This was observed with an ADIS16470 IMU (adis16475 driver), whose
register read is a two-transfer, cs_change-framed exchange: a logic
analyzer showed the data frame clocked with CS high, and the driver read
0 while the device drove 0x4056 on the wire.

Re-assert the CS GPIO for every transfer so that multi-transfer messages
keep chip-select active across the whole message. gpiod_set_value() is
idempotent and polarity-aware, so this is a no-op for the first transfer
and for messages that keep CS asserted throughout.

Fixes: 63c1440596ff ("spi: tegra114: add support for gpio based CS")
Signed-off-by: Carlos Jones Jr <carlosjr.jones@analog.com>
Link: https://patch.msgid.link/20261002085540.1625-1-carlosjr.jones@analog.com
Signed-off-by: Mark Brown <broonie@kernel.org>

Carlos Jones Jr <carlosjr.jones@analog.com> · 2026-10-02 08:55 UTC · committed by Mark Brown

Browse files
7 files changed, +22 −22
modified drivers/base/regmap/regcache-maple.c
@@ -312,21 +312,16 @@ static void regcache_maple_exit(struct regmap *map)
312 312 struct maple_tree *mt = map->cache;
313 313 MA_STATE(mas, mt, 0, UINT_MAX);
314 314 unsigned int *entry;
315 - unsigned long flags;
316 315
317 316 /* if we've already been called then just return */
318 317 if (!mt)
319 318 return;
320 319
321 - /*
322 - * Register access may take the Maple lock from hard IRQ context, so
323 - * preserve its IRQ-safe lockdep state during teardown.
324 - */
325 - mas_lock_irqsave(&mas, flags);
320 + mas_lock(&mas);
326 321 mas_for_each(&mas, entry, UINT_MAX)
327 322 kfree(entry);
328 323 __mt_destroy(mt);
329 - mas_unlock_irqrestore(&mas, flags);
324 + mas_unlock(&mas);
330 325
331 326 kfree(mt);
332 327 map->cache = NULL;
modified drivers/base/regmap/regcache.c
@@ -225,7 +225,9 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
225 225 if (map->cache_ops->init) {
226 226 dev_dbg(map->dev, "Initializing %s cache\n",
227 227 map->cache_ops->name);
228 + map->lock(map->lock_arg);
228 229 ret = map->cache_ops->init(map);
230 + map->unlock(map->lock_arg);
229 231 if (ret)
230 232 goto err_free_reg_defaults;
231 233 }
@@ -257,7 +259,9 @@ err_free:
257 259 err_exit:
258 260 if (map->cache_ops->exit) {
259 261 dev_dbg(map->dev, "Destroying %s cache\n", map->cache_ops->name);
262 + map->lock(map->lock_arg);
260 263 map->cache_ops->exit(map);
264 + map->unlock(map->lock_arg);
261 265 }
262 266 err_free_reg_defaults:
263 267 kfree(map->reg_defaults);
@@ -277,7 +281,9 @@ void regcache_exit(struct regmap *map)
277 281 if (map->cache_ops->exit) {
278 282 dev_dbg(map->dev, "Destroying %s cache\n",
279 283 map->cache_ops->name);
284 + map->lock(map->lock_arg);
280 285 map->cache_ops->exit(map);
286 + map->unlock(map->lock_arg);
281 287 }
282 288
283 289 kfree(map->reg_defaults);
modified drivers/base/regmap/regmap-debugfs.c
@@ -664,7 +664,6 @@ void regmap_debugfs_exit(struct regmap *map)
664 664 {
665 665 if (map->debugfs) {
666 666 debugfs_remove_recursive(map->debugfs);
667 - map->debugfs = NULL;
668 667 mutex_lock(&map->cache_lock);
669 668 regmap_debugfs_free_dump_cache(map);
670 669 mutex_unlock(&map->cache_lock);
modified drivers/base/regmap/regmap-irq.c
@@ -963,7 +963,7 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
963 963 return 0;
964 964
965 965 err_domain:
966 - irq_domain_remove(d->domain);
966 + /* Should really dispose of the domain but... */
967 967 err_mutex:
968 968 mutex_destroy(&d->lock);
969 969 lockdep_unregister_key(&d->lock_key);
modified drivers/base/regmap/regmap.c
@@ -1422,8 +1422,8 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
1422 1422 {
1423 1423 int ret;
1424 1424
1425 - regmap_debugfs_exit(map);
1426 1425 regcache_exit(map);
1426 + regmap_debugfs_exit(map);
1427 1427
1428 1428 map->max_register = config->max_register;
1429 1429 map->max_register_is_set = map->max_register ?: config->max_register_is_0;
@@ -1440,16 +1440,12 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
1440 1440 if (ret)
1441 1441 return ret;
1442 1442
1443 + regmap_debugfs_init(map);
1444 +
1443 1445 map->cache_bypass = false;
1444 1446 map->cache_only = false;
1445 1447
1446 - ret = regcache_init(map, config);
1447 - if (ret)
1448 - return ret;
1449 -
1450 - regmap_debugfs_init(map);
1451 -
1452 - return 0;
1448 + return regcache_init(map, config);
1453 1449 }
1454 1450 EXPORT_SYMBOL_GPL(regmap_reinit_cache);
1455 1451
@@ -1463,8 +1459,9 @@ void regmap_exit(struct regmap *map)
1463 1459 struct regmap_async *async;
1464 1460
1465 1461 regmap_detach_dev(map->dev, map);
1466 - regmap_debugfs_exit(map);
1467 1462 regcache_exit(map);
1463 +
1464 + regmap_debugfs_exit(map);
1468 1465 regmap_range_exit(map);
1469 1466 if (map->bus && map->bus->free_context)
1470 1467 map->bus->free_context(map->bus_context);
modified drivers/spi/spi-tegra114.c
@@ -859,6 +859,13 @@ static u32 tegra_spi_setup_transfer_one(struct spi_device *spi,
859 859 command1 |= SPI_BIT_LENGTH(bits_per_word - 1);
860 860 }
861 861
862 + /*
863 + * Re-assert the CS GPIO for every transfer: transfer_end() drops it
864 + * on cs_change, and the assert above only covers is_first_of_msg.
865 + */
866 + if (spi_get_csgpiod(spi, 0))
867 + gpiod_set_value(spi_get_csgpiod(spi, 0), 1);
868 +
862 869 return command1;
863 870 }
864 871
modified include/linux/maple_tree.h
@@ -507,13 +507,9 @@ struct ma_wr_state {
507 507 };
508 508
509 509 #define mas_lock(mas) spin_lock(&((mas)->tree->ma_lock))
510 - #define mas_lock_irqsave(mas, flags) \
511 - spin_lock_irqsave(&((mas)->tree->ma_lock), flags)
512 510 #define mas_lock_nested(mas, subclass) \
513 511 spin_lock_nested(&((mas)->tree->ma_lock), subclass)
514 512 #define mas_unlock(mas) spin_unlock(&((mas)->tree->ma_lock))
515 - #define mas_unlock_irqrestore(mas, flags) \
516 - spin_unlock_irqrestore(&((mas)->tree->ma_lock), flags)
517 513
518 514 /*
519 515 * Special values for ma_state.node.