| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 3 |
* emc1403.c - SMSC Thermal Driver |
| 4 |
* |
| 5 |
* Copyright (C) 2008 Intel Corp |
| 6 |
* |
| 7 |
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8 |
* |
| 9 |
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10 |
*/ |
| 11 |
|
| 12 |
#include <linux/module.h> |
| 13 |
#include <linux/init.h> |
| 14 |
#include <linux/slab.h> |
| 15 |
#include <linux/i2c.h> |
| 16 |
#include <linux/hwmon.h> |
| 17 |
#include <linux/hwmon-sysfs.h> |
| 18 |
#include <linux/err.h> |
| 19 |
#include <linux/sysfs.h> |
| 20 |
#include <linux/regmap.h> |
| 21 |
#include <linux/util_macros.h> |
| 22 |
|
| 23 |
#define THERMAL_PID_REG 0xfd |
| 24 |
#define THERMAL_SMSC_ID_REG 0xfe |
| 25 |
#define THERMAL_REVISION_REG 0xff |
| 26 |
|
| 27 |
enum emc1403_chip { emc1402, emc1403, emc1404, emc1428 }; |
| 28 |
|
| 29 |
struct thermal_data { |
| 30 |
enum emc1403_chip chip; |
| 31 |
struct regmap *regmap; |
| 32 |
}; |
| 33 |
|
| 34 |
static ssize_t power_state_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 35 |
{ |
| 36 |
struct thermal_data *data = dev_get_drvdata(dev); |
| 37 |
unsigned int val; |
| 38 |
int retval; |
| 39 |
|
| 40 |
retval = regmap_read(data->regmap, 0x03, &val); |
| 41 |
if (retval < 0) |
| 42 |
return retval; |
| 43 |
return sprintf(buf, "%d\n", !!(val & BIT(6))); |
| 44 |
} |
| 45 |
|
| 46 |
static ssize_t power_state_store(struct device *dev, struct device_attribute *attr, |
| 47 |
const char *buf, size_t count) |
| 48 |
{ |
| 49 |
struct thermal_data *data = dev_get_drvdata(dev); |
| 50 |
unsigned long val; |
| 51 |
int retval; |
| 52 |
|
| 53 |
if (kstrtoul(buf, 10, &val)) |
| 54 |
return -EINVAL; |
| 55 |
|
| 56 |
retval = regmap_update_bits(data->regmap, 0x03, BIT(6), |
| 57 |
val ? BIT(6) : 0); |
| 58 |
if (retval < 0) |
| 59 |
return retval; |
| 60 |
return count; |
| 61 |
} |
| 62 |
|
| 63 |
static DEVICE_ATTR_RW(power_state); |
| 64 |
|
| 65 |
static struct attribute *emc1403_attrs[] = { |
| 66 |
&dev_attr_power_state.attr, |
| 67 |
NULL |
| 68 |
}; |
| 69 |
ATTRIBUTE_GROUPS(emc1403); |
| 70 |
|
| 71 |
static int emc1403_detect(struct i2c_client *client, |
| 72 |
struct i2c_board_info *info) |
| 73 |
{ |
| 74 |
int id; |
| 75 |
/* Check if thermal chip is SMSC and EMC1403 or EMC1423 */ |
| 76 |
|
| 77 |
id = i2c_smbus_read_byte_data(client, THERMAL_SMSC_ID_REG); |
| 78 |
if (id != 0x5d) |
| 79 |
return -ENODEV; |
| 80 |
|
| 81 |
id = i2c_smbus_read_byte_data(client, THERMAL_PID_REG); |
| 82 |
switch (id) { |
| 83 |
case 0x20: |
| 84 |
strscpy(info->type, "emc1402", I2C_NAME_SIZE); |
| 85 |
break; |
| 86 |
case 0x21: |
| 87 |
strscpy(info->type, "emc1403", I2C_NAME_SIZE); |
| 88 |
break; |
| 89 |
case 0x22: |
| 90 |
strscpy(info->type, "emc1422", I2C_NAME_SIZE); |
| 91 |
break; |
| 92 |
case 0x23: |
| 93 |
strscpy(info->type, "emc1423", I2C_NAME_SIZE); |
| 94 |
break; |
| 95 |
case 0x25: |
| 96 |
strscpy(info->type, "emc1404", I2C_NAME_SIZE); |
| 97 |
break; |
| 98 |
case 0x27: |
| 99 |
strscpy(info->type, "emc1424", I2C_NAME_SIZE); |
| 100 |
break; |
| 101 |
case 0x29: |
| 102 |
strscpy(info->type, "emc1428", I2C_NAME_SIZE); |
| 103 |
break; |
| 104 |
case 0x59: |
| 105 |
strscpy(info->type, "emc1438", I2C_NAME_SIZE); |
| 106 |
break; |
| 107 |
case 0x60: |
| 108 |
strscpy(info->type, "emc1442", I2C_NAME_SIZE); |
| 109 |
break; |
| 110 |
default: |
| 111 |
return -ENODEV; |
| 112 |
} |
| 113 |
|
| 114 |
id = i2c_smbus_read_byte_data(client, THERMAL_REVISION_REG); |
| 115 |
if (id < 0x01 || id > 0x04) |
| 116 |
return -ENODEV; |
| 117 |
|
| 118 |
return 0; |
| 119 |
} |
| 120 |
|
| 121 |
static bool emc1403_regmap_is_volatile(struct device *dev, unsigned int reg) |
| 122 |
{ |
| 123 |
switch (reg) { |
| 124 |
case 0x00: /* internal diode high byte */ |
| 125 |
case 0x01: /* external diode 1 high byte */ |
| 126 |
case 0x02: /* status */ |
| 127 |
case 0x10: /* external diode 1 low byte */ |
| 128 |
case 0x1b: /* external diode fault */ |
| 129 |
case 0x23: /* external diode 2 high byte */ |
| 130 |
case 0x24: /* external diode 2 low byte */ |
| 131 |
case 0x29: /* internal diode low byte */ |
| 132 |
case 0x2a: /* externl diode 3 high byte */ |
| 133 |
case 0x2b: /* external diode 3 low byte */ |
| 134 |
case 0x35: /* high limit status */ |
| 135 |
case 0x36: /* low limit status */ |
| 136 |
case 0x37: /* therm limit status */ |
| 137 |
case 0x41: /* external diode 4 high byte */ |
| 138 |
case 0x42: /* external diode 4 low byte */ |
| 139 |
case 0x43: /* external diode 5 high byte */ |
| 140 |
case 0x44: /* external diode 5 low byte */ |
| 141 |
case 0x45: /* external diode 6 high byte */ |
| 142 |
case 0x46: /* external diode 6 low byte */ |
| 143 |
case 0x47: /* external diode 7 high byte */ |
| 144 |
case 0x48: /* external diode 7 low byte */ |
| 145 |
return true; |
| 146 |
default: |
| 147 |
return false; |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
static const struct regmap_config emc1403_regmap_config = { |
| 152 |
.reg_bits = 8, |
| 153 |
.val_bits = 8, |
| 154 |
.cache_type = REGCACHE_MAPLE, |
| 155 |
.volatile_reg = emc1403_regmap_is_volatile, |
| 156 |
}; |
| 157 |
|
| 158 |
enum emc1403_reg_map {temp_min, temp_max, temp_crit, temp_input}; |
| 159 |
|
| 160 |
static u8 ema1403_temp_map[] = { |
| 161 |
[hwmon_temp_min] = temp_min, |
| 162 |
[hwmon_temp_max] = temp_max, |
| 163 |
[hwmon_temp_crit] = temp_crit, |
| 164 |
[hwmon_temp_input] = temp_input, |
| 165 |
}; |
| 166 |
|
| 167 |
static u8 emc1403_temp_regs[][4] = { |
| 168 |
[0] = { |
| 169 |
[temp_min] = 0x06, |
| 170 |
[temp_max] = 0x05, |
| 171 |
[temp_crit] = 0x20, |
| 172 |
[temp_input] = 0x00, |
| 173 |
}, |
| 174 |
[1] = { |
| 175 |
[temp_min] = 0x08, |
| 176 |
[temp_max] = 0x07, |
| 177 |
[temp_crit] = 0x19, |
| 178 |
[temp_input] = 0x01, |
| 179 |
}, |
| 180 |
[2] = { |
| 181 |
[temp_min] = 0x16, |
| 182 |
[temp_max] = 0x15, |
| 183 |
[temp_crit] = 0x1a, |
| 184 |
[temp_input] = 0x23, |
| 185 |
}, |
| 186 |
[3] = { |
| 187 |
[temp_min] = 0x2d, |
| 188 |
[temp_max] = 0x2c, |
| 189 |
[temp_crit] = 0x30, |
| 190 |
[temp_input] = 0x2a, |
| 191 |
}, |
| 192 |
[4] = { |
| 193 |
[temp_min] = 0x51, |
| 194 |
[temp_max] = 0x50, |
| 195 |
[temp_crit] = 0x64, |
| 196 |
[temp_input] = 0x41, |
| 197 |
}, |
| 198 |
[5] = { |
| 199 |
[temp_min] = 0x55, |
| 200 |
[temp_max] = 0x54, |
| 201 |
[temp_crit] = 0x65, |
| 202 |
[temp_input] = 0x43 |
| 203 |
}, |
| 204 |
[6] = { |
| 205 |
[temp_min] = 0x59, |
| 206 |
[temp_max] = 0x58, |
| 207 |
[temp_crit] = 0x66, |
| 208 |
[temp_input] = 0x45, |
| 209 |
}, |
| 210 |
[7] = { |
| 211 |
[temp_min] = 0x5d, |
| 212 |
[temp_max] = 0x5c, |
| 213 |
[temp_crit] = 0x67, |
| 214 |
[temp_input] = 0x47, |
| 215 |
}, |
| 216 |
}; |
| 217 |
|
| 218 |
static s8 emc1403_temp_regs_low[][4] = { |
| 219 |
[0] = { |
| 220 |
[temp_min] = -1, |
| 221 |
[temp_max] = -1, |
| 222 |
[temp_crit] = -1, |
| 223 |
[temp_input] = 0x29, |
| 224 |
}, |
| 225 |
[1] = { |
| 226 |
[temp_min] = 0x14, |
| 227 |
[temp_max] = 0x13, |
| 228 |
[temp_crit] = -1, |
| 229 |
[temp_input] = 0x10, |
| 230 |
}, |
| 231 |
[2] = { |
| 232 |
[temp_min] = 0x18, |
| 233 |
[temp_max] = 0x17, |
| 234 |
[temp_crit] = -1, |
| 235 |
[temp_input] = 0x24, |
| 236 |
}, |
| 237 |
[3] = { |
| 238 |
[temp_min] = 0x2f, |
| 239 |
[temp_max] = 0x2e, |
| 240 |
[temp_crit] = -1, |
| 241 |
[temp_input] = 0x2b, |
| 242 |
}, |
| 243 |
[4] = { |
| 244 |
[temp_min] = 0x53, |
| 245 |
[temp_max] = 0x52, |
| 246 |
[temp_crit] = -1, |
| 247 |
[temp_input] = 0x42, |
| 248 |
}, |
| 249 |
[5] = { |
| 250 |
[temp_min] = 0x57, |
| 251 |
[temp_max] = 0x56, |
| 252 |
[temp_crit] = -1, |
| 253 |
[temp_input] = 0x44, |
| 254 |
}, |
| 255 |
[6] = { |
| 256 |
[temp_min] = 0x5b, |
| 257 |
[temp_max] = 0x5a, |
| 258 |
[temp_crit] = -1, |
| 259 |
[temp_input] = 0x46, |
| 260 |
}, |
| 261 |
[7] = { |
| 262 |
[temp_min] = 0x5f, |
| 263 |
[temp_max] = 0x5e, |
| 264 |
[temp_crit] = -1, |
| 265 |
[temp_input] = 0x48, |
| 266 |
}, |
| 267 |
}; |
| 268 |
|
| 269 |
static int emc1403_get_temp(struct thermal_data *data, int channel, |
| 270 |
enum emc1403_reg_map map, long *val) |
| 271 |
{ |
| 272 |
unsigned int regvalh; |
| 273 |
unsigned int regvall = 0; |
| 274 |
int ret; |
| 275 |
s8 reg; |
| 276 |
|
| 277 |
ret = regmap_read(data->regmap, emc1403_temp_regs[channel][map], ®valh); |
| 278 |
if (ret < 0) |
| 279 |
return ret; |
| 280 |
|
| 281 |
reg = emc1403_temp_regs_low[channel][map]; |
| 282 |
if (reg >= 0) { |
| 283 |
ret = regmap_read(data->regmap, reg, ®vall); |
| 284 |
if (ret < 0) |
| 285 |
return ret; |
| 286 |
} |
| 287 |
|
| 288 |
if (data->chip == emc1428) |
| 289 |
*val = sign_extend32((regvalh << 3) | (regvall >> 5), 10) * 125; |
| 290 |
else |
| 291 |
*val = ((regvalh << 3) | (regvall >> 5)) * 125; |
| 292 |
|
| 293 |
return 0; |
| 294 |
} |
| 295 |
|
| 296 |
static int emc1403_get_hyst(struct thermal_data *data, int channel, |
| 297 |
enum emc1403_reg_map map, long *val) |
| 298 |
{ |
| 299 |
int hyst, ret; |
| 300 |
long limit; |
| 301 |
|
| 302 |
ret = emc1403_get_temp(data, channel, map, &limit); |
| 303 |
if (ret < 0) |
| 304 |
return ret; |
| 305 |
ret = regmap_read(data->regmap, 0x21, &hyst); |
| 306 |
if (ret < 0) |
| 307 |
return ret; |
| 308 |
if (map == temp_min) |
| 309 |
*val = limit + hyst * 1000; |
| 310 |
else |
| 311 |
*val = limit - hyst * 1000; |
| 312 |
return 0; |
| 313 |
} |
| 314 |
|
| 315 |
static int emc1403_temp_read(struct thermal_data *data, u32 attr, int channel, long *val) |
| 316 |
{ |
| 317 |
unsigned int regval; |
| 318 |
int ret; |
| 319 |
|
| 320 |
switch (attr) { |
| 321 |
case hwmon_temp_min: |
| 322 |
case hwmon_temp_max: |
| 323 |
case hwmon_temp_crit: |
| 324 |
case hwmon_temp_input: |
| 325 |
ret = emc1403_get_temp(data, channel, ema1403_temp_map[attr], val); |
| 326 |
break; |
| 327 |
case hwmon_temp_min_hyst: |
| 328 |
ret = emc1403_get_hyst(data, channel, temp_min, val); |
| 329 |
break; |
| 330 |
case hwmon_temp_max_hyst: |
| 331 |
ret = emc1403_get_hyst(data, channel, temp_max, val); |
| 332 |
break; |
| 333 |
case hwmon_temp_crit_hyst: |
| 334 |
ret = emc1403_get_hyst(data, channel, temp_crit, val); |
| 335 |
break; |
| 336 |
case hwmon_temp_min_alarm: |
| 337 |
if (data->chip == emc1402) { |
| 338 |
ret = regmap_read(data->regmap, 0x02, ®val); |
| 339 |
if (ret < 0) |
| 340 |
break; |
| 341 |
*val = !!(regval & BIT(5 - 2 * channel)); |
| 342 |
} else { |
| 343 |
ret = regmap_read(data->regmap, 0x36, ®val); |
| 344 |
if (ret < 0) |
| 345 |
break; |
| 346 |
*val = !!(regval & BIT(channel)); |
| 347 |
} |
| 348 |
break; |
| 349 |
case hwmon_temp_max_alarm: |
| 350 |
if (data->chip == emc1402) { |
| 351 |
ret = regmap_read(data->regmap, 0x02, ®val); |
| 352 |
if (ret < 0) |
| 353 |
break; |
| 354 |
*val = !!(regval & BIT(6 - 2 * channel)); |
| 355 |
} else { |
| 356 |
ret = regmap_read(data->regmap, 0x35, ®val); |
| 357 |
if (ret < 0) |
| 358 |
break; |
| 359 |
*val = !!(regval & BIT(channel)); |
| 360 |
} |
| 361 |
break; |
| 362 |
case hwmon_temp_crit_alarm: |
| 363 |
if (data->chip == emc1402) { |
| 364 |
ret = regmap_read(data->regmap, 0x02, ®val); |
| 365 |
if (ret < 0) |
| 366 |
break; |
| 367 |
*val = !!(regval & BIT(channel)); |
| 368 |
} else { |
| 369 |
ret = regmap_read(data->regmap, 0x37, ®val); |
| 370 |
if (ret < 0) |
| 371 |
break; |
| 372 |
*val = !!(regval & BIT(channel)); |
| 373 |
} |
| 374 |
break; |
| 375 |
case hwmon_temp_fault: |
| 376 |
ret = regmap_read(data->regmap, 0x1b, ®val); |
| 377 |
if (ret < 0) |
| 378 |
break; |
| 379 |
*val = !!(regval & BIT(channel)); |
| 380 |
break; |
| 381 |
default: |
| 382 |
return -EOPNOTSUPP; |
| 383 |
} |
| 384 |
return ret; |
| 385 |
} |
| 386 |
|
| 387 |
static int emc1403_get_convrate(struct thermal_data *data, long *val) |
| 388 |
{ |
| 389 |
unsigned int convrate; |
| 390 |
int ret; |
| 391 |
|
| 392 |
ret = regmap_read(data->regmap, 0x04, &convrate); |
| 393 |
if (ret < 0) |
| 394 |
return ret; |
| 395 |
if (convrate > 10) |
| 396 |
convrate = 4; |
| 397 |
|
| 398 |
*val = 16000 >> convrate; |
| 399 |
return 0; |
| 400 |
} |
| 401 |
|
| 402 |
static int emc1403_chip_read(struct thermal_data *data, u32 attr, long *val) |
| 403 |
{ |
| 404 |
switch (attr) { |
| 405 |
case hwmon_chip_update_interval: |
| 406 |
return emc1403_get_convrate(data, val); |
| 407 |
default: |
| 408 |
return -EOPNOTSUPP; |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
static int emc1403_read(struct device *dev, enum hwmon_sensor_types type, |
| 413 |
u32 attr, int channel, long *val) |
| 414 |
{ |
| 415 |
struct thermal_data *data = dev_get_drvdata(dev); |
| 416 |
|
| 417 |
switch (type) { |
| 418 |
case hwmon_temp: |
| 419 |
return emc1403_temp_read(data, attr, channel, val); |
| 420 |
case hwmon_chip: |
| 421 |
return emc1403_chip_read(data, attr, val); |
| 422 |
default: |
| 423 |
return -EOPNOTSUPP; |
| 424 |
} |
| 425 |
} |
| 426 |
|
| 427 |
static int emc1403_set_hyst(struct thermal_data *data, long val) |
| 428 |
{ |
| 429 |
int hyst, ret; |
| 430 |
long limit; |
| 431 |
|
| 432 |
if (data->chip == emc1428) |
| 433 |
val = clamp_val(val, -128000, 127000); |
| 434 |
else |
| 435 |
val = clamp_val(val, 0, 255000); |
| 436 |
|
| 437 |
ret = emc1403_get_temp(data, 0, temp_crit, &limit); |
| 438 |
if (ret < 0) |
| 439 |
return ret; |
| 440 |
|
| 441 |
hyst = limit - val; |
| 442 |
if (data->chip == emc1428) |
| 443 |
hyst = clamp_val(DIV_ROUND_CLOSEST(hyst, 1000), 0, 127); |
| 444 |
else |
| 445 |
hyst = clamp_val(DIV_ROUND_CLOSEST(hyst, 1000), 0, 255); |
| 446 |
return regmap_write(data->regmap, 0x21, hyst); |
| 447 |
} |
| 448 |
|
| 449 |
static int emc1403_set_temp(struct thermal_data *data, int channel, |
| 450 |
enum emc1403_reg_map map, long val) |
| 451 |
{ |
| 452 |
unsigned int regval; |
| 453 |
int ret; |
| 454 |
u8 regh; |
| 455 |
s8 regl; |
| 456 |
|
| 457 |
regh = emc1403_temp_regs[channel][map]; |
| 458 |
regl = emc1403_temp_regs_low[channel][map]; |
| 459 |
|
| 460 |
if (regl >= 0) { |
| 461 |
if (data->chip == emc1428) |
| 462 |
val = clamp_val(val, -128000, 127875); |
| 463 |
else |
| 464 |
val = clamp_val(val, 0, 255875); |
| 465 |
regval = DIV_ROUND_CLOSEST(val, 125); |
| 466 |
ret = regmap_write(data->regmap, regh, (regval >> 3) & 0xff); |
| 467 |
if (ret < 0) |
| 468 |
return ret; |
| 469 |
ret = regmap_write(data->regmap, regl, (regval & 0x07) << 5); |
| 470 |
} else { |
| 471 |
if (data->chip == emc1428) |
| 472 |
val = clamp_val(val, -128000, 127000); |
| 473 |
else |
| 474 |
val = clamp_val(val, 0, 255000); |
| 475 |
regval = DIV_ROUND_CLOSEST(val, 1000); |
| 476 |
ret = regmap_write(data->regmap, regh, regval); |
| 477 |
} |
| 478 |
return ret; |
| 479 |
} |
| 480 |
|
| 481 |
static int emc1403_temp_write(struct thermal_data *data, u32 attr, int channel, long val) |
| 482 |
{ |
| 483 |
switch (attr) { |
| 484 |
case hwmon_temp_min: |
| 485 |
case hwmon_temp_max: |
| 486 |
case hwmon_temp_crit: |
| 487 |
return emc1403_set_temp(data, channel, ema1403_temp_map[attr], val); |
| 488 |
case hwmon_temp_crit_hyst: |
| 489 |
return emc1403_set_hyst(data, val); |
| 490 |
default: |
| 491 |
return -EOPNOTSUPP; |
| 492 |
} |
| 493 |
} |
| 494 |
|
| 495 |
/* Lookup table for temperature conversion times in msec */ |
| 496 |
static const u16 ina3221_conv_time[] = { |
| 497 |
16000, 8000, 4000, 2000, 1000, 500, 250, 125, 62, 31, 16 |
| 498 |
}; |
| 499 |
|
| 500 |
static int emc1403_set_convrate(struct thermal_data *data, unsigned int interval) |
| 501 |
{ |
| 502 |
int convrate; |
| 503 |
|
| 504 |
convrate = find_closest_descending(interval, ina3221_conv_time, |
| 505 |
ARRAY_SIZE(ina3221_conv_time)); |
| 506 |
return regmap_write(data->regmap, 0x04, convrate); |
| 507 |
} |
| 508 |
|
| 509 |
static int emc1403_chip_write(struct thermal_data *data, u32 attr, long val) |
| 510 |
{ |
| 511 |
switch (attr) { |
| 512 |
case hwmon_chip_update_interval: |
| 513 |
return emc1403_set_convrate(data, clamp_val(val, 0, 100000)); |
| 514 |
default: |
| 515 |
return -EOPNOTSUPP; |
| 516 |
} |
| 517 |
} |
| 518 |
|
| 519 |
static int emc1403_write(struct device *dev, enum hwmon_sensor_types type, |
| 520 |
u32 attr, int channel, long val) |
| 521 |
{ |
| 522 |
struct thermal_data *data = dev_get_drvdata(dev); |
| 523 |
|
| 524 |
switch (type) { |
| 525 |
case hwmon_temp: |
| 526 |
return emc1403_temp_write(data, attr, channel, val); |
| 527 |
case hwmon_chip: |
| 528 |
return emc1403_chip_write(data, attr, val); |
| 529 |
default: |
| 530 |
return -EOPNOTSUPP; |
| 531 |
} |
| 532 |
} |
| 533 |
|
| 534 |
static umode_t emc1403_temp_is_visible(const void *_data, u32 attr, int channel) |
| 535 |
{ |
| 536 |
const struct thermal_data *data = _data; |
| 537 |
|
| 538 |
if (data->chip == emc1402 && channel > 1) |
| 539 |
return 0; |
| 540 |
if (data->chip == emc1403 && channel > 2) |
| 541 |
return 0; |
| 542 |
if (data->chip != emc1428 && channel > 3) |
| 543 |
return 0; |
| 544 |
|
| 545 |
switch (attr) { |
| 546 |
case hwmon_temp_input: |
| 547 |
case hwmon_temp_min_alarm: |
| 548 |
case hwmon_temp_max_alarm: |
| 549 |
case hwmon_temp_crit_alarm: |
| 550 |
case hwmon_temp_fault: |
| 551 |
case hwmon_temp_min_hyst: |
| 552 |
case hwmon_temp_max_hyst: |
| 553 |
return 0444; |
| 554 |
case hwmon_temp_min: |
| 555 |
case hwmon_temp_max: |
| 556 |
case hwmon_temp_crit: |
| 557 |
return 0644; |
| 558 |
case hwmon_temp_crit_hyst: |
| 559 |
if (channel == 0) |
| 560 |
return 0644; |
| 561 |
return 0444; |
| 562 |
default: |
| 563 |
return 0; |
| 564 |
} |
| 565 |
} |
| 566 |
|
| 567 |
static umode_t emc1403_chip_is_visible(const void *_data, u32 attr) |
| 568 |
{ |
| 569 |
switch (attr) { |
| 570 |
case hwmon_chip_update_interval: |
| 571 |
return 0644; |
| 572 |
default: |
| 573 |
return 0; |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
static umode_t emc1403_is_visible(const void *data, enum hwmon_sensor_types type, |
| 578 |
u32 attr, int channel) |
| 579 |
{ |
| 580 |
switch (type) { |
| 581 |
case hwmon_temp: |
| 582 |
return emc1403_temp_is_visible(data, attr, channel); |
| 583 |
case hwmon_chip: |
| 584 |
return emc1403_chip_is_visible(data, attr); |
| 585 |
default: |
| 586 |
return 0; |
| 587 |
} |
| 588 |
} |
| 589 |
|
| 590 |
static const struct hwmon_channel_info * const emc1403_info[] = { |
| 591 |
HWMON_CHANNEL_INFO(chip, HWMON_C_UPDATE_INTERVAL), |
| 592 |
HWMON_CHANNEL_INFO(temp, |
| 593 |
HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | |
| 594 |
HWMON_T_CRIT | HWMON_T_MIN_HYST | HWMON_T_MAX_HYST | |
| 595 |
HWMON_T_CRIT_HYST | HWMON_T_MIN_ALARM | |
| 596 |
HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM, |
| 597 |
HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | |
| 598 |
HWMON_T_CRIT | HWMON_T_MIN_HYST | HWMON_T_MAX_HYST | |
| 599 |
HWMON_T_CRIT_HYST | HWMON_T_MIN_ALARM | |
| 600 |
HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM | HWMON_T_FAULT, |
| 601 |
HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | |
| 602 |
HWMON_T_CRIT | HWMON_T_MIN_HYST | HWMON_T_MAX_HYST | |
| 603 |
HWMON_T_CRIT_HYST | HWMON_T_MIN_ALARM | |
| 604 |
HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM | HWMON_T_FAULT, |
| 605 |
HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | |
| 606 |
HWMON_T_CRIT | HWMON_T_MIN_HYST | HWMON_T_MAX_HYST | |
| 607 |
HWMON_T_CRIT_HYST | HWMON_T_MIN_ALARM | |
| 608 |
HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM | HWMON_T_FAULT, |
| 609 |
HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | |
| 610 |
HWMON_T_CRIT | HWMON_T_MIN_HYST | HWMON_T_MAX_HYST | |
| 611 |
HWMON_T_CRIT_HYST | HWMON_T_MIN_ALARM | |
| 612 |
HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM | HWMON_T_FAULT, |
| 613 |
HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | |
| 614 |
HWMON_T_CRIT | HWMON_T_MIN_HYST | HWMON_T_MAX_HYST | |
| 615 |
HWMON_T_CRIT_HYST | HWMON_T_MIN_ALARM | |
| 616 |
HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM | HWMON_T_FAULT, |
| 617 |
HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | |
| 618 |
HWMON_T_CRIT | HWMON_T_MIN_HYST | HWMON_T_MAX_HYST | |
| 619 |
HWMON_T_CRIT_HYST | HWMON_T_MIN_ALARM | |
| 620 |
HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM | HWMON_T_FAULT, |
| 621 |
HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | |
| 622 |
HWMON_T_CRIT | HWMON_T_MIN_HYST | HWMON_T_MAX_HYST | |
| 623 |
HWMON_T_CRIT_HYST | HWMON_T_MIN_ALARM | |
| 624 |
HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM | HWMON_T_FAULT |
| 625 |
), |
| 626 |
NULL |
| 627 |
}; |
| 628 |
|
| 629 |
static const struct hwmon_ops emc1403_hwmon_ops = { |
| 630 |
.is_visible = emc1403_is_visible, |
| 631 |
.read = emc1403_read, |
| 632 |
.write = emc1403_write, |
| 633 |
}; |
| 634 |
|
| 635 |
static const struct hwmon_chip_info emc1403_chip_info = { |
| 636 |
.ops = &emc1403_hwmon_ops, |
| 637 |
.info = emc1403_info, |
| 638 |
}; |
| 639 |
|
| 640 |
/* Last digit of chip name indicates number of channels */ |
| 641 |
static const struct i2c_device_id emc1403_idtable[] = { |
| 642 |
{ "emc1402", emc1402 }, |
| 643 |
{ "emc1403", emc1403 }, |
| 644 |
{ "emc1404", emc1404 }, |
| 645 |
{ "emc1412", emc1402 }, |
| 646 |
{ "emc1413", emc1403 }, |
| 647 |
{ "emc1414", emc1404 }, |
| 648 |
{ "emc1422", emc1402 }, |
| 649 |
{ "emc1423", emc1403 }, |
| 650 |
{ "emc1424", emc1404 }, |
| 651 |
{ "emc1428", emc1428 }, |
| 652 |
{ "emc1438", emc1428 }, |
| 653 |
{ "emc1442", emc1402 }, |
| 654 |
{ } |
| 655 |
}; |
| 656 |
MODULE_DEVICE_TABLE(i2c, emc1403_idtable); |
| 657 |
|
| 658 |
static int emc1403_probe(struct i2c_client *client) |
| 659 |
{ |
| 660 |
struct thermal_data *data; |
| 661 |
struct device *hwmon_dev; |
| 662 |
const struct i2c_device_id *id = i2c_match_id(emc1403_idtable, client); |
| 663 |
|
| 664 |
data = devm_kzalloc(&client->dev, sizeof(struct thermal_data), |
| 665 |
GFP_KERNEL); |
| 666 |
if (!data) |
| 667 |
return -ENOMEM; |
| 668 |
|
| 669 |
data->chip = id->driver_data; |
| 670 |
data->regmap = devm_regmap_init_i2c(client, &emc1403_regmap_config); |
| 671 |
if (IS_ERR(data->regmap)) |
| 672 |
return PTR_ERR(data->regmap); |
| 673 |
|
| 674 |
hwmon_dev = devm_hwmon_device_register_with_info(&client->dev, |
| 675 |
client->name, data, |
| 676 |
&emc1403_chip_info, |
| 677 |
emc1403_groups); |
| 678 |
return PTR_ERR_OR_ZERO(hwmon_dev); |
| 679 |
} |
| 680 |
|
| 681 |
static const unsigned short emc1403_address_list[] = { |
| 682 |
0x18, 0x1c, 0x29, 0x3c, 0x4c, 0x4d, 0x5c, I2C_CLIENT_END |
| 683 |
}; |
| 684 |
|
| 685 |
static struct i2c_driver sensor_emc1403 = { |
| 686 |
.class = I2C_CLASS_HWMON, |
| 687 |
.driver = { |
| 688 |
.name = "emc1403", |
| 689 |
}, |
| 690 |
.detect = emc1403_detect, |
| 691 |
.probe = emc1403_probe, |
| 692 |
.id_table = emc1403_idtable, |
| 693 |
.address_list = emc1403_address_list, |
| 694 |
}; |
| 695 |
|
| 696 |
module_i2c_driver(sensor_emc1403); |
| 697 |
|
| 698 |
MODULE_AUTHOR("Kalhan Trisal <[email protected]"); |
| 699 |
MODULE_DESCRIPTION("emc1403 Thermal Driver"); |
| 700 |
MODULE_LICENSE("GPL v2"); |