111f1cecaSGeorgi Djakov /* SPDX-License-Identifier: GPL-2.0 */
211f1cecaSGeorgi Djakov /*
311f1cecaSGeorgi Djakov * Copyright (c) 2018-2019, Linaro Ltd.
411f1cecaSGeorgi Djakov * Author: Georgi Djakov <georgi.djakov@linaro.org>
511f1cecaSGeorgi Djakov */
611f1cecaSGeorgi Djakov
711f1cecaSGeorgi Djakov #ifndef __LINUX_INTERCONNECT_H
811f1cecaSGeorgi Djakov #define __LINUX_INTERCONNECT_H
911f1cecaSGeorgi Djakov
1011f1cecaSGeorgi Djakov #include <linux/mutex.h>
1111f1cecaSGeorgi Djakov #include <linux/types.h>
1211f1cecaSGeorgi Djakov
1311f1cecaSGeorgi Djakov /* macros for converting to icc units */
1411f1cecaSGeorgi Djakov #define Bps_to_icc(x) ((x) / 1000)
1511f1cecaSGeorgi Djakov #define kBps_to_icc(x) (x)
1611f1cecaSGeorgi Djakov #define MBps_to_icc(x) ((x) * 1000)
1711f1cecaSGeorgi Djakov #define GBps_to_icc(x) ((x) * 1000 * 1000)
1811f1cecaSGeorgi Djakov #define bps_to_icc(x) (1)
1911f1cecaSGeorgi Djakov #define kbps_to_icc(x) ((x) / 8 + ((x) % 8 ? 1 : 0))
2011f1cecaSGeorgi Djakov #define Mbps_to_icc(x) ((x) * 1000 / 8)
2111f1cecaSGeorgi Djakov #define Gbps_to_icc(x) ((x) * 1000 * 1000 / 8)
2211f1cecaSGeorgi Djakov
2311f1cecaSGeorgi Djakov struct icc_path;
2411f1cecaSGeorgi Djakov struct device;
2511f1cecaSGeorgi Djakov
26b41b0ce5SGeorgi Djakov /**
27b41b0ce5SGeorgi Djakov * struct icc_bulk_data - Data used for bulk icc operations.
28b41b0ce5SGeorgi Djakov *
29b41b0ce5SGeorgi Djakov * @path: reference to the interconnect path (internal use)
30b41b0ce5SGeorgi Djakov * @name: the name from the "interconnect-names" DT property
31b41b0ce5SGeorgi Djakov * @avg_bw: average bandwidth in icc units
32b41b0ce5SGeorgi Djakov * @peak_bw: peak bandwidth in icc units
33b41b0ce5SGeorgi Djakov */
34b41b0ce5SGeorgi Djakov struct icc_bulk_data {
35b41b0ce5SGeorgi Djakov struct icc_path *path;
36b41b0ce5SGeorgi Djakov const char *name;
37b41b0ce5SGeorgi Djakov u32 avg_bw;
38b41b0ce5SGeorgi Djakov u32 peak_bw;
39b41b0ce5SGeorgi Djakov };
40b41b0ce5SGeorgi Djakov
4111f1cecaSGeorgi Djakov #if IS_ENABLED(CONFIG_INTERCONNECT)
4211f1cecaSGeorgi Djakov
4387e3031bSGeorgi Djakov struct icc_path *of_icc_get(struct device *dev, const char *name);
44e145d9a1SAkash Asthana struct icc_path *devm_of_icc_get(struct device *dev, const char *name);
45*2fcfa72fSPeng Fan int devm_of_icc_bulk_get(struct device *dev, int num_paths, struct icc_bulk_data *paths);
461597d453SGeorgi Djakov struct icc_path *of_icc_get_by_index(struct device *dev, int idx);
4711f1cecaSGeorgi Djakov void icc_put(struct icc_path *path);
487d374b20SGeorgi Djakov int icc_enable(struct icc_path *path);
497d374b20SGeorgi Djakov int icc_disable(struct icc_path *path);
5011f1cecaSGeorgi Djakov int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw);
51127ab2ccSGeorgi Djakov void icc_set_tag(struct icc_path *path, u32 tag);
520430b1d5SViresh Kumar const char *icc_get_name(struct icc_path *path);
53e45f1c1dSGeorgi Djakov int __must_check of_icc_bulk_get(struct device *dev, int num_paths,
54e45f1c1dSGeorgi Djakov struct icc_bulk_data *paths);
55e45f1c1dSGeorgi Djakov void icc_bulk_put(int num_paths, struct icc_bulk_data *paths);
56e45f1c1dSGeorgi Djakov int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths);
57e45f1c1dSGeorgi Djakov int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths);
58e45f1c1dSGeorgi Djakov void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths);
5911f1cecaSGeorgi Djakov
6011f1cecaSGeorgi Djakov #else
6111f1cecaSGeorgi Djakov
of_icc_get(struct device * dev,const char * name)6287e3031bSGeorgi Djakov static inline struct icc_path *of_icc_get(struct device *dev,
6387e3031bSGeorgi Djakov const char *name)
6487e3031bSGeorgi Djakov {
6587e3031bSGeorgi Djakov return NULL;
6687e3031bSGeorgi Djakov }
6787e3031bSGeorgi Djakov
devm_of_icc_get(struct device * dev,const char * name)68e145d9a1SAkash Asthana static inline struct icc_path *devm_of_icc_get(struct device *dev,
69e145d9a1SAkash Asthana const char *name)
70e145d9a1SAkash Asthana {
71e145d9a1SAkash Asthana return NULL;
72e145d9a1SAkash Asthana }
73e145d9a1SAkash Asthana
of_icc_get_by_index(struct device * dev,int idx)741597d453SGeorgi Djakov static inline struct icc_path *of_icc_get_by_index(struct device *dev, int idx)
751597d453SGeorgi Djakov {
761597d453SGeorgi Djakov return NULL;
771597d453SGeorgi Djakov }
781597d453SGeorgi Djakov
icc_put(struct icc_path * path)7911f1cecaSGeorgi Djakov static inline void icc_put(struct icc_path *path)
8011f1cecaSGeorgi Djakov {
8111f1cecaSGeorgi Djakov }
8211f1cecaSGeorgi Djakov
icc_enable(struct icc_path * path)837d374b20SGeorgi Djakov static inline int icc_enable(struct icc_path *path)
847d374b20SGeorgi Djakov {
857d374b20SGeorgi Djakov return 0;
867d374b20SGeorgi Djakov }
877d374b20SGeorgi Djakov
icc_disable(struct icc_path * path)887d374b20SGeorgi Djakov static inline int icc_disable(struct icc_path *path)
897d374b20SGeorgi Djakov {
907d374b20SGeorgi Djakov return 0;
917d374b20SGeorgi Djakov }
927d374b20SGeorgi Djakov
icc_set_bw(struct icc_path * path,u32 avg_bw,u32 peak_bw)9311f1cecaSGeorgi Djakov static inline int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw)
9411f1cecaSGeorgi Djakov {
9511f1cecaSGeorgi Djakov return 0;
9611f1cecaSGeorgi Djakov }
9711f1cecaSGeorgi Djakov
icc_set_tag(struct icc_path * path,u32 tag)98127ab2ccSGeorgi Djakov static inline void icc_set_tag(struct icc_path *path, u32 tag)
99127ab2ccSGeorgi Djakov {
100127ab2ccSGeorgi Djakov }
101127ab2ccSGeorgi Djakov
icc_get_name(struct icc_path * path)1020430b1d5SViresh Kumar static inline const char *icc_get_name(struct icc_path *path)
1030430b1d5SViresh Kumar {
1040430b1d5SViresh Kumar return NULL;
1050430b1d5SViresh Kumar }
1060430b1d5SViresh Kumar
of_icc_bulk_get(struct device * dev,int num_paths,struct icc_bulk_data * paths)107e45f1c1dSGeorgi Djakov static inline int of_icc_bulk_get(struct device *dev, int num_paths, struct icc_bulk_data *paths)
108e45f1c1dSGeorgi Djakov {
109e45f1c1dSGeorgi Djakov return 0;
110e45f1c1dSGeorgi Djakov }
111e45f1c1dSGeorgi Djakov
devm_of_icc_bulk_get(struct device * dev,int num_paths,struct icc_bulk_data * paths)112*2fcfa72fSPeng Fan static inline int devm_of_icc_bulk_get(struct device *dev, int num_paths,
113*2fcfa72fSPeng Fan struct icc_bulk_data *paths)
114*2fcfa72fSPeng Fan {
115*2fcfa72fSPeng Fan return 0;
116*2fcfa72fSPeng Fan }
117*2fcfa72fSPeng Fan
icc_bulk_put(int num_paths,struct icc_bulk_data * paths)118e45f1c1dSGeorgi Djakov static inline void icc_bulk_put(int num_paths, struct icc_bulk_data *paths)
119e45f1c1dSGeorgi Djakov {
120e45f1c1dSGeorgi Djakov }
121e45f1c1dSGeorgi Djakov
icc_bulk_set_bw(int num_paths,const struct icc_bulk_data * paths)122e45f1c1dSGeorgi Djakov static inline int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths)
123e45f1c1dSGeorgi Djakov {
124e45f1c1dSGeorgi Djakov return 0;
125e45f1c1dSGeorgi Djakov }
126e45f1c1dSGeorgi Djakov
icc_bulk_enable(int num_paths,const struct icc_bulk_data * paths)127e45f1c1dSGeorgi Djakov static inline int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths)
128e45f1c1dSGeorgi Djakov {
129e45f1c1dSGeorgi Djakov return 0;
130e45f1c1dSGeorgi Djakov }
131e45f1c1dSGeorgi Djakov
icc_bulk_disable(int num_paths,const struct icc_bulk_data * paths)132e45f1c1dSGeorgi Djakov static inline void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths)
133e45f1c1dSGeorgi Djakov {
134e45f1c1dSGeorgi Djakov }
135e45f1c1dSGeorgi Djakov
13611f1cecaSGeorgi Djakov #endif /* CONFIG_INTERCONNECT */
13711f1cecaSGeorgi Djakov
13811f1cecaSGeorgi Djakov #endif /* __LINUX_INTERCONNECT_H */
139