From patchwork Mon Aug 18 22:23:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 4739551 Return-Path: X-Original-To: patchwork-linux-arm-msm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 75E159F377 for ; Mon, 18 Aug 2014 22:24:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6667720123 for ; Mon, 18 Aug 2014 22:24:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6174320121 for ; Mon, 18 Aug 2014 22:24:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752421AbaHRWYE (ORCPT ); Mon, 18 Aug 2014 18:24:04 -0400 Received: from mail-pa0-f52.google.com ([209.85.220.52]:34740 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752414AbaHRWYE (ORCPT ); Mon, 18 Aug 2014 18:24:04 -0400 Received: by mail-pa0-f52.google.com with SMTP id bj1so8721595pad.11 for ; Mon, 18 Aug 2014 15:24:02 -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=MAgE5O3oyYijJfIhfIzvPD/OornGDN9Oskt86C1bOxc=; b=kXenojBYX/G70XKAXh4+uhDQ/RSocT7wq455x7qhGvl11xnVmnQWX10BYVTRCtv2Ct xbbof95NE+EK2HVxZlloZxSGePAbRafeco25ok3eHAf2exeIo7NjG8Ja/BkzXa8wZHSI EHPnLzwfag4Ez76Q3wqSCrAi8Qzk5gOO9AA0k0Z7vC5zHF4bJ+FzKd8T0WWlp65vgCDu STnJPartNBplqauc3UtfYm+v1AnLAjpgZil//EeGUEKfLee61cwtxcyiW3NKlWPQ5hOF RjUmguTX4R5JLOg3jo2Ihwp9vAqOqyErrdbm8KWF/JbyxU88v9SdPoKWUiyEdxPlvdR9 cR1g== X-Gm-Message-State: ALoCoQlhBEk6kUdu3XnlCqtKiB2PMkHHdjtRFRVQiVyOQifyytm7Hxv2xXGRC3Z79RLAeQzojVy6 X-Received: by 10.66.146.70 with SMTP id ta6mr10204685pab.131.1408400642895; Mon, 18 Aug 2014 15:24:02 -0700 (PDT) Received: from ubuntu.localdomain (proxy6-global253.qualcomm.com. [199.106.103.253]) by mx.google.com with ESMTPSA id nn3sm25508125pdb.58.2014.08.18.15.24.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Aug 2014 15:24:02 -0700 (PDT) From: Lina Iyer To: daniel.lezcano@linaro.org, khilman@linaro.org, sboyd@codeaurora.org, davidb@codeaurora.org, galak@codeaurora.org, linux-arm-msm@vger.kernel.org, lorenzo.pieralisi@arm.com Cc: msivasub@codeauorora.org, Lina Iyer , Venkat Devarasetty , Mahesh Sivasubramanian Subject: [PATCH v3 6/8] qcom: msm-pm: Add cpu low power mode functions Date: Mon, 18 Aug 2014 16:23:32 -0600 Message-Id: <1408400614-45419-7-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1408400614-45419-1-git-send-email-lina.iyer@linaro.org> References: <1408400614-45419-1-git-send-email-lina.iyer@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Add interface layer to abstract and handle hardware specific functionality for executing various cpu low power modes in QCOM chipsets. Signed-off-by: Venkat Devarasetty Signed-off-by: Mahesh Sivasubramanian Signed-off-by: Lina Iyer --- drivers/soc/qcom/Makefile | 2 +- drivers/soc/qcom/msm-pm.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++ include/soc/qcom/pm.h | 38 +++++++++++++++ 3 files changed, 156 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 9457b2a..acdd6fa 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 spm-devices.o +obj-$(CONFIG_QCOM_PM) += spm.o spm-devices.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..5a984e3 --- /dev/null +++ b/drivers/soc/qcom/msm-pm.c @@ -0,0 +1,117 @@ +/* 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 +#include +#include +#include + +#include +#include +#include +#include + +#define SCM_CMD_TERMINATE_PC (0x2) +#define SCM_FLUSH_FLAG_MASK (0x3) + +static int msm_pm_collapse(unsigned long unused) +{ + enum msm_pm_l2_scm_flag flag; + + flag = MSM_SCM_L2_ON & SCM_FLUSH_FLAG_MASK; + scm_call_atomic1(SCM_SVC_BOOT, SCM_CMD_TERMINATE_PC, flag); + + return 0; +} + +static void 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; + + per_cpu(last_known_entry, cpu) = entry; + scm_set_boot_addr(virt_to_phys(entry), flags[cpu]); +} + +static int do_power_down(void) +{ + int ret; + + cpu_pm_enter(); + + msm_spm_set_low_power_mode(MSM_SPM_MODE_POWER_COLLAPSE); + set_up_boot_address(cpu_resume, raw_smp_processor_id()); + ret = cpu_suspend(0, msm_pm_collapse); + + cpu_pm_exit(); + + return ret; +} + +static inline int do_idle(void) +{ + msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING); + + /* Flush and clock-gate */ + mb(); + wfi(); + + return 0; +} + +/** + * msm_cpu_pm_enter_sleep(): Enter a low power mode on current cpu + * + * @mode - sleep mode to enter + * @from_idle - bool to indicate that the mode is exercised during idle/suspend + * + * The code should be with interrupts disabled and on the core on which the + * low power is to be executed. + * + */ +int msm_cpu_pm_enter_sleep(enum msm_pm_sleep_mode mode, bool from_idle) +{ + int ret; + + switch (mode) { + case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE: + ret = do_power_down(); + break; + default: + case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT: + ret = do_idle(); + break; + } + + local_irq_enable(); + + return ret; +} +EXPORT_SYMBOL(msm_cpu_pm_enter_sleep); diff --git a/include/soc/qcom/pm.h b/include/soc/qcom/pm.h new file mode 100644 index 0000000..7563e09 --- /dev/null +++ b/include/soc/qcom/pm.h @@ -0,0 +1,38 @@ +/* + * 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_WAIT_FOR_INTERRUPT, + MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE, + MSM_PM_SLEEP_MODE_NR, +}; + + +enum msm_pm_l2_scm_flag { + MSM_SCM_L2_ON = 0, + MSM_SCM_L2_OFF = 1 +}; + +#ifdef CONFIG_QCOM_PM +int msm_cpu_pm_enter_sleep(enum msm_pm_sleep_mode mode, bool from_idle); +#else +static inline int msm_cpu_pm_enter_sleep(enum msm_pm_sleep_mode mode, + bool from_idle) +{ return -ENODEV; } +#endif + +#endif /* __QCOM_PM_H */