Michal Simek | eb1dfa7 | 2013-02-04 12:38:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 Xilinx Inc. |
| 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | eb1dfa7 | 2013-02-04 12:38:59 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <asm/io.h> |
| 9 | #include <malloc.h> |
| 10 | #include <asm/arch/hardware.h> |
Soren Brinkmann | 4dded98 | 2013-11-21 13:39:01 -0800 | [diff] [blame^] | 11 | #include <asm/arch/clk.h> |
Michal Simek | eb1dfa7 | 2013-02-04 12:38:59 +0100 | [diff] [blame] | 12 | |
| 13 | #define SLCR_LOCK_MAGIC 0x767B |
| 14 | #define SLCR_UNLOCK_MAGIC 0xDF0D |
| 15 | |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 16 | #define SLCR_IDCODE_MASK 0x1F000 |
| 17 | #define SLCR_IDCODE_SHIFT 12 |
| 18 | |
Michal Simek | eb1dfa7 | 2013-02-04 12:38:59 +0100 | [diff] [blame] | 19 | static int slcr_lock = 1; /* 1 means locked, 0 means unlocked */ |
| 20 | |
| 21 | void zynq_slcr_lock(void) |
| 22 | { |
| 23 | if (!slcr_lock) |
| 24 | writel(SLCR_LOCK_MAGIC, &slcr_base->slcr_lock); |
| 25 | } |
| 26 | |
| 27 | void 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 */ |
| 34 | void 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 Simek | d9f2c11 | 2012-10-15 14:01:23 +0200 | [diff] [blame] | 52 | |
| 53 | /* Setup clk for network */ |
Soren Brinkmann | 4dded98 | 2013-11-21 13:39:01 -0800 | [diff] [blame^] | 54 | void zynq_slcr_gem_clk_setup(u32 gem_id, unsigned long clk_rate) |
Michal Simek | d9f2c11 | 2012-10-15 14:01:23 +0200 | [diff] [blame] | 55 | { |
Soren Brinkmann | 4dded98 | 2013-11-21 13:39:01 -0800 | [diff] [blame^] | 56 | int ret; |
| 57 | |
Michal Simek | d9f2c11 | 2012-10-15 14:01:23 +0200 | [diff] [blame] | 58 | 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 Brinkmann | 4dded98 | 2013-11-21 13:39:01 -0800 | [diff] [blame^] | 65 | ret = zynq_clk_set_rate(gem0_clk + gem_id, clk_rate); |
| 66 | if (ret) |
| 67 | goto out; |
| 68 | |
Michal Simek | d9f2c11 | 2012-10-15 14:01:23 +0200 | [diff] [blame] | 69 | if (gem_id) { |
Michal Simek | d9f2c11 | 2012-10-15 14:01:23 +0200 | [diff] [blame] | 70 | /* Configure GEM_RCLK_CTRL */ |
Soren Brinkmann | 3b5b992 | 2013-11-21 13:39:00 -0800 | [diff] [blame] | 71 | writel(1, &slcr_base->gem1_rclk_ctrl); |
Michal Simek | d9f2c11 | 2012-10-15 14:01:23 +0200 | [diff] [blame] | 72 | } else { |
Michal Simek | d9f2c11 | 2012-10-15 14:01:23 +0200 | [diff] [blame] | 73 | /* Configure GEM_RCLK_CTRL */ |
Soren Brinkmann | 3b5b992 | 2013-11-21 13:39:00 -0800 | [diff] [blame] | 74 | writel(1, &slcr_base->gem0_rclk_ctrl); |
Michal Simek | d9f2c11 | 2012-10-15 14:01:23 +0200 | [diff] [blame] | 75 | } |
Michal Simek | 661ccfc | 2013-05-08 15:37:28 +0200 | [diff] [blame] | 76 | udelay(100000); |
Michal Simek | d9f2c11 | 2012-10-15 14:01:23 +0200 | [diff] [blame] | 77 | out: |
| 78 | zynq_slcr_lock(); |
| 79 | } |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 80 | |
| 81 | void 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 | |
| 94 | void 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 Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 107 | u32 zynq_slcr_get_boot_mode(void) |
| 108 | { |
| 109 | /* Get the bootmode register value */ |
| 110 | return readl(&slcr_base->boot_mode); |
| 111 | } |
| 112 | |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 113 | u32 zynq_slcr_get_idcode(void) |
| 114 | { |
| 115 | return (readl(&slcr_base->pss_idcode) & SLCR_IDCODE_MASK) >> |
| 116 | SLCR_IDCODE_SHIFT; |
| 117 | } |