Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * lm63.c - driver for the National Semiconductor LM63 temperature sensor |
| 3 | * with integrated fan control |
Jean Delvare | 7c81c60 | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 4 | * Copyright (C) 2004-2008 Jean Delvare <jdelvare@suse.de> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Based on the lm90 driver. |
| 6 | * |
| 7 | * The LM63 is a sensor chip made by National Semiconductor. It measures |
| 8 | * two temperatures (its own and one external one) and the speed of one |
| 9 | * fan, those speed it can additionally control. Complete datasheet can be |
| 10 | * obtained from National's website at: |
| 11 | * http://www.national.com/pf/LM/LM63.html |
| 12 | * |
| 13 | * The LM63 is basically an LM86 with fan speed monitoring and control |
| 14 | * capabilities added. It misses some of the LM86 features though: |
| 15 | * - No low limit for local temperature. |
| 16 | * - No critical limit for local temperature. |
| 17 | * - Critical limit for remote temperature can be changed only once. We |
| 18 | * will consider that the critical limit is read-only. |
| 19 | * |
| 20 | * The datasheet isn't very clear about what the tachometer reading is. |
| 21 | * I had a explanation from National Semiconductor though. The two lower |
| 22 | * bits of the read value have to be masked out. The value is still 16 bit |
| 23 | * in width. |
| 24 | * |
| 25 | * This program is free software; you can redistribute it and/or modify |
| 26 | * it under the terms of the GNU General Public License as published by |
| 27 | * the Free Software Foundation; either version 2 of the License, or |
| 28 | * (at your option) any later version. |
| 29 | * |
| 30 | * This program is distributed in the hope that it will be useful, |
| 31 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 33 | * GNU General Public License for more details. |
| 34 | * |
| 35 | * You should have received a copy of the GNU General Public License |
| 36 | * along with this program; if not, write to the Free Software |
| 37 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 38 | */ |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/module.h> |
| 41 | #include <linux/init.h> |
| 42 | #include <linux/slab.h> |
| 43 | #include <linux/jiffies.h> |
| 44 | #include <linux/i2c.h> |
Jean Delvare | 10c08f8 | 2005-06-06 19:34:45 +0200 | [diff] [blame] | 45 | #include <linux/hwmon-sysfs.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 46 | #include <linux/hwmon.h> |
| 47 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 48 | #include <linux/mutex.h> |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 49 | #include <linux/sysfs.h> |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 50 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * Addresses to scan |
Jean Delvare | d93ab78 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 54 | * Address is fully defined internally and cannot be changed except for |
| 55 | * LM64 which has one pin dedicated to address selection. |
| 56 | * LM63 and LM96163 have address 0x4c. |
| 57 | * LM64 can have address 0x18 or 0x4e. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | */ |
| 59 | |
Matthew Garrett | 10f2ed3 | 2010-05-27 19:58:38 +0200 | [diff] [blame] | 60 | static const unsigned short normal_i2c[] = { 0x18, 0x4c, 0x4e, I2C_CLIENT_END }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | * The LM63 registers |
| 64 | */ |
| 65 | |
| 66 | #define LM63_REG_CONFIG1 0x03 |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 67 | #define LM63_REG_CONVRATE 0x04 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #define LM63_REG_CONFIG2 0xBF |
| 69 | #define LM63_REG_CONFIG_FAN 0x4A |
| 70 | |
| 71 | #define LM63_REG_TACH_COUNT_MSB 0x47 |
| 72 | #define LM63_REG_TACH_COUNT_LSB 0x46 |
| 73 | #define LM63_REG_TACH_LIMIT_MSB 0x49 |
| 74 | #define LM63_REG_TACH_LIMIT_LSB 0x48 |
| 75 | |
| 76 | #define LM63_REG_PWM_VALUE 0x4C |
| 77 | #define LM63_REG_PWM_FREQ 0x4D |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 78 | #define LM63_REG_LUT_TEMP_HYST 0x4F |
| 79 | #define LM63_REG_LUT_TEMP(nr) (0x50 + 2 * (nr)) |
| 80 | #define LM63_REG_LUT_PWM(nr) (0x51 + 2 * (nr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | #define LM63_REG_LOCAL_TEMP 0x00 |
| 83 | #define LM63_REG_LOCAL_HIGH 0x05 |
| 84 | |
| 85 | #define LM63_REG_REMOTE_TEMP_MSB 0x01 |
| 86 | #define LM63_REG_REMOTE_TEMP_LSB 0x10 |
| 87 | #define LM63_REG_REMOTE_OFFSET_MSB 0x11 |
| 88 | #define LM63_REG_REMOTE_OFFSET_LSB 0x12 |
| 89 | #define LM63_REG_REMOTE_HIGH_MSB 0x07 |
| 90 | #define LM63_REG_REMOTE_HIGH_LSB 0x13 |
| 91 | #define LM63_REG_REMOTE_LOW_MSB 0x08 |
| 92 | #define LM63_REG_REMOTE_LOW_LSB 0x14 |
| 93 | #define LM63_REG_REMOTE_TCRIT 0x19 |
| 94 | #define LM63_REG_REMOTE_TCRIT_HYST 0x21 |
| 95 | |
| 96 | #define LM63_REG_ALERT_STATUS 0x02 |
| 97 | #define LM63_REG_ALERT_MASK 0x16 |
| 98 | |
| 99 | #define LM63_REG_MAN_ID 0xFE |
| 100 | #define LM63_REG_CHIP_ID 0xFF |
| 101 | |
Guenter Roeck | f496b2d | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 102 | #define LM96163_REG_TRUTHERM 0x30 |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 103 | #define LM96163_REG_REMOTE_TEMP_U_MSB 0x31 |
| 104 | #define LM96163_REG_REMOTE_TEMP_U_LSB 0x32 |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 105 | #define LM96163_REG_CONFIG_ENHANCED 0x45 |
| 106 | |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 107 | #define LM63_MAX_CONVRATE 9 |
| 108 | |
| 109 | #define LM63_MAX_CONVRATE_HZ 32 |
| 110 | #define LM96163_MAX_CONVRATE_HZ 26 |
| 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | /* |
| 113 | * Conversions and various macros |
| 114 | * For tachometer counts, the LM63 uses 16-bit values. |
| 115 | * For local temperature and high limit, remote critical limit and hysteresis |
Steven Cole | 44bbe87 | 2005-05-03 18:21:25 -0600 | [diff] [blame] | 116 | * value, it uses signed 8-bit values with LSB = 1 degree Celsius. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | * For remote temperature, low and high limits, it uses signed 11-bit values |
Steven Cole | 44bbe87 | 2005-05-03 18:21:25 -0600 | [diff] [blame] | 118 | * with LSB = 0.125 degree Celsius, left-justified in 16-bit registers. |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 119 | * For LM64 the actual remote diode temperature is 16 degree Celsius higher |
| 120 | * than the register reading. Remote temperature setpoints have to be |
| 121 | * adapted accordingly. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | */ |
| 123 | |
| 124 | #define FAN_FROM_REG(reg) ((reg) == 0xFFFC || (reg) == 0 ? 0 : \ |
| 125 | 5400000 / (reg)) |
| 126 | #define FAN_TO_REG(val) ((val) <= 82 ? 0xFFFC : \ |
| 127 | (5400000 / (val)) & 0xFFFC) |
| 128 | #define TEMP8_FROM_REG(reg) ((reg) * 1000) |
| 129 | #define TEMP8_TO_REG(val) ((val) <= -128000 ? -128 : \ |
| 130 | (val) >= 127000 ? 127 : \ |
| 131 | (val) < 0 ? ((val) - 500) / 1000 : \ |
| 132 | ((val) + 500) / 1000) |
Guenter Roeck | 94e55df | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 133 | #define TEMP8U_TO_REG(val) ((val) <= 0 ? 0 : \ |
| 134 | (val) >= 255000 ? 255 : \ |
| 135 | ((val) + 500) / 1000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125) |
| 137 | #define TEMP11_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ |
| 138 | (val) >= 127875 ? 0x7FE0 : \ |
| 139 | (val) < 0 ? ((val) - 62) / 125 * 32 : \ |
| 140 | ((val) + 62) / 125 * 32) |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 141 | #define TEMP11U_TO_REG(val) ((val) <= 0 ? 0 : \ |
| 142 | (val) >= 255875 ? 0xFFE0 : \ |
| 143 | ((val) + 62) / 125 * 32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | #define HYST_TO_REG(val) ((val) <= 0 ? 0 : \ |
| 145 | (val) >= 127000 ? 127 : \ |
| 146 | ((val) + 500) / 1000) |
| 147 | |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 148 | #define UPDATE_INTERVAL(max, rate) \ |
| 149 | ((1000 << (LM63_MAX_CONVRATE - (rate))) / (max)) |
| 150 | |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 151 | enum chips { lm63, lm64, lm96163 }; |
Matthew Garrett | 10f2ed3 | 2010-05-27 19:58:38 +0200 | [diff] [blame] | 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | * Client data (each client gets its own) |
| 155 | */ |
| 156 | |
| 157 | struct lm63_data { |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 158 | struct device *hwmon_dev; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 159 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | char valid; /* zero until following fields are valid */ |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 161 | char lut_valid; /* zero until lut fields are valid */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | unsigned long last_updated; /* in jiffies */ |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 163 | unsigned long lut_last_updated; /* in jiffies */ |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 164 | enum chips kind; |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 165 | int temp2_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 167 | int update_interval; /* in milliseconds */ |
| 168 | int max_convrate_hz; |
Jean Delvare | 2fe28ab | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 169 | int lut_size; /* 8 or 12 */ |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | /* registers values */ |
| 172 | u8 config, config_fan; |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 173 | u16 fan[2]; /* 0: input |
| 174 | 1: low limit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | u8 pwm1_freq; |
Jean Delvare | 2fe28ab | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 176 | u8 pwm1[13]; /* 0: current output |
| 177 | 1-12: lookup table */ |
| 178 | s8 temp8[15]; /* 0: local input |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 179 | 1: local high limit |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 180 | 2: remote critical limit |
Jean Delvare | 2fe28ab | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 181 | 3-14: lookup table */ |
Guenter Roeck | 786375f | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 182 | s16 temp11[4]; /* 0: remote input |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 183 | 1: remote low limit |
Guenter Roeck | 786375f | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 184 | 2: remote high limit |
| 185 | 3: remote offset */ |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 186 | u16 temp11u; /* remote input (unsigned) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | u8 temp2_crit_hyst; |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 188 | u8 lut_temp_hyst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | u8 alarms; |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 190 | bool pwm_highres; |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 191 | bool lut_temp_highres; |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 192 | bool remote_unsigned; /* true if unsigned remote upper limits */ |
Guenter Roeck | f496b2d | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 193 | bool trutherm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 196 | static inline int temp8_from_reg(struct lm63_data *data, int nr) |
| 197 | { |
| 198 | if (data->remote_unsigned) |
| 199 | return TEMP8_FROM_REG((u8)data->temp8[nr]); |
| 200 | return TEMP8_FROM_REG(data->temp8[nr]); |
| 201 | } |
| 202 | |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 203 | static inline int lut_temp_from_reg(struct lm63_data *data, int nr) |
| 204 | { |
| 205 | return data->temp8[nr] * (data->lut_temp_highres ? 500 : 1000); |
| 206 | } |
| 207 | |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 208 | static inline int lut_temp_to_reg(struct lm63_data *data, long val) |
| 209 | { |
| 210 | val -= data->temp2_offset; |
| 211 | if (data->lut_temp_highres) |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 212 | return DIV_ROUND_CLOSEST(clamp_val(val, 0, 127500), 500); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 213 | else |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 214 | return DIV_ROUND_CLOSEST(clamp_val(val, 0, 127000), 1000); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 215 | } |
| 216 | |
Jean Delvare | 817c6cc | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 217 | /* |
| 218 | * Update the lookup table register cache. |
| 219 | * client->update_lock must be held when calling this function. |
| 220 | */ |
| 221 | static void lm63_update_lut(struct i2c_client *client) |
| 222 | { |
| 223 | struct lm63_data *data = i2c_get_clientdata(client); |
| 224 | int i; |
| 225 | |
| 226 | if (time_after(jiffies, data->lut_last_updated + 5 * HZ) || |
| 227 | !data->lut_valid) { |
| 228 | for (i = 0; i < data->lut_size; i++) { |
| 229 | data->pwm1[1 + i] = i2c_smbus_read_byte_data(client, |
| 230 | LM63_REG_LUT_PWM(i)); |
| 231 | data->temp8[3 + i] = i2c_smbus_read_byte_data(client, |
| 232 | LM63_REG_LUT_TEMP(i)); |
| 233 | } |
| 234 | data->lut_temp_hyst = i2c_smbus_read_byte_data(client, |
| 235 | LM63_REG_LUT_TEMP_HYST); |
| 236 | |
| 237 | data->lut_last_updated = jiffies; |
| 238 | data->lut_valid = 1; |
| 239 | } |
| 240 | } |
| 241 | |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 242 | static struct lm63_data *lm63_update_device(struct device *dev) |
| 243 | { |
| 244 | struct i2c_client *client = to_i2c_client(dev); |
| 245 | struct lm63_data *data = i2c_get_clientdata(client); |
| 246 | unsigned long next_update; |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 247 | |
| 248 | mutex_lock(&data->update_lock); |
| 249 | |
Jean Delvare | 5b0620d | 2013-07-08 14:18:24 +0200 | [diff] [blame] | 250 | next_update = data->last_updated + |
| 251 | msecs_to_jiffies(data->update_interval); |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 252 | if (time_after(jiffies, next_update) || !data->valid) { |
| 253 | if (data->config & 0x04) { /* tachometer enabled */ |
| 254 | /* order matters for fan1_input */ |
| 255 | data->fan[0] = i2c_smbus_read_byte_data(client, |
| 256 | LM63_REG_TACH_COUNT_LSB) & 0xFC; |
| 257 | data->fan[0] |= i2c_smbus_read_byte_data(client, |
| 258 | LM63_REG_TACH_COUNT_MSB) << 8; |
| 259 | data->fan[1] = (i2c_smbus_read_byte_data(client, |
| 260 | LM63_REG_TACH_LIMIT_LSB) & 0xFC) |
| 261 | | (i2c_smbus_read_byte_data(client, |
| 262 | LM63_REG_TACH_LIMIT_MSB) << 8); |
| 263 | } |
| 264 | |
| 265 | data->pwm1_freq = i2c_smbus_read_byte_data(client, |
| 266 | LM63_REG_PWM_FREQ); |
| 267 | if (data->pwm1_freq == 0) |
| 268 | data->pwm1_freq = 1; |
| 269 | data->pwm1[0] = i2c_smbus_read_byte_data(client, |
| 270 | LM63_REG_PWM_VALUE); |
| 271 | |
| 272 | data->temp8[0] = i2c_smbus_read_byte_data(client, |
| 273 | LM63_REG_LOCAL_TEMP); |
| 274 | data->temp8[1] = i2c_smbus_read_byte_data(client, |
| 275 | LM63_REG_LOCAL_HIGH); |
| 276 | |
| 277 | /* order matters for temp2_input */ |
| 278 | data->temp11[0] = i2c_smbus_read_byte_data(client, |
| 279 | LM63_REG_REMOTE_TEMP_MSB) << 8; |
| 280 | data->temp11[0] |= i2c_smbus_read_byte_data(client, |
| 281 | LM63_REG_REMOTE_TEMP_LSB); |
| 282 | data->temp11[1] = (i2c_smbus_read_byte_data(client, |
| 283 | LM63_REG_REMOTE_LOW_MSB) << 8) |
| 284 | | i2c_smbus_read_byte_data(client, |
| 285 | LM63_REG_REMOTE_LOW_LSB); |
| 286 | data->temp11[2] = (i2c_smbus_read_byte_data(client, |
| 287 | LM63_REG_REMOTE_HIGH_MSB) << 8) |
| 288 | | i2c_smbus_read_byte_data(client, |
| 289 | LM63_REG_REMOTE_HIGH_LSB); |
| 290 | data->temp11[3] = (i2c_smbus_read_byte_data(client, |
| 291 | LM63_REG_REMOTE_OFFSET_MSB) << 8) |
| 292 | | i2c_smbus_read_byte_data(client, |
| 293 | LM63_REG_REMOTE_OFFSET_LSB); |
| 294 | |
| 295 | if (data->kind == lm96163) |
| 296 | data->temp11u = (i2c_smbus_read_byte_data(client, |
| 297 | LM96163_REG_REMOTE_TEMP_U_MSB) << 8) |
| 298 | | i2c_smbus_read_byte_data(client, |
| 299 | LM96163_REG_REMOTE_TEMP_U_LSB); |
| 300 | |
| 301 | data->temp8[2] = i2c_smbus_read_byte_data(client, |
| 302 | LM63_REG_REMOTE_TCRIT); |
| 303 | data->temp2_crit_hyst = i2c_smbus_read_byte_data(client, |
| 304 | LM63_REG_REMOTE_TCRIT_HYST); |
| 305 | |
| 306 | data->alarms = i2c_smbus_read_byte_data(client, |
| 307 | LM63_REG_ALERT_STATUS) & 0x7F; |
| 308 | |
| 309 | data->last_updated = jiffies; |
| 310 | data->valid = 1; |
| 311 | } |
| 312 | |
Jean Delvare | 817c6cc | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 313 | lm63_update_lut(client); |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 314 | |
| 315 | mutex_unlock(&data->update_lock); |
| 316 | |
| 317 | return data; |
| 318 | } |
| 319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | /* |
Jean Delvare | 817c6cc | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 321 | * Trip points in the lookup table should be in ascending order for both |
| 322 | * temperatures and PWM output values. |
| 323 | */ |
| 324 | static int lm63_lut_looks_bad(struct i2c_client *client) |
| 325 | { |
| 326 | struct lm63_data *data = i2c_get_clientdata(client); |
| 327 | int i; |
| 328 | |
| 329 | mutex_lock(&data->update_lock); |
| 330 | lm63_update_lut(client); |
| 331 | |
| 332 | for (i = 1; i < data->lut_size; i++) { |
| 333 | if (data->pwm1[1 + i - 1] > data->pwm1[1 + i] |
| 334 | || data->temp8[3 + i - 1] > data->temp8[3 + i]) { |
| 335 | dev_warn(&client->dev, |
| 336 | "Lookup table doesn't look sane (check entries %d and %d)\n", |
| 337 | i, i + 1); |
| 338 | break; |
| 339 | } |
| 340 | } |
| 341 | mutex_unlock(&data->update_lock); |
| 342 | |
| 343 | return i == data->lut_size ? 0 : 1; |
| 344 | } |
| 345 | |
| 346 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | * Sysfs callback functions and files |
| 348 | */ |
| 349 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 350 | static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, |
| 351 | char *buf) |
| 352 | { |
| 353 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 354 | struct lm63_data *data = lm63_update_device(dev); |
| 355 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 358 | static ssize_t set_fan(struct device *dev, struct device_attribute *dummy, |
| 359 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | { |
| 361 | struct i2c_client *client = to_i2c_client(dev); |
| 362 | struct lm63_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 363 | unsigned long val; |
| 364 | int err; |
| 365 | |
| 366 | err = kstrtoul(buf, 10, &val); |
| 367 | if (err) |
| 368 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 370 | mutex_lock(&data->update_lock); |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 371 | data->fan[1] = FAN_TO_REG(val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB, |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 373 | data->fan[1] & 0xFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB, |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 375 | data->fan[1] >> 8); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 376 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | return count; |
| 378 | } |
| 379 | |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 380 | static ssize_t show_pwm1(struct device *dev, struct device_attribute *devattr, |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 381 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 383 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | struct lm63_data *data = lm63_update_device(dev); |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 385 | int nr = attr->index; |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 386 | int pwm; |
| 387 | |
| 388 | if (data->pwm_highres) |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 389 | pwm = data->pwm1[nr]; |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 390 | else |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 391 | pwm = data->pwm1[nr] >= 2 * data->pwm1_freq ? |
| 392 | 255 : (data->pwm1[nr] * 255 + data->pwm1_freq) / |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 393 | (2 * data->pwm1_freq); |
| 394 | |
| 395 | return sprintf(buf, "%d\n", pwm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 398 | static ssize_t set_pwm1(struct device *dev, struct device_attribute *devattr, |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 399 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | { |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 401 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | struct i2c_client *client = to_i2c_client(dev); |
| 403 | struct lm63_data *data = i2c_get_clientdata(client); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 404 | int nr = attr->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | unsigned long val; |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 406 | int err; |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 407 | u8 reg; |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | if (!(data->config_fan & 0x20)) /* register is read-only */ |
| 410 | return -EPERM; |
| 411 | |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 412 | err = kstrtoul(buf, 10, &val); |
| 413 | if (err) |
| 414 | return err; |
| 415 | |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 416 | reg = nr ? LM63_REG_LUT_PWM(nr - 1) : LM63_REG_PWM_VALUE; |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 417 | val = clamp_val(val, 0, 255); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 418 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 419 | mutex_lock(&data->update_lock); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 420 | data->pwm1[nr] = data->pwm_highres ? val : |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 421 | (val * data->pwm1_freq * 2 + 127) / 255; |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 422 | i2c_smbus_write_byte_data(client, reg, data->pwm1[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 423 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | return count; |
| 425 | } |
| 426 | |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 427 | static ssize_t show_pwm1_enable(struct device *dev, |
| 428 | struct device_attribute *dummy, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | { |
| 430 | struct lm63_data *data = lm63_update_device(dev); |
| 431 | return sprintf(buf, "%d\n", data->config_fan & 0x20 ? 1 : 2); |
| 432 | } |
| 433 | |
Jean Delvare | 817c6cc | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 434 | static ssize_t set_pwm1_enable(struct device *dev, |
| 435 | struct device_attribute *dummy, |
| 436 | const char *buf, size_t count) |
| 437 | { |
| 438 | struct i2c_client *client = to_i2c_client(dev); |
| 439 | struct lm63_data *data = i2c_get_clientdata(client); |
| 440 | unsigned long val; |
| 441 | int err; |
| 442 | |
| 443 | err = kstrtoul(buf, 10, &val); |
| 444 | if (err) |
| 445 | return err; |
| 446 | if (val < 1 || val > 2) |
| 447 | return -EINVAL; |
| 448 | |
| 449 | /* |
| 450 | * Only let the user switch to automatic mode if the lookup table |
| 451 | * looks sane. |
| 452 | */ |
| 453 | if (val == 2 && lm63_lut_looks_bad(client)) |
| 454 | return -EPERM; |
| 455 | |
| 456 | mutex_lock(&data->update_lock); |
| 457 | data->config_fan = i2c_smbus_read_byte_data(client, |
| 458 | LM63_REG_CONFIG_FAN); |
| 459 | if (val == 1) |
| 460 | data->config_fan |= 0x20; |
| 461 | else |
| 462 | data->config_fan &= ~0x20; |
| 463 | i2c_smbus_write_byte_data(client, LM63_REG_CONFIG_FAN, |
| 464 | data->config_fan); |
| 465 | mutex_unlock(&data->update_lock); |
| 466 | return count; |
| 467 | } |
| 468 | |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 469 | /* |
| 470 | * There are 8bit registers for both local(temp1) and remote(temp2) sensor. |
| 471 | * For remote sensor registers temp2_offset has to be considered, |
| 472 | * for local sensor it must not. |
| 473 | * So we need separate 8bit accessors for local and remote sensor. |
| 474 | */ |
| 475 | static ssize_t show_local_temp8(struct device *dev, |
| 476 | struct device_attribute *devattr, |
| 477 | char *buf) |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 478 | { |
| 479 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 480 | struct lm63_data *data = lm63_update_device(dev); |
| 481 | return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[attr->index])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 484 | static ssize_t show_remote_temp8(struct device *dev, |
| 485 | struct device_attribute *devattr, |
| 486 | char *buf) |
| 487 | { |
| 488 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 489 | struct lm63_data *data = lm63_update_device(dev); |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 490 | return sprintf(buf, "%d\n", temp8_from_reg(data, attr->index) |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 491 | + data->temp2_offset); |
| 492 | } |
| 493 | |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 494 | static ssize_t show_lut_temp(struct device *dev, |
| 495 | struct device_attribute *devattr, |
| 496 | char *buf) |
| 497 | { |
| 498 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 499 | struct lm63_data *data = lm63_update_device(dev); |
| 500 | return sprintf(buf, "%d\n", lut_temp_from_reg(data, attr->index) |
| 501 | + data->temp2_offset); |
| 502 | } |
| 503 | |
Guenter Roeck | 94e55df | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 504 | static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, |
| 505 | const char *buf, size_t count) |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 506 | { |
Guenter Roeck | 94e55df | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 507 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 508 | struct i2c_client *client = to_i2c_client(dev); |
| 509 | struct lm63_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 94e55df | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 510 | int nr = attr->index; |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 511 | long val; |
| 512 | int err; |
Guenter Roeck | 94e55df | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 513 | int temp; |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 514 | u8 reg; |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 515 | |
| 516 | err = kstrtol(buf, 10, &val); |
| 517 | if (err) |
| 518 | return err; |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 519 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 520 | mutex_lock(&data->update_lock); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 521 | switch (nr) { |
| 522 | case 2: |
| 523 | reg = LM63_REG_REMOTE_TCRIT; |
Guenter Roeck | 94e55df | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 524 | if (data->remote_unsigned) |
| 525 | temp = TEMP8U_TO_REG(val - data->temp2_offset); |
| 526 | else |
| 527 | temp = TEMP8_TO_REG(val - data->temp2_offset); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 528 | break; |
| 529 | case 1: |
| 530 | reg = LM63_REG_LOCAL_HIGH; |
Guenter Roeck | 94e55df | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 531 | temp = TEMP8_TO_REG(val); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 532 | break; |
| 533 | default: /* lookup table */ |
| 534 | reg = LM63_REG_LUT_TEMP(nr - 3); |
| 535 | temp = lut_temp_to_reg(data, val); |
Guenter Roeck | 94e55df | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 536 | } |
| 537 | data->temp8[nr] = temp; |
| 538 | i2c_smbus_write_byte_data(client, reg, temp); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 539 | mutex_unlock(&data->update_lock); |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 540 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | } |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 542 | |
| 543 | static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, |
| 544 | char *buf) |
| 545 | { |
| 546 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 547 | struct lm63_data *data = lm63_update_device(dev); |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 548 | int nr = attr->index; |
| 549 | int temp; |
| 550 | |
| 551 | if (!nr) { |
| 552 | /* |
| 553 | * Use unsigned temperature unless its value is zero. |
| 554 | * If it is zero, use signed temperature. |
| 555 | */ |
| 556 | if (data->temp11u) |
| 557 | temp = TEMP11_FROM_REG(data->temp11u); |
| 558 | else |
| 559 | temp = TEMP11_FROM_REG(data->temp11[nr]); |
| 560 | } else { |
| 561 | if (data->remote_unsigned && nr == 2) |
| 562 | temp = TEMP11_FROM_REG((u16)data->temp11[nr]); |
| 563 | else |
| 564 | temp = TEMP11_FROM_REG(data->temp11[nr]); |
| 565 | } |
| 566 | return sprintf(buf, "%d\n", temp + data->temp2_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | } |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 568 | |
| 569 | static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, |
| 570 | const char *buf, size_t count) |
| 571 | { |
Guenter Roeck | 786375f | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 572 | static const u8 reg[6] = { |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 573 | LM63_REG_REMOTE_LOW_MSB, |
| 574 | LM63_REG_REMOTE_LOW_LSB, |
| 575 | LM63_REG_REMOTE_HIGH_MSB, |
| 576 | LM63_REG_REMOTE_HIGH_LSB, |
Guenter Roeck | 786375f | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 577 | LM63_REG_REMOTE_OFFSET_MSB, |
| 578 | LM63_REG_REMOTE_OFFSET_LSB, |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 579 | }; |
| 580 | |
| 581 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 582 | struct i2c_client *client = to_i2c_client(dev); |
| 583 | struct lm63_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 584 | long val; |
| 585 | int err; |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 586 | int nr = attr->index; |
| 587 | |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 588 | err = kstrtol(buf, 10, &val); |
| 589 | if (err) |
| 590 | return err; |
| 591 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 592 | mutex_lock(&data->update_lock); |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 593 | if (data->remote_unsigned && nr == 2) |
| 594 | data->temp11[nr] = TEMP11U_TO_REG(val - data->temp2_offset); |
| 595 | else |
| 596 | data->temp11[nr] = TEMP11_TO_REG(val - data->temp2_offset); |
| 597 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 598 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], |
| 599 | data->temp11[nr] >> 8); |
| 600 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], |
| 601 | data->temp11[nr] & 0xff); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 602 | mutex_unlock(&data->update_lock); |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 603 | return count; |
| 604 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 606 | /* |
| 607 | * Hysteresis register holds a relative value, while we want to present |
| 608 | * an absolute to user-space |
| 609 | */ |
| 610 | static ssize_t show_temp2_crit_hyst(struct device *dev, |
| 611 | struct device_attribute *dummy, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | { |
| 613 | struct lm63_data *data = lm63_update_device(dev); |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 614 | return sprintf(buf, "%d\n", temp8_from_reg(data, 2) |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 615 | + data->temp2_offset |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | - TEMP8_FROM_REG(data->temp2_crit_hyst)); |
| 617 | } |
| 618 | |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 619 | static ssize_t show_lut_temp_hyst(struct device *dev, |
| 620 | struct device_attribute *devattr, char *buf) |
| 621 | { |
| 622 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 623 | struct lm63_data *data = lm63_update_device(dev); |
| 624 | |
| 625 | return sprintf(buf, "%d\n", lut_temp_from_reg(data, attr->index) |
| 626 | + data->temp2_offset |
| 627 | - TEMP8_FROM_REG(data->lut_temp_hyst)); |
| 628 | } |
| 629 | |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 630 | /* |
| 631 | * And now the other way around, user-space provides an absolute |
| 632 | * hysteresis value and we have to store a relative one |
| 633 | */ |
| 634 | static ssize_t set_temp2_crit_hyst(struct device *dev, |
| 635 | struct device_attribute *dummy, |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 636 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | { |
| 638 | struct i2c_client *client = to_i2c_client(dev); |
| 639 | struct lm63_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 640 | long val; |
| 641 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | long hyst; |
| 643 | |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 644 | err = kstrtol(buf, 10, &val); |
| 645 | if (err) |
| 646 | return err; |
| 647 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 648 | mutex_lock(&data->update_lock); |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 649 | hyst = temp8_from_reg(data, 2) + data->temp2_offset - val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST, |
| 651 | HYST_TO_REG(hyst)); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 652 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | return count; |
| 654 | } |
| 655 | |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 656 | /* |
| 657 | * Set conversion rate. |
| 658 | * client->update_lock must be held when calling this function. |
| 659 | */ |
| 660 | static void lm63_set_convrate(struct i2c_client *client, struct lm63_data *data, |
| 661 | unsigned int interval) |
| 662 | { |
| 663 | int i; |
| 664 | unsigned int update_interval; |
| 665 | |
| 666 | /* Shift calculations to avoid rounding errors */ |
| 667 | interval <<= 6; |
| 668 | |
| 669 | /* find the nearest update rate */ |
| 670 | update_interval = (1 << (LM63_MAX_CONVRATE + 6)) * 1000 |
| 671 | / data->max_convrate_hz; |
| 672 | for (i = 0; i < LM63_MAX_CONVRATE; i++, update_interval >>= 1) |
| 673 | if (interval >= update_interval * 3 / 4) |
| 674 | break; |
| 675 | |
| 676 | i2c_smbus_write_byte_data(client, LM63_REG_CONVRATE, i); |
| 677 | data->update_interval = UPDATE_INTERVAL(data->max_convrate_hz, i); |
| 678 | } |
| 679 | |
| 680 | static ssize_t show_update_interval(struct device *dev, |
| 681 | struct device_attribute *attr, char *buf) |
| 682 | { |
| 683 | struct lm63_data *data = dev_get_drvdata(dev); |
| 684 | |
| 685 | return sprintf(buf, "%u\n", data->update_interval); |
| 686 | } |
| 687 | |
| 688 | static ssize_t set_update_interval(struct device *dev, |
| 689 | struct device_attribute *attr, |
| 690 | const char *buf, size_t count) |
| 691 | { |
| 692 | struct i2c_client *client = to_i2c_client(dev); |
| 693 | struct lm63_data *data = i2c_get_clientdata(client); |
| 694 | unsigned long val; |
| 695 | int err; |
| 696 | |
| 697 | err = kstrtoul(buf, 10, &val); |
| 698 | if (err) |
| 699 | return err; |
| 700 | |
| 701 | mutex_lock(&data->update_lock); |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 702 | lm63_set_convrate(client, data, clamp_val(val, 0, 100000)); |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 703 | mutex_unlock(&data->update_lock); |
| 704 | |
| 705 | return count; |
| 706 | } |
| 707 | |
Guenter Roeck | f496b2d | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 708 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, |
| 709 | char *buf) |
| 710 | { |
| 711 | struct i2c_client *client = to_i2c_client(dev); |
| 712 | struct lm63_data *data = i2c_get_clientdata(client); |
| 713 | |
| 714 | return sprintf(buf, data->trutherm ? "1\n" : "2\n"); |
| 715 | } |
| 716 | |
| 717 | static ssize_t set_type(struct device *dev, struct device_attribute *attr, |
| 718 | const char *buf, size_t count) |
| 719 | { |
| 720 | struct i2c_client *client = to_i2c_client(dev); |
| 721 | struct lm63_data *data = i2c_get_clientdata(client); |
| 722 | unsigned long val; |
| 723 | int ret; |
| 724 | u8 reg; |
| 725 | |
| 726 | ret = kstrtoul(buf, 10, &val); |
| 727 | if (ret < 0) |
| 728 | return ret; |
| 729 | if (val != 1 && val != 2) |
| 730 | return -EINVAL; |
| 731 | |
| 732 | mutex_lock(&data->update_lock); |
| 733 | data->trutherm = val == 1; |
| 734 | reg = i2c_smbus_read_byte_data(client, LM96163_REG_TRUTHERM) & ~0x02; |
| 735 | i2c_smbus_write_byte_data(client, LM96163_REG_TRUTHERM, |
| 736 | reg | (data->trutherm ? 0x02 : 0x00)); |
| 737 | data->valid = 0; |
| 738 | mutex_unlock(&data->update_lock); |
| 739 | |
| 740 | return count; |
| 741 | } |
| 742 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 743 | static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy, |
| 744 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | { |
| 746 | struct lm63_data *data = lm63_update_device(dev); |
| 747 | return sprintf(buf, "%u\n", data->alarms); |
| 748 | } |
| 749 | |
Jean Delvare | 2d45771 | 2006-09-24 20:52:15 +0200 | [diff] [blame] | 750 | static ssize_t show_alarm(struct device *dev, struct device_attribute *devattr, |
| 751 | char *buf) |
| 752 | { |
| 753 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 754 | struct lm63_data *data = lm63_update_device(dev); |
| 755 | int bitnr = attr->index; |
| 756 | |
| 757 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); |
| 758 | } |
| 759 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 760 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); |
| 761 | static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan, |
| 762 | set_fan, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 764 | static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm1, set_pwm1, 0); |
Jean Delvare | 817c6cc | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 765 | static DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, |
| 766 | show_pwm1_enable, set_pwm1_enable); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 767 | static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IWUSR | S_IRUGO, |
| 768 | show_pwm1, set_pwm1, 1); |
| 769 | static SENSOR_DEVICE_ATTR(pwm1_auto_point1_temp, S_IWUSR | S_IRUGO, |
| 770 | show_lut_temp, set_temp8, 3); |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 771 | static SENSOR_DEVICE_ATTR(pwm1_auto_point1_temp_hyst, S_IRUGO, |
| 772 | show_lut_temp_hyst, NULL, 3); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 773 | static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO, |
| 774 | show_pwm1, set_pwm1, 2); |
| 775 | static SENSOR_DEVICE_ATTR(pwm1_auto_point2_temp, S_IWUSR | S_IRUGO, |
| 776 | show_lut_temp, set_temp8, 4); |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 777 | static SENSOR_DEVICE_ATTR(pwm1_auto_point2_temp_hyst, S_IRUGO, |
| 778 | show_lut_temp_hyst, NULL, 4); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 779 | static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IWUSR | S_IRUGO, |
| 780 | show_pwm1, set_pwm1, 3); |
| 781 | static SENSOR_DEVICE_ATTR(pwm1_auto_point3_temp, S_IWUSR | S_IRUGO, |
| 782 | show_lut_temp, set_temp8, 5); |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 783 | static SENSOR_DEVICE_ATTR(pwm1_auto_point3_temp_hyst, S_IRUGO, |
| 784 | show_lut_temp_hyst, NULL, 5); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 785 | static SENSOR_DEVICE_ATTR(pwm1_auto_point4_pwm, S_IWUSR | S_IRUGO, |
| 786 | show_pwm1, set_pwm1, 4); |
| 787 | static SENSOR_DEVICE_ATTR(pwm1_auto_point4_temp, S_IWUSR | S_IRUGO, |
| 788 | show_lut_temp, set_temp8, 6); |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 789 | static SENSOR_DEVICE_ATTR(pwm1_auto_point4_temp_hyst, S_IRUGO, |
| 790 | show_lut_temp_hyst, NULL, 6); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 791 | static SENSOR_DEVICE_ATTR(pwm1_auto_point5_pwm, S_IWUSR | S_IRUGO, |
| 792 | show_pwm1, set_pwm1, 5); |
| 793 | static SENSOR_DEVICE_ATTR(pwm1_auto_point5_temp, S_IWUSR | S_IRUGO, |
| 794 | show_lut_temp, set_temp8, 7); |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 795 | static SENSOR_DEVICE_ATTR(pwm1_auto_point5_temp_hyst, S_IRUGO, |
| 796 | show_lut_temp_hyst, NULL, 7); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 797 | static SENSOR_DEVICE_ATTR(pwm1_auto_point6_pwm, S_IWUSR | S_IRUGO, |
| 798 | show_pwm1, set_pwm1, 6); |
| 799 | static SENSOR_DEVICE_ATTR(pwm1_auto_point6_temp, S_IWUSR | S_IRUGO, |
| 800 | show_lut_temp, set_temp8, 8); |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 801 | static SENSOR_DEVICE_ATTR(pwm1_auto_point6_temp_hyst, S_IRUGO, |
| 802 | show_lut_temp_hyst, NULL, 8); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 803 | static SENSOR_DEVICE_ATTR(pwm1_auto_point7_pwm, S_IWUSR | S_IRUGO, |
| 804 | show_pwm1, set_pwm1, 7); |
| 805 | static SENSOR_DEVICE_ATTR(pwm1_auto_point7_temp, S_IWUSR | S_IRUGO, |
| 806 | show_lut_temp, set_temp8, 9); |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 807 | static SENSOR_DEVICE_ATTR(pwm1_auto_point7_temp_hyst, S_IRUGO, |
| 808 | show_lut_temp_hyst, NULL, 9); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 809 | static SENSOR_DEVICE_ATTR(pwm1_auto_point8_pwm, S_IWUSR | S_IRUGO, |
| 810 | show_pwm1, set_pwm1, 8); |
| 811 | static SENSOR_DEVICE_ATTR(pwm1_auto_point8_temp, S_IWUSR | S_IRUGO, |
| 812 | show_lut_temp, set_temp8, 10); |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 813 | static SENSOR_DEVICE_ATTR(pwm1_auto_point8_temp_hyst, S_IRUGO, |
| 814 | show_lut_temp_hyst, NULL, 10); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 815 | static SENSOR_DEVICE_ATTR(pwm1_auto_point9_pwm, S_IWUSR | S_IRUGO, |
| 816 | show_pwm1, set_pwm1, 9); |
| 817 | static SENSOR_DEVICE_ATTR(pwm1_auto_point9_temp, S_IWUSR | S_IRUGO, |
| 818 | show_lut_temp, set_temp8, 11); |
Jean Delvare | 2fe28ab | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 819 | static SENSOR_DEVICE_ATTR(pwm1_auto_point9_temp_hyst, S_IRUGO, |
| 820 | show_lut_temp_hyst, NULL, 11); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 821 | static SENSOR_DEVICE_ATTR(pwm1_auto_point10_pwm, S_IWUSR | S_IRUGO, |
| 822 | show_pwm1, set_pwm1, 10); |
| 823 | static SENSOR_DEVICE_ATTR(pwm1_auto_point10_temp, S_IWUSR | S_IRUGO, |
| 824 | show_lut_temp, set_temp8, 12); |
Jean Delvare | 2fe28ab | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 825 | static SENSOR_DEVICE_ATTR(pwm1_auto_point10_temp_hyst, S_IRUGO, |
| 826 | show_lut_temp_hyst, NULL, 12); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 827 | static SENSOR_DEVICE_ATTR(pwm1_auto_point11_pwm, S_IWUSR | S_IRUGO, |
| 828 | show_pwm1, set_pwm1, 11); |
| 829 | static SENSOR_DEVICE_ATTR(pwm1_auto_point11_temp, S_IWUSR | S_IRUGO, |
| 830 | show_lut_temp, set_temp8, 13); |
Jean Delvare | 2fe28ab | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 831 | static SENSOR_DEVICE_ATTR(pwm1_auto_point11_temp_hyst, S_IRUGO, |
| 832 | show_lut_temp_hyst, NULL, 13); |
Jean Delvare | af2ef4f | 2012-03-23 10:02:19 +0100 | [diff] [blame] | 833 | static SENSOR_DEVICE_ATTR(pwm1_auto_point12_pwm, S_IWUSR | S_IRUGO, |
| 834 | show_pwm1, set_pwm1, 12); |
| 835 | static SENSOR_DEVICE_ATTR(pwm1_auto_point12_temp, S_IWUSR | S_IRUGO, |
| 836 | show_lut_temp, set_temp8, 14); |
Jean Delvare | 2fe28ab | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 837 | static SENSOR_DEVICE_ATTR(pwm1_auto_point12_temp_hyst, S_IRUGO, |
| 838 | show_lut_temp_hyst, NULL, 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 840 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_local_temp8, NULL, 0); |
| 841 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_local_temp8, |
Guenter Roeck | 94e55df | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 842 | set_temp8, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
Jean Delvare | bc51ae1 | 2005-06-05 20:32:27 +0200 | [diff] [blame] | 844 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0); |
| 845 | static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11, |
| 846 | set_temp11, 1); |
| 847 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11, |
| 848 | set_temp11, 2); |
Guenter Roeck | 786375f | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 849 | static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_temp11, |
| 850 | set_temp11, 3); |
Dirk Eibach | 2778fb1 | 2011-02-09 04:51:34 -0500 | [diff] [blame] | 851 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_remote_temp8, |
Guenter Roeck | 94e55df | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 852 | set_temp8, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst, |
| 854 | set_temp2_crit_hyst); |
| 855 | |
Guenter Roeck | f496b2d | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 856 | static DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, set_type); |
| 857 | |
Jean Delvare | 2d45771 | 2006-09-24 20:52:15 +0200 | [diff] [blame] | 858 | /* Individual alarm files */ |
| 859 | static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0); |
| 860 | 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] | 861 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); |
Jean Delvare | 2d45771 | 2006-09-24 20:52:15 +0200 | [diff] [blame] | 862 | static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); |
| 863 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); |
| 864 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); |
| 865 | /* Raw alarm file for compatibility */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
| 867 | |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 868 | static DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, show_update_interval, |
| 869 | set_update_interval); |
| 870 | |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 871 | static struct attribute *lm63_attributes[] = { |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 872 | &sensor_dev_attr_pwm1.dev_attr.attr, |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 873 | &dev_attr_pwm1_enable.attr, |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 874 | &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, |
| 875 | &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr, |
| 876 | &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr, |
| 877 | &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, |
| 878 | &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr, |
| 879 | &sensor_dev_attr_pwm1_auto_point2_temp_hyst.dev_attr.attr, |
| 880 | &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr, |
| 881 | &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr, |
| 882 | &sensor_dev_attr_pwm1_auto_point3_temp_hyst.dev_attr.attr, |
| 883 | &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr, |
| 884 | &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr, |
| 885 | &sensor_dev_attr_pwm1_auto_point4_temp_hyst.dev_attr.attr, |
| 886 | &sensor_dev_attr_pwm1_auto_point5_pwm.dev_attr.attr, |
| 887 | &sensor_dev_attr_pwm1_auto_point5_temp.dev_attr.attr, |
| 888 | &sensor_dev_attr_pwm1_auto_point5_temp_hyst.dev_attr.attr, |
| 889 | &sensor_dev_attr_pwm1_auto_point6_pwm.dev_attr.attr, |
| 890 | &sensor_dev_attr_pwm1_auto_point6_temp.dev_attr.attr, |
| 891 | &sensor_dev_attr_pwm1_auto_point6_temp_hyst.dev_attr.attr, |
| 892 | &sensor_dev_attr_pwm1_auto_point7_pwm.dev_attr.attr, |
| 893 | &sensor_dev_attr_pwm1_auto_point7_temp.dev_attr.attr, |
| 894 | &sensor_dev_attr_pwm1_auto_point7_temp_hyst.dev_attr.attr, |
| 895 | &sensor_dev_attr_pwm1_auto_point8_pwm.dev_attr.attr, |
| 896 | &sensor_dev_attr_pwm1_auto_point8_temp.dev_attr.attr, |
| 897 | &sensor_dev_attr_pwm1_auto_point8_temp_hyst.dev_attr.attr, |
| 898 | |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 899 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 900 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| 901 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
| 902 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 903 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
Guenter Roeck | 786375f | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 904 | &sensor_dev_attr_temp2_offset.dev_attr.attr, |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 905 | &sensor_dev_attr_temp2_crit.dev_attr.attr, |
| 906 | &dev_attr_temp2_crit_hyst.attr, |
| 907 | |
| 908 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, |
Jean Delvare | 7817a39 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 909 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 910 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, |
| 911 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, |
| 912 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, |
| 913 | &dev_attr_alarms.attr, |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 914 | &dev_attr_update_interval.attr, |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 915 | NULL |
| 916 | }; |
| 917 | |
Jean Delvare | 2fe28ab | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 918 | static struct attribute *lm63_attributes_extra_lut[] = { |
| 919 | &sensor_dev_attr_pwm1_auto_point9_pwm.dev_attr.attr, |
| 920 | &sensor_dev_attr_pwm1_auto_point9_temp.dev_attr.attr, |
| 921 | &sensor_dev_attr_pwm1_auto_point9_temp_hyst.dev_attr.attr, |
| 922 | &sensor_dev_attr_pwm1_auto_point10_pwm.dev_attr.attr, |
| 923 | &sensor_dev_attr_pwm1_auto_point10_temp.dev_attr.attr, |
| 924 | &sensor_dev_attr_pwm1_auto_point10_temp_hyst.dev_attr.attr, |
| 925 | &sensor_dev_attr_pwm1_auto_point11_pwm.dev_attr.attr, |
| 926 | &sensor_dev_attr_pwm1_auto_point11_temp.dev_attr.attr, |
| 927 | &sensor_dev_attr_pwm1_auto_point11_temp_hyst.dev_attr.attr, |
| 928 | &sensor_dev_attr_pwm1_auto_point12_pwm.dev_attr.attr, |
| 929 | &sensor_dev_attr_pwm1_auto_point12_temp.dev_attr.attr, |
| 930 | &sensor_dev_attr_pwm1_auto_point12_temp_hyst.dev_attr.attr, |
| 931 | NULL |
| 932 | }; |
| 933 | |
| 934 | static const struct attribute_group lm63_group_extra_lut = { |
| 935 | .attrs = lm63_attributes_extra_lut, |
| 936 | }; |
| 937 | |
Guenter Roeck | 94e55df | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 938 | /* |
| 939 | * On LM63, temp2_crit can be set only once, which should be job |
| 940 | * of the bootloader. |
| 941 | * On LM64, temp2_crit can always be set. |
| 942 | * On LM96163, temp2_crit can be set if bit 1 of the configuration |
| 943 | * register is true. |
| 944 | */ |
| 945 | static umode_t lm63_attribute_mode(struct kobject *kobj, |
| 946 | struct attribute *attr, int index) |
| 947 | { |
| 948 | struct device *dev = container_of(kobj, struct device, kobj); |
| 949 | struct i2c_client *client = to_i2c_client(dev); |
| 950 | struct lm63_data *data = i2c_get_clientdata(client); |
| 951 | |
| 952 | if (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr |
| 953 | && (data->kind == lm64 || |
| 954 | (data->kind == lm96163 && (data->config & 0x02)))) |
| 955 | return attr->mode | S_IWUSR; |
| 956 | |
| 957 | return attr->mode; |
| 958 | } |
| 959 | |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 960 | static const struct attribute_group lm63_group = { |
Guenter Roeck | 94e55df | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 961 | .is_visible = lm63_attribute_mode, |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 962 | .attrs = lm63_attributes, |
| 963 | }; |
| 964 | |
| 965 | static struct attribute *lm63_attributes_fan1[] = { |
| 966 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 967 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
| 968 | |
| 969 | &sensor_dev_attr_fan1_min_alarm.dev_attr.attr, |
| 970 | NULL |
| 971 | }; |
| 972 | |
| 973 | static const struct attribute_group lm63_group_fan1 = { |
| 974 | .attrs = lm63_attributes_fan1, |
| 975 | }; |
| 976 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | /* |
| 978 | * Real code |
| 979 | */ |
| 980 | |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 981 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 982 | static int lm63_detect(struct i2c_client *client, |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 983 | struct i2c_board_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | { |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 985 | struct i2c_adapter *adapter = client->adapter; |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 986 | u8 man_id, chip_id, reg_config1, reg_config2; |
| 987 | u8 reg_alert_status, reg_alert_mask; |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 988 | int address = client->addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
| 990 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 991 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 993 | man_id = i2c_smbus_read_byte_data(client, LM63_REG_MAN_ID); |
| 994 | chip_id = i2c_smbus_read_byte_data(client, LM63_REG_CHIP_ID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 996 | reg_config1 = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1); |
| 997 | reg_config2 = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG2); |
| 998 | reg_alert_status = i2c_smbus_read_byte_data(client, |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 999 | LM63_REG_ALERT_STATUS); |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 1000 | reg_alert_mask = i2c_smbus_read_byte_data(client, LM63_REG_ALERT_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 1002 | if (man_id != 0x01 /* National Semiconductor */ |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 1003 | || (reg_config1 & 0x18) != 0x00 |
| 1004 | || (reg_config2 & 0xF8) != 0x00 |
| 1005 | || (reg_alert_status & 0x20) != 0x00 |
| 1006 | || (reg_alert_mask & 0xA4) != 0xA4) { |
| 1007 | dev_dbg(&adapter->dev, |
| 1008 | "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n", |
| 1009 | man_id, chip_id); |
| 1010 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
Matthew Garrett | 10f2ed3 | 2010-05-27 19:58:38 +0200 | [diff] [blame] | 1013 | if (chip_id == 0x41 && address == 0x4c) |
| 1014 | strlcpy(info->type, "lm63", I2C_NAME_SIZE); |
| 1015 | else if (chip_id == 0x51 && (address == 0x18 || address == 0x4e)) |
| 1016 | strlcpy(info->type, "lm64", I2C_NAME_SIZE); |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 1017 | else if (chip_id == 0x49 && address == 0x4c) |
| 1018 | strlcpy(info->type, "lm96163", I2C_NAME_SIZE); |
Matthew Garrett | 10f2ed3 | 2010-05-27 19:58:38 +0200 | [diff] [blame] | 1019 | else |
| 1020 | return -ENODEV; |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 1021 | |
| 1022 | return 0; |
| 1023 | } |
| 1024 | |
Guenter Roeck | 662bda2 | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 1025 | /* |
| 1026 | * Ideally we shouldn't have to initialize anything, since the BIOS |
| 1027 | * should have taken care of everything |
| 1028 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | static void lm63_init_client(struct i2c_client *client) |
| 1030 | { |
| 1031 | struct lm63_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 1032 | u8 convrate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | |
| 1034 | data->config = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1); |
| 1035 | data->config_fan = i2c_smbus_read_byte_data(client, |
| 1036 | LM63_REG_CONFIG_FAN); |
| 1037 | |
| 1038 | /* Start converting if needed */ |
| 1039 | if (data->config & 0x40) { /* standby */ |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1040 | dev_dbg(&client->dev, "Switching to operational mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | data->config &= 0xA7; |
| 1042 | i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1, |
| 1043 | data->config); |
| 1044 | } |
Jean Delvare | 409c0b5 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 1045 | /* Tachometer is always enabled on LM64 */ |
| 1046 | if (data->kind == lm64) |
| 1047 | data->config |= 0x04; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | |
| 1049 | /* We may need pwm1_freq before ever updating the client data */ |
| 1050 | data->pwm1_freq = i2c_smbus_read_byte_data(client, LM63_REG_PWM_FREQ); |
| 1051 | if (data->pwm1_freq == 0) |
| 1052 | data->pwm1_freq = 1; |
| 1053 | |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 1054 | switch (data->kind) { |
| 1055 | case lm63: |
| 1056 | case lm64: |
| 1057 | data->max_convrate_hz = LM63_MAX_CONVRATE_HZ; |
Jean Delvare | 2fe28ab | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 1058 | data->lut_size = 8; |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 1059 | break; |
| 1060 | case lm96163: |
| 1061 | data->max_convrate_hz = LM96163_MAX_CONVRATE_HZ; |
Jean Delvare | 2fe28ab | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 1062 | data->lut_size = 12; |
Guenter Roeck | f496b2d | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 1063 | data->trutherm |
| 1064 | = i2c_smbus_read_byte_data(client, |
| 1065 | LM96163_REG_TRUTHERM) & 0x02; |
Guenter Roeck | 04738b2 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 1066 | break; |
| 1067 | } |
| 1068 | convrate = i2c_smbus_read_byte_data(client, LM63_REG_CONVRATE); |
| 1069 | if (unlikely(convrate > LM63_MAX_CONVRATE)) |
| 1070 | convrate = LM63_MAX_CONVRATE; |
| 1071 | data->update_interval = UPDATE_INTERVAL(data->max_convrate_hz, |
| 1072 | convrate); |
| 1073 | |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 1074 | /* |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 1075 | * For LM96163, check if high resolution PWM |
| 1076 | * and unsigned temperature format is enabled. |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 1077 | */ |
| 1078 | if (data->kind == lm96163) { |
| 1079 | u8 config_enhanced |
| 1080 | = i2c_smbus_read_byte_data(client, |
| 1081 | LM96163_REG_CONFIG_ENHANCED); |
Jean Delvare | d216f68 | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 1082 | if (config_enhanced & 0x20) |
| 1083 | data->lut_temp_highres = true; |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 1084 | if ((config_enhanced & 0x10) |
| 1085 | && !(data->config_fan & 0x08) && data->pwm1_freq == 8) |
| 1086 | data->pwm_highres = true; |
| 1087 | if (config_enhanced & 0x08) |
Guenter Roeck | e872c91 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 1088 | data->remote_unsigned = true; |
Guenter Roeck | 210961c | 2012-01-16 22:51:45 +0100 | [diff] [blame] | 1089 | } |
| 1090 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | /* Show some debug info about the LM63 configuration */ |
Jean Delvare | 409c0b5 | 2012-01-16 22:51:46 +0100 | [diff] [blame] | 1092 | if (data->kind == lm63) |
| 1093 | dev_dbg(&client->dev, "Alert/tach pin configured for %s\n", |
| 1094 | (data->config & 0x04) ? "tachometer input" : |
| 1095 | "alert output"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | dev_dbg(&client->dev, "PWM clock %s kHz, output frequency %u Hz\n", |
| 1097 | (data->config_fan & 0x08) ? "1.4" : "360", |
| 1098 | ((data->config_fan & 0x08) ? 700 : 180000) / data->pwm1_freq); |
| 1099 | dev_dbg(&client->dev, "PWM output active %s, %s mode\n", |
| 1100 | (data->config_fan & 0x10) ? "low" : "high", |
| 1101 | (data->config_fan & 0x20) ? "manual" : "auto"); |
| 1102 | } |
| 1103 | |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 1104 | static int lm63_probe(struct i2c_client *client, |
| 1105 | const struct i2c_device_id *id) |
| 1106 | { |
| 1107 | struct lm63_data *data; |
| 1108 | int err; |
| 1109 | |
Guenter Roeck | c5a4a91 | 2012-06-02 09:58:08 -0700 | [diff] [blame] | 1110 | data = devm_kzalloc(&client->dev, sizeof(struct lm63_data), GFP_KERNEL); |
| 1111 | if (!data) |
| 1112 | return -ENOMEM; |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 1113 | |
| 1114 | i2c_set_clientdata(client, data); |
| 1115 | data->valid = 0; |
| 1116 | mutex_init(&data->update_lock); |
| 1117 | |
| 1118 | /* Set the device type */ |
| 1119 | data->kind = id->driver_data; |
| 1120 | if (data->kind == lm64) |
| 1121 | data->temp2_offset = 16000; |
| 1122 | |
| 1123 | /* Initialize chip */ |
| 1124 | lm63_init_client(client); |
| 1125 | |
| 1126 | /* Register sysfs hooks */ |
| 1127 | err = sysfs_create_group(&client->dev.kobj, &lm63_group); |
| 1128 | if (err) |
Guenter Roeck | c5a4a91 | 2012-06-02 09:58:08 -0700 | [diff] [blame] | 1129 | return err; |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 1130 | if (data->config & 0x04) { /* tachometer enabled */ |
| 1131 | err = sysfs_create_group(&client->dev.kobj, &lm63_group_fan1); |
| 1132 | if (err) |
| 1133 | goto exit_remove_files; |
| 1134 | } |
| 1135 | if (data->kind == lm96163) { |
| 1136 | err = device_create_file(&client->dev, &dev_attr_temp2_type); |
| 1137 | if (err) |
| 1138 | goto exit_remove_files; |
| 1139 | |
| 1140 | err = sysfs_create_group(&client->dev.kobj, |
| 1141 | &lm63_group_extra_lut); |
| 1142 | if (err) |
| 1143 | goto exit_remove_files; |
| 1144 | } |
| 1145 | |
| 1146 | data->hwmon_dev = hwmon_device_register(&client->dev); |
| 1147 | if (IS_ERR(data->hwmon_dev)) { |
| 1148 | err = PTR_ERR(data->hwmon_dev); |
| 1149 | goto exit_remove_files; |
| 1150 | } |
| 1151 | |
| 1152 | return 0; |
| 1153 | |
| 1154 | exit_remove_files: |
| 1155 | sysfs_remove_group(&client->dev.kobj, &lm63_group); |
| 1156 | sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); |
| 1157 | if (data->kind == lm96163) { |
| 1158 | device_remove_file(&client->dev, &dev_attr_temp2_type); |
| 1159 | sysfs_remove_group(&client->dev.kobj, &lm63_group_extra_lut); |
| 1160 | } |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 1161 | return err; |
| 1162 | } |
| 1163 | |
Jean Delvare | d5957be | 2008-07-16 19:30:13 +0200 | [diff] [blame] | 1164 | static int lm63_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | { |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1166 | struct lm63_data *data = i2c_get_clientdata(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1168 | hwmon_device_unregister(data->hwmon_dev); |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 1169 | sysfs_remove_group(&client->dev.kobj, &lm63_group); |
| 1170 | sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); |
Jean Delvare | 2fe28ab | 2012-01-16 22:51:47 +0100 | [diff] [blame] | 1171 | if (data->kind == lm96163) { |
| 1172 | device_remove_file(&client->dev, &dev_attr_temp2_type); |
| 1173 | sysfs_remove_group(&client->dev.kobj, &lm63_group_extra_lut); |
| 1174 | } |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | return 0; |
| 1177 | } |
| 1178 | |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 1179 | /* |
| 1180 | * Driver data (common to all clients) |
| 1181 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 1183 | static const struct i2c_device_id lm63_id[] = { |
| 1184 | { "lm63", lm63 }, |
| 1185 | { "lm64", lm64 }, |
| 1186 | { "lm96163", lm96163 }, |
| 1187 | { } |
| 1188 | }; |
| 1189 | MODULE_DEVICE_TABLE(i2c, lm63_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | |
Jean Delvare | dac27dc | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 1191 | static struct i2c_driver lm63_driver = { |
| 1192 | .class = I2C_CLASS_HWMON, |
| 1193 | .driver = { |
| 1194 | .name = "lm63", |
| 1195 | }, |
| 1196 | .probe = lm63_probe, |
| 1197 | .remove = lm63_remove, |
| 1198 | .id_table = lm63_id, |
| 1199 | .detect = lm63_detect, |
| 1200 | .address_list = normal_i2c, |
| 1201 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | |
Axel Lin | f0967ee | 2012-01-20 15:38:18 +0800 | [diff] [blame] | 1203 | module_i2c_driver(lm63_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | |
Jean Delvare | 7c81c60 | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1205 | MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | MODULE_DESCRIPTION("LM63 driver"); |
| 1207 | MODULE_LICENSE("GPL"); |