Re: [PATCH V1 2/3] rpmsg: glink: Add support to handle signals command
From: Matthias Kaehlcke
Date: Wed Nov 24 2021 - 14:18:05 EST
On Thu, Sep 30, 2021 at 09:02:03PM +0530, Deepak Kumar Singh wrote:
> Remote peripherals send signal notifications over glink with commandID 15.
>
> Add support to send and receive the signal command and convert the signals
> from NATIVE to TIOCM while receiving and vice versa while sending.
>
> Signed-off-by: Chris Lew <clew@xxxxxxxxxxxxxx>
> Signed-off-by: Deepak Kumar Singh <deesin@xxxxxxxxxxxxxx>
> ---
> drivers/rpmsg/qcom_glink_native.c | 75 +++++++++++++++++++++++++++++++++++++++
> 1 file changed, 75 insertions(+)
>
> diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c
> index 05533c7..384fcd2 100644
> --- a/drivers/rpmsg/qcom_glink_native.c
> +++ b/drivers/rpmsg/qcom_glink_native.c
>
> ...
>
> +static int qcom_glink_handle_signals(struct qcom_glink *glink,
> + unsigned int rcid, unsigned int sigs)
> +{
> + struct glink_channel *channel;
> + unsigned long flags;
> +
> + spin_lock_irqsave(&glink->idr_lock, flags);
> + channel = idr_find(&glink->rcids, rcid);
> + spin_unlock_irqrestore(&glink->idr_lock, flags);
> + if (!channel) {
> + dev_err(glink->dev, "signal for non-existing channel\n");
> + return -EINVAL;
> + }
> +
> + /* convert signals from NATIVE to TIOCM */
> + if (sigs & NATIVE_DTR_SIG)
> + sigs |= TIOCM_DSR;
> + if (sigs & NATIVE_CTS_SIG)
> + sigs |= TIOCM_CTS;
> + if (sigs & NATIVE_CD_SIG)
> + sigs |= TIOCM_CD;
> + if (sigs & NATIVE_RI_SIG)
> + sigs |= TIOCM_RI;
> + sigs &= 0x0fff;
'sigs' is only used when the channel has a signal handler, hence you could
return before the above block if there is no signal handler and remove the
condition below.
> +
> + if (channel->ept.sig_cb)
> + channel->ept.sig_cb(channel->ept.rpdev, channel->ept.priv, sigs);
> +
> + return 0;
> +}