Orange Pi5 kernel

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

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * powr1220.c - Driver for the Lattice POWR1220 programmable power supply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * and monitor. Users can read all ADC inputs along with their labels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * using the sysfs nodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (c) 2014 Echo360 https://www.echo360.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Scott Kanowitz <skanowitz@echo360.com> <scott.kanowitz@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/hwmon-sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define ADC_STEP_MV			2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define ADC_MAX_LOW_MEASUREMENT_MV	2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) enum powr1220_regs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	VMON_STATUS0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	VMON_STATUS1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	VMON_STATUS2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	OUTPUT_STATUS0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	OUTPUT_STATUS1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	OUTPUT_STATUS2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	INPUT_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	ADC_VALUE_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	ADC_VALUE_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	ADC_MUX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	UES_BYTE0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	UES_BYTE1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	UES_BYTE2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	UES_BYTE3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	GP_OUTPUT1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	GP_OUTPUT2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	GP_OUTPUT3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	INPUT_VALUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	RESET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	TRIM1_TRIM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	TRIM2_TRIM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	TRIM3_TRIM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	TRIM4_TRIM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	TRIM5_TRIM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	TRIM6_TRIM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	TRIM7_TRIM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	TRIM8_TRIM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	MAX_POWR1220_REGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) enum powr1220_adc_values {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	VMON1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	VMON2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	VMON3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	VMON4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	VMON5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	VMON6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	VMON7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	VMON8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	VMON9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	VMON10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	VMON11,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	VMON12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	VCCA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	VCCINP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	MAX_POWR1220_ADC_VALUES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) struct powr1220_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct mutex update_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	bool adc_valid[MAX_POWR1220_ADC_VALUES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	 /* the next value is in jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	unsigned long adc_last_updated[MAX_POWR1220_ADC_VALUES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	/* values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	int adc_maxes[MAX_POWR1220_ADC_VALUES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	int adc_values[MAX_POWR1220_ADC_VALUES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static const char * const input_names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	[VMON1]    = "vmon1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	[VMON2]    = "vmon2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	[VMON3]    = "vmon3",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	[VMON4]    = "vmon4",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	[VMON5]    = "vmon5",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	[VMON6]    = "vmon6",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	[VMON7]    = "vmon7",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	[VMON8]    = "vmon8",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	[VMON9]    = "vmon9",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	[VMON10]   = "vmon10",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	[VMON11]   = "vmon11",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	[VMON12]   = "vmon12",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	[VCCA]     = "vcca",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	[VCCINP]   = "vccinp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /* Reads the specified ADC channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static int powr1220_read_adc(struct device *dev, int ch_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct powr1220_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	int reading;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	int adc_range = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (time_after(jiffies, data->adc_last_updated[ch_num] + HZ) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			!data->adc_valid[ch_num]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		 * figure out if we need to use the attenuator for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		 * high inputs or inputs that we don't yet have a measurement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		 * for. We dynamically set the attenuator depending on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		 * max reading.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		if (data->adc_maxes[ch_num] > ADC_MAX_LOW_MEASUREMENT_MV ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 				data->adc_maxes[ch_num] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			adc_range = 1 << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		/* set the attenuator and mux */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		result = i2c_smbus_write_byte_data(data->client, ADC_MUX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 				adc_range | ch_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		 * wait at least Tconvert time (200 us) for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		 * conversion to complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		udelay(200);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		/* get the ADC reading */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		result = i2c_smbus_read_byte_data(data->client, ADC_VALUE_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		reading = result >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		/* get the upper half of the reading */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		result = i2c_smbus_read_byte_data(data->client, ADC_VALUE_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		reading |= result << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		/* now convert the reading to a voltage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		reading *= ADC_STEP_MV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		data->adc_values[ch_num] = reading;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		data->adc_valid[ch_num] = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		data->adc_last_updated[ch_num] = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		result = reading;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		if (reading > data->adc_maxes[ch_num])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			data->adc_maxes[ch_num] = reading;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		result = data->adc_values[ch_num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* Shows the voltage associated with the specified ADC channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static ssize_t powr1220_voltage_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 				     struct device_attribute *dev_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 				     char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	int adc_val = powr1220_read_adc(dev, attr->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (adc_val < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		return adc_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	return sprintf(buf, "%d\n", adc_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /* Shows the maximum setting associated with the specified ADC channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static ssize_t powr1220_max_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 				 struct device_attribute *dev_attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct powr1220_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	return sprintf(buf, "%d\n", data->adc_maxes[attr->index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* Shows the label associated with the specified ADC channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static ssize_t powr1220_label_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 				   struct device_attribute *dev_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 				   char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	return sprintf(buf, "%s\n", input_names[attr->index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static SENSOR_DEVICE_ATTR_RO(in0_input, powr1220_voltage, VMON1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static SENSOR_DEVICE_ATTR_RO(in1_input, powr1220_voltage, VMON2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static SENSOR_DEVICE_ATTR_RO(in2_input, powr1220_voltage, VMON3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static SENSOR_DEVICE_ATTR_RO(in3_input, powr1220_voltage, VMON4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static SENSOR_DEVICE_ATTR_RO(in4_input, powr1220_voltage, VMON5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static SENSOR_DEVICE_ATTR_RO(in5_input, powr1220_voltage, VMON6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static SENSOR_DEVICE_ATTR_RO(in6_input, powr1220_voltage, VMON7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static SENSOR_DEVICE_ATTR_RO(in7_input, powr1220_voltage, VMON8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static SENSOR_DEVICE_ATTR_RO(in8_input, powr1220_voltage, VMON9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static SENSOR_DEVICE_ATTR_RO(in9_input, powr1220_voltage, VMON10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static SENSOR_DEVICE_ATTR_RO(in10_input, powr1220_voltage, VMON11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static SENSOR_DEVICE_ATTR_RO(in11_input, powr1220_voltage, VMON12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static SENSOR_DEVICE_ATTR_RO(in12_input, powr1220_voltage, VCCA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static SENSOR_DEVICE_ATTR_RO(in13_input, powr1220_voltage, VCCINP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static SENSOR_DEVICE_ATTR_RO(in0_highest, powr1220_max, VMON1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static SENSOR_DEVICE_ATTR_RO(in1_highest, powr1220_max, VMON2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static SENSOR_DEVICE_ATTR_RO(in2_highest, powr1220_max, VMON3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static SENSOR_DEVICE_ATTR_RO(in3_highest, powr1220_max, VMON4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static SENSOR_DEVICE_ATTR_RO(in4_highest, powr1220_max, VMON5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static SENSOR_DEVICE_ATTR_RO(in5_highest, powr1220_max, VMON6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static SENSOR_DEVICE_ATTR_RO(in6_highest, powr1220_max, VMON7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static SENSOR_DEVICE_ATTR_RO(in7_highest, powr1220_max, VMON8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static SENSOR_DEVICE_ATTR_RO(in8_highest, powr1220_max, VMON9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static SENSOR_DEVICE_ATTR_RO(in9_highest, powr1220_max, VMON10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static SENSOR_DEVICE_ATTR_RO(in10_highest, powr1220_max, VMON11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static SENSOR_DEVICE_ATTR_RO(in11_highest, powr1220_max, VMON12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static SENSOR_DEVICE_ATTR_RO(in12_highest, powr1220_max, VCCA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static SENSOR_DEVICE_ATTR_RO(in13_highest, powr1220_max, VCCINP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static SENSOR_DEVICE_ATTR_RO(in0_label, powr1220_label, VMON1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static SENSOR_DEVICE_ATTR_RO(in1_label, powr1220_label, VMON2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static SENSOR_DEVICE_ATTR_RO(in2_label, powr1220_label, VMON3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static SENSOR_DEVICE_ATTR_RO(in3_label, powr1220_label, VMON4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static SENSOR_DEVICE_ATTR_RO(in4_label, powr1220_label, VMON5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static SENSOR_DEVICE_ATTR_RO(in5_label, powr1220_label, VMON6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static SENSOR_DEVICE_ATTR_RO(in6_label, powr1220_label, VMON7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static SENSOR_DEVICE_ATTR_RO(in7_label, powr1220_label, VMON8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static SENSOR_DEVICE_ATTR_RO(in8_label, powr1220_label, VMON9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static SENSOR_DEVICE_ATTR_RO(in9_label, powr1220_label, VMON10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static SENSOR_DEVICE_ATTR_RO(in10_label, powr1220_label, VMON11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static SENSOR_DEVICE_ATTR_RO(in11_label, powr1220_label, VMON12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static SENSOR_DEVICE_ATTR_RO(in12_label, powr1220_label, VCCA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static SENSOR_DEVICE_ATTR_RO(in13_label, powr1220_label, VCCINP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static struct attribute *powr1220_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	&sensor_dev_attr_in0_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	&sensor_dev_attr_in1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	&sensor_dev_attr_in2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	&sensor_dev_attr_in3_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	&sensor_dev_attr_in4_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	&sensor_dev_attr_in5_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	&sensor_dev_attr_in6_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	&sensor_dev_attr_in7_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	&sensor_dev_attr_in8_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	&sensor_dev_attr_in9_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	&sensor_dev_attr_in10_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	&sensor_dev_attr_in11_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	&sensor_dev_attr_in12_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	&sensor_dev_attr_in13_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	&sensor_dev_attr_in0_highest.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	&sensor_dev_attr_in1_highest.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	&sensor_dev_attr_in2_highest.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	&sensor_dev_attr_in3_highest.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	&sensor_dev_attr_in4_highest.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	&sensor_dev_attr_in5_highest.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	&sensor_dev_attr_in6_highest.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	&sensor_dev_attr_in7_highest.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	&sensor_dev_attr_in8_highest.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	&sensor_dev_attr_in9_highest.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	&sensor_dev_attr_in10_highest.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	&sensor_dev_attr_in11_highest.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	&sensor_dev_attr_in12_highest.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	&sensor_dev_attr_in13_highest.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	&sensor_dev_attr_in0_label.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	&sensor_dev_attr_in1_label.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	&sensor_dev_attr_in2_label.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	&sensor_dev_attr_in3_label.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	&sensor_dev_attr_in4_label.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	&sensor_dev_attr_in5_label.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	&sensor_dev_attr_in6_label.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	&sensor_dev_attr_in7_label.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	&sensor_dev_attr_in8_label.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	&sensor_dev_attr_in9_label.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	&sensor_dev_attr_in10_label.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	&sensor_dev_attr_in11_label.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	&sensor_dev_attr_in12_label.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	&sensor_dev_attr_in13_label.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) ATTRIBUTE_GROUPS(powr1220);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static int powr1220_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	struct powr1220_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	mutex_init(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	data->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 			client->name, data, powr1220_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	return PTR_ERR_OR_ZERO(hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static const struct i2c_device_id powr1220_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	{ "powr1220", 0, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) MODULE_DEVICE_TABLE(i2c, powr1220_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) static struct i2c_driver powr1220_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	.class		= I2C_CLASS_HWMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		.name	= "powr1220",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	.probe_new	= powr1220_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	.id_table	= powr1220_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) module_i2c_driver(powr1220_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) MODULE_AUTHOR("Scott Kanowitz");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) MODULE_DESCRIPTION("POWR1220 driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) MODULE_LICENSE("GPL");