aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2012-01-14 16:21:59 -0500
committerGuenter Roeck <guenter.roeck@ericsson.com>2012-03-18 21:27:03 -0400
commitf24d548bf2c4da3fd2cc4d0ffec108216b705850 (patch)
tree1924ead82228fdef480684397295e94fb9901120
parent724cc3316e6e1060f727958b4c327001c0bbd62c (diff)
hwmon: (atxp1) Fix checkpatch issues
Fixed: ERROR: code indent should use tabs where possible ERROR: do not use assignment in if condition ERROR: else should follow close brace '}' ERROR: "foo * bar" should be "foo *bar" WARNING: braces {} are not necessary for single statement blocks WARNING: line over 80 characters WARNING: please, no space before tabs WARNING: please, no spaces at the start of a line WARNING: simple_strtoul is obsolete, use kstrtoul instead Modify multi-line comments to follow Documentation/CodingStyle. Cc: Sebastian Witt <se.witt@gmx.net> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/atxp1.c158
1 files changed, 93 insertions, 65 deletions
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c
index e69036a51253..58af6aa93530 100644
--- a/drivers/hwmon/atxp1.c
+++ b/drivers/hwmon/atxp1.c
@@ -1,22 +1,22 @@
1/* 1/*
2 atxp1.c - kernel module for setting CPU VID and general purpose 2 * atxp1.c - kernel module for setting CPU VID and general purpose
3 I/Os using the Attansic ATXP1 chip. 3 * I/Os using the Attansic ATXP1 chip.
4 4 *
5 This program is free software; you can redistribute it and/or modify 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 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 7 * the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 * (at your option) any later version.
9 9 *
10 This program is distributed in the hope that it will be useful, 10 * This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 * GNU General Public License for more details.
14 14 *
15 You should have received a copy of the GNU General Public License 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 16 * along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 18 *
19*/ 19 */
20 20
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/init.h> 22#include <linux/init.h>
@@ -48,7 +48,7 @@ static const unsigned short normal_i2c[] = { 0x37, 0x4e, I2C_CLIENT_END };
48static int atxp1_probe(struct i2c_client *client, 48static int atxp1_probe(struct i2c_client *client,
49 const struct i2c_device_id *id); 49 const struct i2c_device_id *id);
50static int atxp1_remove(struct i2c_client *client); 50static int atxp1_remove(struct i2c_client *client);
51static struct atxp1_data * atxp1_update_device(struct device *dev); 51static struct atxp1_data *atxp1_update_device(struct device *dev);
52static int atxp1_detect(struct i2c_client *client, struct i2c_board_info *info); 52static int atxp1_detect(struct i2c_client *client, struct i2c_board_info *info);
53 53
54static const struct i2c_device_id atxp1_id[] = { 54static const struct i2c_device_id atxp1_id[] = {
@@ -83,7 +83,7 @@ struct atxp1_data {
83 u8 vrm; /* Detected CPU VRM */ 83 u8 vrm; /* Detected CPU VRM */
84}; 84};
85 85
86static struct atxp1_data * atxp1_update_device(struct device *dev) 86static struct atxp1_data *atxp1_update_device(struct device *dev)
87{ 87{
88 struct i2c_client *client; 88 struct i2c_client *client;
89 struct atxp1_data *data; 89 struct atxp1_data *data;
@@ -97,7 +97,8 @@ static struct atxp1_data * atxp1_update_device(struct device *dev)
97 97
98 /* Update local register data */ 98 /* Update local register data */
99 data->reg.vid = i2c_smbus_read_byte_data(client, ATXP1_VID); 99 data->reg.vid = i2c_smbus_read_byte_data(client, ATXP1_VID);
100 data->reg.cpu_vid = i2c_smbus_read_byte_data(client, ATXP1_CVID); 100 data->reg.cpu_vid = i2c_smbus_read_byte_data(client,
101 ATXP1_CVID);
101 data->reg.gpio1 = i2c_smbus_read_byte_data(client, ATXP1_GPIO1); 102 data->reg.gpio1 = i2c_smbus_read_byte_data(client, ATXP1_GPIO1);
102 data->reg.gpio2 = i2c_smbus_read_byte_data(client, ATXP1_GPIO2); 103 data->reg.gpio2 = i2c_smbus_read_byte_data(client, ATXP1_GPIO2);
103 104
@@ -110,29 +111,37 @@ static struct atxp1_data * atxp1_update_device(struct device *dev)
110} 111}
111 112
112/* sys file functions for cpu0_vid */ 113/* sys file functions for cpu0_vid */
113static ssize_t atxp1_showvcore(struct device *dev, struct device_attribute *attr, char *buf) 114static ssize_t atxp1_showvcore(struct device *dev,
115 struct device_attribute *attr, char *buf)
114{ 116{
115 int size; 117 int size;
116 struct atxp1_data *data; 118 struct atxp1_data *data;
117 119
118 data = atxp1_update_device(dev); 120 data = atxp1_update_device(dev);
119 121
120 size = sprintf(buf, "%d\n", vid_from_reg(data->reg.vid & ATXP1_VIDMASK, data->vrm)); 122 size = sprintf(buf, "%d\n", vid_from_reg(data->reg.vid & ATXP1_VIDMASK,
123 data->vrm));
121 124
122 return size; 125 return size;
123} 126}
124 127
125static ssize_t atxp1_storevcore(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 128static ssize_t atxp1_storevcore(struct device *dev,
129 struct device_attribute *attr,
130 const char *buf, size_t count)
126{ 131{
127 struct atxp1_data *data; 132 struct atxp1_data *data;
128 struct i2c_client *client; 133 struct i2c_client *client;
129 int vid, cvid; 134 int vid, cvid;
130 unsigned int vcore; 135 unsigned long vcore;
136 int err;
131 137
132 client = to_i2c_client(dev); 138 client = to_i2c_client(dev);
133 data = atxp1_update_device(dev); 139 data = atxp1_update_device(dev);
134 140
135 vcore = simple_strtoul(buf, NULL, 10); 141 err = kstrtoul(buf, 10, &vcore);
142 if (err)
143 return err;
144
136 vcore /= 25; 145 vcore /= 25;
137 vcore *= 25; 146 vcore *= 25;
138 147
@@ -144,7 +153,10 @@ static ssize_t atxp1_storevcore(struct device *dev, struct device_attribute *att
144 return -1; 153 return -1;
145 } 154 }
146 155
147 /* If output enabled, use control register value. Otherwise original CPU VID */ 156 /*
157 * If output enabled, use control register value.
158 * Otherwise original CPU VID
159 */
148 if (data->reg.vid & ATXP1_VIDENA) 160 if (data->reg.vid & ATXP1_VIDENA)
149 cvid = data->reg.vid & ATXP1_VIDMASK; 161 cvid = data->reg.vid & ATXP1_VIDMASK;
150 else 162 else
@@ -154,18 +166,17 @@ static ssize_t atxp1_storevcore(struct device *dev, struct device_attribute *att
154 if (vid == cvid) 166 if (vid == cvid)
155 return count; 167 return count;
156 168
157 dev_dbg(dev, "Setting VCore to %d mV (0x%02x)\n", vcore, vid); 169 dev_dbg(dev, "Setting VCore to %d mV (0x%02x)\n", (int)vcore, vid);
158 170
159 /* Write every 25 mV step to increase stability */ 171 /* Write every 25 mV step to increase stability */
160 if (cvid > vid) { 172 if (cvid > vid) {
161 for (; cvid >= vid; cvid--) { 173 for (; cvid >= vid; cvid--)
162 i2c_smbus_write_byte_data(client, ATXP1_VID, cvid | ATXP1_VIDENA); 174 i2c_smbus_write_byte_data(client,
163 } 175 ATXP1_VID, cvid | ATXP1_VIDENA);
164 } 176 } else {
165 else { 177 for (; cvid <= vid; cvid++)
166 for (; cvid <= vid; cvid++) { 178 i2c_smbus_write_byte_data(client,
167 i2c_smbus_write_byte_data(client, ATXP1_VID, cvid | ATXP1_VIDENA); 179 ATXP1_VID, cvid | ATXP1_VIDENA);
168 }
169 } 180 }
170 181
171 data->valid = 0; 182 data->valid = 0;
@@ -173,13 +184,16 @@ static ssize_t atxp1_storevcore(struct device *dev, struct device_attribute *att
173 return count; 184 return count;
174} 185}
175 186
176/* CPU core reference voltage 187/*
177 unit: millivolt 188 * CPU core reference voltage
178*/ 189 * unit: millivolt
179static DEVICE_ATTR(cpu0_vid, S_IRUGO | S_IWUSR, atxp1_showvcore, atxp1_storevcore); 190 */
191static DEVICE_ATTR(cpu0_vid, S_IRUGO | S_IWUSR, atxp1_showvcore,
192 atxp1_storevcore);
180 193
181/* sys file functions for GPIO1 */ 194/* sys file functions for GPIO1 */
182static ssize_t atxp1_showgpio1(struct device *dev, struct device_attribute *attr, char *buf) 195static ssize_t atxp1_showgpio1(struct device *dev,
196 struct device_attribute *attr, char *buf)
183{ 197{
184 int size; 198 int size;
185 struct atxp1_data *data; 199 struct atxp1_data *data;
@@ -191,21 +205,26 @@ static ssize_t atxp1_showgpio1(struct device *dev, struct device_attribute *attr
191 return size; 205 return size;
192} 206}
193 207
194static ssize_t atxp1_storegpio1(struct device *dev, struct device_attribute *attr, const char*buf, size_t count) 208static ssize_t atxp1_storegpio1(struct device *dev,
209 struct device_attribute *attr, const char *buf,
210 size_t count)
195{ 211{
196 struct atxp1_data *data; 212 struct atxp1_data *data;
197 struct i2c_client *client; 213 struct i2c_client *client;
198 unsigned int value; 214 unsigned long value;
215 int err;
199 216
200 client = to_i2c_client(dev); 217 client = to_i2c_client(dev);
201 data = atxp1_update_device(dev); 218 data = atxp1_update_device(dev);
202 219
203 value = simple_strtoul(buf, NULL, 16); 220 err = kstrtoul(buf, 16, &value);
221 if (err)
222 return err;
204 223
205 value &= ATXP1_GPIO1MASK; 224 value &= ATXP1_GPIO1MASK;
206 225
207 if (value != (data->reg.gpio1 & ATXP1_GPIO1MASK)) { 226 if (value != (data->reg.gpio1 & ATXP1_GPIO1MASK)) {
208 dev_info(dev, "Writing 0x%x to GPIO1.\n", value); 227 dev_info(dev, "Writing 0x%x to GPIO1.\n", (unsigned int)value);
209 228
210 i2c_smbus_write_byte_data(client, ATXP1_GPIO1, value); 229 i2c_smbus_write_byte_data(client, ATXP1_GPIO1, value);
211 230
@@ -215,13 +234,15 @@ static ssize_t atxp1_storegpio1(struct device *dev, struct device_attribute *att
215 return count; 234 return count;
216} 235}
217 236
218/* GPIO1 data register 237/*
219 unit: Four bit as hex (e.g. 0x0f) 238 * GPIO1 data register
220*/ 239 * unit: Four bit as hex (e.g. 0x0f)
240 */
221static DEVICE_ATTR(gpio1, S_IRUGO | S_IWUSR, atxp1_showgpio1, atxp1_storegpio1); 241static DEVICE_ATTR(gpio1, S_IRUGO | S_IWUSR, atxp1_showgpio1, atxp1_storegpio1);
222 242
223/* sys file functions for GPIO2 */ 243/* sys file functions for GPIO2 */
224static ssize_t atxp1_showgpio2(struct device *dev, struct device_attribute *attr, char *buf) 244static ssize_t atxp1_showgpio2(struct device *dev,
245 struct device_attribute *attr, char *buf)
225{ 246{
226 int size; 247 int size;
227 struct atxp1_data *data; 248 struct atxp1_data *data;
@@ -233,19 +254,22 @@ static ssize_t atxp1_showgpio2(struct device *dev, struct device_attribute *attr
233 return size; 254 return size;
234} 255}
235 256
236static ssize_t atxp1_storegpio2(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 257static ssize_t atxp1_storegpio2(struct device *dev,
258 struct device_attribute *attr,
259 const char *buf, size_t count)
237{ 260{
238 struct atxp1_data *data; 261 struct atxp1_data *data = atxp1_update_device(dev);
239 struct i2c_client *client; 262 struct i2c_client *client = to_i2c_client(dev);
240 unsigned int value; 263 unsigned long value;
241 264 int err;
242 client = to_i2c_client(dev);
243 data = atxp1_update_device(dev);
244 265
245 value = simple_strtoul(buf, NULL, 16) & 0xff; 266 err = kstrtoul(buf, 16, &value);
267 if (err)
268 return err;
269 value &= 0xff;
246 270
247 if (value != data->reg.gpio2) { 271 if (value != data->reg.gpio2) {
248 dev_info(dev, "Writing 0x%x to GPIO1.\n", value); 272 dev_info(dev, "Writing 0x%x to GPIO1.\n", (unsigned int)value);
249 273
250 i2c_smbus_write_byte_data(client, ATXP1_GPIO2, value); 274 i2c_smbus_write_byte_data(client, ATXP1_GPIO2, value);
251 275
@@ -255,9 +279,10 @@ static ssize_t atxp1_storegpio2(struct device *dev, struct device_attribute *att
255 return count; 279 return count;
256} 280}
257 281
258/* GPIO2 data register 282/*
259 unit: Eight bit as hex (e.g. 0xff) 283 * GPIO2 data register
260*/ 284 * unit: Eight bit as hex (e.g. 0xff)
285 */
261static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2); 286static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2);
262 287
263static struct attribute *atxp1_attributes[] = { 288static struct attribute *atxp1_attributes[] = {
@@ -290,8 +315,10 @@ static int atxp1_detect(struct i2c_client *new_client,
290 (i2c_smbus_read_byte_data(new_client, 0xff) == 0))) 315 (i2c_smbus_read_byte_data(new_client, 0xff) == 0)))
291 return -ENODEV; 316 return -ENODEV;
292 317
293 /* No vendor ID, now checking if registers 0x10,0x11 (non-existent) 318 /*
294 * showing the same as register 0x00 */ 319 * No vendor ID, now checking if registers 0x10,0x11 (non-existent)
320 * showing the same as register 0x00
321 */
295 temp = i2c_smbus_read_byte_data(new_client, 0x00); 322 temp = i2c_smbus_read_byte_data(new_client, 0x00);
296 323
297 if (!((i2c_smbus_read_byte_data(new_client, 0x10) == temp) && 324 if (!((i2c_smbus_read_byte_data(new_client, 0x10) == temp) &&
@@ -333,7 +360,8 @@ static int atxp1_probe(struct i2c_client *new_client,
333 mutex_init(&data->update_lock); 360 mutex_init(&data->update_lock);
334 361
335 /* Register sysfs hooks */ 362 /* Register sysfs hooks */
336 if ((err = sysfs_create_group(&new_client->dev.kobj, &atxp1_group))) 363 err = sysfs_create_group(&new_client->dev.kobj, &atxp1_group);
364 if (err)
337 goto exit_free; 365 goto exit_free;
338 366
339 data->hwmon_dev = hwmon_device_register(&new_client->dev); 367 data->hwmon_dev = hwmon_device_register(&new_client->dev);
@@ -357,7 +385,7 @@ exit:
357 385
358static int atxp1_remove(struct i2c_client *client) 386static int atxp1_remove(struct i2c_client *client)
359{ 387{
360 struct atxp1_data * data = i2c_get_clientdata(client); 388 struct atxp1_data *data = i2c_get_clientdata(client);
361 389
362 hwmon_device_unregister(data->hwmon_dev); 390 hwmon_device_unregister(data->hwmon_dev);
363 sysfs_remove_group(&client->dev.kobj, &atxp1_group); 391 sysfs_remove_group(&client->dev.kobj, &atxp1_group);