drivers/spi/spi-offload-trigger-pwm.c
Source file repositories/reference/linux-study-clean/drivers/spi/spi-offload-trigger-pwm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spi/spi-offload-trigger-pwm.c- Extension
.c- Size
- 4846 bytes
- Lines
- 173
- Domain
- Driver Families
- Bucket
- drivers/spi
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/err.hlinux/math.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/property.hlinux/pwm.hlinux/spi/offload/provider.hlinux/spi/offload/types.hlinux/time.hlinux/types.h
Detected Declarations
struct spi_offload_trigger_pwm_statefunction spi_offload_trigger_pwm_matchfunction spi_offload_trigger_pwm_validatefunction spi_offload_trigger_pwm_enablefunction spi_offload_trigger_pwm_disablefunction spi_offload_trigger_pwm_releasefunction spi_offload_trigger_pwm_probe
Annotated Snippet
struct spi_offload_trigger_pwm_state {
struct device *dev;
struct pwm_device *pwm;
};
static bool spi_offload_trigger_pwm_match(struct spi_offload_trigger *trigger,
enum spi_offload_trigger_type type,
u64 *args, u32 nargs)
{
if (nargs)
return false;
return type == SPI_OFFLOAD_TRIGGER_PERIODIC;
}
static int spi_offload_trigger_pwm_validate(struct spi_offload_trigger *trigger,
struct spi_offload_trigger_config *config)
{
struct spi_offload_trigger_pwm_state *st = spi_offload_trigger_get_priv(trigger);
struct spi_offload_trigger_periodic *periodic = &config->periodic;
struct pwm_waveform wf = { };
int ret;
if (config->type != SPI_OFFLOAD_TRIGGER_PERIODIC)
return -EINVAL;
if (!periodic->frequency_hz)
return -EINVAL;
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;
}
static int spi_offload_trigger_pwm_enable(struct spi_offload_trigger *trigger,
struct spi_offload_trigger_config *config)
{
struct spi_offload_trigger_pwm_state *st = spi_offload_trigger_get_priv(trigger);
struct spi_offload_trigger_periodic *periodic = &config->periodic;
struct pwm_waveform wf = { };
if (config->type != SPI_OFFLOAD_TRIGGER_PERIODIC)
return -EINVAL;
if (!periodic->frequency_hz)
return -EINVAL;
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);
}
static void spi_offload_trigger_pwm_disable(struct spi_offload_trigger *trigger)
{
struct spi_offload_trigger_pwm_state *st = spi_offload_trigger_get_priv(trigger);
struct pwm_waveform wf;
int ret;
ret = pwm_get_waveform_might_sleep(st->pwm, &wf);
if (ret < 0) {
dev_err(st->dev, "failed to get waveform: %d\n", ret);
return;
}
wf.duty_length_ns = 0;
ret = pwm_set_waveform_might_sleep(st->pwm, &wf, false);
if (ret < 0)
dev_err(st->dev, "failed to disable PWM: %d\n", ret);
}
static const struct spi_offload_trigger_ops spi_offload_trigger_pwm_ops = {
.match = spi_offload_trigger_pwm_match,
.validate = spi_offload_trigger_pwm_validate,
.enable = spi_offload_trigger_pwm_enable,
.disable = spi_offload_trigger_pwm_disable,
};
Annotation
- Immediate include surface: `linux/device.h`, `linux/err.h`, `linux/math.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_device.h`, `linux/property.h`, `linux/pwm.h`.
- Detected declarations: `struct spi_offload_trigger_pwm_state`, `function spi_offload_trigger_pwm_match`, `function spi_offload_trigger_pwm_validate`, `function spi_offload_trigger_pwm_enable`, `function spi_offload_trigger_pwm_disable`, `function spi_offload_trigger_pwm_release`, `function spi_offload_trigger_pwm_probe`.
- Atlas domain: Driver Families / drivers/spi.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.