xref: /openbmc/linux/drivers/video/fbdev/via/via_clock.h (revision f7018c21350204c4cf628462f229d44d03545254)
1*f7018c21STomi Valkeinen /*
2*f7018c21STomi Valkeinen  * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3*f7018c21STomi Valkeinen  * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4*f7018c21STomi Valkeinen  * Copyright 2011 Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
5*f7018c21STomi Valkeinen  *
6*f7018c21STomi Valkeinen  * This program is free software; you can redistribute it and/or
7*f7018c21STomi Valkeinen  * modify it under the terms of the GNU General Public
8*f7018c21STomi Valkeinen  * License as published by the Free Software Foundation;
9*f7018c21STomi Valkeinen  * either version 2, or (at your option) any later version.
10*f7018c21STomi Valkeinen  *
11*f7018c21STomi Valkeinen  * This program is distributed in the hope that it will be useful,
12*f7018c21STomi Valkeinen  * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
13*f7018c21STomi Valkeinen  * the implied warranty of MERCHANTABILITY or FITNESS FOR
14*f7018c21STomi Valkeinen  * A PARTICULAR PURPOSE.See the GNU General Public License
15*f7018c21STomi Valkeinen  * for more details.
16*f7018c21STomi Valkeinen  *
17*f7018c21STomi Valkeinen  * You should have received a copy of the GNU General Public License
18*f7018c21STomi Valkeinen  * along with this program; if not, write to the Free Software
19*f7018c21STomi Valkeinen  * Foundation, Inc.,
20*f7018c21STomi Valkeinen  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21*f7018c21STomi Valkeinen  */
22*f7018c21STomi Valkeinen /*
23*f7018c21STomi Valkeinen  * clock and PLL management functions
24*f7018c21STomi Valkeinen  */
25*f7018c21STomi Valkeinen 
26*f7018c21STomi Valkeinen #ifndef __VIA_CLOCK_H__
27*f7018c21STomi Valkeinen #define __VIA_CLOCK_H__
28*f7018c21STomi Valkeinen 
29*f7018c21STomi Valkeinen #include <linux/types.h>
30*f7018c21STomi Valkeinen 
31*f7018c21STomi Valkeinen enum via_clksrc {
32*f7018c21STomi Valkeinen 	VIA_CLKSRC_X1 = 0,
33*f7018c21STomi Valkeinen 	VIA_CLKSRC_TVX1,
34*f7018c21STomi Valkeinen 	VIA_CLKSRC_TVPLL,
35*f7018c21STomi Valkeinen 	VIA_CLKSRC_DVP1TVCLKR,
36*f7018c21STomi Valkeinen 	VIA_CLKSRC_CAP0,
37*f7018c21STomi Valkeinen 	VIA_CLKSRC_CAP1,
38*f7018c21STomi Valkeinen };
39*f7018c21STomi Valkeinen 
40*f7018c21STomi Valkeinen struct via_pll_config {
41*f7018c21STomi Valkeinen 	u16 multiplier;
42*f7018c21STomi Valkeinen 	u8 divisor;
43*f7018c21STomi Valkeinen 	u8 rshift;
44*f7018c21STomi Valkeinen };
45*f7018c21STomi Valkeinen 
46*f7018c21STomi Valkeinen struct via_clock {
47*f7018c21STomi Valkeinen 	void (*set_primary_clock_state)(u8 state);
48*f7018c21STomi Valkeinen 	void (*set_primary_clock_source)(enum via_clksrc src, bool use_pll);
49*f7018c21STomi Valkeinen 	void (*set_primary_pll_state)(u8 state);
50*f7018c21STomi Valkeinen 	void (*set_primary_pll)(struct via_pll_config config);
51*f7018c21STomi Valkeinen 
52*f7018c21STomi Valkeinen 	void (*set_secondary_clock_state)(u8 state);
53*f7018c21STomi Valkeinen 	void (*set_secondary_clock_source)(enum via_clksrc src, bool use_pll);
54*f7018c21STomi Valkeinen 	void (*set_secondary_pll_state)(u8 state);
55*f7018c21STomi Valkeinen 	void (*set_secondary_pll)(struct via_pll_config config);
56*f7018c21STomi Valkeinen 
57*f7018c21STomi Valkeinen 	void (*set_engine_pll_state)(u8 state);
58*f7018c21STomi Valkeinen 	void (*set_engine_pll)(struct via_pll_config config);
59*f7018c21STomi Valkeinen };
60*f7018c21STomi Valkeinen 
61*f7018c21STomi Valkeinen 
62*f7018c21STomi Valkeinen static inline u32 get_pll_internal_frequency(u32 ref_freq,
63*f7018c21STomi Valkeinen 	struct via_pll_config pll)
64*f7018c21STomi Valkeinen {
65*f7018c21STomi Valkeinen 	return ref_freq / pll.divisor * pll.multiplier;
66*f7018c21STomi Valkeinen }
67*f7018c21STomi Valkeinen 
68*f7018c21STomi Valkeinen static inline u32 get_pll_output_frequency(u32 ref_freq,
69*f7018c21STomi Valkeinen 	struct via_pll_config pll)
70*f7018c21STomi Valkeinen {
71*f7018c21STomi Valkeinen 	return get_pll_internal_frequency(ref_freq, pll) >> pll.rshift;
72*f7018c21STomi Valkeinen }
73*f7018c21STomi Valkeinen 
74*f7018c21STomi Valkeinen void via_clock_init(struct via_clock *clock, int gfx_chip);
75*f7018c21STomi Valkeinen 
76*f7018c21STomi Valkeinen #endif /* __VIA_CLOCK_H__ */
77