Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Guenter Roeck | fbb6670 | 2012-01-19 11:02:14 -0800 | [diff] [blame] | 2 | * adm1031.c - Part of lm_sensors, Linux kernel modules for hardware |
| 3 | * monitoring |
| 4 | * Based on lm75.c and lm85.c |
| 5 | * Supports adm1030 / adm1031 |
| 6 | * Copyright (C) 2004 Alexandre d'Alton <alex@alexdalton.org> |
Jean Delvare | 7c81c60 | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 7 | * Reworked by Jean Delvare <jdelvare@suse.de> |
Guenter Roeck | fbb6670 | 2012-01-19 11:02:14 -0800 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/slab.h> |
| 27 | #include <linux/jiffies.h> |
| 28 | #include <linux/i2c.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 29 | #include <linux/hwmon.h> |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 30 | #include <linux/hwmon-sysfs.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 31 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 32 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | /* Following macros takes channel parameter starting from 0 to 2 */ |
| 35 | #define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr)) |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 36 | #define ADM1031_REG_FAN_DIV(nr) (0x20 + (nr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #define ADM1031_REG_PWM (0x22) |
| 38 | #define ADM1031_REG_FAN_MIN(nr) (0x10 + (nr)) |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 39 | #define ADM1031_REG_FAN_FILTER (0x23) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 41 | #define ADM1031_REG_TEMP_OFFSET(nr) (0x0d + (nr)) |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 42 | #define ADM1031_REG_TEMP_MAX(nr) (0x14 + 4 * (nr)) |
| 43 | #define ADM1031_REG_TEMP_MIN(nr) (0x15 + 4 * (nr)) |
| 44 | #define ADM1031_REG_TEMP_CRIT(nr) (0x16 + 4 * (nr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 46 | #define ADM1031_REG_TEMP(nr) (0x0a + (nr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #define ADM1031_REG_AUTO_TEMP(nr) (0x24 + (nr)) |
| 48 | |
| 49 | #define ADM1031_REG_STATUS(nr) (0x2 + (nr)) |
| 50 | |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 51 | #define ADM1031_REG_CONF1 0x00 |
| 52 | #define ADM1031_REG_CONF2 0x01 |
| 53 | #define ADM1031_REG_EXT_TEMP 0x06 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | #define ADM1031_CONF1_MONITOR_ENABLE 0x01 /* Monitoring enable */ |
| 56 | #define ADM1031_CONF1_PWM_INVERT 0x08 /* PWM Invert */ |
| 57 | #define ADM1031_CONF1_AUTO_MODE 0x80 /* Auto FAN */ |
| 58 | |
| 59 | #define ADM1031_CONF2_PWM1_ENABLE 0x01 |
| 60 | #define ADM1031_CONF2_PWM2_ENABLE 0x02 |
| 61 | #define ADM1031_CONF2_TACH1_ENABLE 0x04 |
| 62 | #define ADM1031_CONF2_TACH2_ENABLE 0x08 |
| 63 | #define ADM1031_CONF2_TEMP_ENABLE(chan) (0x10 << (chan)) |
| 64 | |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 65 | #define ADM1031_UPDATE_RATE_MASK 0x1c |
| 66 | #define ADM1031_UPDATE_RATE_SHIFT 2 |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /* Addresses to scan */ |
Mark M. Hoffman | 25e9c86 | 2008-02-17 22:28:03 -0500 | [diff] [blame] | 69 | static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Jean Delvare | e5e9f44 | 2009-12-14 21:17:27 +0100 | [diff] [blame] | 71 | enum chips { adm1030, adm1031 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | typedef u8 auto_chan_table_t[8][2]; |
| 74 | |
| 75 | /* Each client has this additional data */ |
| 76 | struct adm1031_data { |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 77 | struct i2c_client *client; |
| 78 | const struct attribute_group *groups[3]; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 79 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | int chip_type; |
| 81 | char valid; /* !=0 if following fields are valid */ |
| 82 | unsigned long last_updated; /* In jiffies */ |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 83 | unsigned int update_interval; /* In milliseconds */ |
Guenter Roeck | fbb6670 | 2012-01-19 11:02:14 -0800 | [diff] [blame] | 84 | /* |
| 85 | * The chan_select_table contains the possible configurations for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | * auto fan control. |
| 87 | */ |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 88 | const auto_chan_table_t *chan_select_table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | u16 alarm; |
| 90 | u8 conf1; |
| 91 | u8 conf2; |
| 92 | u8 fan[2]; |
| 93 | u8 fan_div[2]; |
| 94 | u8 fan_min[2]; |
| 95 | u8 pwm[2]; |
| 96 | u8 old_pwm[2]; |
| 97 | s8 temp[3]; |
| 98 | u8 ext_temp[3]; |
| 99 | u8 auto_temp[3]; |
| 100 | u8 auto_temp_min[3]; |
| 101 | u8 auto_temp_off[3]; |
| 102 | u8 auto_temp_max[3]; |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 103 | s8 temp_offset[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | s8 temp_min[3]; |
| 105 | s8 temp_max[3]; |
| 106 | s8 temp_crit[3]; |
| 107 | }; |
| 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | static inline u8 adm1031_read_value(struct i2c_client *client, u8 reg) |
| 110 | { |
| 111 | return i2c_smbus_read_byte_data(client, reg); |
| 112 | } |
| 113 | |
| 114 | static inline int |
| 115 | adm1031_write_value(struct i2c_client *client, u8 reg, unsigned int value) |
| 116 | { |
| 117 | return i2c_smbus_write_byte_data(client, reg, value); |
| 118 | } |
| 119 | |
Axel Lin | 278ee1c | 2014-07-03 21:56:33 +0800 | [diff] [blame] | 120 | static struct adm1031_data *adm1031_update_device(struct device *dev) |
| 121 | { |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 122 | struct adm1031_data *data = dev_get_drvdata(dev); |
| 123 | struct i2c_client *client = data->client; |
Axel Lin | 278ee1c | 2014-07-03 21:56:33 +0800 | [diff] [blame] | 124 | unsigned long next_update; |
| 125 | int chan; |
| 126 | |
| 127 | mutex_lock(&data->update_lock); |
| 128 | |
| 129 | next_update = data->last_updated |
| 130 | + msecs_to_jiffies(data->update_interval); |
| 131 | if (time_after(jiffies, next_update) || !data->valid) { |
| 132 | |
| 133 | dev_dbg(&client->dev, "Starting adm1031 update\n"); |
| 134 | for (chan = 0; |
| 135 | chan < ((data->chip_type == adm1031) ? 3 : 2); chan++) { |
| 136 | u8 oldh, newh; |
| 137 | |
| 138 | oldh = |
| 139 | adm1031_read_value(client, ADM1031_REG_TEMP(chan)); |
| 140 | data->ext_temp[chan] = |
| 141 | adm1031_read_value(client, ADM1031_REG_EXT_TEMP); |
| 142 | newh = |
| 143 | adm1031_read_value(client, ADM1031_REG_TEMP(chan)); |
| 144 | if (newh != oldh) { |
| 145 | data->ext_temp[chan] = |
| 146 | adm1031_read_value(client, |
| 147 | ADM1031_REG_EXT_TEMP); |
| 148 | #ifdef DEBUG |
| 149 | oldh = |
| 150 | adm1031_read_value(client, |
| 151 | ADM1031_REG_TEMP(chan)); |
| 152 | |
| 153 | /* oldh is actually newer */ |
| 154 | if (newh != oldh) |
| 155 | dev_warn(&client->dev, |
| 156 | "Remote temperature may be wrong.\n"); |
| 157 | #endif |
| 158 | } |
| 159 | data->temp[chan] = newh; |
| 160 | |
| 161 | data->temp_offset[chan] = |
| 162 | adm1031_read_value(client, |
| 163 | ADM1031_REG_TEMP_OFFSET(chan)); |
| 164 | data->temp_min[chan] = |
| 165 | adm1031_read_value(client, |
| 166 | ADM1031_REG_TEMP_MIN(chan)); |
| 167 | data->temp_max[chan] = |
| 168 | adm1031_read_value(client, |
| 169 | ADM1031_REG_TEMP_MAX(chan)); |
| 170 | data->temp_crit[chan] = |
| 171 | adm1031_read_value(client, |
| 172 | ADM1031_REG_TEMP_CRIT(chan)); |
| 173 | data->auto_temp[chan] = |
| 174 | adm1031_read_value(client, |
| 175 | ADM1031_REG_AUTO_TEMP(chan)); |
| 176 | |
| 177 | } |
| 178 | |
| 179 | data->conf1 = adm1031_read_value(client, ADM1031_REG_CONF1); |
| 180 | data->conf2 = adm1031_read_value(client, ADM1031_REG_CONF2); |
| 181 | |
| 182 | data->alarm = adm1031_read_value(client, ADM1031_REG_STATUS(0)) |
| 183 | | (adm1031_read_value(client, ADM1031_REG_STATUS(1)) << 8); |
| 184 | if (data->chip_type == adm1030) |
| 185 | data->alarm &= 0xc0ff; |
| 186 | |
| 187 | for (chan = 0; chan < (data->chip_type == adm1030 ? 1 : 2); |
| 188 | chan++) { |
| 189 | data->fan_div[chan] = |
| 190 | adm1031_read_value(client, |
| 191 | ADM1031_REG_FAN_DIV(chan)); |
| 192 | data->fan_min[chan] = |
| 193 | adm1031_read_value(client, |
| 194 | ADM1031_REG_FAN_MIN(chan)); |
| 195 | data->fan[chan] = |
| 196 | adm1031_read_value(client, |
| 197 | ADM1031_REG_FAN_SPEED(chan)); |
| 198 | data->pwm[chan] = |
| 199 | (adm1031_read_value(client, |
| 200 | ADM1031_REG_PWM) >> (4 * chan)) & 0x0f; |
| 201 | } |
| 202 | data->last_updated = jiffies; |
| 203 | data->valid = 1; |
| 204 | } |
| 205 | |
| 206 | mutex_unlock(&data->update_lock); |
| 207 | |
| 208 | return data; |
| 209 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
| 211 | #define TEMP_TO_REG(val) (((val) < 0 ? ((val - 500) / 1000) : \ |
| 212 | ((val + 500) / 1000))) |
| 213 | |
| 214 | #define TEMP_FROM_REG(val) ((val) * 1000) |
| 215 | |
| 216 | #define TEMP_FROM_REG_EXT(val, ext) (TEMP_FROM_REG(val) + (ext) * 125) |
| 217 | |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 218 | #define TEMP_OFFSET_TO_REG(val) (TEMP_TO_REG(val) & 0x8f) |
| 219 | #define TEMP_OFFSET_FROM_REG(val) TEMP_FROM_REG((val) < 0 ? \ |
| 220 | (val) | 0x70 : (val)) |
| 221 | |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 222 | #define FAN_FROM_REG(reg, div) ((reg) ? \ |
| 223 | (11250 * 60) / ((reg) * (div)) : 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | static int FAN_TO_REG(int reg, int div) |
| 226 | { |
| 227 | int tmp; |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 228 | tmp = FAN_FROM_REG(clamp_val(reg, 0, 65535), div); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | return tmp > 255 ? 255 : tmp; |
| 230 | } |
| 231 | |
| 232 | #define FAN_DIV_FROM_REG(reg) (1<<(((reg)&0xc0)>>6)) |
| 233 | |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 234 | #define PWM_TO_REG(val) (clamp_val((val), 0, 255) >> 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | #define PWM_FROM_REG(val) ((val) << 4) |
| 236 | |
| 237 | #define FAN_CHAN_FROM_REG(reg) (((reg) >> 5) & 7) |
| 238 | #define FAN_CHAN_TO_REG(val, reg) \ |
| 239 | (((reg) & 0x1F) | (((val) << 5) & 0xe0)) |
| 240 | |
| 241 | #define AUTO_TEMP_MIN_TO_REG(val, reg) \ |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 242 | ((((val) / 500) & 0xf8) | ((reg) & 0x7)) |
| 243 | #define AUTO_TEMP_RANGE_FROM_REG(reg) (5000 * (1 << ((reg) & 0x7))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | #define AUTO_TEMP_MIN_FROM_REG(reg) (1000 * ((((reg) >> 3) & 0x1f) << 2)) |
| 245 | |
| 246 | #define AUTO_TEMP_MIN_FROM_REG_DEG(reg) ((((reg) >> 3) & 0x1f) << 2) |
| 247 | |
| 248 | #define AUTO_TEMP_OFF_FROM_REG(reg) \ |
| 249 | (AUTO_TEMP_MIN_FROM_REG(reg) - 5000) |
| 250 | |
| 251 | #define AUTO_TEMP_MAX_FROM_REG(reg) \ |
| 252 | (AUTO_TEMP_RANGE_FROM_REG(reg) + \ |
| 253 | AUTO_TEMP_MIN_FROM_REG(reg)) |
| 254 | |
| 255 | static int AUTO_TEMP_MAX_TO_REG(int val, int reg, int pwm) |
| 256 | { |
| 257 | int ret; |
| 258 | int range = val - AUTO_TEMP_MIN_FROM_REG(reg); |
| 259 | |
| 260 | range = ((val - AUTO_TEMP_MIN_FROM_REG(reg))*10)/(16 - pwm); |
| 261 | ret = ((reg & 0xf8) | |
| 262 | (range < 10000 ? 0 : |
| 263 | range < 20000 ? 1 : |
| 264 | range < 40000 ? 2 : range < 80000 ? 3 : 4)); |
| 265 | return ret; |
| 266 | } |
| 267 | |
| 268 | /* FAN auto control */ |
| 269 | #define GET_FAN_AUTO_BITFIELD(data, idx) \ |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 270 | (*(data)->chan_select_table)[FAN_CHAN_FROM_REG((data)->conf1)][idx % 2] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Guenter Roeck | fbb6670 | 2012-01-19 11:02:14 -0800 | [diff] [blame] | 272 | /* |
| 273 | * The tables below contains the possible values for the auto fan |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | * control bitfields. the index in the table is the register value. |
| 275 | * MSb is the auto fan control enable bit, so the four first entries |
| 276 | * in the table disables auto fan control when both bitfields are zero. |
| 277 | */ |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 278 | static const auto_chan_table_t auto_channel_select_table_adm1031 = { |
| 279 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, |
| 280 | { 2 /* 0b010 */ , 4 /* 0b100 */ }, |
| 281 | { 2 /* 0b010 */ , 2 /* 0b010 */ }, |
| 282 | { 4 /* 0b100 */ , 4 /* 0b100 */ }, |
| 283 | { 7 /* 0b111 */ , 7 /* 0b111 */ }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | }; |
| 285 | |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 286 | static const auto_chan_table_t auto_channel_select_table_adm1030 = { |
| 287 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, |
| 288 | { 2 /* 0b10 */ , 0 }, |
| 289 | { 0xff /* invalid */ , 0 }, |
| 290 | { 0xff /* invalid */ , 0 }, |
| 291 | { 3 /* 0b11 */ , 0 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | }; |
| 293 | |
Guenter Roeck | fbb6670 | 2012-01-19 11:02:14 -0800 | [diff] [blame] | 294 | /* |
| 295 | * That function checks if a bitfield is valid and returns the other bitfield |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | * nearest match if no exact match where found. |
| 297 | */ |
| 298 | static int |
Guenter Roeck | ce15a81 | 2012-03-24 08:51:05 -0700 | [diff] [blame] | 299 | get_fan_auto_nearest(struct adm1031_data *data, int chan, u8 val, u8 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { |
| 301 | int i; |
| 302 | int first_match = -1, exact_match = -1; |
| 303 | u8 other_reg_val = |
| 304 | (*data->chan_select_table)[FAN_CHAN_FROM_REG(reg)][chan ? 0 : 1]; |
| 305 | |
Guenter Roeck | ce15a81 | 2012-03-24 08:51:05 -0700 | [diff] [blame] | 306 | if (val == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | for (i = 0; i < 8; i++) { |
| 310 | if ((val == (*data->chan_select_table)[i][chan]) && |
| 311 | ((*data->chan_select_table)[i][chan ? 0 : 1] == |
| 312 | other_reg_val)) { |
| 313 | /* We found an exact match */ |
| 314 | exact_match = i; |
| 315 | break; |
| 316 | } else if (val == (*data->chan_select_table)[i][chan] && |
| 317 | first_match == -1) { |
Guenter Roeck | fbb6670 | 2012-01-19 11:02:14 -0800 | [diff] [blame] | 318 | /* |
| 319 | * Save the first match in case of an exact match has |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 320 | * not been found |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | */ |
| 322 | first_match = i; |
| 323 | } |
| 324 | } |
| 325 | |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 326 | if (exact_match >= 0) |
Guenter Roeck | ce15a81 | 2012-03-24 08:51:05 -0700 | [diff] [blame] | 327 | return exact_match; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 328 | else if (first_match >= 0) |
Guenter Roeck | ce15a81 | 2012-03-24 08:51:05 -0700 | [diff] [blame] | 329 | return first_match; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 330 | |
Guenter Roeck | ce15a81 | 2012-03-24 08:51:05 -0700 | [diff] [blame] | 331 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 334 | static ssize_t show_fan_auto_channel(struct device *dev, |
| 335 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 337 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | struct adm1031_data *data = adm1031_update_device(dev); |
| 339 | return sprintf(buf, "%d\n", GET_FAN_AUTO_BITFIELD(data, nr)); |
| 340 | } |
| 341 | |
| 342 | static ssize_t |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 343 | set_fan_auto_channel(struct device *dev, struct device_attribute *attr, |
| 344 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | { |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 346 | struct adm1031_data *data = dev_get_drvdata(dev); |
| 347 | struct i2c_client *client = data->client; |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 348 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 349 | long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | u8 reg; |
| 351 | int ret; |
| 352 | u8 old_fan_mode; |
| 353 | |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 354 | ret = kstrtol(buf, 10, &val); |
| 355 | if (ret) |
| 356 | return ret; |
| 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | old_fan_mode = data->conf1; |
| 359 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 360 | mutex_lock(&data->update_lock); |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 361 | |
Guenter Roeck | ce15a81 | 2012-03-24 08:51:05 -0700 | [diff] [blame] | 362 | ret = get_fan_auto_nearest(data, nr, val, data->conf1); |
| 363 | if (ret < 0) { |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 364 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | return ret; |
| 366 | } |
Guenter Roeck | ce15a81 | 2012-03-24 08:51:05 -0700 | [diff] [blame] | 367 | reg = ret; |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 368 | data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1); |
| 369 | if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) ^ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) { |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 371 | if (data->conf1 & ADM1031_CONF1_AUTO_MODE) { |
Guenter Roeck | fbb6670 | 2012-01-19 11:02:14 -0800 | [diff] [blame] | 372 | /* |
| 373 | * Switch to Auto Fan Mode |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 374 | * Save PWM registers |
Guenter Roeck | fbb6670 | 2012-01-19 11:02:14 -0800 | [diff] [blame] | 375 | * Set PWM registers to 33% Both |
| 376 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | data->old_pwm[0] = data->pwm[0]; |
| 378 | data->old_pwm[1] = data->pwm[1]; |
| 379 | adm1031_write_value(client, ADM1031_REG_PWM, 0x55); |
| 380 | } else { |
| 381 | /* Switch to Manual Mode */ |
| 382 | data->pwm[0] = data->old_pwm[0]; |
| 383 | data->pwm[1] = data->old_pwm[1]; |
| 384 | /* Restore PWM registers */ |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 385 | adm1031_write_value(client, ADM1031_REG_PWM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | data->pwm[0] | (data->pwm[1] << 4)); |
| 387 | } |
| 388 | } |
| 389 | data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1); |
| 390 | adm1031_write_value(client, ADM1031_REG_CONF1, data->conf1); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 391 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | return count; |
| 393 | } |
| 394 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 395 | static SENSOR_DEVICE_ATTR(auto_fan1_channel, S_IRUGO | S_IWUSR, |
| 396 | show_fan_auto_channel, set_fan_auto_channel, 0); |
| 397 | static SENSOR_DEVICE_ATTR(auto_fan2_channel, S_IRUGO | S_IWUSR, |
| 398 | show_fan_auto_channel, set_fan_auto_channel, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
| 400 | /* Auto Temps */ |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 401 | static ssize_t show_auto_temp_off(struct device *dev, |
| 402 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 404 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | struct adm1031_data *data = adm1031_update_device(dev); |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 406 | return sprintf(buf, "%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | AUTO_TEMP_OFF_FROM_REG(data->auto_temp[nr])); |
| 408 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 409 | static ssize_t show_auto_temp_min(struct device *dev, |
| 410 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 412 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | struct adm1031_data *data = adm1031_update_device(dev); |
| 414 | return sprintf(buf, "%d\n", |
| 415 | AUTO_TEMP_MIN_FROM_REG(data->auto_temp[nr])); |
| 416 | } |
| 417 | static ssize_t |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 418 | set_auto_temp_min(struct device *dev, struct device_attribute *attr, |
| 419 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | { |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 421 | struct adm1031_data *data = dev_get_drvdata(dev); |
| 422 | struct i2c_client *client = data->client; |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 423 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 424 | long val; |
| 425 | int ret; |
| 426 | |
| 427 | ret = kstrtol(buf, 10, &val); |
| 428 | if (ret) |
| 429 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
Guenter Roeck | 145e74a4 | 2014-07-03 13:44:23 -0700 | [diff] [blame] | 431 | val = clamp_val(val, 0, 127000); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 432 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | data->auto_temp[nr] = AUTO_TEMP_MIN_TO_REG(val, data->auto_temp[nr]); |
| 434 | adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr), |
| 435 | data->auto_temp[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 436 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | return count; |
| 438 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 439 | static ssize_t show_auto_temp_max(struct device *dev, |
| 440 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 442 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | struct adm1031_data *data = adm1031_update_device(dev); |
| 444 | return sprintf(buf, "%d\n", |
| 445 | AUTO_TEMP_MAX_FROM_REG(data->auto_temp[nr])); |
| 446 | } |
| 447 | static ssize_t |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 448 | set_auto_temp_max(struct device *dev, struct device_attribute *attr, |
| 449 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | { |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 451 | struct adm1031_data *data = dev_get_drvdata(dev); |
| 452 | struct i2c_client *client = data->client; |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 453 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 454 | long val; |
| 455 | int ret; |
| 456 | |
| 457 | ret = kstrtol(buf, 10, &val); |
| 458 | if (ret) |
| 459 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
Guenter Roeck | 145e74a4 | 2014-07-03 13:44:23 -0700 | [diff] [blame] | 461 | val = clamp_val(val, 0, 127000); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 462 | mutex_lock(&data->update_lock); |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 463 | data->temp_max[nr] = AUTO_TEMP_MAX_TO_REG(val, data->auto_temp[nr], |
| 464 | data->pwm[nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr), |
| 466 | data->temp_max[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 467 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | return count; |
| 469 | } |
| 470 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 471 | #define auto_temp_reg(offset) \ |
| 472 | static SENSOR_DEVICE_ATTR(auto_temp##offset##_off, S_IRUGO, \ |
| 473 | show_auto_temp_off, NULL, offset - 1); \ |
| 474 | static SENSOR_DEVICE_ATTR(auto_temp##offset##_min, S_IRUGO | S_IWUSR, \ |
| 475 | show_auto_temp_min, set_auto_temp_min, offset - 1); \ |
| 476 | static SENSOR_DEVICE_ATTR(auto_temp##offset##_max, S_IRUGO | S_IWUSR, \ |
| 477 | show_auto_temp_max, set_auto_temp_max, offset - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
| 479 | auto_temp_reg(1); |
| 480 | auto_temp_reg(2); |
| 481 | auto_temp_reg(3); |
| 482 | |
| 483 | /* pwm */ |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 484 | static ssize_t show_pwm(struct device *dev, |
| 485 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 487 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | struct adm1031_data *data = adm1031_update_device(dev); |
| 489 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr])); |
| 490 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 491 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
| 492 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | { |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 494 | struct adm1031_data *data = dev_get_drvdata(dev); |
| 495 | struct i2c_client *client = data->client; |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 496 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 497 | long val; |
| 498 | int ret, reg; |
| 499 | |
| 500 | ret = kstrtol(buf, 10, &val); |
| 501 | if (ret) |
| 502 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 504 | mutex_lock(&data->update_lock); |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 505 | if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | (((val>>4) & 0xf) != 5)) { |
| 507 | /* In automatic mode, the only PWM accepted is 33% */ |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 508 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | return -EINVAL; |
| 510 | } |
| 511 | data->pwm[nr] = PWM_TO_REG(val); |
| 512 | reg = adm1031_read_value(client, ADM1031_REG_PWM); |
| 513 | adm1031_write_value(client, ADM1031_REG_PWM, |
| 514 | nr ? ((data->pwm[nr] << 4) & 0xf0) | (reg & 0xf) |
| 515 | : (data->pwm[nr] & 0xf) | (reg & 0xf0)); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 516 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | return count; |
| 518 | } |
| 519 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 520 | static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0); |
| 521 | static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1); |
| 522 | static SENSOR_DEVICE_ATTR(auto_fan1_min_pwm, S_IRUGO | S_IWUSR, |
| 523 | show_pwm, set_pwm, 0); |
| 524 | static SENSOR_DEVICE_ATTR(auto_fan2_min_pwm, S_IRUGO | S_IWUSR, |
| 525 | show_pwm, set_pwm, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
| 527 | /* Fans */ |
| 528 | |
| 529 | /* |
| 530 | * That function checks the cases where the fan reading is not |
Steven Cole | 44bbe87 | 2005-05-03 18:21:25 -0600 | [diff] [blame] | 531 | * relevant. It is used to provide 0 as fan reading when the fan is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | * not supposed to run |
| 533 | */ |
| 534 | static int trust_fan_readings(struct adm1031_data *data, int chan) |
| 535 | { |
| 536 | int res = 0; |
| 537 | |
| 538 | if (data->conf1 & ADM1031_CONF1_AUTO_MODE) { |
| 539 | switch (data->conf1 & 0x60) { |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 540 | case 0x00: |
| 541 | /* |
| 542 | * remote temp1 controls fan1, |
| 543 | * remote temp2 controls fan2 |
| 544 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | res = data->temp[chan+1] >= |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 546 | AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[chan+1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | break; |
| 548 | case 0x20: /* remote temp1 controls both fans */ |
| 549 | res = |
| 550 | data->temp[1] >= |
| 551 | AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[1]); |
| 552 | break; |
| 553 | case 0x40: /* remote temp2 controls both fans */ |
| 554 | res = |
| 555 | data->temp[2] >= |
| 556 | AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[2]); |
| 557 | break; |
| 558 | case 0x60: /* max controls both fans */ |
| 559 | res = |
| 560 | data->temp[0] >= |
| 561 | AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[0]) |
| 562 | || data->temp[1] >= |
| 563 | AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[1]) |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 564 | || (data->chip_type == adm1031 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | && data->temp[2] >= |
| 566 | AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[2])); |
| 567 | break; |
| 568 | } |
| 569 | } else { |
| 570 | res = data->pwm[chan] > 0; |
| 571 | } |
| 572 | return res; |
| 573 | } |
| 574 | |
| 575 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 576 | static ssize_t show_fan(struct device *dev, |
| 577 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 579 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | struct adm1031_data *data = adm1031_update_device(dev); |
| 581 | int value; |
| 582 | |
| 583 | value = trust_fan_readings(data, nr) ? FAN_FROM_REG(data->fan[nr], |
| 584 | FAN_DIV_FROM_REG(data->fan_div[nr])) : 0; |
| 585 | return sprintf(buf, "%d\n", value); |
| 586 | } |
| 587 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 588 | static ssize_t show_fan_div(struct device *dev, |
| 589 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 591 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | struct adm1031_data *data = adm1031_update_device(dev); |
| 593 | return sprintf(buf, "%d\n", FAN_DIV_FROM_REG(data->fan_div[nr])); |
| 594 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 595 | static ssize_t show_fan_min(struct device *dev, |
| 596 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 598 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | struct adm1031_data *data = adm1031_update_device(dev); |
| 600 | return sprintf(buf, "%d\n", |
| 601 | FAN_FROM_REG(data->fan_min[nr], |
| 602 | FAN_DIV_FROM_REG(data->fan_div[nr]))); |
| 603 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 604 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
| 605 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | { |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 607 | struct adm1031_data *data = dev_get_drvdata(dev); |
| 608 | struct i2c_client *client = data->client; |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 609 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 610 | long val; |
| 611 | int ret; |
| 612 | |
| 613 | ret = kstrtol(buf, 10, &val); |
| 614 | if (ret) |
| 615 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 617 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | if (val) { |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 619 | data->fan_min[nr] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | FAN_TO_REG(val, FAN_DIV_FROM_REG(data->fan_div[nr])); |
| 621 | } else { |
| 622 | data->fan_min[nr] = 0xff; |
| 623 | } |
| 624 | adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), data->fan_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 625 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | return count; |
| 627 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 628 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
| 629 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 631 | struct adm1031_data *data = dev_get_drvdata(dev); |
| 632 | struct i2c_client *client = data->client; |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 633 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 634 | long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | u8 tmp; |
| 636 | int old_div; |
| 637 | int new_min; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 638 | int ret; |
| 639 | |
| 640 | ret = kstrtol(buf, 10, &val); |
| 641 | if (ret) |
| 642 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
| 644 | tmp = val == 8 ? 0xc0 : |
| 645 | val == 4 ? 0x80 : |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 646 | val == 2 ? 0x40 : |
| 647 | val == 1 ? 0x00 : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | 0xff; |
| 649 | if (tmp == 0xff) |
| 650 | return -EINVAL; |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 651 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 652 | mutex_lock(&data->update_lock); |
Jean Delvare | 38a1f0e | 2007-12-02 23:32:42 +0100 | [diff] [blame] | 653 | /* Get fresh readings */ |
| 654 | data->fan_div[nr] = adm1031_read_value(client, |
| 655 | ADM1031_REG_FAN_DIV(nr)); |
| 656 | data->fan_min[nr] = adm1031_read_value(client, |
| 657 | ADM1031_REG_FAN_MIN(nr)); |
| 658 | |
| 659 | /* Write the new clock divider and fan min */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | old_div = FAN_DIV_FROM_REG(data->fan_div[nr]); |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 661 | data->fan_div[nr] = tmp | (0x3f & data->fan_div[nr]); |
| 662 | new_min = data->fan_min[nr] * old_div / val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | data->fan_min[nr] = new_min > 0xff ? 0xff : new_min; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 665 | adm1031_write_value(client, ADM1031_REG_FAN_DIV(nr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | data->fan_div[nr]); |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 667 | adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | data->fan_min[nr]); |
Jean Delvare | 38a1f0e | 2007-12-02 23:32:42 +0100 | [diff] [blame] | 669 | |
| 670 | /* Invalidate the cache: fan speed is no longer valid */ |
| 671 | data->valid = 0; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 672 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | return count; |
| 674 | } |
| 675 | |
| 676 | #define fan_offset(offset) \ |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 677 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
| 678 | show_fan, NULL, offset - 1); \ |
| 679 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
| 680 | show_fan_min, set_fan_min, offset - 1); \ |
| 681 | static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ |
| 682 | show_fan_div, set_fan_div, offset - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | |
| 684 | fan_offset(1); |
| 685 | fan_offset(2); |
| 686 | |
| 687 | |
| 688 | /* Temps */ |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 689 | static ssize_t show_temp(struct device *dev, |
| 690 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 692 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | struct adm1031_data *data = adm1031_update_device(dev); |
| 694 | int ext; |
| 695 | ext = nr == 0 ? |
| 696 | ((data->ext_temp[nr] >> 6) & 0x3) * 2 : |
| 697 | (((data->ext_temp[nr] >> ((nr - 1) * 3)) & 7)); |
| 698 | return sprintf(buf, "%d\n", TEMP_FROM_REG_EXT(data->temp[nr], ext)); |
| 699 | } |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 700 | static ssize_t show_temp_offset(struct device *dev, |
| 701 | struct device_attribute *attr, char *buf) |
| 702 | { |
| 703 | int nr = to_sensor_dev_attr(attr)->index; |
| 704 | struct adm1031_data *data = adm1031_update_device(dev); |
| 705 | return sprintf(buf, "%d\n", |
| 706 | TEMP_OFFSET_FROM_REG(data->temp_offset[nr])); |
| 707 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 708 | static ssize_t show_temp_min(struct device *dev, |
| 709 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 711 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | struct adm1031_data *data = adm1031_update_device(dev); |
| 713 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr])); |
| 714 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 715 | static ssize_t show_temp_max(struct device *dev, |
| 716 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 718 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | struct adm1031_data *data = adm1031_update_device(dev); |
| 720 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr])); |
| 721 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 722 | static ssize_t show_temp_crit(struct device *dev, |
| 723 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 725 | int nr = to_sensor_dev_attr(attr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | struct adm1031_data *data = adm1031_update_device(dev); |
| 727 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[nr])); |
| 728 | } |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 729 | static ssize_t set_temp_offset(struct device *dev, |
| 730 | struct device_attribute *attr, const char *buf, |
| 731 | size_t count) |
| 732 | { |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 733 | struct adm1031_data *data = dev_get_drvdata(dev); |
| 734 | struct i2c_client *client = data->client; |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 735 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 736 | long val; |
| 737 | int ret; |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 738 | |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 739 | ret = kstrtol(buf, 10, &val); |
| 740 | if (ret) |
| 741 | return ret; |
| 742 | |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 743 | val = clamp_val(val, -15000, 15000); |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 744 | mutex_lock(&data->update_lock); |
| 745 | data->temp_offset[nr] = TEMP_OFFSET_TO_REG(val); |
| 746 | adm1031_write_value(client, ADM1031_REG_TEMP_OFFSET(nr), |
| 747 | data->temp_offset[nr]); |
| 748 | mutex_unlock(&data->update_lock); |
| 749 | return count; |
| 750 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 751 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, |
| 752 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | { |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 754 | struct adm1031_data *data = dev_get_drvdata(dev); |
| 755 | struct i2c_client *client = data->client; |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 756 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 757 | long val; |
| 758 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 760 | ret = kstrtol(buf, 10, &val); |
| 761 | if (ret) |
| 762 | return ret; |
| 763 | |
Guenter Roeck | 145e74a4 | 2014-07-03 13:44:23 -0700 | [diff] [blame] | 764 | val = clamp_val(val, -55000, 127000); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 765 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | data->temp_min[nr] = TEMP_TO_REG(val); |
| 767 | adm1031_write_value(client, ADM1031_REG_TEMP_MIN(nr), |
| 768 | data->temp_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 769 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | return count; |
| 771 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 772 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
| 773 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | { |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 775 | struct adm1031_data *data = dev_get_drvdata(dev); |
| 776 | struct i2c_client *client = data->client; |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 777 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 778 | long val; |
| 779 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 781 | ret = kstrtol(buf, 10, &val); |
| 782 | if (ret) |
| 783 | return ret; |
| 784 | |
Guenter Roeck | 145e74a4 | 2014-07-03 13:44:23 -0700 | [diff] [blame] | 785 | val = clamp_val(val, -55000, 127000); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 786 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | data->temp_max[nr] = TEMP_TO_REG(val); |
| 788 | adm1031_write_value(client, ADM1031_REG_TEMP_MAX(nr), |
| 789 | data->temp_max[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 790 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | return count; |
| 792 | } |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 793 | static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, |
| 794 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | { |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 796 | struct adm1031_data *data = dev_get_drvdata(dev); |
| 797 | struct i2c_client *client = data->client; |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 798 | int nr = to_sensor_dev_attr(attr)->index; |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 799 | long val; |
| 800 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 802 | ret = kstrtol(buf, 10, &val); |
| 803 | if (ret) |
| 804 | return ret; |
| 805 | |
Guenter Roeck | 145e74a4 | 2014-07-03 13:44:23 -0700 | [diff] [blame] | 806 | val = clamp_val(val, -55000, 127000); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 807 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | data->temp_crit[nr] = TEMP_TO_REG(val); |
| 809 | adm1031_write_value(client, ADM1031_REG_TEMP_CRIT(nr), |
| 810 | data->temp_crit[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 811 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | return count; |
| 813 | } |
| 814 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 815 | #define temp_reg(offset) \ |
| 816 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
| 817 | show_temp, NULL, offset - 1); \ |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 818 | static SENSOR_DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \ |
| 819 | show_temp_offset, set_temp_offset, offset - 1); \ |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 820 | static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ |
| 821 | show_temp_min, set_temp_min, offset - 1); \ |
| 822 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ |
| 823 | show_temp_max, set_temp_max, offset - 1); \ |
| 824 | static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \ |
| 825 | show_temp_crit, set_temp_crit, offset - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
| 827 | temp_reg(1); |
| 828 | temp_reg(2); |
| 829 | temp_reg(3); |
| 830 | |
| 831 | /* Alarms */ |
Julia Lawall | bfb6b17 | 2016-12-22 13:04:32 +0100 | [diff] [blame] | 832 | static ssize_t alarms_show(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | 1c72009 | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 833 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | { |
| 835 | struct adm1031_data *data = adm1031_update_device(dev); |
| 836 | return sprintf(buf, "%d\n", data->alarm); |
| 837 | } |
| 838 | |
Julia Lawall | bfb6b17 | 2016-12-22 13:04:32 +0100 | [diff] [blame] | 839 | static DEVICE_ATTR_RO(alarms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 841 | static ssize_t show_alarm(struct device *dev, |
| 842 | struct device_attribute *attr, char *buf) |
| 843 | { |
| 844 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 845 | struct adm1031_data *data = adm1031_update_device(dev); |
| 846 | return sprintf(buf, "%d\n", (data->alarm >> bitnr) & 1); |
| 847 | } |
| 848 | |
| 849 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0); |
| 850 | static SENSOR_DEVICE_ATTR(fan1_fault, S_IRUGO, show_alarm, NULL, 1); |
| 851 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 2); |
| 852 | static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); |
| 853 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 4); |
| 854 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 5); |
| 855 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); |
| 856 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 7); |
| 857 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 8); |
| 858 | static SENSOR_DEVICE_ATTR(fan2_fault, S_IRUGO, show_alarm, NULL, 9); |
| 859 | static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 10); |
| 860 | static SENSOR_DEVICE_ATTR(temp3_min_alarm, S_IRUGO, show_alarm, NULL, 11); |
| 861 | static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 12); |
| 862 | static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13); |
| 863 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 865 | /* Update Interval */ |
| 866 | static const unsigned int update_intervals[] = { |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 867 | 16000, 8000, 4000, 2000, 1000, 500, 250, 125, |
| 868 | }; |
| 869 | |
Julia Lawall | bfb6b17 | 2016-12-22 13:04:32 +0100 | [diff] [blame] | 870 | static ssize_t update_interval_show(struct device *dev, |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 871 | struct device_attribute *attr, char *buf) |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 872 | { |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 873 | struct adm1031_data *data = dev_get_drvdata(dev); |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 874 | |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 875 | return sprintf(buf, "%u\n", data->update_interval); |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 876 | } |
| 877 | |
Julia Lawall | bfb6b17 | 2016-12-22 13:04:32 +0100 | [diff] [blame] | 878 | static ssize_t update_interval_store(struct device *dev, |
| 879 | struct device_attribute *attr, |
| 880 | const char *buf, size_t count) |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 881 | { |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 882 | struct adm1031_data *data = dev_get_drvdata(dev); |
| 883 | struct i2c_client *client = data->client; |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 884 | unsigned long val; |
| 885 | int i, err; |
| 886 | u8 reg; |
| 887 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 888 | err = kstrtoul(buf, 10, &val); |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 889 | if (err) |
| 890 | return err; |
| 891 | |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 892 | /* |
| 893 | * Find the nearest update interval from the table. |
| 894 | * Use it to determine the matching update rate. |
| 895 | */ |
| 896 | for (i = 0; i < ARRAY_SIZE(update_intervals) - 1; i++) { |
| 897 | if (val >= update_intervals[i]) |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 898 | break; |
| 899 | } |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 900 | /* if not found, we point to the last entry (lowest update interval) */ |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 901 | |
| 902 | /* set the new update rate while preserving other settings */ |
| 903 | reg = adm1031_read_value(client, ADM1031_REG_FAN_FILTER); |
| 904 | reg &= ~ADM1031_UPDATE_RATE_MASK; |
| 905 | reg |= i << ADM1031_UPDATE_RATE_SHIFT; |
| 906 | adm1031_write_value(client, ADM1031_REG_FAN_FILTER, reg); |
| 907 | |
| 908 | mutex_lock(&data->update_lock); |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 909 | data->update_interval = update_intervals[i]; |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 910 | mutex_unlock(&data->update_lock); |
| 911 | |
| 912 | return count; |
| 913 | } |
| 914 | |
Julia Lawall | bfb6b17 | 2016-12-22 13:04:32 +0100 | [diff] [blame] | 915 | static DEVICE_ATTR_RW(update_interval); |
Jean Delvare | 87c33da | 2010-05-27 19:58:46 +0200 | [diff] [blame] | 916 | |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 917 | static struct attribute *adm1031_attributes[] = { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 918 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 919 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
| 920 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 921 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
| 922 | &sensor_dev_attr_fan1_fault.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 923 | &sensor_dev_attr_pwm1.dev_attr.attr, |
| 924 | &sensor_dev_attr_auto_fan1_channel.dev_attr.attr, |
| 925 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 926 | &sensor_dev_attr_temp1_offset.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 927 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 928 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 929 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 930 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 931 | &sensor_dev_attr_temp1_crit.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 932 | &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 933 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 934 | &sensor_dev_attr_temp2_offset.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 935 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 936 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 937 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 938 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 939 | &sensor_dev_attr_temp2_crit.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 940 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, |
| 941 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 942 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 943 | &sensor_dev_attr_auto_temp1_off.dev_attr.attr, |
| 944 | &sensor_dev_attr_auto_temp1_min.dev_attr.attr, |
| 945 | &sensor_dev_attr_auto_temp1_max.dev_attr.attr, |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 946 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 947 | &sensor_dev_attr_auto_temp2_off.dev_attr.attr, |
| 948 | &sensor_dev_attr_auto_temp2_min.dev_attr.attr, |
| 949 | &sensor_dev_attr_auto_temp2_max.dev_attr.attr, |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 950 | |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 951 | &sensor_dev_attr_auto_fan1_min_pwm.dev_attr.attr, |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 952 | |
Guenter Roeck | a51b994 | 2010-09-17 17:24:14 +0200 | [diff] [blame] | 953 | &dev_attr_update_interval.attr, |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 954 | &dev_attr_alarms.attr, |
| 955 | |
| 956 | NULL |
| 957 | }; |
| 958 | |
| 959 | static const struct attribute_group adm1031_group = { |
| 960 | .attrs = adm1031_attributes, |
| 961 | }; |
| 962 | |
| 963 | static struct attribute *adm1031_attributes_opt[] = { |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 964 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
| 965 | &sensor_dev_attr_fan2_div.dev_attr.attr, |
| 966 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 967 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
| 968 | &sensor_dev_attr_fan2_fault.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 969 | &sensor_dev_attr_pwm2.dev_attr.attr, |
| 970 | &sensor_dev_attr_auto_fan2_channel.dev_attr.attr, |
| 971 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
Ira Snyder | 49dc9ef | 2009-09-23 22:59:41 +0200 | [diff] [blame] | 972 | &sensor_dev_attr_temp3_offset.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 973 | &sensor_dev_attr_temp3_min.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 974 | &sensor_dev_attr_temp3_min_alarm.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 975 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 976 | &sensor_dev_attr_temp3_max_alarm.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 977 | &sensor_dev_attr_temp3_crit.dev_attr.attr, |
Jean Delvare | 050ab87 | 2007-12-02 23:42:24 +0100 | [diff] [blame] | 978 | &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr, |
| 979 | &sensor_dev_attr_temp3_fault.dev_attr.attr, |
Jean Delvare | c801082 | 2007-12-02 23:39:38 +0100 | [diff] [blame] | 980 | &sensor_dev_attr_auto_temp3_off.dev_attr.attr, |
| 981 | &sensor_dev_attr_auto_temp3_min.dev_attr.attr, |
| 982 | &sensor_dev_attr_auto_temp3_max.dev_attr.attr, |
| 983 | &sensor_dev_attr_auto_fan2_min_pwm.dev_attr.attr, |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 984 | NULL |
| 985 | }; |
| 986 | |
| 987 | static const struct attribute_group adm1031_group_opt = { |
| 988 | .attrs = adm1031_attributes_opt, |
| 989 | }; |
| 990 | |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 991 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 992 | static int adm1031_detect(struct i2c_client *client, |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 993 | struct i2c_board_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | { |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 995 | struct i2c_adapter *adapter = client->adapter; |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 996 | const char *name; |
| 997 | int id, co; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | |
| 999 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 1000 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 1002 | id = i2c_smbus_read_byte_data(client, 0x3d); |
| 1003 | co = i2c_smbus_read_byte_data(client, 0x3e); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 1005 | if (!((id == 0x31 || id == 0x30) && co == 0x41)) |
| 1006 | return -ENODEV; |
| 1007 | name = (id == 0x30) ? "adm1030" : "adm1031"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 1009 | strlcpy(info->type, name, I2C_NAME_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 1011 | return 0; |
| 1012 | } |
| 1013 | |
Axel Lin | 278ee1c | 2014-07-03 21:56:33 +0800 | [diff] [blame] | 1014 | static void adm1031_init_client(struct i2c_client *client) |
| 1015 | { |
| 1016 | unsigned int read_val; |
| 1017 | unsigned int mask; |
| 1018 | int i; |
| 1019 | struct adm1031_data *data = i2c_get_clientdata(client); |
| 1020 | |
| 1021 | mask = (ADM1031_CONF2_PWM1_ENABLE | ADM1031_CONF2_TACH1_ENABLE); |
| 1022 | if (data->chip_type == adm1031) { |
| 1023 | mask |= (ADM1031_CONF2_PWM2_ENABLE | |
| 1024 | ADM1031_CONF2_TACH2_ENABLE); |
| 1025 | } |
| 1026 | /* Initialize the ADM1031 chip (enables fan speed reading ) */ |
| 1027 | read_val = adm1031_read_value(client, ADM1031_REG_CONF2); |
| 1028 | if ((read_val | mask) != read_val) |
| 1029 | adm1031_write_value(client, ADM1031_REG_CONF2, read_val | mask); |
| 1030 | |
| 1031 | read_val = adm1031_read_value(client, ADM1031_REG_CONF1); |
| 1032 | if ((read_val | ADM1031_CONF1_MONITOR_ENABLE) != read_val) { |
| 1033 | adm1031_write_value(client, ADM1031_REG_CONF1, |
| 1034 | read_val | ADM1031_CONF1_MONITOR_ENABLE); |
| 1035 | } |
| 1036 | |
| 1037 | /* Read the chip's update rate */ |
| 1038 | mask = ADM1031_UPDATE_RATE_MASK; |
| 1039 | read_val = adm1031_read_value(client, ADM1031_REG_FAN_FILTER); |
| 1040 | i = (read_val & mask) >> ADM1031_UPDATE_RATE_SHIFT; |
| 1041 | /* Save it as update interval */ |
| 1042 | data->update_interval = update_intervals[i]; |
| 1043 | } |
| 1044 | |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 1045 | static int adm1031_probe(struct i2c_client *client, |
| 1046 | const struct i2c_device_id *id) |
| 1047 | { |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 1048 | struct device *dev = &client->dev; |
| 1049 | struct device *hwmon_dev; |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 1050 | struct adm1031_data *data; |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 1051 | |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 1052 | data = devm_kzalloc(dev, sizeof(struct adm1031_data), GFP_KERNEL); |
Guenter Roeck | dc2fd66 | 2012-06-02 09:57:59 -0700 | [diff] [blame] | 1053 | if (!data) |
| 1054 | return -ENOMEM; |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 1055 | |
| 1056 | i2c_set_clientdata(client, data); |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 1057 | data->client = client; |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 1058 | data->chip_type = id->driver_data; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1059 | mutex_init(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | |
Jean Delvare | af200f8 | 2008-07-16 19:30:09 +0200 | [diff] [blame] | 1061 | if (data->chip_type == adm1030) |
| 1062 | data->chan_select_table = &auto_channel_select_table_adm1030; |
| 1063 | else |
| 1064 | data->chan_select_table = &auto_channel_select_table_adm1031; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | |
| 1066 | /* Initialize the ADM1031 chip */ |
Jean Delvare | 6d6006b | 2007-12-02 23:33:57 +0100 | [diff] [blame] | 1067 | adm1031_init_client(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 1069 | /* sysfs hooks */ |
| 1070 | data->groups[0] = &adm1031_group; |
| 1071 | if (data->chip_type == adm1031) |
| 1072 | data->groups[1] = &adm1031_group_opt; |
Mark M. Hoffman | 681c6f7 | 2006-09-24 21:15:35 +0200 | [diff] [blame] | 1073 | |
Axel Lin | b060f3c | 2014-07-03 21:57:44 +0800 | [diff] [blame] | 1074 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
| 1075 | data, data->groups); |
| 1076 | return PTR_ERR_OR_ZERO(hwmon_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
Axel Lin | 278ee1c | 2014-07-03 21:56:33 +0800 | [diff] [blame] | 1079 | static const struct i2c_device_id adm1031_id[] = { |
| 1080 | { "adm1030", adm1030 }, |
| 1081 | { "adm1031", adm1031 }, |
| 1082 | { } |
| 1083 | }; |
| 1084 | MODULE_DEVICE_TABLE(i2c, adm1031_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | |
Axel Lin | 278ee1c | 2014-07-03 21:56:33 +0800 | [diff] [blame] | 1086 | static struct i2c_driver adm1031_driver = { |
| 1087 | .class = I2C_CLASS_HWMON, |
| 1088 | .driver = { |
| 1089 | .name = "adm1031", |
| 1090 | }, |
| 1091 | .probe = adm1031_probe, |
Axel Lin | 278ee1c | 2014-07-03 21:56:33 +0800 | [diff] [blame] | 1092 | .id_table = adm1031_id, |
| 1093 | .detect = adm1031_detect, |
| 1094 | .address_list = normal_i2c, |
| 1095 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
Axel Lin | f0967ee | 2012-01-20 15:38:18 +0800 | [diff] [blame] | 1097 | module_i2c_driver(adm1031_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | |
| 1099 | MODULE_AUTHOR("Alexandre d'Alton <alex@alexdalton.org>"); |
| 1100 | MODULE_DESCRIPTION("ADM1031/ADM1030 driver"); |
| 1101 | MODULE_LICENSE("GPL"); |