Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 1 | /* |
| 2 | * A hwmon driver for the Analog Devices ADT7473 |
| 3 | * Copyright (C) 2007 IBM |
| 4 | * |
| 5 | * Author: Darrick J. Wong <djwong@us.ibm.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/jiffies.h> |
| 24 | #include <linux/i2c.h> |
| 25 | #include <linux/hwmon.h> |
| 26 | #include <linux/hwmon-sysfs.h> |
| 27 | #include <linux/err.h> |
| 28 | #include <linux/mutex.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/log2.h> |
| 31 | |
| 32 | /* Addresses to scan */ |
Mark M. Hoffman | 25e9c86 | 2008-02-17 22:28:03 -0500 | [diff] [blame] | 33 | static const unsigned short normal_i2c[] = { 0x2C, 0x2D, 0x2E, I2C_CLIENT_END }; |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 34 | |
| 35 | /* Insmod parameters */ |
| 36 | I2C_CLIENT_INSMOD_1(adt7473); |
| 37 | |
| 38 | /* ADT7473 registers */ |
| 39 | #define ADT7473_REG_BASE_ADDR 0x20 |
| 40 | |
| 41 | #define ADT7473_REG_VOLT_BASE_ADDR 0x21 |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 42 | #define ADT7473_REG_VOLT_MIN_BASE_ADDR 0x46 |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 43 | |
| 44 | #define ADT7473_REG_TEMP_BASE_ADDR 0x25 |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 45 | #define ADT7473_REG_TEMP_LIMITS_BASE_ADDR 0x4E |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 46 | #define ADT7473_REG_TEMP_TMIN_BASE_ADDR 0x67 |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 47 | #define ADT7473_REG_TEMP_TMAX_BASE_ADDR 0x6A |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 48 | |
| 49 | #define ADT7473_REG_FAN_BASE_ADDR 0x28 |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 50 | #define ADT7473_REG_FAN_MIN_BASE_ADDR 0x54 |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 51 | |
| 52 | #define ADT7473_REG_PWM_BASE_ADDR 0x30 |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 53 | #define ADT7473_REG_PWM_MIN_BASE_ADDR 0x64 |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 54 | #define ADT7473_REG_PWM_MAX_BASE_ADDR 0x38 |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 55 | #define ADT7473_REG_PWM_BHVR_BASE_ADDR 0x5C |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 56 | #define ADT7473_PWM_BHVR_MASK 0xE0 |
| 57 | #define ADT7473_PWM_BHVR_SHIFT 5 |
| 58 | |
| 59 | #define ADT7473_REG_CFG1 0x40 |
| 60 | #define ADT7473_CFG1_START 0x01 |
| 61 | #define ADT7473_CFG1_READY 0x04 |
| 62 | #define ADT7473_REG_CFG2 0x73 |
| 63 | #define ADT7473_REG_CFG3 0x78 |
| 64 | #define ADT7473_REG_CFG4 0x7D |
| 65 | #define ADT7473_CFG4_MAX_DUTY_AT_OVT 0x08 |
| 66 | #define ADT7473_REG_CFG5 0x7C |
| 67 | #define ADT7473_CFG5_TEMP_TWOS 0x01 |
| 68 | #define ADT7473_CFG5_TEMP_OFFSET 0x02 |
| 69 | |
| 70 | #define ADT7473_REG_DEVICE 0x3D |
| 71 | #define ADT7473_VENDOR 0x41 |
| 72 | #define ADT7473_REG_VENDOR 0x3E |
| 73 | #define ADT7473_DEVICE 0x73 |
| 74 | #define ADT7473_REG_REVISION 0x3F |
| 75 | #define ADT7473_REV_68 0x68 |
| 76 | #define ADT7473_REV_69 0x69 |
| 77 | |
| 78 | #define ADT7473_REG_ALARM1 0x41 |
| 79 | #define ADT7473_VCCP_ALARM 0x02 |
| 80 | #define ADT7473_VCC_ALARM 0x04 |
| 81 | #define ADT7473_R1T_ALARM 0x10 |
| 82 | #define ADT7473_LT_ALARM 0x20 |
| 83 | #define ADT7473_R2T_ALARM 0x40 |
| 84 | #define ADT7473_OOL 0x80 |
| 85 | #define ADT7473_REG_ALARM2 0x42 |
| 86 | #define ADT7473_OVT_ALARM 0x02 |
| 87 | #define ADT7473_FAN1_ALARM 0x04 |
| 88 | #define ADT7473_FAN2_ALARM 0x08 |
| 89 | #define ADT7473_FAN3_ALARM 0x10 |
| 90 | #define ADT7473_FAN4_ALARM 0x20 |
| 91 | #define ADT7473_R1T_SHORT 0x40 |
| 92 | #define ADT7473_R2T_SHORT 0x80 |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 93 | |
| 94 | #define ALARM2(x) ((x) << 8) |
| 95 | |
| 96 | #define ADT7473_VOLT_COUNT 2 |
| 97 | #define ADT7473_REG_VOLT(x) (ADT7473_REG_VOLT_BASE_ADDR + (x)) |
| 98 | #define ADT7473_REG_VOLT_MIN(x) (ADT7473_REG_VOLT_MIN_BASE_ADDR + ((x) * 2)) |
| 99 | #define ADT7473_REG_VOLT_MAX(x) (ADT7473_REG_VOLT_MIN_BASE_ADDR + \ |
| 100 | ((x) * 2) + 1) |
| 101 | |
| 102 | #define ADT7473_TEMP_COUNT 3 |
| 103 | #define ADT7473_REG_TEMP(x) (ADT7473_REG_TEMP_BASE_ADDR + (x)) |
| 104 | #define ADT7473_REG_TEMP_MIN(x) (ADT7473_REG_TEMP_LIMITS_BASE_ADDR + ((x) * 2)) |
| 105 | #define ADT7473_REG_TEMP_MAX(x) (ADT7473_REG_TEMP_LIMITS_BASE_ADDR + \ |
| 106 | ((x) * 2) + 1) |
| 107 | #define ADT7473_REG_TEMP_TMIN(x) (ADT7473_REG_TEMP_TMIN_BASE_ADDR + (x)) |
| 108 | #define ADT7473_REG_TEMP_TMAX(x) (ADT7473_REG_TEMP_TMAX_BASE_ADDR + (x)) |
| 109 | |
| 110 | #define ADT7473_FAN_COUNT 4 |
| 111 | #define ADT7473_REG_FAN(x) (ADT7473_REG_FAN_BASE_ADDR + ((x) * 2)) |
| 112 | #define ADT7473_REG_FAN_MIN(x) (ADT7473_REG_FAN_MIN_BASE_ADDR + ((x) * 2)) |
| 113 | |
| 114 | #define ADT7473_PWM_COUNT 3 |
| 115 | #define ADT7473_REG_PWM(x) (ADT7473_REG_PWM_BASE_ADDR + (x)) |
| 116 | #define ADT7473_REG_PWM_MAX(x) (ADT7473_REG_PWM_MAX_BASE_ADDR + (x)) |
| 117 | #define ADT7473_REG_PWM_MIN(x) (ADT7473_REG_PWM_MIN_BASE_ADDR + (x)) |
| 118 | #define ADT7473_REG_PWM_BHVR(x) (ADT7473_REG_PWM_BHVR_BASE_ADDR + (x)) |
| 119 | |
| 120 | /* How often do we reread sensors values? (In jiffies) */ |
| 121 | #define SENSOR_REFRESH_INTERVAL (2 * HZ) |
| 122 | |
| 123 | /* How often do we reread sensor limit values? (In jiffies) */ |
| 124 | #define LIMIT_REFRESH_INTERVAL (60 * HZ) |
| 125 | |
| 126 | /* datasheet says to divide this number by the fan reading to get fan rpm */ |
| 127 | #define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x)) |
| 128 | #define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM |
| 129 | #define FAN_PERIOD_INVALID 65535 |
| 130 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) |
| 131 | |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 132 | #define ROUND_DIV(x, divisor) (((x) + ((divisor) / 2)) / (divisor)) |
| 133 | |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 134 | struct adt7473_data { |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 135 | struct device *hwmon_dev; |
| 136 | struct attribute_group attrs; |
| 137 | struct mutex lock; |
| 138 | char sensors_valid; |
| 139 | char limits_valid; |
| 140 | unsigned long sensors_last_updated; /* In jiffies */ |
| 141 | unsigned long limits_last_updated; /* In jiffies */ |
| 142 | |
| 143 | u8 volt[ADT7473_VOLT_COUNT]; |
| 144 | s8 volt_min[ADT7473_VOLT_COUNT]; |
| 145 | s8 volt_max[ADT7473_VOLT_COUNT]; |
| 146 | |
| 147 | s8 temp[ADT7473_TEMP_COUNT]; |
| 148 | s8 temp_min[ADT7473_TEMP_COUNT]; |
| 149 | s8 temp_max[ADT7473_TEMP_COUNT]; |
| 150 | s8 temp_tmin[ADT7473_TEMP_COUNT]; |
| 151 | /* This is called the !THERM limit in the datasheet */ |
| 152 | s8 temp_tmax[ADT7473_TEMP_COUNT]; |
| 153 | |
| 154 | u16 fan[ADT7473_FAN_COUNT]; |
| 155 | u16 fan_min[ADT7473_FAN_COUNT]; |
| 156 | |
| 157 | u8 pwm[ADT7473_PWM_COUNT]; |
| 158 | u8 pwm_max[ADT7473_PWM_COUNT]; |
| 159 | u8 pwm_min[ADT7473_PWM_COUNT]; |
| 160 | u8 pwm_behavior[ADT7473_PWM_COUNT]; |
| 161 | |
| 162 | u8 temp_twos_complement; |
| 163 | u8 temp_offset; |
| 164 | |
| 165 | u16 alarm; |
| 166 | u8 max_duty_at_overheat; |
| 167 | }; |
| 168 | |
Jean Delvare | eea5476 | 2008-07-16 19:30:10 +0200 | [diff] [blame] | 169 | static int adt7473_probe(struct i2c_client *client, |
| 170 | const struct i2c_device_id *id); |
| 171 | static int adt7473_detect(struct i2c_client *client, int kind, |
| 172 | struct i2c_board_info *info); |
| 173 | static int adt7473_remove(struct i2c_client *client); |
| 174 | |
| 175 | static const struct i2c_device_id adt7473_id[] = { |
| 176 | { "adt7473", adt7473 }, |
| 177 | { } |
| 178 | }; |
| 179 | MODULE_DEVICE_TABLE(i2c, adt7473_id); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 180 | |
| 181 | static struct i2c_driver adt7473_driver = { |
Jean Delvare | eea5476 | 2008-07-16 19:30:10 +0200 | [diff] [blame] | 182 | .class = I2C_CLASS_HWMON, |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 183 | .driver = { |
| 184 | .name = "adt7473", |
| 185 | }, |
Jean Delvare | eea5476 | 2008-07-16 19:30:10 +0200 | [diff] [blame] | 186 | .probe = adt7473_probe, |
| 187 | .remove = adt7473_remove, |
| 188 | .id_table = adt7473_id, |
| 189 | .detect = adt7473_detect, |
| 190 | .address_data = &addr_data, |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | /* |
| 194 | * 16-bit registers on the ADT7473 are low-byte first. The data sheet says |
| 195 | * that the low byte must be read before the high byte. |
| 196 | */ |
| 197 | static inline int adt7473_read_word_data(struct i2c_client *client, u8 reg) |
| 198 | { |
| 199 | u16 foo; |
| 200 | foo = i2c_smbus_read_byte_data(client, reg); |
| 201 | foo |= ((u16)i2c_smbus_read_byte_data(client, reg + 1) << 8); |
| 202 | return foo; |
| 203 | } |
| 204 | |
| 205 | static inline int adt7473_write_word_data(struct i2c_client *client, u8 reg, |
| 206 | u16 value) |
| 207 | { |
| 208 | return i2c_smbus_write_byte_data(client, reg, value & 0xFF) |
| 209 | && i2c_smbus_write_byte_data(client, reg + 1, value >> 8); |
| 210 | } |
| 211 | |
| 212 | static void adt7473_init_client(struct i2c_client *client) |
| 213 | { |
| 214 | int reg = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG1); |
| 215 | |
| 216 | if (!(reg & ADT7473_CFG1_READY)) { |
| 217 | dev_err(&client->dev, "Chip not ready.\n"); |
| 218 | } else { |
| 219 | /* start monitoring */ |
| 220 | i2c_smbus_write_byte_data(client, ADT7473_REG_CFG1, |
| 221 | reg | ADT7473_CFG1_START); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | static struct adt7473_data *adt7473_update_device(struct device *dev) |
| 226 | { |
| 227 | struct i2c_client *client = to_i2c_client(dev); |
| 228 | struct adt7473_data *data = i2c_get_clientdata(client); |
| 229 | unsigned long local_jiffies = jiffies; |
| 230 | u8 cfg; |
| 231 | int i; |
| 232 | |
| 233 | mutex_lock(&data->lock); |
| 234 | if (time_before(local_jiffies, data->sensors_last_updated + |
| 235 | SENSOR_REFRESH_INTERVAL) |
| 236 | && data->sensors_valid) |
| 237 | goto no_sensor_update; |
| 238 | |
| 239 | for (i = 0; i < ADT7473_VOLT_COUNT; i++) |
| 240 | data->volt[i] = i2c_smbus_read_byte_data(client, |
| 241 | ADT7473_REG_VOLT(i)); |
| 242 | |
| 243 | /* Determine temperature encoding */ |
| 244 | cfg = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG5); |
| 245 | data->temp_twos_complement = (cfg & ADT7473_CFG5_TEMP_TWOS); |
| 246 | |
| 247 | /* |
| 248 | * What does this do? it implies a variable temperature sensor |
| 249 | * offset, but the datasheet doesn't say anything about this bit |
| 250 | * and other parts of the datasheet imply that "offset64" mode |
| 251 | * means that you shift temp values by -64 if the above bit was set. |
| 252 | */ |
| 253 | data->temp_offset = (cfg & ADT7473_CFG5_TEMP_OFFSET); |
| 254 | |
| 255 | for (i = 0; i < ADT7473_TEMP_COUNT; i++) |
| 256 | data->temp[i] = i2c_smbus_read_byte_data(client, |
| 257 | ADT7473_REG_TEMP(i)); |
| 258 | |
| 259 | for (i = 0; i < ADT7473_FAN_COUNT; i++) |
| 260 | data->fan[i] = adt7473_read_word_data(client, |
| 261 | ADT7473_REG_FAN(i)); |
| 262 | |
| 263 | for (i = 0; i < ADT7473_PWM_COUNT; i++) |
| 264 | data->pwm[i] = i2c_smbus_read_byte_data(client, |
| 265 | ADT7473_REG_PWM(i)); |
| 266 | |
| 267 | data->alarm = i2c_smbus_read_byte_data(client, ADT7473_REG_ALARM1); |
| 268 | if (data->alarm & ADT7473_OOL) |
| 269 | data->alarm |= ALARM2(i2c_smbus_read_byte_data(client, |
| 270 | ADT7473_REG_ALARM2)); |
| 271 | |
| 272 | data->sensors_last_updated = local_jiffies; |
| 273 | data->sensors_valid = 1; |
| 274 | |
| 275 | no_sensor_update: |
| 276 | if (time_before(local_jiffies, data->limits_last_updated + |
| 277 | LIMIT_REFRESH_INTERVAL) |
| 278 | && data->limits_valid) |
| 279 | goto out; |
| 280 | |
| 281 | for (i = 0; i < ADT7473_VOLT_COUNT; i++) { |
| 282 | data->volt_min[i] = i2c_smbus_read_byte_data(client, |
| 283 | ADT7473_REG_VOLT_MIN(i)); |
| 284 | data->volt_max[i] = i2c_smbus_read_byte_data(client, |
| 285 | ADT7473_REG_VOLT_MAX(i)); |
| 286 | } |
| 287 | |
| 288 | for (i = 0; i < ADT7473_TEMP_COUNT; i++) { |
| 289 | data->temp_min[i] = i2c_smbus_read_byte_data(client, |
| 290 | ADT7473_REG_TEMP_MIN(i)); |
| 291 | data->temp_max[i] = i2c_smbus_read_byte_data(client, |
| 292 | ADT7473_REG_TEMP_MAX(i)); |
| 293 | data->temp_tmin[i] = i2c_smbus_read_byte_data(client, |
| 294 | ADT7473_REG_TEMP_TMIN(i)); |
| 295 | data->temp_tmax[i] = i2c_smbus_read_byte_data(client, |
| 296 | ADT7473_REG_TEMP_TMAX(i)); |
| 297 | } |
| 298 | |
| 299 | for (i = 0; i < ADT7473_FAN_COUNT; i++) |
| 300 | data->fan_min[i] = adt7473_read_word_data(client, |
| 301 | ADT7473_REG_FAN_MIN(i)); |
| 302 | |
| 303 | for (i = 0; i < ADT7473_PWM_COUNT; i++) { |
| 304 | data->pwm_max[i] = i2c_smbus_read_byte_data(client, |
| 305 | ADT7473_REG_PWM_MAX(i)); |
| 306 | data->pwm_min[i] = i2c_smbus_read_byte_data(client, |
| 307 | ADT7473_REG_PWM_MIN(i)); |
| 308 | data->pwm_behavior[i] = i2c_smbus_read_byte_data(client, |
| 309 | ADT7473_REG_PWM_BHVR(i)); |
| 310 | } |
| 311 | |
Jean Delvare | ed4ec81 | 2008-04-26 16:34:26 +0200 | [diff] [blame] | 312 | i = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG4); |
| 313 | data->max_duty_at_overheat = !!(i & ADT7473_CFG4_MAX_DUTY_AT_OVT); |
| 314 | |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 315 | data->limits_last_updated = local_jiffies; |
| 316 | data->limits_valid = 1; |
| 317 | |
| 318 | out: |
| 319 | mutex_unlock(&data->lock); |
| 320 | return data; |
| 321 | } |
| 322 | |
| 323 | /* |
Jean Delvare | be821b7 | 2008-10-26 17:04:40 +0100 | [diff] [blame] | 324 | * Conversions |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 325 | */ |
Jean Delvare | be821b7 | 2008-10-26 17:04:40 +0100 | [diff] [blame] | 326 | |
| 327 | /* IN are scaled acording to built-in resistors */ |
| 328 | static const int adt7473_scaling[] = { /* .001 Volts */ |
| 329 | 2250, 3300 |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 330 | }; |
Jean Delvare | be821b7 | 2008-10-26 17:04:40 +0100 | [diff] [blame] | 331 | #define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from)) |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 332 | |
| 333 | static int decode_volt(int volt_index, u8 raw) |
| 334 | { |
Jean Delvare | be821b7 | 2008-10-26 17:04:40 +0100 | [diff] [blame] | 335 | return SCALE(raw, 192, adt7473_scaling[volt_index]); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | static u8 encode_volt(int volt_index, int cooked) |
| 339 | { |
Jean Delvare | be821b7 | 2008-10-26 17:04:40 +0100 | [diff] [blame] | 340 | int raw = SCALE(cooked, adt7473_scaling[volt_index], 192); |
| 341 | return SENSORS_LIMIT(raw, 0, 255); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | static ssize_t show_volt_min(struct device *dev, |
| 345 | struct device_attribute *devattr, |
| 346 | char *buf) |
| 347 | { |
| 348 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 349 | struct adt7473_data *data = adt7473_update_device(dev); |
| 350 | return sprintf(buf, "%d\n", |
| 351 | decode_volt(attr->index, data->volt_min[attr->index])); |
| 352 | } |
| 353 | |
| 354 | static ssize_t set_volt_min(struct device *dev, |
| 355 | struct device_attribute *devattr, |
| 356 | const char *buf, |
| 357 | size_t count) |
| 358 | { |
| 359 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 360 | struct i2c_client *client = to_i2c_client(dev); |
| 361 | struct adt7473_data *data = i2c_get_clientdata(client); |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 362 | long volt; |
| 363 | |
| 364 | if (strict_strtol(buf, 10, &volt)) |
| 365 | return -EINVAL; |
| 366 | |
| 367 | volt = encode_volt(attr->index, volt); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 368 | |
| 369 | mutex_lock(&data->lock); |
| 370 | data->volt_min[attr->index] = volt; |
| 371 | i2c_smbus_write_byte_data(client, ADT7473_REG_VOLT_MIN(attr->index), |
| 372 | volt); |
| 373 | mutex_unlock(&data->lock); |
| 374 | |
| 375 | return count; |
| 376 | } |
| 377 | |
| 378 | static ssize_t show_volt_max(struct device *dev, |
| 379 | struct device_attribute *devattr, |
| 380 | char *buf) |
| 381 | { |
| 382 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 383 | struct adt7473_data *data = adt7473_update_device(dev); |
| 384 | return sprintf(buf, "%d\n", |
| 385 | decode_volt(attr->index, data->volt_max[attr->index])); |
| 386 | } |
| 387 | |
| 388 | static ssize_t set_volt_max(struct device *dev, |
| 389 | struct device_attribute *devattr, |
| 390 | const char *buf, |
| 391 | size_t count) |
| 392 | { |
| 393 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 394 | struct i2c_client *client = to_i2c_client(dev); |
| 395 | struct adt7473_data *data = i2c_get_clientdata(client); |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 396 | long volt; |
| 397 | |
| 398 | if (strict_strtol(buf, 10, &volt)) |
| 399 | return -EINVAL; |
| 400 | |
| 401 | volt = encode_volt(attr->index, volt); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 402 | |
| 403 | mutex_lock(&data->lock); |
| 404 | data->volt_max[attr->index] = volt; |
| 405 | i2c_smbus_write_byte_data(client, ADT7473_REG_VOLT_MAX(attr->index), |
| 406 | volt); |
| 407 | mutex_unlock(&data->lock); |
| 408 | |
| 409 | return count; |
| 410 | } |
| 411 | |
| 412 | static ssize_t show_volt(struct device *dev, struct device_attribute *devattr, |
| 413 | char *buf) |
| 414 | { |
| 415 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 416 | struct adt7473_data *data = adt7473_update_device(dev); |
| 417 | |
| 418 | return sprintf(buf, "%d\n", |
| 419 | decode_volt(attr->index, data->volt[attr->index])); |
| 420 | } |
| 421 | |
| 422 | /* |
| 423 | * This chip can report temperature data either as a two's complement |
| 424 | * number in the range -128 to 127, or as an unsigned number that must |
| 425 | * be offset by 64. |
| 426 | */ |
Mark M. Hoffman | 1852448 | 2008-03-06 08:41:09 -0500 | [diff] [blame] | 427 | static int decode_temp(u8 twos_complement, u8 raw) |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 428 | { |
Mark M. Hoffman | 1852448 | 2008-03-06 08:41:09 -0500 | [diff] [blame] | 429 | return twos_complement ? (s8)raw : raw - 64; |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 430 | } |
| 431 | |
Mark M. Hoffman | 1852448 | 2008-03-06 08:41:09 -0500 | [diff] [blame] | 432 | static u8 encode_temp(u8 twos_complement, int cooked) |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 433 | { |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 434 | u8 ret = twos_complement ? cooked & 0xFF : cooked + 64; |
| 435 | return SENSORS_LIMIT(ret, 0, 255); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | static ssize_t show_temp_min(struct device *dev, |
| 439 | struct device_attribute *devattr, |
| 440 | char *buf) |
| 441 | { |
| 442 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 443 | struct adt7473_data *data = adt7473_update_device(dev); |
Mark M. Hoffman | 1852448 | 2008-03-06 08:41:09 -0500 | [diff] [blame] | 444 | return sprintf(buf, "%d\n", 1000 * decode_temp( |
| 445 | data->temp_twos_complement, |
| 446 | data->temp_min[attr->index])); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | static ssize_t set_temp_min(struct device *dev, |
| 450 | struct device_attribute *devattr, |
| 451 | const char *buf, |
| 452 | size_t count) |
| 453 | { |
| 454 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 455 | struct i2c_client *client = to_i2c_client(dev); |
| 456 | struct adt7473_data *data = i2c_get_clientdata(client); |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 457 | long temp; |
| 458 | |
| 459 | if (strict_strtol(buf, 10, &temp)) |
| 460 | return -EINVAL; |
| 461 | |
| 462 | temp = ROUND_DIV(temp, 1000); |
Mark M. Hoffman | 1852448 | 2008-03-06 08:41:09 -0500 | [diff] [blame] | 463 | temp = encode_temp(data->temp_twos_complement, temp); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 464 | |
| 465 | mutex_lock(&data->lock); |
| 466 | data->temp_min[attr->index] = temp; |
| 467 | i2c_smbus_write_byte_data(client, ADT7473_REG_TEMP_MIN(attr->index), |
| 468 | temp); |
| 469 | mutex_unlock(&data->lock); |
| 470 | |
| 471 | return count; |
| 472 | } |
| 473 | |
| 474 | static ssize_t show_temp_max(struct device *dev, |
| 475 | struct device_attribute *devattr, |
| 476 | char *buf) |
| 477 | { |
| 478 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 479 | struct adt7473_data *data = adt7473_update_device(dev); |
Mark M. Hoffman | 1852448 | 2008-03-06 08:41:09 -0500 | [diff] [blame] | 480 | return sprintf(buf, "%d\n", 1000 * decode_temp( |
| 481 | data->temp_twos_complement, |
| 482 | data->temp_max[attr->index])); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | static ssize_t set_temp_max(struct device *dev, |
| 486 | struct device_attribute *devattr, |
| 487 | const char *buf, |
| 488 | size_t count) |
| 489 | { |
| 490 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 491 | struct i2c_client *client = to_i2c_client(dev); |
| 492 | struct adt7473_data *data = i2c_get_clientdata(client); |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 493 | long temp; |
| 494 | |
| 495 | if (strict_strtol(buf, 10, &temp)) |
| 496 | return -EINVAL; |
| 497 | |
| 498 | temp = ROUND_DIV(temp, 1000); |
Mark M. Hoffman | 1852448 | 2008-03-06 08:41:09 -0500 | [diff] [blame] | 499 | temp = encode_temp(data->temp_twos_complement, temp); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 500 | |
| 501 | mutex_lock(&data->lock); |
| 502 | data->temp_max[attr->index] = temp; |
| 503 | i2c_smbus_write_byte_data(client, ADT7473_REG_TEMP_MAX(attr->index), |
| 504 | temp); |
| 505 | mutex_unlock(&data->lock); |
| 506 | |
| 507 | return count; |
| 508 | } |
| 509 | |
| 510 | static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, |
| 511 | char *buf) |
| 512 | { |
| 513 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 514 | struct adt7473_data *data = adt7473_update_device(dev); |
Mark M. Hoffman | 1852448 | 2008-03-06 08:41:09 -0500 | [diff] [blame] | 515 | return sprintf(buf, "%d\n", 1000 * decode_temp( |
| 516 | data->temp_twos_complement, |
| 517 | data->temp[attr->index])); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | static ssize_t show_fan_min(struct device *dev, |
| 521 | struct device_attribute *devattr, |
| 522 | char *buf) |
| 523 | { |
| 524 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 525 | struct adt7473_data *data = adt7473_update_device(dev); |
| 526 | |
| 527 | if (FAN_DATA_VALID(data->fan_min[attr->index])) |
| 528 | return sprintf(buf, "%d\n", |
| 529 | FAN_PERIOD_TO_RPM(data->fan_min[attr->index])); |
| 530 | else |
| 531 | return sprintf(buf, "0\n"); |
| 532 | } |
| 533 | |
| 534 | static ssize_t set_fan_min(struct device *dev, |
| 535 | struct device_attribute *devattr, |
| 536 | const char *buf, size_t count) |
| 537 | { |
| 538 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 539 | struct i2c_client *client = to_i2c_client(dev); |
| 540 | struct adt7473_data *data = i2c_get_clientdata(client); |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 541 | long temp; |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 542 | |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 543 | if (strict_strtol(buf, 10, &temp) || !temp) |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 544 | return -EINVAL; |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 545 | |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 546 | temp = FAN_RPM_TO_PERIOD(temp); |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 547 | temp = SENSORS_LIMIT(temp, 1, 65534); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 548 | |
| 549 | mutex_lock(&data->lock); |
| 550 | data->fan_min[attr->index] = temp; |
| 551 | adt7473_write_word_data(client, ADT7473_REG_FAN_MIN(attr->index), temp); |
| 552 | mutex_unlock(&data->lock); |
| 553 | |
| 554 | return count; |
| 555 | } |
| 556 | |
| 557 | static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, |
| 558 | char *buf) |
| 559 | { |
| 560 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 561 | struct adt7473_data *data = adt7473_update_device(dev); |
| 562 | |
| 563 | if (FAN_DATA_VALID(data->fan[attr->index])) |
| 564 | return sprintf(buf, "%d\n", |
| 565 | FAN_PERIOD_TO_RPM(data->fan[attr->index])); |
| 566 | else |
| 567 | return sprintf(buf, "0\n"); |
| 568 | } |
| 569 | |
| 570 | static ssize_t show_max_duty_at_crit(struct device *dev, |
| 571 | struct device_attribute *devattr, |
| 572 | char *buf) |
| 573 | { |
| 574 | struct adt7473_data *data = adt7473_update_device(dev); |
| 575 | return sprintf(buf, "%d\n", data->max_duty_at_overheat); |
| 576 | } |
| 577 | |
| 578 | static ssize_t set_max_duty_at_crit(struct device *dev, |
| 579 | struct device_attribute *devattr, |
| 580 | const char *buf, |
| 581 | size_t count) |
| 582 | { |
| 583 | u8 reg; |
| 584 | struct i2c_client *client = to_i2c_client(dev); |
| 585 | struct adt7473_data *data = i2c_get_clientdata(client); |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 586 | long temp; |
| 587 | |
| 588 | if (strict_strtol(buf, 10, &temp)) |
| 589 | return -EINVAL; |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 590 | |
| 591 | mutex_lock(&data->lock); |
Mark M. Hoffman | 321c413 | 2008-05-26 15:09:36 -0400 | [diff] [blame] | 592 | data->max_duty_at_overheat = !!temp; |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 593 | reg = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG4); |
| 594 | if (temp) |
| 595 | reg |= ADT7473_CFG4_MAX_DUTY_AT_OVT; |
| 596 | else |
| 597 | reg &= ~ADT7473_CFG4_MAX_DUTY_AT_OVT; |
| 598 | i2c_smbus_write_byte_data(client, ADT7473_REG_CFG4, reg); |
| 599 | mutex_unlock(&data->lock); |
| 600 | |
| 601 | return count; |
| 602 | } |
| 603 | |
| 604 | static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, |
| 605 | char *buf) |
| 606 | { |
| 607 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 608 | struct adt7473_data *data = adt7473_update_device(dev); |
| 609 | return sprintf(buf, "%d\n", data->pwm[attr->index]); |
| 610 | } |
| 611 | |
| 612 | static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, |
| 613 | const char *buf, size_t count) |
| 614 | { |
| 615 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 616 | struct i2c_client *client = to_i2c_client(dev); |
| 617 | struct adt7473_data *data = i2c_get_clientdata(client); |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 618 | long temp; |
| 619 | |
| 620 | if (strict_strtol(buf, 10, &temp)) |
| 621 | return -EINVAL; |
| 622 | |
| 623 | temp = SENSORS_LIMIT(temp, 0, 255); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 624 | |
| 625 | mutex_lock(&data->lock); |
| 626 | data->pwm[attr->index] = temp; |
| 627 | i2c_smbus_write_byte_data(client, ADT7473_REG_PWM(attr->index), temp); |
| 628 | mutex_unlock(&data->lock); |
| 629 | |
| 630 | return count; |
| 631 | } |
| 632 | |
| 633 | static ssize_t show_pwm_max(struct device *dev, |
| 634 | struct device_attribute *devattr, |
| 635 | char *buf) |
| 636 | { |
| 637 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 638 | struct adt7473_data *data = adt7473_update_device(dev); |
| 639 | return sprintf(buf, "%d\n", data->pwm_max[attr->index]); |
| 640 | } |
| 641 | |
| 642 | static ssize_t set_pwm_max(struct device *dev, |
| 643 | struct device_attribute *devattr, |
| 644 | const char *buf, |
| 645 | size_t count) |
| 646 | { |
| 647 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 648 | struct i2c_client *client = to_i2c_client(dev); |
| 649 | struct adt7473_data *data = i2c_get_clientdata(client); |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 650 | long temp; |
| 651 | |
| 652 | if (strict_strtol(buf, 10, &temp)) |
| 653 | return -EINVAL; |
| 654 | |
| 655 | temp = SENSORS_LIMIT(temp, 0, 255); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 656 | |
| 657 | mutex_lock(&data->lock); |
| 658 | data->pwm_max[attr->index] = temp; |
| 659 | i2c_smbus_write_byte_data(client, ADT7473_REG_PWM_MAX(attr->index), |
| 660 | temp); |
| 661 | mutex_unlock(&data->lock); |
| 662 | |
| 663 | return count; |
| 664 | } |
| 665 | |
| 666 | static ssize_t show_pwm_min(struct device *dev, |
| 667 | struct device_attribute *devattr, |
| 668 | char *buf) |
| 669 | { |
| 670 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 671 | struct adt7473_data *data = adt7473_update_device(dev); |
| 672 | return sprintf(buf, "%d\n", data->pwm_min[attr->index]); |
| 673 | } |
| 674 | |
| 675 | static ssize_t set_pwm_min(struct device *dev, |
| 676 | struct device_attribute *devattr, |
| 677 | const char *buf, |
| 678 | size_t count) |
| 679 | { |
| 680 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 681 | struct i2c_client *client = to_i2c_client(dev); |
| 682 | struct adt7473_data *data = i2c_get_clientdata(client); |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 683 | long temp; |
| 684 | |
| 685 | if (strict_strtol(buf, 10, &temp)) |
| 686 | return -EINVAL; |
| 687 | |
| 688 | temp = SENSORS_LIMIT(temp, 0, 255); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 689 | |
| 690 | mutex_lock(&data->lock); |
| 691 | data->pwm_min[attr->index] = temp; |
| 692 | i2c_smbus_write_byte_data(client, ADT7473_REG_PWM_MIN(attr->index), |
| 693 | temp); |
| 694 | mutex_unlock(&data->lock); |
| 695 | |
| 696 | return count; |
| 697 | } |
| 698 | |
| 699 | static ssize_t show_temp_tmax(struct device *dev, |
| 700 | struct device_attribute *devattr, |
| 701 | char *buf) |
| 702 | { |
| 703 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 704 | struct adt7473_data *data = adt7473_update_device(dev); |
Mark M. Hoffman | 1852448 | 2008-03-06 08:41:09 -0500 | [diff] [blame] | 705 | return sprintf(buf, "%d\n", 1000 * decode_temp( |
| 706 | data->temp_twos_complement, |
| 707 | data->temp_tmax[attr->index])); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | static ssize_t set_temp_tmax(struct device *dev, |
| 711 | struct device_attribute *devattr, |
| 712 | const char *buf, |
| 713 | size_t count) |
| 714 | { |
| 715 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 716 | struct i2c_client *client = to_i2c_client(dev); |
| 717 | struct adt7473_data *data = i2c_get_clientdata(client); |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 718 | long temp; |
| 719 | |
| 720 | if (strict_strtol(buf, 10, &temp)) |
| 721 | return -EINVAL; |
| 722 | |
| 723 | temp = ROUND_DIV(temp, 1000); |
Mark M. Hoffman | 1852448 | 2008-03-06 08:41:09 -0500 | [diff] [blame] | 724 | temp = encode_temp(data->temp_twos_complement, temp); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 725 | |
| 726 | mutex_lock(&data->lock); |
| 727 | data->temp_tmax[attr->index] = temp; |
| 728 | i2c_smbus_write_byte_data(client, ADT7473_REG_TEMP_TMAX(attr->index), |
| 729 | temp); |
| 730 | mutex_unlock(&data->lock); |
| 731 | |
| 732 | return count; |
| 733 | } |
| 734 | |
| 735 | static ssize_t show_temp_tmin(struct device *dev, |
| 736 | struct device_attribute *devattr, |
| 737 | char *buf) |
| 738 | { |
| 739 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 740 | struct adt7473_data *data = adt7473_update_device(dev); |
Mark M. Hoffman | 1852448 | 2008-03-06 08:41:09 -0500 | [diff] [blame] | 741 | return sprintf(buf, "%d\n", 1000 * decode_temp( |
| 742 | data->temp_twos_complement, |
| 743 | data->temp_tmin[attr->index])); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | static ssize_t set_temp_tmin(struct device *dev, |
| 747 | struct device_attribute *devattr, |
| 748 | const char *buf, |
| 749 | size_t count) |
| 750 | { |
| 751 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 752 | struct i2c_client *client = to_i2c_client(dev); |
| 753 | struct adt7473_data *data = i2c_get_clientdata(client); |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 754 | long temp; |
| 755 | |
| 756 | if (strict_strtol(buf, 10, &temp)) |
| 757 | return -EINVAL; |
| 758 | |
| 759 | temp = ROUND_DIV(temp, 1000); |
Mark M. Hoffman | 1852448 | 2008-03-06 08:41:09 -0500 | [diff] [blame] | 760 | temp = encode_temp(data->temp_twos_complement, temp); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 761 | |
| 762 | mutex_lock(&data->lock); |
| 763 | data->temp_tmin[attr->index] = temp; |
| 764 | i2c_smbus_write_byte_data(client, ADT7473_REG_TEMP_TMIN(attr->index), |
| 765 | temp); |
| 766 | mutex_unlock(&data->lock); |
| 767 | |
| 768 | return count; |
| 769 | } |
| 770 | |
| 771 | static ssize_t show_pwm_enable(struct device *dev, |
| 772 | struct device_attribute *devattr, |
| 773 | char *buf) |
| 774 | { |
| 775 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 776 | struct adt7473_data *data = adt7473_update_device(dev); |
| 777 | |
| 778 | switch (data->pwm_behavior[attr->index] >> ADT7473_PWM_BHVR_SHIFT) { |
| 779 | case 3: |
| 780 | return sprintf(buf, "0\n"); |
| 781 | case 7: |
| 782 | return sprintf(buf, "1\n"); |
| 783 | default: |
| 784 | return sprintf(buf, "2\n"); |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | static ssize_t set_pwm_enable(struct device *dev, |
| 789 | struct device_attribute *devattr, |
| 790 | const char *buf, |
| 791 | size_t count) |
| 792 | { |
| 793 | u8 reg; |
| 794 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 795 | struct i2c_client *client = to_i2c_client(dev); |
| 796 | struct adt7473_data *data = i2c_get_clientdata(client); |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 797 | long temp; |
| 798 | |
| 799 | if (strict_strtol(buf, 10, &temp)) |
| 800 | return -EINVAL; |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 801 | |
| 802 | switch (temp) { |
| 803 | case 0: |
| 804 | temp = 3; |
| 805 | break; |
| 806 | case 1: |
| 807 | temp = 7; |
| 808 | break; |
| 809 | case 2: |
| 810 | /* Enter automatic mode with fans off */ |
| 811 | temp = 4; |
| 812 | break; |
| 813 | default: |
| 814 | return -EINVAL; |
| 815 | } |
| 816 | |
| 817 | mutex_lock(&data->lock); |
| 818 | reg = i2c_smbus_read_byte_data(client, |
| 819 | ADT7473_REG_PWM_BHVR(attr->index)); |
| 820 | reg = (temp << ADT7473_PWM_BHVR_SHIFT) | |
| 821 | (reg & ~ADT7473_PWM_BHVR_MASK); |
| 822 | i2c_smbus_write_byte_data(client, ADT7473_REG_PWM_BHVR(attr->index), |
| 823 | reg); |
| 824 | data->pwm_behavior[attr->index] = reg; |
| 825 | mutex_unlock(&data->lock); |
| 826 | |
| 827 | return count; |
| 828 | } |
| 829 | |
| 830 | static ssize_t show_pwm_auto_temp(struct device *dev, |
| 831 | struct device_attribute *devattr, |
| 832 | char *buf) |
| 833 | { |
| 834 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 835 | struct adt7473_data *data = adt7473_update_device(dev); |
| 836 | int bhvr = data->pwm_behavior[attr->index] >> ADT7473_PWM_BHVR_SHIFT; |
| 837 | |
| 838 | switch (bhvr) { |
| 839 | case 3: |
| 840 | case 4: |
| 841 | case 7: |
| 842 | return sprintf(buf, "0\n"); |
| 843 | case 0: |
| 844 | case 1: |
| 845 | case 5: |
| 846 | case 6: |
| 847 | return sprintf(buf, "%d\n", bhvr + 1); |
| 848 | case 2: |
| 849 | return sprintf(buf, "4\n"); |
| 850 | } |
| 851 | /* shouldn't ever get here */ |
| 852 | BUG(); |
| 853 | } |
| 854 | |
| 855 | static ssize_t set_pwm_auto_temp(struct device *dev, |
| 856 | struct device_attribute *devattr, |
| 857 | const char *buf, |
| 858 | size_t count) |
| 859 | { |
| 860 | u8 reg; |
| 861 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 862 | struct i2c_client *client = to_i2c_client(dev); |
| 863 | struct adt7473_data *data = i2c_get_clientdata(client); |
Darrick J. Wong | 862343c | 2008-11-12 13:26:58 -0800 | [diff] [blame^] | 864 | long temp; |
| 865 | |
| 866 | if (strict_strtol(buf, 10, &temp)) |
| 867 | return -EINVAL; |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 868 | |
| 869 | switch (temp) { |
| 870 | case 1: |
| 871 | case 2: |
| 872 | case 6: |
| 873 | case 7: |
| 874 | temp--; |
| 875 | break; |
| 876 | case 0: |
| 877 | temp = 4; |
| 878 | break; |
| 879 | default: |
| 880 | return -EINVAL; |
| 881 | } |
| 882 | |
| 883 | mutex_lock(&data->lock); |
| 884 | reg = i2c_smbus_read_byte_data(client, |
| 885 | ADT7473_REG_PWM_BHVR(attr->index)); |
| 886 | reg = (temp << ADT7473_PWM_BHVR_SHIFT) | |
| 887 | (reg & ~ADT7473_PWM_BHVR_MASK); |
| 888 | i2c_smbus_write_byte_data(client, ADT7473_REG_PWM_BHVR(attr->index), |
| 889 | reg); |
| 890 | data->pwm_behavior[attr->index] = reg; |
| 891 | mutex_unlock(&data->lock); |
| 892 | |
| 893 | return count; |
| 894 | } |
| 895 | |
| 896 | static ssize_t show_alarm(struct device *dev, |
| 897 | struct device_attribute *devattr, |
| 898 | char *buf) |
| 899 | { |
| 900 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 901 | struct adt7473_data *data = adt7473_update_device(dev); |
| 902 | |
| 903 | if (data->alarm & attr->index) |
| 904 | return sprintf(buf, "1\n"); |
| 905 | else |
| 906 | return sprintf(buf, "0\n"); |
| 907 | } |
| 908 | |
| 909 | |
| 910 | static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, show_volt_max, |
| 911 | set_volt_max, 0); |
| 912 | static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, show_volt_max, |
| 913 | set_volt_max, 1); |
| 914 | |
| 915 | static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, show_volt_min, |
| 916 | set_volt_min, 0); |
| 917 | static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, show_volt_min, |
| 918 | set_volt_min, 1); |
| 919 | |
| 920 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_volt, NULL, 0); |
| 921 | static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_volt, NULL, 1); |
| 922 | |
| 923 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, |
| 924 | ADT7473_VCCP_ALARM); |
| 925 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, |
| 926 | ADT7473_VCC_ALARM); |
| 927 | |
| 928 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, |
| 929 | set_temp_max, 0); |
| 930 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max, |
| 931 | set_temp_max, 1); |
| 932 | static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_max, |
| 933 | set_temp_max, 2); |
| 934 | |
| 935 | static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min, |
| 936 | set_temp_min, 0); |
| 937 | static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min, |
| 938 | set_temp_min, 1); |
| 939 | static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_temp_min, |
| 940 | set_temp_min, 2); |
| 941 | |
| 942 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); |
| 943 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1); |
| 944 | static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2); |
| 945 | |
| 946 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, |
| 947 | ADT7473_R1T_ALARM | ALARM2(ADT7473_R1T_SHORT)); |
| 948 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, |
| 949 | ADT7473_LT_ALARM); |
| 950 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, |
| 951 | ADT7473_R2T_ALARM | ALARM2(ADT7473_R2T_SHORT)); |
| 952 | |
| 953 | static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, |
| 954 | set_fan_min, 0); |
| 955 | static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min, |
| 956 | set_fan_min, 1); |
| 957 | static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, |
| 958 | set_fan_min, 2); |
| 959 | static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min, |
| 960 | set_fan_min, 3); |
| 961 | |
| 962 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); |
| 963 | static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1); |
| 964 | static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2); |
| 965 | static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3); |
| 966 | |
| 967 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, |
| 968 | ALARM2(ADT7473_FAN1_ALARM)); |
| 969 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, |
| 970 | ALARM2(ADT7473_FAN2_ALARM)); |
| 971 | static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, |
| 972 | ALARM2(ADT7473_FAN3_ALARM)); |
| 973 | static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, |
| 974 | ALARM2(ADT7473_FAN4_ALARM)); |
| 975 | |
| 976 | static SENSOR_DEVICE_ATTR(pwm_use_point2_pwm_at_crit, S_IWUSR | S_IRUGO, |
| 977 | show_max_duty_at_crit, set_max_duty_at_crit, 0); |
| 978 | |
| 979 | static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0); |
| 980 | static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1); |
| 981 | static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2); |
| 982 | |
| 983 | static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IWUSR | S_IRUGO, |
| 984 | show_pwm_min, set_pwm_min, 0); |
| 985 | static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm, S_IWUSR | S_IRUGO, |
| 986 | show_pwm_min, set_pwm_min, 1); |
| 987 | static SENSOR_DEVICE_ATTR(pwm3_auto_point1_pwm, S_IWUSR | S_IRUGO, |
| 988 | show_pwm_min, set_pwm_min, 2); |
| 989 | |
| 990 | static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO, |
| 991 | show_pwm_max, set_pwm_max, 0); |
| 992 | static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm, S_IWUSR | S_IRUGO, |
| 993 | show_pwm_max, set_pwm_max, 1); |
| 994 | static SENSOR_DEVICE_ATTR(pwm3_auto_point2_pwm, S_IWUSR | S_IRUGO, |
| 995 | show_pwm_max, set_pwm_max, 2); |
| 996 | |
| 997 | static SENSOR_DEVICE_ATTR(temp1_auto_point1_temp, S_IWUSR | S_IRUGO, |
| 998 | show_temp_tmin, set_temp_tmin, 0); |
| 999 | static SENSOR_DEVICE_ATTR(temp2_auto_point1_temp, S_IWUSR | S_IRUGO, |
| 1000 | show_temp_tmin, set_temp_tmin, 1); |
| 1001 | static SENSOR_DEVICE_ATTR(temp3_auto_point1_temp, S_IWUSR | S_IRUGO, |
| 1002 | show_temp_tmin, set_temp_tmin, 2); |
| 1003 | |
| 1004 | static SENSOR_DEVICE_ATTR(temp1_auto_point2_temp, S_IWUSR | S_IRUGO, |
| 1005 | show_temp_tmax, set_temp_tmax, 0); |
| 1006 | static SENSOR_DEVICE_ATTR(temp2_auto_point2_temp, S_IWUSR | S_IRUGO, |
| 1007 | show_temp_tmax, set_temp_tmax, 1); |
| 1008 | static SENSOR_DEVICE_ATTR(temp3_auto_point2_temp, S_IWUSR | S_IRUGO, |
| 1009 | show_temp_tmax, set_temp_tmax, 2); |
| 1010 | |
| 1011 | static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_enable, |
| 1012 | set_pwm_enable, 0); |
| 1013 | static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_enable, |
| 1014 | set_pwm_enable, 1); |
| 1015 | static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_enable, |
| 1016 | set_pwm_enable, 2); |
| 1017 | |
| 1018 | static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IWUSR | S_IRUGO, |
| 1019 | show_pwm_auto_temp, set_pwm_auto_temp, 0); |
| 1020 | static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IWUSR | S_IRUGO, |
| 1021 | show_pwm_auto_temp, set_pwm_auto_temp, 1); |
| 1022 | static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO, |
| 1023 | show_pwm_auto_temp, set_pwm_auto_temp, 2); |
| 1024 | |
| 1025 | static struct attribute *adt7473_attr[] = |
| 1026 | { |
| 1027 | &sensor_dev_attr_in1_max.dev_attr.attr, |
| 1028 | &sensor_dev_attr_in2_max.dev_attr.attr, |
| 1029 | &sensor_dev_attr_in1_min.dev_attr.attr, |
| 1030 | &sensor_dev_attr_in2_min.dev_attr.attr, |
| 1031 | &sensor_dev_attr_in1_input.dev_attr.attr, |
| 1032 | &sensor_dev_attr_in2_input.dev_attr.attr, |
| 1033 | &sensor_dev_attr_in1_alarm.dev_attr.attr, |
| 1034 | &sensor_dev_attr_in2_alarm.dev_attr.attr, |
| 1035 | |
| 1036 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 1037 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
| 1038 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
| 1039 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
| 1040 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
| 1041 | &sensor_dev_attr_temp3_min.dev_attr.attr, |
| 1042 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 1043 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| 1044 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
| 1045 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, |
| 1046 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, |
| 1047 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, |
| 1048 | &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr, |
| 1049 | &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr, |
| 1050 | &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr, |
| 1051 | &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr, |
| 1052 | &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr, |
| 1053 | &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr, |
| 1054 | |
| 1055 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
| 1056 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
| 1057 | &sensor_dev_attr_fan3_min.dev_attr.attr, |
| 1058 | &sensor_dev_attr_fan4_min.dev_attr.attr, |
| 1059 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 1060 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
| 1061 | &sensor_dev_attr_fan3_input.dev_attr.attr, |
| 1062 | &sensor_dev_attr_fan4_input.dev_attr.attr, |
| 1063 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
| 1064 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
| 1065 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, |
| 1066 | &sensor_dev_attr_fan4_alarm.dev_attr.attr, |
| 1067 | |
| 1068 | &sensor_dev_attr_pwm_use_point2_pwm_at_crit.dev_attr.attr, |
| 1069 | |
| 1070 | &sensor_dev_attr_pwm1.dev_attr.attr, |
| 1071 | &sensor_dev_attr_pwm2.dev_attr.attr, |
| 1072 | &sensor_dev_attr_pwm3.dev_attr.attr, |
| 1073 | &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, |
| 1074 | &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, |
| 1075 | &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, |
| 1076 | &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, |
| 1077 | &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr, |
| 1078 | &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, |
| 1079 | |
| 1080 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
| 1081 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, |
| 1082 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, |
| 1083 | &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, |
| 1084 | &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr, |
| 1085 | &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr, |
| 1086 | |
| 1087 | NULL |
| 1088 | }; |
| 1089 | |
Jean Delvare | eea5476 | 2008-07-16 19:30:10 +0200 | [diff] [blame] | 1090 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
| 1091 | static int adt7473_detect(struct i2c_client *client, int kind, |
| 1092 | struct i2c_board_info *info) |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 1093 | { |
Jean Delvare | eea5476 | 2008-07-16 19:30:10 +0200 | [diff] [blame] | 1094 | struct i2c_adapter *adapter = client->adapter; |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 1095 | |
| 1096 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
Jean Delvare | eea5476 | 2008-07-16 19:30:10 +0200 | [diff] [blame] | 1097 | return -ENODEV; |
| 1098 | |
| 1099 | if (kind <= 0) { |
| 1100 | int vendor, device, revision; |
| 1101 | |
| 1102 | vendor = i2c_smbus_read_byte_data(client, ADT7473_REG_VENDOR); |
| 1103 | if (vendor != ADT7473_VENDOR) |
| 1104 | return -ENODEV; |
| 1105 | |
| 1106 | device = i2c_smbus_read_byte_data(client, ADT7473_REG_DEVICE); |
| 1107 | if (device != ADT7473_DEVICE) |
| 1108 | return -ENODEV; |
| 1109 | |
| 1110 | revision = i2c_smbus_read_byte_data(client, |
| 1111 | ADT7473_REG_REVISION); |
| 1112 | if (revision != ADT7473_REV_68 && revision != ADT7473_REV_69) |
| 1113 | return -ENODEV; |
| 1114 | } else |
| 1115 | dev_dbg(&adapter->dev, "detection forced\n"); |
| 1116 | |
| 1117 | strlcpy(info->type, "adt7473", I2C_NAME_SIZE); |
| 1118 | |
| 1119 | return 0; |
| 1120 | } |
| 1121 | |
| 1122 | static int adt7473_probe(struct i2c_client *client, |
| 1123 | const struct i2c_device_id *id) |
| 1124 | { |
| 1125 | struct adt7473_data *data; |
| 1126 | int err; |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 1127 | |
| 1128 | data = kzalloc(sizeof(struct adt7473_data), GFP_KERNEL); |
| 1129 | if (!data) { |
| 1130 | err = -ENOMEM; |
| 1131 | goto exit; |
| 1132 | } |
| 1133 | |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 1134 | i2c_set_clientdata(client, data); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 1135 | mutex_init(&data->lock); |
| 1136 | |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 1137 | dev_info(&client->dev, "%s chip found\n", client->name); |
| 1138 | |
| 1139 | /* Initialize the ADT7473 chip */ |
| 1140 | adt7473_init_client(client); |
| 1141 | |
| 1142 | /* Register sysfs hooks */ |
| 1143 | data->attrs.attrs = adt7473_attr; |
| 1144 | err = sysfs_create_group(&client->dev.kobj, &data->attrs); |
| 1145 | if (err) |
Jean Delvare | eea5476 | 2008-07-16 19:30:10 +0200 | [diff] [blame] | 1146 | goto exit_free; |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 1147 | |
| 1148 | data->hwmon_dev = hwmon_device_register(&client->dev); |
| 1149 | if (IS_ERR(data->hwmon_dev)) { |
| 1150 | err = PTR_ERR(data->hwmon_dev); |
| 1151 | goto exit_remove; |
| 1152 | } |
| 1153 | |
| 1154 | return 0; |
| 1155 | |
| 1156 | exit_remove: |
| 1157 | sysfs_remove_group(&client->dev.kobj, &data->attrs); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 1158 | exit_free: |
| 1159 | kfree(data); |
| 1160 | exit: |
| 1161 | return err; |
| 1162 | } |
| 1163 | |
Jean Delvare | eea5476 | 2008-07-16 19:30:10 +0200 | [diff] [blame] | 1164 | static int adt7473_remove(struct i2c_client *client) |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 1165 | { |
| 1166 | struct adt7473_data *data = i2c_get_clientdata(client); |
| 1167 | |
| 1168 | hwmon_device_unregister(data->hwmon_dev); |
| 1169 | sysfs_remove_group(&client->dev.kobj, &data->attrs); |
Darrick J. Wong | 57df46d | 2008-02-18 13:33:23 -0800 | [diff] [blame] | 1170 | kfree(data); |
| 1171 | return 0; |
| 1172 | } |
| 1173 | |
| 1174 | static int __init adt7473_init(void) |
| 1175 | { |
| 1176 | return i2c_add_driver(&adt7473_driver); |
| 1177 | } |
| 1178 | |
| 1179 | static void __exit adt7473_exit(void) |
| 1180 | { |
| 1181 | i2c_del_driver(&adt7473_driver); |
| 1182 | } |
| 1183 | |
| 1184 | MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>"); |
| 1185 | MODULE_DESCRIPTION("ADT7473 driver"); |
| 1186 | MODULE_LICENSE("GPL"); |
| 1187 | |
| 1188 | module_init(adt7473_init); |
| 1189 | module_exit(adt7473_exit); |