Lines Matching +full:ipi +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0
17 * scp_ipi_register() - register an ipi function
20 * @id: IPI ID
21 * @handler: IPI handler
22 * @priv: private data for IPI handler
24 * Register an ipi function to receive ipi interrupt from SCP.
26 * Returns 0 if ipi registers successfully, -error on error.
29 u32 id, in scp_ipi_register() argument
34 return -EPROBE_DEFER; in scp_ipi_register()
36 if (WARN_ON(id >= SCP_IPI_MAX) || WARN_ON(handler == NULL)) in scp_ipi_register()
37 return -EINVAL; in scp_ipi_register()
39 scp_ipi_lock(scp, id); in scp_ipi_register()
40 scp->ipi_desc[id].handler = handler; in scp_ipi_register()
41 scp->ipi_desc[id].priv = priv; in scp_ipi_register()
42 scp_ipi_unlock(scp, id); in scp_ipi_register()
49 * scp_ipi_unregister() - unregister an ipi function
52 * @id: IPI ID
54 * Unregister an ipi function to receive ipi interrupt from SCP.
56 void scp_ipi_unregister(struct mtk_scp *scp, u32 id) in scp_ipi_unregister() argument
61 if (WARN_ON(id >= SCP_IPI_MAX)) in scp_ipi_unregister()
64 scp_ipi_lock(scp, id); in scp_ipi_unregister()
65 scp->ipi_desc[id].handler = NULL; in scp_ipi_unregister()
66 scp->ipi_desc[id].priv = NULL; in scp_ipi_unregister()
67 scp_ipi_unlock(scp, id); in scp_ipi_unregister()
72 * scp_memcpy_aligned() - Copy src to dst, where dst is in SCP SRAM region.
90 i = 4 - (dst - ptr); in scp_memcpy_aligned()
92 memcpy((u8 *)&val + (4 - i), src, i); in scp_memcpy_aligned()
96 __iowrite32_copy(dst + i, src + i, (len - i) / 4); in scp_memcpy_aligned()
97 remain = (len - i) % 4; in scp_memcpy_aligned()
100 val = readl_relaxed(dst + len - remain); in scp_memcpy_aligned()
101 memcpy(&val, src + len - remain, remain); in scp_memcpy_aligned()
102 writel_relaxed(val, dst + len - remain); in scp_memcpy_aligned()
108 * scp_ipi_lock() - Lock before operations of an IPI ID
111 * @id: IPI ID
115 void scp_ipi_lock(struct mtk_scp *scp, u32 id) in scp_ipi_lock() argument
117 if (WARN_ON(id >= SCP_IPI_MAX)) in scp_ipi_lock()
119 mutex_lock(&scp->ipi_desc[id].lock); in scp_ipi_lock()
124 * scp_ipi_lock() - Unlock after operations of an IPI ID
127 * @id: IPI ID
131 void scp_ipi_unlock(struct mtk_scp *scp, u32 id) in scp_ipi_unlock() argument
133 if (WARN_ON(id >= SCP_IPI_MAX)) in scp_ipi_unlock()
135 mutex_unlock(&scp->ipi_desc[id].lock); in scp_ipi_unlock()
140 * scp_ipi_send() - send data from AP to scp.
143 * @id: IPI ID
148 * This function is thread-safe. When this function returns,
150 * When the processing completes, IPI handler registered
153 * Returns 0 if sending data successfully, -error on error.
155 int scp_ipi_send(struct mtk_scp *scp, u32 id, void *buf, unsigned int len, in scp_ipi_send() argument
158 struct mtk_share_obj __iomem *send_obj = scp->send_buf; in scp_ipi_send()
162 if (WARN_ON(id <= SCP_IPI_INIT) || WARN_ON(id >= SCP_IPI_MAX) || in scp_ipi_send()
163 WARN_ON(id == SCP_IPI_NS_SERVICE) || in scp_ipi_send()
164 WARN_ON(len > sizeof(send_obj->share_buf)) || WARN_ON(!buf)) in scp_ipi_send()
165 return -EINVAL; in scp_ipi_send()
167 ret = clk_prepare_enable(scp->clk); in scp_ipi_send()
169 dev_err(scp->dev, "failed to enable clock\n"); in scp_ipi_send()
173 mutex_lock(&scp->send_lock); in scp_ipi_send()
179 dev_err(scp->dev, "%s: IPI timeout!\n", __func__); in scp_ipi_send()
180 ret = -ETIMEDOUT; in scp_ipi_send()
183 } while (readl(scp->reg_base + scp->data->host_to_scp_reg)); in scp_ipi_send()
185 scp_memcpy_aligned(send_obj->share_buf, buf, len); in scp_ipi_send()
187 writel(len, &send_obj->len); in scp_ipi_send()
188 writel(id, &send_obj->id); in scp_ipi_send()
190 scp->ipi_id_ack[id] = false; in scp_ipi_send()
192 writel(scp->data->host_to_scp_int_bit, in scp_ipi_send()
193 scp->reg_base + scp->data->host_to_scp_reg); in scp_ipi_send()
198 ret = wait_event_timeout(scp->ack_wq, in scp_ipi_send()
199 scp->ipi_id_ack[id], in scp_ipi_send()
201 scp->ipi_id_ack[id] = false; in scp_ipi_send()
202 if (WARN(!ret, "scp ipi %d ack time out !", id)) in scp_ipi_send()
203 ret = -EIO; in scp_ipi_send()
209 mutex_unlock(&scp->send_lock); in scp_ipi_send()
210 clk_disable_unprepare(scp->clk); in scp_ipi_send()
217 MODULE_DESCRIPTION("MediaTek scp IPI interface");