Skip to content

Commit 81a1f90

Browse files
dmaengine: ti: k3-udma-glue: Add function to parse channel by ID
The existing helper function of_k3_udma_glue_parse() fetches the DMA Channel thread ID from the device-tree node. This makes it necessary to have a device-tree node with the Channel thread IDs populated. However, in the case where the thread ID is known by alternate methods (an example being that of Firmware running on remote core sharing details of the thread IDs), there is no equivalent function to implement the functionality of the existing of_k3_udma_glue_parse() function. In such cases, the driver utilizing the DMA APIs might not even have a device-tree node to begin with, since it could be probed with other methods (RPMsg-Bus for example). Add the of_k3_udma_glue_parse_chn_by_id() helper function which accepts the thread ID as an argument, thereby making it unnecessary to have a device-tree node for obtaining the thread ID. Since of_k3_udma_glue_parse() and of_k3_udma_glue_parse_chn_by_id() share a lot of code in common, create a new function to handle the common code which is named as of_k3_udma_glue_parse_chn_common(). Signed-off-by: Siddharth Vadapalli <[email protected]> Acked-by: Peter Ujfalusi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 7510bf8 commit 81a1f90

File tree

1 file changed

+48
-25
lines changed

1 file changed

+48
-25
lines changed

drivers/dma/ti/k3-udma-glue.c

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,35 @@ static int of_k3_udma_glue_parse(struct device_node *udmax_np,
111111
return 0;
112112
}
113113

114+
static int of_k3_udma_glue_parse_chn_common(struct k3_udma_glue_common *common, u32 thread_id,
115+
bool tx_chn)
116+
{
117+
if (tx_chn && !(thread_id & K3_PSIL_DST_THREAD_ID_OFFSET))
118+
return -EINVAL;
119+
120+
if (!tx_chn && (thread_id & K3_PSIL_DST_THREAD_ID_OFFSET))
121+
return -EINVAL;
122+
123+
/* get psil endpoint config */
124+
common->ep_config = psil_get_ep_config(thread_id);
125+
if (IS_ERR(common->ep_config)) {
126+
dev_err(common->dev,
127+
"No configuration for psi-l thread 0x%04x\n",
128+
thread_id);
129+
return PTR_ERR(common->ep_config);
130+
}
131+
132+
common->epib = common->ep_config->needs_epib;
133+
common->psdata_size = common->ep_config->psd_size;
134+
135+
if (tx_chn)
136+
common->dst_thread = thread_id;
137+
else
138+
common->src_thread = thread_id;
139+
140+
return 0;
141+
}
142+
114143
static int of_k3_udma_glue_parse_chn(struct device_node *chn_np,
115144
const char *name, struct k3_udma_glue_common *common,
116145
bool tx_chn)
@@ -153,38 +182,32 @@ static int of_k3_udma_glue_parse_chn(struct device_node *chn_np,
153182
common->atype_asel = dma_spec.args[1];
154183
}
155184

156-
if (tx_chn && !(thread_id & K3_PSIL_DST_THREAD_ID_OFFSET)) {
157-
ret = -EINVAL;
158-
goto out_put_spec;
159-
}
185+
ret = of_k3_udma_glue_parse_chn_common(common, thread_id, tx_chn);
160186

161-
if (!tx_chn && (thread_id & K3_PSIL_DST_THREAD_ID_OFFSET)) {
162-
ret = -EINVAL;
163-
goto out_put_spec;
164-
}
187+
out_put_spec:
188+
of_node_put(dma_spec.np);
189+
return ret;
190+
}
165191

166-
/* get psil endpoint config */
167-
common->ep_config = psil_get_ep_config(thread_id);
168-
if (IS_ERR(common->ep_config)) {
169-
dev_err(common->dev,
170-
"No configuration for psi-l thread 0x%04x\n",
171-
thread_id);
172-
ret = PTR_ERR(common->ep_config);
173-
goto out_put_spec;
174-
}
192+
static int
193+
of_k3_udma_glue_parse_chn_by_id(struct device_node *udmax_np, struct k3_udma_glue_common *common,
194+
bool tx_chn, u32 thread_id)
195+
{
196+
int ret = 0;
175197

176-
common->epib = common->ep_config->needs_epib;
177-
common->psdata_size = common->ep_config->psd_size;
198+
if (unlikely(!udmax_np))
199+
return -EINVAL;
178200

179-
if (tx_chn)
180-
common->dst_thread = thread_id;
181-
else
182-
common->src_thread = thread_id;
201+
ret = of_k3_udma_glue_parse(udmax_np, common);
202+
if (ret)
203+
goto out_put_spec;
204+
205+
ret = of_k3_udma_glue_parse_chn_common(common, thread_id, tx_chn);
183206

184207
out_put_spec:
185-
of_node_put(dma_spec.np);
208+
of_node_put(udmax_np);
186209
return ret;
187-
};
210+
}
188211

189212
static void k3_udma_glue_dump_tx_chn(struct k3_udma_glue_tx_channel *tx_chn)
190213
{

0 commit comments

Comments
 (0)