Commit 14975cff authored by Chandan Uddaraju's avatar Chandan Uddaraju Committed by Rob Clark

drm/msm/dp: add support for DP PLL driver

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

Changes in v7:

-- Remove DRM_MSM_DP_PLL config from Makefile and Kconfig
-- Remove set_parent from determin_rate API
-- Remove phy_pll_vco_div_clk from parent list
-- Remove flag CLK_DIVIDER_ONE_BASED
-- Remove redundant cell-index property parsing

Changes in v8:

-- Unregister hardware clocks during driver cleanup

Changes in v9:

-- Remove redundant Kconfig option DRM_MSM_DP_10NM_PLL

Changes in v10:

-- Limit 10nm PLL function scope
Signed-off-by: default avatarChandan Uddaraju <chandanu@codeaurora.org>
Signed-off-by: default avatarVara Reddy <varar@codeaurora.org>
Signed-off-by: default avatarTanmay Shah <tanmay@codeaurora.org>
Signed-off-by: default avatarRob Clark <robdclark@chromium.org>
parent c943b494
......@@ -61,6 +61,7 @@ config DRM_MSM_HDMI_HDCP
config DRM_MSM_DP
bool "Enable DisplayPort support in MSM DRM driver"
depends on DRM_MSM
default y
help
Compile in support for DP driver in MSM DRM driver. DP external
display support is enabled through this config option. It can
......
......@@ -109,7 +109,9 @@ msm-$(CONFIG_DRM_MSM_DP)+= dp/dp_aux.o \
dp/dp_link.o \
dp/dp_panel.o \
dp/dp_parser.o \
dp/dp_power.o
dp/dp_power.o \
dp/dp_pll.o \
dp/dp_pll_10nm.o
msm-$(CONFIG_DRM_FBDEV_EMULATION) += msm_fbdev.o
msm-$(CONFIG_COMMON_CLK) += disp/mdp4/mdp4_lvds_pll.o
......
......@@ -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 <linux/rational.h>
......@@ -131,51 +132,58 @@ static inline void dp_write_ahb(struct dp_catalog_private *catalog,
static 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,
* this function uses writel() instread of writel_relaxed()
*/
writel(data, catalog->io->phy_io.base + offset);
writel(data, catalog->io->phy_reg.base + offset);
}
static inline u32 dp_read_phy(struct dp_catalog_private *catalog,
u32 offset)
{
offset += DP_PHY_REG_OFFSET;
/*
* To make sure phy reg writes happens before any other operation,
* this function uses writel() instread of writel_relaxed()
*/
return readl_relaxed(catalog->io->phy_io.base + offset);
return readl_relaxed(catalog->io->phy_reg.base + offset);
}
static inline void dp_write_pll(struct dp_catalog_private *catalog,
u32 offset, u32 data)
{
writel_relaxed(data, catalog->io->dp_pll_io.base + offset);
offset += DP_PHY_PLL_OFFSET;
writel_relaxed(data, catalog->io->phy_reg.base + offset);
}
static inline void dp_write_ln_tx0(struct dp_catalog_private *catalog,
u32 offset, u32 data)
{
writel_relaxed(data, catalog->io->ln_tx0_io.base + offset);
offset += DP_PHY_LN_TX0_OFFSET;
writel_relaxed(data, catalog->io->phy_reg.base + offset);
}
static inline void dp_write_ln_tx1(struct dp_catalog_private *catalog,
u32 offset, u32 data)
{
writel_relaxed(data, catalog->io->ln_tx1_io.base + offset);
offset += DP_PHY_LN_TX1_OFFSET;
writel_relaxed(data, catalog->io->phy_reg.base + offset);
}
static inline u32 dp_read_ln_tx0(struct dp_catalog_private *catalog,
u32 offset)
{
return readl_relaxed(catalog->io->ln_tx0_io.base + offset);
offset += DP_PHY_LN_TX0_OFFSET;
return readl_relaxed(catalog->io->phy_reg.base + offset);
}
static inline u32 dp_read_ln_tx1(struct dp_catalog_private *catalog,
u32 offset)
{
return readl_relaxed(catalog->io->ln_tx1_io.base + offset);
offset += DP_PHY_LN_TX1_OFFSET;
return readl_relaxed(catalog->io->phy_reg.base + offset);
}
static inline void dp_write_usb_cm(struct dp_catalog_private *catalog,
......@@ -398,13 +406,16 @@ void dp_catalog_dump_regs(struct dp_catalog *dp_catalog)
dump_regs(catalog->io->usb3_dp_com.base, catalog->io->usb3_dp_com.len);
pr_info("LN TX0 regs\n");
dump_regs(catalog->io->ln_tx0_io.base, catalog->io->ln_tx0_io.len);
dump_regs(catalog->io->phy_reg.base + DP_PHY_LN_TX0_OFFSET,
DP_PHY_LN_TX0_SIZE);
pr_info("LN TX1 regs\n");
dump_regs(catalog->io->ln_tx1_io.base, catalog->io->ln_tx1_io.len);
dump_regs(catalog->io->phy_reg.base + DP_PHY_LN_TX1_OFFSET,
DP_PHY_LN_TX1_SIZE);
pr_info("DP PHY regs\n");
dump_regs(catalog->io->phy_io.base, catalog->io->phy_io.len);
dump_regs(catalog->io->phy_reg.base + DP_PHY_REG_OFFSET,
DP_PHY_REG_SIZE);
}
void dp_catalog_aux_setup(struct dp_catalog *dp_catalog)
......
......@@ -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 drm_dp_aux *aux;
......@@ -232,7 +234,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;
......@@ -410,6 +411,7 @@ static void dp_display_deinit_sub_modules(struct dp_display_private *dp)
dp_ctrl_put(dp->ctrl);
dp_panel_put(dp->panel);
dp_aux_put(dp->aux);
dp_pll_put(dp->pll);
}
static int dp_init_sub_modules(struct dp_display_private *dp)
......@@ -420,6 +422,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;
......@@ -450,6 +455,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);
......
......@@ -25,4 +25,7 @@ int dp_display_request_irq(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_ */
......@@ -6,6 +6,7 @@
#include <linux/of_gpio.h>
#include "dp_parser.h"
#include "dp_reg.h"
static const struct dp_regulator_cfg sdm845_dp_reg_cfg = {
.num = 2,
......@@ -52,6 +53,7 @@ static void dp_parser_unmap_io_resources(struct dp_parser *parser)
struct dp_io *io = &parser->io;
msm_dss_iounmap(&io->dp_controller);
msm_dss_iounmap(&io->phy_reg);
msm_dss_iounmap(&io->usb3_dp_com);
}
......
......@@ -10,6 +10,7 @@
#include "dpu_io_util.h"
#include "msm_drv.h"
#include "dp_pll.h"
#define DP_LABEL "MDSS DP DISPLAY"
#define DP_MAX_PIXEL_CLK_KHZ 675000
......@@ -66,10 +67,7 @@ struct dp_display_data {
*/
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_pll_io;
struct dss_io_data phy_reg;
struct dss_io_data usb3_dp_com;
};
......@@ -117,6 +115,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;
u32 max_dp_lanes;
......
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
*/
#include <linux/device.h>
#include "dp_parser.h"
#include "dp_pll.h"
#include "dp_pll_private.h"
static int dp_pll_get_phy_io(struct dp_parser *parser)
{
struct dp_io *io = &parser->io;
io->usb3_dp_com.base = ioremap(REG_USB3_DP_COM_REGION_BASE,
REG_USB3_DP_COM_REGION_SIZE);
if (!io->usb3_dp_com.base) {
DRM_ERROR("unable to map USB3 DP COM IO\n");
return -EIO;
}
/* ToDo(user): DP PLL and DP PHY will not be part of
* DP driver eventually so for now Hardcode Base and offsets
* of PHY registers so we can remove them from dts and bindings
*/
io->phy_reg.base = ioremap(REG_DP_PHY_REGION_BASE,
REG_DP_PHY_REGION_SIZE);
if (!io->phy_reg.base) {
DRM_ERROR("DP PHY io region mapping failed\n");
return -EIO;
}
io->phy_reg.len = REG_DP_PHY_REGION_SIZE;
return 0;
}
static int msm_dp_pll_init(struct msm_dp_pll *pll,
enum msm_dp_pll_type type, int id)
{
struct device *dev = &pll->pdev->dev;
int ret = 0;
switch (type) {
case MSM_DP_PLL_10NM:
ret = msm_dp_pll_10nm_init(pll, id);
break;
default:
DRM_DEV_ERROR(dev, "%s: Wrong PLL type %d\n", __func__, type);
return -ENXIO;
}
if (ret) {
DRM_DEV_ERROR(dev, "%s: failed to init DP PLL\n", __func__);
return ret;
}
pll->type = type;
DRM_DEBUG_DP("DP:%d PLL registered", id);
return ret;
}
struct msm_dp_pll *dp_pll_get(struct dp_pll_in *pll_in)
{
struct msm_dp_pll *dp_pll;
struct dp_parser *parser = pll_in->parser;
struct dp_io_pll *pll_io;
int ret;
dp_pll = devm_kzalloc(&pll_in->pdev->dev, sizeof(*dp_pll), GFP_KERNEL);
if (!dp_pll)
return ERR_PTR(-ENOMEM);
pll_io = &dp_pll->pll_io;
dp_pll->pdev = pll_in->pdev;
dp_pll_get_phy_io(parser);
pll_io->pll_base = parser->io.phy_reg.base + DP_PHY_PLL_OFFSET;
pll_io->phy_base = parser->io.phy_reg.base + DP_PHY_REG_OFFSET;
pll_io->ln_tx0_base = parser->io.phy_reg.base + DP_PHY_LN_TX0_OFFSET;
pll_io->ln_tx1_base = parser->io.phy_reg.base + DP_PHY_LN_TX1_OFFSET;
ret = msm_dp_pll_init(dp_pll, MSM_DP_PLL_10NM, 0);
if (ret) {
kfree(dp_pll);
return ERR_PTR(ret);
}
return dp_pll;
}
void dp_pll_put(struct msm_dp_pll *dp_pll)
{
if (dp_pll->type == MSM_DP_PLL_10NM)
msm_dp_pll_10nm_deinit(dp_pll);
}
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
*/
#ifndef __DP_PLL_H
#define __DP_PLL_H
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/platform_device.h>
#include "dpu_io_util.h"
#include "msm_drv.h"
#include "dp_parser.h"
#define PLL_REG_W(base, offset, data) \
writel((data), (base) + (offset))
#define PLL_REG_R(base, offset) readl((base) + (offset))
enum msm_dp_pll_type {
MSM_DP_PLL_10NM,
MSM_DP_PLL_MAX
};
struct dp_pll_in {
struct platform_device *pdev;
struct dp_parser *parser;
};
struct dp_io_pll {
void __iomem *pll_base;
void __iomem *phy_base;
void __iomem *ln_tx0_base;
void __iomem *ln_tx1_base;
};
struct msm_dp_pll {
enum msm_dp_pll_type type;
bool pll_on;
struct dp_io_pll pll_io;
/* clock-provider: */
struct clk_hw_onecell_data *hw_data;
struct platform_device *pdev;
void *priv;
/* Pll specific resources like GPIO, power supply, clocks, etc*/
struct dss_module_power mp;
int (*get_provider)(struct msm_dp_pll *pll,
struct clk **link_clk_provider,
struct clk **pixel_clk_provider);
};
struct msm_dp_pll *dp_pll_get(struct dp_pll_in *pll_in);
void dp_pll_put(struct msm_dp_pll *dp_pll);
#endif /* __DP_PLL_H */
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
*/
#ifndef __DP_PLL_10NM_H
#define __DP_PLL_10NM_H
#include "dp_pll.h"
#include "dp_reg.h"
#define DP_VCO_HSCLK_RATE_1620MHZDIV1000 1620000UL
#define DP_VCO_HSCLK_RATE_2700MHZDIV1000 2700000UL
#define DP_VCO_HSCLK_RATE_5400MHZDIV1000 5400000UL
#define DP_VCO_HSCLK_RATE_8100MHZDIV1000 8100000UL
#define NUM_DP_CLOCKS_MAX 6
#define DP_PHY_PLL_POLL_SLEEP_US 500
#define DP_PHY_PLL_POLL_TIMEOUT_US 10000
#define DP_VCO_RATE_8100MHZDIV1000 8100000UL
#define DP_VCO_RATE_9720MHZDIV1000 9720000UL
#define DP_VCO_RATE_10800MHZDIV1000 10800000UL
struct dp_pll_vco_clk {
struct clk_hw hw;
unsigned long rate; /* current vco rate */
u64 min_rate; /* min vco rate */
u64 max_rate; /* max vco rate */
void *priv;
};
struct dp_pll_db {
struct msm_dp_pll *base;
int id;
struct platform_device *pdev;
/* private clocks: */
bool fixed_factor_clk[NUM_DP_CLOCKS_MAX];
struct clk_hw *hws[NUM_DP_CLOCKS_MAX];
u32 num_hws;
/* lane and orientation settings */
u8 lane_cnt;
u8 orientation;
/* COM PHY settings */
u32 hsclk_sel;
u32 dec_start_mode0;
u32 div_frac_start1_mode0;
u32 div_frac_start2_mode0;
u32 div_frac_start3_mode0;
u32 integloop_gain0_mode0;
u32 integloop_gain1_mode0;
u32 vco_tune_map;
u32 lock_cmp1_mode0;
u32 lock_cmp2_mode0;
u32 lock_cmp3_mode0;
u32 lock_cmp_en;
/* PHY vco divider */
u32 phy_vco_div;
/*
* Certain pll's needs to update the same vco rate after resume in
* suspend/resume scenario. Cached the vco rate for such plls.
*/
unsigned long vco_cached_rate;
u32 cached_cfg0;
u32 cached_cfg1;
u32 cached_outdiv;
uint32_t index;
};
static inline struct dp_pll_vco_clk *to_dp_vco_hw(struct clk_hw *hw)
{
return container_of(hw, struct dp_pll_vco_clk, hw);
}
#define to_msm_dp_pll(vco) ((struct msm_dp_pll *)vco->priv)
#define to_dp_pll_db(x) ((struct dp_pll_db *)x->priv)
int msm_dp_pll_10nm_init(struct msm_dp_pll *dp_pll, int id);
void msm_dp_pll_10nm_deinit(struct msm_dp_pll *dp_pll);
#endif /* __DP_PLL_10NM_H */
......@@ -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",
......
......@@ -14,7 +14,6 @@
* @init: initializes the regulators/core clocks/GPIOs/pinctrl
* @deinit: turns off the regulators/core clocks/GPIOs/pinctrl
* @clk_enable: enable/disable the DP clocks
* @set_link_clk_parent: set the parent of DP link clock
* @set_pixel_clk_parent: set the parent of DP pixel clock
*/
struct dp_power {
......@@ -22,10 +21,49 @@ struct dp_power {
bool link_clks_on;
};
/**
* dp_power_init() - enable power supplies for display controller
*
* @power: instance of power module
* @flip: bool for flipping gpio direction
* return: 0 if success or error if failure.
*
* This API will turn on the regulators and configures gpio's
* aux/hpd.
*/
int dp_power_init(struct dp_power *power, bool flip);
/**
* dp_power_deinit() - turn off regulators and gpios.
*
* @power: instance of power module
* return: 0 for success
*
* This API turns off power and regulators.
*/
int dp_power_deinit(struct dp_power *power);
/**
* dp_power_clk_enable() - enable display controller clocks
*
* @power: instance of power module
* @pm_type: type of pm, core/ctrl/phy
* @enable: enables or disables
* return: pointer to allocated power module data
*
* This API will call setrate and enable for DP clocks
*/
int dp_power_clk_enable(struct dp_power *power, enum dp_pm_type pm_type,
bool enable);
/**
* dp_power_set_link_clk_parent() - configures parent of link clocks
*
* @power: instance of power module
* return: 0 for success, error for failures
*
* This API will set the link clock parent source
*/
int dp_power_set_link_clk_parent(struct dp_power *power);
/**
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment