From patchwork Tue Sep 23 23:51:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 4960901 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 64E02BEEA5 for ; Tue, 23 Sep 2014 23:55:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 58AE82017A for ; Tue, 23 Sep 2014 23:55:00 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5098A2010F for ; Tue, 23 Sep 2014 23:54:59 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XWZsf-0003zs-MB; Tue, 23 Sep 2014 23:52:25 +0000 Received: from mail-pd0-f173.google.com ([209.85.192.173]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XWZsU-0003uN-Vw for linux-arm-kernel@lists.infradead.org; Tue, 23 Sep 2014 23:52:15 +0000 Received: by mail-pd0-f173.google.com with SMTP id y10so7374168pdj.4 for ; Tue, 23 Sep 2014 16:51:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UkhbdzEPA3gVm71nIJREEe/vjzexONBNDUjlKZMCigU=; b=WNmeo8OqiZYvJseVZIPOkkV1vufPmfGzEZSwi3E+FpfjzKs+Yaf92EzCLaGvaggA85 uHKNw8vutn1WfizGPBf7NSkOMbSQUI3A4ArL5NC8GmLUc85VRUzEWMHNrrqCZwSvj1vY pHBXzt3qqIqkHOUSWg+KdMZ8iTDwqjvnTtJG+5qUAD5DsT8s3eqa8XAp5AQjStgIY7uL cUxtErsnyMn0wprwyc3Gpbq2sYPy+gbinSyP+4NeWAGPe4mzEbrUJRKtTl9/8fPAFUoN evR7CeB/XBV1oT6QbQovHjhENP9jSHWOV3XXs2HshPgJuZeRyXKHZ5TS6AtBzfr6zbbA 1o7w== X-Gm-Message-State: ALoCoQmoOk3UriLghmfDSnio2PjGFCP+vEClGbj53JlQHtVkOxSKDGBSftNkhf+o1SdUxBP8g7s4 X-Received: by 10.70.118.38 with SMTP id kj6mr4324241pdb.167.1411516313700; Tue, 23 Sep 2014 16:51:53 -0700 (PDT) Received: from ubuntu.localdomain (proxy6-global253.qualcomm.com. [199.106.103.253]) by mx.google.com with ESMTPSA id ix1sm13033521pbc.60.2014.09.23.16.51.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Sep 2014 16:51:53 -0700 (PDT) From: Lina Iyer To: galak@codeaurora.org, sboyd@codeaurora.org, daniel.lezcano@linaro.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v6 3/5] qcom: msm-pm: Add cpu low power mode functions Date: Tue, 23 Sep 2014 17:51:19 -0600 Message-Id: <1411516281-58328-4-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1411516281-58328-1-git-send-email-lina.iyer@linaro.org> References: <1411516281-58328-1-git-send-email-lina.iyer@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140923_165215_100263_6BD5471B X-CRM114-Status: GOOD ( 19.04 ) X-Spam-Score: -0.9 (/) Cc: msivasub@codeaurora.org, lorenzo.pieralisi@arm.com, khilman@linaro.org, Lina Iyer , linux-pm@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Based on work by many authors, available at codeaurora.org Add interface layer to abstract and handle hardware specific functionality for executing various cpu low power modes in QCOM chipsets. QCOM cpus support multiple low power modes. The C-States are defined as - * WFI (clock gating) * Retention (clock gating at lower power) * Standalone Power Collapse (Standalone PC or SPC) - The power to the cpu is lost and the cpu warmboots. * Power Collapse (PC) - Same as SPC, but is a cognizant of the fact that the SoC may do deeper sleep modes. Signed-off-by: Lina Iyer [lina: simplify the driver for an initial submission, add commit text description of idle states] --- drivers/soc/qcom/Makefile | 2 +- drivers/soc/qcom/msm-pm.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++ include/soc/qcom/pm.h | 31 ++++++++++++++ 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 drivers/soc/qcom/msm-pm.c create mode 100644 include/soc/qcom/pm.h diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index 20b329f..dc25007 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -1,4 +1,4 @@ obj-$(CONFIG_QCOM_GSBI) += qcom_gsbi.o -obj-$(CONFIG_QCOM_PM) += spm.o +obj-$(CONFIG_QCOM_PM) += spm.o msm-pm.o CFLAGS_scm.o :=$(call as-instr,.arch_extension sec,-DREQUIRES_SEC=1) obj-$(CONFIG_QCOM_SCM) += scm.o scm-boot.o diff --git a/drivers/soc/qcom/msm-pm.c b/drivers/soc/qcom/msm-pm.c new file mode 100644 index 0000000..8926c71 --- /dev/null +++ b/drivers/soc/qcom/msm-pm.c @@ -0,0 +1,106 @@ +/* Copyright (c) 2010-2014, 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 +#include + +#include +#include + +#include +#include +#include +#include + +#define SCM_CMD_TERMINATE_PC (0x2) +#define SCM_FLUSH_FLAG_MASK (0x3) + +static int set_up_boot_address(void *entry, int cpu) +{ + static int flags[NR_CPUS] = { + SCM_FLAG_WARMBOOT_CPU0, + SCM_FLAG_WARMBOOT_CPU1, + SCM_FLAG_WARMBOOT_CPU2, + SCM_FLAG_WARMBOOT_CPU3, + }; + static DEFINE_PER_CPU(void *, last_known_entry); + + if (entry == per_cpu(last_known_entry, cpu)) + return 0; + + per_cpu(last_known_entry, cpu) = entry; + return scm_set_boot_addr(virt_to_phys(entry), flags[cpu]); +} + +static int msm_pm_collapse(unsigned long int unused) +{ + int ret; + enum msm_pm_l2_scm_flag flag; + + ret = set_up_boot_address(cpu_resume, raw_smp_processor_id()); + if (ret) { + pr_err("Failed to set warm boot address for cpu %d\n", + raw_smp_processor_id()); + return ret; + } + + flag = MSM_SCM_L2_ON & SCM_FLUSH_FLAG_MASK; + scm_call_atomic1(SCM_SVC_BOOT, SCM_CMD_TERMINATE_PC, flag); + + return 0; +} + +/** + * msm_cpu_pm_enter_sleep(): Enter a low power mode on current cpu + * + * @mode - sleep mode to enter + * + * The code should be called with interrupts disabled and on the core on + * which the low power mode is to be executed. + * + */ +static int msm_cpu_pm_enter_sleep(enum msm_pm_sleep_mode mode) +{ + int ret; + + switch (mode) { + case MSM_PM_SLEEP_MODE_SPC: + msm_spm_set_low_power_mode(MSM_SPM_MODE_POWER_COLLAPSE); + ret = cpu_suspend(0, msm_pm_collapse); + break; + default: + case MSM_PM_SLEEP_MODE_WFI: + msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING); + ret = cpu_do_idle(); + break; + } + + local_irq_enable(); + + return ret; +} + +static struct platform_device qcom_cpuidle_device = { + .name = "qcom_cpuidle", + .id = -1, + .dev.platform_data = msm_cpu_pm_enter_sleep, +}; + +static int __init msm_pm_device_init(void) +{ + platform_device_register(&qcom_cpuidle_device); + + return 0; +} +device_initcall(msm_pm_device_init); diff --git a/include/soc/qcom/pm.h b/include/soc/qcom/pm.h new file mode 100644 index 0000000..c2f006b --- /dev/null +++ b/include/soc/qcom/pm.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2009-2014, The Linux Foundation. All rights reserved. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * 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 __QCOM_PM_H +#define __QCOM_PM_H + +enum msm_pm_sleep_mode { + MSM_PM_SLEEP_MODE_WFI, + MSM_PM_SLEEP_MODE_RET, + MSM_PM_SLEEP_MODE_SPC, + MSM_PM_SLEEP_MODE_PC, + MSM_PM_SLEEP_MODE_NR, +}; + +enum msm_pm_l2_scm_flag { + MSM_SCM_L2_ON = 0, + MSM_SCM_L2_OFF = 1 +}; + +#endif /* __QCOM_PM_H */