2 * Status and system control registers for Xilinx Zynq Platform
4 * Copyright (c) 2011 Michal Simek <monstr@monstr.eu>
5 * Copyright (c) 2012 PetaLogix Pty Ltd.
6 * Based on hw/arm_sysctl.c, written by Paul Brook
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, see <http://www.gnu.org/licenses/>.
18 #include "qemu/timer.h"
19 #include "hw/sysbus.h"
20 #include "sysemu/sysemu.h"
22 #ifndef ZYNQ_SLCR_ERR_DEBUG
23 #define ZYNQ_SLCR_ERR_DEBUG 0
26 #define DB_PRINT(...) do { \
27 if (ZYNQ_SLCR_ERR_DEBUG) { \
28 fprintf(stderr, ": %s: ", __func__); \
29 fprintf(stderr, ## __VA_ARGS__); \
33 #define XILINX_LOCK_KEY 0x767b
34 #define XILINX_UNLOCK_KEY 0xdf0d
36 #define R_PSS_RST_CTRL_SOFT_RST 0x1
44 ARM_PLL_CTRL
= 0x100 / 4,
52 ARM_CLK_CTRL
= 0x120 / 4,
73 #define FPGA_CTRL_REGS(n, start) \
74 FPGA ## n ## _CLK_CTRL = (start) / 4, \
75 FPGA ## n ## _THR_CTRL, \
76 FPGA ## n ## _THR_CNT, \
77 FPGA ## n ## _THR_STA,
78 FPGA_CTRL_REGS(0, 0x170)
79 FPGA_CTRL_REGS(1, 0x180)
80 FPGA_CTRL_REGS(2, 0x190)
81 FPGA_CTRL_REGS(3, 0x1a0)
83 BANDGAP_TRIP
= 0x1b8 / 4,
84 PLL_PREDIVISOR
= 0x1c0 / 4,
87 PSS_RST_CTRL
= 0x200 / 4,
102 FPGA_RST_CTRL
= 0x240 / 4,
105 RS_AWDT_CTRL
= 0x24c / 4,
108 REBOOT_STATUS
= 0x258 / 4,
111 APU_CTRL
= 0x300 / 4,
114 TZ_DMA_NS
= 0x440 / 4,
118 PSS_IDCODE
= 0x530 / 4,
120 DDR_URGENT
= 0x600 / 4,
121 DDR_CAL_START
= 0x60c / 4,
122 DDR_REF_START
= 0x614 / 4,
128 #define MIO_LENGTH 54
130 MIO_LOOPBACK
= 0x804 / 4,
134 SD0_WP_CD_SEL
= 0x830 / 4,
137 LVL_SHFTR_EN
= 0x900 / 4,
144 DMAC_RAM
= 0xa50 / 4,
154 DEVCI_RAM
= 0xaa0 / 4,
158 GPIOB_CTRL
= 0xb00 / 4,
162 GPIOB_CFG_HSTL
= 0xb14 / 4,
163 GPIOB_DRVR_BIAS_CTRL
,
166 #define DDRIOB_LENGTH 14
169 #define ZYNQ_SLCR_MMIO_SIZE 0x1000
170 #define ZYNQ_SLCR_NUM_REGS (ZYNQ_SLCR_MMIO_SIZE / 4)
172 #define TYPE_ZYNQ_SLCR "xilinx,zynq_slcr"
173 #define ZYNQ_SLCR(obj) OBJECT_CHECK(ZynqSLCRState, (obj), TYPE_ZYNQ_SLCR)
175 typedef struct ZynqSLCRState
{
176 SysBusDevice parent_obj
;
180 uint32_t regs
[ZYNQ_SLCR_NUM_REGS
];
183 static void zynq_slcr_reset(DeviceState
*d
)
185 ZynqSLCRState
*s
= ZYNQ_SLCR(d
);
190 s
->regs
[LOCKSTA
] = 1;
192 s
->regs
[ARM_PLL_CTRL
] = 0x0001A008;
193 s
->regs
[DDR_PLL_CTRL
] = 0x0001A008;
194 s
->regs
[IO_PLL_CTRL
] = 0x0001A008;
195 s
->regs
[PLL_STATUS
] = 0x0000003F;
196 s
->regs
[ARM_PLL_CFG
] = 0x00014000;
197 s
->regs
[DDR_PLL_CFG
] = 0x00014000;
198 s
->regs
[IO_PLL_CFG
] = 0x00014000;
201 s
->regs
[ARM_CLK_CTRL
] = 0x1F000400;
202 s
->regs
[DDR_CLK_CTRL
] = 0x18400003;
203 s
->regs
[DCI_CLK_CTRL
] = 0x01E03201;
204 s
->regs
[APER_CLK_CTRL
] = 0x01FFCCCD;
205 s
->regs
[USB0_CLK_CTRL
] = s
->regs
[USB1_CLK_CTRL
] = 0x00101941;
206 s
->regs
[GEM0_RCLK_CTRL
] = s
->regs
[GEM1_RCLK_CTRL
] = 0x00000001;
207 s
->regs
[GEM0_CLK_CTRL
] = s
->regs
[GEM1_CLK_CTRL
] = 0x00003C01;
208 s
->regs
[SMC_CLK_CTRL
] = 0x00003C01;
209 s
->regs
[LQSPI_CLK_CTRL
] = 0x00002821;
210 s
->regs
[SDIO_CLK_CTRL
] = 0x00001E03;
211 s
->regs
[UART_CLK_CTRL
] = 0x00003F03;
212 s
->regs
[SPI_CLK_CTRL
] = 0x00003F03;
213 s
->regs
[CAN_CLK_CTRL
] = 0x00501903;
214 s
->regs
[DBG_CLK_CTRL
] = 0x00000F03;
215 s
->regs
[PCAP_CLK_CTRL
] = 0x00000F01;
218 s
->regs
[FPGA0_CLK_CTRL
] = s
->regs
[FPGA1_CLK_CTRL
] = s
->regs
[FPGA2_CLK_CTRL
]
219 = s
->regs
[FPGA3_CLK_CTRL
] = 0x00101800;
220 s
->regs
[FPGA0_THR_STA
] = s
->regs
[FPGA1_THR_STA
] = s
->regs
[FPGA2_THR_STA
]
221 = s
->regs
[FPGA3_THR_STA
] = 0x00010000;
224 s
->regs
[BANDGAP_TRIP
] = 0x0000001F;
225 s
->regs
[PLL_PREDIVISOR
] = 0x00000001;
226 s
->regs
[CLK_621_TRUE
] = 0x00000001;
229 s
->regs
[FPGA_RST_CTRL
] = 0x01F33F0F;
230 s
->regs
[RST_REASON
] = 0x00000040;
232 s
->regs
[BOOT_MODE
] = 0x00000001;
235 for (i
= 0; i
< 54; i
++) {
236 s
->regs
[MIO
+ i
] = 0x00001601;
238 for (i
= 2; i
<= 8; i
++) {
239 s
->regs
[MIO
+ i
] = 0x00000601;
242 s
->regs
[MIO_MST_TRI0
] = s
->regs
[MIO_MST_TRI1
] = 0xFFFFFFFF;
244 s
->regs
[CPU_RAM
+ 0] = s
->regs
[CPU_RAM
+ 1] = s
->regs
[CPU_RAM
+ 3]
245 = s
->regs
[CPU_RAM
+ 4] = s
->regs
[CPU_RAM
+ 7]
247 s
->regs
[CPU_RAM
+ 2] = s
->regs
[CPU_RAM
+ 5] = 0x01010101;
248 s
->regs
[CPU_RAM
+ 6] = 0x00000001;
250 s
->regs
[IOU
+ 0] = s
->regs
[IOU
+ 1] = s
->regs
[IOU
+ 2] = s
->regs
[IOU
+ 3]
252 s
->regs
[IOU
+ 4] = s
->regs
[IOU
+ 5] = 0x00090909;
253 s
->regs
[IOU
+ 6] = 0x00000909;
255 s
->regs
[DMAC_RAM
] = 0x00000009;
257 s
->regs
[AFI0
+ 0] = s
->regs
[AFI0
+ 1] = 0x09090909;
258 s
->regs
[AFI1
+ 0] = s
->regs
[AFI1
+ 1] = 0x09090909;
259 s
->regs
[AFI2
+ 0] = s
->regs
[AFI2
+ 1] = 0x09090909;
260 s
->regs
[AFI3
+ 0] = s
->regs
[AFI3
+ 1] = 0x09090909;
261 s
->regs
[AFI0
+ 2] = s
->regs
[AFI1
+ 2] = s
->regs
[AFI2
+ 2]
262 = s
->regs
[AFI3
+ 2] = 0x00000909;
264 s
->regs
[OCM
+ 0] = 0x01010101;
265 s
->regs
[OCM
+ 1] = s
->regs
[OCM
+ 2] = 0x09090909;
267 s
->regs
[DEVCI_RAM
] = 0x00000909;
268 s
->regs
[CSG_RAM
] = 0x00000001;
270 s
->regs
[DDRIOB
+ 0] = s
->regs
[DDRIOB
+ 1] = s
->regs
[DDRIOB
+ 2]
271 = s
->regs
[DDRIOB
+ 3] = 0x00000e00;
272 s
->regs
[DDRIOB
+ 4] = s
->regs
[DDRIOB
+ 5] = s
->regs
[DDRIOB
+ 6]
274 s
->regs
[DDRIOB
+ 12] = 0x00000021;
278 static bool zynq_slcr_check_offset(hwaddr offset
, bool rnw
)
285 return !rnw
; /* Write only */
296 return rnw
;/* read only */
298 case ARM_PLL_CTRL
... IO_PLL_CTRL
:
299 case ARM_PLL_CFG
... IO_PLL_CFG
:
300 case ARM_CLK_CTRL
... TOPSW_CLK_CTRL
:
301 case FPGA0_CLK_CTRL
... FPGA0_THR_CNT
:
302 case FPGA1_CLK_CTRL
... FPGA1_THR_CNT
:
303 case FPGA2_CLK_CTRL
... FPGA2_THR_CNT
:
304 case FPGA3_CLK_CTRL
... FPGA3_THR_CNT
:
308 case PSS_RST_CTRL
... A9_CPU_RST_CTRL
:
314 case TZ_DMA_NS
... TZ_DMA_PERIPH_NS
:
317 case MIO
... MIO
+ MIO_LENGTH
- 1:
318 case MIO_LOOPBACK
... MIO_MST_TRI1
:
326 case AFI0
... AFI3
+ AFI_LENGTH
- 1:
330 case GPIOB_CTRL
... GPIOB_CFG_CMOS33
:
332 case GPIOB_DRVR_BIAS_CTRL
:
333 case DDRIOB
... DDRIOB
+ DDRIOB_LENGTH
- 1:
340 static uint64_t zynq_slcr_read(void *opaque
, hwaddr offset
,
343 ZynqSLCRState
*s
= opaque
;
345 uint32_t ret
= s
->regs
[offset
];
347 if (!zynq_slcr_check_offset(offset
, true)) {
348 qemu_log_mask(LOG_GUEST_ERROR
, "zynq_slcr: Invalid read access to "
349 " addr %" HWADDR_PRIx
"\n", offset
* 4);
352 DB_PRINT("addr: %08" HWADDR_PRIx
" data: %08" PRIx32
"\n", offset
* 4, ret
);
356 static void zynq_slcr_write(void *opaque
, hwaddr offset
,
357 uint64_t val
, unsigned size
)
359 ZynqSLCRState
*s
= (ZynqSLCRState
*)opaque
;
362 DB_PRINT("addr: %08" HWADDR_PRIx
" data: %08" PRIx64
"\n", offset
* 4, val
);
364 if (!zynq_slcr_check_offset(offset
, false)) {
365 qemu_log_mask(LOG_GUEST_ERROR
, "zynq_slcr: Invalid write access to "
366 "addr %" HWADDR_PRIx
"\n", offset
* 4);
372 s
->regs
[SCL
] = val
& 0x1;
375 if ((val
& 0xFFFF) == XILINX_LOCK_KEY
) {
376 DB_PRINT("XILINX LOCK 0xF8000000 + 0x%x <= 0x%x\n", (int)offset
,
377 (unsigned)val
& 0xFFFF);
378 s
->regs
[LOCKSTA
] = 1;
380 DB_PRINT("WRONG XILINX LOCK KEY 0xF8000000 + 0x%x <= 0x%x\n",
381 (int)offset
, (unsigned)val
& 0xFFFF);
385 if ((val
& 0xFFFF) == XILINX_UNLOCK_KEY
) {
386 DB_PRINT("XILINX UNLOCK 0xF8000000 + 0x%x <= 0x%x\n", (int)offset
,
387 (unsigned)val
& 0xFFFF);
388 s
->regs
[LOCKSTA
] = 0;
390 DB_PRINT("WRONG XILINX UNLOCK KEY 0xF8000000 + 0x%x <= 0x%x\n",
391 (int)offset
, (unsigned)val
& 0xFFFF);
396 if (!s
->regs
[LOCKSTA
]) {
397 s
->regs
[offset
/ 4] = val
;
399 DB_PRINT("SCLR registers are locked. Unlock them first\n");
405 if (val
& R_PSS_RST_CTRL_SOFT_RST
) {
406 qemu_system_reset_request();
412 static const MemoryRegionOps slcr_ops
= {
413 .read
= zynq_slcr_read
,
414 .write
= zynq_slcr_write
,
415 .endianness
= DEVICE_NATIVE_ENDIAN
,
418 static void zynq_slcr_init(Object
*obj
)
420 ZynqSLCRState
*s
= ZYNQ_SLCR(obj
);
422 memory_region_init_io(&s
->iomem
, obj
, &slcr_ops
, s
, "slcr",
423 ZYNQ_SLCR_MMIO_SIZE
);
424 sysbus_init_mmio(SYS_BUS_DEVICE(obj
), &s
->iomem
);
427 static const VMStateDescription vmstate_zynq_slcr
= {
430 .minimum_version_id
= 2,
431 .fields
= (VMStateField
[]) {
432 VMSTATE_UINT32_ARRAY(regs
, ZynqSLCRState
, ZYNQ_SLCR_NUM_REGS
),
433 VMSTATE_END_OF_LIST()
437 static void zynq_slcr_class_init(ObjectClass
*klass
, void *data
)
439 DeviceClass
*dc
= DEVICE_CLASS(klass
);
441 dc
->vmsd
= &vmstate_zynq_slcr
;
442 dc
->reset
= zynq_slcr_reset
;
445 static const TypeInfo zynq_slcr_info
= {
446 .class_init
= zynq_slcr_class_init
,
447 .name
= TYPE_ZYNQ_SLCR
,
448 .parent
= TYPE_SYS_BUS_DEVICE
,
449 .instance_size
= sizeof(ZynqSLCRState
),
450 .instance_init
= zynq_slcr_init
,
453 static void zynq_slcr_register_types(void)
455 type_register_static(&zynq_slcr_info
);
458 type_init(zynq_slcr_register_types
)