linux/drivers/hwmon/tc654.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * tc654.c - Linux kernel modules for fan speed controller
 *
 * Copyright (C) 2016 Allied Telesis Labs NZ
 */

#include <linux/bitops.h>
#include <linux/err.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/jiffies.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/thermal.h>
#include <linux/util_macros.h>

enum tc654_regs {};

/* Macros to easily index the registers */
#define TC654_REG_RPM(idx)
#define TC654_REG_FAN_FAULT(idx)

/* Config register bits */
#define TC654_REG_CONFIG_RES
#define TC654_REG_CONFIG_DUTYC
#define TC654_REG_CONFIG_SDM

/* Status register bits */
#define TC654_REG_STATUS_F2F
#define TC654_REG_STATUS_F1F

/* RPM resolution for RPM Output registers */
#define TC654_HIGH_RPM_RESOLUTION
#define TC654_LOW_RPM_RESOLUTION

/* Convert to the fan fault RPM threshold from register value */
#define TC654_FAN_FAULT_FROM_REG(val)

/* Convert to register value from the fan fault RPM threshold */
#define TC654_FAN_FAULT_TO_REG(val)

/* Register data is read (and cached) at most once per second. */
#define TC654_UPDATE_INTERVAL

struct tc654_data {};

/* helper to grab and cache data, at most one time per second */
static struct tc654_data *tc654_update_client(struct device *dev)
{}

/*
 * sysfs attributes
 */

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

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

static ssize_t fan_min_store(struct device *dev, struct device_attribute *da,
			     const char *buf, size_t count)
{}

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

static const u8 TC654_FAN_PULSE_SHIFT[] =;

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

static ssize_t fan_pulses_store(struct device *dev,
				struct device_attribute *da, const char *buf,
				size_t count)
{}

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

static ssize_t pwm_mode_store(struct device *dev, struct device_attribute *da,
			      const char *buf, size_t count)
{}

static const int tc654_pwm_map[16] =;

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

static int _set_pwm(struct tc654_data *data, unsigned long val)
{}

static ssize_t pwm_store(struct device *dev, struct device_attribute *da,
			 const char *buf, size_t count)
{}

static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0);
static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1);
static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
static SENSOR_DEVICE_ATTR_RO(fan1_alarm, fan_alarm, 0);
static SENSOR_DEVICE_ATTR_RO(fan2_alarm, fan_alarm, 1);
static SENSOR_DEVICE_ATTR_RW(fan1_pulses, fan_pulses, 0);
static SENSOR_DEVICE_ATTR_RW(fan2_pulses, fan_pulses, 1);
static SENSOR_DEVICE_ATTR_RW(pwm1_mode, pwm_mode, 0);
static SENSOR_DEVICE_ATTR_RW(pwm1, pwm, 0);

/* Driver data */
static struct attribute *tc654_attrs[] =;

ATTRIBUTE_GROUPS();

/*
 * thermal cooling device functions
 *
 * Account for the "ShutDown Mode (SDM)" state by offsetting
 * the 16 PWM duty cycle states by 1.
 *
 * State  0 =   0% PWM | Shutdown - Fan(s) are off
 * State  1 =  30% PWM | duty_cycle =  0
 * State  2 = ~35% PWM | duty_cycle =  1
 * [...]
 * State 15 = ~95% PWM | duty_cycle = 14
 * State 16 = 100% PWM | duty_cycle = 15
 */
#define TC654_MAX_COOLING_STATE

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

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

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

static const struct thermal_cooling_device_ops tc654_fan_cool_ops =;

/*
 * device probe and removal
 */

static int tc654_probe(struct i2c_client *client)
{}

static const struct i2c_device_id tc654_id[] =;

MODULE_DEVICE_TABLE(i2c, tc654_id);

static struct i2c_driver tc654_driver =;

module_i2c_driver();

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