1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (C) 2020 Linaro Ltd 4 * 5 * Author: Daniel Lezcano <daniel.lezcano@linaro.org> 6 */ 7 #ifndef ___DTPM_H__ 8 #define ___DTPM_H__ 9 10 #include <linux/powercap.h> 11 12 #define MAX_DTPM_DESCR 8 13 #define MAX_DTPM_CONSTRAINTS 1 14 15 struct dtpm { 16 struct powercap_zone zone; 17 struct dtpm *parent; 18 struct list_head sibling; 19 struct list_head children; 20 struct dtpm_ops *ops; 21 unsigned long flags; 22 u64 power_limit; 23 u64 power_max; 24 u64 power_min; 25 int weight; 26 }; 27 28 struct dtpm_ops { 29 u64 (*set_power_uw)(struct dtpm *, u64); 30 u64 (*get_power_uw)(struct dtpm *); 31 int (*update_power_uw)(struct dtpm *); 32 void (*release)(struct dtpm *); 33 }; 34 35 typedef int (*dtpm_init_t)(void); 36 37 struct dtpm_descr { 38 dtpm_init_t init; 39 }; 40 41 /* Init section thermal table */ 42 extern struct dtpm_descr __dtpm_table[]; 43 extern struct dtpm_descr __dtpm_table_end[]; 44 45 #define DTPM_TABLE_ENTRY(name, __init) \ 46 static struct dtpm_descr __dtpm_table_entry_##name \ 47 __used __section("__dtpm_table") = { \ 48 .init = __init, \ 49 } 50 51 #define DTPM_DECLARE(name, init) DTPM_TABLE_ENTRY(name, init) 52 53 #define for_each_dtpm_table(__dtpm) \ 54 for (__dtpm = __dtpm_table; \ 55 __dtpm < __dtpm_table_end; \ 56 __dtpm++) 57 58 static inline struct dtpm *to_dtpm(struct powercap_zone *zone) 59 { 60 return container_of(zone, struct dtpm, zone); 61 } 62 63 int dtpm_update_power(struct dtpm *dtpm); 64 65 int dtpm_release_zone(struct powercap_zone *pcz); 66 67 void dtpm_init(struct dtpm *dtpm, struct dtpm_ops *ops); 68 69 void dtpm_unregister(struct dtpm *dtpm); 70 71 int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent); 72 73 #endif 74