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.

Dependency Surface

Detected Declarations

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

Implementation Notes