1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (c) 2017 Chen-Yu Tsai. All rights reserved. 4 */ 5 6 #ifndef _CCU_SDM_H 7 #define _CCU_SDM_H 8 9 #include "ccu.h" 10 #include "ccu_common.h" 11 12 struct ccu_sdm_setting 13 { 14 unsigned long rate; 15 16 /* 17 * XXX We don't know what the step and bottom register fields 18 * mean. Just copy the whole register value from the vendor 19 * kernel for now. 20 */ 21 u32 pattern; 22 23 /* 24 * M and N factors here should be the values used in 25 * calculation, not the raw values written to registers 26 */ 27 u32 m; 28 u32 n; 29 }; 30 31 struct ccu_sdm_internal 32 { 33 struct ccu_sdm_setting *table; 34 u32 table_size; 35 /* early SoCs don't have the SDM enable bit in the PLL register */ 36 u32 enable; 37 /* second enable bit in tuning register */ 38 u32 tuning_enable; 39 u32 tuning_reg; 40 }; 41 42 #define _SUNXI_CCU_SDM(_table, _enable, \ 43 _reg, _reg_enable) \ 44 { \ 45 .table = _table, \ 46 .table_size = ARRAY_SIZE(_table), \ 47 .enable = _enable, \ 48 .tuning_enable = _reg_enable, \ 49 .tuning_reg = _reg, \ 50 } 51 52 bool ccu_sdm_helper_is_enabled(struct ccu_common *common, 53 struct ccu_sdm_internal *sdm); 54 void ccu_sdm_helper_enable(struct ccu_common *common, 55 struct ccu_sdm_internal *sdm, 56 unsigned long rate); 57 void ccu_sdm_helper_disable(struct ccu_common *common, 58 struct ccu_sdm_internal *sdm); 59 60 bool ccu_sdm_helper_has_rate(struct ccu_common *common, 61 struct ccu_sdm_internal *sdm, 62 unsigned long rate); 63 64 unsigned long ccu_sdm_helper_read_rate(struct ccu_common *common, 65 struct ccu_sdm_internal *sdm, 66 u32 m, u32 n); 67 68 int ccu_sdm_helper_get_factors(struct ccu_common *common, 69 struct ccu_sdm_internal *sdm, 70 unsigned long rate, 71 unsigned long *m, unsigned long *n); 72 73 #endif 74