xref: /openbmc/linux/drivers/hwmon/max6639.c (revision dd5b2498)
1 /*
2  * max6639.c - Support for Maxim MAX6639
3  *
4  * 2-Channel Temperature Monitor with Dual PWM Fan-Speed Controller
5  *
6  * Copyright (C) 2010, 2011 Roland Stigge <stigge@antcom.de>
7  *
8  * based on the initial MAX6639 support from semptian.net
9  * by He Changqing <hechangqing@semptian.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25 
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/slab.h>
29 #include <linux/jiffies.h>
30 #include <linux/i2c.h>
31 #include <linux/hwmon.h>
32 #include <linux/hwmon-sysfs.h>
33 #include <linux/err.h>
34 #include <linux/mutex.h>
35 #include <linux/platform_data/max6639.h>
36 
37 /* Addresses to scan */
38 static const unsigned short normal_i2c[] = { 0x2c, 0x2e, 0x2f, I2C_CLIENT_END };
39 
40 /* The MAX6639 registers, valid channel numbers: 0, 1 */
41 #define MAX6639_REG_TEMP(ch)			(0x00 + (ch))
42 #define MAX6639_REG_STATUS			0x02
43 #define MAX6639_REG_OUTPUT_MASK			0x03
44 #define MAX6639_REG_GCONFIG			0x04
45 #define MAX6639_REG_TEMP_EXT(ch)		(0x05 + (ch))
46 #define MAX6639_REG_ALERT_LIMIT(ch)		(0x08 + (ch))
47 #define MAX6639_REG_OT_LIMIT(ch)		(0x0A + (ch))
48 #define MAX6639_REG_THERM_LIMIT(ch)		(0x0C + (ch))
49 #define MAX6639_REG_FAN_CONFIG1(ch)		(0x10 + (ch) * 4)
50 #define MAX6639_REG_FAN_CONFIG2a(ch)		(0x11 + (ch) * 4)
51 #define MAX6639_REG_FAN_CONFIG2b(ch)		(0x12 + (ch) * 4)
52 #define MAX6639_REG_FAN_CONFIG3(ch)		(0x13 + (ch) * 4)
53 #define MAX6639_REG_FAN_CNT(ch)			(0x20 + (ch))
54 #define MAX6639_REG_TARGET_CNT(ch)		(0x22 + (ch))
55 #define MAX6639_REG_FAN_PPR(ch)			(0x24 + (ch))
56 #define MAX6639_REG_TARGTDUTY(ch)		(0x26 + (ch))
57 #define MAX6639_REG_FAN_START_TEMP(ch)		(0x28 + (ch))
58 #define MAX6639_REG_DEVID			0x3D
59 #define MAX6639_REG_MANUID			0x3E
60 #define MAX6639_REG_DEVREV			0x3F
61 
62 /* Register bits */
63 #define MAX6639_GCONFIG_STANDBY			0x80
64 #define MAX6639_GCONFIG_POR			0x40
65 #define MAX6639_GCONFIG_DISABLE_TIMEOUT		0x20
66 #define MAX6639_GCONFIG_CH2_LOCAL		0x10
67 #define MAX6639_GCONFIG_PWM_FREQ_HI		0x08
68 
69 #define MAX6639_FAN_CONFIG1_PWM			0x80
70 
71 #define MAX6639_FAN_CONFIG3_THERM_FULL_SPEED	0x40
72 
73 static const int rpm_ranges[] = { 2000, 4000, 8000, 16000 };
74 
75 #define FAN_FROM_REG(val, rpm_range)	((val) == 0 || (val) == 255 ? \
76 				0 : (rpm_ranges[rpm_range] * 30) / (val))
77 #define TEMP_LIMIT_TO_REG(val)	clamp_val((val) / 1000, 0, 255)
78 
79 /*
80  * Client data (each client gets its own)
81  */
82 struct max6639_data {
83 	struct i2c_client *client;
84 	struct mutex update_lock;
85 	char valid;		/* !=0 if following fields are valid */
86 	unsigned long last_updated;	/* In jiffies */
87 
88 	/* Register values sampled regularly */
89 	u16 temp[2];		/* Temperature, in 1/8 C, 0..255 C */
90 	bool temp_fault[2];	/* Detected temperature diode failure */
91 	u8 fan[2];		/* Register value: TACH count for fans >=30 */
92 	u8 status;		/* Detected channel alarms and fan failures */
93 
94 	/* Register values only written to */
95 	u8 pwm[2];		/* Register value: Duty cycle 0..120 */
96 	u8 temp_therm[2];	/* THERM Temperature, 0..255 C (->_max) */
97 	u8 temp_alert[2];	/* ALERT Temperature, 0..255 C (->_crit) */
98 	u8 temp_ot[2];		/* OT Temperature, 0..255 C (->_emergency) */
99 
100 	/* Register values initialized only once */
101 	u8 ppr;			/* Pulses per rotation 0..3 for 1..4 ppr */
102 	u8 rpm_range;		/* Index in above rpm_ranges table */
103 };
104 
105 static struct max6639_data *max6639_update_device(struct device *dev)
106 {
107 	struct max6639_data *data = dev_get_drvdata(dev);
108 	struct i2c_client *client = data->client;
109 	struct max6639_data *ret = data;
110 	int i;
111 	int status_reg;
112 
113 	mutex_lock(&data->update_lock);
114 
115 	if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
116 		int res;
117 
118 		dev_dbg(&client->dev, "Starting max6639 update\n");
119 
120 		status_reg = i2c_smbus_read_byte_data(client,
121 						      MAX6639_REG_STATUS);
122 		if (status_reg < 0) {
123 			ret = ERR_PTR(status_reg);
124 			goto abort;
125 		}
126 
127 		data->status = status_reg;
128 
129 		for (i = 0; i < 2; i++) {
130 			res = i2c_smbus_read_byte_data(client,
131 					MAX6639_REG_FAN_CNT(i));
132 			if (res < 0) {
133 				ret = ERR_PTR(res);
134 				goto abort;
135 			}
136 			data->fan[i] = res;
137 
138 			res = i2c_smbus_read_byte_data(client,
139 					MAX6639_REG_TEMP_EXT(i));
140 			if (res < 0) {
141 				ret = ERR_PTR(res);
142 				goto abort;
143 			}
144 			data->temp[i] = res >> 5;
145 			data->temp_fault[i] = res & 0x01;
146 
147 			res = i2c_smbus_read_byte_data(client,
148 					MAX6639_REG_TEMP(i));
149 			if (res < 0) {
150 				ret = ERR_PTR(res);
151 				goto abort;
152 			}
153 			data->temp[i] |= res << 3;
154 		}
155 
156 		data->last_updated = jiffies;
157 		data->valid = 1;
158 	}
159 abort:
160 	mutex_unlock(&data->update_lock);
161 
162 	return ret;
163 }
164 
165 static ssize_t temp_input_show(struct device *dev,
166 			       struct device_attribute *dev_attr, char *buf)
167 {
168 	long temp;
169 	struct max6639_data *data = max6639_update_device(dev);
170 	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
171 
172 	if (IS_ERR(data))
173 		return PTR_ERR(data);
174 
175 	temp = data->temp[attr->index] * 125;
176 	return sprintf(buf, "%ld\n", temp);
177 }
178 
179 static ssize_t temp_fault_show(struct device *dev,
180 			       struct device_attribute *dev_attr, char *buf)
181 {
182 	struct max6639_data *data = max6639_update_device(dev);
183 	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
184 
185 	if (IS_ERR(data))
186 		return PTR_ERR(data);
187 
188 	return sprintf(buf, "%d\n", data->temp_fault[attr->index]);
189 }
190 
191 static ssize_t temp_max_show(struct device *dev,
192 			     struct device_attribute *dev_attr, char *buf)
193 {
194 	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
195 	struct max6639_data *data = dev_get_drvdata(dev);
196 
197 	return sprintf(buf, "%d\n", (data->temp_therm[attr->index] * 1000));
198 }
199 
200 static ssize_t temp_max_store(struct device *dev,
201 			      struct device_attribute *dev_attr,
202 			      const char *buf, size_t count)
203 {
204 	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
205 	struct max6639_data *data = dev_get_drvdata(dev);
206 	struct i2c_client *client = data->client;
207 	unsigned long val;
208 	int res;
209 
210 	res = kstrtoul(buf, 10, &val);
211 	if (res)
212 		return res;
213 
214 	mutex_lock(&data->update_lock);
215 	data->temp_therm[attr->index] = TEMP_LIMIT_TO_REG(val);
216 	i2c_smbus_write_byte_data(client,
217 				  MAX6639_REG_THERM_LIMIT(attr->index),
218 				  data->temp_therm[attr->index]);
219 	mutex_unlock(&data->update_lock);
220 	return count;
221 }
222 
223 static ssize_t temp_crit_show(struct device *dev,
224 			      struct device_attribute *dev_attr, char *buf)
225 {
226 	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
227 	struct max6639_data *data = dev_get_drvdata(dev);
228 
229 	return sprintf(buf, "%d\n", (data->temp_alert[attr->index] * 1000));
230 }
231 
232 static ssize_t temp_crit_store(struct device *dev,
233 			       struct device_attribute *dev_attr,
234 			       const char *buf, size_t count)
235 {
236 	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
237 	struct max6639_data *data = dev_get_drvdata(dev);
238 	struct i2c_client *client = data->client;
239 	unsigned long val;
240 	int res;
241 
242 	res = kstrtoul(buf, 10, &val);
243 	if (res)
244 		return res;
245 
246 	mutex_lock(&data->update_lock);
247 	data->temp_alert[attr->index] = TEMP_LIMIT_TO_REG(val);
248 	i2c_smbus_write_byte_data(client,
249 				  MAX6639_REG_ALERT_LIMIT(attr->index),
250 				  data->temp_alert[attr->index]);
251 	mutex_unlock(&data->update_lock);
252 	return count;
253 }
254 
255 static ssize_t temp_emergency_show(struct device *dev,
256 				   struct device_attribute *dev_attr,
257 				   char *buf)
258 {
259 	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
260 	struct max6639_data *data = dev_get_drvdata(dev);
261 
262 	return sprintf(buf, "%d\n", (data->temp_ot[attr->index] * 1000));
263 }
264 
265 static ssize_t temp_emergency_store(struct device *dev,
266 				    struct device_attribute *dev_attr,
267 				    const char *buf, size_t count)
268 {
269 	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
270 	struct max6639_data *data = dev_get_drvdata(dev);
271 	struct i2c_client *client = data->client;
272 	unsigned long val;
273 	int res;
274 
275 	res = kstrtoul(buf, 10, &val);
276 	if (res)
277 		return res;
278 
279 	mutex_lock(&data->update_lock);
280 	data->temp_ot[attr->index] = TEMP_LIMIT_TO_REG(val);
281 	i2c_smbus_write_byte_data(client,
282 				  MAX6639_REG_OT_LIMIT(attr->index),
283 				  data->temp_ot[attr->index]);
284 	mutex_unlock(&data->update_lock);
285 	return count;
286 }
287 
288 static ssize_t pwm_show(struct device *dev, struct device_attribute *dev_attr,
289 			char *buf)
290 {
291 	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
292 	struct max6639_data *data = dev_get_drvdata(dev);
293 
294 	return sprintf(buf, "%d\n", data->pwm[attr->index] * 255 / 120);
295 }
296 
297 static ssize_t pwm_store(struct device *dev,
298 			 struct device_attribute *dev_attr, const char *buf,
299 			 size_t count)
300 {
301 	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
302 	struct max6639_data *data = dev_get_drvdata(dev);
303 	struct i2c_client *client = data->client;
304 	unsigned long val;
305 	int res;
306 
307 	res = kstrtoul(buf, 10, &val);
308 	if (res)
309 		return res;
310 
311 	val = clamp_val(val, 0, 255);
312 
313 	mutex_lock(&data->update_lock);
314 	data->pwm[attr->index] = (u8)(val * 120 / 255);
315 	i2c_smbus_write_byte_data(client,
316 				  MAX6639_REG_TARGTDUTY(attr->index),
317 				  data->pwm[attr->index]);
318 	mutex_unlock(&data->update_lock);
319 	return count;
320 }
321 
322 static ssize_t fan_input_show(struct device *dev,
323 			      struct device_attribute *dev_attr, char *buf)
324 {
325 	struct max6639_data *data = max6639_update_device(dev);
326 	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
327 
328 	if (IS_ERR(data))
329 		return PTR_ERR(data);
330 
331 	return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index],
332 		       data->rpm_range));
333 }
334 
335 static ssize_t alarm_show(struct device *dev,
336 			  struct device_attribute *dev_attr, char *buf)
337 {
338 	struct max6639_data *data = max6639_update_device(dev);
339 	struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
340 
341 	if (IS_ERR(data))
342 		return PTR_ERR(data);
343 
344 	return sprintf(buf, "%d\n", !!(data->status & (1 << attr->index)));
345 }
346 
347 static SENSOR_DEVICE_ATTR_RO(temp1_input, temp_input, 0);
348 static SENSOR_DEVICE_ATTR_RO(temp2_input, temp_input, 1);
349 static SENSOR_DEVICE_ATTR_RO(temp1_fault, temp_fault, 0);
350 static SENSOR_DEVICE_ATTR_RO(temp2_fault, temp_fault, 1);
351 static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0);
352 static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1);
353 static SENSOR_DEVICE_ATTR_RW(temp1_crit, temp_crit, 0);
354 static SENSOR_DEVICE_ATTR_RW(temp2_crit, temp_crit, 1);
355 static SENSOR_DEVICE_ATTR_RW(temp1_emergency, temp_emergency, 0);
356 static SENSOR_DEVICE_ATTR_RW(temp2_emergency, temp_emergency, 1);
357 static SENSOR_DEVICE_ATTR_RW(pwm1, pwm, 0);
358 static SENSOR_DEVICE_ATTR_RW(pwm2, pwm, 1);
359 static SENSOR_DEVICE_ATTR_RO(fan1_input, fan_input, 0);
360 static SENSOR_DEVICE_ATTR_RO(fan2_input, fan_input, 1);
361 static SENSOR_DEVICE_ATTR_RO(fan1_fault, alarm, 1);
362 static SENSOR_DEVICE_ATTR_RO(fan2_fault, alarm, 0);
363 static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, 3);
364 static SENSOR_DEVICE_ATTR_RO(temp2_max_alarm, alarm, 2);
365 static SENSOR_DEVICE_ATTR_RO(temp1_crit_alarm, alarm, 7);
366 static SENSOR_DEVICE_ATTR_RO(temp2_crit_alarm, alarm, 6);
367 static SENSOR_DEVICE_ATTR_RO(temp1_emergency_alarm, alarm, 5);
368 static SENSOR_DEVICE_ATTR_RO(temp2_emergency_alarm, alarm, 4);
369 
370 
371 static struct attribute *max6639_attrs[] = {
372 	&sensor_dev_attr_temp1_input.dev_attr.attr,
373 	&sensor_dev_attr_temp2_input.dev_attr.attr,
374 	&sensor_dev_attr_temp1_fault.dev_attr.attr,
375 	&sensor_dev_attr_temp2_fault.dev_attr.attr,
376 	&sensor_dev_attr_temp1_max.dev_attr.attr,
377 	&sensor_dev_attr_temp2_max.dev_attr.attr,
378 	&sensor_dev_attr_temp1_crit.dev_attr.attr,
379 	&sensor_dev_attr_temp2_crit.dev_attr.attr,
380 	&sensor_dev_attr_temp1_emergency.dev_attr.attr,
381 	&sensor_dev_attr_temp2_emergency.dev_attr.attr,
382 	&sensor_dev_attr_pwm1.dev_attr.attr,
383 	&sensor_dev_attr_pwm2.dev_attr.attr,
384 	&sensor_dev_attr_fan1_input.dev_attr.attr,
385 	&sensor_dev_attr_fan2_input.dev_attr.attr,
386 	&sensor_dev_attr_fan1_fault.dev_attr.attr,
387 	&sensor_dev_attr_fan2_fault.dev_attr.attr,
388 	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
389 	&sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
390 	&sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
391 	&sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
392 	&sensor_dev_attr_temp1_emergency_alarm.dev_attr.attr,
393 	&sensor_dev_attr_temp2_emergency_alarm.dev_attr.attr,
394 	NULL
395 };
396 ATTRIBUTE_GROUPS(max6639);
397 
398 /*
399  *  returns respective index in rpm_ranges table
400  *  1 by default on invalid range
401  */
402 static int rpm_range_to_reg(int range)
403 {
404 	int i;
405 
406 	for (i = 0; i < ARRAY_SIZE(rpm_ranges); i++) {
407 		if (rpm_ranges[i] == range)
408 			return i;
409 	}
410 
411 	return 1; /* default: 4000 RPM */
412 }
413 
414 static int max6639_init_client(struct i2c_client *client,
415 			       struct max6639_data *data)
416 {
417 	struct max6639_platform_data *max6639_info =
418 		dev_get_platdata(&client->dev);
419 	int i;
420 	int rpm_range = 1; /* default: 4000 RPM */
421 	int err;
422 
423 	/* Reset chip to default values, see below for GCONFIG setup */
424 	err = i2c_smbus_write_byte_data(client, MAX6639_REG_GCONFIG,
425 				  MAX6639_GCONFIG_POR);
426 	if (err)
427 		goto exit;
428 
429 	/* Fans pulse per revolution is 2 by default */
430 	if (max6639_info && max6639_info->ppr > 0 &&
431 			max6639_info->ppr < 5)
432 		data->ppr = max6639_info->ppr;
433 	else
434 		data->ppr = 2;
435 	data->ppr -= 1;
436 
437 	if (max6639_info)
438 		rpm_range = rpm_range_to_reg(max6639_info->rpm_range);
439 	data->rpm_range = rpm_range;
440 
441 	for (i = 0; i < 2; i++) {
442 
443 		/* Set Fan pulse per revolution */
444 		err = i2c_smbus_write_byte_data(client,
445 				MAX6639_REG_FAN_PPR(i),
446 				data->ppr << 6);
447 		if (err)
448 			goto exit;
449 
450 		/* Fans config PWM, RPM */
451 		err = i2c_smbus_write_byte_data(client,
452 			MAX6639_REG_FAN_CONFIG1(i),
453 			MAX6639_FAN_CONFIG1_PWM | rpm_range);
454 		if (err)
455 			goto exit;
456 
457 		/* Fans PWM polarity high by default */
458 		if (max6639_info && max6639_info->pwm_polarity == 0)
459 			err = i2c_smbus_write_byte_data(client,
460 				MAX6639_REG_FAN_CONFIG2a(i), 0x00);
461 		else
462 			err = i2c_smbus_write_byte_data(client,
463 				MAX6639_REG_FAN_CONFIG2a(i), 0x02);
464 		if (err)
465 			goto exit;
466 
467 		/*
468 		 * /THERM full speed enable,
469 		 * PWM frequency 25kHz, see also GCONFIG below
470 		 */
471 		err = i2c_smbus_write_byte_data(client,
472 			MAX6639_REG_FAN_CONFIG3(i),
473 			MAX6639_FAN_CONFIG3_THERM_FULL_SPEED | 0x03);
474 		if (err)
475 			goto exit;
476 
477 		/* Max. temp. 80C/90C/100C */
478 		data->temp_therm[i] = 80;
479 		data->temp_alert[i] = 90;
480 		data->temp_ot[i] = 100;
481 		err = i2c_smbus_write_byte_data(client,
482 				MAX6639_REG_THERM_LIMIT(i),
483 				data->temp_therm[i]);
484 		if (err)
485 			goto exit;
486 		err = i2c_smbus_write_byte_data(client,
487 				MAX6639_REG_ALERT_LIMIT(i),
488 				data->temp_alert[i]);
489 		if (err)
490 			goto exit;
491 		err = i2c_smbus_write_byte_data(client,
492 				MAX6639_REG_OT_LIMIT(i), data->temp_ot[i]);
493 		if (err)
494 			goto exit;
495 
496 		/* PWM 120/120 (i.e. 100%) */
497 		data->pwm[i] = 120;
498 		err = i2c_smbus_write_byte_data(client,
499 				MAX6639_REG_TARGTDUTY(i), data->pwm[i]);
500 		if (err)
501 			goto exit;
502 	}
503 	/* Start monitoring */
504 	err = i2c_smbus_write_byte_data(client, MAX6639_REG_GCONFIG,
505 		MAX6639_GCONFIG_DISABLE_TIMEOUT | MAX6639_GCONFIG_CH2_LOCAL |
506 		MAX6639_GCONFIG_PWM_FREQ_HI);
507 exit:
508 	return err;
509 }
510 
511 /* Return 0 if detection is successful, -ENODEV otherwise */
512 static int max6639_detect(struct i2c_client *client,
513 			  struct i2c_board_info *info)
514 {
515 	struct i2c_adapter *adapter = client->adapter;
516 	int dev_id, manu_id;
517 
518 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
519 		return -ENODEV;
520 
521 	/* Actual detection via device and manufacturer ID */
522 	dev_id = i2c_smbus_read_byte_data(client, MAX6639_REG_DEVID);
523 	manu_id = i2c_smbus_read_byte_data(client, MAX6639_REG_MANUID);
524 	if (dev_id != 0x58 || manu_id != 0x4D)
525 		return -ENODEV;
526 
527 	strlcpy(info->type, "max6639", I2C_NAME_SIZE);
528 
529 	return 0;
530 }
531 
532 static int max6639_probe(struct i2c_client *client,
533 			 const struct i2c_device_id *id)
534 {
535 	struct device *dev = &client->dev;
536 	struct max6639_data *data;
537 	struct device *hwmon_dev;
538 	int err;
539 
540 	data = devm_kzalloc(dev, sizeof(struct max6639_data), GFP_KERNEL);
541 	if (!data)
542 		return -ENOMEM;
543 
544 	data->client = client;
545 	mutex_init(&data->update_lock);
546 
547 	/* Initialize the max6639 chip */
548 	err = max6639_init_client(client, data);
549 	if (err < 0)
550 		return err;
551 
552 	hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
553 							   data,
554 							   max6639_groups);
555 	return PTR_ERR_OR_ZERO(hwmon_dev);
556 }
557 
558 #ifdef CONFIG_PM_SLEEP
559 static int max6639_suspend(struct device *dev)
560 {
561 	struct i2c_client *client = to_i2c_client(dev);
562 	int data = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG);
563 	if (data < 0)
564 		return data;
565 
566 	return i2c_smbus_write_byte_data(client,
567 			MAX6639_REG_GCONFIG, data | MAX6639_GCONFIG_STANDBY);
568 }
569 
570 static int max6639_resume(struct device *dev)
571 {
572 	struct i2c_client *client = to_i2c_client(dev);
573 	int data = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG);
574 	if (data < 0)
575 		return data;
576 
577 	return i2c_smbus_write_byte_data(client,
578 			MAX6639_REG_GCONFIG, data & ~MAX6639_GCONFIG_STANDBY);
579 }
580 #endif /* CONFIG_PM_SLEEP */
581 
582 static const struct i2c_device_id max6639_id[] = {
583 	{"max6639", 0},
584 	{ }
585 };
586 
587 MODULE_DEVICE_TABLE(i2c, max6639_id);
588 
589 static SIMPLE_DEV_PM_OPS(max6639_pm_ops, max6639_suspend, max6639_resume);
590 
591 static struct i2c_driver max6639_driver = {
592 	.class = I2C_CLASS_HWMON,
593 	.driver = {
594 		   .name = "max6639",
595 		   .pm = &max6639_pm_ops,
596 		   },
597 	.probe = max6639_probe,
598 	.id_table = max6639_id,
599 	.detect = max6639_detect,
600 	.address_list = normal_i2c,
601 };
602 
603 module_i2c_driver(max6639_driver);
604 
605 MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
606 MODULE_DESCRIPTION("max6639 driver");
607 MODULE_LICENSE("GPL");
608