Skip to content

Commit 7a5bc4e

Browse files
mediatek-jitaockhu-mediatek
authored andcommitted
drm/mediatek: change the dsi phytiming calculate method
Change the method of frame rate calc which can get more accurate frame rate. data rate = pixel_clock * bit_per_pixel / lanes Adjust hfp_wc to adapt the additional phy_data if MIPI_DSI_MODE_VIDEO_BURST hfp_wc = hfp * bpp - data_phy_cycles * lanes - 12 - 6; else hfp_wc = hfp * bpp - data_phy_cycles * lanes - 12; Note: //(2: 1 for sync, 1 for phy idle) data_phy_cycles = T_hs_exit + T_lpx + T_hs_prepare + T_hs_zero + 2; bpp: bit per pixel Signed-off-by: Jitao Shi <jitao.shi@mediatek.com> Tested-by: Ryan Case <ryandcase@chromium.org> Signed-off-by: CK Hu <ck.hu@mediatek.com>
1 parent e249e3e commit 7a5bc4e

1 file changed

Lines changed: 81 additions & 37 deletions

File tree

‎drivers/gpu/drm/mediatek/mtk_dsi.c‎

Lines changed: 81 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,6 @@
138138
#define DATA_0 (0xff << 16)
139139
#define DATA_1 (0xff << 24)
140140

141-
#define T_LPX 5
142-
#define T_HS_PREP 6
143-
#define T_HS_TRAIL 8
144-
#define T_HS_EXIT 7
145-
#define T_HS_ZERO 10
146-
147141
#define NS_TO_CYCLE(n, c) ((n) / (c) + (((n) % (c)) ? 1 : 0))
148142

149143
#define MTK_DSI_HOST_IS_READ(type) \
@@ -152,6 +146,25 @@
152146
(type == MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM) || \
153147
(type == MIPI_DSI_DCS_READ))
154148

149+
struct mtk_phy_timing {
150+
u32 lpx;
151+
u32 da_hs_prepare;
152+
u32 da_hs_zero;
153+
u32 da_hs_trail;
154+
155+
u32 ta_go;
156+
u32 ta_sure;
157+
u32 ta_get;
158+
u32 da_hs_exit;
159+
160+
u32 clk_hs_zero;
161+
u32 clk_hs_trail;
162+
163+
u32 clk_hs_prepare;
164+
u32 clk_hs_post;
165+
u32 clk_hs_exit;
166+
};
167+
155168
struct phy;
156169

