From patchwork Thu Nov 30 17:41:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 120259 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp89761qgn; Thu, 30 Nov 2017 09:46:01 -0800 (PST) X-Google-Smtp-Source: AGs4zMaEnr7X38qohJiKwLPYfWYrf4+eHPIggLSyxJSCluDy2YtmD/qKS2CzjYAP4yMX0vI2Rw5O X-Received: by 10.99.116.17 with SMTP id p17mr3013665pgc.385.1512063960770; Thu, 30 Nov 2017 09:46:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512063960; cv=none; d=google.com; s=arc-20160816; b=rnliJXngMgPRjDMgZKSgDe4nbT81Vm1q+ROPi6/Y6vEpRX8AfjT+Ki+3EPecf3oI79 qK3rwZUAhcK8AQdUM/zua2wlr8BRfcdUS4rYBWfRuyOjDj2OLx0KVataVnUazjppmseq qSOgTurtVGlLgXst2bAX10spe80CPHML4yosycAdibsirHU4df0fN2tKEK1CyyfrVc3a 43Ebs5drG6Ob2EULkeiwbaX2OMJGTO75oj/M/uHnMgWXTJU89s6Zgw0V0/hoaB5C9pYy i7/b87AjFM6E3z4lHsczZz7woAat2iGtiuagqiovUAnnLoWBZ1bWQwYU2zTiD+8WVobE SsZQ== 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=HZYbyrD9ze1PZ+q2JHZiocYridKvauK/rrLWoYJTwSg=; b=LSnVCjX+fOHS2zz7J8YHV48qgj1i9Sgg99awtUVrCSpVlmYJ7tUBfjD4IUcgTtJG6s C5B/1cXs1e6FXQaAJZoxVACpRyOHR+WgogxiYi1C+I308T92ohuVVNobPUDTmv2Arowz qW/lsT0Eci1/bnMPp776+Fp6TKy4IrtULuc/AuJg88arQplfM3THpsYMYO2WTVTxFSvf ldr2Q0hSEahZY32LfXZK1GVQdduJ3lmNxb7F3ehK+c6dPUEWFa49LZc8RF1L1El+v0JN 0DLx4ogF3e8zFZTg/fOAKfQrO10bQ/xcuUAk8yhIe22Rh+QljHDMe5K1OkMB7nvrUPRo oimA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CZAveNjX; 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; dmarc=pass (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 bf5si3526200plb.578.2017.11.30.09.46.00; Thu, 30 Nov 2017 09:46:00 -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=@linaro.org header.s=google header.b=CZAveNjX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753909AbdK3Rp5 (ORCPT + 28 others); Thu, 30 Nov 2017 12:45:57 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:38161 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753859AbdK3Rpv (ORCPT ); Thu, 30 Nov 2017 12:45:51 -0500 Received: by mail-wm0-f66.google.com with SMTP id 64so13891681wme.3 for ; Thu, 30 Nov 2017 09:45:51 -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=HZYbyrD9ze1PZ+q2JHZiocYridKvauK/rrLWoYJTwSg=; b=CZAveNjXnOSTavULFyikC8aJVE4/CpXxvDfAG3F/i66WfkylWG6w6Fx97FfkH7wg+m Uy98YhTIj+z+uMsRjNtNTs4eECcfobHDi15LvejbWl1AI2TUAvMjyMskUT4qkoBXQxVt SFcQUiL47yp2yawQzHwjV7TtECgJ6GaJyaSg0= 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=HZYbyrD9ze1PZ+q2JHZiocYridKvauK/rrLWoYJTwSg=; b=LKwv0HHnq017jFrZA6ZYg2gsD560zYYx99KBEPzj47mbTFsB4myZ4tBstAjmmVJ0NZ GSrlMmXQbt/FG/v0VQFNIdkvp4yWXrj1/pBXtU2nyrAoR36oxADUSana+RNFI50HXHDh i3zJ82bmZEAM/DFMkq+cCmks/DlhaMBmq0WoTowWayKUm0NN8dZs2eXZlKuZgX4V4q8r Gi54SUauEYyUFY9Nyl6QlMtJwFHcK+X8PdDkgbw5Wyj9lVShCMJ/emh+WsuCo1BDaG7l GY8l7EXPEMYE2M6y69c05mAcDXT0WQJQq8EGiK5vJVKiMxbdNDpPmIPU4u+M3jF2CZMa fZVQ== X-Gm-Message-State: AJaThX7Y9KAMmawolrocDynonxAo9IN34d5dLsNhKJHRUX2xblkRhdnZ 2MS29wT3jT93sKK8O5blk8qoQg== X-Received: by 10.28.55.71 with SMTP id e68mr1325425wma.139.1512063950329; Thu, 30 Nov 2017 09:45:50 -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 189sm2412189wmu.3.2017.11.30.09.45.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Nov 2017 09:45:49 -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@linaro.org Subject: [PATCH v8 02/13] dt-bindings: Add SLIMbus bindings Date: Thu, 30 Nov 2017 17:41:49 +0000 Message-Id: <20171130174200.6684-3-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171130174200.6684-1-srinivas.kandagatla@linaro.org> References: <20171130174200.6684-1-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sagar Dharia SLIMbus (Serial Low Power Interchip Media Bus) is a specification developed by MIPI (Mobile Industry Processor Interface) alliance. SLIMbus is a 2-wire implementation, which is used to communicate with peripheral components like audio-codec. This patch adds device tree bindings for the slimbus. Signed-off-by: Sagar Dharia Signed-off-by: Srinivas Kandagatla Reviewed-by: Rob Herring --- Documentation/devicetree/bindings/slimbus/bus.txt | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/slimbus/bus.txt -- 2.15.0 diff --git a/Documentation/devicetree/bindings/slimbus/bus.txt b/Documentation/devicetree/bindings/slimbus/bus.txt new file mode 100644 index 000000000000..52fa6426388c --- /dev/null +++ b/Documentation/devicetree/bindings/slimbus/bus.txt @@ -0,0 +1,50 @@ +SLIM(Serial Low Power Interchip Media Bus) bus + +SLIMbus is a 2-wire bus, and is used to communicate with peripheral +components like audio-codec. + +Required property for SLIMbus controller node: +- compatible - name of SLIMbus controller + +Child nodes: +Every SLIMbus controller node can contain zero or more child nodes +representing slave devices on the bus. Every SLIMbus slave device is +uniquely determined by the enumeration address containing 4 fields: +Manufacturer ID, Product code, Device index, and Instance value for +the device. +If child node is not present and it is instantiated after device +discovery (slave device reporting itself present). + +In some cases it may be necessary to describe non-probeable device +details such as non-standard ways of powering up a device. In +such cases, child nodes for those devices will be present as +slaves of the SLIMbus controller, as detailed below. + +Required property for SLIMbus child node if it is present: +- reg - Should be ('Device index', 'Instance ID') from SLIMbus + Enumeration Address. + Device Index Uniquely identifies multiple Devices within + a single Component. + Instance ID Is for the cases where multiple Devices of the + same type or Class are attached to the bus. + +- compatible -"slimMID,PID". The textual representation of Manufacturer ID, + Product Code, shall be in lower case hexadecimal with leading + zeroes suppressed + +SLIMbus example for Qualcomm's slimbus manager component: + + 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 Thu Nov 30 17:41:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 120272 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp92626qgn; Thu, 30 Nov 2017 09:48:41 -0800 (PST) X-Google-Smtp-Source: AGs4zMZhyZ6XClXBFpVau5T+P2va2sreAZLLPtkG9SOCP7DojS8Y3oboAImeRZRonbum0g8d4RKe X-Received: by 10.159.240.134 with SMTP id p6mr3410516plr.344.1512064121786; Thu, 30 Nov 2017 09:48:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512064121; cv=none; d=google.com; s=arc-20160816; b=HCzU0BKgrgoZotLDOIOFKnkMBPj7ost/6v3pUXCjTgD/VCGgniFGvCcwkB/XlafSEy f4ZoqnP6fNo+zsPaWwcgJKfFKpBK8jV55a4eDEJRqmV6VvyDzr0RWY4Uy0Qmkgg0/DkD ckKLRXtypx+mR+pBa52StmtEMOyglow7m6oyUDP3Zz0WkitmjqtKDIz0KFii7iZJK1DJ OnxHERSKQe5z5oZeEiccbVll6vkKHbZooz4HU1nIb45Ada7NwFwT7o867z08Dm2Ya8je CZw7GFIc/OzSwtS2HJ/VHBTUXbeViuXDLH2UN7tZlV1CDPyUDTQbqoLOKsLmKOZhqICX llzg== 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=0N9XFFk6kABFDqiY54brdoEIphK4edmNkEECCAkJGu8=; b=WXjyD2toSqdTOphGXsyf/eRreQ6mgHNZymR14XdKzkhMThGF66smwxEB7KAZu2LV2f D2PfkfkGUdaD6m/o4NOMiNINeWcq4AkYWYArrbpcxfbLMtIzYanS/Gk6iZlxwZMXSPWn D6VAxB5KEqXcXg93SahCg8qP5bLhKcMT8g02UwGj/vGYqKz8/kZoaOPvsgR96FGKkFzF 2iqE/TbEoZOSBKaqVfjwzioCB/6nbZtRrNzbod7cOuY7DeXhydBxLZoCbbOWR0aks0er ERTRq29zOzSueNmfi+ShGgHD8wGdkkaInX6JTABzUQbGzHsCcYzYj5SOG74yP5WO+fzS qXyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g1lJNLyT; 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; dmarc=pass (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 q8si3535904pli.184.2017.11.30.09.48.41; Thu, 30 Nov 2017 09:48:41 -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=@linaro.org header.s=google header.b=g1lJNLyT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753803AbdK3Rsk (ORCPT + 28 others); Thu, 30 Nov 2017 12:48:40 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:36685 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753884AbdK3Rpz (ORCPT ); Thu, 30 Nov 2017 12:45:55 -0500 Received: by mail-wr0-f194.google.com with SMTP id v105so7431665wrc.3 for ; Thu, 30 Nov 2017 09:45:54 -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=0N9XFFk6kABFDqiY54brdoEIphK4edmNkEECCAkJGu8=; b=g1lJNLyTxdjnLd0eytCIfWEPBlONgk6aPt5LYkxHO2LuQKDJGQYFbbIPvEP58NN93J 8l99UOI95F4XPEP8UME8EQq83xpimzO4rOIOLe9D6U7JWUD8ES6XgCfv48u8O0lobuhX g28ffYcZDPYIYZEnWhyEEqy2Dh2vCy2+wwjHQ= 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=0N9XFFk6kABFDqiY54brdoEIphK4edmNkEECCAkJGu8=; b=bLsii3kJaP8EK/W1mJvkkfIihnetiTOHphEAJKqaM1OwhtXIDaYr7fahJdb1epnlZp GD29PT4WPnjP6XosUHEQmax4tzXyguy+eGrFa/ZR2OsDEjZ8wJ2OW2N0nNJ8LqfqeAXn ps0QaVGGYjJ6nBIRWqL0ac8B4hg8sxIhB8YMTWh3lTT8VOTBlYI3yT2JPyckLGaPtXJY dwmzOGxCqEHWSz7R8nr4bAucZLJCSoMl/j+YPi0pE+ptC8Ot9et+rC1qKSCiKx59DpYy +wTqNvTAFlEI27wGFtZDsee8Ovr+tSV8XnJwLQzbxhrCXtkV9yRDXIWwu1HTnWjXmTkW Z3yA== X-Gm-Message-State: AJaThX40GT1c6WFZ4iI9x5Nd6c6A+SgIqsnxUFdbGBLN3wN+N1qfDJ1T qPAXYW3xZFLMNh1CPlS3PhJFmA== X-Received: by 10.223.191.13 with SMTP id p13mr2912800wrh.69.1512063953730; Thu, 30 Nov 2017 09:45:53 -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 189sm2412189wmu.3.2017.11.30.09.45.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Nov 2017 09:45:53 -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@linaro.org Subject: [PATCH v8 04/13] slimbus: core: Add slim controllers support Date: Thu, 30 Nov 2017 17:41:51 +0000 Message-Id: <20171130174200.6684-5-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171130174200.6684-1-srinivas.kandagatla@linaro.org> References: <20171130174200.6684-1-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sagar Dharia This patch adds support to slim controllers in the slim core, including some utility functions invoked by the controller and slim device drivers. Signed-off-by: Srinivas Kandagatla --- drivers/slimbus/core.c | 306 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/slimbus/slimbus.h | 115 +++++++++++++++++ include/linux/slimbus.h | 8 ++ 3 files changed, 429 insertions(+) create mode 100644 drivers/slimbus/slimbus.h -- 2.15.0 diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c index 005714464fd8..41e83c15591a 100644 --- a/drivers/slimbus/core.c +++ b/drivers/slimbus/core.c @@ -14,7 +14,11 @@ #include #include #include +#include #include +#include "slimbus.h" + +static DEFINE_IDA(ctrl_ida); static const struct slim_device_id *slim_match(const struct slim_device_id *id, const struct slim_device *sbdev) @@ -99,6 +103,308 @@ void slim_driver_unregister(struct slim_driver *drv) } EXPORT_SYMBOL_GPL(slim_driver_unregister); +static void slim_dev_release(struct device *dev) +{ + struct slim_device *sbdev = to_slim_device(dev); + + kfree(sbdev); +} + +static int slim_add_device(struct slim_controller *ctrl, + struct slim_device *sbdev, + struct device_node *node) +{ + sbdev->dev.bus = &slimbus_bus; + sbdev->dev.parent = ctrl->dev; + sbdev->dev.release = slim_dev_release; + sbdev->dev.driver = NULL; + sbdev->ctrl = ctrl; + + dev_set_name(&sbdev->dev, "%x:%x:%x:%x", + sbdev->e_addr.manf_id, + sbdev->e_addr.prod_code, + sbdev->e_addr.dev_index, + sbdev->e_addr.instance); + + return device_register(&sbdev->dev); +} + +static struct slim_device *slim_alloc_device(struct slim_controller *ctrl, + struct slim_eaddr *eaddr, + struct device_node *node) +{ + struct slim_device *sbdev; + int ret; + + sbdev = kzalloc(sizeof(*sbdev), GFP_KERNEL); + if (!sbdev) + return NULL; + + sbdev->e_addr = *eaddr; + ret = slim_add_device(ctrl, sbdev, node); + if (ret) { + kfree(sbdev); + return NULL; + } + + return sbdev; +} + +/* + * slim_register_controller() - Controller bring-up and registration. + * + * @ctrl: Controller to be registered. + * + * A controller is registered with the framework using this API. + * If devices on a controller were registered before controller, + * this will make sure that they get probed when controller is up + */ +int slim_register_controller(struct slim_controller *ctrl) +{ + int id; + + id = ida_simple_get(&ctrl_ida, 0, 0, GFP_KERNEL); + if (id < 0) + return id; + + ctrl->id = id; + + if (!ctrl->min_cg) + ctrl->min_cg = SLIM_MIN_CLK_GEAR; + if (!ctrl->max_cg) + ctrl->max_cg = SLIM_MAX_CLK_GEAR; + + ida_init(&ctrl->laddr_ida); + idr_init(&ctrl->tid_idr); + mutex_init(&ctrl->lock); + + dev_dbg(ctrl->dev, "Bus [%s] registered:dev:%p\n", + ctrl->name, ctrl->dev); + + return 0; +} +EXPORT_SYMBOL_GPL(slim_register_controller); + +/* slim_remove_device: Remove the effect of slim_add_device() */ +static void slim_remove_device(struct slim_device *sbdev) +{ + device_unregister(&sbdev->dev); +} + +static int slim_ctrl_remove_device(struct device *dev, void *null) +{ + slim_remove_device(to_slim_device(dev)); + return 0; +} + +/** + * slim_unregister_controller() - Controller tear-down. + * + * @ctrl: Controller to tear-down. + */ +int slim_unregister_controller(struct slim_controller *ctrl) +{ + /* Remove all clients */ + device_for_each_child(ctrl->dev, NULL, slim_ctrl_remove_device); + ida_simple_remove(&ctrl_ida, ctrl->id); + + return 0; +} +EXPORT_SYMBOL_GPL(slim_unregister_controller); + +static void slim_device_update_status(struct slim_device *sbdev, + enum slim_device_status status) +{ + struct slim_driver *sbdrv; + + if (sbdev->status == status) + return; + + sbdev->status = status; + if (!sbdev->dev.driver) + return; + + sbdrv = to_slim_driver(sbdev->dev.driver); + if (sbdrv->device_status) + sbdrv->device_status(sbdev, sbdev->status); +} + +/** + * slim_report_absent() - Controller calls this function when a device + * reports absent, OR when the device cannot be communicated with + * + * @sbdev: Device that cannot be reached, or sent report absent + */ +void slim_report_absent(struct slim_device *sbdev) +{ + struct slim_controller *ctrl = sbdev->ctrl; + + if (!ctrl) + return; + + /* invalidate logical addresses */ + mutex_lock(&ctrl->lock); + sbdev->is_laddr_valid = false; + mutex_unlock(&ctrl->lock); + + ida_simple_remove(&ctrl->laddr_ida, sbdev->laddr); + slim_device_update_status(sbdev, SLIM_DEVICE_STATUS_DOWN); +} +EXPORT_SYMBOL_GPL(slim_report_absent); + +static bool slim_eaddr_equal(struct slim_eaddr *a, struct slim_eaddr *b) +{ + return (a->manf_id == b->manf_id && + a->prod_code == b->prod_code && + a->dev_index == b->dev_index && + a->instance == b->instance); +} + +static int slim_match_dev(struct device *dev, void *data) +{ + struct slim_eaddr *e_addr = data; + struct slim_device *sbdev = to_slim_device(dev); + + return slim_eaddr_equal(&sbdev->e_addr, e_addr); +} + +static struct slim_device *find_slim_device(struct slim_controller *ctrl, + struct slim_eaddr *eaddr) +{ + struct slim_device *sbdev; + struct device *dev; + + dev = device_find_child(ctrl->dev, eaddr, slim_match_dev); + if (dev) { + sbdev = to_slim_device(dev); + return sbdev; + } + + return NULL; +} + +/** + * slim_get_device() - get handle to a device. + * + * @ctrl: Controller on which this device will be added/queried + * @e_addr: Enumeration address of the device to be queried + * + * Return: pointer to a device if it has already reported. Creates a new + * device and returns pointer to it if the device has not yet enumerated. + */ +struct slim_device *slim_get_device(struct slim_controller *ctrl, + struct slim_eaddr *e_addr) +{ + struct slim_device *sbdev; + + sbdev = find_slim_device(ctrl, e_addr); + if (!sbdev) { + sbdev = slim_alloc_device(ctrl, e_addr, NULL); + if (!sbdev) + return ERR_PTR(-ENOMEM); + } + + return sbdev; +} +EXPORT_SYMBOL_GPL(slim_get_device); + +static int slim_device_alloc_laddr(struct slim_device *sbdev, + bool report_present) +{ + struct slim_controller *ctrl = sbdev->ctrl; + u8 laddr; + int ret; + + mutex_lock(&ctrl->lock); + if (ctrl->get_laddr) { + ret = ctrl->get_laddr(ctrl, &sbdev->e_addr, &laddr); + if (ret < 0) + goto err; + } else if (report_present) { + ret = ida_simple_get(&ctrl->laddr_ida, + 0, SLIM_LA_MANAGER - 1, GFP_KERNEL); + if (ret < 0) + goto err; + + laddr = ret; + } else { + ret = -EINVAL; + goto err; + } + + if (ctrl->set_laddr) { + ret = ctrl->set_laddr(ctrl, &sbdev->e_addr, laddr); + if (ret) { + ret = -EINVAL; + goto err; + } + } + + sbdev->laddr = laddr; + sbdev->is_laddr_valid = true; + + slim_device_update_status(sbdev, SLIM_DEVICE_STATUS_UP); + + dev_dbg(ctrl->dev, "setting slimbus l-addr:%x, ea:%x,%x,%x,%x\n", + laddr, sbdev->e_addr.manf_id, sbdev->e_addr.prod_code, + sbdev->e_addr.dev_index, sbdev->e_addr.instance); + +err: + mutex_unlock(&ctrl->lock); + return ret; + +} + +/** + * slim_device_report_present() - Report enumerated device. + * + * @ctrl: Controller with which device is enumerated. + * @e_addr: Enumeration address of the device. + * @laddr: Return logical address (if valid flag is false) + * + * Called by controller in response to REPORT_PRESENT. Framework will assign + * a logical address to this enumeration address. + * Function returns -EXFULL to indicate that all logical addresses are already + * taken. + */ +int slim_device_report_present(struct slim_controller *ctrl, + struct slim_eaddr *e_addr, u8 *laddr) +{ + struct slim_device *sbdev; + int ret; + + sbdev = slim_get_device(ctrl, e_addr); + if (IS_ERR(sbdev)) + return -ENODEV; + + if (sbdev->is_laddr_valid) { + *laddr = sbdev->laddr; + return 0; + } + + ret = slim_device_alloc_laddr(sbdev, true); + + return ret; +} +EXPORT_SYMBOL_GPL(slim_device_report_present); + +/** + * slim_get_logical_addr() - get/allocate logical address of a SLIMbus device. + * + * @sbdev: client handle requesting the address. + * + * Return: zero if a logical address is valid or a new logical address + * has been assigned. error code in case of error. + */ +int slim_get_logical_addr(struct slim_device *sbdev) +{ + if (!sbdev->is_laddr_valid) + return slim_device_alloc_laddr(sbdev, false); + + return 0; +} +EXPORT_SYMBOL_GPL(slim_get_logical_addr); + static void __exit slimbus_exit(void) { bus_unregister(&slimbus_bus); diff --git a/drivers/slimbus/slimbus.h b/drivers/slimbus/slimbus.h new file mode 100644 index 000000000000..aac23bedef28 --- /dev/null +++ b/drivers/slimbus/slimbus.h @@ -0,0 +1,115 @@ +/* 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. + */ + +#ifndef _DRIVERS_SLIMBUS_H +#define _DRIVERS_SLIMBUS_H +#include +#include +#include +#include + +/* Standard values per SLIMbus spec needed by controllers and devices */ +#define SLIM_MAX_CLK_GEAR 10 +#define SLIM_MIN_CLK_GEAR 1 + +/* Manager's logical address is set to 0xFF per spec */ +#define SLIM_LA_MANAGER 0xFF + +/** + * struct slim_framer - Represents SLIMbus framer. + * Every controller may have multiple framers. There is 1 active framer device + * responsible for clocking the bus. + * Manager is responsible for framer hand-over. + * @dev: Driver model representation of the device. + * @e_addr: Enumeration address of the framer. + * @rootfreq: Root Frequency at which the framer can run. This is maximum + * frequency ('clock gear 10') at which the bus can operate. + * @superfreq: Superframes per root frequency. Every frame is 6144 bits. + */ +struct slim_framer { + struct device dev; + struct slim_eaddr e_addr; + int rootfreq; + int superfreq; +}; + +#define to_slim_framer(d) container_of(d, struct slim_framer, dev) + +/** + * struct slim_controller - Controls every instance of SLIMbus + * (similar to 'master' on SPI) + * @dev: Device interface to this driver + * @id: Board-specific number identifier for this controller/bus + * @name: Name for this controller + * @min_cg: Minimum clock gear supported by this controller (default value: 1) + * @max_cg: Maximum clock gear supported by this controller (default value: 10) + * @clkgear: Current clock gear in which this bus is running + * @laddr_ida: logical address id allocator + * @a_framer: Active framer which is clocking the bus managed by this controller + * @lock: Mutex protecting controller data structures + * @devices: Slim device list + * @tid_idr: tid id allocator + * @txn_lock: Lock to protect table of transactions + * @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. + * @get_laddr: It is possible that controller needs to set fixed logical + * address table and get_laddr can be used in that case so that controller + * can do this assignment. Use case is when the master is on the remote + * processor side, who is resposible for allocating laddr. + * + * 'Manager device' is responsible for device management, bandwidth + * allocation, channel setup, and port associations per channel. + * Device management means Logical address assignment/removal based on + * enumeration (report-present, report-absent) of a device. + * Bandwidth allocation is done dynamically by the manager based on active + * channels on the bus, message-bandwidth requests made by SLIMbus devices. + * Based on current bandwidth usage, manager chooses a frequency to run + * the bus at (in steps of 'clock-gear', 1 through 10, each clock gear + * representing twice the frequency than the previous gear). + * Manager is also responsible for entering (and exiting) low-power-mode + * (known as 'clock pause'). + * Manager can do handover of framer if there are multiple framers on the + * bus and a certain usecase warrants using certain framer to avoid keeping + * previous framer being powered-on. + * + * Controller here performs duties of the manager device, and 'interface + * device'. Interface device is responsible for monitoring the bus and + * reporting information such as loss-of-synchronization, data + * slot-collision. + */ +struct slim_controller { + struct device *dev; + unsigned int id; + char name[SLIMBUS_NAME_SIZE]; + int min_cg; + int max_cg; + int clkgear; + struct ida laddr_ida; + struct slim_framer *a_framer; + struct mutex lock; + struct list_head devices; + struct idr tid_idr; + spinlock_t txn_lock; + int (*set_laddr)(struct slim_controller *ctrl, + struct slim_eaddr *ea, u8 laddr); + int (*get_laddr)(struct slim_controller *ctrl, + struct slim_eaddr *ea, u8 *laddr); +}; + +int slim_device_report_present(struct slim_controller *ctrl, + struct slim_eaddr *e_addr, u8 *laddr); +void slim_report_absent(struct slim_device *sbdev); +int slim_register_controller(struct slim_controller *ctrl); +int slim_unregister_controller(struct slim_controller *ctrl); + +#endif /* _LINUX_SLIMBUS_H */ diff --git a/include/linux/slimbus.h b/include/linux/slimbus.h index 852cdb9f1abd..2f1081667b43 100644 --- a/include/linux/slimbus.h +++ b/include/linux/slimbus.h @@ -44,11 +44,14 @@ enum slim_device_status { SLIM_DEVICE_STATUS_RESERVED, }; +struct slim_controller; + /** * struct slim_device - Slim device handle. * @dev: Driver model representation of the device. * @e_addr: Enumeration address of this device. * @status: slim device status + * @ctrl: slim controller instance. * @laddr: 1-byte Logical address of this device. * @is_laddr_valid: indicates if the laddr is valid or not * @@ -59,6 +62,7 @@ enum slim_device_status { struct slim_device { struct device dev; struct slim_eaddr e_addr; + struct slim_controller *ctrl; enum slim_device_status status; u8 laddr; bool is_laddr_valid; @@ -120,4 +124,8 @@ static inline void slim_set_devicedata(struct slim_device *dev, void *data) { dev_set_drvdata(&dev->dev, 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); #endif /* _LINUX_SLIMBUS_H */ From patchwork Thu Nov 30 17:41:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 120260 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp89853qgn; Thu, 30 Nov 2017 09:46:05 -0800 (PST) X-Google-Smtp-Source: AGs4zMaWocwT4jD4gRmwMKpbpsI3nkkpncsH15PyCEQLli20bnlRPzYFLwiv28VhSgAYTcBk6aw7 X-Received: by 10.101.89.5 with SMTP id f5mr3135500pgu.370.1512063965858; Thu, 30 Nov 2017 09:46:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512063965; cv=none; d=google.com; s=arc-20160816; b=FUzq9sOhiq7eeL783S3YUXgQCReTYGNu521FtxYfNIDUHrTXY+9EITJIRbwlTOHVwa ijNPdzO7z1YXBRkdJdV5495a+8UO6p0EOdZtK8qJXNkcteHqIq4KpJuFiWh+bWldVYRF 8eCDvb2Rqz3zq8xSGW1UOxdjV8ll3laXKh5h8lmH0UuIh4JOiLvBAfDOCQW5RLLobfAv SH8dgkfuLDGp1wL3RRs+U7meOPaz6LiIZE1gJsi0CuFHi/OCIo55yqU40wTa/jvE4ASv w6Ah8v1AYSWlJrJFGJTwgtBIMxFsbaOHO2wpopNEO/VPG867kaQHSd1+4TQJnAN+fLor UMZw== 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=G9P/SKvsaVsATtWl4/EB59S0Mpjkj5OU/kcbV1pDHx8=; b=CAr+dr0GIEhgTxW23fKIHKEYSCiFjVeJIG037C/F1z9kmNnUybDMj57p5JqI9CuoPx PaMYwdxCBSqQWlUcAlZUMVaNpiTwZzzpA/7J0EmottTWRhlwxKsHYZytyYt9sohiMSLe CcPBmM5vOpDRqxBThhQnTVRWyTAP6zy3r3Dhwovx05u6Dk69lCO7fgA7YxS79CGlqsu+ HyEb5ItyRBYNAoXoglrKsz/m8/UCQJ1/aruWdUttTyKRRc6G6dFIlNXCDj1JgHctTec2 aDs+18AeQImPV0x2zI0OSElrRU0lIclaAQTvsOrh5Z5ZaOcpmFwzs1+5SkOTHpXwbPwO zFkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kWGM4kVn; 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; dmarc=pass (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 x10si3577916pfk.208.2017.11.30.09.46.05; Thu, 30 Nov 2017 09:46:05 -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=@linaro.org header.s=google header.b=kWGM4kVn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753933AbdK3RqB (ORCPT + 28 others); Thu, 30 Nov 2017 12:46:01 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:41293 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753902AbdK3Rp5 (ORCPT ); Thu, 30 Nov 2017 12:45:57 -0500 Received: by mail-wm0-f68.google.com with SMTP id g75so14735606wme.0 for ; Thu, 30 Nov 2017 09:45:56 -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=G9P/SKvsaVsATtWl4/EB59S0Mpjkj5OU/kcbV1pDHx8=; b=kWGM4kVn7o9j+Vm8dO3omaUnJEC2whQkbZ98pDoeY540jMDfTHVbCyHR9CpDV5pZL2 gZR2TVUH9TsxW8PTqg+nbgPga98W/zpG/AXT6RQKBngqKM0XQEqRi/lwIsB4Mh1i1CLG VMGdUGBoBkUFfuEPEycIxgqhk30D+DP+AomUg= 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=G9P/SKvsaVsATtWl4/EB59S0Mpjkj5OU/kcbV1pDHx8=; b=qw5CjHriLfuSzSWHGRJSPhNrgrv5K7Utj2QEDOy8uG5kbYP+vSXitBNKZIuRTG0eiR sJkmtvjb9iXKa5JedrziczZG2Odomo3Ux+gz0ddGo206Nj49A81QEQlen6SewHFYGuwC AZ4/gdp6ngDgZ0CxzFvETWsXoatq0xNAnIs9y7N7s7heILGOetB2K+9F/5cxHzkTKDWq xIF1DB4mdmAAgNmwAyTZ4dx1UzpabVFm15bpkLcUJT+dKDJIYnJKUMd6Nn9VAIWkVHau F4unpKu5SQ87r77/OBSeuy0d/qISgoG2y4Q19HTr6xBxVb/p70ONSaip81WY7LvIBLUG PZlw== X-Gm-Message-State: AJaThX5ql++RjmT0viW/BBzPISqyuyDpyWKVS4hYf0lDj8q7RZh8XDmq +x+RNEBuBrFljEO4gsGv/1p0Lg== X-Received: by 10.28.120.19 with SMTP id t19mr1352851wmc.64.1512063955278; Thu, 30 Nov 2017 09:45:55 -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 189sm2412189wmu.3.2017.11.30.09.45.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Nov 2017 09:45:54 -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@linaro.org Subject: [PATCH v8 05/13] slimbus: core: add support to device tree helper Date: Thu, 30 Nov 2017 17:41:52 +0000 Message-Id: <20171130174200.6684-6-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171130174200.6684-1-srinivas.kandagatla@linaro.org> References: <20171130174200.6684-1-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c index 41e83c15591a..0c66f76b1a85 100644 --- a/drivers/slimbus/core.c +++ b/drivers/slimbus/core.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "slimbus.h" @@ -120,6 +121,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, @@ -150,6 +154,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. * @@ -181,6 +229,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 Thu Nov 30 17:41:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 120262 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp89947qgn; Thu, 30 Nov 2017 09:46:10 -0800 (PST) X-Google-Smtp-Source: AGs4zMb4U5ma6UXBRs0CVVW6fHxB4oPbAbG3+eOnkJLhmAGKuDwfsrbTBqfLQMNCSxzG9R9WThym X-Received: by 10.98.34.199 with SMTP id p68mr7288954pfj.241.1512063970591; Thu, 30 Nov 2017 09:46:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512063970; cv=none; d=google.com; s=arc-20160816; b=fvdoxGHX+R0zjvvA0Sy7QAMJQJAxVM6JRRZoDLYe9zqkaHUTGBc6+0vmNiq/K7zjsC k5wi9q2NbCmwLJwQqaOl32PtXKeZ49BfJkgI3Ol84Gcwu6bcNQXDCyLUFTeFa4U/6+iN QfcYdvp4DyChT6mwz5RrYZvFZ4Re8/XODyN7LxV8DfVdLr4nrf+sigRFZ3O8/+NsZF31 Ug2z76GSrC/BqHrgXV/zsuL/jgXOSAvAq9DZmwfBvqYAWNcu7eDh8Ck0pBkAKYCVhks7 A/eDAPtKdhX8OJ5xY4heQ5wg5ZYYrNiRndpvKBXMnBJNDZhOwUJKZmz1HJMo4sxpFtvS BNkw== 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=YgGAa69yyWr01N2JttceMcXvKJsuFgu566SyWuQFg0g=; b=NeZS3GuPqcR3qOrWIEE3u8jJmAG/TJ+eJl+iied4pikVrWd3KxMSgxvk5bwedMSNG4 JPVhIKJUG4Z+3HHEHLFIs+xROp4XYByc6nEN8I8xCS6wh/qBRXB3OrIPR2aTk/C3CyTE 1HOPXIiY/1CZAiym+eP6hBKfXQKHBa+34nxQfxtxqnYX8E4WiNJ3Nl9rXuORi1E0sZ59 RuwhpaV3ttbB3LR+p8haY7x8CO6hRIXoEJXu18v5ZTqcRaTU5ftmH832Bk9Bu32pqQRs pAtRrg4WBrtaUvPAggGfmkA3SeTSOLAZu37PbSUCDErveZQbnwMUkgkly3Kry7yblCbD bqXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S6NimDUs; 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; dmarc=pass (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 x10si3577916pfk.208.2017.11.30.09.46.10; Thu, 30 Nov 2017 09:46:10 -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=@linaro.org header.s=google header.b=S6NimDUs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753985AbdK3RqJ (ORCPT + 28 others); Thu, 30 Nov 2017 12:46:09 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:32971 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753916AbdK3RqB (ORCPT ); Thu, 30 Nov 2017 12:46:01 -0500 Received: by mail-wr0-f193.google.com with SMTP id v22so7464788wrb.0 for ; Thu, 30 Nov 2017 09:46:00 -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=YgGAa69yyWr01N2JttceMcXvKJsuFgu566SyWuQFg0g=; b=S6NimDUsmEd8xkArG0mDxt9FYAQ336uCy2rCntCkhL68GoOvT3AIN2kc10OMTxlnff fOZnu8vW30vPtLrzo3W7ULu+KWQuCrCQwWrC9QE6XUUrfeM4dvkY9c7VguIzMKR+8838 JQx/07xOxEUnxBtPWrGasF9V7DiBS9LNVCh6E= 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=YgGAa69yyWr01N2JttceMcXvKJsuFgu566SyWuQFg0g=; b=onmx0y1yH4UkTVjZlXyHcbd+FCkuPWyuVukRNuLkSueytGHvmsprnLgPUjvBVUWzrg 3LyWIqTHj2H89sQB9Bb6YKqDDAT71Xi13aYLiaIl+QQNJwALqp3kCZ81sXbK7Q70NQy1 JsbM8qBJuw/p+IEy/h8TbmVHs4ArBdR+DxYYwcPl2badePedQNY/P3892MHl7TptCY1U VhntDs7rDhuNcdS88/EHkMGuxrf7LqAjPnkmjYW/WDso1FcchZy2wHBtVuX8MuAbgW7G 6TH0kSGOCCUfiVtyICK3Kb5eb7Z9gs2iPaQIuPAdr0IV7Bz0M8hCHGVsaDVR5Metnkq1 maAg== X-Gm-Message-State: AJaThX4P+vwyDkw8sfmaqcZ2DBP1gvu0YAVRfrpbaH5vXs/cM8yg+L8H KDorcSyDL4xwtOg0fh5mZ9zU4A== X-Received: by 10.223.142.143 with SMTP id q15mr2836900wrb.6.1512063959290; Thu, 30 Nov 2017 09:45:59 -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 189sm2412189wmu.3.2017.11.30.09.45.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Nov 2017 09:45:58 -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@linaro.org Subject: [PATCH v8 07/13] slimbus: Add support for 'clock-pause' feature Date: Thu, 30 Nov 2017 17:41:54 +0000 Message-Id: <20171130174200.6684-8-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171130174200.6684-1-srinivas.kandagatla@linaro.org> References: <20171130174200.6684-1-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sagar Dharia Per SLIMbus specification, a reconfiguration sequence known as 'clock pause' needs to be broadcast over the bus while entering low- power mode. Clock-pause is initiated by the controller driver. To exit clock-pause, controller typically wakes up the framer device. Since wakeup precedure is controller-specific, framework calls it via controller's function pointer to invoke it. Signed-off-by: Sagar Dharia Signed-off-by: Srinivas Kandagatla --- drivers/slimbus/Makefile | 2 +- drivers/slimbus/core.c | 16 ++++++ drivers/slimbus/messaging.c | 35 +++++++++++- drivers/slimbus/sched.c | 128 ++++++++++++++++++++++++++++++++++++++++++++ drivers/slimbus/slimbus.h | 53 ++++++++++++++++++ 5 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 drivers/slimbus/sched.c -- 2.15.0 diff --git a/drivers/slimbus/Makefile b/drivers/slimbus/Makefile index a65677ec3f7a..fd794f83d1cf 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 messaging.o +slimbus-y := core.o messaging.o sched.o diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c index 0c66f76b1a85..17485b0d0771 100644 --- a/drivers/slimbus/core.c +++ b/drivers/slimbus/core.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include "slimbus.h" @@ -225,6 +226,8 @@ int slim_register_controller(struct slim_controller *ctrl) ida_init(&ctrl->laddr_ida); idr_init(&ctrl->tid_idr); mutex_init(&ctrl->lock); + mutex_init(&ctrl->sched.m_reconf); + init_completion(&ctrl->sched.pause_comp); dev_dbg(ctrl->dev, "Bus [%s] registered:dev:%p\n", ctrl->name, ctrl->dev); @@ -256,6 +259,8 @@ int slim_unregister_controller(struct slim_controller *ctrl) { /* Remove all clients */ device_for_each_child(ctrl->dev, NULL, slim_ctrl_remove_device); + /* Enter Clock Pause */ + slim_ctrl_clk_pause(ctrl, false, 0); ida_simple_remove(&ctrl_ida, ctrl->id); return 0; @@ -423,6 +428,14 @@ int slim_device_report_present(struct slim_controller *ctrl, struct slim_device *sbdev; int ret; + ret = pm_runtime_get_sync(ctrl->dev); + + if (ctrl->sched.clk_state != SLIM_CLK_ACTIVE) { + dev_err(ctrl->dev, "slim ctrl not active,state:%d, ret:%d\n", + ctrl->sched.clk_state, ret); + goto slimbus_not_active; + } + sbdev = slim_get_device(ctrl, e_addr); if (IS_ERR(sbdev)) return -ENODEV; @@ -434,6 +447,9 @@ int slim_device_report_present(struct slim_controller *ctrl, ret = slim_device_alloc_laddr(sbdev, true); +slimbus_not_active: + pm_runtime_mark_last_busy(ctrl->dev); + pm_runtime_put_autosuspend(ctrl->dev); return ret; } EXPORT_SYMBOL_GPL(slim_device_report_present); diff --git a/drivers/slimbus/messaging.c b/drivers/slimbus/messaging.c index 7c12dc933816..5f3bab2cd9e3 100644 --- a/drivers/slimbus/messaging.c +++ b/drivers/slimbus/messaging.c @@ -10,6 +10,7 @@ * GNU General Public License for more details. */ #include +#include #include "slimbus.h" /** @@ -52,6 +53,10 @@ void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 len) memcpy(msg->rbuf, reply, len); if (txn->comp) complete(txn->comp); + + /* Remove runtime-pm vote now that response was received for TID txn */ + pm_runtime_mark_last_busy(ctrl->dev); + pm_runtime_put_autosuspend(ctrl->dev); } EXPORT_SYMBOL_GPL(slim_msg_response); @@ -71,10 +76,29 @@ EXPORT_SYMBOL_GPL(slim_msg_response); int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn) { DECLARE_COMPLETION_ONSTACK(done); - bool need_tid; + bool need_tid, clk_pause_msg = false; unsigned long flags; int ret, tid, timeout; + /* + * do not vote for runtime-PM if the transactions are part of clock + * pause sequence + */ + if (ctrl->sched.clk_state == SLIM_CLK_ENTERING_PAUSE && + (txn->mt == SLIM_MSG_MT_CORE && + txn->mc >= SLIM_MSG_MC_BEGIN_RECONFIGURATION && + txn->mc <= SLIM_MSG_MC_RECONFIGURE_NOW)) + clk_pause_msg = true; + + if (!clk_pause_msg) { + ret = pm_runtime_get_sync(ctrl->dev); + if (ctrl->sched.clk_state != SLIM_CLK_ACTIVE) { + dev_err(ctrl->dev, "ctrl wrong state:%d, ret:%d\n", + ctrl->sched.clk_state, ret); + goto slim_xfer_err; + } + } + need_tid = slim_tid_txn(txn->mt, txn->mc); if (need_tid) { @@ -113,6 +137,15 @@ int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn) dev_err(ctrl->dev, "Tx:MT:0x%x, MC:0x%x, LA:0x%x failed:%d\n", txn->mt, txn->mc, txn->la, ret); +slim_xfer_err: + if (!clk_pause_msg && (!need_tid || ret == -ETIMEDOUT)) { + /* + * remove runtime-pm vote if this was TX only, or + * if there was error during this transaction + */ + pm_runtime_mark_last_busy(ctrl->dev); + pm_runtime_mark_last_busy(ctrl->dev); + } return ret; } diff --git a/drivers/slimbus/sched.c b/drivers/slimbus/sched.c new file mode 100644 index 000000000000..74300f1a6898 --- /dev/null +++ b/drivers/slimbus/sched.c @@ -0,0 +1,128 @@ +/* Copyright (c) 2011-2016, 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_ctrl_clk_pause() - Called by slimbus controller to enter/exit + * 'clock pause' + * @ctrl: controller requesting bus to be paused or woken up + * @wakeup: Wakeup this controller from clock pause. + * @restart: Restart time value per spec used for clock pause. This value + * isn't used when controller is to be woken up. + * + * Slimbus specification needs this sequence to turn-off clocks for the bus. + * The sequence involves sending 3 broadcast messages (reconfiguration + * sequence) to inform all devices on the bus. + * To exit clock-pause, controller typically wakes up active framer device. + * This API executes clock pause reconfiguration sequence if wakeup is false. + * If wakeup is true, controller's wakeup is called. + * For entering clock-pause, -EBUSY is returned if a message txn in pending. + */ +int slim_ctrl_clk_pause(struct slim_controller *ctrl, bool wakeup, u8 restart) +{ + int i, ret = 0; + unsigned long flags; + struct slim_sched *sched = &ctrl->sched; + struct slim_val_inf msg = {0, 0, NULL, NULL}; + + DEFINE_SLIM_BCAST_TXN(txn, SLIM_MSG_MC_BEGIN_RECONFIGURATION, + 3, SLIM_LA_MANAGER, &msg); + + if (wakeup == false && restart > SLIM_CLK_UNSPECIFIED) + return -EINVAL; + + mutex_lock(&sched->m_reconf); + if (wakeup) { + if (sched->clk_state == SLIM_CLK_ACTIVE) { + mutex_unlock(&sched->m_reconf); + return 0; + } + + /* + * Fine-tune calculation based on clock gear, + * message-bandwidth after bandwidth management + */ + ret = wait_for_completion_timeout(&sched->pause_comp, + msecs_to_jiffies(100)); + if (!ret) { + mutex_unlock(&sched->m_reconf); + pr_err("Previous clock pause did not finish"); + return -ETIMEDOUT; + } + ret = 0; + + /* + * Slimbus framework will call controller wakeup + * Controller should make sure that it sets active framer + * out of clock pause + */ + if (sched->clk_state == SLIM_CLK_PAUSED && ctrl->wakeup) + ret = ctrl->wakeup(ctrl); + if (!ret) + sched->clk_state = SLIM_CLK_ACTIVE; + mutex_unlock(&sched->m_reconf); + + return ret; + } + + /* already paused */ + if (ctrl->sched.clk_state == SLIM_CLK_PAUSED) { + mutex_unlock(&sched->m_reconf); + return 0; + } + + spin_lock_irqsave(&ctrl->txn_lock, flags); + for (i = 0; i < SLIM_MAX_TIDS; i++) { + /* Pending response for a message */ + if (idr_find(&ctrl->tid_idr, i)) { + spin_unlock_irqrestore(&ctrl->txn_lock, flags); + mutex_unlock(&sched->m_reconf); + return -EBUSY; + } + } + spin_unlock_irqrestore(&ctrl->txn_lock, flags); + + sched->clk_state = SLIM_CLK_ENTERING_PAUSE; + + /* clock pause sequence */ + ret = slim_do_transfer(ctrl, &txn); + if (ret) + goto clk_pause_ret; + + txn.mc = SLIM_MSG_MC_NEXT_PAUSE_CLOCK; + txn.rl = 4; + msg.num_bytes = 1; + msg.wbuf = &restart; + ret = slim_do_transfer(ctrl, &txn); + if (ret) + goto clk_pause_ret; + + txn.mc = SLIM_MSG_MC_RECONFIGURE_NOW; + txn.rl = 3; + msg.num_bytes = 1; + msg.wbuf = NULL; + ret = slim_do_transfer(ctrl, &txn); + +clk_pause_ret: + if (ret) { + sched->clk_state = SLIM_CLK_ACTIVE; + } else { + sched->clk_state = SLIM_CLK_PAUSED; + complete(&sched->pause_comp); + } + mutex_unlock(&sched->m_reconf); + + return ret; +} +EXPORT_SYMBOL_GPL(slim_ctrl_clk_pause); diff --git a/drivers/slimbus/slimbus.h b/drivers/slimbus/slimbus.h index 5a83ce15c63a..e0ae7bb1ba47 100644 --- a/drivers/slimbus/slimbus.h +++ b/drivers/slimbus/slimbus.h @@ -21,6 +21,16 @@ /* SLIMbus message types. Related to interpretation of message code. */ #define SLIM_MSG_MT_CORE 0x0 +/* Clock pause Reconfiguration messages */ +#define SLIM_MSG_MC_BEGIN_RECONFIGURATION 0x40 +#define SLIM_MSG_MC_NEXT_PAUSE_CLOCK 0x4A +#define SLIM_MSG_MC_RECONFIGURE_NOW 0x5F + +/* Clock pause values per SLIMbus spec */ +#define SLIM_CLK_FAST 0 +#define SLIM_CLK_CONST_PHASE 1 +#define SLIM_CLK_UNSPECIFIED 2 + /* Destination type Values */ #define SLIM_MSG_DEST_LOGICALADDR 0 #define SLIM_MSG_DEST_ENUMADDR 1 @@ -87,6 +97,42 @@ struct slim_msg_txn { #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, } + +#define DEFINE_SLIM_BCAST_TXN(name, mc, rl, la, msg) \ + struct slim_msg_txn name = { rl, 0, mc, SLIM_MSG_DEST_BROADCAST, 0,\ + 0, la, msg, } +/** + * enum slim_clk_state: SLIMbus controller's clock state used internally for + * maintaining current clock state. + * @SLIM_CLK_ACTIVE: SLIMbus clock is active + * @SLIM_CLK_ENTERING_PAUSE: SLIMbus clock pause sequence is being sent on the + * bus. If this succeeds, state changes to SLIM_CLK_PAUSED. If the + * transition fails, state changes back to SLIM_CLK_ACTIVE + * @SLIM_CLK_PAUSED: SLIMbus controller clock has paused. + */ +enum slim_clk_state { + SLIM_CLK_ACTIVE, + SLIM_CLK_ENTERING_PAUSE, + SLIM_CLK_PAUSED, +}; + +/** + * struct slim_sched: Framework uses this structure internally for scheduling. + * @clk_state: Controller's clock state from enum slim_clk_state + * @pause_comp: Signals completion of clock pause sequence. This is useful when + * client tries to call SLIMbus transaction when controller is entering + * clock pause. + * @m_reconf: This mutex is held until current reconfiguration (data channel + * scheduling, message bandwidth reservation) is done. Message APIs can + * use the bus concurrently when this mutex is held since elemental access + * messages can be sent on the bus when reconfiguration is in progress. + */ +struct slim_sched { + enum slim_clk_state clk_state; + struct completion pause_comp; + struct mutex m_reconf; +}; + /** * struct slim_controller - Controls every instance of SLIMbus * (similar to 'master' on SPI) @@ -102,6 +148,7 @@ struct slim_msg_txn { * @devices: Slim device list * @tid_idr: tid id allocator * @txn_lock: Lock to protect table of transactions + * @sched: scheduler structure used by the controller * @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. @@ -112,6 +159,9 @@ struct slim_msg_txn { * address table and get_laddr can be used in that case so that controller * can do this assignment. Use case is when the master is on the remote * processor side, who is resposible for allocating laddr. + * @wakeup: This function pointer implements controller-specific procedure + * to wake it up from clock-pause. Framework will call this to bring + * the controller out of clock pause. * * 'Manager device' is responsible for device management, bandwidth * allocation, channel setup, and port associations per channel. @@ -146,12 +196,14 @@ struct slim_controller { struct list_head devices; struct idr tid_idr; spinlock_t txn_lock; + struct slim_sched sched; 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, struct slim_eaddr *ea, u8 *laddr); + int (*wakeup)(struct slim_controller *ctrl); }; int slim_device_report_present(struct slim_controller *ctrl, @@ -161,6 +213,7 @@ 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); +int slim_ctrl_clk_pause(struct slim_controller *ctrl, bool wakeup, u8 restart); static inline bool slim_tid_txn(u8 mt, u8 mc) { From patchwork Thu Nov 30 17:41:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 120265 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp90096qgn; Thu, 30 Nov 2017 09:46:19 -0800 (PST) X-Google-Smtp-Source: AGs4zMYEO+pWYWKSPpNvgQTWWOKTUqK8y3nKCFC4V84ZAqq/SZDxzZsnn6valZd7jqd+LsE65HvI X-Received: by 10.159.195.12 with SMTP id bd12mr3484864plb.14.1512063979371; Thu, 30 Nov 2017 09:46:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512063979; cv=none; d=google.com; s=arc-20160816; b=uP4rusHxu42G8GC6zye2LslTRC6kgvoOzYgJASy6zgabdYBYK/LmQnys0NKZQ1myhl KErSXk5Y7Eai5JvZmnl32WSO3p3s7jQZLbaGdHDvHW1U5QqMaI4Z2m6XiuOivdeQLOdM 5bMY5O090965RziOMtnnjFXmcJVQj6XXN12QB81TqQgvQj0M9eWEYnEfutbS+Sl89vlc 9rx+no7ZUFcIzUdE8RGMZBZbz63hXHoz/9P/h3961C30ySjiI/aCX+/dc/pwMib3zC/R 1W9/fa5zvQ2Rg4mSJr83yHlDceg+gvJO6gXT9cHRUUjN7lHyeTr/HOzSprTEHzONZAjt /MnQ== 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=MQex56jFB/jBMT1c7EpZ12WTINTo1UOCdc2vpO79A18=; b=GNTlKV8Yybe6cIveb9+Lcic0eSqsSZ/JUCX3caRrOFOgFFRxI2wmzjCqKAXdDuJA0m EFA2aaNPNtkwnXWjwllB2+KQ/MUdJFC+rrYRuVeInQDd3LuKcEwFVOOPGgZ4C+jqBuFx 6j5l17M6t0JT96Vk3j9Vw9uDgDMNMnGhBmQla5OGLokvgr6xUaYUDiJx4rlpp1jLoMwm FcT17XpfaR/WCoDynC+nAbkMZ9nhkhkn3mykq50xoFd/5y2BF7mjjm+3NBWeAxIc5bjv 6JhBi5HApvlQNK55SxM4iCKGmNS6f6ieX9xaxxKuH6goJCl74aU6hrPxIj1gxQ5g1ZZD R1Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GQ+UuEJh; 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; dmarc=pass (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 l8si3374193pga.538.2017.11.30.09.46.19; Thu, 30 Nov 2017 09:46:19 -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=@linaro.org header.s=google header.b=GQ+UuEJh; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754002AbdK3RqQ (ORCPT + 28 others); Thu, 30 Nov 2017 12:46:16 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36144 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753978AbdK3RqI (ORCPT ); Thu, 30 Nov 2017 12:46:08 -0500 Received: by mail-wm0-f66.google.com with SMTP id b76so14015806wmg.1 for ; Thu, 30 Nov 2017 09:46:08 -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=MQex56jFB/jBMT1c7EpZ12WTINTo1UOCdc2vpO79A18=; b=GQ+UuEJhPYn5PuD3oc8JqiENWvJrDS9t9+viDoc7jJKMMRBOi60gcX7zIK5nGwBGDM UqCY/jywJXx6r/4wtCQM/ym5qzTCxpTSUGNTGe/3A5K7gn/JJPycBL6g15efoiMZqqPM mSWkGbxXFpiCj/au+TvKqsIV1TvxVP7eUKr6k= 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=MQex56jFB/jBMT1c7EpZ12WTINTo1UOCdc2vpO79A18=; b=YOokZ880AaNYRM2gooPh9jQro5AKMWWttaL5C0ht8btSVWhaa/x/J4X/AJkEw8ZRwR XzJWpzzux/jisu2bkNeiWTnH5vVDjOx2Ai95acQnJGeeOeq4PC0eqRovbjxgztmqTMRI jChVObGYYJQZGpW2Gils8YNUwW2tpxkXLeP8a8++m/Rc4lRgwrFWLIET183OQv1q8Bd4 /pFXULrEb9FaXqiAEaebwvEITe/J3UnoPZe+wSe1lYWNXPoE+Qqs5Su5ykBrfz+d91L4 6Wueix4xcbYQ0cwPS/ZOzmROAJgWBlElChx6+ekWcUyaYfAiyEqQiwaZ+BtZt3MRFysg Rg1g== X-Gm-Message-State: AJaThX5vpc//QvTyzoW/2rPvclwpKnk4zKjIIoblN0RIA+D7moZXhj1c MLI1Xm9ZzSONNTMBBAswuIplXQ== X-Received: by 10.28.0.199 with SMTP id 190mr2411890wma.143.1512063967320; Thu, 30 Nov 2017 09:46:07 -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 189sm2412189wmu.3.2017.11.30.09.46.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Nov 2017 09:46:06 -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@linaro.org Subject: [PATCH v8 12/13] slimbus: qcom: Add runtime-pm support using clock-pause Date: Thu, 30 Nov 2017 17:41:59 +0000 Message-Id: <20171130174200.6684-13-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171130174200.6684-1-srinivas.kandagatla@linaro.org> References: <20171130174200.6684-1-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 | 101 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 3 deletions(-) -- 2.15.0 diff --git a/drivers/slimbus/qcom-ctrl.c b/drivers/slimbus/qcom-ctrl.c index af7b109e3d28..8c05346cd69c 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 @@ -281,6 +283,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) { @@ -517,6 +543,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; @@ -624,14 +651,81 @@ 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); + } + + 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( @@ -653,6 +747,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); From patchwork Thu Nov 30 17:42:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 120266 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp90112qgn; Thu, 30 Nov 2017 09:46:20 -0800 (PST) X-Google-Smtp-Source: AGs4zMa4EUsKu7Tbzs4bXQYGDm0gcSPHG7KDEKOUOg6JeWFPIO78Ds2uZ3QLovvsaqykW1pZREXb X-Received: by 10.159.255.7 with SMTP id bi7mr3359018plb.221.1512063980110; Thu, 30 Nov 2017 09:46:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512063980; cv=none; d=google.com; s=arc-20160816; b=EJ5S3ZmutSK8cPE24MPU1SLq9X8qB7/Wpq1w0Joe19E5obS+ygdIluFqAH/VDWFOrB tIAjmokXDRFN2x9MPSp43QOHjX//g5uWz6p9LHEoVMdJo/fpVuILU9CvyLXRdHUhsRWg Si6hlhx9g9KLLJ/cMkRyZYt28Gws5KalnynEuhRUX3CTdUxskp3L5seGbIrUompKuWbp NG0+u9ZIEWmC0IEplMZYNj0olnn45qmYITJPM0lXshwOEgBTeBfCzEMC+Ntl9h0A8aB8 ZOhZpxfHRD5CZB3hR42uxDI3q8LYnOPbBeqMXy9HAjzi8Glx2KMkJE/QUHDoDBCH4pdb MV1A== 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=oN+gQMaYSPqgunueWNmVACOEPNkRbvNrlCZeAnHBNLQ=; b=VBbY+YMIR/C37Kf9Js7B/O1rQ/M91eP4D1CQ1LBzSlk6ALnMhpnDk3IFJ3WuxqOKp4 ruVaxAwJRbT9JWd9Fk/Fu27ZTFaFJThOsCMO0NhtoWJlBJ6fuTqlMtov4tkRjGCIbzbi 3EkVqWLq6BGfS4LnVauNHE00otYJqREmbzpC0qSuPsmHe7cIp5zHNcrMsM04vWfdXg89 Lf4TMNzG54tomt6sfswGjCzltAblBL4l+HBNqvFPvwWnPcWSFeEqUB5G6diH+TlXftUw +TJIizDaq+9GW4ZrAgdX1oWOkTgwsOPiDo1SyICbxgSFdxdDHjLxXPIOyJD1Jc9Dv9+K j25g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZnsM5y7j; 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; dmarc=pass (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 l8si3374193pga.538.2017.11.30.09.46.19; Thu, 30 Nov 2017 09:46:20 -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=@linaro.org header.s=google header.b=ZnsM5y7j; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754018AbdK3RqS (ORCPT + 28 others); Thu, 30 Nov 2017 12:46:18 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34460 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753987AbdK3RqK (ORCPT ); Thu, 30 Nov 2017 12:46:10 -0500 Received: by mail-wm0-f66.google.com with SMTP id y82so2482905wmg.1 for ; Thu, 30 Nov 2017 09:46:09 -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=oN+gQMaYSPqgunueWNmVACOEPNkRbvNrlCZeAnHBNLQ=; b=ZnsM5y7jsHbZCj/RfAbPvdZjtMrukWdTvX+ukXARk7js6u6kCCHltjEw0sK1YP/CZR vIX9AtPv6cujTfFSmqx02zRuuGv1iRn6RQI5R93olBLpXZLJRcF2v31CAyE+cTJI9Onh M/FQqjr6ofcJi7b08b6enVQ9tboDxhkItQ4wI= 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=oN+gQMaYSPqgunueWNmVACOEPNkRbvNrlCZeAnHBNLQ=; b=kUxTFqwxEFOkpeYBCpSDTbrp85R5FIGW0BrHKQogW5KO7L6nOYDAZL1TqwiMAWXh2U CSFexjJlsjB66obdixGAmSJAUqFN9PonGULTnBHPrlbAf6A7z4pDF7mMCDhn62VCAx5O ZwRae4613UhqznLgA7i4MGQOu+oS4jrIhGYBarWDoCdzVtdc0Mq+TIeWsqQJVlw8fYRV uYnFZfiOenapqKN3TNhXzZ4zm5Z1O5UE0XTd83f1Om00JJyK9R8PdyY7RBktGljfXCUP bQVc2ps9yGfXbIy4ii/dsXQAC0h0Pi3nXwZGB4JWcI22HwZM1ME14tkY74kHJ15KA7eE Ix7Q== X-Gm-Message-State: AJaThX6EPuTSoXudmnLoHXwTKdcZsjjy54wmqKqMv8S3PfBGr//trari fW3CVV5SGAijjsT/YQYMs5b6BQ== X-Received: by 10.28.55.71 with SMTP id e68mr1326187wma.139.1512063968877; Thu, 30 Nov 2017 09:46:08 -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 189sm2412189wmu.3.2017.11.30.09.46.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Nov 2017 09:46:08 -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@linaro.org Subject: [PATCH v8 13/13] MAINTAINERS: Add SLIMbus maintainer Date: Thu, 30 Nov 2017 17:42:00 +0000 Message-Id: <20171130174200.6684-14-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171130174200.6684-1-srinivas.kandagatla@linaro.org> References: <20171130174200.6684-1-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Srinivas Kandagatla Add myself as maintainer for slimbus. Signed-off-by: Srinivas Kandagatla Acked-by: Bjorn Andersson --- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.15.0 diff --git a/MAINTAINERS b/MAINTAINERS index aa71ab52fd76..f26bf2707709 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12500,6 +12500,14 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git F: include/linux/srcu.h F: kernel/rcu/srcu.c +SERIAL LOW-POWER INTER-CHIP MEDIA BUS (SLIMbus) +M: Srinivas Kandagatla +L: alsa-devel@alsa-project.org (moderated for non-subscribers) +S: Maintained +F: drivers/slimbus/ +F: Documentation/devicetree/bindings/slimbus/ +F: include/linux/slimbus.h + SMACK SECURITY MODULE M: Casey Schaufler L: linux-security-module@vger.kernel.org