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 #include "disp_hal.h"
16 #include "hdf_log.h"
17 #include "lcd_abs_if.h"
18 #include "mipi_dsi_core.h"
19 #include "mipi_dsi.h"
20
DispInit(uint32_t devId)21 int32_t DispInit(uint32_t devId)
22 {
23 struct PanelData *panelData = GetPanel(devId);
24 if (panelData == NULL) {
25 HDF_LOGE("%s: GetPanelData failed", __func__);
26 return HDF_FAILURE;
27 }
28 if (panelData->init) {
29 /* panel driver init */
30 if (panelData->init(panelData) != HDF_SUCCESS) {
31 HDF_LOGE("%s: panelData->init failed", __func__);
32 return HDF_FAILURE;
33 }
34 }
35 return HDF_SUCCESS;
36 }
37
DispGetInfo(uint32_t devId,struct DispInfo * info)38 int32_t DispGetInfo(uint32_t devId, struct DispInfo *info)
39 {
40 if (info == NULL) {
41 return HDF_FAILURE;
42 }
43 struct PanelData *panelData = GetPanel(devId);
44 if (panelData == NULL) {
45 HDF_LOGE("%s: GetPanelData failed", __func__);
46 return HDF_FAILURE;
47 }
48 struct PanelInfo *panelInfo = panelData->info;
49 if (panelInfo == NULL) {
50 HDF_LOGE("%s: GetPanelInfo failed", __func__);
51 return HDF_FAILURE;
52 }
53 info->width = panelInfo->width;
54 info->height = panelInfo->height;
55 info->hbp = panelInfo->hbp;
56 info->hfp = panelInfo->hfp;
57 info->hsw = panelInfo->hsw;
58 info->vbp = panelInfo->vbp;
59 info->vfp = panelInfo->vfp;
60 info->vsw = panelInfo->vsw;
61 info->intfType = (uint32_t)panelInfo->intfType;
62 info->intfSync = panelInfo->intfSync;
63 info->frameRate = panelInfo->frameRate;
64 return HDF_SUCCESS;
65 }
66
DispOn(uint32_t devId)67 int32_t DispOn(uint32_t devId)
68 {
69 struct PanelData *panelData = GetPanel(devId);
70 if (panelData == NULL) {
71 HDF_LOGE("%s: GetPanelData failed", __func__);
72 return HDF_FAILURE;
73 }
74 if (panelData->on) {
75 /* panel driver on */
76 if (panelData->on(panelData) != HDF_SUCCESS) {
77 HDF_LOGE("%s: panelData->on failed", __func__);
78 return HDF_FAILURE;
79 }
80 }
81 return HDF_SUCCESS;
82 }
83
DispOff(uint32_t devId)84 int32_t DispOff(uint32_t devId)
85 {
86 struct PanelData *panelData = GetPanel(devId);
87 if (panelData == NULL) {
88 HDF_LOGE("%s: GetPanelData failed", __func__);
89 return HDF_FAILURE;
90 }
91 if (panelData->off) {
92 /* panel driver off */
93 if (panelData->off(panelData) != HDF_SUCCESS) {
94 HDF_LOGE("%s: panelData->off failed", __func__);
95 return HDF_FAILURE;
96 }
97 }
98 return HDF_SUCCESS;
99 }
100
DispSetBacklight(uint32_t devId,uint32_t level)101 int32_t DispSetBacklight(uint32_t devId, uint32_t level)
102 {
103 struct PanelData *panelData = GetPanel(devId);
104 if (panelData == NULL) {
105 HDF_LOGE("%s: GetPanelData failed", __func__);
106 return HDF_FAILURE;
107 }
108 if (panelData->setBacklight) {
109 /* panel driver set backlight */
110 if (panelData->setBacklight(panelData, level) != HDF_SUCCESS) {
111 HDF_LOGE("%s: panelData->setBacklight failed", __func__);
112 return HDF_FAILURE;
113 }
114 }
115 return HDF_SUCCESS;
116 }
117
118 #define HDF_MIPI_DSI_SERVICE "HDF_PLATFORM_MIPI_DSI"
119
GetDispService()120 static struct MipiDsiService *GetDispService()
121 {
122 static struct MipiDsiService *service = NULL;
123 if (service == NULL) {
124 struct MipiDsiCntlr *mipiDsiCntlr = (struct MipiDsiCntlr *)DevSvcManagerClntGetService(HDF_MIPI_DSI_SERVICE);
125 if (mipiDsiCntlr == NULL) {
126 HDF_LOGE("failed to get service %s", HDF_MIPI_DSI_SERVICE);
127 return NULL;
128 }
129 service = (struct MipiDsiService *)mipiDsiCntlr->priv; // @see mipi_dsi.c
130 }
131 return service;
132 }
133
DispMmap(uint32_t size)134 void *DispMmap(uint32_t size)
135 {
136 struct MipiDsiService *service = GetDispService();
137 if (service == NULL || service->mmap == NULL) {
138 return NULL;
139 }
140 return service->mmap(size);
141 }
142
DispFlush(void)143 void DispFlush(void)
144 {
145 struct MipiDsiService *service = GetDispService();
146 if (service == NULL || service->flush == NULL) {
147 return;
148 }
149 service->flush();
150 }
151