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