^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) * gl520sm.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>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Kyösti Mälkki <kmalkki@cc.hut.fi>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (c) 2005 Maarten Deprez <maartendeprez@users.sourceforge.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/hwmon-sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/hwmon-vid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /* Type of the extra sensor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static unsigned short extra_sensor_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) module_param(extra_sensor_type, ushort, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) MODULE_PARM_DESC(extra_sensor_type, "Type of extra sensor (0=autodetect, 1=temperature, 2=voltage)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /* Addresses to scan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static const unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * Many GL520 constants specified below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * One of the inputs can be configured as either temp or voltage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * That's why _TEMP2 and _IN4 access the same register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /* The GL520 registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define GL520_REG_CHIP_ID 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define GL520_REG_REVISION 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define GL520_REG_CONF 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define GL520_REG_MASK 0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define GL520_REG_VID_INPUT 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static const u8 GL520_REG_IN_INPUT[] = { 0x15, 0x14, 0x13, 0x0d, 0x0e };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static const u8 GL520_REG_IN_LIMIT[] = { 0x0c, 0x09, 0x0a, 0x0b };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static const u8 GL520_REG_IN_MIN[] = { 0x0c, 0x09, 0x0a, 0x0b, 0x18 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static const u8 GL520_REG_IN_MAX[] = { 0x0c, 0x09, 0x0a, 0x0b, 0x17 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static const u8 GL520_REG_TEMP_INPUT[] = { 0x04, 0x0e };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static const u8 GL520_REG_TEMP_MAX[] = { 0x05, 0x17 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static const u8 GL520_REG_TEMP_MAX_HYST[] = { 0x06, 0x18 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define GL520_REG_FAN_INPUT 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define GL520_REG_FAN_MIN 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define GL520_REG_FAN_DIV 0x0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define GL520_REG_FAN_OFF GL520_REG_FAN_DIV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define GL520_REG_ALARMS 0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define GL520_REG_BEEP_MASK 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define GL520_REG_BEEP_ENABLE GL520_REG_CONF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* Client data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct gl520_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) const struct attribute_group *groups[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct mutex update_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) char valid; /* zero until the following fields are valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) unsigned long last_updated; /* in jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) u8 vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) u8 vrm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) u8 in_input[5]; /* [0] = VVD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) u8 in_min[5]; /* [0] = VDD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) u8 in_max[5]; /* [0] = VDD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) u8 fan_input[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) u8 fan_min[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) u8 fan_div[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) u8 fan_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) u8 temp_input[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) u8 temp_max[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) u8 temp_max_hyst[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) u8 alarms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) u8 beep_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) u8 beep_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) u8 alarm_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) u8 two_temps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * Registers 0x07 to 0x0c are word-sized, others are byte-sized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * GL520 uses a high-byte first convention
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static int gl520_read_value(struct i2c_client *client, u8 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if ((reg >= 0x07) && (reg <= 0x0c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return i2c_smbus_read_word_swapped(client, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return i2c_smbus_read_byte_data(client, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if ((reg >= 0x07) && (reg <= 0x0c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return i2c_smbus_write_word_swapped(client, reg, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return i2c_smbus_write_byte_data(client, reg, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static struct gl520_data *gl520_update_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct gl520_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) int val, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) dev_dbg(&client->dev, "Starting gl520sm update\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) data->alarms = gl520_read_value(client, GL520_REG_ALARMS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) data->vid = gl520_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) GL520_REG_VID_INPUT) & 0x1f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) data->in_input[i] = gl520_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) GL520_REG_IN_INPUT[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) val = gl520_read_value(client, GL520_REG_IN_LIMIT[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) data->in_min[i] = val & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) data->in_max[i] = (val >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) val = gl520_read_value(client, GL520_REG_FAN_INPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) data->fan_input[0] = (val >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) data->fan_input[1] = val & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) val = gl520_read_value(client, GL520_REG_FAN_MIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) data->fan_min[0] = (val >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) data->fan_min[1] = val & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) data->temp_input[0] = gl520_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) GL520_REG_TEMP_INPUT[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) data->temp_max[0] = gl520_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) GL520_REG_TEMP_MAX[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) data->temp_max_hyst[0] = gl520_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) GL520_REG_TEMP_MAX_HYST[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) val = gl520_read_value(client, GL520_REG_FAN_DIV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) data->fan_div[0] = (val >> 6) & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) data->fan_div[1] = (val >> 4) & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) data->fan_off = (val >> 2) & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) data->alarms &= data->alarm_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) val = gl520_read_value(client, GL520_REG_CONF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) data->beep_enable = !((val >> 2) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /* Temp1 and Vin4 are the same input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (data->two_temps) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) data->temp_input[1] = gl520_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) GL520_REG_TEMP_INPUT[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) data->temp_max[1] = gl520_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) GL520_REG_TEMP_MAX[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) data->temp_max_hyst[1] = gl520_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) GL520_REG_TEMP_MAX_HYST[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) data->in_input[4] = gl520_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) GL520_REG_IN_INPUT[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) data->in_min[4] = gl520_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) GL520_REG_IN_MIN[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) data->in_max[4] = gl520_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) GL520_REG_IN_MAX[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) data->last_updated = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) data->valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * Sysfs stuff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static ssize_t cpu0_vid_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct gl520_data *data = gl520_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static DEVICE_ATTR_RO(cpu0_vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #define VDD_FROM_REG(val) DIV_ROUND_CLOSEST((val) * 95, 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #define VDD_CLAMP(val) clamp_val(val, 0, 255 * 95 / 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #define VDD_TO_REG(val) DIV_ROUND_CLOSEST(VDD_CLAMP(val) * 4, 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #define IN_FROM_REG(val) ((val) * 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #define IN_CLAMP(val) clamp_val(val, 0, 255 * 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #define IN_TO_REG(val) DIV_ROUND_CLOSEST(IN_CLAMP(val), 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static ssize_t in_input_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) int n = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct gl520_data *data = gl520_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) u8 r = data->in_input[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (n == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return sprintf(buf, "%d\n", VDD_FROM_REG(r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return sprintf(buf, "%d\n", IN_FROM_REG(r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static ssize_t in_min_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) int n = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct gl520_data *data = gl520_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) u8 r = data->in_min[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (n == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return sprintf(buf, "%d\n", VDD_FROM_REG(r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return sprintf(buf, "%d\n", IN_FROM_REG(r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static ssize_t in_max_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) int n = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct gl520_data *data = gl520_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) u8 r = data->in_max[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (n == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return sprintf(buf, "%d\n", VDD_FROM_REG(r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return sprintf(buf, "%d\n", IN_FROM_REG(r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static ssize_t in_min_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct gl520_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) int n = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) u8 r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) long v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) err = kstrtol(buf, 10, &v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (n == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) r = VDD_TO_REG(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) r = IN_TO_REG(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) data->in_min[n] = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (n < 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) gl520_write_value(client, GL520_REG_IN_MIN[n],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) (gl520_read_value(client, GL520_REG_IN_MIN[n])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) & ~0xff) | r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) gl520_write_value(client, GL520_REG_IN_MIN[n], r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static ssize_t in_max_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct gl520_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) int n = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) u8 r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) long v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) err = kstrtol(buf, 10, &v);
^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) if (n == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) r = VDD_TO_REG(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) r = IN_TO_REG(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) data->in_max[n] = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (n < 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) gl520_write_value(client, GL520_REG_IN_MAX[n],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) (gl520_read_value(client, GL520_REG_IN_MAX[n])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) & ~0xff00) | (r << 8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) gl520_write_value(client, GL520_REG_IN_MAX[n], r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static SENSOR_DEVICE_ATTR_RO(in0_input, in_input, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static SENSOR_DEVICE_ATTR_RO(in1_input, in_input, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static SENSOR_DEVICE_ATTR_RO(in2_input, in_input, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static SENSOR_DEVICE_ATTR_RO(in3_input, in_input, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static SENSOR_DEVICE_ATTR_RO(in4_input, in_input, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) #define DIV_FROM_REG(val) (1 << (val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (480000 / ((val) << (div))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) #define FAN_BASE(div) (480000 >> (div))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) #define FAN_CLAMP(val, div) clamp_val(val, FAN_BASE(div) / 255, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) FAN_BASE(div))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) #define FAN_TO_REG(val, div) ((val) == 0 ? 0 : \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) DIV_ROUND_CLOSEST(480000, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) FAN_CLAMP(val, div) << (div)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static ssize_t fan_input_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) int n = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) struct gl520_data *data = gl520_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_input[n],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) data->fan_div[n]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) int n = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) struct gl520_data *data = gl520_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[n],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) data->fan_div[n]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) static ssize_t fan_div_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) int n = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) struct gl520_data *data = gl520_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[n]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static ssize_t fan1_off_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) struct gl520_data *data = gl520_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) return sprintf(buf, "%d\n", data->fan_off);
^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_min_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 gl520_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 n = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) u8 r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) unsigned long v;
^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, &v);
^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) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) r = FAN_TO_REG(v, data->fan_div[n]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) data->fan_min[n] = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (n == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) gl520_write_value(client, GL520_REG_FAN_MIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) (gl520_read_value(client, GL520_REG_FAN_MIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) & ~0xff00) | (r << 8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) gl520_write_value(client, GL520_REG_FAN_MIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) (gl520_read_value(client, GL520_REG_FAN_MIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) & ~0xff) | r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (data->fan_min[n] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) data->alarm_mask &= (n == 0) ? ~0x20 : ~0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) data->alarm_mask |= (n == 0) ? 0x20 : 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) data->beep_mask &= data->alarm_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static ssize_t fan_div_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) struct gl520_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) int n = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) u8 r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) unsigned long v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) err = kstrtoul(buf, 10, &v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) switch (v) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) r = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) r = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) r = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) "fan_div value %ld not supported. Choose one of 1, 2, 4 or 8!\n", v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) data->fan_div[n] = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (n == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) gl520_write_value(client, GL520_REG_FAN_DIV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) (gl520_read_value(client, GL520_REG_FAN_DIV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) & ~0xc0) | (r << 6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) gl520_write_value(client, GL520_REG_FAN_DIV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) (gl520_read_value(client, GL520_REG_FAN_DIV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) & ~0x30) | (r << 4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static ssize_t fan1_off_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) struct gl520_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) u8 r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) unsigned long v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) err = kstrtoul(buf, 10, &v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) r = (v ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) data->fan_off = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) gl520_write_value(client, GL520_REG_FAN_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) (gl520_read_value(client, GL520_REG_FAN_OFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) & ~0x0c) | (r << 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) static SENSOR_DEVICE_ATTR_RO(fan1_input, fan_input, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) static SENSOR_DEVICE_ATTR_RO(fan2_input, fan_input, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) static DEVICE_ATTR_RW(fan1_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) #define TEMP_FROM_REG(val) (((val) - 130) * 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) #define TEMP_CLAMP(val) clamp_val(val, -130000, 125000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) #define TEMP_TO_REG(val) (DIV_ROUND_CLOSEST(TEMP_CLAMP(val), 1000) + 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) static ssize_t temp_input_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) int n = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) struct gl520_data *data = gl520_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_input[n]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static ssize_t temp_max_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) int n = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) struct gl520_data *data = gl520_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[n]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) static ssize_t temp_max_hyst_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) int n = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) struct gl520_data *data = gl520_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max_hyst[n]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) static ssize_t temp_max_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) struct gl520_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) int n = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) long v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) err = kstrtol(buf, 10, &v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) data->temp_max[n] = TEMP_TO_REG(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) gl520_write_value(client, GL520_REG_TEMP_MAX[n], data->temp_max[n]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) static ssize_t temp_max_hyst_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) struct gl520_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) int n = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) long v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) err = kstrtol(buf, 10, &v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) data->temp_max_hyst[n] = TEMP_TO_REG(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) gl520_write_value(client, GL520_REG_TEMP_MAX_HYST[n],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) data->temp_max_hyst[n]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) static SENSOR_DEVICE_ATTR_RO(temp1_input, temp_input, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) static SENSOR_DEVICE_ATTR_RO(temp2_input, temp_input, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) static SENSOR_DEVICE_ATTR_RW(temp1_max_hyst, temp_max_hyst, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) static SENSOR_DEVICE_ATTR_RW(temp2_max_hyst, temp_max_hyst, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) struct gl520_data *data = gl520_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) return sprintf(buf, "%d\n", data->alarms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) static ssize_t beep_enable_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) struct gl520_data *data = gl520_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) return sprintf(buf, "%d\n", data->beep_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) static ssize_t beep_mask_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) struct gl520_data *data = gl520_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) return sprintf(buf, "%d\n", data->beep_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) static ssize_t beep_enable_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) struct gl520_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) u8 r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) unsigned long v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) err = kstrtoul(buf, 10, &v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) r = (v ? 0 : 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) data->beep_enable = !r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) gl520_write_value(client, GL520_REG_BEEP_ENABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) (gl520_read_value(client, GL520_REG_BEEP_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) & ~0x04) | (r << 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) static ssize_t beep_mask_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) struct gl520_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) unsigned long r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) err = kstrtoul(buf, 10, &r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) r &= data->alarm_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) data->beep_mask = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) gl520_write_value(client, GL520_REG_BEEP_MASK, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) static DEVICE_ATTR_RO(alarms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) static DEVICE_ATTR_RW(beep_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) static DEVICE_ATTR_RW(beep_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) int bit_nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) struct gl520_data *data = gl520_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) return sprintf(buf, "%d\n", (data->alarms >> bit_nr) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) static ssize_t beep_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) int bitnr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) struct gl520_data *data = gl520_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) return sprintf(buf, "%d\n", (data->beep_mask >> bitnr) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) static ssize_t beep_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) struct gl520_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) int bitnr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) unsigned long bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) err = kstrtoul(buf, 10, &bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) if (bit & ~1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) if (bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) data->beep_mask |= (1 << bitnr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) data->beep_mask &= ~(1 << bitnr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) static SENSOR_DEVICE_ATTR_RW(in0_beep, beep, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) static SENSOR_DEVICE_ATTR_RW(in1_beep, beep, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) static SENSOR_DEVICE_ATTR_RW(in2_beep, beep, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) static SENSOR_DEVICE_ATTR_RW(in3_beep, beep, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) static SENSOR_DEVICE_ATTR_RW(temp1_beep, beep, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) static SENSOR_DEVICE_ATTR_RW(fan1_beep, beep, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) static SENSOR_DEVICE_ATTR_RW(fan2_beep, beep, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) static SENSOR_DEVICE_ATTR_RW(temp2_beep, beep, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) static SENSOR_DEVICE_ATTR_RW(in4_beep, beep, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) static struct attribute *gl520_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) &dev_attr_cpu0_vid.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) &sensor_dev_attr_in0_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) &sensor_dev_attr_in0_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) &sensor_dev_attr_in0_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) &sensor_dev_attr_in0_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) &sensor_dev_attr_in0_beep.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) &sensor_dev_attr_in1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) &sensor_dev_attr_in1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) &sensor_dev_attr_in1_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) &sensor_dev_attr_in1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) &sensor_dev_attr_in1_beep.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) &sensor_dev_attr_in2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) &sensor_dev_attr_in2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) &sensor_dev_attr_in2_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) &sensor_dev_attr_in2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) &sensor_dev_attr_in2_beep.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) &sensor_dev_attr_in3_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) &sensor_dev_attr_in3_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) &sensor_dev_attr_in3_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) &sensor_dev_attr_in3_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) &sensor_dev_attr_in3_beep.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) &sensor_dev_attr_fan1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) &sensor_dev_attr_fan1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) &sensor_dev_attr_fan1_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) &sensor_dev_attr_fan1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) &sensor_dev_attr_fan1_beep.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) &dev_attr_fan1_off.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) &sensor_dev_attr_fan2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) &sensor_dev_attr_fan2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) &sensor_dev_attr_fan2_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) &sensor_dev_attr_fan2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) &sensor_dev_attr_fan2_beep.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) &sensor_dev_attr_temp1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) &sensor_dev_attr_temp1_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) &sensor_dev_attr_temp1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) &sensor_dev_attr_temp1_beep.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) &dev_attr_alarms.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) &dev_attr_beep_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) &dev_attr_beep_mask.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) static const struct attribute_group gl520_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) .attrs = gl520_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) static struct attribute *gl520_attributes_in4[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) &sensor_dev_attr_in4_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) &sensor_dev_attr_in4_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) &sensor_dev_attr_in4_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) &sensor_dev_attr_in4_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) &sensor_dev_attr_in4_beep.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) static struct attribute *gl520_attributes_temp2[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) &sensor_dev_attr_temp2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) &sensor_dev_attr_temp2_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) &sensor_dev_attr_temp2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) &sensor_dev_attr_temp2_beep.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) static const struct attribute_group gl520_group_in4 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) .attrs = gl520_attributes_in4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) static const struct attribute_group gl520_group_temp2 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) .attrs = gl520_attributes_temp2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) * Real code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) /* Return 0 if detection is successful, -ENODEV otherwise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) static int gl520_detect(struct i2c_client *client, struct i2c_board_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) struct i2c_adapter *adapter = client->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) I2C_FUNC_SMBUS_WORD_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) /* Determine the chip type. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) if ((gl520_read_value(client, GL520_REG_CHIP_ID) != 0x20) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) ((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) ((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) dev_dbg(&client->dev, "Unknown chip type, skipping\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) strlcpy(info->type, "gl520sm", I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) /* Called when we have found a new GL520SM. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) static void gl520_init_client(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) struct gl520_data *data = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) u8 oldconf, conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) conf = oldconf = gl520_read_value(client, GL520_REG_CONF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) data->alarm_mask = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) data->vrm = vid_which_vrm();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (extra_sensor_type == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) conf &= ~0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) else if (extra_sensor_type == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) conf |= 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) data->two_temps = !(conf & 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) /* If IRQ# is disabled, we can safely force comparator mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (!(conf & 0x20))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) conf &= 0xf7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) /* Enable monitoring if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) conf |= 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) if (conf != oldconf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) gl520_write_value(client, GL520_REG_CONF, conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) gl520_update_device(&(client->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) if (data->fan_min[0] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) data->alarm_mask &= ~0x20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) if (data->fan_min[1] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) data->alarm_mask &= ~0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) data->beep_mask &= data->alarm_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) static int gl520_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) struct gl520_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) data = devm_kzalloc(dev, sizeof(struct gl520_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) i2c_set_clientdata(client, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) mutex_init(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) data->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) /* Initialize the GL520SM chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) gl520_init_client(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) /* sysfs hooks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) data->groups[0] = &gl520_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) if (data->two_temps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) data->groups[1] = &gl520_group_temp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) data->groups[1] = &gl520_group_in4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) data, data->groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) return PTR_ERR_OR_ZERO(hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) static const struct i2c_device_id gl520_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) { "gl520sm", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) MODULE_DEVICE_TABLE(i2c, gl520_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) static struct i2c_driver gl520_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) .class = I2C_CLASS_HWMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) .name = "gl520sm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) .probe_new = gl520_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) .id_table = gl520_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) .detect = gl520_detect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) .address_list = normal_i2c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) module_i2c_driver(gl520_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) "Kyösti Mälkki <kmalkki@cc.hut.fi>, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) "Maarten Deprez <maartendeprez@users.sourceforge.net>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) MODULE_DESCRIPTION("GL520SM driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) MODULE_LICENSE("GPL");