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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * Addresses to scan |
| 53 | * Address is fully defined internally and cannot be changed. |
| 54 | */ |
| 55 | |
Matthew Garrett | 10f2ed3 | 2010-05-27 19:58:38 +0200 | [diff] [blame] | 56 | static const unsigned short normal_i2c[] = { 0x18, 0x4c, 0x4e, I2C_CLIENT_END }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | * The LM63 registers |
| 60 | */ |
| 61 | |
| 62 | #define LM63_REG_CONFIG1 0x03 |
| 63 | #define LM63_REG_CONFIG2 0xBF |
| 64 | #define LM63_REG_CONFIG_FAN 0x4A |
| 65 | |
| 66 | #define LM63_REG_TACH_COUNT_MSB 0x47 |
| 67 | #define LM63_REG_TACH_COUNT_LSB 0x46 |
| 68 | #define LM63_REG_TACH_LIMIT_MSB 0x49 |
| 69 | #define LM63_REG_TACH_LIMIT_LSB 0x48 |
| 70 | |
| 71 | #define LM63_REG_PWM_VALUE 0x4C |
| 72 | #define LM63_REG_PWM_FREQ 0x4D |
| 73 | |
| 74 | #define LM63_REG_LOCAL_TEMP 0x00 |
| 75 | #define LM63_REG_LOCAL_HIGH 0x05 |
| 76 | |
| 77 | #define LM63_REG_REMOTE_TEMP_MSB 0x01 |
| 78 | #define LM63_REG_REMOTE_TEMP_LSB 0x10 |
| 79 | #define LM63_REG_REMOTE_OFFSET_MSB 0x11 |
| 80 | #define LM63_REG_REMOTE_OFFSET_LSB 0x12 |
| 81 | #define LM63_REG_REMOTE_HIGH_MSB 0x07 |
| 82 | #define LM63_REG_REMOTE_HIGH_LSB 0x13 |
| 83 | #define LM63_REG_REMOTE_LOW_MSB 0x08 |
| 84 | #define LM63_REG_REMOTE_LOW_LSB 0x14 |
| 85 | #define LM63_REG_REMOTE_TCRIT 0x19 |
| 86 | #define LM63_REG_REMOTE_TCRIT_HYST 0x21 |
| 87 | |
| 88 | #define LM63_REG_ALERT_STATUS 0x02 |
| 89 | #define LM63_REG_ALERT_MASK 0x16 |
| 90 | |
| 91 | #define LM63_REG_MAN_ID 0xFE |
| 92 | #define LM63_REG_CHIP_ID 0xFF |
| 93 | |
| 94 | /* |
| 95 | * Conversions and various macros |
| 96 | * For tachometer counts, the LM63 uses 16-bit values. |
| 97 | * For local temperature and high limit, remote critical limit and hysteresis |
Steven Cole | 44bbe87 | 2005-05-03 18:21:25 -0600 | [diff] [blame] | 98 | * value, it uses signed 8-bit values with LSB = 1 degree Celsius. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | * 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] | 100 | * with LSB = 0.125 degree Celsius, left-justified in 16-bit registers. |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 101 | * For LM64 the actual remote diode temperature is 16 degree Celsius higher |
| 102 | * than the register reading. Remote temperature setpoints have to be |
| 103 | * adapted accordingly. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | */ |
| 105 | |
| 106 | #define FAN_FROM_REG(reg) ((reg) == 0xFFFC || (reg) == 0 ? 0 : \ |
| 107 | 5400000 / (reg)) |
| 108 | #define FAN_TO_REG(val) ((val) <= 82 ? 0xFFFC : \ |
| 109 | (5400000 / (val)) & 0xFFFC) |
| 110 | #define TEMP8_FROM_REG(reg) ((reg) * 1000) |
| 111 | #define TEMP8_TO_REG(val) ((val) <= -128000 ? -128 : \ |
| 112 | (val) >= 127000 ? 127 : \ |
| 113 | (val) < 0 ? ((val) - 500) / 1000 : \ |
| 114 | ((val) + 500) / 1000) |
| 115 | #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125) |
| 116 | #define TEMP11_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ |
| 117 | (val) >= 127875 ? 0x7FE0 : \ |
| 118 | (val) < 0 ? ((val) - 62) / 125 * 32 : \ |
| 119 | ((val) + 62) / 125 * 32) |
| 120 | #define HYST_TO_REG(val) ((val) <= 0 ? 0 : \ |
| 121 | (val) >= 127000 ? 127 : \ |
| 122 | ((val) + 500) / 1000) |
| 123 | |
| 124 | /* |
| 125 | * Functions declaration |
| 126 | */ |
| 127 | |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 128 | static int lm63_probe(struct i2c_client *client, |
| 129 | const struct i2c_device_id *id); |
| 130 | static int lm63_remove(struct i2c_client *client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | static struct lm63_data *lm63_update_device(struct device *dev); |
| 133 | |
Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 134 | 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] | 135 | static void lm63_init_client(struct i2c_client *client); |
| 136 | |
Matthew Garrett | 10f2ed3 | 2010-05-27 19:58:38 +0200 | [diff] [blame] | 137 | enum chips { lm63, lm64 }; |
| 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | /* |
| 140 | * Driver data (common to all clients) |
| 141 | */ |
| 142 | |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 143 | static const struct i2c_device_id lm63_id[] = { |
Matthew Garrett | 10f2ed3 | 2010-05-27 19:58:38 +0200 | [diff] [blame] | 144 | { "lm63", lm63 }, |
| 145 | { "lm64", lm64 }, |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 146 | { } |
| 147 | }; |
| 148 | MODULE_DEVICE_TABLE(i2c, lm63_id); |
| 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | static struct i2c_driver lm63_driver = { |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 151 | .class = I2C_CLASS_HWMON, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 152 | .driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 153 | .name = "lm63", |
| 154 | }, |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 155 | .probe = lm63_probe, |
| 156 | .remove = lm63_remove, |
| 157 | .id_table = lm63_id, |
| 158 | .detect = lm63_detect, |
Jean Delvare | c3813d6 | 2009-12-14 21:17:25 +0100 | [diff] [blame] | 159 | .address_list = normal_i2c, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | /* |
| 163 | * Client data (each client gets its own) |
| 164 | */ |
| 165 | |
| 166 | struct lm63_data { |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 167 | struct device *hwmon_dev; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 168 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | char valid; /* zero until following fields are valid */ |
| 170 | unsigned long last_updated; /* in jiffies */ |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 171 | int kind; |
| 172 | int temp2_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
| 174 | /* registers values */ |
| 175 | u8 config, config_fan; |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 176 | u16 fan[2]; /* 0: input |
| 177 | 1: low limit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | u8 pwm1_freq; |
| 179 | u8 pwm1_value; |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 180 | s8 temp8[3]; /* 0: local input |
| 181 | 1: local high limit |
| 182 | 2: remote critical limit */ |
| 183 | s16 temp11[3]; /* 0: remote input |
| 184 | 1: remote low limit |
| 185 | 2: remote high limit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | u8 temp2_crit_hyst; |
| 187 | u8 alarms; |
| 188 | }; |
| 189 | |
| 190 | /* |
| 191 | * Sysfs callback functions and files |
| 192 | */ |
| 193 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 194 | static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, |
| 195 | char *buf) |
| 196 | { |
| 197 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 198 | struct lm63_data *data = lm63_update_device(dev); |
| 199 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 202 | static ssize_t set_fan(struct device *dev, struct device_attribute *dummy, |
| 203 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | { |
| 205 | struct i2c_client *client = to_i2c_client(dev); |
| 206 | struct lm63_data *data = i2c_get_clientdata(client); |
| 207 | unsigned long val = simple_strtoul(buf, NULL, 10); |
| 208 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 209 | mutex_lock(&data->update_lock); |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 210 | data->fan[1] = FAN_TO_REG(val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB, |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 212 | data->fan[1] & 0xFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB, |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 214 | data->fan[1] >> 8); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 215 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | return count; |
| 217 | } |
| 218 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 219 | static ssize_t show_pwm1(struct device *dev, struct device_attribute *dummy, |
| 220 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | { |
| 222 | struct lm63_data *data = lm63_update_device(dev); |
| 223 | return sprintf(buf, "%d\n", data->pwm1_value >= 2 * data->pwm1_freq ? |
| 224 | 255 : (data->pwm1_value * 255 + data->pwm1_freq) / |
| 225 | (2 * data->pwm1_freq)); |
| 226 | } |
| 227 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 228 | static ssize_t set_pwm1(struct device *dev, struct device_attribute *dummy, |
| 229 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
| 231 | struct i2c_client *client = to_i2c_client(dev); |
| 232 | struct lm63_data *data = i2c_get_clientdata(client); |
| 233 | unsigned long val; |
| 234 | |
| 235 | if (!(data->config_fan & 0x20)) /* register is read-only */ |
| 236 | return -EPERM; |
| 237 | |
| 238 | val = simple_strtoul(buf, NULL, 10); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 239 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | data->pwm1_value = val <= 0 ? 0 : |
| 241 | val >= 255 ? 2 * data->pwm1_freq : |
| 242 | (val * data->pwm1_freq * 2 + 127) / 255; |
| 243 | 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] | 244 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | return count; |
| 246 | } |
| 247 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 248 | static ssize_t show_pwm1_enable(struct device *dev, struct device_attribute *dummy, |
| 249 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { |
| 251 | struct lm63_data *data = lm63_update_device(dev); |
| 252 | return sprintf(buf, "%d\n", data->config_fan & 0x20 ? 1 : 2); |
| 253 | } |
| 254 | |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 255 | /* |
| 256 | * There are 8bit registers for both local(temp1) and remote(temp2) sensor. |
| 257 | * For remote sensor registers temp2_offset has to be considered, |
| 258 | * for local sensor it must not. |
| 259 | * So we need separate 8bit accessors for local and remote sensor. |
| 260 | */ |
| 261 | static ssize_t show_local_temp8(struct device *dev, |
| 262 | struct device_attribute *devattr, |
| 263 | char *buf) |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 264 | { |
| 265 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 266 | struct lm63_data *data = lm63_update_device(dev); |
| 267 | return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[attr->index])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 270 | static ssize_t show_remote_temp8(struct device *dev, |
| 271 | struct device_attribute *devattr, |
| 272 | char *buf) |
| 273 | { |
| 274 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 275 | struct lm63_data *data = lm63_update_device(dev); |
| 276 | return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[attr->index]) |
| 277 | + data->temp2_offset); |
| 278 | } |
| 279 | |
| 280 | static ssize_t set_local_temp8(struct device *dev, |
| 281 | struct device_attribute *dummy, |
| 282 | const char *buf, size_t count) |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 283 | { |
| 284 | struct i2c_client *client = to_i2c_client(dev); |
| 285 | struct lm63_data *data = i2c_get_clientdata(client); |
| 286 | long val = simple_strtol(buf, NULL, 10); |
| 287 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 288 | mutex_lock(&data->update_lock); |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 289 | data->temp8[1] = TEMP8_TO_REG(val); |
| 290 | i2c_smbus_write_byte_data(client, LM63_REG_LOCAL_HIGH, data->temp8[1]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 291 | mutex_unlock(&data->update_lock); |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 292 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | } |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 294 | |
| 295 | static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, |
| 296 | char *buf) |
| 297 | { |
| 298 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 299 | struct lm63_data *data = lm63_update_device(dev); |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 300 | return sprintf(buf, "%d\n", TEMP11_FROM_REG(data->temp11[attr->index]) |
| 301 | + data->temp2_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | } |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 303 | |
| 304 | static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, |
| 305 | const char *buf, size_t count) |
| 306 | { |
| 307 | static const u8 reg[4] = { |
| 308 | LM63_REG_REMOTE_LOW_MSB, |
| 309 | LM63_REG_REMOTE_LOW_LSB, |
| 310 | LM63_REG_REMOTE_HIGH_MSB, |
| 311 | LM63_REG_REMOTE_HIGH_LSB, |
| 312 | }; |
| 313 | |
| 314 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 315 | struct i2c_client *client = to_i2c_client(dev); |
| 316 | struct lm63_data *data = i2c_get_clientdata(client); |
| 317 | long val = simple_strtol(buf, NULL, 10); |
| 318 | int nr = attr->index; |
| 319 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 320 | mutex_lock(&data->update_lock); |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 321 | data->temp11[nr] = TEMP11_TO_REG(val - data->temp2_offset); |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 322 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], |
| 323 | data->temp11[nr] >> 8); |
| 324 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], |
| 325 | data->temp11[nr] & 0xff); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 326 | mutex_unlock(&data->update_lock); |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 327 | return count; |
| 328 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | /* Hysteresis register holds a relative value, while we want to present |
| 331 | an absolute to user-space */ |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 332 | static ssize_t show_temp2_crit_hyst(struct device *dev, struct device_attribute *dummy, |
| 333 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | { |
| 335 | struct lm63_data *data = lm63_update_device(dev); |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 336 | return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[2]) |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 337 | + data->temp2_offset |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | - TEMP8_FROM_REG(data->temp2_crit_hyst)); |
| 339 | } |
| 340 | |
| 341 | /* And now the other way around, user-space provides an absolute |
| 342 | hysteresis value and we have to store a relative one */ |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 343 | static ssize_t set_temp2_crit_hyst(struct device *dev, struct device_attribute *dummy, |
| 344 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | { |
| 346 | struct i2c_client *client = to_i2c_client(dev); |
| 347 | struct lm63_data *data = i2c_get_clientdata(client); |
| 348 | long val = simple_strtol(buf, NULL, 10); |
| 349 | long hyst; |
| 350 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 351 | mutex_lock(&data->update_lock); |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 352 | hyst = TEMP8_FROM_REG(data->temp8[2]) + data->temp2_offset - val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST, |
| 354 | HYST_TO_REG(hyst)); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 355 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | return count; |
| 357 | } |
| 358 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 359 | static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy, |
| 360 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | { |
| 362 | struct lm63_data *data = lm63_update_device(dev); |
| 363 | return sprintf(buf, "%u\n", data->alarms); |
| 364 | } |
| 365 | |
Jean Delvare | 2d45771 | 2006-09-24 20:52:15 +0200 | [diff] [blame] | 366 | static ssize_t show_alarm(struct device *dev, struct device_attribute *devattr, |
| 367 | char *buf) |
| 368 | { |
| 369 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 370 | struct lm63_data *data = lm63_update_device(dev); |
| 371 | int bitnr = attr->index; |
| 372 | |
| 373 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); |
| 374 | } |
| 375 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 376 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); |
| 377 | static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan, |
| 378 | set_fan, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
| 380 | static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm1, set_pwm1); |
| 381 | static DEVICE_ATTR(pwm1_enable, S_IRUGO, show_pwm1_enable, NULL); |
| 382 | |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 383 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_local_temp8, NULL, 0); |
| 384 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_local_temp8, |
| 385 | set_local_temp8, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 387 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0); |
| 388 | static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11, |
| 389 | set_temp11, 1); |
| 390 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11, |
| 391 | set_temp11, 2); |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 392 | /* |
| 393 | * On LM63, temp2_crit can be set only once, which should be job |
| 394 | * of the bootloader. |
| 395 | */ |
| 396 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_remote_temp8, |
| 397 | NULL, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst, |
| 399 | set_temp2_crit_hyst); |
| 400 | |
Jean Delvare | 2d45771 | 2006-09-24 20:52:15 +0200 | [diff] [blame] | 401 | /* Individual alarm files */ |
| 402 | static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0); |
| 403 | 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] | 404 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); |
Jean Delvare | 2d45771 | 2006-09-24 20:52:15 +0200 | [diff] [blame] | 405 | static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); |
| 406 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); |
| 407 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); |
| 408 | /* Raw alarm file for compatibility */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
| 410 | |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 411 | static struct attribute *lm63_attributes[] = { |
| 412 | &dev_attr_pwm1.attr, |
| 413 | &dev_attr_pwm1_enable.attr, |
| 414 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 415 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| 416 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
| 417 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 418 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
| 419 | &sensor_dev_attr_temp2_crit.dev_attr.attr, |
| 420 | &dev_attr_temp2_crit_hyst.attr, |
| 421 | |
| 422 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, |
Jean Delvare | 7817a39 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 423 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 424 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, |
| 425 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, |
| 426 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, |
| 427 | &dev_attr_alarms.attr, |
| 428 | NULL |
| 429 | }; |
| 430 | |
| 431 | static const struct attribute_group lm63_group = { |
| 432 | .attrs = lm63_attributes, |
| 433 | }; |
| 434 | |
| 435 | static struct attribute *lm63_attributes_fan1[] = { |
| 436 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 437 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
| 438 | |
| 439 | &sensor_dev_attr_fan1_min_alarm.dev_attr.attr, |
| 440 | NULL |
| 441 | }; |
| 442 | |
| 443 | static const struct attribute_group lm63_group_fan1 = { |
| 444 | .attrs = lm63_attributes_fan1, |
| 445 | }; |
| 446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | /* |
| 448 | * Real code |
| 449 | */ |
| 450 | |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 451 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 452 | static int lm63_detect(struct i2c_client *new_client, |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 453 | struct i2c_board_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | { |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 455 | struct i2c_adapter *adapter = new_client->adapter; |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 456 | u8 man_id, chip_id, reg_config1, reg_config2; |
| 457 | u8 reg_alert_status, reg_alert_mask; |
Matthew Garrett | 10f2ed3 | 2010-05-27 19:58:38 +0200 | [diff] [blame] | 458 | int address = new_client->addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
| 460 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 461 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 463 | man_id = i2c_smbus_read_byte_data(new_client, LM63_REG_MAN_ID); |
| 464 | 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] | 465 | |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 466 | reg_config1 = i2c_smbus_read_byte_data(new_client, |
| 467 | LM63_REG_CONFIG1); |
| 468 | reg_config2 = i2c_smbus_read_byte_data(new_client, |
| 469 | LM63_REG_CONFIG2); |
| 470 | reg_alert_status = i2c_smbus_read_byte_data(new_client, |
| 471 | LM63_REG_ALERT_STATUS); |
| 472 | reg_alert_mask = i2c_smbus_read_byte_data(new_client, |
| 473 | LM63_REG_ALERT_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 475 | if (man_id != 0x01 /* National Semiconductor */ |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 476 | || (reg_config1 & 0x18) != 0x00 |
| 477 | || (reg_config2 & 0xF8) != 0x00 |
| 478 | || (reg_alert_status & 0x20) != 0x00 |
| 479 | || (reg_alert_mask & 0xA4) != 0xA4) { |
| 480 | dev_dbg(&adapter->dev, |
| 481 | "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n", |
| 482 | man_id, chip_id); |
| 483 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Matthew Garrett | 10f2ed3 | 2010-05-27 19:58:38 +0200 | [diff] [blame] | 486 | if (chip_id == 0x41 && address == 0x4c) |
| 487 | strlcpy(info->type, "lm63", I2C_NAME_SIZE); |
| 488 | else if (chip_id == 0x51 && (address == 0x18 || address == 0x4e)) |
| 489 | strlcpy(info->type, "lm64", I2C_NAME_SIZE); |
| 490 | else |
| 491 | return -ENODEV; |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 492 | |
| 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | static int lm63_probe(struct i2c_client *new_client, |
| 497 | const struct i2c_device_id *id) |
| 498 | { |
| 499 | struct lm63_data *data; |
| 500 | int err; |
| 501 | |
| 502 | data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL); |
| 503 | if (!data) { |
| 504 | err = -ENOMEM; |
| 505 | goto exit; |
| 506 | } |
| 507 | |
| 508 | i2c_set_clientdata(new_client, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | data->valid = 0; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 510 | mutex_init(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 512 | /* Set the device type */ |
| 513 | data->kind = id->driver_data; |
| 514 | if (data->kind == lm64) |
| 515 | data->temp2_offset = 16000; |
| 516 | |
| 517 | /* Initialize chip */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | lm63_init_client(new_client); |
| 519 | |
| 520 | /* Register sysfs hooks */ |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 521 | if ((err = sysfs_create_group(&new_client->dev.kobj, |
| 522 | &lm63_group))) |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 523 | goto exit_free; |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 524 | if (data->config & 0x04) { /* tachometer enabled */ |
| 525 | if ((err = sysfs_create_group(&new_client->dev.kobj, |
| 526 | &lm63_group_fan1))) |
| 527 | goto exit_remove_files; |
| 528 | } |
| 529 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 530 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
| 531 | if (IS_ERR(data->hwmon_dev)) { |
| 532 | err = PTR_ERR(data->hwmon_dev); |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 533 | goto exit_remove_files; |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 534 | } |
| 535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | return 0; |
| 537 | |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 538 | exit_remove_files: |
| 539 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group); |
| 540 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | exit_free: |
| 542 | kfree(data); |
| 543 | exit: |
| 544 | return err; |
| 545 | } |
| 546 | |
| 547 | /* Idealy we shouldn't have to initialize anything, since the BIOS |
| 548 | should have taken care of everything */ |
| 549 | static void lm63_init_client(struct i2c_client *client) |
| 550 | { |
| 551 | struct lm63_data *data = i2c_get_clientdata(client); |
| 552 | |
| 553 | data->config = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1); |
| 554 | data->config_fan = i2c_smbus_read_byte_data(client, |
| 555 | LM63_REG_CONFIG_FAN); |
| 556 | |
| 557 | /* Start converting if needed */ |
| 558 | if (data->config & 0x40) { /* standby */ |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 559 | dev_dbg(&client->dev, "Switching to operational mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | data->config &= 0xA7; |
| 561 | i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1, |
| 562 | data->config); |
| 563 | } |
| 564 | |
| 565 | /* We may need pwm1_freq before ever updating the client data */ |
| 566 | data->pwm1_freq = i2c_smbus_read_byte_data(client, LM63_REG_PWM_FREQ); |
| 567 | if (data->pwm1_freq == 0) |
| 568 | data->pwm1_freq = 1; |
| 569 | |
| 570 | /* Show some debug info about the LM63 configuration */ |
| 571 | dev_dbg(&client->dev, "Alert/tach pin configured for %s\n", |
| 572 | (data->config & 0x04) ? "tachometer input" : |
| 573 | "alert output"); |
| 574 | dev_dbg(&client->dev, "PWM clock %s kHz, output frequency %u Hz\n", |
| 575 | (data->config_fan & 0x08) ? "1.4" : "360", |
| 576 | ((data->config_fan & 0x08) ? 700 : 180000) / data->pwm1_freq); |
| 577 | dev_dbg(&client->dev, "PWM output active %s, %s mode\n", |
| 578 | (data->config_fan & 0x10) ? "low" : "high", |
| 579 | (data->config_fan & 0x20) ? "manual" : "auto"); |
| 580 | } |
| 581 | |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 582 | static int lm63_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | { |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 584 | struct lm63_data *data = i2c_get_clientdata(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 586 | hwmon_device_unregister(data->hwmon_dev); |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 587 | sysfs_remove_group(&client->dev.kobj, &lm63_group); |
| 588 | sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 589 | |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 590 | kfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | static struct lm63_data *lm63_update_device(struct device *dev) |
| 595 | { |
| 596 | struct i2c_client *client = to_i2c_client(dev); |
| 597 | struct lm63_data *data = i2c_get_clientdata(client); |
| 598 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 599 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | |
| 601 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { |
| 602 | if (data->config & 0x04) { /* tachometer enabled */ |
| 603 | /* order matters for fan1_input */ |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 604 | data->fan[0] = i2c_smbus_read_byte_data(client, |
| 605 | LM63_REG_TACH_COUNT_LSB) & 0xFC; |
| 606 | data->fan[0] |= i2c_smbus_read_byte_data(client, |
| 607 | LM63_REG_TACH_COUNT_MSB) << 8; |
| 608 | data->fan[1] = (i2c_smbus_read_byte_data(client, |
| 609 | LM63_REG_TACH_LIMIT_LSB) & 0xFC) |
| 610 | | (i2c_smbus_read_byte_data(client, |
| 611 | LM63_REG_TACH_LIMIT_MSB) << 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | data->pwm1_freq = i2c_smbus_read_byte_data(client, |
| 615 | LM63_REG_PWM_FREQ); |
| 616 | if (data->pwm1_freq == 0) |
| 617 | data->pwm1_freq = 1; |
| 618 | data->pwm1_value = i2c_smbus_read_byte_data(client, |
| 619 | LM63_REG_PWM_VALUE); |
| 620 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 621 | data->temp8[0] = i2c_smbus_read_byte_data(client, |
| 622 | LM63_REG_LOCAL_TEMP); |
| 623 | data->temp8[1] = i2c_smbus_read_byte_data(client, |
| 624 | LM63_REG_LOCAL_HIGH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
| 626 | /* order matters for temp2_input */ |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 627 | data->temp11[0] = i2c_smbus_read_byte_data(client, |
| 628 | LM63_REG_REMOTE_TEMP_MSB) << 8; |
| 629 | data->temp11[0] |= i2c_smbus_read_byte_data(client, |
| 630 | LM63_REG_REMOTE_TEMP_LSB); |
| 631 | data->temp11[1] = (i2c_smbus_read_byte_data(client, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | LM63_REG_REMOTE_LOW_MSB) << 8) |
| 633 | | i2c_smbus_read_byte_data(client, |
| 634 | LM63_REG_REMOTE_LOW_LSB); |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 635 | data->temp11[2] = (i2c_smbus_read_byte_data(client, |
| 636 | LM63_REG_REMOTE_HIGH_MSB) << 8) |
| 637 | | i2c_smbus_read_byte_data(client, |
| 638 | LM63_REG_REMOTE_HIGH_LSB); |
| 639 | data->temp8[2] = i2c_smbus_read_byte_data(client, |
| 640 | LM63_REG_REMOTE_TCRIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | data->temp2_crit_hyst = i2c_smbus_read_byte_data(client, |
| 642 | LM63_REG_REMOTE_TCRIT_HYST); |
| 643 | |
| 644 | data->alarms = i2c_smbus_read_byte_data(client, |
| 645 | LM63_REG_ALERT_STATUS) & 0x7F; |
| 646 | |
| 647 | data->last_updated = jiffies; |
| 648 | data->valid = 1; |
| 649 | } |
| 650 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 651 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
| 653 | return data; |
| 654 | } |
| 655 | |
| 656 | static int __init sensors_lm63_init(void) |
| 657 | { |
| 658 | return i2c_add_driver(&lm63_driver); |
| 659 | } |
| 660 | |
| 661 | static void __exit sensors_lm63_exit(void) |
| 662 | { |
| 663 | i2c_del_driver(&lm63_driver); |
| 664 | } |
| 665 | |
| 666 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); |
| 667 | MODULE_DESCRIPTION("LM63 driver"); |
| 668 | MODULE_LICENSE("GPL"); |
| 669 | |
| 670 | module_init(sensors_lm63_init); |
| 671 | module_exit(sensors_lm63_exit); |