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.
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/kernel.hlinux/module.hlinux/init.hlinux/err.hlinux/i2c.hpmbus.h
Detected Declarations
struct max31785_dataenum max31785_regsfunction max31785_waitfunction max31785_i2c_write_byte_datafunction max31785_i2c_read_word_datafunction max31785_read_byte_datafunction max31785_write_bytefunction max31785_read_long_datafunction max31785_get_pwmfunction max31785_get_pwm_modefunction max31785_read_word_datafunction max31785_scale_pwmfunction max31785_pwm_enablefunction max31785_write_word_datafunction max31785_configure_dual_tachfunction max31785_probe
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
- Immediate include surface: `linux/delay.h`, `linux/kernel.h`, `linux/module.h`, `linux/init.h`, `linux/err.h`, `linux/i2c.h`, `pmbus.h`.
- Detected declarations: `struct max31785_data`, `enum max31785_regs`, `function max31785_wait`, `function max31785_i2c_write_byte_data`, `function max31785_i2c_read_word_data`, `function max31785_read_byte_data`, `function max31785_write_byte`, `function max31785_read_long_data`, `function max31785_get_pwm`, `function max31785_get_pwm_mode`.
- Atlas domain: Driver Families / drivers/hwmon.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.