2020#include "di.h"
2121#include <power/max77620.h>
2222#include <power/max7762x.h>
23+ #include <mem/heap.h>
2324#include <soc/clock.h>
2425#include <soc/gpio.h>
2526#include <soc/hw_init.h>
@@ -170,9 +171,9 @@ int display_dsi_read(u8 cmd, u32 len, void *data, bool video_enabled)
170171
171172void display_dsi_write (u8 cmd , u32 len , void * data , bool video_enabled )
172173{
174+ u8 * fifo8 ;
175+ u32 * fifo32 ;
173176 u32 host_control ;
174- u32 fifo32 [DSI_STATUS_RX_FIFO_SIZE ] = {0 };
175- u8 * fifo8 = (u8 * )fifo32 ;
176177
177178 // Enable host cmd packets during video and save host control.
178179 if (video_enabled )
@@ -193,13 +194,16 @@ void display_dsi_write(u8 cmd, u32 len, void *data, bool video_enabled)
193194 break ;
194195
195196 default :
197+ fifo32 = calloc (DSI_STATUS_RX_FIFO_SIZE * 8 , 4 );
198+ fifo8 = (u8 * )fifo32 ;
196199 fifo32 [0 ] = (len << 8 ) | MIPI_DSI_DCS_LONG_WRITE ;
197200 fifo8 [4 ] = cmd ;
198201 memcpy (& fifo8 [5 ], data , len );
199202 len += 4 + 1 ; // Increase length by CMD/length word and DCS CMD.
200203 for (u32 i = 0 ; i < (ALIGN (len , 4 ) / 4 ); i ++ )
201204 DSI (_DSIREG (DSI_WR_DATA )) = fifo32 [i ];
202205 DSI (_DSIREG (DSI_TRIGGER )) = DSI_TRIGGER_HOST ;
206+ free (fifo32 );
203207 break ;
204208 }
205209
@@ -215,29 +219,30 @@ void display_dsi_write(u8 cmd, u32 len, void *data, bool video_enabled)
215219void display_init ()
216220{
217221 // Check if display is already initialized.
218- if (CLOCK (CLK_RST_CONTROLLER_CLK_ENB_L_SET ) & BIT (CLK_L_DISP1 ))
222+ if (CLOCK (CLK_RST_CONTROLLER_CLK_OUT_ENB_L ) & BIT (CLK_L_DISP1 ))
219223 _display_panel_and_hw_end (true);
220224
221225 // Get Chip ID.
222226 bool tegra_t210 = hw_get_chip_id () == GP_HIDREV_MAJOR_T210 ;
223227
224- // T210B01: Power on SD2 regulator for supplying LD0 .
228+ // T210B01: Power on SD2 regulator for supplying LDO0 .
225229 if (!tegra_t210 )
226230 {
227231 // Set SD2 regulator voltage.
228- max77620_regulator_set_voltage (REGULATOR_SD2 , 1325000 );
232+ max7762x_regulator_set_voltage (REGULATOR_SD2 , 1325000 );
229233
230234 // Set slew rate and enable SD2 regulator.
231235 i2c_send_byte (I2C_5 , MAX77620_I2C_ADDR , MAX77620_REG_SD2_CFG , (1 << MAX77620_SD_SR_SHIFT ) | MAX77620_SD_CFG1_FSRADE_SD_ENABLE );
232- max77620_regulator_enable (REGULATOR_SD2 , 1 );
236+ max7762x_regulator_enable (REGULATOR_SD2 , true );
233237
234238 }
235239
236240 // Enable power to display panel controller.
237- max77620_regulator_set_volt_and_flags (REGULATOR_LDO0 , 1200000 , MAX77620_POWER_MODE_NORMAL ); // Configure to 1.2V.
241+ max7762x_regulator_set_voltage (REGULATOR_LDO0 , 1200000 );
242+ max7762x_regulator_enable (REGULATOR_LDO0 , true);
243+
238244 if (tegra_t210 )
239- i2c_send_byte (I2C_5 , MAX77620_I2C_ADDR , MAX77620_REG_GPIO7 ,
240- MAX77620_CNFG_GPIO_OUTPUT_VAL_HIGH | MAX77620_CNFG_GPIO_DRV_PUSHPULL ); // T210: LD0 -> GPIO7 -> Display panel.
245+ max77620_config_gpio (7 , MAX77620_GPIO_OUTPUT_ENABLE ); // T210: LD0 -> GPIO7 -> Display panel.
241246
242247 // Enable Display Interface specific clocks.
243248 CLOCK (CLK_RST_CONTROLLER_RST_DEV_H_CLR ) = BIT (CLK_H_MIPI_CAL ) | BIT (CLK_H_DSI );
@@ -293,7 +298,7 @@ void display_init()
293298
294299 // Set DISP1 clock source and parent clock.
295300 CLOCK (CLK_RST_CONTROLLER_CLK_SOURCE_DISP1 ) = 0x40000000 ; // PLLD_OUT.
296- u32 plld_div = (3 << 20 ) | (20 << 11 ) | 1 ; // DIVM: 1, DIVN: 20, DIVP: 3. PLLD_OUT: 768 MHz, PLLD_OUT0 (DSI): 96 MHz.
301+ u32 plld_div = (3 << 20 ) | (20 << 11 ) | 1 ; // DIVM: 1, DIVN: 20, DIVP: 3. PLLD_OUT: 768 MHz, PLLD_OUT0 (DSI): 97.5 MHz (offset) .
297302 CLOCK (CLK_RST_CONTROLLER_PLLD_BASE ) = PLLCX_BASE_ENABLE | PLLCX_BASE_LOCK | plld_div ;
298303
299304 if (tegra_t210 )
@@ -335,9 +340,12 @@ void display_init()
335340
336341#if 0
337342 // Get Display ID.
338- _display_id = 0xCCCCCC ;
343+ _display_id = 0xCCCCCC ; // Set initial value. 4th byte cleared.
339344 display_dsi_read (MIPI_DCS_GET_DISPLAY_ID , 3 , & _display_id , DSI_VIDEO_DISABLED );
340345#else
346+ // Drain RX FIFO.
347+ _display_dsi_read_rx_fifo (NULL );
348+
341349 // Set reply size.
342350 _display_dsi_send_cmd (MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE , 3 , 0 );
343351 _display_dsi_wait (250000 , _DSIREG (DSI_TRIGGER ), DSI_TRIGGER_HOST | DSI_TRIGGER_VIDEO );
@@ -407,11 +415,11 @@ void display_init()
407415 _display_dsi_send_cmd (MIPI_DSI_DCS_SHORT_WRITE , MIPI_DCS_SET_DISPLAY_ON , 20000 );
408416
409417 // Configure PLLD for DISP1.
410- plld_div = (1 << 20 ) | (24 << 11 ) | 1 ; // DIVM: 1, DIVN: 24, DIVP: 1. PLLD_OUT: 768 MHz, PLLD_OUT0 (DSI): 230.4 MHz.
418+ plld_div = (1 << 20 ) | (24 << 11 ) | 1 ; // DIVM: 1, DIVN: 24, DIVP: 1. PLLD_OUT: 768 MHz, PLLD_OUT0 (DSI): 234 MHz (offset) .
411419 CLOCK (CLK_RST_CONTROLLER_PLLD_BASE ) = PLLCX_BASE_ENABLE | PLLCX_BASE_LOCK | plld_div ;
412420
413421 if (tegra_t210 )
414- CLOCK (CLK_RST_CONTROLLER_PLLD_MISC1 ) = 0x20 ; // PLLD_SETUP
422+ CLOCK (CLK_RST_CONTROLLER_PLLD_MISC1 ) = 0x20 ; // PLLD_SETUP.
415423 else
416424 CLOCK (CLK_RST_CONTROLLER_PLLD_MISC1 ) = 0 ;
417425 CLOCK (CLK_RST_CONTROLLER_PLLD_MISC ) = 0x2DFC00 ; // Use new PLLD_SDM_DIN.
@@ -420,7 +428,7 @@ void display_init()
420428 DSI (_DSIREG (DSI_PAD_CONTROL_1 )) = 0 ;
421429 DSI (_DSIREG (DSI_PHY_TIMING_0 )) = tegra_t210 ? 0x6070601 : 0x6070603 ;
422430 exec_cfg ((u32 * )DSI_BASE , _display_dsi_packet_config , 19 );
423- // Set pixel clock dividers: 230.4 / 3 / 1 = 76.8 MHz. 60 Hz.
431+ // Set pixel clock dividers: 234 / 3 / 1 = 78 MHz (offset) for 60 Hz.
424432 DISPLAY_A (_DIREG (DC_DISP_DISP_CLOCK_CONTROL )) = PIXEL_CLK_DIVIDER_PCD1 | SHIFT_CLK_DIVIDER (4 ); // 4: div3.
425433 exec_cfg ((u32 * )DSI_BASE , _display_dsi_mode_config , 10 );
426434 usleep (10000 );
@@ -600,11 +608,20 @@ static void _display_panel_and_hw_end(bool no_panel_deinit)
600608
601609void display_end () { _display_panel_and_hw_end (false); };
602610
603- u16 display_get_decoded_lcd_id ()
611+ u16 display_get_decoded_panel_id ()
604612{
605613 return _display_id ;
606614}
607615
616+ void display_set_decoded_panel_id (u32 id )
617+ {
618+ // Decode Display ID.
619+ _display_id = ((id >> 8 ) & 0xFF00 ) | (id & 0xFF );
620+
621+ if ((_display_id & 0xFF ) == PANEL_JDI_XXX062M )
622+ _display_id = PANEL_JDI_XXX062M ;
623+ }
624+
608625void display_color_screen (u32 color )
609626{
610627 exec_cfg ((u32 * )DISPLAY_A_BASE , cfg_display_one_color , 8 );
0 commit comments