summaryrefslogtreecommitdiff
path: root/drivers/video/fbdev/starfive/starfive_display_dev.h
blob: 36da01891fbcd32741541bfa7fc18101a4ddab86 (plain)
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
/*
 * StarFive Vout driver
 *
 * Copyright 2020 StarFive Inc.
 *
 * Licensed under the GPL-2.
 */

#ifndef __SF_FB_DISPLAY_DEV_H_
#define __SF_FB_DISPLAY_DEV_H_

#include <linux/fb.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include "starfive_fb.h"

#define RST_SEQ_LEN		16

#define FB_HSYNC_HIGH_ACT		(0x03)
#define FB_VSYNC_HIGH_ACT		(0x04)

#define MIPI_VIDEO_MODE 		(0x05)
#define MIPI_COMMAND_MODE 		(0x06)

#define ARRAY_AND_SIZE(x)		(u8 *)(x), ARRAY_SIZE(x)

/*display prefer and ce*/
#define COLOR_TYPE_MAX			(3)
#define PREFER_WARM			(1)
#define PREFER_NATURE			(2)
#define PREFER_COOL			(3)

#define CE_BRIGHT 			(12)
#define CE_VELVIA			(11)
#define CE_STANDARD			(10)


enum {
	DCS_CMD = 2,
	GEN_CMD,
	SW_PACK0,
	SW_PACK1,
	SW_PACK2,
	LW_PACK,
	SHUTDOWN_SW_PACK,
};

/*Device flags*/
#define	PREFER_CMD_SEND_MONOLITHIC	(0x00000001)
#define	CE_CMD_SEND_MONOLITHIC		(0x00000002)

#define RESUME_WITH_PREFER		(0x00000010)
#define RESUME_WITH_CE			(0x00000020)


/*
 * Video stream type
 */
typedef enum {
	VIDEO_NON_BURST_WITH_SYNC_PULSES = 0,
	VIDEO_NON_BURST_WITH_SYNC_EVENTS,	// hs_freq and pck should be multipe
	VIDEO_BURST_WITH_SYNC_PULSES,
}dsih_video_mode_t;

#ifdef CONFIG_FBCON_DRAW_PANIC_TEXT
extern int kpanic_in_progress;
#endif

/*struct sf_fb_dev_cmds.cmds must follow this format*/
struct wr_cmd_hdr {
	u8 wait;
	u8 cmd_type0;
	u8 cmd_type1;
	u8 dlen;
} __packed;

struct sf_fb_dev_cmds {
	unsigned char *cmds;
	unsigned short n_pack;
	unsigned short n_cmds;
};

struct bl_cmds {
	struct sf_fb_dev_cmds bl_cmd;
	unsigned int brightness_bit;
};

struct mipi_color_bits {
	unsigned int color_bits; // must be set !!
	unsigned int is_18bit_loosely; // optional
};

struct rw_timeout {
	unsigned int hs_rd_to_cnt;
	unsigned int lp_rd_to_cnt;
	unsigned int hs_wr_to_cnt;
	unsigned int lp_wr_to_cnt;
	unsigned int bta_to_cnt;
};

struct video_mode_info {
	unsigned int hsync;	/* Horizontal Synchronization, unit : pclk. */
	unsigned int hbp;	/* Horizontal Back Porch, unit : pclk. */
	unsigned int hfp;	/* Horizontal Front Porch, unit : pclk. */
	unsigned int vsync;	/* Vertical Synchronization, unit : line. */
	unsigned int vbp;	/* Vertical Back Porch, unit : line. */
	unsigned int vfp;	/* Vertical Front Porch, unit : line. */
	unsigned int sync_pol;
	unsigned int lp_cmd_en:1;
	unsigned int frame_bta_ack:1;
	unsigned int lp_hfp_en:1; // default should be 1
	unsigned int lp_hbp_en:1;
	unsigned int lp_vact_en:1;
	unsigned int lp_vfp_en:1;
	unsigned int lp_vbp_en:1;
	unsigned int lp_vsa_en:1;
	dsih_video_mode_t mipi_trans_type; /* burst or no burst*/
};

struct command_mode_info {
	unsigned int tear_fx_en:1;
	unsigned int ack_rqst_en:1;
	unsigned int gen_sw_0p_tx:1;	// default should be 1
	unsigned int gen_sw_1p_tx:1;	// default should be 1
	unsigned int gen_sw_2p_tx:1;	// default should be 1
	unsigned int gen_sr_0p_tx:1;	// default should be 1
	unsigned int gen_sr_1p_tx:1;	// default should be 1
	unsigned int gen_sr_2p_tx:1;	// default should be 1
	unsigned int gen_lw_tx:1;		// default should be 1
	unsigned int dcs_sw_0p_tx:1;	// default should be 1
	unsigned int dcs_sw_1p_tx:1;	// default should be 1
	unsigned int dcs_sr_0p_tx:1;	// default should be 1
	unsigned int dcs_lw_tx:1;		// default should be 1
	unsigned int max_rd_pkt_size:1;	// default should be 1
	struct rw_timeout timeout;
};

