Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * lm90.c - Part of lm_sensors, Linux kernel modules for hardware |
| 3 | * monitoring |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 4 | * Copyright (C) 2003-2009 Jean Delvare <khali@linux-fr.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * Based on the lm83 driver. The LM90 is a sensor chip made by National |
| 7 | * Semiconductor. It reports up to two temperatures (its own plus up to |
| 8 | * one external one) with a 0.125 deg resolution (1 deg for local |
Jean Delvare | a874a10 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 9 | * temperature) and a 3-4 deg accuracy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 11 | * This driver also supports the LM89 and LM99, two other sensor chips |
| 12 | * made by National Semiconductor. Both have an increased remote |
| 13 | * temperature measurement accuracy (1 degree), and the LM99 |
| 14 | * additionally shifts remote temperatures (measured and limits) by 16 |
Jean Delvare | 97ae60b | 2008-10-26 17:04:39 +0100 | [diff] [blame] | 15 | * degrees, which allows for higher temperatures measurement. |
Steven Cole | 44bbe87 | 2005-05-03 18:21:25 -0600 | [diff] [blame] | 16 | * Note that there is no way to differentiate between both chips. |
Jean Delvare | 97ae60b | 2008-10-26 17:04:39 +0100 | [diff] [blame] | 17 | * When device is auto-detected, the driver will assume an LM99. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * |
| 19 | * This driver also supports the LM86, another sensor chip made by |
| 20 | * National Semiconductor. It is exactly similar to the LM90 except it |
| 21 | * has a higher accuracy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | * |
| 23 | * This driver also supports the ADM1032, a sensor chip made by Analog |
| 24 | * Devices. That chip is similar to the LM90, with a few differences |
Jean Delvare | a874a10 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 25 | * that are not handled by this driver. Among others, it has a higher |
| 26 | * accuracy than the LM90, much like the LM86 does. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | * |
| 28 | * This driver also supports the MAX6657, MAX6658 and MAX6659 sensor |
Jean Delvare | a874a10 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 29 | * chips made by Maxim. These chips are similar to the LM86. |
Steven Cole | 44bbe87 | 2005-05-03 18:21:25 -0600 | [diff] [blame] | 30 | * Note that there is no easy way to differentiate between the three |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | * variants. The extra address and features of the MAX6659 are not |
Jean Delvare | 69f2f96 | 2007-09-05 14:15:37 +0200 | [diff] [blame] | 32 | * supported by this driver. These chips lack the remote temperature |
| 33 | * offset feature. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | * |
Darrick J. Wong | 1a51e06 | 2009-03-12 13:36:38 +0100 | [diff] [blame] | 35 | * This driver also supports the MAX6646, MAX6647, MAX6648, MAX6649 and |
| 36 | * MAX6692 chips made by Maxim. These are again similar to the LM86, |
| 37 | * but they use unsigned temperature values and can report temperatures |
| 38 | * from 0 to 145 degrees. |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 39 | * |
Rainer Birkenmaier | 32c82a9 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 40 | * This driver also supports the MAX6680 and MAX6681, two other sensor |
| 41 | * chips made by Maxim. These are quite similar to the other Maxim |
Jean Delvare | a874a10 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 42 | * chips. The MAX6680 and MAX6681 only differ in the pinout so they can |
| 43 | * be treated identically. |
Rainer Birkenmaier | 32c82a9 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 44 | * |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 45 | * This driver also supports the ADT7461 chip from Analog Devices. |
| 46 | * It's supported in both compatibility and extended mode. It is mostly |
| 47 | * compatible with LM90 except for a data format difference for the |
| 48 | * temperature value registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | * |
| 50 | * Since the LM90 was the first chipset supported by this driver, most |
| 51 | * comments will refer to this chipset, but are actually general and |
| 52 | * concern all supported chipsets, unless mentioned otherwise. |
| 53 | * |
| 54 | * This program is free software; you can redistribute it and/or modify |
| 55 | * it under the terms of the GNU General Public License as published by |
| 56 | * the Free Software Foundation; either version 2 of the License, or |
| 57 | * (at your option) any later version. |
| 58 | * |
| 59 | * This program is distributed in the hope that it will be useful, |
| 60 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 61 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 62 | * GNU General Public License for more details. |
| 63 | * |
| 64 | * You should have received a copy of the GNU General Public License |
| 65 | * along with this program; if not, write to the Free Software |
| 66 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 67 | */ |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #include <linux/module.h> |
| 70 | #include <linux/init.h> |
| 71 | #include <linux/slab.h> |
| 72 | #include <linux/jiffies.h> |
| 73 | #include <linux/i2c.h> |
Jean Delvare | 10c08f8 | 2005-06-06 19:34:45 +0200 | [diff] [blame] | 74 | #include <linux/hwmon-sysfs.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 75 | #include <linux/hwmon.h> |
| 76 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 77 | #include <linux/mutex.h> |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 78 | #include <linux/sysfs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * Addresses to scan |
| 82 | * Address is fully defined internally and cannot be changed except for |
Rainer Birkenmaier | 32c82a9 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 83 | * MAX6659, MAX6680 and MAX6681. |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 84 | * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, MAX6649, MAX6657 |
| 85 | * and MAX6658 have address 0x4c. |
| 86 | * ADM1032-2, ADT7461-2, LM89-1, LM99-1 and MAX6646 have address 0x4d. |
| 87 | * MAX6647 has address 0x4e. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | * MAX6659 can have address 0x4c, 0x4d or 0x4e (unsupported). |
Rainer Birkenmaier | 32c82a9 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 89 | * MAX6680 and MAX6681 can have address 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, |
| 90 | * 0x4c, 0x4d or 0x4e. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | */ |
| 92 | |
Mark M. Hoffman | 25e9c86 | 2008-02-17 22:28:03 -0500 | [diff] [blame] | 93 | static const unsigned short normal_i2c[] = { |
| 94 | 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | /* |
| 97 | * Insmod parameters |
| 98 | */ |
| 99 | |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 100 | I2C_CLIENT_INSMOD_8(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680, |
| 101 | max6646); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | /* |
| 104 | * The LM90 registers |
| 105 | */ |
| 106 | |
| 107 | #define LM90_REG_R_MAN_ID 0xFE |
| 108 | #define LM90_REG_R_CHIP_ID 0xFF |
| 109 | #define LM90_REG_R_CONFIG1 0x03 |
| 110 | #define LM90_REG_W_CONFIG1 0x09 |
| 111 | #define LM90_REG_R_CONFIG2 0xBF |
| 112 | #define LM90_REG_W_CONFIG2 0xBF |
| 113 | #define LM90_REG_R_CONVRATE 0x04 |
| 114 | #define LM90_REG_W_CONVRATE 0x0A |
| 115 | #define LM90_REG_R_STATUS 0x02 |
| 116 | #define LM90_REG_R_LOCAL_TEMP 0x00 |
| 117 | #define LM90_REG_R_LOCAL_HIGH 0x05 |
| 118 | #define LM90_REG_W_LOCAL_HIGH 0x0B |
| 119 | #define LM90_REG_R_LOCAL_LOW 0x06 |
| 120 | #define LM90_REG_W_LOCAL_LOW 0x0C |
| 121 | #define LM90_REG_R_LOCAL_CRIT 0x20 |
| 122 | #define LM90_REG_W_LOCAL_CRIT 0x20 |
| 123 | #define LM90_REG_R_REMOTE_TEMPH 0x01 |
| 124 | #define LM90_REG_R_REMOTE_TEMPL 0x10 |
| 125 | #define LM90_REG_R_REMOTE_OFFSH 0x11 |
| 126 | #define LM90_REG_W_REMOTE_OFFSH 0x11 |
| 127 | #define LM90_REG_R_REMOTE_OFFSL 0x12 |
| 128 | #define LM90_REG_W_REMOTE_OFFSL 0x12 |
| 129 | #define LM90_REG_R_REMOTE_HIGHH 0x07 |
| 130 | #define LM90_REG_W_REMOTE_HIGHH 0x0D |
| 131 | #define LM90_REG_R_REMOTE_HIGHL 0x13 |
| 132 | #define LM90_REG_W_REMOTE_HIGHL 0x13 |
| 133 | #define LM90_REG_R_REMOTE_LOWH 0x08 |
| 134 | #define LM90_REG_W_REMOTE_LOWH 0x0E |
| 135 | #define LM90_REG_R_REMOTE_LOWL 0x14 |
| 136 | #define LM90_REG_W_REMOTE_LOWL 0x14 |
| 137 | #define LM90_REG_R_REMOTE_CRIT 0x19 |
| 138 | #define LM90_REG_W_REMOTE_CRIT 0x19 |
| 139 | #define LM90_REG_R_TCRIT_HYST 0x21 |
| 140 | #define LM90_REG_W_TCRIT_HYST 0x21 |
| 141 | |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 142 | /* MAX6646/6647/6649/6657/6658/6659 registers */ |
Jean Delvare | f65e170 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 143 | |
| 144 | #define MAX6657_REG_R_LOCAL_TEMPL 0x11 |
| 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | /* |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 147 | * Device flags |
| 148 | */ |
| 149 | #define LM90_FLAG_ADT7461_EXT 0x01 /* ADT7461 extended mode */ |
| 150 | |
| 151 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | * Functions declaration |
| 153 | */ |
| 154 | |
Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 155 | static int lm90_detect(struct i2c_client *client, struct i2c_board_info *info); |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 156 | static int lm90_probe(struct i2c_client *client, |
| 157 | const struct i2c_device_id *id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | static void lm90_init_client(struct i2c_client *client); |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 159 | static int lm90_remove(struct i2c_client *client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | static struct lm90_data *lm90_update_device(struct device *dev); |
| 161 | |
| 162 | /* |
| 163 | * Driver data (common to all clients) |
| 164 | */ |
| 165 | |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 166 | static const struct i2c_device_id lm90_id[] = { |
| 167 | { "adm1032", adm1032 }, |
| 168 | { "adt7461", adt7461 }, |
| 169 | { "lm90", lm90 }, |
| 170 | { "lm86", lm86 }, |
Jean Delvare | 97ae60b | 2008-10-26 17:04:39 +0100 | [diff] [blame] | 171 | { "lm89", lm86 }, |
| 172 | { "lm99", lm99 }, |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 173 | { "max6646", max6646 }, |
| 174 | { "max6647", max6646 }, |
| 175 | { "max6649", max6646 }, |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 176 | { "max6657", max6657 }, |
| 177 | { "max6658", max6657 }, |
| 178 | { "max6659", max6657 }, |
| 179 | { "max6680", max6680 }, |
| 180 | { "max6681", max6680 }, |
| 181 | { } |
| 182 | }; |
| 183 | MODULE_DEVICE_TABLE(i2c, lm90_id); |
| 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | static struct i2c_driver lm90_driver = { |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 186 | .class = I2C_CLASS_HWMON, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 187 | .driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 188 | .name = "lm90", |
| 189 | }, |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 190 | .probe = lm90_probe, |
| 191 | .remove = lm90_remove, |
| 192 | .id_table = lm90_id, |
| 193 | .detect = lm90_detect, |
Jean Delvare | c3813d6 | 2009-12-14 21:17:25 +0100 | [diff] [blame^] | 194 | .address_list = normal_i2c, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | }; |
| 196 | |
| 197 | /* |
| 198 | * Client data (each client gets its own) |
| 199 | */ |
| 200 | |
| 201 | struct lm90_data { |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 202 | struct device *hwmon_dev; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 203 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | char valid; /* zero until following fields are valid */ |
| 205 | unsigned long last_updated; /* in jiffies */ |
| 206 | int kind; |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 207 | int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | /* registers values */ |
Jean Delvare | f65e170 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 210 | s8 temp8[4]; /* 0: local low limit |
| 211 | 1: local high limit |
| 212 | 2: local critical limit |
| 213 | 3: remote critical limit */ |
| 214 | s16 temp11[5]; /* 0: remote input |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 215 | 1: remote low limit |
Jean Delvare | 69f2f96 | 2007-09-05 14:15:37 +0200 | [diff] [blame] | 216 | 2: remote high limit |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 217 | 3: remote offset (except max6646 and max6657) |
Jean Delvare | f65e170 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 218 | 4: local input */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | u8 temp_hyst; |
| 220 | u8 alarms; /* bitvector */ |
| 221 | }; |
| 222 | |
| 223 | /* |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 224 | * Conversions |
| 225 | * For local temperatures and limits, critical limits and the hysteresis |
| 226 | * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celsius. |
| 227 | * For remote temperatures and limits, it uses signed 11-bit values with |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 228 | * LSB = 0.125 degree Celsius, left-justified in 16-bit registers. Some |
| 229 | * Maxim chips use unsigned values. |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 230 | */ |
| 231 | |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 232 | static inline int temp_from_s8(s8 val) |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 233 | { |
| 234 | return val * 1000; |
| 235 | } |
| 236 | |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 237 | static inline int temp_from_u8(u8 val) |
| 238 | { |
| 239 | return val * 1000; |
| 240 | } |
| 241 | |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 242 | static inline int temp_from_s16(s16 val) |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 243 | { |
| 244 | return val / 32 * 125; |
| 245 | } |
| 246 | |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 247 | static inline int temp_from_u16(u16 val) |
| 248 | { |
| 249 | return val / 32 * 125; |
| 250 | } |
| 251 | |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 252 | static s8 temp_to_s8(long val) |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 253 | { |
| 254 | if (val <= -128000) |
| 255 | return -128; |
| 256 | if (val >= 127000) |
| 257 | return 127; |
| 258 | if (val < 0) |
| 259 | return (val - 500) / 1000; |
| 260 | return (val + 500) / 1000; |
| 261 | } |
| 262 | |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 263 | static u8 temp_to_u8(long val) |
| 264 | { |
| 265 | if (val <= 0) |
| 266 | return 0; |
| 267 | if (val >= 255000) |
| 268 | return 255; |
| 269 | return (val + 500) / 1000; |
| 270 | } |
| 271 | |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 272 | static s16 temp_to_s16(long val) |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 273 | { |
| 274 | if (val <= -128000) |
| 275 | return 0x8000; |
| 276 | if (val >= 127875) |
| 277 | return 0x7FE0; |
| 278 | if (val < 0) |
| 279 | return (val - 62) / 125 * 32; |
| 280 | return (val + 62) / 125 * 32; |
| 281 | } |
| 282 | |
| 283 | static u8 hyst_to_reg(long val) |
| 284 | { |
| 285 | if (val <= 0) |
| 286 | return 0; |
| 287 | if (val >= 30500) |
| 288 | return 31; |
| 289 | return (val + 500) / 1000; |
| 290 | } |
| 291 | |
| 292 | /* |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 293 | * ADT7461 in compatibility mode is almost identical to LM90 except that |
| 294 | * attempts to write values that are outside the range 0 < temp < 127 are |
| 295 | * treated as the boundary value. |
| 296 | * |
| 297 | * ADT7461 in "extended mode" operation uses unsigned integers offset by |
| 298 | * 64 (e.g., 0 -> -64 degC). The range is restricted to -64..191 degC. |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 299 | */ |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 300 | static inline int temp_from_u8_adt7461(struct lm90_data *data, u8 val) |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 301 | { |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 302 | if (data->flags & LM90_FLAG_ADT7461_EXT) |
| 303 | return (val - 64) * 1000; |
| 304 | else |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 305 | return temp_from_s8(val); |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 306 | } |
| 307 | |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 308 | static inline int temp_from_u16_adt7461(struct lm90_data *data, u16 val) |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 309 | { |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 310 | if (data->flags & LM90_FLAG_ADT7461_EXT) |
| 311 | return (val - 0x4000) / 64 * 250; |
| 312 | else |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 313 | return temp_from_s16(val); |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 314 | } |
| 315 | |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 316 | static u8 temp_to_u8_adt7461(struct lm90_data *data, long val) |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 317 | { |
| 318 | if (data->flags & LM90_FLAG_ADT7461_EXT) { |
| 319 | if (val <= -64000) |
| 320 | return 0; |
| 321 | if (val >= 191000) |
| 322 | return 0xFF; |
| 323 | return (val + 500 + 64000) / 1000; |
| 324 | } else { |
| 325 | if (val <= 0) |
| 326 | return 0; |
| 327 | if (val >= 127000) |
| 328 | return 127; |
| 329 | return (val + 500) / 1000; |
| 330 | } |
| 331 | } |
| 332 | |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 333 | static u16 temp_to_u16_adt7461(struct lm90_data *data, long val) |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 334 | { |
| 335 | if (data->flags & LM90_FLAG_ADT7461_EXT) { |
| 336 | if (val <= -64000) |
| 337 | return 0; |
| 338 | if (val >= 191750) |
| 339 | return 0xFFC0; |
| 340 | return (val + 64000 + 125) / 250 * 64; |
| 341 | } else { |
| 342 | if (val <= 0) |
| 343 | return 0; |
| 344 | if (val >= 127750) |
| 345 | return 0x7FC0; |
| 346 | return (val + 125) / 250 * 64; |
| 347 | } |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | * Sysfs stuff |
| 352 | */ |
| 353 | |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 354 | static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr, |
| 355 | char *buf) |
| 356 | { |
| 357 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 358 | struct lm90_data *data = lm90_update_device(dev); |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 359 | int temp; |
| 360 | |
| 361 | if (data->kind == adt7461) |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 362 | temp = temp_from_u8_adt7461(data, data->temp8[attr->index]); |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 363 | else if (data->kind == max6646) |
| 364 | temp = temp_from_u8(data->temp8[attr->index]); |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 365 | else |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 366 | temp = temp_from_s8(data->temp8[attr->index]); |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 367 | |
Jean Delvare | 97ae60b | 2008-10-26 17:04:39 +0100 | [diff] [blame] | 368 | /* +16 degrees offset for temp2 for the LM99 */ |
| 369 | if (data->kind == lm99 && attr->index == 3) |
| 370 | temp += 16000; |
| 371 | |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 372 | return sprintf(buf, "%d\n", temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 375 | static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, |
| 376 | const char *buf, size_t count) |
| 377 | { |
| 378 | static const u8 reg[4] = { |
| 379 | LM90_REG_W_LOCAL_LOW, |
| 380 | LM90_REG_W_LOCAL_HIGH, |
| 381 | LM90_REG_W_LOCAL_CRIT, |
| 382 | LM90_REG_W_REMOTE_CRIT, |
| 383 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 385 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 386 | struct i2c_client *client = to_i2c_client(dev); |
| 387 | struct lm90_data *data = i2c_get_clientdata(client); |
| 388 | long val = simple_strtol(buf, NULL, 10); |
| 389 | int nr = attr->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Jean Delvare | 97ae60b | 2008-10-26 17:04:39 +0100 | [diff] [blame] | 391 | /* +16 degrees offset for temp2 for the LM99 */ |
| 392 | if (data->kind == lm99 && attr->index == 3) |
| 393 | val -= 16000; |
| 394 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 395 | mutex_lock(&data->update_lock); |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 396 | if (data->kind == adt7461) |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 397 | data->temp8[nr] = temp_to_u8_adt7461(data, val); |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 398 | else if (data->kind == max6646) |
| 399 | data->temp8[nr] = temp_to_u8(val); |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 400 | else |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 401 | data->temp8[nr] = temp_to_s8(val); |
Jean Delvare | f65e170 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 402 | i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 403 | mutex_unlock(&data->update_lock); |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 404 | return count; |
| 405 | } |
| 406 | |
| 407 | static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, |
| 408 | char *buf) |
| 409 | { |
| 410 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 411 | struct lm90_data *data = lm90_update_device(dev); |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 412 | int temp; |
| 413 | |
| 414 | if (data->kind == adt7461) |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 415 | temp = temp_from_u16_adt7461(data, data->temp11[attr->index]); |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 416 | else if (data->kind == max6646) |
| 417 | temp = temp_from_u16(data->temp11[attr->index]); |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 418 | else |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 419 | temp = temp_from_s16(data->temp11[attr->index]); |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 420 | |
Jean Delvare | 97ae60b | 2008-10-26 17:04:39 +0100 | [diff] [blame] | 421 | /* +16 degrees offset for temp2 for the LM99 */ |
| 422 | if (data->kind == lm99 && attr->index <= 2) |
| 423 | temp += 16000; |
| 424 | |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 425 | return sprintf(buf, "%d\n", temp); |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, |
| 429 | const char *buf, size_t count) |
| 430 | { |
Jean Delvare | 69f2f96 | 2007-09-05 14:15:37 +0200 | [diff] [blame] | 431 | static const u8 reg[6] = { |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 432 | LM90_REG_W_REMOTE_LOWH, |
| 433 | LM90_REG_W_REMOTE_LOWL, |
| 434 | LM90_REG_W_REMOTE_HIGHH, |
| 435 | LM90_REG_W_REMOTE_HIGHL, |
Jean Delvare | 69f2f96 | 2007-09-05 14:15:37 +0200 | [diff] [blame] | 436 | LM90_REG_W_REMOTE_OFFSH, |
| 437 | LM90_REG_W_REMOTE_OFFSL, |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 438 | }; |
| 439 | |
| 440 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 441 | struct i2c_client *client = to_i2c_client(dev); |
| 442 | struct lm90_data *data = i2c_get_clientdata(client); |
| 443 | long val = simple_strtol(buf, NULL, 10); |
| 444 | int nr = attr->index; |
| 445 | |
Jean Delvare | 97ae60b | 2008-10-26 17:04:39 +0100 | [diff] [blame] | 446 | /* +16 degrees offset for temp2 for the LM99 */ |
| 447 | if (data->kind == lm99 && attr->index <= 2) |
| 448 | val -= 16000; |
| 449 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 450 | mutex_lock(&data->update_lock); |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 451 | if (data->kind == adt7461) |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 452 | data->temp11[nr] = temp_to_u16_adt7461(data, val); |
Jean Delvare | 5f502a8 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 453 | else if (data->kind == max6657 || data->kind == max6680) |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 454 | data->temp11[nr] = temp_to_s8(val) << 8; |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 455 | else if (data->kind == max6646) |
| 456 | data->temp11[nr] = temp_to_u8(val) << 8; |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 457 | else |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 458 | data->temp11[nr] = temp_to_s16(val); |
Jean Delvare | 5f502a8 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 459 | |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 460 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], |
| 461 | data->temp11[nr] >> 8); |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 462 | if (data->kind != max6657 && data->kind != max6680 |
| 463 | && data->kind != max6646) |
Jean Delvare | 5f502a8 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 464 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], |
| 465 | data->temp11[nr] & 0xff); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 466 | mutex_unlock(&data->update_lock); |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 467 | return count; |
| 468 | } |
| 469 | |
| 470 | static ssize_t show_temphyst(struct device *dev, struct device_attribute *devattr, |
| 471 | char *buf) |
| 472 | { |
| 473 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 474 | struct lm90_data *data = lm90_update_device(dev); |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 475 | int temp; |
| 476 | |
| 477 | if (data->kind == adt7461) |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 478 | temp = temp_from_u8_adt7461(data, data->temp8[attr->index]); |
Jean Delvare | ec38fa2 | 2008-10-26 17:04:39 +0100 | [diff] [blame] | 479 | else if (data->kind == max6646) |
| 480 | temp = temp_from_u8(data->temp8[attr->index]); |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 481 | else |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 482 | temp = temp_from_s8(data->temp8[attr->index]); |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 483 | |
Jean Delvare | 97ae60b | 2008-10-26 17:04:39 +0100 | [diff] [blame] | 484 | /* +16 degrees offset for temp2 for the LM99 */ |
| 485 | if (data->kind == lm99 && attr->index == 3) |
| 486 | temp += 16000; |
| 487 | |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 488 | return sprintf(buf, "%d\n", temp - temp_from_s8(data->temp_hyst)); |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy, |
| 492 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | { |
| 494 | struct i2c_client *client = to_i2c_client(dev); |
| 495 | struct lm90_data *data = i2c_get_clientdata(client); |
| 496 | long val = simple_strtol(buf, NULL, 10); |
Jean Delvare | ec38fa2 | 2008-10-26 17:04:39 +0100 | [diff] [blame] | 497 | int temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 499 | mutex_lock(&data->update_lock); |
Jean Delvare | ec38fa2 | 2008-10-26 17:04:39 +0100 | [diff] [blame] | 500 | if (data->kind == adt7461) |
| 501 | temp = temp_from_u8_adt7461(data, data->temp8[2]); |
| 502 | else if (data->kind == max6646) |
| 503 | temp = temp_from_u8(data->temp8[2]); |
| 504 | else |
| 505 | temp = temp_from_s8(data->temp8[2]); |
| 506 | |
| 507 | data->temp_hyst = hyst_to_reg(temp - val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST, |
Jean Delvare | ec38fa2 | 2008-10-26 17:04:39 +0100 | [diff] [blame] | 509 | data->temp_hyst); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 510 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | return count; |
| 512 | } |
| 513 | |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 514 | static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy, |
| 515 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | { |
| 517 | struct lm90_data *data = lm90_update_device(dev); |
| 518 | return sprintf(buf, "%d\n", data->alarms); |
| 519 | } |
| 520 | |
Jean Delvare | 2d45771 | 2006-09-24 20:52:15 +0200 | [diff] [blame] | 521 | static ssize_t show_alarm(struct device *dev, struct device_attribute |
| 522 | *devattr, char *buf) |
| 523 | { |
| 524 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 525 | struct lm90_data *data = lm90_update_device(dev); |
| 526 | int bitnr = attr->index; |
| 527 | |
| 528 | return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); |
| 529 | } |
| 530 | |
Jean Delvare | f65e170 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 531 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp11, NULL, 4); |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 532 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0); |
| 533 | static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8, |
Jean Delvare | f65e170 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 534 | set_temp8, 0); |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 535 | static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11, |
| 536 | set_temp11, 1); |
| 537 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp8, |
Jean Delvare | f65e170 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 538 | set_temp8, 1); |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 539 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11, |
| 540 | set_temp11, 2); |
| 541 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp8, |
Jean Delvare | f65e170 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 542 | set_temp8, 2); |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 543 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8, |
Jean Delvare | f65e170 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 544 | set_temp8, 3); |
Jean Delvare | 30d7394 | 2005-06-05 21:27:28 +0200 | [diff] [blame] | 545 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst, |
Jean Delvare | f65e170 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 546 | set_temphyst, 2); |
| 547 | static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 3); |
Jean Delvare | 69f2f96 | 2007-09-05 14:15:37 +0200 | [diff] [blame] | 548 | static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_temp11, |
| 549 | set_temp11, 3); |
Jean Delvare | 2d45771 | 2006-09-24 20:52:15 +0200 | [diff] [blame] | 550 | |
| 551 | /* Individual alarm files */ |
| 552 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); |
| 553 | 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] | 554 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); |
Jean Delvare | 2d45771 | 2006-09-24 20:52:15 +0200 | [diff] [blame] | 555 | static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); |
| 556 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); |
| 557 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 5); |
| 558 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); |
| 559 | /* Raw alarm file for compatibility */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
| 561 | |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 562 | static struct attribute *lm90_attributes[] = { |
| 563 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 564 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| 565 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
| 566 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
| 567 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 568 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
| 569 | &sensor_dev_attr_temp1_crit.dev_attr.attr, |
| 570 | &sensor_dev_attr_temp2_crit.dev_attr.attr, |
| 571 | &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, |
| 572 | &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr, |
| 573 | |
| 574 | &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, |
| 575 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, |
Jean Delvare | 7817a39 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 576 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 577 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, |
| 578 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, |
| 579 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, |
| 580 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, |
| 581 | &dev_attr_alarms.attr, |
| 582 | NULL |
| 583 | }; |
| 584 | |
| 585 | static const struct attribute_group lm90_group = { |
| 586 | .attrs = lm90_attributes, |
| 587 | }; |
| 588 | |
Jean Delvare | c3df580 | 2005-10-26 21:39:40 +0200 | [diff] [blame] | 589 | /* pec used for ADM1032 only */ |
| 590 | static ssize_t show_pec(struct device *dev, struct device_attribute *dummy, |
| 591 | char *buf) |
| 592 | { |
| 593 | struct i2c_client *client = to_i2c_client(dev); |
| 594 | return sprintf(buf, "%d\n", !!(client->flags & I2C_CLIENT_PEC)); |
| 595 | } |
| 596 | |
| 597 | static ssize_t set_pec(struct device *dev, struct device_attribute *dummy, |
| 598 | const char *buf, size_t count) |
| 599 | { |
| 600 | struct i2c_client *client = to_i2c_client(dev); |
| 601 | long val = simple_strtol(buf, NULL, 10); |
| 602 | |
| 603 | switch (val) { |
| 604 | case 0: |
| 605 | client->flags &= ~I2C_CLIENT_PEC; |
| 606 | break; |
| 607 | case 1: |
| 608 | client->flags |= I2C_CLIENT_PEC; |
| 609 | break; |
| 610 | default: |
| 611 | return -EINVAL; |
| 612 | } |
| 613 | |
| 614 | return count; |
| 615 | } |
| 616 | |
| 617 | static DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec); |
| 618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | /* |
| 620 | * Real code |
| 621 | */ |
| 622 | |
Jean Delvare | c3df580 | 2005-10-26 21:39:40 +0200 | [diff] [blame] | 623 | /* The ADM1032 supports PEC but not on write byte transactions, so we need |
Jean Delvare | 0966415 | 2007-06-09 10:11:15 -0400 | [diff] [blame] | 624 | to explicitly ask for a transaction without PEC. */ |
Jean Delvare | c3df580 | 2005-10-26 21:39:40 +0200 | [diff] [blame] | 625 | static inline s32 adm1032_write_byte(struct i2c_client *client, u8 value) |
| 626 | { |
| 627 | return i2c_smbus_xfer(client->adapter, client->addr, |
| 628 | client->flags & ~I2C_CLIENT_PEC, |
| 629 | I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); |
| 630 | } |
| 631 | |
| 632 | /* It is assumed that client->update_lock is held (unless we are in |
| 633 | detection or initialization steps). This matters when PEC is enabled, |
| 634 | because we don't want the address pointer to change between the write |
| 635 | byte and the read byte transactions. */ |
Jean Delvare | 8256fe0 | 2005-10-26 21:37:52 +0200 | [diff] [blame] | 636 | static int lm90_read_reg(struct i2c_client* client, u8 reg, u8 *value) |
| 637 | { |
| 638 | int err; |
| 639 | |
Jean Delvare | c3df580 | 2005-10-26 21:39:40 +0200 | [diff] [blame] | 640 | if (client->flags & I2C_CLIENT_PEC) { |
| 641 | err = adm1032_write_byte(client, reg); |
| 642 | if (err >= 0) |
| 643 | err = i2c_smbus_read_byte(client); |
| 644 | } else |
| 645 | err = i2c_smbus_read_byte_data(client, reg); |
Jean Delvare | 8256fe0 | 2005-10-26 21:37:52 +0200 | [diff] [blame] | 646 | |
| 647 | if (err < 0) { |
| 648 | dev_warn(&client->dev, "Register %#02x read failed (%d)\n", |
| 649 | reg, err); |
| 650 | return err; |
| 651 | } |
| 652 | *value = err; |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 657 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 658 | static int lm90_detect(struct i2c_client *new_client, |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 659 | struct i2c_board_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | { |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 661 | struct i2c_adapter *adapter = new_client->adapter; |
| 662 | int address = new_client->addr; |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 663 | const char *name = NULL; |
| 664 | int man_id, chip_id, reg_config1, reg_convrate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | |
| 666 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 667 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 669 | /* detection and identification */ |
| 670 | if ((man_id = i2c_smbus_read_byte_data(new_client, |
Jean Delvare | e0ae87a | 2007-11-25 21:58:21 +0100 | [diff] [blame] | 671 | LM90_REG_R_MAN_ID)) < 0 |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 672 | || (chip_id = i2c_smbus_read_byte_data(new_client, |
Jean Delvare | e0ae87a | 2007-11-25 21:58:21 +0100 | [diff] [blame] | 673 | LM90_REG_R_CHIP_ID)) < 0 |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 674 | || (reg_config1 = i2c_smbus_read_byte_data(new_client, |
Jean Delvare | e0ae87a | 2007-11-25 21:58:21 +0100 | [diff] [blame] | 675 | LM90_REG_R_CONFIG1)) < 0 |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 676 | || (reg_convrate = i2c_smbus_read_byte_data(new_client, |
Jean Delvare | e0ae87a | 2007-11-25 21:58:21 +0100 | [diff] [blame] | 677 | LM90_REG_R_CONVRATE)) < 0) |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 678 | return -ENODEV; |
| 679 | |
| 680 | if ((address == 0x4C || address == 0x4D) |
| 681 | && man_id == 0x01) { /* National Semiconductor */ |
| 682 | int reg_config2; |
| 683 | |
| 684 | reg_config2 = i2c_smbus_read_byte_data(new_client, |
| 685 | LM90_REG_R_CONFIG2); |
| 686 | if (reg_config2 < 0) |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 687 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 689 | if ((reg_config1 & 0x2A) == 0x00 |
| 690 | && (reg_config2 & 0xF8) == 0x00 |
| 691 | && reg_convrate <= 0x09) { |
| 692 | if (address == 0x4C |
| 693 | && (chip_id & 0xF0) == 0x20) { /* LM90 */ |
| 694 | name = "lm90"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | } else |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 696 | if ((chip_id & 0xF0) == 0x30) { /* LM89/LM99 */ |
| 697 | name = "lm99"; |
| 698 | dev_info(&adapter->dev, |
| 699 | "Assuming LM99 chip at 0x%02x\n", |
| 700 | address); |
| 701 | dev_info(&adapter->dev, |
| 702 | "If it is an LM89, instantiate it " |
| 703 | "with the new_device sysfs " |
| 704 | "interface\n"); |
Rainer Birkenmaier | 32c82a9 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 705 | } else |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 706 | if (address == 0x4C |
| 707 | && (chip_id & 0xF0) == 0x10) { /* LM86 */ |
| 708 | name = "lm86"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | } |
| 710 | } |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 711 | } else |
| 712 | if ((address == 0x4C || address == 0x4D) |
| 713 | && man_id == 0x41) { /* Analog Devices */ |
| 714 | if ((chip_id & 0xF0) == 0x40 /* ADM1032 */ |
| 715 | && (reg_config1 & 0x3F) == 0x00 |
| 716 | && reg_convrate <= 0x0A) { |
| 717 | name = "adm1032"; |
| 718 | /* The ADM1032 supports PEC, but only if combined |
| 719 | transactions are not used. */ |
| 720 | if (i2c_check_functionality(adapter, |
| 721 | I2C_FUNC_SMBUS_BYTE)) |
| 722 | info->flags |= I2C_CLIENT_PEC; |
| 723 | } else |
| 724 | if (chip_id == 0x51 /* ADT7461 */ |
| 725 | && (reg_config1 & 0x1B) == 0x00 |
| 726 | && reg_convrate <= 0x0A) { |
| 727 | name = "adt7461"; |
| 728 | } |
| 729 | } else |
| 730 | if (man_id == 0x4D) { /* Maxim */ |
| 731 | /* |
| 732 | * The MAX6657, MAX6658 and MAX6659 do NOT have a chip_id |
| 733 | * register. Reading from that address will return the last |
| 734 | * read value, which in our case is those of the man_id |
| 735 | * register. Likewise, the config1 register seems to lack a |
| 736 | * low nibble, so the value will be those of the previous |
| 737 | * read, so in our case those of the man_id register. |
| 738 | */ |
| 739 | if (chip_id == man_id |
| 740 | && (address == 0x4C || address == 0x4D) |
| 741 | && (reg_config1 & 0x1F) == (man_id & 0x0F) |
| 742 | && reg_convrate <= 0x09) { |
| 743 | name = "max6657"; |
| 744 | } else |
| 745 | /* |
| 746 | * The chip_id register of the MAX6680 and MAX6681 holds the |
| 747 | * revision of the chip. The lowest bit of the config1 register |
| 748 | * is unused and should return zero when read, so should the |
| 749 | * second to last bit of config1 (software reset). |
| 750 | */ |
| 751 | if (chip_id == 0x01 |
| 752 | && (reg_config1 & 0x03) == 0x00 |
| 753 | && reg_convrate <= 0x07) { |
| 754 | name = "max6680"; |
| 755 | } else |
| 756 | /* |
| 757 | * The chip_id register of the MAX6646/6647/6649 holds the |
| 758 | * revision of the chip. The lowest 6 bits of the config1 |
| 759 | * register are unused and should return zero when read. |
| 760 | */ |
| 761 | if (chip_id == 0x59 |
| 762 | && (reg_config1 & 0x3f) == 0x00 |
| 763 | && reg_convrate <= 0x07) { |
| 764 | name = "max6646"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | } |
| 766 | } |
| 767 | |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 768 | if (!name) { /* identification failed */ |
| 769 | dev_dbg(&adapter->dev, |
| 770 | "Unsupported chip at 0x%02x (man_id=0x%02X, " |
| 771 | "chip_id=0x%02X)\n", address, man_id, chip_id); |
| 772 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | } |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 774 | |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 775 | strlcpy(info->type, name, I2C_NAME_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | static int lm90_probe(struct i2c_client *new_client, |
| 781 | const struct i2c_device_id *id) |
| 782 | { |
| 783 | struct i2c_adapter *adapter = to_i2c_adapter(new_client->dev.parent); |
| 784 | struct lm90_data *data; |
| 785 | int err; |
| 786 | |
| 787 | data = kzalloc(sizeof(struct lm90_data), GFP_KERNEL); |
| 788 | if (!data) { |
| 789 | err = -ENOMEM; |
| 790 | goto exit; |
| 791 | } |
| 792 | i2c_set_clientdata(new_client, data); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 793 | mutex_init(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 795 | /* Set the device type */ |
| 796 | data->kind = id->driver_data; |
| 797 | if (data->kind == adm1032) { |
| 798 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) |
| 799 | new_client->flags &= ~I2C_CLIENT_PEC; |
| 800 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
| 802 | /* Initialize the LM90 chip */ |
| 803 | lm90_init_client(new_client); |
| 804 | |
| 805 | /* Register sysfs hooks */ |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 806 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm90_group))) |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 807 | goto exit_free; |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 808 | if (new_client->flags & I2C_CLIENT_PEC) { |
| 809 | if ((err = device_create_file(&new_client->dev, |
| 810 | &dev_attr_pec))) |
| 811 | goto exit_remove_files; |
| 812 | } |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 813 | if (data->kind != max6657 && data->kind != max6646) { |
Jean Delvare | 69f2f96 | 2007-09-05 14:15:37 +0200 | [diff] [blame] | 814 | if ((err = device_create_file(&new_client->dev, |
| 815 | &sensor_dev_attr_temp2_offset.dev_attr))) |
| 816 | goto exit_remove_files; |
| 817 | } |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 818 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 819 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
| 820 | if (IS_ERR(data->hwmon_dev)) { |
| 821 | err = PTR_ERR(data->hwmon_dev); |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 822 | goto exit_remove_files; |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 823 | } |
| 824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | return 0; |
| 826 | |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 827 | exit_remove_files: |
| 828 | sysfs_remove_group(&new_client->dev.kobj, &lm90_group); |
| 829 | device_remove_file(&new_client->dev, &dev_attr_pec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | exit_free: |
| 831 | kfree(data); |
| 832 | exit: |
| 833 | return err; |
| 834 | } |
| 835 | |
| 836 | static void lm90_init_client(struct i2c_client *client) |
| 837 | { |
Rainer Birkenmaier | 32c82a9 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 838 | u8 config, config_orig; |
| 839 | struct lm90_data *data = i2c_get_clientdata(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
| 841 | /* |
| 842 | * Start the conversions. |
| 843 | */ |
| 844 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, |
| 845 | 5); /* 2 Hz */ |
Jean Delvare | 8256fe0 | 2005-10-26 21:37:52 +0200 | [diff] [blame] | 846 | if (lm90_read_reg(client, LM90_REG_R_CONFIG1, &config) < 0) { |
| 847 | dev_warn(&client->dev, "Initialization failed!\n"); |
| 848 | return; |
| 849 | } |
Rainer Birkenmaier | 32c82a9 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 850 | config_orig = config; |
| 851 | |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 852 | /* Check Temperature Range Select */ |
| 853 | if (data->kind == adt7461) { |
| 854 | if (config & 0x04) |
| 855 | data->flags |= LM90_FLAG_ADT7461_EXT; |
| 856 | } |
| 857 | |
Rainer Birkenmaier | 32c82a9 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 858 | /* |
| 859 | * Put MAX6680/MAX8881 into extended resolution (bit 0x10, |
| 860 | * 0.125 degree resolution) and range (0x08, extend range |
| 861 | * to -64 degree) mode for the remote temperature sensor. |
| 862 | */ |
| 863 | if (data->kind == max6680) { |
| 864 | config |= 0x18; |
| 865 | } |
| 866 | |
| 867 | config &= 0xBF; /* run */ |
| 868 | if (config != config_orig) /* Only write if changed */ |
| 869 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | } |
| 871 | |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 872 | static int lm90_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | { |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 874 | struct lm90_data *data = i2c_get_clientdata(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 876 | hwmon_device_unregister(data->hwmon_dev); |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 877 | sysfs_remove_group(&client->dev.kobj, &lm90_group); |
| 878 | device_remove_file(&client->dev, &dev_attr_pec); |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 879 | if (data->kind != max6657 && data->kind != max6646) |
Jean Delvare | 69f2f96 | 2007-09-05 14:15:37 +0200 | [diff] [blame] | 880 | device_remove_file(&client->dev, |
| 881 | &sensor_dev_attr_temp2_offset.dev_attr); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 882 | |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 883 | kfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | return 0; |
| 885 | } |
| 886 | |
Jean Delvare | 6388a38 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 887 | static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) |
| 888 | { |
| 889 | int err; |
| 890 | u8 oldh, newh, l; |
| 891 | |
| 892 | /* |
| 893 | * There is a trick here. We have to read two registers to have the |
| 894 | * sensor temperature, but we have to beware a conversion could occur |
| 895 | * inbetween the readings. The datasheet says we should either use |
| 896 | * the one-shot conversion register, which we don't want to do |
| 897 | * (disables hardware monitoring) or monitor the busy bit, which is |
| 898 | * impossible (we can't read the values and monitor that bit at the |
| 899 | * exact same time). So the solution used here is to read the high |
| 900 | * byte once, then the low byte, then the high byte again. If the new |
| 901 | * high byte matches the old one, then we have a valid reading. Else |
| 902 | * we have to read the low byte again, and now we believe we have a |
| 903 | * correct reading. |
| 904 | */ |
| 905 | if ((err = lm90_read_reg(client, regh, &oldh)) |
| 906 | || (err = lm90_read_reg(client, regl, &l)) |
| 907 | || (err = lm90_read_reg(client, regh, &newh))) |
| 908 | return err; |
| 909 | if (oldh != newh) { |
| 910 | err = lm90_read_reg(client, regl, &l); |
| 911 | if (err) |
| 912 | return err; |
| 913 | } |
| 914 | *value = (newh << 8) | l; |
| 915 | |
| 916 | return 0; |
| 917 | } |
| 918 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | static struct lm90_data *lm90_update_device(struct device *dev) |
| 920 | { |
| 921 | struct i2c_client *client = to_i2c_client(dev); |
| 922 | struct lm90_data *data = i2c_get_clientdata(client); |
| 923 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 924 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
| 926 | if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { |
Jean Delvare | 6388a38 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 927 | u8 h, l; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | |
| 929 | dev_dbg(&client->dev, "Updating lm90 data.\n"); |
Jean Delvare | f65e170 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 930 | lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, &data->temp8[0]); |
| 931 | lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, &data->temp8[1]); |
| 932 | lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, &data->temp8[2]); |
| 933 | lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[3]); |
Jean Delvare | 8256fe0 | 2005-10-26 21:37:52 +0200 | [diff] [blame] | 934 | lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 936 | if (data->kind == max6657 || data->kind == max6646) { |
Jean Delvare | f65e170 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 937 | lm90_read16(client, LM90_REG_R_LOCAL_TEMP, |
| 938 | MAX6657_REG_R_LOCAL_TEMPL, |
| 939 | &data->temp11[4]); |
| 940 | } else { |
| 941 | if (lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP, |
| 942 | &h) == 0) |
| 943 | data->temp11[4] = h << 8; |
| 944 | } |
Jean Delvare | 6388a38 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 945 | lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, |
| 946 | LM90_REG_R_REMOTE_TEMPL, &data->temp11[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | |
Jean Delvare | 5f502a8 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 948 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) { |
| 949 | data->temp11[1] = h << 8; |
| 950 | if (data->kind != max6657 && data->kind != max6680 |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 951 | && data->kind != max6646 |
Jean Delvare | 5f502a8 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 952 | && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL, |
| 953 | &l) == 0) |
| 954 | data->temp11[1] |= l; |
| 955 | } |
| 956 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) { |
| 957 | data->temp11[2] = h << 8; |
| 958 | if (data->kind != max6657 && data->kind != max6680 |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 959 | && data->kind != max6646 |
Jean Delvare | 5f502a8 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 960 | && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL, |
| 961 | &l) == 0) |
| 962 | data->temp11[2] |= l; |
| 963 | } |
| 964 | |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 965 | if (data->kind != max6657 && data->kind != max6646) { |
Jean Delvare | 69f2f96 | 2007-09-05 14:15:37 +0200 | [diff] [blame] | 966 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH, |
Jean Delvare | 6388a38 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 967 | &h) == 0 |
Jean Delvare | 69f2f96 | 2007-09-05 14:15:37 +0200 | [diff] [blame] | 968 | && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL, |
| 969 | &l) == 0) |
Jean Delvare | 6388a38 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 970 | data->temp11[3] = (h << 8) | l; |
Jean Delvare | 69f2f96 | 2007-09-05 14:15:37 +0200 | [diff] [blame] | 971 | } |
Jean Delvare | 8256fe0 | 2005-10-26 21:37:52 +0200 | [diff] [blame] | 972 | lm90_read_reg(client, LM90_REG_R_STATUS, &data->alarms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | |
| 974 | data->last_updated = jiffies; |
| 975 | data->valid = 1; |
| 976 | } |
| 977 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 978 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | |
| 980 | return data; |
| 981 | } |
| 982 | |
| 983 | static int __init sensors_lm90_init(void) |
| 984 | { |
| 985 | return i2c_add_driver(&lm90_driver); |
| 986 | } |
| 987 | |
| 988 | static void __exit sensors_lm90_exit(void) |
| 989 | { |
| 990 | i2c_del_driver(&lm90_driver); |
| 991 | } |
| 992 | |
| 993 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); |
| 994 | MODULE_DESCRIPTION("LM90/ADM1032 driver"); |
| 995 | MODULE_LICENSE("GPL"); |
| 996 | |
| 997 | module_init(sensors_lm90_init); |
| 998 | module_exit(sensors_lm90_exit); |