4 * Copyright (C) 2013 Texas Instruments Incorporated
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
11 #define DSS_SUBSYS_NAME "HDMIPLL"
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/err.h>
17 #include <linux/platform_device.h>
18 #include <linux/clk.h>
19 #include <linux/seq_file.h>
21 #include <video/omapfb_dss.h>
26 void hdmi_pll_dump(struct hdmi_pll_data
*pll
, struct seq_file
*s
)
28 #define DUMPPLL(r) seq_printf(s, "%-35s %08x\n", #r,\
29 hdmi_read_reg(pll->base, r))
31 DUMPPLL(PLLCTRL_PLL_CONTROL
);
32 DUMPPLL(PLLCTRL_PLL_STATUS
);
33 DUMPPLL(PLLCTRL_PLL_GO
);
34 DUMPPLL(PLLCTRL_CFG1
);
35 DUMPPLL(PLLCTRL_CFG2
);
36 DUMPPLL(PLLCTRL_CFG3
);
37 DUMPPLL(PLLCTRL_SSC_CFG1
);
38 DUMPPLL(PLLCTRL_SSC_CFG2
);
39 DUMPPLL(PLLCTRL_CFG4
);
42 void hdmi_pll_compute(struct hdmi_pll_data
*pll
,
43 unsigned long target_tmds
, struct dss_pll_clock_info
*pi
)
45 unsigned long fint
, clkdco
, clkout
;
46 unsigned long target_bitclk
, target_clkdco
;
47 unsigned long min_dco
;
48 unsigned n
, m
, mf
, m2
, sd
;
50 const struct dss_pll_hw
*hw
= pll
->pll
.hw
;
52 clkin
= clk_get_rate(pll
->pll
.clkin
);
54 DSSDBG("clkin %lu, target tmds %lu\n", clkin
, target_tmds
);
56 target_bitclk
= target_tmds
* 10;
59 n
= DIV_ROUND_UP(clkin
, hw
->fint_max
);
62 /* adjust m2 so that the clkdco will be high enough */
63 min_dco
= roundup(hw
->clkdco_min
, fint
);
64 m2
= DIV_ROUND_UP(min_dco
, target_bitclk
);
68 target_clkdco
= target_bitclk
* m2
;
69 m
= target_clkdco
/ fint
;
73 /* adjust clkdco with fractional mf */
74 if (WARN_ON(target_clkdco
- clkdco
> fint
))
77 mf
= (u32
)div_u64(262144ull * (target_clkdco
- clkdco
), fint
);
80 clkdco
+= (u32
)div_u64((u64
)mf
* fint
, 262144);
85 sd
= DIV_ROUND_UP(fint
* m
, 250000000);
87 DSSDBG("N = %u, M = %u, M.f = %u, M2 = %u, SD = %u\n",
89 DSSDBG("Fint %lu, clkdco %lu, clkout %lu\n", fint
, clkdco
, clkout
);
99 pi
->clkout
[0] = clkout
;
102 static int hdmi_pll_enable(struct dss_pll
*dsspll
)
104 struct hdmi_pll_data
*pll
= container_of(dsspll
, struct hdmi_pll_data
, pll
);
105 struct hdmi_wp_data
*wp
= pll
->wp
;
108 dss_ctrl_pll_enable(DSS_PLL_HDMI
, true);
110 r
= hdmi_wp_set_pll_pwr(wp
, HDMI_PLLPWRCMD_BOTHON_ALLCLKS
);
117 static void hdmi_pll_disable(struct dss_pll
*dsspll
)
119 struct hdmi_pll_data
*pll
= container_of(dsspll
, struct hdmi_pll_data
, pll
);
120 struct hdmi_wp_data
*wp
= pll
->wp
;
122 hdmi_wp_set_pll_pwr(wp
, HDMI_PLLPWRCMD_ALLOFF
);
124 dss_ctrl_pll_enable(DSS_PLL_HDMI
, false);
127 static const struct dss_pll_ops dsi_pll_ops
= {
128 .enable
= hdmi_pll_enable
,
129 .disable
= hdmi_pll_disable
,
130 .set_config
= dss_pll_write_config_type_b
,
133 static const struct dss_pll_hw dss_omap4_hdmi_pll_hw
= {
141 .clkdco_min
= 500000000,
142 .clkdco_low
= 1000000000,
143 .clkdco_max
= 2000000000,
153 .has_selfreqdco
= true,
156 static const struct dss_pll_hw dss_omap5_hdmi_pll_hw
= {
164 .clkdco_min
= 750000000,
165 .clkdco_low
= 1500000000,
166 .clkdco_max
= 2500000000UL,
176 .has_selfreqdco
= true,
180 static int dsi_init_pll_data(struct platform_device
*pdev
, struct hdmi_pll_data
*hpll
)
182 struct dss_pll
*pll
= &hpll
->pll
;
186 clk
= devm_clk_get(&pdev
->dev
, "sys_clk");
188 DSSERR("can't get sys_clk\n");
193 pll
->id
= DSS_PLL_HDMI
;
194 pll
->base
= hpll
->base
;
197 switch (omapdss_get_version()) {
198 case OMAPDSS_VER_OMAP4430_ES1
:
199 case OMAPDSS_VER_OMAP4430_ES2
:
200 case OMAPDSS_VER_OMAP4
:
201 pll
->hw
= &dss_omap4_hdmi_pll_hw
;
204 case OMAPDSS_VER_OMAP5
:
205 case OMAPDSS_VER_DRA7xx
:
206 pll
->hw
= &dss_omap5_hdmi_pll_hw
;
213 pll
->ops
= &dsi_pll_ops
;
215 r
= dss_pll_register(pll
);
222 int hdmi_pll_init(struct platform_device
*pdev
, struct hdmi_pll_data
*pll
,
223 struct hdmi_wp_data
*wp
)
226 struct resource
*res
;
230 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "pll");
232 DSSERR("can't get PLL mem resource\n");
236 pll
->base
= devm_ioremap_resource(&pdev
->dev
, res
);
237 if (IS_ERR(pll
->base
)) {
238 DSSERR("can't ioremap PLLCTRL\n");
239 return PTR_ERR(pll
->base
);
242 r
= dsi_init_pll_data(pdev
, pll
);
244 DSSERR("failed to init HDMI PLL\n");
251 void hdmi_pll_uninit(struct hdmi_pll_data
*hpll
)
253 struct dss_pll
*pll
= &hpll
->pll
;
255 dss_pll_unregister(pll
);