From patchwork Sat Sep 27 00:58:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 38029 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f198.google.com (mail-we0-f198.google.com [74.125.82.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A648F202DB for ; Sat, 27 Sep 2014 00:58:50 +0000 (UTC) Received: by mail-we0-f198.google.com with SMTP id t60sf6271653wes.1 for ; Fri, 26 Sep 2014 17:58:49 -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=Obvoe/Xc6KFws7wzPP/Syc29Kxzrx7GavcNeMDohFPQ=; b=EdidGpRkHaRhPk4NqERx48ucD7FEjfXCb0W7iZmlMqCXF5LP4ZvB2FQ/00ycxLON/o 9cUdkRnc/WnEmO1IPKyHLghSEuoUwT7L2R6OEE7NtMy804BYbxd+i8xmOnSBRWTZfPaD HcHXbgM2KykrbGDWXA63MBVYE/5YlNVXS7zGwC9SHLlbvj8CBiSZ8lvA4UC8SsmUuhHM 7HgYmzprDIdRPuWrYvg1sBssbwFaQ/uNIkrWoO+PhrZXhMQ/Y5suu2698O+yxJzkslOu aLln1G9MgY9NDW/s+T9M8ZSdS0ihRWlvPJOUbQ/1HD0PvZDguTAok/dFLRr4/mEOuBrF DmVg== X-Gm-Message-State: ALoCoQkeeprutATDYWieis2k213vP+O2ZFkEfd4myI0Pd7Nb4L1A5eBccDFNhd8IEeXhyg3MqWXM X-Received: by 10.180.76.230 with SMTP id n6mr6616328wiw.0.1411779529906; Fri, 26 Sep 2014 17:58:49 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.207 with SMTP id ba15ls306062lab.16.gmail; Fri, 26 Sep 2014 17:58:49 -0700 (PDT) X-Received: by 10.152.8.168 with SMTP id s8mr1953490laa.3.1411779529525; Fri, 26 Sep 2014 17:58:49 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com [209.85.215.48]) by mx.google.com with ESMTPS id ge3si9254003lbc.40.2014.09.26.17.58.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 26 Sep 2014 17:58:49 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by mail-la0-f48.google.com with SMTP id q1so3746503lam.21 for ; Fri, 26 Sep 2014 17:58:49 -0700 (PDT) X-Received: by 10.112.202.1 with SMTP id ke1mr22708151lbc.33.1411779529153; Fri, 26 Sep 2014 17:58:49 -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.112.130.169 with SMTP id of9csp150144lbb; Fri, 26 Sep 2014 17:58:48 -0700 (PDT) X-Received: by 10.68.216.135 with SMTP id oq7mr36495400pbc.47.1411779522800; Fri, 26 Sep 2014 17:58:42 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rl12si11625654pab.232.2014.09.26.17.58.42 for ; Fri, 26 Sep 2014 17:58:42 -0700 (PDT) Received-SPF: none (google.com: linux-pm-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 S1752763AbaI0A6j (ORCPT + 15 others); Fri, 26 Sep 2014 20:58:39 -0400 Received: from mail-pd0-f174.google.com ([209.85.192.174]:47489 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752737AbaI0A6h (ORCPT ); Fri, 26 Sep 2014 20:58:37 -0400 Received: by mail-pd0-f174.google.com with SMTP id g10so13162237pdj.5 for ; Fri, 26 Sep 2014 17:58:37 -0700 (PDT) X-Received: by 10.70.131.13 with SMTP id oi13mr42182975pdb.23.1411779517303; Fri, 26 Sep 2014 17:58:37 -0700 (PDT) Received: from ubuntu.localdomain (proxy6-global253.qualcomm.com. [199.106.103.253]) by mx.google.com with ESMTPSA id rg1sm6030307pdb.14.2014.09.26.17.58.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Sep 2014 17:58:36 -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 Cc: lorenzo.pieralisi@arm.com, msivasub@codeaurora.org, Lina Iyer Subject: [PATCH v7 4/7] qcom: pm: Add cpu low power mode functions Date: Fri, 26 Sep 2014 18:58:12 -0600 Message-Id: <1411779495-39724-5-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1411779495-39724-1-git-send-email-lina.iyer@linaro.org> References: <1411779495-39724-1-git-send-email-lina.iyer@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@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.215.48 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: , 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/pm.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++ include/soc/qcom/pm.h | 26 +++++++++++ 3 files changed, 136 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..a2f7d72 --- /dev/null +++ b/drivers/soc/qcom/pm.c @@ -0,0 +1,109 @@ +/* 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) +#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); + + 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 qcom_pm_collapse(unsigned long int unused) +{ + int ret; + u32 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 = SCM_L2_ON & SCM_FLUSH_FLAG_MASK; + scm_call_atomic1(SCM_SVC_BOOT, SCM_CMD_TERMINATE_PC, flag); + + 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; + + switch (mode) { + case PM_SLEEP_MODE_SPC: + qcom_spm_set_low_power_mode(SPM_MODE_POWER_COLLAPSE); + ret = cpu_suspend(0, qcom_pm_collapse); + break; + default: + case PM_SLEEP_MODE_WFI: + qcom_spm_set_low_power_mode(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 = qcom_cpu_pm_enter_sleep, +}; + +static int __init qcom_pm_device_init(void) +{ + platform_device_register(&qcom_cpuidle_device); + + return 0; +} +device_initcall(qcom_pm_device_init); diff --git a/include/soc/qcom/pm.h b/include/soc/qcom/pm.h new file mode 100644 index 0000000..563b9c3 --- /dev/null +++ b/include/soc/qcom/pm.h @@ -0,0 +1,26 @@ +/* + * 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_WFI, + PM_SLEEP_MODE_RET, + PM_SLEEP_MODE_SPC, + PM_SLEEP_MODE_PC, + PM_SLEEP_MODE_NR, +}; + +#endif /* __QCOM_PM_H */