struct external_info {
	unsigned char crc_rx_en:1;
	unsigned char ecc_rx_en:1;
	unsigned char eotp_rx_en:1;
	unsigned char eotp_tx_en:1;
	unsigned int dev_read_time;	//HSBYTECLK is danwe
};

struct phy_time_info {
	unsigned char lpx;
	//unsigned char clk_lpx;
	unsigned char clk_tprepare;
	unsigned char clk_hs_zero;
	unsigned char clk_hs_trail;
	unsigned char clk_hs_exit;
	unsigned char clk_hs_post;

	//unsigned char data_lpx;
	unsigned char data_tprepare;
	unsigned char data_hs_zero;
	unsigned char data_hs_trail;
	unsigned char data_hs_exit;
	unsigned char data_hs_post;
};

struct te_info {
	unsigned int te_source;
	unsigned int te_trigger_mode;
	unsigned int te_en;
	unsigned int te_sync_en; // In command mode should set 1,  video should set 0
	unsigned int te_cps;	// te count per second
};

struct sf_fb_timing_mipi {
	unsigned int hs_freq; /*PHY output freq, bytes KHZ*/
	unsigned int lp_freq; /*default is 10MHZ*/
	unsigned int fps;
	unsigned int dphy_bps;
	unsigned int dsi_burst_mode;
	unsigned int dsi_sync_pulse;
	unsigned int dsi_hsa;
	unsigned int dsi_hbp;
	unsigned int dsi_hfp;
	unsigned int dsi_vsa;
	unsigned int dsi_vbp;
	unsigned int dsi_vfp;
	unsigned int no_lanes; /*lane numbers*/
	unsigned int display_mode; //video mode or command mode.
	unsigned int auto_stop_clklane_en;
	unsigned int im_pin_val; /*IM PIN val, if use gpio_im, default config is 1  ?? */
	struct mipi_color_bits color_mode; /*color bits*/
	struct video_mode_info videomode_info;
	struct command_mode_info commandmode_info;
	struct phy_time_info phytime_info;
	struct te_info teinfo;
	struct external_info ext_info;
};

struct sf_fb_timing_rgb {
	struct video_mode_info videomode_info;
};

struct rd_cmd_hdr {
	unsigned char pack_type;
	unsigned char cmd;
	unsigned char id_count;
} __packed;
struct common_id_info {
	struct rd_cmd_hdr hdr;
	unsigned char id[6];
} __packed;

struct sf_fb_id_info {
	unsigned char num_id_info;
	struct common_id_info *id_info;
	struct sf_fb_dev_cmds prepare_cmd;
};

struct prefer_ce_info {
	int type;
	struct sf_fb_dev_cmds cmds;
};

struct sf_fb_prefer_ce {
	int types;
	struct prefer_ce_info *info;
};

struct sf_fb_display_dev {
	const char* name;	/* Device name. */
	unsigned int interface_info;//interface infomation  MIPI or RGB
	unsigned int lcd_id;
	unsigned int refresh_en;	/* Refresh enable. */
	unsigned int pclk;		/* Pixel clock in HZ. */
	unsigned int bpp;		/* Bits per pixel. */
	unsigned int xres;		/* Device resolution. */
	unsigned int yres;
	unsigned int width;		/* Width of device in mm. */
	unsigned int height;		/* Height of device in mm. */
	unsigned int flags;		/* Device flags. */
	unsigned int auto_fps;		/* auto adjust frame rate flag*/
	unsigned int send_suspend_cmd_in_hs_mode;   /* send suspend cmd is hs mode */

	struct {
		struct sf_fb_timing_rgb rgb;
		//struct comipfb_dev_timing_rgb rgb;
		struct sf_fb_timing_mipi mipi;
	} timing;

	struct sf_fb_id_info panel_id_info;
	struct sf_fb_id_info esd_id_info;
	struct sf_fb_dev_cmds cmds_init;
	struct sf_fb_dev_cmds cmds_suspend;
	struct sf_fb_dev_cmds cmds_resume;
	struct sf_fb_dev_cmds cmds_pre_suspend;
	struct bl_cmds backlight_info;

	struct sf_fb_prefer_ce resume_prefer_info;
	struct sf_fb_prefer_ce display_prefer_info;
	struct sf_fb_prefer_ce display_ce_info;
	int init_last;		/*when resume, send gamma/ce cmd before init cmd*/
	u32 rst_seq[RST_SEQ_LEN];
	u32 rst_seq_len;

	int (*power)(struct sf_fb_data *fb_data, int onoff);
	int (*reset)(struct sf_fb_data *fb_data);
	int (*suspend)(struct sf_fb_data *fb_data);
	int (*resume)(struct sf_fb_data *fb_data);
};

extern int sf_fb_display_dev_register(struct sf_fb_display_dev* dev);
extern int sf_fb_display_dev_unregister(struct sf_fb_display_dev* dev);
extern struct sf_fb_display_dev* sf_fb_display_dev_get_by_name(char *dev_name);
extern struct sf_fb_display_dev* sf_fb_display_dev_get(struct sf_fb_data *fb_data);

#endif /*__SF_FB_DISPLAY_DEV_H_*/