Skip to content

Commit a4fbf36

Browse files
Josh-Tsaiamstan
authored andcommitted
fwk: dogwood: allow the user to select every sensor to be a sensor source
The UI ERS x12 defines the every sensor can be a sensor source. BRANCH=fwk-dogwood-27111 BUG=https://app.clickup.com/t/86et9h4tv TEST=Use ec console "fanctl get 0/1/2" to check the sensor source after executing the host command to change the sensor source. Signed-off-by: Josh-Tsai <josh_tsai@compal.com>
1 parent eec99f4 commit a4fbf36

2 files changed

Lines changed: 14 additions & 54 deletions

File tree

zephyr/program/framework/dogwood/src/thermal.c

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "temp_sensor/f75303.h"
2020
#include "temp_sensor/f75397.h"
21+
#include "temp_sensor/temp_sensor.h"
2122

2223
#define CPRINTS(format, args...) cprints(CC_THERMAL, format, ##args)
2324
#define CPRINTF(format, args...) cprintf(CC_THERMAL, format, ##args)
@@ -27,6 +28,7 @@
2728
#define TEMP_ID_DDR TEMP_SENSOR_ID(DT_NODELABEL(temp_sensor_memory))
2829
#define TEMP_ID_AMBIENT TEMP_SENSOR_ID(DT_NODELABEL(temp_sensor_ambient))
2930
#define TEMP_ID_CHIPSET TEMP_SENSOR_ID(DT_NODELABEL(temp_sensor_chipset))
31+
#define TEMP_ID_VIRTUAL TEMP_SENSOR_ID(DT_NODELABEL(temp_sensor_virtual))
3032

3133
/* The macro of temperature sensor F75303 IDs */
3234
#define F75303_ID_UTH1 F75303_SENSOR_ID(DT_NODELABEL(power_f75303))
@@ -57,10 +59,7 @@ void fan_init(void)
5759
fan_params[idx].max_temperature = 54;
5860
fan_params[idx].min_temperature = 40;
5961
fan_params[idx].fan_always_on = false;
60-
if (idx == FAN_APU)
61-
fan_params[idx].sensor_source = SENSOR_SRC_APU;
62-
else
63-
fan_params[idx].sensor_source = SENSOR_SRC_OFF;
62+
fan_params[idx].sensor_source = TEMP_ID_DDR;
6463
fan_params[idx].target_duty = 0;
6564
}
6665
}
@@ -112,7 +111,7 @@ static int thermal_fan_percent_with_hysteresis(int low, int high, int cur, bool
112111
return 100 * (cur - low) / (high - low);
113112
}
114113

