drivers/hwmon/pmbus/inspur-ipsps.c

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

File Facts

System
Linux kernel
Corpus path
drivers/hwmon/pmbus/inspur-ipsps.c
Extension
.c
Size
5874 bytes
Lines
228
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
/*
 * Copyright 2019 Inspur Corp.
 */

#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/pmbus.h>
#include <linux/hwmon-sysfs.h>

#include "pmbus.h"

#define IPSPS_REG_VENDOR_ID	0x99
#define IPSPS_REG_MODEL		0x9A
#define IPSPS_REG_FW_VERSION	0x9B
#define IPSPS_REG_PN		0x9C
#define IPSPS_REG_SN		0x9E
#define IPSPS_REG_HW_VERSION	0xB0
#define IPSPS_REG_MODE		0xFC

#define MODE_ACTIVE		0x55
#define MODE_STANDBY		0x0E
#define MODE_REDUNDANCY		0x00

#define MODE_ACTIVE_STRING		"active"
#define MODE_STANDBY_STRING		"standby"
#define MODE_REDUNDANCY_STRING		"redundancy"

enum ipsps_index {
	vendor,
	model,
	fw_version,
	part_number,
	serial_number,
	hw_version,
	mode,
	num_regs,
};

static const u8 ipsps_regs[num_regs] = {
	[vendor] = IPSPS_REG_VENDOR_ID,
	[model] = IPSPS_REG_MODEL,
	[fw_version] = IPSPS_REG_FW_VERSION,
	[part_number] = IPSPS_REG_PN,
	[serial_number] = IPSPS_REG_SN,
	[hw_version] = IPSPS_REG_HW_VERSION,
	[mode] = IPSPS_REG_MODE,
};

static ssize_t ipsps_string_show(struct device *dev,
				 struct device_attribute *devattr,
				 char *buf)
{
	u8 reg;
	int rc;
	char *p;
	char data[I2C_SMBUS_BLOCK_MAX + 1];
	struct i2c_client *client = to_i2c_client(dev->parent);
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);

	reg = ipsps_regs[attr->index];
	rc = i2c_smbus_read_block_data(client, reg, data);
	if (rc < 0)
		return rc;

	/* filled with printable characters, ending with # */
	p = memscan(data, '#', rc);
	*p = '\0';

	return sysfs_emit(buf, "%s\n", data);
}

static ssize_t ipsps_fw_version_show(struct device *dev,
				     struct device_attribute *devattr,
				     char *buf)
{
	u8 reg;
	int rc;
	u8 data[I2C_SMBUS_BLOCK_MAX] = { 0 };
	struct i2c_client *client = to_i2c_client(dev->parent);
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);

	reg = ipsps_regs[attr->index];
	rc = i2c_smbus_read_block_data(client, reg, data);
	if (rc < 0)
		return rc;

Annotation

Implementation Notes