blob: 717ec65aeee0132a6a07f49c774192ec18f4e4f4 [file] [log] [blame]
Michal Simekeb1dfa72013-02-04 12:38:59 +01001/*
2 * Copyright (c) 2013 Xilinx Inc.
3 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Michal Simekeb1dfa72013-02-04 12:38:59 +01005 */
6
7#include <common.h>
8#include <asm/io.h>
9#include <malloc.h>
10#include <asm/arch/hardware.h>
11
12#define SLCR_LOCK_MAGIC 0x767B
13#define SLCR_UNLOCK_MAGIC 0xDF0D
14
Michal Simek15d654c2013-04-22 15:43:02 +020015#define SLCR_IDCODE_MASK 0x1F000
16#define SLCR_IDCODE_SHIFT 12
17
Michal Simekeb1dfa72013-02-04 12:38:59 +010018static int slcr_lock = 1; /* 1 means locked, 0 means unlocked */
19
20void zynq_slcr_lock(void)
21{
22 if (!slcr_lock)
23 writel(SLCR_LOCK_MAGIC, &slcr_base->slcr_lock);
24}
25
26void zynq_slcr_unlock(void)
27{
28 if (slcr_lock)
29 writel(SLCR_UNLOCK_MAGIC, &slcr_base->slcr_unlock);
30}
31
32/* Reset the entire system */
33void zynq_slcr_cpu_reset(void)
34{
35 /*
36 * Unlock the SLCR then reset the system.
37 * Note that this seems to require raw i/o
38 * functions or there's a lockup?
39 */
40 zynq_slcr_unlock();
41
42 /*
43 * Clear 0x0F000000 bits of reboot status register to workaround
44 * the FSBL not loading the bitstream after soft-reboot
45 * This is a temporary solution until we know more.
46 */
47 clrbits_le32(&slcr_base->reboot_status, 0xF000000);
48
49 writel(1, &slcr_base->pss_rst_ctrl);
50}
Michal Simekd9f2c112012-10-15 14:01:23 +020051
52/* Setup clk for network */
53void zynq_slcr_gem_clk_setup(u32 gem_id, u32 rclk, u32 clk)
54{
55 zynq_slcr_unlock();
56
57 if (gem_id > 1) {
58 printf("Non existing GEM id %d\n", gem_id);
59 goto out;
60 }
61
62 if (gem_id) {
63 /* Set divisors for appropriate frequency in GEM_CLK_CTRL */
64 writel(clk, &slcr_base->gem1_clk_ctrl);
65 /* Configure GEM_RCLK_CTRL */
66 writel(rclk, &slcr_base->gem1_rclk_ctrl);
67 } else {
68 /* Set divisors for appropriate frequency in GEM_CLK_CTRL */
69 writel(clk, &slcr_base->gem0_clk_ctrl);
70 /* Configure GEM_RCLK_CTRL */
71 writel(rclk, &slcr_base->gem0_rclk_ctrl);
72 }
Michal Simek661ccfc2013-05-08 15:37:28 +020073 udelay(100000);
Michal Simekd9f2c112012-10-15 14:01:23 +020074out:
75 zynq_slcr_lock();
76}
Michal Simek15d654c2013-04-22 15:43:02 +020077
78void zynq_slcr_devcfg_disable(void)
79{
80 zynq_slcr_unlock();
81
82 /* Disable AXI interface */
83 writel(0xFFFFFFFF, &slcr_base->fpga_rst_ctrl);
84
85 /* Set Level Shifters DT618760 */
86 writel(0xA, &slcr_base->lvl_shftr_en);
87
88 zynq_slcr_lock();
89}
90
91void zynq_slcr_devcfg_enable(void)
92{
93 zynq_slcr_unlock();
94
95 /* Set Level Shifters DT618760 */
96 writel(0xF, &slcr_base->lvl_shftr_en);
97
98 /* Disable AXI interface */
99 writel(0x0, &slcr_base->fpga_rst_ctrl);
100
101 zynq_slcr_lock();
102}
103
104u32 zynq_slcr_get_idcode(void)
105{
106 return (readl(&slcr_base->pss_idcode) & SLCR_IDCODE_MASK) >>
107 SLCR_IDCODE_SHIFT;
108}