aboutsummaryrefslogtreecommitdiff
path: root/drivers/misc/mediatek/ext_disp/mt6735/extd_factory.c
blob: 9900ccfbc61b9076a42e711b85bd4d43e192c947 (plain) (blame)
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
#include <linux/delay.h>
#include <linux/uaccess.h>

#include "extd_factory.h"
#include "external_display.h"


static HDMI_DRIVER *hdmi_tx_drv = NULL;
static int is_context_inited = 0;
disp_ddp_path_config hdmi_factory_dpi_params;
DPI_PARAM_CONTEXT DPI_Params_Context;

typedef struct
{
	bool hdmi_factory_inited;
	bool hdmi_callback_returned;
}hdmi_factory_context;

static hdmi_factory_context* _get_context(void)
{	
	static hdmi_factory_context g_context;
	if(!is_context_inited)
	{
		memset((void*)&g_context, 0, sizeof(hdmi_factory_context));
		is_context_inited = 1;
		printk("[hdmi]_get_context set is_context_inited\n");
	}

	return &g_context;
}
#define pgc	_get_context()

static bool hdmi_factory_callback(HDMI_STATE state)
{
	printk("[hdmi]hdmi_factory_callback, state: %d\n", state);
	pgc->hdmi_callback_returned = state;
	return pgc->hdmi_callback_returned;
}

int hdmi_factory_mode_init()
{
	printk("[hdmi] hdmi_factory_mode_init \n");

    hdmi_tx_drv = (HDMI_DRIVER *)HDMI_GetDriver();
    if(NULL == hdmi_tx_drv)
    {
        printk("[hdmi]%s, hdmi_init fail, can not get hdmi driver handle\n", __func__);
        return -1;
    }
	hdmi_tx_drv->register_callback(hdmi_factory_callback);

	pgc->hdmi_factory_inited = true;
	return 0;
}

