1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
8 #define DSS_SUBSYS_NAME "HDMIPLL"
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/err.h>
14 #include <linux/platform_device.h>
15 #include <linux/clk.h>
16 #include <linux/seq_file.h>
17 #include <linux/pm_runtime.h>
23 void hdmi_pll_dump(struct hdmi_pll_data
*pll
, struct seq_file
*s
)
25 #define DUMPPLL(r) seq_printf(s, "%-35s %08x\n", #r,\
26 hdmi_read_reg(pll->base, r))
28 DUMPPLL(PLLCTRL_PLL_CONTROL
);
29 DUMPPLL(PLLCTRL_PLL_STATUS
);
30 DUMPPLL(PLLCTRL_PLL_GO
);
31 DUMPPLL(PLLCTRL_CFG1
);
32 DUMPPLL(PLLCTRL_CFG2
);
33 DUMPPLL(PLLCTRL_CFG3
);
34 DUMPPLL(PLLCTRL_SSC_CFG1
);
35 DUMPPLL(PLLCTRL_SSC_CFG2
);
36 DUMPPLL(PLLCTRL_CFG4
);
39 static int hdmi_pll_enable(struct dss_pll
*dsspll
)
41 struct hdmi_pll_data
*pll
= container_of(dsspll
, struct hdmi_pll_data
, pll
);
42 struct hdmi_wp_data
*wp
= pll
->wp
;
45 r
= pm_runtime_get_sync(&pll
->pdev
->dev
);
48 dss_ctrl_pll_enable(dsspll
, true);
50 r
= hdmi_wp_set_pll_pwr(wp
, HDMI_PLLPWRCMD_BOTHON_ALLCLKS
);
57 static void hdmi_pll_disable(struct dss_pll
*dsspll
)
59 struct hdmi_pll_data
*pll
= container_of(dsspll
, struct hdmi_pll_data
, pll
);
60 struct hdmi_wp_data
*wp
= pll
->wp
;
63 hdmi_wp_set_pll_pwr(wp
, HDMI_PLLPWRCMD_ALLOFF
);
65 dss_ctrl_pll_enable(dsspll
, false);
67 r
= pm_runtime_put_sync(&pll
->pdev
->dev
);
68 WARN_ON(r
< 0 && r
!= -ENOSYS
);
71 static const struct dss_pll_ops hdmi_pll_ops
= {
72 .enable
= hdmi_pll_enable
,
73 .disable
= hdmi_pll_disable
,
74 .set_config
= dss_pll_write_config_type_b
,
77 static const struct dss_pll_hw dss_omap4_hdmi_pll_hw
= {
78 .type
= DSS_PLL_TYPE_B
,
87 .clkdco_min
= 500000000,
88 .clkdco_low
= 1000000000,
89 .clkdco_max
= 2000000000,
99 .has_selfreqdco
= true,
102 static const struct dss_pll_hw dss_omap5_hdmi_pll_hw
= {
103 .type
= DSS_PLL_TYPE_B
,
112 .clkdco_min
= 750000000,
113 .clkdco_low
= 1500000000,
114 .clkdco_max
= 2500000000UL,
124 .has_selfreqdco
= true,
128 static int hdmi_init_pll_data(struct dss_device
*dss
,
129 struct platform_device
*pdev
,
130 struct hdmi_pll_data
*hpll
)
132 struct dss_pll
*pll
= &hpll
->pll
;
136 clk
= devm_clk_get(&pdev
->dev
, "sys_clk");
138 DSSERR("can't get sys_clk\n");
143 pll
->id
= DSS_PLL_HDMI
;
144 pll
->base
= hpll
->base
;
147 if (hpll
->wp
->version
== 4)
148 pll
->hw
= &dss_omap4_hdmi_pll_hw
;
150 pll
->hw
= &dss_omap5_hdmi_pll_hw
;
152 pll
->ops
= &hdmi_pll_ops
;
154 r
= dss_pll_register(dss
, pll
);
161 int hdmi_pll_init(struct dss_device
*dss
, struct platform_device
*pdev
,
162 struct hdmi_pll_data
*pll
, struct hdmi_wp_data
*wp
)
165 struct resource
*res
;
170 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "pll");
171 pll
->base
= devm_ioremap_resource(&pdev
->dev
, res
);
172 if (IS_ERR(pll
->base
))
173 return PTR_ERR(pll
->base
);
175 r
= hdmi_init_pll_data(dss
, pdev
, pll
);
177 DSSERR("failed to init HDMI PLL\n");
184 void hdmi_pll_uninit(struct hdmi_pll_data
*hpll
)
186 struct dss_pll
*pll
= &hpll
->pll
;
188 dss_pll_unregister(pll
);