drivers/hwmon/raspberrypi-hwmon.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/raspberrypi-hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/raspberrypi-hwmon.c- Extension
.c- Size
- 6927 bytes
- Lines
- 293
- 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/device.hlinux/err.hlinux/hwmon.hlinux/module.hlinux/platform_device.hlinux/slab.hlinux/workqueue.hsoc/bcm2835/raspberrypi-firmware.h
Detected Declarations
struct rpi_hwmon_datafunction rpi_firmware_get_throttledfunction rpi_firmware_get_voltagefunction get_values_pollfunction rpi_hwmon_cancel_poll_workfunction rpi_readfunction rpi_read_stringfunction rpi_is_visiblefunction rpi_hwmon_probefunction rpi_hwmon_suspendfunction rpi_hwmon_resume
Annotated Snippet
struct rpi_hwmon_data {
struct device *hwmon_dev;
struct rpi_firmware *fw;
u32 valid_inputs;
u32 last_throttled;
struct delayed_work get_values_poll_work;
};
static const char * const rpi_hwmon_labels[] = {
"core",
"sdram_c",
"sdram_i",
"sdram_p",
};
static void rpi_firmware_get_throttled(struct rpi_hwmon_data *data)
{
u32 new_uv, old_uv, value;
int ret;
/* Request firmware to clear sticky bits */
value = 0xffff;
ret = rpi_firmware_property(data->fw, RPI_FIRMWARE_GET_THROTTLED,
&value, sizeof(value));
if (ret) {
dev_err_once(data->hwmon_dev, "Failed to get throttled (%d)\n",
ret);
return;
}
new_uv = value & UNDERVOLTAGE_STICKY_BIT;
old_uv = data->last_throttled & UNDERVOLTAGE_STICKY_BIT;
data->last_throttled = value;
if (new_uv == old_uv)
return;
if (new_uv)
dev_crit(data->hwmon_dev, "Undervoltage detected!\n");
else
dev_info(data->hwmon_dev, "Voltage normalised\n");
hwmon_notify_event(data->hwmon_dev, hwmon_in, hwmon_in_lcrit_alarm, 0);
}
static int rpi_firmware_get_voltage(struct rpi_hwmon_data *data, u32 id,
long *val)
{
struct rpi_firmware_get_voltage_request packet =
RPI_FIRMWARE_GET_VOLTAGE_REQUEST(id);
int ret;
ret = rpi_firmware_property(data->fw, RPI_FIRMWARE_GET_VOLTAGE,
&packet, sizeof(packet));
if (ret)
return ret;
*val = le32_to_cpu(packet.value) / 1000;
return 0;
}
static void get_values_poll(struct work_struct *work)
{
struct rpi_hwmon_data *data;
data = container_of(work, struct rpi_hwmon_data,
get_values_poll_work.work);
rpi_firmware_get_throttled(data);
/*
* We can't run faster than the sticky shift (100ms) since we get
* flipping in the sticky bits that are cleared.
*/
schedule_delayed_work(&data->get_values_poll_work, 2 * HZ);
}
static void rpi_hwmon_cancel_poll_work(void *res)
{
struct rpi_hwmon_data *data = res;
disable_delayed_work_sync(&data->get_values_poll_work);
}
static int rpi_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
struct rpi_hwmon_data *data = dev_get_drvdata(dev);
Annotation
- Immediate include surface: `linux/device.h`, `linux/err.h`, `linux/hwmon.h`, `linux/module.h`, `linux/platform_device.h`, `linux/slab.h`, `linux/workqueue.h`, `soc/bcm2835/raspberrypi-firmware.h`.
- Detected declarations: `struct rpi_hwmon_data`, `function rpi_firmware_get_throttled`, `function rpi_firmware_get_voltage`, `function get_values_poll`, `function rpi_hwmon_cancel_poll_work`, `function rpi_read`, `function rpi_read_string`, `function rpi_is_visible`, `function rpi_hwmon_probe`, `function rpi_hwmon_suspend`.
- 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.