From patchwork Wed Aug 27 18:54:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nishanth Menon X-Patchwork-Id: 36136 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f69.google.com (mail-yh0-f69.google.com [209.85.213.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4E849203C5 for ; Wed, 27 Aug 2014 18:55:29 +0000 (UTC) Received: by mail-yh0-f69.google.com with SMTP id v1sf1949755yhn.4 for ; Wed, 27 Aug 2014 11:55:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=60vAQ/95uqCqo9uFPE50ZeNqx1JvUTlRABM2lSbMRE4=; b=hw13GJ39zifstnLIZIz5duaeqleIv8D6QTzOBbFFvQhAufWx0xNqlZhPTPm1VKn/R+ YZ8uIIAyC7G8mOIO2JeP3uZwPHlcHSSVK+6ZVpFYSkLSKNPPqdsCDFEjCsR6plIw6XEW BY8s3PpjK8vYCqnibj9ezegMiC1lvkPYW2BfxSamWshJuRS3w7atE5j5l5Hes6kWXDQm +YpLgIYT8p8sZvVI87xfyMcRreoRVuNT8BqMewUdE9POG1KtwtM+p6IQDHGkh+J3kZ30 y8/0kAbipCal484SoqK6ZA89pihiaTaT1okv+rWZPRcdq7A4S59I/8RQ66o4HWLBFaKX JsSQ== X-Gm-Message-State: ALoCoQl48RAvcWlgnwxPXJL5vbnj6S/+ECV5yFe4V0uvHq62u6E9Gbx6R1M5GtprmAMEy93F4OmE X-Received: by 10.52.1.233 with SMTP id 9mr14619456vdp.5.1409165729060; Wed, 27 Aug 2014 11:55:29 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.101.210 with SMTP id u76ls297289qge.62.gmail; Wed, 27 Aug 2014 11:55:29 -0700 (PDT) X-Received: by 10.221.44.69 with SMTP id uf5mr31219015vcb.4.1409165728974; Wed, 27 Aug 2014 11:55:28 -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 qn4si1667953vdb.45.2014.08.27.11.55.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 27 Aug 2014 11:55:28 -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 lf12so90169vcb.12 for ; Wed, 27 Aug 2014 11:55:28 -0700 (PDT) X-Received: by 10.52.5.201 with SMTP id u9mr85468vdu.85.1409165728848; Wed, 27 Aug 2014 11:55:28 -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 uj3csp125538vcb; Wed, 27 Aug 2014 11:55:28 -0700 (PDT) X-Received: by 10.68.139.162 with SMTP id qz2mr24545969pbb.153.1409165727867; Wed, 27 Aug 2014 11:55:27 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bn13si2283047pdb.59.2014.08.27.11.55.27 for ; Wed, 27 Aug 2014 11:55:27 -0700 (PDT) Received-SPF: none (google.com: linux-omap-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 S964948AbaH0Sz0 (ORCPT + 6 others); Wed, 27 Aug 2014 14:55:26 -0400 Received: from arroyo.ext.ti.com ([192.94.94.40]:58561 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935477AbaH0SzY (ORCPT ); Wed, 27 Aug 2014 14:55:24 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id s7RIsv8V008211; Wed, 27 Aug 2014 13:54:57 -0500 Received: from DLEE70.ent.ti.com (dlemailx.itg.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s7RIsvr5010737; Wed, 27 Aug 2014 13:54:57 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Wed, 27 Aug 2014 13:54:56 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s7RIsuXd007098; Wed, 27 Aug 2014 13:54:56 -0500 From: Nishanth Menon To: Tony Lindgren , Kevin Hilman , Santosh Shilimkar CC: Paul Walmsley , Tero Kristo , , , , , , Nishanth Menon Subject: [PATCH V2 4/7] ARM: OMAP2+: powerdomain: introduce logic for finding valid power domain Date: Wed, 27 Aug 2014 13:54:54 -0500 Message-ID: <1409165694-26568-1-git-send-email-nm@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1408715373-25791-1-git-send-email-nm@ti.com> References: <1408715373-25791-1-git-send-email-nm@ti.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: nm@ti.com 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: , powerdomain configuration in OMAP is done using PWRSTCTRL register for each power domain. However, PRCM lets us write any value we'd like to the logic and power domain target states, however the SoC integration tends to actually function only at a few discrete states. These valid states are already in our powerdomains_xxx_data.c file. So, provide a function to easily query valid low power state that the power domain is allowed to go to. Based on work originally done by Jean Pihet https://patchwork.kernel.org/patch/1325091/ . There is no attempt to create a new powerdomain solution here, except fixing issues seen attempting invalid programming attempts. Future consolidation to the generic powerdomain framework should consider this requirement as well. Similar solutions have been done in product kernels in the past such as: https://android.googlesource.com/kernel/omap.git/+blame/android-omap-panda-3.0/arch/arm/mach-omap2/pm44xx.c Reviewed-by: Kevin Hilman Acked-by: Santosh Shilimkar Signed-off-by: Nishanth Menon --- Not posting the entire series again and updating just this patch.. V2: drop BUG in favor of WARN, picked up Santosh and Kevin's acks. V1: https://patchwork.kernel.org/patch/4764131/ arch/arm/mach-omap2/powerdomain.c | 76 +++++++++++++++++++++++++++++++++++++ arch/arm/mach-omap2/powerdomain.h | 3 ++ 2 files changed, 79 insertions(+) diff --git a/arch/arm/mach-omap2/powerdomain.c b/arch/arm/mach-omap2/powerdomain.c index f391948..7fb033e 100644 --- a/arch/arm/mach-omap2/powerdomain.c +++ b/arch/arm/mach-omap2/powerdomain.c @@ -1081,6 +1081,82 @@ int pwrdm_post_transition(struct powerdomain *pwrdm) } /** + * pwrdm_get_valid_lp_state() - Find best match deep power state + * @pwrdm: power domain for which we want to find best match + * @is_logic_state: Are we looking for logic state match here? Should + * be one of PWRDM_xxx macro values + * @req_state: requested power state + * + * Returns: closest match for requested power state. default fallback + * is RET for logic state and ON for power state. + * + * This does a search from the power domain data looking for the + * closest valid power domain state that the hardware can achieve. + * PRCM definitions for PWRSTCTRL allows us to program whatever + * configuration we'd like, and PRCM will actually attempt such + * a transition, however if the powerdomain does not actually support it, + * we endup with a hung system. The valid power domain states are already + * available in our powerdomain data files. So this function tries to do + * the following: + * a) find if we have an exact match to the request - no issues. + * b) else find if a deeper power state is possible. + * c) failing which, it tries to find closest higher power state for the + * request. + */ +u8 pwrdm_get_valid_lp_state(struct powerdomain *pwrdm, + bool is_logic_state, u8 req_state) +{ + u8 pwrdm_states = is_logic_state ? pwrdm->pwrsts_logic_ret : + pwrdm->pwrsts; + /* For logic, ret is highest and others, ON is highest */ + u8 default_pwrst = is_logic_state ? PWRDM_POWER_RET : PWRDM_POWER_ON; + u8 new_pwrst; + bool found; + + /* If it is already supported, nothing to search */ + if (pwrdm_states & BIT(req_state)) + return req_state; + + if (!req_state) + goto up_search; + + /* + * So, we dont have a exact match + * Can we get a deeper power state match? + */ + new_pwrst = req_state - 1; + found = true; + while (!(pwrdm_states & BIT(new_pwrst))) { + /* No match even at OFF? Not available */ + if (new_pwrst == PWRDM_POWER_OFF) { + found = false; + break; + } + new_pwrst--; + } + + if (found) + goto done; + +up_search: + /* OK, no deeper ones, can we get a higher match? */ + new_pwrst = req_state + 1; + while (!(pwrdm_states & BIT(new_pwrst))) { + if (new_pwrst > PWRDM_POWER_ON) { + WARN(1, "powerdomain: %s: Fix max powerstate to ON\n", + pwrdm->name); + return PWRDM_POWER_ON; + } + + if (new_pwrst == default_pwrst) + break; + new_pwrst++; + } +done: + return new_pwrst; +} + +/** * omap_set_pwrdm_state - change a powerdomain's current power state * @pwrdm: struct powerdomain * to change the power state of * @pwrst: power state to change to diff --git a/arch/arm/mach-omap2/powerdomain.h b/arch/arm/mach-omap2/powerdomain.h index a754c82..11bd4dd 100644 --- a/arch/arm/mach-omap2/powerdomain.h +++ b/arch/arm/mach-omap2/powerdomain.h @@ -220,6 +220,9 @@ struct voltagedomain *pwrdm_get_voltdm(struct powerdomain *pwrdm); int pwrdm_get_mem_bank_count(struct powerdomain *pwrdm); +u8 pwrdm_get_valid_lp_state(struct powerdomain *pwrdm, + bool is_logic_state, u8 req_state); + int pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst); int pwrdm_read_next_pwrst(struct powerdomain *pwrdm); int pwrdm_read_pwrst(struct powerdomain *pwrdm);