blob: 04516789b070dab5ed51a91473a88c099274506d [file] [log] [blame]
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +03001/*
2 * nct7904.c - driver for Nuvoton NCT7904D.
3 *
4 * Copyright (c) 2015 Kontron
5 * Author: Vadim V. Vlasov <vvlasov@dev.rtsoft.ru>
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
18#include <linux/module.h>
19#include <linux/device.h>
20#include <linux/init.h>
21#include <linux/i2c.h>
22#include <linux/mutex.h>
23#include <linux/hwmon.h>
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +030024
25#define VENDOR_ID_REG 0x7A /* Any bank */
26#define NUVOTON_ID 0x50
27#define CHIP_ID_REG 0x7B /* Any bank */
28#define NCT7904_ID 0xC5
29#define DEVICE_ID_REG 0x7C /* Any bank */
30
31#define BANK_SEL_REG 0xFF
32#define BANK_0 0x00
33#define BANK_1 0x01
34#define BANK_2 0x02
35#define BANK_3 0x03
36#define BANK_4 0x04
37#define BANK_MAX 0x04
38
39#define FANIN_MAX 12 /* Counted from 1 */
40#define VSEN_MAX 21 /* VSEN1..14, 3VDD, VBAT, V3VSB,
41 LTD (not a voltage), VSEN17..19 */
42#define FANCTL_MAX 4 /* Counted from 1 */
43#define TCPU_MAX 8 /* Counted from 1 */
44#define TEMP_MAX 4 /* Counted from 1 */
45
46#define VT_ADC_CTRL0_REG 0x20 /* Bank 0 */
47#define VT_ADC_CTRL1_REG 0x21 /* Bank 0 */
48#define VT_ADC_CTRL2_REG 0x22 /* Bank 0 */
49#define FANIN_CTRL0_REG 0x24
50#define FANIN_CTRL1_REG 0x25
51#define DTS_T_CTRL0_REG 0x26
52#define DTS_T_CTRL1_REG 0x27
53#define VT_ADC_MD_REG 0x2E
54
55#define VSEN1_HV_REG 0x40 /* Bank 0; 2 regs (HV/LV) per sensor */
56#define TEMP_CH1_HV_REG 0x42 /* Bank 0; same as VSEN2_HV */
57#define LTD_HV_REG 0x62 /* Bank 0; 2 regs in VSEN range */
58#define FANIN1_HV_REG 0x80 /* Bank 0; 2 regs (HV/LV) per sensor */
59#define T_CPU1_HV_REG 0xA0 /* Bank 0; 2 regs (HV/LV) per sensor */
60
61#define PRTS_REG 0x03 /* Bank 2 */
62#define FANCTL1_FMR_REG 0x00 /* Bank 3; 1 reg per channel */
63#define FANCTL1_OUT_REG 0x10 /* Bank 3; 1 reg per channel */
64
65static const unsigned short normal_i2c[] = {
66 0x2d, 0x2e, I2C_CLIENT_END
67};
68
69struct nct7904_data {
70 struct i2c_client *client;
71 struct mutex bank_lock;
72 int bank_sel;
73 u32 fanin_mask;
74 u32 vsen_mask;
75 u32 tcpu_mask;
76 u8 fan_mode[FANCTL_MAX];
77};
78
79/* Access functions */
Jakob Albert73ed6e22018-06-13 17:13:25 +020080static int nct7904_bank_lock(struct nct7904_data *data, unsigned int bank)
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +030081{
82 int ret;
83
84 mutex_lock(&data->bank_lock);
85 if (data->bank_sel == bank)
86 return 0;
87 ret = i2c_smbus_write_byte_data(data->client, BANK_SEL_REG, bank);
88 if (ret == 0)
89 data->bank_sel = bank;
90 else
91 data->bank_sel = -1;
92 return ret;
93}
94
95static inline void nct7904_bank_release(struct nct7904_data *data)
96{
97 mutex_unlock(&data->bank_lock);
98}
99
100/* Read 1-byte register. Returns unsigned reg or -ERRNO on error. */
101static int nct7904_read_reg(struct nct7904_data *data,
Jakob Albert73ed6e22018-06-13 17:13:25 +0200102 unsigned int bank, unsigned int reg)
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300103{
104 struct i2c_client *client = data->client;
105 int ret;
106
107 ret = nct7904_bank_lock(data, bank);
108 if (ret == 0)
109 ret = i2c_smbus_read_byte_data(client, reg);
110
111 nct7904_bank_release(data);
112 return ret;
113}
114
115/*
116 * Read 2-byte register. Returns register in big-endian format or
117 * -ERRNO on error.
118 */
119static int nct7904_read_reg16(struct nct7904_data *data,
Jakob Albert73ed6e22018-06-13 17:13:25 +0200120 unsigned int bank, unsigned int reg)
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300121{
122 struct i2c_client *client = data->client;
123 int ret, hi;
124
125 ret = nct7904_bank_lock(data, bank);
126 if (ret == 0) {
127 ret = i2c_smbus_read_byte_data(client, reg);
128 if (ret >= 0) {
129 hi = ret;
130 ret = i2c_smbus_read_byte_data(client, reg + 1);
131 if (ret >= 0)
132 ret |= hi << 8;
133 }
134 }
135
136 nct7904_bank_release(data);
137 return ret;
138}
139
140/* Write 1-byte register. Returns 0 or -ERRNO on error. */
141static int nct7904_write_reg(struct nct7904_data *data,
Jakob Albert73ed6e22018-06-13 17:13:25 +0200142 unsigned int bank, unsigned int reg, u8 val)
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300143{
144 struct i2c_client *client = data->client;
145 int ret;
146
147 ret = nct7904_bank_lock(data, bank);
148 if (ret == 0)
149 ret = i2c_smbus_write_byte_data(client, reg, val);
150
151 nct7904_bank_release(data);
152 return ret;
153}
154
Guenter Roeckd65a5102016-06-26 12:22:03 -0700155static int nct7904_read_fan(struct device *dev, u32 attr, int channel,
156 long *val)
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300157{
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300158 struct nct7904_data *data = dev_get_drvdata(dev);
Guenter Roeckd65a5102016-06-26 12:22:03 -0700159 unsigned int cnt, rpm;
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300160 int ret;
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300161
Jakob Albertec1460e2018-06-13 17:13:23 +0200162 switch (attr) {
Guenter Roeckd65a5102016-06-26 12:22:03 -0700163 case hwmon_fan_input:
164 ret = nct7904_read_reg16(data, BANK_0,
165 FANIN1_HV_REG + channel * 2);
166 if (ret < 0)
167 return ret;
168 cnt = ((ret & 0xff00) >> 3) | (ret & 0x1f);
169 if (cnt == 0x1fff)
170 rpm = 0;
171 else
172 rpm = 1350000 / cnt;
173 *val = rpm;
174 return 0;
175 default:
176 return -EOPNOTSUPP;
177 }
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300178}
179
Guenter Roeckd65a5102016-06-26 12:22:03 -0700180static umode_t nct7904_fan_is_visible(const void *_data, u32 attr, int channel)
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300181{
Guenter Roeckd65a5102016-06-26 12:22:03 -0700182 const struct nct7904_data *data = _data;
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300183
Guenter Roeckd65a5102016-06-26 12:22:03 -0700184 if (attr == hwmon_fan_input && data->fanin_mask & (1 << channel))
Guenter Roecke590be42018-12-10 14:02:17 -0800185 return 0444;
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300186 return 0;
187}
188
Guenter Roeckd65a5102016-06-26 12:22:03 -0700189static u8 nct7904_chan_to_index[] = {
190 0, /* Not used */
191 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
192 18, 19, 20, 16
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300193};
194
Guenter Roeckd65a5102016-06-26 12:22:03 -0700195static int nct7904_read_in(struct device *dev, u32 attr, int channel,
196 long *val)
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300197{
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300198 struct nct7904_data *data = dev_get_drvdata(dev);
Guenter Roeckd65a5102016-06-26 12:22:03 -0700199 int ret, volt, index;
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300200
Guenter Roeckd65a5102016-06-26 12:22:03 -0700201 index = nct7904_chan_to_index[channel];
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300202
Jakob Albertec1460e2018-06-13 17:13:23 +0200203 switch (attr) {
Guenter Roeckd65a5102016-06-26 12:22:03 -0700204 case hwmon_in_input:
205 ret = nct7904_read_reg16(data, BANK_0,
206 VSEN1_HV_REG + index * 2);
207 if (ret < 0)
208 return ret;
209 volt = ((ret & 0xff00) >> 5) | (ret & 0x7);
210 if (index < 14)
211 volt *= 2; /* 0.002V scale */
212 else
213 volt *= 6; /* 0.006V scale */
214 *val = volt;
215 return 0;
216 default:
217 return -EOPNOTSUPP;
218 }
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300219}
220
Guenter Roeckd65a5102016-06-26 12:22:03 -0700221static umode_t nct7904_in_is_visible(const void *_data, u32 attr, int channel)
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300222{
Guenter Roeckd65a5102016-06-26 12:22:03 -0700223 const struct nct7904_data *data = _data;
224 int index = nct7904_chan_to_index[channel];
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300225
Guenter Roeckd65a5102016-06-26 12:22:03 -0700226 if (channel > 0 && attr == hwmon_in_input &&
227 (data->vsen_mask & BIT(index)))
Guenter Roecke590be42018-12-10 14:02:17 -0800228 return 0444;
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300229
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300230 return 0;
231}
232
Guenter Roeckd65a5102016-06-26 12:22:03 -0700233static int nct7904_read_temp(struct device *dev, u32 attr, int channel,
234 long *val)
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300235{
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300236 struct nct7904_data *data = dev_get_drvdata(dev);
Guenter Roeckd65a5102016-06-26 12:22:03 -0700237 int ret, temp;
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300238
Jakob Albertec1460e2018-06-13 17:13:23 +0200239 switch (attr) {
Guenter Roeckd65a5102016-06-26 12:22:03 -0700240 case hwmon_temp_input:
241 if (channel == 0)
242 ret = nct7904_read_reg16(data, BANK_0, LTD_HV_REG);
243 else
244 ret = nct7904_read_reg16(data, BANK_0,
245 T_CPU1_HV_REG + (channel - 1) * 2);
246 if (ret < 0)
247 return ret;
248 temp = ((ret & 0xff00) >> 5) | (ret & 0x7);
249 *val = sign_extend32(temp, 10) * 125;
250 return 0;
251 default:
252 return -EOPNOTSUPP;
253 }
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300254}
255
Guenter Roeckd65a5102016-06-26 12:22:03 -0700256static umode_t nct7904_temp_is_visible(const void *_data, u32 attr, int channel)
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300257{
Guenter Roeckd65a5102016-06-26 12:22:03 -0700258 const struct nct7904_data *data = _data;
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300259
Guenter Roeckd65a5102016-06-26 12:22:03 -0700260 if (attr == hwmon_temp_input) {
261 if (channel == 0) {
262 if (data->vsen_mask & BIT(17))
Guenter Roecke590be42018-12-10 14:02:17 -0800263 return 0444;
Guenter Roeckd65a5102016-06-26 12:22:03 -0700264 } else {
265 if (data->tcpu_mask & BIT(channel - 1))
Guenter Roecke590be42018-12-10 14:02:17 -0800266 return 0444;
Guenter Roeckd65a5102016-06-26 12:22:03 -0700267 }
268 }
269
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300270 return 0;
271}
272
Guenter Roeckd65a5102016-06-26 12:22:03 -0700273static int nct7904_read_pwm(struct device *dev, u32 attr, int channel,
274 long *val)
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300275{
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300276 struct nct7904_data *data = dev_get_drvdata(dev);
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300277 int ret;
278
Jakob Albertec1460e2018-06-13 17:13:23 +0200279 switch (attr) {
Guenter Roeckd65a5102016-06-26 12:22:03 -0700280 case hwmon_pwm_input:
281 ret = nct7904_read_reg(data, BANK_3, FANCTL1_OUT_REG + channel);
282 if (ret < 0)
283 return ret;
284 *val = ret;
285 return 0;
286 case hwmon_pwm_enable:
287 ret = nct7904_read_reg(data, BANK_3, FANCTL1_FMR_REG + channel);
288 if (ret < 0)
289 return ret;
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300290
Guenter Roeckd65a5102016-06-26 12:22:03 -0700291 *val = ret ? 2 : 1;
292 return 0;
293 default:
294 return -EOPNOTSUPP;
295 }
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300296}
297
Guenter Roeckd65a5102016-06-26 12:22:03 -0700298static int nct7904_write_pwm(struct device *dev, u32 attr, int channel,
299 long val)
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300300{
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300301 struct nct7904_data *data = dev_get_drvdata(dev);
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300302 int ret;
303
Jakob Albertec1460e2018-06-13 17:13:23 +0200304 switch (attr) {
Guenter Roeckd65a5102016-06-26 12:22:03 -0700305 case hwmon_pwm_input:
306 if (val < 0 || val > 255)
307 return -EINVAL;
308 ret = nct7904_write_reg(data, BANK_3, FANCTL1_OUT_REG + channel,
309 val);
310 return ret;
311 case hwmon_pwm_enable:
312 if (val < 1 || val > 2 ||
313 (val == 2 && !data->fan_mode[channel]))
314 return -EINVAL;
315 ret = nct7904_write_reg(data, BANK_3, FANCTL1_FMR_REG + channel,
316 val == 2 ? data->fan_mode[channel] : 0);
317 return ret;
318 default:
319 return -EOPNOTSUPP;
320 }
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300321}
322
Guenter Roeckd65a5102016-06-26 12:22:03 -0700323static umode_t nct7904_pwm_is_visible(const void *_data, u32 attr, int channel)
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300324{
Jakob Albertec1460e2018-06-13 17:13:23 +0200325 switch (attr) {
Guenter Roeckd65a5102016-06-26 12:22:03 -0700326 case hwmon_pwm_input:
327 case hwmon_pwm_enable:
Guenter Roecke590be42018-12-10 14:02:17 -0800328 return 0644;
Guenter Roeckd65a5102016-06-26 12:22:03 -0700329 default:
330 return 0;
331 }
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300332}
333
Guenter Roeckd65a5102016-06-26 12:22:03 -0700334static int nct7904_read(struct device *dev, enum hwmon_sensor_types type,
335 u32 attr, int channel, long *val)
336{
337 switch (type) {
338 case hwmon_in:
339 return nct7904_read_in(dev, attr, channel, val);
340 case hwmon_fan:
341 return nct7904_read_fan(dev, attr, channel, val);
342 case hwmon_pwm:
343 return nct7904_read_pwm(dev, attr, channel, val);
344 case hwmon_temp:
345 return nct7904_read_temp(dev, attr, channel, val);
346 default:
347 return -EOPNOTSUPP;
348 }
349}
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300350
Guenter Roeckd65a5102016-06-26 12:22:03 -0700351static int nct7904_write(struct device *dev, enum hwmon_sensor_types type,
352 u32 attr, int channel, long val)
353{
354 switch (type) {
355 case hwmon_pwm:
356 return nct7904_write_pwm(dev, attr, channel, val);
357 default:
358 return -EOPNOTSUPP;
359 }
360}
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300361
Guenter Roeckd65a5102016-06-26 12:22:03 -0700362static umode_t nct7904_is_visible(const void *data,
363 enum hwmon_sensor_types type,
364 u32 attr, int channel)
365{
366 switch (type) {
367 case hwmon_in:
368 return nct7904_in_is_visible(data, attr, channel);
369 case hwmon_fan:
370 return nct7904_fan_is_visible(data, attr, channel);
371 case hwmon_pwm:
372 return nct7904_pwm_is_visible(data, attr, channel);
373 case hwmon_temp:
374 return nct7904_temp_is_visible(data, attr, channel);
375 default:
376 return 0;
377 }
378}
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300379
380/* Return 0 if detection is successful, -ENODEV otherwise */
381static int nct7904_detect(struct i2c_client *client,
382 struct i2c_board_info *info)
383{
384 struct i2c_adapter *adapter = client->adapter;
385
386 if (!i2c_check_functionality(adapter,
387 I2C_FUNC_SMBUS_READ_BYTE |
388 I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
389 return -ENODEV;
390
391 /* Determine the chip type. */
392 if (i2c_smbus_read_byte_data(client, VENDOR_ID_REG) != NUVOTON_ID ||
393 i2c_smbus_read_byte_data(client, CHIP_ID_REG) != NCT7904_ID ||
Guenter Roeck6552f322015-02-27 08:23:37 -0800394 (i2c_smbus_read_byte_data(client, DEVICE_ID_REG) & 0xf0) != 0x50 ||
395 (i2c_smbus_read_byte_data(client, BANK_SEL_REG) & 0xf8) != 0x00)
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300396 return -ENODEV;
397
398 strlcpy(info->type, "nct7904", I2C_NAME_SIZE);
399
400 return 0;
401}
402
Guenter Roeckd65a5102016-06-26 12:22:03 -0700403static const struct hwmon_channel_info *nct7904_info[] = {
Guenter Roeck4ec1d232019-03-29 13:26:40 -0700404 HWMON_CHANNEL_INFO(in,
405 HWMON_I_INPUT, /* dummy, skipped in is_visible */
406 HWMON_I_INPUT,
407 HWMON_I_INPUT,
408 HWMON_I_INPUT,
409 HWMON_I_INPUT,
410 HWMON_I_INPUT,
411 HWMON_I_INPUT,
412 HWMON_I_INPUT,
413 HWMON_I_INPUT,
414 HWMON_I_INPUT,
415 HWMON_I_INPUT,
416 HWMON_I_INPUT,
417 HWMON_I_INPUT,
418 HWMON_I_INPUT,
419 HWMON_I_INPUT,
420 HWMON_I_INPUT,
421 HWMON_I_INPUT,
422 HWMON_I_INPUT,
423 HWMON_I_INPUT,
424 HWMON_I_INPUT,
425 HWMON_I_INPUT),
426 HWMON_CHANNEL_INFO(fan,
427 HWMON_F_INPUT,
428 HWMON_F_INPUT,
429 HWMON_F_INPUT,
430 HWMON_F_INPUT,
431 HWMON_F_INPUT,
432 HWMON_F_INPUT,
433 HWMON_F_INPUT,
434 HWMON_F_INPUT),
435 HWMON_CHANNEL_INFO(pwm,
436 HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
437 HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
438 HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
439 HWMON_PWM_INPUT | HWMON_PWM_ENABLE),
440 HWMON_CHANNEL_INFO(temp,
441 HWMON_T_INPUT,
442 HWMON_T_INPUT,
443 HWMON_T_INPUT,
444 HWMON_T_INPUT,
445 HWMON_T_INPUT,
446 HWMON_T_INPUT,
447 HWMON_T_INPUT,
448 HWMON_T_INPUT,
449 HWMON_T_INPUT),
Guenter Roeckd65a5102016-06-26 12:22:03 -0700450 NULL
451};
452
453static const struct hwmon_ops nct7904_hwmon_ops = {
454 .is_visible = nct7904_is_visible,
455 .read = nct7904_read,
456 .write = nct7904_write,
457};
458
459static const struct hwmon_chip_info nct7904_chip_info = {
460 .ops = &nct7904_hwmon_ops,
461 .info = nct7904_info,
462};
463
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300464static int nct7904_probe(struct i2c_client *client,
465 const struct i2c_device_id *id)
466{
467 struct nct7904_data *data;
468 struct device *hwmon_dev;
469 struct device *dev = &client->dev;
470 int ret, i;
471 u32 mask;
472
473 data = devm_kzalloc(dev, sizeof(struct nct7904_data), GFP_KERNEL);
474 if (!data)
475 return -ENOMEM;
476
477 data->client = client;
478 mutex_init(&data->bank_lock);
479 data->bank_sel = -1;
480
481 /* Setup sensor groups. */
482 /* FANIN attributes */
483 ret = nct7904_read_reg16(data, BANK_0, FANIN_CTRL0_REG);
484 if (ret < 0)
485 return ret;
486 data->fanin_mask = (ret >> 8) | ((ret & 0xff) << 8);
487
488 /*
489 * VSEN attributes
490 *
491 * Note: voltage sensors overlap with external temperature
492 * sensors. So, if we ever decide to support the latter
493 * we will have to adjust 'vsen_mask' accordingly.
494 */
495 mask = 0;
496 ret = nct7904_read_reg16(data, BANK_0, VT_ADC_CTRL0_REG);
497 if (ret >= 0)
498 mask = (ret >> 8) | ((ret & 0xff) << 8);
499 ret = nct7904_read_reg(data, BANK_0, VT_ADC_CTRL2_REG);
500 if (ret >= 0)
501 mask |= (ret << 16);
502 data->vsen_mask = mask;
503
504 /* CPU_TEMP attributes */
505 ret = nct7904_read_reg16(data, BANK_0, DTS_T_CTRL0_REG);
506 if (ret < 0)
507 return ret;
508 data->tcpu_mask = ((ret >> 8) & 0xf) | ((ret & 0xf) << 4);
509
510 for (i = 0; i < FANCTL_MAX; i++) {
511 ret = nct7904_read_reg(data, BANK_3, FANCTL1_FMR_REG + i);
512 if (ret < 0)
513 return ret;
514 data->fan_mode[i] = ret;
515 }
516
517 hwmon_dev =
Guenter Roeckd65a5102016-06-26 12:22:03 -0700518 devm_hwmon_device_register_with_info(dev, client->name, data,
519 &nct7904_chip_info, NULL);
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300520 return PTR_ERR_OR_ZERO(hwmon_dev);
521}
522
523static const struct i2c_device_id nct7904_id[] = {
524 {"nct7904", 0},
525 {}
526};
Javier Martinez Canillas1252be92015-07-30 18:18:39 +0200527MODULE_DEVICE_TABLE(i2c, nct7904_id);
Vadim V. Vlasov9c947d22015-02-27 16:16:00 +0300528
529static struct i2c_driver nct7904_driver = {
530 .class = I2C_CLASS_HWMON,
531 .driver = {
532 .name = "nct7904",
533 },
534 .probe = nct7904_probe,
535 .id_table = nct7904_id,
536 .detect = nct7904_detect,
537 .address_list = normal_i2c,
538};
539
540module_i2c_driver(nct7904_driver);
541
542MODULE_AUTHOR("Vadim V. Vlasov <vvlasov@dev.rtsoft.ru>");
543MODULE_DESCRIPTION("Hwmon driver for NUVOTON NCT7904");
544MODULE_LICENSE("GPL");