From patchwork Thu Sep 4 22:35:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 4848531 Return-Path: X-Original-To: patchwork-linux-pm@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 9F8A49F314 for ; Thu, 4 Sep 2014 22:36:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ABE2720225 for ; Thu, 4 Sep 2014 22:36:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9D71120295 for ; Thu, 4 Sep 2014 22:36:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756016AbaIDWgc (ORCPT ); Thu, 4 Sep 2014 18:36:32 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:56739 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756000AbaIDWgb (ORCPT ); Thu, 4 Sep 2014 18:36:31 -0400 Received: by mail-pa0-f42.google.com with SMTP id lf10so21056504pab.15 for ; Thu, 04 Sep 2014 15:36:31 -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=CyHcxidKvEsLhvC5VsvHVXcbKPtbs66fDNDGt0Xby1k=; b=H3yQemOzgCiknbJ6QD22fx13eMXNZH/Y+1Lz4KwhdngokXAyYFCPrE1zkrxsfd1NX0 GOUxBYI9pBv2WnlyFVJAFoxHh+s6NZiOm7xZfMRMn2zpepdgMsfggS1YKvZlraRahxKv K4D0updtxohkWK5SZl1T8U7V0Ga52MnHaQrHBVUJ8d3Nb6yCP/Eo3Y8Fnv42DHgpTtDj efxepCg4icx6HE2A6VdT33xfsqt368eEhVTdYoW26o8biGWApt5iubrPvHdWP+rsrTzX FtS0Zwt3gF9uFqO2XF3jhMHuRKj/K9IaCVLhZOb7B0VXtiNonNV1c0IRHKDQwLqWXrPz TOnA== X-Gm-Message-State: ALoCoQnPkhQ/X0XXZNQ/5k3A+dWHU92jufXrBfXqDsDDL1PKBGG+m5UWVgE7UqqXiVjnCbIvob/q X-Received: by 10.70.119.1 with SMTP id kq1mr13452885pdb.35.1409870191109; Thu, 04 Sep 2014 15:36:31 -0700 (PDT) Received: from ubuntu.localdomain (proxy6-global253.qualcomm.com. [199.106.103.253]) by mx.google.com with ESMTPSA id om6sm133722pdb.89.2014.09.04.15.36.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Sep 2014 15:36:30 -0700 (PDT) From: Lina Iyer To: daniel.lezcano@linaro.org, lorenzo.pieralisi@arm.com, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, khilman@linaro.org, sboyd@codeaurora.org, galak@codeaurora.org Cc: linux-pm@vger.kernel.org, msivasub@codeaurora.org, Lina Iyer Subject: [PATCH v5 5/7] qcom: msm-pm: Add cpu low power mode functions Date: Thu, 4 Sep 2014 16:35:30 -0600 Message-Id: <1409870132-16929-6-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1409870132-16929-1-git-send-email-lina.iyer@linaro.org> References: <1409870132-16929-1-git-send-email-lina.iyer@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 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..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 */