Commit 2bf9233a108cea32edbb5a65afa8e609fa146577

Authored by Chris Verges
Committed by Guenter Roeck
1 parent 8c14d126ae

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>

Showing 2 changed files with 43 additions and 0 deletions Side-by-side Diff

Documentation/hwmon/lm73
... ... @@ -77,4 +77,15 @@
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.
drivers/hwmon/lm73.c
... ... @@ -8,6 +8,7 @@
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,6 +44,9 @@
43 44 #define LM73_CTRL_RES_MASK (BIT(5) | BIT(6))
44 45 #define LM73_CTRL_TO_MASK BIT(7)
45 46  
  47 +#define LM73_CTRL_HI_SHIFT 2
  48 +#define LM73_CTRL_LO_SHIFT 1
  49 +
46 50 static const unsigned short lm73_convrates[] = {
47 51 14, /* 11-bits (0.25000 C/LSB): RES1 Bit = 0, RES0 Bit = 0 */
48 52 28, /* 12-bits (0.12500 C/LSB): RES1 Bit = 0, RES0 Bit = 1 */
... ... @@ -140,6 +144,28 @@
140 144 return scnprintf(buf, PAGE_SIZE, "%hu\n", lm73_convrates[res]);
141 145 }
142 146  
  147 +static ssize_t show_maxmin_alarm(struct device *dev,
  148 + struct device_attribute *da, char *buf)
  149 +{
  150 + struct i2c_client *client = to_i2c_client(dev);
  151 + struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
  152 + struct lm73_data *data = i2c_get_clientdata(client);
  153 + s32 ctrl;
  154 +
  155 + mutex_lock(&data->lock);
  156 + ctrl = i2c_smbus_read_byte_data(client, LM73_REG_CTRL);
  157 + if (ctrl < 0)
  158 + goto abort;
  159 + data->ctrl = ctrl;
  160 + mutex_unlock(&data->lock);
  161 +
  162 + return scnprintf(buf, PAGE_SIZE, "%d\n", (ctrl >> attr->index) & 1);
  163 +
  164 +abort:
  165 + mutex_unlock(&data->lock);
  166 + return ctrl;
  167 +}
  168 +
143 169 /*-----------------------------------------------------------------------*/
144 170  
145 171 /* sysfs attributes for hwmon */
146 172  
... ... @@ -152,12 +178,18 @@
152 178 show_temp, NULL, LM73_REG_INPUT);
153 179 static SENSOR_DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO,
154 180 show_convrate, set_convrate, 0);
  181 +static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO,
  182 + show_maxmin_alarm, NULL, LM73_CTRL_HI_SHIFT);
  183 +static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO,
  184 + show_maxmin_alarm, NULL, LM73_CTRL_LO_SHIFT);
155 185  
156 186 static struct attribute *lm73_attributes[] = {
157 187 &sensor_dev_attr_temp1_input.dev_attr.attr,
158 188 &sensor_dev_attr_temp1_max.dev_attr.attr,
159 189 &sensor_dev_attr_temp1_min.dev_attr.attr,
160 190 &sensor_dev_attr_update_interval.dev_attr.attr,
  191 + &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
  192 + &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
161 193 NULL
162 194 };
163 195