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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) Samsung Electronics Co., Ltd.
*
* 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.
*/
#include "panel.h"
#include "panel_drv.h"
#include "dynamic_freq.h"
#include "../dpu20/panels/decon_lcd.h"
#include <linux/dev_ril_bridge.h>
static int search_dynamic_freq_idx(struct panel_device *panel, int band_idx, int freq)
{
int i, ret = 0;
int min, max, array_idx;
struct df_freq_tbl_info *df_tbl;
struct dynamic_freq_range *array;
if (band_idx >= FREQ_RANGE_MAX) {
panel_err("[DYN_FREQ]:ERR:%s: exceed max band idx : %d\n", __func__, band_idx);
ret = -1;
goto search_exit;
}
df_tbl = &panel->df_freq_tbl[band_idx];
if (df_tbl == NULL) {
panel_err("[DYN_FREQ]:ERR:%s:failed to find band_idx : %d\n", __func__, band_idx);
ret = -1;
goto search_exit;
}
array_idx = df_tbl->size;
if (array_idx == 1) {
array = &df_tbl->array[0];
panel_info("[DYN_FREQ]:INFO:%s:Found adap_freq idx(0) : %d\n",
__func__, array->freq_idx);
ret = array->freq_idx;
} else {
for (i = 0; i < array_idx; i++) {
array = &df_tbl->array[i];
panel_info("min : %d, max : %d\n", array->min, array->max);
min = (int)freq - array->min;
max = (int)freq - array->max;
if ((min >= 0) && (max <= 0)) {
panel_info("[DYN_FREQ]:INFO:%s:Found adap_freq idx : %d\n",
__func__, array->freq_idx);
ret = array->freq_idx;
break;
}
}
if (i >= array_idx) {
panel_err("[DYN_FREQ]:ERR:%s:Can't found freq idx\n", __func__);
ret = -1;
goto search_exit;
}
}
search_exit:
return ret;
}
int set_dynamic_freq_ffc(struct panel_device *panel)
{
int ret = 0;
struct panel_state *state = &panel->state;
struct df_status_info *status = &panel->df_status;
if (state->connect_panel == PANEL_DISCONNECT) {
panel_warn("PANEL:WARN:%s:panel no use\n", __func__);
return -ENODEV;
}
if (state->cur_state == PANEL_STATE_OFF ||
state->cur_state == PANEL_STATE_ON || !IS_PANEL_ACTIVE(panel))
return 0;
mutex_lock(&panel->op_lock);
if (status->target_df != status->ffc_df) {
status->ffc_df = status->target_df;
ret = panel_do_seqtbl_by_index_nolock(panel, PANEL_DYNAMIC_FFC_SEQ);
if (unlikely(ret < 0)) {
panel_err("[DYN_FREQ]:ERR:%s:failed to set PANEL_FFC_SEQ\n", __func__);
goto exit_changed;
}
}
exit_changed:
mutex_unlock(&panel->op_lock);
return ret;
}
int dynamic_freq_update(struct panel_device *panel, int idx)
{
struct df_setting_info *df_setting;
struct df_status_info *status = &panel->df_status;
if (idx >= panel->lcd_info.df_set_info.df_cnt) {
panel_err("[DYN_FREQ]:ERR:%s:invalid idx : %d\n", __func__, idx);
return -EINVAL;
}
df_setting = &panel->lcd_info.df_set_info.setting_info[idx];
panel_info("[DYN_FREQ]:INFO:%s:IDX : %d Setting HS : %d\n",
__func__, idx, df_setting->hs);
status->request_df = idx;
status->context = DF_CONTEXT_RIL;
return 0;
}
static int df_notifier(struct notifier_block *self, unsigned long size, void *buf)
{
int df_idx;
struct panel_device *panel;
struct dev_ril_bridge_msg *msg;
struct ril_noti_info *ch_info;
struct df_status_info *dyn_status;
panel = container_of(self, struct panel_device, df_noti);
if (panel == NULL) {
panel_err("[DYN_FREQ]:ERR:%s:panel is null\n", __func__);
goto exit_notifier;
}
dyn_status = &panel->df_status;
if (dyn_status == NULL) {
panel_err("[DYN_FREQ]:ERR:%s:dymanic status is null\n", __func__);
goto exit_notifier;
};
if (!dyn_status->enabled) {
panel_err("[DYN_FREQ]:ERR:%s:df is disabled\n", __func__);
goto exit_notifier;
}
msg = (struct dev_ril_bridge_msg *)buf;
if (msg == NULL) {
panel_err("[DYN_FREQ]:ERR:%s:msg is null\n", __func__);
goto exit_notifier;
}
if (msg->dev_id == IPC_SYSTEM_CP_CHANNEL_INFO &&
msg->data_len == sizeof(struct ril_noti_info)) {
ch_info = (struct ril_noti_info *)msg->data;
if (ch_info == NULL) {
panel_err("[DYN_FREQ]:ERR:%s:ch_info is null\n", __func__);
goto exit_notifier;
}
panel_info("[DYN_FREQ]:INFO:%s: (b:%d, c:%d)\n",
__func__, ch_info->band, ch_info->channel);
df_idx = search_dynamic_freq_idx(panel, ch_info->band, ch_info->channel);
if (df_idx < 0) {
panel_info("[DYN_FREQ]:ERR:%s:failed to search freq idx\n", __func__);
goto exit_notifier;
}
if (df_idx != dyn_status->current_df)
dynamic_freq_update(panel, df_idx);
}
exit_notifier:
return 0;
}
static int init_dynamic_freq_status(struct panel_device *panel)
{
int ret = 0;
int cur_idx;
struct df_status_info *status;
struct df_setting_info *tune;
status = &panel->df_status;
if (status == NULL) {
panel_err("[DYN_FREQ]:ERR:%s:dynamic status is null\n", __func__);
ret = -EINVAL;
goto init_exit;
}
cur_idx = panel->lcd_info.df_set_info.dft_index;
tune = &panel->lcd_info.df_set_info.setting_info[cur_idx];
status->enabled = true;
status->request_df = panel->lcd_info.df_set_info.dft_index;
status->current_df = MAX_DYNAMIC_FREQ;
status->target_df = MAX_DYNAMIC_FREQ;
status->ffc_df = MAX_DYNAMIC_FREQ;
init_exit:
return ret;
}
static int parse_dynamic_freq(struct panel_device *panel)
{
int ret = 0, i, cnt = 0;
unsigned int dft_hs = 0;
struct device_node *freq_node;
struct df_setting_info *set_info;
struct device *dev = panel->dev;
struct device_node *node = panel->ddi_node;
struct decon_lcd *lcd_info = &panel->lcd_info;
struct df_dt_info *df = &lcd_info->df_set_info;
if (node == NULL) {
panel_err("[DYN_FREQ]:ERR:%s:ddi node is NULL\n", __func__);
node = of_parse_phandle(dev->of_node, "ddi_info", 0);
}
cnt = of_property_count_u32_elems(node, "dynamic_freq");
if (cnt <= 0) {
panel_warn("[DYN_FREQ]:WARN:%s:Can't found dynamic freq info\n", __func__);
return -EINVAL;
}
if (cnt > MAX_DYNAMIC_FREQ) {
panel_info("[DYN_FREQ]:ERR:%s:freq cnt exceed max freq num (%d:%d)\n",
__func__, cnt, MAX_DYNAMIC_FREQ);
cnt = MAX_DYNAMIC_FREQ;
}
df->df_cnt = cnt;
of_property_read_u32(node, "timing,dsi-hs-clk", &dft_hs);
panel_info("[DYN_FREQ]:INFO:%s default hs clock(%d)\n", __func__, dft_hs);
panel_info("[DYN_FREQ]:INFO:%s:FREQ CNT : %d\n", __func__, cnt);
for (i = 0; i < cnt; i++) {
freq_node = of_parse_phandle(node, "dynamic_freq", i);
set_info = &df->setting_info[i];
of_property_read_u32(freq_node, "hs-clk", &set_info->hs);
if (dft_hs == set_info->hs) {
df->dft_index = i;
panel_info("[DYN_FREQ]:INFO:%s:found default hs idx : %d\n",
__func__, df->dft_index);
}
of_property_read_u32_array(freq_node, "cmd_underrun_lp_ref",
set_info->cmd_underrun_lp_ref,
lcd_info->dt_lcd_mres.mres_number);
of_property_read_u32_array(freq_node, "pmsk", (u32 *)&set_info->dphy_pms,
sizeof(struct stdphy_pms)/sizeof(unsigned int));
panel_info("[DYN_FREQ]:INFO:HS_FREQ : %d\n", set_info->hs);
panel_info("[DYN_FREQ]:INFO:PMS[p] : %d\n", set_info->dphy_pms.p);
panel_info("[DYN_FREQ]:INFO:PMS[m] : %d\n", set_info->dphy_pms.m);
panel_info("[DYN_FREQ]:INFO:PMS[s] : %d\n", set_info->dphy_pms.s);
panel_info("[DYN_FREQ]:INFO:PMS[k] : %d\n", set_info->dphy_pms.k);
}
return ret;
}
int dynamic_freq_probe(struct panel_device *panel, struct df_freq_tbl_info *freq_tbl)
{
int ret = 0;
if (freq_tbl == NULL) {
panel_err("[DYN_FREQ]:ERR:%s:frequence set is null", __func__);
panel_err("[DYN_FREQ]:ERR:%s:can't support DF\n", __func__);
goto exit_probe;
}
ret = parse_dynamic_freq(panel);
if (ret) {
panel_err("[DYN_FREQ]:ERR:%s:faied to parse df\n", __func__);
goto exit_probe;
}
panel->df_freq_tbl = freq_tbl;
panel->df_noti.notifier_call = df_notifier;
register_dev_ril_bridge_event_notifier(&panel->df_noti);
init_dynamic_freq_status(panel);
exit_probe:
return ret;
}
|