1184610Salfred/* SPDX-License-Identifier: GPL-2.0 */
2184610Salfred/*
3184610Salfred * Copyright (c) 2018-2019, Linaro Ltd.
4184610Salfred * Author: Georgi Djakov <georgi.djakov@linaro.org>
5184610Salfred */
6184610Salfred
7184610Salfred#ifndef __LINUX_INTERCONNECT_H
8184610Salfred#define __LINUX_INTERCONNECT_H
9184610Salfred
10184610Salfred#include <linux/mutex.h>
11184610Salfred#include <linux/types.h>
12184610Salfred
13184610Salfred/* macros for converting to icc units */
14184610Salfred#define Bps_to_icc(x)	((x) / 1000)
15184610Salfred#define kBps_to_icc(x)	(x)
16184610Salfred#define MBps_to_icc(x)	((x) * 1000)
17184610Salfred#define GBps_to_icc(x)	((x) * 1000 * 1000)
18184610Salfred#define bps_to_icc(x)	(1)
19184610Salfred#define kbps_to_icc(x)	((x) / 8 + ((x) % 8 ? 1 : 0))
20184610Salfred#define Mbps_to_icc(x)	((x) * 1000 / 8)
21184610Salfred#define Gbps_to_icc(x)	((x) * 1000 * 1000 / 8)
22184610Salfred
23184610Salfredstruct icc_path;
24184610Salfredstruct device;
25184610Salfred
26184610Salfred/**
27184610Salfred * struct icc_bulk_data - Data used for bulk icc operations.
28184610Salfred *
29184610Salfred * @path: reference to the interconnect path (internal use)
30184610Salfred * @name: the name from the "interconnect-names" DT property
31184610Salfred * @avg_bw: average bandwidth in icc units
32184610Salfred * @peak_bw: peak bandwidth in icc units
33184610Salfred */
34184610Salfredstruct icc_bulk_data {
35184610Salfred	struct icc_path	*path;
36184610Salfred	const char *name;
37184610Salfred	u32 avg_bw;
38194677Sthompsa	u32 peak_bw;
39194677Sthompsa};
40194677Sthompsa
41194677Sthompsa#if IS_ENABLED(CONFIG_INTERCONNECT)
42194677Sthompsa
43194677Sthompsastruct icc_path *of_icc_get(struct device *dev, const char *name);
44194677Sthompsastruct icc_path *devm_of_icc_get(struct device *dev, const char *name);
45194677Sthompsaint devm_of_icc_bulk_get(struct device *dev, int num_paths, struct icc_bulk_data *paths);
46194677Sthompsastruct icc_path *of_icc_get_by_index(struct device *dev, int idx);
47194677Sthompsavoid icc_put(struct icc_path *path);
48194677Sthompsaint icc_enable(struct icc_path *path);
49194677Sthompsaint icc_disable(struct icc_path *path);
50194677Sthompsaint icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw);
51194677Sthompsavoid icc_set_tag(struct icc_path *path, u32 tag);
52194677Sthompsaconst char *icc_get_name(struct icc_path *path);
53194677Sthompsaint __must_check of_icc_bulk_get(struct device *dev, int num_paths,
54194677Sthompsa				 struct icc_bulk_data *paths);
55194677Sthompsavoid icc_bulk_put(int num_paths, struct icc_bulk_data *paths);
56194677Sthompsaint icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths);
57194677Sthompsaint icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths);
58194677Sthompsavoid icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths);
59198373Sthompsa
60194677Sthompsa#else
61188942Sthompsa
62194677Sthompsastatic inline struct icc_path *of_icc_get(struct device *dev,
63194677Sthompsa					  const char *name)
64188942Sthompsa{
65194677Sthompsa	return NULL;
66184610Salfred}
67184610Salfred
68188942Sthompsastatic inline struct icc_path *devm_of_icc_get(struct device *dev,
69184610Salfred						const char *name)
70188942Sthompsa{
71184610Salfred	return NULL;
72184610Salfred}
73184610Salfred
74184610Salfredstatic inline struct icc_path *of_icc_get_by_index(struct device *dev, int idx)
75184610Salfred{
76184610Salfred	return NULL;
77207077Sthompsa}
78184610Salfred
79184610Salfredstatic inline void icc_put(struct icc_path *path)
80192502Sthompsa{
81192502Sthompsa}
82184610Salfred
83184610Salfredstatic inline int icc_enable(struct icc_path *path)
84184610Salfred{
85184610Salfred	return 0;
86184610Salfred}
87184610Salfred
88184610Salfredstatic inline int icc_disable(struct icc_path *path)
89184610Salfred{
90184610Salfred	return 0;
91184610Salfred}
92190741Sthompsa
93184610Salfredstatic inline int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw)
94187259Sthompsa{
95187259Sthompsa	return 0;
96188981Sthompsa}
97187259Sthompsa
98187259Sthompsastatic inline void icc_set_tag(struct icc_path *path, u32 tag)
99190741Sthompsa{
100184610Salfred}
101184610Salfred
102184610Salfredstatic inline const char *icc_get_name(struct icc_path *path)
103184610Salfred{
104184610Salfred	return NULL;
105184610Salfred}
106184610Salfred
107184610Salfredstatic inline int of_icc_bulk_get(struct device *dev, int num_paths, struct icc_bulk_data *paths)
108184610Salfred{
109184610Salfred	return 0;
110184610Salfred}
111184610Salfred
112184610Salfredstatic inline int devm_of_icc_bulk_get(struct device *dev, int num_paths,
113188981Sthompsa				       struct icc_bulk_data *paths)
114188981Sthompsa{
115184610Salfred	return 0;
116189583Sthompsa}
117189583Sthompsa
118189583Sthompsastatic inline void icc_bulk_put(int num_paths, struct icc_bulk_data *paths)
119189583Sthompsa{
120189583Sthompsa}
121189583Sthompsa
122190741Sthompsastatic inline int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths)
123190741Sthompsa{
124190741Sthompsa	return 0;
125190741Sthompsa}
126192984Sthompsa
127190741Sthompsastatic inline int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths)
128192984Sthompsa{
129190741Sthompsa	return 0;
130190741Sthompsa}
131190741Sthompsa
132190741Sthompsastatic inline void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths)
133190741Sthompsa{
134190741Sthompsa}
135192984Sthompsa
136190741Sthompsa#endif /* CONFIG_INTERCONNECT */
137195959Salfred
138195959Salfred#endif /* __LINUX_INTERCONNECT_H */
139190741Sthompsa