From patchwork Tue Oct 7 21:41:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 5049661 Return-Path: X-Original-To: patchwork-linux-arm@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 95EB89F295 for ; Tue, 7 Oct 2014 21:44:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 970A2201FA for ; Tue, 7 Oct 2014 21:44:34 +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 9C713201F7 for ; Tue, 7 Oct 2014 21:44:33 +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 1XbcX0-0002f8-PC; Tue, 07 Oct 2014 21:42:54 +0000 Received: from mail-pa0-f49.google.com ([209.85.220.49]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XbcWY-0002HD-J3 for linux-arm-kernel@lists.infradead.org; Tue, 07 Oct 2014 21:42:27 +0000 Received: by mail-pa0-f49.google.com with SMTP id hz1so7707332pad.8 for ; Tue, 07 Oct 2014 14:42:05 -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=hVuCpswC0rzax26yYrkulss5dgmQQnsjMMF+QiTOet0=; b=hBDJwpZDLLU+plAmhr2/NARUHRbzJi0Q2+tbzUFC5q/QRWVnvrjgYmgdfpS2++vngw 1aRgYf8MwiEBUzyJPgKdoExKRlI8K0LvLWXkvDss1M47bvdbC9aR3aT2VqC6heHf6P5h gDS5uxoSfUzze4sFs87Ou80nTB5Ecqby23nma5lq1FGQypDZwCpLzpwldL7Qn5MsiosZ /gAeTcSJA3PMTKQbK7cRwupq6U30Mmog0nvthT0fU0RV3ygemhTdsTXjvkNsOLFyYxHG rwL+tp4QhGQWr/ml2Cct42szfxuMUhFUx25e3pbMZFSgDbC6gjqUOXKKYP/WWugXEIGp xdQA== X-Gm-Message-State: ALoCoQlvmDWa4KeOPCIQxlPX+j4QN3MApITrSUpEaPFlOAz7L0sB640Cgowwwuuv6sluyH33Cphd X-Received: by 10.70.37.7 with SMTP id u7mr4263509pdj.155.1412718125636; Tue, 07 Oct 2014 14:42:05 -0700 (PDT) Received: from ubuntu.localdomain (proxy6-global253.qualcomm.com. [199.106.103.253]) by mx.google.com with ESMTPSA id td4sm17131222pab.19.2014.10.07.14.42.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Oct 2014 14:42:05 -0700 (PDT) From: Lina Iyer To: daniel.lezcano@linaro.org, khilman@linaro.org, sboyd@codeaurora.org, galak@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 4/7] qcom: pm: Add cpu low power mode functions Date: Tue, 7 Oct 2014 15:41:43 -0600 Message-Id: <1412718106-17049-5-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1412718106-17049-1-git-send-email-lina.iyer@linaro.org> References: <1412718106-17049-1-git-send-email-lina.iyer@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141007_144226_698289_13E9A322 X-CRM114-Status: GOOD ( 20.07 ) X-Spam-Score: -0.7 (/) Cc: msivasub@codeaurora.org, devicetree@vger.kernel.org, lorenzo.pieralisi@arm.com, Lina Iyer 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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, T_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 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 - * Standby * Retention (clock gating at lower power) * Standalone Power Collapse (Standalone PC or SPC) - The power to the cpu is removed and core is reset upon resume. * Power Collapse (PC) - Same as SPC, but is a cognizant of the fact that the SoC may do deeper sleep modes. Support Standby and SPC for the currently available QCOM SoCs. Based on work by: Mahesh Sivasubramanian , Praveen Chidambaram , Murali Nalajala Original tree available at - git://codeaurora.org/quic/la/kernel/msm-3.10.git Signed-off-by: Lina Iyer --- drivers/soc/qcom/Makefile | 2 +- drivers/soc/qcom/pm.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++ include/soc/qcom/pm.h | 28 +++++++++++ 3 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 drivers/soc/qcom/pm.c create mode 100644 include/soc/qcom/pm.h diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index 20b329f..19900ed 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 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/pm.c b/drivers/soc/qcom/pm.c new file mode 100644 index 0000000..1cb622e --- /dev/null +++ b/drivers/soc/qcom/pm.c @@ -0,0 +1,115 @@ +/* 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 + +#define SCM_CMD_TERMINATE_PC (0x2) +#define SCM_FLUSH_FLAG_MASK (0x3) +#define SCM_L2_ON (0x0) +#define SCM_L2_OFF (0x1) + +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); + int ret; + + if (entry == per_cpu(last_known_entry, cpu)) + return 0; + + ret = scm_set_boot_addr(virt_to_phys(entry), flags[cpu]); + if (!ret) + per_cpu(last_known_entry, cpu) = entry; + + return ret; +} + +static int qcom_pm_collapse(unsigned long int unused) +{ + int ret; + u32 flag; + int cpu = smp_processor_id(); + + ret = set_up_boot_address(cpu_resume, cpu); + if (ret) { + pr_err("Failed to set warm boot address for cpu %d\n", cpu); + return ret; + } + + flag = SCM_L2_ON & SCM_FLUSH_FLAG_MASK; + scm_call_atomic1(SCM_SVC_BOOT, SCM_CMD_TERMINATE_PC, flag); + + /** + * Returns here only if there was a pending interrupt and we did not + * power down as a result. + */ + return 0; +} + +/** + * qcom_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 qcom_cpu_pm_enter_sleep(enum pm_sleep_mode mode) +{ + int ret; + + ret = qcom_spm_set_low_power_mode(mode); + if (ret) + return ret; + + switch (mode) { + case PM_SLEEP_MODE_SPC: + cpu_suspend(0, qcom_pm_collapse); + break; + default: + case PM_SLEEP_MODE_STBY: + cpu_do_idle(); + break; + } + + return 0; +} + +static struct platform_device qcom_cpuidle_device = { + .name = "qcom_cpuidle", + .id = -1, + .dev.platform_data = qcom_cpu_pm_enter_sleep, +}; + +static int __init qcom_pm_device_init(void) +{ + platform_device_register(&qcom_cpuidle_device); + + return 0; +} +module_init(qcom_pm_device_init); diff --git a/include/soc/qcom/pm.h b/include/soc/qcom/pm.h new file mode 100644 index 0000000..e63dc1c --- /dev/null +++ b/include/soc/qcom/pm.h @@ -0,0 +1,28 @@ +/* + * 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 pm_sleep_mode { + PM_SLEEP_MODE_STBY, + PM_SLEEP_MODE_RET, + PM_SLEEP_MODE_SPC, + PM_SLEEP_MODE_PC, + PM_SLEEP_MODE_NR, +}; + +int qcom_spm_set_low_power_mode(enum pm_sleep_mode mode); + +#endif /* __QCOM_PM_H */