Skip to content

Commit

Permalink
Merge pull request #733 from FrameworkComputer/azalea.PL_v0716_fan_v0719
Browse files Browse the repository at this point in the history
Azalea.pl v0716 fan v0719
  • Loading branch information
kiram9 authored Jul 26, 2023
2 parents 7343d12 + 74ee5bb commit 42ec4cc
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 43 deletions.
18 changes: 9 additions & 9 deletions zephyr/program/lotus/azalea/overlay.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
named-temp-sensors {
compatible = "cros-ec,temp-sensors";
local-f75303 {
temp_host_warn = <52>;
temp_host_high = <70>;
temp_host_warn = <70>;
temp_host_high = <80>;
temp_host_halt = <120>;
temp_host_release_warn = <45>;
temp_host_release_warn = <50>;
temp_host_release_high = <55>;
temp_host_release_halt = <115>;
temp_fan_off = <40>;
Expand All @@ -26,10 +26,10 @@
sensor = <&local_f75303>;
};
cpu-f75303 {
temp_host_warn = <61>;
temp_host_high = <70>;
temp_host_warn = <70>;
temp_host_high = <80>;
temp_host_halt = <120>;
temp_host_release_warn = <50>;
temp_host_release_warn = <53>;
temp_host_release_high = <55>;
temp_host_release_halt = <115>;
temp_fan_off = <46>;
Expand All @@ -38,10 +38,10 @@
sensor = <&cpu_f75303>;
};
ddr-f75303 {
temp_host_warn = <49>;
temp_host_high = <70>;
temp_host_warn = <70>;
temp_host_high = <80>;
temp_host_halt = <120>;
temp_host_release_warn = <45>;
temp_host_release_warn = <50>;
temp_host_release_high = <55>;
temp_host_release_halt = <115>;
temp_fan_off = <128>;
Expand Down
98 changes: 64 additions & 34 deletions zephyr/program/lotus/azalea/src/cpu_power.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,54 +74,64 @@ static void set_pl_limits(uint32_t spl, uint32_t fppt, uint32_t sppt, uint32_t p
update_peak_package_power_limit(p3t);
}

static void update_os_power_slider(int mode, int with_dc, int active_mpower)
static void update_os_power_slider(int mode, int active_mpower)
{
switch (mode) {
case EC_DC_BEST_PERFORMANCE:
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPL] = 30000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPPT] = 35000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_FPPT] = battery_mwatt_type - POWER_ROP;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_FPPT] =
((battery_mwatt_type == BATTERY_61mW) ? 46000 : 40000);
power_limit[FUNCTION_SLIDER].mwatt[TYPE_P3T] =
((battery_mwatt_type == BATTERY_61mW) ? 70000 : 80000);
CPRINTS("DC BEST PERFORMANCE");
break;
case EC_DC_BALANCED:
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPL] = 28000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPPT] = 33000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_FPPT] = battery_mwatt_type - POWER_ROP;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_FPPT] =
((battery_mwatt_type == BATTERY_61mW) ? 41000 : 35000);
power_limit[FUNCTION_SLIDER].mwatt[TYPE_P3T] =
((battery_mwatt_type == BATTERY_61mW) ? 70000 : 80000);
CPRINTS("DC BALANCED");
break;
case EC_DC_BEST_EFFICIENCY:
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPL] = 15000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPPT] = 20000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_FPPT] = 30000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_P3T] =
((battery_mwatt_type == BATTERY_61mW) ? 70000 : 80000);
CPRINTS("DC BEST EFFICIENCY");
break;
case EC_DC_BATTERY_SAVER:
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPL] = 15000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPPT] = 15000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_FPPT] = 30000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_P3T] = battery_mwatt_type;
CPRINTS("DC BATTERY SAVER");
break;
case EC_AC_BEST_PERFORMANCE:
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPL] = 30000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPPT] =
(with_dc ? 35000 : (MIN(35000, ((active_mpower - 15000) * 9 / 10))));
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPPT] = 35000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_FPPT] = 53000;
/* p3t is for minimum power table */
power_limit[FUNCTION_SLIDER].mwatt[TYPE_P3T] = 30000;
CPRINTS("AC BEST PERFORMANCE");
break;
case EC_AC_BALANCED:
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPL] = 28000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPPT] =
(with_dc ? 33000 : (MIN(33000, ((active_mpower - 15000) * 9 / 10))));
power_limit[FUNCTION_SLIDER].mwatt[TYPE_FPPT] =
(with_dc ? 51000 : (MIN(51000, (active_mpower - 15000))));
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPPT] = 33000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_FPPT] = 51000;
/* p3t is for minimum power table */
power_limit[FUNCTION_SLIDER].mwatt[TYPE_P3T] = 28000;
CPRINTS("AC BALANCED");
break;
case EC_AC_BEST_EFFICIENCY:
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPL] = (with_dc ? 15000 : 28000);
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPPT] =
(with_dc ? 25000 : (MIN(33000, ((active_mpower - 15000) * 9 / 10))));
power_limit[FUNCTION_SLIDER].mwatt[TYPE_FPPT] =
(with_dc ? 30000 : (MIN(51000, (active_mpower - 15000))));
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPL] = 15000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPPT] = 25000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_FPPT] = 30000;
/* p3t is for minimum power table */
power_limit[FUNCTION_SLIDER].mwatt[TYPE_P3T] = 28000;
CPRINTS("AC BEST EFFICIENCY");
break;
default:
Expand All @@ -130,33 +140,50 @@ static void update_os_power_slider(int mode, int with_dc, int active_mpower)
}
}

