Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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)  * lm85.c - Part of lm_sensors, Linux kernel modules for hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *	    monitoring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (c) 2002, 2003  Philip Pokorny <ppokorny@penguincomputing.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * Copyright (c) 2003        Margit Schubert-While <margitsw@t-online.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Copyright (c) 2004        Justin Thiessen <jthiessen@penguincomputing.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * Copyright (C) 2007--2014  Jean Delvare <jdelvare@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * Chip details at	      <http://www.national.com/ds/LM/LM85.pdf>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/hwmon-vid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/hwmon-sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/util_macros.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) /* Addresses to scan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) enum chips {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 	lm85, lm96000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 	adm1027, adt7463, adt7468,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 	emc6d100, emc6d102, emc6d103, emc6d103s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) /* The LM85 registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #define LM85_REG_IN(nr)			(0x20 + (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #define LM85_REG_IN_MIN(nr)		(0x44 + (nr) * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #define LM85_REG_IN_MAX(nr)		(0x45 + (nr) * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #define LM85_REG_TEMP(nr)		(0x25 + (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #define LM85_REG_TEMP_MIN(nr)		(0x4e + (nr) * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #define LM85_REG_TEMP_MAX(nr)		(0x4f + (nr) * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) /* Fan speeds are LSB, MSB (2 bytes) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #define LM85_REG_FAN(nr)		(0x28 + (nr) * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #define LM85_REG_FAN_MIN(nr)		(0x54 + (nr) * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #define LM85_REG_PWM(nr)		(0x30 + (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #define LM85_REG_COMPANY		0x3e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #define LM85_REG_VERSTEP		0x3f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #define ADT7468_REG_CFG5		0x7c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #define ADT7468_OFF64			(1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #define ADT7468_HFPWM			(1 << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #define IS_ADT7468_OFF64(data)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 	((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #define IS_ADT7468_HFPWM(data)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 	((data)->type == adt7468 && !((data)->cfg5 & ADT7468_HFPWM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) /* These are the recognized values for the above regs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #define LM85_COMPANY_NATIONAL		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #define LM85_COMPANY_ANALOG_DEV		0x41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #define LM85_COMPANY_SMSC		0x5c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #define LM85_VERSTEP_LM85C		0x60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #define LM85_VERSTEP_LM85B		0x62
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #define LM85_VERSTEP_LM96000_1		0x68
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) #define LM85_VERSTEP_LM96000_2		0x69
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #define LM85_VERSTEP_ADM1027		0x60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #define LM85_VERSTEP_ADT7463		0x62
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) #define LM85_VERSTEP_ADT7463C		0x6A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) #define LM85_VERSTEP_ADT7468_1		0x71
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) #define LM85_VERSTEP_ADT7468_2		0x72
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) #define LM85_VERSTEP_EMC6D100_A0        0x60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) #define LM85_VERSTEP_EMC6D100_A1        0x61
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) #define LM85_VERSTEP_EMC6D102		0x65
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) #define LM85_VERSTEP_EMC6D103_A0	0x68
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) #define LM85_VERSTEP_EMC6D103_A1	0x69
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #define LM85_VERSTEP_EMC6D103S		0x6A	/* Also known as EMC6D103:A2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) #define LM85_REG_CONFIG			0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) #define LM85_REG_ALARM1			0x41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) #define LM85_REG_ALARM2			0x42
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) #define LM85_REG_VID			0x43
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) /* Automated FAN control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) #define LM85_REG_AFAN_CONFIG(nr)	(0x5c + (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) #define LM85_REG_AFAN_RANGE(nr)		(0x5f + (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) #define LM85_REG_AFAN_SPIKE1		0x62
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) #define LM85_REG_AFAN_MINPWM(nr)	(0x64 + (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) #define LM85_REG_AFAN_LIMIT(nr)		(0x67 + (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) #define LM85_REG_AFAN_CRITICAL(nr)	(0x6a + (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) #define LM85_REG_AFAN_HYST1		0x6d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) #define LM85_REG_AFAN_HYST2		0x6e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) #define ADM1027_REG_EXTEND_ADC1		0x76
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) #define ADM1027_REG_EXTEND_ADC2		0x77
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) #define EMC6D100_REG_ALARM3             0x7d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) /* IN5, IN6 and IN7 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) #define EMC6D100_REG_IN(nr)             (0x70 + ((nr) - 5))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) #define EMC6D100_REG_IN_MIN(nr)         (0x73 + ((nr) - 5) * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) #define EMC6D100_REG_IN_MAX(nr)         (0x74 + ((nr) - 5) * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) #define EMC6D102_REG_EXTEND_ADC1	0x85
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) #define EMC6D102_REG_EXTEND_ADC2	0x86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) #define EMC6D102_REG_EXTEND_ADC3	0x87
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) #define EMC6D102_REG_EXTEND_ADC4	0x88
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114)  * Conversions. Rounding and limit checking is only done on the TO_REG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115)  * variants. Note that you should be a bit careful with which arguments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116)  * these macros are called: arguments may be evaluated more than once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) /* IN are scaled according to built-in resistors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) static const int lm85_scaling[] = {  /* .001 Volts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	2500, 2250, 3300, 5000, 12000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	3300, 1500, 1800 /*EMC6D100*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) #define SCALE(val, from, to)	(((val) * (to) + ((from) / 2)) / (from))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) #define INS_TO_REG(n, val)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 		SCALE(clamp_val(val, 0, 255 * lm85_scaling[n] / 192), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 		      lm85_scaling[n], 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) #define INSEXT_FROM_REG(n, val, ext)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 		SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) #define INS_FROM_REG(n, val)	SCALE((val), 192, lm85_scaling[n])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) /* FAN speed is measured using 90kHz clock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) static inline u16 FAN_TO_REG(unsigned long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	if (!val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 		return 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	return clamp_val(5400000 / val, 1, 0xfffe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) #define FAN_FROM_REG(val)	((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 				 5400000 / (val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) /* Temperature is reported in .001 degC increments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) #define TEMP_TO_REG(val)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 		DIV_ROUND_CLOSEST(clamp_val((val), -127000, 127000), 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) #define TEMPEXT_FROM_REG(val, ext)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 		SCALE(((val) << 4) + (ext), 16, 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) #define TEMP_FROM_REG(val)	((val) * 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) #define PWM_TO_REG(val)			clamp_val(val, 0, 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) #define PWM_FROM_REG(val)		(val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156)  * ZONEs have the following parameters:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157)  *    Limit (low) temp,           1. degC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158)  *    Hysteresis (below limit),   1. degC (0-15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159)  *    Range of speed control,     .1 degC (2-80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160)  *    Critical (high) temp,       1. degC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162)  * FAN PWMs have the following parameters:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163)  *    Reference Zone,                 1, 2, 3, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164)  *    Spinup time,                    .05 sec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165)  *    PWM value at limit/low temp,    1 count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166)  *    PWM Frequency,                  1. Hz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167)  *    PWM is Min or OFF below limit,  flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168)  *    Invert PWM output,              flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170)  * Some chips filter the temp, others the fan.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171)  *    Filter constant (or disabled)   .1 seconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) /* These are the zone temperature range encodings in .001 degree C */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) static const int lm85_range_map[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	2000, 2500, 3300, 4000, 5000, 6600, 8000, 10000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) static int RANGE_TO_REG(long range)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	return find_closest(range, lm85_range_map, ARRAY_SIZE(lm85_range_map));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) #define RANGE_FROM_REG(val)	lm85_range_map[(val) & 0x0f]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) /* These are the PWM frequency encodings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) static const int lm85_freq_map[] = { /* 1 Hz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	10, 15, 23, 30, 38, 47, 61, 94
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) static const int lm96000_freq_map[] = { /* 1 Hz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	10, 15, 23, 30, 38, 47, 61, 94,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	22500, 24000, 25700, 25700, 27700, 27700, 30000, 30000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) static const int adm1027_freq_map[] = { /* 1 Hz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	11, 15, 22, 29, 35, 44, 59, 88
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) static int FREQ_TO_REG(const int *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 		       unsigned int map_size, unsigned long freq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	return find_closest(freq, map, map_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) static int FREQ_FROM_REG(const int *map, unsigned int map_size, u8 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	return map[reg % map_size];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212)  * Since we can't use strings, I'm abusing these numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213)  *   to stand in for the following meanings:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214)  *      1 -- PWM responds to Zone 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215)  *      2 -- PWM responds to Zone 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216)  *      3 -- PWM responds to Zone 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217)  *     23 -- PWM responds to the higher temp of Zone 2 or 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218)  *    123 -- PWM responds to highest of Zone 1, 2, or 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219)  *      0 -- PWM is always at 0% (ie, off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220)  *     -1 -- PWM is always at 100%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221)  *     -2 -- PWM responds to manual control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) static const int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) #define ZONE_FROM_REG(val)	lm85_zone_map[(val) >> 5]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) static int ZONE_TO_REG(int zone)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	for (i = 0; i <= 7; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 		if (zone == lm85_zone_map[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	if (i > 7)   /* Not found. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 		i = 3;  /* Always 100% */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	return i << 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) #define HYST_TO_REG(val)	clamp_val(((val) + 500) / 1000, 0, 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) #define HYST_FROM_REG(val)	((val) * 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243)  * Chip sampling rates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245)  * Some sensors are not updated more frequently than once per second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246)  *    so it doesn't make sense to read them more often than that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247)  *    We cache the results and return the saved data if the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248)  *    is called again before a second has elapsed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250)  * Also, there is significant configuration data for this chip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251)  *    given the automatic PWM fan control that is possible.  There
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252)  *    are about 47 bytes of config data to only 22 bytes of actual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253)  *    readings.  So, we keep the config data up to date in the cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254)  *    when it is written and only sample it once every 1 *minute*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) #define LM85_DATA_INTERVAL  (HZ + HZ / 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) #define LM85_CONFIG_INTERVAL  (1 * 60 * HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260)  * LM85 can automatically adjust fan speeds based on temperature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261)  * This structure encapsulates an entire Zone config.  There are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262)  * three zones (one for each temperature input) on the lm85
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) struct lm85_zone {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	s8 limit;	/* Low temp limit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	u8 hyst;	/* Low limit hysteresis. (0-15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	u8 range;	/* Temp range, encoded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	s8 critical;	/* "All fans ON" temp limit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	u8 max_desired; /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 			 * Actual "max" temperature specified.  Preserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 			 * to prevent "drift" as other autofan control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 			 * values change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) struct lm85_autofan {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	u8 config;	/* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	u8 min_pwm;	/* Minimum PWM value, encoded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	u8 min_off;	/* Min PWM or OFF below "limit", flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283)  * For each registered chip, we need to keep some data in memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284)  * The structure is dynamically allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) struct lm85_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	const struct attribute_group *groups[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	const int *freq_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	unsigned int freq_map_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	enum chips type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	bool has_vid5;	/* true if VID5 is configured for ADT7463 or ADT7468 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	struct mutex update_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	int valid;		/* !=0 if following fields are valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	unsigned long last_reading;	/* In jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	unsigned long last_config;	/* In jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	u8 in[8];		/* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	u8 in_max[8];		/* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	u8 in_min[8];		/* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	s8 temp[3];		/* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	s8 temp_min[3];		/* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	s8 temp_max[3];		/* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	u16 fan[4];		/* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	u16 fan_min[4];		/* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	u8 pwm[3];		/* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	u8 pwm_freq[3];		/* Register encoding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	u8 temp_ext[3];		/* Decoded values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	u8 in_ext[8];		/* Decoded values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	u8 vid;			/* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	u8 vrm;			/* VRM version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	u32 alarms;		/* Register encoding, combined */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	u8 cfg5;		/* Config Register 5 on ADT7468 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	struct lm85_autofan autofan[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	struct lm85_zone zone[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) static int lm85_read_value(struct i2c_client *client, u8 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	/* What size location is it? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	switch (reg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	case LM85_REG_FAN(0):  /* Read WORD data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	case LM85_REG_FAN(1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	case LM85_REG_FAN(2):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	case LM85_REG_FAN(3):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	case LM85_REG_FAN_MIN(0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	case LM85_REG_FAN_MIN(1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	case LM85_REG_FAN_MIN(2):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	case LM85_REG_FAN_MIN(3):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	case LM85_REG_ALARM1:	/* Read both bytes at once */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		res = i2c_smbus_read_byte_data(client, reg) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		res |= i2c_smbus_read_byte_data(client, reg + 1) << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	default:	/* Read BYTE data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		res = i2c_smbus_read_byte_data(client, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) static void lm85_write_value(struct i2c_client *client, u8 reg, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	switch (reg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	case LM85_REG_FAN(0):  /* Write WORD data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	case LM85_REG_FAN(1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	case LM85_REG_FAN(2):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	case LM85_REG_FAN(3):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	case LM85_REG_FAN_MIN(0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	case LM85_REG_FAN_MIN(1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	case LM85_REG_FAN_MIN(2):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	case LM85_REG_FAN_MIN(3):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	/* NOTE: ALARM is read only, so not included here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 		i2c_smbus_write_byte_data(client, reg, value & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		i2c_smbus_write_byte_data(client, reg + 1, value >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	default:	/* Write BYTE data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		i2c_smbus_write_byte_data(client, reg, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	}
^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 struct lm85_data *lm85_update_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	if (!data->valid ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	     time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		/* Things that change quickly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 		dev_dbg(&client->dev, "Reading sensor values\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 		 * Have to read extended bits first to "freeze" the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 		 * more significant bits that are read later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		 * There are 2 additional resolution bits per channel and we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 		 * have room for 4, so we shift them to the left.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		if (data->type == adm1027 || data->type == adt7463 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 		    data->type == adt7468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 			int ext1 = lm85_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 						   ADM1027_REG_EXTEND_ADC1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 			int ext2 =  lm85_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 						    ADM1027_REG_EXTEND_ADC2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 			int val = (ext1 << 8) + ext2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 			for (i = 0; i <= 4; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 				data->in_ext[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 					((val >> (i * 2)) & 0x03) << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 			for (i = 0; i <= 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 				data->temp_ext[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 					(val >> ((i + 4) * 2)) & 0x0c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 		data->vid = lm85_read_value(client, LM85_REG_VID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		for (i = 0; i <= 3; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 			data->in[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 			    lm85_read_value(client, LM85_REG_IN(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 			data->fan[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 			    lm85_read_value(client, LM85_REG_FAN(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		if (!data->has_vid5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 			data->in[4] = lm85_read_value(client, LM85_REG_IN(4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		if (data->type == adt7468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 			data->cfg5 = lm85_read_value(client, ADT7468_REG_CFG5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 		for (i = 0; i <= 2; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 			data->temp[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 			    lm85_read_value(client, LM85_REG_TEMP(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 			data->pwm[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 			    lm85_read_value(client, LM85_REG_PWM(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 			if (IS_ADT7468_OFF64(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 				data->temp[i] -= 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		data->alarms = lm85_read_value(client, LM85_REG_ALARM1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 		if (data->type == emc6d100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 			/* Three more voltage sensors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 			for (i = 5; i <= 7; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 				data->in[i] = lm85_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 							EMC6D100_REG_IN(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 			/* More alarm bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 			data->alarms |= lm85_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 						EMC6D100_REG_ALARM3) << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 		} else if (data->type == emc6d102 || data->type == emc6d103 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 			   data->type == emc6d103s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 			 * Have to read LSB bits after the MSB ones because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 			 * the reading of the MSB bits has frozen the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 			 * LSBs (backward from the ADM1027).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 			int ext1 = lm85_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 						   EMC6D102_REG_EXTEND_ADC1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 			int ext2 = lm85_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 						   EMC6D102_REG_EXTEND_ADC2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 			int ext3 = lm85_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 						   EMC6D102_REG_EXTEND_ADC3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 			int ext4 = lm85_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 						   EMC6D102_REG_EXTEND_ADC4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 			data->in_ext[0] = ext3 & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 			data->in_ext[1] = ext4 & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 			data->in_ext[2] = ext4 >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 			data->in_ext[3] = ext3 >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 			data->in_ext[4] = ext2 >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 			data->temp_ext[0] = ext1 & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 			data->temp_ext[1] = ext2 & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 			data->temp_ext[2] = ext1 >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		data->last_reading = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	}  /* last_reading */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	if (!data->valid ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	     time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 		/* Things that don't change often */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		dev_dbg(&client->dev, "Reading config values\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		for (i = 0; i <= 3; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 			data->in_min[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 			    lm85_read_value(client, LM85_REG_IN_MIN(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 			data->in_max[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 			    lm85_read_value(client, LM85_REG_IN_MAX(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 			data->fan_min[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 			    lm85_read_value(client, LM85_REG_FAN_MIN(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		if (!data->has_vid5)  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 			data->in_min[4] = lm85_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 					  LM85_REG_IN_MIN(4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 			data->in_max[4] = lm85_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 					  LM85_REG_IN_MAX(4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		if (data->type == emc6d100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 			for (i = 5; i <= 7; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 				data->in_min[i] = lm85_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 						EMC6D100_REG_IN_MIN(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 				data->in_max[i] = lm85_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 						EMC6D100_REG_IN_MAX(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		for (i = 0; i <= 2; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 			int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 			data->temp_min[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 			    lm85_read_value(client, LM85_REG_TEMP_MIN(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 			data->temp_max[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 			    lm85_read_value(client, LM85_REG_TEMP_MAX(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 			data->autofan[i].config =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 			    lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 			val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 			data->pwm_freq[i] = val % data->freq_map_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 			data->zone[i].range = val >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 			data->autofan[i].min_pwm =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 			    lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 			data->zone[i].limit =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 			    lm85_read_value(client, LM85_REG_AFAN_LIMIT(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 			data->zone[i].critical =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 			    lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 			if (IS_ADT7468_OFF64(data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 				data->temp_min[i] -= 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 				data->temp_max[i] -= 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 				data->zone[i].limit -= 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 				data->zone[i].critical -= 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 		if (data->type != emc6d103s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 			i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 			data->autofan[0].min_off = (i & 0x20) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 			data->autofan[1].min_off = (i & 0x40) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 			data->autofan[2].min_off = (i & 0x80) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 			i = lm85_read_value(client, LM85_REG_AFAN_HYST1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 			data->zone[0].hyst = i >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 			data->zone[1].hyst = i & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 			i = lm85_read_value(client, LM85_REG_AFAN_HYST2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 			data->zone[2].hyst = i >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		data->last_config = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	}  /* last_config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	data->valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) /* 4 Fans */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) static ssize_t fan_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 			char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 			    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) static ssize_t fan_min_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 			     struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 			     size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	data->fan_min[nr] = FAN_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) static SENSOR_DEVICE_ATTR_RO(fan3_input, fan, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) static SENSOR_DEVICE_ATTR_RW(fan3_min, fan_min, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) static SENSOR_DEVICE_ATTR_RO(fan4_input, fan, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) static SENSOR_DEVICE_ATTR_RW(fan4_min, fan_min, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) /* vid, vrm, alarms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) static ssize_t cpu0_vid_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 			     struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	int vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	if (data->has_vid5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 		/* 6-pin VID (VRM 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		vid = vid_from_reg(data->vid & 0x3f, data->vrm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		/* 5-pin VID (VRM 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		vid = vid_from_reg(data->vid & 0x1f, data->vrm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	return sprintf(buf, "%d\n", vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) static DEVICE_ATTR_RO(cpu0_vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) static ssize_t vrm_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 			char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	return sprintf(buf, "%ld\n", (long) data->vrm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) static ssize_t vrm_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 			 const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	if (val > 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	data->vrm = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) static DEVICE_ATTR_RW(vrm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 			   char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	return sprintf(buf, "%u\n", data->alarms);
^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 DEVICE_ATTR_RO(alarms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 			  char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	return sprintf(buf, "%u\n", (data->alarms >> nr) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) static SENSOR_DEVICE_ATTR_RO(in5_alarm, alarm, 18);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) static SENSOR_DEVICE_ATTR_RO(in6_alarm, alarm, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) static SENSOR_DEVICE_ATTR_RO(in7_alarm, alarm, 17);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) static SENSOR_DEVICE_ATTR_RO(temp1_fault, alarm, 14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) static SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) static SENSOR_DEVICE_ATTR_RO(fan3_alarm, alarm, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) static SENSOR_DEVICE_ATTR_RO(fan4_alarm, alarm, 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) /* pwm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) static ssize_t pwm_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 			char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) static ssize_t pwm_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 			 const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	data->pwm[nr] = PWM_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) static ssize_t pwm_enable_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 			       struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	int pwm_zone, enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	pwm_zone = ZONE_FROM_REG(data->autofan[nr].config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	switch (pwm_zone) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	case -1:	/* PWM is always at 100% */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		enable = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	case 0:		/* PWM is always at 0% */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	case -2:	/* PWM responds to manual control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		enable = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	default:	/* PWM in automatic mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		enable = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	return sprintf(buf, "%d\n", enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) static ssize_t pwm_enable_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 				struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 				const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	u8 config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	switch (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		config = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 		config = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		 * Here we have to choose arbitrarily one of the 5 possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		 * configurations; I go for the safest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		config = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	data->autofan[nr].config = lm85_read_value(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		LM85_REG_AFAN_CONFIG(nr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	data->autofan[nr].config = (data->autofan[nr].config & ~0xe0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		| (config << 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 		data->autofan[nr].config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) static ssize_t pwm_freq_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 			     struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	int freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	if (IS_ADT7468_HFPWM(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		freq = 22500;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		freq = FREQ_FROM_REG(data->freq_map, data->freq_map_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 				     data->pwm_freq[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	return sprintf(buf, "%d\n", freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) static ssize_t pwm_freq_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 			      struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 			      size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	 * The ADT7468 has a special high-frequency PWM output mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	 * where all PWM outputs are driven by a 22.5 kHz clock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	 * This might confuse the user, but there's not much we can do.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	if (data->type == adt7468 && val >= 11300) {	/* High freq. mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		data->cfg5 &= ~ADT7468_HFPWM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	} else {					/* Low freq. mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 						 data->freq_map_size, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 				 (data->zone[nr].range << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 				 | data->pwm_freq[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		if (data->type == adt7468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 			data->cfg5 |= ADT7468_HFPWM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 			lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) static SENSOR_DEVICE_ATTR_RW(pwm1, pwm, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) static SENSOR_DEVICE_ATTR_RW(pwm1_enable, pwm_enable, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) static SENSOR_DEVICE_ATTR_RW(pwm1_freq, pwm_freq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) static SENSOR_DEVICE_ATTR_RW(pwm2, pwm, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) static SENSOR_DEVICE_ATTR_RW(pwm2_enable, pwm_enable, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) static SENSOR_DEVICE_ATTR_RW(pwm2_freq, pwm_freq, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) static SENSOR_DEVICE_ATTR_RW(pwm3, pwm, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) static SENSOR_DEVICE_ATTR_RW(pwm3_enable, pwm_enable, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) static SENSOR_DEVICE_ATTR_RW(pwm3_freq, pwm_freq, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) /* Voltages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) static ssize_t in_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		       char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	return sprintf(buf, "%d\n", INSEXT_FROM_REG(nr, data->in[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 						    data->in_ext[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) static ssize_t in_min_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 			   char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_min[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) static ssize_t in_min_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 			    const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	data->in_min[nr] = INS_TO_REG(nr, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) static ssize_t in_max_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 			   char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_max[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) static ssize_t in_max_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 			    const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	data->in_max[nr] = INS_TO_REG(nr, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) static SENSOR_DEVICE_ATTR_RO(in0_input, in, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) static SENSOR_DEVICE_ATTR_RO(in1_input, in, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) static SENSOR_DEVICE_ATTR_RO(in2_input, in, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) static SENSOR_DEVICE_ATTR_RO(in3_input, in, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) static SENSOR_DEVICE_ATTR_RO(in4_input, in, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) static SENSOR_DEVICE_ATTR_RO(in5_input, in, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) static SENSOR_DEVICE_ATTR_RW(in5_min, in_min, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) static SENSOR_DEVICE_ATTR_RW(in5_max, in_max, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) static SENSOR_DEVICE_ATTR_RO(in6_input, in, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) static SENSOR_DEVICE_ATTR_RW(in6_min, in_min, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) static SENSOR_DEVICE_ATTR_RW(in6_max, in_max, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) static SENSOR_DEVICE_ATTR_RO(in7_input, in, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) static SENSOR_DEVICE_ATTR_RW(in7_min, in_min, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) static SENSOR_DEVICE_ATTR_RW(in7_max, in_max, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) /* Temps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) static ssize_t temp_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 			 char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	return sprintf(buf, "%d\n", TEMPEXT_FROM_REG(data->temp[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 						     data->temp_ext[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) static ssize_t temp_min_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 			     struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) static ssize_t temp_min_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 			      struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 			      size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	if (IS_ADT7468_OFF64(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		val += 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	data->temp_min[nr] = TEMP_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) static ssize_t temp_max_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 			     struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) static ssize_t temp_max_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 			      struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 			      size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	if (IS_ADT7468_OFF64(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		val += 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	data->temp_max[nr] = TEMP_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) static SENSOR_DEVICE_ATTR_RW(temp1_min, temp_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) static SENSOR_DEVICE_ATTR_RW(temp2_min, temp_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) static SENSOR_DEVICE_ATTR_RW(temp3_min, temp_min, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_max, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) /* Automatic PWM control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) static ssize_t pwm_auto_channels_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 				      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 				      char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	return sprintf(buf, "%d\n", ZONE_FROM_REG(data->autofan[nr].config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) static ssize_t pwm_auto_channels_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 				       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 				       const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	data->autofan[nr].config = (data->autofan[nr].config & (~0xe0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		| ZONE_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		data->autofan[nr].config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) static ssize_t pwm_auto_pwm_min_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 				     struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	return sprintf(buf, "%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) static ssize_t pwm_auto_pwm_min_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 				      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 				      const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	data->autofan[nr].min_pwm = PWM_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 		data->autofan[nr].min_pwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) static ssize_t pwm_auto_pwm_minctl_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 					struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 					char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	return sprintf(buf, "%d\n", data->autofan[nr].min_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) static ssize_t pwm_auto_pwm_minctl_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 					 struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 					 const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	u8 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	data->autofan[nr].min_off = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	tmp = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	tmp &= ~(0x20 << nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	if (data->autofan[nr].min_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 		tmp |= 0x20 << nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	lm85_write_value(client, LM85_REG_AFAN_SPIKE1, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) static SENSOR_DEVICE_ATTR_RW(pwm1_auto_channels, pwm_auto_channels, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) static SENSOR_DEVICE_ATTR_RW(pwm1_auto_pwm_min, pwm_auto_pwm_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) static SENSOR_DEVICE_ATTR_RW(pwm1_auto_pwm_minctl, pwm_auto_pwm_minctl, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) static SENSOR_DEVICE_ATTR_RW(pwm2_auto_channels, pwm_auto_channels, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) static SENSOR_DEVICE_ATTR_RW(pwm2_auto_pwm_min, pwm_auto_pwm_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) static SENSOR_DEVICE_ATTR_RW(pwm2_auto_pwm_minctl, pwm_auto_pwm_minctl, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) static SENSOR_DEVICE_ATTR_RW(pwm3_auto_channels, pwm_auto_channels, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) static SENSOR_DEVICE_ATTR_RW(pwm3_auto_pwm_min, pwm_auto_pwm_min, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) static SENSOR_DEVICE_ATTR_RW(pwm3_auto_pwm_minctl, pwm_auto_pwm_minctl, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) /* Temperature settings for automatic PWM control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) static ssize_t temp_auto_temp_off_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 				       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 				       char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		HYST_FROM_REG(data->zone[nr].hyst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) static ssize_t temp_auto_temp_off_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 					struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 					const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	int min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	min = TEMP_FROM_REG(data->zone[nr].limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	data->zone[nr].hyst = HYST_TO_REG(min - val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	if (nr == 0 || nr == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		lm85_write_value(client, LM85_REG_AFAN_HYST1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 			(data->zone[0].hyst << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 			| data->zone[1].hyst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 		lm85_write_value(client, LM85_REG_AFAN_HYST2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 			(data->zone[2].hyst << 4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) static ssize_t temp_auto_temp_min_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 				       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 				       char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) static ssize_t temp_auto_temp_min_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 					struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 					const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	data->zone[nr].limit = TEMP_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 		data->zone[nr].limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) /* Update temp_auto_max and temp_auto_range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	data->zone[nr].range = RANGE_TO_REG(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 		TEMP_FROM_REG(data->zone[nr].max_desired) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 		TEMP_FROM_REG(data->zone[nr].limit));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 		((data->zone[nr].range & 0x0f) << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 		| data->pwm_freq[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) static ssize_t temp_auto_temp_max_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 				       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 				       char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 		RANGE_FROM_REG(data->zone[nr].range));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) static ssize_t temp_auto_temp_max_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 					struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 					const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	int min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	min = TEMP_FROM_REG(data->zone[nr].limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	data->zone[nr].max_desired = TEMP_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	data->zone[nr].range = RANGE_TO_REG(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 		val - min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 		((data->zone[nr].range & 0x0f) << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 		| data->pwm_freq[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) static ssize_t temp_auto_temp_crit_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 					struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 					char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	struct lm85_data *data = lm85_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].critical));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) static ssize_t temp_auto_temp_crit_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 					 struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 					 const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	int nr = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	struct lm85_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	data->zone[nr].critical = TEMP_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 		data->zone[nr].critical);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_off, temp_auto_temp_off, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_min, temp_auto_temp_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_max, temp_auto_temp_max, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_crit, temp_auto_temp_crit, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_off, temp_auto_temp_off, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_min, temp_auto_temp_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_max, temp_auto_temp_max, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_crit, temp_auto_temp_crit, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_off, temp_auto_temp_off, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_min, temp_auto_temp_min, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_max, temp_auto_temp_max, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_crit, temp_auto_temp_crit, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) static struct attribute *lm85_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	&sensor_dev_attr_fan1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	&sensor_dev_attr_fan2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	&sensor_dev_attr_fan3_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	&sensor_dev_attr_fan4_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	&sensor_dev_attr_fan1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	&sensor_dev_attr_fan2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	&sensor_dev_attr_fan3_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	&sensor_dev_attr_fan4_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	&sensor_dev_attr_fan1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	&sensor_dev_attr_fan2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	&sensor_dev_attr_fan3_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	&sensor_dev_attr_fan4_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	&sensor_dev_attr_pwm1.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	&sensor_dev_attr_pwm2.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	&sensor_dev_attr_pwm3.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	&sensor_dev_attr_pwm1_enable.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	&sensor_dev_attr_pwm2_enable.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	&sensor_dev_attr_pwm3_enable.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	&sensor_dev_attr_pwm1_freq.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	&sensor_dev_attr_pwm2_freq.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	&sensor_dev_attr_pwm3_freq.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	&sensor_dev_attr_in0_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	&sensor_dev_attr_in1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	&sensor_dev_attr_in2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	&sensor_dev_attr_in3_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	&sensor_dev_attr_in0_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	&sensor_dev_attr_in1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	&sensor_dev_attr_in2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	&sensor_dev_attr_in3_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	&sensor_dev_attr_in0_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	&sensor_dev_attr_in1_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	&sensor_dev_attr_in2_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	&sensor_dev_attr_in3_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	&sensor_dev_attr_in0_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	&sensor_dev_attr_in1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	&sensor_dev_attr_in2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 	&sensor_dev_attr_in3_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	&sensor_dev_attr_temp1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	&sensor_dev_attr_temp2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	&sensor_dev_attr_temp3_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	&sensor_dev_attr_temp1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	&sensor_dev_attr_temp2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	&sensor_dev_attr_temp3_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	&sensor_dev_attr_temp1_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	&sensor_dev_attr_temp2_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	&sensor_dev_attr_temp3_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	&sensor_dev_attr_temp1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	&sensor_dev_attr_temp2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	&sensor_dev_attr_temp3_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	&sensor_dev_attr_temp1_fault.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	&sensor_dev_attr_temp3_fault.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	&sensor_dev_attr_pwm1_auto_channels.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 	&sensor_dev_attr_pwm2_auto_channels.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	&sensor_dev_attr_pwm3_auto_channels.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	&sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	&sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	&sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	&sensor_dev_attr_temp1_auto_temp_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	&sensor_dev_attr_temp2_auto_temp_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	&sensor_dev_attr_temp3_auto_temp_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	&sensor_dev_attr_temp1_auto_temp_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	&sensor_dev_attr_temp2_auto_temp_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	&sensor_dev_attr_temp3_auto_temp_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	&sensor_dev_attr_temp1_auto_temp_crit.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	&sensor_dev_attr_temp2_auto_temp_crit.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	&sensor_dev_attr_temp3_auto_temp_crit.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 	&dev_attr_vrm.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	&dev_attr_cpu0_vid.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	&dev_attr_alarms.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) static const struct attribute_group lm85_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	.attrs = lm85_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) static struct attribute *lm85_attributes_minctl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	&sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	&sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 	&sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) static const struct attribute_group lm85_group_minctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	.attrs = lm85_attributes_minctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) static struct attribute *lm85_attributes_temp_off[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	&sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	&sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	&sensor_dev_attr_temp3_auto_temp_off.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) static const struct attribute_group lm85_group_temp_off = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	.attrs = lm85_attributes_temp_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) static struct attribute *lm85_attributes_in4[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 	&sensor_dev_attr_in4_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	&sensor_dev_attr_in4_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 	&sensor_dev_attr_in4_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	&sensor_dev_attr_in4_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) static const struct attribute_group lm85_group_in4 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 	.attrs = lm85_attributes_in4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) static struct attribute *lm85_attributes_in567[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	&sensor_dev_attr_in5_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	&sensor_dev_attr_in6_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 	&sensor_dev_attr_in7_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 	&sensor_dev_attr_in5_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	&sensor_dev_attr_in6_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 	&sensor_dev_attr_in7_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	&sensor_dev_attr_in5_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 	&sensor_dev_attr_in6_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	&sensor_dev_attr_in7_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	&sensor_dev_attr_in5_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 	&sensor_dev_attr_in6_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	&sensor_dev_attr_in7_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) static const struct attribute_group lm85_group_in567 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 	.attrs = lm85_attributes_in567,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) static void lm85_init_client(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 	int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	/* Start monitoring if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 	value = lm85_read_value(client, LM85_REG_CONFIG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	if (!(value & 0x01)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 		dev_info(&client->dev, "Starting monitoring\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 		lm85_write_value(client, LM85_REG_CONFIG, value | 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	/* Warn about unusual configuration bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	if (value & 0x02)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 		dev_warn(&client->dev, "Device configuration is locked\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 	if (!(value & 0x04))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 		dev_warn(&client->dev, "Device is not ready\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) static int lm85_is_fake(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	 * Differenciate between real LM96000 and Winbond WPCD377I. The latter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 	 * emulate the former except that it has no hardware monitoring function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	 * so the readings are always 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 	u8 in_temp, fan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 	for (i = 0; i < 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 		in_temp = i2c_smbus_read_byte_data(client, 0x20 + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 		fan = i2c_smbus_read_byte_data(client, 0x28 + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 		if (in_temp != 0x00 || fan != 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) /* Return 0 if detection is successful, -ENODEV otherwise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	struct i2c_adapter *adapter = client->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	int address = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	const char *type_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	int company, verstep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 		/* We need to be able to do byte I/O */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 	/* Determine the chip type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	company = lm85_read_value(client, LM85_REG_COMPANY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	verstep = lm85_read_value(client, LM85_REG_VERSTEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	dev_dbg(&adapter->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 		"Detecting device at 0x%02x with COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 		address, company, verstep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	if (company == LM85_COMPANY_NATIONAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 		switch (verstep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 		case LM85_VERSTEP_LM85C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 			type_name = "lm85c";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 		case LM85_VERSTEP_LM85B:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 			type_name = "lm85b";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 		case LM85_VERSTEP_LM96000_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 		case LM85_VERSTEP_LM96000_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 			/* Check for Winbond WPCD377I */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 			if (lm85_is_fake(client)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 				dev_dbg(&adapter->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 					"Found Winbond WPCD377I, ignoring\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 				return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 			type_name = "lm96000";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	} else if (company == LM85_COMPANY_ANALOG_DEV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 		switch (verstep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 		case LM85_VERSTEP_ADM1027:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 			type_name = "adm1027";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 		case LM85_VERSTEP_ADT7463:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 		case LM85_VERSTEP_ADT7463C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 			type_name = "adt7463";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 		case LM85_VERSTEP_ADT7468_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 		case LM85_VERSTEP_ADT7468_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 			type_name = "adt7468";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	} else if (company == LM85_COMPANY_SMSC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 		switch (verstep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 		case LM85_VERSTEP_EMC6D100_A0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 		case LM85_VERSTEP_EMC6D100_A1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 			/* Note: we can't tell a '100 from a '101 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 			type_name = "emc6d100";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 		case LM85_VERSTEP_EMC6D102:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 			type_name = "emc6d102";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 		case LM85_VERSTEP_EMC6D103_A0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 		case LM85_VERSTEP_EMC6D103_A1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 			type_name = "emc6d103";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 		case LM85_VERSTEP_EMC6D103S:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 			type_name = "emc6d103s";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 	if (!type_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	strlcpy(info->type, type_name, I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) static const struct i2c_device_id lm85_id[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) static int lm85_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 	struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 	struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 	struct lm85_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 	int idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 	data = devm_kzalloc(dev, sizeof(struct lm85_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	data->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 	if (client->dev.of_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 		data->type = (enum chips)of_device_get_match_data(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 		data->type = i2c_match_id(lm85_id, client)->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	mutex_init(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 	/* Fill in the chip specific driver values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 	switch (data->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	case adm1027:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 	case adt7463:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 	case adt7468:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 	case emc6d100:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 	case emc6d102:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 	case emc6d103:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 	case emc6d103s:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 		data->freq_map = adm1027_freq_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 		data->freq_map_size = ARRAY_SIZE(adm1027_freq_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	case lm96000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 		data->freq_map = lm96000_freq_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 		data->freq_map_size = ARRAY_SIZE(lm96000_freq_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 		data->freq_map = lm85_freq_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 		data->freq_map_size = ARRAY_SIZE(lm85_freq_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	/* Set the VRM version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 	data->vrm = vid_which_vrm();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 	/* Initialize the LM85 chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 	lm85_init_client(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 	/* sysfs hooks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 	data->groups[idx++] = &lm85_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 	/* minctl and temp_off exist on all chips except emc6d103s */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 	if (data->type != emc6d103s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 		data->groups[idx++] = &lm85_group_minctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 		data->groups[idx++] = &lm85_group_temp_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 	 * The ADT7463/68 have an optional VRM 10 mode where pin 21 is used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 	 * as a sixth digital VID input rather than an analog input.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 	if (data->type == adt7463 || data->type == adt7468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 		u8 vid = lm85_read_value(client, LM85_REG_VID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 		if (vid & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 			data->has_vid5 = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 	if (!data->has_vid5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 		data->groups[idx++] = &lm85_group_in4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 	/* The EMC6D100 has 3 additional voltage inputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 	if (data->type == emc6d100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 		data->groups[idx++] = &lm85_group_in567;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 	hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 							   data, data->groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 	return PTR_ERR_OR_ZERO(hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) static const struct i2c_device_id lm85_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	{ "adm1027", adm1027 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 	{ "adt7463", adt7463 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	{ "adt7468", adt7468 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 	{ "lm85", lm85 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 	{ "lm85b", lm85 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 	{ "lm85c", lm85 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 	{ "lm96000", lm96000 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	{ "emc6d100", emc6d100 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 	{ "emc6d101", emc6d100 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	{ "emc6d102", emc6d102 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	{ "emc6d103", emc6d103 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	{ "emc6d103s", emc6d103s },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) MODULE_DEVICE_TABLE(i2c, lm85_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) static const struct of_device_id __maybe_unused lm85_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 		.compatible = "adi,adm1027",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 		.data = (void *)adm1027
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 		.compatible = "adi,adt7463",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 		.data = (void *)adt7463
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 		.compatible = "adi,adt7468",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 		.data = (void *)adt7468
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 		.compatible = "national,lm85",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 		.data = (void *)lm85
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 		.compatible = "national,lm85b",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 		.data = (void *)lm85
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 		.compatible = "national,lm85c",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 		.data = (void *)lm85
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 		.compatible = "ti,lm96000",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 		.data = (void *)lm96000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 		.compatible = "smsc,emc6d100",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 		.data = (void *)emc6d100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 		.compatible = "smsc,emc6d101",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 		.data = (void *)emc6d100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 		.compatible = "smsc,emc6d102",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 		.data = (void *)emc6d102
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 		.compatible = "smsc,emc6d103",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 		.data = (void *)emc6d103
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 		.compatible = "smsc,emc6d103s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 		.data = (void *)emc6d103s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) MODULE_DEVICE_TABLE(of, lm85_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) static struct i2c_driver lm85_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	.class		= I2C_CLASS_HWMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 		.name   = "lm85",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 		.of_match_table = of_match_ptr(lm85_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	.probe_new	= lm85_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	.id_table	= lm85_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 	.detect		= lm85_detect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 	.address_list	= normal_i2c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) module_i2c_driver(lm85_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 	"Margit Schubert-While <margitsw@t-online.de>, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 	"Justin Thiessen <jthiessen@penguincomputing.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) MODULE_DESCRIPTION("LM85-B, LM85-C driver");