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