static void update_adapter_power_limit(int battery_percent, int active_mpower)
static void update_adapter_power_limit(int battery_percent,
int active_mpower, bool with_dc, int ports_cost)
{
if ((active_mpower < 55000)) {
/* dc mode (active_mpower == 0) or AC < 55W (active_mpower == 0) */
/* DC mode (active_mpower == 0) or AC < 55W (active_mpower == 0) */
power_limit[FUNCTION_POWER].mwatt[TYPE_SPL] = 30000;
power_limit[FUNCTION_POWER].mwatt[TYPE_SPPT] = battery_mwatt_type - POWER_ROP;
power_limit[FUNCTION_POWER].mwatt[TYPE_FPPT] = battery_mwatt_type - POWER_ROP;
power_limit[FUNCTION_POWER].mwatt[TYPE_SPPT] = 35000;
power_limit[FUNCTION_POWER].mwatt[TYPE_FPPT] =
((battery_mwatt_type == BATTERY_61mW) ? 46000 : 40000);
power_limit[FUNCTION_POWER].mwatt[TYPE_P3T] =
battery_mwatt_p3t - POWER_ROP - POWER_PORT_COST;
} else if (battery_percent > 40) {
/* ADP > 55W and Battery percentage > 40% */
power_limit[FUNCTION_SLIDER].mwatt[TYPE_P3T];
} else if (!with_dc) {
/* AC only and AC >= 55W */
power_limit[FUNCTION_POWER].mwatt[TYPE_SPL] = 30000;
power_limit[FUNCTION_POWER].mwatt[TYPE_SPPT] =
MIN(43000, (active_mpower * 85 / 100) + battery_mwatt_type - POWER_ROP);
MIN(power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPPT],
(active_mpower - 15000 - ports_cost));
power_limit[FUNCTION_POWER].mwatt[TYPE_FPPT] =
MIN(53000, (active_mpower * 85 / 100) + battery_mwatt_type - POWER_ROP);
power_limit[FUNCTION_POWER].mwatt[TYPE_P3T] = (active_mpower * 95 / 100)
+ battery_mwatt_type - POWER_ROP - POWER_PORT_COST;
MIN(power_limit[FUNCTION_SLIDER].mwatt[TYPE_FPPT],
(active_mpower - 15000 - ports_cost));
power_limit[FUNCTION_POWER].mwatt[TYPE_P3T] =
MAX(power_limit[FUNCTION_SLIDER].mwatt[TYPE_P3T],
((active_mpower * 95 / 100) - 20000));
} else if (battery_percent > 40) {
/* ADP > 55W and Battery percentage > 40% */
power_limit[FUNCTION_POWER].mwatt[TYPE_SPL] = 30000;
power_limit[FUNCTION_POWER].mwatt[TYPE_SPPT] = 35000;
power_limit[FUNCTION_POWER].mwatt[TYPE_FPPT] = 53000;
power_limit[FUNCTION_POWER].mwatt[TYPE_P3T] =
MAX(power_limit[FUNCTION_SLIDER].mwatt[TYPE_P3T],
((active_mpower * 95 / 100) - 20000
- (ports_cost ? 5000 : 0)) + battery_mwatt_type);
} else {
/* ADP > 55W and Battery percentage <= 40% */
power_limit[FUNCTION_POWER].mwatt[TYPE_SPL] = 30000;
power_limit[FUNCTION_POWER].mwatt[TYPE_SPPT] =
MIN(43000, (active_mpower * 85 / 100) - POWER_ROP);
MIN(power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPPT],
(active_mpower * 85 / 100) - 20000 - ports_cost);
power_limit[FUNCTION_POWER].mwatt[TYPE_FPPT] =
MIN(53000, (active_mpower * 85 / 100) - POWER_ROP);
MIN(power_limit[FUNCTION_SLIDER].mwatt[TYPE_FPPT],
(active_mpower * 85 / 100) - 20000 - ports_cost);
power_limit[FUNCTION_POWER].mwatt[TYPE_P3T] =
(active_mpower * 95 / 100) - POWER_ROP - POWER_PORT_COST;
MAX(power_limit[FUNCTION_SLIDER].mwatt[TYPE_P3T],
((active_mpower * 95 / 100) - 20000 - (ports_cost ? 5000 : 0)));
}
}

