^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * gl518sm.c - Part of lm_sensors, Linux kernel modules for hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * monitoring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl> and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Kyosti Malkki <kmalkki@cc.hut.fi>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2004 Hong-Gunn Chew <hglinux@gunnet.org> and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Jean Delvare <jdelvare@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Ported to Linux 2.6 by Hong-Gunn Chew with the help of Jean Delvare
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * and advice of Greg Kroah-Hartman.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Notes about the port:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Release 0x00 of the GL518SM chipset doesn't support reading of in0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * in1 nor in2. The original driver had an ugly workaround to get them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * anyway (changing limits and watching alarms trigger and wear off).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * We did not keep that part of the original driver in the Linux 2.6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * version, since it was making the driver significantly more complex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * with no real benefit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/hwmon-sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* Addresses to scan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static const unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) enum chips { gl518sm_r00, gl518sm_r80 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /* Many GL518 constants specified below */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* The GL518 registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define GL518_REG_CHIP_ID 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define GL518_REG_REVISION 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define GL518_REG_VENDOR_ID 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define GL518_REG_CONF 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define GL518_REG_TEMP_IN 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define GL518_REG_TEMP_MAX 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define GL518_REG_TEMP_HYST 0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define GL518_REG_FAN_COUNT 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define GL518_REG_FAN_LIMIT 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define GL518_REG_VIN1_LIMIT 0x09
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define GL518_REG_VIN2_LIMIT 0x0a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define GL518_REG_VIN3_LIMIT 0x0b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define GL518_REG_VDD_LIMIT 0x0c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define GL518_REG_VIN3 0x0d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define GL518_REG_MISC 0x0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define GL518_REG_ALARM 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define GL518_REG_MASK 0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define GL518_REG_INT 0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define GL518_REG_VIN2 0x13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define GL518_REG_VIN1 0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define GL518_REG_VDD 0x15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * Conversions. Rounding and limit checking is only done on the TO_REG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * variants. Note that you should be a bit careful with which arguments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * these macros are called: arguments may be evaluated more than once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * Fixing this is just not worth it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define RAW_FROM_REG(val) val
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define BOOL_FROM_REG(val) ((val) ? 0 : 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define BOOL_TO_REG(val) ((val) ? 0 : 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define TEMP_CLAMP(val) clamp_val(val, -119000, 136000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define TEMP_TO_REG(val) (DIV_ROUND_CLOSEST(TEMP_CLAMP(val), 1000) + 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define TEMP_FROM_REG(val) (((val) - 119) * 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static inline u8 FAN_TO_REG(long rpm, int div)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) long rpmdiv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (rpm == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) rpmdiv = clamp_val(rpm, 1, 960000) * div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return clamp_val((480000 + rpmdiv / 2) / rpmdiv, 1, 255);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (480000 / ((val) * (div))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define IN_CLAMP(val) clamp_val(val, 0, 255 * 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define IN_TO_REG(val) DIV_ROUND_CLOSEST(IN_CLAMP(val), 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define IN_FROM_REG(val) ((val) * 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define VDD_CLAMP(val) clamp_val(val, 0, 255 * 95 / 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define VDD_TO_REG(val) DIV_ROUND_CLOSEST(VDD_CLAMP(val) * 4, 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define VDD_FROM_REG(val) DIV_ROUND_CLOSEST((val) * 95, 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define DIV_FROM_REG(val) (1 << (val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define BEEP_MASK_TO_REG(val) ((val) & 0x7f & data->alarm_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define BEEP_MASK_FROM_REG(val) ((val) & 0x7f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /* Each client has this additional data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct gl518_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) const struct attribute_group *groups[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) enum chips type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct mutex update_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) char valid; /* !=0 if following fields are valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) unsigned long last_updated; /* In jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) u8 voltage_in[4]; /* Register values; [0] = VDD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) u8 voltage_min[4]; /* Register values; [0] = VDD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) u8 voltage_max[4]; /* Register values; [0] = VDD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) u8 fan_in[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) u8 fan_min[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) u8 fan_div[2]; /* Register encoding, shifted right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) u8 fan_auto1; /* Boolean */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) u8 temp_in; /* Register values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) u8 temp_max; /* Register values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) u8 temp_hyst; /* Register values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) u8 alarms; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) u8 alarm_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) u8 beep_mask; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) u8 beep_enable; /* Boolean */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * Registers 0x07 to 0x0c are word-sized, others are byte-sized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * GL518 uses a high-byte first convention, which is exactly opposite to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * the SMBus standard.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static int gl518_read_value(struct i2c_client *client, u8 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if ((reg >= 0x07) && (reg <= 0x0c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return i2c_smbus_read_word_swapped(client, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return i2c_smbus_read_byte_data(client, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if ((reg >= 0x07) && (reg <= 0x0c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return i2c_smbus_write_word_swapped(client, reg, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return i2c_smbus_write_byte_data(client, reg, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static struct gl518_data *gl518_update_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct gl518_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) || !data->valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) dev_dbg(&client->dev, "Starting gl518 update\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) data->alarms = gl518_read_value(client, GL518_REG_INT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) data->beep_mask = gl518_read_value(client, GL518_REG_ALARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) val = gl518_read_value(client, GL518_REG_VDD_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) data->voltage_min[0] = val & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) data->voltage_max[0] = (val >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) val = gl518_read_value(client, GL518_REG_VIN1_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) data->voltage_min[1] = val & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) data->voltage_max[1] = (val >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) val = gl518_read_value(client, GL518_REG_VIN2_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) data->voltage_min[2] = val & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) data->voltage_max[2] = (val >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) val = gl518_read_value(client, GL518_REG_VIN3_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) data->voltage_min[3] = val & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) data->voltage_max[3] = (val >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) val = gl518_read_value(client, GL518_REG_FAN_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) data->fan_in[0] = (val >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) data->fan_in[1] = val & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) val = gl518_read_value(client, GL518_REG_FAN_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) data->fan_min[0] = (val >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) data->fan_min[1] = val & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) data->temp_in = gl518_read_value(client, GL518_REG_TEMP_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) data->temp_max =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) gl518_read_value(client, GL518_REG_TEMP_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) data->temp_hyst =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) gl518_read_value(client, GL518_REG_TEMP_HYST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) val = gl518_read_value(client, GL518_REG_MISC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) data->fan_div[0] = (val >> 6) & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) data->fan_div[1] = (val >> 4) & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) data->fan_auto1 = (val >> 3) & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) data->alarms &= data->alarm_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) val = gl518_read_value(client, GL518_REG_CONF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) data->beep_enable = (val >> 2) & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (data->type != gl518sm_r00) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) data->voltage_in[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) gl518_read_value(client, GL518_REG_VDD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) data->voltage_in[1] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) gl518_read_value(client, GL518_REG_VIN1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) data->voltage_in[2] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) gl518_read_value(client, GL518_REG_VIN2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) data->voltage_in[3] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) gl518_read_value(client, GL518_REG_VIN3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) data->last_updated = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) data->valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * Sysfs stuff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #define show(type, suffix, value) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static ssize_t show_##suffix(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct device_attribute *attr, char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct gl518_data *data = gl518_update_device(dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return sprintf(buf, "%d\n", type##_FROM_REG(data->value)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) show(TEMP, temp_input1, temp_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) show(TEMP, temp_max1, temp_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) show(TEMP, temp_hyst1, temp_hyst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) show(BOOL, fan_auto1, fan_auto1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) show(VDD, in_input0, voltage_in[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) show(IN, in_input1, voltage_in[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) show(IN, in_input2, voltage_in[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) show(IN, in_input3, voltage_in[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) show(VDD, in_min0, voltage_min[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) show(IN, in_min1, voltage_min[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) show(IN, in_min2, voltage_min[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) show(IN, in_min3, voltage_min[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) show(VDD, in_max0, voltage_max[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) show(IN, in_max1, voltage_max[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) show(IN, in_max2, voltage_max[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) show(IN, in_max3, voltage_max[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) show(RAW, alarms, alarms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) show(BOOL, beep_enable, beep_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) show(BEEP_MASK, beep_mask, beep_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static ssize_t fan_input_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct gl518_data *data = gl518_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_in[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) DIV_FROM_REG(data->fan_div[nr])));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) struct gl518_data *data = gl518_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) DIV_FROM_REG(data->fan_div[nr])));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static ssize_t fan_div_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct gl518_data *data = gl518_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #define set(type, suffix, value, reg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static ssize_t set_##suffix(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct device_attribute *attr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) const char *buf, size_t count) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct gl518_data *data = dev_get_drvdata(dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct i2c_client *client = data->client; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) long val; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) int err = kstrtol(buf, 10, &val); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (err) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return err; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) mutex_lock(&data->update_lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) data->value = type##_TO_REG(val); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) gl518_write_value(client, reg, data->value); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) mutex_unlock(&data->update_lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return count; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) #define set_bits(type, suffix, value, reg, mask, shift) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static ssize_t set_##suffix(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) struct device_attribute *attr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) const char *buf, size_t count) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct gl518_data *data = dev_get_drvdata(dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct i2c_client *client = data->client; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) int regvalue; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) unsigned long val; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) int err = kstrtoul(buf, 10, &val); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (err) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return err; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) mutex_lock(&data->update_lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) regvalue = gl518_read_value(client, reg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) data->value = type##_TO_REG(val); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) regvalue = (regvalue & ~mask) | (data->value << shift); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) gl518_write_value(client, reg, regvalue); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) mutex_unlock(&data->update_lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) return count; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) #define set_low(type, suffix, value, reg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) set_bits(type, suffix, value, reg, 0x00ff, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) #define set_high(type, suffix, value, reg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) set_bits(type, suffix, value, reg, 0xff00, 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) set(TEMP, temp_max1, temp_max, GL518_REG_TEMP_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) set(TEMP, temp_hyst1, temp_hyst, GL518_REG_TEMP_HYST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) set_bits(BOOL, fan_auto1, fan_auto1, GL518_REG_MISC, 0x08, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) set_low(VDD, in_min0, voltage_min[0], GL518_REG_VDD_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) set_low(IN, in_min1, voltage_min[1], GL518_REG_VIN1_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) set_low(IN, in_min2, voltage_min[2], GL518_REG_VIN2_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) set_low(IN, in_min3, voltage_min[3], GL518_REG_VIN3_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) set_high(VDD, in_max0, voltage_max[0], GL518_REG_VDD_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) set_high(IN, in_max1, voltage_max[1], GL518_REG_VIN1_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) set_high(IN, in_max2, voltage_max[2], GL518_REG_VIN2_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) set_high(IN, in_max3, voltage_max[3], GL518_REG_VIN3_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) set_bits(BOOL, beep_enable, beep_enable, GL518_REG_CONF, 0x04, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) set(BEEP_MASK, beep_mask, beep_mask, GL518_REG_ALARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static ssize_t fan_min_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) struct gl518_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) int regvalue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) regvalue = (regvalue & (0xff << (8 * nr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) | (data->fan_min[nr] << (8 * (1 - nr)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) gl518_write_value(client, GL518_REG_FAN_LIMIT, regvalue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) data->beep_mask = gl518_read_value(client, GL518_REG_ALARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (data->fan_min[nr] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) data->alarm_mask &= ~(0x20 << nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) data->alarm_mask |= (0x20 << nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) data->beep_mask &= data->alarm_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) gl518_write_value(client, GL518_REG_ALARM, data->beep_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static ssize_t fan_div_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct gl518_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) int regvalue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) switch (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) val = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) val = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) val = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) "Invalid fan clock divider %lu, choose one of 1, 2, 4 or 8\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) regvalue = gl518_read_value(client, GL518_REG_MISC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) data->fan_div[nr] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) regvalue = (regvalue & ~(0xc0 >> (2 * nr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) | (data->fan_div[nr] << (6 - 2 * nr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) gl518_write_value(client, GL518_REG_MISC, regvalue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static DEVICE_ATTR(temp1_input, 0444, show_temp_input1, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) static DEVICE_ATTR(temp1_max, 0644, show_temp_max1, set_temp_max1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) static DEVICE_ATTR(temp1_max_hyst, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) show_temp_hyst1, set_temp_hyst1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) static DEVICE_ATTR(fan1_auto, 0644, show_fan_auto1, set_fan_auto1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static SENSOR_DEVICE_ATTR_RO(fan1_input, fan_input, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) static SENSOR_DEVICE_ATTR_RO(fan2_input, fan_input, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static DEVICE_ATTR(in0_input, 0444, show_in_input0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static DEVICE_ATTR(in1_input, 0444, show_in_input1, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) static DEVICE_ATTR(in2_input, 0444, show_in_input2, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static DEVICE_ATTR(in3_input, 0444, show_in_input3, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) static DEVICE_ATTR(in0_min, 0644, show_in_min0, set_in_min0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static DEVICE_ATTR(in1_min, 0644, show_in_min1, set_in_min1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) static DEVICE_ATTR(in2_min, 0644, show_in_min2, set_in_min2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static DEVICE_ATTR(in3_min, 0644, show_in_min3, set_in_min3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static DEVICE_ATTR(in0_max, 0644, show_in_max0, set_in_max0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) static DEVICE_ATTR(in1_max, 0644, show_in_max1, set_in_max1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) static DEVICE_ATTR(in2_max, 0644, show_in_max2, set_in_max2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static DEVICE_ATTR(in3_max, 0644, show_in_max3, set_in_max3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) static DEVICE_ATTR(alarms, 0444, show_alarms, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) static DEVICE_ATTR(beep_enable, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) show_beep_enable, set_beep_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) static DEVICE_ATTR(beep_mask, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) show_beep_mask, set_beep_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) int bitnr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) struct gl518_data *data = gl518_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static ssize_t beep_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) int bitnr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) struct gl518_data *data = gl518_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) static ssize_t beep_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) struct gl518_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) int bitnr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) unsigned long bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) err = kstrtoul(buf, 10, &bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) if (bit & ~1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) data->beep_mask = gl518_read_value(client, GL518_REG_ALARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) if (bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) data->beep_mask |= (1 << bitnr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) data->beep_mask &= ~(1 << bitnr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) gl518_write_value(client, GL518_REG_ALARM, data->beep_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static SENSOR_DEVICE_ATTR_RW(in0_beep, beep, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) static SENSOR_DEVICE_ATTR_RW(in1_beep, beep, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) static SENSOR_DEVICE_ATTR_RW(in2_beep, beep, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) static SENSOR_DEVICE_ATTR_RW(in3_beep, beep, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) static SENSOR_DEVICE_ATTR_RW(temp1_beep, beep, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static SENSOR_DEVICE_ATTR_RW(fan1_beep, beep, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) static SENSOR_DEVICE_ATTR_RW(fan2_beep, beep, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) static struct attribute *gl518_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) &dev_attr_in3_input.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) &dev_attr_in0_min.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) &dev_attr_in1_min.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) &dev_attr_in2_min.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) &dev_attr_in3_min.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) &dev_attr_in0_max.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) &dev_attr_in1_max.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) &dev_attr_in2_max.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) &dev_attr_in3_max.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) &sensor_dev_attr_in0_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) &sensor_dev_attr_in1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) &sensor_dev_attr_in2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) &sensor_dev_attr_in3_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) &sensor_dev_attr_in0_beep.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) &sensor_dev_attr_in1_beep.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) &sensor_dev_attr_in2_beep.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) &sensor_dev_attr_in3_beep.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) &dev_attr_fan1_auto.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) &sensor_dev_attr_fan1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) &sensor_dev_attr_fan2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) &sensor_dev_attr_fan1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) &sensor_dev_attr_fan2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) &sensor_dev_attr_fan1_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) &sensor_dev_attr_fan2_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) &sensor_dev_attr_fan1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) &sensor_dev_attr_fan2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) &sensor_dev_attr_fan1_beep.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) &sensor_dev_attr_fan2_beep.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) &dev_attr_temp1_input.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) &dev_attr_temp1_max.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) &dev_attr_temp1_max_hyst.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) &sensor_dev_attr_temp1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) &sensor_dev_attr_temp1_beep.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) &dev_attr_alarms.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) &dev_attr_beep_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) &dev_attr_beep_mask.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) static const struct attribute_group gl518_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) .attrs = gl518_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) static struct attribute *gl518_attributes_r80[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) &dev_attr_in0_input.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) &dev_attr_in1_input.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) &dev_attr_in2_input.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) static const struct attribute_group gl518_group_r80 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) .attrs = gl518_attributes_r80,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) * Real code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) /* Return 0 if detection is successful, -ENODEV otherwise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) static int gl518_detect(struct i2c_client *client, struct i2c_board_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) struct i2c_adapter *adapter = client->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) int rev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) I2C_FUNC_SMBUS_WORD_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) /* Now, we do the remaining detection. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if ((gl518_read_value(client, GL518_REG_CHIP_ID) != 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) || (gl518_read_value(client, GL518_REG_CONF) & 0x80))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) /* Determine the chip type. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) rev = gl518_read_value(client, GL518_REG_REVISION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) if (rev != 0x00 && rev != 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) strlcpy(info->type, "gl518sm", I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) * Called when we have found a new GL518SM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) * Note that we preserve D4:NoFan2 and D2:beep_enable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) static void gl518_init_client(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) /* Make sure we leave D7:Reset untouched */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) u8 regvalue = gl518_read_value(client, GL518_REG_CONF) & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) /* Comparator mode (D3=0), standby mode (D6=0) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) gl518_write_value(client, GL518_REG_CONF, (regvalue &= 0x37));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) /* Never interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) gl518_write_value(client, GL518_REG_MASK, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) /* Clear status register (D5=1), start (D6=1) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) gl518_write_value(client, GL518_REG_CONF, 0x20 | regvalue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) gl518_write_value(client, GL518_REG_CONF, 0x40 | regvalue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) static int gl518_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) struct gl518_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) int revision;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) data = devm_kzalloc(dev, sizeof(struct gl518_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) data->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) revision = gl518_read_value(client, GL518_REG_REVISION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) data->type = revision == 0x80 ? gl518sm_r80 : gl518sm_r00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) mutex_init(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) /* Initialize the GL518SM chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) data->alarm_mask = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) gl518_init_client(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) /* sysfs hooks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) data->groups[0] = &gl518_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) if (data->type == gl518sm_r80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) data->groups[1] = &gl518_group_r80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) data, data->groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) return PTR_ERR_OR_ZERO(hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) static const struct i2c_device_id gl518_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) { "gl518sm", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) MODULE_DEVICE_TABLE(i2c, gl518_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) static struct i2c_driver gl518_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) .class = I2C_CLASS_HWMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) .name = "gl518sm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) .probe_new = gl518_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) .id_table = gl518_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) .detect = gl518_detect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) .address_list = normal_i2c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) module_i2c_driver(gl518_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) "Kyosti Malkki <kmalkki@cc.hut.fi> and "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) "Hong-Gunn Chew <hglinux@gunnet.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) MODULE_DESCRIPTION("GL518SM driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) MODULE_LICENSE("GPL");