drivers/hwmon/cgbc-hwmon.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/cgbc-hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/cgbc-hwmon.c- Extension
.c- Size
- 8689 bytes
- Lines
- 308
- 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/device.hlinux/hwmon.hlinux/mfd/cgbc.hlinux/module.hlinux/platform_device.h
Detected Declarations
struct cgbc_hwmon_sensorstruct cgbc_hwmon_dataenum cgbc_sensor_typesfunction cgbc_hwmon_cmdfunction cgbc_hwmon_probe_sensorsfunction cgbc_hwmon_readfunction cgbc_hwmon_is_visiblefunction cgbc_hwmon_read_stringfunction cgbc_hwmon_probe
Annotated Snippet
struct cgbc_hwmon_sensor {
enum hwmon_sensor_types type;
bool active;
unsigned int index;
unsigned int channel;
const char *label;
};
struct cgbc_hwmon_data {
struct cgbc_device_data *cgbc;
unsigned int nb_sensors;
struct cgbc_hwmon_sensor *sensors;
};
enum cgbc_sensor_types {
CGBC_HWMON_TYPE_TEMP = 1,
CGBC_HWMON_TYPE_IN,
CGBC_HWMON_TYPE_FAN
};
static const char * const cgbc_hwmon_labels_temp[] = {
"CPU Temperature",
"Box Temperature",
"Ambient Temperature",
"Board Temperature",
"Carrier Temperature",
"Chipset Temperature",
"Video Temperature",
"Other Temperature",
"TOPDIM Temperature",
"BOTTOMDIM Temperature",
};
static const struct {
enum hwmon_sensor_types type;
const char *label;
} cgbc_hwmon_labels_in[] = {
{ hwmon_in, "CPU Voltage" },
{ hwmon_in, "DC Runtime Voltage" },
{ hwmon_in, "DC Standby Voltage" },
{ hwmon_in, "CMOS Battery Voltage" },
{ hwmon_in, "Battery Voltage" },
{ hwmon_in, "AC Voltage" },
{ hwmon_in, "Other Voltage" },
{ hwmon_in, "5V Voltage" },
{ hwmon_in, "5V Standby Voltage" },
{ hwmon_in, "3V3 Voltage" },
{ hwmon_in, "3V3 Standby Voltage" },
{ hwmon_in, "VCore A Voltage" },
{ hwmon_in, "VCore B Voltage" },
{ hwmon_in, "12V Voltage" },
{ hwmon_curr, "DC Current" },
{ hwmon_curr, "5V Current" },
{ hwmon_curr, "12V Current" },
};
#define CGBC_HWMON_NB_IN_SENSORS 14
static const char * const cgbc_hwmon_labels_fan[] = {
"CPU Fan",
"Box Fan",
"Ambient Fan",
"Chipset Fan",
"Video Fan",
"Other Fan",
};
static int cgbc_hwmon_cmd(struct cgbc_device_data *cgbc, u8 index, u8 *data)
{
u8 cmd[2] = {CGBC_HWMON_CMD_SENSOR, index};
return cgbc_command(cgbc, cmd, sizeof(cmd), data, CGBC_HWMON_CMD_SENSOR_DATA_SIZE, NULL);
}
static int cgbc_hwmon_probe_sensors(struct device *dev, struct cgbc_hwmon_data *hwmon)
{
struct cgbc_device_data *cgbc = hwmon->cgbc;
struct cgbc_hwmon_sensor *sensor = hwmon->sensors;
u8 data[CGBC_HWMON_CMD_SENSOR_DATA_SIZE], nb_sensors, i;
int ret;
ret = cgbc_hwmon_cmd(cgbc, 0, &data[0]);
if (ret)
return ret;
nb_sensors = data[0];
hwmon->sensors = devm_kzalloc(dev, sizeof(*hwmon->sensors) * nb_sensors, GFP_KERNEL);
if (!hwmon->sensors)
return -ENOMEM;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/device.h`, `linux/hwmon.h`, `linux/mfd/cgbc.h`, `linux/module.h`, `linux/platform_device.h`.
- Detected declarations: `struct cgbc_hwmon_sensor`, `struct cgbc_hwmon_data`, `enum cgbc_sensor_types`, `function cgbc_hwmon_cmd`, `function cgbc_hwmon_probe_sensors`, `function cgbc_hwmon_read`, `function cgbc_hwmon_is_visible`, `function cgbc_hwmon_read_string`, `function cgbc_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.