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