drivers/hwmon/pmbus/ibm-cffps.c

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

File Facts

System
Linux kernel
Corpus path
drivers/hwmon/pmbus/ibm-cffps.c
Extension
.c
Size
14883 bytes
Lines
608
Domain
Driver Families
Bucket
drivers/hwmon
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern 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

static const struct file_operations ibm_cffps_input_history_fops = {
	.llseek = noop_llseek,
	.read = ibm_cffps_debugfs_read_input_history,
	.open = simple_open,
};

static ssize_t ibm_cffps_debugfs_read(struct file *file, char __user *buf,
				      size_t count, loff_t *ppos)
{
	int i, rc;
	int *idxp = file->private_data;
	int idx = *idxp;
	struct ibm_cffps *psu = to_psu(idxp, idx);
	char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };

	rc = pmbus_lock_interruptible(psu->client);
	if (rc)
		return rc;

	rc = pmbus_set_page(psu->client, 0, 0xff);
	if (rc)
		goto unlock;

	switch (idx) {
	case CFFPS_DEBUGFS_MAX_POWER_OUT:
		if (psu->version == cffps1)
			rc = i2c_smbus_read_word_swapped(psu->client, PMBUS_MFR_POUT_MAX);
		else
			rc = i2c_smbus_read_word_data(psu->client, PMBUS_MFR_POUT_MAX);
		if (rc >= 0)
			rc = snprintf(data, I2C_SMBUS_BLOCK_MAX, "%d", rc);
		break;
	case CFFPS_DEBUGFS_CCIN:
		rc = i2c_smbus_read_word_swapped(psu->client, CFFPS_CCIN_CMD);
		if (rc >= 0)
			rc = snprintf(data, 5, "%04X", rc);
		break;
	case CFFPS_DEBUGFS_FW:
		switch (psu->version) {
		case cffps1:
			for (i = 0; i < CFFPS1_FW_NUM_BYTES; ++i) {
				rc = i2c_smbus_read_byte_data(psu->client, CFFPS_FW_CMD + i);
				if (rc < 0)
					goto unlock;

				snprintf(&data[i * 2], 3, "%02X", rc);
			}

			rc = i * 2;
			break;
		case cffps2:
			for (i = 0; i < CFFPS2_FW_NUM_WORDS; ++i) {
				rc = i2c_smbus_read_word_data(psu->client, CFFPS_FW_CMD + i);
				if (rc < 0)
					goto unlock;

				snprintf(&data[i * 4], 5, "%04X", rc);
			}

			rc = i * 4;
			break;
		default:
			rc = -EOPNOTSUPP;
			break;
		}
		break;
	case CFFPS_DEBUGFS_ON_OFF_CONFIG:
		rc = i2c_smbus_read_byte_data(psu->client, PMBUS_ON_OFF_CONFIG);
		if (rc >= 0)
			rc = snprintf(data, 3, "%02x", rc);
		break;
	default:
		rc = -EINVAL;
		break;
	}

unlock:
	pmbus_unlock(psu->client);
	if (rc < 0)
		return rc;

	data[rc] = '\n';
	rc += 2;

	return simple_read_from_buffer(buf, count, ppos, data, rc);
}

static ssize_t ibm_cffps_debugfs_write(struct file *file,
				       const char __user *buf, size_t count,
				       loff_t *ppos)

Annotation

Implementation Notes