157170
struct mtk_dsi_driver_data {
@@ -182,6 +195,7 @@ struct mtk_dsi {
182195
enum mipi_dsi_pixel_format format;
183196
unsigned int lanes;
184197
struct videomode vm;
198+
struct mtk_phy_timing phy_timing;
185199
int refcount;
186200
bool enabled;
187201
u32 irq_data;
@@ -215,17 +229,36 @@ static void mtk_dsi_phy_timconfig(struct mtk_dsi *dsi)
215229
{
216230
u32 timcon0, timcon1, timcon2, timcon3;
217231
u32 ui, cycle_time;
232+
struct mtk_phy_timing *timing = &dsi->phy_timing;
233+
234+
ui = DIV_ROUND_UP(1000000000, dsi->data_rate);
235+
cycle_time = div_u64(8000000000ULL, dsi->data_rate);
236+
237+
timing->lpx = NS_TO_CYCLE(60, cycle_time);
238+
timing->da_hs_prepare = NS_TO_CYCLE(50 + 5 * ui, cycle_time);
239+
timing->da_hs_zero = NS_TO_CYCLE(110 + 6 * ui, cycle_time);
240+
timing->da_hs_trail = NS_TO_CYCLE(77 + 4 * ui, cycle_time);
218241

219-
ui = 1000 / dsi->data_rate + 0x01;
220-
cycle_time = 8000 / dsi->data_rate + 0x01;
242+
timing->ta_go = 4 * timing->lpx;
243+
timing->ta_sure = 3 * timing->lpx / 2;
244+
timing->ta_get = 5 * timing->lpx;
245+
timing->da_hs_exit = 2 * timing->lpx;
221246

222-
timcon0 = T_LPX | T_HS_PREP << 8 | T_HS_ZERO << 16 | T_HS_TRAIL << 24;
223-
timcon1 = 4 * T_LPX | (3 * T_LPX / 2) << 8 | 5 * T_LPX << 16 |
224-
T_HS_EXIT << 24;
225-
timcon2 = ((NS_TO_CYCLE(0x64, cycle_time) + 0xa) << 24) |
226-
(NS_TO_CYCLE(0x150, cycle_time) << 16);
227-
timcon3 = NS_TO_CYCLE(0x40, cycle_time) | (2 * T_LPX) << 16 |
228-
NS_TO_CYCLE(80 + 52 * ui, cycle_time) << 8;
247+
timing->clk_hs_zero = NS_TO_CYCLE(336, cycle_time);
248+
timing->clk_hs_trail = NS_TO_CYCLE(100, cycle_time) + 10;
249+
250+
timing->clk_hs_prepare = NS_TO_CYCLE(64, cycle_time);
251+
timing->clk_hs_post = NS_TO_CYCLE(80 + 52 * ui, cycle_time);
252+
timing->clk_hs_exit = 2 * timing->lpx;
253+
254+
timcon0 = timing->lpx | timing->da_hs_prepare << 8 |
255+
timing->da_hs_zero << 16 | timing->da_hs_trail << 24;
256+
timcon1 = timing->ta_go | timing->ta_sure << 8 |
257+
timing->ta_get << 16 | timing->da_hs_exit << 24;
258+
timcon2 = 1 << 8 | timing->clk_hs_zero << 16 |
259+
timing->clk_hs_trail << 24;
260+
timcon3 = timing->clk_hs_prepare | timing->clk_hs_post << 8 |
261+
timing->clk_hs_exit << 16;
229262

230263
writel(timcon0, dsi->regs + DSI_PHY_TIMECON0);
231264
writel(timcon1, dsi->regs + DSI_PHY_TIMECON1);
@@ -412,7 +445,8 @@ static void mtk_dsi_config_vdo_timing(struct mtk_dsi *dsi)
412445
u32 horizontal_sync_active_byte;
413446
u32 horizontal_backporch_byte;
414447
u32 horizontal_frontporch_byte;
415-
u32 dsi_tmp_buf_bpp;
448+
u32 dsi_tmp_buf_bpp, data_phy_cycles;
449+
struct mtk_phy_timing *timing = &dsi->phy_timing;
416450

417451
struct videomode *vm = &dsi->vm;
418452

@@ -439,7 +473,34 @@ static void mtk_dsi_config_vdo_timing(struct mtk_dsi *dsi)
439473
horizontal_backporch_byte = ((vm->hback_porch + vm->hsync_len) *
440474
dsi_tmp_buf_bpp - 10);
441475

442-
horizontal_frontporch_byte = (vm->hfront_porch * dsi_tmp_buf_bpp - 12);
476+
data_phy_cycles = timing->lpx + timing->da_hs_prepare +
477+
timing->da_hs_zero + timing->da_hs_exit + 2;
478+
479+
if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST) {
480+
if (vm->hfront_porch * dsi_tmp_buf_bpp >
481+
data_phy_cycles * dsi->lanes + 18) {
482+
horizontal_frontporch_byte = vm->hfront_porch *
483+
dsi_tmp_buf_bpp -
484+
data_phy_cycles *
485+
dsi->lanes - 18;
486+
} else {
487+
DRM_WARN("HFP less than d-phy, FPS will under 60Hz\n");
488+
horizontal_frontporch_byte = vm->hfront_porch *
489+
dsi_tmp_buf_bpp;
490+
}
491+
} else {
492+
if (vm->hfront_porch * dsi_tmp_buf_bpp >
493+
data_phy_cycles * dsi->lanes + 12) {
494+
horizontal_frontporch_byte = vm->hfront_porch *
495+
dsi_tmp_buf_bpp -
496+
data_phy_cycles *
497+
dsi->lanes - 12;
498+
} else {
499+
DRM_WARN("HFP less than d-phy, FPS will under 60Hz\n");
500+
horizontal_frontporch_byte = vm->hfront_porch *
501+
dsi_tmp_buf_bpp;
502+
}
503+
}
443504

444505
writel(horizontal_sync_active_byte, dsi->regs + DSI_HSA_WC);
445506
writel(horizontal_backporch_byte, dsi->regs + DSI_HBP_WC);
@@ -539,8 +600,7 @@ static int mtk_dsi_poweron(struct mtk_dsi *dsi)
539600
{
540601
struct device *dev = dsi->host.dev;
541602
int ret;
542-
u64 pixel_clock, total_bits;
543-
u32 htotal, htotal_bits, bit_per_pixel, overhead_cycles, overhead_bits;
603+
u32 bit_per_pixel;
544604

545605
if (++dsi->refcount != 1)
546606
return 0;
@@ -559,24 +619,8 @@ static int mtk_dsi_poweron(struct mtk_dsi *dsi)
559619
break;
560620
}
561621

562-
/**
563-
* htotal_time = htotal * byte_per_pixel / num_lanes
564-
* overhead_time = lpx + hs_prepare + hs_zero + hs_trail + hs_exit
565-
* mipi_ratio = (htotal_time + overhead_time) / htotal_time
566-
* data_rate = pixel_clock * bit_per_pixel * mipi_ratio / num_lanes;
567-
*/
568-
pixel_clock = dsi->vm.pixelclock;
569-
htotal = dsi->vm.hactive + dsi->vm.hback_porch + dsi->vm.hfront_porch +
570-
dsi->vm.hsync_len;
571-
htotal_bits = htotal * bit_per_pixel;
572-
573-
overhead_cycles = T_LPX + T_HS_PREP + T_HS_ZERO + T_HS_TRAIL +
574-
T_HS_EXIT;
575-
overhead_bits = overhead_cycles * dsi->lanes * 8;
576-
total_bits = htotal_bits + overhead_bits;
577-
578-
dsi->data_rate = DIV_ROUND_UP_ULL(pixel_clock * total_bits,
579-
htotal * dsi->lanes);
622+
dsi->data_rate = DIV_ROUND_UP_ULL(dsi->vm.pixelclock * bit_per_pixel,
623+
dsi->lanes);
580624

581625
ret = clk_set_rate(dsi->hs_clk, dsi->data_rate);
582626
if (ret < 0) {

0 commit comments

Comments
 (0)