linux/drivers/hwmon/ltc4282.c

// SPDX-License-Identifier: GPL-2.0
/*
 * Analog Devices LTC4282 I2C High Current Hot Swap Controller over I2C
 *
 * Copyright 2023 Analog Devices Inc.
 */
#include <linux/bitfield.h>
#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/i2c.h>
#include <linux/math.h>
#include <linux/minmax.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/mutex.h>
#include <linux/regmap.h>
#include <linux/property.h>
#include <linux/string.h>
#include <linux/units.h>
#include <linux/util_macros.h>

#define LTC4282_CTRL_LSB
  #define LTC4282_CTRL_OV_RETRY_MASK
  #define LTC4282_CTRL_UV_RETRY_MASK
  #define LTC4282_CTRL_OC_RETRY_MASK
  #define LTC4282_CTRL_ON_ACTIVE_LOW_MASK
  #define LTC4282_CTRL_ON_DELAY_MASK
#define LTC4282_CTRL_MSB
  #define LTC4282_CTRL_VIN_MODE_MASK
  #define LTC4282_CTRL_OV_MODE_MASK
  #define LTC4282_CTRL_UV_MODE_MASK
#define LTC4282_FAULT_LOG
  #define LTC4282_OV_FAULT_MASK
  #define LTC4282_UV_FAULT_MASK
  #define LTC4282_VDD_FAULT_MASK
  #define LTC4282_OC_FAULT_MASK
  #define LTC4282_POWER_BAD_FAULT_MASK
  #define LTC4282_FET_SHORT_FAULT_MASK
  #define LTC4282_FET_BAD_FAULT_MASK
  #define LTC4282_FET_FAILURE_FAULT_MASK
#define LTC4282_ADC_ALERT_LOG
  #define LTC4282_GPIO_ALARM_L_MASK
  #define LTC4282_GPIO_ALARM_H_MASK
  #define LTC4282_VSOURCE_ALARM_L_MASK
  #define LTC4282_VSOURCE_ALARM_H_MASK
  #define LTC4282_VSENSE_ALARM_L_MASK
  #define LTC4282_VSENSE_ALARM_H_MASK
  #define LTC4282_POWER_ALARM_L_MASK
  #define LTC4282_POWER_ALARM_H_MASK
#define LTC4282_FET_BAD_FAULT_TIMEOUT
  #define LTC4282_FET_BAD_MAX_TIMEOUT
#define LTC4282_GPIO_CONFIG
  #define LTC4282_GPIO_2_FET_STRESS_MASK
  #define LTC4282_GPIO_1_CONFIG_MASK
#define LTC4282_VGPIO_MIN
#define LTC4282_VGPIO_MAX
#define LTC4282_VSOURCE_MIN
#define LTC4282_VSOURCE_MAX
#define LTC4282_VSENSE_MIN
#define LTC4282_VSENSE_MAX
#define LTC4282_POWER_MIN
#define LTC4282_POWER_MAX
#define LTC4282_CLK_DIV
  #define LTC4282_CLK_DIV_MASK
  #define LTC4282_CLKOUT_MASK
#define LTC4282_ILIM_ADJUST
  #define LTC4282_GPIO_MODE_MASK
  #define LTC4282_VDD_MONITOR_MASK
  #define LTC4282_FOLDBACK_MODE_MASK
  #define LTC4282_ILIM_ADJUST_MASK
#define LTC4282_ENERGY
#define LTC4282_TIME_COUNTER
#define LTC4282_ALERT_CTRL
  #define LTC4282_ALERT_OUT_MASK
#define LTC4282_ADC_CTRL
  #define LTC4282_FAULT_LOG_EN_MASK
  #define LTC4282_METER_HALT_MASK
  #define LTC4282_METER_RESET_MASK
  #define LTC4282_RESET_MASK
#define LTC4282_STATUS_LSB
  #define LTC4282_OV_STATUS_MASK
  #define LTC4282_UV_STATUS_MASK
  #define LTC4282_VDD_STATUS_MASK
  #define LTC4282_OC_STATUS_MASK
  #define LTC4282_POWER_GOOD_MASK
  #define LTC4282_FET_FAILURE_MASK
#define LTC4282_STATUS_MSB
#define LTC4282_RESERVED_1
#define LTC4282_RESERVED_2
#define LTC4282_VGPIO
#define LTC4282_VGPIO_LOWEST
#define LTC4282_VGPIO_HIGHEST
#define LTC4282_VSOURCE
#define LTC4282_VSOURCE_LOWEST
#define LTC4282_VSOURCE_HIGHEST
#define LTC4282_VSENSE
#define LTC4282_VSENSE_LOWEST
#define LTC4282_VSENSE_HIGHEST
#define LTC4282_POWER
#define LTC4282_POWER_LOWEST
#define LTC4282_POWER_HIGHEST
#define LTC4282_RESERVED_3

