xref: /openbmc/linux/drivers/soc/samsung/exynos-asv.h (revision d4692f6c)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4  *	      http://www.samsung.com/
5  * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
6  *
7  * Samsung Exynos SoC Adaptive Supply Voltage support
8  */
9 #ifndef __LINUX_SOC_EXYNOS_ASV_H
10 #define __LINUX_SOC_EXYNOS_ASV_H
11 
12 struct regmap;
13 
14 /* HPM, IDS values to select target group */
15 struct asv_limit_entry {
16 	unsigned int hpm;
17 	unsigned int ids;
18 };
19 
20 struct exynos_asv_table {
21 	unsigned int num_rows;
22 	unsigned int num_cols;
23 	u32 *buf;
24 };
25 
26 struct exynos_asv_subsys {
27 	struct exynos_asv *asv;
28 	const char *cpu_dt_compat;
29 	int id;
30 	struct exynos_asv_table table;
31 
32 	unsigned int base_volt;
33 	unsigned int offset_volt_h;
34 	unsigned int offset_volt_l;
35 };
36 
37 struct exynos_asv {
38 	struct device *dev;
39 	struct regmap *chipid_regmap;
40 	struct exynos_asv_subsys subsys[2];
41 
42 	int (*opp_get_voltage)(const struct exynos_asv_subsys *subs,
43 			       int level, unsigned int voltage);
44 	unsigned int group;
45 	unsigned int table;
46 
47 	/* True if SG fields from PKG_ID register should be used */
48 	bool use_sg;
49 	/* ASV bin read from DT */
50 	int of_bin;
51 };
52 
53 static inline u32 __asv_get_table_entry(const struct exynos_asv_table *table,
54 					unsigned int row, unsigned int col)
55 {
56 	return table->buf[row * (table->num_cols) + col];
57 }
58 
59 static inline u32 exynos_asv_opp_get_voltage(const struct exynos_asv_subsys *subsys,
60 					unsigned int level, unsigned int group)
61 {
62 	return __asv_get_table_entry(&subsys->table, level, group + 1);
63 }
64 
65 static inline u32 exynos_asv_opp_get_frequency(const struct exynos_asv_subsys *subsys,
66 					unsigned int level)
67 {
68 	return __asv_get_table_entry(&subsys->table, level, 0);
69 }
70 
71 int exynos_asv_init(struct device *dev, struct regmap *regmap);
72 
73 #endif /* __LINUX_SOC_EXYNOS_ASV_H */
74