blob: 4ca23794c2d98044a25b6c6db2102ad5455c8327 [file] [log] [blame]
Vishnuvardhan Prodduturiaf59b912015-10-20 21:14:27 +05301/* Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
Aparna Mallavarapu083766b2014-07-21 21:04:48 +05302
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <bits.h>
30#include <debug.h>
31#include <reg.h>
32
33/* base addresses */
34#define QPNP_WLED_CTRL_BASE 0xd800
35#define QPNP_WLED_SINK_BASE 0xd900
36#define QPNP_WLED_IBB_BASE 0xdc00
37#define QPNP_WLED_LAB_BASE 0xde00
38
39/* ctrl registers */
40#define QPNP_WLED_EN_REG(b) (b + 0x46)
41#define QPNP_WLED_FDBK_OP_REG(b) (b + 0x48)
42#define QPNP_WLED_VREF_REG(b) (b + 0x49)
43#define QPNP_WLED_BOOST_DUTY_REG(b) (b + 0x4B)
44#define QPNP_WLED_SWITCH_FREQ_REG(b) (b + 0x4C)
45#define QPNP_WLED_OVP_REG(b) (b + 0x4D)
46#define QPNP_WLED_ILIM_REG(b) (b + 0x4E)
Vishnuvardhan Prodduturiaf59b912015-10-20 21:14:27 +053047#define QPNP_WLED_VLOOP_COMP_RES(b) (b + 0x55)
48#define QPNP_WLED_VLOOP_COMP_GM(b) (b + 0x56)
49#define QPNP_WLED_PSM_CTRL(b) (b + 0x5B)
Parth Dixite46b1a22016-06-06 19:16:20 +053050#define QPNP_WLED_TEST4(b) (b + 0xE5)
51#define QPNP_WLED_CTRL_SPARE_REG(b) (b + 0xDF)
52#define QPNP_WLED_REF_7P7_TRIM_REG(b) (b + 0xF2)
Aparna Mallavarapu083766b2014-07-21 21:04:48 +053053
Parth Dixite46b1a22016-06-06 19:16:20 +053054#define QPNP_WLED_7P7_TRIM_MASK 0xF
Aparna Mallavarapu083766b2014-07-21 21:04:48 +053055#define QPNP_WLED_EN_MASK 0x7F
56#define QPNP_WLED_EN_SHIFT 7
57#define QPNP_WLED_FDBK_OP_MASK 0xF8
58#define QPNP_WLED_VREF_MASK 0xF0
59#define QPNP_WLED_VREF_STEP_MV 25
60#define QPNP_WLED_VREF_MIN_MV 300
61#define QPNP_WLED_VREF_MAX_MV 675
62#define QPNP_WLED_DFLT_VREF_MV 350
63#define QPNP_WLED_ILIM_MASK 0xF8
64#define QPNP_WLED_ILIM_MIN_MA 105
65#define QPNP_WLED_ILIM_MAX_MA 1980
66#define QPNP_WLED_ILIM_STEP_MA 280
67#define QPNP_WLED_DFLT_ILIM_MA 980
Alex Sarraf9bd81b92015-05-20 15:59:32 -070068#define QPNP_WLED_ILIM_OVERWRITE 0x80
Aparna Mallavarapu083766b2014-07-21 21:04:48 +053069#define QPNP_WLED_BOOST_DUTY_MASK 0xFC
70#define QPNP_WLED_BOOST_DUTY_STEP_NS 52
71#define QPNP_WLED_BOOST_DUTY_MIN_NS 26
72#define QPNP_WLED_BOOST_DUTY_MAX_NS 156
73#define QPNP_WLED_DEF_BOOST_DUTY_NS 104
74#define QPNP_WLED_DFLT_HYB_THRES 625
75#define QPNP_WLED_SWITCH_FREQ_MASK 0xF0
76#define QPNP_WLED_SWITCH_FREQ_800_KHZ 800
77#define QPNP_WLED_SWITCH_FREQ_1600_KHZ 1600
78#define QPNP_WLED_OVP_MASK 0xFC
79#define QPNP_WLED_OVP_17800_MV 17800
80#define QPNP_WLED_OVP_19400_MV 19400
81#define QPNP_WLED_OVP_29500_MV 29500
82#define QPNP_WLED_OVP_31000_MV 31000
83
84/* sink registers */
85#define QPNP_WLED_CURR_SINK_REG(b) (b + 0x46)
86#define QPNP_WLED_SYNC_REG(b) (b + 0x47)
87#define QPNP_WLED_MOD_REG(b) (b + 0x4A)
88#define QPNP_WLED_HYB_THRES_REG(b) (b + 0x4B)
89#define QPNP_WLED_MOD_EN_REG(b, n) (b + 0x50 + (n * 0x10))
90#define QPNP_WLED_SYNC_DLY_REG(b, n) (QPNP_WLED_MOD_EN_REG(b, n) + 0x01)
91#define QPNP_WLED_FS_CURR_REG(b, n) (QPNP_WLED_MOD_EN_REG(b, n) + 0x02)
92#define QPNP_WLED_CABC_REG(b, n) (QPNP_WLED_MOD_EN_REG(b, n) + 0x06)
93#define QPNP_WLED_BRIGHT_LSB_REG(b, n) (QPNP_WLED_MOD_EN_REG(b, n) + 0x07)
94#define QPNP_WLED_BRIGHT_MSB_REG(b, n) (QPNP_WLED_MOD_EN_REG(b, n) + 0x08)
95
96#define QPNP_WLED_MOD_FREQ_1200_KHZ 1200
97#define QPNP_WLED_MOD_FREQ_2400_KHZ 2400
98#define QPNP_WLED_MOD_FREQ_9600_KHZ 9600
99#define QPNP_WLED_MOD_FREQ_19200_KHZ 19200
100#define QPNP_WLED_MOD_FREQ_MASK 0x3F
101#define QPNP_WLED_MOD_FREQ_SHIFT 6
102#define QPNP_WLED_PHASE_STAG_MASK 0xDF
103#define QPNP_WLED_PHASE_STAG_SHIFT 5
104#define QPNP_WLED_DIM_RES_MASK 0xFD
105#define QPNP_WLED_DIM_RES_SHIFT 1
106#define QPNP_WLED_DIM_HYB_MASK 0xFB
107#define QPNP_WLED_DIM_HYB_SHIFT 2
108#define QPNP_WLED_DIM_ANA_MASK 0xFE
109#define QPNP_WLED_HYB_THRES_MASK 0xF8
110#define QPNP_WLED_HYB_THRES_MIN 78
111#define QPNP_WLED_DEF_HYB_THRES 625
112#define QPNP_WLED_HYB_THRES_MAX 10000
113#define QPNP_WLED_MOD_EN_MASK 0x7F
114#define QPNP_WLED_MOD_EN_SHFT 7
115#define QPNP_WLED_MOD_EN 1
116#define QPNP_WLED_SYNC_DLY_MASK 0xF8
117#define QPNP_WLED_SYNC_DLY_MIN_US 0
118#define QPNP_WLED_SYNC_DLY_MAX_US 1400
119#define QPNP_WLED_SYNC_DLY_STEP_US 200
120#define QPNP_WLED_DEF_SYNC_DLY_US 400
121#define QPNP_WLED_FS_CURR_MASK 0xF0
122#define QPNP_WLED_FS_CURR_MIN_UA 0
123#define QPNP_WLED_FS_CURR_MAX_UA 30000
124#define QPNP_WLED_FS_CURR_STEP_UA 2500
125#define QPNP_WLED_CABC_MASK 0x7F
126#define QPNP_WLED_CABC_SHIFT 7
127#define QPNP_WLED_CURR_SINK_SHIFT 4
128#define QPNP_WLED_BRIGHT_LSB_MASK 0xFF
129#define QPNP_WLED_BRIGHT_MSB_SHIFT 8
130#define QPNP_WLED_BRIGHT_MSB_MASK 0x0F
131#define QPNP_WLED_SYNC 0x0F
132#define QPNP_WLED_SYNC_RESET 0x00
133
134#define QPNP_WLED_SWITCH_FREQ_800_KHZ_CODE 0x0B
135#define QPNP_WLED_SWITCH_FREQ_1600_KHZ_CODE 0x05
136
137#define QPNP_WLED_DISP_SEL_REG(b) (b + 0x44)
138#define QPNP_WLED_MODULE_RDY_REG(b) (b + 0x45)
139#define QPNP_WLED_MODULE_EN_REG(b) (b + 0x46)
140#define QPNP_WLED_MODULE_RDY_MASK 0x7F
141#define QPNP_WLED_MODULE_RDY_SHIFT 7
142#define QPNP_WLED_MODULE_EN_MASK 0x7F
143#define QPNP_WLED_MODULE_EN_SHIFT 7
Vishnuvardhan Prodduturiaf59b912015-10-20 21:14:27 +0530144#define QPNP_IBB_SWIRE_RDY_MASK 0x40
145#define QPNP_IBB_SWIRE_RDY_SHIFT 6
146#define QPNP_IBB_MODULE_EN_MASK 0x80
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530147#define QPNP_WLED_DISP_SEL_MASK 0x7F
148#define QPNP_WLED_DISP_SEL_SHIFT 7
149
150#define QPNP_WLED_IBB_BIAS_REG(b) (b + 0x58)
151#define QPNP_WLED_IBB_BIAS_MASK 0x7F
152#define QPNP_WLED_IBB_BIAS_SHIFT 7
153#define QPNP_WLED_IBB_PWRUP_DLY_MASK 0xCF
154#define QPNP_WLED_IBB_PWRUP_DLY_SHIFT 4
Aparna Mallavarapua42de902014-12-08 17:25:44 -0800155#define QPNP_WLED_IBB_PWRUP_DLY_MIN_MS 0
156#define QPNP_WLED_IBB_PWRUP_DLY_MAX_MS 3
157#define QPNP_WLED_IBB_PWRDN_DLY_MIN_MS 0
158#define QPNP_WLED_IBB_PWRDN_DLY_MAX_MS 3
159#define IBB_LAB_VREG_STEP_SIZE 100000
160#define QPNP_LABIBB_OUTPUT_VOLTAGE 0x41
Vishnuvardhan Prodduturiaf59b912015-10-20 21:14:27 +0530161#define QPNP_LABIBB_PS_CTL 0x50
Aparna Mallavarapua42de902014-12-08 17:25:44 -0800162#define QPNP_LAB_OUTPUT_OVERRIDE_EN BIT(7)
163#define QPNP_LAB_SET_VOLTAGE_MASK (BIT(4) - 1)
164#define QPNP_IBB_SET_VOLTAGE_MASK (BIT(6) - 1)
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530165#define QPNP_WLED_LAB_IBB_RDY_REG(b) (b + 0x49)
166#define QPNP_WLED_LAB_FAST_PC_REG(b) (b + 0x5E)
167#define QPNP_WLED_LAB_FAST_PC_MASK 0xFB
168#define QPNP_WLED_LAB_START_DLY_US 8
169#define QPNP_WLED_LAB_FAST_PC_SHIFT 2
wufeng.jiangb1008482016-06-14 10:41:39 +0800170#define QPNP_WLED_PRECHARGE_MASK 0xFC
171#define QPNP_WLED_PRECHARGE_US200 0x00
172#define QPNP_WLED_PRECHARGE_US300 0x01
173#define QPNP_WLED_PRECHARGE_US400 0x02
174#define QPNP_WLED_PRECHARGE_US500 0x03
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530175
176#define QPNP_WLED_SEC_ACCESS_REG(b) (b + 0xD0)
177#define QPNP_WLED_SEC_UNLOCK 0xA5
178
Parth Dixit36ee8b72016-02-11 12:01:15 +0530179#if TARGET_MAX_WLED_STRINGS
180#define QPNP_WLED_MAX_STRINGS TARGET_MAX_WLED_STRINGS
181#else
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530182#define QPNP_WLED_MAX_STRINGS 4
Parth Dixit36ee8b72016-02-11 12:01:15 +0530183#endif
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530184#define WLED_MAX_LEVEL_511 511
185#define WLED_MAX_LEVEL_4095 4095
186#define QPNP_WLED_RAMP_DLY_MS 20
187#define QPNP_WLED_TRIGGER_NONE "none"
188#define QPNP_WLED_STR_SIZE 20
189#define QPNP_WLED_MIN_MSLEEP 20
190#define QPNP_WLED_MAX_BR_LEVEL 1638
191
Channagoud Kadabif5f0ded2015-02-25 13:42:18 -0800192#define PWRDN_DLY2_MASK 0x3
193
Parth Dixite46b1a22016-06-06 19:16:20 +0530194#define NUM_SUPPORTED_AVDD_VOLTAGES 6
195
196/* Supported values 7900, 7600, 7300, 6400, 6100, 5800 */
197#if TARGET_QPNP_WLED_AVDD_DEFAULT_VOLTAGE_MV
198#define QPNP_WLED_AVDD_DEFAULT_VOLTAGE_MV TARGET_QPNP_WLED_AVDD_DEFAULT_VOLTAGE_MV
199#else
200#define QPNP_WLED_AVDD_DEFAULT_VOLTAGE_MV 7600
201#endif
202
203#define QPNP_WLED_AVDD_MIN_TRIM_VALUE 0x0
204#define QPNP_WLED_AVDD_MAX_TRIM_VALUE 0xF
205#define QPNP_WLED_AVDD_SET_BIT BIT(4)
206
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530207/* output feedback mode */
208enum qpnp_wled_fdbk_op {
209 QPNP_WLED_FDBK_AUTO,
210 QPNP_WLED_FDBK_WLED1,
211 QPNP_WLED_FDBK_WLED2,
212 QPNP_WLED_FDBK_WLED3,
213 QPNP_WLED_FDBK_WLED4,
214};
215
216/* dimming modes */
217enum qpnp_wled_dim_mode {
218 QPNP_WLED_DIM_ANALOG,
219 QPNP_WLED_DIM_DIGITAL,
220 QPNP_WLED_DIM_HYBRID,
221};
222
223/* dimming curve shapes */
224enum qpnp_wled_dim_shape {
225 QPNP_WLED_DIM_SHAPE_LOG,
226 QPNP_WLED_DIM_SHAPE_LINEAR,
227 QPNP_WLED_DIM_SHAPE_SQUARE,
228};
229
230
231/**
232 * qpnp_wled - wed data structure
233 * @ fdbk_op - output feedback mode
234 * @ dim_mode - dimming mode
235 * @ dim_shape - dimming curve shape
236 * @ ctrl_base - base address for wled ctrl
237 * @ sink_base - base address for wled sink
238 * @ ibb_base - base address for IBB(Inverting Buck Boost)
239 * @ lab_base - base address for LAB(LCD/AMOLED Boost)
240 * @ mod_freq_khz - modulator frequency in KHZ
241 * @ hyb_thres - threshold for hybrid dimming
242 * @ sync_dly_us - sync delay in us
243 * @ vref_mv - ref voltage in mv
244 * @ switch_freq_khz - switching frequency in KHZ
245 * @ ovp_mv - over voltage protection in mv
246 * @ ilim_ma - current limiter in ma
247 * @ boost_duty_ns - boost duty cycle in ns
248 * @ fs_curr_ua - full scale current in ua
249 * @ ramp_ms - delay between ramp steps in ms
250 * @ ramp_step - ramp step size
251 * @ strings - supported list of strings
252 * @ num_strings - number of strings
253 * @ en_9b_dim_res - enable or disable 9bit dimming
254 * @ en_phase_stag - enable or disable phase staggering
255 * @ en_cabc - enable or disable cabc
256 * @ disp_type_amoled - type of display: LCD/AMOLED
257 * @ ibb_bias_active - activate display bias
258 * @ lab_fast_precharge - fast/slow precharge
259 */
260struct qpnp_wled {
261 enum qpnp_wled_fdbk_op fdbk_op;
262 enum qpnp_wled_dim_mode dim_mode;
263 enum qpnp_wled_dim_shape dim_shape;
264 uint16_t ctrl_base;
265 uint16_t sink_base;
266 uint16_t ibb_base;
267 uint16_t lab_base;
268 uint16_t mod_freq_khz;
269 uint16_t hyb_thres;
270 uint16_t sync_dly_us;
271 uint16_t vref_mv;
272 uint16_t switch_freq_khz;
273 uint16_t ovp_mv;
274 uint16_t ilim_ma;
275 uint16_t boost_duty_ns;
276 uint16_t fs_curr_ua;
277 uint16_t ibb_pwrup_dly_ms;
Aparna Mallavarapua42de902014-12-08 17:25:44 -0800278 uint16_t ibb_pwrdn_dly_ms;
279 uint16_t ibb_discharge_en;
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530280 uint16_t ramp_ms;
281 uint16_t ramp_step;
282 uint8_t strings[QPNP_WLED_MAX_STRINGS];
283 uint8_t num_strings;
284 bool en_9b_dim_res;
285 bool en_phase_stag;
286 bool en_cabc;
287 bool disp_type_amoled;
288 bool ibb_bias_active;
289 bool lab_fast_precharge;
wufeng.jiangb1008482016-06-14 10:41:39 +0800290 uint8_t lab_max_precharge_time;
Aparna Mallavarapua42de902014-12-08 17:25:44 -0800291 uint32_t lab_min_volt;
292 uint32_t lab_max_volt;
293 uint32_t ibb_min_volt;
294 uint32_t ibb_max_volt;
295 uint32_t ibb_init_volt;
296 uint32_t lab_init_volt;
Vishnuvardhan Prodduturiaf59b912015-10-20 21:14:27 +0530297 bool lab_ibb_swire_control;
298 bool wled_avdd_control;
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530299};
300
Aparna Mallavarapua42de902014-12-08 17:25:44 -0800301struct qpnp_wled_config_data {
302 bool display_type;
303 char pwr_up_delay;
304 char pwr_down_delay;
305 char ibb_discharge_en;
306 uint32_t lab_min_volt;
307 uint32_t lab_max_volt;
308 uint32_t ibb_min_volt;
309 uint32_t ibb_max_volt;
310 uint32_t ibb_init_volt;
311 uint32_t lab_init_volt;
Vishnuvardhan Prodduturiaf59b912015-10-20 21:14:27 +0530312 bool lab_ibb_swire_control;
313 bool wled_avdd_control;
Aparna Mallavarapua42de902014-12-08 17:25:44 -0800314};
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530315/* WLED Initial Setup */
Aparna Mallavarapua42de902014-12-08 17:25:44 -0800316int qpnp_wled_init(struct qpnp_wled_config_data *config);
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530317
318/* Enable IBB */
Aparna Mallavarapua42de902014-12-08 17:25:44 -0800319int qpnp_ibb_enable(bool state);
vijay kumar7b890ab2014-09-23 11:09:13 +0530320void qpnp_wled_enable_backlight(int enable);