Padmanabhan Komanduru | 95bb8da | 2016-02-29 19:03:12 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2013-2017, The Linux Foundation. All rights reserved. |
Dhaval Patel | 83e27fc | 2013-12-19 14:52:24 -0800 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef __MDSS_PLL_H |
| 14 | #define __MDSS_PLL_H |
Shashank Babu Chinta Venkata | 704b93b | 2017-02-06 15:23:11 -0800 | [diff] [blame] | 15 | #include <linux/sde_io_util.h> |
| 16 | #include <linux/clk-provider.h> |
Dhaval Patel | 83e27fc | 2013-12-19 14:52:24 -0800 | [diff] [blame] | 17 | #include <linux/io.h> |
Shashank Babu Chinta Venkata | 704b93b | 2017-02-06 15:23:11 -0800 | [diff] [blame] | 18 | #include <linux/clk.h> |
| 19 | #include <linux/clkdev.h> |
| 20 | #include <linux/regmap.h> |
| 21 | #include "../clk-regmap.h" |
| 22 | #include "../clk-regmap-divider.h" |
| 23 | #include "../clk-regmap-mux.h" |
| 24 | |
Dhaval Patel | 83e27fc | 2013-12-19 14:52:24 -0800 | [diff] [blame] | 25 | |
| 26 | #define MDSS_PLL_REG_W(base, offset, data) \ |
| 27 | writel_relaxed((data), (base) + (offset)) |
Jeevan Shriram | 3287bab | 2014-08-19 09:07:48 -0700 | [diff] [blame] | 28 | #define MDSS_PLL_REG_R(base, offset) readl_relaxed((base) + (offset)) |
| 29 | |
| 30 | #define PLL_CALC_DATA(addr0, addr1, data0, data1) \ |
Jeevan Shriram | d9bc2bf | 2015-08-23 14:33:59 -0700 | [diff] [blame] | 31 | (((data1) << 24) | ((((addr1) / 4) & 0xFF) << 16) | \ |
| 32 | ((data0) << 8) | (((addr0) / 4) & 0xFF)) |
Jeevan Shriram | 3287bab | 2014-08-19 09:07:48 -0700 | [diff] [blame] | 33 | |
| 34 | #define MDSS_DYN_PLL_REG_W(base, offset, addr0, addr1, data0, data1) \ |
| 35 | writel_relaxed(PLL_CALC_DATA(addr0, addr1, data0, data1), \ |
| 36 | (base) + (offset)) |
Dhaval Patel | 83e27fc | 2013-12-19 14:52:24 -0800 | [diff] [blame] | 37 | |
| 38 | enum { |
Shashank Babu Chinta Venkata | 704b93b | 2017-02-06 15:23:11 -0800 | [diff] [blame] | 39 | MDSS_DSI_PLL_10NM, |
Padmanabhan Komanduru | 6f0508d | 2017-04-28 16:38:57 -0700 | [diff] [blame] | 40 | MDSS_DP_PLL_10NM, |
Dhaval Patel | 83e27fc | 2013-12-19 14:52:24 -0800 | [diff] [blame] | 41 | MDSS_UNKNOWN_PLL, |
| 42 | }; |
| 43 | |
Padmanabhan Komanduru | a7b90d1 | 2014-03-27 20:03:11 +0530 | [diff] [blame] | 44 | enum { |
Kuogee Hsieh | 6c9c1d9 | 2015-01-21 15:56:53 -0800 | [diff] [blame] | 45 | MDSS_PLL_TARGET_8996, |
Padmanabhan Komanduru | a7b90d1 | 2014-03-27 20:03:11 +0530 | [diff] [blame] | 46 | }; |
| 47 | |
Padmanabhan Komanduru | 95bb8da | 2016-02-29 19:03:12 +0530 | [diff] [blame] | 48 | #define DFPS_MAX_NUM_OF_FRAME_RATES 20 |
Jeevan Shriram | d41c1b5 | 2015-07-02 11:34:05 -0700 | [diff] [blame] | 49 | |
| 50 | struct dfps_panel_info { |
| 51 | uint32_t enabled; |
| 52 | uint32_t frame_rate_cnt; |
| 53 | uint32_t frame_rate[DFPS_MAX_NUM_OF_FRAME_RATES]; /* hz */ |
| 54 | }; |
| 55 | |
| 56 | struct dfps_pll_codes { |
| 57 | uint32_t pll_codes_1; |
| 58 | uint32_t pll_codes_2; |
| 59 | }; |
| 60 | |
| 61 | struct dfps_codes_info { |
| 62 | uint32_t is_valid; |
| 63 | uint32_t frame_rate; /* hz */ |
| 64 | uint32_t clk_rate; /* hz */ |
| 65 | struct dfps_pll_codes pll_codes; |
| 66 | }; |
| 67 | |
| 68 | struct dfps_info { |
| 69 | struct dfps_panel_info panel_dfps; |
| 70 | struct dfps_codes_info codes_dfps[DFPS_MAX_NUM_OF_FRAME_RATES]; |
| 71 | void *dfps_fb_base; |
| 72 | }; |
| 73 | |
Dhaval Patel | 83e27fc | 2013-12-19 14:52:24 -0800 | [diff] [blame] | 74 | struct mdss_pll_resources { |
| 75 | |
| 76 | /* Pll specific resources like GPIO, power supply, clocks, etc*/ |
| 77 | struct dss_module_power mp; |
| 78 | |
Jeevan Shriram | 6dd6b97 | 2014-08-19 22:43:46 -0700 | [diff] [blame] | 79 | /* |
Veera Sundaram Sankaran | 23775f1 | 2014-11-13 14:28:25 -0800 | [diff] [blame] | 80 | * dsi/edp/hmdi plls' base register, phy, gdsc and dynamic refresh |
Jeevan Shriram | 6dd6b97 | 2014-08-19 22:43:46 -0700 | [diff] [blame] | 81 | * register mapping |
| 82 | */ |
Dhaval Patel | 83e27fc | 2013-12-19 14:52:24 -0800 | [diff] [blame] | 83 | void __iomem *pll_base; |
| 84 | void __iomem *phy_base; |
Padmanabhan Komanduru | 6f0508d | 2017-04-28 16:38:57 -0700 | [diff] [blame] | 85 | void __iomem *ln_tx0_base; |
| 86 | void __iomem *ln_tx1_base; |
Veera Sundaram Sankaran | 23775f1 | 2014-11-13 14:28:25 -0800 | [diff] [blame] | 87 | void __iomem *gdsc_base; |
Jeevan Shriram | 6dd6b97 | 2014-08-19 22:43:46 -0700 | [diff] [blame] | 88 | void __iomem *dyn_pll_base; |
Dhaval Patel | 83e27fc | 2013-12-19 14:52:24 -0800 | [diff] [blame] | 89 | |
Huaibin Yang | ff625c0 | 2014-12-09 12:38:51 -0800 | [diff] [blame] | 90 | bool is_init_locked; |
Huaibin Yang | c5c6ad4 | 2014-11-26 15:18:39 -0800 | [diff] [blame] | 91 | s64 vco_current_rate; |
Huaibin Yang | ff625c0 | 2014-12-09 12:38:51 -0800 | [diff] [blame] | 92 | s64 vco_locking_rate; |
Huaibin Yang | c5c6ad4 | 2014-11-26 15:18:39 -0800 | [diff] [blame] | 93 | s64 vco_ref_clk_rate; |
| 94 | |
Dhaval Patel | 83e27fc | 2013-12-19 14:52:24 -0800 | [diff] [blame] | 95 | /* |
| 96 | * Certain pll's needs to update the same vco rate after resume in |
| 97 | * suspend/resume scenario. Cached the vco rate for such plls. |
| 98 | */ |
| 99 | unsigned long vco_cached_rate; |
Shashank Babu Chinta Venkata | 2182d62 | 2017-05-08 14:39:40 -0700 | [diff] [blame] | 100 | u32 cached_cfg0; |
| 101 | u32 cached_cfg1; |
Dhaval Patel | 83e27fc | 2013-12-19 14:52:24 -0800 | [diff] [blame] | 102 | |
| 103 | /* dsi/edp/hmdi pll interface type */ |
| 104 | u32 pll_interface_type; |
| 105 | |
| 106 | /* |
Padmanabhan Komanduru | a7b90d1 | 2014-03-27 20:03:11 +0530 | [diff] [blame] | 107 | * Target ID. Used in pll_register API for valid target check before |
| 108 | * registering the PLL clocks. |
| 109 | */ |
| 110 | u32 target_id; |
| 111 | |
| 112 | /* HW recommended delay during configuration of vco clock rate */ |
| 113 | u32 vco_delay; |
| 114 | |
Padmanabhan Komanduru | 99fa0d7 | 2014-05-05 19:48:23 +0530 | [diff] [blame] | 115 | /* Ref-count of the PLL resources */ |
| 116 | u32 resource_ref_cnt; |
| 117 | |
Padmanabhan Komanduru | a7b90d1 | 2014-03-27 20:03:11 +0530 | [diff] [blame] | 118 | /* |
Dhaval Patel | 83e27fc | 2013-12-19 14:52:24 -0800 | [diff] [blame] | 119 | * Keep track to resource status to avoid updating same status for the |
| 120 | * pll from different paths |
| 121 | */ |
| 122 | bool resource_enable; |
| 123 | |
| 124 | /* |
| 125 | * Certain plls' do not allow vco rate update if it is on. Keep track of |
| 126 | * status for them to turn on/off after set rate success. |
| 127 | */ |
| 128 | bool pll_on; |
| 129 | |
| 130 | /* |
| 131 | * handoff_status is true of pll is already enabled by bootloader with |
| 132 | * continuous splash enable case. Clock API will call the handoff API |
| 133 | * to enable the status. It is disabled if continuous splash |
| 134 | * feature is disabled. |
| 135 | */ |
| 136 | bool handoff_resources; |
Jeevan Shriram | 3287bab | 2014-08-19 09:07:48 -0700 | [diff] [blame] | 137 | |
| 138 | /* |
| 139 | * caching the pll trim codes in the case of dynamic refresh |
| 140 | */ |
Huaibin Yang | c5c6ad4 | 2014-11-26 15:18:39 -0800 | [diff] [blame] | 141 | int cache_pll_trim_codes[2]; |
Jeevan Shriram | 3287bab | 2014-08-19 09:07:48 -0700 | [diff] [blame] | 142 | |
| 143 | /* |
| 144 | * for maintaining the status of saving trim codes |
| 145 | */ |
| 146 | bool reg_upd; |
Siddhartha Agrawal | a91de84 | 2014-08-25 10:41:10 -0700 | [diff] [blame] | 147 | |
| 148 | /* |
| 149 | * Notifier callback for MDSS gdsc regulator events |
| 150 | */ |
| 151 | struct notifier_block gdsc_cb; |
| 152 | |
| 153 | /* |
| 154 | * Worker function to call PLL off event |
| 155 | */ |
| 156 | struct work_struct pll_off; |
| 157 | |
Siddhartha Agrawal | 174bbb3 | 2014-09-05 10:44:54 -0700 | [diff] [blame] | 158 | /* |
| 159 | * PLL index if multiple index are available. Eg. in case of |
| 160 | * DSI we have 2 plls. |
| 161 | */ |
| 162 | uint32_t index; |
| 163 | |
Kuogee Hsieh | 1d23056 | 2015-05-29 09:38:54 -0700 | [diff] [blame] | 164 | bool ssc_en; /* share pll with master */ |
| 165 | bool ssc_center; /* default is down spread */ |
Padmanabhan Komanduru | 4953815 | 2015-12-16 17:35:13 +0530 | [diff] [blame] | 166 | u32 ssc_freq; |
| 167 | u32 ssc_ppm; |
Kuogee Hsieh | 1d23056 | 2015-05-29 09:38:54 -0700 | [diff] [blame] | 168 | |
Kuogee Hsieh | df49854 | 2015-02-04 14:26:07 -0800 | [diff] [blame] | 169 | struct mdss_pll_resources *slave; |
| 170 | |
Dhaval Patel | 0d49d47 | 2015-04-27 10:37:21 -0700 | [diff] [blame] | 171 | /* |
| 172 | * target pll revision information |
| 173 | */ |
| 174 | int revision; |
| 175 | |
Kuogee Hsieh | 6c9c1d9 | 2015-01-21 15:56:53 -0800 | [diff] [blame] | 176 | void *priv; |
Jeevan Shriram | d41c1b5 | 2015-07-02 11:34:05 -0700 | [diff] [blame] | 177 | |
| 178 | /* |
| 179 | * dynamic refresh pll codes stored in this structure |
| 180 | */ |
| 181 | struct dfps_info *dfps; |
| 182 | |
Jeevan Shriram | 3287bab | 2014-08-19 09:07:48 -0700 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | struct mdss_pll_vco_calc { |
| 186 | s32 div_frac_start1; |
| 187 | s32 div_frac_start2; |
| 188 | s32 div_frac_start3; |
| 189 | s64 dec_start1; |
| 190 | s64 dec_start2; |
| 191 | s64 pll_plllock_cmp1; |
| 192 | s64 pll_plllock_cmp2; |
| 193 | s64 pll_plllock_cmp3; |
Dhaval Patel | 83e27fc | 2013-12-19 14:52:24 -0800 | [diff] [blame] | 194 | }; |
| 195 | |
Veera Sundaram Sankaran | 23775f1 | 2014-11-13 14:28:25 -0800 | [diff] [blame] | 196 | static inline bool is_gdsc_disabled(struct mdss_pll_resources *pll_res) |
| 197 | { |
| 198 | if (!pll_res->gdsc_base) { |
| 199 | WARN(1, "gdsc_base register is not defined\n"); |
| 200 | return true; |
| 201 | } |
Shashank Babu Chinta Venkata | 4302e8f | 2017-04-17 13:46:36 -0700 | [diff] [blame] | 202 | return readl_relaxed(pll_res->gdsc_base) & BIT(31) ? false : true; |
Veera Sundaram Sankaran | 23775f1 | 2014-11-13 14:28:25 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Shashank Babu Chinta Venkata | 704b93b | 2017-02-06 15:23:11 -0800 | [diff] [blame] | 205 | static inline int mdss_pll_div_prepare(struct clk_hw *hw) |
Chandan Uddaraju | 16128f3 | 2016-02-22 16:43:23 -0800 | [diff] [blame] | 206 | { |
Shashank Babu Chinta Venkata | 704b93b | 2017-02-06 15:23:11 -0800 | [diff] [blame] | 207 | struct clk_hw *parent_hw = clk_hw_get_parent(hw); |
Chandan Uddaraju | 16128f3 | 2016-02-22 16:43:23 -0800 | [diff] [blame] | 208 | /* Restore the divider's value */ |
Shashank Babu Chinta Venkata | 704b93b | 2017-02-06 15:23:11 -0800 | [diff] [blame] | 209 | return hw->init->ops->set_rate(hw, clk_hw_get_rate(hw), |
| 210 | clk_hw_get_rate(parent_hw)); |
Chandan Uddaraju | 16128f3 | 2016-02-22 16:43:23 -0800 | [diff] [blame] | 211 | } |
| 212 | |
Shashank Babu Chinta Venkata | 704b93b | 2017-02-06 15:23:11 -0800 | [diff] [blame] | 213 | static inline int mdss_set_mux_sel(void *context, unsigned int reg, |
| 214 | unsigned int val) |
Chandan Uddaraju | 16128f3 | 2016-02-22 16:43:23 -0800 | [diff] [blame] | 215 | { |
| 216 | return 0; |
| 217 | } |
| 218 | |
Shashank Babu Chinta Venkata | 704b93b | 2017-02-06 15:23:11 -0800 | [diff] [blame] | 219 | static inline int mdss_get_mux_sel(void *context, unsigned int reg, |
| 220 | unsigned int *val) |
Chandan Uddaraju | 16128f3 | 2016-02-22 16:43:23 -0800 | [diff] [blame] | 221 | { |
Shashank Babu Chinta Venkata | 704b93b | 2017-02-06 15:23:11 -0800 | [diff] [blame] | 222 | *val = 0; |
Chandan Uddaraju | 16128f3 | 2016-02-22 16:43:23 -0800 | [diff] [blame] | 223 | return 0; |
| 224 | } |
| 225 | |
Dhaval Patel | 83e27fc | 2013-12-19 14:52:24 -0800 | [diff] [blame] | 226 | int mdss_pll_resource_enable(struct mdss_pll_resources *pll_res, bool enable); |
| 227 | int mdss_pll_util_resource_init(struct platform_device *pdev, |
| 228 | struct mdss_pll_resources *pll_res); |
| 229 | void mdss_pll_util_resource_deinit(struct platform_device *pdev, |
| 230 | struct mdss_pll_resources *pll_res); |
| 231 | void mdss_pll_util_resource_release(struct platform_device *pdev, |
| 232 | struct mdss_pll_resources *pll_res); |
| 233 | int mdss_pll_util_resource_enable(struct mdss_pll_resources *pll_res, |
| 234 | bool enable); |
| 235 | int mdss_pll_util_resource_parse(struct platform_device *pdev, |
| 236 | struct mdss_pll_resources *pll_res); |
Siddhartha Agrawal | a91de84 | 2014-08-25 10:41:10 -0700 | [diff] [blame] | 237 | struct dss_vreg *mdss_pll_get_mp_by_reg_name(struct mdss_pll_resources *pll_res |
| 238 | , char *name); |
Dhaval Patel | 83e27fc | 2013-12-19 14:52:24 -0800 | [diff] [blame] | 239 | #endif |