| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * sis5595.c - Part of lm_sensors, Linux kernel modules |
|---|
| 3 | 4 | * for hardware monitoring |
|---|
| .. | .. |
|---|
| 7 | 8 | * Mark D. Studebaker <mdsxyz123@yahoo.com> |
|---|
| 8 | 9 | * Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with |
|---|
| 9 | 10 | * the help of Jean Delvare <jdelvare@suse.de> |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 12 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 13 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 14 | | - * (at your option) any later version. |
|---|
| 15 | | - * |
|---|
| 16 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 17 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 18 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 19 | | - * GNU General Public License for more details. |
|---|
| 20 | | - * |
|---|
| 21 | | - * You should have received a copy of the GNU General Public License |
|---|
| 22 | | - * along with this program; if not, write to the Free Software |
|---|
| 23 | | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 24 | 11 | */ |
|---|
| 25 | 12 | |
|---|
| 26 | 13 | /* |
|---|
| .. | .. |
|---|
| 66 | 53 | #include <linux/sysfs.h> |
|---|
| 67 | 54 | #include <linux/acpi.h> |
|---|
| 68 | 55 | #include <linux/io.h> |
|---|
| 69 | | - |
|---|
| 70 | 56 | |
|---|
| 71 | 57 | /* |
|---|
| 72 | 58 | * If force_addr is set to anything different from 0, we forcibly enable |
|---|
| .. | .. |
|---|
| 222 | 208 | }; |
|---|
| 223 | 209 | |
|---|
| 224 | 210 | /* 4 Voltages */ |
|---|
| 225 | | -static ssize_t show_in(struct device *dev, struct device_attribute *da, |
|---|
| 211 | +static ssize_t in_show(struct device *dev, struct device_attribute *da, |
|---|
| 226 | 212 | char *buf) |
|---|
| 227 | 213 | { |
|---|
| 228 | 214 | struct sis5595_data *data = sis5595_update_device(dev); |
|---|
| .. | .. |
|---|
| 231 | 217 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); |
|---|
| 232 | 218 | } |
|---|
| 233 | 219 | |
|---|
| 234 | | -static ssize_t show_in_min(struct device *dev, struct device_attribute *da, |
|---|
| 220 | +static ssize_t in_min_show(struct device *dev, struct device_attribute *da, |
|---|
| 235 | 221 | char *buf) |
|---|
| 236 | 222 | { |
|---|
| 237 | 223 | struct sis5595_data *data = sis5595_update_device(dev); |
|---|
| .. | .. |
|---|
| 240 | 226 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); |
|---|
| 241 | 227 | } |
|---|
| 242 | 228 | |
|---|
| 243 | | -static ssize_t show_in_max(struct device *dev, struct device_attribute *da, |
|---|
| 229 | +static ssize_t in_max_show(struct device *dev, struct device_attribute *da, |
|---|
| 244 | 230 | char *buf) |
|---|
| 245 | 231 | { |
|---|
| 246 | 232 | struct sis5595_data *data = sis5595_update_device(dev); |
|---|
| .. | .. |
|---|
| 249 | 235 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); |
|---|
| 250 | 236 | } |
|---|
| 251 | 237 | |
|---|
| 252 | | -static ssize_t set_in_min(struct device *dev, struct device_attribute *da, |
|---|
| 253 | | - const char *buf, size_t count) |
|---|
| 238 | +static ssize_t in_min_store(struct device *dev, struct device_attribute *da, |
|---|
| 239 | + const char *buf, size_t count) |
|---|
| 254 | 240 | { |
|---|
| 255 | 241 | struct sis5595_data *data = dev_get_drvdata(dev); |
|---|
| 256 | 242 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| .. | .. |
|---|
| 269 | 255 | return count; |
|---|
| 270 | 256 | } |
|---|
| 271 | 257 | |
|---|
| 272 | | -static ssize_t set_in_max(struct device *dev, struct device_attribute *da, |
|---|
| 273 | | - const char *buf, size_t count) |
|---|
| 258 | +static ssize_t in_max_store(struct device *dev, struct device_attribute *da, |
|---|
| 259 | + const char *buf, size_t count) |
|---|
| 274 | 260 | { |
|---|
| 275 | 261 | struct sis5595_data *data = dev_get_drvdata(dev); |
|---|
| 276 | 262 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| .. | .. |
|---|
| 289 | 275 | return count; |
|---|
| 290 | 276 | } |
|---|
| 291 | 277 | |
|---|
| 292 | | -#define show_in_offset(offset) \ |
|---|
| 293 | | -static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
|---|
| 294 | | - show_in, NULL, offset); \ |
|---|
| 295 | | -static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
|---|
| 296 | | - show_in_min, set_in_min, offset); \ |
|---|
| 297 | | -static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ |
|---|
| 298 | | - show_in_max, set_in_max, offset); |
|---|
| 299 | | - |
|---|
| 300 | | -show_in_offset(0); |
|---|
| 301 | | -show_in_offset(1); |
|---|
| 302 | | -show_in_offset(2); |
|---|
| 303 | | -show_in_offset(3); |
|---|
| 304 | | -show_in_offset(4); |
|---|
| 278 | +static SENSOR_DEVICE_ATTR_RO(in0_input, in, 0); |
|---|
| 279 | +static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0); |
|---|
| 280 | +static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0); |
|---|
| 281 | +static SENSOR_DEVICE_ATTR_RO(in1_input, in, 1); |
|---|
| 282 | +static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1); |
|---|
| 283 | +static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1); |
|---|
| 284 | +static SENSOR_DEVICE_ATTR_RO(in2_input, in, 2); |
|---|
| 285 | +static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2); |
|---|
| 286 | +static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2); |
|---|
| 287 | +static SENSOR_DEVICE_ATTR_RO(in3_input, in, 3); |
|---|
| 288 | +static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3); |
|---|
| 289 | +static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3); |
|---|
| 290 | +static SENSOR_DEVICE_ATTR_RO(in4_input, in, 4); |
|---|
| 291 | +static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4); |
|---|
| 292 | +static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4); |
|---|
| 305 | 293 | |
|---|
| 306 | 294 | /* Temperature */ |
|---|
| 307 | 295 | static ssize_t temp1_input_show(struct device *dev, |
|---|
| .. | .. |
|---|
| 368 | 356 | static DEVICE_ATTR_RW(temp1_max_hyst); |
|---|
| 369 | 357 | |
|---|
| 370 | 358 | /* 2 Fans */ |
|---|
| 371 | | -static ssize_t show_fan(struct device *dev, struct device_attribute *da, |
|---|
| 359 | +static ssize_t fan_show(struct device *dev, struct device_attribute *da, |
|---|
| 372 | 360 | char *buf) |
|---|
| 373 | 361 | { |
|---|
| 374 | 362 | struct sis5595_data *data = sis5595_update_device(dev); |
|---|
| .. | .. |
|---|
| 378 | 366 | DIV_FROM_REG(data->fan_div[nr]))); |
|---|
| 379 | 367 | } |
|---|
| 380 | 368 | |
|---|
| 381 | | -static ssize_t show_fan_min(struct device *dev, struct device_attribute *da, |
|---|
| 369 | +static ssize_t fan_min_show(struct device *dev, struct device_attribute *da, |
|---|
| 382 | 370 | char *buf) |
|---|
| 383 | 371 | { |
|---|
| 384 | 372 | struct sis5595_data *data = sis5595_update_device(dev); |
|---|
| .. | .. |
|---|
| 388 | 376 | DIV_FROM_REG(data->fan_div[nr]))); |
|---|
| 389 | 377 | } |
|---|
| 390 | 378 | |
|---|
| 391 | | -static ssize_t set_fan_min(struct device *dev, struct device_attribute *da, |
|---|
| 392 | | - const char *buf, size_t count) |
|---|
| 379 | +static ssize_t fan_min_store(struct device *dev, struct device_attribute *da, |
|---|
| 380 | + const char *buf, size_t count) |
|---|
| 393 | 381 | { |
|---|
| 394 | 382 | struct sis5595_data *data = dev_get_drvdata(dev); |
|---|
| 395 | 383 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| .. | .. |
|---|
| 408 | 396 | return count; |
|---|
| 409 | 397 | } |
|---|
| 410 | 398 | |
|---|
| 411 | | -static ssize_t show_fan_div(struct device *dev, struct device_attribute *da, |
|---|
| 399 | +static ssize_t fan_div_show(struct device *dev, struct device_attribute *da, |
|---|
| 412 | 400 | char *buf) |
|---|
| 413 | 401 | { |
|---|
| 414 | 402 | struct sis5595_data *data = sis5595_update_device(dev); |
|---|
| .. | .. |
|---|
| 423 | 411 | * least surprise; the user doesn't expect the fan minimum to change just |
|---|
| 424 | 412 | * because the divisor changed. |
|---|
| 425 | 413 | */ |
|---|
| 426 | | -static ssize_t set_fan_div(struct device *dev, struct device_attribute *da, |
|---|
| 427 | | - const char *buf, size_t count) |
|---|
| 414 | +static ssize_t fan_div_store(struct device *dev, struct device_attribute *da, |
|---|
| 415 | + const char *buf, size_t count) |
|---|
| 428 | 416 | { |
|---|
| 429 | 417 | struct sis5595_data *data = dev_get_drvdata(dev); |
|---|
| 430 | 418 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| .. | .. |
|---|
| 480 | 468 | return count; |
|---|
| 481 | 469 | } |
|---|
| 482 | 470 | |
|---|
| 483 | | -#define show_fan_offset(offset) \ |
|---|
| 484 | | -static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
|---|
| 485 | | - show_fan, NULL, offset - 1); \ |
|---|
| 486 | | -static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
|---|
| 487 | | - show_fan_min, set_fan_min, offset - 1); \ |
|---|
| 488 | | -static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ |
|---|
| 489 | | - show_fan_div, set_fan_div, offset - 1); |
|---|
| 490 | | - |
|---|
| 491 | | -show_fan_offset(1); |
|---|
| 492 | | -show_fan_offset(2); |
|---|
| 471 | +static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0); |
|---|
| 472 | +static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0); |
|---|
| 473 | +static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0); |
|---|
| 474 | +static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1); |
|---|
| 475 | +static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1); |
|---|
| 476 | +static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1); |
|---|
| 493 | 477 | |
|---|
| 494 | 478 | /* Alarms */ |
|---|
| 495 | 479 | static ssize_t alarms_show(struct device *dev, struct device_attribute *attr, |
|---|
| .. | .. |
|---|
| 500 | 484 | } |
|---|
| 501 | 485 | static DEVICE_ATTR_RO(alarms); |
|---|
| 502 | 486 | |
|---|
| 503 | | -static ssize_t show_alarm(struct device *dev, struct device_attribute *da, |
|---|
| 487 | +static ssize_t alarm_show(struct device *dev, struct device_attribute *da, |
|---|
| 504 | 488 | char *buf) |
|---|
| 505 | 489 | { |
|---|
| 506 | 490 | struct sis5595_data *data = sis5595_update_device(dev); |
|---|
| 507 | 491 | int nr = to_sensor_dev_attr(da)->index; |
|---|
| 508 | 492 | return sprintf(buf, "%u\n", (data->alarms >> nr) & 1); |
|---|
| 509 | 493 | } |
|---|
| 510 | | -static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); |
|---|
| 511 | | -static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); |
|---|
| 512 | | -static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); |
|---|
| 513 | | -static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3); |
|---|
| 514 | | -static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 15); |
|---|
| 515 | | -static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6); |
|---|
| 516 | | -static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7); |
|---|
| 517 | | -static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 15); |
|---|
| 494 | +static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0); |
|---|
| 495 | +static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1); |
|---|
| 496 | +static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2); |
|---|
| 497 | +static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3); |
|---|
| 498 | +static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 15); |
|---|
| 499 | +static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 6); |
|---|
| 500 | +static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 7); |
|---|
| 501 | +static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 15); |
|---|
| 518 | 502 | |
|---|
| 519 | 503 | static ssize_t name_show(struct device *dev, struct device_attribute *attr, |
|---|
| 520 | 504 | char *buf) |
|---|
| .. | .. |
|---|
| 672 | 656 | |
|---|
| 673 | 657 | return 0; |
|---|
| 674 | 658 | } |
|---|
| 675 | | - |
|---|
| 676 | 659 | |
|---|
| 677 | 660 | /* ISA access must be locked explicitly. */ |
|---|
| 678 | 661 | static int sis5595_read_value(struct sis5595_data *data, u8 reg) |
|---|