hm60x/hm801: Buttons rework.
[maemo-rb.git] / firmware / target / arm / imx233 / clkctrl-imx233.h
blobae2e0465a0230e35b8922a8fba6efa33e4a08cc3
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright © 2011 by Amaury Pouly
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef CLKCTRL_IMX233_H
22 #define CLKCTRL_IMX233_H
24 #include "config.h"
25 #include "system.h"
26 #include "cpu.h"
28 #define HW_CLKCTRL_BASE 0x80040000
30 #define HW_CLKCTRL_PLLCTRL0 (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x0))
31 #define HW_CLKCTRL_PLLCTRL0__POWER (1 << 16)
32 #define HW_CLKCTRL_PLLCTRL0__EN_USB_CLKS (1 << 18)
33 #define HW_CLKCTRL_PLLCTRL0__DIV_SEL_BP 20
34 #define HW_CLKCTRL_PLLCTRL0__DIV_SEL_BM (3 << 20)
36 #define HW_CLKCTRL_PLLCTRL1 (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x10))
38 #define HW_CLKCTRL_CPU (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x20))
39 #define HW_CLKCTRL_CPU__DIV_CPU_BP 0
40 #define HW_CLKCTRL_CPU__DIV_CPU_BM 0x3f
41 #define HW_CLKCTRL_CPU__INTERRUPT_WAIT (1 << 12)
42 #define HW_CLKCTRL_CPU__DIV_XTAL_BP 16
43 #define HW_CLKCTRL_CPU__DIV_XTAL_BM (0x3ff << 16)
44 #define HW_CLKCTRL_CPU__DIV_XTAL_FRAC_EN (1 << 26)
45 #define HW_CLKCTRL_CPU__BUSY_REF_CPU (1 << 28)
47 #define HW_CLKCTRL_HBUS (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x30))
48 #define HW_CLKCTRL_HBUS__DIV_BP 0
49 #define HW_CLKCTRL_HBUS__DIV_BM 0x1f
50 #define HW_CLKCTRL_HBUS__DIV_FRAC_EN (1 << 5)
51 #define HW_CLKCTRL_HBUS__SLOW_DIV_BP 16
52 #define HW_CLKCTRL_HBUS__SLOW_DIV_BM (0x7 << 16)
53 #define HW_CLKCTRL_HBUS__AUTO_SLOW_MODE (1 << 20)
55 /* warning: this register doesn't have a CLR/SET variant ! */
56 #define HW_CLKCTRL_XBUS (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x40))
57 #define HW_CLKCTRL_XBUS__DIV_BP 0
58 #define HW_CLKCTRL_XBUS__DIV_BM 0x3ff
59 #define HW_CLKCTRL_XBUS__BUSY (1 << 31)
61 #define HW_CLKCTRL_XTAL (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x50))
62 #define HW_CLKCTRL_XTAL__TIMROT_CLK32K_GATE (1 << 26)
63 #define HW_CLKCTRL_XTAL__DRI_CLK24M_GATE (1 << 28)
64 #define HW_CLKCTRL_XTAL__FILT_CLK24M_GATE (1 << 30)
66 /* warning: this register doesn't have a CLR/SET variant ! */
67 #define HW_CLKCTRL_PIX (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x60))
68 #define HW_CLKCTRL_PIX__DIV_BP 0
69 #define HW_CLKCTRL_PIX__DIV_BM 0xfff
71 /* warning: this register doesn't have a CLR/SET variant ! */
72 #define HW_CLKCTRL_SSP (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x70))
73 #define HW_CLKCTRL_SSP__DIV_BP 0
74 #define HW_CLKCTRL_SSP__DIV_BM 0x1ff
76 /* warning: this register doesn't have a CLR/SET variant ! */
77 #define HW_CLKCTRL_EMI (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0xa0))
78 #define HW_CLKCTRL_EMI__DIV_EMI_BP 0
79 #define HW_CLKCTRL_EMI__DIV_EMI_BM 0x3f
80 #define HW_CLKCTRL_EMI__DIV_XTAL_BP 8
81 #define HW_CLKCTRL_EMI__DIV_XTAL_BM (0xf << 8)
82 #define HW_CLKCTRL_EMI__BUSY_REF_EMI (1 << 28)
83 #define HW_CLKCTRL_EMI__SYNC_MODE_EN (1 << 30)
84 #define HW_CLKCTRL_EMI__CLKGATE (1 << 31)
86 #define HW_CLKCTRL_CLKSEQ (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x110))
87 #define HW_CLKCTRL_CLKSEQ__BYPASS_PIX (1 << 1)
88 #define HW_CLKCTRL_CLKSEQ__BYPASS_SSP (1 << 5)
89 #define HW_CLKCTRL_CLKSEQ__BYPASS_EMI (1 << 6)
90 #define HW_CLKCTRL_CLKSEQ__BYPASS_CPU (1 << 7)
92 #define HW_CLKCTRL_FRAC (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0xf0))
93 #define HW_CLKCTRL_FRAC_CPU (*(volatile uint8_t *)(HW_CLKCTRL_BASE + 0xf0))
94 #define HW_CLKCTRL_FRAC_EMI (*(volatile uint8_t *)(HW_CLKCTRL_BASE + 0xf1))
95 #define HW_CLKCTRL_FRAC_PIX (*(volatile uint8_t *)(HW_CLKCTRL_BASE + 0xf2))
96 #define HW_CLKCTRL_FRAC_IO (*(volatile uint8_t *)(HW_CLKCTRL_BASE + 0xf3))
97 #define HW_CLKCTRL_FRAC_XX__XXDIV_BM 0x3f
98 #define HW_CLKCTRL_FRAC_XX__XX_STABLE (1 << 6)
99 #define HW_CLKCTRL_FRAC_XX__CLKGATEXX (1 << 7)
101 /* warning: this register doesn't have a CLR/SET variant ! */
102 #define HW_CLKCTRL_RESET (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x120))
103 #define HW_CLKCTRL_RESET_CHIP 0x2
104 #define HW_CLKCTRL_RESET_DIG 0x1
106 static inline void core_sleep(void)
108 __REG_SET(HW_CLKCTRL_CPU) = HW_CLKCTRL_CPU__INTERRUPT_WAIT;
109 asm volatile (
110 "mcr p15, 0, %0, c7, c0, 4 \n" /* Wait for interrupt */
111 "nop\n" /* Datasheet unclear: "The lr sent to handler points here after RTI"*/
112 : : "r"(0)
114 enable_irq();
117 enum imx233_clock_t
119 CLK_PIX, /* freq, div, frac, bypass, enable */
120 CLK_SSP, /* freq, div, bypass, enable */
121 CLK_IO, /* freq, frac */
122 CLK_CPU, /* freq, div, frac, bypass */
123 CLK_HBUS, /* freq, div, frac */
124 CLK_PLL, /* freq */
125 CLK_XTAL, /* freq */
126 CLK_EMI, /* freq */
127 CLK_XBUS, /* freq, div */
130 enum imx233_xtal_clk_t
132 XTAL_FILT = 1 << 30,
133 XTAL_DRI = 1 << 28,
134 XTAL_TIMROT = 1 << 26,
137 /* Auto-Slow monitoring */
138 enum imx233_as_monitor_t
140 AS_CPU_INSTR = 1 << 21, /* Monitor CPU instruction access to AHB */
141 AS_CPU_DATA = 1 << 22, /* Monitor CPU data access to AHB */
142 AS_TRAFFIC = 1 << 23, /* Monitor AHB master activity */
143 AS_TRAFFIC_JAM = 1 << 24, /* Monitor AHB masters (>=3) activity */
144 AS_APBXDMA = 1 << 25, /* Monitor APBX DMA activity */
145 AS_APBHDMA = 1 << 26, /* Monitor APBH DMA activity */
146 AS_PXP = 1 << 27, /* Monitor PXP activity */
147 AS_DCP = 1 << 28, /* Monitor DCP activity */
150 enum imx233_as_div_t
152 AS_DIV_1 = 0,
153 AS_DIV_2 = 1,
154 AS_DIV_4 = 2,
155 AS_DIV_8 = 3,
156 AS_DIV_16 = 4,
157 AS_DIV_32 = 5
160 /* can use a mask of clocks */
161 void imx233_enable_xtal_clock(enum imx233_xtal_clk_t xtal_clk, bool enable);
162 bool imx233_is_xtal_clock_enable(enum imx233_xtal_clk_t clk);
163 /* only use it for non-fractional clocks (ie not for IO) */
164 void imx233_enable_clock(enum imx233_clock_t clk, bool enable);
165 bool imx233_is_clock_enable(enum imx233_clock_t cl);
166 void imx233_set_clock_divisor(enum imx233_clock_t clk, int div);
167 int imx233_get_clock_divisor(enum imx233_clock_t clk);
168 /* call with fracdiv=0 to disable it */
169 void imx233_set_fractional_divisor(enum imx233_clock_t clk, int fracdiv);
170 /* 0 means fractional dividor disable */
171 int imx233_get_fractional_divisor(enum imx233_clock_t clk);
172 void imx233_set_bypass_pll(enum imx233_clock_t clk, bool bypass);
173 bool imx233_get_bypass_pll(enum imx233_clock_t clk);
174 void imx233_enable_usb_pll(bool enable);
175 bool imx233_is_usb_pll_enable(void);
176 unsigned imx233_get_clock_freq(enum imx233_clock_t clk);
178 void imx233_set_auto_slow_divisor(enum imx233_as_div_t div);
179 enum imx233_as_div_t imx233_get_auto_slow_divisor(void);
180 void imx233_enable_auto_slow(bool enable);
181 bool imx233_is_auto_slow_enable(void);
182 void imx233_enable_auto_slow_monitor(enum imx233_as_monitor_t monitor, bool enable);
183 bool imx233_is_auto_slow_monitor_enable(enum imx233_as_monitor_t monitor);
185 #endif /* CLKCTRL_IMX233_H */