linux/drivers/hwmon/max6650.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * max6650.c - Part of lm_sensors, Linux kernel modules for hardware
 *             monitoring.
 *
 * (C) 2007 by Hans J. Koch <[email protected]>
 *
 * based on code written by John Morris <[email protected]>
 * Copyright (c) 2003 Spirent Communications
 * and Claus Gindhart <[email protected]>
 *
 * This module has only been tested with the MAX6650 chip. It should
 * also work with the MAX6651. It does not distinguish max6650 and max6651
 * chips.
 *
 * The datasheet was last seen at:
 *
 *        http://pdfserv.maxim-ic.com/en/ds/MAX6650-MAX6651.pdf
 */

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

/*
 * Insmod parameters
 */

/* fan_voltage: 5=5V fan, 12=12V fan, 0=don't change */
static int fan_voltage;
/* prescaler: Possible values are 1, 2, 4, 8, 16 or 0 for don't change */
static int prescaler;
/* clock: The clock frequency of the chip (max6651 can be clocked externally) */
static int clock =;

module_param(fan_voltage, int, 0444);
module_param(prescaler, int, 0444);
module_param(clock, int, 0444);

/*
 * MAX 6650/6651 registers
 */

#define MAX6650_REG_SPEED
#define MAX6650_REG_CONFIG
#define MAX6650_REG_GPIO_DEF
#define MAX6650_REG_DAC
#define MAX6650_REG_ALARM_EN
#define MAX6650_REG_ALARM
#define MAX6650_REG_TACH0
#define MAX6650_REG_TACH1
#define MAX6650_REG_TACH2
#define MAX6650_REG_TACH3
#define MAX6650_REG_GPIO_STAT
#define MAX6650_REG_COUNT

/*
 * Config register bits
 */

#define MAX6650_CFG_V12
#define MAX6650_CFG_PRESCALER_MASK
#define MAX6650_CFG_PRESCALER_2
#define MAX6650_CFG_PRESCALER_4
#define MAX6650_CFG_PRESCALER_8
#define MAX6650_CFG_PRESCALER_16
#define MAX6650_CFG_MODE_MASK
#define MAX6650_CFG_MODE_ON
#define MAX6650_CFG_MODE_OFF
#define MAX6650_CFG_MODE_CLOSED_LOOP
#define MAX6650_CFG_MODE_OPEN_LOOP
#define MAX6650_COUNT_MASK

/*
 * Alarm status register bits
 */

#define MAX6650_ALRM_MAX
#define MAX6650_ALRM_MIN
#define MAX6650_ALRM_TACH
#define MAX6650_ALRM_GPIO1
#define MAX6650_ALRM_GPIO2

/* Minimum and maximum values of the FAN-RPM */
#define FAN_RPM_MIN
#define FAN_RPM_MAX

#define DIV_FROM_REG(reg)
#define DAC_LIMIT(v12)

/*
 * Client data (each client gets its own)
 */

struct max6650_data {};

static const u8 tach_reg[] =;

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

static int dac_to_pwm(int dac, bool v12)
{}

static u8 pwm_to_dac(unsigned int pwm, bool v12)
{}

static struct max6650_data *max6650_update_device(struct device *dev)
{}

/*
 * Change the operating mode of the chip (if needed).
 * mode is one of the MAX6650_CFG_MODE_* values.
 */
static int max6650_set_operating_mode(struct max6650_data *data, u8 mode)
{}

/*
 * Set the fan speed to the specified RPM (or read back the RPM setting).
 * This works in closed loop mode only. Use pwm1 for open loop speed setting.
 *
 * The MAX6650/1 will automatically control fan speed when in closed loop
 * mode.
 *
 * Assumptions:
 *
 * 1) The MAX6650/1 internal 254kHz clock frequency is set correctly. Use
 *    the clock module parameter if you need to fine tune this.
 *
 * 2) The prescaler (low three bits of the config register) has already
 *    been set to an appropriate value. Use the prescaler module parameter
 *    if your BIOS doesn't initialize the chip properly.
 *
 * The relevant equations are given on pages 21 and 22 of the datasheet.
 *
 * From the datasheet, the relevant equation when in regulation is:
 *
 *    [fCLK / (128 x (KTACH + 1))] = 2 x FanSpeed / KSCALE
 *
 * where:
 *
 *    fCLK is the oscillator frequency (either the 254kHz internal
 *         oscillator or the externally applied clock)
 *
 *    KTACH is the value in the speed register
 *
 *    FanSpeed is the speed of the fan in rps
 *
 *    KSCALE is the prescaler value (1, 2, 4, 8, or 16)
 *
 * When reading, we need to solve for FanSpeed. When writing, we need to
 * solve for KTACH.
 *
 * Note: this tachometer is completely separate from the tachometers
 * used to measure the fan speeds. Only one fan's speed (fan1) is
 * controlled.
 */

static int max6650_set_target(struct max6650_data *data, unsigned long rpm)
{}

/*
 * Get gpio alarm status:
 * Possible values:
 * 0 = no alarm
 * 1 = alarm
 */

static ssize_t alarm_show(struct device *dev,
			  struct device_attribute *devattr, char *buf)
{}

static SENSOR_DEVICE_ATTR_RO(gpio1_alarm, alarm, MAX6650_ALRM_GPIO1);
static SENSOR_DEVICE_ATTR_RO(gpio2_alarm, alarm, MAX6650_ALRM_GPIO2);

static umode_t max6650_attrs_visible(struct kobject *kobj, struct attribute *a,
				     int n)
{}

static struct attribute *max6650_attrs[] =;

static const struct attribute_group max6650_group =;

static const struct attribute_group *max6650_groups[] =;

static int max6650_init_client(struct max6650_data *data,
			       struct i2c_client *client)
{}

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

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

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

static const struct thermal_cooling_device_ops max6650_cooling_ops =;

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

static const u8 max6650_pwm_modes[] =;

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

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

static const struct hwmon_channel_info * const max6650_info[] =;

static const struct hwmon_ops max6650_hwmon_ops =;

static const struct hwmon_chip_info max6650_chip_info =;

static const struct i2c_device_id max6650_id[];

static int max6650_probe(struct i2c_client *client)
{}

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

static struct i2c_driver max6650_driver =;

module_i2c_driver();

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