1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (c) 2018-2019, Linaro Ltd.
4 * Author: Georgi Djakov <georgi.djakov@linaro.org>
5 */
6
7 #ifndef __LINUX_INTERCONNECT_H
8 #define __LINUX_INTERCONNECT_H
9
10 #include <linux/mutex.h>
11 #include <linux/types.h>
12
13 /* macros for converting to icc units */
14 #define Bps_to_icc(x) ((x) / 1000)
15 #define kBps_to_icc(x) (x)
16 #define MBps_to_icc(x) ((x) * 1000)
17 #define GBps_to_icc(x) ((x) * 1000 * 1000)
18 #define bps_to_icc(x) (1)
19 #define kbps_to_icc(x) (((x) + 7) / 8)
20 #define Mbps_to_icc(x) ((x) * 1000 / 8)
21 #define Gbps_to_icc(x) ((x) * 1000 * 1000 / 8)
22
23 /* macro to indicate dynamic id allocation */
24 #define ICC_ALLOC_DYN_ID -1
25
26 struct icc_path;
27 struct device;
28
29 /**
30 * struct icc_bulk_data - Data used for bulk icc operations.
31 *
32 * @path: reference to the interconnect path (internal use)
33 * @name: the name from the "interconnect-names" DT property
34 * @avg_bw: average bandwidth in icc units
35 * @peak_bw: peak bandwidth in icc units
36 */
37 struct icc_bulk_data {
38 struct icc_path *path;
39 const char *name;
40 u32 avg_bw;
41 u32 peak_bw;
42 };
43
44 #if IS_ENABLED(CONFIG_INTERCONNECT)
45
46 struct icc_path *of_icc_get(struct device *dev, const char *name);
47 struct icc_path *devm_of_icc_get(struct device *dev, const char *name);
48 int devm_of_icc_bulk_get(struct device *dev, int num_paths, struct icc_bulk_data *paths);
49 struct icc_path *of_icc_get_by_index(struct device *dev, int idx);
50 struct icc_path *devm_of_icc_get_by_index(struct device *dev, int idx);
51 void icc_put(struct icc_path *path);
52 int icc_enable(struct icc_path *path);
53 int icc_disable(struct icc_path *path);
54 int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw);
55 void icc_set_tag(struct icc_path *path, u32 tag);
56 const char *icc_get_name(struct icc_path *path);
57 int __must_check of_icc_bulk_get(struct device *dev, int num_paths,
58 struct icc_bulk_data *paths);
59 void icc_bulk_put(int num_paths, struct icc_bulk_data *paths);
60 int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths);
61 int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths);
62 void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths);
63
64 #else
65
of_icc_get(struct device * dev,const char * name)66 static inline struct icc_path *of_icc_get(struct device *dev,
67 const char *name)
68 {
69 return NULL;
70 }
71
devm_of_icc_get(struct device * dev,const char * name)72 static inline struct icc_path *devm_of_icc_get(struct device *dev,
73 const char *name)
74 {
75 return NULL;
76 }
77
of_icc_get_by_index(struct device * dev,int idx)78 static inline struct icc_path *of_icc_get_by_index(struct device *dev, int idx)
79 {
80 return NULL;
81 }
82
devm_of_icc_get_by_index(struct device * dev,int idx)83 static inline struct icc_path *devm_of_icc_get_by_index(struct device *dev, int idx)
84 {
85 return NULL;
86 }
87
icc_put(struct icc_path * path)88 static inline void icc_put(struct icc_path *path)
89 {
90 }
91
icc_enable(struct icc_path * path)92 static inline int icc_enable(struct icc_path *path)
93 {
94 return 0;
95 }
96
icc_disable(struct icc_path * path)97 static inline int icc_disable(struct icc_path *path)
98 {
99 return 0;
100 }
101
icc_set_bw(struct icc_path * path,u32 avg_bw,u32 peak_bw)102 static inline int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw)
103 {
104 return 0;
105 }
106
icc_set_tag(struct icc_path * path,u32 tag)107 static inline void icc_set_tag(struct icc_path *path, u32 tag)
108 {
109 }
110
icc_get_name(struct icc_path * path)111 static inline const char *icc_get_name(struct icc_path *path)
112 {
113 return NULL;
114 }
115
of_icc_bulk_get(struct device * dev,int num_paths,struct icc_bulk_data * paths)116 static inline int of_icc_bulk_get(struct device *dev, int num_paths, struct icc_bulk_data *paths)
117 {
118 return 0;
119 }
120
devm_of_icc_bulk_get(struct device * dev,int num_paths,struct icc_bulk_data * paths)121 static inline int devm_of_icc_bulk_get(struct device *dev, int num_paths,
122 struct icc_bulk_data *paths)
123 {
124 return 0;
125 }
126
icc_bulk_put(int num_paths,struct icc_bulk_data * paths)127 static inline void icc_bulk_put(int num_paths, struct icc_bulk_data *paths)
128 {
129 }
130
icc_bulk_set_bw(int num_paths,const struct icc_bulk_data * paths)131 static inline int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths)
132 {
133 return 0;
134 }
135
icc_bulk_enable(int num_paths,const struct icc_bulk_data * paths)136 static inline int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths)
137 {
138 return 0;
139 }
140
icc_bulk_disable(int num_paths,const struct icc_bulk_data * paths)141 static inline void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths)
142 {
143 }
144
145 #endif /* CONFIG_INTERCONNECT */
146
147 #endif /* __LINUX_INTERCONNECT_H */
148