Angel Pons | e67ab18 | 2020-04-04 18:51:11 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 2 | |
| 3 | #include <assert.h> |
| 4 | #include <device/mmio.h> |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 5 | #include <delay.h> |
| 6 | #include <soc/dsi.h> |
| 7 | #include <soc/pll.h> |
Elyes HAOUAS | 29c4d1b | 2020-07-22 11:45:07 +0200 | [diff] [blame] | 8 | #include <types.h> |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 9 | |
Yu-Ping Wu | 443fbd7 | 2020-02-11 18:33:57 +0800 | [diff] [blame] | 10 | void mtk_dsi_configure_mipi_tx(u32 data_rate, u32 lanes) |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 11 | { |
Yu-Ping Wu | 443fbd7 | 2020-02-11 18:33:57 +0800 | [diff] [blame] | 12 | unsigned int txdiv0, txdiv1; |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 13 | u64 pcw; |
| 14 | |
Yu-Ping Wu | 443fbd7 | 2020-02-11 18:33:57 +0800 | [diff] [blame] | 15 | if (data_rate >= 2000 * MHz) { |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 16 | txdiv0 = 0; |
| 17 | txdiv1 = 0; |
Yu-Ping Wu | 443fbd7 | 2020-02-11 18:33:57 +0800 | [diff] [blame] | 18 | } else if (data_rate >= 1000 * MHz) { |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 19 | txdiv0 = 1; |
| 20 | txdiv1 = 0; |
Yu-Ping Wu | 443fbd7 | 2020-02-11 18:33:57 +0800 | [diff] [blame] | 21 | } else if (data_rate >= 500 * MHz) { |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 22 | txdiv0 = 2; |
| 23 | txdiv1 = 0; |
Yu-Ping Wu | 443fbd7 | 2020-02-11 18:33:57 +0800 | [diff] [blame] | 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) */ |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 27 | txdiv0 = 3; |
| 28 | txdiv1 = 0; |
| 29 | } else { |
| 30 | /* MIN = 125 */ |
Yu-Ping Wu | 443fbd7 | 2020-02-11 18:33:57 +0800 | [diff] [blame] | 31 | assert(data_rate >= MTK_DSI_DATA_RATE_MIN_MHZ * MHz); |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 32 | txdiv0 = 4; |
| 33 | txdiv1 = 0; |
| 34 | } |
| 35 | |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 36 | clrbits32(&mipi_tx->pll_con4, BIT(11) | BIT(10)); |
| 37 | setbits32(&mipi_tx->pll_pwr, AD_DSI_PLL_SDM_PWR_ON); |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 38 | udelay(30); |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 39 | clrbits32(&mipi_tx->pll_pwr, AD_DSI_PLL_SDM_ISO_EN); |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 40 | |
| 41 | pcw = (u64)data_rate * (1 << txdiv0) * (1 << txdiv1); |
| 42 | pcw <<= 24; |
Yu-Ping Wu | 443fbd7 | 2020-02-11 18:33:57 +0800 | [diff] [blame] | 43 | pcw /= CLK26M_HZ; |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 44 | |
| 45 | write32(&mipi_tx->pll_con0, pcw); |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 46 | clrsetbits32(&mipi_tx->pll_con1, RG_DSI_PLL_POSDIV, txdiv0 << 8); |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 47 | udelay(30); |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 48 | setbits32(&mipi_tx->pll_con1, RG_DSI_PLL_EN); |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 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 */ |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 56 | clrbits32(&mipi_tx->d0_sw_ctl_en, DSI_SW_CTL_EN); |
| 57 | clrbits32(&mipi_tx->d1_sw_ctl_en, DSI_SW_CTL_EN); |
| 58 | clrbits32(&mipi_tx->d2_sw_ctl_en, DSI_SW_CTL_EN); |
| 59 | clrbits32(&mipi_tx->d3_sw_ctl_en, DSI_SW_CTL_EN); |
| 60 | clrbits32(&mipi_tx->ck_sw_ctl_en, DSI_SW_CTL_EN); |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 61 | |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 62 | setbits32(&mipi_tx->ck_ckmode_en, DSI_CK_CKMODE_EN); |
Hung-Te Lin | 32ddc0d | 2019-08-07 10:58:36 +0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | void mtk_dsi_reset(void) |
| 66 | { |
| 67 | write32(&dsi0->dsi_force_commit, |
| 68 | DSI_FORCE_COMMIT_USE_MMSYS | DSI_FORCE_COMMIT_ALWAYS); |
| 69 | write32(&dsi0->dsi_con_ctrl, 1); |
| 70 | write32(&dsi0->dsi_con_ctrl, 0); |
| 71 | } |