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