drivers/hwmon/scpi-hwmon.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/scpi-hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/scpi-hwmon.c- Extension
.c- Size
- 8235 bytes
- Lines
- 307
- 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/hwmon.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/scpi_protocol.hlinux/slab.hlinux/sysfs.hlinux/thermal.h
Detected Declarations
struct sensor_datastruct scpi_thermal_zonestruct scpi_sensorsfunction scpi_scale_readingfunction scpi_read_tempfunction scpi_show_sensorfunction scpi_show_labelfunction scpi_hwmon_probe
Annotated Snippet
struct sensor_data {
unsigned int scale;
struct scpi_sensor_info info;
struct device_attribute dev_attr_input;
struct device_attribute dev_attr_label;
char input[20];
char label[20];
};
struct scpi_thermal_zone {
int sensor_id;
struct scpi_sensors *scpi_sensors;
};
struct scpi_sensors {
struct scpi_ops *scpi_ops;
struct sensor_data *data;
struct list_head thermal_zones;
struct attribute **attrs;
struct attribute_group group;
const struct attribute_group *groups[2];
};
static const u32 gxbb_scpi_scale[] = {
[TEMPERATURE] = 1, /* (celsius) */
[VOLTAGE] = 1000, /* (millivolts) */
[CURRENT] = 1000, /* (milliamperes) */
[POWER] = 1000000, /* (microwatts) */
[ENERGY] = 1000000, /* (microjoules) */
};
static const u32 scpi_scale[] = {
[TEMPERATURE] = 1000, /* (millicelsius) */
[VOLTAGE] = 1000, /* (millivolts) */
[CURRENT] = 1000, /* (milliamperes) */
[POWER] = 1000000, /* (microwatts) */
[ENERGY] = 1000000, /* (microjoules) */
};
static void scpi_scale_reading(u64 *value, struct sensor_data *sensor)
{
if (scpi_scale[sensor->info.class] != sensor->scale) {
*value *= scpi_scale[sensor->info.class];
do_div(*value, sensor->scale);
}
}
static int scpi_read_temp(struct thermal_zone_device *tz, int *temp)
{
struct scpi_thermal_zone *zone = thermal_zone_device_priv(tz);
struct scpi_sensors *scpi_sensors = zone->scpi_sensors;
struct scpi_ops *scpi_ops = scpi_sensors->scpi_ops;
struct sensor_data *sensor = &scpi_sensors->data[zone->sensor_id];
u64 value;
int ret;
ret = scpi_ops->sensor_get_value(sensor->info.sensor_id, &value);
if (ret)
return ret;
scpi_scale_reading(&value, sensor);
*temp = value;
return 0;
}
/* hwmon callback functions */
static ssize_t
scpi_show_sensor(struct device *dev, struct device_attribute *attr, char *buf)
{
struct scpi_sensors *scpi_sensors = dev_get_drvdata(dev);
struct scpi_ops *scpi_ops = scpi_sensors->scpi_ops;
struct sensor_data *sensor;
u64 value;
int ret;
sensor = container_of(attr, struct sensor_data, dev_attr_input);
ret = scpi_ops->sensor_get_value(sensor->info.sensor_id, &value);
if (ret)
return ret;
scpi_scale_reading(&value, sensor);
/*
* Temperature sensor values are treated as signed values based on
* observation even though that is not explicitly specified, and
* because an unsigned u64 temperature does not really make practical
* sense especially when the temperature is below zero degrees Celsius.
*/
Annotation
- Immediate include surface: `linux/hwmon.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/scpi_protocol.h`, `linux/slab.h`, `linux/sysfs.h`, `linux/thermal.h`.
- Detected declarations: `struct sensor_data`, `struct scpi_thermal_zone`, `struct scpi_sensors`, `function scpi_scale_reading`, `function scpi_read_temp`, `function scpi_show_sensor`, `function scpi_show_label`, `function scpi_hwmon_probe`.
- 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.