aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/pcf8591.c
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2012-01-15 00:57:29 -0500
committerGuenter Roeck <guenter.roeck@ericsson.com>2012-03-18 21:27:07 -0400
commit57256088e1e0f26bb8abf677c9622de4841a89ac (patch)
treec2a512ea137d72d58ff3c730a39711ac0991bb60 /drivers/hwmon/pcf8591.c
parent2804a4cfcdef5f0d4f412b31ab9d4a4a9aa3057a (diff)
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: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/pcf8591.c')
-rw-r--r--drivers/hwmon/pcf8591.c139
1 files changed, 85 insertions, 54 deletions
diff --git a/drivers/hwmon/pcf8591.c b/drivers/hwmon/pcf8591.c
index 2041155a9fa3..4174c7463d70 100644
--- a/drivers/hwmon/pcf8591.c
+++ b/drivers/hwmon/pcf8591.c
@@ -1,22 +1,22 @@
1/* 1/*
2 Copyright (C) 2001-2004 Aurelien Jarno <aurelien@aurel32.net> 2 * Copyright (C) 2001-2004 Aurelien Jarno <aurelien@aurel32.net>
3 Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with 3 * Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with
4 the help of Jean Delvare <khali@linux-fr.org> 4 * the help of Jean Delvare <khali@linux-fr.org>
5 5 *
6 This program is free software; you can redistribute it and/or modify 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 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 8 * the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 * (at your option) any later version.
10 10 *
11 This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 * GNU General Public License for more details.
15 15 *
16 You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19 */
20 20
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 22
@@ -39,28 +39,34 @@ MODULE_PARM_DESC(input_mode,
39 " 2 = single ended and differential mixed\n" 39 " 2 = single ended and differential mixed\n"
40 " 3 = two differential inputs\n"); 40 " 3 = two differential inputs\n");
41 41
42/* The PCF8591 control byte 42/*
43 7 6 5 4 3 2 1 0 43 * The PCF8591 control byte
44 | 0 |AOEF| AIP | 0 |AINC| AICH | */ 44 * 7 6 5 4 3 2 1 0
45 * | 0 |AOEF| AIP | 0 |AINC| AICH |
46 */
45 47
46/* Analog Output Enable Flag (analog output active if 1) */ 48/* Analog Output Enable Flag (analog output active if 1) */
47#define PCF8591_CONTROL_AOEF 0x40 49#define PCF8591_CONTROL_AOEF 0x40
48 50
49/* Analog Input Programming 51/*
50 0x00 = four single ended inputs 52 * Analog Input Programming
51 0x10 = three differential inputs 53 * 0x00 = four single ended inputs
52 0x20 = single ended and differential mixed 54 * 0x10 = three differential inputs
53 0x30 = two differential inputs */ 55 * 0x20 = single ended and differential mixed
56 * 0x30 = two differential inputs
57 */
54#define PCF8591_CONTROL_AIP_MASK 0x30 58#define PCF8591_CONTROL_AIP_MASK 0x30
55 59
56/* Autoincrement Flag (switch on if 1) */ 60/* Autoincrement Flag (switch on if 1) */
57#define PCF8591_CONTROL_AINC 0x04 61#define PCF8591_CONTROL_AINC 0x04
58 62
59/* Channel selection 63/*
60 0x00 = channel 0 64 * Channel selection
61 0x01 = channel 1 65 * 0x00 = channel 0
62 0x02 = channel 2 66 * 0x01 = channel 1
63 0x03 = channel 3 */ 67 * 0x02 = channel 2
68 * 0x03 = channel 3
69 */
64#define PCF8591_CONTROL_AICH_MASK 0x03 70#define PCF8591_CONTROL_AICH_MASK 0x03
65 71
66/* Initial values */ 72/* Initial values */
@@ -68,7 +74,7 @@ MODULE_PARM_DESC(input_mode,
68#define PCF8591_INIT_AOUT 0 /* DAC out = 0 */ 74#define PCF8591_INIT_AOUT 0 /* DAC out = 0 */
69 75
70/* Conversions */ 76/* Conversions */
71#define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg)) 77#define REG_TO_SIGNED(reg) (((reg) & 0x80) ? ((reg) - 256) : (reg))
72 78
73struct pcf8591_data { 79struct pcf8591_data {
74 struct device *hwmon_dev; 80 struct device *hwmon_dev;
@@ -83,7 +89,9 @@ static int pcf8591_read_channel(struct device *dev, int channel);
83 89
84/* following are the sysfs callback functions */ 90/* following are the sysfs callback functions */
85#define show_in_channel(channel) \ 91#define show_in_channel(channel) \
86static ssize_t show_in##channel##_input(struct device *dev, struct device_attribute *attr, char *buf) \ 92static ssize_t show_in##channel##_input(struct device *dev, \
93 struct device_attribute *attr, \
94 char *buf) \
87{ \ 95{ \
88 return sprintf(buf, "%d\n", pcf8591_read_channel(dev, channel));\ 96 return sprintf(buf, "%d\n", pcf8591_read_channel(dev, channel));\
89} \ 97} \
@@ -95,39 +103,57 @@ show_in_channel(1);
95show_in_channel(2); 103show_in_channel(2);
96show_in_channel(3); 104show_in_channel(3);
97 105
98static ssize_t show_out0_ouput(struct device *dev, struct device_attribute *attr, char *buf) 106static ssize_t show_out0_ouput(struct device *dev,
107 struct device_attribute *attr, char *buf)
99{ 108{
100 struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev)); 109 struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev));
101 return sprintf(buf, "%d\n", data->aout * 10); 110 return sprintf(buf, "%d\n", data->aout * 10);
102} 111}
103 112
104static ssize_t set_out0_output(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 113static ssize_t set_out0_output(struct device *dev,
114 struct device_attribute *attr,
115 const char *buf, size_t count)
105{ 116{
106 unsigned int value; 117 unsigned long val;
107 struct i2c_client *client = to_i2c_client(dev); 118 struct i2c_client *client = to_i2c_client(dev);
108 struct pcf8591_data *data = i2c_get_clientdata(client); 119 struct pcf8591_data *data = i2c_get_clientdata(client);
109 if ((value = (simple_strtoul(buf, NULL, 10) + 5) / 10) <= 255) { 120 int err;
110 data->aout = value; 121
111 i2c_smbus_write_byte_data(client, data->control, data->aout); 122 err = kstrtoul(buf, 10, &val);
112 return count; 123 if (err)
113 } 124 return err;
114 return -EINVAL; 125
126 val /= 10;
127 if (val > 255)
128 return -EINVAL;
129
130 data->aout = val;
131 i2c_smbus_write_byte_data(client, data->control, data->aout);
132 return count;
115} 133}
116 134
117static DEVICE_ATTR(out0_output, S_IWUSR | S_IRUGO, 135static DEVICE_ATTR(out0_output, S_IWUSR | S_IRUGO,
118 show_out0_ouput, set_out0_output); 136 show_out0_ouput, set_out0_output);
119 137
120static ssize_t show_out0_enable(struct device *dev, struct device_attribute *attr, char *buf) 138static ssize_t show_out0_enable(struct device *dev,
139 struct device_attribute *attr, char *buf)
121{ 140{
122 struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev)); 141 struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev));
123 return sprintf(buf, "%u\n", !(!(data->control & PCF8591_CONTROL_AOEF))); 142 return sprintf(buf, "%u\n", !(!(data->control & PCF8591_CONTROL_AOEF)));
124} 143}
125 144
126static ssize_t set_out0_enable(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 145static ssize_t set_out0_enable(struct device *dev,
146 struct device_attribute *attr,
147 const char *buf, size_t count)
127{ 148{
128 struct i2c_client *client = to_i2c_client(dev); 149 struct i2c_client *client = to_i2c_client(dev);
129 struct pcf8591_data *data = i2c_get_clientdata(client); 150 struct pcf8591_data *data = i2c_get_clientdata(client);
130 unsigned long val = simple_strtoul(buf, NULL, 10); 151 unsigned long val;
152 int err;
153
154 err = kstrtoul(buf, 10, &val);
155 if (err)
156 return err;
131 157
132 mutex_lock(&data->update_lock); 158 mutex_lock(&data->update_lock);
133 if (val) 159 if (val)
@@ -174,7 +200,8 @@ static int pcf8591_probe(struct i2c_client *client,
174 struct pcf8591_data *data; 200 struct pcf8591_data *data;
175 int err; 201 int err;
176 202
177 if (!(data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) { 203 data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL);
204 if (!data) {
178 err = -ENOMEM; 205 err = -ENOMEM;
179 goto exit; 206 goto exit;
180 } 207 }
@@ -192,15 +219,15 @@ static int pcf8591_probe(struct i2c_client *client,
192 219
193 /* Register input2 if not in "two differential inputs" mode */ 220 /* Register input2 if not in "two differential inputs" mode */
194 if (input_mode != 3) { 221 if (input_mode != 3) {
195 if ((err = device_create_file(&client->dev, 222 err = device_create_file(&client->dev, &dev_attr_in2_input);
196 &dev_attr_in2_input))) 223 if (err)
197 goto exit_sysfs_remove; 224 goto exit_sysfs_remove;
198 } 225 }
199 226
200 /* Register input3 only in "four single ended inputs" mode */ 227 /* Register input3 only in "four single ended inputs" mode */
201 if (input_mode == 0) { 228 if (input_mode == 0) {
202 if ((err = device_create_file(&client->dev, 229 err = device_create_file(&client->dev, &dev_attr_in3_input);
203 &dev_attr_in3_input))) 230 if (err)
204 goto exit_sysfs_remove; 231 goto exit_sysfs_remove;
205 } 232 }
206 233
@@ -241,8 +268,10 @@ static void pcf8591_init_client(struct i2c_client *client)
241 268
242 i2c_smbus_write_byte_data(client, data->control, data->aout); 269 i2c_smbus_write_byte_data(client, data->control, data->aout);
243 270
244 /* The first byte transmitted contains the conversion code of the 271 /*
245 previous read cycle. FLUSH IT! */ 272 * The first byte transmitted contains the conversion code of the
273 * previous read cycle. FLUSH IT!
274 */
246 i2c_smbus_read_byte(client); 275 i2c_smbus_read_byte(client);
247} 276}
248 277
@@ -259,8 +288,10 @@ static int pcf8591_read_channel(struct device *dev, int channel)
259 | channel; 288 | channel;
260 i2c_smbus_write_byte(client, data->control); 289 i2c_smbus_write_byte(client, data->control);
261 290
262 /* The first byte transmitted contains the conversion code of 291 /*
263 the previous read cycle. FLUSH IT! */ 292 * The first byte transmitted contains the conversion code of
293 * the previous read cycle. FLUSH IT!
294 */
264 i2c_smbus_read_byte(client); 295 i2c_smbus_read_byte(client);
265 } 296 }
266 value = i2c_smbus_read_byte(client); 297 value = i2c_smbus_read_byte(client);