blob: 8d696e533f8fac2296e12b2b015e684abca3edf5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Hans de Goede35e1a152015-01-14 17:30:22 +01002/*
3 * sun9i clock register definitions
4 *
5 * (C) Copyright 2015 Hans de Goede <hdegoede@redhat.com>
Hans de Goede35e1a152015-01-14 17:30:22 +01006 */
7
8#ifndef _SUNXI_CLOCK_SUN9I_H
9#define _SUNXI_CLOCK_SUN9I_H
10
Simon Glass4dcacfc2020-05-10 11:40:13 -060011#ifndef __ASSEMBLY__
12#include <linux/bitops.h>
13#endif
14
Andre Przywara7bd03262025-01-24 23:42:46 +000015#define CCU_MMC0_CLK_CFG 0x410
16#define CCU_MMC1_CLK_CFG 0x414
17#define CCU_MMC2_CLK_CFG 0x418
18#define CCU_MMC3_CLK_CFG 0x41c
19#define CCU_AHB_GATE0 0x580
20#define CCU_AHB_RESET0_CFG 0x5a0
21
Hans de Goede35e1a152015-01-14 17:30:22 +010022struct sunxi_ccm_reg {
23 u32 pll1_c0_cfg; /* 0x00 c0cpu# pll configuration */
24 u32 pll2_c1_cfg; /* 0x04 c1cpu# pll configuration */
25 u32 pll3_audio_cfg; /* 0x08 audio pll configuration */
26 u32 pll4_periph0_cfg; /* 0x0c peripheral0 pll configuration */
27 u32 pll5_ve_cfg; /* 0x10 videoengine pll configuration */
28 u32 pll6_ddr_cfg; /* 0x14 ddr pll configuration */
29 u32 pll7_video0_cfg; /* 0x18 video0 pll configuration */
30 u32 pll8_video1_cfg; /* 0x1c video1 pll configuration */
31 u32 pll9_gpu_cfg; /* 0x20 gpu pll configuration */
32 u32 pll10_de_cfg; /* 0x24 displayengine pll configuration */
33 u32 pll11_isp_cfg; /* 0x28 isp pll6 ontrol */
34 u32 pll12_periph1_cfg; /* 0x2c peripheral1 pll configuration */
35 u8 reserved1[0x20]; /* 0x30 */
36 u32 cpu_clk_source; /* 0x50 cpu clk source configuration */
37 u32 c0_cfg; /* 0x54 cpu cluster 0 clock configuration */
38 u32 c1_cfg; /* 0x58 cpu cluster 1 clock configuration */
39 u32 gtbus_cfg; /* 0x5c gtbus clock configuration */
40 u32 ahb0_cfg; /* 0x60 ahb0 clock configuration */
41 u32 ahb1_cfg; /* 0x64 ahb1 clock configuration */
42 u32 ahb2_cfg; /* 0x68 ahb2 clock configuration */
43 u8 reserved2[0x04]; /* 0x6c */
44 u32 apb0_cfg; /* 0x70 apb0 clock configuration */
45 u32 apb1_cfg; /* 0x74 apb1 clock configuration */
46 u32 cci400_cfg; /* 0x78 cci400 clock configuration */
47 u8 reserved3[0x04]; /* 0x7c */
48 u32 ats_cfg; /* 0x80 ats clock configuration */
49 u32 trace_cfg; /* 0x84 trace clock configuration */
Philipp Tomsichd36af1c2016-10-28 18:21:28 +080050 u8 reserved4[0x14]; /* 0x88 */
51 u32 pll_stable_status; /* 0x9c */
52 u8 reserved5[0xe0]; /* 0xa0 */
Hans de Goede35e1a152015-01-14 17:30:22 +010053 u32 clk_output_a; /* 0x180 clk_output_a */
54 u32 clk_output_b; /* 0x184 clk_output_a */
Philipp Tomsichd36af1c2016-10-28 18:21:28 +080055 u8 reserved6[0x278]; /* 0x188 */
Hans de Goede35e1a152015-01-14 17:30:22 +010056
Roy Spliet2b735ad2015-05-26 17:00:41 +020057 u32 nand0_clk_cfg; /* 0x400 nand0 clock configuration0 */
Hans de Goede35e1a152015-01-14 17:30:22 +010058 u32 nand0_clk_cfg1; /* 0x404 nand1 clock configuration */
Philipp Tomsichd36af1c2016-10-28 18:21:28 +080059 u8 reserved7[0x08]; /* 0x408 */
Hans de Goede35e1a152015-01-14 17:30:22 +010060 u32 sd0_clk_cfg; /* 0x410 sd0 clock configuration */
61 u32 sd1_clk_cfg; /* 0x414 sd1 clock configuration */
62 u32 sd2_clk_cfg; /* 0x418 sd2 clock configuration */
63 u32 sd3_clk_cfg; /* 0x41c sd3 clock configuration */
Philipp Tomsichd36af1c2016-10-28 18:21:28 +080064 u8 reserved8[0x08]; /* 0x420 */
Hans de Goede35e1a152015-01-14 17:30:22 +010065 u32 ts_clk_cfg; /* 0x428 transport stream clock cfg */
66 u32 ss_clk_cfg; /* 0x42c security system clock cfg */
67 u32 spi0_clk_cfg; /* 0x430 spi0 clock configuration */
68 u32 spi1_clk_cfg; /* 0x434 spi1 clock configuration */
69 u32 spi2_clk_cfg; /* 0x438 spi2 clock configuration */
70 u32 spi3_clk_cfg; /* 0x43c spi3 clock configuration */
Philipp Tomsichd36af1c2016-10-28 18:21:28 +080071 u8 reserved9[0x44]; /* 0x440 */
72 u32 dram_clk_cfg; /* 0x484 DRAM (controller) clock config */
73 u8 reserved10[0x8]; /* 0x488 */
Hans de Goede35e1a152015-01-14 17:30:22 +010074 u32 de_clk_cfg; /* 0x490 display engine clock configuration */
Philipp Tomsichd36af1c2016-10-28 18:21:28 +080075 u8 reserved11[0x04]; /* 0x494 */
Hans de Goede35e1a152015-01-14 17:30:22 +010076 u32 mp_clk_cfg; /* 0x498 mp clock configuration */
77 u32 lcd0_clk_cfg; /* 0x49c LCD0 module clock */
78 u32 lcd1_clk_cfg; /* 0x4a0 LCD1 module clock */
Philipp Tomsichd36af1c2016-10-28 18:21:28 +080079 u8 reserved12[0x1c]; /* 0x4a4 */
Hans de Goede35e1a152015-01-14 17:30:22 +010080 u32 csi_isp_clk_cfg; /* 0x4c0 CSI ISP module clock */
81 u32 csi0_clk_cfg; /* 0x4c4 CSI0 module clock */
82 u32 csi1_clk_cfg; /* 0x4c8 CSI1 module clock */
83 u32 fd_clk_cfg; /* 0x4cc FD module clock */
84 u32 ve_clk_cfg; /* 0x4d0 VE module clock */
85 u32 avs_clk_cfg; /* 0x4d4 AVS module clock */
Philipp Tomsichd36af1c2016-10-28 18:21:28 +080086 u8 reserved13[0x18]; /* 0x4d8 */
Hans de Goede35e1a152015-01-14 17:30:22 +010087 u32 gpu_core_clk_cfg; /* 0x4f0 GPU core clock config */
88 u32 gpu_mem_clk_cfg; /* 0x4f4 GPU memory clock config */
89 u32 gpu_axi_clk_cfg; /* 0x4f8 GPU AXI clock config */
Philipp Tomsichd36af1c2016-10-28 18:21:28 +080090 u8 reserved14[0x10]; /* 0x4fc */
Hans de Goede35e1a152015-01-14 17:30:22 +010091 u32 gp_adc_clk_cfg; /* 0x50c General Purpose ADC clk config */
Philipp Tomsichd36af1c2016-10-28 18:21:28 +080092 u8 reserved15[0x70]; /* 0x510 */
Hans de Goede35e1a152015-01-14 17:30:22 +010093
94 u32 ahb_gate0; /* 0x580 AHB0 Gating Register */
95 u32 ahb_gate1; /* 0x584 AHB1 Gating Register */
96 u32 ahb_gate2; /* 0x588 AHB2 Gating Register */
Philipp Tomsichd36af1c2016-10-28 18:21:28 +080097 u8 reserved16[0x04]; /* 0x58c */
Hans de Goede35e1a152015-01-14 17:30:22 +010098 u32 apb0_gate; /* 0x590 APB0 Clock Gating Register */
99 u32 apb1_gate; /* 0x594 APB1 Clock Gating Register */
Philipp Tomsichd36af1c2016-10-28 18:21:28 +0800100 u8 reserved17[0x08]; /* 0x598 */
Hans de Goede35e1a152015-01-14 17:30:22 +0100101 u32 ahb_reset0_cfg; /* 0x5a0 AHB0 Software Reset Register */
102 u32 ahb_reset1_cfg; /* 0x5a4 AHB1 Software Reset Register */
103 u32 ahb_reset2_cfg; /* 0x5a8 AHB2 Software Reset Register */
Philipp Tomsichd36af1c2016-10-28 18:21:28 +0800104 u8 reserved18[0x04]; /* 0x5ac */
Hans de Goede35e1a152015-01-14 17:30:22 +0100105 u32 apb0_reset_cfg; /* 0x5b0 Bus Software Reset Register 3 */
106 u32 apb1_reset_cfg; /* 0x5b4 Bus Software Reset Register 4 */
107};
108
Hans de Goede35e1a152015-01-14 17:30:22 +0100109#define CCM_PLL4_CTRL_N_SHIFT 8
110#define CCM_PLL4_CTRL_N_MASK (0xff << CCM_PLL4_CTRL_N_SHIFT)
111#define CCM_PLL4_CTRL_P_SHIFT 16
112#define CCM_PLL4_CTRL_P_MASK (0x1 << CCM_PLL4_CTRL_P_SHIFT)
113#define CCM_PLL4_CTRL_M_SHIFT 18
114#define CCM_PLL4_CTRL_M_MASK (0x1 << CCM_PLL4_CTRL_M_SHIFT)
115
Philipp Tomsichd7c0efb2016-10-28 18:21:31 +0800116/* pllx_cfg bits */
117#define CCM_PLL1_CTRL_N(n) (((n) & 0xff) << 8)
118#define CCM_PLL1_CTRL_P(n) (((n) & 0x1) << 16)
119#define CCM_PLL1_CTRL_EN (1 << 31)
120#define CCM_PLL1_CLOCK_TIME_2 (2 << 24)
121
122#define CCM_PLL2_CTRL_N(n) (((n) & 0xff) << 8)
123#define CCM_PLL2_CTRL_P(n) (((n) & 0x1) << 16)
124#define CCM_PLL2_CTRL_EN (1 << 31)
125#define CCM_PLL2_CLOCK_TIME_2 (2 << 24)
126
127#define CCM_PLL4_CTRL_N(n) (((n) & 0xff) << 8)
128#define CCM_PLL4_CTRL_EN (1 << 31)
129
130#define CCM_PLL6_CTRL_N(n) (((n) & 0xff) << 8)
131#define CCM_PLL6_CTRL_P(p) (((p) & 0x1) << 16)
132#define CCM_PLL6_CTRL_EN (1 << 31)
133#define CCM_PLL6_CFG_UPDATE (1 << 30)
134
135#define CCM_PLL12_CTRL_N(n) (((n) & 0xff) << 8)
136#define CCM_PLL12_CTRL_EN (1 << 31)
137
138#define PLL_C0CPUX_STATUS (1 << 0)
139#define PLL_C1CPUX_STATUS (1 << 1)
140#define PLL_DDR_STATUS (1 << 5)
141#define PLL_PERIPH1_STATUS (1 << 11)
142
143/* cpu_clk_source bits */
144#define C0_CPUX_CLK_SRC_SHIFT 0
145#define C1_CPUX_CLK_SRC_SHIFT 8
146#define C0_CPUX_CLK_SRC_MASK (1 << C0_CPUX_CLK_SRC_SHIFT)
147#define C1_CPUX_CLK_SRC_MASK (1 << C1_CPUX_CLK_SRC_SHIFT)
148#define C0_CPUX_CLK_SRC_OSC24M (0 << C0_CPUX_CLK_SRC_SHIFT)
149#define C0_CPUX_CLK_SRC_PLL1 (1 << C0_CPUX_CLK_SRC_SHIFT)
150#define C1_CPUX_CLK_SRC_OSC24M (0 << C1_CPUX_CLK_SRC_SHIFT)
151#define C1_CPUX_CLK_SRC_PLL2 (1 << C1_CPUX_CLK_SRC_SHIFT)
152
153/* c0_cfg */
154#define C0_CFG_AXI0_CLK_DIV_RATIO(n) (((n - 1) & 0x3) << 0)
155#define C0_CFG_APB0_CLK_DIV_RATIO(n) (((n - 1) & 0x3) << 8)
156
157/* ahbx_cfg */
158#define AHBx_SRC_CLK_SELECT_SHIFT 24
159#define AHBx_SRC_MASK (0x3 << AHBx_SRC_CLK_SELECT_SHIFT)
160#define AHB0_SRC_GTBUS_CLK (0x0 << AHBx_SRC_CLK_SELECT_SHIFT)
161#define AHB1_SRC_GTBUS_CLK (0x0 << AHBx_SRC_CLK_SELECT_SHIFT)
162#define AHB2_SRC_OSC24M (0x0 << AHBx_SRC_CLK_SELECT_SHIFT)
163#define AHBx_SRC_PLL_PERIPH0 (0x1 << AHBx_SRC_CLK_SELECT_SHIFT)
164#define AHBx_SRC_PLL_PERIPH1 (0x2 << AHBx_SRC_CLK_SELECT_SHIFT)
165#define AHBx_CLK_DIV_RATIO(n) (((ffs(n) - 1) & 0x3) << 0)
166
167/* apb0_cfg */
168#define APB0_SRC_CLK_SELECT_SHIFT 24
169#define APB0_SRC_MASK (0x1 << APB0_SRC_CLK_SELECT_SHIFT)
170#define APB0_SRC_OSC24M (0x0 << APB0_SRC_CLK_SELECT_SHIFT)
171#define APB0_SRC_PLL_PERIPH0 (0x1 << APB0_SRC_CLK_SELECT_SHIFT)
172#define APB0_CLK_DIV_RATIO(n) (((ffs(n) - 1) & 0x3) << 0)
173
174/* gtbus_clk_cfg */
175#define GTBUS_SRC_CLK_SELECT_SHIFT 24
176#define GTBUS_SRC_MASK (0x3 << GTBUS_SRC_CLK_SELECT_SHIFT)
177#define GTBUS_SRC_OSC24M (0x0 << GTBUS_SRC_CLK_SELECT_SHIFT)
178#define GTBUS_SRC_PLL_PERIPH0 (0x1 << GTBUS_SRC_CLK_SELECT_SHIFT)
179#define GTBUS_SRC_PLL_PERIPH1 (0x2 << GTBUS_SRC_CLK_SELECT_SHIFT)
180#define GTBUS_CLK_DIV_RATIO(n) (((n - 1) & 0x3) << 0)
181
182/* cci400_clk_cfg */
183#define CCI400_SRC_CLK_SELECT_SHIFT 24
184#define CCI400_SRC_MASK (0x3 << CCI400_SRC_CLK_SELECT_SHIFT)
185#define CCI400_SRC_OSC24M (0x0 << CCI400_SRC_CLK_SELECT_SHIFT)
186#define CCI400_SRC_PLL_PERIPH0 (0x1 << CCI400_SRC_CLK_SELECT_SHIFT)
187#define CCI400_SRC_PLL_PERIPH1 (0x2 << CCI400_SRC_CLK_SELECT_SHIFT)
188#define CCI400_CLK_DIV_RATIO(n) (((n - 1) & 0x3) << 0)
189
Hans de Goede35e1a152015-01-14 17:30:22 +0100190/* sd#_clk_cfg fields */
191#define CCM_MMC_CTRL_M(x) ((x) - 1)
192#define CCM_MMC_CTRL_OCLK_DLY(x) ((x) << 8)
193#define CCM_MMC_CTRL_N(x) ((x) << 16)
194#define CCM_MMC_CTRL_SCLK_DLY(x) ((x) << 20)
195#define CCM_MMC_CTRL_OSCM24 (0 << 24)
196#define CCM_MMC_CTRL_PLL_PERIPH0 (1 << 24)
197#define CCM_MMC_CTRL_ENABLE (1 << 31)
198
199/* ahb_gate0 fields */
Philipp Tomsichd36af1c2016-10-28 18:21:28 +0800200#define AHB_GATE_OFFSET_MCTL 14
201
Hans de Goede35e1a152015-01-14 17:30:22 +0100202/* On sun9i all sdc-s share their ahb gate, so ignore (x) */
Roy Spliet2b735ad2015-05-26 17:00:41 +0200203#define AHB_GATE_OFFSET_NAND0 13
Hans de Goede35e1a152015-01-14 17:30:22 +0100204#define AHB_GATE_OFFSET_MMC(x) 8
205
Roy Spliet2b735ad2015-05-26 17:00:41 +0200206/* ahb gate1 field */
207#define AHB_GATE_OFFSET_DMA 24
208
Hans de Goede35e1a152015-01-14 17:30:22 +0100209/* apb1_gate fields */
210#define APB1_GATE_UART_SHIFT 16
211#define APB1_GATE_UART_MASK (0xff << APB1_GATE_UART_SHIFT)
212#define APB1_GATE_TWI_SHIFT 0
213#define APB1_GATE_TWI_MASK (0xf << APB1_GATE_TWI_SHIFT)
214
215/* ahb_reset0_cfg fields */
Philipp Tomsichd36af1c2016-10-28 18:21:28 +0800216#define AHB_RESET_OFFSET_MCTL 14
217
Hans de Goede35e1a152015-01-14 17:30:22 +0100218/* On sun9i all sdc-s share their ahb reset, so ignore (x) */
219#define AHB_RESET_OFFSET_MMC(x) 8
220
221/* apb1_reset_cfg fields */
222#define APB1_RESET_UART_SHIFT 16
223#define APB1_RESET_UART_MASK (0xff << APB1_RESET_UART_SHIFT)
224#define APB1_RESET_TWI_SHIFT 0
225#define APB1_RESET_TWI_MASK (0xf << APB1_RESET_TWI_SHIFT)
226
Hans de Goede35e1a152015-01-14 17:30:22 +0100227#ifndef __ASSEMBLY__
Philipp Tomsichd7c0efb2016-10-28 18:21:31 +0800228void clock_set_pll1(unsigned int clk);
Philipp Tomsichd7c0efb2016-10-28 18:21:31 +0800229void clock_set_pll6(unsigned int clk);
Hans de Goede35e1a152015-01-14 17:30:22 +0100230unsigned int clock_get_pll4_periph0(void);
231#endif
232
233#endif /* _SUNXI_CLOCK_SUN9I_H */