]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/arm/imx-common/rdc-sema.c
dcb5c419ee712d026598e8bfc74e24432b88d7ed
2 * Copyright (C) 2016 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
8 #include <asm/arch/imx-regs.h>
9 #include <asm/imx-common/rdc-sema.h>
10 #include <asm/arch/imx-rdc.h>
11 #include <asm-generic/errno.h>
14 * Check if the RDC Semaphore is required for this peripheral.
16 static inline int imx_rdc_check_sema_required(int per_id
)
18 struct rdc_regs
*imx_rdc
= (struct rdc_regs
*)RDC_BASE_ADDR
;
21 reg
= readl(&imx_rdc
->pdap
[per_id
]);
24 * Intial value or this peripheral is assigned to only one domain
26 if (!(reg
& RDC_PDAP_SREQ_MASK
))
33 * Check the peripheral read / write access permission on Domain [dom_id].
35 int imx_rdc_check_permission(int per_id
, int dom_id
)
37 struct rdc_regs
*imx_rdc
= (struct rdc_regs
*)RDC_BASE_ADDR
;
40 reg
= readl(&imx_rdc
->pdap
[per_id
]);
41 if (!(reg
& RDC_PDAP_DRW_MASK(dom_id
)))
42 return -EACCES
; /*No access*/
48 * Lock up the RDC semaphore for this peripheral if semaphore is required.
50 int imx_rdc_sema_lock(int per_id
)
52 struct rdc_sema_regs
*imx_rdc_sema
;
56 ret
= imx_rdc_check_sema_required(per_id
);
60 if (per_id
< SEMA_GATES_NUM
)
61 imx_rdc_sema
= (struct rdc_sema_regs
*)SEMAPHORE1_BASE_ADDR
;
63 imx_rdc_sema
= (struct rdc_sema_regs
*)SEMAPHORE2_BASE_ADDR
;
66 writeb(RDC_SEMA_PROC_ID
,
67 &imx_rdc_sema
->gate
[per_id
% SEMA_GATES_NUM
]);
68 reg
= readb(&imx_rdc_sema
->gate
[per_id
% SEMA_GATES_NUM
]);
69 if ((reg
& RDC_SEMA_GATE_GTFSM_MASK
) == RDC_SEMA_PROC_ID
)
70 break; /* Get the Semaphore*/
77 * Unlock the RDC semaphore for this peripheral if main CPU is the
80 int imx_rdc_sema_unlock(int per_id
)
82 struct rdc_sema_regs
*imx_rdc_sema
;
86 ret
= imx_rdc_check_sema_required(per_id
);
90 if (per_id
< SEMA_GATES_NUM
)
91 imx_rdc_sema
= (struct rdc_sema_regs
*)SEMAPHORE1_BASE_ADDR
;
93 imx_rdc_sema
= (struct rdc_sema_regs
*)SEMAPHORE2_BASE_ADDR
;
95 reg
= readb(&imx_rdc_sema
->gate
[per_id
% SEMA_GATES_NUM
]);
96 if ((reg
& RDC_SEMA_GATE_GTFSM_MASK
) != RDC_SEMA_PROC_ID
)
97 return 1; /*Not the semaphore owner */
99 writeb(0x0, &imx_rdc_sema
->gate
[per_id
% SEMA_GATES_NUM
]);
105 * Setup RDC setting for one peripheral
107 int imx_rdc_setup_peri(rdc_peri_cfg_t p
)
109 struct rdc_regs
*imx_rdc
= (struct rdc_regs
*)RDC_BASE_ADDR
;
112 u32 peri_id
= p
& RDC_PERI_MASK
;
113 u32 domain
= (p
& RDC_DOMAIN_MASK
) >> RDC_DOMAIN_SHIFT_BASE
;
115 /* No domain assigned */
121 share_count
= (domain
& 0x3)
122 + ((domain
>> 2) & 0x3)
123 + ((domain
>> 4) & 0x3)
124 + ((domain
>> 6) & 0x3);
126 if (share_count
> 0x3)
127 reg
|= RDC_PDAP_SREQ_MASK
;
129 writel(reg
, &imx_rdc
->pdap
[peri_id
]);
135 * Setup RDC settings for multiple peripherals
137 int imx_rdc_setup_peripherals(rdc_peri_cfg_t
const *peripherals_list
,
140 rdc_peri_cfg_t
const *p
= peripherals_list
;
143 for (i
= 0; i
< count
; i
++) {
144 ret
= imx_rdc_setup_peri(*p
);
154 * Setup RDC setting for one master
156 int imx_rdc_setup_ma(rdc_ma_cfg_t p
)
158 struct rdc_regs
*imx_rdc
= (struct rdc_regs
*)RDC_BASE_ADDR
;
159 u32 master_id
= (p
& RDC_MASTER_MASK
) >> RDC_MASTER_SHIFT
;
160 u32 domain
= (p
& RDC_DOMAIN_MASK
) >> RDC_DOMAIN_SHIFT_BASE
;
162 writel((domain
& RDC_MDA_DID_MASK
), &imx_rdc
->mda
[master_id
]);
168 * Setup RDC settings for multiple masters
170 int imx_rdc_setup_masters(rdc_ma_cfg_t
const *masters_list
, unsigned count
)
172 rdc_ma_cfg_t
const *p
= masters_list
;
175 for (i
= 0; i
< count
; i
++) {
176 ret
= imx_rdc_setup_ma(*p
);