Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 2 | * lm85.c - Part of lm_sensors, Linux kernel modules for hardware |
| 3 | * monitoring |
| 4 | * Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> |
| 5 | * Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> |
| 6 | * Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> |
| 7 | * Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com> |
Jean Delvare | 590e853 | 2014-06-11 18:35:56 +0200 | [diff] [blame] | 8 | * Copyright (C) 2007--2014 Jean Delvare <jdelvare@suse.de> |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 9 | * |
| 10 | * Chip details at <http://www.national.com/ds/LM/LM85.pdf> |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/module.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/jiffies.h> |
| 31 | #include <linux/i2c.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 32 | #include <linux/hwmon.h> |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 33 | #include <linux/hwmon-vid.h> |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 34 | #include <linux/hwmon-sysfs.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 35 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 36 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | /* Addresses to scan */ |
Mark M. Hoffman | 25e9c86 | 2008-02-17 22:28:03 -0500 | [diff] [blame] | 39 | static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Jean Delvare | e5e9f44 | 2009-12-14 21:17:27 +0100 | [diff] [blame] | 41 | enum chips { |
Jean Delvare | 590e853 | 2014-06-11 18:35:56 +0200 | [diff] [blame] | 42 | lm85, |
Jean Delvare | e5e9f44 | 2009-12-14 21:17:27 +0100 | [diff] [blame] | 43 | adm1027, adt7463, adt7468, |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 44 | emc6d100, emc6d102, emc6d103, emc6d103s |
Jean Delvare | e5e9f44 | 2009-12-14 21:17:27 +0100 | [diff] [blame] | 45 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | /* The LM85 registers */ |
| 48 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 49 | #define LM85_REG_IN(nr) (0x20 + (nr)) |
| 50 | #define LM85_REG_IN_MIN(nr) (0x44 + (nr) * 2) |
| 51 | #define LM85_REG_IN_MAX(nr) (0x45 + (nr) * 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 53 | #define LM85_REG_TEMP(nr) (0x25 + (nr)) |
| 54 | #define LM85_REG_TEMP_MIN(nr) (0x4e + (nr) * 2) |
| 55 | #define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | /* Fan speeds are LSB, MSB (2 bytes) */ |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 58 | #define LM85_REG_FAN(nr) (0x28 + (nr) * 2) |
| 59 | #define LM85_REG_FAN_MIN(nr) (0x54 + (nr) * 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 61 | #define LM85_REG_PWM(nr) (0x30 + (nr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 63 | #define LM85_REG_COMPANY 0x3e |
| 64 | #define LM85_REG_VERSTEP 0x3f |
Darrick J. Wong | 79b92f2 | 2008-11-12 13:26:59 -0800 | [diff] [blame] | 65 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 66 | #define ADT7468_REG_CFG5 0x7c |
| 67 | #define ADT7468_OFF64 (1 << 0) |
| 68 | #define ADT7468_HFPWM (1 << 1) |
| 69 | #define IS_ADT7468_OFF64(data) \ |
Darrick J. Wong | 79b92f2 | 2008-11-12 13:26:59 -0800 | [diff] [blame] | 70 | ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64)) |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 71 | #define IS_ADT7468_HFPWM(data) \ |
Jean Delvare | f6c61cf | 2010-10-28 20:31:50 +0200 | [diff] [blame] | 72 | ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_HFPWM)) |
Darrick J. Wong | 79b92f2 | 2008-11-12 13:26:59 -0800 | [diff] [blame] | 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | /* These are the recognized values for the above regs */ |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 75 | #define LM85_COMPANY_NATIONAL 0x01 |
| 76 | #define LM85_COMPANY_ANALOG_DEV 0x41 |
| 77 | #define LM85_COMPANY_SMSC 0x5c |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 78 | #define LM85_VERSTEP_LM85C 0x60 |
| 79 | #define LM85_VERSTEP_LM85B 0x62 |
| 80 | #define LM85_VERSTEP_LM96000_1 0x68 |
| 81 | #define LM85_VERSTEP_LM96000_2 0x69 |
| 82 | #define LM85_VERSTEP_ADM1027 0x60 |
| 83 | #define LM85_VERSTEP_ADT7463 0x62 |
| 84 | #define LM85_VERSTEP_ADT7463C 0x6A |
| 85 | #define LM85_VERSTEP_ADT7468_1 0x71 |
| 86 | #define LM85_VERSTEP_ADT7468_2 0x72 |
| 87 | #define LM85_VERSTEP_EMC6D100_A0 0x60 |
| 88 | #define LM85_VERSTEP_EMC6D100_A1 0x61 |
| 89 | #define LM85_VERSTEP_EMC6D102 0x65 |
| 90 | #define LM85_VERSTEP_EMC6D103_A0 0x68 |
| 91 | #define LM85_VERSTEP_EMC6D103_A1 0x69 |
| 92 | #define LM85_VERSTEP_EMC6D103S 0x6A /* Also known as EMC6D103:A2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 94 | #define LM85_REG_CONFIG 0x40 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 96 | #define LM85_REG_ALARM1 0x41 |
| 97 | #define LM85_REG_ALARM2 0x42 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 99 | #define LM85_REG_VID 0x43 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | /* Automated FAN control */ |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 102 | #define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr)) |
| 103 | #define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr)) |
| 104 | #define LM85_REG_AFAN_SPIKE1 0x62 |
| 105 | #define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr)) |
| 106 | #define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr)) |
| 107 | #define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr)) |
| 108 | #define LM85_REG_AFAN_HYST1 0x6d |
| 109 | #define LM85_REG_AFAN_HYST2 0x6e |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 111 | #define ADM1027_REG_EXTEND_ADC1 0x76 |
| 112 | #define ADM1027_REG_EXTEND_ADC2 0x77 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | #define EMC6D100_REG_ALARM3 0x7d |
| 115 | /* IN5, IN6 and IN7 */ |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 116 | #define EMC6D100_REG_IN(nr) (0x70 + ((nr) - 5)) |
| 117 | #define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr) - 5) * 2) |
| 118 | #define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr) - 5) * 2) |
| 119 | #define EMC6D102_REG_EXTEND_ADC1 0x85 |
| 120 | #define EMC6D102_REG_EXTEND_ADC2 0x86 |
| 121 | #define EMC6D102_REG_EXTEND_ADC3 0x87 |
| 122 | #define EMC6D102_REG_EXTEND_ADC4 0x88 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 125 | /* |
| 126 | * Conversions. Rounding and limit checking is only done on the TO_REG |
| 127 | * variants. Note that you should be a bit careful with which arguments |
| 128 | * these macros are called: arguments may be evaluated more than once. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | */ |
| 130 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 131 | /* IN are scaled according to built-in resistors */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 132 | static const int lm85_scaling[] = { /* .001 Volts */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 133 | 2500, 2250, 3300, 5000, 12000, |
| 134 | 3300, 1500, 1800 /*EMC6D100*/ |
| 135 | }; |
| 136 | #define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 138 | #define INS_TO_REG(n, val) \ |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 139 | clamp_val(SCALE(val, lm85_scaling[n], 192), 0, 255) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 141 | #define INSEXT_FROM_REG(n, val, ext) \ |
Jean Delvare | 5a4d3ef | 2007-07-05 20:38:32 +0200 | [diff] [blame] | 142 | SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 144 | #define INS_FROM_REG(n, val) SCALE((val), 192, lm85_scaling[n]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | /* FAN speed is measured using 90kHz clock */ |
Jean Delvare | 63f281a | 2007-07-05 20:39:40 +0200 | [diff] [blame] | 147 | static inline u16 FAN_TO_REG(unsigned long val) |
| 148 | { |
| 149 | if (!val) |
| 150 | return 0xffff; |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 151 | return clamp_val(5400000 / val, 1, 0xfffe); |
Jean Delvare | 63f281a | 2007-07-05 20:39:40 +0200 | [diff] [blame] | 152 | } |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 153 | #define FAN_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \ |
| 154 | 5400000 / (val)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | /* Temperature is reported in .001 degC increments */ |
| 157 | #define TEMP_TO_REG(val) \ |
Guenter Roeck | 3248c3b | 2014-07-29 22:23:12 -0700 | [diff] [blame^] | 158 | DIV_ROUND_CLOSEST(clamp_val((val), -127000, 127000), 1000) |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 159 | #define TEMPEXT_FROM_REG(val, ext) \ |
Jean Delvare | 5a4d3ef | 2007-07-05 20:38:32 +0200 | [diff] [blame] | 160 | SCALE(((val) << 4) + (ext), 16, 1000) |
| 161 | #define TEMP_FROM_REG(val) ((val) * 1000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 163 | #define PWM_TO_REG(val) clamp_val(val, 0, 255) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | #define PWM_FROM_REG(val) (val) |
| 165 | |
| 166 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 167 | /* |
| 168 | * ZONEs have the following parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | * Limit (low) temp, 1. degC |
| 170 | * Hysteresis (below limit), 1. degC (0-15) |
| 171 | * Range of speed control, .1 degC (2-80) |
| 172 | * Critical (high) temp, 1. degC |
| 173 | * |
| 174 | * FAN PWMs have the following parameters: |
| 175 | * Reference Zone, 1, 2, 3, etc. |
| 176 | * Spinup time, .05 sec |
| 177 | * PWM value at limit/low temp, 1 count |
| 178 | * PWM Frequency, 1. Hz |
| 179 | * PWM is Min or OFF below limit, flag |
| 180 | * Invert PWM output, flag |
| 181 | * |
| 182 | * Some chips filter the temp, others the fan. |
| 183 | * Filter constant (or disabled) .1 seconds |
| 184 | */ |
| 185 | |
| 186 | /* These are the zone temperature range encodings in .001 degree C */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 187 | static const int lm85_range_map[] = { |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 188 | 2000, 2500, 3300, 4000, 5000, 6600, 8000, 10000, |
| 189 | 13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000 |
| 190 | }; |
| 191 | |
Guenter Roeck | 3248c3b | 2014-07-29 22:23:12 -0700 | [diff] [blame^] | 192 | static int RANGE_TO_REG(long range) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
| 194 | int i; |
| 195 | |
Jean Delvare | d38b149 | 2008-04-03 10:40:39 +0200 | [diff] [blame] | 196 | /* Find the closest match */ |
Jean Delvare | 1b92ada | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 197 | for (i = 0; i < 15; ++i) { |
| 198 | if (range <= (lm85_range_map[i] + lm85_range_map[i + 1]) / 2) |
| 199 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
Jean Delvare | d38b149 | 2008-04-03 10:40:39 +0200 | [diff] [blame] | 201 | |
Jean Delvare | 1b92ada | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 202 | return i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 204 | #define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | /* These are the PWM frequency encodings */ |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 207 | static const int lm85_freq_map[8] = { /* 1 Hz */ |
Jean Delvare | 8a0795d | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 208 | 10, 15, 23, 30, 38, 47, 61, 94 |
| 209 | }; |
| 210 | static const int adm1027_freq_map[8] = { /* 1 Hz */ |
| 211 | 11, 15, 22, 29, 35, 44, 59, 88 |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 212 | }; |
| 213 | |
Guenter Roeck | 3248c3b | 2014-07-29 22:23:12 -0700 | [diff] [blame^] | 214 | static int FREQ_TO_REG(const int *map, unsigned long freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | { |
| 216 | int i; |
| 217 | |
Jean Delvare | 86010c9 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 218 | /* Find the closest match */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 219 | for (i = 0; i < 7; ++i) |
Jean Delvare | 8a0795d | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 220 | if (freq <= (map[i] + map[i + 1]) / 2) |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 221 | break; |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 222 | return i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | } |
Jean Delvare | 8a0795d | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 224 | |
| 225 | static int FREQ_FROM_REG(const int *map, u8 reg) |
| 226 | { |
| 227 | return map[reg & 0x07]; |
| 228 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 230 | /* |
| 231 | * Since we can't use strings, I'm abusing these numbers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | * to stand in for the following meanings: |
| 233 | * 1 -- PWM responds to Zone 1 |
| 234 | * 2 -- PWM responds to Zone 2 |
| 235 | * 3 -- PWM responds to Zone 3 |
| 236 | * 23 -- PWM responds to the higher temp of Zone 2 or 3 |
| 237 | * 123 -- PWM responds to highest of Zone 1, 2, or 3 |
| 238 | * 0 -- PWM is always at 0% (ie, off) |
| 239 | * -1 -- PWM is always at 100% |
| 240 | * -2 -- PWM responds to manual control |
| 241 | */ |
| 242 | |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 243 | static const int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 }; |
| 244 | #define ZONE_FROM_REG(val) lm85_zone_map[(val) >> 5] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 246 | static int ZONE_TO_REG(int zone) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
| 248 | int i; |
| 249 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 250 | for (i = 0; i <= 7; ++i) |
| 251 | if (zone == lm85_zone_map[i]) |
| 252 | break; |
| 253 | if (i > 7) /* Not found. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | i = 3; /* Always 100% */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 255 | return i << 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 258 | #define HYST_TO_REG(val) clamp_val(((val) + 500) / 1000, 0, 15) |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 259 | #define HYST_FROM_REG(val) ((val) * 1000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 261 | /* |
| 262 | * Chip sampling rates |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | * |
| 264 | * Some sensors are not updated more frequently than once per second |
| 265 | * so it doesn't make sense to read them more often than that. |
| 266 | * We cache the results and return the saved data if the driver |
| 267 | * is called again before a second has elapsed. |
| 268 | * |
| 269 | * Also, there is significant configuration data for this chip |
| 270 | * given the automatic PWM fan control that is possible. There |
| 271 | * are about 47 bytes of config data to only 22 bytes of actual |
| 272 | * readings. So, we keep the config data up to date in the cache |
| 273 | * when it is written and only sample it once every 1 *minute* |
| 274 | */ |
| 275 | #define LM85_DATA_INTERVAL (HZ + HZ / 2) |
| 276 | #define LM85_CONFIG_INTERVAL (1 * 60 * HZ) |
| 277 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 278 | /* |
| 279 | * LM85 can automatically adjust fan speeds based on temperature |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | * This structure encapsulates an entire Zone config. There are |
| 281 | * three zones (one for each temperature input) on the lm85 |
| 282 | */ |
| 283 | struct lm85_zone { |
| 284 | s8 limit; /* Low temp limit */ |
| 285 | u8 hyst; /* Low limit hysteresis. (0-15) */ |
| 286 | u8 range; /* Temp range, encoded */ |
| 287 | s8 critical; /* "All fans ON" temp limit */ |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 288 | u8 max_desired; /* |
| 289 | * Actual "max" temperature specified. Preserved |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | * to prevent "drift" as other autofan control |
| 291 | * values change. |
| 292 | */ |
| 293 | }; |
| 294 | |
| 295 | struct lm85_autofan { |
| 296 | u8 config; /* Register value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | u8 min_pwm; /* Minimum PWM value, encoded */ |
| 298 | u8 min_off; /* Min PWM or OFF below "limit", flag */ |
| 299 | }; |
| 300 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 301 | /* |
| 302 | * For each registered chip, we need to keep some data in memory. |
| 303 | * The structure is dynamically allocated. |
| 304 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | struct lm85_data { |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 306 | struct device *hwmon_dev; |
Jean Delvare | 8a0795d | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 307 | const int *freq_map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | enum chips type; |
| 309 | |
Guenter Roeck | de24880 | 2011-02-25 08:19:42 -0800 | [diff] [blame] | 310 | bool has_vid5; /* true if VID5 is configured for ADT7463 or ADT7468 */ |
| 311 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 312 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | int valid; /* !=0 if following fields are valid */ |
| 314 | unsigned long last_reading; /* In jiffies */ |
| 315 | unsigned long last_config; /* In jiffies */ |
| 316 | |
| 317 | u8 in[8]; /* Register value */ |
| 318 | u8 in_max[8]; /* Register value */ |
| 319 | u8 in_min[8]; /* Register value */ |
| 320 | s8 temp[3]; /* Register value */ |
| 321 | s8 temp_min[3]; /* Register value */ |
| 322 | s8 temp_max[3]; /* Register value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | u16 fan[4]; /* Register value */ |
| 324 | u16 fan_min[4]; /* Register value */ |
| 325 | u8 pwm[3]; /* Register value */ |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 326 | u8 pwm_freq[3]; /* Register encoding */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | u8 temp_ext[3]; /* Decoded values */ |
| 328 | u8 in_ext[8]; /* Decoded values */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | u8 vid; /* Register value */ |
| 330 | u8 vrm; /* VRM version */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | u32 alarms; /* Register encoding, combined */ |
Darrick J. Wong | 79b92f2 | 2008-11-12 13:26:59 -0800 | [diff] [blame] | 332 | u8 cfg5; /* Config Register 5 on ADT7468 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | struct lm85_autofan autofan[3]; |
| 334 | struct lm85_zone zone[3]; |
| 335 | }; |
| 336 | |
Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 337 | static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info); |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 338 | static int lm85_probe(struct i2c_client *client, |
| 339 | const struct i2c_device_id *id); |
| 340 | static int lm85_remove(struct i2c_client *client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Darren Jenkins | f6c27fc | 2006-02-27 23:14:58 +0100 | [diff] [blame] | 342 | static int lm85_read_value(struct i2c_client *client, u8 reg); |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 343 | static void lm85_write_value(struct i2c_client *client, u8 reg, int value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | static struct lm85_data *lm85_update_device(struct device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
| 346 | |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 347 | static const struct i2c_device_id lm85_id[] = { |
| 348 | { "adm1027", adm1027 }, |
| 349 | { "adt7463", adt7463 }, |
Darrick J. Wong | c15ade6 | 2009-03-10 12:55:47 -0700 | [diff] [blame] | 350 | { "adt7468", adt7468 }, |
Jean Delvare | 590e853 | 2014-06-11 18:35:56 +0200 | [diff] [blame] | 351 | { "lm85", lm85 }, |
| 352 | { "lm85b", lm85 }, |
| 353 | { "lm85c", lm85 }, |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 354 | { "emc6d100", emc6d100 }, |
| 355 | { "emc6d101", emc6d100 }, |
| 356 | { "emc6d102", emc6d102 }, |
Jan Beulich | f065a93 | 2011-02-18 03:18:26 -0500 | [diff] [blame] | 357 | { "emc6d103", emc6d103 }, |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 358 | { "emc6d103s", emc6d103s }, |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 359 | { } |
| 360 | }; |
| 361 | MODULE_DEVICE_TABLE(i2c, lm85_id); |
| 362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | static struct i2c_driver lm85_driver = { |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 364 | .class = I2C_CLASS_HWMON, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 365 | .driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 366 | .name = "lm85", |
| 367 | }, |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 368 | .probe = lm85_probe, |
| 369 | .remove = lm85_remove, |
| 370 | .id_table = lm85_id, |
| 371 | .detect = lm85_detect, |
Jean Delvare | c3813d6 | 2009-12-14 21:17:25 +0100 | [diff] [blame] | 372 | .address_list = normal_i2c, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | }; |
| 374 | |
| 375 | |
| 376 | /* 4 Fans */ |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 377 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, |
| 378 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 380 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 382 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 384 | |
| 385 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, |
| 386 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 388 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 390 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 392 | |
| 393 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
| 394 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 396 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | struct i2c_client *client = to_i2c_client(dev); |
| 398 | struct lm85_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 399 | unsigned long val; |
| 400 | int err; |
| 401 | |
| 402 | err = kstrtoul(buf, 10, &val); |
| 403 | if (err) |
| 404 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 406 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | data->fan_min[nr] = FAN_TO_REG(val); |
| 408 | lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 409 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | return count; |
| 411 | } |
| 412 | |
| 413 | #define show_fan_offset(offset) \ |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 414 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
| 415 | show_fan, NULL, offset - 1); \ |
| 416 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
| 417 | show_fan_min, set_fan_min, offset - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
| 419 | show_fan_offset(1); |
| 420 | show_fan_offset(2); |
| 421 | show_fan_offset(3); |
| 422 | show_fan_offset(4); |
| 423 | |
| 424 | /* vid, vrm, alarms */ |
| 425 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 426 | static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, |
| 427 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
| 429 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 9c516ef | 2005-11-26 20:07:54 +0100 | [diff] [blame] | 430 | int vid; |
| 431 | |
Guenter Roeck | de24880 | 2011-02-25 08:19:42 -0800 | [diff] [blame] | 432 | if (data->has_vid5) { |
Jean Delvare | 9c516ef | 2005-11-26 20:07:54 +0100 | [diff] [blame] | 433 | /* 6-pin VID (VRM 10) */ |
| 434 | vid = vid_from_reg(data->vid & 0x3f, data->vrm); |
| 435 | } else { |
| 436 | /* 5-pin VID (VRM 9) */ |
| 437 | vid = vid_from_reg(data->vid & 0x1f, data->vrm); |
| 438 | } |
| 439 | |
| 440 | return sprintf(buf, "%d\n", vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); |
| 444 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 445 | static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, |
| 446 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | { |
Jean Delvare | 90d6619 | 2007-10-08 18:24:35 +0200 | [diff] [blame] | 448 | struct lm85_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | return sprintf(buf, "%ld\n", (long) data->vrm); |
| 450 | } |
| 451 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 452 | static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, |
| 453 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | { |
Jean Delvare | 8f74efe | 2007-12-01 11:25:33 +0100 | [diff] [blame] | 455 | struct lm85_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 456 | unsigned long val; |
| 457 | int err; |
| 458 | |
| 459 | err = kstrtoul(buf, 10, &val); |
| 460 | if (err) |
| 461 | return err; |
| 462 | |
Guenter Roeck | 3248c3b | 2014-07-29 22:23:12 -0700 | [diff] [blame^] | 463 | if (val > 255) |
| 464 | return -EINVAL; |
| 465 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 466 | data->vrm = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | return count; |
| 468 | } |
| 469 | |
| 470 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); |
| 471 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 472 | static ssize_t show_alarms_reg(struct device *dev, struct device_attribute |
| 473 | *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
| 475 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 68188ba | 2005-05-16 18:52:38 +0200 | [diff] [blame] | 476 | return sprintf(buf, "%u\n", data->alarms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); |
| 480 | |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 481 | static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, |
| 482 | char *buf) |
| 483 | { |
| 484 | int nr = to_sensor_dev_attr(attr)->index; |
| 485 | struct lm85_data *data = lm85_update_device(dev); |
| 486 | return sprintf(buf, "%u\n", (data->alarms >> nr) & 1); |
| 487 | } |
| 488 | |
| 489 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); |
| 490 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); |
| 491 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); |
| 492 | static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3); |
| 493 | static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8); |
| 494 | static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 18); |
| 495 | static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 16); |
| 496 | static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 17); |
| 497 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); |
| 498 | static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14); |
| 499 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5); |
| 500 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 6); |
| 501 | static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 15); |
| 502 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 10); |
| 503 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 11); |
| 504 | static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 12); |
| 505 | static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 13); |
| 506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | /* pwm */ |
| 508 | |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 509 | static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, |
| 510 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 512 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 514 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 516 | |
| 517 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
| 518 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 520 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | struct i2c_client *client = to_i2c_client(dev); |
| 522 | struct lm85_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 523 | unsigned long val; |
| 524 | int err; |
| 525 | |
| 526 | err = kstrtoul(buf, 10, &val); |
| 527 | if (err) |
| 528 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 530 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | data->pwm[nr] = PWM_TO_REG(val); |
| 532 | lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 533 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | return count; |
| 535 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 536 | |
| 537 | static ssize_t show_pwm_enable(struct device *dev, struct device_attribute |
| 538 | *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 540 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 4b4df95 | 2007-12-03 23:23:21 +0100 | [diff] [blame] | 542 | int pwm_zone, enable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
| 544 | pwm_zone = ZONE_FROM_REG(data->autofan[nr].config); |
Jean Delvare | 4b4df95 | 2007-12-03 23:23:21 +0100 | [diff] [blame] | 545 | switch (pwm_zone) { |
| 546 | case -1: /* PWM is always at 100% */ |
| 547 | enable = 0; |
| 548 | break; |
| 549 | case 0: /* PWM is always at 0% */ |
| 550 | case -2: /* PWM responds to manual control */ |
| 551 | enable = 1; |
| 552 | break; |
| 553 | default: /* PWM in automatic mode */ |
| 554 | enable = 2; |
| 555 | } |
| 556 | return sprintf(buf, "%d\n", enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Jean Delvare | 455f791 | 2007-12-03 23:28:42 +0100 | [diff] [blame] | 559 | static ssize_t set_pwm_enable(struct device *dev, struct device_attribute |
| 560 | *attr, const char *buf, size_t count) |
| 561 | { |
| 562 | int nr = to_sensor_dev_attr(attr)->index; |
| 563 | struct i2c_client *client = to_i2c_client(dev); |
| 564 | struct lm85_data *data = i2c_get_clientdata(client); |
Jean Delvare | 455f791 | 2007-12-03 23:28:42 +0100 | [diff] [blame] | 565 | u8 config; |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 566 | unsigned long val; |
| 567 | int err; |
| 568 | |
| 569 | err = kstrtoul(buf, 10, &val); |
| 570 | if (err) |
| 571 | return err; |
Jean Delvare | 455f791 | 2007-12-03 23:28:42 +0100 | [diff] [blame] | 572 | |
| 573 | switch (val) { |
| 574 | case 0: |
| 575 | config = 3; |
| 576 | break; |
| 577 | case 1: |
| 578 | config = 7; |
| 579 | break; |
| 580 | case 2: |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 581 | /* |
| 582 | * Here we have to choose arbitrarily one of the 5 possible |
| 583 | * configurations; I go for the safest |
| 584 | */ |
Jean Delvare | 455f791 | 2007-12-03 23:28:42 +0100 | [diff] [blame] | 585 | config = 6; |
| 586 | break; |
| 587 | default: |
| 588 | return -EINVAL; |
| 589 | } |
| 590 | |
| 591 | mutex_lock(&data->update_lock); |
| 592 | data->autofan[nr].config = lm85_read_value(client, |
| 593 | LM85_REG_AFAN_CONFIG(nr)); |
| 594 | data->autofan[nr].config = (data->autofan[nr].config & ~0xe0) |
| 595 | | (config << 5); |
| 596 | lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr), |
| 597 | data->autofan[nr].config); |
| 598 | mutex_unlock(&data->update_lock); |
| 599 | return count; |
| 600 | } |
| 601 | |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 602 | static ssize_t show_pwm_freq(struct device *dev, |
| 603 | struct device_attribute *attr, char *buf) |
| 604 | { |
| 605 | int nr = to_sensor_dev_attr(attr)->index; |
| 606 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | f6c61cf | 2010-10-28 20:31:50 +0200 | [diff] [blame] | 607 | int freq; |
| 608 | |
| 609 | if (IS_ADT7468_HFPWM(data)) |
| 610 | freq = 22500; |
| 611 | else |
| 612 | freq = FREQ_FROM_REG(data->freq_map, data->pwm_freq[nr]); |
| 613 | |
| 614 | return sprintf(buf, "%d\n", freq); |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | static ssize_t set_pwm_freq(struct device *dev, |
| 618 | struct device_attribute *attr, const char *buf, size_t count) |
| 619 | { |
| 620 | int nr = to_sensor_dev_attr(attr)->index; |
| 621 | struct i2c_client *client = to_i2c_client(dev); |
| 622 | struct lm85_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 623 | unsigned long val; |
| 624 | int err; |
| 625 | |
| 626 | err = kstrtoul(buf, 10, &val); |
| 627 | if (err) |
| 628 | return err; |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 629 | |
| 630 | mutex_lock(&data->update_lock); |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 631 | /* |
| 632 | * The ADT7468 has a special high-frequency PWM output mode, |
Jean Delvare | f6c61cf | 2010-10-28 20:31:50 +0200 | [diff] [blame] | 633 | * where all PWM outputs are driven by a 22.5 kHz clock. |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 634 | * This might confuse the user, but there's not much we can do. |
| 635 | */ |
Jean Delvare | f6c61cf | 2010-10-28 20:31:50 +0200 | [diff] [blame] | 636 | if (data->type == adt7468 && val >= 11300) { /* High freq. mode */ |
| 637 | data->cfg5 &= ~ADT7468_HFPWM; |
| 638 | lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5); |
| 639 | } else { /* Low freq. mode */ |
| 640 | data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val); |
| 641 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), |
| 642 | (data->zone[nr].range << 4) |
| 643 | | data->pwm_freq[nr]); |
| 644 | if (data->type == adt7468) { |
| 645 | data->cfg5 |= ADT7468_HFPWM; |
| 646 | lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5); |
| 647 | } |
| 648 | } |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 649 | mutex_unlock(&data->update_lock); |
| 650 | return count; |
| 651 | } |
| 652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | #define show_pwm_reg(offset) \ |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 654 | static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ |
| 655 | show_pwm, set_pwm, offset - 1); \ |
Jean Delvare | 455f791 | 2007-12-03 23:28:42 +0100 | [diff] [blame] | 656 | static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 657 | show_pwm_enable, set_pwm_enable, offset - 1); \ |
| 658 | static SENSOR_DEVICE_ATTR(pwm##offset##_freq, S_IRUGO | S_IWUSR, \ |
| 659 | show_pwm_freq, set_pwm_freq, offset - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
| 661 | show_pwm_reg(1); |
| 662 | show_pwm_reg(2); |
| 663 | show_pwm_reg(3); |
| 664 | |
| 665 | /* Voltages */ |
| 666 | |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 667 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, |
| 668 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 670 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 672 | return sprintf(buf, "%d\n", INSEXT_FROM_REG(nr, data->in[nr], |
| 673 | data->in_ext[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 675 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 676 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 677 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 679 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 681 | return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_min[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 683 | |
| 684 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, |
| 685 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 687 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | struct i2c_client *client = to_i2c_client(dev); |
| 689 | struct lm85_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 690 | long val; |
| 691 | int err; |
| 692 | |
| 693 | err = kstrtol(buf, 10, &val); |
| 694 | if (err) |
| 695 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 697 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | data->in_min[nr] = INS_TO_REG(nr, val); |
| 699 | lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 700 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | return count; |
| 702 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 703 | |
| 704 | static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, |
| 705 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 707 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 709 | return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_max[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 711 | |
| 712 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, |
| 713 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 715 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | struct i2c_client *client = to_i2c_client(dev); |
| 717 | struct lm85_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 718 | long val; |
| 719 | int err; |
| 720 | |
| 721 | err = kstrtol(buf, 10, &val); |
| 722 | if (err) |
| 723 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 725 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | data->in_max[nr] = INS_TO_REG(nr, val); |
| 727 | lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 728 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | return count; |
| 730 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | #define show_in_reg(offset) \ |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 733 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
| 734 | show_in, NULL, offset); \ |
| 735 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
| 736 | show_in_min, set_in_min, offset); \ |
| 737 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ |
| 738 | show_in_max, set_in_max, offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | |
| 740 | show_in_reg(0); |
| 741 | show_in_reg(1); |
| 742 | show_in_reg(2); |
| 743 | show_in_reg(3); |
| 744 | show_in_reg(4); |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 745 | show_in_reg(5); |
| 746 | show_in_reg(6); |
| 747 | show_in_reg(7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | |
| 749 | /* Temps */ |
| 750 | |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 751 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
| 752 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 754 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 756 | return sprintf(buf, "%d\n", TEMPEXT_FROM_REG(data->temp[nr], |
| 757 | data->temp_ext[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 759 | |
| 760 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, |
| 761 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 763 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 765 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 767 | |
| 768 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, |
| 769 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 771 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | struct i2c_client *client = to_i2c_client(dev); |
| 773 | struct lm85_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 774 | long val; |
| 775 | int err; |
| 776 | |
| 777 | err = kstrtol(buf, 10, &val); |
| 778 | if (err) |
| 779 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
Darrick J. Wong | 79b92f2 | 2008-11-12 13:26:59 -0800 | [diff] [blame] | 781 | if (IS_ADT7468_OFF64(data)) |
| 782 | val += 64; |
| 783 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 784 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | data->temp_min[nr] = TEMP_TO_REG(val); |
| 786 | lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 787 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | return count; |
| 789 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 790 | |
| 791 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, |
| 792 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 794 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 796 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 798 | |
| 799 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
| 800 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 802 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | struct i2c_client *client = to_i2c_client(dev); |
| 804 | struct lm85_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 805 | long val; |
| 806 | int err; |
| 807 | |
| 808 | err = kstrtol(buf, 10, &val); |
| 809 | if (err) |
| 810 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | |
Darrick J. Wong | 79b92f2 | 2008-11-12 13:26:59 -0800 | [diff] [blame] | 812 | if (IS_ADT7468_OFF64(data)) |
| 813 | val += 64; |
| 814 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 815 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | data->temp_max[nr] = TEMP_TO_REG(val); |
| 817 | lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 818 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | return count; |
| 820 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | #define show_temp_reg(offset) \ |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 823 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
| 824 | show_temp, NULL, offset - 1); \ |
| 825 | static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ |
| 826 | show_temp_min, set_temp_min, offset - 1); \ |
| 827 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ |
| 828 | show_temp_max, set_temp_max, offset - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
| 830 | show_temp_reg(1); |
| 831 | show_temp_reg(2); |
| 832 | show_temp_reg(3); |
| 833 | |
| 834 | |
| 835 | /* Automatic PWM control */ |
| 836 | |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 837 | static ssize_t show_pwm_auto_channels(struct device *dev, |
| 838 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 840 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 842 | return sprintf(buf, "%d\n", ZONE_FROM_REG(data->autofan[nr].config)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 844 | |
| 845 | static ssize_t set_pwm_auto_channels(struct device *dev, |
| 846 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 848 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | struct i2c_client *client = to_i2c_client(dev); |
| 850 | struct lm85_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 851 | long val; |
| 852 | int err; |
| 853 | |
| 854 | err = kstrtol(buf, 10, &val); |
| 855 | if (err) |
| 856 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 858 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | data->autofan[nr].config = (data->autofan[nr].config & (~0xe0)) |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 860 | | ZONE_TO_REG(val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr), |
| 862 | data->autofan[nr].config); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 863 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | return count; |
| 865 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 866 | |
| 867 | static ssize_t show_pwm_auto_pwm_min(struct device *dev, |
| 868 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 870 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 872 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 874 | |
| 875 | static ssize_t set_pwm_auto_pwm_min(struct device *dev, |
| 876 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 878 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | struct i2c_client *client = to_i2c_client(dev); |
| 880 | struct lm85_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 881 | unsigned long val; |
| 882 | int err; |
| 883 | |
| 884 | err = kstrtoul(buf, 10, &val); |
| 885 | if (err) |
| 886 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 888 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | data->autofan[nr].min_pwm = PWM_TO_REG(val); |
| 890 | lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr), |
| 891 | data->autofan[nr].min_pwm); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 892 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | return count; |
| 894 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 895 | |
| 896 | static ssize_t show_pwm_auto_pwm_minctl(struct device *dev, |
| 897 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 899 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 901 | return sprintf(buf, "%d\n", data->autofan[nr].min_off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 903 | |
| 904 | static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, |
| 905 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 907 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | struct i2c_client *client = to_i2c_client(dev); |
| 909 | struct lm85_data *data = i2c_get_clientdata(client); |
Jean Delvare | 7133e56 | 2008-04-12 19:56:35 +0200 | [diff] [blame] | 910 | u8 tmp; |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 911 | long val; |
| 912 | int err; |
| 913 | |
| 914 | err = kstrtol(buf, 10, &val); |
| 915 | if (err) |
| 916 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 918 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | data->autofan[nr].min_off = val; |
Jean Delvare | 7133e56 | 2008-04-12 19:56:35 +0200 | [diff] [blame] | 920 | tmp = lm85_read_value(client, LM85_REG_AFAN_SPIKE1); |
| 921 | tmp &= ~(0x20 << nr); |
| 922 | if (data->autofan[nr].min_off) |
| 923 | tmp |= 0x20 << nr; |
| 924 | lm85_write_value(client, LM85_REG_AFAN_SPIKE1, tmp); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 925 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | return count; |
| 927 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 928 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | #define pwm_auto(offset) \ |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 930 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels, \ |
| 931 | S_IRUGO | S_IWUSR, show_pwm_auto_channels, \ |
| 932 | set_pwm_auto_channels, offset - 1); \ |
| 933 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_min, \ |
| 934 | S_IRUGO | S_IWUSR, show_pwm_auto_pwm_min, \ |
| 935 | set_pwm_auto_pwm_min, offset - 1); \ |
| 936 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, \ |
| 937 | S_IRUGO | S_IWUSR, show_pwm_auto_pwm_minctl, \ |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 938 | set_pwm_auto_pwm_minctl, offset - 1) |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | pwm_auto(1); |
| 941 | pwm_auto(2); |
| 942 | pwm_auto(3); |
| 943 | |
| 944 | /* Temperature settings for automatic PWM control */ |
| 945 | |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 946 | static ssize_t show_temp_auto_temp_off(struct device *dev, |
| 947 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 949 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 951 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | HYST_FROM_REG(data->zone[nr].hyst)); |
| 953 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 954 | |
| 955 | static ssize_t set_temp_auto_temp_off(struct device *dev, |
| 956 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 958 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | struct i2c_client *client = to_i2c_client(dev); |
| 960 | struct lm85_data *data = i2c_get_clientdata(client); |
| 961 | int min; |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 962 | long val; |
| 963 | int err; |
| 964 | |
| 965 | err = kstrtol(buf, 10, &val); |
| 966 | if (err) |
| 967 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 969 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | min = TEMP_FROM_REG(data->zone[nr].limit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | data->zone[nr].hyst = HYST_TO_REG(min - val); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 972 | if (nr == 0 || nr == 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | lm85_write_value(client, LM85_REG_AFAN_HYST1, |
| 974 | (data->zone[0].hyst << 4) |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 975 | | data->zone[1].hyst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | } else { |
| 977 | lm85_write_value(client, LM85_REG_AFAN_HYST2, |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 978 | (data->zone[2].hyst << 4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | } |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 980 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | return count; |
| 982 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 983 | |
| 984 | static ssize_t show_temp_auto_temp_min(struct device *dev, |
| 985 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 987 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 989 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 991 | |
| 992 | static ssize_t set_temp_auto_temp_min(struct device *dev, |
| 993 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 995 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | struct i2c_client *client = to_i2c_client(dev); |
| 997 | struct lm85_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 998 | long val; |
| 999 | int err; |
| 1000 | |
| 1001 | err = kstrtol(buf, 10, &val); |
| 1002 | if (err) |
| 1003 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1005 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | data->zone[nr].limit = TEMP_TO_REG(val); |
| 1007 | lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr), |
| 1008 | data->zone[nr].limit); |
| 1009 | |
| 1010 | /* Update temp_auto_max and temp_auto_range */ |
| 1011 | data->zone[nr].range = RANGE_TO_REG( |
| 1012 | TEMP_FROM_REG(data->zone[nr].max_desired) - |
| 1013 | TEMP_FROM_REG(data->zone[nr].limit)); |
| 1014 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), |
| 1015 | ((data->zone[nr].range & 0x0f) << 4) |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 1016 | | (data->pwm_freq[nr] & 0x07)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1018 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | return count; |
| 1020 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1021 | |
| 1022 | static ssize_t show_temp_auto_temp_max(struct device *dev, |
| 1023 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1025 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1027 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | RANGE_FROM_REG(data->zone[nr].range)); |
| 1029 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1030 | |
| 1031 | static ssize_t set_temp_auto_temp_max(struct device *dev, |
| 1032 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1034 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | struct i2c_client *client = to_i2c_client(dev); |
| 1036 | struct lm85_data *data = i2c_get_clientdata(client); |
| 1037 | int min; |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1038 | long val; |
| 1039 | int err; |
| 1040 | |
| 1041 | err = kstrtol(buf, 10, &val); |
| 1042 | if (err) |
| 1043 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1045 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | min = TEMP_FROM_REG(data->zone[nr].limit); |
| 1047 | data->zone[nr].max_desired = TEMP_TO_REG(val); |
| 1048 | data->zone[nr].range = RANGE_TO_REG( |
| 1049 | val - min); |
| 1050 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), |
| 1051 | ((data->zone[nr].range & 0x0f) << 4) |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 1052 | | (data->pwm_freq[nr] & 0x07)); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1053 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | return count; |
| 1055 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1056 | |
| 1057 | static ssize_t show_temp_auto_temp_crit(struct device *dev, |
| 1058 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1060 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | struct lm85_data *data = lm85_update_device(dev); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1062 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].critical)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1064 | |
| 1065 | static ssize_t set_temp_auto_temp_crit(struct device *dev, |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1066 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1068 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | struct i2c_client *client = to_i2c_client(dev); |
| 1070 | struct lm85_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1071 | long val; |
| 1072 | int err; |
| 1073 | |
| 1074 | err = kstrtol(buf, 10, &val); |
| 1075 | if (err) |
| 1076 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1078 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | data->zone[nr].critical = TEMP_TO_REG(val); |
| 1080 | lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr), |
| 1081 | data->zone[nr].critical); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1082 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | return count; |
| 1084 | } |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1085 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | #define temp_auto(offset) \ |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1087 | static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_off, \ |
| 1088 | S_IRUGO | S_IWUSR, show_temp_auto_temp_off, \ |
| 1089 | set_temp_auto_temp_off, offset - 1); \ |
| 1090 | static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_min, \ |
| 1091 | S_IRUGO | S_IWUSR, show_temp_auto_temp_min, \ |
| 1092 | set_temp_auto_temp_min, offset - 1); \ |
| 1093 | static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_max, \ |
| 1094 | S_IRUGO | S_IWUSR, show_temp_auto_temp_max, \ |
| 1095 | set_temp_auto_temp_max, offset - 1); \ |
| 1096 | static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_crit, \ |
| 1097 | S_IRUGO | S_IWUSR, show_temp_auto_temp_crit, \ |
| 1098 | set_temp_auto_temp_crit, offset - 1); |
| 1099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | temp_auto(1); |
| 1101 | temp_auto(2); |
| 1102 | temp_auto(3); |
| 1103 | |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1104 | static struct attribute *lm85_attributes[] = { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1105 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 1106 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
| 1107 | &sensor_dev_attr_fan3_input.dev_attr.attr, |
| 1108 | &sensor_dev_attr_fan4_input.dev_attr.attr, |
| 1109 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
| 1110 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
| 1111 | &sensor_dev_attr_fan3_min.dev_attr.attr, |
| 1112 | &sensor_dev_attr_fan4_min.dev_attr.attr, |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 1113 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
| 1114 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
| 1115 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, |
| 1116 | &sensor_dev_attr_fan4_alarm.dev_attr.attr, |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1117 | |
| 1118 | &sensor_dev_attr_pwm1.dev_attr.attr, |
| 1119 | &sensor_dev_attr_pwm2.dev_attr.attr, |
| 1120 | &sensor_dev_attr_pwm3.dev_attr.attr, |
| 1121 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
| 1122 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, |
| 1123 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 1124 | &sensor_dev_attr_pwm1_freq.dev_attr.attr, |
| 1125 | &sensor_dev_attr_pwm2_freq.dev_attr.attr, |
| 1126 | &sensor_dev_attr_pwm3_freq.dev_attr.attr, |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1127 | |
| 1128 | &sensor_dev_attr_in0_input.dev_attr.attr, |
| 1129 | &sensor_dev_attr_in1_input.dev_attr.attr, |
| 1130 | &sensor_dev_attr_in2_input.dev_attr.attr, |
| 1131 | &sensor_dev_attr_in3_input.dev_attr.attr, |
| 1132 | &sensor_dev_attr_in0_min.dev_attr.attr, |
| 1133 | &sensor_dev_attr_in1_min.dev_attr.attr, |
| 1134 | &sensor_dev_attr_in2_min.dev_attr.attr, |
| 1135 | &sensor_dev_attr_in3_min.dev_attr.attr, |
| 1136 | &sensor_dev_attr_in0_max.dev_attr.attr, |
| 1137 | &sensor_dev_attr_in1_max.dev_attr.attr, |
| 1138 | &sensor_dev_attr_in2_max.dev_attr.attr, |
| 1139 | &sensor_dev_attr_in3_max.dev_attr.attr, |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 1140 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
| 1141 | &sensor_dev_attr_in1_alarm.dev_attr.attr, |
| 1142 | &sensor_dev_attr_in2_alarm.dev_attr.attr, |
| 1143 | &sensor_dev_attr_in3_alarm.dev_attr.attr, |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1144 | |
| 1145 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 1146 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| 1147 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
| 1148 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
| 1149 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
| 1150 | &sensor_dev_attr_temp3_min.dev_attr.attr, |
| 1151 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 1152 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
| 1153 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 1154 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, |
| 1155 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, |
| 1156 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, |
| 1157 | &sensor_dev_attr_temp1_fault.dev_attr.attr, |
| 1158 | &sensor_dev_attr_temp3_fault.dev_attr.attr, |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1159 | |
| 1160 | &sensor_dev_attr_pwm1_auto_channels.dev_attr.attr, |
| 1161 | &sensor_dev_attr_pwm2_auto_channels.dev_attr.attr, |
| 1162 | &sensor_dev_attr_pwm3_auto_channels.dev_attr.attr, |
| 1163 | &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr, |
| 1164 | &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr, |
| 1165 | &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr, |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1166 | |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1167 | &sensor_dev_attr_temp1_auto_temp_min.dev_attr.attr, |
| 1168 | &sensor_dev_attr_temp2_auto_temp_min.dev_attr.attr, |
| 1169 | &sensor_dev_attr_temp3_auto_temp_min.dev_attr.attr, |
| 1170 | &sensor_dev_attr_temp1_auto_temp_max.dev_attr.attr, |
| 1171 | &sensor_dev_attr_temp2_auto_temp_max.dev_attr.attr, |
| 1172 | &sensor_dev_attr_temp3_auto_temp_max.dev_attr.attr, |
| 1173 | &sensor_dev_attr_temp1_auto_temp_crit.dev_attr.attr, |
| 1174 | &sensor_dev_attr_temp2_auto_temp_crit.dev_attr.attr, |
| 1175 | &sensor_dev_attr_temp3_auto_temp_crit.dev_attr.attr, |
| 1176 | |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1177 | &dev_attr_vrm.attr, |
| 1178 | &dev_attr_cpu0_vid.attr, |
| 1179 | &dev_attr_alarms.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1180 | NULL |
| 1181 | }; |
| 1182 | |
| 1183 | static const struct attribute_group lm85_group = { |
| 1184 | .attrs = lm85_attributes, |
| 1185 | }; |
| 1186 | |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1187 | static struct attribute *lm85_attributes_minctl[] = { |
| 1188 | &sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr, |
| 1189 | &sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr, |
| 1190 | &sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr, |
Jean Delvare | 5f441e2 | 2011-04-29 16:33:36 +0200 | [diff] [blame] | 1191 | NULL |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1192 | }; |
| 1193 | |
| 1194 | static const struct attribute_group lm85_group_minctl = { |
| 1195 | .attrs = lm85_attributes_minctl, |
| 1196 | }; |
| 1197 | |
| 1198 | static struct attribute *lm85_attributes_temp_off[] = { |
| 1199 | &sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr, |
| 1200 | &sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr, |
| 1201 | &sensor_dev_attr_temp3_auto_temp_off.dev_attr.attr, |
Jean Delvare | 5f441e2 | 2011-04-29 16:33:36 +0200 | [diff] [blame] | 1202 | NULL |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1203 | }; |
| 1204 | |
| 1205 | static const struct attribute_group lm85_group_temp_off = { |
| 1206 | .attrs = lm85_attributes_temp_off, |
| 1207 | }; |
| 1208 | |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 1209 | static struct attribute *lm85_attributes_in4[] = { |
Jean Delvare | b353a48 | 2007-07-05 20:36:12 +0200 | [diff] [blame] | 1210 | &sensor_dev_attr_in4_input.dev_attr.attr, |
| 1211 | &sensor_dev_attr_in4_min.dev_attr.attr, |
| 1212 | &sensor_dev_attr_in4_max.dev_attr.attr, |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 1213 | &sensor_dev_attr_in4_alarm.dev_attr.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1214 | NULL |
| 1215 | }; |
| 1216 | |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 1217 | static const struct attribute_group lm85_group_in4 = { |
| 1218 | .attrs = lm85_attributes_in4, |
| 1219 | }; |
| 1220 | |
| 1221 | static struct attribute *lm85_attributes_in567[] = { |
| 1222 | &sensor_dev_attr_in5_input.dev_attr.attr, |
| 1223 | &sensor_dev_attr_in6_input.dev_attr.attr, |
| 1224 | &sensor_dev_attr_in7_input.dev_attr.attr, |
| 1225 | &sensor_dev_attr_in5_min.dev_attr.attr, |
| 1226 | &sensor_dev_attr_in6_min.dev_attr.attr, |
| 1227 | &sensor_dev_attr_in7_min.dev_attr.attr, |
| 1228 | &sensor_dev_attr_in5_max.dev_attr.attr, |
| 1229 | &sensor_dev_attr_in6_max.dev_attr.attr, |
| 1230 | &sensor_dev_attr_in7_max.dev_attr.attr, |
Jean Delvare | bf76e9d | 2007-07-05 20:37:58 +0200 | [diff] [blame] | 1231 | &sensor_dev_attr_in5_alarm.dev_attr.attr, |
| 1232 | &sensor_dev_attr_in6_alarm.dev_attr.attr, |
| 1233 | &sensor_dev_attr_in7_alarm.dev_attr.attr, |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 1234 | NULL |
| 1235 | }; |
| 1236 | |
| 1237 | static const struct attribute_group lm85_group_in567 = { |
| 1238 | .attrs = lm85_attributes_in567, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1239 | }; |
| 1240 | |
Jean Delvare | 5f4475947 | 2008-06-25 09:10:30 -0400 | [diff] [blame] | 1241 | static void lm85_init_client(struct i2c_client *client) |
| 1242 | { |
| 1243 | int value; |
| 1244 | |
| 1245 | /* Start monitoring if needed */ |
| 1246 | value = lm85_read_value(client, LM85_REG_CONFIG); |
| 1247 | if (!(value & 0x01)) { |
| 1248 | dev_info(&client->dev, "Starting monitoring\n"); |
| 1249 | lm85_write_value(client, LM85_REG_CONFIG, value | 0x01); |
| 1250 | } |
| 1251 | |
| 1252 | /* Warn about unusual configuration bits */ |
| 1253 | if (value & 0x02) |
| 1254 | dev_warn(&client->dev, "Device configuration is locked\n"); |
| 1255 | if (!(value & 0x04)) |
| 1256 | dev_warn(&client->dev, "Device is not ready\n"); |
| 1257 | } |
| 1258 | |
Jean Delvare | 5cfaf33 | 2009-09-15 17:18:14 +0200 | [diff] [blame] | 1259 | static int lm85_is_fake(struct i2c_client *client) |
| 1260 | { |
| 1261 | /* |
| 1262 | * Differenciate between real LM96000 and Winbond WPCD377I. The latter |
| 1263 | * emulate the former except that it has no hardware monitoring function |
| 1264 | * so the readings are always 0. |
| 1265 | */ |
| 1266 | int i; |
| 1267 | u8 in_temp, fan; |
| 1268 | |
| 1269 | for (i = 0; i < 8; i++) { |
| 1270 | in_temp = i2c_smbus_read_byte_data(client, 0x20 + i); |
| 1271 | fan = i2c_smbus_read_byte_data(client, 0x28 + i); |
| 1272 | if (in_temp != 0x00 || fan != 0xff) |
| 1273 | return 0; |
| 1274 | } |
| 1275 | |
| 1276 | return 1; |
| 1277 | } |
| 1278 | |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1279 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 1280 | static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | { |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1282 | struct i2c_adapter *adapter = client->adapter; |
| 1283 | int address = client->addr; |
Jean Delvare | 590e853 | 2014-06-11 18:35:56 +0200 | [diff] [blame] | 1284 | const char *type_name = NULL; |
Jean Delvare | d42a2eb | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1285 | int company, verstep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1287 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | /* We need to be able to do byte I/O */ |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1289 | return -ENODEV; |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1290 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | |
Jean Delvare | d42a2eb | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1292 | /* Determine the chip type */ |
| 1293 | company = lm85_read_value(client, LM85_REG_COMPANY); |
| 1294 | verstep = lm85_read_value(client, LM85_REG_VERSTEP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
Guenter Roeck | b55f375 | 2013-01-10 10:01:24 -0800 | [diff] [blame] | 1296 | dev_dbg(&adapter->dev, |
| 1297 | "Detecting device at 0x%02x with COMPANY: 0x%02x and VERSTEP: 0x%02x\n", |
Jean Delvare | d42a2eb | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1298 | address, company, verstep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | |
Jean Delvare | d42a2eb | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1300 | if (company == LM85_COMPANY_NATIONAL) { |
| 1301 | switch (verstep) { |
| 1302 | case LM85_VERSTEP_LM85C: |
| 1303 | type_name = "lm85c"; |
| 1304 | break; |
| 1305 | case LM85_VERSTEP_LM85B: |
| 1306 | type_name = "lm85b"; |
| 1307 | break; |
| 1308 | case LM85_VERSTEP_LM96000_1: |
| 1309 | case LM85_VERSTEP_LM96000_2: |
| 1310 | /* Check for Winbond WPCD377I */ |
| 1311 | if (lm85_is_fake(client)) { |
| 1312 | dev_dbg(&adapter->dev, |
| 1313 | "Found Winbond WPCD377I, ignoring\n"); |
| 1314 | return -ENODEV; |
| 1315 | } |
Jean Delvare | 590e853 | 2014-06-11 18:35:56 +0200 | [diff] [blame] | 1316 | type_name = "lm85"; |
Jean Delvare | d42a2eb | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1317 | break; |
Jean Delvare | 69fc1fe | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 1318 | } |
Jean Delvare | d42a2eb | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1319 | } else if (company == LM85_COMPANY_ANALOG_DEV) { |
| 1320 | switch (verstep) { |
| 1321 | case LM85_VERSTEP_ADM1027: |
| 1322 | type_name = "adm1027"; |
| 1323 | break; |
| 1324 | case LM85_VERSTEP_ADT7463: |
| 1325 | case LM85_VERSTEP_ADT7463C: |
| 1326 | type_name = "adt7463"; |
| 1327 | break; |
| 1328 | case LM85_VERSTEP_ADT7468_1: |
| 1329 | case LM85_VERSTEP_ADT7468_2: |
| 1330 | type_name = "adt7468"; |
| 1331 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | } |
Jean Delvare | d42a2eb | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1333 | } else if (company == LM85_COMPANY_SMSC) { |
| 1334 | switch (verstep) { |
| 1335 | case LM85_VERSTEP_EMC6D100_A0: |
| 1336 | case LM85_VERSTEP_EMC6D100_A1: |
| 1337 | /* Note: we can't tell a '100 from a '101 */ |
| 1338 | type_name = "emc6d100"; |
| 1339 | break; |
| 1340 | case LM85_VERSTEP_EMC6D102: |
| 1341 | type_name = "emc6d102"; |
| 1342 | break; |
Jan Beulich | f065a93 | 2011-02-18 03:18:26 -0500 | [diff] [blame] | 1343 | case LM85_VERSTEP_EMC6D103_A0: |
| 1344 | case LM85_VERSTEP_EMC6D103_A1: |
| 1345 | type_name = "emc6d103"; |
| 1346 | break; |
Jan Beulich | f065a93 | 2011-02-18 03:18:26 -0500 | [diff] [blame] | 1347 | case LM85_VERSTEP_EMC6D103S: |
| 1348 | type_name = "emc6d103s"; |
| 1349 | break; |
Jean Delvare | d42a2eb | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1350 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | } |
| 1352 | |
Jean Delvare | 590e853 | 2014-06-11 18:35:56 +0200 | [diff] [blame] | 1353 | if (!type_name) |
| 1354 | return -ENODEV; |
| 1355 | |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1356 | strlcpy(info->type, type_name, I2C_NAME_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1358 | return 0; |
| 1359 | } |
| 1360 | |
Guenter Roeck | bc6db2b | 2011-02-25 08:26:47 -0800 | [diff] [blame] | 1361 | static void lm85_remove_files(struct i2c_client *client, struct lm85_data *data) |
| 1362 | { |
| 1363 | sysfs_remove_group(&client->dev.kobj, &lm85_group); |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1364 | if (data->type != emc6d103s) { |
| 1365 | sysfs_remove_group(&client->dev.kobj, &lm85_group_minctl); |
| 1366 | sysfs_remove_group(&client->dev.kobj, &lm85_group_temp_off); |
| 1367 | } |
Guenter Roeck | bc6db2b | 2011-02-25 08:26:47 -0800 | [diff] [blame] | 1368 | if (!data->has_vid5) |
| 1369 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in4); |
| 1370 | if (data->type == emc6d100) |
| 1371 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in567); |
| 1372 | } |
| 1373 | |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1374 | static int lm85_probe(struct i2c_client *client, |
| 1375 | const struct i2c_device_id *id) |
| 1376 | { |
| 1377 | struct lm85_data *data; |
| 1378 | int err; |
| 1379 | |
Guenter Roeck | 747e5d6 | 2012-06-02 09:58:10 -0700 | [diff] [blame] | 1380 | data = devm_kzalloc(&client->dev, sizeof(struct lm85_data), GFP_KERNEL); |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1381 | if (!data) |
| 1382 | return -ENOMEM; |
| 1383 | |
| 1384 | i2c_set_clientdata(client, data); |
| 1385 | data->type = id->driver_data; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1386 | mutex_init(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1388 | /* Fill in the chip specific driver values */ |
| 1389 | switch (data->type) { |
| 1390 | case adm1027: |
| 1391 | case adt7463: |
Jean Delvare | fa7a579 | 2010-10-28 20:31:50 +0200 | [diff] [blame] | 1392 | case adt7468: |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1393 | case emc6d100: |
| 1394 | case emc6d102: |
Jan Beulich | f065a93 | 2011-02-18 03:18:26 -0500 | [diff] [blame] | 1395 | case emc6d103: |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1396 | case emc6d103s: |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1397 | data->freq_map = adm1027_freq_map; |
| 1398 | break; |
| 1399 | default: |
| 1400 | data->freq_map = lm85_freq_map; |
| 1401 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | |
| 1403 | /* Set the VRM version */ |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 1404 | data->vrm = vid_which_vrm(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | |
| 1406 | /* Initialize the LM85 chip */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1407 | lm85_init_client(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | |
| 1409 | /* Register sysfs hooks */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1410 | err = sysfs_create_group(&client->dev.kobj, &lm85_group); |
| 1411 | if (err) |
Guenter Roeck | 747e5d6 | 2012-06-02 09:58:10 -0700 | [diff] [blame] | 1412 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1414 | /* minctl and temp_off exist on all chips except emc6d103s */ |
| 1415 | if (data->type != emc6d103s) { |
| 1416 | err = sysfs_create_group(&client->dev.kobj, &lm85_group_minctl); |
| 1417 | if (err) |
Jean Delvare | bc4d45f | 2011-04-29 16:33:36 +0200 | [diff] [blame] | 1418 | goto err_remove_files; |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1419 | err = sysfs_create_group(&client->dev.kobj, |
| 1420 | &lm85_group_temp_off); |
| 1421 | if (err) |
Jean Delvare | bc4d45f | 2011-04-29 16:33:36 +0200 | [diff] [blame] | 1422 | goto err_remove_files; |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1423 | } |
| 1424 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1425 | /* |
| 1426 | * The ADT7463/68 have an optional VRM 10 mode where pin 21 is used |
| 1427 | * as a sixth digital VID input rather than an analog input. |
| 1428 | */ |
Guenter Roeck | de24880 | 2011-02-25 08:19:42 -0800 | [diff] [blame] | 1429 | if (data->type == adt7463 || data->type == adt7468) { |
| 1430 | u8 vid = lm85_read_value(client, LM85_REG_VID); |
| 1431 | if (vid & 0x80) |
| 1432 | data->has_vid5 = true; |
| 1433 | } |
| 1434 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1435 | if (!data->has_vid5) { |
| 1436 | err = sysfs_create_group(&client->dev.kobj, &lm85_group_in4); |
| 1437 | if (err) |
Jean Delvare | f908037 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1438 | goto err_remove_files; |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1439 | } |
Jean Delvare | 6b9aad2 | 2007-07-05 20:37:21 +0200 | [diff] [blame] | 1440 | |
| 1441 | /* The EMC6D100 has 3 additional voltage inputs */ |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1442 | if (data->type == emc6d100) { |
| 1443 | err = sysfs_create_group(&client->dev.kobj, &lm85_group_in567); |
| 1444 | if (err) |
Jean Delvare | f908037 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1445 | goto err_remove_files; |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1446 | } |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 1447 | |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1448 | data->hwmon_dev = hwmon_device_register(&client->dev); |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1449 | if (IS_ERR(data->hwmon_dev)) { |
| 1450 | err = PTR_ERR(data->hwmon_dev); |
Jean Delvare | f908037 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1451 | goto err_remove_files; |
Jean Delvare | 9c516ef | 2005-11-26 20:07:54 +0100 | [diff] [blame] | 1452 | } |
| 1453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | return 0; |
| 1455 | |
| 1456 | /* Error out and cleanup code */ |
Jean Delvare | f908037 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1457 | err_remove_files: |
Guenter Roeck | bc6db2b | 2011-02-25 08:26:47 -0800 | [diff] [blame] | 1458 | lm85_remove_files(client, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | return err; |
| 1460 | } |
| 1461 | |
Jean Delvare | 67712d0 | 2008-10-17 17:51:14 +0200 | [diff] [blame] | 1462 | static int lm85_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | { |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1464 | struct lm85_data *data = i2c_get_clientdata(client); |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1465 | hwmon_device_unregister(data->hwmon_dev); |
Guenter Roeck | bc6db2b | 2011-02-25 08:26:47 -0800 | [diff] [blame] | 1466 | lm85_remove_files(client, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | return 0; |
| 1468 | } |
| 1469 | |
| 1470 | |
Ben Dooks | d8d2061 | 2005-10-26 21:05:46 +0200 | [diff] [blame] | 1471 | static int lm85_read_value(struct i2c_client *client, u8 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | { |
| 1473 | int res; |
| 1474 | |
| 1475 | /* What size location is it? */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1476 | switch (reg) { |
| 1477 | case LM85_REG_FAN(0): /* Read WORD data */ |
| 1478 | case LM85_REG_FAN(1): |
| 1479 | case LM85_REG_FAN(2): |
| 1480 | case LM85_REG_FAN(3): |
| 1481 | case LM85_REG_FAN_MIN(0): |
| 1482 | case LM85_REG_FAN_MIN(1): |
| 1483 | case LM85_REG_FAN_MIN(2): |
| 1484 | case LM85_REG_FAN_MIN(3): |
| 1485 | case LM85_REG_ALARM1: /* Read both bytes at once */ |
| 1486 | res = i2c_smbus_read_byte_data(client, reg) & 0xff; |
| 1487 | res |= i2c_smbus_read_byte_data(client, reg + 1) << 8; |
| 1488 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | default: /* Read BYTE data */ |
| 1490 | res = i2c_smbus_read_byte_data(client, reg); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1491 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1494 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1497 | static void lm85_write_value(struct i2c_client *client, u8 reg, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | { |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1499 | switch (reg) { |
| 1500 | case LM85_REG_FAN(0): /* Write WORD data */ |
| 1501 | case LM85_REG_FAN(1): |
| 1502 | case LM85_REG_FAN(2): |
| 1503 | case LM85_REG_FAN(3): |
| 1504 | case LM85_REG_FAN_MIN(0): |
| 1505 | case LM85_REG_FAN_MIN(1): |
| 1506 | case LM85_REG_FAN_MIN(2): |
| 1507 | case LM85_REG_FAN_MIN(3): |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | /* NOTE: ALARM is read only, so not included here */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1509 | i2c_smbus_write_byte_data(client, reg, value & 0xff); |
| 1510 | i2c_smbus_write_byte_data(client, reg + 1, value >> 8); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1511 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | default: /* Write BYTE data */ |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1513 | i2c_smbus_write_byte_data(client, reg, value); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1514 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | static struct lm85_data *lm85_update_device(struct device *dev) |
| 1519 | { |
| 1520 | struct i2c_client *client = to_i2c_client(dev); |
| 1521 | struct lm85_data *data = i2c_get_clientdata(client); |
| 1522 | int i; |
| 1523 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1524 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1526 | if (!data->valid || |
| 1527 | time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | /* Things that change quickly */ |
| 1529 | dev_dbg(&client->dev, "Reading sensor values\n"); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1530 | |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1531 | /* |
| 1532 | * Have to read extended bits first to "freeze" the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | * more significant bits that are read later. |
Jean Delvare | 5a4d3ef | 2007-07-05 20:38:32 +0200 | [diff] [blame] | 1534 | * There are 2 additional resolution bits per channel and we |
| 1535 | * have room for 4, so we shift them to the left. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | */ |
Darrick J. Wong | 79b92f2 | 2008-11-12 13:26:59 -0800 | [diff] [blame] | 1537 | if (data->type == adm1027 || data->type == adt7463 || |
| 1538 | data->type == adt7468) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | int ext1 = lm85_read_value(client, |
| 1540 | ADM1027_REG_EXTEND_ADC1); |
| 1541 | int ext2 = lm85_read_value(client, |
| 1542 | ADM1027_REG_EXTEND_ADC2); |
| 1543 | int val = (ext1 << 8) + ext2; |
| 1544 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1545 | for (i = 0; i <= 4; i++) |
| 1546 | data->in_ext[i] = |
| 1547 | ((val >> (i * 2)) & 0x03) << 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1549 | for (i = 0; i <= 2; i++) |
| 1550 | data->temp_ext[i] = |
| 1551 | (val >> ((i + 4) * 2)) & 0x0c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
Jean Delvare | 9c516ef | 2005-11-26 20:07:54 +0100 | [diff] [blame] | 1554 | data->vid = lm85_read_value(client, LM85_REG_VID); |
| 1555 | |
| 1556 | for (i = 0; i <= 3; ++i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | data->in[i] = |
| 1558 | lm85_read_value(client, LM85_REG_IN(i)); |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1559 | data->fan[i] = |
| 1560 | lm85_read_value(client, LM85_REG_FAN(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
Guenter Roeck | de24880 | 2011-02-25 08:19:42 -0800 | [diff] [blame] | 1563 | if (!data->has_vid5) |
| 1564 | data->in[4] = lm85_read_value(client, LM85_REG_IN(4)); |
Jean Delvare | 9c516ef | 2005-11-26 20:07:54 +0100 | [diff] [blame] | 1565 | |
Darrick J. Wong | 79b92f2 | 2008-11-12 13:26:59 -0800 | [diff] [blame] | 1566 | if (data->type == adt7468) |
| 1567 | data->cfg5 = lm85_read_value(client, ADT7468_REG_CFG5); |
| 1568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | for (i = 0; i <= 2; ++i) { |
| 1570 | data->temp[i] = |
| 1571 | lm85_read_value(client, LM85_REG_TEMP(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | data->pwm[i] = |
| 1573 | lm85_read_value(client, LM85_REG_PWM(i)); |
Darrick J. Wong | 79b92f2 | 2008-11-12 13:26:59 -0800 | [diff] [blame] | 1574 | |
| 1575 | if (IS_ADT7468_OFF64(data)) |
| 1576 | data->temp[i] -= 64; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | data->alarms = lm85_read_value(client, LM85_REG_ALARM1); |
| 1580 | |
Jean Delvare | dd1ac53 | 2008-05-01 08:47:33 +0200 | [diff] [blame] | 1581 | if (data->type == emc6d100) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | /* Three more voltage sensors */ |
| 1583 | for (i = 5; i <= 7; ++i) { |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1584 | data->in[i] = lm85_read_value(client, |
| 1585 | EMC6D100_REG_IN(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | } |
| 1587 | /* More alarm bits */ |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1588 | data->alarms |= lm85_read_value(client, |
| 1589 | EMC6D100_REG_ALARM3) << 16; |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1590 | } else if (data->type == emc6d102 || data->type == emc6d103 || |
| 1591 | data->type == emc6d103s) { |
Guenter Roeck | 09770b26 | 2012-01-14 20:47:36 -0800 | [diff] [blame] | 1592 | /* |
| 1593 | * Have to read LSB bits after the MSB ones because |
| 1594 | * the reading of the MSB bits has frozen the |
| 1595 | * LSBs (backward from the ADM1027). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | */ |
| 1597 | int ext1 = lm85_read_value(client, |
| 1598 | EMC6D102_REG_EXTEND_ADC1); |
| 1599 | int ext2 = lm85_read_value(client, |
| 1600 | EMC6D102_REG_EXTEND_ADC2); |
| 1601 | int ext3 = lm85_read_value(client, |
| 1602 | EMC6D102_REG_EXTEND_ADC3); |
| 1603 | int ext4 = lm85_read_value(client, |
| 1604 | EMC6D102_REG_EXTEND_ADC4); |
| 1605 | data->in_ext[0] = ext3 & 0x0f; |
| 1606 | data->in_ext[1] = ext4 & 0x0f; |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1607 | data->in_ext[2] = ext4 >> 4; |
| 1608 | data->in_ext[3] = ext3 >> 4; |
| 1609 | data->in_ext[4] = ext2 >> 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | |
| 1611 | data->temp_ext[0] = ext1 & 0x0f; |
| 1612 | data->temp_ext[1] = ext2 & 0x0f; |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1613 | data->temp_ext[2] = ext1 >> 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1616 | data->last_reading = jiffies; |
| 1617 | } /* last_reading */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1619 | if (!data->valid || |
| 1620 | time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | /* Things that don't change often */ |
| 1622 | dev_dbg(&client->dev, "Reading config values\n"); |
| 1623 | |
Jean Delvare | 9c516ef | 2005-11-26 20:07:54 +0100 | [diff] [blame] | 1624 | for (i = 0; i <= 3; ++i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | data->in_min[i] = |
| 1626 | lm85_read_value(client, LM85_REG_IN_MIN(i)); |
| 1627 | data->in_max[i] = |
| 1628 | lm85_read_value(client, LM85_REG_IN_MAX(i)); |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1629 | data->fan_min[i] = |
| 1630 | lm85_read_value(client, LM85_REG_FAN_MIN(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | } |
| 1632 | |
Guenter Roeck | de24880 | 2011-02-25 08:19:42 -0800 | [diff] [blame] | 1633 | if (!data->has_vid5) { |
Jean Delvare | 9c516ef | 2005-11-26 20:07:54 +0100 | [diff] [blame] | 1634 | data->in_min[4] = lm85_read_value(client, |
| 1635 | LM85_REG_IN_MIN(4)); |
| 1636 | data->in_max[4] = lm85_read_value(client, |
| 1637 | LM85_REG_IN_MAX(4)); |
| 1638 | } |
| 1639 | |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1640 | if (data->type == emc6d100) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | for (i = 5; i <= 7; ++i) { |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1642 | data->in_min[i] = lm85_read_value(client, |
| 1643 | EMC6D100_REG_IN_MIN(i)); |
| 1644 | data->in_max[i] = lm85_read_value(client, |
| 1645 | EMC6D100_REG_IN_MAX(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | } |
| 1647 | } |
| 1648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | for (i = 0; i <= 2; ++i) { |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1650 | int val; |
| 1651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | data->temp_min[i] = |
| 1653 | lm85_read_value(client, LM85_REG_TEMP_MIN(i)); |
| 1654 | data->temp_max[i] = |
| 1655 | lm85_read_value(client, LM85_REG_TEMP_MAX(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | data->autofan[i].config = |
| 1658 | lm85_read_value(client, LM85_REG_AFAN_CONFIG(i)); |
| 1659 | val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i)); |
Jean Delvare | 34e7dc6 | 2008-10-17 17:51:13 +0200 | [diff] [blame] | 1660 | data->pwm_freq[i] = val & 0x07; |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1661 | data->zone[i].range = val >> 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | data->autofan[i].min_pwm = |
| 1663 | lm85_read_value(client, LM85_REG_AFAN_MINPWM(i)); |
| 1664 | data->zone[i].limit = |
| 1665 | lm85_read_value(client, LM85_REG_AFAN_LIMIT(i)); |
| 1666 | data->zone[i].critical = |
| 1667 | lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i)); |
Darrick J. Wong | 79b92f2 | 2008-11-12 13:26:59 -0800 | [diff] [blame] | 1668 | |
| 1669 | if (IS_ADT7468_OFF64(data)) { |
| 1670 | data->temp_min[i] -= 64; |
| 1671 | data->temp_max[i] -= 64; |
| 1672 | data->zone[i].limit -= 64; |
| 1673 | data->zone[i].critical -= 64; |
| 1674 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1677 | if (data->type != emc6d103s) { |
| 1678 | i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1); |
| 1679 | data->autofan[0].min_off = (i & 0x20) != 0; |
| 1680 | data->autofan[1].min_off = (i & 0x40) != 0; |
| 1681 | data->autofan[2].min_off = (i & 0x80) != 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1683 | i = lm85_read_value(client, LM85_REG_AFAN_HYST1); |
| 1684 | data->zone[0].hyst = i >> 4; |
| 1685 | data->zone[1].hyst = i & 0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | |
Guenter Roeck | 06923f8 | 2011-02-19 08:27:47 -0800 | [diff] [blame] | 1687 | i = lm85_read_value(client, LM85_REG_AFAN_HYST2); |
| 1688 | data->zone[2].hyst = i >> 4; |
| 1689 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | data->last_config = jiffies; |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1692 | } /* last_config */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | |
| 1694 | data->valid = 1; |
| 1695 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1696 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | |
| 1698 | return data; |
| 1699 | } |
| 1700 | |
Axel Lin | f0967ee | 2012-01-20 15:38:18 +0800 | [diff] [blame] | 1701 | module_i2c_driver(lm85_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | MODULE_LICENSE("GPL"); |
Jean Delvare | 1f44809 | 2008-04-29 14:03:37 +0200 | [diff] [blame] | 1704 | MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, " |
| 1705 | "Margit Schubert-While <margitsw@t-online.de>, " |
Jean Delvare | e89e22b | 2008-06-25 08:47:35 -0400 | [diff] [blame] | 1706 | "Justin Thiessen <jthiessen@penguincomputing.com>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | MODULE_DESCRIPTION("LM85-B, LM85-C driver"); |