Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (lm73) Add support for max/min alarms

Add support for temp1_min_alarm and temp1_max_alarm

Signed-off-by: Chris Verges <kg4ysn@gmail.com>
[linux@roeck-us.net: cleanup; dropped platform data and interrupt support]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Chris Verges and committed by
Guenter Roeck
2bf9233a 8c14d126

+43
+11
Documentation/hwmon/lm73
··· 77 77 78 78 where 'x' is the output from 'update_interval' and 'g(x)' is the 79 79 resolution in degrees C per LSB. 80 + 81 + Alarm Support 82 + ------------- 83 + 84 + The LM73 features a simple over-temperature alarm mechanism. This 85 + feature is exposed via the sysfs attributes. 86 + 87 + The attributes 'temp1_max_alarm' and 'temp1_min_alarm' are flags 88 + provided by the LM73 that indicate whether the measured temperature has 89 + passed the 'temp1_max' and 'temp1_min' thresholds, respectively. These 90 + values _must_ be read to clear the registers on the LM73.
+32
drivers/hwmon/lm73.c
··· 8 8 * Guillaume Ligneul <guillaume.ligneul@gmail.com> 9 9 * Adrien Demarez <adrien.demarez@bolloretelecom.eu> 10 10 * Jeremy Laine <jeremy.laine@bolloretelecom.eu> 11 + * Chris Verges <kg4ysn@gmail.com> 11 12 * 12 13 * This software program is licensed subject to the GNU General Public License 13 14 * (GPL).Version 2,June 1991, available at ··· 43 42 #define LM73_CTRL_RES_SHIFT 5 44 43 #define LM73_CTRL_RES_MASK (BIT(5) | BIT(6)) 45 44 #define LM73_CTRL_TO_MASK BIT(7) 45 + 46 + #define LM73_CTRL_HI_SHIFT 2 47 + #define LM73_CTRL_LO_SHIFT 1 46 48 47 49 static const unsigned short lm73_convrates[] = { 48 50 14, /* 11-bits (0.25000 C/LSB): RES1 Bit = 0, RES0 Bit = 0 */ ··· 144 140 return scnprintf(buf, PAGE_SIZE, "%hu\n", lm73_convrates[res]); 145 141 } 146 142 143 + static ssize_t show_maxmin_alarm(struct device *dev, 144 + struct device_attribute *da, char *buf) 145 + { 146 + struct i2c_client *client = to_i2c_client(dev); 147 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 148 + struct lm73_data *data = i2c_get_clientdata(client); 149 + s32 ctrl; 150 + 151 + mutex_lock(&data->lock); 152 + ctrl = i2c_smbus_read_byte_data(client, LM73_REG_CTRL); 153 + if (ctrl < 0) 154 + goto abort; 155 + data->ctrl = ctrl; 156 + mutex_unlock(&data->lock); 157 + 158 + return scnprintf(buf, PAGE_SIZE, "%d\n", (ctrl >> attr->index) & 1); 159 + 160 + abort: 161 + mutex_unlock(&data->lock); 162 + return ctrl; 163 + } 164 + 147 165 /*-----------------------------------------------------------------------*/ 148 166 149 167 /* sysfs attributes for hwmon */ ··· 178 152 show_temp, NULL, LM73_REG_INPUT); 179 153 static SENSOR_DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, 180 154 show_convrate, set_convrate, 0); 155 + static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, 156 + show_maxmin_alarm, NULL, LM73_CTRL_HI_SHIFT); 157 + static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, 158 + show_maxmin_alarm, NULL, LM73_CTRL_LO_SHIFT); 181 159 182 160 static struct attribute *lm73_attributes[] = { 183 161 &sensor_dev_attr_temp1_input.dev_attr.attr, 184 162 &sensor_dev_attr_temp1_max.dev_attr.attr, 185 163 &sensor_dev_attr_temp1_min.dev_attr.attr, 186 164 &sensor_dev_attr_update_interval.dev_attr.attr, 165 + &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, 166 + &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, 187 167 NULL 188 168 }; 189 169