1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2014 Texas Instruments Ltd
7 #include <linux/delay.h>
10 #include <linux/kernel.h>
11 #include <linux/platform_device.h>
12 #include <linux/sched.h>
14 #include <video/omapfb_dss.h>
17 #include "dss_features.h"
19 struct dss_video_pll
{
24 void __iomem
*clkctrl_base
;
27 #define REG_MOD(reg, val, start, end) \
28 writel_relaxed(FLD_MOD(readl_relaxed(reg), val, start, end), reg)
30 static void dss_dpll_enable_scp_clk(struct dss_video_pll
*vpll
)
32 REG_MOD(vpll
->clkctrl_base
, 1, 14, 14); /* CIO_CLK_ICG */
35 static void dss_dpll_disable_scp_clk(struct dss_video_pll
*vpll
)
37 REG_MOD(vpll
->clkctrl_base
, 0, 14, 14); /* CIO_CLK_ICG */
40 static void dss_dpll_power_enable(struct dss_video_pll
*vpll
)
42 REG_MOD(vpll
->clkctrl_base
, 2, 31, 30); /* PLL_POWER_ON_ALL */
45 * DRA7x PLL CTRL's PLL_PWR_STATUS seems to always return 0,
46 * so we have to use fixed delay here.
51 static void dss_dpll_power_disable(struct dss_video_pll
*vpll
)
53 REG_MOD(vpll
->clkctrl_base
, 0, 31, 30); /* PLL_POWER_OFF */
56 static int dss_video_pll_enable(struct dss_pll
*pll
)
58 struct dss_video_pll
*vpll
= container_of(pll
, struct dss_video_pll
, pll
);
61 r
= dss_runtime_get();
65 dss_ctrl_pll_enable(pll
->id
, true);
67 dss_dpll_enable_scp_clk(vpll
);
69 r
= dss_pll_wait_reset_done(pll
);
73 dss_dpll_power_enable(vpll
);
78 dss_dpll_disable_scp_clk(vpll
);
79 dss_ctrl_pll_enable(pll
->id
, false);
85 static void dss_video_pll_disable(struct dss_pll
*pll
)
87 struct dss_video_pll
*vpll
= container_of(pll
, struct dss_video_pll
, pll
);
89 dss_dpll_power_disable(vpll
);
91 dss_dpll_disable_scp_clk(vpll
);
93 dss_ctrl_pll_enable(pll
->id
, false);
98 static const struct dss_pll_ops dss_pll_ops
= {
99 .enable
= dss_video_pll_enable
,
100 .disable
= dss_video_pll_disable
,
101 .set_config
= dss_pll_write_config_type_a
,
104 static const struct dss_pll_hw dss_dra7_video_pll_hw
= {
105 .n_max
= (1 << 8) - 1,
106 .m_max
= (1 << 12) - 1,
107 .mX_max
= (1 << 5) - 1,
110 .clkdco_max
= 1800000000,
125 struct dss_pll
*dss_video_pll_init(struct platform_device
*pdev
, int id
,
126 struct regulator
*regulator
)
128 const char * const reg_name
[] = { "pll1", "pll2" };
129 const char * const clkctrl_name
[] = { "pll1_clkctrl", "pll2_clkctrl" };
130 const char * const clkin_name
[] = { "video1_clk", "video2_clk" };
132 struct dss_video_pll
*vpll
;
133 void __iomem
*pll_base
, *clkctrl_base
;
140 pll_base
= devm_platform_ioremap_resource_byname(pdev
, reg_name
[id
]);
141 if (IS_ERR(pll_base
)) {
142 dev_err(&pdev
->dev
, "failed to ioremap pll%d reg_name\n", id
);
143 return ERR_CAST(pll_base
);
148 clkctrl_base
= devm_platform_ioremap_resource_byname(pdev
, clkctrl_name
[id
]);
149 if (IS_ERR(clkctrl_base
)) {
150 dev_err(&pdev
->dev
, "failed to ioremap pll%d clkctrl\n", id
);
151 return ERR_CAST(clkctrl_base
);
156 clk
= devm_clk_get(&pdev
->dev
, clkin_name
[id
]);
158 DSSERR("can't get video pll clkin\n");
159 return ERR_CAST(clk
);
162 vpll
= devm_kzalloc(&pdev
->dev
, sizeof(*vpll
), GFP_KERNEL
);
164 return ERR_PTR(-ENOMEM
);
166 vpll
->dev
= &pdev
->dev
;
167 vpll
->clkctrl_base
= clkctrl_base
;
171 pll
->name
= id
== 0 ? "video0" : "video1";
172 pll
->id
= id
== 0 ? DSS_PLL_VIDEO1
: DSS_PLL_VIDEO2
;
174 pll
->regulator
= regulator
;
175 pll
->base
= pll_base
;
176 pll
->hw
= &dss_dra7_video_pll_hw
;
177 pll
->ops
= &dss_pll_ops
;
179 r
= dss_pll_register(pll
);
186 void dss_video_pll_uninit(struct dss_pll
*pll
)
188 dss_pll_unregister(pll
);