| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ug.c,v 1.12 2011/06/20 18:12:06 pgoyette Exp $ */ | | 1 | /* $NetBSD: ug.c,v 1.13 2018/06/03 10:04:40 maxv Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2007 Mihai Chelaru <kefren@netbsd.ro> | | 4 | * Copyright (c) 2007 Mihai Chelaru <kefren@netbsd.ro> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -16,27 +16,27 @@ | | | @@ -16,27 +16,27 @@ |
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | | 26 | */ |
27 | | | 27 | |
28 | #include <sys/cdefs.h> | | 28 | #include <sys/cdefs.h> |
29 | __KERNEL_RCSID(0, "$NetBSD: ug.c,v 1.12 2011/06/20 18:12:06 pgoyette Exp $"); | | 29 | __KERNEL_RCSID(0, "$NetBSD: ug.c,v 1.13 2018/06/03 10:04:40 maxv Exp $"); |
30 | | | 30 | |
31 | #include <sys/param.h> | | 31 | #include <sys/param.h> |
32 | #include <sys/systm.h> | | 32 | #include <sys/systm.h> |
33 | #include <sys/kernel.h> | | 33 | #include <sys/kernel.h> |
34 | #include <sys/proc.h> | | 34 | #include <sys/proc.h> |
35 | #include <sys/device.h> | | 35 | #include <sys/device.h> |
36 | #include <sys/malloc.h> | | 36 | #include <sys/malloc.h> |
37 | #include <sys/errno.h> | | 37 | #include <sys/errno.h> |
38 | #include <sys/conf.h> | | 38 | #include <sys/conf.h> |
39 | #include <sys/envsys.h> | | 39 | #include <sys/envsys.h> |
40 | #include <sys/time.h> | | 40 | #include <sys/time.h> |
41 | | | 41 | |
42 | #include <sys/bus.h> | | 42 | #include <sys/bus.h> |
| @@ -46,27 +46,27 @@ __KERNEL_RCSID(0, "$NetBSD: ug.c,v 1.12 | | | @@ -46,27 +46,27 @@ __KERNEL_RCSID(0, "$NetBSD: ug.c,v 1.12 |
46 | #include <dev/isa/isavar.h> | | 46 | #include <dev/isa/isavar.h> |
47 | | | 47 | |
48 | #include <dev/sysmon/sysmonvar.h> | | 48 | #include <dev/sysmon/sysmonvar.h> |
49 | | | 49 | |
50 | #include <dev/ic/ugreg.h> | | 50 | #include <dev/ic/ugreg.h> |
51 | #include <dev/ic/ugvar.h> | | 51 | #include <dev/ic/ugvar.h> |
52 | | | 52 | |
53 | uint8_t ug_ver; | | 53 | uint8_t ug_ver; |
54 | | | 54 | |
55 | /* | | 55 | /* |
56 | * Imported from linux driver | | 56 | * Imported from linux driver |
57 | */ | | 57 | */ |
58 | | | 58 | |
59 | struct ug2_motherboard_info ug2_mb[] = { | | 59 | static const struct ug2_motherboard_info ug2_mb[] = { |
60 | { 0x000C, "unknown. Please send-pr(1)", { | | 60 | { 0x000C, "unknown. Please send-pr(1)", { |
61 | { "CPU Core", 0, 0, 10, 1, 0 }, | | 61 | { "CPU Core", 0, 0, 10, 1, 0 }, |
62 | { "DDR", 1, 0, 10, 1, 0 }, | | 62 | { "DDR", 1, 0, 10, 1, 0 }, |
63 | { "DDR VTT", 2, 0, 10, 1, 0 }, | | 63 | { "DDR VTT", 2, 0, 10, 1, 0 }, |
64 | { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, | | 64 | { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, |
65 | { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 }, | | 65 | { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 }, |
66 | { "MCH 2.5V", 5, 0, 20, 1, 0 }, | | 66 | { "MCH 2.5V", 5, 0, 20, 1, 0 }, |
67 | { "ICH 1.05V", 6, 0, 10, 1, 0 }, | | 67 | { "ICH 1.05V", 6, 0, 10, 1, 0 }, |
68 | { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, | | 68 | { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, |
69 | { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, | | 69 | { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, |
70 | { "ATX +5V", 9, 0, 30, 1, 0 }, | | 70 | { "ATX +5V", 9, 0, 30, 1, 0 }, |
71 | { "+3.3V", 10, 0, 20, 1, 0 }, | | 71 | { "+3.3V", 10, 0, 20, 1, 0 }, |
72 | { "5VSB", 11, 0, 30, 1, 0 }, | | 72 | { "5VSB", 11, 0, 30, 1, 0 }, |
| @@ -475,51 +475,51 @@ ug_refresh(struct sysmon_envsys *sme, en | | | @@ -475,51 +475,51 @@ ug_refresh(struct sysmon_envsys *sme, en |
475 | | | 475 | |
476 | /* and Fans */ | | 476 | /* and Fans */ |
477 | if (edata->sensor >= UG_FAN_MIN) | | 477 | if (edata->sensor >= UG_FAN_MIN) |
478 | edata->value_cur = ug_read(sc, UG_CPUFAN + | | 478 | edata->value_cur = ug_read(sc, UG_CPUFAN + |
479 | edata->sensor - UG_FAN_MIN) * UG_RFACT_FAN; | | 479 | edata->sensor - UG_FAN_MIN) * UG_RFACT_FAN; |
480 | } | | 480 | } |
481 | | | 481 | |
482 | void | | 482 | void |
483 | ug2_attach(device_t dv) | | 483 | ug2_attach(device_t dv) |
484 | { | | 484 | { |
485 | struct ug_softc *sc = device_private(dv); | | 485 | struct ug_softc *sc = device_private(dv); |
486 | uint8_t buf[2]; | | 486 | uint8_t buf[2]; |
487 | int i; | | 487 | int i; |
488 | struct ug2_motherboard_info *ai; | | 488 | const struct ug2_motherboard_info *ai; |
489 | struct ug2_sensor_info *si; | | 489 | const struct ug2_sensor_info *si; |
490 | | | 490 | |
491 | aprint_normal(": Abit uGuru 2005 system monitor\n"); | | 491 | aprint_normal(": Abit uGuru 2005 system monitor\n"); |
492 | | | 492 | |
493 | if (ug2_read(sc, UG2_MISC_BANK, UG2_BOARD_ID, 2, buf) != 2) { | | 493 | if (ug2_read(sc, UG2_MISC_BANK, UG2_BOARD_ID, 2, buf) != 2) { |
494 | aprint_error_dev(dv, "Cannot detect board ID. Using default\n"); | | 494 | aprint_error_dev(dv, "Cannot detect board ID. Using default\n"); |
495 | buf[0] = UG_MAX_MSB_BOARD; | | 495 | buf[0] = UG_MAX_MSB_BOARD; |
496 | buf[1] = UG_MAX_LSB_BOARD; | | 496 | buf[1] = UG_MAX_LSB_BOARD; |
497 | } | | 497 | } |
498 | | | 498 | |
499 | if (buf[0] > UG_MAX_MSB_BOARD || buf[1] > UG_MAX_LSB_BOARD || | | 499 | if (buf[0] > UG_MAX_MSB_BOARD || buf[1] > UG_MAX_LSB_BOARD || |
500 | buf[1] < UG_MIN_LSB_BOARD) { | | 500 | buf[1] < UG_MIN_LSB_BOARD) { |
501 | aprint_error_dev(dv, "Invalid board ID(%X,%X). Using default\n", | | 501 | aprint_error_dev(dv, "Invalid board ID(%X,%X). Using default\n", |
502 | buf[0], buf[1]); | | 502 | buf[0], buf[1]); |
503 | buf[0] = UG_MAX_MSB_BOARD; | | 503 | buf[0] = UG_MAX_MSB_BOARD; |
504 | buf[1] = UG_MAX_LSB_BOARD; | | 504 | buf[1] = UG_MAX_LSB_BOARD; |
505 | } | | 505 | } |
506 | | | 506 | |
507 | ai = &ug2_mb[buf[1] - UG_MIN_LSB_BOARD]; | | 507 | ai = &ug2_mb[buf[1] - UG_MIN_LSB_BOARD]; |
508 | | | 508 | |
509 | aprint_normal_dev(dv, "mainboard %s (%.2X%.2X)\n", | | 509 | aprint_normal_dev(dv, "mainboard %s (%.2X%.2X)\n", |
510 | ai->name, buf[0], buf[1]); | | 510 | ai->name, buf[0], buf[1]); |
511 | | | 511 | |
512 | sc->mbsens = (void*)ai->sensors; | | 512 | sc->mbsens = (const void *)ai->sensors; |
513 | sc->sc_sme = sysmon_envsys_create(); | | 513 | sc->sc_sme = sysmon_envsys_create(); |
514 | | | 514 | |
515 | for (i = 0, si = ai->sensors; si && si->name; si++, i++) { | | 515 | for (i = 0, si = ai->sensors; si && si->name; si++, i++) { |
516 | COPYDESCR(sc->sc_sensor[i].desc, si->name); | | 516 | COPYDESCR(sc->sc_sensor[i].desc, si->name); |
517 | sc->sc_sensor[i].rfact = 1; | | 517 | sc->sc_sensor[i].rfact = 1; |
518 | sc->sc_sensor[i].state = ENVSYS_SVALID; | | 518 | sc->sc_sensor[i].state = ENVSYS_SVALID; |
519 | switch (si->type) { | | 519 | switch (si->type) { |
520 | case UG2_VOLTAGE_SENSOR: | | 520 | case UG2_VOLTAGE_SENSOR: |
521 | sc->sc_sensor[i].units = ENVSYS_SVOLTS_DC; | | 521 | sc->sc_sensor[i].units = ENVSYS_SVOLTS_DC; |
522 | sc->sc_sensor[i].rfact = UG_RFACT; | | 522 | sc->sc_sensor[i].rfact = UG_RFACT; |
523 | break; | | 523 | break; |
524 | case UG2_TEMP_SENSOR: | | 524 | case UG2_TEMP_SENSOR: |
525 | sc->sc_sensor[i].units = ENVSYS_STEMP; | | 525 | sc->sc_sensor[i].units = ENVSYS_STEMP; |
| @@ -542,27 +542,28 @@ ug2_attach(device_t dv) | | | @@ -542,27 +542,28 @@ ug2_attach(device_t dv) |
542 | sc->sc_sme->sme_cookie = sc; | | 542 | sc->sc_sme->sme_cookie = sc; |
543 | sc->sc_sme->sme_refresh = ug2_refresh; | | 543 | sc->sc_sme->sme_refresh = ug2_refresh; |
544 | | | 544 | |
545 | if (sysmon_envsys_register(sc->sc_sme)) { | | 545 | if (sysmon_envsys_register(sc->sc_sme)) { |
546 | aprint_error_dev(dv, "unable to register with sysmon\n"); | | 546 | aprint_error_dev(dv, "unable to register with sysmon\n"); |
547 | sysmon_envsys_destroy(sc->sc_sme); | | 547 | sysmon_envsys_destroy(sc->sc_sme); |
548 | } | | 548 | } |
549 | } | | 549 | } |
550 | | | 550 | |
551 | void | | 551 | void |
552 | ug2_refresh(struct sysmon_envsys *sme, envsys_data_t *edata) | | 552 | ug2_refresh(struct sysmon_envsys *sme, envsys_data_t *edata) |
553 | { | | 553 | { |
554 | struct ug_softc *sc = sme->sme_cookie; | | 554 | struct ug_softc *sc = sme->sme_cookie; |
555 | struct ug2_sensor_info *si = (struct ug2_sensor_info *)sc->mbsens; | | 555 | const struct ug2_sensor_info *si = |
| | | 556 | (const struct ug2_sensor_info *)sc->mbsens; |
556 | int rfact = 1; | | 557 | int rfact = 1; |
557 | uint8_t v; | | 558 | uint8_t v; |
558 | | | 559 | |
559 | si += edata->sensor; | | 560 | si += edata->sensor; |
560 | | | 561 | |
561 | #define SENSOR_VALUE (v * si->multiplier * rfact / si->divisor + si->offset) | | 562 | #define SENSOR_VALUE (v * si->multiplier * rfact / si->divisor + si->offset) |
562 | | | 563 | |
563 | if (ug2_read(sc, UG2_SENSORS_BANK, UG2_VALUES_OFFSET + | | 564 | if (ug2_read(sc, UG2_SENSORS_BANK, UG2_VALUES_OFFSET + |
564 | si->port, 1, &v) == 1) { | | 565 | si->port, 1, &v) == 1) { |
565 | switch (si->type) { | | 566 | switch (si->type) { |
566 | case UG2_TEMP_SENSOR: | | 567 | case UG2_TEMP_SENSOR: |
567 | edata->value_cur = SENSOR_VALUE * 1000000 | | 568 | edata->value_cur = SENSOR_VALUE * 1000000 |
568 | + 273150000; | | 569 | + 273150000; |