Changed the Fintek F71878AD fan control implementation to support restoring to the default control settings.

This commit is contained in:
Michael Möller 2020-02-09 17:13:53 +01:00
parent 5fd46f7f46
commit dc15084ed5

View File

@ -4,10 +4,11 @@
License, v. 2.0. If a copy of the MPL was not distributed with this License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. file, You can obtain one at http://mozilla.org/MPL/2.0/.
Copyright (C) 2009-2011 Michael Möller <mmoeller@openhardwaremonitor.org> Copyright (C) 2009-2020 Michael Möller <mmoeller@openhardwaremonitor.org>
*/ */
using System;
using System.Globalization; using System.Globalization;
using System.Text; using System.Text;
@ -37,6 +38,9 @@ namespace OpenHardwareMonitor.Hardware.LPC {
private readonly byte[] FAN_PWM_REG = private readonly byte[] FAN_PWM_REG =
new byte[] { 0xA3, 0xB3, 0xC3, 0xD3 }; new byte[] { 0xA3, 0xB3, 0xC3, 0xD3 };
private bool[] restoreDefaultFanPwmControlRequired = new bool[4];
private byte[] initialFanPwmControl = new byte[4];
private byte ReadByte(byte register) { private byte ReadByte(byte register) {
Ring0.WriteIoPort( Ring0.WriteIoPort(
(ushort)(address + ADDRESS_REGISTER_OFFSET), register); (ushort)(address + ADDRESS_REGISTER_OFFSET), register);
@ -54,9 +58,37 @@ namespace OpenHardwareMonitor.Hardware.LPC {
public void WriteGPIO(int index, byte value) { } public void WriteGPIO(int index, byte value) { }
private void SaveDefaultFanPwmControl(int index) {
if (!restoreDefaultFanPwmControlRequired[index]) {
initialFanPwmControl[index] = ReadByte(FAN_PWM_REG[index]);
restoreDefaultFanPwmControlRequired[index] = true;
}
}
private void RestoreDefaultFanPwmControl(int index) {
if (restoreDefaultFanPwmControlRequired[index]) {
WriteByte(FAN_PWM_REG[index], initialFanPwmControl[index]);
restoreDefaultFanPwmControlRequired[index] = false;
}
}
public void SetControl(int index, byte? value) { public void SetControl(int index, byte? value) {
if(index < controls.Length) if (index < 0 || index >= controls.Length)
WriteByte(FAN_PWM_REG[index], value ?? 128); throw new ArgumentOutOfRangeException("index");
if (!Ring0.WaitIsaBusMutex(10))
return;
if (value.HasValue) {
SaveDefaultFanPwmControl(index);
WriteByte(FAN_PWM_REG[index], value.Value);
} else {
RestoreDefaultFanPwmControl(index);
}
Ring0.ReleaseIsaBusMutex();
} }
public F718XX(Chip chip, ushort address) { public F718XX(Chip chip, ushort address) {
@ -168,7 +200,7 @@ namespace OpenHardwareMonitor.Hardware.LPC {
fans[i] = null; fans[i] = null;
} }
for (int i = 0; i < controls.Length; i++) { for (int i = 0; i < controls.Length; i++) {
controls[i] = (100*ReadByte((byte)(PWM_VALUES_OFFSET + i)))/256.0f; controls[i] = ReadByte((byte)(PWM_VALUES_OFFSET + i)) * 100.0f / 0xFF;
} }
Ring0.ReleaseIsaBusMutex(); Ring0.ReleaseIsaBusMutex();