From patchwork Wed Nov 15 14:10:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 118959 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4365725qgn; Wed, 15 Nov 2017 06:14:11 -0800 (PST) X-Google-Smtp-Source: AGs4zMYYP9M+aRvjEJvt8Ihgvpn9yvzxJyl2ITne5qVDCramQGTEhqb22WyQ4w/j8PJfHPhyaJQA X-Received: by 10.98.76.90 with SMTP id z87mr14117807pfa.194.1510755251620; Wed, 15 Nov 2017 06:14:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510755251; cv=none; d=google.com; s=arc-20160816; b=t+xObY8vgC25u4FGy9xb7g2bGH75cG0rmpP/LvUTLQFWrha+8/lRRpbJsVqE2AcIad iCrX28UxxIAwS6HEJS/5xh6hACBFDA5iGZ0ERZ9vbtB/PunyTqjafrcyAUuQPdMvkwZZ lwPm9BL3wGn/d0b+iZWxAI+PUt6GE1x7KLhH/6iT4N/zaiPpyhNV3mLqU5u2X/169J/8 hvqpWX/Ups6cenSqQmJ0P2Luj6+LJdjvzs5k05Sy2L0gXpyfXWoRoZxl8Akz8zSZQ0VW qKam4o67epFNW92dzx7Vg8IcZFGfs/hYX65bp23UR4K0WyOsiunDM+iYykKvbGENN7jc KMfw== 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:dkim-signature:arc-authentication-results; bh=/rjgEZawIQntl4tZIsGQnGk7eXaavM/8aSTkjiKHp2s=; b=QIArbhtNOuSzGqOqe0UYPfLkVo4R/WcU4402BzI309QMvPzsQoooHeQtTwHcT8RCW+ TxRxJBhnKxw+upP/rxpuaRhgEAliNuFf3wUoMeo68YpMzUvp1Wn1RlLu9t5OP5qyxvR6 kvYptwTkXaR9u3eOGcijweMDj7v6elz5MxolPh7M614B+GA5XvC+gqB5uqwX/SeEZjJE xnQyEWKzlnaa80TI6cyYzJRkJTaonieCeY0wo12WyQGNjcaV50jvX9ttJWdOBTc81lYH 9S3qKpp5TUE3cKVtaBb6c+vGrkhX5ZHY6R1Ip8roqYNTqvrdNFzR/Wr+hkLMc0QH+8HC nagA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=GgoTevjY; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 135si1601027pgh.503.2017.11.15.06.14.11; Wed, 15 Nov 2017 06:14:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=GgoTevjY; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757323AbdKOOOH (ORCPT + 10 others); Wed, 15 Nov 2017 09:14:07 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:55029 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757271AbdKOONd (ORCPT ); Wed, 15 Nov 2017 09:13:33 -0500 Received: by mail-wr0-f193.google.com with SMTP id l22so20557600wrc.11 for ; Wed, 15 Nov 2017 06:13:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1Shk3HB+/o90xMcmE9oUAL57FgciUrEF3MQbNYzoRWo=; b=GgoTevjYQC7p4R18Ie5+pfzSYuD6TblH7SN5n9+VtQmtWfaAOyo9taV5x2OPxg6zfE 7VwAziLLZDRwQOEAstSJPJwOx0CXcjcMPTeYTV55ZNcpBJ/47806uHpirsuqSEx8FsqD vuiyMq4WMBeD5PNIgih5A2xOtbLCUQtAQS9XU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1Shk3HB+/o90xMcmE9oUAL57FgciUrEF3MQbNYzoRWo=; b=PcgarfL7DvUXcOP7kl76VvzfCq/fDHw7UzOHUbcnOTAw/uQAIhzhjd59kCx2EnH56l Wt/BWXPw72to7osR+qX+z8sdZ0D62En0uUypQx1BnqHfBrn8XvNO3ILtme1BhwNJWF7t q1Ix1eekIgQKrRmDXcUrHR4nH2YVZpQsvFqbIuDSOV0zIdHqaxQQSFHz1uPfQ0plPsvQ xh++6GeMEiybesCenPxoI0+naF88ZWBYUMEOJSs1pNVQ7a1nbEk2E1jdfJ6coaPYMivi obxHCdBLDH63LEN4CLBTdpGNpLRWngw8B9OjbbytK2ZoJoDh5d9eVC90tDJef4K0wVoL vbRA== X-Gm-Message-State: AJaThX6E/+3fap1L1cUCEDglTGY5Oig5fA0uSEua5AbjdYSOgSTq4ISH wO5paud2W3cqaqvaGdJ9BXpGAg== X-Received: by 10.223.177.220 with SMTP id r28mr12444364wra.13.1510755212060; Wed, 15 Nov 2017 06:13:32 -0800 (PST) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id m11sm56707wrf.56.2017.11.15.06.13.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Nov 2017 06:13:31 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org, broonie@kernel.org, alsa-devel@alsa-project.org Cc: sdharia@codeaurora.org, bp@suse.de, poeschel@lemonage.de, treding@nvidia.com, andreas.noever@gmail.com, alan@linux.intel.com, mathieu.poirier@linaro.org, daniel@ffwll.ch, jkosina@suse.cz, sharon.dvir1@mail.huji.ac.il, joe@perches.com, davem@davemloft.net, james.hogan@imgtec.com, michael.opdenacker@free-electrons.com, robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, vinod.koul@intel.com, arnd@arndb.de, Srinivas Kandagatla Subject: [PATCH v7 05/13] slimbus: core: add support to device tree helper Date: Wed, 15 Nov 2017 14:10:35 +0000 Message-Id: <20171115141043.29202-6-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171115141043.29202-1-srinivas.kandagatla@linaro.org> References: <20171115141043.29202-1-srinivas.kandagatla@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Srinivas Kandagatla This patch adds support to parse slim devices from device tree. Signed-off-by: Srinivas Kandagatla --- drivers/slimbus/core.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) -- 2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" 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/slimbus/core.c b/drivers/slimbus/core.c index d31a9c4fe7e9..f7b14961c7e3 100644 --- a/drivers/slimbus/core.c +++ b/drivers/slimbus/core.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "slimbus.h" @@ -128,6 +129,9 @@ static int slim_add_device(struct slim_controller *ctrl, sbdev->dev.driver = NULL; sbdev->ctrl = ctrl; + if (node) + sbdev->dev.of_node = of_node_get(node); + dev_set_name(&sbdev->dev, "%x:%x:%x:%x", sbdev->e_addr.manf_id, sbdev->e_addr.prod_code, @@ -160,6 +164,50 @@ static struct slim_device *slim_alloc_device(struct slim_controller *ctrl, return sbdev; } +static void of_register_slim_devices(struct slim_controller *ctrl) +{ + struct device *dev = ctrl->dev; + struct device_node *node; + + if (!ctrl->dev->of_node) + return; + + for_each_child_of_node(ctrl->dev->of_node, node) { + struct slim_device *sbdev; + struct slim_eaddr e_addr; + const char *compat = NULL; + int reg[2], ret; + int manf_id, prod_code; + + compat = of_get_property(node, "compatible", NULL); + if (!compat) + continue; + + ret = sscanf(compat, "slim%x,%x", &manf_id, &prod_code); + if (ret != 2) { + dev_err(dev, "Manf ID & Product code not found %s\n", + compat); + continue; + } + + ret = of_property_read_u32_array(node, "reg", reg, 2); + if (ret) { + dev_err(dev, "Device and Instance id not found:%d\n", + ret); + continue; + } + + e_addr.dev_index = reg[0]; + e_addr.instance = reg[1]; + e_addr.manf_id = manf_id; + e_addr.prod_code = prod_code; + + sbdev = slim_alloc_device(ctrl, &e_addr, node); + if (!sbdev) + continue; + } +} + /* * slim_register_controller() - Controller bring-up and registration. * @@ -191,6 +239,8 @@ int slim_register_controller(struct slim_controller *ctrl) dev_dbg(ctrl->dev, "Bus [%s] registered:dev:%p\n", ctrl->name, ctrl->dev); + of_register_slim_devices(ctrl); + return 0; } EXPORT_SYMBOL_GPL(slim_register_controller); From patchwork Wed Nov 15 14:10:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 118958 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4365676qgn; Wed, 15 Nov 2017 06:14:08 -0800 (PST) X-Google-Smtp-Source: AGs4zMZKifYCieXw5rEcG/hW0+GxhmxKw4RGWDI6b0dzbx/Q9IwrG+gEccvQBIc7R+U2/Y5GvjqC X-Received: by 10.84.246.194 with SMTP id j2mr6052523plt.7.1510755248661; Wed, 15 Nov 2017 06:14:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510755248; cv=none; d=google.com; s=arc-20160816; b=J4WfO8NAjNdQekZv9whSz7xd+T5xBCkIW6qSqx0KtvO3QGKAmojBGmUqg4grI9xXhs Zr+sblBb5keNG4m3o+DHcqmVHI0AB+SN4dj1ihMFb2vNLAsibpfKdCL4aKXO6J1hiX4A 0XSoXIU/s3ZustrxAxKlfRlu+B+WN8zDxObhg7qsSenhmfBBYWEslGozWu+cNDz63ejt Ae3xMgFSQvEnV/agKIQgqQ8ZZXNe8fbo5QPPpyke+bpQC2zis2uub+r9ROU073hM9JHt foDsXe+anpvAVeqytmNcFpYOdB8iNaaiLLlDpL+joYztLM8r1BAxgjHSJ6u3RjIRQuLP C5Lw== 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:dkim-signature:arc-authentication-results; bh=2+oRm8GPhZO3jQwS/ZpXXBe/1AvJ4jptnaDt0k7rCCA=; b=t6GpCI6Cr1ZyRD0wijYpp4dhlJw5WL45sccOtM3Ud16o/UzJvT51tlkrusIcyPThd2 t7xM6uawz286tDeDZNXk2huvw80XIbQVLx5PbnMorEWr5ipWXfHB8asZxSCD/nFwZdWj NwFA0NgH8SyalhmPC1RRumds3ZI5TKH7BJdDzq8WfJ6soe7dD/z7McoaPrqZBq2Ikp6m 3B/uKsKdLXSEMBBN1LZzFVsIOgIzDqGbiYtanpE1ibQb84OCide7VaF/oQRHk0SkED6P EYDP+Atr0S90mDUrwEpPMDhPGYxTOrkOgfxfAewAaTQqVr5yyGIR9FB5WJ6J0v0FaP45 txXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=IueAPqyv; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 135si1601027pgh.503.2017.11.15.06.14.08; Wed, 15 Nov 2017 06:14:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=IueAPqyv; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756377AbdKOOOD (ORCPT + 10 others); Wed, 15 Nov 2017 09:14:03 -0500 Received: from mail-wm0-f46.google.com ([74.125.82.46]:42059 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757323AbdKOONf (ORCPT ); Wed, 15 Nov 2017 09:13:35 -0500 Received: by mail-wm0-f46.google.com with SMTP id t139so3310492wmt.1 for ; Wed, 15 Nov 2017 06:13:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LJWw8B9erY7UNP+hGdZTQQTcbKjvTJUxs8uQiWV4aqk=; b=IueAPqyvs6xWc2l+VnJRRr66yzX5SrXy/vR6MuQIWm+DJBU4oAP2I9MLFf4nsQ1avs 5sA5I8IUtpNT1EKFrA1GKtjatVDdaLcskHfriYW+wFv4kqLMTmeIojfen0E/ddpClm+y USwdgk523zububxgPDiDM5gm6hOsadbztEm/0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LJWw8B9erY7UNP+hGdZTQQTcbKjvTJUxs8uQiWV4aqk=; b=MaeuEIUPGIZh1YyGBNxtFWFrVdetZgmu8M/Se4OYLkgq6qhlNsQSebPsilrvz4elOw oB0qsjFWM2cSq1JLZed1CrUVpwto96hO2Q+H6CdOthFn+omlRRw4HQK5cnLkay3cLqDG DgpiVSzGVcDINAJ0sul+VENJUkB/rTb5zA9/9ZCd2//V3AIaReMCnxyYwugYcntI/Ezj aF2Jl05IwkCU2HmHT/fzsgx7SDF5jfvV2PAjItfD4hgdhUAiLa1GGUFEQ8wdvQOGOoev tgCgyEvr8/tiwm8CoIj4uH+ylsfLyycSKToAHqsWOiqlL56mJBP+2MA41G6yI01XxXVM 3hyg== X-Gm-Message-State: AJaThX7zBBG9b4t26QPhkoFmzmPxH8tiR12g9auWi7Me5P5wOQxk5hI7 CbaaJTPC1BjFiOhuRTtPHOCqdw== X-Received: by 10.28.14.85 with SMTP id 82mr10669751wmo.120.1510755213809; Wed, 15 Nov 2017 06:13:33 -0800 (PST) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id m11sm56707wrf.56.2017.11.15.06.13.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Nov 2017 06:13:33 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org, broonie@kernel.org, alsa-devel@alsa-project.org Cc: sdharia@codeaurora.org, bp@suse.de, poeschel@lemonage.de, treding@nvidia.com, andreas.noever@gmail.com, alan@linux.intel.com, mathieu.poirier@linaro.org, daniel@ffwll.ch, jkosina@suse.cz, sharon.dvir1@mail.huji.ac.il, joe@perches.com, davem@davemloft.net, james.hogan@imgtec.com, michael.opdenacker@free-electrons.com, robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, vinod.koul@intel.com, arnd@arndb.de, Srinivas Kandagatla Subject: [PATCH v7 06/13] slimbus: Add messaging APIs to slimbus framework Date: Wed, 15 Nov 2017 14:10:36 +0000 Message-Id: <20171115141043.29202-7-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171115141043.29202-1-srinivas.kandagatla@linaro.org> References: <20171115141043.29202-1-srinivas.kandagatla@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Sagar Dharia Slimbus devices use value-element, and information elements to control device parameters (e.g. value element is used to represent gain for codec, information element is used to represent interrupt status for codec when codec interrupt fires). Messaging APIs are used to set/get these value and information elements. Slimbus specification uses 8-bit "transaction IDs" for messages where a read-value is anticipated. Framework uses a table of pointers to store those TIDs and responds back to the caller in O(1). Caller can do synchronous and asynchronous reads/writes. Signed-off-by: Srinivas Kandagatla --- drivers/slimbus/Makefile | 2 +- drivers/slimbus/messaging.c | 415 ++++++++++++++++++++++++++++++++++++++++++++ drivers/slimbus/slimbus.h | 74 ++++++++ include/linux/slimbus.h | 31 ++++ 4 files changed, 521 insertions(+), 1 deletion(-) create mode 100644 drivers/slimbus/messaging.c -- 2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" 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/slimbus/Makefile b/drivers/slimbus/Makefile index 50deace4e76d..dfa049a382ef 100644 --- a/drivers/slimbus/Makefile +++ b/drivers/slimbus/Makefile @@ -2,4 +2,4 @@ # Makefile for kernel slimbus framework. # obj-$(CONFIG_SLIMBUS) += slimbus.o -slimbus-y := core.o +slimbus-y := core.o messaging.o diff --git a/drivers/slimbus/messaging.c b/drivers/slimbus/messaging.c new file mode 100644 index 000000000000..ba78c1bfe15d --- /dev/null +++ b/drivers/slimbus/messaging.c @@ -0,0 +1,415 @@ +/* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that 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. + */ +#include +#include "slimbus.h" + +/** + * slim_msg_response() - Deliver Message response received from a device to the + * framework. + * + * @ctrl: Controller handle + * @reply: Reply received from the device + * @len: Length of the reply + * @tid: Transaction ID received with which framework can associate reply. + * + * Called by controller to inform framework about the response received. + * This helps in making the API asynchronous, and controller-driver doesn't need + * to manage 1 more table other than the one managed by framework mapping TID + * with buffers + */ +void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 len) +{ + struct slim_msg_txn *txn; + struct slim_val_inf *msg; + unsigned long flags; + + spin_lock_irqsave(&ctrl->txn_lock, flags); + txn = idr_find(&ctrl->tid_idr, tid); + if (txn == NULL) { + spin_unlock_irqrestore(&ctrl->txn_lock, flags); + return; + } + + msg = txn->msg; + if (msg == NULL || msg->rbuf == NULL) { + dev_err(ctrl->dev, "Got response to invalid TID:%d, len:%d\n", + tid, len); + return; + } + + idr_remove(&ctrl->tid_idr, tid); + spin_unlock_irqrestore(&ctrl->txn_lock, flags); + + memcpy(msg->rbuf, reply, len); + if (txn->comp) + complete(txn->comp); +} +EXPORT_SYMBOL_GPL(slim_msg_response); + +/** + * slim_do_transfer() - Process a slimbus-messaging transaction + * + * @ctrl: Controller handle + * @txn: Transaction to be sent over SLIMbus + * + * Called by controller to transmit messaging transactions not dealing with + * Interface/Value elements. (e.g. transmittting a message to assign logical + * address to a slave device + * + * Return: -ETIMEDOUT: If transmission of this message timed out + * (e.g. due to bus lines not being clocked or driven by controller) + * -ENOTCONN: If the transmitted message was not ACKed by destination + * device. + */ +int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn) +{ + DECLARE_COMPLETION_ONSTACK(done); + bool need_tid; + unsigned long flags; + int ret, tid, timeout; + + need_tid = slim_tid_txn(txn->mt, txn->mc); + + if (need_tid) { + spin_lock_irqsave(&ctrl->txn_lock, flags); + tid = idr_alloc(&ctrl->tid_idr, txn, 0, + SLIM_MAX_TIDS, GFP_KERNEL); + txn->tid = tid; + + if (!txn->msg->comp) + txn->comp = &done; + else + txn->comp = txn->comp; + + spin_unlock_irqrestore(&ctrl->txn_lock, flags); + + if (tid < 0) + return tid; + } + + ret = ctrl->xfer_msg(ctrl, txn); + + if (ret && need_tid && !txn->msg->comp) { + unsigned long ms = txn->rl + HZ; + + timeout = wait_for_completion_timeout(txn->comp, + msecs_to_jiffies(ms)); + if (!timeout) { + ret = -ETIMEDOUT; + spin_lock_irqsave(&ctrl->txn_lock, flags); + idr_remove(&ctrl->tid_idr, tid); + spin_unlock_irqrestore(&ctrl->txn_lock, flags); + } + } + + if (ret) + dev_err(ctrl->dev, "Tx:MT:0x%x, MC:0x%x, LA:0x%x failed:%d\n", + txn->mt, txn->mc, txn->la, ret); + + return ret; +} + +static int slim_val_inf_sanity(struct slim_controller *ctrl, + struct slim_val_inf *msg, u8 mc) +{ + if (!msg || msg->num_bytes > 16 || + (msg->start_offset + msg->num_bytes) > 0xC00) + goto reterr; + switch (mc) { + case SLIM_MSG_MC_REQUEST_VALUE: + case SLIM_MSG_MC_REQUEST_INFORMATION: + if (msg->rbuf != NULL) + return 0; + break; + case SLIM_MSG_MC_CHANGE_VALUE: + case SLIM_MSG_MC_CLEAR_INFORMATION: + if (msg->wbuf != NULL) + return 0; + break; + case SLIM_MSG_MC_REQUEST_CHANGE_VALUE: + case SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION: + if (msg->rbuf != NULL && msg->wbuf != NULL) + return 0; + break; + default: + break; + } +reterr: + dev_err(ctrl->dev, "Sanity check failed:msg:offset:0x%x, mc:%d\n", + msg->start_offset, mc); + return -EINVAL; +} + +static u16 slim_slicesize(int code) +{ + static const u8 sizetocode[16] = { + 0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7 + }; + + clamp(code, 1, (int)ARRAY_SIZE(sizetocode)); + return sizetocode[code - 1]; +} + +static int slim_xfer_msg(struct slim_controller *ctrl, + struct slim_device *sbdev, + struct slim_val_inf *msg, u8 mc) +{ + DEFINE_SLIM_LDEST_TXN(txn_stack, mc, 6, sbdev->laddr, msg); + struct slim_msg_txn *txn = &txn_stack; + int ret; + u16 sl; + + ret = slim_val_inf_sanity(ctrl, msg, mc); + if (ret) + return ret; + + sl = slim_slicesize(msg->num_bytes); + + dev_dbg(ctrl->dev, "SB xfer msg:os:%x, len:%d, MC:%x, sl:%x\n", + msg->start_offset, msg->num_bytes, mc, sl); + + txn->ec = ((sl | (1 << 3)) | ((msg->start_offset & 0xFFF) << 4)); + + switch (mc) { + case SLIM_MSG_MC_REQUEST_CHANGE_VALUE: + case SLIM_MSG_MC_CHANGE_VALUE: + case SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION: + case SLIM_MSG_MC_CLEAR_INFORMATION: + txn->rl += msg->num_bytes; + default: + break; + } + + if (slim_tid_txn(txn->mt, txn->mc)) + txn->rl++; + + return slim_do_transfer(ctrl, txn); +} + +/** + * slim_request_val_element() - request value element + * + * @sb: client handle requesting elemental message reads, writes. + * @msg: Input structure for start-offset, number of bytes to read. + * context: can sleep + * + * Return: -EINVAL: Invalid parameters + * -ETIMEDOUT: If transmission of this message timed out (e.g. due to + * bus lines not being clocked or driven by controller) + * -ENOTCONN: If the transmitted message was not ACKed by the device. + */ +int slim_request_val_element(struct slim_device *sb, + struct slim_val_inf *msg) +{ + struct slim_controller *ctrl = sb->ctrl; + + if (!ctrl) + return -EINVAL; + + return slim_xfer_msg(ctrl, sb, msg, SLIM_MSG_MC_REQUEST_VALUE); +} +EXPORT_SYMBOL_GPL(slim_request_val_element); + +/** + * slim_request_inf_element() - Request a info element + * + * @sb: client handle requesting elemental message reads. + * @msg: Input structure for start-offset, number of bytes to read + * wbuf will contain information element(s) bit masks to be cleared. + * rbuf will return what the information element value was + */ +int slim_request_inf_element(struct slim_device *sb, + struct slim_val_inf *msg) +{ + struct slim_controller *ctrl = sb->ctrl; + + if (!ctrl) + return -EINVAL; + + return slim_xfer_msg(ctrl, sb, msg, SLIM_MSG_MC_REQUEST_INFORMATION); +} +EXPORT_SYMBOL_GPL(slim_request_inf_element); + +/** + * slim_change_val_element: change a given value element + * + * @sb: client handle requesting elemental message reads, writes. + * @msg: Input structure for start-offset, number of bytes to write. + * context: can sleep + * + * Return: + * -EINVAL: Invalid parameters + * -ETIMEDOUT: If transmission of this message timed out (e.g. due to + * bus lines not being clocked or driven by controller) + * -ENOTCONN: If the transmitted message was not ACKed by the device. + */ +int slim_change_val_element(struct slim_device *sb, struct slim_val_inf *msg) +{ + struct slim_controller *ctrl = sb->ctrl; + + if (!ctrl) + return -EINVAL; + + return slim_xfer_msg(ctrl, sb, msg, SLIM_MSG_MC_CHANGE_VALUE); +} +EXPORT_SYMBOL_GPL(slim_change_val_element); + +/** + * slim_clear_inf_element() - Clear info element + * + * @sb: client handle requesting elemental message reads, writes. + * @msg: Input structure for start-offset, number of bytes to read + * wbuf will contain information element(s) bit masks to be cleared. + * rbuf will return what the information element value was + */ +int slim_clear_inf_element(struct slim_device *sb, struct slim_val_inf *msg) +{ + struct slim_controller *ctrl = sb->ctrl; + + if (!ctrl) + return -EINVAL; + + return slim_xfer_msg(ctrl, sb, msg, SLIM_MSG_MC_CLEAR_INFORMATION); +} +EXPORT_SYMBOL_GPL(slim_clear_inf_element); + +/** + * slim_request_val_element() - change and request a given value element + * + * @sb: client handle requesting elemental message reads, writes. + * @msg: Input structure for start-offset, number of bytes to write. + * context: can sleep + * + * Return: + * -EINVAL: Invalid parameters + * -ETIMEDOUT: If transmission of this message timed out (e.g. due to + * bus lines not being clocked or driven by controller) + * -ENOTCONN: If the transmitted message was not ACKed by the device. + */ +int slim_request_change_val_element(struct slim_device *sb, + struct slim_val_inf *msg) +{ + struct slim_controller *ctrl = sb->ctrl; + + if (!ctrl) + return -EINVAL; + + return slim_xfer_msg(ctrl, sb, msg, SLIM_MSG_MC_REQUEST_CHANGE_VALUE); +} +EXPORT_SYMBOL_GPL(slim_request_change_val_element); + +/** + * slim_request_clear_inf_element() - Clear and request info element + * + * @sb: client handle requesting elemental message reads, writes. + * @msg: Input structure for start-offset, number of bytes to read + * wbuf will contain information element(s) bit masks to be cleared. + * rbuf will return what the information element value was + */ +int slim_request_clear_inf_element(struct slim_device *sb, + struct slim_val_inf *msg) +{ + struct slim_controller *ctrl = sb->ctrl; + + if (!ctrl) + return -EINVAL; + + return slim_xfer_msg(ctrl, sb, msg, + SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION); +} +EXPORT_SYMBOL_GPL(slim_request_clear_inf_element); + +static void slim_fill_msg(struct slim_val_inf *msg, u32 addr, + size_t count, u8 *rbuf, u8 *wbuf) +{ + msg->start_offset = addr; + msg->num_bytes = count; + msg->rbuf = rbuf; + msg->wbuf = wbuf; +} + +/** + * slim_read() - Read slimbus value element + * + * @sdev: client handle. + * @addr: address of value element to read. + * @count: number of bytes to read. Maximum bytes allowed are 16. + * @val: will return what the value element value was + */ +int slim_read(struct slim_device *sdev, u32 addr, size_t count, u8 *val) +{ + struct slim_val_inf msg; + int ret; + + slim_fill_msg(&msg, addr, count, val, NULL); + + ret = slim_request_val_element(sdev, &msg); + + return ret; + +} +EXPORT_SYMBOL_GPL(slim_read); + +/** + * slim_readb() - Read byte from slimbus value element + * + * @sdev: client handle. + * @addr: address in the value element to read. + * + * Return: byte value of value element. + */ +int slim_readb(struct slim_device *sdev, u32 addr) +{ + int ret; + u8 buf; + + ret = slim_read(sdev, addr, 1, &buf); + if (ret < 0) + return ret; + else + return buf; +} +EXPORT_SYMBOL_GPL(slim_readb); + +/** + * slim_write() - Write slimbus value element + * + * @sdev: client handle. + * @addr: address in the value element to write. + * @count: number of bytes to write. Maximum bytes allowed are 16. + * @val: value to write to value element + */ +int slim_write(struct slim_device *sdev, u32 addr, size_t count, u8 *val) +{ + struct slim_val_inf msg; + int ret; + + slim_fill_msg(&msg, addr, count, val, NULL); + ret = slim_change_val_element(sdev, &msg); + + return ret; + +} +EXPORT_SYMBOL_GPL(slim_write); + +/** + * slim_writeb() - Write byte to slimbus value element + * + * @sdev: client handle. + * @addr: address of value element to write. + * @value: value to write to value element + */ +int slim_writeb(struct slim_device *sdev, u32 addr, u8 value) +{ + return slim_write(sdev, addr, 1, &value); +} +EXPORT_SYMBOL_GPL(slim_writeb); diff --git a/drivers/slimbus/slimbus.h b/drivers/slimbus/slimbus.h index b53319992ad4..f3ed5d4dbb0a 100644 --- a/drivers/slimbus/slimbus.h +++ b/drivers/slimbus/slimbus.h @@ -15,8 +15,31 @@ #include #include #include +#include #include +/* SLIMbus message types. Related to interpretation of message code. */ +#define SLIM_MSG_MT_CORE 0x0 + + +/* Information Element management messages */ +#define SLIM_MSG_MC_REQUEST_INFORMATION 0x20 +#define SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION 0x21 +#define SLIM_MSG_MC_REPLY_INFORMATION 0x24 +#define SLIM_MSG_MC_CLEAR_INFORMATION 0x28 +#define SLIM_MSG_MC_REPORT_INFORMATION 0x29 + +/* Value Element management messages */ +#define SLIM_MSG_MC_REQUEST_VALUE 0x60 +#define SLIM_MSG_MC_REQUEST_CHANGE_VALUE 0x61 +#define SLIM_MSG_MC_REPLY_VALUE 0x64 +#define SLIM_MSG_MC_CHANGE_VALUE 0x68 + +/* Destination type Values */ +#define SLIM_MSG_DEST_LOGICALADDR 0 +#define SLIM_MSG_DEST_ENUMADDR 1 +#define SLIM_MSG_DEST_BROADCAST 3 + /* Standard values per SLIMbus spec needed by controllers and devices */ #define SLIM_MAX_CLK_GEAR 10 #define SLIM_MIN_CLK_GEAR 1 @@ -24,6 +47,7 @@ /* Manager's logical address is set to 0xFF per spec */ #define SLIM_LA_MANAGER 0xFF +#define SLIM_MAX_TIDS 256 /** * struct slim_framer - Represents Slimbus framer. * Every controller may have multiple framers. There is 1 active framer device @@ -44,6 +68,40 @@ struct slim_framer { #define to_slim_framer(d) container_of(d, struct slim_framer, dev) +/** + * struct slim_msg_txn - Message to be sent by the controller. + * This structure has packet header, + * payload and buffer to be filled (if any) + * @rl: Header field. remaining length. + * @mt: Header field. Message type. + * @mc: Header field. LSB is message code for type mt. + * @dt: Header field. Destination type. + * @ec: Element code. Used for elemental access APIs. + * @len: Length of payload. (excludes ec) + * @tid: Transaction ID. Used for messages expecting response. + * (relevant for message-codes involving read operation) + * @la: Logical address of the device this message is going to. + * (Not used when destination type is broadcast.) + * @msg: Elemental access message to be read/written + * @comp: completion if read/write is synchronous, used internally + * for tid based transactions. + */ +struct slim_msg_txn { + u8 rl; + u8 mt; + u8 mc; + u8 dt; + u16 ec; + u8 tid; + u8 la; + struct slim_val_inf *msg; + struct completion *comp; +}; + +/* Frequently used message transaction structures */ +#define DEFINE_SLIM_LDEST_TXN(name, mc, rl, la, msg) \ + struct slim_msg_txn name = { rl, 0, mc, SLIM_MSG_DEST_LOGICALADDR, 0,\ + 0, la, msg, } /** * struct slim_controller - Controls every instance of SLIMbus * (similar to 'master' on SPI) @@ -60,6 +118,9 @@ struct slim_framer { * @devices: Slim device list * @tid_idr: tid id allocator * @txn_lock: Lock to protect table of transactions + * @xfer_msg: Transfer a message on this controller (this can be a broadcast + * control/status message like data channel setup, or a unicast message + * like value element read/write. * @set_laddr: Setup logical address at laddr for the slave with elemental * address e_addr. Drivers implementing controller will be expected to * send unicast message to this device with its logical address. @@ -101,6 +162,8 @@ struct slim_controller { struct list_head devices; struct idr tid_idr; spinlock_t txn_lock; + int (*xfer_msg)(struct slim_controller *ctrl, + struct slim_msg_txn *tx); int (*set_laddr)(struct slim_controller *ctrl, struct slim_eaddr *ea, u8 laddr); int (*get_laddr)(struct slim_controller *ctrl, @@ -112,5 +175,16 @@ int slim_device_report_present(struct slim_controller *ctrl, void slim_report_absent(struct slim_device *sbdev); int slim_register_controller(struct slim_controller *ctrl); int slim_unregister_controller(struct slim_controller *ctrl); +void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 l); +int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn); + +static inline bool slim_tid_txn(u8 mt, u8 mc) +{ + return (mt == SLIM_MSG_MT_CORE && + (mc == SLIM_MSG_MC_REQUEST_INFORMATION || + mc == SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION || + mc == SLIM_MSG_MC_REQUEST_VALUE || + mc == SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION)); +} #endif /* _LINUX_SLIMBUS_H */ diff --git a/include/linux/slimbus.h b/include/linux/slimbus.h index ba3fdf1f5176..42b2a8561a45 100644 --- a/include/linux/slimbus.h +++ b/include/linux/slimbus.h @@ -14,6 +14,7 @@ #define _LINUX_SLIMBUS_H #include #include +#include #include /** @@ -100,6 +101,23 @@ struct slim_driver { }; #define to_slim_driver(d) container_of(d, struct slim_driver, driver) +/** + * struct slim_val_inf - Slimbus value or information element + * @start_offset: Specifies starting offset in information/value element map + * @num_bytes: upto 16. This ensures that the message will fit the slicesize + * per slimbus spec + * @comp: completion for asynchronous operations, valid only if TID is + * required for transaction, like REQUEST operations. + * Rest of the transactions are synchronous anyway. + */ +struct slim_val_inf { + u16 start_offset; + u8 num_bytes; + u8 *rbuf; + const u8 *wbuf; + struct completion *comp; +}; + /* * use a macro to avoid include chaining to get THIS_MODULE */ @@ -133,4 +151,17 @@ static inline void slim_set_devicedata(struct slim_device *dev, void *data) struct slim_device *slim_get_device(struct slim_controller *ctrl, struct slim_eaddr *e_addr); int slim_get_logical_addr(struct slim_device *sbdev, u8 *laddr); + +int slim_request_val_element(struct slim_device *sb, struct slim_val_inf *msg); +int slim_request_inf_element(struct slim_device *sb, struct slim_val_inf *msg); +int slim_change_val_element(struct slim_device *sb, struct slim_val_inf *msg); +int slim_clear_inf_element(struct slim_device *sb, struct slim_val_inf *msg); +int slim_request_change_val_element(struct slim_device *sb, + struct slim_val_inf *msg); +int slim_request_clear_inf_element(struct slim_device *sb, + struct slim_val_inf *msg); +int slim_readb(struct slim_device *sdev, u32 addr); +int slim_writeb(struct slim_device *sdev, u32 addr, u8 value); +int slim_read(struct slim_device *sdev, u32 addr, size_t count, u8 *val); +int slim_write(struct slim_device *sdev, u32 addr, size_t count, u8 *val); #endif /* _LINUX_SLIMBUS_H */ From patchwork Wed Nov 15 14:10:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 118966 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4368172qgn; Wed, 15 Nov 2017 06:16:10 -0800 (PST) X-Google-Smtp-Source: AGs4zMZK4Rj0wlvh+WdoXPON+/zGQGw9/CXPCOuxexfIQDSnsEXcr8I4AJ+DCbM51x6fKhlWxE5G X-Received: by 10.98.51.198 with SMTP id z189mr17969104pfz.198.1510755369952; Wed, 15 Nov 2017 06:16:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510755369; cv=none; d=google.com; s=arc-20160816; b=CvGhX8upxqCy19WZ+IZT0s+zzZV+VuuzGOi9mxqQRqXbxR0dItcWO7iwS2wbjwGS9Q dwdKq86So8ujsHiGew74zy9HfGkvcz2f0dxPCtmdWuSSkuWU0SvKxwfQit+89JzkStKI U7QqhaqRdN82TXyh4jZ177WJry77+d4hvIG9YV+BxUVP0zp/OeGDAoqqh7TUAP8eX6D/ 3ia1m5dW9r0/gfGuyW+VYM4zD+BRjWwRYwGOG8FeEUakO5/FdZeTaTJSG1kuUPNU+FFy oOmtbjPyH0Vu1X6CzHJ4iB55F0t85jEJHCn8agebeP3kYkeXqMLLhAVr5mxBJp/YaeTn 7xHQ== 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:dkim-signature:arc-authentication-results; bh=bi44ro+n/n36buL4oqHE7/aYMQyr7hy0iz52oMWZ6sE=; b=Vpm09mPq8x1iEE0d1QAmaMujGC5/y1zLAT+M4JLUlBM7Sg215FoJAAB1CTBxDznW5R oAGdkA7yWLNkJ4LtpG9Kb5SppBa1vPCk+cgMNCzEXw24aiKP3XslQdAOAs+OmGsp2rpz gR0pbP7YFYxyXFCl9sTS/4Kff7n0F3DGLIMpnUhj5skrVZhbRO5skRM/XRBe7tMBl+La gYU2el4spD1uFa81gDi7JCjvF8zsx86Dsv6w66Mep95fznnFDR1O1fFt7c2s1DqJE9aa K/bN+OYwW1dBxZ+JuyDtJVR9Vu+id/mVtMbExDrF5iLqHTvt9csOFHyaI91bjXWL7Wso Outw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=gwn4/TkA; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 42si6334793plb.653.2017.11.15.06.16.09; Wed, 15 Nov 2017 06:16:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=gwn4/TkA; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758070AbdKOOQF (ORCPT + 10 others); Wed, 15 Nov 2017 09:16:05 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35548 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758173AbdKOONm (ORCPT ); Wed, 15 Nov 2017 09:13:42 -0500 Received: by mail-wm0-f68.google.com with SMTP id y80so3265986wmd.0 for ; Wed, 15 Nov 2017 06:13:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FNRqUIZbyHtKgcIWIUBQaibngjuRuTF7fHannC9bfuo=; b=gwn4/TkA+Xu9YOE+2p/rMvgcGYSCsub2A1JYS4KimdBvGKilf3MkLwSn/2CJpNa8FV wmprFQD3oEiBYeamYnKwr+b00vAwmhp5rUxn6HZqHSghls0vf2KAsMpMAPHWe4RUILlQ /lm+a5ZYShfKpb7VawdtQMb+3Owy0j2z+AgZY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FNRqUIZbyHtKgcIWIUBQaibngjuRuTF7fHannC9bfuo=; b=kGojE9zlAatj2BfXflrCsHtYVN+q/aQEXUWXmgyNjehv4nOEWp/JQ+jl8wZL2zv7ol cgTAk9lZouB34K5qpBFW0E8yFqPPFYXBqrhbhcY+OHDGxZPNKQNU17AC4sLtyOQNctsL 9LJO16imIoxpm3A9ebapCikUhSV9IwCua5Qi2D2DWfV7QMG9nSaVaqFoGSqd2emvMOCM u+CqJNcu3WIOIbMrCng07bZOGbxg/0UKZK9QKapcear96ac8FCV6psuLwSuDuILF6VKZ vlT2707pZIzL39j6cu90R8z3Ootn6sb33BPEYqm78sMWVNSfB4SIPv/gzqLd9NggNvB3 /w4Q== X-Gm-Message-State: AJaThX5TESKHCTw8Oanvm2Q+2ZnoP/IW0l+Gs9FZhue60O9hWqXx1D57 h3+WLk3/FtnubcgCewzdcgxMJg== X-Received: by 10.28.131.200 with SMTP id f191mr12534307wmd.39.1510755221180; Wed, 15 Nov 2017 06:13:41 -0800 (PST) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id m11sm56707wrf.56.2017.11.15.06.13.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Nov 2017 06:13:40 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org, broonie@kernel.org, alsa-devel@alsa-project.org Cc: sdharia@codeaurora.org, bp@suse.de, poeschel@lemonage.de, treding@nvidia.com, andreas.noever@gmail.com, alan@linux.intel.com, mathieu.poirier@linaro.org, daniel@ffwll.ch, jkosina@suse.cz, sharon.dvir1@mail.huji.ac.il, joe@perches.com, davem@davemloft.net, james.hogan@imgtec.com, michael.opdenacker@free-electrons.com, robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, vinod.koul@intel.com, arnd@arndb.de, Srinivas Kandagatla Subject: [PATCH v7 10/13] dt-bindings: Add qcom slimbus controller bindings Date: Wed, 15 Nov 2017 14:10:40 +0000 Message-Id: <20171115141043.29202-11-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171115141043.29202-1-srinivas.kandagatla@linaro.org> References: <20171115141043.29202-1-srinivas.kandagatla@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Sagar Dharia This patch add device tree bindings for Qualcomm slimbus controller. Signed-off-by: Sagar Dharia Signed-off-by: Srinivas Kandagatla --- .../devicetree/bindings/slimbus/slim-qcom-ctrl.txt | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Documentation/devicetree/bindings/slimbus/slim-qcom-ctrl.txt -- 2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" 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/Documentation/devicetree/bindings/slimbus/slim-qcom-ctrl.txt b/Documentation/devicetree/bindings/slimbus/slim-qcom-ctrl.txt new file mode 100644 index 000000000000..e4d28910b2e0 --- /dev/null +++ b/Documentation/devicetree/bindings/slimbus/slim-qcom-ctrl.txt @@ -0,0 +1,43 @@ +Qualcomm SLIMBUS controller +This controller is used if applications processor driver controls slimbus +master component. + +Required properties: + + - #address-cells - refer to Documentation/devicetree/bindings/slimbus/bus.txt + - #size-cells - refer to Documentation/devicetree/bindings/slimbus/bus.txt + + - reg : Offset and length of the register region(s) for the device + - reg-names : Register region name(s) referenced in reg above + Required register resource entries are: + "ctrl": Physical address of controller register blocks + - compatible : should be "qcom,-slim" for SOC specific compatible + followed by "qcom,slim" for fallback. + - interrupts : Interrupt number used by this controller + - clocks : Interface and core clocks used by this slimbus controller + - clock-names : Required clock-name entries are: + "iface_clk" : Interface clock for this controller + "core_clk" : Interrupt for controller core's BAM + + +Optional property: + - reg entry for slew rate : If slew rate control register is provided, this + entry should be used. + - reg-name for slew rate: "slew" + +Example: + + slim@28080000 { + compatible = "qcom,apq8064-slim", "qcom,slim"; + reg = <0x28080000 0x2000>, + interrupts = <0 33 0>; + clocks = <&lcc SLIMBUS_SRC>, <&lcc AUDIO_SLIMBUS_CLK>; + clock-names = "iface", "core"; + #address-cells = <2>; + #size-cell = <0>; + + codec: wcd9310@1,0{ + compatible = "slim217,60"; + reg = <1 0>; + }; + }; From patchwork Wed Nov 15 14:10:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 118964 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4367854qgn; Wed, 15 Nov 2017 06:15:55 -0800 (PST) X-Google-Smtp-Source: AGs4zMYRXJWvi3lVbNlssiFq7r0IlOd0l/BX5rmPnR3ewS7F7f9u5a4/LtDkKM90aC8y4XY/he/E X-Received: by 10.159.229.10 with SMTP id s10mr13663799plq.386.1510755355553; Wed, 15 Nov 2017 06:15:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510755355; cv=none; d=google.com; s=arc-20160816; b=f34LDZILzDUO/sy2nqnRYZbXJBpmxfl/nld1ru/H1340kIdjzH0Zy/mxvrqMjvFUAL sMJmDv5UX+Ay+mXc3+yFY7SEWibZCx8Zz86dsFz2xBVa2pqncDMORnCjZSDplcnEWKEo Kfp8GEZQptV0eXcN9wGtcx6ml23wX1EZolMEYaklvsKk2iqbueLAtycPlxPYLoGofHSs LJJDL+nj+mLU7MRHaQJJ25d872Mcy1Fi22Q5snFpUOL9gbF7gZMSObOjps6YXBLy96ve HKDr276R7cm/SY8YZwJJ/szGJ8Yw+Yr25czsqr2q9JpKkvp5eX3xRGOAq11dzXjL4Fzo HJgQ== 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:dkim-signature:arc-authentication-results; bh=FMKo6n9YKXZneGhZWsMg6YkvcXNL4K92A8Wvfqbr024=; b=DWg/OEBxLRACL0H9aYk47waqQB6sOQFnr3z9dk1qoCDI81Eytnq7/C36nsLQutGudV sOzhZVmvt4x1zpdnYpA9+FJtlWwHohLwd8pECy5z9WPmkZcBsZxZQxuyQaOMSFYv/US6 sau7vG/mdjchMrv0fwBRICETf2Q7pfVzgARaGQdOPT3FdfNEr7+TaIEmbF9dPq6bNKb2 PtzNLIBA5HtaGxHEUaoWbIhwlLmzLSWCNPwp5VRTX2aRHEMh2dl6G98aojj1Je4xCTEg Syi58AGvZ58v1tl8z+6w6Diz41ssxb3u0q7M3L/krjMO8nh5clFRsG7PHsw/wNjUDYiX s/Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=CxY7hq/3; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 42si6334793plb.653.2017.11.15.06.15.55; Wed, 15 Nov 2017 06:15:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=CxY7hq/3; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757973AbdKOOPx (ORCPT + 10 others); Wed, 15 Nov 2017 09:15:53 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:52687 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932438AbdKOONr (ORCPT ); Wed, 15 Nov 2017 09:13:47 -0500 Received: by mail-wr0-f196.google.com with SMTP id o14so1672833wrf.9 for ; Wed, 15 Nov 2017 06:13:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Fpp9bd4NzhrFt49fV29VG9EqNkVvbhn6sFBTqylybMA=; b=CxY7hq/3XqxttWax2mU+2L9gXvBThCsqzfZLLaAbC3W9Lp6ao++iBLNReAgLtNzpzX 8CmqZnPqVV5tVvr6ZJ9RCcwxG0o2LIuzQC/y8Stl5QuVJAgpVwQ5xLTOGncJ7iQsElvn +mXsmpp8FoHdTUnEROoLlo38D6V+WMB3Ukme0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Fpp9bd4NzhrFt49fV29VG9EqNkVvbhn6sFBTqylybMA=; b=d73PeG6K9k+LGBBiZ+PSYw2Q6pTd32wG5Uin77JbLCIwOUPMbqi8/NIO+BExID8BQk np1YQAJ9XAavoosx86+kM6spZGxt0LWK2x+UVTSZh+EjP0uBxC52Tn4zV6wDrj3RbbcK KoRulL43849lAPH/DosegGUv1mw7oKifaX6Rs8S9Ofa7VU8Y0H3QJD6Oz2HtjfOxP3C0 CQYId7xOYJ/qAS7vbgrs4EJisNg8aLNDLEOCJHTvxDon/NI9llruHVyXShtf71+RqMPp C6Dppm6AGJtQPYSd6AwxMYIthr4db1dY1SpOTFfOlCWE+cYz+V91Sdh1DwThYQn1eNty oIOw== X-Gm-Message-State: AJaThX4UP8LBQg1woK7UbXeORb+ERybRWI+ao0Tih7vSjCn/Q5HAelCU OwpZbOZp/mGOxeQe6L9TK1dsaQ== X-Received: by 10.223.186.202 with SMTP id w10mr10057830wrg.132.1510755224760; Wed, 15 Nov 2017 06:13:44 -0800 (PST) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id m11sm56707wrf.56.2017.11.15.06.13.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Nov 2017 06:13:44 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org, broonie@kernel.org, alsa-devel@alsa-project.org Cc: sdharia@codeaurora.org, bp@suse.de, poeschel@lemonage.de, treding@nvidia.com, andreas.noever@gmail.com, alan@linux.intel.com, mathieu.poirier@linaro.org, daniel@ffwll.ch, jkosina@suse.cz, sharon.dvir1@mail.huji.ac.il, joe@perches.com, davem@davemloft.net, james.hogan@imgtec.com, michael.opdenacker@free-electrons.com, robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, vinod.koul@intel.com, arnd@arndb.de, Srinivas Kandagatla Subject: [PATCH v7 12/13] slimbus: qcom: Add runtime-pm support using clock-pause Date: Wed, 15 Nov 2017 14:10:42 +0000 Message-Id: <20171115141043.29202-13-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171115141043.29202-1-srinivas.kandagatla@linaro.org> References: <20171115141043.29202-1-srinivas.kandagatla@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Sagar Dharia Slimbus HW mandates that clock-pause sequence has to be executed before disabling relevant interface and core clocks. Runtime-PM's autosuspend feature is used here to enter/exit low power mode for Qualcomm's Slimbus controller. Autosuspend feature enables driver to avoid changing power-modes too frequently since entering clock-pause is an expensive sequence Signed-off-by: Sagar Dharia Signed-off-by: Srinivas Kandagatla --- drivers/slimbus/qcom-ctrl.c | 113 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 3 deletions(-) -- 2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" 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/slimbus/qcom-ctrl.c b/drivers/slimbus/qcom-ctrl.c index 25c1974f04ec..38340b104db4 100644 --- a/drivers/slimbus/qcom-ctrl.c +++ b/drivers/slimbus/qcom-ctrl.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "slimbus.h" /* Manager registers */ @@ -71,6 +72,7 @@ ((l) | ((mt) << 5) | ((mc) << 8) | ((dt) << 15) | ((ad) << 16)) #define SLIM_ROOT_FREQ 24576000 +#define QCOM_SLIM_AUTOSUSPEND 1000 /* MAX message size over control channel */ #define SLIM_MSGQ_BUF_LEN 40 @@ -295,6 +297,30 @@ static irqreturn_t qcom_slim_interrupt(int irq, void *d) return ret; } +static int qcom_clk_pause_wakeup(struct slim_controller *sctrl) +{ + struct qcom_slim_ctrl *ctrl = dev_get_drvdata(sctrl->dev); + + clk_prepare_enable(ctrl->hclk); + clk_prepare_enable(ctrl->rclk); + enable_irq(ctrl->irq); + + writel_relaxed(1, ctrl->base + FRM_WAKEUP); + /* Make sure framer wakeup write goes through before ISR fires */ + mb(); + /* + * HW Workaround: Currently, slave is reporting lost-sync messages + * after slimbus comes out of clock pause. + * Transaction with slave fail before slave reports that message + * Give some time for that report to come + * Slimbus wakes up in clock gear 10 at 24.576MHz. With each superframe + * being 250 usecs, we wait for 5-10 superframes here to ensure + * we get the message + */ + usleep_range(1250, 2500); + return 0; +} + void *slim_alloc_txbuf(struct qcom_slim_ctrl *ctrl, struct slim_msg_txn *txn, struct completion *done) { @@ -540,6 +566,7 @@ static int qcom_slim_probe(struct platform_device *pdev) sctrl->set_laddr = qcom_set_laddr; sctrl->xfer_msg = qcom_xfer_msg; + sctrl->wakeup = qcom_clk_pause_wakeup; ctrl->tx.n = QCOM_TX_MSGS; ctrl->tx.sl_sz = SLIM_MSGQ_BUF_LEN; ctrl->rx.n = QCOM_RX_MSGS; @@ -647,14 +674,93 @@ static int qcom_slim_remove(struct platform_device *pdev) { struct qcom_slim_ctrl *ctrl = platform_get_drvdata(pdev); - disable_irq(ctrl->irq); - clk_disable_unprepare(ctrl->hclk); - clk_disable_unprepare(ctrl->rclk); + pm_runtime_disable(&pdev->dev); slim_unregister_controller(&ctrl->ctrl); destroy_workqueue(ctrl->rxwq); return 0; } +/* + * If PM_RUNTIME is not defined, these 2 functions become helper + * functions to be called from system suspend/resume. + */ +#ifdef CONFIG_PM +static int qcom_slim_runtime_suspend(struct device *device) +{ + struct platform_device *pdev = to_platform_device(device); + struct qcom_slim_ctrl *ctrl = platform_get_drvdata(pdev); + int ret; + + dev_dbg(device, "pm_runtime: suspending...\n"); + ret = slim_ctrl_clk_pause(&ctrl->ctrl, false, SLIM_CLK_UNSPECIFIED); + if (ret) { + dev_err(device, "clk pause not entered:%d", ret); + } else { + disable_irq(ctrl->irq); + clk_disable_unprepare(ctrl->hclk); + clk_disable_unprepare(ctrl->rclk); + } + return ret; +} + +static int qcom_slim_runtime_resume(struct device *device) +{ + struct platform_device *pdev = to_platform_device(device); + struct qcom_slim_ctrl *ctrl = platform_get_drvdata(pdev); + int ret = 0; + + dev_dbg(device, "pm_runtime: resuming...\n"); + ret = slim_ctrl_clk_pause(&ctrl->ctrl, true, 0); + if (ret) + dev_err(device, "clk pause not exited:%d", ret); + return ret; +} +#endif + +#ifdef CONFIG_PM_SLEEP +static int qcom_slim_suspend(struct device *dev) +{ + int ret = 0; + + if (!pm_runtime_enabled(dev) || + (!pm_runtime_suspended(dev))) { + dev_dbg(dev, "system suspend"); + ret = qcom_slim_runtime_suspend(dev); + } + + /* + * If the clock pause failed due to active channels, there is + * a possibility that some audio stream is active during suspend. + * (e.g. modem usecase during suspend) + * We dont want to return suspend failure in that case so that + * display and relevant components can still go to suspend. + * If there is some other error, then it should prevent + * system level suspend + */ + if (ret == -EISCONN) + ret = 0; + + return ret; +} + +static int qcom_slim_resume(struct device *dev) +{ + if (!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev)) { + int ret; + + dev_dbg(dev, "system resume"); + ret = qcom_slim_runtime_resume(dev); + if (!ret) { + pm_runtime_mark_last_busy(dev); + pm_request_autosuspend(dev); + } + return ret; + + } + return 0; +} +#endif /* CONFIG_PM_SLEEP */ + static const struct dev_pm_ops qcom_slim_dev_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(qcom_slim_suspend, qcom_slim_resume) SET_RUNTIME_PM_OPS( @@ -676,6 +782,7 @@ static struct platform_driver qcom_slim_driver = { .driver = { .name = "qcom_slim_ctrl", .of_match_table = qcom_slim_dt_match, + .pm = &qcom_slim_dev_pm_ops, }, }; module_platform_driver(qcom_slim_driver);