[coreboot-gerrit] Change in coreboot[master]: [WIP]superio/nuvoton/npcd378: Add PSU fan control
Patrick Rudolph (Code Review)
gerrit at coreboot.org
Fri May 4 09:12:26 CEST 2018
Patrick Rudolph has uploaded this change for review. ( https://review.coreboot.org/26050
Change subject: [WIP]superio/nuvoton/npcd378: Add PSU fan control
......................................................................
[WIP]superio/nuvoton/npcd378: Add PSU fan control
Implement method to access HWM space and set the PSU fan using a new
CMOS option psu_fan_lvl. Add the CMOS option to all board that use
NPCD378. In case no CMOS is set use the default fan level 3.
Change-Id: I56ce7ad1df88638589a577b8a09d5d775557887b
Signed-off-by: Patrick Rudolph <patrick.rudolph at 9elements.com>
---
M src/mainboard/hp/compaq_8200_elite_sff/cmos.default
M src/mainboard/hp/compaq_8200_elite_sff/cmos.layout
M src/superio/nuvoton/npcd378/npcd378.h
M src/superio/nuvoton/npcd378/superio.c
4 files changed, 85 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/50/26050/1
diff --git a/src/mainboard/hp/compaq_8200_elite_sff/cmos.default b/src/mainboard/hp/compaq_8200_elite_sff/cmos.default
index d00ae5e..306760c 100644
--- a/src/mainboard/hp/compaq_8200_elite_sff/cmos.default
+++ b/src/mainboard/hp/compaq_8200_elite_sff/cmos.default
@@ -3,3 +3,4 @@
power_on_after_fail=Enable
nmi=Enable
sata_mode=AHCI
+psu_fan_lvl=3
\ No newline at end of file
diff --git a/src/mainboard/hp/compaq_8200_elite_sff/cmos.layout b/src/mainboard/hp/compaq_8200_elite_sff/cmos.layout
index 3ead211..830d286 100644
--- a/src/mainboard/hp/compaq_8200_elite_sff/cmos.layout
+++ b/src/mainboard/hp/compaq_8200_elite_sff/cmos.layout
@@ -51,7 +51,9 @@
# coreboot config options: console
#392 3 r 0 unused
395 4 e 6 debug_level
-#399 9 r 0 unused
+#399 1 r 0 unused
+400 3 h 0 psu_fan_lvl
+#403 5 r 0 unused
# coreboot config options: southbridge
408 1 e 1 nmi
diff --git a/src/superio/nuvoton/npcd378/npcd378.h b/src/superio/nuvoton/npcd378/npcd378.h
index 732dd00..902608c 100644
--- a/src/superio/nuvoton/npcd378/npcd378.h
+++ b/src/superio/nuvoton/npcd378/npcd378.h
@@ -17,6 +17,31 @@
#ifndef SUPERIO_NUVOTON_NPCD378_H
#define SUPERIO_NUVOTON_NPCD378_H
+/* HWM at LDN8 */
+#define NPCD378_HWM_PSU_FAN_MIN 0x17
+#define NPCD378_HWM_PSU_FAN_MAX 0xf8
+#define NPCD378_HWM_PSU_FAN_PWM_CTRL 0x198
+
+/*
+ * Read HWM register at specific page and offset.
+ *
+ * @param iobase IOBASE address of LDN8
+ * @param reg MSB is page, LSB sets the offset in selected page
+ *
+ * @return Byte read from HWM
+ */
+uint8_t npcd378_hwm_read(const uint16_t iobase, const uint16_t reg);
+
+/*
+ * Write to HWM register at specific page and offset.
+ *
+ * @param iobase IOBASE address of LDN8
+ * @param reg MSB is page, LSB sets the offset in selected page
+ * @param val The value to write to HWM register
+ */
+void npcd378_hwm_write(const uint16_t iobase, const uint16_t reg,
+ const uint8_t val);
+
/* Logical Device Numbers (LDN). */
/* Default Nuvoton hardware: */
#define NPCD378_FDC 0x00 /* Floppy */
diff --git a/src/superio/nuvoton/npcd378/superio.c b/src/superio/nuvoton/npcd378/superio.c
index a05d199..1f5ac72 100644
--- a/src/superio/nuvoton/npcd378/superio.c
+++ b/src/superio/nuvoton/npcd378/superio.c
@@ -18,24 +18,79 @@
*/
#include <arch/io.h>
+#include <console/console.h>
#include <device/device.h>
#include <device/pnp.h>
+#include <option.h>
#include <pc80/keyboard.h>
#include <stdlib.h>
#include <superio/conf_mode.h>
#include "npcd378.h"
+uint8_t npcd378_hwm_read(const uint16_t iobase, const uint16_t reg)
+{
+ outb((reg >> 8) & 0xf, iobase + 0xff);
+ uint8_t reg8 = inb(iobase + (reg & 0xff));
+ if (reg8 == 0xff)
+ reg8 = inb(iobase + (reg & 0xff));
+
+ outb(0, iobase + 0xff);
+ return reg8;
+}
+
+void npcd378_hwm_write(const uint16_t iobase, const uint16_t reg,
+ const uint8_t val)
+{
+ outb((reg >> 8) & 0xf, iobase + 0xff);
+ outb(val, iobase + (reg & 0xff));
+
+ outb(0, iobase + 0xff);
+}
+
+static uint16_t npcd378_get_iobase(struct device *dev)
+{
+ struct resource *res;
+
+ for (res = dev->resource_list; res; res = res->next)
+ if ((res->flags & IORESOURCE_IO) && (res->index == 0x60))
+ return res->base;
+
+ return 0;
+}
+
static void npcd378_init(struct device *dev)
{
+ uint16_t hwm_iobase;
+ uint8_t pwm, fan_lvl;
+
if (!dev->enabled)
return;
switch (dev->path.pnp.device) {
- /* TODO: Might potentially need code for HWM or FDC etc. */
+ /* TODO: Might potentially need code for FDC etc. */
case NPCD378_KBC:
pc_keyboard_init(PROBE_AUX_DEVICE);
break;
+ case NPCD378_HWM:
+ hwm_iobase = npcd378_get_iobase(dev);
+ if (!hwm_iobase) {
+ printk(BIOS_ERR, "NPCD378: LDN%u IOBASE not set.\n",
+ NPCD378_HWM);
+ break;
+ }
+ if (!get_option(&fan_lvl, "psu_fan_lvl") || fan_lvl > 7)
+ fan_lvl = 3;
+
+ pwm = NPCD378_HWM_PSU_FAN_MIN +
+ (NPCD378_HWM_PSU_FAN_MAX - NPCD378_HWM_PSU_FAN_MIN) *
+ fan_lvl / 7;
+
+ /* Set PSU fan PWM lvl */
+ npcd378_hwm_write(hwm_iobase, NPCD378_HWM_PSU_FAN_PWM_CTRL,
+ pwm);
+ printk(BIOS_INFO, "NPCD378: PSU fan PWM 0x%02x\n", pwm);
+ break;
}
}
--
To view, visit https://review.coreboot.org/26050
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I56ce7ad1df88638589a577b8a09d5d775557887b
Gerrit-Change-Number: 26050
Gerrit-PatchSet: 1
Gerrit-Owner: Patrick Rudolph <patrick.rudolph at 9elements.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180504/a6488314/attachment-0001.html>
More information about the coreboot-gerrit
mailing list