drivers/pwm/pwm-renesas-tpu.c
Source file repositories/reference/linux-study-clean/drivers/pwm/pwm-renesas-tpu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pwm/pwm-renesas-tpu.c- Extension
.c- Size
- 12489 bytes
- Lines
- 506
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/err.hlinux/io.hlinux/init.hlinux/ioport.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/pm_runtime.hlinux/pwm.hlinux/slab.hlinux/spinlock.h
Detected Declarations
struct tpu_devicestruct tpu_pwm_devicestruct tpu_deviceenum tpu_pin_statefunction tpu_pwm_writefunction tpu_pwm_set_pinfunction tpu_pwm_start_stopfunction tpu_pwm_timer_startfunction tpu_pwm_timer_stopfunction tpu_pwm_requestfunction tpu_pwm_freefunction tpu_pwm_configfunction tpu_pwm_set_polarityfunction tpu_pwm_enablefunction tpu_pwm_disablefunction tpu_pwm_applyfunction tpu_probe
Annotated Snippet
struct tpu_pwm_device {
bool timer_on; /* Whether the timer is running */
struct tpu_device *tpu;
unsigned int channel; /* Channel number in the TPU */
enum pwm_polarity polarity;
unsigned int prescaler;
u16 period;
u16 duty;
};
struct tpu_device {
struct platform_device *pdev;
spinlock_t lock;
void __iomem *base;
struct clk *clk;
struct tpu_pwm_device tpd[TPU_CHANNEL_MAX];
};
static inline struct tpu_device *to_tpu_device(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static void tpu_pwm_write(struct tpu_pwm_device *tpd, int reg_nr, u16 value)
{
void __iomem *base = tpd->tpu->base + TPU_CHANNEL_OFFSET
+ tpd->channel * TPU_CHANNEL_SIZE;
iowrite16(value, base + reg_nr);
}
static void tpu_pwm_set_pin(struct tpu_pwm_device *tpd,
enum tpu_pin_state state)
{
static const char * const states[] = { "inactive", "PWM", "active" };
dev_dbg(&tpd->tpu->pdev->dev, "%u: configuring pin as %s\n",
tpd->channel, states[state]);
switch (state) {
case TPU_PIN_INACTIVE:
tpu_pwm_write(tpd, TPU_TIORn,
tpd->polarity == PWM_POLARITY_INVERSED ?
TPU_TIOR_IOA_1 : TPU_TIOR_IOA_0);
break;
case TPU_PIN_PWM:
tpu_pwm_write(tpd, TPU_TIORn,
tpd->polarity == PWM_POLARITY_INVERSED ?
TPU_TIOR_IOA_0_SET : TPU_TIOR_IOA_1_CLR);
break;
case TPU_PIN_ACTIVE:
tpu_pwm_write(tpd, TPU_TIORn,
tpd->polarity == PWM_POLARITY_INVERSED ?
TPU_TIOR_IOA_0 : TPU_TIOR_IOA_1);
break;
}
}
static void tpu_pwm_start_stop(struct tpu_pwm_device *tpd, int start)
{
unsigned long flags;
u16 value;
spin_lock_irqsave(&tpd->tpu->lock, flags);
value = ioread16(tpd->tpu->base + TPU_TSTR);
if (start)
value |= 1 << tpd->channel;
else
value &= ~(1 << tpd->channel);
iowrite16(value, tpd->tpu->base + TPU_TSTR);
spin_unlock_irqrestore(&tpd->tpu->lock, flags);
}
static int tpu_pwm_timer_start(struct tpu_pwm_device *tpd)
{
int ret;
if (!tpd->timer_on) {
/* Wake up device and enable clock. */
pm_runtime_get_sync(&tpd->tpu->pdev->dev);
ret = clk_prepare_enable(tpd->tpu->clk);
if (ret) {
dev_err(&tpd->tpu->pdev->dev, "cannot enable clock\n");
return ret;
}
Annotation
- Immediate include surface: `linux/clk.h`, `linux/err.h`, `linux/io.h`, `linux/init.h`, `linux/ioport.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`.
- Detected declarations: `struct tpu_device`, `struct tpu_pwm_device`, `struct tpu_device`, `enum tpu_pin_state`, `function tpu_pwm_write`, `function tpu_pwm_set_pin`, `function tpu_pwm_start_stop`, `function tpu_pwm_timer_start`, `function tpu_pwm_timer_stop`, `function tpu_pwm_request`.
- Atlas domain: Driver Families / drivers/pwm.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.