aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/adm1031.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/adm1031.c')
-rw-r--r--drivers/hwmon/adm1031.c68
1 files changed, 66 insertions, 2 deletions
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
index 1644b92e7cc..15c1a9616af 100644
--- a/drivers/hwmon/adm1031.c
+++ b/drivers/hwmon/adm1031.c
@@ -36,6 +36,7 @@
36#define ADM1031_REG_FAN_DIV(nr) (0x20 + (nr)) 36#define ADM1031_REG_FAN_DIV(nr) (0x20 + (nr))
37#define ADM1031_REG_PWM (0x22) 37#define ADM1031_REG_PWM (0x22)
38#define ADM1031_REG_FAN_MIN(nr) (0x10 + (nr)) 38#define ADM1031_REG_FAN_MIN(nr) (0x10 + (nr))
39#define ADM1031_REG_FAN_FILTER (0x23)
39 40
40#define ADM1031_REG_TEMP_OFFSET(nr) (0x0d + (nr)) 41#define ADM1031_REG_TEMP_OFFSET(nr) (0x0d + (nr))
41#define ADM1031_REG_TEMP_MAX(nr) (0x14 + 4 * (nr)) 42#define ADM1031_REG_TEMP_MAX(nr) (0x14 + 4 * (nr))
@@ -61,6 +62,9 @@
61#define ADM1031_CONF2_TACH2_ENABLE 0x08 62#define ADM1031_CONF2_TACH2_ENABLE 0x08
62#define ADM1031_CONF2_TEMP_ENABLE(chan) (0x10 << (chan)) 63#define ADM1031_CONF2_TEMP_ENABLE(chan) (0x10 << (chan))
63 64
65#define ADM1031_UPDATE_RATE_MASK 0x1c
66#define ADM1031_UPDATE_RATE_SHIFT 2
67
64/* Addresses to scan */ 68/* Addresses to scan */
65static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 69static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
66 70
@@ -75,6 +79,7 @@ struct adm1031_data {
75 int chip_type; 79 int chip_type;
76 char valid; /* !=0 if following fields are valid */ 80 char valid; /* !=0 if following fields are valid */
77 unsigned long last_updated; /* In jiffies */ 81 unsigned long last_updated; /* In jiffies */
82 unsigned int update_rate; /* In milliseconds */
78 /* The chan_select_table contains the possible configurations for 83 /* The chan_select_table contains the possible configurations for
79 * auto fan control. 84 * auto fan control.
80 */ 85 */
@@ -738,6 +743,57 @@ static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 12);
738static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13); 743static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13);
739static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14); 744static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14);
740 745
746/* Update Rate */
747static const unsigned int update_rates[] = {
748 16000, 8000, 4000, 2000, 1000, 500, 250, 125,
749};
750
751static ssize_t show_update_rate(struct device *dev,
752 struct device_attribute *attr, char *buf)
753{
754 struct i2c_client *client = to_i2c_client(dev);
755 struct adm1031_data *data = i2c_get_clientdata(client);
756
757 return sprintf(buf, "%u\n", data->update_rate);
758}
759
760static ssize_t set_update_rate(struct device *dev,
761 struct device_attribute *attr,
762 const char *buf, size_t count)
763{
764 struct i2c_client *client = to_i2c_client(dev);
765 struct adm1031_data *data = i2c_get_clientdata(client);
766 unsigned long val;
767 int i, err;
768 u8 reg;
769
770 err = strict_strtoul(buf, 10, &val);
771 if (err)
772 return err;
773
774 /* find the nearest update rate from the table */
775 for (i = 0; i < ARRAY_SIZE(update_rates) - 1; i++) {
776 if (val >= update_rates[i])
777 break;
778 }
779 /* if not found, we point to the last entry (lowest update rate) */
780
781 /* set the new update rate while preserving other settings */
782 reg = adm1031_read_value(client, ADM1031_REG_FAN_FILTER);
783 reg &= ~ADM1031_UPDATE_RATE_MASK;
784 reg |= i << ADM1031_UPDATE_RATE_SHIFT;
785 adm1031_write_value(client, ADM1031_REG_FAN_FILTER, reg);
786
787 mutex_lock(&data->update_lock);
788 data->update_rate = update_rates[i];
789 mutex_unlock(&data->update_lock);
790
791 return count;
792}
793
794static DEVICE_ATTR(update_rate, S_IRUGO | S_IWUSR, show_update_rate,
795 set_update_rate);
796
741static struct attribute *adm1031_attributes[] = { 797static struct attribute *adm1031_attributes[] = {
742 &sensor_dev_attr_fan1_input.dev_attr.attr, 798 &sensor_dev_attr_fan1_input.dev_attr.attr,
743 &sensor_dev_attr_fan1_div.dev_attr.attr, 799 &sensor_dev_attr_fan1_div.dev_attr.attr,
@@ -774,6 +830,7 @@ static struct attribute *adm1031_attributes[] = {
774 830
775 &sensor_dev_attr_auto_fan1_min_pwm.dev_attr.attr, 831 &sensor_dev_attr_auto_fan1_min_pwm.dev_attr.attr,
776 832
833 &dev_attr_update_rate.attr,
777 &dev_attr_alarms.attr, 834 &dev_attr_alarms.attr,
778 835
779 NULL 836 NULL
@@ -900,6 +957,7 @@ static void adm1031_init_client(struct i2c_client *client)
900{ 957{
901 unsigned int read_val; 958 unsigned int read_val;
902 unsigned int mask; 959 unsigned int mask;
960 int i;
903 struct adm1031_data *data = i2c_get_clientdata(client); 961 struct adm1031_data *data = i2c_get_clientdata(client);
904 962
905 mask = (ADM1031_CONF2_PWM1_ENABLE | ADM1031_CONF2_TACH1_ENABLE); 963 mask = (ADM1031_CONF2_PWM1_ENABLE | ADM1031_CONF2_TACH1_ENABLE);
@@ -919,18 +977,24 @@ static void adm1031_init_client(struct i2c_client *client)
919 ADM1031_CONF1_MONITOR_ENABLE); 977 ADM1031_CONF1_MONITOR_ENABLE);
920 } 978 }
921 979
980 /* Read the chip's update rate */
981 mask = ADM1031_UPDATE_RATE_MASK;
982 read_val = adm1031_read_value(client, ADM1031_REG_FAN_FILTER);
983 i = (read_val & mask) >> ADM1031_UPDATE_RATE_SHIFT;
984 data->update_rate = update_rates[i];
922} 985}
923 986
924static struct adm1031_data *adm1031_update_device(struct device *dev) 987static struct adm1031_data *adm1031_update_device(struct device *dev)
925{ 988{
926 struct i2c_client *client = to_i2c_client(dev); 989 struct i2c_client *client = to_i2c_client(dev);
927 struct adm1031_data *data = i2c_get_clientdata(client); 990 struct adm1031_data *data = i2c_get_clientdata(client);
991 unsigned long next_update;
928 int chan; 992 int chan;
929 993
930 mutex_lock(&data->update_lock); 994 mutex_lock(&data->update_lock);
931 995
932 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 996 next_update = data->last_updated + msecs_to_jiffies(data->update_rate);
933 || !data->valid) { 997 if (time_after(jiffies, next_update) || !data->valid) {
934 998
935 dev_dbg(&client->dev, "Starting adm1031 update\n"); 999 dev_dbg(&client->dev, "Starting adm1031 update\n");
936 for (chan = 0; 1000 for (chan = 0;