/drivers/hwmon/lm93.c
C | 2637 lines | 2016 code | 356 blank | 265 comment | 104 complexity | 97a316c9b70c7a5380fdd89033d52859 MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
Large files files are truncated, but you can click here to view the full file
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 Ported to Linux 2.6 by Eric J. Bowersox <ericb@aspsys.com>
18 Copyright (c) 2005 Aspen Systems, Inc.
19
20 Adapted to 2.6.20 by Carsten Emde <cbe@osadl.org>
21 Copyright (c) 2006 Carsten Emde, Open Source Automation Development Lab
22
23 Modified for mainline integration by Hans J. Koch <hjk@linutronix.de>
24 Copyright (c) 2007 Hans J. Koch, Linutronix GmbH
25
26 This program is free software; you can redistribute it and/or modify
27 it under the terms of the GNU General Public License as published by
28 the Free Software Foundation; either version 2 of the License, or
29 (at your option) any later version.
30
31 This program is distributed in the hope that it will be useful,
32 but WITHOUT ANY WARRANTY; without even the implied warranty of
33 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 GNU General Public License for more details.
35
36 You should have received a copy of the GNU General Public License
37 along with this program; if not, write to the Free Software
38 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
39*/
40
41#include <linux/module.h>
42#include <linux/init.h>
43#include <linux/slab.h>
44#include <linux/i2c.h>
45#include <linux/hwmon.h>
46#include <linux/hwmon-sysfs.h>
47#include <linux/hwmon-vid.h>
48#include <linux/err.h>
49#include <linux/delay.h>
50
51/* LM93 REGISTER ADDRESSES */
52
53/* miscellaneous */
54#define LM93_REG_MFR_ID 0x3e
55#define LM93_REG_VER 0x3f
56#define LM93_REG_STATUS_CONTROL 0xe2
57#define LM93_REG_CONFIG 0xe3
58#define LM93_REG_SLEEP_CONTROL 0xe4
59
60/* alarm values start here */
61#define LM93_REG_HOST_ERROR_1 0x48
62
63/* voltage inputs: in1-in16 (nr => 0-15) */
64#define LM93_REG_IN(nr) (0x56 + (nr))
65#define LM93_REG_IN_MIN(nr) (0x90 + (nr) * 2)
66#define LM93_REG_IN_MAX(nr) (0x91 + (nr) * 2)
67
68/* temperature inputs: temp1-temp4 (nr => 0-3) */
69#define LM93_REG_TEMP(nr) (0x50 + (nr))
70#define LM93_REG_TEMP_MIN(nr) (0x78 + (nr) * 2)
71#define LM93_REG_TEMP_MAX(nr) (0x79 + (nr) * 2)
72
73/* temp[1-4]_auto_boost (nr => 0-3) */
74#define LM93_REG_BOOST(nr) (0x80 + (nr))
75
76/* #PROCHOT inputs: prochot1-prochot2 (nr => 0-1) */
77#define LM93_REG_PROCHOT_CUR(nr) (0x67 + (nr) * 2)
78#define LM93_REG_PROCHOT_AVG(nr) (0x68 + (nr) * 2)
79#define LM93_REG_PROCHOT_MAX(nr) (0xb0 + (nr))
80
81/* fan tach inputs: fan1-fan4 (nr => 0-3) */
82#define LM93_REG_FAN(nr) (0x6e + (nr) * 2)
83#define LM93_REG_FAN_MIN(nr) (0xb4 + (nr) * 2)
84
85/* pwm outputs: pwm1-pwm2 (nr => 0-1, reg => 0-3) */
86#define LM93_REG_PWM_CTL(nr,reg) (0xc8 + (reg) + (nr) * 4)
87#define LM93_PWM_CTL1 0x0
88#define LM93_PWM_CTL2 0x1
89#define LM93_PWM_CTL3 0x2
90#define LM93_PWM_CTL4 0x3
91
92/* GPIO input state */
93#define LM93_REG_GPI 0x6b
94
95/* vid inputs: vid1-vid2 (nr => 0-1) */
96#define LM93_REG_VID(nr) (0x6c + (nr))
97
98/* vccp1 & vccp2: VID relative inputs (nr => 0-1) */
99#define LM93_REG_VCCP_LIMIT_OFF(nr) (0xb2 + (nr))
100
101/* temp[1-4]_auto_boost_hyst */
102#define LM93_REG_BOOST_HYST_12 0xc0
103#define LM93_REG_BOOST_HYST_34 0xc1
104#define LM93_REG_BOOST_HYST(nr) (0xc0 + (nr)/2)
105
106/* temp[1-4]_auto_pwm_[min|hyst] */
107#define LM93_REG_PWM_MIN_HYST_12 0xc3
108#define LM93_REG_PWM_MIN_HYST_34 0xc4
109#define LM93_REG_PWM_MIN_HYST(nr) (0xc3 + (nr)/2)
110
111/* prochot_override & prochot_interval */
112#define LM93_REG_PROCHOT_OVERRIDE 0xc6
113#define LM93_REG_PROCHOT_INTERVAL 0xc7
114
115/* temp[1-4]_auto_base (nr => 0-3) */
116#define LM93_REG_TEMP_BASE(nr) (0xd0 + (nr))
117
118/* temp[1-4]_auto_offsets (step => 0-11) */
119#define LM93_REG_TEMP_OFFSET(step) (0xd4 + (step))
120
121/* #PROCHOT & #VRDHOT PWM ramp control */
122#define LM93_REG_PWM_RAMP_CTL 0xbf
123
124/* miscellaneous */
125#define LM93_REG_SFC1 0xbc
126#define LM93_REG_SFC2 0xbd
127#define LM93_REG_GPI_VID_CTL 0xbe
128#define LM93_REG_SF_TACH_TO_PWM 0xe0
129
130/* error masks */
131#define LM93_REG_GPI_ERR_MASK 0xec
132#define LM93_REG_MISC_ERR_MASK 0xed
133
134/* LM93 REGISTER VALUES */
135#define LM93_MFR_ID 0x73
136#define LM93_MFR_ID_PROTOTYPE 0x72
137
138/* SMBus capabilities */
139#define LM93_SMBUS_FUNC_FULL (I2C_FUNC_SMBUS_BYTE_DATA | \
140 I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BLOCK_DATA)
141#define LM93_SMBUS_FUNC_MIN (I2C_FUNC_SMBUS_BYTE_DATA | \
142 I2C_FUNC_SMBUS_WORD_DATA)
143
144/* Addresses to scan */
145static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
146
147/* Insmod parameters */
148
149static int disable_block;
150module_param(disable_block, bool, 0);
151MODULE_PARM_DESC(disable_block,
152 "Set to non-zero to disable SMBus block data transactions.");
153
154static int init;
155module_param(init, bool, 0);
156MODULE_PARM_DESC(init, "Set to non-zero to force chip initialization.");
157
158static int vccp_limit_type[2] = {0,0};
159module_param_array(vccp_limit_type, int, NULL, 0);
160MODULE_PARM_DESC(vccp_limit_type, "Configures in7 and in8 limit modes.");
161
162static int vid_agtl;
163module_param(vid_agtl, int, 0);
164MODULE_PARM_DESC(vid_agtl, "Configures VID pin input thresholds.");
165
166/* Driver data */
167static struct i2c_driver lm93_driver;
168
169/* LM93 BLOCK READ COMMANDS */
170static const struct { u8 cmd; u8 len; } lm93_block_read_cmds[12] = {
171 { 0xf2, 8 },
172 { 0xf3, 8 },
173 { 0xf4, 6 },
174 { 0xf5, 16 },
175 { 0xf6, 4 },
176 { 0xf7, 8 },
177 { 0xf8, 12 },
178 { 0xf9, 32 },
179 { 0xfa, 8 },
180 { 0xfb, 8 },
181 { 0xfc, 16 },
182 { 0xfd, 9 },
183};
184
185/* ALARMS: SYSCTL format described further below
186 REG: 64 bits in 8 registers, as immediately below */
187struct block1_t {
188 u8 host_status_1;
189 u8 host_status_2;
190 u8 host_status_3;
191 u8 host_status_4;
192 u8 p1_prochot_status;
193 u8 p2_prochot_status;
194 u8 gpi_status;
195 u8 fan_status;
196};
197
198/*
199 * Client-specific data
200 */
201struct lm93_data {
202 struct device *hwmon_dev;
203
204 struct mutex update_lock;
205 unsigned long last_updated; /* In jiffies */
206
207 /* client update function */
208 void (*update)(struct lm93_data *, struct i2c_client *);
209
210 char valid; /* !=0 if following fields are valid */
211
212 /* register values, arranged by block read groups */
213 struct block1_t block1;
214
215 /* temp1 - temp4: unfiltered readings
216 temp1 - temp2: filtered readings */
217 u8 block2[6];
218
219 /* vin1 - vin16: readings */
220 u8 block3[16];
221
222 /* prochot1 - prochot2: readings */
223 struct {
224 u8 cur;
225 u8 avg;
226 } block4[2];
227
228 /* fan counts 1-4 => 14-bits, LE, *left* justified */
229 u16 block5[4];
230
231 /* block6 has a lot of data we don't need */
232 struct {
233 u8 min;
234 u8 max;
235 } temp_lim[4];
236
237 /* vin1 - vin16: low and high limits */
238 struct {
239 u8 min;
240 u8 max;
241 } block7[16];
242
243 /* fan count limits 1-4 => same format as block5 */
244 u16 block8[4];
245
246 /* pwm control registers (2 pwms, 4 regs) */
247 u8 block9[2][4];
248
249 /* auto/pwm base temp and offset temp registers */
250 struct {
251 u8 base[4];
252 u8 offset[12];
253 } block10;
254
255 /* master config register */
256 u8 config;
257
258 /* VID1 & VID2 => register format, 6-bits, right justified */
259 u8 vid[2];
260
261 /* prochot1 - prochot2: limits */
262 u8 prochot_max[2];
263
264 /* vccp1 & vccp2 (in7 & in8): VID relative limits (register format) */
265 u8 vccp_limits[2];
266
267 /* GPIO input state (register format, i.e. inverted) */
268 u8 gpi;
269
270 /* #PROCHOT override (register format) */
271 u8 prochot_override;
272
273 /* #PROCHOT intervals (register format) */
274 u8 prochot_interval;
275
276 /* Fan Boost Temperatures (register format) */
277 u8 boost[4];
278
279 /* Fan Boost Hysteresis (register format) */
280 u8 boost_hyst[2];
281
282 /* Temperature Zone Min. PWM & Hysteresis (register format) */
283 u8 auto_pwm_min_hyst[2];
284
285 /* #PROCHOT & #VRDHOT PWM Ramp Control */
286 u8 pwm_ramp_ctl;
287
288 /* miscellaneous setup regs */
289 u8 sfc1;
290 u8 sfc2;
291 u8 sf_tach_to_pwm;
292
293 /* The two PWM CTL2 registers can read something other than what was
294 last written for the OVR_DC field (duty cycle override). So, we
295 save the user-commanded value here. */
296 u8 pwm_override[2];
297};
298
299/* VID: mV
300 REG: 6-bits, right justified, *always* using Intel VRM/VRD 10 */
301static int LM93_VID_FROM_REG(u8 reg)
302{
303 return vid_from_reg((reg & 0x3f), 100);
304}
305
306/* min, max, and nominal register values, per channel (u8) */
307static const u8 lm93_vin_reg_min[16] = {
308 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
309 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xae,
310};
311static const u8 lm93_vin_reg_max[16] = {
312 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
313 0xff, 0xfa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd1,
314};
315/* Values from the datasheet. They're here for documentation only.
316static const u8 lm93_vin_reg_nom[16] = {
317 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
318 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0xc0,
319};
320*/
321
322/* min, max, and nominal voltage readings, per channel (mV)*/
323static const unsigned long lm93_vin_val_min[16] = {
324 0, 0, 0, 0, 0, 0, 0, 0,
325 0, 0, 0, 0, 0, 0, 0, 3000,
326};
327
328static const unsigned long lm93_vin_val_max[16] = {
329 1236, 1236, 1236, 1600, 2000, 2000, 1600, 1600,
330 4400, 6500, 3333, 2625, 1312, 1312, 1236, 3600,
331};
332/* Values from the datasheet. They're here for documentation only.
333static const unsigned long lm93_vin_val_nom[16] = {
334 927, 927, 927, 1200, 1500, 1500, 1200, 1200,
335 3300, 5000, 2500, 1969, 984, 984, 309, 3300,
336};
337*/
338
339static unsigned LM93_IN_FROM_REG(int nr, u8 reg)
340{
341 const long uV_max = lm93_vin_val_max[nr] * 1000;
342 const long uV_min = lm93_vin_val_min[nr] * 1000;
343
344 const long slope = (uV_max - uV_min) /
345 (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]);
346 const long intercept = uV_min - slope * lm93_vin_reg_min[nr];
347
348 return (slope * reg + intercept + 500) / 1000;
349}
350
351/* IN: mV, limits determined by channel nr
352 REG: scaling determined by channel nr */
353static u8 LM93_IN_TO_REG(int nr, unsigned val)
354{
355 /* range limit */
356 const long mV = SENSORS_LIMIT(val,
357 lm93_vin_val_min[nr], lm93_vin_val_max[nr]);
358
359 /* try not to lose too much precision here */
360 const long uV = mV * 1000;
361 const long uV_max = lm93_vin_val_max[nr] * 1000;
362 const long uV_min = lm93_vin_val_min[nr] * 1000;
363
364 /* convert */
365 const long slope = (uV_max - uV_min) /
366 (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]);
367 const long intercept = uV_min - slope * lm93_vin_reg_min[nr];
368
369 u8 result = ((uV - intercept + (slope/2)) / slope);
370 result = SENSORS_LIMIT(result,
371 lm93_vin_reg_min[nr], lm93_vin_reg_max[nr]);
372 return result;
373}
374
375/* vid in mV, upper == 0 indicates low limit, otherwise upper limit */
376static unsigned LM93_IN_REL_FROM_REG(u8 reg, int upper, int vid)
377{
378 const long uV_offset = upper ? (((reg >> 4 & 0x0f) + 1) * 12500) :
379 (((reg >> 0 & 0x0f) + 1) * -25000);
380 const long uV_vid = vid * 1000;
381 return (uV_vid + uV_offset + 5000) / 10000;
382}
383
384#define LM93_IN_MIN_FROM_REG(reg,vid) LM93_IN_REL_FROM_REG(reg,0,vid)
385#define LM93_IN_MAX_FROM_REG(reg,vid) LM93_IN_REL_FROM_REG(reg,1,vid)
386
387/* vid in mV , upper == 0 indicates low limit, otherwise upper limit
388 upper also determines which nibble of the register is returned
389 (the other nibble will be 0x0) */
390static u8 LM93_IN_REL_TO_REG(unsigned val, int upper, int vid)
391{
392 long uV_offset = vid * 1000 - val * 10000;
393 if (upper) {
394 uV_offset = SENSORS_LIMIT(uV_offset, 12500, 200000);
395 return (u8)((uV_offset / 12500 - 1) << 4);
396 } else {
397 uV_offset = SENSORS_LIMIT(uV_offset, -400000, -25000);
398 return (u8)((uV_offset / -25000 - 1) << 0);
399 }
400}
401
402/* TEMP: 1/1000 degrees C (-128C to +127C)
403 REG: 1C/bit, two's complement */
404static int LM93_TEMP_FROM_REG(u8 reg)
405{
406 return (s8)reg * 1000;
407}
408
409#define LM93_TEMP_MIN (-128000)
410#define LM93_TEMP_MAX ( 127000)
411
412/* TEMP: 1/1000 degrees C (-128C to +127C)
413 REG: 1C/bit, two's complement */
414static u8 LM93_TEMP_TO_REG(long temp)
415{
416 int ntemp = SENSORS_LIMIT(temp, LM93_TEMP_MIN, LM93_TEMP_MAX);
417 ntemp += (ntemp<0 ? -500 : 500);
418 return (u8)(ntemp / 1000);
419}
420
421/* Determine 4-bit temperature offset resolution */
422static int LM93_TEMP_OFFSET_MODE_FROM_REG(u8 sfc2, int nr)
423{
424 /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */
425 return sfc2 & (nr < 2 ? 0x10 : 0x20);
426}
427
428/* This function is common to all 4-bit temperature offsets
429 reg is 4 bits right justified
430 mode 0 => 1C/bit, mode !0 => 0.5C/bit */
431static int LM93_TEMP_OFFSET_FROM_REG(u8 reg, int mode)
432{
433 return (reg & 0x0f) * (mode ? 5 : 10);
434}
435
436#define LM93_TEMP_OFFSET_MIN ( 0)
437#define LM93_TEMP_OFFSET_MAX0 (150)
438#define LM93_TEMP_OFFSET_MAX1 ( 75)
439
440/* This function is common to all 4-bit temperature offsets
441 returns 4 bits right justified
442 mode 0 => 1C/bit, mode !0 => 0.5C/bit */
443static u8 LM93_TEMP_OFFSET_TO_REG(int off, int mode)
444{
445 int factor = mode ? 5 : 10;
446
447 off = SENSORS_LIMIT(off, LM93_TEMP_OFFSET_MIN,
448 mode ? LM93_TEMP_OFFSET_MAX1 : LM93_TEMP_OFFSET_MAX0);
449 return (u8)((off + factor/2) / factor);
450}
451
452/* 0 <= nr <= 3 */
453static int LM93_TEMP_AUTO_OFFSET_FROM_REG(u8 reg, int nr, int mode)
454{
455 /* temp1-temp2 (nr=0,1) use lower nibble */
456 if (nr < 2)
457 return LM93_TEMP_OFFSET_FROM_REG(reg & 0x0f, mode);
458
459 /* temp3-temp4 (nr=2,3) use upper nibble */
460 else
461 return LM93_TEMP_OFFSET_FROM_REG(reg >> 4 & 0x0f, mode);
462}
463
464/* TEMP: 1/10 degrees C (0C to +15C (mode 0) or +7.5C (mode non-zero))
465 REG: 1.0C/bit (mode 0) or 0.5C/bit (mode non-zero)
466 0 <= nr <= 3 */
467static u8 LM93_TEMP_AUTO_OFFSET_TO_REG(u8 old, int off, int nr, int mode)
468{
469 u8 new = LM93_TEMP_OFFSET_TO_REG(off, mode);
470
471 /* temp1-temp2 (nr=0,1) use lower nibble */
472 if (nr < 2)
473 return (old & 0xf0) | (new & 0x0f);
474
475 /* temp3-temp4 (nr=2,3) use upper nibble */
476 else
477 return (new << 4 & 0xf0) | (old & 0x0f);
478}
479
480static int LM93_AUTO_BOOST_HYST_FROM_REGS(struct lm93_data *data, int nr,
481 int mode)
482{
483 u8 reg;
484
485 switch (nr) {
486 case 0:
487 reg = data->boost_hyst[0] & 0x0f;
488 break;
489 case 1:
490 reg = data->boost_hyst[0] >> 4 & 0x0f;
491 break;
492 case 2:
493 reg = data->boost_hyst[1] & 0x0f;
494 break;
495 case 3:
496 default:
497 reg = data->boost_hyst[1] >> 4 & 0x0f;
498 break;
499 }
500
501 return LM93_TEMP_FROM_REG(data->boost[nr]) -
502 LM93_TEMP_OFFSET_FROM_REG(reg, mode);
503}
504
505static u8 LM93_AUTO_BOOST_HYST_TO_REG(struct lm93_data *data, long hyst,
506 int nr, int mode)
507{
508 u8 reg = LM93_TEMP_OFFSET_TO_REG(
509 (LM93_TEMP_FROM_REG(data->boost[nr]) - hyst), mode);
510
511 switch (nr) {
512 case 0:
513 reg = (data->boost_hyst[0] & 0xf0) | (reg & 0x0f);
514 break;
515 case 1:
516 reg = (reg << 4 & 0xf0) | (data->boost_hyst[0] & 0x0f);
517 break;
518 case 2:
519 reg = (data->boost_hyst[1] & 0xf0) | (reg & 0x0f);
520 break;
521 case 3:
522 default:
523 reg = (reg << 4 & 0xf0) | (data->boost_hyst[1] & 0x0f);
524 break;
525 }
526
527 return reg;
528}
529
530/* PWM: 0-255 per sensors documentation
531 REG: 0-13 as mapped below... right justified */
532typedef enum { LM93_PWM_MAP_HI_FREQ, LM93_PWM_MAP_LO_FREQ } pwm_freq_t;
533static int lm93_pwm_map[2][16] = {
534 {
535 0x00, /* 0.00% */ 0x40, /* 25.00% */
536 0x50, /* 31.25% */ 0x60, /* 37.50% */
537 0x70, /* 43.75% */ 0x80, /* 50.00% */
538 0x90, /* 56.25% */ 0xa0, /* 62.50% */
539 0xb0, /* 68.75% */ 0xc0, /* 75.00% */
540 0xd0, /* 81.25% */ 0xe0, /* 87.50% */
541 0xf0, /* 93.75% */ 0xff, /* 100.00% */
542 0xff, 0xff, /* 14, 15 are reserved and should never occur */
543 },
544 {
545 0x00, /* 0.00% */ 0x40, /* 25.00% */
546 0x49, /* 28.57% */ 0x52, /* 32.14% */
547 0x5b, /* 35.71% */ 0x64, /* 39.29% */
548 0x6d, /* 42.86% */ 0x76, /* 46.43% */
549 0x80, /* 50.00% */ 0x89, /* 53.57% */
550 0x92, /* 57.14% */ 0xb6, /* 71.43% */
551 0xdb, /* 85.71% */ 0xff, /* 100.00% */
552 0xff, 0xff, /* 14, 15 are reserved and should never occur */
553 },
554};
555
556static int LM93_PWM_FROM_REG(u8 reg, pwm_freq_t freq)
557{
558 return lm93_pwm_map[freq][reg & 0x0f];
559}
560
561/* round up to nearest match */
562static u8 LM93_PWM_TO_REG(int pwm, pwm_freq_t freq)
563{
564 int i;
565 for (i = 0; i < 13; i++)
566 if (pwm <= lm93_pwm_map[freq][i])
567 break;
568
569 /* can fall through with i==13 */
570 return (u8)i;
571}
572
573static int LM93_FAN_FROM_REG(u16 regs)
574{
575 const u16 count = le16_to_cpu(regs) >> 2;
576 return count==0 ? -1 : count==0x3fff ? 0: 1350000 / count;
577}
578
579/*
580 * RPM: (82.5 to 1350000)
581 * REG: 14-bits, LE, *left* justified
582 */
583static u16 LM93_FAN_TO_REG(long rpm)
584{
585 u16 count, regs;
586
587 if (rpm == 0) {
588 count = 0x3fff;
589 } else {
590 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
591 count = SENSORS_LIMIT((1350000 + rpm) / rpm, 1, 0x3ffe);
592 }
593
594 regs = count << 2;
595 return cpu_to_le16(regs);
596}
597
598/* PWM FREQ: HZ
599 REG: 0-7 as mapped below */
600static int lm93_pwm_freq_map[8] = {
601 22500, 96, 84, 72, 60, 48, 36, 12
602};
603
604static int LM93_PWM_FREQ_FROM_REG(u8 reg)
605{
606 return lm93_pwm_freq_map[reg & 0x07];
607}
608
609/* round up to nearest match */
610static u8 LM93_PWM_FREQ_TO_REG(int freq)
611{
612 int i;
613 for (i = 7; i > 0; i--)
614 if (freq <= lm93_pwm_freq_map[i])
615 break;
616
617 /* can fall through with i==0 */
618 return (u8)i;
619}
620
621/* TIME: 1/100 seconds
622 * REG: 0-7 as mapped below */
623static int lm93_spinup_time_map[8] = {
624 0, 10, 25, 40, 70, 100, 200, 400,
625};
626
627static int LM93_SPINUP_TIME_FROM_REG(u8 reg)
628{
629 return lm93_spinup_time_map[reg >> 5 & 0x07];
630}
631
632/* round up to nearest match */
633static u8 LM93_SPINUP_TIME_TO_REG(int time)
634{
635 int i;
636 for (i = 0; i < 7; i++)
637 if (time <= lm93_spinup_time_map[i])
638 break;
639
640 /* can fall through with i==8 */
641 return (u8)i;
642}
643
644#define LM93_RAMP_MIN 0
645#define LM93_RAMP_MAX 75
646
647static int LM93_RAMP_FROM_REG(u8 reg)
648{
649 return (reg & 0x0f) * 5;
650}
651
652/* RAMP: 1/100 seconds
653 REG: 50mS/bit 4-bits right justified */
654static u8 LM93_RAMP_TO_REG(int ramp)
655{
656 ramp = SENSORS_LIMIT(ramp, LM93_RAMP_MIN, LM93_RAMP_MAX);
657 return (u8)((ramp + 2) / 5);
658}
659
660/* PROCHOT: 0-255, 0 => 0%, 255 => > 96.6%
661 * REG: (same) */
662static u8 LM93_PROCHOT_TO_REG(long prochot)
663{
664 prochot = SENSORS_LIMIT(prochot, 0, 255);
665 return (u8)prochot;
666}
667
668/* PROCHOT-INTERVAL: 73 - 37200 (1/100 seconds)
669 * REG: 0-9 as mapped below */
670static int lm93_interval_map[10] = {
671 73, 146, 290, 580, 1170, 2330, 4660, 9320, 18600, 37200,
672};
673
674static int LM93_INTERVAL_FROM_REG(u8 reg)
675{
676 return lm93_interval_map[reg & 0x0f];
677}
678
679/* round up to nearest match */
680static u8 LM93_INTERVAL_TO_REG(long interval)
681{
682 int i;
683 for (i = 0; i < 9; i++)
684 if (interval <= lm93_interval_map[i])
685 break;
686
687 /* can fall through with i==9 */
688 return (u8)i;
689}
690
691/* GPIO: 0-255, GPIO0 is LSB
692 * REG: inverted */
693static unsigned LM93_GPI_FROM_REG(u8 reg)
694{
695 return ~reg & 0xff;
696}
697
698/* alarm bitmask definitions
699 The LM93 has nearly 64 bits of error status... I've pared that down to
700 what I think is a useful subset in order to fit it into 32 bits.
701
702 Especially note that the #VRD_HOT alarms are missing because we provide
703 that information as values in another sysfs file.
704
705 If libsensors is extended to support 64 bit values, this could be revisited.
706*/
707#define LM93_ALARM_IN1 0x00000001
708#define LM93_ALARM_IN2 0x00000002
709#define LM93_ALARM_IN3 0x00000004
710#define LM93_ALARM_IN4 0x00000008
711#define LM93_ALARM_IN5 0x00000010
712#define LM93_ALARM_IN6 0x00000020
713#define LM93_ALARM_IN7 0x00000040
714#define LM93_ALARM_IN8 0x00000080
715#define LM93_ALARM_IN9 0x00000100
716#define LM93_ALARM_IN10 0x00000200
717#define LM93_ALARM_IN11 0x00000400
718#define LM93_ALARM_IN12 0x00000800
719#define LM93_ALARM_IN13 0x00001000
720#define LM93_ALARM_IN14 0x00002000
721#define LM93_ALARM_IN15 0x00004000
722#define LM93_ALARM_IN16 0x00008000
723#define LM93_ALARM_FAN1 0x00010000
724#define LM93_ALARM_FAN2 0x00020000
725#define LM93_ALARM_FAN3 0x00040000
726#define LM93_ALARM_FAN4 0x00080000
727#define LM93_ALARM_PH1_ERR 0x00100000
728#define LM93_ALARM_PH2_ERR 0x00200000
729#define LM93_ALARM_SCSI1_ERR 0x00400000
730#define LM93_ALARM_SCSI2_ERR 0x00800000
731#define LM93_ALARM_DVDDP1_ERR 0x01000000
732#define LM93_ALARM_DVDDP2_ERR 0x02000000
733#define LM93_ALARM_D1_ERR 0x04000000
734#define LM93_ALARM_D2_ERR 0x08000000
735#define LM93_ALARM_TEMP1 0x10000000
736#define LM93_ALARM_TEMP2 0x20000000
737#define LM93_ALARM_TEMP3 0x40000000
738
739static unsigned LM93_ALARMS_FROM_REG(struct block1_t b1)
740{
741 unsigned result;
742 result = b1.host_status_2 & 0x3f;
743
744 if (vccp_limit_type[0])
745 result |= (b1.host_status_4 & 0x10) << 2;
746 else
747 result |= b1.host_status_2 & 0x40;
748
749 if (vccp_limit_type[1])
750 result |= (b1.host_status_4 & 0x20) << 2;
751 else
752 result |= b1.host_status_2 & 0x80;
753
754 result |= b1.host_status_3 << 8;
755 result |= (b1.fan_status & 0x0f) << 16;
756 result |= (b1.p1_prochot_status & 0x80) << 13;
757 result |= (b1.p2_prochot_status & 0x80) << 14;
758 result |= (b1.host_status_4 & 0xfc) << 20;
759 result |= (b1.host_status_1 & 0x07) << 28;
760 return result;
761}
762
763#define MAX_RETRIES 5
764
765static u8 lm93_read_byte(struct i2c_client *client, u8 reg)
766{
767 int value, i;
768
769 /* retry in case of read errors */
770 for (i=1; i<=MAX_RETRIES; i++) {
771 if ((value = i2c_smbus_read_byte_data(client, reg)) >= 0) {
772 return value;
773 } else {
774 dev_warn(&client->dev,"lm93: read byte data failed, "
775 "address 0x%02x.\n", reg);
776 mdelay(i + 3);
777 }
778
779 }
780
781 /* <TODO> what to return in case of error? */
782 dev_err(&client->dev,"lm93: All read byte retries failed!!\n");
783 return 0;
784}
785
786static int lm93_write_byte(struct i2c_client *client, u8 reg, u8 value)
787{
788 int result;
789
790 /* <TODO> how to handle write errors? */
791 result = i2c_smbus_write_byte_data(client, reg, value);
792
793 if (result < 0)
794 dev_warn(&client->dev,"lm93: write byte data failed, "
795 "0x%02x at address 0x%02x.\n", value, reg);
796
797 return result;
798}
799
800static u16 lm93_read_word(struct i2c_client *client, u8 reg)
801{
802 int value, i;
803
804 /* retry in case of read errors */
805 for (i=1; i<=MAX_RETRIES; i++) {
806 if ((value = i2c_smbus_read_word_data(client, reg)) >= 0) {
807 return value;
808 } else {
809 dev_warn(&client->dev,"lm93: read word data failed, "
810 "address 0x%02x.\n", reg);
811 mdelay(i + 3);
812 }
813
814 }
815
816 /* <TODO> what to return in case of error? */
817 dev_err(&client->dev,"lm93: All read word retries failed!!\n");
818 return 0;
819}
820
821static int lm93_write_word(struct i2c_client *client, u8 reg, u16 value)
822{
823 int result;
824
825 /* <TODO> how to handle write errors? */
826 result = i2c_smbus_write_word_data(client, reg, value);
827
828 if (result < 0)
829 dev_warn(&client->dev,"lm93: write word data failed, "
830 "0x%04x at address 0x%02x.\n", value, reg);
831
832 return result;
833}
834
835static u8 lm93_block_buffer[I2C_SMBUS_BLOCK_MAX];
836
837/*
838 read block data into values, retry if not expected length
839 fbn => index to lm93_block_read_cmds table
840 (Fixed Block Number - section 14.5.2 of LM93 datasheet)
841*/
842static void lm93_read_block(struct i2c_client *client, u8 fbn, u8 *values)
843{
844 int i, result=0;
845
846 for (i = 1; i <= MAX_RETRIES; i++) {
847 result = i2c_smbus_read_block_data(client,
848 lm93_block_read_cmds[fbn].cmd, lm93_block_buffer);
849
850 if (result == lm93_block_read_cmds[fbn].len) {
851 break;
852 } else {
853 dev_warn(&client->dev,"lm93: block read data failed, "
854 "command 0x%02x.\n",
855 lm93_block_read_cmds[fbn].cmd);
856 mdelay(i + 3);
857 }
858 }
859
860 if (result == lm93_block_read_cmds[fbn].len) {
861 memcpy(values,lm93_block_buffer,lm93_block_read_cmds[fbn].len);
862 } else {
863 /* <TODO> what to do in case of error? */
864 }
865}
866
867static struct lm93_data *lm93_update_device(struct device *dev)
868{
869 struct i2c_client *client = to_i2c_client(dev);
870 struct lm93_data *data = i2c_get_clientdata(client);
871 const unsigned long interval = HZ + (HZ / 2);
872
873 mutex_lock(&data->update_lock);
874
875 if (time_after(jiffies, data->last_updated + interval) ||
876 !data->valid) {
877
878 data->update(data, client);
879 data->last_updated = jiffies;
880 data->valid = 1;
881 }
882
883 mutex_unlock(&data->update_lock);
884 return data;
885}
886
887/* update routine for data that has no corresponding SMBus block command */
888static void lm93_update_client_common(struct lm93_data *data,
889 struct i2c_client *client)
890{
891 int i;
892 u8 *ptr;
893
894 /* temp1 - temp4: limits */
895 for (i = 0; i < 4; i++) {
896 data->temp_lim[i].min =
897 lm93_read_byte(client, LM93_REG_TEMP_MIN(i));
898 data->temp_lim[i].max =
899 lm93_read_byte(client, LM93_REG_TEMP_MAX(i));
900 }
901
902 /* config register */
903 data->config = lm93_read_byte(client, LM93_REG_CONFIG);
904
905 /* vid1 - vid2: values */
906 for (i = 0; i < 2; i++)
907 data->vid[i] = lm93_read_byte(client, LM93_REG_VID(i));
908
909 /* prochot1 - prochot2: limits */
910 for (i = 0; i < 2; i++)
911 data->prochot_max[i] = lm93_read_byte(client,
912 LM93_REG_PROCHOT_MAX(i));
913
914 /* vccp1 - vccp2: VID relative limits */
915 for (i = 0; i < 2; i++)
916 data->vccp_limits[i] = lm93_read_byte(client,
917 LM93_REG_VCCP_LIMIT_OFF(i));
918
919 /* GPIO input state */
920 data->gpi = lm93_read_byte(client, LM93_REG_GPI);
921
922 /* #PROCHOT override state */
923 data->prochot_override = lm93_read_byte(client,
924 LM93_REG_PROCHOT_OVERRIDE);
925
926 /* #PROCHOT intervals */
927 data->prochot_interval = lm93_read_byte(client,
928 LM93_REG_PROCHOT_INTERVAL);
929
930 /* Fan Boost Temperature registers */
931 for (i = 0; i < 4; i++)
932 data->boost[i] = lm93_read_byte(client, LM93_REG_BOOST(i));
933
934 /* Fan Boost Temperature Hyst. registers */
935 data->boost_hyst[0] = lm93_read_byte(client, LM93_REG_BOOST_HYST_12);
936 data->boost_hyst[1] = lm93_read_byte(client, LM93_REG_BOOST_HYST_34);
937
938 /* Temperature Zone Min. PWM & Hysteresis registers */
939 data->auto_pwm_min_hyst[0] =
940 lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_12);
941 data->auto_pwm_min_hyst[1] =
942 lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_34);
943
944 /* #PROCHOT & #VRDHOT PWM Ramp Control register */
945 data->pwm_ramp_ctl = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL);
946
947 /* misc setup registers */
948 data->sfc1 = lm93_read_byte(client, LM93_REG_SFC1);
949 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
950 data->sf_tach_to_pwm = lm93_read_byte(client,
951 LM93_REG_SF_TACH_TO_PWM);
952
953 /* write back alarm values to clear */
954 for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++)
955 lm93_write_byte(client, LM93_REG_HOST_ERROR_1 + i, *(ptr + i));
956}
957
958/* update routine which uses SMBus block data commands */
959static void lm93_update_client_full(struct lm93_data *data,
960 struct i2c_client *client)
961{
962 dev_dbg(&client->dev,"starting device update (block data enabled)\n");
963
964 /* in1 - in16: values & limits */
965 lm93_read_block(client, 3, (u8 *)(data->block3));
966 lm93_read_block(client, 7, (u8 *)(data->block7));
967
968 /* temp1 - temp4: values */
969 lm93_read_block(client, 2, (u8 *)(data->block2));
970
971 /* prochot1 - prochot2: values */
972 lm93_read_block(client, 4, (u8 *)(data->block4));
973
974 /* fan1 - fan4: values & limits */
975 lm93_read_block(client, 5, (u8 *)(data->block5));
976 lm93_read_block(client, 8, (u8 *)(data->block8));
977
978 /* pmw control registers */
979 lm93_read_block(client, 9, (u8 *)(data->block9));
980
981 /* alarm values */
982 lm93_read_block(client, 1, (u8 *)(&data->block1));
983
984 /* auto/pwm registers */
985 lm93_read_block(client, 10, (u8 *)(&data->block10));
986
987 lm93_update_client_common(data, client);
988}
989
990/* update routine which uses SMBus byte/word data commands only */
991static void lm93_update_client_min(struct lm93_data *data,
992 struct i2c_client *client)
993{
994 int i,j;
995 u8 *ptr;
996
997 dev_dbg(&client->dev,"starting device update (block data disabled)\n");
998
999 /* in1 - in16: values & limits */
1000 for (i = 0; i < 16; i++) {
1001 data->block3[i] =
1002 lm93_read_byte(client, LM93_REG_IN(i));
1003 data->block7[i].min =
1004 lm93_read_byte(client, LM93_REG_IN_MIN(i));
1005 data->block7[i].max =
1006 lm93_read_byte(client, LM93_REG_IN_MAX(i));
1007 }
1008
1009 /* temp1 - temp4: values */
1010 for (i = 0; i < 4; i++) {
1011 data->block2[i] =
1012 lm93_read_byte(client, LM93_REG_TEMP(i));
1013 }
1014
1015 /* prochot1 - prochot2: values */
1016 for (i = 0; i < 2; i++) {
1017 data->block4[i].cur =
1018 lm93_read_byte(client, LM93_REG_PROCHOT_CUR(i));
1019 data->block4[i].avg =
1020 lm93_read_byte(client, LM93_REG_PROCHOT_AVG(i));
1021 }
1022
1023 /* fan1 - fan4: values & limits */
1024 for (i = 0; i < 4; i++) {
1025 data->block5[i] =
1026 lm93_read_word(client, LM93_REG_FAN(i));
1027 data->block8[i] =
1028 lm93_read_word(client, LM93_REG_FAN_MIN(i));
1029 }
1030
1031 /* pwm control registers */
1032 for (i = 0; i < 2; i++) {
1033 for (j = 0; j < 4; j++) {
1034 data->block9[i][j] =
1035 lm93_read_byte(client, LM93_REG_PWM_CTL(i,j));
1036 }
1037 }
1038
1039 /* alarm values */
1040 for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++) {
1041 *(ptr + i) =
1042 lm93_read_byte(client, LM93_REG_HOST_ERROR_1 + i);
1043 }
1044
1045 /* auto/pwm (base temp) registers */
1046 for (i = 0; i < 4; i++) {
1047 data->block10.base[i] =
1048 lm93_read_byte(client, LM93_REG_TEMP_BASE(i));
1049 }
1050
1051 /* auto/pwm (offset temp) registers */
1052 for (i = 0; i < 12; i++) {
1053 data->block10.offset[i] =
1054 lm93_read_byte(client, LM93_REG_TEMP_OFFSET(i));
1055 }
1056
1057 lm93_update_client_common(data, client);
1058}
1059
1060/* following are the sysfs callback functions */
1061static ssize_t show_in(struct device *dev, struct device_attribute *attr,
1062 char *buf)
1063{
1064 int nr = (to_sensor_dev_attr(attr))->index;
1065
1066 struct lm93_data *data = lm93_update_device(dev);
1067 return sprintf(buf, "%d\n", LM93_IN_FROM_REG(nr, data->block3[nr]));
1068}
1069
1070static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 0);
1071static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 1);
1072static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 2);
1073static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in, NULL, 3);
1074static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in, NULL, 4);
1075static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in, NULL, 5);
1076static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_in, NULL, 6);
1077static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_in, NULL, 7);
1078static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, show_in, NULL, 8);
1079static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, show_in, NULL, 9);
1080static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, show_in, NULL, 10);
1081static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, show_in, NULL, 11);
1082static SENSOR_DEVICE_ATTR(in13_input, S_IRUGO, show_in, NULL, 12);
1083static SENSOR_DEVICE_ATTR(in14_input, S_IRUGO, show_in, NULL, 13);
1084static SENSOR_DEVICE_ATTR(in15_input, S_IRUGO, show_in, NULL, 14);
1085static SENSOR_DEVICE_ATTR(in16_input, S_IRUGO, show_in, NULL, 15);
1086
1087static ssize_t show_in_min(struct device *dev,
1088 struct device_attribute *attr, char *buf)
1089{
1090 int nr = (to_sensor_dev_attr(attr))->index;
1091 struct lm93_data *data = lm93_update_device(dev);
1092 int vccp = nr - 6;
1093 long rc, vid;
1094
1095 if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) {
1096 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1097 rc = LM93_IN_MIN_FROM_REG(data->vccp_limits[vccp], vid);
1098 }
1099 else {
1100 rc = LM93_IN_FROM_REG(nr, data->block7[nr].min); \
1101 }
1102 return sprintf(buf, "%ld\n", rc); \
1103}
1104
1105static ssize_t store_in_min(struct device *dev, struct device_attribute *attr,
1106 const char *buf, size_t count)
1107{
1108 int nr = (to_sensor_dev_attr(attr))->index;
1109 struct i2c_client *client = to_i2c_client(dev);
1110 struct lm93_data *data = i2c_get_clientdata(client);
1111 u32 val = simple_strtoul(buf, NULL, 10);
1112 int vccp = nr - 6;
1113 long vid;
1114
1115 mutex_lock(&data->update_lock);
1116 if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) {
1117 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1118 data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0xf0) |
1119 LM93_IN_REL_TO_REG(val, 0, vid);
1120 lm93_write_byte(client, LM93_REG_VCCP_LIMIT_OFF(vccp),
1121 data->vccp_limits[vccp]);
1122 }
1123 else {
1124 data->block7[nr].min = LM93_IN_TO_REG(nr,val);
1125 lm93_write_byte(client, LM93_REG_IN_MIN(nr),
1126 data->block7[nr].min);
1127 }
1128 mutex_unlock(&data->update_lock);
1129 return count;
1130}
1131
1132static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO,
1133 show_in_min, store_in_min, 0);
1134static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO,
1135 show_in_min, store_in_min, 1);
1136static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO,
1137 show_in_min, store_in_min, 2);
1138static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO,
1139 show_in_min, store_in_min, 3);
1140static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO,
1141 show_in_min, store_in_min, 4);
1142static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO,
1143 show_in_min, store_in_min, 5);
1144static SENSOR_DEVICE_ATTR(in7_min, S_IWUSR | S_IRUGO,
1145 show_in_min, store_in_min, 6);
1146static SENSOR_DEVICE_ATTR(in8_min, S_IWUSR | S_IRUGO,
1147 show_in_min, store_in_min, 7);
1148static SENSOR_DEVICE_ATTR(in9_min, S_IWUSR | S_IRUGO,
1149 show_in_min, store_in_min, 8);
1150static SENSOR_DEVICE_ATTR(in10_min, S_IWUSR | S_IRUGO,
1151 show_in_min, store_in_min, 9);
1152static SENSOR_DEVICE_ATTR(in11_min, S_IWUSR | S_IRUGO,
1153 show_in_min, store_in_min, 10);
1154static SENSOR_DEVICE_ATTR(in12_min, S_IWUSR | S_IRUGO,
1155 show_in_min, store_in_min, 11);
1156static SENSOR_DEVICE_ATTR(in13_min, S_IWUSR | S_IRUGO,
1157 show_in_min, store_in_min, 12);
1158static SENSOR_DEVICE_ATTR(in14_min, S_IWUSR | S_IRUGO,
1159 show_in_min, store_in_min, 13);
1160static SENSOR_DEVICE_ATTR(in15_min, S_IWUSR | S_IRUGO,
1161 show_in_min, store_in_min, 14);
1162static SENSOR_DEVICE_ATTR(in16_min, S_IWUSR | S_IRUGO,
1163 show_in_min, store_in_min, 15);
1164
1165static ssize_t show_in_max(struct device *dev,
1166 struct device_attribute *attr, char *buf)
1167{
1168 int nr = (to_sensor_dev_attr(attr))->index;
1169 struct lm93_data *data = lm93_update_device(dev);
1170 int vccp = nr - 6;
1171 long rc, vid;
1172
1173 if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) {
1174 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1175 rc = LM93_IN_MAX_FROM_REG(data->vccp_limits[vccp],vid);
1176 }
1177 else {
1178 rc = LM93_IN_FROM_REG(nr,data->block7[nr].max); \
1179 }
1180 return sprintf(buf,"%ld\n",rc); \
1181}
1182
1183static ssize_t store_in_max(struct device *dev, struct device_attribute *attr,
1184 const char *buf, size_t count)
1185{
1186 int nr = (to_sensor_dev_attr(attr))->index;
1187 struct i2c_client *client = to_i2c_client(dev);
1188 struct lm93_data *data = i2c_get_clientdata(client);
1189 u32 val = simple_strtoul(buf, NULL, 10);
1190 int vccp = nr - 6;
1191 long vid;
1192
1193 mutex_lock(&data->update_lock);
1194 if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) {
1195 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1196 data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0x0f) |
1197 LM93_IN_REL_TO_REG(val, 1, vid);
1198 lm93_write_byte(client, LM93_REG_VCCP_LIMIT_OFF(vccp),
1199 data->vccp_limits[vccp]);
1200 }
1201 else {
1202 data->block7[nr].max = LM93_IN_TO_REG(nr,val);
1203 lm93_write_byte(client, LM93_REG_IN_MAX(nr),
1204 data->block7[nr].max);
1205 }
1206 mutex_unlock(&data->update_lock);
1207 return count;
1208}
1209
1210static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO,
1211 show_in_max, store_in_max, 0);
1212static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO,
1213 show_in_max, store_in_max, 1);
1214static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO,
1215 show_in_max, store_in_max, 2);
1216static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO,
1217 show_in_max, store_in_max, 3);
1218static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO,
1219 show_in_max, store_in_max, 4);
1220static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO,
1221 show_in_max, store_in_max, 5);
1222static SENSOR_DEVICE_ATTR(in7_max, S_IWUSR | S_IRUGO,
1223 show_in_max, store_in_max, 6);
1224static SENSOR_DEVICE_ATTR(in8_max, S_IWUSR | S_IRUGO,
1225 show_in_max, store_in_max, 7);
1226static SENSOR_DEVICE_ATTR(in9_max, S_IWUSR | S_IRUGO,
1227 show_in_max, store_in_max, 8);
1228static SENSOR_DEVICE_ATTR(in10_max, S_IWUSR | S_IRUGO,
1229 show_in_max, store_in_max, 9);
1230static SENSOR_DEVICE_ATTR(in11_max, S_IWUSR | S_IRUGO,
1231 show_in_max, store_in_max, 10);
1232static SENSOR_DEVICE_ATTR(in12_max, S_IWUSR | S_IRUGO,
1233 show_in_max, store_in_max, 11);
1234static SENSOR_DEVICE_ATTR(in13_max, S_IWUSR | S_IRUGO,
1235 show_in_max, store_in_max, 12);
1236static SENSOR_DEVICE_ATTR(in14_max, S_IWUSR | S_IRUGO,
1237 show_in_max, store_in_max, 13);
1238static SENSOR_DEVICE_ATTR(in15_max, S_IWUSR | S_IRUGO,
1239 show_in_max, store_in_max, 14);
1240static SENSOR_DEVICE_ATTR(in16_max, S_IWUSR | S_IRUGO,
1241 show_in_max, store_in_max, 15);
1242
1243static ssize_t show_temp(struct device *dev,
1244 struct device_attribute *attr, char *buf)
1245{
1246 int nr = (to_sensor_dev_attr(attr))->index;
1247 struct lm93_data *data = lm93_update_device(dev);
1248 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->block2[nr]));
1249}
1250
1251static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
1252static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
1253static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
1254
1255static ssize_t show_temp_min(struct device *dev,
1256 struct device_attribute *attr, char *buf)
1257{
1258 int nr = (to_sensor_dev_attr(attr))->index;
1259 struct lm93_data *data = lm93_update_device(dev);
1260 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->temp_lim[nr].min));
1261}
1262
1263static ssize_t store_temp_min(struct device *dev, struct device_attribute *attr,
1264 const char *buf, size_t count)
1265{
1266 int nr = (to_sensor_dev_attr(attr))->index;
1267 struct i2c_client *client = to_i2c_client(dev);
1268 struct lm93_data *data = i2c_get_clientdata(client);
1269 long val = simple_strtol(buf, NULL, 10);
1270
1271 mutex_lock(&data->update_lock);
1272 data->temp_lim[nr].min = LM93_TEMP_TO_REG(val);
1273 lm93_write_byte(client, LM93_REG_TEMP_MIN(nr), data->temp_lim[nr].min);
1274 mutex_unlock(&data->update_lock);
1275 return count;
1276}
1277
1278static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO,
1279 show_temp_min, store_temp_min, 0);
1280static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO,
1281 show_temp_min, store_temp_min, 1);
1282static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO,
1283 show_temp_min, store_temp_min, 2);
1284
1285static ssize_t show_temp_max(struct device *dev,
1286 struct device_attribute *attr, char *buf)
1287{
1288 int nr = (to_sensor_dev_attr(attr))->index;
1289 struct lm93_data *data = lm93_update_device(dev);
1290 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->temp_lim[nr].max));
1291}
1292
1293static ssize_t store_temp_max(struct device *dev, struct device_attribute *attr,
1294 const char *buf, size_t count)
1295{
1296 int nr = (to_sensor_dev_attr(attr))->index;
1297 struct i2c_client *client = to_i2c_client(dev);
1298 struct lm93_data *data = i2c_get_clientdata(client);
1299 long val = simple_strtol(buf, NULL, 10);
1300
1301 mutex_lock(&data->update_lock);
1302 data->temp_lim[nr].max = LM93_TEMP_TO_REG(val);
1303 lm93_write_byte(client, LM93_REG_TEMP_MAX(nr), data->temp_lim[nr].max);
1304 mutex_unlock(&data->update_lock);
1305 return count;
1306}
1307
1308static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
1309 show_temp_max, store_temp_max, 0);
1310static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO,
1311 show_temp_max, store_temp_max, 1);
1312static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO,
1313 show_temp_max, store_temp_max, 2);
1314
1315static ssize_t show_temp_auto_base(struct device *dev,
1316 struct device_attribute *attr, char *buf)
1317{
1318 int nr = (to_sensor_dev_attr(attr))->index;
1319 struct lm93_data *data = lm93_update_device(dev);
1320 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->block10.base[nr]));
1321}
1322
1323static ssize_t store_temp_auto_base(struct device *dev,
1324 struct device_attribute *attr,
1325 const char *buf, size_t count)
1326{
1327 int nr = (to_sensor_dev_attr(attr))->index;
1328 struct i2c_client *client = to_i2c_client(dev);
1329 struct lm93_data *data = i2c_get_clientdata(client);
1330 long val = simple_strtol(buf, NULL, 10);
1331
1332 mutex_lock(&data->update_lock);
1333 data->block10.base[nr] = LM93_TEMP_TO_REG(val);
1334 lm93_write_byte(client, LM93_REG_TEMP_BASE(nr), data->block10.base[nr]);
1335 mutex_unlock(&data->update_lock);
1336 return count;
1337}
1338
1339static SENSOR_DEVICE_ATTR(temp1_auto_base, S_IWUSR | S_IRUGO,
1340 show_temp_auto_base, store_temp_auto_base, 0);
1341static SENSOR_DEVICE_ATTR(temp2_auto_base, S_IWUSR | S_IRUGO,
1342 show_temp_auto_base, store_temp_auto_base, 1);
1343static SENSOR_DEVICE_ATTR(temp3_auto_base, S_IWUSR | S_IRUGO,
1344 show_temp_auto_base, store_temp_auto_base, 2);
1345
1346static ssize_t show_temp_auto_boost(struct device *dev,
1347 struct device_attribute *attr,char *buf)
1348{
1349 int nr = (to_sensor_dev_attr(attr))->index;
1350 struct lm93_data *data = lm93_update_device(dev);
1351 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->boost[nr]));
1352}
1353
1354static ssize_t store_temp_auto_boost(struct device *dev,
1355 struct device_attribute *attr,
1356 const char *buf, size_t count)
1357{
1358 int nr = (to_sensor_dev_attr(attr))->index;
1359 struct i2c_client *client = to_i2c_client(dev);
1360 struct lm93_data *data = i2c_get_clientdata(client);
1361 long val = simple_strtol(buf, NULL, 10);
1362
1363 mutex_lock(&data->update_lock);
1364 data->boost[nr] = LM93_TEMP_TO_REG(val);
1365 lm93_write_byte(client, LM93_REG_BOOST(nr), data->boost[nr]);
1366 mutex_unlock(&data->update_lock);
1367 return count;
1368}
1369
1370static SENSOR_DEVICE_ATTR(temp1_auto_boost, S_IWUSR | S_IRUGO,
1371 show_temp_auto_boost, store_temp_auto_boost, 0);
1372static SENSOR_DEVICE_ATTR(temp2_auto_boost, S_IWUSR | S_IRUGO,
1373 show_temp_auto_boost, store_temp_auto_boost, 1);
1374static SENSOR_DEVICE_ATTR(temp3_auto_boost, S_IWUSR | S_IRUGO,
1375 show_temp_auto_boost, store_temp_auto_boost, 2);
1376
1377static ssize_t show_temp_auto_boost_hyst(struct device *dev,
1378 struct device_attribute *attr,
1379 char *buf)
1380{
1381 int nr = (to_sensor_dev_attr(attr))->index;
1382 struct lm93_data *data = lm93_update_device(dev);
1383 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr);
1384 return sprintf(buf,"%d\n",
1385 LM93_AUTO_BOOST_HYST_FROM_REGS(data, nr, mode));
1386}
1387
1388static ssize_t store_temp_auto_boost_hyst(struct device *dev,
1389 struct device_attribute *attr,
1390 const char *buf, size_t count)
1391{
1392 int nr = (to_sensor_dev_attr(attr))->index;
1393 struct i2c_client *client = to_i2c_client(dev);
1394 struct lm93_data *data = i2c_get_clientdata(client);
1395 u32 val = simple_strtoul(buf, NULL, 10);
1396
1397 mutex_lock(&data->update_lock);
1398 /* force 0.5C/bit mode */
1399 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1400 data->sfc2 |= ((nr < 2) ? 0x10 : 0x20);
1401 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1402 data->boost_hyst[nr/2] = LM93_AUTO_BOOST_HYST_TO_REG(data, val, nr, 1);
1403 lm93_write_byte(client, LM93_REG_BOOST_HYST(nr),
1404 data->boost_hyst[nr/2]);
1405 mutex_unlock(&data->update_lock);
1406 return count;
1407}
1408
1409static SENSOR_DEVICE_ATTR(temp1_auto_boost_hyst, S_IWUSR | S_IRUGO,
1410 show_temp_auto_boost_hyst,
1411 store_temp_auto_boost_hyst, 0);
1412static SENSOR_DEVICE_ATTR(temp2_auto_boost_hyst, S_IWUSR | S_IRUGO,
1413 show_temp_auto_boost_hyst,
1414 store_temp_auto_boost_hyst, 1);
1415static SENSOR_DEVICE_ATTR(temp3_auto_boost_hyst, S_IWUSR | S_IRUGO,
1416 show_temp_auto_boost_hyst,
1417 store_temp_auto_boost_hyst, 2);
1418
1419static ssize_t show_temp_auto_offset(struct device *dev,
1420 struct device_attribute *attr, char *buf)
1421{
1422 struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr);
1423 int nr = s_attr->index;
1424 int ofs = s_attr->nr;
1425 struct lm93_data *data = lm93_update_device(dev);
1426 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr);
1427 return sprintf(buf,"%d\n",
1428 LM93_TEMP_AUTO_OFFSET_FROM_REG(data->block10.offset[ofs],
1429 nr,mode));
1430}
1431
1432static ssize_t store_temp_auto_offset(struct device *dev,
1433 struct device_attribute *attr,
1434 const char *buf, size_t count)
1435{
1436 struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr);
1437 int nr = s_attr->index;
1438 int ofs = s_attr->nr;
1439 struct i2c_client *client = to_i2c_client(dev);
1440 struct lm93_data *data = i2c_get_clientdata(client);
1441 u32 val = simple_strtoul(buf, NULL, 10);
1442
1443 mutex_lock(&data->update_lock);
1444 /* force 0.5C/bit mode */
1445 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1446 data->sfc2 |= ((nr < 2) ? 0x10 : 0x20);
1447 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1448 data->block10.offset[ofs] = LM93_TEMP_AUTO_OFFSET_TO_REG(
1449 data->block10.offset[ofs], val, nr, 1);
1450 lm93_write_byte(client, LM93_REG_TEMP_OFFSET(ofs),
1451 data->block10.offset[ofs]);
1452 mutex_unlock(&data->update_lock);
1453 return count;
1454}
1455
1456static SENSOR_DEVICE_ATTR_2(temp1_auto_offset1, S_IWUSR | S_IRUGO,
1457 show_temp_auto_offset, store_temp_auto_offset, 0, 0);
1458static SENSOR_DEVICE_ATTR_2(temp1_auto_offset2, S_IWUSR | S_IRUGO,
1459 show_temp_auto_offset, store_temp_auto_offset, 1, 0);
1460static SENSOR_DEVICE_ATTR_2(temp1_auto_offset3, S_IWUSR | S_IRUGO,
1461 show_temp_auto_offset, store_temp_auto_offset, 2, 0);
1462static SENSOR_DEVICE_ATTR_2(temp1_auto_offset4, S_IWUSR | S_IRUGO,
1463 show_temp_auto_offset, store_temp_auto_offset, 3, 0);
1464static SENSOR_DEVICE_ATTR_2(temp1_auto_offset5, S_IWUSR | S_IRUGO,
1465 show_temp_auto_offset, store_temp_auto_offset, 4, 0);
1466static SENSOR_DEVICE_ATTR_2(temp1_auto_offset6, S_IWUSR | S_IRUGO,
1467 show_temp_auto_offset, store_temp_auto_offset, 5, 0);
1468static SENSOR_DEVICE_ATTR_2(temp1_auto_offset7, S_IWUSR | S_IRUGO,
1469 show_temp_auto_offset, store_temp_auto_offset, 6, 0);
1470static SENSOR_DEVICE_ATTR_2(temp1_auto_offset8, S_IWUSR | S_IRUGO,
1471 show_temp_auto_offset, store_temp_auto_offset, 7, 0);
1472static SENSOR_DEVICE_ATTR_2(temp1_auto_offset9, S_IWUSR | S_IRUGO,
1473 show_temp_auto_offset, store_temp_auto_offset, 8, 0);
1474static SENSOR_DEVICE_ATTR_2(temp1_auto_offset10, S_IWUSR | S_IRUGO,
1475 show_temp_auto_offset, store_temp_auto_offset, 9, 0);
1476static SENSOR_DEVICE_ATTR_2(temp1_auto_offset11, S_IWUSR | S_IRUGO,
1477 show_temp_auto_offset, store_temp_auto_offset, 10, 0);
1478static SENSOR_DEVICE_ATTR_2(temp1_auto_offset12, S_IWUSR | S_IRUGO,
1479 show_temp_auto_offset, store_temp_auto_offset, 11, 0);
1480static SENSOR_DEVICE_ATTR_2(temp2_auto_offset1, S_IWUSR | S_IRUGO,
1481 show_temp_auto_offset, store_temp_auto_offset, 0, 1);
1482static SENSOR_DEVICE_ATTR_2(temp2_auto_offset2, S_IWUSR | S_IRUGO,
1483 show_temp_auto_offset, store_temp_auto_offset, 1, 1);
1484static SENSOR_DEVICE_ATTR_2(temp2_auto_offset3, S_IWUSR | S_IRUGO,
1485 show_temp_auto_offset, store_temp_auto_offset, 2, 1);
1486static SENSOR_DEVICE_ATTR_2(temp2_auto_offset4, S_IWUSR | S_IRUGO,
1487 show_temp_auto_offset, store_temp_auto_offset, 3, 1);
1488static SENSOR_DEVICE_ATTR_2(temp2_auto_offset5, S_IWUSR | S_IRUGO,
1489 show_temp_auto_offset, store_temp_auto_offset, 4, 1);
1490static SENSOR_DEVICE_ATTR_2(temp2_auto_offset6, S_IWUSR | S_IRUGO,
1491 show_temp_auto_offset, store_temp_auto_offset, 5, 1);
1492static SENSOR_DEVICE_ATTR_2(temp2_auto_offset7, S_IWUSR | S_IRUGO,
1493 show_temp_auto_offset, store_temp_auto_offset, 6, 1);
1494static SENSOR_DEVICE_ATTR_2(temp2_auto_offset8, S_IWUSR | S_IRUGO,
1495 show_temp_auto_offset, store_temp_auto_offset, 7, 1);
1496static SENSOR_DEVICE_ATTR_2(temp2_auto_offset9, S_IWUSR | S_IRUGO,
1497 show_temp_auto_offset, store_temp_auto_offset, 8, 1);
1498static SENSOR_DEVICE_ATTR_2(temp2_auto_offset10, S_IWUSR | S_IRUGO,
1499 show_temp_auto_offset, store_temp_auto_offset, 9, 1);
1500static SENSOR_DEVICE_ATTR_2(temp2_auto_offset11, S_IWUSR | S_IRUGO,
1501 show_temp_auto_offset, store_temp_auto_offset, 10, 1);
1502static SENSOR_DEVICE_ATTR_2(temp2_auto_offset12, S_IWUSR | S_IRUGO,
1503 show_temp_auto_offset, store_temp_auto_offset, 11, 1);
1504static SENSOR_DEVICE_ATTR_2(temp3_auto_offset1, S_IWUSR | S_IRUGO,
1505 show_temp_auto_offset, store_temp_auto_offset, 0, 2);
1506static SENSOR_DEVICE_ATTR_2(temp3_auto_offset2, S_IWUSR | S_IRUGO,
1507 show_temp_auto_offset, store_temp_auto_offset, 1, 2);
1508static SENSOR_DEVICE_ATTR_2(temp3_auto_offset3, S_IWUSR | S_IRUGO,
1509 show_temp_auto_offset, store_temp_auto_offset, 2, 2);
1510static SENSOR_DEVICE_ATTR_2(temp3_auto_offset4, S_IWUSR | S_IRUGO,
1511 show_temp_auto_offset, store_temp_auto_offset, 3, 2);
1512static SENSOR_DEVICE_ATTR_2(temp3_auto_offset5, S_IWUSR | S_IRUGO,
1513 show_temp_auto_offset, store_temp_auto_offset, 4, 2);
1514static SENSOR_DEVICE_ATTR_2(temp3_auto_offset6, S_IWUSR | S_IRUGO,
1515 show_temp_auto_offset, store_temp_auto_offset, 5, 2);
1516static SENSOR_DEVICE_ATTR_2(temp3_auto_offset7, S_IWUSR | S_IRUGO,
1517 show_temp_auto_offset, store_temp_auto_offset, 6, 2);
1518static SENSOR_DEVICE_ATTR_2(temp3_auto_offset8, S_IWUSR | S_IRUGO,
1519 show_temp_auto_offset, store_temp_auto_offset, 7, 2);
1520static SENSOR_DEVICE_ATTR_2(temp3_auto_offset9, S_IWUSR | S_IRUGO,
1521 show_temp_auto_offset, store_temp_auto_offset, 8, 2);
1522static SENSOR_DEVICE_ATTR_2(temp3_auto_offset10, S_IWUSR | S_IRUGO,
1523 show_temp_auto_offset, store_temp_auto_offset, 9, 2);
1524static SENSOR_DEVICE_ATTR_2(temp3_auto_offset11, S_IWUSR | S_IRUGO,
1525 show_temp_auto_offset, store_temp_auto_offset, 10, 2);
1526static SENSOR_DEVICE_ATTR_2(temp3_auto_offset12, S_IWUSR | S_IRUGO,
1527 show_temp_auto_offset, store_temp_auto_offset, 11, 2);
1528
1529static ssize_t show_temp_auto_pwm_min(struct device *dev,
1530 struct device_attribute *attr, char *buf)
1531{
1532 int nr = (to_sensor_dev_attr(attr))->index;
1533 u8 reg, ctl4;
1534 struct lm93_data *data = lm93_update_device(dev);
1535 reg = data->auto_pwm_min_hyst[nr/2] >> 4 & 0x0f;
1536 ctl4 = data->block9[nr][LM93_PWM_CTL4];
1537 return sprintf(buf,"%d\n",LM93_PWM_FROM_REG(reg, (ctl4 & 0x07) ?
1538 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ));
1539}
1540
1541static ssize_t store_temp_auto_pwm_min(struct device *dev,
1542 struct device_attribute *attr,
1543 const char *buf, size_t count)
1544{
1545 int nr = (to_sensor_dev_attr(attr))->index;
1546 struct i2c_client *client = to_i2c_client(dev);
1547 struct lm93_data *data = i2c_get_clientdata(client);
1548 u32 val = simple_strtoul(buf, NULL, 10);
1549 u8 reg, ctl4;
1550
1551 mutex_lock(&data->update_lock);
1552 reg = lm93_read_byte(client, LM93_REG_PWM_MIN_HYST(nr));
1553 ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4));
1554 reg = (reg & 0x0f) |
1555 LM93_PWM_TO_REG(val, (ctl4 & 0x07) ?
1556 LM93_PWM_MAP_LO_FREQ :
1557 LM93_PWM_MAP_HI_FREQ) << 4;
1558 data->auto_pwm_min_hyst[nr/2] = reg;
1559 lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg);
1560 mutex_unlock(&data->update_lock);
1561 return count;
1562}
1563
1564static SENSOR_DEVICE_ATTR(temp1_auto_pwm_min, S_IWUSR | S_IRUGO,
1565 show_temp_auto_pwm_min,
1566 store_temp_auto_pwm_min, 0);
1567static SENSOR_DEVICE_ATTR(temp2_auto_pwm_min, S_IWUSR | S_IRUGO,
1568 show_temp_auto_pwm_min,
1569 store_temp_auto_pwm_min, 1);
1570static SENSOR_DEVICE_ATTR(temp3_auto_pwm_min, S_IWUSR | S_IRUGO,
1571 show_temp_auto_pwm_min,
1572 store_temp_auto_pwm_min, 2);
1573
1574static ssize_t show_temp_auto_offset_hyst(struct device *dev,
1575 struct device_attribute *attr, char *buf)
1576{
1577 int nr = (to_sensor_dev_attr(attr))->index;
1578 struct lm93_data *data = lm93_update_device(dev);
1579 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr);
1580 return sprintf(buf,"%d\n",LM93_TEMP_OFFSET_FROM_REG(
1581 data->auto_pwm_min_hyst[nr/2], mode));
1582}
1583
1584static ssize_t store_temp_auto_offset_hyst(struct device *dev,
1585 struct device_attribute *attr,
1586 const char *buf, size_t count)
1587{
1588 int nr = (to_sensor_dev_attr(attr))->index;
1589 struct i2c_client *client = to_i2c_client(dev);
1590 struct lm93_data *data = i2c_get_clientdata(client);
1591 u32 val = simple_strtoul(buf, NULL, 10);
1592 u8 reg;
1593
1594 mutex_lock(&data->update_lock);
1595 /* force 0.5C/bit mode */
1596 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1597 data->sfc2 |= ((nr < 2) ? 0x10 : 0x20);
1598 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1599 reg = data->auto_pwm_min_hyst[nr/2];
1600 reg = (reg & 0xf0) | (LM93_TE…
Large files files are truncated, but you can click here to view the full file