Skip to content

Commit 3e9004d

Browse files
kiram9JohnAZoidberg
authored andcommitted
fwk: add temperature_filter file for virtual temp
Signed-off-by: LeoCX_Tsai <LeoCX_Tsai@compal.com>
1 parent 73f1196 commit 3e9004d

5 files changed

Lines changed: 80 additions & 1 deletion

File tree

baseboard/fwk/build.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ baseboard-$(CONFIG_SYSTEMSERIAL_DEBUG) += system_serial.o
1313
baseboard-$(CONFIG_8042_AUX) += ps2mouse.o
1414
baseboard-$(HAS_TASK_HOSTCMD) += baseboard_host_commands.o
1515
baseboard-$(CONFIG_CHARGE_MANAGER) += battery_extender.o
16+
baseboard-$(CONFIG_FAN_VIRTUAL_TEMP) += temperature_filter.o

baseboard/fwk/temperature_filter.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <string.h>
2+
#include "console.h"
3+
#include "i2c_hid.h"
4+
#include "hooks.h"
5+
#include "host_command.h"
6+
#include "util.h"
7+
#include "math_util.h"
8+
#include "temperature_filter.h"
9+
10+
11+
12+
void thermal_filter_reset(struct biquad *filter)
13+
{
14+
memset(&filter->state, 30 << IN_SCALE, sizeof(filter->state));
15+
}
16+
17+
int thermal_filter_update(struct biquad *filter, int value)
18+
{
19+
int out_scaled =
20+
filter->coeff[0] * (value << IN_SCALE) +
21+
filter->coeff[1] * filter->state[0] +
22+
filter->coeff[2] * filter->state[1] -
23+
filter->coeff[4] * filter->state[2] -
24+
filter->coeff[5] * filter->state[3];
25+
int out = out_scaled >> Q_SCALE;
26+
/* update delay line */
27+
filter->state[1] = filter->state[0];
28+
filter->state[3] = filter->state[2];
29+
filter->state[0] = value << IN_SCALE;
30+
filter->state[2] = out;
31+
return out >> IN_SCALE;
32+
}
33+
34+
int thermal_filter_get(struct biquad *filter)
35+
{
36+
return filter->state[2] >> IN_SCALE;
37+
}

baseboard/fwk/temperature_filter.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* Copyright 2022 The ChromiumOS Authors
2+
* Use of this source code is governed by a BSD-style license that can be
3+
* found in the LICENSE file.
4+
*
5+
* Low pass filter for on die temperature
6+
*/
7+
#ifndef __CROS_EC_TEMPERATURE_FILTER_H
8+
#define __CROS_EC_TEMPERATURE_FILTER_H
9+
10+
#include "util.h"
11+
#include "math_util.h"
12+
13+
#define Q_SCALE 14
14+
/* scale input up to improve filter performance */
15+
#define IN_SCALE 7
16+
17+
struct biquad {
18+
/* State values x[n-1], x[n-2], y[n-1], y[n-2] */
19+
int32_t state[4];
20+
const int32_t *coeff;
21+
};
22+
23+
void thermal_filter_reset(struct biquad *filter);
24+
25+
int thermal_filter_update(struct biquad *filter, int value);
26+
27+
int thermal_filter_get(struct biquad *filter);
28+
29+
#endif /* __CROS_EC_TEMPERATURE_FILTER_H */

board/hx30/board.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,13 @@
457457

458458
#define CONFIG_WP_ACTIVE_HIGH
459459

460+
/*
461+
* Enable Virtual temp for better fan running
462+
* also smooth fan up/down rate.
463+
*/
464+
#define CONFIG_FAN_VIRTUAL_TEMP
465+
466+
460467
/* LED signals */
461468
/*
462469
#define GPIO_BAT_LED_RED GPIO_BATT_LOW_LED_L

common/thermal.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static void thermal_control(void)
6060
int temp_fan_configured;
6161

6262
#ifdef CONFIG_CUSTOM_FAN_CONTROL
63-
int temp[TEMP_SENSOR_COUNT];
63+
int temp[TEMP_SENSOR_COUNT] = {0};
6464
#endif
6565

6666
/* Get ready to count things */
@@ -87,6 +87,11 @@ static void thermal_control(void)
8787
else
8888
num_sensors_read++;
8989

90+
#if defined(CONFIG_FANS) && defined(CONFIG_CUSTOM_FAN_CONTROL)
91+
/* Store all sensors value */
92+
temp[i] = K_TO_C(t);
93+
#endif
94+
9095
/* check all the limits */
9196
for (j = 0; j < EC_TEMP_THRESH_COUNT; j++) {
9297
int limit = thermal_params[i].temp_host[j];

0 commit comments

Comments
 (0)