#include <linux/slab.h>
#include <linux/string.h>
#include <linux/types.h>
+#include <linux/workqueue.h>
MODULE_AUTHOR("Matthew Garrett <mjg59@srcf.ucam.org>");
MODULE_DESCRIPTION("HP laptop WMI driver");
u8 gpu_delta;
u8 mode;
u8 pwm;
+ struct delayed_work keep_alive_dwork;
};
struct victus_s_fan_table_header {
struct victus_s_fan_table_entry entries[];
} __packed;
+/*
+ * 90s delay to prevent the firmware from resetting fan mode after fixed
+ * 120s timeout
+ */
+#define KEEP_ALIVE_DELAY_SECS 90
+
static inline u8 rpm_to_pwm(u8 rpm, struct hp_wmi_hwmon_priv *priv)
{
return fixp_linear_interpolate(0, 0, priv->max_rpm, U8_MAX,
static void __exit hp_wmi_bios_remove(struct platform_device *device)
{
int i;
+ struct hp_wmi_hwmon_priv *priv;
for (i = 0; i < rfkill2_count; i++) {
rfkill_unregister(rfkill2[i].rfkill);
rfkill_unregister(wwan_rfkill);
rfkill_destroy(wwan_rfkill);
}
+
+ priv = platform_get_drvdata(device);
+ if (priv)
+ cancel_delayed_work_sync(&priv->keep_alive_dwork);
}
static int hp_wmi_resume_handler(struct device *device)
if (is_victus_s_thermal_profile())
hp_wmi_get_fan_count_userdefine_trigger();
ret = hp_wmi_fan_speed_max_set(1);
- return ret;
+ if (ret < 0)
+ return ret;
+ schedule_delayed_work(&priv->keep_alive_dwork,
+ secs_to_jiffies(KEEP_ALIVE_DELAY_SECS));
+ return 0;
case PWM_MODE_MANUAL:
if (!is_victus_s_thermal_profile())
return -EOPNOTSUPP;
ret = hp_wmi_fan_speed_set(priv, pwm_to_rpm(priv->pwm, priv));
- return ret;
+ if (ret < 0)
+ return ret;
+ schedule_delayed_work(&priv->keep_alive_dwork,
+ secs_to_jiffies(KEEP_ALIVE_DELAY_SECS));
+ return 0;
case PWM_MODE_AUTO:
if (is_victus_s_thermal_profile()) {
hp_wmi_get_fan_count_userdefine_trigger();
} else {
ret = hp_wmi_fan_speed_max_set(0);
}
- return ret;
+ if (ret < 0)
+ return ret;
+ cancel_delayed_work_sync(&priv->keep_alive_dwork);
+ return 0;
default:
/* shouldn't happen */
return -EINVAL;
.info = info,
};
+static void hp_wmi_hwmon_keep_alive_handler(struct work_struct *work)
+{
+ struct delayed_work *dwork;
+ struct hp_wmi_hwmon_priv *priv;
+
+ dwork = to_delayed_work(work);
+ priv = container_of(dwork, struct hp_wmi_hwmon_priv, keep_alive_dwork);
+ /*
+ * Re-apply the current hwmon context settings.
+ * NOTE: hp_wmi_apply_fan_settings will handle the re-scheduling.
+ */
+ hp_wmi_apply_fan_settings(priv);
+}
+
static int hp_wmi_setup_fan_settings(struct hp_wmi_hwmon_priv *priv)
{
u8 fan_data[128] = { 0 };
return PTR_ERR(hwmon);
}
+ INIT_DELAYED_WORK(&priv->keep_alive_dwork, hp_wmi_hwmon_keep_alive_handler);
+ platform_set_drvdata(hp_wmi_platform_dev, priv);
hp_wmi_apply_fan_settings(priv);
return 0;