| [2653] | 1 | /* |
|---|
| 2 | lm93.c - Part of lm_sensors, Linux kernel modules for hardware monitoring |
|---|
| 3 | |
|---|
| 4 | Author/Maintainer: Mark M. Hoffman <mhoffman@lightlink.com> |
|---|
| 5 | Copyright (c) 2004 Utilitek Systems, Inc. |
|---|
| 6 | |
|---|
| 7 | derived in part from lm78.c: |
|---|
| 8 | Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> |
|---|
| 9 | |
|---|
| 10 | derived in part from lm85.c: |
|---|
| 11 | Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> |
|---|
| 12 | Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> |
|---|
| 13 | |
|---|
| 14 | derived in part from w83l785ts.c: |
|---|
| 15 | Copyright (c) 2003-2004 Jean Delvare <khali@linux-fr.org> |
|---|
| 16 | |
|---|
| 17 | This program is free software; you can redistribute it and/or modify |
|---|
| 18 | it under the terms of the GNU General Public License as published by |
|---|
| 19 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 20 | (at your option) any later version. |
|---|
| 21 | |
|---|
| 22 | This program is distributed in the hope that it will be useful, |
|---|
| 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 25 | GNU General Public License for more details. |
|---|
| 26 | |
|---|
| 27 | You should have received a copy of the GNU General Public License |
|---|
| 28 | along with this program; if not, write to the Free Software |
|---|
| 29 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 30 | */ |
|---|
| 31 | |
|---|
| 32 | #define DEBUG 1 |
|---|
| 33 | |
|---|
| 34 | #include <linux/module.h> |
|---|
| 35 | #include <linux/slab.h> |
|---|
| 36 | #include <linux/ioport.h> |
|---|
| 37 | #include <linux/i2c.h> |
|---|
| 38 | #include <linux/i2c-proc.h> |
|---|
| 39 | #include <linux/init.h> |
|---|
| 40 | #include <linux/delay.h> |
|---|
| 41 | #include <asm/io.h> |
|---|
| 42 | #include <asm/bitops.h> |
|---|
| 43 | #include "version.h" |
|---|
| 44 | #include "sensors_vid.h" |
|---|
| [2671] | 45 | #include "lm93.h" |
|---|
| [2653] | 46 | |
|---|
| 47 | #ifndef I2C_DRIVERID_LM93 |
|---|
| 48 | #define I2C_DRIVERID_LM93 1049 |
|---|
| 49 | #endif |
|---|
| 50 | |
|---|
| 51 | /* I2C addresses to scan */ |
|---|
| 52 | static unsigned short normal_i2c[] = { SENSORS_I2C_END }; |
|---|
| 53 | static unsigned short normal_i2c_range[] = { 0x2c, 0x2e, SENSORS_I2C_END }; |
|---|
| 54 | |
|---|
| 55 | /* ISA addresses to scan (none) */ |
|---|
| 56 | static unsigned int normal_isa[] = { SENSORS_ISA_END }; |
|---|
| 57 | static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; |
|---|
| 58 | |
|---|
| 59 | /* module parameters */ |
|---|
| 60 | SENSORS_INSMOD_1(lm93); |
|---|
| 61 | |
|---|
| 62 | static int disable_block /* = 0 */ ; |
|---|
| 63 | MODULE_PARM(disable_block, "i"); |
|---|
| 64 | MODULE_PARM_DESC(disable_block, |
|---|
| 65 | "Set to non-zero to disable SMBus block data transactions."); |
|---|
| 66 | |
|---|
| 67 | static int init = 1; |
|---|
| 68 | MODULE_PARM(init, "i"); |
|---|
| [2715] | 69 | MODULE_PARM_DESC(init, "Set to zero to bypass most chip initialization"); |
|---|
| [2653] | 70 | |
|---|
| 71 | static int vccp_limit_type[2] /* = {0,0} */ ; |
|---|
| 72 | MODULE_PARM(vccp_limit_type, "2-2i"); |
|---|
| 73 | MODULE_PARM_DESC(vccp_limit_type, "Configures in7 and in8 limit modes"); |
|---|
| 74 | |
|---|
| [2715] | 75 | static int vid_agtl = 0; |
|---|
| 76 | MODULE_PARM(vid_agtl, "i"); |
|---|
| 77 | MODULE_PARM_DESC(vid_agtl, "Configures VID pin input thresholds"); |
|---|
| 78 | |
|---|
| [2653] | 79 | /* -- SENSORS SYSCTL START -- */ |
|---|
| 80 | /* volts * 100 */ |
|---|
| [2672] | 81 | #define LM93_SYSCTL_IN1 1001 |
|---|
| 82 | #define LM93_SYSCTL_IN2 1002 |
|---|
| 83 | #define LM93_SYSCTL_IN3 1003 |
|---|
| 84 | #define LM93_SYSCTL_IN4 1004 |
|---|
| 85 | #define LM93_SYSCTL_IN5 1005 |
|---|
| 86 | #define LM93_SYSCTL_IN6 1006 |
|---|
| 87 | #define LM93_SYSCTL_IN7 1007 |
|---|
| 88 | #define LM93_SYSCTL_IN8 1008 |
|---|
| 89 | #define LM93_SYSCTL_IN9 1009 |
|---|
| 90 | #define LM93_SYSCTL_IN10 1010 |
|---|
| 91 | #define LM93_SYSCTL_IN11 1011 |
|---|
| 92 | #define LM93_SYSCTL_IN12 1012 |
|---|
| 93 | #define LM93_SYSCTL_IN13 1013 |
|---|
| 94 | #define LM93_SYSCTL_IN14 1014 |
|---|
| 95 | #define LM93_SYSCTL_IN15 1015 |
|---|
| 96 | #define LM93_SYSCTL_IN16 1016 |
|---|
| [2653] | 97 | |
|---|
| [3000] | 98 | /* degrees Celsius * 10 */ |
|---|
| [2671] | 99 | #define LM93_SYSCTL_TEMP1 1101 |
|---|
| 100 | #define LM93_SYSCTL_TEMP2 1102 |
|---|
| 101 | #define LM93_SYSCTL_TEMP3 1103 |
|---|
| [2653] | 102 | |
|---|
| [2671] | 103 | #define LM93_SYSCTL_TEMP1_AUTO_BASE 1111 |
|---|
| 104 | #define LM93_SYSCTL_TEMP2_AUTO_BASE 1112 |
|---|
| 105 | #define LM93_SYSCTL_TEMP3_AUTO_BASE 1113 |
|---|
| 106 | |
|---|
| 107 | #define LM93_SYSCTL_TEMP1_AUTO_OFFSETS 1121 |
|---|
| 108 | #define LM93_SYSCTL_TEMP2_AUTO_OFFSETS 1122 |
|---|
| 109 | #define LM93_SYSCTL_TEMP3_AUTO_OFFSETS 1123 |
|---|
| 110 | |
|---|
| 111 | #define LM93_SYSCTL_TEMP1_AUTO_BOOST 1131 |
|---|
| 112 | #define LM93_SYSCTL_TEMP2_AUTO_BOOST 1132 |
|---|
| 113 | #define LM93_SYSCTL_TEMP3_AUTO_BOOST 1133 |
|---|
| 114 | |
|---|
| 115 | #define LM93_SYSCTL_TEMP1_AUTO_BOOST_HYST 1141 |
|---|
| 116 | #define LM93_SYSCTL_TEMP2_AUTO_BOOST_HYST 1142 |
|---|
| 117 | #define LM93_SYSCTL_TEMP3_AUTO_BOOST_HYST 1143 |
|---|
| 118 | |
|---|
| 119 | /* 0 => off, 255 => 100% */ |
|---|
| 120 | #define LM93_SYSCTL_TEMP1_AUTO_PWM_MIN 1151 |
|---|
| 121 | #define LM93_SYSCTL_TEMP2_AUTO_PWM_MIN 1152 |
|---|
| 122 | #define LM93_SYSCTL_TEMP3_AUTO_PWM_MIN 1153 |
|---|
| 123 | |
|---|
| [3000] | 124 | /* degrees Celsius * 10 */ |
|---|
| [2671] | 125 | #define LM93_SYSCTL_TEMP1_AUTO_OFFSET_HYST 1161 |
|---|
| 126 | #define LM93_SYSCTL_TEMP2_AUTO_OFFSET_HYST 1162 |
|---|
| 127 | #define LM93_SYSCTL_TEMP3_AUTO_OFFSET_HYST 1163 |
|---|
| 128 | |
|---|
| [2653] | 129 | /* rotations/minute */ |
|---|
| [2672] | 130 | #define LM93_SYSCTL_FAN1 1201 |
|---|
| 131 | #define LM93_SYSCTL_FAN2 1202 |
|---|
| 132 | #define LM93_SYSCTL_FAN3 1203 |
|---|
| 133 | #define LM93_SYSCTL_FAN4 1204 |
|---|
| [2653] | 134 | |
|---|
| 135 | /* 1-2 => enable smart tach mode associated with this pwm #, or disable */ |
|---|
| [2672] | 136 | #define LM93_SYSCTL_FAN1_SMART_TACH 1205 |
|---|
| 137 | #define LM93_SYSCTL_FAN2_SMART_TACH 1206 |
|---|
| 138 | #define LM93_SYSCTL_FAN3_SMART_TACH 1207 |
|---|
| 139 | #define LM93_SYSCTL_FAN4_SMART_TACH 1208 |
|---|
| [2653] | 140 | |
|---|
| 141 | /* volts * 1000 */ |
|---|
| [2672] | 142 | #define LM93_SYSCTL_VID1 1301 |
|---|
| 143 | #define LM93_SYSCTL_VID2 1302 |
|---|
| [2653] | 144 | |
|---|
| 145 | /* 0 => off, 255 => 100% */ |
|---|
| [2671] | 146 | #define LM93_SYSCTL_PWM1 1401 |
|---|
| 147 | #define LM93_SYSCTL_PWM2 1402 |
|---|
| [2653] | 148 | |
|---|
| [2660] | 149 | /* Hz */ |
|---|
| [2671] | 150 | #define LM93_SYSCTL_PWM1_FREQ 1411 |
|---|
| 151 | #define LM93_SYSCTL_PWM2_FREQ 1412 |
|---|
| [2660] | 152 | |
|---|
| [2671] | 153 | /* bitvector */ |
|---|
| 154 | #define LM93_SYSCTL_PWM1_AUTO_CHANNELS 1421 |
|---|
| 155 | #define LM93_SYSCTL_PWM2_AUTO_CHANNELS 1422 |
|---|
| 156 | |
|---|
| 157 | /* Hz */ |
|---|
| 158 | #define LM93_SYSCTL_PWM1_AUTO_SPINUP_MIN 1431 |
|---|
| 159 | #define LM93_SYSCTL_PWM2_AUTO_SPINUP_MIN 1432 |
|---|
| 160 | |
|---|
| 161 | /* seconds */ |
|---|
| 162 | #define LM93_SYSCTL_PWM1_AUTO_SPINUP_TIME 1441 |
|---|
| 163 | #define LM93_SYSCTL_PWM2_AUTO_SPINUP_TIME 1442 |
|---|
| 164 | |
|---|
| 165 | /* seconds */ |
|---|
| 166 | #define LM93_SYSCTL_PWM_AUTO_PROCHOT_RAMP 1451 |
|---|
| 167 | #define LM93_SYSCTL_PWM_AUTO_VRDHOT_RAMP 1452 |
|---|
| 168 | |
|---|
| [2653] | 169 | /* 0 => 0%, 255 => > 99.6% */ |
|---|
| [2672] | 170 | #define LM93_SYSCTL_PROCHOT1 1501 |
|---|
| 171 | #define LM93_SYSCTL_PROCHOT2 1502 |
|---|
| [2653] | 172 | |
|---|
| 173 | /* !0 => enable #PROCHOT logical short */ |
|---|
| [2672] | 174 | #define LM93_SYSCTL_PROCHOT_SHORT 1503 |
|---|
| [2653] | 175 | |
|---|
| [2660] | 176 | /* 2 boolean enable/disable, 3rd value indicates duty cycle */ |
|---|
| [2672] | 177 | #define LM93_SYSCTL_PROCHOT_OVERRIDE 1504 |
|---|
| [2660] | 178 | |
|---|
| 179 | /* 2 values, 0-9 */ |
|---|
| [2672] | 180 | #define LM93_SYSCTL_PROCHOT_INTERVAL 1505 |
|---|
| [2660] | 181 | |
|---|
| 182 | /* GPIO input (bitmask) */ |
|---|
| [2672] | 183 | #define LM93_SYSCTL_GPIO 1601 |
|---|
| [2660] | 184 | |
|---|
| 185 | /* #VRDHOT input (boolean) */ |
|---|
| [2672] | 186 | #define LM93_SYSCTL_VRDHOT1 1701 |
|---|
| 187 | #define LM93_SYSCTL_VRDHOT2 1702 |
|---|
| [2660] | 188 | |
|---|
| 189 | /* alarms (bitmask) */ |
|---|
| [2672] | 190 | #define LM93_SYSCTL_ALARMS 2001 |
|---|
| [2653] | 191 | |
|---|
| [2660] | 192 | /* alarm bitmask definitions |
|---|
| 193 | The LM93 has nearly 64 bits of error status... I've pared that down to |
|---|
| 194 | what I think is a useful subset in order to fit it into 32 bits. |
|---|
| [2653] | 195 | |
|---|
| [2660] | 196 | Especially note that the #VRD_HOT alarms are missing because we provide |
|---|
| 197 | that information as values in another /proc file. |
|---|
| 198 | |
|---|
| 199 | If libsensors is extended to support 64 bit values, this could be revisited. |
|---|
| [2653] | 200 | */ |
|---|
| [2660] | 201 | #define LM93_ALARM_IN1 0x00000001 |
|---|
| 202 | #define LM93_ALARM_IN2 0x00000002 |
|---|
| 203 | #define LM93_ALARM_IN3 0x00000004 |
|---|
| 204 | #define LM93_ALARM_IN4 0x00000008 |
|---|
| 205 | #define LM93_ALARM_IN5 0x00000010 |
|---|
| 206 | #define LM93_ALARM_IN6 0x00000020 |
|---|
| 207 | #define LM93_ALARM_IN7 0x00000040 |
|---|
| 208 | #define LM93_ALARM_IN8 0x00000080 |
|---|
| 209 | #define LM93_ALARM_IN9 0x00000100 |
|---|
| 210 | #define LM93_ALARM_IN10 0x00000200 |
|---|
| 211 | #define LM93_ALARM_IN11 0x00000400 |
|---|
| 212 | #define LM93_ALARM_IN12 0x00000800 |
|---|
| 213 | #define LM93_ALARM_IN13 0x00001000 |
|---|
| 214 | #define LM93_ALARM_IN14 0x00002000 |
|---|
| 215 | #define LM93_ALARM_IN15 0x00004000 |
|---|
| 216 | #define LM93_ALARM_IN16 0x00008000 |
|---|
| 217 | #define LM93_ALARM_FAN1 0x00010000 |
|---|
| 218 | #define LM93_ALARM_FAN2 0x00020000 |
|---|
| 219 | #define LM93_ALARM_FAN3 0x00040000 |
|---|
| 220 | #define LM93_ALARM_FAN4 0x00080000 |
|---|
| 221 | #define LM93_ALARM_PH1_ERR 0x00100000 |
|---|
| 222 | #define LM93_ALARM_PH2_ERR 0x00200000 |
|---|
| 223 | #define LM93_ALARM_SCSI1_ERR 0x00400000 |
|---|
| 224 | #define LM93_ALARM_SCSI2_ERR 0x00800000 |
|---|
| 225 | #define LM93_ALARM_DVDDP1_ERR 0x01000000 |
|---|
| 226 | #define LM93_ALARM_DVDDP2_ERR 0x02000000 |
|---|
| 227 | #define LM93_ALARM_D1_ERR 0x04000000 |
|---|
| 228 | #define LM93_ALARM_D2_ERR 0x08000000 |
|---|
| 229 | #define LM93_ALARM_TEMP1 0x10000000 |
|---|
| 230 | #define LM93_ALARM_TEMP2 0x20000000 |
|---|
| 231 | #define LM93_ALARM_TEMP3 0x40000000 |
|---|
| [2653] | 232 | |
|---|
| 233 | /* -- SENSORS SYSCTL END -- */ |
|---|
| 234 | |
|---|
| [2672] | 235 | /* SMBus capabilities */ |
|---|
| 236 | #define LM93_SMBUS_FUNC_FULL (I2C_FUNC_SMBUS_BYTE_DATA | \ |
|---|
| 237 | I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BLOCK_DATA) |
|---|
| 238 | #define LM93_SMBUS_FUNC_MIN (I2C_FUNC_SMBUS_BYTE_DATA | \ |
|---|
| 239 | I2C_FUNC_SMBUS_WORD_DATA) |
|---|
| [2653] | 240 | |
|---|
| [2672] | 241 | /* LM93 BLOCK READ COMMANDS */ |
|---|
| 242 | static const struct { u8 cmd; u8 len; } lm93_block_read_cmds[12] = { |
|---|
| 243 | { 0xf2, 8 }, |
|---|
| 244 | { 0xf3, 8 }, |
|---|
| 245 | { 0xf4, 6 }, |
|---|
| 246 | { 0xf5, 16 }, |
|---|
| 247 | { 0xf6, 4 }, |
|---|
| 248 | { 0xf7, 8 }, |
|---|
| 249 | { 0xf8, 12 }, |
|---|
| 250 | { 0xf9, 32 }, |
|---|
| 251 | { 0xfa, 8 }, |
|---|
| 252 | { 0xfb, 8 }, |
|---|
| 253 | { 0xfc, 16 }, |
|---|
| 254 | { 0xfd, 9 }, |
|---|
| 255 | }; |
|---|
| [2653] | 256 | |
|---|
| [2672] | 257 | /* ALARMS: SYSCTL format described further below |
|---|
| 258 | REG: 64 bits in 8 registers, as immediately below */ |
|---|
| 259 | struct block1_t { |
|---|
| 260 | u8 host_status_1; |
|---|
| 261 | u8 host_status_2; |
|---|
| 262 | u8 host_status_3; |
|---|
| 263 | u8 host_status_4; |
|---|
| 264 | u8 p1_prochot_status; |
|---|
| 265 | u8 p2_prochot_status; |
|---|
| 266 | u8 gpi_status; |
|---|
| 267 | u8 fan_status; |
|---|
| 268 | }; |
|---|
| [2653] | 269 | |
|---|
| [2672] | 270 | /* unique ID for each LM93 detected */ |
|---|
| 271 | static int lm93_id = 0; |
|---|
| [2671] | 272 | |
|---|
| [2672] | 273 | /* For each registered client, we need to keep some data in memory. That |
|---|
| 274 | data is pointed to by client->data. The structure itself is dynamically |
|---|
| 275 | allocated, at the same time the client itself is allocated. */ |
|---|
| [2671] | 276 | |
|---|
| [2672] | 277 | struct lm93_data { |
|---|
| 278 | struct i2c_client client; |
|---|
| 279 | int sysctl_id; |
|---|
| [2671] | 280 | |
|---|
| [2672] | 281 | struct semaphore update_lock; |
|---|
| 282 | unsigned long last_updated; /* In jiffies */ |
|---|
| [2671] | 283 | |
|---|
| [2672] | 284 | /* client update function */ |
|---|
| 285 | void (*update)(struct lm93_data *, struct i2c_client *); |
|---|
| [2671] | 286 | |
|---|
| [2672] | 287 | char valid; /* !=0 if following fields are valid */ |
|---|
| [2671] | 288 | |
|---|
| [2672] | 289 | /* register values, arranged by block read groups */ |
|---|
| 290 | struct block1_t block1; |
|---|
| [2653] | 291 | |
|---|
| [2672] | 292 | /* temp1 - temp4: unfiltered readings |
|---|
| 293 | temp1 - temp2: filtered readings */ |
|---|
| 294 | u8 block2[6]; |
|---|
| [2653] | 295 | |
|---|
| [2672] | 296 | /* vin1 - vin16: readings */ |
|---|
| 297 | u8 block3[16]; |
|---|
| [2653] | 298 | |
|---|
| [2672] | 299 | /* prochot1 - prochot2: readings */ |
|---|
| 300 | struct { u8 cur; u8 avg; } block4[2]; |
|---|
| [2660] | 301 | |
|---|
| [2672] | 302 | /* fan counts 1-4 => 14-bits, LE, *left* justified */ |
|---|
| 303 | u16 block5[4]; |
|---|
| [2671] | 304 | |
|---|
| [2672] | 305 | /* block6 has a lot of data we don't need */ |
|---|
| [4658] | 306 | struct { u8 min; u8 max; } temp_lim[4]; |
|---|
| [2671] | 307 | |
|---|
| [2672] | 308 | /* vin1 - vin16: low and high limits */ |
|---|
| 309 | struct { u8 min; u8 max; } block7[16]; |
|---|
| [2671] | 310 | |
|---|
| [2672] | 311 | /* fan count limits 1-4 => same format as block5 */ |
|---|
| 312 | u16 block8[4]; |
|---|
| [2671] | 313 | |
|---|
| [2672] | 314 | /* pwm control registers (2 pwms, 4 regs) */ |
|---|
| 315 | u8 block9[2][4]; |
|---|
| [2671] | 316 | |
|---|
| [2672] | 317 | /* auto/pwm base temp and offset temp registers */ |
|---|
| 318 | struct { u8 base[4]; u8 offset[12]; } block10; |
|---|
| [2653] | 319 | |
|---|
| [2672] | 320 | /* master config register */ |
|---|
| 321 | u8 config; |
|---|
| [2653] | 322 | |
|---|
| [2672] | 323 | /* VID1 & VID2 => register format, 6-bits, right justified */ |
|---|
| 324 | u8 vid[2]; |
|---|
| [2660] | 325 | |
|---|
| [2672] | 326 | /* prochot1 - prochot2: limits */ |
|---|
| 327 | u8 prochot_max[2]; |
|---|
| [2660] | 328 | |
|---|
| [2672] | 329 | /* vccp1 & vccp2 (in7 & in8): VID relative limits (register format) */ |
|---|
| 330 | u8 vccp_limits[2]; |
|---|
| [2660] | 331 | |
|---|
| [2672] | 332 | /* GPIO input state (register format, i.e. inverted) */ |
|---|
| 333 | u8 gpi; |
|---|
| [2660] | 334 | |
|---|
| [2672] | 335 | /* #PROCHOT override (register format) */ |
|---|
| 336 | u8 prochot_override; |
|---|
| [2660] | 337 | |
|---|
| [2672] | 338 | /* #PROCHOT intervals (register format) */ |
|---|
| 339 | u8 prochot_interval; |
|---|
| [2653] | 340 | |
|---|
| [2672] | 341 | /* Fan Boost Temperatures (register format) */ |
|---|
| 342 | u8 boost[4]; |
|---|
| [2653] | 343 | |
|---|
| [2672] | 344 | /* Fan Boost Hysteresis (register format) */ |
|---|
| 345 | u8 boost_hyst[2]; |
|---|
| [2653] | 346 | |
|---|
| [2672] | 347 | /* Temperature Zone Min. PWM & Hysteresis (register format) */ |
|---|
| 348 | u8 auto_pwm_min_hyst[2]; |
|---|
| [2653] | 349 | |
|---|
| [2672] | 350 | /* #PROCHOT & #VRDHOT PWM Ramp Control */ |
|---|
| 351 | u8 pwm_ramp_ctl; |
|---|
| [2653] | 352 | |
|---|
| [2672] | 353 | /* miscellaneous setup regs */ |
|---|
| 354 | u8 sfc1; |
|---|
| 355 | u8 sfc2; |
|---|
| 356 | u8 sf_tach_to_pwm; |
|---|
| [2653] | 357 | |
|---|
| [2672] | 358 | /* The two PWM CTL2 registers can read something other than what was |
|---|
| 359 | last written for the OVR_DC field (duty cycle override). So, we |
|---|
| 360 | save the user-commanded value here. */ |
|---|
| 361 | u8 pwm_override[2]; |
|---|
| 362 | }; |
|---|
| [2653] | 363 | |
|---|
| 364 | #define MAX_RETRIES 5 |
|---|
| 365 | |
|---|
| 366 | static u8 lm93_read_byte(struct i2c_client *client, u8 reg) |
|---|
| 367 | { |
|---|
| 368 | int value, i; |
|---|
| 369 | |
|---|
| 370 | /* retry in case of read errors */ |
|---|
| 371 | for (i=1; i<=MAX_RETRIES; i++) { |
|---|
| 372 | if ((value = i2c_smbus_read_byte_data(client, reg)) >= 0) { |
|---|
| 373 | return value; |
|---|
| 374 | } else { |
|---|
| 375 | printk(KERN_WARNING "lm93.o: read byte data failed, " |
|---|
| 376 | "address 0x%02x.\n", reg); |
|---|
| [2835] | 377 | mdelay(i + 3); |
|---|
| [2653] | 378 | } |
|---|
| 379 | |
|---|
| 380 | } |
|---|
| 381 | |
|---|
| 382 | /* <TODO> what to return in case of error? */ |
|---|
| [2744] | 383 | printk(KERN_ERR "lm93.o: All read byte retries failed!!\n"); |
|---|
| [2653] | 384 | return 0; |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | static int lm93_write_byte(struct i2c_client *client, u8 reg, u8 value) |
|---|
| 388 | { |
|---|
| 389 | int result; |
|---|
| 390 | |
|---|
| 391 | /* <TODO> how to handle write errors? */ |
|---|
| 392 | result = i2c_smbus_write_byte_data(client, reg, value); |
|---|
| 393 | |
|---|
| 394 | if (result < 0) |
|---|
| 395 | printk(KERN_WARNING "lm93.o: write byte data failed, " |
|---|
| 396 | "0x%02x at address 0x%02x.\n", value, reg); |
|---|
| 397 | |
|---|
| 398 | return result; |
|---|
| 399 | } |
|---|
| 400 | |
|---|
| 401 | static u16 lm93_read_word(struct i2c_client *client, u8 reg) |
|---|
| 402 | { |
|---|
| 403 | int value, i; |
|---|
| 404 | |
|---|
| 405 | /* retry in case of read errors */ |
|---|
| 406 | for (i=1; i<=MAX_RETRIES; i++) { |
|---|
| 407 | if ((value = i2c_smbus_read_word_data(client, reg)) >= 0) { |
|---|
| 408 | return value; |
|---|
| 409 | } else { |
|---|
| 410 | printk(KERN_WARNING "lm93.o: read word data failed, " |
|---|
| 411 | "address 0x%02x.\n", reg); |
|---|
| [2835] | 412 | mdelay(i + 3); |
|---|
| [2653] | 413 | } |
|---|
| 414 | |
|---|
| 415 | } |
|---|
| 416 | |
|---|
| 417 | /* <TODO> what to return in case of error? */ |
|---|
| [2744] | 418 | printk(KERN_ERR "lm93.o: All read word retries failed!!\n"); |
|---|
| [2653] | 419 | return 0; |
|---|
| 420 | } |
|---|
| 421 | |
|---|
| 422 | static int lm93_write_word(struct i2c_client *client, u8 reg, u16 value) |
|---|
| 423 | { |
|---|
| 424 | int result; |
|---|
| 425 | |
|---|
| 426 | /* <TODO> how to handle write errors? */ |
|---|
| 427 | result = i2c_smbus_write_word_data(client, reg, value); |
|---|
| 428 | |
|---|
| 429 | if (result < 0) |
|---|
| 430 | printk(KERN_WARNING "lm93.o: write word data failed, " |
|---|
| 431 | "0x%04x at address 0x%02x.\n", value, reg); |
|---|
| 432 | |
|---|
| 433 | return result; |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | static u8 lm93_block_buffer[I2C_SMBUS_BLOCK_MAX]; |
|---|
| 437 | |
|---|
| 438 | /* |
|---|
| 439 | read block data into values, retry if not expected length |
|---|
| 440 | fbn => index to lm93_block_read_cmds table |
|---|
| 441 | (Fixed Block Number - section 14.5.2 of LM93 datasheet) |
|---|
| 442 | */ |
|---|
| 443 | static void lm93_read_block(struct i2c_client *client, u8 fbn, u8 *values) |
|---|
| 444 | { |
|---|
| [2788] | 445 | int i, result=0; |
|---|
| [2653] | 446 | |
|---|
| 447 | for (i = 1; i <= MAX_RETRIES; i++) { |
|---|
| 448 | result = i2c_smbus_read_block_data(client, |
|---|
| 449 | lm93_block_read_cmds[fbn].cmd, lm93_block_buffer); |
|---|
| 450 | |
|---|
| [2788] | 451 | if (result == lm93_block_read_cmds[fbn].len) { |
|---|
| 452 | break; |
|---|
| 453 | } else { |
|---|
| [2653] | 454 | printk(KERN_WARNING "lm93.o: block read data failed, " |
|---|
| 455 | "command 0x%02x.\n", |
|---|
| 456 | lm93_block_read_cmds[fbn].cmd); |
|---|
| [2835] | 457 | mdelay(i + 3); |
|---|
| [2653] | 458 | } |
|---|
| 459 | } |
|---|
| 460 | |
|---|
| 461 | if (result == lm93_block_read_cmds[fbn].len) { |
|---|
| 462 | memcpy(values,lm93_block_buffer,lm93_block_read_cmds[fbn].len); |
|---|
| 463 | } else { |
|---|
| 464 | /* <TODO> what to do in case of error? */ |
|---|
| 465 | } |
|---|
| 466 | } |
|---|
| 467 | |
|---|
| 468 | static void lm93_update_client(struct i2c_client *client) |
|---|
| 469 | { |
|---|
| 470 | struct lm93_data *data = client->data; |
|---|
| 471 | |
|---|
| 472 | down(&data->update_lock); |
|---|
| 473 | |
|---|
| 474 | if (time_after(jiffies - data->last_updated, HZ + HZ / 2) || |
|---|
| 475 | time_before(jiffies, data->last_updated) || !data->valid) { |
|---|
| 476 | |
|---|
| 477 | data->update(data, client); |
|---|
| 478 | data->last_updated = jiffies; |
|---|
| 479 | data->valid = 1; |
|---|
| 480 | } |
|---|
| 481 | |
|---|
| 482 | up(&data->update_lock); |
|---|
| 483 | } |
|---|
| 484 | |
|---|
| 485 | /* update routine for data that has no corresponding SMBus block data command */ |
|---|
| 486 | static void lm93_update_client_common(struct lm93_data *data, |
|---|
| 487 | struct i2c_client *client) |
|---|
| 488 | { |
|---|
| 489 | int i; |
|---|
| [2722] | 490 | u8 *ptr; |
|---|
| [2653] | 491 | |
|---|
| [2671] | 492 | /* temp1 - temp4: limits */ |
|---|
| 493 | for (i = 0; i < 4; i++) { |
|---|
| [2653] | 494 | data->temp_lim[i].min = |
|---|
| 495 | lm93_read_byte(client, LM93_REG_TEMP_MIN(i)); |
|---|
| 496 | data->temp_lim[i].max = |
|---|
| 497 | lm93_read_byte(client, LM93_REG_TEMP_MAX(i)); |
|---|
| 498 | } |
|---|
| 499 | |
|---|
| 500 | /* config register */ |
|---|
| 501 | data->config = lm93_read_byte(client, LM93_REG_CONFIG); |
|---|
| 502 | |
|---|
| 503 | /* vid1 - vid2: values */ |
|---|
| 504 | for (i = 0; i < 2; i++) |
|---|
| 505 | data->vid[i] = lm93_read_byte(client, LM93_REG_VID(i)); |
|---|
| 506 | |
|---|
| 507 | /* prochot1 - prochot2: limits */ |
|---|
| 508 | for (i = 0; i < 2; i++) |
|---|
| 509 | data->prochot_max[i] = lm93_read_byte(client, |
|---|
| 510 | LM93_REG_PROCHOT_MAX(i)); |
|---|
| 511 | |
|---|
| 512 | /* vccp1 - vccp2: VID relative limits */ |
|---|
| 513 | for (i = 0; i < 2; i++) |
|---|
| 514 | data->vccp_limits[i] = lm93_read_byte(client, |
|---|
| 515 | LM93_REG_VCCP_LIMIT_OFF(i)); |
|---|
| 516 | |
|---|
| [2660] | 517 | /* GPIO input state */ |
|---|
| 518 | data->gpi = lm93_read_byte(client, LM93_REG_GPI); |
|---|
| 519 | |
|---|
| 520 | /* #PROCHOT override state */ |
|---|
| 521 | data->prochot_override = lm93_read_byte(client, |
|---|
| 522 | LM93_REG_PROCHOT_OVERRIDE); |
|---|
| 523 | |
|---|
| 524 | /* #PROCHOT intervals */ |
|---|
| 525 | data->prochot_interval = lm93_read_byte(client, |
|---|
| 526 | LM93_REG_PROCHOT_INTERVAL); |
|---|
| 527 | |
|---|
| [2671] | 528 | /* Fan Boost Termperature registers */ |
|---|
| 529 | for (i = 0; i < 4; i++) |
|---|
| 530 | data->boost[i] = lm93_read_byte(client, LM93_REG_BOOST(i)); |
|---|
| 531 | |
|---|
| 532 | /* Fan Boost Temperature Hyst. registers */ |
|---|
| 533 | data->boost_hyst[0] = lm93_read_byte(client, LM93_REG_BOOST_HYST_12); |
|---|
| 534 | data->boost_hyst[1] = lm93_read_byte(client, LM93_REG_BOOST_HYST_34); |
|---|
| 535 | |
|---|
| 536 | /* Temperature Zone Min. PWM & Hysteresis registers */ |
|---|
| 537 | data->auto_pwm_min_hyst[0] = |
|---|
| 538 | lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_12); |
|---|
| 539 | data->auto_pwm_min_hyst[1] = |
|---|
| 540 | lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_34); |
|---|
| 541 | |
|---|
| 542 | /* #PROCHOT & #VRDHOT PWM Ramp Control register */ |
|---|
| 543 | data->pwm_ramp_ctl = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL); |
|---|
| 544 | |
|---|
| [2653] | 545 | /* misc setup registers */ |
|---|
| 546 | data->sfc1 = lm93_read_byte(client, LM93_REG_SFC1); |
|---|
| 547 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
|---|
| 548 | data->sf_tach_to_pwm = lm93_read_byte(client, |
|---|
| 549 | LM93_REG_SF_TACH_TO_PWM); |
|---|
| [2722] | 550 | |
|---|
| 551 | /* write back alarm values to clear */ |
|---|
| 552 | for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++) |
|---|
| 553 | lm93_write_byte(client, LM93_REG_HOST_ERROR_1 + i, *(ptr + i)); |
|---|
| [2653] | 554 | } |
|---|
| 555 | |
|---|
| 556 | /* update routine which uses SMBus block data commands */ |
|---|
| 557 | static void lm93_update_client_full(struct lm93_data *data, |
|---|
| 558 | struct i2c_client *client) |
|---|
| 559 | { |
|---|
| 560 | pr_debug("lm93.o: starting device update (block data enabled)\n"); |
|---|
| 561 | |
|---|
| 562 | /* in1 - in16: values & limits */ |
|---|
| 563 | lm93_read_block(client, 3, (u8 *)(data->block3)); |
|---|
| 564 | lm93_read_block(client, 7, (u8 *)(data->block7)); |
|---|
| 565 | |
|---|
| [2671] | 566 | /* temp1 - temp4: values */ |
|---|
| [2653] | 567 | lm93_read_block(client, 2, (u8 *)(data->block2)); |
|---|
| 568 | |
|---|
| 569 | /* prochot1 - prochot2: values */ |
|---|
| 570 | lm93_read_block(client, 4, (u8 *)(data->block4)); |
|---|
| 571 | |
|---|
| 572 | /* fan1 - fan4: values & limits */ |
|---|
| 573 | lm93_read_block(client, 5, (u8 *)(data->block5)); |
|---|
| 574 | lm93_read_block(client, 8, (u8 *)(data->block8)); |
|---|
| 575 | |
|---|
| [2660] | 576 | /* pmw control registers */ |
|---|
| 577 | lm93_read_block(client, 9, (u8 *)(data->block9)); |
|---|
| [2653] | 578 | |
|---|
| [2666] | 579 | /* alarm values */ |
|---|
| 580 | lm93_read_block(client, 1, (u8 *)(&data->block1)); |
|---|
| 581 | |
|---|
| [2671] | 582 | /* auto/pwm registers */ |
|---|
| 583 | lm93_read_block(client, 10, (u8 *)(&data->block10)); |
|---|
| 584 | |
|---|
| [2653] | 585 | lm93_update_client_common(data, client); |
|---|
| 586 | } |
|---|
| 587 | |
|---|
| 588 | /* update routine which uses SMBus byte/word data commands only */ |
|---|
| 589 | static void lm93_update_client_min(struct lm93_data *data, |
|---|
| 590 | struct i2c_client *client) |
|---|
| 591 | { |
|---|
| [2660] | 592 | int i,j; |
|---|
| [2666] | 593 | u8 *ptr; |
|---|
| [2653] | 594 | |
|---|
| 595 | pr_debug("lm93.o: starting device update (block data disabled)\n"); |
|---|
| 596 | |
|---|
| 597 | /* in1 - in16: values & limits */ |
|---|
| 598 | for (i = 0; i < 16; i++) { |
|---|
| 599 | data->block3[i] = |
|---|
| 600 | lm93_read_byte(client, LM93_REG_IN(i)); |
|---|
| 601 | data->block7[i].min = |
|---|
| 602 | lm93_read_byte(client, LM93_REG_IN_MIN(i)); |
|---|
| 603 | data->block7[i].max = |
|---|
| 604 | lm93_read_byte(client, LM93_REG_IN_MAX(i)); |
|---|
| 605 | } |
|---|
| 606 | |
|---|
| [2671] | 607 | /* temp1 - temp4: values */ |
|---|
| [2653] | 608 | for (i = 0; i < 4; i++) { |
|---|
| 609 | data->block2[i] = |
|---|
| 610 | lm93_read_byte(client, LM93_REG_TEMP(i)); |
|---|
| 611 | } |
|---|
| 612 | |
|---|
| 613 | /* prochot1 - prochot2: values */ |
|---|
| 614 | for (i = 0; i < 2; i++) { |
|---|
| 615 | data->block4[i].cur = |
|---|
| 616 | lm93_read_byte(client, LM93_REG_PROCHOT_CUR(i)); |
|---|
| 617 | data->block4[i].avg = |
|---|
| 618 | lm93_read_byte(client, LM93_REG_PROCHOT_AVG(i)); |
|---|
| 619 | } |
|---|
| 620 | |
|---|
| 621 | /* fan1 - fan4: values & limits */ |
|---|
| 622 | for (i = 0; i < 4; i++) { |
|---|
| 623 | data->block5[i] = |
|---|
| 624 | lm93_read_word(client, LM93_REG_FAN(i)); |
|---|
| 625 | data->block8[i] = |
|---|
| 626 | lm93_read_word(client, LM93_REG_FAN_MIN(i)); |
|---|
| 627 | } |
|---|
| 628 | |
|---|
| [2660] | 629 | /* pwm control registers */ |
|---|
| 630 | for (i = 0; i < 2; i++) { |
|---|
| 631 | for (j = 0; j < 4; j++) { |
|---|
| 632 | data->block9[i][j] = |
|---|
| [2671] | 633 | lm93_read_byte(client, LM93_REG_PWM_CTL(i,j)); |
|---|
| [2660] | 634 | } |
|---|
| 635 | } |
|---|
| 636 | |
|---|
| [2666] | 637 | /* alarm values */ |
|---|
| [2671] | 638 | for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++) { |
|---|
| [2666] | 639 | *(ptr + i) = |
|---|
| [2667] | 640 | lm93_read_byte(client, LM93_REG_HOST_ERROR_1 + i); |
|---|
| [2666] | 641 | } |
|---|
| 642 | |
|---|
| [2671] | 643 | /* auto/pwm (base temp) registers */ |
|---|
| 644 | for (i = 0; i < 4; i++) { |
|---|
| 645 | data->block10.base[i] = |
|---|
| 646 | lm93_read_byte(client, LM93_REG_TEMP_BASE(i)); |
|---|
| 647 | } |
|---|
| 648 | |
|---|
| 649 | /* auto/pwm (offset temp) registers */ |
|---|
| 650 | for (i = 0; i < 12; i++) { |
|---|
| 651 | data->block10.offset[i] = |
|---|
| 652 | lm93_read_byte(client, LM93_REG_TEMP_OFFSET(i)); |
|---|
| 653 | } |
|---|
| 654 | |
|---|
| [2653] | 655 | lm93_update_client_common(data, client); |
|---|
| 656 | } |
|---|
| 657 | |
|---|
| [2672] | 658 | /* VID: mV |
|---|
| 659 | REG: 6-bits, right justified, *always* using Intel VRM/VRD 10 */ |
|---|
| 660 | static int LM93_VID_FROM_REG(u8 reg) |
|---|
| 661 | { |
|---|
| 662 | return vid_from_reg((reg & 0x3f), 100); |
|---|
| 663 | } |
|---|
| [2653] | 664 | |
|---|
| [2672] | 665 | static void lm93_vid(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 666 | int *nrels_mag, long *results) |
|---|
| 667 | { |
|---|
| 668 | struct lm93_data *data = client->data; |
|---|
| 669 | int nr = ctl_name - LM93_SYSCTL_VID1; |
|---|
| 670 | |
|---|
| 671 | if (0 > nr || nr > 1) |
|---|
| 672 | return; /* ERROR */ |
|---|
| 673 | |
|---|
| 674 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| [2689] | 675 | *nrels_mag = 3; |
|---|
| [2672] | 676 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 677 | lm93_update_client(client); |
|---|
| 678 | results[0] = LM93_VID_FROM_REG(data->vid[nr]); |
|---|
| 679 | *nrels_mag = 1; |
|---|
| 680 | } |
|---|
| 681 | } |
|---|
| 682 | |
|---|
| 683 | /* min, max, and nominal voltage readings, per channel (mV)*/ |
|---|
| 684 | static const unsigned long lm93_vin_val_min[16] = { |
|---|
| 685 | 0, 0, 0, 0, 0, 0, 0, 0, |
|---|
| 686 | 0, 0, 0, 0, 0, 0, 0, 3000, |
|---|
| 687 | }; |
|---|
| 688 | static const unsigned long lm93_vin_val_max[16] = { |
|---|
| 689 | 1236, 1236, 1236, 1600, 2000, 2000, 1600, 1600, |
|---|
| [2924] | 690 | 4400, 6500, 3333, 2625, 1312, 1312, 1236, 3600, |
|---|
| [2672] | 691 | }; |
|---|
| 692 | /* |
|---|
| 693 | static const unsigned long lm93_vin_val_nom[16] = { |
|---|
| 694 | 927, 927, 927, 1200, 1500, 1500, 1200, 1200, |
|---|
| 695 | 3300, 5000, 2500, 1969, 984, 984, 309, 3300, |
|---|
| 696 | }; |
|---|
| 697 | */ |
|---|
| 698 | |
|---|
| 699 | /* min, max, and nominal register values, per channel (u8) */ |
|---|
| 700 | static const u8 lm93_vin_reg_min[16] = { |
|---|
| 701 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|---|
| 702 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xae, |
|---|
| 703 | }; |
|---|
| 704 | static const u8 lm93_vin_reg_max[16] = { |
|---|
| 705 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
|---|
| 706 | 0xff, 0xfa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd1, |
|---|
| 707 | }; |
|---|
| 708 | /* |
|---|
| 709 | static const u8 lm93_vin_reg_nom[16] = { |
|---|
| 710 | 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, |
|---|
| 711 | 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0xc0, |
|---|
| 712 | }; |
|---|
| 713 | */ |
|---|
| 714 | |
|---|
| 715 | /* IN: 1/100 V, limits determined by channel nr |
|---|
| 716 | REG: scaling determined by channel nr */ |
|---|
| 717 | static u8 LM93_IN_TO_REG(int nr, unsigned val) |
|---|
| 718 | { |
|---|
| 719 | /* range limit */ |
|---|
| 720 | const long mV = SENSORS_LIMIT(val * 10, |
|---|
| 721 | lm93_vin_val_min[nr], lm93_vin_val_max[nr]); |
|---|
| 722 | |
|---|
| 723 | /* try not to lose too much precision here */ |
|---|
| 724 | const long uV = mV * 1000; |
|---|
| 725 | const long uV_max = lm93_vin_val_max[nr] * 1000; |
|---|
| 726 | const long uV_min = lm93_vin_val_min[nr] * 1000; |
|---|
| 727 | |
|---|
| 728 | /* convert */ |
|---|
| 729 | const long slope = (uV_max - uV_min) / |
|---|
| 730 | (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]); |
|---|
| 731 | const long intercept = uV_min - slope * lm93_vin_reg_min[nr]; |
|---|
| 732 | |
|---|
| 733 | u8 result = ((uV - intercept + (slope/2)) / slope); |
|---|
| 734 | result = SENSORS_LIMIT(result, |
|---|
| 735 | lm93_vin_reg_min[nr], lm93_vin_reg_max[nr]); |
|---|
| 736 | return result; |
|---|
| 737 | } |
|---|
| 738 | |
|---|
| 739 | static unsigned LM93_IN_FROM_REG(int nr, u8 reg) |
|---|
| 740 | { |
|---|
| 741 | const long uV_max = lm93_vin_val_max[nr] * 1000; |
|---|
| 742 | const long uV_min = lm93_vin_val_min[nr] * 1000; |
|---|
| 743 | |
|---|
| 744 | const long slope = (uV_max - uV_min) / |
|---|
| 745 | (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]); |
|---|
| 746 | const long intercept = uV_min - slope * lm93_vin_reg_min[nr]; |
|---|
| 747 | |
|---|
| 748 | return (slope * reg + intercept + 5000) / 10000; |
|---|
| 749 | } |
|---|
| 750 | |
|---|
| 751 | /* vid in mV , upper == 0 indicates low limit, otherwise upper limit |
|---|
| 752 | upper also determines which nibble of the register is returned |
|---|
| 753 | (the other nibble will be 0x0) */ |
|---|
| 754 | static u8 LM93_IN_REL_TO_REG(unsigned val, int upper, int vid) |
|---|
| 755 | { |
|---|
| 756 | long uV_offset = vid * 1000 - val * 10000; |
|---|
| 757 | if (upper) { |
|---|
| 758 | uV_offset = SENSORS_LIMIT(uV_offset, 12500, 200000); |
|---|
| 759 | return (u8)((uV_offset / 12500 - 1) << 4); |
|---|
| 760 | } else { |
|---|
| 761 | uV_offset = SENSORS_LIMIT(uV_offset, -400000, -25000); |
|---|
| 762 | return (u8)((uV_offset / -25000 - 1) << 0); |
|---|
| 763 | } |
|---|
| 764 | } |
|---|
| 765 | |
|---|
| 766 | /* vid in mV, upper == 0 indicates low limit, otherwise upper limit */ |
|---|
| 767 | static unsigned LM93_IN_REL_FROM_REG(u8 reg, int upper, int vid) |
|---|
| 768 | { |
|---|
| 769 | const long uV_offset = upper ? (((reg >> 4 & 0x0f) + 1) * 12500) : |
|---|
| 770 | (((reg >> 0 & 0x0f) + 1) * -25000); |
|---|
| 771 | const long uV_vid = vid * 1000; |
|---|
| 772 | return (uV_vid + uV_offset + 5000) / 10000; |
|---|
| 773 | } |
|---|
| 774 | |
|---|
| [2653] | 775 | static void lm93_in(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 776 | int *nrels_mag, long *results) |
|---|
| 777 | { |
|---|
| 778 | struct lm93_data *data = client->data; |
|---|
| 779 | int nr = ctl_name - LM93_SYSCTL_IN1; /* 0 <= nr <= 15 */ |
|---|
| 780 | int vccp = ctl_name - LM93_SYSCTL_IN7; /* 0 <= vccp <= 1 if relevant */ |
|---|
| 781 | |
|---|
| 782 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 783 | *nrels_mag = 2; |
|---|
| 784 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 785 | |
|---|
| 786 | lm93_update_client(client); |
|---|
| 787 | |
|---|
| 788 | /* for limits, check in7 and in8 for VID relative mode */ |
|---|
| 789 | if ((ctl_name==LM93_SYSCTL_IN7 || ctl_name==LM93_SYSCTL_IN8) && |
|---|
| 790 | (vccp_limit_type[vccp])) { |
|---|
| 791 | long vid = LM93_VID_FROM_REG(data->vid[vccp]); |
|---|
| 792 | results[0] = LM93_IN_REL_FROM_REG( |
|---|
| 793 | data->vccp_limits[vccp], 0, vid); |
|---|
| 794 | results[1] = LM93_IN_REL_FROM_REG( |
|---|
| 795 | data->vccp_limits[vccp], 1, vid); |
|---|
| 796 | |
|---|
| 797 | /* otherwise, use absolute limits */ |
|---|
| 798 | } else { |
|---|
| 799 | results[0] = LM93_IN_FROM_REG(nr, |
|---|
| 800 | data->block7[nr].min); |
|---|
| 801 | results[1] = LM93_IN_FROM_REG(nr, |
|---|
| 802 | data->block7[nr].max); |
|---|
| 803 | } |
|---|
| 804 | |
|---|
| 805 | results[2] = LM93_IN_FROM_REG(nr, data->block3[nr]); |
|---|
| 806 | *nrels_mag = 3; |
|---|
| 807 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 808 | down(&data->update_lock); |
|---|
| 809 | |
|---|
| 810 | /* for limits, check in7 and in8 for VID relative mode */ |
|---|
| 811 | if ((ctl_name==LM93_SYSCTL_IN7 || ctl_name==LM93_SYSCTL_IN8) && |
|---|
| 812 | (vccp_limit_type[vccp])) { |
|---|
| 813 | |
|---|
| 814 | long vid = LM93_VID_FROM_REG(data->vid[vccp]); |
|---|
| 815 | if (*nrels_mag >= 2) { |
|---|
| 816 | data->vccp_limits[vccp] = |
|---|
| 817 | (data->vccp_limits[vccp] & 0x0f) | |
|---|
| 818 | LM93_IN_REL_TO_REG(results[1], 1, vid); |
|---|
| 819 | } |
|---|
| 820 | if (*nrels_mag >= 1) { |
|---|
| 821 | data->vccp_limits[vccp] = |
|---|
| 822 | (data->vccp_limits[vccp] & 0xf0) | |
|---|
| 823 | LM93_IN_REL_TO_REG(results[0], 0, vid); |
|---|
| 824 | lm93_write_byte(client, |
|---|
| 825 | LM93_REG_VCCP_LIMIT_OFF(vccp), |
|---|
| 826 | data->vccp_limits[vccp]); |
|---|
| 827 | } |
|---|
| 828 | |
|---|
| 829 | /* otherwise, use absolute limits */ |
|---|
| 830 | } else { |
|---|
| 831 | if (*nrels_mag >= 1) { |
|---|
| 832 | data->block7[nr].min = LM93_IN_TO_REG(nr, |
|---|
| 833 | results[0]); |
|---|
| 834 | lm93_write_byte(client, LM93_REG_IN_MIN(nr), |
|---|
| 835 | data->block7[nr].min); |
|---|
| 836 | } |
|---|
| 837 | if (*nrels_mag >= 2) { |
|---|
| 838 | data->block7[nr].max = LM93_IN_TO_REG(nr, |
|---|
| 839 | results[1]); |
|---|
| 840 | lm93_write_byte(client, LM93_REG_IN_MAX(nr), |
|---|
| 841 | data->block7[nr].max); |
|---|
| 842 | } |
|---|
| 843 | } |
|---|
| 844 | up(&data->update_lock); |
|---|
| 845 | } |
|---|
| 846 | } |
|---|
| 847 | |
|---|
| [2672] | 848 | static unsigned LM93_ALARMS_FROM_REG(struct block1_t b1) |
|---|
| 849 | { |
|---|
| 850 | unsigned result; |
|---|
| [2734] | 851 | result = b1.host_status_2 & 0x3f; |
|---|
| 852 | |
|---|
| 853 | if (vccp_limit_type[0]) |
|---|
| [2744] | 854 | result |= (b1.host_status_4 & 0x10) << 2; |
|---|
| [2734] | 855 | else |
|---|
| 856 | result |= b1.host_status_2 & 0x40; |
|---|
| 857 | |
|---|
| 858 | if (vccp_limit_type[1]) |
|---|
| [2744] | 859 | result |= (b1.host_status_4 & 0x20) << 2; |
|---|
| [2734] | 860 | else |
|---|
| 861 | result |= b1.host_status_2 & 0x80; |
|---|
| 862 | |
|---|
| [2672] | 863 | result |= b1.host_status_3 << 8; |
|---|
| [2685] | 864 | result |= (b1.fan_status & 0x0f) << 16; |
|---|
| [2672] | 865 | result |= (b1.p1_prochot_status & 0x80) << 13; |
|---|
| 866 | result |= (b1.p2_prochot_status & 0x80) << 14; |
|---|
| 867 | result |= (b1.host_status_4 & 0xfc) << 20; |
|---|
| 868 | result |= (b1.host_status_1 & 0x07) << 28; |
|---|
| 869 | return result; |
|---|
| 870 | } |
|---|
| 871 | |
|---|
| 872 | static void lm93_alarms(struct i2c_client *client, int operation, |
|---|
| 873 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 874 | { |
|---|
| 875 | struct lm93_data *data = client->data; |
|---|
| 876 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 877 | *nrels_mag = 0; |
|---|
| 878 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 879 | lm93_update_client(client); |
|---|
| 880 | results[0] = LM93_ALARMS_FROM_REG(data->block1); |
|---|
| 881 | *nrels_mag = 1; |
|---|
| 882 | } |
|---|
| 883 | } |
|---|
| 884 | |
|---|
| 885 | #define LM93_TEMP_MIN (-1280) |
|---|
| 886 | #define LM93_TEMP_MAX ( 1270) |
|---|
| 887 | |
|---|
| 888 | /* TEMP: 1/10 degrees C (-128C to +127C) |
|---|
| 889 | REG: 1C/bit, two's complement */ |
|---|
| 890 | static u8 LM93_TEMP_TO_REG(int temp) |
|---|
| 891 | { |
|---|
| 892 | int ntemp = SENSORS_LIMIT(temp, LM93_TEMP_MIN, LM93_TEMP_MAX); |
|---|
| 893 | ntemp += (ntemp<0 ? -5 : 5); |
|---|
| 894 | return (u8)(ntemp / 10); |
|---|
| 895 | } |
|---|
| 896 | |
|---|
| 897 | static int LM93_TEMP_FROM_REG(u8 reg) |
|---|
| 898 | { |
|---|
| 899 | return (s8)reg * 10; |
|---|
| 900 | } |
|---|
| 901 | |
|---|
| 902 | static void lm93_temp(struct i2c_client *client, int operation, int ctl_name, |
|---|
| [2653] | 903 | int *nrels_mag, long *results) |
|---|
| 904 | { |
|---|
| 905 | struct lm93_data *data = client->data; |
|---|
| 906 | int nr = ctl_name - LM93_SYSCTL_TEMP1; |
|---|
| 907 | |
|---|
| 908 | if (0 > nr || nr > 2) |
|---|
| 909 | return; /* ERROR */ |
|---|
| 910 | |
|---|
| 911 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 912 | *nrels_mag = 1; |
|---|
| 913 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 914 | lm93_update_client(client); |
|---|
| 915 | results[0] = LM93_TEMP_FROM_REG(data->temp_lim[nr].max); |
|---|
| 916 | results[1] = LM93_TEMP_FROM_REG(data->temp_lim[nr].min); |
|---|
| 917 | results[2] = LM93_TEMP_FROM_REG(data->block2[nr]); |
|---|
| 918 | *nrels_mag = 3; |
|---|
| 919 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 920 | down(&data->update_lock); |
|---|
| 921 | if (*nrels_mag >= 1) { |
|---|
| 922 | data->temp_lim[nr].max = LM93_TEMP_TO_REG(results[0]); |
|---|
| 923 | lm93_write_byte(client, LM93_REG_TEMP_MAX(nr), |
|---|
| 924 | data->temp_lim[nr].max); |
|---|
| 925 | } |
|---|
| 926 | if (*nrels_mag >= 2) { |
|---|
| 927 | data->temp_lim[nr].min = LM93_TEMP_TO_REG(results[1]); |
|---|
| 928 | lm93_write_byte(client, LM93_REG_TEMP_MIN(nr), |
|---|
| 929 | data->temp_lim[nr].min); |
|---|
| 930 | } |
|---|
| 931 | up(&data->update_lock); |
|---|
| 932 | } |
|---|
| 933 | } |
|---|
| 934 | |
|---|
| [2672] | 935 | /* Determine 4-bit temperature offset resolution */ |
|---|
| 936 | static int LM93_TEMP_OFFSET_MODE_FROM_REG(u8 sfc2, int nr) |
|---|
| [2671] | 937 | { |
|---|
| [2672] | 938 | /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */ |
|---|
| 939 | return sfc2 & (nr < 2 ? 0x10 : 0x20); |
|---|
| 940 | } |
|---|
| [2671] | 941 | |
|---|
| [2672] | 942 | #define LM93_TEMP_OFFSET_MIN ( 0) |
|---|
| 943 | #define LM93_TEMP_OFFSET_MAX0 (150) |
|---|
| 944 | #define LM93_TEMP_OFFSET_MAX1 ( 75) |
|---|
| [2671] | 945 | |
|---|
| [2672] | 946 | /* This function is common to all 4-bit temperature offsets |
|---|
| 947 | returns 4 bits right justified |
|---|
| 948 | mode 0 => 1C/bit, mode !0 => 0.5C/bit */ |
|---|
| 949 | static u8 LM93_TEMP_OFFSET_TO_REG(int off, int mode) |
|---|
| 950 | { |
|---|
| 951 | int factor = mode ? 5 : 10; |
|---|
| 952 | |
|---|
| 953 | off = SENSORS_LIMIT(off, LM93_TEMP_OFFSET_MIN, |
|---|
| 954 | mode ? LM93_TEMP_OFFSET_MAX1 : LM93_TEMP_OFFSET_MAX0); |
|---|
| 955 | return (u8)((off + factor/2) / factor); |
|---|
| [2671] | 956 | } |
|---|
| 957 | |
|---|
| [2672] | 958 | /* This function is common to all 4-bit temperature offsets |
|---|
| 959 | reg is 4 bits right justified |
|---|
| 960 | mode 0 => 1C/bit, mode !0 => 0.5C/bit */ |
|---|
| 961 | static int LM93_TEMP_OFFSET_FROM_REG(u8 reg, int mode) |
|---|
| 962 | { |
|---|
| 963 | return (reg & 0x0f) * (mode ? 5 : 10); |
|---|
| 964 | } |
|---|
| 965 | |
|---|
| 966 | /* TEMP: 1/10 degrees C (0C to +15C (mode 0) or +7.5C (mode non-zero)) |
|---|
| 967 | REG: 1.0C/bit (mode 0) or 0.5C/bit (mode non-zero) |
|---|
| 968 | 0 <= nr <= 3 */ |
|---|
| 969 | static u8 LM93_TEMP_AUTO_OFFSET_TO_REG(u8 old, int off, int nr, int mode) |
|---|
| 970 | { |
|---|
| 971 | u8 new = LM93_TEMP_OFFSET_TO_REG(off, mode); |
|---|
| 972 | |
|---|
| 973 | /* temp1-temp2 (nr=0,1) use lower nibble */ |
|---|
| 974 | if (nr < 2) |
|---|
| 975 | return (old & 0xf0) | (new & 0x0f); |
|---|
| 976 | |
|---|
| 977 | /* temp3-temp4 (nr=2,3) use upper nibble */ |
|---|
| 978 | else |
|---|
| 979 | return (new << 4 & 0xf0) | (old & 0x0f); |
|---|
| 980 | } |
|---|
| 981 | |
|---|
| 982 | /* 0 <= nr <= 3 */ |
|---|
| 983 | static int LM93_TEMP_AUTO_OFFSET_FROM_REG(u8 reg, int nr, int mode) |
|---|
| 984 | { |
|---|
| 985 | /* temp1-temp2 (nr=0,1) use lower nibble */ |
|---|
| 986 | if (nr < 2) |
|---|
| 987 | return LM93_TEMP_OFFSET_FROM_REG(reg & 0x0f, mode); |
|---|
| 988 | |
|---|
| 989 | /* temp3-temp4 (nr=2,3) use upper nibble */ |
|---|
| 990 | else |
|---|
| 991 | return LM93_TEMP_OFFSET_FROM_REG(reg >> 4 & 0x0f, mode); |
|---|
| 992 | } |
|---|
| 993 | |
|---|
| 994 | static void lm93_temp_auto_offsets(struct i2c_client *client, int operation, |
|---|
| [2671] | 995 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 996 | { |
|---|
| 997 | struct lm93_data *data = client->data; |
|---|
| 998 | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_OFFSETS; |
|---|
| 999 | int ii; |
|---|
| 1000 | |
|---|
| 1001 | if (0 > nr || nr > 2) |
|---|
| 1002 | return; /* ERROR */ |
|---|
| 1003 | |
|---|
| 1004 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1005 | *nrels_mag = 1; |
|---|
| 1006 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1007 | int mode; |
|---|
| 1008 | lm93_update_client(client); |
|---|
| 1009 | |
|---|
| 1010 | /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */ |
|---|
| 1011 | mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); |
|---|
| 1012 | |
|---|
| 1013 | for (ii = 0; ii < 12; ii++) { |
|---|
| 1014 | results[ii] = LM93_TEMP_AUTO_OFFSET_FROM_REG( |
|---|
| 1015 | data->block10.offset[ii], nr, mode); |
|---|
| 1016 | } |
|---|
| 1017 | *nrels_mag = 12; |
|---|
| 1018 | } |
|---|
| 1019 | else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1020 | /* we only care about the first 12 values */ |
|---|
| 1021 | int nrels = *nrels_mag > 12 ? 12 : *nrels_mag; |
|---|
| 1022 | |
|---|
| 1023 | down(&data->update_lock); |
|---|
| 1024 | |
|---|
| 1025 | /* force 0.5C/bit mode */ |
|---|
| 1026 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
|---|
| 1027 | data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); |
|---|
| 1028 | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); |
|---|
| 1029 | |
|---|
| 1030 | for (ii = 0; ii < nrels; ii++) { |
|---|
| 1031 | data->block10.offset[ii] = LM93_TEMP_AUTO_OFFSET_TO_REG( |
|---|
| 1032 | data->block10.offset[ii], results[ii], nr, 1); |
|---|
| 1033 | lm93_write_byte(client, LM93_REG_TEMP_OFFSET(ii), |
|---|
| 1034 | data->block10.offset[ii]); |
|---|
| 1035 | } |
|---|
| 1036 | up(&data->update_lock); |
|---|
| 1037 | } |
|---|
| 1038 | } |
|---|
| 1039 | |
|---|
| [2672] | 1040 | /* RPM: (82.5 to 1350000) |
|---|
| 1041 | REG: 14-bits, LE, *left* justified */ |
|---|
| 1042 | static u16 LM93_FAN_TO_REG(long rpm) |
|---|
| 1043 | { |
|---|
| 1044 | u16 count, regs; |
|---|
| 1045 | |
|---|
| 1046 | if (rpm == 0) { |
|---|
| 1047 | count = 0x3fff; |
|---|
| 1048 | } else { |
|---|
| 1049 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); |
|---|
| 1050 | count = SENSORS_LIMIT((1350000 + rpm) / rpm, 1, 0x3ffe); |
|---|
| 1051 | } |
|---|
| 1052 | |
|---|
| 1053 | regs = count << 2; |
|---|
| 1054 | return cpu_to_le16(regs); |
|---|
| 1055 | } |
|---|
| 1056 | |
|---|
| 1057 | static int LM93_FAN_FROM_REG(u16 regs) |
|---|
| 1058 | { |
|---|
| 1059 | const u16 count = le16_to_cpu(regs) >> 2; |
|---|
| 1060 | return count==0 ? -1 : count==0x3fff ? 0: 1350000 / count; |
|---|
| 1061 | } |
|---|
| 1062 | |
|---|
| 1063 | static void lm93_fan(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1064 | int *nrels_mag, long *results) |
|---|
| 1065 | { |
|---|
| 1066 | struct lm93_data *data = client->data; |
|---|
| 1067 | int nr = ctl_name - LM93_SYSCTL_FAN1; |
|---|
| 1068 | |
|---|
| 1069 | if (0 > nr || nr > 3) |
|---|
| 1070 | return; /* ERROR */ |
|---|
| 1071 | |
|---|
| 1072 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1073 | *nrels_mag = 0; |
|---|
| 1074 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1075 | lm93_update_client(client); |
|---|
| 1076 | results[0] = LM93_FAN_FROM_REG(data->block8[nr]); /* min */ |
|---|
| 1077 | results[1] = LM93_FAN_FROM_REG(data->block5[nr]); /* val */ |
|---|
| 1078 | *nrels_mag = 2; |
|---|
| 1079 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1080 | if (*nrels_mag >= 1) { |
|---|
| 1081 | down(&data->update_lock); |
|---|
| 1082 | data->block8[nr] = LM93_FAN_TO_REG(results[0]); |
|---|
| 1083 | lm93_write_word(client, LM93_REG_FAN_MIN(nr), |
|---|
| 1084 | data->block8[nr]); |
|---|
| 1085 | up(&data->update_lock); |
|---|
| 1086 | } |
|---|
| 1087 | } |
|---|
| 1088 | } |
|---|
| 1089 | |
|---|
| 1090 | /* PROCHOT: 0-255, 0 => 0%, 255 => > 96.6% |
|---|
| 1091 | * REG: (same) */ |
|---|
| 1092 | static u8 LM93_PROCHOT_TO_REG(long prochot) |
|---|
| 1093 | { |
|---|
| 1094 | prochot = SENSORS_LIMIT(prochot, 0, 255); |
|---|
| 1095 | return (u8)prochot; |
|---|
| 1096 | } |
|---|
| 1097 | |
|---|
| 1098 | static void lm93_prochot(struct i2c_client *client, int operation, |
|---|
| [2671] | 1099 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 1100 | { |
|---|
| 1101 | struct lm93_data *data = client->data; |
|---|
| [2672] | 1102 | int nr = ctl_name - LM93_SYSCTL_PROCHOT1; |
|---|
| 1103 | |
|---|
| 1104 | if (0 > nr || nr > 1) |
|---|
| 1105 | return; /* ERROR */ |
|---|
| 1106 | |
|---|
| 1107 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1108 | *nrels_mag = 0; |
|---|
| 1109 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1110 | lm93_update_client(client); |
|---|
| 1111 | results[0] = data->prochot_max[nr]; |
|---|
| [4401] | 1112 | results[1] = data->block4[nr].cur; |
|---|
| [2672] | 1113 | results[2] = data->block4[nr].avg; |
|---|
| 1114 | *nrels_mag = 3; |
|---|
| 1115 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1116 | down(&data->update_lock); |
|---|
| 1117 | if (*nrels_mag >= 1) { |
|---|
| 1118 | data->prochot_max[nr] = LM93_PROCHOT_TO_REG(results[0]); |
|---|
| 1119 | lm93_write_byte(client, LM93_REG_PROCHOT_MAX(nr), |
|---|
| 1120 | data->prochot_max[nr]); |
|---|
| 1121 | } |
|---|
| 1122 | up(&data->update_lock); |
|---|
| 1123 | } |
|---|
| 1124 | } |
|---|
| 1125 | |
|---|
| 1126 | /* PROCHOT-OVERRIDE; 0-15, 0 is 6.25%, 15 is 99.88% |
|---|
| 1127 | * REG: (same) */ |
|---|
| 1128 | static u8 LM93_PROCHOT_OVERRIDE_TO_REG(int force1, int force2, long prochot) |
|---|
| 1129 | { |
|---|
| 1130 | u8 result = 0; |
|---|
| 1131 | |
|---|
| 1132 | result |= force1 ? 0x80 : 0x00; |
|---|
| 1133 | result |= force2 ? 0x40 : 0x00; |
|---|
| 1134 | prochot = SENSORS_LIMIT(prochot, 0, 15); |
|---|
| 1135 | result |= prochot; |
|---|
| 1136 | return result; |
|---|
| 1137 | } |
|---|
| 1138 | |
|---|
| 1139 | static void lm93_prochot_override(struct i2c_client *client, int operation, |
|---|
| 1140 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 1141 | { |
|---|
| 1142 | struct lm93_data *data = client->data; |
|---|
| 1143 | |
|---|
| 1144 | if (ctl_name != LM93_SYSCTL_PROCHOT_OVERRIDE) |
|---|
| 1145 | return; /* ERROR */ |
|---|
| 1146 | |
|---|
| 1147 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1148 | *nrels_mag = 0; |
|---|
| 1149 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1150 | lm93_update_client(client); |
|---|
| 1151 | results[0] = (data->prochot_override & 0x80) ? 1 : 0; |
|---|
| 1152 | results[1] = (data->prochot_override & 0x40) ? 1 : 0; |
|---|
| 1153 | results[2] = data->prochot_override & 0x0f; |
|---|
| 1154 | *nrels_mag = 3; |
|---|
| 1155 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1156 | |
|---|
| 1157 | /* grab old values */ |
|---|
| 1158 | int force2 = (data->prochot_override & 0x40) ? 1 : 0; |
|---|
| 1159 | int prochot = data->prochot_override & 0x0f; |
|---|
| 1160 | |
|---|
| 1161 | down(&data->update_lock); |
|---|
| 1162 | if (*nrels_mag >= 3) { |
|---|
| 1163 | data->prochot_override = LM93_PROCHOT_OVERRIDE_TO_REG( |
|---|
| 1164 | results[0], results[1], results[2]); |
|---|
| 1165 | } |
|---|
| 1166 | if (*nrels_mag == 2) { |
|---|
| 1167 | data->prochot_override = LM93_PROCHOT_OVERRIDE_TO_REG( |
|---|
| 1168 | results[0], results[1], prochot); |
|---|
| 1169 | } |
|---|
| 1170 | if (*nrels_mag == 1) { |
|---|
| 1171 | data->prochot_override = LM93_PROCHOT_OVERRIDE_TO_REG( |
|---|
| 1172 | results[0], force2, prochot); |
|---|
| 1173 | } |
|---|
| 1174 | if (*nrels_mag >= 1) { |
|---|
| 1175 | lm93_write_byte(client, LM93_REG_PROCHOT_OVERRIDE, |
|---|
| 1176 | data->prochot_override); |
|---|
| 1177 | } |
|---|
| 1178 | up(&data->update_lock); |
|---|
| 1179 | } |
|---|
| 1180 | } |
|---|
| 1181 | |
|---|
| 1182 | /* PROCHOT-INTERVAL: 73 - 37200 (1/100 seconds) |
|---|
| 1183 | * REG: 0-9 as mapped below */ |
|---|
| 1184 | static int lm93_interval_map[10] = { |
|---|
| 1185 | 73, 146, 290, 580, 1170, 2330, 4660, 9320, 18600, 37200, |
|---|
| 1186 | }; |
|---|
| 1187 | |
|---|
| 1188 | static int LM93_INTERVAL_FROM_REG(u8 reg) |
|---|
| 1189 | { |
|---|
| 1190 | return lm93_interval_map[reg & 0x0f]; |
|---|
| 1191 | } |
|---|
| 1192 | |
|---|
| 1193 | /* round up to nearest match */ |
|---|
| 1194 | static u8 LM93_INTERVAL_TO_REG(long interval) |
|---|
| 1195 | { |
|---|
| 1196 | int i; |
|---|
| 1197 | for (i = 0; i < 9; i++) |
|---|
| 1198 | if (interval <= lm93_interval_map[i]) |
|---|
| 1199 | break; |
|---|
| 1200 | |
|---|
| 1201 | /* can fall through with i==9 */ |
|---|
| 1202 | return (u8)i; |
|---|
| 1203 | } |
|---|
| 1204 | |
|---|
| 1205 | static void lm93_prochot_interval(struct i2c_client *client, int operation, |
|---|
| 1206 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 1207 | { |
|---|
| 1208 | struct lm93_data *data = client->data; |
|---|
| 1209 | |
|---|
| 1210 | if (ctl_name != LM93_SYSCTL_PROCHOT_INTERVAL) |
|---|
| 1211 | return; /* ERROR */ |
|---|
| 1212 | |
|---|
| 1213 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1214 | *nrels_mag = 2; |
|---|
| 1215 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1216 | lm93_update_client(client); |
|---|
| 1217 | results[0] = LM93_INTERVAL_FROM_REG( |
|---|
| 1218 | data->prochot_interval & 0x0f); |
|---|
| 1219 | results[1] = LM93_INTERVAL_FROM_REG( |
|---|
| 1220 | (data->prochot_interval & 0xf0) >> 4); |
|---|
| 1221 | *nrels_mag = 2; |
|---|
| 1222 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1223 | down(&data->update_lock); |
|---|
| 1224 | data->prochot_interval = lm93_read_byte(client, |
|---|
| 1225 | LM93_REG_PROCHOT_INTERVAL); |
|---|
| 1226 | if (*nrels_mag >= 2) { |
|---|
| 1227 | data->prochot_interval = |
|---|
| 1228 | (LM93_INTERVAL_TO_REG(results[1]) << 4) | |
|---|
| 1229 | (data->prochot_interval & 0x0f); |
|---|
| 1230 | } |
|---|
| 1231 | if (*nrels_mag >= 1) { |
|---|
| 1232 | data->prochot_interval = |
|---|
| 1233 | (data->prochot_interval & 0xf0) | |
|---|
| 1234 | LM93_INTERVAL_TO_REG(results[0]); |
|---|
| 1235 | lm93_write_byte(client, LM93_REG_PROCHOT_INTERVAL, |
|---|
| 1236 | data->prochot_interval); |
|---|
| 1237 | } |
|---|
| 1238 | up(&data->update_lock); |
|---|
| 1239 | } |
|---|
| 1240 | } |
|---|
| 1241 | |
|---|
| 1242 | /* PWM: 0-255 per sensors documentation |
|---|
| 1243 | REG: 0-13 as mapped below... right justified */ |
|---|
| 1244 | typedef enum { LM93_PWM_MAP_HI_FREQ, LM93_PWM_MAP_LO_FREQ } pwm_freq_t; |
|---|
| 1245 | static int lm93_pwm_map[2][14] = { |
|---|
| 1246 | { |
|---|
| 1247 | 0x00, /* 0.00% */ 0x40, /* 25.00% */ |
|---|
| 1248 | 0x50, /* 31.25% */ 0x60, /* 37.50% */ |
|---|
| 1249 | 0x70, /* 43.75% */ 0x80, /* 50.00% */ |
|---|
| 1250 | 0x90, /* 56.25% */ 0xa0, /* 62.50% */ |
|---|
| 1251 | 0xb0, /* 68.75% */ 0xc0, /* 75.00% */ |
|---|
| 1252 | 0xd0, /* 81.25% */ 0xe0, /* 87.50% */ |
|---|
| 1253 | 0xf0, /* 93.75% */ 0xff, /* 100.00% */ |
|---|
| 1254 | }, |
|---|
| 1255 | { |
|---|
| 1256 | 0x00, /* 0.00% */ 0x40, /* 25.00% */ |
|---|
| 1257 | 0x49, /* 28.57% */ 0x52, /* 32.14% */ |
|---|
| 1258 | 0x5b, /* 35.71% */ 0x64, /* 39.29% */ |
|---|
| 1259 | 0x6d, /* 42.86% */ 0x76, /* 46.43% */ |
|---|
| 1260 | 0x80, /* 50.00% */ 0x89, /* 53.57% */ |
|---|
| 1261 | 0x92, /* 57.14% */ 0xb6, /* 71.43% */ |
|---|
| 1262 | 0xdb, /* 85.71% */ 0xff, /* 100.00% */ |
|---|
| 1263 | }, |
|---|
| 1264 | }; |
|---|
| 1265 | |
|---|
| 1266 | static int LM93_PWM_FROM_REG(u8 reg, pwm_freq_t freq) |
|---|
| 1267 | { |
|---|
| 1268 | return lm93_pwm_map[freq][reg & 0x0f]; |
|---|
| 1269 | } |
|---|
| 1270 | |
|---|
| 1271 | /* round up to nearest match */ |
|---|
| 1272 | static u8 LM93_PWM_TO_REG(int pwm, pwm_freq_t freq) |
|---|
| 1273 | { |
|---|
| 1274 | int i; |
|---|
| 1275 | for (i = 0; i < 13; i++) |
|---|
| 1276 | if (pwm <= lm93_pwm_map[freq][i]) |
|---|
| 1277 | break; |
|---|
| 1278 | |
|---|
| 1279 | /* can fall through with i==13 */ |
|---|
| 1280 | return (u8)i; |
|---|
| 1281 | } |
|---|
| 1282 | |
|---|
| 1283 | static void lm93_pwm(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1284 | int *nrels_mag, long *results) |
|---|
| 1285 | { |
|---|
| 1286 | struct lm93_data *data = client->data; |
|---|
| 1287 | int nr = ctl_name - LM93_SYSCTL_PWM1; |
|---|
| 1288 | u8 ctl2, ctl4; |
|---|
| 1289 | |
|---|
| 1290 | if (0 > nr || nr > 1) |
|---|
| 1291 | return; /* ERROR */ |
|---|
| 1292 | |
|---|
| 1293 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1294 | *nrels_mag = 0; |
|---|
| 1295 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1296 | lm93_update_client(client); |
|---|
| 1297 | ctl2 = data->block9[nr][LM93_PWM_CTL2]; |
|---|
| 1298 | ctl4 = data->block9[nr][LM93_PWM_CTL4]; |
|---|
| 1299 | results[1] = (ctl2 & 0x01) ? 1 : 0; |
|---|
| 1300 | ctl2 = ctl2 >> 4 & 0x0f; |
|---|
| 1301 | if (results[1]) /* show user commanded value if enabled */ |
|---|
| 1302 | results[0] = data->pwm_override[nr]; |
|---|
| 1303 | else /* show present h/w value if manual pwm disabled */ |
|---|
| 1304 | results[0] = LM93_PWM_FROM_REG(ctl2, (ctl4 & 0x07) ? |
|---|
| 1305 | LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ); |
|---|
| 1306 | *nrels_mag = 2; |
|---|
| 1307 | } |
|---|
| 1308 | else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1309 | if (*nrels_mag >= 1) { |
|---|
| 1310 | down(&data->update_lock); |
|---|
| 1311 | ctl2 = lm93_read_byte( |
|---|
| 1312 | client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2)); |
|---|
| 1313 | ctl4 = lm93_read_byte( |
|---|
| 1314 | client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); |
|---|
| 1315 | ctl2 = (ctl2 & 0x0f) | |
|---|
| 1316 | LM93_PWM_TO_REG(results[0], (ctl4 & 0x07) ? |
|---|
| 1317 | LM93_PWM_MAP_LO_FREQ : |
|---|
| 1318 | LM93_PWM_MAP_HI_FREQ) << 4; |
|---|
| 1319 | if (*nrels_mag >= 2) { |
|---|
| 1320 | if (results[1]) |
|---|
| 1321 | ctl2 |= 0x01; |
|---|
| 1322 | else |
|---|
| 1323 | ctl2 &= ~0x01; |
|---|
| 1324 | } |
|---|
| 1325 | /* save user commanded value */ |
|---|
| 1326 | data->pwm_override[nr] = |
|---|
| 1327 | LM93_PWM_FROM_REG(ctl2 >> 4 & 0x0f, |
|---|
| 1328 | (ctl4 & 0x07) ? LM93_PWM_MAP_LO_FREQ : |
|---|
| 1329 | LM93_PWM_MAP_HI_FREQ); |
|---|
| 1330 | lm93_write_byte(client, |
|---|
| 1331 | LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2), ctl2); |
|---|
| 1332 | up(&data->update_lock); |
|---|
| 1333 | } |
|---|
| 1334 | } |
|---|
| 1335 | } |
|---|
| 1336 | |
|---|
| 1337 | /* PWM FREQ: HZ |
|---|
| 1338 | REG: 0-7 as mapped below */ |
|---|
| 1339 | static int lm93_pwm_freq_map[8] = { |
|---|
| 1340 | 22500, 96, 84, 72, 60, 48, 36, 12 |
|---|
| 1341 | }; |
|---|
| 1342 | |
|---|
| 1343 | static int LM93_PWM_FREQ_FROM_REG(u8 reg) |
|---|
| 1344 | { |
|---|
| 1345 | return lm93_pwm_freq_map[reg & 0x07]; |
|---|
| 1346 | } |
|---|
| 1347 | |
|---|
| 1348 | /* round up to nearest match */ |
|---|
| 1349 | static u8 LM93_PWM_FREQ_TO_REG(int freq) |
|---|
| 1350 | { |
|---|
| 1351 | int i; |
|---|
| 1352 | for (i = 7; i > 0; i--) |
|---|
| 1353 | if (freq <= lm93_pwm_freq_map[i]) |
|---|
| 1354 | break; |
|---|
| 1355 | |
|---|
| 1356 | /* can fall through with i==0 */ |
|---|
| 1357 | return (u8)i; |
|---|
| 1358 | } |
|---|
| 1359 | |
|---|
| 1360 | /* helper function - must grab data->update_lock before calling |
|---|
| 1361 | fan is 0-3, indicating fan1-fan4 */ |
|---|
| 1362 | static void lm93_write_fan_smart_tach(struct i2c_client *client, |
|---|
| 1363 | struct lm93_data *data, int fan, long value) |
|---|
| 1364 | { |
|---|
| 1365 | /* insert the new mapping and write it out */ |
|---|
| 1366 | data->sf_tach_to_pwm = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM); |
|---|
| [2689] | 1367 | data->sf_tach_to_pwm &= ~(0x3 << fan * 2); |
|---|
| [2672] | 1368 | data->sf_tach_to_pwm |= value << fan * 2; |
|---|
| 1369 | lm93_write_byte(client, LM93_REG_SF_TACH_TO_PWM, data->sf_tach_to_pwm); |
|---|
| 1370 | |
|---|
| 1371 | /* insert the enable bit and write it out */ |
|---|
| 1372 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
|---|
| 1373 | if (value) |
|---|
| 1374 | data->sfc2 |= 1 << fan; |
|---|
| 1375 | else |
|---|
| [2689] | 1376 | data->sfc2 &= ~(1 << fan); |
|---|
| [2672] | 1377 | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); |
|---|
| 1378 | } |
|---|
| 1379 | |
|---|
| 1380 | /* helper function - must grab data->update_lock before calling |
|---|
| 1381 | pwm is 0-1, indicating pwm1-pwm2 |
|---|
| 1382 | this disables smart tach for all tach channels bound to the given pwm */ |
|---|
| 1383 | static void lm93_disable_fan_smart_tach(struct i2c_client *client, |
|---|
| 1384 | struct lm93_data *data, int pwm) |
|---|
| 1385 | { |
|---|
| 1386 | int mapping = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM); |
|---|
| 1387 | int mask; |
|---|
| 1388 | |
|---|
| 1389 | /* collapse the mapping into a mask of enable bits */ |
|---|
| 1390 | mapping = (mapping >> pwm) & 0x55; |
|---|
| 1391 | mask = mapping & 0x01; |
|---|
| 1392 | mask |= (mapping & 0x04) >> 1; |
|---|
| 1393 | mask |= (mapping & 0x10) >> 2; |
|---|
| 1394 | mask |= (mapping & 0x40) >> 3; |
|---|
| 1395 | |
|---|
| 1396 | /* disable smart tach according to the mask */ |
|---|
| 1397 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
|---|
| 1398 | data->sfc2 &= ~mask; |
|---|
| 1399 | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); |
|---|
| 1400 | } |
|---|
| 1401 | |
|---|
| 1402 | static void lm93_pwm_freq(struct i2c_client *client, int operation, |
|---|
| 1403 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 1404 | { |
|---|
| 1405 | struct lm93_data *data = client->data; |
|---|
| 1406 | int nr = ctl_name - LM93_SYSCTL_PWM1_FREQ; |
|---|
| 1407 | u8 ctl4; |
|---|
| 1408 | |
|---|
| 1409 | if (0 > nr || nr > 1) |
|---|
| 1410 | return; /* ERROR */ |
|---|
| 1411 | |
|---|
| 1412 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1413 | *nrels_mag = 0; |
|---|
| 1414 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1415 | lm93_update_client(client); |
|---|
| 1416 | ctl4 = data->block9[nr][LM93_PWM_CTL4]; |
|---|
| 1417 | results[0] = LM93_PWM_FREQ_FROM_REG(ctl4); |
|---|
| 1418 | *nrels_mag = 1; |
|---|
| 1419 | } |
|---|
| 1420 | else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1421 | if (*nrels_mag >= 1) { |
|---|
| 1422 | down(&data->update_lock); |
|---|
| 1423 | ctl4 = lm93_read_byte( client, |
|---|
| 1424 | LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); |
|---|
| 1425 | ctl4 = (ctl4 & 0xf8) | LM93_PWM_FREQ_TO_REG(results[0]); |
|---|
| 1426 | data->block9[nr][LM93_PWM_CTL4] = ctl4; |
|---|
| 1427 | |
|---|
| 1428 | /* ctl4 == 0 -> 22.5KHz -> disable smart tach */ |
|---|
| 1429 | if (!ctl4) |
|---|
| 1430 | lm93_disable_fan_smart_tach(client, data, nr); |
|---|
| 1431 | |
|---|
| 1432 | lm93_write_byte(client, |
|---|
| 1433 | LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4), ctl4); |
|---|
| 1434 | up(&data->update_lock); |
|---|
| 1435 | } |
|---|
| 1436 | } |
|---|
| 1437 | } |
|---|
| 1438 | |
|---|
| 1439 | /* GPIO: 0-255, GPIO0 is LSB |
|---|
| 1440 | * REG: inverted */ |
|---|
| 1441 | static unsigned LM93_GPI_FROM_REG(u8 reg) |
|---|
| 1442 | { |
|---|
| 1443 | return ~reg & 0xff; |
|---|
| 1444 | } |
|---|
| 1445 | |
|---|
| 1446 | static void lm93_gpio(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1447 | int *nrels_mag, long *results) |
|---|
| 1448 | { |
|---|
| 1449 | struct lm93_data *data = client->data; |
|---|
| 1450 | |
|---|
| 1451 | if (ctl_name != LM93_SYSCTL_GPIO) |
|---|
| 1452 | return; /* ERROR */ |
|---|
| 1453 | |
|---|
| 1454 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1455 | *nrels_mag = 0; |
|---|
| 1456 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1457 | lm93_update_client(client); |
|---|
| 1458 | results[0] = LM93_GPI_FROM_REG(data->gpi); |
|---|
| 1459 | *nrels_mag = 1; |
|---|
| 1460 | } |
|---|
| 1461 | } |
|---|
| 1462 | |
|---|
| 1463 | static void lm93_temp_auto_base(struct i2c_client *client, int operation, |
|---|
| 1464 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 1465 | { |
|---|
| 1466 | struct lm93_data *data = client->data; |
|---|
| 1467 | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_BASE; |
|---|
| 1468 | |
|---|
| 1469 | if (0 > nr || nr > 2) |
|---|
| 1470 | return; /* ERROR */ |
|---|
| 1471 | |
|---|
| 1472 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1473 | *nrels_mag = 1; |
|---|
| 1474 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1475 | lm93_update_client(client); |
|---|
| 1476 | results[0] = LM93_TEMP_FROM_REG(data->block10.base[nr]); |
|---|
| 1477 | *nrels_mag = 1; |
|---|
| 1478 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1479 | down(&data->update_lock); |
|---|
| 1480 | if (*nrels_mag >= 1) { |
|---|
| 1481 | data->block10.base[nr] = LM93_TEMP_TO_REG(results[0]); |
|---|
| 1482 | lm93_write_byte(client, LM93_REG_TEMP_BASE(nr), |
|---|
| 1483 | data->block10.base[nr]); |
|---|
| 1484 | } |
|---|
| 1485 | up(&data->update_lock); |
|---|
| 1486 | } |
|---|
| 1487 | } |
|---|
| 1488 | |
|---|
| 1489 | static void lm93_temp_auto_boost(struct i2c_client *client, int operation, |
|---|
| 1490 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 1491 | { |
|---|
| 1492 | struct lm93_data *data = client->data; |
|---|
| [2671] | 1493 | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_BOOST; |
|---|
| 1494 | |
|---|
| 1495 | if (0 > nr || nr > 2) |
|---|
| 1496 | return; /* ERROR */ |
|---|
| 1497 | |
|---|
| 1498 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1499 | *nrels_mag = 1; |
|---|
| 1500 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1501 | lm93_update_client(client); |
|---|
| 1502 | results[0] = LM93_TEMP_FROM_REG(data->boost[nr]); |
|---|
| 1503 | *nrels_mag = 1; |
|---|
| 1504 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1505 | down(&data->update_lock); |
|---|
| 1506 | if (*nrels_mag >= 1) { |
|---|
| 1507 | data->boost[nr] = LM93_TEMP_TO_REG(results[0]); |
|---|
| 1508 | lm93_write_byte(client, LM93_REG_BOOST(nr), |
|---|
| 1509 | data->boost[nr]); |
|---|
| 1510 | } |
|---|
| 1511 | up(&data->update_lock); |
|---|
| 1512 | } |
|---|
| 1513 | |
|---|
| 1514 | } |
|---|
| 1515 | |
|---|
| 1516 | static u8 LM93_AUTO_BOOST_HYST_TO_REG(struct lm93_data *data, long hyst, |
|---|
| 1517 | int nr, int mode) |
|---|
| 1518 | { |
|---|
| 1519 | u8 reg = LM93_TEMP_OFFSET_TO_REG( |
|---|
| 1520 | (LM93_TEMP_FROM_REG(data->boost[nr]) - hyst), mode); |
|---|
| 1521 | |
|---|
| 1522 | switch (nr) { |
|---|
| 1523 | case 0: |
|---|
| 1524 | reg = (data->boost_hyst[0] & 0xf0) | (reg & 0x0f); |
|---|
| 1525 | break; |
|---|
| 1526 | case 1: |
|---|
| 1527 | reg = (reg << 4 & 0xf0) | (data->boost_hyst[0] & 0x0f); |
|---|
| 1528 | break; |
|---|
| 1529 | case 2: |
|---|
| 1530 | reg = (data->boost_hyst[1] & 0xf0) | (reg & 0x0f); |
|---|
| 1531 | break; |
|---|
| 1532 | case 3: |
|---|
| 1533 | default: |
|---|
| 1534 | reg = (reg << 4 & 0xf0) | (data->boost_hyst[1] & 0x0f); |
|---|
| 1535 | break; |
|---|
| 1536 | } |
|---|
| 1537 | |
|---|
| 1538 | return reg; |
|---|
| 1539 | } |
|---|
| 1540 | |
|---|
| 1541 | static int LM93_AUTO_BOOST_HYST_FROM_REGS(struct lm93_data *data, int nr, |
|---|
| 1542 | int mode) |
|---|
| 1543 | { |
|---|
| 1544 | u8 reg; |
|---|
| 1545 | |
|---|
| 1546 | switch (nr) { |
|---|
| 1547 | case 0: |
|---|
| 1548 | reg = data->boost_hyst[0] & 0x0f; |
|---|
| 1549 | break; |
|---|
| 1550 | case 1: |
|---|
| 1551 | reg = data->boost_hyst[0] >> 4 & 0x0f; |
|---|
| 1552 | break; |
|---|
| 1553 | case 2: |
|---|
| 1554 | reg = data->boost_hyst[1] & 0x0f; |
|---|
| 1555 | break; |
|---|
| 1556 | case 3: |
|---|
| 1557 | default: |
|---|
| 1558 | reg = data->boost_hyst[1] >> 4 & 0x0f; |
|---|
| 1559 | break; |
|---|
| 1560 | } |
|---|
| 1561 | |
|---|
| 1562 | return LM93_TEMP_FROM_REG(data->boost[nr]) - |
|---|
| 1563 | LM93_TEMP_OFFSET_FROM_REG(reg, mode); |
|---|
| 1564 | } |
|---|
| 1565 | |
|---|
| [2672] | 1566 | static void lm93_temp_auto_boost_hyst(struct i2c_client *client, int operation, |
|---|
| [2671] | 1567 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 1568 | { |
|---|
| 1569 | struct lm93_data *data = client->data; |
|---|
| 1570 | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_BOOST_HYST; |
|---|
| 1571 | |
|---|
| 1572 | if (0 > nr || nr > 2) |
|---|
| 1573 | return; /* ERROR */ |
|---|
| 1574 | |
|---|
| 1575 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1576 | *nrels_mag = 1; |
|---|
| 1577 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1578 | int mode; |
|---|
| 1579 | lm93_update_client(client); |
|---|
| 1580 | |
|---|
| 1581 | /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */ |
|---|
| 1582 | mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); |
|---|
| 1583 | |
|---|
| 1584 | results[0] = LM93_AUTO_BOOST_HYST_FROM_REGS(data, nr, mode); |
|---|
| 1585 | *nrels_mag = 1; |
|---|
| 1586 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1587 | if (*nrels_mag >= 1) { |
|---|
| 1588 | down(&data->update_lock); |
|---|
| 1589 | |
|---|
| 1590 | /* force 0.5C/bit mode */ |
|---|
| 1591 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
|---|
| 1592 | data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); |
|---|
| 1593 | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); |
|---|
| 1594 | |
|---|
| 1595 | data->boost_hyst[nr/2] = |
|---|
| 1596 | LM93_AUTO_BOOST_HYST_TO_REG(data, |
|---|
| 1597 | results[0], nr, 1); |
|---|
| 1598 | lm93_write_byte(client, LM93_REG_BOOST_HYST(nr), |
|---|
| 1599 | data->boost_hyst[nr/2]); |
|---|
| 1600 | up(&data->update_lock); |
|---|
| 1601 | } |
|---|
| 1602 | } |
|---|
| 1603 | } |
|---|
| 1604 | |
|---|
| [2672] | 1605 | static void lm93_temp_auto_pwm_min(struct i2c_client *client, int operation, |
|---|
| [2671] | 1606 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 1607 | { |
|---|
| 1608 | struct lm93_data *data = client->data; |
|---|
| 1609 | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_PWM_MIN; |
|---|
| 1610 | u8 reg, ctl4; |
|---|
| 1611 | |
|---|
| 1612 | if (0 > nr || nr > 2) |
|---|
| 1613 | return; /* ERROR */ |
|---|
| 1614 | |
|---|
| 1615 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1616 | *nrels_mag = 0; |
|---|
| 1617 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1618 | lm93_update_client(client); |
|---|
| 1619 | reg = data->auto_pwm_min_hyst[nr/2] >> 4 & 0x0f; |
|---|
| 1620 | ctl4 = data->block9[nr][LM93_PWM_CTL4]; |
|---|
| 1621 | results[0] = LM93_PWM_FROM_REG(reg, (ctl4 & 0x07) ? |
|---|
| 1622 | LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ); |
|---|
| 1623 | *nrels_mag = 1; |
|---|
| 1624 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1625 | if (*nrels_mag >= 1) { |
|---|
| 1626 | down(&data->update_lock); |
|---|
| 1627 | reg = lm93_read_byte(client, LM93_REG_PWM_MIN_HYST(nr)); |
|---|
| 1628 | ctl4 = lm93_read_byte( |
|---|
| 1629 | client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); |
|---|
| 1630 | reg = (reg & 0x0f) | |
|---|
| 1631 | LM93_PWM_TO_REG(results[0], (ctl4 & 0x07) ? |
|---|
| 1632 | LM93_PWM_MAP_LO_FREQ : |
|---|
| 1633 | LM93_PWM_MAP_HI_FREQ) << 4; |
|---|
| 1634 | |
|---|
| 1635 | data->auto_pwm_min_hyst[nr/2] = reg; |
|---|
| 1636 | lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg); |
|---|
| 1637 | up(&data->update_lock); |
|---|
| 1638 | } |
|---|
| 1639 | } |
|---|
| 1640 | } |
|---|
| 1641 | |
|---|
| [2672] | 1642 | static void lm93_temp_auto_offset_hyst(struct i2c_client *client, int operation, |
|---|
| [2671] | 1643 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 1644 | { |
|---|
| 1645 | struct lm93_data *data = client->data; |
|---|
| 1646 | int nr = ctl_name - LM93_SYSCTL_TEMP1_AUTO_OFFSET_HYST; |
|---|
| 1647 | |
|---|
| 1648 | if (0 > nr || nr > 2) |
|---|
| 1649 | return; /* ERROR */ |
|---|
| 1650 | |
|---|
| 1651 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1652 | *nrels_mag = 1; |
|---|
| 1653 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1654 | int mode; |
|---|
| 1655 | lm93_update_client(client); |
|---|
| 1656 | |
|---|
| 1657 | /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */ |
|---|
| 1658 | mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); |
|---|
| 1659 | |
|---|
| 1660 | results[0] = LM93_TEMP_OFFSET_FROM_REG( |
|---|
| 1661 | data->auto_pwm_min_hyst[nr/2], mode); |
|---|
| 1662 | |
|---|
| 1663 | *nrels_mag = 1; |
|---|
| 1664 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1665 | if (*nrels_mag >= 1) { |
|---|
| 1666 | u8 reg; |
|---|
| 1667 | down(&data->update_lock); |
|---|
| 1668 | |
|---|
| 1669 | /* force 0.5C/bit mode */ |
|---|
| 1670 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); |
|---|
| 1671 | data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); |
|---|
| 1672 | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); |
|---|
| 1673 | |
|---|
| 1674 | reg = data->auto_pwm_min_hyst[nr/2]; |
|---|
| 1675 | reg = (reg & 0xf0) | |
|---|
| 1676 | (LM93_TEMP_OFFSET_TO_REG(results[0], 1) & 0x0f); |
|---|
| 1677 | |
|---|
| 1678 | data->auto_pwm_min_hyst[nr/2] = reg; |
|---|
| 1679 | lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg); |
|---|
| 1680 | up(&data->update_lock); |
|---|
| 1681 | } |
|---|
| 1682 | } |
|---|
| 1683 | } |
|---|
| 1684 | |
|---|
| [2653] | 1685 | /* some tedious bit-twiddling here to deal with the register format: |
|---|
| 1686 | |
|---|
| 1687 | data->sf_tach_to_pwm: (tach to pwm mapping bits) |
|---|
| 1688 | |
|---|
| 1689 | bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|
| 1690 | T4:P2 T4:P1 T3:P2 T3:P1 T2:P2 T2:P1 T1:P2 T1:P1 |
|---|
| 1691 | |
|---|
| 1692 | data->sfc2: (enable bits) |
|---|
| 1693 | |
|---|
| 1694 | bit | 3 | 2 | 1 | 0 |
|---|
| 1695 | T4 T3 T2 T1 |
|---|
| 1696 | */ |
|---|
| [2660] | 1697 | |
|---|
| [2672] | 1698 | static void lm93_fan_smart_tach(struct i2c_client *client, int operation, |
|---|
| 1699 | int ctl_name, int *nrels_mag, long *results) |
|---|
| [2660] | 1700 | { |
|---|
| [2653] | 1701 | struct lm93_data *data = client->data; |
|---|
| 1702 | int nr = ctl_name - LM93_SYSCTL_FAN1_SMART_TACH; |
|---|
| 1703 | |
|---|
| 1704 | if (0 > nr || nr > 3) |
|---|
| 1705 | return; /* ERROR */ |
|---|
| 1706 | |
|---|
| 1707 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1708 | *nrels_mag = 0; |
|---|
| 1709 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| [2746] | 1710 | int mapping; |
|---|
| 1711 | |
|---|
| [2653] | 1712 | lm93_update_client(client); |
|---|
| 1713 | |
|---|
| 1714 | /* extract the relevant mapping */ |
|---|
| [2746] | 1715 | mapping = (data->sf_tach_to_pwm >> (nr * 2)) & 0x03; |
|---|
| [2653] | 1716 | |
|---|
| 1717 | /* if there's a mapping and it's enabled */ |
|---|
| 1718 | if (mapping && ((data->sfc2 >> nr) & 0x01)) |
|---|
| 1719 | results[0] = mapping; |
|---|
| 1720 | else |
|---|
| 1721 | results[0] = 0; |
|---|
| 1722 | |
|---|
| 1723 | *nrels_mag = 1; |
|---|
| 1724 | |
|---|
| 1725 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1726 | if (*nrels_mag >= 1) { |
|---|
| 1727 | down(&data->update_lock); |
|---|
| 1728 | |
|---|
| 1729 | /* sanity test, ignore the write otherwise */ |
|---|
| 1730 | if (0 <= results[0] && results[0] <= 2) { |
|---|
| 1731 | |
|---|
| [2660] | 1732 | /* can't enable if pwm freq is 22.5KHz */ |
|---|
| 1733 | if (results[0]) { |
|---|
| 1734 | u8 ctl4 = lm93_read_byte(client, |
|---|
| 1735 | LM93_REG_PWM_CTL(results[0]-1, |
|---|
| 1736 | LM93_PWM_CTL4)); |
|---|
| 1737 | if ((ctl4 & 0x07) == 0) |
|---|
| 1738 | results[0] = 0; |
|---|
| 1739 | } |
|---|
| [2653] | 1740 | |
|---|
| [2660] | 1741 | lm93_write_fan_smart_tach(client, data, nr, |
|---|
| 1742 | results[0]); |
|---|
| [2653] | 1743 | } |
|---|
| 1744 | up(&data->update_lock); |
|---|
| 1745 | } |
|---|
| 1746 | } |
|---|
| 1747 | } |
|---|
| 1748 | |
|---|
| [2672] | 1749 | static void lm93_prochot_short(struct i2c_client *client, int operation, |
|---|
| 1750 | int ctl_name, int *nrels_mag, long *results) |
|---|
| [2653] | 1751 | { |
|---|
| 1752 | struct lm93_data *data = client->data; |
|---|
| 1753 | |
|---|
| 1754 | if (ctl_name != LM93_SYSCTL_PROCHOT_SHORT) |
|---|
| 1755 | return; /* ERROR */ |
|---|
| 1756 | |
|---|
| 1757 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1758 | *nrels_mag = 0; |
|---|
| 1759 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1760 | lm93_update_client(client); |
|---|
| 1761 | results[0] = (data->config & 0x10) ? 1 : 0; |
|---|
| 1762 | *nrels_mag = 1; |
|---|
| 1763 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1764 | down(&data->update_lock); |
|---|
| 1765 | if (*nrels_mag >= 1) { |
|---|
| 1766 | if (results[0]) |
|---|
| 1767 | data->config |= 0x10; |
|---|
| 1768 | else |
|---|
| 1769 | data->config &= ~0x10; |
|---|
| 1770 | lm93_write_byte(client, LM93_REG_CONFIG, data->config); |
|---|
| 1771 | } |
|---|
| 1772 | up(&data->update_lock); |
|---|
| 1773 | } |
|---|
| 1774 | } |
|---|
| 1775 | |
|---|
| [2672] | 1776 | static void lm93_vrdhot(struct i2c_client *client, int operation, |
|---|
| [2660] | 1777 | int ctl_name, int *nrels_mag, long *results) |
|---|
| [2653] | 1778 | { |
|---|
| [2660] | 1779 | struct lm93_data *data = client->data; |
|---|
| 1780 | int nr = ctl_name - LM93_SYSCTL_VRDHOT1; |
|---|
| 1781 | |
|---|
| 1782 | if (0 > nr || nr > 1) |
|---|
| 1783 | return; /* ERROR */ |
|---|
| 1784 | |
|---|
| 1785 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1786 | *nrels_mag = 0; |
|---|
| 1787 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1788 | lm93_update_client(client); |
|---|
| 1789 | results[0] = data->block1.host_status_1 & (1 << (nr+4)) ? 1 : 0; |
|---|
| [2653] | 1790 | *nrels_mag = 1; |
|---|
| 1791 | } |
|---|
| 1792 | } |
|---|
| 1793 | |
|---|
| [2672] | 1794 | static void lm93_pwm_auto_chan(struct i2c_client *client, int operation, |
|---|
| 1795 | int ctl_name, int *nrels_mag, long *results) |
|---|
| [2660] | 1796 | { |
|---|
| 1797 | struct lm93_data *data = client->data; |
|---|
| [2671] | 1798 | int nr = ctl_name - LM93_SYSCTL_PWM1_AUTO_CHANNELS; |
|---|
| 1799 | |
|---|
| 1800 | if (0 > nr || nr > 1) |
|---|
| 1801 | return; /* ERROR */ |
|---|
| 1802 | |
|---|
| 1803 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1804 | *nrels_mag = 0; |
|---|
| 1805 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1806 | lm93_update_client(client); |
|---|
| 1807 | results[0] = data->block9[nr][LM93_PWM_CTL1]; |
|---|
| 1808 | *nrels_mag = 1; |
|---|
| 1809 | } |
|---|
| 1810 | else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1811 | if (*nrels_mag >= 1) { |
|---|
| 1812 | down(&data->update_lock); |
|---|
| 1813 | data->block9[nr][LM93_PWM_CTL1] = |
|---|
| 1814 | SENSORS_LIMIT(results[0], 0, 255); |
|---|
| 1815 | lm93_write_byte(client, |
|---|
| 1816 | LM93_REG_PWM_CTL(nr,LM93_PWM_CTL1), |
|---|
| 1817 | data->block9[nr][LM93_PWM_CTL1]); |
|---|
| 1818 | up(&data->update_lock); |
|---|
| 1819 | } |
|---|
| 1820 | } |
|---|
| 1821 | } |
|---|
| 1822 | |
|---|
| [2672] | 1823 | static void lm93_pwm_auto_spinup_min(struct i2c_client *client, int operation, |
|---|
| [2671] | 1824 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 1825 | { |
|---|
| 1826 | struct lm93_data *data = client->data; |
|---|
| 1827 | int nr = ctl_name - LM93_SYSCTL_PWM1_AUTO_SPINUP_MIN; |
|---|
| 1828 | u8 ctl3, ctl4; |
|---|
| 1829 | |
|---|
| 1830 | if (0 > nr || nr > 1) |
|---|
| [2672] | 1831 | return; /* ERROR */ |
|---|
| 1832 | |
|---|
| [2671] | 1833 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| [2672] | 1834 | *nrels_mag = 0; |
|---|
| [2671] | 1835 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1836 | lm93_update_client(client); |
|---|
| 1837 | ctl3 = data->block9[nr][LM93_PWM_CTL3]; |
|---|
| 1838 | ctl4 = data->block9[nr][LM93_PWM_CTL4]; |
|---|
| 1839 | results[0] = LM93_PWM_FROM_REG(ctl3 & 0x0f, (ctl4 & 0x07) ? |
|---|
| 1840 | LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ); |
|---|
| 1841 | *nrels_mag = 1; |
|---|
| 1842 | } |
|---|
| 1843 | else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1844 | if (*nrels_mag >= 1) { |
|---|
| 1845 | down(&data->update_lock); |
|---|
| 1846 | ctl3 = lm93_read_byte(client, |
|---|
| 1847 | LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3)); |
|---|
| 1848 | ctl4 = lm93_read_byte(client, |
|---|
| 1849 | LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4)); |
|---|
| 1850 | ctl3 = (ctl3 & 0xf0) | |
|---|
| 1851 | LM93_PWM_TO_REG(results[0], (ctl4 & 0x07) ? |
|---|
| 1852 | LM93_PWM_MAP_LO_FREQ : |
|---|
| 1853 | LM93_PWM_MAP_HI_FREQ); |
|---|
| 1854 | data->block9[nr][LM93_PWM_CTL3] = ctl3; |
|---|
| 1855 | lm93_write_byte(client, |
|---|
| 1856 | LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3); |
|---|
| 1857 | up(&data->update_lock); |
|---|
| 1858 | } |
|---|
| 1859 | } |
|---|
| 1860 | } |
|---|
| 1861 | |
|---|
| 1862 | /* TIME: 1/100 seconds |
|---|
| 1863 | * REG: 0-7 as mapped below */ |
|---|
| 1864 | static int lm93_spinup_time_map[8] = { |
|---|
| 1865 | 0, 10, 25, 40, 70, 100, 200, 400, |
|---|
| 1866 | }; |
|---|
| 1867 | |
|---|
| 1868 | static int LM93_SPINUP_TIME_FROM_REG(u8 reg) |
|---|
| 1869 | { |
|---|
| 1870 | return lm93_spinup_time_map[reg >> 5 & 0x07]; |
|---|
| 1871 | } |
|---|
| 1872 | |
|---|
| 1873 | /* round up to nearest match */ |
|---|
| 1874 | static u8 LM93_SPINUP_TIME_TO_REG(int time) |
|---|
| 1875 | { |
|---|
| 1876 | int i; |
|---|
| 1877 | for (i = 0; i < 7; i++) |
|---|
| 1878 | if (time <= lm93_spinup_time_map[i]) |
|---|
| 1879 | break; |
|---|
| 1880 | |
|---|
| 1881 | /* can fall through with i==8 */ |
|---|
| 1882 | return (u8)i; |
|---|
| 1883 | } |
|---|
| 1884 | |
|---|
| [2672] | 1885 | static void lm93_pwm_auto_spinup_time(struct i2c_client *client, int operation, |
|---|
| [2671] | 1886 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 1887 | { |
|---|
| 1888 | struct lm93_data *data = client->data; |
|---|
| 1889 | int nr = ctl_name - LM93_SYSCTL_PWM1_AUTO_SPINUP_TIME; |
|---|
| 1890 | |
|---|
| 1891 | if (0 > nr || nr > 1) |
|---|
| [2672] | 1892 | return; /* ERROR */ |
|---|
| 1893 | |
|---|
| [2671] | 1894 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| [2672] | 1895 | *nrels_mag = 2; |
|---|
| [2671] | 1896 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1897 | lm93_update_client(client); |
|---|
| 1898 | results[0] = LM93_SPINUP_TIME_FROM_REG( |
|---|
| 1899 | data->block9[nr][LM93_PWM_CTL3]); |
|---|
| 1900 | *nrels_mag = 1; |
|---|
| 1901 | } |
|---|
| 1902 | else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1903 | if (*nrels_mag >= 1) { |
|---|
| 1904 | u8 ctl3; |
|---|
| 1905 | down(&data->update_lock); |
|---|
| 1906 | ctl3 = lm93_read_byte(client, |
|---|
| 1907 | LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3)); |
|---|
| 1908 | ctl3 = (ctl3 & 0x1f) | (LM93_SPINUP_TIME_TO_REG( |
|---|
| 1909 | results[0]) << 5 & 0xe0); |
|---|
| 1910 | data->block9[nr][LM93_PWM_CTL3] = ctl3; |
|---|
| 1911 | lm93_write_byte(client, |
|---|
| 1912 | LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3); |
|---|
| 1913 | up(&data->update_lock); |
|---|
| 1914 | } |
|---|
| 1915 | } |
|---|
| 1916 | } |
|---|
| 1917 | |
|---|
| 1918 | #define LM93_RAMP_MIN 0 |
|---|
| 1919 | #define LM93_RAMP_MAX 75 |
|---|
| 1920 | |
|---|
| 1921 | /* RAMP: 1/100 seconds |
|---|
| 1922 | REG: 50mS/bit 4-bits right justified */ |
|---|
| 1923 | static u8 LM93_RAMP_TO_REG(int ramp) |
|---|
| 1924 | { |
|---|
| 1925 | ramp = SENSORS_LIMIT(ramp, LM93_RAMP_MIN, LM93_RAMP_MAX); |
|---|
| 1926 | return (u8)((ramp + 2) / 5); |
|---|
| 1927 | } |
|---|
| 1928 | |
|---|
| 1929 | static int LM93_RAMP_FROM_REG(u8 reg) |
|---|
| 1930 | { |
|---|
| 1931 | return (reg & 0x0f) * 5; |
|---|
| 1932 | } |
|---|
| 1933 | |
|---|
| [2672] | 1934 | static void lm93_pwm_auto_ramp(struct i2c_client *client, int operation, |
|---|
| [2671] | 1935 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 1936 | { |
|---|
| 1937 | struct lm93_data *data = client->data; |
|---|
| 1938 | |
|---|
| 1939 | if (!(ctl_name == LM93_SYSCTL_PWM_AUTO_PROCHOT_RAMP || |
|---|
| 1940 | ctl_name == LM93_SYSCTL_PWM_AUTO_VRDHOT_RAMP)) |
|---|
| [2672] | 1941 | return; /* ERROR */ |
|---|
| 1942 | |
|---|
| [2671] | 1943 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| [2672] | 1944 | *nrels_mag = 2; |
|---|
| [2671] | 1945 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1946 | lm93_update_client(client); |
|---|
| 1947 | if (ctl_name == LM93_SYSCTL_PWM_AUTO_PROCHOT_RAMP) |
|---|
| 1948 | results[0] = LM93_RAMP_FROM_REG( |
|---|
| 1949 | data->pwm_ramp_ctl >> 4 & 0x0f); |
|---|
| 1950 | else |
|---|
| 1951 | results[0] = LM93_RAMP_FROM_REG( |
|---|
| 1952 | data->pwm_ramp_ctl & 0x0f); |
|---|
| 1953 | *nrels_mag = 1; |
|---|
| 1954 | } |
|---|
| 1955 | else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1956 | if (*nrels_mag >= 1) { |
|---|
| 1957 | u8 ramp; |
|---|
| 1958 | down(&data->update_lock); |
|---|
| 1959 | ramp = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL); |
|---|
| 1960 | if (ctl_name == LM93_SYSCTL_PWM_AUTO_PROCHOT_RAMP) |
|---|
| 1961 | ramp = (ramp & 0x0f) | (LM93_RAMP_TO_REG( |
|---|
| 1962 | results[0]) << 4 & 0xf0); |
|---|
| 1963 | else |
|---|
| 1964 | ramp = (ramp & 0xf0) | (LM93_RAMP_TO_REG( |
|---|
| 1965 | results[0]) & 0x0f); |
|---|
| 1966 | lm93_write_byte(client, LM93_REG_PWM_RAMP_CTL, ramp); |
|---|
| 1967 | up(&data->update_lock); |
|---|
| 1968 | } |
|---|
| 1969 | } |
|---|
| 1970 | } |
|---|
| 1971 | |
|---|
| [2672] | 1972 | /* These files are created for each detected LM93. This is just a template; |
|---|
| 1973 | though at first sight, you might think we could use a statically |
|---|
| 1974 | allocated list, we need some way to get back to the parent - which |
|---|
| 1975 | is done through one of the 'extra' fields which are initialized |
|---|
| 1976 | when a new copy is allocated. */ |
|---|
| 1977 | |
|---|
| 1978 | #define LM93_SYSCTL_IN(nr) {LM93_SYSCTL_IN##nr, "in" #nr, NULL, 0, \ |
|---|
| 1979 | 0644, NULL, &i2c_proc_real, &i2c_sysctl_real, NULL, &lm93_in} |
|---|
| 1980 | #define LM93_SYSCTL_TEMP(nr) {LM93_SYSCTL_TEMP##nr, "temp" #nr, NULL, 0, \ |
|---|
| 1981 | 0644, NULL, &i2c_proc_real, &i2c_sysctl_real, NULL, &lm93_temp} |
|---|
| 1982 | #define LM93_SYSCTL_TEMP_AUTO_BASE(nr) {LM93_SYSCTL_TEMP##nr##_AUTO_BASE, \ |
|---|
| 1983 | "temp" #nr "_auto_base", NULL, 0, 0644, NULL, &i2c_proc_real, \ |
|---|
| 1984 | &i2c_sysctl_real, NULL, &lm93_temp_auto_base} |
|---|
| 1985 | #define LM93_SYSCTL_TEMP_AUTO_OFFSETS(nr) {LM93_SYSCTL_TEMP##nr##_AUTO_OFFSETS,\ |
|---|
| 1986 | "temp" #nr "_auto_offsets", NULL, 0, 0644, NULL, &i2c_proc_real, \ |
|---|
| 1987 | &i2c_sysctl_real, NULL, &lm93_temp_auto_offsets} |
|---|
| 1988 | #define LM93_SYSCTL_TEMP_AUTO_BOOST(nr) { LM93_SYSCTL_TEMP##nr##_AUTO_BOOST, \ |
|---|
| 1989 | "temp" #nr "_auto_boost", NULL, 0, 0644, NULL, &i2c_proc_real, \ |
|---|
| 1990 | &i2c_sysctl_real, NULL, &lm93_temp_auto_boost} |
|---|
| 1991 | #define LM93_SYSCTL_TEMP_AUTO_BOOST_HYST(nr) { \ |
|---|
| 1992 | LM93_SYSCTL_TEMP##nr##_AUTO_BOOST_HYST, "temp" #nr "_auto_boost_hyst", \ |
|---|
| 1993 | NULL, 0, 0644, NULL, &i2c_proc_real, &i2c_sysctl_real, NULL, \ |
|---|
| 1994 | &lm93_temp_auto_boost_hyst} |
|---|
| 1995 | #define LM93_SYSCTL_TEMP_AUTO_PWM_MIN(nr) { \ |
|---|
| 1996 | LM93_SYSCTL_TEMP##nr##_AUTO_PWM_MIN, "temp" #nr "_auto_pwm_min", \ |
|---|
| 1997 | NULL, 0, 0644, NULL, &i2c_proc_real, &i2c_sysctl_real, NULL, \ |
|---|
| 1998 | &lm93_temp_auto_pwm_min} |
|---|
| 1999 | #define LM93_SYSCTL_TEMP_AUTO_OFFSET_HYST(nr) { \ |
|---|
| 2000 | LM93_SYSCTL_TEMP##nr##_AUTO_OFFSET_HYST,"temp" #nr "_auto_offset_hyst",\ |
|---|
| 2001 | NULL, 0, 0644, NULL, &i2c_proc_real, &i2c_sysctl_real, NULL, \ |
|---|
| 2002 | &lm93_temp_auto_offset_hyst} |
|---|
| 2003 | #define LM93_SYSCTL_PWM(nr) {LM93_SYSCTL_PWM##nr, "pwm" #nr, NULL, 0, \ |
|---|
| 2004 | 0644, NULL, &i2c_proc_real, &i2c_sysctl_real, NULL, &lm93_pwm} |
|---|
| 2005 | #define LM93_SYSCTL_PWM_FREQ(nr) {LM93_SYSCTL_PWM##nr##_FREQ, \ |
|---|
| 2006 | "pwm" #nr "_freq", NULL, 0, 0644, NULL, &i2c_proc_real, \ |
|---|
| 2007 | &i2c_sysctl_real, NULL, &lm93_pwm_freq} |
|---|
| 2008 | #define LM93_SYSCTL_PWM_AUTO_CHAN(nr) {LM93_SYSCTL_PWM##nr##_AUTO_CHANNELS, \ |
|---|
| 2009 | "pwm" #nr "_auto_channels", NULL, 0, 0644, NULL, &i2c_proc_real, \ |
|---|
| 2010 | &i2c_sysctl_real, NULL, &lm93_pwm_auto_chan} |
|---|
| 2011 | #define LM93_SYSCTL_PWM_AUTO_SPINUP_MIN(nr) { \ |
|---|
| 2012 | LM93_SYSCTL_PWM##nr##_AUTO_SPINUP_MIN, "pwm" #nr "_auto_spinup_min", \ |
|---|
| 2013 | NULL, 0, 0644, NULL, &i2c_proc_real, &i2c_sysctl_real, NULL, \ |
|---|
| 2014 | &lm93_pwm_auto_spinup_min} |
|---|
| 2015 | #define LM93_SYSCTL_PWM_AUTO_SPINUP_TIME(nr) { \ |
|---|
| 2016 | LM93_SYSCTL_PWM##nr##_AUTO_SPINUP_TIME, "pwm" #nr "_auto_spinup_time", \ |
|---|
| 2017 | NULL, 0, 0644, NULL, &i2c_proc_real, &i2c_sysctl_real, NULL, \ |
|---|
| 2018 | &lm93_pwm_auto_spinup_time} |
|---|
| 2019 | #define LM93_SYSCTL_FAN(nr) {LM93_SYSCTL_FAN##nr, "fan" #nr, NULL, 0, \ |
|---|
| 2020 | 0644, NULL, &i2c_proc_real, &i2c_sysctl_real, NULL, &lm93_fan} |
|---|
| 2021 | #define LM93_SYSCTL_VID(nr) {LM93_SYSCTL_VID##nr, "vid" #nr, NULL, 0, \ |
|---|
| 2022 | 0444, NULL, &i2c_proc_real, &i2c_sysctl_real, NULL, &lm93_vid} |
|---|
| 2023 | #define LM93_SYSCTL_PROCHOT(nr) {LM93_SYSCTL_PROCHOT##nr, "prochot" #nr, NULL, \ |
|---|
| 2024 | 0, 0644, NULL, &i2c_proc_real, &i2c_sysctl_real, NULL, &lm93_prochot} |
|---|
| 2025 | #define LM93_SYSCTL_VRDHOT(nr) {LM93_SYSCTL_VRDHOT##nr, "vrdhot" #nr, NULL, \ |
|---|
| 2026 | 0, 0444, NULL, &i2c_proc_real, &i2c_sysctl_real, NULL, &lm93_vrdhot} |
|---|
| 2027 | #define LM93_SYSCTL_FAN_SMART_TACH(nr) {LM93_SYSCTL_FAN##nr##_SMART_TACH, \ |
|---|
| 2028 | "fan" #nr "_smart_tach", NULL, 0, 0644, NULL, &i2c_proc_real, \ |
|---|
| 2029 | &i2c_sysctl_real, NULL, &lm93_fan_smart_tach} |
|---|
| 2030 | static ctl_table lm93_dir_table_template[] = { |
|---|
| 2031 | LM93_SYSCTL_IN(1), |
|---|
| 2032 | LM93_SYSCTL_IN(2), |
|---|
| 2033 | LM93_SYSCTL_IN(3), |
|---|
| 2034 | LM93_SYSCTL_IN(4), |
|---|
| 2035 | LM93_SYSCTL_IN(5), |
|---|
| 2036 | LM93_SYSCTL_IN(6), |
|---|
| 2037 | LM93_SYSCTL_IN(7), |
|---|
| 2038 | LM93_SYSCTL_IN(8), |
|---|
| 2039 | LM93_SYSCTL_IN(9), |
|---|
| 2040 | LM93_SYSCTL_IN(10), |
|---|
| 2041 | LM93_SYSCTL_IN(11), |
|---|
| 2042 | LM93_SYSCTL_IN(12), |
|---|
| 2043 | LM93_SYSCTL_IN(13), |
|---|
| 2044 | LM93_SYSCTL_IN(14), |
|---|
| 2045 | LM93_SYSCTL_IN(15), |
|---|
| 2046 | LM93_SYSCTL_IN(16), |
|---|
| 2047 | |
|---|
| 2048 | LM93_SYSCTL_TEMP(1), |
|---|
| 2049 | LM93_SYSCTL_TEMP(2), |
|---|
| 2050 | LM93_SYSCTL_TEMP(3), |
|---|
| 2051 | |
|---|
| 2052 | LM93_SYSCTL_TEMP_AUTO_BASE(1), |
|---|
| 2053 | LM93_SYSCTL_TEMP_AUTO_BASE(2), |
|---|
| 2054 | LM93_SYSCTL_TEMP_AUTO_BASE(3), |
|---|
| 2055 | |
|---|
| 2056 | LM93_SYSCTL_TEMP_AUTO_OFFSETS(1), |
|---|
| 2057 | LM93_SYSCTL_TEMP_AUTO_OFFSETS(2), |
|---|
| 2058 | LM93_SYSCTL_TEMP_AUTO_OFFSETS(3), |
|---|
| 2059 | |
|---|
| 2060 | LM93_SYSCTL_TEMP_AUTO_BOOST(1), |
|---|
| 2061 | LM93_SYSCTL_TEMP_AUTO_BOOST(2), |
|---|
| 2062 | LM93_SYSCTL_TEMP_AUTO_BOOST(3), |
|---|
| 2063 | |
|---|
| 2064 | LM93_SYSCTL_TEMP_AUTO_BOOST_HYST(1), |
|---|
| 2065 | LM93_SYSCTL_TEMP_AUTO_BOOST_HYST(2), |
|---|
| 2066 | LM93_SYSCTL_TEMP_AUTO_BOOST_HYST(3), |
|---|
| 2067 | |
|---|
| 2068 | LM93_SYSCTL_TEMP_AUTO_PWM_MIN(1), |
|---|
| 2069 | LM93_SYSCTL_TEMP_AUTO_PWM_MIN(2), |
|---|
| 2070 | LM93_SYSCTL_TEMP_AUTO_PWM_MIN(3), |
|---|
| 2071 | |
|---|
| 2072 | LM93_SYSCTL_TEMP_AUTO_OFFSET_HYST(1), |
|---|
| 2073 | LM93_SYSCTL_TEMP_AUTO_OFFSET_HYST(2), |
|---|
| 2074 | LM93_SYSCTL_TEMP_AUTO_OFFSET_HYST(3), |
|---|
| 2075 | |
|---|
| 2076 | LM93_SYSCTL_FAN(1), |
|---|
| 2077 | LM93_SYSCTL_FAN(2), |
|---|
| 2078 | LM93_SYSCTL_FAN(3), |
|---|
| 2079 | LM93_SYSCTL_FAN(4), |
|---|
| 2080 | |
|---|
| 2081 | LM93_SYSCTL_FAN_SMART_TACH(1), |
|---|
| 2082 | LM93_SYSCTL_FAN_SMART_TACH(2), |
|---|
| 2083 | LM93_SYSCTL_FAN_SMART_TACH(3), |
|---|
| 2084 | LM93_SYSCTL_FAN_SMART_TACH(4), |
|---|
| 2085 | |
|---|
| 2086 | LM93_SYSCTL_PWM(1), |
|---|
| 2087 | LM93_SYSCTL_PWM(2), |
|---|
| 2088 | |
|---|
| 2089 | LM93_SYSCTL_PWM_FREQ(1), |
|---|
| 2090 | LM93_SYSCTL_PWM_FREQ(2), |
|---|
| 2091 | |
|---|
| 2092 | LM93_SYSCTL_PWM_AUTO_CHAN(1), |
|---|
| 2093 | LM93_SYSCTL_PWM_AUTO_CHAN(2), |
|---|
| 2094 | |
|---|
| 2095 | LM93_SYSCTL_PWM_AUTO_SPINUP_MIN(1), |
|---|
| 2096 | LM93_SYSCTL_PWM_AUTO_SPINUP_MIN(2), |
|---|
| 2097 | |
|---|
| 2098 | LM93_SYSCTL_PWM_AUTO_SPINUP_TIME(1), |
|---|
| 2099 | LM93_SYSCTL_PWM_AUTO_SPINUP_TIME(2), |
|---|
| 2100 | |
|---|
| 2101 | {LM93_SYSCTL_PWM_AUTO_PROCHOT_RAMP, "pwm_auto_prochot_ramp", NULL, 0, |
|---|
| 2102 | 0644, NULL, &i2c_proc_real, &i2c_sysctl_real, NULL, |
|---|
| 2103 | &lm93_pwm_auto_ramp}, |
|---|
| 2104 | |
|---|
| 2105 | {LM93_SYSCTL_PWM_AUTO_VRDHOT_RAMP, "pwm_auto_vrdhot_ramp", NULL, 0, |
|---|
| 2106 | 0644, NULL, &i2c_proc_real, &i2c_sysctl_real, NULL, |
|---|
| 2107 | &lm93_pwm_auto_ramp}, |
|---|
| 2108 | |
|---|
| 2109 | LM93_SYSCTL_VID(1), |
|---|
| 2110 | LM93_SYSCTL_VID(2), |
|---|
| 2111 | |
|---|
| 2112 | LM93_SYSCTL_PROCHOT(1), |
|---|
| 2113 | LM93_SYSCTL_PROCHOT(2), |
|---|
| 2114 | |
|---|
| 2115 | {LM93_SYSCTL_PROCHOT_SHORT, "prochot_short", NULL, 0, 0644, NULL, |
|---|
| 2116 | &i2c_proc_real, &i2c_sysctl_real, NULL, &lm93_prochot_short}, |
|---|
| 2117 | |
|---|
| 2118 | {LM93_SYSCTL_PROCHOT_OVERRIDE, "prochot_override", NULL, 0, 0644, NULL, |
|---|
| 2119 | &i2c_proc_real, &i2c_sysctl_real, NULL, &lm93_prochot_override}, |
|---|
| 2120 | |
|---|
| 2121 | {LM93_SYSCTL_PROCHOT_INTERVAL, "prochot_interval", NULL, 0, 0644, NULL, |
|---|
| 2122 | &i2c_proc_real, &i2c_sysctl_real, NULL, &lm93_prochot_interval}, |
|---|
| 2123 | |
|---|
| 2124 | LM93_SYSCTL_VRDHOT(1), |
|---|
| 2125 | LM93_SYSCTL_VRDHOT(2), |
|---|
| 2126 | |
|---|
| 2127 | {LM93_SYSCTL_GPIO, "gpio", NULL, 0, 0444, NULL, |
|---|
| 2128 | &i2c_proc_real, &i2c_sysctl_real, NULL, &lm93_gpio}, |
|---|
| 2129 | |
|---|
| 2130 | {LM93_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 2131 | &i2c_sysctl_real, NULL, &lm93_alarms}, |
|---|
| 2132 | |
|---|
| 2133 | {0} |
|---|
| 2134 | }; |
|---|
| 2135 | |
|---|
| 2136 | static void lm93_init_client(struct i2c_client *client) |
|---|
| [2660] | 2137 | { |
|---|
| [2672] | 2138 | int i; |
|---|
| [2715] | 2139 | u8 reg; |
|---|
| [2672] | 2140 | |
|---|
| [2715] | 2141 | /* configure VID pin input thresholds */ |
|---|
| 2142 | reg = lm93_read_byte(client, LM93_REG_GPI_VID_CTL); |
|---|
| 2143 | lm93_write_byte(client, LM93_REG_GPI_VID_CTL, |
|---|
| 2144 | reg | (vid_agtl ? 0x03 : 0x00)); |
|---|
| 2145 | |
|---|
| [2672] | 2146 | if (init) { |
|---|
| 2147 | /* enable #ALERT pin */ |
|---|
| 2148 | reg = lm93_read_byte(client, LM93_REG_CONFIG); |
|---|
| 2149 | lm93_write_byte(client, LM93_REG_CONFIG, reg | 0x08); |
|---|
| 2150 | |
|---|
| 2151 | /* enable ASF mode for BMC status registers */ |
|---|
| 2152 | reg = lm93_read_byte(client, LM93_REG_STATUS_CONTROL); |
|---|
| 2153 | lm93_write_byte(client, LM93_REG_STATUS_CONTROL, reg | 0x02); |
|---|
| 2154 | |
|---|
| 2155 | /* set sleep state to S0 */ |
|---|
| 2156 | lm93_write_byte(client, LM93_REG_SLEEP_CONTROL, 0); |
|---|
| [2734] | 2157 | |
|---|
| 2158 | /* unmask #VRDHOT and dynamic VCCP (if nec) error events */ |
|---|
| 2159 | reg = lm93_read_byte(client, LM93_REG_MISC_ERR_MASK); |
|---|
| 2160 | reg &= ~0x03; |
|---|
| 2161 | reg &= ~(vccp_limit_type[0] ? 0x10 : 0); |
|---|
| 2162 | reg &= ~(vccp_limit_type[1] ? 0x20 : 0); |
|---|
| 2163 | lm93_write_byte(client, LM93_REG_MISC_ERR_MASK, reg); |
|---|
| [2672] | 2164 | } |
|---|
| [2734] | 2165 | |
|---|
| 2166 | /* start monitoring */ |
|---|
| 2167 | reg = lm93_read_byte(client, LM93_REG_CONFIG); |
|---|
| 2168 | lm93_write_byte(client, LM93_REG_CONFIG, reg | 0x01); |
|---|
| 2169 | |
|---|
| [2672] | 2170 | /* spin until ready */ |
|---|
| 2171 | for (i=0; i<20; i++) { |
|---|
| 2172 | mdelay(10); |
|---|
| 2173 | if ((lm93_read_byte(client, LM93_REG_CONFIG) & 0x80) == 0x80) |
|---|
| 2174 | return; |
|---|
| 2175 | } |
|---|
| 2176 | |
|---|
| 2177 | printk(KERN_WARNING "lm93.o: timed out waiting for sensor " |
|---|
| 2178 | "chip to signal ready!\n"); |
|---|
| 2179 | } |
|---|
| 2180 | |
|---|
| 2181 | /* forward declaration */ |
|---|
| 2182 | static struct i2c_driver lm93_driver; |
|---|
| 2183 | |
|---|
| 2184 | /* This function is called by i2c_detect */ |
|---|
| 2185 | static int lm93_detect(struct i2c_adapter *adapter, int address, |
|---|
| 2186 | unsigned short flags, int kind) |
|---|
| 2187 | { |
|---|
| [2837] | 2188 | int err = 0, func; |
|---|
| [2672] | 2189 | struct lm93_data *data; |
|---|
| 2190 | struct i2c_client *client; |
|---|
| 2191 | void (*update)(struct lm93_data *, struct i2c_client *); |
|---|
| 2192 | |
|---|
| 2193 | /* lm93 is SMBus only */ |
|---|
| 2194 | if (i2c_is_isa_adapter(adapter)) { |
|---|
| 2195 | pr_debug("lm93.o: detect failed, " |
|---|
| 2196 | "cannot attach to legacy adapter!\n"); |
|---|
| 2197 | goto ERROR0; |
|---|
| 2198 | } |
|---|
| 2199 | |
|---|
| 2200 | /* choose update routine based on bus capabilities */ |
|---|
| 2201 | func = i2c_get_functionality(adapter); |
|---|
| 2202 | |
|---|
| 2203 | if ( ((LM93_SMBUS_FUNC_FULL & func) == LM93_SMBUS_FUNC_FULL) && |
|---|
| 2204 | (!disable_block) ) { |
|---|
| 2205 | pr_debug("lm93.o: using SMBus block data transactions\n"); |
|---|
| 2206 | update = lm93_update_client_full; |
|---|
| 2207 | } else if ((LM93_SMBUS_FUNC_MIN & func) == LM93_SMBUS_FUNC_MIN) { |
|---|
| 2208 | pr_debug("lm93.o: disabled SMBus block data transactions\n"); |
|---|
| 2209 | update = lm93_update_client_min; |
|---|
| 2210 | } else { |
|---|
| 2211 | pr_debug("lm93.o: detect failed, " |
|---|
| 2212 | "smbus byte and/or word data not supported!\n"); |
|---|
| 2213 | goto ERROR0; |
|---|
| 2214 | } |
|---|
| 2215 | |
|---|
| 2216 | /* OK. For now, we presume we have a valid client. We now create the |
|---|
| 2217 | client structure, even though we cannot fill it completely yet. |
|---|
| 2218 | But it allows us to access lm78_{read,write}_value. */ |
|---|
| 2219 | |
|---|
| 2220 | if (!(data = kmalloc(sizeof(struct lm93_data), GFP_KERNEL))) { |
|---|
| 2221 | pr_debug("lm93.o: detect failed, kmalloc failed!\n"); |
|---|
| 2222 | err = -ENOMEM; |
|---|
| 2223 | goto ERROR0; |
|---|
| 2224 | } |
|---|
| 2225 | |
|---|
| 2226 | client = &data->client; |
|---|
| 2227 | client->addr = address; |
|---|
| 2228 | client->data = data; |
|---|
| 2229 | client->adapter = adapter; |
|---|
| 2230 | client->driver = &lm93_driver; |
|---|
| 2231 | client->flags = 0; |
|---|
| 2232 | |
|---|
| 2233 | /* detection */ |
|---|
| 2234 | if (kind < 0) { |
|---|
| 2235 | int mfr = lm93_read_byte(client, LM93_REG_MFR_ID); |
|---|
| 2236 | |
|---|
| 2237 | if (mfr != 0x01) { |
|---|
| 2238 | pr_debug("lm93.o: detect failed, " |
|---|
| 2239 | "bad manufacturer id 0x%02x!\n", mfr); |
|---|
| 2240 | goto ERROR1; |
|---|
| 2241 | } |
|---|
| 2242 | } |
|---|
| 2243 | |
|---|
| 2244 | if (kind <= 0) { |
|---|
| 2245 | int ver = lm93_read_byte(client, LM93_REG_VER); |
|---|
| 2246 | |
|---|
| 2247 | if ((ver == LM93_MFR_ID) || (ver == LM93_MFR_ID_PROTOTYPE)) { |
|---|
| 2248 | kind = lm93; |
|---|
| 2249 | } else { |
|---|
| 2250 | pr_debug("lm93.o: detect failed, " |
|---|
| 2251 | "bad version id 0x%02x!\n", ver); |
|---|
| 2252 | if (kind == 0) |
|---|
| 2253 | pr_debug("lm93.o: " |
|---|
| 2254 | "(ignored 'force' parameter)\n"); |
|---|
| 2255 | goto ERROR1; |
|---|
| 2256 | } |
|---|
| 2257 | } |
|---|
| 2258 | |
|---|
| 2259 | /* fill in remaining client fields */ |
|---|
| 2260 | strcpy(client->name, "LM93 chip"); |
|---|
| 2261 | client->id = lm93_id++; |
|---|
| 2262 | pr_debug("lm93.o: assigning ID %d to %s at %d,0x%02x\n", client->id, |
|---|
| 2263 | client->name, i2c_adapter_id(client->adapter), client->addr); |
|---|
| 2264 | |
|---|
| 2265 | /* housekeeping */ |
|---|
| 2266 | data->valid = 0; |
|---|
| 2267 | data->update = update; |
|---|
| 2268 | init_MUTEX(&data->update_lock); |
|---|
| 2269 | |
|---|
| 2270 | /* tell the I2C layer a new client has arrived */ |
|---|
| 2271 | if ((err = i2c_attach_client(client))) |
|---|
| 2272 | goto ERROR1; |
|---|
| 2273 | |
|---|
| 2274 | /* initialize the chip */ |
|---|
| 2275 | lm93_init_client(client); |
|---|
| 2276 | |
|---|
| 2277 | /* register a new directory entry with module sensors */ |
|---|
| 2278 | if ((data->sysctl_id = i2c_register_entry(client, "lm93", |
|---|
| [2784] | 2279 | lm93_dir_table_template, THIS_MODULE)) < 0) { |
|---|
| [2672] | 2280 | err = data->sysctl_id; |
|---|
| 2281 | goto ERROR2; |
|---|
| 2282 | } |
|---|
| 2283 | |
|---|
| 2284 | return 0; |
|---|
| 2285 | |
|---|
| 2286 | ERROR2: |
|---|
| 2287 | i2c_detach_client(client); |
|---|
| 2288 | ERROR1: |
|---|
| 2289 | kfree(data); |
|---|
| 2290 | ERROR0: |
|---|
| 2291 | return err; |
|---|
| 2292 | } |
|---|
| 2293 | |
|---|
| 2294 | /* This function is called when: |
|---|
| 2295 | * lm93_driver is inserted (when this module is loaded), for each |
|---|
| 2296 | available adapter |
|---|
| 2297 | * when a new adapter is inserted (and lm93_driver is still present) */ |
|---|
| 2298 | static int lm93_attach_adapter(struct i2c_adapter *adapter) |
|---|
| 2299 | { |
|---|
| 2300 | return i2c_detect(adapter, &addr_data, lm93_detect); |
|---|
| 2301 | } |
|---|
| 2302 | |
|---|
| 2303 | static int lm93_detach_client(struct i2c_client *client) |
|---|
| 2304 | { |
|---|
| 2305 | int err; |
|---|
| [2660] | 2306 | struct lm93_data *data = client->data; |
|---|
| [2672] | 2307 | |
|---|
| 2308 | i2c_deregister_entry(data->sysctl_id); |
|---|
| 2309 | |
|---|
| 2310 | if ((err = i2c_detach_client(client))) { |
|---|
| 2311 | printk (KERN_ERR "lm93.o: Client deregistration failed; " |
|---|
| 2312 | "client not detached.\n"); |
|---|
| 2313 | return err; |
|---|
| [2660] | 2314 | } |
|---|
| [3015] | 2315 | kfree(data); |
|---|
| [2672] | 2316 | return 0; |
|---|
| [2660] | 2317 | } |
|---|
| 2318 | |
|---|
| [2672] | 2319 | static struct i2c_driver lm93_driver = { |
|---|
| 2320 | .name = "LM93 sensor driver", |
|---|
| 2321 | .id = I2C_DRIVERID_LM93, |
|---|
| 2322 | .flags = I2C_DF_NOTIFY, |
|---|
| 2323 | .attach_adapter = lm93_attach_adapter, |
|---|
| 2324 | .detach_client = lm93_detach_client, |
|---|
| 2325 | }; |
|---|
| 2326 | |
|---|
| [2653] | 2327 | static int __init lm93_init(void) |
|---|
| 2328 | { |
|---|
| 2329 | printk(KERN_INFO "lm93.o version %s (%s)\n", LM_VERSION, LM_DATE); |
|---|
| 2330 | return i2c_add_driver(&lm93_driver); |
|---|
| 2331 | } |
|---|
| 2332 | |
|---|
| 2333 | static void __exit lm93_exit(void) |
|---|
| 2334 | { |
|---|
| 2335 | i2c_del_driver(&lm93_driver); |
|---|
| 2336 | } |
|---|
| 2337 | |
|---|
| 2338 | MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>"); |
|---|
| 2339 | MODULE_DESCRIPTION("LM93 driver"); |
|---|
| 2340 | MODULE_LICENSE("GPL"); |
|---|
| 2341 | |
|---|
| 2342 | module_init(lm93_init); |
|---|
| 2343 | module_exit(lm93_exit); |
|---|