17e3c0381SLina Iyer /* SPDX-License-Identifier: GPL-2.0 */ 271350db4SDurgadoss R /* 371350db4SDurgadoss R * thermal_core.h 471350db4SDurgadoss R * 571350db4SDurgadoss R * Copyright (C) 2012 Intel Corp 671350db4SDurgadoss R * Author: Durgadoss R <durgadoss.r@intel.com> 771350db4SDurgadoss R */ 871350db4SDurgadoss R 971350db4SDurgadoss R #ifndef __THERMAL_CORE_H__ 1071350db4SDurgadoss R #define __THERMAL_CORE_H__ 1171350db4SDurgadoss R 1271350db4SDurgadoss R #include <linux/device.h> 1371350db4SDurgadoss R #include <linux/thermal.h> 1471350db4SDurgadoss R 155b8583d3SDaniel Lezcano #include "thermal_netlink.h" 165b8583d3SDaniel Lezcano 178097db40SDaniel Lezcano /* Default Thermal Governor */ 188097db40SDaniel Lezcano #if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE) 198097db40SDaniel Lezcano #define DEFAULT_THERMAL_GOVERNOR "step_wise" 208097db40SDaniel Lezcano #elif defined(CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE) 218097db40SDaniel Lezcano #define DEFAULT_THERMAL_GOVERNOR "fair_share" 228097db40SDaniel Lezcano #elif defined(CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE) 238097db40SDaniel Lezcano #define DEFAULT_THERMAL_GOVERNOR "user_space" 248097db40SDaniel Lezcano #elif defined(CONFIG_THERMAL_DEFAULT_GOV_POWER_ALLOCATOR) 258097db40SDaniel Lezcano #define DEFAULT_THERMAL_GOVERNOR "power_allocator" 2604bf1fe4SThierry Reding #elif defined(CONFIG_THERMAL_DEFAULT_GOV_BANG_BANG) 2704bf1fe4SThierry Reding #define DEFAULT_THERMAL_GOVERNOR "bang_bang" 288097db40SDaniel Lezcano #endif 298097db40SDaniel Lezcano 3071350db4SDurgadoss R /* Initial state of a cooling device during binding */ 3171350db4SDurgadoss R #define THERMAL_NO_TARGET -1UL 3271350db4SDurgadoss R 33980af75eSDaniel Lezcano /* Init section thermal table */ 34980af75eSDaniel Lezcano extern struct thermal_governor *__governor_thermal_table[]; 35980af75eSDaniel Lezcano extern struct thermal_governor *__governor_thermal_table_end[]; 36980af75eSDaniel Lezcano 37980af75eSDaniel Lezcano #define THERMAL_TABLE_ENTRY(table, name) \ 38980af75eSDaniel Lezcano static typeof(name) *__thermal_table_entry_##name \ 3933def849SJoe Perches __used __section("__" #table "_thermal_table") = &name 40980af75eSDaniel Lezcano 41980af75eSDaniel Lezcano #define THERMAL_GOVERNOR_DECLARE(name) THERMAL_TABLE_ENTRY(governor, name) 42980af75eSDaniel Lezcano 43980af75eSDaniel Lezcano #define for_each_governor_table(__governor) \ 44980af75eSDaniel Lezcano for (__governor = __governor_thermal_table; \ 45980af75eSDaniel Lezcano __governor < __governor_thermal_table_end; \ 46980af75eSDaniel Lezcano __governor++) 47980af75eSDaniel Lezcano 483d44a509SDaniel Lezcano int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *), 493d44a509SDaniel Lezcano void *); 503d44a509SDaniel Lezcano 513d44a509SDaniel Lezcano int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *, 523d44a509SDaniel Lezcano void *), void *); 533d44a509SDaniel Lezcano 543d44a509SDaniel Lezcano int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *), 553d44a509SDaniel Lezcano void *thermal_governor); 563d44a509SDaniel Lezcano 57329b064fSDaniel Lezcano struct thermal_zone_device *thermal_zone_get_by_id(int id); 58329b064fSDaniel Lezcano 59c68df440SDaniel Lezcano struct thermal_attr { 60c68df440SDaniel Lezcano struct device_attribute attr; 61c68df440SDaniel Lezcano char name[THERMAL_NAME_LENGTH]; 62c68df440SDaniel Lezcano }; 63c68df440SDaniel Lezcano 6433a88af1SDaniel Lezcano static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev) 6533a88af1SDaniel Lezcano { 6633a88af1SDaniel Lezcano return cdev->ops->get_requested_power && cdev->ops->state2power && 6733a88af1SDaniel Lezcano cdev->ops->power2state; 6833a88af1SDaniel Lezcano } 6933a88af1SDaniel Lezcano 7023ff8529SDaniel Lezcano void thermal_cdev_update(struct thermal_cooling_device *); 71b70dbf40SLukasz Luba void __thermal_cdev_update(struct thermal_cooling_device *cdev); 7223ff8529SDaniel Lezcano 73*8289d810SRafael J. Wysocki int get_tz_trend(struct thermal_zone_device *tz, int trip_index); 74f0129c23SDaniel Lezcano 7506f1041fSDaniel Lezcano struct thermal_instance * 7606f1041fSDaniel Lezcano get_thermal_instance(struct thermal_zone_device *tz, 7706f1041fSDaniel Lezcano struct thermal_cooling_device *cdev, 7806f1041fSDaniel Lezcano int trip); 7906f1041fSDaniel Lezcano 8071350db4SDurgadoss R /* 8171350db4SDurgadoss R * This structure is used to describe the behavior of 8271350db4SDurgadoss R * a certain cooling device on a certain trip point 8371350db4SDurgadoss R * in a certain thermal zone 8471350db4SDurgadoss R */ 8571350db4SDurgadoss R struct thermal_instance { 8671350db4SDurgadoss R int id; 8771350db4SDurgadoss R char name[THERMAL_NAME_LENGTH]; 8871350db4SDurgadoss R struct thermal_zone_device *tz; 8971350db4SDurgadoss R struct thermal_cooling_device *cdev; 9071350db4SDurgadoss R int trip; 91bb431ba2SZhang Rui bool initialized; 9271350db4SDurgadoss R unsigned long upper; /* Highest cooling state for this trip point */ 9371350db4SDurgadoss R unsigned long lower; /* Lowest cooling state for this trip point */ 9471350db4SDurgadoss R unsigned long target; /* expected cooling state */ 9571350db4SDurgadoss R char attr_name[THERMAL_NAME_LENGTH]; 9671350db4SDurgadoss R struct device_attribute attr; 97db916513SJavi Merino char weight_attr_name[THERMAL_NAME_LENGTH]; 98db916513SJavi Merino struct device_attribute weight_attr; 9971350db4SDurgadoss R struct list_head tz_node; /* node in tz->thermal_instances */ 10071350db4SDurgadoss R struct list_head cdev_node; /* node in cdev->thermal_instances */ 1016cd9e9f6SKapileshwar Singh unsigned int weight; /* The weight of the cooling device */ 102790930f4SRafael J. Wysocki bool upper_no_limit; 10371350db4SDurgadoss R }; 10471350db4SDurgadoss R 105ba78da44SEduardo Valentin #define to_thermal_zone(_dev) \ 106ba78da44SEduardo Valentin container_of(_dev, struct thermal_zone_device, device) 107ba78da44SEduardo Valentin 10899ea2effSEduardo Valentin #define to_cooling_device(_dev) \ 10999ea2effSEduardo Valentin container_of(_dev, struct thermal_cooling_device, device) 11099ea2effSEduardo Valentin 11180a26a5cSZhang Rui int thermal_register_governor(struct thermal_governor *); 11280a26a5cSZhang Rui void thermal_unregister_governor(struct thermal_governor *); 1136b885202SEduardo Valentin int thermal_zone_device_set_policy(struct thermal_zone_device *, char *); 11497d2423bSEduardo Valentin int thermal_build_list_of_policies(char *buf); 11505eeee2bSGuenter Roeck void __thermal_zone_device_update(struct thermal_zone_device *tz, 11605eeee2bSGuenter Roeck enum thermal_notify_event event); 11780a26a5cSZhang Rui 118bceb5646SDaniel Lezcano /* Helpers */ 119a930da9bSDaniel Lezcano void __thermal_zone_set_trips(struct thermal_zone_device *tz); 1207c3d5c20SDaniel Lezcano int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, 1217c3d5c20SDaniel Lezcano struct thermal_trip *trip); 122a930da9bSDaniel Lezcano int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp); 123bceb5646SDaniel Lezcano 124a369ee88SEduardo Valentin /* sysfs I/F */ 125a369ee88SEduardo Valentin int thermal_zone_create_device_groups(struct thermal_zone_device *, int); 12632fa5ba3SChristophe Jaillet void thermal_zone_destroy_device_groups(struct thermal_zone_device *); 12745cf2ec9SEduardo Valentin void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *); 1288ea22951SViresh Kumar void thermal_cooling_device_destroy_sysfs(struct thermal_cooling_device *cdev); 129790930f4SRafael J. Wysocki void thermal_cooling_device_stats_reinit(struct thermal_cooling_device *cdev); 13045cf2ec9SEduardo Valentin /* used only at binding time */ 13133e678d4SViresh Kumar ssize_t trip_point_show(struct device *, struct device_attribute *, char *); 13233e678d4SViresh Kumar ssize_t weight_show(struct device *, struct device_attribute *, char *); 13333e678d4SViresh Kumar ssize_t weight_store(struct device *, struct device_attribute *, const char *, 13433e678d4SViresh Kumar size_t); 135a369ee88SEduardo Valentin 1368ea22951SViresh Kumar #ifdef CONFIG_THERMAL_STATISTICS 1378ea22951SViresh Kumar void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, 1388ea22951SViresh Kumar unsigned long new_state); 1398ea22951SViresh Kumar #else 1408ea22951SViresh Kumar static inline void 1418ea22951SViresh Kumar thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, 1428ea22951SViresh Kumar unsigned long new_state) {} 1438ea22951SViresh Kumar #endif /* CONFIG_THERMAL_STATISTICS */ 1448ea22951SViresh Kumar 1454e5e4705SEduardo Valentin /* device tree support */ 146514acd00SAndrzej Pietrasiewicz int thermal_zone_device_is_enabled(struct thermal_zone_device *tz); 147514acd00SAndrzej Pietrasiewicz 14871350db4SDurgadoss R #endif /* __THERMAL_CORE_H__ */ 149