Skip to content

Commit 424a3a7

Browse files
mediatek-jitaoChun-Kuang Hu
authored andcommitted
drm/mediatek: config mipitx impedance with calibration data
Read calibration data from nvmem, and config mipitx impedance with calibration data to make sure their impedance are 100ohm. Signed-off-by: Jitao Shi <[email protected]> Signed-off-by: Chun-Kuang Hu <[email protected]>
1 parent 3d50b59 commit 424a3a7

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

drivers/gpu/drm/mediatek/mtk_mipi_tx.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,44 @@ static const struct phy_ops mtk_mipi_tx_ops = {
8888
.owner = THIS_MODULE,
8989
};
9090

91+
static void mtk_mipi_tx_get_calibration_datal(struct mtk_mipi_tx *mipi_tx)
92+
{
93+
struct nvmem_cell *cell;
94+
size_t len;
95+
u32 *buf;
96+
97+
cell = nvmem_cell_get(mipi_tx->dev, "calibration-data");
98+
if (IS_ERR(cell)) {
99+
dev_info(mipi_tx->dev, "can't get nvmem_cell_get, ignore it\n");
100+
return;
101+
}
102+
buf = (u32 *)nvmem_cell_read(cell, &len);
103+
nvmem_cell_put(cell);
104+
105+
if (IS_ERR(buf)) {
106+
dev_info(mipi_tx->dev, "can't get data, ignore it\n");
107+
return;
108+
}
109+
110+
if (len < 3 * sizeof(u32)) {
111+
dev_info(mipi_tx->dev, "invalid calibration data\n");
112+
kfree(buf);
113+
return;
114+
}
115+
116+
mipi_tx->rt_code[0] = ((buf[0] >> 6 & 0x1f) << 5) |
117+
(buf[0] >> 11 & 0x1f);
118+
mipi_tx->rt_code[1] = ((buf[1] >> 27 & 0x1f) << 5) |
119+
(buf[0] >> 1 & 0x1f);
120+
mipi_tx->rt_code[2] = ((buf[1] >> 17 & 0x1f) << 5) |
121+
(buf[1] >> 22 & 0x1f);
122+
mipi_tx->rt_code[3] = ((buf[1] >> 7 & 0x1f) << 5) |
123+
(buf[1] >> 12 & 0x1f);
124+
mipi_tx->rt_code[4] = ((buf[2] >> 27 & 0x1f) << 5) |
125+
(buf[1] >> 2 & 0x1f);
126+
kfree(buf);
127+
}
128+
91129
static int mtk_mipi_tx_probe(struct platform_device *pdev)
92130
{
93131
struct device *dev = &pdev->dev;
@@ -174,6 +212,8 @@ static int mtk_mipi_tx_probe(struct platform_device *pdev)
174212

175213
mipi_tx->dev = dev;
176214

215+
mtk_mipi_tx_get_calibration_datal(mipi_tx);
216+
177217
return of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
178218
mipi_tx->pll);
179219
}

drivers/gpu/drm/mediatek/mtk_mipi_tx.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
#include <linux/delay.h>
1313
#include <linux/io.h>
1414
#include <linux/module.h>
15+
#include <linux/nvmem-consumer.h>
1516
#include <linux/of_device.h>
1617
#include <linux/platform_device.h>
1718
#include <linux/phy/phy.h>
19+
#include <linux/slab.h>
1820

1921
struct mtk_mipitx_data {
2022
const u32 mppll_preserve;
@@ -28,6 +30,7 @@ struct mtk_mipi_tx {
2830
void __iomem *regs;
2931
u32 data_rate;
3032
u32 mipitx_drive;
33+
u32 rt_code[5];
3134
const struct mtk_mipitx_data *driver_data;
3235
struct clk_hw pll_hw;
3336
struct clk *pll;

drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define MIPITX_PLL_CON4 0x003c
2929
#define RG_DSI_PLL_IBIAS (3 << 10)
3030

31+
#define MIPITX_D2P_RTCODE 0x0100
3132
#define MIPITX_D2_SW_CTL_EN 0x0144
3233
#define MIPITX_D0_SW_CTL_EN 0x0244
3334
#define MIPITX_CK_CKMODE_EN 0x0328
@@ -108,6 +109,24 @@ static const struct clk_ops mtk_mipi_tx_pll_ops = {
108109
.recalc_rate = mtk_mipi_tx_pll_recalc_rate,
109110
};
110111

112+
static void mtk_mipi_tx_config_calibration_data(struct mtk_mipi_tx *mipi_tx)
113+
{
114+
int i, j;
115+
116+
for (i = 0; i < 5; i++) {
117+
if ((mipi_tx->rt_code[i] & 0x1f) == 0)
118+
mipi_tx->rt_code[i] |= 0x10;
119+
120+
if ((mipi_tx->rt_code[i] >> 5 & 0x1f) == 0)
121+
mipi_tx->rt_code[i] |= 0x10 << 5;
122+
123+
for (j = 0; j < 10; j++)
124+
mtk_mipi_tx_update_bits(mipi_tx,
125+
MIPITX_D2P_RTCODE * (i + 1) + j * 4,
126+
1, mipi_tx->rt_code[i] >> j & 1);
127+
}
128+
}
129+
111130
static void mtk_mipi_tx_power_on_signal(struct phy *phy)
112131
{
113132
struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
@@ -130,6 +149,8 @@ static void mtk_mipi_tx_power_on_signal(struct phy *phy)
130149
RG_DSI_HSTX_LDO_REF_SEL,
131150
(mipi_tx->mipitx_drive - 3000) / 200 << 6);
132151

152+
mtk_mipi_tx_config_calibration_data(mipi_tx);
153+
133154
mtk_mipi_tx_set_bits(mipi_tx, MIPITX_CK_CKMODE_EN, DSI_CK_CKMODE_EN);
134155
}
135156

0 commit comments

Comments
 (0)