#define LTC4282_CLKIN_MIN
#define LTC4282_CLKIN_MAX
#define LTC4282_CLKIN_RANGE
#define LTC4282_CLKOUT_SYSTEM
#define LTC4282_CLKOUT_CNV

enum {};

struct ltc4282_cache {};

struct ltc4282_state {};

enum {};

static int ltc4282_set_rate(struct clk_hw *hw,
			    unsigned long rate, unsigned long parent_rate)
{}

/*
 * Note the 15HZ conversion rate assumes 12bit ADC which is what we are
 * supporting for now.
 */
static const unsigned int ltc4282_out_rates[] =;

static long ltc4282_round_rate(struct clk_hw *hw, unsigned long rate,
			       unsigned long *parent_rate)
{}

static unsigned long ltc4282_recalc_rate(struct clk_hw *hw,
					 unsigned long parent)
{}

static void ltc4282_disable(struct clk_hw *clk_hw)
{}

static int ltc4282_read_voltage_word(const struct ltc4282_state *st, u32 reg,
				     u32 fs, long *val)
{}

static int ltc4282_read_voltage_byte_cached(const struct ltc4282_state *st,
					    u32 reg, u32 fs, long *val,
					    u32 *cached_raw)
{}

static int ltc4282_read_voltage_byte(const struct ltc4282_state *st, u32 reg,
				     u32 fs, long *val)
{}

static int __ltc4282_read_alarm(struct ltc4282_state *st, u32 reg, u32 mask,
				long *val)
{}

static int ltc4282_read_alarm(struct ltc4282_state *st, u32 reg, u32 mask,
			      long *val)
{}

static int ltc4282_vdd_source_read_in(struct ltc4282_state *st, u32 channel,
				      long *val)
{}

static int ltc4282_vdd_source_read_hist(struct ltc4282_state *st, u32 reg,
					u32 channel, long *cached, long *val)
{}

static int ltc4282_vdd_source_read_lim(struct ltc4282_state *st, u32 reg,
				       u32 channel, u32 *cached, long *val)
{}

static int ltc4282_vdd_source_read_alm(struct ltc4282_state *st, u32 mask,
				       u32 channel, long *val)
{}

static int ltc4282_read_in(struct ltc4282_state *st, u32 attr, long *val,
			   u32 channel)
{}

static int ltc4282_read_current_word(const struct ltc4282_state *st, u32 reg,
				     long *val)
{}

static int ltc4282_read_current_byte(const struct ltc4282_state *st, u32 reg,
				     long *val)
{}

static int ltc4282_read_curr(struct ltc4282_state *st, const u32 attr,
			     long *val)
{}

static int ltc4282_read_power_word(const struct ltc4282_state *st, u32 reg,
				   long *val)
{}

static int ltc4282_read_power_byte(const struct ltc4282_state *st, u32 reg,
				   long *val)
{}

static int ltc4282_read_energy(const struct ltc4282_state *st, u64 *val)
{}

static int ltc4282_read_power(struct ltc4282_state *st, const u32 attr,
			      long *val)
{}

static int ltc4282_read(struct device *dev, enum hwmon_sensor_types type,
			u32 attr, int channel, long *val)
{}

static int ltc4282_write_power_byte(const struct ltc4282_state *st, u32 reg,
				    long val)
{}

static int ltc4282_write_power_word(const struct ltc4282_state *st, u32 reg,
				    long val)
{}

static int __ltc4282_in_write_history(const struct ltc4282_state *st, u32 reg,
				      long lowest, long highest, u32 fs)
{}

static int ltc4282_in_write_history(struct ltc4282_state *st, u32 reg,
				    long lowest, long highest, u32 fs)
{}

static int ltc4282_power_reset_hist(struct ltc4282_state *st)
{}

static int ltc4282_write_power(struct ltc4282_state *st, u32 attr,
			       long val)
{}

static int ltc4282_write_voltage_byte_cached(const struct ltc4282_state *st,
					     u32 reg, u32 fs, long val,
					     u32 *cache_raw)
{}

static int ltc4282_write_voltage_byte(const struct ltc4282_state *st, u32 reg,
				      u32 fs, long val)
{}

static int ltc4282_cache_history(struct ltc4282_state *st, u32 channel)
{}

static int ltc4282_cache_sync(struct ltc4282_state *st, u32 channel)
{}

static int ltc4282_vdd_source_write_lim(struct ltc4282_state *st, u32 reg,
					int channel, u32 *cache, long val)
{}

static int ltc4282_vdd_source_reset_hist(struct ltc4282_state *st, int channel)
{}

/*
 * We need to mux between VSOURCE and VDD which means they are mutually
 * exclusive. Moreover, we can't really disable both VDD and VSOURCE as the ADC
 * is continuously running (we cannot independently halt it without also
 * stopping VGPIO). Hence, the logic is that disabling or enabling VDD will
 * automatically have the reverse effect on VSOURCE and vice-versa.
 */
