Skip to contentSkip to conversation

Add SPI offload trigger offset

PATCH Superseded Marcelo Schmitt 2 participants 5 messages Sep 18, 2025

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add SPI offload trigger offset

This was initially proposed as part of a patch set to a driver in the IIO subsystem [1].

The changes to code in the SPI subsystem are minimal. From that first version to this one, the changes are:

Change log v1 -> v2
[SPI]
- Using upper case: adc -> ADC.
- Codestyle/readability improvements according to suggestions.

The updates to the ADC driver that use these changes proposed to the SPI subsystem will go in a patch set titled 'Add SPI offload support to AD4030'.

[1] https://lore.kernel.org/linux-iio/[email protected]/

Best regards,
Marcelo

Axel Haslam (2):
spi: offload: types: add offset parameter
spi: spi-offload-trigger-pwm: Use duty offset

 drivers/spi/spi-offload-trigger-pwm.c | 3 +++
 include/linux/spi/offload/types.h     | 1 +
 2 files changed, 4 insertions(+)

base-commit: e27fcbde216b317fecfd4487ffcd7f81726ac8ea

Signature · 1 line
2.50.1
#1 lore raw

PATCH v2 1/2 spi: offload: types: add offset parameter

From: Axel Haslam <[email protected]>

Add an offset parameter that can be passed in the periodic trigger. This is useful for example when ADC drivers implement a separate periodic signal to trigger conversion and need offload to read the result with some delay.

---
 include/linux/spi/offload/types.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/spi/offload/types.h +1 -0
index 6f7892347871..0170fd1f42e5 100644
@@ -59,6 +59,7 @@ enum spi_offload_trigger_type {
 
 struct spi_offload_trigger_periodic {
 	u64 frequency_hz;
+	u64 offset_ns;
 };
 
 struct spi_offload_trigger_config {
Signature · 1 line
2.50.1
#3 lore raw

PATCH v2 2/2 spi: spi-offload-trigger-pwm: Use duty offset

In reply to Marcelo Schmitt

From: Axel Haslam <[email protected]>

Pass the duty offset to the waveform pwm.

---
 drivers/spi/spi-offload-trigger-pwm.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/spi/spi-offload-trigger-pwm.c +3 -0
index 805ed41560df..3e8c19227edb 100644
@@ -51,12 +51,14 @@ static int spi_offload_trigger_pwm_validate(struct spi_offload_trigger *trigger,
 	wf.period_length_ns = DIV_ROUND_UP_ULL(NSEC_PER_SEC, periodic->frequency_hz);
 	/* REVISIT: 50% duty-cycle for now - may add config parameter later */
 	wf.duty_length_ns = wf.period_length_ns / 2;
+	wf.duty_offset_ns = periodic->offset_ns;
 
 	ret = pwm_round_waveform_might_sleep(st->pwm, &wf);
 	if (ret < 0)
 		return ret;
 
 	periodic->frequency_hz = DIV_ROUND_UP_ULL(NSEC_PER_SEC, wf.period_length_ns);
+	periodic->offset_ns = wf.duty_offset_ns;
 
 	return 0;
 }
@@ -77,6 +79,7 @@ static int spi_offload_trigger_pwm_enable(struct spi_offload_trigger *trigger,
 	wf.period_length_ns = DIV_ROUND_UP_ULL(NSEC_PER_SEC, periodic->frequency_hz);
 	/* REVISIT: 50% duty-cycle for now - may add config parameter later */
 	wf.duty_length_ns = wf.period_length_ns / 2;
+	wf.duty_offset_ns = periodic->offset_ns;
 
 	return pwm_set_waveform_might_sleep(st->pwm, &wf, false);
 }
Signature · 1 line
2.50.1
reviewer
#2 lore raw

Re: [PATCH v2 1/2] spi: offload: types: add offset parameter

In reply to Marcelo Schmitt
Quoted 18 lines · Marcelo Schmitt

From: Axel Haslam <[email protected]>

Add an offset parameter that can be passed in the periodic trigger. This is useful for example when ADC drivers implement a separate periodic signal to trigger conversion and need offload to read the result with some delay.

---
 include/linux/spi/offload/types.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/spi/offload/types.h +0 -0
index 6f7892347871..0170fd1f42e5 100644

include/linux/spi/offload/types.h enum spi_offload_trigger_type { · line 59

Quoted 1 line
include/linux/spi/offload/types.h +0 -0
@@ -59,6 +59,7 @@ enum spi_offload_trigger_type {
 

I think this would be a good time to add some documentation comments:

/**
* spi_offload_trigger_periodic - configuration parameters for periodic triggers
* @frequency_hz: The rate that the trigger should fire in Hz.
* @offset_ns: A delay in nanoseconds between when this trigger fires
* compared to another trigger. This requires specialized hardware
* that supports such synchronization with a delay between two or
* more triggers. Set to 0 when not needed.
*/

Quoted 6 lines
include/linux/spi/offload/types.h +1 -0
 struct spi_offload_trigger_periodic {
 	u64 frequency_hz;
+	u64 offset_ns;
 };
 
 struct spi_offload_trigger_config {
reviewer
#4 lore raw

Re: [PATCH v2 2/2] spi: spi-offload-trigger-pwm: Use duty offset

In reply to Marcelo Schmitt
Quoted 30 lines · Marcelo Schmitt

From: Axel Haslam <[email protected]>

Pass the duty offset to the waveform pwm.

---
 drivers/spi/spi-offload-trigger-pwm.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/spi/spi-offload-trigger-pwm.c +2 -0
index 805ed41560df..3e8c19227edb 100644
@@ -51,12 +51,14 @@ static int spi_offload_trigger_pwm_validate(struct spi_offload_trigger *trigger,
 	wf.period_length_ns = DIV_ROUND_UP_ULL(NSEC_PER_SEC, periodic->frequency_hz);
 	/* REVISIT: 50% duty-cycle for now - may add config parameter later */
 	wf.duty_length_ns = wf.period_length_ns / 2;
+	wf.duty_offset_ns = periodic->offset_ns;
 
 	ret = pwm_round_waveform_might_sleep(st->pwm, &wf);
 	if (ret < 0)
 		return ret;
 
 	periodic->frequency_hz = DIV_ROUND_UP_ULL(NSEC_PER_SEC, wf.period_length_ns);
+	periodic->offset_ns = wf.duty_offset_ns;
 
 	return 0;
 }

drivers/spi/spi-offload-trigger-pwm.c static int spi_offload_trigger_pwm_enable(struct spi_offload_trigger *trigger, · line 85

Quoted 7 lines
drivers/spi/spi-offload-trigger-pwm.c +1 -0
@@ -77,6 +79,7 @@ static int spi_offload_trigger_pwm_enable(struct spi_offload_trigger *trigger,
 	wf.period_length_ns = DIV_ROUND_UP_ULL(NSEC_PER_SEC, periodic->frequency_hz);
 	/* REVISIT: 50% duty-cycle for now - may add config parameter later */
 	wf.duty_length_ns = wf.period_length_ns / 2;
+	wf.duty_offset_ns = periodic->offset_ns;
 
 	return pwm_set_waveform_might_sleep(st->pwm, &wf, false);
 }

Does this really need to be a separate patch from the one that adds the field?