include/linux/pwm.h

Source file repositories/reference/linux-study-clean/include/linux/pwm.h

File Facts

System
Linux kernel
Corpus path
include/linux/pwm.h
Extension
.h
Size
18520 bytes
Lines
661
Domain
Core OS
Bucket
Core Kernel Interface
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct pwm_args {
	u64 period;
	enum pwm_polarity polarity;
};

enum {
	PWMF_REQUESTED = 0,
	PWMF_EXPORTED = 1,
};

/**
 * struct pwm_waveform - description of a PWM waveform
 * @period_length_ns: PWM period
 * @duty_length_ns: PWM duty cycle
 * @duty_offset_ns: offset of the rising edge from the period's start
 *
 * This is a representation of a PWM waveform alternative to struct pwm_state
 * below. It's more expressive than struct pwm_state as it contains a
 * duty_offset_ns and so can represent offsets other than zero (with .polarity =
 * PWM_POLARITY_NORMAL) and period - duty_cycle (.polarity =
 * PWM_POLARITY_INVERSED).
 *
 * Note there is no explicit bool for enabled. A "disabled" PWM is represented
 * by .period_length_ns = 0. Note further that the behaviour of a "disabled" PWM
 * is undefined. Depending on the hardware's capabilities it might drive the
 * active or inactive level, go high-z or even continue to toggle.
 *
 * The unit for all three members is nanoseconds.
 */
struct pwm_waveform {
	u64 period_length_ns;
	u64 duty_length_ns;
	u64 duty_offset_ns;
};

/*
 * struct pwm_state - state of a PWM channel
 * @period: PWM period (in nanoseconds)
 * @duty_cycle: PWM duty cycle (in nanoseconds)
 * @polarity: PWM polarity
 * @enabled: PWM enabled status
 * @usage_power: If set, the PWM driver is only required to maintain the power
 *               output but has more freedom regarding signal form.
 *               If supported, the signal can be optimized, for example to
 *               improve EMI by phase shifting individual channels.
 */
struct pwm_state {
	u64 period;
	u64 duty_cycle;
	enum pwm_polarity polarity;
	bool enabled;
	bool usage_power;
};

/**
 * struct pwm_device - PWM channel object
 * @label: name of the PWM device
 * @flags: flags associated with the PWM device
 * @hwpwm: per-chip relative index of the PWM device
 * @chip: PWM chip providing this PWM device
 * @args: PWM arguments
 * @state: last applied state
 * @last: last implemented state (for PWM_DEBUG)
 */
struct pwm_device {
	const char *label;
	unsigned long flags;
	unsigned int hwpwm;
	struct pwm_chip *chip;

	struct pwm_args args;
	struct pwm_state state;
	struct pwm_state last;
};

/**
 * pwm_get_state() - retrieve the current PWM state
 * @pwm: PWM device
 * @state: state to fill with the current PWM state
 *
 * The returned PWM state represents the state that was applied by a previous call to
 * pwm_apply_might_sleep(). Drivers may have to slightly tweak that state before programming it to
 * hardware. If pwm_apply_might_sleep() was never called, this returns either the current hardware
 * state (if supported) or the default settings.
 */
static inline void pwm_get_state(const struct pwm_device *pwm,
				 struct pwm_state *state)
{
	*state = pwm->state;
}

Annotation

Implementation Notes