drivers/thermal/khadas_mcu_fan.c
Source file repositories/reference/linux-study-clean/drivers/thermal/khadas_mcu_fan.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/khadas_mcu_fan.c- Extension
.c- Size
- 3681 bytes
- Lines
- 163
- Domain
- Driver Families
- Bucket
- drivers/thermal
- 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/module.hlinux/of.hlinux/platform_device.hlinux/mfd/khadas-mcu.hlinux/regmap.hlinux/sysfs.hlinux/thermal.h
Detected Declarations
struct khadas_mcu_fan_ctxfunction khadas_mcu_fan_set_levelfunction khadas_mcu_fan_get_max_statefunction khadas_mcu_fan_get_cur_statefunction khadas_mcu_fan_set_cur_statefunction khadas_mcu_fan_probefunction khadas_mcu_fan_shutdownfunction khadas_mcu_fan_suspendfunction khadas_mcu_fan_resume
Annotated Snippet
struct khadas_mcu_fan_ctx {
struct khadas_mcu *mcu;
unsigned int level;
struct thermal_cooling_device *cdev;
};
static int khadas_mcu_fan_set_level(struct khadas_mcu_fan_ctx *ctx,
unsigned int level)
{
int ret;
ret = regmap_write(ctx->mcu->regmap, KHADAS_MCU_CMD_FAN_STATUS_CTRL_REG,
level);
if (ret)
return ret;
ctx->level = level;
return 0;
}
static int khadas_mcu_fan_get_max_state(struct thermal_cooling_device *cdev,
unsigned long *state)
{
*state = MAX_LEVEL;
return 0;
}
static int khadas_mcu_fan_get_cur_state(struct thermal_cooling_device *cdev,
unsigned long *state)
{
struct khadas_mcu_fan_ctx *ctx = cdev->devdata;
*state = ctx->level;
return 0;
}
static int
khadas_mcu_fan_set_cur_state(struct thermal_cooling_device *cdev,
unsigned long state)
{
struct khadas_mcu_fan_ctx *ctx = cdev->devdata;
if (state > MAX_LEVEL)
return -EINVAL;
if (state == ctx->level)
return 0;
return khadas_mcu_fan_set_level(ctx, state);
}
static const struct thermal_cooling_device_ops khadas_mcu_fan_cooling_ops = {
.get_max_state = khadas_mcu_fan_get_max_state,
.get_cur_state = khadas_mcu_fan_get_cur_state,
.set_cur_state = khadas_mcu_fan_set_cur_state,
};
static int khadas_mcu_fan_probe(struct platform_device *pdev)
{
struct khadas_mcu *mcu = dev_get_drvdata(pdev->dev.parent);
struct thermal_cooling_device *cdev;
struct device *dev = &pdev->dev;
struct khadas_mcu_fan_ctx *ctx;
int ret;
ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
if (!ctx)
return -ENOMEM;
ctx->mcu = mcu;
platform_set_drvdata(pdev, ctx);
cdev = devm_thermal_of_child_cooling_device_register(dev->parent,
dev->parent->of_node,
"khadas-mcu-fan", ctx,
&khadas_mcu_fan_cooling_ops);
if (IS_ERR(cdev)) {
ret = PTR_ERR(cdev);
dev_err(dev, "Failed to register khadas-mcu-fan as cooling device: %d\n",
ret);
return ret;
}
ctx->cdev = cdev;
return 0;
}
static void khadas_mcu_fan_shutdown(struct platform_device *pdev)
Annotation
- Immediate include surface: `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/mfd/khadas-mcu.h`, `linux/regmap.h`, `linux/sysfs.h`, `linux/thermal.h`.
- Detected declarations: `struct khadas_mcu_fan_ctx`, `function khadas_mcu_fan_set_level`, `function khadas_mcu_fan_get_max_state`, `function khadas_mcu_fan_get_cur_state`, `function khadas_mcu_fan_set_cur_state`, `function khadas_mcu_fan_probe`, `function khadas_mcu_fan_shutdown`, `function khadas_mcu_fan_suspend`, `function khadas_mcu_fan_resume`.
- Atlas domain: Driver Families / drivers/thermal.
- 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.