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 26*b41b0ce5SGeorgi Djakov /** 27*b41b0ce5SGeorgi Djakov * struct icc_bulk_data - Data used for bulk icc operations. 28*b41b0ce5SGeorgi Djakov * 29*b41b0ce5SGeorgi Djakov * @path: reference to the interconnect path (internal use) 30*b41b0ce5SGeorgi Djakov * @name: the name from the "interconnect-names" DT property 31*b41b0ce5SGeorgi Djakov * @avg_bw: average bandwidth in icc units 32*b41b0ce5SGeorgi Djakov * @peak_bw: peak bandwidth in icc units 33*b41b0ce5SGeorgi Djakov */ 34*b41b0ce5SGeorgi Djakov struct icc_bulk_data { 35*b41b0ce5SGeorgi Djakov struct icc_path *path; 36*b41b0ce5SGeorgi Djakov const char *name; 37*b41b0ce5SGeorgi Djakov u32 avg_bw; 38*b41b0ce5SGeorgi Djakov u32 peak_bw; 39*b41b0ce5SGeorgi Djakov }; 40*b41b0ce5SGeorgi Djakov 41*b41b0ce5SGeorgi Djakov int __must_check of_icc_bulk_get(struct device *dev, int num_paths, 42*b41b0ce5SGeorgi Djakov struct icc_bulk_data *paths); 43*b41b0ce5SGeorgi Djakov void icc_bulk_put(int num_paths, struct icc_bulk_data *paths); 44*b41b0ce5SGeorgi Djakov int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths); 45*b41b0ce5SGeorgi Djakov int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths); 46*b41b0ce5SGeorgi Djakov void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths); 47*b41b0ce5SGeorgi Djakov 4811f1cecaSGeorgi Djakov #if IS_ENABLED(CONFIG_INTERCONNECT) 4911f1cecaSGeorgi Djakov 5011f1cecaSGeorgi Djakov struct icc_path *icc_get(struct device *dev, const int src_id, 5111f1cecaSGeorgi Djakov const int dst_id); 5287e3031bSGeorgi Djakov struct icc_path *of_icc_get(struct device *dev, const char *name); 53e145d9a1SAkash Asthana struct icc_path *devm_of_icc_get(struct device *dev, const char *name); 541597d453SGeorgi Djakov struct icc_path *of_icc_get_by_index(struct device *dev, int idx); 5511f1cecaSGeorgi Djakov void icc_put(struct icc_path *path); 567d374b20SGeorgi Djakov int icc_enable(struct icc_path *path); 577d374b20SGeorgi Djakov int icc_disable(struct icc_path *path); 5811f1cecaSGeorgi Djakov int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw); 59127ab2ccSGeorgi Djakov void icc_set_tag(struct icc_path *path, u32 tag); 600430b1d5SViresh Kumar const char *icc_get_name(struct icc_path *path); 6111f1cecaSGeorgi Djakov 6211f1cecaSGeorgi Djakov #else 6311f1cecaSGeorgi Djakov 6411f1cecaSGeorgi Djakov static inline struct icc_path *icc_get(struct device *dev, const int src_id, 6511f1cecaSGeorgi Djakov const int dst_id) 6611f1cecaSGeorgi Djakov { 6711f1cecaSGeorgi Djakov return NULL; 6811f1cecaSGeorgi Djakov } 6911f1cecaSGeorgi Djakov 7087e3031bSGeorgi Djakov static inline struct icc_path *of_icc_get(struct device *dev, 7187e3031bSGeorgi Djakov const char *name) 7287e3031bSGeorgi Djakov { 7387e3031bSGeorgi Djakov return NULL; 7487e3031bSGeorgi Djakov } 7587e3031bSGeorgi Djakov 76e145d9a1SAkash Asthana static inline struct icc_path *devm_of_icc_get(struct device *dev, 77e145d9a1SAkash Asthana const char *name) 78e145d9a1SAkash Asthana { 79e145d9a1SAkash Asthana return NULL; 80e145d9a1SAkash Asthana } 81e145d9a1SAkash Asthana 821597d453SGeorgi Djakov static inline struct icc_path *of_icc_get_by_index(struct device *dev, int idx) 831597d453SGeorgi Djakov { 841597d453SGeorgi Djakov return NULL; 851597d453SGeorgi Djakov } 861597d453SGeorgi Djakov 8711f1cecaSGeorgi Djakov static inline void icc_put(struct icc_path *path) 8811f1cecaSGeorgi Djakov { 8911f1cecaSGeorgi Djakov } 9011f1cecaSGeorgi Djakov 917d374b20SGeorgi Djakov static inline int icc_enable(struct icc_path *path) 927d374b20SGeorgi Djakov { 937d374b20SGeorgi Djakov return 0; 947d374b20SGeorgi Djakov } 957d374b20SGeorgi Djakov 967d374b20SGeorgi Djakov static inline int icc_disable(struct icc_path *path) 977d374b20SGeorgi Djakov { 987d374b20SGeorgi Djakov return 0; 997d374b20SGeorgi Djakov } 1007d374b20SGeorgi Djakov 10111f1cecaSGeorgi Djakov static inline int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw) 10211f1cecaSGeorgi Djakov { 10311f1cecaSGeorgi Djakov return 0; 10411f1cecaSGeorgi Djakov } 10511f1cecaSGeorgi Djakov 106127ab2ccSGeorgi Djakov static inline void icc_set_tag(struct icc_path *path, u32 tag) 107127ab2ccSGeorgi Djakov { 108127ab2ccSGeorgi Djakov } 109127ab2ccSGeorgi Djakov 1100430b1d5SViresh Kumar static inline const char *icc_get_name(struct icc_path *path) 1110430b1d5SViresh Kumar { 1120430b1d5SViresh Kumar return NULL; 1130430b1d5SViresh Kumar } 1140430b1d5SViresh Kumar 11511f1cecaSGeorgi Djakov #endif /* CONFIG_INTERCONNECT */ 11611f1cecaSGeorgi Djakov 11711f1cecaSGeorgi Djakov #endif /* __LINUX_INTERCONNECT_H */ 118