Skip to content

Commit

Permalink
drm/starfive: Use clock api
Browse files Browse the repository at this point in the history
Signed-off-by: Emil Renner Berthing <[email protected]>
  • Loading branch information
esmil committed Dec 27, 2021
1 parent e4b380e commit bab456b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
18 changes: 17 additions & 1 deletion drivers/gpu/drm/starfive/starfive_drm_crtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,24 @@ static int starfive_crtc_get_memres(struct platform_device *pdev, struct starfiv
dev_err(&pdev->dev, "Could not match resource name\n");
}

sf_crtc->topclk = ioremap(0x11800000, 0x10000);
sf_crtc->toprst = ioremap(0x11840000, 0x10000);

return 0;
}

static int starfive_crtc_get_clks(struct platform_device *pdev, struct starfive_crtc *sf_crtc)
{
struct clk_bulk_data clks[] = {
{ .id = "disp_axi" },
{ .id = "vout_src" },
};
int ret = devm_clk_bulk_get(&pdev->dev, ARRAY_SIZE(clks), clks);

sf_crtc->clk_disp_axi = clks[0].clk;
sf_crtc->clk_vout_src = clks[1].clk;
return ret;
}

static int starfive_parse_dt(struct device *dev, struct starfive_crtc *sf_crtc)
{
int ret;
Expand Down Expand Up @@ -412,6 +424,10 @@ static int starfive_crtc_bind(struct device *dev, struct device *master, void *d
if (ret)
return ret;

ret = starfive_crtc_get_clks(pdev, crtcp);
if (ret)
return ret;

ret = starfive_parse_dt(dev, crtcp);

crtcp->pp_conn_lcdc = starfive_pp_get_2lcdc_id(crtcp);
Expand Down
4 changes: 3 additions & 1 deletion drivers/gpu/drm/starfive/starfive_drm_crtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ struct starfive_crtc {
void __iomem *base_vpp2; // 0x120c0000
void __iomem *base_lcdc; // 0x12000000

void __iomem *topclk; // 0x11800000, 0x10000
struct clk *clk_disp_axi;
struct clk *clk_vout_src;

void __iomem *toprst; // 0x11840000, 0x10000

int lcdc_irq;
Expand Down
13 changes: 7 additions & 6 deletions drivers/gpu/drm/starfive/starfive_drm_vpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/*
* Copyright (C) 2021 StarFive Technology Co., Ltd.
*/
#include <linux/clk.h>
#include <linux/module.h>
#include <linux/delay.h>
#include "starfive_drm_vpp.h"
Expand Down Expand Up @@ -739,8 +740,8 @@ void dsitx_vout_init(struct starfive_crtc *sf_crtc)
sf_reg_status_wait(sf_crtc->toprst, rstgen_status1_REG, 23, 0);
sf_set_clear(sf_crtc->toprst, rstgen_assert1_REG, BIT(24), BIT(24));
sf_reg_status_wait(sf_crtc->toprst, rstgen_status1_REG, 24, 0);
sf_set_clear(sf_crtc->topclk, clk_disp_axi_ctrl_REG, BIT(31), BIT(31));
sf_set_clear(sf_crtc->topclk, clk_vout_src_ctrl_REG, BIT(31), BIT(31));
clk_prepare_enable(sf_crtc->clk_disp_axi);
clk_prepare_enable(sf_crtc->clk_vout_src);
sf_set_clear(sf_crtc->toprst, rstgen_assert1_REG, 0, BIT(23));
sf_reg_status_wait(sf_crtc->toprst, rstgen_status1_REG, 23, 1);
sf_set_clear(sf_crtc->toprst, rstgen_assert1_REG, 0, BIT(24));
Expand Down Expand Up @@ -770,8 +771,8 @@ void vout_reset(struct starfive_crtc *sf_crtc)

iowrite32(0xFFFFFFFF, sf_crtc->base_rst);

sf_set_clear(sf_crtc->topclk, clk_disp_axi_ctrl_REG, BIT(31), BIT(31));
sf_set_clear(sf_crtc->topclk, clk_vout_src_ctrl_REG, BIT(31), BIT(31));
clk_prepare_enable(sf_crtc->clk_disp_axi);
clk_prepare_enable(sf_crtc->clk_vout_src);

sf_set_clear(sf_crtc->toprst, rstgen_assert1_REG, 0, BIT(23));
sf_reg_status_wait(sf_crtc->toprst, rstgen_status1_REG, 23, 1);
Expand Down Expand Up @@ -807,8 +808,8 @@ void vout_disable(struct starfive_crtc *sf_crtc)
{
iowrite32(0xFFFFFFFF, sf_crtc->base_rst);

sf_set_clear(sf_crtc->topclk, clk_disp_axi_ctrl_REG, 0, BIT(31));
sf_set_clear(sf_crtc->topclk, clk_vout_src_ctrl_REG, 0, BIT(31));
clk_disable_unprepare(sf_crtc->clk_disp_axi);
clk_disable_unprepare(sf_crtc->clk_vout_src);

sf_set_clear(sf_crtc->toprst, rstgen_assert1_REG, BIT(23), BIT(23));
sf_reg_status_wait(sf_crtc->toprst, rstgen_status1_REG, 23, 0);
Expand Down
5 changes: 0 additions & 5 deletions drivers/gpu/drm/starfive/starfive_drm_vpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ struct pp_mode {
#define PP_COEF_B1 0
#define PP_OFFSET_1 16

//for vout reg
#define CLKGEN_BASE_ADDR 0x11800000

#define clk_disp_axi_ctrl_REG 0x1C0
#define clk_vout_src_ctrl_REG 0x1B4
#define rstgen_assert1_REG 0x4
#define rstgen_status1_REG 0x14
#define vout_rstgen_assert0_REG 0x0
Expand Down

0 comments on commit bab456b

Please sign in to comment.