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