]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/zynq/slcr.c
ARM: zynq: Fix sparse warnings in slcr.c
[karo-tx-uboot.git] / arch / arm / cpu / armv7 / zynq / slcr.c
1 /*
2  * Copyright (c) 2013 Xilinx Inc.
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6
7 #include <common.h>
8 #include <asm/io.h>
9 #include <malloc.h>
10 #include <asm/arch/hardware.h>
11 #include <asm/arch/sys_proto.h>
12 #include <asm/arch/clk.h>
13
14 #define SLCR_LOCK_MAGIC         0x767B
15 #define SLCR_UNLOCK_MAGIC       0xDF0D
16
17 #define SLCR_IDCODE_MASK        0x1F000
18 #define SLCR_IDCODE_SHIFT       12
19
20 static int slcr_lock = 1; /* 1 means locked, 0 means unlocked */
21
22 void zynq_slcr_lock(void)
23 {
24         if (!slcr_lock)
25                 writel(SLCR_LOCK_MAGIC, &slcr_base->slcr_lock);
26 }
27
28 void zynq_slcr_unlock(void)
29 {
30         if (slcr_lock)
31                 writel(SLCR_UNLOCK_MAGIC, &slcr_base->slcr_unlock);
32 }
33
34 /* Reset the entire system */
35 void zynq_slcr_cpu_reset(void)
36 {
37         /*
38          * Unlock the SLCR then reset the system.
39          * Note that this seems to require raw i/o
40          * functions or there's a lockup?
41          */
42         zynq_slcr_unlock();
43
44         /*
45          * Clear 0x0F000000 bits of reboot status register to workaround
46          * the FSBL not loading the bitstream after soft-reboot
47          * This is a temporary solution until we know more.
48          */
49         clrbits_le32(&slcr_base->reboot_status, 0xF000000);
50
51         writel(1, &slcr_base->pss_rst_ctrl);
52 }
53
54 /* Setup clk for network */
55 void zynq_slcr_gem_clk_setup(u32 gem_id, unsigned long clk_rate)
56 {
57         int ret;
58
59         zynq_slcr_unlock();
60
61         if (gem_id > 1) {
62                 printf("Non existing GEM id %d\n", gem_id);
63                 goto out;
64         }
65
66         ret = zynq_clk_set_rate(gem0_clk + gem_id, clk_rate);
67         if (ret)
68                 goto out;
69
70         if (gem_id) {
71                 /* Configure GEM_RCLK_CTRL */
72                 writel(1, &slcr_base->gem1_rclk_ctrl);
73         } else {
74                 /* Configure GEM_RCLK_CTRL */
75                 writel(1, &slcr_base->gem0_rclk_ctrl);
76         }
77         udelay(100000);
78 out:
79         zynq_slcr_lock();
80 }
81
82 void zynq_slcr_devcfg_disable(void)
83 {
84         zynq_slcr_unlock();
85
86         /* Disable AXI interface */
87         writel(0xFFFFFFFF, &slcr_base->fpga_rst_ctrl);
88
89         /* Set Level Shifters DT618760 */
90         writel(0xA, &slcr_base->lvl_shftr_en);
91
92         zynq_slcr_lock();
93 }
94
95 void zynq_slcr_devcfg_enable(void)
96 {
97         zynq_slcr_unlock();
98
99         /* Set Level Shifters DT618760 */
100         writel(0xF, &slcr_base->lvl_shftr_en);
101
102         /* Disable AXI interface */
103         writel(0x0, &slcr_base->fpga_rst_ctrl);
104
105         zynq_slcr_lock();
106 }
107
108 u32 zynq_slcr_get_boot_mode(void)
109 {
110         /* Get the bootmode register value */
111         return readl(&slcr_base->boot_mode);
112 }
113
114 u32 zynq_slcr_get_idcode(void)
115 {
116         return (readl(&slcr_base->pss_idcode) & SLCR_IDCODE_MASK) >>
117                                                         SLCR_IDCODE_SHIFT;
118 }