.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * tc654.c - Linux kernel modules for fan speed controller |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2016 Allied Telesis Labs NZ |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or modify |
---|
7 | | - * it under the terms of the GNU General Public License as published by |
---|
8 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
9 | | - * (at your option) any later version. |
---|
10 | | - * |
---|
11 | | - * This program is distributed in the hope that it will be useful, |
---|
12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | | - * GNU General Public License for more details. |
---|
15 | 6 | */ |
---|
16 | 7 | |
---|
17 | 8 | #include <linux/bitops.h> |
---|
.. | .. |
---|
200 | 191 | * sysfs attributes |
---|
201 | 192 | */ |
---|
202 | 193 | |
---|
203 | | -static ssize_t show_fan(struct device *dev, struct device_attribute *da, |
---|
| 194 | +static ssize_t fan_show(struct device *dev, struct device_attribute *da, |
---|
204 | 195 | char *buf) |
---|
205 | 196 | { |
---|
206 | 197 | int nr = to_sensor_dev_attr(da)->index; |
---|
.. | .. |
---|
218 | 209 | return sprintf(buf, "%d\n", val); |
---|
219 | 210 | } |
---|
220 | 211 | |
---|
221 | | -static ssize_t show_fan_min(struct device *dev, struct device_attribute *da, |
---|
| 212 | +static ssize_t fan_min_show(struct device *dev, struct device_attribute *da, |
---|
222 | 213 | char *buf) |
---|
223 | 214 | { |
---|
224 | 215 | int nr = to_sensor_dev_attr(da)->index; |
---|
.. | .. |
---|
231 | 222 | TC654_FAN_FAULT_FROM_REG(data->fan_fault[nr])); |
---|
232 | 223 | } |
---|
233 | 224 | |
---|
234 | | -static ssize_t set_fan_min(struct device *dev, struct device_attribute *da, |
---|
235 | | - const char *buf, size_t count) |
---|
| 225 | +static ssize_t fan_min_store(struct device *dev, struct device_attribute *da, |
---|
| 226 | + const char *buf, size_t count) |
---|
236 | 227 | { |
---|
237 | 228 | int nr = to_sensor_dev_attr(da)->index; |
---|
238 | 229 | struct tc654_data *data = dev_get_drvdata(dev); |
---|
.. | .. |
---|
255 | 246 | return ret < 0 ? ret : count; |
---|
256 | 247 | } |
---|
257 | 248 | |
---|
258 | | -static ssize_t show_fan_alarm(struct device *dev, struct device_attribute *da, |
---|
| 249 | +static ssize_t fan_alarm_show(struct device *dev, struct device_attribute *da, |
---|
259 | 250 | char *buf) |
---|
260 | 251 | { |
---|
261 | 252 | int nr = to_sensor_dev_attr(da)->index; |
---|
.. | .. |
---|
275 | 266 | |
---|
276 | 267 | static const u8 TC654_FAN_PULSE_SHIFT[] = { 1, 3 }; |
---|
277 | 268 | |
---|
278 | | -static ssize_t show_fan_pulses(struct device *dev, struct device_attribute *da, |
---|
279 | | - char *buf) |
---|
| 269 | +static ssize_t fan_pulses_show(struct device *dev, |
---|
| 270 | + struct device_attribute *da, char *buf) |
---|
280 | 271 | { |
---|
281 | 272 | int nr = to_sensor_dev_attr(da)->index; |
---|
282 | 273 | struct tc654_data *data = tc654_update_client(dev); |
---|
.. | .. |
---|
289 | 280 | return sprintf(buf, "%d\n", val); |
---|
290 | 281 | } |
---|
291 | 282 | |
---|
292 | | -static ssize_t set_fan_pulses(struct device *dev, struct device_attribute *da, |
---|
293 | | - const char *buf, size_t count) |
---|
| 283 | +static ssize_t fan_pulses_store(struct device *dev, |
---|
| 284 | + struct device_attribute *da, const char *buf, |
---|
| 285 | + size_t count) |
---|
294 | 286 | { |
---|
295 | 287 | int nr = to_sensor_dev_attr(da)->index; |
---|
296 | 288 | struct tc654_data *data = dev_get_drvdata(dev); |
---|
.. | .. |
---|
329 | 321 | return ret < 0 ? ret : count; |
---|
330 | 322 | } |
---|
331 | 323 | |
---|
332 | | -static ssize_t show_pwm_mode(struct device *dev, |
---|
333 | | - struct device_attribute *da, char *buf) |
---|
| 324 | +static ssize_t pwm_mode_show(struct device *dev, struct device_attribute *da, |
---|
| 325 | + char *buf) |
---|
334 | 326 | { |
---|
335 | 327 | struct tc654_data *data = tc654_update_client(dev); |
---|
336 | 328 | |
---|
.. | .. |
---|
340 | 332 | return sprintf(buf, "%d\n", !!(data->config & TC654_REG_CONFIG_DUTYC)); |
---|
341 | 333 | } |
---|
342 | 334 | |
---|
343 | | -static ssize_t set_pwm_mode(struct device *dev, |
---|
344 | | - struct device_attribute *da, |
---|
345 | | - const char *buf, size_t count) |
---|
| 335 | +static ssize_t pwm_mode_store(struct device *dev, struct device_attribute *da, |
---|
| 336 | + const char *buf, size_t count) |
---|
346 | 337 | { |
---|
347 | 338 | struct tc654_data *data = dev_get_drvdata(dev); |
---|
348 | 339 | struct i2c_client *client = data->client; |
---|
.. | .. |
---|
371 | 362 | static const int tc654_pwm_map[16] = { 77, 88, 102, 112, 124, 136, 148, 160, |
---|
372 | 363 | 172, 184, 196, 207, 219, 231, 243, 255}; |
---|
373 | 364 | |
---|
374 | | -static ssize_t show_pwm(struct device *dev, struct device_attribute *da, |
---|
| 365 | +static ssize_t pwm_show(struct device *dev, struct device_attribute *da, |
---|
375 | 366 | char *buf) |
---|
376 | 367 | { |
---|
377 | 368 | struct tc654_data *data = tc654_update_client(dev); |
---|
.. | .. |
---|
388 | 379 | return sprintf(buf, "%d\n", pwm); |
---|
389 | 380 | } |
---|
390 | 381 | |
---|
391 | | -static ssize_t set_pwm(struct device *dev, struct device_attribute *da, |
---|
392 | | - const char *buf, size_t count) |
---|
| 382 | +static ssize_t pwm_store(struct device *dev, struct device_attribute *da, |
---|
| 383 | + const char *buf, size_t count) |
---|
393 | 384 | { |
---|
394 | 385 | struct tc654_data *data = dev_get_drvdata(dev); |
---|
395 | 386 | struct i2c_client *client = data->client; |
---|
.. | .. |
---|
423 | 414 | return ret < 0 ? ret : count; |
---|
424 | 415 | } |
---|
425 | 416 | |
---|
426 | | -static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); |
---|
427 | | -static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1); |
---|
428 | | -static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, |
---|
429 | | - set_fan_min, 0); |
---|
430 | | -static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min, |
---|
431 | | - set_fan_min, 1); |
---|
432 | | -static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0); |
---|
433 | | -static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 1); |
---|
434 | | -static SENSOR_DEVICE_ATTR(fan1_pulses, S_IWUSR | S_IRUGO, show_fan_pulses, |
---|
435 | | - set_fan_pulses, 0); |
---|
436 | | -static SENSOR_DEVICE_ATTR(fan2_pulses, S_IWUSR | S_IRUGO, show_fan_pulses, |
---|
437 | | - set_fan_pulses, 1); |
---|
438 | | -static SENSOR_DEVICE_ATTR(pwm1_mode, S_IWUSR | S_IRUGO, |
---|
439 | | - show_pwm_mode, set_pwm_mode, 0); |
---|
440 | | -static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, |
---|
441 | | - set_pwm, 0); |
---|
| 417 | +static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0); |
---|
| 418 | +static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1); |
---|
| 419 | +static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0); |
---|
| 420 | +static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1); |
---|
| 421 | +static SENSOR_DEVICE_ATTR_RO(fan1_alarm, fan_alarm, 0); |
---|
| 422 | +static SENSOR_DEVICE_ATTR_RO(fan2_alarm, fan_alarm, 1); |
---|
| 423 | +static SENSOR_DEVICE_ATTR_RW(fan1_pulses, fan_pulses, 0); |
---|
| 424 | +static SENSOR_DEVICE_ATTR_RW(fan2_pulses, fan_pulses, 1); |
---|
| 425 | +static SENSOR_DEVICE_ATTR_RW(pwm1_mode, pwm_mode, 0); |
---|
| 426 | +static SENSOR_DEVICE_ATTR_RW(pwm1, pwm, 0); |
---|
442 | 427 | |
---|
443 | 428 | /* Driver data */ |
---|
444 | 429 | static struct attribute *tc654_attrs[] = { |
---|
.. | .. |
---|
461 | 446 | * device probe and removal |
---|
462 | 447 | */ |
---|
463 | 448 | |
---|
464 | | -static int tc654_probe(struct i2c_client *client, |
---|
465 | | - const struct i2c_device_id *id) |
---|
| 449 | +static int tc654_probe(struct i2c_client *client) |
---|
466 | 450 | { |
---|
467 | 451 | struct device *dev = &client->dev; |
---|
468 | 452 | struct tc654_data *data; |
---|
.. | .. |
---|
503 | 487 | .driver = { |
---|
504 | 488 | .name = "tc654", |
---|
505 | 489 | }, |
---|
506 | | - .probe = tc654_probe, |
---|
| 490 | + .probe_new = tc654_probe, |
---|
507 | 491 | .id_table = tc654_id, |
---|
508 | 492 | }; |
---|
509 | 493 | |
---|