| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * lm83.c - Part of lm_sensors, Linux kernel modules for hardware |
|---|
| 3 | 4 | * monitoring |
|---|
| .. | .. |
|---|
| 15 | 16 | * Also supports the LM82 temp sensor, which is basically a stripped down |
|---|
| 16 | 17 | * model of the LM83. Datasheet is here: |
|---|
| 17 | 18 | * http://www.national.com/pf/LM/LM82.html |
|---|
| 18 | | - * |
|---|
| 19 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 20 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 21 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 22 | | - * (at your option) any later version. |
|---|
| 23 | | - * |
|---|
| 24 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 25 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 26 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 27 | | - * GNU General Public License for more details. |
|---|
| 28 | 19 | */ |
|---|
| 29 | 20 | |
|---|
| 30 | 21 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 158 | 149 | * Sysfs stuff |
|---|
| 159 | 150 | */ |
|---|
| 160 | 151 | |
|---|
| 161 | | -static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, |
|---|
| 152 | +static ssize_t temp_show(struct device *dev, struct device_attribute *devattr, |
|---|
| 162 | 153 | char *buf) |
|---|
| 163 | 154 | { |
|---|
| 164 | 155 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
|---|
| .. | .. |
|---|
| 166 | 157 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index])); |
|---|
| 167 | 158 | } |
|---|
| 168 | 159 | |
|---|
| 169 | | -static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, |
|---|
| 170 | | - const char *buf, size_t count) |
|---|
| 160 | +static ssize_t temp_store(struct device *dev, |
|---|
| 161 | + struct device_attribute *devattr, const char *buf, |
|---|
| 162 | + size_t count) |
|---|
| 171 | 163 | { |
|---|
| 172 | 164 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
|---|
| 173 | 165 | struct lm83_data *data = dev_get_drvdata(dev); |
|---|
| .. | .. |
|---|
| 195 | 187 | return sprintf(buf, "%d\n", data->alarms); |
|---|
| 196 | 188 | } |
|---|
| 197 | 189 | |
|---|
| 198 | | -static ssize_t show_alarm(struct device *dev, struct device_attribute |
|---|
| 199 | | - *devattr, char *buf) |
|---|
| 190 | +static ssize_t alarm_show(struct device *dev, |
|---|
| 191 | + struct device_attribute *devattr, char *buf) |
|---|
| 200 | 192 | { |
|---|
| 201 | 193 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
|---|
| 202 | 194 | struct lm83_data *data = lm83_update_device(dev); |
|---|
| .. | .. |
|---|
| 205 | 197 | return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); |
|---|
| 206 | 198 | } |
|---|
| 207 | 199 | |
|---|
| 208 | | -static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); |
|---|
| 209 | | -static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1); |
|---|
| 210 | | -static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2); |
|---|
| 211 | | -static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3); |
|---|
| 212 | | -static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, |
|---|
| 213 | | - set_temp, 4); |
|---|
| 214 | | -static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp, |
|---|
| 215 | | - set_temp, 5); |
|---|
| 216 | | -static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp, |
|---|
| 217 | | - set_temp, 6); |
|---|
| 218 | | -static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_temp, |
|---|
| 219 | | - set_temp, 7); |
|---|
| 220 | | -static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp, NULL, 8); |
|---|
| 221 | | -static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp, NULL, 8); |
|---|
| 222 | | -static SENSOR_DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_temp, |
|---|
| 223 | | - set_temp, 8); |
|---|
| 224 | | -static SENSOR_DEVICE_ATTR(temp4_crit, S_IRUGO, show_temp, NULL, 8); |
|---|
| 200 | +static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0); |
|---|
| 201 | +static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1); |
|---|
| 202 | +static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2); |
|---|
| 203 | +static SENSOR_DEVICE_ATTR_RO(temp4_input, temp, 3); |
|---|
| 204 | +static SENSOR_DEVICE_ATTR_RW(temp1_max, temp, 4); |
|---|
| 205 | +static SENSOR_DEVICE_ATTR_RW(temp2_max, temp, 5); |
|---|
| 206 | +static SENSOR_DEVICE_ATTR_RW(temp3_max, temp, 6); |
|---|
| 207 | +static SENSOR_DEVICE_ATTR_RW(temp4_max, temp, 7); |
|---|
| 208 | +static SENSOR_DEVICE_ATTR_RO(temp1_crit, temp, 8); |
|---|
| 209 | +static SENSOR_DEVICE_ATTR_RO(temp2_crit, temp, 8); |
|---|
| 210 | +static SENSOR_DEVICE_ATTR_RW(temp3_crit, temp, 8); |
|---|
| 211 | +static SENSOR_DEVICE_ATTR_RO(temp4_crit, temp, 8); |
|---|
| 225 | 212 | |
|---|
| 226 | 213 | /* Individual alarm files */ |
|---|
| 227 | | -static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); |
|---|
| 228 | | -static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 1); |
|---|
| 229 | | -static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 2); |
|---|
| 230 | | -static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 4); |
|---|
| 231 | | -static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); |
|---|
| 232 | | -static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 8); |
|---|
| 233 | | -static SENSOR_DEVICE_ATTR(temp4_crit_alarm, S_IRUGO, show_alarm, NULL, 9); |
|---|
| 234 | | -static SENSOR_DEVICE_ATTR(temp4_fault, S_IRUGO, show_alarm, NULL, 10); |
|---|
| 235 | | -static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO, show_alarm, NULL, 12); |
|---|
| 236 | | -static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 13); |
|---|
| 237 | | -static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 15); |
|---|
| 214 | +static SENSOR_DEVICE_ATTR_RO(temp1_crit_alarm, alarm, 0); |
|---|
| 215 | +static SENSOR_DEVICE_ATTR_RO(temp3_crit_alarm, alarm, 1); |
|---|
| 216 | +static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 2); |
|---|
| 217 | +static SENSOR_DEVICE_ATTR_RO(temp3_max_alarm, alarm, 4); |
|---|
| 218 | +static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, 6); |
|---|
| 219 | +static SENSOR_DEVICE_ATTR_RO(temp2_crit_alarm, alarm, 8); |
|---|
| 220 | +static SENSOR_DEVICE_ATTR_RO(temp4_crit_alarm, alarm, 9); |
|---|
| 221 | +static SENSOR_DEVICE_ATTR_RO(temp4_fault, alarm, 10); |
|---|
| 222 | +static SENSOR_DEVICE_ATTR_RO(temp4_max_alarm, alarm, 12); |
|---|
| 223 | +static SENSOR_DEVICE_ATTR_RO(temp2_fault, alarm, 13); |
|---|
| 224 | +static SENSOR_DEVICE_ATTR_RO(temp2_max_alarm, alarm, 15); |
|---|
| 238 | 225 | /* Raw alarm file for compatibility */ |
|---|
| 239 | 226 | static DEVICE_ATTR_RO(alarms); |
|---|
| 240 | 227 | |
|---|
| .. | .. |
|---|
| 330 | 317 | return 0; |
|---|
| 331 | 318 | } |
|---|
| 332 | 319 | |
|---|
| 333 | | -static int lm83_probe(struct i2c_client *new_client, |
|---|
| 334 | | - const struct i2c_device_id *id) |
|---|
| 320 | +static const struct i2c_device_id lm83_id[]; |
|---|
| 321 | + |
|---|
| 322 | +static int lm83_probe(struct i2c_client *new_client) |
|---|
| 335 | 323 | { |
|---|
| 336 | 324 | struct device *hwmon_dev; |
|---|
| 337 | 325 | struct lm83_data *data; |
|---|
| .. | .. |
|---|
| 351 | 339 | * declare 1 and 3 common, and then 2 and 4 only for the LM83. |
|---|
| 352 | 340 | */ |
|---|
| 353 | 341 | data->groups[0] = &lm83_group; |
|---|
| 354 | | - if (id->driver_data == lm83) |
|---|
| 342 | + if (i2c_match_id(lm83_id, new_client)->driver_data == lm83) |
|---|
| 355 | 343 | data->groups[1] = &lm83_group_opt; |
|---|
| 356 | 344 | |
|---|
| 357 | 345 | hwmon_dev = devm_hwmon_device_register_with_groups(&new_client->dev, |
|---|
| .. | .. |
|---|
| 376 | 364 | .driver = { |
|---|
| 377 | 365 | .name = "lm83", |
|---|
| 378 | 366 | }, |
|---|
| 379 | | - .probe = lm83_probe, |
|---|
| 367 | + .probe_new = lm83_probe, |
|---|
| 380 | 368 | .id_table = lm83_id, |
|---|
| 381 | 369 | .detect = lm83_detect, |
|---|
| 382 | 370 | .address_list = normal_i2c, |
|---|