Module Name: src Committed By: pgoyette Date: Wed Jun 1 02:37:47 UTC 2016
Modified Files: src/sys/dev/ic: nslm7x.c nslm7xvar.h src/sys/dev/isa: lm_isa_common.c wbsio.c Log Message: Add support for Nuvoton NCT6776F from OpenBSD >From PR kern/49747 To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 src/sys/dev/ic/nslm7x.c cvs rdiff -u -r1.28 -r1.29 src/sys/dev/ic/nslm7xvar.h cvs rdiff -u -r1.3 -r1.4 src/sys/dev/isa/lm_isa_common.c cvs rdiff -u -r1.9 -r1.10 src/sys/dev/isa/wbsio.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/ic/nslm7x.c diff -u src/sys/dev/ic/nslm7x.c:1.62 src/sys/dev/ic/nslm7x.c:1.63 --- src/sys/dev/ic/nslm7x.c:1.62 Thu Apr 23 23:23:00 2015 +++ src/sys/dev/ic/nslm7x.c Wed Jun 1 02:37:47 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: nslm7x.c,v 1.62 2015/04/23 23:23:00 pgoyette Exp $ */ +/* $NetBSD: nslm7x.c,v 1.63 2016/06/01 02:37:47 pgoyette Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: nslm7x.c,v 1.62 2015/04/23 23:23:00 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nslm7x.c,v 1.63 2016/06/01 02:37:47 pgoyette Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -1619,6 +1619,154 @@ static struct lm_sensor as99127f_sensors { .desc = NULL } }; +/* NCT6776F */ +static struct lm_sensor nct6776f_sensors[] = { + /* Voltage */ + { + .desc = "VCore", + .type = ENVSYS_SVOLTS_DC, + .bank = 0, + .reg = 0x20, + .refresh = lm_refresh_volt, + .rfact = RFACT_NONE / 2 + }, + { + .desc = "+12V", + .type = ENVSYS_SVOLTS_DC, + .bank = 0, + .reg = 0x21, + .refresh = lm_refresh_volt, + .rfact = RFACT(56, 10) / 2 + }, + { + .desc = "AVCC", + .type = ENVSYS_SVOLTS_DC, + .bank = 0, + .reg = 0x22, + .refresh = lm_refresh_volt, + .rfact = RFACT(34, 34) / 2 + }, + { + .desc = "+3.3V", + .type = ENVSYS_SVOLTS_DC, + .bank = 0, + .reg = 0x23, + .refresh = lm_refresh_volt, + .rfact = RFACT(34, 34) / 2 + }, + { + .desc = "-12V", + .type = ENVSYS_SVOLTS_DC, + .bank = 0, + .reg = 0x24, + .refresh = wb_w83627ehf_refresh_nvolt, + .rfact = 0 + }, + { + .desc = "+5V", + .type = ENVSYS_SVOLTS_DC, + .bank = 0, + .reg = 0x25, + .refresh = lm_refresh_volt, + .rfact = 16000 + }, + { + .desc = "VIN3", + .type = ENVSYS_SVOLTS_DC, + .bank = 0, + .reg = 0x26, + .refresh = lm_refresh_volt, + .rfact = RFACT_NONE + }, + { + .desc = "+3.3VSB", + .type = ENVSYS_SVOLTS_DC, + .bank = 5, + .reg = 0x50, + .refresh = lm_refresh_volt, + .rfact = RFACT(34, 34) / 2 + }, + { + .desc = "VBAT", + .type = ENVSYS_SVOLTS_DC, + .bank = 5, + .reg = 0x51, + .refresh = lm_refresh_volt, + .rfact = RFACT(34, 34) / 2 + }, + + /* Temperature */ + { + .desc = "MB Temperature", + .type = ENVSYS_STEMP, + .bank = 0, + .reg = 0x27, + .refresh = lm_refresh_temp, + .rfact = 0 + }, + { + .desc = "CPU Temperature", + .type = ENVSYS_STEMP, + .bank = 1, + .reg = 0x50, + .refresh = wb_refresh_temp, + .rfact = 0 + }, + { + .desc = "Aux Temp", + .type = ENVSYS_STEMP, + .bank = 2, + .reg = 0x50, + .refresh = wb_refresh_temp, + .rfact = 0 + }, + + /* Fans */ + { + .desc = "System Fan", + .type = ENVSYS_SFANRPM, + .bank = 6, + .reg = 0x56, + .refresh = wb_nct6776f_refresh_fanrpm, + .rfact = 0 + }, + { + .desc = "CPU Fan", + .type = ENVSYS_SFANRPM, + .bank = 6, + .reg = 0x58, + .refresh = wb_nct6776f_refresh_fanrpm, + .rfact = 0 + }, + { + .desc = "Aux Fan0", + .type = ENVSYS_SFANRPM, + .bank = 6, + .reg = 0x5a, + .refresh = wb_nct6776f_refresh_fanrpm, + .rfact = 0 + }, + { + .desc = "Aux Fan1", + .type = ENVSYS_SFANRPM, + .bank = 6, + .reg = 0x5c, + .refresh = wb_nct6776f_refresh_fanrpm, + .rfact = 0 + }, + + { + .desc = "Aux Fan2", + .type = ENVSYS_SFANRPM, + .bank = 6, + .reg = 0x5e, + .refresh = wb_nct6776f_refresh_fanrpm, + .rfact = 0 + }, + + { .desc = NULL } +}; + static void lm_generic_banksel(struct lm_softc *lmsc, int bank) { @@ -1819,6 +1967,7 @@ static int wb_match(struct lm_softc *sc) { const char *model = NULL; + const char *vendor = "Winbond"; int banksel, vendid, cf_flags; aprint_naive("\n"); @@ -1866,8 +2015,14 @@ wb_match(struct lm_softc *sc) wb_temp_diode_type(sc, cf_flags); break; case WB_CHIPID_W83627DHG: - model = "W83627DHG"; - lm_setup_sensors(sc, w83627dhg_sensors); + if (sc->sioid == WBSIO_ID_NCT6776F) { + vendor = "Nuvoton"; + model = "NCT6776F"; + lm_setup_sensors(sc, nct6776f_sensors); + } else { + model = "W83627DHG"; + lm_setup_sensors(sc, w83627dhg_sensors); + } wb_temp_diode_type(sc, cf_flags); break; case WB_CHIPID_W83637HF: @@ -1912,6 +2067,7 @@ wb_match(struct lm_softc *sc) lm_setup_sensors(sc, w83792d_sensors); break; case WB_CHIPID_AS99127F: + vendor = "ASUS"; if (vendid == WB_VENDID_ASUS) { model = "AS99127F"; lm_setup_sensors(sc, w83781d_sensors); @@ -1929,7 +2085,7 @@ wb_match(struct lm_softc *sc) return 1; } - aprint_normal_dev(sc->sc_dev, "Winbond %s Hardware monitor\n", model); + aprint_normal_dev(sc->sc_dev, "%s %s Hardware monitor\n", vendor, model); sc->refresh_sensor_data = wb_refresh_sensor_data; return 1; @@ -2193,6 +2349,22 @@ wb_refresh_fanrpm(struct lm_softc *sc, i } static void +wb_nct6776f_refresh_fanrpm(struct lm_softc *sc, int n) +{ + int datah, datal; + + datah = (*sc->lm_readreg)(sc, sc->lm_sensors[n].reg); + datal = (*sc->lm_readreg)(sc, sc->lm_sensors[n].reg + 1); + + if ((datah == 0xff) || (datah == 0)) { + sc->sensors[n].state = ENVSYS_SINVALID; + } else { + sc->sensors[n].state = ENVSYS_SVALID; + sc->sensors[n].value_cur = (datah << 8) | datal; + } +} + +static void wb_w83792d_refresh_fanrpm(struct lm_softc *sc, int n) { int reg, shift, data, divisor = 1; Index: src/sys/dev/ic/nslm7xvar.h diff -u src/sys/dev/ic/nslm7xvar.h:1.28 src/sys/dev/ic/nslm7xvar.h:1.29 --- src/sys/dev/ic/nslm7xvar.h:1.28 Tue Jan 17 16:14:47 2012 +++ src/sys/dev/ic/nslm7xvar.h Wed Jun 1 02:37:47 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: nslm7xvar.h,v 1.28 2012/01/17 16:14:47 jakllsch Exp $ */ +/* $NetBSD: nslm7xvar.h,v 1.29 2016/06/01 02:37:47 pgoyette Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -144,6 +144,9 @@ #define WB_CHIPID_W83627EHF 0xa1 #define WB_CHIPID_W83627DHG 0xc1 +/* wbsio Device IDs */ +#define WBSIO_ID_NCT6776F 0xc3 + /* Config bits */ #define WB_CONFIG_VMR9 0x01 @@ -170,6 +173,7 @@ struct lm_softc { struct lm_sensor *lm_sensors; uint8_t chipid; uint8_t vrm9; + uint8_t sioid; }; struct lm_sensor { Index: src/sys/dev/isa/lm_isa_common.c diff -u src/sys/dev/isa/lm_isa_common.c:1.3 src/sys/dev/isa/lm_isa_common.c:1.4 --- src/sys/dev/isa/lm_isa_common.c:1.3 Wed Jan 18 00:11:43 2012 +++ src/sys/dev/isa/lm_isa_common.c Wed Jun 1 02:37:47 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: lm_isa_common.c,v 1.3 2012/01/18 00:11:43 jakllsch Exp $ */ +/* $NetBSD: lm_isa_common.c,v 1.4 2016/06/01 02:37:47 pgoyette Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: lm_isa_common.c,v 1.3 2012/01/18 00:11:43 jakllsch Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lm_isa_common.c,v 1.4 2016/06/01 02:37:47 pgoyette Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -121,6 +121,8 @@ lm_isa_attach(device_t parent, device_t sc->lmsc.sc_dev = self; sc->lmsc.lm_writereg = lm_isa_writereg; sc->lmsc.lm_readreg = lm_isa_readreg; + /* pass wbsio Device ID */ + sc->lmsc.sioid = (uint8_t)(uintptr_t)ia->ia_aux; lm_attach(&sc->lmsc); } Index: src/sys/dev/isa/wbsio.c diff -u src/sys/dev/isa/wbsio.c:1.9 src/sys/dev/isa/wbsio.c:1.10 --- src/sys/dev/isa/wbsio.c:1.9 Wed Jan 18 00:23:30 2012 +++ src/sys/dev/isa/wbsio.c Wed Jun 1 02:37:47 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: wbsio.c,v 1.9 2012/01/18 00:23:30 jakllsch Exp $ */ +/* $NetBSD: wbsio.c,v 1.10 2016/06/01 02:37:47 pgoyette Exp $ */ /* $OpenBSD: wbsio.c,v 1.5 2009/03/29 21:53:52 sthen Exp $ */ /* * Copyright (c) 2008 Mark Kettenis <kette...@openbsd.org> @@ -53,6 +53,7 @@ #define WBSIO_ID_W83637HF 0x70 #define WBSIO_ID_W83667HG 0xa5 #define WBSIO_ID_W83697HF 0x60 +#define WBSIO_ID_NCT6776F 0xc3 /* Logical Device Number (LDN) Assignments */ #define WBSIO_LDN_HM 0x0b @@ -147,6 +148,7 @@ wbsio_probe(device_t parent, cfdata_t ma case WBSIO_ID_W83627DHG: case WBSIO_ID_W83637HF: case WBSIO_ID_W83697HF: + case WBSIO_ID_NCT6776F: ia->ia_nio = 1; ia->ia_io[0].ir_size = WBSIO_IOSIZE; ia->ia_niomem = 0; @@ -164,6 +166,7 @@ wbsio_attach(device_t parent, device_t s struct wbsio_softc *sc = device_private(self); struct isa_attach_args *ia = aux; const char *desc = NULL; + const char *vendor = "Winbond"; uint8_t reg; sc->sc_dev = self; @@ -205,20 +208,22 @@ wbsio_attach(device_t parent, device_t s case WBSIO_ID_W83697HF: desc = "W83697HF"; break; + case WBSIO_ID_NCT6776F: + vendor = "Nuvoton"; + desc = "NCT6776F"; + break; } - /* Read device revision */ reg = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_REV); aprint_naive("\n"); - aprint_normal(": Winbond LPC Super I/O %s rev 0x%02x\n", desc, reg); + aprint_normal(": %s LPC Super I/O %s rev 0x%02x\n", vendor, desc, reg); /* Escape from configuration mode */ wbsio_conf_disable(sc->sc_iot, sc->sc_ioh); if (!pmf_device_register(self, NULL, NULL)) aprint_error_dev(self, "couldn't establish power handler\n"); - wbsio_rescan(self, "wbsio", NULL); } @@ -258,7 +263,7 @@ wbsio_search(device_t parent, cfdata_t c { struct wbsio_softc *sc = device_private(parent); uint16_t iobase; - uint8_t reg0, reg1; + uint8_t reg0, reg1, devid; /* Enter configuration mode */ wbsio_conf_enable(sc->sc_iot, sc->sc_ioh); @@ -283,6 +288,13 @@ wbsio_search(device_t parent, cfdata_t c if (iobase == 0) return -1; + /* Enter configuration mode */ + wbsio_conf_enable(sc->sc_iot, sc->sc_ioh); + /* Read device ID */ + devid = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_ID); + /* Escape from configuration mode */ + wbsio_conf_disable(sc->sc_iot, sc->sc_ioh); + sc->sc_ia.ia_nio = 1; sc->sc_ia.ia_io = &sc->sc_io; sc->sc_ia.ia_io[0].ir_addr = iobase; @@ -290,6 +302,8 @@ wbsio_search(device_t parent, cfdata_t c sc->sc_ia.ia_niomem = 0; sc->sc_ia.ia_nirq = 0; sc->sc_ia.ia_ndrq = 0; + /* Store device-id to ia_aux */ + sc->sc_ia.ia_aux = (void *)(uintptr_t)devid; sc->sc_lm_dev = config_attach(parent, cf, &sc->sc_ia, wbsio_print); return 0;