Commit 57256088 authored by Guenter Roeck's avatar Guenter Roeck Committed by Guenter Roeck

hwmon: (pcf8591) Fix checkpatch issues

Fixed:
ERROR: do not use assignment in if condition
ERROR: spaces required around that ':' (ctx:VxV)
ERROR: spaces required around that '?' (ctx:VxV)
WARNING: line over 80 characters
WARNING: simple_strtoul is obsolete, use kstrtoul instead

Modify multi-line comments to follow Documentation/CodingStyle.

Cc: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 2804a4cf
/* /*
Copyright (C) 2001-2004 Aurelien Jarno <aurelien@aurel32.net> * Copyright (C) 2001-2004 Aurelien Jarno <aurelien@aurel32.net>
Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with * Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with
the help of Jean Delvare <khali@linux-fr.org> * the help of Jean Delvare <khali@linux-fr.org>
*
This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. * (at your option) any later version.
*
This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. * GNU General Public License for more details.
*
You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
...@@ -39,28 +39,34 @@ MODULE_PARM_DESC(input_mode, ...@@ -39,28 +39,34 @@ MODULE_PARM_DESC(input_mode,
" 2 = single ended and differential mixed\n" " 2 = single ended and differential mixed\n"
" 3 = two differential inputs\n"); " 3 = two differential inputs\n");
/* The PCF8591 control byte /*
7 6 5 4 3 2 1 0 * The PCF8591 control byte
| 0 |AOEF| AIP | 0 |AINC| AICH | */ * 7 6 5 4 3 2 1 0
* | 0 |AOEF| AIP | 0 |AINC| AICH |
*/
/* Analog Output Enable Flag (analog output active if 1) */ /* Analog Output Enable Flag (analog output active if 1) */
#define PCF8591_CONTROL_AOEF 0x40 #define PCF8591_CONTROL_AOEF 0x40
/* Analog Input Programming /*
0x00 = four single ended inputs * Analog Input Programming
0x10 = three differential inputs * 0x00 = four single ended inputs
0x20 = single ended and differential mixed * 0x10 = three differential inputs
0x30 = two differential inputs */ * 0x20 = single ended and differential mixed
* 0x30 = two differential inputs
*/
#define PCF8591_CONTROL_AIP_MASK 0x30 #define PCF8591_CONTROL_AIP_MASK 0x30
/* Autoincrement Flag (switch on if 1) */ /* Autoincrement Flag (switch on if 1) */
#define PCF8591_CONTROL_AINC 0x04 #define PCF8591_CONTROL_AINC 0x04
/* Channel selection /*
0x00 = channel 0 * Channel selection
0x01 = channel 1 * 0x00 = channel 0
0x02 = channel 2 * 0x01 = channel 1
0x03 = channel 3 */ * 0x02 = channel 2
* 0x03 = channel 3
*/
#define PCF8591_CONTROL_AICH_MASK 0x03 #define PCF8591_CONTROL_AICH_MASK 0x03
/* Initial values */ /* Initial values */
...@@ -68,7 +74,7 @@ MODULE_PARM_DESC(input_mode, ...@@ -68,7 +74,7 @@ MODULE_PARM_DESC(input_mode,
#define PCF8591_INIT_AOUT 0 /* DAC out = 0 */ #define PCF8591_INIT_AOUT 0 /* DAC out = 0 */
/* Conversions */ /* Conversions */
#define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg)) #define REG_TO_SIGNED(reg) (((reg) & 0x80) ? ((reg) - 256) : (reg))
struct pcf8591_data { struct pcf8591_data {
struct device *hwmon_dev; struct device *hwmon_dev;
...@@ -83,7 +89,9 @@ static int pcf8591_read_channel(struct device *dev, int channel); ...@@ -83,7 +89,9 @@ static int pcf8591_read_channel(struct device *dev, int channel);
/* following are the sysfs callback functions */ /* following are the sysfs callback functions */
#define show_in_channel(channel) \ #define show_in_channel(channel) \
static ssize_t show_in##channel##_input(struct device *dev, struct device_attribute *attr, char *buf) \ static ssize_t show_in##channel##_input(struct device *dev, \
struct device_attribute *attr, \
char *buf) \
{ \ { \
return sprintf(buf, "%d\n", pcf8591_read_channel(dev, channel));\ return sprintf(buf, "%d\n", pcf8591_read_channel(dev, channel));\
} \ } \
...@@ -95,39 +103,57 @@ show_in_channel(1); ...@@ -95,39 +103,57 @@ show_in_channel(1);
show_in_channel(2); show_in_channel(2);
show_in_channel(3); show_in_channel(3);
static ssize_t show_out0_ouput(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_out0_ouput(struct device *dev,
struct device_attribute *attr, char *buf)
{ {
struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev)); struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev));
return sprintf(buf, "%d\n", data->aout * 10); return sprintf(buf, "%d\n", data->aout * 10);
} }
static ssize_t set_out0_output(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) static ssize_t set_out0_output(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{ {
unsigned int value; unsigned long val;
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct pcf8591_data *data = i2c_get_clientdata(client); struct pcf8591_data *data = i2c_get_clientdata(client);
if ((value = (simple_strtoul(buf, NULL, 10) + 5) / 10) <= 255) { int err;
data->aout = value;
err = kstrtoul(buf, 10, &val);
if (err)
return err;
val /= 10;
if (val > 255)
return -EINVAL;
data->aout = val;
i2c_smbus_write_byte_data(client, data->control, data->aout); i2c_smbus_write_byte_data(client, data->control, data->aout);
return count; return count;
}
return -EINVAL;
} }
static DEVICE_ATTR(out0_output, S_IWUSR | S_IRUGO, static DEVICE_ATTR(out0_output, S_IWUSR | S_IRUGO,
show_out0_ouput, set_out0_output); show_out0_ouput, set_out0_output);
static ssize_t show_out0_enable(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_out0_enable(struct device *dev,
struct device_attribute *attr, char *buf)
{ {
struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev)); struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev));
return sprintf(buf, "%u\n", !(!(data->control & PCF8591_CONTROL_AOEF))); return sprintf(buf, "%u\n", !(!(data->control & PCF8591_CONTROL_AOEF)));
} }
static ssize_t set_out0_enable(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) static ssize_t set_out0_enable(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct pcf8591_data *data = i2c_get_clientdata(client); struct pcf8591_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val;
int err;
err = kstrtoul(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
if (val) if (val)
...@@ -174,7 +200,8 @@ static int pcf8591_probe(struct i2c_client *client, ...@@ -174,7 +200,8 @@ static int pcf8591_probe(struct i2c_client *client,
struct pcf8591_data *data; struct pcf8591_data *data;
int err; int err;
if (!(data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) { data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL);
if (!data) {
err = -ENOMEM; err = -ENOMEM;
goto exit; goto exit;
} }
...@@ -192,15 +219,15 @@ static int pcf8591_probe(struct i2c_client *client, ...@@ -192,15 +219,15 @@ static int pcf8591_probe(struct i2c_client *client,
/* Register input2 if not in "two differential inputs" mode */ /* Register input2 if not in "two differential inputs" mode */
if (input_mode != 3) { if (input_mode != 3) {
if ((err = device_create_file(&client->dev, err = device_create_file(&client->dev, &dev_attr_in2_input);
&dev_attr_in2_input))) if (err)
goto exit_sysfs_remove; goto exit_sysfs_remove;
} }
/* Register input3 only in "four single ended inputs" mode */ /* Register input3 only in "four single ended inputs" mode */
if (input_mode == 0) { if (input_mode == 0) {
if ((err = device_create_file(&client->dev, err = device_create_file(&client->dev, &dev_attr_in3_input);
&dev_attr_in3_input))) if (err)
goto exit_sysfs_remove; goto exit_sysfs_remove;
} }
...@@ -241,8 +268,10 @@ static void pcf8591_init_client(struct i2c_client *client) ...@@ -241,8 +268,10 @@ static void pcf8591_init_client(struct i2c_client *client)
i2c_smbus_write_byte_data(client, data->control, data->aout); i2c_smbus_write_byte_data(client, data->control, data->aout);
/* The first byte transmitted contains the conversion code of the /*
previous read cycle. FLUSH IT! */ * The first byte transmitted contains the conversion code of the
* previous read cycle. FLUSH IT!
*/
i2c_smbus_read_byte(client); i2c_smbus_read_byte(client);
} }
...@@ -259,8 +288,10 @@ static int pcf8591_read_channel(struct device *dev, int channel) ...@@ -259,8 +288,10 @@ static int pcf8591_read_channel(struct device *dev, int channel)
| channel; | channel;
i2c_smbus_write_byte(client, data->control); i2c_smbus_write_byte(client, data->control);
/* The first byte transmitted contains the conversion code of /*
the previous read cycle. FLUSH IT! */ * The first byte transmitted contains the conversion code of
* the previous read cycle. FLUSH IT!
*/
i2c_smbus_read_byte(client); i2c_smbus_read_byte(client);
} }
value = i2c_smbus_read_byte(client); value = i2c_smbus_read_byte(client);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment