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/>.
17 #include "qemu/osdep.h"
19 #include "qemu/timer.h"
20 #include "hw/sysbus.h"
21 #include "sysemu/sysemu.h"
23 #ifndef ZYNQ_SLCR_ERR_DEBUG
24 #define ZYNQ_SLCR_ERR_DEBUG 0
27 #define DB_PRINT(...) do { \
28 if (ZYNQ_SLCR_ERR_DEBUG) { \
29 fprintf(stderr, ": %s: ", __func__); \
30 fprintf(stderr, ## __VA_ARGS__); \
34 #define XILINX_LOCK_KEY 0x767b
35 #define XILINX_UNLOCK_KEY 0xdf0d
37 #define R_PSS_RST_CTRL_SOFT_RST 0x1
45 ARM_PLL_CTRL
= 0x100 / 4,
53 ARM_CLK_CTRL
= 0x120 / 4,
74 #define FPGA_CTRL_REGS(n, start) \
75 FPGA ## n ## _CLK_CTRL = (start) / 4, \
76 FPGA ## n ## _THR_CTRL, \
77 FPGA ## n ## _THR_CNT, \
78 FPGA ## n ## _THR_STA,
79 FPGA_CTRL_REGS(0, 0x170)
80 FPGA_CTRL_REGS(1, 0x180)
81 FPGA_CTRL_REGS(2, 0x190)
82 FPGA_CTRL_REGS(3, 0x1a0)
84 BANDGAP_TRIP
= 0x1b8 / 4,
85 PLL_PREDIVISOR
= 0x1c0 / 4,
88 PSS_RST_CTRL
= 0x200 / 4,
103 FPGA_RST_CTRL
= 0x240 / 4,
106 RS_AWDT_CTRL
= 0x24c / 4,
109 REBOOT_STATUS
= 0x258 / 4,
112 APU_CTRL
= 0x300 / 4,
115 TZ_DMA_NS
= 0x440 / 4,
119 PSS_IDCODE
= 0x530 / 4,
121 DDR_URGENT
= 0x600 / 4,
122 DDR_CAL_START
= 0x60c / 4,
123 DDR_REF_START
= 0x614 / 4,
129 #define MIO_LENGTH 54
131 MIO_LOOPBACK
= 0x804 / 4,
135 SD0_WP_CD_SEL
= 0x830 / 4,
138 LVL_SHFTR_EN
= 0x900 / 4,
145 DMAC_RAM
= 0xa50 / 4,
155 DEVCI_RAM
= 0xaa0 / 4,
159 GPIOB_CTRL
= 0xb00 / 4,
163 GPIOB_CFG_HSTL
= 0xb14 / 4,
164 GPIOB_DRVR_BIAS_CTRL
,
167 #define DDRIOB_LENGTH 14
170 #define ZYNQ_SLCR_MMIO_SIZE 0x1000
171 #define ZYNQ_SLCR_NUM_REGS (ZYNQ_SLCR_MMIO_SIZE / 4)
173 #define TYPE_ZYNQ_SLCR "xilinx,zynq_slcr"
174 #define ZYNQ_SLCR(obj) OBJECT_CHECK(ZynqSLCRState, (obj), TYPE_ZYNQ_SLCR)
176 typedef struct ZynqSLCRState
{
177 SysBusDevice parent_obj
;
181 uint32_t regs
[ZYNQ_SLCR_NUM_REGS
];
184 static void zynq_slcr_reset(DeviceState
*d
)
186 ZynqSLCRState
*s
= ZYNQ_SLCR(d
);
191 s
->regs
[LOCKSTA
] = 1;
193 s
->regs
[ARM_PLL_CTRL
] = 0x0001A008;
194 s
->regs
[DDR_PLL_CTRL
] = 0x0001A008;
195 s
->regs
[IO_PLL_CTRL
] = 0x0001A008;
196 s
->regs
[PLL_STATUS
] = 0x0000003F;
197 s
->regs
[ARM_PLL_CFG
] = 0x00014000;
198 s
->regs
[DDR_PLL_CFG
] = 0x00014000;
199 s
->regs
[IO_PLL_CFG
] = 0x00014000;
202 s
->regs
[ARM_CLK_CTRL
] = 0x1F000400;
203 s
->regs
[DDR_CLK_CTRL
] = 0x18400003;
204 s
->regs
[DCI_CLK_CTRL
] = 0x01E03201;
205 s
->regs
[APER_CLK_CTRL
] = 0x01FFCCCD;
206 s
->regs
[USB0_CLK_CTRL
] = s
->regs
[USB1_CLK_CTRL
] = 0x00101941;
207 s
->regs
[GEM0_RCLK_CTRL
] = s
->regs
[GEM1_RCLK_CTRL
] = 0x00000001;
208 s
->regs
[GEM0_CLK_CTRL
] = s
->regs
[GEM1_CLK_CTRL
] = 0x00003C01;
209 s
->regs
[SMC_CLK_CTRL
] = 0x00003C01;
210 s
->regs
[LQSPI_CLK_CTRL
] = 0x00002821;
211 s
->regs
[SDIO_CLK_CTRL
] = 0x00001E03;
212 s
->regs
[UART_CLK_CTRL
] = 0x00003F03;
213 s
->regs
[SPI_CLK_CTRL
] = 0x00003F03;
214 s
->regs
[CAN_CLK_CTRL
] = 0x00501903;
215 s
->regs
[DBG_CLK_CTRL
] = 0x00000F03;
216 s
->regs
[PCAP_CLK_CTRL
] = 0x00000F01;
219 s
->regs
[FPGA0_CLK_CTRL
] = s
->regs
[FPGA1_CLK_CTRL
] = s
->regs
[FPGA2_CLK_CTRL
]
220 = s
->regs
[FPGA3_CLK_CTRL
] = 0x00101800;
221 s
->regs
[FPGA0_THR_STA
] = s
->regs
[FPGA1_THR_STA
] = s
->regs
[FPGA2_THR_STA
]
222 = s
->regs
[FPGA3_THR_STA
] = 0x00010000;
225 s
->regs
[BANDGAP_TRIP
] = 0x0000001F;
226 s
->regs
[PLL_PREDIVISOR
] = 0x00000001;
227 s
->regs
[CLK_621_TRUE
] = 0x00000001;
230 s
->regs
[FPGA_RST_CTRL
] = 0x01F33F0F;
231 s
->regs
[RST_REASON
] = 0x00000040;
233 s
->regs
[BOOT_MODE
] = 0x00000001;
236 for (i
= 0; i
< 54; i
++) {
237 s
->regs
[MIO
+ i
] = 0x00001601;
239 for (i
= 2; i
<= 8; i
++) {
240 s
->regs
[MIO
+ i
] = 0x00000601;
243 s
->regs
[MIO_MST_TRI0
] = s
->regs
[MIO_MST_TRI1
] = 0xFFFFFFFF;
245 s
->regs
[CPU_RAM
+ 0] = s
->regs
[CPU_RAM
+ 1] = s
->regs
[CPU_RAM
+ 3]
246 = s
->regs
[CPU_RAM
+ 4] = s
->regs
[CPU_RAM
+ 7]
248 s
->regs
[CPU_RAM
+ 2] = s
->regs
[CPU_RAM
+ 5] = 0x01010101;
249 s
->regs
[CPU_RAM
+ 6] = 0x00000001;
251 s
->regs
[IOU
+ 0] = s
->regs
[IOU
+ 1] = s
->regs
[IOU
+ 2] = s
->regs
[IOU
+ 3]
253 s
->regs
[IOU
+ 4] = s
->regs
[IOU
+ 5] = 0x00090909;
254 s
->regs
[IOU
+ 6] = 0x00000909;
256 s
->regs
[DMAC_RAM
] = 0x00000009;
258 s
->regs
[AFI0
+ 0] = s
->regs
[AFI0
+ 1] = 0x09090909;
259 s
->regs
[AFI1
+ 0] = s
->regs
[AFI1
+ 1] = 0x09090909;
260 s
->regs
[AFI2
+ 0] = s
->regs
[AFI2
+ 1] = 0x09090909;
261 s
->regs
[AFI3
+ 0] = s
->regs
[AFI3
+ 1] = 0x09090909;
262 s
->regs
[AFI0
+ 2] = s
->regs
[AFI1
+ 2] = s
->regs
[AFI2
+ 2]
263 = s
->regs
[AFI3
+ 2] = 0x00000909;
265 s
->regs
[OCM
+ 0] = 0x01010101;
266 s
->regs
[OCM
+ 1] = s
->regs
[OCM
+ 2] = 0x09090909;
268 s
->regs
[DEVCI_RAM
] = 0x00000909;
269 s
->regs
[CSG_RAM
] = 0x00000001;
271 s
->regs
[DDRIOB
+ 0] = s
->regs
[DDRIOB
+ 1] = s
->regs
[DDRIOB
+ 2]
272 = s
->regs
[DDRIOB
+ 3] = 0x00000e00;
273 s
->regs
[DDRIOB
+ 4] = s
->regs
[DDRIOB
+ 5] = s
->regs
[DDRIOB
+ 6]
275 s
->regs
[DDRIOB
+ 12] = 0x00000021;
279 static bool zynq_slcr_check_offset(hwaddr offset
, bool rnw
)
286 return !rnw
; /* Write only */
297 return rnw
;/* read only */
299 case ARM_PLL_CTRL
... IO_PLL_CTRL
:
300 case ARM_PLL_CFG
... IO_PLL_CFG
:
301 case ARM_CLK_CTRL
... TOPSW_CLK_CTRL
:
302 case FPGA0_CLK_CTRL
... FPGA0_THR_CNT
:
303 case FPGA1_CLK_CTRL
... FPGA1_THR_CNT
:
304 case FPGA2_CLK_CTRL
... FPGA2_THR_CNT
:
305 case FPGA3_CLK_CTRL
... FPGA3_THR_CNT
:
309 case PSS_RST_CTRL
... A9_CPU_RST_CTRL
:
315 case TZ_DMA_NS
... TZ_DMA_PERIPH_NS
:
318 case MIO
... MIO
+ MIO_LENGTH
- 1:
319 case MIO_LOOPBACK
... MIO_MST_TRI1
:
327 case AFI0
... AFI3
+ AFI_LENGTH
- 1:
331 case GPIOB_CTRL
... GPIOB_CFG_CMOS33
:
333 case GPIOB_DRVR_BIAS_CTRL
:
334 case DDRIOB
... DDRIOB
+ DDRIOB_LENGTH
- 1:
341 static uint64_t zynq_slcr_read(void *opaque
, hwaddr offset
,
344 ZynqSLCRState
*s
= opaque
;
346 uint32_t ret
= s
->regs
[offset
];
348 if (!zynq_slcr_check_offset(offset
, true)) {
349 qemu_log_mask(LOG_GUEST_ERROR
, "zynq_slcr: Invalid read access to "
350 " addr %" HWADDR_PRIx
"\n", offset
* 4);
353 DB_PRINT("addr: %08" HWADDR_PRIx
" data: %08" PRIx32
"\n", offset
* 4, ret
);
357 static void zynq_slcr_write(void *opaque
, hwaddr offset
,
358 uint64_t val
, unsigned size
)
360 ZynqSLCRState
*s
= (ZynqSLCRState
*)opaque
;
363 DB_PRINT("addr: %08" HWADDR_PRIx
" data: %08" PRIx64
"\n", offset
* 4, val
);
365 if (!zynq_slcr_check_offset(offset
, false)) {
366 qemu_log_mask(LOG_GUEST_ERROR
, "zynq_slcr: Invalid write access to "
367 "addr %" HWADDR_PRIx
"\n", offset
* 4);
373 s
->regs
[SCL
] = val
& 0x1;
376 if ((val
& 0xFFFF) == XILINX_LOCK_KEY
) {
377 DB_PRINT("XILINX LOCK 0xF8000000 + 0x%x <= 0x%x\n", (int)offset
,
378 (unsigned)val
& 0xFFFF);
379 s
->regs
[LOCKSTA
] = 1;
381 DB_PRINT("WRONG XILINX LOCK KEY 0xF8000000 + 0x%x <= 0x%x\n",
382 (int)offset
, (unsigned)val
& 0xFFFF);
386 if ((val
& 0xFFFF) == XILINX_UNLOCK_KEY
) {
387 DB_PRINT("XILINX UNLOCK 0xF8000000 + 0x%x <= 0x%x\n", (int)offset
,
388 (unsigned)val
& 0xFFFF);
389 s
->regs
[LOCKSTA
] = 0;
391 DB_PRINT("WRONG XILINX UNLOCK KEY 0xF8000000 + 0x%x <= 0x%x\n",
392 (int)offset
, (unsigned)val
& 0xFFFF);
397 if (s
->regs
[LOCKSTA
]) {
398 qemu_log_mask(LOG_GUEST_ERROR
,
399 "SCLR registers are locked. Unlock them first\n");
402 s
->regs
[offset
] = val
;
406 if (val
& R_PSS_RST_CTRL_SOFT_RST
) {
407 qemu_system_reset_request();
413 static const MemoryRegionOps slcr_ops
= {
414 .read
= zynq_slcr_read
,
415 .write
= zynq_slcr_write
,
416 .endianness
= DEVICE_NATIVE_ENDIAN
,
419 static void zynq_slcr_init(Object
*obj
)
421 ZynqSLCRState
*s
= ZYNQ_SLCR(obj
);
423 memory_region_init_io(&s
->iomem
, obj
, &slcr_ops
, s
, "slcr",
424 ZYNQ_SLCR_MMIO_SIZE
);
425 sysbus_init_mmio(SYS_BUS_DEVICE(obj
), &s
->iomem
);
428 static const VMStateDescription vmstate_zynq_slcr
= {
431 .minimum_version_id
= 2,
432 .fields
= (VMStateField
[]) {
433 VMSTATE_UINT32_ARRAY(regs
, ZynqSLCRState
, ZYNQ_SLCR_NUM_REGS
),
434 VMSTATE_END_OF_LIST()
438 static void zynq_slcr_class_init(ObjectClass
*klass
, void *data
)
440 DeviceClass
*dc
= DEVICE_CLASS(klass
);
442 dc
->vmsd
= &vmstate_zynq_slcr
;
443 dc
->reset
= zynq_slcr_reset
;
446 static const TypeInfo zynq_slcr_info
= {
447 .class_init
= zynq_slcr_class_init
,
448 .name
= TYPE_ZYNQ_SLCR
,
449 .parent
= TYPE_SYS_BUS_DEVICE
,
450 .instance_size
= sizeof(ZynqSLCRState
),
451 .instance_init
= zynq_slcr_init
,
454 static void zynq_slcr_register_types(void)
456 type_register_static(&zynq_slcr_info
);
459 type_init(zynq_slcr_register_types
)