drivers/hwmon/pmbus/lx1308.c

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

File Facts

System
Linux kernel
Corpus path
drivers/hwmon/pmbus/lx1308.c
Extension
.c
Size
5094 bytes
Lines
205
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-or-later

#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include "pmbus.h"

#define LX1308_MFR_IOUT_OCP3_FAULT	0xBE
#define LX1308_MFR_IOUT_OCP3_WARN	0xBF

/*
 * Decode a Linear11-encoded word to an integer value.
 * Linear11 format: bits[15:11] = signed 5-bit exponent,
 * bits[10:0] = signed 11-bit mantissa. Result = mant * 2^exp.
 */
static inline int linear11_to_int(u16 word)
{
	s16 exp = ((s16)word) >> 11;
	s16 mant = ((s16)((word & 0x7ff) << 5)) >> 5;

	return (exp >= 0) ? (int)((u32)mant << exp) : (mant >> -exp);
}

static int lx1308_read_word_data(struct i2c_client *client, int page,
				 int phase, int reg)
{
	int ret;

	if (page > 0)
		return -ENXIO;

	switch (reg) {
	/*
	 * The LX1308 OCP3 registers (slow OCP, 60ms delay) use a
	 * manufacturer-specific U8.0 format. Read the byte value N and present
	 * it as a Linear11 word with exponent 0.
	 */
	case PMBUS_IOUT_OC_FAULT_LIMIT:
		ret = i2c_smbus_read_byte_data(client, LX1308_MFR_IOUT_OCP3_FAULT);
		if (ret < 0)
			break;
		ret &= 0x7FF;
		break;

	case PMBUS_IOUT_OC_WARN_LIMIT:
		ret = i2c_smbus_read_byte_data(client, LX1308_MFR_IOUT_OCP3_WARN);
		if (ret < 0)
			break;
		ret &= 0x7FF;
		break;

	/*
	 * The following registers are not implemented by the LX1308. Return
	 * -ENXIO to suppress the corresponding sysfs attributes.
	 */
	case PMBUS_IIN_OC_WARN_LIMIT:
	case PMBUS_IIN_OC_FAULT_LIMIT:
	case PMBUS_IOUT_UC_FAULT_LIMIT:
	case PMBUS_PIN_OP_WARN_LIMIT:
	case PMBUS_POUT_OP_WARN_LIMIT:
	case PMBUS_UT_WARN_LIMIT:
	case PMBUS_UT_FAULT_LIMIT:
	case PMBUS_MFR_IIN_MAX:
	case PMBUS_MFR_IOUT_MAX:
	case PMBUS_MFR_VIN_MIN:
	case PMBUS_MFR_VIN_MAX:
	case PMBUS_MFR_VOUT_MIN:
	case PMBUS_MFR_VOUT_MAX:
	case PMBUS_MFR_PIN_MAX:
	case PMBUS_MFR_POUT_MAX:
	case PMBUS_MFR_MAX_TEMP_1:
		ret = -ENXIO;
		break;

	default:
		ret = -ENODATA;
		break;
	}

	return ret;
}

static int lx1308_write_word_data(struct i2c_client *client, int page,
				  int reg, u16 word)
{
	int ret;

	if (page > 0)
		return -ENXIO;

Annotation

Implementation Notes