summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/bds/ec.tasklist1
-rw-r--r--board/link/ec.tasklist1
-rw-r--r--chip/lm4/pwm.c32
-rw-r--r--util/ectool.c27
4 files changed, 55 insertions, 6 deletions
diff --git a/board/bds/ec.tasklist b/board/bds/ec.tasklist
index 5e2ec6459f..b7f8a04532 100644
--- a/board/bds/ec.tasklist
+++ b/board/bds/ec.tasklist
@@ -16,6 +16,7 @@
#define CONFIG_TASK_LIST \
TASK(WATCHDOG, watchdog_task, NULL) \
TASK(TEMPSENSOR, temp_sensor_task, NULL) \
+ TASK(PWM, pwm_task, NULL) \
TASK(KEYSCAN, keyboard_scan_task, NULL) \
TASK(POWERBTN, power_button_task, NULL) \
TASK(CONSOLE, console_task, NULL) \
diff --git a/board/link/ec.tasklist b/board/link/ec.tasklist
index a17d39199f..a8a05c24ea 100644
--- a/board/link/ec.tasklist
+++ b/board/link/ec.tasklist
@@ -16,6 +16,7 @@
#define CONFIG_TASK_LIST \
TASK(WATCHDOG, watchdog_task, NULL) \
TASK(TEMPSENSOR, temp_sensor_task, NULL) \
+ TASK(PWM, pwm_task, NULL) \
TASK(KEYSCAN, keyboard_scan_task, NULL) \
TASK(POWERBTN, power_button_task, NULL) \
TASK(X86POWER, x86_power_task, NULL) \
diff --git a/chip/lm4/pwm.c b/chip/lm4/pwm.c
index c792b0e1f2..f15b24ae02 100644
--- a/chip/lm4/pwm.c
+++ b/chip/lm4/pwm.c
@@ -12,6 +12,9 @@
#include "registers.h"
#include "uart.h"
#include "util.h"
+#include "task.h"
+#include "lpc.h"
+#include "lpc_commands.h"
/* Maximum RPM for fan controller */
#define MAX_RPM 0x1fff
@@ -89,6 +92,35 @@ int pwm_set_keyboard_backlight(int percent)
}
+static void update_lpc_mapped_memory(void)
+{
+ int i, r;
+ uint16_t *mapped = (uint16_t *)(lpc_get_memmap_range() +
+ EC_LPC_MEMMAP_FAN);
+
+ for (i = 0; i < 4; ++i)
+ mapped[i] = 0xffff;
+
+ r = pwm_get_fan_rpm();
+
+ /* Write fan speed. Or 0xFFFE for fan stalled. */
+ if (r)
+ mapped[0] = r;
+ else
+ mapped[0] = 0xfffe;
+}
+
+
+void pwm_task(void)
+{
+ while (1) {
+ update_lpc_mapped_memory();
+ /* Wait 1s */
+ task_wait_msg(1000000);
+ }
+}
+
+
/*****************************************************************************/
/* Console commands */
diff --git a/util/ectool.c b/util/ectool.c
index 1a4ba232fb..a0bd71c236 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -117,12 +117,25 @@ int ec_command(int command, const void *indata, int insize,
return 0;
}
+
uint8_t read_mapped_mem8(uint8_t offset)
{
return inb(EC_LPC_ADDR_MEMMAP + offset);
}
+uint16_t read_mapped_mem16(uint8_t offset)
+{
+ return inw(EC_LPC_ADDR_MEMMAP + offset);
+}
+
+
+uint32_t read_mapped_mem32(uint8_t offset)
+{
+ return inl(EC_LPC_ADDR_MEMMAP + offset);
+}
+
+
void print_help(const char *prog)
{
printf("Usage: %s <command> [params]\n\n", prog);
@@ -472,7 +485,7 @@ int cmd_temperature(int argc, char *argv[])
}
printf("Reading temperature...");
- rv = read_mapped_mem8(id);
+ rv = read_mapped_mem8(EC_LPC_MEMMAP_TEMP_SENSOR + id);
if (rv == 0xff)
printf("Error\n");
else
@@ -482,14 +495,16 @@ int cmd_temperature(int argc, char *argv[])
int cmd_pwm_get_fan_rpm(void)
{
- struct lpc_response_pwm_get_fan_rpm r;
int rv;
- rv = ec_command(EC_LPC_COMMAND_PWM_GET_FAN_RPM, NULL, 0, &r, sizeof(r));
- if (rv)
- return rv;
+ rv = read_mapped_mem16(EC_LPC_MEMMAP_FAN);
+ if (rv == 0xffff)
+ return -1;
- printf("Current fan RPM: %d\n", r.rpm);
+ if (rv == 0xfffe)
+ printf("Fan stalled!\n");
+ else
+ printf("Current fan RPM: %d\n", rv);
return 0;
}