18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Driver for 48c2ecf20Sopenharmony_ci * Maxim MAX16065/MAX16066 12-Channel/8-Channel, Flash-Configurable 58c2ecf20Sopenharmony_ci * System Managers with Nonvolatile Fault Registers 68c2ecf20Sopenharmony_ci * Maxim MAX16067/MAX16068 6-Channel, Flash-Configurable System Managers 78c2ecf20Sopenharmony_ci * with Nonvolatile Fault Registers 88c2ecf20Sopenharmony_ci * Maxim MAX16070/MAX16071 12-Channel/8-Channel, Flash-Configurable System 98c2ecf20Sopenharmony_ci * Monitors with Nonvolatile Fault Registers 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * Copyright (C) 2011 Ericsson AB. 128c2ecf20Sopenharmony_ci */ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <linux/kernel.h> 158c2ecf20Sopenharmony_ci#include <linux/module.h> 168c2ecf20Sopenharmony_ci#include <linux/init.h> 178c2ecf20Sopenharmony_ci#include <linux/err.h> 188c2ecf20Sopenharmony_ci#include <linux/slab.h> 198c2ecf20Sopenharmony_ci#include <linux/i2c.h> 208c2ecf20Sopenharmony_ci#include <linux/hwmon.h> 218c2ecf20Sopenharmony_ci#include <linux/hwmon-sysfs.h> 228c2ecf20Sopenharmony_ci#include <linux/jiffies.h> 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cienum chips { max16065, max16066, max16067, max16068, max16070, max16071 }; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci/* 278c2ecf20Sopenharmony_ci * Registers 288c2ecf20Sopenharmony_ci */ 298c2ecf20Sopenharmony_ci#define MAX16065_ADC(x) ((x) * 2) 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#define MAX16065_CURR_SENSE 0x18 328c2ecf20Sopenharmony_ci#define MAX16065_CSP_ADC 0x19 338c2ecf20Sopenharmony_ci#define MAX16065_FAULT(x) (0x1b + (x)) 348c2ecf20Sopenharmony_ci#define MAX16065_SCALE(x) (0x43 + (x)) 358c2ecf20Sopenharmony_ci#define MAX16065_CURR_CONTROL 0x47 368c2ecf20Sopenharmony_ci#define MAX16065_LIMIT(l, x) (0x48 + (l) + (x) * 3) /* 378c2ecf20Sopenharmony_ci * l: limit 388c2ecf20Sopenharmony_ci * 0: min/max 398c2ecf20Sopenharmony_ci * 1: crit 408c2ecf20Sopenharmony_ci * 2: lcrit 418c2ecf20Sopenharmony_ci * x: ADC index 428c2ecf20Sopenharmony_ci */ 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#define MAX16065_SW_ENABLE 0x73 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define MAX16065_WARNING_OV (1 << 3) /* Set if secondary threshold is OV 478c2ecf20Sopenharmony_ci warning */ 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#define MAX16065_CURR_ENABLE (1 << 0) 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#define MAX16065_NUM_LIMIT 3 528c2ecf20Sopenharmony_ci#define MAX16065_NUM_ADC 12 /* maximum number of ADC channels */ 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistatic const int max16065_num_adc[] = { 558c2ecf20Sopenharmony_ci [max16065] = 12, 568c2ecf20Sopenharmony_ci [max16066] = 8, 578c2ecf20Sopenharmony_ci [max16067] = 6, 588c2ecf20Sopenharmony_ci [max16068] = 6, 598c2ecf20Sopenharmony_ci [max16070] = 12, 608c2ecf20Sopenharmony_ci [max16071] = 8, 618c2ecf20Sopenharmony_ci}; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cistatic const bool max16065_have_secondary[] = { 648c2ecf20Sopenharmony_ci [max16065] = true, 658c2ecf20Sopenharmony_ci [max16066] = true, 668c2ecf20Sopenharmony_ci [max16067] = false, 678c2ecf20Sopenharmony_ci [max16068] = false, 688c2ecf20Sopenharmony_ci [max16070] = true, 698c2ecf20Sopenharmony_ci [max16071] = true, 708c2ecf20Sopenharmony_ci}; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistatic const bool max16065_have_current[] = { 738c2ecf20Sopenharmony_ci [max16065] = true, 748c2ecf20Sopenharmony_ci [max16066] = true, 758c2ecf20Sopenharmony_ci [max16067] = false, 768c2ecf20Sopenharmony_ci [max16068] = false, 778c2ecf20Sopenharmony_ci [max16070] = true, 788c2ecf20Sopenharmony_ci [max16071] = true, 798c2ecf20Sopenharmony_ci}; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cistruct max16065_data { 828c2ecf20Sopenharmony_ci enum chips type; 838c2ecf20Sopenharmony_ci struct i2c_client *client; 848c2ecf20Sopenharmony_ci const struct attribute_group *groups[4]; 858c2ecf20Sopenharmony_ci struct mutex update_lock; 868c2ecf20Sopenharmony_ci bool valid; 878c2ecf20Sopenharmony_ci unsigned long last_updated; /* in jiffies */ 888c2ecf20Sopenharmony_ci int num_adc; 898c2ecf20Sopenharmony_ci bool have_current; 908c2ecf20Sopenharmony_ci int curr_gain; 918c2ecf20Sopenharmony_ci /* limits are in mV */ 928c2ecf20Sopenharmony_ci int limit[MAX16065_NUM_LIMIT][MAX16065_NUM_ADC]; 938c2ecf20Sopenharmony_ci int range[MAX16065_NUM_ADC + 1];/* voltage range */ 948c2ecf20Sopenharmony_ci int adc[MAX16065_NUM_ADC + 1]; /* adc values (raw) including csp_adc */ 958c2ecf20Sopenharmony_ci int curr_sense; 968c2ecf20Sopenharmony_ci int fault[2]; 978c2ecf20Sopenharmony_ci}; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_cistatic const int max16065_adc_range[] = { 5560, 2780, 1390, 0 }; 1008c2ecf20Sopenharmony_cistatic const int max16065_csp_adc_range[] = { 7000, 14000 }; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci/* ADC registers have 10 bit resolution. */ 1038c2ecf20Sopenharmony_cistatic inline int ADC_TO_MV(int adc, int range) 1048c2ecf20Sopenharmony_ci{ 1058c2ecf20Sopenharmony_ci return (adc * range) / 1024; 1068c2ecf20Sopenharmony_ci} 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci/* 1098c2ecf20Sopenharmony_ci * Limit registers have 8 bit resolution and match upper 8 bits of ADC 1108c2ecf20Sopenharmony_ci * registers. 1118c2ecf20Sopenharmony_ci */ 1128c2ecf20Sopenharmony_cistatic inline int LIMIT_TO_MV(int limit, int range) 1138c2ecf20Sopenharmony_ci{ 1148c2ecf20Sopenharmony_ci return limit * range / 256; 1158c2ecf20Sopenharmony_ci} 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_cistatic inline int MV_TO_LIMIT(int mv, int range) 1188c2ecf20Sopenharmony_ci{ 1198c2ecf20Sopenharmony_ci return clamp_val(DIV_ROUND_CLOSEST(mv * 256, range), 0, 255); 1208c2ecf20Sopenharmony_ci} 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_cistatic inline int ADC_TO_CURR(int adc, int gain) 1238c2ecf20Sopenharmony_ci{ 1248c2ecf20Sopenharmony_ci return adc * 1400000 / (gain * 255); 1258c2ecf20Sopenharmony_ci} 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci/* 1288c2ecf20Sopenharmony_ci * max16065_read_adc() 1298c2ecf20Sopenharmony_ci * 1308c2ecf20Sopenharmony_ci * Read 16 bit value from <reg>, <reg+1>. 1318c2ecf20Sopenharmony_ci * Upper 8 bits are in <reg>, lower 2 bits are in bits 7:6 of <reg+1>. 1328c2ecf20Sopenharmony_ci */ 1338c2ecf20Sopenharmony_cistatic int max16065_read_adc(struct i2c_client *client, int reg) 1348c2ecf20Sopenharmony_ci{ 1358c2ecf20Sopenharmony_ci int rv; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci rv = i2c_smbus_read_word_swapped(client, reg); 1388c2ecf20Sopenharmony_ci if (unlikely(rv < 0)) 1398c2ecf20Sopenharmony_ci return rv; 1408c2ecf20Sopenharmony_ci return rv >> 6; 1418c2ecf20Sopenharmony_ci} 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistatic struct max16065_data *max16065_update_device(struct device *dev) 1448c2ecf20Sopenharmony_ci{ 1458c2ecf20Sopenharmony_ci struct max16065_data *data = dev_get_drvdata(dev); 1468c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci mutex_lock(&data->update_lock); 1498c2ecf20Sopenharmony_ci if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 1508c2ecf20Sopenharmony_ci int i; 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci for (i = 0; i < data->num_adc; i++) 1538c2ecf20Sopenharmony_ci data->adc[i] 1548c2ecf20Sopenharmony_ci = max16065_read_adc(client, MAX16065_ADC(i)); 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci if (data->have_current) { 1578c2ecf20Sopenharmony_ci data->adc[MAX16065_NUM_ADC] 1588c2ecf20Sopenharmony_ci = max16065_read_adc(client, MAX16065_CSP_ADC); 1598c2ecf20Sopenharmony_ci data->curr_sense 1608c2ecf20Sopenharmony_ci = i2c_smbus_read_byte_data(client, 1618c2ecf20Sopenharmony_ci MAX16065_CURR_SENSE); 1628c2ecf20Sopenharmony_ci } 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci for (i = 0; i < DIV_ROUND_UP(data->num_adc, 8); i++) 1658c2ecf20Sopenharmony_ci data->fault[i] 1668c2ecf20Sopenharmony_ci = i2c_smbus_read_byte_data(client, MAX16065_FAULT(i)); 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci data->last_updated = jiffies; 1698c2ecf20Sopenharmony_ci data->valid = 1; 1708c2ecf20Sopenharmony_ci } 1718c2ecf20Sopenharmony_ci mutex_unlock(&data->update_lock); 1728c2ecf20Sopenharmony_ci return data; 1738c2ecf20Sopenharmony_ci} 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_cistatic ssize_t max16065_alarm_show(struct device *dev, 1768c2ecf20Sopenharmony_ci struct device_attribute *da, char *buf) 1778c2ecf20Sopenharmony_ci{ 1788c2ecf20Sopenharmony_ci struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da); 1798c2ecf20Sopenharmony_ci struct max16065_data *data = max16065_update_device(dev); 1808c2ecf20Sopenharmony_ci int val = data->fault[attr2->nr]; 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci if (val < 0) 1838c2ecf20Sopenharmony_ci return val; 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci val &= (1 << attr2->index); 1868c2ecf20Sopenharmony_ci if (val) 1878c2ecf20Sopenharmony_ci i2c_smbus_write_byte_data(data->client, 1888c2ecf20Sopenharmony_ci MAX16065_FAULT(attr2->nr), val); 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci return snprintf(buf, PAGE_SIZE, "%d\n", !!val); 1918c2ecf20Sopenharmony_ci} 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_cistatic ssize_t max16065_input_show(struct device *dev, 1948c2ecf20Sopenharmony_ci struct device_attribute *da, char *buf) 1958c2ecf20Sopenharmony_ci{ 1968c2ecf20Sopenharmony_ci struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 1978c2ecf20Sopenharmony_ci struct max16065_data *data = max16065_update_device(dev); 1988c2ecf20Sopenharmony_ci int adc = data->adc[attr->index]; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci if (unlikely(adc < 0)) 2018c2ecf20Sopenharmony_ci return adc; 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci return snprintf(buf, PAGE_SIZE, "%d\n", 2048c2ecf20Sopenharmony_ci ADC_TO_MV(adc, data->range[attr->index])); 2058c2ecf20Sopenharmony_ci} 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_cistatic ssize_t max16065_current_show(struct device *dev, 2088c2ecf20Sopenharmony_ci struct device_attribute *da, char *buf) 2098c2ecf20Sopenharmony_ci{ 2108c2ecf20Sopenharmony_ci struct max16065_data *data = max16065_update_device(dev); 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci if (unlikely(data->curr_sense < 0)) 2138c2ecf20Sopenharmony_ci return data->curr_sense; 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci return snprintf(buf, PAGE_SIZE, "%d\n", 2168c2ecf20Sopenharmony_ci ADC_TO_CURR(data->curr_sense, data->curr_gain)); 2178c2ecf20Sopenharmony_ci} 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_cistatic ssize_t max16065_limit_store(struct device *dev, 2208c2ecf20Sopenharmony_ci struct device_attribute *da, 2218c2ecf20Sopenharmony_ci const char *buf, size_t count) 2228c2ecf20Sopenharmony_ci{ 2238c2ecf20Sopenharmony_ci struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da); 2248c2ecf20Sopenharmony_ci struct max16065_data *data = dev_get_drvdata(dev); 2258c2ecf20Sopenharmony_ci unsigned long val; 2268c2ecf20Sopenharmony_ci int err; 2278c2ecf20Sopenharmony_ci int limit; 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci err = kstrtoul(buf, 10, &val); 2308c2ecf20Sopenharmony_ci if (unlikely(err < 0)) 2318c2ecf20Sopenharmony_ci return err; 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci limit = MV_TO_LIMIT(val, data->range[attr2->index]); 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci mutex_lock(&data->update_lock); 2368c2ecf20Sopenharmony_ci data->limit[attr2->nr][attr2->index] 2378c2ecf20Sopenharmony_ci = LIMIT_TO_MV(limit, data->range[attr2->index]); 2388c2ecf20Sopenharmony_ci i2c_smbus_write_byte_data(data->client, 2398c2ecf20Sopenharmony_ci MAX16065_LIMIT(attr2->nr, attr2->index), 2408c2ecf20Sopenharmony_ci limit); 2418c2ecf20Sopenharmony_ci mutex_unlock(&data->update_lock); 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci return count; 2448c2ecf20Sopenharmony_ci} 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_cistatic ssize_t max16065_limit_show(struct device *dev, 2478c2ecf20Sopenharmony_ci struct device_attribute *da, char *buf) 2488c2ecf20Sopenharmony_ci{ 2498c2ecf20Sopenharmony_ci struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da); 2508c2ecf20Sopenharmony_ci struct max16065_data *data = dev_get_drvdata(dev); 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci return snprintf(buf, PAGE_SIZE, "%d\n", 2538c2ecf20Sopenharmony_ci data->limit[attr2->nr][attr2->index]); 2548c2ecf20Sopenharmony_ci} 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci/* Construct a sensor_device_attribute structure for each register */ 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci/* Input voltages */ 2598c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in0_input, max16065_input, 0); 2608c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in1_input, max16065_input, 1); 2618c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in2_input, max16065_input, 2); 2628c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in3_input, max16065_input, 3); 2638c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in4_input, max16065_input, 4); 2648c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in5_input, max16065_input, 5); 2658c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in6_input, max16065_input, 6); 2668c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in7_input, max16065_input, 7); 2678c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in8_input, max16065_input, 8); 2688c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in9_input, max16065_input, 9); 2698c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in10_input, max16065_input, 10); 2708c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in11_input, max16065_input, 11); 2718c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in12_input, max16065_input, 12); 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci/* Input voltages lcrit */ 2748c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in0_lcrit, max16065_limit, 2, 0); 2758c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in1_lcrit, max16065_limit, 2, 1); 2768c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in2_lcrit, max16065_limit, 2, 2); 2778c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in3_lcrit, max16065_limit, 2, 3); 2788c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in4_lcrit, max16065_limit, 2, 4); 2798c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in5_lcrit, max16065_limit, 2, 5); 2808c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in6_lcrit, max16065_limit, 2, 6); 2818c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in7_lcrit, max16065_limit, 2, 7); 2828c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in8_lcrit, max16065_limit, 2, 8); 2838c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in9_lcrit, max16065_limit, 2, 9); 2848c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in10_lcrit, max16065_limit, 2, 10); 2858c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in11_lcrit, max16065_limit, 2, 11); 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci/* Input voltages crit */ 2888c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in0_crit, max16065_limit, 1, 0); 2898c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in1_crit, max16065_limit, 1, 1); 2908c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in2_crit, max16065_limit, 1, 2); 2918c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in3_crit, max16065_limit, 1, 3); 2928c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in4_crit, max16065_limit, 1, 4); 2938c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in5_crit, max16065_limit, 1, 5); 2948c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in6_crit, max16065_limit, 1, 6); 2958c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in7_crit, max16065_limit, 1, 7); 2968c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in8_crit, max16065_limit, 1, 8); 2978c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in9_crit, max16065_limit, 1, 9); 2988c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in10_crit, max16065_limit, 1, 10); 2998c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in11_crit, max16065_limit, 1, 11); 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci/* Input voltages min */ 3028c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in0_min, max16065_limit, 0, 0); 3038c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in1_min, max16065_limit, 0, 1); 3048c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in2_min, max16065_limit, 0, 2); 3058c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in3_min, max16065_limit, 0, 3); 3068c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in4_min, max16065_limit, 0, 4); 3078c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in5_min, max16065_limit, 0, 5); 3088c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in6_min, max16065_limit, 0, 6); 3098c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in7_min, max16065_limit, 0, 7); 3108c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in8_min, max16065_limit, 0, 8); 3118c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in9_min, max16065_limit, 0, 9); 3128c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in10_min, max16065_limit, 0, 10); 3138c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in11_min, max16065_limit, 0, 11); 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci/* Input voltages max */ 3168c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in0_max, max16065_limit, 0, 0); 3178c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in1_max, max16065_limit, 0, 1); 3188c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in2_max, max16065_limit, 0, 2); 3198c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in3_max, max16065_limit, 0, 3); 3208c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in4_max, max16065_limit, 0, 4); 3218c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in5_max, max16065_limit, 0, 5); 3228c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in6_max, max16065_limit, 0, 6); 3238c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in7_max, max16065_limit, 0, 7); 3248c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in8_max, max16065_limit, 0, 8); 3258c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in9_max, max16065_limit, 0, 9); 3268c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in10_max, max16065_limit, 0, 10); 3278c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RW(in11_max, max16065_limit, 0, 11); 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci/* alarms */ 3308c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RO(in0_alarm, max16065_alarm, 0, 0); 3318c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RO(in1_alarm, max16065_alarm, 0, 1); 3328c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RO(in2_alarm, max16065_alarm, 0, 2); 3338c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RO(in3_alarm, max16065_alarm, 0, 3); 3348c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RO(in4_alarm, max16065_alarm, 0, 4); 3358c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RO(in5_alarm, max16065_alarm, 0, 5); 3368c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RO(in6_alarm, max16065_alarm, 0, 6); 3378c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RO(in7_alarm, max16065_alarm, 0, 7); 3388c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RO(in8_alarm, max16065_alarm, 1, 0); 3398c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RO(in9_alarm, max16065_alarm, 1, 1); 3408c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RO(in10_alarm, max16065_alarm, 1, 2); 3418c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RO(in11_alarm, max16065_alarm, 1, 3); 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci/* Current and alarm */ 3448c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(curr1_input, max16065_current, 0); 3458c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_2_RO(curr1_alarm, max16065_alarm, 1, 4); 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci/* 3488c2ecf20Sopenharmony_ci * Finally, construct an array of pointers to members of the above objects, 3498c2ecf20Sopenharmony_ci * as required for sysfs_create_group() 3508c2ecf20Sopenharmony_ci */ 3518c2ecf20Sopenharmony_cistatic struct attribute *max16065_basic_attributes[] = { 3528c2ecf20Sopenharmony_ci &sensor_dev_attr_in0_input.dev_attr.attr, 3538c2ecf20Sopenharmony_ci &sensor_dev_attr_in0_lcrit.dev_attr.attr, 3548c2ecf20Sopenharmony_ci &sensor_dev_attr_in0_crit.dev_attr.attr, 3558c2ecf20Sopenharmony_ci &sensor_dev_attr_in0_alarm.dev_attr.attr, 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci &sensor_dev_attr_in1_input.dev_attr.attr, 3588c2ecf20Sopenharmony_ci &sensor_dev_attr_in1_lcrit.dev_attr.attr, 3598c2ecf20Sopenharmony_ci &sensor_dev_attr_in1_crit.dev_attr.attr, 3608c2ecf20Sopenharmony_ci &sensor_dev_attr_in1_alarm.dev_attr.attr, 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci &sensor_dev_attr_in2_input.dev_attr.attr, 3638c2ecf20Sopenharmony_ci &sensor_dev_attr_in2_lcrit.dev_attr.attr, 3648c2ecf20Sopenharmony_ci &sensor_dev_attr_in2_crit.dev_attr.attr, 3658c2ecf20Sopenharmony_ci &sensor_dev_attr_in2_alarm.dev_attr.attr, 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci &sensor_dev_attr_in3_input.dev_attr.attr, 3688c2ecf20Sopenharmony_ci &sensor_dev_attr_in3_lcrit.dev_attr.attr, 3698c2ecf20Sopenharmony_ci &sensor_dev_attr_in3_crit.dev_attr.attr, 3708c2ecf20Sopenharmony_ci &sensor_dev_attr_in3_alarm.dev_attr.attr, 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ci &sensor_dev_attr_in4_input.dev_attr.attr, 3738c2ecf20Sopenharmony_ci &sensor_dev_attr_in4_lcrit.dev_attr.attr, 3748c2ecf20Sopenharmony_ci &sensor_dev_attr_in4_crit.dev_attr.attr, 3758c2ecf20Sopenharmony_ci &sensor_dev_attr_in4_alarm.dev_attr.attr, 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci &sensor_dev_attr_in5_input.dev_attr.attr, 3788c2ecf20Sopenharmony_ci &sensor_dev_attr_in5_lcrit.dev_attr.attr, 3798c2ecf20Sopenharmony_ci &sensor_dev_attr_in5_crit.dev_attr.attr, 3808c2ecf20Sopenharmony_ci &sensor_dev_attr_in5_alarm.dev_attr.attr, 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_ci &sensor_dev_attr_in6_input.dev_attr.attr, 3838c2ecf20Sopenharmony_ci &sensor_dev_attr_in6_lcrit.dev_attr.attr, 3848c2ecf20Sopenharmony_ci &sensor_dev_attr_in6_crit.dev_attr.attr, 3858c2ecf20Sopenharmony_ci &sensor_dev_attr_in6_alarm.dev_attr.attr, 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci &sensor_dev_attr_in7_input.dev_attr.attr, 3888c2ecf20Sopenharmony_ci &sensor_dev_attr_in7_lcrit.dev_attr.attr, 3898c2ecf20Sopenharmony_ci &sensor_dev_attr_in7_crit.dev_attr.attr, 3908c2ecf20Sopenharmony_ci &sensor_dev_attr_in7_alarm.dev_attr.attr, 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci &sensor_dev_attr_in8_input.dev_attr.attr, 3938c2ecf20Sopenharmony_ci &sensor_dev_attr_in8_lcrit.dev_attr.attr, 3948c2ecf20Sopenharmony_ci &sensor_dev_attr_in8_crit.dev_attr.attr, 3958c2ecf20Sopenharmony_ci &sensor_dev_attr_in8_alarm.dev_attr.attr, 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci &sensor_dev_attr_in9_input.dev_attr.attr, 3988c2ecf20Sopenharmony_ci &sensor_dev_attr_in9_lcrit.dev_attr.attr, 3998c2ecf20Sopenharmony_ci &sensor_dev_attr_in9_crit.dev_attr.attr, 4008c2ecf20Sopenharmony_ci &sensor_dev_attr_in9_alarm.dev_attr.attr, 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ci &sensor_dev_attr_in10_input.dev_attr.attr, 4038c2ecf20Sopenharmony_ci &sensor_dev_attr_in10_lcrit.dev_attr.attr, 4048c2ecf20Sopenharmony_ci &sensor_dev_attr_in10_crit.dev_attr.attr, 4058c2ecf20Sopenharmony_ci &sensor_dev_attr_in10_alarm.dev_attr.attr, 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci &sensor_dev_attr_in11_input.dev_attr.attr, 4088c2ecf20Sopenharmony_ci &sensor_dev_attr_in11_lcrit.dev_attr.attr, 4098c2ecf20Sopenharmony_ci &sensor_dev_attr_in11_crit.dev_attr.attr, 4108c2ecf20Sopenharmony_ci &sensor_dev_attr_in11_alarm.dev_attr.attr, 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci NULL 4138c2ecf20Sopenharmony_ci}; 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_cistatic struct attribute *max16065_current_attributes[] = { 4168c2ecf20Sopenharmony_ci &sensor_dev_attr_in12_input.dev_attr.attr, 4178c2ecf20Sopenharmony_ci &sensor_dev_attr_curr1_input.dev_attr.attr, 4188c2ecf20Sopenharmony_ci &sensor_dev_attr_curr1_alarm.dev_attr.attr, 4198c2ecf20Sopenharmony_ci NULL 4208c2ecf20Sopenharmony_ci}; 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_cistatic struct attribute *max16065_min_attributes[] = { 4238c2ecf20Sopenharmony_ci &sensor_dev_attr_in0_min.dev_attr.attr, 4248c2ecf20Sopenharmony_ci &sensor_dev_attr_in1_min.dev_attr.attr, 4258c2ecf20Sopenharmony_ci &sensor_dev_attr_in2_min.dev_attr.attr, 4268c2ecf20Sopenharmony_ci &sensor_dev_attr_in3_min.dev_attr.attr, 4278c2ecf20Sopenharmony_ci &sensor_dev_attr_in4_min.dev_attr.attr, 4288c2ecf20Sopenharmony_ci &sensor_dev_attr_in5_min.dev_attr.attr, 4298c2ecf20Sopenharmony_ci &sensor_dev_attr_in6_min.dev_attr.attr, 4308c2ecf20Sopenharmony_ci &sensor_dev_attr_in7_min.dev_attr.attr, 4318c2ecf20Sopenharmony_ci &sensor_dev_attr_in8_min.dev_attr.attr, 4328c2ecf20Sopenharmony_ci &sensor_dev_attr_in9_min.dev_attr.attr, 4338c2ecf20Sopenharmony_ci &sensor_dev_attr_in10_min.dev_attr.attr, 4348c2ecf20Sopenharmony_ci &sensor_dev_attr_in11_min.dev_attr.attr, 4358c2ecf20Sopenharmony_ci NULL 4368c2ecf20Sopenharmony_ci}; 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_cistatic struct attribute *max16065_max_attributes[] = { 4398c2ecf20Sopenharmony_ci &sensor_dev_attr_in0_max.dev_attr.attr, 4408c2ecf20Sopenharmony_ci &sensor_dev_attr_in1_max.dev_attr.attr, 4418c2ecf20Sopenharmony_ci &sensor_dev_attr_in2_max.dev_attr.attr, 4428c2ecf20Sopenharmony_ci &sensor_dev_attr_in3_max.dev_attr.attr, 4438c2ecf20Sopenharmony_ci &sensor_dev_attr_in4_max.dev_attr.attr, 4448c2ecf20Sopenharmony_ci &sensor_dev_attr_in5_max.dev_attr.attr, 4458c2ecf20Sopenharmony_ci &sensor_dev_attr_in6_max.dev_attr.attr, 4468c2ecf20Sopenharmony_ci &sensor_dev_attr_in7_max.dev_attr.attr, 4478c2ecf20Sopenharmony_ci &sensor_dev_attr_in8_max.dev_attr.attr, 4488c2ecf20Sopenharmony_ci &sensor_dev_attr_in9_max.dev_attr.attr, 4498c2ecf20Sopenharmony_ci &sensor_dev_attr_in10_max.dev_attr.attr, 4508c2ecf20Sopenharmony_ci &sensor_dev_attr_in11_max.dev_attr.attr, 4518c2ecf20Sopenharmony_ci NULL 4528c2ecf20Sopenharmony_ci}; 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_cistatic umode_t max16065_basic_is_visible(struct kobject *kobj, 4558c2ecf20Sopenharmony_ci struct attribute *a, int n) 4568c2ecf20Sopenharmony_ci{ 4578c2ecf20Sopenharmony_ci struct device *dev = container_of(kobj, struct device, kobj); 4588c2ecf20Sopenharmony_ci struct max16065_data *data = dev_get_drvdata(dev); 4598c2ecf20Sopenharmony_ci int index = n / 4; 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci if (index >= data->num_adc || !data->range[index]) 4628c2ecf20Sopenharmony_ci return 0; 4638c2ecf20Sopenharmony_ci return a->mode; 4648c2ecf20Sopenharmony_ci} 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_cistatic umode_t max16065_secondary_is_visible(struct kobject *kobj, 4678c2ecf20Sopenharmony_ci struct attribute *a, int index) 4688c2ecf20Sopenharmony_ci{ 4698c2ecf20Sopenharmony_ci struct device *dev = container_of(kobj, struct device, kobj); 4708c2ecf20Sopenharmony_ci struct max16065_data *data = dev_get_drvdata(dev); 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_ci if (index >= data->num_adc) 4738c2ecf20Sopenharmony_ci return 0; 4748c2ecf20Sopenharmony_ci return a->mode; 4758c2ecf20Sopenharmony_ci} 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_cistatic const struct attribute_group max16065_basic_group = { 4788c2ecf20Sopenharmony_ci .attrs = max16065_basic_attributes, 4798c2ecf20Sopenharmony_ci .is_visible = max16065_basic_is_visible, 4808c2ecf20Sopenharmony_ci}; 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_cistatic const struct attribute_group max16065_current_group = { 4838c2ecf20Sopenharmony_ci .attrs = max16065_current_attributes, 4848c2ecf20Sopenharmony_ci}; 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_cistatic const struct attribute_group max16065_min_group = { 4878c2ecf20Sopenharmony_ci .attrs = max16065_min_attributes, 4888c2ecf20Sopenharmony_ci .is_visible = max16065_secondary_is_visible, 4898c2ecf20Sopenharmony_ci}; 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_cistatic const struct attribute_group max16065_max_group = { 4928c2ecf20Sopenharmony_ci .attrs = max16065_max_attributes, 4938c2ecf20Sopenharmony_ci .is_visible = max16065_secondary_is_visible, 4948c2ecf20Sopenharmony_ci}; 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_cistatic const struct i2c_device_id max16065_id[]; 4978c2ecf20Sopenharmony_ci 4988c2ecf20Sopenharmony_cistatic int max16065_probe(struct i2c_client *client) 4998c2ecf20Sopenharmony_ci{ 5008c2ecf20Sopenharmony_ci struct i2c_adapter *adapter = client->adapter; 5018c2ecf20Sopenharmony_ci struct max16065_data *data; 5028c2ecf20Sopenharmony_ci struct device *dev = &client->dev; 5038c2ecf20Sopenharmony_ci struct device *hwmon_dev; 5048c2ecf20Sopenharmony_ci int i, j, val; 5058c2ecf20Sopenharmony_ci bool have_secondary; /* true if chip has secondary limits */ 5068c2ecf20Sopenharmony_ci bool secondary_is_max = false; /* secondary limits reflect max */ 5078c2ecf20Sopenharmony_ci int groups = 0; 5088c2ecf20Sopenharmony_ci const struct i2c_device_id *id = i2c_match_id(max16065_id, client); 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA 5118c2ecf20Sopenharmony_ci | I2C_FUNC_SMBUS_READ_WORD_DATA)) 5128c2ecf20Sopenharmony_ci return -ENODEV; 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 5158c2ecf20Sopenharmony_ci if (unlikely(!data)) 5168c2ecf20Sopenharmony_ci return -ENOMEM; 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci data->client = client; 5198c2ecf20Sopenharmony_ci mutex_init(&data->update_lock); 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci data->num_adc = max16065_num_adc[id->driver_data]; 5228c2ecf20Sopenharmony_ci data->have_current = max16065_have_current[id->driver_data]; 5238c2ecf20Sopenharmony_ci have_secondary = max16065_have_secondary[id->driver_data]; 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci if (have_secondary) { 5268c2ecf20Sopenharmony_ci val = i2c_smbus_read_byte_data(client, MAX16065_SW_ENABLE); 5278c2ecf20Sopenharmony_ci if (unlikely(val < 0)) 5288c2ecf20Sopenharmony_ci return val; 5298c2ecf20Sopenharmony_ci secondary_is_max = val & MAX16065_WARNING_OV; 5308c2ecf20Sopenharmony_ci } 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_ci /* Read scale registers, convert to range */ 5338c2ecf20Sopenharmony_ci for (i = 0; i < DIV_ROUND_UP(data->num_adc, 4); i++) { 5348c2ecf20Sopenharmony_ci val = i2c_smbus_read_byte_data(client, MAX16065_SCALE(i)); 5358c2ecf20Sopenharmony_ci if (unlikely(val < 0)) 5368c2ecf20Sopenharmony_ci return val; 5378c2ecf20Sopenharmony_ci for (j = 0; j < 4 && i * 4 + j < data->num_adc; j++) { 5388c2ecf20Sopenharmony_ci data->range[i * 4 + j] = 5398c2ecf20Sopenharmony_ci max16065_adc_range[(val >> (j * 2)) & 0x3]; 5408c2ecf20Sopenharmony_ci } 5418c2ecf20Sopenharmony_ci } 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci /* Read limits */ 5448c2ecf20Sopenharmony_ci for (i = 0; i < MAX16065_NUM_LIMIT; i++) { 5458c2ecf20Sopenharmony_ci if (i == 0 && !have_secondary) 5468c2ecf20Sopenharmony_ci continue; 5478c2ecf20Sopenharmony_ci 5488c2ecf20Sopenharmony_ci for (j = 0; j < data->num_adc; j++) { 5498c2ecf20Sopenharmony_ci val = i2c_smbus_read_byte_data(client, 5508c2ecf20Sopenharmony_ci MAX16065_LIMIT(i, j)); 5518c2ecf20Sopenharmony_ci if (unlikely(val < 0)) 5528c2ecf20Sopenharmony_ci return val; 5538c2ecf20Sopenharmony_ci data->limit[i][j] = LIMIT_TO_MV(val, data->range[j]); 5548c2ecf20Sopenharmony_ci } 5558c2ecf20Sopenharmony_ci } 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci /* sysfs hooks */ 5588c2ecf20Sopenharmony_ci data->groups[groups++] = &max16065_basic_group; 5598c2ecf20Sopenharmony_ci if (have_secondary) 5608c2ecf20Sopenharmony_ci data->groups[groups++] = secondary_is_max ? 5618c2ecf20Sopenharmony_ci &max16065_max_group : &max16065_min_group; 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ci if (data->have_current) { 5648c2ecf20Sopenharmony_ci val = i2c_smbus_read_byte_data(client, MAX16065_CURR_CONTROL); 5658c2ecf20Sopenharmony_ci if (unlikely(val < 0)) 5668c2ecf20Sopenharmony_ci return val; 5678c2ecf20Sopenharmony_ci if (val & MAX16065_CURR_ENABLE) { 5688c2ecf20Sopenharmony_ci /* 5698c2ecf20Sopenharmony_ci * Current gain is 6, 12, 24, 48 based on values in 5708c2ecf20Sopenharmony_ci * bit 2,3. 5718c2ecf20Sopenharmony_ci */ 5728c2ecf20Sopenharmony_ci data->curr_gain = 6 << ((val >> 2) & 0x03); 5738c2ecf20Sopenharmony_ci data->range[MAX16065_NUM_ADC] 5748c2ecf20Sopenharmony_ci = max16065_csp_adc_range[(val >> 1) & 0x01]; 5758c2ecf20Sopenharmony_ci data->groups[groups++] = &max16065_current_group; 5768c2ecf20Sopenharmony_ci } else { 5778c2ecf20Sopenharmony_ci data->have_current = false; 5788c2ecf20Sopenharmony_ci } 5798c2ecf20Sopenharmony_ci } 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, 5828c2ecf20Sopenharmony_ci data, data->groups); 5838c2ecf20Sopenharmony_ci return PTR_ERR_OR_ZERO(hwmon_dev); 5848c2ecf20Sopenharmony_ci} 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_cistatic const struct i2c_device_id max16065_id[] = { 5878c2ecf20Sopenharmony_ci { "max16065", max16065 }, 5888c2ecf20Sopenharmony_ci { "max16066", max16066 }, 5898c2ecf20Sopenharmony_ci { "max16067", max16067 }, 5908c2ecf20Sopenharmony_ci { "max16068", max16068 }, 5918c2ecf20Sopenharmony_ci { "max16070", max16070 }, 5928c2ecf20Sopenharmony_ci { "max16071", max16071 }, 5938c2ecf20Sopenharmony_ci { } 5948c2ecf20Sopenharmony_ci}; 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, max16065_id); 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_ci/* This is the driver that will be inserted */ 5998c2ecf20Sopenharmony_cistatic struct i2c_driver max16065_driver = { 6008c2ecf20Sopenharmony_ci .driver = { 6018c2ecf20Sopenharmony_ci .name = "max16065", 6028c2ecf20Sopenharmony_ci }, 6038c2ecf20Sopenharmony_ci .probe_new = max16065_probe, 6048c2ecf20Sopenharmony_ci .id_table = max16065_id, 6058c2ecf20Sopenharmony_ci}; 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_cimodule_i2c_driver(max16065_driver); 6088c2ecf20Sopenharmony_ci 6098c2ecf20Sopenharmony_ciMODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>"); 6108c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("MAX16065 driver"); 6118c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 612