summaryrefstree
path: root/kernel/drivers/video/fbdev/exynos/panel/panel_bl.h
blob: 0a549799e623d60b4057dc7478793900442af148 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (c) Samsung Electronics Co., Ltd.
 * Gwanghui Lee <gwanghui.lee@samsung.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef __PANEL_BL_H__
#define __PANEL_BL_H__

#include "timenval.h"

struct panel_info;
struct panel_device;

#undef DEBUG_PAC
#undef CONFIG_PANEL_BL_USE_BRT_CACHE

#ifndef CONFIG_EXYNOS_DECON_LCD_S6E3HF4
#define CONFIG_LCD_EXTEND_HBM
#endif

#ifdef CONFIG_PANEL_BACKLIGHT_PAC_3_0
#define BRT_SCALE	(100)
#define PANEL_BACKLIGHT_PAC_STEPS	(512)
#else
#define PANEL_BACKLIGHT_PAC_STEPS	(256)
#define BRT_SCALE	(1)
#endif
#define BRT_SCALE_UP(_val_)	((_val_) * BRT_SCALE)
#define BRT_SCALE_DN(_val_)	((_val_) / BRT_SCALE)
#define BRT_TBL_INDEX(_val_)	(BRT_SCALE_DN((_val_) + ((BRT_SCALE) - 1)))
#define BRT(brt)			(BRT_SCALE_UP(brt))
#define BRT_LT(brt)			(BRT_SCALE_UP(brt) - 1)
#define BRT_GT(brt)			(BRT_SCALE_UP(brt) + 1)
#define BRT_USER(brt)		(BRT_SCALE_DN(brt))

#define UI_MIN_BRIGHTNESS			(BRT(0))
#define UI_DEF_BRIGHTNESS			(BRT(128))
#define UI_MAX_BRIGHTNESS			(BRT(255))
#define UI_BRIGHTNESS_STEPS		(UI_MAX_BRIGHTNESS - UI_MIN_BRIGHTNESS + 1)
#define IS_UI_BRIGHTNESS(br)            (((br) <= UI_MAX_BRIGHTNESS) ? 1 : 0)

#define AOR_TO_RATIO(aor, vtotal) \
	(((aor) * disp_pow(10, 5) / (vtotal) + 5 * disp_pow(10, 0)) / disp_pow(10, 1))

#define VIRTUAL_BASE_LUMINANCE(lum, aor_ratio) \
	((lum) * disp_pow(10, 6) / (disp_pow(10, 4) - (aor_ratio)))

enum SEARCH_TYPE {
	SEARCH_TYPE_EXACT,
	SEARCH_TYPE_LOWER,
	SEARCH_TYPE_UPPER,
	MAX_SEARCH_TYPE,
};

enum DIMTYPE {
	A_DIMMING = 0,
	S_DIMMING,
	MAX_DIMMING_TYPE,
};

enum {
	IRC_R_64 = 8,
	IRC_G_64,
	IRC_B_64,
	IRC_R_128,
	IRC_G_128,
	IRC_B_128,
	IRC_R_192,
	IRC_G_192,
	IRC_B_192,
	MAX_IRC_PARAM,
};

struct brightness_table {
	/* brightness to step mapping table */
	u32 *brt_to_step;
	u32 sz_brt_to_step;
	/* brightness to brightness mapping table */
	u32 (*brt_to_brt)[2];
	u32 sz_brt_to_brt;
	/* brightness table */
	u32 *brt;
	u32 sz_brt;
	/* actual brightness table */
	u32 *lum;
	u32 sz_lum;

	/*
	 * luminance table has 3 (ui, hbm, ext_hbm) regions.
	 * to determine current luminance's region, these sizes are necessary.
	 * ui luminance : ui brightness region. (typ:0 ~ 255)
	 * hbm luminance : hbm interpolation brightness region
	 * ext hbm luminance : extended hbm brightness
	 */
	u32 sz_ui_lum;
	u32 sz_hbm_lum;
	u32 sz_ext_hbm_lum;
	u32 vtotal;
};

