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