blob: 5ba58fad1621a15d7945865f4fe4de25c8f0ceb6 [file] [log] [blame]
Michal Simek59c651f2013-02-04 12:38:59 +01001/*
2 * Copyright (c) 2013 Xilinx Inc.
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Michal Simek59c651f2013-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>
Michal Simek3b5b5992014-04-25 13:48:08 +020011#include <asm/arch/sys_proto.h>
Soren Brinkmann97598fc2013-11-21 13:39:01 -080012#include <asm/arch/clk.h>
Michal Simek59c651f2013-02-04 12:38:59 +010013
14#define SLCR_LOCK_MAGIC 0x767B
15#define SLCR_UNLOCK_MAGIC 0xDF0D
16
Michal Simekd5dae852013-04-22 15:43:02 +020017#define SLCR_IDCODE_MASK 0x1F000
18#define SLCR_IDCODE_SHIFT 12
19
Michal Simek59c651f2013-02-04 12:38:59 +010020static int slcr_lock = 1; /* 1 means locked, 0 means unlocked */
21
22void zynq_slcr_lock(void)
23{
Michal Simek2da7a742013-08-30 07:26:08 +020024 if (!slcr_lock) {
Michal Simek59c651f2013-02-04 12:38:59 +010025 writel(SLCR_LOCK_MAGIC, &slcr_base->slcr_lock);
Michal Simek2da7a742013-08-30 07:26:08 +020026 slcr_lock = 1;
27 }
Michal Simek59c651f2013-02-04 12:38:59 +010028}
29
30void zynq_slcr_unlock(void)
31{
Michal Simek2da7a742013-08-30 07:26:08 +020032 if (slcr_lock) {
Michal Simek59c651f2013-02-04 12:38:59 +010033 writel(SLCR_UNLOCK_MAGIC, &slcr_base->slcr_unlock);
Michal Simek2da7a742013-08-30 07:26:08 +020034 slcr_lock = 0;
35 }
Michal Simek59c651f2013-02-04 12:38:59 +010036}
37
38/* Reset the entire system */
39void zynq_slcr_cpu_reset(void)
40{
41 /*
42 * Unlock the SLCR then reset the system.
43 * Note that this seems to require raw i/o
44 * functions or there's a lockup?
45 */
46 zynq_slcr_unlock();
47
48 /*
49 * Clear 0x0F000000 bits of reboot status register to workaround
50 * the FSBL not loading the bitstream after soft-reboot
51 * This is a temporary solution until we know more.
52 */
53 clrbits_le32(&slcr_base->reboot_status, 0xF000000);
54
55 writel(1, &slcr_base->pss_rst_ctrl);
56}
Michal Simek80243522012-10-15 14:01:23 +020057
58/* Setup clk for network */
Soren Brinkmann97598fc2013-11-21 13:39:01 -080059void zynq_slcr_gem_clk_setup(u32 gem_id, unsigned long clk_rate)
Michal Simek80243522012-10-15 14:01:23 +020060{
Soren Brinkmann97598fc2013-11-21 13:39:01 -080061 int ret;
62
Michal Simek80243522012-10-15 14:01:23 +020063 zynq_slcr_unlock();
64
65 if (gem_id > 1) {
66 printf("Non existing GEM id %d\n", gem_id);
67 goto out;
68 }
69
Soren Brinkmann97598fc2013-11-21 13:39:01 -080070 ret = zynq_clk_set_rate(gem0_clk + gem_id, clk_rate);
71 if (ret)
72 goto out;
73
Michal Simek80243522012-10-15 14:01:23 +020074 if (gem_id) {
Michal Simek80243522012-10-15 14:01:23 +020075 /* Configure GEM_RCLK_CTRL */
Soren Brinkmann1cd46ed2013-11-21 13:39:00 -080076 writel(1, &slcr_base->gem1_rclk_ctrl);
Michal Simek80243522012-10-15 14:01:23 +020077 } else {
Michal Simek80243522012-10-15 14:01:23 +020078 /* Configure GEM_RCLK_CTRL */
Soren Brinkmann1cd46ed2013-11-21 13:39:00 -080079 writel(1, &slcr_base->gem0_rclk_ctrl);
Michal Simek80243522012-10-15 14:01:23 +020080 }
Michal Simek39523be2013-05-08 15:37:28 +020081 udelay(100000);
Michal Simek80243522012-10-15 14:01:23 +020082out:
83 zynq_slcr_lock();
84}
Michal Simekd5dae852013-04-22 15:43:02 +020085
86void zynq_slcr_devcfg_disable(void)
87{
88 zynq_slcr_unlock();
89
Michal Simek6e047692014-03-27 10:06:43 +010090 /* Disable AXI interface by asserting FPGA resets */
Michal Simekd5dae852013-04-22 15:43:02 +020091 writel(0xFFFFFFFF, &slcr_base->fpga_rst_ctrl);
92
93 /* Set Level Shifters DT618760 */
94 writel(0xA, &slcr_base->lvl_shftr_en);
95
96 zynq_slcr_lock();
97}
98
99void zynq_slcr_devcfg_enable(void)
100{
101 zynq_slcr_unlock();
102
103 /* Set Level Shifters DT618760 */
104 writel(0xF, &slcr_base->lvl_shftr_en);
105
Michal Simek6e047692014-03-27 10:06:43 +0100106 /* Enable AXI interface by de-asserting FPGA resets */
Michal Simekd5dae852013-04-22 15:43:02 +0200107 writel(0x0, &slcr_base->fpga_rst_ctrl);
108
109 zynq_slcr_lock();
110}
111
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +0530112u32 zynq_slcr_get_boot_mode(void)
113{
114 /* Get the bootmode register value */
115 return readl(&slcr_base->boot_mode);
116}
117
Michal Simekd5dae852013-04-22 15:43:02 +0200118u32 zynq_slcr_get_idcode(void)
119{
120 return (readl(&slcr_base->pss_idcode) & SLCR_IDCODE_MASK) >>
121 SLCR_IDCODE_SHIFT;
122}