drivers/hwmon/emc2305.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/emc2305.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/emc2305.c- Extension
.c- Size
- 20425 bytes
- Lines
- 785
- 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/err.hlinux/hwmon.hlinux/i2c.hlinux/module.hlinux/platform_data/emc2305.hlinux/thermal.hlinux/pwm.hlinux/of_device.hlinux/util_macros.h
Detected Declarations
struct emc2305_cdev_datastruct emc2305_dataenum emc230x_product_idfunction emc2305_get_max_channelfunction emc2305_get_cdev_idxfunction emc2305_get_cur_statefunction emc2305_get_max_statefunction __emc2305_set_cur_statefunction emc2305_set_cur_statefunction emc2305_show_faultfunction emc2305_show_fanfunction emc2305_show_pwmfunction emc2305_set_pwmfunction emc2305_set_single_tzfunction emc2305_set_tzfunction emc2305_is_visiblefunction emc2305_writefunction emc2305_readfunction emc2305_identifyfunction emc2305_of_parse_pwm_childfunction emc2305_probe_childs_from_dtfunction for_each_child_of_nodefunction emc2305_probefunction emc2305_shutdown
Annotated Snippet
struct emc2305_cdev_data {
struct thermal_cooling_device *cdev;
unsigned int cur_state;
unsigned long last_hwmon_state;
unsigned long last_thermal_state;
};
/**
* struct emc2305_data - device-specific data
* @client: i2c client
* @hwmon_dev: hwmon device
* @max_state: maximum cooling state of the cooling device
* @pwm_num: number of PWM channels
* @pwm_output_mask: PWM output mask
* @pwm_polarity_mask: PWM polarity mask
* @pwm_separate: separate PWM settings for every channel
* @pwm_shutdown: Set shutdown PWM.
* @pwm_min: array of minimum PWM per channel
* @pwm_freq: array of PWM frequency per channel
* @cdev_data: array of cooling devices data
*/
struct emc2305_data {
struct i2c_client *client;
struct device *hwmon_dev;
u8 max_state;
u8 pwm_num;
u8 pwm_output_mask;
u8 pwm_polarity_mask;
bool pwm_separate;
s16 pwm_shutdown[EMC2305_PWM_MAX];
u8 pwm_min[EMC2305_PWM_MAX];
u16 pwm_freq[EMC2305_PWM_MAX];
struct emc2305_cdev_data cdev_data[EMC2305_PWM_MAX];
};
static char *emc2305_fan_name[] = {
"emc2305_fan",
"emc2305_fan1",
"emc2305_fan2",
"emc2305_fan3",
"emc2305_fan4",
"emc2305_fan5",
};
static int emc2305_get_max_channel(const struct emc2305_data *data)
{
return data->pwm_num;
}
static int emc2305_get_cdev_idx(struct thermal_cooling_device *cdev)
{
struct emc2305_data *data = cdev->devdata;
size_t len = strlen(cdev->type);
int ret;
if (len <= 0)
return -EINVAL;
/*
* Returns index of cooling device 0..4 in case of separate PWM setting.
* Zero index is used in case of one common PWM setting.
* If the mode is not set as pwm_separate, all PWMs are to be bound
* to the common thermal zone and should work at the same speed
* to perform cooling for the same thermal junction.
* Otherwise, return specific channel that will be used in bound
* related PWM to the thermal zone.
*/
if (!data->pwm_separate)
return 0;
ret = cdev->type[len - 1];
switch (ret) {
case '1' ... '5':
return ret - '1';
default:
break;
}
return -EINVAL;
}
static int emc2305_get_cur_state(struct thermal_cooling_device *cdev, unsigned long *state)
{
int cdev_idx;
struct emc2305_data *data = cdev->devdata;
cdev_idx = emc2305_get_cdev_idx(cdev);
if (cdev_idx < 0)
return cdev_idx;
*state = data->cdev_data[cdev_idx].cur_state;
Annotation
- Immediate include surface: `linux/err.h`, `linux/hwmon.h`, `linux/i2c.h`, `linux/module.h`, `linux/platform_data/emc2305.h`, `linux/thermal.h`, `linux/pwm.h`, `linux/of_device.h`.
- Detected declarations: `struct emc2305_cdev_data`, `struct emc2305_data`, `enum emc230x_product_id`, `function emc2305_get_max_channel`, `function emc2305_get_cdev_idx`, `function emc2305_get_cur_state`, `function emc2305_get_max_state`, `function __emc2305_set_cur_state`, `function emc2305_set_cur_state`, `function emc2305_show_fault`.
- 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.