Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (nct7904) Convert to use new hwmon registration API

Simplify code and reduce code size by using the new hwmon
registration API.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>

+270 -285
+270 -285
drivers/hwmon/nct7904.c
··· 21 21 #include <linux/i2c.h> 22 22 #include <linux/mutex.h> 23 23 #include <linux/hwmon.h> 24 - #include <linux/hwmon-sysfs.h> 25 24 26 25 #define VENDOR_ID_REG 0x7A /* Any bank */ 27 26 #define NUVOTON_ID 0x50 ··· 152 153 return ret; 153 154 } 154 155 155 - /* FANIN ATTR */ 156 - static ssize_t show_fan(struct device *dev, 157 - struct device_attribute *devattr, char *buf) 156 + static int nct7904_read_fan(struct device *dev, u32 attr, int channel, 157 + long *val) 158 158 { 159 - int index = to_sensor_dev_attr(devattr)->index; 160 159 struct nct7904_data *data = dev_get_drvdata(dev); 160 + unsigned int cnt, rpm; 161 161 int ret; 162 - unsigned cnt, rpm; 163 162 164 - ret = nct7904_read_reg16(data, BANK_0, FANIN1_HV_REG + index * 2); 165 - if (ret < 0) 166 - return ret; 167 - cnt = ((ret & 0xff00) >> 3) | (ret & 0x1f); 168 - if (cnt == 0x1fff) 169 - rpm = 0; 170 - else 171 - rpm = 1350000 / cnt; 172 - return sprintf(buf, "%u\n", rpm); 163 + switch(attr) { 164 + case hwmon_fan_input: 165 + ret = nct7904_read_reg16(data, BANK_0, 166 + FANIN1_HV_REG + channel * 2); 167 + if (ret < 0) 168 + return ret; 169 + cnt = ((ret & 0xff00) >> 3) | (ret & 0x1f); 170 + if (cnt == 0x1fff) 171 + rpm = 0; 172 + else 173 + rpm = 1350000 / cnt; 174 + *val = rpm; 175 + return 0; 176 + default: 177 + return -EOPNOTSUPP; 178 + } 173 179 } 174 180 175 - static umode_t nct7904_fanin_is_visible(struct kobject *kobj, 176 - struct attribute *a, int n) 181 + static umode_t nct7904_fan_is_visible(const void *_data, u32 attr, int channel) 177 182 { 178 - struct device *dev = container_of(kobj, struct device, kobj); 179 - struct nct7904_data *data = dev_get_drvdata(dev); 183 + const struct nct7904_data *data = _data; 180 184 181 - if (data->fanin_mask & (1 << n)) 182 - return a->mode; 185 + if (attr == hwmon_fan_input && data->fanin_mask & (1 << channel)) 186 + return S_IRUGO; 183 187 return 0; 184 188 } 185 189 186 - static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); 187 - static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1); 188 - static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2); 189 - static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3); 190 - static SENSOR_DEVICE_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 4); 191 - static SENSOR_DEVICE_ATTR(fan6_input, S_IRUGO, show_fan, NULL, 5); 192 - static SENSOR_DEVICE_ATTR(fan7_input, S_IRUGO, show_fan, NULL, 6); 193 - static SENSOR_DEVICE_ATTR(fan8_input, S_IRUGO, show_fan, NULL, 7); 194 - static SENSOR_DEVICE_ATTR(fan9_input, S_IRUGO, show_fan, NULL, 8); 195 - static SENSOR_DEVICE_ATTR(fan10_input, S_IRUGO, show_fan, NULL, 9); 196 - static SENSOR_DEVICE_ATTR(fan11_input, S_IRUGO, show_fan, NULL, 10); 197 - static SENSOR_DEVICE_ATTR(fan12_input, S_IRUGO, show_fan, NULL, 11); 198 - 199 - static struct attribute *nct7904_fanin_attrs[] = { 200 - &sensor_dev_attr_fan1_input.dev_attr.attr, 201 - &sensor_dev_attr_fan2_input.dev_attr.attr, 202 - &sensor_dev_attr_fan3_input.dev_attr.attr, 203 - &sensor_dev_attr_fan4_input.dev_attr.attr, 204 - &sensor_dev_attr_fan5_input.dev_attr.attr, 205 - &sensor_dev_attr_fan6_input.dev_attr.attr, 206 - &sensor_dev_attr_fan7_input.dev_attr.attr, 207 - &sensor_dev_attr_fan8_input.dev_attr.attr, 208 - &sensor_dev_attr_fan9_input.dev_attr.attr, 209 - &sensor_dev_attr_fan10_input.dev_attr.attr, 210 - &sensor_dev_attr_fan11_input.dev_attr.attr, 211 - &sensor_dev_attr_fan12_input.dev_attr.attr, 212 - NULL 190 + static u8 nct7904_chan_to_index[] = { 191 + 0, /* Not used */ 192 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 193 + 18, 19, 20, 16 213 194 }; 214 195 215 - static const struct attribute_group nct7904_fanin_group = { 216 - .attrs = nct7904_fanin_attrs, 217 - .is_visible = nct7904_fanin_is_visible, 218 - }; 219 - 220 - /* VSEN ATTR */ 221 - static ssize_t show_voltage(struct device *dev, 222 - struct device_attribute *devattr, char *buf) 196 + static int nct7904_read_in(struct device *dev, u32 attr, int channel, 197 + long *val) 223 198 { 224 - int index = to_sensor_dev_attr(devattr)->index; 225 199 struct nct7904_data *data = dev_get_drvdata(dev); 226 - int ret; 227 - int volt; 200 + int ret, volt, index; 228 201 229 - ret = nct7904_read_reg16(data, BANK_0, VSEN1_HV_REG + index * 2); 230 - if (ret < 0) 231 - return ret; 232 - volt = ((ret & 0xff00) >> 5) | (ret & 0x7); 233 - if (index < 14) 234 - volt *= 2; /* 0.002V scale */ 235 - else 236 - volt *= 6; /* 0.006V scale */ 202 + index = nct7904_chan_to_index[channel]; 237 203 238 - return sprintf(buf, "%d\n", volt); 204 + switch(attr) { 205 + case hwmon_in_input: 206 + ret = nct7904_read_reg16(data, BANK_0, 207 + VSEN1_HV_REG + index * 2); 208 + if (ret < 0) 209 + return ret; 210 + volt = ((ret & 0xff00) >> 5) | (ret & 0x7); 211 + if (index < 14) 212 + volt *= 2; /* 0.002V scale */ 213 + else 214 + volt *= 6; /* 0.006V scale */ 215 + *val = volt; 216 + return 0; 217 + default: 218 + return -EOPNOTSUPP; 219 + } 239 220 } 240 221 241 - static ssize_t show_ltemp(struct device *dev, 242 - struct device_attribute *devattr, char *buf) 222 + static umode_t nct7904_in_is_visible(const void *_data, u32 attr, int channel) 243 223 { 244 - struct nct7904_data *data = dev_get_drvdata(dev); 245 - int ret; 246 - int temp; 224 + const struct nct7904_data *data = _data; 225 + int index = nct7904_chan_to_index[channel]; 247 226 248 - ret = nct7904_read_reg16(data, BANK_0, LTD_HV_REG); 249 - if (ret < 0) 250 - return ret; 251 - temp = ((ret & 0xff00) >> 5) | (ret & 0x7); 252 - temp = sign_extend32(temp, 10) * 125; 227 + if (channel > 0 && attr == hwmon_in_input && 228 + (data->vsen_mask & BIT(index))) 229 + return S_IRUGO; 253 230 254 - return sprintf(buf, "%d\n", temp); 255 - } 256 - 257 - static umode_t nct7904_vsen_is_visible(struct kobject *kobj, 258 - struct attribute *a, int n) 259 - { 260 - struct device *dev = container_of(kobj, struct device, kobj); 261 - struct nct7904_data *data = dev_get_drvdata(dev); 262 - 263 - if (data->vsen_mask & (1 << n)) 264 - return a->mode; 265 231 return 0; 266 232 } 267 233 268 - static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_voltage, NULL, 0); 269 - static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_voltage, NULL, 1); 270 - static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_voltage, NULL, 2); 271 - static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_voltage, NULL, 3); 272 - static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_voltage, NULL, 4); 273 - static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_voltage, NULL, 5); 274 - static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_voltage, NULL, 6); 275 - static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_voltage, NULL, 7); 276 - static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, show_voltage, NULL, 8); 277 - static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, show_voltage, NULL, 9); 278 - static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, show_voltage, NULL, 10); 279 - static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, show_voltage, NULL, 11); 280 - static SENSOR_DEVICE_ATTR(in13_input, S_IRUGO, show_voltage, NULL, 12); 281 - static SENSOR_DEVICE_ATTR(in14_input, S_IRUGO, show_voltage, NULL, 13); 282 - /* 283 - * Next 3 voltage sensors have specific names in the Nuvoton doc 284 - * (3VDD, VBAT, 3VSB) but we use vacant numbers for them. 285 - */ 286 - static SENSOR_DEVICE_ATTR(in15_input, S_IRUGO, show_voltage, NULL, 14); 287 - static SENSOR_DEVICE_ATTR(in16_input, S_IRUGO, show_voltage, NULL, 15); 288 - static SENSOR_DEVICE_ATTR(in20_input, S_IRUGO, show_voltage, NULL, 16); 289 - /* This is not a voltage, but a local temperature sensor. */ 290 - static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_ltemp, NULL, 0); 291 - static SENSOR_DEVICE_ATTR(in17_input, S_IRUGO, show_voltage, NULL, 18); 292 - static SENSOR_DEVICE_ATTR(in18_input, S_IRUGO, show_voltage, NULL, 19); 293 - static SENSOR_DEVICE_ATTR(in19_input, S_IRUGO, show_voltage, NULL, 20); 294 - 295 - static struct attribute *nct7904_vsen_attrs[] = { 296 - &sensor_dev_attr_in1_input.dev_attr.attr, 297 - &sensor_dev_attr_in2_input.dev_attr.attr, 298 - &sensor_dev_attr_in3_input.dev_attr.attr, 299 - &sensor_dev_attr_in4_input.dev_attr.attr, 300 - &sensor_dev_attr_in5_input.dev_attr.attr, 301 - &sensor_dev_attr_in6_input.dev_attr.attr, 302 - &sensor_dev_attr_in7_input.dev_attr.attr, 303 - &sensor_dev_attr_in8_input.dev_attr.attr, 304 - &sensor_dev_attr_in9_input.dev_attr.attr, 305 - &sensor_dev_attr_in10_input.dev_attr.attr, 306 - &sensor_dev_attr_in11_input.dev_attr.attr, 307 - &sensor_dev_attr_in12_input.dev_attr.attr, 308 - &sensor_dev_attr_in13_input.dev_attr.attr, 309 - &sensor_dev_attr_in14_input.dev_attr.attr, 310 - &sensor_dev_attr_in15_input.dev_attr.attr, 311 - &sensor_dev_attr_in16_input.dev_attr.attr, 312 - &sensor_dev_attr_in20_input.dev_attr.attr, 313 - &sensor_dev_attr_temp1_input.dev_attr.attr, 314 - &sensor_dev_attr_in17_input.dev_attr.attr, 315 - &sensor_dev_attr_in18_input.dev_attr.attr, 316 - &sensor_dev_attr_in19_input.dev_attr.attr, 317 - NULL 318 - }; 319 - 320 - static const struct attribute_group nct7904_vsen_group = { 321 - .attrs = nct7904_vsen_attrs, 322 - .is_visible = nct7904_vsen_is_visible, 323 - }; 324 - 325 - /* CPU_TEMP ATTR */ 326 - static ssize_t show_tcpu(struct device *dev, 327 - struct device_attribute *devattr, char *buf) 234 + static int nct7904_read_temp(struct device *dev, u32 attr, int channel, 235 + long *val) 328 236 { 329 - int index = to_sensor_dev_attr(devattr)->index; 330 237 struct nct7904_data *data = dev_get_drvdata(dev); 331 - int ret; 332 - int temp; 238 + int ret, temp; 333 239 334 - ret = nct7904_read_reg16(data, BANK_0, T_CPU1_HV_REG + index * 2); 335 - if (ret < 0) 336 - return ret; 337 - 338 - temp = ((ret & 0xff00) >> 5) | (ret & 0x7); 339 - temp = sign_extend32(temp, 10) * 125; 340 - return sprintf(buf, "%d\n", temp); 240 + switch(attr) { 241 + case hwmon_temp_input: 242 + if (channel == 0) 243 + ret = nct7904_read_reg16(data, BANK_0, LTD_HV_REG); 244 + else 245 + ret = nct7904_read_reg16(data, BANK_0, 246 + T_CPU1_HV_REG + (channel - 1) * 2); 247 + if (ret < 0) 248 + return ret; 249 + temp = ((ret & 0xff00) >> 5) | (ret & 0x7); 250 + *val = sign_extend32(temp, 10) * 125; 251 + return 0; 252 + default: 253 + return -EOPNOTSUPP; 254 + } 341 255 } 342 256 343 - static umode_t nct7904_tcpu_is_visible(struct kobject *kobj, 344 - struct attribute *a, int n) 257 + static umode_t nct7904_temp_is_visible(const void *_data, u32 attr, int channel) 345 258 { 346 - struct device *dev = container_of(kobj, struct device, kobj); 347 - struct nct7904_data *data = dev_get_drvdata(dev); 259 + const struct nct7904_data *data = _data; 348 260 349 - if (data->tcpu_mask & (1 << n)) 350 - return a->mode; 261 + if (attr == hwmon_temp_input) { 262 + if (channel == 0) { 263 + if (data->vsen_mask & BIT(17)) 264 + return S_IRUGO; 265 + } else { 266 + if (data->tcpu_mask & BIT(channel - 1)) 267 + return S_IRUGO; 268 + } 269 + } 270 + 351 271 return 0; 352 272 } 353 273 354 - /* "temp1_input" reserved for local temp */ 355 - static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_tcpu, NULL, 0); 356 - static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_tcpu, NULL, 1); 357 - static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_tcpu, NULL, 2); 358 - static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, show_tcpu, NULL, 3); 359 - static SENSOR_DEVICE_ATTR(temp6_input, S_IRUGO, show_tcpu, NULL, 4); 360 - static SENSOR_DEVICE_ATTR(temp7_input, S_IRUGO, show_tcpu, NULL, 5); 361 - static SENSOR_DEVICE_ATTR(temp8_input, S_IRUGO, show_tcpu, NULL, 6); 362 - static SENSOR_DEVICE_ATTR(temp9_input, S_IRUGO, show_tcpu, NULL, 7); 363 - 364 - static struct attribute *nct7904_tcpu_attrs[] = { 365 - &sensor_dev_attr_temp2_input.dev_attr.attr, 366 - &sensor_dev_attr_temp3_input.dev_attr.attr, 367 - &sensor_dev_attr_temp4_input.dev_attr.attr, 368 - &sensor_dev_attr_temp5_input.dev_attr.attr, 369 - &sensor_dev_attr_temp6_input.dev_attr.attr, 370 - &sensor_dev_attr_temp7_input.dev_attr.attr, 371 - &sensor_dev_attr_temp8_input.dev_attr.attr, 372 - &sensor_dev_attr_temp9_input.dev_attr.attr, 373 - NULL 374 - }; 375 - 376 - static const struct attribute_group nct7904_tcpu_group = { 377 - .attrs = nct7904_tcpu_attrs, 378 - .is_visible = nct7904_tcpu_is_visible, 379 - }; 380 - 381 - /* PWM ATTR */ 382 - static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr, 383 - const char *buf, size_t count) 274 + static int nct7904_read_pwm(struct device *dev, u32 attr, int channel, 275 + long *val) 384 276 { 385 - int index = to_sensor_dev_attr(devattr)->index; 386 277 struct nct7904_data *data = dev_get_drvdata(dev); 387 - unsigned long val; 388 278 int ret; 389 279 390 - if (kstrtoul(buf, 10, &val) < 0) 391 - return -EINVAL; 392 - if (val > 255) 393 - return -EINVAL; 280 + switch(attr) { 281 + case hwmon_pwm_input: 282 + ret = nct7904_read_reg(data, BANK_3, FANCTL1_OUT_REG + channel); 283 + if (ret < 0) 284 + return ret; 285 + *val = ret; 286 + return 0; 287 + case hwmon_pwm_enable: 288 + ret = nct7904_read_reg(data, BANK_3, FANCTL1_FMR_REG + channel); 289 + if (ret < 0) 290 + return ret; 394 291 395 - ret = nct7904_write_reg(data, BANK_3, FANCTL1_OUT_REG + index, val); 396 - 397 - return ret ? ret : count; 292 + *val = ret ? 2 : 1; 293 + return 0; 294 + default: 295 + return -EOPNOTSUPP; 296 + } 398 297 } 399 298 400 - static ssize_t show_pwm(struct device *dev, 401 - struct device_attribute *devattr, char *buf) 299 + static int nct7904_write_pwm(struct device *dev, u32 attr, int channel, 300 + long val) 402 301 { 403 - int index = to_sensor_dev_attr(devattr)->index; 404 302 struct nct7904_data *data = dev_get_drvdata(dev); 405 - int val; 406 - 407 - val = nct7904_read_reg(data, BANK_3, FANCTL1_OUT_REG + index); 408 - if (val < 0) 409 - return val; 410 - 411 - return sprintf(buf, "%d\n", val); 412 - } 413 - 414 - static ssize_t store_enable(struct device *dev, 415 - struct device_attribute *devattr, 416 - const char *buf, size_t count) 417 - { 418 - int index = to_sensor_dev_attr(devattr)->index; 419 - struct nct7904_data *data = dev_get_drvdata(dev); 420 - unsigned long val; 421 303 int ret; 422 304 423 - if (kstrtoul(buf, 10, &val) < 0) 424 - return -EINVAL; 425 - if (val < 1 || val > 2 || (val == 2 && !data->fan_mode[index])) 426 - return -EINVAL; 427 - 428 - ret = nct7904_write_reg(data, BANK_3, FANCTL1_FMR_REG + index, 429 - val == 2 ? data->fan_mode[index] : 0); 430 - 431 - return ret ? ret : count; 305 + switch(attr) { 306 + case hwmon_pwm_input: 307 + if (val < 0 || val > 255) 308 + return -EINVAL; 309 + ret = nct7904_write_reg(data, BANK_3, FANCTL1_OUT_REG + channel, 310 + val); 311 + return ret; 312 + case hwmon_pwm_enable: 313 + if (val < 1 || val > 2 || 314 + (val == 2 && !data->fan_mode[channel])) 315 + return -EINVAL; 316 + ret = nct7904_write_reg(data, BANK_3, FANCTL1_FMR_REG + channel, 317 + val == 2 ? data->fan_mode[channel] : 0); 318 + return ret; 319 + default: 320 + return -EOPNOTSUPP; 321 + } 432 322 } 433 323 434 - /* Return 1 for manual mode or 2 for SmartFan mode */ 435 - static ssize_t show_enable(struct device *dev, 436 - struct device_attribute *devattr, char *buf) 324 + static umode_t nct7904_pwm_is_visible(const void *_data, u32 attr, int channel) 437 325 { 438 - int index = to_sensor_dev_attr(devattr)->index; 439 - struct nct7904_data *data = dev_get_drvdata(dev); 440 - int val; 441 - 442 - val = nct7904_read_reg(data, BANK_3, FANCTL1_FMR_REG + index); 443 - if (val < 0) 444 - return val; 445 - 446 - return sprintf(buf, "%d\n", val ? 2 : 1); 326 + switch(attr) { 327 + case hwmon_pwm_input: 328 + case hwmon_pwm_enable: 329 + return S_IRUGO | S_IWUSR; 330 + default: 331 + return 0; 332 + } 447 333 } 448 334 449 - /* 2 attributes per channel: pwm and mode */ 450 - static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, 451 - show_pwm, store_pwm, 0); 452 - static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, 453 - show_enable, store_enable, 0); 454 - static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, 455 - show_pwm, store_pwm, 1); 456 - static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, 457 - show_enable, store_enable, 1); 458 - static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, 459 - show_pwm, store_pwm, 2); 460 - static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, 461 - show_enable, store_enable, 2); 462 - static SENSOR_DEVICE_ATTR(pwm4, S_IRUGO | S_IWUSR, 463 - show_pwm, store_pwm, 3); 464 - static SENSOR_DEVICE_ATTR(pwm4_enable, S_IRUGO | S_IWUSR, 465 - show_enable, store_enable, 3); 335 + static int nct7904_read(struct device *dev, enum hwmon_sensor_types type, 336 + u32 attr, int channel, long *val) 337 + { 338 + switch (type) { 339 + case hwmon_in: 340 + return nct7904_read_in(dev, attr, channel, val); 341 + case hwmon_fan: 342 + return nct7904_read_fan(dev, attr, channel, val); 343 + case hwmon_pwm: 344 + return nct7904_read_pwm(dev, attr, channel, val); 345 + case hwmon_temp: 346 + return nct7904_read_temp(dev, attr, channel, val); 347 + default: 348 + return -EOPNOTSUPP; 349 + } 350 + } 466 351 467 - static struct attribute *nct7904_fanctl_attrs[] = { 468 - &sensor_dev_attr_pwm1.dev_attr.attr, 469 - &sensor_dev_attr_pwm1_enable.dev_attr.attr, 470 - &sensor_dev_attr_pwm2.dev_attr.attr, 471 - &sensor_dev_attr_pwm2_enable.dev_attr.attr, 472 - &sensor_dev_attr_pwm3.dev_attr.attr, 473 - &sensor_dev_attr_pwm3_enable.dev_attr.attr, 474 - &sensor_dev_attr_pwm4.dev_attr.attr, 475 - &sensor_dev_attr_pwm4_enable.dev_attr.attr, 476 - NULL 477 - }; 352 + static int nct7904_write(struct device *dev, enum hwmon_sensor_types type, 353 + u32 attr, int channel, long val) 354 + { 355 + switch (type) { 356 + case hwmon_pwm: 357 + return nct7904_write_pwm(dev, attr, channel, val); 358 + default: 359 + return -EOPNOTSUPP; 360 + } 361 + } 478 362 479 - static const struct attribute_group nct7904_fanctl_group = { 480 - .attrs = nct7904_fanctl_attrs, 481 - }; 482 - 483 - static const struct attribute_group *nct7904_groups[] = { 484 - &nct7904_fanin_group, 485 - &nct7904_vsen_group, 486 - &nct7904_tcpu_group, 487 - &nct7904_fanctl_group, 488 - NULL 489 - }; 363 + static umode_t nct7904_is_visible(const void *data, 364 + enum hwmon_sensor_types type, 365 + u32 attr, int channel) 366 + { 367 + switch (type) { 368 + case hwmon_in: 369 + return nct7904_in_is_visible(data, attr, channel); 370 + case hwmon_fan: 371 + return nct7904_fan_is_visible(data, attr, channel); 372 + case hwmon_pwm: 373 + return nct7904_pwm_is_visible(data, attr, channel); 374 + case hwmon_temp: 375 + return nct7904_temp_is_visible(data, attr, channel); 376 + default: 377 + return 0; 378 + } 379 + } 490 380 491 381 /* Return 0 if detection is successful, -ENODEV otherwise */ 492 382 static int nct7904_detect(struct i2c_client *client, ··· 399 511 400 512 return 0; 401 513 } 514 + 515 + static const u32 nct7904_in_config[] = { 516 + HWMON_I_INPUT, /* dummy, skipped in is_visible */ 517 + HWMON_I_INPUT, 518 + HWMON_I_INPUT, 519 + HWMON_I_INPUT, 520 + HWMON_I_INPUT, 521 + HWMON_I_INPUT, 522 + HWMON_I_INPUT, 523 + HWMON_I_INPUT, 524 + HWMON_I_INPUT, 525 + HWMON_I_INPUT, 526 + HWMON_I_INPUT, 527 + HWMON_I_INPUT, 528 + HWMON_I_INPUT, 529 + HWMON_I_INPUT, 530 + HWMON_I_INPUT, 531 + HWMON_I_INPUT, 532 + HWMON_I_INPUT, 533 + HWMON_I_INPUT, 534 + HWMON_I_INPUT, 535 + HWMON_I_INPUT, 536 + HWMON_I_INPUT, 537 + 0 538 + }; 539 + 540 + static const struct hwmon_channel_info nct7904_in = { 541 + .type = hwmon_in, 542 + .config = nct7904_in_config, 543 + }; 544 + 545 + static const u32 nct7904_fan_config[] = { 546 + HWMON_F_INPUT, 547 + HWMON_F_INPUT, 548 + HWMON_F_INPUT, 549 + HWMON_F_INPUT, 550 + HWMON_F_INPUT, 551 + HWMON_F_INPUT, 552 + HWMON_F_INPUT, 553 + HWMON_F_INPUT, 554 + 0 555 + }; 556 + 557 + static const struct hwmon_channel_info nct7904_fan = { 558 + .type = hwmon_fan, 559 + .config = nct7904_fan_config, 560 + }; 561 + 562 + static const u32 nct7904_pwm_config[] = { 563 + HWMON_PWM_INPUT | HWMON_PWM_ENABLE, 564 + HWMON_PWM_INPUT | HWMON_PWM_ENABLE, 565 + HWMON_PWM_INPUT | HWMON_PWM_ENABLE, 566 + HWMON_PWM_INPUT | HWMON_PWM_ENABLE, 567 + 0 568 + }; 569 + 570 + static const struct hwmon_channel_info nct7904_pwm = { 571 + .type = hwmon_pwm, 572 + .config = nct7904_pwm_config, 573 + }; 574 + 575 + static const u32 nct7904_temp_config[] = { 576 + HWMON_T_INPUT, 577 + HWMON_T_INPUT, 578 + HWMON_T_INPUT, 579 + HWMON_T_INPUT, 580 + HWMON_T_INPUT, 581 + HWMON_T_INPUT, 582 + HWMON_T_INPUT, 583 + HWMON_T_INPUT, 584 + HWMON_T_INPUT, 585 + 0 586 + }; 587 + 588 + static const struct hwmon_channel_info nct7904_temp = { 589 + .type = hwmon_temp, 590 + .config = nct7904_temp_config, 591 + }; 592 + 593 + static const struct hwmon_channel_info *nct7904_info[] = { 594 + &nct7904_in, 595 + &nct7904_fan, 596 + &nct7904_pwm, 597 + &nct7904_temp, 598 + NULL 599 + }; 600 + 601 + static const struct hwmon_ops nct7904_hwmon_ops = { 602 + .is_visible = nct7904_is_visible, 603 + .read = nct7904_read, 604 + .write = nct7904_write, 605 + }; 606 + 607 + static const struct hwmon_chip_info nct7904_chip_info = { 608 + .ops = &nct7904_hwmon_ops, 609 + .info = nct7904_info, 610 + }; 402 611 403 612 static int nct7904_probe(struct i2c_client *client, 404 613 const struct i2c_device_id *id) ··· 551 566 } 552 567 553 568 hwmon_dev = 554 - devm_hwmon_device_register_with_groups(dev, client->name, data, 555 - nct7904_groups); 569 + devm_hwmon_device_register_with_info(dev, client->name, data, 570 + &nct7904_chip_info, NULL); 556 571 return PTR_ERR_OR_ZERO(hwmon_dev); 557 572 } 558 573