blob: a71b96db80d7b7e3a030844c61f6c317feec041f [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)
Mayank Grover0b0ec802016-11-04 11:47:46 +053049#define QPNP_WLED_PSM_EN(b) (b + 0x5A)
Vishnuvardhan Prodduturiaf59b912015-10-20 21:14:27 +053050#define QPNP_WLED_PSM_CTRL(b) (b + 0x5B)
Parth Dixite46b1a22016-06-06 19:16:20 +053051#define QPNP_WLED_TEST4(b) (b + 0xE5)
52#define QPNP_WLED_CTRL_SPARE_REG(b) (b + 0xDF)
53#define QPNP_WLED_REF_7P7_TRIM_REG(b) (b + 0xF2)
Aparna Mallavarapu083766b2014-07-21 21:04:48 +053054
Parth Dixite46b1a22016-06-06 19:16:20 +053055#define QPNP_WLED_7P7_TRIM_MASK 0xF
Aparna Mallavarapu083766b2014-07-21 21:04:48 +053056#define QPNP_WLED_EN_MASK 0x7F
57#define QPNP_WLED_EN_SHIFT 7
58#define QPNP_WLED_FDBK_OP_MASK 0xF8
59#define QPNP_WLED_VREF_MASK 0xF0
60#define QPNP_WLED_VREF_STEP_MV 25
61#define QPNP_WLED_VREF_MIN_MV 300
62#define QPNP_WLED_VREF_MAX_MV 675
63#define QPNP_WLED_DFLT_VREF_MV 350
64#define QPNP_WLED_ILIM_MASK 0xF8
65#define QPNP_WLED_ILIM_MIN_MA 105
66#define QPNP_WLED_ILIM_MAX_MA 1980
67#define QPNP_WLED_ILIM_STEP_MA 280
68#define QPNP_WLED_DFLT_ILIM_MA 980
Alex Sarraf9bd81b92015-05-20 15:59:32 -070069#define QPNP_WLED_ILIM_OVERWRITE 0x80
Aparna Mallavarapu083766b2014-07-21 21:04:48 +053070#define QPNP_WLED_BOOST_DUTY_MASK 0xFC
71#define QPNP_WLED_BOOST_DUTY_STEP_NS 52
72#define QPNP_WLED_BOOST_DUTY_MIN_NS 26
73#define QPNP_WLED_BOOST_DUTY_MAX_NS 156
74#define QPNP_WLED_DEF_BOOST_DUTY_NS 104
75#define QPNP_WLED_DFLT_HYB_THRES 625
76#define QPNP_WLED_SWITCH_FREQ_MASK 0xF0
77#define QPNP_WLED_SWITCH_FREQ_800_KHZ 800
78#define QPNP_WLED_SWITCH_FREQ_1600_KHZ 1600
79#define QPNP_WLED_OVP_MASK 0xFC
80#define QPNP_WLED_OVP_17800_MV 17800
81#define QPNP_WLED_OVP_19400_MV 19400
82#define QPNP_WLED_OVP_29500_MV 29500
83#define QPNP_WLED_OVP_31000_MV 31000
84
85/* sink registers */
86#define QPNP_WLED_CURR_SINK_REG(b) (b + 0x46)
87#define QPNP_WLED_SYNC_REG(b) (b + 0x47)
88#define QPNP_WLED_MOD_REG(b) (b + 0x4A)
89#define QPNP_WLED_HYB_THRES_REG(b) (b + 0x4B)
90#define QPNP_WLED_MOD_EN_REG(b, n) (b + 0x50 + (n * 0x10))
91#define QPNP_WLED_SYNC_DLY_REG(b, n) (QPNP_WLED_MOD_EN_REG(b, n) + 0x01)
92#define QPNP_WLED_FS_CURR_REG(b, n) (QPNP_WLED_MOD_EN_REG(b, n) + 0x02)
93#define QPNP_WLED_CABC_REG(b, n) (QPNP_WLED_MOD_EN_REG(b, n) + 0x06)
94#define QPNP_WLED_BRIGHT_LSB_REG(b, n) (QPNP_WLED_MOD_EN_REG(b, n) + 0x07)
95#define QPNP_WLED_BRIGHT_MSB_REG(b, n) (QPNP_WLED_MOD_EN_REG(b, n) + 0x08)
96
97#define QPNP_WLED_MOD_FREQ_1200_KHZ 1200
98#define QPNP_WLED_MOD_FREQ_2400_KHZ 2400
99#define QPNP_WLED_MOD_FREQ_9600_KHZ 9600
100#define QPNP_WLED_MOD_FREQ_19200_KHZ 19200
101#define QPNP_WLED_MOD_FREQ_MASK 0x3F
102#define QPNP_WLED_MOD_FREQ_SHIFT 6
103#define QPNP_WLED_PHASE_STAG_MASK 0xDF
104#define QPNP_WLED_PHASE_STAG_SHIFT 5
105#define QPNP_WLED_DIM_RES_MASK 0xFD
106#define QPNP_WLED_DIM_RES_SHIFT 1
107#define QPNP_WLED_DIM_HYB_MASK 0xFB
108#define QPNP_WLED_DIM_HYB_SHIFT 2
109#define QPNP_WLED_DIM_ANA_MASK 0xFE
110#define QPNP_WLED_HYB_THRES_MASK 0xF8
111#define QPNP_WLED_HYB_THRES_MIN 78
112#define QPNP_WLED_DEF_HYB_THRES 625
113#define QPNP_WLED_HYB_THRES_MAX 10000
114#define QPNP_WLED_MOD_EN_MASK 0x7F
115#define QPNP_WLED_MOD_EN_SHFT 7
116#define QPNP_WLED_MOD_EN 1
117#define QPNP_WLED_SYNC_DLY_MASK 0xF8
118#define QPNP_WLED_SYNC_DLY_MIN_US 0
119#define QPNP_WLED_SYNC_DLY_MAX_US 1400
120#define QPNP_WLED_SYNC_DLY_STEP_US 200
121#define QPNP_WLED_DEF_SYNC_DLY_US 400
122#define QPNP_WLED_FS_CURR_MASK 0xF0
123#define QPNP_WLED_FS_CURR_MIN_UA 0
124#define QPNP_WLED_FS_CURR_MAX_UA 30000
125#define QPNP_WLED_FS_CURR_STEP_UA 2500
126#define QPNP_WLED_CABC_MASK 0x7F
127#define QPNP_WLED_CABC_SHIFT 7
128#define QPNP_WLED_CURR_SINK_SHIFT 4
129#define QPNP_WLED_BRIGHT_LSB_MASK 0xFF
130#define QPNP_WLED_BRIGHT_MSB_SHIFT 8
131#define QPNP_WLED_BRIGHT_MSB_MASK 0x0F
132#define QPNP_WLED_SYNC 0x0F
133#define QPNP_WLED_SYNC_RESET 0x00
134
135#define QPNP_WLED_SWITCH_FREQ_800_KHZ_CODE 0x0B
136#define QPNP_WLED_SWITCH_FREQ_1600_KHZ_CODE 0x05
137
138#define QPNP_WLED_DISP_SEL_REG(b) (b + 0x44)
139#define QPNP_WLED_MODULE_RDY_REG(b) (b + 0x45)
140#define QPNP_WLED_MODULE_EN_REG(b) (b + 0x46)
141#define QPNP_WLED_MODULE_RDY_MASK 0x7F
142#define QPNP_WLED_MODULE_RDY_SHIFT 7
143#define QPNP_WLED_MODULE_EN_MASK 0x7F
144#define QPNP_WLED_MODULE_EN_SHIFT 7
Vishnuvardhan Prodduturiaf59b912015-10-20 21:14:27 +0530145#define QPNP_IBB_SWIRE_RDY_MASK 0x40
146#define QPNP_IBB_SWIRE_RDY_SHIFT 6
147#define QPNP_IBB_MODULE_EN_MASK 0x80
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530148#define QPNP_WLED_DISP_SEL_MASK 0x7F
149#define QPNP_WLED_DISP_SEL_SHIFT 7
150
151#define QPNP_WLED_IBB_BIAS_REG(b) (b + 0x58)
152#define QPNP_WLED_IBB_BIAS_MASK 0x7F
153#define QPNP_WLED_IBB_BIAS_SHIFT 7
154#define QPNP_WLED_IBB_PWRUP_DLY_MASK 0xCF
155#define QPNP_WLED_IBB_PWRUP_DLY_SHIFT 4
Aparna Mallavarapua42de902014-12-08 17:25:44 -0800156#define QPNP_WLED_IBB_PWRUP_DLY_MIN_MS 0
157#define QPNP_WLED_IBB_PWRUP_DLY_MAX_MS 3
158#define QPNP_WLED_IBB_PWRDN_DLY_MIN_MS 0
159#define QPNP_WLED_IBB_PWRDN_DLY_MAX_MS 3
160#define IBB_LAB_VREG_STEP_SIZE 100000
161#define QPNP_LABIBB_OUTPUT_VOLTAGE 0x41
Vishnuvardhan Prodduturiaf59b912015-10-20 21:14:27 +0530162#define QPNP_LABIBB_PS_CTL 0x50
Aparna Mallavarapua42de902014-12-08 17:25:44 -0800163#define QPNP_LAB_OUTPUT_OVERRIDE_EN BIT(7)
164#define QPNP_LAB_SET_VOLTAGE_MASK (BIT(4) - 1)
165#define QPNP_IBB_SET_VOLTAGE_MASK (BIT(6) - 1)
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530166#define QPNP_WLED_LAB_IBB_RDY_REG(b) (b + 0x49)
167#define QPNP_WLED_LAB_FAST_PC_REG(b) (b + 0x5E)
168#define QPNP_WLED_LAB_FAST_PC_MASK 0xFB
169#define QPNP_WLED_LAB_START_DLY_US 8
170#define QPNP_WLED_LAB_FAST_PC_SHIFT 2
wufeng.jiangb1008482016-06-14 10:41:39 +0800171#define QPNP_WLED_PRECHARGE_MASK 0xFC
172#define QPNP_WLED_PRECHARGE_US200 0x00
173#define QPNP_WLED_PRECHARGE_US300 0x01
174#define QPNP_WLED_PRECHARGE_US400 0x02
175#define QPNP_WLED_PRECHARGE_US500 0x03
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530176
177#define QPNP_WLED_SEC_ACCESS_REG(b) (b + 0xD0)
178#define QPNP_WLED_SEC_UNLOCK 0xA5
179
Parth Dixit36ee8b72016-02-11 12:01:15 +0530180#if TARGET_MAX_WLED_STRINGS
181#define QPNP_WLED_MAX_STRINGS TARGET_MAX_WLED_STRINGS
182#else
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530183#define QPNP_WLED_MAX_STRINGS 4
Parth Dixit36ee8b72016-02-11 12:01:15 +0530184#endif
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530185#define WLED_MAX_LEVEL_511 511
186#define WLED_MAX_LEVEL_4095 4095
187#define QPNP_WLED_RAMP_DLY_MS 20
188#define QPNP_WLED_TRIGGER_NONE "none"
189#define QPNP_WLED_STR_SIZE 20
190#define QPNP_WLED_MIN_MSLEEP 20
191#define QPNP_WLED_MAX_BR_LEVEL 1638
192
Channagoud Kadabif5f0ded2015-02-25 13:42:18 -0800193#define PWRDN_DLY2_MASK 0x3
194
Parth Dixite46b1a22016-06-06 19:16:20 +0530195#define NUM_SUPPORTED_AVDD_VOLTAGES 6
196
197/* Supported values 7900, 7600, 7300, 6400, 6100, 5800 */
198#if TARGET_QPNP_WLED_AVDD_DEFAULT_VOLTAGE_MV
199#define QPNP_WLED_AVDD_DEFAULT_VOLTAGE_MV TARGET_QPNP_WLED_AVDD_DEFAULT_VOLTAGE_MV
200#else
201#define QPNP_WLED_AVDD_DEFAULT_VOLTAGE_MV 7600
202#endif
203
204#define QPNP_WLED_AVDD_MIN_TRIM_VALUE 0x0
205#define QPNP_WLED_AVDD_MAX_TRIM_VALUE 0xF
206#define QPNP_WLED_AVDD_SET_BIT BIT(4)
207
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530208/* output feedback mode */
209enum qpnp_wled_fdbk_op {
210 QPNP_WLED_FDBK_AUTO,
211 QPNP_WLED_FDBK_WLED1,
212 QPNP_WLED_FDBK_WLED2,
213 QPNP_WLED_FDBK_WLED3,
214 QPNP_WLED_FDBK_WLED4,
215};
216
217/* dimming modes */
218enum qpnp_wled_dim_mode {
219 QPNP_WLED_DIM_ANALOG,
220 QPNP_WLED_DIM_DIGITAL,
221 QPNP_WLED_DIM_HYBRID,
222};
223
224/* dimming curve shapes */
225enum qpnp_wled_dim_shape {
226 QPNP_WLED_DIM_SHAPE_LOG,
227 QPNP_WLED_DIM_SHAPE_LINEAR,
228 QPNP_WLED_DIM_SHAPE_SQUARE,
229};
230
231
232/**
233 * qpnp_wled - wed data structure
234 * @ fdbk_op - output feedback mode
235 * @ dim_mode - dimming mode
236 * @ dim_shape - dimming curve shape
237 * @ ctrl_base - base address for wled ctrl
238 * @ sink_base - base address for wled sink
239 * @ ibb_base - base address for IBB(Inverting Buck Boost)
240 * @ lab_base - base address for LAB(LCD/AMOLED Boost)
241 * @ mod_freq_khz - modulator frequency in KHZ
242 * @ hyb_thres - threshold for hybrid dimming
243 * @ sync_dly_us - sync delay in us
244 * @ vref_mv - ref voltage in mv
245 * @ switch_freq_khz - switching frequency in KHZ
246 * @ ovp_mv - over voltage protection in mv
247 * @ ilim_ma - current limiter in ma
248 * @ boost_duty_ns - boost duty cycle in ns
249 * @ fs_curr_ua - full scale current in ua
250 * @ ramp_ms - delay between ramp steps in ms
251 * @ ramp_step - ramp step size
252 * @ strings - supported list of strings
253 * @ num_strings - number of strings
254 * @ en_9b_dim_res - enable or disable 9bit dimming
255 * @ en_phase_stag - enable or disable phase staggering
256 * @ en_cabc - enable or disable cabc
257 * @ disp_type_amoled - type of display: LCD/AMOLED
258 * @ ibb_bias_active - activate display bias
259 * @ lab_fast_precharge - fast/slow precharge
260 */
261struct qpnp_wled {
262 enum qpnp_wled_fdbk_op fdbk_op;
263 enum qpnp_wled_dim_mode dim_mode;
264 enum qpnp_wled_dim_shape dim_shape;
265 uint16_t ctrl_base;
266 uint16_t sink_base;
267 uint16_t ibb_base;
268 uint16_t lab_base;
269 uint16_t mod_freq_khz;
270 uint16_t hyb_thres;
271 uint16_t sync_dly_us;
272 uint16_t vref_mv;
273 uint16_t switch_freq_khz;
274 uint16_t ovp_mv;
275 uint16_t ilim_ma;
276 uint16_t boost_duty_ns;
277 uint16_t fs_curr_ua;
278 uint16_t ibb_pwrup_dly_ms;
Aparna Mallavarapua42de902014-12-08 17:25:44 -0800279 uint16_t ibb_pwrdn_dly_ms;
280 uint16_t ibb_discharge_en;
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530281 uint16_t ramp_ms;
282 uint16_t ramp_step;
283 uint8_t strings[QPNP_WLED_MAX_STRINGS];
284 uint8_t num_strings;
285 bool en_9b_dim_res;
286 bool en_phase_stag;
287 bool en_cabc;
288 bool disp_type_amoled;
289 bool ibb_bias_active;
290 bool lab_fast_precharge;
wufeng.jiangb1008482016-06-14 10:41:39 +0800291 uint8_t lab_max_precharge_time;
Aparna Mallavarapua42de902014-12-08 17:25:44 -0800292 uint32_t lab_min_volt;
293 uint32_t lab_max_volt;
294 uint32_t ibb_min_volt;
295 uint32_t ibb_max_volt;
296 uint32_t ibb_init_volt;
297 uint32_t lab_init_volt;
Vishnuvardhan Prodduturiaf59b912015-10-20 21:14:27 +0530298 bool lab_ibb_swire_control;
299 bool wled_avdd_control;
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530300};
301
Aparna Mallavarapua42de902014-12-08 17:25:44 -0800302struct qpnp_wled_config_data {
303 bool display_type;
304 char pwr_up_delay;
305 char pwr_down_delay;
306 char ibb_discharge_en;
307 uint32_t lab_min_volt;
308 uint32_t lab_max_volt;
309 uint32_t ibb_min_volt;
310 uint32_t ibb_max_volt;
311 uint32_t ibb_init_volt;
312 uint32_t lab_init_volt;
Vishnuvardhan Prodduturiaf59b912015-10-20 21:14:27 +0530313 bool lab_ibb_swire_control;
314 bool wled_avdd_control;
Aparna Mallavarapua42de902014-12-08 17:25:44 -0800315};
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530316/* WLED Initial Setup */
Aparna Mallavarapua42de902014-12-08 17:25:44 -0800317int qpnp_wled_init(struct qpnp_wled_config_data *config);
Aparna Mallavarapu083766b2014-07-21 21:04:48 +0530318
319/* Enable IBB */
Aparna Mallavarapua42de902014-12-08 17:25:44 -0800320int qpnp_ibb_enable(bool state);
vijay kumar7b890ab2014-09-23 11:09:13 +0530321void qpnp_wled_enable_backlight(int enable);