18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * A hwmon driver for the Analog Devices ADT7462 48c2ecf20Sopenharmony_ci * Copyright (C) 2008 IBM 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Author: Darrick J. Wong <darrick.wong@oracle.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/module.h> 108c2ecf20Sopenharmony_ci#include <linux/jiffies.h> 118c2ecf20Sopenharmony_ci#include <linux/i2c.h> 128c2ecf20Sopenharmony_ci#include <linux/hwmon.h> 138c2ecf20Sopenharmony_ci#include <linux/hwmon-sysfs.h> 148c2ecf20Sopenharmony_ci#include <linux/err.h> 158c2ecf20Sopenharmony_ci#include <linux/mutex.h> 168c2ecf20Sopenharmony_ci#include <linux/log2.h> 178c2ecf20Sopenharmony_ci#include <linux/slab.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* Addresses to scan */ 208c2ecf20Sopenharmony_cistatic const unsigned short normal_i2c[] = { 0x58, 0x5C, I2C_CLIENT_END }; 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* ADT7462 registers */ 238c2ecf20Sopenharmony_ci#define ADT7462_REG_DEVICE 0x3D 248c2ecf20Sopenharmony_ci#define ADT7462_REG_VENDOR 0x3E 258c2ecf20Sopenharmony_ci#define ADT7462_REG_REVISION 0x3F 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define ADT7462_REG_MIN_TEMP_BASE_ADDR 0x44 288c2ecf20Sopenharmony_ci#define ADT7462_REG_MIN_TEMP_MAX_ADDR 0x47 298c2ecf20Sopenharmony_ci#define ADT7462_REG_MAX_TEMP_BASE_ADDR 0x48 308c2ecf20Sopenharmony_ci#define ADT7462_REG_MAX_TEMP_MAX_ADDR 0x4B 318c2ecf20Sopenharmony_ci#define ADT7462_REG_TEMP_BASE_ADDR 0x88 328c2ecf20Sopenharmony_ci#define ADT7462_REG_TEMP_MAX_ADDR 0x8F 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define ADT7462_REG_FAN_BASE_ADDR 0x98 358c2ecf20Sopenharmony_ci#define ADT7462_REG_FAN_MAX_ADDR 0x9F 368c2ecf20Sopenharmony_ci#define ADT7462_REG_FAN2_BASE_ADDR 0xA2 378c2ecf20Sopenharmony_ci#define ADT7462_REG_FAN2_MAX_ADDR 0xA9 388c2ecf20Sopenharmony_ci#define ADT7462_REG_FAN_ENABLE 0x07 398c2ecf20Sopenharmony_ci#define ADT7462_REG_FAN_MIN_BASE_ADDR 0x78 408c2ecf20Sopenharmony_ci#define ADT7462_REG_FAN_MIN_MAX_ADDR 0x7F 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define ADT7462_REG_CFG2 0x02 438c2ecf20Sopenharmony_ci#define ADT7462_FSPD_MASK 0x20 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define ADT7462_REG_PWM_BASE_ADDR 0xAA 468c2ecf20Sopenharmony_ci#define ADT7462_REG_PWM_MAX_ADDR 0xAD 478c2ecf20Sopenharmony_ci#define ADT7462_REG_PWM_MIN_BASE_ADDR 0x28 488c2ecf20Sopenharmony_ci#define ADT7462_REG_PWM_MIN_MAX_ADDR 0x2B 498c2ecf20Sopenharmony_ci#define ADT7462_REG_PWM_MAX 0x2C 508c2ecf20Sopenharmony_ci#define ADT7462_REG_PWM_TEMP_MIN_BASE_ADDR 0x5C 518c2ecf20Sopenharmony_ci#define ADT7462_REG_PWM_TEMP_MIN_MAX_ADDR 0x5F 528c2ecf20Sopenharmony_ci#define ADT7462_REG_PWM_TEMP_RANGE_BASE_ADDR 0x60 538c2ecf20Sopenharmony_ci#define ADT7462_REG_PWM_TEMP_RANGE_MAX_ADDR 0x63 548c2ecf20Sopenharmony_ci#define ADT7462_PWM_HYST_MASK 0x0F 558c2ecf20Sopenharmony_ci#define ADT7462_PWM_RANGE_MASK 0xF0 568c2ecf20Sopenharmony_ci#define ADT7462_PWM_RANGE_SHIFT 4 578c2ecf20Sopenharmony_ci#define ADT7462_REG_PWM_CFG_BASE_ADDR 0x21 588c2ecf20Sopenharmony_ci#define ADT7462_REG_PWM_CFG_MAX_ADDR 0x24 598c2ecf20Sopenharmony_ci#define ADT7462_PWM_CHANNEL_MASK 0xE0 608c2ecf20Sopenharmony_ci#define ADT7462_PWM_CHANNEL_SHIFT 5 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci#define ADT7462_REG_PIN_CFG_BASE_ADDR 0x10 638c2ecf20Sopenharmony_ci#define ADT7462_REG_PIN_CFG_MAX_ADDR 0x13 648c2ecf20Sopenharmony_ci#define ADT7462_PIN7_INPUT 0x01 /* cfg0 */ 658c2ecf20Sopenharmony_ci#define ADT7462_DIODE3_INPUT 0x20 668c2ecf20Sopenharmony_ci#define ADT7462_DIODE1_INPUT 0x40 678c2ecf20Sopenharmony_ci#define ADT7462_VID_INPUT 0x80 688c2ecf20Sopenharmony_ci#define ADT7462_PIN22_INPUT 0x04 /* cfg1 */ 698c2ecf20Sopenharmony_ci#define ADT7462_PIN21_INPUT 0x08 708c2ecf20Sopenharmony_ci#define ADT7462_PIN19_INPUT 0x10 718c2ecf20Sopenharmony_ci#define ADT7462_PIN15_INPUT 0x20 728c2ecf20Sopenharmony_ci#define ADT7462_PIN13_INPUT 0x40 738c2ecf20Sopenharmony_ci#define ADT7462_PIN8_INPUT 0x80 748c2ecf20Sopenharmony_ci#define ADT7462_PIN23_MASK 0x03 758c2ecf20Sopenharmony_ci#define ADT7462_PIN23_SHIFT 0 768c2ecf20Sopenharmony_ci#define ADT7462_PIN26_MASK 0x0C /* cfg2 */ 778c2ecf20Sopenharmony_ci#define ADT7462_PIN26_SHIFT 2 788c2ecf20Sopenharmony_ci#define ADT7462_PIN25_MASK 0x30 798c2ecf20Sopenharmony_ci#define ADT7462_PIN25_SHIFT 4 808c2ecf20Sopenharmony_ci#define ADT7462_PIN24_MASK 0xC0 818c2ecf20Sopenharmony_ci#define ADT7462_PIN24_SHIFT 6 828c2ecf20Sopenharmony_ci#define ADT7462_PIN26_VOLT_INPUT 0x08 838c2ecf20Sopenharmony_ci#define ADT7462_PIN25_VOLT_INPUT 0x20 848c2ecf20Sopenharmony_ci#define ADT7462_PIN28_SHIFT 4 /* cfg3 */ 858c2ecf20Sopenharmony_ci#define ADT7462_PIN28_VOLT 0x5 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci#define ADT7462_REG_ALARM1 0xB8 888c2ecf20Sopenharmony_ci#define ADT7462_LT_ALARM 0x02 898c2ecf20Sopenharmony_ci#define ADT7462_R1T_ALARM 0x04 908c2ecf20Sopenharmony_ci#define ADT7462_R2T_ALARM 0x08 918c2ecf20Sopenharmony_ci#define ADT7462_R3T_ALARM 0x10 928c2ecf20Sopenharmony_ci#define ADT7462_REG_ALARM2 0xBB 938c2ecf20Sopenharmony_ci#define ADT7462_V0_ALARM 0x01 948c2ecf20Sopenharmony_ci#define ADT7462_V1_ALARM 0x02 958c2ecf20Sopenharmony_ci#define ADT7462_V2_ALARM 0x04 968c2ecf20Sopenharmony_ci#define ADT7462_V3_ALARM 0x08 978c2ecf20Sopenharmony_ci#define ADT7462_V4_ALARM 0x10 988c2ecf20Sopenharmony_ci#define ADT7462_V5_ALARM 0x20 998c2ecf20Sopenharmony_ci#define ADT7462_V6_ALARM 0x40 1008c2ecf20Sopenharmony_ci#define ADT7462_V7_ALARM 0x80 1018c2ecf20Sopenharmony_ci#define ADT7462_REG_ALARM3 0xBC 1028c2ecf20Sopenharmony_ci#define ADT7462_V8_ALARM 0x08 1038c2ecf20Sopenharmony_ci#define ADT7462_V9_ALARM 0x10 1048c2ecf20Sopenharmony_ci#define ADT7462_V10_ALARM 0x20 1058c2ecf20Sopenharmony_ci#define ADT7462_V11_ALARM 0x40 1068c2ecf20Sopenharmony_ci#define ADT7462_V12_ALARM 0x80 1078c2ecf20Sopenharmony_ci#define ADT7462_REG_ALARM4 0xBD 1088c2ecf20Sopenharmony_ci#define ADT7462_F0_ALARM 0x01 1098c2ecf20Sopenharmony_ci#define ADT7462_F1_ALARM 0x02 1108c2ecf20Sopenharmony_ci#define ADT7462_F2_ALARM 0x04 1118c2ecf20Sopenharmony_ci#define ADT7462_F3_ALARM 0x08 1128c2ecf20Sopenharmony_ci#define ADT7462_F4_ALARM 0x10 1138c2ecf20Sopenharmony_ci#define ADT7462_F5_ALARM 0x20 1148c2ecf20Sopenharmony_ci#define ADT7462_F6_ALARM 0x40 1158c2ecf20Sopenharmony_ci#define ADT7462_F7_ALARM 0x80 1168c2ecf20Sopenharmony_ci#define ADT7462_ALARM1 0x0000 1178c2ecf20Sopenharmony_ci#define ADT7462_ALARM2 0x0100 1188c2ecf20Sopenharmony_ci#define ADT7462_ALARM3 0x0200 1198c2ecf20Sopenharmony_ci#define ADT7462_ALARM4 0x0300 1208c2ecf20Sopenharmony_ci#define ADT7462_ALARM_REG_SHIFT 8 1218c2ecf20Sopenharmony_ci#define ADT7462_ALARM_FLAG_MASK 0x0F 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci#define ADT7462_TEMP_COUNT 4 1248c2ecf20Sopenharmony_ci#define ADT7462_TEMP_REG(x) (ADT7462_REG_TEMP_BASE_ADDR + ((x) * 2)) 1258c2ecf20Sopenharmony_ci#define ADT7462_TEMP_MIN_REG(x) (ADT7462_REG_MIN_TEMP_BASE_ADDR + (x)) 1268c2ecf20Sopenharmony_ci#define ADT7462_TEMP_MAX_REG(x) (ADT7462_REG_MAX_TEMP_BASE_ADDR + (x)) 1278c2ecf20Sopenharmony_ci#define TEMP_FRAC_OFFSET 6 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci#define ADT7462_FAN_COUNT 8 1308c2ecf20Sopenharmony_ci#define ADT7462_REG_FAN_MIN(x) (ADT7462_REG_FAN_MIN_BASE_ADDR + (x)) 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci#define ADT7462_PWM_COUNT 4 1338c2ecf20Sopenharmony_ci#define ADT7462_REG_PWM(x) (ADT7462_REG_PWM_BASE_ADDR + (x)) 1348c2ecf20Sopenharmony_ci#define ADT7462_REG_PWM_MIN(x) (ADT7462_REG_PWM_MIN_BASE_ADDR + (x)) 1358c2ecf20Sopenharmony_ci#define ADT7462_REG_PWM_TMIN(x) \ 1368c2ecf20Sopenharmony_ci (ADT7462_REG_PWM_TEMP_MIN_BASE_ADDR + (x)) 1378c2ecf20Sopenharmony_ci#define ADT7462_REG_PWM_TRANGE(x) \ 1388c2ecf20Sopenharmony_ci (ADT7462_REG_PWM_TEMP_RANGE_BASE_ADDR + (x)) 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci#define ADT7462_PIN_CFG_REG_COUNT 4 1418c2ecf20Sopenharmony_ci#define ADT7462_REG_PIN_CFG(x) (ADT7462_REG_PIN_CFG_BASE_ADDR + (x)) 1428c2ecf20Sopenharmony_ci#define ADT7462_REG_PWM_CFG(x) (ADT7462_REG_PWM_CFG_BASE_ADDR + (x)) 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci#define ADT7462_ALARM_REG_COUNT 4 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci/* 1478c2ecf20Sopenharmony_ci * The chip can measure 13 different voltage sources: 1488c2ecf20Sopenharmony_ci * 1498c2ecf20Sopenharmony_ci * 1. +12V1 (pin 7) 1508c2ecf20Sopenharmony_ci * 2. Vccp1/+2.5V/+1.8V/+1.5V (pin 23) 1518c2ecf20Sopenharmony_ci * 3. +12V3 (pin 22) 1528c2ecf20Sopenharmony_ci * 4. +5V (pin 21) 1538c2ecf20Sopenharmony_ci * 5. +1.25V/+0.9V (pin 19) 1548c2ecf20Sopenharmony_ci * 6. +2.5V/+1.8V (pin 15) 1558c2ecf20Sopenharmony_ci * 7. +3.3v (pin 13) 1568c2ecf20Sopenharmony_ci * 8. +12V2 (pin 8) 1578c2ecf20Sopenharmony_ci * 9. Vbatt/FSB_Vtt (pin 26) 1588c2ecf20Sopenharmony_ci * A. +3.3V/+1.2V1 (pin 25) 1598c2ecf20Sopenharmony_ci * B. Vccp2/+2.5V/+1.8V/+1.5V (pin 24) 1608c2ecf20Sopenharmony_ci * C. +1.5V ICH (only if BOTH pin 28/29 are set to +1.5V) 1618c2ecf20Sopenharmony_ci * D. +1.5V 3GPIO (only if BOTH pin 28/29 are set to +1.5V) 1628c2ecf20Sopenharmony_ci * 1638c2ecf20Sopenharmony_ci * Each of these 13 has a factor to convert raw to voltage. Even better, 1648c2ecf20Sopenharmony_ci * the pins can be connected to other sensors (tach/gpio/hot/etc), which 1658c2ecf20Sopenharmony_ci * makes the bookkeeping tricky. 1668c2ecf20Sopenharmony_ci * 1678c2ecf20Sopenharmony_ci * Some, but not all, of these voltages have low/high limits. 1688c2ecf20Sopenharmony_ci */ 1698c2ecf20Sopenharmony_ci#define ADT7462_VOLT_COUNT 13 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci#define ADT7462_VENDOR 0x41 1728c2ecf20Sopenharmony_ci#define ADT7462_DEVICE 0x62 1738c2ecf20Sopenharmony_ci/* datasheet only mentions a revision 4 */ 1748c2ecf20Sopenharmony_ci#define ADT7462_REVISION 0x04 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci/* How often do we reread sensors values? (In jiffies) */ 1778c2ecf20Sopenharmony_ci#define SENSOR_REFRESH_INTERVAL (2 * HZ) 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci/* How often do we reread sensor limit values? (In jiffies) */ 1808c2ecf20Sopenharmony_ci#define LIMIT_REFRESH_INTERVAL (60 * HZ) 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci/* datasheet says to divide this number by the fan reading to get fan rpm */ 1838c2ecf20Sopenharmony_ci#define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x)) 1848c2ecf20Sopenharmony_ci#define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM 1858c2ecf20Sopenharmony_ci#define FAN_PERIOD_INVALID 65535 1868c2ecf20Sopenharmony_ci#define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci#define MASK_AND_SHIFT(value, prefix) \ 1898c2ecf20Sopenharmony_ci (((value) & prefix##_MASK) >> prefix##_SHIFT) 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_cistruct adt7462_data { 1928c2ecf20Sopenharmony_ci struct i2c_client *client; 1938c2ecf20Sopenharmony_ci struct mutex lock; 1948c2ecf20Sopenharmony_ci char sensors_valid; 1958c2ecf20Sopenharmony_ci char limits_valid; 1968c2ecf20Sopenharmony_ci unsigned long sensors_last_updated; /* In jiffies */ 1978c2ecf20Sopenharmony_ci unsigned long limits_last_updated; /* In jiffies */ 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci u8 temp[ADT7462_TEMP_COUNT]; 2008c2ecf20Sopenharmony_ci /* bits 6-7 are quarter pieces of temp */ 2018c2ecf20Sopenharmony_ci u8 temp_frac[ADT7462_TEMP_COUNT]; 2028c2ecf20Sopenharmony_ci u8 temp_min[ADT7462_TEMP_COUNT]; 2038c2ecf20Sopenharmony_ci u8 temp_max[ADT7462_TEMP_COUNT]; 2048c2ecf20Sopenharmony_ci u16 fan[ADT7462_FAN_COUNT]; 2058c2ecf20Sopenharmony_ci u8 fan_enabled; 2068c2ecf20Sopenharmony_ci u8 fan_min[ADT7462_FAN_COUNT]; 2078c2ecf20Sopenharmony_ci u8 cfg2; 2088c2ecf20Sopenharmony_ci u8 pwm[ADT7462_PWM_COUNT]; 2098c2ecf20Sopenharmony_ci u8 pin_cfg[ADT7462_PIN_CFG_REG_COUNT]; 2108c2ecf20Sopenharmony_ci u8 voltages[ADT7462_VOLT_COUNT]; 2118c2ecf20Sopenharmony_ci u8 volt_max[ADT7462_VOLT_COUNT]; 2128c2ecf20Sopenharmony_ci u8 volt_min[ADT7462_VOLT_COUNT]; 2138c2ecf20Sopenharmony_ci u8 pwm_min[ADT7462_PWM_COUNT]; 2148c2ecf20Sopenharmony_ci u8 pwm_tmin[ADT7462_PWM_COUNT]; 2158c2ecf20Sopenharmony_ci u8 pwm_trange[ADT7462_PWM_COUNT]; 2168c2ecf20Sopenharmony_ci u8 pwm_max; /* only one per chip */ 2178c2ecf20Sopenharmony_ci u8 pwm_cfg[ADT7462_PWM_COUNT]; 2188c2ecf20Sopenharmony_ci u8 alarms[ADT7462_ALARM_REG_COUNT]; 2198c2ecf20Sopenharmony_ci}; 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci/* 2228c2ecf20Sopenharmony_ci * 16-bit registers on the ADT7462 are low-byte first. The data sheet says 2238c2ecf20Sopenharmony_ci * that the low byte must be read before the high byte. 2248c2ecf20Sopenharmony_ci */ 2258c2ecf20Sopenharmony_cistatic inline int adt7462_read_word_data(struct i2c_client *client, u8 reg) 2268c2ecf20Sopenharmony_ci{ 2278c2ecf20Sopenharmony_ci u16 foo; 2288c2ecf20Sopenharmony_ci foo = i2c_smbus_read_byte_data(client, reg); 2298c2ecf20Sopenharmony_ci foo |= ((u16)i2c_smbus_read_byte_data(client, reg + 1) << 8); 2308c2ecf20Sopenharmony_ci return foo; 2318c2ecf20Sopenharmony_ci} 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci/* For some reason these registers are not contiguous. */ 2348c2ecf20Sopenharmony_cistatic int ADT7462_REG_FAN(int fan) 2358c2ecf20Sopenharmony_ci{ 2368c2ecf20Sopenharmony_ci if (fan < 4) 2378c2ecf20Sopenharmony_ci return ADT7462_REG_FAN_BASE_ADDR + (2 * fan); 2388c2ecf20Sopenharmony_ci return ADT7462_REG_FAN2_BASE_ADDR + (2 * (fan - 4)); 2398c2ecf20Sopenharmony_ci} 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci/* Voltage registers are scattered everywhere */ 2428c2ecf20Sopenharmony_cistatic int ADT7462_REG_VOLT_MAX(struct adt7462_data *data, int which) 2438c2ecf20Sopenharmony_ci{ 2448c2ecf20Sopenharmony_ci switch (which) { 2458c2ecf20Sopenharmony_ci case 0: 2468c2ecf20Sopenharmony_ci if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT)) 2478c2ecf20Sopenharmony_ci return 0x7C; 2488c2ecf20Sopenharmony_ci break; 2498c2ecf20Sopenharmony_ci case 1: 2508c2ecf20Sopenharmony_ci return 0x69; 2518c2ecf20Sopenharmony_ci case 2: 2528c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT)) 2538c2ecf20Sopenharmony_ci return 0x7F; 2548c2ecf20Sopenharmony_ci break; 2558c2ecf20Sopenharmony_ci case 3: 2568c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT)) 2578c2ecf20Sopenharmony_ci return 0x7E; 2588c2ecf20Sopenharmony_ci break; 2598c2ecf20Sopenharmony_ci case 4: 2608c2ecf20Sopenharmony_ci if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT)) 2618c2ecf20Sopenharmony_ci return 0x4B; 2628c2ecf20Sopenharmony_ci break; 2638c2ecf20Sopenharmony_ci case 5: 2648c2ecf20Sopenharmony_ci if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT)) 2658c2ecf20Sopenharmony_ci return 0x49; 2668c2ecf20Sopenharmony_ci break; 2678c2ecf20Sopenharmony_ci case 6: 2688c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT)) 2698c2ecf20Sopenharmony_ci return 0x68; 2708c2ecf20Sopenharmony_ci break; 2718c2ecf20Sopenharmony_ci case 7: 2728c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT)) 2738c2ecf20Sopenharmony_ci return 0x7D; 2748c2ecf20Sopenharmony_ci break; 2758c2ecf20Sopenharmony_ci case 8: 2768c2ecf20Sopenharmony_ci if (!(data->pin_cfg[2] & ADT7462_PIN26_VOLT_INPUT)) 2778c2ecf20Sopenharmony_ci return 0x6C; 2788c2ecf20Sopenharmony_ci break; 2798c2ecf20Sopenharmony_ci case 9: 2808c2ecf20Sopenharmony_ci if (!(data->pin_cfg[2] & ADT7462_PIN25_VOLT_INPUT)) 2818c2ecf20Sopenharmony_ci return 0x6B; 2828c2ecf20Sopenharmony_ci break; 2838c2ecf20Sopenharmony_ci case 10: 2848c2ecf20Sopenharmony_ci return 0x6A; 2858c2ecf20Sopenharmony_ci case 11: 2868c2ecf20Sopenharmony_ci if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == 2878c2ecf20Sopenharmony_ci ADT7462_PIN28_VOLT && 2888c2ecf20Sopenharmony_ci !(data->pin_cfg[0] & ADT7462_VID_INPUT)) 2898c2ecf20Sopenharmony_ci return 0x50; 2908c2ecf20Sopenharmony_ci break; 2918c2ecf20Sopenharmony_ci case 12: 2928c2ecf20Sopenharmony_ci if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == 2938c2ecf20Sopenharmony_ci ADT7462_PIN28_VOLT && 2948c2ecf20Sopenharmony_ci !(data->pin_cfg[0] & ADT7462_VID_INPUT)) 2958c2ecf20Sopenharmony_ci return 0x4C; 2968c2ecf20Sopenharmony_ci break; 2978c2ecf20Sopenharmony_ci } 2988c2ecf20Sopenharmony_ci return 0; 2998c2ecf20Sopenharmony_ci} 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_cistatic int ADT7462_REG_VOLT_MIN(struct adt7462_data *data, int which) 3028c2ecf20Sopenharmony_ci{ 3038c2ecf20Sopenharmony_ci switch (which) { 3048c2ecf20Sopenharmony_ci case 0: 3058c2ecf20Sopenharmony_ci if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT)) 3068c2ecf20Sopenharmony_ci return 0x6D; 3078c2ecf20Sopenharmony_ci break; 3088c2ecf20Sopenharmony_ci case 1: 3098c2ecf20Sopenharmony_ci return 0x72; 3108c2ecf20Sopenharmony_ci case 2: 3118c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT)) 3128c2ecf20Sopenharmony_ci return 0x6F; 3138c2ecf20Sopenharmony_ci break; 3148c2ecf20Sopenharmony_ci case 3: 3158c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT)) 3168c2ecf20Sopenharmony_ci return 0x71; 3178c2ecf20Sopenharmony_ci break; 3188c2ecf20Sopenharmony_ci case 4: 3198c2ecf20Sopenharmony_ci if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT)) 3208c2ecf20Sopenharmony_ci return 0x47; 3218c2ecf20Sopenharmony_ci break; 3228c2ecf20Sopenharmony_ci case 5: 3238c2ecf20Sopenharmony_ci if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT)) 3248c2ecf20Sopenharmony_ci return 0x45; 3258c2ecf20Sopenharmony_ci break; 3268c2ecf20Sopenharmony_ci case 6: 3278c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT)) 3288c2ecf20Sopenharmony_ci return 0x70; 3298c2ecf20Sopenharmony_ci break; 3308c2ecf20Sopenharmony_ci case 7: 3318c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT)) 3328c2ecf20Sopenharmony_ci return 0x6E; 3338c2ecf20Sopenharmony_ci break; 3348c2ecf20Sopenharmony_ci case 8: 3358c2ecf20Sopenharmony_ci if (!(data->pin_cfg[2] & ADT7462_PIN26_VOLT_INPUT)) 3368c2ecf20Sopenharmony_ci return 0x75; 3378c2ecf20Sopenharmony_ci break; 3388c2ecf20Sopenharmony_ci case 9: 3398c2ecf20Sopenharmony_ci if (!(data->pin_cfg[2] & ADT7462_PIN25_VOLT_INPUT)) 3408c2ecf20Sopenharmony_ci return 0x74; 3418c2ecf20Sopenharmony_ci break; 3428c2ecf20Sopenharmony_ci case 10: 3438c2ecf20Sopenharmony_ci return 0x73; 3448c2ecf20Sopenharmony_ci case 11: 3458c2ecf20Sopenharmony_ci if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == 3468c2ecf20Sopenharmony_ci ADT7462_PIN28_VOLT && 3478c2ecf20Sopenharmony_ci !(data->pin_cfg[0] & ADT7462_VID_INPUT)) 3488c2ecf20Sopenharmony_ci return 0x76; 3498c2ecf20Sopenharmony_ci break; 3508c2ecf20Sopenharmony_ci case 12: 3518c2ecf20Sopenharmony_ci if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == 3528c2ecf20Sopenharmony_ci ADT7462_PIN28_VOLT && 3538c2ecf20Sopenharmony_ci !(data->pin_cfg[0] & ADT7462_VID_INPUT)) 3548c2ecf20Sopenharmony_ci return 0x77; 3558c2ecf20Sopenharmony_ci break; 3568c2ecf20Sopenharmony_ci } 3578c2ecf20Sopenharmony_ci return 0; 3588c2ecf20Sopenharmony_ci} 3598c2ecf20Sopenharmony_ci 3608c2ecf20Sopenharmony_cistatic int ADT7462_REG_VOLT(struct adt7462_data *data, int which) 3618c2ecf20Sopenharmony_ci{ 3628c2ecf20Sopenharmony_ci switch (which) { 3638c2ecf20Sopenharmony_ci case 0: 3648c2ecf20Sopenharmony_ci if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT)) 3658c2ecf20Sopenharmony_ci return 0xA3; 3668c2ecf20Sopenharmony_ci break; 3678c2ecf20Sopenharmony_ci case 1: 3688c2ecf20Sopenharmony_ci return 0x90; 3698c2ecf20Sopenharmony_ci case 2: 3708c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT)) 3718c2ecf20Sopenharmony_ci return 0xA9; 3728c2ecf20Sopenharmony_ci break; 3738c2ecf20Sopenharmony_ci case 3: 3748c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT)) 3758c2ecf20Sopenharmony_ci return 0xA7; 3768c2ecf20Sopenharmony_ci break; 3778c2ecf20Sopenharmony_ci case 4: 3788c2ecf20Sopenharmony_ci if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT)) 3798c2ecf20Sopenharmony_ci return 0x8F; 3808c2ecf20Sopenharmony_ci break; 3818c2ecf20Sopenharmony_ci case 5: 3828c2ecf20Sopenharmony_ci if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT)) 3838c2ecf20Sopenharmony_ci return 0x8B; 3848c2ecf20Sopenharmony_ci break; 3858c2ecf20Sopenharmony_ci case 6: 3868c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT)) 3878c2ecf20Sopenharmony_ci return 0x96; 3888c2ecf20Sopenharmony_ci break; 3898c2ecf20Sopenharmony_ci case 7: 3908c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT)) 3918c2ecf20Sopenharmony_ci return 0xA5; 3928c2ecf20Sopenharmony_ci break; 3938c2ecf20Sopenharmony_ci case 8: 3948c2ecf20Sopenharmony_ci if (!(data->pin_cfg[2] & ADT7462_PIN26_VOLT_INPUT)) 3958c2ecf20Sopenharmony_ci return 0x93; 3968c2ecf20Sopenharmony_ci break; 3978c2ecf20Sopenharmony_ci case 9: 3988c2ecf20Sopenharmony_ci if (!(data->pin_cfg[2] & ADT7462_PIN25_VOLT_INPUT)) 3998c2ecf20Sopenharmony_ci return 0x92; 4008c2ecf20Sopenharmony_ci break; 4018c2ecf20Sopenharmony_ci case 10: 4028c2ecf20Sopenharmony_ci return 0x91; 4038c2ecf20Sopenharmony_ci case 11: 4048c2ecf20Sopenharmony_ci if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == 4058c2ecf20Sopenharmony_ci ADT7462_PIN28_VOLT && 4068c2ecf20Sopenharmony_ci !(data->pin_cfg[0] & ADT7462_VID_INPUT)) 4078c2ecf20Sopenharmony_ci return 0x94; 4088c2ecf20Sopenharmony_ci break; 4098c2ecf20Sopenharmony_ci case 12: 4108c2ecf20Sopenharmony_ci if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == 4118c2ecf20Sopenharmony_ci ADT7462_PIN28_VOLT && 4128c2ecf20Sopenharmony_ci !(data->pin_cfg[0] & ADT7462_VID_INPUT)) 4138c2ecf20Sopenharmony_ci return 0x95; 4148c2ecf20Sopenharmony_ci break; 4158c2ecf20Sopenharmony_ci } 4168c2ecf20Sopenharmony_ci return 0; 4178c2ecf20Sopenharmony_ci} 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci/* Provide labels for sysfs */ 4208c2ecf20Sopenharmony_cistatic const char *voltage_label(struct adt7462_data *data, int which) 4218c2ecf20Sopenharmony_ci{ 4228c2ecf20Sopenharmony_ci switch (which) { 4238c2ecf20Sopenharmony_ci case 0: 4248c2ecf20Sopenharmony_ci if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT)) 4258c2ecf20Sopenharmony_ci return "+12V1"; 4268c2ecf20Sopenharmony_ci break; 4278c2ecf20Sopenharmony_ci case 1: 4288c2ecf20Sopenharmony_ci switch (MASK_AND_SHIFT(data->pin_cfg[1], ADT7462_PIN23)) { 4298c2ecf20Sopenharmony_ci case 0: 4308c2ecf20Sopenharmony_ci return "Vccp1"; 4318c2ecf20Sopenharmony_ci case 1: 4328c2ecf20Sopenharmony_ci return "+2.5V"; 4338c2ecf20Sopenharmony_ci case 2: 4348c2ecf20Sopenharmony_ci return "+1.8V"; 4358c2ecf20Sopenharmony_ci case 3: 4368c2ecf20Sopenharmony_ci return "+1.5V"; 4378c2ecf20Sopenharmony_ci } 4388c2ecf20Sopenharmony_ci fallthrough; 4398c2ecf20Sopenharmony_ci case 2: 4408c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT)) 4418c2ecf20Sopenharmony_ci return "+12V3"; 4428c2ecf20Sopenharmony_ci break; 4438c2ecf20Sopenharmony_ci case 3: 4448c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT)) 4458c2ecf20Sopenharmony_ci return "+5V"; 4468c2ecf20Sopenharmony_ci break; 4478c2ecf20Sopenharmony_ci case 4: 4488c2ecf20Sopenharmony_ci if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT)) { 4498c2ecf20Sopenharmony_ci if (data->pin_cfg[1] & ADT7462_PIN19_INPUT) 4508c2ecf20Sopenharmony_ci return "+0.9V"; 4518c2ecf20Sopenharmony_ci return "+1.25V"; 4528c2ecf20Sopenharmony_ci } 4538c2ecf20Sopenharmony_ci break; 4548c2ecf20Sopenharmony_ci case 5: 4558c2ecf20Sopenharmony_ci if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT)) { 4568c2ecf20Sopenharmony_ci if (data->pin_cfg[1] & ADT7462_PIN19_INPUT) 4578c2ecf20Sopenharmony_ci return "+1.8V"; 4588c2ecf20Sopenharmony_ci return "+2.5V"; 4598c2ecf20Sopenharmony_ci } 4608c2ecf20Sopenharmony_ci break; 4618c2ecf20Sopenharmony_ci case 6: 4628c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT)) 4638c2ecf20Sopenharmony_ci return "+3.3V"; 4648c2ecf20Sopenharmony_ci break; 4658c2ecf20Sopenharmony_ci case 7: 4668c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT)) 4678c2ecf20Sopenharmony_ci return "+12V2"; 4688c2ecf20Sopenharmony_ci break; 4698c2ecf20Sopenharmony_ci case 8: 4708c2ecf20Sopenharmony_ci switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN26)) { 4718c2ecf20Sopenharmony_ci case 0: 4728c2ecf20Sopenharmony_ci return "Vbatt"; 4738c2ecf20Sopenharmony_ci case 1: 4748c2ecf20Sopenharmony_ci return "FSB_Vtt"; 4758c2ecf20Sopenharmony_ci } 4768c2ecf20Sopenharmony_ci break; 4778c2ecf20Sopenharmony_ci case 9: 4788c2ecf20Sopenharmony_ci switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN25)) { 4798c2ecf20Sopenharmony_ci case 0: 4808c2ecf20Sopenharmony_ci return "+3.3V"; 4818c2ecf20Sopenharmony_ci case 1: 4828c2ecf20Sopenharmony_ci return "+1.2V1"; 4838c2ecf20Sopenharmony_ci } 4848c2ecf20Sopenharmony_ci break; 4858c2ecf20Sopenharmony_ci case 10: 4868c2ecf20Sopenharmony_ci switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN24)) { 4878c2ecf20Sopenharmony_ci case 0: 4888c2ecf20Sopenharmony_ci return "Vccp2"; 4898c2ecf20Sopenharmony_ci case 1: 4908c2ecf20Sopenharmony_ci return "+2.5V"; 4918c2ecf20Sopenharmony_ci case 2: 4928c2ecf20Sopenharmony_ci return "+1.8V"; 4938c2ecf20Sopenharmony_ci case 3: 4948c2ecf20Sopenharmony_ci return "+1.5"; 4958c2ecf20Sopenharmony_ci } 4968c2ecf20Sopenharmony_ci fallthrough; 4978c2ecf20Sopenharmony_ci case 11: 4988c2ecf20Sopenharmony_ci if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == 4998c2ecf20Sopenharmony_ci ADT7462_PIN28_VOLT && 5008c2ecf20Sopenharmony_ci !(data->pin_cfg[0] & ADT7462_VID_INPUT)) 5018c2ecf20Sopenharmony_ci return "+1.5V ICH"; 5028c2ecf20Sopenharmony_ci break; 5038c2ecf20Sopenharmony_ci case 12: 5048c2ecf20Sopenharmony_ci if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == 5058c2ecf20Sopenharmony_ci ADT7462_PIN28_VOLT && 5068c2ecf20Sopenharmony_ci !(data->pin_cfg[0] & ADT7462_VID_INPUT)) 5078c2ecf20Sopenharmony_ci return "+1.5V 3GPIO"; 5088c2ecf20Sopenharmony_ci break; 5098c2ecf20Sopenharmony_ci } 5108c2ecf20Sopenharmony_ci return "N/A"; 5118c2ecf20Sopenharmony_ci} 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ci/* Multipliers are actually in uV, not mV. */ 5148c2ecf20Sopenharmony_cistatic int voltage_multiplier(struct adt7462_data *data, int which) 5158c2ecf20Sopenharmony_ci{ 5168c2ecf20Sopenharmony_ci switch (which) { 5178c2ecf20Sopenharmony_ci case 0: 5188c2ecf20Sopenharmony_ci if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT)) 5198c2ecf20Sopenharmony_ci return 62500; 5208c2ecf20Sopenharmony_ci break; 5218c2ecf20Sopenharmony_ci case 1: 5228c2ecf20Sopenharmony_ci switch (MASK_AND_SHIFT(data->pin_cfg[1], ADT7462_PIN23)) { 5238c2ecf20Sopenharmony_ci case 0: 5248c2ecf20Sopenharmony_ci if (data->pin_cfg[0] & ADT7462_VID_INPUT) 5258c2ecf20Sopenharmony_ci return 12500; 5268c2ecf20Sopenharmony_ci return 6250; 5278c2ecf20Sopenharmony_ci case 1: 5288c2ecf20Sopenharmony_ci return 13000; 5298c2ecf20Sopenharmony_ci case 2: 5308c2ecf20Sopenharmony_ci return 9400; 5318c2ecf20Sopenharmony_ci case 3: 5328c2ecf20Sopenharmony_ci return 7800; 5338c2ecf20Sopenharmony_ci } 5348c2ecf20Sopenharmony_ci fallthrough; 5358c2ecf20Sopenharmony_ci case 2: 5368c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT)) 5378c2ecf20Sopenharmony_ci return 62500; 5388c2ecf20Sopenharmony_ci break; 5398c2ecf20Sopenharmony_ci case 3: 5408c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT)) 5418c2ecf20Sopenharmony_ci return 26000; 5428c2ecf20Sopenharmony_ci break; 5438c2ecf20Sopenharmony_ci case 4: 5448c2ecf20Sopenharmony_ci if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT)) { 5458c2ecf20Sopenharmony_ci if (data->pin_cfg[1] & ADT7462_PIN19_INPUT) 5468c2ecf20Sopenharmony_ci return 4690; 5478c2ecf20Sopenharmony_ci return 6500; 5488c2ecf20Sopenharmony_ci } 5498c2ecf20Sopenharmony_ci break; 5508c2ecf20Sopenharmony_ci case 5: 5518c2ecf20Sopenharmony_ci if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT)) { 5528c2ecf20Sopenharmony_ci if (data->pin_cfg[1] & ADT7462_PIN15_INPUT) 5538c2ecf20Sopenharmony_ci return 9400; 5548c2ecf20Sopenharmony_ci return 13000; 5558c2ecf20Sopenharmony_ci } 5568c2ecf20Sopenharmony_ci break; 5578c2ecf20Sopenharmony_ci case 6: 5588c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT)) 5598c2ecf20Sopenharmony_ci return 17200; 5608c2ecf20Sopenharmony_ci break; 5618c2ecf20Sopenharmony_ci case 7: 5628c2ecf20Sopenharmony_ci if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT)) 5638c2ecf20Sopenharmony_ci return 62500; 5648c2ecf20Sopenharmony_ci break; 5658c2ecf20Sopenharmony_ci case 8: 5668c2ecf20Sopenharmony_ci switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN26)) { 5678c2ecf20Sopenharmony_ci case 0: 5688c2ecf20Sopenharmony_ci return 15600; 5698c2ecf20Sopenharmony_ci case 1: 5708c2ecf20Sopenharmony_ci return 6250; 5718c2ecf20Sopenharmony_ci } 5728c2ecf20Sopenharmony_ci break; 5738c2ecf20Sopenharmony_ci case 9: 5748c2ecf20Sopenharmony_ci switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN25)) { 5758c2ecf20Sopenharmony_ci case 0: 5768c2ecf20Sopenharmony_ci return 17200; 5778c2ecf20Sopenharmony_ci case 1: 5788c2ecf20Sopenharmony_ci return 6250; 5798c2ecf20Sopenharmony_ci } 5808c2ecf20Sopenharmony_ci break; 5818c2ecf20Sopenharmony_ci case 10: 5828c2ecf20Sopenharmony_ci switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN24)) { 5838c2ecf20Sopenharmony_ci case 0: 5848c2ecf20Sopenharmony_ci return 6250; 5858c2ecf20Sopenharmony_ci case 1: 5868c2ecf20Sopenharmony_ci return 13000; 5878c2ecf20Sopenharmony_ci case 2: 5888c2ecf20Sopenharmony_ci return 9400; 5898c2ecf20Sopenharmony_ci case 3: 5908c2ecf20Sopenharmony_ci return 7800; 5918c2ecf20Sopenharmony_ci } 5928c2ecf20Sopenharmony_ci fallthrough; 5938c2ecf20Sopenharmony_ci case 11: 5948c2ecf20Sopenharmony_ci case 12: 5958c2ecf20Sopenharmony_ci if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == 5968c2ecf20Sopenharmony_ci ADT7462_PIN28_VOLT && 5978c2ecf20Sopenharmony_ci !(data->pin_cfg[0] & ADT7462_VID_INPUT)) 5988c2ecf20Sopenharmony_ci return 7800; 5998c2ecf20Sopenharmony_ci } 6008c2ecf20Sopenharmony_ci return 0; 6018c2ecf20Sopenharmony_ci} 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_cistatic int temp_enabled(struct adt7462_data *data, int which) 6048c2ecf20Sopenharmony_ci{ 6058c2ecf20Sopenharmony_ci switch (which) { 6068c2ecf20Sopenharmony_ci case 0: 6078c2ecf20Sopenharmony_ci case 2: 6088c2ecf20Sopenharmony_ci return 1; 6098c2ecf20Sopenharmony_ci case 1: 6108c2ecf20Sopenharmony_ci if (data->pin_cfg[0] & ADT7462_DIODE1_INPUT) 6118c2ecf20Sopenharmony_ci return 1; 6128c2ecf20Sopenharmony_ci break; 6138c2ecf20Sopenharmony_ci case 3: 6148c2ecf20Sopenharmony_ci if (data->pin_cfg[0] & ADT7462_DIODE3_INPUT) 6158c2ecf20Sopenharmony_ci return 1; 6168c2ecf20Sopenharmony_ci break; 6178c2ecf20Sopenharmony_ci } 6188c2ecf20Sopenharmony_ci return 0; 6198c2ecf20Sopenharmony_ci} 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_cistatic const char *temp_label(struct adt7462_data *data, int which) 6228c2ecf20Sopenharmony_ci{ 6238c2ecf20Sopenharmony_ci switch (which) { 6248c2ecf20Sopenharmony_ci case 0: 6258c2ecf20Sopenharmony_ci return "local"; 6268c2ecf20Sopenharmony_ci case 1: 6278c2ecf20Sopenharmony_ci if (data->pin_cfg[0] & ADT7462_DIODE1_INPUT) 6288c2ecf20Sopenharmony_ci return "remote1"; 6298c2ecf20Sopenharmony_ci break; 6308c2ecf20Sopenharmony_ci case 2: 6318c2ecf20Sopenharmony_ci return "remote2"; 6328c2ecf20Sopenharmony_ci case 3: 6338c2ecf20Sopenharmony_ci if (data->pin_cfg[0] & ADT7462_DIODE3_INPUT) 6348c2ecf20Sopenharmony_ci return "remote3"; 6358c2ecf20Sopenharmony_ci break; 6368c2ecf20Sopenharmony_ci } 6378c2ecf20Sopenharmony_ci return "N/A"; 6388c2ecf20Sopenharmony_ci} 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci/* Map Trange register values to mC */ 6418c2ecf20Sopenharmony_ci#define NUM_TRANGE_VALUES 16 6428c2ecf20Sopenharmony_cistatic const int trange_values[NUM_TRANGE_VALUES] = { 6438c2ecf20Sopenharmony_ci 2000, 6448c2ecf20Sopenharmony_ci 2500, 6458c2ecf20Sopenharmony_ci 3300, 6468c2ecf20Sopenharmony_ci 4000, 6478c2ecf20Sopenharmony_ci 5000, 6488c2ecf20Sopenharmony_ci 6700, 6498c2ecf20Sopenharmony_ci 8000, 6508c2ecf20Sopenharmony_ci 10000, 6518c2ecf20Sopenharmony_ci 13300, 6528c2ecf20Sopenharmony_ci 16000, 6538c2ecf20Sopenharmony_ci 20000, 6548c2ecf20Sopenharmony_ci 26700, 6558c2ecf20Sopenharmony_ci 32000, 6568c2ecf20Sopenharmony_ci 40000, 6578c2ecf20Sopenharmony_ci 53300, 6588c2ecf20Sopenharmony_ci 80000 6598c2ecf20Sopenharmony_ci}; 6608c2ecf20Sopenharmony_ci 6618c2ecf20Sopenharmony_cistatic int find_trange_value(int trange) 6628c2ecf20Sopenharmony_ci{ 6638c2ecf20Sopenharmony_ci int i; 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci for (i = 0; i < NUM_TRANGE_VALUES; i++) 6668c2ecf20Sopenharmony_ci if (trange_values[i] == trange) 6678c2ecf20Sopenharmony_ci return i; 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_ci return -EINVAL; 6708c2ecf20Sopenharmony_ci} 6718c2ecf20Sopenharmony_ci 6728c2ecf20Sopenharmony_cistatic struct adt7462_data *adt7462_update_device(struct device *dev) 6738c2ecf20Sopenharmony_ci{ 6748c2ecf20Sopenharmony_ci struct adt7462_data *data = dev_get_drvdata(dev); 6758c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 6768c2ecf20Sopenharmony_ci unsigned long local_jiffies = jiffies; 6778c2ecf20Sopenharmony_ci int i; 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 6808c2ecf20Sopenharmony_ci if (time_before(local_jiffies, data->sensors_last_updated + 6818c2ecf20Sopenharmony_ci SENSOR_REFRESH_INTERVAL) 6828c2ecf20Sopenharmony_ci && data->sensors_valid) 6838c2ecf20Sopenharmony_ci goto no_sensor_update; 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_ci for (i = 0; i < ADT7462_TEMP_COUNT; i++) { 6868c2ecf20Sopenharmony_ci /* 6878c2ecf20Sopenharmony_ci * Reading the fractional register locks the integral 6888c2ecf20Sopenharmony_ci * register until both have been read. 6898c2ecf20Sopenharmony_ci */ 6908c2ecf20Sopenharmony_ci data->temp_frac[i] = i2c_smbus_read_byte_data(client, 6918c2ecf20Sopenharmony_ci ADT7462_TEMP_REG(i)); 6928c2ecf20Sopenharmony_ci data->temp[i] = i2c_smbus_read_byte_data(client, 6938c2ecf20Sopenharmony_ci ADT7462_TEMP_REG(i) + 1); 6948c2ecf20Sopenharmony_ci } 6958c2ecf20Sopenharmony_ci 6968c2ecf20Sopenharmony_ci for (i = 0; i < ADT7462_FAN_COUNT; i++) 6978c2ecf20Sopenharmony_ci data->fan[i] = adt7462_read_word_data(client, 6988c2ecf20Sopenharmony_ci ADT7462_REG_FAN(i)); 6998c2ecf20Sopenharmony_ci 7008c2ecf20Sopenharmony_ci data->fan_enabled = i2c_smbus_read_byte_data(client, 7018c2ecf20Sopenharmony_ci ADT7462_REG_FAN_ENABLE); 7028c2ecf20Sopenharmony_ci 7038c2ecf20Sopenharmony_ci for (i = 0; i < ADT7462_PWM_COUNT; i++) 7048c2ecf20Sopenharmony_ci data->pwm[i] = i2c_smbus_read_byte_data(client, 7058c2ecf20Sopenharmony_ci ADT7462_REG_PWM(i)); 7068c2ecf20Sopenharmony_ci 7078c2ecf20Sopenharmony_ci for (i = 0; i < ADT7462_PIN_CFG_REG_COUNT; i++) 7088c2ecf20Sopenharmony_ci data->pin_cfg[i] = i2c_smbus_read_byte_data(client, 7098c2ecf20Sopenharmony_ci ADT7462_REG_PIN_CFG(i)); 7108c2ecf20Sopenharmony_ci 7118c2ecf20Sopenharmony_ci for (i = 0; i < ADT7462_VOLT_COUNT; i++) { 7128c2ecf20Sopenharmony_ci int reg = ADT7462_REG_VOLT(data, i); 7138c2ecf20Sopenharmony_ci if (!reg) 7148c2ecf20Sopenharmony_ci data->voltages[i] = 0; 7158c2ecf20Sopenharmony_ci else 7168c2ecf20Sopenharmony_ci data->voltages[i] = i2c_smbus_read_byte_data(client, 7178c2ecf20Sopenharmony_ci reg); 7188c2ecf20Sopenharmony_ci } 7198c2ecf20Sopenharmony_ci 7208c2ecf20Sopenharmony_ci data->alarms[0] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM1); 7218c2ecf20Sopenharmony_ci data->alarms[1] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM2); 7228c2ecf20Sopenharmony_ci data->alarms[2] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM3); 7238c2ecf20Sopenharmony_ci data->alarms[3] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM4); 7248c2ecf20Sopenharmony_ci 7258c2ecf20Sopenharmony_ci data->sensors_last_updated = local_jiffies; 7268c2ecf20Sopenharmony_ci data->sensors_valid = 1; 7278c2ecf20Sopenharmony_ci 7288c2ecf20Sopenharmony_cino_sensor_update: 7298c2ecf20Sopenharmony_ci if (time_before(local_jiffies, data->limits_last_updated + 7308c2ecf20Sopenharmony_ci LIMIT_REFRESH_INTERVAL) 7318c2ecf20Sopenharmony_ci && data->limits_valid) 7328c2ecf20Sopenharmony_ci goto out; 7338c2ecf20Sopenharmony_ci 7348c2ecf20Sopenharmony_ci for (i = 0; i < ADT7462_TEMP_COUNT; i++) { 7358c2ecf20Sopenharmony_ci data->temp_min[i] = i2c_smbus_read_byte_data(client, 7368c2ecf20Sopenharmony_ci ADT7462_TEMP_MIN_REG(i)); 7378c2ecf20Sopenharmony_ci data->temp_max[i] = i2c_smbus_read_byte_data(client, 7388c2ecf20Sopenharmony_ci ADT7462_TEMP_MAX_REG(i)); 7398c2ecf20Sopenharmony_ci } 7408c2ecf20Sopenharmony_ci 7418c2ecf20Sopenharmony_ci for (i = 0; i < ADT7462_FAN_COUNT; i++) 7428c2ecf20Sopenharmony_ci data->fan_min[i] = i2c_smbus_read_byte_data(client, 7438c2ecf20Sopenharmony_ci ADT7462_REG_FAN_MIN(i)); 7448c2ecf20Sopenharmony_ci 7458c2ecf20Sopenharmony_ci for (i = 0; i < ADT7462_VOLT_COUNT; i++) { 7468c2ecf20Sopenharmony_ci int reg = ADT7462_REG_VOLT_MAX(data, i); 7478c2ecf20Sopenharmony_ci data->volt_max[i] = 7488c2ecf20Sopenharmony_ci (reg ? i2c_smbus_read_byte_data(client, reg) : 0); 7498c2ecf20Sopenharmony_ci 7508c2ecf20Sopenharmony_ci reg = ADT7462_REG_VOLT_MIN(data, i); 7518c2ecf20Sopenharmony_ci data->volt_min[i] = 7528c2ecf20Sopenharmony_ci (reg ? i2c_smbus_read_byte_data(client, reg) : 0); 7538c2ecf20Sopenharmony_ci } 7548c2ecf20Sopenharmony_ci 7558c2ecf20Sopenharmony_ci for (i = 0; i < ADT7462_PWM_COUNT; i++) { 7568c2ecf20Sopenharmony_ci data->pwm_min[i] = i2c_smbus_read_byte_data(client, 7578c2ecf20Sopenharmony_ci ADT7462_REG_PWM_MIN(i)); 7588c2ecf20Sopenharmony_ci data->pwm_tmin[i] = i2c_smbus_read_byte_data(client, 7598c2ecf20Sopenharmony_ci ADT7462_REG_PWM_TMIN(i)); 7608c2ecf20Sopenharmony_ci data->pwm_trange[i] = i2c_smbus_read_byte_data(client, 7618c2ecf20Sopenharmony_ci ADT7462_REG_PWM_TRANGE(i)); 7628c2ecf20Sopenharmony_ci data->pwm_cfg[i] = i2c_smbus_read_byte_data(client, 7638c2ecf20Sopenharmony_ci ADT7462_REG_PWM_CFG(i)); 7648c2ecf20Sopenharmony_ci } 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ci data->pwm_max = i2c_smbus_read_byte_data(client, ADT7462_REG_PWM_MAX); 7678c2ecf20Sopenharmony_ci 7688c2ecf20Sopenharmony_ci data->cfg2 = i2c_smbus_read_byte_data(client, ADT7462_REG_CFG2); 7698c2ecf20Sopenharmony_ci 7708c2ecf20Sopenharmony_ci data->limits_last_updated = local_jiffies; 7718c2ecf20Sopenharmony_ci data->limits_valid = 1; 7728c2ecf20Sopenharmony_ci 7738c2ecf20Sopenharmony_ciout: 7748c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 7758c2ecf20Sopenharmony_ci return data; 7768c2ecf20Sopenharmony_ci} 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_cistatic ssize_t temp_min_show(struct device *dev, 7798c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 7808c2ecf20Sopenharmony_ci{ 7818c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 7828c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 7838c2ecf20Sopenharmony_ci 7848c2ecf20Sopenharmony_ci if (!temp_enabled(data, attr->index)) 7858c2ecf20Sopenharmony_ci return sprintf(buf, "0\n"); 7868c2ecf20Sopenharmony_ci 7878c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", 1000 * (data->temp_min[attr->index] - 64)); 7888c2ecf20Sopenharmony_ci} 7898c2ecf20Sopenharmony_ci 7908c2ecf20Sopenharmony_cistatic ssize_t temp_min_store(struct device *dev, 7918c2ecf20Sopenharmony_ci struct device_attribute *devattr, 7928c2ecf20Sopenharmony_ci const char *buf, size_t count) 7938c2ecf20Sopenharmony_ci{ 7948c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 7958c2ecf20Sopenharmony_ci struct adt7462_data *data = dev_get_drvdata(dev); 7968c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 7978c2ecf20Sopenharmony_ci long temp; 7988c2ecf20Sopenharmony_ci 7998c2ecf20Sopenharmony_ci if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) 8008c2ecf20Sopenharmony_ci return -EINVAL; 8018c2ecf20Sopenharmony_ci 8028c2ecf20Sopenharmony_ci temp = clamp_val(temp, -64000, 191000); 8038c2ecf20Sopenharmony_ci temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; 8048c2ecf20Sopenharmony_ci 8058c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 8068c2ecf20Sopenharmony_ci data->temp_min[attr->index] = temp; 8078c2ecf20Sopenharmony_ci i2c_smbus_write_byte_data(client, ADT7462_TEMP_MIN_REG(attr->index), 8088c2ecf20Sopenharmony_ci temp); 8098c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 8108c2ecf20Sopenharmony_ci 8118c2ecf20Sopenharmony_ci return count; 8128c2ecf20Sopenharmony_ci} 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_cistatic ssize_t temp_max_show(struct device *dev, 8158c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 8168c2ecf20Sopenharmony_ci{ 8178c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 8188c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_ci if (!temp_enabled(data, attr->index)) 8218c2ecf20Sopenharmony_ci return sprintf(buf, "0\n"); 8228c2ecf20Sopenharmony_ci 8238c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", 1000 * (data->temp_max[attr->index] - 64)); 8248c2ecf20Sopenharmony_ci} 8258c2ecf20Sopenharmony_ci 8268c2ecf20Sopenharmony_cistatic ssize_t temp_max_store(struct device *dev, 8278c2ecf20Sopenharmony_ci struct device_attribute *devattr, 8288c2ecf20Sopenharmony_ci const char *buf, size_t count) 8298c2ecf20Sopenharmony_ci{ 8308c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 8318c2ecf20Sopenharmony_ci struct adt7462_data *data = dev_get_drvdata(dev); 8328c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 8338c2ecf20Sopenharmony_ci long temp; 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ci if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) 8368c2ecf20Sopenharmony_ci return -EINVAL; 8378c2ecf20Sopenharmony_ci 8388c2ecf20Sopenharmony_ci temp = clamp_val(temp, -64000, 191000); 8398c2ecf20Sopenharmony_ci temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 8428c2ecf20Sopenharmony_ci data->temp_max[attr->index] = temp; 8438c2ecf20Sopenharmony_ci i2c_smbus_write_byte_data(client, ADT7462_TEMP_MAX_REG(attr->index), 8448c2ecf20Sopenharmony_ci temp); 8458c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 8468c2ecf20Sopenharmony_ci 8478c2ecf20Sopenharmony_ci return count; 8488c2ecf20Sopenharmony_ci} 8498c2ecf20Sopenharmony_ci 8508c2ecf20Sopenharmony_cistatic ssize_t temp_show(struct device *dev, struct device_attribute *devattr, 8518c2ecf20Sopenharmony_ci char *buf) 8528c2ecf20Sopenharmony_ci{ 8538c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 8548c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 8558c2ecf20Sopenharmony_ci u8 frac = data->temp_frac[attr->index] >> TEMP_FRAC_OFFSET; 8568c2ecf20Sopenharmony_ci 8578c2ecf20Sopenharmony_ci if (!temp_enabled(data, attr->index)) 8588c2ecf20Sopenharmony_ci return sprintf(buf, "0\n"); 8598c2ecf20Sopenharmony_ci 8608c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", 1000 * (data->temp[attr->index] - 64) + 8618c2ecf20Sopenharmony_ci 250 * frac); 8628c2ecf20Sopenharmony_ci} 8638c2ecf20Sopenharmony_ci 8648c2ecf20Sopenharmony_cistatic ssize_t temp_label_show(struct device *dev, 8658c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 8668c2ecf20Sopenharmony_ci{ 8678c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 8688c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 8698c2ecf20Sopenharmony_ci 8708c2ecf20Sopenharmony_ci return sprintf(buf, "%s\n", temp_label(data, attr->index)); 8718c2ecf20Sopenharmony_ci} 8728c2ecf20Sopenharmony_ci 8738c2ecf20Sopenharmony_cistatic ssize_t volt_max_show(struct device *dev, 8748c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 8758c2ecf20Sopenharmony_ci{ 8768c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 8778c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 8788c2ecf20Sopenharmony_ci int x = voltage_multiplier(data, attr->index); 8798c2ecf20Sopenharmony_ci 8808c2ecf20Sopenharmony_ci x *= data->volt_max[attr->index]; 8818c2ecf20Sopenharmony_ci x /= 1000; /* convert from uV to mV */ 8828c2ecf20Sopenharmony_ci 8838c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", x); 8848c2ecf20Sopenharmony_ci} 8858c2ecf20Sopenharmony_ci 8868c2ecf20Sopenharmony_cistatic ssize_t volt_max_store(struct device *dev, 8878c2ecf20Sopenharmony_ci struct device_attribute *devattr, 8888c2ecf20Sopenharmony_ci const char *buf, size_t count) 8898c2ecf20Sopenharmony_ci{ 8908c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 8918c2ecf20Sopenharmony_ci struct adt7462_data *data = dev_get_drvdata(dev); 8928c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 8938c2ecf20Sopenharmony_ci int x = voltage_multiplier(data, attr->index); 8948c2ecf20Sopenharmony_ci long temp; 8958c2ecf20Sopenharmony_ci 8968c2ecf20Sopenharmony_ci if (kstrtol(buf, 10, &temp) || !x) 8978c2ecf20Sopenharmony_ci return -EINVAL; 8988c2ecf20Sopenharmony_ci 8998c2ecf20Sopenharmony_ci temp = clamp_val(temp, 0, 255 * x / 1000); 9008c2ecf20Sopenharmony_ci temp *= 1000; /* convert mV to uV */ 9018c2ecf20Sopenharmony_ci temp = DIV_ROUND_CLOSEST(temp, x); 9028c2ecf20Sopenharmony_ci 9038c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 9048c2ecf20Sopenharmony_ci data->volt_max[attr->index] = temp; 9058c2ecf20Sopenharmony_ci i2c_smbus_write_byte_data(client, 9068c2ecf20Sopenharmony_ci ADT7462_REG_VOLT_MAX(data, attr->index), 9078c2ecf20Sopenharmony_ci temp); 9088c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 9098c2ecf20Sopenharmony_ci 9108c2ecf20Sopenharmony_ci return count; 9118c2ecf20Sopenharmony_ci} 9128c2ecf20Sopenharmony_ci 9138c2ecf20Sopenharmony_cistatic ssize_t volt_min_show(struct device *dev, 9148c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 9158c2ecf20Sopenharmony_ci{ 9168c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 9178c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 9188c2ecf20Sopenharmony_ci int x = voltage_multiplier(data, attr->index); 9198c2ecf20Sopenharmony_ci 9208c2ecf20Sopenharmony_ci x *= data->volt_min[attr->index]; 9218c2ecf20Sopenharmony_ci x /= 1000; /* convert from uV to mV */ 9228c2ecf20Sopenharmony_ci 9238c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", x); 9248c2ecf20Sopenharmony_ci} 9258c2ecf20Sopenharmony_ci 9268c2ecf20Sopenharmony_cistatic ssize_t volt_min_store(struct device *dev, 9278c2ecf20Sopenharmony_ci struct device_attribute *devattr, 9288c2ecf20Sopenharmony_ci const char *buf, size_t count) 9298c2ecf20Sopenharmony_ci{ 9308c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 9318c2ecf20Sopenharmony_ci struct adt7462_data *data = dev_get_drvdata(dev); 9328c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 9338c2ecf20Sopenharmony_ci int x = voltage_multiplier(data, attr->index); 9348c2ecf20Sopenharmony_ci long temp; 9358c2ecf20Sopenharmony_ci 9368c2ecf20Sopenharmony_ci if (kstrtol(buf, 10, &temp) || !x) 9378c2ecf20Sopenharmony_ci return -EINVAL; 9388c2ecf20Sopenharmony_ci 9398c2ecf20Sopenharmony_ci temp = clamp_val(temp, 0, 255 * x / 1000); 9408c2ecf20Sopenharmony_ci temp *= 1000; /* convert mV to uV */ 9418c2ecf20Sopenharmony_ci temp = DIV_ROUND_CLOSEST(temp, x); 9428c2ecf20Sopenharmony_ci 9438c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 9448c2ecf20Sopenharmony_ci data->volt_min[attr->index] = temp; 9458c2ecf20Sopenharmony_ci i2c_smbus_write_byte_data(client, 9468c2ecf20Sopenharmony_ci ADT7462_REG_VOLT_MIN(data, attr->index), 9478c2ecf20Sopenharmony_ci temp); 9488c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 9498c2ecf20Sopenharmony_ci 9508c2ecf20Sopenharmony_ci return count; 9518c2ecf20Sopenharmony_ci} 9528c2ecf20Sopenharmony_ci 9538c2ecf20Sopenharmony_cistatic ssize_t voltage_show(struct device *dev, 9548c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 9558c2ecf20Sopenharmony_ci{ 9568c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 9578c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 9588c2ecf20Sopenharmony_ci int x = voltage_multiplier(data, attr->index); 9598c2ecf20Sopenharmony_ci 9608c2ecf20Sopenharmony_ci x *= data->voltages[attr->index]; 9618c2ecf20Sopenharmony_ci x /= 1000; /* convert from uV to mV */ 9628c2ecf20Sopenharmony_ci 9638c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", x); 9648c2ecf20Sopenharmony_ci} 9658c2ecf20Sopenharmony_ci 9668c2ecf20Sopenharmony_cistatic ssize_t voltage_label_show(struct device *dev, 9678c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 9688c2ecf20Sopenharmony_ci{ 9698c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 9708c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 9718c2ecf20Sopenharmony_ci 9728c2ecf20Sopenharmony_ci return sprintf(buf, "%s\n", voltage_label(data, attr->index)); 9738c2ecf20Sopenharmony_ci} 9748c2ecf20Sopenharmony_ci 9758c2ecf20Sopenharmony_cistatic ssize_t alarm_show(struct device *dev, 9768c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 9778c2ecf20Sopenharmony_ci{ 9788c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 9798c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 9808c2ecf20Sopenharmony_ci int reg = attr->index >> ADT7462_ALARM_REG_SHIFT; 9818c2ecf20Sopenharmony_ci int mask = attr->index & ADT7462_ALARM_FLAG_MASK; 9828c2ecf20Sopenharmony_ci 9838c2ecf20Sopenharmony_ci if (data->alarms[reg] & mask) 9848c2ecf20Sopenharmony_ci return sprintf(buf, "1\n"); 9858c2ecf20Sopenharmony_ci else 9868c2ecf20Sopenharmony_ci return sprintf(buf, "0\n"); 9878c2ecf20Sopenharmony_ci} 9888c2ecf20Sopenharmony_ci 9898c2ecf20Sopenharmony_cistatic int fan_enabled(struct adt7462_data *data, int fan) 9908c2ecf20Sopenharmony_ci{ 9918c2ecf20Sopenharmony_ci return data->fan_enabled & (1 << fan); 9928c2ecf20Sopenharmony_ci} 9938c2ecf20Sopenharmony_ci 9948c2ecf20Sopenharmony_cistatic ssize_t fan_min_show(struct device *dev, 9958c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 9968c2ecf20Sopenharmony_ci{ 9978c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 9988c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 9998c2ecf20Sopenharmony_ci u16 temp; 10008c2ecf20Sopenharmony_ci 10018c2ecf20Sopenharmony_ci /* Only the MSB of the min fan period is stored... */ 10028c2ecf20Sopenharmony_ci temp = data->fan_min[attr->index]; 10038c2ecf20Sopenharmony_ci temp <<= 8; 10048c2ecf20Sopenharmony_ci 10058c2ecf20Sopenharmony_ci if (!fan_enabled(data, attr->index) || 10068c2ecf20Sopenharmony_ci !FAN_DATA_VALID(temp)) 10078c2ecf20Sopenharmony_ci return sprintf(buf, "0\n"); 10088c2ecf20Sopenharmony_ci 10098c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", FAN_PERIOD_TO_RPM(temp)); 10108c2ecf20Sopenharmony_ci} 10118c2ecf20Sopenharmony_ci 10128c2ecf20Sopenharmony_cistatic ssize_t fan_min_store(struct device *dev, 10138c2ecf20Sopenharmony_ci struct device_attribute *devattr, 10148c2ecf20Sopenharmony_ci const char *buf, size_t count) 10158c2ecf20Sopenharmony_ci{ 10168c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 10178c2ecf20Sopenharmony_ci struct adt7462_data *data = dev_get_drvdata(dev); 10188c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 10198c2ecf20Sopenharmony_ci long temp; 10208c2ecf20Sopenharmony_ci 10218c2ecf20Sopenharmony_ci if (kstrtol(buf, 10, &temp) || !temp || 10228c2ecf20Sopenharmony_ci !fan_enabled(data, attr->index)) 10238c2ecf20Sopenharmony_ci return -EINVAL; 10248c2ecf20Sopenharmony_ci 10258c2ecf20Sopenharmony_ci temp = FAN_RPM_TO_PERIOD(temp); 10268c2ecf20Sopenharmony_ci temp >>= 8; 10278c2ecf20Sopenharmony_ci temp = clamp_val(temp, 1, 255); 10288c2ecf20Sopenharmony_ci 10298c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 10308c2ecf20Sopenharmony_ci data->fan_min[attr->index] = temp; 10318c2ecf20Sopenharmony_ci i2c_smbus_write_byte_data(client, ADT7462_REG_FAN_MIN(attr->index), 10328c2ecf20Sopenharmony_ci temp); 10338c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 10348c2ecf20Sopenharmony_ci 10358c2ecf20Sopenharmony_ci return count; 10368c2ecf20Sopenharmony_ci} 10378c2ecf20Sopenharmony_ci 10388c2ecf20Sopenharmony_cistatic ssize_t fan_show(struct device *dev, struct device_attribute *devattr, 10398c2ecf20Sopenharmony_ci char *buf) 10408c2ecf20Sopenharmony_ci{ 10418c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 10428c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 10438c2ecf20Sopenharmony_ci 10448c2ecf20Sopenharmony_ci if (!fan_enabled(data, attr->index) || 10458c2ecf20Sopenharmony_ci !FAN_DATA_VALID(data->fan[attr->index])) 10468c2ecf20Sopenharmony_ci return sprintf(buf, "0\n"); 10478c2ecf20Sopenharmony_ci 10488c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", 10498c2ecf20Sopenharmony_ci FAN_PERIOD_TO_RPM(data->fan[attr->index])); 10508c2ecf20Sopenharmony_ci} 10518c2ecf20Sopenharmony_ci 10528c2ecf20Sopenharmony_cistatic ssize_t force_pwm_max_show(struct device *dev, 10538c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 10548c2ecf20Sopenharmony_ci{ 10558c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 10568c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", (data->cfg2 & ADT7462_FSPD_MASK ? 1 : 0)); 10578c2ecf20Sopenharmony_ci} 10588c2ecf20Sopenharmony_ci 10598c2ecf20Sopenharmony_cistatic ssize_t force_pwm_max_store(struct device *dev, 10608c2ecf20Sopenharmony_ci struct device_attribute *devattr, 10618c2ecf20Sopenharmony_ci const char *buf, size_t count) 10628c2ecf20Sopenharmony_ci{ 10638c2ecf20Sopenharmony_ci struct adt7462_data *data = dev_get_drvdata(dev); 10648c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 10658c2ecf20Sopenharmony_ci long temp; 10668c2ecf20Sopenharmony_ci u8 reg; 10678c2ecf20Sopenharmony_ci 10688c2ecf20Sopenharmony_ci if (kstrtol(buf, 10, &temp)) 10698c2ecf20Sopenharmony_ci return -EINVAL; 10708c2ecf20Sopenharmony_ci 10718c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 10728c2ecf20Sopenharmony_ci reg = i2c_smbus_read_byte_data(client, ADT7462_REG_CFG2); 10738c2ecf20Sopenharmony_ci if (temp) 10748c2ecf20Sopenharmony_ci reg |= ADT7462_FSPD_MASK; 10758c2ecf20Sopenharmony_ci else 10768c2ecf20Sopenharmony_ci reg &= ~ADT7462_FSPD_MASK; 10778c2ecf20Sopenharmony_ci data->cfg2 = reg; 10788c2ecf20Sopenharmony_ci i2c_smbus_write_byte_data(client, ADT7462_REG_CFG2, reg); 10798c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 10808c2ecf20Sopenharmony_ci 10818c2ecf20Sopenharmony_ci return count; 10828c2ecf20Sopenharmony_ci} 10838c2ecf20Sopenharmony_ci 10848c2ecf20Sopenharmony_cistatic ssize_t pwm_show(struct device *dev, struct device_attribute *devattr, 10858c2ecf20Sopenharmony_ci char *buf) 10868c2ecf20Sopenharmony_ci{ 10878c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 10888c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 10898c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", data->pwm[attr->index]); 10908c2ecf20Sopenharmony_ci} 10918c2ecf20Sopenharmony_ci 10928c2ecf20Sopenharmony_cistatic ssize_t pwm_store(struct device *dev, struct device_attribute *devattr, 10938c2ecf20Sopenharmony_ci const char *buf, size_t count) 10948c2ecf20Sopenharmony_ci{ 10958c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 10968c2ecf20Sopenharmony_ci struct adt7462_data *data = dev_get_drvdata(dev); 10978c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 10988c2ecf20Sopenharmony_ci long temp; 10998c2ecf20Sopenharmony_ci 11008c2ecf20Sopenharmony_ci if (kstrtol(buf, 10, &temp)) 11018c2ecf20Sopenharmony_ci return -EINVAL; 11028c2ecf20Sopenharmony_ci 11038c2ecf20Sopenharmony_ci temp = clamp_val(temp, 0, 255); 11048c2ecf20Sopenharmony_ci 11058c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 11068c2ecf20Sopenharmony_ci data->pwm[attr->index] = temp; 11078c2ecf20Sopenharmony_ci i2c_smbus_write_byte_data(client, ADT7462_REG_PWM(attr->index), temp); 11088c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 11098c2ecf20Sopenharmony_ci 11108c2ecf20Sopenharmony_ci return count; 11118c2ecf20Sopenharmony_ci} 11128c2ecf20Sopenharmony_ci 11138c2ecf20Sopenharmony_cistatic ssize_t pwm_max_show(struct device *dev, 11148c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 11158c2ecf20Sopenharmony_ci{ 11168c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 11178c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", data->pwm_max); 11188c2ecf20Sopenharmony_ci} 11198c2ecf20Sopenharmony_ci 11208c2ecf20Sopenharmony_cistatic ssize_t pwm_max_store(struct device *dev, 11218c2ecf20Sopenharmony_ci struct device_attribute *devattr, 11228c2ecf20Sopenharmony_ci const char *buf, size_t count) 11238c2ecf20Sopenharmony_ci{ 11248c2ecf20Sopenharmony_ci struct adt7462_data *data = dev_get_drvdata(dev); 11258c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 11268c2ecf20Sopenharmony_ci long temp; 11278c2ecf20Sopenharmony_ci 11288c2ecf20Sopenharmony_ci if (kstrtol(buf, 10, &temp)) 11298c2ecf20Sopenharmony_ci return -EINVAL; 11308c2ecf20Sopenharmony_ci 11318c2ecf20Sopenharmony_ci temp = clamp_val(temp, 0, 255); 11328c2ecf20Sopenharmony_ci 11338c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 11348c2ecf20Sopenharmony_ci data->pwm_max = temp; 11358c2ecf20Sopenharmony_ci i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_MAX, temp); 11368c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 11378c2ecf20Sopenharmony_ci 11388c2ecf20Sopenharmony_ci return count; 11398c2ecf20Sopenharmony_ci} 11408c2ecf20Sopenharmony_ci 11418c2ecf20Sopenharmony_cistatic ssize_t pwm_min_show(struct device *dev, 11428c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 11438c2ecf20Sopenharmony_ci{ 11448c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 11458c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 11468c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", data->pwm_min[attr->index]); 11478c2ecf20Sopenharmony_ci} 11488c2ecf20Sopenharmony_ci 11498c2ecf20Sopenharmony_cistatic ssize_t pwm_min_store(struct device *dev, 11508c2ecf20Sopenharmony_ci struct device_attribute *devattr, 11518c2ecf20Sopenharmony_ci const char *buf, size_t count) 11528c2ecf20Sopenharmony_ci{ 11538c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 11548c2ecf20Sopenharmony_ci struct adt7462_data *data = dev_get_drvdata(dev); 11558c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 11568c2ecf20Sopenharmony_ci long temp; 11578c2ecf20Sopenharmony_ci 11588c2ecf20Sopenharmony_ci if (kstrtol(buf, 10, &temp)) 11598c2ecf20Sopenharmony_ci return -EINVAL; 11608c2ecf20Sopenharmony_ci 11618c2ecf20Sopenharmony_ci temp = clamp_val(temp, 0, 255); 11628c2ecf20Sopenharmony_ci 11638c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 11648c2ecf20Sopenharmony_ci data->pwm_min[attr->index] = temp; 11658c2ecf20Sopenharmony_ci i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_MIN(attr->index), 11668c2ecf20Sopenharmony_ci temp); 11678c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 11688c2ecf20Sopenharmony_ci 11698c2ecf20Sopenharmony_ci return count; 11708c2ecf20Sopenharmony_ci} 11718c2ecf20Sopenharmony_ci 11728c2ecf20Sopenharmony_cistatic ssize_t pwm_hyst_show(struct device *dev, 11738c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 11748c2ecf20Sopenharmony_ci{ 11758c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 11768c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 11778c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", 1000 * 11788c2ecf20Sopenharmony_ci (data->pwm_trange[attr->index] & ADT7462_PWM_HYST_MASK)); 11798c2ecf20Sopenharmony_ci} 11808c2ecf20Sopenharmony_ci 11818c2ecf20Sopenharmony_cistatic ssize_t pwm_hyst_store(struct device *dev, 11828c2ecf20Sopenharmony_ci struct device_attribute *devattr, 11838c2ecf20Sopenharmony_ci const char *buf, size_t count) 11848c2ecf20Sopenharmony_ci{ 11858c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 11868c2ecf20Sopenharmony_ci struct adt7462_data *data = dev_get_drvdata(dev); 11878c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 11888c2ecf20Sopenharmony_ci long temp; 11898c2ecf20Sopenharmony_ci 11908c2ecf20Sopenharmony_ci if (kstrtol(buf, 10, &temp)) 11918c2ecf20Sopenharmony_ci return -EINVAL; 11928c2ecf20Sopenharmony_ci 11938c2ecf20Sopenharmony_ci temp = clamp_val(temp, 0, 15000); 11948c2ecf20Sopenharmony_ci temp = DIV_ROUND_CLOSEST(temp, 1000); 11958c2ecf20Sopenharmony_ci 11968c2ecf20Sopenharmony_ci /* package things up */ 11978c2ecf20Sopenharmony_ci temp &= ADT7462_PWM_HYST_MASK; 11988c2ecf20Sopenharmony_ci temp |= data->pwm_trange[attr->index] & ADT7462_PWM_RANGE_MASK; 11998c2ecf20Sopenharmony_ci 12008c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 12018c2ecf20Sopenharmony_ci data->pwm_trange[attr->index] = temp; 12028c2ecf20Sopenharmony_ci i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_TRANGE(attr->index), 12038c2ecf20Sopenharmony_ci temp); 12048c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 12058c2ecf20Sopenharmony_ci 12068c2ecf20Sopenharmony_ci return count; 12078c2ecf20Sopenharmony_ci} 12088c2ecf20Sopenharmony_ci 12098c2ecf20Sopenharmony_cistatic ssize_t pwm_tmax_show(struct device *dev, 12108c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 12118c2ecf20Sopenharmony_ci{ 12128c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 12138c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 12148c2ecf20Sopenharmony_ci 12158c2ecf20Sopenharmony_ci /* tmax = tmin + trange */ 12168c2ecf20Sopenharmony_ci int trange = trange_values[data->pwm_trange[attr->index] >> 12178c2ecf20Sopenharmony_ci ADT7462_PWM_RANGE_SHIFT]; 12188c2ecf20Sopenharmony_ci int tmin = (data->pwm_tmin[attr->index] - 64) * 1000; 12198c2ecf20Sopenharmony_ci 12208c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", tmin + trange); 12218c2ecf20Sopenharmony_ci} 12228c2ecf20Sopenharmony_ci 12238c2ecf20Sopenharmony_cistatic ssize_t pwm_tmax_store(struct device *dev, 12248c2ecf20Sopenharmony_ci struct device_attribute *devattr, 12258c2ecf20Sopenharmony_ci const char *buf, size_t count) 12268c2ecf20Sopenharmony_ci{ 12278c2ecf20Sopenharmony_ci int temp; 12288c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 12298c2ecf20Sopenharmony_ci struct adt7462_data *data = dev_get_drvdata(dev); 12308c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 12318c2ecf20Sopenharmony_ci int tmin, trange_value; 12328c2ecf20Sopenharmony_ci long trange; 12338c2ecf20Sopenharmony_ci 12348c2ecf20Sopenharmony_ci if (kstrtol(buf, 10, &trange)) 12358c2ecf20Sopenharmony_ci return -EINVAL; 12368c2ecf20Sopenharmony_ci 12378c2ecf20Sopenharmony_ci /* trange = tmax - tmin */ 12388c2ecf20Sopenharmony_ci tmin = (data->pwm_tmin[attr->index] - 64) * 1000; 12398c2ecf20Sopenharmony_ci trange_value = find_trange_value(trange - tmin); 12408c2ecf20Sopenharmony_ci if (trange_value < 0) 12418c2ecf20Sopenharmony_ci return trange_value; 12428c2ecf20Sopenharmony_ci 12438c2ecf20Sopenharmony_ci temp = trange_value << ADT7462_PWM_RANGE_SHIFT; 12448c2ecf20Sopenharmony_ci temp |= data->pwm_trange[attr->index] & ADT7462_PWM_HYST_MASK; 12458c2ecf20Sopenharmony_ci 12468c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 12478c2ecf20Sopenharmony_ci data->pwm_trange[attr->index] = temp; 12488c2ecf20Sopenharmony_ci i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_TRANGE(attr->index), 12498c2ecf20Sopenharmony_ci temp); 12508c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 12518c2ecf20Sopenharmony_ci 12528c2ecf20Sopenharmony_ci return count; 12538c2ecf20Sopenharmony_ci} 12548c2ecf20Sopenharmony_ci 12558c2ecf20Sopenharmony_cistatic ssize_t pwm_tmin_show(struct device *dev, 12568c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 12578c2ecf20Sopenharmony_ci{ 12588c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 12598c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 12608c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", 1000 * (data->pwm_tmin[attr->index] - 64)); 12618c2ecf20Sopenharmony_ci} 12628c2ecf20Sopenharmony_ci 12638c2ecf20Sopenharmony_cistatic ssize_t pwm_tmin_store(struct device *dev, 12648c2ecf20Sopenharmony_ci struct device_attribute *devattr, 12658c2ecf20Sopenharmony_ci const char *buf, size_t count) 12668c2ecf20Sopenharmony_ci{ 12678c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 12688c2ecf20Sopenharmony_ci struct adt7462_data *data = dev_get_drvdata(dev); 12698c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 12708c2ecf20Sopenharmony_ci long temp; 12718c2ecf20Sopenharmony_ci 12728c2ecf20Sopenharmony_ci if (kstrtol(buf, 10, &temp)) 12738c2ecf20Sopenharmony_ci return -EINVAL; 12748c2ecf20Sopenharmony_ci 12758c2ecf20Sopenharmony_ci temp = clamp_val(temp, -64000, 191000); 12768c2ecf20Sopenharmony_ci temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; 12778c2ecf20Sopenharmony_ci 12788c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 12798c2ecf20Sopenharmony_ci data->pwm_tmin[attr->index] = temp; 12808c2ecf20Sopenharmony_ci i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_TMIN(attr->index), 12818c2ecf20Sopenharmony_ci temp); 12828c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 12838c2ecf20Sopenharmony_ci 12848c2ecf20Sopenharmony_ci return count; 12858c2ecf20Sopenharmony_ci} 12868c2ecf20Sopenharmony_ci 12878c2ecf20Sopenharmony_cistatic ssize_t pwm_auto_show(struct device *dev, 12888c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 12898c2ecf20Sopenharmony_ci{ 12908c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 12918c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 12928c2ecf20Sopenharmony_ci int cfg = data->pwm_cfg[attr->index] >> ADT7462_PWM_CHANNEL_SHIFT; 12938c2ecf20Sopenharmony_ci 12948c2ecf20Sopenharmony_ci switch (cfg) { 12958c2ecf20Sopenharmony_ci case 4: /* off */ 12968c2ecf20Sopenharmony_ci return sprintf(buf, "0\n"); 12978c2ecf20Sopenharmony_ci case 7: /* manual */ 12988c2ecf20Sopenharmony_ci return sprintf(buf, "1\n"); 12998c2ecf20Sopenharmony_ci default: /* automatic */ 13008c2ecf20Sopenharmony_ci return sprintf(buf, "2\n"); 13018c2ecf20Sopenharmony_ci } 13028c2ecf20Sopenharmony_ci} 13038c2ecf20Sopenharmony_ci 13048c2ecf20Sopenharmony_cistatic void set_pwm_channel(struct i2c_client *client, 13058c2ecf20Sopenharmony_ci struct adt7462_data *data, 13068c2ecf20Sopenharmony_ci int which, 13078c2ecf20Sopenharmony_ci int value) 13088c2ecf20Sopenharmony_ci{ 13098c2ecf20Sopenharmony_ci int temp = data->pwm_cfg[which] & ~ADT7462_PWM_CHANNEL_MASK; 13108c2ecf20Sopenharmony_ci temp |= value << ADT7462_PWM_CHANNEL_SHIFT; 13118c2ecf20Sopenharmony_ci 13128c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 13138c2ecf20Sopenharmony_ci data->pwm_cfg[which] = temp; 13148c2ecf20Sopenharmony_ci i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_CFG(which), temp); 13158c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 13168c2ecf20Sopenharmony_ci} 13178c2ecf20Sopenharmony_ci 13188c2ecf20Sopenharmony_cistatic ssize_t pwm_auto_store(struct device *dev, 13198c2ecf20Sopenharmony_ci struct device_attribute *devattr, 13208c2ecf20Sopenharmony_ci const char *buf, size_t count) 13218c2ecf20Sopenharmony_ci{ 13228c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 13238c2ecf20Sopenharmony_ci struct adt7462_data *data = dev_get_drvdata(dev); 13248c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 13258c2ecf20Sopenharmony_ci long temp; 13268c2ecf20Sopenharmony_ci 13278c2ecf20Sopenharmony_ci if (kstrtol(buf, 10, &temp)) 13288c2ecf20Sopenharmony_ci return -EINVAL; 13298c2ecf20Sopenharmony_ci 13308c2ecf20Sopenharmony_ci switch (temp) { 13318c2ecf20Sopenharmony_ci case 0: /* off */ 13328c2ecf20Sopenharmony_ci set_pwm_channel(client, data, attr->index, 4); 13338c2ecf20Sopenharmony_ci return count; 13348c2ecf20Sopenharmony_ci case 1: /* manual */ 13358c2ecf20Sopenharmony_ci set_pwm_channel(client, data, attr->index, 7); 13368c2ecf20Sopenharmony_ci return count; 13378c2ecf20Sopenharmony_ci default: 13388c2ecf20Sopenharmony_ci return -EINVAL; 13398c2ecf20Sopenharmony_ci } 13408c2ecf20Sopenharmony_ci} 13418c2ecf20Sopenharmony_ci 13428c2ecf20Sopenharmony_cistatic ssize_t pwm_auto_temp_show(struct device *dev, 13438c2ecf20Sopenharmony_ci struct device_attribute *devattr, char *buf) 13448c2ecf20Sopenharmony_ci{ 13458c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 13468c2ecf20Sopenharmony_ci struct adt7462_data *data = adt7462_update_device(dev); 13478c2ecf20Sopenharmony_ci int channel = data->pwm_cfg[attr->index] >> ADT7462_PWM_CHANNEL_SHIFT; 13488c2ecf20Sopenharmony_ci 13498c2ecf20Sopenharmony_ci switch (channel) { 13508c2ecf20Sopenharmony_ci case 0: /* temp[1234] only */ 13518c2ecf20Sopenharmony_ci case 1: 13528c2ecf20Sopenharmony_ci case 2: 13538c2ecf20Sopenharmony_ci case 3: 13548c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", (1 << channel)); 13558c2ecf20Sopenharmony_ci case 5: /* temp1 & temp4 */ 13568c2ecf20Sopenharmony_ci return sprintf(buf, "9\n"); 13578c2ecf20Sopenharmony_ci case 6: 13588c2ecf20Sopenharmony_ci return sprintf(buf, "15\n"); 13598c2ecf20Sopenharmony_ci default: 13608c2ecf20Sopenharmony_ci return sprintf(buf, "0\n"); 13618c2ecf20Sopenharmony_ci } 13628c2ecf20Sopenharmony_ci} 13638c2ecf20Sopenharmony_ci 13648c2ecf20Sopenharmony_cistatic int cvt_auto_temp(int input) 13658c2ecf20Sopenharmony_ci{ 13668c2ecf20Sopenharmony_ci if (input == 0xF) 13678c2ecf20Sopenharmony_ci return 6; 13688c2ecf20Sopenharmony_ci if (input == 0x9) 13698c2ecf20Sopenharmony_ci return 5; 13708c2ecf20Sopenharmony_ci if (input < 1 || !is_power_of_2(input)) 13718c2ecf20Sopenharmony_ci return -EINVAL; 13728c2ecf20Sopenharmony_ci return ilog2(input); 13738c2ecf20Sopenharmony_ci} 13748c2ecf20Sopenharmony_ci 13758c2ecf20Sopenharmony_cistatic ssize_t pwm_auto_temp_store(struct device *dev, 13768c2ecf20Sopenharmony_ci struct device_attribute *devattr, 13778c2ecf20Sopenharmony_ci const char *buf, size_t count) 13788c2ecf20Sopenharmony_ci{ 13798c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 13808c2ecf20Sopenharmony_ci struct adt7462_data *data = dev_get_drvdata(dev); 13818c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 13828c2ecf20Sopenharmony_ci long temp; 13838c2ecf20Sopenharmony_ci 13848c2ecf20Sopenharmony_ci if (kstrtol(buf, 10, &temp)) 13858c2ecf20Sopenharmony_ci return -EINVAL; 13868c2ecf20Sopenharmony_ci 13878c2ecf20Sopenharmony_ci temp = cvt_auto_temp(temp); 13888c2ecf20Sopenharmony_ci if (temp < 0) 13898c2ecf20Sopenharmony_ci return temp; 13908c2ecf20Sopenharmony_ci 13918c2ecf20Sopenharmony_ci set_pwm_channel(client, data, attr->index, temp); 13928c2ecf20Sopenharmony_ci 13938c2ecf20Sopenharmony_ci return count; 13948c2ecf20Sopenharmony_ci} 13958c2ecf20Sopenharmony_ci 13968c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0); 13978c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1); 13988c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp3_max, temp_max, 2); 13998c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp4_max, temp_max, 3); 14008c2ecf20Sopenharmony_ci 14018c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp1_min, temp_min, 0); 14028c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp2_min, temp_min, 1); 14038c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp3_min, temp_min, 2); 14048c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp4_min, temp_min, 3); 14058c2ecf20Sopenharmony_ci 14068c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0); 14078c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1); 14088c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2); 14098c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(temp4_input, temp, 3); 14108c2ecf20Sopenharmony_ci 14118c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(temp1_label, temp_label, 0); 14128c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(temp2_label, temp_label, 1); 14138c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(temp3_label, temp_label, 2); 14148c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(temp4_label, temp_label, 3); 14158c2ecf20Sopenharmony_ci 14168c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 14178c2ecf20Sopenharmony_ci ADT7462_ALARM1 | ADT7462_LT_ALARM); 14188c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 14198c2ecf20Sopenharmony_ci ADT7462_ALARM1 | ADT7462_R1T_ALARM); 14208c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 14218c2ecf20Sopenharmony_ci ADT7462_ALARM1 | ADT7462_R2T_ALARM); 14228c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(temp4_alarm, alarm, 14238c2ecf20Sopenharmony_ci ADT7462_ALARM1 | ADT7462_R3T_ALARM); 14248c2ecf20Sopenharmony_ci 14258c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in1_max, volt_max, 0); 14268c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in2_max, volt_max, 1); 14278c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in3_max, volt_max, 2); 14288c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in4_max, volt_max, 3); 14298c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in5_max, volt_max, 4); 14308c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in6_max, volt_max, 5); 14318c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in7_max, volt_max, 6); 14328c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in8_max, volt_max, 7); 14338c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in9_max, volt_max, 8); 14348c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in10_max, volt_max, 9); 14358c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in11_max, volt_max, 10); 14368c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in12_max, volt_max, 11); 14378c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in13_max, volt_max, 12); 14388c2ecf20Sopenharmony_ci 14398c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in1_min, volt_min, 0); 14408c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in2_min, volt_min, 1); 14418c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in3_min, volt_min, 2); 14428c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in4_min, volt_min, 3); 14438c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in5_min, volt_min, 4); 14448c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in6_min, volt_min, 5); 14458c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in7_min, volt_min, 6); 14468c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in8_min, volt_min, 7); 14478c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in9_min, volt_min, 8); 14488c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in10_min, volt_min, 9); 14498c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in11_min, volt_min, 10); 14508c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in12_min, volt_min, 11); 14518c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(in13_min, volt_min, 12); 14528c2ecf20Sopenharmony_ci 14538c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in1_input, voltage, 0); 14548c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in2_input, voltage, 1); 14558c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in3_input, voltage, 2); 14568c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in4_input, voltage, 3); 14578c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in5_input, voltage, 4); 14588c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in6_input, voltage, 5); 14598c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in7_input, voltage, 6); 14608c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in8_input, voltage, 7); 14618c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in9_input, voltage, 8); 14628c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in10_input, voltage, 9); 14638c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in11_input, voltage, 10); 14648c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in12_input, voltage, 11); 14658c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in13_input, voltage, 12); 14668c2ecf20Sopenharmony_ci 14678c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in1_label, voltage_label, 0); 14688c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in2_label, voltage_label, 1); 14698c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in3_label, voltage_label, 2); 14708c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in4_label, voltage_label, 3); 14718c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in5_label, voltage_label, 4); 14728c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in6_label, voltage_label, 5); 14738c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in7_label, voltage_label, 6); 14748c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in8_label, voltage_label, 7); 14758c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in9_label, voltage_label, 8); 14768c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in10_label, voltage_label, 9); 14778c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in11_label, voltage_label, 10); 14788c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in12_label, voltage_label, 11); 14798c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in13_label, voltage_label, 12); 14808c2ecf20Sopenharmony_ci 14818c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 14828c2ecf20Sopenharmony_ci ADT7462_ALARM2 | ADT7462_V0_ALARM); 14838c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 14848c2ecf20Sopenharmony_ci ADT7462_ALARM2 | ADT7462_V7_ALARM); 14858c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 14868c2ecf20Sopenharmony_ci ADT7462_ALARM2 | ADT7462_V2_ALARM); 14878c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 14888c2ecf20Sopenharmony_ci ADT7462_ALARM2 | ADT7462_V6_ALARM); 14898c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in5_alarm, alarm, 14908c2ecf20Sopenharmony_ci ADT7462_ALARM2 | ADT7462_V5_ALARM); 14918c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in6_alarm, alarm, 14928c2ecf20Sopenharmony_ci ADT7462_ALARM2 | ADT7462_V4_ALARM); 14938c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in7_alarm, alarm, 14948c2ecf20Sopenharmony_ci ADT7462_ALARM2 | ADT7462_V3_ALARM); 14958c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in8_alarm, alarm, 14968c2ecf20Sopenharmony_ci ADT7462_ALARM2 | ADT7462_V1_ALARM); 14978c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in9_alarm, alarm, 14988c2ecf20Sopenharmony_ci ADT7462_ALARM3 | ADT7462_V10_ALARM); 14998c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in10_alarm, alarm, 15008c2ecf20Sopenharmony_ci ADT7462_ALARM3 | ADT7462_V9_ALARM); 15018c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in11_alarm, alarm, 15028c2ecf20Sopenharmony_ci ADT7462_ALARM3 | ADT7462_V8_ALARM); 15038c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in12_alarm, alarm, 15048c2ecf20Sopenharmony_ci ADT7462_ALARM3 | ADT7462_V11_ALARM); 15058c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in13_alarm, alarm, 15068c2ecf20Sopenharmony_ci ADT7462_ALARM3 | ADT7462_V12_ALARM); 15078c2ecf20Sopenharmony_ci 15088c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0); 15098c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1); 15108c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(fan3_min, fan_min, 2); 15118c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(fan4_min, fan_min, 3); 15128c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(fan5_min, fan_min, 4); 15138c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(fan6_min, fan_min, 5); 15148c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(fan7_min, fan_min, 6); 15158c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(fan8_min, fan_min, 7); 15168c2ecf20Sopenharmony_ci 15178c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0); 15188c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1); 15198c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(fan3_input, fan, 2); 15208c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(fan4_input, fan, 3); 15218c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(fan5_input, fan, 4); 15228c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(fan6_input, fan, 5); 15238c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(fan7_input, fan, 6); 15248c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(fan8_input, fan, 7); 15258c2ecf20Sopenharmony_ci 15268c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 15278c2ecf20Sopenharmony_ci ADT7462_ALARM4 | ADT7462_F0_ALARM); 15288c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 15298c2ecf20Sopenharmony_ci ADT7462_ALARM4 | ADT7462_F1_ALARM); 15308c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(fan3_alarm, alarm, 15318c2ecf20Sopenharmony_ci ADT7462_ALARM4 | ADT7462_F2_ALARM); 15328c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(fan4_alarm, alarm, 15338c2ecf20Sopenharmony_ci ADT7462_ALARM4 | ADT7462_F3_ALARM); 15348c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(fan5_alarm, alarm, 15358c2ecf20Sopenharmony_ci ADT7462_ALARM4 | ADT7462_F4_ALARM); 15368c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(fan6_alarm, alarm, 15378c2ecf20Sopenharmony_ci ADT7462_ALARM4 | ADT7462_F5_ALARM); 15388c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(fan7_alarm, alarm, 15398c2ecf20Sopenharmony_ci ADT7462_ALARM4 | ADT7462_F6_ALARM); 15408c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(fan8_alarm, alarm, 15418c2ecf20Sopenharmony_ci ADT7462_ALARM4 | ADT7462_F7_ALARM); 15428c2ecf20Sopenharmony_ci 15438c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(force_pwm_max, force_pwm_max, 0); 15448c2ecf20Sopenharmony_ci 15458c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm1, pwm, 0); 15468c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm2, pwm, 1); 15478c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm3, pwm, 2); 15488c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm4, pwm, 3); 15498c2ecf20Sopenharmony_ci 15508c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm1_auto_point1_pwm, pwm_min, 0); 15518c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm2_auto_point1_pwm, pwm_min, 1); 15528c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm3_auto_point1_pwm, pwm_min, 2); 15538c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm4_auto_point1_pwm, pwm_min, 3); 15548c2ecf20Sopenharmony_ci 15558c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm1_auto_point2_pwm, pwm_max, 0); 15568c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm2_auto_point2_pwm, pwm_max, 1); 15578c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm3_auto_point2_pwm, pwm_max, 2); 15588c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm4_auto_point2_pwm, pwm_max, 3); 15598c2ecf20Sopenharmony_ci 15608c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp1_auto_point1_hyst, pwm_hyst, 0); 15618c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp2_auto_point1_hyst, pwm_hyst, 1); 15628c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp3_auto_point1_hyst, pwm_hyst, 2); 15638c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp4_auto_point1_hyst, pwm_hyst, 3); 15648c2ecf20Sopenharmony_ci 15658c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp1_auto_point2_hyst, pwm_hyst, 0); 15668c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp2_auto_point2_hyst, pwm_hyst, 1); 15678c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp3_auto_point2_hyst, pwm_hyst, 2); 15688c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp4_auto_point2_hyst, pwm_hyst, 3); 15698c2ecf20Sopenharmony_ci 15708c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp1_auto_point1_temp, pwm_tmin, 0); 15718c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp2_auto_point1_temp, pwm_tmin, 1); 15728c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp3_auto_point1_temp, pwm_tmin, 2); 15738c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp4_auto_point1_temp, pwm_tmin, 3); 15748c2ecf20Sopenharmony_ci 15758c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp1_auto_point2_temp, pwm_tmax, 0); 15768c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp2_auto_point2_temp, pwm_tmax, 1); 15778c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp3_auto_point2_temp, pwm_tmax, 2); 15788c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(temp4_auto_point2_temp, pwm_tmax, 3); 15798c2ecf20Sopenharmony_ci 15808c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm1_enable, pwm_auto, 0); 15818c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm2_enable, pwm_auto, 1); 15828c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm3_enable, pwm_auto, 2); 15838c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm4_enable, pwm_auto, 3); 15848c2ecf20Sopenharmony_ci 15858c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm1_auto_channels_temp, pwm_auto_temp, 0); 15868c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm2_auto_channels_temp, pwm_auto_temp, 1); 15878c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm3_auto_channels_temp, pwm_auto_temp, 2); 15888c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RW(pwm4_auto_channels_temp, pwm_auto_temp, 3); 15898c2ecf20Sopenharmony_ci 15908c2ecf20Sopenharmony_cistatic struct attribute *adt7462_attrs[] = { 15918c2ecf20Sopenharmony_ci &sensor_dev_attr_temp1_max.dev_attr.attr, 15928c2ecf20Sopenharmony_ci &sensor_dev_attr_temp2_max.dev_attr.attr, 15938c2ecf20Sopenharmony_ci &sensor_dev_attr_temp3_max.dev_attr.attr, 15948c2ecf20Sopenharmony_ci &sensor_dev_attr_temp4_max.dev_attr.attr, 15958c2ecf20Sopenharmony_ci 15968c2ecf20Sopenharmony_ci &sensor_dev_attr_temp1_min.dev_attr.attr, 15978c2ecf20Sopenharmony_ci &sensor_dev_attr_temp2_min.dev_attr.attr, 15988c2ecf20Sopenharmony_ci &sensor_dev_attr_temp3_min.dev_attr.attr, 15998c2ecf20Sopenharmony_ci &sensor_dev_attr_temp4_min.dev_attr.attr, 16008c2ecf20Sopenharmony_ci 16018c2ecf20Sopenharmony_ci &sensor_dev_attr_temp1_input.dev_attr.attr, 16028c2ecf20Sopenharmony_ci &sensor_dev_attr_temp2_input.dev_attr.attr, 16038c2ecf20Sopenharmony_ci &sensor_dev_attr_temp3_input.dev_attr.attr, 16048c2ecf20Sopenharmony_ci &sensor_dev_attr_temp4_input.dev_attr.attr, 16058c2ecf20Sopenharmony_ci 16068c2ecf20Sopenharmony_ci &sensor_dev_attr_temp1_label.dev_attr.attr, 16078c2ecf20Sopenharmony_ci &sensor_dev_attr_temp2_label.dev_attr.attr, 16088c2ecf20Sopenharmony_ci &sensor_dev_attr_temp3_label.dev_attr.attr, 16098c2ecf20Sopenharmony_ci &sensor_dev_attr_temp4_label.dev_attr.attr, 16108c2ecf20Sopenharmony_ci 16118c2ecf20Sopenharmony_ci &sensor_dev_attr_temp1_alarm.dev_attr.attr, 16128c2ecf20Sopenharmony_ci &sensor_dev_attr_temp2_alarm.dev_attr.attr, 16138c2ecf20Sopenharmony_ci &sensor_dev_attr_temp3_alarm.dev_attr.attr, 16148c2ecf20Sopenharmony_ci &sensor_dev_attr_temp4_alarm.dev_attr.attr, 16158c2ecf20Sopenharmony_ci 16168c2ecf20Sopenharmony_ci &sensor_dev_attr_in1_max.dev_attr.attr, 16178c2ecf20Sopenharmony_ci &sensor_dev_attr_in2_max.dev_attr.attr, 16188c2ecf20Sopenharmony_ci &sensor_dev_attr_in3_max.dev_attr.attr, 16198c2ecf20Sopenharmony_ci &sensor_dev_attr_in4_max.dev_attr.attr, 16208c2ecf20Sopenharmony_ci &sensor_dev_attr_in5_max.dev_attr.attr, 16218c2ecf20Sopenharmony_ci &sensor_dev_attr_in6_max.dev_attr.attr, 16228c2ecf20Sopenharmony_ci &sensor_dev_attr_in7_max.dev_attr.attr, 16238c2ecf20Sopenharmony_ci &sensor_dev_attr_in8_max.dev_attr.attr, 16248c2ecf20Sopenharmony_ci &sensor_dev_attr_in9_max.dev_attr.attr, 16258c2ecf20Sopenharmony_ci &sensor_dev_attr_in10_max.dev_attr.attr, 16268c2ecf20Sopenharmony_ci &sensor_dev_attr_in11_max.dev_attr.attr, 16278c2ecf20Sopenharmony_ci &sensor_dev_attr_in12_max.dev_attr.attr, 16288c2ecf20Sopenharmony_ci &sensor_dev_attr_in13_max.dev_attr.attr, 16298c2ecf20Sopenharmony_ci 16308c2ecf20Sopenharmony_ci &sensor_dev_attr_in1_min.dev_attr.attr, 16318c2ecf20Sopenharmony_ci &sensor_dev_attr_in2_min.dev_attr.attr, 16328c2ecf20Sopenharmony_ci &sensor_dev_attr_in3_min.dev_attr.attr, 16338c2ecf20Sopenharmony_ci &sensor_dev_attr_in4_min.dev_attr.attr, 16348c2ecf20Sopenharmony_ci &sensor_dev_attr_in5_min.dev_attr.attr, 16358c2ecf20Sopenharmony_ci &sensor_dev_attr_in6_min.dev_attr.attr, 16368c2ecf20Sopenharmony_ci &sensor_dev_attr_in7_min.dev_attr.attr, 16378c2ecf20Sopenharmony_ci &sensor_dev_attr_in8_min.dev_attr.attr, 16388c2ecf20Sopenharmony_ci &sensor_dev_attr_in9_min.dev_attr.attr, 16398c2ecf20Sopenharmony_ci &sensor_dev_attr_in10_min.dev_attr.attr, 16408c2ecf20Sopenharmony_ci &sensor_dev_attr_in11_min.dev_attr.attr, 16418c2ecf20Sopenharmony_ci &sensor_dev_attr_in12_min.dev_attr.attr, 16428c2ecf20Sopenharmony_ci &sensor_dev_attr_in13_min.dev_attr.attr, 16438c2ecf20Sopenharmony_ci 16448c2ecf20Sopenharmony_ci &sensor_dev_attr_in1_input.dev_attr.attr, 16458c2ecf20Sopenharmony_ci &sensor_dev_attr_in2_input.dev_attr.attr, 16468c2ecf20Sopenharmony_ci &sensor_dev_attr_in3_input.dev_attr.attr, 16478c2ecf20Sopenharmony_ci &sensor_dev_attr_in4_input.dev_attr.attr, 16488c2ecf20Sopenharmony_ci &sensor_dev_attr_in5_input.dev_attr.attr, 16498c2ecf20Sopenharmony_ci &sensor_dev_attr_in6_input.dev_attr.attr, 16508c2ecf20Sopenharmony_ci &sensor_dev_attr_in7_input.dev_attr.attr, 16518c2ecf20Sopenharmony_ci &sensor_dev_attr_in8_input.dev_attr.attr, 16528c2ecf20Sopenharmony_ci &sensor_dev_attr_in9_input.dev_attr.attr, 16538c2ecf20Sopenharmony_ci &sensor_dev_attr_in10_input.dev_attr.attr, 16548c2ecf20Sopenharmony_ci &sensor_dev_attr_in11_input.dev_attr.attr, 16558c2ecf20Sopenharmony_ci &sensor_dev_attr_in12_input.dev_attr.attr, 16568c2ecf20Sopenharmony_ci &sensor_dev_attr_in13_input.dev_attr.attr, 16578c2ecf20Sopenharmony_ci 16588c2ecf20Sopenharmony_ci &sensor_dev_attr_in1_label.dev_attr.attr, 16598c2ecf20Sopenharmony_ci &sensor_dev_attr_in2_label.dev_attr.attr, 16608c2ecf20Sopenharmony_ci &sensor_dev_attr_in3_label.dev_attr.attr, 16618c2ecf20Sopenharmony_ci &sensor_dev_attr_in4_label.dev_attr.attr, 16628c2ecf20Sopenharmony_ci &sensor_dev_attr_in5_label.dev_attr.attr, 16638c2ecf20Sopenharmony_ci &sensor_dev_attr_in6_label.dev_attr.attr, 16648c2ecf20Sopenharmony_ci &sensor_dev_attr_in7_label.dev_attr.attr, 16658c2ecf20Sopenharmony_ci &sensor_dev_attr_in8_label.dev_attr.attr, 16668c2ecf20Sopenharmony_ci &sensor_dev_attr_in9_label.dev_attr.attr, 16678c2ecf20Sopenharmony_ci &sensor_dev_attr_in10_label.dev_attr.attr, 16688c2ecf20Sopenharmony_ci &sensor_dev_attr_in11_label.dev_attr.attr, 16698c2ecf20Sopenharmony_ci &sensor_dev_attr_in12_label.dev_attr.attr, 16708c2ecf20Sopenharmony_ci &sensor_dev_attr_in13_label.dev_attr.attr, 16718c2ecf20Sopenharmony_ci 16728c2ecf20Sopenharmony_ci &sensor_dev_attr_in1_alarm.dev_attr.attr, 16738c2ecf20Sopenharmony_ci &sensor_dev_attr_in2_alarm.dev_attr.attr, 16748c2ecf20Sopenharmony_ci &sensor_dev_attr_in3_alarm.dev_attr.attr, 16758c2ecf20Sopenharmony_ci &sensor_dev_attr_in4_alarm.dev_attr.attr, 16768c2ecf20Sopenharmony_ci &sensor_dev_attr_in5_alarm.dev_attr.attr, 16778c2ecf20Sopenharmony_ci &sensor_dev_attr_in6_alarm.dev_attr.attr, 16788c2ecf20Sopenharmony_ci &sensor_dev_attr_in7_alarm.dev_attr.attr, 16798c2ecf20Sopenharmony_ci &sensor_dev_attr_in8_alarm.dev_attr.attr, 16808c2ecf20Sopenharmony_ci &sensor_dev_attr_in9_alarm.dev_attr.attr, 16818c2ecf20Sopenharmony_ci &sensor_dev_attr_in10_alarm.dev_attr.attr, 16828c2ecf20Sopenharmony_ci &sensor_dev_attr_in11_alarm.dev_attr.attr, 16838c2ecf20Sopenharmony_ci &sensor_dev_attr_in12_alarm.dev_attr.attr, 16848c2ecf20Sopenharmony_ci &sensor_dev_attr_in13_alarm.dev_attr.attr, 16858c2ecf20Sopenharmony_ci 16868c2ecf20Sopenharmony_ci &sensor_dev_attr_fan1_min.dev_attr.attr, 16878c2ecf20Sopenharmony_ci &sensor_dev_attr_fan2_min.dev_attr.attr, 16888c2ecf20Sopenharmony_ci &sensor_dev_attr_fan3_min.dev_attr.attr, 16898c2ecf20Sopenharmony_ci &sensor_dev_attr_fan4_min.dev_attr.attr, 16908c2ecf20Sopenharmony_ci &sensor_dev_attr_fan5_min.dev_attr.attr, 16918c2ecf20Sopenharmony_ci &sensor_dev_attr_fan6_min.dev_attr.attr, 16928c2ecf20Sopenharmony_ci &sensor_dev_attr_fan7_min.dev_attr.attr, 16938c2ecf20Sopenharmony_ci &sensor_dev_attr_fan8_min.dev_attr.attr, 16948c2ecf20Sopenharmony_ci 16958c2ecf20Sopenharmony_ci &sensor_dev_attr_fan1_input.dev_attr.attr, 16968c2ecf20Sopenharmony_ci &sensor_dev_attr_fan2_input.dev_attr.attr, 16978c2ecf20Sopenharmony_ci &sensor_dev_attr_fan3_input.dev_attr.attr, 16988c2ecf20Sopenharmony_ci &sensor_dev_attr_fan4_input.dev_attr.attr, 16998c2ecf20Sopenharmony_ci &sensor_dev_attr_fan5_input.dev_attr.attr, 17008c2ecf20Sopenharmony_ci &sensor_dev_attr_fan6_input.dev_attr.attr, 17018c2ecf20Sopenharmony_ci &sensor_dev_attr_fan7_input.dev_attr.attr, 17028c2ecf20Sopenharmony_ci &sensor_dev_attr_fan8_input.dev_attr.attr, 17038c2ecf20Sopenharmony_ci 17048c2ecf20Sopenharmony_ci &sensor_dev_attr_fan1_alarm.dev_attr.attr, 17058c2ecf20Sopenharmony_ci &sensor_dev_attr_fan2_alarm.dev_attr.attr, 17068c2ecf20Sopenharmony_ci &sensor_dev_attr_fan3_alarm.dev_attr.attr, 17078c2ecf20Sopenharmony_ci &sensor_dev_attr_fan4_alarm.dev_attr.attr, 17088c2ecf20Sopenharmony_ci &sensor_dev_attr_fan5_alarm.dev_attr.attr, 17098c2ecf20Sopenharmony_ci &sensor_dev_attr_fan6_alarm.dev_attr.attr, 17108c2ecf20Sopenharmony_ci &sensor_dev_attr_fan7_alarm.dev_attr.attr, 17118c2ecf20Sopenharmony_ci &sensor_dev_attr_fan8_alarm.dev_attr.attr, 17128c2ecf20Sopenharmony_ci 17138c2ecf20Sopenharmony_ci &sensor_dev_attr_force_pwm_max.dev_attr.attr, 17148c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm1.dev_attr.attr, 17158c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm2.dev_attr.attr, 17168c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm3.dev_attr.attr, 17178c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm4.dev_attr.attr, 17188c2ecf20Sopenharmony_ci 17198c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, 17208c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, 17218c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, 17228c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm4_auto_point1_pwm.dev_attr.attr, 17238c2ecf20Sopenharmony_ci 17248c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, 17258c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr, 17268c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, 17278c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm4_auto_point2_pwm.dev_attr.attr, 17288c2ecf20Sopenharmony_ci 17298c2ecf20Sopenharmony_ci &sensor_dev_attr_temp1_auto_point1_hyst.dev_attr.attr, 17308c2ecf20Sopenharmony_ci &sensor_dev_attr_temp2_auto_point1_hyst.dev_attr.attr, 17318c2ecf20Sopenharmony_ci &sensor_dev_attr_temp3_auto_point1_hyst.dev_attr.attr, 17328c2ecf20Sopenharmony_ci &sensor_dev_attr_temp4_auto_point1_hyst.dev_attr.attr, 17338c2ecf20Sopenharmony_ci 17348c2ecf20Sopenharmony_ci &sensor_dev_attr_temp1_auto_point2_hyst.dev_attr.attr, 17358c2ecf20Sopenharmony_ci &sensor_dev_attr_temp2_auto_point2_hyst.dev_attr.attr, 17368c2ecf20Sopenharmony_ci &sensor_dev_attr_temp3_auto_point2_hyst.dev_attr.attr, 17378c2ecf20Sopenharmony_ci &sensor_dev_attr_temp4_auto_point2_hyst.dev_attr.attr, 17388c2ecf20Sopenharmony_ci 17398c2ecf20Sopenharmony_ci &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr, 17408c2ecf20Sopenharmony_ci &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr, 17418c2ecf20Sopenharmony_ci &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr, 17428c2ecf20Sopenharmony_ci &sensor_dev_attr_temp4_auto_point1_temp.dev_attr.attr, 17438c2ecf20Sopenharmony_ci 17448c2ecf20Sopenharmony_ci &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr, 17458c2ecf20Sopenharmony_ci &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr, 17468c2ecf20Sopenharmony_ci &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr, 17478c2ecf20Sopenharmony_ci &sensor_dev_attr_temp4_auto_point2_temp.dev_attr.attr, 17488c2ecf20Sopenharmony_ci 17498c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm1_enable.dev_attr.attr, 17508c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm2_enable.dev_attr.attr, 17518c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm3_enable.dev_attr.attr, 17528c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm4_enable.dev_attr.attr, 17538c2ecf20Sopenharmony_ci 17548c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, 17558c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr, 17568c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr, 17578c2ecf20Sopenharmony_ci &sensor_dev_attr_pwm4_auto_channels_temp.dev_attr.attr, 17588c2ecf20Sopenharmony_ci NULL 17598c2ecf20Sopenharmony_ci}; 17608c2ecf20Sopenharmony_ci 17618c2ecf20Sopenharmony_ciATTRIBUTE_GROUPS(adt7462); 17628c2ecf20Sopenharmony_ci 17638c2ecf20Sopenharmony_ci/* Return 0 if detection is successful, -ENODEV otherwise */ 17648c2ecf20Sopenharmony_cistatic int adt7462_detect(struct i2c_client *client, 17658c2ecf20Sopenharmony_ci struct i2c_board_info *info) 17668c2ecf20Sopenharmony_ci{ 17678c2ecf20Sopenharmony_ci struct i2c_adapter *adapter = client->adapter; 17688c2ecf20Sopenharmony_ci int vendor, device, revision; 17698c2ecf20Sopenharmony_ci 17708c2ecf20Sopenharmony_ci if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 17718c2ecf20Sopenharmony_ci return -ENODEV; 17728c2ecf20Sopenharmony_ci 17738c2ecf20Sopenharmony_ci vendor = i2c_smbus_read_byte_data(client, ADT7462_REG_VENDOR); 17748c2ecf20Sopenharmony_ci if (vendor != ADT7462_VENDOR) 17758c2ecf20Sopenharmony_ci return -ENODEV; 17768c2ecf20Sopenharmony_ci 17778c2ecf20Sopenharmony_ci device = i2c_smbus_read_byte_data(client, ADT7462_REG_DEVICE); 17788c2ecf20Sopenharmony_ci if (device != ADT7462_DEVICE) 17798c2ecf20Sopenharmony_ci return -ENODEV; 17808c2ecf20Sopenharmony_ci 17818c2ecf20Sopenharmony_ci revision = i2c_smbus_read_byte_data(client, ADT7462_REG_REVISION); 17828c2ecf20Sopenharmony_ci if (revision != ADT7462_REVISION) 17838c2ecf20Sopenharmony_ci return -ENODEV; 17848c2ecf20Sopenharmony_ci 17858c2ecf20Sopenharmony_ci strlcpy(info->type, "adt7462", I2C_NAME_SIZE); 17868c2ecf20Sopenharmony_ci 17878c2ecf20Sopenharmony_ci return 0; 17888c2ecf20Sopenharmony_ci} 17898c2ecf20Sopenharmony_ci 17908c2ecf20Sopenharmony_cistatic int adt7462_probe(struct i2c_client *client) 17918c2ecf20Sopenharmony_ci{ 17928c2ecf20Sopenharmony_ci struct device *dev = &client->dev; 17938c2ecf20Sopenharmony_ci struct adt7462_data *data; 17948c2ecf20Sopenharmony_ci struct device *hwmon_dev; 17958c2ecf20Sopenharmony_ci 17968c2ecf20Sopenharmony_ci data = devm_kzalloc(dev, sizeof(struct adt7462_data), GFP_KERNEL); 17978c2ecf20Sopenharmony_ci if (!data) 17988c2ecf20Sopenharmony_ci return -ENOMEM; 17998c2ecf20Sopenharmony_ci 18008c2ecf20Sopenharmony_ci data->client = client; 18018c2ecf20Sopenharmony_ci mutex_init(&data->lock); 18028c2ecf20Sopenharmony_ci 18038c2ecf20Sopenharmony_ci dev_info(&client->dev, "%s chip found\n", client->name); 18048c2ecf20Sopenharmony_ci 18058c2ecf20Sopenharmony_ci hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, 18068c2ecf20Sopenharmony_ci data, 18078c2ecf20Sopenharmony_ci adt7462_groups); 18088c2ecf20Sopenharmony_ci return PTR_ERR_OR_ZERO(hwmon_dev); 18098c2ecf20Sopenharmony_ci} 18108c2ecf20Sopenharmony_ci 18118c2ecf20Sopenharmony_cistatic const struct i2c_device_id adt7462_id[] = { 18128c2ecf20Sopenharmony_ci { "adt7462", 0 }, 18138c2ecf20Sopenharmony_ci { } 18148c2ecf20Sopenharmony_ci}; 18158c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, adt7462_id); 18168c2ecf20Sopenharmony_ci 18178c2ecf20Sopenharmony_cistatic struct i2c_driver adt7462_driver = { 18188c2ecf20Sopenharmony_ci .class = I2C_CLASS_HWMON, 18198c2ecf20Sopenharmony_ci .driver = { 18208c2ecf20Sopenharmony_ci .name = "adt7462", 18218c2ecf20Sopenharmony_ci }, 18228c2ecf20Sopenharmony_ci .probe_new = adt7462_probe, 18238c2ecf20Sopenharmony_ci .id_table = adt7462_id, 18248c2ecf20Sopenharmony_ci .detect = adt7462_detect, 18258c2ecf20Sopenharmony_ci .address_list = normal_i2c, 18268c2ecf20Sopenharmony_ci}; 18278c2ecf20Sopenharmony_ci 18288c2ecf20Sopenharmony_cimodule_i2c_driver(adt7462_driver); 18298c2ecf20Sopenharmony_ci 18308c2ecf20Sopenharmony_ciMODULE_AUTHOR("Darrick J. Wong <darrick.wong@oracle.com>"); 18318c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("ADT7462 driver"); 18328c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 1833