drivers/hwmon/pmbus/pli1209bc.c

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

File Facts

System
Linux kernel
Corpus path
drivers/hwmon/pmbus/pli1209bc.c
Extension
.c
Size
4019 bytes
Lines
149
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

// SPDX-License-Identifier: GPL-2.0+
/*
 * Hardware monitoring driver for Vicor PLI1209BC Digital Supervisor
 *
 * Copyright (c) 2022 9elements GmbH
 */

#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/pmbus.h>
#include <linux/regulator/driver.h>
#include "pmbus.h"

/*
 * The capability command is only supported at page 0. Probing the device while
 * the page register is set to 1 will falsely enable PEC support. Disable
 * capability probing accordingly, since the PLI1209BC does not have any
 * additional capabilities.
 */
static struct pmbus_platform_data pli1209bc_plat_data = {
	.flags = PMBUS_NO_CAPABILITY,
};

static int pli1209bc_read_word_data(struct i2c_client *client, int page,
				    int phase, int reg)
{
	int data;

	switch (reg) {
	/* PMBUS_READ_POUT uses a direct format with R=0 */
	case PMBUS_READ_POUT:
		data = pmbus_read_word_data(client, page, phase, reg);
		if (data < 0)
			return data;
		data = sign_extend32(data, 15) * 10;
		return clamp_val(data, -32768, 32767) & 0xffff;
	/*
	 * PMBUS_READ_VOUT and PMBUS_READ_TEMPERATURE_1 return invalid data
	 * when the BCM is turned off. Since it is not possible to return
	 * ENODATA error, return zero instead.
	 */
	case PMBUS_READ_VOUT:
	case PMBUS_READ_TEMPERATURE_1:
		data = pmbus_read_word_data(client, page, phase,
					    PMBUS_STATUS_WORD);
		if (data < 0)
			return data;
		if (data & PB_STATUS_POWER_GOOD_N)
			return 0;
		return pmbus_read_word_data(client, page, phase, reg);
	default:
		return -ENODATA;
	}
}

#if IS_ENABLED(CONFIG_SENSORS_PLI1209BC_REGULATOR)
static const struct regulator_desc pli1209bc_reg_desc = {
	.name = "vout2",
	.id = 1,
	.of_match = of_match_ptr("vout2"),
	.regulators_node = of_match_ptr("regulators"),
	.ops = &pmbus_regulator_ops,
	.type = REGULATOR_VOLTAGE,
	.owner = THIS_MODULE,
};
#endif

static struct pmbus_driver_info pli1209bc_info = {
	.pages = 2,
	.format[PSC_VOLTAGE_IN] = direct,
	.format[PSC_VOLTAGE_OUT] = direct,
	.format[PSC_CURRENT_IN] = direct,
	.format[PSC_CURRENT_OUT] = direct,
	.format[PSC_POWER] = direct,
	.format[PSC_TEMPERATURE] = direct,
	.m[PSC_VOLTAGE_IN] = 1,
	.b[PSC_VOLTAGE_IN] = 0,
	.R[PSC_VOLTAGE_IN] = 1,
	.m[PSC_VOLTAGE_OUT] = 1,
	.b[PSC_VOLTAGE_OUT] = 0,
	.R[PSC_VOLTAGE_OUT] = 1,
	.m[PSC_CURRENT_IN] = 1,
	.b[PSC_CURRENT_IN] = 0,
	.R[PSC_CURRENT_IN] = 3,
	.m[PSC_CURRENT_OUT] = 1,
	.b[PSC_CURRENT_OUT] = 0,
	.R[PSC_CURRENT_OUT] = 2,
	.m[PSC_POWER] = 1,
	.b[PSC_POWER] = 0,

Annotation

Implementation Notes