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