void hdmi_factory_dpi_parameters(int arg, int io_driving)
{
    HDMI_POLARITY clk_pol, de_pol, hsync_pol, vsync_pol;
    DPI_U32 dpi_clock = 0;
    DPI_U32 dpi_clk_div, dpi_clk_duty, hsync_pulse_width, hsync_back_porch, hsync_front_porch, vsync_pulse_width, vsync_back_porch, vsync_front_porch, intermediat_buffer_num;

    switch (arg)
    {
        case HDMI_VIDEO_720x480p_60Hz:
        {
            clk_pol     = HDMI_POLARITY_FALLING;
            de_pol      = HDMI_POLARITY_RISING;
            hsync_pol   = HDMI_POLARITY_RISING;
            vsync_pol   = HDMI_POLARITY_RISING;;

            dpi_clk_div = 2;

            hsync_pulse_width   = 62;
            hsync_back_porch    = 60;
            hsync_front_porch   = 16;

            vsync_pulse_width   = 6;
            vsync_back_porch    = 30;
            vsync_front_porch   = 9;

            DPI_Params_Context.bg_height = ((480 * DPI_Params_Context.scaling_factor) / 100 >> 2) << 2 ;
            DPI_Params_Context.bg_width = ((720 * DPI_Params_Context.scaling_factor) / 100 >> 2) << 2 ;
            DPI_Params_Context.hdmi_width = 720 - DPI_Params_Context.bg_width;
            DPI_Params_Context.hdmi_height = 480 - DPI_Params_Context.bg_height;
            DPI_Params_Context.output_video_resolution = HDMI_VIDEO_720x480p_60Hz;
            dpi_clock = 27027;
            break;
        }
        case HDMI_VIDEO_1280x720p_60Hz:
        {
            clk_pol     = HDMI_POLARITY_FALLING;
            de_pol      = HDMI_POLARITY_RISING;
            hsync_pol   = HDMI_POLARITY_FALLING;
            vsync_pol   = HDMI_POLARITY_FALLING;

            dpi_clk_div = 2;

            hsync_pulse_width   = 40;
            hsync_back_porch    = 220;
            hsync_front_porch   = 110;

            vsync_pulse_width   = 5;
            vsync_back_porch    = 20;
            vsync_front_porch   = 5;
            dpi_clock = 74250;

            DPI_Params_Context.bg_height = ((720 * DPI_Params_Context.scaling_factor) / 100 >> 2) << 2 ;
            DPI_Params_Context.bg_width = ((1280 * DPI_Params_Context.scaling_factor) / 100 >> 2) << 2 ;
            DPI_Params_Context.hdmi_width = 1280 - DPI_Params_Context.bg_width; 
            DPI_Params_Context.hdmi_height = 720 - DPI_Params_Context.bg_height;

            DPI_Params_Context.output_video_resolution = HDMI_VIDEO_1280x720p_60Hz;
            break;
        }
        case HDMI_VIDEO_1920x1080p_30Hz:
        {
            clk_pol     = HDMI_POLARITY_FALLING;
            de_pol      = HDMI_POLARITY_RISING;
            hsync_pol   = HDMI_POLARITY_FALLING;
            vsync_pol   = HDMI_POLARITY_FALLING;  

            dpi_clk_div = 2;

            hsync_pulse_width   = 44;
            hsync_back_porch    = 148;
            hsync_front_porch   = 88;

            vsync_pulse_width   = 5;
            vsync_back_porch    = 36;
            vsync_front_porch   = 4;

            DPI_Params_Context.bg_height = ((1080 *DPI_Params_Context.scaling_factor)/100 >>2) <<2 ;
            DPI_Params_Context.bg_width = ((1920 *DPI_Params_Context.scaling_factor)/100 >>2) <<2 ;
            DPI_Params_Context.hdmi_width = 1920 -DPI_Params_Context.bg_width;
            DPI_Params_Context.hdmi_height = 1080 - DPI_Params_Context.bg_height;

            DPI_Params_Context.output_video_resolution = HDMI_VIDEO_1920x1080p_30Hz;
            dpi_clock = 74250;
            break;
        }
        case HDMI_VIDEO_1920x1080p_60Hz:
        {
            clk_pol     = HDMI_POLARITY_FALLING;
            de_pol      = HDMI_POLARITY_RISING;
            hsync_pol   = HDMI_POLARITY_FALLING;
            vsync_pol   = HDMI_POLARITY_FALLING;

            dpi_clk_div = 2;

            hsync_pulse_width   = 44;
            hsync_back_porch    = 148;
            hsync_front_porch   = 88;

            vsync_pulse_width   = 5;
            vsync_back_porch    = 36;
            vsync_front_porch   = 4;

            DPI_Params_Context.bg_height = ((1080 *DPI_Params_Context.scaling_factor)/100 >>2) <<2 ;
            DPI_Params_Context.bg_width = ((1920 *DPI_Params_Context.scaling_factor)/100 >>2) <<2 ;
            DPI_Params_Context.hdmi_width = 1920 -DPI_Params_Context.bg_width;
            DPI_Params_Context.hdmi_height = 1080 - DPI_Params_Context.bg_height;

            DPI_Params_Context.output_video_resolution = HDMI_VIDEO_1920x1080p_60Hz;
            dpi_clock = 148500;
            break;
        }
		
        default:
            break;
    }

    hdmi_factory_dpi_params.dispif_config.dpi.width = DPI_Params_Context.hdmi_width;
    hdmi_factory_dpi_params.dispif_config.dpi.height = DPI_Params_Context.hdmi_height;
    hdmi_factory_dpi_params.dispif_config.dpi.bg_width = DPI_Params_Context.bg_width;
    hdmi_factory_dpi_params.dispif_config.dpi.bg_height = DPI_Params_Context.bg_height;
    
    hdmi_factory_dpi_params.dispif_config.dpi.clk_pol = clk_pol;
    hdmi_factory_dpi_params.dispif_config.dpi.de_pol = de_pol;
    hdmi_factory_dpi_params.dispif_config.dpi.vsync_pol = vsync_pol;
    hdmi_factory_dpi_params.dispif_config.dpi.hsync_pol = hsync_pol;

    hdmi_factory_dpi_params.dispif_config.dpi.hsync_pulse_width = hsync_pulse_width;
    hdmi_factory_dpi_params.dispif_config.dpi.hsync_back_porch = hsync_back_porch;
    hdmi_factory_dpi_params.dispif_config.dpi.hsync_front_porch = hsync_front_porch;
    hdmi_factory_dpi_params.dispif_config.dpi.vsync_pulse_width = vsync_pulse_width;
    hdmi_factory_dpi_params.dispif_config.dpi.vsync_back_porch = vsync_back_porch;
    hdmi_factory_dpi_params.dispif_config.dpi.vsync_front_porch = vsync_front_porch;
    
    hdmi_factory_dpi_params.dispif_config.dpi.format = 0;
    hdmi_factory_dpi_params.dispif_config.dpi.rgb_order = 0;
    hdmi_factory_dpi_params.dispif_config.dpi.i2x_en = true;
    hdmi_factory_dpi_params.dispif_config.dpi.i2x_edge = 2;
    hdmi_factory_dpi_params.dispif_config.dpi.embsync = false;
	hdmi_factory_dpi_params.dispif_config.dpi.io_driving_current = (LCM_DRIVING_CURRENT)io_driving;
    hdmi_factory_dpi_params.dispif_config.dpi.dpi_clock = dpi_clock;

    printk("[hdmi]hdmi_factory_dpi_parameters:%d\n", arg);
}

