^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * via686a.c - Part of lm_sensors, Linux kernel modules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * for hardware monitoring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Kyösti Mälkki <kmalkki@cc.hut.fi>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Mark Studebaker <mdsxyz123@yahoo.com>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * and Bob Dougherty <bobd@stanford.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * (Some conversion-factor data were contributed by Jonathan Teh Soon Yew
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * <j.teh@iname.com> and Alex van Kaam <darkside@chello.nl>.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Supports the Via VT82C686A, VT82C686B south bridges.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Reports all as a 686A.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Warning - only supports a single device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/hwmon-sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * If force_addr is set to anything different from 0, we forcibly enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * the device at the given address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static unsigned short force_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) module_param(force_addr, ushort, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) MODULE_PARM_DESC(force_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) "Initialize the base address of the sensors");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static struct platform_device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * The Via 686a southbridge has a LM78-like chip integrated on the same IC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * This driver is a customized copy of lm78.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /* Many VIA686A constants specified below */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* Length of ISA address segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define VIA686A_EXTENT 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define VIA686A_BASE_REG 0x70
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define VIA686A_ENABLE_REG 0x74
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /* The VIA686A registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* ins numbered 0-4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define VIA686A_REG_IN_MAX(nr) (0x2b + ((nr) * 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define VIA686A_REG_IN_MIN(nr) (0x2c + ((nr) * 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define VIA686A_REG_IN(nr) (0x22 + (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* fans numbered 1-2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define VIA686A_REG_FAN_MIN(nr) (0x3a + (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define VIA686A_REG_FAN(nr) (0x28 + (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* temps numbered 1-3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static const u8 VIA686A_REG_TEMP[] = { 0x20, 0x21, 0x1f };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static const u8 VIA686A_REG_TEMP_OVER[] = { 0x39, 0x3d, 0x1d };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static const u8 VIA686A_REG_TEMP_HYST[] = { 0x3a, 0x3e, 0x1e };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* bits 7-6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define VIA686A_REG_TEMP_LOW1 0x4b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* 2 = bits 5-4, 3 = bits 7-6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define VIA686A_REG_TEMP_LOW23 0x49
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define VIA686A_REG_ALARM1 0x41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define VIA686A_REG_ALARM2 0x42
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define VIA686A_REG_FANDIV 0x47
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define VIA686A_REG_CONFIG 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * The following register sets temp interrupt mode (bits 1-0 for temp1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * 3-2 for temp2, 5-4 for temp3). Modes are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * 00 interrupt stays as long as value is out-of-range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * 01 interrupt is cleared once register is read (default)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * 10 comparator mode- like 00, but ignores hysteresis
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * 11 same as 00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define VIA686A_REG_TEMP_MODE 0x4b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /* We'll just assume that you want to set all 3 simultaneously: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define VIA686A_TEMP_MODE_MASK 0x3F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define VIA686A_TEMP_MODE_CONTINUOUS 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * Conversions. Limit checking is only done on the TO_REG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * variants.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) ******** VOLTAGE CONVERSIONS (Bob Dougherty) ********
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * From HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * voltagefactor[0]=1.25/2628; (2628/1.25=2102.4) // Vccp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * voltagefactor[1]=1.25/2628; (2628/1.25=2102.4) // +2.5V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * voltagefactor[2]=1.67/2628; (2628/1.67=1573.7) // +3.3V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * voltagefactor[3]=2.6/2628; (2628/2.60=1010.8) // +5V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * voltagefactor[4]=6.3/2628; (2628/6.30=417.14) // +12V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * in[i]=(data[i+2]*25.0+133)*voltagefactor[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * That is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * volts = (25*regVal+133)*factor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * regVal = (volts/factor-133)/25
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * (These conversions were contributed by Jonathan Teh Soon Yew
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * <j.teh@iname.com>)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static inline u8 IN_TO_REG(long val, int in_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * To avoid floating point, we multiply constants by 10 (100 for +12V).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * Rounding is done (120500 is actually 133000 - 12500).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * Remember that val is expressed in 0.001V/bit, which is why we divide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * by an additional 10000 (100000 for +12V): 1000 for val and 10 (100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * for the constants.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (in_num <= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return (u8) clamp_val((val * 21024 - 1205000) / 250000, 0, 255);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) else if (in_num == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return (u8) clamp_val((val * 15737 - 1205000) / 250000, 0, 255);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) else if (in_num == 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return (u8) clamp_val((val * 10108 - 1205000) / 250000, 0, 255);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return (u8) clamp_val((val * 41714 - 12050000) / 2500000, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 255);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static inline long IN_FROM_REG(u8 val, int in_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * To avoid floating point, we multiply constants by 10 (100 for +12V).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * We also multiply them by 1000 because we want 0.001V/bit for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * output value. Rounding is done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (in_num <= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return (long) ((250000 * val + 1330000 + 21024 / 2) / 21024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) else if (in_num == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return (long) ((250000 * val + 1330000 + 15737 / 2) / 15737);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) else if (in_num == 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return (long) ((250000 * val + 1330000 + 10108 / 2) / 10108);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return (long) ((2500000 * val + 13300000 + 41714 / 2) / 41714);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /********* FAN RPM CONVERSIONS ********/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * Higher register values = slower fans (the fan's strobe gates a counter).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * But this chip saturates back at 0, not at 255 like all the other chips.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * So, 0 means 0 RPM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static inline u8 FAN_TO_REG(long rpm, int div)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (rpm == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) rpm = clamp_val(rpm, 1, 1000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 255);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (val) == 255 ? 0 : 1350000 / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) ((val) * (div)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /******** TEMP CONVERSIONS (Bob Dougherty) *********/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * linear fits from HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * if(temp<169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * return double(temp)*0.427-32.08;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * else if(temp>=169 && temp<=202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * return double(temp)*0.582-58.16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * return double(temp)*0.924-127.33;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * A fifth-order polynomial fits the unofficial data (provided by Alex van
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * Kaam <darkside@chello.nl>) a bit better. It also give more reasonable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * numbers on my machine (ie. they agree with what my BIOS tells me).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * Here's the fifth-order fit to the 8-bit data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * temp = 1.625093e-10*val^5 - 1.001632e-07*val^4 + 2.457653e-05*val^3 -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * 2.967619e-03*val^2 + 2.175144e-01*val - 7.090067e+0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * (2000-10-25- RFD: thanks to Uwe Andersen <uandersen@mayah.com> for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * finding my typos in this formula!)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * Alas, none of the elegant function-fit solutions will work because we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * aren't allowed to use floating point in the kernel and doing it with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * integers doesn't provide enough precision. So we'll do boring old
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * look-up table stuff. The unofficial data (see below) have effectively
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * 7-bit resolution (they are rounded to the nearest degree). I'm assuming
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * that the transfer function of the device is monotonic and smooth, so a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * smooth function fit to the data will allow us to get better precision.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * I used the 5th-order poly fit described above and solved for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * VIA register values 0-255. I *10 before rounding, so we get tenth-degree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * precision. (I could have done all 1024 values for our 10-bit readings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * but the function is very linear in the useful range (0-80 deg C), so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * we'll just use linear interpolation for 10-bit readings.) So, temp_lut
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * is the temp at via register values 0-255:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static const s16 temp_lut[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) -709, -688, -667, -646, -627, -607, -589, -570, -553, -536, -519,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) -503, -487, -471, -456, -442, -428, -414, -400, -387, -375,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) -362, -350, -339, -327, -316, -305, -295, -285, -275, -265,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) -255, -246, -237, -229, -220, -212, -204, -196, -188, -180,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) -173, -166, -159, -152, -145, -139, -132, -126, -120, -114,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) -108, -102, -96, -91, -85, -80, -74, -69, -64, -59, -54, -49,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) -44, -39, -34, -29, -25, -20, -15, -11, -6, -2, 3, 7, 12, 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 20, 25, 29, 33, 37, 42, 46, 50, 54, 59, 63, 67, 71, 75, 79, 84,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 88, 92, 96, 100, 104, 109, 113, 117, 121, 125, 130, 134, 138,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 142, 146, 151, 155, 159, 163, 168, 172, 176, 181, 185, 189,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 193, 198, 202, 206, 211, 215, 219, 224, 228, 232, 237, 241,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 245, 250, 254, 259, 263, 267, 272, 276, 281, 285, 290, 294,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 299, 303, 307, 312, 316, 321, 325, 330, 334, 339, 344, 348,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 353, 357, 362, 366, 371, 376, 380, 385, 390, 395, 399, 404,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 409, 414, 419, 423, 428, 433, 438, 443, 449, 454, 459, 464,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 469, 475, 480, 486, 491, 497, 502, 508, 514, 520, 526, 532,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 538, 544, 551, 557, 564, 571, 578, 584, 592, 599, 606, 614,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 621, 629, 637, 645, 654, 662, 671, 680, 689, 698, 708, 718,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 728, 738, 749, 759, 770, 782, 793, 805, 818, 830, 843, 856,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 870, 883, 898, 912, 927, 943, 958, 975, 991, 1008, 1026, 1044,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 1062, 1081, 1101, 1121, 1141, 1162, 1184, 1206, 1229, 1252,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 1276, 1301, 1326, 1352, 1378, 1406, 1434, 1462
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * the original LUT values from Alex van Kaam <darkside@chello.nl>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * (for via register values 12-240):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * {-50,-49,-47,-45,-43,-41,-39,-38,-37,-35,-34,-33,-32,-31,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * -30,-29,-28,-27,-26,-25,-24,-24,-23,-22,-21,-20,-20,-19,-18,-17,-17,-16,-15,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * -15,-14,-14,-13,-12,-12,-11,-11,-10,-9,-9,-8,-8,-7,-7,-6,-6,-5,-5,-4,-4,-3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * -3,-2,-2,-1,-1,0,0,1,1,1,3,3,3,4,4,4,5,5,5,6,6,7,7,8,8,9,9,9,10,10,11,11,12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * 12,12,13,13,13,14,14,15,15,16,16,16,17,17,18,18,19,19,20,20,21,21,21,22,22,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * 22,23,23,24,24,25,25,26,26,26,27,27,27,28,28,29,29,30,30,30,31,31,32,32,33,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * 33,34,34,35,35,35,36,36,37,37,38,38,39,39,40,40,41,41,42,42,43,43,44,44,45,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * 45,46,46,47,48,48,49,49,50,51,51,52,52,53,53,54,55,55,56,57,57,58,59,59,60,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * 61,62,62,63,64,65,66,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,83,84,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * 85,86,88,89,91,92,94,96,97,99,101,103,105,107,109,110};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * Here's the reverse LUT. I got it by doing a 6-th order poly fit (needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * an extra term for a good fit to these inverse data!) and then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * solving for each temp value from -50 to 110 (the useable range for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * this chip). Here's the fit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * viaRegVal = -1.160370e-10*val^6 +3.193693e-08*val^5 - 1.464447e-06*val^4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * - 2.525453e-04*val^3 + 1.424593e-02*val^2 + 2.148941e+00*val +7.275808e+01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * Note that n=161:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static const u8 via_lut[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 12, 12, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 20, 20, 21, 22, 23,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 39, 40,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 41, 43, 45, 46, 48, 49, 51, 53, 55, 57, 59, 60, 62, 64, 66,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 69, 71, 73, 75, 77, 79, 82, 84, 86, 88, 91, 93, 95, 98, 100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 103, 105, 107, 110, 112, 115, 117, 119, 122, 124, 126, 129,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 131, 134, 136, 138, 140, 143, 145, 147, 150, 152, 154, 156,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 182, 183, 185, 187, 188, 190, 192, 193, 195, 196, 198, 199,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 200, 202, 203, 205, 206, 207, 208, 209, 210, 211, 212, 213,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 214, 215, 216, 217, 218, 219, 220, 221, 222, 222, 223, 224,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 225, 226, 226, 227, 228, 228, 229, 230, 230, 231, 232, 232,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 233, 233, 234, 235, 235, 236, 236, 237, 237, 238, 238, 239,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 239, 240
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * Converting temps to (8-bit) hyst and over registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * No interpolation here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * The +50 is because the temps start at -50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static inline u8 TEMP_TO_REG(long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return via_lut[val <= -50000 ? 0 : val >= 110000 ? 160 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) (val < 0 ? val - 500 : val + 500) / 1000 + 50];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /* for 8-bit temperature hyst and over registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) #define TEMP_FROM_REG(val) ((long)temp_lut[val] * 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) /* for 10-bit temperature readings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static inline long TEMP_FROM_REG10(u16 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) u16 eight_bits = val >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) u16 two_bits = val & 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) /* no interpolation for these */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (two_bits == 0 || eight_bits == 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return TEMP_FROM_REG(eight_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* do some linear interpolation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return (temp_lut[eight_bits] * (4 - two_bits) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) temp_lut[eight_bits + 1] * two_bits) * 25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) #define DIV_FROM_REG(val) (1 << (val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) #define DIV_TO_REG(val) ((val) == 8 ? 3 : (val) == 4 ? 2 : (val) == 1 ? 0 : 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * For each registered chip, we need to keep some data in memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * The structure is dynamically allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) struct via686a_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) unsigned short addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct mutex update_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) char valid; /* !=0 if following fields are valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) unsigned long last_updated; /* In jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) u8 in[5]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) u8 in_max[5]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) u8 in_min[5]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) u8 fan[2]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) u8 fan_min[2]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) u16 temp[3]; /* Register value 10 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) u8 temp_over[3]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) u8 temp_hyst[3]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) u8 fan_div[2]; /* Register encoding, shifted right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) u16 alarms; /* Register encoding, combined */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static struct pci_dev *s_bridge; /* pointer to the (only) via686a */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static int via686a_probe(struct platform_device *pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static int via686a_remove(struct platform_device *pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static inline int via686a_read_value(struct via686a_data *data, u8 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return inb_p(data->addr + reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static inline void via686a_write_value(struct via686a_data *data, u8 reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) outb_p(value, data->addr + reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static struct via686a_data *via686a_update_device(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static void via686a_init_device(struct via686a_data *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) /* following are the sysfs callback functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) /* 7 voltage sensors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static ssize_t in_show(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) char *buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) struct via686a_data *data = via686a_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return sprintf(buf, "%ld\n", IN_FROM_REG(data->in[nr], nr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) static ssize_t in_min_show(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) char *buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct via686a_data *data = via686a_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_min[nr], nr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static ssize_t in_max_show(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) char *buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) struct via686a_data *data = via686a_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_max[nr], nr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static ssize_t in_min_store(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) const char *buf, size_t count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) struct via686a_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) data->in_min[nr] = IN_TO_REG(val, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) via686a_write_value(data, VIA686A_REG_IN_MIN(nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) data->in_min[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) static ssize_t in_max_store(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) const char *buf, size_t count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) struct via686a_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) data->in_max[nr] = IN_TO_REG(val, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) via686a_write_value(data, VIA686A_REG_IN_MAX(nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) data->in_max[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static SENSOR_DEVICE_ATTR_RO(in0_input, in, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) static SENSOR_DEVICE_ATTR_RO(in1_input, in, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) static SENSOR_DEVICE_ATTR_RO(in2_input, in, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static SENSOR_DEVICE_ATTR_RO(in3_input, in, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static SENSOR_DEVICE_ATTR_RO(in4_input, in, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) /* 3 temperatures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static ssize_t temp_show(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) char *buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) struct via686a_data *data = via686a_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) return sprintf(buf, "%ld\n", TEMP_FROM_REG10(data->temp[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static ssize_t temp_over_show(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) char *buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) struct via686a_data *data = via686a_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_over[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static ssize_t temp_hyst_show(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) char *buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) struct via686a_data *data = via686a_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_hyst[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) static ssize_t temp_over_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) struct device_attribute *da, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) size_t count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) struct via686a_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) data->temp_over[nr] = TEMP_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) via686a_write_value(data, VIA686A_REG_TEMP_OVER[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) data->temp_over[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) static ssize_t temp_hyst_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) struct device_attribute *da, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) size_t count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) struct via686a_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) data->temp_hyst[nr] = TEMP_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) via686a_write_value(data, VIA686A_REG_TEMP_HYST[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) data->temp_hyst[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_over, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) static SENSOR_DEVICE_ATTR_RW(temp1_max_hyst, temp_hyst, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_over, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static SENSOR_DEVICE_ATTR_RW(temp2_max_hyst, temp_hyst, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_over, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static SENSOR_DEVICE_ATTR_RW(temp3_max_hyst, temp_hyst, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /* 2 Fans */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) static ssize_t fan_show(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) char *buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) struct via686a_data *data = via686a_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) DIV_FROM_REG(data->fan_div[nr])));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) static ssize_t fan_min_show(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) char *buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) struct via686a_data *data = via686a_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) FAN_FROM_REG(data->fan_min[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) DIV_FROM_REG(data->fan_div[nr])));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) static ssize_t fan_div_show(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) char *buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) struct via686a_data *data = via686a_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) static ssize_t fan_min_store(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) const char *buf, size_t count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) struct via686a_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) via686a_write_value(data, VIA686A_REG_FAN_MIN(nr+1), data->fan_min[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) static ssize_t fan_div_store(struct device *dev, struct device_attribute *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) const char *buf, size_t count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) struct via686a_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) int old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) old = via686a_read_value(data, VIA686A_REG_FANDIV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) data->fan_div[nr] = DIV_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) via686a_write_value(data, VIA686A_REG_FANDIV, old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) /* Alarms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) struct via686a_data *data = via686a_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) return sprintf(buf, "%u\n", data->alarms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) static DEVICE_ATTR_RO(alarms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) int bitnr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) struct via686a_data *data = via686a_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) static SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) static ssize_t name_show(struct device *dev, struct device_attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) *devattr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) struct via686a_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) return sprintf(buf, "%s\n", data->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) static DEVICE_ATTR_RO(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) static struct attribute *via686a_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) &sensor_dev_attr_in0_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) &sensor_dev_attr_in1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) &sensor_dev_attr_in2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) &sensor_dev_attr_in3_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) &sensor_dev_attr_in4_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) &sensor_dev_attr_in0_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) &sensor_dev_attr_in1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) &sensor_dev_attr_in2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) &sensor_dev_attr_in3_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) &sensor_dev_attr_in4_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) &sensor_dev_attr_in0_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) &sensor_dev_attr_in1_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) &sensor_dev_attr_in2_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) &sensor_dev_attr_in3_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) &sensor_dev_attr_in4_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) &sensor_dev_attr_in0_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) &sensor_dev_attr_in1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) &sensor_dev_attr_in2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) &sensor_dev_attr_in3_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) &sensor_dev_attr_in4_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) &sensor_dev_attr_temp1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) &sensor_dev_attr_temp2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) &sensor_dev_attr_temp3_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) &sensor_dev_attr_temp1_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) &sensor_dev_attr_temp2_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) &sensor_dev_attr_temp3_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) &sensor_dev_attr_temp1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) &sensor_dev_attr_temp2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) &sensor_dev_attr_temp3_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) &sensor_dev_attr_fan1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) &sensor_dev_attr_fan2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) &sensor_dev_attr_fan1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) &sensor_dev_attr_fan2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) &sensor_dev_attr_fan1_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) &sensor_dev_attr_fan2_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) &sensor_dev_attr_fan1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) &sensor_dev_attr_fan2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) &dev_attr_alarms.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) &dev_attr_name.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) static const struct attribute_group via686a_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) .attrs = via686a_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) static struct platform_driver via686a_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) .name = "via686a",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) .probe = via686a_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) .remove = via686a_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) /* This is called when the module is loaded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) static int via686a_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) struct via686a_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) /* Reserve the ISA region */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) res = platform_get_resource(pdev, IORESOURCE_IO, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) if (!devm_request_region(&pdev->dev, res->start, VIA686A_EXTENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) via686a_driver.driver.name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) dev_err(&pdev->dev, "Region 0x%lx-0x%lx already in use!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) (unsigned long)res->start, (unsigned long)res->end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) data = devm_kzalloc(&pdev->dev, sizeof(struct via686a_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) platform_set_drvdata(pdev, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) data->addr = res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) data->name = "via686a";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) mutex_init(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) /* Initialize the VIA686A chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) via686a_init_device(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) /* Register sysfs hooks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) err = sysfs_create_group(&pdev->dev.kobj, &via686a_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) data->hwmon_dev = hwmon_device_register(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) if (IS_ERR(data->hwmon_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) err = PTR_ERR(data->hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) goto exit_remove_files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) exit_remove_files:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) sysfs_remove_group(&pdev->dev.kobj, &via686a_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) static int via686a_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) struct via686a_data *data = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) hwmon_device_unregister(data->hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) sysfs_remove_group(&pdev->dev.kobj, &via686a_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) static void via686a_update_fan_div(struct via686a_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) int reg = via686a_read_value(data, VIA686A_REG_FANDIV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) data->fan_div[0] = (reg >> 4) & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) data->fan_div[1] = reg >> 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) static void via686a_init_device(struct via686a_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) u8 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) /* Start monitoring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) reg = via686a_read_value(data, VIA686A_REG_CONFIG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) via686a_write_value(data, VIA686A_REG_CONFIG, (reg | 0x01) & 0x7F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) /* Configure temp interrupt mode for continuous-interrupt operation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) reg = via686a_read_value(data, VIA686A_REG_TEMP_MODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) via686a_write_value(data, VIA686A_REG_TEMP_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) (reg & ~VIA686A_TEMP_MODE_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) | VIA686A_TEMP_MODE_CONTINUOUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) /* Pre-read fan clock divisor values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) via686a_update_fan_div(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) static struct via686a_data *via686a_update_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) struct via686a_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) || !data->valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) for (i = 0; i <= 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) data->in[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) via686a_read_value(data, VIA686A_REG_IN(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) data->in_min[i] = via686a_read_value(data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) VIA686A_REG_IN_MIN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) (i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) data->in_max[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) via686a_read_value(data, VIA686A_REG_IN_MAX(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) for (i = 1; i <= 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) data->fan[i - 1] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) via686a_read_value(data, VIA686A_REG_FAN(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) data->fan_min[i - 1] = via686a_read_value(data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) VIA686A_REG_FAN_MIN(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) for (i = 0; i <= 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) data->temp[i] = via686a_read_value(data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) VIA686A_REG_TEMP[i]) << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) data->temp_over[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) via686a_read_value(data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) VIA686A_REG_TEMP_OVER[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) data->temp_hyst[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) via686a_read_value(data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) VIA686A_REG_TEMP_HYST[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) * add in lower 2 bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) * temp1 uses bits 7-6 of VIA686A_REG_TEMP_LOW1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) * temp2 uses bits 5-4 of VIA686A_REG_TEMP_LOW23
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) * temp3 uses bits 7-6 of VIA686A_REG_TEMP_LOW23
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) data->temp[0] |= (via686a_read_value(data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) VIA686A_REG_TEMP_LOW1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) & 0xc0) >> 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) data->temp[1] |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) (via686a_read_value(data, VIA686A_REG_TEMP_LOW23) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 0x30) >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) data->temp[2] |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) (via686a_read_value(data, VIA686A_REG_TEMP_LOW23) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 0xc0) >> 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) via686a_update_fan_div(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) data->alarms =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) via686a_read_value(data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) VIA686A_REG_ALARM1) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) (via686a_read_value(data, VIA686A_REG_ALARM2) << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) data->last_updated = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) data->valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) static const struct pci_device_id via686a_pci_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) MODULE_DEVICE_TABLE(pci, via686a_pci_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) static int via686a_device_add(unsigned short address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) struct resource res = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) .start = address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) .end = address + VIA686A_EXTENT - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) .name = "via686a",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) .flags = IORESOURCE_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) err = acpi_check_resource_conflict(&res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) pdev = platform_device_alloc("via686a", address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) if (!pdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) pr_err("Device allocation failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) err = platform_device_add_resources(pdev, &res, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) pr_err("Device resource addition failed (%d)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) goto exit_device_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) err = platform_device_add(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) pr_err("Device addition failed (%d)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) goto exit_device_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) exit_device_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) platform_device_put(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) static int via686a_pci_probe(struct pci_dev *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) const struct pci_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) u16 address, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) if (force_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) address = force_addr & ~(VIA686A_EXTENT - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) dev_warn(&dev->dev, "Forcing ISA address 0x%x\n", address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) if (PCIBIOS_SUCCESSFUL !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) pci_write_config_word(dev, VIA686A_BASE_REG, address | 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) if (PCIBIOS_SUCCESSFUL !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) pci_read_config_word(dev, VIA686A_BASE_REG, &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) address = val & ~(VIA686A_EXTENT - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) if (address == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) dev_err(&dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) "base address not set - upgrade BIOS or use force_addr=0xaddr\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) if (PCIBIOS_SUCCESSFUL !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) pci_read_config_word(dev, VIA686A_ENABLE_REG, &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) if (!(val & 0x0001)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) if (!force_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) dev_warn(&dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) "Sensors disabled, enable with force_addr=0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) dev_warn(&dev->dev, "Enabling sensors\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) if (PCIBIOS_SUCCESSFUL !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) pci_write_config_word(dev, VIA686A_ENABLE_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) val | 0x0001))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) if (platform_driver_register(&via686a_driver))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) /* Sets global pdev as a side effect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) if (via686a_device_add(address))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) goto exit_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) * Always return failure here. This is to allow other drivers to bind
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) * to this pci device. We don't really want to have control over the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) * pci device, we only wanted to read as few register values from it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) s_bridge = pci_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) exit_unregister:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) platform_driver_unregister(&via686a_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) static struct pci_driver via686a_pci_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) .name = "via686a",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) .id_table = via686a_pci_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) .probe = via686a_pci_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) static int __init sm_via686a_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) return pci_register_driver(&via686a_pci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) static void __exit sm_via686a_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) pci_unregister_driver(&via686a_pci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) if (s_bridge != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) platform_device_unregister(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) platform_driver_unregister(&via686a_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) pci_dev_put(s_bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) s_bridge = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) MODULE_AUTHOR("Kyösti Mälkki <kmalkki@cc.hut.fi>, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) "Mark Studebaker <mdsxyz123@yahoo.com> "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) "and Bob Dougherty <bobd@stanford.edu>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) MODULE_DESCRIPTION("VIA 686A Sensor device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) module_init(sm_via686a_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) module_exit(sm_via686a_exit);