115-
static int thermal_process_sensor_source_apu(int fan, int *temp)
114+
static int thermal_process_sensor(int fan, enum temp_sensor_id id, int *temp)
116115
{
117116
struct fan_parameter_t *fan_param = &fan_params[fan];
118117
int duty;
@@ -122,32 +121,7 @@ static int thermal_process_sensor_source_apu(int fan, int *temp)
122121

123122
temp_ratio = thermal_fan_percent_with_hysteresis(fan_param->min_temperature,
124123
fan_param->max_temperature,
125-
temp[TEMP_ID_POWER],
126-
fan_param->target_duty ? true : false);
127-
128-
/**
129-
* If the current temperature between minimum and maximum, we need to convert the
130-
* current ratio to fan duty
131-
*/
132-
if (temp_ratio <= 0)
133-
duty = 0;
134-
else
135-
duty = ((temp_ratio - 1) * duty_max + (100 - temp_ratio) * duty_min) / 99;
136-
137-
return duty;
138-
}
139-
140-
static int thermal_process_sensor_source_chassis(int fan, int *temp)
141-
{
142-
struct fan_parameter_t *fan_param = &fan_params[fan];
143-
int duty;
144-
int duty_max = fan_param->max_duty;
145-
int duty_min = fan_param->min_duty;
146-
int temp_ratio;
147-
148-
temp_ratio = thermal_fan_percent_with_hysteresis(fan_param->min_temperature,
149-
fan_param->max_temperature,
150-
temp[TEMP_ID_AMBIENT],
124+
temp[id],
151125
fan_param->target_duty ? true : false);
152126

153127
/**
@@ -172,15 +146,13 @@ static void thermal_set_fan_duty(int fan, int duty)
172146
void board_override_fan_control(int fan, int *temp)
173147
{
174148
struct fan_parameter_t *fan_param = &fan_params[fan];
149+
enum temp_sensor_id id = fan_param->sensor_source;
175150

176151
if (!is_thermal_control_enabled(fan))
177152
return;
178153

179-
/* TODO: should we use the unit mk to calculate the target duty? */
180-
if (fan_param->sensor_source == SENSOR_SRC_APU)
181-
fan_param->target_duty = thermal_process_sensor_source_apu(fan, temp);
182-
else if (fan_param->sensor_source == SENSOR_SRC_CHASSIS)
183-
fan_param->target_duty = thermal_process_sensor_source_chassis(fan, temp);
154+
if (id != TEMP_SENSOR_OFF)
155+
fan_param->target_duty = thermal_process_sensor(fan, id, temp);
184156
else
185157
fan_param->target_duty = 0;
186158

@@ -207,7 +179,6 @@ static int cmd_fan_control(int argc, const char **argv)
207179

208180
/* Get the parameters */
209181
if (argc == 3) {
210-
static const char * const source[] = { "NULL", "APU", "CHASSIS",};
211182

212183
if (strcasecmp(argv[1], "get") == 0) {
213184
CPRINTS("Fan%d parameters:", fan_index);
@@ -216,7 +187,9 @@ static int cmd_fan_control(int argc, const char **argv)
216187
CPRINTS(" Minimum Duty:%d", fan_param->min_duty);
217188
CPRINTS(" Maximum Temperature:%d", fan_param->max_temperature);
218189
CPRINTS(" Minimum Temperature:%d", fan_param->min_temperature);
219-
CPRINTS(" Sensor Source:%s", source[fan_param->sensor_source]);
190+
CPRINTS(" Sensor Source:%s",
191+
(fan_param->sensor_source == TEMP_SENSOR_OFF) ?
192+
"off" : temp_sensors[fan_param->sensor_source].name);
220193
CPRINTS(" Always on %sabled", fan_param->fan_always_on ? "en" : "dis");
221194
return EC_SUCCESS;
222195
} else
@@ -248,11 +221,8 @@ static int cmd_fan_control(int argc, const char **argv)
248221
fan_param->min_temperature = value;
249222
break;
250223
case 7:
251-
/* APU FAN sensor source can't be changed */
252-
if (fan_index == FAN_APU ||
253-
(value != SENSOR_SRC_APU &&
254-
value != SENSOR_SRC_CHASSIS))
255-
break;
224+
if (value < 0 || value >= TEMP_SENSOR_COUNT)
225+
return EC_ERROR_PARAM1 + param - 1;
256226

257227
fan_param->sensor_source = value;
258228
break;
@@ -286,12 +256,8 @@ static enum ec_status hc_fan_configuration(struct host_cmd_handler_args *args)
286256

287257
fan = &fan_params[p->fan_index];
288258

289-
if (p->command == FAN_HC_CMD_SET) {
259+
if (p->command == FAN_HC_CMD_SET)
290260
memcpy(fan, &p->fan_config, sizeof(p->fan_config));
291-
/* avoid the sensor source of the APU fan to be changed */
292-
if (p->fan_index == FAN_APU)
293-
fan->sensor_source = SENSOR_SRC_APU;
294-
}
295261

296262
memcpy(&r->fan_config, fan, sizeof(*r));
297263
args->response_size = sizeof(*r);

zephyr/program/framework/include/board_host_command.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,6 @@ struct ec_response_wake_on_lan_control {
596596
*/
597597
#define EC_CMD_FAN_CONFIGURATION 0x3E27
598598

599-
enum sensor_source_t {
600-
SENSOR_SRC_OFF = 0,
601-
SENSOR_SRC_APU = 1,
602-
SENSOR_SRC_CHASSIS = 2,
603-
};
604-
605599
enum fan_hc_command_t {
606600
FAN_HC_CMD_GET = 0,
607601
FAN_HC_CMD_SET = 1,

0 commit comments

Comments
 (0)