From patchwork Tue Aug 19 22:15:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 35677 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f197.google.com (mail-ig0-f197.google.com [209.85.213.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7B1AD2034C for ; Tue, 19 Aug 2014 22:16:11 +0000 (UTC) Received: by mail-ig0-f197.google.com with SMTP id r2sf32167876igi.4 for ; Tue, 19 Aug 2014 15:16:11 -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=EitR3yDcBN/JccWsNG1wodCWi8Y2hDtQ5BdLmwsqsvs=; b=fEHsSFzmJ2lNWK9Fctvkx9LaG2nelu0aRT7NKpu90AuyoWDJWUyZZsIr0igjRLPCCR 8VywkgcZIAaeK/KIXsdkVov/889wfy2PYhao81wgacALR20THBy/ZabycWyKYWRX1IRJ MCgaptzaHKGwS6G01rC1/rReMGGp1xO13VPksOoIGt7vXjs0srdcXrvVKu13DU7m/n1a MX01cQKILKPHG1VMn1mBoTAqjaGqq/TF7RzfsnT7Ode8PtawIZgzfZVmBCEdfxU8OmbZ wnV7B48yzoiudKmofaM8NO/q46mOXvIkYFejM/PjDuxzVAVMhcQALDNv6WWw5vCvbFK1 azIg== X-Gm-Message-State: ALoCoQlL2pYksFpMBr0DZuMDeKVGEKAI5Mmg+PArwT971dAcHRsPC68eS7Afy7zz8ZSiwQotQx9k X-Received: by 10.50.33.18 with SMTP id n18mr4747738igi.8.1408486571025; Tue, 19 Aug 2014 15:16:11 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.32.138 with SMTP id h10ls18848qgh.87.gmail; Tue, 19 Aug 2014 15:16:10 -0700 (PDT) X-Received: by 10.52.28.40 with SMTP id y8mr2579907vdg.60.1408486570950; Tue, 19 Aug 2014 15:16:10 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id sf9si9686672vcb.80.2014.08.19.15.16.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Aug 2014 15:16:10 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id lf12so8299332vcb.12 for ; Tue, 19 Aug 2014 15:16:10 -0700 (PDT) X-Received: by 10.52.3.40 with SMTP id 8mr569425vdz.24.1408486570855; Tue, 19 Aug 2014 15:16:10 -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 uj3csp3364vcb; Tue, 19 Aug 2014 15:16:10 -0700 (PDT) X-Received: by 10.70.102.200 with SMTP id fq8mr23686631pdb.152.1408486568996; Tue, 19 Aug 2014 15:16:08 -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.08 for ; Tue, 19 Aug 2014 15:16:08 -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 S1751928AbaHSWQH (ORCPT + 5 others); Tue, 19 Aug 2014 18:16:07 -0400 Received: from mail-pa0-f46.google.com ([209.85.220.46]:46103 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751506AbaHSWQH (ORCPT ); Tue, 19 Aug 2014 18:16:07 -0400 Received: by mail-pa0-f46.google.com with SMTP id lj1so10846587pab.19 for ; Tue, 19 Aug 2014 15:16:06 -0700 (PDT) X-Received: by 10.70.44.70 with SMTP id c6mr45471856pdm.75.1408486566629; Tue, 19 Aug 2014 15:16:06 -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.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Aug 2014 15:16:06 -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 Subject: [PATCH v4 7/8] qcom: cpuidle: Add cpuidle driver for QCOM cpus Date: Tue, 19 Aug 2014 16:15:36 -0600 Message-Id: <1408486537-6358-8-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.181 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 cpuidle driver interface to allow cpus to go into C-States. Use the cpuidle DT interfacecommon across ARM architectures to provide the C-State information to the cpuidle framework. Signed-off-by: Lina Iyer --- drivers/cpuidle/Kconfig.arm | 7 +++ drivers/cpuidle/Makefile | 1 + drivers/cpuidle/cpuidle-qcom.c | 119 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 drivers/cpuidle/cpuidle-qcom.c diff --git a/drivers/cpuidle/Kconfig.arm b/drivers/cpuidle/Kconfig.arm index e339c7f..26e31bd 100644 --- a/drivers/cpuidle/Kconfig.arm +++ b/drivers/cpuidle/Kconfig.arm @@ -63,3 +63,10 @@ config ARM_MVEBU_V7_CPUIDLE depends on ARCH_MVEBU help Select this to enable cpuidle on Armada 370, 38x and XP processors. + +config ARM_QCOM_CPUIDLE + bool "CPU Idle drivers for Qualcomm processors" + depends on QCOM_PM + select DT_IDLE_STATES + help + Select this to enable cpuidle for QCOM processors diff --git a/drivers/cpuidle/Makefile b/drivers/cpuidle/Makefile index 4d177b9..6c222d5 100644 --- a/drivers/cpuidle/Makefile +++ b/drivers/cpuidle/Makefile @@ -17,6 +17,7 @@ obj-$(CONFIG_ARM_ZYNQ_CPUIDLE) += cpuidle-zynq.o obj-$(CONFIG_ARM_U8500_CPUIDLE) += cpuidle-ux500.o obj-$(CONFIG_ARM_AT91_CPUIDLE) += cpuidle-at91.o obj-$(CONFIG_ARM_EXYNOS_CPUIDLE) += cpuidle-exynos.o +obj-$(CONFIG_ARM_QCOM_CPUIDLE) += cpuidle-qcom.o ############################################################################### # MIPS drivers diff --git a/drivers/cpuidle/cpuidle-qcom.c b/drivers/cpuidle/cpuidle-qcom.c new file mode 100644 index 0000000..4aae672 --- /dev/null +++ b/drivers/cpuidle/cpuidle-qcom.c @@ -0,0 +1,119 @@ +/* Copyright (c) 2014, The Linux Foundation. All rights reserved. + * Copyright (c) 2014, Linaro Limited. + * + * 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 "dt_idle_states.h" + +static enum msm_pm_sleep_mode modes[CPUIDLE_STATE_MAX]; + +static int qcom_lpm_enter(struct cpuidle_device *dev, + struct cpuidle_driver *drv, int index) +{ + return msm_cpu_pm_enter_sleep(modes[index], true); +} + +static struct cpuidle_driver qcom_cpuidle_driver = { + .name = "qcom_cpuidle", + .owner = THIS_MODULE, +}; + +static void parse_state_translations(struct cpuidle_driver *drv) +{ + struct device_node *state_node, *cpu_node; + const char *mode_name; + int i, j; + + struct name_map { + enum msm_pm_sleep_mode mode; + char *name; + }; + static struct name_map c_states[] = { + { MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE, + "standalone-pc" }, + { MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT, "wfi" }, + }; + + cpu_node = of_cpu_device_node_get(cpumask_first(drv->cpumask)); + if (!cpu_node) + return; + + /** + * Get the state description from idle-state node entry-method + * First state is always WFI, per spec. + */ + modes[0] = MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT; + for (i = 1; i < drv->state_count; i++) { + mode_name = NULL; + state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i); + of_property_read_string(state_node, "entry-method", + &mode_name); + for (j = 0; mode_name && (j < ARRAY_SIZE(c_states)); j++) { + if (!strcmp(mode_name, c_states[j].name)) { + modes[i] = c_states[j].mode; + break; + } + } + } +} + +static int qcom_cpuidle_init(void) +{ + struct cpuidle_driver *drv = &qcom_cpuidle_driver; + int ret; + int i; + + drv->cpumask = kzalloc(cpumask_size(), GFP_KERNEL); + if (!drv->cpumask) + return -ENOMEM; + cpumask_copy(drv->cpumask, cpu_possible_mask); + + /** + * Default to standard for WFI (index = 0) + * Probe only for other states + */ + ret = dt_init_idle_driver(drv, 1); + if (ret < 0) { + pr_err("%s: failed to initialize idle states\n", __func__); + goto failed; + } + + /* Parse the idle states for C-States on this cpu */ + parse_state_translations(drv); + + /* Register entry point for all low states */ + for (i = 0; i < drv->state_count; i++) + drv->states[i].enter = qcom_lpm_enter; + drv->safe_state_index = 0; + + ret = cpuidle_register(drv, NULL); + if (ret) { + pr_err("%s: failed to register cpuidle driver\n", __func__); + goto failed; + } + + return 0; + +failed: + kfree(drv->cpumask); + return ret; +} +module_init(qcom_cpuidle_init);