xref: /qemu/include/hw/misc/aspeed_scu.h (revision 9a937f6cc4c18a335e813882d15c83252d611042)
1 /*
2  * ASPEED System Control Unit
3  *
4  * Andrew Jeffery <andrew@aj.id.au>
5  *
6  * Copyright 2016 IBM Corp.
7  *
8  * This code is licensed under the GPL version 2 or later.  See
9  * the COPYING file in the top-level directory.
10  */
11 #ifndef ASPEED_SCU_H
12 #define ASPEED_SCU_H
13 
14 #include "hw/sysbus.h"
15 
16 #define TYPE_ASPEED_SCU "aspeed.scu"
17 #define ASPEED_SCU(obj) OBJECT_CHECK(AspeedSCUState, (obj), TYPE_ASPEED_SCU)
18 #define TYPE_ASPEED_2400_SCU TYPE_ASPEED_SCU "-ast2400"
19 #define TYPE_ASPEED_2500_SCU TYPE_ASPEED_SCU "-ast2500"
20 
21 #define ASPEED_SCU_NR_REGS (0x1A8 >> 2)
22 
23 typedef struct AspeedSCUState {
24     /*< private >*/
25     SysBusDevice parent_obj;
26 
27     /*< public >*/
28     MemoryRegion iomem;
29 
30     uint32_t regs[ASPEED_SCU_NR_REGS];
31     uint32_t silicon_rev;
32     uint32_t hw_strap1;
33     uint32_t hw_strap2;
34     uint32_t hw_prot_key;
35 
36     uint32_t clkin;
37     uint32_t hpll;
38     uint32_t apb_freq;
39 } AspeedSCUState;
40 
41 #define AST2400_A0_SILICON_REV   0x02000303U
42 #define AST2400_A1_SILICON_REV   0x02010303U
43 #define AST2500_A0_SILICON_REV   0x04000303U
44 #define AST2500_A1_SILICON_REV   0x04010303U
45 
46 #define ASPEED_IS_AST2500(si_rev)     ((((si_rev) >> 24) & 0xff) == 0x04)
47 
48 extern bool is_supported_silicon_rev(uint32_t silicon_rev);
49 
50 #define ASPEED_SCU_CLASS(klass) \
51      OBJECT_CLASS_CHECK(AspeedSCUClass, (klass), TYPE_ASPEED_SCU)
52 #define ASPEED_SCU_GET_CLASS(obj) \
53      OBJECT_GET_CLASS(AspeedSCUClass, (obj), TYPE_ASPEED_SCU)
54 
55 typedef struct  AspeedSCUClass {
56     SysBusDeviceClass parent_class;
57 
58     const uint32_t *resets;
59     uint32_t (*calc_hpll)(AspeedSCUState *s);
60     uint32_t apb_divider;
61 }  AspeedSCUClass;
62 
63 #define ASPEED_SCU_PROT_KEY      0x1688A8A8
64 
65 /*
66  * Extracted from Aspeed SDK v00.03.21. Fixes and extra definitions
67  * were added.
68  *
69  * Original header file :
70  *    arch/arm/mach-aspeed/include/mach/regs-scu.h
71  *
72  *    Copyright (C) 2012-2020  ASPEED Technology Inc.
73  *
74  *    This program is free software; you can redistribute it and/or modify
75  *    it under the terms of the GNU General Public License version 2 as
76  *    published by the Free Software Foundation.
77  *
78  *      History      :
79  *       1. 2012/12/29 Ryan Chen Create
80  */
81 
82 /* SCU08   Clock Selection Register
83  *
84  *  31     Enable Video Engine clock dynamic slow down
85  *  30:28  Video Engine clock slow down setting
86  *  27     2D Engine GCLK clock source selection
87  *  26     2D Engine GCLK clock throttling enable
88  *  25:23  APB PCLK divider selection
89  *  22:20  LPC Host LHCLK divider selection
90  *  19     LPC Host LHCLK clock generation/output enable control
91  *  18:16  MAC AHB bus clock divider selection
92  *  15     SD/SDIO clock running enable
93  *  14:12  SD/SDIO divider selection
94  *  11     Reserved
95  *  10:8   Video port output clock delay control bit
96  *  7      ARM CPU/AHB clock slow down enable
97  *  6:4    ARM CPU/AHB clock slow down setting
98  *  3:2    ECLK clock source selection
99  *  1      CPU/AHB clock slow down idle timer
100  *  0      CPU/AHB clock dynamic slow down enable (defined in bit[6:4])
101  */
102 #define SCU_CLK_GET_PCLK_DIV(x)                    (((x) >> 23) & 0x7)
103 
104 /* SCU24   H-PLL Parameter Register (for Aspeed AST2400 SOC)
105  *
106  *  18     H-PLL parameter selection
107  *           0: Select H-PLL by strapping resistors
108  *           1: Select H-PLL by the programmed registers (SCU24[17:0])
109  *  17     Enable H-PLL bypass mode
110  *  16     Turn off H-PLL
111  *  10:5   H-PLL Numerator
112  *  4      H-PLL Output Divider
113  *  3:0    H-PLL Denumerator
114  *
115  *  (Output frequency) = 24MHz * (2-OD) * [(Numerator+2) / (Denumerator+1)]
116  */
117 
118 #define SCU_AST2400_H_PLL_PROGRAMMED               (0x1 << 18)
119 #define SCU_AST2400_H_PLL_BYPASS_EN                (0x1 << 17)
120 #define SCU_AST2400_H_PLL_OFF                      (0x1 << 16)
121 
122 /* SCU24   H-PLL Parameter Register (for Aspeed AST2500 SOC)
123  *
124  *  21     Enable H-PLL reset
125  *  20     Enable H-PLL bypass mode
126  *  19     Turn off H-PLL
127  *  18:13  H-PLL Post Divider
128  *  12:5   H-PLL Numerator (M)
129  *  4:0    H-PLL Denumerator (N)
130  *
131  *  (Output frequency) = CLKIN(24MHz) * [(M+1) / (N+1)] / (P+1)
132  *
133  * The default frequency is 792Mhz when CLKIN = 24MHz
134  */
135 
136 #define SCU_H_PLL_BYPASS_EN                        (0x1 << 20)
137 #define SCU_H_PLL_OFF                              (0x1 << 19)
138 
139 /* SCU70  Hardware Strapping Register definition (for Aspeed AST2400 SOC)
140  *
141  * 31:29  Software defined strapping registers
142  * 28:27  DRAM size setting (for VGA driver use)
143  * 26:24  DRAM configuration setting
144  * 23     Enable 25 MHz reference clock input
145  * 22     Enable GPIOE pass-through mode
146  * 21     Enable GPIOD pass-through mode
147  * 20     Disable LPC to decode SuperIO 0x2E/0x4E address
148  * 19     Disable ACPI function
149  * 23,18  Clock source selection
150  * 17     Enable BMC 2nd boot watchdog timer
151  * 16     SuperIO configuration address selection
152  * 15     VGA Class Code selection
153  * 14     Enable LPC dedicated reset pin function
154  * 13:12  SPI mode selection
155  * 11:10  CPU/AHB clock frequency ratio selection
156  * 9:8    H-PLL default clock frequency selection
157  * 7      Define MAC#2 interface
158  * 6      Define MAC#1 interface
159  * 5      Enable VGA BIOS ROM
160  * 4      Boot flash memory extended option
161  * 3:2    VGA memory size selection
162  * 1:0    BMC CPU boot code selection
163  */
164 #define SCU_AST2400_HW_STRAP_SW_DEFINE(x)          ((x) << 29)
165 #define SCU_AST2400_HW_STRAP_SW_DEFINE_MASK        (0x7 << 29)
166 
167 #define SCU_AST2400_HW_STRAP_DRAM_SIZE(x)          ((x) << 27)
168 #define SCU_AST2400_HW_STRAP_DRAM_SIZE_MASK        (0x3 << 27)
169 #define     DRAM_SIZE_64MB                             0
170 #define     DRAM_SIZE_128MB                            1
171 #define     DRAM_SIZE_256MB                            2
172 #define     DRAM_SIZE_512MB                            3
173 
174 #define SCU_AST2400_HW_STRAP_DRAM_CONFIG(x)        ((x) << 24)
175 #define SCU_AST2400_HW_STRAP_DRAM_CONFIG_MASK      (0x7 << 24)
176 
177 #define SCU_HW_STRAP_GPIOE_PT_EN                   (0x1 << 22)
178 #define SCU_HW_STRAP_GPIOD_PT_EN                   (0x1 << 21)
179 #define SCU_HW_STRAP_LPC_DEC_SUPER_IO              (0x1 << 20)
180 #define SCU_AST2400_HW_STRAP_ACPI_DIS              (0x1 << 19)
181 
182 /* bit 23, 18 [1,0] */
183 #define SCU_AST2400_HW_STRAP_SET_CLK_SOURCE(x)     (((((x) & 0x3) >> 1) << 23) \
184                                                     | (((x) & 0x1) << 18))
185 #define SCU_AST2400_HW_STRAP_GET_CLK_SOURCE(x)     (((((x) >> 23) & 0x1) << 1) \
186                                                     | (((x) >> 18) & 0x1))
187 #define SCU_AST2400_HW_STRAP_CLK_SOURCE_MASK       ((0x1 << 23) | (0x1 << 18))
188 #define SCU_HW_STRAP_CLK_25M_IN                    (0x1 << 23)
189 #define     AST2400_CLK_24M_IN                         0
190 #define     AST2400_CLK_48M_IN                         1
191 #define     AST2400_CLK_25M_IN_24M_USB_CKI             2
192 #define     AST2400_CLK_25M_IN_48M_USB_CKI             3
193 
194 #define SCU_HW_STRAP_CLK_48M_IN                    (0x1 << 18)
195 #define SCU_HW_STRAP_2ND_BOOT_WDT                  (0x1 << 17)
196 #define SCU_HW_STRAP_SUPER_IO_CONFIG               (0x1 << 16)
197 #define SCU_HW_STRAP_VGA_CLASS_CODE                (0x1 << 15)
198 #define SCU_HW_STRAP_LPC_RESET_PIN                 (0x1 << 14)
199 
200 #define SCU_HW_STRAP_SPI_MODE(x)                   ((x) << 12)
201 #define SCU_HW_STRAP_SPI_MODE_MASK                 (0x3 << 12)
202 #define     SCU_HW_STRAP_SPI_DIS                       0
203 #define     SCU_HW_STRAP_SPI_MASTER                    1
204 #define     SCU_HW_STRAP_SPI_M_S_EN                    2
205 #define     SCU_HW_STRAP_SPI_PASS_THROUGH              3
206 
207 #define SCU_AST2400_HW_STRAP_SET_CPU_AHB_RATIO(x)  ((x) << 10)
208 #define SCU_AST2400_HW_STRAP_GET_CPU_AHB_RATIO(x)  (((x) >> 10) & 3)
209 #define SCU_AST2400_HW_STRAP_CPU_AHB_RATIO_MASK    (0x3 << 10)
210 #define     AST2400_CPU_AHB_RATIO_1_1                  0
211 #define     AST2400_CPU_AHB_RATIO_2_1                  1
212 #define     AST2400_CPU_AHB_RATIO_4_1                  2
213 #define     AST2400_CPU_AHB_RATIO_3_1                  3
214 
215 #define SCU_AST2400_HW_STRAP_GET_H_PLL_CLK(x)      (((x) >> 8) & 0x3)
216 #define SCU_AST2400_HW_STRAP_H_PLL_CLK_MASK        (0x3 << 8)
217 #define     AST2400_CPU_384MHZ                         0
218 #define     AST2400_CPU_360MHZ                         1
219 #define     AST2400_CPU_336MHZ                         2
220 #define     AST2400_CPU_408MHZ                         3
221 
222 #define SCU_HW_STRAP_MAC1_RGMII                    (0x1 << 7)
223 #define SCU_HW_STRAP_MAC0_RGMII                    (0x1 << 6)
224 #define SCU_HW_STRAP_VGA_BIOS_ROM                  (0x1 << 5)
225 #define SCU_HW_STRAP_SPI_WIDTH                     (0x1 << 4)
226 
227 #define SCU_HW_STRAP_VGA_SIZE_GET(x)               (((x) >> 2) & 0x3)
228 #define SCU_HW_STRAP_VGA_MASK                      (0x3 << 2)
229 #define SCU_HW_STRAP_VGA_SIZE_SET(x)               ((x) << 2)
230 #define     VGA_8M_DRAM                                0
231 #define     VGA_16M_DRAM                               1
232 #define     VGA_32M_DRAM                               2
233 #define     VGA_64M_DRAM                               3
234 
235 #define SCU_AST2400_HW_STRAP_BOOT_MODE(x)          (x)
236 #define     AST2400_NOR_BOOT                           0
237 #define     AST2400_NAND_BOOT                          1
238 #define     AST2400_SPI_BOOT                           2
239 #define     AST2400_DIS_BOOT                           3
240 
241 /*
242  * SCU70  Hardware strapping register definition (for Aspeed AST2500
243  *        SoC and higher)
244  *
245  * 31     Enable SPI Flash Strap Auto Fetch Mode
246  * 30     Enable GPIO Strap Mode
247  * 29     Select UART Debug Port
248  * 28     Reserved (1)
249  * 27     Enable fast reset mode for ARM ICE debugger
250  * 26     Enable eSPI flash mode
251  * 25     Enable eSPI mode
252  * 24     Select DDR4 SDRAM
253  * 23     Select 25 MHz reference clock input mode
254  * 22     Enable GPIOE pass-through mode
255  * 21     Enable GPIOD pass-through mode
256  * 20     Disable LPC to decode SuperIO 0x2E/0x4E address
257  * 19     Enable ACPI function
258  * 18     Select USBCKI input frequency
259  * 17     Enable BMC 2nd boot watchdog timer
260  * 16     SuperIO configuration address selection
261  * 15     VGA Class Code selection
262  * 14     Select dedicated LPC reset input
263  * 13:12  SPI mode selection
264  * 11:9   AXI/AHB clock frequency ratio selection
265  * 8      Reserved (0)
266  * 7      Define MAC#2 interface
267  * 6      Define MAC#1 interface
268  * 5      Enable dedicated VGA BIOS ROM
269  * 4      Reserved (0)
270  * 3:2    VGA memory size selection
271  * 1      Reserved (1)
272  * 0      Disable CPU boot
273  */
274 #define SCU_AST2500_HW_STRAP_SPI_AUTOFETCH_ENABLE  (0x1 << 31)
275 #define SCU_AST2500_HW_STRAP_GPIO_STRAP_ENABLE     (0x1 << 30)
276 #define SCU_AST2500_HW_STRAP_UART_DEBUG            (0x1 << 29)
277 #define     UART_DEBUG_UART1                           0
278 #define     UART_DEBUG_UART5                           1
279 #define SCU_AST2500_HW_STRAP_RESERVED28            (0x1 << 28)
280 
281 #define SCU_AST2500_HW_STRAP_FAST_RESET_DBG        (0x1 << 27)
282 #define SCU_AST2500_HW_STRAP_ESPI_FLASH_ENABLE     (0x1 << 26)
283 #define SCU_AST2500_HW_STRAP_ESPI_ENABLE           (0x1 << 25)
284 #define SCU_AST2500_HW_STRAP_DDR4_ENABLE           (0x1 << 24)
285 
286 #define SCU_AST2500_HW_STRAP_ACPI_ENABLE           (0x1 << 19)
287 #define SCU_AST2500_HW_STRAP_USBCKI_FREQ           (0x1 << 18)
288 #define     USBCKI_FREQ_24MHZ                          0
289 #define     USBCKI_FREQ_28MHZ                          1
290 
291 #define SCU_AST2500_HW_STRAP_SET_AXI_AHB_RATIO(x)  ((x) << 9)
292 #define SCU_AST2500_HW_STRAP_GET_AXI_AHB_RATIO(x)  (((x) >> 9) & 7)
293 #define SCU_AST2500_HW_STRAP_CPU_AXI_RATIO_MASK    (0x7 << 9)
294 #define     AXI_AHB_RATIO_UNDEFINED                    0
295 #define     AXI_AHB_RATIO_2_1                          1
296 #define     AXI_AHB_RATIO_3_1                          2
297 #define     AXI_AHB_RATIO_4_1                          3
298 #define     AXI_AHB_RATIO_5_1                          4
299 #define     AXI_AHB_RATIO_6_1                          5
300 #define     AXI_AHB_RATIO_7_1                          6
301 #define     AXI_AHB_RATIO_8_1                          7
302 
303 #define SCU_AST2500_HW_STRAP_RESERVED1             (0x1 << 1)
304 #define SCU_AST2500_HW_STRAP_DIS_BOOT              (0x1 << 0)
305 
306 #define AST2500_HW_STRAP1_DEFAULTS (                                    \
307         SCU_AST2500_HW_STRAP_RESERVED28 |                               \
308         SCU_HW_STRAP_2ND_BOOT_WDT |                                     \
309         SCU_HW_STRAP_VGA_CLASS_CODE |                                   \
310         SCU_HW_STRAP_LPC_RESET_PIN |                                    \
311         SCU_AST2500_HW_STRAP_SET_AXI_AHB_RATIO(AXI_AHB_RATIO_2_1) |     \
312         SCU_HW_STRAP_VGA_SIZE_SET(VGA_16M_DRAM) |                       \
313         SCU_AST2500_HW_STRAP_RESERVED1)
314 
315 #endif /* ASPEED_SCU_H */
316