18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2015, 2018, The Linux Foundation. All rights reserved. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include <linux/kernel.h> 78c2ecf20Sopenharmony_ci#include <linux/export.h> 88c2ecf20Sopenharmony_ci#include <linux/clk-provider.h> 98c2ecf20Sopenharmony_ci#include <linux/regmap.h> 108c2ecf20Sopenharmony_ci#include <linux/delay.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include "clk-alpha-pll.h" 138c2ecf20Sopenharmony_ci#include "common.h" 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define PLL_MODE(p) ((p)->offset + 0x0) 168c2ecf20Sopenharmony_ci# define PLL_OUTCTRL BIT(0) 178c2ecf20Sopenharmony_ci# define PLL_BYPASSNL BIT(1) 188c2ecf20Sopenharmony_ci# define PLL_RESET_N BIT(2) 198c2ecf20Sopenharmony_ci# define PLL_OFFLINE_REQ BIT(7) 208c2ecf20Sopenharmony_ci# define PLL_LOCK_COUNT_SHIFT 8 218c2ecf20Sopenharmony_ci# define PLL_LOCK_COUNT_MASK 0x3f 228c2ecf20Sopenharmony_ci# define PLL_BIAS_COUNT_SHIFT 14 238c2ecf20Sopenharmony_ci# define PLL_BIAS_COUNT_MASK 0x3f 248c2ecf20Sopenharmony_ci# define PLL_VOTE_FSM_ENA BIT(20) 258c2ecf20Sopenharmony_ci# define PLL_FSM_ENA BIT(20) 268c2ecf20Sopenharmony_ci# define PLL_VOTE_FSM_RESET BIT(21) 278c2ecf20Sopenharmony_ci# define PLL_UPDATE BIT(22) 288c2ecf20Sopenharmony_ci# define PLL_UPDATE_BYPASS BIT(23) 298c2ecf20Sopenharmony_ci# define PLL_OFFLINE_ACK BIT(28) 308c2ecf20Sopenharmony_ci# define ALPHA_PLL_ACK_LATCH BIT(29) 318c2ecf20Sopenharmony_ci# define PLL_ACTIVE_FLAG BIT(30) 328c2ecf20Sopenharmony_ci# define PLL_LOCK_DET BIT(31) 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define PLL_L_VAL(p) ((p)->offset + (p)->regs[PLL_OFF_L_VAL]) 358c2ecf20Sopenharmony_ci#define PLL_CAL_L_VAL(p) ((p)->offset + (p)->regs[PLL_OFF_CAL_L_VAL]) 368c2ecf20Sopenharmony_ci#define PLL_ALPHA_VAL(p) ((p)->offset + (p)->regs[PLL_OFF_ALPHA_VAL]) 378c2ecf20Sopenharmony_ci#define PLL_ALPHA_VAL_U(p) ((p)->offset + (p)->regs[PLL_OFF_ALPHA_VAL_U]) 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#define PLL_USER_CTL(p) ((p)->offset + (p)->regs[PLL_OFF_USER_CTL]) 408c2ecf20Sopenharmony_ci# define PLL_POST_DIV_SHIFT 8 418c2ecf20Sopenharmony_ci# define PLL_POST_DIV_MASK(p) GENMASK((p)->width, 0) 428c2ecf20Sopenharmony_ci# define PLL_ALPHA_EN BIT(24) 438c2ecf20Sopenharmony_ci# define PLL_ALPHA_MODE BIT(25) 448c2ecf20Sopenharmony_ci# define PLL_VCO_SHIFT 20 458c2ecf20Sopenharmony_ci# define PLL_VCO_MASK 0x3 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define PLL_USER_CTL_U(p) ((p)->offset + (p)->regs[PLL_OFF_USER_CTL_U]) 488c2ecf20Sopenharmony_ci#define PLL_USER_CTL_U1(p) ((p)->offset + (p)->regs[PLL_OFF_USER_CTL_U1]) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#define PLL_CONFIG_CTL(p) ((p)->offset + (p)->regs[PLL_OFF_CONFIG_CTL]) 518c2ecf20Sopenharmony_ci#define PLL_CONFIG_CTL_U(p) ((p)->offset + (p)->regs[PLL_OFF_CONFIG_CTL_U]) 528c2ecf20Sopenharmony_ci#define PLL_CONFIG_CTL_U1(p) ((p)->offset + (p)->regs[PLL_OFF_CONFIG_CTL_U1]) 538c2ecf20Sopenharmony_ci#define PLL_TEST_CTL(p) ((p)->offset + (p)->regs[PLL_OFF_TEST_CTL]) 548c2ecf20Sopenharmony_ci#define PLL_TEST_CTL_U(p) ((p)->offset + (p)->regs[PLL_OFF_TEST_CTL_U]) 558c2ecf20Sopenharmony_ci#define PLL_TEST_CTL_U1(p) ((p)->offset + (p)->regs[PLL_OFF_TEST_CTL_U1]) 568c2ecf20Sopenharmony_ci#define PLL_STATUS(p) ((p)->offset + (p)->regs[PLL_OFF_STATUS]) 578c2ecf20Sopenharmony_ci#define PLL_OPMODE(p) ((p)->offset + (p)->regs[PLL_OFF_OPMODE]) 588c2ecf20Sopenharmony_ci#define PLL_FRAC(p) ((p)->offset + (p)->regs[PLL_OFF_FRAC]) 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ciconst u8 clk_alpha_pll_regs[][PLL_OFF_MAX_REGS] = { 618c2ecf20Sopenharmony_ci [CLK_ALPHA_PLL_TYPE_DEFAULT] = { 628c2ecf20Sopenharmony_ci [PLL_OFF_L_VAL] = 0x04, 638c2ecf20Sopenharmony_ci [PLL_OFF_ALPHA_VAL] = 0x08, 648c2ecf20Sopenharmony_ci [PLL_OFF_ALPHA_VAL_U] = 0x0c, 658c2ecf20Sopenharmony_ci [PLL_OFF_USER_CTL] = 0x10, 668c2ecf20Sopenharmony_ci [PLL_OFF_USER_CTL_U] = 0x14, 678c2ecf20Sopenharmony_ci [PLL_OFF_CONFIG_CTL] = 0x18, 688c2ecf20Sopenharmony_ci [PLL_OFF_TEST_CTL] = 0x1c, 698c2ecf20Sopenharmony_ci [PLL_OFF_TEST_CTL_U] = 0x20, 708c2ecf20Sopenharmony_ci [PLL_OFF_STATUS] = 0x24, 718c2ecf20Sopenharmony_ci }, 728c2ecf20Sopenharmony_ci [CLK_ALPHA_PLL_TYPE_HUAYRA] = { 738c2ecf20Sopenharmony_ci [PLL_OFF_L_VAL] = 0x04, 748c2ecf20Sopenharmony_ci [PLL_OFF_ALPHA_VAL] = 0x08, 758c2ecf20Sopenharmony_ci [PLL_OFF_USER_CTL] = 0x10, 768c2ecf20Sopenharmony_ci [PLL_OFF_CONFIG_CTL] = 0x14, 778c2ecf20Sopenharmony_ci [PLL_OFF_CONFIG_CTL_U] = 0x18, 788c2ecf20Sopenharmony_ci [PLL_OFF_TEST_CTL] = 0x1c, 798c2ecf20Sopenharmony_ci [PLL_OFF_TEST_CTL_U] = 0x20, 808c2ecf20Sopenharmony_ci [PLL_OFF_STATUS] = 0x24, 818c2ecf20Sopenharmony_ci }, 828c2ecf20Sopenharmony_ci [CLK_ALPHA_PLL_TYPE_BRAMMO] = { 838c2ecf20Sopenharmony_ci [PLL_OFF_L_VAL] = 0x04, 848c2ecf20Sopenharmony_ci [PLL_OFF_ALPHA_VAL] = 0x08, 858c2ecf20Sopenharmony_ci [PLL_OFF_ALPHA_VAL_U] = 0x0c, 868c2ecf20Sopenharmony_ci [PLL_OFF_USER_CTL] = 0x10, 878c2ecf20Sopenharmony_ci [PLL_OFF_CONFIG_CTL] = 0x18, 888c2ecf20Sopenharmony_ci [PLL_OFF_TEST_CTL] = 0x1c, 898c2ecf20Sopenharmony_ci [PLL_OFF_STATUS] = 0x24, 908c2ecf20Sopenharmony_ci }, 918c2ecf20Sopenharmony_ci [CLK_ALPHA_PLL_TYPE_FABIA] = { 928c2ecf20Sopenharmony_ci [PLL_OFF_L_VAL] = 0x04, 938c2ecf20Sopenharmony_ci [PLL_OFF_USER_CTL] = 0x0c, 948c2ecf20Sopenharmony_ci [PLL_OFF_USER_CTL_U] = 0x10, 958c2ecf20Sopenharmony_ci [PLL_OFF_CONFIG_CTL] = 0x14, 968c2ecf20Sopenharmony_ci [PLL_OFF_CONFIG_CTL_U] = 0x18, 978c2ecf20Sopenharmony_ci [PLL_OFF_TEST_CTL] = 0x1c, 988c2ecf20Sopenharmony_ci [PLL_OFF_TEST_CTL_U] = 0x20, 998c2ecf20Sopenharmony_ci [PLL_OFF_STATUS] = 0x24, 1008c2ecf20Sopenharmony_ci [PLL_OFF_OPMODE] = 0x2c, 1018c2ecf20Sopenharmony_ci [PLL_OFF_FRAC] = 0x38, 1028c2ecf20Sopenharmony_ci }, 1038c2ecf20Sopenharmony_ci [CLK_ALPHA_PLL_TYPE_TRION] = { 1048c2ecf20Sopenharmony_ci [PLL_OFF_L_VAL] = 0x04, 1058c2ecf20Sopenharmony_ci [PLL_OFF_CAL_L_VAL] = 0x08, 1068c2ecf20Sopenharmony_ci [PLL_OFF_USER_CTL] = 0x0c, 1078c2ecf20Sopenharmony_ci [PLL_OFF_USER_CTL_U] = 0x10, 1088c2ecf20Sopenharmony_ci [PLL_OFF_USER_CTL_U1] = 0x14, 1098c2ecf20Sopenharmony_ci [PLL_OFF_CONFIG_CTL] = 0x18, 1108c2ecf20Sopenharmony_ci [PLL_OFF_CONFIG_CTL_U] = 0x1c, 1118c2ecf20Sopenharmony_ci [PLL_OFF_CONFIG_CTL_U1] = 0x20, 1128c2ecf20Sopenharmony_ci [PLL_OFF_TEST_CTL] = 0x24, 1138c2ecf20Sopenharmony_ci [PLL_OFF_TEST_CTL_U] = 0x28, 1148c2ecf20Sopenharmony_ci [PLL_OFF_TEST_CTL_U1] = 0x2c, 1158c2ecf20Sopenharmony_ci [PLL_OFF_STATUS] = 0x30, 1168c2ecf20Sopenharmony_ci [PLL_OFF_OPMODE] = 0x38, 1178c2ecf20Sopenharmony_ci [PLL_OFF_ALPHA_VAL] = 0x40, 1188c2ecf20Sopenharmony_ci }, 1198c2ecf20Sopenharmony_ci}; 1208c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_alpha_pll_regs); 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci/* 1238c2ecf20Sopenharmony_ci * Even though 40 bits are present, use only 32 for ease of calculation. 1248c2ecf20Sopenharmony_ci */ 1258c2ecf20Sopenharmony_ci#define ALPHA_REG_BITWIDTH 40 1268c2ecf20Sopenharmony_ci#define ALPHA_REG_16BIT_WIDTH 16 1278c2ecf20Sopenharmony_ci#define ALPHA_BITWIDTH 32U 1288c2ecf20Sopenharmony_ci#define ALPHA_SHIFT(w) min(w, ALPHA_BITWIDTH) 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci#define PLL_HUAYRA_M_WIDTH 8 1318c2ecf20Sopenharmony_ci#define PLL_HUAYRA_M_SHIFT 8 1328c2ecf20Sopenharmony_ci#define PLL_HUAYRA_M_MASK 0xff 1338c2ecf20Sopenharmony_ci#define PLL_HUAYRA_N_SHIFT 0 1348c2ecf20Sopenharmony_ci#define PLL_HUAYRA_N_MASK 0xff 1358c2ecf20Sopenharmony_ci#define PLL_HUAYRA_ALPHA_WIDTH 16 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci#define PLL_STANDBY 0x0 1388c2ecf20Sopenharmony_ci#define PLL_RUN 0x1 1398c2ecf20Sopenharmony_ci#define PLL_OUT_MASK 0x7 1408c2ecf20Sopenharmony_ci#define PLL_RATE_MARGIN 500 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci/* TRION PLL specific settings and offsets */ 1438c2ecf20Sopenharmony_ci#define TRION_PLL_CAL_VAL 0x44 1448c2ecf20Sopenharmony_ci#define TRION_PCAL_DONE BIT(26) 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci/* LUCID PLL specific settings and offsets */ 1478c2ecf20Sopenharmony_ci#define LUCID_PCAL_DONE BIT(27) 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci#define pll_alpha_width(p) \ 1508c2ecf20Sopenharmony_ci ((PLL_ALPHA_VAL_U(p) - PLL_ALPHA_VAL(p) == 4) ? \ 1518c2ecf20Sopenharmony_ci ALPHA_REG_BITWIDTH : ALPHA_REG_16BIT_WIDTH) 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci#define pll_has_64bit_config(p) ((PLL_CONFIG_CTL_U(p) - PLL_CONFIG_CTL(p)) == 4) 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci#define to_clk_alpha_pll(_hw) container_of(to_clk_regmap(_hw), \ 1568c2ecf20Sopenharmony_ci struct clk_alpha_pll, clkr) 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci#define to_clk_alpha_pll_postdiv(_hw) container_of(to_clk_regmap(_hw), \ 1598c2ecf20Sopenharmony_ci struct clk_alpha_pll_postdiv, clkr) 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_cistatic int wait_for_pll(struct clk_alpha_pll *pll, u32 mask, bool inverse, 1628c2ecf20Sopenharmony_ci const char *action) 1638c2ecf20Sopenharmony_ci{ 1648c2ecf20Sopenharmony_ci u32 val; 1658c2ecf20Sopenharmony_ci int count; 1668c2ecf20Sopenharmony_ci int ret; 1678c2ecf20Sopenharmony_ci const char *name = clk_hw_get_name(&pll->clkr.hw); 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci ret = regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val); 1708c2ecf20Sopenharmony_ci if (ret) 1718c2ecf20Sopenharmony_ci return ret; 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci for (count = 100; count > 0; count--) { 1748c2ecf20Sopenharmony_ci ret = regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val); 1758c2ecf20Sopenharmony_ci if (ret) 1768c2ecf20Sopenharmony_ci return ret; 1778c2ecf20Sopenharmony_ci if (inverse && !(val & mask)) 1788c2ecf20Sopenharmony_ci return 0; 1798c2ecf20Sopenharmony_ci else if ((val & mask) == mask) 1808c2ecf20Sopenharmony_ci return 0; 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci udelay(1); 1838c2ecf20Sopenharmony_ci } 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci WARN(1, "%s failed to %s!\n", name, action); 1868c2ecf20Sopenharmony_ci return -ETIMEDOUT; 1878c2ecf20Sopenharmony_ci} 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci#define wait_for_pll_enable_active(pll) \ 1908c2ecf20Sopenharmony_ci wait_for_pll(pll, PLL_ACTIVE_FLAG, 0, "enable") 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci#define wait_for_pll_enable_lock(pll) \ 1938c2ecf20Sopenharmony_ci wait_for_pll(pll, PLL_LOCK_DET, 0, "enable") 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci#define wait_for_pll_disable(pll) \ 1968c2ecf20Sopenharmony_ci wait_for_pll(pll, PLL_ACTIVE_FLAG, 1, "disable") 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci#define wait_for_pll_offline(pll) \ 1998c2ecf20Sopenharmony_ci wait_for_pll(pll, PLL_OFFLINE_ACK, 0, "offline") 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci#define wait_for_pll_update(pll) \ 2028c2ecf20Sopenharmony_ci wait_for_pll(pll, PLL_UPDATE, 1, "update") 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci#define wait_for_pll_update_ack_set(pll) \ 2058c2ecf20Sopenharmony_ci wait_for_pll(pll, ALPHA_PLL_ACK_LATCH, 0, "update_ack_set") 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci#define wait_for_pll_update_ack_clear(pll) \ 2088c2ecf20Sopenharmony_ci wait_for_pll(pll, ALPHA_PLL_ACK_LATCH, 1, "update_ack_clear") 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_civoid clk_alpha_pll_configure(struct clk_alpha_pll *pll, struct regmap *regmap, 2118c2ecf20Sopenharmony_ci const struct alpha_pll_config *config) 2128c2ecf20Sopenharmony_ci{ 2138c2ecf20Sopenharmony_ci u32 val, mask; 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_L_VAL(pll), config->l); 2168c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_ALPHA_VAL(pll), config->alpha); 2178c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_CONFIG_CTL(pll), config->config_ctl_val); 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci if (pll_has_64bit_config(pll)) 2208c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_CONFIG_CTL_U(pll), 2218c2ecf20Sopenharmony_ci config->config_ctl_hi_val); 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci if (pll_alpha_width(pll) > 32) 2248c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_ALPHA_VAL_U(pll), config->alpha_hi); 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci val = config->main_output_mask; 2278c2ecf20Sopenharmony_ci val |= config->aux_output_mask; 2288c2ecf20Sopenharmony_ci val |= config->aux2_output_mask; 2298c2ecf20Sopenharmony_ci val |= config->early_output_mask; 2308c2ecf20Sopenharmony_ci val |= config->pre_div_val; 2318c2ecf20Sopenharmony_ci val |= config->post_div_val; 2328c2ecf20Sopenharmony_ci val |= config->vco_val; 2338c2ecf20Sopenharmony_ci val |= config->alpha_en_mask; 2348c2ecf20Sopenharmony_ci val |= config->alpha_mode_mask; 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci mask = config->main_output_mask; 2378c2ecf20Sopenharmony_ci mask |= config->aux_output_mask; 2388c2ecf20Sopenharmony_ci mask |= config->aux2_output_mask; 2398c2ecf20Sopenharmony_ci mask |= config->early_output_mask; 2408c2ecf20Sopenharmony_ci mask |= config->pre_div_mask; 2418c2ecf20Sopenharmony_ci mask |= config->post_div_mask; 2428c2ecf20Sopenharmony_ci mask |= config->vco_mask; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci regmap_update_bits(regmap, PLL_USER_CTL(pll), mask, val); 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ci if (pll->flags & SUPPORTS_FSM_MODE) 2478c2ecf20Sopenharmony_ci qcom_pll_set_fsm_mode(regmap, PLL_MODE(pll), 6, 0); 2488c2ecf20Sopenharmony_ci} 2498c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_alpha_pll_configure); 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_cistatic int clk_alpha_pll_hwfsm_enable(struct clk_hw *hw) 2528c2ecf20Sopenharmony_ci{ 2538c2ecf20Sopenharmony_ci int ret; 2548c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 2558c2ecf20Sopenharmony_ci u32 val; 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci ret = regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val); 2588c2ecf20Sopenharmony_ci if (ret) 2598c2ecf20Sopenharmony_ci return ret; 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci val |= PLL_FSM_ENA; 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci if (pll->flags & SUPPORTS_OFFLINE_REQ) 2648c2ecf20Sopenharmony_ci val &= ~PLL_OFFLINE_REQ; 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci ret = regmap_write(pll->clkr.regmap, PLL_MODE(pll), val); 2678c2ecf20Sopenharmony_ci if (ret) 2688c2ecf20Sopenharmony_ci return ret; 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci /* Make sure enable request goes through before waiting for update */ 2718c2ecf20Sopenharmony_ci mb(); 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci return wait_for_pll_enable_active(pll); 2748c2ecf20Sopenharmony_ci} 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_cistatic void clk_alpha_pll_hwfsm_disable(struct clk_hw *hw) 2778c2ecf20Sopenharmony_ci{ 2788c2ecf20Sopenharmony_ci int ret; 2798c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 2808c2ecf20Sopenharmony_ci u32 val; 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci ret = regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val); 2838c2ecf20Sopenharmony_ci if (ret) 2848c2ecf20Sopenharmony_ci return; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci if (pll->flags & SUPPORTS_OFFLINE_REQ) { 2878c2ecf20Sopenharmony_ci ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), 2888c2ecf20Sopenharmony_ci PLL_OFFLINE_REQ, PLL_OFFLINE_REQ); 2898c2ecf20Sopenharmony_ci if (ret) 2908c2ecf20Sopenharmony_ci return; 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci ret = wait_for_pll_offline(pll); 2938c2ecf20Sopenharmony_ci if (ret) 2948c2ecf20Sopenharmony_ci return; 2958c2ecf20Sopenharmony_ci } 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ci /* Disable hwfsm */ 2988c2ecf20Sopenharmony_ci ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), 2998c2ecf20Sopenharmony_ci PLL_FSM_ENA, 0); 3008c2ecf20Sopenharmony_ci if (ret) 3018c2ecf20Sopenharmony_ci return; 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci wait_for_pll_disable(pll); 3048c2ecf20Sopenharmony_ci} 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_cistatic int pll_is_enabled(struct clk_hw *hw, u32 mask) 3078c2ecf20Sopenharmony_ci{ 3088c2ecf20Sopenharmony_ci int ret; 3098c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 3108c2ecf20Sopenharmony_ci u32 val; 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci ret = regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val); 3138c2ecf20Sopenharmony_ci if (ret) 3148c2ecf20Sopenharmony_ci return ret; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci return !!(val & mask); 3178c2ecf20Sopenharmony_ci} 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_cistatic int clk_alpha_pll_hwfsm_is_enabled(struct clk_hw *hw) 3208c2ecf20Sopenharmony_ci{ 3218c2ecf20Sopenharmony_ci return pll_is_enabled(hw, PLL_ACTIVE_FLAG); 3228c2ecf20Sopenharmony_ci} 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_cistatic int clk_alpha_pll_is_enabled(struct clk_hw *hw) 3258c2ecf20Sopenharmony_ci{ 3268c2ecf20Sopenharmony_ci return pll_is_enabled(hw, PLL_LOCK_DET); 3278c2ecf20Sopenharmony_ci} 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_cistatic int clk_alpha_pll_enable(struct clk_hw *hw) 3308c2ecf20Sopenharmony_ci{ 3318c2ecf20Sopenharmony_ci int ret; 3328c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 3338c2ecf20Sopenharmony_ci u32 val, mask; 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci mask = PLL_OUTCTRL | PLL_RESET_N | PLL_BYPASSNL; 3368c2ecf20Sopenharmony_ci ret = regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val); 3378c2ecf20Sopenharmony_ci if (ret) 3388c2ecf20Sopenharmony_ci return ret; 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci /* If in FSM mode, just vote for it */ 3418c2ecf20Sopenharmony_ci if (val & PLL_VOTE_FSM_ENA) { 3428c2ecf20Sopenharmony_ci ret = clk_enable_regmap(hw); 3438c2ecf20Sopenharmony_ci if (ret) 3448c2ecf20Sopenharmony_ci return ret; 3458c2ecf20Sopenharmony_ci return wait_for_pll_enable_active(pll); 3468c2ecf20Sopenharmony_ci } 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci /* Skip if already enabled */ 3498c2ecf20Sopenharmony_ci if ((val & mask) == mask) 3508c2ecf20Sopenharmony_ci return 0; 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ci ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), 3538c2ecf20Sopenharmony_ci PLL_BYPASSNL, PLL_BYPASSNL); 3548c2ecf20Sopenharmony_ci if (ret) 3558c2ecf20Sopenharmony_ci return ret; 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci /* 3588c2ecf20Sopenharmony_ci * H/W requires a 5us delay between disabling the bypass and 3598c2ecf20Sopenharmony_ci * de-asserting the reset. 3608c2ecf20Sopenharmony_ci */ 3618c2ecf20Sopenharmony_ci mb(); 3628c2ecf20Sopenharmony_ci udelay(5); 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), 3658c2ecf20Sopenharmony_ci PLL_RESET_N, PLL_RESET_N); 3668c2ecf20Sopenharmony_ci if (ret) 3678c2ecf20Sopenharmony_ci return ret; 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci ret = wait_for_pll_enable_lock(pll); 3708c2ecf20Sopenharmony_ci if (ret) 3718c2ecf20Sopenharmony_ci return ret; 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), 3748c2ecf20Sopenharmony_ci PLL_OUTCTRL, PLL_OUTCTRL); 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci /* Ensure that the write above goes through before returning. */ 3778c2ecf20Sopenharmony_ci mb(); 3788c2ecf20Sopenharmony_ci return ret; 3798c2ecf20Sopenharmony_ci} 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_cistatic void clk_alpha_pll_disable(struct clk_hw *hw) 3828c2ecf20Sopenharmony_ci{ 3838c2ecf20Sopenharmony_ci int ret; 3848c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 3858c2ecf20Sopenharmony_ci u32 val, mask; 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci ret = regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val); 3888c2ecf20Sopenharmony_ci if (ret) 3898c2ecf20Sopenharmony_ci return; 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci /* If in FSM mode, just unvote it */ 3928c2ecf20Sopenharmony_ci if (val & PLL_VOTE_FSM_ENA) { 3938c2ecf20Sopenharmony_ci clk_disable_regmap(hw); 3948c2ecf20Sopenharmony_ci return; 3958c2ecf20Sopenharmony_ci } 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci mask = PLL_OUTCTRL; 3988c2ecf20Sopenharmony_ci regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), mask, 0); 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ci /* Delay of 2 output clock ticks required until output is disabled */ 4018c2ecf20Sopenharmony_ci mb(); 4028c2ecf20Sopenharmony_ci udelay(1); 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_ci mask = PLL_RESET_N | PLL_BYPASSNL; 4058c2ecf20Sopenharmony_ci regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), mask, 0); 4068c2ecf20Sopenharmony_ci} 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_cistatic unsigned long 4098c2ecf20Sopenharmony_cialpha_pll_calc_rate(u64 prate, u32 l, u32 a, u32 alpha_width) 4108c2ecf20Sopenharmony_ci{ 4118c2ecf20Sopenharmony_ci return (prate * l) + ((prate * a) >> ALPHA_SHIFT(alpha_width)); 4128c2ecf20Sopenharmony_ci} 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_cistatic unsigned long 4158c2ecf20Sopenharmony_cialpha_pll_round_rate(unsigned long rate, unsigned long prate, u32 *l, u64 *a, 4168c2ecf20Sopenharmony_ci u32 alpha_width) 4178c2ecf20Sopenharmony_ci{ 4188c2ecf20Sopenharmony_ci u64 remainder; 4198c2ecf20Sopenharmony_ci u64 quotient; 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci quotient = rate; 4228c2ecf20Sopenharmony_ci remainder = do_div(quotient, prate); 4238c2ecf20Sopenharmony_ci *l = quotient; 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci if (!remainder) { 4268c2ecf20Sopenharmony_ci *a = 0; 4278c2ecf20Sopenharmony_ci return rate; 4288c2ecf20Sopenharmony_ci } 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci /* Upper ALPHA_BITWIDTH bits of Alpha */ 4318c2ecf20Sopenharmony_ci quotient = remainder << ALPHA_SHIFT(alpha_width); 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_ci remainder = do_div(quotient, prate); 4348c2ecf20Sopenharmony_ci 4358c2ecf20Sopenharmony_ci if (remainder) 4368c2ecf20Sopenharmony_ci quotient++; 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci *a = quotient; 4398c2ecf20Sopenharmony_ci return alpha_pll_calc_rate(prate, *l, *a, alpha_width); 4408c2ecf20Sopenharmony_ci} 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_cistatic const struct pll_vco * 4438c2ecf20Sopenharmony_cialpha_pll_find_vco(const struct clk_alpha_pll *pll, unsigned long rate) 4448c2ecf20Sopenharmony_ci{ 4458c2ecf20Sopenharmony_ci const struct pll_vco *v = pll->vco_table; 4468c2ecf20Sopenharmony_ci const struct pll_vco *end = v + pll->num_vco; 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci for (; v < end; v++) 4498c2ecf20Sopenharmony_ci if (rate >= v->min_freq && rate <= v->max_freq) 4508c2ecf20Sopenharmony_ci return v; 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_ci return NULL; 4538c2ecf20Sopenharmony_ci} 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_cistatic unsigned long 4568c2ecf20Sopenharmony_ciclk_alpha_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) 4578c2ecf20Sopenharmony_ci{ 4588c2ecf20Sopenharmony_ci u32 l, low, high, ctl; 4598c2ecf20Sopenharmony_ci u64 a = 0, prate = parent_rate; 4608c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 4618c2ecf20Sopenharmony_ci u32 alpha_width = pll_alpha_width(pll); 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_L_VAL(pll), &l); 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_USER_CTL(pll), &ctl); 4668c2ecf20Sopenharmony_ci if (ctl & PLL_ALPHA_EN) { 4678c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_ALPHA_VAL(pll), &low); 4688c2ecf20Sopenharmony_ci if (alpha_width > 32) { 4698c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_ALPHA_VAL_U(pll), 4708c2ecf20Sopenharmony_ci &high); 4718c2ecf20Sopenharmony_ci a = (u64)high << 32 | low; 4728c2ecf20Sopenharmony_ci } else { 4738c2ecf20Sopenharmony_ci a = low & GENMASK(alpha_width - 1, 0); 4748c2ecf20Sopenharmony_ci } 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci if (alpha_width > ALPHA_BITWIDTH) 4778c2ecf20Sopenharmony_ci a >>= alpha_width - ALPHA_BITWIDTH; 4788c2ecf20Sopenharmony_ci } 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci return alpha_pll_calc_rate(prate, l, a, alpha_width); 4818c2ecf20Sopenharmony_ci} 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_cistatic int __clk_alpha_pll_update_latch(struct clk_alpha_pll *pll) 4858c2ecf20Sopenharmony_ci{ 4868c2ecf20Sopenharmony_ci int ret; 4878c2ecf20Sopenharmony_ci u32 mode; 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_MODE(pll), &mode); 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci /* Latch the input to the PLL */ 4928c2ecf20Sopenharmony_ci regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), PLL_UPDATE, 4938c2ecf20Sopenharmony_ci PLL_UPDATE); 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci /* Wait for 2 reference cycle before checking ACK bit */ 4968c2ecf20Sopenharmony_ci udelay(1); 4978c2ecf20Sopenharmony_ci 4988c2ecf20Sopenharmony_ci /* 4998c2ecf20Sopenharmony_ci * PLL will latch the new L, Alpha and freq control word. 5008c2ecf20Sopenharmony_ci * PLL will respond by raising PLL_ACK_LATCH output when new programming 5018c2ecf20Sopenharmony_ci * has been latched in and PLL is being updated. When 5028c2ecf20Sopenharmony_ci * UPDATE_LOGIC_BYPASS bit is not set, PLL_UPDATE will be cleared 5038c2ecf20Sopenharmony_ci * automatically by hardware when PLL_ACK_LATCH is asserted by PLL. 5048c2ecf20Sopenharmony_ci */ 5058c2ecf20Sopenharmony_ci if (mode & PLL_UPDATE_BYPASS) { 5068c2ecf20Sopenharmony_ci ret = wait_for_pll_update_ack_set(pll); 5078c2ecf20Sopenharmony_ci if (ret) 5088c2ecf20Sopenharmony_ci return ret; 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), PLL_UPDATE, 0); 5118c2ecf20Sopenharmony_ci } else { 5128c2ecf20Sopenharmony_ci ret = wait_for_pll_update(pll); 5138c2ecf20Sopenharmony_ci if (ret) 5148c2ecf20Sopenharmony_ci return ret; 5158c2ecf20Sopenharmony_ci } 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci ret = wait_for_pll_update_ack_clear(pll); 5188c2ecf20Sopenharmony_ci if (ret) 5198c2ecf20Sopenharmony_ci return ret; 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci /* Wait for PLL output to stabilize */ 5228c2ecf20Sopenharmony_ci udelay(10); 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ci return 0; 5258c2ecf20Sopenharmony_ci} 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_cistatic int clk_alpha_pll_update_latch(struct clk_alpha_pll *pll, 5288c2ecf20Sopenharmony_ci int (*is_enabled)(struct clk_hw *)) 5298c2ecf20Sopenharmony_ci{ 5308c2ecf20Sopenharmony_ci if (!is_enabled(&pll->clkr.hw) || 5318c2ecf20Sopenharmony_ci !(pll->flags & SUPPORTS_DYNAMIC_UPDATE)) 5328c2ecf20Sopenharmony_ci return 0; 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_ci return __clk_alpha_pll_update_latch(pll); 5358c2ecf20Sopenharmony_ci} 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_cistatic int __clk_alpha_pll_set_rate(struct clk_hw *hw, unsigned long rate, 5388c2ecf20Sopenharmony_ci unsigned long prate, 5398c2ecf20Sopenharmony_ci int (*is_enabled)(struct clk_hw *)) 5408c2ecf20Sopenharmony_ci{ 5418c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 5428c2ecf20Sopenharmony_ci const struct pll_vco *vco; 5438c2ecf20Sopenharmony_ci u32 l, alpha_width = pll_alpha_width(pll); 5448c2ecf20Sopenharmony_ci u64 a; 5458c2ecf20Sopenharmony_ci 5468c2ecf20Sopenharmony_ci rate = alpha_pll_round_rate(rate, prate, &l, &a, alpha_width); 5478c2ecf20Sopenharmony_ci vco = alpha_pll_find_vco(pll, rate); 5488c2ecf20Sopenharmony_ci if (pll->vco_table && !vco) { 5498c2ecf20Sopenharmony_ci pr_err("%s: alpha pll not in a valid vco range\n", 5508c2ecf20Sopenharmony_ci clk_hw_get_name(hw)); 5518c2ecf20Sopenharmony_ci return -EINVAL; 5528c2ecf20Sopenharmony_ci } 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci regmap_write(pll->clkr.regmap, PLL_L_VAL(pll), l); 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci if (alpha_width > ALPHA_BITWIDTH) 5578c2ecf20Sopenharmony_ci a <<= alpha_width - ALPHA_BITWIDTH; 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci if (alpha_width > 32) 5608c2ecf20Sopenharmony_ci regmap_write(pll->clkr.regmap, PLL_ALPHA_VAL_U(pll), a >> 32); 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci regmap_write(pll->clkr.regmap, PLL_ALPHA_VAL(pll), a); 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci if (vco) { 5658c2ecf20Sopenharmony_ci regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll), 5668c2ecf20Sopenharmony_ci PLL_VCO_MASK << PLL_VCO_SHIFT, 5678c2ecf20Sopenharmony_ci vco->val << PLL_VCO_SHIFT); 5688c2ecf20Sopenharmony_ci } 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_ci regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll), 5718c2ecf20Sopenharmony_ci PLL_ALPHA_EN, PLL_ALPHA_EN); 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ci return clk_alpha_pll_update_latch(pll, is_enabled); 5748c2ecf20Sopenharmony_ci} 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_cistatic int clk_alpha_pll_set_rate(struct clk_hw *hw, unsigned long rate, 5778c2ecf20Sopenharmony_ci unsigned long prate) 5788c2ecf20Sopenharmony_ci{ 5798c2ecf20Sopenharmony_ci return __clk_alpha_pll_set_rate(hw, rate, prate, 5808c2ecf20Sopenharmony_ci clk_alpha_pll_is_enabled); 5818c2ecf20Sopenharmony_ci} 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_cistatic int clk_alpha_pll_hwfsm_set_rate(struct clk_hw *hw, unsigned long rate, 5848c2ecf20Sopenharmony_ci unsigned long prate) 5858c2ecf20Sopenharmony_ci{ 5868c2ecf20Sopenharmony_ci return __clk_alpha_pll_set_rate(hw, rate, prate, 5878c2ecf20Sopenharmony_ci clk_alpha_pll_hwfsm_is_enabled); 5888c2ecf20Sopenharmony_ci} 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_cistatic long clk_alpha_pll_round_rate(struct clk_hw *hw, unsigned long rate, 5918c2ecf20Sopenharmony_ci unsigned long *prate) 5928c2ecf20Sopenharmony_ci{ 5938c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 5948c2ecf20Sopenharmony_ci u32 l, alpha_width = pll_alpha_width(pll); 5958c2ecf20Sopenharmony_ci u64 a; 5968c2ecf20Sopenharmony_ci unsigned long min_freq, max_freq; 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_ci rate = alpha_pll_round_rate(rate, *prate, &l, &a, alpha_width); 5998c2ecf20Sopenharmony_ci if (!pll->vco_table || alpha_pll_find_vco(pll, rate)) 6008c2ecf20Sopenharmony_ci return rate; 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci min_freq = pll->vco_table[0].min_freq; 6038c2ecf20Sopenharmony_ci max_freq = pll->vco_table[pll->num_vco - 1].max_freq; 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci return clamp(rate, min_freq, max_freq); 6068c2ecf20Sopenharmony_ci} 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_cistatic unsigned long 6098c2ecf20Sopenharmony_cialpha_huayra_pll_calc_rate(u64 prate, u32 l, u32 a) 6108c2ecf20Sopenharmony_ci{ 6118c2ecf20Sopenharmony_ci /* 6128c2ecf20Sopenharmony_ci * a contains 16 bit alpha_val in two’s complement number in the range 6138c2ecf20Sopenharmony_ci * of [-0.5, 0.5). 6148c2ecf20Sopenharmony_ci */ 6158c2ecf20Sopenharmony_ci if (a >= BIT(PLL_HUAYRA_ALPHA_WIDTH - 1)) 6168c2ecf20Sopenharmony_ci l -= 1; 6178c2ecf20Sopenharmony_ci 6188c2ecf20Sopenharmony_ci return (prate * l) + (prate * a >> PLL_HUAYRA_ALPHA_WIDTH); 6198c2ecf20Sopenharmony_ci} 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_cistatic unsigned long 6228c2ecf20Sopenharmony_cialpha_huayra_pll_round_rate(unsigned long rate, unsigned long prate, 6238c2ecf20Sopenharmony_ci u32 *l, u32 *a) 6248c2ecf20Sopenharmony_ci{ 6258c2ecf20Sopenharmony_ci u64 remainder; 6268c2ecf20Sopenharmony_ci u64 quotient; 6278c2ecf20Sopenharmony_ci 6288c2ecf20Sopenharmony_ci quotient = rate; 6298c2ecf20Sopenharmony_ci remainder = do_div(quotient, prate); 6308c2ecf20Sopenharmony_ci *l = quotient; 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci if (!remainder) { 6338c2ecf20Sopenharmony_ci *a = 0; 6348c2ecf20Sopenharmony_ci return rate; 6358c2ecf20Sopenharmony_ci } 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci quotient = remainder << PLL_HUAYRA_ALPHA_WIDTH; 6388c2ecf20Sopenharmony_ci remainder = do_div(quotient, prate); 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci if (remainder) 6418c2ecf20Sopenharmony_ci quotient++; 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci /* 6448c2ecf20Sopenharmony_ci * alpha_val should be in two’s complement number in the range 6458c2ecf20Sopenharmony_ci * of [-0.5, 0.5) so if quotient >= 0.5 then increment the l value 6468c2ecf20Sopenharmony_ci * since alpha value will be subtracted in this case. 6478c2ecf20Sopenharmony_ci */ 6488c2ecf20Sopenharmony_ci if (quotient >= BIT(PLL_HUAYRA_ALPHA_WIDTH - 1)) 6498c2ecf20Sopenharmony_ci *l += 1; 6508c2ecf20Sopenharmony_ci 6518c2ecf20Sopenharmony_ci *a = quotient; 6528c2ecf20Sopenharmony_ci return alpha_huayra_pll_calc_rate(prate, *l, *a); 6538c2ecf20Sopenharmony_ci} 6548c2ecf20Sopenharmony_ci 6558c2ecf20Sopenharmony_cistatic unsigned long 6568c2ecf20Sopenharmony_cialpha_pll_huayra_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) 6578c2ecf20Sopenharmony_ci{ 6588c2ecf20Sopenharmony_ci u64 rate = parent_rate, tmp; 6598c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 6608c2ecf20Sopenharmony_ci u32 l, alpha = 0, ctl, alpha_m, alpha_n; 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_L_VAL(pll), &l); 6638c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_USER_CTL(pll), &ctl); 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci if (ctl & PLL_ALPHA_EN) { 6668c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_ALPHA_VAL(pll), &alpha); 6678c2ecf20Sopenharmony_ci /* 6688c2ecf20Sopenharmony_ci * Depending upon alpha_mode, it can be treated as M/N value or 6698c2ecf20Sopenharmony_ci * as a two’s complement number. When alpha_mode=1, 6708c2ecf20Sopenharmony_ci * pll_alpha_val<15:8>=M and pll_apla_val<7:0>=N 6718c2ecf20Sopenharmony_ci * 6728c2ecf20Sopenharmony_ci * Fout=FIN*(L+(M/N)) 6738c2ecf20Sopenharmony_ci * 6748c2ecf20Sopenharmony_ci * M is a signed number (-128 to 127) and N is unsigned 6758c2ecf20Sopenharmony_ci * (0 to 255). M/N has to be within +/-0.5. 6768c2ecf20Sopenharmony_ci * 6778c2ecf20Sopenharmony_ci * When alpha_mode=0, it is a two’s complement number in the 6788c2ecf20Sopenharmony_ci * range [-0.5, 0.5). 6798c2ecf20Sopenharmony_ci * 6808c2ecf20Sopenharmony_ci * Fout=FIN*(L+(alpha_val)/2^16) 6818c2ecf20Sopenharmony_ci * 6828c2ecf20Sopenharmony_ci * where alpha_val is two’s complement number. 6838c2ecf20Sopenharmony_ci */ 6848c2ecf20Sopenharmony_ci if (!(ctl & PLL_ALPHA_MODE)) 6858c2ecf20Sopenharmony_ci return alpha_huayra_pll_calc_rate(rate, l, alpha); 6868c2ecf20Sopenharmony_ci 6878c2ecf20Sopenharmony_ci alpha_m = alpha >> PLL_HUAYRA_M_SHIFT & PLL_HUAYRA_M_MASK; 6888c2ecf20Sopenharmony_ci alpha_n = alpha >> PLL_HUAYRA_N_SHIFT & PLL_HUAYRA_N_MASK; 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_ci rate *= l; 6918c2ecf20Sopenharmony_ci tmp = parent_rate; 6928c2ecf20Sopenharmony_ci if (alpha_m >= BIT(PLL_HUAYRA_M_WIDTH - 1)) { 6938c2ecf20Sopenharmony_ci alpha_m = BIT(PLL_HUAYRA_M_WIDTH) - alpha_m; 6948c2ecf20Sopenharmony_ci tmp *= alpha_m; 6958c2ecf20Sopenharmony_ci do_div(tmp, alpha_n); 6968c2ecf20Sopenharmony_ci rate -= tmp; 6978c2ecf20Sopenharmony_ci } else { 6988c2ecf20Sopenharmony_ci tmp *= alpha_m; 6998c2ecf20Sopenharmony_ci do_div(tmp, alpha_n); 7008c2ecf20Sopenharmony_ci rate += tmp; 7018c2ecf20Sopenharmony_ci } 7028c2ecf20Sopenharmony_ci 7038c2ecf20Sopenharmony_ci return rate; 7048c2ecf20Sopenharmony_ci } 7058c2ecf20Sopenharmony_ci 7068c2ecf20Sopenharmony_ci return alpha_huayra_pll_calc_rate(rate, l, alpha); 7078c2ecf20Sopenharmony_ci} 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_cistatic int alpha_pll_huayra_set_rate(struct clk_hw *hw, unsigned long rate, 7108c2ecf20Sopenharmony_ci unsigned long prate) 7118c2ecf20Sopenharmony_ci{ 7128c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 7138c2ecf20Sopenharmony_ci u32 l, a, ctl, cur_alpha = 0; 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_ci rate = alpha_huayra_pll_round_rate(rate, prate, &l, &a); 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_USER_CTL(pll), &ctl); 7188c2ecf20Sopenharmony_ci 7198c2ecf20Sopenharmony_ci if (ctl & PLL_ALPHA_EN) 7208c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_ALPHA_VAL(pll), &cur_alpha); 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_ci /* 7238c2ecf20Sopenharmony_ci * Huayra PLL supports PLL dynamic programming. User can change L_VAL, 7248c2ecf20Sopenharmony_ci * without having to go through the power on sequence. 7258c2ecf20Sopenharmony_ci */ 7268c2ecf20Sopenharmony_ci if (clk_alpha_pll_is_enabled(hw)) { 7278c2ecf20Sopenharmony_ci if (cur_alpha != a) { 7288c2ecf20Sopenharmony_ci pr_err("%s: clock needs to be gated\n", 7298c2ecf20Sopenharmony_ci clk_hw_get_name(hw)); 7308c2ecf20Sopenharmony_ci return -EBUSY; 7318c2ecf20Sopenharmony_ci } 7328c2ecf20Sopenharmony_ci 7338c2ecf20Sopenharmony_ci regmap_write(pll->clkr.regmap, PLL_L_VAL(pll), l); 7348c2ecf20Sopenharmony_ci /* Ensure that the write above goes to detect L val change. */ 7358c2ecf20Sopenharmony_ci mb(); 7368c2ecf20Sopenharmony_ci return wait_for_pll_enable_lock(pll); 7378c2ecf20Sopenharmony_ci } 7388c2ecf20Sopenharmony_ci 7398c2ecf20Sopenharmony_ci regmap_write(pll->clkr.regmap, PLL_L_VAL(pll), l); 7408c2ecf20Sopenharmony_ci regmap_write(pll->clkr.regmap, PLL_ALPHA_VAL(pll), a); 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_ci if (a == 0) 7438c2ecf20Sopenharmony_ci regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll), 7448c2ecf20Sopenharmony_ci PLL_ALPHA_EN, 0x0); 7458c2ecf20Sopenharmony_ci else 7468c2ecf20Sopenharmony_ci regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll), 7478c2ecf20Sopenharmony_ci PLL_ALPHA_EN | PLL_ALPHA_MODE, PLL_ALPHA_EN); 7488c2ecf20Sopenharmony_ci 7498c2ecf20Sopenharmony_ci return 0; 7508c2ecf20Sopenharmony_ci} 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_cistatic long alpha_pll_huayra_round_rate(struct clk_hw *hw, unsigned long rate, 7538c2ecf20Sopenharmony_ci unsigned long *prate) 7548c2ecf20Sopenharmony_ci{ 7558c2ecf20Sopenharmony_ci u32 l, a; 7568c2ecf20Sopenharmony_ci 7578c2ecf20Sopenharmony_ci return alpha_huayra_pll_round_rate(rate, *prate, &l, &a); 7588c2ecf20Sopenharmony_ci} 7598c2ecf20Sopenharmony_ci 7608c2ecf20Sopenharmony_cistatic int trion_pll_is_enabled(struct clk_alpha_pll *pll, 7618c2ecf20Sopenharmony_ci struct regmap *regmap) 7628c2ecf20Sopenharmony_ci{ 7638c2ecf20Sopenharmony_ci u32 mode_regval, opmode_regval; 7648c2ecf20Sopenharmony_ci int ret; 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ci ret = regmap_read(regmap, PLL_MODE(pll), &mode_regval); 7678c2ecf20Sopenharmony_ci ret |= regmap_read(regmap, PLL_OPMODE(pll), &opmode_regval); 7688c2ecf20Sopenharmony_ci if (ret) 7698c2ecf20Sopenharmony_ci return 0; 7708c2ecf20Sopenharmony_ci 7718c2ecf20Sopenharmony_ci return ((opmode_regval & PLL_RUN) && (mode_regval & PLL_OUTCTRL)); 7728c2ecf20Sopenharmony_ci} 7738c2ecf20Sopenharmony_ci 7748c2ecf20Sopenharmony_cistatic int clk_trion_pll_is_enabled(struct clk_hw *hw) 7758c2ecf20Sopenharmony_ci{ 7768c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_ci return trion_pll_is_enabled(pll, pll->clkr.regmap); 7798c2ecf20Sopenharmony_ci} 7808c2ecf20Sopenharmony_ci 7818c2ecf20Sopenharmony_cistatic int clk_trion_pll_enable(struct clk_hw *hw) 7828c2ecf20Sopenharmony_ci{ 7838c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 7848c2ecf20Sopenharmony_ci struct regmap *regmap = pll->clkr.regmap; 7858c2ecf20Sopenharmony_ci u32 val; 7868c2ecf20Sopenharmony_ci int ret; 7878c2ecf20Sopenharmony_ci 7888c2ecf20Sopenharmony_ci ret = regmap_read(regmap, PLL_MODE(pll), &val); 7898c2ecf20Sopenharmony_ci if (ret) 7908c2ecf20Sopenharmony_ci return ret; 7918c2ecf20Sopenharmony_ci 7928c2ecf20Sopenharmony_ci /* If in FSM mode, just vote for it */ 7938c2ecf20Sopenharmony_ci if (val & PLL_VOTE_FSM_ENA) { 7948c2ecf20Sopenharmony_ci ret = clk_enable_regmap(hw); 7958c2ecf20Sopenharmony_ci if (ret) 7968c2ecf20Sopenharmony_ci return ret; 7978c2ecf20Sopenharmony_ci return wait_for_pll_enable_active(pll); 7988c2ecf20Sopenharmony_ci } 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_ci /* Set operation mode to RUN */ 8018c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_OPMODE(pll), PLL_RUN); 8028c2ecf20Sopenharmony_ci 8038c2ecf20Sopenharmony_ci ret = wait_for_pll_enable_lock(pll); 8048c2ecf20Sopenharmony_ci if (ret) 8058c2ecf20Sopenharmony_ci return ret; 8068c2ecf20Sopenharmony_ci 8078c2ecf20Sopenharmony_ci /* Enable the PLL outputs */ 8088c2ecf20Sopenharmony_ci ret = regmap_update_bits(regmap, PLL_USER_CTL(pll), 8098c2ecf20Sopenharmony_ci PLL_OUT_MASK, PLL_OUT_MASK); 8108c2ecf20Sopenharmony_ci if (ret) 8118c2ecf20Sopenharmony_ci return ret; 8128c2ecf20Sopenharmony_ci 8138c2ecf20Sopenharmony_ci /* Enable the global PLL outputs */ 8148c2ecf20Sopenharmony_ci return regmap_update_bits(regmap, PLL_MODE(pll), 8158c2ecf20Sopenharmony_ci PLL_OUTCTRL, PLL_OUTCTRL); 8168c2ecf20Sopenharmony_ci} 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_cistatic void clk_trion_pll_disable(struct clk_hw *hw) 8198c2ecf20Sopenharmony_ci{ 8208c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 8218c2ecf20Sopenharmony_ci struct regmap *regmap = pll->clkr.regmap; 8228c2ecf20Sopenharmony_ci u32 val; 8238c2ecf20Sopenharmony_ci int ret; 8248c2ecf20Sopenharmony_ci 8258c2ecf20Sopenharmony_ci ret = regmap_read(regmap, PLL_MODE(pll), &val); 8268c2ecf20Sopenharmony_ci if (ret) 8278c2ecf20Sopenharmony_ci return; 8288c2ecf20Sopenharmony_ci 8298c2ecf20Sopenharmony_ci /* If in FSM mode, just unvote it */ 8308c2ecf20Sopenharmony_ci if (val & PLL_VOTE_FSM_ENA) { 8318c2ecf20Sopenharmony_ci clk_disable_regmap(hw); 8328c2ecf20Sopenharmony_ci return; 8338c2ecf20Sopenharmony_ci } 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ci /* Disable the global PLL output */ 8368c2ecf20Sopenharmony_ci ret = regmap_update_bits(regmap, PLL_MODE(pll), PLL_OUTCTRL, 0); 8378c2ecf20Sopenharmony_ci if (ret) 8388c2ecf20Sopenharmony_ci return; 8398c2ecf20Sopenharmony_ci 8408c2ecf20Sopenharmony_ci /* Disable the PLL outputs */ 8418c2ecf20Sopenharmony_ci ret = regmap_update_bits(regmap, PLL_USER_CTL(pll), 8428c2ecf20Sopenharmony_ci PLL_OUT_MASK, 0); 8438c2ecf20Sopenharmony_ci if (ret) 8448c2ecf20Sopenharmony_ci return; 8458c2ecf20Sopenharmony_ci 8468c2ecf20Sopenharmony_ci /* Place the PLL mode in STANDBY */ 8478c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_OPMODE(pll), PLL_STANDBY); 8488c2ecf20Sopenharmony_ci regmap_update_bits(regmap, PLL_MODE(pll), PLL_RESET_N, PLL_RESET_N); 8498c2ecf20Sopenharmony_ci} 8508c2ecf20Sopenharmony_ci 8518c2ecf20Sopenharmony_cistatic unsigned long 8528c2ecf20Sopenharmony_ciclk_trion_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) 8538c2ecf20Sopenharmony_ci{ 8548c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 8558c2ecf20Sopenharmony_ci u32 l, frac, alpha_width = pll_alpha_width(pll); 8568c2ecf20Sopenharmony_ci 8578c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_L_VAL(pll), &l); 8588c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_ALPHA_VAL(pll), &frac); 8598c2ecf20Sopenharmony_ci 8608c2ecf20Sopenharmony_ci return alpha_pll_calc_rate(parent_rate, l, frac, alpha_width); 8618c2ecf20Sopenharmony_ci} 8628c2ecf20Sopenharmony_ci 8638c2ecf20Sopenharmony_ciconst struct clk_ops clk_alpha_pll_fixed_ops = { 8648c2ecf20Sopenharmony_ci .enable = clk_alpha_pll_enable, 8658c2ecf20Sopenharmony_ci .disable = clk_alpha_pll_disable, 8668c2ecf20Sopenharmony_ci .is_enabled = clk_alpha_pll_is_enabled, 8678c2ecf20Sopenharmony_ci .recalc_rate = clk_alpha_pll_recalc_rate, 8688c2ecf20Sopenharmony_ci}; 8698c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_alpha_pll_fixed_ops); 8708c2ecf20Sopenharmony_ci 8718c2ecf20Sopenharmony_ciconst struct clk_ops clk_alpha_pll_ops = { 8728c2ecf20Sopenharmony_ci .enable = clk_alpha_pll_enable, 8738c2ecf20Sopenharmony_ci .disable = clk_alpha_pll_disable, 8748c2ecf20Sopenharmony_ci .is_enabled = clk_alpha_pll_is_enabled, 8758c2ecf20Sopenharmony_ci .recalc_rate = clk_alpha_pll_recalc_rate, 8768c2ecf20Sopenharmony_ci .round_rate = clk_alpha_pll_round_rate, 8778c2ecf20Sopenharmony_ci .set_rate = clk_alpha_pll_set_rate, 8788c2ecf20Sopenharmony_ci}; 8798c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_alpha_pll_ops); 8808c2ecf20Sopenharmony_ci 8818c2ecf20Sopenharmony_ciconst struct clk_ops clk_alpha_pll_huayra_ops = { 8828c2ecf20Sopenharmony_ci .enable = clk_alpha_pll_enable, 8838c2ecf20Sopenharmony_ci .disable = clk_alpha_pll_disable, 8848c2ecf20Sopenharmony_ci .is_enabled = clk_alpha_pll_is_enabled, 8858c2ecf20Sopenharmony_ci .recalc_rate = alpha_pll_huayra_recalc_rate, 8868c2ecf20Sopenharmony_ci .round_rate = alpha_pll_huayra_round_rate, 8878c2ecf20Sopenharmony_ci .set_rate = alpha_pll_huayra_set_rate, 8888c2ecf20Sopenharmony_ci}; 8898c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_alpha_pll_huayra_ops); 8908c2ecf20Sopenharmony_ci 8918c2ecf20Sopenharmony_ciconst struct clk_ops clk_alpha_pll_hwfsm_ops = { 8928c2ecf20Sopenharmony_ci .enable = clk_alpha_pll_hwfsm_enable, 8938c2ecf20Sopenharmony_ci .disable = clk_alpha_pll_hwfsm_disable, 8948c2ecf20Sopenharmony_ci .is_enabled = clk_alpha_pll_hwfsm_is_enabled, 8958c2ecf20Sopenharmony_ci .recalc_rate = clk_alpha_pll_recalc_rate, 8968c2ecf20Sopenharmony_ci .round_rate = clk_alpha_pll_round_rate, 8978c2ecf20Sopenharmony_ci .set_rate = clk_alpha_pll_hwfsm_set_rate, 8988c2ecf20Sopenharmony_ci}; 8998c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_alpha_pll_hwfsm_ops); 9008c2ecf20Sopenharmony_ci 9018c2ecf20Sopenharmony_ciconst struct clk_ops clk_alpha_pll_fixed_trion_ops = { 9028c2ecf20Sopenharmony_ci .enable = clk_trion_pll_enable, 9038c2ecf20Sopenharmony_ci .disable = clk_trion_pll_disable, 9048c2ecf20Sopenharmony_ci .is_enabled = clk_trion_pll_is_enabled, 9058c2ecf20Sopenharmony_ci .recalc_rate = clk_trion_pll_recalc_rate, 9068c2ecf20Sopenharmony_ci .round_rate = clk_alpha_pll_round_rate, 9078c2ecf20Sopenharmony_ci}; 9088c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_alpha_pll_fixed_trion_ops); 9098c2ecf20Sopenharmony_ci 9108c2ecf20Sopenharmony_cistatic unsigned long 9118c2ecf20Sopenharmony_ciclk_alpha_pll_postdiv_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) 9128c2ecf20Sopenharmony_ci{ 9138c2ecf20Sopenharmony_ci struct clk_alpha_pll_postdiv *pll = to_clk_alpha_pll_postdiv(hw); 9148c2ecf20Sopenharmony_ci u32 ctl; 9158c2ecf20Sopenharmony_ci 9168c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_USER_CTL(pll), &ctl); 9178c2ecf20Sopenharmony_ci 9188c2ecf20Sopenharmony_ci ctl >>= PLL_POST_DIV_SHIFT; 9198c2ecf20Sopenharmony_ci ctl &= PLL_POST_DIV_MASK(pll); 9208c2ecf20Sopenharmony_ci 9218c2ecf20Sopenharmony_ci return parent_rate >> fls(ctl); 9228c2ecf20Sopenharmony_ci} 9238c2ecf20Sopenharmony_ci 9248c2ecf20Sopenharmony_cistatic const struct clk_div_table clk_alpha_div_table[] = { 9258c2ecf20Sopenharmony_ci { 0x0, 1 }, 9268c2ecf20Sopenharmony_ci { 0x1, 2 }, 9278c2ecf20Sopenharmony_ci { 0x3, 4 }, 9288c2ecf20Sopenharmony_ci { 0x7, 8 }, 9298c2ecf20Sopenharmony_ci { 0xf, 16 }, 9308c2ecf20Sopenharmony_ci { } 9318c2ecf20Sopenharmony_ci}; 9328c2ecf20Sopenharmony_ci 9338c2ecf20Sopenharmony_cistatic const struct clk_div_table clk_alpha_2bit_div_table[] = { 9348c2ecf20Sopenharmony_ci { 0x0, 1 }, 9358c2ecf20Sopenharmony_ci { 0x1, 2 }, 9368c2ecf20Sopenharmony_ci { 0x3, 4 }, 9378c2ecf20Sopenharmony_ci { } 9388c2ecf20Sopenharmony_ci}; 9398c2ecf20Sopenharmony_ci 9408c2ecf20Sopenharmony_cistatic long 9418c2ecf20Sopenharmony_ciclk_alpha_pll_postdiv_round_rate(struct clk_hw *hw, unsigned long rate, 9428c2ecf20Sopenharmony_ci unsigned long *prate) 9438c2ecf20Sopenharmony_ci{ 9448c2ecf20Sopenharmony_ci struct clk_alpha_pll_postdiv *pll = to_clk_alpha_pll_postdiv(hw); 9458c2ecf20Sopenharmony_ci const struct clk_div_table *table; 9468c2ecf20Sopenharmony_ci 9478c2ecf20Sopenharmony_ci if (pll->width == 2) 9488c2ecf20Sopenharmony_ci table = clk_alpha_2bit_div_table; 9498c2ecf20Sopenharmony_ci else 9508c2ecf20Sopenharmony_ci table = clk_alpha_div_table; 9518c2ecf20Sopenharmony_ci 9528c2ecf20Sopenharmony_ci return divider_round_rate(hw, rate, prate, table, 9538c2ecf20Sopenharmony_ci pll->width, CLK_DIVIDER_POWER_OF_TWO); 9548c2ecf20Sopenharmony_ci} 9558c2ecf20Sopenharmony_ci 9568c2ecf20Sopenharmony_cistatic long 9578c2ecf20Sopenharmony_ciclk_alpha_pll_postdiv_round_ro_rate(struct clk_hw *hw, unsigned long rate, 9588c2ecf20Sopenharmony_ci unsigned long *prate) 9598c2ecf20Sopenharmony_ci{ 9608c2ecf20Sopenharmony_ci struct clk_alpha_pll_postdiv *pll = to_clk_alpha_pll_postdiv(hw); 9618c2ecf20Sopenharmony_ci u32 ctl, div; 9628c2ecf20Sopenharmony_ci 9638c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_USER_CTL(pll), &ctl); 9648c2ecf20Sopenharmony_ci 9658c2ecf20Sopenharmony_ci ctl >>= PLL_POST_DIV_SHIFT; 9668c2ecf20Sopenharmony_ci ctl &= BIT(pll->width) - 1; 9678c2ecf20Sopenharmony_ci div = 1 << fls(ctl); 9688c2ecf20Sopenharmony_ci 9698c2ecf20Sopenharmony_ci if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) 9708c2ecf20Sopenharmony_ci *prate = clk_hw_round_rate(clk_hw_get_parent(hw), div * rate); 9718c2ecf20Sopenharmony_ci 9728c2ecf20Sopenharmony_ci return DIV_ROUND_UP_ULL((u64)*prate, div); 9738c2ecf20Sopenharmony_ci} 9748c2ecf20Sopenharmony_ci 9758c2ecf20Sopenharmony_cistatic int clk_alpha_pll_postdiv_set_rate(struct clk_hw *hw, unsigned long rate, 9768c2ecf20Sopenharmony_ci unsigned long parent_rate) 9778c2ecf20Sopenharmony_ci{ 9788c2ecf20Sopenharmony_ci struct clk_alpha_pll_postdiv *pll = to_clk_alpha_pll_postdiv(hw); 9798c2ecf20Sopenharmony_ci int div; 9808c2ecf20Sopenharmony_ci 9818c2ecf20Sopenharmony_ci /* 16 -> 0xf, 8 -> 0x7, 4 -> 0x3, 2 -> 0x1, 1 -> 0x0 */ 9828c2ecf20Sopenharmony_ci div = DIV_ROUND_UP_ULL(parent_rate, rate) - 1; 9838c2ecf20Sopenharmony_ci 9848c2ecf20Sopenharmony_ci return regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll), 9858c2ecf20Sopenharmony_ci PLL_POST_DIV_MASK(pll) << PLL_POST_DIV_SHIFT, 9868c2ecf20Sopenharmony_ci div << PLL_POST_DIV_SHIFT); 9878c2ecf20Sopenharmony_ci} 9888c2ecf20Sopenharmony_ci 9898c2ecf20Sopenharmony_ciconst struct clk_ops clk_alpha_pll_postdiv_ops = { 9908c2ecf20Sopenharmony_ci .recalc_rate = clk_alpha_pll_postdiv_recalc_rate, 9918c2ecf20Sopenharmony_ci .round_rate = clk_alpha_pll_postdiv_round_rate, 9928c2ecf20Sopenharmony_ci .set_rate = clk_alpha_pll_postdiv_set_rate, 9938c2ecf20Sopenharmony_ci}; 9948c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_alpha_pll_postdiv_ops); 9958c2ecf20Sopenharmony_ci 9968c2ecf20Sopenharmony_ciconst struct clk_ops clk_alpha_pll_postdiv_ro_ops = { 9978c2ecf20Sopenharmony_ci .round_rate = clk_alpha_pll_postdiv_round_ro_rate, 9988c2ecf20Sopenharmony_ci .recalc_rate = clk_alpha_pll_postdiv_recalc_rate, 9998c2ecf20Sopenharmony_ci}; 10008c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_alpha_pll_postdiv_ro_ops); 10018c2ecf20Sopenharmony_ci 10028c2ecf20Sopenharmony_civoid clk_fabia_pll_configure(struct clk_alpha_pll *pll, struct regmap *regmap, 10038c2ecf20Sopenharmony_ci const struct alpha_pll_config *config) 10048c2ecf20Sopenharmony_ci{ 10058c2ecf20Sopenharmony_ci u32 val, mask; 10068c2ecf20Sopenharmony_ci 10078c2ecf20Sopenharmony_ci if (config->l) 10088c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_L_VAL(pll), config->l); 10098c2ecf20Sopenharmony_ci 10108c2ecf20Sopenharmony_ci if (config->alpha) 10118c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_FRAC(pll), config->alpha); 10128c2ecf20Sopenharmony_ci 10138c2ecf20Sopenharmony_ci if (config->config_ctl_val) 10148c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_CONFIG_CTL(pll), 10158c2ecf20Sopenharmony_ci config->config_ctl_val); 10168c2ecf20Sopenharmony_ci 10178c2ecf20Sopenharmony_ci if (config->config_ctl_hi_val) 10188c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_CONFIG_CTL_U(pll), 10198c2ecf20Sopenharmony_ci config->config_ctl_hi_val); 10208c2ecf20Sopenharmony_ci 10218c2ecf20Sopenharmony_ci if (config->user_ctl_val) 10228c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_USER_CTL(pll), config->user_ctl_val); 10238c2ecf20Sopenharmony_ci 10248c2ecf20Sopenharmony_ci if (config->user_ctl_hi_val) 10258c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_USER_CTL_U(pll), 10268c2ecf20Sopenharmony_ci config->user_ctl_hi_val); 10278c2ecf20Sopenharmony_ci 10288c2ecf20Sopenharmony_ci if (config->test_ctl_val) 10298c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_TEST_CTL(pll), 10308c2ecf20Sopenharmony_ci config->test_ctl_val); 10318c2ecf20Sopenharmony_ci 10328c2ecf20Sopenharmony_ci if (config->test_ctl_hi_val) 10338c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_TEST_CTL_U(pll), 10348c2ecf20Sopenharmony_ci config->test_ctl_hi_val); 10358c2ecf20Sopenharmony_ci 10368c2ecf20Sopenharmony_ci if (config->post_div_mask) { 10378c2ecf20Sopenharmony_ci mask = config->post_div_mask; 10388c2ecf20Sopenharmony_ci val = config->post_div_val; 10398c2ecf20Sopenharmony_ci regmap_update_bits(regmap, PLL_USER_CTL(pll), mask, val); 10408c2ecf20Sopenharmony_ci } 10418c2ecf20Sopenharmony_ci 10428c2ecf20Sopenharmony_ci regmap_update_bits(regmap, PLL_MODE(pll), PLL_UPDATE_BYPASS, 10438c2ecf20Sopenharmony_ci PLL_UPDATE_BYPASS); 10448c2ecf20Sopenharmony_ci 10458c2ecf20Sopenharmony_ci regmap_update_bits(regmap, PLL_MODE(pll), PLL_RESET_N, PLL_RESET_N); 10468c2ecf20Sopenharmony_ci} 10478c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_fabia_pll_configure); 10488c2ecf20Sopenharmony_ci 10498c2ecf20Sopenharmony_cistatic int alpha_pll_fabia_enable(struct clk_hw *hw) 10508c2ecf20Sopenharmony_ci{ 10518c2ecf20Sopenharmony_ci int ret; 10528c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 10538c2ecf20Sopenharmony_ci u32 val, opmode_val; 10548c2ecf20Sopenharmony_ci struct regmap *regmap = pll->clkr.regmap; 10558c2ecf20Sopenharmony_ci 10568c2ecf20Sopenharmony_ci ret = regmap_read(regmap, PLL_MODE(pll), &val); 10578c2ecf20Sopenharmony_ci if (ret) 10588c2ecf20Sopenharmony_ci return ret; 10598c2ecf20Sopenharmony_ci 10608c2ecf20Sopenharmony_ci /* If in FSM mode, just vote for it */ 10618c2ecf20Sopenharmony_ci if (val & PLL_VOTE_FSM_ENA) { 10628c2ecf20Sopenharmony_ci ret = clk_enable_regmap(hw); 10638c2ecf20Sopenharmony_ci if (ret) 10648c2ecf20Sopenharmony_ci return ret; 10658c2ecf20Sopenharmony_ci return wait_for_pll_enable_active(pll); 10668c2ecf20Sopenharmony_ci } 10678c2ecf20Sopenharmony_ci 10688c2ecf20Sopenharmony_ci ret = regmap_read(regmap, PLL_OPMODE(pll), &opmode_val); 10698c2ecf20Sopenharmony_ci if (ret) 10708c2ecf20Sopenharmony_ci return ret; 10718c2ecf20Sopenharmony_ci 10728c2ecf20Sopenharmony_ci /* Skip If PLL is already running */ 10738c2ecf20Sopenharmony_ci if ((opmode_val & PLL_RUN) && (val & PLL_OUTCTRL)) 10748c2ecf20Sopenharmony_ci return 0; 10758c2ecf20Sopenharmony_ci 10768c2ecf20Sopenharmony_ci ret = regmap_update_bits(regmap, PLL_MODE(pll), PLL_OUTCTRL, 0); 10778c2ecf20Sopenharmony_ci if (ret) 10788c2ecf20Sopenharmony_ci return ret; 10798c2ecf20Sopenharmony_ci 10808c2ecf20Sopenharmony_ci ret = regmap_write(regmap, PLL_OPMODE(pll), PLL_STANDBY); 10818c2ecf20Sopenharmony_ci if (ret) 10828c2ecf20Sopenharmony_ci return ret; 10838c2ecf20Sopenharmony_ci 10848c2ecf20Sopenharmony_ci ret = regmap_update_bits(regmap, PLL_MODE(pll), PLL_RESET_N, 10858c2ecf20Sopenharmony_ci PLL_RESET_N); 10868c2ecf20Sopenharmony_ci if (ret) 10878c2ecf20Sopenharmony_ci return ret; 10888c2ecf20Sopenharmony_ci 10898c2ecf20Sopenharmony_ci ret = regmap_write(regmap, PLL_OPMODE(pll), PLL_RUN); 10908c2ecf20Sopenharmony_ci if (ret) 10918c2ecf20Sopenharmony_ci return ret; 10928c2ecf20Sopenharmony_ci 10938c2ecf20Sopenharmony_ci ret = wait_for_pll_enable_lock(pll); 10948c2ecf20Sopenharmony_ci if (ret) 10958c2ecf20Sopenharmony_ci return ret; 10968c2ecf20Sopenharmony_ci 10978c2ecf20Sopenharmony_ci ret = regmap_update_bits(regmap, PLL_USER_CTL(pll), 10988c2ecf20Sopenharmony_ci PLL_OUT_MASK, PLL_OUT_MASK); 10998c2ecf20Sopenharmony_ci if (ret) 11008c2ecf20Sopenharmony_ci return ret; 11018c2ecf20Sopenharmony_ci 11028c2ecf20Sopenharmony_ci return regmap_update_bits(regmap, PLL_MODE(pll), PLL_OUTCTRL, 11038c2ecf20Sopenharmony_ci PLL_OUTCTRL); 11048c2ecf20Sopenharmony_ci} 11058c2ecf20Sopenharmony_ci 11068c2ecf20Sopenharmony_cistatic void alpha_pll_fabia_disable(struct clk_hw *hw) 11078c2ecf20Sopenharmony_ci{ 11088c2ecf20Sopenharmony_ci int ret; 11098c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 11108c2ecf20Sopenharmony_ci u32 val; 11118c2ecf20Sopenharmony_ci struct regmap *regmap = pll->clkr.regmap; 11128c2ecf20Sopenharmony_ci 11138c2ecf20Sopenharmony_ci ret = regmap_read(regmap, PLL_MODE(pll), &val); 11148c2ecf20Sopenharmony_ci if (ret) 11158c2ecf20Sopenharmony_ci return; 11168c2ecf20Sopenharmony_ci 11178c2ecf20Sopenharmony_ci /* If in FSM mode, just unvote it */ 11188c2ecf20Sopenharmony_ci if (val & PLL_FSM_ENA) { 11198c2ecf20Sopenharmony_ci clk_disable_regmap(hw); 11208c2ecf20Sopenharmony_ci return; 11218c2ecf20Sopenharmony_ci } 11228c2ecf20Sopenharmony_ci 11238c2ecf20Sopenharmony_ci ret = regmap_update_bits(regmap, PLL_MODE(pll), PLL_OUTCTRL, 0); 11248c2ecf20Sopenharmony_ci if (ret) 11258c2ecf20Sopenharmony_ci return; 11268c2ecf20Sopenharmony_ci 11278c2ecf20Sopenharmony_ci /* Disable main outputs */ 11288c2ecf20Sopenharmony_ci ret = regmap_update_bits(regmap, PLL_USER_CTL(pll), PLL_OUT_MASK, 0); 11298c2ecf20Sopenharmony_ci if (ret) 11308c2ecf20Sopenharmony_ci return; 11318c2ecf20Sopenharmony_ci 11328c2ecf20Sopenharmony_ci /* Place the PLL in STANDBY */ 11338c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_OPMODE(pll), PLL_STANDBY); 11348c2ecf20Sopenharmony_ci} 11358c2ecf20Sopenharmony_ci 11368c2ecf20Sopenharmony_cistatic unsigned long alpha_pll_fabia_recalc_rate(struct clk_hw *hw, 11378c2ecf20Sopenharmony_ci unsigned long parent_rate) 11388c2ecf20Sopenharmony_ci{ 11398c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 11408c2ecf20Sopenharmony_ci u32 l, frac, alpha_width = pll_alpha_width(pll); 11418c2ecf20Sopenharmony_ci 11428c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_L_VAL(pll), &l); 11438c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_FRAC(pll), &frac); 11448c2ecf20Sopenharmony_ci 11458c2ecf20Sopenharmony_ci return alpha_pll_calc_rate(parent_rate, l, frac, alpha_width); 11468c2ecf20Sopenharmony_ci} 11478c2ecf20Sopenharmony_ci 11488c2ecf20Sopenharmony_cistatic int alpha_pll_fabia_set_rate(struct clk_hw *hw, unsigned long rate, 11498c2ecf20Sopenharmony_ci unsigned long prate) 11508c2ecf20Sopenharmony_ci{ 11518c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 11528c2ecf20Sopenharmony_ci u32 l, alpha_width = pll_alpha_width(pll); 11538c2ecf20Sopenharmony_ci u64 a; 11548c2ecf20Sopenharmony_ci unsigned long rrate, max = rate + PLL_RATE_MARGIN; 11558c2ecf20Sopenharmony_ci 11568c2ecf20Sopenharmony_ci rrate = alpha_pll_round_rate(rate, prate, &l, &a, alpha_width); 11578c2ecf20Sopenharmony_ci 11588c2ecf20Sopenharmony_ci /* 11598c2ecf20Sopenharmony_ci * Due to limited number of bits for fractional rate programming, the 11608c2ecf20Sopenharmony_ci * rounded up rate could be marginally higher than the requested rate. 11618c2ecf20Sopenharmony_ci */ 11628c2ecf20Sopenharmony_ci if (rrate > (rate + PLL_RATE_MARGIN) || rrate < rate) { 11638c2ecf20Sopenharmony_ci pr_err("%s: Rounded rate %lu not within range [%lu, %lu)\n", 11648c2ecf20Sopenharmony_ci clk_hw_get_name(hw), rrate, rate, max); 11658c2ecf20Sopenharmony_ci return -EINVAL; 11668c2ecf20Sopenharmony_ci } 11678c2ecf20Sopenharmony_ci 11688c2ecf20Sopenharmony_ci regmap_write(pll->clkr.regmap, PLL_L_VAL(pll), l); 11698c2ecf20Sopenharmony_ci regmap_write(pll->clkr.regmap, PLL_FRAC(pll), a); 11708c2ecf20Sopenharmony_ci 11718c2ecf20Sopenharmony_ci return __clk_alpha_pll_update_latch(pll); 11728c2ecf20Sopenharmony_ci} 11738c2ecf20Sopenharmony_ci 11748c2ecf20Sopenharmony_cistatic int alpha_pll_fabia_prepare(struct clk_hw *hw) 11758c2ecf20Sopenharmony_ci{ 11768c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 11778c2ecf20Sopenharmony_ci const struct pll_vco *vco; 11788c2ecf20Sopenharmony_ci struct clk_hw *parent_hw; 11798c2ecf20Sopenharmony_ci unsigned long cal_freq, rrate; 11808c2ecf20Sopenharmony_ci u32 cal_l, val, alpha_width = pll_alpha_width(pll); 11818c2ecf20Sopenharmony_ci const char *name = clk_hw_get_name(hw); 11828c2ecf20Sopenharmony_ci u64 a; 11838c2ecf20Sopenharmony_ci int ret; 11848c2ecf20Sopenharmony_ci 11858c2ecf20Sopenharmony_ci /* Check if calibration needs to be done i.e. PLL is in reset */ 11868c2ecf20Sopenharmony_ci ret = regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val); 11878c2ecf20Sopenharmony_ci if (ret) 11888c2ecf20Sopenharmony_ci return ret; 11898c2ecf20Sopenharmony_ci 11908c2ecf20Sopenharmony_ci /* Return early if calibration is not needed. */ 11918c2ecf20Sopenharmony_ci if (val & PLL_RESET_N) 11928c2ecf20Sopenharmony_ci return 0; 11938c2ecf20Sopenharmony_ci 11948c2ecf20Sopenharmony_ci vco = alpha_pll_find_vco(pll, clk_hw_get_rate(hw)); 11958c2ecf20Sopenharmony_ci if (!vco) { 11968c2ecf20Sopenharmony_ci pr_err("%s: alpha pll not in a valid vco range\n", name); 11978c2ecf20Sopenharmony_ci return -EINVAL; 11988c2ecf20Sopenharmony_ci } 11998c2ecf20Sopenharmony_ci 12008c2ecf20Sopenharmony_ci cal_freq = DIV_ROUND_CLOSEST((pll->vco_table[0].min_freq + 12018c2ecf20Sopenharmony_ci pll->vco_table[0].max_freq) * 54, 100); 12028c2ecf20Sopenharmony_ci 12038c2ecf20Sopenharmony_ci parent_hw = clk_hw_get_parent(hw); 12048c2ecf20Sopenharmony_ci if (!parent_hw) 12058c2ecf20Sopenharmony_ci return -EINVAL; 12068c2ecf20Sopenharmony_ci 12078c2ecf20Sopenharmony_ci rrate = alpha_pll_round_rate(cal_freq, clk_hw_get_rate(parent_hw), 12088c2ecf20Sopenharmony_ci &cal_l, &a, alpha_width); 12098c2ecf20Sopenharmony_ci /* 12108c2ecf20Sopenharmony_ci * Due to a limited number of bits for fractional rate programming, the 12118c2ecf20Sopenharmony_ci * rounded up rate could be marginally higher than the requested rate. 12128c2ecf20Sopenharmony_ci */ 12138c2ecf20Sopenharmony_ci if (rrate > (cal_freq + PLL_RATE_MARGIN) || rrate < cal_freq) 12148c2ecf20Sopenharmony_ci return -EINVAL; 12158c2ecf20Sopenharmony_ci 12168c2ecf20Sopenharmony_ci /* Setup PLL for calibration frequency */ 12178c2ecf20Sopenharmony_ci regmap_write(pll->clkr.regmap, PLL_CAL_L_VAL(pll), cal_l); 12188c2ecf20Sopenharmony_ci 12198c2ecf20Sopenharmony_ci /* Bringup the PLL at calibration frequency */ 12208c2ecf20Sopenharmony_ci ret = clk_alpha_pll_enable(hw); 12218c2ecf20Sopenharmony_ci if (ret) { 12228c2ecf20Sopenharmony_ci pr_err("%s: alpha pll calibration failed\n", name); 12238c2ecf20Sopenharmony_ci return ret; 12248c2ecf20Sopenharmony_ci } 12258c2ecf20Sopenharmony_ci 12268c2ecf20Sopenharmony_ci clk_alpha_pll_disable(hw); 12278c2ecf20Sopenharmony_ci 12288c2ecf20Sopenharmony_ci return 0; 12298c2ecf20Sopenharmony_ci} 12308c2ecf20Sopenharmony_ci 12318c2ecf20Sopenharmony_ciconst struct clk_ops clk_alpha_pll_fabia_ops = { 12328c2ecf20Sopenharmony_ci .prepare = alpha_pll_fabia_prepare, 12338c2ecf20Sopenharmony_ci .enable = alpha_pll_fabia_enable, 12348c2ecf20Sopenharmony_ci .disable = alpha_pll_fabia_disable, 12358c2ecf20Sopenharmony_ci .is_enabled = clk_alpha_pll_is_enabled, 12368c2ecf20Sopenharmony_ci .set_rate = alpha_pll_fabia_set_rate, 12378c2ecf20Sopenharmony_ci .recalc_rate = alpha_pll_fabia_recalc_rate, 12388c2ecf20Sopenharmony_ci .round_rate = clk_alpha_pll_round_rate, 12398c2ecf20Sopenharmony_ci}; 12408c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_alpha_pll_fabia_ops); 12418c2ecf20Sopenharmony_ci 12428c2ecf20Sopenharmony_ciconst struct clk_ops clk_alpha_pll_fixed_fabia_ops = { 12438c2ecf20Sopenharmony_ci .enable = alpha_pll_fabia_enable, 12448c2ecf20Sopenharmony_ci .disable = alpha_pll_fabia_disable, 12458c2ecf20Sopenharmony_ci .is_enabled = clk_alpha_pll_is_enabled, 12468c2ecf20Sopenharmony_ci .recalc_rate = alpha_pll_fabia_recalc_rate, 12478c2ecf20Sopenharmony_ci .round_rate = clk_alpha_pll_round_rate, 12488c2ecf20Sopenharmony_ci}; 12498c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_alpha_pll_fixed_fabia_ops); 12508c2ecf20Sopenharmony_ci 12518c2ecf20Sopenharmony_cistatic unsigned long clk_alpha_pll_postdiv_fabia_recalc_rate(struct clk_hw *hw, 12528c2ecf20Sopenharmony_ci unsigned long parent_rate) 12538c2ecf20Sopenharmony_ci{ 12548c2ecf20Sopenharmony_ci struct clk_alpha_pll_postdiv *pll = to_clk_alpha_pll_postdiv(hw); 12558c2ecf20Sopenharmony_ci u32 i, div = 1, val; 12568c2ecf20Sopenharmony_ci int ret; 12578c2ecf20Sopenharmony_ci 12588c2ecf20Sopenharmony_ci ret = regmap_read(pll->clkr.regmap, PLL_USER_CTL(pll), &val); 12598c2ecf20Sopenharmony_ci if (ret) 12608c2ecf20Sopenharmony_ci return ret; 12618c2ecf20Sopenharmony_ci 12628c2ecf20Sopenharmony_ci val >>= pll->post_div_shift; 12638c2ecf20Sopenharmony_ci val &= BIT(pll->width) - 1; 12648c2ecf20Sopenharmony_ci 12658c2ecf20Sopenharmony_ci for (i = 0; i < pll->num_post_div; i++) { 12668c2ecf20Sopenharmony_ci if (pll->post_div_table[i].val == val) { 12678c2ecf20Sopenharmony_ci div = pll->post_div_table[i].div; 12688c2ecf20Sopenharmony_ci break; 12698c2ecf20Sopenharmony_ci } 12708c2ecf20Sopenharmony_ci } 12718c2ecf20Sopenharmony_ci 12728c2ecf20Sopenharmony_ci return (parent_rate / div); 12738c2ecf20Sopenharmony_ci} 12748c2ecf20Sopenharmony_ci 12758c2ecf20Sopenharmony_cistatic unsigned long 12768c2ecf20Sopenharmony_ciclk_trion_pll_postdiv_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) 12778c2ecf20Sopenharmony_ci{ 12788c2ecf20Sopenharmony_ci struct clk_alpha_pll_postdiv *pll = to_clk_alpha_pll_postdiv(hw); 12798c2ecf20Sopenharmony_ci struct regmap *regmap = pll->clkr.regmap; 12808c2ecf20Sopenharmony_ci u32 i, div = 1, val; 12818c2ecf20Sopenharmony_ci 12828c2ecf20Sopenharmony_ci regmap_read(regmap, PLL_USER_CTL(pll), &val); 12838c2ecf20Sopenharmony_ci 12848c2ecf20Sopenharmony_ci val >>= pll->post_div_shift; 12858c2ecf20Sopenharmony_ci val &= PLL_POST_DIV_MASK(pll); 12868c2ecf20Sopenharmony_ci 12878c2ecf20Sopenharmony_ci for (i = 0; i < pll->num_post_div; i++) { 12888c2ecf20Sopenharmony_ci if (pll->post_div_table[i].val == val) { 12898c2ecf20Sopenharmony_ci div = pll->post_div_table[i].div; 12908c2ecf20Sopenharmony_ci break; 12918c2ecf20Sopenharmony_ci } 12928c2ecf20Sopenharmony_ci } 12938c2ecf20Sopenharmony_ci 12948c2ecf20Sopenharmony_ci return (parent_rate / div); 12958c2ecf20Sopenharmony_ci} 12968c2ecf20Sopenharmony_ci 12978c2ecf20Sopenharmony_cistatic long 12988c2ecf20Sopenharmony_ciclk_trion_pll_postdiv_round_rate(struct clk_hw *hw, unsigned long rate, 12998c2ecf20Sopenharmony_ci unsigned long *prate) 13008c2ecf20Sopenharmony_ci{ 13018c2ecf20Sopenharmony_ci struct clk_alpha_pll_postdiv *pll = to_clk_alpha_pll_postdiv(hw); 13028c2ecf20Sopenharmony_ci 13038c2ecf20Sopenharmony_ci return divider_round_rate(hw, rate, prate, pll->post_div_table, 13048c2ecf20Sopenharmony_ci pll->width, CLK_DIVIDER_ROUND_CLOSEST); 13058c2ecf20Sopenharmony_ci}; 13068c2ecf20Sopenharmony_ci 13078c2ecf20Sopenharmony_cistatic int 13088c2ecf20Sopenharmony_ciclk_trion_pll_postdiv_set_rate(struct clk_hw *hw, unsigned long rate, 13098c2ecf20Sopenharmony_ci unsigned long parent_rate) 13108c2ecf20Sopenharmony_ci{ 13118c2ecf20Sopenharmony_ci struct clk_alpha_pll_postdiv *pll = to_clk_alpha_pll_postdiv(hw); 13128c2ecf20Sopenharmony_ci struct regmap *regmap = pll->clkr.regmap; 13138c2ecf20Sopenharmony_ci int i, val = 0, div; 13148c2ecf20Sopenharmony_ci 13158c2ecf20Sopenharmony_ci div = DIV_ROUND_UP_ULL(parent_rate, rate); 13168c2ecf20Sopenharmony_ci for (i = 0; i < pll->num_post_div; i++) { 13178c2ecf20Sopenharmony_ci if (pll->post_div_table[i].div == div) { 13188c2ecf20Sopenharmony_ci val = pll->post_div_table[i].val; 13198c2ecf20Sopenharmony_ci break; 13208c2ecf20Sopenharmony_ci } 13218c2ecf20Sopenharmony_ci } 13228c2ecf20Sopenharmony_ci 13238c2ecf20Sopenharmony_ci return regmap_update_bits(regmap, PLL_USER_CTL(pll), 13248c2ecf20Sopenharmony_ci PLL_POST_DIV_MASK(pll) << PLL_POST_DIV_SHIFT, 13258c2ecf20Sopenharmony_ci val << PLL_POST_DIV_SHIFT); 13268c2ecf20Sopenharmony_ci} 13278c2ecf20Sopenharmony_ci 13288c2ecf20Sopenharmony_ciconst struct clk_ops clk_alpha_pll_postdiv_trion_ops = { 13298c2ecf20Sopenharmony_ci .recalc_rate = clk_trion_pll_postdiv_recalc_rate, 13308c2ecf20Sopenharmony_ci .round_rate = clk_trion_pll_postdiv_round_rate, 13318c2ecf20Sopenharmony_ci .set_rate = clk_trion_pll_postdiv_set_rate, 13328c2ecf20Sopenharmony_ci}; 13338c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_alpha_pll_postdiv_trion_ops); 13348c2ecf20Sopenharmony_ci 13358c2ecf20Sopenharmony_cistatic long clk_alpha_pll_postdiv_fabia_round_rate(struct clk_hw *hw, 13368c2ecf20Sopenharmony_ci unsigned long rate, unsigned long *prate) 13378c2ecf20Sopenharmony_ci{ 13388c2ecf20Sopenharmony_ci struct clk_alpha_pll_postdiv *pll = to_clk_alpha_pll_postdiv(hw); 13398c2ecf20Sopenharmony_ci 13408c2ecf20Sopenharmony_ci return divider_round_rate(hw, rate, prate, pll->post_div_table, 13418c2ecf20Sopenharmony_ci pll->width, CLK_DIVIDER_ROUND_CLOSEST); 13428c2ecf20Sopenharmony_ci} 13438c2ecf20Sopenharmony_ci 13448c2ecf20Sopenharmony_cistatic int clk_alpha_pll_postdiv_fabia_set_rate(struct clk_hw *hw, 13458c2ecf20Sopenharmony_ci unsigned long rate, unsigned long parent_rate) 13468c2ecf20Sopenharmony_ci{ 13478c2ecf20Sopenharmony_ci struct clk_alpha_pll_postdiv *pll = to_clk_alpha_pll_postdiv(hw); 13488c2ecf20Sopenharmony_ci int i, val = 0, div, ret; 13498c2ecf20Sopenharmony_ci 13508c2ecf20Sopenharmony_ci /* 13518c2ecf20Sopenharmony_ci * If the PLL is in FSM mode, then treat set_rate callback as a 13528c2ecf20Sopenharmony_ci * no-operation. 13538c2ecf20Sopenharmony_ci */ 13548c2ecf20Sopenharmony_ci ret = regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val); 13558c2ecf20Sopenharmony_ci if (ret) 13568c2ecf20Sopenharmony_ci return ret; 13578c2ecf20Sopenharmony_ci 13588c2ecf20Sopenharmony_ci if (val & PLL_VOTE_FSM_ENA) 13598c2ecf20Sopenharmony_ci return 0; 13608c2ecf20Sopenharmony_ci 13618c2ecf20Sopenharmony_ci div = DIV_ROUND_UP_ULL(parent_rate, rate); 13628c2ecf20Sopenharmony_ci for (i = 0; i < pll->num_post_div; i++) { 13638c2ecf20Sopenharmony_ci if (pll->post_div_table[i].div == div) { 13648c2ecf20Sopenharmony_ci val = pll->post_div_table[i].val; 13658c2ecf20Sopenharmony_ci break; 13668c2ecf20Sopenharmony_ci } 13678c2ecf20Sopenharmony_ci } 13688c2ecf20Sopenharmony_ci 13698c2ecf20Sopenharmony_ci return regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll), 13708c2ecf20Sopenharmony_ci (BIT(pll->width) - 1) << pll->post_div_shift, 13718c2ecf20Sopenharmony_ci val << pll->post_div_shift); 13728c2ecf20Sopenharmony_ci} 13738c2ecf20Sopenharmony_ci 13748c2ecf20Sopenharmony_ciconst struct clk_ops clk_alpha_pll_postdiv_fabia_ops = { 13758c2ecf20Sopenharmony_ci .recalc_rate = clk_alpha_pll_postdiv_fabia_recalc_rate, 13768c2ecf20Sopenharmony_ci .round_rate = clk_alpha_pll_postdiv_fabia_round_rate, 13778c2ecf20Sopenharmony_ci .set_rate = clk_alpha_pll_postdiv_fabia_set_rate, 13788c2ecf20Sopenharmony_ci}; 13798c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_alpha_pll_postdiv_fabia_ops); 13808c2ecf20Sopenharmony_ci 13818c2ecf20Sopenharmony_ci/** 13828c2ecf20Sopenharmony_ci * clk_trion_pll_configure - configure the trion pll 13838c2ecf20Sopenharmony_ci * 13848c2ecf20Sopenharmony_ci * @pll: clk alpha pll 13858c2ecf20Sopenharmony_ci * @regmap: register map 13868c2ecf20Sopenharmony_ci * @config: configuration to apply for pll 13878c2ecf20Sopenharmony_ci */ 13888c2ecf20Sopenharmony_civoid clk_trion_pll_configure(struct clk_alpha_pll *pll, struct regmap *regmap, 13898c2ecf20Sopenharmony_ci const struct alpha_pll_config *config) 13908c2ecf20Sopenharmony_ci{ 13918c2ecf20Sopenharmony_ci if (config->l) 13928c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_L_VAL(pll), config->l); 13938c2ecf20Sopenharmony_ci 13948c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_CAL_L_VAL(pll), TRION_PLL_CAL_VAL); 13958c2ecf20Sopenharmony_ci 13968c2ecf20Sopenharmony_ci if (config->alpha) 13978c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_ALPHA_VAL(pll), config->alpha); 13988c2ecf20Sopenharmony_ci 13998c2ecf20Sopenharmony_ci if (config->config_ctl_val) 14008c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_CONFIG_CTL(pll), 14018c2ecf20Sopenharmony_ci config->config_ctl_val); 14028c2ecf20Sopenharmony_ci 14038c2ecf20Sopenharmony_ci if (config->config_ctl_hi_val) 14048c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_CONFIG_CTL_U(pll), 14058c2ecf20Sopenharmony_ci config->config_ctl_hi_val); 14068c2ecf20Sopenharmony_ci 14078c2ecf20Sopenharmony_ci if (config->config_ctl_hi1_val) 14088c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_CONFIG_CTL_U1(pll), 14098c2ecf20Sopenharmony_ci config->config_ctl_hi1_val); 14108c2ecf20Sopenharmony_ci 14118c2ecf20Sopenharmony_ci if (config->user_ctl_val) 14128c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_USER_CTL(pll), 14138c2ecf20Sopenharmony_ci config->user_ctl_val); 14148c2ecf20Sopenharmony_ci 14158c2ecf20Sopenharmony_ci if (config->user_ctl_hi_val) 14168c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_USER_CTL_U(pll), 14178c2ecf20Sopenharmony_ci config->user_ctl_hi_val); 14188c2ecf20Sopenharmony_ci 14198c2ecf20Sopenharmony_ci if (config->user_ctl_hi1_val) 14208c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_USER_CTL_U1(pll), 14218c2ecf20Sopenharmony_ci config->user_ctl_hi1_val); 14228c2ecf20Sopenharmony_ci 14238c2ecf20Sopenharmony_ci if (config->test_ctl_val) 14248c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_TEST_CTL(pll), 14258c2ecf20Sopenharmony_ci config->test_ctl_val); 14268c2ecf20Sopenharmony_ci 14278c2ecf20Sopenharmony_ci if (config->test_ctl_hi_val) 14288c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_TEST_CTL_U(pll), 14298c2ecf20Sopenharmony_ci config->test_ctl_hi_val); 14308c2ecf20Sopenharmony_ci 14318c2ecf20Sopenharmony_ci if (config->test_ctl_hi1_val) 14328c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_TEST_CTL_U1(pll), 14338c2ecf20Sopenharmony_ci config->test_ctl_hi1_val); 14348c2ecf20Sopenharmony_ci 14358c2ecf20Sopenharmony_ci regmap_update_bits(regmap, PLL_MODE(pll), PLL_UPDATE_BYPASS, 14368c2ecf20Sopenharmony_ci PLL_UPDATE_BYPASS); 14378c2ecf20Sopenharmony_ci 14388c2ecf20Sopenharmony_ci /* Disable PLL output */ 14398c2ecf20Sopenharmony_ci regmap_update_bits(regmap, PLL_MODE(pll), PLL_OUTCTRL, 0); 14408c2ecf20Sopenharmony_ci 14418c2ecf20Sopenharmony_ci /* Set operation mode to OFF */ 14428c2ecf20Sopenharmony_ci regmap_write(regmap, PLL_OPMODE(pll), PLL_STANDBY); 14438c2ecf20Sopenharmony_ci 14448c2ecf20Sopenharmony_ci /* Place the PLL in STANDBY mode */ 14458c2ecf20Sopenharmony_ci regmap_update_bits(regmap, PLL_MODE(pll), PLL_RESET_N, PLL_RESET_N); 14468c2ecf20Sopenharmony_ci} 14478c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_trion_pll_configure); 14488c2ecf20Sopenharmony_ci 14498c2ecf20Sopenharmony_ci/* 14508c2ecf20Sopenharmony_ci * The TRION PLL requires a power-on self-calibration which happens when the 14518c2ecf20Sopenharmony_ci * PLL comes out of reset. Calibrate in case it is not completed. 14528c2ecf20Sopenharmony_ci */ 14538c2ecf20Sopenharmony_cistatic int __alpha_pll_trion_prepare(struct clk_hw *hw, u32 pcal_done) 14548c2ecf20Sopenharmony_ci{ 14558c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 14568c2ecf20Sopenharmony_ci u32 regval; 14578c2ecf20Sopenharmony_ci int ret; 14588c2ecf20Sopenharmony_ci 14598c2ecf20Sopenharmony_ci /* Return early if calibration is not needed. */ 14608c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_STATUS(pll), ®val); 14618c2ecf20Sopenharmony_ci if (regval & pcal_done) 14628c2ecf20Sopenharmony_ci return 0; 14638c2ecf20Sopenharmony_ci 14648c2ecf20Sopenharmony_ci /* On/off to calibrate */ 14658c2ecf20Sopenharmony_ci ret = clk_trion_pll_enable(hw); 14668c2ecf20Sopenharmony_ci if (!ret) 14678c2ecf20Sopenharmony_ci clk_trion_pll_disable(hw); 14688c2ecf20Sopenharmony_ci 14698c2ecf20Sopenharmony_ci return ret; 14708c2ecf20Sopenharmony_ci} 14718c2ecf20Sopenharmony_ci 14728c2ecf20Sopenharmony_cistatic int alpha_pll_trion_prepare(struct clk_hw *hw) 14738c2ecf20Sopenharmony_ci{ 14748c2ecf20Sopenharmony_ci return __alpha_pll_trion_prepare(hw, TRION_PCAL_DONE); 14758c2ecf20Sopenharmony_ci} 14768c2ecf20Sopenharmony_ci 14778c2ecf20Sopenharmony_cistatic int alpha_pll_lucid_prepare(struct clk_hw *hw) 14788c2ecf20Sopenharmony_ci{ 14798c2ecf20Sopenharmony_ci return __alpha_pll_trion_prepare(hw, LUCID_PCAL_DONE); 14808c2ecf20Sopenharmony_ci} 14818c2ecf20Sopenharmony_ci 14828c2ecf20Sopenharmony_cistatic int alpha_pll_trion_set_rate(struct clk_hw *hw, unsigned long rate, 14838c2ecf20Sopenharmony_ci unsigned long prate) 14848c2ecf20Sopenharmony_ci{ 14858c2ecf20Sopenharmony_ci struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 14868c2ecf20Sopenharmony_ci unsigned long rrate; 14878c2ecf20Sopenharmony_ci u32 regval, l, alpha_width = pll_alpha_width(pll); 14888c2ecf20Sopenharmony_ci u64 a; 14898c2ecf20Sopenharmony_ci int ret; 14908c2ecf20Sopenharmony_ci 14918c2ecf20Sopenharmony_ci rrate = alpha_pll_round_rate(rate, prate, &l, &a, alpha_width); 14928c2ecf20Sopenharmony_ci 14938c2ecf20Sopenharmony_ci /* 14948c2ecf20Sopenharmony_ci * Due to a limited number of bits for fractional rate programming, the 14958c2ecf20Sopenharmony_ci * rounded up rate could be marginally higher than the requested rate. 14968c2ecf20Sopenharmony_ci */ 14978c2ecf20Sopenharmony_ci if (rrate > (rate + PLL_RATE_MARGIN) || rrate < rate) { 14988c2ecf20Sopenharmony_ci pr_err("Call set rate on the PLL with rounded rates!\n"); 14998c2ecf20Sopenharmony_ci return -EINVAL; 15008c2ecf20Sopenharmony_ci } 15018c2ecf20Sopenharmony_ci 15028c2ecf20Sopenharmony_ci regmap_write(pll->clkr.regmap, PLL_L_VAL(pll), l); 15038c2ecf20Sopenharmony_ci regmap_write(pll->clkr.regmap, PLL_ALPHA_VAL(pll), a); 15048c2ecf20Sopenharmony_ci 15058c2ecf20Sopenharmony_ci /* Latch the PLL input */ 15068c2ecf20Sopenharmony_ci ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), 15078c2ecf20Sopenharmony_ci PLL_UPDATE, PLL_UPDATE); 15088c2ecf20Sopenharmony_ci if (ret) 15098c2ecf20Sopenharmony_ci return ret; 15108c2ecf20Sopenharmony_ci 15118c2ecf20Sopenharmony_ci /* Wait for 2 reference cycles before checking the ACK bit. */ 15128c2ecf20Sopenharmony_ci udelay(1); 15138c2ecf20Sopenharmony_ci regmap_read(pll->clkr.regmap, PLL_MODE(pll), ®val); 15148c2ecf20Sopenharmony_ci if (!(regval & ALPHA_PLL_ACK_LATCH)) { 15158c2ecf20Sopenharmony_ci pr_err("Lucid PLL latch failed. Output may be unstable!\n"); 15168c2ecf20Sopenharmony_ci return -EINVAL; 15178c2ecf20Sopenharmony_ci } 15188c2ecf20Sopenharmony_ci 15198c2ecf20Sopenharmony_ci /* Return the latch input to 0 */ 15208c2ecf20Sopenharmony_ci ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), 15218c2ecf20Sopenharmony_ci PLL_UPDATE, 0); 15228c2ecf20Sopenharmony_ci if (ret) 15238c2ecf20Sopenharmony_ci return ret; 15248c2ecf20Sopenharmony_ci 15258c2ecf20Sopenharmony_ci if (clk_hw_is_enabled(hw)) { 15268c2ecf20Sopenharmony_ci ret = wait_for_pll_enable_lock(pll); 15278c2ecf20Sopenharmony_ci if (ret) 15288c2ecf20Sopenharmony_ci return ret; 15298c2ecf20Sopenharmony_ci } 15308c2ecf20Sopenharmony_ci 15318c2ecf20Sopenharmony_ci /* Wait for PLL output to stabilize */ 15328c2ecf20Sopenharmony_ci udelay(100); 15338c2ecf20Sopenharmony_ci return 0; 15348c2ecf20Sopenharmony_ci} 15358c2ecf20Sopenharmony_ci 15368c2ecf20Sopenharmony_ciconst struct clk_ops clk_alpha_pll_trion_ops = { 15378c2ecf20Sopenharmony_ci .prepare = alpha_pll_trion_prepare, 15388c2ecf20Sopenharmony_ci .enable = clk_trion_pll_enable, 15398c2ecf20Sopenharmony_ci .disable = clk_trion_pll_disable, 15408c2ecf20Sopenharmony_ci .is_enabled = clk_trion_pll_is_enabled, 15418c2ecf20Sopenharmony_ci .recalc_rate = clk_trion_pll_recalc_rate, 15428c2ecf20Sopenharmony_ci .round_rate = clk_alpha_pll_round_rate, 15438c2ecf20Sopenharmony_ci .set_rate = alpha_pll_trion_set_rate, 15448c2ecf20Sopenharmony_ci}; 15458c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_alpha_pll_trion_ops); 15468c2ecf20Sopenharmony_ci 15478c2ecf20Sopenharmony_ciconst struct clk_ops clk_alpha_pll_lucid_ops = { 15488c2ecf20Sopenharmony_ci .prepare = alpha_pll_lucid_prepare, 15498c2ecf20Sopenharmony_ci .enable = clk_trion_pll_enable, 15508c2ecf20Sopenharmony_ci .disable = clk_trion_pll_disable, 15518c2ecf20Sopenharmony_ci .is_enabled = clk_trion_pll_is_enabled, 15528c2ecf20Sopenharmony_ci .recalc_rate = clk_trion_pll_recalc_rate, 15538c2ecf20Sopenharmony_ci .round_rate = clk_alpha_pll_round_rate, 15548c2ecf20Sopenharmony_ci .set_rate = alpha_pll_trion_set_rate, 15558c2ecf20Sopenharmony_ci}; 15568c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_alpha_pll_lucid_ops); 15578c2ecf20Sopenharmony_ci 15588c2ecf20Sopenharmony_ciconst struct clk_ops clk_alpha_pll_postdiv_lucid_ops = { 15598c2ecf20Sopenharmony_ci .recalc_rate = clk_alpha_pll_postdiv_fabia_recalc_rate, 15608c2ecf20Sopenharmony_ci .round_rate = clk_alpha_pll_postdiv_fabia_round_rate, 15618c2ecf20Sopenharmony_ci .set_rate = clk_alpha_pll_postdiv_fabia_set_rate, 15628c2ecf20Sopenharmony_ci}; 15638c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(clk_alpha_pll_postdiv_lucid_ops); 1564