18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * powr1220.c - Driver for the Lattice POWR1220 programmable power supply
48c2ecf20Sopenharmony_ci * and monitor. Users can read all ADC inputs along with their labels
58c2ecf20Sopenharmony_ci * using the sysfs nodes.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright (c) 2014 Echo360 https://www.echo360.com
88c2ecf20Sopenharmony_ci * Scott Kanowitz <skanowitz@echo360.com> <scott.kanowitz@gmail.com>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/module.h>
128c2ecf20Sopenharmony_ci#include <linux/init.h>
138c2ecf20Sopenharmony_ci#include <linux/slab.h>
148c2ecf20Sopenharmony_ci#include <linux/jiffies.h>
158c2ecf20Sopenharmony_ci#include <linux/i2c.h>
168c2ecf20Sopenharmony_ci#include <linux/hwmon.h>
178c2ecf20Sopenharmony_ci#include <linux/hwmon-sysfs.h>
188c2ecf20Sopenharmony_ci#include <linux/err.h>
198c2ecf20Sopenharmony_ci#include <linux/mutex.h>
208c2ecf20Sopenharmony_ci#include <linux/delay.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define ADC_STEP_MV			2
238c2ecf20Sopenharmony_ci#define ADC_MAX_LOW_MEASUREMENT_MV	2000
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cienum powr1220_regs {
268c2ecf20Sopenharmony_ci	VMON_STATUS0,
278c2ecf20Sopenharmony_ci	VMON_STATUS1,
288c2ecf20Sopenharmony_ci	VMON_STATUS2,
298c2ecf20Sopenharmony_ci	OUTPUT_STATUS0,
308c2ecf20Sopenharmony_ci	OUTPUT_STATUS1,
318c2ecf20Sopenharmony_ci	OUTPUT_STATUS2,
328c2ecf20Sopenharmony_ci	INPUT_STATUS,
338c2ecf20Sopenharmony_ci	ADC_VALUE_LOW,
348c2ecf20Sopenharmony_ci	ADC_VALUE_HIGH,
358c2ecf20Sopenharmony_ci	ADC_MUX,
368c2ecf20Sopenharmony_ci	UES_BYTE0,
378c2ecf20Sopenharmony_ci	UES_BYTE1,
388c2ecf20Sopenharmony_ci	UES_BYTE2,
398c2ecf20Sopenharmony_ci	UES_BYTE3,
408c2ecf20Sopenharmony_ci	GP_OUTPUT1,
418c2ecf20Sopenharmony_ci	GP_OUTPUT2,
428c2ecf20Sopenharmony_ci	GP_OUTPUT3,
438c2ecf20Sopenharmony_ci	INPUT_VALUE,
448c2ecf20Sopenharmony_ci	RESET,
458c2ecf20Sopenharmony_ci	TRIM1_TRIM,
468c2ecf20Sopenharmony_ci	TRIM2_TRIM,
478c2ecf20Sopenharmony_ci	TRIM3_TRIM,
488c2ecf20Sopenharmony_ci	TRIM4_TRIM,
498c2ecf20Sopenharmony_ci	TRIM5_TRIM,
508c2ecf20Sopenharmony_ci	TRIM6_TRIM,
518c2ecf20Sopenharmony_ci	TRIM7_TRIM,
528c2ecf20Sopenharmony_ci	TRIM8_TRIM,
538c2ecf20Sopenharmony_ci	MAX_POWR1220_REGS
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cienum powr1220_adc_values {
578c2ecf20Sopenharmony_ci	VMON1,
588c2ecf20Sopenharmony_ci	VMON2,
598c2ecf20Sopenharmony_ci	VMON3,
608c2ecf20Sopenharmony_ci	VMON4,
618c2ecf20Sopenharmony_ci	VMON5,
628c2ecf20Sopenharmony_ci	VMON6,
638c2ecf20Sopenharmony_ci	VMON7,
648c2ecf20Sopenharmony_ci	VMON8,
658c2ecf20Sopenharmony_ci	VMON9,
668c2ecf20Sopenharmony_ci	VMON10,
678c2ecf20Sopenharmony_ci	VMON11,
688c2ecf20Sopenharmony_ci	VMON12,
698c2ecf20Sopenharmony_ci	VCCA,
708c2ecf20Sopenharmony_ci	VCCINP,
718c2ecf20Sopenharmony_ci	MAX_POWR1220_ADC_VALUES
728c2ecf20Sopenharmony_ci};
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_cistruct powr1220_data {
758c2ecf20Sopenharmony_ci	struct i2c_client *client;
768c2ecf20Sopenharmony_ci	struct mutex update_lock;
778c2ecf20Sopenharmony_ci	bool adc_valid[MAX_POWR1220_ADC_VALUES];
788c2ecf20Sopenharmony_ci	 /* the next value is in jiffies */
798c2ecf20Sopenharmony_ci	unsigned long adc_last_updated[MAX_POWR1220_ADC_VALUES];
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	/* values */
828c2ecf20Sopenharmony_ci	int adc_maxes[MAX_POWR1220_ADC_VALUES];
838c2ecf20Sopenharmony_ci	int adc_values[MAX_POWR1220_ADC_VALUES];
848c2ecf20Sopenharmony_ci};
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_cistatic const char * const input_names[] = {
878c2ecf20Sopenharmony_ci	[VMON1]    = "vmon1",
888c2ecf20Sopenharmony_ci	[VMON2]    = "vmon2",
898c2ecf20Sopenharmony_ci	[VMON3]    = "vmon3",
908c2ecf20Sopenharmony_ci	[VMON4]    = "vmon4",
918c2ecf20Sopenharmony_ci	[VMON5]    = "vmon5",
928c2ecf20Sopenharmony_ci	[VMON6]    = "vmon6",
938c2ecf20Sopenharmony_ci	[VMON7]    = "vmon7",
948c2ecf20Sopenharmony_ci	[VMON8]    = "vmon8",
958c2ecf20Sopenharmony_ci	[VMON9]    = "vmon9",
968c2ecf20Sopenharmony_ci	[VMON10]   = "vmon10",
978c2ecf20Sopenharmony_ci	[VMON11]   = "vmon11",
988c2ecf20Sopenharmony_ci	[VMON12]   = "vmon12",
998c2ecf20Sopenharmony_ci	[VCCA]     = "vcca",
1008c2ecf20Sopenharmony_ci	[VCCINP]   = "vccinp",
1018c2ecf20Sopenharmony_ci};
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/* Reads the specified ADC channel */
1048c2ecf20Sopenharmony_cistatic int powr1220_read_adc(struct device *dev, int ch_num)
1058c2ecf20Sopenharmony_ci{
1068c2ecf20Sopenharmony_ci	struct powr1220_data *data = dev_get_drvdata(dev);
1078c2ecf20Sopenharmony_ci	int reading;
1088c2ecf20Sopenharmony_ci	int result;
1098c2ecf20Sopenharmony_ci	int adc_range = 0;
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci	mutex_lock(&data->update_lock);
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	if (time_after(jiffies, data->adc_last_updated[ch_num] + HZ) ||
1148c2ecf20Sopenharmony_ci			!data->adc_valid[ch_num]) {
1158c2ecf20Sopenharmony_ci		/*
1168c2ecf20Sopenharmony_ci		 * figure out if we need to use the attenuator for
1178c2ecf20Sopenharmony_ci		 * high inputs or inputs that we don't yet have a measurement
1188c2ecf20Sopenharmony_ci		 * for. We dynamically set the attenuator depending on the
1198c2ecf20Sopenharmony_ci		 * max reading.
1208c2ecf20Sopenharmony_ci		 */
1218c2ecf20Sopenharmony_ci		if (data->adc_maxes[ch_num] > ADC_MAX_LOW_MEASUREMENT_MV ||
1228c2ecf20Sopenharmony_ci				data->adc_maxes[ch_num] == 0)
1238c2ecf20Sopenharmony_ci			adc_range = 1 << 4;
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci		/* set the attenuator and mux */
1268c2ecf20Sopenharmony_ci		result = i2c_smbus_write_byte_data(data->client, ADC_MUX,
1278c2ecf20Sopenharmony_ci				adc_range | ch_num);
1288c2ecf20Sopenharmony_ci		if (result)
1298c2ecf20Sopenharmony_ci			goto exit;
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci		/*
1328c2ecf20Sopenharmony_ci		 * wait at least Tconvert time (200 us) for the
1338c2ecf20Sopenharmony_ci		 * conversion to complete
1348c2ecf20Sopenharmony_ci		 */
1358c2ecf20Sopenharmony_ci		udelay(200);
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci		/* get the ADC reading */
1388c2ecf20Sopenharmony_ci		result = i2c_smbus_read_byte_data(data->client, ADC_VALUE_LOW);
1398c2ecf20Sopenharmony_ci		if (result < 0)
1408c2ecf20Sopenharmony_ci			goto exit;
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci		reading = result >> 4;
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci		/* get the upper half of the reading */
1458c2ecf20Sopenharmony_ci		result = i2c_smbus_read_byte_data(data->client, ADC_VALUE_HIGH);
1468c2ecf20Sopenharmony_ci		if (result < 0)
1478c2ecf20Sopenharmony_ci			goto exit;
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci		reading |= result << 4;
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci		/* now convert the reading to a voltage */
1528c2ecf20Sopenharmony_ci		reading *= ADC_STEP_MV;
1538c2ecf20Sopenharmony_ci		data->adc_values[ch_num] = reading;
1548c2ecf20Sopenharmony_ci		data->adc_valid[ch_num] = true;
1558c2ecf20Sopenharmony_ci		data->adc_last_updated[ch_num] = jiffies;
1568c2ecf20Sopenharmony_ci		result = reading;
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci		if (reading > data->adc_maxes[ch_num])
1598c2ecf20Sopenharmony_ci			data->adc_maxes[ch_num] = reading;
1608c2ecf20Sopenharmony_ci	} else {
1618c2ecf20Sopenharmony_ci		result = data->adc_values[ch_num];
1628c2ecf20Sopenharmony_ci	}
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ciexit:
1658c2ecf20Sopenharmony_ci	mutex_unlock(&data->update_lock);
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci	return result;
1688c2ecf20Sopenharmony_ci}
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci/* Shows the voltage associated with the specified ADC channel */
1718c2ecf20Sopenharmony_cistatic ssize_t powr1220_voltage_show(struct device *dev,
1728c2ecf20Sopenharmony_ci				     struct device_attribute *dev_attr,
1738c2ecf20Sopenharmony_ci				     char *buf)
1748c2ecf20Sopenharmony_ci{
1758c2ecf20Sopenharmony_ci	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
1768c2ecf20Sopenharmony_ci	int adc_val = powr1220_read_adc(dev, attr->index);
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	if (adc_val < 0)
1798c2ecf20Sopenharmony_ci		return adc_val;
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", adc_val);
1828c2ecf20Sopenharmony_ci}
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci/* Shows the maximum setting associated with the specified ADC channel */
1858c2ecf20Sopenharmony_cistatic ssize_t powr1220_max_show(struct device *dev,
1868c2ecf20Sopenharmony_ci				 struct device_attribute *dev_attr, char *buf)
1878c2ecf20Sopenharmony_ci{
1888c2ecf20Sopenharmony_ci	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
1898c2ecf20Sopenharmony_ci	struct powr1220_data *data = dev_get_drvdata(dev);
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", data->adc_maxes[attr->index]);
1928c2ecf20Sopenharmony_ci}
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci/* Shows the label associated with the specified ADC channel */
1958c2ecf20Sopenharmony_cistatic ssize_t powr1220_label_show(struct device *dev,
1968c2ecf20Sopenharmony_ci				   struct device_attribute *dev_attr,
1978c2ecf20Sopenharmony_ci				   char *buf)
1988c2ecf20Sopenharmony_ci{
1998c2ecf20Sopenharmony_ci	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci	return sprintf(buf, "%s\n", input_names[attr->index]);
2028c2ecf20Sopenharmony_ci}
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in0_input, powr1220_voltage, VMON1);
2058c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in1_input, powr1220_voltage, VMON2);
2068c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in2_input, powr1220_voltage, VMON3);
2078c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in3_input, powr1220_voltage, VMON4);
2088c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in4_input, powr1220_voltage, VMON5);
2098c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in5_input, powr1220_voltage, VMON6);
2108c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in6_input, powr1220_voltage, VMON7);
2118c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in7_input, powr1220_voltage, VMON8);
2128c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in8_input, powr1220_voltage, VMON9);
2138c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in9_input, powr1220_voltage, VMON10);
2148c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in10_input, powr1220_voltage, VMON11);
2158c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in11_input, powr1220_voltage, VMON12);
2168c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in12_input, powr1220_voltage, VCCA);
2178c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in13_input, powr1220_voltage, VCCINP);
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in0_highest, powr1220_max, VMON1);
2208c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in1_highest, powr1220_max, VMON2);
2218c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in2_highest, powr1220_max, VMON3);
2228c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in3_highest, powr1220_max, VMON4);
2238c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in4_highest, powr1220_max, VMON5);
2248c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in5_highest, powr1220_max, VMON6);
2258c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in6_highest, powr1220_max, VMON7);
2268c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in7_highest, powr1220_max, VMON8);
2278c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in8_highest, powr1220_max, VMON9);
2288c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in9_highest, powr1220_max, VMON10);
2298c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in10_highest, powr1220_max, VMON11);
2308c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in11_highest, powr1220_max, VMON12);
2318c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in12_highest, powr1220_max, VCCA);
2328c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in13_highest, powr1220_max, VCCINP);
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in0_label, powr1220_label, VMON1);
2358c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in1_label, powr1220_label, VMON2);
2368c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in2_label, powr1220_label, VMON3);
2378c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in3_label, powr1220_label, VMON4);
2388c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in4_label, powr1220_label, VMON5);
2398c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in5_label, powr1220_label, VMON6);
2408c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in6_label, powr1220_label, VMON7);
2418c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in7_label, powr1220_label, VMON8);
2428c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in8_label, powr1220_label, VMON9);
2438c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in9_label, powr1220_label, VMON10);
2448c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in10_label, powr1220_label, VMON11);
2458c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in11_label, powr1220_label, VMON12);
2468c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in12_label, powr1220_label, VCCA);
2478c2ecf20Sopenharmony_cistatic SENSOR_DEVICE_ATTR_RO(in13_label, powr1220_label, VCCINP);
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_cistatic struct attribute *powr1220_attrs[] = {
2508c2ecf20Sopenharmony_ci	&sensor_dev_attr_in0_input.dev_attr.attr,
2518c2ecf20Sopenharmony_ci	&sensor_dev_attr_in1_input.dev_attr.attr,
2528c2ecf20Sopenharmony_ci	&sensor_dev_attr_in2_input.dev_attr.attr,
2538c2ecf20Sopenharmony_ci	&sensor_dev_attr_in3_input.dev_attr.attr,
2548c2ecf20Sopenharmony_ci	&sensor_dev_attr_in4_input.dev_attr.attr,
2558c2ecf20Sopenharmony_ci	&sensor_dev_attr_in5_input.dev_attr.attr,
2568c2ecf20Sopenharmony_ci	&sensor_dev_attr_in6_input.dev_attr.attr,
2578c2ecf20Sopenharmony_ci	&sensor_dev_attr_in7_input.dev_attr.attr,
2588c2ecf20Sopenharmony_ci	&sensor_dev_attr_in8_input.dev_attr.attr,
2598c2ecf20Sopenharmony_ci	&sensor_dev_attr_in9_input.dev_attr.attr,
2608c2ecf20Sopenharmony_ci	&sensor_dev_attr_in10_input.dev_attr.attr,
2618c2ecf20Sopenharmony_ci	&sensor_dev_attr_in11_input.dev_attr.attr,
2628c2ecf20Sopenharmony_ci	&sensor_dev_attr_in12_input.dev_attr.attr,
2638c2ecf20Sopenharmony_ci	&sensor_dev_attr_in13_input.dev_attr.attr,
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	&sensor_dev_attr_in0_highest.dev_attr.attr,
2668c2ecf20Sopenharmony_ci	&sensor_dev_attr_in1_highest.dev_attr.attr,
2678c2ecf20Sopenharmony_ci	&sensor_dev_attr_in2_highest.dev_attr.attr,
2688c2ecf20Sopenharmony_ci	&sensor_dev_attr_in3_highest.dev_attr.attr,
2698c2ecf20Sopenharmony_ci	&sensor_dev_attr_in4_highest.dev_attr.attr,
2708c2ecf20Sopenharmony_ci	&sensor_dev_attr_in5_highest.dev_attr.attr,
2718c2ecf20Sopenharmony_ci	&sensor_dev_attr_in6_highest.dev_attr.attr,
2728c2ecf20Sopenharmony_ci	&sensor_dev_attr_in7_highest.dev_attr.attr,
2738c2ecf20Sopenharmony_ci	&sensor_dev_attr_in8_highest.dev_attr.attr,
2748c2ecf20Sopenharmony_ci	&sensor_dev_attr_in9_highest.dev_attr.attr,
2758c2ecf20Sopenharmony_ci	&sensor_dev_attr_in10_highest.dev_attr.attr,
2768c2ecf20Sopenharmony_ci	&sensor_dev_attr_in11_highest.dev_attr.attr,
2778c2ecf20Sopenharmony_ci	&sensor_dev_attr_in12_highest.dev_attr.attr,
2788c2ecf20Sopenharmony_ci	&sensor_dev_attr_in13_highest.dev_attr.attr,
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci	&sensor_dev_attr_in0_label.dev_attr.attr,
2818c2ecf20Sopenharmony_ci	&sensor_dev_attr_in1_label.dev_attr.attr,
2828c2ecf20Sopenharmony_ci	&sensor_dev_attr_in2_label.dev_attr.attr,
2838c2ecf20Sopenharmony_ci	&sensor_dev_attr_in3_label.dev_attr.attr,
2848c2ecf20Sopenharmony_ci	&sensor_dev_attr_in4_label.dev_attr.attr,
2858c2ecf20Sopenharmony_ci	&sensor_dev_attr_in5_label.dev_attr.attr,
2868c2ecf20Sopenharmony_ci	&sensor_dev_attr_in6_label.dev_attr.attr,
2878c2ecf20Sopenharmony_ci	&sensor_dev_attr_in7_label.dev_attr.attr,
2888c2ecf20Sopenharmony_ci	&sensor_dev_attr_in8_label.dev_attr.attr,
2898c2ecf20Sopenharmony_ci	&sensor_dev_attr_in9_label.dev_attr.attr,
2908c2ecf20Sopenharmony_ci	&sensor_dev_attr_in10_label.dev_attr.attr,
2918c2ecf20Sopenharmony_ci	&sensor_dev_attr_in11_label.dev_attr.attr,
2928c2ecf20Sopenharmony_ci	&sensor_dev_attr_in12_label.dev_attr.attr,
2938c2ecf20Sopenharmony_ci	&sensor_dev_attr_in13_label.dev_attr.attr,
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci	NULL
2968c2ecf20Sopenharmony_ci};
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ciATTRIBUTE_GROUPS(powr1220);
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_cistatic int powr1220_probe(struct i2c_client *client)
3018c2ecf20Sopenharmony_ci{
3028c2ecf20Sopenharmony_ci	struct powr1220_data *data;
3038c2ecf20Sopenharmony_ci	struct device *hwmon_dev;
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
3068c2ecf20Sopenharmony_ci		return -ENODEV;
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
3098c2ecf20Sopenharmony_ci	if (!data)
3108c2ecf20Sopenharmony_ci		return -ENOMEM;
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci	mutex_init(&data->update_lock);
3138c2ecf20Sopenharmony_ci	data->client = client;
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci	hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev,
3168c2ecf20Sopenharmony_ci			client->name, data, powr1220_groups);
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci	return PTR_ERR_OR_ZERO(hwmon_dev);
3198c2ecf20Sopenharmony_ci}
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_cistatic const struct i2c_device_id powr1220_ids[] = {
3228c2ecf20Sopenharmony_ci	{ "powr1220", 0, },
3238c2ecf20Sopenharmony_ci	{ }
3248c2ecf20Sopenharmony_ci};
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, powr1220_ids);
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_cistatic struct i2c_driver powr1220_driver = {
3298c2ecf20Sopenharmony_ci	.class		= I2C_CLASS_HWMON,
3308c2ecf20Sopenharmony_ci	.driver = {
3318c2ecf20Sopenharmony_ci		.name	= "powr1220",
3328c2ecf20Sopenharmony_ci	},
3338c2ecf20Sopenharmony_ci	.probe_new	= powr1220_probe,
3348c2ecf20Sopenharmony_ci	.id_table	= powr1220_ids,
3358c2ecf20Sopenharmony_ci};
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_cimodule_i2c_driver(powr1220_driver);
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ciMODULE_AUTHOR("Scott Kanowitz");
3408c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("POWR1220 driver");
3418c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
342