1
2
3
4
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_USB_L1_SEL 0x04
18
19#define SLCR_IDCODE_MASK 0x1F000
20#define SLCR_IDCODE_SHIFT 12
21
22
23
24
25
26
27
28
29
30
31struct zynq_slcr_mio_get_status {
32 const char *peri_name;
33 const int *get_pins;
34 int num_pins;
35 u32 mask;
36 u32 check_val;
37};
38
39static const int usb0_pins[] = {
40 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39
41};
42
43static const int usb1_pins[] = {
44 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
45};
46
47static const struct zynq_slcr_mio_get_status mio_periphs[] = {
48 {
49 "usb0",
50 usb0_pins,
51 ARRAY_SIZE(usb0_pins),
52 SLCR_USB_L1_SEL,
53 SLCR_USB_L1_SEL,
54 },
55 {
56 "usb1",
57 usb1_pins,
58 ARRAY_SIZE(usb1_pins),
59 SLCR_USB_L1_SEL,
60 SLCR_USB_L1_SEL,
61 },
62};
63
64static int slcr_lock = 1;
65
66void zynq_slcr_lock(void)
67{
68 if (!slcr_lock) {
69 writel(SLCR_LOCK_MAGIC, &slcr_base->slcr_lock);
70 slcr_lock = 1;
71 }
72}
73
74void zynq_slcr_unlock(void)
75{
76 if (slcr_lock) {
77 writel(SLCR_UNLOCK_MAGIC, &slcr_base->slcr_unlock);
78 slcr_lock = 0;
79 }
80}
81
82
83void zynq_slcr_cpu_reset(void)
84{
85
86
87
88
89
90 zynq_slcr_unlock();
91
92
93
94
95
96
97 clrbits_le32(&slcr_base->reboot_status, 0xF000000);
98
99 writel(1, &slcr_base->pss_rst_ctrl);
100}
101
102
103void zynq_slcr_gem_clk_setup(u32 gem_id, unsigned long clk_rate)
104{
105 int ret;
106
107 zynq_slcr_unlock();
108
109 if (gem_id > 1) {
110 printf("Non existing GEM id %d\n", gem_id);
111 goto out;
112 }
113
114 ret = zynq_clk_set_rate(gem0_clk + gem_id, clk_rate);
115 if (ret)
116 goto out;
117
118 if (gem_id) {
119
120 writel(1, &slcr_base->gem1_rclk_ctrl);
121 } else {
122
123 writel(1, &slcr_base->gem0_rclk_ctrl);
124 }
125 udelay(100000);
126out:
127 zynq_slcr_lock();
128}
129
130void zynq_slcr_devcfg_disable(void)
131{
132 u32 reg_val;
133
134 zynq_slcr_unlock();
135
136
137 writel(0xF, &slcr_base->fpga_rst_ctrl);
138
139
140 reg_val = readl(&slcr_base->lvl_shftr_en);
141 reg_val &= ~0xF;
142 writel(reg_val, &slcr_base->lvl_shftr_en);
143
144
145 writel(0xA, &slcr_base->lvl_shftr_en);
146
147 zynq_slcr_lock();
148}
149
150void zynq_slcr_devcfg_enable(void)
151{
152 zynq_slcr_unlock();
153
154
155 writel(0xF, &slcr_base->lvl_shftr_en);
156
157
158 writel(0x0, &slcr_base->fpga_rst_ctrl);
159
160 zynq_slcr_lock();
161}
162
163u32 zynq_slcr_get_boot_mode(void)
164{
165
166 return readl(&slcr_base->boot_mode);
167}
168
169u32 zynq_slcr_get_idcode(void)
170{
171 return (readl(&slcr_base->pss_idcode) & SLCR_IDCODE_MASK) >>
172 SLCR_IDCODE_SHIFT;
173}
174
175
176
177
178
179
180
181
182
183int zynq_slcr_get_mio_pin_status(const char *periph)
184{
185 const struct zynq_slcr_mio_get_status *mio_ptr;
186 int val, i, j;
187 int mio = 0;
188
189 for (i = 0; i < ARRAY_SIZE(mio_periphs); i++) {
190 if (strcmp(periph, mio_periphs[i].peri_name) == 0) {
191 mio_ptr = &mio_periphs[i];
192 for (j = 0; j < mio_ptr->num_pins; j++) {
193 val = readl(&slcr_base->mio_pin
194 [mio_ptr->get_pins[j]]);
195 if ((val & mio_ptr->mask) == mio_ptr->check_val)
196 mio++;
197 }
198 break;
199 }
200 }
201
202 return mio;
203}
204