interconnect.h (3436B)
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) / 8 + ((x) % 8 ? 1 : 0)) 20#define Mbps_to_icc(x) ((x) * 1000 / 8) 21#define Gbps_to_icc(x) ((x) * 1000 * 1000 / 8) 22 23struct icc_path; 24struct device; 25 26/** 27 * struct icc_bulk_data - Data used for bulk icc operations. 28 * 29 * @path: reference to the interconnect path (internal use) 30 * @name: the name from the "interconnect-names" DT property 31 * @avg_bw: average bandwidth in icc units 32 * @peak_bw: peak bandwidth in icc units 33 */ 34struct icc_bulk_data { 35 struct icc_path *path; 36 const char *name; 37 u32 avg_bw; 38 u32 peak_bw; 39}; 40 41#if IS_ENABLED(CONFIG_INTERCONNECT) 42 43struct icc_path *icc_get(struct device *dev, const int src_id, 44 const int dst_id); 45struct icc_path *of_icc_get(struct device *dev, const char *name); 46struct icc_path *devm_of_icc_get(struct device *dev, const char *name); 47struct icc_path *of_icc_get_by_index(struct device *dev, int idx); 48void icc_put(struct icc_path *path); 49int icc_enable(struct icc_path *path); 50int icc_disable(struct icc_path *path); 51int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw); 52void icc_set_tag(struct icc_path *path, u32 tag); 53const char *icc_get_name(struct icc_path *path); 54int __must_check of_icc_bulk_get(struct device *dev, int num_paths, 55 struct icc_bulk_data *paths); 56void icc_bulk_put(int num_paths, struct icc_bulk_data *paths); 57int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths); 58int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths); 59void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths); 60 61#else 62 63static inline struct icc_path *icc_get(struct device *dev, const int src_id, 64 const int dst_id) 65{ 66 return NULL; 67} 68 69static inline struct icc_path *of_icc_get(struct device *dev, 70 const char *name) 71{ 72 return NULL; 73} 74 75static inline struct icc_path *devm_of_icc_get(struct device *dev, 76 const char *name) 77{ 78 return NULL; 79} 80 81static inline struct icc_path *of_icc_get_by_index(struct device *dev, int idx) 82{ 83 return NULL; 84} 85 86static inline void icc_put(struct icc_path *path) 87{ 88} 89 90static inline int icc_enable(struct icc_path *path) 91{ 92 return 0; 93} 94 95static inline int icc_disable(struct icc_path *path) 96{ 97 return 0; 98} 99 100static inline int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw) 101{ 102 return 0; 103} 104 105static inline void icc_set_tag(struct icc_path *path, u32 tag) 106{ 107} 108 109static inline const char *icc_get_name(struct icc_path *path) 110{ 111 return NULL; 112} 113 114static inline int of_icc_bulk_get(struct device *dev, int num_paths, struct icc_bulk_data *paths) 115{ 116 return 0; 117} 118 119static inline void icc_bulk_put(int num_paths, struct icc_bulk_data *paths) 120{ 121} 122 123static inline int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths) 124{ 125 return 0; 126} 127 128static inline int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths) 129{ 130 return 0; 131} 132 133static inline void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths) 134{ 135} 136 137#endif /* CONFIG_INTERCONNECT */ 138 139#endif /* __LINUX_INTERCONNECT_H */