Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 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 | |
| 23 | struct icc_path; |
| 24 | struct device; |
| 25 | |
Georgi Djakov | b41b0ce | 2020-07-29 15:34:39 +0300 | [diff] [blame] | 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 | */ |
| 34 | struct icc_bulk_data { |
| 35 | struct icc_path *path; |
| 36 | const char *name; |
| 37 | u32 avg_bw; |
| 38 | u32 peak_bw; |
| 39 | }; |
| 40 | |
| 41 | int __must_check of_icc_bulk_get(struct device *dev, int num_paths, |
| 42 | struct icc_bulk_data *paths); |
| 43 | void icc_bulk_put(int num_paths, struct icc_bulk_data *paths); |
| 44 | int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths); |
| 45 | int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths); |
| 46 | void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths); |
| 47 | |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 48 | #if IS_ENABLED(CONFIG_INTERCONNECT) |
| 49 | |
| 50 | struct icc_path *icc_get(struct device *dev, const int src_id, |
| 51 | const int dst_id); |
Georgi Djakov | 87e3031 | 2019-01-16 18:10:58 +0200 | [diff] [blame] | 52 | struct icc_path *of_icc_get(struct device *dev, const char *name); |
Akash Asthana | e145d9a | 2020-04-15 15:53:10 +0530 | [diff] [blame] | 53 | struct icc_path *devm_of_icc_get(struct device *dev, const char *name); |
Georgi Djakov | 1597d45 | 2020-05-12 15:53:20 +0300 | [diff] [blame] | 54 | struct icc_path *of_icc_get_by_index(struct device *dev, int idx); |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 55 | void icc_put(struct icc_path *path); |
Georgi Djakov | 7d374b2 | 2020-05-10 18:30:37 +0300 | [diff] [blame] | 56 | int icc_enable(struct icc_path *path); |
| 57 | int icc_disable(struct icc_path *path); |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 58 | int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw); |
Georgi Djakov | 127ab2c | 2019-08-09 15:13:23 +0300 | [diff] [blame] | 59 | void icc_set_tag(struct icc_path *path, u32 tag); |
Viresh Kumar | 0430b1d | 2020-05-18 14:25:32 +0300 | [diff] [blame] | 60 | const char *icc_get_name(struct icc_path *path); |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 61 | |
| 62 | #else |
| 63 | |
| 64 | static inline struct icc_path *icc_get(struct device *dev, const int src_id, |
| 65 | const int dst_id) |
| 66 | { |
| 67 | return NULL; |
| 68 | } |
| 69 | |
Georgi Djakov | 87e3031 | 2019-01-16 18:10:58 +0200 | [diff] [blame] | 70 | static inline struct icc_path *of_icc_get(struct device *dev, |
| 71 | const char *name) |
| 72 | { |
| 73 | return NULL; |
| 74 | } |
| 75 | |
Akash Asthana | e145d9a | 2020-04-15 15:53:10 +0530 | [diff] [blame] | 76 | static inline struct icc_path *devm_of_icc_get(struct device *dev, |
| 77 | const char *name) |
| 78 | { |
| 79 | return NULL; |
| 80 | } |
| 81 | |
Georgi Djakov | 1597d45 | 2020-05-12 15:53:20 +0300 | [diff] [blame] | 82 | static inline struct icc_path *of_icc_get_by_index(struct device *dev, int idx) |
| 83 | { |
| 84 | return NULL; |
| 85 | } |
| 86 | |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 87 | static inline void icc_put(struct icc_path *path) |
| 88 | { |
| 89 | } |
| 90 | |
Georgi Djakov | 7d374b2 | 2020-05-10 18:30:37 +0300 | [diff] [blame] | 91 | static inline int icc_enable(struct icc_path *path) |
| 92 | { |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | static inline int icc_disable(struct icc_path *path) |
| 97 | { |
| 98 | return 0; |
| 99 | } |
| 100 | |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 101 | static inline int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw) |
| 102 | { |
| 103 | return 0; |
| 104 | } |
| 105 | |
Georgi Djakov | 127ab2c | 2019-08-09 15:13:23 +0300 | [diff] [blame] | 106 | static inline void icc_set_tag(struct icc_path *path, u32 tag) |
| 107 | { |
| 108 | } |
| 109 | |
Viresh Kumar | 0430b1d | 2020-05-18 14:25:32 +0300 | [diff] [blame] | 110 | static inline const char *icc_get_name(struct icc_path *path) |
| 111 | { |
| 112 | return NULL; |
| 113 | } |
| 114 | |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 115 | #endif /* CONFIG_INTERCONNECT */ |
| 116 | |
| 117 | #endif /* __LINUX_INTERCONNECT_H */ |