drm/msm/dp: add support for DP PLL driver
Subsystems (4)
PATCH v6 4/5 drm/msm/dp: add support for DP PLL driver
From: Chandan Uddaraju <[email protected]>
Add the needed DP PLL specific files to support
display port interface on msm targets.
The DP driver calls the DP PLL driver registration. The DP driver sets the link and pixel clock sources.
Changes in v2:
-- Update copyright markings on all relevant files. -- Use DRM_DEBUG_DP for debug msgs.
Changes in v4:
-- Update the DP link clock provider names
Changes in V5:
-- Addressed comments from Stephen Boyd, Rob clark.
Changes in V6:
-- Remove PLL as separate driver and include PLL as DP module -- Remove redundant clock parsing from PLL module and make DP as
clock provider
-- Map USB3 DPCOM and PHY IO using hardcoded register address and
move mapping form parser to PLL module
-- Access DP PHY modules from same base address using offsets instead of
deriving base address of individual module from device tree.
-- Remove dp_pll_10nm_util.c and include its functionality in
dp_pll_10nm.c
-- Introduce new data structures private to PLL module
--- drivers/gpu/drm/msm/Kconfig | 13 + drivers/gpu/drm/msm/Makefile | 3 + drivers/gpu/drm/msm/dp/dp_catalog.c | 64 ++- drivers/gpu/drm/msm/dp/dp_display.c | 17 +- drivers/gpu/drm/msm/dp/dp_display.h | 3 + drivers/gpu/drm/msm/dp/dp_parser.c | 51 +- drivers/gpu/drm/msm/dp/dp_parser.h | 9 +- drivers/gpu/drm/msm/dp/dp_pll.c | 93 ++++ drivers/gpu/drm/msm/dp/dp_pll.h | 59 +++ drivers/gpu/drm/msm/dp/dp_pll_10nm.c | 903 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/msm/dp/dp_pll_private.h | 103 ++++ drivers/gpu/drm/msm/dp/dp_power.c | 10 + drivers/gpu/drm/msm/dp/dp_power.h | 71 ++- drivers/gpu/drm/msm/dp/dp_reg.h | 16 + 14 files changed, 1349 insertions(+), 66 deletions(-) create mode 100644 drivers/gpu/drm/msm/dp/dp_pll.c create mode 100644 drivers/gpu/drm/msm/dp/dp_pll.h create mode 100644 drivers/gpu/drm/msm/dp/dp_pll_10nm.c create mode 100644 drivers/gpu/drm/msm/dp/dp_pll_private.h
drivers/gpu/drm/msm/Kconfig +13 -0
@@ -65,6 +65,19 @@ config DRM_MSM_DP display support is enabled through this config option. It can be primary or secondary display on device. +config DRM_MSM_DP_PLL + bool "Enable DP PLL driver in MSM DRM" + depends on DRM_MSM_DP && COMMON_CLK + help + Choose this option to enable DP PLL driver which provides DP + source clocks under common clock framework. + +config DRM_MSM_DP_10NM_PLL + bool "Enable DP 10nm PLL driver in MSM DRM (used by SDM845)" + depends on DRM_MSM_DP_PLL + help + Choose this option if DP PLL on SDM845 is used on the platform. + config DRM_MSM_DSI bool "Enable DSI support in MSM DRM driver" depends on DRM_MSM
drivers/gpu/drm/msm/Makefile +3 -0
@@ -140,4 +140,7 @@ msm-$(CONFIG_DRM_MSM_DSI_14NM_PHY) += dsi/pll/dsi_pll_14nm.o msm-$(CONFIG_DRM_MSM_DSI_10NM_PHY) += dsi/pll/dsi_pll_10nm.o endif +msm-$(CONFIG_DRM_MSM_DP_PLL)+= dp/dp_pll.o +msm-$(CONFIG_DRM_MSM_DP_10NM_PLL)+= dp/dp_pll_10nm.o + obj-$(CONFIG_DRM_MSM) += msm.o
drivers/gpu/drm/msm/dp/dp_catalog.c +45 -19
140 lines not on this page · raw message
drivers/gpu/drm/msm/dp/dp_display.c +16 -1
@@ -22,6 +22,7 @@#include "dp_ctrl.h" #include "dp_display.h" #include "dp_drm.h" +#include "dp_pll.h" static struct msm_dp *g_dp_display;#define HPD_STRING_SIZE 30
@@ -42,6 +43,7 @@ struct dp_display_private {struct dp_usbpd *usbpd;struct dp_parser *parser; +struct msm_dp_pll *pll;struct dp_power *power;struct dp_catalog *catalog;struct dp_aux *aux;
@@ -223,7 +225,6 @@ static int dp_display_process_hpd_high(struct dp_display_private *dp) edid = dp->panel->edid; dp->audio_supported =drm_detect_monitor_audio (edid); -dp_panel_handle_sink_request (dp->panel); dp->dp_display.max_pclk_khz =DP_MAX_PIXEL_CLK_KHZ ;
@@ -411,6 +412,9 @@ static int dp_init_sub_modules(struct dp_display_private *dp)struct dp_panel_in panel_in = { .dev = dev, }; +struct dp_pll_in pll_in = { + .pdev = dp->pdev, + };/* Callback APIs used for cable status change event */ cb->configure = dp_display_usbpd_configure_cb;
@@ -441,6 +445,17 @@ static int dp_init_sub_modules(struct dp_display_private *dp) goto error; } + pll_in.parser = dp->parser; + dp->pll =dp_pll_get (&pll_in); +if (IS_ERR_OR_NULL (dp->pll)) { + rc = -EINVAL ; +DRM_ERROR ("failed to initialize pll, rc = %d\n" , rc); + dp->pll =NULL ; + goto error; + } + + dp->parser->pll = dp->pll; + dp->power =dp_power_get (dp->parser);if (IS_ERR (dp->power)) { rc =PTR_ERR (dp->power);
drivers/gpu/drm/msm/dp/dp_display.h +3 -0
@@ -25,4 +25,7 @@ int dp_display_get_modes(struct msm_dp *dp_display,bool dp_display_check_video_test (struct msm_dp *dp_display);int dp_display_get_test_bpp (struct msm_dp *dp_display); +void __init msm_dp_pll_driver_register (void ); +void __exit msm_dp_pll_driver_unregister(void); +#endif /* _DP_DISPLAY_H_ */
drivers/gpu/drm/msm/dp/dp_parser.c +12 -39
84 lines not on this page · raw message
drivers/gpu/drm/msm/dp/dp_parser.h +3 -6
@@ -12,6 +12,7 @@#include "dpu_io_util.h" #include "msm_drv.h" +#include "dp_pll.h" #define DP_LABEL "MDSS DP DISPLAY"#define AUX_CFG_LEN 10
@@ -64,17 +65,12 @@ struct dp_display_data {* @phy_io: phy's mapped memory address * @ln_tx0_io: USB-DP lane TX0's mapped memory address * @ln_tx1_io: USB-DP lane TX1's mapped memory address -* @dp_cc_io: DP cc's mapped memory address * @dp_pll_io: DP PLL mapped memory address * @usb3_dp_com: USB3 DP PHY combo mapped memory address */ struct dp_io {struct dss_io_data dp_controller; -struct dss_io_data phy_io; -struct dss_io_data ln_tx0_io; -struct dss_io_data ln_tx1_io; -struct dss_io_data dp_cc_io; -struct dss_io_data dp_pll_io; +struct dss_io_data phy_reg;struct dss_io_data usb3_dp_com; };
@@ -183,6 +179,7 @@ struct dp_parser {struct dp_pinctrl pinctrl;struct dp_io io;struct dp_display_data disp_data; +struct msm_dp_pll *pll;const struct dp_regulator_cfg *regulator_cfg;u8 l_map[4 ];struct dp_aux_cfg aux_cfg[AUX_CFG_LEN ];
drivers/gpu/drm/msm/dp/dp_pll.c new file +93 -0
93 lines not on this page · raw message
drivers/gpu/drm/msm/dp/dp_pll.h new file +59 -0
59 lines not on this page · raw message
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +903 -0
903 lines not on this page · raw message
drivers/gpu/drm/msm/dp/dp_pll_private.h new file +103 -0
103 lines not on this page · raw message
drivers/gpu/drm/msm/dp/dp_power.c +10 -0
@@ -101,6 +101,16 @@ static int dp_power_clk_init(struct dp_power_private *power) core = &power->parser->mp[DP_CORE_PM ]; ctrl = &power->parser->mp[DP_CTRL_PM ]; +if (power->parser->pll && power->parser->pll->get_provider) { + rc = power->parser->pll->get_provider (power->parser->pll, + &power->link_provider, &power->pixel_provider); +if (rc) { +DRM_ERROR ("%s:provider failed,don't set parent\n" , + __func__); +return 0 ; + } + } + rc =msm_dss_get_clk (dev, core->clk_config, core->num_clk);if (rc) { DRM_ERROR("failed to get %s clk. err=%d\n",
drivers/gpu/drm/msm/dp/dp_power.h +70 -1
90 lines not on this page · raw message
drivers/gpu/drm/msm/dp/dp_reg.h +16 -0
@@ -6,6 +6,22 @@#ifndef _DP_REG_H_#define _DP_REG_H_ +/* DP PHY Register Regions */ +#define REG_DP_PHY_REGION_BASE (0x088ea000) +#define REG_DP_PHY_REGION_SIZE (0x00000C00) + +#define REG_USB3_DP_COM_REGION_BASE (0x088e8000) +#define REG_USB3_DP_COM_REGION_SIZE (0x00000020) + +#define DP_PHY_PLL_OFFSET (0x00000000) +#define DP_PHY_PLL_SIZE (0x00000200) +#define DP_PHY_REG_OFFSET (0x00000A00) +#define DP_PHY_REG_SIZE (0x00000200) +#define DP_PHY_LN_TX0_OFFSET (0x00000200) +#define DP_PHY_LN_TX0_SIZE (0x00000200) +#define DP_PHY_LN_TX1_OFFSET (0x00000600) +#define DP_PHY_LN_TX1_SIZE (0x00000200) +/* DP_TX Registers */ #define REG_DP_HW_VERSION (0x00000000)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Quoting Tanmay Shah (2020-06-08 20:46:23)
Quoted 13 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +1
-0@@ -5,6 +5,7 @@#define pr_fmt (fmt) "[drm-dp] %s: " fmt, __func__ +#include <linux/rational.h> #include <linux/delay.h> #include <linux/iopoll.h> #include <drm/drm_dp_helper.h>
drivers/gpu/drm/msm/dp/dp_catalog.c static inline void dp_write_ahb(struct dp_catalog_private *catalog, · line 141
Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +0
-5@@ -134,59 +135,61 @@ static inline void dp_write_ahb(struct dp_catalog_private *catalog,writel (data, catalog->io->dp_controller.base + offset); } -static inline u32 dp_read_cc (struct dp_catalog_private *catalog,u32 offset) -{ -return readl_relaxed (catalog->io->dp_cc_io.base + offset); -} -
Why was this added in the first place? Remove it from the place it came in please.
Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +1
-0static inline void dp_write_phy (struct dp_catalog_private *catalog,u32 offset,u32 data) { + offset +=DP_PHY_REG_OFFSET ;/* * To make sure phy reg writes happens before any other operation,
[...]
Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +1
-1@@ -568,17 +574,37 @@ void dp_catalog_ctrl_config_msa(struct dp_catalog *dp_catalog, bool fixed_nvid) {u32 pixel_m, pixel_n; -u32 mvid, nvid; +u32 mvid, nvid, div, pixel_div =0 , dispcc_input_rate;u32 const nvid_fixed =DP_LINK_CONSTANT_N_VALUE ;u32 const link_rate_hbr2 =540000 ;
drivers/gpu/drm/msm/dp/dp_catalog.c void dp_catalog_ctrl_config_msa(struct dp_catalog *dp_catalog, · line 586
Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +2
-3u32 const link_rate_hbr3 =810000 ; +unsigned long den, num;struct dp_catalog_private *catalog =container_of (dp_catalog, struct dp_catalog_private, dp_catalog); - pixel_m =dp_read_cc (catalog,MMSS_DP_PIXEL_M ); - pixel_n =dp_read_cc (catalog,MMSS_DP_PIXEL_N ); -DRM_DEBUG_DP ("pixel_m=0x%x, pixel_n=0x%x\n" , pixel_m, pixel_n); + div =dp_read_phy (catalog,REG_DP_PHY_VCO_DIV );
Why do we need to read the phy? The pixel_div seems to match what the clk driver is doing so presumably we can make this follow the link rate being used vs. having to read the phy.
Quoted 82 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +21
-0+ div &=0x03 ; + +if (div ==0 ) + pixel_div =6 ; +else if (div ==1 ) + pixel_div =2 ; +else if (div ==2 ) + pixel_div =4 ; +else +DRM_ERROR ("Invalid pixel mux divider\n" ); + + dispcc_input_rate = (rate *10 ) / pixel_div; + +rational_best_approximation (dispcc_input_rate, stream_rate_khz, + (unsigned long )(1 <<16 ) -1 , + (unsigned long )(1 <<16 ) -1 , &den, &num); + + den = ~(den - num); + den = den &0xFFFF ; + pixel_m = num; + pixel_n = den; mvid = (pixel_m &0xFFFF ) *5 ; nvid = (0xFFFF & (~pixel_n)) + (pixel_m &0xFFFF );drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +52
-0@@ -0,0 +1,903 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2016-2020, The Linux Foundation. All rights reserved. +*/ + +/* +* Display Port PLL driver block diagram for branch clocks +* +* +------------------------------+ +* | DP_VCO_CLK | +* | | +* | +-------------------+ | +* | | (DP PLL/VCO) | | +* | +---------+---------+ | +* | v | +* | +----------+-----------+ | +* | | hsclk_divsel_clk_src | | +* | +----------+-----------+ | +* +------------------------------+ +* | +* +---------<---------v------------>----------+ +* | | +* +--------v---------+ | +* | dp_phy_pll | | +* | link_clk | | +* +--------+---------+ | +* | | +* | | +* v v +* Input to DISPCC block | +* for link clk, crypto clk | +* and interface clock | +* | +* | +* +--------<------------+-----------------+---<---+ +* | | | +* +----v---------+ +--------v-----+ +--------v------+ +* | vco_divided | | vco_divided | | vco_divided | +* | _clk_src | | _clk_src | | _clk_src | +* | | | | | | +* |divsel_six | | divsel_two | | divsel_four | +* +-------+------+ +-----+--------+ +--------+------+ +* | | | +* v---->----------v-------------<------v +* | +* +----------+---------+ +* | dp_phy_pll_vco | +* | div_clk | +* +---------+----------+ +* | +* v +* Input to DISPCC block
drivers/gpu/drm/msm/dp/dp_pll_10nm.c line 62
Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +10
-0+* for DP pixel clock +* +*/ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/err.h> +#include <linux/kernel.h> +#include <linux/regmap.h> +#include <linux/iopoll.h>
Should be a clk-provider.h include here given that this is providing clks.
Quoted 103 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +103
-0+ +#include "dp_hpd.h" +#include "dp_pll.h" +#include "dp_pll_private.h" + +#define NUM_PROVIDED_CLKS 2 + +#define DP_LINK_CLK_SRC 0 +#define DP_PIXEL_CLK_SRC 1 + +static struct dp_pll_db *dp_pdb; + +static const struct clk_ops dp_10nm_vco_clk_ops = { + .recalc_rate = dp_vco_recalc_rate_10nm, + .set_rate = dp_vco_set_rate_10nm, + .round_rate = dp_vco_round_rate_10nm, + .prepare = dp_vco_prepare_10nm, + .unprepare = dp_vco_unprepare_10nm, +}; + +struct dp_pll_10nm_pclksel { +struct clk_hw hw; + +/* divider params */ +u8 shift; +u8 width; +u8 flags;/* same flags as used by clk_divider struct */ + +struct dp_pll_db *pll; +}; + +#define to_pll_10nm_pclksel (_hw) \ + container_of(_hw, struct dp_pll_10nm_pclksel, hw) + +static const struct clk_parent_data disp_cc_parent_data_0[] = { + { .fw_name ="bi_tcxo" }, + { .fw_name ="dp_phy_pll_link_clk" , .name ="dp_phy_pll_link_clk" }, + { .fw_name ="dp_phy_pll_vco_div_clk" , + .name ="dp_phy_pll_vco_div_clk" }, + { .fw_name ="core_bi_pll_test_se" , .name ="core_bi_pll_test_se" }, +}; + +static struct dp_pll_vco_clk dp_vco_clk = { + .min_rate =DP_VCO_HSCLK_RATE_1620MHZDIV1000 , + .max_rate =DP_VCO_HSCLK_RATE_8100MHZDIV1000 , +}; + +static int dp_pll_mux_set_parent_10nm (struct clk_hw *hw,u8 val) +{ +struct dp_pll_10nm_pclksel *pclksel =to_pll_10nm_pclksel (hw); +struct dp_pll_db *dp_res = pclksel->pll; +struct dp_io_pll *pll_io = &dp_res->base->pll_io; +u32 auxclk_div; + + auxclk_div =PLL_REG_R (pll_io->phy_base,REG_DP_PHY_VCO_DIV ); + auxclk_div &= ~0x03 ; + +if (val ==0 ) + auxclk_div |=1 ; +else if (val ==1 ) + auxclk_div |=2 ; +else if (val ==2 ) + auxclk_div |=0 ; + +PLL_REG_W (pll_io->phy_base, +REG_DP_PHY_VCO_DIV , auxclk_div); +DRM_DEBUG_DP ("%s: mux=%d auxclk_div=%x\n" , __func__, val, auxclk_div); + +return 0 ; +} + +static u8 dp_pll_mux_get_parent_10nm (struct clk_hw *hw) +{ +u32 auxclk_div =0 ; +struct dp_pll_10nm_pclksel *pclksel =to_pll_10nm_pclksel (hw); +struct dp_pll_db *dp_res = pclksel->pll; +struct dp_io_pll *pll_io = &dp_res->base->pll_io; +u8 val =0 ; + + auxclk_div =PLL_REG_R (pll_io->phy_base,REG_DP_PHY_VCO_DIV ); + auxclk_div &=0x03 ; + +if (auxclk_div ==1 )/* Default divider */ + val =0 ; +else if (auxclk_div ==2 ) + val =1 ; +else if (auxclk_div ==0 ) + val =2 ; + +DRM_DEBUG_DP ("%s: auxclk_div=%d, val=%d\n" , __func__, auxclk_div, val); + +return val; +} + +static int dp_pll_clk_mux_determine_rate (struct clk_hw *hw, +struct clk_rate_request *req) +{ +unsigned long rate =0 ; +int ret =0 ; + + rate =clk_get_rate (hw->clk); + +if (rate <=0 ) {
drivers/gpu/drm/msm/dp/dp_pll_10nm.c line 175
Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +10
-0+DRM_ERROR ("Rate is not set properly\n" ); +return -EINVAL ; + } + + req->rate = rate; + +DRM_DEBUG_DP ("%s: rate=%ld\n" , __func__, req->rate); +/* Set the new parent of mux if there is a new valid parent */ +if (hw->clk && req->best_parent_hw->clk) { + ret =clk_set_parent (hw->clk, req->best_parent_hw->clk);
Why do we need to call clk consumer APIs from the clk provider ops? This is pretty confusing what's going on here.
Quoted 54 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +54
-0+if (ret) { +DRM_ERROR ("%s: clk_set_parent failed: ret=%d\n" , + __func__, ret); +return ret; + } + } +return 0 ; +} + +static unsigned long dp_pll_mux_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +struct clk_hw *div_clk_hw =NULL , *vco_clk_hw =NULL ; +struct dp_pll_vco_clk *vco; + + div_clk_hw =clk_hw_get_parent (hw); +if (!div_clk_hw) +return 0 ; + + vco_clk_hw =clk_hw_get_parent (div_clk_hw); +if (!vco_clk_hw) +return 0 ; + + vco =to_dp_vco_hw (vco_clk_hw); +if (!vco) +return 0 ; + +if (vco->rate ==DP_VCO_HSCLK_RATE_8100MHZDIV1000 ) +return (vco->rate /6 ); +else if (vco->rate ==DP_VCO_HSCLK_RATE_5400MHZDIV1000 ) +return (vco->rate /4 ); +else +return (vco->rate /2 ); +} + +static int dp_pll_10nm_get_provider (struct msm_dp_pll *pll, +struct clk **link_clk_provider, +struct clk **pixel_clk_provider) +{ +struct clk_hw_onecell_data *hw_data = pll->hw_data; + +if (link_clk_provider) + *link_clk_provider = hw_data->hws[DP_LINK_CLK_SRC ]->clk; +if (pixel_clk_provider) + *pixel_clk_provider = hw_data->hws[DP_PIXEL_CLK_SRC ]->clk; + +return 0 ; +} + +static const struct clk_ops dp_10nm_pclksel_clk_ops = { + .get_parent = dp_pll_mux_get_parent_10nm, + .set_parent = dp_pll_mux_set_parent_10nm, + .recalc_rate = dp_pll_mux_recalc_rate, + .determine_rate = dp_pll_clk_mux_determine_rate,
drivers/gpu/drm/msm/dp/dp_pll_10nm.c line 239
Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +10
-0+}; + +static struct clk_hw *dp_pll_10nm_pixel_clk_sel (struct dp_pll_db *pll_10nm) +{ +struct device *dev = &pll_10nm->pdev->dev; +struct dp_pll_10nm_pclksel *pll_pclksel; +struct clk_init_data pclksel_init = { + .parent_data = disp_cc_parent_data_0, + .num_parents =3 , + .name ="dp_phy_pll_vco_div_clk" ,
So the dp_phy_pll_vco_div_clk has a potential parent that is dp_phy_pll_vco_div_clk. Huh?
drivers/gpu/drm/msm/dp/dp_pll_10nm.c line 251
Quoted 12 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +12
-0+ .ops = &dp_10nm_pclksel_clk_ops, + }; +int ret; + + pll_pclksel =devm_kzalloc (dev,sizeof (*pll_pclksel),GFP_KERNEL ); +if (!pll_pclksel) +return ERR_PTR (-ENOMEM ); + + pll_pclksel->pll = pll_10nm; + pll_pclksel->shift =0 ; + pll_pclksel->width =4 ; + pll_pclksel->flags =CLK_DIVIDER_ONE_BASED ;
Is this flag used?
Quoted 17 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +17
-0+ pll_pclksel->hw.init = &pclksel_init; + + ret =clk_hw_register (dev, &pll_pclksel->hw); +if (ret) +return ERR_PTR (ret); + +return &pll_pclksel->hw; +} + +static int dp_pll_10nm_register (struct dp_pll_db *pll_10nm) +{ +struct clk_hw_onecell_data *hw_data; +int ret; +struct clk_hw *hw; + +struct msm_dp_pll *pll = pll_10nm->base; +struct device *dev = &pll_10nm->pdev->dev;
drivers/gpu/drm/msm/dp/dp_pll_10nm.c line 278
Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +10
-0+struct clk_hw **hws = pll_10nm->hws; +int num =0 ; +struct clk_init_data vco_init = { + .parent_data = &(const struct clk_parent_data ){ + .fw_name ="bi_tcxo" , + }, + .num_parents =1 , + .name ="dp_vco_clk" , + .ops = &dp_10nm_vco_clk_ops, + };
I thought the plan was to not have a vco clk? Just expose the two clks for the link and the vco divider. Furthermore, drop the divider "parents" and implement a single clk that programs the right divider value for the various link rates chosen.
Quoted 80 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +80
-0+ +DRM_DEBUG_DP ("DP->id = %d" , pll_10nm->id); + + hw_data =devm_kzalloc (dev,sizeof (*hw_data) + +NUM_PROVIDED_CLKS *sizeof (struct clk_hw *), +GFP_KERNEL ); +if (!hw_data) +return -ENOMEM ; + + dp_vco_clk.hw.init = &vco_init; + ret =clk_hw_register (dev, &dp_vco_clk.hw); +if (ret) +return ret; + hws[num++] = &dp_vco_clk.hw; + + hw =clk_hw_register_fixed_factor (dev,"dp_phy_pll_link_clk" , +"dp_vco_clk" ,CLK_SET_RATE_PARENT ,1 ,10 ); + +if (IS_ERR (hw)) +return PTR_ERR (hw); + hws[num++] = hw; + hw_data->hws[DP_LINK_CLK_SRC ] = hw; + + hw =clk_hw_register_fixed_factor (dev,"dp_vco_divsel_two_clk_src" , +"dp_vco_clk" ,0 ,1 ,2 ); +if (IS_ERR (hw)) +return PTR_ERR (hw); + hws[num++] = hw; + + hw =clk_hw_register_fixed_factor (dev,"dp_vco_divsel_four_clk_src" , +"dp_vco_clk" ,0 ,1 ,4 ); +if (IS_ERR (hw)) +return PTR_ERR (hw); + hws[num++] = hw; + + hw =clk_hw_register_fixed_factor (dev,"dp_vco_divsel_six_clk_src" , +"dp_vco_clk" ,0 ,1 ,6 ); +if (IS_ERR (hw)) +return PTR_ERR (hw); + hws[num++] = hw; + + hw =dp_pll_10nm_pixel_clk_sel (pll_10nm); +if (IS_ERR (hw)) +return PTR_ERR (hw); + + hws[num++] = hw; + hw_data->hws[DP_PIXEL_CLK_SRC ] = hw; + + pll_10nm->num_hws = num; + + hw_data->num =NUM_PROVIDED_CLKS ; + pll->hw_data = hw_data; + + ret =of_clk_add_hw_provider (dev->of_node, of_clk_hw_onecell_get, + pll->hw_data); +if (ret) { +DRM_DEV_ERROR (dev,"failed to register clk provider: %d\n" , + ret); +return ret; + } + +return ret; +} + +int msm_dp_pll_10nm_init (struct msm_dp_pll *pll,int id) +{ +struct dp_pll_db *dp_10nm_pll; +struct platform_device *pdev = pll->pdev; +int ret; + + dp_10nm_pll =devm_kzalloc (&pdev->dev, +sizeof (*dp_10nm_pll),GFP_KERNEL ); +if (!dp_10nm_pll) +return -ENOMEM ; + +DRM_DEBUG_DP ("DP PLL%d" , id); + + dp_10nm_pll->base = pll; + dp_10nm_pll->pdev = pll->pdev; + dp_10nm_pll->id = id;
drivers/gpu/drm/msm/dp/dp_pll_10nm.c line 368
Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +10
-0+ dp_pdb = dp_10nm_pll; + pll->priv = (void *)dp_10nm_pll; + dp_vco_clk.priv = pll; + + ret =of_property_read_u32 (pdev->dev.of_node,"cell-index" , + &dp_10nm_pll->index); +if (ret) { +DRM_ERROR ("Unable to get the cell-index ret=%d\n" , ret); + dp_10nm_pll->index =0 ; + }
Is the cell-index used for anything?
Quoted 11 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +11
-0+ + ret =dp_pll_10nm_register (dp_10nm_pll); +if (ret) { +DRM_DEV_ERROR (&pdev->dev,"failed to register PLL: %d\n" , ret); +return ret; + } + + pll->get_provider = dp_pll_10nm_get_provider; + +return ret; +}
Quoted 18 lines · Stephen Boyd
Quoting Tanmay Shah (2020-06-08 20:46:23)
Quoted 17 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +1
-0@@ -5,6 +5,7 @@#define pr_fmt (fmt) "[drm-dp] %s: " fmt, __func__ +#include <linux/rational.h> #include <linux/delay.h> #include <linux/iopoll.h> #include <drm/drm_dp_helper.h> @@ -134,59 +135,61 @@ static inline void dp_write_ahb(struct dp_catalog_private *catalog,writel (data, catalog->io->dp_controller.base + offset); }
Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c static inline void dp_write_ahb(struct dp_catalog_private *catalog, · line 141
Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +0
-5-static inline u32 dp_read_cc (struct dp_catalog_private *catalog,u32 offset) -{ -return readl_relaxed (catalog->io->dp_cc_io.base + offset); -} -Why was this added in the first place? Remove it from the place it came in please.
Sure. I will remove it as part of DP base driver patch.
Quoted 124 lines
Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +1
-0static inline void dp_write_phy (struct dp_catalog_private *catalog,u32 offset,u32 data) { + offset +=DP_PHY_REG_OFFSET ;/* * To make sure phy reg writes happens before any other operation, [...]
Quoted 11 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +2
-1@@ -568,17 +574,37 @@ void dp_catalog_ctrl_config_msa(struct dp_catalog *dp_catalog, bool fixed_nvid) {u32 pixel_m, pixel_n; -u32 mvid, nvid; +u32 mvid, nvid, div, pixel_div =0 , dispcc_input_rate;u32 const nvid_fixed =DP_LINK_CONSTANT_N_VALUE ;u32 const link_rate_hbr2 =540000 ;u32 const link_rate_hbr3 =810000 ; +unsigned long den, num;drivers/gpu/drm/msm/dp/dp_catalog.c void dp_catalog_ctrl_config_msa(struct · line 589
Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +1
-3struct dp_catalog_private *catalog =container_of (dp_catalog, struct dp_catalog_private, dp_catalog); - pixel_m =dp_read_cc (catalog,MMSS_DP_PIXEL_M ); - pixel_n =dp_read_cc (catalog,MMSS_DP_PIXEL_N ); -DRM_DEBUG_DP ("pixel_m=0x%x, pixel_n=0x%x\n" , pixel_m, pixel_n); + div =dp_read_phy (catalog,REG_DP_PHY_VCO_DIV );Why do we need to read the phy? The
pixel_divseems to match what the clk driver is doing so presumably we can make this follow the link rate being used vs. having to read the phy.Quoted 89 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +14
-0+ div &=0x03 ; + +if (div ==0 ) + pixel_div =6 ; +else if (div ==1 ) + pixel_div =2 ; +else if (div ==2 ) + pixel_div =4 ; +else +DRM_ERROR ("Invalid pixel mux divider\n" ); + + dispcc_input_rate = (rate *10 ) / pixel_div; + + rational_best_approximation(dispcc_input_rate,
stream_rate_khz,drivers/gpu/drm/msm/dp/dp_catalog.c +7
-0+ (unsigned long )(1 <<16 ) -1 , + (unsigned long)(1 << 16) - 1, &den, &num); + + den = ~(den - num); + den = den &0xFFFF ; + pixel_m = num; + pixel_n = den; mvid = (pixel_m &0xFFFF ) *5 ; nvid = (0xFFFF & (~pixel_n)) + (pixel_m &0xFFFF );drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +3
-0@@ -0,0 +1,903 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
+ */drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +53
-0+ +/* +* Display Port PLL driver block diagram for branch clocks +* +* +------------------------------+ +* | DP_VCO_CLK | +* | | +* | +-------------------+ | +* | | (DP PLL/VCO) | | +* | +---------+---------+ | +* | v | +* | +----------+-----------+ | +* | | hsclk_divsel_clk_src | | +* | +----------+-----------+ | +* +------------------------------+ +* | +* +---------<---------v------------>----------+ +* | | +* +--------v---------+ | +* | dp_phy_pll | | +* | link_clk | | +* +--------+---------+ | +* | | +* | | +* v v +* Input to DISPCC block | +* for link clk, crypto clk | +* and interface clock | +* | +* | +* +--------<------------+-----------------+---<---+ +* | | | +* +----v---------+ +--------v-----+ +--------v------+ +* | vco_divided | | vco_divided | | vco_divided | +* | _clk_src | | _clk_src | | _clk_src | +* | | | | | | +* |divsel_six | | divsel_two | | divsel_four | +* +-------+------+ +-----+--------+ +--------+------+ +* | | | +* v---->----------v-------------<------v +* | +* +----------+---------+ +* | dp_phy_pll_vco | +* | div_clk | +* +---------+----------+ +* | +* v +* Input to DISPCC block +* for DP pixel clock +* +*/ + +#include <linux/clk.h>
Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c line 62
Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +5
-0+#include <linux/delay.h> +#include <linux/err.h> +#include <linux/kernel.h> +#include <linux/regmap.h> +#include <linux/iopoll.h> Should be a
clk-provider.hinclude here given that this is providing clks.
Yes. currently it is included in dp_parser.h but I will include here as well.
Quoted 113 lines
Quoted 113 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +37
-0+ +#include "dp_hpd.h" +#include "dp_pll.h" +#include "dp_pll_private.h" + +#define NUM_PROVIDED_CLKS 2 + +#define DP_LINK_CLK_SRC 0 +#define DP_PIXEL_CLK_SRC 1 + +static struct dp_pll_db *dp_pdb; + +static const struct clk_ops dp_10nm_vco_clk_ops = { + .recalc_rate = dp_vco_recalc_rate_10nm, + .set_rate = dp_vco_set_rate_10nm, + .round_rate = dp_vco_round_rate_10nm, + .prepare = dp_vco_prepare_10nm, + .unprepare = dp_vco_unprepare_10nm, +}; + +struct dp_pll_10nm_pclksel { +struct clk_hw hw; + +/* divider params */ +u8 shift; +u8 width; +u8 flags;/* same flags as used by clk_divider struct */ + +struct dp_pll_db *pll; +}; + +#define to_pll_10nm_pclksel (_hw) \ + container_of(_hw, struct dp_pll_10nm_pclksel, hw) + +static const struct clk_parent_data disp_cc_parent_data_0[] = { + { .fw_name ="bi_tcxo" }, + { .fw_name = "dp_phy_pll_link_clk", .name ="
dp_phy_pll_link_clk" },drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +3
-0+ { .fw_name = "dp_phy_pll_vco_div_clk", + .name = "dp_phy_pll_vco_div_clk"}, + { .fw_name = "core_bi_pll_test_se", .name ="
core_bi_pll_test_se" },drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +27
-0+}; + +static struct dp_pll_vco_clk dp_vco_clk = { + .min_rate =DP_VCO_HSCLK_RATE_1620MHZDIV1000 , + .max_rate =DP_VCO_HSCLK_RATE_8100MHZDIV1000 , +}; + +static int dp_pll_mux_set_parent_10nm (struct clk_hw *hw,u8 val) +{ +struct dp_pll_10nm_pclksel *pclksel =to_pll_10nm_pclksel (hw); +struct dp_pll_db *dp_res = pclksel->pll; +struct dp_io_pll *pll_io = &dp_res->base->pll_io; +u32 auxclk_div; + + auxclk_div =PLL_REG_R (pll_io->phy_base,REG_DP_PHY_VCO_DIV ); + auxclk_div &= ~0x03 ; + +if (val ==0 ) + auxclk_div |=1 ; +else if (val ==1 ) + auxclk_div |=2 ; +else if (val ==2 ) + auxclk_div |=0 ; + +PLL_REG_W (pll_io->phy_base, +REG_DP_PHY_VCO_DIV , auxclk_div); + DRM_DEBUG_DP("%s: mux=%d auxclk_div=%x\n", __func__, val,
auxclk_div);drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +23
-0+ +return 0 ; +} + +static u8 dp_pll_mux_get_parent_10nm (struct clk_hw *hw) +{ +u32 auxclk_div =0 ; +struct dp_pll_10nm_pclksel *pclksel =to_pll_10nm_pclksel (hw); +struct dp_pll_db *dp_res = pclksel->pll; +struct dp_io_pll *pll_io = &dp_res->base->pll_io; +u8 val =0 ; + + auxclk_div =PLL_REG_R (pll_io->phy_base,REG_DP_PHY_VCO_DIV ); + auxclk_div &=0x03 ; + +if (auxclk_div ==1 )/* Default divider */ + val =0 ; +else if (auxclk_div ==2 ) + val =1 ; +else if (auxclk_div ==0 ) + val =2 ; + + DRM_DEBUG_DP("%s: auxclk_div=%d, val=%d\n", __func__,
auxclk_div, val);drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +19
-0+ +return val; +} + +static int dp_pll_clk_mux_determine_rate (struct clk_hw *hw, +struct clk_rate_request *req) +{ +unsigned long rate =0 ; +int ret =0 ; + + rate =clk_get_rate (hw->clk); + +if (rate <=0 ) { +DRM_ERROR ("Rate is not set properly\n" ); +return -EINVAL ; + } + + req->rate = rate; +
Quoted 9 lines
Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +4
-0+DRM_DEBUG_DP ("%s: rate=%ld\n" , __func__, req->rate); +/* Set the new parent of mux if there is a new valid parent */ +if (hw->clk && req->best_parent_hw->clk) { + ret = clk_set_parent(hw->clk,
req->best_parent_hw->clk);Why do we need to call clk consumer APIs from the clk provider ops? This is pretty confusing what's going on here.
Sure. Use of clk_set_parent is redundant here and I will remove it.
Quoted 63 lines
Quoted 63 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +2
-0+if (ret) { + DRM_ERROR("%s: clk_set_parent failed:ret=%d\n",
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +41
-0+ __func__, ret); +return ret; + } + } +return 0 ; +} + +static unsigned long dp_pll_mux_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +struct clk_hw *div_clk_hw =NULL , *vco_clk_hw =NULL ; +struct dp_pll_vco_clk *vco; + + div_clk_hw =clk_hw_get_parent (hw); +if (!div_clk_hw) +return 0 ; + + vco_clk_hw =clk_hw_get_parent (div_clk_hw); +if (!vco_clk_hw) +return 0 ; + + vco =to_dp_vco_hw (vco_clk_hw); +if (!vco) +return 0 ; + +if (vco->rate ==DP_VCO_HSCLK_RATE_8100MHZDIV1000 ) +return (vco->rate /6 ); +else if (vco->rate ==DP_VCO_HSCLK_RATE_5400MHZDIV1000 ) +return (vco->rate /4 ); +else +return (vco->rate /2 ); +} + +static int dp_pll_10nm_get_provider (struct msm_dp_pll *pll, +struct clk **link_clk_provider, +struct clk **pixel_clk_provider) +{ +struct clk_hw_onecell_data *hw_data = pll->hw_data; + +if (link_clk_provider) + *link_clk_provider =hw_data->hws[DP_LINK_CLK_SRC]->clk;
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +2
-0+if (pixel_clk_provider) + *pixel_clk_provider =hw_data->hws[DP_PIXEL_CLK_SRC]->clk;
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +12
-0+ +return 0 ; +} + +static const struct clk_ops dp_10nm_pclksel_clk_ops = { + .get_parent = dp_pll_mux_get_parent_10nm, + .set_parent = dp_pll_mux_set_parent_10nm, + .recalc_rate = dp_pll_mux_recalc_rate, + .determine_rate = dp_pll_clk_mux_determine_rate, +}; + +static struct clk_hw *dp_pll_10nm_pixel_clk_sel(struct dp_pll_db
*pll_10nm)drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +2
-0+{ +struct device *dev = &pll_10nm->pdev->dev;
Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c line 239
Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +5
-0+struct dp_pll_10nm_pclksel *pll_pclksel; +struct clk_init_data pclksel_init = { + .parent_data = disp_cc_parent_data_0, + .num_parents =3 , + .name ="dp_phy_pll_vco_div_clk" ,So the
dp_phy_pll_vco_div_clkhas a potential parent that isdp_phy_pll_vco_div_clk. Huh?
Thats right. I will remove dp_phy_pll_vco_div_clk from parent list disp_cc_parent_data_0.
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +5
-0+ .ops = &dp_10nm_pclksel_clk_ops, + }; +int ret; + + pll_pclksel = devm_kzalloc(dev, sizeof(*pll_pclksel),
GFP_KERNEL);
+ if (!pll_pclksel)
Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c line 251
Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +6
-0+return ERR_PTR (-ENOMEM ); + + pll_pclksel->pll = pll_10nm; + pll_pclksel->shift =0 ; + pll_pclksel->width =4 ; + pll_pclksel->flags =CLK_DIVIDER_ONE_BASED ;Is this flag used?
No it is redundant. I will remove.
Quoted 24 lines
Quoted 24 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +24
-0+ pll_pclksel->hw.init = &pclksel_init; + + ret =clk_hw_register (dev, &pll_pclksel->hw); +if (ret) +return ERR_PTR (ret); + +return &pll_pclksel->hw; +} + +static int dp_pll_10nm_register (struct dp_pll_db *pll_10nm) +{ +struct clk_hw_onecell_data *hw_data; +int ret; +struct clk_hw *hw; + +struct msm_dp_pll *pll = pll_10nm->base; +struct device *dev = &pll_10nm->pdev->dev; +struct clk_hw **hws = pll_10nm->hws; +int num =0 ; +struct clk_init_data vco_init = { + .parent_data = &(const struct clk_parent_data ){ + .fw_name ="bi_tcxo" , + }, + .num_parents =1 ,
Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c line 278
Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +3
-0+ .name = "dp_vco_clk", + .ops = &dp_10nm_vco_clk_ops, + };I thought the plan was to not have a vco clk? Just expose the two clks for the link and the vco divider. Furthermore, drop the divider "parents" and implement a single clk that programs the right divider value for the various link rates chosen.
As mentioned in above diagram, there is an additional divider in the PLL after the VCO (vco_divided_clk_src). The input rate to the dispcc branch is (vco_rate * 10)/ vco_dividied_clk_src.
In order to know the MNDs at the dispcc, we need to know the input rate.
This register read is to figure out which divider value is currently being set in the PLL. This input rate is not the same as the link rate. When we move the PHY/PLL to a separate driver, we would have take care of finding a different way to get this input rate.
Quoted 93 lines
Quoted 93 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +5
-0+ +DRM_DEBUG_DP ("DP->id = %d" , pll_10nm->id); + + hw_data =devm_kzalloc (dev,sizeof (*hw_data) + + NUM_PROVIDED_CLKS * sizeof(struct
clk_hw*),drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +12
-0+ GFP_KERNEL); +if (!hw_data) +return -ENOMEM ; + + dp_vco_clk.hw.init = &vco_init; + ret =clk_hw_register (dev, &dp_vco_clk.hw); +if (ret) +return ret; + hws[num++] = &dp_vco_clk.hw; + + hw = clk_hw_register_fixed_factor(dev, "dp_phy_pll_link_clk", + "dp_vco_clk", CLK_SET_RATE_PARENT, 1,10);
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +7
-0+ +if (IS_ERR (hw)) +return PTR_ERR (hw); + hws[num++] = hw; + hw_data->hws[DP_LINK_CLK_SRC ] = hw; + + hw = clk_hw_register_fixed_factor(dev,"
dp_vco_divsel_two_clk_src",drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +6
-0+ "dp_vco_clk", 0, 1, 2); +if (IS_ERR (hw)) +return PTR_ERR (hw); + hws[num++] = hw; + + hw = clk_hw_register_fixed_factor(dev,"
dp_vco_divsel_four_clk_src",drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +6
-0+ "dp_vco_clk", 0, 1, 4); +if (IS_ERR (hw)) +return PTR_ERR (hw); + hws[num++] = hw; + + hw = clk_hw_register_fixed_factor(dev,"
dp_vco_divsel_six_clk_src",drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +18
-0+ "dp_vco_clk", 0, 1, 6); +if (IS_ERR (hw)) +return PTR_ERR (hw); + hws[num++] = hw; + + hw =dp_pll_10nm_pixel_clk_sel (pll_10nm); +if (IS_ERR (hw)) +return PTR_ERR (hw); + + hws[num++] = hw; + hw_data->hws[DP_PIXEL_CLK_SRC ] = hw; + + pll_10nm->num_hws = num; + + hw_data->num =NUM_PROVIDED_CLKS ; + pll->hw_data = hw_data; + + ret = of_clk_add_hw_provider(dev->of_node,
of_clk_hw_onecell_get,drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +3
-0+ pll->hw_data); +if (ret) { + DRM_DEV_ERROR(dev, "failed to register clk provider:%d\n",
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +15
-0+ ret); +return ret; + } + +return ret; +} + +int msm_dp_pll_10nm_init (struct msm_dp_pll *pll,int id) +{ +struct dp_pll_db *dp_10nm_pll; +struct platform_device *pdev = pll->pdev; +int ret; + + dp_10nm_pll = devm_kzalloc(&pdev->dev, + sizeof(*dp_10nm_pll),
GFP_KERNEL);drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +13
-0+if (!dp_10nm_pll) +return -ENOMEM ; + +DRM_DEBUG_DP ("DP PLL%d" , id); + + dp_10nm_pll->base = pll; + dp_10nm_pll->pdev = pll->pdev; + dp_10nm_pll->id = id; + dp_pdb = dp_10nm_pll; + pll->priv = (void *)dp_10nm_pll; + dp_vco_clk.priv = pll; + + ret = of_property_read_u32(pdev->dev.of_node, "cell-index",
Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c
Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +3
-0+ &dp_10nm_pll->index); +if (ret) { + DRM_ERROR("Unable to get the cell-index ret=%d\n",ret);
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +2
-0+ dp_10nm_pll->index =0 ; + }Is the cell-index used for anything?
No it is redundant and will be removed in next patch.
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +4
-0+ + ret =dp_pll_10nm_register (dp_10nm_pll); +if (ret) { + DRM_DEV_ERROR(&pdev->dev, "failed to register PLL:%d\n", ret);
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +3
-0+return ret; + } +
Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c line 379
Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +4
-0+ pll->get_provider = dp_pll_10nm_get_provider; + +return ret; +}_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi Stephen,
Thanks for reviews.
Please ignore previous response to this patch. Here, I have re-organized it.
Thanks,
Quoted 390 lines · On 2020-06-11 13:07, [email protected] wrote:
Quoted 18 lines · Stephen Boyd
Quoting Tanmay Shah (2020-06-08 20:46:23)
Quoted 17 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +1
-0@@ -5,6 +5,7 @@#define pr_fmt (fmt) "[drm-dp] %s: " fmt, __func__ +#include <linux/rational.h> #include <linux/delay.h> #include <linux/iopoll.h> #include <drm/drm_dp_helper.h> @@ -134,59 +135,61 @@ static inline void dp_write_ahb(struct dp_catalog_private *catalog,writel (data, catalog->io->dp_controller.base + offset); }Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c static inline void dp_write_ahb(struct dp_catalog_private *catalog, · line 141
Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +0
-5-static inline u32 dp_read_cc (struct dp_catalog_private *catalog,u32 offset) -{ -return readl_relaxed (catalog->io->dp_cc_io.base + offset); -} -Why was this added in the first place? Remove it from the place it came in please.
Sure. I will remove it as part of DP base driver patch.
Quoted 24 lines
Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +1
-0static inline void dp_write_phy (struct dp_catalog_private *catalog,u32 offset,u32 data) { + offset +=DP_PHY_REG_OFFSET ;/* * To make sure phy reg writes happens before any other operation, [...]
Quoted 16 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +2
-1@@ -568,17 +574,37 @@ void dp_catalog_ctrl_config_msa(struct dp_catalog *dp_catalog, bool fixed_nvid) {u32 pixel_m, pixel_n; -u32 mvid, nvid; +u32 mvid, nvid, div, pixel_div =0 , dispcc_input_rate;u32 const nvid_fixed =DP_LINK_CONSTANT_N_VALUE ;u32 const link_rate_hbr2 =540000 ;u32 const link_rate_hbr3 =810000 ; +unsigned long den, num;struct dp_catalog_private *catalog =container_of (dp_catalog, struct dp_catalog_private, dp_catalog);Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c void dp_catalog_ctrl_config_msa(struct dp_catalog *dp_catalog, · line 586
Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +1
-3- pixel_m =dp_read_cc (catalog,MMSS_DP_PIXEL_M ); - pixel_n =dp_read_cc (catalog,MMSS_DP_PIXEL_N ); -DRM_DEBUG_DP ("pixel_m=0x%x, pixel_n=0x%x\n" , pixel_m, pixel_n); + div =dp_read_phy (catalog,REG_DP_PHY_VCO_DIV );Why do we need to read the phy? The
pixel_divseems to match what the clk driver is doing so presumably we can make this follow the link rate being used vs. having to read the phy.As mentioned in above diagram, there is an additional divider in the PLL after the VCO (
vco_divided_clk_src).
The input rate to the dispcc branch is (vco_rate* 10)/vco_dividied_clk_src. In order to know the MNDs at the dispcc, we need to know the input rate. This register read is to figure out which divider value is currently being set in the PLL.
This input rate is not the same as the link rate. When we move the PHY/PLL to a separate driver,
we would have take care of finding a different way to get this input rate.Quoted 89 lines
Quoted 89 lines
drivers/gpu/drm/msm/dp/dp_catalog.c +14
-0+ div &=0x03 ; + +if (div ==0 ) + pixel_div =6 ; +else if (div ==1 ) + pixel_div =2 ; +else if (div ==2 ) + pixel_div =4 ; +else +DRM_ERROR ("Invalid pixel mux divider\n" ); + + dispcc_input_rate = (rate *10 ) / pixel_div; + + rational_best_approximation(dispcc_input_rate,
stream_rate_khz,drivers/gpu/drm/msm/dp/dp_catalog.c +7
-0+ (unsigned long )(1 <<16 ) -1 , + (unsigned long)(1 << 16) - 1, &den, &num); + + den = ~(den - num); + den = den &0xFFFF ; + pixel_m = num; + pixel_n = den; mvid = (pixel_m &0xFFFF ) *5 ; nvid = (0xFFFF & (~pixel_n)) + (pixel_m &0xFFFF );drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +3
-0@@ -0,0 +1,903 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
+ */drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +53
-0+ +/* +* Display Port PLL driver block diagram for branch clocks +* +* +------------------------------+ +* | DP_VCO_CLK | +* | | +* | +-------------------+ | +* | | (DP PLL/VCO) | | +* | +---------+---------+ | +* | v | +* | +----------+-----------+ | +* | | hsclk_divsel_clk_src | | +* | +----------+-----------+ | +* +------------------------------+ +* | +* +---------<---------v------------>----------+ +* | | +* +--------v---------+ | +* | dp_phy_pll | | +* | link_clk | | +* +--------+---------+ | +* | | +* | | +* v v +* Input to DISPCC block | +* for link clk, crypto clk | +* and interface clock | +* | +* | +* +--------<------------+-----------------+---<---+ +* | | | +* +----v---------+ +--------v-----+ +--------v------+ +* | vco_divided | | vco_divided | | vco_divided | +* | _clk_src | | _clk_src | | _clk_src | +* | | | | | | +* |divsel_six | | divsel_two | | divsel_four | +* +-------+------+ +-----+--------+ +--------+------+ +* | | | +* v---->----------v-------------<------v +* | +* +----------+---------+ +* | dp_phy_pll_vco | +* | div_clk | +* +---------+----------+ +* | +* v +* Input to DISPCC block +* for DP pixel clock +* +*/ + +#include <linux/clk.h> Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c line 62
Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +5
-0+#include <linux/delay.h> +#include <linux/err.h> +#include <linux/kernel.h> +#include <linux/regmap.h> +#include <linux/iopoll.h> Should be a
clk-provider.hinclude here given that this is providing clks.Yes. currently it is included in
dp_parser.hbut I will include here as well.Quoted 116 lines
Quoted 116 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +37
-0+ +#include "dp_hpd.h" +#include "dp_pll.h" +#include "dp_pll_private.h" + +#define NUM_PROVIDED_CLKS 2 + +#define DP_LINK_CLK_SRC 0 +#define DP_PIXEL_CLK_SRC 1 + +static struct dp_pll_db *dp_pdb; + +static const struct clk_ops dp_10nm_vco_clk_ops = { + .recalc_rate = dp_vco_recalc_rate_10nm, + .set_rate = dp_vco_set_rate_10nm, + .round_rate = dp_vco_round_rate_10nm, + .prepare = dp_vco_prepare_10nm, + .unprepare = dp_vco_unprepare_10nm, +}; + +struct dp_pll_10nm_pclksel { +struct clk_hw hw; + +/* divider params */ +u8 shift; +u8 width; +u8 flags;/* same flags as used by clk_divider struct */ + +struct dp_pll_db *pll; +}; + +#define to_pll_10nm_pclksel (_hw) \ + container_of(_hw, struct dp_pll_10nm_pclksel, hw) + +static const struct clk_parent_data disp_cc_parent_data_0[] = { + { .fw_name ="bi_tcxo" }, + { .fw_name = "dp_phy_pll_link_clk", .name ="
dp_phy_pll_link_clk" },drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +3
-0+ { .fw_name = "dp_phy_pll_vco_div_clk", + .name = "dp_phy_pll_vco_div_clk"}, + { .fw_name = "core_bi_pll_test_se", .name ="
core_bi_pll_test_se" },drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +10
-0+}; + +static struct dp_pll_vco_clk dp_vco_clk = { + .min_rate =DP_VCO_HSCLK_RATE_1620MHZDIV1000 , + .max_rate =DP_VCO_HSCLK_RATE_8100MHZDIV1000 , +}; + +static int dp_pll_mux_set_parent_10nm (struct clk_hw *hw,u8 val) +{ + struct dp_pll_10nm_pclksel *pclksel =
to_pll_10nm_pclksel(hw);drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +17
-0+struct dp_pll_db *dp_res = pclksel->pll; +struct dp_io_pll *pll_io = &dp_res->base->pll_io; +u32 auxclk_div; + + auxclk_div =PLL_REG_R (pll_io->phy_base,REG_DP_PHY_VCO_DIV ); + auxclk_div &= ~0x03 ; + +if (val ==0 ) + auxclk_div |=1 ; +else if (val ==1 ) + auxclk_div |=2 ; +else if (val ==2 ) + auxclk_div |=0 ; + +PLL_REG_W (pll_io->phy_base, +REG_DP_PHY_VCO_DIV , auxclk_div); + DRM_DEBUG_DP("%s: mux=%d auxclk_div=%x\n", __func__, val,
auxclk_div);drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +8
-0+ +return 0 ; +} + +static u8 dp_pll_mux_get_parent_10nm (struct clk_hw *hw) +{ +u32 auxclk_div =0 ; + struct dp_pll_10nm_pclksel *pclksel =
to_pll_10nm_pclksel(hw);drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +15
-0+struct dp_pll_db *dp_res = pclksel->pll; +struct dp_io_pll *pll_io = &dp_res->base->pll_io; +u8 val =0 ; + + auxclk_div =PLL_REG_R (pll_io->phy_base,REG_DP_PHY_VCO_DIV ); + auxclk_div &=0x03 ; + +if (auxclk_div ==1 )/* Default divider */ + val =0 ; +else if (auxclk_div ==2 ) + val =1 ; +else if (auxclk_div ==0 ) + val =2 ; + + DRM_DEBUG_DP("%s: auxclk_div=%d, val=%d\n", __func__,
auxclk_div, val);drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +20
-0+ +return val; +} + +static int dp_pll_clk_mux_determine_rate (struct clk_hw *hw, +struct clk_rate_request *req) +{ +unsigned long rate =0 ; +int ret =0 ; + + rate =clk_get_rate (hw->clk); + +if (rate <=0 ) { +DRM_ERROR ("Rate is not set properly\n" ); +return -EINVAL ; + } + + req->rate = rate; + +DRM_DEBUG_DP ("%s: rate=%ld\n" , __func__, req->rate);Quoted 9 lines
Quoted 5 lines
+ /* Set the new parent of mux if there is a new valid parent
*/drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +2
-0+if (hw->clk && req->best_parent_hw->clk) { + ret = clk_set_parent(hw->clk,
req->best_parent_hw->clk);Why do we need to call clk consumer APIs from the clk provider ops? This is pretty confusing what's going on here.
Sure. Use of
clk_set_parentis redundant here and I will remove it.Quoted 63 lines
Quoted 63 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +2
-0+if (ret) { + DRM_ERROR("%s: clk_set_parent failed:ret=%d\n",
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +41
-0+ __func__, ret); +return ret; + } + } +return 0 ; +} + +static unsigned long dp_pll_mux_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +struct clk_hw *div_clk_hw =NULL , *vco_clk_hw =NULL ; +struct dp_pll_vco_clk *vco; + + div_clk_hw =clk_hw_get_parent (hw); +if (!div_clk_hw) +return 0 ; + + vco_clk_hw =clk_hw_get_parent (div_clk_hw); +if (!vco_clk_hw) +return 0 ; + + vco =to_dp_vco_hw (vco_clk_hw); +if (!vco) +return 0 ; + +if (vco->rate ==DP_VCO_HSCLK_RATE_8100MHZDIV1000 ) +return (vco->rate /6 ); +else if (vco->rate ==DP_VCO_HSCLK_RATE_5400MHZDIV1000 ) +return (vco->rate /4 ); +else +return (vco->rate /2 ); +} + +static int dp_pll_10nm_get_provider (struct msm_dp_pll *pll, +struct clk **link_clk_provider, +struct clk **pixel_clk_provider) +{ +struct clk_hw_onecell_data *hw_data = pll->hw_data; + +if (link_clk_provider) + *link_clk_provider =hw_data->hws[DP_LINK_CLK_SRC]->clk;
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +2
-0+if (pixel_clk_provider) + *pixel_clk_provider =hw_data->hws[DP_PIXEL_CLK_SRC]->clk;
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +12
-0+ +return 0 ; +} + +static const struct clk_ops dp_10nm_pclksel_clk_ops = { + .get_parent = dp_pll_mux_get_parent_10nm, + .set_parent = dp_pll_mux_set_parent_10nm, + .recalc_rate = dp_pll_mux_recalc_rate, + .determine_rate = dp_pll_clk_mux_determine_rate, +}; + +static struct clk_hw *dp_pll_10nm_pixel_clk_sel(struct dp_pll_db
*pll_10nm)drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +2
-0+{ +struct device *dev = &pll_10nm->pdev->dev;Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c line 239
Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +5
-0+struct dp_pll_10nm_pclksel *pll_pclksel; +struct clk_init_data pclksel_init = { + .parent_data = disp_cc_parent_data_0, + .num_parents =3 , + .name ="dp_phy_pll_vco_div_clk" ,So the
dp_phy_pll_vco_div_clkhas a potential parent that isdp_phy_pll_vco_div_clk. Huh?Thats right. I will remove
dp_phy_pll_vco_div_clkfrom parent listdisp_cc_parent_data_0.Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +5
-0+ .ops = &dp_10nm_pclksel_clk_ops, + }; +int ret; + + pll_pclksel = devm_kzalloc(dev, sizeof(*pll_pclksel),
GFP_KERNEL);
+ if (!pll_pclksel)Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c line 251
Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +6
-0+return ERR_PTR (-ENOMEM ); + + pll_pclksel->pll = pll_10nm; + pll_pclksel->shift =0 ; + pll_pclksel->width =4 ; + pll_pclksel->flags =CLK_DIVIDER_ONE_BASED ;Is this flag used?
Quoted 34 lines
No it is redundant. I will remove.
Quoted 33 lines
Quoted 17 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +17
-0+ pll_pclksel->hw.init = &pclksel_init; + + ret =clk_hw_register (dev, &pll_pclksel->hw); +if (ret) +return ERR_PTR (ret); + +return &pll_pclksel->hw; +} + +static int dp_pll_10nm_register (struct dp_pll_db *pll_10nm) +{ +struct clk_hw_onecell_data *hw_data; +int ret; +struct clk_hw *hw; + +struct msm_dp_pll *pll = pll_10nm->base; +struct device *dev = &pll_10nm->pdev->dev;drivers/gpu/drm/msm/dp/dp_pll_10nm.c line 278
Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +10
-0+struct clk_hw **hws = pll_10nm->hws; +int num =0 ; +struct clk_init_data vco_init = { + .parent_data = &(const struct clk_parent_data ){ + .fw_name ="bi_tcxo" , + }, + .num_parents =1 , + .name ="dp_vco_clk" , + .ops = &dp_10nm_vco_clk_ops, + };I thought the plan was to not have a vco clk? Just expose the two clks for the link and the vco divider. Furthermore, drop the divider "parents" and implement a single clk that programs the right divider value for the various link rates chosen.
This will be taken care at later point of time.
Quoted 123 lines
Quoted 93 lines
Quoted 93 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +5
-0+ +DRM_DEBUG_DP ("DP->id = %d" , pll_10nm->id); + + hw_data =devm_kzalloc (dev,sizeof (*hw_data) + + NUM_PROVIDED_CLKS * sizeof(struct
clk_hw*),drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +12
-0+ GFP_KERNEL); +if (!hw_data) +return -ENOMEM ; + + dp_vco_clk.hw.init = &vco_init; + ret =clk_hw_register (dev, &dp_vco_clk.hw); +if (ret) +return ret; + hws[num++] = &dp_vco_clk.hw; + + hw = clk_hw_register_fixed_factor(dev, "dp_phy_pll_link_clk", + "dp_vco_clk", CLK_SET_RATE_PARENT, 1,10);
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +7
-0+ +if (IS_ERR (hw)) +return PTR_ERR (hw); + hws[num++] = hw; + hw_data->hws[DP_LINK_CLK_SRC ] = hw; + + hw = clk_hw_register_fixed_factor(dev,"
dp_vco_divsel_two_clk_src",drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +6
-0+ "dp_vco_clk", 0, 1, 2); +if (IS_ERR (hw)) +return PTR_ERR (hw); + hws[num++] = hw; + + hw = clk_hw_register_fixed_factor(dev,"
dp_vco_divsel_four_clk_src",drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +6
-0+ "dp_vco_clk", 0, 1, 4); +if (IS_ERR (hw)) +return PTR_ERR (hw); + hws[num++] = hw; + + hw = clk_hw_register_fixed_factor(dev,"
dp_vco_divsel_six_clk_src",drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +18
-0+ "dp_vco_clk", 0, 1, 6); +if (IS_ERR (hw)) +return PTR_ERR (hw); + hws[num++] = hw; + + hw =dp_pll_10nm_pixel_clk_sel (pll_10nm); +if (IS_ERR (hw)) +return PTR_ERR (hw); + + hws[num++] = hw; + hw_data->hws[DP_PIXEL_CLK_SRC ] = hw; + + pll_10nm->num_hws = num; + + hw_data->num =NUM_PROVIDED_CLKS ; + pll->hw_data = hw_data; + + ret = of_clk_add_hw_provider(dev->of_node,
of_clk_hw_onecell_get,drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +3
-0+ pll->hw_data); +if (ret) { + DRM_DEV_ERROR(dev, "failed to register clk provider:%d\n",
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +15
-0+ ret); +return ret; + } + +return ret; +} + +int msm_dp_pll_10nm_init (struct msm_dp_pll *pll,int id) +{ +struct dp_pll_db *dp_10nm_pll; +struct platform_device *pdev = pll->pdev; +int ret; + + dp_10nm_pll = devm_kzalloc(&pdev->dev, + sizeof(*dp_10nm_pll),
GFP_KERNEL);drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +13
-0+if (!dp_10nm_pll) +return -ENOMEM ; + +DRM_DEBUG_DP ("DP PLL%d" , id); + + dp_10nm_pll->base = pll; + dp_10nm_pll->pdev = pll->pdev; + dp_10nm_pll->id = id; + dp_pdb = dp_10nm_pll; + pll->priv = (void *)dp_10nm_pll; + dp_vco_clk.priv = pll; + + ret = of_property_read_u32(pdev->dev.of_node, "cell-index",Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c
Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +3
-0+ &dp_10nm_pll->index); +if (ret) { + DRM_ERROR("Unable to get the cell-index ret=%d\n",ret);
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +2
-0+ dp_10nm_pll->index =0 ; + }Is the cell-index used for anything?
No it is redundant and will be removed in next patch.
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +4
-0+ + ret =dp_pll_10nm_register (dp_10nm_pll); +if (ret) { + DRM_DEV_ERROR(&pdev->dev, "failed to register PLL:%d\n", ret);
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +3
-0+return ret; + } +Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c line 379
Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_pll_10nm.c new file +4
-0+ pll->get_provider = dp_pll_10nm_get_provider; + +return ret; +}_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel