drivers/hwmon/npcm750-pwm-fan.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/npcm750-pwm-fan.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/npcm750-pwm-fan.c- Extension
.c- Size
- 29558 bytes
- Lines
- 1054
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/clk.hlinux/device.hlinux/hwmon.hlinux/interrupt.hlinux/kernel.hlinux/module.hlinux/of_address.hlinux/of_irq.hlinux/platform_device.hlinux/spinlock.hlinux/sysfs.hlinux/thermal.h
Detected Declarations
struct npcm_hwmon_infostruct npcm7xx_fan_devstruct npcm7xx_cooling_devicestruct npcm7xx_pwm_fan_datafunction npcm7xx_pwm_config_setfunction npcm7xx_fan_start_capturefunction npcm7xx_fan_pollingfunction npcm7xx_fan_computefunction npcm7xx_check_cmpfunction npcm7xx_fan_isrfunction npcm7xx_read_pwmfunction npcm7xx_write_pwmfunction npcm7xx_pwm_is_visiblefunction npcm7xx_read_fanfunction npcm7xx_fan_is_visiblefunction npcm7xx_readfunction npcm7xx_writefunction npcm7xx_is_visiblefunction npcm7xx_pwm_initfunction npcm7xx_fan_initfunction npcm7xx_pwm_cz_get_max_statefunction npcm7xx_pwm_cz_get_cur_statefunction npcm7xx_pwm_cz_set_cur_statefunction npcm7xx_create_pwm_coolingfunction npcm7xx_en_pwm_fanfunction npcm7xx_pwm_fan_probefunction for_each_child_of_node_scoped
Annotated Snippet
struct npcm_hwmon_info {
u32 pwm_max_channel;
};
struct npcm7xx_fan_dev {
u8 fan_st_flg;
u8 fan_pls_per_rev;
u16 fan_cnt;
u32 fan_cnt_tmp;
};
struct npcm7xx_cooling_device {
char name[THERMAL_NAME_LENGTH];
struct npcm7xx_pwm_fan_data *data;
struct thermal_cooling_device *tcdev;
int pwm_port;
u8 *cooling_levels;
u8 max_state;
u8 cur_state;
};
struct npcm7xx_pwm_fan_data {
void __iomem *pwm_base;
void __iomem *fan_base;
int pwm_modules;
struct clk *pwm_clk;
struct clk *fan_clk;
spinlock_t fan_lock[NPCM7XX_FAN_MAX_MODULE];
int fan_irq[NPCM7XX_FAN_MAX_MODULE];
bool pwm_present[NPCM7XX_PWM_MAX_CHN_NUM];
bool fan_present[NPCM7XX_FAN_MAX_CHN_NUM];
u32 input_clk_freq;
struct timer_list fan_timer;
struct npcm7xx_fan_dev fan_dev[NPCM7XX_FAN_MAX_CHN_NUM];
struct npcm7xx_cooling_device *cdev[NPCM7XX_PWM_MAX_CHN_NUM];
const struct npcm_hwmon_info *info;
u8 fan_select;
};
static int npcm7xx_pwm_config_set(struct npcm7xx_pwm_fan_data *data,
int channel, u16 val)
{
u32 pwm_ch = (channel % NPCM7XX_PWM_MAX_CHN_NUM_IN_A_MODULE);
u32 module = (channel / NPCM7XX_PWM_MAX_CHN_NUM_IN_A_MODULE);
u32 tmp_buf, ctrl_en_bit, env_bit;
/*
* Config PWM Comparator register for setting duty cycle
*/
/* write new CMR value */
iowrite32(val, NPCM7XX_PWM_REG_CMRx(data->pwm_base, module, pwm_ch));
tmp_buf = ioread32(NPCM7XX_PWM_REG_CR(data->pwm_base, module));
switch (pwm_ch) {
case 0:
ctrl_en_bit = NPCM7XX_PWM_CTRL_CH0_EN_BIT;
env_bit = NPCM7XX_PWM_CTRL_CH0_INV_BIT;
break;
case 1:
ctrl_en_bit = NPCM7XX_PWM_CTRL_CH1_EN_BIT;
env_bit = NPCM7XX_PWM_CTRL_CH1_INV_BIT;
break;
case 2:
ctrl_en_bit = NPCM7XX_PWM_CTRL_CH2_EN_BIT;
env_bit = NPCM7XX_PWM_CTRL_CH2_INV_BIT;
break;
case 3:
ctrl_en_bit = NPCM7XX_PWM_CTRL_CH3_EN_BIT;
env_bit = NPCM7XX_PWM_CTRL_CH3_INV_BIT;
break;
default:
return -ENODEV;
}
if (val == 0) {
/* Disable PWM */
tmp_buf &= ~ctrl_en_bit;
tmp_buf |= env_bit;
} else {
/* Enable PWM */
tmp_buf |= ctrl_en_bit;
tmp_buf &= ~env_bit;
}
iowrite32(tmp_buf, NPCM7XX_PWM_REG_CR(data->pwm_base, module));
return 0;
}
static inline void npcm7xx_fan_start_capture(struct npcm7xx_pwm_fan_data *data,
Annotation
- Immediate include surface: `linux/clk.h`, `linux/device.h`, `linux/hwmon.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/module.h`, `linux/of_address.h`, `linux/of_irq.h`.
- Detected declarations: `struct npcm_hwmon_info`, `struct npcm7xx_fan_dev`, `struct npcm7xx_cooling_device`, `struct npcm7xx_pwm_fan_data`, `function npcm7xx_pwm_config_set`, `function npcm7xx_fan_start_capture`, `function npcm7xx_fan_polling`, `function npcm7xx_fan_compute`, `function npcm7xx_check_cmp`, `function npcm7xx_fan_isr`.
- Atlas domain: Driver Families / drivers/hwmon.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.