drivers/pwm/pwm-raspberrypi-poe.c
Source file repositories/reference/linux-study-clean/drivers/pwm/pwm-raspberrypi-poe.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pwm/pwm-raspberrypi-poe.c- Extension
.c- Size
- 4832 bytes
- Lines
- 197
- Domain
- Driver Families
- Bucket
- drivers/pwm
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/of.hlinux/platform_device.hlinux/pwm.hsoc/bcm2835/raspberrypi-firmware.hdt-bindings/pwm/raspberrypi,firmware-poe-pwm.h
Detected Declarations
struct raspberrypi_pwmstruct raspberrypi_pwm_propfunction raspberrypi_pwm_set_propertyfunction raspberrypi_pwm_get_propertyfunction raspberrypi_pwm_get_statefunction raspberrypi_pwm_applyfunction raspberrypi_pwm_probe
Annotated Snippet
struct raspberrypi_pwm {
struct rpi_firmware *firmware;
unsigned int duty_cycle;
};
struct raspberrypi_pwm_prop {
__le32 reg;
__le32 val;
__le32 ret;
} __packed;
static inline
struct raspberrypi_pwm *raspberrypi_pwm_from_chip(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static int raspberrypi_pwm_set_property(struct rpi_firmware *firmware,
u32 reg, u32 val)
{
struct raspberrypi_pwm_prop msg = {
.reg = cpu_to_le32(reg),
.val = cpu_to_le32(val),
};
int ret;
ret = rpi_firmware_property(firmware, RPI_FIRMWARE_SET_POE_HAT_VAL,
&msg, sizeof(msg));
if (ret)
return ret;
if (msg.ret)
return -EIO;
return 0;
}
static int raspberrypi_pwm_get_property(struct rpi_firmware *firmware,
u32 reg, u32 *val)
{
struct raspberrypi_pwm_prop msg = {
.reg = cpu_to_le32(reg),
};
int ret;
ret = rpi_firmware_property(firmware, RPI_FIRMWARE_GET_POE_HAT_VAL,
&msg, sizeof(msg));
if (ret)
return ret;
if (msg.ret)
return -EIO;
*val = le32_to_cpu(msg.val);
return 0;
}
static int raspberrypi_pwm_get_state(struct pwm_chip *chip,
struct pwm_device *pwm,
struct pwm_state *state)
{
struct raspberrypi_pwm *rpipwm = raspberrypi_pwm_from_chip(chip);
state->period = RPI_PWM_PERIOD_NS;
state->duty_cycle = DIV_ROUND_UP(rpipwm->duty_cycle * RPI_PWM_PERIOD_NS,
RPI_PWM_MAX_DUTY);
state->enabled = !!(rpipwm->duty_cycle);
state->polarity = PWM_POLARITY_NORMAL;
return 0;
}
static int raspberrypi_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
const struct pwm_state *state)
{
struct raspberrypi_pwm *rpipwm = raspberrypi_pwm_from_chip(chip);
unsigned int duty_cycle;
int ret;
if (state->period < RPI_PWM_PERIOD_NS ||
state->polarity != PWM_POLARITY_NORMAL)
return -EINVAL;
if (!state->enabled)
duty_cycle = 0;
else if (state->duty_cycle < RPI_PWM_PERIOD_NS)
duty_cycle = DIV_ROUND_DOWN_ULL(state->duty_cycle * RPI_PWM_MAX_DUTY,
RPI_PWM_PERIOD_NS);
else
duty_cycle = RPI_PWM_MAX_DUTY;
Annotation
- Immediate include surface: `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/pwm.h`, `soc/bcm2835/raspberrypi-firmware.h`, `dt-bindings/pwm/raspberrypi,firmware-poe-pwm.h`.
- Detected declarations: `struct raspberrypi_pwm`, `struct raspberrypi_pwm_prop`, `function raspberrypi_pwm_set_property`, `function raspberrypi_pwm_get_property`, `function raspberrypi_pwm_get_state`, `function raspberrypi_pwm_apply`, `function raspberrypi_pwm_probe`.
- Atlas domain: Driver Families / drivers/pwm.
- 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.