coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
dsi.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <assert.h>
4 #include <device/mmio.h>
5 #include <console/console.h>
6 #include <delay.h>
7 #include <soc/dsi.h>
8 #include <timer.h>
9 
10 void mtk_dsi_configure_mipi_tx(u32 data_rate, u32 lanes)
11 {
12  u32 txdiv0, txdiv1;
13  u64 pcw;
14  u32 reg;
15  int i;
16 
17  reg = read32(&mipi_tx0->dsi_bg_con);
18 
19  reg = (reg & (~RG_DSI_V02_SEL)) | (4 << 20);
20  reg = (reg & (~RG_DSI_V032_SEL)) | (4 << 17);
21  reg = (reg & (~RG_DSI_V04_SEL)) | (4 << 14);
22  reg = (reg & (~RG_DSI_V072_SEL)) | (4 << 11);
23  reg = (reg & (~RG_DSI_V10_SEL)) | (4 << 8);
24  reg = (reg & (~RG_DSI_V12_SEL)) | (4 << 5);
25  reg |= RG_DSI_BG_CKEN;
26  reg |= RG_DSI_BG_CORE_EN;
27  write32(&mipi_tx0->dsi_bg_con, reg);
28  udelay(30);
29 
31  8 << 4 | RG_DSI_LNT_HS_BIAS_EN);
32 
35 
38 
40 
41  if (data_rate > 500 * MHz) {
42  txdiv0 = 0;
43  txdiv1 = 0;
44  } else if (data_rate >= 250 * MHz) {
45  txdiv0 = 1;
46  txdiv1 = 0;
47  } else if (data_rate >= 125 * MHz) {
48  txdiv0 = 2;
49  txdiv1 = 0;
50  } else if (data_rate >= 62 * MHz) {
51  txdiv0 = 2;
52  txdiv1 = 1;
53  } else {
54  /* MIN = 50 */
55  assert(data_rate >= MTK_DSI_DATA_RATE_MIN_MHZ * MHz);
56  txdiv0 = 2;
57  txdiv1 = 2;
58  }
59 
62  RG_DSI0_MPPLL_PREDIV, txdiv1 << 5 | txdiv0 << 3);
63 
64  /**
65  * PLL PCW config
66  * PCW bit 24~30 = integer part of pcw
67  * PCW bit 0~23 = fractional part of pcw
68  * pcw = data_Rate*4*txdiv/(Ref_clk*2);
69  * Post DIV =4, so need data_Rate*4
70  * Ref_clk is 26MHz
71  */
72  pcw = (u64)(data_rate * (1 << txdiv0) * (1 << txdiv1)) << 24;
73  pcw /= 13 * MHz;
75 
77 
79 
80  for (i = 0; i < lanes; i++)
82 
84 
85  udelay(40);
86 
89 }
90 
91 void mtk_dsi_reset(void)
92 {
95 }
96 
98 {
99  int lpx = 5;
100  timing->lpx = lpx;
101  timing->da_hs_prepare = 6;
102  timing->da_hs_zero = 10;
103  timing->da_hs_trail = 8;
104 
105  timing->ta_go = 4 * lpx;
106  timing->ta_sure = 3 * lpx / 2;
107  timing->ta_get = 5 * lpx;
108  timing->da_hs_exit = 7;
109 
110  timing->da_hs_sync = 0;
111  timing->clk_hs_exit = 2 * lpx;
112 
113  timing->d_phy = 12;
114 }
115 
117 {
118  struct stopwatch sw;
119  uint32_t pwr_ack;
120 
122 
123  stopwatch_init_usecs_expire(&sw, 1000);
124 
125  do {
126  if (stopwatch_expired(&sw)) {
127  printk(BIOS_ERR, "enable lvdstx_power failed!!!\n");
128  return;
129  }
131  } while (pwr_ack == 0);
132 
134 }
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#define assert(statement)
Definition: assert.h:74
#define MHz
Definition: helpers.h:80
#define printk(level,...)
Definition: stdlib.h:16
static struct dsi_regs *const dsi0
Definition: dsi_common.h:87
#define setbits32(addr, set)
Definition: mmio.h:21
#define clrsetbits32(addr, clear, set)
Definition: mmio.h:16
#define clrbits32(addr, clear)
Definition: mmio.h:26
static int stopwatch_expired(struct stopwatch *sw)
Definition: timer.h:152
static void stopwatch_init_usecs_expire(struct stopwatch *sw, long us)
Definition: timer.h:127
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
__weak void mtk_dsi_override_phy_timing(struct mtk_phy_timing *timing)
Definition: dsi.c:62
void mtk_dsi_pin_drv_ctrl(void)
Definition: dsi.c:116
void mtk_dsi_configure_mipi_tx(u32 data_rate, u32 lanes)
Definition: dsi.c:10
void mtk_dsi_reset(void)
Definition: dsi.c:91
@ RG_DSI0_MPPLL_PREDIV
Definition: dsi.h:110
@ RG_DSI0_MPPLL_TXDIV0
Definition: dsi.h:111
@ RG_DSI0_MPPLL_PLL_EN
Definition: dsi.h:109
@ RG_DSI0_MPPLL_TXDIV1
Definition: dsi.h:112
@ RG_DSI0_MPPLL_SDM_SSC_EN
Definition: dsi.h:123
@ RG_DSI0_MPPLL_SDM_FRA_EN
Definition: dsi.h:121
@ RG_DSI_BG_CKEN
Definition: dsi.h:93
@ RG_DSI_BG_CORE_EN
Definition: dsi.h:92
@ RG_DSI_V04_SEL
Definition: dsi.h:99
@ RG_DSI_V10_SEL
Definition: dsi.h:97
@ RG_DSI_V072_SEL
Definition: dsi.h:98
@ RG_DSI_V032_SEL
Definition: dsi.h:100
@ RG_DSI_V12_SEL
Definition: dsi.h:96
@ RG_DSI_V02_SEL
Definition: dsi.h:101
@ RG_DSI_MPPLL_SDM_PWR_ON
Definition: dsi.h:129
@ RG_DSI_MPPLL_SDM_ISO_EN
Definition: dsi.h:130
#define MTK_DSI_DATA_RATE_MIN_MHZ
Definition: dsi.h:12
@ RG_DSI_LNT_HS_BIAS_EN
Definition: dsi.h:80
@ RG_DSI_PAD_TIE_LOW_EN
Definition: dsi.h:85
@ RG_DSI_LNT_IMP_CAL_CODE
Definition: dsi.h:83
@ RG_DA_LVDSTX_PWR_ON
Definition: dsi.h:157
@ RG_DA_LVDS_ISO_EN
Definition: dsi.h:156
@ RG_AD_LVDSTX_PWR_ACK
Definition: dsi.h:155
static struct mipi_tx_regs *const mipi_tx0
Definition: dsi.h:51
static struct lvds_tx1_regs *const lvds_tx1
Definition: dsi.h:146
@ LDOOUT_EN
Definition: dsi.h:67
@ RG_DSI0_LDOCORE_EN
Definition: dsi.h:56
@ RG_DSI0_CKG_LDOOUT_EN
Definition: dsi.h:57
uint64_t u64
Definition: stdint.h:54
unsigned int uint32_t
Definition: stdint.h:14
uint32_t u32
Definition: stdint.h:51
u32 dsi_con_ctrl
Definition: dsi_common.h:53
u32 vopll_ctl3
Definition: dsi.h:143
u32 dsi_data_lane[4]
Definition: dsi.h:22
u32 dsi_pll_con2
Definition: dsi.h:29
u32 dsi_bg_con
Definition: dsi.h:25
u32 dsi_pll_con0
Definition: dsi.h:27
u32 dsi_pll_con1
Definition: dsi.h:28
u32 dsi_pll_pwr
Definition: dsi.h:33
u32 dsi_top_con
Definition: dsi.h:24
u32 dsi_con
Definition: dsi.h:20
u32 dsi_clock_lane
Definition: dsi.h:21
void udelay(uint32_t us)
Definition: udelay.c:15