Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *  thermal_core.h
0004  *
0005  *  Copyright (C) 2012  Intel Corp
0006  *  Author: Durgadoss R <durgadoss.r@intel.com>
0007  */
0008 
0009 #ifndef __THERMAL_CORE_H__
0010 #define __THERMAL_CORE_H__
0011 
0012 #include <linux/device.h>
0013 #include <linux/thermal.h>
0014 
0015 #include "thermal_netlink.h"
0016 
0017 /* Default Thermal Governor */
0018 #if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE)
0019 #define DEFAULT_THERMAL_GOVERNOR       "step_wise"
0020 #elif defined(CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE)
0021 #define DEFAULT_THERMAL_GOVERNOR       "fair_share"
0022 #elif defined(CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE)
0023 #define DEFAULT_THERMAL_GOVERNOR       "user_space"
0024 #elif defined(CONFIG_THERMAL_DEFAULT_GOV_POWER_ALLOCATOR)
0025 #define DEFAULT_THERMAL_GOVERNOR       "power_allocator"
0026 #endif
0027 
0028 /* Initial state of a cooling device during binding */
0029 #define THERMAL_NO_TARGET -1UL
0030 
0031 /* Init section thermal table */
0032 extern struct thermal_governor *__governor_thermal_table[];
0033 extern struct thermal_governor *__governor_thermal_table_end[];
0034 
0035 #define THERMAL_TABLE_ENTRY(table, name)            \
0036     static typeof(name) *__thermal_table_entry_##name   \
0037     __used __section("__" #table "_thermal_table") = &name
0038 
0039 #define THERMAL_GOVERNOR_DECLARE(name)  THERMAL_TABLE_ENTRY(governor, name)
0040 
0041 #define for_each_governor_table(__governor)     \
0042     for (__governor = __governor_thermal_table; \
0043          __governor < __governor_thermal_table_end; \
0044          __governor++)
0045 
0046 int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *),
0047               void *);
0048 
0049 int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *,
0050                           void *), void *);
0051 
0052 int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
0053                   void *thermal_governor);
0054 
0055 struct thermal_zone_device *thermal_zone_get_by_id(int id);
0056 
0057 struct thermal_attr {
0058     struct device_attribute attr;
0059     char name[THERMAL_NAME_LENGTH];
0060 };
0061 
0062 static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
0063 {
0064     return cdev->ops->get_requested_power && cdev->ops->state2power &&
0065         cdev->ops->power2state;
0066 }
0067 
0068 void thermal_cdev_update(struct thermal_cooling_device *);
0069 void __thermal_cdev_update(struct thermal_cooling_device *cdev);
0070 
0071 int get_tz_trend(struct thermal_zone_device *tz, int trip);
0072 
0073 struct thermal_instance *
0074 get_thermal_instance(struct thermal_zone_device *tz,
0075              struct thermal_cooling_device *cdev,
0076              int trip);
0077 
0078 /*
0079  * This structure is used to describe the behavior of
0080  * a certain cooling device on a certain trip point
0081  * in a certain thermal zone
0082  */
0083 struct thermal_instance {
0084     int id;
0085     char name[THERMAL_NAME_LENGTH];
0086     struct thermal_zone_device *tz;
0087     struct thermal_cooling_device *cdev;
0088     int trip;
0089     bool initialized;
0090     unsigned long upper;    /* Highest cooling state for this trip point */
0091     unsigned long lower;    /* Lowest cooling state for this trip point */
0092     unsigned long target;   /* expected cooling state */
0093     char attr_name[THERMAL_NAME_LENGTH];
0094     struct device_attribute attr;
0095     char weight_attr_name[THERMAL_NAME_LENGTH];
0096     struct device_attribute weight_attr;
0097     struct list_head tz_node; /* node in tz->thermal_instances */
0098     struct list_head cdev_node; /* node in cdev->thermal_instances */
0099     unsigned int weight; /* The weight of the cooling device */
0100 };
0101 
0102 #define to_thermal_zone(_dev) \
0103     container_of(_dev, struct thermal_zone_device, device)
0104 
0105 #define to_cooling_device(_dev) \
0106     container_of(_dev, struct thermal_cooling_device, device)
0107 
0108 int thermal_register_governor(struct thermal_governor *);
0109 void thermal_unregister_governor(struct thermal_governor *);
0110 int thermal_zone_device_set_policy(struct thermal_zone_device *, char *);
0111 int thermal_build_list_of_policies(char *buf);
0112 
0113 /* Helpers */
0114 void thermal_zone_set_trips(struct thermal_zone_device *tz);
0115 
0116 /* sysfs I/F */
0117 int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
0118 void thermal_zone_destroy_device_groups(struct thermal_zone_device *);
0119 void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *);
0120 void thermal_cooling_device_destroy_sysfs(struct thermal_cooling_device *cdev);
0121 /* used only at binding time */
0122 ssize_t trip_point_show(struct device *, struct device_attribute *, char *);
0123 ssize_t weight_show(struct device *, struct device_attribute *, char *);
0124 ssize_t weight_store(struct device *, struct device_attribute *, const char *,
0125              size_t);
0126 
0127 #ifdef CONFIG_THERMAL_STATISTICS
0128 void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
0129                      unsigned long new_state);
0130 #else
0131 static inline void
0132 thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
0133                     unsigned long new_state) {}
0134 #endif /* CONFIG_THERMAL_STATISTICS */
0135 
0136 /* device tree support */
0137 #ifdef CONFIG_THERMAL_OF
0138 int of_parse_thermal_zones(void);
0139 int of_thermal_get_ntrips(struct thermal_zone_device *);
0140 bool of_thermal_is_trip_valid(struct thermal_zone_device *, int);
0141 const struct thermal_trip *
0142 of_thermal_get_trip_points(struct thermal_zone_device *);
0143 #else
0144 static inline int of_parse_thermal_zones(void) { return 0; }
0145 static inline int of_thermal_get_ntrips(struct thermal_zone_device *tz)
0146 {
0147     return 0;
0148 }
0149 static inline bool of_thermal_is_trip_valid(struct thermal_zone_device *tz,
0150                         int trip)
0151 {
0152     return false;
0153 }
0154 static inline const struct thermal_trip *
0155 of_thermal_get_trip_points(struct thermal_zone_device *tz)
0156 {
0157     return NULL;
0158 }
0159 #endif
0160 
0161 int thermal_zone_device_is_enabled(struct thermal_zone_device *tz);
0162 
0163 #endif /* __THERMAL_CORE_H__ */