drivers/pwm/pwm-jz4740.c
Source file repositories/reference/linux-study-clean/drivers/pwm/pwm-jz4740.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pwm/pwm-jz4740.c- Extension
.c- Size
- 7330 bytes
- Lines
- 281
- 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/clk.hlinux/err.hlinux/kernel.hlinux/mfd/ingenic-tcu.hlinux/mfd/syscon.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/pwm.hlinux/regmap.h
Detected Declarations
struct soc_infostruct jz4740_pwm_chipfunction jz4740_pwm_can_use_chnfunction jz4740_pwm_requestfunction jz4740_pwm_freefunction jz4740_pwm_enablefunction jz4740_pwm_disablefunction jz4740_pwm_applyfunction jz4740_pwm_probe
Annotated Snippet
struct soc_info {
unsigned int num_pwms;
};
struct jz4740_pwm_chip {
struct regmap *map;
struct clk *clk[];
};
static inline struct jz4740_pwm_chip *to_jz4740(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static bool jz4740_pwm_can_use_chn(struct pwm_chip *chip, unsigned int channel)
{
/* Enable all TCU channels for PWM use by default except channels 0/1 */
u32 pwm_channels_mask = GENMASK(chip->npwm - 1, 2);
device_property_read_u32(pwmchip_parent(chip)->parent,
"ingenic,pwm-channels-mask",
&pwm_channels_mask);
return !!(pwm_channels_mask & BIT(channel));
}
static int jz4740_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
{
struct jz4740_pwm_chip *jz = to_jz4740(chip);
struct clk *clk;
char name[16];
int err;
if (!jz4740_pwm_can_use_chn(chip, pwm->hwpwm))
return -EBUSY;
snprintf(name, sizeof(name), "timer%u", pwm->hwpwm);
clk = clk_get(pwmchip_parent(chip), name);
if (IS_ERR(clk)) {
dev_err(pwmchip_parent(chip),
"error %pe: Failed to get clock\n", clk);
return PTR_ERR(clk);
}
err = clk_prepare_enable(clk);
if (err < 0) {
clk_put(clk);
return err;
}
jz->clk[pwm->hwpwm] = clk;
return 0;
}
static void jz4740_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
{
struct jz4740_pwm_chip *jz = to_jz4740(chip);
struct clk *clk = jz->clk[pwm->hwpwm];
clk_disable_unprepare(clk);
clk_put(clk);
}
static int jz4740_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
{
struct jz4740_pwm_chip *jz = to_jz4740(chip);
/* Enable PWM output */
regmap_set_bits(jz->map, TCU_REG_TCSRc(pwm->hwpwm), TCU_TCSR_PWM_EN);
/* Start counter */
regmap_write(jz->map, TCU_REG_TESR, BIT(pwm->hwpwm));
return 0;
}
static void jz4740_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
{
struct jz4740_pwm_chip *jz = to_jz4740(chip);
/*
* Set duty > period. This trick allows the TCU channels in TCU2 mode to
* properly return to their init level.
*/
regmap_write(jz->map, TCU_REG_TDHRc(pwm->hwpwm), 0xffff);
regmap_write(jz->map, TCU_REG_TDFRc(pwm->hwpwm), 0x0);
/*
Annotation
- Immediate include surface: `linux/clk.h`, `linux/err.h`, `linux/kernel.h`, `linux/mfd/ingenic-tcu.h`, `linux/mfd/syscon.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`.
- Detected declarations: `struct soc_info`, `struct jz4740_pwm_chip`, `function jz4740_pwm_can_use_chn`, `function jz4740_pwm_request`, `function jz4740_pwm_free`, `function jz4740_pwm_enable`, `function jz4740_pwm_disable`, `function jz4740_pwm_apply`, `function jz4740_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.