1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Freescale Semiconductor, Inc.
7 #include <asm/arch/imx-regs.h>
8 #include <asm/mach-imx/rdc-sema.h>
9 #include <asm/arch/imx-rdc.h>
10 #include <linux/errno.h>
13 * Check if the RDC Semaphore is required for this peripheral.
15 static inline int imx_rdc_check_sema_required(int per_id)
17 struct rdc_regs *imx_rdc = (struct rdc_regs *)RDC_BASE_ADDR;
20 reg = readl(&imx_rdc->pdap[per_id]);
23 * Intial value or this peripheral is assigned to only one domain
25 if (!(reg & RDC_PDAP_SREQ_MASK))
32 * Check the peripheral read / write access permission on Domain [dom_id].
34 int imx_rdc_check_permission(int per_id, int dom_id)
36 struct rdc_regs *imx_rdc = (struct rdc_regs *)RDC_BASE_ADDR;
39 reg = readl(&imx_rdc->pdap[per_id]);
40 if (!(reg & RDC_PDAP_DRW_MASK(dom_id)))
41 return -EACCES; /*No access*/
47 * Lock up the RDC semaphore for this peripheral if semaphore is required.
49 int imx_rdc_sema_lock(int per_id)
51 struct rdc_sema_regs *imx_rdc_sema;
55 ret = imx_rdc_check_sema_required(per_id);
59 if (per_id < SEMA_GATES_NUM)
60 imx_rdc_sema = (struct rdc_sema_regs *)SEMAPHORE1_BASE_ADDR;
62 imx_rdc_sema = (struct rdc_sema_regs *)SEMAPHORE2_BASE_ADDR;
65 writeb(RDC_SEMA_PROC_ID,
66 &imx_rdc_sema->gate[per_id % SEMA_GATES_NUM]);
67 reg = readb(&imx_rdc_sema->gate[per_id % SEMA_GATES_NUM]);
68 if ((reg & RDC_SEMA_GATE_GTFSM_MASK) == RDC_SEMA_PROC_ID)
69 break; /* Get the Semaphore*/
76 * Unlock the RDC semaphore for this peripheral if main CPU is the
79 int imx_rdc_sema_unlock(int per_id)
81 struct rdc_sema_regs *imx_rdc_sema;
85 ret = imx_rdc_check_sema_required(per_id);
89 if (per_id < SEMA_GATES_NUM)
90 imx_rdc_sema = (struct rdc_sema_regs *)SEMAPHORE1_BASE_ADDR;
92 imx_rdc_sema = (struct rdc_sema_regs *)SEMAPHORE2_BASE_ADDR;
94 reg = readb(&imx_rdc_sema->gate[per_id % SEMA_GATES_NUM]);
95 if ((reg & RDC_SEMA_GATE_GTFSM_MASK) != RDC_SEMA_PROC_ID)
96 return -EACCES; /*Not the semaphore owner */
98 writeb(0x0, &imx_rdc_sema->gate[per_id % SEMA_GATES_NUM]);
104 * Setup RDC setting for one peripheral
106 int imx_rdc_setup_peri(rdc_peri_cfg_t p)
108 struct rdc_regs *imx_rdc = (struct rdc_regs *)RDC_BASE_ADDR;
111 u32 peri_id = p & RDC_PERI_MASK;
112 u32 domain = (p & RDC_DOMAIN_MASK) >> RDC_DOMAIN_SHIFT_BASE;
114 /* No domain assigned */
120 share_count = (domain & 0x3)
121 + ((domain >> 2) & 0x3)
122 + ((domain >> 4) & 0x3)
123 + ((domain >> 6) & 0x3);
125 if (share_count > 0x3)
126 reg |= RDC_PDAP_SREQ_MASK;
128 writel(reg, &imx_rdc->pdap[peri_id]);
134 * Setup RDC settings for multiple peripherals
136 int imx_rdc_setup_peripherals(rdc_peri_cfg_t const *peripherals_list,
139 rdc_peri_cfg_t const *p = peripherals_list;
142 for (i = 0; i < count; i++) {
143 ret = imx_rdc_setup_peri(*p);
153 * Setup RDC setting for one master
155 int imx_rdc_setup_ma(rdc_ma_cfg_t p)
157 struct rdc_regs *imx_rdc = (struct rdc_regs *)RDC_BASE_ADDR;
158 u32 master_id = (p & RDC_MASTER_MASK) >> RDC_MASTER_SHIFT;
159 u32 domain = (p & RDC_DOMAIN_MASK) >> RDC_DOMAIN_SHIFT_BASE;
161 writel((domain & RDC_MDA_DID_MASK), &imx_rdc->mda[master_id]);
167 * Setup RDC settings for multiple masters
169 int imx_rdc_setup_masters(rdc_ma_cfg_t const *masters_list, unsigned count)
171 rdc_ma_cfg_t const *p = masters_list;
174 for (i = 0; i < count; i++) {
175 ret = imx_rdc_setup_ma(*p);