drivers/hwmon/max77705-hwmon.c

Source file repositories/reference/linux-study-clean/drivers/hwmon/max77705-hwmon.c

File Facts

System
Linux kernel
Corpus path
drivers/hwmon/max77705-hwmon.c
Extension
.c
Size
4663 bytes
Lines
222
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 channel_desc {
	u8 reg;
	u8 avg_reg;
	const char *const label;
	// register resolution. nano Volts for voltage, nano Amperes for current
	u32 resolution;
};

static const struct channel_desc current_channel_desc[] = {
	{
		.reg = IIN_REG,
		.label = "IIN_REG",
		.resolution = 125000
	},
	{
		.reg = ISYS_REG,
		.avg_reg = AVGISYS_REG,
		.label = "ISYS_REG",
		.resolution = 312500
	}
};

static const struct channel_desc voltage_channel_desc[] = {
	{
		.reg = VBYP_REG,
		.label = "VBYP_REG",
		.resolution = 427246
	},
	{
		.reg = VSYS_REG,
		.label = "VSYS_REG",
		.resolution = 156250
	}
};

static int max77705_read_and_convert(struct regmap *regmap, u8 reg, u32 res,
				     bool is_signed, long *val)
{
	int ret;
	u32 regval;

	ret = regmap_read(regmap, reg, &regval);
	if (ret < 0)
		return ret;

	if (is_signed)
		*val = mult_frac((long)sign_extend32(regval, 15), res, 1000000);
	else
		*val = mult_frac((long)regval, res, 1000000);

	return 0;
}

static umode_t max77705_is_visible(const void *data,
				   enum hwmon_sensor_types type,
				   u32 attr, int channel)
{
	switch (type) {
	case hwmon_in:
		switch (attr) {
		case hwmon_in_input:
		case hwmon_in_label:
			return 0444;
		default:
			break;
		}
		break;
	case hwmon_curr:
		switch (attr) {
		case hwmon_curr_input:
		case hwmon_in_label:
			return 0444;
		case hwmon_curr_average:
			if (current_channel_desc[channel].avg_reg)
				return 0444;
			break;
		default:
			break;
		}
		break;
	default:
		break;
	}
	return 0;
}

static int max77705_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
				int channel, const char **buf)
{
	switch (type) {

Annotation

Implementation Notes