| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * LM73 Sensor driver |
|---|
| 3 | 4 | * Based on LM75 |
|---|
| .. | .. |
|---|
| 9 | 10 | * Adrien Demarez <adrien.demarez@bolloretelecom.eu> |
|---|
| 10 | 11 | * Jeremy Laine <jeremy.laine@bolloretelecom.eu> |
|---|
| 11 | 12 | * Chris Verges <kg4ysn@gmail.com> |
|---|
| 12 | | - * |
|---|
| 13 | | - * This software program is licensed subject to the GNU General Public License |
|---|
| 14 | | - * (GPL).Version 2,June 1991, available at |
|---|
| 15 | | - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|---|
| 16 | 13 | */ |
|---|
| 17 | 14 | |
|---|
| 18 | 15 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 62 | 59 | |
|---|
| 63 | 60 | /*-----------------------------------------------------------------------*/ |
|---|
| 64 | 61 | |
|---|
| 65 | | -static ssize_t set_temp(struct device *dev, struct device_attribute *da, |
|---|
| 66 | | - const char *buf, size_t count) |
|---|
| 62 | +static ssize_t temp_store(struct device *dev, struct device_attribute *da, |
|---|
| 63 | + const char *buf, size_t count) |
|---|
| 67 | 64 | { |
|---|
| 68 | 65 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 69 | 66 | struct lm73_data *data = dev_get_drvdata(dev); |
|---|
| .. | .. |
|---|
| 81 | 78 | return (err < 0) ? err : count; |
|---|
| 82 | 79 | } |
|---|
| 83 | 80 | |
|---|
| 84 | | -static ssize_t show_temp(struct device *dev, struct device_attribute *da, |
|---|
| 81 | +static ssize_t temp_show(struct device *dev, struct device_attribute *da, |
|---|
| 85 | 82 | char *buf) |
|---|
| 86 | 83 | { |
|---|
| 87 | 84 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| .. | .. |
|---|
| 98 | 95 | return scnprintf(buf, PAGE_SIZE, "%d\n", temp); |
|---|
| 99 | 96 | } |
|---|
| 100 | 97 | |
|---|
| 101 | | -static ssize_t set_convrate(struct device *dev, struct device_attribute *da, |
|---|
| 102 | | - const char *buf, size_t count) |
|---|
| 98 | +static ssize_t convrate_store(struct device *dev, struct device_attribute *da, |
|---|
| 99 | + const char *buf, size_t count) |
|---|
| 103 | 100 | { |
|---|
| 104 | 101 | struct lm73_data *data = dev_get_drvdata(dev); |
|---|
| 105 | 102 | unsigned long convrate; |
|---|
| .. | .. |
|---|
| 133 | 130 | return count; |
|---|
| 134 | 131 | } |
|---|
| 135 | 132 | |
|---|
| 136 | | -static ssize_t show_convrate(struct device *dev, struct device_attribute *da, |
|---|
| 133 | +static ssize_t convrate_show(struct device *dev, struct device_attribute *da, |
|---|
| 137 | 134 | char *buf) |
|---|
| 138 | 135 | { |
|---|
| 139 | 136 | struct lm73_data *data = dev_get_drvdata(dev); |
|---|
| .. | .. |
|---|
| 143 | 140 | return scnprintf(buf, PAGE_SIZE, "%hu\n", lm73_convrates[res]); |
|---|
| 144 | 141 | } |
|---|
| 145 | 142 | |
|---|
| 146 | | -static ssize_t show_maxmin_alarm(struct device *dev, |
|---|
| 143 | +static ssize_t maxmin_alarm_show(struct device *dev, |
|---|
| 147 | 144 | struct device_attribute *da, char *buf) |
|---|
| 148 | 145 | { |
|---|
| 149 | 146 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| .. | .. |
|---|
| 168 | 165 | |
|---|
| 169 | 166 | /* sysfs attributes for hwmon */ |
|---|
| 170 | 167 | |
|---|
| 171 | | -static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, |
|---|
| 172 | | - show_temp, set_temp, LM73_REG_MAX); |
|---|
| 173 | | -static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, |
|---|
| 174 | | - show_temp, set_temp, LM73_REG_MIN); |
|---|
| 175 | | -static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, |
|---|
| 176 | | - show_temp, NULL, LM73_REG_INPUT); |
|---|
| 177 | | -static SENSOR_DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, |
|---|
| 178 | | - show_convrate, set_convrate, 0); |
|---|
| 179 | | -static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, |
|---|
| 180 | | - show_maxmin_alarm, NULL, LM73_CTRL_HI_SHIFT); |
|---|
| 181 | | -static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, |
|---|
| 182 | | - show_maxmin_alarm, NULL, LM73_CTRL_LO_SHIFT); |
|---|
| 168 | +static SENSOR_DEVICE_ATTR_RW(temp1_max, temp, LM73_REG_MAX); |
|---|
| 169 | +static SENSOR_DEVICE_ATTR_RW(temp1_min, temp, LM73_REG_MIN); |
|---|
| 170 | +static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, LM73_REG_INPUT); |
|---|
| 171 | +static SENSOR_DEVICE_ATTR_RW(update_interval, convrate, 0); |
|---|
| 172 | +static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, maxmin_alarm, |
|---|
| 173 | + LM73_CTRL_HI_SHIFT); |
|---|
| 174 | +static SENSOR_DEVICE_ATTR_RO(temp1_min_alarm, maxmin_alarm, |
|---|
| 175 | + LM73_CTRL_LO_SHIFT); |
|---|
| 183 | 176 | |
|---|
| 184 | 177 | static struct attribute *lm73_attrs[] = { |
|---|
| 185 | 178 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
|---|
| .. | .. |
|---|
| 197 | 190 | /* device probe and removal */ |
|---|
| 198 | 191 | |
|---|
| 199 | 192 | static int |
|---|
| 200 | | -lm73_probe(struct i2c_client *client, const struct i2c_device_id *id) |
|---|
| 193 | +lm73_probe(struct i2c_client *client) |
|---|
| 201 | 194 | { |
|---|
| 202 | 195 | struct device *dev = &client->dev; |
|---|
| 203 | 196 | struct device *hwmon_dev; |
|---|
| .. | .. |
|---|
| 269 | 262 | return 0; |
|---|
| 270 | 263 | } |
|---|
| 271 | 264 | |
|---|
| 265 | +static const struct of_device_id lm73_of_match[] = { |
|---|
| 266 | + { |
|---|
| 267 | + .compatible = "ti,lm73", |
|---|
| 268 | + }, |
|---|
| 269 | + { }, |
|---|
| 270 | +}; |
|---|
| 271 | + |
|---|
| 272 | +MODULE_DEVICE_TABLE(of, lm73_of_match); |
|---|
| 273 | + |
|---|
| 272 | 274 | static struct i2c_driver lm73_driver = { |
|---|
| 273 | 275 | .class = I2C_CLASS_HWMON, |
|---|
| 274 | 276 | .driver = { |
|---|
| 275 | 277 | .name = "lm73", |
|---|
| 278 | + .of_match_table = lm73_of_match, |
|---|
| 276 | 279 | }, |
|---|
| 277 | | - .probe = lm73_probe, |
|---|
| 280 | + .probe_new = lm73_probe, |
|---|
| 278 | 281 | .id_table = lm73_ids, |
|---|
| 279 | 282 | .detect = lm73_detect, |
|---|
| 280 | 283 | .address_list = normal_i2c, |
|---|