drivers/hwmon/macsmc-hwmon.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/macsmc-hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/macsmc-hwmon.c- Extension
.c- Size
- 21824 bytes
- Lines
- 853
- 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/bitfield.hlinux/hwmon.hlinux/math64.hlinux/mfd/macsmc.hlinux/module.hlinux/of.hlinux/platform_device.h
Detected Declarations
struct macsmc_hwmon_sensorstruct macsmc_hwmon_fanstruct macsmc_hwmon_sensorsstruct macsmc_hwmon_fansstruct macsmc_hwmonfunction macsmc_hwmon_read_labelfunction macsmc_hwmon_read_ioft_scaledfunction macsmc_hwmon_read_f32_scaledfunction macsmc_hwmon_read_keyfunction macsmc_hwmon_write_f32function macsmc_hwmon_write_keyfunction macsmc_hwmon_read_fanfunction macsmc_hwmon_write_fanfunction macsmc_hwmon_readfunction macsmc_hwmon_writefunction macsmc_hwmon_fan_is_visiblefunction macsmc_hwmon_is_visiblefunction macsmc_hwmon_parse_keyfunction macsmc_hwmon_create_sensorfunction macsmc_hwmon_create_fanfunction macsmc_hwmon_populate_sensorsfunction for_each_child_of_node_with_prefixfunction for_each_child_of_node_with_prefixfunction for_each_child_of_node_with_prefixfunction for_each_child_of_node_with_prefixfunction for_each_child_of_node_with_prefixfunction for_each_child_of_node_with_prefixfunction for_each_child_of_node_with_prefixfunction for_each_child_of_node_with_prefixfunction for_each_child_of_node_with_prefixfunction for_each_child_of_node_with_prefixfunction macsmc_hwmon_populate_configsfunction macsmc_hwmon_populate_fan_configsfunction macsmc_hwmon_create_infosfunction macsmc_hwmon_probe
Annotated Snippet
struct macsmc_hwmon_sensor {
struct apple_smc_key_info info;
smc_key macsmc_key;
char label[MAX_LABEL_LENGTH];
u32 attrs;
};
struct macsmc_hwmon_fan {
struct macsmc_hwmon_sensor now;
struct macsmc_hwmon_sensor min;
struct macsmc_hwmon_sensor max;
struct macsmc_hwmon_sensor set;
struct macsmc_hwmon_sensor mode;
char label[MAX_LABEL_LENGTH];
u32 attrs;
bool manual;
};
struct macsmc_hwmon_sensors {
struct hwmon_channel_info channel_info;
struct macsmc_hwmon_sensor *sensors;
u32 count;
};
struct macsmc_hwmon_fans {
struct hwmon_channel_info channel_info;
struct macsmc_hwmon_fan *fans;
u32 count;
};
struct macsmc_hwmon {
struct device *dev;
struct apple_smc *smc;
struct device *hwmon_dev;
struct hwmon_chip_info chip_info;
/* Chip + sensor types + NULL */
const struct hwmon_channel_info *channel_infos[1 + NUM_SENSOR_TYPES + 1];
struct macsmc_hwmon_sensors temp;
struct macsmc_hwmon_sensors volt;
struct macsmc_hwmon_sensors curr;
struct macsmc_hwmon_sensors power;
struct macsmc_hwmon_fans fan;
};
static int macsmc_hwmon_read_label(struct device *dev,
enum hwmon_sensor_types type, u32 attr,
int channel, const char **str)
{
struct macsmc_hwmon *hwmon = dev_get_drvdata(dev);
switch (type) {
case hwmon_temp:
*str = hwmon->temp.sensors[channel].label;
break;
case hwmon_in:
*str = hwmon->volt.sensors[channel].label;
break;
case hwmon_curr:
*str = hwmon->curr.sensors[channel].label;
break;
case hwmon_power:
*str = hwmon->power.sensors[channel].label;
break;
case hwmon_fan:
*str = hwmon->fan.fans[channel].label;
break;
default:
return -EOPNOTSUPP;
}
return 0;
}
/*
* A number of sensors report data in a 48.16 fixed-point decimal format that is
* not used by any other function of the SMC.
*/
static int macsmc_hwmon_read_ioft_scaled(struct apple_smc *smc, smc_key key,
u64 *p, int scale)
{
u64 val;
int ret;
ret = apple_smc_read_u64(smc, key, &val);
if (ret < 0)
return ret;
*p = mul_u64_u32_div(val, scale, 65536);
return 0;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/hwmon.h`, `linux/math64.h`, `linux/mfd/macsmc.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`.
- Detected declarations: `struct macsmc_hwmon_sensor`, `struct macsmc_hwmon_fan`, `struct macsmc_hwmon_sensors`, `struct macsmc_hwmon_fans`, `struct macsmc_hwmon`, `function macsmc_hwmon_read_label`, `function macsmc_hwmon_read_ioft_scaled`, `function macsmc_hwmon_read_f32_scaled`, `function macsmc_hwmon_read_key`, `function macsmc_hwmon_write_f32`.
- 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.