int hdmi_factory_mode_test(HDMI_FACTORY_TEST test_step, void *info)
{
    int ret = 0;
	if(pgc->hdmi_factory_inited == false)
	{
		hdmi_factory_mode_init();
	}

    switch(test_step)
    {
        case STEP1_CHIP_INIT:
		{
			printk("[hdmi] STEP1_CHIP_INIT\n");
            hdmi_tx_drv->power_on();
            break;			
		}
		case STEP2_JUDGE_CALLBACK:
        {
            printk("[hdmi] STEP2_JUDGE_CALLBACK: %d\n", pgc->hdmi_callback_returned);	
            int hdmi_status = (int)pgc->hdmi_callback_returned;
			if (copy_to_user(info, &hdmi_status, sizeof(hdmi_status)))
            {
                printk("[HDMI]copy_to_user failed! line:%d \n", __LINE__);
                ret = -1;
            }
            break;
        }
        case STEP3_START_DPI_AND_CONFIG:
        {
			/*
			*  test_type(24bit-31bit), resolution/test_case(16bit-23bit), hsync/vsync/de/clk io drivint(8bit-15bit), data io driving(0bit-7bit)
			*  test_type (factory:0, HQA:1, DVT:2) 
			*/
			int test_type  = ((long int)info >> 24);
			int resolution = (((long int)info >> 16) & 0xFF);
			int test_case = resolution;
			int vsync_io_driving = (((long int)info >> 8) & 0xFF);
			int data_io_driving = ((long int)info & 0xFF);
			int io_driving = ((long int)info & 0xFFFF);
			
			printk("[hdmi] STEP3_START_DPI_AND_CONFIG, resolution/test case: %d, io_driving: 0x%x\n", resolution, io_driving);

			if(test_type == 0)        //Factory mode
			{
				hdmi_factory_dpi_parameters(resolution, io_driving);
				ext_disp_factory_test(0, (void *)&hdmi_factory_dpi_params);

				msleep(100);
				hdmi_tx_drv->video_config(resolution, HDMI_VIN_FORMAT_RGB888, HDMI_VOUT_FORMAT_RGB888);
			}
			else if(test_type == 1)   //HQA
			{
				hdmi_factory_dpi_parameters(resolution, io_driving);
				ext_disp_factory_test(0, (void *)&hdmi_factory_dpi_params);

				printk("[hdmi] Not need video config for DPI HQA\n");
			}
			else if(test_type == 2)   //DVT
			{
#ifdef HDMI_DPI_DVT_TEST              //Need to add dvt header file
				printk("[hdmi] Start DPI DVT Test\n");
				hdmi_dvt_dpi_ioctl(test_case);
#endif
			}
			
            break;
        }
        case STEP4_DPI_STOP_AND_POWER_OFF:
        {
			printk("[hdmi] STEP4_DPI_STOP_AND_POWER_OFF\n");
			hdmi_tx_drv->power_off();

			pgc->hdmi_factory_inited = false;
			is_context_inited = false;

			hdmi_tx_drv->unregister_callback(hdmi_factory_callback);
            break;
        }  
        default:
            break;
    }

    return ret;
}