From patchwork Thu Sep 28 13:11:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 114431 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp728052qgf; Thu, 28 Sep 2017 06:14:51 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCjvL/mgnyDtnZeG0qGll2n9wSjt/X5TK7FgCNzGRjKZTr8j/e/C1EjZbgg53SwhBdwd76h X-Received: by 10.98.10.12 with SMTP id s12mr4380136pfi.127.1506604491034; Thu, 28 Sep 2017 06:14:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506604491; cv=none; d=google.com; s=arc-20160816; b=oBygjCfsb4nufwI0GFo6LXjOY3duZXozK7YsCdsY5ot60+HyP/Ox8g5ESHpDKW+q9O /Ntj8u/fOMAvc3whRuRLRAebKyM3m7oyf0weKE+xoVTU7DhRniH+GhSavPW1Ysnz8GaY yMuljFukbq0UVHhTM/Cjg4a2NAt+qsBLVzzTXvHSdx/arPrOl+9Ztbkw6mRW10j4OWAO WvWJj44mwWNGfAHXUi1jAY+wDDlEpP0uoFe0EDd+0YsXbuSw4ZQS8hTQRU8xl1NrNW+c 5vUw0yJzPKblJR88uRY6LteODolfxkGf5/3Bfxcng1H8GbkE743wl4TqP8JMwQO6U5xY b35Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=iaVnY0tokBLadkbOPYMnddK/vyqepNugIOxQckMadzE=; b=aVwbv6hPm81LjjvW0EA6kGBDRVxcFmpssoNfQCDyxpE+kjR7ffC2t8rvbQokt+Mw8M LfqiQ1Czkwy9ddgWWmzRM01K2bXkg3aMI5eD2T9y40fJOuoXqdgcqSc4iiT34z4Ciwj+ rt4yj0NfsQNaZKDYQziGbEaWalEjZAm4vR5WkETEGYngrAy6grzUuYYhJnNUA35KRzEW LohnndLnd6tGu+hr3/KHh0rfRGJDFVRD032n84z8gOdDy4B2ubMsjLa4Utng566UVhiz AFFwrBT33BfXMGc3flRhulBoWrkwS2Q4m6SBSVOdcPTB6ocVqQgoKG9f0vbSUl+K7oe+ F8fg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x85si1374651pfk.613.2017.09.28.06.14.49; Thu, 28 Sep 2017 06:14:51 -0700 (PDT) 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; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753408AbdI1NOs (ORCPT + 26 others); Thu, 28 Sep 2017 09:14:48 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:57226 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752079AbdI1NOp (ORCPT ); Thu, 28 Sep 2017 09:14:45 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DF6B9165C; Thu, 28 Sep 2017 06:14:44 -0700 (PDT) Received: from e107155-lin.cambridge.arm.com (unknown [10.1.210.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 85E8C3F483; Thu, 28 Sep 2017 06:14:42 -0700 (PDT) From: Sudeep Holla To: ALKML , LKML , DTML Cc: Sudeep Holla , Roy Franz , Harb Abdulhamid , Nishanth Menon , Arnd Bergmann , Loc Ho , Alexey Klimov , Ryan Harkin , Jassi Brar , Kevin Hilman , Ulf Hansson Subject: [PATCH v3 17/22] firmware: arm_scmi: add device power domain support using genpd Date: Thu, 28 Sep 2017 14:11:41 +0100 Message-Id: <1506604306-20739-18-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506604306-20739-1-git-send-email-sudeep.holla@arm.com> References: <1506604306-20739-1-git-send-email-sudeep.holla@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch hooks up the support for device power domain provided by SCMI using the Linux generic power domain infrastructure. Cc: Kevin Hilman Cc: Ulf Hansson Signed-off-by: Sudeep Holla --- drivers/firmware/Kconfig | 13 +++ drivers/firmware/arm_scmi/Makefile | 1 + drivers/firmware/arm_scmi/scmi_pm_domain.c | 134 +++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 drivers/firmware/arm_scmi/scmi_pm_domain.c -- 2.7.4 Reviewed-by: Ulf Hansson diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index c3d1a12763ce..a4462bc661c8 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -40,6 +40,19 @@ config ARM_SCMI_PROTOCOL This protocol library provides interface for all the client drivers making use of the features offered by the SCMI. +config ARM_SCMI_POWER_DOMAIN + tristate "SCMI power domain driver" + depends on ARM_SCMI_PROTOCOL || (COMPILE_TEST && OF) + default y + select PM_GENERIC_DOMAINS if PM + help + This enables support for the SCMI power domains which can be + enabled or disabled via the SCP firmware + + This driver can also be built as a module. If so, the module + will be called scmi_pm_domain. Note this may needed early in boot + before rootfs may be available. + config ARM_SCPI_PROTOCOL tristate "ARM System Control and Power Interface (SCPI) Message Protocol" depends on ARM || ARM64 || COMPILE_TEST diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile index 7fb026c71833..289e9e5a4764 100644 --- a/drivers/firmware/arm_scmi/Makefile +++ b/drivers/firmware/arm_scmi/Makefile @@ -1,3 +1,4 @@ obj-$(CONFIG_ARM_SCMI_PROTOCOL) = arm_scmi.o arm_scmi-y = base.o clock.o driver.o mbox_if.o perf.o power.o sensors.o arm_scmi-$(CONFIG_ARM_MHU) += arm_mhu_if.o +obj-$(CONFIG_ARM_SCMI_POWER_DOMAIN) += scmi_pm_domain.o diff --git a/drivers/firmware/arm_scmi/scmi_pm_domain.c b/drivers/firmware/arm_scmi/scmi_pm_domain.c new file mode 100644 index 000000000000..e53aa9d0af6e --- /dev/null +++ b/drivers/firmware/arm_scmi/scmi_pm_domain.c @@ -0,0 +1,134 @@ +/* + * SCMI Generic power domain support. + * + * Copyright (C) 2017 ARM Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include + +struct scmi_pm_domain { + struct generic_pm_domain genpd; + const struct scmi_handle *handle; + const char *name; + u32 domain; +}; + +#define to_scmi_pd(gpd) container_of(gpd, struct scmi_pm_domain, genpd) + +static int scmi_pd_power(struct generic_pm_domain *domain, bool power_on) +{ + int ret; + u32 state, ret_state; + struct scmi_pm_domain *pd = to_scmi_pd(domain); + const struct scmi_power_ops *ops = pd->handle->power_ops; + + if (power_on) + state = SCMI_POWER_STATE_GENERIC_ON; + else + state = SCMI_POWER_STATE_GENERIC_OFF; + + ret = ops->state_set(pd->handle, pd->domain, state); + if (!ret) + ret = ops->state_get(pd->handle, pd->domain, &ret_state); + if (!ret && state != ret_state) + return -EIO; + + return ret; +} + +static int scmi_pd_power_on(struct generic_pm_domain *domain) +{ + return scmi_pd_power(domain, true); +} + +static int scmi_pd_power_off(struct generic_pm_domain *domain) +{ + return scmi_pd_power(domain, false); +} + +static int scmi_pm_domain_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct scmi_pm_domain *scmi_pd; + struct genpd_onecell_data *scmi_pd_data; + struct generic_pm_domain **domains; + int num_domains, i; + const struct scmi_handle *handle = devm_scmi_handle_get(dev); + + if (IS_ERR_OR_NULL(handle) || !handle->power_ops) + return -EPROBE_DEFER; + + num_domains = handle->power_ops->num_domains_get(handle); + if (num_domains < 0) { + dev_err(dev, "number of domains not found\n"); + return num_domains; + } + + scmi_pd = devm_kcalloc(dev, num_domains, sizeof(*scmi_pd), GFP_KERNEL); + if (!scmi_pd) + return -ENOMEM; + + scmi_pd_data = devm_kzalloc(dev, sizeof(*scmi_pd_data), GFP_KERNEL); + if (!scmi_pd_data) + return -ENOMEM; + + domains = devm_kcalloc(dev, num_domains, sizeof(*domains), GFP_KERNEL); + if (!domains) + return -ENOMEM; + + for (i = 0; i < num_domains; i++, scmi_pd++) { + domains[i] = &scmi_pd->genpd; + + scmi_pd->domain = i; + scmi_pd->handle = handle; + scmi_pd->name = handle->power_ops->name_get(handle, i); + scmi_pd->genpd.name = scmi_pd->name; + scmi_pd->genpd.power_off = scmi_pd_power_off; + scmi_pd->genpd.power_on = scmi_pd_power_on; + + /* + * Treat all power domains as off at boot. + * + * The SCP firmware itself may have switched on some domains, + * but for reference counting purpose, keep it this way. + */ + pm_genpd_init(&scmi_pd->genpd, NULL, true); + } + + scmi_pd_data->domains = domains; + scmi_pd_data->num_domains = num_domains; + + of_genpd_add_provider_onecell(np, scmi_pd_data); + + return 0; +} + +static struct platform_driver scmi_power_domain_driver = { + .driver = { + .name = "scmi-power-domain", + }, + .probe = scmi_pm_domain_probe, +}; +module_platform_driver(scmi_power_domain_driver); + +MODULE_AUTHOR("Sudeep Holla "); +MODULE_DESCRIPTION("ARM SCMI power domain driver"); +MODULE_LICENSE("GPL v2");