Skip to content

Commit 9a8406b

Browse files
Liu Yingvinodkoul
authored andcommitted
phy: dphy: Correct clk_pre parameter
The D-PHY specification (v1.2) explicitly mentions that the T-CLK-PRE parameter's unit is Unit Interval(UI) and the minimum value is 8. Also, kernel doc of the 'clk_pre' member of struct phy_configure_opts_mipi_dphy mentions that it should be in UI. However, the dphy core driver wrongly sets 'clk_pre' to 8000, which seems to hint that it's in picoseconds. So, let's fix the dphy core driver to correctly reflect the T-CLK-PRE parameter's minimum value according to the D-PHY specification. I'm assuming that all impacted custom drivers shall program values in TxByteClkHS cycles into hardware for the T-CLK-PRE parameter. The D-PHY specification mentions that the frequency of TxByteClkHS is exactly 1/8 the High-Speed(HS) bit rate(each HS bit consumes one UI). So, relevant custom driver code is changed to program those values as DIV_ROUND_UP(cfg->clk_pre, BITS_PER_BYTE), then. Note that I've only tested the patch with RM67191 DSI panel on i.MX8mq EVK. Help is needed to test with other i.MX8mq, Meson and Rockchip platforms, as I don't have the hardwares. Fixes: 2ed8699 ("phy: Add MIPI D-PHY configuration options") Tested-by: Liu Ying <[email protected]> # RM67191 DSI panel on i.MX8mq EVK Reviewed-by: Andrzej Hajda <[email protected]> Reviewed-by: Neil Armstrong <[email protected]> # for phy-meson-axg-mipi-dphy.c Tested-by: Neil Armstrong <[email protected]> # for phy-meson-axg-mipi-dphy.c Tested-by: Guido Günther <[email protected]> # Librem 5 (imx8mq) with it's rather picky panel Reviewed-by: Laurent Pinchart <[email protected]> Signed-off-by: Liu Ying <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 46e9947 commit 9a8406b

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

drivers/gpu/drm/bridge/nwl-dsi.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include <linux/bitfield.h>
10+
#include <linux/bits.h>
1011
#include <linux/clk.h>
1112
#include <linux/irq.h>
1213
#include <linux/math64.h>
@@ -196,12 +197,9 @@ static u32 ps2bc(struct nwl_dsi *dsi, unsigned long long ps)
196197
/*
197198
* ui2bc - UI time periods to byte clock cycles
198199
*/
199-
static u32 ui2bc(struct nwl_dsi *dsi, unsigned long long ui)
200+
static u32 ui2bc(unsigned int ui)
200201
{
201-
u32 bpp = mipi_dsi_pixel_format_to_bpp(dsi->format);
202-
203-
return DIV64_U64_ROUND_UP(ui * dsi->lanes,
204-
dsi->mode.clock * 1000 * bpp);
202+
return DIV_ROUND_UP(ui, BITS_PER_BYTE);
205203
}
206204

207205
/*
@@ -232,12 +230,12 @@ static int nwl_dsi_config_host(struct nwl_dsi *dsi)
232230
}
233231

234232
/* values in byte clock cycles */
235-
cycles = ui2bc(dsi, cfg->clk_pre);
233+
cycles = ui2bc(cfg->clk_pre);
236234
DRM_DEV_DEBUG_DRIVER(dsi->dev, "cfg_t_pre: 0x%x\n", cycles);
237235
nwl_dsi_write(dsi, NWL_DSI_CFG_T_PRE, cycles);
238236
cycles = ps2bc(dsi, cfg->lpx + cfg->clk_prepare + cfg->clk_zero);
239237
DRM_DEV_DEBUG_DRIVER(dsi->dev, "cfg_tx_gap (pre): 0x%x\n", cycles);
240-
cycles += ui2bc(dsi, cfg->clk_pre);
238+
cycles += ui2bc(cfg->clk_pre);
241239
DRM_DEV_DEBUG_DRIVER(dsi->dev, "cfg_t_post: 0x%x\n", cycles);
242240
nwl_dsi_write(dsi, NWL_DSI_CFG_T_POST, cycles);
243241
cycles = ps2bc(dsi, cfg->hs_exit);

drivers/phy/amlogic/phy-meson-axg-mipi-dphy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <linux/bitfield.h>
1111
#include <linux/bitops.h>
12+
#include <linux/bits.h>
1213
#include <linux/clk.h>
1314
#include <linux/delay.h>
1415
#include <linux/io.h>
@@ -250,7 +251,7 @@ static int phy_meson_axg_mipi_dphy_power_on(struct phy *phy)
250251
(DIV_ROUND_UP(priv->config.clk_zero, temp) << 16) |
251252
(DIV_ROUND_UP(priv->config.clk_prepare, temp) << 24));
252253
regmap_write(priv->regmap, MIPI_DSI_CLK_TIM1,
253-
DIV_ROUND_UP(priv->config.clk_pre, temp));
254+
DIV_ROUND_UP(priv->config.clk_pre, BITS_PER_BYTE));
254255

255256
regmap_write(priv->regmap, MIPI_DSI_HS_TIM,
256257
DIV_ROUND_UP(priv->config.hs_exit, temp) |

drivers/phy/phy-core-mipi-dphy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int phy_mipi_dphy_get_default_config(unsigned long pixel_clock,
3636

3737
cfg->clk_miss = 0;
3838
cfg->clk_post = 60000 + 52 * ui;
39-
cfg->clk_pre = 8000;
39+
cfg->clk_pre = 8;
4040
cfg->clk_prepare = 38000;
4141
cfg->clk_settle = 95000;
4242
cfg->clk_term_en = 0;
@@ -97,7 +97,7 @@ int phy_mipi_dphy_config_validate(struct phy_configure_opts_mipi_dphy *cfg)
9797
if (cfg->clk_post < (60000 + 52 * ui))
9898
return -EINVAL;
9999

100-
if (cfg->clk_pre < 8000)
100+
if (cfg->clk_pre < 8)
101101
return -EINVAL;
102102

103103
if (cfg->clk_prepare < 38000 || cfg->clk_prepare > 95000)

drivers/phy/rockchip/phy-rockchip-inno-dsidphy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Author: Wyon Bi <[email protected]>
66
*/
77

8+
#include <linux/bits.h>
89
#include <linux/kernel.h>
910
#include <linux/clk.h>
1011
#include <linux/iopoll.h>
@@ -364,7 +365,7 @@ static void inno_dsidphy_mipi_mode_enable(struct inno_dsidphy *inno)
364365
* The value of counter for HS Tclk-pre
365366
* Tclk-pre = Tpin_txbyteclkhs * value
366367
*/
367-
clk_pre = DIV_ROUND_UP(cfg->clk_pre, t_txbyteclkhs);
368+
clk_pre = DIV_ROUND_UP(cfg->clk_pre, BITS_PER_BYTE);
368369

369370
/*
370371
* The value of counter for HS Tlpx Time

0 commit comments

Comments
 (0)