From patchwork Thu Sep 28 13:11:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 114430 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp727949qgf; Thu, 28 Sep 2017 06:14:46 -0700 (PDT) X-Google-Smtp-Source: AOwi7QArbawcFd3DyiVQKtjq2q4v7RJdwxmYnFRxlqhtT+8UUkNJXbaYGtWvX6ca1/oCR6luLaxV X-Received: by 10.159.246.5 with SMTP id b5mr4030182pls.109.1506604486045; Thu, 28 Sep 2017 06:14:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506604486; cv=none; d=google.com; s=arc-20160816; b=QjqO81IlzwHiClbIthruWYq+gvFBWVAyR/RaXq0982AmfKY5kRHsVPAuDhS/HT+FQQ 9OiaGIzKLm9fMMVCzWNbzUHxrWD0goKsNakYC7S+bbI0AUWdIL3poW66Aamc8QBdgVsh fRbH5/y5rOCdtTWe7KQKLkgKcM+qinethMwSyZltOuzDtgFooNUjGxA56V3Hmgh5jQbL NFT9EteMqV8AFGyynHIhbIpvfAAAKFF9C5+sW4SEBvVi1GhktipBEIWoO+Ja4L+ykec8 c+yoEQlApN6/nT7EIkZoDNPDHoFIq2HxQuxxKxOfFRkF+ikK2pq/Z3qrtLbJTldGmtQ+ Il1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=VK4a7JMGqOjUhjFdHyDymRbkOBu7WKw4YJWkrvdFWuk=; b=g8xBMXHhj+2Qm3JSoDJw3xfdsHIzTZZGnJ2oLytVLw0BmU8TH4pd2a16LE9KFDAJAp NHW98gMEuXoMv1dalV9BVlf3auF1b8tWRU0gc2OpYg2zQelx0RrhV3YhCN/uTc8D+6HG GLqg5dPVXeom4Hrx+5oH9G+wZTM04pubrt5O8dbr4yt2yEUMLebYUjIzkKwxv0I9N0+z /oAkk+cbBjSu0JJ+ssCHNN9LR7qL8Bwhno+jBVDLXxMAoLDrRR95sG/QpfMEtBGbIlsj CbGczgjv7MEOPeGbtJ5jvf/YqcGKRpqhEEZSRx9V9HIeK9hos3hFp9QVdjioHkdjcx1e z3EQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 q11si1378625pli.749.2017.09.28.06.14.45; Thu, 28 Sep 2017 06:14:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753317AbdI1NOn (ORCPT + 6 others); Thu, 28 Sep 2017 09:14:43 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:57198 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752079AbdI1NOm (ORCPT ); Thu, 28 Sep 2017 09:14:42 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 45EB9199B; Thu, 28 Sep 2017 06:14:42 -0700 (PDT) Received: from e107155-lin.cambridge.arm.com (unknown [10.1.210.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 334F53F483; Thu, 28 Sep 2017 06:14:40 -0700 (PDT) From: Sudeep Holla To: ALKML , LKML , DTML Cc: Sudeep Holla , Roy Franz , Harb Abdulhamid , Nishanth Menon , Arnd Bergmann , Loc Ho , Alexey Klimov , Ryan Harkin , Jassi Brar Subject: [PATCH v3 16/22] firmware: arm_scmi: add arm_mhu specific mailbox interface Date: Thu, 28 Sep 2017 14:11:40 +0100 Message-Id: <1506604306-20739-17-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506604306-20739-1-git-send-email-sudeep.holla@arm.com> References: <1506604306-20739-1-git-send-email-sudeep.holla@arm.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This patch adds ARM MHU specific mailbox interface for SCMI. Cc: Arnd Bergmann Signed-off-by: Sudeep Holla --- drivers/firmware/arm_scmi/Makefile | 1 + drivers/firmware/arm_scmi/arm_mhu_if.c | 106 +++++++++++++++++++++++++++++++++ drivers/firmware/arm_scmi/driver.c | 3 + drivers/firmware/arm_scmi/mbox_if.h | 3 + 4 files changed, 113 insertions(+) create mode 100644 drivers/firmware/arm_scmi/arm_mhu_if.c -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile index 733157c5b4e2..7fb026c71833 100644 --- a/drivers/firmware/arm_scmi/Makefile +++ b/drivers/firmware/arm_scmi/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_ARM_SCMI_PROTOCOL) = arm_scmi.o arm_scmi-y = base.o clock.o driver.o mbox_if.o perf.o power.o sensors.o +arm_scmi-$(CONFIG_ARM_MHU) += arm_mhu_if.o diff --git a/drivers/firmware/arm_scmi/arm_mhu_if.c b/drivers/firmware/arm_scmi/arm_mhu_if.c new file mode 100644 index 000000000000..2271a4811378 --- /dev/null +++ b/drivers/firmware/arm_scmi/arm_mhu_if.c @@ -0,0 +1,106 @@ +/* + * System Control and Management Interface (SCMI) MHU mailbox interface + * + * Copyright (C) 2017 ARM Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include +#include + +#include "common.h" +#include "mbox_if.h" + +union mhu_data { + void *ptr; + u32 val; +}; + +static void mhu_tx_prepare(struct mbox_client *cl, void *m) +{ + struct scmi_chan_info *cinfo = client_to_scmi_chan_info(cl); + union mhu_data tmp; + + scmi_generic_tx_prepare(cinfo, m); + + /* clear only the relavant bit */ + tmp.ptr = cinfo->priv; + *(u32 *)m &= tmp.val; +} + +static void mhu_rx_callback(struct mbox_client *cl, void *m) +{ + struct scmi_chan_info *cinfo = client_to_scmi_chan_info(cl); + + scmi_generic_rx_callback(cinfo); +} + +static int mhu_mbox_request_channel(struct scmi_chan_info *cinfo, int index) +{ + int ret = 0; + struct mbox_client *cl = &cinfo->cl; + struct device_node *np = cl->dev->of_node; + union mhu_data tmp = {0}; + + if (index != 0 && index != 1) /* Tx = 0, Rx =1 */ + return -EINVAL; + + cl->rx_callback = mhu_rx_callback; + cl->tx_prepare = mhu_tx_prepare; + + ret = of_property_read_u32_index(np, "mbox-data", index, &tmp.val); + if (ret) + return ret; + + cinfo->chan = mbox_request_channel(cl, index); + if (IS_ERR(cinfo->chan)) + ret = PTR_ERR(cinfo->chan); + + cinfo->priv = tmp.ptr; + + return ret; +} + +static int mhu_mbox_send_message(struct scmi_chan_info *cinfo, void *msg) +{ + struct scmi_xfer *t = msg; + + t->con_priv = cinfo->priv; + + return mbox_send_message(cinfo->chan, msg); +} + +static void mhu_mbox_client_txdone(struct scmi_chan_info *cinfo, int r) +{ + mbox_client_txdone(cinfo->chan, r); +} + +static void mhu_mbox_free_channel(struct scmi_chan_info *cinfo) +{ + mbox_free_channel(cinfo->chan); +} + +static struct scmi_mbox_ops arm_mhu_mbox_ops = { + .request_channel = mhu_mbox_request_channel, + .send_message = mhu_mbox_send_message, + .client_txdone = mhu_mbox_client_txdone, + .free_channel = mhu_mbox_free_channel, +}; + +const struct scmi_desc mhu_scmi_desc = { + .max_rx_timeout_ms = 30, + .max_msg = 20, + .max_msg_size = 128, + .mbox_ops = &arm_mhu_mbox_ops, +}; diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 97285a22dfaa..bdc9c566e6c1 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -648,6 +648,9 @@ EXPORT_SYMBOL_GPL(devm_scmi_handle_get); /* Each compatible listed below must have descriptor associated with it */ static const struct of_device_id scmi_of_match[] = { { .compatible = "arm,scmi", .data = &scmi_generic_desc }, +#if IS_REACHABLE(CONFIG_ARM_MHU) + { .compatible = "arm,mhu-scmi", .data = &mhu_scmi_desc }, +#endif { /* Sentinel */ }, }; diff --git a/drivers/firmware/arm_scmi/mbox_if.h b/drivers/firmware/arm_scmi/mbox_if.h index 02baa73e8613..a23fc6d7a91f 100644 --- a/drivers/firmware/arm_scmi/mbox_if.h +++ b/drivers/firmware/arm_scmi/mbox_if.h @@ -66,3 +66,6 @@ void scmi_generic_rx_callback(struct scmi_chan_info *cinfo); void scmi_generic_tx_prepare(struct scmi_chan_info *cinfo, void *m); extern const struct scmi_desc scmi_generic_desc; +#if IS_REACHABLE(CONFIG_ARM_MHU) +extern const struct scmi_desc mhu_scmi_desc; +#endif