blob: 81c921122e8f65053e7e581426fc8083a62b44e1 [file] [log] [blame]
Xiubo Lie87f3b32014-11-21 17:40:58 +08001/*
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 Hu435acd82015-10-26 19:47:41 +08009#include <fsl_csu.h>
Xiubo Lie87f3b32014-11-21 17:40:58 +080010#include <asm/arch/ns_access.h>
Hou Zhiqiang664b6522016-08-02 19:03:26 +080011#include <asm/arch/fsl_serdes.h>
Xiubo Lie87f3b32014-11-21 17:40:58 +080012
Hou Zhiqiangc37fdbd2016-08-02 19:03:24 +080013void set_devices_ns_access(struct csu_ns_dev *ns_dev, u16 val)
Xiubo Lie87f3b32014-11-21 17:40:58 +080014{
15 u32 *base = (u32 *)CONFIG_SYS_FSL_CSU_ADDR;
16 u32 *reg;
Hou Zhiqiangc37fdbd2016-08-02 19:03:24 +080017 uint32_t tmp;
18
19 reg = base + ns_dev->ind / 2;
20 tmp = in_be32(reg);
21 if (ns_dev->ind % 2 == 0) {
22 tmp &= 0x0000ffff;
23 tmp |= val << 16;
24 } else {
25 tmp &= 0xffff0000;
26 tmp |= val;
27 }
28
29 out_be32(reg, tmp);
30}
31
32static void enable_devices_ns_access(struct csu_ns_dev *ns_dev, uint32_t num)
33{
Xiubo Lie87f3b32014-11-21 17:40:58 +080034 int i;
35
Hou Zhiqiangc37fdbd2016-08-02 19:03:24 +080036 for (i = 0; i < num; i++)
37 set_devices_ns_access(ns_dev + i, ns_dev[i].val);
Xiubo Lie87f3b32014-11-21 17:40:58 +080038}
Mingkai Hu435acd82015-10-26 19:47:41 +080039
40void enable_layerscape_ns_access(void)
41{
42 enable_devices_ns_access(ns_dev, ARRAY_SIZE(ns_dev));
43}
Hou Zhiqiang664b6522016-08-02 19:03:26 +080044
45void set_pcie_ns_access(int pcie, u16 val)
46{
47 switch (pcie) {
48#ifdef CONFIG_PCIE1
49 case PCIE1:
50 set_devices_ns_access(&ns_dev[CSU_CSLX_PCIE1], val);
51 set_devices_ns_access(&ns_dev[CSU_CSLX_PCIE1_IO], val);
52 return;
53#endif
54#ifdef CONFIG_PCIE2
55 case PCIE2:
56 set_devices_ns_access(&ns_dev[CSU_CSLX_PCIE2], val);
57 set_devices_ns_access(&ns_dev[CSU_CSLX_PCIE2_IO], val);
58 return;
59#endif
60#ifdef CONFIG_PCIE3
61 case PCIE3:
62 set_devices_ns_access(&ns_dev[CSU_CSLX_PCIE3], val);
63 set_devices_ns_access(&ns_dev[CSU_CSLX_PCIE3_IO], val);
64 return;
65#endif
66 default:
67 debug("The PCIE%d doesn't exist!\n", pcie);
68 return;
69 }
70}