blob: d7c18823322048f7c74764ab528a04a6c34b5c73 [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>
Soren Brinkmann4dded982013-11-21 13:39:01 -080011#include <asm/arch/clk.h>
Michal Simekeb1dfa72013-02-04 12:38:59 +010012
13#define SLCR_LOCK_MAGIC 0x767B
14#define SLCR_UNLOCK_MAGIC 0xDF0D
15
Michal Simek15d654c2013-04-22 15:43:02 +020016#define SLCR_IDCODE_MASK 0x1F000
17#define SLCR_IDCODE_SHIFT 12
18
Michal Simekeb1dfa72013-02-04 12:38:59 +010019static int slcr_lock = 1; /* 1 means locked, 0 means unlocked */
20
21void zynq_slcr_lock(void)
22{
23 if (!slcr_lock)
24 writel(SLCR_LOCK_MAGIC, &slcr_base->slcr_lock);
25}
26
27void zynq_slcr_unlock(void)
28{
29 if (slcr_lock)
30 writel(SLCR_UNLOCK_MAGIC, &slcr_base->slcr_unlock);
31}
32
33/* Reset the entire system */
34void zynq_slcr_cpu_reset(void)
35{
36 /*
37 * Unlock the SLCR then reset the system.
38 * Note that this seems to require raw i/o
39 * functions or there's a lockup?
40 */
41 zynq_slcr_unlock();
42
43 /*
44 * Clear 0x0F000000 bits of reboot status register to workaround
45 * the FSBL not loading the bitstream after soft-reboot
46 * This is a temporary solution until we know more.
47 */
48 clrbits_le32(&slcr_base->reboot_status, 0xF000000);
49
50 writel(1, &slcr_base->pss_rst_ctrl);
51}
Michal Simekd9f2c112012-10-15 14:01:23 +020052
53/* Setup clk for network */
Soren Brinkmann4dded982013-11-21 13:39:01 -080054void zynq_slcr_gem_clk_setup(u32 gem_id, unsigned long clk_rate)
Michal Simekd9f2c112012-10-15 14:01:23 +020055{
Soren Brinkmann4dded982013-11-21 13:39:01 -080056 int ret;
57
Michal Simekd9f2c112012-10-15 14:01:23 +020058 zynq_slcr_unlock();
59
60 if (gem_id > 1) {
61 printf("Non existing GEM id %d\n", gem_id);
62 goto out;
63 }
64
Soren Brinkmann4dded982013-11-21 13:39:01 -080065 ret = zynq_clk_set_rate(gem0_clk + gem_id, clk_rate);
66 if (ret)
67 goto out;
68
Michal Simekd9f2c112012-10-15 14:01:23 +020069 if (gem_id) {
Michal Simekd9f2c112012-10-15 14:01:23 +020070 /* Configure GEM_RCLK_CTRL */
Soren Brinkmann3b5b9922013-11-21 13:39:00 -080071 writel(1, &slcr_base->gem1_rclk_ctrl);
Michal Simekd9f2c112012-10-15 14:01:23 +020072 } else {
Michal Simekd9f2c112012-10-15 14:01:23 +020073 /* Configure GEM_RCLK_CTRL */
Soren Brinkmann3b5b9922013-11-21 13:39:00 -080074 writel(1, &slcr_base->gem0_rclk_ctrl);
Michal Simekd9f2c112012-10-15 14:01:23 +020075 }
Michal Simek661ccfc2013-05-08 15:37:28 +020076 udelay(100000);
Michal Simekd9f2c112012-10-15 14:01:23 +020077out:
78 zynq_slcr_lock();
79}
Michal Simek15d654c2013-04-22 15:43:02 +020080
81void zynq_slcr_devcfg_disable(void)
82{
83 zynq_slcr_unlock();
84
85 /* Disable AXI interface */
86 writel(0xFFFFFFFF, &slcr_base->fpga_rst_ctrl);
87
88 /* Set Level Shifters DT618760 */
89 writel(0xA, &slcr_base->lvl_shftr_en);
90
91 zynq_slcr_lock();
92}
93
94void zynq_slcr_devcfg_enable(void)
95{
96 zynq_slcr_unlock();
97
98 /* Set Level Shifters DT618760 */
99 writel(0xF, &slcr_base->lvl_shftr_en);
100
101 /* Disable AXI interface */
102 writel(0x0, &slcr_base->fpga_rst_ctrl);
103
104 zynq_slcr_lock();
105}
106
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +0530107u32 zynq_slcr_get_boot_mode(void)
108{
109 /* Get the bootmode register value */
110 return readl(&slcr_base->boot_mode);
111}
112
Michal Simek15d654c2013-04-22 15:43:02 +0200113u32 zynq_slcr_get_idcode(void)
114{
115 return (readl(&slcr_base->pss_idcode) & SLCR_IDCODE_MASK) >>
116 SLCR_IDCODE_SHIFT;
117}