1 /*
2 * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "lcd_abs_if.h"
17 #include "hdf_log.h"
18
19 #define TRANSFORM_KILO 1000
20 #define TRANSFORM_MILL 1000000
21
22 static struct PanelManager g_panelManager;
23
RegisterPanel(struct PanelData * data)24 int32_t RegisterPanel(struct PanelData *data)
25 {
26 int32_t panelNum;
27
28 if (data == NULL) {
29 HDF_LOGE("%s: panel data is null", __func__);
30 return HDF_ERR_INVALID_PARAM;
31 }
32 panelNum = g_panelManager.panelNum;
33 if (panelNum >= PANEL_MAX) {
34 HDF_LOGE("%s registered panel up PANEL_MAX", __func__);
35 return HDF_FAILURE;
36 }
37 g_panelManager.panel[panelNum] = data;
38 g_panelManager.panelNum++;
39 HDF_LOGI("%s: register success", __func__);
40 return HDF_SUCCESS;
41 }
42
GetPanelManager(void)43 struct PanelManager *GetPanelManager(void)
44 {
45 if (g_panelManager.panelNum == 0) {
46 return NULL;
47 } else {
48 return &g_panelManager;
49 }
50 }
51
GetPanel(int32_t index)52 struct PanelData *GetPanel(int32_t index)
53 {
54 struct PanelManager *panelManager = NULL;
55
56 panelManager = GetPanelManager();
57 if (panelManager == NULL) {
58 HDF_LOGE("%s panelManager is null", __func__);
59 return NULL;
60 }
61 if (index >= g_panelManager.panelNum) {
62 HDF_LOGE("%s index is greater than g_panelManager.panelNum", __func__);
63 return NULL;
64 }
65 return panelManager->panel[index];
66 }
67
GetBitsPerPixel(enum DsiOutFormat format)68 int32_t GetBitsPerPixel(enum DsiOutFormat format)
69 {
70 int32_t bpp;
71
72 switch (format) {
73 case FORMAT_RGB_16_BIT:
74 bpp = 16;
75 break;
76 case FORMAT_RGB_18_BIT:
77 bpp = 18;
78 break;
79 case FORMAT_RGB_24_BIT:
80 bpp = 24;
81 break;
82 default:
83 bpp = 32;
84 break;
85 }
86 return bpp;
87 }
88
CalcPixelClk(struct PanelInfo * info)89 uint32_t CalcPixelClk(struct PanelInfo *info)
90 {
91 uint16_t hpixel;
92 uint16_t vline;
93
94 hpixel = info->width + info->hbp + info->hfp + info->hsw;
95 vline = info->height + info->vbp + info->vfp + info->vsw;
96 uint32_t pixNum = hpixel * vline * info->frameRate;
97 if ((pixNum % TRANSFORM_KILO) == 0) {
98 return pixNum / TRANSFORM_KILO;
99 }
100 return (pixNum / TRANSFORM_KILO + 1);
101 }
102
CalcDataRate(struct PanelInfo * info)103 uint32_t CalcDataRate(struct PanelInfo *info)
104 {
105 uint16_t hpixel;
106 uint16_t vline;
107 uint32_t bitClk;
108
109 hpixel = info->width + info->hbp + info->hfp + info->hsw;
110 vline = info->height + info->vbp + info->vfp + info->vsw;
111 int32_t bpp = GetBitsPerPixel(info->mipi.format);
112 uint32_t bitNum = hpixel * vline * info->frameRate * bpp;
113 if ((bitNum % TRANSFORM_MILL) == 0) {
114 bitClk = bitNum / TRANSFORM_MILL;
115 } else {
116 bitClk = bitNum / TRANSFORM_MILL + 1;
117 }
118 if (info->mipi.lane == 0) {
119 info->mipi.lane = 1; // default 1 lane
120 }
121 if ((bitClk % info->mipi.lane) == 0) {
122 return bitClk / info->mipi.lane;
123 }
124 return bitClk / info->mipi.lane + 1;
125 }
126