linux/drivers/hwmon/mlxreg-fan.c

// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
//
// Copyright (c) 2018 Mellanox Technologies. All rights reserved.
// Copyright (c) 2018 Vadim Pasternak <[email protected]>

#include <linux/bitops.h>
#include <linux/device.h>
#include <linux/hwmon.h>
#include <linux/module.h>
#include <linux/platform_data/mlxreg.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include <linux/thermal.h>

#define MLXREG_FAN_MAX_TACHO
#define MLXREG_FAN_MAX_PWM
#define MLXREG_FAN_PWM_NOT_CONNECTED
#define MLXREG_FAN_MAX_STATE
#define MLXREG_FAN_MIN_DUTY
#define MLXREG_FAN_MAX_DUTY
#define MLXREG_FAN_SPEED_MIN_LEVEL
#define MLXREG_FAN_TACHO_SAMPLES_PER_PULSE_DEF
#define MLXREG_FAN_TACHO_DIV_MIN
#define MLXREG_FAN_TACHO_DIV_DEF
#define MLXREG_FAN_TACHO_DIV_SCALE_MAX
/*
 * FAN datasheet defines the formula for RPM calculations as RPM = 15/t-high.
 * The logic in a programmable device measures the time t-high by sampling the
 * tachometer every t-sample (with the default value 11.32 uS) and increment
 * a counter (N) as long as the pulse has not change:
 * RPM = 15 / (t-sample * (K + Regval)), where:
 * Regval: is the value read from the programmable device register;
 *  - 0xff - represents tachometer fault;
 *  - 0xfe - represents tachometer minimum value , which is 4444 RPM;
 *  - 0x00 - represents tachometer maximum value , which is 300000 RPM;
 * K: is 44 and it represents the minimum allowed samples per pulse;
 * N: is equal K + Regval;
 * In order to calculate RPM from the register value the following formula is
 * used: RPM = 15 / ((Regval + K) * 11.32) * 10^(-6)), which in  the
 * default case is modified to:
 * RPM = 15000000 * 100 / ((Regval + 44) * 1132);
 * - for Regval 0x00, RPM will be 15000000 * 100 / (44 * 1132) = 30115;
 * - for Regval 0xfe, RPM will be 15000000 * 100 / ((254 + 44) * 1132) = 4446;
 * In common case the formula is modified to:
 * RPM = 15000000 * 100 / ((Regval + samples) * divider).
 */
#define MLXREG_FAN_GET_RPM(rval, d, s)
#define MLXREG_FAN_GET_FAULT(val, mask)
#define MLXREG_FAN_PWM_DUTY2STATE(duty)
#define MLXREG_FAN_PWM_STATE2DUTY(stat)

struct mlxreg_fan;

/*
 * struct mlxreg_fan_tacho - tachometer data (internal use):
 *
 * @connected: indicates if tachometer is connected;
 * @reg: register offset;
 * @mask: fault mask;
 * @prsnt: present register offset;
 */
struct mlxreg_fan_tacho {};

/*
 * struct mlxreg_fan_pwm - PWM data (internal use):
 *
 * @fan: private data;
 * @connected: indicates if PWM is connected;
 * @reg: register offset;
 * @cooling: cooling device levels;
 * @last_hwmon_state: last cooling state set by hwmon subsystem;
 * @last_thermal_state: last cooling state set by thermal subsystem;
 * @cdev: cooling device;
 */
struct mlxreg_fan_pwm {};

/*
 * struct mlxreg_fan - private data (internal use):
 *
 * @dev: basic device;
 * @regmap: register map of parent device;
 * @tacho: tachometer data;
 * @pwm: PWM data;
 * @tachos_per_drwr - number of tachometers per drawer;
 * @samples: minimum allowed samples per pulse;
 * @divider: divider value for tachometer RPM calculation;
 */
struct mlxreg_fan {};

static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,
				    unsigned long state);

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

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

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

static char *mlxreg_fan_name[] =;

static const struct hwmon_channel_info * const mlxreg_fan_hwmon_info[] =;

static const struct hwmon_ops mlxreg_fan_hwmon_hwmon_ops =;

static const struct hwmon_chip_info mlxreg_fan_hwmon_chip_info =;

static int mlxreg_fan_get_max_state(struct thermal_cooling_device *cdev,
				    unsigned long *state)
{}

static int mlxreg_fan_get_cur_state(struct thermal_cooling_device *cdev,
				    unsigned long *state)

{}

static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,
				    unsigned long state)

{}

static const struct thermal_cooling_device_ops mlxreg_fan_cooling_ops =;

static int mlxreg_fan_connect_verify(struct mlxreg_fan *fan,
				     struct mlxreg_core_data *data)
{}

static int mlxreg_pwm_connect_verify(struct mlxreg_fan *fan,
				     struct mlxreg_core_data *data)
{}

static int mlxreg_fan_speed_divider_get(struct mlxreg_fan *fan,
					struct mlxreg_core_data *data)
{}

static int mlxreg_fan_config(struct mlxreg_fan *fan,
			     struct mlxreg_core_platform_data *pdata)
{}

static int mlxreg_fan_cooling_config(struct device *dev, struct mlxreg_fan *fan)
{}

static int mlxreg_fan_probe(struct platform_device *pdev)
{}

static struct platform_driver mlxreg_fan_driver =;

module_platform_driver();

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