Blame view
drivers/hwmon/nct7904.c
30.9 KB
c942fddf8 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
9c947d25c hwmon: Add Nuvoto... |
2 3 4 5 6 |
/* * nct7904.c - driver for Nuvoton NCT7904D. * * Copyright (c) 2015 Kontron * Author: Vadim V. Vlasov <vvlasov@dev.rtsoft.ru> |
b67b73561 hwmon: (nct7904) ... |
7 8 9 |
* * Copyright (c) 2019 Advantech * Author: Amy.Shih <amy.shih@advantech.com.tw> |
02fc3c7cc hwmon: (nct7904) ... |
10 |
* |
77849a552 hwmon: (nct7904) ... |
11 12 13 |
* Copyright (c) 2020 Advantech * Author: Yuechao Zhao <yuechao.zhao@advantech.com.cn> * |
02fc3c7cc hwmon: (nct7904) ... |
14 15 16 17 |
* Supports the following chips: * * Chip #vin #fan #pwm #temp #dts chip ID * nct7904d 20 12 4 5 8 0xc5 |
9c947d25c hwmon: Add Nuvoto... |
18 19 20 21 22 23 24 25 |
*/ #include <linux/module.h> #include <linux/device.h> #include <linux/init.h> #include <linux/i2c.h> #include <linux/mutex.h> #include <linux/hwmon.h> |
77849a552 hwmon: (nct7904) ... |
26 |
#include <linux/watchdog.h> |
9c947d25c hwmon: Add Nuvoto... |
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
#define VENDOR_ID_REG 0x7A /* Any bank */ #define NUVOTON_ID 0x50 #define CHIP_ID_REG 0x7B /* Any bank */ #define NCT7904_ID 0xC5 #define DEVICE_ID_REG 0x7C /* Any bank */ #define BANK_SEL_REG 0xFF #define BANK_0 0x00 #define BANK_1 0x01 #define BANK_2 0x02 #define BANK_3 0x03 #define BANK_4 0x04 #define BANK_MAX 0x04 #define FANIN_MAX 12 /* Counted from 1 */ #define VSEN_MAX 21 /* VSEN1..14, 3VDD, VBAT, V3VSB, LTD (not a voltage), VSEN17..19 */ #define FANCTL_MAX 4 /* Counted from 1 */ #define TCPU_MAX 8 /* Counted from 1 */ #define TEMP_MAX 4 /* Counted from 1 */ |
6d44e43f2 hwmon: (nct7904) ... |
48 |
#define SMI_STS_MAX 10 /* Counted from 1 */ |
9c947d25c hwmon: Add Nuvoto... |
49 50 51 52 53 54 55 56 57 |
#define VT_ADC_CTRL0_REG 0x20 /* Bank 0 */ #define VT_ADC_CTRL1_REG 0x21 /* Bank 0 */ #define VT_ADC_CTRL2_REG 0x22 /* Bank 0 */ #define FANIN_CTRL0_REG 0x24 #define FANIN_CTRL1_REG 0x25 #define DTS_T_CTRL0_REG 0x26 #define DTS_T_CTRL1_REG 0x27 #define VT_ADC_MD_REG 0x2E |
486842db3 hwmon: (nct7904) ... |
58 59 60 61 62 |
#define VSEN1_HV_LL_REG 0x02 /* Bank 1; 2 regs (HV/LV) per sensor */ #define VSEN1_LV_LL_REG 0x03 /* Bank 1; 2 regs (HV/LV) per sensor */ #define VSEN1_HV_HL_REG 0x00 /* Bank 1; 2 regs (HV/LV) per sensor */ #define VSEN1_LV_HL_REG 0x01 /* Bank 1; 2 regs (HV/LV) per sensor */ #define SMI_STS1_REG 0xC1 /* Bank 0; SMI Status Register */ |
3b710d7ae hwmon: (nct7904) ... |
63 |
#define SMI_STS3_REG 0xC3 /* Bank 0; SMI Status Register */ |
486842db3 hwmon: (nct7904) ... |
64 65 66 |
#define SMI_STS5_REG 0xC5 /* Bank 0; SMI Status Register */ #define SMI_STS7_REG 0xC7 /* Bank 0; SMI Status Register */ #define SMI_STS8_REG 0xC8 /* Bank 0; SMI Status Register */ |
9c947d25c hwmon: Add Nuvoto... |
67 68 69 |
#define VSEN1_HV_REG 0x40 /* Bank 0; 2 regs (HV/LV) per sensor */ #define TEMP_CH1_HV_REG 0x42 /* Bank 0; same as VSEN2_HV */ #define LTD_HV_REG 0x62 /* Bank 0; 2 regs in VSEN range */ |
486842db3 hwmon: (nct7904) ... |
70 71 72 73 74 75 76 77 78 79 80 81 |
#define LTD_HV_HL_REG 0x44 /* Bank 1; 1 reg for LTD */ #define LTD_LV_HL_REG 0x45 /* Bank 1; 1 reg for LTD */ #define LTD_HV_LL_REG 0x46 /* Bank 1; 1 reg for LTD */ #define LTD_LV_LL_REG 0x47 /* Bank 1; 1 reg for LTD */ #define TEMP_CH1_CH_REG 0x05 /* Bank 1; 1 reg for LTD */ #define TEMP_CH1_W_REG 0x06 /* Bank 1; 1 reg for LTD */ #define TEMP_CH1_WH_REG 0x07 /* Bank 1; 1 reg for LTD */ #define TEMP_CH1_C_REG 0x04 /* Bank 1; 1 reg per sensor */ #define DTS_T_CPU1_C_REG 0x90 /* Bank 1; 1 reg per sensor */ #define DTS_T_CPU1_CH_REG 0x91 /* Bank 1; 1 reg per sensor */ #define DTS_T_CPU1_W_REG 0x92 /* Bank 1; 1 reg per sensor */ #define DTS_T_CPU1_WH_REG 0x93 /* Bank 1; 1 reg per sensor */ |
9c947d25c hwmon: Add Nuvoto... |
82 |
#define FANIN1_HV_REG 0x80 /* Bank 0; 2 regs (HV/LV) per sensor */ |
486842db3 hwmon: (nct7904) ... |
83 84 |
#define FANIN1_HV_HL_REG 0x60 /* Bank 1; 2 regs (HV/LV) per sensor */ #define FANIN1_LV_HL_REG 0x61 /* Bank 1; 2 regs (HV/LV) per sensor */ |
9c947d25c hwmon: Add Nuvoto... |
85 86 87 |
#define T_CPU1_HV_REG 0xA0 /* Bank 0; 2 regs (HV/LV) per sensor */ #define PRTS_REG 0x03 /* Bank 2 */ |
b67b73561 hwmon: (nct7904) ... |
88 89 |
#define PFE_REG 0x00 /* Bank 2; PECI Function Enable */ #define TSI_CTRL_REG 0x50 /* Bank 2; TSI Control Register */ |
9c947d25c hwmon: Add Nuvoto... |
90 91 |
#define FANCTL1_FMR_REG 0x00 /* Bank 3; 1 reg per channel */ #define FANCTL1_OUT_REG 0x10 /* Bank 3; 1 reg per channel */ |
77849a552 hwmon: (nct7904) ... |
92 93 94 95 96 97 |
#define WDT_LOCK_REG 0xE0 /* W/O Lock Watchdog Register */ #define WDT_EN_REG 0xE1 /* R/O Watchdog Enable Register */ #define WDT_STS_REG 0xE2 /* R/O Watchdog Status Register */ #define WDT_TIMER_REG 0xE3 /* R/W Watchdog Timer Register */ #define WDT_SOFT_EN 0x55 /* Enable soft watchdog timer */ #define WDT_SOFT_DIS 0xAA /* Disable soft watchdog timer */ |
6fc28b7e0 hwmon: (nct7904) ... |
98 99 100 |
#define VOLT_MONITOR_MODE 0x0 #define THERMAL_DIODE_MODE 0x1 #define THERMISTOR_MODE 0x3 |
486842db3 hwmon: (nct7904) ... |
101 |
#define ENABLE_TSI BIT(1) |
77849a552 hwmon: (nct7904) ... |
102 103 104 105 106 |
#define WATCHDOG_TIMEOUT 1 /* 1 minute default timeout */ /*The timeout range is 1-255 minutes*/ #define MIN_TIMEOUT (1 * 60) #define MAX_TIMEOUT (255 * 60) |
156ad7f9e hwmon: (nct7904) ... |
107 |
static int timeout; |
77849a552 hwmon: (nct7904) ... |
108 109 |
module_param(timeout, int, 0); MODULE_PARM_DESC(timeout, "Watchdog timeout in minutes. 1 <= timeout <= 255, default=" |
156ad7f9e hwmon: (nct7904) ... |
110 |
__MODULE_STRING(WATCHDOG_TIMEOUT) "."); |
77849a552 hwmon: (nct7904) ... |
111 112 113 |
static bool nowayout = WATCHDOG_NOWAYOUT; module_param(nowayout, bool, 0); |
156ad7f9e hwmon: (nct7904) ... |
114 |
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" |
77849a552 hwmon: (nct7904) ... |
115 |
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
9c947d25c hwmon: Add Nuvoto... |
116 117 118 119 120 121 |
static const unsigned short normal_i2c[] = { 0x2d, 0x2e, I2C_CLIENT_END }; struct nct7904_data { struct i2c_client *client; |
77849a552 hwmon: (nct7904) ... |
122 |
struct watchdog_device wdt; |
9c947d25c hwmon: Add Nuvoto... |
123 124 125 126 127 128 |
struct mutex bank_lock; int bank_sel; u32 fanin_mask; u32 vsen_mask; u32 tcpu_mask; u8 fan_mode[FANCTL_MAX]; |
b67b73561 hwmon: (nct7904) ... |
129 130 |
u8 enable_dts; u8 has_dts; |
486842db3 hwmon: (nct7904) ... |
131 |
u8 temp_mode; /* 0: TR mode, 1: TD mode */ |
6bbfdcbc8 hwmon: (nct7904) ... |
132 133 |
u8 fan_alarm[2]; u8 vsen_alarm[3]; |
9c947d25c hwmon: Add Nuvoto... |
134 135 136 |
}; /* Access functions */ |
73ed6e22c hwmon: (nct7904) ... |
137 |
static int nct7904_bank_lock(struct nct7904_data *data, unsigned int bank) |
9c947d25c hwmon: Add Nuvoto... |
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
{ int ret; mutex_lock(&data->bank_lock); if (data->bank_sel == bank) return 0; ret = i2c_smbus_write_byte_data(data->client, BANK_SEL_REG, bank); if (ret == 0) data->bank_sel = bank; else data->bank_sel = -1; return ret; } static inline void nct7904_bank_release(struct nct7904_data *data) { mutex_unlock(&data->bank_lock); } /* Read 1-byte register. Returns unsigned reg or -ERRNO on error. */ static int nct7904_read_reg(struct nct7904_data *data, |
73ed6e22c hwmon: (nct7904) ... |
159 |
unsigned int bank, unsigned int reg) |
9c947d25c hwmon: Add Nuvoto... |
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
{ struct i2c_client *client = data->client; int ret; ret = nct7904_bank_lock(data, bank); if (ret == 0) ret = i2c_smbus_read_byte_data(client, reg); nct7904_bank_release(data); return ret; } /* * Read 2-byte register. Returns register in big-endian format or * -ERRNO on error. */ static int nct7904_read_reg16(struct nct7904_data *data, |
73ed6e22c hwmon: (nct7904) ... |
177 |
unsigned int bank, unsigned int reg) |
9c947d25c hwmon: Add Nuvoto... |
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
{ struct i2c_client *client = data->client; int ret, hi; ret = nct7904_bank_lock(data, bank); if (ret == 0) { ret = i2c_smbus_read_byte_data(client, reg); if (ret >= 0) { hi = ret; ret = i2c_smbus_read_byte_data(client, reg + 1); if (ret >= 0) ret |= hi << 8; } } nct7904_bank_release(data); return ret; } /* Write 1-byte register. Returns 0 or -ERRNO on error. */ static int nct7904_write_reg(struct nct7904_data *data, |
73ed6e22c hwmon: (nct7904) ... |
199 |
unsigned int bank, unsigned int reg, u8 val) |
9c947d25c hwmon: Add Nuvoto... |
200 201 202 203 204 205 206 207 208 209 210 |
{ struct i2c_client *client = data->client; int ret; ret = nct7904_bank_lock(data, bank); if (ret == 0) ret = i2c_smbus_write_byte_data(client, reg, val); nct7904_bank_release(data); return ret; } |
d65a5102a hwmon: (nct7904) ... |
211 212 |
static int nct7904_read_fan(struct device *dev, u32 attr, int channel, long *val) |
9c947d25c hwmon: Add Nuvoto... |
213 |
{ |
9c947d25c hwmon: Add Nuvoto... |
214 |
struct nct7904_data *data = dev_get_drvdata(dev); |
d65a5102a hwmon: (nct7904) ... |
215 |
unsigned int cnt, rpm; |
9c947d25c hwmon: Add Nuvoto... |
216 |
int ret; |
9c947d25c hwmon: Add Nuvoto... |
217 |
|
ec1460ef7 hwmon: (nct7904) ... |
218 |
switch (attr) { |
d65a5102a hwmon: (nct7904) ... |
219 220 221 222 223 224 |
case hwmon_fan_input: ret = nct7904_read_reg16(data, BANK_0, FANIN1_HV_REG + channel * 2); if (ret < 0) return ret; cnt = ((ret & 0xff00) >> 3) | (ret & 0x1f); |
8aebbbb2d hwmon: (nct7904) ... |
225 |
if (cnt == 0 || cnt == 0x1fff) |
d65a5102a hwmon: (nct7904) ... |
226 227 228 229 230 |
rpm = 0; else rpm = 1350000 / cnt; *val = rpm; return 0; |
486842db3 hwmon: (nct7904) ... |
231 232 233 234 235 236 |
case hwmon_fan_min: ret = nct7904_read_reg16(data, BANK_1, FANIN1_HV_HL_REG + channel * 2); if (ret < 0) return ret; cnt = ((ret & 0xff00) >> 3) | (ret & 0x1f); |
8aebbbb2d hwmon: (nct7904) ... |
237 |
if (cnt == 0 || cnt == 0x1fff) |
486842db3 hwmon: (nct7904) ... |
238 239 240 241 242 243 244 |
rpm = 0; else rpm = 1350000 / cnt; *val = rpm; return 0; case hwmon_fan_alarm: ret = nct7904_read_reg(data, BANK_0, |
3b710d7ae hwmon: (nct7904) ... |
245 |
SMI_STS5_REG + (channel >> 3)); |
486842db3 hwmon: (nct7904) ... |
246 247 |
if (ret < 0) return ret; |
6bbfdcbc8 hwmon: (nct7904) ... |
248 249 250 251 252 253 254 255 256 |
if (!data->fan_alarm[channel >> 3]) data->fan_alarm[channel >> 3] = ret & 0xff; else /* If there is new alarm showing up */ data->fan_alarm[channel >> 3] |= (ret & 0xff); *val = (data->fan_alarm[channel >> 3] >> (channel & 0x07)) & 1; /* Needs to clean the alarm if alarm existing */ if (*val) data->fan_alarm[channel >> 3] ^= 1 << (channel & 0x07); |
486842db3 hwmon: (nct7904) ... |
257 |
return 0; |
d65a5102a hwmon: (nct7904) ... |
258 259 260 |
default: return -EOPNOTSUPP; } |
9c947d25c hwmon: Add Nuvoto... |
261 |
} |
d65a5102a hwmon: (nct7904) ... |
262 |
static umode_t nct7904_fan_is_visible(const void *_data, u32 attr, int channel) |
9c947d25c hwmon: Add Nuvoto... |
263 |
{ |
d65a5102a hwmon: (nct7904) ... |
264 |
const struct nct7904_data *data = _data; |
9c947d25c hwmon: Add Nuvoto... |
265 |
|
486842db3 hwmon: (nct7904) ... |
266 267 268 269 270 271 272 273 274 275 276 277 278 |
switch (attr) { case hwmon_fan_input: case hwmon_fan_alarm: if (data->fanin_mask & (1 << channel)) return 0444; break; case hwmon_fan_min: if (data->fanin_mask & (1 << channel)) return 0644; break; default: break; } |
9c947d25c hwmon: Add Nuvoto... |
279 280 |
return 0; } |
d65a5102a hwmon: (nct7904) ... |
281 282 283 284 |
static u8 nct7904_chan_to_index[] = { 0, /* Not used */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18, 19, 20, 16 |
9c947d25c hwmon: Add Nuvoto... |
285 |
}; |
d65a5102a hwmon: (nct7904) ... |
286 287 |
static int nct7904_read_in(struct device *dev, u32 attr, int channel, long *val) |
9c947d25c hwmon: Add Nuvoto... |
288 |
{ |
9c947d25c hwmon: Add Nuvoto... |
289 |
struct nct7904_data *data = dev_get_drvdata(dev); |
d65a5102a hwmon: (nct7904) ... |
290 |
int ret, volt, index; |
9c947d25c hwmon: Add Nuvoto... |
291 |
|
d65a5102a hwmon: (nct7904) ... |
292 |
index = nct7904_chan_to_index[channel]; |
9c947d25c hwmon: Add Nuvoto... |
293 |
|
ec1460ef7 hwmon: (nct7904) ... |
294 |
switch (attr) { |
d65a5102a hwmon: (nct7904) ... |
295 296 297 298 299 300 301 302 303 304 305 306 |
case hwmon_in_input: ret = nct7904_read_reg16(data, BANK_0, VSEN1_HV_REG + index * 2); if (ret < 0) return ret; volt = ((ret & 0xff00) >> 5) | (ret & 0x7); if (index < 14) volt *= 2; /* 0.002V scale */ else volt *= 6; /* 0.006V scale */ *val = volt; return 0; |
486842db3 hwmon: (nct7904) ... |
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
case hwmon_in_min: ret = nct7904_read_reg16(data, BANK_1, VSEN1_HV_LL_REG + index * 4); if (ret < 0) return ret; volt = ((ret & 0xff00) >> 5) | (ret & 0x7); if (index < 14) volt *= 2; /* 0.002V scale */ else volt *= 6; /* 0.006V scale */ *val = volt; return 0; case hwmon_in_max: ret = nct7904_read_reg16(data, BANK_1, VSEN1_HV_HL_REG + index * 4); if (ret < 0) return ret; volt = ((ret & 0xff00) >> 5) | (ret & 0x7); if (index < 14) volt *= 2; /* 0.002V scale */ else volt *= 6; /* 0.006V scale */ *val = volt; return 0; case hwmon_in_alarm: ret = nct7904_read_reg(data, BANK_0, SMI_STS1_REG + (index >> 3)); if (ret < 0) return ret; |
6bbfdcbc8 hwmon: (nct7904) ... |
336 337 338 339 340 341 342 343 344 |
if (!data->vsen_alarm[index >> 3]) data->vsen_alarm[index >> 3] = ret & 0xff; else /* If there is new alarm showing up */ data->vsen_alarm[index >> 3] |= (ret & 0xff); *val = (data->vsen_alarm[index >> 3] >> (index & 0x07)) & 1; /* Needs to clean the alarm if alarm existing */ if (*val) data->vsen_alarm[index >> 3] ^= 1 << (index & 0x07); |
486842db3 hwmon: (nct7904) ... |
345 |
return 0; |
d65a5102a hwmon: (nct7904) ... |
346 347 348 |
default: return -EOPNOTSUPP; } |
9c947d25c hwmon: Add Nuvoto... |
349 |
} |
d65a5102a hwmon: (nct7904) ... |
350 |
static umode_t nct7904_in_is_visible(const void *_data, u32 attr, int channel) |
9c947d25c hwmon: Add Nuvoto... |
351 |
{ |
d65a5102a hwmon: (nct7904) ... |
352 353 |
const struct nct7904_data *data = _data; int index = nct7904_chan_to_index[channel]; |
9c947d25c hwmon: Add Nuvoto... |
354 |
|
486842db3 hwmon: (nct7904) ... |
355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
switch (attr) { case hwmon_in_input: case hwmon_in_alarm: if (channel > 0 && (data->vsen_mask & BIT(index))) return 0444; break; case hwmon_in_min: case hwmon_in_max: if (channel > 0 && (data->vsen_mask & BIT(index))) return 0644; break; default: break; } |
9c947d25c hwmon: Add Nuvoto... |
369 |
|
9c947d25c hwmon: Add Nuvoto... |
370 371 |
return 0; } |
d65a5102a hwmon: (nct7904) ... |
372 373 |
static int nct7904_read_temp(struct device *dev, u32 attr, int channel, long *val) |
9c947d25c hwmon: Add Nuvoto... |
374 |
{ |
9c947d25c hwmon: Add Nuvoto... |
375 |
struct nct7904_data *data = dev_get_drvdata(dev); |
d65a5102a hwmon: (nct7904) ... |
376 |
int ret, temp; |
486842db3 hwmon: (nct7904) ... |
377 |
unsigned int reg1, reg2, reg3; |
7b2fd270a hwmon: (nct7904) ... |
378 |
s8 temps; |
d65a5102a hwmon: (nct7904) ... |
379 |
|
ec1460ef7 hwmon: (nct7904) ... |
380 |
switch (attr) { |
d65a5102a hwmon: (nct7904) ... |
381 |
case hwmon_temp_input: |
b67b73561 hwmon: (nct7904) ... |
382 |
if (channel == 4) |
d65a5102a hwmon: (nct7904) ... |
383 |
ret = nct7904_read_reg16(data, BANK_0, LTD_HV_REG); |
b67b73561 hwmon: (nct7904) ... |
384 385 386 |
else if (channel < 5) ret = nct7904_read_reg16(data, BANK_0, TEMP_CH1_HV_REG + channel * 4); |
d65a5102a hwmon: (nct7904) ... |
387 388 |
else ret = nct7904_read_reg16(data, BANK_0, |
b67b73561 hwmon: (nct7904) ... |
389 390 |
T_CPU1_HV_REG + (channel - 5) * 2); |
d65a5102a hwmon: (nct7904) ... |
391 392 393 394 395 |
if (ret < 0) return ret; temp = ((ret & 0xff00) >> 5) | (ret & 0x7); *val = sign_extend32(temp, 10) * 125; return 0; |
486842db3 hwmon: (nct7904) ... |
396 |
case hwmon_temp_alarm: |
3b710d7ae hwmon: (nct7904) ... |
397 398 399 400 401 402 403 |
if (channel == 4) { ret = nct7904_read_reg(data, BANK_0, SMI_STS3_REG); if (ret < 0) return ret; *val = (ret >> 1) & 1; } else if (channel < 4) { |
486842db3 hwmon: (nct7904) ... |
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
ret = nct7904_read_reg(data, BANK_0, SMI_STS1_REG); if (ret < 0) return ret; *val = (ret >> (((channel * 2) + 1) & 0x07)) & 1; } else { if ((channel - 5) < 4) { ret = nct7904_read_reg(data, BANK_0, SMI_STS7_REG + ((channel - 5) >> 3)); if (ret < 0) return ret; *val = (ret >> ((channel - 5) & 0x07)) & 1; } else { ret = nct7904_read_reg(data, BANK_0, SMI_STS8_REG + ((channel - 5) >> 3)); if (ret < 0) return ret; *val = (ret >> (((channel - 5) & 0x07) - 4)) & 1; } } return 0; case hwmon_temp_type: if (channel < 5) { if ((data->tcpu_mask >> channel) & 0x01) { if ((data->temp_mode >> channel) & 0x01) *val = 3; /* TD */ else *val = 4; /* TR */ } else { *val = 0; } } else { if ((data->has_dts >> (channel - 5)) & 0x01) { if (data->enable_dts & ENABLE_TSI) *val = 5; /* TSI */ else *val = 6; /* PECI */ } else { *val = 0; } } return 0; case hwmon_temp_max: |
4a2d78822 hwmon: (nct7904) ... |
450 |
reg1 = LTD_HV_LL_REG; |
486842db3 hwmon: (nct7904) ... |
451 452 453 454 |
reg2 = TEMP_CH1_W_REG; reg3 = DTS_T_CPU1_W_REG; break; case hwmon_temp_max_hyst: |
4a2d78822 hwmon: (nct7904) ... |
455 |
reg1 = LTD_LV_LL_REG; |
486842db3 hwmon: (nct7904) ... |
456 457 458 459 |
reg2 = TEMP_CH1_WH_REG; reg3 = DTS_T_CPU1_WH_REG; break; case hwmon_temp_crit: |
4a2d78822 hwmon: (nct7904) ... |
460 |
reg1 = LTD_HV_HL_REG; |
486842db3 hwmon: (nct7904) ... |
461 462 463 464 |
reg2 = TEMP_CH1_C_REG; reg3 = DTS_T_CPU1_C_REG; break; case hwmon_temp_crit_hyst: |
4a2d78822 hwmon: (nct7904) ... |
465 |
reg1 = LTD_LV_HL_REG; |
486842db3 hwmon: (nct7904) ... |
466 467 468 |
reg2 = TEMP_CH1_CH_REG; reg3 = DTS_T_CPU1_CH_REG; break; |
d65a5102a hwmon: (nct7904) ... |
469 470 471 |
default: return -EOPNOTSUPP; } |
486842db3 hwmon: (nct7904) ... |
472 473 474 475 476 477 478 479 480 481 482 483 |
if (channel == 4) ret = nct7904_read_reg(data, BANK_1, reg1); else if (channel < 5) ret = nct7904_read_reg(data, BANK_1, reg2 + channel * 8); else ret = nct7904_read_reg(data, BANK_1, reg3 + (channel - 5) * 4); if (ret < 0) return ret; |
7b2fd270a hwmon: (nct7904) ... |
484 485 |
temps = ret; *val = temps * 1000; |
486842db3 hwmon: (nct7904) ... |
486 |
return 0; |
9c947d25c hwmon: Add Nuvoto... |
487 |
} |
d65a5102a hwmon: (nct7904) ... |
488 |
static umode_t nct7904_temp_is_visible(const void *_data, u32 attr, int channel) |
9c947d25c hwmon: Add Nuvoto... |
489 |
{ |
d65a5102a hwmon: (nct7904) ... |
490 |
const struct nct7904_data *data = _data; |
486842db3 hwmon: (nct7904) ... |
491 492 493 494 |
switch (attr) { case hwmon_temp_input: case hwmon_temp_alarm: case hwmon_temp_type: |
b67b73561 hwmon: (nct7904) ... |
495 496 |
if (channel < 5) { if (data->tcpu_mask & BIT(channel)) |
e590be4ab hwmon: (nct7904) ... |
497 |
return 0444; |
d65a5102a hwmon: (nct7904) ... |
498 |
} else { |
b67b73561 hwmon: (nct7904) ... |
499 |
if (data->has_dts & BIT(channel - 5)) |
e590be4ab hwmon: (nct7904) ... |
500 |
return 0444; |
d65a5102a hwmon: (nct7904) ... |
501 |
} |
486842db3 hwmon: (nct7904) ... |
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
break; case hwmon_temp_max: case hwmon_temp_max_hyst: case hwmon_temp_crit: case hwmon_temp_crit_hyst: if (channel < 5) { if (data->tcpu_mask & BIT(channel)) return 0644; } else { if (data->has_dts & BIT(channel - 5)) return 0644; } break; default: break; |
d65a5102a hwmon: (nct7904) ... |
517 |
} |
9c947d25c hwmon: Add Nuvoto... |
518 |
|
9c947d25c hwmon: Add Nuvoto... |
519 520 |
return 0; } |
d65a5102a hwmon: (nct7904) ... |
521 522 |
static int nct7904_read_pwm(struct device *dev, u32 attr, int channel, long *val) |
9c947d25c hwmon: Add Nuvoto... |
523 |
{ |
9c947d25c hwmon: Add Nuvoto... |
524 |
struct nct7904_data *data = dev_get_drvdata(dev); |
9c947d25c hwmon: Add Nuvoto... |
525 |
int ret; |
ec1460ef7 hwmon: (nct7904) ... |
526 |
switch (attr) { |
d65a5102a hwmon: (nct7904) ... |
527 528 529 530 531 532 533 534 535 536 |
case hwmon_pwm_input: ret = nct7904_read_reg(data, BANK_3, FANCTL1_OUT_REG + channel); if (ret < 0) return ret; *val = ret; return 0; case hwmon_pwm_enable: ret = nct7904_read_reg(data, BANK_3, FANCTL1_FMR_REG + channel); if (ret < 0) return ret; |
9c947d25c hwmon: Add Nuvoto... |
537 |
|
d65a5102a hwmon: (nct7904) ... |
538 539 540 541 542 |
*val = ret ? 2 : 1; return 0; default: return -EOPNOTSUPP; } |
9c947d25c hwmon: Add Nuvoto... |
543 |
} |
486842db3 hwmon: (nct7904) ... |
544 545 546 547 548 549 550 551 552 553 554 |
static int nct7904_write_temp(struct device *dev, u32 attr, int channel, long val) { struct nct7904_data *data = dev_get_drvdata(dev); int ret; unsigned int reg1, reg2, reg3; val = clamp_val(val / 1000, -128, 127); switch (attr) { case hwmon_temp_max: |
4a2d78822 hwmon: (nct7904) ... |
555 |
reg1 = LTD_HV_LL_REG; |
486842db3 hwmon: (nct7904) ... |
556 557 558 559 |
reg2 = TEMP_CH1_W_REG; reg3 = DTS_T_CPU1_W_REG; break; case hwmon_temp_max_hyst: |
4a2d78822 hwmon: (nct7904) ... |
560 |
reg1 = LTD_LV_LL_REG; |
486842db3 hwmon: (nct7904) ... |
561 562 563 564 |
reg2 = TEMP_CH1_WH_REG; reg3 = DTS_T_CPU1_WH_REG; break; case hwmon_temp_crit: |
4a2d78822 hwmon: (nct7904) ... |
565 |
reg1 = LTD_HV_HL_REG; |
486842db3 hwmon: (nct7904) ... |
566 567 568 569 |
reg2 = TEMP_CH1_C_REG; reg3 = DTS_T_CPU1_C_REG; break; case hwmon_temp_crit_hyst: |
4a2d78822 hwmon: (nct7904) ... |
570 |
reg1 = LTD_LV_HL_REG; |
486842db3 hwmon: (nct7904) ... |
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 |
reg2 = TEMP_CH1_CH_REG; reg3 = DTS_T_CPU1_CH_REG; break; default: return -EOPNOTSUPP; } if (channel == 4) ret = nct7904_write_reg(data, BANK_1, reg1, val); else if (channel < 5) ret = nct7904_write_reg(data, BANK_1, reg2 + channel * 8, val); else ret = nct7904_write_reg(data, BANK_1, reg3 + (channel - 5) * 4, val); return ret; } static int nct7904_write_fan(struct device *dev, u32 attr, int channel, long val) { struct nct7904_data *data = dev_get_drvdata(dev); int ret; u8 tmp; switch (attr) { case hwmon_fan_min: if (val <= 0) return -EINVAL; val = clamp_val(DIV_ROUND_CLOSEST(1350000, val), 1, 0x1fff); tmp = (val >> 5) & 0xff; ret = nct7904_write_reg(data, BANK_1, FANIN1_HV_HL_REG + channel * 2, tmp); if (ret < 0) return ret; tmp = val & 0x1f; ret = nct7904_write_reg(data, BANK_1, FANIN1_LV_HL_REG + channel * 2, tmp); return ret; default: return -EOPNOTSUPP; } } static int nct7904_write_in(struct device *dev, u32 attr, int channel, long val) { struct nct7904_data *data = dev_get_drvdata(dev); int ret, index, tmp; index = nct7904_chan_to_index[channel]; if (index < 14) val = val / 2; /* 0.002V scale */ else val = val / 6; /* 0.006V scale */ val = clamp_val(val, 0, 0x7ff); switch (attr) { case hwmon_in_min: tmp = nct7904_read_reg(data, BANK_1, VSEN1_LV_LL_REG + index * 4); if (tmp < 0) return tmp; tmp &= ~0x7; tmp |= val & 0x7; ret = nct7904_write_reg(data, BANK_1, VSEN1_LV_LL_REG + index * 4, tmp); if (ret < 0) return ret; tmp = nct7904_read_reg(data, BANK_1, VSEN1_HV_LL_REG + index * 4); if (tmp < 0) return tmp; tmp = (val >> 3) & 0xff; ret = nct7904_write_reg(data, BANK_1, VSEN1_HV_LL_REG + index * 4, tmp); return ret; case hwmon_in_max: tmp = nct7904_read_reg(data, BANK_1, VSEN1_LV_HL_REG + index * 4); if (tmp < 0) return tmp; tmp &= ~0x7; tmp |= val & 0x7; ret = nct7904_write_reg(data, BANK_1, VSEN1_LV_HL_REG + index * 4, tmp); if (ret < 0) return ret; tmp = nct7904_read_reg(data, BANK_1, VSEN1_HV_HL_REG + index * 4); if (tmp < 0) return tmp; tmp = (val >> 3) & 0xff; ret = nct7904_write_reg(data, BANK_1, VSEN1_HV_HL_REG + index * 4, tmp); return ret; default: return -EOPNOTSUPP; } } |
d65a5102a hwmon: (nct7904) ... |
674 675 |
static int nct7904_write_pwm(struct device *dev, u32 attr, int channel, long val) |
9c947d25c hwmon: Add Nuvoto... |
676 |
{ |
9c947d25c hwmon: Add Nuvoto... |
677 |
struct nct7904_data *data = dev_get_drvdata(dev); |
d65a5102a hwmon: (nct7904) ... |
678 |
int ret; |
9c947d25c hwmon: Add Nuvoto... |
679 |
|
ec1460ef7 hwmon: (nct7904) ... |
680 |
switch (attr) { |
d65a5102a hwmon: (nct7904) ... |
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 |
case hwmon_pwm_input: if (val < 0 || val > 255) return -EINVAL; ret = nct7904_write_reg(data, BANK_3, FANCTL1_OUT_REG + channel, val); return ret; case hwmon_pwm_enable: if (val < 1 || val > 2 || (val == 2 && !data->fan_mode[channel])) return -EINVAL; ret = nct7904_write_reg(data, BANK_3, FANCTL1_FMR_REG + channel, val == 2 ? data->fan_mode[channel] : 0); return ret; default: return -EOPNOTSUPP; } |
9c947d25c hwmon: Add Nuvoto... |
697 |
} |
d65a5102a hwmon: (nct7904) ... |
698 |
static umode_t nct7904_pwm_is_visible(const void *_data, u32 attr, int channel) |
9c947d25c hwmon: Add Nuvoto... |
699 |
{ |
ec1460ef7 hwmon: (nct7904) ... |
700 |
switch (attr) { |
d65a5102a hwmon: (nct7904) ... |
701 702 |
case hwmon_pwm_input: case hwmon_pwm_enable: |
e590be4ab hwmon: (nct7904) ... |
703 |
return 0644; |
d65a5102a hwmon: (nct7904) ... |
704 705 706 |
default: return 0; } |
9c947d25c hwmon: Add Nuvoto... |
707 |
} |
d65a5102a hwmon: (nct7904) ... |
708 709 |
static int nct7904_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) |
9c947d25c hwmon: Add Nuvoto... |
710 |
{ |
d65a5102a hwmon: (nct7904) ... |
711 712 713 714 715 716 717 718 719 720 721 722 |
switch (type) { case hwmon_in: return nct7904_read_in(dev, attr, channel, val); case hwmon_fan: return nct7904_read_fan(dev, attr, channel, val); case hwmon_pwm: return nct7904_read_pwm(dev, attr, channel, val); case hwmon_temp: return nct7904_read_temp(dev, attr, channel, val); default: return -EOPNOTSUPP; } |
9c947d25c hwmon: Add Nuvoto... |
723 |
} |
d65a5102a hwmon: (nct7904) ... |
724 725 726 727 |
static int nct7904_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long val) { switch (type) { |
486842db3 hwmon: (nct7904) ... |
728 729 730 731 |
case hwmon_in: return nct7904_write_in(dev, attr, channel, val); case hwmon_fan: return nct7904_write_fan(dev, attr, channel, val); |
d65a5102a hwmon: (nct7904) ... |
732 733 |
case hwmon_pwm: return nct7904_write_pwm(dev, attr, channel, val); |
486842db3 hwmon: (nct7904) ... |
734 735 |
case hwmon_temp: return nct7904_write_temp(dev, attr, channel, val); |
d65a5102a hwmon: (nct7904) ... |
736 737 738 739 |
default: return -EOPNOTSUPP; } } |
9c947d25c hwmon: Add Nuvoto... |
740 |
|
d65a5102a hwmon: (nct7904) ... |
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 |
static umode_t nct7904_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, int channel) { switch (type) { case hwmon_in: return nct7904_in_is_visible(data, attr, channel); case hwmon_fan: return nct7904_fan_is_visible(data, attr, channel); case hwmon_pwm: return nct7904_pwm_is_visible(data, attr, channel); case hwmon_temp: return nct7904_temp_is_visible(data, attr, channel); default: return 0; } } |
9c947d25c hwmon: Add Nuvoto... |
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 |
/* Return 0 if detection is successful, -ENODEV otherwise */ static int nct7904_detect(struct i2c_client *client, struct i2c_board_info *info) { struct i2c_adapter *adapter = client->adapter; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) return -ENODEV; /* Determine the chip type. */ if (i2c_smbus_read_byte_data(client, VENDOR_ID_REG) != NUVOTON_ID || i2c_smbus_read_byte_data(client, CHIP_ID_REG) != NCT7904_ID || |
6552f327c hwmon: (nct7904) ... |
773 774 |
(i2c_smbus_read_byte_data(client, DEVICE_ID_REG) & 0xf0) != 0x50 || (i2c_smbus_read_byte_data(client, BANK_SEL_REG) & 0xf8) != 0x00) |
9c947d25c hwmon: Add Nuvoto... |
775 776 777 778 779 780 |
return -ENODEV; strlcpy(info->type, "nct7904", I2C_NAME_SIZE); return 0; } |
d65a5102a hwmon: (nct7904) ... |
781 |
static const struct hwmon_channel_info *nct7904_info[] = { |
4ec1d234a hwmon: (nct7904) ... |
782 |
HWMON_CHANNEL_INFO(in, |
486842db3 hwmon: (nct7904) ... |
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 |
/* dummy, skipped in is_visible */ HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM), |
4ec1d234a hwmon: (nct7904) ... |
826 |
HWMON_CHANNEL_INFO(fan, |
486842db3 hwmon: (nct7904) ... |
827 828 829 830 831 832 833 |
HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, |
02fc3c7cc hwmon: (nct7904) ... |
834 835 836 837 |
HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, |
486842db3 hwmon: (nct7904) ... |
838 |
HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM), |
4ec1d234a hwmon: (nct7904) ... |
839 840 841 842 843 844 |
HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE, HWMON_PWM_INPUT | HWMON_PWM_ENABLE, HWMON_PWM_INPUT | HWMON_PWM_ENABLE, HWMON_PWM_INPUT | HWMON_PWM_ENABLE), HWMON_CHANNEL_INFO(temp, |
486842db3 hwmon: (nct7904) ... |
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 |
HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | |
02fc3c7cc hwmon: (nct7904) ... |
868 869 870 871 872 873 874 875 876 877 878 879 |
HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | |
486842db3 hwmon: (nct7904) ... |
880 881 882 883 |
HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | HWMON_T_CRIT_HYST), |
d65a5102a hwmon: (nct7904) ... |
884 885 886 887 888 889 890 891 892 893 894 895 896 |
NULL }; static const struct hwmon_ops nct7904_hwmon_ops = { .is_visible = nct7904_is_visible, .read = nct7904_read, .write = nct7904_write, }; static const struct hwmon_chip_info nct7904_chip_info = { .ops = &nct7904_hwmon_ops, .info = nct7904_info, }; |
77849a552 hwmon: (nct7904) ... |
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 |
/* * Watchdog Function */ static int nct7904_wdt_start(struct watchdog_device *wdt) { struct nct7904_data *data = watchdog_get_drvdata(wdt); /* Enable soft watchdog timer */ return nct7904_write_reg(data, BANK_0, WDT_LOCK_REG, WDT_SOFT_EN); } static int nct7904_wdt_stop(struct watchdog_device *wdt) { struct nct7904_data *data = watchdog_get_drvdata(wdt); return nct7904_write_reg(data, BANK_0, WDT_LOCK_REG, WDT_SOFT_DIS); } static int nct7904_wdt_set_timeout(struct watchdog_device *wdt, unsigned int timeout) { struct nct7904_data *data = watchdog_get_drvdata(wdt); /* * The NCT7904 is very special in watchdog function. * Its minimum unit is minutes. And wdt->timeout needs * to match the actual timeout selected. So, this needs * to be: wdt->timeout = timeout / 60 * 60. * For example, if the user configures a timeout of * 119 seconds, the actual timeout will be 60 seconds. * So, wdt->timeout must then be set to 60 seconds. */ wdt->timeout = timeout / 60 * 60; return nct7904_write_reg(data, BANK_0, WDT_TIMER_REG, wdt->timeout / 60); } static int nct7904_wdt_ping(struct watchdog_device *wdt) { /* * Note: * NCT7904 does not support refreshing WDT_TIMER_REG register when * the watchdog is active. Please disable watchdog before feeding * the watchdog and enable it again. */ struct nct7904_data *data = watchdog_get_drvdata(wdt); int ret; /* Disable soft watchdog timer */ ret = nct7904_write_reg(data, BANK_0, WDT_LOCK_REG, WDT_SOFT_DIS); if (ret < 0) return ret; /* feed watchdog */ ret = nct7904_write_reg(data, BANK_0, WDT_TIMER_REG, wdt->timeout / 60); if (ret < 0) return ret; /* Enable soft watchdog timer */ return nct7904_write_reg(data, BANK_0, WDT_LOCK_REG, WDT_SOFT_EN); } static unsigned int nct7904_wdt_get_timeleft(struct watchdog_device *wdt) { struct nct7904_data *data = watchdog_get_drvdata(wdt); int ret; ret = nct7904_read_reg(data, BANK_0, WDT_TIMER_REG); if (ret < 0) return 0; return ret * 60; } static const struct watchdog_info nct7904_wdt_info = { .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, .identity = "nct7904 watchdog", }; static const struct watchdog_ops nct7904_wdt_ops = { .owner = THIS_MODULE, .start = nct7904_wdt_start, .stop = nct7904_wdt_stop, .ping = nct7904_wdt_ping, .set_timeout = nct7904_wdt_set_timeout, .get_timeleft = nct7904_wdt_get_timeleft, }; |
674870385 hwmon: use simple... |
985 |
static int nct7904_probe(struct i2c_client *client) |
9c947d25c hwmon: Add Nuvoto... |
986 987 988 989 990 991 |
{ struct nct7904_data *data; struct device *hwmon_dev; struct device *dev = &client->dev; int ret, i; u32 mask; |
b67b73561 hwmon: (nct7904) ... |
992 |
u8 val, bit; |
9c947d25c hwmon: Add Nuvoto... |
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 |
data = devm_kzalloc(dev, sizeof(struct nct7904_data), GFP_KERNEL); if (!data) return -ENOMEM; data->client = client; mutex_init(&data->bank_lock); data->bank_sel = -1; /* Setup sensor groups. */ /* FANIN attributes */ ret = nct7904_read_reg16(data, BANK_0, FANIN_CTRL0_REG); if (ret < 0) return ret; data->fanin_mask = (ret >> 8) | ((ret & 0xff) << 8); /* * VSEN attributes * * Note: voltage sensors overlap with external temperature * sensors. So, if we ever decide to support the latter * we will have to adjust 'vsen_mask' accordingly. */ mask = 0; ret = nct7904_read_reg16(data, BANK_0, VT_ADC_CTRL0_REG); if (ret >= 0) mask = (ret >> 8) | ((ret & 0xff) << 8); ret = nct7904_read_reg(data, BANK_0, VT_ADC_CTRL2_REG); if (ret >= 0) mask |= (ret << 16); data->vsen_mask = mask; /* CPU_TEMP attributes */ |
b67b73561 hwmon: (nct7904) ... |
1026 |
ret = nct7904_read_reg(data, BANK_0, VT_ADC_CTRL0_REG); |
b3e260678 hwmon: (nct7904) ... |
1027 1028 |
if (ret < 0) return ret; |
b67b73561 hwmon: (nct7904) ... |
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 |
if ((ret & 0x6) == 0x6) data->tcpu_mask |= 1; /* TR1 */ if ((ret & 0x18) == 0x18) data->tcpu_mask |= 2; /* TR2 */ if ((ret & 0x20) == 0x20) data->tcpu_mask |= 4; /* TR3 */ if ((ret & 0x80) == 0x80) data->tcpu_mask |= 8; /* TR4 */ /* LTD */ ret = nct7904_read_reg(data, BANK_0, VT_ADC_CTRL2_REG); |
b3e260678 hwmon: (nct7904) ... |
1041 1042 |
if (ret < 0) return ret; |
b67b73561 hwmon: (nct7904) ... |
1043 1044 1045 1046 1047 |
if ((ret & 0x02) == 0x02) data->tcpu_mask |= 0x10; /* Multi-Function detecting for Volt and TR/TD */ ret = nct7904_read_reg(data, BANK_0, VT_ADC_MD_REG); |
b3e260678 hwmon: (nct7904) ... |
1048 1049 |
if (ret < 0) return ret; |
b67b73561 hwmon: (nct7904) ... |
1050 |
|
486842db3 hwmon: (nct7904) ... |
1051 |
data->temp_mode = 0; |
b67b73561 hwmon: (nct7904) ... |
1052 |
for (i = 0; i < 4; i++) { |
539ad001d hwmon: (nct7904) ... |
1053 |
val = (ret >> (i * 2)) & 0x03; |
b67b73561 hwmon: (nct7904) ... |
1054 |
bit = (1 << i); |
6fc28b7e0 hwmon: (nct7904) ... |
1055 |
if (val == VOLT_MONITOR_MODE) { |
b67b73561 hwmon: (nct7904) ... |
1056 |
data->tcpu_mask &= ~bit; |
6fc28b7e0 hwmon: (nct7904) ... |
1057 1058 1059 1060 1061 |
} else if (val == THERMAL_DIODE_MODE && i < 2) { data->temp_mode |= bit; data->vsen_mask &= ~(0x06 << (i * 2)); } else if (val == THERMISTOR_MODE) { data->vsen_mask &= ~(0x02 << (i * 2)); |
539ad001d hwmon: (nct7904) ... |
1062 |
} else { |
6fc28b7e0 hwmon: (nct7904) ... |
1063 1064 |
/* Reserved */ data->tcpu_mask &= ~bit; |
539ad001d hwmon: (nct7904) ... |
1065 1066 |
data->vsen_mask &= ~(0x06 << (i * 2)); } |
b67b73561 hwmon: (nct7904) ... |
1067 1068 1069 1070 |
} /* PECI */ ret = nct7904_read_reg(data, BANK_2, PFE_REG); |
b3e260678 hwmon: (nct7904) ... |
1071 1072 |
if (ret < 0) return ret; |
b67b73561 hwmon: (nct7904) ... |
1073 |
if (ret & 0x80) { |
a653acf00 hwmon: (nct7904) ... |
1074 |
data->enable_dts = 1; /* Enable DTS & PECI */ |
b67b73561 hwmon: (nct7904) ... |
1075 1076 |
} else { ret = nct7904_read_reg(data, BANK_2, TSI_CTRL_REG); |
b3e260678 hwmon: (nct7904) ... |
1077 1078 |
if (ret < 0) return ret; |
b67b73561 hwmon: (nct7904) ... |
1079 |
if (ret & 0x80) |
a653acf00 hwmon: (nct7904) ... |
1080 |
data->enable_dts = 0x3; /* Enable DTS & TSI */ |
b67b73561 hwmon: (nct7904) ... |
1081 1082 1083 1084 |
} /* Check DTS enable status */ if (data->enable_dts) { |
b3e260678 hwmon: (nct7904) ... |
1085 1086 1087 1088 |
ret = nct7904_read_reg(data, BANK_0, DTS_T_CTRL0_REG); if (ret < 0) return ret; data->has_dts = ret & 0xF; |
486842db3 hwmon: (nct7904) ... |
1089 |
if (data->enable_dts & ENABLE_TSI) { |
b3e260678 hwmon: (nct7904) ... |
1090 1091 1092 1093 |
ret = nct7904_read_reg(data, BANK_0, DTS_T_CTRL1_REG); if (ret < 0) return ret; data->has_dts |= (ret & 0xF) << 4; |
b67b73561 hwmon: (nct7904) ... |
1094 1095 |
} } |
9c947d25c hwmon: Add Nuvoto... |
1096 1097 1098 1099 1100 1101 1102 |
for (i = 0; i < FANCTL_MAX; i++) { ret = nct7904_read_reg(data, BANK_3, FANCTL1_FMR_REG + i); if (ret < 0) return ret; data->fan_mode[i] = ret; } |
6d44e43f2 hwmon: (nct7904) ... |
1103 1104 1105 1106 1107 1108 |
/* Read all of SMI status register to clear alarms */ for (i = 0; i < SMI_STS_MAX; i++) { ret = nct7904_read_reg(data, BANK_0, SMI_STS1_REG + i); if (ret < 0) return ret; } |
9c947d25c hwmon: Add Nuvoto... |
1109 |
hwmon_dev = |
d65a5102a hwmon: (nct7904) ... |
1110 1111 |
devm_hwmon_device_register_with_info(dev, client->name, data, &nct7904_chip_info, NULL); |
77849a552 hwmon: (nct7904) ... |
1112 1113 1114 1115 1116 1117 1118 |
ret = PTR_ERR_OR_ZERO(hwmon_dev); if (ret) return ret; /* Watchdog initialization */ data->wdt.ops = &nct7904_wdt_ops; data->wdt.info = &nct7904_wdt_info; |
156ad7f9e hwmon: (nct7904) ... |
1119 |
data->wdt.timeout = WATCHDOG_TIMEOUT * 60; /* Set default timeout */ |
77849a552 hwmon: (nct7904) ... |
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 |
data->wdt.min_timeout = MIN_TIMEOUT; data->wdt.max_timeout = MAX_TIMEOUT; data->wdt.parent = &client->dev; watchdog_init_timeout(&data->wdt, timeout * 60, &client->dev); watchdog_set_nowayout(&data->wdt, nowayout); watchdog_set_drvdata(&data->wdt, data); watchdog_stop_on_unregister(&data->wdt); return devm_watchdog_register_device(dev, &data->wdt); |
9c947d25c hwmon: Add Nuvoto... |
1131 1132 1133 1134 1135 1136 |
} static const struct i2c_device_id nct7904_id[] = { {"nct7904", 0}, {} }; |
1252be9ce hwmon: (nct7904) ... |
1137 |
MODULE_DEVICE_TABLE(i2c, nct7904_id); |
9c947d25c hwmon: Add Nuvoto... |
1138 1139 1140 1141 1142 1143 |
static struct i2c_driver nct7904_driver = { .class = I2C_CLASS_HWMON, .driver = { .name = "nct7904", }, |
674870385 hwmon: use simple... |
1144 |
.probe_new = nct7904_probe, |
9c947d25c hwmon: Add Nuvoto... |
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 |
.id_table = nct7904_id, .detect = nct7904_detect, .address_list = normal_i2c, }; module_i2c_driver(nct7904_driver); MODULE_AUTHOR("Vadim V. Vlasov <vvlasov@dev.rtsoft.ru>"); MODULE_DESCRIPTION("Hwmon driver for NUVOTON NCT7904"); MODULE_LICENSE("GPL"); |