coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
mtk_mipi_dphy.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 <delay.h>
6 #include <soc/dsi.h>
7 #include <soc/pll.h>
8 #include <types.h>
9 
10 void mtk_dsi_configure_mipi_tx(u32 data_rate, u32 lanes)
11 {
12  unsigned int txdiv0, txdiv1;
13  u64 pcw;
14 
15  if (data_rate >= 2000 * MHz) {
16  txdiv0 = 0;
17  txdiv1 = 0;
18  } else if (data_rate >= 1000 * MHz) {
19  txdiv0 = 1;
20  txdiv1 = 0;
21  } else if (data_rate >= 500 * MHz) {
22  txdiv0 = 2;
23  txdiv1 = 0;
24  } else if (data_rate > 250 * MHz) {
25  /* (data_rate == 250MHz) is a special case that should go to the
26  else-block below (txdiv0 = 4) */
27  txdiv0 = 3;
28  txdiv1 = 0;
29  } else {
30  /* MIN = 125 */
31  assert(data_rate >= MTK_DSI_DATA_RATE_MIN_MHZ * MHz);
32  txdiv0 = 4;
33  txdiv1 = 0;
34  }
35 
36  clrbits32(&mipi_tx->pll_con4, BIT(11) | BIT(10));
38  udelay(30);
40 
41  pcw = (u64)data_rate * (1 << txdiv0) * (1 << txdiv1);
42  pcw <<= 24;
43  pcw /= CLK26M_HZ;
44 
45  write32(&mipi_tx->pll_con0, pcw);
47  udelay(30);
49 
50  /* BG_LPF_EN / BG_CORE_EN */
51  write32(&mipi_tx->lane_con, 0x3fff0180);
52  udelay(40);
53  write32(&mipi_tx->lane_con, 0x3fff00c0);
54 
55  /* Switch OFF each Lane */
61 
63 }
64 
65 void mtk_dsi_reset(void)
66 {
71 }
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
#define assert(statement)
Definition: assert.h:74
#define MHz
Definition: helpers.h:80
@ DSI_FORCE_COMMIT_ALWAYS
Definition: dsi_common.h:213
@ DSI_FORCE_COMMIT_USE_MMSYS
Definition: dsi_common.h:212
static struct dsi_regs *const dsi0
Definition: dsi_common.h:87
#define BIT(nr)
Definition: ec_commands.h:45
#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
@ CLK26M_HZ
Definition: pll.h:215
void mtk_dsi_configure_mipi_tx(u32 data_rate, u32 lanes)
Definition: mtk_mipi_dphy.c:10
void mtk_dsi_reset(void)
Definition: mtk_mipi_dphy.c:65
#define MTK_DSI_DATA_RATE_MIN_MHZ
Definition: dsi.h:12
#define RG_DSI_PLL_POSDIV
Definition: dsi.h:54
#define RG_DSI_PLL_EN
Definition: dsi.h:53
static struct mipi_tx_regs *const mipi_tx
Definition: dsi.h:45
#define AD_DSI_PLL_SDM_ISO_EN
Definition: dsi.h:51
#define AD_DSI_PLL_SDM_PWR_ON
Definition: dsi.h:50
#define DSI_CK_CKMODE_EN
Definition: dsi.h:48
#define DSI_SW_CTL_EN
Definition: dsi.h:49
uint64_t u64
Definition: stdint.h:54
uint32_t u32
Definition: stdint.h:51
u32 dsi_con_ctrl
Definition: dsi_common.h:53
u32 dsi_force_commit
Definition: dsi_common.h:83
u32 d0_sw_ctl_en
Definition: dsi.h:32
u32 d2_sw_ctl_en
Definition: dsi.h:30
u32 ck_sw_ctl_en
Definition: dsi.h:36
u32 ck_ckmode_en
Definition: dsi.h:34
u32 d1_sw_ctl_en
Definition: dsi.h:38
u32 lane_con
Definition: dsi.h:21
u32 pll_pwr
Definition: dsi.h:23
u32 pll_con4
Definition: dsi.h:28
u32 pll_con1
Definition: dsi.h:25
u32 pll_con0
Definition: dsi.h:24
u32 d3_sw_ctl_en
Definition: dsi.h:40
void udelay(uint32_t us)
Definition: udelay.c:15