aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOscar Salvador <osalvador.vilardaga@gmail.com>2017-05-18 17:24:36 -0400
committerBen Skeggs <bskeggs@redhat.com>2017-06-16 00:05:02 -0400
commitbfb96e4c344e312858f53c9cad22150389a76cba (patch)
tree7bf0d1ab48e266452b7b65262b5eb677cd0de8ea
parentdbddaaf083e255958eee9debb441fb49f3dfc0e9 (diff)
drm/nouveau/hwmon: Remove old code, add .write/.read operations
This patch removes old code related to the old api and transforms the functions for the new api. It also adds the .write and .read operations. Signed-off-by: Oscar Salvador <osalvador.vilardaga@gmail.com> Reviewed-by: Martin Peres <martin.peres@free.fr> Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_hwmon.c844
1 files changed, 261 insertions, 583 deletions
diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c b/drivers/gpu/drm/nouveau/nouveau_hwmon.c
index 5ae3107d73df..bb0718579c2c 100644
--- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c
+++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c
@@ -38,21 +38,6 @@
38#include <nvkm/subdev/volt.h> 38#include <nvkm/subdev/volt.h>
39 39
40#if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE)) 40#if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
41static ssize_t
42nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char *buf)
43{
44 struct drm_device *dev = dev_get_drvdata(d);
45 struct nouveau_drm *drm = nouveau_drm(dev);
46 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
47 int temp = nvkm_therm_temp_get(therm);
48
49 if (temp < 0)
50 return temp;
51
52 return snprintf(buf, PAGE_SIZE, "%d\n", temp * 1000);
53}
54static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, nouveau_hwmon_show_temp,
55 NULL, 0);
56 41
57static ssize_t 42static ssize_t
58nouveau_hwmon_show_temp1_auto_point1_pwm(struct device *d, 43nouveau_hwmon_show_temp1_auto_point1_pwm(struct device *d,
@@ -130,234 +115,7 @@ static SENSOR_DEVICE_ATTR(temp1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
130 nouveau_hwmon_set_temp1_auto_point1_temp_hyst, 0); 115 nouveau_hwmon_set_temp1_auto_point1_temp_hyst, 0);
131 116
132static ssize_t 117static ssize_t
133nouveau_hwmon_max_temp(struct device *d, struct device_attribute *a, char *buf) 118nouveau_hwmon_get_pwm1_max(struct device *d,
134{
135 struct drm_device *dev = dev_get_drvdata(d);
136 struct nouveau_drm *drm = nouveau_drm(dev);
137 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
138
139 return snprintf(buf, PAGE_SIZE, "%d\n",
140 therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK) * 1000);
141}
142static ssize_t
143nouveau_hwmon_set_max_temp(struct device *d, struct device_attribute *a,
144 const char *buf, size_t count)
145{
146 struct drm_device *dev = dev_get_drvdata(d);
147 struct nouveau_drm *drm = nouveau_drm(dev);
148 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
149 long value;
150
151 if (kstrtol(buf, 10, &value) == -EINVAL)
152 return count;
153
154 therm->attr_set(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK, value / 1000);
155
156 return count;
157}
158static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, nouveau_hwmon_max_temp,
159 nouveau_hwmon_set_max_temp,
160 0);
161
162static ssize_t
163nouveau_hwmon_max_temp_hyst(struct device *d, struct device_attribute *a,
164 char *buf)
165{
166 struct drm_device *dev = dev_get_drvdata(d);
167 struct nouveau_drm *drm = nouveau_drm(dev);
168 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
169
170 return snprintf(buf, PAGE_SIZE, "%d\n",
171 therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK_HYST) * 1000);
172}
173static ssize_t
174nouveau_hwmon_set_max_temp_hyst(struct device *d, struct device_attribute *a,
175 const char *buf, size_t count)
176{
177 struct drm_device *dev = dev_get_drvdata(d);
178 struct nouveau_drm *drm = nouveau_drm(dev);
179 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
180 long value;
181
182 if (kstrtol(buf, 10, &value) == -EINVAL)
183 return count;
184
185 therm->attr_set(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK_HYST,
186 value / 1000);
187
188 return count;
189}
190static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
191 nouveau_hwmon_max_temp_hyst,
192 nouveau_hwmon_set_max_temp_hyst, 0);
193
194static ssize_t
195nouveau_hwmon_critical_temp(struct device *d, struct device_attribute *a,
196 char *buf)
197{
198 struct drm_device *dev = dev_get_drvdata(d);
199 struct nouveau_drm *drm = nouveau_drm(dev);
200 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
201
202 return snprintf(buf, PAGE_SIZE, "%d\n",
203 therm->attr_get(therm, NVKM_THERM_ATTR_THRS_CRITICAL) * 1000);
204}
205static ssize_t
206nouveau_hwmon_set_critical_temp(struct device *d, struct device_attribute *a,
207 const char *buf,
208 size_t count)
209{
210 struct drm_device *dev = dev_get_drvdata(d);
211 struct nouveau_drm *drm = nouveau_drm(dev);
212 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
213 long value;
214
215 if (kstrtol(buf, 10, &value) == -EINVAL)
216 return count;
217
218 therm->attr_set(therm, NVKM_THERM_ATTR_THRS_CRITICAL, value / 1000);
219
220 return count;
221}
222static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO | S_IWUSR,
223 nouveau_hwmon_critical_temp,
224 nouveau_hwmon_set_critical_temp,
225 0);
226
227static ssize_t
228nouveau_hwmon_critical_temp_hyst(struct device *d, struct device_attribute *a,
229 char *buf)
230{
231 struct drm_device *dev = dev_get_drvdata(d);
232 struct nouveau_drm *drm = nouveau_drm(dev);
233 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
234
235 return snprintf(buf, PAGE_SIZE, "%d\n",
236 therm->attr_get(therm, NVKM_THERM_ATTR_THRS_CRITICAL_HYST) * 1000);
237}
238static ssize_t
239nouveau_hwmon_set_critical_temp_hyst(struct device *d,
240 struct device_attribute *a,
241 const char *buf,
242 size_t count)
243{
244 struct drm_device *dev = dev_get_drvdata(d);
245 struct nouveau_drm *drm = nouveau_drm(dev);
246 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
247 long value;
248
249 if (kstrtol(buf, 10, &value) == -EINVAL)
250 return count;
251
252 therm->attr_set(therm, NVKM_THERM_ATTR_THRS_CRITICAL_HYST,
253 value / 1000);
254
255 return count;
256}
257static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO | S_IWUSR,
258 nouveau_hwmon_critical_temp_hyst,
259 nouveau_hwmon_set_critical_temp_hyst, 0);
260static ssize_t
261nouveau_hwmon_emergency_temp(struct device *d, struct device_attribute *a,
262 char *buf)
263{
264 struct drm_device *dev = dev_get_drvdata(d);
265 struct nouveau_drm *drm = nouveau_drm(dev);
266 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
267
268 return snprintf(buf, PAGE_SIZE, "%d\n",
269 therm->attr_get(therm, NVKM_THERM_ATTR_THRS_SHUTDOWN) * 1000);
270}
271static ssize_t
272nouveau_hwmon_set_emergency_temp(struct device *d, struct device_attribute *a,
273 const char *buf,
274 size_t count)
275{
276 struct drm_device *dev = dev_get_drvdata(d);
277 struct nouveau_drm *drm = nouveau_drm(dev);
278 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
279 long value;
280
281 if (kstrtol(buf, 10, &value) == -EINVAL)
282 return count;
283
284 therm->attr_set(therm, NVKM_THERM_ATTR_THRS_SHUTDOWN, value / 1000);
285
286 return count;
287}
288static SENSOR_DEVICE_ATTR(temp1_emergency, S_IRUGO | S_IWUSR,
289 nouveau_hwmon_emergency_temp,
290 nouveau_hwmon_set_emergency_temp,
291 0);
292
293static ssize_t
294nouveau_hwmon_emergency_temp_hyst(struct device *d, struct device_attribute *a,
295 char *buf)
296{
297 struct drm_device *dev = dev_get_drvdata(d);
298 struct nouveau_drm *drm = nouveau_drm(dev);
299 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
300
301 return snprintf(buf, PAGE_SIZE, "%d\n",
302 therm->attr_get(therm, NVKM_THERM_ATTR_THRS_SHUTDOWN_HYST) * 1000);
303}
304static ssize_t
305nouveau_hwmon_set_emergency_temp_hyst(struct device *d,
306 struct device_attribute *a,
307 const char *buf,
308 size_t count)
309{
310 struct drm_device *dev = dev_get_drvdata(d);
311 struct nouveau_drm *drm = nouveau_drm(dev);
312 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
313 long value;
314
315 if (kstrtol(buf, 10, &value) == -EINVAL)
316 return count;
317
318 therm->attr_set(therm, NVKM_THERM_ATTR_THRS_SHUTDOWN_HYST,
319 value / 1000);
320
321 return count;
322}
323static SENSOR_DEVICE_ATTR(temp1_emergency_hyst, S_IRUGO | S_IWUSR,
324 nouveau_hwmon_emergency_temp_hyst,
325 nouveau_hwmon_set_emergency_temp_hyst,
326 0);
327
328static ssize_t nouveau_hwmon_show_name(struct device *dev,
329 struct device_attribute *attr,
330 char *buf)
331{
332 return sprintf(buf, "nouveau\n");
333}
334static SENSOR_DEVICE_ATTR(name, S_IRUGO, nouveau_hwmon_show_name, NULL, 0);
335
336static ssize_t nouveau_hwmon_show_update_rate(struct device *dev,
337 struct device_attribute *attr,
338 char *buf)
339{
340 return sprintf(buf, "1000\n");
341}
342static SENSOR_DEVICE_ATTR(update_rate, S_IRUGO,
343 nouveau_hwmon_show_update_rate,
344 NULL, 0);
345
346static ssize_t
347nouveau_hwmon_show_fan1_input(struct device *d, struct device_attribute *attr,
348 char *buf)
349{
350 struct drm_device *dev = dev_get_drvdata(d);
351 struct nouveau_drm *drm = nouveau_drm(dev);
352 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
353
354 return snprintf(buf, PAGE_SIZE, "%d\n", nvkm_therm_fan_sense(therm));
355}
356static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, nouveau_hwmon_show_fan1_input,
357 NULL, 0);
358
359 static ssize_t
360nouveau_hwmon_get_pwm1_enable(struct device *d,
361 struct device_attribute *a, char *buf) 119 struct device_attribute *a, char *buf)
362{ 120{
363 struct drm_device *dev = dev_get_drvdata(d); 121 struct drm_device *dev = dev_get_drvdata(d);
@@ -365,46 +123,7 @@ nouveau_hwmon_get_pwm1_enable(struct device *d,
365 struct nvkm_therm *therm = nvxx_therm(&drm->client.device); 123 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
366 int ret; 124 int ret;
367 125
368 ret = therm->attr_get(therm, NVKM_THERM_ATTR_FAN_MODE); 126 ret = therm->attr_get(therm, NVKM_THERM_ATTR_FAN_MAX_DUTY);
369 if (ret < 0)
370 return ret;
371
372 return sprintf(buf, "%i\n", ret);
373}
374
375static ssize_t
376nouveau_hwmon_set_pwm1_enable(struct device *d, struct device_attribute *a,
377 const char *buf, size_t count)
378{
379 struct drm_device *dev = dev_get_drvdata(d);
380 struct nouveau_drm *drm = nouveau_drm(dev);
381 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
382 long value;
383 int ret;
384
385 ret = kstrtol(buf, 10, &value);
386 if (ret)
387 return ret;
388
389 ret = therm->attr_set(therm, NVKM_THERM_ATTR_FAN_MODE, value);
390 if (ret)
391 return ret;
392 else
393 return count;
394}
395static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
396 nouveau_hwmon_get_pwm1_enable,
397 nouveau_hwmon_set_pwm1_enable, 0);
398
399static ssize_t
400nouveau_hwmon_get_pwm1(struct device *d, struct device_attribute *a, char *buf)
401{
402 struct drm_device *dev = dev_get_drvdata(d);
403 struct nouveau_drm *drm = nouveau_drm(dev);
404 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
405 int ret;
406
407 ret = therm->fan_get(therm);
408 if (ret < 0) 127 if (ret < 0)
409 return ret; 128 return ret;
410 129
@@ -412,30 +131,6 @@ nouveau_hwmon_get_pwm1(struct device *d, struct device_attribute *a, char *buf)
412} 131}
413 132
414static ssize_t 133static ssize_t
415nouveau_hwmon_set_pwm1(struct device *d, struct device_attribute *a,
416 const char *buf, size_t count)
417{
418 struct drm_device *dev = dev_get_drvdata(d);
419 struct nouveau_drm *drm = nouveau_drm(dev);
420 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
421 int ret = -ENODEV;
422 long value;
423
424 if (kstrtol(buf, 10, &value) == -EINVAL)
425 return -EINVAL;
426
427 ret = therm->fan_set(therm, value);
428 if (ret)
429 return ret;
430
431 return count;
432}
433
434static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR,
435 nouveau_hwmon_get_pwm1,
436 nouveau_hwmon_set_pwm1, 0);
437
438static ssize_t
439nouveau_hwmon_get_pwm1_min(struct device *d, 134nouveau_hwmon_get_pwm1_min(struct device *d,
440 struct device_attribute *a, char *buf) 135 struct device_attribute *a, char *buf)
441{ 136{
@@ -470,28 +165,11 @@ nouveau_hwmon_set_pwm1_min(struct device *d, struct device_attribute *a,
470 165
471 return count; 166 return count;
472} 167}
473
474static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO | S_IWUSR, 168static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO | S_IWUSR,
475 nouveau_hwmon_get_pwm1_min, 169 nouveau_hwmon_get_pwm1_min,
476 nouveau_hwmon_set_pwm1_min, 0); 170 nouveau_hwmon_set_pwm1_min, 0);
477 171
478static ssize_t 172static ssize_t
479nouveau_hwmon_get_pwm1_max(struct device *d,
480 struct device_attribute *a, char *buf)
481{
482 struct drm_device *dev = dev_get_drvdata(d);
483 struct nouveau_drm *drm = nouveau_drm(dev);
484 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
485 int ret;
486
487 ret = therm->attr_get(therm, NVKM_THERM_ATTR_FAN_MAX_DUTY);
488 if (ret < 0)
489 return ret;
490
491 return sprintf(buf, "%i\n", ret);
492}
493
494static ssize_t
495nouveau_hwmon_set_pwm1_max(struct device *d, struct device_attribute *a, 173nouveau_hwmon_set_pwm1_max(struct device *d, struct device_attribute *a,
496 const char *buf, size_t count) 174 const char *buf, size_t count)
497{ 175{
@@ -510,189 +188,10 @@ nouveau_hwmon_set_pwm1_max(struct device *d, struct device_attribute *a,
510 188
511 return count; 189 return count;
512} 190}
513
514static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO | S_IWUSR, 191static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO | S_IWUSR,
515 nouveau_hwmon_get_pwm1_max, 192 nouveau_hwmon_get_pwm1_max,
516 nouveau_hwmon_set_pwm1_max, 0); 193 nouveau_hwmon_set_pwm1_max, 0);
517 194
518static ssize_t
519nouveau_hwmon_get_in0_input(struct device *d,
520 struct device_attribute *a, char *buf)
521{
522 struct drm_device *dev = dev_get_drvdata(d);
523 struct nouveau_drm *drm = nouveau_drm(dev);
524 struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
525 int ret;
526
527 ret = nvkm_volt_get(volt);
528 if (ret < 0)
529 return ret;
530
531 return sprintf(buf, "%i\n", ret / 1000);
532}
533
534static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO,
535 nouveau_hwmon_get_in0_input, NULL, 0);
536
537static ssize_t
538nouveau_hwmon_get_in0_min(struct device *d,
539 struct device_attribute *a, char *buf)
540{
541 struct drm_device *dev = dev_get_drvdata(d);
542 struct nouveau_drm *drm = nouveau_drm(dev);
543 struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
544
545 if (!volt || !volt->min_uv)
546 return -ENODEV;
547
548 return sprintf(buf, "%i\n", volt->min_uv / 1000);
549}
550
551static SENSOR_DEVICE_ATTR(in0_min, S_IRUGO,
552 nouveau_hwmon_get_in0_min, NULL, 0);
553
554static ssize_t
555nouveau_hwmon_get_in0_max(struct device *d,
556 struct device_attribute *a, char *buf)
557{
558 struct drm_device *dev = dev_get_drvdata(d);
559 struct nouveau_drm *drm = nouveau_drm(dev);
560 struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
561
562 if (!volt || !volt->max_uv)
563 return -ENODEV;
564
565 return sprintf(buf, "%i\n", volt->max_uv / 1000);
566}
567
568static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO,
569 nouveau_hwmon_get_in0_max, NULL, 0);
570
571static ssize_t
572nouveau_hwmon_get_in0_label(struct device *d,
573 struct device_attribute *a, char *buf)
574{
575 return sprintf(buf, "GPU core\n");
576}
577
578static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO,
579 nouveau_hwmon_get_in0_label, NULL, 0);
580
581static ssize_t
582nouveau_hwmon_get_power1_input(struct device *d, struct device_attribute *a,
583 char *buf)
584{
585 struct drm_device *dev = dev_get_drvdata(d);
586 struct nouveau_drm *drm = nouveau_drm(dev);
587 struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
588 int result = nvkm_iccsense_read_all(iccsense);
589
590 if (result < 0)
591 return result;
592
593 return sprintf(buf, "%i\n", result);
594}
595
596static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO,
597 nouveau_hwmon_get_power1_input, NULL, 0);
598
599static ssize_t
600nouveau_hwmon_get_power1_max(struct device *d, struct device_attribute *a,
601 char *buf)
602{
603 struct drm_device *dev = dev_get_drvdata(d);
604 struct nouveau_drm *drm = nouveau_drm(dev);
605 struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
606 return sprintf(buf, "%i\n", iccsense->power_w_max);
607}
608
609static SENSOR_DEVICE_ATTR(power1_max, S_IRUGO,
610 nouveau_hwmon_get_power1_max, NULL, 0);
611
612static ssize_t
613nouveau_hwmon_get_power1_crit(struct device *d, struct device_attribute *a,
614 char *buf)
615{
616 struct drm_device *dev = dev_get_drvdata(d);
617 struct nouveau_drm *drm = nouveau_drm(dev);
618 struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
619 return sprintf(buf, "%i\n", iccsense->power_w_crit);
620}
621
622static SENSOR_DEVICE_ATTR(power1_crit, S_IRUGO,
623 nouveau_hwmon_get_power1_crit, NULL, 0);
624
625static struct attribute *hwmon_default_attributes[] = {
626 &sensor_dev_attr_name.dev_attr.attr,
627 &sensor_dev_attr_update_rate.dev_attr.attr,
628 NULL
629};
630static struct attribute *hwmon_temp_attributes[] = {
631 &sensor_dev_attr_temp1_input.dev_attr.attr,
632 &sensor_dev_attr_temp1_auto_point1_pwm.dev_attr.attr,
633 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
634 &sensor_dev_attr_temp1_auto_point1_temp_hyst.dev_attr.attr,
635 &sensor_dev_attr_temp1_max.dev_attr.attr,
636 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
637 &sensor_dev_attr_temp1_crit.dev_attr.attr,
638 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
639 &sensor_dev_attr_temp1_emergency.dev_attr.attr,
640 &sensor_dev_attr_temp1_emergency_hyst.dev_attr.attr,
641 NULL
642};
643static struct attribute *hwmon_fan_rpm_attributes[] = {
644 &sensor_dev_attr_fan1_input.dev_attr.attr,
645 NULL
646};
647static struct attribute *hwmon_pwm_fan_attributes[] = {
648 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
649 &sensor_dev_attr_pwm1.dev_attr.attr,
650 &sensor_dev_attr_pwm1_min.dev_attr.attr,
651 &sensor_dev_attr_pwm1_max.dev_attr.attr,
652 NULL
653};
654
655static struct attribute *hwmon_in0_attributes[] = {
656 &sensor_dev_attr_in0_input.dev_attr.attr,
657 &sensor_dev_attr_in0_min.dev_attr.attr,
658 &sensor_dev_attr_in0_max.dev_attr.attr,
659 &sensor_dev_attr_in0_label.dev_attr.attr,
660 NULL
661};
662
663static struct attribute *hwmon_power_attributes[] = {
664 &sensor_dev_attr_power1_input.dev_attr.attr,
665 NULL
666};
667
668static struct attribute *hwmon_power_caps_attributes[] = {
669 &sensor_dev_attr_power1_max.dev_attr.attr,
670 &sensor_dev_attr_power1_crit.dev_attr.attr,
671 NULL
672};
673
674static const struct attribute_group hwmon_default_attrgroup = {
675 .attrs = hwmon_default_attributes,
676};
677static const struct attribute_group hwmon_temp_attrgroup = {
678 .attrs = hwmon_temp_attributes,
679};
680static const struct attribute_group hwmon_fan_rpm_attrgroup = {
681 .attrs = hwmon_fan_rpm_attributes,
682};
683static const struct attribute_group hwmon_pwm_fan_attrgroup = {
684 .attrs = hwmon_pwm_fan_attributes,
685};
686static const struct attribute_group hwmon_in0_attrgroup = {
687 .attrs = hwmon_in0_attributes,
688};
689static const struct attribute_group hwmon_power_attrgroup = {
690 .attrs = hwmon_power_attributes,
691};
692static const struct attribute_group hwmon_power_caps_attrgroup = {
693 .attrs = hwmon_power_caps_attributes,
694};
695
696static const u32 nouveau_config_chip[] = { 195static const u32 nouveau_config_chip[] = {
697 HWMON_C_UPDATE_INTERVAL, 196 HWMON_C_UPDATE_INTERVAL,
698 0 197 0
@@ -812,13 +311,14 @@ nouveau_temp_is_visible(const void *data, u32 attr, int channel)
812 311
813 switch (attr) { 312 switch (attr) {
814 case hwmon_temp_input: 313 case hwmon_temp_input:
314 return 0444;
815 case hwmon_temp_max: 315 case hwmon_temp_max:
816 case hwmon_temp_max_hyst: 316 case hwmon_temp_max_hyst:
817 case hwmon_temp_crit: 317 case hwmon_temp_crit:
818 case hwmon_temp_crit_hyst: 318 case hwmon_temp_crit_hyst:
819 case hwmon_temp_emergency: 319 case hwmon_temp_emergency:
820 case hwmon_temp_emergency_hyst: 320 case hwmon_temp_emergency_hyst:
821 return 0444; 321 return 0644;
822 default: 322 default:
823 return 0; 323 return 0;
824 } 324 }
@@ -880,6 +380,222 @@ nouveau_fan_is_visible(const void *data, u32 attr, int channel)
880 } 380 }
881} 381}
882 382
383static int
384nouveau_chip_read(struct device *dev, u32 attr, int channel, long *val)
385{
386 switch (attr) {
387 case hwmon_chip_update_interval:
388 *val = 1000;
389 break;
390 default:
391 return -EOPNOTSUPP;
392 }
393
394 return 0;
395}
396
397static int
398nouveau_temp_read(struct device *dev, u32 attr, int channel, long *val)
399{
400 struct drm_device *drm_dev = dev_get_drvdata(dev);
401 struct nouveau_drm *drm = nouveau_drm(drm_dev);
402 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
403 int ret;
404
405 if (!therm || !therm->attr_get)
406 return -EOPNOTSUPP;
407
408 switch (attr) {
409 case hwmon_temp_input:
410 ret = nvkm_therm_temp_get(therm);
411 *val = ret < 0 ? ret : (ret * 1000);
412 break;
413 case hwmon_temp_max:
414 *val = therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK)
415 * 1000;
416 break;
417 case hwmon_temp_max_hyst:
418 *val = therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK_HYST)
419 * 1000;
420 break;
421 case hwmon_temp_crit:
422 *val = therm->attr_get(therm, NVKM_THERM_ATTR_THRS_CRITICAL)
423 * 1000;
424 break;
425 case hwmon_temp_crit_hyst:
426 *val = therm->attr_get(therm, NVKM_THERM_ATTR_THRS_CRITICAL_HYST)
427 * 1000;
428 break;
429 case hwmon_temp_emergency:
430 *val = therm->attr_get(therm, NVKM_THERM_ATTR_THRS_SHUTDOWN)
431 * 1000;
432 break;
433 case hwmon_temp_emergency_hyst:
434 *val = therm->attr_get(therm, NVKM_THERM_ATTR_THRS_SHUTDOWN_HYST)
435 * 1000;
436 break;
437 default:
438 return -EOPNOTSUPP;
439 }
440
441 return 0;
442}
443
444static int
445nouveau_fan_read(struct device *dev, u32 attr, int channel, long *val)
446{
447 struct drm_device *drm_dev = dev_get_drvdata(dev);
448 struct nouveau_drm *drm = nouveau_drm(drm_dev);
449 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
450
451 if (!therm)
452 return -EOPNOTSUPP;
453
454 switch (attr) {
455 case hwmon_fan_input:
456 *val = nvkm_therm_fan_sense(therm);
457 break;
458 default:
459 return -EOPNOTSUPP;
460 }
461
462 return 0;
463}
464
465static int
466nouveau_in_read(struct device *dev, u32 attr, int channel, long *val)
467{
468 struct drm_device *drm_dev = dev_get_drvdata(dev);
469 struct nouveau_drm *drm = nouveau_drm(drm_dev);
470 struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
471 int ret;
472
473 if (!volt)
474 return -EOPNOTSUPP;
475
476 switch (attr) {
477 case hwmon_in_input:
478 ret = nvkm_volt_get(volt);
479 *val = ret < 0 ? ret : (ret / 1000);
480 break;
481 case hwmon_in_min:
482 *val = volt->min_uv > 0 ? (volt->min_uv / 1000) : -ENODEV;
483 break;
484 case hwmon_in_max:
485 *val = volt->max_uv > 0 ? (volt->max_uv / 1000) : -ENODEV;
486 break;
487 default:
488 return -EOPNOTSUPP;
489 }
490
491 return 0;
492}
493
494static int
495nouveau_pwm_read(struct device *dev, u32 attr, int channel, long *val)
496{
497 struct drm_device *drm_dev = dev_get_drvdata(dev);
498 struct nouveau_drm *drm = nouveau_drm(drm_dev);
499 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
500
501 if (!therm || !therm->attr_get || !therm->fan_get)
502 return -EOPNOTSUPP;
503
504 switch (attr) {
505 case hwmon_pwm_enable:
506 *val = therm->attr_get(therm, NVKM_THERM_ATTR_FAN_MODE);
507 break;
508 case hwmon_pwm_input:
509 *val = therm->fan_get(therm);
510 break;
511 default:
512 return -EOPNOTSUPP;
513 }
514
515 return 0;
516}
517
518static int
519nouveau_power_read(struct device *dev, u32 attr, int channel, long *val)
520{
521 struct drm_device *drm_dev = dev_get_drvdata(dev);
522 struct nouveau_drm *drm = nouveau_drm(drm_dev);
523 struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
524
525 if (!iccsense)
526 return -EOPNOTSUPP;
527
528 switch (attr) {
529 case hwmon_power_input:
530 *val = nvkm_iccsense_read_all(iccsense);
531 break;
532 case hwmon_power_max:
533 *val = iccsense->power_w_max;
534 break;
535 case hwmon_power_crit:
536 *val = iccsense->power_w_crit;
537 break;
538 default:
539 return -EOPNOTSUPP;
540 }
541
542 return 0;
543}
544
545static int
546nouveau_temp_write(struct device *dev, u32 attr, int channel, long val)
547{
548 struct drm_device *drm_dev = dev_get_drvdata(dev);
549 struct nouveau_drm *drm = nouveau_drm(drm_dev);
550 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
551
552 if (!therm || !therm->attr_set)
553 return -EOPNOTSUPP;
554
555 switch (attr) {
556 case hwmon_temp_max:
557 return therm->attr_set(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK,
558 val / 1000);
559 case hwmon_temp_max_hyst:
560 return therm->attr_set(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK_HYST,
561 val / 1000);
562 case hwmon_temp_crit:
563 return therm->attr_set(therm, NVKM_THERM_ATTR_THRS_CRITICAL,
564 val / 1000);
565 case hwmon_temp_crit_hyst:
566 return therm->attr_set(therm, NVKM_THERM_ATTR_THRS_CRITICAL_HYST,
567 val / 1000);
568 case hwmon_temp_emergency:
569 return therm->attr_set(therm, NVKM_THERM_ATTR_THRS_SHUTDOWN,
570 val / 1000);
571 case hwmon_temp_emergency_hyst:
572 return therm->attr_set(therm, NVKM_THERM_ATTR_THRS_SHUTDOWN_HYST,
573 val / 1000);
574 default:
575 return -EOPNOTSUPP;
576 }
577}
578
579static int
580nouveau_pwm_write(struct device *dev, u32 attr, int channel, long val)
581{
582 struct drm_device *drm_dev = dev_get_drvdata(dev);
583 struct nouveau_drm *drm = nouveau_drm(drm_dev);
584 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
585
586 if (!therm || !therm->attr_set)
587 return -EOPNOTSUPP;
588
589 switch (attr) {
590 case hwmon_pwm_input:
591 return therm->fan_set(therm, val);
592 case hwmon_pwm_enable:
593 return therm->attr_set(therm, NVKM_THERM_ATTR_FAN_MODE, val);
594 default:
595 return -EOPNOTSUPP;
596 }
597}
598
883static umode_t 599static umode_t
884nouveau_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, 600nouveau_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr,
885 int channel) 601 int channel)
@@ -916,11 +632,47 @@ nouveau_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
916 return -EOPNOTSUPP; 632 return -EOPNOTSUPP;
917} 633}
918 634
635static int
636nouveau_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
637 int channel, long *val)
638{
639 switch (type) {
640 case hwmon_chip:
641 return nouveau_chip_read(dev, attr, channel, val);
642 case hwmon_temp:
643 return nouveau_temp_read(dev, attr, channel, val);
644 case hwmon_fan:
645 return nouveau_fan_read(dev, attr, channel, val);
646 case hwmon_in:
647 return nouveau_in_read(dev, attr, channel, val);
648 case hwmon_pwm:
649 return nouveau_pwm_read(dev, attr, channel, val);
650 case hwmon_power:
651 return nouveau_power_read(dev, attr, channel, val);
652 default:
653 return -EOPNOTSUPP;
654 }
655}
656
657static int
658nouveau_write(struct device *dev, enum hwmon_sensor_types type, u32 attr,
659 int channel, long val)
660{
661 switch (type) {
662 case hwmon_temp:
663 return nouveau_temp_write(dev, attr, channel, val);
664 case hwmon_pwm:
665 return nouveau_pwm_write(dev, attr, channel, val);
666 default:
667 return -EOPNOTSUPP;
668 }
669}
670
919static const struct hwmon_ops nouveau_hwmon_ops = { 671static const struct hwmon_ops nouveau_hwmon_ops = {
920 .is_visible = nouveau_is_visible, 672 .is_visible = nouveau_is_visible,
921 .read = NULL, 673 .read = nouveau_read,
922 .read_string = nouveau_read_string, 674 .read_string = nouveau_read_string,
923 .write = NULL, 675 .write = nouveau_write,
924}; 676};
925 677
926static const struct hwmon_chip_info nouveau_chip_info = { 678static const struct hwmon_chip_info nouveau_chip_info = {
@@ -935,8 +687,6 @@ nouveau_hwmon_init(struct drm_device *dev)
935#if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE)) 687#if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
936 struct nouveau_drm *drm = nouveau_drm(dev); 688 struct nouveau_drm *drm = nouveau_drm(dev);
937 struct nvkm_therm *therm = nvxx_therm(&drm->client.device); 689 struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
938 struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
939 struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
940 struct nouveau_hwmon *hwmon; 690 struct nouveau_hwmon *hwmon;
941 struct device *hwmon_dev; 691 struct device *hwmon_dev;
942 int ret = 0; 692 int ret = 0;
@@ -946,79 +696,16 @@ nouveau_hwmon_init(struct drm_device *dev)
946 return -ENOMEM; 696 return -ENOMEM;
947 hwmon->dev = dev; 697 hwmon->dev = dev;
948 698
949 hwmon_dev = hwmon_device_register(dev->dev); 699 hwmon_dev = hwmon_device_register_with_info(dev->dev, "nouveau", dev,
700 &nouveau_chip_info, NULL);
950 if (IS_ERR(hwmon_dev)) { 701 if (IS_ERR(hwmon_dev)) {
951 ret = PTR_ERR(hwmon_dev); 702 ret = PTR_ERR(hwmon_dev);
952 NV_ERROR(drm, "Unable to register hwmon device: %d\n", ret); 703 NV_ERROR(drm, "Unable to register hwmon device: %d\n", ret);
953 return ret; 704 return ret;
954 } 705 }
955 dev_set_drvdata(hwmon_dev, dev);
956
957 /* set the default attributes */
958 ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_default_attrgroup);
959 if (ret)
960 goto error;
961
962 if (therm && therm->attr_get && therm->attr_set) {
963 /* if the card has a working thermal sensor */
964 if (nvkm_therm_temp_get(therm) >= 0) {
965 ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_temp_attrgroup);
966 if (ret)
967 goto error;
968 }
969
970 /* if the card has a pwm fan */
971 /*XXX: incorrect, need better detection for this, some boards have
972 * the gpio entries for pwm fan control even when there's no
973 * actual fan connected to it... therm table? */
974 if (therm->fan_get && therm->fan_get(therm) >= 0) {
975 ret = sysfs_create_group(&hwmon_dev->kobj,
976 &hwmon_pwm_fan_attrgroup);
977 if (ret)
978 goto error;
979 }
980 }
981
982 /* if the card can read the fan rpm */
983 if (therm && nvkm_therm_fan_sense(therm) >= 0) {
984 ret = sysfs_create_group(&hwmon_dev->kobj,
985 &hwmon_fan_rpm_attrgroup);
986 if (ret)
987 goto error;
988 }
989
990 if (volt && nvkm_volt_get(volt) >= 0) {
991 ret = sysfs_create_group(&hwmon_dev->kobj,
992 &hwmon_in0_attrgroup);
993
994 if (ret)
995 goto error;
996 }
997
998 if (iccsense && iccsense->data_valid && !list_empty(&iccsense->rails)) {
999 ret = sysfs_create_group(&hwmon_dev->kobj,
1000 &hwmon_power_attrgroup);
1001
1002 if (ret)
1003 goto error;
1004
1005 if (iccsense->power_w_max && iccsense->power_w_crit) {
1006 ret = sysfs_create_group(&hwmon_dev->kobj,
1007 &hwmon_power_caps_attrgroup);
1008 if (ret)
1009 goto error;
1010 }
1011 }
1012 706
1013 hwmon->hwmon = hwmon_dev; 707 hwmon->hwmon = hwmon_dev;
1014
1015 return 0; 708 return 0;
1016
1017error:
1018 NV_ERROR(drm, "Unable to create some hwmon sysfs files: %d\n", ret);
1019 hwmon_device_unregister(hwmon_dev);
1020 hwmon->hwmon = NULL;
1021 return ret;
1022#else 709#else
1023 return 0; 710 return 0;
1024#endif 711#endif
@@ -1030,17 +717,8 @@ nouveau_hwmon_fini(struct drm_device *dev)
1030#if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE)) 717#if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
1031 struct nouveau_hwmon *hwmon = nouveau_hwmon(dev); 718 struct nouveau_hwmon *hwmon = nouveau_hwmon(dev);
1032 719
1033 if (hwmon->hwmon) { 720 if (hwmon->hwmon)
1034 sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_default_attrgroup);
1035 sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_temp_attrgroup);
1036 sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_pwm_fan_attrgroup);
1037 sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_fan_rpm_attrgroup);
1038 sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_in0_attrgroup);
1039 sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_power_attrgroup);
1040 sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_power_caps_attrgroup);
1041
1042 hwmon_device_unregister(hwmon->hwmon); 721 hwmon_device_unregister(hwmon->hwmon);
1043 }
1044 722
1045 nouveau_drm(dev)->hwmon = NULL; 723 nouveau_drm(dev)->hwmon = NULL;
1046 kfree(hwmon); 724 kfree(hwmon);