drivers/hwmon/surface_temp.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/surface_temp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/surface_temp.c- Extension
.c- Size
- 6574 bytes
- Lines
- 236
- 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/bitops.hlinux/hwmon.hlinux/kernel.hlinux/module.hlinux/types.hlinux/surface_aggregator/controller.hlinux/surface_aggregator/device.h
Detected Declarations
struct ssam_tmp_get_name_rspstruct ssam_tempfunction ssam_tmp_get_available_sensorsfunction ssam_tmp_get_temperaturefunction ssam_tmp_get_namefunction ssam_temp_hwmon_is_visiblefunction ssam_temp_hwmon_readfunction ssam_temp_hwmon_read_stringfunction ssam_temp_probe
Annotated Snippet
struct ssam_tmp_get_name_rsp {
__le16 unknown1;
char unknown2;
char name[SSAM_TMP_SENSOR_NAME_LENGTH];
} __packed;
static_assert(sizeof(struct ssam_tmp_get_name_rsp) == 21);
SSAM_DEFINE_SYNC_REQUEST_CL_R(__ssam_tmp_get_available_sensors, __le16, {
.target_category = SSAM_SSH_TC_TMP,
.command_id = 0x04,
});
SSAM_DEFINE_SYNC_REQUEST_MD_R(__ssam_tmp_get_temperature, __le16, {
.target_category = SSAM_SSH_TC_TMP,
.command_id = 0x01,
});
SSAM_DEFINE_SYNC_REQUEST_MD_R(__ssam_tmp_get_name, struct ssam_tmp_get_name_rsp, {
.target_category = SSAM_SSH_TC_TMP,
.command_id = 0x0e,
});
static int ssam_tmp_get_available_sensors(struct ssam_device *sdev, s16 *sensors)
{
__le16 sensors_le;
int status;
status = __ssam_tmp_get_available_sensors(sdev, &sensors_le);
if (status)
return status;
*sensors = le16_to_cpu(sensors_le);
return 0;
}
static int ssam_tmp_get_temperature(struct ssam_device *sdev, u8 iid, long *temperature)
{
__le16 temp_le;
int status;
status = __ssam_tmp_get_temperature(sdev->ctrl, sdev->uid.target, iid, &temp_le);
if (status)
return status;
/* Convert 1/10 °K to 1/1000 °C */
*temperature = (le16_to_cpu(temp_le) - 2731) * 100L;
return 0;
}
static int ssam_tmp_get_name(struct ssam_device *sdev, u8 iid, char *buf, size_t buf_len)
{
struct ssam_tmp_get_name_rsp name_rsp;
int status;
status = __ssam_tmp_get_name(sdev->ctrl, sdev->uid.target, iid, &name_rsp);
if (status)
return status;
/*
* This should not fail unless the name in the returned struct is not
* null-terminated or someone changed something in the struct
* definitions above, since our buffer and struct have the same
* capacity by design. So if this fails, log an error message. Since
* the more likely cause is that the returned string isn't
* null-terminated, we might have received garbage (as opposed to just
* an incomplete string), so also fail the function.
*/
status = strscpy(buf, name_rsp.name, buf_len);
if (status < 0) {
dev_err(&sdev->dev, "received non-null-terminated sensor name string\n");
return status;
}
return 0;
}
/* -- Driver.---------------------------------------------------------------- */
struct ssam_temp {
struct ssam_device *sdev;
s16 sensors;
char names[SSAM_TMP_SENSOR_MAX_COUNT][SSAM_TMP_SENSOR_NAME_LENGTH];
};
static umode_t ssam_temp_hwmon_is_visible(const void *data,
enum hwmon_sensor_types type,
u32 attr, int channel)
{
const struct ssam_temp *ssam_temp = data;
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/hwmon.h`, `linux/kernel.h`, `linux/module.h`, `linux/types.h`, `linux/surface_aggregator/controller.h`, `linux/surface_aggregator/device.h`.
- Detected declarations: `struct ssam_tmp_get_name_rsp`, `struct ssam_temp`, `function ssam_tmp_get_available_sensors`, `function ssam_tmp_get_temperature`, `function ssam_tmp_get_name`, `function ssam_temp_hwmon_is_visible`, `function ssam_temp_hwmon_read`, `function ssam_temp_hwmon_read_string`, `function ssam_temp_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.