^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) * adm1026.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) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Chip details at:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * <https://www.onsemi.com/PowerSolutions/product.do?id=ADM1026>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/hwmon-sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/hwmon-vid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /* Addresses to scan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) -1, -1, -1, -1, -1, -1, -1, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) -1, -1, -1, -1, -1, -1, -1, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) -1, -1, -1, -1, -1, -1, -1, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) -1, -1, -1, -1, -1, -1, -1, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) module_param_array(gpio_input, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) MODULE_PARM_DESC(gpio_input, "List of GPIO pins (0-16) to program as inputs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) module_param_array(gpio_output, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) MODULE_PARM_DESC(gpio_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) "List of GPIO pins (0-16) to program as outputs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) module_param_array(gpio_inverted, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) MODULE_PARM_DESC(gpio_inverted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) "List of GPIO pins (0-16) to program as inverted");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) module_param_array(gpio_normal, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) MODULE_PARM_DESC(gpio_normal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) "List of GPIO pins (0-16) to program as normal/non-inverted");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) module_param_array(gpio_fan, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) MODULE_PARM_DESC(gpio_fan, "List of GPIO pins (0-7) to program as fan tachs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* Many ADM1026 constants specified below */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* The ADM1026 registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define ADM1026_REG_CONFIG1 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define CFG1_MONITOR 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define CFG1_INT_ENABLE 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define CFG1_INT_CLEAR 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define CFG1_AIN8_9 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define CFG1_THERM_HOT 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define CFG1_DAC_AFC 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define CFG1_PWM_AFC 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define CFG1_RESET 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define ADM1026_REG_CONFIG2 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define ADM1026_REG_CONFIG3 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define CFG3_GPIO16_ENABLE 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define CFG3_CI_CLEAR 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define CFG3_VREF_250 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define CFG3_GPIO16_DIR 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define CFG3_GPIO16_POL 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define ADM1026_REG_E2CONFIG 0x13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define E2CFG_READ 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define E2CFG_WRITE 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define E2CFG_ERASE 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define E2CFG_ROM 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define E2CFG_CLK_EXT 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * There are 10 general analog inputs and 7 dedicated inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * They are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * 0 - 9 = AIN0 - AIN9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * 10 = Vbat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * 11 = 3.3V Standby
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * 12 = 3.3V Main
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * 13 = +5V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * 14 = Vccp (CPU core voltage)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * 15 = +12V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * 16 = -12V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static u16 ADM1026_REG_IN[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) 0x36, 0x37, 0x27, 0x29, 0x26, 0x2a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static u16 ADM1026_REG_IN_MIN[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) 0x5e, 0x5f, 0x6d, 0x49, 0x6b, 0x4a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static u16 ADM1026_REG_IN_MAX[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 0x56, 0x57, 0x6c, 0x41, 0x6a, 0x42,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 0x43, 0x44, 0x45, 0x46, 0x47
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) };
^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) * Temperatures are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * 0 - Internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * 1 - External 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * 2 - External 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static u16 ADM1026_REG_TEMP[] = { 0x1f, 0x28, 0x29 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static u16 ADM1026_REG_TEMP_MIN[] = { 0x69, 0x48, 0x49 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static u16 ADM1026_REG_TEMP_MAX[] = { 0x68, 0x40, 0x41 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static u16 ADM1026_REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define ADM1026_REG_FAN(nr) (0x38 + (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define ADM1026_REG_FAN_DIV_0_3 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #define ADM1026_REG_FAN_DIV_4_7 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #define ADM1026_REG_DAC 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #define ADM1026_REG_PWM 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #define ADM1026_REG_GPIO_CFG_0_3 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #define ADM1026_REG_GPIO_CFG_4_7 0x09
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #define ADM1026_REG_GPIO_CFG_8_11 0x0a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #define ADM1026_REG_GPIO_CFG_12_15 0x0b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /* CFG_16 in REG_CFG3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #define ADM1026_REG_GPIO_STATUS_0_7 0x24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define ADM1026_REG_GPIO_STATUS_8_15 0x25
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /* STATUS_16 in REG_STATUS4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #define ADM1026_REG_GPIO_MASK_0_7 0x1c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #define ADM1026_REG_GPIO_MASK_8_15 0x1d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /* MASK_16 in REG_MASK4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #define ADM1026_REG_COMPANY 0x16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #define ADM1026_REG_VERSTEP 0x17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /* These are the recognized values for the above regs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #define ADM1026_COMPANY_ANALOG_DEV 0x41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) #define ADM1026_VERSTEP_GENERIC 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) #define ADM1026_VERSTEP_ADM1026 0x44
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #define ADM1026_REG_MASK1 0x18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #define ADM1026_REG_MASK2 0x19
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #define ADM1026_REG_MASK3 0x1a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) #define ADM1026_REG_MASK4 0x1b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) #define ADM1026_REG_STATUS1 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #define ADM1026_REG_STATUS2 0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #define ADM1026_REG_STATUS3 0x22
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #define ADM1026_REG_STATUS4 0x23
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) #define ADM1026_FAN_CONTROL_TEMP_RANGE 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #define ADM1026_PWM_MAX 255
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * Conversions. Rounding and limit checking is only done on the TO_REG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * variants. Note that you should be a bit careful with which arguments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * these macros are called: arguments may be evaluated more than once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * IN are scaled according to built-in resistors. These are the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * voltages corresponding to 3/4 of full scale (192 or 0xc0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * NOTE: The -12V input needs an additional factor to account
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * for the Vref pullup resistor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * NEG12_OFFSET = SCALE * Vref / V-192 - Vref
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * = 13875 * 2.50 / 1.875 - 2500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * = 16000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * The values in this table are based on Table II, page 15 of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * datasheet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static int adm1026_scaling[] = { /* .001 Volts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 2250, 2250, 2250, 2250, 2250, 2250,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 1875, 1875, 1875, 1875, 3000, 3330,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 3330, 4995, 2250, 12000, 13875
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #define NEG12_OFFSET 16000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #define SCALE(val, from, to) (((val)*(to) + ((from)/2))/(from))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #define INS_TO_REG(n, val) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) SCALE(clamp_val(val, 0, 255 * adm1026_scaling[n] / 192), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) adm1026_scaling[n], 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) #define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * FAN speed is measured using 22.5kHz clock and counts for 2 pulses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * and we assume a 2 pulse-per-rev fan tach signal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #define FAN_TO_REG(val, div) ((val) <= 0 ? 0xff : \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) clamp_val(1350000 / ((val) * (div)), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 1, 254))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 0xff ? 0 : \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 1350000 / ((val) * (div)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #define DIV_FROM_REG(val) (1 << (val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /* Temperature is reported in 1 degC increments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #define TEMP_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) #define TEMP_FROM_REG(val) ((val) * 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) #define OFFSET_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #define OFFSET_FROM_REG(val) ((val) * 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) #define PWM_TO_REG(val) (clamp_val(val, 0, 255))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) #define PWM_FROM_REG(val) (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) #define PWM_MIN_TO_REG(val) ((val) & 0xf0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * Analog output is a voltage, and scaled to millivolts. The datasheet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * indicates that the DAC could be used to drive the fans, but in our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * example board (Arima HDAMA) it isn't connected to the fans at all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) #define DAC_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val(val, 0, 2500) * 255, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 2500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #define DAC_FROM_REG(val) (((val) * 2500) / 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * Chip sampling rates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * Some sensors are not updated more frequently than once per second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * so it doesn't make sense to read them more often than that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * We cache the results and return the saved data if the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * is called again before a second has elapsed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * Also, there is significant configuration data for this chip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * So, we keep the config data up to date in the cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * when it is written and only sample it once every 5 *minutes*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #define ADM1026_DATA_INTERVAL (1 * HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) #define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
^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) * We allow for multiple chips in a single system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * For each registered ADM1026, we need to keep state information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * at client->data. The adm1026_data structure is dynamically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * allocated, when a new client structure is allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct pwm_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) u8 pwm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) u8 enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) u8 auto_pwm_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct adm1026_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) const struct attribute_group *groups[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct mutex update_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) int valid; /* !=0 if following fields are valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) unsigned long last_reading; /* In jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) unsigned long last_config; /* In jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) u8 in[17]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) u8 in_max[17]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) u8 in_min[17]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) s8 temp[3]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) s8 temp_min[3]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) s8 temp_max[3]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) s8 temp_tmin[3]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) s8 temp_crit[3]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) s8 temp_offset[3]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) u8 fan[8]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) u8 fan_min[8]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) u8 fan_div[8]; /* Decoded value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) struct pwm_data pwm1; /* Pwm control values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) u8 vrm; /* VRM version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) u8 analog_out; /* Register value (DAC) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) long alarms; /* Register encoding, combined */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) long alarm_mask; /* Register encoding, combined */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) long gpio; /* Register encoding, combined */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) long gpio_mask; /* Register encoding, combined */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) u8 gpio_config[17]; /* Decoded value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) u8 config1; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) u8 config2; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) u8 config3; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static int adm1026_read_value(struct i2c_client *client, u8 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (reg < 0x80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /* "RAM" locations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) res = i2c_smbus_read_byte_data(client, reg) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /* EEPROM, do nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (reg < 0x80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) /* "RAM" locations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) res = i2c_smbus_write_byte_data(client, reg, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) /* EEPROM, do nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static struct adm1026_data *adm1026_update_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) long value, alarms, gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (!data->valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) || time_after(jiffies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) data->last_reading + ADM1026_DATA_INTERVAL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /* Things that change quickly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) dev_dbg(&client->dev, "Reading sensor values\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) for (i = 0; i <= 16; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) data->in[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) adm1026_read_value(client, ADM1026_REG_IN[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) for (i = 0; i <= 7; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) data->fan[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) adm1026_read_value(client, ADM1026_REG_FAN(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) for (i = 0; i <= 2; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * NOTE: temp[] is s8 and we assume 2's complement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * "conversion" in the assignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) data->temp[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) adm1026_read_value(client, ADM1026_REG_TEMP[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) data->pwm1.pwm = adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) ADM1026_REG_PWM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) data->analog_out = adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) ADM1026_REG_DAC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /* GPIO16 is MSbit of alarms, move it to gpio */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) alarms &= 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) alarms <<= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) alarms <<= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) alarms |= adm1026_read_value(client, ADM1026_REG_STATUS2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) alarms <<= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) alarms |= adm1026_read_value(client, ADM1026_REG_STATUS1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) data->alarms = alarms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) /* Read the GPIO values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) gpio |= adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) ADM1026_REG_GPIO_STATUS_8_15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) gpio <<= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) gpio |= adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) ADM1026_REG_GPIO_STATUS_0_7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) data->gpio = gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) data->last_reading = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) } /* last_reading */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (!data->valid ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) time_after(jiffies, data->last_config + ADM1026_CONFIG_INTERVAL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) /* Things that don't change often */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) dev_dbg(&client->dev, "Reading config values\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) for (i = 0; i <= 16; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) data->in_min[i] = adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) ADM1026_REG_IN_MIN[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) data->in_max[i] = adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) ADM1026_REG_IN_MAX[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) for (i = 0; i <= 7; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) data->fan_min[i] = adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) ADM1026_REG_FAN_MIN(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) data->fan_div[i] = DIV_FROM_REG(value & 0x03);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) value >>= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) for (i = 0; i <= 2; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * NOTE: temp_xxx[] are s8 and we assume 2's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) * complement "conversion" in the assignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) data->temp_min[i] = adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) ADM1026_REG_TEMP_MIN[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) data->temp_max[i] = adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) ADM1026_REG_TEMP_MAX[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) data->temp_tmin[i] = adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) ADM1026_REG_TEMP_TMIN[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) data->temp_crit[i] = adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) ADM1026_REG_TEMP_THERM[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) data->temp_offset[i] = adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) ADM1026_REG_TEMP_OFFSET[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) /* Read the STATUS/alarm masks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) alarms = (alarms & 0x7f) << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) alarms <<= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) alarms <<= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) alarms |= adm1026_read_value(client, ADM1026_REG_MASK1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) data->alarm_mask = alarms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) /* Read the GPIO values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) gpio |= adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) ADM1026_REG_GPIO_MASK_8_15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) gpio <<= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) data->gpio_mask = gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) /* Read various values from CONFIG1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) data->config1 = adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) ADM1026_REG_CONFIG1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (data->config1 & CFG1_PWM_AFC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) data->pwm1.enable = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) data->pwm1.auto_pwm_min =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) PWM_MIN_FROM_REG(data->pwm1.pwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) /* Read the GPIO config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) data->config2 = adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) ADM1026_REG_CONFIG2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) data->config3 = adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) ADM1026_REG_CONFIG3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) data->gpio_config[16] = (data->config3 >> 6) & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) for (i = 0; i <= 15; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if ((i & 0x03) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) value = adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) ADM1026_REG_GPIO_CFG_0_3 + i/4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) data->gpio_config[i] = value & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) value >>= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) data->last_config = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) } /* last_config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) data->valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static ssize_t in_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) static ssize_t in_min_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_min[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static ssize_t in_min_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) data->in_min[nr] = INS_TO_REG(nr, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) static ssize_t in_max_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_max[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) static ssize_t in_max_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) data->in_max[nr] = INS_TO_REG(nr, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) adm1026_write_value(client, ADM1026_REG_IN_MAX[nr], data->in_max[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) static SENSOR_DEVICE_ATTR_RO(in0_input, in, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) static SENSOR_DEVICE_ATTR_RO(in1_input, in, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) static SENSOR_DEVICE_ATTR_RO(in2_input, in, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) static SENSOR_DEVICE_ATTR_RO(in3_input, in, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) static SENSOR_DEVICE_ATTR_RO(in4_input, in, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) static SENSOR_DEVICE_ATTR_RO(in5_input, in, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) static SENSOR_DEVICE_ATTR_RW(in5_min, in_min, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) static SENSOR_DEVICE_ATTR_RW(in5_max, in_max, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) static SENSOR_DEVICE_ATTR_RO(in6_input, in, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) static SENSOR_DEVICE_ATTR_RW(in6_min, in_min, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) static SENSOR_DEVICE_ATTR_RW(in6_max, in_max, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) static SENSOR_DEVICE_ATTR_RO(in7_input, in, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) static SENSOR_DEVICE_ATTR_RW(in7_min, in_min, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) static SENSOR_DEVICE_ATTR_RW(in7_max, in_max, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) static SENSOR_DEVICE_ATTR_RO(in8_input, in, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) static SENSOR_DEVICE_ATTR_RW(in8_min, in_min, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) static SENSOR_DEVICE_ATTR_RW(in8_max, in_max, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) static SENSOR_DEVICE_ATTR_RO(in9_input, in, 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) static SENSOR_DEVICE_ATTR_RW(in9_min, in_min, 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) static SENSOR_DEVICE_ATTR_RW(in9_max, in_max, 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) static SENSOR_DEVICE_ATTR_RO(in10_input, in, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) static SENSOR_DEVICE_ATTR_RW(in10_min, in_min, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) static SENSOR_DEVICE_ATTR_RW(in10_max, in_max, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static SENSOR_DEVICE_ATTR_RO(in11_input, in, 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) static SENSOR_DEVICE_ATTR_RW(in11_min, in_min, 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) static SENSOR_DEVICE_ATTR_RW(in11_max, in_max, 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) static SENSOR_DEVICE_ATTR_RO(in12_input, in, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) static SENSOR_DEVICE_ATTR_RW(in12_min, in_min, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) static SENSOR_DEVICE_ATTR_RW(in12_max, in_max, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) static SENSOR_DEVICE_ATTR_RO(in13_input, in, 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) static SENSOR_DEVICE_ATTR_RW(in13_min, in_min, 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) static SENSOR_DEVICE_ATTR_RW(in13_max, in_max, 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) static SENSOR_DEVICE_ATTR_RO(in14_input, in, 14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) static SENSOR_DEVICE_ATTR_RW(in14_min, in_min, 14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) static SENSOR_DEVICE_ATTR_RW(in14_max, in_max, 14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) static SENSOR_DEVICE_ATTR_RO(in15_input, in, 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) static SENSOR_DEVICE_ATTR_RW(in15_min, in_min, 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) static SENSOR_DEVICE_ATTR_RW(in15_max, in_max, 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) static ssize_t in16_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in[16]) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) NEG12_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) static ssize_t in16_min_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_min[16])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) - NEG12_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) static ssize_t in16_min_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) data->in_min[16] = INS_TO_REG(16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) clamp_val(val, INT_MIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) INT_MAX - NEG12_OFFSET) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) NEG12_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) static ssize_t in16_max_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_max[16])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) - NEG12_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) static ssize_t in16_max_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 adm1026_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) long val;
^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 = kstrtol(buf, 10, &val);
^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) data->in_max[16] = INS_TO_REG(16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) clamp_val(val, INT_MIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) INT_MAX - NEG12_OFFSET) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) NEG12_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) static SENSOR_DEVICE_ATTR_RO(in16_input, in16, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) static SENSOR_DEVICE_ATTR_RW(in16_min, in16_min, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) static SENSOR_DEVICE_ATTR_RW(in16_max, in16_max, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) /* Now add fan read/write functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) static ssize_t fan_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) data->fan_div[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) data->fan_div[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) static ssize_t fan_min_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) data->fan_min[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) static SENSOR_DEVICE_ATTR_RO(fan3_input, fan, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) static SENSOR_DEVICE_ATTR_RW(fan3_min, fan_min, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) static SENSOR_DEVICE_ATTR_RO(fan4_input, fan, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) static SENSOR_DEVICE_ATTR_RW(fan4_min, fan_min, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) static SENSOR_DEVICE_ATTR_RO(fan5_input, fan, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) static SENSOR_DEVICE_ATTR_RW(fan5_min, fan_min, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) static SENSOR_DEVICE_ATTR_RO(fan6_input, fan, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) static SENSOR_DEVICE_ATTR_RW(fan6_min, fan_min, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) static SENSOR_DEVICE_ATTR_RO(fan7_input, fan, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) static SENSOR_DEVICE_ATTR_RW(fan7_min, fan_min, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) static SENSOR_DEVICE_ATTR_RO(fan8_input, fan, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) static SENSOR_DEVICE_ATTR_RW(fan8_min, fan_min, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) /* Adjust fan_min to account for new fan divisor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) static void fixup_fan_min(struct device *dev, int fan, int old_div)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) int new_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) int new_div = data->fan_div[fan];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) /* 0 and 0xff are special. Don't adjust them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) new_min = data->fan_min[fan] * old_div / new_div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) new_min = clamp_val(new_min, 1, 254);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) data->fan_min[fan] = new_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) /* Now add fan_div read/write functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) static ssize_t fan_div_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) return sprintf(buf, "%d\n", data->fan_div[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) static ssize_t fan_div_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) int orig_div, new_div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) new_div = DIV_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) orig_div = data->fan_div[nr];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) data->fan_div[nr] = DIV_FROM_REG(new_div);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) if (nr < 4) { /* 0 <= nr < 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) (DIV_TO_REG(data->fan_div[0]) << 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) (DIV_TO_REG(data->fan_div[1]) << 2) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) (DIV_TO_REG(data->fan_div[2]) << 4) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) (DIV_TO_REG(data->fan_div[3]) << 6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) } else { /* 3 < nr < 8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) (DIV_TO_REG(data->fan_div[4]) << 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) (DIV_TO_REG(data->fan_div[5]) << 2) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) (DIV_TO_REG(data->fan_div[6]) << 4) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) (DIV_TO_REG(data->fan_div[7]) << 6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) if (data->fan_div[nr] != orig_div)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) fixup_fan_min(dev, nr, orig_div);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) static SENSOR_DEVICE_ATTR_RW(fan3_div, fan_div, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) static SENSOR_DEVICE_ATTR_RW(fan4_div, fan_div, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) static SENSOR_DEVICE_ATTR_RW(fan5_div, fan_div, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) static SENSOR_DEVICE_ATTR_RW(fan6_div, fan_div, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) static SENSOR_DEVICE_ATTR_RW(fan7_div, fan_div, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) static SENSOR_DEVICE_ATTR_RW(fan8_div, fan_div, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) /* Temps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) static ssize_t temp_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) static ssize_t temp_min_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) static ssize_t temp_min_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) data->temp_min[nr] = TEMP_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) adm1026_write_value(client, ADM1026_REG_TEMP_MIN[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) data->temp_min[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) static ssize_t temp_max_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) static ssize_t temp_max_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) data->temp_max[nr] = TEMP_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) adm1026_write_value(client, ADM1026_REG_TEMP_MAX[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) data->temp_max[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) static SENSOR_DEVICE_ATTR_RW(temp1_min, temp_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) static SENSOR_DEVICE_ATTR_RW(temp2_min, temp_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) static SENSOR_DEVICE_ATTR_RW(temp3_min, temp_min, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_max, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) static ssize_t temp_offset_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) static ssize_t temp_offset_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) data->temp_offset[nr] = TEMP_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) data->temp_offset[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) static SENSOR_DEVICE_ATTR_RW(temp1_offset, temp_offset, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) static SENSOR_DEVICE_ATTR_RW(temp2_offset, temp_offset, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) static SENSOR_DEVICE_ATTR_RW(temp3_offset, temp_offset, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) static ssize_t temp_auto_point1_temp_hyst_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) return sprintf(buf, "%d\n", TEMP_FROM_REG(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) ADM1026_FAN_ACTIVATION_TEMP_HYST + data->temp_tmin[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) static ssize_t temp_auto_point2_temp_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_tmin[nr] +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) ADM1026_FAN_CONTROL_TEMP_RANGE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) static ssize_t temp_auto_point1_temp_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) static ssize_t temp_auto_point1_temp_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) data->temp_tmin[nr] = TEMP_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) adm1026_write_value(client, ADM1026_REG_TEMP_TMIN[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) data->temp_tmin[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) static SENSOR_DEVICE_ATTR_RW(temp1_auto_point1_temp, temp_auto_point1_temp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) static SENSOR_DEVICE_ATTR_RO(temp1_auto_point1_temp_hyst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) temp_auto_point1_temp_hyst, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) static SENSOR_DEVICE_ATTR_RO(temp1_auto_point2_temp, temp_auto_point2_temp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) static SENSOR_DEVICE_ATTR_RW(temp2_auto_point1_temp, temp_auto_point1_temp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) static SENSOR_DEVICE_ATTR_RO(temp2_auto_point1_temp_hyst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) temp_auto_point1_temp_hyst, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) static SENSOR_DEVICE_ATTR_RO(temp2_auto_point2_temp, temp_auto_point2_temp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) static SENSOR_DEVICE_ATTR_RW(temp3_auto_point1_temp, temp_auto_point1_temp, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) static SENSOR_DEVICE_ATTR_RO(temp3_auto_point1_temp_hyst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) temp_auto_point1_temp_hyst, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) static SENSOR_DEVICE_ATTR_RO(temp3_auto_point2_temp, temp_auto_point2_temp, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) static ssize_t show_temp_crit_enable(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) return sprintf(buf, "%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) static ssize_t set_temp_crit_enable(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) struct device_attribute *attr, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) if (val > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) adm1026_write_value(client, ADM1026_REG_CONFIG1, data->config1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) static DEVICE_ATTR(temp1_crit_enable, 0644, show_temp_crit_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) set_temp_crit_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) static DEVICE_ATTR(temp2_crit_enable, 0644, show_temp_crit_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) set_temp_crit_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) static DEVICE_ATTR(temp3_crit_enable, 0644, show_temp_crit_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) set_temp_crit_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) static ssize_t temp_crit_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) static ssize_t temp_crit_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) int nr = sensor_attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) data->temp_crit[nr] = TEMP_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) adm1026_write_value(client, ADM1026_REG_TEMP_THERM[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) data->temp_crit[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) static SENSOR_DEVICE_ATTR_RW(temp1_crit, temp_crit, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) static SENSOR_DEVICE_ATTR_RW(temp2_crit, temp_crit, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) static SENSOR_DEVICE_ATTR_RW(temp3_crit, temp_crit, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) static ssize_t analog_out_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) return sprintf(buf, "%d\n", DAC_FROM_REG(data->analog_out));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) static ssize_t analog_out_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) data->analog_out = DAC_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) static DEVICE_ATTR_RW(analog_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) static ssize_t cpu0_vid_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) int vid = (data->gpio >> 11) & 0x1f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) dev_dbg(dev, "Setting VID from GPIO11-15.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) return sprintf(buf, "%d\n", vid_from_reg(vid, data->vrm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) static DEVICE_ATTR_RO(cpu0_vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) static ssize_t vrm_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) return sprintf(buf, "%d\n", data->vrm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) static ssize_t vrm_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) if (val > 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) data->vrm = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) static DEVICE_ATTR_RW(vrm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) return sprintf(buf, "%ld\n", data->alarms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) static DEVICE_ATTR_RO(alarms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) int bitnr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) return sprintf(buf, "%ld\n", (data->alarms >> bitnr) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) static SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) static SENSOR_DEVICE_ATTR_RO(in9_alarm, alarm, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) static SENSOR_DEVICE_ATTR_RO(in11_alarm, alarm, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) static SENSOR_DEVICE_ATTR_RO(in12_alarm, alarm, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) static SENSOR_DEVICE_ATTR_RO(in13_alarm, alarm, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) static SENSOR_DEVICE_ATTR_RO(in14_alarm, alarm, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) static SENSOR_DEVICE_ATTR_RO(in15_alarm, alarm, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) static SENSOR_DEVICE_ATTR_RO(in16_alarm, alarm, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) static SENSOR_DEVICE_ATTR_RO(in5_alarm, alarm, 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) static SENSOR_DEVICE_ATTR_RO(in6_alarm, alarm, 14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) static SENSOR_DEVICE_ATTR_RO(in7_alarm, alarm, 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 17);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) static SENSOR_DEVICE_ATTR_RO(fan3_alarm, alarm, 18);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) static SENSOR_DEVICE_ATTR_RO(fan4_alarm, alarm, 19);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) static SENSOR_DEVICE_ATTR_RO(fan5_alarm, alarm, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) static SENSOR_DEVICE_ATTR_RO(fan6_alarm, alarm, 21);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) static SENSOR_DEVICE_ATTR_RO(fan7_alarm, alarm, 22);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) static SENSOR_DEVICE_ATTR_RO(fan8_alarm, alarm, 23);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) static SENSOR_DEVICE_ATTR_RO(in10_alarm, alarm, 25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) static SENSOR_DEVICE_ATTR_RO(in8_alarm, alarm, 26);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) static ssize_t alarm_mask_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) return sprintf(buf, "%ld\n", data->alarm_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) static ssize_t alarm_mask_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) unsigned long mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) data->alarm_mask = val & 0x7fffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) mask = data->alarm_mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) | (data->gpio_mask & 0x10000 ? 0x80000000 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) adm1026_write_value(client, ADM1026_REG_MASK1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) mask & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) mask >>= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) adm1026_write_value(client, ADM1026_REG_MASK2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) mask & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) mask >>= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) adm1026_write_value(client, ADM1026_REG_MASK3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) mask & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) mask >>= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) adm1026_write_value(client, ADM1026_REG_MASK4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) mask & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) static DEVICE_ATTR_RW(alarm_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) static ssize_t gpio_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) return sprintf(buf, "%ld\n", data->gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) static ssize_t gpio_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) long gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) data->gpio = val & 0x1ffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) gpio = data->gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7, gpio & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) gpio >>= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15, gpio & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) adm1026_write_value(client, ADM1026_REG_STATUS4, gpio & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) static DEVICE_ATTR_RW(gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) static ssize_t gpio_mask_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) return sprintf(buf, "%ld\n", data->gpio_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) static ssize_t gpio_mask_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) long mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) data->gpio_mask = val & 0x1ffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) mask = data->gpio_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7, mask & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) mask >>= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15, mask & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) adm1026_write_value(client, ADM1026_REG_MASK1, mask & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) static DEVICE_ATTR_RW(gpio_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) static ssize_t pwm1_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm1.pwm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) static ssize_t pwm1_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) if (data->pwm1.enable == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) data->pwm1.pwm = PWM_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) static ssize_t temp1_auto_point1_pwm_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) return sprintf(buf, "%d\n", data->pwm1.auto_pwm_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) static ssize_t temp1_auto_point1_pwm_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) data->pwm1.auto_pwm_min = clamp_val(val, 0, 255);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) if (data->pwm1.enable == 2) { /* apply immediately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) static ssize_t temp1_auto_point2_pwm_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) return sprintf(buf, "%d\n", ADM1026_PWM_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) static ssize_t pwm1_enable_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) struct adm1026_data *data = adm1026_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) return sprintf(buf, "%d\n", data->pwm1.enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) static ssize_t pwm1_enable_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) struct adm1026_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) int old_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) if (val >= 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) old_enable = data->pwm1.enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) data->pwm1.enable = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) data->config1 = (data->config1 & ~CFG1_PWM_AFC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) | ((val == 2) ? CFG1_PWM_AFC : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) adm1026_write_value(client, ADM1026_REG_CONFIG1, data->config1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) } else if (!((old_enable == 1) && (val == 1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) /* set pwm to safe value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) data->pwm1.pwm = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) /* enable PWM fan control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) static DEVICE_ATTR_RW(pwm1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) static DEVICE_ATTR(pwm2, 0644, pwm1_show, pwm1_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) static DEVICE_ATTR(pwm3, 0644, pwm1_show, pwm1_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) static DEVICE_ATTR_RW(pwm1_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) static DEVICE_ATTR(pwm2_enable, 0644, pwm1_enable_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) pwm1_enable_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) static DEVICE_ATTR(pwm3_enable, 0644, pwm1_enable_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) pwm1_enable_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) static DEVICE_ATTR_RW(temp1_auto_point1_pwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) static DEVICE_ATTR(temp2_auto_point1_pwm, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) temp1_auto_point1_pwm_show, temp1_auto_point1_pwm_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) static DEVICE_ATTR(temp3_auto_point1_pwm, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) temp1_auto_point1_pwm_show, temp1_auto_point1_pwm_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) static DEVICE_ATTR_RO(temp1_auto_point2_pwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) static DEVICE_ATTR(temp2_auto_point2_pwm, 0444, temp1_auto_point2_pwm_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) static DEVICE_ATTR(temp3_auto_point2_pwm, 0444, temp1_auto_point2_pwm_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) static struct attribute *adm1026_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) &sensor_dev_attr_in0_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) &sensor_dev_attr_in0_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) &sensor_dev_attr_in0_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) &sensor_dev_attr_in0_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) &sensor_dev_attr_in1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) &sensor_dev_attr_in1_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) &sensor_dev_attr_in1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) &sensor_dev_attr_in1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) &sensor_dev_attr_in2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) &sensor_dev_attr_in2_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) &sensor_dev_attr_in2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) &sensor_dev_attr_in2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) &sensor_dev_attr_in3_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) &sensor_dev_attr_in3_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) &sensor_dev_attr_in3_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) &sensor_dev_attr_in3_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) &sensor_dev_attr_in4_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) &sensor_dev_attr_in4_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) &sensor_dev_attr_in4_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) &sensor_dev_attr_in4_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) &sensor_dev_attr_in5_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) &sensor_dev_attr_in5_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) &sensor_dev_attr_in5_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) &sensor_dev_attr_in5_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) &sensor_dev_attr_in6_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) &sensor_dev_attr_in6_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) &sensor_dev_attr_in6_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) &sensor_dev_attr_in6_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) &sensor_dev_attr_in7_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) &sensor_dev_attr_in7_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) &sensor_dev_attr_in7_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) &sensor_dev_attr_in7_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) &sensor_dev_attr_in10_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) &sensor_dev_attr_in10_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) &sensor_dev_attr_in10_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) &sensor_dev_attr_in10_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) &sensor_dev_attr_in11_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) &sensor_dev_attr_in11_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) &sensor_dev_attr_in11_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) &sensor_dev_attr_in11_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) &sensor_dev_attr_in12_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) &sensor_dev_attr_in12_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) &sensor_dev_attr_in12_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) &sensor_dev_attr_in12_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) &sensor_dev_attr_in13_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) &sensor_dev_attr_in13_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) &sensor_dev_attr_in13_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) &sensor_dev_attr_in13_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) &sensor_dev_attr_in14_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) &sensor_dev_attr_in14_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) &sensor_dev_attr_in14_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) &sensor_dev_attr_in14_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) &sensor_dev_attr_in15_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) &sensor_dev_attr_in15_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) &sensor_dev_attr_in15_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) &sensor_dev_attr_in15_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) &sensor_dev_attr_in16_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) &sensor_dev_attr_in16_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) &sensor_dev_attr_in16_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) &sensor_dev_attr_in16_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) &sensor_dev_attr_fan1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) &sensor_dev_attr_fan1_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) &sensor_dev_attr_fan1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) &sensor_dev_attr_fan1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) &sensor_dev_attr_fan2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) &sensor_dev_attr_fan2_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) &sensor_dev_attr_fan2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) &sensor_dev_attr_fan2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) &sensor_dev_attr_fan3_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) &sensor_dev_attr_fan3_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) &sensor_dev_attr_fan3_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) &sensor_dev_attr_fan3_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) &sensor_dev_attr_fan4_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) &sensor_dev_attr_fan4_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) &sensor_dev_attr_fan4_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) &sensor_dev_attr_fan4_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) &sensor_dev_attr_fan5_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) &sensor_dev_attr_fan5_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) &sensor_dev_attr_fan5_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) &sensor_dev_attr_fan5_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) &sensor_dev_attr_fan6_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) &sensor_dev_attr_fan6_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) &sensor_dev_attr_fan6_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) &sensor_dev_attr_fan6_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) &sensor_dev_attr_fan7_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) &sensor_dev_attr_fan7_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) &sensor_dev_attr_fan7_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) &sensor_dev_attr_fan7_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) &sensor_dev_attr_fan8_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) &sensor_dev_attr_fan8_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) &sensor_dev_attr_fan8_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) &sensor_dev_attr_fan8_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) &sensor_dev_attr_temp1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) &sensor_dev_attr_temp1_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) &sensor_dev_attr_temp1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) &sensor_dev_attr_temp1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) &sensor_dev_attr_temp2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) &sensor_dev_attr_temp2_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) &sensor_dev_attr_temp2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) &sensor_dev_attr_temp2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) &sensor_dev_attr_temp1_offset.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) &sensor_dev_attr_temp2_offset.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) &sensor_dev_attr_temp1_auto_point1_temp_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) &sensor_dev_attr_temp2_auto_point1_temp_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) &sensor_dev_attr_temp1_crit.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) &sensor_dev_attr_temp2_crit.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) &dev_attr_temp1_crit_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) &dev_attr_temp2_crit_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) &dev_attr_cpu0_vid.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) &dev_attr_vrm.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) &dev_attr_alarms.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) &dev_attr_alarm_mask.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) &dev_attr_gpio.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) &dev_attr_gpio_mask.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) &dev_attr_pwm1.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) &dev_attr_pwm2.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) &dev_attr_pwm3.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) &dev_attr_pwm1_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) &dev_attr_pwm2_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) &dev_attr_pwm3_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) &dev_attr_temp1_auto_point1_pwm.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) &dev_attr_temp2_auto_point1_pwm.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) &dev_attr_temp1_auto_point2_pwm.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) &dev_attr_temp2_auto_point2_pwm.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) &dev_attr_analog_out.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) static const struct attribute_group adm1026_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) .attrs = adm1026_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) static struct attribute *adm1026_attributes_temp3[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) &sensor_dev_attr_temp3_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) &sensor_dev_attr_temp3_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) &sensor_dev_attr_temp3_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) &sensor_dev_attr_temp3_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) &sensor_dev_attr_temp3_offset.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) &sensor_dev_attr_temp3_auto_point1_temp_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) &sensor_dev_attr_temp3_crit.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) &dev_attr_temp3_crit_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) &dev_attr_temp3_auto_point1_pwm.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) &dev_attr_temp3_auto_point2_pwm.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) static const struct attribute_group adm1026_group_temp3 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) .attrs = adm1026_attributes_temp3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) static struct attribute *adm1026_attributes_in8_9[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) &sensor_dev_attr_in8_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) &sensor_dev_attr_in8_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) &sensor_dev_attr_in8_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) &sensor_dev_attr_in8_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) &sensor_dev_attr_in9_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) &sensor_dev_attr_in9_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) &sensor_dev_attr_in9_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) &sensor_dev_attr_in9_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) static const struct attribute_group adm1026_group_in8_9 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) .attrs = adm1026_attributes_in8_9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) /* Return 0 if detection is successful, -ENODEV otherwise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) static int adm1026_detect(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) struct i2c_board_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) struct i2c_adapter *adapter = client->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) int address = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) int company, verstep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) /* We need to be able to do byte I/O */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) /* Now, we do the remaining detection. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) company = adm1026_read_value(client, ADM1026_REG_COMPANY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) verstep = adm1026_read_value(client, ADM1026_REG_VERSTEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) dev_dbg(&adapter->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) "Detecting device at %d,0x%02x with COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) i2c_adapter_id(client->adapter), client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) company, verstep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) /* Determine the chip type. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x...\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) i2c_adapter_id(adapter), address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) if (company == ADM1026_COMPANY_ANALOG_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) && verstep == ADM1026_VERSTEP_ADM1026) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) /* Analog Devices ADM1026 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) } else if (company == ADM1026_COMPANY_ANALOG_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) && (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) dev_err(&adapter->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) "Unrecognized stepping 0x%02x. Defaulting to ADM1026.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) verstep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) } else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) dev_err(&adapter->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) "Found version/stepping 0x%02x. Assuming generic ADM1026.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) verstep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) dev_dbg(&adapter->dev, "Autodetection failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) /* Not an ADM1026... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) strlcpy(info->type, "adm1026", I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) static void adm1026_print_gpio(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) struct adm1026_data *data = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) dev_dbg(&client->dev, "GPIO config is:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) for (i = 0; i <= 7; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) if (data->config2 & (1 << i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) dev_dbg(&client->dev, "\t%sGP%s%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) data->gpio_config[i] & 0x02 ? "" : "!",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) data->gpio_config[i] & 0x01 ? "OUT" : "IN",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) dev_dbg(&client->dev, "\tFAN%d\n", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) for (i = 8; i <= 15; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) dev_dbg(&client->dev, "\t%sGP%s%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) data->gpio_config[i] & 0x02 ? "" : "!",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) data->gpio_config[i] & 0x01 ? "OUT" : "IN",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) if (data->config3 & CFG3_GPIO16_ENABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) dev_dbg(&client->dev, "\t%sGP%s16\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) data->gpio_config[16] & 0x02 ? "" : "!",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) data->gpio_config[16] & 0x01 ? "OUT" : "IN");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) /* GPIO16 is THERM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) dev_dbg(&client->dev, "\tTHERM\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) static void adm1026_fixup_gpio(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) struct adm1026_data *data = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) /* Make the changes requested. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) * We may need to unlock/stop monitoring or soft-reset the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) * chip before we can make changes. This hasn't been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) * tested much. FIXME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) /* Make outputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) for (i = 0; i <= 16; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) if (gpio_output[i] >= 0 && gpio_output[i] <= 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) data->gpio_config[gpio_output[i]] |= 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) /* if GPIO0-7 is output, it isn't a FAN tach */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) if (gpio_output[i] >= 0 && gpio_output[i] <= 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) data->config2 |= 1 << gpio_output[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) /* Input overrides output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) for (i = 0; i <= 16; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) if (gpio_input[i] >= 0 && gpio_input[i] <= 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) data->gpio_config[gpio_input[i]] &= ~0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) /* if GPIO0-7 is input, it isn't a FAN tach */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) if (gpio_input[i] >= 0 && gpio_input[i] <= 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) data->config2 |= 1 << gpio_input[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) /* Inverted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) for (i = 0; i <= 16; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) data->gpio_config[gpio_inverted[i]] &= ~0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) /* Normal overrides inverted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) for (i = 0; i <= 16; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) data->gpio_config[gpio_normal[i]] |= 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) /* Fan overrides input and output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) for (i = 0; i <= 7; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) data->config2 &= ~(1 << gpio_fan[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) /* Write new configs to registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) data->config3 = (data->config3 & 0x3f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) | ((data->gpio_config[16] & 0x03) << 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) for (i = 15, value = 0; i >= 0; --i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) value <<= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) value |= data->gpio_config[i] & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) if ((i & 0x03) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) adm1026_write_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) ADM1026_REG_GPIO_CFG_0_3 + i/4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) /* Print the new config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) adm1026_print_gpio(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) static void adm1026_init_client(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) int value, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) struct adm1026_data *data = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) dev_dbg(&client->dev, "Initializing device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) /* Read chip config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) /* Inform user of chip config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) dev_dbg(&client->dev, "ADM1026_REG_CONFIG1 is: 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) data->config1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) if ((data->config1 & CFG1_MONITOR) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) dev_dbg(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) "Monitoring not currently enabled.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) if (data->config1 & CFG1_INT_ENABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) dev_dbg(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) "SMBALERT interrupts are enabled.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) if (data->config1 & CFG1_AIN8_9) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) dev_dbg(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) "in8 and in9 enabled. temp3 disabled.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) dev_dbg(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) "temp3 enabled. in8 and in9 disabled.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) if (data->config1 & CFG1_THERM_HOT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) dev_dbg(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) "Automatic THERM, PWM, and temp limits enabled.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) if (data->config3 & CFG3_GPIO16_ENABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) dev_dbg(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) "GPIO16 enabled. THERM pin disabled.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) dev_dbg(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) "THERM pin enabled. GPIO16 disabled.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) if (data->config3 & CFG3_VREF_250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) dev_dbg(&client->dev, "Vref is 2.50 Volts.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) dev_dbg(&client->dev, "Vref is 1.82 Volts.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) /* Read and pick apart the existing GPIO configuration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) for (i = 0; i <= 15; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) if ((i & 0x03) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) value = adm1026_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) ADM1026_REG_GPIO_CFG_0_3 + i / 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) data->gpio_config[i] = value & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) value >>= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) data->gpio_config[16] = (data->config3 >> 6) & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) /* ... and then print it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) adm1026_print_gpio(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) * If the user asks us to reprogram the GPIO config, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) * do it now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) if (gpio_input[0] != -1 || gpio_output[0] != -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) || gpio_inverted[0] != -1 || gpio_normal[0] != -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) || gpio_fan[0] != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) adm1026_fixup_gpio(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) * WE INTENTIONALLY make no changes to the limits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) * offsets, pwms, fans and zones. If they were
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) * configured, we don't want to mess with them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) * If they weren't, the default is 100% PWM, no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) * control and will suffice until 'sensors -s'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) * can be run by the user. We DO set the default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) * value for pwm1.auto_pwm_min to its maximum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) * so that enabling automatic pwm fan control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) * without first setting a value for pwm1.auto_pwm_min
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) * will not result in potentially dangerous fan speed decrease.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) data->pwm1.auto_pwm_min = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) /* Start monitoring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) /* Set MONITOR, clear interrupt acknowledge and s/w reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) dev_dbg(&client->dev, "Setting CONFIG to: 0x%02x\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) data->config1 = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) /* initialize fan_div[] to hardware defaults */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) for (i = 0; i <= 7; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) data->fan_div[i] = DIV_FROM_REG(value & 0x03);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) value >>= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) static int adm1026_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) struct adm1026_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) data = devm_kzalloc(dev, sizeof(struct adm1026_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) i2c_set_clientdata(client, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) data->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) mutex_init(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) /* Set the VRM version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) data->vrm = vid_which_vrm();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) /* Initialize the ADM1026 chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) adm1026_init_client(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) /* sysfs hooks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) data->groups[0] = &adm1026_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) if (data->config1 & CFG1_AIN8_9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) data->groups[1] = &adm1026_group_in8_9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) data->groups[1] = &adm1026_group_temp3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) data, data->groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) return PTR_ERR_OR_ZERO(hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) static const struct i2c_device_id adm1026_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) { "adm1026", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) MODULE_DEVICE_TABLE(i2c, adm1026_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) static struct i2c_driver adm1026_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) .class = I2C_CLASS_HWMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) .name = "adm1026",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) .probe_new = adm1026_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) .id_table = adm1026_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) .detect = adm1026_detect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) .address_list = normal_i2c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) module_i2c_driver(adm1026_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) "Justin Thiessen <jthiessen@penguincomputing.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) MODULE_DESCRIPTION("ADM1026 driver");