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