Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp67041ybc; Fri, 22 Nov 2019 02:09:45 -0800 (PST) X-Google-Smtp-Source: APXvYqx8jfFiPLHidP1VRi+dTF87msal5vZ1aRxXiajU5Gw8EozYcrSe41hPaNV80bXxukYSfi4q X-Received: by 2002:a17:907:40f2:: with SMTP id no2mr21407482ejb.250.1574417384931; Fri, 22 Nov 2019 02:09:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574417384; cv=none; d=google.com; s=arc-20160816; b=dQB2ljWzUva5isH7+ktYF2N8lfSd6xgObKzSjXyqjTQSaaUdh+56SE8fi9wIOzWkoE ZvveOg37nhDiarbNyYYpy3yet8ywkhU3z8Di9VjqfMKzAhbmExK/Wgp9EFOrS2i+hJjL 18/Y/r5JmVJfhnzquDEITi1ksQxeieeBAnVmCRCKwCzLU/bVqAkiy9/e1NiBBB4AhMX3 Fyhg4hoy7fJEn4MidyWv1jCgRa7WJX3DYFmqA5onPsJJdEUUZ/ae+fAWyk6y17iroCAy OcemXwR5J6X8S677IzkvkLXjeOVJ4QJkLR/qJHjdd+G6WfzckX+smsfe5fvdSkJnNC7E IPuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:feedback-id:references:in-reply-to :message-id:date:subject:cc:to:from:dmarc-filter:dkim-signature :dkim-signature; bh=Ox5MgMOTNSBLQyF3rJuVwWtl8CpX3wcP6bUbF6tENZk=; b=KbmDs2RkhYVZwwUl9GlguDJ1nic4WWwsAGOfi80yHDJnSmLngZv5NVaavBlkMAY0Bp WnL3Zsxi268tcnkuzr3I9BmOr2A1UeFLVUuuqJUWdVqV31I8iTUvlZuAtHZJGzBgM5V3 D7jjIwxkiSvXJ4wTXUGyQr1E8qe+fqzrqbfK40SyDvCzHhSUE0gxPAi6XeDbQDtbT82u 8IjWGbvngkVHUelkbt+TpV1cebJG0iepWcL/iyU57KmaZYJl/g+MolkE4uRWuvC7cRB6 PEfWJD+plOn++YUCkJJwig9mMS0o/Na6m1DLfF++KBMVDVZiXfkqSvkOJYcSIB3rumPl swWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=zsmsymrwgfyinv5wlfyidntwsjeeldzt header.b=bTcMoO3h; dkim=pass header.i=@amazonses.com header.s=gdwg2y3kokkkj5a55z2ilkup5wp5hhxx header.b=gWR0nAKy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e58si4502479eda.7.2019.11.22.02.09.20; Fri, 22 Nov 2019 02:09:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=zsmsymrwgfyinv5wlfyidntwsjeeldzt header.b=bTcMoO3h; dkim=pass header.i=@amazonses.com header.s=gdwg2y3kokkkj5a55z2ilkup5wp5hhxx header.b=gWR0nAKy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727212AbfKVKG7 (ORCPT + 99 others); Fri, 22 Nov 2019 05:06:59 -0500 Received: from a27-188.smtp-out.us-west-2.amazonses.com ([54.240.27.188]:59618 "EHLO a27-188.smtp-out.us-west-2.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726568AbfKVKG7 (ORCPT ); Fri, 22 Nov 2019 05:06:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=zsmsymrwgfyinv5wlfyidntwsjeeldzt; d=codeaurora.org; t=1574417218; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; bh=Rk7nWGoRvkHeq5yw1JfVVIeVY65a6K5/gPi2ZUkgcJ8=; b=bTcMoO3hPOIwcVnNY2Yg5gLYLdBnaB5MvUt1epScGuK0dQ/q/3Ag+c0QOhyd1Sp6 MovwCixGCurFbu8/P/Dyprpfo15nRLLdAkwv3vN+hwby/Zq4rJNZ42ffz9Uwa0KnW/F glWWm1bbJtpS2jl1cXO5lq8cQMifXL1lsxEvHUVE= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=gdwg2y3kokkkj5a55z2ilkup5wp5hhxx; d=amazonses.com; t=1574417218; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:Feedback-ID; bh=Rk7nWGoRvkHeq5yw1JfVVIeVY65a6K5/gPi2ZUkgcJ8=; b=gWR0nAKysMbAfogGm847Axqx0lxG790Qn53qyTJqv05Ki2qcGWPt9q/mUAy4D2o6 Z/W63YG/dGveo/+HG8oQ5u1iz/1rRbtvwY6bjHH+k9R+/ru3y7eTbOZahAI3YG3QLwP WApupYOg9FcmhXOiM1rW8C2T1D2rYppZnyOK4a/c= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 56B9FC93001 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=aneela@codeaurora.org From: Arun Kumar Neelakantam To: ohad@wizery.com, bjorn.andersson@linaro.org, clew@codeaurora.org, sricharan@codeaurora.org Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Arun Kumar Neelakantam , Andy Gross , linux-arm-msm@vger.kernel.org (open list:ARM/QUALCOMM SUPPORT) Subject: [RESEND PATCH V4 2/4] rpmsg: glink: Add support to handle signals command Date: Fri, 22 Nov 2019 10:06:58 +0000 Message-ID: <0101016e92943c97-f6bb9eb4-8db9-4cc1-b1a0-29e99ec4579d-000000@us-west-2.amazonses.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1574417197-27817-1-git-send-email-aneela@codeaurora.org> References: <1574417197-27817-1-git-send-email-aneela@codeaurora.org> X-SES-Outgoing: 2019.11.22-54.240.27.188 Feedback-ID: 1.us-west-2.CZuq2qbDmUIuT3qdvXlRHZZCpfZqZ4GtG9v3VKgRyF0=:AmazonSES Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Arun Kumar Neelakantam --- drivers/rpmsg/qcom_glink_native.c | 126 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c index 0ff4cbe..59c80f9 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* + * Copyright (c) 2018, The Linux Foundation. * Copyright (c) 2016-2017, Linaro Ltd */ @@ -17,6 +18,7 @@ #include #include #include +#include #include #include @@ -150,6 +152,8 @@ enum { * @intent_req_lock: Synchronises multiple intent requests * @intent_req_result: Result of intent request * @intent_req_comp: Completion for intent_req signalling + * @lsigs: local side signals + * @rsigs: remote side signals */ struct glink_channel { struct rpmsg_endpoint ept; @@ -181,6 +185,10 @@ struct glink_channel { struct mutex intent_req_lock; bool intent_req_result; struct completion intent_req_comp; + + unsigned int lsigs; + unsigned int rsigs; + }; #define to_glink_channel(_ept) container_of(_ept, struct glink_channel, ept) @@ -201,9 +209,15 @@ struct glink_channel { #define RPM_CMD_TX_DATA_CONT 12 #define RPM_CMD_READ_NOTIF 13 #define RPM_CMD_RX_DONE_W_REUSE 14 +#define RPM_CMD_SIGNALS 15 #define GLINK_FEATURE_INTENTLESS BIT(1) +#define NATIVE_DTR_SIG BIT(31) +#define NATIVE_CTS_SIG BIT(30) +#define NATIVE_CD_SIG BIT(29) +#define NATIVE_RI_SIG BIT(28) + static void qcom_glink_rx_done_work(struct work_struct *work); static struct glink_channel *qcom_glink_alloc_channel(struct qcom_glink *glink, @@ -954,6 +968,76 @@ static int qcom_glink_rx_open_ack(struct qcom_glink *glink, unsigned int lcid) return 0; } +/** + * qcom_glink_send_signals() - convert a signal cmd to wire format and transmit + * @glink: The transport to transmit on. + * @channel: The glink channel + * @sigs: The signals to encode. + * + * Return: 0 on success or standard Linux error code. + */ +static int qcom_glink_send_signals(struct qcom_glink *glink, + struct glink_channel *channel, + u32 sigs) +{ + struct glink_msg msg; + + /* convert signals from TIOCM to NATIVE */ + sigs &= 0x0fff; + if (sigs & TIOCM_DTR) + sigs |= NATIVE_DTR_SIG; + if (sigs & TIOCM_RTS) + sigs |= NATIVE_CTS_SIG; + if (sigs & TIOCM_CD) + sigs |= NATIVE_CD_SIG; + if (sigs & TIOCM_RI) + sigs |= NATIVE_RI_SIG; + + msg.cmd = cpu_to_le16(RPM_CMD_SIGNALS); + msg.param1 = cpu_to_le16(channel->lcid); + msg.param2 = cpu_to_le32(sigs); + + return qcom_glink_tx(glink, &msg, sizeof(msg), NULL, 0, true); +} + +static int qcom_glink_handle_signals(struct qcom_glink *glink, + unsigned int rcid, unsigned int signals) +{ + struct glink_channel *channel; + unsigned long flags; + u32 old; + + 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; + } + + old = channel->rsigs; + + /* convert signals from NATIVE to TIOCM */ + if (signals & NATIVE_DTR_SIG) + signals |= TIOCM_DSR; + if (signals & NATIVE_CTS_SIG) + signals |= TIOCM_CTS; + if (signals & NATIVE_CD_SIG) + signals |= TIOCM_CD; + if (signals & NATIVE_RI_SIG) + signals |= TIOCM_RI; + signals &= 0x0fff; + + channel->rsigs = signals; + + if (channel->ept.sig_cb) { + channel->ept.sig_cb(channel->ept.rpdev, channel->ept.priv, + old, channel->rsigs); + } + + return 0; +} + static irqreturn_t qcom_glink_native_intr(int irq, void *data) { struct qcom_glink *glink = data; @@ -1015,6 +1099,10 @@ static irqreturn_t qcom_glink_native_intr(int irq, void *data) qcom_glink_handle_intent_req_ack(glink, param1, param2); qcom_glink_rx_advance(glink, ALIGN(sizeof(msg), 8)); break; + case RPM_CMD_SIGNALS: + qcom_glink_handle_signals(glink, param1, param2); + qcom_glink_rx_advance(glink, ALIGN(sizeof(msg), 8)); + break; default: dev_err(glink->dev, "unhandled rx cmd: %d\n", cmd); ret = -EINVAL; @@ -1320,6 +1408,42 @@ static int qcom_glink_trysend(struct rpmsg_endpoint *ept, void *data, int len) return __qcom_glink_send(channel, data, len, false); } +static int qcom_glink_get_sigs(struct rpmsg_endpoint *ept) +{ + struct glink_channel *channel = to_glink_channel(ept); + + return channel->rsigs; +} + +static int qcom_glink_set_sigs(struct rpmsg_endpoint *ept, u32 set, u32 clear) +{ + struct glink_channel *channel = to_glink_channel(ept); + struct qcom_glink *glink = channel->glink; + u32 sigs = channel->lsigs; + + if (set & TIOCM_DTR) + sigs |= TIOCM_DTR; + if (set & TIOCM_RTS) + sigs |= TIOCM_RTS; + if (set & TIOCM_CD) + sigs |= TIOCM_CD; + if (set & TIOCM_RI) + sigs |= TIOCM_RI; + + if (clear & TIOCM_DTR) + sigs &= ~TIOCM_DTR; + if (clear & TIOCM_RTS) + sigs &= ~TIOCM_RTS; + if (clear & TIOCM_CD) + sigs &= ~TIOCM_CD; + if (clear & TIOCM_RI) + sigs &= ~TIOCM_RI; + + channel->lsigs = sigs; + + return qcom_glink_send_signals(glink, channel, sigs); +} + /* * Finds the device_node for the glink child interested in this channel. */ @@ -1353,6 +1477,8 @@ static struct device_node *qcom_glink_match_channel(struct device_node *node, .destroy_ept = qcom_glink_destroy_ept, .send = qcom_glink_send, .trysend = qcom_glink_trysend, + .get_signals = qcom_glink_get_sigs, + .set_signals = qcom_glink_set_sigs, }; static void qcom_glink_rpdev_release(struct device *dev) -- 1.9.1