Compare
c9fc60c18b6d42efdea0cd88ca132b2f452157c3..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
8 files changed,
+44
−56
- drivers/spi/spi-tegra114.c
- fs/tracefs/event_inode.c
- kernel/trace/Makefile
- kernel/trace/ring_buffer.c
- kernel/trace/trace.c
- kernel/trace/trace_events_hist.c
- kernel/trace/trace_snapshot.c
- kernel/trace/undefsyms_base.c
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 fs/tracefs/event_inode.c
| @@ -91,14 +91,6 @@ static void free_ei_rcu(struct rcu_head *rcu) | |||
| 91 | 91 | } | |
| 92 | 92 | } | |
| 93 | 93 | ||
| 94 | - | /* read under eventfs_srcu and, by tracefs_d_revalidate(), in rcu pathwalk */ | |
| 95 | - | static void free_ei_srcu(struct rcu_head *rcu) | |
| 96 | - | { | |
| 97 | - | struct eventfs_inode *ei = container_of(rcu, struct eventfs_inode, rcu); | |
| 98 | - | ||
| 99 | - | call_rcu(&ei->rcu, free_ei_rcu); | |
| 100 | - | } | |
| 101 | - | ||
| 102 | 94 | /* | |
| 103 | 95 | * eventfs_inode reference count management. | |
| 104 | 96 | * | |
| @@ -120,7 +112,7 @@ static void release_ei(struct kref *ref) | |||
| 120 | 112 | entry->release(entry->name, ei->data); | |
| 121 | 113 | } | |
| 122 | 114 | ||
| 123 | - | call_srcu(&eventfs_srcu, &ei->rcu, free_ei_srcu); | |
| 115 | + | call_srcu(&eventfs_srcu, &ei->rcu, free_ei_rcu); | |
| 124 | 116 | } | |
| 125 | 117 | ||
| 126 | 118 | static inline void put_ei(struct eventfs_inode *ei) | |
modified kernel/trace/Makefile
| @@ -146,12 +146,11 @@ KASAN_SANITIZE_undefsyms_base.o := y | |||
| 146 | 146 | ||
| 147 | 147 | UNDEFINED_ALLOWLIST = __asan __gcov __kasan __kcsan __hwasan __sancov __sanitizer __tsan __ubsan __msan \ | |
| 148 | 148 | __aeabi_unwind_cpp __s390_indirect_jump __x86_indirect_thunk simple_ring_buffer \ | |
| 149 | - | current_thread_info_reg \ | |
| 150 | - | $(shell $(NM) -u $(obj)/undefsyms_base.o 2>/dev/null | awk '$$2 {print $$2}') | |
| 149 | + | $(shell $(NM) -u $(obj)/undefsyms_base.o 2>/dev/null | awk '{print $$2}') | |
| 151 | 150 | ||
| 152 | 151 | quiet_cmd_check_undefined = NM $< | |
| 153 | 152 | cmd_check_undefined = \ | |
| 154 | - | undefsyms=$$($(NM) -u $< | awk '$$2 {print $$2}' | grep -v $(addprefix -e , $(UNDEFINED_ALLOWLIST)) || true); \ | |
| 153 | + | undefsyms=$$($(NM) -u $< | grep -v $(addprefix -e , $(UNDEFINED_ALLOWLIST)) || true); \ | |
| 155 | 154 | if [ -n "$$undefsyms" ]; then \ | |
| 156 | 155 | echo "Unexpected symbols in $<:" >&2; \ | |
| 157 | 156 | echo "$$undefsyms" >&2; \ | |
modified kernel/trace/ring_buffer.c
| @@ -2380,9 +2380,6 @@ int ring_buffer_meta_seq_init(struct file *file, struct trace_buffer *buffer, in | |||
| 2380 | 2380 | struct seq_file *m; | |
| 2381 | 2381 | int ret; | |
| 2382 | 2382 | ||
| 2383 | - | if (!cpumask_test_cpu(cpu, buffer->cpumask)) | |
| 2384 | - | return -ENODEV; | |
| 2385 | - | ||
| 2386 | 2383 | ret = seq_open(file, &rb_meta_seq_ops); | |
| 2387 | 2384 | if (ret) | |
| 2388 | 2385 | return ret; | |
| @@ -2445,30 +2442,20 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer, | |||
| 2445 | 2442 | struct trace_buffer *buffer = cpu_buffer->buffer; | |
| 2446 | 2443 | struct ring_buffer_cpu_meta *meta = NULL; | |
| 2447 | 2444 | struct buffer_page *bpage, *tmp; | |
| 2445 | + | bool user_thread = current->mm != NULL; | |
| 2448 | 2446 | struct ring_buffer_desc *desc = NULL; | |
| 2449 | - | bool user_thread = false; | |
| 2450 | 2447 | long i; | |
| 2451 | 2448 | ||
| 2452 | - | if (buffer->range_addr_start) { | |
| 2453 | - | meta = rb_range_meta(buffer, nr_pages, cpu_buffer->cpu); | |
| 2454 | - | } else if (buffer->remote) { | |
| 2455 | - | desc = ring_buffer_desc(buffer->remote->desc, cpu_buffer->cpu); | |
| 2456 | - | if (!desc || WARN_ON(desc->nr_page_va != (nr_pages + 1))) | |
| 2457 | - | return -EINVAL; | |
| 2458 | - | } else { | |
| 2459 | - | /* | |
| 2460 | - | * Check if the available memory is there first. | |
| 2461 | - | * Note, si_mem_available() only gives us a rough estimate of available | |
| 2462 | - | * memory. It may not be accurate. But we don't care, we just want | |
| 2463 | - | * to prevent doing any allocation when it is obvious that it is | |
| 2464 | - | * not going to succeed. | |
| 2465 | - | */ | |
| 2466 | - | i = si_mem_available(); | |
| 2467 | - | if (i < nr_pages) | |
| 2468 | - | return -ENOMEM; | |
| 2469 | - | ||
| 2470 | - | user_thread = current->mm != NULL; | |
| 2471 | - | } | |
| 2449 | + | /* | |
| 2450 | + | * Check if the available memory is there first. | |
| 2451 | + | * Note, si_mem_available() only gives us a rough estimate of available | |
| 2452 | + | * memory. It may not be accurate. But we don't care, we just want | |
| 2453 | + | * to prevent doing any allocation when it is obvious that it is | |
| 2454 | + | * not going to succeed. | |
| 2455 | + | */ | |
| 2456 | + | i = si_mem_available(); | |
| 2457 | + | if (i < nr_pages) | |
| 2458 | + | return -ENOMEM; | |
| 2472 | 2459 | ||
| 2473 | 2460 | /* | |
| 2474 | 2461 | * If a user thread allocates too much, and si_mem_available() | |
| @@ -2482,6 +2469,15 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer, | |||
| 2482 | 2469 | if (user_thread) | |
| 2483 | 2470 | set_current_oom_origin(); | |
| 2484 | 2471 | ||
| 2472 | + | if (buffer->range_addr_start) | |
| 2473 | + | meta = rb_range_meta(buffer, nr_pages, cpu_buffer->cpu); | |
| 2474 | + | ||
| 2475 | + | if (buffer->remote) { | |
| 2476 | + | desc = ring_buffer_desc(buffer->remote->desc, cpu_buffer->cpu); | |
| 2477 | + | if (!desc || WARN_ON(desc->nr_page_va != (nr_pages + 1))) | |
| 2478 | + | return -EINVAL; | |
| 2479 | + | } | |
| 2480 | + | ||
| 2485 | 2481 | for (i = 0; i < nr_pages; i++) { | |
| 2486 | 2482 | ||
| 2487 | 2483 | bpage = alloc_cpu_page(cpu_buffer->cpu); | |
| @@ -3631,8 +3627,10 @@ static void rb_inc_iter(struct ring_buffer_iter *iter) | |||
| 3631 | 3627 | /* Return the index into the sub-buffers for a given sub-buffer */ | |
| 3632 | 3628 | static int rb_meta_subbuf_idx(struct ring_buffer_cpu_meta *meta, void *subbuf) | |
| 3633 | 3629 | { | |
| 3634 | - | void *subbuf_array = rb_subbufs_from_meta(meta); | |
| 3630 | + | void *subbuf_array; | |
| 3635 | 3631 | ||
| 3632 | + | subbuf_array = (void *)meta + sizeof(int) * meta->nr_subbufs; | |
| 3633 | + | subbuf_array = (void *)ALIGN((unsigned long)subbuf_array, meta->subbuf_size); | |
| 3636 | 3634 | return (subbuf - subbuf_array) / meta->subbuf_size; | |
| 3637 | 3635 | } | |
| 3638 | 3636 | ||
| @@ -7999,8 +7997,12 @@ consume: | |||
| 7999 | 7997 | goto out; | |
| 8000 | 7998 | } | |
| 8001 | 7999 | ||
| 8000 | + | /* Did the reader catch up with the writer? */ | |
| 8001 | + | if (cpu_buffer->reader_page == cpu_buffer->commit_page) | |
| 8002 | + | goto out; | |
| 8003 | + | ||
| 8002 | 8004 | reader = rb_get_reader_page(cpu_buffer); | |
| 8003 | - | if (!reader) | |
| 8005 | + | if (WARN_ON(!reader)) | |
| 8004 | 8006 | goto out; | |
| 8005 | 8007 | ||
| 8006 | 8008 | /* Check if any events were dropped */ | |
modified kernel/trace/trace.c
| @@ -5881,7 +5881,7 @@ static int tracing_buffer_meta_open(struct inode *inode, struct file *filp) | |||
| 5881 | 5881 | ||
| 5882 | 5882 | ret = ring_buffer_meta_seq_init(filp, tr->array_buffer.buffer, cpu); | |
| 5883 | 5883 | if (ret < 0) | |
| 5884 | - | trace_array_put(tr); | |
| 5884 | + | __trace_array_put(tr); | |
| 5885 | 5885 | return ret; | |
| 5886 | 5886 | } | |
| 5887 | 5887 | ||
| @@ -9287,12 +9287,6 @@ static struct notifier_block trace_module_nb = { | |||
| 9287 | 9287 | ||
| 9288 | 9288 | static __init void tracer_init_tracefs_work_func(struct work_struct *work) | |
| 9289 | 9289 | { | |
| 9290 | - | /* | |
| 9291 | - | * Do not attempt to initialize tracefs if tracing was disabled or | |
| 9292 | - | * failed to allocate | |
| 9293 | - | */ | |
| 9294 | - | if (tracing_disabled) | |
| 9295 | - | return; | |
| 9296 | 9290 | ||
| 9297 | 9291 | event_trace_init(); | |
| 9298 | 9292 | ||
modified kernel/trace/trace_events_hist.c
| @@ -289,7 +289,7 @@ static u64 hist_field_log2(struct hist_field *hist_field, | |||
| 289 | 289 | ||
| 290 | 290 | u64 val = hist_fn_call(operand, elt, buffer, rbe, event); | |
| 291 | 291 | ||
| 292 | - | return order_base_2(val); | |
| 292 | + | return (u64) ilog2(roundup_pow_of_two(val)); | |
| 293 | 293 | } | |
| 294 | 294 | ||
| 295 | 295 | static u64 hist_field_bucket(struct hist_field *hist_field, | |
| @@ -873,7 +873,7 @@ static u64 hist_field_timestamp(struct hist_field *hist_field, | |||
| 873 | 873 | struct hist_trigger_data *hist_data = hist_field->hist_data; | |
| 874 | 874 | struct trace_array *tr = hist_data->event_file->tr; | |
| 875 | 875 | ||
| 876 | - | u64 ts = tracing_event_time_stamp(buffer, rbe); | |
| 876 | + | u64 ts = ring_buffer_event_time_stamp(buffer, rbe); | |
| 877 | 877 | ||
| 878 | 878 | if (hist_data->attrs->ts_in_usecs && trace_clock_in_ns(tr)) | |
| 879 | 879 | ts = ns2usecs(ts); | |
| @@ -3090,7 +3090,7 @@ create_field_var_hist(struct hist_trigger_data *target_hist_data, | |||
| 3090 | 3090 | key_field = hist_data->fields[i]; | |
| 3091 | 3091 | if (!first) | |
| 3092 | 3092 | seq_buf_putc(&s, ','); | |
| 3093 | - | expr_field_str(key_field, &s); | |
| 3093 | + | seq_buf_puts(&s, key_field->field->name); | |
| 3094 | 3094 | first = false; | |
| 3095 | 3095 | } | |
| 3096 | 3096 | ||
modified kernel/trace/trace_snapshot.c
| @@ -675,12 +675,9 @@ tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt, | |||
| 675 | 675 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) | |
| 676 | 676 | return -EINVAL; | |
| 677 | 677 | #endif | |
| 678 | - | if (tr->allocated_snapshot) { | |
| 678 | + | if (tr->allocated_snapshot) | |
| 679 | 679 | ret = resize_buffer_duplicate_size(&tr->snapshot_buffer, | |
| 680 | 680 | &tr->array_buffer, iter->cpu_file); | |
| 681 | - | if (ret < 0) | |
| 682 | - | return ret; | |
| 683 | - | } | |
| 684 | 681 | ||
| 685 | 682 | ret = tracing_arm_snapshot_locked(tr); | |
| 686 | 683 | if (ret) | |
modified kernel/trace/undefsyms_base.c
| @@ -9,7 +9,6 @@ | |||
| 9 | 9 | ||
| 10 | 10 | #include <linux/atomic.h> | |
| 11 | 11 | #include <linux/string.h> | |
| 12 | - | #include <asm/local.h> | |
| 13 | 12 | #include <asm/page.h> | |
| 14 | 13 | ||
| 15 | 14 | void undefsyms_base(void *p, int n); | |
| @@ -19,13 +18,11 @@ static char page[PAGE_SIZE] __aligned(PAGE_SIZE); | |||
| 19 | 18 | void undefsyms_base(void *p, int n) | |
| 20 | 19 | { | |
| 21 | 20 | char buffer[256] = { 0 }; | |
| 22 | - | u32 u = 0; | |
| 23 | 21 | ||
| 22 | + | u32 u = 0; | |
| 24 | 23 | memset((char * volatile)page, 8, PAGE_SIZE); | |
| 25 | 24 | memset((char * volatile)buffer, 8, sizeof(buffer)); | |
| 26 | 25 | memcpy((void * volatile)p, buffer, sizeof(buffer)); | |
| 27 | 26 | cmpxchg((u32 * volatile)&u, 0, 8); | |
| 28 | - | cmpxchg((unsigned long *)p, 0, 8); | |
| 29 | - | local_set((local_t *)p, 8); | |
| 30 | 27 | WARN_ON(n == 0xdeadbeef); | |
| 31 | 28 | } | |