#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/mutex.h>
#include <linux/sysfs.h>
static const unsigned short normal_i2c[] = …;
enum chips { … };
#define GL518_REG_CHIP_ID …
#define GL518_REG_REVISION …
#define GL518_REG_VENDOR_ID …
#define GL518_REG_CONF …
#define GL518_REG_TEMP_IN …
#define GL518_REG_TEMP_MAX …
#define GL518_REG_TEMP_HYST …
#define GL518_REG_FAN_COUNT …
#define GL518_REG_FAN_LIMIT …
#define GL518_REG_VIN1_LIMIT …
#define GL518_REG_VIN2_LIMIT …
#define GL518_REG_VIN3_LIMIT …
#define GL518_REG_VDD_LIMIT …
#define GL518_REG_VIN3 …
#define GL518_REG_MISC …
#define GL518_REG_ALARM …
#define GL518_REG_MASK …
#define GL518_REG_INT …
#define GL518_REG_VIN2 …
#define GL518_REG_VIN1 …
#define GL518_REG_VDD …
#define RAW_FROM_REG(val) …
#define BOOL_FROM_REG(val) …
#define BOOL_TO_REG(val) …
#define TEMP_CLAMP(val) …
#define TEMP_TO_REG(val) …
#define TEMP_FROM_REG(val) …
static inline u8 FAN_TO_REG(long rpm, int div)
{ … }
#define FAN_FROM_REG(val, div) …
#define IN_CLAMP(val) …
#define IN_TO_REG(val) …
#define IN_FROM_REG(val) …
#define VDD_CLAMP(val) …
#define VDD_TO_REG(val) …
#define VDD_FROM_REG(val) …
#define DIV_FROM_REG(val) …
#define BEEP_MASK_TO_REG(val) …
#define BEEP_MASK_FROM_REG(val) …
struct gl518_data { … };
static int gl518_read_value(struct i2c_client *client, u8 reg)
{ … }
static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value)
{ … }
static struct gl518_data *gl518_update_device(struct device *dev)
{ … }
#define show(type, suffix, value) …
show(TEMP, temp_input1, temp_in);
show(TEMP, temp_max1, temp_max);
show(TEMP, temp_hyst1, temp_hyst);
show(BOOL, fan_auto1, fan_auto1);
show(VDD, in_input0, voltage_in[0]);
show(IN, in_input1, voltage_in[1]);
show(IN, in_input2, voltage_in[2]);
show(IN, in_input3, voltage_in[3]);
show(VDD, in_min0, voltage_min[0]);
show(IN, in_min1, voltage_min[1]);
show(IN, in_min2, voltage_min[2]);
show(IN, in_min3, voltage_min[3]);
show(VDD, in_max0, voltage_max[0]);
show(IN, in_max1, voltage_max[1]);
show(IN, in_max2, voltage_max[2]);
show(IN, in_max3, voltage_max[3]);
show(RAW, alarms, alarms);
show(BOOL, beep_enable, beep_enable);
show(BEEP_MASK, beep_mask, beep_mask);
static ssize_t fan_input_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
static ssize_t fan_div_show(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
#define set(type, suffix, value, reg) …
#define set_bits(type, suffix, value, reg, mask, shift) …
#define set_low(type, suffix, value, reg) …
#define set_high(type, suffix, value, reg) …
set(TEMP, temp_max1, temp_max, GL518_REG_TEMP_MAX);
set(TEMP, temp_hyst1, temp_hyst, GL518_REG_TEMP_HYST);
set_bits(BOOL, fan_auto1, fan_auto1, GL518_REG_MISC, 0x08, 3);
set_low(VDD, in_min0, voltage_min[0], GL518_REG_VDD_LIMIT);
set_low(IN, in_min1, voltage_min[1], GL518_REG_VIN1_LIMIT);
set_low(IN, in_min2, voltage_min[2], GL518_REG_VIN2_LIMIT);
set_low(IN, in_min3, voltage_min[3], GL518_REG_VIN3_LIMIT);
set_high(VDD, in_max0, voltage_max[0], GL518_REG_VDD_LIMIT);
set_high(IN, in_max1, voltage_max[1], GL518_REG_VIN1_LIMIT);
set_high(IN, in_max2, voltage_max[2], GL518_REG_VIN2_LIMIT);
set_high(IN, in_max3, voltage_max[3], GL518_REG_VIN3_LIMIT);
set_bits(BOOL, beep_enable, beep_enable, GL518_REG_CONF, 0x04, 2);
set(BEEP_MASK, beep_mask, beep_mask, GL518_REG_ALARM);
static ssize_t fan_min_store(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t count)
{ … }
static ssize_t fan_div_store(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t count)
{ … }
static DEVICE_ATTR(temp1_input, 0444, show_temp_input1, NULL);
static DEVICE_ATTR(temp1_max, 0644, show_temp_max1, set_temp_max1);
static DEVICE_ATTR(temp1_max_hyst, 0644,
show_temp_hyst1, set_temp_hyst1);
static DEVICE_ATTR(fan1_auto, 0644, show_fan_auto1, set_fan_auto1);
static SENSOR_DEVICE_ATTR_RO(fan1_input, fan_input, 0);
static SENSOR_DEVICE_ATTR_RO(fan2_input, fan_input, 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_RW(fan1_div, fan_div, 0);
static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1);
static DEVICE_ATTR(in0_input, 0444, show_in_input0, NULL);
static DEVICE_ATTR(in1_input, 0444, show_in_input1, NULL);
static DEVICE_ATTR(in2_input, 0444, show_in_input2, NULL);
static DEVICE_ATTR(in3_input, 0444, show_in_input3, NULL);
static DEVICE_ATTR(in0_min, 0644, show_in_min0, set_in_min0);
static DEVICE_ATTR(in1_min, 0644, show_in_min1, set_in_min1);
static DEVICE_ATTR(in2_min, 0644, show_in_min2, set_in_min2);
static DEVICE_ATTR(in3_min, 0644, show_in_min3, set_in_min3);
static DEVICE_ATTR(in0_max, 0644, show_in_max0, set_in_max0);
static DEVICE_ATTR(in1_max, 0644, show_in_max1, set_in_max1);
static DEVICE_ATTR(in2_max, 0644, show_in_max2, set_in_max2);
static DEVICE_ATTR(in3_max, 0644, show_in_max3, set_in_max3);
static DEVICE_ATTR(alarms, 0444, show_alarms, NULL);
static DEVICE_ATTR(beep_enable, 0644,
show_beep_enable, set_beep_enable);
static DEVICE_ATTR(beep_mask, 0644,
show_beep_mask, set_beep_mask);
static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0);
static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1);
static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2);
static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3);
static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4);
static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 5);
static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 6);
static ssize_t beep_show(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
static ssize_t beep_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ … }
static SENSOR_DEVICE_ATTR_RW(in0_beep, beep, 0);
static SENSOR_DEVICE_ATTR_RW(in1_beep, beep, 1);
static SENSOR_DEVICE_ATTR_RW(in2_beep, beep, 2);
static SENSOR_DEVICE_ATTR_RW(in3_beep, beep, 3);
static SENSOR_DEVICE_ATTR_RW(temp1_beep, beep, 4);
static SENSOR_DEVICE_ATTR_RW(fan1_beep, beep, 5);
static SENSOR_DEVICE_ATTR_RW(fan2_beep, beep, 6);
static struct attribute *gl518_attributes[] = …;
static const struct attribute_group gl518_group = …;
static struct attribute *gl518_attributes_r80[] = …;
static const struct attribute_group gl518_group_r80 = …;
static int gl518_detect(struct i2c_client *client, struct i2c_board_info *info)
{ … }
static void gl518_init_client(struct i2c_client *client)
{ … }
static int gl518_probe(struct i2c_client *client)
{ … }
static const struct i2c_device_id gl518_id[] = …;
MODULE_DEVICE_TABLE(i2c, gl518_id);
static struct i2c_driver gl518_driver = …;
module_i2c_driver(…) …;
MODULE_AUTHOR(…) …;
MODULE_DESCRIPTION(…) …;
MODULE_LICENSE(…) …;