blob: 057d173ddb74eae6fd78d7df2ef61af88348e0b0 [file] [log] [blame]
Dhaval Patel83e27fc2013-12-19 14:52:24 -08001/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
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
15
16#include <linux/mdss_io_util.h>
17#include <linux/io.h>
18
19#define MDSS_PLL_REG_W(base, offset, data) \
20 writel_relaxed((data), (base) + (offset))
Jeevan Shriram3287bab2014-08-19 09:07:48 -070021#define MDSS_PLL_REG_R(base, offset) readl_relaxed((base) + (offset))
22
23#define PLL_CALC_DATA(addr0, addr1, data0, data1) \
24 (((data1) << 24) | (((addr1)/4) << 16) | ((data0) << 8) | ((addr0)/4))
25
26#define MDSS_DYN_PLL_REG_W(base, offset, addr0, addr1, data0, data1) \
27 writel_relaxed(PLL_CALC_DATA(addr0, addr1, data0, data1), \
28 (base) + (offset))
Dhaval Patel83e27fc2013-12-19 14:52:24 -080029
30enum {
Padmanabhan Komandurua7b90d12014-03-27 20:03:11 +053031 MDSS_DSI_PLL_LPM,
32 MDSS_DSI_PLL_HPM,
Chandan Uddarajuc2dae7e2014-05-19 12:23:43 -070033 MDSS_DSI_PLL_20NM,
Dhaval Patel83e27fc2013-12-19 14:52:24 -080034 MDSS_EDP_PLL,
35 MDSS_HDMI_PLL,
Casey Piper27b58302014-06-12 21:30:41 -070036 MDSS_HDMI_PLL_20NM,
Dhaval Patel83e27fc2013-12-19 14:52:24 -080037 MDSS_UNKNOWN_PLL,
38};
39
Padmanabhan Komandurua7b90d12014-03-27 20:03:11 +053040enum {
41 MDSS_PLL_TARGET_8974,
Chandan Uddarajuc2dae7e2014-05-19 12:23:43 -070042 MDSS_PLL_TARGET_8994,
Jeykumar Sankarancb2cd1f2014-11-22 10:26:00 -080043 MDSS_PLL_TARGET_8992,
Padmanabhan Komandurua7b90d12014-03-27 20:03:11 +053044 MDSS_PLL_TARGET_8916,
Padmanabhan Komanduru5a8e1ec2014-05-21 12:41:32 +053045 MDSS_PLL_TARGET_8939,
Shivaraj Shettyaaeeb492014-09-26 12:08:01 +053046 MDSS_PLL_TARGET_8909,
Padmanabhan Komandurua7b90d12014-03-27 20:03:11 +053047};
48
Dhaval Patel83e27fc2013-12-19 14:52:24 -080049struct mdss_pll_resources {
50
51 /* Pll specific resources like GPIO, power supply, clocks, etc*/
52 struct dss_module_power mp;
53
Jeevan Shriram6dd6b972014-08-19 22:43:46 -070054 /*
Veera Sundaram Sankaran23775f12014-11-13 14:28:25 -080055 * dsi/edp/hmdi plls' base register, phy, gdsc and dynamic refresh
Jeevan Shriram6dd6b972014-08-19 22:43:46 -070056 * register mapping
57 */
Dhaval Patel83e27fc2013-12-19 14:52:24 -080058 void __iomem *pll_base;
Siddhartha Agrawala91de842014-08-25 10:41:10 -070059 void __iomem *pll_1_base;
Dhaval Patel83e27fc2013-12-19 14:52:24 -080060 void __iomem *phy_base;
Veera Sundaram Sankaran23775f12014-11-13 14:28:25 -080061 void __iomem *gdsc_base;
Jeevan Shriram6dd6b972014-08-19 22:43:46 -070062 void __iomem *dyn_pll_base;
Dhaval Patel83e27fc2013-12-19 14:52:24 -080063
Huaibin Yangc5c6ad42014-11-26 15:18:39 -080064 s64 vco_current_rate;
65 s64 vco_ref_clk_rate;
66
Dhaval Patel83e27fc2013-12-19 14:52:24 -080067 /*
68 * Certain pll's needs to update the same vco rate after resume in
69 * suspend/resume scenario. Cached the vco rate for such plls.
70 */
71 unsigned long vco_cached_rate;
72
73 /* dsi/edp/hmdi pll interface type */
74 u32 pll_interface_type;
75
76 /*
Padmanabhan Komandurua7b90d12014-03-27 20:03:11 +053077 * Target ID. Used in pll_register API for valid target check before
78 * registering the PLL clocks.
79 */
80 u32 target_id;
81
82 /* HW recommended delay during configuration of vco clock rate */
83 u32 vco_delay;
84
Padmanabhan Komanduru99fa0d72014-05-05 19:48:23 +053085 /* Ref-count of the PLL resources */
86 u32 resource_ref_cnt;
87
Padmanabhan Komandurua7b90d12014-03-27 20:03:11 +053088 /*
Dhaval Patel83e27fc2013-12-19 14:52:24 -080089 * Keep track to resource status to avoid updating same status for the
90 * pll from different paths
91 */
92 bool resource_enable;
93
94 /*
95 * Certain plls' do not allow vco rate update if it is on. Keep track of
96 * status for them to turn on/off after set rate success.
97 */
98 bool pll_on;
99
100 /*
101 * handoff_status is true of pll is already enabled by bootloader with
102 * continuous splash enable case. Clock API will call the handoff API
103 * to enable the status. It is disabled if continuous splash
104 * feature is disabled.
105 */
106 bool handoff_resources;
Jeevan Shriram3287bab2014-08-19 09:07:48 -0700107
108 /*
109 * caching the pll trim codes in the case of dynamic refresh
110 */
Huaibin Yangc5c6ad42014-11-26 15:18:39 -0800111 int cache_pll_trim_codes[2];
Jeevan Shriram3287bab2014-08-19 09:07:48 -0700112
113 /*
114 * for maintaining the status of saving trim codes
115 */
116 bool reg_upd;
Siddhartha Agrawala91de842014-08-25 10:41:10 -0700117
118 /*
119 * Notifier callback for MDSS gdsc regulator events
120 */
121 struct notifier_block gdsc_cb;
122
123 /*
124 * Worker function to call PLL off event
125 */
126 struct work_struct pll_off;
127
Siddhartha Agrawal174bbb32014-09-05 10:44:54 -0700128 /*
129 * PLL index if multiple index are available. Eg. in case of
130 * DSI we have 2 plls.
131 */
132 uint32_t index;
133
Jeevan Shriram3287bab2014-08-19 09:07:48 -0700134};
135
136struct mdss_pll_vco_calc {
137 s32 div_frac_start1;
138 s32 div_frac_start2;
139 s32 div_frac_start3;
140 s64 dec_start1;
141 s64 dec_start2;
142 s64 pll_plllock_cmp1;
143 s64 pll_plllock_cmp2;
144 s64 pll_plllock_cmp3;
Dhaval Patel83e27fc2013-12-19 14:52:24 -0800145};
146
Veera Sundaram Sankaran23775f12014-11-13 14:28:25 -0800147static inline bool is_gdsc_disabled(struct mdss_pll_resources *pll_res)
148{
149 if (!pll_res->gdsc_base) {
150 WARN(1, "gdsc_base register is not defined\n");
151 return true;
152 }
153
154 return ((readl_relaxed(pll_res->gdsc_base + 0x4) & BIT(31)) &&
155 (!(readl_relaxed(pll_res->gdsc_base) & BIT(0)))) ? false : true;
156}
157
Dhaval Patel83e27fc2013-12-19 14:52:24 -0800158int mdss_pll_resource_enable(struct mdss_pll_resources *pll_res, bool enable);
159int mdss_pll_util_resource_init(struct platform_device *pdev,
160 struct mdss_pll_resources *pll_res);
161void mdss_pll_util_resource_deinit(struct platform_device *pdev,
162 struct mdss_pll_resources *pll_res);
163void mdss_pll_util_resource_release(struct platform_device *pdev,
164 struct mdss_pll_resources *pll_res);
165int mdss_pll_util_resource_enable(struct mdss_pll_resources *pll_res,
166 bool enable);
167int mdss_pll_util_resource_parse(struct platform_device *pdev,
168 struct mdss_pll_resources *pll_res);
Siddhartha Agrawala91de842014-08-25 10:41:10 -0700169struct dss_vreg *mdss_pll_get_mp_by_reg_name(struct mdss_pll_resources *pll_res
170 , char *name);
Dhaval Patel83e27fc2013-12-19 14:52:24 -0800171#endif