xref: /OK3568_Linux_fs/u-boot/drivers/video/ssd2828.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * (C) 2015 Siarhei Siamashka <siarhei.siamashka@gmail.com>
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun /*
8*4882a593Smuzhiyun  * Support for the SSD2828 bridge chip, which can take pixel data coming
9*4882a593Smuzhiyun  * from a parallel LCD interface and translate it on the flight into MIPI DSI
10*4882a593Smuzhiyun  * interface for driving a MIPI compatible TFT display.
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  * Implemented as a utility function. To be used from display drivers, which are
13*4882a593Smuzhiyun  * responsible for driving parallel LCD hardware in front of the video pipeline.
14*4882a593Smuzhiyun  */
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #ifndef _SSD2828_H
17*4882a593Smuzhiyun #define _SSD2828_H
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun struct ctfb_res_modes;
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun struct ssd2828_config {
22*4882a593Smuzhiyun 	/*********************************************************************/
23*4882a593Smuzhiyun 	/* SSD2828 configuration                                             */
24*4882a593Smuzhiyun 	/*********************************************************************/
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun 	/*
27*4882a593Smuzhiyun 	 * The pins, which are used for SPI communication. This is only used
28*4882a593Smuzhiyun 	 * for configuring SSD2828, so the performance is irrelevant (only
29*4882a593Smuzhiyun 	 * around a hundred of bytes is moved). Also these can be any arbitrary
30*4882a593Smuzhiyun 	 * GPIO pins (not necessarily the pins having hardware SPI function).
31*4882a593Smuzhiyun 	 * Moreover, the 'sdo' pin may be even not wired up in some devices.
32*4882a593Smuzhiyun 	 *
33*4882a593Smuzhiyun 	 * These configuration variables need to be set as pin numbers for
34*4882a593Smuzhiyun 	 * the standard u-boot GPIO interface (gpio_get_value/gpio_set_value
35*4882a593Smuzhiyun 	 * functions). Note that -1 value can be used for the pins, which are
36*4882a593Smuzhiyun 	 * not really wired up.
37*4882a593Smuzhiyun 	 */
38*4882a593Smuzhiyun 	int csx_pin;
39*4882a593Smuzhiyun 	int sck_pin;
40*4882a593Smuzhiyun 	int sdi_pin;
41*4882a593Smuzhiyun 	int sdo_pin;
42*4882a593Smuzhiyun 	/* SSD2828 reset pin (shared with LCD panel reset) */
43*4882a593Smuzhiyun 	int reset_pin;
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun 	/*
46*4882a593Smuzhiyun 	 * The SSD2828 has its own dedicated clock source 'tx_clk' (connected
47*4882a593Smuzhiyun 	 * to TX_CLK_XIO/TX_CLK_XIN pins), which is necessary at least for
48*4882a593Smuzhiyun 	 * clocking SPI after reset. The exact clock speed is not strictly,
49*4882a593Smuzhiyun 	 * defined, but the datasheet says that it must be somewhere in the
50*4882a593Smuzhiyun 	 * 8MHz - 30MHz range (see "TX_CLK Timing" section). It can be also
51*4882a593Smuzhiyun 	 * used as a reference clock for PLL. If the exact clock frequency
52*4882a593Smuzhiyun 	 * is known, then it can be specified here. If it is unknown, or the
53*4882a593Smuzhiyun 	 * information is not trustworthy, then it can be set to 0.
54*4882a593Smuzhiyun 	 *
55*4882a593Smuzhiyun 	 * If unsure, set to 0.
56*4882a593Smuzhiyun 	 */
57*4882a593Smuzhiyun 	int ssd2828_tx_clk_khz;
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun 	/*
60*4882a593Smuzhiyun 	 * This is not a property of the used LCD panel, but more like a
61*4882a593Smuzhiyun 	 * property of the SSD2828 wiring. See the "SSD2828QN4 RGB data
62*4882a593Smuzhiyun 	 * arrangement" table in the datasheet. The SSD2828 pins are arranged
63*4882a593Smuzhiyun 	 * in such a way that 18bpp and 24bpp configurations are completely
64*4882a593Smuzhiyun 	 * incompatible with each other.
65*4882a593Smuzhiyun 	 *
66*4882a593Smuzhiyun 	 * Depending on the color depth, this must be set to 16, 18 or 24.
67*4882a593Smuzhiyun 	 */
68*4882a593Smuzhiyun 	int ssd2828_color_depth;
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun 	/*********************************************************************/
71*4882a593Smuzhiyun 	/* LCD panel configuration                                           */
72*4882a593Smuzhiyun 	/*********************************************************************/
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun 	/*
75*4882a593Smuzhiyun 	 * The number of lanes in the MIPI DSI interface. May vary from 1 to 4.
76*4882a593Smuzhiyun 	 *
77*4882a593Smuzhiyun 	 * This information can be found in the LCD panel datasheet.
78*4882a593Smuzhiyun 	 */
79*4882a593Smuzhiyun 	int mipi_dsi_number_of_data_lanes;
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun 	/*
82*4882a593Smuzhiyun 	 * Data transfer bit rate per lane. Please note that it is expected
83*4882a593Smuzhiyun 	 * to be higher than the pixel clock rate of the used video mode when
84*4882a593Smuzhiyun 	 * multiplied by the number of lanes. This is perfectly normal because
85*4882a593Smuzhiyun 	 * MIPI DSI handles data transfers in periodic bursts, and uses the
86*4882a593Smuzhiyun 	 * idle time between bursts for sending configuration information and
87*4882a593Smuzhiyun 	 * commands. Or just for saving power.
88*4882a593Smuzhiyun 	 *
89*4882a593Smuzhiyun 	 * The necessary Mbps/lane information can be found in the LCD panel
90*4882a593Smuzhiyun 	 * datasheet. Note that the transfer rate can't be always set precisely
91*4882a593Smuzhiyun 	 * and it may be rounded *up* (introducing no more than 10Mbps error).
92*4882a593Smuzhiyun 	 */
93*4882a593Smuzhiyun 	int mipi_dsi_bitrate_per_data_lane_mbps;
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun 	/*
96*4882a593Smuzhiyun 	 * Setting this to 1 enforces packing of 18bpp pixel data in 24bpp
97*4882a593Smuzhiyun 	 * envelope when sending it over the MIPI DSI link.
98*4882a593Smuzhiyun 	 *
99*4882a593Smuzhiyun 	 * If unsure, set to 0.
100*4882a593Smuzhiyun 	 */
101*4882a593Smuzhiyun 	int mipi_dsi_loosely_packed_pixel_format;
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun 	/*
104*4882a593Smuzhiyun 	 * According to the "Example for system sleep in and out" section in
105*4882a593Smuzhiyun 	 * the SSD2828 datasheet, some LCD panel specific delays are necessary
106*4882a593Smuzhiyun 	 * after MIPI DCS commands EXIT_SLEEP_MODE and SET_DISPLAY_ON.
107*4882a593Smuzhiyun 	 *
108*4882a593Smuzhiyun 	 * For example, Allwinner uses 100 milliseconds delay after
109*4882a593Smuzhiyun 	 * EXIT_SLEEP_MODE and 200 milliseconds delay after SET_DISPLAY_ON.
110*4882a593Smuzhiyun 	 */
111*4882a593Smuzhiyun 	int mipi_dsi_delay_after_exit_sleep_mode_ms;
112*4882a593Smuzhiyun 	int mipi_dsi_delay_after_set_display_on_ms;
113*4882a593Smuzhiyun };
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun /*
116*4882a593Smuzhiyun  * Initialize the SSD2828 chip. It needs the 'ssd2828_config' structure
117*4882a593Smuzhiyun  * and also the video mode timings.
118*4882a593Smuzhiyun  *
119*4882a593Smuzhiyun  * The right place to insert this function call is after the parallel LCD
120*4882a593Smuzhiyun  * interface is initialized and before turning on the backlight. This is
121*4882a593Smuzhiyun  * advised in the "Example for system sleep in and out" section of the
122*4882a593Smuzhiyun  * SSD2828 datasheet. And also SS2828 may use 'pclk' as the clock source
123*4882a593Smuzhiyun  * for PLL, which means that the input signal must be already there.
124*4882a593Smuzhiyun  */
125*4882a593Smuzhiyun int ssd2828_init(const struct ssd2828_config *cfg,
126*4882a593Smuzhiyun 		 const struct ctfb_res_modes *mode);
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun #endif
129