| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * gl518sm.c - Part of lm_sensors, Linux kernel modules for hardware |
|---|
| 3 | 4 | * monitoring |
|---|
| .. | .. |
|---|
| 5 | 6 | * Kyosti Malkki <kmalkki@cc.hut.fi> |
|---|
| 6 | 7 | * Copyright (C) 2004 Hong-Gunn Chew <hglinux@gunnet.org> and |
|---|
| 7 | 8 | * Jean Delvare <jdelvare@suse.de> |
|---|
| 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 | * Ported to Linux 2.6 by Hong-Gunn Chew with the help of Jean Delvare |
|---|
| 24 | 11 | * and advice of Greg Kroah-Hartman. |
|---|
| .. | .. |
|---|
| 264 | 251 | show(BOOL, beep_enable, beep_enable); |
|---|
| 265 | 252 | show(BEEP_MASK, beep_mask, beep_mask); |
|---|
| 266 | 253 | |
|---|
| 267 | | -static ssize_t show_fan_input(struct device *dev, |
|---|
| 254 | +static ssize_t fan_input_show(struct device *dev, |
|---|
| 268 | 255 | struct device_attribute *attr, char *buf) |
|---|
| 269 | 256 | { |
|---|
| 270 | 257 | int nr = to_sensor_dev_attr(attr)->index; |
|---|
| .. | .. |
|---|
| 273 | 260 | DIV_FROM_REG(data->fan_div[nr]))); |
|---|
| 274 | 261 | } |
|---|
| 275 | 262 | |
|---|
| 276 | | -static ssize_t show_fan_min(struct device *dev, |
|---|
| 277 | | - struct device_attribute *attr, char *buf) |
|---|
| 263 | +static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr, |
|---|
| 264 | + char *buf) |
|---|
| 278 | 265 | { |
|---|
| 279 | 266 | int nr = to_sensor_dev_attr(attr)->index; |
|---|
| 280 | 267 | struct gl518_data *data = gl518_update_device(dev); |
|---|
| .. | .. |
|---|
| 282 | 269 | DIV_FROM_REG(data->fan_div[nr]))); |
|---|
| 283 | 270 | } |
|---|
| 284 | 271 | |
|---|
| 285 | | -static ssize_t show_fan_div(struct device *dev, |
|---|
| 286 | | - struct device_attribute *attr, char *buf) |
|---|
| 272 | +static ssize_t fan_div_show(struct device *dev, struct device_attribute *attr, |
|---|
| 273 | + char *buf) |
|---|
| 287 | 274 | { |
|---|
| 288 | 275 | int nr = to_sensor_dev_attr(attr)->index; |
|---|
| 289 | 276 | struct gl518_data *data = gl518_update_device(dev); |
|---|
| .. | .. |
|---|
| 350 | 337 | set_bits(BOOL, beep_enable, beep_enable, GL518_REG_CONF, 0x04, 2); |
|---|
| 351 | 338 | set(BEEP_MASK, beep_mask, beep_mask, GL518_REG_ALARM); |
|---|
| 352 | 339 | |
|---|
| 353 | | -static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
|---|
| 354 | | - const char *buf, size_t count) |
|---|
| 340 | +static ssize_t fan_min_store(struct device *dev, |
|---|
| 341 | + struct device_attribute *attr, const char *buf, |
|---|
| 342 | + size_t count) |
|---|
| 355 | 343 | { |
|---|
| 356 | 344 | struct gl518_data *data = dev_get_drvdata(dev); |
|---|
| 357 | 345 | struct i2c_client *client = data->client; |
|---|
| .. | .. |
|---|
| 383 | 371 | return count; |
|---|
| 384 | 372 | } |
|---|
| 385 | 373 | |
|---|
| 386 | | -static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
|---|
| 387 | | - const char *buf, size_t count) |
|---|
| 374 | +static ssize_t fan_div_store(struct device *dev, |
|---|
| 375 | + struct device_attribute *attr, const char *buf, |
|---|
| 376 | + size_t count) |
|---|
| 388 | 377 | { |
|---|
| 389 | 378 | struct gl518_data *data = dev_get_drvdata(dev); |
|---|
| 390 | 379 | struct i2c_client *client = data->client; |
|---|
| .. | .. |
|---|
| 427 | 416 | return count; |
|---|
| 428 | 417 | } |
|---|
| 429 | 418 | |
|---|
| 430 | | -static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL); |
|---|
| 431 | | -static DEVICE_ATTR(temp1_max, S_IWUSR|S_IRUGO, show_temp_max1, set_temp_max1); |
|---|
| 432 | | -static DEVICE_ATTR(temp1_max_hyst, S_IWUSR|S_IRUGO, |
|---|
| 433 | | - show_temp_hyst1, set_temp_hyst1); |
|---|
| 434 | | -static DEVICE_ATTR(fan1_auto, S_IWUSR|S_IRUGO, show_fan_auto1, set_fan_auto1); |
|---|
| 435 | | -static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0); |
|---|
| 436 | | -static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1); |
|---|
| 437 | | -static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR|S_IRUGO, |
|---|
| 438 | | - show_fan_min, set_fan_min, 0); |
|---|
| 439 | | -static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR|S_IRUGO, |
|---|
| 440 | | - show_fan_min, set_fan_min, 1); |
|---|
| 441 | | -static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR|S_IRUGO, |
|---|
| 442 | | - show_fan_div, set_fan_div, 0); |
|---|
| 443 | | -static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR|S_IRUGO, |
|---|
| 444 | | - show_fan_div, set_fan_div, 1); |
|---|
| 445 | | -static DEVICE_ATTR(in0_input, S_IRUGO, show_in_input0, NULL); |
|---|
| 446 | | -static DEVICE_ATTR(in1_input, S_IRUGO, show_in_input1, NULL); |
|---|
| 447 | | -static DEVICE_ATTR(in2_input, S_IRUGO, show_in_input2, NULL); |
|---|
| 448 | | -static DEVICE_ATTR(in3_input, S_IRUGO, show_in_input3, NULL); |
|---|
| 449 | | -static DEVICE_ATTR(in0_min, S_IWUSR|S_IRUGO, show_in_min0, set_in_min0); |
|---|
| 450 | | -static DEVICE_ATTR(in1_min, S_IWUSR|S_IRUGO, show_in_min1, set_in_min1); |
|---|
| 451 | | -static DEVICE_ATTR(in2_min, S_IWUSR|S_IRUGO, show_in_min2, set_in_min2); |
|---|
| 452 | | -static DEVICE_ATTR(in3_min, S_IWUSR|S_IRUGO, show_in_min3, set_in_min3); |
|---|
| 453 | | -static DEVICE_ATTR(in0_max, S_IWUSR|S_IRUGO, show_in_max0, set_in_max0); |
|---|
| 454 | | -static DEVICE_ATTR(in1_max, S_IWUSR|S_IRUGO, show_in_max1, set_in_max1); |
|---|
| 455 | | -static DEVICE_ATTR(in2_max, S_IWUSR|S_IRUGO, show_in_max2, set_in_max2); |
|---|
| 456 | | -static DEVICE_ATTR(in3_max, S_IWUSR|S_IRUGO, show_in_max3, set_in_max3); |
|---|
| 457 | | -static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
|---|
| 458 | | -static DEVICE_ATTR(beep_enable, S_IWUSR|S_IRUGO, |
|---|
| 459 | | - show_beep_enable, set_beep_enable); |
|---|
| 460 | | -static DEVICE_ATTR(beep_mask, S_IWUSR|S_IRUGO, |
|---|
| 461 | | - show_beep_mask, set_beep_mask); |
|---|
| 419 | +static DEVICE_ATTR(temp1_input, 0444, show_temp_input1, NULL); |
|---|
| 420 | +static DEVICE_ATTR(temp1_max, 0644, show_temp_max1, set_temp_max1); |
|---|
| 421 | +static DEVICE_ATTR(temp1_max_hyst, 0644, |
|---|
| 422 | + show_temp_hyst1, set_temp_hyst1); |
|---|
| 423 | +static DEVICE_ATTR(fan1_auto, 0644, show_fan_auto1, set_fan_auto1); |
|---|
| 424 | +static SENSOR_DEVICE_ATTR_RO(fan1_input, fan_input, 0); |
|---|
| 425 | +static SENSOR_DEVICE_ATTR_RO(fan2_input, fan_input, 1); |
|---|
| 426 | +static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0); |
|---|
| 427 | +static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1); |
|---|
| 428 | +static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0); |
|---|
| 429 | +static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1); |
|---|
| 430 | +static DEVICE_ATTR(in0_input, 0444, show_in_input0, NULL); |
|---|
| 431 | +static DEVICE_ATTR(in1_input, 0444, show_in_input1, NULL); |
|---|
| 432 | +static DEVICE_ATTR(in2_input, 0444, show_in_input2, NULL); |
|---|
| 433 | +static DEVICE_ATTR(in3_input, 0444, show_in_input3, NULL); |
|---|
| 434 | +static DEVICE_ATTR(in0_min, 0644, show_in_min0, set_in_min0); |
|---|
| 435 | +static DEVICE_ATTR(in1_min, 0644, show_in_min1, set_in_min1); |
|---|
| 436 | +static DEVICE_ATTR(in2_min, 0644, show_in_min2, set_in_min2); |
|---|
| 437 | +static DEVICE_ATTR(in3_min, 0644, show_in_min3, set_in_min3); |
|---|
| 438 | +static DEVICE_ATTR(in0_max, 0644, show_in_max0, set_in_max0); |
|---|
| 439 | +static DEVICE_ATTR(in1_max, 0644, show_in_max1, set_in_max1); |
|---|
| 440 | +static DEVICE_ATTR(in2_max, 0644, show_in_max2, set_in_max2); |
|---|
| 441 | +static DEVICE_ATTR(in3_max, 0644, show_in_max3, set_in_max3); |
|---|
| 442 | +static DEVICE_ATTR(alarms, 0444, show_alarms, NULL); |
|---|
| 443 | +static DEVICE_ATTR(beep_enable, 0644, |
|---|
| 444 | + show_beep_enable, set_beep_enable); |
|---|
| 445 | +static DEVICE_ATTR(beep_mask, 0644, |
|---|
| 446 | + show_beep_mask, set_beep_mask); |
|---|
| 462 | 447 | |
|---|
| 463 | | -static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, |
|---|
| 448 | +static ssize_t alarm_show(struct device *dev, struct device_attribute *attr, |
|---|
| 464 | 449 | char *buf) |
|---|
| 465 | 450 | { |
|---|
| 466 | 451 | int bitnr = to_sensor_dev_attr(attr)->index; |
|---|
| .. | .. |
|---|
| 468 | 453 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); |
|---|
| 469 | 454 | } |
|---|
| 470 | 455 | |
|---|
| 471 | | -static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); |
|---|
| 472 | | -static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); |
|---|
| 473 | | -static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); |
|---|
| 474 | | -static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3); |
|---|
| 475 | | -static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); |
|---|
| 476 | | -static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 5); |
|---|
| 477 | | -static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 6); |
|---|
| 456 | +static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0); |
|---|
| 457 | +static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1); |
|---|
| 458 | +static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2); |
|---|
| 459 | +static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3); |
|---|
| 460 | +static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4); |
|---|
| 461 | +static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 5); |
|---|
| 462 | +static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 6); |
|---|
| 478 | 463 | |
|---|
| 479 | | -static ssize_t show_beep(struct device *dev, struct device_attribute *attr, |
|---|
| 480 | | - char *buf) |
|---|
| 464 | +static ssize_t beep_show(struct device *dev, struct device_attribute *attr, |
|---|
| 465 | + char *buf) |
|---|
| 481 | 466 | { |
|---|
| 482 | 467 | int bitnr = to_sensor_dev_attr(attr)->index; |
|---|
| 483 | 468 | struct gl518_data *data = gl518_update_device(dev); |
|---|
| 484 | 469 | return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1); |
|---|
| 485 | 470 | } |
|---|
| 486 | 471 | |
|---|
| 487 | | -static ssize_t set_beep(struct device *dev, struct device_attribute *attr, |
|---|
| 488 | | - const char *buf, size_t count) |
|---|
| 472 | +static ssize_t beep_store(struct device *dev, struct device_attribute *attr, |
|---|
| 473 | + const char *buf, size_t count) |
|---|
| 489 | 474 | { |
|---|
| 490 | 475 | struct gl518_data *data = dev_get_drvdata(dev); |
|---|
| 491 | 476 | struct i2c_client *client = data->client; |
|---|
| .. | .. |
|---|
| 511 | 496 | return count; |
|---|
| 512 | 497 | } |
|---|
| 513 | 498 | |
|---|
| 514 | | -static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 0); |
|---|
| 515 | | -static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 1); |
|---|
| 516 | | -static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 2); |
|---|
| 517 | | -static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 3); |
|---|
| 518 | | -static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 4); |
|---|
| 519 | | -static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 5); |
|---|
| 520 | | -static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 6); |
|---|
| 499 | +static SENSOR_DEVICE_ATTR_RW(in0_beep, beep, 0); |
|---|
| 500 | +static SENSOR_DEVICE_ATTR_RW(in1_beep, beep, 1); |
|---|
| 501 | +static SENSOR_DEVICE_ATTR_RW(in2_beep, beep, 2); |
|---|
| 502 | +static SENSOR_DEVICE_ATTR_RW(in3_beep, beep, 3); |
|---|
| 503 | +static SENSOR_DEVICE_ATTR_RW(temp1_beep, beep, 4); |
|---|
| 504 | +static SENSOR_DEVICE_ATTR_RW(fan1_beep, beep, 5); |
|---|
| 505 | +static SENSOR_DEVICE_ATTR_RW(fan2_beep, beep, 6); |
|---|
| 521 | 506 | |
|---|
| 522 | 507 | static struct attribute *gl518_attributes[] = { |
|---|
| 523 | 508 | &dev_attr_in3_input.attr, |
|---|
| .. | .. |
|---|
| 626 | 611 | gl518_write_value(client, GL518_REG_CONF, 0x40 | regvalue); |
|---|
| 627 | 612 | } |
|---|
| 628 | 613 | |
|---|
| 629 | | -static int gl518_probe(struct i2c_client *client, |
|---|
| 630 | | - const struct i2c_device_id *id) |
|---|
| 614 | +static int gl518_probe(struct i2c_client *client) |
|---|
| 631 | 615 | { |
|---|
| 632 | 616 | struct device *dev = &client->dev; |
|---|
| 633 | 617 | struct device *hwmon_dev; |
|---|
| .. | .. |
|---|
| 668 | 652 | .driver = { |
|---|
| 669 | 653 | .name = "gl518sm", |
|---|
| 670 | 654 | }, |
|---|
| 671 | | - .probe = gl518_probe, |
|---|
| 655 | + .probe_new = gl518_probe, |
|---|
| 672 | 656 | .id_table = gl518_id, |
|---|
| 673 | 657 | .detect = gl518_detect, |
|---|
| 674 | 658 | .address_list = normal_i2c, |
|---|