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)  * emc1403.c - SMSC Thermal Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2008 Intel Corp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^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)  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^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/slab.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/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define THERMAL_PID_REG		0xfd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define THERMAL_SMSC_ID_REG	0xfe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define THERMAL_REVISION_REG	0xff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) enum emc1403_chip { emc1402, emc1403, emc1404 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) struct thermal_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	const struct attribute_group *groups[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static ssize_t temp_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 			 char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct thermal_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	retval = regmap_read(data->regmap, sda->index, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	return sprintf(buf, "%d000\n", val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static ssize_t bit_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct thermal_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	retval = regmap_read(data->regmap, sda->nr, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	return sprintf(buf, "%d\n", !!(val & sda->index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static ssize_t temp_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			  const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct thermal_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (kstrtoul(buf, 10, &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	retval = regmap_write(data->regmap, sda->index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			      DIV_ROUND_CLOSEST(val, 1000));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static ssize_t bit_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			 const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct thermal_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (kstrtoul(buf, 10, &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	retval = regmap_update_bits(data->regmap, sda->nr, sda->index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 				    val ? sda->index : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static ssize_t show_hyst_common(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 				struct device_attribute *attr, char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				bool is_min)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct thermal_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct regmap *regmap = data->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	unsigned int limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	unsigned int hyst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	retval = regmap_read(regmap, sda->index, &limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	retval = regmap_read(regmap, 0x21, &hyst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return sprintf(buf, "%d000\n", is_min ? limit + hyst : limit - hyst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static ssize_t hyst_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			 char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	return show_hyst_common(dev, attr, buf, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static ssize_t min_hyst_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			     struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	return show_hyst_common(dev, attr, buf, true);
^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) static ssize_t hyst_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			  const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct thermal_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct regmap *regmap = data->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	unsigned int limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	int hyst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (kstrtoul(buf, 10, &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	mutex_lock(&data->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	retval = regmap_read(regmap, sda->index, &limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	hyst = limit * 1000 - val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	hyst = clamp_val(DIV_ROUND_CLOSEST(hyst, 1000), 0, 255);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	retval = regmap_write(regmap, 0x21, hyst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (retval == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		retval = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	mutex_unlock(&data->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  *	Sensors. We pass the actual i2c register to the methods.
^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 SENSOR_DEVICE_ATTR_RW(temp1_min, temp, 0x06);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static SENSOR_DEVICE_ATTR_RW(temp1_max, temp, 0x05);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static SENSOR_DEVICE_ATTR_RW(temp1_crit, temp, 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static SENSOR_DEVICE_ATTR_2_RO(temp1_min_alarm, bit, 0x36, 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static SENSOR_DEVICE_ATTR_2_RO(temp1_max_alarm, bit, 0x35, 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static SENSOR_DEVICE_ATTR_2_RO(temp1_crit_alarm, bit, 0x37, 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static SENSOR_DEVICE_ATTR_RO(temp1_min_hyst, min_hyst, 0x06);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static SENSOR_DEVICE_ATTR_RO(temp1_max_hyst, hyst, 0x05);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static SENSOR_DEVICE_ATTR_RW(temp1_crit_hyst, hyst, 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static SENSOR_DEVICE_ATTR_RW(temp2_min, temp, 0x08);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static SENSOR_DEVICE_ATTR_RW(temp2_max, temp, 0x07);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static SENSOR_DEVICE_ATTR_RW(temp2_crit, temp, 0x19);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static SENSOR_DEVICE_ATTR_2_RO(temp2_fault, bit, 0x1b, 0x02);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static SENSOR_DEVICE_ATTR_2_RO(temp2_min_alarm, bit, 0x36, 0x02);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static SENSOR_DEVICE_ATTR_2_RO(temp2_max_alarm, bit, 0x35, 0x02);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static SENSOR_DEVICE_ATTR_2_RO(temp2_crit_alarm, bit, 0x37, 0x02);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static SENSOR_DEVICE_ATTR_RO(temp2_min_hyst, min_hyst, 0x08);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static SENSOR_DEVICE_ATTR_RO(temp2_max_hyst, hyst, 0x07);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static SENSOR_DEVICE_ATTR_RO(temp2_crit_hyst, hyst, 0x19);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static SENSOR_DEVICE_ATTR_RW(temp3_min, temp, 0x16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static SENSOR_DEVICE_ATTR_RW(temp3_max, temp, 0x15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static SENSOR_DEVICE_ATTR_RW(temp3_crit, temp, 0x1A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 0x23);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static SENSOR_DEVICE_ATTR_2_RO(temp3_fault, bit, 0x1b, 0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static SENSOR_DEVICE_ATTR_2_RO(temp3_min_alarm, bit, 0x36, 0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static SENSOR_DEVICE_ATTR_2_RO(temp3_max_alarm, bit, 0x35, 0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static SENSOR_DEVICE_ATTR_2_RO(temp3_crit_alarm, bit, 0x37, 0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static SENSOR_DEVICE_ATTR_RO(temp3_min_hyst, min_hyst, 0x16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static SENSOR_DEVICE_ATTR_RO(temp3_max_hyst, hyst, 0x15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static SENSOR_DEVICE_ATTR_RO(temp3_crit_hyst, hyst, 0x1A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static SENSOR_DEVICE_ATTR_RW(temp4_min, temp, 0x2D);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static SENSOR_DEVICE_ATTR_RW(temp4_max, temp, 0x2C);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static SENSOR_DEVICE_ATTR_RW(temp4_crit, temp, 0x30);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static SENSOR_DEVICE_ATTR_RO(temp4_input, temp, 0x2A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static SENSOR_DEVICE_ATTR_2_RO(temp4_fault, bit, 0x1b, 0x08);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static SENSOR_DEVICE_ATTR_2_RO(temp4_min_alarm, bit, 0x36, 0x08);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static SENSOR_DEVICE_ATTR_2_RO(temp4_max_alarm, bit, 0x35, 0x08);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static SENSOR_DEVICE_ATTR_2_RO(temp4_crit_alarm, bit, 0x37, 0x08);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static SENSOR_DEVICE_ATTR_RO(temp4_min_hyst, min_hyst, 0x2D);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static SENSOR_DEVICE_ATTR_RO(temp4_max_hyst, hyst, 0x2C);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static SENSOR_DEVICE_ATTR_RO(temp4_crit_hyst, hyst, 0x30);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static SENSOR_DEVICE_ATTR_2_RW(power_state, bit, 0x03, 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static struct attribute *emc1402_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	&sensor_dev_attr_temp1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	&sensor_dev_attr_temp1_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	&sensor_dev_attr_temp1_crit.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	&sensor_dev_attr_temp1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	&sensor_dev_attr_temp1_min_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	&sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	&sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	&sensor_dev_attr_temp2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	&sensor_dev_attr_temp2_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	&sensor_dev_attr_temp2_crit.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	&sensor_dev_attr_temp2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	&sensor_dev_attr_temp2_min_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	&sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	&sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	&sensor_dev_attr_power_state.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static const struct attribute_group emc1402_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		.attrs = emc1402_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static struct attribute *emc1403_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	&sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	&sensor_dev_attr_temp2_fault.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	&sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	&sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	&sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	&sensor_dev_attr_temp3_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	&sensor_dev_attr_temp3_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	&sensor_dev_attr_temp3_crit.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	&sensor_dev_attr_temp3_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	&sensor_dev_attr_temp3_fault.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	&sensor_dev_attr_temp3_min_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	&sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	&sensor_dev_attr_temp3_crit_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	&sensor_dev_attr_temp3_min_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	&sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	&sensor_dev_attr_temp3_crit_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static const struct attribute_group emc1403_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	.attrs = emc1403_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static struct attribute *emc1404_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	&sensor_dev_attr_temp4_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	&sensor_dev_attr_temp4_max.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	&sensor_dev_attr_temp4_crit.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	&sensor_dev_attr_temp4_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	&sensor_dev_attr_temp4_fault.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	&sensor_dev_attr_temp4_min_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	&sensor_dev_attr_temp4_max_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	&sensor_dev_attr_temp4_crit_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	&sensor_dev_attr_temp4_min_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	&sensor_dev_attr_temp4_max_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	&sensor_dev_attr_temp4_crit_hyst.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static const struct attribute_group emc1404_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	.attrs = emc1404_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)  * EMC14x2 uses a different register and different bits to report alarm and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)  * fault status. For simplicity, provide a separate attribute group for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)  * chip series.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)  * Since we can not re-use the same attribute names, create a separate attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  * array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static struct sensor_device_attribute_2 emc1402_alarms[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	SENSOR_ATTR_2_RO(temp1_min_alarm, bit, 0x02, 0x20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	SENSOR_ATTR_2_RO(temp1_max_alarm, bit, 0x02, 0x40),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	SENSOR_ATTR_2_RO(temp1_crit_alarm, bit, 0x02, 0x01),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	SENSOR_ATTR_2_RO(temp2_fault, bit, 0x02, 0x04),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	SENSOR_ATTR_2_RO(temp2_min_alarm, bit, 0x02, 0x08),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	SENSOR_ATTR_2_RO(temp2_max_alarm, bit, 0x02, 0x10),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	SENSOR_ATTR_2_RO(temp2_crit_alarm, bit, 0x02, 0x02),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static struct attribute *emc1402_alarm_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	&emc1402_alarms[0].dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	&emc1402_alarms[1].dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	&emc1402_alarms[2].dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	&emc1402_alarms[3].dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	&emc1402_alarms[4].dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	&emc1402_alarms[5].dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	&emc1402_alarms[6].dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static const struct attribute_group emc1402_alarm_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	.attrs = emc1402_alarm_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static int emc1403_detect(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			struct i2c_board_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	/* Check if thermal chip is SMSC and EMC1403 or EMC1423 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	id = i2c_smbus_read_byte_data(client, THERMAL_SMSC_ID_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	if (id != 0x5d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	id = i2c_smbus_read_byte_data(client, THERMAL_PID_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	switch (id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	case 0x20:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		strlcpy(info->type, "emc1402", I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	case 0x21:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		strlcpy(info->type, "emc1403", I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	case 0x22:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		strlcpy(info->type, "emc1422", I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	case 0x23:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		strlcpy(info->type, "emc1423", I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	case 0x25:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		strlcpy(info->type, "emc1404", I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	case 0x27:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		strlcpy(info->type, "emc1424", I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		return -ENODEV;
^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) 	id = i2c_smbus_read_byte_data(client, THERMAL_REVISION_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	if (id < 0x01 || id > 0x04)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static bool emc1403_regmap_is_volatile(struct device *dev, unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	switch (reg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	case 0x00:	/* internal diode high byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	case 0x01:	/* external diode 1 high byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	case 0x02:	/* status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	case 0x10:	/* external diode 1 low byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	case 0x1b:	/* external diode fault */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	case 0x23:	/* external diode 2 high byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	case 0x24:	/* external diode 2 low byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	case 0x29:	/* internal diode low byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	case 0x2a:	/* externl diode 3 high byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	case 0x2b:	/* external diode 3 low byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	case 0x35:	/* high limit status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	case 0x36:	/* low limit status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	case 0x37:	/* therm limit status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static const struct regmap_config emc1403_regmap_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	.reg_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	.val_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	.cache_type = REGCACHE_RBTREE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	.volatile_reg = emc1403_regmap_is_volatile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) static const struct i2c_device_id emc1403_idtable[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static int emc1403_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	struct thermal_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	const struct i2c_device_id *id = i2c_match_id(emc1403_idtable, client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	data = devm_kzalloc(&client->dev, sizeof(struct thermal_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 			    GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	if (data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	data->regmap = devm_regmap_init_i2c(client, &emc1403_regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	if (IS_ERR(data->regmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		return PTR_ERR(data->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	mutex_init(&data->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	switch (id->driver_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	case emc1404:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		data->groups[2] = &emc1404_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	case emc1403:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		data->groups[1] = &emc1403_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	case emc1402:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		data->groups[0] = &emc1402_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	if (id->driver_data == emc1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		data->groups[1] = &emc1402_alarm_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 							   client->name, data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 							   data->groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	if (IS_ERR(hwmon_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		return PTR_ERR(hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	dev_info(&client->dev, "%s Thermal chip found\n", id->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) static const unsigned short emc1403_address_list[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	0x18, 0x1c, 0x29, 0x4c, 0x4d, 0x5c, I2C_CLIENT_END
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) /* Last digit of chip name indicates number of channels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static const struct i2c_device_id emc1403_idtable[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	{ "emc1402", emc1402 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	{ "emc1403", emc1403 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	{ "emc1404", emc1404 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	{ "emc1412", emc1402 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	{ "emc1413", emc1403 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	{ "emc1414", emc1404 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	{ "emc1422", emc1402 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	{ "emc1423", emc1403 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	{ "emc1424", emc1404 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) MODULE_DEVICE_TABLE(i2c, emc1403_idtable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static struct i2c_driver sensor_emc1403 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	.class = I2C_CLASS_HWMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		.name = "emc1403",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	.detect = emc1403_detect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	.probe_new = emc1403_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	.id_table = emc1403_idtable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	.address_list = emc1403_address_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) module_i2c_driver(sensor_emc1403);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) MODULE_AUTHOR("Kalhan Trisal <kalhan.trisal@intel.com");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) MODULE_DESCRIPTION("emc1403 Thermal Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) MODULE_LICENSE("GPL v2");