drivers/hwmon/pmbus/mp5926.c

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

File Facts

System
Linux kernel
Corpus path
drivers/hwmon/pmbus/mp5926.c
Extension
.c
Size
4554 bytes
Lines
185
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 mp5926_data {
	struct pmbus_driver_info info;
	u8 vout_mode;
	u8 vout_linear_exponent;
};

#define to_mp5926_data(x)  container_of(x, struct mp5926_data, info)

static int mp5926_read_byte_data(struct i2c_client *client, int page,
				 int reg)
{
	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
	struct mp5926_data *data = to_mp5926_data(info);
	int ret;

	switch (reg) {
	case PMBUS_VOUT_MODE:
		if (data->vout_mode == linear) {
			/*
			 * The VOUT format used by the chip is linear11,
			 * not linear16. Report that VOUT is in linear mode
			 * and return exponent value extracted while probing
			 * the chip.
			 */
			return data->vout_linear_exponent;
		}
		return PB_VOUT_MODE_DIRECT;
	default:
		ret = -ENODATA;
		break;
	}
	return ret;
}

static int mp5926_read_word_data(struct i2c_client *client, int page, int phase,
				 int reg)
{
	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
	struct mp5926_data *data = to_mp5926_data(info);
	int ret;

	switch (reg) {
	case PMBUS_READ_VOUT:
		ret = pmbus_read_word_data(client, page, phase, reg);
		if (ret < 0)
			return ret;
		/*
		 * Because the VOUT format used by the chip is linear11 and not
		 * linear16, we disregard bits[15:11]. The exponent is reported
		 * as part of the VOUT_MODE command.
		 */
		if (data->vout_mode == linear)
			ret = ((s16)((ret & 0x7ff) << 5)) >> 5;
		break;
	default:
		ret = -ENODATA;
		break;
	}
	return ret;
}

static struct pmbus_driver_info mp5926_info = {
	.pages = PAGE,
	.format[PSC_VOLTAGE_IN] = direct,
	.format[PSC_CURRENT_IN] = direct,
	.format[PSC_VOLTAGE_OUT] = direct,
	.format[PSC_TEMPERATURE] = direct,
	.format[PSC_POWER] = direct,

	.m[PSC_VOLTAGE_IN] = 16,
	.b[PSC_VOLTAGE_IN] = 0,
	.R[PSC_VOLTAGE_IN] = 0,

	.m[PSC_CURRENT_IN] = 16,
	.b[PSC_CURRENT_IN] = 0,
	.R[PSC_CURRENT_IN] = 0,

	.m[PSC_VOLTAGE_OUT] = 16,
	.b[PSC_VOLTAGE_OUT] = 0,
	.R[PSC_VOLTAGE_OUT] = 0,

	.m[PSC_TEMPERATURE] = 4,
	.b[PSC_TEMPERATURE] = 0,
	.R[PSC_TEMPERATURE] = 0,

	.m[PSC_POWER] = 25,
	.b[PSC_POWER] = 0,
	.R[PSC_POWER] = -2,

	.read_word_data = mp5926_read_word_data,

Annotation

Implementation Notes