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)  * Copyright (c) 2011 David George <david.george@ska.ac.za>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * based on adm1021.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * some credit to Christoph Scheurer, but largely a rewrite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/hwmon-sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) /* Addresses to scan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static const unsigned short max1668_addr_list[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /* max1668 registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define MAX1668_REG_TEMP(nr)	(nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define MAX1668_REG_STAT1	0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define MAX1668_REG_STAT2	0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define MAX1668_REG_MAN_ID	0xfe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define MAX1668_REG_DEV_ID	0xff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) /* limits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /* write high limits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define MAX1668_REG_LIMH_WR(nr)	(0x13 + 2 * (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) /* write low limits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define MAX1668_REG_LIML_WR(nr)	(0x14 + 2 * (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) /* read high limits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define MAX1668_REG_LIMH_RD(nr)	(0x08 + 2 * (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) /* read low limits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define MAX1668_REG_LIML_RD(nr)	(0x09 + 2 * (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) /* manufacturer and device ID Constants */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define MAN_ID_MAXIM		0x4d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define DEV_ID_MAX1668		0x3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define DEV_ID_MAX1805		0x5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define DEV_ID_MAX1989		0xb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /* read only mode module parameter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static bool read_only;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) module_param(read_only, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) MODULE_PARM_DESC(read_only, "Don't set any values, read only mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) enum chips { max1668, max1805, max1989 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) struct max1668_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	const struct attribute_group *groups[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	enum chips type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct mutex update_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	char valid;		/* !=0 if following fields are valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	unsigned long last_updated;	/* In jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	/* 1x local and 4x remote */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	s8 temp_max[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	s8 temp_min[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	s8 temp[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	u16 alarms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static struct max1668_data *max1668_update_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct max1668_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct max1668_data *ret = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	s32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (data->valid && !time_after(jiffies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			data->last_updated + HZ + HZ / 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	for (i = 0; i < 5; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		val = i2c_smbus_read_byte_data(client, MAX1668_REG_TEMP(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		if (unlikely(val < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			ret = ERR_PTR(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		data->temp[i] = (s8) val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		val = i2c_smbus_read_byte_data(client, MAX1668_REG_LIMH_RD(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if (unlikely(val < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			ret = ERR_PTR(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		data->temp_max[i] = (s8) val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		val = i2c_smbus_read_byte_data(client, MAX1668_REG_LIML_RD(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if (unlikely(val < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			ret = ERR_PTR(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		data->temp_min[i] = (s8) val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	val = i2c_smbus_read_byte_data(client, MAX1668_REG_STAT1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if (unlikely(val < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		ret = ERR_PTR(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	data->alarms = val << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	val = i2c_smbus_read_byte_data(client, MAX1668_REG_STAT2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (unlikely(val < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		ret = ERR_PTR(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	data->alarms |= val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	data->last_updated = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	data->valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) abort:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static ssize_t show_temp(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			 struct device_attribute *devattr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	int index = to_sensor_dev_attr(devattr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct max1668_data *data = max1668_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (IS_ERR(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return PTR_ERR(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return sprintf(buf, "%d\n", data->temp[index] * 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static ssize_t show_temp_max(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			     struct device_attribute *devattr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	int index = to_sensor_dev_attr(devattr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct max1668_data *data = max1668_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (IS_ERR(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		return PTR_ERR(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	return sprintf(buf, "%d\n", data->temp_max[index] * 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static ssize_t show_temp_min(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			     struct device_attribute *devattr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	int index = to_sensor_dev_attr(devattr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	struct max1668_data *data = max1668_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (IS_ERR(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		return PTR_ERR(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return sprintf(buf, "%d\n", data->temp_min[index] * 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			  char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	int index = to_sensor_dev_attr(attr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct max1668_data *data = max1668_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (IS_ERR(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		return PTR_ERR(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return sprintf(buf, "%u\n", (data->alarms >> index) & 0x1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static ssize_t show_fault(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			  struct device_attribute *devattr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	int index = to_sensor_dev_attr(devattr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct max1668_data *data = max1668_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (IS_ERR(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		return PTR_ERR(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	return sprintf(buf, "%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		       (data->alarms & (1 << 12)) && data->temp[index] == 127);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static ssize_t set_temp_max(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			    struct device_attribute *devattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			    const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	int index = to_sensor_dev_attr(devattr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	struct max1668_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	long temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	ret = kstrtol(buf, 10, &temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	data->temp_max[index] = clamp_val(temp/1000, -128, 127);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	ret = i2c_smbus_write_byte_data(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 					MAX1668_REG_LIMH_WR(index),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 					data->temp_max[index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		count = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static ssize_t set_temp_min(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			    struct device_attribute *devattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			    const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	int index = to_sensor_dev_attr(devattr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct max1668_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	long temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	ret = kstrtol(buf, 10, &temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	data->temp_min[index] = clamp_val(temp/1000, -128, 127);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	ret = i2c_smbus_write_byte_data(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 					MAX1668_REG_LIML_WR(index),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 					data->temp_min[index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		count = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 				set_temp_max, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO, show_temp_min,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 				set_temp_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO, show_temp_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 				set_temp_max, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static SENSOR_DEVICE_ATTR(temp2_min, S_IRUGO, show_temp_min,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 				set_temp_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO, show_temp_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 				set_temp_max, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static SENSOR_DEVICE_ATTR(temp3_min, S_IRUGO, show_temp_min,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 				set_temp_min, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static SENSOR_DEVICE_ATTR(temp4_max, S_IRUGO, show_temp_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 				set_temp_max, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static SENSOR_DEVICE_ATTR(temp4_min, S_IRUGO, show_temp_min,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 				set_temp_min, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, show_temp, NULL, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static SENSOR_DEVICE_ATTR(temp5_max, S_IRUGO, show_temp_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 				set_temp_max, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static SENSOR_DEVICE_ATTR(temp5_min, S_IRUGO, show_temp_min,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 				set_temp_min, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static SENSOR_DEVICE_ATTR(temp3_min_alarm, S_IRUGO, show_alarm, NULL, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static SENSOR_DEVICE_ATTR(temp4_min_alarm, S_IRUGO, show_alarm, NULL, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO, show_alarm, NULL, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static SENSOR_DEVICE_ATTR(temp5_min_alarm, S_IRUGO, show_alarm, NULL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static SENSOR_DEVICE_ATTR(temp5_max_alarm, S_IRUGO, show_alarm, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_fault, NULL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_fault, NULL, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static SENSOR_DEVICE_ATTR(temp4_fault, S_IRUGO, show_fault, NULL, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static SENSOR_DEVICE_ATTR(temp5_fault, S_IRUGO, show_fault, NULL, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /* Attributes common to MAX1668, MAX1989 and MAX1805 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static struct attribute *max1668_attribute_common[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	&sensor_dev_attr_temp1_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	&sensor_dev_attr_temp1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	&sensor_dev_attr_temp1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	&sensor_dev_attr_temp2_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	&sensor_dev_attr_temp2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	&sensor_dev_attr_temp2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	&sensor_dev_attr_temp3_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	&sensor_dev_attr_temp3_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	&sensor_dev_attr_temp3_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	&sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	&sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	&sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	&sensor_dev_attr_temp3_min_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	&sensor_dev_attr_temp2_fault.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	&sensor_dev_attr_temp3_fault.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /* Attributes not present on MAX1805 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static struct attribute *max1668_attribute_unique[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	&sensor_dev_attr_temp4_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	&sensor_dev_attr_temp4_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	&sensor_dev_attr_temp4_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	&sensor_dev_attr_temp5_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	&sensor_dev_attr_temp5_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	&sensor_dev_attr_temp5_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	&sensor_dev_attr_temp4_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	&sensor_dev_attr_temp4_min_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	&sensor_dev_attr_temp5_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	&sensor_dev_attr_temp5_min_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	&sensor_dev_attr_temp4_fault.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	&sensor_dev_attr_temp5_fault.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) static umode_t max1668_attribute_mode(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 				     struct attribute *attr, int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	umode_t ret = S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	if (read_only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	if (attr == &sensor_dev_attr_temp1_max.dev_attr.attr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	    attr == &sensor_dev_attr_temp2_max.dev_attr.attr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	    attr == &sensor_dev_attr_temp3_max.dev_attr.attr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	    attr == &sensor_dev_attr_temp4_max.dev_attr.attr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	    attr == &sensor_dev_attr_temp5_max.dev_attr.attr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	    attr == &sensor_dev_attr_temp1_min.dev_attr.attr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	    attr == &sensor_dev_attr_temp2_min.dev_attr.attr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	    attr == &sensor_dev_attr_temp3_min.dev_attr.attr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	    attr == &sensor_dev_attr_temp4_min.dev_attr.attr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	    attr == &sensor_dev_attr_temp5_min.dev_attr.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		ret |= S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static const struct attribute_group max1668_group_common = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	.attrs = max1668_attribute_common,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	.is_visible = max1668_attribute_mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) static const struct attribute_group max1668_group_unique = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	.attrs = max1668_attribute_unique,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	.is_visible = max1668_attribute_mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /* Return 0 if detection is successful, -ENODEV otherwise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) static int max1668_detect(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			  struct i2c_board_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	struct i2c_adapter *adapter = client->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	const char *type_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	int man_id, dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	/* Check for unsupported part */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	man_id = i2c_smbus_read_byte_data(client, MAX1668_REG_MAN_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	if (man_id != MAN_ID_MAXIM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	dev_id = i2c_smbus_read_byte_data(client, MAX1668_REG_DEV_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	if (dev_id < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	type_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	if (dev_id == DEV_ID_MAX1668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		type_name = "max1668";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	else if (dev_id == DEV_ID_MAX1805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		type_name = "max1805";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	else if (dev_id == DEV_ID_MAX1989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		type_name = "max1989";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	if (!type_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	strlcpy(info->type, type_name, I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static const struct i2c_device_id max1668_id[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static int max1668_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct i2c_adapter *adapter = client->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	struct max1668_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	data = devm_kzalloc(dev, sizeof(struct max1668_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	data->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	data->type = i2c_match_id(max1668_id, client)->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	mutex_init(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	/* sysfs hooks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	data->groups[0] = &max1668_group_common;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	if (data->type == max1668 || data->type == max1989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		data->groups[1] = &max1668_group_unique;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 							   data, data->groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	return PTR_ERR_OR_ZERO(hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static const struct i2c_device_id max1668_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	{ "max1668", max1668 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	{ "max1805", max1805 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	{ "max1989", max1989 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) MODULE_DEVICE_TABLE(i2c, max1668_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /* This is the driver that will be inserted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static struct i2c_driver max1668_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	.class = I2C_CLASS_HWMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		  .name	= "max1668",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		  },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	.probe_new = max1668_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	.id_table = max1668_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	.detect	= max1668_detect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	.address_list = max1668_addr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) module_i2c_driver(max1668_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) MODULE_AUTHOR("David George <david.george@ska.ac.za>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) MODULE_DESCRIPTION("MAX1668 remote temperature sensor driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) MODULE_LICENSE("GPL");