drivers/hwmon/gxp-fan-ctrl.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/gxp-fan-ctrl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/gxp-fan-ctrl.c- Extension
.c- Size
- 6002 bytes
- Lines
- 254
- Domain
- Driver Families
- Bucket
- drivers/hwmon
- 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/bits.hlinux/err.hlinux/hwmon.hlinux/io.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.h
Detected Declarations
struct gxp_fan_ctrl_drvdatafunction fan_installedfunction fan_failedfunction fan_enabledfunction gxp_pwm_writefunction gxp_fan_ctrl_writefunction gxp_fan_readfunction gxp_pwm_readfunction gxp_fan_ctrl_readfunction gxp_fan_ctrl_is_visiblefunction gxp_fan_ctrl_probe
Annotated Snippet
struct gxp_fan_ctrl_drvdata {
void __iomem *base;
void __iomem *plreg;
void __iomem *fn2;
};
static bool fan_installed(struct device *dev, int fan)
{
struct gxp_fan_ctrl_drvdata *drvdata = dev_get_drvdata(dev);
u8 val;
val = readb(drvdata->plreg + OFS_FAN_INST);
return !!(val & BIT(fan));
}
static long fan_failed(struct device *dev, int fan)
{
struct gxp_fan_ctrl_drvdata *drvdata = dev_get_drvdata(dev);
u8 val;
val = readb(drvdata->plreg + OFS_FAN_FAIL);
return !!(val & BIT(fan));
}
static long fan_enabled(struct device *dev, int fan)
{
struct gxp_fan_ctrl_drvdata *drvdata = dev_get_drvdata(dev);
u32 val;
/*
* Check the power status as if the platform is off the value
* reported for the PWM will be incorrect. Report fan as
* disabled.
*/
val = readl(drvdata->fn2 + OFS_SEVSTAT);
return !!((val & BIT(POWER_BIT)) && fan_installed(dev, fan));
}
static int gxp_pwm_write(struct device *dev, u32 attr, int channel, long val)
{
struct gxp_fan_ctrl_drvdata *drvdata = dev_get_drvdata(dev);
switch (attr) {
case hwmon_pwm_input:
if (val > 255 || val < 0)
return -EINVAL;
writeb(val, drvdata->base + channel);
return 0;
default:
return -EOPNOTSUPP;
}
}
static int gxp_fan_ctrl_write(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long val)
{
switch (type) {
case hwmon_pwm:
return gxp_pwm_write(dev, attr, channel, val);
default:
return -EOPNOTSUPP;
}
}
static int gxp_fan_read(struct device *dev, u32 attr, int channel, long *val)
{
switch (attr) {
case hwmon_fan_enable:
*val = fan_enabled(dev, channel);
return 0;
case hwmon_fan_fault:
*val = fan_failed(dev, channel);
return 0;
default:
return -EOPNOTSUPP;
}
}
static int gxp_pwm_read(struct device *dev, u32 attr, int channel, long *val)
{
struct gxp_fan_ctrl_drvdata *drvdata = dev_get_drvdata(dev);
u32 reg;
/*
* Check the power status of the platform. If the platform is off
* the value reported for the PWM will be incorrect. In this case
* report a PWM of zero.
Annotation
- Immediate include surface: `linux/bits.h`, `linux/err.h`, `linux/hwmon.h`, `linux/io.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`.
- Detected declarations: `struct gxp_fan_ctrl_drvdata`, `function fan_installed`, `function fan_failed`, `function fan_enabled`, `function gxp_pwm_write`, `function gxp_fan_ctrl_write`, `function gxp_fan_read`, `function gxp_pwm_read`, `function gxp_fan_ctrl_read`, `function gxp_fan_ctrl_is_visible`.
- Atlas domain: Driver Families / drivers/hwmon.
- 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.