# ASRock X370 Gaming K4
# 2018, contributed by Rigo Reddig <rigo.reddig@gmail.com>
#
# dmi: board_name:   X370 Gaming K4
# dmi: board_vendor: ASRock
# dmi: bios_version: P4.70
# cpu: AMD Ryzen 7 1700X Eight-Core Processor
chip "nct6779-isa-*"

    # Fans
    label fan1 "Chassis Fan 3 Speed"
    label fan2 "CPU Fan 1 Speed"
    label fan3 "CPU Fan 2 Speed"
    label fan4 "Chassis Fan 1 Speed"
    label fan5 "Chassis Fan 2 Speed"

    # Temperatures
    label temp1 "Motherboard"
    label temp2 "CPU MB"
    label temp3 "Auxillary"
    label temp4 "VRM"
    label temp5 "AUXTIN2"
    
    # temp6 is almost always at -25. Not certain what to do about this.
    label temp6 "CPU (PECI)" 
    
    # temp7 (CPU tCTL) A Thermal BIAS value generated by CPU 
    # it includes an offset it is usedto drive mainboard Fans to higher speeds.
    
    # temp7 value is rounded off to the nearest ~1C only reported if
    # "Use Tctrl" has been selected in UEFI as the fan control sensor.
    
    # It will likely be offset by 20/10C on Ryzen X series CPU's
    label temp7 "CPU tCTL"

    # Voltages
    
    # VCore is different to VDDCR_CPU
    # VCore is a voltage measured somewhere by the Firmware.
    # (Readings may appear low at times (0.54V) and fluctuate - this is normal)
    label in0 "VCore"
    label in1 "VPPM" #scalar
    label in2 "AVCC"
    label in3 "3VCC"
    label in4 "+12V" #scalar
    label in5 "VDDCR_SOC" #(Data Fabric)
    label in6 "DRAM (VDDIO)"
    label in7 "3VSB"
    label in8 "VBat"
    ignore in9 #Unused input that is always at 0.
    label in10 "Mem_VTT" #(1/2 of VDDIO)
    label in11 "Chipset 1.05V"
    label in12 "+5V"
    label in13 "VDDP"
    label in14 "1.8V+"

    # CPU VCore limits set according to overclockers testing and AMD Max Safe 
    # voltage recommendations.
    # Keep in mind Ryzen CPU's may boost to higher voltages for short times. 
    # This is entirely dependant on individual chip binning.
    # If your chip indicates 1.55V continuously the sensors may not be treated 
    # correctly by your mainboard or you have buggy firmware.
    # In that case It might be actually 1.55V which would correlates with 
    # high heat, or it may be just a bad readout.
    
    # Note: sustained 1.45 is also not safe.
    # I am not sure about the low load voltage drops, they are normal
    # (commonly occuring on many boards) and thus likely a measurement or 
    # sensor anomaly.
    # There is a more accurate on-die voltage sensor with ryzen.
    # but the documentation is covered by NDA. k10-temp would need to be 
    # adapated to read voltages in addition to temperatures like HWInfo64 on 
    # Windows already does.
    set in0_min 0.40 #Possibly inaccurate at low voltages. 
    set in0_max 1.45

    # VPPM Voltage 5%
    set in1_min 2.50 * 0.95
    set in1_max 2.50 * 1.05
    
    # Most PSU voltages set according to ATX v2.2 spec +/- 5% on the following:
    # +3.3VDC	± 5%	+3.135 VDC	+3.465 VDC
    # +5VDC	    ± 5%	+4.750 VDC	+5.250 VDC
    # +5VSB 	± 5%	+4.750 VDC	+5.250 VDC
    # -5VDC     ± 10%	-4.500 VDC	-5.500 VDC
    # +12VDC	± 5%	+11.400 VDC	+12.600 VDC
    # -12VDC	± 10%	-10.800 VDC	-13.200 VDC
    
    # +12VDC
    set in4_min 12 * 0.95
    set in4_max 12 * 1.05

    # VDDCR_SOC (fabric & peripheral) voltage levels
    # This can vary largely from board to board and among CPU's
    set in5_min 0.80
    set in5_max 1.20

    # DDR 4 RAM Tolerances VDDIO (1.2V DDR4 JEDEC standard)
    set in6_min 1.10 #Underclocking
    set in6_max 1.50 #Intel XMP2.0 recommended max safe voltage
    
    # Memory VTT Voltages (this should correspond to approximately VDDIO/2)
    set in10_min 1.20 * 0.5 #Stock Voltage
    set in10_max 1.50 * 0.5 #Overclocked XMP Voltage

    # Uncertain tolerances for the Ryzen Chipset
    set in11_min 0.90 #Undervolting
    set in11_max 1.20 #Overvolting
    
    set in12_min 5 * 0.95
    set in12_max 5 * 1.05

    # CLDO_VDDP Magic - helps to set to 1.0V when RAM overclocking or on XMP
    set in13_min 0.95 * 0.96
    set in13_max 0.95 * 1.13

    # PLL (Phase locked loop) voltage on the CPU. 
    set in14_min 1.8 * 0.98
    set in14_max 1.8 * 1.02

    # Compute Inputs
    # The nct6779D uses a 2.048V input range, all inputs above that are scaled 
    # using a voltage divider.
    # Below inputs utilize an integrated voltage divider:
    # ADC, AVCC, VBAT, 3VSB and 3VCC 
    #
    # values as per nuvoton nct6779D datasheet
    # Section 8.5 Analog Inputs (Page 54,55)
    # #       Vs     R1,Rin   R2,Rf    Vin
    # in4  +12.0     56       10     ~+1.84
    # in12  +5.0     20       10     ~+1.67
    #
    compute in0 @*2, @/2
    compute in1 @*2, @/2
    compute in4 ((56/10)+1)*@, @/((56/10)+1)
    compute in12 ((20/10)+1)*@, @/((20/10)+1)


    # Potential things to filter
    # These inputs are unused unless you have a case intrusion switch connected.
    #ignore intrusion0
    #ignore intrusion1
