Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | adm1031.c - Part of lm_sensors, Linux kernel modules for hardware |
| 3 | monitoring |
| 4 | Based on lm75.c and lm85.c |
| 5 | Supports adm1030 / adm1031 |
| 6 | Copyright (C) 2004 Alexandre d'Alton <alex@alexdalton.org> |
| 7 | Reworked by Jean Delvare <khali@linux-fr.org> |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 2 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program; if not, write to the Free Software |
| 21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | */ |
| 23 | |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/slab.h> |
| 27 | #include <linux/jiffies.h> |
| 28 | #include <linux/i2c.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 29 | #include <linux/hwmon.h> |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 30 | #include <linux/hwmon-sysfs.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 31 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 32 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | /* Following macros takes channel parameter starting from 0 to 2 */ |
| 35 | #define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr)) |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 36 | #define ADM1031_REG_FAN_DIV(nr) (0x20 + (nr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #define ADM1031_REG_PWM (0x22) |
| 38 | #define ADM1031_REG_FAN_MIN(nr) (0x10 + (nr)) |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 39 | #define ADM1031_REG_FAN_FILTER (0x23) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 41 | #define ADM1031_REG_TEMP_OFFSET(nr) (0x0d + (nr)) |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 42 | #define ADM1031_REG_TEMP_MAX(nr) (0x14 + 4 * (nr)) |
| 43 | #define ADM1031_REG_TEMP_MIN(nr) (0x15 + 4 * (nr)) |
| 44 | #define ADM1031_REG_TEMP_CRIT(nr) (0x16 + 4 * (nr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 46 | #define ADM1031_REG_TEMP(nr) (0x0a + (nr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #define ADM1031_REG_AUTO_TEMP(nr) (0x24 + (nr)) |
| 48 | |
| 49 | #define ADM1031_REG_STATUS(nr) (0x2 + (nr)) |
| 50 | |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 51 | #define ADM1031_REG_CONF1 0x00 |
| 52 | #define ADM1031_REG_CONF2 0x01 |
| 53 | #define ADM1031_REG_EXT_TEMP 0x06 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | #define ADM1031_CONF1_MONITOR_ENABLE 0x01 /* Monitoring enable */ |
| 56 | #define ADM1031_CONF1_PWM_INVERT 0x08 /* PWM Invert */ |
| 57 | #define ADM1031_CONF1_AUTO_MODE 0x80 /* Auto FAN */ |
| 58 | |
| 59 | #define ADM1031_CONF2_PWM1_ENABLE 0x01 |
| 60 | #define ADM1031_CONF2_PWM2_ENABLE 0x02 |
| 61 | #define ADM1031_CONF2_TACH1_ENABLE 0x04 |
| 62 | #define ADM1031_CONF2_TACH2_ENABLE 0x08 |
| 63 | #define ADM1031_CONF2_TEMP_ENABLE(chan) (0x10 << (chan)) |
| 64 | |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 65 | #define ADM1031_UPDATE_RATE_MASK 0x1c |
| 66 | #define ADM1031_UPDATE_RATE_SHIFT 2 |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /* Addresses to scan */ |
Mark M. Hoffman | 25e9c86 | 2008-02-17 22:28:03 -0500 | [diff] [blame] | 69 | static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Jean Delvare | e5e9f44 | 2009-12-14 21:17:27 +0100 | [diff] [blame] | 71 | enum chips { adm1030, adm1031 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | typedef u8 auto_chan_table_t[8][2]; |
| 74 | |
| 75 | /* Each client has this additional data */ |
| 76 | struct adm1031_data { |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 77 | struct device *hwmon_dev; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 78 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | int chip_type; |
| 80 | char valid; /* !=0 if following fields are valid */ |
| 81 | unsigned long last_updated; /* In jiffies */ |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 82 | unsigned int update_interval; /* In milliseconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | /* The chan_select_table contains the possible configurations for |
| 84 | * auto fan control. |
| 85 | */ |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 86 | const auto_chan_table_t *chan_select_table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | u16 alarm; |
| 88 | u8 conf1; |
| 89 | u8 conf2; |
| 90 | u8 fan[2]; |
| 91 | u8 fan_div[2]; |
| 92 | u8 fan_min[2]; |
| 93 | u8 pwm[2]; |
| 94 | u8 old_pwm[2]; |
| 95 | s8 temp[3]; |
| 96 | u8 ext_temp[3]; |
| 97 | u8 auto_temp[3]; |
| 98 | u8 auto_temp_min[3]; |
| 99 | u8 auto_temp_off[3]; |
| 100 | u8 auto_temp_max[3]; |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 101 | s8 temp_offset[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | s8 temp_min[3]; |
| 103 | s8 temp_max[3]; |
| 104 | s8 temp_crit[3]; |
| 105 | }; |
| 106 | |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 107 | static int adm1031_probe(struct i2c_client *client, |
| 108 | const struct i2c_device_id *id); |
Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 109 | static int adm1031_detect(struct i2c_client *client, |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 110 | struct i2c_board_info *info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | static void adm1031_init_client(struct i2c_client *client); |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 112 | static int adm1031_remove(struct i2c_client *client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | static struct adm1031_data *adm1031_update_device(struct device *dev); |
| 114 | |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 115 | static const struct i2c_device_id adm1031_id[] = { |
| 116 | { "adm1030", adm1030 }, |
| 117 | { "adm1031", adm1031 }, |
| 118 | { } |
| 119 | }; |
| 120 | MODULE_DEVICE_TABLE(i2c, adm1031_id); |
| 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | /* This is the driver that will be inserted */ |
| 123 | static struct i2c_driver adm1031_driver = { |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 124 | .class = I2C_CLASS_HWMON, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 125 | .driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 126 | .name = "adm1031", |
| 127 | }, |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 128 | .probe = adm1031_probe, |
| 129 | .remove = adm1031_remove, |
| 130 | .id_table = adm1031_id, |
| 131 | .detect = adm1031_detect, |
Jean Delvare | c3813d6 | 2009-12-14 21:17:25 +0100 | [diff] [blame] | 132 | .address_list = normal_i2c, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | static inline u8 adm1031_read_value(struct i2c_client *client, u8 reg) |
| 136 | { |
| 137 | return i2c_smbus_read_byte_data(client, reg); |
| 138 | } |
| 139 | |
| 140 | static inline int |
| 141 | adm1031_write_value(struct i2c_client *client, u8 reg, unsigned int value) |
| 142 | { |
| 143 | return i2c_smbus_write_byte_data(client, reg, value); |
| 144 | } |
| 145 | |
| 146 | |
| 147 | #define TEMP_TO_REG(val) (((val) < 0 ? ((val - 500) / 1000) : \ |
| 148 | ((val + 500) / 1000))) |
| 149 | |
| 150 | #define TEMP_FROM_REG(val) ((val) * 1000) |
| 151 | |
| 152 | #define TEMP_FROM_REG_EXT(val, ext) (TEMP_FROM_REG(val) + (ext) * 125) |
| 153 | |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 154 | #define TEMP_OFFSET_TO_REG(val) (TEMP_TO_REG(val) & 0x8f) |
| 155 | #define TEMP_OFFSET_FROM_REG(val) TEMP_FROM_REG((val) < 0 ? \ |
| 156 | (val) | 0x70 : (val)) |
| 157 | |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 158 | #define FAN_FROM_REG(reg, div) ((reg) ? \ |
| 159 | (11250 * 60) / ((reg) * (div)) : 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
| 161 | static int FAN_TO_REG(int reg, int div) |
| 162 | { |
| 163 | int tmp; |
| 164 | tmp = FAN_FROM_REG(SENSORS_LIMIT(reg, 0, 65535), div); |
| 165 | return tmp > 255 ? 255 : tmp; |
| 166 | } |
| 167 | |
| 168 | #define FAN_DIV_FROM_REG(reg) (1<<(((reg)&0xc0)>>6)) |
| 169 | |
| 170 | #define PWM_TO_REG(val) (SENSORS_LIMIT((val), 0, 255) >> 4) |
| 171 | #define PWM_FROM_REG(val) ((val) << 4) |
| 172 | |
| 173 | #define FAN_CHAN_FROM_REG(reg) (((reg) >> 5) & 7) |
| 174 | #define FAN_CHAN_TO_REG(val, reg) \ |
| 175 | (((reg) & 0x1F) | (((val) << 5) & 0xe0)) |
| 176 | |
| 177 | #define AUTO_TEMP_MIN_TO_REG(val, reg) \ |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 178 | ((((val) / 500) & 0xf8) | ((reg) & 0x7)) |
| 179 | #define AUTO_TEMP_RANGE_FROM_REG(reg) (5000 * (1 << ((reg) & 0x7))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | #define AUTO_TEMP_MIN_FROM_REG(reg) (1000 * ((((reg) >> 3) & 0x1f) << 2)) |
| 181 | |
| 182 | #define AUTO_TEMP_MIN_FROM_REG_DEG(reg) ((((reg) >> 3) & 0x1f) << 2) |
| 183 | |
| 184 | #define AUTO_TEMP_OFF_FROM_REG(reg) \ |
| 185 | (AUTO_TEMP_MIN_FROM_REG(reg) - 5000) |
| 186 | |
| 187 | #define AUTO_TEMP_MAX_FROM_REG(reg) \ |
| 188 | (AUTO_TEMP_RANGE_FROM_REG(reg) + \ |
| 189 | AUTO_TEMP_MIN_FROM_REG(reg)) |
| 190 | |
| 191 | static int AUTO_TEMP_MAX_TO_REG(int val, int reg, int pwm) |
| 192 | { |
| 193 | int ret; |
| 194 | int range = val - AUTO_TEMP_MIN_FROM_REG(reg); |
| 195 | |
| 196 | range = ((val - AUTO_TEMP_MIN_FROM_REG(reg))*10)/(16 - pwm); |
| 197 | ret = ((reg & 0xf8) | |
| 198 | (range < 10000 ? 0 : |
| 199 | range < 20000 ? 1 : |
| 200 | range < 40000 ? 2 : range < 80000 ? 3 : 4)); |
| 201 | return ret; |
| 202 | } |
| 203 | |
| 204 | /* FAN auto control */ |
| 205 | #define GET_FAN_AUTO_BITFIELD(data, idx) \ |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 206 | (*(data)->chan_select_table)[FAN_CHAN_FROM_REG((data)->conf1)][idx % 2] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 208 | /* The tables below contains the possible values for the auto fan |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | * control bitfields. the index in the table is the register value. |
| 210 | * MSb is the auto fan control enable bit, so the four first entries |
| 211 | * in the table disables auto fan control when both bitfields are zero. |
| 212 | */ |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 213 | static const auto_chan_table_t auto_channel_select_table_adm1031 = { |
| 214 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, |
| 215 | { 2 /* 0b010 */ , 4 /* 0b100 */ }, |
| 216 | { 2 /* 0b010 */ , 2 /* 0b010 */ }, |
| 217 | { 4 /* 0b100 */ , 4 /* 0b100 */ }, |
| 218 | { 7 /* 0b111 */ , 7 /* 0b111 */ }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | }; |
| 220 | |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 221 | static const auto_chan_table_t auto_channel_select_table_adm1030 = { |
| 222 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, |
| 223 | { 2 /* 0b10 */ , 0 }, |
| 224 | { 0xff /* invalid */ , 0 }, |
| 225 | { 0xff /* invalid */ , 0 }, |
| 226 | { 3 /* 0b11 */ , 0 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | }; |
| 228 | |
| 229 | /* That function checks if a bitfield is valid and returns the other bitfield |
| 230 | * nearest match if no exact match where found. |
| 231 | */ |
| 232 | static int |
| 233 | get_fan_auto_nearest(struct adm1031_data *data, |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 234 | int chan, u8 val, u8 reg, u8 *new_reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { |
| 236 | int i; |
| 237 | int first_match = -1, exact_match = -1; |
| 238 | u8 other_reg_val = |
| 239 | (*data->chan_select_table)[FAN_CHAN_FROM_REG(reg)][chan ? 0 : 1]; |
| 240 | |
| 241 | if (val == 0) { |
| 242 | *new_reg = 0; |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | for (i = 0; i < 8; i++) { |
| 247 | if ((val == (*data->chan_select_table)[i][chan]) && |
| 248 | ((*data->chan_select_table)[i][chan ? 0 : 1] == |
| 249 | other_reg_val)) { |
| 250 | /* We found an exact match */ |
| 251 | exact_match = i; |
| 252 | break; |
| 253 | } else if (val == (*data->chan_select_table)[i][chan] && |
| 254 | first_match == -1) { |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 255 | /* Save the first match in case of an exact match has |
| 256 | * not been found |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | */ |
| 258 | first_match = i; |
| 259 | } |
| 260 | } |
| 261 | |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 262 | if (exact_match >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | *new_reg = exact_match; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 264 | else if (first_match >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | *new_reg = first_match; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 266 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | return -EINVAL; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | return 0; |
| 270 | } |
| 271 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 272 | static ssize_t show_fan_auto_channel(struct device *dev, |
| 273 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 275 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | struct adm1031_data *data = adm1031_update_device(dev); |
| 277 | return sprintf(buf, "%d\n", GET_FAN_AUTO_BITFIELD(data, nr)); |
| 278 | } |
| 279 | |
| 280 | static ssize_t |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 281 | set_fan_auto_channel(struct device *dev, struct device_attribute *attr, |
| 282 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
| 284 | struct i2c_client *client = to_i2c_client(dev); |
| 285 | struct adm1031_data *data = i2c_get_clientdata(client); |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 286 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 287 | long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | u8 reg; |
| 289 | int ret; |
| 290 | u8 old_fan_mode; |
| 291 | |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 292 | ret = kstrtol(buf, 10, &val); |
| 293 | if (ret) |
| 294 | return ret; |
| 295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | old_fan_mode = data->conf1; |
| 297 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 298 | mutex_lock(&data->update_lock); |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 299 | |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 300 | ret = get_fan_auto_nearest(data, nr, val, data->conf1, ®); |
| 301 | if (ret) { |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 302 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | return ret; |
| 304 | } |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 305 | data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1); |
| 306 | if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) ^ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) { |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 308 | if (data->conf1 & ADM1031_CONF1_AUTO_MODE) { |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 309 | /* Switch to Auto Fan Mode |
| 310 | * Save PWM registers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | * Set PWM registers to 33% Both */ |
| 312 | data->old_pwm[0] = data->pwm[0]; |
| 313 | data->old_pwm[1] = data->pwm[1]; |
| 314 | adm1031_write_value(client, ADM1031_REG_PWM, 0x55); |
| 315 | } else { |
| 316 | /* Switch to Manual Mode */ |
| 317 | data->pwm[0] = data->old_pwm[0]; |
| 318 | data->pwm[1] = data->old_pwm[1]; |
| 319 | /* Restore PWM registers */ |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 320 | adm1031_write_value(client, ADM1031_REG_PWM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | data->pwm[0] | (data->pwm[1] << 4)); |
| 322 | } |
| 323 | } |
| 324 | data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1); |
| 325 | adm1031_write_value(client, ADM1031_REG_CONF1, data->conf1); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 326 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | return count; |
| 328 | } |
| 329 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 330 | static SENSOR_DEVICE_ATTR(auto_fan1_channel, S_IRUGO | S_IWUSR, |
| 331 | show_fan_auto_channel, set_fan_auto_channel, 0); |
| 332 | static SENSOR_DEVICE_ATTR(auto_fan2_channel, S_IRUGO | S_IWUSR, |
| 333 | show_fan_auto_channel, set_fan_auto_channel, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
| 335 | /* Auto Temps */ |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 336 | static ssize_t show_auto_temp_off(struct device *dev, |
| 337 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 339 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | struct adm1031_data *data = adm1031_update_device(dev); |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 341 | return sprintf(buf, "%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | AUTO_TEMP_OFF_FROM_REG(data->auto_temp[nr])); |
| 343 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 344 | static ssize_t show_auto_temp_min(struct device *dev, |
| 345 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 347 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | struct adm1031_data *data = adm1031_update_device(dev); |
| 349 | return sprintf(buf, "%d\n", |
| 350 | AUTO_TEMP_MIN_FROM_REG(data->auto_temp[nr])); |
| 351 | } |
| 352 | static ssize_t |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 353 | set_auto_temp_min(struct device *dev, struct device_attribute *attr, |
| 354 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | { |
| 356 | struct i2c_client *client = to_i2c_client(dev); |
| 357 | struct adm1031_data *data = i2c_get_clientdata(client); |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 358 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 359 | long val; |
| 360 | int ret; |
| 361 | |
| 362 | ret = kstrtol(buf, 10, &val); |
| 363 | if (ret) |
| 364 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 366 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | data->auto_temp[nr] = AUTO_TEMP_MIN_TO_REG(val, data->auto_temp[nr]); |
| 368 | adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr), |
| 369 | data->auto_temp[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 370 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | return count; |
| 372 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 373 | static ssize_t show_auto_temp_max(struct device *dev, |
| 374 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 376 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | struct adm1031_data *data = adm1031_update_device(dev); |
| 378 | return sprintf(buf, "%d\n", |
| 379 | AUTO_TEMP_MAX_FROM_REG(data->auto_temp[nr])); |
| 380 | } |
| 381 | static ssize_t |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 382 | set_auto_temp_max(struct device *dev, struct device_attribute *attr, |
| 383 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | { |
| 385 | struct i2c_client *client = to_i2c_client(dev); |
| 386 | struct adm1031_data *data = i2c_get_clientdata(client); |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 387 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 388 | long val; |
| 389 | int ret; |
| 390 | |
| 391 | ret = kstrtol(buf, 10, &val); |
| 392 | if (ret) |
| 393 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 395 | mutex_lock(&data->update_lock); |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 396 | data->temp_max[nr] = AUTO_TEMP_MAX_TO_REG(val, data->auto_temp[nr], |
| 397 | data->pwm[nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr), |
| 399 | data->temp_max[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 400 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | return count; |
| 402 | } |
| 403 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 404 | #define auto_temp_reg(offset) \ |
| 405 | static SENSOR_DEVICE_ATTR(auto_temp##offset##_off, S_IRUGO, \ |
| 406 | show_auto_temp_off, NULL, offset - 1); \ |
| 407 | static SENSOR_DEVICE_ATTR(auto_temp##offset##_min, S_IRUGO | S_IWUSR, \ |
| 408 | show_auto_temp_min, set_auto_temp_min, offset - 1); \ |
| 409 | static SENSOR_DEVICE_ATTR(auto_temp##offset##_max, S_IRUGO | S_IWUSR, \ |
| 410 | show_auto_temp_max, set_auto_temp_max, offset - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
| 412 | auto_temp_reg(1); |
| 413 | auto_temp_reg(2); |
| 414 | auto_temp_reg(3); |
| 415 | |
| 416 | /* pwm */ |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 417 | static ssize_t show_pwm(struct device *dev, |
| 418 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 420 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | struct adm1031_data *data = adm1031_update_device(dev); |
| 422 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr])); |
| 423 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 424 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
| 425 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | { |
| 427 | struct i2c_client *client = to_i2c_client(dev); |
| 428 | struct adm1031_data *data = i2c_get_clientdata(client); |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 429 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 430 | long val; |
| 431 | int ret, reg; |
| 432 | |
| 433 | ret = kstrtol(buf, 10, &val); |
| 434 | if (ret) |
| 435 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 437 | mutex_lock(&data->update_lock); |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 438 | if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | (((val>>4) & 0xf) != 5)) { |
| 440 | /* In automatic mode, the only PWM accepted is 33% */ |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 441 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | return -EINVAL; |
| 443 | } |
| 444 | data->pwm[nr] = PWM_TO_REG(val); |
| 445 | reg = adm1031_read_value(client, ADM1031_REG_PWM); |
| 446 | adm1031_write_value(client, ADM1031_REG_PWM, |
| 447 | nr ? ((data->pwm[nr] << 4) & 0xf0) | (reg & 0xf) |
| 448 | : (data->pwm[nr] & 0xf) | (reg & 0xf0)); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 449 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | return count; |
| 451 | } |
| 452 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 453 | static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0); |
| 454 | static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1); |
| 455 | static SENSOR_DEVICE_ATTR(auto_fan1_min_pwm, S_IRUGO | S_IWUSR, |
| 456 | show_pwm, set_pwm, 0); |
| 457 | static SENSOR_DEVICE_ATTR(auto_fan2_min_pwm, S_IRUGO | S_IWUSR, |
| 458 | show_pwm, set_pwm, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
| 460 | /* Fans */ |
| 461 | |
| 462 | /* |
| 463 | * That function checks the cases where the fan reading is not |
Steven Cole | 44bbe87 | 2005-05-03 18:21:25 -0600 | [diff] [blame] | 464 | * relevant. It is used to provide 0 as fan reading when the fan is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | * not supposed to run |
| 466 | */ |
| 467 | static int trust_fan_readings(struct adm1031_data *data, int chan) |
| 468 | { |
| 469 | int res = 0; |
| 470 | |
| 471 | if (data->conf1 & ADM1031_CONF1_AUTO_MODE) { |
| 472 | switch (data->conf1 & 0x60) { |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 473 | case 0x00: |
| 474 | /* |
| 475 | * remote temp1 controls fan1, |
| 476 | * remote temp2 controls fan2 |
| 477 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | res = data->temp[chan+1] >= |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 479 | AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[chan+1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | break; |
| 481 | case 0x20: /* remote temp1 controls both fans */ |
| 482 | res = |
| 483 | data->temp[1] >= |
| 484 | AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[1]); |
| 485 | break; |
| 486 | case 0x40: /* remote temp2 controls both fans */ |
| 487 | res = |
| 488 | data->temp[2] >= |
| 489 | AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[2]); |
| 490 | break; |
| 491 | case 0x60: /* max controls both fans */ |
| 492 | res = |
| 493 | data->temp[0] >= |
| 494 | AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[0]) |
| 495 | || data->temp[1] >= |
| 496 | AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[1]) |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 497 | || (data->chip_type == adm1031 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | && data->temp[2] >= |
| 499 | AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[2])); |
| 500 | break; |
| 501 | } |
| 502 | } else { |
| 503 | res = data->pwm[chan] > 0; |
| 504 | } |
| 505 | return res; |
| 506 | } |
| 507 | |
| 508 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 509 | static ssize_t show_fan(struct device *dev, |
| 510 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 512 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | struct adm1031_data *data = adm1031_update_device(dev); |
| 514 | int value; |
| 515 | |
| 516 | value = trust_fan_readings(data, nr) ? FAN_FROM_REG(data->fan[nr], |
| 517 | FAN_DIV_FROM_REG(data->fan_div[nr])) : 0; |
| 518 | return sprintf(buf, "%d\n", value); |
| 519 | } |
| 520 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 521 | static ssize_t show_fan_div(struct device *dev, |
| 522 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 524 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | struct adm1031_data *data = adm1031_update_device(dev); |
| 526 | return sprintf(buf, "%d\n", FAN_DIV_FROM_REG(data->fan_div[nr])); |
| 527 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 528 | static ssize_t show_fan_min(struct device *dev, |
| 529 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 531 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | struct adm1031_data *data = adm1031_update_device(dev); |
| 533 | return sprintf(buf, "%d\n", |
| 534 | FAN_FROM_REG(data->fan_min[nr], |
| 535 | FAN_DIV_FROM_REG(data->fan_div[nr]))); |
| 536 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 537 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
| 538 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | { |
| 540 | struct i2c_client *client = to_i2c_client(dev); |
| 541 | struct adm1031_data *data = i2c_get_clientdata(client); |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 542 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 543 | long val; |
| 544 | int ret; |
| 545 | |
| 546 | ret = kstrtol(buf, 10, &val); |
| 547 | if (ret) |
| 548 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 550 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | if (val) { |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 552 | data->fan_min[nr] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | FAN_TO_REG(val, FAN_DIV_FROM_REG(data->fan_div[nr])); |
| 554 | } else { |
| 555 | data->fan_min[nr] = 0xff; |
| 556 | } |
| 557 | adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), data->fan_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 558 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | return count; |
| 560 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 561 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
| 562 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | { |
| 564 | struct i2c_client *client = to_i2c_client(dev); |
| 565 | struct adm1031_data *data = i2c_get_clientdata(client); |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 566 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 567 | long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | u8 tmp; |
| 569 | int old_div; |
| 570 | int new_min; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 571 | int ret; |
| 572 | |
| 573 | ret = kstrtol(buf, 10, &val); |
| 574 | if (ret) |
| 575 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
| 577 | tmp = val == 8 ? 0xc0 : |
| 578 | val == 4 ? 0x80 : |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 579 | val == 2 ? 0x40 : |
| 580 | val == 1 ? 0x00 : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | 0xff; |
| 582 | if (tmp == 0xff) |
| 583 | return -EINVAL; |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 584 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 585 | mutex_lock(&data->update_lock); |
Jean Delvare | 38a1f0e | 2007-12-02 23:32:42 +0100 | [diff] [blame] | 586 | /* Get fresh readings */ |
| 587 | data->fan_div[nr] = adm1031_read_value(client, |
| 588 | ADM1031_REG_FAN_DIV(nr)); |
| 589 | data->fan_min[nr] = adm1031_read_value(client, |
| 590 | ADM1031_REG_FAN_MIN(nr)); |
| 591 | |
| 592 | /* Write the new clock divider and fan min */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | old_div = FAN_DIV_FROM_REG(data->fan_div[nr]); |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 594 | data->fan_div[nr] = tmp | (0x3f & data->fan_div[nr]); |
| 595 | new_min = data->fan_min[nr] * old_div / val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | data->fan_min[nr] = new_min > 0xff ? 0xff : new_min; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 598 | adm1031_write_value(client, ADM1031_REG_FAN_DIV(nr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | data->fan_div[nr]); |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 600 | adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | data->fan_min[nr]); |
Jean Delvare | 38a1f0e | 2007-12-02 23:32:42 +0100 | [diff] [blame] | 602 | |
| 603 | /* Invalidate the cache: fan speed is no longer valid */ |
| 604 | data->valid = 0; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 605 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | return count; |
| 607 | } |
| 608 | |
| 609 | #define fan_offset(offset) \ |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 610 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
| 611 | show_fan, NULL, offset - 1); \ |
| 612 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
| 613 | show_fan_min, set_fan_min, offset - 1); \ |
| 614 | static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ |
| 615 | show_fan_div, set_fan_div, offset - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
| 617 | fan_offset(1); |
| 618 | fan_offset(2); |
| 619 | |
| 620 | |
| 621 | /* Temps */ |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 622 | static ssize_t show_temp(struct device *dev, |
| 623 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 625 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | struct adm1031_data *data = adm1031_update_device(dev); |
| 627 | int ext; |
| 628 | ext = nr == 0 ? |
| 629 | ((data->ext_temp[nr] >> 6) & 0x3) * 2 : |
| 630 | (((data->ext_temp[nr] >> ((nr - 1) * 3)) & 7)); |
| 631 | return sprintf(buf, "%d\n", TEMP_FROM_REG_EXT(data->temp[nr], ext)); |
| 632 | } |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 633 | static ssize_t show_temp_offset(struct device *dev, |
| 634 | struct device_attribute *attr, char *buf) |
| 635 | { |
| 636 | int nr = to_sensor_dev_attr(attr)->index; |
| 637 | struct adm1031_data *data = adm1031_update_device(dev); |
| 638 | return sprintf(buf, "%d\n", |
| 639 | TEMP_OFFSET_FROM_REG(data->temp_offset[nr])); |
| 640 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 641 | static ssize_t show_temp_min(struct device *dev, |
| 642 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 644 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | struct adm1031_data *data = adm1031_update_device(dev); |
| 646 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr])); |
| 647 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 648 | static ssize_t show_temp_max(struct device *dev, |
| 649 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 651 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | struct adm1031_data *data = adm1031_update_device(dev); |
| 653 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr])); |
| 654 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 655 | static ssize_t show_temp_crit(struct device *dev, |
| 656 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 658 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | struct adm1031_data *data = adm1031_update_device(dev); |
| 660 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[nr])); |
| 661 | } |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 662 | static ssize_t set_temp_offset(struct device *dev, |
| 663 | struct device_attribute *attr, const char *buf, |
| 664 | size_t count) |
| 665 | { |
| 666 | struct i2c_client *client = to_i2c_client(dev); |
| 667 | struct adm1031_data *data = i2c_get_clientdata(client); |
| 668 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 669 | long val; |
| 670 | int ret; |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 671 | |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 672 | ret = kstrtol(buf, 10, &val); |
| 673 | if (ret) |
| 674 | return ret; |
| 675 | |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 676 | val = SENSORS_LIMIT(val, -15000, 15000); |
| 677 | mutex_lock(&data->update_lock); |
| 678 | data->temp_offset[nr] = TEMP_OFFSET_TO_REG(val); |
| 679 | adm1031_write_value(client, ADM1031_REG_TEMP_OFFSET(nr), |
| 680 | data->temp_offset[nr]); |
| 681 | mutex_unlock(&data->update_lock); |
| 682 | return count; |
| 683 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 684 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, |
| 685 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | { |
| 687 | struct i2c_client *client = to_i2c_client(dev); |
| 688 | struct adm1031_data *data = i2c_get_clientdata(client); |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 689 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 690 | long val; |
| 691 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 693 | ret = kstrtol(buf, 10, &val); |
| 694 | if (ret) |
| 695 | return ret; |
| 696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 698 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | data->temp_min[nr] = TEMP_TO_REG(val); |
| 700 | adm1031_write_value(client, ADM1031_REG_TEMP_MIN(nr), |
| 701 | data->temp_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 702 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | return count; |
| 704 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 705 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
| 706 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | { |
| 708 | struct i2c_client *client = to_i2c_client(dev); |
| 709 | struct adm1031_data *data = i2c_get_clientdata(client); |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 710 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 711 | long val; |
| 712 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 714 | ret = kstrtol(buf, 10, &val); |
| 715 | if (ret) |
| 716 | return ret; |
| 717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 719 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | data->temp_max[nr] = TEMP_TO_REG(val); |
| 721 | adm1031_write_value(client, ADM1031_REG_TEMP_MAX(nr), |
| 722 | data->temp_max[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 723 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | return count; |
| 725 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 726 | static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, |
| 727 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | { |
| 729 | struct i2c_client *client = to_i2c_client(dev); |
| 730 | struct adm1031_data *data = i2c_get_clientdata(client); |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 731 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 732 | long val; |
| 733 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 735 | ret = kstrtol(buf, 10, &val); |
| 736 | if (ret) |
| 737 | return ret; |
| 738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 740 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | data->temp_crit[nr] = TEMP_TO_REG(val); |
| 742 | adm1031_write_value(client, ADM1031_REG_TEMP_CRIT(nr), |
| 743 | data->temp_crit[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 744 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | return count; |
| 746 | } |
| 747 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 748 | #define temp_reg(offset) \ |
| 749 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
| 750 | show_temp, NULL, offset - 1); \ |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 751 | static SENSOR_DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \ |
| 752 | show_temp_offset, set_temp_offset, offset - 1); \ |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 753 | static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ |
| 754 | show_temp_min, set_temp_min, offset - 1); \ |
| 755 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ |
| 756 | show_temp_max, set_temp_max, offset - 1); \ |
| 757 | static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \ |
| 758 | show_temp_crit, set_temp_crit, offset - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
| 760 | temp_reg(1); |
| 761 | temp_reg(2); |
| 762 | temp_reg(3); |
| 763 | |
| 764 | /* Alarms */ |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 765 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, |
| 766 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | { |
| 768 | struct adm1031_data *data = adm1031_update_device(dev); |
| 769 | return sprintf(buf, "%d\n", data->alarm); |
| 770 | } |
| 771 | |
| 772 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
| 773 | |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 774 | static ssize_t show_alarm(struct device *dev, |
| 775 | struct device_attribute *attr, char *buf) |
| 776 | { |
| 777 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 778 | struct adm1031_data *data = adm1031_update_device(dev); |
| 779 | return sprintf(buf, "%d\n", (data->alarm >> bitnr) & 1); |
| 780 | } |
| 781 | |
| 782 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0); |
| 783 | static SENSOR_DEVICE_ATTR(fan1_fault, S_IRUGO, show_alarm, NULL, 1); |
| 784 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 2); |
| 785 | static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); |
| 786 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 4); |
| 787 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 5); |
| 788 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); |
| 789 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 7); |
| 790 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 8); |
| 791 | static SENSOR_DEVICE_ATTR(fan2_fault, S_IRUGO, show_alarm, NULL, 9); |
| 792 | static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 10); |
| 793 | static SENSOR_DEVICE_ATTR(temp3_min_alarm, S_IRUGO, show_alarm, NULL, 11); |
| 794 | static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 12); |
| 795 | static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13); |
| 796 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 798 | /* Update Interval */ |
| 799 | static const unsigned int update_intervals[] = { |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 800 | 16000, 8000, 4000, 2000, 1000, 500, 250, 125, |
| 801 | }; |
| 802 | |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 803 | static ssize_t show_update_interval(struct device *dev, |
| 804 | struct device_attribute *attr, char *buf) |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 805 | { |
| 806 | struct i2c_client *client = to_i2c_client(dev); |
| 807 | struct adm1031_data *data = i2c_get_clientdata(client); |
| 808 | |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 809 | return sprintf(buf, "%u\n", data->update_interval); |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 810 | } |
| 811 | |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 812 | static ssize_t set_update_interval(struct device *dev, |
| 813 | struct device_attribute *attr, |
| 814 | const char *buf, size_t count) |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 815 | { |
| 816 | struct i2c_client *client = to_i2c_client(dev); |
| 817 | struct adm1031_data *data = i2c_get_clientdata(client); |
| 818 | unsigned long val; |
| 819 | int i, err; |
| 820 | u8 reg; |
| 821 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 822 | err = kstrtoul(buf, 10, &val); |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 823 | if (err) |
| 824 | return err; |
| 825 | |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 826 | /* |
| 827 | * Find the nearest update interval from the table. |
| 828 | * Use it to determine the matching update rate. |
| 829 | */ |
| 830 | for (i = 0; i < ARRAY_SIZE(update_intervals) - 1; i++) { |
| 831 | if (val >= update_intervals[i]) |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 832 | break; |
| 833 | } |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 834 | /* if not found, we point to the last entry (lowest update interval) */ |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 835 | |
| 836 | /* set the new update rate while preserving other settings */ |
| 837 | reg = adm1031_read_value(client, ADM1031_REG_FAN_FILTER); |
| 838 | reg &= ~ADM1031_UPDATE_RATE_MASK; |
| 839 | reg |= i << ADM1031_UPDATE_RATE_SHIFT; |
| 840 | adm1031_write_value(client, ADM1031_REG_FAN_FILTER, reg); |
| 841 | |
| 842 | mutex_lock(&data->update_lock); |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 843 | data->update_interval = update_intervals[i]; |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 844 | mutex_unlock(&data->update_lock); |
| 845 | |
| 846 | return count; |
| 847 | } |
| 848 | |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 849 | static DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, show_update_interval, |
| 850 | set_update_interval); |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 851 | |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 852 | static struct attribute *adm1031_attributes[] = { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 853 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 854 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
| 855 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 856 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
| 857 | &sensor_dev_attr_fan1_fault.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 858 | &sensor_dev_attr_pwm1.dev_attr.attr, |
| 859 | &sensor_dev_attr_auto_fan1_channel.dev_attr.attr, |
| 860 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 861 | &sensor_dev_attr_temp1_offset.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 862 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 863 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 864 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 865 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 866 | &sensor_dev_attr_temp1_crit.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 867 | &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 868 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 869 | &sensor_dev_attr_temp2_offset.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 870 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 871 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 872 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 873 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 874 | &sensor_dev_attr_temp2_crit.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 875 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, |
| 876 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 877 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 878 | &sensor_dev_attr_auto_temp1_off.dev_attr.attr, |
| 879 | &sensor_dev_attr_auto_temp1_min.dev_attr.attr, |
| 880 | &sensor_dev_attr_auto_temp1_max.dev_attr.attr, |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 881 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 882 | &sensor_dev_attr_auto_temp2_off.dev_attr.attr, |
| 883 | &sensor_dev_attr_auto_temp2_min.dev_attr.attr, |
| 884 | &sensor_dev_attr_auto_temp2_max.dev_attr.attr, |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 885 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 886 | &sensor_dev_attr_auto_fan1_min_pwm.dev_attr.attr, |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 887 | |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 888 | &dev_attr_update_interval.attr, |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 889 | &dev_attr_alarms.attr, |
| 890 | |
| 891 | NULL |
| 892 | }; |
| 893 | |
| 894 | static const struct attribute_group adm1031_group = { |
| 895 | .attrs = adm1031_attributes, |
| 896 | }; |
| 897 | |
| 898 | static struct attribute *adm1031_attributes_opt[] = { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 899 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
| 900 | &sensor_dev_attr_fan2_div.dev_attr.attr, |
| 901 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 902 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
| 903 | &sensor_dev_attr_fan2_fault.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 904 | &sensor_dev_attr_pwm2.dev_attr.attr, |
| 905 | &sensor_dev_attr_auto_fan2_channel.dev_attr.attr, |
| 906 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 907 | &sensor_dev_attr_temp3_offset.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 908 | &sensor_dev_attr_temp3_min.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 909 | &sensor_dev_attr_temp3_min_alarm.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 910 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 911 | &sensor_dev_attr_temp3_max_alarm.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 912 | &sensor_dev_attr_temp3_crit.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 913 | &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr, |
| 914 | &sensor_dev_attr_temp3_fault.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 915 | &sensor_dev_attr_auto_temp3_off.dev_attr.attr, |
| 916 | &sensor_dev_attr_auto_temp3_min.dev_attr.attr, |
| 917 | &sensor_dev_attr_auto_temp3_max.dev_attr.attr, |
| 918 | &sensor_dev_attr_auto_fan2_min_pwm.dev_attr.attr, |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 919 | NULL |
| 920 | }; |
| 921 | |
| 922 | static const struct attribute_group adm1031_group_opt = { |
| 923 | .attrs = adm1031_attributes_opt, |
| 924 | }; |
| 925 | |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 926 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 927 | static int adm1031_detect(struct i2c_client *client, |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 928 | struct i2c_board_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | { |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 930 | struct i2c_adapter *adapter = client->adapter; |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 931 | const char *name; |
| 932 | int id, co; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | |
| 934 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 935 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 937 | id = i2c_smbus_read_byte_data(client, 0x3d); |
| 938 | co = i2c_smbus_read_byte_data(client, 0x3e); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 940 | if (!((id == 0x31 || id == 0x30) && co == 0x41)) |
| 941 | return -ENODEV; |
| 942 | name = (id == 0x30) ? "adm1030" : "adm1031"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 944 | strlcpy(info->type, name, I2C_NAME_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 946 | return 0; |
| 947 | } |
| 948 | |
| 949 | static int adm1031_probe(struct i2c_client *client, |
| 950 | const struct i2c_device_id *id) |
| 951 | { |
| 952 | struct adm1031_data *data; |
| 953 | int err; |
| 954 | |
| 955 | data = kzalloc(sizeof(struct adm1031_data), GFP_KERNEL); |
| 956 | if (!data) { |
| 957 | err = -ENOMEM; |
| 958 | goto exit; |
| 959 | } |
| 960 | |
| 961 | i2c_set_clientdata(client, data); |
| 962 | data->chip_type = id->driver_data; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 963 | mutex_init(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 965 | if (data->chip_type == adm1030) |
| 966 | data->chan_select_table = &auto_channel_select_table_adm1030; |
| 967 | else |
| 968 | data->chan_select_table = &auto_channel_select_table_adm1031; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | |
| 970 | /* Initialize the ADM1031 chip */ |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 971 | adm1031_init_client(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | |
| 973 | /* Register sysfs hooks */ |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 974 | err = sysfs_create_group(&client->dev.kobj, &adm1031_group); |
| 975 | if (err) |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 976 | goto exit_free; |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 977 | |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 978 | if (data->chip_type == adm1031) { |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 979 | err = sysfs_create_group(&client->dev.kobj, &adm1031_group_opt); |
| 980 | if (err) |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 981 | goto exit_remove; |
| 982 | } |
| 983 | |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 984 | data->hwmon_dev = hwmon_device_register(&client->dev); |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 985 | if (IS_ERR(data->hwmon_dev)) { |
| 986 | err = PTR_ERR(data->hwmon_dev); |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 987 | goto exit_remove; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | return 0; |
| 991 | |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 992 | exit_remove: |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 993 | sysfs_remove_group(&client->dev.kobj, &adm1031_group); |
| 994 | sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | exit_free: |
Alexey Dobriyan | 1f57ff8 | 2005-08-26 01:49:14 +0400 | [diff] [blame] | 996 | kfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | exit: |
| 998 | return err; |
| 999 | } |
| 1000 | |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 1001 | static int adm1031_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | { |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1003 | struct adm1031_data *data = i2c_get_clientdata(client); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1004 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1005 | hwmon_device_unregister(data->hwmon_dev); |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 1006 | sysfs_remove_group(&client->dev.kobj, &adm1031_group); |
| 1007 | sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1008 | kfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | return 0; |
| 1010 | } |
| 1011 | |
| 1012 | static void adm1031_init_client(struct i2c_client *client) |
| 1013 | { |
| 1014 | unsigned int read_val; |
| 1015 | unsigned int mask; |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 1016 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | struct adm1031_data *data = i2c_get_clientdata(client); |
| 1018 | |
| 1019 | mask = (ADM1031_CONF2_PWM1_ENABLE | ADM1031_CONF2_TACH1_ENABLE); |
| 1020 | if (data->chip_type == adm1031) { |
| 1021 | mask |= (ADM1031_CONF2_PWM2_ENABLE | |
| 1022 | ADM1031_CONF2_TACH2_ENABLE); |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 1023 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | /* Initialize the ADM1031 chip (enables fan speed reading ) */ |
| 1025 | read_val = adm1031_read_value(client, ADM1031_REG_CONF2); |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1026 | if ((read_val | mask) != read_val) |
| 1027 | adm1031_write_value(client, ADM1031_REG_CONF2, read_val | mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | |
| 1029 | read_val = adm1031_read_value(client, ADM1031_REG_CONF1); |
| 1030 | if ((read_val | ADM1031_CONF1_MONITOR_ENABLE) != read_val) { |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1031 | adm1031_write_value(client, ADM1031_REG_CONF1, |
| 1032 | read_val | ADM1031_CONF1_MONITOR_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 1035 | /* Read the chip's update rate */ |
| 1036 | mask = ADM1031_UPDATE_RATE_MASK; |
| 1037 | read_val = adm1031_read_value(client, ADM1031_REG_FAN_FILTER); |
| 1038 | i = (read_val & mask) >> ADM1031_UPDATE_RATE_SHIFT; |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 1039 | /* Save it as update interval */ |
| 1040 | data->update_interval = update_intervals[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | static struct adm1031_data *adm1031_update_device(struct device *dev) |
| 1044 | { |
| 1045 | struct i2c_client *client = to_i2c_client(dev); |
| 1046 | struct adm1031_data *data = i2c_get_clientdata(client); |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 1047 | unsigned long next_update; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | int chan; |
| 1049 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1050 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 1052 | next_update = data->last_updated |
| 1053 | + msecs_to_jiffies(data->update_interval); |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 1054 | if (time_after(jiffies, next_update) || !data->valid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | |
| 1056 | dev_dbg(&client->dev, "Starting adm1031 update\n"); |
| 1057 | for (chan = 0; |
| 1058 | chan < ((data->chip_type == adm1031) ? 3 : 2); chan++) { |
| 1059 | u8 oldh, newh; |
| 1060 | |
| 1061 | oldh = |
| 1062 | adm1031_read_value(client, ADM1031_REG_TEMP(chan)); |
| 1063 | data->ext_temp[chan] = |
| 1064 | adm1031_read_value(client, ADM1031_REG_EXT_TEMP); |
| 1065 | newh = |
| 1066 | adm1031_read_value(client, ADM1031_REG_TEMP(chan)); |
| 1067 | if (newh != oldh) { |
| 1068 | data->ext_temp[chan] = |
| 1069 | adm1031_read_value(client, |
| 1070 | ADM1031_REG_EXT_TEMP); |
| 1071 | #ifdef DEBUG |
| 1072 | oldh = |
| 1073 | adm1031_read_value(client, |
| 1074 | ADM1031_REG_TEMP(chan)); |
| 1075 | |
| 1076 | /* oldh is actually newer */ |
| 1077 | if (newh != oldh) |
| 1078 | dev_warn(&client->dev, |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1079 | "Remote temperature may be wrong.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | #endif |
| 1081 | } |
| 1082 | data->temp[chan] = newh; |
| 1083 | |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 1084 | data->temp_offset[chan] = |
| 1085 | adm1031_read_value(client, |
| 1086 | ADM1031_REG_TEMP_OFFSET(chan)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | data->temp_min[chan] = |
| 1088 | adm1031_read_value(client, |
| 1089 | ADM1031_REG_TEMP_MIN(chan)); |
| 1090 | data->temp_max[chan] = |
| 1091 | adm1031_read_value(client, |
| 1092 | ADM1031_REG_TEMP_MAX(chan)); |
| 1093 | data->temp_crit[chan] = |
| 1094 | adm1031_read_value(client, |
| 1095 | ADM1031_REG_TEMP_CRIT(chan)); |
| 1096 | data->auto_temp[chan] = |
| 1097 | adm1031_read_value(client, |
| 1098 | ADM1031_REG_AUTO_TEMP(chan)); |
| 1099 | |
| 1100 | } |
| 1101 | |
| 1102 | data->conf1 = adm1031_read_value(client, ADM1031_REG_CONF1); |
| 1103 | data->conf2 = adm1031_read_value(client, ADM1031_REG_CONF2); |
| 1104 | |
| 1105 | data->alarm = adm1031_read_value(client, ADM1031_REG_STATUS(0)) |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1106 | | (adm1031_read_value(client, ADM1031_REG_STATUS(1)) << 8); |
| 1107 | if (data->chip_type == adm1030) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | data->alarm &= 0xc0ff; |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 1109 | |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1110 | for (chan = 0; chan < (data->chip_type == adm1030 ? 1 : 2); |
| 1111 | chan++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | data->fan_div[chan] = |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1113 | adm1031_read_value(client, |
| 1114 | ADM1031_REG_FAN_DIV(chan)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | data->fan_min[chan] = |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1116 | adm1031_read_value(client, |
| 1117 | ADM1031_REG_FAN_MIN(chan)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | data->fan[chan] = |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1119 | adm1031_read_value(client, |
| 1120 | ADM1031_REG_FAN_SPEED(chan)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | data->pwm[chan] = |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1122 | (adm1031_read_value(client, |
| 1123 | ADM1031_REG_PWM) >> (4 * chan)) & 0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | } |
| 1125 | data->last_updated = jiffies; |
| 1126 | data->valid = 1; |
| 1127 | } |
| 1128 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1129 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | |
| 1131 | return data; |
| 1132 | } |
| 1133 | |
| 1134 | static int __init sensors_adm1031_init(void) |
| 1135 | { |
| 1136 | return i2c_add_driver(&adm1031_driver); |
| 1137 | } |
| 1138 | |
| 1139 | static void __exit sensors_adm1031_exit(void) |
| 1140 | { |
| 1141 | i2c_del_driver(&adm1031_driver); |
| 1142 | } |
| 1143 | |
| 1144 | MODULE_AUTHOR("Alexandre d'Alton <alex@alexdalton.org>"); |
| 1145 | MODULE_DESCRIPTION("ADM1031/ADM1030 driver"); |
| 1146 | MODULE_LICENSE("GPL"); |
| 1147 | |
| 1148 | module_init(sensors_adm1031_init); |
| 1149 | module_exit(sensors_adm1031_exit); |