enum panel_bl_hw_type {
	PANEL_BL_HW_TYPE_TFT,
	PANEL_BL_HW_TYPE_OCTA,
	MAX_PANEL_BL_HW_TYPE,
};

enum panel_bl_subdev_type {
	PANEL_BL_SUBDEV_TYPE_DISP,
#ifdef CONFIG_SUPPORT_HMD
	PANEL_BL_SUBDEV_TYPE_HMD,
#endif
#ifdef CONFIG_SUPPORT_AOD_BL
	PANEL_BL_SUBDEV_TYPE_AOD,
#endif
	MAX_PANEL_BL_SUBDEV,
};

struct panel_bl_properties {
	int id;
	int brightness;
	int actual_brightness;
	int actual_brightness_index;
	int actual_brightness_intrp;
	int step;
	int brightness_of_step;
	int acl_pwrsave;
	int acl_opr;
};

struct panel_bl_sub_dev {
	const char *name;
	enum panel_bl_hw_type hw_type;
	enum panel_bl_subdev_type subdev_type;
	struct brightness_table brt_tbl;
	int brightness;
#if defined(CONFIG_PANEL_BL_USE_BRT_CACHE)
	int *brt_cache_tbl;
	int sz_brt_cache_tbl;
#endif
};

struct panel_bl_device {
	const char *name;
	struct backlight_device *bd;
	void *bd_data;
	struct mutex ops_lock;
	struct mutex lock;
	struct panel_bl_properties props;
	struct panel_bl_sub_dev subdev[MAX_PANEL_BL_SUBDEV];
#ifdef CONFIG_SUPPORT_INDISPLAY
	int saved_br;
	bool finger_layer;
#endif
	struct timenval tnv[2];
};

int panel_bl_probe(struct panel_device *panel);
int panel_bl_set_brightness(struct panel_bl_device *panel_bl, int id, int force);
int get_max_brightness(struct panel_bl_device *panel_bl);
int get_brightness_pac_step(struct panel_bl_device *panel_bl, int brightness);
int get_brightness_of_brt_to_step(struct panel_bl_device *panel_bl, int id, int brightness);
int get_actual_brightness(struct panel_bl_device *panel_bl, int brightness);
int get_subdev_actual_brightness(struct panel_bl_device *panel_bl, int id, int brightness);
int get_actual_brightness_index(struct panel_bl_device *panel_bl, int brightness);
int get_subdev_actual_brightness_index(struct panel_bl_device *panel_bl,
		int id, int brightness);
int get_actual_brightness_interpolation(struct panel_bl_device *panel_bl, int brightness);
int get_subdev_actual_brightness_interpolation(struct panel_bl_device *panel_bl, int id, int brightness);
int panel_bl_get_acl_pwrsave(struct panel_bl_device *panel_bl);
int panel_bl_get_acl_opr(struct panel_bl_device *panel_bl);
bool is_hbm_brightness(struct panel_bl_device *panel_bl, int brightness);
bool is_ext_hbm_brightness(struct panel_bl_device *panel_bl, int brightness);
int panel_bl_set_subdev(struct panel_bl_device *panel_bl, int id);

int panel_bl_update_average(struct panel_bl_device *panel_bl, size_t index);
int panel_bl_clear_average(struct panel_bl_device *panel_bl, size_t index);
int panel_bl_get_average_and_clear(struct panel_bl_device *panel_bl, size_t index);
int aor_interpolation(unsigned int *brt_tbl, unsigned int *lum_tbl,
		u8 (*aor_tbl)[2], int size, int size_ui_lum, u32 vtotal, int brightness);
int panel_bl_aor_interpolation(struct panel_bl_device *panel_bl,
		int id, u8(*aor_tbl)[2]);
int irc_interpolation(unsigned int *brt_tbl, unsigned int *lum_tbl,
		u8 (*irc_tbl)[MAX_IRC_PARAM], int size, int size_ui_lum,
		u8 *dst, int brightness);
int panel_bl_irc_interpolation(struct panel_bl_device *panel_bl, int id,
		u8 (*irc_tbl)[MAX_IRC_PARAM], u8 *dst);
#endif /* __PANEL_BL_H__ */