static int ltc4282_vdd_source_enable(struct ltc4282_state *st, int channel,
				     long val)
{}

static int ltc4282_write_in(struct ltc4282_state *st, u32 attr, long val,
			    int channel)
{}

static int ltc4282_curr_reset_hist(struct ltc4282_state *st)
{}

static int ltc4282_write_curr(struct ltc4282_state *st, u32 attr,
			      long val)
{}

static int ltc4282_energy_enable_set(struct ltc4282_state *st, long val)
{}

static int ltc4282_write(struct device *dev,
			 enum hwmon_sensor_types type,
			 u32 attr, int channel, long val)
{}

static umode_t ltc4282_in_is_visible(const struct ltc4282_state *st, u32 attr)
{}

static umode_t ltc4282_curr_is_visible(u32 attr)
{}

static umode_t ltc4282_power_is_visible(u32 attr)
{}

static umode_t ltc4282_is_visible(const void *data,
				  enum hwmon_sensor_types type,
				  u32 attr, int channel)
{}

static const char * const ltc4282_in_strs[] =;

static int ltc4282_read_labels(struct device *dev,
			       enum hwmon_sensor_types type,
			       u32 attr, int channel, const char **str)
{}

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

static const struct clk_ops ltc4282_ops =;

static int ltc428_clk_provider_setup(struct ltc4282_state *st,
				     struct device *dev)
{}

static int ltc428_clks_setup(struct ltc4282_state *st, struct device *dev)
{}

static const int ltc4282_curr_lim_uv[] =;

static int ltc4282_get_defaults(struct ltc4282_state *st, u32 *vin_mode)
{}

/*
 * Set max limits for ISENSE and Power as that depends on the max voltage on
 * rsense that is defined in ILIM_ADJUST. This is specially important for power
 * because for some rsense and vfsout values, if we allow the default raw 255
 * value, that would overflow long in 32bit archs when reading back the max
 * power limit.
 *
 * Also set meaningful historic values for VDD and VSOURCE
 * (0 would not mean much).
 */
static int ltc4282_set_max_limits(struct ltc4282_state *st)
{}

static const char * const ltc4282_gpio1_modes[] =;

static const char * const ltc4282_gpio2_modes[] =;

static int ltc4282_gpio_setup(struct ltc4282_state *st, struct device *dev)
{}

static const char * const ltc4282_dividers[] =;

/* This maps the Vout full scale for the given Vin mode */
static const u16 ltc4282_vfs_milli[] =;

static const u16 ltc4282_vdd_milli[] =;

enum {};

static int ltc4282_setup(struct ltc4282_state *st, struct device *dev)
{}

static bool ltc4282_readable_reg(struct device *dev, unsigned int reg)
{}

static bool ltc4282_writable_reg(struct device *dev, unsigned int reg)
{}

static const struct regmap_config ltc4282_regmap_config =;

static const struct hwmon_channel_info * const ltc4282_info[] =;

static const struct hwmon_ops ltc4282_hwmon_ops =;

static const struct hwmon_chip_info ltc2947_chip_info =;

/* energy attributes are 6bytes wide so we need u64 */
static SENSOR_DEVICE_ATTR_RO(energy1_input, ltc4282_energy, 0);

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

static int ltc4282_show_fault_log(void *arg, u64 *val, u32 mask)
{}

static int ltc4282_show_curr1_crit_fault_log(void *arg, u64 *val)
{}
DEFINE_DEBUGFS_ATTRIBUTE();

static int ltc4282_show_in1_lcrit_fault_log(void *arg, u64 *val)
{}
DEFINE_DEBUGFS_ATTRIBUTE();

static int ltc4282_show_in1_crit_fault_log(void *arg, u64 *val)
{}
DEFINE_DEBUGFS_ATTRIBUTE();

static int ltc4282_show_fet_bad_fault_log(void *arg, u64 *val)
{}
DEFINE_DEBUGFS_ATTRIBUTE();

static int ltc4282_show_fet_short_fault_log(void *arg, u64 *val)
{}
DEFINE_DEBUGFS_ATTRIBUTE();

static int ltc4282_show_power1_bad_fault_log(void *arg, u64 *val)
{}
DEFINE_DEBUGFS_ATTRIBUTE();

static void ltc4282_debugfs_remove(void *dir)
{}

static void ltc4282_debugfs_init(struct ltc4282_state *st,
				 struct i2c_client *i2c,
				 const struct device *hwmon)
{}

static int ltc4282_probe(struct i2c_client *i2c)
{}

static const struct of_device_id ltc4282_of_match[] =;
MODULE_DEVICE_TABLE(of, ltc4282_of_match);

static struct i2c_driver ltc4282_driver =;
module_i2c_driver();

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