drivers/hwmon/pmbus/bpa-rs600.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/pmbus/bpa-rs600.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/pmbus/bpa-rs600.c- Extension
.c- Size
- 4939 bytes
- Lines
- 209
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/i2c.hlinux/init.hlinux/kernel.hlinux/module.hlinux/pmbus.hpmbus.h
Detected Declarations
enum chipsfunction bpa_rs600_read_byte_datafunction bpa_rs600_read_vinfunction bpa_rs600_read_pin_maxfunction bpa_rs600_read_word_datafunction bpa_rs600_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Hardware monitoring driver for BluTek BPA-RS600 Power Supplies
*
* Copyright 2021 Allied Telesis Labs
*/
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pmbus.h>
#include "pmbus.h"
enum chips { bpa_rs600, bpd_rs600 };
static int bpa_rs600_read_byte_data(struct i2c_client *client, int page, int reg)
{
int ret;
if (page > 0)
return -ENXIO;
switch (reg) {
case PMBUS_FAN_CONFIG_12:
/*
* Two fans are reported in PMBUS_FAN_CONFIG_12 but there is
* only one fan in the module. Mask out the FAN2 bits.
*/
ret = pmbus_read_byte_data(client, 0, PMBUS_FAN_CONFIG_12);
if (ret >= 0)
ret &= ~(PB_FAN_2_INSTALLED | PB_FAN_2_PULSE_MASK);
break;
default:
ret = -ENODATA;
break;
}
return ret;
}
/*
* The BPA-RS600 violates the PMBus spec. Specifically it treats the
* mantissa as unsigned. Deal with this here to allow the PMBus core
* to work with correctly encoded data.
*/
static int bpa_rs600_read_vin(struct i2c_client *client)
{
int ret, exponent, mantissa;
ret = pmbus_read_word_data(client, 0, 0xff, PMBUS_READ_VIN);
if (ret < 0)
return ret;
if (ret & BIT(10)) {
exponent = ret >> 11;
mantissa = ret & 0x7ff;
exponent++;
mantissa >>= 1;
ret = (exponent << 11) | mantissa;
}
return ret;
}
/*
* Firmware V5.70 incorrectly reports 1640W for MFR_PIN_MAX.
* Deal with this by returning a sensible value.
*/
static int bpa_rs600_read_pin_max(struct i2c_client *client)
{
int ret;
ret = pmbus_read_word_data(client, 0, 0xff, PMBUS_MFR_PIN_MAX);
if (ret < 0)
return ret;
/* Detect invalid 1640W (linear encoding) */
if (ret == 0x0b34)
/* Report 700W (linear encoding) */
return 0x095e;
return ret;
}
static int bpa_rs600_read_word_data(struct i2c_client *client, int page, int phase, int reg)
{
int ret;
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/pmbus.h`, `pmbus.h`.
- Detected declarations: `enum chips`, `function bpa_rs600_read_byte_data`, `function bpa_rs600_read_vin`, `function bpa_rs600_read_pin_max`, `function bpa_rs600_read_word_data`, `function bpa_rs600_probe`.
- 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.