drivers/hwmon/pmbus/mpq7932.c

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

File Facts

System
Linux kernel
Corpus path
drivers/hwmon/pmbus/mpq7932.c
Extension
.c
Size
4638 bytes
Lines
168
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 mpq7932_data {
	struct pmbus_driver_info info;
	struct pmbus_platform_data pdata;
};

#if IS_ENABLED(CONFIG_SENSORS_MPQ7932_REGULATOR)
static const struct regulator_desc mpq7932_regulators_desc[] = {
	PMBUS_REGULATOR_STEP("buck", 0, MPQ7932_N_VOLTAGES,
			     MPQ7932_UV_STEP, MPQ7932_BUCK_UV_MIN),
	PMBUS_REGULATOR_STEP("buck", 1, MPQ7932_N_VOLTAGES,
			     MPQ7932_UV_STEP, MPQ7932_BUCK_UV_MIN),
	PMBUS_REGULATOR_STEP("buck", 2, MPQ7932_N_VOLTAGES,
			     MPQ7932_UV_STEP, MPQ7932_BUCK_UV_MIN),
	PMBUS_REGULATOR_STEP("buck", 3, MPQ7932_N_VOLTAGES,
			     MPQ7932_UV_STEP, MPQ7932_BUCK_UV_MIN),
	PMBUS_REGULATOR_STEP("buck", 4, MPQ7932_N_VOLTAGES,
			     MPQ7932_UV_STEP, MPQ7932_BUCK_UV_MIN),
	PMBUS_REGULATOR_STEP("buck", 5, MPQ7932_N_VOLTAGES,
			     MPQ7932_UV_STEP, MPQ7932_BUCK_UV_MIN),
};

static const struct regulator_desc mpq7932_regulators_desc_one[] = {
	PMBUS_REGULATOR_STEP_ONE_NODE("buck", MPQ7932_N_VOLTAGES,
				      MPQ7932_UV_STEP, MPQ7932_BUCK_UV_MIN),
};
#endif

static int mpq7932_write_word_data(struct i2c_client *client, int page, int reg,
				   u16 word)
{
	switch (reg) {
	/*
	 * chip supports only byte access for VOUT_COMMAND otherwise
	 * access results -EREMOTEIO
	 */
	case PMBUS_VOUT_COMMAND:
		return pmbus_write_byte_data(client, page, reg, word & 0xFF);

	default:
		return -ENODATA;
	}
}

static int mpq7932_read_word_data(struct i2c_client *client, int page,
				  int phase, int reg)
{
	switch (reg) {
	/*
	 * chip supports neither (PMBUS_VOUT_MARGIN_HIGH, PMBUS_VOUT_MARGIN_LOW)
	 * nor (PMBUS_MFR_VOUT_MIN, PMBUS_MFR_VOUT_MAX). As a result set voltage
	 * fails due to error in pmbus_regulator_get_low_margin, so faked.
	 */
	case PMBUS_MFR_VOUT_MIN:
		return 0;

	case PMBUS_MFR_VOUT_MAX:
		return MPQ7932_VOUT_MAX;

	/*
	 * chip supports only byte access for VOUT_COMMAND otherwise
	 * access results in -EREMOTEIO
	 */
	case PMBUS_READ_VOUT:
		return pmbus_read_byte_data(client, page, PMBUS_VOUT_COMMAND);

	default:
		return -ENODATA;
	}
}

static int mpq7932_probe(struct i2c_client *client)
{
	struct mpq7932_data *data;
	struct pmbus_driver_info *info;
	struct device *dev = &client->dev;
	int i;

	data = devm_kzalloc(dev, sizeof(struct mpq7932_data), GFP_KERNEL);
	if (!data)
		return -ENOMEM;

	info = &data->info;
	info->pages = (int)(unsigned long)device_get_match_data(&client->dev);
	info->format[PSC_VOLTAGE_OUT] = direct;
	info->m[PSC_VOLTAGE_OUT] = 160;
	info->b[PSC_VOLTAGE_OUT] = -33;
	for (i = 0; i < info->pages; i++) {
		info->func[i] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
				| PMBUS_HAVE_STATUS_TEMP;
	}

Annotation

Implementation Notes