drivers/hwmon/pmbus/tps25990.c

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

File Facts

System
Linux kernel
Corpus path
drivers/hwmon/pmbus/tps25990.c
Extension
.c
Size
11344 bytes
Lines
443
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
//
// Copyright (c) 2024 BayLibre, SAS.
// Author: Jerome Brunet <jbrunet@baylibre.com>

#include <linux/bitfield.h>
#include <linux/debugfs.h>
#include <linux/err.h>
#include <linux/hwmon-sysfs.h>
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>

#include "pmbus.h"

#define TPS25990_READ_VAUX		0xd0
#define TPS25990_READ_VIN_MIN		0xd1
#define TPS25990_READ_VIN_PEAK		0xd2
#define TPS25990_READ_IIN_PEAK		0xd4
#define TPS25990_READ_PIN_PEAK		0xd5
#define TPS25990_READ_TEMP_AVG		0xd6
#define TPS25990_READ_TEMP_PEAK		0xd7
#define TPS25990_READ_VOUT_MIN		0xda
#define TPS25990_READ_VIN_AVG		0xdc
#define TPS25990_READ_VOUT_AVG		0xdd
#define TPS25990_READ_IIN_AVG		0xde
#define TPS25990_READ_PIN_AVG		0xdf
#define TPS25990_VIREF			0xe0
#define TPS25990_PK_MIN_AVG		0xea
#define  PK_MIN_AVG_RST_PEAK		BIT(7)
#define  PK_MIN_AVG_RST_AVG		BIT(6)
#define  PK_MIN_AVG_RST_MIN		BIT(5)
#define  PK_MIN_AVG_AVG_CNT		GENMASK(2, 0)
#define TPS25990_MFR_WRITE_PROTECT	0xf8
#define  TPS25990_UNLOCKED		BIT(7)

#define TPS25990_8B_SHIFT		2
#define TPS25990_VIN_OVF_NUM		525100
#define TPS25990_VIN_OVF_DIV		10163
#define TPS25990_VIN_OVF_OFF		155
#define TPS25990_IIN_OCF_NUM		953800
#define TPS25990_IIN_OCF_DIV		129278
#define TPS25990_IIN_OCF_OFF		157

#define PK_MIN_AVG_RST_MASK		(PK_MIN_AVG_RST_PEAK | \
					 PK_MIN_AVG_RST_AVG  | \
					 PK_MIN_AVG_RST_MIN)

/*
 * Arbitrary default Rimon value: 1kOhm
 * This correspond to an overcurrent limit of 55A, close to the specified limit
 * of un-stacked TPS25990 and makes further calculation easier to setup in
 * sensor.conf, if necessary
 */
#define TPS25990_DEFAULT_RIMON		1000000000

static void tps25990_set_m(int *m, u32 rimon)
{
	u64 val = ((u64)*m) * rimon;

	/* Make sure m fits the s32 type */
	*m = DIV_ROUND_CLOSEST_ULL(val, 1000000);
}

static int tps25990_mfr_write_protect_set(struct i2c_client *client,
					  u8 protect)
{
	u8 val;

	switch (protect) {
	case 0:
		val = 0xa2;
		break;
	case PB_WP_ALL:
		val = 0x0;
		break;
	default:
		return -EINVAL;
	}

	return pmbus_write_byte_data(client, -1, TPS25990_MFR_WRITE_PROTECT,
				     val);
}

static int tps25990_mfr_write_protect_get(struct i2c_client *client)
{
	int ret = pmbus_read_byte_data(client, -1, TPS25990_MFR_WRITE_PROTECT);

	if (ret < 0)

Annotation

Implementation Notes