2020-04-04 18:51:11 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2019-08-07 04:58:36 +02:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <device/mmio.h>
|
|
|
|
#include <delay.h>
|
|
|
|
#include <soc/dsi.h>
|
|
|
|
#include <soc/pll.h>
|
2020-07-22 11:45:07 +02:00
|
|
|
#include <types.h>
|
2019-08-07 04:58:36 +02:00
|
|
|
|
2020-02-11 11:33:57 +01:00
|
|
|
void mtk_dsi_configure_mipi_tx(u32 data_rate, u32 lanes)
|
2019-08-07 04:58:36 +02:00
|
|
|
{
|
2020-02-11 11:33:57 +01:00
|
|
|
unsigned int txdiv0, txdiv1;
|
2019-08-07 04:58:36 +02:00
|
|
|
u64 pcw;
|
|
|
|
|
2020-02-11 11:33:57 +01:00
|
|
|
if (data_rate >= 2000 * MHz) {
|
2019-08-07 04:58:36 +02:00
|
|
|
txdiv0 = 0;
|
|
|
|
txdiv1 = 0;
|
2020-02-11 11:33:57 +01:00
|
|
|
} else if (data_rate >= 1000 * MHz) {
|
2019-08-07 04:58:36 +02:00
|
|
|
txdiv0 = 1;
|
|
|
|
txdiv1 = 0;
|
2020-02-11 11:33:57 +01:00
|
|
|
} else if (data_rate >= 500 * MHz) {
|
2019-08-07 04:58:36 +02:00
|
|
|
txdiv0 = 2;
|
|
|
|
txdiv1 = 0;
|
2020-02-11 11:33:57 +01:00
|
|
|
} else if (data_rate > 250 * MHz) {
|
|
|
|
/* (data_rate == 250MHz) is a special case that should go to the
|
|
|
|
else-block below (txdiv0 = 4) */
|
2019-08-07 04:58:36 +02:00
|
|
|
txdiv0 = 3;
|
|
|
|
txdiv1 = 0;
|
|
|
|
} else {
|
|
|
|
/* MIN = 125 */
|
2020-02-11 11:33:57 +01:00
|
|
|
assert(data_rate >= MTK_DSI_DATA_RATE_MIN_MHZ * MHz);
|
2019-08-07 04:58:36 +02:00
|
|
|
txdiv0 = 4;
|
|
|
|
txdiv1 = 0;
|
|
|
|
}
|
|
|
|
|
2019-12-03 07:03:27 +01:00
|
|
|
clrbits32(&mipi_tx->pll_con4, BIT(11) | BIT(10));
|
|
|
|
setbits32(&mipi_tx->pll_pwr, AD_DSI_PLL_SDM_PWR_ON);
|
2019-08-07 04:58:36 +02:00
|
|
|
udelay(30);
|
2019-12-03 07:03:27 +01:00
|
|
|
clrbits32(&mipi_tx->pll_pwr, AD_DSI_PLL_SDM_ISO_EN);
|
2019-08-07 04:58:36 +02:00
|
|
|
|
|
|
|
pcw = (u64)data_rate * (1 << txdiv0) * (1 << txdiv1);
|
|
|
|
pcw <<= 24;
|
2020-02-11 11:33:57 +01:00
|
|
|
pcw /= CLK26M_HZ;
|
2019-08-07 04:58:36 +02:00
|
|
|
|
|
|
|
write32(&mipi_tx->pll_con0, pcw);
|
2019-12-03 07:03:27 +01:00
|
|
|
clrsetbits32(&mipi_tx->pll_con1, RG_DSI_PLL_POSDIV, txdiv0 << 8);
|
2019-08-07 04:58:36 +02:00
|
|
|
udelay(30);
|
2019-12-03 07:03:27 +01:00
|
|
|
setbits32(&mipi_tx->pll_con1, RG_DSI_PLL_EN);
|
2019-08-07 04:58:36 +02:00
|
|
|
|
|
|
|
/* BG_LPF_EN / BG_CORE_EN */
|
|
|
|
write32(&mipi_tx->lane_con, 0x3fff0180);
|
|
|
|
udelay(40);
|
|
|
|
write32(&mipi_tx->lane_con, 0x3fff00c0);
|
|
|
|
|
|
|
|
/* Switch OFF each Lane */
|
2019-12-03 07:03:27 +01:00
|
|
|
clrbits32(&mipi_tx->d0_sw_ctl_en, DSI_SW_CTL_EN);
|
|
|
|
clrbits32(&mipi_tx->d1_sw_ctl_en, DSI_SW_CTL_EN);
|
|
|
|
clrbits32(&mipi_tx->d2_sw_ctl_en, DSI_SW_CTL_EN);
|
|
|
|
clrbits32(&mipi_tx->d3_sw_ctl_en, DSI_SW_CTL_EN);
|
|
|
|
clrbits32(&mipi_tx->ck_sw_ctl_en, DSI_SW_CTL_EN);
|
2019-08-07 04:58:36 +02:00
|
|
|
|
2019-12-03 07:03:27 +01:00
|
|
|
setbits32(&mipi_tx->ck_ckmode_en, DSI_CK_CKMODE_EN);
|
2019-08-07 04:58:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void mtk_dsi_reset(void)
|
|
|
|
{
|
|
|
|
write32(&dsi0->dsi_force_commit,
|
|
|
|
DSI_FORCE_COMMIT_USE_MMSYS | DSI_FORCE_COMMIT_ALWAYS);
|
|
|
|
write32(&dsi0->dsi_con_ctrl, 1);
|
|
|
|
write32(&dsi0->dsi_con_ctrl, 0);
|
|
|
|
}
|