linux/drivers/hwmon/ltc4261.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Driver for Linear Technology LTC4261 I2C Negative Voltage Hot Swap Controller
 *
 * Copyright (C) 2010 Ericsson AB.
 *
 * Derived from:
 *
 *  Driver for Linear Technology LTC4245 I2C Multiple Supply Hot Swap Controller
 *  Copyright (C) 2008 Ira W. Snyder <[email protected]>
 *
 * Datasheet: http://cds.linear.com/docs/Datasheet/42612fb.pdf
 */

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

/* chip registers */
#define LTC4261_STATUS
#define LTC4261_FAULT
#define LTC4261_ALERT
#define LTC4261_CONTROL
#define LTC4261_SENSE_H
#define LTC4261_SENSE_L
#define LTC4261_ADIN2_H
#define LTC4261_ADIN2_L
#define LTC4261_ADIN_H
#define LTC4261_ADIN_L

/*
 * Fault register bits
 */
#define FAULT_OV
#define FAULT_UV
#define FAULT_OC

struct ltc4261_data {};

static struct ltc4261_data *ltc4261_update_device(struct device *dev)
{}

/* Return the voltage from the given register in mV or mA */
static int ltc4261_get_value(struct ltc4261_data *data, u8 reg)
{}

static ssize_t ltc4261_value_show(struct device *dev,
				  struct device_attribute *da, char *buf)
{}

static ssize_t ltc4261_bool_show(struct device *dev,
				 struct device_attribute *da, char *buf)
{}

/*
 * Input voltages.
 */
static SENSOR_DEVICE_ATTR_RO(in1_input, ltc4261_value, LTC4261_ADIN_H);
static SENSOR_DEVICE_ATTR_RO(in2_input, ltc4261_value, LTC4261_ADIN2_H);

/*
 * Voltage alarms. The chip has only one set of voltage alarm status bits,
 * triggered by input voltage alarms. In many designs, those alarms are
 * associated with the ADIN2 sensor, due to the proximity of the ADIN2 pin
 * to the OV pin. ADIN2 is, however, not available on all chip variants.
 * To ensure that the alarm condition is reported to the user, report it
 * with both voltage sensors.
 */
static SENSOR_DEVICE_ATTR_RO(in1_min_alarm, ltc4261_bool, FAULT_UV);
static SENSOR_DEVICE_ATTR_RO(in1_max_alarm, ltc4261_bool, FAULT_OV);
static SENSOR_DEVICE_ATTR_RO(in2_min_alarm, ltc4261_bool, FAULT_UV);
static SENSOR_DEVICE_ATTR_RO(in2_max_alarm, ltc4261_bool, FAULT_OV);

/* Currents (via sense resistor) */
static SENSOR_DEVICE_ATTR_RO(curr1_input, ltc4261_value, LTC4261_SENSE_H);

/* Overcurrent alarm */
static SENSOR_DEVICE_ATTR_RO(curr1_max_alarm, ltc4261_bool, FAULT_OC);

static struct attribute *ltc4261_attrs[] =;
ATTRIBUTE_GROUPS();

static int ltc4261_probe(struct i2c_client *client)
{}

static const struct i2c_device_id ltc4261_id[] =;

MODULE_DEVICE_TABLE(i2c, ltc4261_id);

/* This is the driver that will be inserted */
static struct i2c_driver ltc4261_driver =;

module_i2c_driver();

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();