From patchwork Tue Aug 19 22:15:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 35676 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3F2BE2034C for ; Tue, 19 Aug 2014 22:16:10 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rp18sf7535941iec.8 for ; Tue, 19 Aug 2014 15:16:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=0nBjqytwJ2/+vm9NxX3qQri4mbz/QkoKLSl+zVZBgV0=; b=GqZbcVOiSkQBilG52RuPbKA7Wez1GSkx61f40WeXndSUgBDR/iF1HO0Icgin9zHzA1 nRFpkYl/yDa2v5ms/ACtFGF82P2yAY/9VyqobaXPadPE+8FgHl3Uy/IBowdraz1qj+4O CVrSzIWnDyKIWcysyvOaIIAy2vsdT1KeFC/RQGp70BdrZ5Xwt14AzcFb+w12xDJgcVF3 Q+tmrFMgK5Ci2vZvQeXTrS2+Sqn4zHj4Vbx5Bj8OPprCQKkwlK4COVb8iUIpLy5SVEOR FEr8Sw/H8Giqnaw9OVNH2MdxCuAM0+xVJAx+AVeWV5oYQh1LwDfcYRkm84NAU1VLjjhy 3JgQ== X-Gm-Message-State: ALoCoQmdOS0yRZy7gJorNu1sfpitttmptWpimBMA+7FUEKAJ+PBpOHgoJVVvjLjNXq99MmKK4HJ4 X-Received: by 10.182.230.133 with SMTP id sy5mr24521347obc.22.1408486569738; Tue, 19 Aug 2014 15:16:09 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.107.70 with SMTP id g64ls21456qgf.85.gmail; Tue, 19 Aug 2014 15:16:09 -0700 (PDT) X-Received: by 10.220.187.134 with SMTP id cw6mr2126072vcb.71.1408486569611; Tue, 19 Aug 2014 15:16:09 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id n4si9692265vcm.58.2014.08.19.15.16.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Aug 2014 15:16:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id id10so8200913vcb.35 for ; Tue, 19 Aug 2014 15:16:09 -0700 (PDT) X-Received: by 10.52.94.108 with SMTP id db12mr9024154vdb.8.1408486569513; Tue, 19 Aug 2014 15:16:09 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp3359vcb; Tue, 19 Aug 2014 15:16:08 -0700 (PDT) X-Received: by 10.70.19.166 with SMTP id g6mr32860864pde.99.1408486567583; Tue, 19 Aug 2014 15:16:07 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id df3si28839804pbc.99.2014.08.19.15.16.06 for ; Tue, 19 Aug 2014 15:16:07 -0700 (PDT) Received-SPF: none (google.com: linux-arm-msm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751444AbaHSWQG (ORCPT + 5 others); Tue, 19 Aug 2014 18:16:06 -0400 Received: from mail-pd0-f172.google.com ([209.85.192.172]:45754 "EHLO mail-pd0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751954AbaHSWQF (ORCPT ); Tue, 19 Aug 2014 18:16:05 -0400 Received: by mail-pd0-f172.google.com with SMTP id y13so10294467pdi.31 for ; Tue, 19 Aug 2014 15:16:04 -0700 (PDT) X-Received: by 10.66.122.175 with SMTP id lt15mr47283030pab.77.1408486564771; Tue, 19 Aug 2014 15:16:04 -0700 (PDT) Received: from ubuntu.localdomain (proxy6-global253.qualcomm.com. [199.106.103.253]) by mx.google.com with ESMTPSA id zq5sm20305897pbb.37.2014.08.19.15.16.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Aug 2014 15:16:04 -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@codeaurora.org, Lina Iyer , Venkat Devarasetty Subject: [PATCH v4 6/8] qcom: msm-pm: Add cpu low power mode functions Date: Tue, 19 Aug 2014 16:15:35 -0600 Message-Id: <1408486537-6358-7-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1408486537-6358-1-git-send-email-lina.iyer@linaro.org> References: <1408486537-6358-1-git-send-email-lina.iyer@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lina.iyer@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 */