xref: /openbmc/linux/arch/arm/mach-omap1/clock.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
23179a019STony Lindgren /*
33179a019STony Lindgren  *  linux/arch/arm/mach-omap1/clock.h
43179a019STony Lindgren  *
552650505SPaul Walmsley  *  Copyright (C) 2004 - 2005, 2009 Nokia corporation
63179a019STony Lindgren  *  Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>
73179a019STony Lindgren  *  Based on clocks.h by Tony Lindgren, Gordon McNutt and RidgeRun, Inc
83179a019STony Lindgren  */
93179a019STony Lindgren 
103179a019STony Lindgren #ifndef __ARCH_ARM_MACH_OMAP1_CLOCK_H
113179a019STony Lindgren #define __ARCH_ARM_MACH_OMAP1_CLOCK_H
123179a019STony Lindgren 
1352650505SPaul Walmsley #include <linux/clk.h>
14e10dd62fSPaul Walmsley #include <linux/clkdev.h>
15*c73b9099SJanusz Krzysztofik #include <linux/clk-provider.h>
16e10dd62fSPaul Walmsley 
17a135eaaeSPaul Walmsley struct module;
18*c73b9099SJanusz Krzysztofik struct omap1_clk;
19a135eaaeSPaul Walmsley 
20e10dd62fSPaul Walmsley struct omap_clk {
21e10dd62fSPaul Walmsley 	u16				cpu;
22e10dd62fSPaul Walmsley 	struct clk_lookup		lk;
23e10dd62fSPaul Walmsley };
24e10dd62fSPaul Walmsley 
25e10dd62fSPaul Walmsley #define CLK(dev, con, ck, cp)		\
26e10dd62fSPaul Walmsley 	{				\
27e10dd62fSPaul Walmsley 		 .cpu = cp,		\
28e10dd62fSPaul Walmsley 		.lk = {			\
29e10dd62fSPaul Walmsley 			.dev_id = dev,	\
30e10dd62fSPaul Walmsley 			.con_id = con,	\
31*c73b9099SJanusz Krzysztofik 			.clk_hw = ck,	\
32e10dd62fSPaul Walmsley 		},			\
33e10dd62fSPaul Walmsley 	}
34e10dd62fSPaul Walmsley 
35e10dd62fSPaul Walmsley /* Platform flags for the clkdev-OMAP integration code */
36e10dd62fSPaul Walmsley #define CK_310		(1 << 0)
37e10dd62fSPaul Walmsley #define CK_7XX		(1 << 1)	/* 7xx, 850 */
38e10dd62fSPaul Walmsley #define CK_1510		(1 << 2)
39e10dd62fSPaul Walmsley #define CK_16XX		(1 << 3)	/* 16xx, 17xx, 5912 */
40e10dd62fSPaul Walmsley #define CK_1710		(1 << 4)	/* 1710 extra for rate selection */
41e10dd62fSPaul Walmsley 
42a135eaaeSPaul Walmsley /**
43a135eaaeSPaul Walmsley  * struct clkops - some clock function pointers
44a135eaaeSPaul Walmsley  * @enable: fn ptr that enables the current clock in hardware
45a135eaaeSPaul Walmsley  * @disable: fn ptr that enables the current clock in hardware
46a135eaaeSPaul Walmsley  * @allow_idle: fn ptr that enables autoidle for the current clock in hardware
47a135eaaeSPaul Walmsley  */
48a135eaaeSPaul Walmsley struct clkops {
49*c73b9099SJanusz Krzysztofik 	int			(*enable)(struct omap1_clk *clk);
50*c73b9099SJanusz Krzysztofik 	void			(*disable)(struct omap1_clk *clk);
51a135eaaeSPaul Walmsley };
52a135eaaeSPaul Walmsley 
53a135eaaeSPaul Walmsley /*
54a135eaaeSPaul Walmsley  * struct clk.flags possibilities
55a135eaaeSPaul Walmsley  *
56a135eaaeSPaul Walmsley  * XXX document the rest of the clock flags here
57a135eaaeSPaul Walmsley  */
58a135eaaeSPaul Walmsley #define ENABLE_REG_32BIT	(1 << 0)	/* Use 32-bit access */
59a135eaaeSPaul Walmsley #define CLOCK_IDLE_CONTROL	(1 << 1)
60a135eaaeSPaul Walmsley #define CLOCK_NO_IDLE_PARENT	(1 << 2)
61a135eaaeSPaul Walmsley 
62a135eaaeSPaul Walmsley /**
63*c73b9099SJanusz Krzysztofik  * struct omap1_clk - OMAP1 struct clk
64*c73b9099SJanusz Krzysztofik  * @hw: struct clk_hw for common clock framework integration
65a135eaaeSPaul Walmsley  * @ops: struct clkops * for this clock
66a135eaaeSPaul Walmsley  * @rate: current clock rate
67a135eaaeSPaul Walmsley  * @enable_reg: register to write to enable the clock (see @enable_bit)
68a135eaaeSPaul Walmsley  * @recalc: fn ptr that returns the clock's current rate
69a135eaaeSPaul Walmsley  * @set_rate: fn ptr that can change the clock's current rate
70a135eaaeSPaul Walmsley  * @round_rate: fn ptr that can round the clock's current rate
71a135eaaeSPaul Walmsley  * @init: fn ptr to do clock-specific initialization
72a135eaaeSPaul Walmsley  * @enable_bit: bitshift to write to enable/disable the clock (see @enable_reg)
73a135eaaeSPaul Walmsley  * @fixed_div: when > 0, this clock's rate is its parent's rate / @fixed_div
74a135eaaeSPaul Walmsley  * @flags: see "struct clk.flags possibilities" above
75a135eaaeSPaul Walmsley  * @rate_offset: bitshift for rate selection bitfield (OMAP1 only)
76a135eaaeSPaul Walmsley  */
77*c73b9099SJanusz Krzysztofik struct omap1_clk {
78*c73b9099SJanusz Krzysztofik 	struct clk_hw		hw;
79a135eaaeSPaul Walmsley 	const struct clkops	*ops;
80a135eaaeSPaul Walmsley 	unsigned long		rate;
81a135eaaeSPaul Walmsley 	void __iomem		*enable_reg;
82*c73b9099SJanusz Krzysztofik 	unsigned long		(*recalc)(struct omap1_clk *clk, unsigned long rate);
83*c73b9099SJanusz Krzysztofik 	int			(*set_rate)(struct omap1_clk *clk, unsigned long rate,
84*c73b9099SJanusz Krzysztofik 					    unsigned long p_rate);
85*c73b9099SJanusz Krzysztofik 	long			(*round_rate)(struct omap1_clk *clk, unsigned long rate,
86*c73b9099SJanusz Krzysztofik 					      unsigned long *p_rate);
87*c73b9099SJanusz Krzysztofik 	int			(*init)(struct omap1_clk *clk);
88a135eaaeSPaul Walmsley 	u8			enable_bit;
89a135eaaeSPaul Walmsley 	u8			fixed_div;
90a135eaaeSPaul Walmsley 	u8			flags;
91a135eaaeSPaul Walmsley 	u8			rate_offset;
92a135eaaeSPaul Walmsley };
93*c73b9099SJanusz Krzysztofik #define to_omap1_clk(_hw)	container_of(_hw, struct omap1_clk, hw)
94a135eaaeSPaul Walmsley 
95*c73b9099SJanusz Krzysztofik void propagate_rate(struct omap1_clk *clk);
96*c73b9099SJanusz Krzysztofik unsigned long followparent_recalc(struct omap1_clk *clk, unsigned long p_rate);
97*c73b9099SJanusz Krzysztofik unsigned long omap_fixed_divisor_recalc(struct omap1_clk *clk, unsigned long p_rate);
98a135eaaeSPaul Walmsley 
99*c73b9099SJanusz Krzysztofik extern struct omap1_clk dummy_ck;
100d5e6072bSRussell King 
101e9b7086bSTony Lindgren int omap1_clk_init(void);
102e9b7086bSTony Lindgren void omap1_clk_late_init(void);
103*c73b9099SJanusz Krzysztofik unsigned long omap1_ckctl_recalc(struct omap1_clk *clk, unsigned long p_rate);
104*c73b9099SJanusz Krzysztofik long omap1_round_sossi_rate(struct omap1_clk *clk, unsigned long rate, unsigned long *p_rate);
105*c73b9099SJanusz Krzysztofik int omap1_set_sossi_rate(struct omap1_clk *clk, unsigned long rate, unsigned long p_rate);
106*c73b9099SJanusz Krzysztofik unsigned long omap1_sossi_recalc(struct omap1_clk *clk, unsigned long p_rate);
107*c73b9099SJanusz Krzysztofik unsigned long omap1_ckctl_recalc_dsp_domain(struct omap1_clk *clk, unsigned long p_rate);
108*c73b9099SJanusz Krzysztofik int omap1_clk_set_rate_dsp_domain(struct omap1_clk *clk, unsigned long rate,
109*c73b9099SJanusz Krzysztofik 				  unsigned long p_rate);
110*c73b9099SJanusz Krzysztofik long omap1_round_uart_rate(struct omap1_clk *clk, unsigned long rate, unsigned long *p_rate);
111*c73b9099SJanusz Krzysztofik int omap1_set_uart_rate(struct omap1_clk *clk, unsigned long rate, unsigned long p_rate);
112*c73b9099SJanusz Krzysztofik unsigned long omap1_uart_recalc(struct omap1_clk *clk, unsigned long p_rate);
113*c73b9099SJanusz Krzysztofik int omap1_set_ext_clk_rate(struct omap1_clk *clk, unsigned long rate, unsigned long p_rate);
114*c73b9099SJanusz Krzysztofik long omap1_round_ext_clk_rate(struct omap1_clk *clk, unsigned long rate, unsigned long *p_rate);
115*c73b9099SJanusz Krzysztofik int omap1_init_ext_clk(struct omap1_clk *clk);
116*c73b9099SJanusz Krzysztofik int omap1_select_table_rate(struct omap1_clk *clk, unsigned long rate, unsigned long p_rate);
117*c73b9099SJanusz Krzysztofik long omap1_round_to_table_rate(struct omap1_clk *clk, unsigned long rate, unsigned long *p_rate);
118*c73b9099SJanusz Krzysztofik int omap1_clk_set_rate_ckctl_arm(struct omap1_clk *clk, unsigned long rate, unsigned long p_rate);
119*c73b9099SJanusz Krzysztofik long omap1_clk_round_rate_ckctl_arm(struct omap1_clk *clk, unsigned long rate,
120*c73b9099SJanusz Krzysztofik 				    unsigned long *p_rate);
1213179a019STony Lindgren 
1223179a019STony Lindgren struct uart_clk {
123*c73b9099SJanusz Krzysztofik 	struct omap1_clk	clk;
1243179a019STony Lindgren 	unsigned long		sysc_addr;
1253179a019STony Lindgren };
1263179a019STony Lindgren 
1273179a019STony Lindgren /* Provide a method for preventing idling some ARM IDLECT clocks */
1283179a019STony Lindgren struct arm_idlect1_clk {
129*c73b9099SJanusz Krzysztofik 	struct omap1_clk	clk;
1303179a019STony Lindgren 	unsigned long		no_idle_count;
1313179a019STony Lindgren 	__u8			idlect_shift;
1323179a019STony Lindgren };
1333179a019STony Lindgren 
1343179a019STony Lindgren /* ARM_CKCTL bit shifts */
1353179a019STony Lindgren #define CKCTL_PERDIV_OFFSET	0
1363179a019STony Lindgren #define CKCTL_LCDDIV_OFFSET	2
1373179a019STony Lindgren #define CKCTL_ARMDIV_OFFSET	4
1383179a019STony Lindgren #define CKCTL_DSPDIV_OFFSET	6
1393179a019STony Lindgren #define CKCTL_TCDIV_OFFSET	8
1403179a019STony Lindgren #define CKCTL_DSPMMUDIV_OFFSET	10
1413179a019STony Lindgren /*#define ARM_TIMXO		12*/
1423179a019STony Lindgren #define EN_DSPCK		13
1433179a019STony Lindgren /*#define ARM_INTHCK_SEL	14*/ /* Divide-by-2 for mpu inth_ck */
1443179a019STony Lindgren /* DSP_CKCTL bit shifts */
1453179a019STony Lindgren #define CKCTL_DSPPERDIV_OFFSET	0
1463179a019STony Lindgren 
1473179a019STony Lindgren /* ARM_IDLECT2 bit shifts */
1483179a019STony Lindgren #define EN_WDTCK	0
1493179a019STony Lindgren #define EN_XORPCK	1
1503179a019STony Lindgren #define EN_PERCK	2
1513179a019STony Lindgren #define EN_LCDCK	3
1523179a019STony Lindgren #define EN_LBCK		4 /* Not on 1610/1710 */
1533179a019STony Lindgren /*#define EN_HSABCK	5*/
1543179a019STony Lindgren #define EN_APICK	6
1553179a019STony Lindgren #define EN_TIMCK	7
1563179a019STony Lindgren #define DMACK_REQ	8
1573179a019STony Lindgren #define EN_GPIOCK	9 /* Not on 1610/1710 */
1583179a019STony Lindgren /*#define EN_LBFREECK	10*/
1593179a019STony Lindgren #define EN_CKOUT_ARM	11
1603179a019STony Lindgren 
1613179a019STony Lindgren /* ARM_IDLECT3 bit shifts */
1623179a019STony Lindgren #define EN_OCPI_CK	0
1633179a019STony Lindgren #define EN_TC1_CK	2
1643179a019STony Lindgren #define EN_TC2_CK	4
1653179a019STony Lindgren 
1663179a019STony Lindgren /* DSP_IDLECT2 bit shifts (0,1,2 are same as for ARM_IDLECT2) */
1673179a019STony Lindgren #define EN_DSPTIMCK	5
1683179a019STony Lindgren 
1693179a019STony Lindgren /* Various register defines for clock controls scattered around OMAP chip */
17090afd5cbSTony Lindgren #define SDW_MCLK_INV_BIT	2	/* In ULPD_CLKC_CTRL */
1713179a019STony Lindgren #define USB_MCLK_EN_BIT		4	/* In ULPD_CLKC_CTRL */
1723179a019STony Lindgren #define USB_HOST_HHC_UHOST_EN	9	/* In MOD_CONF_CTRL_0 */
1733179a019STony Lindgren #define SWD_ULPD_PLL_CLK_REQ	1	/* In SWD_CLK_DIV_CTRL_SEL */
1743179a019STony Lindgren #define COM_ULPD_PLL_CLK_REQ	1	/* In COM_CLK_DIV_CTRL_SEL */
1753179a019STony Lindgren #define SWD_CLK_DIV_CTRL_SEL	0xfffe0874
1763179a019STony Lindgren #define COM_CLK_DIV_CTRL_SEL	0xfffe0878
1773179a019STony Lindgren #define SOFT_REQ_REG		0xfffe0834
1783179a019STony Lindgren #define SOFT_REQ_REG2		0xfffe0880
1793179a019STony Lindgren 
18052650505SPaul Walmsley extern __u32 arm_idlect1_mask;
181*c73b9099SJanusz Krzysztofik extern struct omap1_clk *api_ck_p, *ck_dpll1_p, *ck_ref_p;
1823179a019STony Lindgren 
18352650505SPaul Walmsley extern const struct clkops clkops_dspck;
184fb2fc920SPaul Walmsley extern const struct clkops clkops_uart_16xx;
18552650505SPaul Walmsley extern const struct clkops clkops_generic;
18690afd5cbSTony Lindgren 
18724ce2705SJanusz Krzysztofik /* used for passing SoC type to omap1_{select,round_to}_table_rate() */
18824ce2705SJanusz Krzysztofik extern u32 cpu_mask;
18924ce2705SJanusz Krzysztofik 
190*c73b9099SJanusz Krzysztofik extern const struct clk_ops omap1_clk_null_ops;
191*c73b9099SJanusz Krzysztofik extern const struct clk_ops omap1_clk_gate_ops;
192*c73b9099SJanusz Krzysztofik extern const struct clk_ops omap1_clk_rate_ops;
193*c73b9099SJanusz Krzysztofik extern const struct clk_ops omap1_clk_full_ops;
194*c73b9099SJanusz Krzysztofik 
1953179a019STony Lindgren #endif
196