blob: 7a7f08678db70a0c56788b2f3aa4ff4b1d9dc31c [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (C) 2015 MediaTek Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
16#include <linux/module.h>
17#include <linux/thermal.h>
18
19#include "thermal_core.h"
20
21/**
22 * backward_compatible_throttle
23 * @tz - thermal_zone_device
24 *
25 * This function update the cooler state by monitoring the current
26 * temperature and trip points
27 */
28static int backward_compatible_throttle(struct thermal_zone_device *tz,
29 int trip)
30{
31 int trip_temp;
32 struct thermal_instance *instance;
33
34 if (trip == THERMAL_TRIPS_NONE)
35 trip_temp = tz->forced_passive;
36 else
37 tz->ops->get_trip_temp(tz, trip, &trip_temp);
38
39 list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
40 if (instance->trip != trip)
41 continue;
42
43 if (tz->temperature >= trip_temp)
44 instance->target = 1;
45 else
46 instance->target = 0;
47 instance->cdev->updated = false;
48 thermal_cdev_update(instance->cdev);
49 }
50
51 return 0;
52}
53
54static struct thermal_governor thermal_gov_backward_compatible = {
55 .name = "backward_compatible",
56 .throttle = backward_compatible_throttle,
57};
58
59static int __init thermal_gov_backward_compatible_init(void)
60{
61 return thermal_register_governor(&thermal_gov_backward_compatible);
62}
63
64static void __exit thermal_gov_backward_compatible_exit(void)
65{
66 thermal_unregister_governor(&thermal_gov_backward_compatible);
67}
68
69/* This should load after thermal framework */
70fs_initcall(thermal_gov_backward_compatible_init);
71module_exit(thermal_gov_backward_compatible_exit);
72
73MODULE_AUTHOR("Weiyi Lu");
74MODULE_DESCRIPTION("A backward compatible Thermal governor");
75MODULE_LICENSE("GPL");