aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/adt7462.c
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
commit8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch)
treea8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /drivers/hwmon/adt7462.c
parent406089d01562f1e2bf9f089fd7637009ebaad589 (diff)
Patched in Tegra support.
Diffstat (limited to 'drivers/hwmon/adt7462.c')
-rw-r--r--drivers/hwmon/adt7462.c74
1 files changed, 46 insertions, 28 deletions
diff --git a/drivers/hwmon/adt7462.c b/drivers/hwmon/adt7462.c
index 98a7d81e25c..2af0c7b6b4e 100644
--- a/drivers/hwmon/adt7462.c
+++ b/drivers/hwmon/adt7462.c
@@ -26,6 +26,7 @@
26#include <linux/hwmon-sysfs.h> 26#include <linux/hwmon-sysfs.h>
27#include <linux/err.h> 27#include <linux/err.h>
28#include <linux/mutex.h> 28#include <linux/mutex.h>
29#include <linux/delay.h>
29#include <linux/log2.h> 30#include <linux/log2.h>
30#include <linux/slab.h> 31#include <linux/slab.h>
31 32
@@ -64,8 +65,8 @@ static const unsigned short normal_i2c[] = { 0x58, 0x5C, I2C_CLIENT_END };
64#define ADT7462_REG_PWM_TEMP_MIN_MAX_ADDR 0x5F 65#define ADT7462_REG_PWM_TEMP_MIN_MAX_ADDR 0x5F
65#define ADT7462_REG_PWM_TEMP_RANGE_BASE_ADDR 0x60 66#define ADT7462_REG_PWM_TEMP_RANGE_BASE_ADDR 0x60
66#define ADT7462_REG_PWM_TEMP_RANGE_MAX_ADDR 0x63 67#define ADT7462_REG_PWM_TEMP_RANGE_MAX_ADDR 0x63
67#define ADT7462_PWM_HYST_MASK 0x0F 68#define ADT7462_PWM_HYST_MASK 0x0F
68#define ADT7462_PWM_RANGE_MASK 0xF0 69#define ADT7462_PWM_RANGE_MASK 0xF0
69#define ADT7462_PWM_RANGE_SHIFT 4 70#define ADT7462_PWM_RANGE_SHIFT 4
70#define ADT7462_REG_PWM_CFG_BASE_ADDR 0x21 71#define ADT7462_REG_PWM_CFG_BASE_ADDR 0x21
71#define ADT7462_REG_PWM_CFG_MAX_ADDR 0x24 72#define ADT7462_REG_PWM_CFG_MAX_ADDR 0x24
@@ -84,7 +85,7 @@ static const unsigned short normal_i2c[] = { 0x58, 0x5C, I2C_CLIENT_END };
84#define ADT7462_PIN15_INPUT 0x20 85#define ADT7462_PIN15_INPUT 0x20
85#define ADT7462_PIN13_INPUT 0x40 86#define ADT7462_PIN13_INPUT 0x40
86#define ADT7462_PIN8_INPUT 0x80 87#define ADT7462_PIN8_INPUT 0x80
87#define ADT7462_PIN23_MASK 0x03 88#define ADT7462_PIN23_MASK 0x03
88#define ADT7462_PIN23_SHIFT 0 89#define ADT7462_PIN23_SHIFT 0
89#define ADT7462_PIN26_MASK 0x0C /* cfg2 */ 90#define ADT7462_PIN26_MASK 0x0C /* cfg2 */
90#define ADT7462_PIN26_SHIFT 2 91#define ADT7462_PIN26_SHIFT 2
@@ -98,7 +99,7 @@ static const unsigned short normal_i2c[] = { 0x58, 0x5C, I2C_CLIENT_END };
98#define ADT7462_PIN28_VOLT 0x5 99#define ADT7462_PIN28_VOLT 0x5
99 100
100#define ADT7462_REG_ALARM1 0xB8 101#define ADT7462_REG_ALARM1 0xB8
101#define ADT7462_LT_ALARM 0x02 102#define ADT7462_LT_ALARM 0x02
102#define ADT7462_R1T_ALARM 0x04 103#define ADT7462_R1T_ALARM 0x04
103#define ADT7462_R2T_ALARM 0x08 104#define ADT7462_R2T_ALARM 0x08
104#define ADT7462_R3T_ALARM 0x10 105#define ADT7462_R3T_ALARM 0x10
@@ -134,9 +135,9 @@ static const unsigned short normal_i2c[] = { 0x58, 0x5C, I2C_CLIENT_END };
134#define ADT7462_ALARM_FLAG_MASK 0x0F 135#define ADT7462_ALARM_FLAG_MASK 0x0F
135 136
136#define ADT7462_TEMP_COUNT 4 137#define ADT7462_TEMP_COUNT 4
137#define ADT7462_TEMP_REG(x) (ADT7462_REG_TEMP_BASE_ADDR + ((x) * 2)) 138#define ADT7462_TEMP_REG(x) (ADT7462_REG_TEMP_BASE_ADDR + (x * 2))
138#define ADT7462_TEMP_MIN_REG(x) (ADT7462_REG_MIN_TEMP_BASE_ADDR + (x)) 139#define ADT7462_TEMP_MIN_REG(x) (ADT7462_REG_MIN_TEMP_BASE_ADDR + (x))
139#define ADT7462_TEMP_MAX_REG(x) (ADT7462_REG_MAX_TEMP_BASE_ADDR + (x)) 140#define ADT7462_TEMP_MAX_REG(x) (ADT7462_REG_MAX_TEMP_BASE_ADDR + (x))
140#define TEMP_FRAC_OFFSET 6 141#define TEMP_FRAC_OFFSET 6
141 142
142#define ADT7462_FAN_COUNT 8 143#define ADT7462_FAN_COUNT 8
@@ -832,7 +833,7 @@ static ssize_t set_temp_min(struct device *dev,
832 struct adt7462_data *data = i2c_get_clientdata(client); 833 struct adt7462_data *data = i2c_get_clientdata(client);
833 long temp; 834 long temp;
834 835
835 if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) 836 if (strict_strtol(buf, 10, &temp) || !temp_enabled(data, attr->index))
836 return -EINVAL; 837 return -EINVAL;
837 838
838 temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; 839 temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
@@ -870,7 +871,7 @@ static ssize_t set_temp_max(struct device *dev,
870 struct adt7462_data *data = i2c_get_clientdata(client); 871 struct adt7462_data *data = i2c_get_clientdata(client);
871 long temp; 872 long temp;
872 873
873 if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) 874 if (strict_strtol(buf, 10, &temp) || !temp_enabled(data, attr->index))
874 return -EINVAL; 875 return -EINVAL;
875 876
876 temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; 877 temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
@@ -934,7 +935,7 @@ static ssize_t set_volt_max(struct device *dev,
934 int x = voltage_multiplier(data, attr->index); 935 int x = voltage_multiplier(data, attr->index);
935 long temp; 936 long temp;
936 937
937 if (kstrtol(buf, 10, &temp) || !x) 938 if (strict_strtol(buf, 10, &temp) || !x)
938 return -EINVAL; 939 return -EINVAL;
939 940
940 temp *= 1000; /* convert mV to uV */ 941 temp *= 1000; /* convert mV to uV */
@@ -976,7 +977,7 @@ static ssize_t set_volt_min(struct device *dev,
976 int x = voltage_multiplier(data, attr->index); 977 int x = voltage_multiplier(data, attr->index);
977 long temp; 978 long temp;
978 979
979 if (kstrtol(buf, 10, &temp) || !x) 980 if (strict_strtol(buf, 10, &temp) || !x)
980 return -EINVAL; 981 return -EINVAL;
981 982
982 temp *= 1000; /* convert mV to uV */ 983 temp *= 1000; /* convert mV to uV */
@@ -1065,7 +1066,7 @@ static ssize_t set_fan_min(struct device *dev,
1065 struct adt7462_data *data = i2c_get_clientdata(client); 1066 struct adt7462_data *data = i2c_get_clientdata(client);
1066 long temp; 1067 long temp;
1067 1068
1068 if (kstrtol(buf, 10, &temp) || !temp || 1069 if (strict_strtol(buf, 10, &temp) || !temp ||
1069 !fan_enabled(data, attr->index)) 1070 !fan_enabled(data, attr->index))
1070 return -EINVAL; 1071 return -EINVAL;
1071 1072
@@ -1114,7 +1115,7 @@ static ssize_t set_force_pwm_max(struct device *dev,
1114 long temp; 1115 long temp;
1115 u8 reg; 1116 u8 reg;
1116 1117
1117 if (kstrtol(buf, 10, &temp)) 1118 if (strict_strtol(buf, 10, &temp))
1118 return -EINVAL; 1119 return -EINVAL;
1119 1120
1120 mutex_lock(&data->lock); 1121 mutex_lock(&data->lock);
@@ -1146,7 +1147,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
1146 struct adt7462_data *data = i2c_get_clientdata(client); 1147 struct adt7462_data *data = i2c_get_clientdata(client);
1147 long temp; 1148 long temp;
1148 1149
1149 if (kstrtol(buf, 10, &temp)) 1150 if (strict_strtol(buf, 10, &temp))
1150 return -EINVAL; 1151 return -EINVAL;
1151 1152
1152 temp = SENSORS_LIMIT(temp, 0, 255); 1153 temp = SENSORS_LIMIT(temp, 0, 255);
@@ -1176,7 +1177,7 @@ static ssize_t set_pwm_max(struct device *dev,
1176 struct adt7462_data *data = i2c_get_clientdata(client); 1177 struct adt7462_data *data = i2c_get_clientdata(client);
1177 long temp; 1178 long temp;
1178 1179
1179 if (kstrtol(buf, 10, &temp)) 1180 if (strict_strtol(buf, 10, &temp))
1180 return -EINVAL; 1181 return -EINVAL;
1181 1182
1182 temp = SENSORS_LIMIT(temp, 0, 255); 1183 temp = SENSORS_LIMIT(temp, 0, 255);
@@ -1208,7 +1209,7 @@ static ssize_t set_pwm_min(struct device *dev,
1208 struct adt7462_data *data = i2c_get_clientdata(client); 1209 struct adt7462_data *data = i2c_get_clientdata(client);
1209 long temp; 1210 long temp;
1210 1211
1211 if (kstrtol(buf, 10, &temp)) 1212 if (strict_strtol(buf, 10, &temp))
1212 return -EINVAL; 1213 return -EINVAL;
1213 1214
1214 temp = SENSORS_LIMIT(temp, 0, 255); 1215 temp = SENSORS_LIMIT(temp, 0, 255);
@@ -1242,7 +1243,7 @@ static ssize_t set_pwm_hyst(struct device *dev,
1242 struct adt7462_data *data = i2c_get_clientdata(client); 1243 struct adt7462_data *data = i2c_get_clientdata(client);
1243 long temp; 1244 long temp;
1244 1245
1245 if (kstrtol(buf, 10, &temp)) 1246 if (strict_strtol(buf, 10, &temp))
1246 return -EINVAL; 1247 return -EINVAL;
1247 1248
1248 temp = DIV_ROUND_CLOSEST(temp, 1000); 1249 temp = DIV_ROUND_CLOSEST(temp, 1000);
@@ -1288,7 +1289,7 @@ static ssize_t set_pwm_tmax(struct device *dev,
1288 int tmin, trange_value; 1289 int tmin, trange_value;
1289 long trange; 1290 long trange;
1290 1291
1291 if (kstrtol(buf, 10, &trange)) 1292 if (strict_strtol(buf, 10, &trange))
1292 return -EINVAL; 1293 return -EINVAL;
1293 1294
1294 /* trange = tmax - tmin */ 1295 /* trange = tmax - tmin */
@@ -1329,7 +1330,7 @@ static ssize_t set_pwm_tmin(struct device *dev,
1329 struct adt7462_data *data = i2c_get_clientdata(client); 1330 struct adt7462_data *data = i2c_get_clientdata(client);
1330 long temp; 1331 long temp;
1331 1332
1332 if (kstrtol(buf, 10, &temp)) 1333 if (strict_strtol(buf, 10, &temp))
1333 return -EINVAL; 1334 return -EINVAL;
1334 1335
1335 temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; 1336 temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
@@ -1386,7 +1387,7 @@ static ssize_t set_pwm_auto(struct device *dev,
1386 struct adt7462_data *data = i2c_get_clientdata(client); 1387 struct adt7462_data *data = i2c_get_clientdata(client);
1387 long temp; 1388 long temp;
1388 1389
1389 if (kstrtol(buf, 10, &temp)) 1390 if (strict_strtol(buf, 10, &temp))
1390 return -EINVAL; 1391 return -EINVAL;
1391 1392
1392 switch (temp) { 1393 switch (temp) {
@@ -1445,7 +1446,7 @@ static ssize_t set_pwm_auto_temp(struct device *dev,
1445 struct adt7462_data *data = i2c_get_clientdata(client); 1446 struct adt7462_data *data = i2c_get_clientdata(client);
1446 long temp; 1447 long temp;
1447 1448
1448 if (kstrtol(buf, 10, &temp)) 1449 if (strict_strtol(buf, 10, &temp))
1449 return -EINVAL; 1450 return -EINVAL;
1450 1451
1451 temp = cvt_auto_temp(temp); 1452 temp = cvt_auto_temp(temp);
@@ -1726,7 +1727,8 @@ static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO,
1726static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO, 1727static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO,
1727 show_pwm_auto_temp, set_pwm_auto_temp, 3); 1728 show_pwm_auto_temp, set_pwm_auto_temp, 3);
1728 1729
1729static struct attribute *adt7462_attr[] = { 1730static struct attribute *adt7462_attr[] =
1731{
1730 &sensor_dev_attr_temp1_max.dev_attr.attr, 1732 &sensor_dev_attr_temp1_max.dev_attr.attr,
1731 &sensor_dev_attr_temp2_max.dev_attr.attr, 1733 &sensor_dev_attr_temp2_max.dev_attr.attr,
1732 &sensor_dev_attr_temp3_max.dev_attr.attr, 1734 &sensor_dev_attr_temp3_max.dev_attr.attr,
@@ -1930,10 +1932,11 @@ static int adt7462_probe(struct i2c_client *client,
1930 struct adt7462_data *data; 1932 struct adt7462_data *data;
1931 int err; 1933 int err;
1932 1934
1933 data = devm_kzalloc(&client->dev, sizeof(struct adt7462_data), 1935 data = kzalloc(sizeof(struct adt7462_data), GFP_KERNEL);
1934 GFP_KERNEL); 1936 if (!data) {
1935 if (!data) 1937 err = -ENOMEM;
1936 return -ENOMEM; 1938 goto exit;
1939 }
1937 1940
1938 i2c_set_clientdata(client, data); 1941 i2c_set_clientdata(client, data);
1939 mutex_init(&data->lock); 1942 mutex_init(&data->lock);
@@ -1944,7 +1947,7 @@ static int adt7462_probe(struct i2c_client *client,
1944 data->attrs.attrs = adt7462_attr; 1947 data->attrs.attrs = adt7462_attr;
1945 err = sysfs_create_group(&client->dev.kobj, &data->attrs); 1948 err = sysfs_create_group(&client->dev.kobj, &data->attrs);
1946 if (err) 1949 if (err)
1947 return err; 1950 goto exit_free;
1948 1951
1949 data->hwmon_dev = hwmon_device_register(&client->dev); 1952 data->hwmon_dev = hwmon_device_register(&client->dev);
1950 if (IS_ERR(data->hwmon_dev)) { 1953 if (IS_ERR(data->hwmon_dev)) {
@@ -1956,6 +1959,9 @@ static int adt7462_probe(struct i2c_client *client,
1956 1959
1957exit_remove: 1960exit_remove:
1958 sysfs_remove_group(&client->dev.kobj, &data->attrs); 1961 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1962exit_free:
1963 kfree(data);
1964exit:
1959 return err; 1965 return err;
1960} 1966}
1961 1967
@@ -1965,11 +1971,23 @@ static int adt7462_remove(struct i2c_client *client)
1965 1971
1966 hwmon_device_unregister(data->hwmon_dev); 1972 hwmon_device_unregister(data->hwmon_dev);
1967 sysfs_remove_group(&client->dev.kobj, &data->attrs); 1973 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1974 kfree(data);
1968 return 0; 1975 return 0;
1969} 1976}
1970 1977
1971module_i2c_driver(adt7462_driver); 1978static int __init adt7462_init(void)
1979{
1980 return i2c_add_driver(&adt7462_driver);
1981}
1982
1983static void __exit adt7462_exit(void)
1984{
1985 i2c_del_driver(&adt7462_driver);
1986}
1972 1987
1973MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>"); 1988MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>");
1974MODULE_DESCRIPTION("ADT7462 driver"); 1989MODULE_DESCRIPTION("ADT7462 driver");
1975MODULE_LICENSE("GPL"); 1990MODULE_LICENSE("GPL");
1991
1992module_init(adt7462_init);
1993module_exit(adt7462_exit);