From patchwork Fri Aug 8 04:00:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 35076 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f70.google.com (mail-qg0-f70.google.com [209.85.192.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CCB9321137 for ; Fri, 8 Aug 2014 04:01:15 +0000 (UTC) Received: by mail-qg0-f70.google.com with SMTP id z60sf14056996qgd.1 for ; Thu, 07 Aug 2014 21:01:15 -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=zGcwz24WXqFFlRt1orDkQMP1ZlJ4dV6rPaKkCN1vKeE=; b=U+wv0JayPJAwcfxu9CU/Yxx6GmqLlkkr8srAJYssJgfyNaSwtVId368rXO/vVvOYfx r/sTJkb2imvvD6Ht6sPkRhg+JLw/FcfzXi4qHeqN0NLH/pJ9WPLx/IDPsL5fDoI6eEz3 6mqtWZ3OWf7hLyHMlYjlOY1dey6ZVPlFM60cjdjbK844HmjZNFCGDVdSJdgrlFP9I499 fL8TGNuqJZHf5B1G99hh74+gBK017X41vojoBniIII5MTaYmFJfSPtxV3FsUaFezkXYL DuBZdKdjmgn4XrffJDR/S33fNxAGezXVUlTetac7fhCshKoUi3Z5oI3dWZkrqQnCM5xy uE5g== X-Gm-Message-State: ALoCoQm/UHmrwiIOJjMt2TCzniu88Xk8+S5xsgaBMM1nvROQpeYFdXc/tQuoApSf0BccyYDky1dW X-Received: by 10.236.201.106 with SMTP id a70mr3528027yho.34.1407470475650; Thu, 07 Aug 2014 21:01:15 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.51.170 with SMTP id u39ls388044qga.21.gmail; Thu, 07 Aug 2014 21:01:15 -0700 (PDT) X-Received: by 10.52.168.134 with SMTP id zw6mr5077046vdb.37.1407470475562; Thu, 07 Aug 2014 21:01:15 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id yi17si2487817vdb.55.2014.08.07.21.01.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 07 Aug 2014 21:01:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.177 as permitted sender) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id hy4so7628615vcb.36 for ; Thu, 07 Aug 2014 21:01:15 -0700 (PDT) X-Received: by 10.52.156.100 with SMTP id wd4mr5052054vdb.39.1407470475482; Thu, 07 Aug 2014 21:01:15 -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.37.5 with SMTP id tc5csp86902vcb; Thu, 7 Aug 2014 21:01:14 -0700 (PDT) X-Received: by 10.70.88.105 with SMTP id bf9mr21982373pdb.54.1407470473467; Thu, 07 Aug 2014 21:01:13 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b11si1450465pdj.25.2014.08.07.21.01.12 for ; Thu, 07 Aug 2014 21:01:13 -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 S1752018AbaHHEBM (ORCPT + 4 others); Fri, 8 Aug 2014 00:01:12 -0400 Received: from mail-ie0-f180.google.com ([209.85.223.180]:40040 "EHLO mail-ie0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751030AbaHHEBL (ORCPT ); Fri, 8 Aug 2014 00:01:11 -0400 Received: by mail-ie0-f180.google.com with SMTP id at20so5854771iec.11 for ; Thu, 07 Aug 2014 21:01:10 -0700 (PDT) X-Received: by 10.50.152.40 with SMTP id uv8mr1453647igb.40.1407470470630; Thu, 07 Aug 2014 21:01:10 -0700 (PDT) Received: from localhost.localdomain (c-24-8-37-141.hsd1.co.comcast.net. [24.8.37.141]) by mx.google.com with ESMTPSA id yt6sm4062230igb.10.2014.08.07.21.01.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Aug 2014 21:01:10 -0700 (PDT) From: Lina Iyer To: daniel.lezcano@linaro.org, khilman@linaro.org, amit.kucheria@linaro.org, sboyd@codeaurora.org, davidb@codeaurora.org, galak@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@vger.kernel.org Cc: msivasub@codeaurora.org, bryanh@codeaurora.org, Lina Iyer , Venkat Devarasetty Subject: [RFC] [PATCH 05/13] qcom: msm-pm: Add cpu low power mode functions Date: Thu, 7 Aug 2014 22:00:50 -0600 Message-Id: <1407470458-22900-6-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1407470458-22900-1-git-send-email-lina.iyer@linaro.org> References: <1407470458-22900-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.177 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 | 218 ++++++++++++++++++++++++++++++++++++++++++++++ include/soc/qcom/pm.h | 39 +++++++++ 3 files changed, 258 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 3de7ed9..87c3b9704 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -1,5 +1,5 @@ obj-$(CONFIG_QCOM_GSBI) += qcom_gsbi.o -obj-$(CONFIG_QCOM_PM) += spm_devices.o spm.o +obj-$(CONFIG_QCOM_PM) += spm_devices.o 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..17a7c8c --- /dev/null +++ b/drivers/soc/qcom/msm-pm.c @@ -0,0 +1,218 @@ +/* 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 +#include + +#define SCM_CMD_TERMINATE_PC (0x2) +#define SCM_CMD_CORE_HOTPLUGGED (0x10) +#define SCM_FLUSH_FLAG_MASK (0x3) + +static bool msm_pm_is_L1_writeback(void) +{ + u32 cache_id = 0; + +#if defined(CONFIG_CPU_V7) + u32 sel = 0; + + asm volatile ("mcr p15, 2, %[ccselr], c0, c0, 0\n\t" + "isb\n\t" + "mrc p15, 1, %[ccsidr], c0, c0, 0\n\t" + :[ccsidr]"=r" (cache_id) + :[ccselr]"r" (sel) + ); + return cache_id & BIT(30); +#elif defined(CONFIG_ARM64) + u32 sel = 0; + asm volatile("msr csselr_el1, %[ccselr]\n\t" + "isb\n\t" + "mrs %[ccsidr],ccsidr_el1\n\t" + :[ccsidr]"=r" (cache_id) + :[ccselr]"r" (sel) + ); + return cache_id & BIT(30); +#else +#error No valid CPU arch selected +#endif +} + +static inline void msm_arch_idle(void) +{ + mb(); + wfi(); +} + +static bool msm_pm_swfi(bool from_idle) +{ + msm_arch_idle(); + return true; +} + +static bool msm_pm_retention(bool from_idle) +{ + int ret = 0; + + ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_RETENTION, false); + WARN_ON(ret); + + msm_arch_idle(); + + ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false); + WARN_ON(ret); + + return true; +} + +static int msm_pm_collapse(unsigned long from_idle) +{ + enum msm_pm_l2_scm_flag flag = MSM_SCM_L2_ON; + + /** + * Single core processors need to have L2 + * flushed when powering down the core. + * Notify SCM to flush secure L2 lines. + */ + if (num_possible_cpus() == 1) + flag = MSM_SCM_L2_OFF; + + if (flag == MSM_SCM_L2_OFF) + flush_cache_all(); + else if (msm_pm_is_L1_writeback()) + flush_cache_louis(); + + flag &= SCM_FLUSH_FLAG_MASK; + if (!from_idle) + flag |= SCM_CMD_CORE_HOTPLUGGED; + + scm_call_atomic1(SCM_SVC_BOOT, SCM_CMD_TERMINATE_PC, flag); + + return 0; +} + +static void set_up_boot_address(void *entry, int cpu, bool from_idle) +{ + static int flags[NR_CPUS] = { + SCM_FLAG_WARMBOOT_CPU0, + SCM_FLAG_WARMBOOT_CPU1, + SCM_FLAG_WARMBOOT_CPU2, + SCM_FLAG_WARMBOOT_CPU3, + }; + + scm_set_boot_addr(virt_to_phys(entry), flags[cpu]); +} + +static bool __ref msm_pm_spm_power_collapse( + unsigned int cpu, bool from_idle) +{ + static DEFINE_PER_CPU(void *, last_known_entry); + void *entry; + bool collapsed = 0; + int ret; + bool save_cpu_regs = (cpu_online(cpu) || from_idle); + + if (from_idle) + cpu_pm_enter(); + + ret = msm_spm_set_low_power_mode( + MSM_SPM_MODE_POWER_COLLAPSE, false); + WARN_ON(ret); + + entry = save_cpu_regs ? cpu_resume : secondary_startup; + if (entry != per_cpu(last_known_entry, cpu)) { + per_cpu(last_known_entry, cpu) = entry; + set_up_boot_address(entry, cpu, from_idle); + } + +#ifdef CONFIG_CPU_V7 + collapsed = !cpu_suspend(from_idle, msm_pm_collapse); +#else + collapsed = !cpu_suspend(0); +#endif + + if (collapsed) + local_fiq_enable(); + + if (from_idle) + cpu_pm_exit(); + + ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false); + WARN_ON(ret); + + return collapsed; +} + +static bool msm_pm_power_collapse_standalone(bool from_idle) +{ + unsigned int cpu = smp_processor_id(); + bool collapsed; + + collapsed = msm_pm_spm_power_collapse(cpu, from_idle); + + return collapsed; +} + +static bool msm_pm_power_collapse(bool from_idle) +{ + unsigned int cpu = smp_processor_id(); + bool collapsed; + + collapsed = msm_pm_spm_power_collapse(cpu, from_idle); + + return collapsed; +} + +static bool (*execute[MSM_PM_SLEEP_MODE_NR])(bool idle) = { + [MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT] = msm_pm_swfi, + [MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE] = + msm_pm_power_collapse_standalone, + [MSM_PM_SLEEP_MODE_RETENTION] = msm_pm_retention, + [MSM_PM_SLEEP_MODE_POWER_COLLAPSE] = msm_pm_power_collapse, +}; + +/** + * 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. + * + */ +bool msm_cpu_pm_enter_sleep(enum msm_pm_sleep_mode mode, bool from_idle) +{ + bool exit_stat = false; + + if (execute[mode]) + exit_stat = execute[mode](from_idle); + + return exit_stat; +} +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..01872ad --- /dev/null +++ b/include/soc/qcom/pm.h @@ -0,0 +1,39 @@ +/* + * 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_RETENTION, + MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE, + MSM_PM_SLEEP_MODE_POWER_COLLAPSE, + 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 +bool msm_cpu_pm_enter_sleep(enum msm_pm_sleep_mode mode, bool from_idle); +#else +static inline bool msm_cpu_pm_enter_sleep(enum msm_pm_sleep_mode mode, + bool from_idle) +{ return true; } +#endif + +#endif /* __QCOM_PM_H */