From patchwork Mon Dec 11 23:42:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 121477 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3430835qgn; Mon, 11 Dec 2017 15:45:33 -0800 (PST) X-Google-Smtp-Source: ACJfBovgrPcYLjHsPx/z5lFK+b+KJO3z2RHV5cqXLhFPBEu6jBGESuLcXSxqBaMJ2o/DGUqOc1Ji X-Received: by 10.84.131.161 with SMTP id d30mr277720pld.332.1513035933077; Mon, 11 Dec 2017 15:45:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513035933; cv=none; d=google.com; s=arc-20160816; b=GOFuMheQlzdzlT8RNMLlxhh07jZVvqbQQ4uLheJo+A+KJgIEfTkBB6czRRMpUWa3gT a+Fu0IjDVMZcIpcsjiJmSx7Z79OKtO1HitlsykyLVQfJDDSx6ANmtj6xCDgVyUcVGbb5 pAEmJvQF/YjgHCwsg3NQ8tpYeR5RL1CUz85hVMMVW5grIILzvcYYQ7evGzh2QfAhm8g+ m7xADwdFypiX3FeFgCfpFanHCAwOVR1N61+3kBLff9ARfmExQUrugW1R1FoPxd0ZQpv9 Te+31Z8uCbMtfxjjSsBpbzFBrQVtz4Y1FKxVS5XEBD+ciE63WjUno5dalKIcylE5Wqji uwjQ== 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=n+h+cXEK073aTzJwNFSC+2mNN6cCjck4a5aAkrExguA=; b=PSFNa6OsR8mqm9bwbB/7f0MVah0SpKLqmWEVmgvu7AIyFbb4sUOFps4p+O9GdLyZQZ mmkRXpDRq+th5HbjeJQC8YHUpQM3VXrqoI2Zj32CMk+baXHgF7dNTFh5HcVXDaOm7TbT E2ijHdysSlEZ05jq+WsED/HY+lrDDm59iEJ/DehrZ/Bzwhb9d/fCbjGjvDQW6IAFWrcr HW6JqyfmCxNhw+OyypKGH0h+07BkEppuScyDMvXGeSXOras3X85+Sh1/9pn/B2dzh873 30DF92t+0+YfifHt+OxJoHp3Pdhv0+ocl3Mt5QWurQjtyRnibuDrDpN2JfuOxefEKrOK pQOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kz4Nyw9p; 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 u73si11754108pfi.245.2017.12.11.15.45.32; Mon, 11 Dec 2017 15:45:33 -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=kz4Nyw9p; 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 S1752573AbdLKXpb (ORCPT + 19 others); Mon, 11 Dec 2017 18:45:31 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36029 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752336AbdLKXpU (ORCPT ); Mon, 11 Dec 2017 18:45:20 -0500 Received: by mail-wm0-f68.google.com with SMTP id b76so17303423wmg.1 for ; Mon, 11 Dec 2017 15:45:20 -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=n+h+cXEK073aTzJwNFSC+2mNN6cCjck4a5aAkrExguA=; b=kz4Nyw9p2XHHMl/sA7ELmKs+p8caTHjH43V/5wYYJPb8d7iO6UanzouBnExo9gryEp h2tFcLpnAS5LISjMzVqtMlvrDfpCWmQ0/fMQRqfVNXVpBf9LoHx3Eb+jQrlhtnFKz7dJ EJa0DBcxfKK++N9EbzMt1I83j7TBrDHMe2+fM= 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=n+h+cXEK073aTzJwNFSC+2mNN6cCjck4a5aAkrExguA=; b=IcumVeJ1p+AyWgSkZHa/o6UdQ8ZghMKu4Ej4oVaHK0y98uZYWQgtjcJKaUUneNnnGr iThsB4aW1qvrf/TvqFep5psAKEvrgYDYQ4tR5RnJ8fIV11CQItk58x+krfbh9hOUBEMd 6jaieGrNjQp72AbPAbgmC34Z7v3B/Vv4hEk1qn/K093cC6OAbJ7G7UOa4PK8UHGlzvaY +RXw14t5SYsVo2BM12Yr4COKY3ue/SN3FkRRY0s6c5SHhfPqtVVpGx/vep9WN4rilNFY wTXpjwibZF5ZRRpSyljiVlE6ulTyI1bGdFcyilvlWiJcE1n18bhAr72MQvGf+hSXg9bm Fb+A== X-Gm-Message-State: AKGB3mIhIZD0rEhGYDcK5v9iRyFBOAmFESmCMGKRA2+6/Vtfne+0CCJ7 Eg0SkHgfvCxe4kdTKxiom8uY4A== X-Received: by 10.28.66.145 with SMTP id k17mr35148wmi.32.1513035919220; Mon, 11 Dec 2017 15:45:19 -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 k69sm10673615wmg.8.2017.12.11.15.45.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Dec 2017 15:45:18 -0800 (PST) From: srinivas.kandagatla@linaro.org To: Mark Brown , Greg Kroah-Hartman , alsa-devel@alsa-project.org Cc: sdharia@codeaurora.org, Rob Herring , Mark Rutland , Jonathan Corbet , pombredanne@nexb.com, j.neuschaefer@gmx.net, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH v10 04/13] slimbus: core: Add slim controllers support Date: Mon, 11 Dec 2017 23:42:58 +0000 Message-Id: <20171211234307.14465-5-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171211234307.14465-1-srinivas.kandagatla@linaro.org> References: <20171211234307.14465-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 | 108 ++++++++++++++++ include/linux/slimbus.h | 8 ++ 3 files changed, 422 insertions(+) create mode 100644 drivers/slimbus/slimbus.h -- 2.15.0 diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c index 02f5075a9309..ed53ae6bd1cc 100644 --- a/drivers/slimbus/core.c +++ b/drivers/slimbus/core.c @@ -7,7 +7,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) @@ -92,6 +96,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..66657722f50f --- /dev/null +++ b/drivers/slimbus/slimbus.h @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2011-2017, The Linux Foundation + */ + +#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 6b4ed290fbb0..aeed98a683be 100644 --- a/include/linux/slimbus.h +++ b/include/linux/slimbus.h @@ -37,11 +37,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 * @@ -52,6 +55,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; @@ -113,4 +117,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 Mon Dec 11 23:43:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 121478 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3431039qgn; Mon, 11 Dec 2017 15:45:50 -0800 (PST) X-Google-Smtp-Source: ACJfBovThxv1tJkTeCDkeB2epaFBeciENzr9Qt6yyYy6SLO0IEpzKNvQx1nc6LXg43ak1EZ8jdaC X-Received: by 10.159.230.3 with SMTP id u3mr281194plq.2.1513035950195; Mon, 11 Dec 2017 15:45:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513035950; cv=none; d=google.com; s=arc-20160816; b=UJiuV13N2erfxVc8zIQwFnDvs8Qz+H7/KAYVBArBBbVfNrEafsZc9eUesx6EXllgvJ tj96ImCnqxX7CxJmixvvsCTn470xZLx/3sdhSlbox6Kk1orspyV8CZFjw8HHTLZo470Z Xz0qYNeaQc+hRXhUfJsJDdB9Po19sK1508CW1Ud/NioFWMc+Wwo5Vg6/IbJ7O6ZJ8LAi 9wKw8vscilLCAuQu6PobJ5ji5leyTzsdZYYUjRuawEaT4DwX4CJwK95E7TYeupeoH80N Iyziz8Lp+/Ea3RksAHDbKnyl3axAk0Q7qdcCmFLjvqtJTSR+O6FQIzIE/JgcdjiEdGnH 2RAA== 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=ERc6jD/GqMasHUaMgGiPYtVC+zp11tYtnn8PjLR6U9I=; b=q/NAN5Z2g8UdmDkQtsmFCo6FQ+6TJm7GkYhtv71HUhrDvwkSYTJofA6D4gSFjazS9C 4UyR+Xq8z+A1zyUxp2b2nd+QVNgtndTrsbRk8C9NVwk13VhFjVXnmFLe3/9SUaVE316z Wza7OY7xWpAHSl2nFgep9dr6SprFItGHMzTPX3VELxiHrd6wu4jk8fDdIKcxMxtqn9Du oXHO/VjKq9qWSrij2B1yNaafZ5nnLZOi45XHCG/seNxkbQJTvBBhh2mAZKvzucOH3q3D V28jCFOfVpSOw//obZDe7B4t20DPfCnPZw2qohw9ouioyINIEKiF3T6dJZP4y4hccT2G xy1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZBkOyVtX; 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 d18si10735824pll.191.2017.12.11.15.45.49; Mon, 11 Dec 2017 15:45:50 -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=ZBkOyVtX; 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 S1752598AbdLKXps (ORCPT + 19 others); Mon, 11 Dec 2017 18:45:48 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33056 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752515AbdLKXpa (ORCPT ); Mon, 11 Dec 2017 18:45:30 -0500 Received: by mail-wm0-f67.google.com with SMTP id g130so15251369wme.0 for ; Mon, 11 Dec 2017 15:45:29 -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=ERc6jD/GqMasHUaMgGiPYtVC+zp11tYtnn8PjLR6U9I=; b=ZBkOyVtXNJSaf+2RebivlFfHsYw36L+hFP4Rm/Shp3vwXQdLd+QtLDGiYwU0gwDUHV fISIm1J4mdg5i994pTP9pZZQNoR8mfWhJBujof6TXz6Uqts2XhBxrGx1dlAADNXKPGJI gwOJhLAo3HA0xzNjcFd018s23gUzAaIC/fBnE= 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=ERc6jD/GqMasHUaMgGiPYtVC+zp11tYtnn8PjLR6U9I=; b=GBC0kER9fMyLREJKKjKScglkEQO4bW4DMhAhp3kViX9VMQd+dCpkDuT97vbfdOQul8 npEGXSdPBepfY/fqmlQ3O2HTktSl68UW4bYG3Grj+ydHFErh1/9arH8599zM7EJQgLS7 AnOh9P7V1e0pgBe8freRhH/obFzjUXE4CQk+7D0LVxYTPemZ3/XWhLoKj2ZdPjaoOGDw XKTR9+uB82c5KRNMEKUJgjQX56ccBXTsWl0GttpxX91dsEgOdZxLyEB5ZrFd8Q7U2sir yhbXCG/V8GqxfhDdEZ5vJBPFsY1X6fXoRE3PjNSQofNgizQR8vEknfPHT3l4i9dePs7V Cpwg== X-Gm-Message-State: AKGB3mKdSnWPhv221wc522oY58zW2kR+gqdCRK3b8jPNvSCqaqNikj3X s5eaTRpSGKjvhseJ+0OPNFJr4Q== X-Received: by 10.28.108.3 with SMTP id h3mr12175wmc.129.1513035929000; Mon, 11 Dec 2017 15:45:29 -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 k69sm10673615wmg.8.2017.12.11.15.45.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Dec 2017 15:45:28 -0800 (PST) From: srinivas.kandagatla@linaro.org To: Mark Brown , Greg Kroah-Hartman , alsa-devel@alsa-project.org Cc: sdharia@codeaurora.org, Rob Herring , Mark Rutland , Jonathan Corbet , pombredanne@nexb.com, j.neuschaefer@gmx.net, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH v10 12/13] slimbus: qcom: Add runtime-pm support using clock-pause Date: Mon, 11 Dec 2017 23:43:06 +0000 Message-Id: <20171211234307.14465-13-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171211234307.14465-1-srinivas.kandagatla@linaro.org> References: <20171211234307.14465-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 ace85ce3de90..35ad70dbfe3a 100644 --- a/drivers/slimbus/qcom-ctrl.c +++ b/drivers/slimbus/qcom-ctrl.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "slimbus.h" /* Manager registers */ @@ -65,6 +66,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 @@ -275,6 +277,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) { @@ -511,6 +537,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; @@ -618,14 +645,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( @@ -647,6 +741,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 Mon Dec 11 23:43:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 121479 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3431079qgn; Mon, 11 Dec 2017 15:45:53 -0800 (PST) X-Google-Smtp-Source: ACJfBovG1L68IbfKiN/HxbtRrPjDm2Wl80Tanv1h42W8QgnkzIM/4v7LbMYpOzs17fvYNj15txD3 X-Received: by 10.84.143.131 with SMTP id 3mr270150plz.113.1513035953122; Mon, 11 Dec 2017 15:45:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513035953; cv=none; d=google.com; s=arc-20160816; b=dzyomPVVtP5acK2Gny/4Mh62/yZmZQFpmQb2u6nZZgnMKv2eb3DHP3n53k3Z02lqYb Ea6iN+v4UiJmuQF/BMK5Hp/IAcHjV10MuevGgiTkpreiSXPzaV56wFssLfe0wVYqdOXB VKbrTdU38If9ugJEZhHAIlkHuT7ErBcRM++zMgvI0rPri6zMIeETrVXGzGhQxl+rFvQc 5tRFDMGW2Dw5Xo9/gWEgHIyHhvbn9gm8lFtfuWv+yUIXngBWIL8PaqoWUtnvr990UWbL ThOcj9tVzPFJ2slBrgRZ+qfxaXlXakbG9Pd+KR9lrXeQVXRH1jqBIS+/t7+dwz6FF7Au poDw== 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=MBEWDGmoZHEJPqxHQkU9G0sGTss42tX5/FBqb/MJkxHCfGMUvIogckHr0/k/BO+Jv1 nLxNyHyCdWrhF9HcePoeyzCyi6tOR+AwsTKfOe4OUHcfyzJ3Q/yvACS1uwAhkZ1+1xBk j+idVy74qJlkaupi8nFWaRK+hCO0hTdgdz/EdrZaM1LJkNggZE9KwcX22Y8y3NSySmI0 uMvMVW1kP7XWNafr27MmLYhiiPZjYpgDrtC8DVTuY1L2vAgSAiUS3OuHhKdfX19ohgYI nIddmugzXAFG6u0miyVwxIgPP6WzBZdtI1Gfe+y6AAIRuLv36+d6YIBuzqqxhzetmuEB k+7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xn0Y81Dw; 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 u192si10443218pgb.585.2017.12.11.15.45.52; Mon, 11 Dec 2017 15:45:53 -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=Xn0Y81Dw; 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 S1752617AbdLKXpv (ORCPT + 19 others); Mon, 11 Dec 2017 18:45:51 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36050 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752556AbdLKXpb (ORCPT ); Mon, 11 Dec 2017 18:45:31 -0500 Received: by mail-wm0-f68.google.com with SMTP id b76so17303906wmg.1 for ; Mon, 11 Dec 2017 15:45:31 -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=Xn0Y81Dwx39sK2RVFXsVILatrnU6IKDqCRr26hffCrzkdqjrfxOJWiGa7ceXDi3RqZ 23GTC/ly/DzMkegds+Lld21d0PfBiskR+psc66k5O8FSuoM74zsuwg6nwv2WaGmO68xA JL99wWXZX+7JDF1P8HAwDskig9XyoH5Z0dBGI= 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=YOMl2wwp8ezYcFX7EcgDexWRHDHLEfbhcB6I/ZtcpwBtm8L8R04ZmZ9/d4+cNimdht fSTHjVgLb/Q6DVSLS5hzEBVcozm4o6E+uZmVGy018QaAZuU6xFkhuLLU7ChrFAJeAjrz CL/cynVHwqefBWuXjG8+b8DeFZh1hb4MJy6o8HTkQbED4OMX8Ep8nsxZuoEEfsLUqcLj CxJLIDvLWJFNuz2scq9J193EnhGuRwidJ+hsKfjF3aW53dPWvc20ns1eaiordTid+wcq 5mcqVPvmkOOjjtkJk2ISL3e4hBK4zL6Fw/HmGRpH0MQJh+BhfFW7Nqi5rv237OCfyiqi mbnw== X-Gm-Message-State: AKGB3mL08RKlJ5z7SCRsWeqgIl5VnnmCZ0tPMop2dPU+tFEUqZU6f25f W4CR/uXMbtl1wJp3JoF1wzdh0A== X-Received: by 10.28.110.26 with SMTP id j26mr33993wmc.46.1513035930020; Mon, 11 Dec 2017 15:45:30 -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 k69sm10673615wmg.8.2017.12.11.15.45.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Dec 2017 15:45:29 -0800 (PST) From: srinivas.kandagatla@linaro.org To: Mark Brown , Greg Kroah-Hartman , alsa-devel@alsa-project.org Cc: sdharia@codeaurora.org, Rob Herring , Mark Rutland , Jonathan Corbet , pombredanne@nexb.com, j.neuschaefer@gmx.net, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH v10 13/13] MAINTAINERS: Add SLIMbus maintainer Date: Mon, 11 Dec 2017 23:43:07 +0000 Message-Id: <20171211234307.14465-14-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171211234307.14465-1-srinivas.kandagatla@linaro.org> References: <20171211234307.14465-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