1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/slab.h>
33#include <linux/jiffies.h>
34#include <linux/i2c.h>
35#include <linux/platform_device.h>
36#include <linux/hwmon.h>
37#include <linux/hwmon-sysfs.h>
38#include <linux/hwmon-vid.h>
39#include <linux/err.h>
40#include <linux/mutex.h>
41#include <linux/acpi.h>
42#include <linux/io.h>
43
44
45static struct platform_device *pdev;
46
47
48static bool force_start;
49module_param(force_start, bool, 0);
50MODULE_PARM_DESC(force_start, "Force the chip to start monitoring inputs");
51
52static unsigned short force_id;
53module_param(force_id, ushort, 0);
54MODULE_PARM_DESC(force_id, "Override the detected device ID");
55
56static bool probe_all_addr;
57module_param(probe_all_addr, bool, 0);
58MODULE_PARM_DESC(probe_all_addr,
59 "Include probing of non-standard LPC addresses");
60
61
62static const unsigned short normal_i2c[] = {0x2c, 0x2d, 0x2e, I2C_CLIENT_END};
63
64enum chips { dme1737, sch5027, sch311x, sch5127 };
65
66#define DO_REPORT "Please report to the driver maintainer."
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87#define DME1737_REG_IN(ix) ((ix) < 5 ? 0x20 + (ix) : \
88 (ix) < 7 ? 0x94 + (ix) : \
89 0x1f)
90#define DME1737_REG_IN_MIN(ix) ((ix) < 5 ? 0x44 + (ix) * 2 \
91 : 0x91 + (ix) * 2)
92#define DME1737_REG_IN_MAX(ix) ((ix) < 5 ? 0x45 + (ix) * 2 \
93 : 0x92 + (ix) * 2)
94
95
96#define DME1737_REG_TEMP(ix) (0x25 + (ix))
97#define DME1737_REG_TEMP_MIN(ix) (0x4e + (ix) * 2)
98#define DME1737_REG_TEMP_MAX(ix) (0x4f + (ix) * 2)
99#define DME1737_REG_TEMP_OFFSET(ix) ((ix) == 0 ? 0x1f \
100 : 0x1c + (ix))
101
102
103
104
105
106
107
108
109
110
111
112#define DME1737_REG_IN_TEMP_LSB(ix) (0x84 + (ix))
113static const u8 DME1737_REG_IN_LSB[] = {3, 4, 4, 3, 2, 0, 0, 5};
114static const u8 DME1737_REG_IN_LSB_SHL[] = {4, 4, 0, 0, 0, 0, 4, 4};
115static const u8 DME1737_REG_TEMP_LSB[] = {1, 2, 1};
116static const u8 DME1737_REG_TEMP_LSB_SHL[] = {4, 4, 0};
117
118
119#define DME1737_REG_FAN(ix) ((ix) < 4 ? 0x28 + (ix) * 2 \
120 : 0xa1 + (ix) * 2)
121#define DME1737_REG_FAN_MIN(ix) ((ix) < 4 ? 0x54 + (ix) * 2 \
122 : 0xa5 + (ix) * 2)
123#define DME1737_REG_FAN_OPT(ix) ((ix) < 4 ? 0x90 + (ix) \
124 : 0xb2 + (ix))
125#define DME1737_REG_FAN_MAX(ix) (0xb4 + (ix))
126
127
128#define DME1737_REG_PWM(ix) ((ix) < 3 ? 0x30 + (ix) \
129 : 0xa1 + (ix))
130#define DME1737_REG_PWM_CONFIG(ix) (0x5c + (ix))
131#define DME1737_REG_PWM_MIN(ix) (0x64 + (ix))
132#define DME1737_REG_PWM_FREQ(ix) ((ix) < 3 ? 0x5f + (ix) \
133 : 0xa3 + (ix))
134
135
136
137
138
139
140#define DME1737_REG_PWM_RR(ix) (0x62 + (ix))
141
142
143#define DME1737_REG_ZONE_LOW(ix) (0x67 + (ix))
144#define DME1737_REG_ZONE_ABS(ix) (0x6a + (ix))
145
146
147
148
149
150
151#define DME1737_REG_ZONE_HYST(ix) (0x6d + (ix))
152
153
154
155
156
157
158#define DME1737_REG_ALARM1 0x41
159#define DME1737_REG_ALARM2 0x42
160#define DME1737_REG_ALARM3 0x83
161static const u8 DME1737_BIT_ALARM_IN[] = {0, 1, 2, 3, 8, 16, 17, 18};
162static const u8 DME1737_BIT_ALARM_TEMP[] = {4, 5, 6};
163static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23};
164
165
166#define DME1737_REG_DEVICE 0x3d
167#define DME1737_REG_COMPANY 0x3e
168#define DME1737_REG_VERSTEP 0x3f
169#define DME1737_REG_CONFIG 0x40
170#define DME1737_REG_CONFIG2 0x7f
171#define DME1737_REG_VID 0x43
172#define DME1737_REG_TACH_PWM 0x81
173
174
175
176
177
178
179#define DME1737_COMPANY_SMSC 0x5c
180#define DME1737_VERSTEP 0x88
181#define DME1737_VERSTEP_MASK 0xf8
182#define SCH311X_DEVICE 0x8c
183#define SCH5027_VERSTEP 0x69
184#define SCH5127_DEVICE 0x8e
185
186
187#define DME1737_ID_1 0x77
188#define DME1737_ID_2 0x78
189#define SCH3112_ID 0x7c
190#define SCH3114_ID 0x7d
191#define SCH3116_ID 0x7f
192#define SCH5027_ID 0x89
193#define SCH5127_ID 0x86
194
195
196#define DME1737_EXTENT 2
197
198
199#define HAS_TEMP_OFFSET (1 << 0)
200#define HAS_VID (1 << 1)
201#define HAS_ZONE3 (1 << 2)
202#define HAS_ZONE_HYST (1 << 3)
203#define HAS_PWM_MIN (1 << 4)
204#define HAS_FAN(ix) (1 << ((ix) + 5))
205#define HAS_PWM(ix) (1 << ((ix) + 11))
206#define HAS_IN7 (1 << 17)
207
208
209
210
211
212struct dme1737_data {
213 struct i2c_client *client;
214 struct device *hwmon_dev;
215 const char *name;
216 unsigned int addr;
217
218 struct mutex update_lock;
219 int valid;
220 unsigned long last_update;
221 unsigned long last_vbat;
222 enum chips type;
223 const int *in_nominal;
224
225 u8 vid;
226 u8 pwm_rr_en;
227 u32 has_features;
228
229
230 u16 in[8];
231 u8 in_min[8];
232 u8 in_max[8];
233 s16 temp[3];
234 s8 temp_min[3];
235 s8 temp_max[3];
236 s8 temp_offset[3];
237 u8 config;
238 u8 config2;
239 u8 vrm;
240 u16 fan[6];
241 u16 fan_min[6];
242 u8 fan_max[2];
243 u8 fan_opt[6];
244 u8 pwm[6];
245 u8 pwm_min[3];
246 u8 pwm_config[3];
247 u8 pwm_acz[3];
248 u8 pwm_freq[6];
249 u8 pwm_rr[2];
250 s8 zone_low[3];
251 s8 zone_abs[3];
252 u8 zone_hyst[2];
253 u32 alarms;
254};
255
256
257static const int IN_NOMINAL_DME1737[] = {5000, 2250, 3300, 5000, 12000, 3300,
258 3300};
259static const int IN_NOMINAL_SCH311x[] = {2500, 1500, 3300, 5000, 12000, 3300,
260 3300};
261static const int IN_NOMINAL_SCH5027[] = {5000, 2250, 3300, 1125, 1125, 3300,
262 3300};
263static const int IN_NOMINAL_SCH5127[] = {2500, 2250, 3300, 1125, 1125, 3300,
264 3300, 1500};
265#define IN_NOMINAL(type) ((type) == sch311x ? IN_NOMINAL_SCH311x : \
266 (type) == sch5027 ? IN_NOMINAL_SCH5027 : \
267 (type) == sch5127 ? IN_NOMINAL_SCH5127 : \
268 IN_NOMINAL_DME1737)
269
270
271
272
273
274
275static inline int IN_FROM_REG(int reg, int nominal, int res)
276{
277 return (reg * nominal + (3 << (res - 3))) / (3 << (res - 2));
278}
279
280static inline int IN_TO_REG(long val, int nominal)
281{
282 val = clamp_val(val, 0, 255 * nominal / 192);
283 return DIV_ROUND_CLOSEST(val * 192, nominal);
284}
285
286
287
288
289
290
291
292static inline int TEMP_FROM_REG(int reg, int res)
293{
294 return (reg * 1000) >> (res - 8);
295}
296
297static inline int TEMP_TO_REG(long val)
298{
299 val = clamp_val(val, -128000, 127000);
300 return DIV_ROUND_CLOSEST(val, 1000);
301}
302
303
304static const int TEMP_RANGE[] = {2000, 2500, 3333, 4000, 5000, 6666, 8000,
305 10000, 13333, 16000, 20000, 26666, 32000,
306 40000, 53333, 80000};
307
308static inline int TEMP_RANGE_FROM_REG(int reg)
309{
310 return TEMP_RANGE[(reg >> 4) & 0x0f];
311}
312
313static int TEMP_RANGE_TO_REG(long val, int reg)
314{
315 int i;
316
317 for (i = 15; i > 0; i--) {
318 if (val > (TEMP_RANGE[i] + TEMP_RANGE[i - 1] + 1) / 2)
319 break;
320 }
321
322 return (reg & 0x0f) | (i << 4);
323}
324
325
326
327
328
329
330
331static inline int TEMP_HYST_FROM_REG(int reg, int ix)
332{
333 return (((ix == 1) ? reg : reg >> 4) & 0x0f) * 1000;
334}
335
336static inline int TEMP_HYST_TO_REG(int temp, long hyst, int ix, int reg)
337{
338 hyst = clamp_val(hyst, temp - 15000, temp);
339 hyst = DIV_ROUND_CLOSEST(temp - hyst, 1000);
340
341 return (ix == 1) ? (reg & 0xf0) | hyst : (reg & 0x0f) | (hyst << 4);
342}
343
344
345static inline int FAN_FROM_REG(int reg, int tpc)
346{
347 if (tpc)
348 return tpc * reg;
349 else
350 return (reg == 0 || reg == 0xffff) ? 0 : 90000 * 60 / reg;
351}
352
353static inline int FAN_TO_REG(long val, int tpc)
354{
355 if (tpc) {
356 return clamp_val(val / tpc, 0, 0xffff);
357 } else {
358 return (val <= 0) ? 0xffff :
359 clamp_val(90000 * 60 / val, 0, 0xfffe);
360 }
361}
362
363
364
365
366
367
368static inline int FAN_TPC_FROM_REG(int reg)
369{
370 return (reg & 0x20) ? 0 : 60 >> (reg & 0x03);
371}
372
373
374
375
376
377
378static inline int FAN_TYPE_FROM_REG(int reg)
379{
380 int edge = (reg >> 1) & 0x03;
381
382 return (edge > 0) ? 1 << (edge - 1) : 0;
383}
384
385static inline int FAN_TYPE_TO_REG(long val, int reg)
386{
387 int edge = (val == 4) ? 3 : val;
388
389 return (reg & 0xf9) | (edge << 1);
390}
391
392
393static const int FAN_MAX[] = {0x54, 0x38, 0x2a, 0x21, 0x1c, 0x18, 0x15, 0x12,
394 0x11, 0x0f, 0x0e};
395
396static int FAN_MAX_FROM_REG(int reg)
397{
398 int i;
399
400 for (i = 10; i > 0; i--) {
401 if (reg == FAN_MAX[i])
402 break;
403 }
404
405 return 1000 + i * 500;
406}
407
408static int FAN_MAX_TO_REG(long val)
409{
410 int i;
411
412 for (i = 10; i > 0; i--) {
413 if (val > (1000 + (i - 1) * 500))
414 break;
415 }
416
417 return FAN_MAX[i];
418}
419
420
421
422
423
424
425
426
427
428
429
430
431
432static inline int PWM_EN_FROM_REG(int reg)
433{
434 static const int en[] = {2, 2, 2, 0, -1, 2, 2, 1};
435
436 return en[(reg >> 5) & 0x07];
437}
438
439static inline int PWM_EN_TO_REG(int val, int reg)
440{
441 int en = (val == 1) ? 7 : 3;
442
443 return (reg & 0x1f) | ((en & 0x07) << 5);
444}
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459static inline int PWM_ACZ_FROM_REG(int reg)
460{
461 static const int acz[] = {1, 2, 4, 0, 0, 6, 7, 0};
462
463 return acz[(reg >> 5) & 0x07];
464}
465
466static inline int PWM_ACZ_TO_REG(long val, int reg)
467{
468 int acz = (val == 4) ? 2 : val - 1;
469
470 return (reg & 0x1f) | ((acz & 0x07) << 5);
471}
472
473
474static const int PWM_FREQ[] = {11, 15, 22, 29, 35, 44, 59, 88,
475 15000, 20000, 30000, 25000, 0, 0, 0, 0};
476
477static inline int PWM_FREQ_FROM_REG(int reg)
478{
479 return PWM_FREQ[reg & 0x0f];
480}
481
482static int PWM_FREQ_TO_REG(long val, int reg)
483{
484 int i;
485
486
487 if (val > 27500) {
488 i = 10;
489 } else if (val > 22500) {
490 i = 11;
491 } else {
492 for (i = 9; i > 0; i--) {
493 if (val > (PWM_FREQ[i] + PWM_FREQ[i - 1] + 1) / 2)
494 break;
495 }
496 }
497
498 return (reg & 0xf0) | i;
499}
500
501
502
503
504
505
506
507static const u8 PWM_RR[] = {206, 104, 69, 41, 26, 18, 10, 5};
508
509static inline int PWM_RR_FROM_REG(int reg, int ix)
510{
511 int rr = (ix == 1) ? reg >> 4 : reg;
512
513 return (rr & 0x08) ? PWM_RR[rr & 0x07] : 0;
514}
515
516static int PWM_RR_TO_REG(long val, int ix, int reg)
517{
518 int i;
519
520 for (i = 0; i < 7; i++) {
521 if (val > (PWM_RR[i] + PWM_RR[i + 1] + 1) / 2)
522 break;
523 }
524
525 return (ix == 1) ? (reg & 0x8f) | (i << 4) : (reg & 0xf8) | i;
526}
527
528
529static inline int PWM_RR_EN_FROM_REG(int reg, int ix)
530{
531 return PWM_RR_FROM_REG(reg, ix) ? 1 : 0;
532}
533
534static inline int PWM_RR_EN_TO_REG(long val, int ix, int reg)
535{
536 int en = (ix == 1) ? 0x80 : 0x08;
537
538 return val ? reg | en : reg & ~en;
539}
540
541
542
543
544
545
546static inline int PWM_OFF_FROM_REG(int reg, int ix)
547{
548 return (reg >> (ix + 5)) & 0x01;
549}
550
551static inline int PWM_OFF_TO_REG(int val, int ix, int reg)
552{
553 return (reg & ~(1 << (ix + 5))) | ((val & 0x01) << (ix + 5));
554}
555
556
557
558
559
560
561
562
563
564
565static u8 dme1737_read(const struct dme1737_data *data, u8 reg)
566{
567 struct i2c_client *client = data->client;
568 s32 val;
569
570 if (client) {
571 val = i2c_smbus_read_byte_data(client, reg);
572
573 if (val < 0) {
574 dev_warn(&client->dev,
575 "Read from register 0x%02x failed! %s\n",
576 reg, DO_REPORT);
577 }
578 } else {
579 outb(reg, data->addr);
580 val = inb(data->addr + 1);
581 }
582
583 return val;
584}
585
586static s32 dme1737_write(const struct dme1737_data *data, u8 reg, u8 val)
587{
588 struct i2c_client *client = data->client;
589 s32 res = 0;
590
591 if (client) {
592 res = i2c_smbus_write_byte_data(client, reg, val);
593
594 if (res < 0) {
595 dev_warn(&client->dev,
596 "Write to register 0x%02x failed! %s\n",
597 reg, DO_REPORT);
598 }
599 } else {
600 outb(reg, data->addr);
601 outb(val, data->addr + 1);
602 }
603
604 return res;
605}
606
607static struct dme1737_data *dme1737_update_device(struct device *dev)
608{
609 struct dme1737_data *data = dev_get_drvdata(dev);
610 int ix;
611 u8 lsb[6];
612
613 mutex_lock(&data->update_lock);
614
615
616 if (time_after(jiffies, data->last_vbat + 600 * HZ) || !data->valid) {
617 dme1737_write(data, DME1737_REG_CONFIG, dme1737_read(data,
618 DME1737_REG_CONFIG) | 0x10);
619 data->last_vbat = jiffies;
620 }
621
622
623 if (time_after(jiffies, data->last_update + HZ) || !data->valid) {
624 if (data->has_features & HAS_VID) {
625 data->vid = dme1737_read(data, DME1737_REG_VID) &
626 0x3f;
627 }
628
629
630 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) {
631
632
633
634
635
636 if (ix == 7 && !(data->has_features & HAS_IN7))
637 continue;
638 data->in[ix] = dme1737_read(data,
639 DME1737_REG_IN(ix)) << 8;
640 data->in_min[ix] = dme1737_read(data,
641 DME1737_REG_IN_MIN(ix));
642 data->in_max[ix] = dme1737_read(data,
643 DME1737_REG_IN_MAX(ix));
644 }
645
646
647 for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) {
648
649
650
651
652
653
654
655 data->temp[ix] = dme1737_read(data,
656 DME1737_REG_TEMP(ix)) << 8;
657 data->temp_min[ix] = dme1737_read(data,
658 DME1737_REG_TEMP_MIN(ix));
659 data->temp_max[ix] = dme1737_read(data,
660 DME1737_REG_TEMP_MAX(ix));
661 if (data->has_features & HAS_TEMP_OFFSET) {
662 data->temp_offset[ix] = dme1737_read(data,
663 DME1737_REG_TEMP_OFFSET(ix));
664 }
665 }
666
667
668
669
670
671
672
673 for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) {
674 if (ix == 5 && !(data->has_features & HAS_IN7))
675 continue;
676 lsb[ix] = dme1737_read(data,
677 DME1737_REG_IN_TEMP_LSB(ix));
678 }
679 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) {
680 if (ix == 7 && !(data->has_features & HAS_IN7))
681 continue;
682 data->in[ix] |= (lsb[DME1737_REG_IN_LSB[ix]] <<
683 DME1737_REG_IN_LSB_SHL[ix]) & 0xf0;
684 }
685 for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) {
686 data->temp[ix] |= (lsb[DME1737_REG_TEMP_LSB[ix]] <<
687 DME1737_REG_TEMP_LSB_SHL[ix]) & 0xf0;
688 }
689
690
691 for (ix = 0; ix < ARRAY_SIZE(data->fan); ix++) {
692
693
694
695
696 if (!(data->has_features & HAS_FAN(ix)))
697 continue;
698 data->fan[ix] = dme1737_read(data,
699 DME1737_REG_FAN(ix));
700 data->fan[ix] |= dme1737_read(data,
701 DME1737_REG_FAN(ix) + 1) << 8;
702 data->fan_min[ix] = dme1737_read(data,
703 DME1737_REG_FAN_MIN(ix));
704 data->fan_min[ix] |= dme1737_read(data,
705 DME1737_REG_FAN_MIN(ix) + 1) << 8;
706 data->fan_opt[ix] = dme1737_read(data,
707 DME1737_REG_FAN_OPT(ix));
708
709 if (ix > 3) {
710 data->fan_max[ix - 4] = dme1737_read(data,
711 DME1737_REG_FAN_MAX(ix));
712 }
713 }
714
715
716 for (ix = 0; ix < ARRAY_SIZE(data->pwm); ix++) {
717
718
719
720
721 if (!(data->has_features & HAS_PWM(ix)))
722 continue;
723 data->pwm[ix] = dme1737_read(data,
724 DME1737_REG_PWM(ix));
725 data->pwm_freq[ix] = dme1737_read(data,
726 DME1737_REG_PWM_FREQ(ix));
727
728 if (ix < 3) {
729 data->pwm_config[ix] = dme1737_read(data,
730 DME1737_REG_PWM_CONFIG(ix));
731 data->pwm_min[ix] = dme1737_read(data,
732 DME1737_REG_PWM_MIN(ix));
733 }
734 }
735 for (ix = 0; ix < ARRAY_SIZE(data->pwm_rr); ix++) {
736 data->pwm_rr[ix] = dme1737_read(data,
737 DME1737_REG_PWM_RR(ix));
738 }
739
740
741 for (ix = 0; ix < ARRAY_SIZE(data->zone_low); ix++) {
742
743 if ((ix == 2) && !(data->has_features & HAS_ZONE3))
744 continue;
745
746 if ((ix == 1) && (data->type == sch5127)) {
747 data->zone_low[1] = dme1737_read(data,
748 DME1737_REG_ZONE_LOW(2));
749 data->zone_abs[1] = dme1737_read(data,
750 DME1737_REG_ZONE_ABS(2));
751 } else {
752 data->zone_low[ix] = dme1737_read(data,
753 DME1737_REG_ZONE_LOW(ix));
754 data->zone_abs[ix] = dme1737_read(data,
755 DME1737_REG_ZONE_ABS(ix));
756 }
757 }
758 if (data->has_features & HAS_ZONE_HYST) {
759 for (ix = 0; ix < ARRAY_SIZE(data->zone_hyst); ix++) {
760 data->zone_hyst[ix] = dme1737_read(data,
761 DME1737_REG_ZONE_HYST(ix));
762 }
763 }
764
765
766 data->alarms = dme1737_read(data,
767 DME1737_REG_ALARM1);
768
769
770
771
772 if (data->alarms & 0x80) {
773 data->alarms |= dme1737_read(data,
774 DME1737_REG_ALARM2) << 8;
775 data->alarms |= dme1737_read(data,
776 DME1737_REG_ALARM3) << 16;
777 }
778
779
780
781
782
783
784 if (!data->client) {
785 if (data->alarms & 0xff0000)
786 dme1737_write(data, DME1737_REG_ALARM3, 0xff);
787 if (data->alarms & 0xff00)
788 dme1737_write(data, DME1737_REG_ALARM2, 0xff);
789 if (data->alarms & 0xff)
790 dme1737_write(data, DME1737_REG_ALARM1, 0xff);
791 }
792
793 data->last_update = jiffies;
794 data->valid = 1;
795 }
796
797 mutex_unlock(&data->update_lock);
798
799 return data;
800}
801
802
803
804
805
806
807#define SYS_IN_INPUT 0
808#define SYS_IN_MIN 1
809#define SYS_IN_MAX 2
810#define SYS_IN_ALARM 3
811
812static ssize_t show_in(struct device *dev, struct device_attribute *attr,
813 char *buf)
814{
815 struct dme1737_data *data = dme1737_update_device(dev);
816 struct sensor_device_attribute_2
817 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
818 int ix = sensor_attr_2->index;
819 int fn = sensor_attr_2->nr;
820 int res;
821
822 switch (fn) {
823 case SYS_IN_INPUT:
824 res = IN_FROM_REG(data->in[ix], data->in_nominal[ix], 16);
825 break;
826 case SYS_IN_MIN:
827 res = IN_FROM_REG(data->in_min[ix], data->in_nominal[ix], 8);
828 break;
829 case SYS_IN_MAX:
830 res = IN_FROM_REG(data->in_max[ix], data->in_nominal[ix], 8);
831 break;
832 case SYS_IN_ALARM:
833 res = (data->alarms >> DME1737_BIT_ALARM_IN[ix]) & 0x01;
834 break;
835 default:
836 res = 0;
837 dev_dbg(dev, "Unknown function %d.\n", fn);
838 }
839
840 return sprintf(buf, "%d\n", res);
841}
842
843static ssize_t set_in(struct device *dev, struct device_attribute *attr,
844 const char *buf, size_t count)
845{
846 struct dme1737_data *data = dev_get_drvdata(dev);
847 struct sensor_device_attribute_2
848 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
849 int ix = sensor_attr_2->index;
850 int fn = sensor_attr_2->nr;
851 long val;
852 int err;
853
854 err = kstrtol(buf, 10, &val);
855 if (err)
856 return err;
857
858 mutex_lock(&data->update_lock);
859 switch (fn) {
860 case SYS_IN_MIN:
861 data->in_min[ix] = IN_TO_REG(val, data->in_nominal[ix]);
862 dme1737_write(data, DME1737_REG_IN_MIN(ix),
863 data->in_min[ix]);
864 break;
865 case SYS_IN_MAX:
866 data->in_max[ix] = IN_TO_REG(val, data->in_nominal[ix]);
867 dme1737_write(data, DME1737_REG_IN_MAX(ix),
868 data->in_max[ix]);
869 break;
870 default:
871 dev_dbg(dev, "Unknown function %d.\n", fn);
872 }
873 mutex_unlock(&data->update_lock);
874
875 return count;
876}
877
878
879
880
881
882
883#define SYS_TEMP_INPUT 0
884#define SYS_TEMP_MIN 1
885#define SYS_TEMP_MAX 2
886#define SYS_TEMP_OFFSET 3
887#define SYS_TEMP_ALARM 4
888#define SYS_TEMP_FAULT 5
889
890static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
891 char *buf)
892{
893 struct dme1737_data *data = dme1737_update_device(dev);
894 struct sensor_device_attribute_2
895 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
896 int ix = sensor_attr_2->index;
897 int fn = sensor_attr_2->nr;
898 int res;
899
900 switch (fn) {
901 case SYS_TEMP_INPUT:
902 res = TEMP_FROM_REG(data->temp[ix], 16);
903 break;
904 case SYS_TEMP_MIN:
905 res = TEMP_FROM_REG(data->temp_min[ix], 8);
906 break;
907 case SYS_TEMP_MAX:
908 res = TEMP_FROM_REG(data->temp_max[ix], 8);
909 break;
910 case SYS_TEMP_OFFSET:
911 res = TEMP_FROM_REG(data->temp_offset[ix], 8);
912 break;
913 case SYS_TEMP_ALARM:
914 res = (data->alarms >> DME1737_BIT_ALARM_TEMP[ix]) & 0x01;
915 break;
916 case SYS_TEMP_FAULT:
917 res = (((u16)data->temp[ix] & 0xff00) == 0x8000);
918 break;
919 default:
920 res = 0;
921 dev_dbg(dev, "Unknown function %d.\n", fn);
922 }
923
924 return sprintf(buf, "%d\n", res);
925}
926
927static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
928 const char *buf, size_t count)
929{
930 struct dme1737_data *data = dev_get_drvdata(dev);
931 struct sensor_device_attribute_2
932 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
933 int ix = sensor_attr_2->index;
934 int fn = sensor_attr_2->nr;
935 long val;
936 int err;
937
938 err = kstrtol(buf, 10, &val);
939 if (err)
940 return err;
941
942 mutex_lock(&data->update_lock);
943 switch (fn) {
944 case SYS_TEMP_MIN:
945 data->temp_min[ix] = TEMP_TO_REG(val);
946 dme1737_write(data, DME1737_REG_TEMP_MIN(ix),
947 data->temp_min[ix]);
948 break;
949 case SYS_TEMP_MAX:
950 data->temp_max[ix] = TEMP_TO_REG(val);
951 dme1737_write(data, DME1737_REG_TEMP_MAX(ix),
952 data->temp_max[ix]);
953 break;
954 case SYS_TEMP_OFFSET:
955 data->temp_offset[ix] = TEMP_TO_REG(val);
956 dme1737_write(data, DME1737_REG_TEMP_OFFSET(ix),
957 data->temp_offset[ix]);
958 break;
959 default:
960 dev_dbg(dev, "Unknown function %d.\n", fn);
961 }
962 mutex_unlock(&data->update_lock);
963
964 return count;
965}
966
967
968
969
970
971
972#define SYS_ZONE_AUTO_CHANNELS_TEMP 0
973#define SYS_ZONE_AUTO_POINT1_TEMP_HYST 1
974#define SYS_ZONE_AUTO_POINT1_TEMP 2
975#define SYS_ZONE_AUTO_POINT2_TEMP 3
976#define SYS_ZONE_AUTO_POINT3_TEMP 4
977
978static ssize_t show_zone(struct device *dev, struct device_attribute *attr,
979 char *buf)
980{
981 struct dme1737_data *data = dme1737_update_device(dev);
982 struct sensor_device_attribute_2
983 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
984 int ix = sensor_attr_2->index;
985 int fn = sensor_attr_2->nr;
986 int res;
987
988 switch (fn) {
989 case SYS_ZONE_AUTO_CHANNELS_TEMP:
990
991 if ((ix == 1) && (data->config2 & 0x02))
992 res = 4;
993 else
994 res = 1 << ix;
995 break;
996 case SYS_ZONE_AUTO_POINT1_TEMP_HYST:
997 res = TEMP_FROM_REG(data->zone_low[ix], 8) -
998 TEMP_HYST_FROM_REG(data->zone_hyst[ix == 2], ix);
999 break;
1000 case SYS_ZONE_AUTO_POINT1_TEMP:
1001 res = TEMP_FROM_REG(data->zone_low[ix], 8);
1002 break;
1003 case SYS_ZONE_AUTO_POINT2_TEMP:
1004
1005 res = TEMP_FROM_REG(data->zone_low[ix], 8) +
1006 TEMP_RANGE_FROM_REG(data->pwm_freq[ix]);
1007 break;
1008 case SYS_ZONE_AUTO_POINT3_TEMP:
1009 res = TEMP_FROM_REG(data->zone_abs[ix], 8);
1010 break;
1011 default:
1012 res = 0;
1013 dev_dbg(dev, "Unknown function %d.\n", fn);
1014 }
1015
1016 return sprintf(buf, "%d\n", res);
1017}
1018
1019static ssize_t set_zone(struct device *dev, struct device_attribute *attr,
1020 const char *buf, size_t count)
1021{
1022 struct dme1737_data *data = dev_get_drvdata(dev);
1023 struct sensor_device_attribute_2
1024 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
1025 int ix = sensor_attr_2->index;
1026 int fn = sensor_attr_2->nr;
1027 long val;
1028 int temp;
1029 int err;
1030 u8 reg;
1031
1032 err = kstrtol(buf, 10, &val);
1033 if (err)
1034 return err;
1035
1036 mutex_lock(&data->update_lock);
1037 switch (fn) {
1038 case SYS_ZONE_AUTO_POINT1_TEMP_HYST:
1039
1040 data->zone_low[ix] = dme1737_read(data,
1041 DME1737_REG_ZONE_LOW(ix));
1042
1043 temp = TEMP_FROM_REG(data->zone_low[ix], 8);
1044 reg = dme1737_read(data, DME1737_REG_ZONE_HYST(ix == 2));
1045 data->zone_hyst[ix == 2] = TEMP_HYST_TO_REG(temp, val, ix, reg);
1046 dme1737_write(data, DME1737_REG_ZONE_HYST(ix == 2),
1047 data->zone_hyst[ix == 2]);
1048 break;
1049 case SYS_ZONE_AUTO_POINT1_TEMP:
1050 data->zone_low[ix] = TEMP_TO_REG(val);
1051 dme1737_write(data, DME1737_REG_ZONE_LOW(ix),
1052 data->zone_low[ix]);
1053 break;
1054 case SYS_ZONE_AUTO_POINT2_TEMP:
1055
1056 data->zone_low[ix] = dme1737_read(data,
1057 DME1737_REG_ZONE_LOW(ix));
1058
1059
1060
1061
1062 temp = TEMP_FROM_REG(data->zone_low[ix], 8);
1063 val = clamp_val(val, temp, temp + 80000);
1064 reg = dme1737_read(data, DME1737_REG_PWM_FREQ(ix));
1065 data->pwm_freq[ix] = TEMP_RANGE_TO_REG(val - temp, reg);
1066 dme1737_write(data, DME1737_REG_PWM_FREQ(ix),
1067 data->pwm_freq[ix]);
1068 break;
1069 case SYS_ZONE_AUTO_POINT3_TEMP:
1070 data->zone_abs[ix] = TEMP_TO_REG(val);
1071 dme1737_write(data, DME1737_REG_ZONE_ABS(ix),
1072 data->zone_abs[ix]);
1073 break;
1074 default:
1075 dev_dbg(dev, "Unknown function %d.\n", fn);
1076 }
1077 mutex_unlock(&data->update_lock);
1078
1079 return count;
1080}
1081
1082
1083
1084
1085
1086
1087#define SYS_FAN_INPUT 0
1088#define SYS_FAN_MIN 1
1089#define SYS_FAN_MAX 2
1090#define SYS_FAN_ALARM 3
1091#define SYS_FAN_TYPE 4
1092
1093static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
1094 char *buf)
1095{
1096 struct dme1737_data *data = dme1737_update_device(dev);
1097 struct sensor_device_attribute_2
1098 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
1099 int ix = sensor_attr_2->index;
1100 int fn = sensor_attr_2->nr;
1101 int res;
1102
1103 switch (fn) {
1104 case SYS_FAN_INPUT:
1105 res = FAN_FROM_REG(data->fan[ix],
1106 ix < 4 ? 0 :
1107 FAN_TPC_FROM_REG(data->fan_opt[ix]));
1108 break;
1109 case SYS_FAN_MIN:
1110 res = FAN_FROM_REG(data->fan_min[ix],
1111 ix < 4 ? 0 :
1112 FAN_TPC_FROM_REG(data->fan_opt[ix]));
1113 break;
1114 case SYS_FAN_MAX:
1115
1116 res = FAN_MAX_FROM_REG(data->fan_max[ix - 4]);
1117 break;
1118 case SYS_FAN_ALARM:
1119 res = (data->alarms >> DME1737_BIT_ALARM_FAN[ix]) & 0x01;
1120 break;
1121 case SYS_FAN_TYPE:
1122
1123 res = FAN_TYPE_FROM_REG(data->fan_opt[ix]);
1124 break;
1125 default:
1126 res = 0;
1127 dev_dbg(dev, "Unknown function %d.\n", fn);
1128 }
1129
1130 return sprintf(buf, "%d\n", res);
1131}
1132
1133static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
1134 const char *buf, size_t count)
1135{
1136 struct dme1737_data *data = dev_get_drvdata(dev);
1137 struct sensor_device_attribute_2
1138 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
1139 int ix = sensor_attr_2->index;
1140 int fn = sensor_attr_2->nr;
1141 long val;
1142 int err;
1143
1144 err = kstrtol(buf, 10, &val);
1145 if (err)
1146 return err;
1147
1148 mutex_lock(&data->update_lock);
1149 switch (fn) {
1150 case SYS_FAN_MIN:
1151 if (ix < 4) {
1152 data->fan_min[ix] = FAN_TO_REG(val, 0);
1153 } else {
1154
1155 data->fan_opt[ix] = dme1737_read(data,
1156 DME1737_REG_FAN_OPT(ix));
1157
1158 data->fan_min[ix] = FAN_TO_REG(val,
1159 FAN_TPC_FROM_REG(data->fan_opt[ix]));
1160 }
1161 dme1737_write(data, DME1737_REG_FAN_MIN(ix),
1162 data->fan_min[ix] & 0xff);
1163 dme1737_write(data, DME1737_REG_FAN_MIN(ix) + 1,
1164 data->fan_min[ix] >> 8);
1165 break;
1166 case SYS_FAN_MAX:
1167
1168 data->fan_max[ix - 4] = FAN_MAX_TO_REG(val);
1169 dme1737_write(data, DME1737_REG_FAN_MAX(ix),
1170 data->fan_max[ix - 4]);
1171 break;
1172 case SYS_FAN_TYPE:
1173
1174 if (!(val == 1 || val == 2 || val == 4)) {
1175 count = -EINVAL;
1176 dev_warn(dev,
1177 "Fan type value %ld not supported. Choose one of 1, 2, or 4.\n",
1178 val);
1179 goto exit;
1180 }
1181 data->fan_opt[ix] = FAN_TYPE_TO_REG(val, dme1737_read(data,
1182 DME1737_REG_FAN_OPT(ix)));
1183 dme1737_write(data, DME1737_REG_FAN_OPT(ix),
1184 data->fan_opt[ix]);
1185 break;
1186 default:
1187 dev_dbg(dev, "Unknown function %d.\n", fn);
1188 }
1189exit:
1190 mutex_unlock(&data->update_lock);
1191
1192 return count;
1193}
1194
1195
1196
1197
1198
1199
1200#define SYS_PWM 0
1201#define SYS_PWM_FREQ 1
1202#define SYS_PWM_ENABLE 2
1203#define SYS_PWM_RAMP_RATE 3
1204#define SYS_PWM_AUTO_CHANNELS_ZONE 4
1205#define SYS_PWM_AUTO_PWM_MIN 5
1206#define SYS_PWM_AUTO_POINT1_PWM 6
1207#define SYS_PWM_AUTO_POINT2_PWM 7
1208
1209static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
1210 char *buf)
1211{
1212 struct dme1737_data *data = dme1737_update_device(dev);
1213 struct sensor_device_attribute_2
1214 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
1215 int ix = sensor_attr_2->index;
1216 int fn = sensor_attr_2->nr;
1217 int res;
1218
1219 switch (fn) {
1220 case SYS_PWM:
1221 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 0)
1222 res = 255;
1223 else
1224 res = data->pwm[ix];
1225 break;
1226 case SYS_PWM_FREQ:
1227 res = PWM_FREQ_FROM_REG(data->pwm_freq[ix]);
1228 break;
1229 case SYS_PWM_ENABLE:
1230 if (ix >= 3)
1231 res = 1;
1232 else
1233 res = PWM_EN_FROM_REG(data->pwm_config[ix]);
1234 break;
1235 case SYS_PWM_RAMP_RATE:
1236
1237 res = PWM_RR_FROM_REG(data->pwm_rr[ix > 0], ix);
1238 break;
1239 case SYS_PWM_AUTO_CHANNELS_ZONE:
1240
1241 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2)
1242 res = PWM_ACZ_FROM_REG(data->pwm_config[ix]);
1243 else
1244 res = data->pwm_acz[ix];
1245 break;
1246 case SYS_PWM_AUTO_PWM_MIN:
1247
1248 if (PWM_OFF_FROM_REG(data->pwm_rr[0], ix))
1249 res = data->pwm_min[ix];
1250 else
1251 res = 0;
1252 break;
1253 case SYS_PWM_AUTO_POINT1_PWM:
1254
1255 res = data->pwm_min[ix];
1256 break;
1257 case SYS_PWM_AUTO_POINT2_PWM:
1258
1259 res = 255;
1260 break;
1261 default:
1262 res = 0;
1263 dev_dbg(dev, "Unknown function %d.\n", fn);
1264 }
1265
1266 return sprintf(buf, "%d\n", res);
1267}
1268
1269static struct attribute *dme1737_pwm_chmod_attr[];
1270static void dme1737_chmod_file(struct device*, struct attribute*, umode_t);
1271
1272static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1273 const char *buf, size_t count)
1274{
1275 struct dme1737_data *data = dev_get_drvdata(dev);
1276 struct sensor_device_attribute_2
1277 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
1278 int ix = sensor_attr_2->index;
1279 int fn = sensor_attr_2->nr;
1280 long val;
1281 int err;
1282
1283 err = kstrtol(buf, 10, &val);
1284 if (err)
1285 return err;
1286
1287 mutex_lock(&data->update_lock);
1288 switch (fn) {
1289 case SYS_PWM:
1290 data->pwm[ix] = clamp_val(val, 0, 255);
1291 dme1737_write(data, DME1737_REG_PWM(ix), data->pwm[ix]);
1292 break;
1293 case SYS_PWM_FREQ:
1294 data->pwm_freq[ix] = PWM_FREQ_TO_REG(val, dme1737_read(data,
1295 DME1737_REG_PWM_FREQ(ix)));
1296 dme1737_write(data, DME1737_REG_PWM_FREQ(ix),
1297 data->pwm_freq[ix]);
1298 break;
1299 case SYS_PWM_ENABLE:
1300
1301 if (val < 0 || val > 2) {
1302 count = -EINVAL;
1303 dev_warn(dev,
1304 "PWM enable %ld not supported. Choose one of 0, 1, or 2.\n",
1305 val);
1306 goto exit;
1307 }
1308
1309 data->pwm_config[ix] = dme1737_read(data,
1310 DME1737_REG_PWM_CONFIG(ix));
1311 if (val == PWM_EN_FROM_REG(data->pwm_config[ix])) {
1312
1313 goto exit;
1314 }
1315
1316 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) {
1317
1318 data->pwm_acz[ix] = PWM_ACZ_FROM_REG(
1319 data->pwm_config[ix]);
1320
1321 data->pwm_rr[ix > 0] = dme1737_read(data,
1322 DME1737_REG_PWM_RR(ix > 0));
1323 data->pwm_rr_en &= ~(1 << ix);
1324 if (PWM_RR_EN_FROM_REG(data->pwm_rr[ix > 0], ix)) {
1325 data->pwm_rr_en |= (1 << ix);
1326 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(0, ix,
1327 data->pwm_rr[ix > 0]);
1328 dme1737_write(data,
1329 DME1737_REG_PWM_RR(ix > 0),
1330 data->pwm_rr[ix > 0]);
1331 }
1332 }
1333
1334 switch (val) {
1335 case 0:
1336
1337 dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix],
1338 S_IRUGO);
1339
1340 data->pwm_config[ix] = PWM_EN_TO_REG(0,
1341 data->pwm_config[ix]);
1342 dme1737_write(data, DME1737_REG_PWM_CONFIG(ix),
1343 data->pwm_config[ix]);
1344 break;
1345 case 1:
1346
1347 data->pwm_config[ix] = PWM_EN_TO_REG(1,
1348 data->pwm_config[ix]);
1349 dme1737_write(data, DME1737_REG_PWM_CONFIG(ix),
1350 data->pwm_config[ix]);
1351
1352 dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix],
1353 S_IRUGO | S_IWUSR);
1354 break;
1355 case 2:
1356
1357 dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix],
1358 S_IRUGO);
1359
1360
1361
1362
1363 data->pwm_config[ix] = PWM_ACZ_TO_REG(
1364 data->pwm_acz[ix],
1365 data->pwm_config[ix]);
1366 dme1737_write(data, DME1737_REG_PWM_CONFIG(ix),
1367 data->pwm_config[ix]);
1368
1369 if (data->pwm_rr_en & (1 << ix)) {
1370 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(1, ix,
1371 dme1737_read(data,
1372 DME1737_REG_PWM_RR(ix > 0)));
1373 dme1737_write(data,
1374 DME1737_REG_PWM_RR(ix > 0),
1375 data->pwm_rr[ix > 0]);
1376 }
1377 break;
1378 }
1379 break;
1380 case SYS_PWM_RAMP_RATE:
1381
1382
1383 data->pwm_config[ix] = dme1737_read(data,
1384 DME1737_REG_PWM_CONFIG(ix));
1385 data->pwm_rr[ix > 0] = dme1737_read(data,
1386 DME1737_REG_PWM_RR(ix > 0));
1387
1388 if (val > 0) {
1389 data->pwm_rr[ix > 0] = PWM_RR_TO_REG(val, ix,
1390 data->pwm_rr[ix > 0]);
1391 }
1392
1393
1394
1395
1396 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) {
1397 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(val > 0, ix,
1398 data->pwm_rr[ix > 0]);
1399 }
1400 dme1737_write(data, DME1737_REG_PWM_RR(ix > 0),
1401 data->pwm_rr[ix > 0]);
1402 break;
1403 case SYS_PWM_AUTO_CHANNELS_ZONE:
1404
1405 if (!(val == 1 || val == 2 || val == 4 ||
1406 val == 6 || val == 7)) {
1407 count = -EINVAL;
1408 dev_warn(dev,
1409 "PWM auto channels zone %ld not supported. Choose one of 1, 2, 4, 6, "
1410 "or 7.\n", val);
1411 goto exit;
1412 }
1413
1414 data->pwm_config[ix] = dme1737_read(data,
1415 DME1737_REG_PWM_CONFIG(ix));
1416 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) {
1417
1418
1419
1420
1421 data->pwm_config[ix] = PWM_ACZ_TO_REG(val,
1422 data->pwm_config[ix]);
1423 dme1737_write(data, DME1737_REG_PWM_CONFIG(ix),
1424 data->pwm_config[ix]);
1425 } else {
1426
1427
1428
1429
1430 data->pwm_acz[ix] = val;
1431 }
1432 break;
1433 case SYS_PWM_AUTO_PWM_MIN:
1434
1435
1436 data->pwm_min[ix] = dme1737_read(data,
1437 DME1737_REG_PWM_MIN(ix));
1438
1439
1440
1441
1442
1443
1444 if (val > ((data->pwm_min[ix] + 1) / 2)) {
1445 data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix,
1446 dme1737_read(data,
1447 DME1737_REG_PWM_RR(0)));
1448 } else {
1449 data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix,
1450 dme1737_read(data,
1451 DME1737_REG_PWM_RR(0)));
1452 }
1453 dme1737_write(data, DME1737_REG_PWM_RR(0),
1454 data->pwm_rr[0]);
1455 break;
1456 case SYS_PWM_AUTO_POINT1_PWM:
1457
1458 data->pwm_min[ix] = clamp_val(val, 0, 255);
1459 dme1737_write(data, DME1737_REG_PWM_MIN(ix),
1460 data->pwm_min[ix]);
1461 break;
1462 default:
1463 dev_dbg(dev, "Unknown function %d.\n", fn);
1464 }
1465exit:
1466 mutex_unlock(&data->update_lock);
1467
1468 return count;
1469}
1470
1471
1472
1473
1474
1475static ssize_t vrm_show(struct device *dev, struct device_attribute *attr,
1476 char *buf)
1477{
1478 struct i2c_client *client = to_i2c_client(dev);
1479 struct dme1737_data *data = i2c_get_clientdata(client);
1480
1481 return sprintf(buf, "%d\n", data->vrm);
1482}
1483
1484static ssize_t vrm_store(struct device *dev, struct device_attribute *attr,
1485 const char *buf, size_t count)
1486{
1487 struct dme1737_data *data = dev_get_drvdata(dev);
1488 unsigned long val;
1489 int err;
1490
1491 err = kstrtoul(buf, 10, &val);
1492 if (err)
1493 return err;
1494
1495 if (val > 255)
1496 return -EINVAL;
1497
1498 data->vrm = val;
1499 return count;
1500}
1501
1502static ssize_t cpu0_vid_show(struct device *dev,
1503 struct device_attribute *attr, char *buf)
1504{
1505 struct dme1737_data *data = dme1737_update_device(dev);
1506
1507 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
1508}
1509
1510static ssize_t name_show(struct device *dev, struct device_attribute *attr,
1511 char *buf)
1512{
1513 struct dme1737_data *data = dev_get_drvdata(dev);
1514
1515 return sprintf(buf, "%s\n", data->name);
1516}
1517
1518
1519
1520
1521
1522
1523
1524#define SENSOR_DEVICE_ATTR_IN(ix) \
1525static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \
1526 show_in, NULL, SYS_IN_INPUT, ix); \
1527static SENSOR_DEVICE_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \
1528 show_in, set_in, SYS_IN_MIN, ix); \
1529static SENSOR_DEVICE_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \
1530 show_in, set_in, SYS_IN_MAX, ix); \
1531static SENSOR_DEVICE_ATTR_2(in##ix##_alarm, S_IRUGO, \
1532 show_in, NULL, SYS_IN_ALARM, ix)
1533
1534SENSOR_DEVICE_ATTR_IN(0);
1535SENSOR_DEVICE_ATTR_IN(1);
1536SENSOR_DEVICE_ATTR_IN(2);
1537SENSOR_DEVICE_ATTR_IN(3);
1538SENSOR_DEVICE_ATTR_IN(4);
1539SENSOR_DEVICE_ATTR_IN(5);
1540SENSOR_DEVICE_ATTR_IN(6);
1541SENSOR_DEVICE_ATTR_IN(7);
1542
1543
1544
1545#define SENSOR_DEVICE_ATTR_TEMP(ix) \
1546static SENSOR_DEVICE_ATTR_2(temp##ix##_input, S_IRUGO, \
1547 show_temp, NULL, SYS_TEMP_INPUT, ix-1); \
1548static SENSOR_DEVICE_ATTR_2(temp##ix##_min, S_IRUGO | S_IWUSR, \
1549 show_temp, set_temp, SYS_TEMP_MIN, ix-1); \
1550static SENSOR_DEVICE_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \
1551 show_temp, set_temp, SYS_TEMP_MAX, ix-1); \
1552static SENSOR_DEVICE_ATTR_2(temp##ix##_offset, S_IRUGO, \
1553 show_temp, set_temp, SYS_TEMP_OFFSET, ix-1); \
1554static SENSOR_DEVICE_ATTR_2(temp##ix##_alarm, S_IRUGO, \
1555 show_temp, NULL, SYS_TEMP_ALARM, ix-1); \
1556static SENSOR_DEVICE_ATTR_2(temp##ix##_fault, S_IRUGO, \
1557 show_temp, NULL, SYS_TEMP_FAULT, ix-1)
1558
1559SENSOR_DEVICE_ATTR_TEMP(1);
1560SENSOR_DEVICE_ATTR_TEMP(2);
1561SENSOR_DEVICE_ATTR_TEMP(3);
1562
1563
1564
1565#define SENSOR_DEVICE_ATTR_ZONE(ix) \
1566static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_channels_temp, S_IRUGO, \
1567 show_zone, NULL, SYS_ZONE_AUTO_CHANNELS_TEMP, ix-1); \
1568static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp_hyst, S_IRUGO, \
1569 show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP_HYST, ix-1); \
1570static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp, S_IRUGO, \
1571 show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP, ix-1); \
1572static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point2_temp, S_IRUGO, \
1573 show_zone, set_zone, SYS_ZONE_AUTO_POINT2_TEMP, ix-1); \
1574static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point3_temp, S_IRUGO, \
1575 show_zone, set_zone, SYS_ZONE_AUTO_POINT3_TEMP, ix-1)
1576
1577SENSOR_DEVICE_ATTR_ZONE(1);
1578SENSOR_DEVICE_ATTR_ZONE(2);
1579SENSOR_DEVICE_ATTR_ZONE(3);
1580
1581
1582
1583#define SENSOR_DEVICE_ATTR_FAN_1TO4(ix) \
1584static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \
1585 show_fan, NULL, SYS_FAN_INPUT, ix-1); \
1586static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \
1587 show_fan, set_fan, SYS_FAN_MIN, ix-1); \
1588static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \
1589 show_fan, NULL, SYS_FAN_ALARM, ix-1); \
1590static SENSOR_DEVICE_ATTR_2(fan##ix##_type, S_IRUGO | S_IWUSR, \
1591 show_fan, set_fan, SYS_FAN_TYPE, ix-1)
1592
1593SENSOR_DEVICE_ATTR_FAN_1TO4(1);
1594SENSOR_DEVICE_ATTR_FAN_1TO4(2);
1595SENSOR_DEVICE_ATTR_FAN_1TO4(3);
1596SENSOR_DEVICE_ATTR_FAN_1TO4(4);
1597
1598
1599
1600#define SENSOR_DEVICE_ATTR_FAN_5TO6(ix) \
1601static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \
1602 show_fan, NULL, SYS_FAN_INPUT, ix-1); \
1603static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \
1604 show_fan, set_fan, SYS_FAN_MIN, ix-1); \
1605static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \
1606 show_fan, NULL, SYS_FAN_ALARM, ix-1); \
1607static SENSOR_DEVICE_ATTR_2(fan##ix##_max, S_IRUGO | S_IWUSR, \
1608 show_fan, set_fan, SYS_FAN_MAX, ix-1)
1609
1610SENSOR_DEVICE_ATTR_FAN_5TO6(5);
1611SENSOR_DEVICE_ATTR_FAN_5TO6(6);
1612
1613
1614
1615#define SENSOR_DEVICE_ATTR_PWM_1TO3(ix) \
1616static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \
1617 show_pwm, set_pwm, SYS_PWM, ix-1); \
1618static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \
1619 show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \
1620static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \
1621 show_pwm, set_pwm, SYS_PWM_ENABLE, ix-1); \
1622static SENSOR_DEVICE_ATTR_2(pwm##ix##_ramp_rate, S_IRUGO, \
1623 show_pwm, set_pwm, SYS_PWM_RAMP_RATE, ix-1); \
1624static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_channels_zone, S_IRUGO, \
1625 show_pwm, set_pwm, SYS_PWM_AUTO_CHANNELS_ZONE, ix-1); \
1626static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_pwm_min, S_IRUGO, \
1627 show_pwm, set_pwm, SYS_PWM_AUTO_PWM_MIN, ix-1); \
1628static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point1_pwm, S_IRUGO, \
1629 show_pwm, set_pwm, SYS_PWM_AUTO_POINT1_PWM, ix-1); \
1630static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point2_pwm, S_IRUGO, \
1631 show_pwm, NULL, SYS_PWM_AUTO_POINT2_PWM, ix-1)
1632
1633SENSOR_DEVICE_ATTR_PWM_1TO3(1);
1634SENSOR_DEVICE_ATTR_PWM_1TO3(2);
1635SENSOR_DEVICE_ATTR_PWM_1TO3(3);
1636
1637
1638
1639#define SENSOR_DEVICE_ATTR_PWM_5TO6(ix) \
1640static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \
1641 show_pwm, set_pwm, SYS_PWM, ix-1); \
1642static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \
1643 show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \
1644static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \
1645 show_pwm, NULL, SYS_PWM_ENABLE, ix-1)
1646
1647SENSOR_DEVICE_ATTR_PWM_5TO6(5);
1648SENSOR_DEVICE_ATTR_PWM_5TO6(6);
1649
1650
1651
1652static DEVICE_ATTR_RW(vrm);
1653static DEVICE_ATTR_RO(cpu0_vid);
1654static DEVICE_ATTR_RO(name);
1655
1656
1657
1658
1659
1660
1661
1662static struct attribute *dme1737_attr[] = {
1663
1664 &sensor_dev_attr_in0_input.dev_attr.attr,
1665 &sensor_dev_attr_in0_min.dev_attr.attr,
1666 &sensor_dev_attr_in0_max.dev_attr.attr,
1667 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1668 &sensor_dev_attr_in1_input.dev_attr.attr,
1669 &sensor_dev_attr_in1_min.dev_attr.attr,
1670 &sensor_dev_attr_in1_max.dev_attr.attr,
1671 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1672 &sensor_dev_attr_in2_input.dev_attr.attr,
1673 &sensor_dev_attr_in2_min.dev_attr.attr,
1674 &sensor_dev_attr_in2_max.dev_attr.attr,
1675 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1676 &sensor_dev_attr_in3_input.dev_attr.attr,
1677 &sensor_dev_attr_in3_min.dev_attr.attr,
1678 &sensor_dev_attr_in3_max.dev_attr.attr,
1679 &sensor_dev_attr_in3_alarm.dev_attr.attr,
1680 &sensor_dev_attr_in4_input.dev_attr.attr,
1681 &sensor_dev_attr_in4_min.dev_attr.attr,
1682 &sensor_dev_attr_in4_max.dev_attr.attr,
1683 &sensor_dev_attr_in4_alarm.dev_attr.attr,
1684 &sensor_dev_attr_in5_input.dev_attr.attr,
1685 &sensor_dev_attr_in5_min.dev_attr.attr,
1686 &sensor_dev_attr_in5_max.dev_attr.attr,
1687 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1688 &sensor_dev_attr_in6_input.dev_attr.attr,
1689 &sensor_dev_attr_in6_min.dev_attr.attr,
1690 &sensor_dev_attr_in6_max.dev_attr.attr,
1691 &sensor_dev_attr_in6_alarm.dev_attr.attr,
1692
1693 &sensor_dev_attr_temp1_input.dev_attr.attr,
1694 &sensor_dev_attr_temp1_min.dev_attr.attr,
1695 &sensor_dev_attr_temp1_max.dev_attr.attr,
1696 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1697 &sensor_dev_attr_temp1_fault.dev_attr.attr,
1698 &sensor_dev_attr_temp2_input.dev_attr.attr,
1699 &sensor_dev_attr_temp2_min.dev_attr.attr,
1700 &sensor_dev_attr_temp2_max.dev_attr.attr,
1701 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1702 &sensor_dev_attr_temp2_fault.dev_attr.attr,
1703 &sensor_dev_attr_temp3_input.dev_attr.attr,
1704 &sensor_dev_attr_temp3_min.dev_attr.attr,
1705 &sensor_dev_attr_temp3_max.dev_attr.attr,
1706 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1707 &sensor_dev_attr_temp3_fault.dev_attr.attr,
1708
1709 &sensor_dev_attr_zone1_auto_point1_temp.dev_attr.attr,
1710 &sensor_dev_attr_zone1_auto_point2_temp.dev_attr.attr,
1711 &sensor_dev_attr_zone1_auto_point3_temp.dev_attr.attr,
1712 &sensor_dev_attr_zone1_auto_channels_temp.dev_attr.attr,
1713 &sensor_dev_attr_zone2_auto_point1_temp.dev_attr.attr,
1714 &sensor_dev_attr_zone2_auto_point2_temp.dev_attr.attr,
1715 &sensor_dev_attr_zone2_auto_point3_temp.dev_attr.attr,
1716 &sensor_dev_attr_zone2_auto_channels_temp.dev_attr.attr,
1717 NULL
1718};
1719
1720static const struct attribute_group dme1737_group = {
1721 .attrs = dme1737_attr,
1722};
1723
1724
1725
1726
1727
1728
1729static struct attribute *dme1737_temp_offset_attr[] = {
1730 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1731 &sensor_dev_attr_temp2_offset.dev_attr.attr,
1732 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1733 NULL
1734};
1735
1736static const struct attribute_group dme1737_temp_offset_group = {
1737 .attrs = dme1737_temp_offset_attr,
1738};
1739
1740
1741
1742
1743
1744
1745static struct attribute *dme1737_vid_attr[] = {
1746 &dev_attr_vrm.attr,
1747 &dev_attr_cpu0_vid.attr,
1748 NULL
1749};
1750
1751static const struct attribute_group dme1737_vid_group = {
1752 .attrs = dme1737_vid_attr,
1753};
1754
1755
1756
1757
1758
1759
1760static struct attribute *dme1737_zone3_attr[] = {
1761 &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr,
1762 &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr,
1763 &sensor_dev_attr_zone3_auto_point3_temp.dev_attr.attr,
1764 &sensor_dev_attr_zone3_auto_channels_temp.dev_attr.attr,
1765 NULL
1766};
1767
1768static const struct attribute_group dme1737_zone3_group = {
1769 .attrs = dme1737_zone3_attr,
1770};
1771
1772
1773
1774
1775
1776
1777
1778static struct attribute *dme1737_zone_hyst_attr[] = {
1779 &sensor_dev_attr_zone1_auto_point1_temp_hyst.dev_attr.attr,
1780 &sensor_dev_attr_zone2_auto_point1_temp_hyst.dev_attr.attr,
1781 &sensor_dev_attr_zone3_auto_point1_temp_hyst.dev_attr.attr,
1782 NULL
1783};
1784
1785static const struct attribute_group dme1737_zone_hyst_group = {
1786 .attrs = dme1737_zone_hyst_attr,
1787};
1788
1789
1790
1791
1792
1793
1794static struct attribute *dme1737_in7_attr[] = {
1795 &sensor_dev_attr_in7_input.dev_attr.attr,
1796 &sensor_dev_attr_in7_min.dev_attr.attr,
1797 &sensor_dev_attr_in7_max.dev_attr.attr,
1798 &sensor_dev_attr_in7_alarm.dev_attr.attr,
1799 NULL
1800};
1801
1802static const struct attribute_group dme1737_in7_group = {
1803 .attrs = dme1737_in7_attr,
1804};
1805
1806
1807
1808
1809
1810
1811static struct attribute *dme1737_pwm1_attr[] = {
1812 &sensor_dev_attr_pwm1.dev_attr.attr,
1813 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
1814 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1815 &sensor_dev_attr_pwm1_ramp_rate.dev_attr.attr,
1816 &sensor_dev_attr_pwm1_auto_channels_zone.dev_attr.attr,
1817 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1818 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
1819 NULL
1820};
1821static struct attribute *dme1737_pwm2_attr[] = {
1822 &sensor_dev_attr_pwm2.dev_attr.attr,
1823 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
1824 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1825 &sensor_dev_attr_pwm2_ramp_rate.dev_attr.attr,
1826 &sensor_dev_attr_pwm2_auto_channels_zone.dev_attr.attr,
1827 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1828 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1829 NULL
1830};
1831static struct attribute *dme1737_pwm3_attr[] = {
1832 &sensor_dev_attr_pwm3.dev_attr.attr,
1833 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
1834 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1835 &sensor_dev_attr_pwm3_ramp_rate.dev_attr.attr,
1836 &sensor_dev_attr_pwm3_auto_channels_zone.dev_attr.attr,
1837 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1838 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1839 NULL
1840};
1841static struct attribute *dme1737_pwm5_attr[] = {
1842 &sensor_dev_attr_pwm5.dev_attr.attr,
1843 &sensor_dev_attr_pwm5_freq.dev_attr.attr,
1844 &sensor_dev_attr_pwm5_enable.dev_attr.attr,
1845 NULL
1846};
1847static struct attribute *dme1737_pwm6_attr[] = {
1848 &sensor_dev_attr_pwm6.dev_attr.attr,
1849 &sensor_dev_attr_pwm6_freq.dev_attr.attr,
1850 &sensor_dev_attr_pwm6_enable.dev_attr.attr,
1851 NULL
1852};
1853
1854static const struct attribute_group dme1737_pwm_group[] = {
1855 { .attrs = dme1737_pwm1_attr },
1856 { .attrs = dme1737_pwm2_attr },
1857 { .attrs = dme1737_pwm3_attr },
1858 { .attrs = NULL },
1859 { .attrs = dme1737_pwm5_attr },
1860 { .attrs = dme1737_pwm6_attr },
1861};
1862
1863
1864
1865
1866
1867
1868static struct attribute *dme1737_auto_pwm_min_attr[] = {
1869 &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr,
1870 &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr,
1871 &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr,
1872};
1873
1874
1875
1876
1877
1878
1879static struct attribute *dme1737_fan1_attr[] = {
1880 &sensor_dev_attr_fan1_input.dev_attr.attr,
1881 &sensor_dev_attr_fan1_min.dev_attr.attr,
1882 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1883 &sensor_dev_attr_fan1_type.dev_attr.attr,
1884 NULL
1885};
1886static struct attribute *dme1737_fan2_attr[] = {
1887 &sensor_dev_attr_fan2_input.dev_attr.attr,
1888 &sensor_dev_attr_fan2_min.dev_attr.attr,
1889 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1890 &sensor_dev_attr_fan2_type.dev_attr.attr,
1891 NULL
1892};
1893static struct attribute *dme1737_fan3_attr[] = {
1894 &sensor_dev_attr_fan3_input.dev_attr.attr,
1895 &sensor_dev_attr_fan3_min.dev_attr.attr,
1896 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1897 &sensor_dev_attr_fan3_type.dev_attr.attr,
1898 NULL
1899};
1900static struct attribute *dme1737_fan4_attr[] = {
1901 &sensor_dev_attr_fan4_input.dev_attr.attr,
1902 &sensor_dev_attr_fan4_min.dev_attr.attr,
1903 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1904 &sensor_dev_attr_fan4_type.dev_attr.attr,
1905 NULL
1906};
1907static struct attribute *dme1737_fan5_attr[] = {
1908 &sensor_dev_attr_fan5_input.dev_attr.attr,
1909 &sensor_dev_attr_fan5_min.dev_attr.attr,
1910 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
1911 &sensor_dev_attr_fan5_max.dev_attr.attr,
1912 NULL
1913};
1914static struct attribute *dme1737_fan6_attr[] = {
1915 &sensor_dev_attr_fan6_input.dev_attr.attr,
1916 &sensor_dev_attr_fan6_min.dev_attr.attr,
1917 &sensor_dev_attr_fan6_alarm.dev_attr.attr,
1918 &sensor_dev_attr_fan6_max.dev_attr.attr,
1919 NULL
1920};
1921
1922static const struct attribute_group dme1737_fan_group[] = {
1923 { .attrs = dme1737_fan1_attr },
1924 { .attrs = dme1737_fan2_attr },
1925 { .attrs = dme1737_fan3_attr },
1926 { .attrs = dme1737_fan4_attr },
1927 { .attrs = dme1737_fan5_attr },
1928 { .attrs = dme1737_fan6_attr },
1929};
1930
1931
1932
1933
1934
1935static struct attribute *dme1737_zone_chmod_attr[] = {
1936 &sensor_dev_attr_zone1_auto_point1_temp.dev_attr.attr,
1937 &sensor_dev_attr_zone1_auto_point2_temp.dev_attr.attr,
1938 &sensor_dev_attr_zone1_auto_point3_temp.dev_attr.attr,
1939 &sensor_dev_attr_zone2_auto_point1_temp.dev_attr.attr,
1940 &sensor_dev_attr_zone2_auto_point2_temp.dev_attr.attr,
1941 &sensor_dev_attr_zone2_auto_point3_temp.dev_attr.attr,
1942 NULL
1943};
1944
1945static const struct attribute_group dme1737_zone_chmod_group = {
1946 .attrs = dme1737_zone_chmod_attr,
1947};
1948
1949
1950
1951
1952
1953
1954static struct attribute *dme1737_zone3_chmod_attr[] = {
1955 &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr,
1956 &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr,
1957 &sensor_dev_attr_zone3_auto_point3_temp.dev_attr.attr,
1958 NULL
1959};
1960
1961static const struct attribute_group dme1737_zone3_chmod_group = {
1962 .attrs = dme1737_zone3_chmod_attr,
1963};
1964
1965
1966
1967
1968
1969
1970static struct attribute *dme1737_pwm1_chmod_attr[] = {
1971 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
1972 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1973 &sensor_dev_attr_pwm1_ramp_rate.dev_attr.attr,
1974 &sensor_dev_attr_pwm1_auto_channels_zone.dev_attr.attr,
1975 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1976 NULL
1977};
1978static struct attribute *dme1737_pwm2_chmod_attr[] = {
1979 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
1980 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1981 &sensor_dev_attr_pwm2_ramp_rate.dev_attr.attr,
1982 &sensor_dev_attr_pwm2_auto_channels_zone.dev_attr.attr,
1983 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1984 NULL
1985};
1986static struct attribute *dme1737_pwm3_chmod_attr[] = {
1987 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
1988 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1989 &sensor_dev_attr_pwm3_ramp_rate.dev_attr.attr,
1990 &sensor_dev_attr_pwm3_auto_channels_zone.dev_attr.attr,
1991 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1992 NULL
1993};
1994static struct attribute *dme1737_pwm5_chmod_attr[] = {
1995 &sensor_dev_attr_pwm5.dev_attr.attr,
1996 &sensor_dev_attr_pwm5_freq.dev_attr.attr,
1997 NULL
1998};
1999static struct attribute *dme1737_pwm6_chmod_attr[] = {
2000 &sensor_dev_attr_pwm6.dev_attr.attr,
2001 &sensor_dev_attr_pwm6_freq.dev_attr.attr,
2002 NULL
2003};
2004
2005static const struct attribute_group dme1737_pwm_chmod_group[] = {
2006 { .attrs = dme1737_pwm1_chmod_attr },
2007 { .attrs = dme1737_pwm2_chmod_attr },
2008 { .attrs = dme1737_pwm3_chmod_attr },
2009 { .attrs = NULL },
2010 { .attrs = dme1737_pwm5_chmod_attr },
2011 { .attrs = dme1737_pwm6_chmod_attr },
2012};
2013
2014
2015
2016
2017
2018static struct attribute *dme1737_pwm_chmod_attr[] = {
2019 &sensor_dev_attr_pwm1.dev_attr.attr,
2020 &sensor_dev_attr_pwm2.dev_attr.attr,
2021 &sensor_dev_attr_pwm3.dev_attr.attr,
2022};
2023
2024
2025
2026
2027
2028static inline void dme1737_sio_enter(int sio_cip)
2029{
2030 outb(0x55, sio_cip);
2031}
2032
2033static inline void dme1737_sio_exit(int sio_cip)
2034{
2035 outb(0xaa, sio_cip);
2036}
2037
2038static inline int dme1737_sio_inb(int sio_cip, int reg)
2039{
2040 outb(reg, sio_cip);
2041 return inb(sio_cip + 1);
2042}
2043
2044static inline void dme1737_sio_outb(int sio_cip, int reg, int val)
2045{
2046 outb(reg, sio_cip);
2047 outb(val, sio_cip + 1);
2048}
2049
2050
2051
2052
2053
2054static int dme1737_i2c_get_features(int, struct dme1737_data*);
2055
2056static void dme1737_chmod_file(struct device *dev,
2057 struct attribute *attr, umode_t mode)
2058{
2059 if (sysfs_chmod_file(&dev->kobj, attr, mode)) {
2060 dev_warn(dev, "Failed to change permissions of %s.\n",
2061 attr->name);
2062 }
2063}
2064
2065static void dme1737_chmod_group(struct device *dev,
2066 const struct attribute_group *group,
2067 umode_t mode)
2068{
2069 struct attribute **attr;
2070
2071 for (attr = group->attrs; *attr; attr++)
2072 dme1737_chmod_file(dev, *attr, mode);
2073}
2074
2075static void dme1737_remove_files(struct device *dev)
2076{
2077 struct dme1737_data *data = dev_get_drvdata(dev);
2078 int ix;
2079
2080 for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) {
2081 if (data->has_features & HAS_FAN(ix)) {
2082 sysfs_remove_group(&dev->kobj,
2083 &dme1737_fan_group[ix]);
2084 }
2085 }
2086
2087 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) {
2088 if (data->has_features & HAS_PWM(ix)) {
2089 sysfs_remove_group(&dev->kobj,
2090 &dme1737_pwm_group[ix]);
2091 if ((data->has_features & HAS_PWM_MIN) && ix < 3) {
2092 sysfs_remove_file(&dev->kobj,
2093 dme1737_auto_pwm_min_attr[ix]);
2094 }
2095 }
2096 }
2097
2098 if (data->has_features & HAS_TEMP_OFFSET)
2099 sysfs_remove_group(&dev->kobj, &dme1737_temp_offset_group);
2100 if (data->has_features & HAS_VID)
2101 sysfs_remove_group(&dev->kobj, &dme1737_vid_group);
2102 if (data->has_features & HAS_ZONE3)
2103 sysfs_remove_group(&dev->kobj, &dme1737_zone3_group);
2104 if (data->has_features & HAS_ZONE_HYST)
2105 sysfs_remove_group(&dev->kobj, &dme1737_zone_hyst_group);
2106 if (data->has_features & HAS_IN7)
2107 sysfs_remove_group(&dev->kobj, &dme1737_in7_group);
2108 sysfs_remove_group(&dev->kobj, &dme1737_group);
2109
2110 if (!data->client)
2111 sysfs_remove_file(&dev->kobj, &dev_attr_name.attr);
2112}
2113
2114static int dme1737_create_files(struct device *dev)
2115{
2116 struct dme1737_data *data = dev_get_drvdata(dev);
2117 int err, ix;
2118
2119
2120 if (!data->client) {
2121 err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr);
2122 if (err)
2123 goto exit;
2124 }
2125
2126
2127 err = sysfs_create_group(&dev->kobj, &dme1737_group);
2128 if (err)
2129 goto exit_remove;
2130
2131
2132 if (data->has_features & HAS_TEMP_OFFSET) {
2133 err = sysfs_create_group(&dev->kobj,
2134 &dme1737_temp_offset_group);
2135 if (err)
2136 goto exit_remove;
2137 }
2138 if (data->has_features & HAS_VID) {
2139 err = sysfs_create_group(&dev->kobj, &dme1737_vid_group);
2140 if (err)
2141 goto exit_remove;
2142 }
2143 if (data->has_features & HAS_ZONE3) {
2144 err = sysfs_create_group(&dev->kobj, &dme1737_zone3_group);
2145 if (err)
2146 goto exit_remove;
2147 }
2148 if (data->has_features & HAS_ZONE_HYST) {
2149 err = sysfs_create_group(&dev->kobj, &dme1737_zone_hyst_group);
2150 if (err)
2151 goto exit_remove;
2152 }
2153 if (data->has_features & HAS_IN7) {
2154 err = sysfs_create_group(&dev->kobj, &dme1737_in7_group);
2155 if (err)
2156 goto exit_remove;
2157 }
2158
2159
2160 for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) {
2161 if (data->has_features & HAS_FAN(ix)) {
2162 err = sysfs_create_group(&dev->kobj,
2163 &dme1737_fan_group[ix]);
2164 if (err)
2165 goto exit_remove;
2166 }
2167 }
2168
2169
2170 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) {
2171 if (data->has_features & HAS_PWM(ix)) {
2172 err = sysfs_create_group(&dev->kobj,
2173 &dme1737_pwm_group[ix]);
2174 if (err)
2175 goto exit_remove;
2176 if ((data->has_features & HAS_PWM_MIN) && (ix < 3)) {
2177 err = sysfs_create_file(&dev->kobj,
2178 dme1737_auto_pwm_min_attr[ix]);
2179 if (err)
2180 goto exit_remove;
2181 }
2182 }
2183 }
2184
2185
2186
2187
2188
2189 if (data->config & 0x02) {
2190 dev_info(dev,
2191 "Device is locked. Some attributes will be read-only.\n");
2192 } else {
2193
2194 dme1737_chmod_group(dev, &dme1737_zone_chmod_group,
2195 S_IRUGO | S_IWUSR);
2196
2197
2198 if (data->has_features & HAS_TEMP_OFFSET) {
2199 dme1737_chmod_group(dev, &dme1737_temp_offset_group,
2200 S_IRUGO | S_IWUSR);
2201 }
2202 if (data->has_features & HAS_ZONE3) {
2203 dme1737_chmod_group(dev, &dme1737_zone3_chmod_group,
2204 S_IRUGO | S_IWUSR);
2205 }
2206 if (data->has_features & HAS_ZONE_HYST) {
2207 dme1737_chmod_group(dev, &dme1737_zone_hyst_group,
2208 S_IRUGO | S_IWUSR);
2209 }
2210
2211
2212 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_chmod_group); ix++) {
2213 if (data->has_features & HAS_PWM(ix)) {
2214 dme1737_chmod_group(dev,
2215 &dme1737_pwm_chmod_group[ix],
2216 S_IRUGO | S_IWUSR);
2217 if ((data->has_features & HAS_PWM_MIN) &&
2218 ix < 3) {
2219 dme1737_chmod_file(dev,
2220 dme1737_auto_pwm_min_attr[ix],
2221 S_IRUGO | S_IWUSR);
2222 }
2223 }
2224 }
2225
2226
2227 for (ix = 0; ix < 3; ix++) {
2228 if ((data->has_features & HAS_PWM(ix)) &&
2229 (PWM_EN_FROM_REG(data->pwm_config[ix]) == 1)) {
2230 dme1737_chmod_file(dev,
2231 dme1737_pwm_chmod_attr[ix],
2232 S_IRUGO | S_IWUSR);
2233 }
2234 }
2235 }
2236
2237 return 0;
2238
2239exit_remove:
2240 dme1737_remove_files(dev);
2241exit:
2242 return err;
2243}
2244
2245static int dme1737_init_device(struct device *dev)
2246{
2247 struct dme1737_data *data = dev_get_drvdata(dev);
2248 struct i2c_client *client = data->client;
2249 int ix;
2250 u8 reg;
2251
2252
2253 data->in_nominal = IN_NOMINAL(data->type);
2254
2255 data->config = dme1737_read(data, DME1737_REG_CONFIG);
2256
2257 if (!(data->config & 0x01)) {
2258 if (!force_start) {
2259 dev_err(dev,
2260 "Device is not monitoring. Use the force_start load parameter to override.\n");
2261 return -EFAULT;
2262 }
2263
2264
2265 data->config |= 0x01;
2266 dme1737_write(data, DME1737_REG_CONFIG, data->config);
2267 }
2268
2269 if (!(data->config & 0x04)) {
2270 dev_err(dev, "Device is not ready.\n");
2271 return -EFAULT;
2272 }
2273
2274
2275
2276
2277
2278 if (client) {
2279 data->config2 = dme1737_read(data, DME1737_REG_CONFIG2);
2280
2281 if (data->config2 & 0x04)
2282 data->has_features |= HAS_FAN(2);
2283
2284
2285
2286
2287
2288
2289 if (client->addr == 0x2e)
2290 data->has_features |= HAS_FAN(3) | HAS_PWM(2);
2291
2292
2293
2294
2295
2296
2297
2298 if (dme1737_i2c_get_features(0x2e, data) &&
2299 dme1737_i2c_get_features(0x4e, data)) {
2300 dev_warn(dev,
2301 "Failed to query Super-IO for optional features.\n");
2302 }
2303 }
2304
2305
2306 data->has_features |= HAS_FAN(0) | HAS_FAN(1) | HAS_PWM(0) | HAS_PWM(1);
2307
2308
2309 switch (data->type) {
2310 case dme1737:
2311 data->has_features |= HAS_TEMP_OFFSET | HAS_VID | HAS_ZONE3 |
2312 HAS_ZONE_HYST | HAS_PWM_MIN;
2313 break;
2314 case sch311x:
2315 data->has_features |= HAS_TEMP_OFFSET | HAS_ZONE3 |
2316 HAS_ZONE_HYST | HAS_PWM_MIN | HAS_FAN(2) | HAS_PWM(2);
2317 break;
2318 case sch5027:
2319 data->has_features |= HAS_ZONE3;
2320 break;
2321 case sch5127:
2322 data->has_features |= HAS_FAN(2) | HAS_PWM(2) | HAS_IN7;
2323 break;
2324 default:
2325 break;
2326 }
2327
2328 dev_info(dev,
2329 "Optional features: pwm3=%s, pwm5=%s, pwm6=%s, fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n",
2330 (data->has_features & HAS_PWM(2)) ? "yes" : "no",
2331 (data->has_features & HAS_PWM(4)) ? "yes" : "no",
2332 (data->has_features & HAS_PWM(5)) ? "yes" : "no",
2333 (data->has_features & HAS_FAN(2)) ? "yes" : "no",
2334 (data->has_features & HAS_FAN(3)) ? "yes" : "no",
2335 (data->has_features & HAS_FAN(4)) ? "yes" : "no",
2336 (data->has_features & HAS_FAN(5)) ? "yes" : "no");
2337
2338 reg = dme1737_read(data, DME1737_REG_TACH_PWM);
2339
2340 if (client && reg != 0xa4) {
2341 dev_warn(dev,
2342 "Non-standard fan to pwm mapping: fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, fan4->pwm%d. %s\n",
2343 (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1,
2344 ((reg >> 4) & 0x03) + 1, ((reg >> 6) & 0x03) + 1,
2345 DO_REPORT);
2346 } else if (!client && reg != 0x24) {
2347 dev_warn(dev,
2348 "Non-standard fan to pwm mapping: fan1->pwm%d, fan2->pwm%d, fan3->pwm%d. %s\n",
2349 (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1,
2350 ((reg >> 4) & 0x03) + 1, DO_REPORT);
2351 }
2352
2353
2354
2355
2356
2357
2358 if (!(data->config & 0x02)) {
2359 for (ix = 0; ix < 3; ix++) {
2360 data->pwm_config[ix] = dme1737_read(data,
2361 DME1737_REG_PWM_CONFIG(ix));
2362 if ((data->has_features & HAS_PWM(ix)) &&
2363 (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) {
2364 dev_info(dev,
2365 "Switching pwm%d to manual mode.\n",
2366 ix + 1);
2367 data->pwm_config[ix] = PWM_EN_TO_REG(1,
2368 data->pwm_config[ix]);
2369 dme1737_write(data, DME1737_REG_PWM(ix), 0);
2370 dme1737_write(data,
2371 DME1737_REG_PWM_CONFIG(ix),
2372 data->pwm_config[ix]);
2373 }
2374 }
2375 }
2376
2377
2378 data->pwm_acz[0] = 1;
2379 data->pwm_acz[1] = 2;
2380 data->pwm_acz[2] = 4;
2381
2382
2383 if (data->has_features & HAS_VID)
2384 data->vrm = vid_which_vrm();
2385
2386 return 0;
2387}
2388
2389
2390
2391
2392
2393static struct i2c_driver dme1737_i2c_driver;
2394
2395static int dme1737_i2c_get_features(int sio_cip, struct dme1737_data *data)
2396{
2397 int err = 0, reg;
2398 u16 addr;
2399
2400 dme1737_sio_enter(sio_cip);
2401
2402
2403
2404
2405
2406 reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20);
2407 if (!(reg == DME1737_ID_1 || reg == DME1737_ID_2 ||
2408 reg == SCH5027_ID)) {
2409 err = -ENODEV;
2410 goto exit;
2411 }
2412
2413
2414 dme1737_sio_outb(sio_cip, 0x07, 0x0a);
2415
2416
2417 addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) |
2418 dme1737_sio_inb(sio_cip, 0x61);
2419 if (!addr) {
2420 err = -ENODEV;
2421 goto exit;
2422 }
2423
2424
2425
2426
2427
2428
2429 if ((inb(addr + 0x43) & 0x0c) == 0x08)
2430 data->has_features |= HAS_FAN(5);
2431 if ((inb(addr + 0x44) & 0x0c) == 0x08)
2432 data->has_features |= HAS_PWM(5);
2433 if ((inb(addr + 0x45) & 0x0c) == 0x08)
2434 data->has_features |= HAS_FAN(4);
2435 if ((inb(addr + 0x46) & 0x0c) == 0x08)
2436 data->has_features |= HAS_PWM(4);
2437
2438exit:
2439 dme1737_sio_exit(sio_cip);
2440
2441 return err;
2442}
2443
2444
2445static int dme1737_i2c_detect(struct i2c_client *client,
2446 struct i2c_board_info *info)
2447{
2448 struct i2c_adapter *adapter = client->adapter;
2449 struct device *dev = &adapter->dev;
2450 u8 company, verstep = 0;
2451 const char *name;
2452
2453 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
2454 return -ENODEV;
2455
2456 company = i2c_smbus_read_byte_data(client, DME1737_REG_COMPANY);
2457 verstep = i2c_smbus_read_byte_data(client, DME1737_REG_VERSTEP);
2458
2459 if (company == DME1737_COMPANY_SMSC &&
2460 verstep == SCH5027_VERSTEP) {
2461 name = "sch5027";
2462 } else if (company == DME1737_COMPANY_SMSC &&
2463 (verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) {
2464 name = "dme1737";
2465 } else {
2466 return -ENODEV;
2467 }
2468
2469 dev_info(dev, "Found a %s chip at 0x%02x (rev 0x%02x).\n",
2470 verstep == SCH5027_VERSTEP ? "SCH5027" : "DME1737",
2471 client->addr, verstep);
2472 strlcpy(info->type, name, I2C_NAME_SIZE);
2473
2474 return 0;
2475}
2476
2477static int dme1737_i2c_probe(struct i2c_client *client,
2478 const struct i2c_device_id *id)
2479{
2480 struct dme1737_data *data;
2481 struct device *dev = &client->dev;
2482 int err;
2483
2484 data = devm_kzalloc(dev, sizeof(struct dme1737_data), GFP_KERNEL);
2485 if (!data)
2486 return -ENOMEM;
2487
2488 i2c_set_clientdata(client, data);
2489 data->type = id->driver_data;
2490 data->client = client;
2491 data->name = client->name;
2492 mutex_init(&data->update_lock);
2493
2494
2495 err = dme1737_init_device(dev);
2496 if (err) {
2497 dev_err(dev, "Failed to initialize device.\n");
2498 return err;
2499 }
2500
2501
2502 err = dme1737_create_files(dev);
2503 if (err) {
2504 dev_err(dev, "Failed to create sysfs files.\n");
2505 return err;
2506 }
2507
2508
2509 data->hwmon_dev = hwmon_device_register(dev);
2510 if (IS_ERR(data->hwmon_dev)) {
2511 dev_err(dev, "Failed to register device.\n");
2512 err = PTR_ERR(data->hwmon_dev);
2513 goto exit_remove;
2514 }
2515
2516 return 0;
2517
2518exit_remove:
2519 dme1737_remove_files(dev);
2520 return err;
2521}
2522
2523static int dme1737_i2c_remove(struct i2c_client *client)
2524{
2525 struct dme1737_data *data = i2c_get_clientdata(client);
2526
2527 hwmon_device_unregister(data->hwmon_dev);
2528 dme1737_remove_files(&client->dev);
2529
2530 return 0;
2531}
2532
2533static const struct i2c_device_id dme1737_id[] = {
2534 { "dme1737", dme1737 },
2535 { "sch5027", sch5027 },
2536 { }
2537};
2538MODULE_DEVICE_TABLE(i2c, dme1737_id);
2539
2540static struct i2c_driver dme1737_i2c_driver = {
2541 .class = I2C_CLASS_HWMON,
2542 .driver = {
2543 .name = "dme1737",
2544 },
2545 .probe = dme1737_i2c_probe,
2546 .remove = dme1737_i2c_remove,
2547 .id_table = dme1737_id,
2548 .detect = dme1737_i2c_detect,
2549 .address_list = normal_i2c,
2550};
2551
2552
2553
2554
2555
2556static int __init dme1737_isa_detect(int sio_cip, unsigned short *addr)
2557{
2558 int err = 0, reg;
2559 unsigned short base_addr;
2560
2561 dme1737_sio_enter(sio_cip);
2562
2563
2564
2565
2566
2567 reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20);
2568 if (!(reg == SCH3112_ID || reg == SCH3114_ID || reg == SCH3116_ID ||
2569 reg == SCH5127_ID)) {
2570 err = -ENODEV;
2571 goto exit;
2572 }
2573
2574
2575 dme1737_sio_outb(sio_cip, 0x07, 0x0a);
2576
2577
2578 base_addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) |
2579 dme1737_sio_inb(sio_cip, 0x61);
2580 if (!base_addr) {
2581 pr_err("Base address not set\n");
2582 err = -ENODEV;
2583 goto exit;
2584 }
2585
2586
2587
2588
2589
2590 *addr = base_addr + 0x70;
2591
2592exit:
2593 dme1737_sio_exit(sio_cip);
2594 return err;
2595}
2596
2597static int __init dme1737_isa_device_add(unsigned short addr)
2598{
2599 struct resource res = {
2600 .start = addr,
2601 .end = addr + DME1737_EXTENT - 1,
2602 .name = "dme1737",
2603 .flags = IORESOURCE_IO,
2604 };
2605 int err;
2606
2607 err = acpi_check_resource_conflict(&res);
2608 if (err)
2609 goto exit;
2610
2611 pdev = platform_device_alloc("dme1737", addr);
2612 if (!pdev) {
2613 pr_err("Failed to allocate device\n");
2614 err = -ENOMEM;
2615 goto exit;
2616 }
2617
2618 err = platform_device_add_resources(pdev, &res, 1);
2619 if (err) {
2620 pr_err("Failed to add device resource (err = %d)\n", err);
2621 goto exit_device_put;
2622 }
2623
2624 err = platform_device_add(pdev);
2625 if (err) {
2626 pr_err("Failed to add device (err = %d)\n", err);
2627 goto exit_device_put;
2628 }
2629
2630 return 0;
2631
2632exit_device_put:
2633 platform_device_put(pdev);
2634 pdev = NULL;
2635exit:
2636 return err;
2637}
2638
2639static int dme1737_isa_probe(struct platform_device *pdev)
2640{
2641 u8 company, device;
2642 struct resource *res;
2643 struct dme1737_data *data;
2644 struct device *dev = &pdev->dev;
2645 int err;
2646
2647 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
2648 if (!devm_request_region(dev, res->start, DME1737_EXTENT, "dme1737")) {
2649 dev_err(dev, "Failed to request region 0x%04x-0x%04x.\n",
2650 (unsigned short)res->start,
2651 (unsigned short)res->start + DME1737_EXTENT - 1);
2652 return -EBUSY;
2653 }
2654
2655 data = devm_kzalloc(dev, sizeof(struct dme1737_data), GFP_KERNEL);
2656 if (!data)
2657 return -ENOMEM;
2658
2659 data->addr = res->start;
2660 platform_set_drvdata(pdev, data);
2661
2662
2663 switch (force_id) {
2664 case SCH3112_ID:
2665 case SCH3114_ID:
2666 case SCH3116_ID:
2667 data->type = sch311x;
2668 break;
2669 case SCH5127_ID:
2670 data->type = sch5127;
2671 break;
2672 default:
2673 company = dme1737_read(data, DME1737_REG_COMPANY);
2674 device = dme1737_read(data, DME1737_REG_DEVICE);
2675
2676 if ((company == DME1737_COMPANY_SMSC) &&
2677 (device == SCH311X_DEVICE)) {
2678 data->type = sch311x;
2679 } else if ((company == DME1737_COMPANY_SMSC) &&
2680 (device == SCH5127_DEVICE)) {
2681 data->type = sch5127;
2682 } else {
2683 return -ENODEV;
2684 }
2685 }
2686
2687 if (data->type == sch5127)
2688 data->name = "sch5127";
2689 else
2690 data->name = "sch311x";
2691
2692
2693 mutex_init(&data->update_lock);
2694
2695 dev_info(dev, "Found a %s chip at 0x%04x\n",
2696 data->type == sch5127 ? "SCH5127" : "SCH311x", data->addr);
2697
2698
2699 err = dme1737_init_device(dev);
2700 if (err) {
2701 dev_err(dev, "Failed to initialize device.\n");
2702 return err;
2703 }
2704
2705
2706 err = dme1737_create_files(dev);
2707 if (err) {
2708 dev_err(dev, "Failed to create sysfs files.\n");
2709 return err;
2710 }
2711
2712
2713 data->hwmon_dev = hwmon_device_register(dev);
2714 if (IS_ERR(data->hwmon_dev)) {
2715 dev_err(dev, "Failed to register device.\n");
2716 err = PTR_ERR(data->hwmon_dev);
2717 goto exit_remove_files;
2718 }
2719
2720 return 0;
2721
2722exit_remove_files:
2723 dme1737_remove_files(dev);
2724 return err;
2725}
2726
2727static int dme1737_isa_remove(struct platform_device *pdev)
2728{
2729 struct dme1737_data *data = platform_get_drvdata(pdev);
2730
2731 hwmon_device_unregister(data->hwmon_dev);
2732 dme1737_remove_files(&pdev->dev);
2733
2734 return 0;
2735}
2736
2737static struct platform_driver dme1737_isa_driver = {
2738 .driver = {
2739 .name = "dme1737",
2740 },
2741 .probe = dme1737_isa_probe,
2742 .remove = dme1737_isa_remove,
2743};
2744
2745
2746
2747
2748
2749static int __init dme1737_init(void)
2750{
2751 int err;
2752 unsigned short addr;
2753
2754 err = i2c_add_driver(&dme1737_i2c_driver);
2755 if (err)
2756 goto exit;
2757
2758 if (dme1737_isa_detect(0x2e, &addr) &&
2759 dme1737_isa_detect(0x4e, &addr) &&
2760 (!probe_all_addr ||
2761 (dme1737_isa_detect(0x162e, &addr) &&
2762 dme1737_isa_detect(0x164e, &addr)))) {
2763
2764 return 0;
2765 }
2766
2767 err = platform_driver_register(&dme1737_isa_driver);
2768 if (err)
2769 goto exit_del_i2c_driver;
2770
2771
2772 err = dme1737_isa_device_add(addr);
2773 if (err)
2774 goto exit_del_isa_driver;
2775
2776 return 0;
2777
2778exit_del_isa_driver:
2779 platform_driver_unregister(&dme1737_isa_driver);
2780exit_del_i2c_driver:
2781 i2c_del_driver(&dme1737_i2c_driver);
2782exit:
2783 return err;
2784}
2785
2786static void __exit dme1737_exit(void)
2787{
2788 if (pdev) {
2789 platform_device_unregister(pdev);
2790 platform_driver_unregister(&dme1737_isa_driver);
2791 }
2792
2793 i2c_del_driver(&dme1737_i2c_driver);
2794}
2795
2796MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>");
2797MODULE_DESCRIPTION("DME1737 sensors");
2798MODULE_LICENSE("GPL");
2799
2800module_init(dme1737_init);
2801module_exit(dme1737_exit);
2802