Lines Matching +full:reg +full:- +full:data
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * w83627ehf - Driver for the hardware monitoring functionality of
4 * the Winbond W83627EHF Super-I/O chip
5 * Copyright (C) 2005-2012 Jean Delvare <jdelvare@suse.de>
10 * Copyright (C) 2010 Sheng-Yuan Huang (Nuvoton) (PS00)
18 * This driver also supports the W83627EHG, which is the lead-free
27 * w83627dhg-p 9 5 4 3 0xb070 0xc1 0x5ca3
30 * w83667hg-b 9 5 3 4 0xb350 0xc1 0x5ca3
41 #include <linux/hwmon-sysfs.h>
42 #include <linux/hwmon-vid.h>
54 /* used to set data->name = w83627ehf_device_names[data->sio_kind] */
71 * Super-I/O constants and functions
83 #define SIO_REG_VID_DATA 0xF1 /* VID data */
95 superio_outb(int ioreg, int reg, int val) in superio_outb() argument
97 outb(reg, ioreg); in superio_outb()
102 superio_inb(int ioreg, int reg) in superio_inb() argument
104 outb(reg, ioreg); in superio_inb()
119 return -EBUSY; in superio_enter()
162 (0x554 + (((nr) - 7) * 2)))
164 (0x555 + (((nr) - 7) * 2)))
166 (0x550 + (nr) - 7))
236 static int is_word_sized(u16 reg) in is_word_sized() argument
238 return ((((reg & 0xff00) == 0x100 in is_word_sized()
239 || (reg & 0xff00) == 0x200) in is_word_sized()
240 && ((reg & 0x00ff) == 0x50 in is_word_sized()
241 || (reg & 0x00ff) == 0x53 in is_word_sized()
242 || (reg & 0x00ff) == 0x55)) in is_word_sized()
243 || (reg & 0xfff0) == 0x630 in is_word_sized()
244 || reg == 0x640 || reg == 0x642 in is_word_sized()
245 || ((reg & 0xfff0) == 0x650 in is_word_sized()
246 && (reg & 0x000f) >= 0x06) in is_word_sized()
247 || reg == 0x73 || reg == 0x75 || reg == 0x77 in is_word_sized()
256 static inline unsigned int step_time_from_reg(u8 reg, u8 mode) in step_time_from_reg() argument
258 return mode ? 100 * reg : 400 * reg; in step_time_from_reg()
267 static unsigned int fan_from_reg8(u16 reg, unsigned int divreg) in fan_from_reg8() argument
269 if (reg == 0 || reg == 255) in fan_from_reg8()
271 return 1350000U / (reg << divreg); in fan_from_reg8()
275 div_from_reg(u8 reg) in div_from_reg() argument
277 return 1 << reg; in div_from_reg()
291 static inline long in_from_reg(u8 reg, u8 nr, const u16 *scale_in) in in_from_reg() argument
293 return DIV_ROUND_CLOSEST(reg * scale_in[nr], 100); in in_from_reg()
302 * Data structures and manipulation thereof
345 u8 pwm_mode[4]; /* 0->DC variable voltage, 1->PWM variable duty cycle */
346 u8 pwm_enable[4]; /* 1->manual
347 * 2->thermal cruise mode (also called SmartFan I)
348 * 3->fan speed cruise mode
349 * 4->variable thermal cruise (also called
351 * 5->enhanced variable thermal cruise (also called
387 * On older chips, only registers 0x50-0x5f are banked.
392 static inline void w83627ehf_set_bank(struct w83627ehf_data *data, u16 reg) in w83627ehf_set_bank() argument
394 u8 bank = reg >> 8; in w83627ehf_set_bank()
395 if (data->bank != bank) { in w83627ehf_set_bank()
396 outb_p(W83627EHF_REG_BANK, data->addr + ADDR_REG_OFFSET); in w83627ehf_set_bank()
397 outb_p(bank, data->addr + DATA_REG_OFFSET); in w83627ehf_set_bank()
398 data->bank = bank; in w83627ehf_set_bank()
402 static u16 w83627ehf_read_value(struct w83627ehf_data *data, u16 reg) in w83627ehf_read_value() argument
404 int res, word_sized = is_word_sized(reg); in w83627ehf_read_value()
406 mutex_lock(&data->lock); in w83627ehf_read_value()
408 w83627ehf_set_bank(data, reg); in w83627ehf_read_value()
409 outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET); in w83627ehf_read_value()
410 res = inb_p(data->addr + DATA_REG_OFFSET); in w83627ehf_read_value()
412 outb_p((reg & 0xff) + 1, in w83627ehf_read_value()
413 data->addr + ADDR_REG_OFFSET); in w83627ehf_read_value()
414 res = (res << 8) + inb_p(data->addr + DATA_REG_OFFSET); in w83627ehf_read_value()
417 mutex_unlock(&data->lock); in w83627ehf_read_value()
421 static int w83627ehf_write_value(struct w83627ehf_data *data, u16 reg, in w83627ehf_write_value() argument
424 int word_sized = is_word_sized(reg); in w83627ehf_write_value()
426 mutex_lock(&data->lock); in w83627ehf_write_value()
428 w83627ehf_set_bank(data, reg); in w83627ehf_write_value()
429 outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET); in w83627ehf_write_value()
431 outb_p(value >> 8, data->addr + DATA_REG_OFFSET); in w83627ehf_write_value()
432 outb_p((reg & 0xff) + 1, in w83627ehf_write_value()
433 data->addr + ADDR_REG_OFFSET); in w83627ehf_write_value()
435 outb_p(value & 0xff, data->addr + DATA_REG_OFFSET); in w83627ehf_write_value()
437 mutex_unlock(&data->lock); in w83627ehf_write_value()
441 /* We left-align 8-bit temperature values to make the code simpler */
442 static u16 w83627ehf_read_temp(struct w83627ehf_data *data, u16 reg) in w83627ehf_read_temp() argument
446 res = w83627ehf_read_value(data, reg); in w83627ehf_read_temp()
447 if (!is_word_sized(reg)) in w83627ehf_read_temp()
453 static int w83627ehf_write_temp(struct w83627ehf_data *data, u16 reg, in w83627ehf_write_temp() argument
456 if (!is_word_sized(reg)) in w83627ehf_write_temp()
458 return w83627ehf_write_value(data, reg, value); in w83627ehf_write_temp()
461 /* This function assumes that the caller holds data->update_lock */
462 static void w83627ehf_write_fan_div(struct w83627ehf_data *data, int nr) in w83627ehf_write_fan_div() argument
464 u8 reg; in w83627ehf_write_fan_div() local
468 reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV1) & 0xcf) in w83627ehf_write_fan_div()
469 | ((data->fan_div[0] & 0x03) << 4); in w83627ehf_write_fan_div()
471 reg |= (data->has_fan & (1 << 4)) ? 1 : 0; in w83627ehf_write_fan_div()
472 w83627ehf_write_value(data, W83627EHF_REG_FANDIV1, reg); in w83627ehf_write_fan_div()
473 reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0xdf) in w83627ehf_write_fan_div()
474 | ((data->fan_div[0] & 0x04) << 3); in w83627ehf_write_fan_div()
475 w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); in w83627ehf_write_fan_div()
478 reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV1) & 0x3f) in w83627ehf_write_fan_div()
479 | ((data->fan_div[1] & 0x03) << 6); in w83627ehf_write_fan_div()
481 reg |= (data->has_fan & (1 << 4)) ? 1 : 0; in w83627ehf_write_fan_div()
482 w83627ehf_write_value(data, W83627EHF_REG_FANDIV1, reg); in w83627ehf_write_fan_div()
483 reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0xbf) in w83627ehf_write_fan_div()
484 | ((data->fan_div[1] & 0x04) << 4); in w83627ehf_write_fan_div()
485 w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); in w83627ehf_write_fan_div()
488 reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV2) & 0x3f) in w83627ehf_write_fan_div()
489 | ((data->fan_div[2] & 0x03) << 6); in w83627ehf_write_fan_div()
490 w83627ehf_write_value(data, W83627EHF_REG_FANDIV2, reg); in w83627ehf_write_fan_div()
491 reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0x7f) in w83627ehf_write_fan_div()
492 | ((data->fan_div[2] & 0x04) << 5); in w83627ehf_write_fan_div()
493 w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); in w83627ehf_write_fan_div()
496 reg = (w83627ehf_read_value(data, W83627EHF_REG_DIODE) & 0xfc) in w83627ehf_write_fan_div()
497 | (data->fan_div[3] & 0x03); in w83627ehf_write_fan_div()
498 w83627ehf_write_value(data, W83627EHF_REG_DIODE, reg); in w83627ehf_write_fan_div()
499 reg = (w83627ehf_read_value(data, W83627EHF_REG_SMI_OVT) & 0x7f) in w83627ehf_write_fan_div()
500 | ((data->fan_div[3] & 0x04) << 5); in w83627ehf_write_fan_div()
501 w83627ehf_write_value(data, W83627EHF_REG_SMI_OVT, reg); in w83627ehf_write_fan_div()
504 reg = (w83627ehf_read_value(data, W83627EHF_REG_DIODE) & 0x73) in w83627ehf_write_fan_div()
505 | ((data->fan_div[4] & 0x03) << 2) in w83627ehf_write_fan_div()
506 | ((data->fan_div[4] & 0x04) << 5); in w83627ehf_write_fan_div()
507 w83627ehf_write_value(data, W83627EHF_REG_DIODE, reg); in w83627ehf_write_fan_div()
512 static void w83627ehf_update_fan_div(struct w83627ehf_data *data) in w83627ehf_update_fan_div() argument
516 i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1); in w83627ehf_update_fan_div()
517 data->fan_div[0] = (i >> 4) & 0x03; in w83627ehf_update_fan_div()
518 data->fan_div[1] = (i >> 6) & 0x03; in w83627ehf_update_fan_div()
519 i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV2); in w83627ehf_update_fan_div()
520 data->fan_div[2] = (i >> 6) & 0x03; in w83627ehf_update_fan_div()
521 i = w83627ehf_read_value(data, W83627EHF_REG_VBAT); in w83627ehf_update_fan_div()
522 data->fan_div[0] |= (i >> 3) & 0x04; in w83627ehf_update_fan_div()
523 data->fan_div[1] |= (i >> 4) & 0x04; in w83627ehf_update_fan_div()
524 data->fan_div[2] |= (i >> 5) & 0x04; in w83627ehf_update_fan_div()
525 if (data->has_fan & ((1 << 3) | (1 << 4))) { in w83627ehf_update_fan_div()
526 i = w83627ehf_read_value(data, W83627EHF_REG_DIODE); in w83627ehf_update_fan_div()
527 data->fan_div[3] = i & 0x03; in w83627ehf_update_fan_div()
528 data->fan_div[4] = ((i >> 2) & 0x03) in w83627ehf_update_fan_div()
531 if (data->has_fan & (1 << 3)) { in w83627ehf_update_fan_div()
532 i = w83627ehf_read_value(data, W83627EHF_REG_SMI_OVT); in w83627ehf_update_fan_div()
533 data->fan_div[3] |= (i >> 5) & 0x04; in w83627ehf_update_fan_div()
537 static void w83627ehf_update_pwm(struct w83627ehf_data *data) in w83627ehf_update_pwm() argument
542 for (i = 0; i < data->pwm_num; i++) { in w83627ehf_update_pwm()
543 if (!(data->has_fan & (1 << i))) in w83627ehf_update_pwm()
546 /* pwmcfg, tolerance mapped for i=0, i=1 to same reg */ in w83627ehf_update_pwm()
548 pwmcfg = w83627ehf_read_value(data, in w83627ehf_update_pwm()
550 tolerance = w83627ehf_read_value(data, in w83627ehf_update_pwm()
553 data->pwm_mode[i] = in w83627ehf_update_pwm()
555 data->pwm_enable[i] = ((pwmcfg >> W83627EHF_PWM_ENABLE_SHIFT[i]) in w83627ehf_update_pwm()
557 data->pwm[i] = w83627ehf_read_value(data, W83627EHF_REG_PWM[i]); in w83627ehf_update_pwm()
559 data->tolerance[i] = (tolerance >> (i == 1 ? 4 : 0)) & 0x0f; in w83627ehf_update_pwm()
565 struct w83627ehf_data *data = dev_get_drvdata(dev); in w83627ehf_update_device() local
568 mutex_lock(&data->update_lock); in w83627ehf_update_device()
570 if (time_after(jiffies, data->last_updated + HZ + HZ/2) in w83627ehf_update_device()
571 || !data->valid) { in w83627ehf_update_device()
573 w83627ehf_update_fan_div(data); in w83627ehf_update_device()
576 for (i = 0; i < data->in_num; i++) { in w83627ehf_update_device()
577 if ((i == 6) && data->in6_skip) in w83627ehf_update_device()
580 data->in[i] = w83627ehf_read_value(data, in w83627ehf_update_device()
582 data->in_min[i] = w83627ehf_read_value(data, in w83627ehf_update_device()
584 data->in_max[i] = w83627ehf_read_value(data, in w83627ehf_update_device()
590 u16 reg; in w83627ehf_update_device() local
592 if (!(data->has_fan & (1 << i))) in w83627ehf_update_device()
595 reg = w83627ehf_read_value(data, W83627EHF_REG_FAN[i]); in w83627ehf_update_device()
596 data->rpm[i] = fan_from_reg8(reg, data->fan_div[i]); in w83627ehf_update_device()
598 if (data->has_fan_min & (1 << i)) in w83627ehf_update_device()
599 data->fan_min[i] = w83627ehf_read_value(data, in w83627ehf_update_device()
607 if (reg >= 0xff && data->fan_div[i] < 0x07) { in w83627ehf_update_device()
610 i + 1, div_from_reg(data->fan_div[i]), in w83627ehf_update_device()
611 div_from_reg(data->fan_div[i] + 1)); in w83627ehf_update_device()
612 data->fan_div[i]++; in w83627ehf_update_device()
613 w83627ehf_write_fan_div(data, i); in w83627ehf_update_device()
615 if ((data->has_fan_min & (1 << i)) in w83627ehf_update_device()
616 && data->fan_min[i] >= 2 in w83627ehf_update_device()
617 && data->fan_min[i] != 255) in w83627ehf_update_device()
618 w83627ehf_write_value(data, in w83627ehf_update_device()
620 (data->fan_min[i] /= 2)); in w83627ehf_update_device()
624 w83627ehf_update_pwm(data); in w83627ehf_update_device()
626 for (i = 0; i < data->pwm_num; i++) { in w83627ehf_update_device()
627 if (!(data->has_fan & (1 << i))) in w83627ehf_update_device()
630 data->fan_start_output[i] = in w83627ehf_update_device()
631 w83627ehf_read_value(data, in w83627ehf_update_device()
633 data->fan_stop_output[i] = in w83627ehf_update_device()
634 w83627ehf_read_value(data, in w83627ehf_update_device()
636 data->fan_stop_time[i] = in w83627ehf_update_device()
637 w83627ehf_read_value(data, in w83627ehf_update_device()
640 if (data->REG_FAN_MAX_OUTPUT && in w83627ehf_update_device()
641 data->REG_FAN_MAX_OUTPUT[i] != 0xff) in w83627ehf_update_device()
642 data->fan_max_output[i] = in w83627ehf_update_device()
643 w83627ehf_read_value(data, in w83627ehf_update_device()
644 data->REG_FAN_MAX_OUTPUT[i]); in w83627ehf_update_device()
646 if (data->REG_FAN_STEP_OUTPUT && in w83627ehf_update_device()
647 data->REG_FAN_STEP_OUTPUT[i] != 0xff) in w83627ehf_update_device()
648 data->fan_step_output[i] = in w83627ehf_update_device()
649 w83627ehf_read_value(data, in w83627ehf_update_device()
650 data->REG_FAN_STEP_OUTPUT[i]); in w83627ehf_update_device()
652 data->target_temp[i] = in w83627ehf_update_device()
653 w83627ehf_read_value(data, in w83627ehf_update_device()
655 (data->pwm_mode[i] == 1 ? 0x7f : 0xff); in w83627ehf_update_device()
660 if (!(data->have_temp & (1 << i))) in w83627ehf_update_device()
662 data->temp[i] = w83627ehf_read_temp(data, in w83627ehf_update_device()
663 data->reg_temp[i]); in w83627ehf_update_device()
664 if (data->reg_temp_over[i]) in w83627ehf_update_device()
665 data->temp_max[i] in w83627ehf_update_device()
666 = w83627ehf_read_temp(data, in w83627ehf_update_device()
667 data->reg_temp_over[i]); in w83627ehf_update_device()
668 if (data->reg_temp_hyst[i]) in w83627ehf_update_device()
669 data->temp_max_hyst[i] in w83627ehf_update_device()
670 = w83627ehf_read_temp(data, in w83627ehf_update_device()
671 data->reg_temp_hyst[i]); in w83627ehf_update_device()
674 if (data->have_temp_offset & (1 << i)) in w83627ehf_update_device()
675 data->temp_offset[i] in w83627ehf_update_device()
676 = w83627ehf_read_value(data, in w83627ehf_update_device()
680 data->alarms = w83627ehf_read_value(data, in w83627ehf_update_device()
682 (w83627ehf_read_value(data, in w83627ehf_update_device()
684 (w83627ehf_read_value(data, in w83627ehf_update_device()
687 data->caseopen = w83627ehf_read_value(data, in w83627ehf_update_device()
690 data->last_updated = jiffies; in w83627ehf_update_device()
691 data->valid = true; in w83627ehf_update_device()
694 mutex_unlock(&data->update_lock); in w83627ehf_update_device()
695 return data; in w83627ehf_update_device()
698 #define store_in_reg(REG, reg) \ argument
700 store_in_##reg(struct device *dev, struct w83627ehf_data *data, int channel, \
704 return -EINVAL; \
705 mutex_lock(&data->update_lock); \
706 data->in_##reg[channel] = in_to_reg(val, channel, data->scale_in); \
707 w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(channel), \
708 data->in_##reg[channel]); \
709 mutex_unlock(&data->update_lock); \
717 store_fan_min(struct device *dev, struct w83627ehf_data *data, int channel, in store_in_reg()
720 unsigned int reg; in store_in_reg() local
724 return -EINVAL; in store_in_reg()
726 mutex_lock(&data->update_lock); in store_in_reg()
729 data->fan_min[channel] = 255; in store_in_reg()
730 new_div = data->fan_div[channel]; /* No change */ in store_in_reg()
733 } else if ((reg = 1350000U / val) >= 128 * 255) { in store_in_reg()
738 data->fan_min[channel] = 254; in store_in_reg()
743 } else if (!reg) { in store_in_reg()
748 data->fan_min[channel] = 1; in store_in_reg()
760 while (reg > 192 && new_div < 7) { in store_in_reg()
761 reg >>= 1; in store_in_reg()
764 data->fan_min[channel] = reg; in store_in_reg()
771 if (new_div != data->fan_div[channel]) { in store_in_reg()
773 channel + 1, div_from_reg(data->fan_div[channel]), in store_in_reg()
775 data->fan_div[channel] = new_div; in store_in_reg()
776 w83627ehf_write_fan_div(data, channel); in store_in_reg()
778 data->last_updated = jiffies; in store_in_reg()
781 w83627ehf_write_value(data, W83627EHF_REG_FAN_MIN[channel], in store_in_reg()
782 data->fan_min[channel]); in store_in_reg()
783 mutex_unlock(&data->update_lock); in store_in_reg()
788 #define store_temp_reg(addr, reg) \ argument
790 store_##reg(struct device *dev, struct w83627ehf_data *data, int channel, \
793 mutex_lock(&data->update_lock); \
794 data->reg[channel] = LM75_TEMP_TO_REG(val); \
795 w83627ehf_write_temp(data, data->addr[channel], data->reg[channel]); \
796 mutex_unlock(&data->update_lock); \
803 store_temp_offset(struct device *dev, struct w83627ehf_data *data, int channel, in store_temp_offset() argument
806 val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -128, 127); in store_temp_offset()
808 mutex_lock(&data->update_lock); in store_temp_offset()
809 data->temp_offset[channel] = val; in store_temp_offset()
810 w83627ehf_write_value(data, W83627EHF_REG_TEMP_OFFSET[channel], val); in store_temp_offset()
811 mutex_unlock(&data->update_lock); in store_temp_offset()
816 store_pwm_mode(struct device *dev, struct w83627ehf_data *data, int channel, in store_pwm_mode() argument
819 u16 reg; in store_pwm_mode() local
822 return -EINVAL; in store_pwm_mode()
824 mutex_lock(&data->update_lock); in store_pwm_mode()
825 reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[channel]); in store_pwm_mode()
826 data->pwm_mode[channel] = val; in store_pwm_mode()
827 reg &= ~(1 << W83627EHF_PWM_MODE_SHIFT[channel]); in store_pwm_mode()
829 reg |= 1 << W83627EHF_PWM_MODE_SHIFT[channel]; in store_pwm_mode()
830 w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[channel], reg); in store_pwm_mode()
831 mutex_unlock(&data->update_lock); in store_pwm_mode()
836 store_pwm(struct device *dev, struct w83627ehf_data *data, int channel, in store_pwm() argument
841 mutex_lock(&data->update_lock); in store_pwm()
842 data->pwm[channel] = val; in store_pwm()
843 w83627ehf_write_value(data, W83627EHF_REG_PWM[channel], val); in store_pwm()
844 mutex_unlock(&data->update_lock); in store_pwm()
849 store_pwm_enable(struct device *dev, struct w83627ehf_data *data, int channel, in store_pwm_enable() argument
852 u16 reg; in store_pwm_enable() local
855 (val > 4 && val != data->pwm_enable_orig[channel])) in store_pwm_enable()
856 return -EINVAL; in store_pwm_enable()
858 mutex_lock(&data->update_lock); in store_pwm_enable()
859 data->pwm_enable[channel] = val; in store_pwm_enable()
860 reg = w83627ehf_read_value(data, in store_pwm_enable()
862 reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[channel]); in store_pwm_enable()
863 reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[channel]; in store_pwm_enable()
864 w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[channel], in store_pwm_enable()
865 reg); in store_pwm_enable()
866 mutex_unlock(&data->update_lock); in store_pwm_enable()
870 #define show_tol_temp(reg) \ argument
871 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
874 struct w83627ehf_data *data = w83627ehf_update_device(dev->parent); \
877 int nr = sensor_attr->index; \
878 return sprintf(buf, "%d\n", data->reg[nr] * 1000); \
888 struct w83627ehf_data *data = dev_get_drvdata(dev); in show_tol_temp() local
890 int nr = sensor_attr->index; in show_tol_temp()
900 mutex_lock(&data->update_lock); in show_tol_temp()
901 data->target_temp[nr] = val; in show_tol_temp()
902 w83627ehf_write_value(data, W83627EHF_REG_TARGET[nr], val); in show_tol_temp()
903 mutex_unlock(&data->update_lock); in show_tol_temp()
911 struct w83627ehf_data *data = dev_get_drvdata(dev); in store_tolerance() local
913 int nr = sensor_attr->index; in store_tolerance()
914 u16 reg; in store_tolerance() local
922 /* Limit the temp to 0C - 15C */ in store_tolerance()
925 mutex_lock(&data->update_lock); in store_tolerance()
926 reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]); in store_tolerance()
928 reg = (reg & 0x0f) | (val << 4); in store_tolerance()
930 reg = (reg & 0xf0) | val; in store_tolerance()
931 w83627ehf_write_value(data, W83627EHF_REG_TOLERANCE[nr], reg); in store_tolerance()
932 data->tolerance[nr] = val; in store_tolerance()
933 mutex_unlock(&data->update_lock); in store_tolerance()
957 #define fan_functions(reg, REG) \ argument
958 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
961 struct w83627ehf_data *data = w83627ehf_update_device(dev->parent); \
964 int nr = sensor_attr->index; \
965 return sprintf(buf, "%d\n", data->reg[nr]); \
968 store_##reg(struct device *dev, struct device_attribute *attr, \
971 struct w83627ehf_data *data = dev_get_drvdata(dev); \
974 int nr = sensor_attr->index; \
981 mutex_lock(&data->update_lock); \
982 data->reg[nr] = val; \
983 w83627ehf_write_value(data, REG[nr], val); \
984 mutex_unlock(&data->update_lock); \
990 fan_functions(fan_max_output, data->REG_FAN_MAX_OUTPUT)
991 fan_functions(fan_step_output, data->REG_FAN_STEP_OUTPUT)
993 #define fan_time_functions(reg, REG) \ argument
994 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
997 struct w83627ehf_data *data = w83627ehf_update_device(dev->parent); \
1000 int nr = sensor_attr->index; \
1002 step_time_from_reg(data->reg[nr], \
1003 data->pwm_mode[nr])); \
1007 store_##reg(struct device *dev, struct device_attribute *attr, \
1010 struct w83627ehf_data *data = dev_get_drvdata(dev); \
1013 int nr = sensor_attr->index; \
1019 val = step_time_to_reg(val, data->pwm_mode[nr]); \
1020 mutex_lock(&data->update_lock); \
1021 data->reg[nr] = val; \
1022 w83627ehf_write_value(data, REG[nr], val); \
1023 mutex_unlock(&data->update_lock); \
1081 struct w83627ehf_data *data = dev_get_drvdata(dev); in cpu0_vid_show() local
1082 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); in cpu0_vid_show()
1089 clear_caseopen(struct device *dev, struct w83627ehf_data *data, int channel, in clear_caseopen() argument
1093 u16 reg; in clear_caseopen() local
1096 return -EINVAL; in clear_caseopen()
1098 mutex_lock(&data->update_lock); in clear_caseopen()
1099 reg = w83627ehf_read_value(data, W83627EHF_REG_CASEOPEN_CLR); in clear_caseopen()
1100 w83627ehf_write_value(data, W83627EHF_REG_CASEOPEN_CLR, reg | mask); in clear_caseopen()
1101 w83627ehf_write_value(data, W83627EHF_REG_CASEOPEN_CLR, reg & ~mask); in clear_caseopen()
1102 data->valid = false; /* Force cache refresh */ in clear_caseopen()
1103 mutex_unlock(&data->update_lock); in clear_caseopen()
1112 struct w83627ehf_data *data = dev_get_drvdata(dev); in w83627ehf_attrs_visible() local
1119 if (devattr->show == cpu0_vid_show && data->have_vid) in w83627ehf_attrs_visible()
1120 return a->mode; in w83627ehf_attrs_visible()
1124 if (sda->index < 2 && in w83627ehf_attrs_visible()
1125 (devattr->show == show_fan_stop_time || in w83627ehf_attrs_visible()
1126 devattr->show == show_fan_start_output || in w83627ehf_attrs_visible()
1127 devattr->show == show_fan_stop_output)) in w83627ehf_attrs_visible()
1128 return a->mode; in w83627ehf_attrs_visible()
1130 if (sda->index < 3 && in w83627ehf_attrs_visible()
1131 (devattr->show == show_fan_max_output || in w83627ehf_attrs_visible()
1132 devattr->show == show_fan_step_output) && in w83627ehf_attrs_visible()
1133 data->REG_FAN_STEP_OUTPUT && in w83627ehf_attrs_visible()
1134 data->REG_FAN_STEP_OUTPUT[sda->index] != 0xff) in w83627ehf_attrs_visible()
1135 return a->mode; in w83627ehf_attrs_visible()
1138 if (sda->index == 2 && in w83627ehf_attrs_visible()
1139 (data->has_fan & (1 << 2)) && data->pwm_num >= 3 && in w83627ehf_attrs_visible()
1140 (devattr->show == show_fan_stop_time || in w83627ehf_attrs_visible()
1141 devattr->show == show_fan_start_output || in w83627ehf_attrs_visible()
1142 devattr->show == show_fan_stop_output)) in w83627ehf_attrs_visible()
1143 return a->mode; in w83627ehf_attrs_visible()
1145 if (sda->index == 3 && in w83627ehf_attrs_visible()
1146 (data->has_fan & (1 << 3)) && data->pwm_num >= 4 && in w83627ehf_attrs_visible()
1147 (devattr->show == show_fan_stop_time || in w83627ehf_attrs_visible()
1148 devattr->show == show_fan_start_output || in w83627ehf_attrs_visible()
1149 devattr->show == show_fan_stop_output || in w83627ehf_attrs_visible()
1150 devattr->show == show_fan_max_output || in w83627ehf_attrs_visible()
1151 devattr->show == show_fan_step_output)) in w83627ehf_attrs_visible()
1152 return a->mode; in w83627ehf_attrs_visible()
1154 if ((devattr->show == show_target_temp || in w83627ehf_attrs_visible()
1155 devattr->show == show_tolerance) && in w83627ehf_attrs_visible()
1156 (data->has_fan & (1 << sda->index)) && in w83627ehf_attrs_visible()
1157 sda->index < data->pwm_num) in w83627ehf_attrs_visible()
1158 return a->mode; in w83627ehf_attrs_visible()
1163 /* These groups handle non-standard attributes used in this device */
1217 static inline void w83627ehf_init_device(struct w83627ehf_data *data, in w83627ehf_init_device() argument
1224 tmp = w83627ehf_read_value(data, W83627EHF_REG_CONFIG); in w83627ehf_init_device()
1226 w83627ehf_write_value(data, W83627EHF_REG_CONFIG, in w83627ehf_init_device()
1231 if (!(data->have_temp & (1 << i))) in w83627ehf_init_device()
1233 if (!data->reg_temp_config[i]) in w83627ehf_init_device()
1235 tmp = w83627ehf_read_value(data, in w83627ehf_init_device()
1236 data->reg_temp_config[i]); in w83627ehf_init_device()
1238 w83627ehf_write_value(data, in w83627ehf_init_device()
1239 data->reg_temp_config[i], in w83627ehf_init_device()
1244 tmp = w83627ehf_read_value(data, W83627EHF_REG_VBAT); in w83627ehf_init_device()
1246 w83627ehf_write_value(data, W83627EHF_REG_VBAT, tmp | 0x01); in w83627ehf_init_device()
1251 diode = w83627ehf_read_value(data, W83627EHF_REG_DIODE); in w83627ehf_init_device()
1262 if (data->temp_label) in w83627ehf_init_device()
1263 label = data->temp_label[data->temp_src[i]]; in w83627ehf_init_device()
1267 data->temp_type[i] = 6; in w83627ehf_init_device()
1269 data->temp_type[i] = 5; in w83627ehf_init_device()
1271 data->temp_type[i] = (diode & (0x10 << i)) ? 1 : 3; in w83627ehf_init_device()
1273 data->temp_type[i] = 4; /* thermistor */ in w83627ehf_init_device()
1278 w83627ehf_set_temp_reg_ehf(struct w83627ehf_data *data, int n_temp) in w83627ehf_set_temp_reg_ehf() argument
1283 data->reg_temp[i] = W83627EHF_REG_TEMP[i]; in w83627ehf_set_temp_reg_ehf()
1284 data->reg_temp_over[i] = W83627EHF_REG_TEMP_OVER[i]; in w83627ehf_set_temp_reg_ehf()
1285 data->reg_temp_hyst[i] = W83627EHF_REG_TEMP_HYST[i]; in w83627ehf_set_temp_reg_ehf()
1286 data->reg_temp_config[i] = W83627EHF_REG_TEMP_CONFIG[i]; in w83627ehf_set_temp_reg_ehf()
1292 struct w83627ehf_data *data) in w83627ehf_check_fan_inputs() argument
1297 if (sio_data->kind == w83627uhg) { in w83627ehf_check_fan_inputs()
1298 data->has_fan = 0x03; /* fan1 and fan2 */ in w83627ehf_check_fan_inputs()
1299 data->has_fan_min = 0x03; in w83627ehf_check_fan_inputs()
1304 if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) { in w83627ehf_check_fan_inputs()
1306 fan4pin = superio_inb(sio_data->sioreg, 0x27) & 0x40; in w83627ehf_check_fan_inputs()
1307 fan5pin = superio_inb(sio_data->sioreg, 0x27) & 0x20; in w83627ehf_check_fan_inputs()
1310 fan4pin = !(superio_inb(sio_data->sioreg, 0x29) & 0x06); in w83627ehf_check_fan_inputs()
1311 fan5pin = !(superio_inb(sio_data->sioreg, 0x24) & 0x02); in w83627ehf_check_fan_inputs()
1314 data->has_fan = data->has_fan_min = 0x03; /* fan1 and fan2 */ in w83627ehf_check_fan_inputs()
1315 data->has_fan |= (fan3pin << 2); in w83627ehf_check_fan_inputs()
1316 data->has_fan_min |= (fan3pin << 2); in w83627ehf_check_fan_inputs()
1325 regval = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1); in w83627ehf_check_fan_inputs()
1327 data->has_fan |= (1 << 3); in w83627ehf_check_fan_inputs()
1328 data->has_fan_min |= (1 << 3); in w83627ehf_check_fan_inputs()
1331 data->has_fan |= (1 << 4); in w83627ehf_check_fan_inputs()
1332 data->has_fan_min |= (1 << 4); in w83627ehf_check_fan_inputs()
1340 const struct w83627ehf_data *data = drvdata; in w83627ehf_is_visible() local
1345 if (!(data->have_temp & (1 << channel))) in w83627ehf_is_visible()
1350 if (data->temp_label) in w83627ehf_is_visible()
1354 if (channel == 2 && data->temp3_val_only) in w83627ehf_is_visible()
1357 if (data->reg_temp_over[channel]) in w83627ehf_is_visible()
1363 if (data->reg_temp_hyst[channel]) in w83627ehf_is_visible()
1373 if (data->have_temp_offset & (1 << channel)) in w83627ehf_is_visible()
1382 if (!(data->has_fan & (1 << channel))) in w83627ehf_is_visible()
1390 if (data->has_fan_min & (1 << channel)) in w83627ehf_is_visible()
1399 if (channel >= data->in_num) in w83627ehf_is_visible()
1401 if (channel == 6 && data->in6_skip) in w83627ehf_is_visible()
1411 if (!(data->has_fan & (1 << channel)) || in w83627ehf_is_visible()
1412 channel >= data->pwm_num) in w83627ehf_is_visible()
1430 w83627ehf_do_read_temp(struct w83627ehf_data *data, u32 attr, in w83627ehf_do_read_temp() argument
1435 *val = LM75_TEMP_FROM_REG(data->temp[channel]); in w83627ehf_do_read_temp()
1438 *val = LM75_TEMP_FROM_REG(data->temp_max[channel]); in w83627ehf_do_read_temp()
1441 *val = LM75_TEMP_FROM_REG(data->temp_max_hyst[channel]); in w83627ehf_do_read_temp()
1444 *val = data->temp_offset[channel] * 1000; in w83627ehf_do_read_temp()
1447 *val = (int)data->temp_type[channel]; in w83627ehf_do_read_temp()
1452 *val = (data->alarms >> bit[channel]) & 1; in w83627ehf_do_read_temp()
1461 return -EOPNOTSUPP; in w83627ehf_do_read_temp()
1465 w83627ehf_do_read_in(struct w83627ehf_data *data, u32 attr, in w83627ehf_do_read_in() argument
1470 *val = in_from_reg(data->in[channel], channel, data->scale_in); in w83627ehf_do_read_in()
1473 *val = in_from_reg(data->in_min[channel], channel, in w83627ehf_do_read_in()
1474 data->scale_in); in w83627ehf_do_read_in()
1477 *val = in_from_reg(data->in_max[channel], channel, in w83627ehf_do_read_in()
1478 data->scale_in); in w83627ehf_do_read_in()
1483 *val = (data->alarms >> bit[channel]) & 1; in w83627ehf_do_read_in()
1490 return -EOPNOTSUPP; in w83627ehf_do_read_in()
1494 w83627ehf_do_read_fan(struct w83627ehf_data *data, u32 attr, in w83627ehf_do_read_fan() argument
1499 *val = data->rpm[channel]; in w83627ehf_do_read_fan()
1502 *val = fan_from_reg8(data->fan_min[channel], in w83627ehf_do_read_fan()
1503 data->fan_div[channel]); in w83627ehf_do_read_fan()
1506 *val = div_from_reg(data->fan_div[channel]); in w83627ehf_do_read_fan()
1511 *val = (data->alarms >> bit[channel]) & 1; in w83627ehf_do_read_fan()
1518 return -EOPNOTSUPP; in w83627ehf_do_read_fan()
1522 w83627ehf_do_read_pwm(struct w83627ehf_data *data, u32 attr, in w83627ehf_do_read_pwm() argument
1527 *val = data->pwm[channel]; in w83627ehf_do_read_pwm()
1530 *val = data->pwm_enable[channel]; in w83627ehf_do_read_pwm()
1533 *val = data->pwm_enable[channel]; in w83627ehf_do_read_pwm()
1538 return -EOPNOTSUPP; in w83627ehf_do_read_pwm()
1542 w83627ehf_do_read_intrusion(struct w83627ehf_data *data, u32 attr, in w83627ehf_do_read_intrusion() argument
1546 return -EOPNOTSUPP; /* shouldn't happen */ in w83627ehf_do_read_intrusion()
1548 *val = !!(data->caseopen & 0x10); in w83627ehf_do_read_intrusion()
1556 struct w83627ehf_data *data = w83627ehf_update_device(dev->parent); in w83627ehf_read() local
1560 return w83627ehf_do_read_fan(data, attr, channel, val); in w83627ehf_read()
1563 return w83627ehf_do_read_in(data, attr, channel, val); in w83627ehf_read()
1566 return w83627ehf_do_read_pwm(data, attr, channel, val); in w83627ehf_read()
1569 return w83627ehf_do_read_temp(data, attr, channel, val); in w83627ehf_read()
1572 return w83627ehf_do_read_intrusion(data, attr, channel, val); in w83627ehf_read()
1578 return -EOPNOTSUPP; in w83627ehf_read()
1585 struct w83627ehf_data *data = dev_get_drvdata(dev); in w83627ehf_read_string() local
1590 *str = data->temp_label[data->temp_src[channel]]; in w83627ehf_read_string()
1599 return -EOPNOTSUPP; in w83627ehf_read_string()
1606 struct w83627ehf_data *data = dev_get_drvdata(dev); in w83627ehf_write() local
1609 return store_in_min(dev, data, channel, val); in w83627ehf_write()
1611 return store_in_max(dev, data, channel, val); in w83627ehf_write()
1614 return store_fan_min(dev, data, channel, val); in w83627ehf_write()
1617 return store_temp_max(dev, data, channel, val); in w83627ehf_write()
1619 return store_temp_max_hyst(dev, data, channel, val); in w83627ehf_write()
1621 return store_temp_offset(dev, data, channel, val); in w83627ehf_write()
1624 return store_pwm_mode(dev, data, channel, val); in w83627ehf_write()
1626 return store_pwm_enable(dev, data, channel, val); in w83627ehf_write()
1628 return store_pwm(dev, data, channel, val); in w83627ehf_write()
1631 return clear_caseopen(dev, data, channel, val); in w83627ehf_write()
1633 return -EOPNOTSUPP; in w83627ehf_write()
1697 struct device *dev = &pdev->dev; in w83627ehf_probe()
1699 struct w83627ehf_data *data; in w83627ehf_probe() local
1706 if (!devm_request_region(dev, res->start, IOREGION_LENGTH, DRVNAME)) in w83627ehf_probe()
1707 return -EBUSY; in w83627ehf_probe()
1709 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); in w83627ehf_probe()
1710 if (!data) in w83627ehf_probe()
1711 return -ENOMEM; in w83627ehf_probe()
1713 data->addr = res->start; in w83627ehf_probe()
1714 mutex_init(&data->lock); in w83627ehf_probe()
1715 mutex_init(&data->update_lock); in w83627ehf_probe()
1716 data->name = w83627ehf_device_names[sio_data->kind]; in w83627ehf_probe()
1717 data->bank = 0xff; /* Force initial bank selection */ in w83627ehf_probe()
1718 platform_set_drvdata(pdev, data); in w83627ehf_probe()
1721 data->in_num = (sio_data->kind == w83627ehf) ? 10 : 9; in w83627ehf_probe()
1723 switch (sio_data->kind) { in w83627ehf_probe()
1725 data->pwm_num = 4; in w83627ehf_probe()
1729 data->pwm_num = 3; in w83627ehf_probe()
1732 data->pwm_num = 2; in w83627ehf_probe()
1737 data->have_temp = 0x07; in w83627ehf_probe()
1740 if (sio_data->kind == w83667hg_b) { in w83627ehf_probe()
1741 u8 reg; in w83627ehf_probe() local
1743 w83627ehf_set_temp_reg_ehf(data, 4); in w83627ehf_probe()
1749 reg = w83627ehf_read_value(data, 0x4a); in w83627ehf_probe()
1750 data->temp_src[0] = reg >> 5; in w83627ehf_probe()
1751 reg = w83627ehf_read_value(data, 0x49); in w83627ehf_probe()
1752 data->temp_src[1] = reg & 0x07; in w83627ehf_probe()
1753 data->temp_src[2] = (reg >> 4) & 0x07; in w83627ehf_probe()
1756 * W83667HG-B has another temperature register at 0x7e. in w83627ehf_probe()
1761 reg = w83627ehf_read_value(data, 0x7d); in w83627ehf_probe()
1762 reg &= 0x07; in w83627ehf_probe()
1763 if (reg != data->temp_src[0] && reg != data->temp_src[1] in w83627ehf_probe()
1764 && reg != data->temp_src[2]) { in w83627ehf_probe()
1765 data->temp_src[3] = reg; in w83627ehf_probe()
1766 data->have_temp |= 1 << 3; in w83627ehf_probe()
1773 reg = w83627ehf_read_value(data, W83627EHF_REG_TEMP_CONFIG[2]); in w83627ehf_probe()
1774 if (data->temp_src[2] == 2 && (reg & 0x01)) in w83627ehf_probe()
1775 data->have_temp &= ~(1 << 2); in w83627ehf_probe()
1777 if ((data->temp_src[2] == 2 && (data->have_temp & (1 << 2))) in w83627ehf_probe()
1778 || (data->temp_src[3] == 2 && (data->have_temp & (1 << 3)))) in w83627ehf_probe()
1779 data->in6_skip = 1; in w83627ehf_probe()
1781 data->temp_label = w83667hg_b_temp_label; in w83627ehf_probe()
1782 data->have_temp_offset = data->have_temp & 0x07; in w83627ehf_probe()
1784 if (data->temp_src[i] > 2) in w83627ehf_probe()
1785 data->have_temp_offset &= ~(1 << i); in w83627ehf_probe()
1787 } else if (sio_data->kind == w83627uhg) { in w83627ehf_probe()
1788 u8 reg; in w83627ehf_probe() local
1790 w83627ehf_set_temp_reg_ehf(data, 3); in w83627ehf_probe()
1796 data->temp_src[0] = 0; /* SYSTIN */ in w83627ehf_probe()
1797 reg = w83627ehf_read_value(data, 0x49) & 0x07; in w83627ehf_probe()
1799 if (reg == 0) in w83627ehf_probe()
1800 data->temp_src[1] = 1; in w83627ehf_probe()
1801 else if (reg >= 2 && reg <= 5) in w83627ehf_probe()
1802 data->temp_src[1] = reg + 2; in w83627ehf_probe()
1804 data->have_temp &= ~(1 << 1); in w83627ehf_probe()
1805 reg = w83627ehf_read_value(data, 0x4a); in w83627ehf_probe()
1806 data->temp_src[2] = reg >> 5; in w83627ehf_probe()
1812 if (data->temp_src[2] == 2 || data->temp_src[2] == 3 || in w83627ehf_probe()
1813 data->temp_src[2] == data->temp_src[0] || in w83627ehf_probe()
1814 ((data->have_temp & (1 << 1)) && in w83627ehf_probe()
1815 data->temp_src[2] == data->temp_src[1])) in w83627ehf_probe()
1816 data->have_temp &= ~(1 << 2); in w83627ehf_probe()
1818 data->temp3_val_only = 1; /* No limit regs */ in w83627ehf_probe()
1820 data->in6_skip = 1; /* No VIN3 */ in w83627ehf_probe()
1822 data->temp_label = w83667hg_b_temp_label; in w83627ehf_probe()
1823 data->have_temp_offset = data->have_temp & 0x03; in w83627ehf_probe()
1825 if (data->temp_src[i] > 1) in w83627ehf_probe()
1826 data->have_temp_offset &= ~(1 << i); in w83627ehf_probe()
1829 w83627ehf_set_temp_reg_ehf(data, 3); in w83627ehf_probe()
1833 if (sio_data->kind == w83667hg) { in w83627ehf_probe()
1834 u8 reg; in w83627ehf_probe() local
1840 reg = w83627ehf_read_value(data, in w83627ehf_probe()
1842 if (reg & 0x01) in w83627ehf_probe()
1843 data->have_temp &= ~(1 << 2); in w83627ehf_probe()
1845 data->in6_skip = 1; in w83627ehf_probe()
1847 data->have_temp_offset = data->have_temp & 0x07; in w83627ehf_probe()
1850 if (sio_data->kind == w83667hg_b) { in w83627ehf_probe()
1851 data->REG_FAN_MAX_OUTPUT = in w83627ehf_probe()
1853 data->REG_FAN_STEP_OUTPUT = in w83627ehf_probe()
1856 data->REG_FAN_MAX_OUTPUT = in w83627ehf_probe()
1858 data->REG_FAN_STEP_OUTPUT = in w83627ehf_probe()
1863 if (sio_data->kind == w83627uhg) in w83627ehf_probe()
1864 data->scale_in = scale_in_w83627uhg; in w83627ehf_probe()
1866 data->scale_in = scale_in_common; in w83627ehf_probe()
1869 w83627ehf_init_device(data, sio_data->kind); in w83627ehf_probe()
1871 data->vrm = vid_which_vrm(); in w83627ehf_probe()
1873 err = superio_enter(sio_data->sioreg); in w83627ehf_probe()
1878 if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) { in w83627ehf_probe()
1884 superio_select(sio_data->sioreg, W83667HG_LD_VID); in w83627ehf_probe()
1885 data->vid = superio_inb(sio_data->sioreg, 0xe3); in w83627ehf_probe()
1886 data->have_vid = true; in w83627ehf_probe()
1887 } else if (sio_data->kind != w83627uhg) { in w83627ehf_probe()
1888 superio_select(sio_data->sioreg, W83627EHF_LD_HWM); in w83627ehf_probe()
1889 if (superio_inb(sio_data->sioreg, SIO_REG_VID_CTRL) & 0x80) { in w83627ehf_probe()
1897 if (sio_data->kind == w83627ehf) { in w83627ehf_probe()
1898 en_vrm10 = superio_inb(sio_data->sioreg, in w83627ehf_probe()
1900 if ((en_vrm10 & 0x08) && data->vrm == 90) { in w83627ehf_probe()
1903 superio_outb(sio_data->sioreg, in w83627ehf_probe()
1907 && data->vrm == 100) { in w83627ehf_probe()
1910 superio_outb(sio_data->sioreg, in w83627ehf_probe()
1916 data->vid = superio_inb(sio_data->sioreg, in w83627ehf_probe()
1918 if (sio_data->kind == w83627ehf) /* 6 VID pins only */ in w83627ehf_probe()
1919 data->vid &= 0x3f; in w83627ehf_probe()
1920 data->have_vid = true; in w83627ehf_probe()
1927 w83627ehf_check_fan_inputs(sio_data, data); in w83627ehf_probe()
1929 superio_exit(sio_data->sioreg); in w83627ehf_probe()
1932 w83627ehf_update_fan_div(data); in w83627ehf_probe()
1934 /* Read pwm data to save original values */ in w83627ehf_probe()
1935 w83627ehf_update_pwm(data); in w83627ehf_probe()
1936 for (i = 0; i < data->pwm_num; i++) in w83627ehf_probe()
1937 data->pwm_enable_orig[i] = data->pwm_enable[i]; in w83627ehf_probe()
1939 hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev, in w83627ehf_probe()
1940 data->name, in w83627ehf_probe()
1941 data, in w83627ehf_probe()
1949 struct w83627ehf_data *data = w83627ehf_update_device(dev); in w83627ehf_suspend() local
1951 mutex_lock(&data->update_lock); in w83627ehf_suspend()
1952 data->vbat = w83627ehf_read_value(data, W83627EHF_REG_VBAT); in w83627ehf_suspend()
1953 mutex_unlock(&data->update_lock); in w83627ehf_suspend()
1960 struct w83627ehf_data *data = dev_get_drvdata(dev); in w83627ehf_resume() local
1963 mutex_lock(&data->update_lock); in w83627ehf_resume()
1964 data->bank = 0xff; /* Force initial bank selection */ in w83627ehf_resume()
1967 for (i = 0; i < data->in_num; i++) { in w83627ehf_resume()
1968 if ((i == 6) && data->in6_skip) in w83627ehf_resume()
1971 w83627ehf_write_value(data, W83627EHF_REG_IN_MIN(i), in w83627ehf_resume()
1972 data->in_min[i]); in w83627ehf_resume()
1973 w83627ehf_write_value(data, W83627EHF_REG_IN_MAX(i), in w83627ehf_resume()
1974 data->in_max[i]); in w83627ehf_resume()
1978 if (!(data->has_fan_min & (1 << i))) in w83627ehf_resume()
1981 w83627ehf_write_value(data, W83627EHF_REG_FAN_MIN[i], in w83627ehf_resume()
1982 data->fan_min[i]); in w83627ehf_resume()
1986 if (!(data->have_temp & (1 << i))) in w83627ehf_resume()
1989 if (data->reg_temp_over[i]) in w83627ehf_resume()
1990 w83627ehf_write_temp(data, data->reg_temp_over[i], in w83627ehf_resume()
1991 data->temp_max[i]); in w83627ehf_resume()
1992 if (data->reg_temp_hyst[i]) in w83627ehf_resume()
1993 w83627ehf_write_temp(data, data->reg_temp_hyst[i], in w83627ehf_resume()
1994 data->temp_max_hyst[i]); in w83627ehf_resume()
1997 if (data->have_temp_offset & (1 << i)) in w83627ehf_resume()
1998 w83627ehf_write_value(data, in w83627ehf_resume()
2000 data->temp_offset[i]); in w83627ehf_resume()
2004 w83627ehf_write_value(data, W83627EHF_REG_VBAT, data->vbat); in w83627ehf_resume()
2006 /* Force re-reading all values */ in w83627ehf_resume()
2007 data->valid = false; in w83627ehf_resume()
2008 mutex_unlock(&data->update_lock); in w83627ehf_resume()
2022 /* w83627ehf_find() looks for a '627 in the Super-I/O config space */
2029 static const char sio_name_W83627DHG_P[] __initconst = "W83627DHG-P"; in w83627ehf_find()
2032 static const char sio_name_W83667HG_B[] __initconst = "W83667HG-B"; in w83627ehf_find()
2049 sio_data->kind = w83627ehf; in w83627ehf_find()
2053 sio_data->kind = w83627ehf; in w83627ehf_find()
2057 sio_data->kind = w83627dhg; in w83627ehf_find()
2061 sio_data->kind = w83627dhg_p; in w83627ehf_find()
2065 sio_data->kind = w83627uhg; in w83627ehf_find()
2069 sio_data->kind = w83667hg; in w83627ehf_find()
2073 sio_data->kind = w83667hg_b; in w83627ehf_find()
2080 return -ENODEV; in w83627ehf_find()
2089 pr_err("Refusing to enable a Super-I/O device with a base I/O port 0\n"); in w83627ehf_find()
2091 return -ENODEV; in w83627ehf_find()
2097 pr_warn("Forcibly enabling Super-I/O. Sensor is probably unusable.\n"); in w83627ehf_find()
2103 sio_data->sioreg = sioaddr; in w83627ehf_find()
2109 * when Super-I/O functions move to a separate file, the Super-I/O
2126 * initialize sio_data->kind and sio_data->sioreg. in sensors_w83627ehf_init()
2128 * when Super-I/O functions move to a separate file, the Super-I/O in sensors_w83627ehf_init()
2129 * driver will probe 0x2e and 0x4e and auto-detect the presence of a in sensors_w83627ehf_init()
2134 return -ENODEV; in sensors_w83627ehf_init()
2137 res.end = address + IOREGION_OFFSET + IOREGION_LENGTH - 1; in sensors_w83627ehf_init()