18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * w83792d.c - Part of lm_sensors, Linux kernel modules for hardware
48c2ecf20Sopenharmony_ci *	       monitoring
58c2ecf20Sopenharmony_ci * Copyright (C) 2004, 2005 Winbond Electronics Corp.
68c2ecf20Sopenharmony_ci *			    Shane Huang,
78c2ecf20Sopenharmony_ci *			    Rudolf Marek <r.marek@assembler.cz>
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Note:
108c2ecf20Sopenharmony_ci * 1. This driver is only for 2.6 kernel, 2.4 kernel need a different driver.
118c2ecf20Sopenharmony_ci * 2. This driver is only for Winbond W83792D C version device, there
128c2ecf20Sopenharmony_ci *     are also some motherboards with B version W83792D device. The
138c2ecf20Sopenharmony_ci *     calculation method to in6-in7(measured value, limits) is a little
148c2ecf20Sopenharmony_ci *     different between C and B version. C or B version can be identified
158c2ecf20Sopenharmony_ci *     by CR[0x49h].
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/*
198c2ecf20Sopenharmony_ci * Supports following chips:
208c2ecf20Sopenharmony_ci *
218c2ecf20Sopenharmony_ci * Chip		#vin	#fanin	#pwm	#temp	wchipid	vendid	i2c	ISA
228c2ecf20Sopenharmony_ci * w83792d	9	7	7	3	0x7a	0x5ca3	yes	no
238c2ecf20Sopenharmony_ci */
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#include <linux/module.h>
268c2ecf20Sopenharmony_ci#include <linux/init.h>
278c2ecf20Sopenharmony_ci#include <linux/slab.h>
288c2ecf20Sopenharmony_ci#include <linux/i2c.h>
298c2ecf20Sopenharmony_ci#include <linux/hwmon.h>
308c2ecf20Sopenharmony_ci#include <linux/hwmon-sysfs.h>
318c2ecf20Sopenharmony_ci#include <linux/err.h>
328c2ecf20Sopenharmony_ci#include <linux/mutex.h>
338c2ecf20Sopenharmony_ci#include <linux/sysfs.h>
348c2ecf20Sopenharmony_ci#include <linux/jiffies.h>
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/* Addresses to scan */
378c2ecf20Sopenharmony_cistatic const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
388c2ecf20Sopenharmony_ci						I2C_CLIENT_END };
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/* Insmod parameters */
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistatic unsigned short force_subclients[4];
438c2ecf20Sopenharmony_cimodule_param_array(force_subclients, short, NULL, 0);
448c2ecf20Sopenharmony_ciMODULE_PARM_DESC(force_subclients,
458c2ecf20Sopenharmony_ci		 "List of subclient addresses: {bus, clientaddr, subclientaddr1, subclientaddr2}");
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistatic bool init;
488c2ecf20Sopenharmony_cimodule_param(init, bool, 0);
498c2ecf20Sopenharmony_ciMODULE_PARM_DESC(init, "Set to one to force chip initialization");
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/* The W83792D registers */
528c2ecf20Sopenharmony_cistatic const u8 W83792D_REG_IN[9] = {
538c2ecf20Sopenharmony_ci	0x20,	/* Vcore A in DataSheet */
548c2ecf20Sopenharmony_ci	0x21,	/* Vcore B in DataSheet */
558c2ecf20Sopenharmony_ci	0x22,	/* VIN0 in DataSheet */
568c2ecf20Sopenharmony_ci	0x23,	/* VIN1 in DataSheet */
578c2ecf20Sopenharmony_ci	0x24,	/* VIN2 in DataSheet */
588c2ecf20Sopenharmony_ci	0x25,	/* VIN3 in DataSheet */
598c2ecf20Sopenharmony_ci	0x26,	/* 5VCC in DataSheet */
608c2ecf20Sopenharmony_ci	0xB0,	/* 5VSB in DataSheet */
618c2ecf20Sopenharmony_ci	0xB1	/* VBAT in DataSheet */
628c2ecf20Sopenharmony_ci};
638c2ecf20Sopenharmony_ci#define W83792D_REG_LOW_BITS1 0x3E  /* Low Bits I in DataSheet */
648c2ecf20Sopenharmony_ci#define W83792D_REG_LOW_BITS2 0x3F  /* Low Bits II in DataSheet */
658c2ecf20Sopenharmony_cistatic const u8 W83792D_REG_IN_MAX[9] = {
668c2ecf20Sopenharmony_ci	0x2B,	/* Vcore A High Limit in DataSheet */
678c2ecf20Sopenharmony_ci	0x2D,	/* Vcore B High Limit in DataSheet */
688c2ecf20Sopenharmony_ci	0x2F,	/* VIN0 High Limit in DataSheet */
698c2ecf20Sopenharmony_ci	0x31,	/* VIN1 High Limit in DataSheet */
708c2ecf20Sopenharmony_ci	0x33,	/* VIN2 High Limit in DataSheet */
718c2ecf20Sopenharmony_ci	0x35,	/* VIN3 High Limit in DataSheet */
728c2ecf20Sopenharmony_ci	0x37,	/* 5VCC High Limit in DataSheet */
738c2ecf20Sopenharmony_ci	0xB4,	/* 5VSB High Limit in DataSheet */
748c2ecf20Sopenharmony_ci	0xB6	/* VBAT High Limit in DataSheet */
758c2ecf20Sopenharmony_ci};
768c2ecf20Sopenharmony_cistatic const u8 W83792D_REG_IN_MIN[9] = {
778c2ecf20Sopenharmony_ci	0x2C,	/* Vcore A Low Limit in DataSheet */
788c2ecf20Sopenharmony_ci	0x2E,	/* Vcore B Low Limit in DataSheet */
798c2ecf20Sopenharmony_ci	0x30,	/* VIN0 Low Limit in DataSheet */
808c2ecf20Sopenharmony_ci	0x32,	/* VIN1 Low Limit in DataSheet */
818c2ecf20Sopenharmony_ci	0x34,	/* VIN2 Low Limit in DataSheet */
828c2ecf20Sopenharmony_ci	0x36,	/* VIN3 Low Limit in DataSheet */
838c2ecf20Sopenharmony_ci	0x38,	/* 5VCC Low Limit in DataSheet */
848c2ecf20Sopenharmony_ci	0xB5,	/* 5VSB Low Limit in DataSheet */
858c2ecf20Sopenharmony_ci	0xB7	/* VBAT Low Limit in DataSheet */
868c2ecf20Sopenharmony_ci};
878c2ecf20Sopenharmony_cistatic const u8 W83792D_REG_FAN[7] = {
888c2ecf20Sopenharmony_ci	0x28,	/* FAN 1 Count in DataSheet */
898c2ecf20Sopenharmony_ci	0x29,	/* FAN 2 Count in DataSheet */
908c2ecf20Sopenharmony_ci	0x2A,	/* FAN 3 Count in DataSheet */
918c2ecf20Sopenharmony_ci	0xB8,	/* FAN 4 Count in DataSheet */
928c2ecf20Sopenharmony_ci	0xB9,	/* FAN 5 Count in DataSheet */
938c2ecf20Sopenharmony_ci	0xBA,	/* FAN 6 Count in DataSheet */
948c2ecf20Sopenharmony_ci	0xBE	/* FAN 7 Count in DataSheet */
958c2ecf20Sopenharmony_ci};
968c2ecf20Sopenharmony_cistatic const u8 W83792D_REG_FAN_MIN[7] = {
978c2ecf20Sopenharmony_ci	0x3B,	/* FAN 1 Count Low Limit in DataSheet */
988c2ecf20Sopenharmony_ci	0x3C,	/* FAN 2 Count Low Limit in DataSheet */
998c2ecf20Sopenharmony_ci	0x3D,	/* FAN 3 Count Low Limit in DataSheet */
1008c2ecf20Sopenharmony_ci	0xBB,	/* FAN 4 Count Low Limit in DataSheet */
1018c2ecf20Sopenharmony_ci	0xBC,	/* FAN 5 Count Low Limit in DataSheet */
1028c2ecf20Sopenharmony_ci	0xBD,	/* FAN 6 Count Low Limit in DataSheet */
1038c2ecf20Sopenharmony_ci	0xBF	/* FAN 7 Count Low Limit in DataSheet */
1048c2ecf20Sopenharmony_ci};
1058c2ecf20Sopenharmony_ci#define W83792D_REG_FAN_CFG 0x84	/* FAN Configuration in DataSheet */
1068c2ecf20Sopenharmony_cistatic const u8 W83792D_REG_FAN_DIV[4] = {
1078c2ecf20Sopenharmony_ci	0x47,	/* contains FAN2 and FAN1 Divisor */
1088c2ecf20Sopenharmony_ci	0x5B,	/* contains FAN4 and FAN3 Divisor */
1098c2ecf20Sopenharmony_ci	0x5C,	/* contains FAN6 and FAN5 Divisor */
1108c2ecf20Sopenharmony_ci	0x9E	/* contains FAN7 Divisor. */
1118c2ecf20Sopenharmony_ci};
1128c2ecf20Sopenharmony_cistatic const u8 W83792D_REG_PWM[7] = {
1138c2ecf20Sopenharmony_ci	0x81,	/* FAN 1 Duty Cycle, be used to control */
1148c2ecf20Sopenharmony_ci	0x83,	/* FAN 2 Duty Cycle, be used to control */
1158c2ecf20Sopenharmony_ci	0x94,	/* FAN 3 Duty Cycle, be used to control */
1168c2ecf20Sopenharmony_ci	0xA3,	/* FAN 4 Duty Cycle, be used to control */
1178c2ecf20Sopenharmony_ci	0xA4,	/* FAN 5 Duty Cycle, be used to control */
1188c2ecf20Sopenharmony_ci	0xA5,	/* FAN 6 Duty Cycle, be used to control */
1198c2ecf20Sopenharmony_ci	0xA6	/* FAN 7 Duty Cycle, be used to control */
1208c2ecf20Sopenharmony_ci};
1218c2ecf20Sopenharmony_ci#define W83792D_REG_BANK		0x4E
1228c2ecf20Sopenharmony_ci#define W83792D_REG_TEMP2_CONFIG	0xC2
1238c2ecf20Sopenharmony_ci#define W83792D_REG_TEMP3_CONFIG	0xCA
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_cistatic const u8 W83792D_REG_TEMP1[3] = {
1268c2ecf20Sopenharmony_ci	0x27,	/* TEMP 1 in DataSheet */
1278c2ecf20Sopenharmony_ci	0x39,	/* TEMP 1 Over in DataSheet */
1288c2ecf20Sopenharmony_ci	0x3A,	/* TEMP 1 Hyst in DataSheet */
1298c2ecf20Sopenharmony_ci};
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cistatic const u8 W83792D_REG_TEMP_ADD[2][6] = {
1328c2ecf20Sopenharmony_ci	{ 0xC0,		/* TEMP 2 in DataSheet */
1338c2ecf20Sopenharmony_ci	  0xC1,		/* TEMP 2(0.5 deg) in DataSheet */
1348c2ecf20Sopenharmony_ci	  0xC5,		/* TEMP 2 Over High part in DataSheet */
1358c2ecf20Sopenharmony_ci	  0xC6,		/* TEMP 2 Over Low part in DataSheet */
1368c2ecf20Sopenharmony_ci	  0xC3,		/* TEMP 2 Thyst High part in DataSheet */
1378c2ecf20Sopenharmony_ci	  0xC4 },	/* TEMP 2 Thyst Low part in DataSheet */
1388c2ecf20Sopenharmony_ci	{ 0xC8,		/* TEMP 3 in DataSheet */
1398c2ecf20Sopenharmony_ci	  0xC9,		/* TEMP 3(0.5 deg) in DataSheet */
1408c2ecf20Sopenharmony_ci	  0xCD,		/* TEMP 3 Over High part in DataSheet */
1418c2ecf20Sopenharmony_ci	  0xCE,		/* TEMP 3 Over Low part in DataSheet */
1428c2ecf20Sopenharmony_ci	  0xCB,		/* TEMP 3 Thyst High part in DataSheet */
1438c2ecf20Sopenharmony_ci	  0xCC }	/* TEMP 3 Thyst Low part in DataSheet */
1448c2ecf20Sopenharmony_ci};
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_cistatic const u8 W83792D_REG_THERMAL[3] = {
1478c2ecf20Sopenharmony_ci	0x85,	/* SmartFanI: Fan1 target value */
1488c2ecf20Sopenharmony_ci	0x86,	/* SmartFanI: Fan2 target value */
1498c2ecf20Sopenharmony_ci	0x96	/* SmartFanI: Fan3 target value */
1508c2ecf20Sopenharmony_ci};
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_cistatic const u8 W83792D_REG_TOLERANCE[3] = {
1538c2ecf20Sopenharmony_ci	0x87,	/* (bit3-0)SmartFan Fan1 tolerance */
1548c2ecf20Sopenharmony_ci	0x87,	/* (bit7-4)SmartFan Fan2 tolerance */
1558c2ecf20Sopenharmony_ci	0x97	/* (bit3-0)SmartFan Fan3 tolerance */
1568c2ecf20Sopenharmony_ci};
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_cistatic const u8 W83792D_REG_POINTS[3][4] = {
1598c2ecf20Sopenharmony_ci	{ 0x85,		/* SmartFanII: Fan1 temp point 1 */
1608c2ecf20Sopenharmony_ci	  0xE3,		/* SmartFanII: Fan1 temp point 2 */
1618c2ecf20Sopenharmony_ci	  0xE4,		/* SmartFanII: Fan1 temp point 3 */
1628c2ecf20Sopenharmony_ci	  0xE5 },	/* SmartFanII: Fan1 temp point 4 */
1638c2ecf20Sopenharmony_ci	{ 0x86,		/* SmartFanII: Fan2 temp point 1 */
1648c2ecf20Sopenharmony_ci	  0xE6,		/* SmartFanII: Fan2 temp point 2 */
1658c2ecf20Sopenharmony_ci	  0xE7,		/* SmartFanII: Fan2 temp point 3 */
1668c2ecf20Sopenharmony_ci	  0xE8 },	/* SmartFanII: Fan2 temp point 4 */
1678c2ecf20Sopenharmony_ci	{ 0x96,		/* SmartFanII: Fan3 temp point 1 */
1688c2ecf20Sopenharmony_ci	  0xE9,		/* SmartFanII: Fan3 temp point 2 */
1698c2ecf20Sopenharmony_ci	  0xEA,		/* SmartFanII: Fan3 temp point 3 */
1708c2ecf20Sopenharmony_ci	  0xEB }	/* SmartFanII: Fan3 temp point 4 */
1718c2ecf20Sopenharmony_ci};
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_cistatic const u8 W83792D_REG_LEVELS[3][4] = {
1748c2ecf20Sopenharmony_ci	{ 0x88,		/* (bit3-0) SmartFanII: Fan1 Non-Stop */
1758c2ecf20Sopenharmony_ci	  0x88,		/* (bit7-4) SmartFanII: Fan1 Level 1 */
1768c2ecf20Sopenharmony_ci	  0xE0,		/* (bit7-4) SmartFanII: Fan1 Level 2 */
1778c2ecf20Sopenharmony_ci	  0xE0 },	/* (bit3-0) SmartFanII: Fan1 Level 3 */
1788c2ecf20Sopenharmony_ci	{ 0x89,		/* (bit3-0) SmartFanII: Fan2 Non-Stop */
1798c2ecf20Sopenharmony_ci	  0x89,		/* (bit7-4) SmartFanII: Fan2 Level 1 */
1808c2ecf20Sopenharmony_ci	  0xE1,		/* (bit7-4) SmartFanII: Fan2 Level 2 */
1818c2ecf20Sopenharmony_ci	  0xE1 },	/* (bit3-0) SmartFanII: Fan2 Level 3 */
1828c2ecf20Sopenharmony_ci	{ 0x98,		/* (bit3-0) SmartFanII: Fan3 Non-Stop */
1838c2ecf20Sopenharmony_ci	  0x98,		/* (bit7-4) SmartFanII: Fan3 Level 1 */
1848c2ecf20Sopenharmony_ci	  0xE2,		/* (bit7-4) SmartFanII: Fan3 Level 2 */
1858c2ecf20Sopenharmony_ci	  0xE2 }	/* (bit3-0) SmartFanII: Fan3 Level 3 */
1868c2ecf20Sopenharmony_ci};
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci#define W83792D_REG_GPIO_EN		0x1A
1898c2ecf20Sopenharmony_ci#define W83792D_REG_CONFIG		0x40
1908c2ecf20Sopenharmony_ci#define W83792D_REG_VID_FANDIV		0x47
1918c2ecf20Sopenharmony_ci#define W83792D_REG_CHIPID		0x49
1928c2ecf20Sopenharmony_ci#define W83792D_REG_WCHIPID		0x58
1938c2ecf20Sopenharmony_ci#define W83792D_REG_CHIPMAN		0x4F
1948c2ecf20Sopenharmony_ci#define W83792D_REG_PIN			0x4B
1958c2ecf20Sopenharmony_ci#define W83792D_REG_I2C_SUBADDR		0x4A
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci#define W83792D_REG_ALARM1 0xA9		/* realtime status register1 */
1988c2ecf20Sopenharmony_ci#define W83792D_REG_ALARM2 0xAA		/* realtime status register2 */
1998c2ecf20Sopenharmony_ci#define W83792D_REG_ALARM3 0xAB		/* realtime status register3 */
2008c2ecf20Sopenharmony_ci#define W83792D_REG_CHASSIS 0x42	/* Bit 5: Case Open status bit */
2018c2ecf20Sopenharmony_ci#define W83792D_REG_CHASSIS_CLR 0x44	/* Bit 7: Case Open CLR_CHS/Reset bit */
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci/* control in0/in1 's limit modifiability */
2048c2ecf20Sopenharmony_ci#define W83792D_REG_VID_IN_B		0x17
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci#define W83792D_REG_VBAT		0x5D
2078c2ecf20Sopenharmony_ci#define W83792D_REG_I2C_ADDR		0x48
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci/*
2108c2ecf20Sopenharmony_ci * Conversions. Rounding and limit checking is only done on the TO_REG
2118c2ecf20Sopenharmony_ci * variants. Note that you should be a bit careful with which arguments
2128c2ecf20Sopenharmony_ci * these macros are called: arguments may be evaluated more than once.
2138c2ecf20Sopenharmony_ci * Fixing this is just not worth it.
2148c2ecf20Sopenharmony_ci */
2158c2ecf20Sopenharmony_ci#define IN_FROM_REG(nr, val) (((nr) <= 1) ? ((val) * 2) : \
2168c2ecf20Sopenharmony_ci		((((nr) == 6) || ((nr) == 7)) ? ((val) * 6) : ((val) * 4)))
2178c2ecf20Sopenharmony_ci#define IN_TO_REG(nr, val) (((nr) <= 1) ? ((val) / 2) : \
2188c2ecf20Sopenharmony_ci		((((nr) == 6) || ((nr) == 7)) ? ((val) / 6) : ((val) / 4)))
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_cistatic inline u8
2218c2ecf20Sopenharmony_ciFAN_TO_REG(long rpm, int div)
2228c2ecf20Sopenharmony_ci{
2238c2ecf20Sopenharmony_ci	if (rpm == 0)
2248c2ecf20Sopenharmony_ci		return 255;
2258c2ecf20Sopenharmony_ci	rpm = clamp_val(rpm, 1, 1000000);
2268c2ecf20Sopenharmony_ci	return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
2278c2ecf20Sopenharmony_ci}
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci#define FAN_FROM_REG(val, div)	((val) == 0   ? -1 : \
2308c2ecf20Sopenharmony_ci				((val) == 255 ? 0 : \
2318c2ecf20Sopenharmony_ci						1350000 / ((val) * (div))))
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci/* for temp1 */
2348c2ecf20Sopenharmony_ci#define TEMP1_TO_REG(val)	(clamp_val(((val) < 0 ? (val) + 0x100 * 1000 \
2358c2ecf20Sopenharmony_ci						      : (val)) / 1000, 0, 0xff))
2368c2ecf20Sopenharmony_ci#define TEMP1_FROM_REG(val)	(((val) & 0x80 ? (val)-0x100 : (val)) * 1000)
2378c2ecf20Sopenharmony_ci/* for temp2 and temp3, because they need additional resolution */
2388c2ecf20Sopenharmony_ci#define TEMP_ADD_FROM_REG(val1, val2) \
2398c2ecf20Sopenharmony_ci	((((val1) & 0x80 ? (val1)-0x100 \
2408c2ecf20Sopenharmony_ci		: (val1)) * 1000) + ((val2 & 0x80) ? 500 : 0))
2418c2ecf20Sopenharmony_ci#define TEMP_ADD_TO_REG_HIGH(val) \
2428c2ecf20Sopenharmony_ci	(clamp_val(((val) < 0 ? (val) + 0x100 * 1000 : (val)) / 1000, 0, 0xff))
2438c2ecf20Sopenharmony_ci#define TEMP_ADD_TO_REG_LOW(val)	((val%1000) ? 0x80 : 0x00)
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci#define DIV_FROM_REG(val)		(1 << (val))
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_cistatic inline u8
2488c2ecf20Sopenharmony_ciDIV_TO_REG(long val)
2498c2ecf20Sopenharmony_ci{
2508c2ecf20Sopenharmony_ci	int i;
2518c2ecf20Sopenharmony_ci	val = clamp_val(val, 1, 128) >> 1;
2528c2ecf20Sopenharmony_ci	for (i = 0; i < 7; i++) {
2538c2ecf20Sopenharmony_ci		if (val == 0)
2548c2ecf20Sopenharmony_ci			break;
2558c2ecf20Sopenharmony_ci		val >>= 1;
2568c2ecf20Sopenharmony_ci	}
2578c2ecf20Sopenharmony_ci	return (u8)i;
2588c2ecf20Sopenharmony_ci}
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_cistruct w83792d_data {
2618c2ecf20Sopenharmony_ci	struct device *hwmon_dev;
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci	struct mutex update_lock;
2648c2ecf20Sopenharmony_ci	char valid;		/* !=0 if following fields are valid */
2658c2ecf20Sopenharmony_ci	unsigned long last_updated;	/* In jiffies */
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci	u8 in[9];		/* Register value */
2688c2ecf20Sopenharmony_ci	u8 in_max[9];		/* Register value */
2698c2ecf20Sopenharmony_ci	u8 in_min[9];		/* Register value */
2708c2ecf20Sopenharmony_ci	u16 low_bits;		/* Additional resolution to voltage in6-0 */
2718c2ecf20Sopenharmony_ci	u8 fan[7];		/* Register value */
2728c2ecf20Sopenharmony_ci	u8 fan_min[7];		/* Register value */
2738c2ecf20Sopenharmony_ci	u8 temp1[3];		/* current, over, thyst */
2748c2ecf20Sopenharmony_ci	u8 temp_add[2][6];	/* Register value */
2758c2ecf20Sopenharmony_ci	u8 fan_div[7];		/* Register encoding, shifted right */
2768c2ecf20Sopenharmony_ci	u8 pwm[7];		/* The 7 PWM outputs */
2778c2ecf20Sopenharmony_ci	u8 pwmenable[3];
2788c2ecf20Sopenharmony_ci	u32 alarms;		/* realtime status register encoding,combined */
2798c2ecf20Sopenharmony_ci	u8 chassis;		/* Chassis status */
2808c2ecf20Sopenharmony_ci	u8 thermal_cruise[3];	/* Smart FanI: Fan1,2,3 target value */
2818c2ecf20Sopenharmony_ci	u8 tolerance[3];	/* Fan1,2,3 tolerance(Smart Fan I/II) */
2828c2ecf20Sopenharmony_ci	u8 sf2_points[3][4];	/* Smart FanII: Fan1,2,3 temperature points */
2838c2ecf20Sopenharmony_ci	u8 sf2_levels[3][4];	/* Smart FanII: Fan1,2,3 duty cycle levels */
2848c2ecf20Sopenharmony_ci};
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_cistatic int w83792d_probe(struct i2c_client *client);
2878c2ecf20Sopenharmony_cistatic int w83792d_detect(struct i2c_client *client,
2888c2ecf20Sopenharmony_ci			  struct i2c_board_info *info);
2898c2ecf20Sopenharmony_cistatic int w83792d_remove(struct i2c_client *client);
2908c2ecf20Sopenharmony_cistatic struct w83792d_data *w83792d_update_device(struct device *dev);
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci#ifdef DEBUG
2938c2ecf20Sopenharmony_cistatic void w83792d_print_debug(struct w83792d_data *data, struct device *dev);
2948c2ecf20Sopenharmony_ci#endif
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_cistatic void w83792d_init_client(struct i2c_client *client);
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_cistatic const struct i2c_device_id w83792d_id[] = {
2998c2ecf20Sopenharmony_ci	{ "w83792d", 0 },
3008c2ecf20Sopenharmony_ci	{ }
3018c2ecf20Sopenharmony_ci};
3028c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, w83792d_id);
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_cistatic struct i2c_driver w83792d_driver = {
3058c2ecf20Sopenharmony_ci	.class		= I2C_CLASS_HWMON,
3068c2ecf20Sopenharmony_ci	.driver = {
3078c2ecf20Sopenharmony_ci		.name = "w83792d",
3088c2ecf20Sopenharmony_ci	},
3098c2ecf20Sopenharmony_ci	.probe_new	= w83792d_probe,
3108c2ecf20Sopenharmony_ci	.remove		= w83792d_remove,
3118c2ecf20Sopenharmony_ci	.id_table	= w83792d_id,
3128c2ecf20Sopenharmony_ci	.detect		= w83792d_detect,
3138c2ecf20Sopenharmony_ci	.address_list	= normal_i2c,
3148c2ecf20Sopenharmony_ci};
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_cistatic inline long in_count_from_reg(int nr, struct w83792d_data *data)
3178c2ecf20Sopenharmony_ci{
3188c2ecf20Sopenharmony_ci	/* in7 and in8 do not have low bits, but the formula still works */
3198c2ecf20Sopenharmony_ci	return (data->in[nr] << 2) | ((data->low_bits >> (2 * nr)) & 0x03);
3208c2ecf20Sopenharmony_ci}
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci/*
3238c2ecf20Sopenharmony_ci * The SMBus locks itself. The Winbond W83792D chip has a bank register,
3248c2ecf20Sopenharmony_ci * but the driver only accesses registers in bank 0, so we don't have
3258c2ecf20Sopenharmony_ci * to switch banks and lock access between switches.
3268c2ecf20Sopenharmony_ci */
3278c2ecf20Sopenharmony_cistatic inline int w83792d_read_value(struct i2c_client *client, u8 reg)
3288c2ecf20Sopenharmony_ci{
3298c2ecf20Sopenharmony_ci	return i2c_smbus_read_byte_data(client, reg);
3308c2ecf20Sopenharmony_ci}
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_cistatic inline int
3338c2ecf20Sopenharmony_ciw83792d_write_value(struct i2c_client *client, u8 reg, u8 value)
3348c2ecf20Sopenharmony_ci{
3358c2ecf20Sopenharmony_ci	return i2c_smbus_write_byte_data(client, reg, value);
3368c2ecf20Sopenharmony_ci}
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci/* following are the sysfs callback functions */
3398c2ecf20Sopenharmony_cistatic ssize_t show_in(struct device *dev, struct device_attribute *attr,
3408c2ecf20Sopenharmony_ci			char *buf)
3418c2ecf20Sopenharmony_ci{
3428c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
3438c2ecf20Sopenharmony_ci	int nr = sensor_attr->index;
3448c2ecf20Sopenharmony_ci	struct w83792d_data *data = w83792d_update_device(dev);
3458c2ecf20Sopenharmony_ci	return sprintf(buf, "%ld\n",
3468c2ecf20Sopenharmony_ci		       IN_FROM_REG(nr, in_count_from_reg(nr, data)));
3478c2ecf20Sopenharmony_ci}
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci#define show_in_reg(reg) \
3508c2ecf20Sopenharmony_cistatic ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
3518c2ecf20Sopenharmony_ci			char *buf) \
3528c2ecf20Sopenharmony_ci{ \
3538c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr \
3548c2ecf20Sopenharmony_ci		= to_sensor_dev_attr(attr); \
3558c2ecf20Sopenharmony_ci	int nr = sensor_attr->index; \
3568c2ecf20Sopenharmony_ci	struct w83792d_data *data = w83792d_update_device(dev); \
3578c2ecf20Sopenharmony_ci	return sprintf(buf, "%ld\n", \
3588c2ecf20Sopenharmony_ci		       (long)(IN_FROM_REG(nr, data->reg[nr]) * 4)); \
3598c2ecf20Sopenharmony_ci}
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_cishow_in_reg(in_min);
3628c2ecf20Sopenharmony_cishow_in_reg(in_max);
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci#define store_in_reg(REG, reg) \
3658c2ecf20Sopenharmony_cistatic ssize_t store_in_##reg(struct device *dev, \
3668c2ecf20Sopenharmony_ci				struct device_attribute *attr, \
3678c2ecf20Sopenharmony_ci				const char *buf, size_t count) \
3688c2ecf20Sopenharmony_ci{ \
3698c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr \
3708c2ecf20Sopenharmony_ci			= to_sensor_dev_attr(attr); \
3718c2ecf20Sopenharmony_ci	int nr = sensor_attr->index; \
3728c2ecf20Sopenharmony_ci	struct i2c_client *client = to_i2c_client(dev); \
3738c2ecf20Sopenharmony_ci	struct w83792d_data *data = i2c_get_clientdata(client); \
3748c2ecf20Sopenharmony_ci	unsigned long val; \
3758c2ecf20Sopenharmony_ci	int err = kstrtoul(buf, 10, &val); \
3768c2ecf20Sopenharmony_ci	if (err) \
3778c2ecf20Sopenharmony_ci		return err; \
3788c2ecf20Sopenharmony_ci	mutex_lock(&data->update_lock); \
3798c2ecf20Sopenharmony_ci	data->in_##reg[nr] = clamp_val(IN_TO_REG(nr, val) / 4, 0, 255); \
3808c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_IN_##REG[nr], \
3818c2ecf20Sopenharmony_ci			    data->in_##reg[nr]); \
3828c2ecf20Sopenharmony_ci	mutex_unlock(&data->update_lock); \
3838c2ecf20Sopenharmony_ci	 \
3848c2ecf20Sopenharmony_ci	return count; \
3858c2ecf20Sopenharmony_ci}
3868c2ecf20Sopenharmony_cistore_in_reg(MIN, min);
3878c2ecf20Sopenharmony_cistore_in_reg(MAX, max);
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci#define show_fan_reg(reg) \
3908c2ecf20Sopenharmony_cistatic ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
3918c2ecf20Sopenharmony_ci			char *buf) \
3928c2ecf20Sopenharmony_ci{ \
3938c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr \
3948c2ecf20Sopenharmony_ci			= to_sensor_dev_attr(attr); \
3958c2ecf20Sopenharmony_ci	int nr = sensor_attr->index - 1; \
3968c2ecf20Sopenharmony_ci	struct w83792d_data *data = w83792d_update_device(dev); \
3978c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", \
3988c2ecf20Sopenharmony_ci		FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
3998c2ecf20Sopenharmony_ci}
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_cishow_fan_reg(fan);
4028c2ecf20Sopenharmony_cishow_fan_reg(fan_min);
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_cistatic ssize_t
4058c2ecf20Sopenharmony_cistore_fan_min(struct device *dev, struct device_attribute *attr,
4068c2ecf20Sopenharmony_ci		const char *buf, size_t count)
4078c2ecf20Sopenharmony_ci{
4088c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
4098c2ecf20Sopenharmony_ci	int nr = sensor_attr->index - 1;
4108c2ecf20Sopenharmony_ci	struct i2c_client *client = to_i2c_client(dev);
4118c2ecf20Sopenharmony_ci	struct w83792d_data *data = i2c_get_clientdata(client);
4128c2ecf20Sopenharmony_ci	unsigned long val;
4138c2ecf20Sopenharmony_ci	int err;
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci	err = kstrtoul(buf, 10, &val);
4168c2ecf20Sopenharmony_ci	if (err)
4178c2ecf20Sopenharmony_ci		return err;
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci	mutex_lock(&data->update_lock);
4208c2ecf20Sopenharmony_ci	data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
4218c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_FAN_MIN[nr],
4228c2ecf20Sopenharmony_ci				data->fan_min[nr]);
4238c2ecf20Sopenharmony_ci	mutex_unlock(&data->update_lock);
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ci	return count;
4268c2ecf20Sopenharmony_ci}
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_cistatic ssize_t
4298c2ecf20Sopenharmony_cishow_fan_div(struct device *dev, struct device_attribute *attr,
4308c2ecf20Sopenharmony_ci		char *buf)
4318c2ecf20Sopenharmony_ci{
4328c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
4338c2ecf20Sopenharmony_ci	int nr = sensor_attr->index;
4348c2ecf20Sopenharmony_ci	struct w83792d_data *data = w83792d_update_device(dev);
4358c2ecf20Sopenharmony_ci	return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr - 1]));
4368c2ecf20Sopenharmony_ci}
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci/*
4398c2ecf20Sopenharmony_ci * Note: we save and restore the fan minimum here, because its value is
4408c2ecf20Sopenharmony_ci * determined in part by the fan divisor.  This follows the principle of
4418c2ecf20Sopenharmony_ci * least surprise; the user doesn't expect the fan minimum to change just
4428c2ecf20Sopenharmony_ci * because the divisor changed.
4438c2ecf20Sopenharmony_ci */
4448c2ecf20Sopenharmony_cistatic ssize_t
4458c2ecf20Sopenharmony_cistore_fan_div(struct device *dev, struct device_attribute *attr,
4468c2ecf20Sopenharmony_ci		const char *buf, size_t count)
4478c2ecf20Sopenharmony_ci{
4488c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
4498c2ecf20Sopenharmony_ci	int nr = sensor_attr->index - 1;
4508c2ecf20Sopenharmony_ci	struct i2c_client *client = to_i2c_client(dev);
4518c2ecf20Sopenharmony_ci	struct w83792d_data *data = i2c_get_clientdata(client);
4528c2ecf20Sopenharmony_ci	unsigned long min;
4538c2ecf20Sopenharmony_ci	/*u8 reg;*/
4548c2ecf20Sopenharmony_ci	u8 fan_div_reg = 0;
4558c2ecf20Sopenharmony_ci	u8 tmp_fan_div;
4568c2ecf20Sopenharmony_ci	unsigned long val;
4578c2ecf20Sopenharmony_ci	int err;
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_ci	err = kstrtoul(buf, 10, &val);
4608c2ecf20Sopenharmony_ci	if (err)
4618c2ecf20Sopenharmony_ci		return err;
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ci	/* Save fan_min */
4648c2ecf20Sopenharmony_ci	mutex_lock(&data->update_lock);
4658c2ecf20Sopenharmony_ci	min = FAN_FROM_REG(data->fan_min[nr],
4668c2ecf20Sopenharmony_ci			   DIV_FROM_REG(data->fan_div[nr]));
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ci	data->fan_div[nr] = DIV_TO_REG(val);
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_ci	fan_div_reg = w83792d_read_value(client, W83792D_REG_FAN_DIV[nr >> 1]);
4718c2ecf20Sopenharmony_ci	fan_div_reg &= (nr & 0x01) ? 0x8f : 0xf8;
4728c2ecf20Sopenharmony_ci	tmp_fan_div = (nr & 0x01) ? (((data->fan_div[nr]) << 4) & 0x70)
4738c2ecf20Sopenharmony_ci					: ((data->fan_div[nr]) & 0x07);
4748c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_FAN_DIV[nr >> 1],
4758c2ecf20Sopenharmony_ci					fan_div_reg | tmp_fan_div);
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci	/* Restore fan_min */
4788c2ecf20Sopenharmony_ci	data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
4798c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_FAN_MIN[nr], data->fan_min[nr]);
4808c2ecf20Sopenharmony_ci	mutex_unlock(&data->update_lock);
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_ci	return count;
4838c2ecf20Sopenharmony_ci}
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci/* read/write the temperature1, includes measured value and limits */
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_cistatic ssize_t show_temp1(struct device *dev, struct device_attribute *attr,
4888c2ecf20Sopenharmony_ci				char *buf)
4898c2ecf20Sopenharmony_ci{
4908c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
4918c2ecf20Sopenharmony_ci	int nr = sensor_attr->index;
4928c2ecf20Sopenharmony_ci	struct w83792d_data *data = w83792d_update_device(dev);
4938c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp1[nr]));
4948c2ecf20Sopenharmony_ci}
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_cistatic ssize_t store_temp1(struct device *dev, struct device_attribute *attr,
4978c2ecf20Sopenharmony_ci				const char *buf, size_t count)
4988c2ecf20Sopenharmony_ci{
4998c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
5008c2ecf20Sopenharmony_ci	int nr = sensor_attr->index;
5018c2ecf20Sopenharmony_ci	struct i2c_client *client = to_i2c_client(dev);
5028c2ecf20Sopenharmony_ci	struct w83792d_data *data = i2c_get_clientdata(client);
5038c2ecf20Sopenharmony_ci	long val;
5048c2ecf20Sopenharmony_ci	int err;
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_ci	err = kstrtol(buf, 10, &val);
5078c2ecf20Sopenharmony_ci	if (err)
5088c2ecf20Sopenharmony_ci		return err;
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_ci	mutex_lock(&data->update_lock);
5118c2ecf20Sopenharmony_ci	data->temp1[nr] = TEMP1_TO_REG(val);
5128c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_TEMP1[nr],
5138c2ecf20Sopenharmony_ci		data->temp1[nr]);
5148c2ecf20Sopenharmony_ci	mutex_unlock(&data->update_lock);
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci	return count;
5178c2ecf20Sopenharmony_ci}
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci/* read/write the temperature2-3, includes measured value and limits */
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_cistatic ssize_t show_temp23(struct device *dev, struct device_attribute *attr,
5228c2ecf20Sopenharmony_ci				char *buf)
5238c2ecf20Sopenharmony_ci{
5248c2ecf20Sopenharmony_ci	struct sensor_device_attribute_2 *sensor_attr
5258c2ecf20Sopenharmony_ci	  = to_sensor_dev_attr_2(attr);
5268c2ecf20Sopenharmony_ci	int nr = sensor_attr->nr;
5278c2ecf20Sopenharmony_ci	int index = sensor_attr->index;
5288c2ecf20Sopenharmony_ci	struct w83792d_data *data = w83792d_update_device(dev);
5298c2ecf20Sopenharmony_ci	return sprintf(buf, "%ld\n",
5308c2ecf20Sopenharmony_ci		(long)TEMP_ADD_FROM_REG(data->temp_add[nr][index],
5318c2ecf20Sopenharmony_ci			data->temp_add[nr][index+1]));
5328c2ecf20Sopenharmony_ci}
5338c2ecf20Sopenharmony_ci
5348c2ecf20Sopenharmony_cistatic ssize_t store_temp23(struct device *dev, struct device_attribute *attr,
5358c2ecf20Sopenharmony_ci				const char *buf, size_t count)
5368c2ecf20Sopenharmony_ci{
5378c2ecf20Sopenharmony_ci	struct sensor_device_attribute_2 *sensor_attr
5388c2ecf20Sopenharmony_ci	  = to_sensor_dev_attr_2(attr);
5398c2ecf20Sopenharmony_ci	int nr = sensor_attr->nr;
5408c2ecf20Sopenharmony_ci	int index = sensor_attr->index;
5418c2ecf20Sopenharmony_ci	struct i2c_client *client = to_i2c_client(dev);
5428c2ecf20Sopenharmony_ci	struct w83792d_data *data = i2c_get_clientdata(client);
5438c2ecf20Sopenharmony_ci	long val;
5448c2ecf20Sopenharmony_ci	int err;
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_ci	err = kstrtol(buf, 10, &val);
5478c2ecf20Sopenharmony_ci	if (err)
5488c2ecf20Sopenharmony_ci		return err;
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_ci	mutex_lock(&data->update_lock);
5518c2ecf20Sopenharmony_ci	data->temp_add[nr][index] = TEMP_ADD_TO_REG_HIGH(val);
5528c2ecf20Sopenharmony_ci	data->temp_add[nr][index+1] = TEMP_ADD_TO_REG_LOW(val);
5538c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_TEMP_ADD[nr][index],
5548c2ecf20Sopenharmony_ci		data->temp_add[nr][index]);
5558c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_TEMP_ADD[nr][index+1],
5568c2ecf20Sopenharmony_ci		data->temp_add[nr][index+1]);
5578c2ecf20Sopenharmony_ci	mutex_unlock(&data->update_lock);
5588c2ecf20Sopenharmony_ci
5598c2ecf20Sopenharmony_ci	return count;
5608c2ecf20Sopenharmony_ci}
5618c2ecf20Sopenharmony_ci
5628c2ecf20Sopenharmony_ci/* get realtime status of all sensors items: voltage, temp, fan */
5638c2ecf20Sopenharmony_cistatic ssize_t
5648c2ecf20Sopenharmony_cialarms_show(struct device *dev, struct device_attribute *attr, char *buf)
5658c2ecf20Sopenharmony_ci{
5668c2ecf20Sopenharmony_ci	struct w83792d_data *data = w83792d_update_device(dev);
5678c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", data->alarms);
5688c2ecf20Sopenharmony_ci}
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_cistatic ssize_t show_alarm(struct device *dev,
5718c2ecf20Sopenharmony_ci			  struct device_attribute *attr, char *buf)
5728c2ecf20Sopenharmony_ci{
5738c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
5748c2ecf20Sopenharmony_ci	int nr = sensor_attr->index;
5758c2ecf20Sopenharmony_ci	struct w83792d_data *data = w83792d_update_device(dev);
5768c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", (data->alarms >> nr) & 1);
5778c2ecf20Sopenharmony_ci}
5788c2ecf20Sopenharmony_ci
5798c2ecf20Sopenharmony_cistatic ssize_t
5808c2ecf20Sopenharmony_cishow_pwm(struct device *dev, struct device_attribute *attr,
5818c2ecf20Sopenharmony_ci		char *buf)
5828c2ecf20Sopenharmony_ci{
5838c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
5848c2ecf20Sopenharmony_ci	int nr = sensor_attr->index;
5858c2ecf20Sopenharmony_ci	struct w83792d_data *data = w83792d_update_device(dev);
5868c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", (data->pwm[nr] & 0x0f) << 4);
5878c2ecf20Sopenharmony_ci}
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_cistatic ssize_t
5908c2ecf20Sopenharmony_cishow_pwmenable(struct device *dev, struct device_attribute *attr,
5918c2ecf20Sopenharmony_ci			char *buf)
5928c2ecf20Sopenharmony_ci{
5938c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
5948c2ecf20Sopenharmony_ci	int nr = sensor_attr->index - 1;
5958c2ecf20Sopenharmony_ci	struct w83792d_data *data = w83792d_update_device(dev);
5968c2ecf20Sopenharmony_ci	long pwm_enable_tmp = 1;
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_ci	switch (data->pwmenable[nr]) {
5998c2ecf20Sopenharmony_ci	case 0:
6008c2ecf20Sopenharmony_ci		pwm_enable_tmp = 1; /* manual mode */
6018c2ecf20Sopenharmony_ci		break;
6028c2ecf20Sopenharmony_ci	case 1:
6038c2ecf20Sopenharmony_ci		pwm_enable_tmp = 3; /*thermal cruise/Smart Fan I */
6048c2ecf20Sopenharmony_ci		break;
6058c2ecf20Sopenharmony_ci	case 2:
6068c2ecf20Sopenharmony_ci		pwm_enable_tmp = 2; /* Smart Fan II */
6078c2ecf20Sopenharmony_ci		break;
6088c2ecf20Sopenharmony_ci	}
6098c2ecf20Sopenharmony_ci
6108c2ecf20Sopenharmony_ci	return sprintf(buf, "%ld\n", pwm_enable_tmp);
6118c2ecf20Sopenharmony_ci}
6128c2ecf20Sopenharmony_ci
6138c2ecf20Sopenharmony_cistatic ssize_t
6148c2ecf20Sopenharmony_cistore_pwm(struct device *dev, struct device_attribute *attr,
6158c2ecf20Sopenharmony_ci		const char *buf, size_t count)
6168c2ecf20Sopenharmony_ci{
6178c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
6188c2ecf20Sopenharmony_ci	int nr = sensor_attr->index;
6198c2ecf20Sopenharmony_ci	struct i2c_client *client = to_i2c_client(dev);
6208c2ecf20Sopenharmony_ci	struct w83792d_data *data = i2c_get_clientdata(client);
6218c2ecf20Sopenharmony_ci	unsigned long val;
6228c2ecf20Sopenharmony_ci	int err;
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_ci	err = kstrtoul(buf, 10, &val);
6258c2ecf20Sopenharmony_ci	if (err)
6268c2ecf20Sopenharmony_ci		return err;
6278c2ecf20Sopenharmony_ci	val = clamp_val(val, 0, 255) >> 4;
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_ci	mutex_lock(&data->update_lock);
6308c2ecf20Sopenharmony_ci	val |= w83792d_read_value(client, W83792D_REG_PWM[nr]) & 0xf0;
6318c2ecf20Sopenharmony_ci	data->pwm[nr] = val;
6328c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_PWM[nr], data->pwm[nr]);
6338c2ecf20Sopenharmony_ci	mutex_unlock(&data->update_lock);
6348c2ecf20Sopenharmony_ci
6358c2ecf20Sopenharmony_ci	return count;
6368c2ecf20Sopenharmony_ci}
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_cistatic ssize_t
6398c2ecf20Sopenharmony_cistore_pwmenable(struct device *dev, struct device_attribute *attr,
6408c2ecf20Sopenharmony_ci			const char *buf, size_t count)
6418c2ecf20Sopenharmony_ci{
6428c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
6438c2ecf20Sopenharmony_ci	int nr = sensor_attr->index - 1;
6448c2ecf20Sopenharmony_ci	struct i2c_client *client = to_i2c_client(dev);
6458c2ecf20Sopenharmony_ci	struct w83792d_data *data = i2c_get_clientdata(client);
6468c2ecf20Sopenharmony_ci	u8 fan_cfg_tmp, cfg1_tmp, cfg2_tmp, cfg3_tmp, cfg4_tmp;
6478c2ecf20Sopenharmony_ci	unsigned long val;
6488c2ecf20Sopenharmony_ci	int err;
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ci	err = kstrtoul(buf, 10, &val);
6518c2ecf20Sopenharmony_ci	if (err)
6528c2ecf20Sopenharmony_ci		return err;
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_ci	if (val < 1 || val > 3)
6558c2ecf20Sopenharmony_ci		return -EINVAL;
6568c2ecf20Sopenharmony_ci
6578c2ecf20Sopenharmony_ci	mutex_lock(&data->update_lock);
6588c2ecf20Sopenharmony_ci	switch (val) {
6598c2ecf20Sopenharmony_ci	case 1:
6608c2ecf20Sopenharmony_ci		data->pwmenable[nr] = 0; /* manual mode */
6618c2ecf20Sopenharmony_ci		break;
6628c2ecf20Sopenharmony_ci	case 2:
6638c2ecf20Sopenharmony_ci		data->pwmenable[nr] = 2; /* Smart Fan II */
6648c2ecf20Sopenharmony_ci		break;
6658c2ecf20Sopenharmony_ci	case 3:
6668c2ecf20Sopenharmony_ci		data->pwmenable[nr] = 1; /* thermal cruise/Smart Fan I */
6678c2ecf20Sopenharmony_ci		break;
6688c2ecf20Sopenharmony_ci	}
6698c2ecf20Sopenharmony_ci	cfg1_tmp = data->pwmenable[0];
6708c2ecf20Sopenharmony_ci	cfg2_tmp = (data->pwmenable[1]) << 2;
6718c2ecf20Sopenharmony_ci	cfg3_tmp = (data->pwmenable[2]) << 4;
6728c2ecf20Sopenharmony_ci	cfg4_tmp = w83792d_read_value(client, W83792D_REG_FAN_CFG) & 0xc0;
6738c2ecf20Sopenharmony_ci	fan_cfg_tmp = ((cfg4_tmp | cfg3_tmp) | cfg2_tmp) | cfg1_tmp;
6748c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_FAN_CFG, fan_cfg_tmp);
6758c2ecf20Sopenharmony_ci	mutex_unlock(&data->update_lock);
6768c2ecf20Sopenharmony_ci
6778c2ecf20Sopenharmony_ci	return count;
6788c2ecf20Sopenharmony_ci}
6798c2ecf20Sopenharmony_ci
6808c2ecf20Sopenharmony_cistatic ssize_t
6818c2ecf20Sopenharmony_cishow_pwm_mode(struct device *dev, struct device_attribute *attr,
6828c2ecf20Sopenharmony_ci			char *buf)
6838c2ecf20Sopenharmony_ci{
6848c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
6858c2ecf20Sopenharmony_ci	int nr = sensor_attr->index;
6868c2ecf20Sopenharmony_ci	struct w83792d_data *data = w83792d_update_device(dev);
6878c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", data->pwm[nr] >> 7);
6888c2ecf20Sopenharmony_ci}
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_cistatic ssize_t
6918c2ecf20Sopenharmony_cistore_pwm_mode(struct device *dev, struct device_attribute *attr,
6928c2ecf20Sopenharmony_ci			const char *buf, size_t count)
6938c2ecf20Sopenharmony_ci{
6948c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
6958c2ecf20Sopenharmony_ci	int nr = sensor_attr->index;
6968c2ecf20Sopenharmony_ci	struct i2c_client *client = to_i2c_client(dev);
6978c2ecf20Sopenharmony_ci	struct w83792d_data *data = i2c_get_clientdata(client);
6988c2ecf20Sopenharmony_ci	unsigned long val;
6998c2ecf20Sopenharmony_ci	int err;
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_ci	err = kstrtoul(buf, 10, &val);
7028c2ecf20Sopenharmony_ci	if (err)
7038c2ecf20Sopenharmony_ci		return err;
7048c2ecf20Sopenharmony_ci	if (val > 1)
7058c2ecf20Sopenharmony_ci		return -EINVAL;
7068c2ecf20Sopenharmony_ci
7078c2ecf20Sopenharmony_ci	mutex_lock(&data->update_lock);
7088c2ecf20Sopenharmony_ci	data->pwm[nr] = w83792d_read_value(client, W83792D_REG_PWM[nr]);
7098c2ecf20Sopenharmony_ci	if (val) {			/* PWM mode */
7108c2ecf20Sopenharmony_ci		data->pwm[nr] |= 0x80;
7118c2ecf20Sopenharmony_ci	} else {			/* DC mode */
7128c2ecf20Sopenharmony_ci		data->pwm[nr] &= 0x7f;
7138c2ecf20Sopenharmony_ci	}
7148c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_PWM[nr], data->pwm[nr]);
7158c2ecf20Sopenharmony_ci	mutex_unlock(&data->update_lock);
7168c2ecf20Sopenharmony_ci
7178c2ecf20Sopenharmony_ci	return count;
7188c2ecf20Sopenharmony_ci}
7198c2ecf20Sopenharmony_ci
7208c2ecf20Sopenharmony_cistatic ssize_t
7218c2ecf20Sopenharmony_ciintrusion0_alarm_show(struct device *dev, struct device_attribute *attr,
7228c2ecf20Sopenharmony_ci		      char *buf)
7238c2ecf20Sopenharmony_ci{
7248c2ecf20Sopenharmony_ci	struct w83792d_data *data = w83792d_update_device(dev);
7258c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", data->chassis);
7268c2ecf20Sopenharmony_ci}
7278c2ecf20Sopenharmony_ci
7288c2ecf20Sopenharmony_cistatic ssize_t
7298c2ecf20Sopenharmony_ciintrusion0_alarm_store(struct device *dev, struct device_attribute *attr,
7308c2ecf20Sopenharmony_ci		       const char *buf, size_t count)
7318c2ecf20Sopenharmony_ci{
7328c2ecf20Sopenharmony_ci	struct i2c_client *client = to_i2c_client(dev);
7338c2ecf20Sopenharmony_ci	struct w83792d_data *data = i2c_get_clientdata(client);
7348c2ecf20Sopenharmony_ci	unsigned long val;
7358c2ecf20Sopenharmony_ci	u8 reg;
7368c2ecf20Sopenharmony_ci
7378c2ecf20Sopenharmony_ci	if (kstrtoul(buf, 10, &val) || val != 0)
7388c2ecf20Sopenharmony_ci		return -EINVAL;
7398c2ecf20Sopenharmony_ci
7408c2ecf20Sopenharmony_ci	mutex_lock(&data->update_lock);
7418c2ecf20Sopenharmony_ci	reg = w83792d_read_value(client, W83792D_REG_CHASSIS_CLR);
7428c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_CHASSIS_CLR, reg | 0x80);
7438c2ecf20Sopenharmony_ci	data->valid = 0;		/* Force cache refresh */
7448c2ecf20Sopenharmony_ci	mutex_unlock(&data->update_lock);
7458c2ecf20Sopenharmony_ci
7468c2ecf20Sopenharmony_ci	return count;
7478c2ecf20Sopenharmony_ci}
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_ci/* For Smart Fan I / Thermal Cruise */
7508c2ecf20Sopenharmony_cistatic ssize_t
7518c2ecf20Sopenharmony_cishow_thermal_cruise(struct device *dev, struct device_attribute *attr,
7528c2ecf20Sopenharmony_ci			char *buf)
7538c2ecf20Sopenharmony_ci{
7548c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
7558c2ecf20Sopenharmony_ci	int nr = sensor_attr->index;
7568c2ecf20Sopenharmony_ci	struct w83792d_data *data = w83792d_update_device(dev);
7578c2ecf20Sopenharmony_ci	return sprintf(buf, "%ld\n", (long)data->thermal_cruise[nr-1]);
7588c2ecf20Sopenharmony_ci}
7598c2ecf20Sopenharmony_ci
7608c2ecf20Sopenharmony_cistatic ssize_t
7618c2ecf20Sopenharmony_cistore_thermal_cruise(struct device *dev, struct device_attribute *attr,
7628c2ecf20Sopenharmony_ci			const char *buf, size_t count)
7638c2ecf20Sopenharmony_ci{
7648c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
7658c2ecf20Sopenharmony_ci	int nr = sensor_attr->index - 1;
7668c2ecf20Sopenharmony_ci	struct i2c_client *client = to_i2c_client(dev);
7678c2ecf20Sopenharmony_ci	struct w83792d_data *data = i2c_get_clientdata(client);
7688c2ecf20Sopenharmony_ci	u8 target_tmp = 0, target_mask = 0;
7698c2ecf20Sopenharmony_ci	unsigned long val;
7708c2ecf20Sopenharmony_ci	int err;
7718c2ecf20Sopenharmony_ci
7728c2ecf20Sopenharmony_ci	err = kstrtoul(buf, 10, &val);
7738c2ecf20Sopenharmony_ci	if (err)
7748c2ecf20Sopenharmony_ci		return err;
7758c2ecf20Sopenharmony_ci
7768c2ecf20Sopenharmony_ci	target_tmp = val;
7778c2ecf20Sopenharmony_ci	target_tmp = target_tmp & 0x7f;
7788c2ecf20Sopenharmony_ci	mutex_lock(&data->update_lock);
7798c2ecf20Sopenharmony_ci	target_mask = w83792d_read_value(client,
7808c2ecf20Sopenharmony_ci					 W83792D_REG_THERMAL[nr]) & 0x80;
7818c2ecf20Sopenharmony_ci	data->thermal_cruise[nr] = clamp_val(target_tmp, 0, 255);
7828c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_THERMAL[nr],
7838c2ecf20Sopenharmony_ci		(data->thermal_cruise[nr]) | target_mask);
7848c2ecf20Sopenharmony_ci	mutex_unlock(&data->update_lock);
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_ci	return count;
7878c2ecf20Sopenharmony_ci}
7888c2ecf20Sopenharmony_ci
7898c2ecf20Sopenharmony_ci/* For Smart Fan I/Thermal Cruise and Smart Fan II */
7908c2ecf20Sopenharmony_cistatic ssize_t
7918c2ecf20Sopenharmony_cishow_tolerance(struct device *dev, struct device_attribute *attr,
7928c2ecf20Sopenharmony_ci		char *buf)
7938c2ecf20Sopenharmony_ci{
7948c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
7958c2ecf20Sopenharmony_ci	int nr = sensor_attr->index;
7968c2ecf20Sopenharmony_ci	struct w83792d_data *data = w83792d_update_device(dev);
7978c2ecf20Sopenharmony_ci	return sprintf(buf, "%ld\n", (long)data->tolerance[nr-1]);
7988c2ecf20Sopenharmony_ci}
7998c2ecf20Sopenharmony_ci
8008c2ecf20Sopenharmony_cistatic ssize_t
8018c2ecf20Sopenharmony_cistore_tolerance(struct device *dev, struct device_attribute *attr,
8028c2ecf20Sopenharmony_ci		const char *buf, size_t count)
8038c2ecf20Sopenharmony_ci{
8048c2ecf20Sopenharmony_ci	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
8058c2ecf20Sopenharmony_ci	int nr = sensor_attr->index - 1;
8068c2ecf20Sopenharmony_ci	struct i2c_client *client = to_i2c_client(dev);
8078c2ecf20Sopenharmony_ci	struct w83792d_data *data = i2c_get_clientdata(client);
8088c2ecf20Sopenharmony_ci	u8 tol_tmp, tol_mask;
8098c2ecf20Sopenharmony_ci	unsigned long val;
8108c2ecf20Sopenharmony_ci	int err;
8118c2ecf20Sopenharmony_ci
8128c2ecf20Sopenharmony_ci	err = kstrtoul(buf, 10, &val);
8138c2ecf20Sopenharmony_ci	if (err)
8148c2ecf20Sopenharmony_ci		return err;
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci	mutex_lock(&data->update_lock);
8178c2ecf20Sopenharmony_ci	tol_mask = w83792d_read_value(client,
8188c2ecf20Sopenharmony_ci		W83792D_REG_TOLERANCE[nr]) & ((nr == 1) ? 0x0f : 0xf0);
8198c2ecf20Sopenharmony_ci	tol_tmp = clamp_val(val, 0, 15);
8208c2ecf20Sopenharmony_ci	tol_tmp &= 0x0f;
8218c2ecf20Sopenharmony_ci	data->tolerance[nr] = tol_tmp;
8228c2ecf20Sopenharmony_ci	if (nr == 1)
8238c2ecf20Sopenharmony_ci		tol_tmp <<= 4;
8248c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_TOLERANCE[nr],
8258c2ecf20Sopenharmony_ci		tol_mask | tol_tmp);
8268c2ecf20Sopenharmony_ci	mutex_unlock(&data->update_lock);
8278c2ecf20Sopenharmony_ci
8288c2ecf20Sopenharmony_ci	return count;
8298c2ecf20Sopenharmony_ci}
8308c2ecf20Sopenharmony_ci
8318c2ecf20Sopenharmony_ci/* For Smart Fan II */
8328c2ecf20Sopenharmony_cistatic ssize_t
8338c2ecf20Sopenharmony_cishow_sf2_point(struct device *dev, struct device_attribute *attr,
8348c2ecf20Sopenharmony_ci		char *buf)
8358c2ecf20Sopenharmony_ci{
8368c2ecf20Sopenharmony_ci	struct sensor_device_attribute_2 *sensor_attr
8378c2ecf20Sopenharmony_ci	  = to_sensor_dev_attr_2(attr);
8388c2ecf20Sopenharmony_ci	int nr = sensor_attr->nr;
8398c2ecf20Sopenharmony_ci	int index = sensor_attr->index;
8408c2ecf20Sopenharmony_ci	struct w83792d_data *data = w83792d_update_device(dev);
8418c2ecf20Sopenharmony_ci	return sprintf(buf, "%ld\n", (long)data->sf2_points[index-1][nr-1]);
8428c2ecf20Sopenharmony_ci}
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_cistatic ssize_t
8458c2ecf20Sopenharmony_cistore_sf2_point(struct device *dev, struct device_attribute *attr,
8468c2ecf20Sopenharmony_ci		const char *buf, size_t count)
8478c2ecf20Sopenharmony_ci{
8488c2ecf20Sopenharmony_ci	struct sensor_device_attribute_2 *sensor_attr
8498c2ecf20Sopenharmony_ci	  = to_sensor_dev_attr_2(attr);
8508c2ecf20Sopenharmony_ci	int nr = sensor_attr->nr - 1;
8518c2ecf20Sopenharmony_ci	int index = sensor_attr->index - 1;
8528c2ecf20Sopenharmony_ci	struct i2c_client *client = to_i2c_client(dev);
8538c2ecf20Sopenharmony_ci	struct w83792d_data *data = i2c_get_clientdata(client);
8548c2ecf20Sopenharmony_ci	u8 mask_tmp = 0;
8558c2ecf20Sopenharmony_ci	unsigned long val;
8568c2ecf20Sopenharmony_ci	int err;
8578c2ecf20Sopenharmony_ci
8588c2ecf20Sopenharmony_ci	err = kstrtoul(buf, 10, &val);
8598c2ecf20Sopenharmony_ci	if (err)
8608c2ecf20Sopenharmony_ci		return err;
8618c2ecf20Sopenharmony_ci
8628c2ecf20Sopenharmony_ci	mutex_lock(&data->update_lock);
8638c2ecf20Sopenharmony_ci	data->sf2_points[index][nr] = clamp_val(val, 0, 127);
8648c2ecf20Sopenharmony_ci	mask_tmp = w83792d_read_value(client,
8658c2ecf20Sopenharmony_ci					W83792D_REG_POINTS[index][nr]) & 0x80;
8668c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_POINTS[index][nr],
8678c2ecf20Sopenharmony_ci		mask_tmp|data->sf2_points[index][nr]);
8688c2ecf20Sopenharmony_ci	mutex_unlock(&data->update_lock);
8698c2ecf20Sopenharmony_ci
8708c2ecf20Sopenharmony_ci	return count;
8718c2ecf20Sopenharmony_ci}
8728c2ecf20Sopenharmony_ci
8738c2ecf20Sopenharmony_cistatic ssize_t
8748c2ecf20Sopenharmony_cishow_sf2_level(struct device *dev, struct device_attribute *attr,
8758c2ecf20Sopenharmony_ci		char *buf)
8768c2ecf20Sopenharmony_ci{
8778c2ecf20Sopenharmony_ci	struct sensor_device_attribute_2 *sensor_attr
8788c2ecf20Sopenharmony_ci	  = to_sensor_dev_attr_2(attr);
8798c2ecf20Sopenharmony_ci	int nr = sensor_attr->nr;
8808c2ecf20Sopenharmony_ci	int index = sensor_attr->index;
8818c2ecf20Sopenharmony_ci	struct w83792d_data *data = w83792d_update_device(dev);
8828c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n",
8838c2ecf20Sopenharmony_ci			(((data->sf2_levels[index-1][nr]) * 100) / 15));
8848c2ecf20Sopenharmony_ci}
8858c2ecf20Sopenharmony_ci
8868c2ecf20Sopenharmony_cistatic ssize_t
8878c2ecf20Sopenharmony_cistore_sf2_level(struct device *dev, struct device_attribute *attr,
8888c2ecf20Sopenharmony_ci		const char *buf, size_t count)
8898c2ecf20Sopenharmony_ci{
8908c2ecf20Sopenharmony_ci	struct sensor_device_attribute_2 *sensor_attr
8918c2ecf20Sopenharmony_ci	  = to_sensor_dev_attr_2(attr);
8928c2ecf20Sopenharmony_ci	int nr = sensor_attr->nr;
8938c2ecf20Sopenharmony_ci	int index = sensor_attr->index - 1;
8948c2ecf20Sopenharmony_ci	struct i2c_client *client = to_i2c_client(dev);
8958c2ecf20Sopenharmony_ci	struct w83792d_data *data = i2c_get_clientdata(client);
8968c2ecf20Sopenharmony_ci	u8 mask_tmp = 0, level_tmp = 0;
8978c2ecf20Sopenharmony_ci	unsigned long val;
8988c2ecf20Sopenharmony_ci	int err;
8998c2ecf20Sopenharmony_ci
9008c2ecf20Sopenharmony_ci	err = kstrtoul(buf, 10, &val);
9018c2ecf20Sopenharmony_ci	if (err)
9028c2ecf20Sopenharmony_ci		return err;
9038c2ecf20Sopenharmony_ci
9048c2ecf20Sopenharmony_ci	mutex_lock(&data->update_lock);
9058c2ecf20Sopenharmony_ci	data->sf2_levels[index][nr] = clamp_val((val * 15) / 100, 0, 15);
9068c2ecf20Sopenharmony_ci	mask_tmp = w83792d_read_value(client, W83792D_REG_LEVELS[index][nr])
9078c2ecf20Sopenharmony_ci		& ((nr == 3) ? 0xf0 : 0x0f);
9088c2ecf20Sopenharmony_ci	if (nr == 3)
9098c2ecf20Sopenharmony_ci		level_tmp = data->sf2_levels[index][nr];
9108c2ecf20Sopenharmony_ci	else
9118c2ecf20Sopenharmony_ci		level_tmp = data->sf2_levels[index][nr] << 4;
9128c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_LEVELS[index][nr],
9138c2ecf20Sopenharmony_ci			    level_tmp | mask_tmp);
9148c2ecf20Sopenharmony_ci	mutex_unlock(&data->update_lock);
9158c2ecf20Sopenharmony_ci
9168c2ecf20Sopenharmony_ci	return count;
9178c2ecf20Sopenharmony_ci}
9188c2ecf20Sopenharmony_ci
9198c2ecf20Sopenharmony_ci
9208c2ecf20Sopenharmony_cistatic int
9218c2ecf20Sopenharmony_ciw83792d_detect_subclients(struct i2c_client *new_client)
9228c2ecf20Sopenharmony_ci{
9238c2ecf20Sopenharmony_ci	int i, id;
9248c2ecf20Sopenharmony_ci	int address = new_client->addr;
9258c2ecf20Sopenharmony_ci	u8 val;
9268c2ecf20Sopenharmony_ci	struct i2c_adapter *adapter = new_client->adapter;
9278c2ecf20Sopenharmony_ci
9288c2ecf20Sopenharmony_ci	id = i2c_adapter_id(adapter);
9298c2ecf20Sopenharmony_ci	if (force_subclients[0] == id && force_subclients[1] == address) {
9308c2ecf20Sopenharmony_ci		for (i = 2; i <= 3; i++) {
9318c2ecf20Sopenharmony_ci			if (force_subclients[i] < 0x48 ||
9328c2ecf20Sopenharmony_ci			    force_subclients[i] > 0x4f) {
9338c2ecf20Sopenharmony_ci				dev_err(&new_client->dev,
9348c2ecf20Sopenharmony_ci					"invalid subclient address %d; must be 0x48-0x4f\n",
9358c2ecf20Sopenharmony_ci					force_subclients[i]);
9368c2ecf20Sopenharmony_ci				return -ENODEV;
9378c2ecf20Sopenharmony_ci			}
9388c2ecf20Sopenharmony_ci		}
9398c2ecf20Sopenharmony_ci		w83792d_write_value(new_client, W83792D_REG_I2C_SUBADDR,
9408c2ecf20Sopenharmony_ci					(force_subclients[2] & 0x07) |
9418c2ecf20Sopenharmony_ci					((force_subclients[3] & 0x07) << 4));
9428c2ecf20Sopenharmony_ci	}
9438c2ecf20Sopenharmony_ci
9448c2ecf20Sopenharmony_ci	val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR);
9458c2ecf20Sopenharmony_ci
9468c2ecf20Sopenharmony_ci	if (!(val & 0x88) && (val & 0x7) == ((val >> 4) & 0x7)) {
9478c2ecf20Sopenharmony_ci		dev_err(&new_client->dev,
9488c2ecf20Sopenharmony_ci			"duplicate addresses 0x%x, use force_subclient\n", 0x48 + (val & 0x7));
9498c2ecf20Sopenharmony_ci		return -ENODEV;
9508c2ecf20Sopenharmony_ci	}
9518c2ecf20Sopenharmony_ci
9528c2ecf20Sopenharmony_ci	if (!(val & 0x08))
9538c2ecf20Sopenharmony_ci		devm_i2c_new_dummy_device(&new_client->dev, adapter, 0x48 + (val & 0x7));
9548c2ecf20Sopenharmony_ci
9558c2ecf20Sopenharmony_ci	if (!(val & 0x80))
9568c2ecf20Sopenharmony_ci		devm_i2c_new_dummy_device(&new_client->dev, adapter, 0x48 + ((val >> 4) & 0x7));
9578c2ecf20Sopenharmony_ci
9588c2ecf20Sopenharmony_ci	return 0;
9598c2ecf20Sopenharmony_ci}
9608c2ecf20Sopenharmony_ci
9618c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in, NULL, 0);
9628c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 1);
9638c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 2);
9648c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 3);
9658c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in, NULL, 4);
9668c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in, NULL, 5);
9678c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in, NULL, 6);
9688c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_in, NULL, 7);
9698c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_in, NULL, 8);
9708c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO,
9718c2ecf20Sopenharmony_ci			show_in_min, store_in_min, 0);
9728c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO,
9738c2ecf20Sopenharmony_ci			show_in_min, store_in_min, 1);
9748c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO,
9758c2ecf20Sopenharmony_ci			show_in_min, store_in_min, 2);
9768c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO,
9778c2ecf20Sopenharmony_ci			show_in_min, store_in_min, 3);
9788c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO,
9798c2ecf20Sopenharmony_ci			show_in_min, store_in_min, 4);
9808c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO,
9818c2ecf20Sopenharmony_ci			show_in_min, store_in_min, 5);
9828c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO,
9838c2ecf20Sopenharmony_ci			show_in_min, store_in_min, 6);
9848c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in7_min, S_IWUSR | S_IRUGO,
9858c2ecf20Sopenharmony_ci			show_in_min, store_in_min, 7);
9868c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in8_min, S_IWUSR | S_IRUGO,
9878c2ecf20Sopenharmony_ci			show_in_min, store_in_min, 8);
9888c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in0_max, S_IWUSR | S_IRUGO,
9898c2ecf20Sopenharmony_ci			show_in_max, store_in_max, 0);
9908c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO,
9918c2ecf20Sopenharmony_ci			show_in_max, store_in_max, 1);
9928c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO,
9938c2ecf20Sopenharmony_ci			show_in_max, store_in_max, 2);
9948c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO,
9958c2ecf20Sopenharmony_ci			show_in_max, store_in_max, 3);
9968c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO,
9978c2ecf20Sopenharmony_ci			show_in_max, store_in_max, 4);
9988c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO,
9998c2ecf20Sopenharmony_ci			show_in_max, store_in_max, 5);
10008c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO,
10018c2ecf20Sopenharmony_ci			show_in_max, store_in_max, 6);
10028c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in7_max, S_IWUSR | S_IRUGO,
10038c2ecf20Sopenharmony_ci			show_in_max, store_in_max, 7);
10048c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in8_max, S_IWUSR | S_IRUGO,
10058c2ecf20Sopenharmony_ci			show_in_max, store_in_max, 8);
10068c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp1, NULL, 0, 0);
10078c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp23, NULL, 0, 0);
10088c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp23, NULL, 1, 0);
10098c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR,
10108c2ecf20Sopenharmony_ci			show_temp1, store_temp1, 0, 1);
10118c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp23,
10128c2ecf20Sopenharmony_ci			store_temp23, 0, 2);
10138c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp23,
10148c2ecf20Sopenharmony_ci			store_temp23, 1, 2);
10158c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(temp1_max_hyst, S_IRUGO | S_IWUSR,
10168c2ecf20Sopenharmony_ci			show_temp1, store_temp1, 0, 2);
10178c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(temp2_max_hyst, S_IRUGO | S_IWUSR,
10188c2ecf20Sopenharmony_ci			show_temp23, store_temp23, 0, 4);
10198c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(temp3_max_hyst, S_IRUGO | S_IWUSR,
10208c2ecf20Sopenharmony_ci			show_temp23, store_temp23, 1, 4);
10218c2ecf20Sopenharmony_cistatic DEVICE_ATTR_RO(alarms);
10228c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
10238c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
10248c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 2);
10258c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 3);
10268c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 4);
10278c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 5);
10288c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 6);
10298c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 7);
10308c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 8);
10318c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 9);
10328c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 10);
10338c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 11);
10348c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 12);
10358c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan7_alarm, S_IRUGO, show_alarm, NULL, 15);
10368c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 19);
10378c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 20);
10388c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 21);
10398c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 22);
10408c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 23);
10418c2ecf20Sopenharmony_cistatic DEVICE_ATTR_RW(intrusion0_alarm);
10428c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0);
10438c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1);
10448c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2);
10458c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 3);
10468c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm5, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 4);
10478c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm6, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 5);
10488c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm7, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 6);
10498c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
10508c2ecf20Sopenharmony_ci			show_pwmenable, store_pwmenable, 1);
10518c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO,
10528c2ecf20Sopenharmony_ci			show_pwmenable, store_pwmenable, 2);
10538c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO,
10548c2ecf20Sopenharmony_ci			show_pwmenable, store_pwmenable, 3);
10558c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm1_mode, S_IWUSR | S_IRUGO,
10568c2ecf20Sopenharmony_ci			show_pwm_mode, store_pwm_mode, 0);
10578c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm2_mode, S_IWUSR | S_IRUGO,
10588c2ecf20Sopenharmony_ci			show_pwm_mode, store_pwm_mode, 1);
10598c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm3_mode, S_IWUSR | S_IRUGO,
10608c2ecf20Sopenharmony_ci			show_pwm_mode, store_pwm_mode, 2);
10618c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm4_mode, S_IWUSR | S_IRUGO,
10628c2ecf20Sopenharmony_ci			show_pwm_mode, store_pwm_mode, 3);
10638c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm5_mode, S_IWUSR | S_IRUGO,
10648c2ecf20Sopenharmony_ci			show_pwm_mode, store_pwm_mode, 4);
10658c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm6_mode, S_IWUSR | S_IRUGO,
10668c2ecf20Sopenharmony_ci			show_pwm_mode, store_pwm_mode, 5);
10678c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(pwm7_mode, S_IWUSR | S_IRUGO,
10688c2ecf20Sopenharmony_ci			show_pwm_mode, store_pwm_mode, 6);
10698c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(tolerance1, S_IWUSR | S_IRUGO,
10708c2ecf20Sopenharmony_ci			show_tolerance, store_tolerance, 1);
10718c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(tolerance2, S_IWUSR | S_IRUGO,
10728c2ecf20Sopenharmony_ci			show_tolerance, store_tolerance, 2);
10738c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(tolerance3, S_IWUSR | S_IRUGO,
10748c2ecf20Sopenharmony_ci			show_tolerance, store_tolerance, 3);
10758c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(thermal_cruise1, S_IWUSR | S_IRUGO,
10768c2ecf20Sopenharmony_ci			show_thermal_cruise, store_thermal_cruise, 1);
10778c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(thermal_cruise2, S_IWUSR | S_IRUGO,
10788c2ecf20Sopenharmony_ci			show_thermal_cruise, store_thermal_cruise, 2);
10798c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(thermal_cruise3, S_IWUSR | S_IRUGO,
10808c2ecf20Sopenharmony_ci			show_thermal_cruise, store_thermal_cruise, 3);
10818c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_point1_fan1, S_IRUGO | S_IWUSR,
10828c2ecf20Sopenharmony_ci			show_sf2_point, store_sf2_point, 1, 1);
10838c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_point2_fan1, S_IRUGO | S_IWUSR,
10848c2ecf20Sopenharmony_ci			show_sf2_point, store_sf2_point, 2, 1);
10858c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_point3_fan1, S_IRUGO | S_IWUSR,
10868c2ecf20Sopenharmony_ci			show_sf2_point, store_sf2_point, 3, 1);
10878c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_point4_fan1, S_IRUGO | S_IWUSR,
10888c2ecf20Sopenharmony_ci			show_sf2_point, store_sf2_point, 4, 1);
10898c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_point1_fan2, S_IRUGO | S_IWUSR,
10908c2ecf20Sopenharmony_ci			show_sf2_point, store_sf2_point, 1, 2);
10918c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_point2_fan2, S_IRUGO | S_IWUSR,
10928c2ecf20Sopenharmony_ci			show_sf2_point, store_sf2_point, 2, 2);
10938c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_point3_fan2, S_IRUGO | S_IWUSR,
10948c2ecf20Sopenharmony_ci			show_sf2_point, store_sf2_point, 3, 2);
10958c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_point4_fan2, S_IRUGO | S_IWUSR,
10968c2ecf20Sopenharmony_ci			show_sf2_point, store_sf2_point, 4, 2);
10978c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_point1_fan3, S_IRUGO | S_IWUSR,
10988c2ecf20Sopenharmony_ci			show_sf2_point, store_sf2_point, 1, 3);
10998c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_point2_fan3, S_IRUGO | S_IWUSR,
11008c2ecf20Sopenharmony_ci			show_sf2_point, store_sf2_point, 2, 3);
11018c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_point3_fan3, S_IRUGO | S_IWUSR,
11028c2ecf20Sopenharmony_ci			show_sf2_point, store_sf2_point, 3, 3);
11038c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_point4_fan3, S_IRUGO | S_IWUSR,
11048c2ecf20Sopenharmony_ci			show_sf2_point, store_sf2_point, 4, 3);
11058c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_level1_fan1, S_IRUGO | S_IWUSR,
11068c2ecf20Sopenharmony_ci			show_sf2_level, store_sf2_level, 1, 1);
11078c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_level2_fan1, S_IRUGO | S_IWUSR,
11088c2ecf20Sopenharmony_ci			show_sf2_level, store_sf2_level, 2, 1);
11098c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_level3_fan1, S_IRUGO | S_IWUSR,
11108c2ecf20Sopenharmony_ci			show_sf2_level, store_sf2_level, 3, 1);
11118c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_level1_fan2, S_IRUGO | S_IWUSR,
11128c2ecf20Sopenharmony_ci			show_sf2_level, store_sf2_level, 1, 2);
11138c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_level2_fan2, S_IRUGO | S_IWUSR,
11148c2ecf20Sopenharmony_ci			show_sf2_level, store_sf2_level, 2, 2);
11158c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_level3_fan2, S_IRUGO | S_IWUSR,
11168c2ecf20Sopenharmony_ci			show_sf2_level, store_sf2_level, 3, 2);
11178c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_level1_fan3, S_IRUGO | S_IWUSR,
11188c2ecf20Sopenharmony_ci			show_sf2_level, store_sf2_level, 1, 3);
11198c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_level2_fan3, S_IRUGO | S_IWUSR,
11208c2ecf20Sopenharmony_ci			show_sf2_level, store_sf2_level, 2, 3);
11218c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2(sf2_level3_fan3, S_IRUGO | S_IWUSR,
11228c2ecf20Sopenharmony_ci			show_sf2_level, store_sf2_level, 3, 3);
11238c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 1);
11248c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 2);
11258c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 3);
11268c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 4);
11278c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 5);
11288c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan6_input, S_IRUGO, show_fan, NULL, 6);
11298c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan7_input, S_IRUGO, show_fan, NULL, 7);
11308c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO,
11318c2ecf20Sopenharmony_ci			show_fan_min, store_fan_min, 1);
11328c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO,
11338c2ecf20Sopenharmony_ci			show_fan_min, store_fan_min, 2);
11348c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO,
11358c2ecf20Sopenharmony_ci			show_fan_min, store_fan_min, 3);
11368c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO,
11378c2ecf20Sopenharmony_ci			show_fan_min, store_fan_min, 4);
11388c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan5_min, S_IWUSR | S_IRUGO,
11398c2ecf20Sopenharmony_ci			show_fan_min, store_fan_min, 5);
11408c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan6_min, S_IWUSR | S_IRUGO,
11418c2ecf20Sopenharmony_ci			show_fan_min, store_fan_min, 6);
11428c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan7_min, S_IWUSR | S_IRUGO,
11438c2ecf20Sopenharmony_ci			show_fan_min, store_fan_min, 7);
11448c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO,
11458c2ecf20Sopenharmony_ci			show_fan_div, store_fan_div, 1);
11468c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO,
11478c2ecf20Sopenharmony_ci			show_fan_div, store_fan_div, 2);
11488c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan3_div, S_IWUSR | S_IRUGO,
11498c2ecf20Sopenharmony_ci			show_fan_div, store_fan_div, 3);
11508c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan4_div, S_IWUSR | S_IRUGO,
11518c2ecf20Sopenharmony_ci			show_fan_div, store_fan_div, 4);
11528c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan5_div, S_IWUSR | S_IRUGO,
11538c2ecf20Sopenharmony_ci			show_fan_div, store_fan_div, 5);
11548c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan6_div, S_IWUSR | S_IRUGO,
11558c2ecf20Sopenharmony_ci			show_fan_div, store_fan_div, 6);
11568c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR(fan7_div, S_IWUSR | S_IRUGO,
11578c2ecf20Sopenharmony_ci			show_fan_div, store_fan_div, 7);
11588c2ecf20Sopenharmony_ci
11598c2ecf20Sopenharmony_cistatic struct attribute *w83792d_attributes_fan[4][7] = {
11608c2ecf20Sopenharmony_ci	{
11618c2ecf20Sopenharmony_ci		&sensor_dev_attr_fan4_input.dev_attr.attr,
11628c2ecf20Sopenharmony_ci		&sensor_dev_attr_fan4_min.dev_attr.attr,
11638c2ecf20Sopenharmony_ci		&sensor_dev_attr_fan4_div.dev_attr.attr,
11648c2ecf20Sopenharmony_ci		&sensor_dev_attr_fan4_alarm.dev_attr.attr,
11658c2ecf20Sopenharmony_ci		&sensor_dev_attr_pwm4.dev_attr.attr,
11668c2ecf20Sopenharmony_ci		&sensor_dev_attr_pwm4_mode.dev_attr.attr,
11678c2ecf20Sopenharmony_ci		NULL
11688c2ecf20Sopenharmony_ci	}, {
11698c2ecf20Sopenharmony_ci		&sensor_dev_attr_fan5_input.dev_attr.attr,
11708c2ecf20Sopenharmony_ci		&sensor_dev_attr_fan5_min.dev_attr.attr,
11718c2ecf20Sopenharmony_ci		&sensor_dev_attr_fan5_div.dev_attr.attr,
11728c2ecf20Sopenharmony_ci		&sensor_dev_attr_fan5_alarm.dev_attr.attr,
11738c2ecf20Sopenharmony_ci		&sensor_dev_attr_pwm5.dev_attr.attr,
11748c2ecf20Sopenharmony_ci		&sensor_dev_attr_pwm5_mode.dev_attr.attr,
11758c2ecf20Sopenharmony_ci		NULL
11768c2ecf20Sopenharmony_ci	}, {
11778c2ecf20Sopenharmony_ci		&sensor_dev_attr_fan6_input.dev_attr.attr,
11788c2ecf20Sopenharmony_ci		&sensor_dev_attr_fan6_min.dev_attr.attr,
11798c2ecf20Sopenharmony_ci		&sensor_dev_attr_fan6_div.dev_attr.attr,
11808c2ecf20Sopenharmony_ci		&sensor_dev_attr_fan6_alarm.dev_attr.attr,
11818c2ecf20Sopenharmony_ci		&sensor_dev_attr_pwm6.dev_attr.attr,
11828c2ecf20Sopenharmony_ci		&sensor_dev_attr_pwm6_mode.dev_attr.attr,
11838c2ecf20Sopenharmony_ci		NULL
11848c2ecf20Sopenharmony_ci	}, {
11858c2ecf20Sopenharmony_ci		&sensor_dev_attr_fan7_input.dev_attr.attr,
11868c2ecf20Sopenharmony_ci		&sensor_dev_attr_fan7_min.dev_attr.attr,
11878c2ecf20Sopenharmony_ci		&sensor_dev_attr_fan7_div.dev_attr.attr,
11888c2ecf20Sopenharmony_ci		&sensor_dev_attr_fan7_alarm.dev_attr.attr,
11898c2ecf20Sopenharmony_ci		&sensor_dev_attr_pwm7.dev_attr.attr,
11908c2ecf20Sopenharmony_ci		&sensor_dev_attr_pwm7_mode.dev_attr.attr,
11918c2ecf20Sopenharmony_ci		NULL
11928c2ecf20Sopenharmony_ci	}
11938c2ecf20Sopenharmony_ci};
11948c2ecf20Sopenharmony_ci
11958c2ecf20Sopenharmony_cistatic const struct attribute_group w83792d_group_fan[4] = {
11968c2ecf20Sopenharmony_ci	{ .attrs = w83792d_attributes_fan[0] },
11978c2ecf20Sopenharmony_ci	{ .attrs = w83792d_attributes_fan[1] },
11988c2ecf20Sopenharmony_ci	{ .attrs = w83792d_attributes_fan[2] },
11998c2ecf20Sopenharmony_ci	{ .attrs = w83792d_attributes_fan[3] },
12008c2ecf20Sopenharmony_ci};
12018c2ecf20Sopenharmony_ci
12028c2ecf20Sopenharmony_cistatic struct attribute *w83792d_attributes[] = {
12038c2ecf20Sopenharmony_ci	&sensor_dev_attr_in0_input.dev_attr.attr,
12048c2ecf20Sopenharmony_ci	&sensor_dev_attr_in0_max.dev_attr.attr,
12058c2ecf20Sopenharmony_ci	&sensor_dev_attr_in0_min.dev_attr.attr,
12068c2ecf20Sopenharmony_ci	&sensor_dev_attr_in1_input.dev_attr.attr,
12078c2ecf20Sopenharmony_ci	&sensor_dev_attr_in1_max.dev_attr.attr,
12088c2ecf20Sopenharmony_ci	&sensor_dev_attr_in1_min.dev_attr.attr,
12098c2ecf20Sopenharmony_ci	&sensor_dev_attr_in2_input.dev_attr.attr,
12108c2ecf20Sopenharmony_ci	&sensor_dev_attr_in2_max.dev_attr.attr,
12118c2ecf20Sopenharmony_ci	&sensor_dev_attr_in2_min.dev_attr.attr,
12128c2ecf20Sopenharmony_ci	&sensor_dev_attr_in3_input.dev_attr.attr,
12138c2ecf20Sopenharmony_ci	&sensor_dev_attr_in3_max.dev_attr.attr,
12148c2ecf20Sopenharmony_ci	&sensor_dev_attr_in3_min.dev_attr.attr,
12158c2ecf20Sopenharmony_ci	&sensor_dev_attr_in4_input.dev_attr.attr,
12168c2ecf20Sopenharmony_ci	&sensor_dev_attr_in4_max.dev_attr.attr,
12178c2ecf20Sopenharmony_ci	&sensor_dev_attr_in4_min.dev_attr.attr,
12188c2ecf20Sopenharmony_ci	&sensor_dev_attr_in5_input.dev_attr.attr,
12198c2ecf20Sopenharmony_ci	&sensor_dev_attr_in5_max.dev_attr.attr,
12208c2ecf20Sopenharmony_ci	&sensor_dev_attr_in5_min.dev_attr.attr,
12218c2ecf20Sopenharmony_ci	&sensor_dev_attr_in6_input.dev_attr.attr,
12228c2ecf20Sopenharmony_ci	&sensor_dev_attr_in6_max.dev_attr.attr,
12238c2ecf20Sopenharmony_ci	&sensor_dev_attr_in6_min.dev_attr.attr,
12248c2ecf20Sopenharmony_ci	&sensor_dev_attr_in7_input.dev_attr.attr,
12258c2ecf20Sopenharmony_ci	&sensor_dev_attr_in7_max.dev_attr.attr,
12268c2ecf20Sopenharmony_ci	&sensor_dev_attr_in7_min.dev_attr.attr,
12278c2ecf20Sopenharmony_ci	&sensor_dev_attr_in8_input.dev_attr.attr,
12288c2ecf20Sopenharmony_ci	&sensor_dev_attr_in8_max.dev_attr.attr,
12298c2ecf20Sopenharmony_ci	&sensor_dev_attr_in8_min.dev_attr.attr,
12308c2ecf20Sopenharmony_ci	&sensor_dev_attr_in0_alarm.dev_attr.attr,
12318c2ecf20Sopenharmony_ci	&sensor_dev_attr_in1_alarm.dev_attr.attr,
12328c2ecf20Sopenharmony_ci	&sensor_dev_attr_in2_alarm.dev_attr.attr,
12338c2ecf20Sopenharmony_ci	&sensor_dev_attr_in3_alarm.dev_attr.attr,
12348c2ecf20Sopenharmony_ci	&sensor_dev_attr_in4_alarm.dev_attr.attr,
12358c2ecf20Sopenharmony_ci	&sensor_dev_attr_in5_alarm.dev_attr.attr,
12368c2ecf20Sopenharmony_ci	&sensor_dev_attr_in6_alarm.dev_attr.attr,
12378c2ecf20Sopenharmony_ci	&sensor_dev_attr_in7_alarm.dev_attr.attr,
12388c2ecf20Sopenharmony_ci	&sensor_dev_attr_in8_alarm.dev_attr.attr,
12398c2ecf20Sopenharmony_ci	&sensor_dev_attr_temp1_input.dev_attr.attr,
12408c2ecf20Sopenharmony_ci	&sensor_dev_attr_temp1_max.dev_attr.attr,
12418c2ecf20Sopenharmony_ci	&sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
12428c2ecf20Sopenharmony_ci	&sensor_dev_attr_temp2_input.dev_attr.attr,
12438c2ecf20Sopenharmony_ci	&sensor_dev_attr_temp2_max.dev_attr.attr,
12448c2ecf20Sopenharmony_ci	&sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
12458c2ecf20Sopenharmony_ci	&sensor_dev_attr_temp3_input.dev_attr.attr,
12468c2ecf20Sopenharmony_ci	&sensor_dev_attr_temp3_max.dev_attr.attr,
12478c2ecf20Sopenharmony_ci	&sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
12488c2ecf20Sopenharmony_ci	&sensor_dev_attr_temp1_alarm.dev_attr.attr,
12498c2ecf20Sopenharmony_ci	&sensor_dev_attr_temp2_alarm.dev_attr.attr,
12508c2ecf20Sopenharmony_ci	&sensor_dev_attr_temp3_alarm.dev_attr.attr,
12518c2ecf20Sopenharmony_ci	&sensor_dev_attr_pwm1.dev_attr.attr,
12528c2ecf20Sopenharmony_ci	&sensor_dev_attr_pwm1_mode.dev_attr.attr,
12538c2ecf20Sopenharmony_ci	&sensor_dev_attr_pwm1_enable.dev_attr.attr,
12548c2ecf20Sopenharmony_ci	&sensor_dev_attr_pwm2.dev_attr.attr,
12558c2ecf20Sopenharmony_ci	&sensor_dev_attr_pwm2_mode.dev_attr.attr,
12568c2ecf20Sopenharmony_ci	&sensor_dev_attr_pwm2_enable.dev_attr.attr,
12578c2ecf20Sopenharmony_ci	&sensor_dev_attr_pwm3.dev_attr.attr,
12588c2ecf20Sopenharmony_ci	&sensor_dev_attr_pwm3_mode.dev_attr.attr,
12598c2ecf20Sopenharmony_ci	&sensor_dev_attr_pwm3_enable.dev_attr.attr,
12608c2ecf20Sopenharmony_ci	&dev_attr_alarms.attr,
12618c2ecf20Sopenharmony_ci	&dev_attr_intrusion0_alarm.attr,
12628c2ecf20Sopenharmony_ci	&sensor_dev_attr_tolerance1.dev_attr.attr,
12638c2ecf20Sopenharmony_ci	&sensor_dev_attr_thermal_cruise1.dev_attr.attr,
12648c2ecf20Sopenharmony_ci	&sensor_dev_attr_tolerance2.dev_attr.attr,
12658c2ecf20Sopenharmony_ci	&sensor_dev_attr_thermal_cruise2.dev_attr.attr,
12668c2ecf20Sopenharmony_ci	&sensor_dev_attr_tolerance3.dev_attr.attr,
12678c2ecf20Sopenharmony_ci	&sensor_dev_attr_thermal_cruise3.dev_attr.attr,
12688c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_point1_fan1.dev_attr.attr,
12698c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_point2_fan1.dev_attr.attr,
12708c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_point3_fan1.dev_attr.attr,
12718c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_point4_fan1.dev_attr.attr,
12728c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_point1_fan2.dev_attr.attr,
12738c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_point2_fan2.dev_attr.attr,
12748c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_point3_fan2.dev_attr.attr,
12758c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_point4_fan2.dev_attr.attr,
12768c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_point1_fan3.dev_attr.attr,
12778c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_point2_fan3.dev_attr.attr,
12788c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_point3_fan3.dev_attr.attr,
12798c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_point4_fan3.dev_attr.attr,
12808c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_level1_fan1.dev_attr.attr,
12818c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_level2_fan1.dev_attr.attr,
12828c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_level3_fan1.dev_attr.attr,
12838c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_level1_fan2.dev_attr.attr,
12848c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_level2_fan2.dev_attr.attr,
12858c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_level3_fan2.dev_attr.attr,
12868c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_level1_fan3.dev_attr.attr,
12878c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_level2_fan3.dev_attr.attr,
12888c2ecf20Sopenharmony_ci	&sensor_dev_attr_sf2_level3_fan3.dev_attr.attr,
12898c2ecf20Sopenharmony_ci	&sensor_dev_attr_fan1_input.dev_attr.attr,
12908c2ecf20Sopenharmony_ci	&sensor_dev_attr_fan1_min.dev_attr.attr,
12918c2ecf20Sopenharmony_ci	&sensor_dev_attr_fan1_div.dev_attr.attr,
12928c2ecf20Sopenharmony_ci	&sensor_dev_attr_fan1_alarm.dev_attr.attr,
12938c2ecf20Sopenharmony_ci	&sensor_dev_attr_fan2_input.dev_attr.attr,
12948c2ecf20Sopenharmony_ci	&sensor_dev_attr_fan2_min.dev_attr.attr,
12958c2ecf20Sopenharmony_ci	&sensor_dev_attr_fan2_div.dev_attr.attr,
12968c2ecf20Sopenharmony_ci	&sensor_dev_attr_fan2_alarm.dev_attr.attr,
12978c2ecf20Sopenharmony_ci	&sensor_dev_attr_fan3_input.dev_attr.attr,
12988c2ecf20Sopenharmony_ci	&sensor_dev_attr_fan3_min.dev_attr.attr,
12998c2ecf20Sopenharmony_ci	&sensor_dev_attr_fan3_div.dev_attr.attr,
13008c2ecf20Sopenharmony_ci	&sensor_dev_attr_fan3_alarm.dev_attr.attr,
13018c2ecf20Sopenharmony_ci	NULL
13028c2ecf20Sopenharmony_ci};
13038c2ecf20Sopenharmony_ci
13048c2ecf20Sopenharmony_cistatic const struct attribute_group w83792d_group = {
13058c2ecf20Sopenharmony_ci	.attrs = w83792d_attributes,
13068c2ecf20Sopenharmony_ci};
13078c2ecf20Sopenharmony_ci
13088c2ecf20Sopenharmony_ci/* Return 0 if detection is successful, -ENODEV otherwise */
13098c2ecf20Sopenharmony_cistatic int
13108c2ecf20Sopenharmony_ciw83792d_detect(struct i2c_client *client, struct i2c_board_info *info)
13118c2ecf20Sopenharmony_ci{
13128c2ecf20Sopenharmony_ci	struct i2c_adapter *adapter = client->adapter;
13138c2ecf20Sopenharmony_ci	int val1, val2;
13148c2ecf20Sopenharmony_ci	unsigned short address = client->addr;
13158c2ecf20Sopenharmony_ci
13168c2ecf20Sopenharmony_ci	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
13178c2ecf20Sopenharmony_ci		return -ENODEV;
13188c2ecf20Sopenharmony_ci
13198c2ecf20Sopenharmony_ci	if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80)
13208c2ecf20Sopenharmony_ci		return -ENODEV;
13218c2ecf20Sopenharmony_ci
13228c2ecf20Sopenharmony_ci	val1 = w83792d_read_value(client, W83792D_REG_BANK);
13238c2ecf20Sopenharmony_ci	val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN);
13248c2ecf20Sopenharmony_ci	/* Check for Winbond ID if in bank 0 */
13258c2ecf20Sopenharmony_ci	if (!(val1 & 0x07)) {  /* is Bank0 */
13268c2ecf20Sopenharmony_ci		if ((!(val1 & 0x80) && val2 != 0xa3) ||
13278c2ecf20Sopenharmony_ci		    ((val1 & 0x80) && val2 != 0x5c))
13288c2ecf20Sopenharmony_ci			return -ENODEV;
13298c2ecf20Sopenharmony_ci	}
13308c2ecf20Sopenharmony_ci	/*
13318c2ecf20Sopenharmony_ci	 * If Winbond chip, address of chip and W83792D_REG_I2C_ADDR
13328c2ecf20Sopenharmony_ci	 * should match
13338c2ecf20Sopenharmony_ci	 */
13348c2ecf20Sopenharmony_ci	if (w83792d_read_value(client, W83792D_REG_I2C_ADDR) != address)
13358c2ecf20Sopenharmony_ci		return -ENODEV;
13368c2ecf20Sopenharmony_ci
13378c2ecf20Sopenharmony_ci	/*  Put it now into bank 0 and Vendor ID High Byte */
13388c2ecf20Sopenharmony_ci	w83792d_write_value(client,
13398c2ecf20Sopenharmony_ci			    W83792D_REG_BANK,
13408c2ecf20Sopenharmony_ci			    (w83792d_read_value(client,
13418c2ecf20Sopenharmony_ci				W83792D_REG_BANK) & 0x78) | 0x80);
13428c2ecf20Sopenharmony_ci
13438c2ecf20Sopenharmony_ci	/* Determine the chip type. */
13448c2ecf20Sopenharmony_ci	val1 = w83792d_read_value(client, W83792D_REG_WCHIPID);
13458c2ecf20Sopenharmony_ci	val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN);
13468c2ecf20Sopenharmony_ci	if (val1 != 0x7a || val2 != 0x5c)
13478c2ecf20Sopenharmony_ci		return -ENODEV;
13488c2ecf20Sopenharmony_ci
13498c2ecf20Sopenharmony_ci	strlcpy(info->type, "w83792d", I2C_NAME_SIZE);
13508c2ecf20Sopenharmony_ci
13518c2ecf20Sopenharmony_ci	return 0;
13528c2ecf20Sopenharmony_ci}
13538c2ecf20Sopenharmony_ci
13548c2ecf20Sopenharmony_cistatic int
13558c2ecf20Sopenharmony_ciw83792d_probe(struct i2c_client *client)
13568c2ecf20Sopenharmony_ci{
13578c2ecf20Sopenharmony_ci	struct w83792d_data *data;
13588c2ecf20Sopenharmony_ci	struct device *dev = &client->dev;
13598c2ecf20Sopenharmony_ci	int i, val1, err;
13608c2ecf20Sopenharmony_ci
13618c2ecf20Sopenharmony_ci	data = devm_kzalloc(dev, sizeof(struct w83792d_data), GFP_KERNEL);
13628c2ecf20Sopenharmony_ci	if (!data)
13638c2ecf20Sopenharmony_ci		return -ENOMEM;
13648c2ecf20Sopenharmony_ci
13658c2ecf20Sopenharmony_ci	i2c_set_clientdata(client, data);
13668c2ecf20Sopenharmony_ci	mutex_init(&data->update_lock);
13678c2ecf20Sopenharmony_ci
13688c2ecf20Sopenharmony_ci	err = w83792d_detect_subclients(client);
13698c2ecf20Sopenharmony_ci	if (err)
13708c2ecf20Sopenharmony_ci		return err;
13718c2ecf20Sopenharmony_ci
13728c2ecf20Sopenharmony_ci	/* Initialize the chip */
13738c2ecf20Sopenharmony_ci	w83792d_init_client(client);
13748c2ecf20Sopenharmony_ci
13758c2ecf20Sopenharmony_ci	/* A few vars need to be filled upon startup */
13768c2ecf20Sopenharmony_ci	for (i = 0; i < 7; i++) {
13778c2ecf20Sopenharmony_ci		data->fan_min[i] = w83792d_read_value(client,
13788c2ecf20Sopenharmony_ci					W83792D_REG_FAN_MIN[i]);
13798c2ecf20Sopenharmony_ci	}
13808c2ecf20Sopenharmony_ci
13818c2ecf20Sopenharmony_ci	/* Register sysfs hooks */
13828c2ecf20Sopenharmony_ci	err = sysfs_create_group(&dev->kobj, &w83792d_group);
13838c2ecf20Sopenharmony_ci	if (err)
13848c2ecf20Sopenharmony_ci		return err;
13858c2ecf20Sopenharmony_ci
13868c2ecf20Sopenharmony_ci	/*
13878c2ecf20Sopenharmony_ci	 * Read GPIO enable register to check if pins for fan 4,5 are used as
13888c2ecf20Sopenharmony_ci	 * GPIO
13898c2ecf20Sopenharmony_ci	 */
13908c2ecf20Sopenharmony_ci	val1 = w83792d_read_value(client, W83792D_REG_GPIO_EN);
13918c2ecf20Sopenharmony_ci
13928c2ecf20Sopenharmony_ci	if (!(val1 & 0x40)) {
13938c2ecf20Sopenharmony_ci		err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[0]);
13948c2ecf20Sopenharmony_ci		if (err)
13958c2ecf20Sopenharmony_ci			goto exit_remove_files;
13968c2ecf20Sopenharmony_ci	}
13978c2ecf20Sopenharmony_ci
13988c2ecf20Sopenharmony_ci	if (!(val1 & 0x20)) {
13998c2ecf20Sopenharmony_ci		err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[1]);
14008c2ecf20Sopenharmony_ci		if (err)
14018c2ecf20Sopenharmony_ci			goto exit_remove_files;
14028c2ecf20Sopenharmony_ci	}
14038c2ecf20Sopenharmony_ci
14048c2ecf20Sopenharmony_ci	val1 = w83792d_read_value(client, W83792D_REG_PIN);
14058c2ecf20Sopenharmony_ci	if (val1 & 0x40) {
14068c2ecf20Sopenharmony_ci		err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[2]);
14078c2ecf20Sopenharmony_ci		if (err)
14088c2ecf20Sopenharmony_ci			goto exit_remove_files;
14098c2ecf20Sopenharmony_ci	}
14108c2ecf20Sopenharmony_ci
14118c2ecf20Sopenharmony_ci	if (val1 & 0x04) {
14128c2ecf20Sopenharmony_ci		err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[3]);
14138c2ecf20Sopenharmony_ci		if (err)
14148c2ecf20Sopenharmony_ci			goto exit_remove_files;
14158c2ecf20Sopenharmony_ci	}
14168c2ecf20Sopenharmony_ci
14178c2ecf20Sopenharmony_ci	data->hwmon_dev = hwmon_device_register(dev);
14188c2ecf20Sopenharmony_ci	if (IS_ERR(data->hwmon_dev)) {
14198c2ecf20Sopenharmony_ci		err = PTR_ERR(data->hwmon_dev);
14208c2ecf20Sopenharmony_ci		goto exit_remove_files;
14218c2ecf20Sopenharmony_ci	}
14228c2ecf20Sopenharmony_ci
14238c2ecf20Sopenharmony_ci	return 0;
14248c2ecf20Sopenharmony_ci
14258c2ecf20Sopenharmony_ciexit_remove_files:
14268c2ecf20Sopenharmony_ci	sysfs_remove_group(&dev->kobj, &w83792d_group);
14278c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++)
14288c2ecf20Sopenharmony_ci		sysfs_remove_group(&dev->kobj, &w83792d_group_fan[i]);
14298c2ecf20Sopenharmony_ci	return err;
14308c2ecf20Sopenharmony_ci}
14318c2ecf20Sopenharmony_ci
14328c2ecf20Sopenharmony_cistatic int
14338c2ecf20Sopenharmony_ciw83792d_remove(struct i2c_client *client)
14348c2ecf20Sopenharmony_ci{
14358c2ecf20Sopenharmony_ci	struct w83792d_data *data = i2c_get_clientdata(client);
14368c2ecf20Sopenharmony_ci	int i;
14378c2ecf20Sopenharmony_ci
14388c2ecf20Sopenharmony_ci	hwmon_device_unregister(data->hwmon_dev);
14398c2ecf20Sopenharmony_ci	sysfs_remove_group(&client->dev.kobj, &w83792d_group);
14408c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++)
14418c2ecf20Sopenharmony_ci		sysfs_remove_group(&client->dev.kobj,
14428c2ecf20Sopenharmony_ci				   &w83792d_group_fan[i]);
14438c2ecf20Sopenharmony_ci
14448c2ecf20Sopenharmony_ci	return 0;
14458c2ecf20Sopenharmony_ci}
14468c2ecf20Sopenharmony_ci
14478c2ecf20Sopenharmony_cistatic void
14488c2ecf20Sopenharmony_ciw83792d_init_client(struct i2c_client *client)
14498c2ecf20Sopenharmony_ci{
14508c2ecf20Sopenharmony_ci	u8 temp2_cfg, temp3_cfg, vid_in_b;
14518c2ecf20Sopenharmony_ci
14528c2ecf20Sopenharmony_ci	if (init)
14538c2ecf20Sopenharmony_ci		w83792d_write_value(client, W83792D_REG_CONFIG, 0x80);
14548c2ecf20Sopenharmony_ci
14558c2ecf20Sopenharmony_ci	/*
14568c2ecf20Sopenharmony_ci	 * Clear the bit6 of W83792D_REG_VID_IN_B(set it into 0):
14578c2ecf20Sopenharmony_ci	 * W83792D_REG_VID_IN_B bit6 = 0: the high/low limit of
14588c2ecf20Sopenharmony_ci	 * vin0/vin1 can be modified by user;
14598c2ecf20Sopenharmony_ci	 * W83792D_REG_VID_IN_B bit6 = 1: the high/low limit of
14608c2ecf20Sopenharmony_ci	 * vin0/vin1 auto-updated, can NOT be modified by user.
14618c2ecf20Sopenharmony_ci	 */
14628c2ecf20Sopenharmony_ci	vid_in_b = w83792d_read_value(client, W83792D_REG_VID_IN_B);
14638c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_VID_IN_B,
14648c2ecf20Sopenharmony_ci			    vid_in_b & 0xbf);
14658c2ecf20Sopenharmony_ci
14668c2ecf20Sopenharmony_ci	temp2_cfg = w83792d_read_value(client, W83792D_REG_TEMP2_CONFIG);
14678c2ecf20Sopenharmony_ci	temp3_cfg = w83792d_read_value(client, W83792D_REG_TEMP3_CONFIG);
14688c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_TEMP2_CONFIG,
14698c2ecf20Sopenharmony_ci				temp2_cfg & 0xe6);
14708c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_TEMP3_CONFIG,
14718c2ecf20Sopenharmony_ci				temp3_cfg & 0xe6);
14728c2ecf20Sopenharmony_ci
14738c2ecf20Sopenharmony_ci	/* Start monitoring */
14748c2ecf20Sopenharmony_ci	w83792d_write_value(client, W83792D_REG_CONFIG,
14758c2ecf20Sopenharmony_ci			    (w83792d_read_value(client,
14768c2ecf20Sopenharmony_ci						W83792D_REG_CONFIG) & 0xf7)
14778c2ecf20Sopenharmony_ci			    | 0x01);
14788c2ecf20Sopenharmony_ci}
14798c2ecf20Sopenharmony_ci
14808c2ecf20Sopenharmony_cistatic struct w83792d_data *w83792d_update_device(struct device *dev)
14818c2ecf20Sopenharmony_ci{
14828c2ecf20Sopenharmony_ci	struct i2c_client *client = to_i2c_client(dev);
14838c2ecf20Sopenharmony_ci	struct w83792d_data *data = i2c_get_clientdata(client);
14848c2ecf20Sopenharmony_ci	int i, j;
14858c2ecf20Sopenharmony_ci	u8 reg_array_tmp[4], reg_tmp;
14868c2ecf20Sopenharmony_ci
14878c2ecf20Sopenharmony_ci	mutex_lock(&data->update_lock);
14888c2ecf20Sopenharmony_ci
14898c2ecf20Sopenharmony_ci	if (time_after
14908c2ecf20Sopenharmony_ci	    (jiffies - data->last_updated, (unsigned long) (HZ * 3))
14918c2ecf20Sopenharmony_ci	    || time_before(jiffies, data->last_updated) || !data->valid) {
14928c2ecf20Sopenharmony_ci		dev_dbg(dev, "Starting device update\n");
14938c2ecf20Sopenharmony_ci
14948c2ecf20Sopenharmony_ci		/* Update the voltages measured value and limits */
14958c2ecf20Sopenharmony_ci		for (i = 0; i < 9; i++) {
14968c2ecf20Sopenharmony_ci			data->in[i] = w83792d_read_value(client,
14978c2ecf20Sopenharmony_ci						W83792D_REG_IN[i]);
14988c2ecf20Sopenharmony_ci			data->in_max[i] = w83792d_read_value(client,
14998c2ecf20Sopenharmony_ci						W83792D_REG_IN_MAX[i]);
15008c2ecf20Sopenharmony_ci			data->in_min[i] = w83792d_read_value(client,
15018c2ecf20Sopenharmony_ci						W83792D_REG_IN_MIN[i]);
15028c2ecf20Sopenharmony_ci		}
15038c2ecf20Sopenharmony_ci		data->low_bits = w83792d_read_value(client,
15048c2ecf20Sopenharmony_ci						W83792D_REG_LOW_BITS1) +
15058c2ecf20Sopenharmony_ci				 (w83792d_read_value(client,
15068c2ecf20Sopenharmony_ci						W83792D_REG_LOW_BITS2) << 8);
15078c2ecf20Sopenharmony_ci		for (i = 0; i < 7; i++) {
15088c2ecf20Sopenharmony_ci			/* Update the Fan measured value and limits */
15098c2ecf20Sopenharmony_ci			data->fan[i] = w83792d_read_value(client,
15108c2ecf20Sopenharmony_ci						W83792D_REG_FAN[i]);
15118c2ecf20Sopenharmony_ci			data->fan_min[i] = w83792d_read_value(client,
15128c2ecf20Sopenharmony_ci						W83792D_REG_FAN_MIN[i]);
15138c2ecf20Sopenharmony_ci			/* Update the PWM/DC Value and PWM/DC flag */
15148c2ecf20Sopenharmony_ci			data->pwm[i] = w83792d_read_value(client,
15158c2ecf20Sopenharmony_ci						W83792D_REG_PWM[i]);
15168c2ecf20Sopenharmony_ci		}
15178c2ecf20Sopenharmony_ci
15188c2ecf20Sopenharmony_ci		reg_tmp = w83792d_read_value(client, W83792D_REG_FAN_CFG);
15198c2ecf20Sopenharmony_ci		data->pwmenable[0] = reg_tmp & 0x03;
15208c2ecf20Sopenharmony_ci		data->pwmenable[1] = (reg_tmp>>2) & 0x03;
15218c2ecf20Sopenharmony_ci		data->pwmenable[2] = (reg_tmp>>4) & 0x03;
15228c2ecf20Sopenharmony_ci
15238c2ecf20Sopenharmony_ci		for (i = 0; i < 3; i++) {
15248c2ecf20Sopenharmony_ci			data->temp1[i] = w83792d_read_value(client,
15258c2ecf20Sopenharmony_ci							W83792D_REG_TEMP1[i]);
15268c2ecf20Sopenharmony_ci		}
15278c2ecf20Sopenharmony_ci		for (i = 0; i < 2; i++) {
15288c2ecf20Sopenharmony_ci			for (j = 0; j < 6; j++) {
15298c2ecf20Sopenharmony_ci				data->temp_add[i][j] = w83792d_read_value(
15308c2ecf20Sopenharmony_ci					client, W83792D_REG_TEMP_ADD[i][j]);
15318c2ecf20Sopenharmony_ci			}
15328c2ecf20Sopenharmony_ci		}
15338c2ecf20Sopenharmony_ci
15348c2ecf20Sopenharmony_ci		/* Update the Fan Divisor */
15358c2ecf20Sopenharmony_ci		for (i = 0; i < 4; i++) {
15368c2ecf20Sopenharmony_ci			reg_array_tmp[i] = w83792d_read_value(client,
15378c2ecf20Sopenharmony_ci							W83792D_REG_FAN_DIV[i]);
15388c2ecf20Sopenharmony_ci		}
15398c2ecf20Sopenharmony_ci		data->fan_div[0] = reg_array_tmp[0] & 0x07;
15408c2ecf20Sopenharmony_ci		data->fan_div[1] = (reg_array_tmp[0] >> 4) & 0x07;
15418c2ecf20Sopenharmony_ci		data->fan_div[2] = reg_array_tmp[1] & 0x07;
15428c2ecf20Sopenharmony_ci		data->fan_div[3] = (reg_array_tmp[1] >> 4) & 0x07;
15438c2ecf20Sopenharmony_ci		data->fan_div[4] = reg_array_tmp[2] & 0x07;
15448c2ecf20Sopenharmony_ci		data->fan_div[5] = (reg_array_tmp[2] >> 4) & 0x07;
15458c2ecf20Sopenharmony_ci		data->fan_div[6] = reg_array_tmp[3] & 0x07;
15468c2ecf20Sopenharmony_ci
15478c2ecf20Sopenharmony_ci		/* Update the realtime status */
15488c2ecf20Sopenharmony_ci		data->alarms = w83792d_read_value(client, W83792D_REG_ALARM1) +
15498c2ecf20Sopenharmony_ci			(w83792d_read_value(client, W83792D_REG_ALARM2) << 8) +
15508c2ecf20Sopenharmony_ci			(w83792d_read_value(client, W83792D_REG_ALARM3) << 16);
15518c2ecf20Sopenharmony_ci
15528c2ecf20Sopenharmony_ci		/* Update CaseOpen status and it's CLR_CHS. */
15538c2ecf20Sopenharmony_ci		data->chassis = (w83792d_read_value(client,
15548c2ecf20Sopenharmony_ci			W83792D_REG_CHASSIS) >> 5) & 0x01;
15558c2ecf20Sopenharmony_ci
15568c2ecf20Sopenharmony_ci		/* Update Thermal Cruise/Smart Fan I target value */
15578c2ecf20Sopenharmony_ci		for (i = 0; i < 3; i++) {
15588c2ecf20Sopenharmony_ci			data->thermal_cruise[i] =
15598c2ecf20Sopenharmony_ci				w83792d_read_value(client,
15608c2ecf20Sopenharmony_ci				W83792D_REG_THERMAL[i]) & 0x7f;
15618c2ecf20Sopenharmony_ci		}
15628c2ecf20Sopenharmony_ci
15638c2ecf20Sopenharmony_ci		/* Update Smart Fan I/II tolerance */
15648c2ecf20Sopenharmony_ci		reg_tmp = w83792d_read_value(client, W83792D_REG_TOLERANCE[0]);
15658c2ecf20Sopenharmony_ci		data->tolerance[0] = reg_tmp & 0x0f;
15668c2ecf20Sopenharmony_ci		data->tolerance[1] = (reg_tmp >> 4) & 0x0f;
15678c2ecf20Sopenharmony_ci		data->tolerance[2] = w83792d_read_value(client,
15688c2ecf20Sopenharmony_ci					W83792D_REG_TOLERANCE[2]) & 0x0f;
15698c2ecf20Sopenharmony_ci
15708c2ecf20Sopenharmony_ci		/* Update Smart Fan II temperature points */
15718c2ecf20Sopenharmony_ci		for (i = 0; i < 3; i++) {
15728c2ecf20Sopenharmony_ci			for (j = 0; j < 4; j++) {
15738c2ecf20Sopenharmony_ci				data->sf2_points[i][j]
15748c2ecf20Sopenharmony_ci				  = w83792d_read_value(client,
15758c2ecf20Sopenharmony_ci					W83792D_REG_POINTS[i][j]) & 0x7f;
15768c2ecf20Sopenharmony_ci			}
15778c2ecf20Sopenharmony_ci		}
15788c2ecf20Sopenharmony_ci
15798c2ecf20Sopenharmony_ci		/* Update Smart Fan II duty cycle levels */
15808c2ecf20Sopenharmony_ci		for (i = 0; i < 3; i++) {
15818c2ecf20Sopenharmony_ci			reg_tmp = w83792d_read_value(client,
15828c2ecf20Sopenharmony_ci						W83792D_REG_LEVELS[i][0]);
15838c2ecf20Sopenharmony_ci			data->sf2_levels[i][0] = reg_tmp & 0x0f;
15848c2ecf20Sopenharmony_ci			data->sf2_levels[i][1] = (reg_tmp >> 4) & 0x0f;
15858c2ecf20Sopenharmony_ci			reg_tmp = w83792d_read_value(client,
15868c2ecf20Sopenharmony_ci						W83792D_REG_LEVELS[i][2]);
15878c2ecf20Sopenharmony_ci			data->sf2_levels[i][2] = (reg_tmp >> 4) & 0x0f;
15888c2ecf20Sopenharmony_ci			data->sf2_levels[i][3] = reg_tmp & 0x0f;
15898c2ecf20Sopenharmony_ci		}
15908c2ecf20Sopenharmony_ci
15918c2ecf20Sopenharmony_ci		data->last_updated = jiffies;
15928c2ecf20Sopenharmony_ci		data->valid = 1;
15938c2ecf20Sopenharmony_ci	}
15948c2ecf20Sopenharmony_ci
15958c2ecf20Sopenharmony_ci	mutex_unlock(&data->update_lock);
15968c2ecf20Sopenharmony_ci
15978c2ecf20Sopenharmony_ci#ifdef DEBUG
15988c2ecf20Sopenharmony_ci	w83792d_print_debug(data, dev);
15998c2ecf20Sopenharmony_ci#endif
16008c2ecf20Sopenharmony_ci
16018c2ecf20Sopenharmony_ci	return data;
16028c2ecf20Sopenharmony_ci}
16038c2ecf20Sopenharmony_ci
16048c2ecf20Sopenharmony_ci#ifdef DEBUG
16058c2ecf20Sopenharmony_cistatic void w83792d_print_debug(struct w83792d_data *data, struct device *dev)
16068c2ecf20Sopenharmony_ci{
16078c2ecf20Sopenharmony_ci	int i = 0, j = 0;
16088c2ecf20Sopenharmony_ci	dev_dbg(dev, "==========The following is the debug message...========\n");
16098c2ecf20Sopenharmony_ci	dev_dbg(dev, "9 set of Voltages: =====>\n");
16108c2ecf20Sopenharmony_ci	for (i = 0; i < 9; i++) {
16118c2ecf20Sopenharmony_ci		dev_dbg(dev, "vin[%d] is: 0x%x\n", i, data->in[i]);
16128c2ecf20Sopenharmony_ci		dev_dbg(dev, "vin[%d] max is: 0x%x\n", i, data->in_max[i]);
16138c2ecf20Sopenharmony_ci		dev_dbg(dev, "vin[%d] min is: 0x%x\n", i, data->in_min[i]);
16148c2ecf20Sopenharmony_ci	}
16158c2ecf20Sopenharmony_ci	dev_dbg(dev, "Low Bit1 is: 0x%x\n", data->low_bits & 0xff);
16168c2ecf20Sopenharmony_ci	dev_dbg(dev, "Low Bit2 is: 0x%x\n", data->low_bits >> 8);
16178c2ecf20Sopenharmony_ci	dev_dbg(dev, "7 set of Fan Counts and Duty Cycles: =====>\n");
16188c2ecf20Sopenharmony_ci	for (i = 0; i < 7; i++) {
16198c2ecf20Sopenharmony_ci		dev_dbg(dev, "fan[%d] is: 0x%x\n", i, data->fan[i]);
16208c2ecf20Sopenharmony_ci		dev_dbg(dev, "fan[%d] min is: 0x%x\n", i, data->fan_min[i]);
16218c2ecf20Sopenharmony_ci		dev_dbg(dev, "pwm[%d]     is: 0x%x\n", i, data->pwm[i]);
16228c2ecf20Sopenharmony_ci	}
16238c2ecf20Sopenharmony_ci	dev_dbg(dev, "3 set of Temperatures: =====>\n");
16248c2ecf20Sopenharmony_ci	for (i = 0; i < 3; i++)
16258c2ecf20Sopenharmony_ci		dev_dbg(dev, "temp1[%d] is: 0x%x\n", i, data->temp1[i]);
16268c2ecf20Sopenharmony_ci
16278c2ecf20Sopenharmony_ci	for (i = 0; i < 2; i++) {
16288c2ecf20Sopenharmony_ci		for (j = 0; j < 6; j++) {
16298c2ecf20Sopenharmony_ci			dev_dbg(dev, "temp_add[%d][%d] is: 0x%x\n", i, j,
16308c2ecf20Sopenharmony_ci							data->temp_add[i][j]);
16318c2ecf20Sopenharmony_ci		}
16328c2ecf20Sopenharmony_ci	}
16338c2ecf20Sopenharmony_ci
16348c2ecf20Sopenharmony_ci	for (i = 0; i < 7; i++)
16358c2ecf20Sopenharmony_ci		dev_dbg(dev, "fan_div[%d] is: 0x%x\n", i, data->fan_div[i]);
16368c2ecf20Sopenharmony_ci
16378c2ecf20Sopenharmony_ci	dev_dbg(dev, "==========End of the debug message...================\n");
16388c2ecf20Sopenharmony_ci	dev_dbg(dev, "\n");
16398c2ecf20Sopenharmony_ci}
16408c2ecf20Sopenharmony_ci#endif
16418c2ecf20Sopenharmony_ci
16428c2ecf20Sopenharmony_cimodule_i2c_driver(w83792d_driver);
16438c2ecf20Sopenharmony_ci
16448c2ecf20Sopenharmony_ciMODULE_AUTHOR("Shane Huang (Winbond)");
16458c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("W83792AD/D driver for linux-2.6");
16468c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
1647