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 <video/omapdss.h>
23 #define HDMI_DEFAULT_REGN 16
24 #define HDMI_DEFAULT_REGM2 1
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
, unsigned long clkin
, int phy
)
44 struct hdmi_pll_info
*pi
= &pll
->info
;
48 /* use our funky units */
52 * Input clock is predivided by N + 1
53 * out put of which is reference clk
56 pi
->regn
= HDMI_DEFAULT_REGN
;
58 refclk
= clkin
/ pi
->regn
;
60 pi
->regm2
= HDMI_DEFAULT_REGM2
;
63 * multiplier is pixel_clk/ref_clk
64 * Multiplying by 100 to avoid fractional part removal
66 pi
->regm
= phy
* pi
->regm2
/ refclk
;
69 * fractional multiplier is remainder of the difference between
70 * multiplier and actual phy(required pixel clock thus should be
71 * multiplied by 2^18(262144) divided by the reference clock
73 mf
= (phy
- pi
->regm
/ pi
->regm2
* refclk
) * 262144;
74 pi
->regmf
= pi
->regm2
* mf
/ refclk
;
77 * Dcofreq should be set to 1 if required pixel clock
78 * is greater than 1000MHz
80 pi
->dcofreq
= phy
> 1000 * 100;
81 pi
->regsd
= ((pi
->regm
* clkin
/ 10) / (pi
->regn
* 250) + 5) / 10;
83 /* Set the reference clock to sysclk reference */
84 pi
->refsel
= HDMI_REFSEL_SYSCLK
;
86 DSSDBG("M = %d Mf = %d\n", pi
->regm
, pi
->regmf
);
87 DSSDBG("range = %d sd = %d\n", pi
->dcofreq
, pi
->regsd
);
91 static int hdmi_pll_config(struct hdmi_pll_data
*pll
)
94 struct hdmi_pll_info
*fmt
= &pll
->info
;
96 /* PLL start always use manual mode */
97 REG_FLD_MOD(pll
->base
, PLLCTRL_PLL_CONTROL
, 0x0, 0, 0);
99 r
= hdmi_read_reg(pll
->base
, PLLCTRL_CFG1
);
100 r
= FLD_MOD(r
, fmt
->regm
, 20, 9); /* CFG1_PLL_REGM */
101 r
= FLD_MOD(r
, fmt
->regn
- 1, 8, 1); /* CFG1_PLL_REGN */
102 hdmi_write_reg(pll
->base
, PLLCTRL_CFG1
, r
);
104 r
= hdmi_read_reg(pll
->base
, PLLCTRL_CFG2
);
106 r
= FLD_MOD(r
, 0x0, 12, 12); /* PLL_HIGHFREQ divide by 2 */
107 r
= FLD_MOD(r
, 0x1, 13, 13); /* PLL_REFEN */
108 r
= FLD_MOD(r
, 0x0, 14, 14); /* PHY_CLKINEN de-assert during locking */
109 r
= FLD_MOD(r
, fmt
->refsel
, 22, 21); /* REFSEL */
112 /* divider programming for frequency beyond 1000Mhz */
113 REG_FLD_MOD(pll
->base
, PLLCTRL_CFG3
, fmt
->regsd
, 17, 10);
114 r
= FLD_MOD(r
, 0x4, 3, 1); /* 1000MHz and 2000MHz */
116 r
= FLD_MOD(r
, 0x2, 3, 1); /* 500MHz and 1000MHz */
119 hdmi_write_reg(pll
->base
, PLLCTRL_CFG2
, r
);
121 r
= hdmi_read_reg(pll
->base
, PLLCTRL_CFG4
);
122 r
= FLD_MOD(r
, fmt
->regm2
, 24, 18);
123 r
= FLD_MOD(r
, fmt
->regmf
, 17, 0);
124 hdmi_write_reg(pll
->base
, PLLCTRL_CFG4
, r
);
127 REG_FLD_MOD(pll
->base
, PLLCTRL_PLL_GO
, 0x1, 0, 0);
129 /* wait for bit change */
130 if (hdmi_wait_for_bit_change(pll
->base
, PLLCTRL_PLL_GO
,
132 DSSERR("PLL GO bit not set\n");
136 /* Wait till the lock bit is set in PLL status */
137 if (hdmi_wait_for_bit_change(pll
->base
,
138 PLLCTRL_PLL_STATUS
, 1, 1, 1) != 1) {
139 DSSERR("cannot lock PLL\n");
140 DSSERR("CFG1 0x%x\n",
141 hdmi_read_reg(pll
->base
, PLLCTRL_CFG1
));
142 DSSERR("CFG2 0x%x\n",
143 hdmi_read_reg(pll
->base
, PLLCTRL_CFG2
));
144 DSSERR("CFG4 0x%x\n",
145 hdmi_read_reg(pll
->base
, PLLCTRL_CFG4
));
149 DSSDBG("PLL locked!\n");
154 static int hdmi_pll_reset(struct hdmi_pll_data
*pll
)
156 /* SYSRESET controlled by power FSM */
157 REG_FLD_MOD(pll
->base
, PLLCTRL_PLL_CONTROL
, 0x0, 3, 3);
159 /* READ 0x0 reset is in progress */
160 if (hdmi_wait_for_bit_change(pll
->base
, PLLCTRL_PLL_STATUS
, 0, 0, 1)
162 DSSERR("Failed to sysreset PLL\n");
169 int hdmi_pll_enable(struct hdmi_pll_data
*pll
, struct hdmi_wp_data
*wp
)
173 r
= hdmi_wp_set_pll_pwr(wp
, HDMI_PLLPWRCMD_ALLOFF
);
177 r
= hdmi_wp_set_pll_pwr(wp
, HDMI_PLLPWRCMD_BOTHON_ALLCLKS
);
181 r
= hdmi_pll_reset(pll
);
185 r
= hdmi_pll_config(pll
);
192 void hdmi_pll_disable(struct hdmi_pll_data
*pll
, struct hdmi_wp_data
*wp
)
194 hdmi_wp_set_pll_pwr(wp
, HDMI_PLLPWRCMD_ALLOFF
);
197 #define PLL_OFFSET 0x200
198 #define PLL_SIZE 0x100
200 int hdmi_pll_init(struct platform_device
*pdev
, struct hdmi_pll_data
*pll
)
202 struct resource
*res
;
203 struct resource temp_res
;
205 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "pll");
207 DSSDBG("can't get PLL mem resource by name\n");
209 * if hwmod/DT doesn't have the memory resource information
210 * split into HDMI sub blocks by name, we try again by getting
211 * the platform's first resource. this code will be removed when
212 * the driver can get the mem resources by name
214 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
216 DSSERR("can't get PLL mem resource\n");
220 temp_res
.start
= res
->start
+ PLL_OFFSET
;
221 temp_res
.end
= temp_res
.start
+ PLL_SIZE
- 1;
225 pll
->base
= devm_ioremap(&pdev
->dev
, res
->start
, resource_size(res
));
227 DSSERR("can't ioremap PLLCTRL\n");