Expand Down Expand Up @@ -251,6 +278,9 @@ void update_soc_power_limit(bool force_update, bool force_no_adapter)
int active_mpower = charge_manager_get_power_limit_uw() / 1000;
bool with_dc = ((battery_is_present() == BP_YES) ? true : false);
int battery_percent = charge_get_percent();
int ports_cost;

ports_cost = cypd_get_port_cost();

/* azalea take 55W and lower adp as no ac */
if (force_no_adapter || (!extpower_is_present()) || (active_mpower < 55000)) {
Expand All @@ -261,10 +291,10 @@ void update_soc_power_limit(bool force_update, bool force_no_adapter)

if (old_slider_mode != mode) {
old_slider_mode = mode;
update_os_power_slider(mode, with_dc, active_mpower);
update_os_power_slider(mode, active_mpower);
}

update_adapter_power_limit(battery_percent, active_mpower);
update_adapter_power_limit(battery_percent, active_mpower, with_dc, ports_cost);

if (active_mpower == 0)
update_dc_safety_power_limit();
Expand Down Expand Up @@ -341,11 +371,11 @@ static void initial_soc_power_limit(void)
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPL] = 28000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_SPPT] = 33000;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_FPPT] =
battery_mwatt_type - POWER_ROP - POWER_PORT_COST;
((battery_mwatt_type == BATTERY_61mW) ? 41000 : 35000);
power_limit[FUNCTION_SLIDER].mwatt[TYPE_P3T] =
battery_mwatt_p3t - POWER_ROP - POWER_PORT_COST;
((battery_mwatt_type == BATTERY_61mW) ? 70000 : 80000);
power_limit[FUNCTION_POWER].mwatt[TYPE_P3T] =
battery_mwatt_p3t - POWER_ROP - POWER_PORT_COST;
power_limit[FUNCTION_SLIDER].mwatt[TYPE_P3T];
}
DECLARE_HOOK(HOOK_INIT, initial_soc_power_limit, HOOK_PRIO_INIT_I2C);

Expand All @@ -357,8 +387,8 @@ static int cmd_cpupower(int argc, const char **argv)
CPRINTF("Now SOC Power Limit:\n FUNC = %d, SPL %dmW,\n",
target_func[TYPE_SPL], power_limit[target_func[TYPE_SPL]].mwatt[TYPE_SPL]);
CPRINTF("FUNC = %d, fPPT %dmW,\n FUNC = %d, sPPT %dmW,\n FUNC = %d, p3T %dmW\n",
target_func[TYPE_SPPT], power_limit[target_func[TYPE_SPPT]].mwatt[TYPE_SPPT],
target_func[TYPE_FPPT], power_limit[target_func[TYPE_FPPT]].mwatt[TYPE_FPPT],
target_func[TYPE_SPPT], power_limit[target_func[TYPE_SPPT]].mwatt[TYPE_SPPT],
target_func[TYPE_P3T], power_limit[target_func[TYPE_P3T]].mwatt[TYPE_P3T]);

if (argc >= 2) {
Expand Down
1 change: 1 addition & 0 deletions zephyr/program/lotus/include/cpu_power.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ struct power_limit_details {
void update_soc_power_limit(bool force_update, bool force_no_adapter);

extern bool thermal_warn_trigger(void);
extern int cypd_get_port_cost(void);

#endif /* __CROS_EC_CPU_POWER_H */
7 changes: 7 additions & 0 deletions zephyr/program/lotus/include/cypress_pd_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,11 @@ int active_charge_pd_chip(void);
*/
int cypd_vbus_state_check(void);

/**
* Return total ports cost, return by mW.
*
* @return int
*/
int cypd_get_port_cost(void);

#endif /* __CROS_EC_CYPRESS_PD_COMMON_H */
18 changes: 18 additions & 0 deletions zephyr/program/lotus/src/cypress_pd_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,24 @@ void cypd_reinitialize(void)
}
}

/*****************************************************************************/
/* project function */

int cypd_get_port_cost(void)
{
int cost_sum = 0;

/* assume per port cost 5W */
for (int port_idx = 0; port_idx < PD_PORT_COUNT; port_idx++) {
if ((pd_port_states[port_idx].c_state == CCG_STATUS_SINK) ||
((pd_port_states[port_idx].pd_state)
&& (pd_port_states[port_idx].power_role == PD_ROLE_SOURCE)))
cost_sum = cost_sum + 5000000;
}

return (cost_sum / 1000);
}

/*****************************************************************************/
/* Host command */

Expand Down

0 comments on commit 42ec4cc

Please sign in to comment.