linux/drivers/hwmon/tmp513.c

// SPDX-License-Identifier: GPL-2.0
/*
 * Driver for Texas Instruments TMP512, TMP513 power monitor chips
 *
 * TMP513:
 * Thermal/Power Management with Triple Remote and
 * Local Temperature Sensor and Current Shunt Monitor
 * Datasheet: https://www.ti.com/lit/gpn/tmp513
 *
 * TMP512:
 * Thermal/Power Management with Dual Remote
 *	and Local Temperature Sensor and Current Shunt Monitor
 * Datasheet: https://www.ti.com/lit/gpn/tmp512
 *
 * Copyright (C) 2019 Eric Tremblay <[email protected]>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 */

#include <linux/bitops.h>
#include <linux/bug.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/hwmon.h>
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/math.h>
#include <linux/module.h>
#include <linux/property.h>
#include <linux/regmap.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/units.h>

// Common register definition
#define TMP51X_SHUNT_CONFIG
#define TMP51X_TEMP_CONFIG
#define TMP51X_STATUS
#define TMP51X_SMBUS_ALERT
#define TMP51X_SHUNT_CURRENT_RESULT
#define TMP51X_BUS_VOLTAGE_RESULT
#define TMP51X_POWER_RESULT
#define TMP51X_BUS_CURRENT_RESULT
#define TMP51X_LOCAL_TEMP_RESULT
#define TMP51X_REMOTE_TEMP_RESULT_1
#define TMP51X_REMOTE_TEMP_RESULT_2
#define TMP51X_SHUNT_CURRENT_H_LIMIT
#define TMP51X_SHUNT_CURRENT_L_LIMIT
#define TMP51X_BUS_VOLTAGE_H_LIMIT
#define TMP51X_BUS_VOLTAGE_L_LIMIT
#define TMP51X_POWER_LIMIT
#define TMP51X_LOCAL_TEMP_LIMIT
#define TMP51X_REMOTE_TEMP_LIMIT_1
#define TMP51X_REMOTE_TEMP_LIMIT_2
#define TMP51X_SHUNT_CALIBRATION
#define TMP51X_N_FACTOR_AND_HYST_1
#define TMP51X_N_FACTOR_2
#define TMP51X_MAN_ID_REG
#define TMP51X_DEVICE_ID_REG

// TMP513 specific register definition
#define TMP513_REMOTE_TEMP_RESULT_3
#define TMP513_REMOTE_TEMP_LIMIT_3
#define TMP513_N_FACTOR_3

// Common attrs, and NULL
#define TMP51X_MANUFACTURER_ID

#define TMP512_DEVICE_ID
#define TMP513_DEVICE_ID

// Default config
#define TMP51X_SHUNT_CONFIG_DEFAULT
#define TMP51X_SHUNT_VALUE_DEFAULT
#define TMP51X_VBUS_RANGE_DEFAULT
#define TMP51X_PGA_DEFAULT
#define TMP51X_MAX_REGISTER_ADDR

// Mask and shift
#define CURRENT_SENSE_VOLTAGE_320_MASK
#define CURRENT_SENSE_VOLTAGE_160_MASK
#define CURRENT_SENSE_VOLTAGE_80_MASK
#define CURRENT_SENSE_VOLTAGE_40_MASK

#define TMP51X_BUS_VOLTAGE_MASK
#define TMP51X_NFACTOR_MASK
#define TMP51X_HYST_MASK

#define TMP51X_BUS_VOLTAGE_SHIFT
#define TMP51X_TEMP_SHIFT

// Alarms
#define TMP51X_SHUNT_CURRENT_H_LIMIT_POS
#define TMP51X_SHUNT_CURRENT_L_LIMIT_POS
#define TMP51X_BUS_VOLTAGE_H_LIMIT_POS
#define TMP51X_BUS_VOLTAGE_L_LIMIT_POS
#define TMP51X_POWER_LIMIT_POS
#define TMP51X_LOCAL_TEMP_LIMIT_POS
#define TMP51X_REMOTE_TEMP_LIMIT_1_POS
#define TMP51X_REMOTE_TEMP_LIMIT_2_POS
#define TMP513_REMOTE_TEMP_LIMIT_3_POS

#define TMP51X_VBUS_RANGE_32V
#define TMP51X_VBUS_RANGE_16V

// Max and Min value
#define MAX_BUS_VOLTAGE_32_LIMIT
#define MAX_BUS_VOLTAGE_16_LIMIT

// Max possible value is -256 to +256 but datasheet indicated -40 to 125.
#define MAX_TEMP_LIMIT
#define MIN_TEMP_LIMIT

#define MAX_TEMP_HYST

#define TMP512_MAX_CHANNELS
#define TMP513_MAX_CHANNELS

#define TMP51X_TEMP_CONFIG_CONV_RATE
#define TMP51X_TEMP_CONFIG_RC
#define TMP51X_TEMP_CHANNEL_MASK(n)
#define TMP51X_TEMP_CONFIG_CONT
#define TMP51X_TEMP_CONFIG_DEFAULT(n)

static const u8 TMP51X_TEMP_INPUT[4] =;

static const u8 TMP51X_TEMP_CRIT[4] =;

static const u8 TMP51X_TEMP_CRIT_ALARM[4] =;

static const u8 TMP51X_TEMP_CRIT_HYST[4] =;

static const u8 TMP51X_CURR_INPUT[2] =;

static const struct regmap_config tmp51x_regmap_config =;

struct tmp51x_data {};

// Set the shift based on the gain 8=4, 4=3, 2=2, 1=1
static inline u8 tmp51x_get_pga_shift(struct tmp51x_data *data)
{}

static int tmp51x_get_value(struct tmp51x_data *data, u8 reg, u8 pos,
			    unsigned int regval, long *val)
{}

static int tmp51x_set_value(struct tmp51x_data *data, u8 reg, long val)
{}

static u8 tmp51x_get_reg(enum hwmon_sensor_types type, u32 attr, int channel)
{}

static u8 tmp51x_get_status_pos(enum hwmon_sensor_types type, u32 attr,
				int channel)
{}

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

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

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

static const struct hwmon_channel_info * const tmp51x_info[] =;

static const struct hwmon_ops tmp51x_hwmon_ops =;

static const struct hwmon_chip_info tmp51x_chip_info =;

/*
 * Calibrate the tmp51x following the datasheet method
 */
static int tmp51x_calibrate(struct tmp51x_data *data)
{}

/*
 * Initialize the configuration and calibration registers.
 */
static int tmp51x_init(struct tmp51x_data *data)
{}

static const struct i2c_device_id tmp51x_id[] =;
MODULE_DEVICE_TABLE(i2c, tmp51x_id);

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

static int tmp51x_vbus_range_to_reg(struct device *dev,
				    struct tmp51x_data *data)
{}

static int tmp51x_pga_gain_to_reg(struct device *dev, struct tmp51x_data *data)
{}

static int tmp51x_read_properties(struct device *dev, struct tmp51x_data *data)
{}

static void tmp51x_use_default(struct tmp51x_data *data)
{}

static int tmp51x_configure(struct device *dev, struct tmp51x_data *data)
{}

static int tmp51x_probe(struct i2c_client *client)
{}

static struct i2c_driver tmp51x_driver =;

module_i2c_driver();

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