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