Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (f75375s) Allow setting up fans with platform_data

Allow initializing fans on systems where BIOS does not do that by
default.

- define f75375s_platform_data in new file f75375s.h
- if platform_data was provided, set fans accordingly in f75375_init()
- split set_pwm_enable() to a sysfs callback and directly usable
set_pwm_enable_direct()

Signed-off-by: Riku Voipio <riku.voipio@movial.fi>
Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>

authored by

Riku Voipio and committed by
Mark M. Hoffman
ff312d07 620c142d

+56 -7
+35 -7
drivers/hwmon/f75375s.c
··· 34 34 #include <linux/i2c.h> 35 35 #include <linux/err.h> 36 36 #include <linux/mutex.h> 37 + #include <linux/f75375s.h> 37 38 38 39 /* Addresses to scan */ 39 40 static unsigned short normal_i2c[] = { 0x2d, 0x2e, I2C_CLIENT_END }; ··· 287 286 return sprintf(buf, "%d\n", data->pwm_enable[nr]); 288 287 } 289 288 290 - static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr, 291 - const char *buf, size_t count) 289 + static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val) 292 290 { 293 - int nr = to_sensor_dev_attr(attr)->index; 294 - struct i2c_client *client = to_i2c_client(dev); 295 291 struct f75375_data *data = i2c_get_clientdata(client); 296 - int val = simple_strtoul(buf, NULL, 10); 297 292 u8 fanmode; 298 293 299 294 if (val < 0 || val > 4) 300 295 return -EINVAL; 301 296 302 - mutex_lock(&data->update_lock); 303 297 fanmode = f75375_read8(client, F75375_REG_FAN_TIMER); 304 298 fanmode = ~(3 << FAN_CTRL_MODE(nr)); 305 299 ··· 316 320 } 317 321 f75375_write8(client, F75375_REG_FAN_TIMER, fanmode); 318 322 data->pwm_enable[nr] = val; 323 + return 0; 324 + } 325 + 326 + static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr, 327 + const char *buf, size_t count) 328 + { 329 + int nr = to_sensor_dev_attr(attr)->index; 330 + struct i2c_client *client = to_i2c_client(dev); 331 + struct f75375_data *data = i2c_get_clientdata(client); 332 + int val = simple_strtoul(buf, NULL, 10); 333 + int err = 0; 334 + 335 + mutex_lock(&data->update_lock); 336 + err = set_pwm_enable_direct(client, nr, val); 319 337 mutex_unlock(&data->update_lock); 320 - return count; 338 + return err ? err : count; 321 339 } 322 340 323 341 static ssize_t set_pwm_mode(struct device *dev, struct device_attribute *attr, ··· 614 604 return 0; 615 605 } 616 606 607 + static void f75375_init(struct i2c_client *client, struct f75375_data *data, 608 + struct f75375s_platform_data *f75375s_pdata) 609 + { 610 + int nr; 611 + set_pwm_enable_direct(client, 0, f75375s_pdata->pwm_enable[0]); 612 + set_pwm_enable_direct(client, 1, f75375s_pdata->pwm_enable[1]); 613 + for (nr = 0; nr < 2; nr++) { 614 + data->pwm[nr] = SENSORS_LIMIT(f75375s_pdata->pwm[nr], 0, 255); 615 + f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr), 616 + data->pwm[nr]); 617 + } 618 + 619 + } 620 + 617 621 static int f75375_probe(struct i2c_client *client) 618 622 { 619 623 struct f75375_data *data = i2c_get_clientdata(client); 624 + struct f75375s_platform_data *f75375s_pdata = client->dev.platform_data; 620 625 int err; 621 626 622 627 if (!i2c_check_functionality(client->adapter, ··· 661 636 err = PTR_ERR(data->hwmon_dev); 662 637 goto exit_remove; 663 638 } 639 + 640 + if (f75375s_pdata != NULL) 641 + f75375_init(client, data, f75375s_pdata); 664 642 665 643 return 0; 666 644
+21
include/linux/f75375s.h
··· 1 + /* 2 + * f75375s.h - platform data structure for f75375s sensor 3 + * 4 + * This file is subject to the terms and conditions of the GNU General Public 5 + * License. See the file "COPYING" in the main directory of this archive 6 + * for more details. 7 + * 8 + * Copyright (C) 2007, Riku Voipio <riku.voipio@iki.fi> 9 + */ 10 + 11 + #ifndef __LINUX_F75375S_H 12 + #define __LINUX_F75375S_H 13 + 14 + /* We want to set fans spinning on systems where there is no 15 + * BIOS to do that for us */ 16 + struct f75375s_platform_data { 17 + u8 pwm[2]; 18 + u8 pwm_enable[2]; 19 + }; 20 + 21 + #endif /* __LINUX_F75375S_H */