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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Driver for Linear Technology LTC4215 I2C Hot Swap Controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2009 Ira W. Snyder <iws@ovro.caltech.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Datasheet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * http://www.linear.com/pc/downloadDocument.do?navId=H0,C1,C1003,C1006,C1163,P17572,D12697
^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/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/hwmon-sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /* Here are names of the chip's registers (a.k.a. commands) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) enum ltc4215_cmd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	LTC4215_CONTROL			= 0x00, /* rw */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	LTC4215_ALERT			= 0x01, /* rw */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	LTC4215_STATUS			= 0x02, /* ro */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	LTC4215_FAULT			= 0x03, /* rw */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	LTC4215_SENSE			= 0x04, /* rw */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	LTC4215_SOURCE			= 0x05, /* rw */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	LTC4215_ADIN			= 0x06, /* rw */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) struct ltc4215_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct mutex update_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	bool valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	unsigned long last_updated; /* in jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	/* Registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	u8 regs[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static struct ltc4215_data *ltc4215_update_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct ltc4215_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	s32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	/* The chip's A/D updates 10 times per second */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (time_after(jiffies, data->last_updated + HZ / 10) || !data->valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		dev_dbg(&client->dev, "Starting ltc4215 update\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		/* Read all registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		for (i = 0; i < ARRAY_SIZE(data->regs); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			val = i2c_smbus_read_byte_data(client, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 			if (unlikely(val < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 				data->regs[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 				data->regs[i] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		data->last_updated = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		data->valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) /* Return the voltage from the given register in millivolts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static int ltc4215_get_voltage(struct device *dev, u8 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct ltc4215_data *data = ltc4215_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	const u8 regval = data->regs[reg];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	u32 voltage = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	switch (reg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	case LTC4215_SENSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		/* 151 uV per increment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		voltage = regval * 151 / 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	case LTC4215_SOURCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		/* 60.5 mV per increment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		voltage = regval * 605 / 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	case LTC4215_ADIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		 * The ADIN input is divided by 12.5, and has 4.82 mV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		 * per increment, so we have the additional multiply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		voltage = regval * 482 * 125 / 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		/* If we get here, the developer messed up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	return voltage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /* Return the current from the sense resistor in mA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static unsigned int ltc4215_get_current(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct ltc4215_data *data = ltc4215_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	 * The strange looking conversions that follow are fixed-point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 * math, since we cannot do floating point in the kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 * Step 1: convert sense register to microVolts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	 * Step 2: convert voltage to milliAmperes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	 * If you play around with the V=IR equation, you come up with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	 * the following: X uV / Y mOhm == Z mA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	 * With the resistors that are fractions of a milliOhm, we multiply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	 * the voltage and resistance by 10, to shift the decimal point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	 * Now we can use the normal division operator again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	/* Calculate voltage in microVolts (151 uV per increment) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	const unsigned int voltage = data->regs[LTC4215_SENSE] * 151;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	/* Calculate current in milliAmperes (4 milliOhm sense resistor) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	const unsigned int curr = voltage / 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return curr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static ssize_t ltc4215_voltage_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 				    struct device_attribute *da, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	const int voltage = ltc4215_get_voltage(dev, attr->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	return snprintf(buf, PAGE_SIZE, "%d\n", voltage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static ssize_t ltc4215_current_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 				    struct device_attribute *da, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	const unsigned int curr = ltc4215_get_current(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	return snprintf(buf, PAGE_SIZE, "%u\n", curr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static ssize_t ltc4215_power_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 				  struct device_attribute *da, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	const unsigned int curr = ltc4215_get_current(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	const int output_voltage = ltc4215_get_voltage(dev, LTC4215_ADIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	/* current in mA * voltage in mV == power in uW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	const unsigned int power = abs(output_voltage * curr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	return snprintf(buf, PAGE_SIZE, "%u\n", power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static ssize_t ltc4215_alarm_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 				  struct device_attribute *da, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct ltc4215_data *data = ltc4215_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	const u8 reg = data->regs[LTC4215_STATUS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	const u32 mask = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	return snprintf(buf, PAGE_SIZE, "%u\n", !!(reg & mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * These macros are used below in constructing device attribute objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  * for use with sysfs_create_group() to make a sysfs device file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * for each register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* Construct a sensor_device_attribute structure for each register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /* Current */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static SENSOR_DEVICE_ATTR_RO(curr1_input, ltc4215_current, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static SENSOR_DEVICE_ATTR_RO(curr1_max_alarm, ltc4215_alarm, 1 << 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /* Power (virtual) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static SENSOR_DEVICE_ATTR_RO(power1_input, ltc4215_power, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /* Input Voltage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static SENSOR_DEVICE_ATTR_RO(in1_input, ltc4215_voltage, LTC4215_ADIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static SENSOR_DEVICE_ATTR_RO(in1_max_alarm, ltc4215_alarm, 1 << 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static SENSOR_DEVICE_ATTR_RO(in1_min_alarm, ltc4215_alarm, 1 << 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /* Output Voltage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static SENSOR_DEVICE_ATTR_RO(in2_input, ltc4215_voltage, LTC4215_SOURCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static SENSOR_DEVICE_ATTR_RO(in2_min_alarm, ltc4215_alarm, 1 << 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  * Finally, construct an array of pointers to members of the above objects,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  * as required for sysfs_create_group()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static struct attribute *ltc4215_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	&sensor_dev_attr_curr1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	&sensor_dev_attr_curr1_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	&sensor_dev_attr_power1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	&sensor_dev_attr_in1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	&sensor_dev_attr_in1_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	&sensor_dev_attr_in1_min_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	&sensor_dev_attr_in2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	&sensor_dev_attr_in2_min_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) ATTRIBUTE_GROUPS(ltc4215);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static int ltc4215_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct i2c_adapter *adapter = client->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct ltc4215_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	data->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	mutex_init(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	/* Initialize the LTC4215 chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	i2c_smbus_write_byte_data(client, LTC4215_FAULT, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 							   data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 							   ltc4215_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	return PTR_ERR_OR_ZERO(hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static const struct i2c_device_id ltc4215_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	{ "ltc4215", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) MODULE_DEVICE_TABLE(i2c, ltc4215_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* This is the driver that will be inserted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static struct i2c_driver ltc4215_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		.name	= "ltc4215",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	.probe_new	= ltc4215_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	.id_table	= ltc4215_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) module_i2c_driver(ltc4215_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) MODULE_AUTHOR("Ira W. Snyder <iws@ovro.caltech.edu>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) MODULE_DESCRIPTION("LTC4215 driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) MODULE_LICENSE("GPL");