drivers/hwmon/pmbus/max31785.c

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

File Facts

System
Linux kernel
Corpus path
drivers/hwmon/pmbus/max31785.c
Extension
.c
Size
11329 bytes
Lines
482
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 max31785_data {
	ktime_t access;			/* Chip access time */
	struct pmbus_driver_info info;
};

/*
 * MAX31785 Driver Workaround
 *
 * The MAX31785 fan controller occasionally exhibits communication issues.
 * These issues are not indicated by the device itself, except for occasional
 * NACK responses during master transactions. No error bits are set in STATUS_BYTE.
 *
 * Keep minimal local delay handling for raw pre-probe SMBus accesses.
 * Normal PMBus-mediated accesses use pmbus_driver_info.access_delay instead.
 */
static inline void max31785_wait(const struct max31785_data *data)
{
	s64 delta = ktime_us_delta(ktime_get(), data->access);

	if (delta < MAX31785_WAIT_DELAY_US)
		usleep_range(MAX31785_WAIT_DELAY_US - delta,
			     MAX31785_WAIT_DELAY_US);
}

static int max31785_i2c_write_byte_data(struct i2c_client *client,
					struct max31785_data *data,
					int command, u8 value)
{
	int rc;

	max31785_wait(data);
	rc = i2c_smbus_write_byte_data(client, command, value);
	data->access = ktime_get();
	return rc;
}

static int max31785_i2c_read_word_data(struct i2c_client *client,
				       struct max31785_data *data,
				       int command)
{
	int rc;

	max31785_wait(data);
	rc = i2c_smbus_read_word_data(client, command);
	data->access = ktime_get();
	return rc;
}

static int max31785_read_byte_data(struct i2c_client *client, int page, int reg)
{
	switch (reg) {
	case PMBUS_VOUT_MODE:
		return -ENOTSUPP;
	case PMBUS_FAN_CONFIG_12:
		if (page < MAX31785_NR_PAGES)
			return -ENODATA;
		return pmbus_read_byte_data(client,
					    page - MAX31785_NR_PAGES,
					    reg);
	}

	return -ENODATA;
}

static int max31785_write_byte(struct i2c_client *client, int page, u8 value)
{
	if (page < MAX31785_NR_PAGES)
		return -ENODATA;

	return -ENOTSUPP;
}

static int max31785_read_long_data(struct i2c_client *client, int page,
				   int reg, u32 *data)
{
	unsigned char cmdbuf[1];
	unsigned char rspbuf[4];
	int rc;

	struct i2c_msg msg[2] = {
		{
			.addr = client->addr,
			.flags = 0,
			.len = sizeof(cmdbuf),
			.buf = cmdbuf,
		},
		{
			.addr = client->addr,
			.flags = I2C_M_RD,
			.len = sizeof(rspbuf),

Annotation

Implementation Notes