spi: offload: Add offset parameter

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. While at it, add some documentation to offload periodic trigger
parameters.

Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
Link: https://patch.msgid.link/cd315e95c0bd8523f00e91c400abcd6a418e5924.1759760519.git.marcelo.schmitt@analog.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Axel Haslam 2025-10-06 11:25:41 -03:00 committed by Mark Brown
parent 3d66d3dbd5
commit b83fb1b14c
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
2 changed files with 12 additions and 0 deletions

View File

@ -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); 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 */ /* REVISIT: 50% duty-cycle for now - may add config parameter later */
wf.duty_length_ns = wf.period_length_ns / 2; 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); ret = pwm_round_waveform_might_sleep(st->pwm, &wf);
if (ret < 0) if (ret < 0)
return ret; return ret;
periodic->frequency_hz = DIV_ROUND_UP_ULL(NSEC_PER_SEC, wf.period_length_ns); periodic->frequency_hz = DIV_ROUND_UP_ULL(NSEC_PER_SEC, wf.period_length_ns);
periodic->offset_ns = wf.duty_offset_ns;
return 0; 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); 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 */ /* REVISIT: 50% duty-cycle for now - may add config parameter later */
wf.duty_length_ns = wf.period_length_ns / 2; 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); return pwm_set_waveform_might_sleep(st->pwm, &wf, false);
} }

View File

@ -57,8 +57,17 @@ enum spi_offload_trigger_type {
SPI_OFFLOAD_TRIGGER_PERIODIC, SPI_OFFLOAD_TRIGGER_PERIODIC,
}; };
/**
* 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.
*/
struct spi_offload_trigger_periodic { struct spi_offload_trigger_periodic {
u64 frequency_hz; u64 frequency_hz;
u64 offset_ns;
}; };
struct spi_offload_trigger_config { struct spi_offload_trigger_config {