| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * emc6w201.c - Hardware monitoring driver for the SMSC EMC6W201 |
|---|
| 3 | 4 | * Copyright (C) 2011 Jean Delvare <jdelvare@suse.de> |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 7 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | | - * (at your option) any later version. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | | - * GNU General Public License for more details. |
|---|
| 14 | | - * |
|---|
| 15 | | - * You should have received a copy of the GNU General Public License |
|---|
| 16 | | - * along with this program; if not, write to the Free Software |
|---|
| 17 | | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 18 | 5 | */ |
|---|
| 19 | 6 | |
|---|
| 20 | 7 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 189 | 176 | |
|---|
| 190 | 177 | static const s16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 }; |
|---|
| 191 | 178 | |
|---|
| 192 | | -static ssize_t show_in(struct device *dev, struct device_attribute *devattr, |
|---|
| 193 | | - char *buf) |
|---|
| 179 | +static ssize_t in_show(struct device *dev, struct device_attribute *devattr, |
|---|
| 180 | + char *buf) |
|---|
| 194 | 181 | { |
|---|
| 195 | 182 | struct emc6w201_data *data = emc6w201_update_device(dev); |
|---|
| 196 | 183 | int sf = to_sensor_dev_attr_2(devattr)->index; |
|---|
| .. | .. |
|---|
| 200 | 187 | (unsigned)data->in[sf][nr] * nominal_mv[nr] / 0xC0); |
|---|
| 201 | 188 | } |
|---|
| 202 | 189 | |
|---|
| 203 | | -static ssize_t set_in(struct device *dev, struct device_attribute *devattr, |
|---|
| 204 | | - const char *buf, size_t count) |
|---|
| 190 | +static ssize_t in_store(struct device *dev, struct device_attribute *devattr, |
|---|
| 191 | + const char *buf, size_t count) |
|---|
| 205 | 192 | { |
|---|
| 206 | 193 | struct emc6w201_data *data = dev_get_drvdata(dev); |
|---|
| 207 | 194 | struct i2c_client *client = data->client; |
|---|
| .. | .. |
|---|
| 228 | 215 | return err < 0 ? err : count; |
|---|
| 229 | 216 | } |
|---|
| 230 | 217 | |
|---|
| 231 | | -static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, |
|---|
| 232 | | - char *buf) |
|---|
| 218 | +static ssize_t temp_show(struct device *dev, struct device_attribute *devattr, |
|---|
| 219 | + char *buf) |
|---|
| 233 | 220 | { |
|---|
| 234 | 221 | struct emc6w201_data *data = emc6w201_update_device(dev); |
|---|
| 235 | 222 | int sf = to_sensor_dev_attr_2(devattr)->index; |
|---|
| .. | .. |
|---|
| 238 | 225 | return sprintf(buf, "%d\n", (int)data->temp[sf][nr] * 1000); |
|---|
| 239 | 226 | } |
|---|
| 240 | 227 | |
|---|
| 241 | | -static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, |
|---|
| 242 | | - const char *buf, size_t count) |
|---|
| 228 | +static ssize_t temp_store(struct device *dev, |
|---|
| 229 | + struct device_attribute *devattr, const char *buf, |
|---|
| 230 | + size_t count) |
|---|
| 243 | 231 | { |
|---|
| 244 | 232 | struct emc6w201_data *data = dev_get_drvdata(dev); |
|---|
| 245 | 233 | struct i2c_client *client = data->client; |
|---|
| .. | .. |
|---|
| 266 | 254 | return err < 0 ? err : count; |
|---|
| 267 | 255 | } |
|---|
| 268 | 256 | |
|---|
| 269 | | -static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, |
|---|
| 270 | | - char *buf) |
|---|
| 257 | +static ssize_t fan_show(struct device *dev, struct device_attribute *devattr, |
|---|
| 258 | + char *buf) |
|---|
| 271 | 259 | { |
|---|
| 272 | 260 | struct emc6w201_data *data = emc6w201_update_device(dev); |
|---|
| 273 | 261 | int sf = to_sensor_dev_attr_2(devattr)->index; |
|---|
| .. | .. |
|---|
| 282 | 270 | return sprintf(buf, "%u\n", rpm); |
|---|
| 283 | 271 | } |
|---|
| 284 | 272 | |
|---|
| 285 | | -static ssize_t set_fan(struct device *dev, struct device_attribute *devattr, |
|---|
| 286 | | - const char *buf, size_t count) |
|---|
| 273 | +static ssize_t fan_store(struct device *dev, struct device_attribute *devattr, |
|---|
| 274 | + const char *buf, size_t count) |
|---|
| 287 | 275 | { |
|---|
| 288 | 276 | struct emc6w201_data *data = dev_get_drvdata(dev); |
|---|
| 289 | 277 | struct i2c_client *client = data->client; |
|---|
| .. | .. |
|---|
| 312 | 300 | return err < 0 ? err : count; |
|---|
| 313 | 301 | } |
|---|
| 314 | 302 | |
|---|
| 315 | | -static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, input); |
|---|
| 316 | | -static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in, |
|---|
| 317 | | - 0, min); |
|---|
| 318 | | -static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in, |
|---|
| 319 | | - 0, max); |
|---|
| 320 | | -static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, input); |
|---|
| 321 | | -static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in, |
|---|
| 322 | | - 1, min); |
|---|
| 323 | | -static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in, |
|---|
| 324 | | - 1, max); |
|---|
| 325 | | -static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, input); |
|---|
| 326 | | -static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in, |
|---|
| 327 | | - 2, min); |
|---|
| 328 | | -static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in, |
|---|
| 329 | | - 2, max); |
|---|
| 330 | | -static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, input); |
|---|
| 331 | | -static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in, |
|---|
| 332 | | - 3, min); |
|---|
| 333 | | -static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in, |
|---|
| 334 | | - 3, max); |
|---|
| 335 | | -static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, input); |
|---|
| 336 | | -static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in, |
|---|
| 337 | | - 4, min); |
|---|
| 338 | | -static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in, |
|---|
| 339 | | - 4, max); |
|---|
| 340 | | -static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, input); |
|---|
| 341 | | -static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in, |
|---|
| 342 | | - 5, min); |
|---|
| 343 | | -static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in, |
|---|
| 344 | | - 5, max); |
|---|
| 303 | +static SENSOR_DEVICE_ATTR_2_RO(in0_input, in, 0, input); |
|---|
| 304 | +static SENSOR_DEVICE_ATTR_2_RW(in0_min, in, 0, min); |
|---|
| 305 | +static SENSOR_DEVICE_ATTR_2_RW(in0_max, in, 0, max); |
|---|
| 306 | +static SENSOR_DEVICE_ATTR_2_RO(in1_input, in, 1, input); |
|---|
| 307 | +static SENSOR_DEVICE_ATTR_2_RW(in1_min, in, 1, min); |
|---|
| 308 | +static SENSOR_DEVICE_ATTR_2_RW(in1_max, in, 1, max); |
|---|
| 309 | +static SENSOR_DEVICE_ATTR_2_RO(in2_input, in, 2, input); |
|---|
| 310 | +static SENSOR_DEVICE_ATTR_2_RW(in2_min, in, 2, min); |
|---|
| 311 | +static SENSOR_DEVICE_ATTR_2_RW(in2_max, in, 2, max); |
|---|
| 312 | +static SENSOR_DEVICE_ATTR_2_RO(in3_input, in, 3, input); |
|---|
| 313 | +static SENSOR_DEVICE_ATTR_2_RW(in3_min, in, 3, min); |
|---|
| 314 | +static SENSOR_DEVICE_ATTR_2_RW(in3_max, in, 3, max); |
|---|
| 315 | +static SENSOR_DEVICE_ATTR_2_RO(in4_input, in, 4, input); |
|---|
| 316 | +static SENSOR_DEVICE_ATTR_2_RW(in4_min, in, 4, min); |
|---|
| 317 | +static SENSOR_DEVICE_ATTR_2_RW(in4_max, in, 4, max); |
|---|
| 318 | +static SENSOR_DEVICE_ATTR_2_RO(in5_input, in, 5, input); |
|---|
| 319 | +static SENSOR_DEVICE_ATTR_2_RW(in5_min, in, 5, min); |
|---|
| 320 | +static SENSOR_DEVICE_ATTR_2_RW(in5_max, in, 5, max); |
|---|
| 345 | 321 | |
|---|
| 346 | | -static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, input); |
|---|
| 347 | | -static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
|---|
| 348 | | - 0, min); |
|---|
| 349 | | -static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp, |
|---|
| 350 | | - 0, max); |
|---|
| 351 | | -static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, input); |
|---|
| 352 | | -static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
|---|
| 353 | | - 1, min); |
|---|
| 354 | | -static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp, |
|---|
| 355 | | - 1, max); |
|---|
| 356 | | -static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, input); |
|---|
| 357 | | -static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
|---|
| 358 | | - 2, min); |
|---|
| 359 | | -static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp, |
|---|
| 360 | | - 2, max); |
|---|
| 361 | | -static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 3, input); |
|---|
| 362 | | -static SENSOR_DEVICE_ATTR_2(temp4_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
|---|
| 363 | | - 3, min); |
|---|
| 364 | | -static SENSOR_DEVICE_ATTR_2(temp4_max, S_IRUGO | S_IWUSR, show_temp, set_temp, |
|---|
| 365 | | - 3, max); |
|---|
| 366 | | -static SENSOR_DEVICE_ATTR_2(temp5_input, S_IRUGO, show_temp, NULL, 4, input); |
|---|
| 367 | | -static SENSOR_DEVICE_ATTR_2(temp5_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
|---|
| 368 | | - 4, min); |
|---|
| 369 | | -static SENSOR_DEVICE_ATTR_2(temp5_max, S_IRUGO | S_IWUSR, show_temp, set_temp, |
|---|
| 370 | | - 4, max); |
|---|
| 371 | | -static SENSOR_DEVICE_ATTR_2(temp6_input, S_IRUGO, show_temp, NULL, 5, input); |
|---|
| 372 | | -static SENSOR_DEVICE_ATTR_2(temp6_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
|---|
| 373 | | - 5, min); |
|---|
| 374 | | -static SENSOR_DEVICE_ATTR_2(temp6_max, S_IRUGO | S_IWUSR, show_temp, set_temp, |
|---|
| 375 | | - 5, max); |
|---|
| 322 | +static SENSOR_DEVICE_ATTR_2_RO(temp1_input, temp, 0, input); |
|---|
| 323 | +static SENSOR_DEVICE_ATTR_2_RW(temp1_min, temp, 0, min); |
|---|
| 324 | +static SENSOR_DEVICE_ATTR_2_RW(temp1_max, temp, 0, max); |
|---|
| 325 | +static SENSOR_DEVICE_ATTR_2_RO(temp2_input, temp, 1, input); |
|---|
| 326 | +static SENSOR_DEVICE_ATTR_2_RW(temp2_min, temp, 1, min); |
|---|
| 327 | +static SENSOR_DEVICE_ATTR_2_RW(temp2_max, temp, 1, max); |
|---|
| 328 | +static SENSOR_DEVICE_ATTR_2_RO(temp3_input, temp, 2, input); |
|---|
| 329 | +static SENSOR_DEVICE_ATTR_2_RW(temp3_min, temp, 2, min); |
|---|
| 330 | +static SENSOR_DEVICE_ATTR_2_RW(temp3_max, temp, 2, max); |
|---|
| 331 | +static SENSOR_DEVICE_ATTR_2_RO(temp4_input, temp, 3, input); |
|---|
| 332 | +static SENSOR_DEVICE_ATTR_2_RW(temp4_min, temp, 3, min); |
|---|
| 333 | +static SENSOR_DEVICE_ATTR_2_RW(temp4_max, temp, 3, max); |
|---|
| 334 | +static SENSOR_DEVICE_ATTR_2_RO(temp5_input, temp, 4, input); |
|---|
| 335 | +static SENSOR_DEVICE_ATTR_2_RW(temp5_min, temp, 4, min); |
|---|
| 336 | +static SENSOR_DEVICE_ATTR_2_RW(temp5_max, temp, 4, max); |
|---|
| 337 | +static SENSOR_DEVICE_ATTR_2_RO(temp6_input, temp, 5, input); |
|---|
| 338 | +static SENSOR_DEVICE_ATTR_2_RW(temp6_min, temp, 5, min); |
|---|
| 339 | +static SENSOR_DEVICE_ATTR_2_RW(temp6_max, temp, 5, max); |
|---|
| 376 | 340 | |
|---|
| 377 | | -static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, input); |
|---|
| 378 | | -static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
|---|
| 379 | | - 0, min); |
|---|
| 380 | | -static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, input); |
|---|
| 381 | | -static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
|---|
| 382 | | - 1, min); |
|---|
| 383 | | -static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, input); |
|---|
| 384 | | -static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
|---|
| 385 | | - 2, min); |
|---|
| 386 | | -static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, input); |
|---|
| 387 | | -static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
|---|
| 388 | | - 3, min); |
|---|
| 389 | | -static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, input); |
|---|
| 390 | | -static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
|---|
| 391 | | - 4, min); |
|---|
| 341 | +static SENSOR_DEVICE_ATTR_2_RO(fan1_input, fan, 0, input); |
|---|
| 342 | +static SENSOR_DEVICE_ATTR_2_RW(fan1_min, fan, 0, min); |
|---|
| 343 | +static SENSOR_DEVICE_ATTR_2_RO(fan2_input, fan, 1, input); |
|---|
| 344 | +static SENSOR_DEVICE_ATTR_2_RW(fan2_min, fan, 1, min); |
|---|
| 345 | +static SENSOR_DEVICE_ATTR_2_RO(fan3_input, fan, 2, input); |
|---|
| 346 | +static SENSOR_DEVICE_ATTR_2_RW(fan3_min, fan, 2, min); |
|---|
| 347 | +static SENSOR_DEVICE_ATTR_2_RO(fan4_input, fan, 3, input); |
|---|
| 348 | +static SENSOR_DEVICE_ATTR_2_RW(fan4_min, fan, 3, min); |
|---|
| 349 | +static SENSOR_DEVICE_ATTR_2_RO(fan5_input, fan, 4, input); |
|---|
| 350 | +static SENSOR_DEVICE_ATTR_2_RW(fan5_min, fan, 4, min); |
|---|
| 392 | 351 | |
|---|
| 393 | 352 | static struct attribute *emc6w201_attrs[] = { |
|---|
| 394 | 353 | &sensor_dev_attr_in0_input.dev_attr.attr, |
|---|
| .. | .. |
|---|
| 485 | 444 | return 0; |
|---|
| 486 | 445 | } |
|---|
| 487 | 446 | |
|---|
| 488 | | -static int emc6w201_probe(struct i2c_client *client, |
|---|
| 489 | | - const struct i2c_device_id *id) |
|---|
| 447 | +static int emc6w201_probe(struct i2c_client *client) |
|---|
| 490 | 448 | { |
|---|
| 491 | 449 | struct device *dev = &client->dev; |
|---|
| 492 | 450 | struct emc6w201_data *data; |
|---|
| .. | .. |
|---|
| 516 | 474 | .driver = { |
|---|
| 517 | 475 | .name = "emc6w201", |
|---|
| 518 | 476 | }, |
|---|
| 519 | | - .probe = emc6w201_probe, |
|---|
| 477 | + .probe_new = emc6w201_probe, |
|---|
| 520 | 478 | .id_table = emc6w201_id, |
|---|
| 521 | 479 | .detect = emc6w201_detect, |
|---|
| 522 | 480 | .address_list = normal_i2c, |
|---|