18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2019 Samsung Electronics Co., Ltd. 48c2ecf20Sopenharmony_ci * http://www.samsung.com/ 58c2ecf20Sopenharmony_ci * Author: Sylwester Nawrocki <s.nawrocki@samsung.com> 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Samsung Exynos SoC Adaptive Supply Voltage support 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci#ifndef __LINUX_SOC_EXYNOS_ASV_H 108c2ecf20Sopenharmony_ci#define __LINUX_SOC_EXYNOS_ASV_H 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_cistruct regmap; 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci/* HPM, IDS values to select target group */ 158c2ecf20Sopenharmony_cistruct asv_limit_entry { 168c2ecf20Sopenharmony_ci unsigned int hpm; 178c2ecf20Sopenharmony_ci unsigned int ids; 188c2ecf20Sopenharmony_ci}; 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistruct exynos_asv_table { 218c2ecf20Sopenharmony_ci unsigned int num_rows; 228c2ecf20Sopenharmony_ci unsigned int num_cols; 238c2ecf20Sopenharmony_ci u32 *buf; 248c2ecf20Sopenharmony_ci}; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistruct exynos_asv_subsys { 278c2ecf20Sopenharmony_ci struct exynos_asv *asv; 288c2ecf20Sopenharmony_ci const char *cpu_dt_compat; 298c2ecf20Sopenharmony_ci int id; 308c2ecf20Sopenharmony_ci struct exynos_asv_table table; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci unsigned int base_volt; 338c2ecf20Sopenharmony_ci unsigned int offset_volt_h; 348c2ecf20Sopenharmony_ci unsigned int offset_volt_l; 358c2ecf20Sopenharmony_ci}; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistruct exynos_asv { 388c2ecf20Sopenharmony_ci struct device *dev; 398c2ecf20Sopenharmony_ci struct regmap *chipid_regmap; 408c2ecf20Sopenharmony_ci struct exynos_asv_subsys subsys[2]; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci int (*opp_get_voltage)(const struct exynos_asv_subsys *subs, 438c2ecf20Sopenharmony_ci int level, unsigned int voltage); 448c2ecf20Sopenharmony_ci unsigned int group; 458c2ecf20Sopenharmony_ci unsigned int table; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci /* True if SG fields from PKG_ID register should be used */ 488c2ecf20Sopenharmony_ci bool use_sg; 498c2ecf20Sopenharmony_ci /* ASV bin read from DT */ 508c2ecf20Sopenharmony_ci int of_bin; 518c2ecf20Sopenharmony_ci}; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_cistatic inline u32 __asv_get_table_entry(const struct exynos_asv_table *table, 548c2ecf20Sopenharmony_ci unsigned int row, unsigned int col) 558c2ecf20Sopenharmony_ci{ 568c2ecf20Sopenharmony_ci return table->buf[row * (table->num_cols) + col]; 578c2ecf20Sopenharmony_ci} 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cistatic inline u32 exynos_asv_opp_get_voltage(const struct exynos_asv_subsys *subsys, 608c2ecf20Sopenharmony_ci unsigned int level, unsigned int group) 618c2ecf20Sopenharmony_ci{ 628c2ecf20Sopenharmony_ci return __asv_get_table_entry(&subsys->table, level, group + 1); 638c2ecf20Sopenharmony_ci} 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistatic inline u32 exynos_asv_opp_get_frequency(const struct exynos_asv_subsys *subsys, 668c2ecf20Sopenharmony_ci unsigned int level) 678c2ecf20Sopenharmony_ci{ 688c2ecf20Sopenharmony_ci return __asv_get_table_entry(&subsys->table, level, 0); 698c2ecf20Sopenharmony_ci} 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#endif /* __LINUX_SOC_EXYNOS_ASV_H */ 72