26 #include <linux/module.h>
28 #include <linux/slab.h>
30 #include <linux/i2c.h>
38 static unsigned short normal_i2c[] = { 0x2c, 0x2e, 0x2f,
I2C_CLIENT_END };
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
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
69 #define MAX6639_FAN_CONFIG1_PWM 0x80
71 #define MAX6639_FAN_CONFIG3_THERM_FULL_SPEED 0x40
73 static const int rpm_ranges[] = { 2000, 4000, 8000, 16000 };
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) SENSORS_LIMIT((val) / 1000, 0, 255)
118 dev_dbg(&client->
dev,
"Starting max6639 update\n");
122 if (status_reg < 0) {
123 ret = ERR_PTR(status_reg);
127 data->
status = status_reg;
129 for (i = 0; i < 2; i++) {
144 data->
temp[
i] = res >> 5;
153 data->
temp[
i] |= res << 3;
173 return PTR_ERR(data);
176 return sprintf(buf,
"%ld\n", temp);
186 return PTR_ERR(data);
203 const char *buf,
size_t count)
211 res = kstrtoul(buf, 10, &val);
236 const char *buf,
size_t count)
244 res = kstrtoul(buf, 10, &val);
270 const char *buf,
size_t count)
278 res = kstrtoul(buf, 10, &val);
303 const char *buf,
size_t count)
311 res = kstrtoul(buf, 10, &val);
315 val = SENSORS_LIMIT(val, 0, 255);
318 data->
pwm[attr->
index] = (
u8)(val * 120 / 255);
333 return PTR_ERR(data);
346 return PTR_ERR(data);
364 show_temp_emergency, set_temp_emergency, 0);
366 show_temp_emergency, set_temp_emergency, 1);
381 static struct attribute *max6639_attributes[] = {
382 &sensor_dev_attr_temp1_input.dev_attr.attr,
383 &sensor_dev_attr_temp2_input.dev_attr.attr,
384 &sensor_dev_attr_temp1_fault.dev_attr.attr,
385 &sensor_dev_attr_temp2_fault.dev_attr.attr,
386 &sensor_dev_attr_temp1_max.dev_attr.attr,
387 &sensor_dev_attr_temp2_max.dev_attr.attr,
388 &sensor_dev_attr_temp1_crit.dev_attr.attr,
389 &sensor_dev_attr_temp2_crit.dev_attr.attr,
390 &sensor_dev_attr_temp1_emergency.dev_attr.attr,
391 &sensor_dev_attr_temp2_emergency.dev_attr.attr,
392 &sensor_dev_attr_pwm1.dev_attr.attr,
393 &sensor_dev_attr_pwm2.dev_attr.attr,
394 &sensor_dev_attr_fan1_input.dev_attr.attr,
395 &sensor_dev_attr_fan2_input.dev_attr.attr,
396 &sensor_dev_attr_fan1_fault.dev_attr.attr,
397 &sensor_dev_attr_fan2_fault.dev_attr.attr,
398 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
399 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
400 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
401 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
402 &sensor_dev_attr_temp1_emergency_alarm.dev_attr.attr,
403 &sensor_dev_attr_temp2_emergency_alarm.dev_attr.attr,
408 .attrs = max6639_attributes,
415 static int rpm_range_to_reg(
int range)
419 for (i = 0; i <
ARRAY_SIZE(rpm_ranges); i++) {
420 if (rpm_ranges[i] == range)
427 static int max6639_init_client(
struct i2c_client *client)
431 client->
dev.platform_data;
443 if (max6639_info && max6639_info->
ppr > 0 &&
444 max6639_info->
ppr < 5)
445 data->
ppr = max6639_info->
ppr;
451 rpm_range = rpm_range_to_reg(max6639_info->
rpm_range);
454 for (i = 0; i < 2; i++) {
525 static int max6639_detect(
struct i2c_client *client,
537 if (dev_id != 0x58 || manu_id != 0x4D)
545 static int max6639_probe(
struct i2c_client *client,
556 i2c_set_clientdata(client, data);
560 err = max6639_init_client(client);
575 dev_info(&client->
dev,
"temperature sensor and fan control found\n");
584 static int max6639_remove(
struct i2c_client *client)
594 #ifdef CONFIG_PM_SLEEP
595 static int max6639_suspend(
struct device *dev)
606 static int max6639_resume(
struct device *dev)
625 static const struct dev_pm_ops max6639_pm_ops = {
633 .pm = &max6639_pm_ops,
635 .probe = max6639_probe,
636 .remove = max6639_remove,
637 .id_table = max6639_id,
638 .detect = max6639_detect,
639 .address_list = normal_i2c,