xref: /linux/include/linux/dtpm.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1a20d0ef9SDaniel Lezcano /* SPDX-License-Identifier: GPL-2.0-only */
2a20d0ef9SDaniel Lezcano /*
3a20d0ef9SDaniel Lezcano  * Copyright (C) 2020 Linaro Ltd
4a20d0ef9SDaniel Lezcano  *
5a20d0ef9SDaniel Lezcano  * Author: Daniel Lezcano <daniel.lezcano@linaro.org>
6a20d0ef9SDaniel Lezcano  */
7a20d0ef9SDaniel Lezcano #ifndef ___DTPM_H__
8a20d0ef9SDaniel Lezcano #define ___DTPM_H__
9a20d0ef9SDaniel Lezcano 
10a20d0ef9SDaniel Lezcano #include <linux/powercap.h>
11a20d0ef9SDaniel Lezcano 
12a20d0ef9SDaniel Lezcano #define MAX_DTPM_DESCR 8
13a20d0ef9SDaniel Lezcano #define MAX_DTPM_CONSTRAINTS 1
14a20d0ef9SDaniel Lezcano 
15a20d0ef9SDaniel Lezcano struct dtpm {
16a20d0ef9SDaniel Lezcano 	struct powercap_zone zone;
17a20d0ef9SDaniel Lezcano 	struct dtpm *parent;
18a20d0ef9SDaniel Lezcano 	struct list_head sibling;
19a20d0ef9SDaniel Lezcano 	struct list_head children;
20a20d0ef9SDaniel Lezcano 	struct dtpm_ops *ops;
21a20d0ef9SDaniel Lezcano 	unsigned long flags;
22a20d0ef9SDaniel Lezcano 	u64 power_limit;
23a20d0ef9SDaniel Lezcano 	u64 power_max;
24a20d0ef9SDaniel Lezcano 	u64 power_min;
25a20d0ef9SDaniel Lezcano 	int weight;
26a20d0ef9SDaniel Lezcano };
27a20d0ef9SDaniel Lezcano 
28a20d0ef9SDaniel Lezcano struct dtpm_ops {
29a20d0ef9SDaniel Lezcano 	u64 (*set_power_uw)(struct dtpm *, u64);
30a20d0ef9SDaniel Lezcano 	u64 (*get_power_uw)(struct dtpm *);
314570dddaSDaniel Lezcano 	int (*update_power_uw)(struct dtpm *);
32a20d0ef9SDaniel Lezcano 	void (*release)(struct dtpm *);
33a20d0ef9SDaniel Lezcano };
34a20d0ef9SDaniel Lezcano 
353759ec67SDaniel Lezcano struct device_node;
363759ec67SDaniel Lezcano 
37b9794a82SDaniel Lezcano struct dtpm_subsys_ops {
38b9794a82SDaniel Lezcano 	const char *name;
39b9794a82SDaniel Lezcano 	int (*init)(void);
40*c404c64dSDaniel Lezcano 	void (*exit)(void);
413759ec67SDaniel Lezcano 	int (*setup)(struct dtpm *, struct device_node *);
423759ec67SDaniel Lezcano };
433759ec67SDaniel Lezcano 
443759ec67SDaniel Lezcano enum DTPM_NODE_TYPE {
453759ec67SDaniel Lezcano 	DTPM_NODE_VIRTUAL = 0,
463759ec67SDaniel Lezcano 	DTPM_NODE_DT,
473759ec67SDaniel Lezcano };
483759ec67SDaniel Lezcano 
493759ec67SDaniel Lezcano struct dtpm_node {
503759ec67SDaniel Lezcano 	enum DTPM_NODE_TYPE type;
513759ec67SDaniel Lezcano 	const char *name;
523759ec67SDaniel Lezcano 	struct dtpm_node *parent;
53a20d0ef9SDaniel Lezcano };
54a20d0ef9SDaniel Lezcano 
to_dtpm(struct powercap_zone * zone)55a20d0ef9SDaniel Lezcano static inline struct dtpm *to_dtpm(struct powercap_zone *zone)
56a20d0ef9SDaniel Lezcano {
57a20d0ef9SDaniel Lezcano 	return container_of(zone, struct dtpm, zone);
58a20d0ef9SDaniel Lezcano }
59a20d0ef9SDaniel Lezcano 
604570dddaSDaniel Lezcano int dtpm_update_power(struct dtpm *dtpm);
61a20d0ef9SDaniel Lezcano 
62a20d0ef9SDaniel Lezcano int dtpm_release_zone(struct powercap_zone *pcz);
63a20d0ef9SDaniel Lezcano 
64d2cdc6adSDaniel Lezcano void dtpm_init(struct dtpm *dtpm, struct dtpm_ops *ops);
65a20d0ef9SDaniel Lezcano 
66a20d0ef9SDaniel Lezcano void dtpm_unregister(struct dtpm *dtpm);
67a20d0ef9SDaniel Lezcano 
68a20d0ef9SDaniel Lezcano int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent);
69a20d0ef9SDaniel Lezcano 
703759ec67SDaniel Lezcano int dtpm_create_hierarchy(struct of_device_id *dtpm_match_table);
71*c404c64dSDaniel Lezcano 
72*c404c64dSDaniel Lezcano void dtpm_destroy_hierarchy(void);
73a20d0ef9SDaniel Lezcano #endif
74