Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Xiubo Li | 54de065 | 2014-11-21 17:40:58 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2014 Freescale Semiconductor |
Xiubo Li | 54de065 | 2014-11-21 17:40:58 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <asm/io.h> |
Mingkai Hu | 5b0df8a | 2015-10-26 19:47:41 +0800 | [diff] [blame] | 8 | #include <fsl_csu.h> |
Xiubo Li | 54de065 | 2014-11-21 17:40:58 +0800 | [diff] [blame] | 9 | #include <asm/arch/ns_access.h> |
Hou Zhiqiang | fd43b36 | 2016-08-02 19:03:26 +0800 | [diff] [blame] | 10 | #include <asm/arch/fsl_serdes.h> |
Xiubo Li | 54de065 | 2014-11-21 17:40:58 +0800 | [diff] [blame] | 11 | |
Hou Zhiqiang | 208c2b2 | 2017-07-03 17:51:10 +0800 | [diff] [blame] | 12 | void set_devices_ns_access(unsigned long index, u16 val) |
Xiubo Li | 54de065 | 2014-11-21 17:40:58 +0800 | [diff] [blame] | 13 | { |
| 14 | u32 *base = (u32 *)CONFIG_SYS_FSL_CSU_ADDR; |
| 15 | u32 *reg; |
Hou Zhiqiang | ba93225 | 2016-08-02 19:03:24 +0800 | [diff] [blame] | 16 | uint32_t tmp; |
Xiubo Li | 54de065 | 2014-11-21 17:40:58 +0800 | [diff] [blame] | 17 | |
Hou Zhiqiang | 208c2b2 | 2017-07-03 17:51:10 +0800 | [diff] [blame] | 18 | reg = base + index / 2; |
Hou Zhiqiang | ba93225 | 2016-08-02 19:03:24 +0800 | [diff] [blame] | 19 | tmp = in_be32(reg); |
Hou Zhiqiang | 208c2b2 | 2017-07-03 17:51:10 +0800 | [diff] [blame] | 20 | if (index % 2 == 0) { |
Hou Zhiqiang | ba93225 | 2016-08-02 19:03:24 +0800 | [diff] [blame] | 21 | tmp &= 0x0000ffff; |
| 22 | tmp |= val << 16; |
| 23 | } else { |
| 24 | tmp &= 0xffff0000; |
| 25 | tmp |= val; |
Xiubo Li | 54de065 | 2014-11-21 17:40:58 +0800 | [diff] [blame] | 26 | } |
Hou Zhiqiang | ba93225 | 2016-08-02 19:03:24 +0800 | [diff] [blame] | 27 | |
| 28 | out_be32(reg, tmp); |
| 29 | } |
| 30 | |
| 31 | static void enable_devices_ns_access(struct csu_ns_dev *ns_dev, uint32_t num) |
| 32 | { |
| 33 | int i; |
| 34 | |
| 35 | for (i = 0; i < num; i++) |
Hou Zhiqiang | 208c2b2 | 2017-07-03 17:51:10 +0800 | [diff] [blame] | 36 | set_devices_ns_access(ns_dev[i].ind, ns_dev[i].val); |
Xiubo Li | 54de065 | 2014-11-21 17:40:58 +0800 | [diff] [blame] | 37 | } |
Mingkai Hu | 5b0df8a | 2015-10-26 19:47:41 +0800 | [diff] [blame] | 38 | |
| 39 | void enable_layerscape_ns_access(void) |
| 40 | { |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 41 | #ifdef CONFIG_ARM64 |
| 42 | if (current_el() == 3) |
| 43 | #endif |
| 44 | enable_devices_ns_access(ns_dev, ARRAY_SIZE(ns_dev)); |
Mingkai Hu | 5b0df8a | 2015-10-26 19:47:41 +0800 | [diff] [blame] | 45 | } |
Hou Zhiqiang | fd43b36 | 2016-08-02 19:03:26 +0800 | [diff] [blame] | 46 | |
| 47 | void set_pcie_ns_access(int pcie, u16 val) |
| 48 | { |
| 49 | switch (pcie) { |
| 50 | #ifdef CONFIG_PCIE1 |
| 51 | case PCIE1: |
Hou Zhiqiang | 208c2b2 | 2017-07-03 17:51:10 +0800 | [diff] [blame] | 52 | set_devices_ns_access(CSU_CSLX_PCIE1, val); |
| 53 | set_devices_ns_access(CSU_CSLX_PCIE1_IO, val); |
Hou Zhiqiang | fd43b36 | 2016-08-02 19:03:26 +0800 | [diff] [blame] | 54 | return; |
| 55 | #endif |
| 56 | #ifdef CONFIG_PCIE2 |
| 57 | case PCIE2: |
Hou Zhiqiang | 208c2b2 | 2017-07-03 17:51:10 +0800 | [diff] [blame] | 58 | set_devices_ns_access(CSU_CSLX_PCIE2, val); |
| 59 | set_devices_ns_access(CSU_CSLX_PCIE2_IO, val); |
Hou Zhiqiang | fd43b36 | 2016-08-02 19:03:26 +0800 | [diff] [blame] | 60 | return; |
| 61 | #endif |
| 62 | #ifdef CONFIG_PCIE3 |
| 63 | case PCIE3: |
Hou Zhiqiang | 208c2b2 | 2017-07-03 17:51:10 +0800 | [diff] [blame] | 64 | set_devices_ns_access(CSU_CSLX_PCIE3, val); |
| 65 | set_devices_ns_access(CSU_CSLX_PCIE3_IO, val); |
Hou Zhiqiang | fd43b36 | 2016-08-02 19:03:26 +0800 | [diff] [blame] | 66 | return; |
| 67 | #endif |
| 68 | default: |
| 69 | debug("The PCIE%d doesn't exist!\n", pcie); |
| 70 | return; |
| 71 | } |
| 72 | } |