| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * smsc47m192.c - Support for hardware monitoring block of |
|---|
| 3 | 4 | * SMSC LPC47M192 and compatible Super I/O chips |
|---|
| .. | .. |
|---|
| 5 | 6 | * Copyright (C) 2006 Hartmut Rick <linux@rick.claranet.de> |
|---|
| 6 | 7 | * |
|---|
| 7 | 8 | * Derived from lm78.c and other chip drivers. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 10 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 11 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 12 | | - * (at your option) any later version. |
|---|
| 13 | | - * |
|---|
| 14 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 15 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | | - * GNU General Public License for more details. |
|---|
| 18 | | - * |
|---|
| 19 | | - * You should have received a copy of the GNU General Public License |
|---|
| 20 | | - * along with this program; if not, write to the Free Software |
|---|
| 21 | | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 22 | 9 | */ |
|---|
| 23 | 10 | |
|---|
| 24 | 11 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 179 | 166 | } |
|---|
| 180 | 167 | |
|---|
| 181 | 168 | /* Voltages */ |
|---|
| 182 | | -static ssize_t show_in(struct device *dev, struct device_attribute *attr, |
|---|
| 183 | | - char *buf) |
|---|
| 169 | +static ssize_t in_show(struct device *dev, struct device_attribute *attr, |
|---|
| 170 | + char *buf) |
|---|
| 184 | 171 | { |
|---|
| 185 | 172 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
|---|
| 186 | 173 | int nr = sensor_attr->index; |
|---|
| .. | .. |
|---|
| 188 | 175 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr], nr)); |
|---|
| 189 | 176 | } |
|---|
| 190 | 177 | |
|---|
| 191 | | -static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, |
|---|
| 192 | | - char *buf) |
|---|
| 178 | +static ssize_t in_min_show(struct device *dev, struct device_attribute *attr, |
|---|
| 179 | + char *buf) |
|---|
| 193 | 180 | { |
|---|
| 194 | 181 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
|---|
| 195 | 182 | int nr = sensor_attr->index; |
|---|
| .. | .. |
|---|
| 197 | 184 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr], nr)); |
|---|
| 198 | 185 | } |
|---|
| 199 | 186 | |
|---|
| 200 | | -static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, |
|---|
| 201 | | - char *buf) |
|---|
| 187 | +static ssize_t in_max_show(struct device *dev, struct device_attribute *attr, |
|---|
| 188 | + char *buf) |
|---|
| 202 | 189 | { |
|---|
| 203 | 190 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
|---|
| 204 | 191 | int nr = sensor_attr->index; |
|---|
| .. | .. |
|---|
| 206 | 193 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr], nr)); |
|---|
| 207 | 194 | } |
|---|
| 208 | 195 | |
|---|
| 209 | | -static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, |
|---|
| 210 | | - const char *buf, size_t count) |
|---|
| 196 | +static ssize_t in_min_store(struct device *dev, struct device_attribute *attr, |
|---|
| 197 | + const char *buf, size_t count) |
|---|
| 211 | 198 | { |
|---|
| 212 | 199 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
|---|
| 213 | 200 | int nr = sensor_attr->index; |
|---|
| .. | .. |
|---|
| 228 | 215 | return count; |
|---|
| 229 | 216 | } |
|---|
| 230 | 217 | |
|---|
| 231 | | -static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, |
|---|
| 232 | | - const char *buf, size_t count) |
|---|
| 218 | +static ssize_t in_max_store(struct device *dev, struct device_attribute *attr, |
|---|
| 219 | + const char *buf, size_t count) |
|---|
| 233 | 220 | { |
|---|
| 234 | 221 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
|---|
| 235 | 222 | int nr = sensor_attr->index; |
|---|
| .. | .. |
|---|
| 250 | 237 | return count; |
|---|
| 251 | 238 | } |
|---|
| 252 | 239 | |
|---|
| 253 | | -#define show_in_offset(offset) \ |
|---|
| 254 | | -static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
|---|
| 255 | | - show_in, NULL, offset); \ |
|---|
| 256 | | -static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
|---|
| 257 | | - show_in_min, set_in_min, offset); \ |
|---|
| 258 | | -static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ |
|---|
| 259 | | - show_in_max, set_in_max, offset); |
|---|
| 260 | | - |
|---|
| 261 | | -show_in_offset(0) |
|---|
| 262 | | -show_in_offset(1) |
|---|
| 263 | | -show_in_offset(2) |
|---|
| 264 | | -show_in_offset(3) |
|---|
| 265 | | -show_in_offset(4) |
|---|
| 266 | | -show_in_offset(5) |
|---|
| 267 | | -show_in_offset(6) |
|---|
| 268 | | -show_in_offset(7) |
|---|
| 240 | +static SENSOR_DEVICE_ATTR_RO(in0_input, in, 0); |
|---|
| 241 | +static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0); |
|---|
| 242 | +static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0); |
|---|
| 243 | +static SENSOR_DEVICE_ATTR_RO(in1_input, in, 1); |
|---|
| 244 | +static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1); |
|---|
| 245 | +static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1); |
|---|
| 246 | +static SENSOR_DEVICE_ATTR_RO(in2_input, in, 2); |
|---|
| 247 | +static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2); |
|---|
| 248 | +static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2); |
|---|
| 249 | +static SENSOR_DEVICE_ATTR_RO(in3_input, in, 3); |
|---|
| 250 | +static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3); |
|---|
| 251 | +static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3); |
|---|
| 252 | +static SENSOR_DEVICE_ATTR_RO(in4_input, in, 4); |
|---|
| 253 | +static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4); |
|---|
| 254 | +static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4); |
|---|
| 255 | +static SENSOR_DEVICE_ATTR_RO(in5_input, in, 5); |
|---|
| 256 | +static SENSOR_DEVICE_ATTR_RW(in5_min, in_min, 5); |
|---|
| 257 | +static SENSOR_DEVICE_ATTR_RW(in5_max, in_max, 5); |
|---|
| 258 | +static SENSOR_DEVICE_ATTR_RO(in6_input, in, 6); |
|---|
| 259 | +static SENSOR_DEVICE_ATTR_RW(in6_min, in_min, 6); |
|---|
| 260 | +static SENSOR_DEVICE_ATTR_RW(in6_max, in_max, 6); |
|---|
| 261 | +static SENSOR_DEVICE_ATTR_RO(in7_input, in, 7); |
|---|
| 262 | +static SENSOR_DEVICE_ATTR_RW(in7_min, in_min, 7); |
|---|
| 263 | +static SENSOR_DEVICE_ATTR_RW(in7_max, in_max, 7); |
|---|
| 269 | 264 | |
|---|
| 270 | 265 | /* Temperatures */ |
|---|
| 271 | | -static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
|---|
| 272 | | - char *buf) |
|---|
| 266 | +static ssize_t temp_show(struct device *dev, struct device_attribute *attr, |
|---|
| 267 | + char *buf) |
|---|
| 273 | 268 | { |
|---|
| 274 | 269 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
|---|
| 275 | 270 | int nr = sensor_attr->index; |
|---|
| .. | .. |
|---|
| 277 | 272 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])); |
|---|
| 278 | 273 | } |
|---|
| 279 | 274 | |
|---|
| 280 | | -static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, |
|---|
| 281 | | - char *buf) |
|---|
| 275 | +static ssize_t temp_min_show(struct device *dev, |
|---|
| 276 | + struct device_attribute *attr, char *buf) |
|---|
| 282 | 277 | { |
|---|
| 283 | 278 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
|---|
| 284 | 279 | int nr = sensor_attr->index; |
|---|
| .. | .. |
|---|
| 286 | 281 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr])); |
|---|
| 287 | 282 | } |
|---|
| 288 | 283 | |
|---|
| 289 | | -static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, |
|---|
| 290 | | - char *buf) |
|---|
| 284 | +static ssize_t temp_max_show(struct device *dev, |
|---|
| 285 | + struct device_attribute *attr, char *buf) |
|---|
| 291 | 286 | { |
|---|
| 292 | 287 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
|---|
| 293 | 288 | int nr = sensor_attr->index; |
|---|
| .. | .. |
|---|
| 295 | 290 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr])); |
|---|
| 296 | 291 | } |
|---|
| 297 | 292 | |
|---|
| 298 | | -static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, |
|---|
| 299 | | - const char *buf, size_t count) |
|---|
| 293 | +static ssize_t temp_min_store(struct device *dev, |
|---|
| 294 | + struct device_attribute *attr, const char *buf, |
|---|
| 295 | + size_t count) |
|---|
| 300 | 296 | { |
|---|
| 301 | 297 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
|---|
| 302 | 298 | int nr = sensor_attr->index; |
|---|
| .. | .. |
|---|
| 317 | 313 | return count; |
|---|
| 318 | 314 | } |
|---|
| 319 | 315 | |
|---|
| 320 | | -static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
|---|
| 321 | | - const char *buf, size_t count) |
|---|
| 316 | +static ssize_t temp_max_store(struct device *dev, |
|---|
| 317 | + struct device_attribute *attr, const char *buf, |
|---|
| 318 | + size_t count) |
|---|
| 322 | 319 | { |
|---|
| 323 | 320 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
|---|
| 324 | 321 | int nr = sensor_attr->index; |
|---|
| .. | .. |
|---|
| 339 | 336 | return count; |
|---|
| 340 | 337 | } |
|---|
| 341 | 338 | |
|---|
| 342 | | -static ssize_t show_temp_offset(struct device *dev, struct device_attribute |
|---|
| 343 | | - *attr, char *buf) |
|---|
| 339 | +static ssize_t temp_offset_show(struct device *dev, |
|---|
| 340 | + struct device_attribute *attr, char *buf) |
|---|
| 344 | 341 | { |
|---|
| 345 | 342 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
|---|
| 346 | 343 | int nr = sensor_attr->index; |
|---|
| .. | .. |
|---|
| 348 | 345 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_offset[nr])); |
|---|
| 349 | 346 | } |
|---|
| 350 | 347 | |
|---|
| 351 | | -static ssize_t set_temp_offset(struct device *dev, struct device_attribute |
|---|
| 352 | | - *attr, const char *buf, size_t count) |
|---|
| 348 | +static ssize_t temp_offset_store(struct device *dev, |
|---|
| 349 | + struct device_attribute *attr, |
|---|
| 350 | + const char *buf, size_t count) |
|---|
| 353 | 351 | { |
|---|
| 354 | 352 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
|---|
| 355 | 353 | int nr = sensor_attr->index; |
|---|
| .. | .. |
|---|
| 385 | 383 | return count; |
|---|
| 386 | 384 | } |
|---|
| 387 | 385 | |
|---|
| 388 | | -#define show_temp_index(index) \ |
|---|
| 389 | | -static SENSOR_DEVICE_ATTR(temp##index##_input, S_IRUGO, \ |
|---|
| 390 | | - show_temp, NULL, index-1); \ |
|---|
| 391 | | -static SENSOR_DEVICE_ATTR(temp##index##_min, S_IRUGO | S_IWUSR, \ |
|---|
| 392 | | - show_temp_min, set_temp_min, index-1); \ |
|---|
| 393 | | -static SENSOR_DEVICE_ATTR(temp##index##_max, S_IRUGO | S_IWUSR, \ |
|---|
| 394 | | - show_temp_max, set_temp_max, index-1); \ |
|---|
| 395 | | -static SENSOR_DEVICE_ATTR(temp##index##_offset, S_IRUGO | S_IWUSR, \ |
|---|
| 396 | | - show_temp_offset, set_temp_offset, index-1); |
|---|
| 397 | | - |
|---|
| 398 | | -show_temp_index(1) |
|---|
| 399 | | -show_temp_index(2) |
|---|
| 400 | | -show_temp_index(3) |
|---|
| 386 | +static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0); |
|---|
| 387 | +static SENSOR_DEVICE_ATTR_RW(temp1_min, temp_min, 0); |
|---|
| 388 | +static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0); |
|---|
| 389 | +static SENSOR_DEVICE_ATTR_RW(temp1_offset, temp_offset, 0); |
|---|
| 390 | +static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1); |
|---|
| 391 | +static SENSOR_DEVICE_ATTR_RW(temp2_min, temp_min, 1); |
|---|
| 392 | +static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1); |
|---|
| 393 | +static SENSOR_DEVICE_ATTR_RW(temp2_offset, temp_offset, 1); |
|---|
| 394 | +static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2); |
|---|
| 395 | +static SENSOR_DEVICE_ATTR_RW(temp3_min, temp_min, 2); |
|---|
| 396 | +static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_max, 2); |
|---|
| 397 | +static SENSOR_DEVICE_ATTR_RW(temp3_offset, temp_offset, 2); |
|---|
| 401 | 398 | |
|---|
| 402 | 399 | /* VID */ |
|---|
| 403 | 400 | static ssize_t cpu0_vid_show(struct device *dev, |
|---|
| .. | .. |
|---|
| 434 | 431 | static DEVICE_ATTR_RW(vrm); |
|---|
| 435 | 432 | |
|---|
| 436 | 433 | /* Alarms */ |
|---|
| 437 | | -static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, |
|---|
| 438 | | - char *buf) |
|---|
| 434 | +static ssize_t alarm_show(struct device *dev, struct device_attribute *attr, |
|---|
| 435 | + char *buf) |
|---|
| 439 | 436 | { |
|---|
| 440 | 437 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
|---|
| 441 | 438 | int nr = sensor_attr->index; |
|---|
| .. | .. |
|---|
| 443 | 440 | return sprintf(buf, "%u\n", (data->alarms & nr) ? 1 : 0); |
|---|
| 444 | 441 | } |
|---|
| 445 | 442 | |
|---|
| 446 | | -static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 0x0010); |
|---|
| 447 | | -static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 0x0020); |
|---|
| 448 | | -static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 0x0040); |
|---|
| 449 | | -static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 0x4000); |
|---|
| 450 | | -static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 0x8000); |
|---|
| 451 | | -static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0x0001); |
|---|
| 452 | | -static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 0x0002); |
|---|
| 453 | | -static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 0x0004); |
|---|
| 454 | | -static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 0x0008); |
|---|
| 455 | | -static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 0x0100); |
|---|
| 456 | | -static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 0x0200); |
|---|
| 457 | | -static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 0x0400); |
|---|
| 458 | | -static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 0x0800); |
|---|
| 443 | +static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 0x0010); |
|---|
| 444 | +static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 0x0020); |
|---|
| 445 | +static SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 0x0040); |
|---|
| 446 | +static SENSOR_DEVICE_ATTR_RO(temp2_fault, alarm, 0x4000); |
|---|
| 447 | +static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 0x8000); |
|---|
| 448 | +static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0x0001); |
|---|
| 449 | +static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 0x0002); |
|---|
| 450 | +static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 0x0004); |
|---|
| 451 | +static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 0x0008); |
|---|
| 452 | +static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 0x0100); |
|---|
| 453 | +static SENSOR_DEVICE_ATTR_RO(in5_alarm, alarm, 0x0200); |
|---|
| 454 | +static SENSOR_DEVICE_ATTR_RO(in6_alarm, alarm, 0x0400); |
|---|
| 455 | +static SENSOR_DEVICE_ATTR_RO(in7_alarm, alarm, 0x0800); |
|---|
| 459 | 456 | |
|---|
| 460 | 457 | static struct attribute *smsc47m192_attributes[] = { |
|---|
| 461 | 458 | &sensor_dev_attr_in0_input.dev_attr.attr, |
|---|
| .. | .. |
|---|
| 590 | 587 | return 0; |
|---|
| 591 | 588 | } |
|---|
| 592 | 589 | |
|---|
| 593 | | -static int smsc47m192_probe(struct i2c_client *client, |
|---|
| 594 | | - const struct i2c_device_id *id) |
|---|
| 590 | +static int smsc47m192_probe(struct i2c_client *client) |
|---|
| 595 | 591 | { |
|---|
| 596 | 592 | struct device *dev = &client->dev; |
|---|
| 597 | 593 | struct device *hwmon_dev; |
|---|
| .. | .. |
|---|
| 632 | 628 | .driver = { |
|---|
| 633 | 629 | .name = "smsc47m192", |
|---|
| 634 | 630 | }, |
|---|
| 635 | | - .probe = smsc47m192_probe, |
|---|
| 631 | + .probe_new = smsc47m192_probe, |
|---|
| 636 | 632 | .id_table = smsc47m192_id, |
|---|
| 637 | 633 | .detect = smsc47m192_detect, |
|---|
| 638 | 634 | .address_list = normal_i2c, |
|---|