Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * lm63.c - driver for the National Semiconductor LM63 temperature sensor |
| 3 | * with integrated fan control |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 4 | * Copyright (C) 2004-2008 Jean Delvare <khali@linux-fr.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Based on the lm90 driver. |
| 6 | * |
| 7 | * The LM63 is a sensor chip made by National Semiconductor. It measures |
| 8 | * two temperatures (its own and one external one) and the speed of one |
| 9 | * fan, those speed it can additionally control. Complete datasheet can be |
| 10 | * obtained from National's website at: |
| 11 | * http://www.national.com/pf/LM/LM63.html |
| 12 | * |
| 13 | * The LM63 is basically an LM86 with fan speed monitoring and control |
| 14 | * capabilities added. It misses some of the LM86 features though: |
| 15 | * - No low limit for local temperature. |
| 16 | * - No critical limit for local temperature. |
| 17 | * - Critical limit for remote temperature can be changed only once. We |
| 18 | * will consider that the critical limit is read-only. |
| 19 | * |
| 20 | * The datasheet isn't very clear about what the tachometer reading is. |
| 21 | * I had a explanation from National Semiconductor though. The two lower |
| 22 | * bits of the read value have to be masked out. The value is still 16 bit |
| 23 | * in width. |
| 24 | * |
| 25 | * This program is free software; you can redistribute it and/or modify |
| 26 | * it under the terms of the GNU General Public License as published by |
| 27 | * the Free Software Foundation; either version 2 of the License, or |
| 28 | * (at your option) any later version. |
| 29 | * |
| 30 | * This program is distributed in the hope that it will be useful, |
| 31 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 33 | * GNU General Public License for more details. |
| 34 | * |
| 35 | * You should have received a copy of the GNU General Public License |
| 36 | * along with this program; if not, write to the Free Software |
| 37 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 38 | */ |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/module.h> |
| 41 | #include <linux/init.h> |
| 42 | #include <linux/slab.h> |
| 43 | #include <linux/jiffies.h> |
| 44 | #include <linux/i2c.h> |
Jean Delvare | 10c08f8 | 2005-06-06 19:34:45 +0200 | [diff] [blame] | 45 | #include <linux/hwmon-sysfs.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 46 | #include <linux/hwmon.h> |
| 47 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 48 | #include <linux/mutex.h> |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 49 | #include <linux/sysfs.h> |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 50 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * Addresses to scan |
| 54 | * Address is fully defined internally and cannot be changed. |
| 55 | */ |
| 56 | |
Matthew Garrett | 10f2ed3 | 2010-05-27 19:58:38 +0200 | [diff] [blame] | 57 | static const unsigned short normal_i2c[] = { 0x18, 0x4c, 0x4e, I2C_CLIENT_END }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | * The LM63 registers |
| 61 | */ |
| 62 | |
| 63 | #define LM63_REG_CONFIG1 0x03 |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 64 | #define LM63_REG_CONVRATE 0x04 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #define LM63_REG_CONFIG2 0xBF |
| 66 | #define LM63_REG_CONFIG_FAN 0x4A |
| 67 | |
| 68 | #define LM63_REG_TACH_COUNT_MSB 0x47 |
| 69 | #define LM63_REG_TACH_COUNT_LSB 0x46 |
| 70 | #define LM63_REG_TACH_LIMIT_MSB 0x49 |
| 71 | #define LM63_REG_TACH_LIMIT_LSB 0x48 |
| 72 | |
| 73 | #define LM63_REG_PWM_VALUE 0x4C |
| 74 | #define LM63_REG_PWM_FREQ 0x4D |
| 75 | |
| 76 | #define LM63_REG_LOCAL_TEMP 0x00 |
| 77 | #define LM63_REG_LOCAL_HIGH 0x05 |
| 78 | |
| 79 | #define LM63_REG_REMOTE_TEMP_MSB 0x01 |
| 80 | #define LM63_REG_REMOTE_TEMP_LSB 0x10 |
| 81 | #define LM63_REG_REMOTE_OFFSET_MSB 0x11 |
| 82 | #define LM63_REG_REMOTE_OFFSET_LSB 0x12 |
| 83 | #define LM63_REG_REMOTE_HIGH_MSB 0x07 |
| 84 | #define LM63_REG_REMOTE_HIGH_LSB 0x13 |
| 85 | #define LM63_REG_REMOTE_LOW_MSB 0x08 |
| 86 | #define LM63_REG_REMOTE_LOW_LSB 0x14 |
| 87 | #define LM63_REG_REMOTE_TCRIT 0x19 |
| 88 | #define LM63_REG_REMOTE_TCRIT_HYST 0x21 |
| 89 | |
| 90 | #define LM63_REG_ALERT_STATUS 0x02 |
| 91 | #define LM63_REG_ALERT_MASK 0x16 |
| 92 | |
| 93 | #define LM63_REG_MAN_ID 0xFE |
| 94 | #define LM63_REG_CHIP_ID 0xFF |
| 95 | |
Guenter Roeck | f496b2d | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 96 | #define LM96163_REG_TRUTHERM 0x30 |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 97 | #define LM96163_REG_REMOTE_TEMP_U_MSB 0x31 |
| 98 | #define LM96163_REG_REMOTE_TEMP_U_LSB 0x32 |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 99 | #define LM96163_REG_CONFIG_ENHANCED 0x45 |
| 100 | |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 101 | #define LM63_MAX_CONVRATE 9 |
| 102 | |
| 103 | #define LM63_MAX_CONVRATE_HZ 32 |
| 104 | #define LM96163_MAX_CONVRATE_HZ 26 |
| 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | /* |
| 107 | * Conversions and various macros |
| 108 | * For tachometer counts, the LM63 uses 16-bit values. |
| 109 | * For local temperature and high limit, remote critical limit and hysteresis |
Steven Cole | 44bbe87 | 2005-05-03 18:21:25 -0600 | [diff] [blame] | 110 | * value, it uses signed 8-bit values with LSB = 1 degree Celsius. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | * For remote temperature, low and high limits, it uses signed 11-bit values |
Steven Cole | 44bbe87 | 2005-05-03 18:21:25 -0600 | [diff] [blame] | 112 | * with LSB = 0.125 degree Celsius, left-justified in 16-bit registers. |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 113 | * For LM64 the actual remote diode temperature is 16 degree Celsius higher |
| 114 | * than the register reading. Remote temperature setpoints have to be |
| 115 | * adapted accordingly. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | */ |
| 117 | |
| 118 | #define FAN_FROM_REG(reg) ((reg) == 0xFFFC || (reg) == 0 ? 0 : \ |
| 119 | 5400000 / (reg)) |
| 120 | #define FAN_TO_REG(val) ((val) <= 82 ? 0xFFFC : \ |
| 121 | (5400000 / (val)) & 0xFFFC) |
| 122 | #define TEMP8_FROM_REG(reg) ((reg) * 1000) |
| 123 | #define TEMP8_TO_REG(val) ((val) <= -128000 ? -128 : \ |
| 124 | (val) >= 127000 ? 127 : \ |
| 125 | (val) < 0 ? ((val) - 500) / 1000 : \ |
| 126 | ((val) + 500) / 1000) |
Guenter Roeck | 94e55df4 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 127 | #define TEMP8U_TO_REG(val) ((val) <= 0 ? 0 : \ |
| 128 | (val) >= 255000 ? 255 : \ |
| 129 | ((val) + 500) / 1000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125) |
| 131 | #define TEMP11_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ |
| 132 | (val) >= 127875 ? 0x7FE0 : \ |
| 133 | (val) < 0 ? ((val) - 62) / 125 * 32 : \ |
| 134 | ((val) + 62) / 125 * 32) |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 135 | #define TEMP11U_TO_REG(val) ((val) <= 0 ? 0 : \ |
| 136 | (val) >= 255875 ? 0xFFE0 : \ |
| 137 | ((val) + 62) / 125 * 32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | #define HYST_TO_REG(val) ((val) <= 0 ? 0 : \ |
| 139 | (val) >= 127000 ? 127 : \ |
| 140 | ((val) + 500) / 1000) |
| 141 | |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 142 | #define UPDATE_INTERVAL(max, rate) \ |
| 143 | ((1000 << (LM63_MAX_CONVRATE - (rate))) / (max)) |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | /* |
| 146 | * Functions declaration |
| 147 | */ |
| 148 | |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 149 | static int lm63_probe(struct i2c_client *client, |
| 150 | const struct i2c_device_id *id); |
| 151 | static int lm63_remove(struct i2c_client *client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | static struct lm63_data *lm63_update_device(struct device *dev); |
| 154 | |
Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 155 | static int lm63_detect(struct i2c_client *client, struct i2c_board_info *info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | static void lm63_init_client(struct i2c_client *client); |
| 157 | |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 158 | enum chips { lm63, lm64, lm96163 }; |
Matthew Garrett | 10f2ed3 | 2010-05-27 19:58:38 +0200 | [diff] [blame] | 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | /* |
| 161 | * Driver data (common to all clients) |
| 162 | */ |
| 163 | |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 164 | static const struct i2c_device_id lm63_id[] = { |
Matthew Garrett | 10f2ed3 | 2010-05-27 19:58:38 +0200 | [diff] [blame] | 165 | { "lm63", lm63 }, |
| 166 | { "lm64", lm64 }, |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 167 | { "lm96163", lm96163 }, |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 168 | { } |
| 169 | }; |
| 170 | MODULE_DEVICE_TABLE(i2c, lm63_id); |
| 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | static struct i2c_driver lm63_driver = { |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 173 | .class = I2C_CLASS_HWMON, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 174 | .driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 175 | .name = "lm63", |
| 176 | }, |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 177 | .probe = lm63_probe, |
| 178 | .remove = lm63_remove, |
| 179 | .id_table = lm63_id, |
| 180 | .detect = lm63_detect, |
Jean Delvare | c3813d6 | 2009-12-14 21:17:25 +0100 | [diff] [blame] | 181 | .address_list = normal_i2c, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | /* |
| 185 | * Client data (each client gets its own) |
| 186 | */ |
| 187 | |
| 188 | struct lm63_data { |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 189 | struct device *hwmon_dev; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 190 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | char valid; /* zero until following fields are valid */ |
| 192 | unsigned long last_updated; /* in jiffies */ |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 193 | enum chips kind; |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 194 | int temp2_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 196 | int update_interval; /* in milliseconds */ |
| 197 | int max_convrate_hz; |
| 198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | /* registers values */ |
| 200 | u8 config, config_fan; |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 201 | u16 fan[2]; /* 0: input |
| 202 | 1: low limit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | u8 pwm1_freq; |
| 204 | u8 pwm1_value; |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 205 | s8 temp8[3]; /* 0: local input |
| 206 | 1: local high limit |
| 207 | 2: remote critical limit */ |
Guenter Roeck | 786375f | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 208 | s16 temp11[4]; /* 0: remote input |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 209 | 1: remote low limit |
Guenter Roeck | 786375f | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 210 | 2: remote high limit |
| 211 | 3: remote offset */ |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 212 | u16 temp11u; /* remote input (unsigned) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | u8 temp2_crit_hyst; |
| 214 | u8 alarms; |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 215 | bool pwm_highres; |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 216 | bool remote_unsigned; /* true if unsigned remote upper limits */ |
Guenter Roeck | f496b2d | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 217 | bool trutherm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | }; |
| 219 | |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 220 | static inline int temp8_from_reg(struct lm63_data *data, int nr) |
| 221 | { |
| 222 | if (data->remote_unsigned) |
| 223 | return TEMP8_FROM_REG((u8)data->temp8[nr]); |
| 224 | return TEMP8_FROM_REG(data->temp8[nr]); |
| 225 | } |
| 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /* |
| 228 | * Sysfs callback functions and files |
| 229 | */ |
| 230 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 231 | static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, |
| 232 | char *buf) |
| 233 | { |
| 234 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 235 | struct lm63_data *data = lm63_update_device(dev); |
| 236 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 239 | static ssize_t set_fan(struct device *dev, struct device_attribute *dummy, |
| 240 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
| 242 | struct i2c_client *client = to_i2c_client(dev); |
| 243 | struct lm63_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 244 | unsigned long val; |
| 245 | int err; |
| 246 | |
| 247 | err = kstrtoul(buf, 10, &val); |
| 248 | if (err) |
| 249 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 251 | mutex_lock(&data->update_lock); |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 252 | data->fan[1] = FAN_TO_REG(val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB, |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 254 | data->fan[1] & 0xFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB, |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 256 | data->fan[1] >> 8); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 257 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | return count; |
| 259 | } |
| 260 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 261 | static ssize_t show_pwm1(struct device *dev, struct device_attribute *dummy, |
| 262 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | { |
| 264 | struct lm63_data *data = lm63_update_device(dev); |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 265 | int pwm; |
| 266 | |
| 267 | if (data->pwm_highres) |
| 268 | pwm = data->pwm1_value; |
| 269 | else |
| 270 | pwm = data->pwm1_value >= 2 * data->pwm1_freq ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | 255 : (data->pwm1_value * 255 + data->pwm1_freq) / |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 272 | (2 * data->pwm1_freq); |
| 273 | |
| 274 | return sprintf(buf, "%d\n", pwm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 277 | static ssize_t set_pwm1(struct device *dev, struct device_attribute *dummy, |
| 278 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | { |
| 280 | struct i2c_client *client = to_i2c_client(dev); |
| 281 | struct lm63_data *data = i2c_get_clientdata(client); |
| 282 | unsigned long val; |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 283 | int err; |
| 284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | if (!(data->config_fan & 0x20)) /* register is read-only */ |
| 286 | return -EPERM; |
| 287 | |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 288 | err = kstrtoul(buf, 10, &val); |
| 289 | if (err) |
| 290 | return err; |
| 291 | |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 292 | val = SENSORS_LIMIT(val, 0, 255); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 293 | mutex_lock(&data->update_lock); |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 294 | data->pwm1_value = data->pwm_highres ? val : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | (val * data->pwm1_freq * 2 + 127) / 255; |
| 296 | i2c_smbus_write_byte_data(client, LM63_REG_PWM_VALUE, data->pwm1_value); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 297 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | return count; |
| 299 | } |
| 300 | |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 301 | static ssize_t show_pwm1_enable(struct device *dev, |
| 302 | struct device_attribute *dummy, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
| 304 | struct lm63_data *data = lm63_update_device(dev); |
| 305 | return sprintf(buf, "%d\n", data->config_fan & 0x20 ? 1 : 2); |
| 306 | } |
| 307 | |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 308 | /* |
| 309 | * There are 8bit registers for both local(temp1) and remote(temp2) sensor. |
| 310 | * For remote sensor registers temp2_offset has to be considered, |
| 311 | * for local sensor it must not. |
| 312 | * So we need separate 8bit accessors for local and remote sensor. |
| 313 | */ |
| 314 | static ssize_t show_local_temp8(struct device *dev, |
| 315 | struct device_attribute *devattr, |
| 316 | char *buf) |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 317 | { |
| 318 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 319 | struct lm63_data *data = lm63_update_device(dev); |
| 320 | return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[attr->index])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 323 | static ssize_t show_remote_temp8(struct device *dev, |
| 324 | struct device_attribute *devattr, |
| 325 | char *buf) |
| 326 | { |
| 327 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 328 | struct lm63_data *data = lm63_update_device(dev); |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 329 | return sprintf(buf, "%d\n", temp8_from_reg(data, attr->index) |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 330 | + data->temp2_offset); |
| 331 | } |
| 332 | |
Guenter Roeck | 94e55df4 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 333 | static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, |
| 334 | const char *buf, size_t count) |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 335 | { |
Guenter Roeck | 94e55df4 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 336 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 337 | struct i2c_client *client = to_i2c_client(dev); |
| 338 | struct lm63_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 94e55df4 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 339 | int nr = attr->index; |
| 340 | int reg = nr == 2 ? LM63_REG_REMOTE_TCRIT : LM63_REG_LOCAL_HIGH; |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 341 | long val; |
| 342 | int err; |
Guenter Roeck | 94e55df4 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 343 | int temp; |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 344 | |
| 345 | err = kstrtol(buf, 10, &val); |
| 346 | if (err) |
| 347 | return err; |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 348 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 349 | mutex_lock(&data->update_lock); |
Guenter Roeck | 94e55df4 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 350 | if (nr == 2) { |
| 351 | if (data->remote_unsigned) |
| 352 | temp = TEMP8U_TO_REG(val - data->temp2_offset); |
| 353 | else |
| 354 | temp = TEMP8_TO_REG(val - data->temp2_offset); |
| 355 | } else { |
| 356 | temp = TEMP8_TO_REG(val); |
| 357 | } |
| 358 | data->temp8[nr] = temp; |
| 359 | i2c_smbus_write_byte_data(client, reg, temp); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 360 | mutex_unlock(&data->update_lock); |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 361 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 363 | |
| 364 | static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, |
| 365 | char *buf) |
| 366 | { |
| 367 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 368 | struct lm63_data *data = lm63_update_device(dev); |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 369 | int nr = attr->index; |
| 370 | int temp; |
| 371 | |
| 372 | if (!nr) { |
| 373 | /* |
| 374 | * Use unsigned temperature unless its value is zero. |
| 375 | * If it is zero, use signed temperature. |
| 376 | */ |
| 377 | if (data->temp11u) |
| 378 | temp = TEMP11_FROM_REG(data->temp11u); |
| 379 | else |
| 380 | temp = TEMP11_FROM_REG(data->temp11[nr]); |
| 381 | } else { |
| 382 | if (data->remote_unsigned && nr == 2) |
| 383 | temp = TEMP11_FROM_REG((u16)data->temp11[nr]); |
| 384 | else |
| 385 | temp = TEMP11_FROM_REG(data->temp11[nr]); |
| 386 | } |
| 387 | return sprintf(buf, "%d\n", temp + data->temp2_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | } |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 389 | |
| 390 | static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, |
| 391 | const char *buf, size_t count) |
| 392 | { |
Guenter Roeck | 786375f | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 393 | static const u8 reg[6] = { |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 394 | LM63_REG_REMOTE_LOW_MSB, |
| 395 | LM63_REG_REMOTE_LOW_LSB, |
| 396 | LM63_REG_REMOTE_HIGH_MSB, |
| 397 | LM63_REG_REMOTE_HIGH_LSB, |
Guenter Roeck | 786375f | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 398 | LM63_REG_REMOTE_OFFSET_MSB, |
| 399 | LM63_REG_REMOTE_OFFSET_LSB, |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 400 | }; |
| 401 | |
| 402 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 403 | struct i2c_client *client = to_i2c_client(dev); |
| 404 | struct lm63_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 405 | long val; |
| 406 | int err; |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 407 | int nr = attr->index; |
| 408 | |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 409 | err = kstrtol(buf, 10, &val); |
| 410 | if (err) |
| 411 | return err; |
| 412 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 413 | mutex_lock(&data->update_lock); |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 414 | if (data->remote_unsigned && nr == 2) |
| 415 | data->temp11[nr] = TEMP11U_TO_REG(val - data->temp2_offset); |
| 416 | else |
| 417 | data->temp11[nr] = TEMP11_TO_REG(val - data->temp2_offset); |
| 418 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 419 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], |
| 420 | data->temp11[nr] >> 8); |
| 421 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], |
| 422 | data->temp11[nr] & 0xff); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 423 | mutex_unlock(&data->update_lock); |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 424 | return count; |
| 425 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 427 | /* |
| 428 | * Hysteresis register holds a relative value, while we want to present |
| 429 | * an absolute to user-space |
| 430 | */ |
| 431 | static ssize_t show_temp2_crit_hyst(struct device *dev, |
| 432 | struct device_attribute *dummy, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | { |
| 434 | struct lm63_data *data = lm63_update_device(dev); |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 435 | return sprintf(buf, "%d\n", temp8_from_reg(data, 2) |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 436 | + data->temp2_offset |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | - TEMP8_FROM_REG(data->temp2_crit_hyst)); |
| 438 | } |
| 439 | |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 440 | /* |
| 441 | * And now the other way around, user-space provides an absolute |
| 442 | * hysteresis value and we have to store a relative one |
| 443 | */ |
| 444 | static ssize_t set_temp2_crit_hyst(struct device *dev, |
| 445 | struct device_attribute *dummy, |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 446 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | { |
| 448 | struct i2c_client *client = to_i2c_client(dev); |
| 449 | struct lm63_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 450 | long val; |
| 451 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | long hyst; |
| 453 | |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 454 | err = kstrtol(buf, 10, &val); |
| 455 | if (err) |
| 456 | return err; |
| 457 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 458 | mutex_lock(&data->update_lock); |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 459 | hyst = temp8_from_reg(data, 2) + data->temp2_offset - val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST, |
| 461 | HYST_TO_REG(hyst)); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 462 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | return count; |
| 464 | } |
| 465 | |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 466 | /* |
| 467 | * Set conversion rate. |
| 468 | * client->update_lock must be held when calling this function. |
| 469 | */ |
| 470 | static void lm63_set_convrate(struct i2c_client *client, struct lm63_data *data, |
| 471 | unsigned int interval) |
| 472 | { |
| 473 | int i; |
| 474 | unsigned int update_interval; |
| 475 | |
| 476 | /* Shift calculations to avoid rounding errors */ |
| 477 | interval <<= 6; |
| 478 | |
| 479 | /* find the nearest update rate */ |
| 480 | update_interval = (1 << (LM63_MAX_CONVRATE + 6)) * 1000 |
| 481 | / data->max_convrate_hz; |
| 482 | for (i = 0; i < LM63_MAX_CONVRATE; i++, update_interval >>= 1) |
| 483 | if (interval >= update_interval * 3 / 4) |
| 484 | break; |
| 485 | |
| 486 | i2c_smbus_write_byte_data(client, LM63_REG_CONVRATE, i); |
| 487 | data->update_interval = UPDATE_INTERVAL(data->max_convrate_hz, i); |
| 488 | } |
| 489 | |
| 490 | static ssize_t show_update_interval(struct device *dev, |
| 491 | struct device_attribute *attr, char *buf) |
| 492 | { |
| 493 | struct lm63_data *data = dev_get_drvdata(dev); |
| 494 | |
| 495 | return sprintf(buf, "%u\n", data->update_interval); |
| 496 | } |
| 497 | |
| 498 | static ssize_t set_update_interval(struct device *dev, |
| 499 | struct device_attribute *attr, |
| 500 | const char *buf, size_t count) |
| 501 | { |
| 502 | struct i2c_client *client = to_i2c_client(dev); |
| 503 | struct lm63_data *data = i2c_get_clientdata(client); |
| 504 | unsigned long val; |
| 505 | int err; |
| 506 | |
| 507 | err = kstrtoul(buf, 10, &val); |
| 508 | if (err) |
| 509 | return err; |
| 510 | |
| 511 | mutex_lock(&data->update_lock); |
| 512 | lm63_set_convrate(client, data, SENSORS_LIMIT(val, 0, 100000)); |
| 513 | mutex_unlock(&data->update_lock); |
| 514 | |
| 515 | return count; |
| 516 | } |
| 517 | |
Guenter Roeck | f496b2d | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 518 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, |
| 519 | char *buf) |
| 520 | { |
| 521 | struct i2c_client *client = to_i2c_client(dev); |
| 522 | struct lm63_data *data = i2c_get_clientdata(client); |
| 523 | |
| 524 | return sprintf(buf, data->trutherm ? "1\n" : "2\n"); |
| 525 | } |
| 526 | |
| 527 | static ssize_t set_type(struct device *dev, struct device_attribute *attr, |
| 528 | const char *buf, size_t count) |
| 529 | { |
| 530 | struct i2c_client *client = to_i2c_client(dev); |
| 531 | struct lm63_data *data = i2c_get_clientdata(client); |
| 532 | unsigned long val; |
| 533 | int ret; |
| 534 | u8 reg; |
| 535 | |
| 536 | ret = kstrtoul(buf, 10, &val); |
| 537 | if (ret < 0) |
| 538 | return ret; |
| 539 | if (val != 1 && val != 2) |
| 540 | return -EINVAL; |
| 541 | |
| 542 | mutex_lock(&data->update_lock); |
| 543 | data->trutherm = val == 1; |
| 544 | reg = i2c_smbus_read_byte_data(client, LM96163_REG_TRUTHERM) & ~0x02; |
| 545 | i2c_smbus_write_byte_data(client, LM96163_REG_TRUTHERM, |
| 546 | reg | (data->trutherm ? 0x02 : 0x00)); |
| 547 | data->valid = 0; |
| 548 | mutex_unlock(&data->update_lock); |
| 549 | |
| 550 | return count; |
| 551 | } |
| 552 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 553 | static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy, |
| 554 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | { |
| 556 | struct lm63_data *data = lm63_update_device(dev); |
| 557 | return sprintf(buf, "%u\n", data->alarms); |
| 558 | } |
| 559 | |
Jean Delvare | 2d45771 | 2006-09-24 20:52:15 +0200 | [diff] [blame] | 560 | static ssize_t show_alarm(struct device *dev, struct device_attribute *devattr, |
| 561 | char *buf) |
| 562 | { |
| 563 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 564 | struct lm63_data *data = lm63_update_device(dev); |
| 565 | int bitnr = attr->index; |
| 566 | |
| 567 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); |
| 568 | } |
| 569 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 570 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); |
| 571 | static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan, |
| 572 | set_fan, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | |
| 574 | static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm1, set_pwm1); |
| 575 | static DEVICE_ATTR(pwm1_enable, S_IRUGO, show_pwm1_enable, NULL); |
| 576 | |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 577 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_local_temp8, NULL, 0); |
| 578 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_local_temp8, |
Guenter Roeck | 94e55df4 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 579 | set_temp8, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 581 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0); |
| 582 | static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11, |
| 583 | set_temp11, 1); |
| 584 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11, |
| 585 | set_temp11, 2); |
Guenter Roeck | 786375f | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 586 | static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_temp11, |
| 587 | set_temp11, 3); |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 588 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_remote_temp8, |
Guenter Roeck | 94e55df4 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 589 | set_temp8, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst, |
| 591 | set_temp2_crit_hyst); |
| 592 | |
Guenter Roeck | f496b2d | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 593 | static DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, set_type); |
| 594 | |
Jean Delvare | 2d45771 | 2006-09-24 20:52:15 +0200 | [diff] [blame] | 595 | /* Individual alarm files */ |
| 596 | static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0); |
| 597 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1); |
Jean Delvare | 7817a39 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 598 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); |
Jean Delvare | 2d45771 | 2006-09-24 20:52:15 +0200 | [diff] [blame] | 599 | static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); |
| 600 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); |
| 601 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); |
| 602 | /* Raw alarm file for compatibility */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
| 604 | |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 605 | static DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, show_update_interval, |
| 606 | set_update_interval); |
| 607 | |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 608 | static struct attribute *lm63_attributes[] = { |
| 609 | &dev_attr_pwm1.attr, |
| 610 | &dev_attr_pwm1_enable.attr, |
| 611 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 612 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| 613 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
| 614 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 615 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
Guenter Roeck | 786375f | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 616 | &sensor_dev_attr_temp2_offset.dev_attr.attr, |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 617 | &sensor_dev_attr_temp2_crit.dev_attr.attr, |
| 618 | &dev_attr_temp2_crit_hyst.attr, |
| 619 | |
| 620 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, |
Jean Delvare | 7817a39 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 621 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 622 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, |
| 623 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, |
| 624 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, |
| 625 | &dev_attr_alarms.attr, |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 626 | &dev_attr_update_interval.attr, |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 627 | NULL |
| 628 | }; |
| 629 | |
Guenter Roeck | 94e55df4 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 630 | /* |
| 631 | * On LM63, temp2_crit can be set only once, which should be job |
| 632 | * of the bootloader. |
| 633 | * On LM64, temp2_crit can always be set. |
| 634 | * On LM96163, temp2_crit can be set if bit 1 of the configuration |
| 635 | * register is true. |
| 636 | */ |
| 637 | static umode_t lm63_attribute_mode(struct kobject *kobj, |
| 638 | struct attribute *attr, int index) |
| 639 | { |
| 640 | struct device *dev = container_of(kobj, struct device, kobj); |
| 641 | struct i2c_client *client = to_i2c_client(dev); |
| 642 | struct lm63_data *data = i2c_get_clientdata(client); |
| 643 | |
| 644 | if (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr |
| 645 | && (data->kind == lm64 || |
| 646 | (data->kind == lm96163 && (data->config & 0x02)))) |
| 647 | return attr->mode | S_IWUSR; |
| 648 | |
| 649 | return attr->mode; |
| 650 | } |
| 651 | |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 652 | static const struct attribute_group lm63_group = { |
Guenter Roeck | 94e55df4 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 653 | .is_visible = lm63_attribute_mode, |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 654 | .attrs = lm63_attributes, |
| 655 | }; |
| 656 | |
| 657 | static struct attribute *lm63_attributes_fan1[] = { |
| 658 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 659 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
| 660 | |
| 661 | &sensor_dev_attr_fan1_min_alarm.dev_attr.attr, |
| 662 | NULL |
| 663 | }; |
| 664 | |
| 665 | static const struct attribute_group lm63_group_fan1 = { |
| 666 | .attrs = lm63_attributes_fan1, |
| 667 | }; |
| 668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | /* |
| 670 | * Real code |
| 671 | */ |
| 672 | |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 673 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 674 | static int lm63_detect(struct i2c_client *new_client, |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 675 | struct i2c_board_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | { |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 677 | struct i2c_adapter *adapter = new_client->adapter; |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 678 | u8 man_id, chip_id, reg_config1, reg_config2; |
| 679 | u8 reg_alert_status, reg_alert_mask; |
Matthew Garrett | 10f2ed3 | 2010-05-27 19:58:38 +0200 | [diff] [blame] | 680 | int address = new_client->addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
| 682 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 683 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 685 | man_id = i2c_smbus_read_byte_data(new_client, LM63_REG_MAN_ID); |
| 686 | chip_id = i2c_smbus_read_byte_data(new_client, LM63_REG_CHIP_ID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 688 | reg_config1 = i2c_smbus_read_byte_data(new_client, |
| 689 | LM63_REG_CONFIG1); |
| 690 | reg_config2 = i2c_smbus_read_byte_data(new_client, |
| 691 | LM63_REG_CONFIG2); |
| 692 | reg_alert_status = i2c_smbus_read_byte_data(new_client, |
| 693 | LM63_REG_ALERT_STATUS); |
| 694 | reg_alert_mask = i2c_smbus_read_byte_data(new_client, |
| 695 | LM63_REG_ALERT_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 697 | if (man_id != 0x01 /* National Semiconductor */ |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 698 | || (reg_config1 & 0x18) != 0x00 |
| 699 | || (reg_config2 & 0xF8) != 0x00 |
| 700 | || (reg_alert_status & 0x20) != 0x00 |
| 701 | || (reg_alert_mask & 0xA4) != 0xA4) { |
| 702 | dev_dbg(&adapter->dev, |
| 703 | "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n", |
| 704 | man_id, chip_id); |
| 705 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Matthew Garrett | 10f2ed3 | 2010-05-27 19:58:38 +0200 | [diff] [blame] | 708 | if (chip_id == 0x41 && address == 0x4c) |
| 709 | strlcpy(info->type, "lm63", I2C_NAME_SIZE); |
| 710 | else if (chip_id == 0x51 && (address == 0x18 || address == 0x4e)) |
| 711 | strlcpy(info->type, "lm64", I2C_NAME_SIZE); |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 712 | else if (chip_id == 0x49 && address == 0x4c) |
| 713 | strlcpy(info->type, "lm96163", I2C_NAME_SIZE); |
Matthew Garrett | 10f2ed3 | 2010-05-27 19:58:38 +0200 | [diff] [blame] | 714 | else |
| 715 | return -ENODEV; |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 716 | |
| 717 | return 0; |
| 718 | } |
| 719 | |
| 720 | static int lm63_probe(struct i2c_client *new_client, |
| 721 | const struct i2c_device_id *id) |
| 722 | { |
| 723 | struct lm63_data *data; |
| 724 | int err; |
| 725 | |
| 726 | data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL); |
| 727 | if (!data) { |
| 728 | err = -ENOMEM; |
| 729 | goto exit; |
| 730 | } |
| 731 | |
| 732 | i2c_set_clientdata(new_client, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | data->valid = 0; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 734 | mutex_init(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 736 | /* Set the device type */ |
| 737 | data->kind = id->driver_data; |
| 738 | if (data->kind == lm64) |
| 739 | data->temp2_offset = 16000; |
| 740 | |
| 741 | /* Initialize chip */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | lm63_init_client(new_client); |
| 743 | |
| 744 | /* Register sysfs hooks */ |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 745 | err = sysfs_create_group(&new_client->dev.kobj, &lm63_group); |
| 746 | if (err) |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 747 | goto exit_free; |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 748 | if (data->config & 0x04) { /* tachometer enabled */ |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 749 | err = sysfs_create_group(&new_client->dev.kobj, |
| 750 | &lm63_group_fan1); |
| 751 | if (err) |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 752 | goto exit_remove_files; |
| 753 | } |
Guenter Roeck | f496b2d | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 754 | if (data->kind == lm96163) { |
| 755 | err = device_create_file(&new_client->dev, |
| 756 | &dev_attr_temp2_type); |
| 757 | if (err) |
| 758 | goto exit_remove_files; |
| 759 | } |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 760 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 761 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
| 762 | if (IS_ERR(data->hwmon_dev)) { |
| 763 | err = PTR_ERR(data->hwmon_dev); |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 764 | goto exit_remove_files; |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 765 | } |
| 766 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | return 0; |
| 768 | |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 769 | exit_remove_files: |
Guenter Roeck | f496b2d | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 770 | device_remove_file(&new_client->dev, &dev_attr_temp2_type); |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 771 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group); |
| 772 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | exit_free: |
| 774 | kfree(data); |
| 775 | exit: |
| 776 | return err; |
| 777 | } |
| 778 | |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 779 | /* |
| 780 | * Ideally we shouldn't have to initialize anything, since the BIOS |
| 781 | * should have taken care of everything |
| 782 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | static void lm63_init_client(struct i2c_client *client) |
| 784 | { |
| 785 | struct lm63_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 786 | u8 convrate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
| 788 | data->config = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1); |
| 789 | data->config_fan = i2c_smbus_read_byte_data(client, |
| 790 | LM63_REG_CONFIG_FAN); |
| 791 | |
| 792 | /* Start converting if needed */ |
| 793 | if (data->config & 0x40) { /* standby */ |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 794 | dev_dbg(&client->dev, "Switching to operational mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | data->config &= 0xA7; |
| 796 | i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1, |
| 797 | data->config); |
| 798 | } |
Jean Delvare | 409c0b5 | 2012-01-16 22:51:46 +0100 | [diff] [blame^] | 799 | /* Tachometer is always enabled on LM64 */ |
| 800 | if (data->kind == lm64) |
| 801 | data->config |= 0x04; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | |
| 803 | /* We may need pwm1_freq before ever updating the client data */ |
| 804 | data->pwm1_freq = i2c_smbus_read_byte_data(client, LM63_REG_PWM_FREQ); |
| 805 | if (data->pwm1_freq == 0) |
| 806 | data->pwm1_freq = 1; |
| 807 | |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 808 | switch (data->kind) { |
| 809 | case lm63: |
| 810 | case lm64: |
| 811 | data->max_convrate_hz = LM63_MAX_CONVRATE_HZ; |
| 812 | break; |
| 813 | case lm96163: |
| 814 | data->max_convrate_hz = LM96163_MAX_CONVRATE_HZ; |
Guenter Roeck | f496b2d | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 815 | data->trutherm |
| 816 | = i2c_smbus_read_byte_data(client, |
| 817 | LM96163_REG_TRUTHERM) & 0x02; |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 818 | break; |
| 819 | } |
| 820 | convrate = i2c_smbus_read_byte_data(client, LM63_REG_CONVRATE); |
| 821 | if (unlikely(convrate > LM63_MAX_CONVRATE)) |
| 822 | convrate = LM63_MAX_CONVRATE; |
| 823 | data->update_interval = UPDATE_INTERVAL(data->max_convrate_hz, |
| 824 | convrate); |
| 825 | |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 826 | /* |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 827 | * For LM96163, check if high resolution PWM |
| 828 | * and unsigned temperature format is enabled. |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 829 | */ |
| 830 | if (data->kind == lm96163) { |
| 831 | u8 config_enhanced |
| 832 | = i2c_smbus_read_byte_data(client, |
| 833 | LM96163_REG_CONFIG_ENHANCED); |
| 834 | if ((config_enhanced & 0x10) |
| 835 | && !(data->config_fan & 0x08) && data->pwm1_freq == 8) |
| 836 | data->pwm_highres = true; |
| 837 | if (config_enhanced & 0x08) |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 838 | data->remote_unsigned = true; |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 839 | } |
| 840 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | /* Show some debug info about the LM63 configuration */ |
Jean Delvare | 409c0b5 | 2012-01-16 22:51:46 +0100 | [diff] [blame^] | 842 | if (data->kind == lm63) |
| 843 | dev_dbg(&client->dev, "Alert/tach pin configured for %s\n", |
| 844 | (data->config & 0x04) ? "tachometer input" : |
| 845 | "alert output"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | dev_dbg(&client->dev, "PWM clock %s kHz, output frequency %u Hz\n", |
| 847 | (data->config_fan & 0x08) ? "1.4" : "360", |
| 848 | ((data->config_fan & 0x08) ? 700 : 180000) / data->pwm1_freq); |
| 849 | dev_dbg(&client->dev, "PWM output active %s, %s mode\n", |
| 850 | (data->config_fan & 0x10) ? "low" : "high", |
| 851 | (data->config_fan & 0x20) ? "manual" : "auto"); |
| 852 | } |
| 853 | |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 854 | static int lm63_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | { |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 856 | struct lm63_data *data = i2c_get_clientdata(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 858 | hwmon_device_unregister(data->hwmon_dev); |
Guenter Roeck | f496b2d | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 859 | device_remove_file(&client->dev, &dev_attr_temp2_type); |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 860 | sysfs_remove_group(&client->dev.kobj, &lm63_group); |
| 861 | sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 862 | |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 863 | kfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | return 0; |
| 865 | } |
| 866 | |
| 867 | static struct lm63_data *lm63_update_device(struct device *dev) |
| 868 | { |
| 869 | struct i2c_client *client = to_i2c_client(dev); |
| 870 | struct lm63_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 871 | unsigned long next_update; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 873 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 875 | next_update = data->last_updated |
| 876 | + msecs_to_jiffies(data->update_interval) + 1; |
| 877 | |
| 878 | if (time_after(jiffies, next_update) || !data->valid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | if (data->config & 0x04) { /* tachometer enabled */ |
| 880 | /* order matters for fan1_input */ |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 881 | data->fan[0] = i2c_smbus_read_byte_data(client, |
| 882 | LM63_REG_TACH_COUNT_LSB) & 0xFC; |
| 883 | data->fan[0] |= i2c_smbus_read_byte_data(client, |
| 884 | LM63_REG_TACH_COUNT_MSB) << 8; |
| 885 | data->fan[1] = (i2c_smbus_read_byte_data(client, |
| 886 | LM63_REG_TACH_LIMIT_LSB) & 0xFC) |
| 887 | | (i2c_smbus_read_byte_data(client, |
| 888 | LM63_REG_TACH_LIMIT_MSB) << 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | data->pwm1_freq = i2c_smbus_read_byte_data(client, |
| 892 | LM63_REG_PWM_FREQ); |
| 893 | if (data->pwm1_freq == 0) |
| 894 | data->pwm1_freq = 1; |
| 895 | data->pwm1_value = i2c_smbus_read_byte_data(client, |
| 896 | LM63_REG_PWM_VALUE); |
| 897 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 898 | data->temp8[0] = i2c_smbus_read_byte_data(client, |
| 899 | LM63_REG_LOCAL_TEMP); |
| 900 | data->temp8[1] = i2c_smbus_read_byte_data(client, |
| 901 | LM63_REG_LOCAL_HIGH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | |
| 903 | /* order matters for temp2_input */ |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 904 | data->temp11[0] = i2c_smbus_read_byte_data(client, |
| 905 | LM63_REG_REMOTE_TEMP_MSB) << 8; |
| 906 | data->temp11[0] |= i2c_smbus_read_byte_data(client, |
| 907 | LM63_REG_REMOTE_TEMP_LSB); |
| 908 | data->temp11[1] = (i2c_smbus_read_byte_data(client, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | LM63_REG_REMOTE_LOW_MSB) << 8) |
| 910 | | i2c_smbus_read_byte_data(client, |
| 911 | LM63_REG_REMOTE_LOW_LSB); |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 912 | data->temp11[2] = (i2c_smbus_read_byte_data(client, |
| 913 | LM63_REG_REMOTE_HIGH_MSB) << 8) |
| 914 | | i2c_smbus_read_byte_data(client, |
| 915 | LM63_REG_REMOTE_HIGH_LSB); |
Guenter Roeck | 786375f | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 916 | data->temp11[3] = (i2c_smbus_read_byte_data(client, |
| 917 | LM63_REG_REMOTE_OFFSET_MSB) << 8) |
| 918 | | i2c_smbus_read_byte_data(client, |
| 919 | LM63_REG_REMOTE_OFFSET_LSB); |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 920 | |
| 921 | if (data->kind == lm96163) |
| 922 | data->temp11u = (i2c_smbus_read_byte_data(client, |
| 923 | LM96163_REG_REMOTE_TEMP_U_MSB) << 8) |
| 924 | | i2c_smbus_read_byte_data(client, |
| 925 | LM96163_REG_REMOTE_TEMP_U_LSB); |
| 926 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 927 | data->temp8[2] = i2c_smbus_read_byte_data(client, |
| 928 | LM63_REG_REMOTE_TCRIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | data->temp2_crit_hyst = i2c_smbus_read_byte_data(client, |
| 930 | LM63_REG_REMOTE_TCRIT_HYST); |
| 931 | |
| 932 | data->alarms = i2c_smbus_read_byte_data(client, |
| 933 | LM63_REG_ALERT_STATUS) & 0x7F; |
| 934 | |
| 935 | data->last_updated = jiffies; |
| 936 | data->valid = 1; |
| 937 | } |
| 938 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 939 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | |
| 941 | return data; |
| 942 | } |
| 943 | |
| 944 | static int __init sensors_lm63_init(void) |
| 945 | { |
| 946 | return i2c_add_driver(&lm63_driver); |
| 947 | } |
| 948 | |
| 949 | static void __exit sensors_lm63_exit(void) |
| 950 | { |
| 951 | i2c_del_driver(&lm63_driver); |
| 952 | } |
| 953 | |
| 954 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); |
| 955 | MODULE_DESCRIPTION("LM63 driver"); |
| 956 | MODULE_LICENSE("GPL"); |
| 957 | |
| 958 | module_init(sensors_lm63_init); |
| 959 | module_exit(sensors_lm63_exit); |